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
*)>);
90 static void breakpoint_re_set_default (struct breakpoint
*);
93 create_sals_from_location_default (struct event_location
*location
,
94 struct linespec_result
*canonical
,
95 enum bptype type_wanted
);
97 static void create_breakpoints_sal_default (struct gdbarch
*,
98 struct linespec_result
*,
99 gdb::unique_xmalloc_ptr
<char>,
100 gdb::unique_xmalloc_ptr
<char>,
102 enum bpdisp
, int, int,
104 const struct breakpoint_ops
*,
105 int, int, int, unsigned);
107 static std::vector
<symtab_and_line
> decode_location_default
108 (struct breakpoint
*b
, struct event_location
*location
,
109 struct program_space
*search_pspace
);
111 static int can_use_hardware_watchpoint
112 (const std::vector
<value_ref_ptr
> &vals
);
114 static void mention (struct breakpoint
*);
116 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
118 const struct breakpoint_ops
*);
119 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
120 const struct symtab_and_line
*);
122 /* This function is used in gdbtk sources and thus can not be made
124 static struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
125 struct symtab_and_line
,
127 const struct breakpoint_ops
*);
129 static struct breakpoint
*
130 momentary_breakpoint_from_master (struct breakpoint
*orig
,
132 const struct breakpoint_ops
*ops
,
135 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
137 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
141 static void describe_other_breakpoints (struct gdbarch
*,
142 struct program_space
*, CORE_ADDR
,
143 struct obj_section
*, int);
145 static int watchpoint_locations_match (struct bp_location
*loc1
,
146 struct bp_location
*loc2
);
148 static int breakpoint_locations_match (struct bp_location
*loc1
,
149 struct bp_location
*loc2
,
150 bool sw_hw_bps_match
= false);
152 static int breakpoint_location_address_match (struct bp_location
*bl
,
153 const struct address_space
*aspace
,
156 static int breakpoint_location_address_range_overlap (struct bp_location
*,
157 const address_space
*,
160 static int remove_breakpoint (struct bp_location
*);
161 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
163 static enum print_stop_action
print_bp_stop_message (bpstat
*bs
);
165 static int hw_breakpoint_used_count (void);
167 static int hw_watchpoint_use_count (struct breakpoint
*);
169 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
171 int *other_type_used
);
173 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
176 static void decref_bp_location (struct bp_location
**loc
);
178 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
180 /* update_global_location_list's modes of operation wrt to whether to
181 insert locations now. */
182 enum ugll_insert_mode
184 /* Don't insert any breakpoint locations into the inferior, only
185 remove already-inserted locations that no longer should be
186 inserted. Functions that delete a breakpoint or breakpoints
187 should specify this mode, so that deleting a breakpoint doesn't
188 have the side effect of inserting the locations of other
189 breakpoints that are marked not-inserted, but should_be_inserted
190 returns true on them.
192 This behavior is useful is situations close to tear-down -- e.g.,
193 after an exec, while the target still has execution, but
194 breakpoint shadows of the previous executable image should *NOT*
195 be restored to the new image; or before detaching, where the
196 target still has execution and wants to delete breakpoints from
197 GDB's lists, and all breakpoints had already been removed from
201 /* May insert breakpoints iff breakpoints_should_be_inserted_now
202 claims breakpoints should be inserted now. */
205 /* Insert locations now, irrespective of
206 breakpoints_should_be_inserted_now. E.g., say all threads are
207 stopped right now, and the user did "continue". We need to
208 insert breakpoints _before_ resuming the target, but
209 UGLL_MAY_INSERT wouldn't insert them, because
210 breakpoints_should_be_inserted_now returns false at that point,
211 as no thread is running yet. */
215 static void update_global_location_list (enum ugll_insert_mode
);
217 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
219 static void insert_breakpoint_locations (void);
221 static void trace_pass_command (const char *, int);
223 static void set_tracepoint_count (int num
);
225 static bool is_masked_watchpoint (const struct breakpoint
*b
);
227 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
230 static int strace_marker_p (struct breakpoint
*b
);
232 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
233 that are implemented on top of software or hardware breakpoints
234 (user breakpoints, internal and momentary breakpoints, etc.). */
235 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
237 /* The breakpoint_ops structure to be used in regular user created
239 struct breakpoint_ops bkpt_breakpoint_ops
;
241 /* Breakpoints set on probes. */
242 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
244 /* Tracepoints set on probes. */
245 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
247 /* Dynamic printf class type. */
248 struct breakpoint_ops dprintf_breakpoint_ops
;
250 /* The structure to be used in regular breakpoints. */
251 struct ordinary_breakpoint
: public base_breakpoint
255 /* Internal breakpoints. */
256 struct internal_breakpoint
: public base_breakpoint
258 void re_set () override
;
259 void check_status (struct bpstat
*bs
) override
;
260 enum print_stop_action
print_it (struct bpstat
*bs
) override
;
261 void print_mention () override
;
264 /* Momentary breakpoints. */
265 struct momentary_breakpoint
: public base_breakpoint
267 void re_set () override
;
268 void check_status (struct bpstat
*bs
) override
;
269 enum print_stop_action
print_it (struct bpstat
*bs
) override
;
270 void print_mention () override
;
273 /* DPrintf breakpoints. */
274 struct dprintf_breakpoint
: public ordinary_breakpoint
278 /* The style in which to perform a dynamic printf. This is a user
279 option because different output options have different tradeoffs;
280 if GDB does the printing, there is better error handling if there
281 is a problem with any of the arguments, but using an inferior
282 function lets you have special-purpose printers and sending of
283 output to the same place as compiled-in print functions. */
285 static const char dprintf_style_gdb
[] = "gdb";
286 static const char dprintf_style_call
[] = "call";
287 static const char dprintf_style_agent
[] = "agent";
288 static const char *const dprintf_style_enums
[] = {
294 static const char *dprintf_style
= dprintf_style_gdb
;
296 /* The function to use for dynamic printf if the preferred style is to
297 call into the inferior. The value is simply a string that is
298 copied into the command, so it can be anything that GDB can
299 evaluate to a callable address, not necessarily a function name. */
301 static std::string dprintf_function
= "printf";
303 /* The channel to use for dynamic printf if the preferred style is to
304 call into the inferior; if a nonempty string, it will be passed to
305 the call as the first argument, with the format string as the
306 second. As with the dprintf function, this can be anything that
307 GDB knows how to evaluate, so in addition to common choices like
308 "stderr", this could be an app-specific expression like
309 "mystreams[curlogger]". */
311 static std::string dprintf_channel
;
313 /* True if dprintf commands should continue to operate even if GDB
315 static bool disconnected_dprintf
= true;
317 struct command_line
*
318 breakpoint_commands (struct breakpoint
*b
)
320 return b
->commands
? b
->commands
.get () : NULL
;
323 /* Flag indicating that a command has proceeded the inferior past the
324 current breakpoint. */
326 static bool breakpoint_proceeded
;
329 bpdisp_text (enum bpdisp disp
)
331 /* NOTE: the following values are a part of MI protocol and
332 represent values of 'disp' field returned when inferior stops at
334 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
336 return bpdisps
[(int) disp
];
339 /* Prototypes for exported functions. */
340 /* If FALSE, gdb will not use hardware support for watchpoints, even
341 if such is available. */
342 static int can_use_hw_watchpoints
;
345 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
346 struct cmd_list_element
*c
,
350 _("Debugger's willingness to use "
351 "watchpoint hardware is %s.\n"),
355 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
356 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
357 for unrecognized breakpoint locations.
358 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
359 static enum auto_boolean pending_break_support
;
361 show_pending_break_support (struct ui_file
*file
, int from_tty
,
362 struct cmd_list_element
*c
,
366 _("Debugger's behavior regarding "
367 "pending breakpoints is %s.\n"),
371 /* If true, gdb will automatically use hardware breakpoints for breakpoints
372 set with "break" but falling in read-only memory.
373 If false, gdb will warn about such breakpoints, but won't automatically
374 use hardware breakpoints. */
375 static bool automatic_hardware_breakpoints
;
377 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
378 struct cmd_list_element
*c
,
382 _("Automatic usage of hardware breakpoints is %s.\n"),
386 /* If on, GDB keeps breakpoints inserted even if the inferior is
387 stopped, and immediately inserts any new breakpoints as soon as
388 they're created. If off (default), GDB keeps breakpoints off of
389 the target as long as possible. That is, it delays inserting
390 breakpoints until the next resume, and removes them again when the
391 target fully stops. This is a bit safer in case GDB crashes while
392 processing user input. */
393 static bool always_inserted_mode
= false;
396 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
397 struct cmd_list_element
*c
, const char *value
)
399 gdb_printf (file
, _("Always inserted breakpoint mode is %s.\n"),
403 /* See breakpoint.h. */
406 breakpoints_should_be_inserted_now (void)
408 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
410 /* If breakpoints are global, they should be inserted even if no
411 thread under gdb's control is running, or even if there are
412 no threads under GDB's control yet. */
417 if (always_inserted_mode
)
419 /* The user wants breakpoints inserted even if all threads
424 for (inferior
*inf
: all_inferiors ())
425 if (inf
->has_execution ()
426 && threads_are_executing (inf
->process_target ()))
429 /* Don't remove breakpoints yet if, even though all threads are
430 stopped, we still have events to process. */
431 for (thread_info
*tp
: all_non_exited_threads ())
432 if (tp
->resumed () && tp
->has_pending_waitstatus ())
438 static const char condition_evaluation_both
[] = "host or target";
440 /* Modes for breakpoint condition evaluation. */
441 static const char condition_evaluation_auto
[] = "auto";
442 static const char condition_evaluation_host
[] = "host";
443 static const char condition_evaluation_target
[] = "target";
444 static const char *const condition_evaluation_enums
[] = {
445 condition_evaluation_auto
,
446 condition_evaluation_host
,
447 condition_evaluation_target
,
451 /* Global that holds the current mode for breakpoint condition evaluation. */
452 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
454 /* Global that we use to display information to the user (gets its value from
455 condition_evaluation_mode_1. */
456 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
458 /* Translate a condition evaluation mode MODE into either "host"
459 or "target". This is used mostly to translate from "auto" to the
460 real setting that is being used. It returns the translated
464 translate_condition_evaluation_mode (const char *mode
)
466 if (mode
== condition_evaluation_auto
)
468 if (target_supports_evaluation_of_breakpoint_conditions ())
469 return condition_evaluation_target
;
471 return condition_evaluation_host
;
477 /* Discovers what condition_evaluation_auto translates to. */
480 breakpoint_condition_evaluation_mode (void)
482 return translate_condition_evaluation_mode (condition_evaluation_mode
);
485 /* Return true if GDB should evaluate breakpoint conditions or false
489 gdb_evaluates_breakpoint_condition_p (void)
491 const char *mode
= breakpoint_condition_evaluation_mode ();
493 return (mode
== condition_evaluation_host
);
496 /* Are we executing breakpoint commands? */
497 static int executing_breakpoint_commands
;
499 /* Are overlay event breakpoints enabled? */
500 static int overlay_events_enabled
;
502 /* See description in breakpoint.h. */
503 bool target_exact_watchpoints
= false;
505 /* Walk the following statement or block through all breakpoints.
506 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
507 current breakpoint. */
509 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
510 for (B = breakpoint_chain; \
511 B ? (TMP=B->next, 1): 0; \
514 /* Chains of all breakpoints defined. */
516 static struct breakpoint
*breakpoint_chain
;
518 /* See breakpoint.h. */
523 return breakpoint_range (breakpoint_chain
);
526 /* See breakpoint.h. */
528 breakpoint_safe_range
529 all_breakpoints_safe ()
531 return breakpoint_safe_range (all_breakpoints ());
534 /* See breakpoint.h. */
539 return tracepoint_range (breakpoint_chain
);
542 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
544 static std::vector
<bp_location
*> bp_locations
;
546 /* See breakpoint.h. */
548 const std::vector
<bp_location
*> &
554 /* Range to iterate over breakpoint locations at a given address. */
556 struct bp_locations_at_addr_range
558 using iterator
= std::vector
<bp_location
*>::iterator
;
560 bp_locations_at_addr_range (CORE_ADDR addr
)
564 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
565 { return loc
->address
< addr_
; }
567 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
568 { return addr_
< loc
->address
; }
571 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
574 m_begin
= it_pair
.first
;
575 m_end
= it_pair
.second
;
578 iterator
begin () const
581 iterator
end () const
589 /* Return a range to iterate over all breakpoint locations exactly at address
592 If it's needed to iterate multiple times on the same range, it's possible
593 to save the range in a local variable and use it multiple times:
595 auto range = all_bp_locations_at_addr (addr);
597 for (bp_location *loc : range)
600 for (bp_location *loc : range)
603 This saves a bit of time, as it avoids re-doing the binary searches to find
604 the range's boundaries. Just remember not to change the bp_locations vector
605 in the mean time, as it could make the range's iterators stale. */
607 static bp_locations_at_addr_range
608 all_bp_locations_at_addr (CORE_ADDR addr
)
610 return bp_locations_at_addr_range (addr
);
613 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
614 ADDRESS for the current elements of BP_LOCATIONS which get a valid
615 result from bp_location_has_shadow. You can use it for roughly
616 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
617 an address you need to read. */
619 static CORE_ADDR bp_locations_placed_address_before_address_max
;
621 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
622 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
623 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
624 You can use it for roughly limiting the subrange of BP_LOCATIONS to
625 scan for shadow bytes for an address you need to read. */
627 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
629 /* The locations that no longer correspond to any breakpoint, unlinked
630 from the bp_locations array, but for which a hit may still be
631 reported by a target. */
632 static std::vector
<bp_location
*> moribund_locations
;
634 /* Number of last breakpoint made. */
636 static int breakpoint_count
;
638 /* The value of `breakpoint_count' before the last command that
639 created breakpoints. If the last (break-like) command created more
640 than one breakpoint, then the difference between BREAKPOINT_COUNT
641 and PREV_BREAKPOINT_COUNT is more than one. */
642 static int prev_breakpoint_count
;
644 /* Number of last tracepoint made. */
646 static int tracepoint_count
;
648 static struct cmd_list_element
*breakpoint_set_cmdlist
;
649 static struct cmd_list_element
*breakpoint_show_cmdlist
;
650 struct cmd_list_element
*save_cmdlist
;
652 /* Return whether a breakpoint is an active enabled breakpoint. */
654 breakpoint_enabled (struct breakpoint
*b
)
656 return (b
->enable_state
== bp_enabled
);
659 /* Set breakpoint count to NUM. */
662 set_breakpoint_count (int num
)
664 prev_breakpoint_count
= breakpoint_count
;
665 breakpoint_count
= num
;
666 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
669 /* Used by `start_rbreak_breakpoints' below, to record the current
670 breakpoint count before "rbreak" creates any breakpoint. */
671 static int rbreak_start_breakpoint_count
;
673 /* Called at the start an "rbreak" command to record the first
676 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
678 rbreak_start_breakpoint_count
= breakpoint_count
;
681 /* Called at the end of an "rbreak" command to record the last
684 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
686 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
689 /* Used in run_command to zero the hit count when a new run starts. */
692 clear_breakpoint_hit_counts (void)
694 for (breakpoint
*b
: all_breakpoints ())
699 /* Return the breakpoint with the specified number, or NULL
700 if the number does not refer to an existing breakpoint. */
703 get_breakpoint (int num
)
705 for (breakpoint
*b
: all_breakpoints ())
706 if (b
->number
== num
)
714 /* Mark locations as "conditions have changed" in case the target supports
715 evaluating conditions on its side. */
718 mark_breakpoint_modified (struct breakpoint
*b
)
720 /* This is only meaningful if the target is
721 evaluating conditions and if the user has
722 opted for condition evaluation on the target's
724 if (gdb_evaluates_breakpoint_condition_p ()
725 || !target_supports_evaluation_of_breakpoint_conditions ())
728 if (!is_breakpoint (b
))
731 for (bp_location
*loc
: b
->locations ())
732 loc
->condition_changed
= condition_modified
;
735 /* Mark location as "conditions have changed" in case the target supports
736 evaluating conditions on its side. */
739 mark_breakpoint_location_modified (struct bp_location
*loc
)
741 /* This is only meaningful if the target is
742 evaluating conditions and if the user has
743 opted for condition evaluation on the target's
745 if (gdb_evaluates_breakpoint_condition_p ()
746 || !target_supports_evaluation_of_breakpoint_conditions ())
750 if (!is_breakpoint (loc
->owner
))
753 loc
->condition_changed
= condition_modified
;
756 /* Sets the condition-evaluation mode using the static global
757 condition_evaluation_mode. */
760 set_condition_evaluation_mode (const char *args
, int from_tty
,
761 struct cmd_list_element
*c
)
763 const char *old_mode
, *new_mode
;
765 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
766 && !target_supports_evaluation_of_breakpoint_conditions ())
768 condition_evaluation_mode_1
= condition_evaluation_mode
;
769 warning (_("Target does not support breakpoint condition evaluation.\n"
770 "Using host evaluation mode instead."));
774 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
775 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
777 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
778 settings was "auto". */
779 condition_evaluation_mode
= condition_evaluation_mode_1
;
781 /* Only update the mode if the user picked a different one. */
782 if (new_mode
!= old_mode
)
784 /* If the user switched to a different evaluation mode, we
785 need to synch the changes with the target as follows:
787 "host" -> "target": Send all (valid) conditions to the target.
788 "target" -> "host": Remove all the conditions from the target.
791 if (new_mode
== condition_evaluation_target
)
793 /* Mark everything modified and synch conditions with the
795 for (bp_location
*loc
: all_bp_locations ())
796 mark_breakpoint_location_modified (loc
);
800 /* Manually mark non-duplicate locations to synch conditions
801 with the target. We do this to remove all the conditions the
802 target knows about. */
803 for (bp_location
*loc
: all_bp_locations ())
804 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
805 loc
->needs_update
= 1;
809 update_global_location_list (UGLL_MAY_INSERT
);
815 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
816 what "auto" is translating to. */
819 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
820 struct cmd_list_element
*c
, const char *value
)
822 if (condition_evaluation_mode
== condition_evaluation_auto
)
824 _("Breakpoint condition evaluation "
825 "mode is %s (currently %s).\n"),
827 breakpoint_condition_evaluation_mode ());
829 gdb_printf (file
, _("Breakpoint condition evaluation mode is %s.\n"),
833 /* Parse COND_STRING in the context of LOC and set as the condition
834 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
835 the number of LOC within its owner. In case of parsing error, mark
836 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
839 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
840 int bp_num
, int loc_num
)
842 bool has_junk
= false;
845 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
846 block_for_pc (loc
->address
), 0);
847 if (*cond_string
!= 0)
851 loc
->cond
= std::move (new_exp
);
852 if (loc
->disabled_by_cond
&& loc
->enabled
)
853 gdb_printf (_("Breakpoint %d's condition is now valid at "
854 "location %d, enabling.\n"),
857 loc
->disabled_by_cond
= false;
860 catch (const gdb_exception_error
&e
)
864 /* Warn if a user-enabled location is now becoming disabled-by-cond.
865 BP_NUM is 0 if the breakpoint is being defined for the first
866 time using the "break ... if ..." command, and non-zero if
869 warning (_("failed to validate condition at location %d.%d, "
870 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
872 warning (_("failed to validate condition at location %d, "
873 "disabling:\n %s"), loc_num
, e
.what ());
876 loc
->disabled_by_cond
= true;
880 error (_("Garbage '%s' follows condition"), cond_string
);
884 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
885 int from_tty
, bool force
)
889 b
->cond_string
.reset ();
891 if (is_watchpoint (b
))
892 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
896 for (bp_location
*loc
: b
->locations ())
899 if (loc
->disabled_by_cond
&& loc
->enabled
)
900 gdb_printf (_("Breakpoint %d's condition is now valid at "
901 "location %d, enabling.\n"),
903 loc
->disabled_by_cond
= false;
906 /* No need to free the condition agent expression
907 bytecode (if we have one). We will handle this
908 when we go through update_global_location_list. */
913 gdb_printf (_("Breakpoint %d now unconditional.\n"), b
->number
);
917 if (is_watchpoint (b
))
919 innermost_block_tracker tracker
;
920 const char *arg
= exp
;
921 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
923 error (_("Junk at end of expression"));
924 watchpoint
*w
= static_cast<watchpoint
*> (b
);
925 w
->cond_exp
= std::move (new_exp
);
926 w
->cond_exp_valid_block
= tracker
.block ();
930 /* Parse and set condition expressions. We make two passes.
931 In the first, we parse the condition string to see if it
932 is valid in at least one location. If so, the condition
933 would be accepted. So we go ahead and set the locations'
934 conditions. In case no valid case is found, we throw
935 the error and the condition string will be rejected.
936 This two-pass approach is taken to avoid setting the
937 state of locations in case of a reject. */
938 for (bp_location
*loc
: b
->locations ())
942 const char *arg
= exp
;
943 parse_exp_1 (&arg
, loc
->address
,
944 block_for_pc (loc
->address
), 0);
946 error (_("Junk at end of expression"));
949 catch (const gdb_exception_error
&e
)
951 /* Condition string is invalid. If this happens to
952 be the last loc, abandon (if not forced) or continue
954 if (loc
->next
== nullptr && !force
)
959 /* If we reach here, the condition is valid at some locations. */
961 for (bp_location
*loc
: b
->locations ())
963 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
968 /* We know that the new condition parsed successfully. The
969 condition string of the breakpoint can be safely updated. */
970 b
->cond_string
= make_unique_xstrdup (exp
);
971 b
->condition_not_parsed
= 0;
973 mark_breakpoint_modified (b
);
975 gdb::observers::breakpoint_modified
.notify (b
);
978 /* See breakpoint.h. */
981 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
984 for (breakpoint
*b
: all_breakpoints ())
985 if (b
->number
== bpnum
)
987 /* Check if this breakpoint has a "stop" method implemented in an
988 extension language. This method and conditions entered into GDB
989 from the CLI are mutually exclusive. */
990 const struct extension_language_defn
*extlang
991 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
995 error (_("Only one stop condition allowed. There is currently"
996 " a %s stop condition defined for this breakpoint."),
997 ext_lang_capitalized_name (extlang
));
999 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1001 if (is_breakpoint (b
))
1002 update_global_location_list (UGLL_MAY_INSERT
);
1007 error (_("No breakpoint number %d."), bpnum
);
1010 /* The options for the "condition" command. */
1012 struct condition_command_opts
1015 bool force_condition
= false;
1018 static const gdb::option::option_def condition_command_option_defs
[] = {
1020 gdb::option::flag_option_def
<condition_command_opts
> {
1022 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1023 N_("Set the condition even if it is invalid for all current locations."),
1028 /* Create an option_def_group for the "condition" options, with
1029 CC_OPTS as context. */
1031 static inline gdb::option::option_def_group
1032 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1034 return {{condition_command_option_defs
}, cc_opts
};
1037 /* Completion for the "condition" command. */
1040 condition_completer (struct cmd_list_element
*cmd
,
1041 completion_tracker
&tracker
,
1042 const char *text
, const char * /*word*/)
1044 bool has_no_arguments
= (*text
== '\0');
1045 condition_command_opts cc_opts
;
1046 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1047 if (gdb::option::complete_options
1048 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1051 text
= skip_spaces (text
);
1052 const char *space
= skip_to_space (text
);
1059 tracker
.advance_custom_word_point_by (1);
1060 /* We don't support completion of history indices. */
1061 if (!isdigit (text
[1]))
1062 complete_internalvar (tracker
, &text
[1]);
1066 /* Suggest the "-force" flag if no arguments are given. If
1067 arguments were passed, they either already include the flag,
1068 or we are beyond the point of suggesting it because it's
1069 positionally the first argument. */
1070 if (has_no_arguments
)
1071 gdb::option::complete_on_all_options (tracker
, group
);
1073 /* We're completing the breakpoint number. */
1074 len
= strlen (text
);
1076 for (breakpoint
*b
: all_breakpoints ())
1080 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1082 if (strncmp (number
, text
, len
) == 0)
1083 tracker
.add_completion (make_unique_xstrdup (number
));
1089 /* We're completing the expression part. Skip the breakpoint num. */
1090 const char *exp_start
= skip_spaces (space
);
1091 tracker
.advance_custom_word_point_by (exp_start
- text
);
1093 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1094 expression_completer (cmd
, tracker
, text
, word
);
1097 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1100 condition_command (const char *arg
, int from_tty
)
1106 error_no_arg (_("breakpoint number"));
1110 /* Check if the "-force" flag was passed. */
1111 condition_command_opts cc_opts
;
1112 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1113 gdb::option::process_options
1114 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1116 bnum
= get_number (&p
);
1118 error (_("Bad breakpoint argument: '%s'"), arg
);
1120 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1123 /* Check that COMMAND do not contain commands that are suitable
1124 only for tracepoints and not suitable for ordinary breakpoints.
1125 Throw if any such commands is found. */
1128 check_no_tracepoint_commands (struct command_line
*commands
)
1130 struct command_line
*c
;
1132 for (c
= commands
; c
; c
= c
->next
)
1134 if (c
->control_type
== while_stepping_control
)
1135 error (_("The 'while-stepping' command can "
1136 "only be used for tracepoints"));
1138 check_no_tracepoint_commands (c
->body_list_0
.get ());
1139 check_no_tracepoint_commands (c
->body_list_1
.get ());
1141 /* Not that command parsing removes leading whitespace and comment
1142 lines and also empty lines. So, we only need to check for
1143 command directly. */
1144 if (strstr (c
->line
, "collect ") == c
->line
)
1145 error (_("The 'collect' command can only be used for tracepoints"));
1147 if (strstr (c
->line
, "teval ") == c
->line
)
1148 error (_("The 'teval' command can only be used for tracepoints"));
1152 struct longjmp_breakpoint
: public momentary_breakpoint
1154 ~longjmp_breakpoint () override
;
1157 /* Encapsulate tests for different types of tracepoints. */
1160 is_tracepoint_type (bptype type
)
1162 return (type
== bp_tracepoint
1163 || type
== bp_fast_tracepoint
1164 || type
== bp_static_tracepoint
);
1167 /* See breakpoint.h. */
1170 is_tracepoint (const struct breakpoint
*b
)
1172 return is_tracepoint_type (b
->type
);
1175 /* Factory function to create an appropriate instance of breakpoint given
1178 static std::unique_ptr
<breakpoint
>
1179 new_breakpoint_from_type (bptype type
)
1186 case bp_hardware_breakpoint
:
1187 b
= new ordinary_breakpoint ();
1190 case bp_fast_tracepoint
:
1191 case bp_static_tracepoint
:
1193 b
= new tracepoint ();
1197 b
= new dprintf_breakpoint ();
1200 case bp_overlay_event
:
1201 case bp_longjmp_master
:
1202 case bp_std_terminate_master
:
1203 case bp_exception_master
:
1204 case bp_thread_event
:
1206 case bp_shlib_event
:
1207 b
= new internal_breakpoint ();
1212 b
= new longjmp_breakpoint ();
1215 case bp_watchpoint_scope
:
1217 case bp_gnu_ifunc_resolver_return
:
1218 case bp_step_resume
:
1219 case bp_hp_step_resume
:
1220 case bp_longjmp_resume
:
1221 case bp_longjmp_call_dummy
:
1222 case bp_exception_resume
:
1225 case bp_std_terminate
:
1226 b
= new momentary_breakpoint ();
1230 gdb_assert_not_reached ("invalid type");
1233 return std::unique_ptr
<breakpoint
> (b
);
1236 /* A helper function that validates that COMMANDS are valid for a
1237 breakpoint. This function will throw an exception if a problem is
1241 validate_commands_for_breakpoint (struct breakpoint
*b
,
1242 struct command_line
*commands
)
1244 if (is_tracepoint (b
))
1246 struct tracepoint
*t
= (struct tracepoint
*) b
;
1247 struct command_line
*c
;
1248 struct command_line
*while_stepping
= 0;
1250 /* Reset the while-stepping step count. The previous commands
1251 might have included a while-stepping action, while the new
1255 /* We need to verify that each top-level element of commands is
1256 valid for tracepoints, that there's at most one
1257 while-stepping element, and that the while-stepping's body
1258 has valid tracing commands excluding nested while-stepping.
1259 We also need to validate the tracepoint action line in the
1260 context of the tracepoint --- validate_actionline actually
1261 has side effects, like setting the tracepoint's
1262 while-stepping STEP_COUNT, in addition to checking if the
1263 collect/teval actions parse and make sense in the
1264 tracepoint's context. */
1265 for (c
= commands
; c
; c
= c
->next
)
1267 if (c
->control_type
== while_stepping_control
)
1269 if (b
->type
== bp_fast_tracepoint
)
1270 error (_("The 'while-stepping' command "
1271 "cannot be used for fast tracepoint"));
1272 else if (b
->type
== bp_static_tracepoint
)
1273 error (_("The 'while-stepping' command "
1274 "cannot be used for static tracepoint"));
1277 error (_("The 'while-stepping' command "
1278 "can be used only once"));
1283 validate_actionline (c
->line
, b
);
1287 struct command_line
*c2
;
1289 gdb_assert (while_stepping
->body_list_1
== nullptr);
1290 c2
= while_stepping
->body_list_0
.get ();
1291 for (; c2
; c2
= c2
->next
)
1293 if (c2
->control_type
== while_stepping_control
)
1294 error (_("The 'while-stepping' command cannot be nested"));
1300 check_no_tracepoint_commands (commands
);
1304 /* Return a vector of all the static tracepoints set at ADDR. The
1305 caller is responsible for releasing the vector. */
1307 std::vector
<breakpoint
*>
1308 static_tracepoints_here (CORE_ADDR addr
)
1310 std::vector
<breakpoint
*> found
;
1312 for (breakpoint
*b
: all_breakpoints ())
1313 if (b
->type
== bp_static_tracepoint
)
1315 for (bp_location
*loc
: b
->locations ())
1316 if (loc
->address
== addr
)
1317 found
.push_back (b
);
1323 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1324 validate that only allowed commands are included. */
1327 breakpoint_set_commands (struct breakpoint
*b
,
1328 counted_command_line
&&commands
)
1330 validate_commands_for_breakpoint (b
, commands
.get ());
1332 b
->commands
= std::move (commands
);
1333 gdb::observers::breakpoint_modified
.notify (b
);
1336 /* Set the internal `silent' flag on the breakpoint. Note that this
1337 is not the same as the "silent" that may appear in the breakpoint's
1341 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1343 int old_silent
= b
->silent
;
1346 if (old_silent
!= silent
)
1347 gdb::observers::breakpoint_modified
.notify (b
);
1350 /* Set the thread for this breakpoint. If THREAD is -1, make the
1351 breakpoint work for any thread. */
1354 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1356 int old_thread
= b
->thread
;
1359 if (old_thread
!= thread
)
1360 gdb::observers::breakpoint_modified
.notify (b
);
1363 /* Set the task for this breakpoint. If TASK is 0, make the
1364 breakpoint work for any task. */
1367 breakpoint_set_task (struct breakpoint
*b
, int task
)
1369 int old_task
= b
->task
;
1372 if (old_task
!= task
)
1373 gdb::observers::breakpoint_modified
.notify (b
);
1377 commands_command_1 (const char *arg
, int from_tty
,
1378 struct command_line
*control
)
1380 counted_command_line cmd
;
1381 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1382 NULL after the call to read_command_lines if the user provides an empty
1383 list of command by just typing "end". */
1384 bool cmd_read
= false;
1386 std::string new_arg
;
1388 if (arg
== NULL
|| !*arg
)
1390 /* Argument not explicitly given. Synthesize it. */
1391 if (breakpoint_count
- prev_breakpoint_count
> 1)
1392 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1394 else if (breakpoint_count
> 0)
1395 new_arg
= string_printf ("%d", breakpoint_count
);
1399 /* Create a copy of ARG. This is needed because the "commands"
1400 command may be coming from a script. In that case, the read
1401 line buffer is going to be overwritten in the lambda of
1402 'map_breakpoint_numbers' below when reading the next line
1403 before we are are done parsing the breakpoint numbers. */
1406 arg
= new_arg
.c_str ();
1408 map_breakpoint_numbers
1409 (arg
, [&] (breakpoint
*b
)
1413 gdb_assert (cmd
== NULL
);
1414 if (control
!= NULL
)
1415 cmd
= control
->body_list_0
;
1419 = string_printf (_("Type commands for breakpoint(s) "
1420 "%s, one per line."),
1423 auto do_validate
= [=] (const char *line
)
1425 validate_actionline (line
, b
);
1427 gdb::function_view
<void (const char *)> validator
;
1428 if (is_tracepoint (b
))
1429 validator
= do_validate
;
1431 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1436 /* If a breakpoint was on the list more than once, we don't need to
1438 if (b
->commands
!= cmd
)
1440 validate_commands_for_breakpoint (b
, cmd
.get ());
1442 gdb::observers::breakpoint_modified
.notify (b
);
1448 commands_command (const char *arg
, int from_tty
)
1450 commands_command_1 (arg
, from_tty
, NULL
);
1453 /* Like commands_command, but instead of reading the commands from
1454 input stream, takes them from an already parsed command structure.
1456 This is used by cli-script.c to DTRT with breakpoint commands
1457 that are part of if and while bodies. */
1458 enum command_control_type
1459 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1461 commands_command_1 (arg
, 0, cmd
);
1462 return simple_control
;
1465 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1468 bp_location_has_shadow (struct bp_location
*bl
)
1470 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1474 if (bl
->target_info
.shadow_len
== 0)
1475 /* BL isn't valid, or doesn't shadow memory. */
1480 /* Update BUF, which is LEN bytes read from the target address
1481 MEMADDR, by replacing a memory breakpoint with its shadowed
1484 If READBUF is not NULL, this buffer must not overlap with the of
1485 the breakpoint location's shadow_contents buffer. Otherwise, a
1486 failed assertion internal error will be raised. */
1489 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1490 const gdb_byte
*writebuf_org
,
1491 ULONGEST memaddr
, LONGEST len
,
1492 struct bp_target_info
*target_info
,
1493 struct gdbarch
*gdbarch
)
1495 /* Now do full processing of the found relevant range of elements. */
1496 CORE_ADDR bp_addr
= 0;
1500 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1501 current_program_space
->aspace
, 0))
1503 /* The breakpoint is inserted in a different address space. */
1507 /* Addresses and length of the part of the breakpoint that
1509 bp_addr
= target_info
->placed_address
;
1510 bp_size
= target_info
->shadow_len
;
1512 if (bp_addr
+ bp_size
<= memaddr
)
1514 /* The breakpoint is entirely before the chunk of memory we are
1519 if (bp_addr
>= memaddr
+ len
)
1521 /* The breakpoint is entirely after the chunk of memory we are
1526 /* Offset within shadow_contents. */
1527 if (bp_addr
< memaddr
)
1529 /* Only copy the second part of the breakpoint. */
1530 bp_size
-= memaddr
- bp_addr
;
1531 bptoffset
= memaddr
- bp_addr
;
1535 if (bp_addr
+ bp_size
> memaddr
+ len
)
1537 /* Only copy the first part of the breakpoint. */
1538 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1541 if (readbuf
!= NULL
)
1543 /* Verify that the readbuf buffer does not overlap with the
1544 shadow_contents buffer. */
1545 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1546 || readbuf
>= (target_info
->shadow_contents
1547 + target_info
->shadow_len
));
1549 /* Update the read buffer with this inserted breakpoint's
1551 memcpy (readbuf
+ bp_addr
- memaddr
,
1552 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1556 const unsigned char *bp
;
1557 CORE_ADDR addr
= target_info
->reqstd_address
;
1560 /* Update the shadow with what we want to write to memory. */
1561 memcpy (target_info
->shadow_contents
+ bptoffset
,
1562 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1564 /* Determine appropriate breakpoint contents and size for this
1566 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1568 /* Update the final write buffer with this inserted
1569 breakpoint's INSN. */
1570 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1574 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1575 by replacing any memory breakpoints with their shadowed contents.
1577 If READBUF is not NULL, this buffer must not overlap with any of
1578 the breakpoint location's shadow_contents buffers. Otherwise,
1579 a failed assertion internal error will be raised.
1581 The range of shadowed area by each bp_location is:
1582 bl->address - bp_locations_placed_address_before_address_max
1583 up to bl->address + bp_locations_shadow_len_after_address_max
1584 The range we were requested to resolve shadows for is:
1585 memaddr ... memaddr + len
1586 Thus the safe cutoff boundaries for performance optimization are
1587 memaddr + len <= (bl->address
1588 - bp_locations_placed_address_before_address_max)
1590 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1593 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1594 const gdb_byte
*writebuf_org
,
1595 ULONGEST memaddr
, LONGEST len
)
1597 /* Left boundary, right boundary and median element of our binary
1599 unsigned bc_l
, bc_r
, bc
;
1601 /* Find BC_L which is a leftmost element which may affect BUF
1602 content. It is safe to report lower value but a failure to
1603 report higher one. */
1606 bc_r
= bp_locations
.size ();
1607 while (bc_l
+ 1 < bc_r
)
1609 struct bp_location
*bl
;
1611 bc
= (bc_l
+ bc_r
) / 2;
1612 bl
= bp_locations
[bc
];
1614 /* Check first BL->ADDRESS will not overflow due to the added
1615 constant. Then advance the left boundary only if we are sure
1616 the BC element can in no way affect the BUF content (MEMADDR
1617 to MEMADDR + LEN range).
1619 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1620 offset so that we cannot miss a breakpoint with its shadow
1621 range tail still reaching MEMADDR. */
1623 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1625 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1632 /* Due to the binary search above, we need to make sure we pick the
1633 first location that's at BC_L's address. E.g., if there are
1634 multiple locations at the same address, BC_L may end up pointing
1635 at a duplicate location, and miss the "master"/"inserted"
1636 location. Say, given locations L1, L2 and L3 at addresses A and
1639 L1@A, L2@A, L3@B, ...
1641 BC_L could end up pointing at location L2, while the "master"
1642 location could be L1. Since the `loc->inserted' flag is only set
1643 on "master" locations, we'd forget to restore the shadow of L1
1646 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1649 /* Now do full processing of the found relevant range of elements. */
1651 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1653 struct bp_location
*bl
= bp_locations
[bc
];
1655 /* bp_location array has BL->OWNER always non-NULL. */
1656 if (bl
->owner
->type
== bp_none
)
1657 warning (_("reading through apparently deleted breakpoint #%d?"),
1660 /* Performance optimization: any further element can no longer affect BUF
1663 if (bl
->address
>= bp_locations_placed_address_before_address_max
1666 - bp_locations_placed_address_before_address_max
)))
1669 if (!bp_location_has_shadow (bl
))
1672 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1673 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1677 /* See breakpoint.h. */
1680 is_breakpoint (const struct breakpoint
*bpt
)
1682 return (bpt
->type
== bp_breakpoint
1683 || bpt
->type
== bp_hardware_breakpoint
1684 || bpt
->type
== bp_dprintf
);
1687 /* Return true if BPT is of any hardware watchpoint kind. */
1690 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1692 return (bpt
->type
== bp_hardware_watchpoint
1693 || bpt
->type
== bp_read_watchpoint
1694 || bpt
->type
== bp_access_watchpoint
);
1697 /* See breakpoint.h. */
1700 is_watchpoint (const struct breakpoint
*bpt
)
1702 return (is_hardware_watchpoint (bpt
)
1703 || bpt
->type
== bp_watchpoint
);
1706 /* Returns true if the current thread and its running state are safe
1707 to evaluate or update watchpoint B. Watchpoints on local
1708 expressions need to be evaluated in the context of the thread that
1709 was current when the watchpoint was created, and, that thread needs
1710 to be stopped to be able to select the correct frame context.
1711 Watchpoints on global expressions can be evaluated on any thread,
1712 and in any state. It is presently left to the target allowing
1713 memory accesses when threads are running. */
1716 watchpoint_in_thread_scope (struct watchpoint
*b
)
1718 return (b
->pspace
== current_program_space
1719 && (b
->watchpoint_thread
== null_ptid
1720 || (inferior_ptid
== b
->watchpoint_thread
1721 && !inferior_thread ()->executing ())));
1724 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1725 associated bp_watchpoint_scope breakpoint. */
1728 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1730 if (w
->related_breakpoint
!= w
)
1732 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1733 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1734 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1735 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1736 w
->related_breakpoint
= w
;
1738 w
->disposition
= disp_del_at_next_stop
;
1741 /* Extract a bitfield value from value VAL using the bit parameters contained in
1744 static struct value
*
1745 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1747 struct value
*bit_val
;
1752 bit_val
= allocate_value (value_type (val
));
1754 unpack_value_bitfield (bit_val
,
1757 value_contents_for_printing (val
).data (),
1764 /* Allocate a dummy location and add it to B, which must be a software
1765 watchpoint. This is required because even if a software watchpoint
1766 is not watching any memory, bpstat_stop_status requires a location
1767 to be able to report stops. */
1770 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1771 struct program_space
*pspace
)
1773 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1775 b
->loc
= allocate_bp_location (b
);
1776 b
->loc
->pspace
= pspace
;
1777 b
->loc
->address
= -1;
1778 b
->loc
->length
= -1;
1781 /* Returns true if B is a software watchpoint that is not watching any
1782 memory (e.g., "watch $pc"). */
1785 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1787 return (b
->type
== bp_watchpoint
1789 && b
->loc
->next
== NULL
1790 && b
->loc
->address
== -1
1791 && b
->loc
->length
== -1);
1794 /* Assuming that B is a watchpoint:
1795 - Reparse watchpoint expression, if REPARSE is non-zero
1796 - Evaluate expression and store the result in B->val
1797 - Evaluate the condition if there is one, and store the result
1799 - Update the list of values that must be watched in B->loc.
1801 If the watchpoint disposition is disp_del_at_next_stop, then do
1802 nothing. If this is local watchpoint that is out of scope, delete
1805 Even with `set breakpoint always-inserted on' the watchpoints are
1806 removed + inserted on each stop here. Normal breakpoints must
1807 never be removed because they might be missed by a running thread
1808 when debugging in non-stop mode. On the other hand, hardware
1809 watchpoints (is_hardware_watchpoint; processed here) are specific
1810 to each LWP since they are stored in each LWP's hardware debug
1811 registers. Therefore, such LWP must be stopped first in order to
1812 be able to modify its hardware watchpoints.
1814 Hardware watchpoints must be reset exactly once after being
1815 presented to the user. It cannot be done sooner, because it would
1816 reset the data used to present the watchpoint hit to the user. And
1817 it must not be done later because it could display the same single
1818 watchpoint hit during multiple GDB stops. Note that the latter is
1819 relevant only to the hardware watchpoint types bp_read_watchpoint
1820 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1821 not user-visible - its hit is suppressed if the memory content has
1824 The following constraints influence the location where we can reset
1825 hardware watchpoints:
1827 * target_stopped_by_watchpoint and target_stopped_data_address are
1828 called several times when GDB stops.
1831 * Multiple hardware watchpoints can be hit at the same time,
1832 causing GDB to stop. GDB only presents one hardware watchpoint
1833 hit at a time as the reason for stopping, and all the other hits
1834 are presented later, one after the other, each time the user
1835 requests the execution to be resumed. Execution is not resumed
1836 for the threads still having pending hit event stored in
1837 LWP_INFO->STATUS. While the watchpoint is already removed from
1838 the inferior on the first stop the thread hit event is kept being
1839 reported from its cached value by linux_nat_stopped_data_address
1840 until the real thread resume happens after the watchpoint gets
1841 presented and thus its LWP_INFO->STATUS gets reset.
1843 Therefore the hardware watchpoint hit can get safely reset on the
1844 watchpoint removal from inferior. */
1847 update_watchpoint (struct watchpoint
*b
, int reparse
)
1849 int within_current_scope
;
1850 struct frame_id saved_frame_id
;
1853 /* If this is a local watchpoint, we only want to check if the
1854 watchpoint frame is in scope if the current thread is the thread
1855 that was used to create the watchpoint. */
1856 if (!watchpoint_in_thread_scope (b
))
1859 if (b
->disposition
== disp_del_at_next_stop
)
1864 /* Determine if the watchpoint is within scope. */
1865 if (b
->exp_valid_block
== NULL
)
1866 within_current_scope
= 1;
1869 struct frame_info
*fi
= get_current_frame ();
1870 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1871 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1873 /* If we're at a point where the stack has been destroyed
1874 (e.g. in a function epilogue), unwinding may not work
1875 properly. Do not attempt to recreate locations at this
1876 point. See similar comments in watchpoint_check. */
1877 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1880 /* Save the current frame's ID so we can restore it after
1881 evaluating the watchpoint expression on its own frame. */
1882 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1883 took a frame parameter, so that we didn't have to change the
1886 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1888 fi
= frame_find_by_id (b
->watchpoint_frame
);
1889 within_current_scope
= (fi
!= NULL
);
1890 if (within_current_scope
)
1894 /* We don't free locations. They are stored in the bp_location array
1895 and update_global_location_list will eventually delete them and
1896 remove breakpoints if needed. */
1899 if (within_current_scope
&& reparse
)
1904 s
= (b
->exp_string_reparse
1905 ? b
->exp_string_reparse
.get ()
1906 : b
->exp_string
.get ());
1907 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1908 /* If the meaning of expression itself changed, the old value is
1909 no longer relevant. We don't want to report a watchpoint hit
1910 to the user when the old value and the new value may actually
1911 be completely different objects. */
1913 b
->val_valid
= false;
1915 /* Note that unlike with breakpoints, the watchpoint's condition
1916 expression is stored in the breakpoint object, not in the
1917 locations (re)created below. */
1918 if (b
->cond_string
!= NULL
)
1920 b
->cond_exp
.reset ();
1922 s
= b
->cond_string
.get ();
1923 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1927 /* If we failed to parse the expression, for example because
1928 it refers to a global variable in a not-yet-loaded shared library,
1929 don't try to insert watchpoint. We don't automatically delete
1930 such watchpoint, though, since failure to parse expression
1931 is different from out-of-scope watchpoint. */
1932 if (!target_has_execution ())
1934 /* Without execution, memory can't change. No use to try and
1935 set watchpoint locations. The watchpoint will be reset when
1936 the target gains execution, through breakpoint_re_set. */
1937 if (!can_use_hw_watchpoints
)
1939 if (b
->ops
->works_in_software_mode (b
))
1940 b
->type
= bp_watchpoint
;
1942 error (_("Can't set read/access watchpoint when "
1943 "hardware watchpoints are disabled."));
1946 else if (within_current_scope
&& b
->exp
)
1948 std::vector
<value_ref_ptr
> val_chain
;
1949 struct value
*v
, *result
;
1950 struct program_space
*frame_pspace
;
1952 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
1955 /* Avoid setting b->val if it's already set. The meaning of
1956 b->val is 'the last value' user saw, and we should update
1957 it only if we reported that last value to user. As it
1958 happens, the code that reports it updates b->val directly.
1959 We don't keep track of the memory value for masked
1961 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1963 if (b
->val_bitsize
!= 0)
1964 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1965 b
->val
= release_value (v
);
1966 b
->val_valid
= true;
1969 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1971 /* Look at each value on the value chain. */
1972 gdb_assert (!val_chain
.empty ());
1973 for (const value_ref_ptr
&iter
: val_chain
)
1977 /* If it's a memory location, and GDB actually needed
1978 its contents to evaluate the expression, then we
1979 must watch it. If the first value returned is
1980 still lazy, that means an error occurred reading it;
1981 watch it anyway in case it becomes readable. */
1982 if (VALUE_LVAL (v
) == lval_memory
1983 && (v
== val_chain
[0] || ! value_lazy (v
)))
1985 struct type
*vtype
= check_typedef (value_type (v
));
1987 /* We only watch structs and arrays if user asked
1988 for it explicitly, never if they just happen to
1989 appear in the middle of some value chain. */
1991 || (vtype
->code () != TYPE_CODE_STRUCT
1992 && vtype
->code () != TYPE_CODE_ARRAY
))
1995 enum target_hw_bp_type type
;
1996 struct bp_location
*loc
, **tmp
;
1997 int bitpos
= 0, bitsize
= 0;
1999 if (value_bitsize (v
) != 0)
2001 /* Extract the bit parameters out from the bitfield
2003 bitpos
= value_bitpos (v
);
2004 bitsize
= value_bitsize (v
);
2006 else if (v
== result
&& b
->val_bitsize
!= 0)
2008 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2009 lvalue whose bit parameters are saved in the fields
2010 VAL_BITPOS and VAL_BITSIZE. */
2011 bitpos
= b
->val_bitpos
;
2012 bitsize
= b
->val_bitsize
;
2015 addr
= value_address (v
);
2018 /* Skip the bytes that don't contain the bitfield. */
2023 if (b
->type
== bp_read_watchpoint
)
2025 else if (b
->type
== bp_access_watchpoint
)
2028 loc
= allocate_bp_location (b
);
2029 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2032 loc
->gdbarch
= value_type (v
)->arch ();
2034 loc
->pspace
= frame_pspace
;
2035 loc
->address
= address_significant (loc
->gdbarch
, addr
);
2039 /* Just cover the bytes that make up the bitfield. */
2040 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2043 loc
->length
= TYPE_LENGTH (value_type (v
));
2045 loc
->watchpoint_type
= type
;
2050 /* Change the type of breakpoint between hardware assisted or
2051 an ordinary watchpoint depending on the hardware support
2052 and free hardware slots. REPARSE is set when the inferior
2057 enum bp_loc_type loc_type
;
2059 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2063 int i
, target_resources_ok
, other_type_used
;
2066 /* Use an exact watchpoint when there's only one memory region to be
2067 watched, and only one debug register is needed to watch it. */
2068 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2070 /* We need to determine how many resources are already
2071 used for all other hardware watchpoints plus this one
2072 to see if we still have enough resources to also fit
2073 this watchpoint in as well. */
2075 /* If this is a software watchpoint, we try to turn it
2076 to a hardware one -- count resources as if B was of
2077 hardware watchpoint type. */
2079 if (type
== bp_watchpoint
)
2080 type
= bp_hardware_watchpoint
;
2082 /* This watchpoint may or may not have been placed on
2083 the list yet at this point (it won't be in the list
2084 if we're trying to create it for the first time,
2085 through watch_command), so always account for it
2088 /* Count resources used by all watchpoints except B. */
2089 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2091 /* Add in the resources needed for B. */
2092 i
+= hw_watchpoint_use_count (b
);
2095 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2096 if (target_resources_ok
<= 0)
2098 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2100 if (target_resources_ok
== 0 && !sw_mode
)
2101 error (_("Target does not support this type of "
2102 "hardware watchpoint."));
2103 else if (target_resources_ok
< 0 && !sw_mode
)
2104 error (_("There are not enough available hardware "
2105 "resources for this watchpoint."));
2107 /* Downgrade to software watchpoint. */
2108 b
->type
= bp_watchpoint
;
2112 /* If this was a software watchpoint, we've just
2113 found we have enough resources to turn it to a
2114 hardware watchpoint. Otherwise, this is a
2119 else if (!b
->ops
->works_in_software_mode (b
))
2121 if (!can_use_hw_watchpoints
)
2122 error (_("Can't set read/access watchpoint when "
2123 "hardware watchpoints are disabled."));
2125 error (_("Expression cannot be implemented with "
2126 "read/access watchpoint."));
2129 b
->type
= bp_watchpoint
;
2131 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2132 : bp_loc_hardware_watchpoint
);
2133 for (bp_location
*bl
: b
->locations ())
2134 bl
->loc_type
= loc_type
;
2137 /* If a software watchpoint is not watching any memory, then the
2138 above left it without any location set up. But,
2139 bpstat_stop_status requires a location to be able to report
2140 stops, so make sure there's at least a dummy one. */
2141 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2142 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2144 else if (!within_current_scope
)
2147 Watchpoint %d deleted because the program has left the block\n\
2148 in which its expression is valid.\n"),
2150 watchpoint_del_at_next_stop (b
);
2153 /* Restore the selected frame. */
2155 select_frame (frame_find_by_id (saved_frame_id
));
2159 /* Returns 1 iff breakpoint location should be
2160 inserted in the inferior. We don't differentiate the type of BL's owner
2161 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2162 breakpoint_ops is not defined, because in insert_bp_location,
2163 tracepoint's insert_location will not be called. */
2165 should_be_inserted (struct bp_location
*bl
)
2167 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2170 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2173 if (!bl
->enabled
|| bl
->disabled_by_cond
2174 || bl
->shlib_disabled
|| bl
->duplicate
)
2177 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2180 /* This is set for example, when we're attached to the parent of a
2181 vfork, and have detached from the child. The child is running
2182 free, and we expect it to do an exec or exit, at which point the
2183 OS makes the parent schedulable again (and the target reports
2184 that the vfork is done). Until the child is done with the shared
2185 memory region, do not insert breakpoints in the parent, otherwise
2186 the child could still trip on the parent's breakpoints. Since
2187 the parent is blocked anyway, it won't miss any breakpoint. */
2188 if (bl
->pspace
->breakpoints_not_allowed
)
2191 /* Don't insert a breakpoint if we're trying to step past its
2192 location, except if the breakpoint is a single-step breakpoint,
2193 and the breakpoint's thread is the thread which is stepping past
2195 if ((bl
->loc_type
== bp_loc_software_breakpoint
2196 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2197 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2199 /* The single-step breakpoint may be inserted at the location
2200 we're trying to step if the instruction branches to itself.
2201 However, the instruction won't be executed at all and it may
2202 break the semantics of the instruction, for example, the
2203 instruction is a conditional branch or updates some flags.
2204 We can't fix it unless GDB is able to emulate the instruction
2205 or switch to displaced stepping. */
2206 && !(bl
->owner
->type
== bp_single_step
2207 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2209 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2210 paddress (bl
->gdbarch
, bl
->address
));
2214 /* Don't insert watchpoints if we're trying to step past the
2215 instruction that triggered one. */
2216 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2217 && stepping_past_nonsteppable_watchpoint ())
2219 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2220 "skipping watchpoint at %s:%d",
2221 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2228 /* Same as should_be_inserted but does the check assuming
2229 that the location is not duplicated. */
2232 unduplicated_should_be_inserted (struct bp_location
*bl
)
2235 const int save_duplicate
= bl
->duplicate
;
2238 result
= should_be_inserted (bl
);
2239 bl
->duplicate
= save_duplicate
;
2243 /* Parses a conditional described by an expression COND into an
2244 agent expression bytecode suitable for evaluation
2245 by the bytecode interpreter. Return NULL if there was
2246 any error during parsing. */
2248 static agent_expr_up
2249 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2254 agent_expr_up aexpr
;
2256 /* We don't want to stop processing, so catch any errors
2257 that may show up. */
2260 aexpr
= gen_eval_for_expr (scope
, cond
);
2263 catch (const gdb_exception_error
&ex
)
2265 /* If we got here, it means the condition could not be parsed to a valid
2266 bytecode expression and thus can't be evaluated on the target's side.
2267 It's no use iterating through the conditions. */
2270 /* We have a valid agent expression. */
2274 /* Based on location BL, create a list of breakpoint conditions to be
2275 passed on to the target. If we have duplicated locations with different
2276 conditions, we will add such conditions to the list. The idea is that the
2277 target will evaluate the list of conditions and will only notify GDB when
2278 one of them is true. */
2281 build_target_condition_list (struct bp_location
*bl
)
2283 int null_condition_or_parse_error
= 0;
2284 int modified
= bl
->needs_update
;
2286 /* Release conditions left over from a previous insert. */
2287 bl
->target_info
.conditions
.clear ();
2289 /* This is only meaningful if the target is
2290 evaluating conditions and if the user has
2291 opted for condition evaluation on the target's
2293 if (gdb_evaluates_breakpoint_condition_p ()
2294 || !target_supports_evaluation_of_breakpoint_conditions ())
2297 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2299 /* Do a first pass to check for locations with no assigned
2300 conditions or conditions that fail to parse to a valid agent
2301 expression bytecode. If any of these happen, then it's no use to
2302 send conditions to the target since this location will always
2303 trigger and generate a response back to GDB. Note we consider
2304 all locations at the same address irrespective of type, i.e.,
2305 even if the locations aren't considered duplicates (e.g.,
2306 software breakpoint and hardware breakpoint at the same
2308 for (bp_location
*loc
: loc_range
)
2310 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2314 /* Re-parse the conditions since something changed. In that
2315 case we already freed the condition bytecodes (see
2316 force_breakpoint_reinsertion). We just
2317 need to parse the condition to bytecodes again. */
2318 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2322 /* If we have a NULL bytecode expression, it means something
2323 went wrong or we have a null condition expression. */
2324 if (!loc
->cond_bytecode
)
2326 null_condition_or_parse_error
= 1;
2332 /* If any of these happened, it means we will have to evaluate the conditions
2333 for the location's address on gdb's side. It is no use keeping bytecodes
2334 for all the other duplicate locations, thus we free all of them here.
2336 This is so we have a finer control over which locations' conditions are
2337 being evaluated by GDB or the remote stub. */
2338 if (null_condition_or_parse_error
)
2340 for (bp_location
*loc
: loc_range
)
2342 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2344 /* Only go as far as the first NULL bytecode is
2346 if (!loc
->cond_bytecode
)
2349 loc
->cond_bytecode
.reset ();
2354 /* No NULL conditions or failed bytecode generation. Build a
2355 condition list for this location's address. If we have software
2356 and hardware locations at the same address, they aren't
2357 considered duplicates, but we still marge all the conditions
2358 anyway, as it's simpler, and doesn't really make a practical
2360 for (bp_location
*loc
: loc_range
)
2362 && is_breakpoint (loc
->owner
)
2363 && loc
->pspace
->num
== bl
->pspace
->num
2364 && loc
->owner
->enable_state
== bp_enabled
2366 && !loc
->disabled_by_cond
)
2368 /* Add the condition to the vector. This will be used later
2369 to send the conditions to the target. */
2370 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2376 /* Parses a command described by string CMD into an agent expression
2377 bytecode suitable for evaluation by the bytecode interpreter.
2378 Return NULL if there was any error during parsing. */
2380 static agent_expr_up
2381 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2383 const char *cmdrest
;
2384 const char *format_start
, *format_end
;
2385 struct gdbarch
*gdbarch
= get_current_arch ();
2392 if (*cmdrest
== ',')
2394 cmdrest
= skip_spaces (cmdrest
);
2396 if (*cmdrest
++ != '"')
2397 error (_("No format string following the location"));
2399 format_start
= cmdrest
;
2401 format_pieces
fpieces (&cmdrest
);
2403 format_end
= cmdrest
;
2405 if (*cmdrest
++ != '"')
2406 error (_("Bad format string, non-terminated '\"'."));
2408 cmdrest
= skip_spaces (cmdrest
);
2410 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2411 error (_("Invalid argument syntax"));
2413 if (*cmdrest
== ',')
2415 cmdrest
= skip_spaces (cmdrest
);
2417 /* For each argument, make an expression. */
2419 std::vector
<struct expression
*> argvec
;
2420 while (*cmdrest
!= '\0')
2425 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2426 argvec
.push_back (expr
.release ());
2428 if (*cmdrest
== ',')
2432 agent_expr_up aexpr
;
2434 /* We don't want to stop processing, so catch any errors
2435 that may show up. */
2438 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2439 format_start
, format_end
- format_start
,
2440 argvec
.size (), argvec
.data ());
2442 catch (const gdb_exception_error
&ex
)
2444 /* If we got here, it means the command could not be parsed to a valid
2445 bytecode expression and thus can't be evaluated on the target's side.
2446 It's no use iterating through the other commands. */
2449 /* We have a valid agent expression, return it. */
2453 /* Based on location BL, create a list of breakpoint commands to be
2454 passed on to the target. If we have duplicated locations with
2455 different commands, we will add any such to the list. */
2458 build_target_command_list (struct bp_location
*bl
)
2460 int null_command_or_parse_error
= 0;
2461 int modified
= bl
->needs_update
;
2463 /* Clear commands left over from a previous insert. */
2464 bl
->target_info
.tcommands
.clear ();
2466 if (!target_can_run_breakpoint_commands ())
2469 /* For now, limit to agent-style dprintf breakpoints. */
2470 if (dprintf_style
!= dprintf_style_agent
)
2473 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2475 /* For now, if we have any location at the same address that isn't a
2476 dprintf, don't install the target-side commands, as that would
2477 make the breakpoint not be reported to the core, and we'd lose
2479 for (bp_location
*loc
: loc_range
)
2480 if (is_breakpoint (loc
->owner
)
2481 && loc
->pspace
->num
== bl
->pspace
->num
2482 && loc
->owner
->type
!= bp_dprintf
)
2485 /* Do a first pass to check for locations with no assigned
2486 conditions or conditions that fail to parse to a valid agent expression
2487 bytecode. If any of these happen, then it's no use to send conditions
2488 to the target since this location will always trigger and generate a
2489 response back to GDB. */
2490 for (bp_location
*loc
: loc_range
)
2492 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2496 /* Re-parse the commands since something changed. In that
2497 case we already freed the command bytecodes (see
2498 force_breakpoint_reinsertion). We just
2499 need to parse the command to bytecodes again. */
2501 = parse_cmd_to_aexpr (bl
->address
,
2502 loc
->owner
->extra_string
.get ());
2505 /* If we have a NULL bytecode expression, it means something
2506 went wrong or we have a null command expression. */
2507 if (!loc
->cmd_bytecode
)
2509 null_command_or_parse_error
= 1;
2515 /* If anything failed, then we're not doing target-side commands,
2517 if (null_command_or_parse_error
)
2519 for (bp_location
*loc
: loc_range
)
2520 if (is_breakpoint (loc
->owner
)
2521 && loc
->pspace
->num
== bl
->pspace
->num
)
2523 /* Only go as far as the first NULL bytecode is
2525 if (loc
->cmd_bytecode
== NULL
)
2528 loc
->cmd_bytecode
.reset ();
2532 /* No NULL commands or failed bytecode generation. Build a command
2533 list for all duplicate locations at this location's address.
2534 Note that here we must care for whether the breakpoint location
2535 types are considered duplicates, otherwise, say, if we have a
2536 software and hardware location at the same address, the target
2537 could end up running the commands twice. For the moment, we only
2538 support targets-side commands with dprintf, but it doesn't hurt
2539 to be pedantically correct in case that changes. */
2540 for (bp_location
*loc
: loc_range
)
2541 if (breakpoint_locations_match (bl
, loc
)
2542 && loc
->owner
->extra_string
2543 && is_breakpoint (loc
->owner
)
2544 && loc
->pspace
->num
== bl
->pspace
->num
2545 && loc
->owner
->enable_state
== bp_enabled
2547 && !loc
->disabled_by_cond
)
2549 /* Add the command to the vector. This will be used later
2550 to send the commands to the target. */
2551 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2554 bl
->target_info
.persist
= 0;
2555 /* Maybe flag this location as persistent. */
2556 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2557 bl
->target_info
.persist
= 1;
2560 /* Return the kind of breakpoint on address *ADDR. Get the kind
2561 of breakpoint according to ADDR except single-step breakpoint.
2562 Get the kind of single-step breakpoint according to the current
2566 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2568 if (bl
->owner
->type
== bp_single_step
)
2570 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2571 struct regcache
*regcache
;
2573 regcache
= get_thread_regcache (thr
);
2575 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2579 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2582 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2583 location. Any error messages are printed to TMP_ERROR_STREAM; and
2584 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2585 Returns 0 for success, 1 if the bp_location type is not supported or
2588 NOTE drow/2003-09-09: This routine could be broken down to an
2589 object-style method for each breakpoint or catchpoint type. */
2591 insert_bp_location (struct bp_location
*bl
,
2592 struct ui_file
*tmp_error_stream
,
2593 int *disabled_breaks
,
2594 int *hw_breakpoint_error
,
2595 int *hw_bp_error_explained_already
)
2597 gdb_exception bp_excpt
;
2599 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2602 /* Note we don't initialize bl->target_info, as that wipes out
2603 the breakpoint location's shadow_contents if the breakpoint
2604 is still inserted at that location. This in turn breaks
2605 target_read_memory which depends on these buffers when
2606 a memory read is requested at the breakpoint location:
2607 Once the target_info has been wiped, we fail to see that
2608 we have a breakpoint inserted at that address and thus
2609 read the breakpoint instead of returning the data saved in
2610 the breakpoint location's shadow contents. */
2611 bl
->target_info
.reqstd_address
= bl
->address
;
2612 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2613 bl
->target_info
.length
= bl
->length
;
2615 /* When working with target-side conditions, we must pass all the conditions
2616 for the same breakpoint address down to the target since GDB will not
2617 insert those locations. With a list of breakpoint conditions, the target
2618 can decide when to stop and notify GDB. */
2620 if (is_breakpoint (bl
->owner
))
2622 build_target_condition_list (bl
);
2623 build_target_command_list (bl
);
2624 /* Reset the modification marker. */
2625 bl
->needs_update
= 0;
2628 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2629 set at a read-only address, then a breakpoint location will have
2630 been changed to hardware breakpoint before we get here. If it is
2631 "off" however, error out before actually trying to insert the
2632 breakpoint, with a nicer error message. */
2633 if (bl
->loc_type
== bp_loc_software_breakpoint
2634 && !automatic_hardware_breakpoints
)
2636 mem_region
*mr
= lookup_mem_region (bl
->address
);
2638 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2640 gdb_printf (tmp_error_stream
,
2641 _("Cannot insert breakpoint %d.\n"
2642 "Cannot set software breakpoint "
2643 "at read-only address %s\n"),
2645 paddress (bl
->gdbarch
, bl
->address
));
2650 if (bl
->loc_type
== bp_loc_software_breakpoint
2651 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2653 /* First check to see if we have to handle an overlay. */
2654 if (overlay_debugging
== ovly_off
2655 || bl
->section
== NULL
2656 || !(section_is_overlay (bl
->section
)))
2658 /* No overlay handling: just set the breakpoint. */
2663 val
= bl
->owner
->ops
->insert_location (bl
);
2665 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2667 catch (gdb_exception
&e
)
2669 bp_excpt
= std::move (e
);
2674 /* This breakpoint is in an overlay section.
2675 Shall we set a breakpoint at the LMA? */
2676 if (!overlay_events_enabled
)
2678 /* Yes -- overlay event support is not active,
2679 so we must try to set a breakpoint at the LMA.
2680 This will not work for a hardware breakpoint. */
2681 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2682 warning (_("hardware breakpoint %d not supported in overlay!"),
2686 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2688 /* Set a software (trap) breakpoint at the LMA. */
2689 bl
->overlay_target_info
= bl
->target_info
;
2690 bl
->overlay_target_info
.reqstd_address
= addr
;
2692 /* No overlay handling: just set the breakpoint. */
2697 bl
->overlay_target_info
.kind
2698 = breakpoint_kind (bl
, &addr
);
2699 bl
->overlay_target_info
.placed_address
= addr
;
2700 val
= target_insert_breakpoint (bl
->gdbarch
,
2701 &bl
->overlay_target_info
);
2704 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2706 catch (gdb_exception
&e
)
2708 bp_excpt
= std::move (e
);
2711 if (bp_excpt
.reason
!= 0)
2712 gdb_printf (tmp_error_stream
,
2713 "Overlay breakpoint %d "
2714 "failed: in ROM?\n",
2718 /* Shall we set a breakpoint at the VMA? */
2719 if (section_is_mapped (bl
->section
))
2721 /* Yes. This overlay section is mapped into memory. */
2726 val
= bl
->owner
->ops
->insert_location (bl
);
2728 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2730 catch (gdb_exception
&e
)
2732 bp_excpt
= std::move (e
);
2737 /* No. This breakpoint will not be inserted.
2738 No error, but do not mark the bp as 'inserted'. */
2743 if (bp_excpt
.reason
!= 0)
2745 /* Can't set the breakpoint. */
2747 /* If the target has closed then it will have deleted any
2748 breakpoints inserted within the target inferior, as a result
2749 any further attempts to interact with the breakpoint objects
2750 is not possible. Just rethrow the error. */
2751 if (bp_excpt
.error
== TARGET_CLOSE_ERROR
)
2753 gdb_assert (bl
->owner
!= nullptr);
2755 /* In some cases, we might not be able to insert a
2756 breakpoint in a shared library that has already been
2757 removed, but we have not yet processed the shlib unload
2758 event. Unfortunately, some targets that implement
2759 breakpoint insertion themselves can't tell why the
2760 breakpoint insertion failed (e.g., the remote target
2761 doesn't define error codes), so we must treat generic
2762 errors as memory errors. */
2763 if (bp_excpt
.reason
== RETURN_ERROR
2764 && (bp_excpt
.error
== GENERIC_ERROR
2765 || bp_excpt
.error
== MEMORY_ERROR
)
2766 && bl
->loc_type
== bp_loc_software_breakpoint
2767 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2768 || shared_objfile_contains_address_p (bl
->pspace
,
2771 /* See also: disable_breakpoints_in_shlibs. */
2772 bl
->shlib_disabled
= 1;
2773 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2774 if (!*disabled_breaks
)
2776 gdb_printf (tmp_error_stream
,
2777 "Cannot insert breakpoint %d.\n",
2779 gdb_printf (tmp_error_stream
,
2780 "Temporarily disabling shared "
2781 "library breakpoints:\n");
2783 *disabled_breaks
= 1;
2784 gdb_printf (tmp_error_stream
,
2785 "breakpoint #%d\n", bl
->owner
->number
);
2790 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2792 *hw_breakpoint_error
= 1;
2793 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2794 gdb_printf (tmp_error_stream
,
2795 "Cannot insert hardware breakpoint %d%s",
2797 bp_excpt
.message
? ":" : ".\n");
2798 if (bp_excpt
.message
!= NULL
)
2799 gdb_printf (tmp_error_stream
, "%s.\n",
2804 if (bp_excpt
.message
== NULL
)
2807 = memory_error_message (TARGET_XFER_E_IO
,
2808 bl
->gdbarch
, bl
->address
);
2810 gdb_printf (tmp_error_stream
,
2811 "Cannot insert breakpoint %d.\n"
2813 bl
->owner
->number
, message
.c_str ());
2817 gdb_printf (tmp_error_stream
,
2818 "Cannot insert breakpoint %d: %s\n",
2833 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2834 /* NOTE drow/2003-09-08: This state only exists for removing
2835 watchpoints. It's not clear that it's necessary... */
2836 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2840 gdb_assert (bl
->owner
->ops
!= NULL
2841 && bl
->owner
->ops
->insert_location
!= NULL
);
2843 val
= bl
->owner
->ops
->insert_location (bl
);
2845 /* If trying to set a read-watchpoint, and it turns out it's not
2846 supported, try emulating one with an access watchpoint. */
2847 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2849 /* But don't try to insert it, if there's already another
2850 hw_access location that would be considered a duplicate
2852 for (bp_location
*loc
: all_bp_locations ())
2854 && loc
->watchpoint_type
== hw_access
2855 && watchpoint_locations_match (bl
, loc
))
2859 bl
->target_info
= loc
->target_info
;
2860 bl
->watchpoint_type
= hw_access
;
2867 bl
->watchpoint_type
= hw_access
;
2868 val
= bl
->owner
->ops
->insert_location (bl
);
2871 /* Back to the original value. */
2872 bl
->watchpoint_type
= hw_read
;
2876 bl
->inserted
= (val
== 0);
2879 else if (bl
->owner
->type
== bp_catchpoint
)
2883 gdb_assert (bl
->owner
->ops
!= NULL
2884 && bl
->owner
->ops
->insert_location
!= NULL
);
2886 val
= bl
->owner
->ops
->insert_location (bl
);
2889 bl
->owner
->enable_state
= bp_disabled
;
2893 Error inserting catchpoint %d: Your system does not support this type\n\
2894 of catchpoint."), bl
->owner
->number
);
2896 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2899 bl
->inserted
= (val
== 0);
2901 /* We've already printed an error message if there was a problem
2902 inserting this catchpoint, and we've disabled the catchpoint,
2903 so just return success. */
2910 /* This function is called when program space PSPACE is about to be
2911 deleted. It takes care of updating breakpoints to not reference
2915 breakpoint_program_space_exit (struct program_space
*pspace
)
2917 /* Remove any breakpoint that was set through this program space. */
2918 for (breakpoint
*b
: all_breakpoints_safe ())
2919 if (b
->pspace
== pspace
)
2920 delete_breakpoint (b
);
2922 /* Breakpoints set through other program spaces could have locations
2923 bound to PSPACE as well. Remove those. */
2924 for (bp_location
*loc
: all_bp_locations ())
2926 struct bp_location
*tmp
;
2928 if (loc
->pspace
== pspace
)
2930 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2931 if (loc
->owner
->loc
== loc
)
2932 loc
->owner
->loc
= loc
->next
;
2934 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2935 if (tmp
->next
== loc
)
2937 tmp
->next
= loc
->next
;
2943 /* Now update the global location list to permanently delete the
2944 removed locations above. */
2945 update_global_location_list (UGLL_DONT_INSERT
);
2948 /* Make sure all breakpoints are inserted in inferior.
2949 Throws exception on any error.
2950 A breakpoint that is already inserted won't be inserted
2951 again, so calling this function twice is safe. */
2953 insert_breakpoints (void)
2955 for (breakpoint
*bpt
: all_breakpoints ())
2956 if (is_hardware_watchpoint (bpt
))
2958 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2960 update_watchpoint (w
, 0 /* don't reparse. */);
2963 /* Updating watchpoints creates new locations, so update the global
2964 location list. Explicitly tell ugll to insert locations and
2965 ignore breakpoints_always_inserted_mode. Also,
2966 update_global_location_list tries to "upgrade" software
2967 breakpoints to hardware breakpoints to handle "set breakpoint
2968 auto-hw", so we need to call it even if we don't have new
2970 update_global_location_list (UGLL_INSERT
);
2973 /* This is used when we need to synch breakpoint conditions between GDB and the
2974 target. It is the case with deleting and disabling of breakpoints when using
2975 always-inserted mode. */
2978 update_inserted_breakpoint_locations (void)
2982 int disabled_breaks
= 0;
2983 int hw_breakpoint_error
= 0;
2984 int hw_bp_details_reported
= 0;
2986 string_file tmp_error_stream
;
2988 /* Explicitly mark the warning -- this will only be printed if
2989 there was an error. */
2990 tmp_error_stream
.puts ("Warning:\n");
2992 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2994 for (bp_location
*bl
: all_bp_locations ())
2996 /* We only want to update software breakpoints and hardware
2998 if (!is_breakpoint (bl
->owner
))
3001 /* We only want to update locations that are already inserted
3002 and need updating. This is to avoid unwanted insertion during
3003 deletion of breakpoints. */
3004 if (!bl
->inserted
|| !bl
->needs_update
)
3007 switch_to_program_space_and_thread (bl
->pspace
);
3009 /* For targets that support global breakpoints, there's no need
3010 to select an inferior to insert breakpoint to. In fact, even
3011 if we aren't attached to any process yet, we should still
3012 insert breakpoints. */
3013 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3014 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3017 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3018 &hw_breakpoint_error
, &hw_bp_details_reported
);
3025 target_terminal::ours_for_output ();
3026 error_stream (tmp_error_stream
);
3030 /* Used when starting or continuing the program. */
3033 insert_breakpoint_locations (void)
3037 int disabled_breaks
= 0;
3038 int hw_breakpoint_error
= 0;
3039 int hw_bp_error_explained_already
= 0;
3041 string_file tmp_error_stream
;
3043 /* Explicitly mark the warning -- this will only be printed if
3044 there was an error. */
3045 tmp_error_stream
.puts ("Warning:\n");
3047 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3049 for (bp_location
*bl
: all_bp_locations ())
3051 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3054 /* There is no point inserting thread-specific breakpoints if
3055 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3056 has BL->OWNER always non-NULL. */
3057 if (bl
->owner
->thread
!= -1
3058 && !valid_global_thread_id (bl
->owner
->thread
))
3061 switch_to_program_space_and_thread (bl
->pspace
);
3063 /* For targets that support global breakpoints, there's no need
3064 to select an inferior to insert breakpoint to. In fact, even
3065 if we aren't attached to any process yet, we should still
3066 insert breakpoints. */
3067 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3068 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3071 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3072 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3077 /* If we failed to insert all locations of a watchpoint, remove
3078 them, as half-inserted watchpoint is of limited use. */
3079 for (breakpoint
*bpt
: all_breakpoints ())
3081 int some_failed
= 0;
3083 if (!is_hardware_watchpoint (bpt
))
3086 if (!breakpoint_enabled (bpt
))
3089 if (bpt
->disposition
== disp_del_at_next_stop
)
3092 for (bp_location
*loc
: bpt
->locations ())
3093 if (!loc
->inserted
&& should_be_inserted (loc
))
3101 for (bp_location
*loc
: bpt
->locations ())
3103 remove_breakpoint (loc
);
3105 hw_breakpoint_error
= 1;
3106 tmp_error_stream
.printf ("Could not insert "
3107 "hardware watchpoint %d.\n",
3115 /* If a hardware breakpoint or watchpoint was inserted, add a
3116 message about possibly exhausted resources. */
3117 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3119 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3120 You may have requested too many hardware breakpoints/watchpoints.\n");
3122 target_terminal::ours_for_output ();
3123 error_stream (tmp_error_stream
);
3127 /* Used when the program stops.
3128 Returns zero if successful, or non-zero if there was a problem
3129 removing a breakpoint location. */
3132 remove_breakpoints (void)
3136 for (bp_location
*bl
: all_bp_locations ())
3137 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3138 val
|= remove_breakpoint (bl
);
3143 /* When a thread exits, remove breakpoints that are related to
3147 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3149 for (breakpoint
*b
: all_breakpoints_safe ())
3151 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3153 b
->disposition
= disp_del_at_next_stop
;
3156 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3157 b
->number
, print_thread_id (tp
));
3159 /* Hide it from the user. */
3165 /* See breakpoint.h. */
3168 remove_breakpoints_inf (inferior
*inf
)
3172 for (bp_location
*bl
: all_bp_locations ())
3174 if (bl
->pspace
!= inf
->pspace
)
3177 if (bl
->inserted
&& !bl
->target_info
.persist
)
3179 val
= remove_breakpoint (bl
);
3186 static int internal_breakpoint_number
= -1;
3188 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3189 If INTERNAL is non-zero, the breakpoint number will be populated
3190 from internal_breakpoint_number and that variable decremented.
3191 Otherwise the breakpoint number will be populated from
3192 breakpoint_count and that value incremented. Internal breakpoints
3193 do not set the internal var bpnum. */
3195 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3198 b
->number
= internal_breakpoint_number
--;
3201 set_breakpoint_count (breakpoint_count
+ 1);
3202 b
->number
= breakpoint_count
;
3206 static struct breakpoint
*
3207 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3208 CORE_ADDR address
, enum bptype type
,
3209 const struct breakpoint_ops
*ops
)
3211 symtab_and_line sal
;
3213 sal
.section
= find_pc_overlay (sal
.pc
);
3214 sal
.pspace
= current_program_space
;
3216 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3217 b
->number
= internal_breakpoint_number
--;
3218 b
->disposition
= disp_donttouch
;
3223 static const char *const longjmp_names
[] =
3225 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3227 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3229 /* Per-objfile data private to breakpoint.c. */
3230 struct breakpoint_objfile_data
3232 /* Minimal symbol for "_ovly_debug_event" (if any). */
3233 struct bound_minimal_symbol overlay_msym
;
3235 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3236 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3238 /* True if we have looked for longjmp probes. */
3239 int longjmp_searched
= 0;
3241 /* SystemTap probe points for longjmp (if any). These are non-owning
3243 std::vector
<probe
*> longjmp_probes
;
3245 /* Minimal symbol for "std::terminate()" (if any). */
3246 struct bound_minimal_symbol terminate_msym
;
3248 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3249 struct bound_minimal_symbol exception_msym
;
3251 /* True if we have looked for exception probes. */
3252 int exception_searched
= 0;
3254 /* SystemTap probe points for unwinding (if any). These are non-owning
3256 std::vector
<probe
*> exception_probes
;
3259 static const struct objfile_key
<breakpoint_objfile_data
>
3260 breakpoint_objfile_key
;
3262 /* Minimal symbol not found sentinel. */
3263 static struct minimal_symbol msym_not_found
;
3265 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3268 msym_not_found_p (const struct minimal_symbol
*msym
)
3270 return msym
== &msym_not_found
;
3273 /* Return per-objfile data needed by breakpoint.c.
3274 Allocate the data if necessary. */
3276 static struct breakpoint_objfile_data
*
3277 get_breakpoint_objfile_data (struct objfile
*objfile
)
3279 struct breakpoint_objfile_data
*bp_objfile_data
;
3281 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3282 if (bp_objfile_data
== NULL
)
3283 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3284 return bp_objfile_data
;
3288 create_overlay_event_breakpoint (void)
3290 const char *const func_name
= "_ovly_debug_event";
3292 for (objfile
*objfile
: current_program_space
->objfiles ())
3294 struct breakpoint
*b
;
3295 struct breakpoint_objfile_data
*bp_objfile_data
;
3297 struct explicit_location explicit_loc
;
3299 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3301 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3304 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3306 struct bound_minimal_symbol m
;
3308 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3309 if (m
.minsym
== NULL
)
3311 /* Avoid future lookups in this objfile. */
3312 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3315 bp_objfile_data
->overlay_msym
= m
;
3318 addr
= bp_objfile_data
->overlay_msym
.value_address ();
3319 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3321 &vtable_breakpoint_ops
);
3322 initialize_explicit_location (&explicit_loc
);
3323 explicit_loc
.function_name
= ASTRDUP (func_name
);
3324 b
->location
= new_explicit_location (&explicit_loc
);
3326 if (overlay_debugging
== ovly_auto
)
3328 b
->enable_state
= bp_enabled
;
3329 overlay_events_enabled
= 1;
3333 b
->enable_state
= bp_disabled
;
3334 overlay_events_enabled
= 0;
3339 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3340 true if a breakpoint was installed. */
3343 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3345 struct gdbarch
*gdbarch
= objfile
->arch ();
3346 struct breakpoint_objfile_data
*bp_objfile_data
3347 = get_breakpoint_objfile_data (objfile
);
3349 if (!bp_objfile_data
->longjmp_searched
)
3351 std::vector
<probe
*> ret
3352 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3356 /* We are only interested in checking one element. */
3359 if (!p
->can_evaluate_arguments ())
3361 /* We cannot use the probe interface here,
3362 because it does not know how to evaluate
3367 bp_objfile_data
->longjmp_probes
= ret
;
3368 bp_objfile_data
->longjmp_searched
= 1;
3371 if (bp_objfile_data
->longjmp_probes
.empty ())
3374 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3376 struct breakpoint
*b
;
3378 b
= create_internal_breakpoint (gdbarch
,
3379 p
->get_relocated_address (objfile
),
3381 &vtable_breakpoint_ops
);
3382 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3383 b
->enable_state
= bp_disabled
;
3389 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3390 Return true if at least one breakpoint was installed. */
3393 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3395 struct gdbarch
*gdbarch
= objfile
->arch ();
3396 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3399 struct breakpoint_objfile_data
*bp_objfile_data
3400 = get_breakpoint_objfile_data (objfile
);
3401 unsigned int installed_bp
= 0;
3403 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3405 struct breakpoint
*b
;
3406 const char *func_name
;
3408 struct explicit_location explicit_loc
;
3410 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3413 func_name
= longjmp_names
[i
];
3414 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3416 struct bound_minimal_symbol m
;
3418 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3419 if (m
.minsym
== NULL
)
3421 /* Prevent future lookups in this objfile. */
3422 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3425 bp_objfile_data
->longjmp_msym
[i
] = m
;
3428 addr
= bp_objfile_data
->longjmp_msym
[i
].value_address ();
3429 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3430 &vtable_breakpoint_ops
);
3431 initialize_explicit_location (&explicit_loc
);
3432 explicit_loc
.function_name
= ASTRDUP (func_name
);
3433 b
->location
= new_explicit_location (&explicit_loc
);
3434 b
->enable_state
= bp_disabled
;
3438 return installed_bp
> 0;
3441 /* Create a master longjmp breakpoint. */
3444 create_longjmp_master_breakpoint (void)
3446 scoped_restore_current_program_space restore_pspace
;
3448 for (struct program_space
*pspace
: program_spaces
)
3450 set_current_program_space (pspace
);
3452 for (objfile
*obj
: current_program_space
->objfiles ())
3454 /* Skip separate debug object, it's handled in the loop below. */
3455 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3458 /* Try a probe kind breakpoint on main objfile. */
3459 if (create_longjmp_master_breakpoint_probe (obj
))
3462 /* Try longjmp_names kind breakpoints on main and separate_debug
3464 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3465 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3471 /* Create a master std::terminate breakpoint. */
3473 create_std_terminate_master_breakpoint (void)
3475 const char *const func_name
= "std::terminate()";
3477 scoped_restore_current_program_space restore_pspace
;
3479 for (struct program_space
*pspace
: program_spaces
)
3483 set_current_program_space (pspace
);
3485 for (objfile
*objfile
: current_program_space
->objfiles ())
3487 struct breakpoint
*b
;
3488 struct breakpoint_objfile_data
*bp_objfile_data
;
3489 struct explicit_location explicit_loc
;
3491 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3493 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3496 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3498 struct bound_minimal_symbol m
;
3500 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3501 if (m
.minsym
== NULL
|| (m
.minsym
->type () != mst_text
3502 && m
.minsym
->type () != mst_file_text
))
3504 /* Prevent future lookups in this objfile. */
3505 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3508 bp_objfile_data
->terminate_msym
= m
;
3511 addr
= bp_objfile_data
->terminate_msym
.value_address ();
3512 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3513 bp_std_terminate_master
,
3514 &vtable_breakpoint_ops
);
3515 initialize_explicit_location (&explicit_loc
);
3516 explicit_loc
.function_name
= ASTRDUP (func_name
);
3517 b
->location
= new_explicit_location (&explicit_loc
);
3518 b
->enable_state
= bp_disabled
;
3523 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3524 probe. Return true if a breakpoint was installed. */
3527 create_exception_master_breakpoint_probe (objfile
*objfile
)
3529 struct breakpoint
*b
;
3530 struct gdbarch
*gdbarch
;
3531 struct breakpoint_objfile_data
*bp_objfile_data
;
3533 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3535 /* We prefer the SystemTap probe point if it exists. */
3536 if (!bp_objfile_data
->exception_searched
)
3538 std::vector
<probe
*> ret
3539 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3543 /* We are only interested in checking one element. */
3546 if (!p
->can_evaluate_arguments ())
3548 /* We cannot use the probe interface here, because it does
3549 not know how to evaluate arguments. */
3553 bp_objfile_data
->exception_probes
= ret
;
3554 bp_objfile_data
->exception_searched
= 1;
3557 if (bp_objfile_data
->exception_probes
.empty ())
3560 gdbarch
= objfile
->arch ();
3562 for (probe
*p
: bp_objfile_data
->exception_probes
)
3564 b
= create_internal_breakpoint (gdbarch
,
3565 p
->get_relocated_address (objfile
),
3566 bp_exception_master
,
3567 &vtable_breakpoint_ops
);
3568 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3569 b
->enable_state
= bp_disabled
;
3575 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3576 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3579 create_exception_master_breakpoint_hook (objfile
*objfile
)
3581 const char *const func_name
= "_Unwind_DebugHook";
3582 struct breakpoint
*b
;
3583 struct gdbarch
*gdbarch
;
3584 struct breakpoint_objfile_data
*bp_objfile_data
;
3586 struct explicit_location explicit_loc
;
3588 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3590 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3593 gdbarch
= objfile
->arch ();
3595 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3597 struct bound_minimal_symbol debug_hook
;
3599 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3600 if (debug_hook
.minsym
== NULL
)
3602 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3606 bp_objfile_data
->exception_msym
= debug_hook
;
3609 addr
= bp_objfile_data
->exception_msym
.value_address ();
3610 addr
= gdbarch_convert_from_func_ptr_addr
3611 (gdbarch
, addr
, current_inferior ()->top_target ());
3612 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3613 &vtable_breakpoint_ops
);
3614 initialize_explicit_location (&explicit_loc
);
3615 explicit_loc
.function_name
= ASTRDUP (func_name
);
3616 b
->location
= new_explicit_location (&explicit_loc
);
3617 b
->enable_state
= bp_disabled
;
3622 /* Install a master breakpoint on the unwinder's debug hook. */
3625 create_exception_master_breakpoint (void)
3627 for (objfile
*obj
: current_program_space
->objfiles ())
3629 /* Skip separate debug object. */
3630 if (obj
->separate_debug_objfile_backlink
)
3633 /* Try a probe kind breakpoint. */
3634 if (create_exception_master_breakpoint_probe (obj
))
3637 /* Iterate over main and separate debug objects and try an
3638 _Unwind_DebugHook kind breakpoint. */
3639 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3640 if (create_exception_master_breakpoint_hook (debug_objfile
))
3645 /* Does B have a location spec? */
3648 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3650 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3654 update_breakpoints_after_exec (void)
3656 /* We're about to delete breakpoints from GDB's lists. If the
3657 INSERTED flag is true, GDB will try to lift the breakpoints by
3658 writing the breakpoints' "shadow contents" back into memory. The
3659 "shadow contents" are NOT valid after an exec, so GDB should not
3660 do that. Instead, the target is responsible from marking
3661 breakpoints out as soon as it detects an exec. We don't do that
3662 here instead, because there may be other attempts to delete
3663 breakpoints after detecting an exec and before reaching here. */
3664 for (bp_location
*bploc
: all_bp_locations ())
3665 if (bploc
->pspace
== current_program_space
)
3666 gdb_assert (!bploc
->inserted
);
3668 for (breakpoint
*b
: all_breakpoints_safe ())
3670 if (b
->pspace
!= current_program_space
)
3673 /* Solib breakpoints must be explicitly reset after an exec(). */
3674 if (b
->type
== bp_shlib_event
)
3676 delete_breakpoint (b
);
3680 /* JIT breakpoints must be explicitly reset after an exec(). */
3681 if (b
->type
== bp_jit_event
)
3683 delete_breakpoint (b
);
3687 /* Thread event breakpoints must be set anew after an exec(),
3688 as must overlay event and longjmp master breakpoints. */
3689 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3690 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3691 || b
->type
== bp_exception_master
)
3693 delete_breakpoint (b
);
3697 /* Step-resume breakpoints are meaningless after an exec(). */
3698 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3700 delete_breakpoint (b
);
3704 /* Just like single-step breakpoints. */
3705 if (b
->type
== bp_single_step
)
3707 delete_breakpoint (b
);
3711 /* Longjmp and longjmp-resume breakpoints are also meaningless
3713 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3714 || b
->type
== bp_longjmp_call_dummy
3715 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3717 delete_breakpoint (b
);
3721 if (b
->type
== bp_catchpoint
)
3723 /* For now, none of the bp_catchpoint breakpoints need to
3724 do anything at this point. In the future, if some of
3725 the catchpoints need to something, we will need to add
3726 a new method, and call this method from here. */
3730 /* bp_finish is a special case. The only way we ought to be able
3731 to see one of these when an exec() has happened, is if the user
3732 caught a vfork, and then said "finish". Ordinarily a finish just
3733 carries them to the call-site of the current callee, by setting
3734 a temporary bp there and resuming. But in this case, the finish
3735 will carry them entirely through the vfork & exec.
3737 We don't want to allow a bp_finish to remain inserted now. But
3738 we can't safely delete it, 'cause finish_command has a handle to
3739 the bp on a bpstat, and will later want to delete it. There's a
3740 chance (and I've seen it happen) that if we delete the bp_finish
3741 here, that its storage will get reused by the time finish_command
3742 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3743 We really must allow finish_command to delete a bp_finish.
3745 In the absence of a general solution for the "how do we know
3746 it's safe to delete something others may have handles to?"
3747 problem, what we'll do here is just uninsert the bp_finish, and
3748 let finish_command delete it.
3750 (We know the bp_finish is "doomed" in the sense that it's
3751 momentary, and will be deleted as soon as finish_command sees
3752 the inferior stopped. So it doesn't matter that the bp's
3753 address is probably bogus in the new a.out, unlike e.g., the
3754 solib breakpoints.) */
3756 if (b
->type
== bp_finish
)
3761 /* Without a symbolic address, we have little hope of the
3762 pre-exec() address meaning the same thing in the post-exec()
3764 if (breakpoint_event_location_empty_p (b
))
3766 delete_breakpoint (b
);
3773 detach_breakpoints (ptid_t ptid
)
3776 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3777 struct inferior
*inf
= current_inferior ();
3779 if (ptid
.pid () == inferior_ptid
.pid ())
3780 error (_("Cannot detach breakpoints of inferior_ptid"));
3782 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3783 inferior_ptid
= ptid
;
3784 for (bp_location
*bl
: all_bp_locations ())
3786 if (bl
->pspace
!= inf
->pspace
)
3789 /* This function must physically remove breakpoints locations
3790 from the specified ptid, without modifying the breakpoint
3791 package's state. Locations of type bp_loc_other are only
3792 maintained at GDB side. So, there is no need to remove
3793 these bp_loc_other locations. Moreover, removing these
3794 would modify the breakpoint package's state. */
3795 if (bl
->loc_type
== bp_loc_other
)
3799 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3805 /* Remove the breakpoint location BL from the current address space.
3806 Note that this is used to detach breakpoints from a child fork.
3807 When we get here, the child isn't in the inferior list, and neither
3808 do we have objects to represent its address space --- we should
3809 *not* look at bl->pspace->aspace here. */
3812 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3816 /* BL is never in moribund_locations by our callers. */
3817 gdb_assert (bl
->owner
!= NULL
);
3819 /* The type of none suggests that owner is actually deleted.
3820 This should not ever happen. */
3821 gdb_assert (bl
->owner
->type
!= bp_none
);
3823 if (bl
->loc_type
== bp_loc_software_breakpoint
3824 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3826 /* "Normal" instruction breakpoint: either the standard
3827 trap-instruction bp (bp_breakpoint), or a
3828 bp_hardware_breakpoint. */
3830 /* First check to see if we have to handle an overlay. */
3831 if (overlay_debugging
== ovly_off
3832 || bl
->section
== NULL
3833 || !(section_is_overlay (bl
->section
)))
3835 /* No overlay handling: just remove the breakpoint. */
3837 /* If we're trying to uninsert a memory breakpoint that we
3838 know is set in a dynamic object that is marked
3839 shlib_disabled, then either the dynamic object was
3840 removed with "remove-symbol-file" or with
3841 "nosharedlibrary". In the former case, we don't know
3842 whether another dynamic object might have loaded over the
3843 breakpoint's address -- the user might well let us know
3844 about it next with add-symbol-file (the whole point of
3845 add-symbol-file is letting the user manually maintain a
3846 list of dynamically loaded objects). If we have the
3847 breakpoint's shadow memory, that is, this is a software
3848 breakpoint managed by GDB, check whether the breakpoint
3849 is still inserted in memory, to avoid overwriting wrong
3850 code with stale saved shadow contents. Note that HW
3851 breakpoints don't have shadow memory, as they're
3852 implemented using a mechanism that is not dependent on
3853 being able to modify the target's memory, and as such
3854 they should always be removed. */
3855 if (bl
->shlib_disabled
3856 && bl
->target_info
.shadow_len
!= 0
3857 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3860 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3864 /* This breakpoint is in an overlay section.
3865 Did we set a breakpoint at the LMA? */
3866 if (!overlay_events_enabled
)
3868 /* Yes -- overlay event support is not active, so we
3869 should have set a breakpoint at the LMA. Remove it.
3871 /* Ignore any failures: if the LMA is in ROM, we will
3872 have already warned when we failed to insert it. */
3873 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3874 target_remove_hw_breakpoint (bl
->gdbarch
,
3875 &bl
->overlay_target_info
);
3877 target_remove_breakpoint (bl
->gdbarch
,
3878 &bl
->overlay_target_info
,
3881 /* Did we set a breakpoint at the VMA?
3882 If so, we will have marked the breakpoint 'inserted'. */
3885 /* Yes -- remove it. Previously we did not bother to
3886 remove the breakpoint if the section had been
3887 unmapped, but let's not rely on that being safe. We
3888 don't know what the overlay manager might do. */
3890 /* However, we should remove *software* breakpoints only
3891 if the section is still mapped, or else we overwrite
3892 wrong code with the saved shadow contents. */
3893 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3894 || section_is_mapped (bl
->section
))
3895 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3901 /* No -- not inserted, so no need to remove. No error. */
3906 /* In some cases, we might not be able to remove a breakpoint in
3907 a shared library that has already been removed, but we have
3908 not yet processed the shlib unload event. Similarly for an
3909 unloaded add-symbol-file object - the user might not yet have
3910 had the chance to remove-symbol-file it. shlib_disabled will
3911 be set if the library/object has already been removed, but
3912 the breakpoint hasn't been uninserted yet, e.g., after
3913 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3914 always-inserted mode. */
3916 && (bl
->loc_type
== bp_loc_software_breakpoint
3917 && (bl
->shlib_disabled
3918 || solib_name_from_address (bl
->pspace
, bl
->address
)
3919 || shared_objfile_contains_address_p (bl
->pspace
,
3925 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3927 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3929 gdb_assert (bl
->owner
->ops
!= NULL
3930 && bl
->owner
->ops
->remove_location
!= NULL
);
3932 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3933 bl
->owner
->ops
->remove_location (bl
, reason
);
3935 /* Failure to remove any of the hardware watchpoints comes here. */
3936 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3937 warning (_("Could not remove hardware watchpoint %d."),
3940 else if (bl
->owner
->type
== bp_catchpoint
3941 && breakpoint_enabled (bl
->owner
)
3944 gdb_assert (bl
->owner
->ops
!= NULL
3945 && bl
->owner
->ops
->remove_location
!= NULL
);
3947 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3951 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3958 remove_breakpoint (struct bp_location
*bl
)
3960 /* BL is never in moribund_locations by our callers. */
3961 gdb_assert (bl
->owner
!= NULL
);
3963 /* The type of none suggests that owner is actually deleted.
3964 This should not ever happen. */
3965 gdb_assert (bl
->owner
->type
!= bp_none
);
3967 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3969 switch_to_program_space_and_thread (bl
->pspace
);
3971 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3974 /* Clear the "inserted" flag in all breakpoints. */
3977 mark_breakpoints_out (void)
3979 for (bp_location
*bl
: all_bp_locations ())
3980 if (bl
->pspace
== current_program_space
)
3984 /* Clear the "inserted" flag in all breakpoints and delete any
3985 breakpoints which should go away between runs of the program.
3987 Plus other such housekeeping that has to be done for breakpoints
3990 Note: this function gets called at the end of a run (by
3991 generic_mourn_inferior) and when a run begins (by
3992 init_wait_for_inferior). */
3997 breakpoint_init_inferior (enum inf_context context
)
3999 struct program_space
*pspace
= current_program_space
;
4001 /* If breakpoint locations are shared across processes, then there's
4003 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4006 mark_breakpoints_out ();
4008 for (breakpoint
*b
: all_breakpoints_safe ())
4010 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4016 case bp_longjmp_call_dummy
:
4018 /* If the call dummy breakpoint is at the entry point it will
4019 cause problems when the inferior is rerun, so we better get
4022 case bp_watchpoint_scope
:
4024 /* Also get rid of scope breakpoints. */
4026 case bp_shlib_event
:
4028 /* Also remove solib event breakpoints. Their addresses may
4029 have changed since the last time we ran the program.
4030 Actually we may now be debugging against different target;
4031 and so the solib backend that installed this breakpoint may
4032 not be used in by the target. E.g.,
4034 (gdb) file prog-linux
4035 (gdb) run # native linux target
4038 (gdb) file prog-win.exe
4039 (gdb) tar rem :9999 # remote Windows gdbserver.
4042 case bp_step_resume
:
4044 /* Also remove step-resume breakpoints. */
4046 case bp_single_step
:
4048 /* Also remove single-step breakpoints. */
4050 delete_breakpoint (b
);
4054 case bp_hardware_watchpoint
:
4055 case bp_read_watchpoint
:
4056 case bp_access_watchpoint
:
4058 struct watchpoint
*w
= (struct watchpoint
*) b
;
4060 /* Likewise for watchpoints on local expressions. */
4061 if (w
->exp_valid_block
!= NULL
)
4062 delete_breakpoint (b
);
4065 /* Get rid of existing locations, which are no longer
4066 valid. New ones will be created in
4067 update_watchpoint, when the inferior is restarted.
4068 The next update_global_location_list call will
4069 garbage collect them. */
4072 if (context
== inf_starting
)
4074 /* Reset val field to force reread of starting value in
4075 insert_breakpoints. */
4076 w
->val
.reset (nullptr);
4077 w
->val_valid
= false;
4087 /* Get rid of the moribund locations. */
4088 for (bp_location
*bl
: moribund_locations
)
4089 decref_bp_location (&bl
);
4090 moribund_locations
.clear ();
4093 /* These functions concern about actual breakpoints inserted in the
4094 target --- to e.g. check if we need to do decr_pc adjustment or if
4095 we need to hop over the bkpt --- so we check for address space
4096 match, not program space. */
4098 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4099 exists at PC. It returns ordinary_breakpoint_here if it's an
4100 ordinary breakpoint, or permanent_breakpoint_here if it's a
4101 permanent breakpoint.
4102 - When continuing from a location with an ordinary breakpoint, we
4103 actually single step once before calling insert_breakpoints.
4104 - When continuing from a location with a permanent breakpoint, we
4105 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4106 the target, to advance the PC past the breakpoint. */
4108 enum breakpoint_here
4109 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4111 int any_breakpoint_here
= 0;
4113 for (bp_location
*bl
: all_bp_locations ())
4115 if (bl
->loc_type
!= bp_loc_software_breakpoint
4116 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4119 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4120 if ((breakpoint_enabled (bl
->owner
)
4122 && breakpoint_location_address_match (bl
, aspace
, pc
))
4124 if (overlay_debugging
4125 && section_is_overlay (bl
->section
)
4126 && !section_is_mapped (bl
->section
))
4127 continue; /* unmapped overlay -- can't be a match */
4128 else if (bl
->permanent
)
4129 return permanent_breakpoint_here
;
4131 any_breakpoint_here
= 1;
4135 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4138 /* See breakpoint.h. */
4141 breakpoint_in_range_p (const address_space
*aspace
,
4142 CORE_ADDR addr
, ULONGEST len
)
4144 for (bp_location
*bl
: all_bp_locations ())
4146 if (bl
->loc_type
!= bp_loc_software_breakpoint
4147 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4150 if ((breakpoint_enabled (bl
->owner
)
4152 && breakpoint_location_address_range_overlap (bl
, aspace
,
4155 if (overlay_debugging
4156 && section_is_overlay (bl
->section
)
4157 && !section_is_mapped (bl
->section
))
4159 /* Unmapped overlay -- can't be a match. */
4170 /* Return true if there's a moribund breakpoint at PC. */
4173 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4175 for (bp_location
*loc
: moribund_locations
)
4176 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4182 /* Returns non-zero iff BL is inserted at PC, in address space
4186 bp_location_inserted_here_p (struct bp_location
*bl
,
4187 const address_space
*aspace
, CORE_ADDR pc
)
4190 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4193 if (overlay_debugging
4194 && section_is_overlay (bl
->section
)
4195 && !section_is_mapped (bl
->section
))
4196 return 0; /* unmapped overlay -- can't be a match */
4203 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4206 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4208 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4210 if (bl
->loc_type
!= bp_loc_software_breakpoint
4211 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4214 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4220 /* This function returns non-zero iff there is a software breakpoint
4224 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4227 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4229 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4232 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4239 /* See breakpoint.h. */
4242 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4245 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4247 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4250 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4258 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4259 CORE_ADDR addr
, ULONGEST len
)
4261 for (breakpoint
*bpt
: all_breakpoints ())
4263 if (bpt
->type
!= bp_hardware_watchpoint
4264 && bpt
->type
!= bp_access_watchpoint
)
4267 if (!breakpoint_enabled (bpt
))
4270 for (bp_location
*loc
: bpt
->locations ())
4271 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4275 /* Check for intersection. */
4276 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4277 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4285 /* See breakpoint.h. */
4288 is_catchpoint (struct breakpoint
*b
)
4290 return (b
->type
== bp_catchpoint
);
4293 /* Clear a bpstat so that it says we are not at any breakpoint.
4294 Also free any storage that is part of a bpstat. */
4297 bpstat_clear (bpstat
**bsp
)
4314 bpstat::bpstat (const bpstat
&other
)
4316 bp_location_at (other
.bp_location_at
),
4317 breakpoint_at (other
.breakpoint_at
),
4318 commands (other
.commands
),
4319 print (other
.print
),
4321 print_it (other
.print_it
)
4323 if (other
.old_val
!= NULL
)
4324 old_val
= release_value (value_copy (other
.old_val
.get ()));
4327 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4328 is part of the bpstat is copied as well. */
4331 bpstat_copy (bpstat
*bs
)
4333 bpstat
*p
= nullptr;
4335 bpstat
*retval
= nullptr;
4340 for (; bs
!= NULL
; bs
= bs
->next
)
4342 tmp
= new bpstat (*bs
);
4345 /* This is the first thing in the chain. */
4355 /* Find the bpstat associated with this breakpoint. */
4358 bpstat_find_breakpoint (bpstat
*bsp
, struct breakpoint
*breakpoint
)
4363 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4365 if (bsp
->breakpoint_at
== breakpoint
)
4371 /* See breakpoint.h. */
4374 bpstat_explains_signal (bpstat
*bsp
, enum gdb_signal sig
)
4376 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4378 if (bsp
->breakpoint_at
== NULL
)
4380 /* A moribund location can never explain a signal other than
4382 if (sig
== GDB_SIGNAL_TRAP
)
4387 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4396 /* Put in *NUM the breakpoint number of the first breakpoint we are
4397 stopped at. *BSP upon return is a bpstat which points to the
4398 remaining breakpoints stopped at (but which is not guaranteed to be
4399 good for anything but further calls to bpstat_num).
4401 Return 0 if passed a bpstat which does not indicate any breakpoints.
4402 Return -1 if stopped at a breakpoint that has been deleted since
4404 Return 1 otherwise. */
4407 bpstat_num (bpstat
**bsp
, int *num
)
4409 struct breakpoint
*b
;
4412 return 0; /* No more breakpoint values */
4414 /* We assume we'll never have several bpstats that correspond to a
4415 single breakpoint -- otherwise, this function might return the
4416 same number more than once and this will look ugly. */
4417 b
= (*bsp
)->breakpoint_at
;
4418 *bsp
= (*bsp
)->next
;
4420 return -1; /* breakpoint that's been deleted since */
4422 *num
= b
->number
; /* We have its number */
4426 /* See breakpoint.h. */
4429 bpstat_clear_actions (void)
4433 if (inferior_ptid
== null_ptid
)
4436 thread_info
*tp
= inferior_thread ();
4437 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4439 bs
->commands
= NULL
;
4440 bs
->old_val
.reset (nullptr);
4444 /* Called when a command is about to proceed the inferior. */
4447 breakpoint_about_to_proceed (void)
4449 if (inferior_ptid
!= null_ptid
)
4451 struct thread_info
*tp
= inferior_thread ();
4453 /* Allow inferior function calls in breakpoint commands to not
4454 interrupt the command list. When the call finishes
4455 successfully, the inferior will be standing at the same
4456 breakpoint as if nothing happened. */
4457 if (tp
->control
.in_infcall
)
4461 breakpoint_proceeded
= 1;
4464 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4465 or its equivalent. */
4468 command_line_is_silent (struct command_line
*cmd
)
4470 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4473 /* Execute all the commands associated with all the breakpoints at
4474 this location. Any of these commands could cause the process to
4475 proceed beyond this point, etc. We look out for such changes by
4476 checking the global "breakpoint_proceeded" after each command.
4478 Returns true if a breakpoint command resumed the inferior. In that
4479 case, it is the caller's responsibility to recall it again with the
4480 bpstat of the current thread. */
4483 bpstat_do_actions_1 (bpstat
**bsp
)
4488 /* Avoid endless recursion if a `source' command is contained
4490 if (executing_breakpoint_commands
)
4493 scoped_restore save_executing
4494 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4496 scoped_restore preventer
= prevent_dont_repeat ();
4498 /* This pointer will iterate over the list of bpstat's. */
4501 breakpoint_proceeded
= 0;
4502 for (; bs
!= NULL
; bs
= bs
->next
)
4504 struct command_line
*cmd
= NULL
;
4506 /* Take ownership of the BSP's command tree, if it has one.
4508 The command tree could legitimately contain commands like
4509 'step' and 'next', which call clear_proceed_status, which
4510 frees stop_bpstat's command tree. To make sure this doesn't
4511 free the tree we're executing out from under us, we need to
4512 take ownership of the tree ourselves. Since a given bpstat's
4513 commands are only executed once, we don't need to copy it; we
4514 can clear the pointer in the bpstat, and make sure we free
4515 the tree when we're done. */
4516 counted_command_line ccmd
= bs
->commands
;
4517 bs
->commands
= NULL
;
4520 if (command_line_is_silent (cmd
))
4522 /* The action has been already done by bpstat_stop_status. */
4528 execute_control_command (cmd
);
4530 if (breakpoint_proceeded
)
4536 if (breakpoint_proceeded
)
4538 if (current_ui
->async
)
4539 /* If we are in async mode, then the target might be still
4540 running, not stopped at any breakpoint, so nothing for
4541 us to do here -- just return to the event loop. */
4544 /* In sync mode, when execute_control_command returns
4545 we're already standing on the next breakpoint.
4546 Breakpoint commands for that stop were not run, since
4547 execute_command does not run breakpoint commands --
4548 only command_line_handler does, but that one is not
4549 involved in execution of breakpoint commands. So, we
4550 can now execute breakpoint commands. It should be
4551 noted that making execute_command do bpstat actions is
4552 not an option -- in this case we'll have recursive
4553 invocation of bpstat for each breakpoint with a
4554 command, and can easily blow up GDB stack. Instead, we
4555 return true, which will trigger the caller to recall us
4556 with the new stop_bpstat. */
4564 /* Helper for bpstat_do_actions. Get the current thread, if there's
4565 one, is alive and has execution. Return NULL otherwise. */
4567 static thread_info
*
4568 get_bpstat_thread ()
4570 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4573 thread_info
*tp
= inferior_thread ();
4574 if (tp
->state
== THREAD_EXITED
|| tp
->executing ())
4580 bpstat_do_actions (void)
4582 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4585 /* Do any commands attached to breakpoint we are stopped at. */
4586 while ((tp
= get_bpstat_thread ()) != NULL
)
4588 /* Since in sync mode, bpstat_do_actions may resume the
4589 inferior, and only return when it is stopped at the next
4590 breakpoint, we keep doing breakpoint actions until it returns
4591 false to indicate the inferior was not resumed. */
4592 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4596 cleanup_if_error
.release ();
4599 /* Print out the (old or new) value associated with a watchpoint. */
4602 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4605 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4608 struct value_print_options opts
;
4609 get_user_print_options (&opts
);
4610 value_print (val
, stream
, &opts
);
4614 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4615 debugging multiple threads. */
4618 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4620 if (uiout
->is_mi_like_p ())
4625 if (show_thread_that_caused_stop ())
4627 struct thread_info
*thr
= inferior_thread ();
4629 uiout
->text ("Thread ");
4630 uiout
->field_string ("thread-id", print_thread_id (thr
));
4632 const char *name
= thread_name (thr
);
4635 uiout
->text (" \"");
4636 uiout
->field_string ("name", name
);
4640 uiout
->text (" hit ");
4644 /* Generic routine for printing messages indicating why we
4645 stopped. The behavior of this function depends on the value
4646 'print_it' in the bpstat structure. Under some circumstances we
4647 may decide not to print anything here and delegate the task to
4650 static enum print_stop_action
4651 print_bp_stop_message (bpstat
*bs
)
4653 switch (bs
->print_it
)
4656 /* Nothing should be printed for this bpstat entry. */
4657 return PRINT_UNKNOWN
;
4661 /* We still want to print the frame, but we already printed the
4662 relevant messages. */
4663 return PRINT_SRC_AND_LOC
;
4666 case print_it_normal
:
4668 struct breakpoint
*b
= bs
->breakpoint_at
;
4670 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4671 which has since been deleted. */
4673 return PRINT_UNKNOWN
;
4675 /* Normal case. Call the breakpoint's print_it method. */
4676 return b
->ops
->print_it (bs
);
4681 internal_error (__FILE__
, __LINE__
,
4682 _("print_bp_stop_message: unrecognized enum value"));
4687 /* See breakpoint.h. */
4690 print_solib_event (bool is_catchpoint
)
4692 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4693 bool any_added
= !current_program_space
->added_solibs
.empty ();
4697 if (any_added
|| any_deleted
)
4698 current_uiout
->text (_("Stopped due to shared library event:\n"));
4700 current_uiout
->text (_("Stopped due to shared library event (no "
4701 "libraries added or removed)\n"));
4704 if (current_uiout
->is_mi_like_p ())
4705 current_uiout
->field_string ("reason",
4706 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4710 current_uiout
->text (_(" Inferior unloaded "));
4711 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4712 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4714 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4717 current_uiout
->text (" ");
4718 current_uiout
->field_string ("library", name
);
4719 current_uiout
->text ("\n");
4725 current_uiout
->text (_(" Inferior loaded "));
4726 ui_out_emit_list
list_emitter (current_uiout
, "added");
4728 for (so_list
*iter
: current_program_space
->added_solibs
)
4731 current_uiout
->text (" ");
4733 current_uiout
->field_string ("library", iter
->so_name
);
4734 current_uiout
->text ("\n");
4739 /* Print a message indicating what happened. This is called from
4740 normal_stop(). The input to this routine is the head of the bpstat
4741 list - a list of the eventpoints that caused this stop. KIND is
4742 the target_waitkind for the stopping event. This
4743 routine calls the generic print routine for printing a message
4744 about reasons for stopping. This will print (for example) the
4745 "Breakpoint n," part of the output. The return value of this
4748 PRINT_UNKNOWN: Means we printed nothing.
4749 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4750 code to print the location. An example is
4751 "Breakpoint 1, " which should be followed by
4753 PRINT_SRC_ONLY: Means we printed something, but there is no need
4754 to also print the location part of the message.
4755 An example is the catch/throw messages, which
4756 don't require a location appended to the end.
4757 PRINT_NOTHING: We have done some printing and we don't need any
4758 further info to be printed. */
4760 enum print_stop_action
4761 bpstat_print (bpstat
*bs
, int kind
)
4763 enum print_stop_action val
;
4765 /* Maybe another breakpoint in the chain caused us to stop.
4766 (Currently all watchpoints go on the bpstat whether hit or not.
4767 That probably could (should) be changed, provided care is taken
4768 with respect to bpstat_explains_signal). */
4769 for (; bs
; bs
= bs
->next
)
4771 val
= print_bp_stop_message (bs
);
4772 if (val
== PRINT_SRC_ONLY
4773 || val
== PRINT_SRC_AND_LOC
4774 || val
== PRINT_NOTHING
)
4778 /* If we had hit a shared library event breakpoint,
4779 print_bp_stop_message would print out this message. If we hit an
4780 OS-level shared library event, do the same thing. */
4781 if (kind
== TARGET_WAITKIND_LOADED
)
4783 print_solib_event (false);
4784 return PRINT_NOTHING
;
4787 /* We reached the end of the chain, or we got a null BS to start
4788 with and nothing was printed. */
4789 return PRINT_UNKNOWN
;
4792 /* Evaluate the boolean expression EXP and return the result. */
4795 breakpoint_cond_eval (expression
*exp
)
4797 struct value
*mark
= value_mark ();
4798 bool res
= value_true (evaluate_expression (exp
));
4800 value_free_to_mark (mark
);
4804 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4806 bpstat::bpstat (struct bp_location
*bl
, bpstat
***bs_link_pointer
)
4808 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4809 breakpoint_at (bl
->owner
),
4813 print_it (print_it_normal
)
4815 **bs_link_pointer
= this;
4816 *bs_link_pointer
= &next
;
4821 breakpoint_at (NULL
),
4825 print_it (print_it_normal
)
4829 /* The target has stopped with waitstatus WS. Check if any hardware
4830 watchpoints have triggered, according to the target. */
4833 watchpoints_triggered (const target_waitstatus
&ws
)
4835 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4838 if (!stopped_by_watchpoint
)
4840 /* We were not stopped by a watchpoint. Mark all watchpoints
4841 as not triggered. */
4842 for (breakpoint
*b
: all_breakpoints ())
4843 if (is_hardware_watchpoint (b
))
4845 struct watchpoint
*w
= (struct watchpoint
*) b
;
4847 w
->watchpoint_triggered
= watch_triggered_no
;
4853 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4855 /* We were stopped by a watchpoint, but we don't know where.
4856 Mark all watchpoints as unknown. */
4857 for (breakpoint
*b
: all_breakpoints ())
4858 if (is_hardware_watchpoint (b
))
4860 struct watchpoint
*w
= (struct watchpoint
*) b
;
4862 w
->watchpoint_triggered
= watch_triggered_unknown
;
4868 /* The target could report the data address. Mark watchpoints
4869 affected by this data address as triggered, and all others as not
4872 for (breakpoint
*b
: all_breakpoints ())
4873 if (is_hardware_watchpoint (b
))
4875 struct watchpoint
*w
= (struct watchpoint
*) b
;
4877 w
->watchpoint_triggered
= watch_triggered_no
;
4878 for (bp_location
*loc
: b
->locations ())
4880 if (is_masked_watchpoint (b
))
4882 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4883 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4885 if (newaddr
== start
)
4887 w
->watchpoint_triggered
= watch_triggered_yes
;
4891 /* Exact match not required. Within range is sufficient. */
4892 else if (target_watchpoint_addr_within_range
4893 (current_inferior ()->top_target (), addr
, loc
->address
,
4896 w
->watchpoint_triggered
= watch_triggered_yes
;
4905 /* Possible return values for watchpoint_check. */
4906 enum wp_check_result
4908 /* The watchpoint has been deleted. */
4911 /* The value has changed. */
4912 WP_VALUE_CHANGED
= 2,
4914 /* The value has not changed. */
4915 WP_VALUE_NOT_CHANGED
= 3,
4917 /* Ignore this watchpoint, no matter if the value changed or not. */
4921 #define BP_TEMPFLAG 1
4922 #define BP_HARDWAREFLAG 2
4924 /* Evaluate watchpoint condition expression and check if its value
4927 static wp_check_result
4928 watchpoint_check (bpstat
*bs
)
4930 struct watchpoint
*b
;
4931 struct frame_info
*fr
;
4932 int within_current_scope
;
4934 /* BS is built from an existing struct breakpoint. */
4935 gdb_assert (bs
->breakpoint_at
!= NULL
);
4936 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4938 /* If this is a local watchpoint, we only want to check if the
4939 watchpoint frame is in scope if the current thread is the thread
4940 that was used to create the watchpoint. */
4941 if (!watchpoint_in_thread_scope (b
))
4944 if (b
->exp_valid_block
== NULL
)
4945 within_current_scope
= 1;
4948 struct frame_info
*frame
= get_current_frame ();
4949 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4950 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4952 /* stack_frame_destroyed_p() returns a non-zero value if we're
4953 still in the function but the stack frame has already been
4954 invalidated. Since we can't rely on the values of local
4955 variables after the stack has been destroyed, we are treating
4956 the watchpoint in that state as `not changed' without further
4957 checking. Don't mark watchpoints as changed if the current
4958 frame is in an epilogue - even if they are in some other
4959 frame, our view of the stack is likely to be wrong and
4960 frame_find_by_id could error out. */
4961 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4964 fr
= frame_find_by_id (b
->watchpoint_frame
);
4965 within_current_scope
= (fr
!= NULL
);
4967 /* If we've gotten confused in the unwinder, we might have
4968 returned a frame that can't describe this variable. */
4969 if (within_current_scope
)
4971 struct symbol
*function
;
4973 function
= get_frame_function (fr
);
4974 if (function
== NULL
4975 || !contained_in (b
->exp_valid_block
, function
->value_block ()))
4976 within_current_scope
= 0;
4979 if (within_current_scope
)
4980 /* If we end up stopping, the current frame will get selected
4981 in normal_stop. So this call to select_frame won't affect
4986 if (within_current_scope
)
4988 /* We use value_{,free_to_}mark because it could be a *long*
4989 time before we return to the command level and call
4990 free_all_values. We can't call free_all_values because we
4991 might be in the middle of evaluating a function call. */
4994 struct value
*new_val
;
4996 if (is_masked_watchpoint (b
))
4997 /* Since we don't know the exact trigger address (from
4998 stopped_data_address), just tell the user we've triggered
4999 a mask watchpoint. */
5000 return WP_VALUE_CHANGED
;
5002 mark
= value_mark ();
5003 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5006 if (b
->val_bitsize
!= 0)
5007 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5009 /* We use value_equal_contents instead of value_equal because
5010 the latter coerces an array to a pointer, thus comparing just
5011 the address of the array instead of its contents. This is
5012 not what we want. */
5013 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5014 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5017 bs
->old_val
= b
->val
;
5018 b
->val
= release_value (new_val
);
5019 b
->val_valid
= true;
5020 if (new_val
!= NULL
)
5021 value_free_to_mark (mark
);
5022 return WP_VALUE_CHANGED
;
5026 /* Nothing changed. */
5027 value_free_to_mark (mark
);
5028 return WP_VALUE_NOT_CHANGED
;
5033 /* This seems like the only logical thing to do because
5034 if we temporarily ignored the watchpoint, then when
5035 we reenter the block in which it is valid it contains
5036 garbage (in the case of a function, it may have two
5037 garbage values, one before and one after the prologue).
5038 So we can't even detect the first assignment to it and
5039 watch after that (since the garbage may or may not equal
5040 the first value assigned). */
5041 /* We print all the stop information in
5042 breakpoint_ops->print_it, but in this case, by the time we
5043 call breakpoint_ops->print_it this bp will be deleted
5044 already. So we have no choice but print the information
5047 SWITCH_THRU_ALL_UIS ()
5049 struct ui_out
*uiout
= current_uiout
;
5051 if (uiout
->is_mi_like_p ())
5053 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5054 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5055 "left the block in\n"
5056 "which its expression is valid.\n",
5057 signed_field ("wpnum", b
->number
));
5060 /* Make sure the watchpoint's commands aren't executed. */
5062 watchpoint_del_at_next_stop (b
);
5068 /* Return true if it looks like target has stopped due to hitting
5069 breakpoint location BL. This function does not check if we should
5070 stop, only if BL explains the stop. */
5073 bpstat_check_location (const struct bp_location
*bl
,
5074 const address_space
*aspace
, CORE_ADDR bp_addr
,
5075 const target_waitstatus
&ws
)
5077 struct breakpoint
*b
= bl
->owner
;
5079 /* BL is from an existing breakpoint. */
5080 gdb_assert (b
!= NULL
);
5082 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5085 /* Determine if the watched values have actually changed, and we
5086 should stop. If not, set BS->stop to 0. */
5089 bpstat_check_watchpoint (bpstat
*bs
)
5091 const struct bp_location
*bl
;
5092 struct watchpoint
*b
;
5094 /* BS is built for existing struct breakpoint. */
5095 bl
= bs
->bp_location_at
.get ();
5096 gdb_assert (bl
!= NULL
);
5097 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5098 gdb_assert (b
!= NULL
);
5101 int must_check_value
= 0;
5103 if (b
->type
== bp_watchpoint
)
5104 /* For a software watchpoint, we must always check the
5106 must_check_value
= 1;
5107 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5108 /* We have a hardware watchpoint (read, write, or access)
5109 and the target earlier reported an address watched by
5111 must_check_value
= 1;
5112 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5113 && b
->type
== bp_hardware_watchpoint
)
5114 /* We were stopped by a hardware watchpoint, but the target could
5115 not report the data address. We must check the watchpoint's
5116 value. Access and read watchpoints are out of luck; without
5117 a data address, we can't figure it out. */
5118 must_check_value
= 1;
5120 if (must_check_value
)
5126 e
= watchpoint_check (bs
);
5128 catch (const gdb_exception
&ex
)
5130 exception_fprintf (gdb_stderr
, ex
,
5131 "Error evaluating expression "
5132 "for watchpoint %d\n",
5135 SWITCH_THRU_ALL_UIS ()
5137 gdb_printf (_("Watchpoint %d deleted.\n"),
5140 watchpoint_del_at_next_stop (b
);
5147 /* We've already printed what needs to be printed. */
5148 bs
->print_it
= print_it_done
;
5152 bs
->print_it
= print_it_noop
;
5155 case WP_VALUE_CHANGED
:
5156 if (b
->type
== bp_read_watchpoint
)
5158 /* There are two cases to consider here:
5160 1. We're watching the triggered memory for reads.
5161 In that case, trust the target, and always report
5162 the watchpoint hit to the user. Even though
5163 reads don't cause value changes, the value may
5164 have changed since the last time it was read, and
5165 since we're not trapping writes, we will not see
5166 those, and as such we should ignore our notion of
5169 2. We're watching the triggered memory for both
5170 reads and writes. There are two ways this may
5173 2.1. This is a target that can't break on data
5174 reads only, but can break on accesses (reads or
5175 writes), such as e.g., x86. We detect this case
5176 at the time we try to insert read watchpoints.
5178 2.2. Otherwise, the target supports read
5179 watchpoints, but, the user set an access or write
5180 watchpoint watching the same memory as this read
5183 If we're watching memory writes as well as reads,
5184 ignore watchpoint hits when we find that the
5185 value hasn't changed, as reads don't cause
5186 changes. This still gives false positives when
5187 the program writes the same value to memory as
5188 what there was already in memory (we will confuse
5189 it for a read), but it's much better than
5192 int other_write_watchpoint
= 0;
5194 if (bl
->watchpoint_type
== hw_read
)
5196 for (breakpoint
*other_b
: all_breakpoints ())
5197 if (other_b
->type
== bp_hardware_watchpoint
5198 || other_b
->type
== bp_access_watchpoint
)
5200 struct watchpoint
*other_w
=
5201 (struct watchpoint
*) other_b
;
5203 if (other_w
->watchpoint_triggered
5204 == watch_triggered_yes
)
5206 other_write_watchpoint
= 1;
5212 if (other_write_watchpoint
5213 || bl
->watchpoint_type
== hw_access
)
5215 /* We're watching the same memory for writes,
5216 and the value changed since the last time we
5217 updated it, so this trap must be for a write.
5219 bs
->print_it
= print_it_noop
;
5224 case WP_VALUE_NOT_CHANGED
:
5225 if (b
->type
== bp_hardware_watchpoint
5226 || b
->type
== bp_watchpoint
)
5228 /* Don't stop: write watchpoints shouldn't fire if
5229 the value hasn't changed. */
5230 bs
->print_it
= print_it_noop
;
5240 else /* must_check_value == 0 */
5242 /* This is a case where some watchpoint(s) triggered, but
5243 not at the address of this watchpoint, or else no
5244 watchpoint triggered after all. So don't print
5245 anything for this watchpoint. */
5246 bs
->print_it
= print_it_noop
;
5252 /* For breakpoints that are currently marked as telling gdb to stop,
5253 check conditions (condition proper, frame, thread and ignore count)
5254 of breakpoint referred to by BS. If we should not stop for this
5255 breakpoint, set BS->stop to 0. */
5258 bpstat_check_breakpoint_conditions (bpstat
*bs
, thread_info
*thread
)
5260 const struct bp_location
*bl
;
5261 struct breakpoint
*b
;
5263 bool condition_result
= true;
5264 struct expression
*cond
;
5266 gdb_assert (bs
->stop
);
5268 /* BS is built for existing struct breakpoint. */
5269 bl
= bs
->bp_location_at
.get ();
5270 gdb_assert (bl
!= NULL
);
5271 b
= bs
->breakpoint_at
;
5272 gdb_assert (b
!= NULL
);
5274 /* Even if the target evaluated the condition on its end and notified GDB, we
5275 need to do so again since GDB does not know if we stopped due to a
5276 breakpoint or a single step breakpoint. */
5278 if (frame_id_p (b
->frame_id
)
5279 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5285 /* If this is a thread/task-specific breakpoint, don't waste cpu
5286 evaluating the condition if this isn't the specified
5288 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5289 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5295 /* Evaluate extension language breakpoints that have a "stop" method
5297 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5299 if (is_watchpoint (b
))
5301 struct watchpoint
*w
= (struct watchpoint
*) b
;
5303 cond
= w
->cond_exp
.get ();
5306 cond
= bl
->cond
.get ();
5308 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5310 int within_current_scope
= 1;
5311 struct watchpoint
* w
;
5313 /* We use value_mark and value_free_to_mark because it could
5314 be a long time before we return to the command level and
5315 call free_all_values. We can't call free_all_values
5316 because we might be in the middle of evaluating a
5318 struct value
*mark
= value_mark ();
5320 if (is_watchpoint (b
))
5321 w
= (struct watchpoint
*) b
;
5325 /* Need to select the frame, with all that implies so that
5326 the conditions will have the right context. Because we
5327 use the frame, we will not see an inlined function's
5328 variables when we arrive at a breakpoint at the start
5329 of the inlined function; the current frame will be the
5331 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5332 select_frame (get_current_frame ());
5335 struct frame_info
*frame
;
5337 /* For local watchpoint expressions, which particular
5338 instance of a local is being watched matters, so we
5339 keep track of the frame to evaluate the expression
5340 in. To evaluate the condition however, it doesn't
5341 really matter which instantiation of the function
5342 where the condition makes sense triggers the
5343 watchpoint. This allows an expression like "watch
5344 global if q > 10" set in `func', catch writes to
5345 global on all threads that call `func', or catch
5346 writes on all recursive calls of `func' by a single
5347 thread. We simply always evaluate the condition in
5348 the innermost frame that's executing where it makes
5349 sense to evaluate the condition. It seems
5351 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5353 select_frame (frame
);
5355 within_current_scope
= 0;
5357 if (within_current_scope
)
5361 condition_result
= breakpoint_cond_eval (cond
);
5363 catch (const gdb_exception
&ex
)
5365 exception_fprintf (gdb_stderr
, ex
,
5366 "Error in testing breakpoint condition:\n");
5371 warning (_("Watchpoint condition cannot be tested "
5372 "in the current scope"));
5373 /* If we failed to set the right context for this
5374 watchpoint, unconditionally report it. */
5376 /* FIXME-someday, should give breakpoint #. */
5377 value_free_to_mark (mark
);
5380 if (cond
&& !condition_result
)
5384 else if (b
->ignore_count
> 0)
5388 /* Increase the hit count even though we don't stop. */
5390 gdb::observers::breakpoint_modified
.notify (b
);
5394 /* Returns true if we need to track moribund locations of LOC's type
5395 on the current target. */
5398 need_moribund_for_location_type (struct bp_location
*loc
)
5400 return ((loc
->loc_type
== bp_loc_software_breakpoint
5401 && !target_supports_stopped_by_sw_breakpoint ())
5402 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5403 && !target_supports_stopped_by_hw_breakpoint ()));
5406 /* See breakpoint.h. */
5409 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5410 const target_waitstatus
&ws
)
5412 bpstat
*bs_head
= nullptr, **bs_link
= &bs_head
;
5414 for (breakpoint
*b
: all_breakpoints ())
5416 if (!breakpoint_enabled (b
))
5419 for (bp_location
*bl
: b
->locations ())
5421 /* For hardware watchpoints, we look only at the first
5422 location. The watchpoint_check function will work on the
5423 entire expression, not the individual locations. For
5424 read watchpoints, the watchpoints_triggered function has
5425 checked all locations already. */
5426 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5429 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5432 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5435 /* Come here if it's a watchpoint, or if the break address
5438 bpstat
*bs
= new bpstat (bl
, &bs_link
); /* Alloc a bpstat to
5441 /* Assume we stop. Should we find a watchpoint that is not
5442 actually triggered, or if the condition of the breakpoint
5443 evaluates as false, we'll reset 'stop' to 0. */
5447 /* If this is a scope breakpoint, mark the associated
5448 watchpoint as triggered so that we will handle the
5449 out-of-scope event. We'll get to the watchpoint next
5451 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5453 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5455 w
->watchpoint_triggered
= watch_triggered_yes
;
5460 /* Check if a moribund breakpoint explains the stop. */
5461 if (!target_supports_stopped_by_sw_breakpoint ()
5462 || !target_supports_stopped_by_hw_breakpoint ())
5464 for (bp_location
*loc
: moribund_locations
)
5466 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5467 && need_moribund_for_location_type (loc
))
5469 bpstat
*bs
= new bpstat (loc
, &bs_link
);
5470 /* For hits of moribund locations, we should just proceed. */
5473 bs
->print_it
= print_it_noop
;
5481 /* See breakpoint.h. */
5484 bpstat_stop_status (const address_space
*aspace
,
5485 CORE_ADDR bp_addr
, thread_info
*thread
,
5486 const target_waitstatus
&ws
,
5489 struct breakpoint
*b
= NULL
;
5490 /* First item of allocated bpstat's. */
5491 bpstat
*bs_head
= stop_chain
;
5493 int need_remove_insert
;
5496 /* First, build the bpstat chain with locations that explain a
5497 target stop, while being careful to not set the target running,
5498 as that may invalidate locations (in particular watchpoint
5499 locations are recreated). Resuming will happen here with
5500 breakpoint conditions or watchpoint expressions that include
5501 inferior function calls. */
5502 if (bs_head
== NULL
)
5503 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5505 /* A bit of special processing for shlib breakpoints. We need to
5506 process solib loading here, so that the lists of loaded and
5507 unloaded libraries are correct before we handle "catch load" and
5509 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5511 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5513 handle_solib_event ();
5518 /* Now go through the locations that caused the target to stop, and
5519 check whether we're interested in reporting this stop to higher
5520 layers, or whether we should resume the target transparently. */
5524 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5529 b
= bs
->breakpoint_at
;
5530 b
->ops
->check_status (bs
);
5533 bpstat_check_breakpoint_conditions (bs
, thread
);
5539 /* We will stop here. */
5540 if (b
->disposition
== disp_disable
)
5542 --(b
->enable_count
);
5543 if (b
->enable_count
<= 0)
5544 b
->enable_state
= bp_disabled
;
5547 gdb::observers::breakpoint_modified
.notify (b
);
5550 bs
->commands
= b
->commands
;
5551 if (command_line_is_silent (bs
->commands
5552 ? bs
->commands
.get () : NULL
))
5555 b
->ops
->after_condition_true (bs
);
5560 /* Print nothing for this entry if we don't stop or don't
5562 if (!bs
->stop
|| !bs
->print
)
5563 bs
->print_it
= print_it_noop
;
5566 /* If we aren't stopping, the value of some hardware watchpoint may
5567 not have changed, but the intermediate memory locations we are
5568 watching may have. Don't bother if we're stopping; this will get
5570 need_remove_insert
= 0;
5571 if (! bpstat_causes_stop (bs_head
))
5572 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5574 && bs
->breakpoint_at
5575 && is_hardware_watchpoint (bs
->breakpoint_at
))
5577 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5579 update_watchpoint (w
, 0 /* don't reparse. */);
5580 need_remove_insert
= 1;
5583 if (need_remove_insert
)
5584 update_global_location_list (UGLL_MAY_INSERT
);
5585 else if (removed_any
)
5586 update_global_location_list (UGLL_DONT_INSERT
);
5591 /* See breakpoint.h. */
5594 bpstat_stop_status_nowatch (const address_space
*aspace
, CORE_ADDR bp_addr
,
5595 thread_info
*thread
, const target_waitstatus
&ws
)
5597 gdb_assert (!target_stopped_by_watchpoint ());
5599 /* Clear all watchpoints' 'watchpoint_triggered' value from a
5600 previous stop to avoid confusing bpstat_stop_status. */
5601 watchpoints_triggered (ws
);
5603 return bpstat_stop_status (aspace
, bp_addr
, thread
, ws
);
5607 handle_jit_event (CORE_ADDR address
)
5609 struct gdbarch
*gdbarch
;
5611 infrun_debug_printf ("handling bp_jit_event");
5613 /* Switch terminal for any messages produced by
5614 breakpoint_re_set. */
5615 target_terminal::ours_for_output ();
5617 gdbarch
= get_frame_arch (get_current_frame ());
5618 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5619 thus it is expected that its objectfile can be found through
5620 minimal symbol lookup. If it doesn't work (and assert fails), it
5621 most likely means that `jit_breakpoint_re_set` was changes and this
5622 function needs to be updated too. */
5623 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5624 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5625 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5627 target_terminal::inferior ();
5630 /* Prepare WHAT final decision for infrun. */
5632 /* Decide what infrun needs to do with this bpstat. */
5635 bpstat_what (bpstat
*bs_head
)
5637 struct bpstat_what retval
;
5640 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5641 retval
.call_dummy
= STOP_NONE
;
5642 retval
.is_longjmp
= false;
5644 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5646 /* Extract this BS's action. After processing each BS, we check
5647 if its action overrides all we've seem so far. */
5648 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5651 if (bs
->breakpoint_at
== NULL
)
5653 /* I suspect this can happen if it was a momentary
5654 breakpoint which has since been deleted. */
5658 bptype
= bs
->breakpoint_at
->type
;
5665 case bp_hardware_breakpoint
:
5666 case bp_single_step
:
5669 case bp_shlib_event
:
5673 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5675 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5678 this_action
= BPSTAT_WHAT_SINGLE
;
5681 case bp_hardware_watchpoint
:
5682 case bp_read_watchpoint
:
5683 case bp_access_watchpoint
:
5687 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5689 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5693 /* There was a watchpoint, but we're not stopping.
5694 This requires no further action. */
5698 case bp_longjmp_call_dummy
:
5702 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5703 retval
.is_longjmp
= bptype
!= bp_exception
;
5706 this_action
= BPSTAT_WHAT_SINGLE
;
5708 case bp_longjmp_resume
:
5709 case bp_exception_resume
:
5712 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5713 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5716 this_action
= BPSTAT_WHAT_SINGLE
;
5718 case bp_step_resume
:
5720 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5723 /* It is for the wrong frame. */
5724 this_action
= BPSTAT_WHAT_SINGLE
;
5727 case bp_hp_step_resume
:
5729 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5732 /* It is for the wrong frame. */
5733 this_action
= BPSTAT_WHAT_SINGLE
;
5736 case bp_watchpoint_scope
:
5737 case bp_thread_event
:
5738 case bp_overlay_event
:
5739 case bp_longjmp_master
:
5740 case bp_std_terminate_master
:
5741 case bp_exception_master
:
5742 this_action
= BPSTAT_WHAT_SINGLE
;
5748 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5750 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5754 /* Some catchpoints are implemented with breakpoints.
5755 For those, we need to step over the breakpoint. */
5756 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5757 this_action
= BPSTAT_WHAT_SINGLE
;
5761 this_action
= BPSTAT_WHAT_SINGLE
;
5764 /* Make sure the action is stop (silent or noisy),
5765 so infrun.c pops the dummy frame. */
5766 retval
.call_dummy
= STOP_STACK_DUMMY
;
5767 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5769 case bp_std_terminate
:
5770 /* Make sure the action is stop (silent or noisy),
5771 so infrun.c pops the dummy frame. */
5772 retval
.call_dummy
= STOP_STD_TERMINATE
;
5773 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5776 case bp_fast_tracepoint
:
5777 case bp_static_tracepoint
:
5778 /* Tracepoint hits should not be reported back to GDB, and
5779 if one got through somehow, it should have been filtered
5781 internal_error (__FILE__
, __LINE__
,
5782 _("bpstat_what: tracepoint encountered"));
5784 case bp_gnu_ifunc_resolver
:
5785 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5786 this_action
= BPSTAT_WHAT_SINGLE
;
5788 case bp_gnu_ifunc_resolver_return
:
5789 /* The breakpoint will be removed, execution will restart from the
5790 PC of the former breakpoint. */
5791 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5796 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5798 this_action
= BPSTAT_WHAT_SINGLE
;
5802 internal_error (__FILE__
, __LINE__
,
5803 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5806 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5813 bpstat_run_callbacks (bpstat
*bs_head
)
5817 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5819 struct breakpoint
*b
= bs
->breakpoint_at
;
5826 handle_jit_event (bs
->bp_location_at
->address
);
5828 case bp_gnu_ifunc_resolver
:
5829 gnu_ifunc_resolver_stop (b
);
5831 case bp_gnu_ifunc_resolver_return
:
5832 gnu_ifunc_resolver_return_stop (b
);
5838 /* See breakpoint.h. */
5841 bpstat_should_step ()
5843 for (breakpoint
*b
: all_breakpoints ())
5844 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5850 /* See breakpoint.h. */
5853 bpstat_causes_stop (bpstat
*bs
)
5855 for (; bs
!= NULL
; bs
= bs
->next
)
5864 /* Compute a number of spaces suitable to indent the next line
5865 so it starts at the position corresponding to the table column
5866 named COL_NAME in the currently active table of UIOUT. */
5869 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5871 int i
, total_width
, width
, align
;
5875 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5877 if (strcmp (text
, col_name
) == 0)
5880 total_width
+= width
+ 1;
5886 /* Determine if the locations of this breakpoint will have their conditions
5887 evaluated by the target, host or a mix of both. Returns the following:
5889 "host": Host evals condition.
5890 "host or target": Host or Target evals condition.
5891 "target": Target evals condition.
5895 bp_condition_evaluator (struct breakpoint
*b
)
5897 char host_evals
= 0;
5898 char target_evals
= 0;
5903 if (!is_breakpoint (b
))
5906 if (gdb_evaluates_breakpoint_condition_p ()
5907 || !target_supports_evaluation_of_breakpoint_conditions ())
5908 return condition_evaluation_host
;
5910 for (bp_location
*bl
: b
->locations ())
5912 if (bl
->cond_bytecode
)
5918 if (host_evals
&& target_evals
)
5919 return condition_evaluation_both
;
5920 else if (target_evals
)
5921 return condition_evaluation_target
;
5923 return condition_evaluation_host
;
5926 /* Determine the breakpoint location's condition evaluator. This is
5927 similar to bp_condition_evaluator, but for locations. */
5930 bp_location_condition_evaluator (struct bp_location
*bl
)
5932 if (bl
&& !is_breakpoint (bl
->owner
))
5935 if (gdb_evaluates_breakpoint_condition_p ()
5936 || !target_supports_evaluation_of_breakpoint_conditions ())
5937 return condition_evaluation_host
;
5939 if (bl
&& bl
->cond_bytecode
)
5940 return condition_evaluation_target
;
5942 return condition_evaluation_host
;
5945 /* Print the LOC location out of the list of B->LOC locations. */
5948 print_breakpoint_location (struct breakpoint
*b
,
5949 struct bp_location
*loc
)
5951 struct ui_out
*uiout
= current_uiout
;
5953 scoped_restore_current_program_space restore_pspace
;
5955 if (loc
!= NULL
&& loc
->shlib_disabled
)
5959 set_current_program_space (loc
->pspace
);
5961 if (b
->display_canonical
)
5962 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5963 else if (loc
&& loc
->symtab
)
5965 const struct symbol
*sym
= loc
->symbol
;
5969 uiout
->text ("in ");
5970 uiout
->field_string ("func", sym
->print_name (),
5971 function_name_style
.style ());
5973 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5974 uiout
->text ("at ");
5976 uiout
->field_string ("file",
5977 symtab_to_filename_for_display (loc
->symtab
),
5978 file_name_style
.style ());
5981 if (uiout
->is_mi_like_p ())
5982 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5984 uiout
->field_signed ("line", loc
->line_number
);
5990 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5992 uiout
->field_stream ("at", stb
);
5996 uiout
->field_string ("pending",
5997 event_location_to_string (b
->location
.get ()));
5998 /* If extra_string is available, it could be holding a condition
5999 or dprintf arguments. In either case, make sure it is printed,
6000 too, but only for non-MI streams. */
6001 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6003 if (b
->type
== bp_dprintf
)
6007 uiout
->text (b
->extra_string
.get ());
6011 if (loc
&& is_breakpoint (b
)
6012 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6013 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6016 uiout
->field_string ("evaluated-by",
6017 bp_location_condition_evaluator (loc
));
6023 bptype_string (enum bptype type
)
6025 struct ep_type_description
6028 const char *description
;
6030 static struct ep_type_description bptypes
[] =
6032 {bp_none
, "?deleted?"},
6033 {bp_breakpoint
, "breakpoint"},
6034 {bp_hardware_breakpoint
, "hw breakpoint"},
6035 {bp_single_step
, "sw single-step"},
6036 {bp_until
, "until"},
6037 {bp_finish
, "finish"},
6038 {bp_watchpoint
, "watchpoint"},
6039 {bp_hardware_watchpoint
, "hw watchpoint"},
6040 {bp_read_watchpoint
, "read watchpoint"},
6041 {bp_access_watchpoint
, "acc watchpoint"},
6042 {bp_longjmp
, "longjmp"},
6043 {bp_longjmp_resume
, "longjmp resume"},
6044 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6045 {bp_exception
, "exception"},
6046 {bp_exception_resume
, "exception resume"},
6047 {bp_step_resume
, "step resume"},
6048 {bp_hp_step_resume
, "high-priority step resume"},
6049 {bp_watchpoint_scope
, "watchpoint scope"},
6050 {bp_call_dummy
, "call dummy"},
6051 {bp_std_terminate
, "std::terminate"},
6052 {bp_shlib_event
, "shlib events"},
6053 {bp_thread_event
, "thread events"},
6054 {bp_overlay_event
, "overlay events"},
6055 {bp_longjmp_master
, "longjmp master"},
6056 {bp_std_terminate_master
, "std::terminate master"},
6057 {bp_exception_master
, "exception master"},
6058 {bp_catchpoint
, "catchpoint"},
6059 {bp_tracepoint
, "tracepoint"},
6060 {bp_fast_tracepoint
, "fast tracepoint"},
6061 {bp_static_tracepoint
, "static tracepoint"},
6062 {bp_dprintf
, "dprintf"},
6063 {bp_jit_event
, "jit events"},
6064 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6065 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6068 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6069 || ((int) type
!= bptypes
[(int) type
].type
))
6070 internal_error (__FILE__
, __LINE__
,
6071 _("bptypes table does not describe type #%d."),
6074 return bptypes
[(int) type
].description
;
6077 /* For MI, output a field named 'thread-groups' with a list as the value.
6078 For CLI, prefix the list with the string 'inf'. */
6081 output_thread_groups (struct ui_out
*uiout
,
6082 const char *field_name
,
6083 const std::vector
<int> &inf_nums
,
6086 int is_mi
= uiout
->is_mi_like_p ();
6088 /* For backward compatibility, don't display inferiors in CLI unless
6089 there are several. Always display them for MI. */
6090 if (!is_mi
&& mi_only
)
6093 ui_out_emit_list
list_emitter (uiout
, field_name
);
6095 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6101 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6102 uiout
->field_string (NULL
, mi_group
);
6107 uiout
->text (" inf ");
6111 uiout
->text (plongest (inf_nums
[i
]));
6116 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6117 instead of going via breakpoint_ops::print_one. This makes "maint
6118 info breakpoints" show the software breakpoint locations of
6119 catchpoints, which are considered internal implementation
6120 detail. Returns true if RAW_LOC is false and if the breakpoint's
6121 print_one method did something; false otherwise. */
6124 print_one_breakpoint_location (struct breakpoint
*b
,
6125 struct bp_location
*loc
,
6127 struct bp_location
**last_loc
,
6128 int allflag
, bool raw_loc
)
6130 struct command_line
*l
;
6131 static char bpenables
[] = "nynny";
6133 struct ui_out
*uiout
= current_uiout
;
6134 int header_of_multiple
= 0;
6135 int part_of_multiple
= (loc
!= NULL
);
6136 struct value_print_options opts
;
6138 get_user_print_options (&opts
);
6140 gdb_assert (!loc
|| loc_number
!= 0);
6141 /* See comment in print_one_breakpoint concerning treatment of
6142 breakpoints with single disabled location. */
6145 && (b
->loc
->next
!= NULL
6146 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6147 header_of_multiple
= 1;
6155 if (part_of_multiple
)
6156 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6158 uiout
->field_signed ("number", b
->number
);
6162 if (part_of_multiple
)
6163 uiout
->field_skip ("type");
6165 uiout
->field_string ("type", bptype_string (b
->type
));
6169 if (part_of_multiple
)
6170 uiout
->field_skip ("disp");
6172 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6176 /* For locations that are disabled because of an invalid condition,
6177 display "N*" on CLI, where "*" refers to a footnote below the
6178 table. For MI, simply display a "N" without a footnote. */
6179 const char *N
= (uiout
->is_mi_like_p ()) ? "N" : "N*";
6180 if (part_of_multiple
)
6181 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? N
6182 : (loc
->enabled
? "y" : "n")));
6184 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6187 bool result
= false;
6188 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one (b
, last_loc
))
6192 if (is_watchpoint (b
))
6194 struct watchpoint
*w
= (struct watchpoint
*) b
;
6196 /* Field 4, the address, is omitted (which makes the columns
6197 not line up too nicely with the headers, but the effect
6198 is relatively readable). */
6199 if (opts
.addressprint
)
6200 uiout
->field_skip ("addr");
6202 uiout
->field_string ("what", w
->exp_string
.get ());
6204 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6205 || is_ada_exception_catchpoint (b
))
6207 if (opts
.addressprint
)
6210 if (header_of_multiple
)
6211 uiout
->field_string ("addr", "<MULTIPLE>",
6212 metadata_style
.style ());
6213 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6214 uiout
->field_string ("addr", "<PENDING>",
6215 metadata_style
.style ());
6217 uiout
->field_core_addr ("addr",
6218 loc
->gdbarch
, loc
->address
);
6221 if (!header_of_multiple
)
6222 print_breakpoint_location (b
, loc
);
6228 if (loc
!= NULL
&& !header_of_multiple
)
6230 std::vector
<int> inf_nums
;
6233 for (inferior
*inf
: all_inferiors ())
6235 if (inf
->pspace
== loc
->pspace
)
6236 inf_nums
.push_back (inf
->num
);
6239 /* For backward compatibility, don't display inferiors in CLI unless
6240 there are several. Always display for MI. */
6242 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6243 && (program_spaces
.size () > 1
6244 || number_of_inferiors () > 1)
6245 /* LOC is for existing B, it cannot be in
6246 moribund_locations and thus having NULL OWNER. */
6247 && loc
->owner
->type
!= bp_catchpoint
))
6249 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6252 if (!part_of_multiple
)
6254 if (b
->thread
!= -1)
6256 /* FIXME: This seems to be redundant and lost here; see the
6257 "stop only in" line a little further down. */
6258 uiout
->text (" thread ");
6259 uiout
->field_signed ("thread", b
->thread
);
6261 else if (b
->task
!= 0)
6263 uiout
->text (" task ");
6264 uiout
->field_signed ("task", b
->task
);
6270 if (!part_of_multiple
)
6271 b
->ops
->print_one_detail (b
, uiout
);
6273 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6276 uiout
->text ("\tstop only in stack frame at ");
6277 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6279 uiout
->field_core_addr ("frame",
6280 b
->gdbarch
, b
->frame_id
.stack_addr
);
6284 if (!part_of_multiple
&& b
->cond_string
)
6287 if (is_tracepoint (b
))
6288 uiout
->text ("\ttrace only if ");
6290 uiout
->text ("\tstop only if ");
6291 uiout
->field_string ("cond", b
->cond_string
.get ());
6293 /* Print whether the target is doing the breakpoint's condition
6294 evaluation. If GDB is doing the evaluation, don't print anything. */
6295 if (is_breakpoint (b
)
6296 && breakpoint_condition_evaluation_mode ()
6297 == condition_evaluation_target
)
6299 uiout
->message (" (%pF evals)",
6300 string_field ("evaluated-by",
6301 bp_condition_evaluator (b
)));
6306 if (!part_of_multiple
&& b
->thread
!= -1)
6308 /* FIXME should make an annotation for this. */
6309 uiout
->text ("\tstop only in thread ");
6310 if (uiout
->is_mi_like_p ())
6311 uiout
->field_signed ("thread", b
->thread
);
6314 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6316 uiout
->field_string ("thread", print_thread_id (thr
));
6321 if (!part_of_multiple
)
6325 /* FIXME should make an annotation for this. */
6326 if (is_catchpoint (b
))
6327 uiout
->text ("\tcatchpoint");
6328 else if (is_tracepoint (b
))
6329 uiout
->text ("\ttracepoint");
6331 uiout
->text ("\tbreakpoint");
6332 uiout
->text (" already hit ");
6333 uiout
->field_signed ("times", b
->hit_count
);
6334 if (b
->hit_count
== 1)
6335 uiout
->text (" time\n");
6337 uiout
->text (" times\n");
6341 /* Output the count also if it is zero, but only if this is mi. */
6342 if (uiout
->is_mi_like_p ())
6343 uiout
->field_signed ("times", b
->hit_count
);
6347 if (!part_of_multiple
&& b
->ignore_count
)
6350 uiout
->message ("\tignore next %pF hits\n",
6351 signed_field ("ignore", b
->ignore_count
));
6354 /* Note that an enable count of 1 corresponds to "enable once"
6355 behavior, which is reported by the combination of enablement and
6356 disposition, so we don't need to mention it here. */
6357 if (!part_of_multiple
&& b
->enable_count
> 1)
6360 uiout
->text ("\tdisable after ");
6361 /* Tweak the wording to clarify that ignore and enable counts
6362 are distinct, and have additive effect. */
6363 if (b
->ignore_count
)
6364 uiout
->text ("additional ");
6366 uiout
->text ("next ");
6367 uiout
->field_signed ("enable", b
->enable_count
);
6368 uiout
->text (" hits\n");
6371 if (!part_of_multiple
&& is_tracepoint (b
))
6373 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6375 if (tp
->traceframe_usage
)
6377 uiout
->text ("\ttrace buffer usage ");
6378 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6379 uiout
->text (" bytes\n");
6383 l
= b
->commands
? b
->commands
.get () : NULL
;
6384 if (!part_of_multiple
&& l
)
6387 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6388 print_command_lines (uiout
, l
, 4);
6391 if (is_tracepoint (b
))
6393 struct tracepoint
*t
= (struct tracepoint
*) b
;
6395 if (!part_of_multiple
&& t
->pass_count
)
6397 annotate_field (10);
6398 uiout
->text ("\tpass count ");
6399 uiout
->field_signed ("pass", t
->pass_count
);
6400 uiout
->text (" \n");
6403 /* Don't display it when tracepoint or tracepoint location is
6405 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6407 annotate_field (11);
6409 if (uiout
->is_mi_like_p ())
6410 uiout
->field_string ("installed",
6411 loc
->inserted
? "y" : "n");
6417 uiout
->text ("\tnot ");
6418 uiout
->text ("installed on target\n");
6423 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6425 if (is_watchpoint (b
))
6427 struct watchpoint
*w
= (struct watchpoint
*) b
;
6429 uiout
->field_string ("original-location", w
->exp_string
.get ());
6431 else if (b
->location
!= NULL
6432 && event_location_to_string (b
->location
.get ()) != NULL
)
6433 uiout
->field_string ("original-location",
6434 event_location_to_string (b
->location
.get ()));
6440 /* See breakpoint.h. */
6442 bool fix_multi_location_breakpoint_output_globally
= false;
6445 print_one_breakpoint (struct breakpoint
*b
,
6446 struct bp_location
**last_loc
,
6449 struct ui_out
*uiout
= current_uiout
;
6450 bool use_fixed_output
6451 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6452 || fix_multi_location_breakpoint_output_globally
);
6454 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6455 bool printed
= print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
6458 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6460 if (!use_fixed_output
)
6461 bkpt_tuple_emitter
.reset ();
6463 /* If this breakpoint has custom print function,
6464 it's already printed. Otherwise, print individual
6465 locations, if any. */
6466 if (!printed
|| allflag
)
6468 /* If breakpoint has a single location that is disabled, we
6469 print it as if it had several locations, since otherwise it's
6470 hard to represent "breakpoint enabled, location disabled"
6473 Note that while hardware watchpoints have several locations
6474 internally, that's not a property exposed to users.
6476 Likewise, while catchpoints may be implemented with
6477 breakpoints (e.g., catch throw), that's not a property
6478 exposed to users. We do however display the internal
6479 breakpoint locations with "maint info breakpoints". */
6480 if (!is_hardware_watchpoint (b
)
6481 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6482 || is_ada_exception_catchpoint (b
))
6484 || (b
->loc
&& (b
->loc
->next
6486 || b
->loc
->disabled_by_cond
))))
6488 gdb::optional
<ui_out_emit_list
> locations_list
;
6490 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6491 MI record. For later versions, place breakpoint locations in a
6493 if (uiout
->is_mi_like_p () && use_fixed_output
)
6494 locations_list
.emplace (uiout
, "locations");
6497 for (bp_location
*loc
: b
->locations ())
6499 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6500 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6509 breakpoint_address_bits (struct breakpoint
*b
)
6511 int print_address_bits
= 0;
6513 /* Software watchpoints that aren't watching memory don't have an
6514 address to print. */
6515 if (is_no_memory_software_watchpoint (b
))
6518 for (bp_location
*loc
: b
->locations ())
6522 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6523 if (addr_bit
> print_address_bits
)
6524 print_address_bits
= addr_bit
;
6527 return print_address_bits
;
6530 /* See breakpoint.h. */
6533 print_breakpoint (breakpoint
*b
)
6535 struct bp_location
*dummy_loc
= NULL
;
6536 print_one_breakpoint (b
, &dummy_loc
, 0);
6539 /* Return true if this breakpoint was set by the user, false if it is
6540 internal or momentary. */
6543 user_breakpoint_p (struct breakpoint
*b
)
6545 return b
->number
> 0;
6548 /* See breakpoint.h. */
6551 pending_breakpoint_p (struct breakpoint
*b
)
6553 return b
->loc
== NULL
;
6556 /* Print information on breakpoints (including watchpoints and tracepoints).
6558 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6559 understood by number_or_range_parser. Only breakpoints included in this
6560 list are then printed.
6562 If SHOW_INTERNAL is true, print internal breakpoints.
6564 If FILTER is non-NULL, call it on each breakpoint and only include the
6565 ones for which it returns true.
6567 Return the total number of breakpoints listed. */
6570 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6571 bool (*filter
) (const struct breakpoint
*))
6573 struct bp_location
*last_loc
= NULL
;
6574 int nr_printable_breakpoints
;
6575 struct value_print_options opts
;
6576 int print_address_bits
= 0;
6577 int print_type_col_width
= 14;
6578 struct ui_out
*uiout
= current_uiout
;
6579 bool has_disabled_by_cond_location
= false;
6581 get_user_print_options (&opts
);
6583 /* Compute the number of rows in the table, as well as the size
6584 required for address fields. */
6585 nr_printable_breakpoints
= 0;
6586 for (breakpoint
*b
: all_breakpoints ())
6588 /* If we have a filter, only list the breakpoints it accepts. */
6589 if (filter
&& !filter (b
))
6592 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6593 accept. Skip the others. */
6594 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6596 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6598 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6602 if (show_internal
|| user_breakpoint_p (b
))
6604 int addr_bit
, type_len
;
6606 addr_bit
= breakpoint_address_bits (b
);
6607 if (addr_bit
> print_address_bits
)
6608 print_address_bits
= addr_bit
;
6610 type_len
= strlen (bptype_string (b
->type
));
6611 if (type_len
> print_type_col_width
)
6612 print_type_col_width
= type_len
;
6614 nr_printable_breakpoints
++;
6619 ui_out_emit_table
table_emitter (uiout
,
6620 opts
.addressprint
? 6 : 5,
6621 nr_printable_breakpoints
,
6624 if (nr_printable_breakpoints
> 0)
6625 annotate_breakpoints_headers ();
6626 if (nr_printable_breakpoints
> 0)
6628 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6629 if (nr_printable_breakpoints
> 0)
6631 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6632 if (nr_printable_breakpoints
> 0)
6634 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6635 if (nr_printable_breakpoints
> 0)
6637 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6638 if (opts
.addressprint
)
6640 if (nr_printable_breakpoints
> 0)
6642 if (print_address_bits
<= 32)
6643 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6645 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6647 if (nr_printable_breakpoints
> 0)
6649 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6650 uiout
->table_body ();
6651 if (nr_printable_breakpoints
> 0)
6652 annotate_breakpoints_table ();
6654 for (breakpoint
*b
: all_breakpoints ())
6657 /* If we have a filter, only list the breakpoints it accepts. */
6658 if (filter
&& !filter (b
))
6661 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6662 accept. Skip the others. */
6664 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6666 if (show_internal
) /* maintenance info breakpoint */
6668 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6671 else /* all others */
6673 if (!number_is_in_list (bp_num_list
, b
->number
))
6677 /* We only print out user settable breakpoints unless the
6678 show_internal is set. */
6679 if (show_internal
|| user_breakpoint_p (b
))
6681 print_one_breakpoint (b
, &last_loc
, show_internal
);
6682 for (bp_location
*loc
: b
->locations ())
6683 if (loc
->disabled_by_cond
)
6684 has_disabled_by_cond_location
= true;
6689 if (nr_printable_breakpoints
== 0)
6691 /* If there's a filter, let the caller decide how to report
6695 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6696 uiout
->message ("No breakpoints or watchpoints.\n");
6698 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6704 if (last_loc
&& !server_command
)
6705 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6707 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6708 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6712 /* FIXME? Should this be moved up so that it is only called when
6713 there have been breakpoints? */
6714 annotate_breakpoints_table_end ();
6716 return nr_printable_breakpoints
;
6719 /* Display the value of default-collect in a way that is generally
6720 compatible with the breakpoint list. */
6723 default_collect_info (void)
6725 struct ui_out
*uiout
= current_uiout
;
6727 /* If it has no value (which is frequently the case), say nothing; a
6728 message like "No default-collect." gets in user's face when it's
6730 if (default_collect
.empty ())
6733 /* The following phrase lines up nicely with per-tracepoint collect
6735 uiout
->text ("default collect ");
6736 uiout
->field_string ("default-collect", default_collect
);
6737 uiout
->text (" \n");
6741 info_breakpoints_command (const char *args
, int from_tty
)
6743 breakpoint_1 (args
, false, NULL
);
6745 default_collect_info ();
6749 info_watchpoints_command (const char *args
, int from_tty
)
6751 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6752 struct ui_out
*uiout
= current_uiout
;
6754 if (num_printed
== 0)
6756 if (args
== NULL
|| *args
== '\0')
6757 uiout
->message ("No watchpoints.\n");
6759 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6764 maintenance_info_breakpoints (const char *args
, int from_tty
)
6766 breakpoint_1 (args
, true, NULL
);
6768 default_collect_info ();
6772 breakpoint_has_pc (struct breakpoint
*b
,
6773 struct program_space
*pspace
,
6774 CORE_ADDR pc
, struct obj_section
*section
)
6776 for (bp_location
*bl
: b
->locations ())
6778 if (bl
->pspace
== pspace
6779 && bl
->address
== pc
6780 && (!overlay_debugging
|| bl
->section
== section
))
6786 /* Print a message describing any user-breakpoints set at PC. This
6787 concerns with logical breakpoints, so we match program spaces, not
6791 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6792 struct program_space
*pspace
, CORE_ADDR pc
,
6793 struct obj_section
*section
, int thread
)
6797 for (breakpoint
*b
: all_breakpoints ())
6798 others
+= (user_breakpoint_p (b
)
6799 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6804 gdb_printf (_("Note: breakpoint "));
6805 else /* if (others == ???) */
6806 gdb_printf (_("Note: breakpoints "));
6807 for (breakpoint
*b
: all_breakpoints ())
6808 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6811 gdb_printf ("%d", b
->number
);
6812 if (b
->thread
== -1 && thread
!= -1)
6813 gdb_printf (" (all threads)");
6814 else if (b
->thread
!= -1)
6815 gdb_printf (" (thread %d)", b
->thread
);
6816 gdb_printf ("%s%s ",
6817 ((b
->enable_state
== bp_disabled
6818 || b
->enable_state
== bp_call_disabled
)
6822 : ((others
== 1) ? " and" : ""));
6824 current_uiout
->message (_("also set at pc %ps.\n"),
6825 styled_string (address_style
.style (),
6826 paddress (gdbarch
, pc
)));
6831 /* Return true iff it is meaningful to use the address member of LOC.
6832 For some breakpoint types, the locations' address members are
6833 irrelevant and it makes no sense to attempt to compare them to
6834 other addresses (or use them for any other purpose either).
6836 More specifically, software watchpoints and catchpoints that are
6837 not backed by breakpoints always have a zero valued location
6838 address and we don't want to mark breakpoints of any of these types
6839 to be a duplicate of an actual breakpoint location at address
6843 bl_address_is_meaningful (bp_location
*loc
)
6845 return loc
->loc_type
!= bp_loc_other
;
6848 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6849 true if LOC1 and LOC2 represent the same watchpoint location. */
6852 watchpoint_locations_match (struct bp_location
*loc1
,
6853 struct bp_location
*loc2
)
6855 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6856 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6858 /* Both of them must exist. */
6859 gdb_assert (w1
!= NULL
);
6860 gdb_assert (w2
!= NULL
);
6862 /* If the target can evaluate the condition expression in hardware,
6863 then we we need to insert both watchpoints even if they are at
6864 the same place. Otherwise the watchpoint will only trigger when
6865 the condition of whichever watchpoint was inserted evaluates to
6866 true, not giving a chance for GDB to check the condition of the
6867 other watchpoint. */
6869 && target_can_accel_watchpoint_condition (loc1
->address
,
6871 loc1
->watchpoint_type
,
6872 w1
->cond_exp
.get ()))
6874 && target_can_accel_watchpoint_condition (loc2
->address
,
6876 loc2
->watchpoint_type
,
6877 w2
->cond_exp
.get ())))
6880 /* Note that this checks the owner's type, not the location's. In
6881 case the target does not support read watchpoints, but does
6882 support access watchpoints, we'll have bp_read_watchpoint
6883 watchpoints with hw_access locations. Those should be considered
6884 duplicates of hw_read locations. The hw_read locations will
6885 become hw_access locations later. */
6886 return (loc1
->owner
->type
== loc2
->owner
->type
6887 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6888 && loc1
->address
== loc2
->address
6889 && loc1
->length
== loc2
->length
);
6892 /* See breakpoint.h. */
6895 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6896 const address_space
*aspace2
, CORE_ADDR addr2
)
6898 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6899 || aspace1
== aspace2
)
6903 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6904 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6905 matches ASPACE2. On targets that have global breakpoints, the address
6906 space doesn't really matter. */
6909 breakpoint_address_match_range (const address_space
*aspace1
,
6911 int len1
, const address_space
*aspace2
,
6914 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6915 || aspace1
== aspace2
)
6916 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6919 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6920 a ranged breakpoint. In most targets, a match happens only if ASPACE
6921 matches the breakpoint's address space. On targets that have global
6922 breakpoints, the address space doesn't really matter. */
6925 breakpoint_location_address_match (struct bp_location
*bl
,
6926 const address_space
*aspace
,
6929 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6932 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6933 bl
->address
, bl
->length
,
6937 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6938 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6939 match happens only if ASPACE matches the breakpoint's address
6940 space. On targets that have global breakpoints, the address space
6941 doesn't really matter. */
6944 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6945 const address_space
*aspace
,
6946 CORE_ADDR addr
, int len
)
6948 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6949 || bl
->pspace
->aspace
== aspace
)
6951 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6953 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6959 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6960 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6961 true, otherwise returns false. */
6964 tracepoint_locations_match (struct bp_location
*loc1
,
6965 struct bp_location
*loc2
)
6967 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6968 /* Since tracepoint locations are never duplicated with others', tracepoint
6969 locations at the same address of different tracepoints are regarded as
6970 different locations. */
6971 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6976 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6977 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6978 the same location. If SW_HW_BPS_MATCH is true, then software
6979 breakpoint locations and hardware breakpoint locations match,
6980 otherwise they don't. */
6983 breakpoint_locations_match (struct bp_location
*loc1
,
6984 struct bp_location
*loc2
,
6985 bool sw_hw_bps_match
)
6987 int hw_point1
, hw_point2
;
6989 /* Both of them must not be in moribund_locations. */
6990 gdb_assert (loc1
->owner
!= NULL
);
6991 gdb_assert (loc2
->owner
!= NULL
);
6993 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6994 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6996 if (hw_point1
!= hw_point2
)
6999 return watchpoint_locations_match (loc1
, loc2
);
7000 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7001 return tracepoint_locations_match (loc1
, loc2
);
7003 /* We compare bp_location.length in order to cover ranged
7004 breakpoints. Keep this in sync with
7005 bp_location_is_less_than. */
7006 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7007 loc2
->pspace
->aspace
, loc2
->address
)
7008 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7009 && loc1
->length
== loc2
->length
);
7013 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7014 int bnum
, int have_bnum
)
7016 /* The longest string possibly returned by hex_string_custom
7017 is 50 chars. These must be at least that big for safety. */
7021 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7022 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7024 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7025 bnum
, astr1
, astr2
);
7027 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7030 /* Adjust a breakpoint's address to account for architectural
7031 constraints on breakpoint placement. Return the adjusted address.
7032 Note: Very few targets require this kind of adjustment. For most
7033 targets, this function is simply the identity function. */
7036 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7037 CORE_ADDR bpaddr
, enum bptype bptype
)
7039 if (bptype
== bp_watchpoint
7040 || bptype
== bp_hardware_watchpoint
7041 || bptype
== bp_read_watchpoint
7042 || bptype
== bp_access_watchpoint
7043 || bptype
== bp_catchpoint
)
7045 /* Watchpoints and the various bp_catch_* eventpoints should not
7046 have their addresses modified. */
7049 else if (bptype
== bp_single_step
)
7051 /* Single-step breakpoints should not have their addresses
7052 modified. If there's any architectural constrain that
7053 applies to this address, then it should have already been
7054 taken into account when the breakpoint was created in the
7055 first place. If we didn't do this, stepping through e.g.,
7056 Thumb-2 IT blocks would break. */
7061 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7063 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7065 /* Some targets have architectural constraints on the placement
7066 of breakpoint instructions. Obtain the adjusted address. */
7067 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7070 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7072 /* An adjusted breakpoint address can significantly alter
7073 a user's expectations. Print a warning if an adjustment
7075 if (adjusted_bpaddr
!= bpaddr
)
7076 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7078 return adjusted_bpaddr
;
7083 bp_location_from_bp_type (bptype type
)
7088 case bp_single_step
:
7092 case bp_longjmp_resume
:
7093 case bp_longjmp_call_dummy
:
7095 case bp_exception_resume
:
7096 case bp_step_resume
:
7097 case bp_hp_step_resume
:
7098 case bp_watchpoint_scope
:
7100 case bp_std_terminate
:
7101 case bp_shlib_event
:
7102 case bp_thread_event
:
7103 case bp_overlay_event
:
7105 case bp_longjmp_master
:
7106 case bp_std_terminate_master
:
7107 case bp_exception_master
:
7108 case bp_gnu_ifunc_resolver
:
7109 case bp_gnu_ifunc_resolver_return
:
7111 return bp_loc_software_breakpoint
;
7112 case bp_hardware_breakpoint
:
7113 return bp_loc_hardware_breakpoint
;
7114 case bp_hardware_watchpoint
:
7115 case bp_read_watchpoint
:
7116 case bp_access_watchpoint
:
7117 return bp_loc_hardware_watchpoint
;
7121 case bp_fast_tracepoint
:
7122 case bp_static_tracepoint
:
7123 return bp_loc_other
;
7125 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7129 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7131 this->owner
= owner
;
7132 this->cond_bytecode
= NULL
;
7133 this->shlib_disabled
= 0;
7135 this->disabled_by_cond
= false;
7137 this->loc_type
= type
;
7139 if (this->loc_type
== bp_loc_software_breakpoint
7140 || this->loc_type
== bp_loc_hardware_breakpoint
)
7141 mark_breakpoint_location_modified (this);
7146 bp_location::bp_location (breakpoint
*owner
)
7147 : bp_location::bp_location (owner
,
7148 bp_location_from_bp_type (owner
->type
))
7152 /* Allocate a struct bp_location. */
7154 static struct bp_location
*
7155 allocate_bp_location (struct breakpoint
*bpt
)
7157 return bpt
->ops
->allocate_location (bpt
);
7160 /* Decrement reference count. If the reference count reaches 0,
7161 destroy the bp_location. Sets *BLP to NULL. */
7164 decref_bp_location (struct bp_location
**blp
)
7166 bp_location_ref_policy::decref (*blp
);
7170 /* Add breakpoint B at the end of the global breakpoint chain. */
7173 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7175 struct breakpoint
*b1
;
7176 struct breakpoint
*result
= b
.get ();
7178 /* Add this breakpoint to the end of the chain so that a list of
7179 breakpoints will come out in order of increasing numbers. */
7181 b1
= breakpoint_chain
;
7183 breakpoint_chain
= b
.release ();
7188 b1
->next
= b
.release ();
7194 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7197 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7198 struct gdbarch
*gdbarch
,
7200 const struct breakpoint_ops
*ops
)
7202 gdb_assert (ops
!= NULL
);
7206 b
->gdbarch
= gdbarch
;
7207 b
->language
= current_language
->la_language
;
7208 b
->input_radix
= input_radix
;
7209 b
->related_breakpoint
= b
;
7212 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7213 that has type BPTYPE and has no locations as yet. */
7215 static struct breakpoint
*
7216 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7218 const struct breakpoint_ops
*ops
)
7220 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7222 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7223 return add_to_breakpoint_chain (std::move (b
));
7226 /* Initialize loc->function_name. */
7229 set_breakpoint_location_function (struct bp_location
*loc
)
7231 gdb_assert (loc
->owner
!= NULL
);
7233 if (loc
->owner
->type
== bp_breakpoint
7234 || loc
->owner
->type
== bp_hardware_breakpoint
7235 || is_tracepoint (loc
->owner
))
7237 const char *function_name
;
7239 if (loc
->msymbol
!= NULL
7240 && (loc
->msymbol
->type () == mst_text_gnu_ifunc
7241 || loc
->msymbol
->type () == mst_data_gnu_ifunc
))
7243 struct breakpoint
*b
= loc
->owner
;
7245 function_name
= loc
->msymbol
->linkage_name ();
7247 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7248 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7250 /* Create only the whole new breakpoint of this type but do not
7251 mess more complicated breakpoints with multiple locations. */
7252 b
->type
= bp_gnu_ifunc_resolver
;
7253 /* Remember the resolver's address for use by the return
7255 loc
->related_address
= loc
->address
;
7259 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7262 loc
->function_name
= make_unique_xstrdup (function_name
);
7266 /* Attempt to determine architecture of location identified by SAL. */
7268 get_sal_arch (struct symtab_and_line sal
)
7271 return sal
.section
->objfile
->arch ();
7273 return sal
.symtab
->compunit ()->objfile ()->arch ();
7278 /* Low level routine for partially initializing a breakpoint of type
7279 BPTYPE. The newly created breakpoint's address, section, source
7280 file name, and line number are provided by SAL.
7282 It is expected that the caller will complete the initialization of
7283 the newly created breakpoint struct as well as output any status
7284 information regarding the creation of a new breakpoint. */
7287 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7288 struct symtab_and_line sal
, enum bptype bptype
,
7289 const struct breakpoint_ops
*ops
)
7291 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7293 add_location_to_breakpoint (b
, &sal
);
7295 if (bptype
!= bp_catchpoint
)
7296 gdb_assert (sal
.pspace
!= NULL
);
7298 /* Store the program space that was used to set the breakpoint,
7299 except for ordinary breakpoints, which are independent of the
7301 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7302 b
->pspace
= sal
.pspace
;
7305 /* set_raw_breakpoint is a low level routine for allocating and
7306 partially initializing a breakpoint of type BPTYPE. The newly
7307 created breakpoint's address, section, source file name, and line
7308 number are provided by SAL. The newly created and partially
7309 initialized breakpoint is added to the breakpoint chain and
7310 is also returned as the value of this function.
7312 It is expected that the caller will complete the initialization of
7313 the newly created breakpoint struct as well as output any status
7314 information regarding the creation of a new breakpoint. In
7315 particular, set_raw_breakpoint does NOT set the breakpoint
7316 number! Care should be taken to not allow an error to occur
7317 prior to completing the initialization of the breakpoint. If this
7318 should happen, a bogus breakpoint will be left on the chain. */
7320 static struct breakpoint
*
7321 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7322 struct symtab_and_line sal
, enum bptype bptype
,
7323 const struct breakpoint_ops
*ops
)
7325 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7327 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7328 return add_to_breakpoint_chain (std::move (b
));
7331 /* Call this routine when stepping and nexting to enable a breakpoint
7332 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7333 initiated the operation. */
7336 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7338 int thread
= tp
->global_num
;
7340 /* To avoid having to rescan all objfile symbols at every step,
7341 we maintain a list of continually-inserted but always disabled
7342 longjmp "master" breakpoints. Here, we simply create momentary
7343 clones of those and enable them for the requested thread. */
7344 for (breakpoint
*b
: all_breakpoints_safe ())
7345 if (b
->pspace
== current_program_space
7346 && (b
->type
== bp_longjmp_master
7347 || b
->type
== bp_exception_master
))
7349 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7350 struct breakpoint
*clone
;
7352 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7353 after their removal. */
7354 clone
= momentary_breakpoint_from_master (b
, type
,
7355 &vtable_breakpoint_ops
, 1);
7356 clone
->thread
= thread
;
7359 tp
->initiating_frame
= frame
;
7362 /* Delete all longjmp breakpoints from THREAD. */
7364 delete_longjmp_breakpoint (int thread
)
7366 for (breakpoint
*b
: all_breakpoints_safe ())
7367 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7369 if (b
->thread
== thread
)
7370 delete_breakpoint (b
);
7375 delete_longjmp_breakpoint_at_next_stop (int thread
)
7377 for (breakpoint
*b
: all_breakpoints_safe ())
7378 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7380 if (b
->thread
== thread
)
7381 b
->disposition
= disp_del_at_next_stop
;
7385 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7386 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7387 pointer to any of them. Return NULL if this system cannot place longjmp
7391 set_longjmp_breakpoint_for_call_dummy (void)
7393 breakpoint
*retval
= nullptr;
7395 for (breakpoint
*b
: all_breakpoints ())
7396 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7398 struct breakpoint
*new_b
;
7400 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7401 &vtable_breakpoint_ops
,
7403 new_b
->thread
= inferior_thread ()->global_num
;
7405 /* Link NEW_B into the chain of RETVAL breakpoints. */
7407 gdb_assert (new_b
->related_breakpoint
== new_b
);
7410 new_b
->related_breakpoint
= retval
;
7411 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7412 retval
= retval
->related_breakpoint
;
7413 retval
->related_breakpoint
= new_b
;
7419 /* Verify all existing dummy frames and their associated breakpoints for
7420 TP. Remove those which can no longer be found in the current frame
7423 If the unwind fails then there is not sufficient information to discard
7424 dummy frames. In this case, elide the clean up and the dummy frames will
7425 be cleaned up next time this function is called from a location where
7426 unwinding is possible. */
7429 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7431 struct breakpoint
*b
, *b_tmp
;
7433 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7434 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7436 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7438 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7439 chained off b->related_breakpoint. */
7440 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7441 dummy_b
= dummy_b
->related_breakpoint
;
7443 /* If there was no bp_call_dummy breakpoint then there's nothing
7444 more to do. Or, if the dummy frame associated with the
7445 bp_call_dummy is still on the stack then we need to leave this
7446 bp_call_dummy in place. */
7447 if (dummy_b
->type
!= bp_call_dummy
7448 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7451 /* We didn't find the dummy frame on the stack, this could be
7452 because we have longjmp'd to a stack frame that is previous to
7453 the dummy frame, or it could be because the stack unwind is
7454 broken at some point between the longjmp frame and the dummy
7457 Next we figure out why the stack unwind stopped. If it looks
7458 like the unwind is complete then we assume the dummy frame has
7459 been jumped over, however, if the unwind stopped for an
7460 unexpected reason then we assume the stack unwind is currently
7461 broken, and that we will (eventually) return to the dummy
7464 It might be tempting to consider using frame_id_inner here, but
7465 that is not safe. There is no guarantee that the stack frames
7466 we are looking at here are even on the same stack as the
7467 original dummy frame, hence frame_id_inner can't be used. See
7468 the comments on frame_id_inner for more details. */
7469 bool unwind_finished_unexpectedly
= false;
7470 for (struct frame_info
*fi
= get_current_frame (); fi
!= nullptr; )
7472 struct frame_info
*prev
= get_prev_frame (fi
);
7473 if (prev
== nullptr)
7475 /* FI is the last stack frame. Why did this frame not
7477 auto stop_reason
= get_frame_unwind_stop_reason (fi
);
7478 if (stop_reason
!= UNWIND_NO_REASON
7479 && stop_reason
!= UNWIND_OUTERMOST
)
7480 unwind_finished_unexpectedly
= true;
7484 if (unwind_finished_unexpectedly
)
7487 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7489 while (b
->related_breakpoint
!= b
)
7491 if (b_tmp
== b
->related_breakpoint
)
7492 b_tmp
= b
->related_breakpoint
->next
;
7493 delete_breakpoint (b
->related_breakpoint
);
7495 delete_breakpoint (b
);
7500 enable_overlay_breakpoints (void)
7502 for (breakpoint
*b
: all_breakpoints ())
7503 if (b
->type
== bp_overlay_event
)
7505 b
->enable_state
= bp_enabled
;
7506 update_global_location_list (UGLL_MAY_INSERT
);
7507 overlay_events_enabled
= 1;
7512 disable_overlay_breakpoints (void)
7514 for (breakpoint
*b
: all_breakpoints ())
7515 if (b
->type
== bp_overlay_event
)
7517 b
->enable_state
= bp_disabled
;
7518 update_global_location_list (UGLL_DONT_INSERT
);
7519 overlay_events_enabled
= 0;
7523 /* Set an active std::terminate breakpoint for each std::terminate
7524 master breakpoint. */
7526 set_std_terminate_breakpoint (void)
7528 for (breakpoint
*b
: all_breakpoints_safe ())
7529 if (b
->pspace
== current_program_space
7530 && b
->type
== bp_std_terminate_master
)
7532 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7533 &vtable_breakpoint_ops
, 1);
7537 /* Delete all the std::terminate breakpoints. */
7539 delete_std_terminate_breakpoint (void)
7541 for (breakpoint
*b
: all_breakpoints_safe ())
7542 if (b
->type
== bp_std_terminate
)
7543 delete_breakpoint (b
);
7547 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7549 struct breakpoint
*b
;
7551 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7552 &vtable_breakpoint_ops
);
7554 b
->enable_state
= bp_enabled
;
7555 /* location has to be used or breakpoint_re_set will delete me. */
7556 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7558 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7563 struct lang_and_radix
7569 /* Create a breakpoint for JIT code registration and unregistration. */
7572 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7574 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7575 &vtable_breakpoint_ops
);
7578 /* Remove JIT code registration and unregistration breakpoint(s). */
7581 remove_jit_event_breakpoints (void)
7583 for (breakpoint
*b
: all_breakpoints_safe ())
7584 if (b
->type
== bp_jit_event
7585 && b
->loc
->pspace
== current_program_space
)
7586 delete_breakpoint (b
);
7590 remove_solib_event_breakpoints (void)
7592 for (breakpoint
*b
: all_breakpoints_safe ())
7593 if (b
->type
== bp_shlib_event
7594 && b
->loc
->pspace
== current_program_space
)
7595 delete_breakpoint (b
);
7598 /* See breakpoint.h. */
7601 remove_solib_event_breakpoints_at_next_stop (void)
7603 for (breakpoint
*b
: all_breakpoints_safe ())
7604 if (b
->type
== bp_shlib_event
7605 && b
->loc
->pspace
== current_program_space
)
7606 b
->disposition
= disp_del_at_next_stop
;
7609 /* Helper for create_solib_event_breakpoint /
7610 create_and_insert_solib_event_breakpoint. Allows specifying which
7611 INSERT_MODE to pass through to update_global_location_list. */
7613 static struct breakpoint
*
7614 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7615 enum ugll_insert_mode insert_mode
)
7617 struct breakpoint
*b
;
7619 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7620 &vtable_breakpoint_ops
);
7621 update_global_location_list_nothrow (insert_mode
);
7626 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7628 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7631 /* See breakpoint.h. */
7634 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7636 struct breakpoint
*b
;
7638 /* Explicitly tell update_global_location_list to insert
7640 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7641 if (!b
->loc
->inserted
)
7643 delete_breakpoint (b
);
7649 /* Disable any breakpoints that are on code in shared libraries. Only
7650 apply to enabled breakpoints, disabled ones can just stay disabled. */
7653 disable_breakpoints_in_shlibs (void)
7655 for (bp_location
*loc
: all_bp_locations ())
7657 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7658 struct breakpoint
*b
= loc
->owner
;
7660 /* We apply the check to all breakpoints, including disabled for
7661 those with loc->duplicate set. This is so that when breakpoint
7662 becomes enabled, or the duplicate is removed, gdb will try to
7663 insert all breakpoints. If we don't set shlib_disabled here,
7664 we'll try to insert those breakpoints and fail. */
7665 if (((b
->type
== bp_breakpoint
)
7666 || (b
->type
== bp_jit_event
)
7667 || (b
->type
== bp_hardware_breakpoint
)
7668 || (is_tracepoint (b
)))
7669 && loc
->pspace
== current_program_space
7670 && !loc
->shlib_disabled
7671 && solib_name_from_address (loc
->pspace
, loc
->address
)
7674 loc
->shlib_disabled
= 1;
7679 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7680 notification of unloaded_shlib. Only apply to enabled breakpoints,
7681 disabled ones can just stay disabled. */
7684 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7686 int disabled_shlib_breaks
= 0;
7688 for (bp_location
*loc
: all_bp_locations ())
7690 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7691 struct breakpoint
*b
= loc
->owner
;
7693 if (solib
->pspace
== loc
->pspace
7694 && !loc
->shlib_disabled
7695 && (((b
->type
== bp_breakpoint
7696 || b
->type
== bp_jit_event
7697 || b
->type
== bp_hardware_breakpoint
)
7698 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7699 || loc
->loc_type
== bp_loc_software_breakpoint
))
7700 || is_tracepoint (b
))
7701 && solib_contains_address_p (solib
, loc
->address
))
7703 loc
->shlib_disabled
= 1;
7704 /* At this point, we cannot rely on remove_breakpoint
7705 succeeding so we must mark the breakpoint as not inserted
7706 to prevent future errors occurring in remove_breakpoints. */
7709 /* This may cause duplicate notifications for the same breakpoint. */
7710 gdb::observers::breakpoint_modified
.notify (b
);
7712 if (!disabled_shlib_breaks
)
7714 target_terminal::ours_for_output ();
7715 warning (_("Temporarily disabling breakpoints "
7716 "for unloaded shared library \"%s\""),
7719 disabled_shlib_breaks
= 1;
7724 /* Disable any breakpoints and tracepoints in OBJFILE upon
7725 notification of free_objfile. Only apply to enabled breakpoints,
7726 disabled ones can just stay disabled. */
7729 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7731 if (objfile
== NULL
)
7734 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7735 managed by the user with add-symbol-file/remove-symbol-file.
7736 Similarly to how breakpoints in shared libraries are handled in
7737 response to "nosharedlibrary", mark breakpoints in such modules
7738 shlib_disabled so they end up uninserted on the next global
7739 location list update. Shared libraries not loaded by the user
7740 aren't handled here -- they're already handled in
7741 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7742 solib_unloaded observer. We skip objfiles that are not
7743 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7745 if ((objfile
->flags
& OBJF_SHARED
) == 0
7746 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7749 for (breakpoint
*b
: all_breakpoints ())
7751 int bp_modified
= 0;
7753 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7756 for (bp_location
*loc
: b
->locations ())
7758 CORE_ADDR loc_addr
= loc
->address
;
7760 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7761 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7764 if (loc
->shlib_disabled
!= 0)
7767 if (objfile
->pspace
!= loc
->pspace
)
7770 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7771 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7774 if (is_addr_in_objfile (loc_addr
, objfile
))
7776 loc
->shlib_disabled
= 1;
7777 /* At this point, we don't know whether the object was
7778 unmapped from the inferior or not, so leave the
7779 inserted flag alone. We'll handle failure to
7780 uninsert quietly, in case the object was indeed
7783 mark_breakpoint_location_modified (loc
);
7790 gdb::observers::breakpoint_modified
.notify (b
);
7794 /* See breakpoint.h. */
7797 init_catchpoint (struct breakpoint
*b
,
7798 struct gdbarch
*gdbarch
, bool temp
,
7799 const char *cond_string
,
7800 const struct breakpoint_ops
*ops
)
7802 symtab_and_line sal
;
7803 sal
.pspace
= current_program_space
;
7805 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
7807 if (cond_string
== nullptr)
7808 b
->cond_string
.reset ();
7810 b
->cond_string
= make_unique_xstrdup (cond_string
);
7811 b
->disposition
= temp
? disp_del
: disp_donttouch
;
7815 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
7817 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
7818 set_breakpoint_number (internal
, b
);
7819 if (is_tracepoint (b
))
7820 set_tracepoint_count (breakpoint_count
);
7823 gdb::observers::breakpoint_created
.notify (b
);
7826 update_global_location_list (UGLL_MAY_INSERT
);
7830 hw_breakpoint_used_count (void)
7834 for (breakpoint
*b
: all_breakpoints ())
7835 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
7836 for (bp_location
*bl
: b
->locations ())
7838 /* Special types of hardware breakpoints may use more than
7840 i
+= b
->ops
->resources_needed (bl
);
7846 /* Returns the resources B would use if it were a hardware
7850 hw_watchpoint_use_count (struct breakpoint
*b
)
7854 if (!breakpoint_enabled (b
))
7857 for (bp_location
*bl
: b
->locations ())
7859 /* Special types of hardware watchpoints may use more than
7861 i
+= b
->ops
->resources_needed (bl
);
7867 /* Returns the sum the used resources of all hardware watchpoints of
7868 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
7869 the sum of the used resources of all hardware watchpoints of other
7870 types _not_ TYPE. */
7873 hw_watchpoint_used_count_others (struct breakpoint
*except
,
7874 enum bptype type
, int *other_type_used
)
7878 *other_type_used
= 0;
7879 for (breakpoint
*b
: all_breakpoints ())
7883 if (!breakpoint_enabled (b
))
7886 if (b
->type
== type
)
7887 i
+= hw_watchpoint_use_count (b
);
7888 else if (is_hardware_watchpoint (b
))
7889 *other_type_used
= 1;
7896 disable_watchpoints_before_interactive_call_start (void)
7898 for (breakpoint
*b
: all_breakpoints ())
7899 if (is_watchpoint (b
) && breakpoint_enabled (b
))
7901 b
->enable_state
= bp_call_disabled
;
7902 update_global_location_list (UGLL_DONT_INSERT
);
7907 enable_watchpoints_after_interactive_call_stop (void)
7909 for (breakpoint
*b
: all_breakpoints ())
7910 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
7912 b
->enable_state
= bp_enabled
;
7913 update_global_location_list (UGLL_MAY_INSERT
);
7918 disable_breakpoints_before_startup (void)
7920 current_program_space
->executing_startup
= 1;
7921 update_global_location_list (UGLL_DONT_INSERT
);
7925 enable_breakpoints_after_startup (void)
7927 current_program_space
->executing_startup
= 0;
7928 breakpoint_re_set ();
7931 /* Create a new single-step breakpoint for thread THREAD, with no
7934 static struct breakpoint
*
7935 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
7937 std::unique_ptr
<breakpoint
> b (new momentary_breakpoint ());
7939 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
7940 &vtable_breakpoint_ops
);
7942 b
->disposition
= disp_donttouch
;
7943 b
->frame_id
= null_frame_id
;
7946 gdb_assert (b
->thread
!= 0);
7948 return add_to_breakpoint_chain (std::move (b
));
7951 /* Set a momentary breakpoint of type TYPE at address specified by
7952 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
7956 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7957 struct frame_id frame_id
, enum bptype type
)
7959 struct breakpoint
*b
;
7961 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
7963 gdb_assert (!frame_id_artificial_p (frame_id
));
7965 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &vtable_breakpoint_ops
);
7966 b
->enable_state
= bp_enabled
;
7967 b
->disposition
= disp_donttouch
;
7968 b
->frame_id
= frame_id
;
7970 b
->thread
= inferior_thread ()->global_num
;
7972 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7974 return breakpoint_up (b
);
7977 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7978 The new breakpoint will have type TYPE, use OPS as its
7979 breakpoint_ops, and will set enabled to LOC_ENABLED. */
7981 static struct breakpoint
*
7982 momentary_breakpoint_from_master (struct breakpoint
*orig
,
7984 const struct breakpoint_ops
*ops
,
7987 struct breakpoint
*copy
;
7989 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
7990 copy
->loc
= allocate_bp_location (copy
);
7991 set_breakpoint_location_function (copy
->loc
);
7993 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7994 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7995 copy
->loc
->address
= orig
->loc
->address
;
7996 copy
->loc
->section
= orig
->loc
->section
;
7997 copy
->loc
->pspace
= orig
->loc
->pspace
;
7998 copy
->loc
->probe
= orig
->loc
->probe
;
7999 copy
->loc
->line_number
= orig
->loc
->line_number
;
8000 copy
->loc
->symtab
= orig
->loc
->symtab
;
8001 copy
->loc
->enabled
= loc_enabled
;
8002 copy
->frame_id
= orig
->frame_id
;
8003 copy
->thread
= orig
->thread
;
8004 copy
->pspace
= orig
->pspace
;
8006 copy
->enable_state
= bp_enabled
;
8007 copy
->disposition
= disp_donttouch
;
8008 copy
->number
= internal_breakpoint_number
--;
8010 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8014 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8018 clone_momentary_breakpoint (struct breakpoint
*orig
)
8020 /* If there's nothing to clone, then return nothing. */
8024 gdb_assert (orig
->ops
== &vtable_breakpoint_ops
);
8025 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8029 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8032 struct symtab_and_line sal
;
8034 sal
= find_pc_line (pc
, 0);
8036 sal
.section
= find_pc_overlay (pc
);
8037 sal
.explicit_pc
= 1;
8039 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8043 /* Tell the user we have just set a breakpoint B. */
8046 mention (struct breakpoint
*b
)
8048 b
->ops
->print_mention (b
);
8049 current_uiout
->text ("\n");
8053 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8055 /* Handle "set breakpoint auto-hw on".
8057 If the explicitly specified breakpoint type is not hardware
8058 breakpoint, check the memory map to see whether the breakpoint
8059 address is in read-only memory.
8061 - location type is not hardware breakpoint, memory is read-only.
8062 We change the type of the location to hardware breakpoint.
8064 - location type is hardware breakpoint, memory is read-write. This
8065 means we've previously made the location hardware one, but then the
8066 memory map changed, so we undo.
8070 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8072 if (automatic_hardware_breakpoints
8073 && bl
->owner
->type
!= bp_hardware_breakpoint
8074 && (bl
->loc_type
== bp_loc_software_breakpoint
8075 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8077 /* When breakpoints are removed, remove_breakpoints will use
8078 location types we've just set here, the only possible problem
8079 is that memory map has changed during running program, but
8080 it's not going to work anyway with current gdb. */
8081 mem_region
*mr
= lookup_mem_region (bl
->address
);
8085 enum bp_loc_type new_type
;
8087 if (mr
->attrib
.mode
!= MEM_RW
)
8088 new_type
= bp_loc_hardware_breakpoint
;
8090 new_type
= bp_loc_software_breakpoint
;
8092 if (new_type
!= bl
->loc_type
)
8094 static bool said
= false;
8096 bl
->loc_type
= new_type
;
8099 gdb_printf (_("Note: automatically using "
8100 "hardware breakpoints for "
8101 "read-only addresses.\n"));
8109 static struct bp_location
*
8110 add_location_to_breakpoint (struct breakpoint
*b
,
8111 const struct symtab_and_line
*sal
)
8113 struct bp_location
*loc
, **tmp
;
8114 CORE_ADDR adjusted_address
;
8115 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8117 if (loc_gdbarch
== NULL
)
8118 loc_gdbarch
= b
->gdbarch
;
8120 /* Adjust the breakpoint's address prior to allocating a location.
8121 Once we call allocate_bp_location(), that mostly uninitialized
8122 location will be placed on the location chain. Adjustment of the
8123 breakpoint may cause target_read_memory() to be called and we do
8124 not want its scan of the location chain to find a breakpoint and
8125 location that's only been partially initialized. */
8126 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8129 /* Sort the locations by their ADDRESS. */
8130 loc
= allocate_bp_location (b
);
8131 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8132 tmp
= &((*tmp
)->next
))
8137 loc
->requested_address
= sal
->pc
;
8138 loc
->address
= adjusted_address
;
8139 loc
->pspace
= sal
->pspace
;
8140 loc
->probe
.prob
= sal
->prob
;
8141 loc
->probe
.objfile
= sal
->objfile
;
8142 gdb_assert (loc
->pspace
!= NULL
);
8143 loc
->section
= sal
->section
;
8144 loc
->gdbarch
= loc_gdbarch
;
8145 loc
->line_number
= sal
->line
;
8146 loc
->symtab
= sal
->symtab
;
8147 loc
->symbol
= sal
->symbol
;
8148 loc
->msymbol
= sal
->msymbol
;
8149 loc
->objfile
= sal
->objfile
;
8151 set_breakpoint_location_function (loc
);
8153 /* While by definition, permanent breakpoints are already present in the
8154 code, we don't mark the location as inserted. Normally one would expect
8155 that GDB could rely on that breakpoint instruction to stop the program,
8156 thus removing the need to insert its own breakpoint, except that executing
8157 the breakpoint instruction can kill the target instead of reporting a
8158 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8159 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8160 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8161 breakpoint be inserted normally results in QEMU knowing about the GDB
8162 breakpoint, and thus trap before the breakpoint instruction is executed.
8163 (If GDB later needs to continue execution past the permanent breakpoint,
8164 it manually increments the PC, thus avoiding executing the breakpoint
8166 if (bp_loc_is_permanent (loc
))
8173 /* Return true if LOC is pointing to a permanent breakpoint,
8174 return false otherwise. */
8177 bp_loc_is_permanent (struct bp_location
*loc
)
8179 gdb_assert (loc
!= NULL
);
8181 /* If we have a non-breakpoint-backed catchpoint or a software
8182 watchpoint, just return 0. We should not attempt to read from
8183 the addresses the locations of these breakpoint types point to.
8184 gdbarch_program_breakpoint_here_p, below, will attempt to read
8186 if (!bl_address_is_meaningful (loc
))
8189 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8190 switch_to_program_space_and_thread (loc
->pspace
);
8191 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8194 /* Build a command list for the dprintf corresponding to the current
8195 settings of the dprintf style options. */
8198 update_dprintf_command_list (struct breakpoint
*b
)
8200 const char *dprintf_args
= b
->extra_string
.get ();
8201 gdb::unique_xmalloc_ptr
<char> printf_line
= nullptr;
8206 dprintf_args
= skip_spaces (dprintf_args
);
8208 /* Allow a comma, as it may have terminated a location, but don't
8210 if (*dprintf_args
== ',')
8212 dprintf_args
= skip_spaces (dprintf_args
);
8214 if (*dprintf_args
!= '"')
8215 error (_("Bad format string, missing '\"'."));
8217 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8218 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8219 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8221 if (dprintf_function
.empty ())
8222 error (_("No function supplied for dprintf call"));
8224 if (!dprintf_channel
.empty ())
8225 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8226 dprintf_function
.c_str (),
8227 dprintf_channel
.c_str (),
8230 printf_line
= xstrprintf ("call (void) %s (%s)",
8231 dprintf_function
.c_str (),
8234 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8236 if (target_can_run_breakpoint_commands ())
8237 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8240 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8241 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8245 internal_error (__FILE__
, __LINE__
,
8246 _("Invalid dprintf style."));
8248 gdb_assert (printf_line
!= NULL
);
8250 /* Manufacture a printf sequence. */
8251 struct command_line
*printf_cmd_line
8252 = new struct command_line (simple_control
, printf_line
.release ());
8253 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8254 command_lines_deleter ()));
8257 /* Update all dprintf commands, making their command lists reflect
8258 current style settings. */
8261 update_dprintf_commands (const char *args
, int from_tty
,
8262 struct cmd_list_element
*c
)
8264 for (breakpoint
*b
: all_breakpoints ())
8265 if (b
->type
== bp_dprintf
)
8266 update_dprintf_command_list (b
);
8269 /* Create a breakpoint with SAL as location. Use LOCATION
8270 as a description of the location, and COND_STRING
8271 as condition expression. If LOCATION is NULL then create an
8272 "address location" from the address in the SAL. */
8275 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8276 gdb::array_view
<const symtab_and_line
> sals
,
8277 event_location_up
&&location
,
8278 gdb::unique_xmalloc_ptr
<char> filter
,
8279 gdb::unique_xmalloc_ptr
<char> cond_string
,
8280 gdb::unique_xmalloc_ptr
<char> extra_string
,
8281 enum bptype type
, enum bpdisp disposition
,
8282 int thread
, int task
, int ignore_count
,
8283 const struct breakpoint_ops
*ops
, int from_tty
,
8284 int enabled
, int internal
, unsigned flags
,
8285 int display_canonical
)
8289 if (type
== bp_hardware_breakpoint
)
8291 int target_resources_ok
;
8293 i
= hw_breakpoint_used_count ();
8294 target_resources_ok
=
8295 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8297 if (target_resources_ok
== 0)
8298 error (_("No hardware breakpoint support in the target."));
8299 else if (target_resources_ok
< 0)
8300 error (_("Hardware breakpoints used exceeds limit."));
8303 gdb_assert (!sals
.empty ());
8305 for (const auto &sal
: sals
)
8307 struct bp_location
*loc
;
8311 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8313 loc_gdbarch
= gdbarch
;
8315 describe_other_breakpoints (loc_gdbarch
,
8316 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8319 if (&sal
== &sals
[0])
8321 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8325 b
->cond_string
= std::move (cond_string
);
8326 b
->extra_string
= std::move (extra_string
);
8327 b
->ignore_count
= ignore_count
;
8328 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8329 b
->disposition
= disposition
;
8331 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8332 b
->loc
->inserted
= 1;
8334 if (type
== bp_static_tracepoint
)
8336 struct tracepoint
*t
= (struct tracepoint
*) b
;
8337 struct static_tracepoint_marker marker
;
8339 if (strace_marker_p (b
))
8341 /* We already know the marker exists, otherwise, we
8342 wouldn't see a sal for it. */
8344 = &event_location_to_string (b
->location
.get ())[3];
8347 p
= skip_spaces (p
);
8349 endp
= skip_to_space (p
);
8351 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8353 gdb_printf (_("Probed static tracepoint "
8355 t
->static_trace_marker_id
.c_str ());
8357 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8359 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8361 gdb_printf (_("Probed static tracepoint "
8363 t
->static_trace_marker_id
.c_str ());
8366 warning (_("Couldn't determine the static "
8367 "tracepoint marker to probe"));
8374 loc
= add_location_to_breakpoint (b
, &sal
);
8375 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8379 /* Do not set breakpoint locations conditions yet. As locations
8380 are inserted, they get sorted based on their addresses. Let
8381 the list stabilize to have reliable location numbers. */
8383 /* Dynamic printf requires and uses additional arguments on the
8384 command line, otherwise it's an error. */
8385 if (type
== bp_dprintf
)
8387 if (b
->extra_string
)
8388 update_dprintf_command_list (b
);
8390 error (_("Format string required"));
8392 else if (b
->extra_string
)
8393 error (_("Garbage '%s' at end of command"), b
->extra_string
.get ());
8397 /* The order of the locations is now stable. Set the location
8398 condition using the location's number. */
8400 for (bp_location
*loc
: b
->locations ())
8402 if (b
->cond_string
!= nullptr)
8403 set_breakpoint_location_condition (b
->cond_string
.get (), loc
,
8404 b
->number
, loc_num
);
8409 b
->display_canonical
= display_canonical
;
8410 if (location
!= NULL
)
8411 b
->location
= std::move (location
);
8413 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8414 b
->filter
= std::move (filter
);
8418 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8419 gdb::array_view
<const symtab_and_line
> sals
,
8420 event_location_up
&&location
,
8421 gdb::unique_xmalloc_ptr
<char> filter
,
8422 gdb::unique_xmalloc_ptr
<char> cond_string
,
8423 gdb::unique_xmalloc_ptr
<char> extra_string
,
8424 enum bptype type
, enum bpdisp disposition
,
8425 int thread
, int task
, int ignore_count
,
8426 const struct breakpoint_ops
*ops
, int from_tty
,
8427 int enabled
, int internal
, unsigned flags
,
8428 int display_canonical
)
8430 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8432 init_breakpoint_sal (b
.get (), gdbarch
,
8433 sals
, std::move (location
),
8435 std::move (cond_string
),
8436 std::move (extra_string
),
8438 thread
, task
, ignore_count
,
8440 enabled
, internal
, flags
,
8443 install_breakpoint (internal
, std::move (b
), 0);
8446 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8447 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8448 value. COND_STRING, if not NULL, specified the condition to be
8449 used for all breakpoints. Essentially the only case where
8450 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8451 function. In that case, it's still not possible to specify
8452 separate conditions for different overloaded functions, so
8453 we take just a single condition string.
8455 NOTE: If the function succeeds, the caller is expected to cleanup
8456 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8457 array contents). If the function fails (error() is called), the
8458 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8459 COND and SALS arrays and each of those arrays contents. */
8462 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8463 struct linespec_result
*canonical
,
8464 gdb::unique_xmalloc_ptr
<char> cond_string
,
8465 gdb::unique_xmalloc_ptr
<char> extra_string
,
8466 enum bptype type
, enum bpdisp disposition
,
8467 int thread
, int task
, int ignore_count
,
8468 const struct breakpoint_ops
*ops
, int from_tty
,
8469 int enabled
, int internal
, unsigned flags
)
8471 if (canonical
->pre_expanded
)
8472 gdb_assert (canonical
->lsals
.size () == 1);
8474 for (const auto &lsal
: canonical
->lsals
)
8476 /* Note that 'location' can be NULL in the case of a plain
8477 'break', without arguments. */
8478 event_location_up location
8479 = (canonical
->location
!= NULL
8480 ? copy_event_location (canonical
->location
.get ()) : NULL
);
8481 gdb::unique_xmalloc_ptr
<char> filter_string
8482 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8484 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8485 std::move (location
),
8486 std::move (filter_string
),
8487 std::move (cond_string
),
8488 std::move (extra_string
),
8490 thread
, task
, ignore_count
, ops
,
8491 from_tty
, enabled
, internal
, flags
,
8492 canonical
->special_display
);
8496 /* Parse LOCATION which is assumed to be a SAL specification possibly
8497 followed by conditionals. On return, SALS contains an array of SAL
8498 addresses found. LOCATION points to the end of the SAL (for
8499 linespec locations).
8501 The array and the line spec strings are allocated on the heap, it is
8502 the caller's responsibility to free them. */
8505 parse_breakpoint_sals (struct event_location
*location
,
8506 struct linespec_result
*canonical
)
8508 struct symtab_and_line cursal
;
8510 if (event_location_type (location
) == LINESPEC_LOCATION
)
8512 const char *spec
= get_linespec_location (location
)->spec_string
;
8516 /* The last displayed codepoint, if it's valid, is our default
8517 breakpoint address. */
8518 if (last_displayed_sal_is_valid ())
8520 /* Set sal's pspace, pc, symtab, and line to the values
8521 corresponding to the last call to print_frame_info.
8522 Be sure to reinitialize LINE with NOTCURRENT == 0
8523 as the breakpoint line number is inappropriate otherwise.
8524 find_pc_line would adjust PC, re-set it back. */
8525 symtab_and_line sal
= get_last_displayed_sal ();
8526 CORE_ADDR pc
= sal
.pc
;
8528 sal
= find_pc_line (pc
, 0);
8530 /* "break" without arguments is equivalent to "break *PC"
8531 where PC is the last displayed codepoint's address. So
8532 make sure to set sal.explicit_pc to prevent GDB from
8533 trying to expand the list of sals to include all other
8534 instances with the same symtab and line. */
8536 sal
.explicit_pc
= 1;
8538 struct linespec_sals lsal
;
8540 lsal
.canonical
= NULL
;
8542 canonical
->lsals
.push_back (std::move (lsal
));
8546 error (_("No default breakpoint address now."));
8550 /* Force almost all breakpoints to be in terms of the
8551 current_source_symtab (which is decode_line_1's default).
8552 This should produce the results we want almost all of the
8553 time while leaving default_breakpoint_* alone.
8555 ObjC: However, don't match an Objective-C method name which
8556 may have a '+' or '-' succeeded by a '['. */
8557 cursal
= get_current_source_symtab_and_line ();
8558 if (last_displayed_sal_is_valid ())
8560 const char *spec
= NULL
;
8562 if (event_location_type (location
) == LINESPEC_LOCATION
)
8563 spec
= get_linespec_location (location
)->spec_string
;
8567 && strchr ("+-", spec
[0]) != NULL
8570 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8571 get_last_displayed_symtab (),
8572 get_last_displayed_line (),
8573 canonical
, NULL
, NULL
);
8578 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8579 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
8583 /* Convert each SAL into a real PC. Verify that the PC can be
8584 inserted as a breakpoint. If it can't throw an error. */
8587 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
8589 for (auto &sal
: sals
)
8590 resolve_sal_pc (&sal
);
8593 /* Fast tracepoints may have restrictions on valid locations. For
8594 instance, a fast tracepoint using a jump instead of a trap will
8595 likely have to overwrite more bytes than a trap would, and so can
8596 only be placed where the instruction is longer than the jump, or a
8597 multi-instruction sequence does not have a jump into the middle of
8601 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8602 gdb::array_view
<const symtab_and_line
> sals
)
8604 for (const auto &sal
: sals
)
8606 struct gdbarch
*sarch
;
8608 sarch
= get_sal_arch (sal
);
8609 /* We fall back to GDBARCH if there is no architecture
8610 associated with SAL. */
8614 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
8615 error (_("May not have a fast tracepoint at %s%s"),
8616 paddress (sarch
, sal
.pc
), msg
.c_str ());
8620 /* Given TOK, a string specification of condition and thread, as
8621 accepted by the 'break' command, extract the condition
8622 string and thread number and set *COND_STRING and *THREAD.
8623 PC identifies the context at which the condition should be parsed.
8624 If no condition is found, *COND_STRING is set to NULL.
8625 If no thread is found, *THREAD is set to -1. */
8628 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
8629 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8630 int *thread
, int *task
,
8631 gdb::unique_xmalloc_ptr
<char> *rest
)
8633 cond_string
->reset ();
8641 const char *end_tok
;
8643 const char *cond_start
= NULL
;
8644 const char *cond_end
= NULL
;
8646 tok
= skip_spaces (tok
);
8648 if ((*tok
== '"' || *tok
== ',') && rest
)
8650 rest
->reset (savestring (tok
, strlen (tok
)));
8654 end_tok
= skip_to_space (tok
);
8656 toklen
= end_tok
- tok
;
8658 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8660 tok
= cond_start
= end_tok
+ 1;
8663 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
8665 catch (const gdb_exception_error
&)
8670 tok
= tok
+ strlen (tok
);
8673 cond_string
->reset (savestring (cond_start
, cond_end
- cond_start
));
8675 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
8680 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8683 struct thread_info
*thr
;
8686 thr
= parse_thread_id (tok
, &tmptok
);
8688 error (_("Junk after thread keyword."));
8689 *thread
= thr
->global_num
;
8692 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8697 *task
= strtol (tok
, &tmptok
, 0);
8699 error (_("Junk after task keyword."));
8700 if (!valid_task_id (*task
))
8701 error (_("Unknown task %d."), *task
);
8706 rest
->reset (savestring (tok
, strlen (tok
)));
8710 error (_("Junk at end of arguments."));
8714 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
8715 succeeds. The parsed values are written to COND_STRING, THREAD,
8716 TASK, and REST. See the comment of 'find_condition_and_thread'
8717 for the description of these parameters and INPUT. */
8720 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
8722 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8723 int *thread
, int *task
,
8724 gdb::unique_xmalloc_ptr
<char> *rest
)
8726 int num_failures
= 0;
8727 for (auto &sal
: sals
)
8729 gdb::unique_xmalloc_ptr
<char> cond
;
8732 gdb::unique_xmalloc_ptr
<char> remaining
;
8734 /* Here we want to parse 'arg' to separate condition from thread
8735 number. But because parsing happens in a context and the
8736 contexts of sals might be different, try each until there is
8737 success. Finding one successful parse is sufficient for our
8738 goal. When setting the breakpoint we'll re-parse the
8739 condition in the context of each sal. */
8742 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
8743 &task_id
, &remaining
);
8744 *cond_string
= std::move (cond
);
8745 *thread
= thread_id
;
8747 *rest
= std::move (remaining
);
8750 catch (const gdb_exception_error
&e
)
8753 /* If no sal remains, do not continue. */
8754 if (num_failures
== sals
.size ())
8760 /* Decode a static tracepoint marker spec. */
8762 static std::vector
<symtab_and_line
>
8763 decode_static_tracepoint_spec (const char **arg_p
)
8765 const char *p
= &(*arg_p
)[3];
8768 p
= skip_spaces (p
);
8770 endp
= skip_to_space (p
);
8772 std::string
marker_str (p
, endp
- p
);
8774 std::vector
<static_tracepoint_marker
> markers
8775 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
8776 if (markers
.empty ())
8777 error (_("No known static tracepoint marker named %s"),
8778 marker_str
.c_str ());
8780 std::vector
<symtab_and_line
> sals
;
8781 sals
.reserve (markers
.size ());
8783 for (const static_tracepoint_marker
&marker
: markers
)
8785 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
8786 sal
.pc
= marker
.address
;
8787 sals
.push_back (sal
);
8794 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
8795 according to IS_TRACEPOINT. */
8797 static const struct breakpoint_ops
*
8798 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
8803 if (location_type
== PROBE_LOCATION
)
8804 return &tracepoint_probe_breakpoint_ops
;
8806 return &vtable_breakpoint_ops
;
8810 if (location_type
== PROBE_LOCATION
)
8811 return &bkpt_probe_breakpoint_ops
;
8813 return &bkpt_breakpoint_ops
;
8817 /* See breakpoint.h. */
8819 const struct breakpoint_ops
*
8820 breakpoint_ops_for_event_location (const struct event_location
*location
,
8823 if (location
!= nullptr)
8824 return breakpoint_ops_for_event_location_type
8825 (event_location_type (location
), is_tracepoint
);
8826 return is_tracepoint
? &vtable_breakpoint_ops
: &bkpt_breakpoint_ops
;
8829 /* See breakpoint.h. */
8832 create_breakpoint (struct gdbarch
*gdbarch
,
8833 struct event_location
*location
,
8834 const char *cond_string
,
8835 int thread
, const char *extra_string
,
8836 bool force_condition
, int parse_extra
,
8837 int tempflag
, enum bptype type_wanted
,
8839 enum auto_boolean pending_break_support
,
8840 const struct breakpoint_ops
*ops
,
8841 int from_tty
, int enabled
, int internal
,
8844 struct linespec_result canonical
;
8847 int prev_bkpt_count
= breakpoint_count
;
8849 gdb_assert (ops
!= NULL
);
8851 /* If extra_string isn't useful, set it to NULL. */
8852 if (extra_string
!= NULL
&& *extra_string
== '\0')
8853 extra_string
= NULL
;
8857 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
8859 catch (const gdb_exception_error
&e
)
8861 /* If caller is interested in rc value from parse, set
8863 if (e
.error
== NOT_FOUND_ERROR
)
8865 /* If pending breakpoint support is turned off, throw
8868 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
8871 exception_print (gdb_stderr
, e
);
8873 /* If pending breakpoint support is auto query and the user
8874 selects no, then simply return the error code. */
8875 if (pending_break_support
== AUTO_BOOLEAN_AUTO
8876 && !nquery (_("Make %s pending on future shared library load? "),
8877 bptype_string (type_wanted
)))
8880 /* At this point, either the user was queried about setting
8881 a pending breakpoint and selected yes, or pending
8882 breakpoint behavior is on and thus a pending breakpoint
8883 is defaulted on behalf of the user. */
8890 if (!pending
&& canonical
.lsals
.empty ())
8893 /* Resolve all line numbers to PC's and verify that the addresses
8894 are ok for the target. */
8897 for (auto &lsal
: canonical
.lsals
)
8898 breakpoint_sals_to_pc (lsal
.sals
);
8901 /* Fast tracepoints may have additional restrictions on location. */
8902 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
8904 for (const auto &lsal
: canonical
.lsals
)
8905 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
8908 /* Verify that condition can be parsed, before setting any
8909 breakpoints. Allocate a separate condition expression for each
8913 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
8914 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
8918 gdb::unique_xmalloc_ptr
<char> rest
;
8919 gdb::unique_xmalloc_ptr
<char> cond
;
8921 const linespec_sals
&lsal
= canonical
.lsals
[0];
8923 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
8924 &cond
, &thread
, &task
, &rest
);
8925 cond_string_copy
= std::move (cond
);
8926 extra_string_copy
= std::move (rest
);
8930 if (type_wanted
!= bp_dprintf
8931 && extra_string
!= NULL
&& *extra_string
!= '\0')
8932 error (_("Garbage '%s' at end of location"), extra_string
);
8934 /* Check the validity of the condition. We should error out
8935 if the condition is invalid at all of the locations and
8936 if it is not forced. In the PARSE_EXTRA case above, this
8937 check is done when parsing the EXTRA_STRING. */
8938 if (cond_string
!= nullptr && !force_condition
)
8940 int num_failures
= 0;
8941 const linespec_sals
&lsal
= canonical
.lsals
[0];
8942 for (const auto &sal
: lsal
.sals
)
8944 const char *cond
= cond_string
;
8947 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
8948 /* One success is sufficient to keep going. */
8951 catch (const gdb_exception_error
&)
8954 /* If this is the last sal, error out. */
8955 if (num_failures
== lsal
.sals
.size ())
8961 /* Create a private copy of condition string. */
8963 cond_string_copy
.reset (xstrdup (cond_string
));
8964 /* Create a private copy of any extra string. */
8966 extra_string_copy
.reset (xstrdup (extra_string
));
8969 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
8970 std::move (cond_string_copy
),
8971 std::move (extra_string_copy
),
8973 tempflag
? disp_del
: disp_donttouch
,
8974 thread
, task
, ignore_count
, ops
,
8975 from_tty
, enabled
, internal
, flags
);
8979 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
8981 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
8982 b
->location
= copy_event_location (location
);
8985 b
->cond_string
= NULL
;
8988 /* Create a private copy of condition string. */
8989 b
->cond_string
.reset (cond_string
!= NULL
8990 ? xstrdup (cond_string
)
8995 /* Create a private copy of any extra string. */
8996 b
->extra_string
.reset (extra_string
!= NULL
8997 ? xstrdup (extra_string
)
8999 b
->ignore_count
= ignore_count
;
9000 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9001 b
->condition_not_parsed
= 1;
9002 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9003 if ((type_wanted
!= bp_breakpoint
9004 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9005 b
->pspace
= current_program_space
;
9007 install_breakpoint (internal
, std::move (b
), 0);
9010 if (canonical
.lsals
.size () > 1)
9012 warning (_("Multiple breakpoints were set.\nUse the "
9013 "\"delete\" command to delete unwanted breakpoints."));
9014 prev_breakpoint_count
= prev_bkpt_count
;
9017 update_global_location_list (UGLL_MAY_INSERT
);
9022 /* Set a breakpoint.
9023 ARG is a string describing breakpoint address,
9024 condition, and thread.
9025 FLAG specifies if a breakpoint is hardware on,
9026 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9030 break_command_1 (const char *arg
, int flag
, int from_tty
)
9032 int tempflag
= flag
& BP_TEMPFLAG
;
9033 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9034 ? bp_hardware_breakpoint
9037 event_location_up location
= string_to_event_location (&arg
, current_language
);
9038 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9039 (location
.get (), false /* is_tracepoint */);
9041 create_breakpoint (get_current_arch (),
9043 NULL
, 0, arg
, false, 1 /* parse arg */,
9044 tempflag
, type_wanted
,
9045 0 /* Ignore count */,
9046 pending_break_support
,
9054 /* Helper function for break_command_1 and disassemble_command. */
9057 resolve_sal_pc (struct symtab_and_line
*sal
)
9061 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9063 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9064 error (_("No line %d in file \"%s\"."),
9065 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9068 /* If this SAL corresponds to a breakpoint inserted using a line
9069 number, then skip the function prologue if necessary. */
9070 if (sal
->explicit_line
)
9071 skip_prologue_sal (sal
);
9074 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9076 const struct blockvector
*bv
;
9077 const struct block
*b
;
9080 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9081 sal
->symtab
->compunit ());
9084 sym
= block_linkage_function (b
);
9087 fixup_symbol_section (sym
, sal
->symtab
->compunit ()->objfile ());
9089 = sym
->obj_section (sal
->symtab
->compunit ()->objfile ());
9093 /* It really is worthwhile to have the section, so we'll
9094 just have to look harder. This case can be executed
9095 if we have line numbers but no functions (as can
9096 happen in assembly source). */
9098 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9099 switch_to_program_space_and_thread (sal
->pspace
);
9101 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9103 sal
->section
= msym
.obj_section ();
9110 break_command (const char *arg
, int from_tty
)
9112 break_command_1 (arg
, 0, from_tty
);
9116 tbreak_command (const char *arg
, int from_tty
)
9118 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9122 hbreak_command (const char *arg
, int from_tty
)
9124 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9128 thbreak_command (const char *arg
, int from_tty
)
9130 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9133 /* The dynamic printf command is mostly like a regular breakpoint, but
9134 with a prewired command list consisting of a single output command,
9135 built from extra arguments supplied on the dprintf command
9139 dprintf_command (const char *arg
, int from_tty
)
9141 event_location_up location
= string_to_event_location (&arg
, current_language
);
9143 /* If non-NULL, ARG should have been advanced past the location;
9144 the next character must be ','. */
9147 if (arg
[0] != ',' || arg
[1] == '\0')
9148 error (_("Format string required"));
9151 /* Skip the comma. */
9156 create_breakpoint (get_current_arch (),
9158 NULL
, 0, arg
, false, 1 /* parse arg */,
9160 0 /* Ignore count */,
9161 pending_break_support
,
9162 &dprintf_breakpoint_ops
,
9170 agent_printf_command (const char *arg
, int from_tty
)
9172 error (_("May only run agent-printf on the target"));
9175 /* Implement the "breakpoint_hit" breakpoint_ops method for
9176 ranged breakpoints. */
9179 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9180 const address_space
*aspace
,
9182 const target_waitstatus
&ws
)
9184 if (ws
.kind () != TARGET_WAITKIND_STOPPED
9185 || ws
.sig () != GDB_SIGNAL_TRAP
)
9188 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9189 bl
->length
, aspace
, bp_addr
);
9192 /* Implement the "resources_needed" breakpoint_ops method for
9193 ranged breakpoints. */
9196 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9198 return target_ranged_break_num_registers ();
9201 /* Implement the "print_it" breakpoint_ops method for
9202 ranged breakpoints. */
9204 static enum print_stop_action
9205 print_it_ranged_breakpoint (bpstat
*bs
)
9207 struct breakpoint
*b
= bs
->breakpoint_at
;
9208 struct bp_location
*bl
= b
->loc
;
9209 struct ui_out
*uiout
= current_uiout
;
9211 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9213 /* Ranged breakpoints have only one location. */
9214 gdb_assert (bl
&& bl
->next
== NULL
);
9216 annotate_breakpoint (b
->number
);
9218 maybe_print_thread_hit_breakpoint (uiout
);
9220 if (b
->disposition
== disp_del
)
9221 uiout
->text ("Temporary ranged breakpoint ");
9223 uiout
->text ("Ranged breakpoint ");
9224 if (uiout
->is_mi_like_p ())
9226 uiout
->field_string ("reason",
9227 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9228 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9230 uiout
->field_signed ("bkptno", b
->number
);
9233 return PRINT_SRC_AND_LOC
;
9236 /* Implement the "print_one" breakpoint_ops method for
9237 ranged breakpoints. */
9240 print_one_ranged_breakpoint (struct breakpoint
*b
,
9241 struct bp_location
**last_loc
)
9243 struct bp_location
*bl
= b
->loc
;
9244 struct value_print_options opts
;
9245 struct ui_out
*uiout
= current_uiout
;
9247 /* Ranged breakpoints have only one location. */
9248 gdb_assert (bl
&& bl
->next
== NULL
);
9250 get_user_print_options (&opts
);
9252 if (opts
.addressprint
)
9253 /* We don't print the address range here, it will be printed later
9254 by print_one_detail_ranged_breakpoint. */
9255 uiout
->field_skip ("addr");
9257 print_breakpoint_location (b
, bl
);
9263 /* Implement the "print_one_detail" breakpoint_ops method for
9264 ranged breakpoints. */
9267 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9268 struct ui_out
*uiout
)
9270 CORE_ADDR address_start
, address_end
;
9271 struct bp_location
*bl
= b
->loc
;
9276 address_start
= bl
->address
;
9277 address_end
= address_start
+ bl
->length
- 1;
9279 uiout
->text ("\taddress range: ");
9280 stb
.printf ("[%s, %s]",
9281 print_core_address (bl
->gdbarch
, address_start
),
9282 print_core_address (bl
->gdbarch
, address_end
));
9283 uiout
->field_stream ("addr", stb
);
9287 /* Implement the "print_mention" breakpoint_ops method for
9288 ranged breakpoints. */
9291 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9293 struct bp_location
*bl
= b
->loc
;
9294 struct ui_out
*uiout
= current_uiout
;
9297 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9299 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9300 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9301 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9304 /* Implement the "print_recreate" breakpoint_ops method for
9305 ranged breakpoints. */
9308 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9310 gdb_printf (fp
, "break-range %s, %s",
9311 event_location_to_string (b
->location
.get ()),
9312 event_location_to_string (b
->location_range_end
.get ()));
9313 print_recreate_thread (b
, fp
);
9316 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9318 static struct breakpoint_ops ranged_breakpoint_ops
;
9320 /* Find the address where the end of the breakpoint range should be
9321 placed, given the SAL of the end of the range. This is so that if
9322 the user provides a line number, the end of the range is set to the
9323 last instruction of the given line. */
9326 find_breakpoint_range_end (struct symtab_and_line sal
)
9330 /* If the user provided a PC value, use it. Otherwise,
9331 find the address of the end of the given location. */
9332 if (sal
.explicit_pc
)
9339 ret
= find_line_pc_range (sal
, &start
, &end
);
9341 error (_("Could not find location of the end of the range."));
9343 /* find_line_pc_range returns the start of the next line. */
9350 /* Implement the "break-range" CLI command. */
9353 break_range_command (const char *arg
, int from_tty
)
9355 const char *arg_start
;
9356 struct linespec_result canonical_start
, canonical_end
;
9357 int bp_count
, can_use_bp
, length
;
9359 struct breakpoint
*b
;
9361 /* We don't support software ranged breakpoints. */
9362 if (target_ranged_break_num_registers () < 0)
9363 error (_("This target does not support hardware ranged breakpoints."));
9365 bp_count
= hw_breakpoint_used_count ();
9366 bp_count
+= target_ranged_break_num_registers ();
9367 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9370 error (_("Hardware breakpoints used exceeds limit."));
9372 arg
= skip_spaces (arg
);
9373 if (arg
== NULL
|| arg
[0] == '\0')
9374 error(_("No address range specified."));
9377 event_location_up start_location
= string_to_event_location (&arg
,
9379 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9382 error (_("Too few arguments."));
9383 else if (canonical_start
.lsals
.empty ())
9384 error (_("Could not find location of the beginning of the range."));
9386 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9388 if (canonical_start
.lsals
.size () > 1
9389 || lsal_start
.sals
.size () != 1)
9390 error (_("Cannot create a ranged breakpoint with multiple locations."));
9392 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9393 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9395 arg
++; /* Skip the comma. */
9396 arg
= skip_spaces (arg
);
9398 /* Parse the end location. */
9402 /* We call decode_line_full directly here instead of using
9403 parse_breakpoint_sals because we need to specify the start location's
9404 symtab and line as the default symtab and line for the end of the
9405 range. This makes it possible to have ranges like "foo.c:27, +14",
9406 where +14 means 14 lines from the start location. */
9407 event_location_up end_location
= string_to_event_location (&arg
,
9409 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9410 sal_start
.symtab
, sal_start
.line
,
9411 &canonical_end
, NULL
, NULL
);
9413 if (canonical_end
.lsals
.empty ())
9414 error (_("Could not find location of the end of the range."));
9416 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9417 if (canonical_end
.lsals
.size () > 1
9418 || lsal_end
.sals
.size () != 1)
9419 error (_("Cannot create a ranged breakpoint with multiple locations."));
9421 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9423 end
= find_breakpoint_range_end (sal_end
);
9424 if (sal_start
.pc
> end
)
9425 error (_("Invalid address range, end precedes start."));
9427 length
= end
- sal_start
.pc
+ 1;
9429 /* Length overflowed. */
9430 error (_("Address range too large."));
9431 else if (length
== 1)
9433 /* This range is simple enough to be handled by
9434 the `hbreak' command. */
9435 hbreak_command (&addr_string_start
[0], 1);
9440 /* Now set up the breakpoint. */
9441 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9442 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9443 set_breakpoint_count (breakpoint_count
+ 1);
9444 b
->number
= breakpoint_count
;
9445 b
->disposition
= disp_donttouch
;
9446 b
->location
= std::move (start_location
);
9447 b
->location_range_end
= std::move (end_location
);
9448 b
->loc
->length
= length
;
9451 gdb::observers::breakpoint_created
.notify (b
);
9452 update_global_location_list (UGLL_MAY_INSERT
);
9455 /* Return non-zero if EXP is verified as constant. Returned zero
9456 means EXP is variable. Also the constant detection may fail for
9457 some constant expressions and in such case still falsely return
9461 watchpoint_exp_is_const (const struct expression
*exp
)
9463 return exp
->op
->constant_p ();
9466 /* Implement the "re_set" method for watchpoints. */
9469 watchpoint::re_set ()
9471 /* Watchpoint can be either on expression using entirely global
9472 variables, or it can be on local variables.
9474 Watchpoints of the first kind are never auto-deleted, and even
9475 persist across program restarts. Since they can use variables
9476 from shared libraries, we need to reparse expression as libraries
9477 are loaded and unloaded.
9479 Watchpoints on local variables can also change meaning as result
9480 of solib event. For example, if a watchpoint uses both a local
9481 and a global variables in expression, it's a local watchpoint,
9482 but unloading of a shared library will make the expression
9483 invalid. This is not a very common use case, but we still
9484 re-evaluate expression, to avoid surprises to the user.
9486 Note that for local watchpoints, we re-evaluate it only if
9487 watchpoints frame id is still valid. If it's not, it means the
9488 watchpoint is out of scope and will be deleted soon. In fact,
9489 I'm not sure we'll ever be called in this case.
9491 If a local watchpoint's frame id is still valid, then
9492 exp_valid_block is likewise valid, and we can safely use it.
9494 Don't do anything about disabled watchpoints, since they will be
9495 reevaluated again when enabled. */
9496 update_watchpoint (this, 1 /* reparse */);
9499 /* Implement the "insert" method for hardware watchpoints. */
9502 watchpoint::insert_location (struct bp_location
*bl
)
9504 int length
= exact
? 1 : bl
->length
;
9506 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9510 /* Implement the "remove" method for hardware watchpoints. */
9513 watchpoint::remove_location (struct bp_location
*bl
,
9514 enum remove_bp_reason reason
)
9516 int length
= exact
? 1 : bl
->length
;
9518 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9523 watchpoint::breakpoint_hit (const struct bp_location
*bl
,
9524 const address_space
*aspace
, CORE_ADDR bp_addr
,
9525 const target_waitstatus
&ws
)
9527 struct breakpoint
*b
= bl
->owner
;
9529 /* Continuable hardware watchpoints are treated as non-existent if the
9530 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9531 some data address). Otherwise gdb won't stop on a break instruction
9532 in the code (not from a breakpoint) when a hardware watchpoint has
9533 been defined. Also skip watchpoints which we know did not trigger
9534 (did not match the data address). */
9535 if (is_hardware_watchpoint (b
)
9536 && watchpoint_triggered
== watch_triggered_no
)
9543 watchpoint::check_status (bpstat
*bs
)
9545 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
9547 bpstat_check_watchpoint (bs
);
9550 /* Implement the "resources_needed" method for hardware
9554 watchpoint::resources_needed (const struct bp_location
*bl
)
9556 int length
= exact
? 1 : bl
->length
;
9558 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9561 /* Implement the "works_in_software_mode" method for hardware
9565 watchpoint::works_in_software_mode () const
9567 /* Read and access watchpoints only work with hardware support. */
9568 return type
== bp_watchpoint
|| type
== bp_hardware_watchpoint
;
9571 enum print_stop_action
9572 watchpoint::print_it (bpstat
*bs
)
9574 struct breakpoint
*b
;
9575 enum print_stop_action result
;
9576 struct ui_out
*uiout
= current_uiout
;
9578 gdb_assert (bs
->bp_location_at
!= NULL
);
9580 b
= bs
->breakpoint_at
;
9582 annotate_watchpoint (b
->number
);
9583 maybe_print_thread_hit_breakpoint (uiout
);
9587 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
9591 case bp_hardware_watchpoint
:
9592 if (uiout
->is_mi_like_p ())
9594 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9596 tuple_emitter
.emplace (uiout
, "value");
9597 uiout
->text ("\nOld value = ");
9598 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9599 uiout
->field_stream ("old", stb
);
9600 uiout
->text ("\nNew value = ");
9601 watchpoint_value_print (val
.get (), &stb
);
9602 uiout
->field_stream ("new", stb
);
9604 /* More than one watchpoint may have been triggered. */
9605 result
= PRINT_UNKNOWN
;
9608 case bp_read_watchpoint
:
9609 if (uiout
->is_mi_like_p ())
9611 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9613 tuple_emitter
.emplace (uiout
, "value");
9614 uiout
->text ("\nValue = ");
9615 watchpoint_value_print (val
.get (), &stb
);
9616 uiout
->field_stream ("value", stb
);
9618 result
= PRINT_UNKNOWN
;
9621 case bp_access_watchpoint
:
9622 if (bs
->old_val
!= NULL
)
9624 if (uiout
->is_mi_like_p ())
9627 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9629 tuple_emitter
.emplace (uiout
, "value");
9630 uiout
->text ("\nOld value = ");
9631 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9632 uiout
->field_stream ("old", stb
);
9633 uiout
->text ("\nNew value = ");
9638 if (uiout
->is_mi_like_p ())
9641 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9642 tuple_emitter
.emplace (uiout
, "value");
9643 uiout
->text ("\nValue = ");
9645 watchpoint_value_print (val
.get (), &stb
);
9646 uiout
->field_stream ("new", stb
);
9648 result
= PRINT_UNKNOWN
;
9651 result
= PRINT_UNKNOWN
;
9657 /* Implement the "print_mention" method for hardware watchpoints. */
9660 watchpoint::print_mention ()
9662 struct ui_out
*uiout
= current_uiout
;
9663 const char *tuple_name
;
9668 uiout
->text ("Watchpoint ");
9671 case bp_hardware_watchpoint
:
9672 uiout
->text ("Hardware watchpoint ");
9675 case bp_read_watchpoint
:
9676 uiout
->text ("Hardware read watchpoint ");
9677 tuple_name
= "hw-rwpt";
9679 case bp_access_watchpoint
:
9680 uiout
->text ("Hardware access (read/write) watchpoint ");
9681 tuple_name
= "hw-awpt";
9684 internal_error (__FILE__
, __LINE__
,
9685 _("Invalid hardware watchpoint type."));
9688 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9689 uiout
->field_signed ("number", number
);
9691 uiout
->field_string ("exp", exp_string
.get ());
9694 /* Implement the "print_recreate" method for watchpoints. */
9697 watchpoint::print_recreate (struct ui_file
*fp
)
9702 case bp_hardware_watchpoint
:
9703 gdb_printf (fp
, "watch");
9705 case bp_read_watchpoint
:
9706 gdb_printf (fp
, "rwatch");
9708 case bp_access_watchpoint
:
9709 gdb_printf (fp
, "awatch");
9712 internal_error (__FILE__
, __LINE__
,
9713 _("Invalid watchpoint type."));
9716 gdb_printf (fp
, " %s", exp_string
.get ());
9717 print_recreate_thread (this, fp
);
9720 /* Implement the "explains_signal" method for watchpoints. */
9723 watchpoint::explains_signal (enum gdb_signal sig
)
9725 /* A software watchpoint cannot cause a signal other than
9727 if (type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
9733 struct masked_watchpoint
: public watchpoint
9735 int insert_location (struct bp_location
*) override
;
9736 int remove_location (struct bp_location
*,
9737 enum remove_bp_reason reason
) override
;
9738 int resources_needed (const struct bp_location
*) override
;
9739 int works_in_software_mode () const override
;
9740 enum print_stop_action
print_it (struct bpstat
*bs
) override
;
9741 void print_one_detail (struct ui_out
*) const override
;
9742 void print_mention () override
;
9743 void print_recreate (struct ui_file
*fp
) override
;
9746 /* Implement the "insert" method for masked hardware watchpoints. */
9749 masked_watchpoint::insert_location (struct bp_location
*bl
)
9751 return target_insert_mask_watchpoint (bl
->address
, hw_wp_mask
,
9752 bl
->watchpoint_type
);
9755 /* Implement the "remove" method for masked hardware watchpoints. */
9758 masked_watchpoint::remove_location (struct bp_location
*bl
,
9759 enum remove_bp_reason reason
)
9761 return target_remove_mask_watchpoint (bl
->address
, hw_wp_mask
,
9762 bl
->watchpoint_type
);
9765 /* Implement the "resources_needed" method for masked hardware
9769 masked_watchpoint::resources_needed (const struct bp_location
*bl
)
9771 return target_masked_watch_num_registers (bl
->address
, hw_wp_mask
);
9774 /* Implement the "works_in_software_mode" method for masked hardware
9778 masked_watchpoint::works_in_software_mode () const
9783 /* Implement the "print_it" method for masked hardware
9786 enum print_stop_action
9787 masked_watchpoint::print_it (bpstat
*bs
)
9789 struct breakpoint
*b
= bs
->breakpoint_at
;
9790 struct ui_out
*uiout
= current_uiout
;
9792 /* Masked watchpoints have only one location. */
9793 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9795 annotate_watchpoint (b
->number
);
9796 maybe_print_thread_hit_breakpoint (uiout
);
9800 case bp_hardware_watchpoint
:
9801 if (uiout
->is_mi_like_p ())
9803 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9806 case bp_read_watchpoint
:
9807 if (uiout
->is_mi_like_p ())
9809 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9812 case bp_access_watchpoint
:
9813 if (uiout
->is_mi_like_p ())
9816 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9819 internal_error (__FILE__
, __LINE__
,
9820 _("Invalid hardware watchpoint type."));
9825 Check the underlying instruction at PC for the memory\n\
9826 address and value which triggered this watchpoint.\n"));
9829 /* More than one watchpoint may have been triggered. */
9830 return PRINT_UNKNOWN
;
9833 /* Implement the "print_one_detail" method for masked hardware
9837 masked_watchpoint::print_one_detail (struct ui_out
*uiout
) const
9839 /* Masked watchpoints have only one location. */
9840 gdb_assert (loc
&& loc
->next
== NULL
);
9842 uiout
->text ("\tmask ");
9843 uiout
->field_core_addr ("mask", loc
->gdbarch
, hw_wp_mask
);
9847 /* Implement the "print_mention" method for masked hardware
9851 masked_watchpoint::print_mention ()
9853 struct ui_out
*uiout
= current_uiout
;
9854 const char *tuple_name
;
9858 case bp_hardware_watchpoint
:
9859 uiout
->text ("Masked hardware watchpoint ");
9862 case bp_read_watchpoint
:
9863 uiout
->text ("Masked hardware read watchpoint ");
9864 tuple_name
= "hw-rwpt";
9866 case bp_access_watchpoint
:
9867 uiout
->text ("Masked hardware access (read/write) watchpoint ");
9868 tuple_name
= "hw-awpt";
9871 internal_error (__FILE__
, __LINE__
,
9872 _("Invalid hardware watchpoint type."));
9875 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9876 uiout
->field_signed ("number", number
);
9878 uiout
->field_string ("exp", exp_string
.get ());
9881 /* Implement the "print_recreate" method for masked hardware
9885 masked_watchpoint::print_recreate (struct ui_file
*fp
)
9889 case bp_hardware_watchpoint
:
9890 gdb_printf (fp
, "watch");
9892 case bp_read_watchpoint
:
9893 gdb_printf (fp
, "rwatch");
9895 case bp_access_watchpoint
:
9896 gdb_printf (fp
, "awatch");
9899 internal_error (__FILE__
, __LINE__
,
9900 _("Invalid hardware watchpoint type."));
9903 gdb_printf (fp
, " %s mask 0x%s", exp_string
.get (),
9904 phex (hw_wp_mask
, sizeof (CORE_ADDR
)));
9905 print_recreate_thread (this, fp
);
9908 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9911 is_masked_watchpoint (const struct breakpoint
*b
)
9913 return dynamic_cast<const masked_watchpoint
*> (b
) != nullptr;
9916 /* accessflag: hw_write: watch write,
9917 hw_read: watch read,
9918 hw_access: watch access (read or write) */
9920 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
9921 bool just_location
, bool internal
)
9923 struct breakpoint
*scope_breakpoint
= NULL
;
9924 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9925 struct value
*result
;
9926 int saved_bitpos
= 0, saved_bitsize
= 0;
9927 const char *exp_start
= NULL
;
9928 const char *exp_end
= NULL
;
9929 const char *tok
, *end_tok
;
9931 const char *cond_start
= NULL
;
9932 const char *cond_end
= NULL
;
9933 enum bptype bp_type
;
9935 /* Flag to indicate whether we are going to use masks for
9936 the hardware watchpoint. */
9937 bool use_mask
= false;
9941 /* Make sure that we actually have parameters to parse. */
9942 if (arg
!= NULL
&& arg
[0] != '\0')
9944 const char *value_start
;
9946 exp_end
= arg
+ strlen (arg
);
9948 /* Look for "parameter value" pairs at the end
9949 of the arguments string. */
9950 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
9952 /* Skip whitespace at the end of the argument list. */
9953 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9956 /* Find the beginning of the last token.
9957 This is the value of the parameter. */
9958 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9960 value_start
= tok
+ 1;
9962 /* Skip whitespace. */
9963 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9968 /* Find the beginning of the second to last token.
9969 This is the parameter itself. */
9970 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9973 toklen
= end_tok
- tok
+ 1;
9975 if (toklen
== 6 && startswith (tok
, "thread"))
9977 struct thread_info
*thr
;
9978 /* At this point we've found a "thread" token, which means
9979 the user is trying to set a watchpoint that triggers
9980 only in a specific thread. */
9984 error(_("You can specify only one thread."));
9986 /* Extract the thread ID from the next token. */
9987 thr
= parse_thread_id (value_start
, &endp
);
9989 /* Check if the user provided a valid thread ID. */
9990 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9991 invalid_thread_id_error (value_start
);
9993 thread
= thr
->global_num
;
9995 else if (toklen
== 4 && startswith (tok
, "task"))
9999 task
= strtol (value_start
, &tmp
, 0);
10000 if (tmp
== value_start
)
10001 error (_("Junk after task keyword."));
10002 if (!valid_task_id (task
))
10003 error (_("Unknown task %d."), task
);
10005 else if (toklen
== 4 && startswith (tok
, "mask"))
10007 /* We've found a "mask" token, which means the user wants to
10008 create a hardware watchpoint that is going to have the mask
10010 struct value
*mask_value
, *mark
;
10013 error(_("You can specify only one mask."));
10015 use_mask
= just_location
= true;
10017 mark
= value_mark ();
10018 mask_value
= parse_to_comma_and_eval (&value_start
);
10019 mask
= value_as_address (mask_value
);
10020 value_free_to_mark (mark
);
10023 /* We didn't recognize what we found. We should stop here. */
10026 /* Truncate the string and get rid of the "parameter value" pair before
10027 the arguments string is parsed by the parse_exp_1 function. */
10034 /* Parse the rest of the arguments. From here on out, everything
10035 is in terms of a newly allocated string instead of the original
10037 std::string
expression (arg
, exp_end
- arg
);
10038 exp_start
= arg
= expression
.c_str ();
10039 innermost_block_tracker tracker
;
10040 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10042 /* Remove trailing whitespace from the expression before saving it.
10043 This makes the eventual display of the expression string a bit
10045 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10048 /* Checking if the expression is not constant. */
10049 if (watchpoint_exp_is_const (exp
.get ()))
10053 len
= exp_end
- exp_start
;
10054 while (len
> 0 && isspace (exp_start
[len
- 1]))
10056 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10059 exp_valid_block
= tracker
.block ();
10060 struct value
*mark
= value_mark ();
10061 struct value
*val_as_value
= nullptr;
10062 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10065 if (val_as_value
!= NULL
&& just_location
)
10067 saved_bitpos
= value_bitpos (val_as_value
);
10068 saved_bitsize
= value_bitsize (val_as_value
);
10076 exp_valid_block
= NULL
;
10077 val
= release_value (value_addr (result
));
10078 value_free_to_mark (mark
);
10082 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10085 error (_("This target does not support masked watchpoints."));
10086 else if (ret
== -2)
10087 error (_("Invalid mask or memory region."));
10090 else if (val_as_value
!= NULL
)
10091 val
= release_value (val_as_value
);
10093 tok
= skip_spaces (arg
);
10094 end_tok
= skip_to_space (tok
);
10096 toklen
= end_tok
- tok
;
10097 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10099 tok
= cond_start
= end_tok
+ 1;
10100 innermost_block_tracker if_tracker
;
10101 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10103 /* The watchpoint expression may not be local, but the condition
10104 may still be. E.g.: `watch global if local > 0'. */
10105 cond_exp_valid_block
= if_tracker
.block ();
10110 error (_("Junk at end of command."));
10112 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10114 /* Save this because create_internal_breakpoint below invalidates
10116 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10118 /* If the expression is "local", then set up a "watchpoint scope"
10119 breakpoint at the point where we've left the scope of the watchpoint
10120 expression. Create the scope breakpoint before the watchpoint, so
10121 that we will encounter it first in bpstat_stop_status. */
10122 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10124 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10126 if (frame_id_p (caller_frame_id
))
10128 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10129 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10132 = create_internal_breakpoint (caller_arch
, caller_pc
,
10133 bp_watchpoint_scope
,
10134 &vtable_breakpoint_ops
);
10136 /* create_internal_breakpoint could invalidate WP_FRAME. */
10139 scope_breakpoint
->enable_state
= bp_enabled
;
10141 /* Automatically delete the breakpoint when it hits. */
10142 scope_breakpoint
->disposition
= disp_del
;
10144 /* Only break in the proper frame (help with recursion). */
10145 scope_breakpoint
->frame_id
= caller_frame_id
;
10147 /* Set the address at which we will stop. */
10148 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10149 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10150 scope_breakpoint
->loc
->address
10151 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10152 scope_breakpoint
->loc
->requested_address
,
10153 scope_breakpoint
->type
);
10157 /* Now set up the breakpoint. We create all watchpoints as hardware
10158 watchpoints here even if hardware watchpoints are turned off, a call
10159 to update_watchpoint later in this function will cause the type to
10160 drop back to bp_watchpoint (software watchpoint) if required. */
10162 if (accessflag
== hw_read
)
10163 bp_type
= bp_read_watchpoint
;
10164 else if (accessflag
== hw_access
)
10165 bp_type
= bp_access_watchpoint
;
10167 bp_type
= bp_hardware_watchpoint
;
10169 std::unique_ptr
<watchpoint
> w
;
10171 w
.reset (new masked_watchpoint ());
10173 w
.reset (new watchpoint ());
10174 init_raw_breakpoint_without_location (w
.get (), nullptr, bp_type
,
10175 &vtable_breakpoint_ops
);
10177 w
->thread
= thread
;
10179 w
->disposition
= disp_donttouch
;
10180 w
->pspace
= current_program_space
;
10181 w
->exp
= std::move (exp
);
10182 w
->exp_valid_block
= exp_valid_block
;
10183 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10186 struct type
*t
= value_type (val
.get ());
10187 CORE_ADDR addr
= value_as_address (val
.get ());
10189 w
->exp_string_reparse
10190 = current_language
->watch_location_expression (t
, addr
);
10192 w
->exp_string
= xstrprintf ("-location %.*s",
10193 (int) (exp_end
- exp_start
), exp_start
);
10196 w
->exp_string
.reset (savestring (exp_start
, exp_end
- exp_start
));
10200 w
->hw_wp_mask
= mask
;
10205 w
->val_bitpos
= saved_bitpos
;
10206 w
->val_bitsize
= saved_bitsize
;
10207 w
->val_valid
= true;
10211 w
->cond_string
.reset (savestring (cond_start
, cond_end
- cond_start
));
10213 w
->cond_string
= 0;
10215 if (frame_id_p (watchpoint_frame
))
10217 w
->watchpoint_frame
= watchpoint_frame
;
10218 w
->watchpoint_thread
= inferior_ptid
;
10222 w
->watchpoint_frame
= null_frame_id
;
10223 w
->watchpoint_thread
= null_ptid
;
10226 if (scope_breakpoint
!= NULL
)
10228 /* The scope breakpoint is related to the watchpoint. We will
10229 need to act on them together. */
10230 w
->related_breakpoint
= scope_breakpoint
;
10231 scope_breakpoint
->related_breakpoint
= w
.get ();
10234 if (!just_location
)
10235 value_free_to_mark (mark
);
10237 /* Finally update the new watchpoint. This creates the locations
10238 that should be inserted. */
10239 update_watchpoint (w
.get (), 1);
10241 install_breakpoint (internal
, std::move (w
), 1);
10244 /* Return count of debug registers needed to watch the given expression.
10245 If the watchpoint cannot be handled in hardware return zero. */
10248 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10250 int found_memory_cnt
= 0;
10252 /* Did the user specifically forbid us to use hardware watchpoints? */
10253 if (!can_use_hw_watchpoints
)
10256 gdb_assert (!vals
.empty ());
10257 struct value
*head
= vals
[0].get ();
10259 /* Make sure that the value of the expression depends only upon
10260 memory contents, and values computed from them within GDB. If we
10261 find any register references or function calls, we can't use a
10262 hardware watchpoint.
10264 The idea here is that evaluating an expression generates a series
10265 of values, one holding the value of every subexpression. (The
10266 expression a*b+c has five subexpressions: a, b, a*b, c, and
10267 a*b+c.) GDB's values hold almost enough information to establish
10268 the criteria given above --- they identify memory lvalues,
10269 register lvalues, computed values, etcetera. So we can evaluate
10270 the expression, and then scan the chain of values that leaves
10271 behind to decide whether we can detect any possible change to the
10272 expression's final value using only hardware watchpoints.
10274 However, I don't think that the values returned by inferior
10275 function calls are special in any way. So this function may not
10276 notice that an expression involving an inferior function call
10277 can't be watched with hardware watchpoints. FIXME. */
10278 for (const value_ref_ptr
&iter
: vals
)
10280 struct value
*v
= iter
.get ();
10282 if (VALUE_LVAL (v
) == lval_memory
)
10284 if (v
!= head
&& value_lazy (v
))
10285 /* A lazy memory lvalue in the chain is one that GDB never
10286 needed to fetch; we either just used its address (e.g.,
10287 `a' in `a.b') or we never needed it at all (e.g., `a'
10288 in `a,b'). This doesn't apply to HEAD; if that is
10289 lazy then it was not readable, but watch it anyway. */
10293 /* Ahh, memory we actually used! Check if we can cover
10294 it with hardware watchpoints. */
10295 struct type
*vtype
= check_typedef (value_type (v
));
10297 /* We only watch structs and arrays if user asked for it
10298 explicitly, never if they just happen to appear in a
10299 middle of some value chain. */
10301 || (vtype
->code () != TYPE_CODE_STRUCT
10302 && vtype
->code () != TYPE_CODE_ARRAY
))
10304 CORE_ADDR vaddr
= value_address (v
);
10308 len
= (target_exact_watchpoints
10309 && is_scalar_type_recursive (vtype
))?
10310 1 : TYPE_LENGTH (value_type (v
));
10312 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10316 found_memory_cnt
+= num_regs
;
10320 else if (VALUE_LVAL (v
) != not_lval
10321 && deprecated_value_modifiable (v
) == 0)
10322 return 0; /* These are values from the history (e.g., $1). */
10323 else if (VALUE_LVAL (v
) == lval_register
)
10324 return 0; /* Cannot watch a register with a HW watchpoint. */
10327 /* The expression itself looks suitable for using a hardware
10328 watchpoint, but give the target machine a chance to reject it. */
10329 return found_memory_cnt
;
10333 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10335 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10338 /* Options for the watch, awatch, and rwatch commands. */
10340 struct watch_options
10342 /* For -location. */
10343 bool location
= false;
10346 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10348 Historically GDB always accepted both '-location' and '-l' flags for
10349 these commands (both flags being synonyms). When converting to the
10350 newer option scheme only '-location' is added here. That's fine (for
10351 backward compatibility) as any non-ambiguous prefix of a flag will be
10352 accepted, so '-l', '-loc', are now all accepted.
10354 What this means is that, if in the future, we add any new flag here
10355 that starts with '-l' then this will break backward compatibility, so
10356 please, don't do that! */
10358 static const gdb::option::option_def watch_option_defs
[] = {
10359 gdb::option::flag_option_def
<watch_options
> {
10361 [] (watch_options
*opt
) { return &opt
->location
; },
10363 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10364 -l can be used as a short form of -location."),
10368 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10371 static gdb::option::option_def_group
10372 make_watch_options_def_group (watch_options
*opts
)
10374 return {{watch_option_defs
}, opts
};
10377 /* A helper function that looks for the "-location" argument and then
10378 calls watch_command_1. */
10381 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10383 watch_options opts
;
10384 auto grp
= make_watch_options_def_group (&opts
);
10385 gdb::option::process_options
10386 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
10387 if (arg
!= nullptr && *arg
== '\0')
10390 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
10393 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10395 watch_command_completer (struct cmd_list_element
*ignore
,
10396 completion_tracker
&tracker
,
10397 const char *text
, const char * /*word*/)
10399 const auto group
= make_watch_options_def_group (nullptr);
10400 if (gdb::option::complete_options
10401 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
10404 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
10405 expression_completer (ignore
, tracker
, text
, word
);
10409 watch_command (const char *arg
, int from_tty
)
10411 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10415 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10417 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10421 rwatch_command (const char *arg
, int from_tty
)
10423 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10427 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10429 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10433 awatch_command (const char *arg
, int from_tty
)
10435 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10439 /* Data for the FSM that manages the until(location)/advance commands
10440 in infcmd.c. Here because it uses the mechanisms of
10443 struct until_break_fsm
: public thread_fsm
10445 /* The thread that was current when the command was executed. */
10448 /* The breakpoint set at the return address in the caller frame,
10449 plus breakpoints at all the destination locations. */
10450 std::vector
<breakpoint_up
> breakpoints
;
10452 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10453 std::vector
<breakpoint_up
> &&breakpoints
)
10454 : thread_fsm (cmd_interp
),
10456 breakpoints (std::move (breakpoints
))
10460 void clean_up (struct thread_info
*thread
) override
;
10461 bool should_stop (struct thread_info
*thread
) override
;
10462 enum async_reply_reason
do_async_reply_reason () override
;
10465 /* Implementation of the 'should_stop' FSM method for the
10466 until(location)/advance commands. */
10469 until_break_fsm::should_stop (struct thread_info
*tp
)
10471 for (const breakpoint_up
&bp
: breakpoints
)
10472 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10473 bp
.get ()) != NULL
)
10482 /* Implementation of the 'clean_up' FSM method for the
10483 until(location)/advance commands. */
10486 until_break_fsm::clean_up (struct thread_info
*)
10488 /* Clean up our temporary breakpoints. */
10489 breakpoints
.clear ();
10490 delete_longjmp_breakpoint (thread
);
10493 /* Implementation of the 'async_reply_reason' FSM method for the
10494 until(location)/advance commands. */
10496 enum async_reply_reason
10497 until_break_fsm::do_async_reply_reason ()
10499 return EXEC_ASYNC_LOCATION_REACHED
;
10503 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10505 struct frame_info
*frame
;
10506 struct gdbarch
*frame_gdbarch
;
10507 struct frame_id stack_frame_id
;
10508 struct frame_id caller_frame_id
;
10510 struct thread_info
*tp
;
10512 clear_proceed_status (0);
10514 /* Set a breakpoint where the user wants it and at return from
10517 event_location_up location
= string_to_event_location (&arg
, current_language
);
10519 std::vector
<symtab_and_line
> sals
10520 = (last_displayed_sal_is_valid ()
10521 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10522 get_last_displayed_symtab (),
10523 get_last_displayed_line ())
10524 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
10528 error (_("Couldn't get information on specified line."));
10531 error (_("Junk at end of arguments."));
10533 tp
= inferior_thread ();
10534 thread
= tp
->global_num
;
10536 /* Note linespec handling above invalidates the frame chain.
10537 Installing a breakpoint also invalidates the frame chain (as it
10538 may need to switch threads), so do any frame handling before
10541 frame
= get_selected_frame (NULL
);
10542 frame_gdbarch
= get_frame_arch (frame
);
10543 stack_frame_id
= get_stack_frame_id (frame
);
10544 caller_frame_id
= frame_unwind_caller_id (frame
);
10546 /* Keep within the current frame, or in frames called by the current
10549 std::vector
<breakpoint_up
> breakpoints
;
10551 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
10553 if (frame_id_p (caller_frame_id
))
10555 struct symtab_and_line sal2
;
10556 struct gdbarch
*caller_gdbarch
;
10558 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10559 sal2
.pc
= frame_unwind_caller_pc (frame
);
10560 caller_gdbarch
= frame_unwind_caller_arch (frame
);
10562 breakpoint_up caller_breakpoint
10563 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
10564 caller_frame_id
, bp_until
);
10565 breakpoints
.emplace_back (std::move (caller_breakpoint
));
10567 set_longjmp_breakpoint (tp
, caller_frame_id
);
10568 lj_deleter
.emplace (thread
);
10571 /* set_momentary_breakpoint could invalidate FRAME. */
10574 /* If the user told us to continue until a specified location, we
10575 don't specify a frame at which we need to stop. Otherwise,
10576 specify the selected frame, because we want to stop only at the
10577 very same frame. */
10578 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
10580 for (symtab_and_line
&sal
: sals
)
10582 resolve_sal_pc (&sal
);
10584 breakpoint_up location_breakpoint
10585 = set_momentary_breakpoint (frame_gdbarch
, sal
,
10586 stop_frame_id
, bp_until
);
10587 breakpoints
.emplace_back (std::move (location_breakpoint
));
10591 (std::unique_ptr
<thread_fsm
>
10592 (new until_break_fsm (command_interp (), tp
->global_num
,
10593 std::move (breakpoints
))));
10596 lj_deleter
->release ();
10598 proceed (-1, GDB_SIGNAL_DEFAULT
);
10602 init_ada_exception_breakpoint (struct breakpoint
*b
,
10603 struct gdbarch
*gdbarch
,
10604 struct symtab_and_line sal
,
10605 const char *addr_string
,
10606 const struct breakpoint_ops
*ops
,
10613 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
10615 loc_gdbarch
= gdbarch
;
10617 describe_other_breakpoints (loc_gdbarch
,
10618 sal
.pspace
, sal
.pc
, sal
.section
, -1);
10619 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10620 version for exception catchpoints, because two catchpoints
10621 used for different exception names will use the same address.
10622 In this case, a "breakpoint ... also set at..." warning is
10623 unproductive. Besides, the warning phrasing is also a bit
10624 inappropriate, we should use the word catchpoint, and tell
10625 the user what type of catchpoint it is. The above is good
10626 enough for now, though. */
10629 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
10631 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
10632 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10633 b
->location
= string_to_event_location (&addr_string
,
10634 language_def (language_ada
));
10635 b
->language
= language_ada
;
10640 /* Compare two breakpoints and return a strcmp-like result. */
10643 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
10645 uintptr_t ua
= (uintptr_t) a
;
10646 uintptr_t ub
= (uintptr_t) b
;
10648 if (a
->number
< b
->number
)
10650 else if (a
->number
> b
->number
)
10653 /* Now sort by address, in case we see, e..g, two breakpoints with
10657 return ua
> ub
? 1 : 0;
10660 /* Delete breakpoints by address or line. */
10663 clear_command (const char *arg
, int from_tty
)
10667 std::vector
<symtab_and_line
> decoded_sals
;
10668 symtab_and_line last_sal
;
10669 gdb::array_view
<symtab_and_line
> sals
;
10673 = decode_line_with_current_source (arg
,
10674 (DECODE_LINE_FUNFIRSTLINE
10675 | DECODE_LINE_LIST_MODE
));
10677 sals
= decoded_sals
;
10681 /* Set sal's line, symtab, pc, and pspace to the values
10682 corresponding to the last call to print_frame_info. If the
10683 codepoint is not valid, this will set all the fields to 0. */
10684 last_sal
= get_last_displayed_sal ();
10685 if (last_sal
.symtab
== 0)
10686 error (_("No source file specified."));
10692 /* We don't call resolve_sal_pc here. That's not as bad as it
10693 seems, because all existing breakpoints typically have both
10694 file/line and pc set. So, if clear is given file/line, we can
10695 match this to existing breakpoint without obtaining pc at all.
10697 We only support clearing given the address explicitly
10698 present in breakpoint table. Say, we've set breakpoint
10699 at file:line. There were several PC values for that file:line,
10700 due to optimization, all in one block.
10702 We've picked one PC value. If "clear" is issued with another
10703 PC corresponding to the same file:line, the breakpoint won't
10704 be cleared. We probably can still clear the breakpoint, but
10705 since the other PC value is never presented to user, user
10706 can only find it by guessing, and it does not seem important
10707 to support that. */
10709 /* For each line spec given, delete bps which correspond to it. Do
10710 it in two passes, solely to preserve the current behavior that
10711 from_tty is forced true if we delete more than one
10714 std::vector
<struct breakpoint
*> found
;
10715 for (const auto &sal
: sals
)
10717 const char *sal_fullname
;
10719 /* If exact pc given, clear bpts at that pc.
10720 If line given (pc == 0), clear all bpts on specified line.
10721 If defaulting, clear all bpts on default line
10724 defaulting sal.pc != 0 tests to do
10729 1 0 <can't happen> */
10731 sal_fullname
= (sal
.symtab
== NULL
10732 ? NULL
: symtab_to_fullname (sal
.symtab
));
10734 /* Find all matching breakpoints and add them to 'found'. */
10735 for (breakpoint
*b
: all_breakpoints ())
10738 /* Are we going to delete b? */
10739 if (b
->type
!= bp_none
&& !is_watchpoint (b
)
10740 && user_breakpoint_p (b
))
10742 for (bp_location
*loc
: b
->locations ())
10744 /* If the user specified file:line, don't allow a PC
10745 match. This matches historical gdb behavior. */
10746 int pc_match
= (!sal
.explicit_line
10748 && (loc
->pspace
== sal
.pspace
)
10749 && (loc
->address
== sal
.pc
)
10750 && (!section_is_overlay (loc
->section
)
10751 || loc
->section
== sal
.section
));
10752 int line_match
= 0;
10754 if ((default_match
|| sal
.explicit_line
)
10755 && loc
->symtab
!= NULL
10756 && sal_fullname
!= NULL
10757 && sal
.pspace
== loc
->pspace
10758 && loc
->line_number
== sal
.line
10759 && filename_cmp (symtab_to_fullname (loc
->symtab
),
10760 sal_fullname
) == 0)
10763 if (pc_match
|| line_match
)
10772 found
.push_back (b
);
10776 /* Now go thru the 'found' chain and delete them. */
10777 if (found
.empty ())
10780 error (_("No breakpoint at %s."), arg
);
10782 error (_("No breakpoint at this line."));
10785 /* Remove duplicates from the vec. */
10786 std::sort (found
.begin (), found
.end (),
10787 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10789 return compare_breakpoints (bp_a
, bp_b
) < 0;
10791 found
.erase (std::unique (found
.begin (), found
.end (),
10792 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10794 return compare_breakpoints (bp_a
, bp_b
) == 0;
10798 if (found
.size () > 1)
10799 from_tty
= 1; /* Always report if deleted more than one. */
10802 if (found
.size () == 1)
10803 gdb_printf (_("Deleted breakpoint "));
10805 gdb_printf (_("Deleted breakpoints "));
10808 for (breakpoint
*iter
: found
)
10811 gdb_printf ("%d ", iter
->number
);
10812 delete_breakpoint (iter
);
10818 /* Delete breakpoint in BS if they are `delete' breakpoints and
10819 all breakpoints that are marked for deletion, whether hit or not.
10820 This is called after any breakpoint is hit, or after errors. */
10823 breakpoint_auto_delete (bpstat
*bs
)
10825 for (; bs
; bs
= bs
->next
)
10826 if (bs
->breakpoint_at
10827 && bs
->breakpoint_at
->disposition
== disp_del
10829 delete_breakpoint (bs
->breakpoint_at
);
10831 for (breakpoint
*b
: all_breakpoints_safe ())
10832 if (b
->disposition
== disp_del_at_next_stop
)
10833 delete_breakpoint (b
);
10836 /* A comparison function for bp_location AP and BP being interfaced to
10837 std::sort. Sort elements primarily by their ADDRESS (no matter what
10838 bl_address_is_meaningful says), secondarily by ordering first
10839 permanent elements and terciarily just ensuring the array is sorted
10840 stable way despite std::sort being an unstable algorithm. */
10843 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
10845 if (a
->address
!= b
->address
)
10846 return a
->address
< b
->address
;
10848 /* Sort locations at the same address by their pspace number, keeping
10849 locations of the same inferior (in a multi-inferior environment)
10852 if (a
->pspace
->num
!= b
->pspace
->num
)
10853 return a
->pspace
->num
< b
->pspace
->num
;
10855 /* Sort permanent breakpoints first. */
10856 if (a
->permanent
!= b
->permanent
)
10857 return a
->permanent
> b
->permanent
;
10859 /* Sort by type in order to make duplicate determination easier.
10860 See update_global_location_list. This is kept in sync with
10861 breakpoint_locations_match. */
10862 if (a
->loc_type
< b
->loc_type
)
10865 /* Likewise, for range-breakpoints, sort by length. */
10866 if (a
->loc_type
== bp_loc_hardware_breakpoint
10867 && b
->loc_type
== bp_loc_hardware_breakpoint
10868 && a
->length
< b
->length
)
10871 /* Make the internal GDB representation stable across GDB runs
10872 where A and B memory inside GDB can differ. Breakpoint locations of
10873 the same type at the same address can be sorted in arbitrary order. */
10875 if (a
->owner
->number
!= b
->owner
->number
)
10876 return a
->owner
->number
< b
->owner
->number
;
10881 /* Set bp_locations_placed_address_before_address_max and
10882 bp_locations_shadow_len_after_address_max according to the current
10883 content of the bp_locations array. */
10886 bp_locations_target_extensions_update (void)
10888 bp_locations_placed_address_before_address_max
= 0;
10889 bp_locations_shadow_len_after_address_max
= 0;
10891 for (bp_location
*bl
: all_bp_locations ())
10893 CORE_ADDR start
, end
, addr
;
10895 if (!bp_location_has_shadow (bl
))
10898 start
= bl
->target_info
.placed_address
;
10899 end
= start
+ bl
->target_info
.shadow_len
;
10901 gdb_assert (bl
->address
>= start
);
10902 addr
= bl
->address
- start
;
10903 if (addr
> bp_locations_placed_address_before_address_max
)
10904 bp_locations_placed_address_before_address_max
= addr
;
10906 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10908 gdb_assert (bl
->address
< end
);
10909 addr
= end
- bl
->address
;
10910 if (addr
> bp_locations_shadow_len_after_address_max
)
10911 bp_locations_shadow_len_after_address_max
= addr
;
10915 /* Download tracepoint locations if they haven't been. */
10918 download_tracepoint_locations (void)
10920 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
10922 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
10924 for (breakpoint
*b
: all_tracepoints ())
10926 struct tracepoint
*t
;
10927 int bp_location_downloaded
= 0;
10929 if ((b
->type
== bp_fast_tracepoint
10930 ? !may_insert_fast_tracepoints
10931 : !may_insert_tracepoints
))
10934 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
10936 if (target_can_download_tracepoint ())
10937 can_download_tracepoint
= TRIBOOL_TRUE
;
10939 can_download_tracepoint
= TRIBOOL_FALSE
;
10942 if (can_download_tracepoint
== TRIBOOL_FALSE
)
10945 for (bp_location
*bl
: b
->locations ())
10947 /* In tracepoint, locations are _never_ duplicated, so
10948 should_be_inserted is equivalent to
10949 unduplicated_should_be_inserted. */
10950 if (!should_be_inserted (bl
) || bl
->inserted
)
10953 switch_to_program_space_and_thread (bl
->pspace
);
10955 target_download_tracepoint (bl
);
10958 bp_location_downloaded
= 1;
10960 t
= (struct tracepoint
*) b
;
10961 t
->number_on_target
= b
->number
;
10962 if (bp_location_downloaded
)
10963 gdb::observers::breakpoint_modified
.notify (b
);
10967 /* Swap the insertion/duplication state between two locations. */
10970 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10972 const int left_inserted
= left
->inserted
;
10973 const int left_duplicate
= left
->duplicate
;
10974 const int left_needs_update
= left
->needs_update
;
10975 const struct bp_target_info left_target_info
= left
->target_info
;
10977 /* Locations of tracepoints can never be duplicated. */
10978 if (is_tracepoint (left
->owner
))
10979 gdb_assert (!left
->duplicate
);
10980 if (is_tracepoint (right
->owner
))
10981 gdb_assert (!right
->duplicate
);
10983 left
->inserted
= right
->inserted
;
10984 left
->duplicate
= right
->duplicate
;
10985 left
->needs_update
= right
->needs_update
;
10986 left
->target_info
= right
->target_info
;
10987 right
->inserted
= left_inserted
;
10988 right
->duplicate
= left_duplicate
;
10989 right
->needs_update
= left_needs_update
;
10990 right
->target_info
= left_target_info
;
10993 /* Force the re-insertion of the locations at ADDRESS. This is called
10994 once a new/deleted/modified duplicate location is found and we are evaluating
10995 conditions on the target's side. Such conditions need to be updated on
10999 force_breakpoint_reinsertion (struct bp_location
*bl
)
11001 CORE_ADDR address
= 0;
11004 address
= bl
->address
;
11005 pspace_num
= bl
->pspace
->num
;
11007 /* This is only meaningful if the target is
11008 evaluating conditions and if the user has
11009 opted for condition evaluation on the target's
11011 if (gdb_evaluates_breakpoint_condition_p ()
11012 || !target_supports_evaluation_of_breakpoint_conditions ())
11015 /* Flag all breakpoint locations with this address and
11016 the same program space as the location
11017 as "its condition has changed". We need to
11018 update the conditions on the target's side. */
11019 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
11021 if (!is_breakpoint (loc
->owner
)
11022 || pspace_num
!= loc
->pspace
->num
)
11025 /* Flag the location appropriately. We use a different state to
11026 let everyone know that we already updated the set of locations
11027 with addr bl->address and program space bl->pspace. This is so
11028 we don't have to keep calling these functions just to mark locations
11029 that have already been marked. */
11030 loc
->condition_changed
= condition_updated
;
11032 /* Free the agent expression bytecode as well. We will compute
11034 loc
->cond_bytecode
.reset ();
11038 /* Called whether new breakpoints are created, or existing breakpoints
11039 deleted, to update the global location list and recompute which
11040 locations are duplicate of which.
11042 The INSERT_MODE flag determines whether locations may not, may, or
11043 shall be inserted now. See 'enum ugll_insert_mode' for more
11047 update_global_location_list (enum ugll_insert_mode insert_mode
)
11049 /* Last breakpoint location address that was marked for update. */
11050 CORE_ADDR last_addr
= 0;
11051 /* Last breakpoint location program space that was marked for update. */
11052 int last_pspace_num
= -1;
11054 /* Used in the duplicates detection below. When iterating over all
11055 bp_locations, points to the first bp_location of a given address.
11056 Breakpoints and watchpoints of different types are never
11057 duplicates of each other. Keep one pointer for each type of
11058 breakpoint/watchpoint, so we only need to loop over all locations
11060 struct bp_location
*bp_loc_first
; /* breakpoint */
11061 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11062 struct bp_location
*awp_loc_first
; /* access watchpoint */
11063 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11065 /* Saved former bp_locations array which we compare against the newly
11066 built bp_locations from the current state of ALL_BREAKPOINTS. */
11067 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
11068 bp_locations
.clear ();
11070 for (breakpoint
*b
: all_breakpoints ())
11071 for (bp_location
*loc
: b
->locations ())
11072 bp_locations
.push_back (loc
);
11074 /* See if we need to "upgrade" a software breakpoint to a hardware
11075 breakpoint. Do this before deciding whether locations are
11076 duplicates. Also do this before sorting because sorting order
11077 depends on location type. */
11078 for (bp_location
*loc
: bp_locations
)
11079 if (!loc
->inserted
&& should_be_inserted (loc
))
11080 handle_automatic_hardware_breakpoints (loc
);
11082 std::sort (bp_locations
.begin (), bp_locations
.end (),
11083 bp_location_is_less_than
);
11085 bp_locations_target_extensions_update ();
11087 /* Identify bp_location instances that are no longer present in the
11088 new list, and therefore should be freed. Note that it's not
11089 necessary that those locations should be removed from inferior --
11090 if there's another location at the same address (previously
11091 marked as duplicate), we don't need to remove/insert the
11094 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11095 and former bp_location array state respectively. */
11098 for (bp_location
*old_loc
: old_locations
)
11100 /* Tells if 'old_loc' is found among the new locations. If
11101 not, we have to free it. */
11102 int found_object
= 0;
11103 /* Tells if the location should remain inserted in the target. */
11104 int keep_in_target
= 0;
11107 /* Skip LOCP entries which will definitely never be needed.
11108 Stop either at or being the one matching OLD_LOC. */
11109 while (loc_i
< bp_locations
.size ()
11110 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11113 for (size_t loc2_i
= loc_i
;
11114 (loc2_i
< bp_locations
.size ()
11115 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11118 /* Check if this is a new/duplicated location or a duplicated
11119 location that had its condition modified. If so, we want to send
11120 its condition to the target if evaluation of conditions is taking
11122 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11123 && (last_addr
!= old_loc
->address
11124 || last_pspace_num
!= old_loc
->pspace
->num
))
11126 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11127 last_pspace_num
= old_loc
->pspace
->num
;
11130 if (bp_locations
[loc2_i
] == old_loc
)
11134 /* We have already handled this address, update it so that we don't
11135 have to go through updates again. */
11136 last_addr
= old_loc
->address
;
11138 /* Target-side condition evaluation: Handle deleted locations. */
11140 force_breakpoint_reinsertion (old_loc
);
11142 /* If this location is no longer present, and inserted, look if
11143 there's maybe a new location at the same address. If so,
11144 mark that one inserted, and don't remove this one. This is
11145 needed so that we don't have a time window where a breakpoint
11146 at certain location is not inserted. */
11148 if (old_loc
->inserted
)
11150 /* If the location is inserted now, we might have to remove
11153 if (found_object
&& should_be_inserted (old_loc
))
11155 /* The location is still present in the location list,
11156 and still should be inserted. Don't do anything. */
11157 keep_in_target
= 1;
11161 /* This location still exists, but it won't be kept in the
11162 target since it may have been disabled. We proceed to
11163 remove its target-side condition. */
11165 /* The location is either no longer present, or got
11166 disabled. See if there's another location at the
11167 same address, in which case we don't need to remove
11168 this one from the target. */
11170 /* OLD_LOC comes from existing struct breakpoint. */
11171 if (bl_address_is_meaningful (old_loc
))
11173 for (size_t loc2_i
= loc_i
;
11174 (loc2_i
< bp_locations
.size ()
11175 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11178 bp_location
*loc2
= bp_locations
[loc2_i
];
11180 if (loc2
== old_loc
)
11183 if (breakpoint_locations_match (loc2
, old_loc
))
11185 /* Read watchpoint locations are switched to
11186 access watchpoints, if the former are not
11187 supported, but the latter are. */
11188 if (is_hardware_watchpoint (old_loc
->owner
))
11190 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11191 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11194 /* loc2 is a duplicated location. We need to check
11195 if it should be inserted in case it will be
11197 if (unduplicated_should_be_inserted (loc2
))
11199 swap_insertion (old_loc
, loc2
);
11200 keep_in_target
= 1;
11208 if (!keep_in_target
)
11210 if (remove_breakpoint (old_loc
))
11212 /* This is just about all we can do. We could keep
11213 this location on the global list, and try to
11214 remove it next time, but there's no particular
11215 reason why we will succeed next time.
11217 Note that at this point, old_loc->owner is still
11218 valid, as delete_breakpoint frees the breakpoint
11219 only after calling us. */
11220 gdb_printf (_("warning: Error removing "
11221 "breakpoint %d\n"),
11222 old_loc
->owner
->number
);
11230 if (removed
&& target_is_non_stop_p ()
11231 && need_moribund_for_location_type (old_loc
))
11233 /* This location was removed from the target. In
11234 non-stop mode, a race condition is possible where
11235 we've removed a breakpoint, but stop events for that
11236 breakpoint are already queued and will arrive later.
11237 We apply an heuristic to be able to distinguish such
11238 SIGTRAPs from other random SIGTRAPs: we keep this
11239 breakpoint location for a bit, and will retire it
11240 after we see some number of events. The theory here
11241 is that reporting of events should, "on the average",
11242 be fair, so after a while we'll see events from all
11243 threads that have anything of interest, and no longer
11244 need to keep this breakpoint location around. We
11245 don't hold locations forever so to reduce chances of
11246 mistaking a non-breakpoint SIGTRAP for a breakpoint
11249 The heuristic failing can be disastrous on
11250 decr_pc_after_break targets.
11252 On decr_pc_after_break targets, like e.g., x86-linux,
11253 if we fail to recognize a late breakpoint SIGTRAP,
11254 because events_till_retirement has reached 0 too
11255 soon, we'll fail to do the PC adjustment, and report
11256 a random SIGTRAP to the user. When the user resumes
11257 the inferior, it will most likely immediately crash
11258 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11259 corrupted, because of being resumed e.g., in the
11260 middle of a multi-byte instruction, or skipped a
11261 one-byte instruction. This was actually seen happen
11262 on native x86-linux, and should be less rare on
11263 targets that do not support new thread events, like
11264 remote, due to the heuristic depending on
11267 Mistaking a random SIGTRAP for a breakpoint trap
11268 causes similar symptoms (PC adjustment applied when
11269 it shouldn't), but then again, playing with SIGTRAPs
11270 behind the debugger's back is asking for trouble.
11272 Since hardware watchpoint traps are always
11273 distinguishable from other traps, so we don't need to
11274 apply keep hardware watchpoint moribund locations
11275 around. We simply always ignore hardware watchpoint
11276 traps we can no longer explain. */
11278 process_stratum_target
*proc_target
= nullptr;
11279 for (inferior
*inf
: all_inferiors ())
11280 if (inf
->pspace
== old_loc
->pspace
)
11282 proc_target
= inf
->process_target ();
11285 if (proc_target
!= nullptr)
11286 old_loc
->events_till_retirement
11287 = 3 * (thread_count (proc_target
) + 1);
11289 old_loc
->events_till_retirement
= 1;
11290 old_loc
->owner
= NULL
;
11292 moribund_locations
.push_back (old_loc
);
11296 old_loc
->owner
= NULL
;
11297 decref_bp_location (&old_loc
);
11302 /* Rescan breakpoints at the same address and section, marking the
11303 first one as "first" and any others as "duplicates". This is so
11304 that the bpt instruction is only inserted once. If we have a
11305 permanent breakpoint at the same place as BPT, make that one the
11306 official one, and the rest as duplicates. Permanent breakpoints
11307 are sorted first for the same address.
11309 Do the same for hardware watchpoints, but also considering the
11310 watchpoint's type (regular/access/read) and length. */
11312 bp_loc_first
= NULL
;
11313 wp_loc_first
= NULL
;
11314 awp_loc_first
= NULL
;
11315 rwp_loc_first
= NULL
;
11317 for (bp_location
*loc
: all_bp_locations ())
11319 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11321 struct bp_location
**loc_first_p
;
11322 breakpoint
*b
= loc
->owner
;
11324 if (!unduplicated_should_be_inserted (loc
)
11325 || !bl_address_is_meaningful (loc
)
11326 /* Don't detect duplicate for tracepoint locations because they are
11327 never duplicated. See the comments in field `duplicate' of
11328 `struct bp_location'. */
11329 || is_tracepoint (b
))
11331 /* Clear the condition modification flag. */
11332 loc
->condition_changed
= condition_unchanged
;
11336 if (b
->type
== bp_hardware_watchpoint
)
11337 loc_first_p
= &wp_loc_first
;
11338 else if (b
->type
== bp_read_watchpoint
)
11339 loc_first_p
= &rwp_loc_first
;
11340 else if (b
->type
== bp_access_watchpoint
)
11341 loc_first_p
= &awp_loc_first
;
11343 loc_first_p
= &bp_loc_first
;
11345 if (*loc_first_p
== NULL
11346 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11347 || !breakpoint_locations_match (loc
, *loc_first_p
))
11349 *loc_first_p
= loc
;
11350 loc
->duplicate
= 0;
11352 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11354 loc
->needs_update
= 1;
11355 /* Clear the condition modification flag. */
11356 loc
->condition_changed
= condition_unchanged
;
11362 /* This and the above ensure the invariant that the first location
11363 is not duplicated, and is the inserted one.
11364 All following are marked as duplicated, and are not inserted. */
11366 swap_insertion (loc
, *loc_first_p
);
11367 loc
->duplicate
= 1;
11369 /* Clear the condition modification flag. */
11370 loc
->condition_changed
= condition_unchanged
;
11373 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11375 if (insert_mode
!= UGLL_DONT_INSERT
)
11376 insert_breakpoint_locations ();
11379 /* Even though the caller told us to not insert new
11380 locations, we may still need to update conditions on the
11381 target's side of breakpoints that were already inserted
11382 if the target is evaluating breakpoint conditions. We
11383 only update conditions for locations that are marked
11385 update_inserted_breakpoint_locations ();
11389 if (insert_mode
!= UGLL_DONT_INSERT
)
11390 download_tracepoint_locations ();
11394 breakpoint_retire_moribund (void)
11396 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11398 struct bp_location
*loc
= moribund_locations
[ix
];
11399 if (--(loc
->events_till_retirement
) == 0)
11401 decref_bp_location (&loc
);
11402 unordered_remove (moribund_locations
, ix
);
11409 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
11414 update_global_location_list (insert_mode
);
11416 catch (const gdb_exception_error
&e
)
11421 /* Clear BKP from a BPS. */
11424 bpstat_remove_bp_location (bpstat
*bps
, struct breakpoint
*bpt
)
11428 for (bs
= bps
; bs
; bs
= bs
->next
)
11429 if (bs
->breakpoint_at
== bpt
)
11431 bs
->breakpoint_at
= NULL
;
11432 bs
->old_val
= NULL
;
11433 /* bs->commands will be freed later. */
11437 /* Callback for iterate_over_threads. */
11439 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11441 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
11443 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11447 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
11451 say_where (struct breakpoint
*b
)
11453 struct value_print_options opts
;
11455 get_user_print_options (&opts
);
11457 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11459 if (b
->loc
== NULL
)
11461 /* For pending locations, the output differs slightly based
11462 on b->extra_string. If this is non-NULL, it contains either
11463 a condition or dprintf arguments. */
11464 if (b
->extra_string
== NULL
)
11466 gdb_printf (_(" (%s) pending."),
11467 event_location_to_string (b
->location
.get ()));
11469 else if (b
->type
== bp_dprintf
)
11471 gdb_printf (_(" (%s,%s) pending."),
11472 event_location_to_string (b
->location
.get ()),
11473 b
->extra_string
.get ());
11477 gdb_printf (_(" (%s %s) pending."),
11478 event_location_to_string (b
->location
.get ()),
11479 b
->extra_string
.get ());
11484 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
11485 gdb_printf (" at %ps",
11486 styled_string (address_style
.style (),
11487 paddress (b
->loc
->gdbarch
,
11488 b
->loc
->address
)));
11489 if (b
->loc
->symtab
!= NULL
)
11491 /* If there is a single location, we can print the location
11493 if (b
->loc
->next
== NULL
)
11495 const char *filename
11496 = symtab_to_filename_for_display (b
->loc
->symtab
);
11497 gdb_printf (": file %ps, line %d.",
11498 styled_string (file_name_style
.style (),
11500 b
->loc
->line_number
);
11503 /* This is not ideal, but each location may have a
11504 different file name, and this at least reflects the
11505 real situation somewhat. */
11506 gdb_printf (": %s.",
11507 event_location_to_string (b
->location
.get ()));
11512 struct bp_location
*loc
= b
->loc
;
11514 for (; loc
; loc
= loc
->next
)
11516 gdb_printf (" (%d locations)", n
);
11521 /* See breakpoint.h. */
11523 bp_location_range
breakpoint::locations ()
11525 return bp_location_range (this->loc
);
11528 static struct bp_location
*
11529 base_breakpoint_allocate_location (struct breakpoint
*self
)
11531 return new bp_location (self
);
11534 struct bp_location
*
11535 breakpoint::allocate_location ()
11537 return new bp_location (this);
11541 base_breakpoint_re_set (struct breakpoint
*b
)
11543 /* Nothing to re-set. */
11546 #define internal_error_pure_virtual_called() \
11547 gdb_assert_not_reached ("pure virtual function called")
11550 base_breakpoint_insert_location (struct bp_location
*bl
)
11552 internal_error_pure_virtual_called ();
11556 breakpoint::insert_location (struct bp_location
*bl
)
11558 internal_error_pure_virtual_called ();
11562 base_breakpoint_remove_location (struct bp_location
*bl
,
11563 enum remove_bp_reason reason
)
11565 internal_error_pure_virtual_called ();
11569 breakpoint::remove_location (struct bp_location
*bl
,
11570 enum remove_bp_reason reason
)
11572 internal_error_pure_virtual_called ();
11576 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
11577 const address_space
*aspace
,
11579 const target_waitstatus
&ws
)
11581 internal_error_pure_virtual_called ();
11585 breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11586 const address_space
*aspace
,
11588 const target_waitstatus
&ws
)
11590 internal_error_pure_virtual_called ();
11594 base_breakpoint_check_status (bpstat
*bs
)
11599 /* A "works_in_software_mode" breakpoint_ops method that just internal
11603 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
11605 internal_error_pure_virtual_called ();
11609 breakpoint::works_in_software_mode () const
11611 internal_error_pure_virtual_called ();
11614 /* A "resources_needed" breakpoint_ops method that just internal
11618 base_breakpoint_resources_needed (const struct bp_location
*bl
)
11620 internal_error_pure_virtual_called ();
11624 breakpoint::resources_needed (const struct bp_location
*bl
)
11626 internal_error_pure_virtual_called ();
11629 static enum print_stop_action
11630 base_breakpoint_print_it (bpstat
*bs
)
11632 internal_error_pure_virtual_called ();
11635 enum print_stop_action
11636 breakpoint::print_it (bpstat
*bs
)
11638 internal_error_pure_virtual_called ();
11642 base_breakpoint_print_one (struct breakpoint
*, struct bp_location
**)
11648 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
11649 struct ui_out
*uiout
)
11655 base_breakpoint_print_mention (struct breakpoint
*b
)
11657 internal_error_pure_virtual_called ();
11661 breakpoint::print_mention ()
11663 internal_error_pure_virtual_called ();
11667 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
11669 internal_error_pure_virtual_called ();
11673 breakpoint::print_recreate (struct ui_file
*fp
)
11675 internal_error_pure_virtual_called ();
11679 base_breakpoint_create_sals_from_location
11680 (struct event_location
*location
,
11681 struct linespec_result
*canonical
,
11682 enum bptype type_wanted
)
11684 internal_error_pure_virtual_called ();
11688 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
11689 struct linespec_result
*c
,
11690 gdb::unique_xmalloc_ptr
<char> cond_string
,
11691 gdb::unique_xmalloc_ptr
<char> extra_string
,
11692 enum bptype type_wanted
,
11693 enum bpdisp disposition
,
11695 int task
, int ignore_count
,
11696 const struct breakpoint_ops
*o
,
11697 int from_tty
, int enabled
,
11698 int internal
, unsigned flags
)
11700 internal_error_pure_virtual_called ();
11703 static std::vector
<symtab_and_line
>
11704 base_breakpoint_decode_location (struct breakpoint
*b
,
11705 struct event_location
*location
,
11706 struct program_space
*search_pspace
)
11708 internal_error_pure_virtual_called ();
11711 std::vector
<symtab_and_line
>
11712 breakpoint::decode_location (struct event_location
*location
,
11713 struct program_space
*search_pspace
)
11715 internal_error_pure_virtual_called ();
11718 /* The default 'explains_signal' method. */
11721 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
11726 /* The default "after_condition_true" method. */
11729 base_breakpoint_after_condition_true (struct bpstat
*bs
)
11731 /* Nothing to do. */
11734 struct breakpoint_ops base_breakpoint_ops
=
11736 base_breakpoint_allocate_location
,
11737 base_breakpoint_re_set
,
11738 base_breakpoint_insert_location
,
11739 base_breakpoint_remove_location
,
11740 base_breakpoint_breakpoint_hit
,
11741 base_breakpoint_check_status
,
11742 base_breakpoint_resources_needed
,
11743 base_breakpoint_works_in_software_mode
,
11744 base_breakpoint_print_it
,
11745 base_breakpoint_print_one
,
11746 base_breakpoint_print_one_detail
,
11747 base_breakpoint_print_mention
,
11748 base_breakpoint_print_recreate
,
11749 base_breakpoint_create_sals_from_location
,
11750 base_breakpoint_create_breakpoints_sal
,
11751 base_breakpoint_decode_location
,
11752 base_breakpoint_explains_signal
,
11753 base_breakpoint_after_condition_true
,
11756 struct breakpoint_ops vtable_breakpoint_ops
=
11758 [] (struct breakpoint
*b
) { return b
->allocate_location (); },
11759 [] (struct breakpoint
*b
) { b
->re_set (); },
11760 [] (struct bp_location
*l
)
11762 return l
->owner
->insert_location (l
);
11764 [] (struct bp_location
*l
, enum remove_bp_reason reason
)
11766 return l
->owner
->remove_location (l
, reason
);
11768 [] (const struct bp_location
*bl
,
11769 const address_space
*aspace
,
11771 const target_waitstatus
&ws
)
11773 return bl
->owner
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
11775 [] (struct bpstat
*bs
) { bs
->breakpoint_at
->check_status (bs
); },
11776 [] (const struct bp_location
*bl
)
11777 { return bl
->owner
->resources_needed (bl
); },
11778 [] (const struct breakpoint
*b
)
11779 { return b
->works_in_software_mode (); },
11780 [] (struct bpstat
*bs
)
11781 { return bs
->breakpoint_at
->print_it (bs
); },
11782 [] (struct breakpoint
*b
, struct bp_location
**bl
)
11783 { return b
->print_one (bl
); },
11784 [] (const struct breakpoint
*b
, struct ui_out
*out
)
11785 { b
->print_one_detail (out
); },
11786 [] (struct breakpoint
*b
) { b
->print_mention (); },
11787 [] (struct breakpoint
*b
, struct ui_file
*fp
)
11788 { b
->print_recreate (fp
); },
11789 create_sals_from_location_default
,
11790 create_breakpoints_sal_default
,
11791 [] (struct breakpoint
*b
,
11792 struct event_location
*location
,
11793 struct program_space
*search_pspace
)
11794 { return b
->decode_location (location
, search_pspace
); },
11795 [] (struct breakpoint
*b
, enum gdb_signal s
)
11796 { return b
->explains_signal (s
); },
11797 [] (struct bpstat
*bs
)
11798 { bs
->breakpoint_at
->after_condition_true (bs
); }
11801 /* Default breakpoint_ops methods. */
11804 base_breakpoint::re_set ()
11806 /* FIXME: is this still reachable? */
11807 if (breakpoint_event_location_empty_p (this))
11809 /* Anything without a location can't be re-set. */
11810 delete_breakpoint (this);
11814 breakpoint_re_set_default (this);
11818 base_breakpoint::insert_location (struct bp_location
*bl
)
11820 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
11822 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
11823 bl
->target_info
.placed_address
= addr
;
11825 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11826 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11828 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11832 base_breakpoint::remove_location (struct bp_location
*bl
,
11833 enum remove_bp_reason reason
)
11835 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11836 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11838 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
11842 base_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11843 const address_space
*aspace
,
11845 const target_waitstatus
&ws
)
11847 if (ws
.kind () != TARGET_WAITKIND_STOPPED
11848 || ws
.sig () != GDB_SIGNAL_TRAP
)
11851 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
11855 if (overlay_debugging
/* unmapped overlay section */
11856 && section_is_overlay (bl
->section
)
11857 && !section_is_mapped (bl
->section
))
11864 dprintf_breakpoint_hit (const struct bp_location
*bl
,
11865 const address_space
*aspace
, CORE_ADDR bp_addr
,
11866 const target_waitstatus
&ws
)
11868 if (dprintf_style
== dprintf_style_agent
11869 && target_can_run_breakpoint_commands ())
11871 /* An agent-style dprintf never causes a stop. If we see a trap
11872 for this address it must be for a breakpoint that happens to
11873 be set at the same address. */
11877 return bl
->owner
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
11881 bkpt_resources_needed (const struct bp_location
*bl
)
11883 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
11888 static enum print_stop_action
11889 bkpt_print_it (bpstat
*bs
)
11891 struct breakpoint
*b
;
11892 const struct bp_location
*bl
;
11894 struct ui_out
*uiout
= current_uiout
;
11896 gdb_assert (bs
->bp_location_at
!= NULL
);
11898 bl
= bs
->bp_location_at
.get ();
11899 b
= bs
->breakpoint_at
;
11901 bp_temp
= b
->disposition
== disp_del
;
11902 if (bl
->address
!= bl
->requested_address
)
11903 breakpoint_adjustment_warning (bl
->requested_address
,
11906 annotate_breakpoint (b
->number
);
11907 maybe_print_thread_hit_breakpoint (uiout
);
11909 if (uiout
->is_mi_like_p ())
11911 uiout
->field_string ("reason",
11912 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11913 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
11916 uiout
->message ("Temporary breakpoint %pF, ",
11917 signed_field ("bkptno", b
->number
));
11919 uiout
->message ("Breakpoint %pF, ",
11920 signed_field ("bkptno", b
->number
));
11922 return PRINT_SRC_AND_LOC
;
11926 bkpt_print_mention (struct breakpoint
*b
)
11928 if (current_uiout
->is_mi_like_p ())
11933 case bp_breakpoint
:
11934 case bp_gnu_ifunc_resolver
:
11935 if (b
->disposition
== disp_del
)
11936 gdb_printf (_("Temporary breakpoint"));
11938 gdb_printf (_("Breakpoint"));
11939 gdb_printf (_(" %d"), b
->number
);
11940 if (b
->type
== bp_gnu_ifunc_resolver
)
11941 gdb_printf (_(" at gnu-indirect-function resolver"));
11943 case bp_hardware_breakpoint
:
11944 gdb_printf (_("Hardware assisted breakpoint %d"), b
->number
);
11947 gdb_printf (_("Dprintf %d"), b
->number
);
11955 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
11957 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11958 gdb_printf (fp
, "tbreak");
11959 else if (tp
->type
== bp_breakpoint
)
11960 gdb_printf (fp
, "break");
11961 else if (tp
->type
== bp_hardware_breakpoint
11962 && tp
->disposition
== disp_del
)
11963 gdb_printf (fp
, "thbreak");
11964 else if (tp
->type
== bp_hardware_breakpoint
)
11965 gdb_printf (fp
, "hbreak");
11967 internal_error (__FILE__
, __LINE__
,
11968 _("unhandled breakpoint type %d"), (int) tp
->type
);
11970 gdb_printf (fp
, " %s",
11971 event_location_to_string (tp
->location
.get ()));
11973 /* Print out extra_string if this breakpoint is pending. It might
11974 contain, for example, conditions that were set by the user. */
11975 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
11976 gdb_printf (fp
, " %s", tp
->extra_string
.get ());
11978 print_recreate_thread (tp
, fp
);
11981 std::vector
<symtab_and_line
>
11982 base_breakpoint::decode_location (struct event_location
*location
,
11983 struct program_space
*search_pspace
)
11985 return decode_location_default (this, location
, search_pspace
);
11988 /* Virtual table for internal breakpoints. */
11991 internal_breakpoint::re_set ()
11995 /* Delete overlay event and longjmp master breakpoints; they
11996 will be reset later by breakpoint_re_set. */
11997 case bp_overlay_event
:
11998 case bp_longjmp_master
:
11999 case bp_std_terminate_master
:
12000 case bp_exception_master
:
12001 delete_breakpoint (this);
12004 /* This breakpoint is special, it's set up when the inferior
12005 starts and we really don't want to touch it. */
12006 case bp_shlib_event
:
12008 /* Like bp_shlib_event, this breakpoint type is special. Once
12009 it is set up, we do not want to touch it. */
12010 case bp_thread_event
:
12016 internal_breakpoint::check_status (bpstat
*bs
)
12018 if (type
== bp_shlib_event
)
12020 /* If requested, stop when the dynamic linker notifies GDB of
12021 events. This allows the user to get control and place
12022 breakpoints in initializer routines for dynamically loaded
12023 objects (among other things). */
12024 bs
->stop
= stop_on_solib_events
;
12025 bs
->print
= stop_on_solib_events
;
12031 enum print_stop_action
12032 internal_breakpoint::print_it (bpstat
*bs
)
12036 case bp_shlib_event
:
12037 /* Did we stop because the user set the stop_on_solib_events
12038 variable? (If so, we report this as a generic, "Stopped due
12039 to shlib event" message.) */
12040 print_solib_event (false);
12043 case bp_thread_event
:
12044 /* Not sure how we will get here.
12045 GDB should not stop for these breakpoints. */
12046 gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
12049 case bp_overlay_event
:
12050 /* By analogy with the thread event, GDB should not stop for these. */
12051 gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12054 case bp_longjmp_master
:
12055 /* These should never be enabled. */
12056 gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12059 case bp_std_terminate_master
:
12060 /* These should never be enabled. */
12061 gdb_printf (_("std::terminate Master Breakpoint: "
12062 "gdb should not stop!\n"));
12065 case bp_exception_master
:
12066 /* These should never be enabled. */
12067 gdb_printf (_("Exception Master Breakpoint: "
12068 "gdb should not stop!\n"));
12072 return PRINT_NOTHING
;
12076 internal_breakpoint::print_mention ()
12078 /* Nothing to mention. These breakpoints are internal. */
12081 /* Virtual table for momentary breakpoints */
12084 momentary_breakpoint::re_set ()
12086 /* Keep temporary breakpoints, which can be encountered when we step
12087 over a dlopen call and solib_add is resetting the breakpoints.
12088 Otherwise these should have been blown away via the cleanup chain
12089 or by breakpoint_init_inferior when we rerun the executable. */
12093 momentary_breakpoint::check_status (bpstat
*bs
)
12095 /* Nothing. The point of these breakpoints is causing a stop. */
12098 enum print_stop_action
12099 momentary_breakpoint::print_it (bpstat
*bs
)
12101 return PRINT_UNKNOWN
;
12105 momentary_breakpoint::print_mention ()
12107 /* Nothing to mention. These breakpoints are internal. */
12110 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12112 It gets cleared already on the removal of the first one of such placed
12113 breakpoints. This is OK as they get all removed altogether. */
12115 longjmp_breakpoint::~longjmp_breakpoint ()
12117 thread_info
*tp
= find_thread_global_id (this->thread
);
12120 tp
->initiating_frame
= null_frame_id
;
12123 /* Specific methods for probe breakpoints. */
12126 bkpt_probe_insert_location (struct bp_location
*bl
)
12128 int v
= bl
->owner
->insert_location (bl
);
12132 /* The insertion was successful, now let's set the probe's semaphore
12134 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12141 bkpt_probe_remove_location (struct bp_location
*bl
,
12142 enum remove_bp_reason reason
)
12144 /* Let's clear the semaphore before removing the location. */
12145 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12147 return bl
->owner
->remove_location (bl
, reason
);
12151 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12152 struct linespec_result
*canonical
,
12153 enum bptype type_wanted
)
12155 struct linespec_sals lsal
;
12157 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12159 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12160 canonical
->lsals
.push_back (std::move (lsal
));
12163 static std::vector
<symtab_and_line
>
12164 bkpt_probe_decode_location (struct breakpoint
*b
,
12165 struct event_location
*location
,
12166 struct program_space
*search_pspace
)
12168 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12170 error (_("probe not found"));
12174 /* The breakpoint_ops structure to be used in tracepoints. */
12177 tracepoint::re_set ()
12179 breakpoint_re_set_default (this);
12183 tracepoint::breakpoint_hit (const struct bp_location
*bl
,
12184 const address_space
*aspace
, CORE_ADDR bp_addr
,
12185 const target_waitstatus
&ws
)
12187 /* By definition, the inferior does not report stops at
12193 tracepoint::print_one_detail (struct ui_out
*uiout
) const
12195 if (!static_trace_marker_id
.empty ())
12197 gdb_assert (type
== bp_static_tracepoint
);
12199 uiout
->message ("\tmarker id is %pF\n",
12200 string_field ("static-tracepoint-marker-string-id",
12201 static_trace_marker_id
.c_str ()));
12206 tracepoint::print_mention ()
12208 if (current_uiout
->is_mi_like_p ())
12213 case bp_tracepoint
:
12214 gdb_printf (_("Tracepoint"));
12215 gdb_printf (_(" %d"), number
);
12217 case bp_fast_tracepoint
:
12218 gdb_printf (_("Fast tracepoint"));
12219 gdb_printf (_(" %d"), number
);
12221 case bp_static_tracepoint
:
12222 gdb_printf (_("Static tracepoint"));
12223 gdb_printf (_(" %d"), number
);
12226 internal_error (__FILE__
, __LINE__
,
12227 _("unhandled tracepoint type %d"), (int) type
);
12234 tracepoint::print_recreate (struct ui_file
*fp
)
12236 if (type
== bp_fast_tracepoint
)
12237 gdb_printf (fp
, "ftrace");
12238 else if (type
== bp_static_tracepoint
)
12239 gdb_printf (fp
, "strace");
12240 else if (type
== bp_tracepoint
)
12241 gdb_printf (fp
, "trace");
12243 internal_error (__FILE__
, __LINE__
,
12244 _("unhandled tracepoint type %d"), (int) type
);
12246 gdb_printf (fp
, " %s", event_location_to_string (location
.get ()));
12247 print_recreate_thread (this, fp
);
12250 gdb_printf (fp
, " passcount %d\n", pass_count
);
12253 std::vector
<symtab_and_line
>
12254 tracepoint::decode_location (struct event_location
*location
,
12255 struct program_space
*search_pspace
)
12257 return decode_location_default (this, location
, search_pspace
);
12260 /* Virtual table for tracepoints on static probes. */
12263 tracepoint_probe_create_sals_from_location
12264 (struct event_location
*location
,
12265 struct linespec_result
*canonical
,
12266 enum bptype type_wanted
)
12268 /* We use the same method for breakpoint on probes. */
12269 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
12272 static std::vector
<symtab_and_line
>
12273 tracepoint_probe_decode_location (struct breakpoint
*b
,
12274 struct event_location
*location
,
12275 struct program_space
*search_pspace
)
12277 /* We use the same method for breakpoint on probes. */
12278 return bkpt_probe_decode_location (b
, location
, search_pspace
);
12281 /* Dprintf breakpoint_ops methods. */
12284 dprintf_re_set (struct breakpoint
*b
)
12286 breakpoint_re_set_default (b
);
12288 /* extra_string should never be non-NULL for dprintf. */
12289 gdb_assert (b
->extra_string
!= NULL
);
12291 /* 1 - connect to target 1, that can run breakpoint commands.
12292 2 - create a dprintf, which resolves fine.
12293 3 - disconnect from target 1
12294 4 - connect to target 2, that can NOT run breakpoint commands.
12296 After steps #3/#4, you'll want the dprintf command list to
12297 be updated, because target 1 and 2 may well return different
12298 answers for target_can_run_breakpoint_commands().
12299 Given absence of finer grained resetting, we get to do
12300 it all the time. */
12301 if (b
->extra_string
!= NULL
)
12302 update_dprintf_command_list (b
);
12305 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
12308 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12310 gdb_printf (fp
, "dprintf %s,%s",
12311 event_location_to_string (tp
->location
.get ()),
12312 tp
->extra_string
.get ());
12313 print_recreate_thread (tp
, fp
);
12316 /* Implement the "after_condition_true" breakpoint_ops method for
12319 dprintf's are implemented with regular commands in their command
12320 list, but we run the commands here instead of before presenting the
12321 stop to the user, as dprintf's don't actually cause a stop. This
12322 also makes it so that the commands of multiple dprintfs at the same
12323 address are all handled. */
12326 dprintf_after_condition_true (struct bpstat
*bs
)
12328 /* dprintf's never cause a stop. This wasn't set in the
12329 check_status hook instead because that would make the dprintf's
12330 condition not be evaluated. */
12333 /* Run the command list here. Take ownership of it instead of
12334 copying. We never want these commands to run later in
12335 bpstat_do_actions, if a breakpoint that causes a stop happens to
12336 be set at same address as this dprintf, or even if running the
12337 commands here throws. */
12338 counted_command_line cmds
= std::move (bs
->commands
);
12339 gdb_assert (cmds
!= nullptr);
12340 execute_control_commands (cmds
.get (), 0);
12343 /* The breakpoint_ops structure to be used on static tracepoints with
12347 strace_marker_create_sals_from_location (struct event_location
*location
,
12348 struct linespec_result
*canonical
,
12349 enum bptype type_wanted
)
12351 struct linespec_sals lsal
;
12352 const char *arg_start
, *arg
;
12354 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
12355 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12357 std::string
str (arg_start
, arg
- arg_start
);
12358 const char *ptr
= str
.c_str ();
12359 canonical
->location
12360 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
12363 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12364 canonical
->lsals
.push_back (std::move (lsal
));
12368 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12369 struct linespec_result
*canonical
,
12370 gdb::unique_xmalloc_ptr
<char> cond_string
,
12371 gdb::unique_xmalloc_ptr
<char> extra_string
,
12372 enum bptype type_wanted
,
12373 enum bpdisp disposition
,
12375 int task
, int ignore_count
,
12376 const struct breakpoint_ops
*ops
,
12377 int from_tty
, int enabled
,
12378 int internal
, unsigned flags
)
12380 const linespec_sals
&lsal
= canonical
->lsals
[0];
12382 /* If the user is creating a static tracepoint by marker id
12383 (strace -m MARKER_ID), then store the sals index, so that
12384 breakpoint_re_set can try to match up which of the newly
12385 found markers corresponds to this one, and, don't try to
12386 expand multiple locations for each sal, given than SALS
12387 already should contain all sals for MARKER_ID. */
12389 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12391 event_location_up location
12392 = copy_event_location (canonical
->location
.get ());
12394 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
12395 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
12396 std::move (location
), NULL
,
12397 std::move (cond_string
),
12398 std::move (extra_string
),
12399 type_wanted
, disposition
,
12400 thread
, task
, ignore_count
, ops
,
12401 from_tty
, enabled
, internal
, flags
,
12402 canonical
->special_display
);
12403 /* Given that its possible to have multiple markers with
12404 the same string id, if the user is creating a static
12405 tracepoint by marker id ("strace -m MARKER_ID"), then
12406 store the sals index, so that breakpoint_re_set can
12407 try to match up which of the newly found markers
12408 corresponds to this one */
12409 tp
->static_trace_marker_id_idx
= i
;
12411 install_breakpoint (internal
, std::move (tp
), 0);
12415 static std::vector
<symtab_and_line
>
12416 strace_marker_decode_location (struct breakpoint
*b
,
12417 struct event_location
*location
,
12418 struct program_space
*search_pspace
)
12420 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12421 const char *s
= get_linespec_location (location
)->spec_string
;
12423 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12424 if (sals
.size () > tp
->static_trace_marker_id_idx
)
12426 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
12431 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
12434 static struct breakpoint_ops strace_marker_breakpoint_ops
;
12437 strace_marker_p (struct breakpoint
*b
)
12439 return b
->ops
== &strace_marker_breakpoint_ops
;
12442 /* Delete a breakpoint and clean up all traces of it in the data
12446 delete_breakpoint (struct breakpoint
*bpt
)
12448 gdb_assert (bpt
!= NULL
);
12450 /* Has this bp already been deleted? This can happen because
12451 multiple lists can hold pointers to bp's. bpstat lists are
12454 One example of this happening is a watchpoint's scope bp. When
12455 the scope bp triggers, we notice that the watchpoint is out of
12456 scope, and delete it. We also delete its scope bp. But the
12457 scope bp is marked "auto-deleting", and is already on a bpstat.
12458 That bpstat is then checked for auto-deleting bp's, which are
12461 A real solution to this problem might involve reference counts in
12462 bp's, and/or giving them pointers back to their referencing
12463 bpstat's, and teaching delete_breakpoint to only free a bp's
12464 storage when no more references were extent. A cheaper bandaid
12466 if (bpt
->type
== bp_none
)
12469 /* At least avoid this stale reference until the reference counting
12470 of breakpoints gets resolved. */
12471 if (bpt
->related_breakpoint
!= bpt
)
12473 struct breakpoint
*related
;
12474 struct watchpoint
*w
;
12476 if (bpt
->type
== bp_watchpoint_scope
)
12477 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12478 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12479 w
= (struct watchpoint
*) bpt
;
12483 watchpoint_del_at_next_stop (w
);
12485 /* Unlink bpt from the bpt->related_breakpoint ring. */
12486 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12487 related
= related
->related_breakpoint
);
12488 related
->related_breakpoint
= bpt
->related_breakpoint
;
12489 bpt
->related_breakpoint
= bpt
;
12492 /* watch_command_1 creates a watchpoint but only sets its number if
12493 update_watchpoint succeeds in creating its bp_locations. If there's
12494 a problem in that process, we'll be asked to delete the half-created
12495 watchpoint. In that case, don't announce the deletion. */
12497 gdb::observers::breakpoint_deleted
.notify (bpt
);
12499 if (breakpoint_chain
== bpt
)
12500 breakpoint_chain
= bpt
->next
;
12502 for (breakpoint
*b
: all_breakpoints ())
12503 if (b
->next
== bpt
)
12505 b
->next
= bpt
->next
;
12509 /* Be sure no bpstat's are pointing at the breakpoint after it's
12511 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12512 in all threads for now. Note that we cannot just remove bpstats
12513 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12514 commands are associated with the bpstat; if we remove it here,
12515 then the later call to bpstat_do_actions (&stop_bpstat); in
12516 event-top.c won't do anything, and temporary breakpoints with
12517 commands won't work. */
12519 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12521 /* Now that breakpoint is removed from breakpoint list, update the
12522 global location list. This will remove locations that used to
12523 belong to this breakpoint. Do this before freeing the breakpoint
12524 itself, since remove_breakpoint looks at location's owner. It
12525 might be better design to have location completely
12526 self-contained, but it's not the case now. */
12527 update_global_location_list (UGLL_DONT_INSERT
);
12529 /* On the chance that someone will soon try again to delete this
12530 same bp, we mark it as deleted before freeing its storage. */
12531 bpt
->type
= bp_none
;
12535 /* Iterator function to call a user-provided callback function once
12536 for each of B and its related breakpoints. */
12539 iterate_over_related_breakpoints (struct breakpoint
*b
,
12540 gdb::function_view
<void (breakpoint
*)> function
)
12542 struct breakpoint
*related
;
12547 struct breakpoint
*next
;
12549 /* FUNCTION may delete RELATED. */
12550 next
= related
->related_breakpoint
;
12552 if (next
== related
)
12554 /* RELATED is the last ring entry. */
12555 function (related
);
12557 /* FUNCTION may have deleted it, so we'd never reach back to
12558 B. There's nothing left to do anyway, so just break
12563 function (related
);
12567 while (related
!= b
);
12571 delete_command (const char *arg
, int from_tty
)
12577 int breaks_to_delete
= 0;
12579 /* Delete all breakpoints if no argument. Do not delete
12580 internal breakpoints, these have to be deleted with an
12581 explicit breakpoint number argument. */
12582 for (breakpoint
*b
: all_breakpoints ())
12583 if (user_breakpoint_p (b
))
12585 breaks_to_delete
= 1;
12589 /* Ask user only if there are some breakpoints to delete. */
12591 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
12592 for (breakpoint
*b
: all_breakpoints_safe ())
12593 if (user_breakpoint_p (b
))
12594 delete_breakpoint (b
);
12597 map_breakpoint_numbers
12598 (arg
, [&] (breakpoint
*br
)
12600 iterate_over_related_breakpoints (br
, delete_breakpoint
);
12604 /* Return true if all locations of B bound to PSPACE are pending. If
12605 PSPACE is NULL, all locations of all program spaces are
12609 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
12611 for (bp_location
*loc
: b
->locations ())
12612 if ((pspace
== NULL
12613 || loc
->pspace
== pspace
)
12614 && !loc
->shlib_disabled
12615 && !loc
->pspace
->executing_startup
)
12620 /* Subroutine of update_breakpoint_locations to simplify it.
12621 Return non-zero if multiple fns in list LOC have the same name.
12622 Null names are ignored. */
12625 ambiguous_names_p (struct bp_location
*loc
)
12627 struct bp_location
*l
;
12628 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
12631 for (l
= loc
; l
!= NULL
; l
= l
->next
)
12634 const char *name
= l
->function_name
.get ();
12636 /* Allow for some names to be NULL, ignore them. */
12640 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
12642 /* NOTE: We can assume slot != NULL here because xcalloc never
12652 /* When symbols change, it probably means the sources changed as well,
12653 and it might mean the static tracepoint markers are no longer at
12654 the same address or line numbers they used to be at last we
12655 checked. Losing your static tracepoints whenever you rebuild is
12656 undesirable. This function tries to resync/rematch gdb static
12657 tracepoints with the markers on the target, for static tracepoints
12658 that have not been set by marker id. Static tracepoint that have
12659 been set by marker id are reset by marker id in breakpoint_re_set.
12662 1) For a tracepoint set at a specific address, look for a marker at
12663 the old PC. If one is found there, assume to be the same marker.
12664 If the name / string id of the marker found is different from the
12665 previous known name, assume that means the user renamed the marker
12666 in the sources, and output a warning.
12668 2) For a tracepoint set at a given line number, look for a marker
12669 at the new address of the old line number. If one is found there,
12670 assume to be the same marker. If the name / string id of the
12671 marker found is different from the previous known name, assume that
12672 means the user renamed the marker in the sources, and output a
12675 3) If a marker is no longer found at the same address or line, it
12676 may mean the marker no longer exists. But it may also just mean
12677 the code changed a bit. Maybe the user added a few lines of code
12678 that made the marker move up or down (in line number terms). Ask
12679 the target for info about the marker with the string id as we knew
12680 it. If found, update line number and address in the matching
12681 static tracepoint. This will get confused if there's more than one
12682 marker with the same ID (possible in UST, although unadvised
12683 precisely because it confuses tools). */
12685 static struct symtab_and_line
12686 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
12688 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12689 struct static_tracepoint_marker marker
;
12694 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12696 if (target_static_tracepoint_marker_at (pc
, &marker
))
12698 if (tp
->static_trace_marker_id
!= marker
.str_id
)
12699 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12700 b
->number
, tp
->static_trace_marker_id
.c_str (),
12701 marker
.str_id
.c_str ());
12703 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
12708 /* Old marker wasn't found on target at lineno. Try looking it up
12710 if (!sal
.explicit_pc
12712 && sal
.symtab
!= NULL
12713 && !tp
->static_trace_marker_id
.empty ())
12715 std::vector
<static_tracepoint_marker
> markers
12716 = target_static_tracepoint_markers_by_strid
12717 (tp
->static_trace_marker_id
.c_str ());
12719 if (!markers
.empty ())
12721 struct symbol
*sym
;
12722 struct static_tracepoint_marker
*tpmarker
;
12723 struct ui_out
*uiout
= current_uiout
;
12724 struct explicit_location explicit_loc
;
12726 tpmarker
= &markers
[0];
12728 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
12730 warning (_("marker for static tracepoint %d (%s) not "
12731 "found at previous line number"),
12732 b
->number
, tp
->static_trace_marker_id
.c_str ());
12734 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
12735 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
12736 uiout
->text ("Now in ");
12739 uiout
->field_string ("func", sym
->print_name (),
12740 function_name_style
.style ());
12741 uiout
->text (" at ");
12743 uiout
->field_string ("file",
12744 symtab_to_filename_for_display (sal2
.symtab
),
12745 file_name_style
.style ());
12748 if (uiout
->is_mi_like_p ())
12750 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
12752 uiout
->field_string ("fullname", fullname
);
12755 uiout
->field_signed ("line", sal2
.line
);
12756 uiout
->text ("\n");
12758 b
->loc
->line_number
= sal2
.line
;
12759 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
12761 b
->location
.reset (NULL
);
12762 initialize_explicit_location (&explicit_loc
);
12763 explicit_loc
.source_filename
12764 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
12765 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
12766 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
12767 b
->location
= new_explicit_location (&explicit_loc
);
12769 /* Might be nice to check if function changed, and warn if
12776 /* Returns 1 iff locations A and B are sufficiently same that
12777 we don't need to report breakpoint as changed. */
12780 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
12784 if (a
->address
!= b
->address
)
12787 if (a
->shlib_disabled
!= b
->shlib_disabled
)
12790 if (a
->enabled
!= b
->enabled
)
12793 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
12800 if ((a
== NULL
) != (b
== NULL
))
12806 /* Split all locations of B that are bound to PSPACE out of B's
12807 location list to a separate list and return that list's head. If
12808 PSPACE is NULL, hoist out all locations of B. */
12810 static struct bp_location
*
12811 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
12813 struct bp_location head
;
12814 struct bp_location
*i
= b
->loc
;
12815 struct bp_location
**i_link
= &b
->loc
;
12816 struct bp_location
*hoisted
= &head
;
12818 if (pspace
== NULL
)
12829 if (i
->pspace
== pspace
)
12844 /* Create new breakpoint locations for B (a hardware or software
12845 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
12846 zero, then B is a ranged breakpoint. Only recreates locations for
12847 FILTER_PSPACE. Locations of other program spaces are left
12851 update_breakpoint_locations (struct breakpoint
*b
,
12852 struct program_space
*filter_pspace
,
12853 gdb::array_view
<const symtab_and_line
> sals
,
12854 gdb::array_view
<const symtab_and_line
> sals_end
)
12856 struct bp_location
*existing_locations
;
12858 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
12860 /* Ranged breakpoints have only one start location and one end
12862 b
->enable_state
= bp_disabled
;
12863 gdb_printf (gdb_stderr
,
12864 _("Could not reset ranged breakpoint %d: "
12865 "multiple locations found\n"),
12870 /* If there's no new locations, and all existing locations are
12871 pending, don't do anything. This optimizes the common case where
12872 all locations are in the same shared library, that was unloaded.
12873 We'd like to retain the location, so that when the library is
12874 loaded again, we don't loose the enabled/disabled status of the
12875 individual locations. */
12876 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
12879 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
12881 for (const auto &sal
: sals
)
12883 struct bp_location
*new_loc
;
12885 switch_to_program_space_and_thread (sal
.pspace
);
12887 new_loc
= add_location_to_breakpoint (b
, &sal
);
12889 /* Reparse conditions, they might contain references to the
12891 if (b
->cond_string
!= NULL
)
12895 s
= b
->cond_string
.get ();
12898 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
12899 block_for_pc (sal
.pc
),
12902 catch (const gdb_exception_error
&e
)
12904 new_loc
->disabled_by_cond
= true;
12908 if (!sals_end
.empty ())
12910 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
12912 new_loc
->length
= end
- sals
[0].pc
+ 1;
12916 /* If possible, carry over 'disable' status from existing
12919 struct bp_location
*e
= existing_locations
;
12920 /* If there are multiple breakpoints with the same function name,
12921 e.g. for inline functions, comparing function names won't work.
12922 Instead compare pc addresses; this is just a heuristic as things
12923 may have moved, but in practice it gives the correct answer
12924 often enough until a better solution is found. */
12925 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
12927 for (; e
; e
= e
->next
)
12929 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
12931 if (have_ambiguous_names
)
12933 for (bp_location
*l
: b
->locations ())
12935 /* Ignore software vs hardware location type at
12936 this point, because with "set breakpoint
12937 auto-hw", after a re-set, locations that were
12938 hardware can end up as software, or vice versa.
12939 As mentioned above, this is an heuristic and in
12940 practice should give the correct answer often
12942 if (breakpoint_locations_match (e
, l
, true))
12944 l
->enabled
= e
->enabled
;
12945 l
->disabled_by_cond
= e
->disabled_by_cond
;
12952 for (bp_location
*l
: b
->locations ())
12953 if (l
->function_name
12954 && strcmp (e
->function_name
.get (),
12955 l
->function_name
.get ()) == 0)
12957 l
->enabled
= e
->enabled
;
12958 l
->disabled_by_cond
= e
->disabled_by_cond
;
12966 if (!locations_are_equal (existing_locations
, b
->loc
))
12967 gdb::observers::breakpoint_modified
.notify (b
);
12970 /* Find the SaL locations corresponding to the given LOCATION.
12971 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
12973 static std::vector
<symtab_and_line
>
12974 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
12975 struct program_space
*search_pspace
, int *found
)
12977 struct gdb_exception exception
;
12979 gdb_assert (b
->ops
!= NULL
);
12981 std::vector
<symtab_and_line
> sals
;
12985 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
12987 catch (gdb_exception_error
&e
)
12989 int not_found_and_ok
= 0;
12991 /* For pending breakpoints, it's expected that parsing will
12992 fail until the right shared library is loaded. User has
12993 already told to create pending breakpoints and don't need
12994 extra messages. If breakpoint is in bp_shlib_disabled
12995 state, then user already saw the message about that
12996 breakpoint being disabled, and don't want to see more
12998 if (e
.error
== NOT_FOUND_ERROR
12999 && (b
->condition_not_parsed
13001 && search_pspace
!= NULL
13002 && b
->loc
->pspace
!= search_pspace
)
13003 || (b
->loc
&& b
->loc
->shlib_disabled
)
13004 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13005 || b
->enable_state
== bp_disabled
))
13006 not_found_and_ok
= 1;
13008 if (!not_found_and_ok
)
13010 /* We surely don't want to warn about the same breakpoint
13011 10 times. One solution, implemented here, is disable
13012 the breakpoint on error. Another solution would be to
13013 have separate 'warning emitted' flag. Since this
13014 happens only when a binary has changed, I don't know
13015 which approach is better. */
13016 b
->enable_state
= bp_disabled
;
13020 exception
= std::move (e
);
13023 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13025 for (auto &sal
: sals
)
13026 resolve_sal_pc (&sal
);
13027 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13029 gdb::unique_xmalloc_ptr
<char> cond_string
, extra_string
;
13032 find_condition_and_thread_for_sals (sals
, b
->extra_string
.get (),
13033 &cond_string
, &thread
,
13034 &task
, &extra_string
);
13035 gdb_assert (b
->cond_string
== NULL
);
13037 b
->cond_string
= std::move (cond_string
);
13038 b
->thread
= thread
;
13041 b
->extra_string
= std::move (extra_string
);
13042 b
->condition_not_parsed
= 0;
13045 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13046 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13056 /* The default re_set method, for typical hardware or software
13057 breakpoints. Reevaluate the breakpoint and recreate its
13061 breakpoint_re_set_default (struct breakpoint
*b
)
13063 struct program_space
*filter_pspace
= current_program_space
;
13064 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13067 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13068 filter_pspace
, &found
);
13070 expanded
= std::move (sals
);
13072 if (b
->location_range_end
!= NULL
)
13074 std::vector
<symtab_and_line
> sals_end
13075 = location_to_sals (b
, b
->location_range_end
.get (),
13076 filter_pspace
, &found
);
13078 expanded_end
= std::move (sals_end
);
13081 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13084 /* Default method for creating SALs from an address string. It basically
13085 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13088 create_sals_from_location_default (struct event_location
*location
,
13089 struct linespec_result
*canonical
,
13090 enum bptype type_wanted
)
13092 parse_breakpoint_sals (location
, canonical
);
13095 /* Call create_breakpoints_sal for the given arguments. This is the default
13096 function for the `create_breakpoints_sal' method of
13100 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13101 struct linespec_result
*canonical
,
13102 gdb::unique_xmalloc_ptr
<char> cond_string
,
13103 gdb::unique_xmalloc_ptr
<char> extra_string
,
13104 enum bptype type_wanted
,
13105 enum bpdisp disposition
,
13107 int task
, int ignore_count
,
13108 const struct breakpoint_ops
*ops
,
13109 int from_tty
, int enabled
,
13110 int internal
, unsigned flags
)
13112 create_breakpoints_sal (gdbarch
, canonical
,
13113 std::move (cond_string
),
13114 std::move (extra_string
),
13115 type_wanted
, disposition
,
13116 thread
, task
, ignore_count
, ops
, from_tty
,
13117 enabled
, internal
, flags
);
13120 /* Decode the line represented by S by calling decode_line_full. This is the
13121 default function for the `decode_location' method of breakpoint_ops. */
13123 static std::vector
<symtab_and_line
>
13124 decode_location_default (struct breakpoint
*b
,
13125 struct event_location
*location
,
13126 struct program_space
*search_pspace
)
13128 struct linespec_result canonical
;
13130 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13131 NULL
, 0, &canonical
, multiple_symbols_all
,
13134 /* We should get 0 or 1 resulting SALs. */
13135 gdb_assert (canonical
.lsals
.size () < 2);
13137 if (!canonical
.lsals
.empty ())
13139 const linespec_sals
&lsal
= canonical
.lsals
[0];
13140 return std::move (lsal
.sals
);
13145 /* Reset a breakpoint. */
13148 breakpoint_re_set_one (breakpoint
*b
)
13150 input_radix
= b
->input_radix
;
13151 set_language (b
->language
);
13153 b
->ops
->re_set (b
);
13156 /* Re-set breakpoint locations for the current program space.
13157 Locations bound to other program spaces are left untouched. */
13160 breakpoint_re_set (void)
13163 scoped_restore_current_language save_language
;
13164 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13165 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13167 /* breakpoint_re_set_one sets the current_language to the language
13168 of the breakpoint it is resetting (see prepare_re_set_context)
13169 before re-evaluating the breakpoint's location. This change can
13170 unfortunately get undone by accident if the language_mode is set
13171 to auto, and we either switch frames, or more likely in this context,
13172 we select the current frame.
13174 We prevent this by temporarily turning the language_mode to
13175 language_mode_manual. We restore it once all breakpoints
13176 have been reset. */
13177 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13178 language_mode
= language_mode_manual
;
13180 /* Note: we must not try to insert locations until after all
13181 breakpoints have been re-set. Otherwise, e.g., when re-setting
13182 breakpoint 1, we'd insert the locations of breakpoint 2, which
13183 hadn't been re-set yet, and thus may have stale locations. */
13185 for (breakpoint
*b
: all_breakpoints_safe ())
13189 breakpoint_re_set_one (b
);
13191 catch (const gdb_exception
&ex
)
13193 exception_fprintf (gdb_stderr
, ex
,
13194 "Error in re-setting breakpoint %d: ",
13199 jit_breakpoint_re_set ();
13202 create_overlay_event_breakpoint ();
13203 create_longjmp_master_breakpoint ();
13204 create_std_terminate_master_breakpoint ();
13205 create_exception_master_breakpoint ();
13207 /* Now we can insert. */
13208 update_global_location_list (UGLL_MAY_INSERT
);
13211 /* Reset the thread number of this breakpoint:
13213 - If the breakpoint is for all threads, leave it as-is.
13214 - Else, reset it to the current thread for inferior_ptid. */
13216 breakpoint_re_set_thread (struct breakpoint
*b
)
13218 if (b
->thread
!= -1)
13220 b
->thread
= inferior_thread ()->global_num
;
13222 /* We're being called after following a fork. The new fork is
13223 selected as current, and unless this was a vfork will have a
13224 different program space from the original thread. Reset that
13226 b
->loc
->pspace
= current_program_space
;
13230 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13231 If from_tty is nonzero, it prints a message to that effect,
13232 which ends with a period (no newline). */
13235 set_ignore_count (int bptnum
, int count
, int from_tty
)
13240 for (breakpoint
*b
: all_breakpoints ())
13241 if (b
->number
== bptnum
)
13243 if (is_tracepoint (b
))
13245 if (from_tty
&& count
!= 0)
13246 gdb_printf (_("Ignore count ignored for tracepoint %d."),
13251 b
->ignore_count
= count
;
13255 gdb_printf (_("Will stop next time "
13256 "breakpoint %d is reached."),
13258 else if (count
== 1)
13259 gdb_printf (_("Will ignore next crossing of breakpoint %d."),
13262 gdb_printf (_("Will ignore next %d "
13263 "crossings of breakpoint %d."),
13266 gdb::observers::breakpoint_modified
.notify (b
);
13270 error (_("No breakpoint number %d."), bptnum
);
13273 /* Command to set ignore-count of breakpoint N to COUNT. */
13276 ignore_command (const char *args
, int from_tty
)
13278 const char *p
= args
;
13282 error_no_arg (_("a breakpoint number"));
13284 num
= get_number (&p
);
13286 error (_("bad breakpoint number: '%s'"), args
);
13288 error (_("Second argument (specified ignore-count) is missing."));
13290 set_ignore_count (num
,
13291 longest_to_int (value_as_long (parse_and_eval (p
))),
13298 /* Call FUNCTION on each of the breakpoints with numbers in the range
13299 defined by BP_NUM_RANGE (an inclusive range). */
13302 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13303 gdb::function_view
<void (breakpoint
*)> function
)
13305 if (bp_num_range
.first
== 0)
13307 warning (_("bad breakpoint number at or near '%d'"),
13308 bp_num_range
.first
);
13312 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13314 bool match
= false;
13316 for (breakpoint
*b
: all_breakpoints_safe ())
13317 if (b
->number
== i
)
13324 gdb_printf (_("No breakpoint number %d.\n"), i
);
13329 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13333 map_breakpoint_numbers (const char *args
,
13334 gdb::function_view
<void (breakpoint
*)> function
)
13336 if (args
== NULL
|| *args
== '\0')
13337 error_no_arg (_("one or more breakpoint numbers"));
13339 number_or_range_parser
parser (args
);
13341 while (!parser
.finished ())
13343 int num
= parser
.get_number ();
13344 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13348 /* Return the breakpoint location structure corresponding to the
13349 BP_NUM and LOC_NUM values. */
13351 static struct bp_location
*
13352 find_location_by_number (int bp_num
, int loc_num
)
13354 breakpoint
*b
= get_breakpoint (bp_num
);
13356 if (!b
|| b
->number
!= bp_num
)
13357 error (_("Bad breakpoint number '%d'"), bp_num
);
13360 error (_("Bad breakpoint location number '%d'"), loc_num
);
13363 for (bp_location
*loc
: b
->locations ())
13364 if (++n
== loc_num
)
13367 error (_("Bad breakpoint location number '%d'"), loc_num
);
13370 /* Modes of operation for extract_bp_num. */
13371 enum class extract_bp_kind
13373 /* Extracting a breakpoint number. */
13376 /* Extracting a location number. */
13380 /* Extract a breakpoint or location number (as determined by KIND)
13381 from the string starting at START. TRAILER is a character which
13382 can be found after the number. If you don't want a trailer, use
13383 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13384 string. This always returns a positive integer. */
13387 extract_bp_num (extract_bp_kind kind
, const char *start
,
13388 int trailer
, const char **end_out
= NULL
)
13390 const char *end
= start
;
13391 int num
= get_number_trailer (&end
, trailer
);
13393 error (kind
== extract_bp_kind::bp
13394 ? _("Negative breakpoint number '%.*s'")
13395 : _("Negative breakpoint location number '%.*s'"),
13396 int (end
- start
), start
);
13398 error (kind
== extract_bp_kind::bp
13399 ? _("Bad breakpoint number '%.*s'")
13400 : _("Bad breakpoint location number '%.*s'"),
13401 int (end
- start
), start
);
13403 if (end_out
!= NULL
)
13408 /* Extract a breakpoint or location range (as determined by KIND) in
13409 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13410 representing the (inclusive) range. The returned pair's elements
13411 are always positive integers. */
13413 static std::pair
<int, int>
13414 extract_bp_or_bp_range (extract_bp_kind kind
,
13415 const std::string
&arg
,
13416 std::string::size_type arg_offset
)
13418 std::pair
<int, int> range
;
13419 const char *bp_loc
= &arg
[arg_offset
];
13420 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13421 if (dash
!= std::string::npos
)
13423 /* bp_loc is a range (x-z). */
13424 if (arg
.length () == dash
+ 1)
13425 error (kind
== extract_bp_kind::bp
13426 ? _("Bad breakpoint number at or near: '%s'")
13427 : _("Bad breakpoint location number at or near: '%s'"),
13431 const char *start_first
= bp_loc
;
13432 const char *start_second
= &arg
[dash
+ 1];
13433 range
.first
= extract_bp_num (kind
, start_first
, '-');
13434 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
13436 if (range
.first
> range
.second
)
13437 error (kind
== extract_bp_kind::bp
13438 ? _("Inverted breakpoint range at '%.*s'")
13439 : _("Inverted breakpoint location range at '%.*s'"),
13440 int (end
- start_first
), start_first
);
13444 /* bp_loc is a single value. */
13445 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
13446 range
.second
= range
.first
;
13451 /* Extract the breakpoint/location range specified by ARG. Returns
13452 the breakpoint range in BP_NUM_RANGE, and the location range in
13455 ARG may be in any of the following forms:
13457 x where 'x' is a breakpoint number.
13458 x-y where 'x' and 'y' specify a breakpoint numbers range.
13459 x.y where 'x' is a breakpoint number and 'y' a location number.
13460 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
13461 location number range.
13465 extract_bp_number_and_location (const std::string
&arg
,
13466 std::pair
<int, int> &bp_num_range
,
13467 std::pair
<int, int> &bp_loc_range
)
13469 std::string::size_type dot
= arg
.find ('.');
13471 if (dot
!= std::string::npos
)
13473 /* Handle 'x.y' and 'x.y-z' cases. */
13475 if (arg
.length () == dot
+ 1 || dot
== 0)
13476 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
13479 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
13480 bp_num_range
.second
= bp_num_range
.first
;
13482 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
13487 /* Handle x and x-y cases. */
13489 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
13490 bp_loc_range
.first
= 0;
13491 bp_loc_range
.second
= 0;
13495 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
13496 specifies whether to enable or disable. */
13499 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
13501 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
13504 if (loc
->disabled_by_cond
&& enable
)
13505 error (_("Breakpoint %d's condition is invalid at location %d, "
13506 "cannot enable."), bp_num
, loc_num
);
13508 if (loc
->enabled
!= enable
)
13510 loc
->enabled
= enable
;
13511 mark_breakpoint_location_modified (loc
);
13513 if (target_supports_enable_disable_tracepoint ()
13514 && current_trace_status ()->running
&& loc
->owner
13515 && is_tracepoint (loc
->owner
))
13516 target_disable_tracepoint (loc
);
13518 update_global_location_list (UGLL_DONT_INSERT
);
13520 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13523 /* Enable or disable a range of breakpoint locations. BP_NUM is the
13524 number of the breakpoint, and BP_LOC_RANGE specifies the
13525 (inclusive) range of location numbers of that breakpoint to
13526 enable/disable. ENABLE specifies whether to enable or disable the
13530 enable_disable_breakpoint_location_range (int bp_num
,
13531 std::pair
<int, int> &bp_loc_range
,
13534 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
13535 enable_disable_bp_num_loc (bp_num
, i
, enable
);
13538 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13539 If from_tty is nonzero, it prints a message to that effect,
13540 which ends with a period (no newline). */
13543 disable_breakpoint (struct breakpoint
*bpt
)
13545 /* Never disable a watchpoint scope breakpoint; we want to
13546 hit them when we leave scope so we can delete both the
13547 watchpoint and its scope breakpoint at that time. */
13548 if (bpt
->type
== bp_watchpoint_scope
)
13551 bpt
->enable_state
= bp_disabled
;
13553 /* Mark breakpoint locations modified. */
13554 mark_breakpoint_modified (bpt
);
13556 if (target_supports_enable_disable_tracepoint ()
13557 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13559 for (bp_location
*location
: bpt
->locations ())
13560 target_disable_tracepoint (location
);
13563 update_global_location_list (UGLL_DONT_INSERT
);
13565 gdb::observers::breakpoint_modified
.notify (bpt
);
13568 /* Enable or disable the breakpoint(s) or breakpoint location(s)
13569 specified in ARGS. ARGS may be in any of the formats handled by
13570 extract_bp_number_and_location. ENABLE specifies whether to enable
13571 or disable the breakpoints/locations. */
13574 enable_disable_command (const char *args
, int from_tty
, bool enable
)
13578 for (breakpoint
*bpt
: all_breakpoints ())
13579 if (user_breakpoint_p (bpt
))
13582 enable_breakpoint (bpt
);
13584 disable_breakpoint (bpt
);
13589 std::string num
= extract_arg (&args
);
13591 while (!num
.empty ())
13593 std::pair
<int, int> bp_num_range
, bp_loc_range
;
13595 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
13597 if (bp_loc_range
.first
== bp_loc_range
.second
13598 && bp_loc_range
.first
== 0)
13600 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
13601 map_breakpoint_number_range (bp_num_range
,
13603 ? enable_breakpoint
13604 : disable_breakpoint
);
13608 /* Handle breakpoint ids with formats 'x.y' or
13610 enable_disable_breakpoint_location_range
13611 (bp_num_range
.first
, bp_loc_range
, enable
);
13613 num
= extract_arg (&args
);
13618 /* The disable command disables the specified breakpoints/locations
13619 (or all defined breakpoints) so they're no longer effective in
13620 stopping the inferior. ARGS may be in any of the forms defined in
13621 extract_bp_number_and_location. */
13624 disable_command (const char *args
, int from_tty
)
13626 enable_disable_command (args
, from_tty
, false);
13630 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13633 int target_resources_ok
;
13635 if (bpt
->type
== bp_hardware_breakpoint
)
13638 i
= hw_breakpoint_used_count ();
13639 target_resources_ok
=
13640 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13642 if (target_resources_ok
== 0)
13643 error (_("No hardware breakpoint support in the target."));
13644 else if (target_resources_ok
< 0)
13645 error (_("Hardware breakpoints used exceeds limit."));
13648 if (is_watchpoint (bpt
))
13650 /* Initialize it just to avoid a GCC false warning. */
13651 enum enable_state orig_enable_state
= bp_disabled
;
13655 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13657 orig_enable_state
= bpt
->enable_state
;
13658 bpt
->enable_state
= bp_enabled
;
13659 update_watchpoint (w
, 1 /* reparse */);
13661 catch (const gdb_exception
&e
)
13663 bpt
->enable_state
= orig_enable_state
;
13664 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13670 bpt
->enable_state
= bp_enabled
;
13672 /* Mark breakpoint locations modified. */
13673 mark_breakpoint_modified (bpt
);
13675 if (target_supports_enable_disable_tracepoint ()
13676 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13678 for (bp_location
*location
: bpt
->locations ())
13679 target_enable_tracepoint (location
);
13682 bpt
->disposition
= disposition
;
13683 bpt
->enable_count
= count
;
13684 update_global_location_list (UGLL_MAY_INSERT
);
13686 gdb::observers::breakpoint_modified
.notify (bpt
);
13691 enable_breakpoint (struct breakpoint
*bpt
)
13693 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13696 /* The enable command enables the specified breakpoints/locations (or
13697 all defined breakpoints) so they once again become (or continue to
13698 be) effective in stopping the inferior. ARGS may be in any of the
13699 forms defined in extract_bp_number_and_location. */
13702 enable_command (const char *args
, int from_tty
)
13704 enable_disable_command (args
, from_tty
, true);
13708 enable_once_command (const char *args
, int from_tty
)
13710 map_breakpoint_numbers
13711 (args
, [&] (breakpoint
*b
)
13713 iterate_over_related_breakpoints
13714 (b
, [&] (breakpoint
*bpt
)
13716 enable_breakpoint_disp (bpt
, disp_disable
, 1);
13722 enable_count_command (const char *args
, int from_tty
)
13727 error_no_arg (_("hit count"));
13729 count
= get_number (&args
);
13731 map_breakpoint_numbers
13732 (args
, [&] (breakpoint
*b
)
13734 iterate_over_related_breakpoints
13735 (b
, [&] (breakpoint
*bpt
)
13737 enable_breakpoint_disp (bpt
, disp_disable
, count
);
13743 enable_delete_command (const char *args
, int from_tty
)
13745 map_breakpoint_numbers
13746 (args
, [&] (breakpoint
*b
)
13748 iterate_over_related_breakpoints
13749 (b
, [&] (breakpoint
*bpt
)
13751 enable_breakpoint_disp (bpt
, disp_del
, 1);
13756 /* Invalidate last known value of any hardware watchpoint if
13757 the memory which that value represents has been written to by
13761 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
13762 CORE_ADDR addr
, ssize_t len
,
13763 const bfd_byte
*data
)
13765 for (breakpoint
*bp
: all_breakpoints ())
13766 if (bp
->enable_state
== bp_enabled
13767 && bp
->type
== bp_hardware_watchpoint
)
13769 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
13771 if (wp
->val_valid
&& wp
->val
!= nullptr)
13773 for (bp_location
*loc
: bp
->locations ())
13774 if (loc
->loc_type
== bp_loc_hardware_watchpoint
13775 && loc
->address
+ loc
->length
> addr
13776 && addr
+ len
> loc
->address
)
13779 wp
->val_valid
= false;
13785 /* Create and insert a breakpoint for software single step. */
13788 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
13789 const address_space
*aspace
,
13792 struct thread_info
*tp
= inferior_thread ();
13793 struct symtab_and_line sal
;
13794 CORE_ADDR pc
= next_pc
;
13796 if (tp
->control
.single_step_breakpoints
== NULL
)
13798 tp
->control
.single_step_breakpoints
13799 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
13802 sal
= find_pc_line (pc
, 0);
13804 sal
.section
= find_pc_overlay (pc
);
13805 sal
.explicit_pc
= 1;
13806 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
13808 update_global_location_list (UGLL_INSERT
);
13811 /* Insert single step breakpoints according to the current state. */
13814 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
13816 struct regcache
*regcache
= get_current_regcache ();
13817 std::vector
<CORE_ADDR
> next_pcs
;
13819 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
13821 if (!next_pcs
.empty ())
13823 struct frame_info
*frame
= get_current_frame ();
13824 const address_space
*aspace
= get_frame_address_space (frame
);
13826 for (CORE_ADDR pc
: next_pcs
)
13827 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
13835 /* See breakpoint.h. */
13838 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
13839 const address_space
*aspace
,
13842 for (bp_location
*loc
: bp
->locations ())
13844 && breakpoint_location_address_match (loc
, aspace
, pc
))
13850 /* Check whether a software single-step breakpoint is inserted at
13854 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
13857 for (breakpoint
*bpt
: all_breakpoints ())
13859 if (bpt
->type
== bp_single_step
13860 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
13866 /* Tracepoint-specific operations. */
13868 /* Set tracepoint count to NUM. */
13870 set_tracepoint_count (int num
)
13872 tracepoint_count
= num
;
13873 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
13877 trace_command (const char *arg
, int from_tty
)
13879 event_location_up location
= string_to_event_location (&arg
,
13881 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
13882 (location
.get (), true /* is_tracepoint */);
13884 create_breakpoint (get_current_arch (),
13886 NULL
, 0, arg
, false, 1 /* parse arg */,
13888 bp_tracepoint
/* type_wanted */,
13889 0 /* Ignore count */,
13890 pending_break_support
,
13894 0 /* internal */, 0);
13898 ftrace_command (const char *arg
, int from_tty
)
13900 event_location_up location
= string_to_event_location (&arg
,
13902 create_breakpoint (get_current_arch (),
13904 NULL
, 0, arg
, false, 1 /* parse arg */,
13906 bp_fast_tracepoint
/* type_wanted */,
13907 0 /* Ignore count */,
13908 pending_break_support
,
13909 &vtable_breakpoint_ops
,
13912 0 /* internal */, 0);
13915 /* strace command implementation. Creates a static tracepoint. */
13918 strace_command (const char *arg
, int from_tty
)
13920 struct breakpoint_ops
*ops
;
13921 event_location_up location
;
13923 /* Decide if we are dealing with a static tracepoint marker (`-m'),
13924 or with a normal static tracepoint. */
13925 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
13927 ops
= &strace_marker_breakpoint_ops
;
13928 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
13932 ops
= &vtable_breakpoint_ops
;
13933 location
= string_to_event_location (&arg
, current_language
);
13936 create_breakpoint (get_current_arch (),
13938 NULL
, 0, arg
, false, 1 /* parse arg */,
13940 bp_static_tracepoint
/* type_wanted */,
13941 0 /* Ignore count */,
13942 pending_break_support
,
13946 0 /* internal */, 0);
13949 /* Set up a fake reader function that gets command lines from a linked
13950 list that was acquired during tracepoint uploading. */
13952 static struct uploaded_tp
*this_utp
;
13953 static int next_cmd
;
13956 read_uploaded_action (void)
13958 char *rslt
= nullptr;
13960 if (next_cmd
< this_utp
->cmd_strings
.size ())
13962 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
13969 /* Given information about a tracepoint as recorded on a target (which
13970 can be either a live system or a trace file), attempt to create an
13971 equivalent GDB tracepoint. This is not a reliable process, since
13972 the target does not necessarily have all the information used when
13973 the tracepoint was originally defined. */
13975 struct tracepoint
*
13976 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
13978 const char *addr_str
;
13979 char small_buf
[100];
13980 struct tracepoint
*tp
;
13982 if (utp
->at_string
)
13983 addr_str
= utp
->at_string
.get ();
13986 /* In the absence of a source location, fall back to raw
13987 address. Since there is no way to confirm that the address
13988 means the same thing as when the trace was started, warn the
13990 warning (_("Uploaded tracepoint %d has no "
13991 "source location, using raw address"),
13993 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
13994 addr_str
= small_buf
;
13997 /* There's not much we can do with a sequence of bytecodes. */
13998 if (utp
->cond
&& !utp
->cond_string
)
13999 warning (_("Uploaded tracepoint %d condition "
14000 "has no source form, ignoring it"),
14003 event_location_up location
= string_to_event_location (&addr_str
,
14005 if (!create_breakpoint (get_current_arch (),
14007 utp
->cond_string
.get (), -1, addr_str
,
14008 false /* force_condition */,
14009 0 /* parse cond/thread */,
14011 utp
->type
/* type_wanted */,
14012 0 /* Ignore count */,
14013 pending_break_support
,
14014 &vtable_breakpoint_ops
,
14016 utp
->enabled
/* enabled */,
14018 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14021 /* Get the tracepoint we just created. */
14022 tp
= get_tracepoint (tracepoint_count
);
14023 gdb_assert (tp
!= NULL
);
14027 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14030 trace_pass_command (small_buf
, 0);
14033 /* If we have uploaded versions of the original commands, set up a
14034 special-purpose "reader" function and call the usual command line
14035 reader, then pass the result to the breakpoint command-setting
14037 if (!utp
->cmd_strings
.empty ())
14039 counted_command_line cmd_list
;
14044 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14046 breakpoint_set_commands (tp
, std::move (cmd_list
));
14048 else if (!utp
->actions
.empty ()
14049 || !utp
->step_actions
.empty ())
14050 warning (_("Uploaded tracepoint %d actions "
14051 "have no source form, ignoring them"),
14054 /* Copy any status information that might be available. */
14055 tp
->hit_count
= utp
->hit_count
;
14056 tp
->traceframe_usage
= utp
->traceframe_usage
;
14061 /* Print information on tracepoint number TPNUM_EXP, or all if
14065 info_tracepoints_command (const char *args
, int from_tty
)
14067 struct ui_out
*uiout
= current_uiout
;
14070 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14072 if (num_printed
== 0)
14074 if (args
== NULL
|| *args
== '\0')
14075 uiout
->message ("No tracepoints.\n");
14077 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14080 default_collect_info ();
14083 /* The 'enable trace' command enables tracepoints.
14084 Not supported by all targets. */
14086 enable_trace_command (const char *args
, int from_tty
)
14088 enable_command (args
, from_tty
);
14091 /* The 'disable trace' command disables tracepoints.
14092 Not supported by all targets. */
14094 disable_trace_command (const char *args
, int from_tty
)
14096 disable_command (args
, from_tty
);
14099 /* Remove a tracepoint (or all if no argument). */
14101 delete_trace_command (const char *arg
, int from_tty
)
14107 int breaks_to_delete
= 0;
14109 /* Delete all breakpoints if no argument.
14110 Do not delete internal or call-dummy breakpoints, these
14111 have to be deleted with an explicit breakpoint number
14113 for (breakpoint
*tp
: all_tracepoints ())
14114 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
14116 breaks_to_delete
= 1;
14120 /* Ask user only if there are some breakpoints to delete. */
14122 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14124 for (breakpoint
*b
: all_breakpoints_safe ())
14125 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14126 delete_breakpoint (b
);
14130 map_breakpoint_numbers
14131 (arg
, [&] (breakpoint
*br
)
14133 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14137 /* Helper function for trace_pass_command. */
14140 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14142 tp
->pass_count
= count
;
14143 gdb::observers::breakpoint_modified
.notify (tp
);
14145 gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
14146 tp
->number
, count
);
14149 /* Set passcount for tracepoint.
14151 First command argument is passcount, second is tracepoint number.
14152 If tracepoint number omitted, apply to most recently defined.
14153 Also accepts special argument "all". */
14156 trace_pass_command (const char *args
, int from_tty
)
14158 struct tracepoint
*t1
;
14161 if (args
== 0 || *args
== 0)
14162 error (_("passcount command requires an "
14163 "argument (count + optional TP num)"));
14165 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14167 args
= skip_spaces (args
);
14168 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14170 args
+= 3; /* Skip special argument "all". */
14172 error (_("Junk at end of arguments."));
14174 for (breakpoint
*b
: all_tracepoints ())
14176 t1
= (struct tracepoint
*) b
;
14177 trace_pass_set_count (t1
, count
, from_tty
);
14180 else if (*args
== '\0')
14182 t1
= get_tracepoint_by_number (&args
, NULL
);
14184 trace_pass_set_count (t1
, count
, from_tty
);
14188 number_or_range_parser
parser (args
);
14189 while (!parser
.finished ())
14191 t1
= get_tracepoint_by_number (&args
, &parser
);
14193 trace_pass_set_count (t1
, count
, from_tty
);
14198 struct tracepoint
*
14199 get_tracepoint (int num
)
14201 for (breakpoint
*t
: all_tracepoints ())
14202 if (t
->number
== num
)
14203 return (struct tracepoint
*) t
;
14208 /* Find the tracepoint with the given target-side number (which may be
14209 different from the tracepoint number after disconnecting and
14212 struct tracepoint
*
14213 get_tracepoint_by_number_on_target (int num
)
14215 for (breakpoint
*b
: all_tracepoints ())
14217 struct tracepoint
*t
= (struct tracepoint
*) b
;
14219 if (t
->number_on_target
== num
)
14226 /* Utility: parse a tracepoint number and look it up in the list.
14227 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14228 If the argument is missing, the most recent tracepoint
14229 (tracepoint_count) is returned. */
14231 struct tracepoint
*
14232 get_tracepoint_by_number (const char **arg
,
14233 number_or_range_parser
*parser
)
14236 const char *instring
= arg
== NULL
? NULL
: *arg
;
14238 if (parser
!= NULL
)
14240 gdb_assert (!parser
->finished ());
14241 tpnum
= parser
->get_number ();
14243 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14244 tpnum
= tracepoint_count
;
14246 tpnum
= get_number (arg
);
14250 if (instring
&& *instring
)
14251 gdb_printf (_("bad tracepoint number at or near '%s'\n"),
14254 gdb_printf (_("No previous tracepoint\n"));
14258 for (breakpoint
*t
: all_tracepoints ())
14259 if (t
->number
== tpnum
)
14260 return (struct tracepoint
*) t
;
14262 gdb_printf ("No tracepoint number %d.\n", tpnum
);
14267 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14269 if (b
->thread
!= -1)
14270 gdb_printf (fp
, " thread %d", b
->thread
);
14273 gdb_printf (fp
, " task %d", b
->task
);
14275 gdb_printf (fp
, "\n");
14278 /* Save information on user settable breakpoints (watchpoints, etc) to
14279 a new script file named FILENAME. If FILTER is non-NULL, call it
14280 on each breakpoint and only include the ones for which it returns
14284 save_breakpoints (const char *filename
, int from_tty
,
14285 bool (*filter
) (const struct breakpoint
*))
14288 int extra_trace_bits
= 0;
14290 if (filename
== 0 || *filename
== 0)
14291 error (_("Argument required (file name in which to save)"));
14293 /* See if we have anything to save. */
14294 for (breakpoint
*tp
: all_breakpoints ())
14296 /* Skip internal and momentary breakpoints. */
14297 if (!user_breakpoint_p (tp
))
14300 /* If we have a filter, only save the breakpoints it accepts. */
14301 if (filter
&& !filter (tp
))
14306 if (is_tracepoint (tp
))
14308 extra_trace_bits
= 1;
14310 /* We can stop searching. */
14317 warning (_("Nothing to save."));
14321 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14325 if (!fp
.open (expanded_filename
.get (), "w"))
14326 error (_("Unable to open file '%s' for saving (%s)"),
14327 expanded_filename
.get (), safe_strerror (errno
));
14329 if (extra_trace_bits
)
14330 save_trace_state_variables (&fp
);
14332 for (breakpoint
*tp
: all_breakpoints ())
14334 /* Skip internal and momentary breakpoints. */
14335 if (!user_breakpoint_p (tp
))
14338 /* If we have a filter, only save the breakpoints it accepts. */
14339 if (filter
&& !filter (tp
))
14342 tp
->ops
->print_recreate (tp
, &fp
);
14344 /* Note, we can't rely on tp->number for anything, as we can't
14345 assume the recreated breakpoint numbers will match. Use $bpnum
14348 if (tp
->cond_string
)
14349 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
.get ());
14351 if (tp
->ignore_count
)
14352 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14354 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
14356 fp
.puts (" commands\n");
14358 current_uiout
->redirect (&fp
);
14361 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
14363 catch (const gdb_exception
&ex
)
14365 current_uiout
->redirect (NULL
);
14369 current_uiout
->redirect (NULL
);
14370 fp
.puts (" end\n");
14373 if (tp
->enable_state
== bp_disabled
)
14374 fp
.puts ("disable $bpnum\n");
14376 /* If this is a multi-location breakpoint, check if the locations
14377 should be individually disabled. Watchpoint locations are
14378 special, and not user visible. */
14379 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14383 for (bp_location
*loc
: tp
->locations ())
14386 fp
.printf ("disable $bpnum.%d\n", n
);
14393 if (extra_trace_bits
&& !default_collect
.empty ())
14394 fp
.printf ("set default-collect %s\n", default_collect
.c_str ());
14397 gdb_printf (_("Saved to file '%s'.\n"), expanded_filename
.get ());
14400 /* The `save breakpoints' command. */
14403 save_breakpoints_command (const char *args
, int from_tty
)
14405 save_breakpoints (args
, from_tty
, NULL
);
14408 /* The `save tracepoints' command. */
14411 save_tracepoints_command (const char *args
, int from_tty
)
14413 save_breakpoints (args
, from_tty
, is_tracepoint
);
14417 /* This help string is used to consolidate all the help string for specifying
14418 locations used by several commands. */
14420 #define LOCATION_HELP_STRING \
14421 "Linespecs are colon-separated lists of location parameters, such as\n\
14422 source filename, function name, label name, and line number.\n\
14423 Example: To specify the start of a label named \"the_top\" in the\n\
14424 function \"fact\" in the file \"factorial.c\", use\n\
14425 \"factorial.c:fact:the_top\".\n\
14427 Address locations begin with \"*\" and specify an exact address in the\n\
14428 program. Example: To specify the fourth byte past the start function\n\
14429 \"main\", use \"*main + 4\".\n\
14431 Explicit locations are similar to linespecs but use an option/argument\n\
14432 syntax to specify location parameters.\n\
14433 Example: To specify the start of the label named \"the_top\" in the\n\
14434 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
14435 -function fact -label the_top\".\n\
14437 By default, a specified function is matched against the program's\n\
14438 functions in all scopes. For C++, this means in all namespaces and\n\
14439 classes. For Ada, this means in all packages. E.g., in C++,\n\
14440 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
14441 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
14442 specified name as a complete fully-qualified name instead."
14444 /* This help string is used for the break, hbreak, tbreak and thbreak
14445 commands. It is defined as a macro to prevent duplication.
14446 COMMAND should be a string constant containing the name of the
14449 #define BREAK_ARGS_HELP(command) \
14450 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
14451 \t[-force-condition] [if CONDITION]\n\
14452 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
14453 probe point. Accepted values are `-probe' (for a generic, automatically\n\
14454 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
14455 `-probe-dtrace' (for a DTrace probe).\n\
14456 LOCATION may be a linespec, address, or explicit location as described\n\
14459 With no LOCATION, uses current execution address of the selected\n\
14460 stack frame. This is useful for breaking on return to a stack frame.\n\
14462 THREADNUM is the number from \"info threads\".\n\
14463 CONDITION is a boolean expression.\n\
14465 With the \"-force-condition\" flag, the condition is defined even when\n\
14466 it is invalid for all current locations.\n\
14467 \n" LOCATION_HELP_STRING "\n\n\
14468 Multiple breakpoints at one place are permitted, and useful if their\n\
14469 conditions are different.\n\
14471 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14473 /* List of subcommands for "catch". */
14474 static struct cmd_list_element
*catch_cmdlist
;
14476 /* List of subcommands for "tcatch". */
14477 static struct cmd_list_element
*tcatch_cmdlist
;
14480 add_catch_command (const char *name
, const char *docstring
,
14481 cmd_func_ftype
*func
,
14482 completer_ftype
*completer
,
14483 void *user_data_catch
,
14484 void *user_data_tcatch
)
14486 struct cmd_list_element
*command
;
14488 command
= add_cmd (name
, class_breakpoint
, docstring
,
14490 command
->func
= func
;
14491 command
->set_context (user_data_catch
);
14492 set_cmd_completer (command
, completer
);
14494 command
= add_cmd (name
, class_breakpoint
, docstring
,
14496 command
->func
= func
;
14497 command
->set_context (user_data_tcatch
);
14498 set_cmd_completer (command
, completer
);
14501 /* Zero if any of the breakpoint's locations could be a location where
14502 functions have been inlined, nonzero otherwise. */
14505 is_non_inline_function (struct breakpoint
*b
)
14507 /* The shared library event breakpoint is set on the address of a
14508 non-inline function. */
14509 if (b
->type
== bp_shlib_event
)
14515 /* Nonzero if the specified PC cannot be a location where functions
14516 have been inlined. */
14519 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
14520 const target_waitstatus
&ws
)
14522 for (breakpoint
*b
: all_breakpoints ())
14524 if (!is_non_inline_function (b
))
14527 for (bp_location
*bl
: b
->locations ())
14529 if (!bl
->shlib_disabled
14530 && bpstat_check_location (bl
, aspace
, pc
, ws
))
14538 /* Remove any references to OBJFILE which is going to be freed. */
14541 breakpoint_free_objfile (struct objfile
*objfile
)
14543 for (bp_location
*loc
: all_bp_locations ())
14544 if (loc
->symtab
!= NULL
&& loc
->symtab
->compunit ()->objfile () == objfile
)
14545 loc
->symtab
= NULL
;
14549 initialize_breakpoint_ops (void)
14551 static int initialized
= 0;
14553 struct breakpoint_ops
*ops
;
14559 /* The breakpoint_ops structure to be inherit by all kinds of
14560 breakpoints (real breakpoints, i.e., user "break" breakpoints,
14561 internal and momentary breakpoints, etc.). */
14562 ops
= &bkpt_base_breakpoint_ops
;
14563 *ops
= vtable_breakpoint_ops
;
14565 /* The breakpoint_ops structure to be used in regular breakpoints. */
14566 ops
= &bkpt_breakpoint_ops
;
14567 *ops
= bkpt_base_breakpoint_ops
;
14568 ops
->resources_needed
= bkpt_resources_needed
;
14569 ops
->print_it
= bkpt_print_it
;
14570 ops
->print_mention
= bkpt_print_mention
;
14571 ops
->print_recreate
= bkpt_print_recreate
;
14573 /* Ranged breakpoints. */
14574 ops
= &ranged_breakpoint_ops
;
14575 *ops
= bkpt_breakpoint_ops
;
14576 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
14577 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
14578 ops
->print_it
= print_it_ranged_breakpoint
;
14579 ops
->print_one
= print_one_ranged_breakpoint
;
14580 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
14581 ops
->print_mention
= print_mention_ranged_breakpoint
;
14582 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
14584 /* Probe breakpoints. */
14585 ops
= &bkpt_probe_breakpoint_ops
;
14586 *ops
= bkpt_breakpoint_ops
;
14587 ops
->insert_location
= bkpt_probe_insert_location
;
14588 ops
->remove_location
= bkpt_probe_remove_location
;
14589 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
14590 ops
->decode_location
= bkpt_probe_decode_location
;
14592 /* Probe tracepoints. */
14593 ops
= &tracepoint_probe_breakpoint_ops
;
14594 *ops
= vtable_breakpoint_ops
;
14595 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
14596 ops
->decode_location
= tracepoint_probe_decode_location
;
14598 /* Static tracepoints with marker (`-m'). */
14599 ops
= &strace_marker_breakpoint_ops
;
14600 *ops
= vtable_breakpoint_ops
;
14601 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
14602 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
14603 ops
->decode_location
= strace_marker_decode_location
;
14605 ops
= &dprintf_breakpoint_ops
;
14606 *ops
= bkpt_breakpoint_ops
;
14607 ops
->re_set
= dprintf_re_set
;
14608 ops
->print_recreate
= dprintf_print_recreate
;
14609 ops
->after_condition_true
= dprintf_after_condition_true
;
14610 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
14613 /* Chain containing all defined "enable breakpoint" subcommands. */
14615 static struct cmd_list_element
*enablebreaklist
= NULL
;
14617 /* See breakpoint.h. */
14619 cmd_list_element
*commands_cmd_element
= nullptr;
14621 void _initialize_breakpoint ();
14623 _initialize_breakpoint ()
14625 struct cmd_list_element
*c
;
14627 initialize_breakpoint_ops ();
14629 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
14631 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
14633 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
14636 breakpoint_chain
= 0;
14637 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14638 before a breakpoint is set. */
14639 breakpoint_count
= 0;
14641 tracepoint_count
= 0;
14643 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
14644 Set ignore-count of breakpoint number N to COUNT.\n\
14645 Usage is `ignore N COUNT'."));
14647 commands_cmd_element
= add_com ("commands", class_breakpoint
,
14648 commands_command
, _("\
14649 Set commands to be executed when the given breakpoints are hit.\n\
14650 Give a space-separated breakpoint list as argument after \"commands\".\n\
14651 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
14653 With no argument, the targeted breakpoint is the last one set.\n\
14654 The commands themselves follow starting on the next line.\n\
14655 Type a line containing \"end\" to indicate the end of them.\n\
14656 Give \"silent\" as the first line to make the breakpoint silent;\n\
14657 then no output is printed when it is hit, except what the commands print."));
14659 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
14660 static std::string condition_command_help
14661 = gdb::option::build_help (_("\
14662 Specify breakpoint number N to break only if COND is true.\n\
14663 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
14664 is an expression to be evaluated whenever breakpoint N is reached.\n\
14667 %OPTIONS%"), cc_opts
);
14669 c
= add_com ("condition", class_breakpoint
, condition_command
,
14670 condition_command_help
.c_str ());
14671 set_cmd_completer_handle_brkchars (c
, condition_completer
);
14673 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
14674 Set a temporary breakpoint.\n\
14675 Like \"break\" except the breakpoint is only temporary,\n\
14676 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14677 by using \"enable delete\" on the breakpoint number.\n\
14679 BREAK_ARGS_HELP ("tbreak")));
14680 set_cmd_completer (c
, location_completer
);
14682 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
14683 Set a hardware assisted breakpoint.\n\
14684 Like \"break\" except the breakpoint requires hardware support,\n\
14685 some target hardware may not have this support.\n\
14687 BREAK_ARGS_HELP ("hbreak")));
14688 set_cmd_completer (c
, location_completer
);
14690 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
14691 Set a temporary hardware assisted breakpoint.\n\
14692 Like \"hbreak\" except the breakpoint is only temporary,\n\
14693 so it will be deleted when hit.\n\
14695 BREAK_ARGS_HELP ("thbreak")));
14696 set_cmd_completer (c
, location_completer
);
14698 cmd_list_element
*enable_cmd
14699 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
14700 Enable all or some breakpoints.\n\
14701 Usage: enable [BREAKPOINTNUM]...\n\
14702 Give breakpoint numbers (separated by spaces) as arguments.\n\
14703 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14704 This is used to cancel the effect of the \"disable\" command.\n\
14705 With a subcommand you can enable temporarily."),
14706 &enablelist
, 1, &cmdlist
);
14708 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
14710 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
14711 Enable all or some breakpoints.\n\
14712 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
14713 Give breakpoint numbers (separated by spaces) as arguments.\n\
14714 This is used to cancel the effect of the \"disable\" command.\n\
14715 May be abbreviated to simply \"enable\"."),
14716 &enablebreaklist
, 1, &enablelist
);
14718 add_cmd ("once", no_class
, enable_once_command
, _("\
14719 Enable some breakpoints for one hit.\n\
14720 Usage: enable breakpoints once BREAKPOINTNUM...\n\
14721 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14724 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14725 Enable some breakpoints and delete when hit.\n\
14726 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
14727 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14730 add_cmd ("count", no_class
, enable_count_command
, _("\
14731 Enable some breakpoints for COUNT hits.\n\
14732 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
14733 If a breakpoint is hit while enabled in this fashion,\n\
14734 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14737 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14738 Enable some breakpoints and delete when hit.\n\
14739 Usage: enable delete BREAKPOINTNUM...\n\
14740 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14743 add_cmd ("once", no_class
, enable_once_command
, _("\
14744 Enable some breakpoints for one hit.\n\
14745 Usage: enable once BREAKPOINTNUM...\n\
14746 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14749 add_cmd ("count", no_class
, enable_count_command
, _("\
14750 Enable some breakpoints for COUNT hits.\n\
14751 Usage: enable count COUNT BREAKPOINTNUM...\n\
14752 If a breakpoint is hit while enabled in this fashion,\n\
14753 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14756 cmd_list_element
*disable_cmd
14757 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
14758 Disable all or some breakpoints.\n\
14759 Usage: disable [BREAKPOINTNUM]...\n\
14760 Arguments are breakpoint numbers with spaces in between.\n\
14761 To disable all breakpoints, give no argument.\n\
14762 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14763 &disablelist
, 1, &cmdlist
);
14764 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
14765 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
14767 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
14768 Disable all or some breakpoints.\n\
14769 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
14770 Arguments are breakpoint numbers with spaces in between.\n\
14771 To disable all breakpoints, give no argument.\n\
14772 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14773 This command may be abbreviated \"disable\"."),
14776 cmd_list_element
*delete_cmd
14777 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
14778 Delete all or some breakpoints.\n\
14779 Usage: delete [BREAKPOINTNUM]...\n\
14780 Arguments are breakpoint numbers with spaces in between.\n\
14781 To delete all breakpoints, give no argument.\n\
14783 Also a prefix command for deletion of other GDB objects."),
14784 &deletelist
, 1, &cmdlist
);
14785 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
14786 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
14788 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
14789 Delete all or some breakpoints or auto-display expressions.\n\
14790 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
14791 Arguments are breakpoint numbers with spaces in between.\n\
14792 To delete all breakpoints, give no argument.\n\
14793 This command may be abbreviated \"delete\"."),
14796 cmd_list_element
*clear_cmd
14797 = add_com ("clear", class_breakpoint
, clear_command
, _("\
14798 Clear breakpoint at specified location.\n\
14799 Argument may be a linespec, explicit, or address location as described below.\n\
14801 With no argument, clears all breakpoints in the line that the selected frame\n\
14802 is executing in.\n"
14803 "\n" LOCATION_HELP_STRING
"\n\n\
14804 See also the \"delete\" command which clears breakpoints by number."));
14805 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
14807 cmd_list_element
*break_cmd
14808 = add_com ("break", class_breakpoint
, break_command
, _("\
14809 Set breakpoint at specified location.\n"
14810 BREAK_ARGS_HELP ("break")));
14811 set_cmd_completer (break_cmd
, location_completer
);
14813 add_com_alias ("b", break_cmd
, class_run
, 1);
14814 add_com_alias ("br", break_cmd
, class_run
, 1);
14815 add_com_alias ("bre", break_cmd
, class_run
, 1);
14816 add_com_alias ("brea", break_cmd
, class_run
, 1);
14818 cmd_list_element
*info_breakpoints_cmd
14819 = add_info ("breakpoints", info_breakpoints_command
, _("\
14820 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14821 The \"Type\" column indicates one of:\n\
14822 \tbreakpoint - normal breakpoint\n\
14823 \twatchpoint - watchpoint\n\
14824 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14825 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14826 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14827 address and file/line number respectively.\n\
14829 Convenience variable \"$_\" and default examine address for \"x\"\n\
14830 are set to the address of the last breakpoint listed unless the command\n\
14831 is prefixed with \"server \".\n\n\
14832 Convenience variable \"$bpnum\" contains the number of the last\n\
14833 breakpoint set."));
14835 add_info_alias ("b", info_breakpoints_cmd
, 1);
14837 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
14838 Status of all breakpoints, or breakpoint number NUMBER.\n\
14839 The \"Type\" column indicates one of:\n\
14840 \tbreakpoint - normal breakpoint\n\
14841 \twatchpoint - watchpoint\n\
14842 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14843 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14844 \tuntil - internal breakpoint used by the \"until\" command\n\
14845 \tfinish - internal breakpoint used by the \"finish\" command\n\
14846 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14847 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14848 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14849 address and file/line number respectively.\n\
14851 Convenience variable \"$_\" and default examine address for \"x\"\n\
14852 are set to the address of the last breakpoint listed unless the command\n\
14853 is prefixed with \"server \".\n\n\
14854 Convenience variable \"$bpnum\" contains the number of the last\n\
14856 &maintenanceinfolist
);
14858 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
14859 Set catchpoints to catch events."),
14861 0/*allow-unknown*/, &cmdlist
);
14863 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
14864 Set temporary catchpoints to catch events."),
14866 0/*allow-unknown*/, &cmdlist
);
14868 const auto opts
= make_watch_options_def_group (nullptr);
14870 static const std::string watch_help
= gdb::option::build_help (_("\
14871 Set a watchpoint for EXPRESSION.\n\
14872 Usage: watch [-location] EXPRESSION\n\
14877 A watchpoint stops execution of your program whenever the value of\n\
14878 an expression changes."), opts
);
14879 c
= add_com ("watch", class_breakpoint
, watch_command
,
14880 watch_help
.c_str ());
14881 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14883 static const std::string rwatch_help
= gdb::option::build_help (_("\
14884 Set a read watchpoint for EXPRESSION.\n\
14885 Usage: rwatch [-location] EXPRESSION\n\
14890 A read watchpoint stops execution of your program whenever the value of\n\
14891 an expression is read."), opts
);
14892 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
14893 rwatch_help
.c_str ());
14894 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14896 static const std::string awatch_help
= gdb::option::build_help (_("\
14897 Set an access watchpoint for EXPRESSION.\n\
14898 Usage: awatch [-location] EXPRESSION\n\
14903 An access watchpoint stops execution of your program whenever the value\n\
14904 of an expression is either read or written."), opts
);
14905 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
14906 awatch_help
.c_str ());
14907 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14909 add_info ("watchpoints", info_watchpoints_command
, _("\
14910 Status of specified watchpoints (all watchpoints if no argument)."));
14912 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14913 respond to changes - contrary to the description. */
14914 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14915 &can_use_hw_watchpoints
, _("\
14916 Set debugger's willingness to use watchpoint hardware."), _("\
14917 Show debugger's willingness to use watchpoint hardware."), _("\
14918 If zero, gdb will not use hardware for new watchpoints, even if\n\
14919 such is available. (However, any hardware watchpoints that were\n\
14920 created before setting this to nonzero, will continue to use watchpoint\n\
14923 show_can_use_hw_watchpoints
,
14924 &setlist
, &showlist
);
14926 can_use_hw_watchpoints
= 1;
14928 /* Tracepoint manipulation commands. */
14930 cmd_list_element
*trace_cmd
14931 = add_com ("trace", class_breakpoint
, trace_command
, _("\
14932 Set a tracepoint at specified location.\n\
14934 BREAK_ARGS_HELP ("trace") "\n\
14935 Do \"help tracepoints\" for info on other tracepoint commands."));
14936 set_cmd_completer (trace_cmd
, location_completer
);
14938 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
14939 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
14940 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
14941 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
14943 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14944 Set a fast tracepoint at specified location.\n\
14946 BREAK_ARGS_HELP ("ftrace") "\n\
14947 Do \"help tracepoints\" for info on other tracepoint commands."));
14948 set_cmd_completer (c
, location_completer
);
14950 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
14951 Set a static tracepoint at location or marker.\n\
14953 strace [LOCATION] [if CONDITION]\n\
14954 LOCATION may be a linespec, explicit, or address location (described below) \n\
14955 or -m MARKER_ID.\n\n\
14956 If a marker id is specified, probe the marker with that name. With\n\
14957 no LOCATION, uses current execution address of the selected stack frame.\n\
14958 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14959 This collects arbitrary user data passed in the probe point call to the\n\
14960 tracing library. You can inspect it when analyzing the trace buffer,\n\
14961 by printing the $_sdata variable like any other convenience variable.\n\
14963 CONDITION is a boolean expression.\n\
14964 \n" LOCATION_HELP_STRING
"\n\n\
14965 Multiple tracepoints at one place are permitted, and useful if their\n\
14966 conditions are different.\n\
14968 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14969 Do \"help tracepoints\" for info on other tracepoint commands."));
14970 set_cmd_completer (c
, location_completer
);
14972 cmd_list_element
*info_tracepoints_cmd
14973 = add_info ("tracepoints", info_tracepoints_command
, _("\
14974 Status of specified tracepoints (all tracepoints if no argument).\n\
14975 Convenience variable \"$tpnum\" contains the number of the\n\
14976 last tracepoint set."));
14978 add_info_alias ("tp", info_tracepoints_cmd
, 1);
14980 cmd_list_element
*delete_tracepoints_cmd
14981 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
14982 Delete specified tracepoints.\n\
14983 Arguments are tracepoint numbers, separated by spaces.\n\
14984 No argument means delete all tracepoints."),
14986 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
14988 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
14989 Disable specified tracepoints.\n\
14990 Arguments are tracepoint numbers, separated by spaces.\n\
14991 No argument means disable all tracepoints."),
14993 deprecate_cmd (c
, "disable");
14995 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
14996 Enable specified tracepoints.\n\
14997 Arguments are tracepoint numbers, separated by spaces.\n\
14998 No argument means enable all tracepoints."),
15000 deprecate_cmd (c
, "enable");
15002 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15003 Set the passcount for a tracepoint.\n\
15004 The trace will end when the tracepoint has been passed 'count' times.\n\
15005 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15006 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15008 add_basic_prefix_cmd ("save", class_breakpoint
,
15009 _("Save breakpoint definitions as a script."),
15011 0/*allow-unknown*/, &cmdlist
);
15013 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15014 Save current breakpoint definitions as a script.\n\
15015 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15016 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15017 session to restore them."),
15019 set_cmd_completer (c
, filename_completer
);
15021 cmd_list_element
*save_tracepoints_cmd
15022 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15023 Save current tracepoint definitions as a script.\n\
15024 Use the 'source' command in another debug session to restore them."),
15026 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
15028 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
15029 deprecate_cmd (c
, "save tracepoints");
15031 add_setshow_prefix_cmd ("breakpoint", class_maintenance
,
15033 Breakpoint specific settings.\n\
15034 Configure various breakpoint-specific variables such as\n\
15035 pending breakpoint behavior."),
15037 Breakpoint specific settings.\n\
15038 Configure various breakpoint-specific variables such as\n\
15039 pending breakpoint behavior."),
15040 &breakpoint_set_cmdlist
, &breakpoint_show_cmdlist
,
15041 &setlist
, &showlist
);
15043 add_setshow_auto_boolean_cmd ("pending", no_class
,
15044 &pending_break_support
, _("\
15045 Set debugger's behavior regarding pending breakpoints."), _("\
15046 Show debugger's behavior regarding pending breakpoints."), _("\
15047 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15048 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15049 an error. If auto, an unrecognized breakpoint location results in a\n\
15050 user-query to see if a pending breakpoint should be created."),
15052 show_pending_break_support
,
15053 &breakpoint_set_cmdlist
,
15054 &breakpoint_show_cmdlist
);
15056 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15058 add_setshow_boolean_cmd ("auto-hw", no_class
,
15059 &automatic_hardware_breakpoints
, _("\
15060 Set automatic usage of hardware breakpoints."), _("\
15061 Show automatic usage of hardware breakpoints."), _("\
15062 If set, the debugger will automatically use hardware breakpoints for\n\
15063 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15064 a warning will be emitted for such breakpoints."),
15066 show_automatic_hardware_breakpoints
,
15067 &breakpoint_set_cmdlist
,
15068 &breakpoint_show_cmdlist
);
15070 add_setshow_boolean_cmd ("always-inserted", class_support
,
15071 &always_inserted_mode
, _("\
15072 Set mode for inserting breakpoints."), _("\
15073 Show mode for inserting breakpoints."), _("\
15074 When this mode is on, breakpoints are inserted immediately as soon as\n\
15075 they're created, kept inserted even when execution stops, and removed\n\
15076 only when the user deletes them. When this mode is off (the default),\n\
15077 breakpoints are inserted only when execution continues, and removed\n\
15078 when execution stops."),
15080 &show_always_inserted_mode
,
15081 &breakpoint_set_cmdlist
,
15082 &breakpoint_show_cmdlist
);
15084 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15085 condition_evaluation_enums
,
15086 &condition_evaluation_mode_1
, _("\
15087 Set mode of breakpoint condition evaluation."), _("\
15088 Show mode of breakpoint condition evaluation."), _("\
15089 When this is set to \"host\", breakpoint conditions will be\n\
15090 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15091 breakpoint conditions will be downloaded to the target (if the target\n\
15092 supports such feature) and conditions will be evaluated on the target's side.\n\
15093 If this is set to \"auto\" (default), this will be automatically set to\n\
15094 \"target\" if it supports condition evaluation, otherwise it will\n\
15095 be set to \"host\"."),
15096 &set_condition_evaluation_mode
,
15097 &show_condition_evaluation_mode
,
15098 &breakpoint_set_cmdlist
,
15099 &breakpoint_show_cmdlist
);
15101 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15102 Set a breakpoint for an address range.\n\
15103 break-range START-LOCATION, END-LOCATION\n\
15104 where START-LOCATION and END-LOCATION can be one of the following:\n\
15105 LINENUM, for that line in the current file,\n\
15106 FILE:LINENUM, for that line in that file,\n\
15107 +OFFSET, for that number of lines after the current line\n\
15108 or the start of the range\n\
15109 FUNCTION, for the first line in that function,\n\
15110 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15111 *ADDRESS, for the instruction at that address.\n\
15113 The breakpoint will stop execution of the inferior whenever it executes\n\
15114 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15115 range (including START-LOCATION and END-LOCATION)."));
15117 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
15118 Set a dynamic printf at specified location.\n\
15119 dprintf location,format string,arg1,arg2,...\n\
15120 location may be a linespec, explicit, or address location.\n"
15121 "\n" LOCATION_HELP_STRING
));
15122 set_cmd_completer (c
, location_completer
);
15124 add_setshow_enum_cmd ("dprintf-style", class_support
,
15125 dprintf_style_enums
, &dprintf_style
, _("\
15126 Set the style of usage for dynamic printf."), _("\
15127 Show the style of usage for dynamic printf."), _("\
15128 This setting chooses how GDB will do a dynamic printf.\n\
15129 If the value is \"gdb\", then the printing is done by GDB to its own\n\
15130 console, as with the \"printf\" command.\n\
15131 If the value is \"call\", the print is done by calling a function in your\n\
15132 program; by default printf(), but you can choose a different function or\n\
15133 output stream by setting dprintf-function and dprintf-channel."),
15134 update_dprintf_commands
, NULL
,
15135 &setlist
, &showlist
);
15137 add_setshow_string_cmd ("dprintf-function", class_support
,
15138 &dprintf_function
, _("\
15139 Set the function to use for dynamic printf."), _("\
15140 Show the function to use for dynamic printf."), NULL
,
15141 update_dprintf_commands
, NULL
,
15142 &setlist
, &showlist
);
15144 add_setshow_string_cmd ("dprintf-channel", class_support
,
15145 &dprintf_channel
, _("\
15146 Set the channel to use for dynamic printf."), _("\
15147 Show the channel to use for dynamic printf."), NULL
,
15148 update_dprintf_commands
, NULL
,
15149 &setlist
, &showlist
);
15151 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
15152 &disconnected_dprintf
, _("\
15153 Set whether dprintf continues after GDB disconnects."), _("\
15154 Show whether dprintf continues after GDB disconnects."), _("\
15155 Use this to let dprintf commands continue to hit and produce output\n\
15156 even if GDB disconnects or detaches from the target."),
15159 &setlist
, &showlist
);
15161 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
15162 Target agent only formatted printing, like the C \"printf\" function.\n\
15163 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
15164 This supports most C printf format specifications, like %s, %d, etc.\n\
15165 This is useful for formatted output in user-defined commands."));
15167 automatic_hardware_breakpoints
= true;
15169 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
15171 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,