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 /* Internal breakpoints class type. */
238 static struct breakpoint_ops internal_breakpoint_ops
;
240 /* Momentary breakpoints class type. */
241 static struct breakpoint_ops momentary_breakpoint_ops
;
243 /* The breakpoint_ops structure to be used in regular user created
245 struct breakpoint_ops bkpt_breakpoint_ops
;
247 /* Breakpoints set on probes. */
248 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
250 /* Tracepoints set on probes. */
251 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
253 /* Dynamic printf class type. */
254 struct breakpoint_ops dprintf_breakpoint_ops
;
256 /* The structure to be used in regular breakpoints. */
257 struct ordinary_breakpoint
: public base_breakpoint
261 /* Internal breakpoints. */
262 struct internal_breakpoint
: public base_breakpoint
266 /* Momentary breakpoints. */
267 struct momentary_breakpoint
: public base_breakpoint
271 /* DPrintf breakpoints. */
272 struct dprintf_breakpoint
: public base_breakpoint
276 /* The style in which to perform a dynamic printf. This is a user
277 option because different output options have different tradeoffs;
278 if GDB does the printing, there is better error handling if there
279 is a problem with any of the arguments, but using an inferior
280 function lets you have special-purpose printers and sending of
281 output to the same place as compiled-in print functions. */
283 static const char dprintf_style_gdb
[] = "gdb";
284 static const char dprintf_style_call
[] = "call";
285 static const char dprintf_style_agent
[] = "agent";
286 static const char *const dprintf_style_enums
[] = {
292 static const char *dprintf_style
= dprintf_style_gdb
;
294 /* The function to use for dynamic printf if the preferred style is to
295 call into the inferior. The value is simply a string that is
296 copied into the command, so it can be anything that GDB can
297 evaluate to a callable address, not necessarily a function name. */
299 static std::string dprintf_function
= "printf";
301 /* The channel to use for dynamic printf if the preferred style is to
302 call into the inferior; if a nonempty string, it will be passed to
303 the call as the first argument, with the format string as the
304 second. As with the dprintf function, this can be anything that
305 GDB knows how to evaluate, so in addition to common choices like
306 "stderr", this could be an app-specific expression like
307 "mystreams[curlogger]". */
309 static std::string dprintf_channel
;
311 /* True if dprintf commands should continue to operate even if GDB
313 static bool disconnected_dprintf
= true;
315 struct command_line
*
316 breakpoint_commands (struct breakpoint
*b
)
318 return b
->commands
? b
->commands
.get () : NULL
;
321 /* Flag indicating that a command has proceeded the inferior past the
322 current breakpoint. */
324 static bool breakpoint_proceeded
;
327 bpdisp_text (enum bpdisp disp
)
329 /* NOTE: the following values are a part of MI protocol and
330 represent values of 'disp' field returned when inferior stops at
332 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
334 return bpdisps
[(int) disp
];
337 /* Prototypes for exported functions. */
338 /* If FALSE, gdb will not use hardware support for watchpoints, even
339 if such is available. */
340 static int can_use_hw_watchpoints
;
343 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
344 struct cmd_list_element
*c
,
348 _("Debugger's willingness to use "
349 "watchpoint hardware is %s.\n"),
353 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
354 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
355 for unrecognized breakpoint locations.
356 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
357 static enum auto_boolean pending_break_support
;
359 show_pending_break_support (struct ui_file
*file
, int from_tty
,
360 struct cmd_list_element
*c
,
364 _("Debugger's behavior regarding "
365 "pending breakpoints is %s.\n"),
369 /* If true, gdb will automatically use hardware breakpoints for breakpoints
370 set with "break" but falling in read-only memory.
371 If false, gdb will warn about such breakpoints, but won't automatically
372 use hardware breakpoints. */
373 static bool automatic_hardware_breakpoints
;
375 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
376 struct cmd_list_element
*c
,
380 _("Automatic usage of hardware breakpoints is %s.\n"),
384 /* If on, GDB keeps breakpoints inserted even if the inferior is
385 stopped, and immediately inserts any new breakpoints as soon as
386 they're created. If off (default), GDB keeps breakpoints off of
387 the target as long as possible. That is, it delays inserting
388 breakpoints until the next resume, and removes them again when the
389 target fully stops. This is a bit safer in case GDB crashes while
390 processing user input. */
391 static bool always_inserted_mode
= false;
394 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
395 struct cmd_list_element
*c
, const char *value
)
397 gdb_printf (file
, _("Always inserted breakpoint mode is %s.\n"),
401 /* See breakpoint.h. */
404 breakpoints_should_be_inserted_now (void)
406 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
408 /* If breakpoints are global, they should be inserted even if no
409 thread under gdb's control is running, or even if there are
410 no threads under GDB's control yet. */
415 if (always_inserted_mode
)
417 /* The user wants breakpoints inserted even if all threads
422 for (inferior
*inf
: all_inferiors ())
423 if (inf
->has_execution ()
424 && threads_are_executing (inf
->process_target ()))
427 /* Don't remove breakpoints yet if, even though all threads are
428 stopped, we still have events to process. */
429 for (thread_info
*tp
: all_non_exited_threads ())
430 if (tp
->resumed () && tp
->has_pending_waitstatus ())
436 static const char condition_evaluation_both
[] = "host or target";
438 /* Modes for breakpoint condition evaluation. */
439 static const char condition_evaluation_auto
[] = "auto";
440 static const char condition_evaluation_host
[] = "host";
441 static const char condition_evaluation_target
[] = "target";
442 static const char *const condition_evaluation_enums
[] = {
443 condition_evaluation_auto
,
444 condition_evaluation_host
,
445 condition_evaluation_target
,
449 /* Global that holds the current mode for breakpoint condition evaluation. */
450 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
452 /* Global that we use to display information to the user (gets its value from
453 condition_evaluation_mode_1. */
454 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
456 /* Translate a condition evaluation mode MODE into either "host"
457 or "target". This is used mostly to translate from "auto" to the
458 real setting that is being used. It returns the translated
462 translate_condition_evaluation_mode (const char *mode
)
464 if (mode
== condition_evaluation_auto
)
466 if (target_supports_evaluation_of_breakpoint_conditions ())
467 return condition_evaluation_target
;
469 return condition_evaluation_host
;
475 /* Discovers what condition_evaluation_auto translates to. */
478 breakpoint_condition_evaluation_mode (void)
480 return translate_condition_evaluation_mode (condition_evaluation_mode
);
483 /* Return true if GDB should evaluate breakpoint conditions or false
487 gdb_evaluates_breakpoint_condition_p (void)
489 const char *mode
= breakpoint_condition_evaluation_mode ();
491 return (mode
== condition_evaluation_host
);
494 /* Are we executing breakpoint commands? */
495 static int executing_breakpoint_commands
;
497 /* Are overlay event breakpoints enabled? */
498 static int overlay_events_enabled
;
500 /* See description in breakpoint.h. */
501 bool target_exact_watchpoints
= false;
503 /* Walk the following statement or block through all breakpoints.
504 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
505 current breakpoint. */
507 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
508 for (B = breakpoint_chain; \
509 B ? (TMP=B->next, 1): 0; \
512 /* Chains of all breakpoints defined. */
514 static struct breakpoint
*breakpoint_chain
;
516 /* See breakpoint.h. */
521 return breakpoint_range (breakpoint_chain
);
524 /* See breakpoint.h. */
526 breakpoint_safe_range
527 all_breakpoints_safe ()
529 return breakpoint_safe_range (all_breakpoints ());
532 /* See breakpoint.h. */
537 return tracepoint_range (breakpoint_chain
);
540 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
542 static std::vector
<bp_location
*> bp_locations
;
544 /* See breakpoint.h. */
546 const std::vector
<bp_location
*> &
552 /* Range to iterate over breakpoint locations at a given address. */
554 struct bp_locations_at_addr_range
556 using iterator
= std::vector
<bp_location
*>::iterator
;
558 bp_locations_at_addr_range (CORE_ADDR addr
)
562 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
563 { return loc
->address
< addr_
; }
565 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
566 { return addr_
< loc
->address
; }
569 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
572 m_begin
= it_pair
.first
;
573 m_end
= it_pair
.second
;
576 iterator
begin () const
579 iterator
end () const
587 /* Return a range to iterate over all breakpoint locations exactly at address
590 If it's needed to iterate multiple times on the same range, it's possible
591 to save the range in a local variable and use it multiple times:
593 auto range = all_bp_locations_at_addr (addr);
595 for (bp_location *loc : range)
598 for (bp_location *loc : range)
601 This saves a bit of time, as it avoids re-doing the binary searches to find
602 the range's boundaries. Just remember not to change the bp_locations vector
603 in the mean time, as it could make the range's iterators stale. */
605 static bp_locations_at_addr_range
606 all_bp_locations_at_addr (CORE_ADDR addr
)
608 return bp_locations_at_addr_range (addr
);
611 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
612 ADDRESS for the current elements of BP_LOCATIONS which get a valid
613 result from bp_location_has_shadow. You can use it for roughly
614 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
615 an address you need to read. */
617 static CORE_ADDR bp_locations_placed_address_before_address_max
;
619 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
620 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
621 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
622 You can use it for roughly limiting the subrange of BP_LOCATIONS to
623 scan for shadow bytes for an address you need to read. */
625 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
627 /* The locations that no longer correspond to any breakpoint, unlinked
628 from the bp_locations array, but for which a hit may still be
629 reported by a target. */
630 static std::vector
<bp_location
*> moribund_locations
;
632 /* Number of last breakpoint made. */
634 static int breakpoint_count
;
636 /* The value of `breakpoint_count' before the last command that
637 created breakpoints. If the last (break-like) command created more
638 than one breakpoint, then the difference between BREAKPOINT_COUNT
639 and PREV_BREAKPOINT_COUNT is more than one. */
640 static int prev_breakpoint_count
;
642 /* Number of last tracepoint made. */
644 static int tracepoint_count
;
646 static struct cmd_list_element
*breakpoint_set_cmdlist
;
647 static struct cmd_list_element
*breakpoint_show_cmdlist
;
648 struct cmd_list_element
*save_cmdlist
;
650 /* Return whether a breakpoint is an active enabled breakpoint. */
652 breakpoint_enabled (struct breakpoint
*b
)
654 return (b
->enable_state
== bp_enabled
);
657 /* Set breakpoint count to NUM. */
660 set_breakpoint_count (int num
)
662 prev_breakpoint_count
= breakpoint_count
;
663 breakpoint_count
= num
;
664 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
667 /* Used by `start_rbreak_breakpoints' below, to record the current
668 breakpoint count before "rbreak" creates any breakpoint. */
669 static int rbreak_start_breakpoint_count
;
671 /* Called at the start an "rbreak" command to record the first
674 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
676 rbreak_start_breakpoint_count
= breakpoint_count
;
679 /* Called at the end of an "rbreak" command to record the last
682 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
684 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
687 /* Used in run_command to zero the hit count when a new run starts. */
690 clear_breakpoint_hit_counts (void)
692 for (breakpoint
*b
: all_breakpoints ())
697 /* Return the breakpoint with the specified number, or NULL
698 if the number does not refer to an existing breakpoint. */
701 get_breakpoint (int num
)
703 for (breakpoint
*b
: all_breakpoints ())
704 if (b
->number
== num
)
712 /* Mark locations as "conditions have changed" in case the target supports
713 evaluating conditions on its side. */
716 mark_breakpoint_modified (struct breakpoint
*b
)
718 /* This is only meaningful if the target is
719 evaluating conditions and if the user has
720 opted for condition evaluation on the target's
722 if (gdb_evaluates_breakpoint_condition_p ()
723 || !target_supports_evaluation_of_breakpoint_conditions ())
726 if (!is_breakpoint (b
))
729 for (bp_location
*loc
: b
->locations ())
730 loc
->condition_changed
= condition_modified
;
733 /* Mark location as "conditions have changed" in case the target supports
734 evaluating conditions on its side. */
737 mark_breakpoint_location_modified (struct bp_location
*loc
)
739 /* This is only meaningful if the target is
740 evaluating conditions and if the user has
741 opted for condition evaluation on the target's
743 if (gdb_evaluates_breakpoint_condition_p ()
744 || !target_supports_evaluation_of_breakpoint_conditions ())
748 if (!is_breakpoint (loc
->owner
))
751 loc
->condition_changed
= condition_modified
;
754 /* Sets the condition-evaluation mode using the static global
755 condition_evaluation_mode. */
758 set_condition_evaluation_mode (const char *args
, int from_tty
,
759 struct cmd_list_element
*c
)
761 const char *old_mode
, *new_mode
;
763 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
764 && !target_supports_evaluation_of_breakpoint_conditions ())
766 condition_evaluation_mode_1
= condition_evaluation_mode
;
767 warning (_("Target does not support breakpoint condition evaluation.\n"
768 "Using host evaluation mode instead."));
772 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
773 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
775 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
776 settings was "auto". */
777 condition_evaluation_mode
= condition_evaluation_mode_1
;
779 /* Only update the mode if the user picked a different one. */
780 if (new_mode
!= old_mode
)
782 /* If the user switched to a different evaluation mode, we
783 need to synch the changes with the target as follows:
785 "host" -> "target": Send all (valid) conditions to the target.
786 "target" -> "host": Remove all the conditions from the target.
789 if (new_mode
== condition_evaluation_target
)
791 /* Mark everything modified and synch conditions with the
793 for (bp_location
*loc
: all_bp_locations ())
794 mark_breakpoint_location_modified (loc
);
798 /* Manually mark non-duplicate locations to synch conditions
799 with the target. We do this to remove all the conditions the
800 target knows about. */
801 for (bp_location
*loc
: all_bp_locations ())
802 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
803 loc
->needs_update
= 1;
807 update_global_location_list (UGLL_MAY_INSERT
);
813 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
814 what "auto" is translating to. */
817 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
818 struct cmd_list_element
*c
, const char *value
)
820 if (condition_evaluation_mode
== condition_evaluation_auto
)
822 _("Breakpoint condition evaluation "
823 "mode is %s (currently %s).\n"),
825 breakpoint_condition_evaluation_mode ());
827 gdb_printf (file
, _("Breakpoint condition evaluation mode is %s.\n"),
831 /* Parse COND_STRING in the context of LOC and set as the condition
832 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
833 the number of LOC within its owner. In case of parsing error, mark
834 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
837 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
838 int bp_num
, int loc_num
)
840 bool has_junk
= false;
843 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
844 block_for_pc (loc
->address
), 0);
845 if (*cond_string
!= 0)
849 loc
->cond
= std::move (new_exp
);
850 if (loc
->disabled_by_cond
&& loc
->enabled
)
851 gdb_printf (_("Breakpoint %d's condition is now valid at "
852 "location %d, enabling.\n"),
855 loc
->disabled_by_cond
= false;
858 catch (const gdb_exception_error
&e
)
862 /* Warn if a user-enabled location is now becoming disabled-by-cond.
863 BP_NUM is 0 if the breakpoint is being defined for the first
864 time using the "break ... if ..." command, and non-zero if
867 warning (_("failed to validate condition at location %d.%d, "
868 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
870 warning (_("failed to validate condition at location %d, "
871 "disabling:\n %s"), loc_num
, e
.what ());
874 loc
->disabled_by_cond
= true;
878 error (_("Garbage '%s' follows condition"), cond_string
);
882 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
883 int from_tty
, bool force
)
887 b
->cond_string
.reset ();
889 if (is_watchpoint (b
))
890 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
894 for (bp_location
*loc
: b
->locations ())
897 if (loc
->disabled_by_cond
&& loc
->enabled
)
898 gdb_printf (_("Breakpoint %d's condition is now valid at "
899 "location %d, enabling.\n"),
901 loc
->disabled_by_cond
= false;
904 /* No need to free the condition agent expression
905 bytecode (if we have one). We will handle this
906 when we go through update_global_location_list. */
911 gdb_printf (_("Breakpoint %d now unconditional.\n"), b
->number
);
915 if (is_watchpoint (b
))
917 innermost_block_tracker tracker
;
918 const char *arg
= exp
;
919 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
921 error (_("Junk at end of expression"));
922 watchpoint
*w
= static_cast<watchpoint
*> (b
);
923 w
->cond_exp
= std::move (new_exp
);
924 w
->cond_exp_valid_block
= tracker
.block ();
928 /* Parse and set condition expressions. We make two passes.
929 In the first, we parse the condition string to see if it
930 is valid in at least one location. If so, the condition
931 would be accepted. So we go ahead and set the locations'
932 conditions. In case no valid case is found, we throw
933 the error and the condition string will be rejected.
934 This two-pass approach is taken to avoid setting the
935 state of locations in case of a reject. */
936 for (bp_location
*loc
: b
->locations ())
940 const char *arg
= exp
;
941 parse_exp_1 (&arg
, loc
->address
,
942 block_for_pc (loc
->address
), 0);
944 error (_("Junk at end of expression"));
947 catch (const gdb_exception_error
&e
)
949 /* Condition string is invalid. If this happens to
950 be the last loc, abandon (if not forced) or continue
952 if (loc
->next
== nullptr && !force
)
957 /* If we reach here, the condition is valid at some locations. */
959 for (bp_location
*loc
: b
->locations ())
961 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
966 /* We know that the new condition parsed successfully. The
967 condition string of the breakpoint can be safely updated. */
968 b
->cond_string
= make_unique_xstrdup (exp
);
969 b
->condition_not_parsed
= 0;
971 mark_breakpoint_modified (b
);
973 gdb::observers::breakpoint_modified
.notify (b
);
976 /* See breakpoint.h. */
979 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
982 for (breakpoint
*b
: all_breakpoints ())
983 if (b
->number
== bpnum
)
985 /* Check if this breakpoint has a "stop" method implemented in an
986 extension language. This method and conditions entered into GDB
987 from the CLI are mutually exclusive. */
988 const struct extension_language_defn
*extlang
989 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
993 error (_("Only one stop condition allowed. There is currently"
994 " a %s stop condition defined for this breakpoint."),
995 ext_lang_capitalized_name (extlang
));
997 set_breakpoint_condition (b
, exp
, from_tty
, force
);
999 if (is_breakpoint (b
))
1000 update_global_location_list (UGLL_MAY_INSERT
);
1005 error (_("No breakpoint number %d."), bpnum
);
1008 /* The options for the "condition" command. */
1010 struct condition_command_opts
1013 bool force_condition
= false;
1016 static const gdb::option::option_def condition_command_option_defs
[] = {
1018 gdb::option::flag_option_def
<condition_command_opts
> {
1020 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1021 N_("Set the condition even if it is invalid for all current locations."),
1026 /* Create an option_def_group for the "condition" options, with
1027 CC_OPTS as context. */
1029 static inline gdb::option::option_def_group
1030 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1032 return {{condition_command_option_defs
}, cc_opts
};
1035 /* Completion for the "condition" command. */
1038 condition_completer (struct cmd_list_element
*cmd
,
1039 completion_tracker
&tracker
,
1040 const char *text
, const char * /*word*/)
1042 bool has_no_arguments
= (*text
== '\0');
1043 condition_command_opts cc_opts
;
1044 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1045 if (gdb::option::complete_options
1046 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1049 text
= skip_spaces (text
);
1050 const char *space
= skip_to_space (text
);
1057 tracker
.advance_custom_word_point_by (1);
1058 /* We don't support completion of history indices. */
1059 if (!isdigit (text
[1]))
1060 complete_internalvar (tracker
, &text
[1]);
1064 /* Suggest the "-force" flag if no arguments are given. If
1065 arguments were passed, they either already include the flag,
1066 or we are beyond the point of suggesting it because it's
1067 positionally the first argument. */
1068 if (has_no_arguments
)
1069 gdb::option::complete_on_all_options (tracker
, group
);
1071 /* We're completing the breakpoint number. */
1072 len
= strlen (text
);
1074 for (breakpoint
*b
: all_breakpoints ())
1078 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1080 if (strncmp (number
, text
, len
) == 0)
1081 tracker
.add_completion (make_unique_xstrdup (number
));
1087 /* We're completing the expression part. Skip the breakpoint num. */
1088 const char *exp_start
= skip_spaces (space
);
1089 tracker
.advance_custom_word_point_by (exp_start
- text
);
1091 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1092 expression_completer (cmd
, tracker
, text
, word
);
1095 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1098 condition_command (const char *arg
, int from_tty
)
1104 error_no_arg (_("breakpoint number"));
1108 /* Check if the "-force" flag was passed. */
1109 condition_command_opts cc_opts
;
1110 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1111 gdb::option::process_options
1112 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1114 bnum
= get_number (&p
);
1116 error (_("Bad breakpoint argument: '%s'"), arg
);
1118 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1121 /* Check that COMMAND do not contain commands that are suitable
1122 only for tracepoints and not suitable for ordinary breakpoints.
1123 Throw if any such commands is found. */
1126 check_no_tracepoint_commands (struct command_line
*commands
)
1128 struct command_line
*c
;
1130 for (c
= commands
; c
; c
= c
->next
)
1132 if (c
->control_type
== while_stepping_control
)
1133 error (_("The 'while-stepping' command can "
1134 "only be used for tracepoints"));
1136 check_no_tracepoint_commands (c
->body_list_0
.get ());
1137 check_no_tracepoint_commands (c
->body_list_1
.get ());
1139 /* Not that command parsing removes leading whitespace and comment
1140 lines and also empty lines. So, we only need to check for
1141 command directly. */
1142 if (strstr (c
->line
, "collect ") == c
->line
)
1143 error (_("The 'collect' command can only be used for tracepoints"));
1145 if (strstr (c
->line
, "teval ") == c
->line
)
1146 error (_("The 'teval' command can only be used for tracepoints"));
1150 struct longjmp_breakpoint
: public momentary_breakpoint
1152 ~longjmp_breakpoint () override
;
1155 /* Encapsulate tests for different types of tracepoints. */
1158 is_tracepoint_type (bptype type
)
1160 return (type
== bp_tracepoint
1161 || type
== bp_fast_tracepoint
1162 || type
== bp_static_tracepoint
);
1165 /* See breakpoint.h. */
1168 is_tracepoint (const struct breakpoint
*b
)
1170 return is_tracepoint_type (b
->type
);
1173 /* Factory function to create an appropriate instance of breakpoint given
1176 static std::unique_ptr
<breakpoint
>
1177 new_breakpoint_from_type (bptype type
)
1184 case bp_hardware_breakpoint
:
1185 b
= new ordinary_breakpoint ();
1188 case bp_fast_tracepoint
:
1189 case bp_static_tracepoint
:
1191 b
= new tracepoint ();
1195 b
= new dprintf_breakpoint ();
1198 case bp_overlay_event
:
1199 case bp_longjmp_master
:
1200 case bp_std_terminate_master
:
1201 case bp_exception_master
:
1202 case bp_thread_event
:
1204 case bp_shlib_event
:
1205 b
= new internal_breakpoint ();
1210 b
= new longjmp_breakpoint ();
1213 case bp_watchpoint_scope
:
1215 case bp_gnu_ifunc_resolver_return
:
1216 case bp_step_resume
:
1217 case bp_hp_step_resume
:
1218 case bp_longjmp_resume
:
1219 case bp_longjmp_call_dummy
:
1220 case bp_exception_resume
:
1223 case bp_std_terminate
:
1224 b
= new momentary_breakpoint ();
1228 gdb_assert_not_reached ("invalid type");
1231 return std::unique_ptr
<breakpoint
> (b
);
1234 /* A helper function that validates that COMMANDS are valid for a
1235 breakpoint. This function will throw an exception if a problem is
1239 validate_commands_for_breakpoint (struct breakpoint
*b
,
1240 struct command_line
*commands
)
1242 if (is_tracepoint (b
))
1244 struct tracepoint
*t
= (struct tracepoint
*) b
;
1245 struct command_line
*c
;
1246 struct command_line
*while_stepping
= 0;
1248 /* Reset the while-stepping step count. The previous commands
1249 might have included a while-stepping action, while the new
1253 /* We need to verify that each top-level element of commands is
1254 valid for tracepoints, that there's at most one
1255 while-stepping element, and that the while-stepping's body
1256 has valid tracing commands excluding nested while-stepping.
1257 We also need to validate the tracepoint action line in the
1258 context of the tracepoint --- validate_actionline actually
1259 has side effects, like setting the tracepoint's
1260 while-stepping STEP_COUNT, in addition to checking if the
1261 collect/teval actions parse and make sense in the
1262 tracepoint's context. */
1263 for (c
= commands
; c
; c
= c
->next
)
1265 if (c
->control_type
== while_stepping_control
)
1267 if (b
->type
== bp_fast_tracepoint
)
1268 error (_("The 'while-stepping' command "
1269 "cannot be used for fast tracepoint"));
1270 else if (b
->type
== bp_static_tracepoint
)
1271 error (_("The 'while-stepping' command "
1272 "cannot be used for static tracepoint"));
1275 error (_("The 'while-stepping' command "
1276 "can be used only once"));
1281 validate_actionline (c
->line
, b
);
1285 struct command_line
*c2
;
1287 gdb_assert (while_stepping
->body_list_1
== nullptr);
1288 c2
= while_stepping
->body_list_0
.get ();
1289 for (; c2
; c2
= c2
->next
)
1291 if (c2
->control_type
== while_stepping_control
)
1292 error (_("The 'while-stepping' command cannot be nested"));
1298 check_no_tracepoint_commands (commands
);
1302 /* Return a vector of all the static tracepoints set at ADDR. The
1303 caller is responsible for releasing the vector. */
1305 std::vector
<breakpoint
*>
1306 static_tracepoints_here (CORE_ADDR addr
)
1308 std::vector
<breakpoint
*> found
;
1310 for (breakpoint
*b
: all_breakpoints ())
1311 if (b
->type
== bp_static_tracepoint
)
1313 for (bp_location
*loc
: b
->locations ())
1314 if (loc
->address
== addr
)
1315 found
.push_back (b
);
1321 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1322 validate that only allowed commands are included. */
1325 breakpoint_set_commands (struct breakpoint
*b
,
1326 counted_command_line
&&commands
)
1328 validate_commands_for_breakpoint (b
, commands
.get ());
1330 b
->commands
= std::move (commands
);
1331 gdb::observers::breakpoint_modified
.notify (b
);
1334 /* Set the internal `silent' flag on the breakpoint. Note that this
1335 is not the same as the "silent" that may appear in the breakpoint's
1339 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1341 int old_silent
= b
->silent
;
1344 if (old_silent
!= silent
)
1345 gdb::observers::breakpoint_modified
.notify (b
);
1348 /* Set the thread for this breakpoint. If THREAD is -1, make the
1349 breakpoint work for any thread. */
1352 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1354 int old_thread
= b
->thread
;
1357 if (old_thread
!= thread
)
1358 gdb::observers::breakpoint_modified
.notify (b
);
1361 /* Set the task for this breakpoint. If TASK is 0, make the
1362 breakpoint work for any task. */
1365 breakpoint_set_task (struct breakpoint
*b
, int task
)
1367 int old_task
= b
->task
;
1370 if (old_task
!= task
)
1371 gdb::observers::breakpoint_modified
.notify (b
);
1375 commands_command_1 (const char *arg
, int from_tty
,
1376 struct command_line
*control
)
1378 counted_command_line cmd
;
1379 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1380 NULL after the call to read_command_lines if the user provides an empty
1381 list of command by just typing "end". */
1382 bool cmd_read
= false;
1384 std::string new_arg
;
1386 if (arg
== NULL
|| !*arg
)
1388 /* Argument not explicitly given. Synthesize it. */
1389 if (breakpoint_count
- prev_breakpoint_count
> 1)
1390 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1392 else if (breakpoint_count
> 0)
1393 new_arg
= string_printf ("%d", breakpoint_count
);
1397 /* Create a copy of ARG. This is needed because the "commands"
1398 command may be coming from a script. In that case, the read
1399 line buffer is going to be overwritten in the lambda of
1400 'map_breakpoint_numbers' below when reading the next line
1401 before we are are done parsing the breakpoint numbers. */
1404 arg
= new_arg
.c_str ();
1406 map_breakpoint_numbers
1407 (arg
, [&] (breakpoint
*b
)
1411 gdb_assert (cmd
== NULL
);
1412 if (control
!= NULL
)
1413 cmd
= control
->body_list_0
;
1417 = string_printf (_("Type commands for breakpoint(s) "
1418 "%s, one per line."),
1421 auto do_validate
= [=] (const char *line
)
1423 validate_actionline (line
, b
);
1425 gdb::function_view
<void (const char *)> validator
;
1426 if (is_tracepoint (b
))
1427 validator
= do_validate
;
1429 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1434 /* If a breakpoint was on the list more than once, we don't need to
1436 if (b
->commands
!= cmd
)
1438 validate_commands_for_breakpoint (b
, cmd
.get ());
1440 gdb::observers::breakpoint_modified
.notify (b
);
1446 commands_command (const char *arg
, int from_tty
)
1448 commands_command_1 (arg
, from_tty
, NULL
);
1451 /* Like commands_command, but instead of reading the commands from
1452 input stream, takes them from an already parsed command structure.
1454 This is used by cli-script.c to DTRT with breakpoint commands
1455 that are part of if and while bodies. */
1456 enum command_control_type
1457 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1459 commands_command_1 (arg
, 0, cmd
);
1460 return simple_control
;
1463 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1466 bp_location_has_shadow (struct bp_location
*bl
)
1468 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1472 if (bl
->target_info
.shadow_len
== 0)
1473 /* BL isn't valid, or doesn't shadow memory. */
1478 /* Update BUF, which is LEN bytes read from the target address
1479 MEMADDR, by replacing a memory breakpoint with its shadowed
1482 If READBUF is not NULL, this buffer must not overlap with the of
1483 the breakpoint location's shadow_contents buffer. Otherwise, a
1484 failed assertion internal error will be raised. */
1487 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1488 const gdb_byte
*writebuf_org
,
1489 ULONGEST memaddr
, LONGEST len
,
1490 struct bp_target_info
*target_info
,
1491 struct gdbarch
*gdbarch
)
1493 /* Now do full processing of the found relevant range of elements. */
1494 CORE_ADDR bp_addr
= 0;
1498 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1499 current_program_space
->aspace
, 0))
1501 /* The breakpoint is inserted in a different address space. */
1505 /* Addresses and length of the part of the breakpoint that
1507 bp_addr
= target_info
->placed_address
;
1508 bp_size
= target_info
->shadow_len
;
1510 if (bp_addr
+ bp_size
<= memaddr
)
1512 /* The breakpoint is entirely before the chunk of memory we are
1517 if (bp_addr
>= memaddr
+ len
)
1519 /* The breakpoint is entirely after the chunk of memory we are
1524 /* Offset within shadow_contents. */
1525 if (bp_addr
< memaddr
)
1527 /* Only copy the second part of the breakpoint. */
1528 bp_size
-= memaddr
- bp_addr
;
1529 bptoffset
= memaddr
- bp_addr
;
1533 if (bp_addr
+ bp_size
> memaddr
+ len
)
1535 /* Only copy the first part of the breakpoint. */
1536 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1539 if (readbuf
!= NULL
)
1541 /* Verify that the readbuf buffer does not overlap with the
1542 shadow_contents buffer. */
1543 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1544 || readbuf
>= (target_info
->shadow_contents
1545 + target_info
->shadow_len
));
1547 /* Update the read buffer with this inserted breakpoint's
1549 memcpy (readbuf
+ bp_addr
- memaddr
,
1550 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1554 const unsigned char *bp
;
1555 CORE_ADDR addr
= target_info
->reqstd_address
;
1558 /* Update the shadow with what we want to write to memory. */
1559 memcpy (target_info
->shadow_contents
+ bptoffset
,
1560 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1562 /* Determine appropriate breakpoint contents and size for this
1564 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1566 /* Update the final write buffer with this inserted
1567 breakpoint's INSN. */
1568 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1572 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1573 by replacing any memory breakpoints with their shadowed contents.
1575 If READBUF is not NULL, this buffer must not overlap with any of
1576 the breakpoint location's shadow_contents buffers. Otherwise,
1577 a failed assertion internal error will be raised.
1579 The range of shadowed area by each bp_location is:
1580 bl->address - bp_locations_placed_address_before_address_max
1581 up to bl->address + bp_locations_shadow_len_after_address_max
1582 The range we were requested to resolve shadows for is:
1583 memaddr ... memaddr + len
1584 Thus the safe cutoff boundaries for performance optimization are
1585 memaddr + len <= (bl->address
1586 - bp_locations_placed_address_before_address_max)
1588 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1591 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1592 const gdb_byte
*writebuf_org
,
1593 ULONGEST memaddr
, LONGEST len
)
1595 /* Left boundary, right boundary and median element of our binary
1597 unsigned bc_l
, bc_r
, bc
;
1599 /* Find BC_L which is a leftmost element which may affect BUF
1600 content. It is safe to report lower value but a failure to
1601 report higher one. */
1604 bc_r
= bp_locations
.size ();
1605 while (bc_l
+ 1 < bc_r
)
1607 struct bp_location
*bl
;
1609 bc
= (bc_l
+ bc_r
) / 2;
1610 bl
= bp_locations
[bc
];
1612 /* Check first BL->ADDRESS will not overflow due to the added
1613 constant. Then advance the left boundary only if we are sure
1614 the BC element can in no way affect the BUF content (MEMADDR
1615 to MEMADDR + LEN range).
1617 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1618 offset so that we cannot miss a breakpoint with its shadow
1619 range tail still reaching MEMADDR. */
1621 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1623 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1630 /* Due to the binary search above, we need to make sure we pick the
1631 first location that's at BC_L's address. E.g., if there are
1632 multiple locations at the same address, BC_L may end up pointing
1633 at a duplicate location, and miss the "master"/"inserted"
1634 location. Say, given locations L1, L2 and L3 at addresses A and
1637 L1@A, L2@A, L3@B, ...
1639 BC_L could end up pointing at location L2, while the "master"
1640 location could be L1. Since the `loc->inserted' flag is only set
1641 on "master" locations, we'd forget to restore the shadow of L1
1644 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1647 /* Now do full processing of the found relevant range of elements. */
1649 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1651 struct bp_location
*bl
= bp_locations
[bc
];
1653 /* bp_location array has BL->OWNER always non-NULL. */
1654 if (bl
->owner
->type
== bp_none
)
1655 warning (_("reading through apparently deleted breakpoint #%d?"),
1658 /* Performance optimization: any further element can no longer affect BUF
1661 if (bl
->address
>= bp_locations_placed_address_before_address_max
1664 - bp_locations_placed_address_before_address_max
)))
1667 if (!bp_location_has_shadow (bl
))
1670 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1671 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1675 /* See breakpoint.h. */
1678 is_breakpoint (const struct breakpoint
*bpt
)
1680 return (bpt
->type
== bp_breakpoint
1681 || bpt
->type
== bp_hardware_breakpoint
1682 || bpt
->type
== bp_dprintf
);
1685 /* Return true if BPT is of any hardware watchpoint kind. */
1688 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1690 return (bpt
->type
== bp_hardware_watchpoint
1691 || bpt
->type
== bp_read_watchpoint
1692 || bpt
->type
== bp_access_watchpoint
);
1695 /* See breakpoint.h. */
1698 is_watchpoint (const struct breakpoint
*bpt
)
1700 return (is_hardware_watchpoint (bpt
)
1701 || bpt
->type
== bp_watchpoint
);
1704 /* Returns true if the current thread and its running state are safe
1705 to evaluate or update watchpoint B. Watchpoints on local
1706 expressions need to be evaluated in the context of the thread that
1707 was current when the watchpoint was created, and, that thread needs
1708 to be stopped to be able to select the correct frame context.
1709 Watchpoints on global expressions can be evaluated on any thread,
1710 and in any state. It is presently left to the target allowing
1711 memory accesses when threads are running. */
1714 watchpoint_in_thread_scope (struct watchpoint
*b
)
1716 return (b
->pspace
== current_program_space
1717 && (b
->watchpoint_thread
== null_ptid
1718 || (inferior_ptid
== b
->watchpoint_thread
1719 && !inferior_thread ()->executing ())));
1722 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1723 associated bp_watchpoint_scope breakpoint. */
1726 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1728 if (w
->related_breakpoint
!= w
)
1730 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1731 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1732 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1733 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1734 w
->related_breakpoint
= w
;
1736 w
->disposition
= disp_del_at_next_stop
;
1739 /* Extract a bitfield value from value VAL using the bit parameters contained in
1742 static struct value
*
1743 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1745 struct value
*bit_val
;
1750 bit_val
= allocate_value (value_type (val
));
1752 unpack_value_bitfield (bit_val
,
1755 value_contents_for_printing (val
).data (),
1762 /* Allocate a dummy location and add it to B, which must be a software
1763 watchpoint. This is required because even if a software watchpoint
1764 is not watching any memory, bpstat_stop_status requires a location
1765 to be able to report stops. */
1768 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1769 struct program_space
*pspace
)
1771 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1773 b
->loc
= allocate_bp_location (b
);
1774 b
->loc
->pspace
= pspace
;
1775 b
->loc
->address
= -1;
1776 b
->loc
->length
= -1;
1779 /* Returns true if B is a software watchpoint that is not watching any
1780 memory (e.g., "watch $pc"). */
1783 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1785 return (b
->type
== bp_watchpoint
1787 && b
->loc
->next
== NULL
1788 && b
->loc
->address
== -1
1789 && b
->loc
->length
== -1);
1792 /* Assuming that B is a watchpoint:
1793 - Reparse watchpoint expression, if REPARSE is non-zero
1794 - Evaluate expression and store the result in B->val
1795 - Evaluate the condition if there is one, and store the result
1797 - Update the list of values that must be watched in B->loc.
1799 If the watchpoint disposition is disp_del_at_next_stop, then do
1800 nothing. If this is local watchpoint that is out of scope, delete
1803 Even with `set breakpoint always-inserted on' the watchpoints are
1804 removed + inserted on each stop here. Normal breakpoints must
1805 never be removed because they might be missed by a running thread
1806 when debugging in non-stop mode. On the other hand, hardware
1807 watchpoints (is_hardware_watchpoint; processed here) are specific
1808 to each LWP since they are stored in each LWP's hardware debug
1809 registers. Therefore, such LWP must be stopped first in order to
1810 be able to modify its hardware watchpoints.
1812 Hardware watchpoints must be reset exactly once after being
1813 presented to the user. It cannot be done sooner, because it would
1814 reset the data used to present the watchpoint hit to the user. And
1815 it must not be done later because it could display the same single
1816 watchpoint hit during multiple GDB stops. Note that the latter is
1817 relevant only to the hardware watchpoint types bp_read_watchpoint
1818 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1819 not user-visible - its hit is suppressed if the memory content has
1822 The following constraints influence the location where we can reset
1823 hardware watchpoints:
1825 * target_stopped_by_watchpoint and target_stopped_data_address are
1826 called several times when GDB stops.
1829 * Multiple hardware watchpoints can be hit at the same time,
1830 causing GDB to stop. GDB only presents one hardware watchpoint
1831 hit at a time as the reason for stopping, and all the other hits
1832 are presented later, one after the other, each time the user
1833 requests the execution to be resumed. Execution is not resumed
1834 for the threads still having pending hit event stored in
1835 LWP_INFO->STATUS. While the watchpoint is already removed from
1836 the inferior on the first stop the thread hit event is kept being
1837 reported from its cached value by linux_nat_stopped_data_address
1838 until the real thread resume happens after the watchpoint gets
1839 presented and thus its LWP_INFO->STATUS gets reset.
1841 Therefore the hardware watchpoint hit can get safely reset on the
1842 watchpoint removal from inferior. */
1845 update_watchpoint (struct watchpoint
*b
, int reparse
)
1847 int within_current_scope
;
1848 struct frame_id saved_frame_id
;
1851 /* If this is a local watchpoint, we only want to check if the
1852 watchpoint frame is in scope if the current thread is the thread
1853 that was used to create the watchpoint. */
1854 if (!watchpoint_in_thread_scope (b
))
1857 if (b
->disposition
== disp_del_at_next_stop
)
1862 /* Determine if the watchpoint is within scope. */
1863 if (b
->exp_valid_block
== NULL
)
1864 within_current_scope
= 1;
1867 struct frame_info
*fi
= get_current_frame ();
1868 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1869 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1871 /* If we're at a point where the stack has been destroyed
1872 (e.g. in a function epilogue), unwinding may not work
1873 properly. Do not attempt to recreate locations at this
1874 point. See similar comments in watchpoint_check. */
1875 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1878 /* Save the current frame's ID so we can restore it after
1879 evaluating the watchpoint expression on its own frame. */
1880 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1881 took a frame parameter, so that we didn't have to change the
1884 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1886 fi
= frame_find_by_id (b
->watchpoint_frame
);
1887 within_current_scope
= (fi
!= NULL
);
1888 if (within_current_scope
)
1892 /* We don't free locations. They are stored in the bp_location array
1893 and update_global_location_list will eventually delete them and
1894 remove breakpoints if needed. */
1897 if (within_current_scope
&& reparse
)
1902 s
= (b
->exp_string_reparse
1903 ? b
->exp_string_reparse
.get ()
1904 : b
->exp_string
.get ());
1905 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1906 /* If the meaning of expression itself changed, the old value is
1907 no longer relevant. We don't want to report a watchpoint hit
1908 to the user when the old value and the new value may actually
1909 be completely different objects. */
1911 b
->val_valid
= false;
1913 /* Note that unlike with breakpoints, the watchpoint's condition
1914 expression is stored in the breakpoint object, not in the
1915 locations (re)created below. */
1916 if (b
->cond_string
!= NULL
)
1918 b
->cond_exp
.reset ();
1920 s
= b
->cond_string
.get ();
1921 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1925 /* If we failed to parse the expression, for example because
1926 it refers to a global variable in a not-yet-loaded shared library,
1927 don't try to insert watchpoint. We don't automatically delete
1928 such watchpoint, though, since failure to parse expression
1929 is different from out-of-scope watchpoint. */
1930 if (!target_has_execution ())
1932 /* Without execution, memory can't change. No use to try and
1933 set watchpoint locations. The watchpoint will be reset when
1934 the target gains execution, through breakpoint_re_set. */
1935 if (!can_use_hw_watchpoints
)
1937 if (b
->ops
->works_in_software_mode (b
))
1938 b
->type
= bp_watchpoint
;
1940 error (_("Can't set read/access watchpoint when "
1941 "hardware watchpoints are disabled."));
1944 else if (within_current_scope
&& b
->exp
)
1946 std::vector
<value_ref_ptr
> val_chain
;
1947 struct value
*v
, *result
;
1948 struct program_space
*frame_pspace
;
1950 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
1953 /* Avoid setting b->val if it's already set. The meaning of
1954 b->val is 'the last value' user saw, and we should update
1955 it only if we reported that last value to user. As it
1956 happens, the code that reports it updates b->val directly.
1957 We don't keep track of the memory value for masked
1959 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1961 if (b
->val_bitsize
!= 0)
1962 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1963 b
->val
= release_value (v
);
1964 b
->val_valid
= true;
1967 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1969 /* Look at each value on the value chain. */
1970 gdb_assert (!val_chain
.empty ());
1971 for (const value_ref_ptr
&iter
: val_chain
)
1975 /* If it's a memory location, and GDB actually needed
1976 its contents to evaluate the expression, then we
1977 must watch it. If the first value returned is
1978 still lazy, that means an error occurred reading it;
1979 watch it anyway in case it becomes readable. */
1980 if (VALUE_LVAL (v
) == lval_memory
1981 && (v
== val_chain
[0] || ! value_lazy (v
)))
1983 struct type
*vtype
= check_typedef (value_type (v
));
1985 /* We only watch structs and arrays if user asked
1986 for it explicitly, never if they just happen to
1987 appear in the middle of some value chain. */
1989 || (vtype
->code () != TYPE_CODE_STRUCT
1990 && vtype
->code () != TYPE_CODE_ARRAY
))
1993 enum target_hw_bp_type type
;
1994 struct bp_location
*loc
, **tmp
;
1995 int bitpos
= 0, bitsize
= 0;
1997 if (value_bitsize (v
) != 0)
1999 /* Extract the bit parameters out from the bitfield
2001 bitpos
= value_bitpos (v
);
2002 bitsize
= value_bitsize (v
);
2004 else if (v
== result
&& b
->val_bitsize
!= 0)
2006 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2007 lvalue whose bit parameters are saved in the fields
2008 VAL_BITPOS and VAL_BITSIZE. */
2009 bitpos
= b
->val_bitpos
;
2010 bitsize
= b
->val_bitsize
;
2013 addr
= value_address (v
);
2016 /* Skip the bytes that don't contain the bitfield. */
2021 if (b
->type
== bp_read_watchpoint
)
2023 else if (b
->type
== bp_access_watchpoint
)
2026 loc
= allocate_bp_location (b
);
2027 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2030 loc
->gdbarch
= value_type (v
)->arch ();
2032 loc
->pspace
= frame_pspace
;
2033 loc
->address
= address_significant (loc
->gdbarch
, addr
);
2037 /* Just cover the bytes that make up the bitfield. */
2038 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2041 loc
->length
= TYPE_LENGTH (value_type (v
));
2043 loc
->watchpoint_type
= type
;
2048 /* Change the type of breakpoint between hardware assisted or
2049 an ordinary watchpoint depending on the hardware support
2050 and free hardware slots. REPARSE is set when the inferior
2055 enum bp_loc_type loc_type
;
2057 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2061 int i
, target_resources_ok
, other_type_used
;
2064 /* Use an exact watchpoint when there's only one memory region to be
2065 watched, and only one debug register is needed to watch it. */
2066 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2068 /* We need to determine how many resources are already
2069 used for all other hardware watchpoints plus this one
2070 to see if we still have enough resources to also fit
2071 this watchpoint in as well. */
2073 /* If this is a software watchpoint, we try to turn it
2074 to a hardware one -- count resources as if B was of
2075 hardware watchpoint type. */
2077 if (type
== bp_watchpoint
)
2078 type
= bp_hardware_watchpoint
;
2080 /* This watchpoint may or may not have been placed on
2081 the list yet at this point (it won't be in the list
2082 if we're trying to create it for the first time,
2083 through watch_command), so always account for it
2086 /* Count resources used by all watchpoints except B. */
2087 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2089 /* Add in the resources needed for B. */
2090 i
+= hw_watchpoint_use_count (b
);
2093 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2094 if (target_resources_ok
<= 0)
2096 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2098 if (target_resources_ok
== 0 && !sw_mode
)
2099 error (_("Target does not support this type of "
2100 "hardware watchpoint."));
2101 else if (target_resources_ok
< 0 && !sw_mode
)
2102 error (_("There are not enough available hardware "
2103 "resources for this watchpoint."));
2105 /* Downgrade to software watchpoint. */
2106 b
->type
= bp_watchpoint
;
2110 /* If this was a software watchpoint, we've just
2111 found we have enough resources to turn it to a
2112 hardware watchpoint. Otherwise, this is a
2117 else if (!b
->ops
->works_in_software_mode (b
))
2119 if (!can_use_hw_watchpoints
)
2120 error (_("Can't set read/access watchpoint when "
2121 "hardware watchpoints are disabled."));
2123 error (_("Expression cannot be implemented with "
2124 "read/access watchpoint."));
2127 b
->type
= bp_watchpoint
;
2129 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2130 : bp_loc_hardware_watchpoint
);
2131 for (bp_location
*bl
: b
->locations ())
2132 bl
->loc_type
= loc_type
;
2135 /* If a software watchpoint is not watching any memory, then the
2136 above left it without any location set up. But,
2137 bpstat_stop_status requires a location to be able to report
2138 stops, so make sure there's at least a dummy one. */
2139 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2140 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2142 else if (!within_current_scope
)
2145 Watchpoint %d deleted because the program has left the block\n\
2146 in which its expression is valid.\n"),
2148 watchpoint_del_at_next_stop (b
);
2151 /* Restore the selected frame. */
2153 select_frame (frame_find_by_id (saved_frame_id
));
2157 /* Returns 1 iff breakpoint location should be
2158 inserted in the inferior. We don't differentiate the type of BL's owner
2159 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2160 breakpoint_ops is not defined, because in insert_bp_location,
2161 tracepoint's insert_location will not be called. */
2163 should_be_inserted (struct bp_location
*bl
)
2165 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2168 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2171 if (!bl
->enabled
|| bl
->disabled_by_cond
2172 || bl
->shlib_disabled
|| bl
->duplicate
)
2175 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2178 /* This is set for example, when we're attached to the parent of a
2179 vfork, and have detached from the child. The child is running
2180 free, and we expect it to do an exec or exit, at which point the
2181 OS makes the parent schedulable again (and the target reports
2182 that the vfork is done). Until the child is done with the shared
2183 memory region, do not insert breakpoints in the parent, otherwise
2184 the child could still trip on the parent's breakpoints. Since
2185 the parent is blocked anyway, it won't miss any breakpoint. */
2186 if (bl
->pspace
->breakpoints_not_allowed
)
2189 /* Don't insert a breakpoint if we're trying to step past its
2190 location, except if the breakpoint is a single-step breakpoint,
2191 and the breakpoint's thread is the thread which is stepping past
2193 if ((bl
->loc_type
== bp_loc_software_breakpoint
2194 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2195 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2197 /* The single-step breakpoint may be inserted at the location
2198 we're trying to step if the instruction branches to itself.
2199 However, the instruction won't be executed at all and it may
2200 break the semantics of the instruction, for example, the
2201 instruction is a conditional branch or updates some flags.
2202 We can't fix it unless GDB is able to emulate the instruction
2203 or switch to displaced stepping. */
2204 && !(bl
->owner
->type
== bp_single_step
2205 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2207 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2208 paddress (bl
->gdbarch
, bl
->address
));
2212 /* Don't insert watchpoints if we're trying to step past the
2213 instruction that triggered one. */
2214 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2215 && stepping_past_nonsteppable_watchpoint ())
2217 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2218 "skipping watchpoint at %s:%d",
2219 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2226 /* Same as should_be_inserted but does the check assuming
2227 that the location is not duplicated. */
2230 unduplicated_should_be_inserted (struct bp_location
*bl
)
2233 const int save_duplicate
= bl
->duplicate
;
2236 result
= should_be_inserted (bl
);
2237 bl
->duplicate
= save_duplicate
;
2241 /* Parses a conditional described by an expression COND into an
2242 agent expression bytecode suitable for evaluation
2243 by the bytecode interpreter. Return NULL if there was
2244 any error during parsing. */
2246 static agent_expr_up
2247 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2252 agent_expr_up aexpr
;
2254 /* We don't want to stop processing, so catch any errors
2255 that may show up. */
2258 aexpr
= gen_eval_for_expr (scope
, cond
);
2261 catch (const gdb_exception_error
&ex
)
2263 /* If we got here, it means the condition could not be parsed to a valid
2264 bytecode expression and thus can't be evaluated on the target's side.
2265 It's no use iterating through the conditions. */
2268 /* We have a valid agent expression. */
2272 /* Based on location BL, create a list of breakpoint conditions to be
2273 passed on to the target. If we have duplicated locations with different
2274 conditions, we will add such conditions to the list. The idea is that the
2275 target will evaluate the list of conditions and will only notify GDB when
2276 one of them is true. */
2279 build_target_condition_list (struct bp_location
*bl
)
2281 int null_condition_or_parse_error
= 0;
2282 int modified
= bl
->needs_update
;
2284 /* Release conditions left over from a previous insert. */
2285 bl
->target_info
.conditions
.clear ();
2287 /* This is only meaningful if the target is
2288 evaluating conditions and if the user has
2289 opted for condition evaluation on the target's
2291 if (gdb_evaluates_breakpoint_condition_p ()
2292 || !target_supports_evaluation_of_breakpoint_conditions ())
2295 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2297 /* Do a first pass to check for locations with no assigned
2298 conditions or conditions that fail to parse to a valid agent
2299 expression bytecode. If any of these happen, then it's no use to
2300 send conditions to the target since this location will always
2301 trigger and generate a response back to GDB. Note we consider
2302 all locations at the same address irrespective of type, i.e.,
2303 even if the locations aren't considered duplicates (e.g.,
2304 software breakpoint and hardware breakpoint at the same
2306 for (bp_location
*loc
: loc_range
)
2308 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2312 /* Re-parse the conditions since something changed. In that
2313 case we already freed the condition bytecodes (see
2314 force_breakpoint_reinsertion). We just
2315 need to parse the condition to bytecodes again. */
2316 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2320 /* If we have a NULL bytecode expression, it means something
2321 went wrong or we have a null condition expression. */
2322 if (!loc
->cond_bytecode
)
2324 null_condition_or_parse_error
= 1;
2330 /* If any of these happened, it means we will have to evaluate the conditions
2331 for the location's address on gdb's side. It is no use keeping bytecodes
2332 for all the other duplicate locations, thus we free all of them here.
2334 This is so we have a finer control over which locations' conditions are
2335 being evaluated by GDB or the remote stub. */
2336 if (null_condition_or_parse_error
)
2338 for (bp_location
*loc
: loc_range
)
2340 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2342 /* Only go as far as the first NULL bytecode is
2344 if (!loc
->cond_bytecode
)
2347 loc
->cond_bytecode
.reset ();
2352 /* No NULL conditions or failed bytecode generation. Build a
2353 condition list for this location's address. If we have software
2354 and hardware locations at the same address, they aren't
2355 considered duplicates, but we still marge all the conditions
2356 anyway, as it's simpler, and doesn't really make a practical
2358 for (bp_location
*loc
: loc_range
)
2360 && is_breakpoint (loc
->owner
)
2361 && loc
->pspace
->num
== bl
->pspace
->num
2362 && loc
->owner
->enable_state
== bp_enabled
2364 && !loc
->disabled_by_cond
)
2366 /* Add the condition to the vector. This will be used later
2367 to send the conditions to the target. */
2368 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2374 /* Parses a command described by string CMD into an agent expression
2375 bytecode suitable for evaluation by the bytecode interpreter.
2376 Return NULL if there was any error during parsing. */
2378 static agent_expr_up
2379 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2381 const char *cmdrest
;
2382 const char *format_start
, *format_end
;
2383 struct gdbarch
*gdbarch
= get_current_arch ();
2390 if (*cmdrest
== ',')
2392 cmdrest
= skip_spaces (cmdrest
);
2394 if (*cmdrest
++ != '"')
2395 error (_("No format string following the location"));
2397 format_start
= cmdrest
;
2399 format_pieces
fpieces (&cmdrest
);
2401 format_end
= cmdrest
;
2403 if (*cmdrest
++ != '"')
2404 error (_("Bad format string, non-terminated '\"'."));
2406 cmdrest
= skip_spaces (cmdrest
);
2408 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2409 error (_("Invalid argument syntax"));
2411 if (*cmdrest
== ',')
2413 cmdrest
= skip_spaces (cmdrest
);
2415 /* For each argument, make an expression. */
2417 std::vector
<struct expression
*> argvec
;
2418 while (*cmdrest
!= '\0')
2423 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2424 argvec
.push_back (expr
.release ());
2426 if (*cmdrest
== ',')
2430 agent_expr_up aexpr
;
2432 /* We don't want to stop processing, so catch any errors
2433 that may show up. */
2436 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2437 format_start
, format_end
- format_start
,
2438 argvec
.size (), argvec
.data ());
2440 catch (const gdb_exception_error
&ex
)
2442 /* If we got here, it means the command could not be parsed to a valid
2443 bytecode expression and thus can't be evaluated on the target's side.
2444 It's no use iterating through the other commands. */
2447 /* We have a valid agent expression, return it. */
2451 /* Based on location BL, create a list of breakpoint commands to be
2452 passed on to the target. If we have duplicated locations with
2453 different commands, we will add any such to the list. */
2456 build_target_command_list (struct bp_location
*bl
)
2458 int null_command_or_parse_error
= 0;
2459 int modified
= bl
->needs_update
;
2461 /* Clear commands left over from a previous insert. */
2462 bl
->target_info
.tcommands
.clear ();
2464 if (!target_can_run_breakpoint_commands ())
2467 /* For now, limit to agent-style dprintf breakpoints. */
2468 if (dprintf_style
!= dprintf_style_agent
)
2471 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2473 /* For now, if we have any location at the same address that isn't a
2474 dprintf, don't install the target-side commands, as that would
2475 make the breakpoint not be reported to the core, and we'd lose
2477 for (bp_location
*loc
: loc_range
)
2478 if (is_breakpoint (loc
->owner
)
2479 && loc
->pspace
->num
== bl
->pspace
->num
2480 && loc
->owner
->type
!= bp_dprintf
)
2483 /* Do a first pass to check for locations with no assigned
2484 conditions or conditions that fail to parse to a valid agent expression
2485 bytecode. If any of these happen, then it's no use to send conditions
2486 to the target since this location will always trigger and generate a
2487 response back to GDB. */
2488 for (bp_location
*loc
: loc_range
)
2490 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2494 /* Re-parse the commands since something changed. In that
2495 case we already freed the command bytecodes (see
2496 force_breakpoint_reinsertion). We just
2497 need to parse the command to bytecodes again. */
2499 = parse_cmd_to_aexpr (bl
->address
,
2500 loc
->owner
->extra_string
.get ());
2503 /* If we have a NULL bytecode expression, it means something
2504 went wrong or we have a null command expression. */
2505 if (!loc
->cmd_bytecode
)
2507 null_command_or_parse_error
= 1;
2513 /* If anything failed, then we're not doing target-side commands,
2515 if (null_command_or_parse_error
)
2517 for (bp_location
*loc
: loc_range
)
2518 if (is_breakpoint (loc
->owner
)
2519 && loc
->pspace
->num
== bl
->pspace
->num
)
2521 /* Only go as far as the first NULL bytecode is
2523 if (loc
->cmd_bytecode
== NULL
)
2526 loc
->cmd_bytecode
.reset ();
2530 /* No NULL commands or failed bytecode generation. Build a command
2531 list for all duplicate locations at this location's address.
2532 Note that here we must care for whether the breakpoint location
2533 types are considered duplicates, otherwise, say, if we have a
2534 software and hardware location at the same address, the target
2535 could end up running the commands twice. For the moment, we only
2536 support targets-side commands with dprintf, but it doesn't hurt
2537 to be pedantically correct in case that changes. */
2538 for (bp_location
*loc
: loc_range
)
2539 if (breakpoint_locations_match (bl
, loc
)
2540 && loc
->owner
->extra_string
2541 && is_breakpoint (loc
->owner
)
2542 && loc
->pspace
->num
== bl
->pspace
->num
2543 && loc
->owner
->enable_state
== bp_enabled
2545 && !loc
->disabled_by_cond
)
2547 /* Add the command to the vector. This will be used later
2548 to send the commands to the target. */
2549 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2552 bl
->target_info
.persist
= 0;
2553 /* Maybe flag this location as persistent. */
2554 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2555 bl
->target_info
.persist
= 1;
2558 /* Return the kind of breakpoint on address *ADDR. Get the kind
2559 of breakpoint according to ADDR except single-step breakpoint.
2560 Get the kind of single-step breakpoint according to the current
2564 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2566 if (bl
->owner
->type
== bp_single_step
)
2568 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2569 struct regcache
*regcache
;
2571 regcache
= get_thread_regcache (thr
);
2573 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2577 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2580 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2581 location. Any error messages are printed to TMP_ERROR_STREAM; and
2582 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2583 Returns 0 for success, 1 if the bp_location type is not supported or
2586 NOTE drow/2003-09-09: This routine could be broken down to an
2587 object-style method for each breakpoint or catchpoint type. */
2589 insert_bp_location (struct bp_location
*bl
,
2590 struct ui_file
*tmp_error_stream
,
2591 int *disabled_breaks
,
2592 int *hw_breakpoint_error
,
2593 int *hw_bp_error_explained_already
)
2595 gdb_exception bp_excpt
;
2597 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2600 /* Note we don't initialize bl->target_info, as that wipes out
2601 the breakpoint location's shadow_contents if the breakpoint
2602 is still inserted at that location. This in turn breaks
2603 target_read_memory which depends on these buffers when
2604 a memory read is requested at the breakpoint location:
2605 Once the target_info has been wiped, we fail to see that
2606 we have a breakpoint inserted at that address and thus
2607 read the breakpoint instead of returning the data saved in
2608 the breakpoint location's shadow contents. */
2609 bl
->target_info
.reqstd_address
= bl
->address
;
2610 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2611 bl
->target_info
.length
= bl
->length
;
2613 /* When working with target-side conditions, we must pass all the conditions
2614 for the same breakpoint address down to the target since GDB will not
2615 insert those locations. With a list of breakpoint conditions, the target
2616 can decide when to stop and notify GDB. */
2618 if (is_breakpoint (bl
->owner
))
2620 build_target_condition_list (bl
);
2621 build_target_command_list (bl
);
2622 /* Reset the modification marker. */
2623 bl
->needs_update
= 0;
2626 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2627 set at a read-only address, then a breakpoint location will have
2628 been changed to hardware breakpoint before we get here. If it is
2629 "off" however, error out before actually trying to insert the
2630 breakpoint, with a nicer error message. */
2631 if (bl
->loc_type
== bp_loc_software_breakpoint
2632 && !automatic_hardware_breakpoints
)
2634 mem_region
*mr
= lookup_mem_region (bl
->address
);
2636 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2638 gdb_printf (tmp_error_stream
,
2639 _("Cannot insert breakpoint %d.\n"
2640 "Cannot set software breakpoint "
2641 "at read-only address %s\n"),
2643 paddress (bl
->gdbarch
, bl
->address
));
2648 if (bl
->loc_type
== bp_loc_software_breakpoint
2649 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2651 /* First check to see if we have to handle an overlay. */
2652 if (overlay_debugging
== ovly_off
2653 || bl
->section
== NULL
2654 || !(section_is_overlay (bl
->section
)))
2656 /* No overlay handling: just set the breakpoint. */
2661 val
= bl
->owner
->ops
->insert_location (bl
);
2663 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2665 catch (gdb_exception
&e
)
2667 bp_excpt
= std::move (e
);
2672 /* This breakpoint is in an overlay section.
2673 Shall we set a breakpoint at the LMA? */
2674 if (!overlay_events_enabled
)
2676 /* Yes -- overlay event support is not active,
2677 so we must try to set a breakpoint at the LMA.
2678 This will not work for a hardware breakpoint. */
2679 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2680 warning (_("hardware breakpoint %d not supported in overlay!"),
2684 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2686 /* Set a software (trap) breakpoint at the LMA. */
2687 bl
->overlay_target_info
= bl
->target_info
;
2688 bl
->overlay_target_info
.reqstd_address
= addr
;
2690 /* No overlay handling: just set the breakpoint. */
2695 bl
->overlay_target_info
.kind
2696 = breakpoint_kind (bl
, &addr
);
2697 bl
->overlay_target_info
.placed_address
= addr
;
2698 val
= target_insert_breakpoint (bl
->gdbarch
,
2699 &bl
->overlay_target_info
);
2702 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2704 catch (gdb_exception
&e
)
2706 bp_excpt
= std::move (e
);
2709 if (bp_excpt
.reason
!= 0)
2710 gdb_printf (tmp_error_stream
,
2711 "Overlay breakpoint %d "
2712 "failed: in ROM?\n",
2716 /* Shall we set a breakpoint at the VMA? */
2717 if (section_is_mapped (bl
->section
))
2719 /* Yes. This overlay section is mapped into memory. */
2724 val
= bl
->owner
->ops
->insert_location (bl
);
2726 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2728 catch (gdb_exception
&e
)
2730 bp_excpt
= std::move (e
);
2735 /* No. This breakpoint will not be inserted.
2736 No error, but do not mark the bp as 'inserted'. */
2741 if (bp_excpt
.reason
!= 0)
2743 /* Can't set the breakpoint. */
2745 /* If the target has closed then it will have deleted any
2746 breakpoints inserted within the target inferior, as a result
2747 any further attempts to interact with the breakpoint objects
2748 is not possible. Just rethrow the error. */
2749 if (bp_excpt
.error
== TARGET_CLOSE_ERROR
)
2751 gdb_assert (bl
->owner
!= nullptr);
2753 /* In some cases, we might not be able to insert a
2754 breakpoint in a shared library that has already been
2755 removed, but we have not yet processed the shlib unload
2756 event. Unfortunately, some targets that implement
2757 breakpoint insertion themselves can't tell why the
2758 breakpoint insertion failed (e.g., the remote target
2759 doesn't define error codes), so we must treat generic
2760 errors as memory errors. */
2761 if (bp_excpt
.reason
== RETURN_ERROR
2762 && (bp_excpt
.error
== GENERIC_ERROR
2763 || bp_excpt
.error
== MEMORY_ERROR
)
2764 && bl
->loc_type
== bp_loc_software_breakpoint
2765 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2766 || shared_objfile_contains_address_p (bl
->pspace
,
2769 /* See also: disable_breakpoints_in_shlibs. */
2770 bl
->shlib_disabled
= 1;
2771 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2772 if (!*disabled_breaks
)
2774 gdb_printf (tmp_error_stream
,
2775 "Cannot insert breakpoint %d.\n",
2777 gdb_printf (tmp_error_stream
,
2778 "Temporarily disabling shared "
2779 "library breakpoints:\n");
2781 *disabled_breaks
= 1;
2782 gdb_printf (tmp_error_stream
,
2783 "breakpoint #%d\n", bl
->owner
->number
);
2788 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2790 *hw_breakpoint_error
= 1;
2791 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2792 gdb_printf (tmp_error_stream
,
2793 "Cannot insert hardware breakpoint %d%s",
2795 bp_excpt
.message
? ":" : ".\n");
2796 if (bp_excpt
.message
!= NULL
)
2797 gdb_printf (tmp_error_stream
, "%s.\n",
2802 if (bp_excpt
.message
== NULL
)
2805 = memory_error_message (TARGET_XFER_E_IO
,
2806 bl
->gdbarch
, bl
->address
);
2808 gdb_printf (tmp_error_stream
,
2809 "Cannot insert breakpoint %d.\n"
2811 bl
->owner
->number
, message
.c_str ());
2815 gdb_printf (tmp_error_stream
,
2816 "Cannot insert breakpoint %d: %s\n",
2831 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2832 /* NOTE drow/2003-09-08: This state only exists for removing
2833 watchpoints. It's not clear that it's necessary... */
2834 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2838 gdb_assert (bl
->owner
->ops
!= NULL
2839 && bl
->owner
->ops
->insert_location
!= NULL
);
2841 val
= bl
->owner
->ops
->insert_location (bl
);
2843 /* If trying to set a read-watchpoint, and it turns out it's not
2844 supported, try emulating one with an access watchpoint. */
2845 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2847 /* But don't try to insert it, if there's already another
2848 hw_access location that would be considered a duplicate
2850 for (bp_location
*loc
: all_bp_locations ())
2852 && loc
->watchpoint_type
== hw_access
2853 && watchpoint_locations_match (bl
, loc
))
2857 bl
->target_info
= loc
->target_info
;
2858 bl
->watchpoint_type
= hw_access
;
2865 bl
->watchpoint_type
= hw_access
;
2866 val
= bl
->owner
->ops
->insert_location (bl
);
2869 /* Back to the original value. */
2870 bl
->watchpoint_type
= hw_read
;
2874 bl
->inserted
= (val
== 0);
2877 else if (bl
->owner
->type
== bp_catchpoint
)
2881 gdb_assert (bl
->owner
->ops
!= NULL
2882 && bl
->owner
->ops
->insert_location
!= NULL
);
2884 val
= bl
->owner
->ops
->insert_location (bl
);
2887 bl
->owner
->enable_state
= bp_disabled
;
2891 Error inserting catchpoint %d: Your system does not support this type\n\
2892 of catchpoint."), bl
->owner
->number
);
2894 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2897 bl
->inserted
= (val
== 0);
2899 /* We've already printed an error message if there was a problem
2900 inserting this catchpoint, and we've disabled the catchpoint,
2901 so just return success. */
2908 /* This function is called when program space PSPACE is about to be
2909 deleted. It takes care of updating breakpoints to not reference
2913 breakpoint_program_space_exit (struct program_space
*pspace
)
2915 /* Remove any breakpoint that was set through this program space. */
2916 for (breakpoint
*b
: all_breakpoints_safe ())
2917 if (b
->pspace
== pspace
)
2918 delete_breakpoint (b
);
2920 /* Breakpoints set through other program spaces could have locations
2921 bound to PSPACE as well. Remove those. */
2922 for (bp_location
*loc
: all_bp_locations ())
2924 struct bp_location
*tmp
;
2926 if (loc
->pspace
== pspace
)
2928 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2929 if (loc
->owner
->loc
== loc
)
2930 loc
->owner
->loc
= loc
->next
;
2932 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2933 if (tmp
->next
== loc
)
2935 tmp
->next
= loc
->next
;
2941 /* Now update the global location list to permanently delete the
2942 removed locations above. */
2943 update_global_location_list (UGLL_DONT_INSERT
);
2946 /* Make sure all breakpoints are inserted in inferior.
2947 Throws exception on any error.
2948 A breakpoint that is already inserted won't be inserted
2949 again, so calling this function twice is safe. */
2951 insert_breakpoints (void)
2953 for (breakpoint
*bpt
: all_breakpoints ())
2954 if (is_hardware_watchpoint (bpt
))
2956 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2958 update_watchpoint (w
, 0 /* don't reparse. */);
2961 /* Updating watchpoints creates new locations, so update the global
2962 location list. Explicitly tell ugll to insert locations and
2963 ignore breakpoints_always_inserted_mode. Also,
2964 update_global_location_list tries to "upgrade" software
2965 breakpoints to hardware breakpoints to handle "set breakpoint
2966 auto-hw", so we need to call it even if we don't have new
2968 update_global_location_list (UGLL_INSERT
);
2971 /* This is used when we need to synch breakpoint conditions between GDB and the
2972 target. It is the case with deleting and disabling of breakpoints when using
2973 always-inserted mode. */
2976 update_inserted_breakpoint_locations (void)
2980 int disabled_breaks
= 0;
2981 int hw_breakpoint_error
= 0;
2982 int hw_bp_details_reported
= 0;
2984 string_file tmp_error_stream
;
2986 /* Explicitly mark the warning -- this will only be printed if
2987 there was an error. */
2988 tmp_error_stream
.puts ("Warning:\n");
2990 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2992 for (bp_location
*bl
: all_bp_locations ())
2994 /* We only want to update software breakpoints and hardware
2996 if (!is_breakpoint (bl
->owner
))
2999 /* We only want to update locations that are already inserted
3000 and need updating. This is to avoid unwanted insertion during
3001 deletion of breakpoints. */
3002 if (!bl
->inserted
|| !bl
->needs_update
)
3005 switch_to_program_space_and_thread (bl
->pspace
);
3007 /* For targets that support global breakpoints, there's no need
3008 to select an inferior to insert breakpoint to. In fact, even
3009 if we aren't attached to any process yet, we should still
3010 insert breakpoints. */
3011 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3012 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3015 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3016 &hw_breakpoint_error
, &hw_bp_details_reported
);
3023 target_terminal::ours_for_output ();
3024 error_stream (tmp_error_stream
);
3028 /* Used when starting or continuing the program. */
3031 insert_breakpoint_locations (void)
3035 int disabled_breaks
= 0;
3036 int hw_breakpoint_error
= 0;
3037 int hw_bp_error_explained_already
= 0;
3039 string_file tmp_error_stream
;
3041 /* Explicitly mark the warning -- this will only be printed if
3042 there was an error. */
3043 tmp_error_stream
.puts ("Warning:\n");
3045 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3047 for (bp_location
*bl
: all_bp_locations ())
3049 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3052 /* There is no point inserting thread-specific breakpoints if
3053 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3054 has BL->OWNER always non-NULL. */
3055 if (bl
->owner
->thread
!= -1
3056 && !valid_global_thread_id (bl
->owner
->thread
))
3059 switch_to_program_space_and_thread (bl
->pspace
);
3061 /* For targets that support global breakpoints, there's no need
3062 to select an inferior to insert breakpoint to. In fact, even
3063 if we aren't attached to any process yet, we should still
3064 insert breakpoints. */
3065 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3066 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3069 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3070 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3075 /* If we failed to insert all locations of a watchpoint, remove
3076 them, as half-inserted watchpoint is of limited use. */
3077 for (breakpoint
*bpt
: all_breakpoints ())
3079 int some_failed
= 0;
3081 if (!is_hardware_watchpoint (bpt
))
3084 if (!breakpoint_enabled (bpt
))
3087 if (bpt
->disposition
== disp_del_at_next_stop
)
3090 for (bp_location
*loc
: bpt
->locations ())
3091 if (!loc
->inserted
&& should_be_inserted (loc
))
3099 for (bp_location
*loc
: bpt
->locations ())
3101 remove_breakpoint (loc
);
3103 hw_breakpoint_error
= 1;
3104 tmp_error_stream
.printf ("Could not insert "
3105 "hardware watchpoint %d.\n",
3113 /* If a hardware breakpoint or watchpoint was inserted, add a
3114 message about possibly exhausted resources. */
3115 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3117 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3118 You may have requested too many hardware breakpoints/watchpoints.\n");
3120 target_terminal::ours_for_output ();
3121 error_stream (tmp_error_stream
);
3125 /* Used when the program stops.
3126 Returns zero if successful, or non-zero if there was a problem
3127 removing a breakpoint location. */
3130 remove_breakpoints (void)
3134 for (bp_location
*bl
: all_bp_locations ())
3135 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3136 val
|= remove_breakpoint (bl
);
3141 /* When a thread exits, remove breakpoints that are related to
3145 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3147 for (breakpoint
*b
: all_breakpoints_safe ())
3149 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3151 b
->disposition
= disp_del_at_next_stop
;
3154 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3155 b
->number
, print_thread_id (tp
));
3157 /* Hide it from the user. */
3163 /* See breakpoint.h. */
3166 remove_breakpoints_inf (inferior
*inf
)
3170 for (bp_location
*bl
: all_bp_locations ())
3172 if (bl
->pspace
!= inf
->pspace
)
3175 if (bl
->inserted
&& !bl
->target_info
.persist
)
3177 val
= remove_breakpoint (bl
);
3184 static int internal_breakpoint_number
= -1;
3186 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3187 If INTERNAL is non-zero, the breakpoint number will be populated
3188 from internal_breakpoint_number and that variable decremented.
3189 Otherwise the breakpoint number will be populated from
3190 breakpoint_count and that value incremented. Internal breakpoints
3191 do not set the internal var bpnum. */
3193 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3196 b
->number
= internal_breakpoint_number
--;
3199 set_breakpoint_count (breakpoint_count
+ 1);
3200 b
->number
= breakpoint_count
;
3204 static struct breakpoint
*
3205 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3206 CORE_ADDR address
, enum bptype type
,
3207 const struct breakpoint_ops
*ops
)
3209 symtab_and_line sal
;
3211 sal
.section
= find_pc_overlay (sal
.pc
);
3212 sal
.pspace
= current_program_space
;
3214 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3215 b
->number
= internal_breakpoint_number
--;
3216 b
->disposition
= disp_donttouch
;
3221 static const char *const longjmp_names
[] =
3223 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3225 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3227 /* Per-objfile data private to breakpoint.c. */
3228 struct breakpoint_objfile_data
3230 /* Minimal symbol for "_ovly_debug_event" (if any). */
3231 struct bound_minimal_symbol overlay_msym
;
3233 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3234 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3236 /* True if we have looked for longjmp probes. */
3237 int longjmp_searched
= 0;
3239 /* SystemTap probe points for longjmp (if any). These are non-owning
3241 std::vector
<probe
*> longjmp_probes
;
3243 /* Minimal symbol for "std::terminate()" (if any). */
3244 struct bound_minimal_symbol terminate_msym
;
3246 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3247 struct bound_minimal_symbol exception_msym
;
3249 /* True if we have looked for exception probes. */
3250 int exception_searched
= 0;
3252 /* SystemTap probe points for unwinding (if any). These are non-owning
3254 std::vector
<probe
*> exception_probes
;
3257 static const struct objfile_key
<breakpoint_objfile_data
>
3258 breakpoint_objfile_key
;
3260 /* Minimal symbol not found sentinel. */
3261 static struct minimal_symbol msym_not_found
;
3263 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3266 msym_not_found_p (const struct minimal_symbol
*msym
)
3268 return msym
== &msym_not_found
;
3271 /* Return per-objfile data needed by breakpoint.c.
3272 Allocate the data if necessary. */
3274 static struct breakpoint_objfile_data
*
3275 get_breakpoint_objfile_data (struct objfile
*objfile
)
3277 struct breakpoint_objfile_data
*bp_objfile_data
;
3279 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3280 if (bp_objfile_data
== NULL
)
3281 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3282 return bp_objfile_data
;
3286 create_overlay_event_breakpoint (void)
3288 const char *const func_name
= "_ovly_debug_event";
3290 for (objfile
*objfile
: current_program_space
->objfiles ())
3292 struct breakpoint
*b
;
3293 struct breakpoint_objfile_data
*bp_objfile_data
;
3295 struct explicit_location explicit_loc
;
3297 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3299 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3302 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3304 struct bound_minimal_symbol m
;
3306 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3307 if (m
.minsym
== NULL
)
3309 /* Avoid future lookups in this objfile. */
3310 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3313 bp_objfile_data
->overlay_msym
= m
;
3316 addr
= bp_objfile_data
->overlay_msym
.value_address ();
3317 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3319 &internal_breakpoint_ops
);
3320 initialize_explicit_location (&explicit_loc
);
3321 explicit_loc
.function_name
= ASTRDUP (func_name
);
3322 b
->location
= new_explicit_location (&explicit_loc
);
3324 if (overlay_debugging
== ovly_auto
)
3326 b
->enable_state
= bp_enabled
;
3327 overlay_events_enabled
= 1;
3331 b
->enable_state
= bp_disabled
;
3332 overlay_events_enabled
= 0;
3337 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3338 true if a breakpoint was installed. */
3341 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3343 struct gdbarch
*gdbarch
= objfile
->arch ();
3344 struct breakpoint_objfile_data
*bp_objfile_data
3345 = get_breakpoint_objfile_data (objfile
);
3347 if (!bp_objfile_data
->longjmp_searched
)
3349 std::vector
<probe
*> ret
3350 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3354 /* We are only interested in checking one element. */
3357 if (!p
->can_evaluate_arguments ())
3359 /* We cannot use the probe interface here,
3360 because it does not know how to evaluate
3365 bp_objfile_data
->longjmp_probes
= ret
;
3366 bp_objfile_data
->longjmp_searched
= 1;
3369 if (bp_objfile_data
->longjmp_probes
.empty ())
3372 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3374 struct breakpoint
*b
;
3376 b
= create_internal_breakpoint (gdbarch
,
3377 p
->get_relocated_address (objfile
),
3379 &internal_breakpoint_ops
);
3380 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3381 b
->enable_state
= bp_disabled
;
3387 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3388 Return true if at least one breakpoint was installed. */
3391 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3393 struct gdbarch
*gdbarch
= objfile
->arch ();
3394 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3397 struct breakpoint_objfile_data
*bp_objfile_data
3398 = get_breakpoint_objfile_data (objfile
);
3399 unsigned int installed_bp
= 0;
3401 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3403 struct breakpoint
*b
;
3404 const char *func_name
;
3406 struct explicit_location explicit_loc
;
3408 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3411 func_name
= longjmp_names
[i
];
3412 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3414 struct bound_minimal_symbol m
;
3416 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3417 if (m
.minsym
== NULL
)
3419 /* Prevent future lookups in this objfile. */
3420 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3423 bp_objfile_data
->longjmp_msym
[i
] = m
;
3426 addr
= bp_objfile_data
->longjmp_msym
[i
].value_address ();
3427 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3428 &internal_breakpoint_ops
);
3429 initialize_explicit_location (&explicit_loc
);
3430 explicit_loc
.function_name
= ASTRDUP (func_name
);
3431 b
->location
= new_explicit_location (&explicit_loc
);
3432 b
->enable_state
= bp_disabled
;
3436 return installed_bp
> 0;
3439 /* Create a master longjmp breakpoint. */
3442 create_longjmp_master_breakpoint (void)
3444 scoped_restore_current_program_space restore_pspace
;
3446 for (struct program_space
*pspace
: program_spaces
)
3448 set_current_program_space (pspace
);
3450 for (objfile
*obj
: current_program_space
->objfiles ())
3452 /* Skip separate debug object, it's handled in the loop below. */
3453 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3456 /* Try a probe kind breakpoint on main objfile. */
3457 if (create_longjmp_master_breakpoint_probe (obj
))
3460 /* Try longjmp_names kind breakpoints on main and separate_debug
3462 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3463 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3469 /* Create a master std::terminate breakpoint. */
3471 create_std_terminate_master_breakpoint (void)
3473 const char *const func_name
= "std::terminate()";
3475 scoped_restore_current_program_space restore_pspace
;
3477 for (struct program_space
*pspace
: program_spaces
)
3481 set_current_program_space (pspace
);
3483 for (objfile
*objfile
: current_program_space
->objfiles ())
3485 struct breakpoint
*b
;
3486 struct breakpoint_objfile_data
*bp_objfile_data
;
3487 struct explicit_location explicit_loc
;
3489 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3491 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3494 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3496 struct bound_minimal_symbol m
;
3498 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3499 if (m
.minsym
== NULL
|| (m
.minsym
->type () != mst_text
3500 && m
.minsym
->type () != mst_file_text
))
3502 /* Prevent future lookups in this objfile. */
3503 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3506 bp_objfile_data
->terminate_msym
= m
;
3509 addr
= bp_objfile_data
->terminate_msym
.value_address ();
3510 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3511 bp_std_terminate_master
,
3512 &internal_breakpoint_ops
);
3513 initialize_explicit_location (&explicit_loc
);
3514 explicit_loc
.function_name
= ASTRDUP (func_name
);
3515 b
->location
= new_explicit_location (&explicit_loc
);
3516 b
->enable_state
= bp_disabled
;
3521 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3522 probe. Return true if a breakpoint was installed. */
3525 create_exception_master_breakpoint_probe (objfile
*objfile
)
3527 struct breakpoint
*b
;
3528 struct gdbarch
*gdbarch
;
3529 struct breakpoint_objfile_data
*bp_objfile_data
;
3531 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3533 /* We prefer the SystemTap probe point if it exists. */
3534 if (!bp_objfile_data
->exception_searched
)
3536 std::vector
<probe
*> ret
3537 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3541 /* We are only interested in checking one element. */
3544 if (!p
->can_evaluate_arguments ())
3546 /* We cannot use the probe interface here, because it does
3547 not know how to evaluate arguments. */
3551 bp_objfile_data
->exception_probes
= ret
;
3552 bp_objfile_data
->exception_searched
= 1;
3555 if (bp_objfile_data
->exception_probes
.empty ())
3558 gdbarch
= objfile
->arch ();
3560 for (probe
*p
: bp_objfile_data
->exception_probes
)
3562 b
= create_internal_breakpoint (gdbarch
,
3563 p
->get_relocated_address (objfile
),
3564 bp_exception_master
,
3565 &internal_breakpoint_ops
);
3566 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3567 b
->enable_state
= bp_disabled
;
3573 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3574 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3577 create_exception_master_breakpoint_hook (objfile
*objfile
)
3579 const char *const func_name
= "_Unwind_DebugHook";
3580 struct breakpoint
*b
;
3581 struct gdbarch
*gdbarch
;
3582 struct breakpoint_objfile_data
*bp_objfile_data
;
3584 struct explicit_location explicit_loc
;
3586 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3588 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3591 gdbarch
= objfile
->arch ();
3593 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3595 struct bound_minimal_symbol debug_hook
;
3597 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3598 if (debug_hook
.minsym
== NULL
)
3600 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3604 bp_objfile_data
->exception_msym
= debug_hook
;
3607 addr
= bp_objfile_data
->exception_msym
.value_address ();
3608 addr
= gdbarch_convert_from_func_ptr_addr
3609 (gdbarch
, addr
, current_inferior ()->top_target ());
3610 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3611 &internal_breakpoint_ops
);
3612 initialize_explicit_location (&explicit_loc
);
3613 explicit_loc
.function_name
= ASTRDUP (func_name
);
3614 b
->location
= new_explicit_location (&explicit_loc
);
3615 b
->enable_state
= bp_disabled
;
3620 /* Install a master breakpoint on the unwinder's debug hook. */
3623 create_exception_master_breakpoint (void)
3625 for (objfile
*obj
: current_program_space
->objfiles ())
3627 /* Skip separate debug object. */
3628 if (obj
->separate_debug_objfile_backlink
)
3631 /* Try a probe kind breakpoint. */
3632 if (create_exception_master_breakpoint_probe (obj
))
3635 /* Iterate over main and separate debug objects and try an
3636 _Unwind_DebugHook kind breakpoint. */
3637 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3638 if (create_exception_master_breakpoint_hook (debug_objfile
))
3643 /* Does B have a location spec? */
3646 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3648 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3652 update_breakpoints_after_exec (void)
3654 /* We're about to delete breakpoints from GDB's lists. If the
3655 INSERTED flag is true, GDB will try to lift the breakpoints by
3656 writing the breakpoints' "shadow contents" back into memory. The
3657 "shadow contents" are NOT valid after an exec, so GDB should not
3658 do that. Instead, the target is responsible from marking
3659 breakpoints out as soon as it detects an exec. We don't do that
3660 here instead, because there may be other attempts to delete
3661 breakpoints after detecting an exec and before reaching here. */
3662 for (bp_location
*bploc
: all_bp_locations ())
3663 if (bploc
->pspace
== current_program_space
)
3664 gdb_assert (!bploc
->inserted
);
3666 for (breakpoint
*b
: all_breakpoints_safe ())
3668 if (b
->pspace
!= current_program_space
)
3671 /* Solib breakpoints must be explicitly reset after an exec(). */
3672 if (b
->type
== bp_shlib_event
)
3674 delete_breakpoint (b
);
3678 /* JIT breakpoints must be explicitly reset after an exec(). */
3679 if (b
->type
== bp_jit_event
)
3681 delete_breakpoint (b
);
3685 /* Thread event breakpoints must be set anew after an exec(),
3686 as must overlay event and longjmp master breakpoints. */
3687 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3688 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3689 || b
->type
== bp_exception_master
)
3691 delete_breakpoint (b
);
3695 /* Step-resume breakpoints are meaningless after an exec(). */
3696 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3698 delete_breakpoint (b
);
3702 /* Just like single-step breakpoints. */
3703 if (b
->type
== bp_single_step
)
3705 delete_breakpoint (b
);
3709 /* Longjmp and longjmp-resume breakpoints are also meaningless
3711 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3712 || b
->type
== bp_longjmp_call_dummy
3713 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3715 delete_breakpoint (b
);
3719 if (b
->type
== bp_catchpoint
)
3721 /* For now, none of the bp_catchpoint breakpoints need to
3722 do anything at this point. In the future, if some of
3723 the catchpoints need to something, we will need to add
3724 a new method, and call this method from here. */
3728 /* bp_finish is a special case. The only way we ought to be able
3729 to see one of these when an exec() has happened, is if the user
3730 caught a vfork, and then said "finish". Ordinarily a finish just
3731 carries them to the call-site of the current callee, by setting
3732 a temporary bp there and resuming. But in this case, the finish
3733 will carry them entirely through the vfork & exec.
3735 We don't want to allow a bp_finish to remain inserted now. But
3736 we can't safely delete it, 'cause finish_command has a handle to
3737 the bp on a bpstat, and will later want to delete it. There's a
3738 chance (and I've seen it happen) that if we delete the bp_finish
3739 here, that its storage will get reused by the time finish_command
3740 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3741 We really must allow finish_command to delete a bp_finish.
3743 In the absence of a general solution for the "how do we know
3744 it's safe to delete something others may have handles to?"
3745 problem, what we'll do here is just uninsert the bp_finish, and
3746 let finish_command delete it.
3748 (We know the bp_finish is "doomed" in the sense that it's
3749 momentary, and will be deleted as soon as finish_command sees
3750 the inferior stopped. So it doesn't matter that the bp's
3751 address is probably bogus in the new a.out, unlike e.g., the
3752 solib breakpoints.) */
3754 if (b
->type
== bp_finish
)
3759 /* Without a symbolic address, we have little hope of the
3760 pre-exec() address meaning the same thing in the post-exec()
3762 if (breakpoint_event_location_empty_p (b
))
3764 delete_breakpoint (b
);
3771 detach_breakpoints (ptid_t ptid
)
3774 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3775 struct inferior
*inf
= current_inferior ();
3777 if (ptid
.pid () == inferior_ptid
.pid ())
3778 error (_("Cannot detach breakpoints of inferior_ptid"));
3780 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3781 inferior_ptid
= ptid
;
3782 for (bp_location
*bl
: all_bp_locations ())
3784 if (bl
->pspace
!= inf
->pspace
)
3787 /* This function must physically remove breakpoints locations
3788 from the specified ptid, without modifying the breakpoint
3789 package's state. Locations of type bp_loc_other are only
3790 maintained at GDB side. So, there is no need to remove
3791 these bp_loc_other locations. Moreover, removing these
3792 would modify the breakpoint package's state. */
3793 if (bl
->loc_type
== bp_loc_other
)
3797 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3803 /* Remove the breakpoint location BL from the current address space.
3804 Note that this is used to detach breakpoints from a child fork.
3805 When we get here, the child isn't in the inferior list, and neither
3806 do we have objects to represent its address space --- we should
3807 *not* look at bl->pspace->aspace here. */
3810 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3814 /* BL is never in moribund_locations by our callers. */
3815 gdb_assert (bl
->owner
!= NULL
);
3817 /* The type of none suggests that owner is actually deleted.
3818 This should not ever happen. */
3819 gdb_assert (bl
->owner
->type
!= bp_none
);
3821 if (bl
->loc_type
== bp_loc_software_breakpoint
3822 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3824 /* "Normal" instruction breakpoint: either the standard
3825 trap-instruction bp (bp_breakpoint), or a
3826 bp_hardware_breakpoint. */
3828 /* First check to see if we have to handle an overlay. */
3829 if (overlay_debugging
== ovly_off
3830 || bl
->section
== NULL
3831 || !(section_is_overlay (bl
->section
)))
3833 /* No overlay handling: just remove the breakpoint. */
3835 /* If we're trying to uninsert a memory breakpoint that we
3836 know is set in a dynamic object that is marked
3837 shlib_disabled, then either the dynamic object was
3838 removed with "remove-symbol-file" or with
3839 "nosharedlibrary". In the former case, we don't know
3840 whether another dynamic object might have loaded over the
3841 breakpoint's address -- the user might well let us know
3842 about it next with add-symbol-file (the whole point of
3843 add-symbol-file is letting the user manually maintain a
3844 list of dynamically loaded objects). If we have the
3845 breakpoint's shadow memory, that is, this is a software
3846 breakpoint managed by GDB, check whether the breakpoint
3847 is still inserted in memory, to avoid overwriting wrong
3848 code with stale saved shadow contents. Note that HW
3849 breakpoints don't have shadow memory, as they're
3850 implemented using a mechanism that is not dependent on
3851 being able to modify the target's memory, and as such
3852 they should always be removed. */
3853 if (bl
->shlib_disabled
3854 && bl
->target_info
.shadow_len
!= 0
3855 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3858 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3862 /* This breakpoint is in an overlay section.
3863 Did we set a breakpoint at the LMA? */
3864 if (!overlay_events_enabled
)
3866 /* Yes -- overlay event support is not active, so we
3867 should have set a breakpoint at the LMA. Remove it.
3869 /* Ignore any failures: if the LMA is in ROM, we will
3870 have already warned when we failed to insert it. */
3871 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3872 target_remove_hw_breakpoint (bl
->gdbarch
,
3873 &bl
->overlay_target_info
);
3875 target_remove_breakpoint (bl
->gdbarch
,
3876 &bl
->overlay_target_info
,
3879 /* Did we set a breakpoint at the VMA?
3880 If so, we will have marked the breakpoint 'inserted'. */
3883 /* Yes -- remove it. Previously we did not bother to
3884 remove the breakpoint if the section had been
3885 unmapped, but let's not rely on that being safe. We
3886 don't know what the overlay manager might do. */
3888 /* However, we should remove *software* breakpoints only
3889 if the section is still mapped, or else we overwrite
3890 wrong code with the saved shadow contents. */
3891 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3892 || section_is_mapped (bl
->section
))
3893 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3899 /* No -- not inserted, so no need to remove. No error. */
3904 /* In some cases, we might not be able to remove a breakpoint in
3905 a shared library that has already been removed, but we have
3906 not yet processed the shlib unload event. Similarly for an
3907 unloaded add-symbol-file object - the user might not yet have
3908 had the chance to remove-symbol-file it. shlib_disabled will
3909 be set if the library/object has already been removed, but
3910 the breakpoint hasn't been uninserted yet, e.g., after
3911 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3912 always-inserted mode. */
3914 && (bl
->loc_type
== bp_loc_software_breakpoint
3915 && (bl
->shlib_disabled
3916 || solib_name_from_address (bl
->pspace
, bl
->address
)
3917 || shared_objfile_contains_address_p (bl
->pspace
,
3923 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3925 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3927 gdb_assert (bl
->owner
->ops
!= NULL
3928 && bl
->owner
->ops
->remove_location
!= NULL
);
3930 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3931 bl
->owner
->ops
->remove_location (bl
, reason
);
3933 /* Failure to remove any of the hardware watchpoints comes here. */
3934 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3935 warning (_("Could not remove hardware watchpoint %d."),
3938 else if (bl
->owner
->type
== bp_catchpoint
3939 && breakpoint_enabled (bl
->owner
)
3942 gdb_assert (bl
->owner
->ops
!= NULL
3943 && bl
->owner
->ops
->remove_location
!= NULL
);
3945 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3949 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3956 remove_breakpoint (struct bp_location
*bl
)
3958 /* BL is never in moribund_locations by our callers. */
3959 gdb_assert (bl
->owner
!= NULL
);
3961 /* The type of none suggests that owner is actually deleted.
3962 This should not ever happen. */
3963 gdb_assert (bl
->owner
->type
!= bp_none
);
3965 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3967 switch_to_program_space_and_thread (bl
->pspace
);
3969 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3972 /* Clear the "inserted" flag in all breakpoints. */
3975 mark_breakpoints_out (void)
3977 for (bp_location
*bl
: all_bp_locations ())
3978 if (bl
->pspace
== current_program_space
)
3982 /* Clear the "inserted" flag in all breakpoints and delete any
3983 breakpoints which should go away between runs of the program.
3985 Plus other such housekeeping that has to be done for breakpoints
3988 Note: this function gets called at the end of a run (by
3989 generic_mourn_inferior) and when a run begins (by
3990 init_wait_for_inferior). */
3995 breakpoint_init_inferior (enum inf_context context
)
3997 struct program_space
*pspace
= current_program_space
;
3999 /* If breakpoint locations are shared across processes, then there's
4001 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4004 mark_breakpoints_out ();
4006 for (breakpoint
*b
: all_breakpoints_safe ())
4008 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4014 case bp_longjmp_call_dummy
:
4016 /* If the call dummy breakpoint is at the entry point it will
4017 cause problems when the inferior is rerun, so we better get
4020 case bp_watchpoint_scope
:
4022 /* Also get rid of scope breakpoints. */
4024 case bp_shlib_event
:
4026 /* Also remove solib event breakpoints. Their addresses may
4027 have changed since the last time we ran the program.
4028 Actually we may now be debugging against different target;
4029 and so the solib backend that installed this breakpoint may
4030 not be used in by the target. E.g.,
4032 (gdb) file prog-linux
4033 (gdb) run # native linux target
4036 (gdb) file prog-win.exe
4037 (gdb) tar rem :9999 # remote Windows gdbserver.
4040 case bp_step_resume
:
4042 /* Also remove step-resume breakpoints. */
4044 case bp_single_step
:
4046 /* Also remove single-step breakpoints. */
4048 delete_breakpoint (b
);
4052 case bp_hardware_watchpoint
:
4053 case bp_read_watchpoint
:
4054 case bp_access_watchpoint
:
4056 struct watchpoint
*w
= (struct watchpoint
*) b
;
4058 /* Likewise for watchpoints on local expressions. */
4059 if (w
->exp_valid_block
!= NULL
)
4060 delete_breakpoint (b
);
4063 /* Get rid of existing locations, which are no longer
4064 valid. New ones will be created in
4065 update_watchpoint, when the inferior is restarted.
4066 The next update_global_location_list call will
4067 garbage collect them. */
4070 if (context
== inf_starting
)
4072 /* Reset val field to force reread of starting value in
4073 insert_breakpoints. */
4074 w
->val
.reset (nullptr);
4075 w
->val_valid
= false;
4085 /* Get rid of the moribund locations. */
4086 for (bp_location
*bl
: moribund_locations
)
4087 decref_bp_location (&bl
);
4088 moribund_locations
.clear ();
4091 /* These functions concern about actual breakpoints inserted in the
4092 target --- to e.g. check if we need to do decr_pc adjustment or if
4093 we need to hop over the bkpt --- so we check for address space
4094 match, not program space. */
4096 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4097 exists at PC. It returns ordinary_breakpoint_here if it's an
4098 ordinary breakpoint, or permanent_breakpoint_here if it's a
4099 permanent breakpoint.
4100 - When continuing from a location with an ordinary breakpoint, we
4101 actually single step once before calling insert_breakpoints.
4102 - When continuing from a location with a permanent breakpoint, we
4103 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4104 the target, to advance the PC past the breakpoint. */
4106 enum breakpoint_here
4107 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4109 int any_breakpoint_here
= 0;
4111 for (bp_location
*bl
: all_bp_locations ())
4113 if (bl
->loc_type
!= bp_loc_software_breakpoint
4114 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4117 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4118 if ((breakpoint_enabled (bl
->owner
)
4120 && breakpoint_location_address_match (bl
, aspace
, pc
))
4122 if (overlay_debugging
4123 && section_is_overlay (bl
->section
)
4124 && !section_is_mapped (bl
->section
))
4125 continue; /* unmapped overlay -- can't be a match */
4126 else if (bl
->permanent
)
4127 return permanent_breakpoint_here
;
4129 any_breakpoint_here
= 1;
4133 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4136 /* See breakpoint.h. */
4139 breakpoint_in_range_p (const address_space
*aspace
,
4140 CORE_ADDR addr
, ULONGEST len
)
4142 for (bp_location
*bl
: all_bp_locations ())
4144 if (bl
->loc_type
!= bp_loc_software_breakpoint
4145 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4148 if ((breakpoint_enabled (bl
->owner
)
4150 && breakpoint_location_address_range_overlap (bl
, aspace
,
4153 if (overlay_debugging
4154 && section_is_overlay (bl
->section
)
4155 && !section_is_mapped (bl
->section
))
4157 /* Unmapped overlay -- can't be a match. */
4168 /* Return true if there's a moribund breakpoint at PC. */
4171 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4173 for (bp_location
*loc
: moribund_locations
)
4174 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4180 /* Returns non-zero iff BL is inserted at PC, in address space
4184 bp_location_inserted_here_p (struct bp_location
*bl
,
4185 const address_space
*aspace
, CORE_ADDR pc
)
4188 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4191 if (overlay_debugging
4192 && section_is_overlay (bl
->section
)
4193 && !section_is_mapped (bl
->section
))
4194 return 0; /* unmapped overlay -- can't be a match */
4201 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4204 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4206 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4208 if (bl
->loc_type
!= bp_loc_software_breakpoint
4209 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4212 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4218 /* This function returns non-zero iff there is a software breakpoint
4222 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4225 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4227 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4230 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4237 /* See breakpoint.h. */
4240 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4243 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4245 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4248 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4256 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4257 CORE_ADDR addr
, ULONGEST len
)
4259 for (breakpoint
*bpt
: all_breakpoints ())
4261 if (bpt
->type
!= bp_hardware_watchpoint
4262 && bpt
->type
!= bp_access_watchpoint
)
4265 if (!breakpoint_enabled (bpt
))
4268 for (bp_location
*loc
: bpt
->locations ())
4269 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4273 /* Check for intersection. */
4274 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4275 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4283 /* See breakpoint.h. */
4286 is_catchpoint (struct breakpoint
*b
)
4288 return (b
->type
== bp_catchpoint
);
4291 /* Clear a bpstat so that it says we are not at any breakpoint.
4292 Also free any storage that is part of a bpstat. */
4295 bpstat_clear (bpstat
**bsp
)
4312 bpstat::bpstat (const bpstat
&other
)
4314 bp_location_at (other
.bp_location_at
),
4315 breakpoint_at (other
.breakpoint_at
),
4316 commands (other
.commands
),
4317 print (other
.print
),
4319 print_it (other
.print_it
)
4321 if (other
.old_val
!= NULL
)
4322 old_val
= release_value (value_copy (other
.old_val
.get ()));
4325 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4326 is part of the bpstat is copied as well. */
4329 bpstat_copy (bpstat
*bs
)
4331 bpstat
*p
= nullptr;
4333 bpstat
*retval
= nullptr;
4338 for (; bs
!= NULL
; bs
= bs
->next
)
4340 tmp
= new bpstat (*bs
);
4343 /* This is the first thing in the chain. */
4353 /* Find the bpstat associated with this breakpoint. */
4356 bpstat_find_breakpoint (bpstat
*bsp
, struct breakpoint
*breakpoint
)
4361 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4363 if (bsp
->breakpoint_at
== breakpoint
)
4369 /* See breakpoint.h. */
4372 bpstat_explains_signal (bpstat
*bsp
, enum gdb_signal sig
)
4374 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4376 if (bsp
->breakpoint_at
== NULL
)
4378 /* A moribund location can never explain a signal other than
4380 if (sig
== GDB_SIGNAL_TRAP
)
4385 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4394 /* Put in *NUM the breakpoint number of the first breakpoint we are
4395 stopped at. *BSP upon return is a bpstat which points to the
4396 remaining breakpoints stopped at (but which is not guaranteed to be
4397 good for anything but further calls to bpstat_num).
4399 Return 0 if passed a bpstat which does not indicate any breakpoints.
4400 Return -1 if stopped at a breakpoint that has been deleted since
4402 Return 1 otherwise. */
4405 bpstat_num (bpstat
**bsp
, int *num
)
4407 struct breakpoint
*b
;
4410 return 0; /* No more breakpoint values */
4412 /* We assume we'll never have several bpstats that correspond to a
4413 single breakpoint -- otherwise, this function might return the
4414 same number more than once and this will look ugly. */
4415 b
= (*bsp
)->breakpoint_at
;
4416 *bsp
= (*bsp
)->next
;
4418 return -1; /* breakpoint that's been deleted since */
4420 *num
= b
->number
; /* We have its number */
4424 /* See breakpoint.h. */
4427 bpstat_clear_actions (void)
4431 if (inferior_ptid
== null_ptid
)
4434 thread_info
*tp
= inferior_thread ();
4435 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4437 bs
->commands
= NULL
;
4438 bs
->old_val
.reset (nullptr);
4442 /* Called when a command is about to proceed the inferior. */
4445 breakpoint_about_to_proceed (void)
4447 if (inferior_ptid
!= null_ptid
)
4449 struct thread_info
*tp
= inferior_thread ();
4451 /* Allow inferior function calls in breakpoint commands to not
4452 interrupt the command list. When the call finishes
4453 successfully, the inferior will be standing at the same
4454 breakpoint as if nothing happened. */
4455 if (tp
->control
.in_infcall
)
4459 breakpoint_proceeded
= 1;
4462 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4463 or its equivalent. */
4466 command_line_is_silent (struct command_line
*cmd
)
4468 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4471 /* Execute all the commands associated with all the breakpoints at
4472 this location. Any of these commands could cause the process to
4473 proceed beyond this point, etc. We look out for such changes by
4474 checking the global "breakpoint_proceeded" after each command.
4476 Returns true if a breakpoint command resumed the inferior. In that
4477 case, it is the caller's responsibility to recall it again with the
4478 bpstat of the current thread. */
4481 bpstat_do_actions_1 (bpstat
**bsp
)
4486 /* Avoid endless recursion if a `source' command is contained
4488 if (executing_breakpoint_commands
)
4491 scoped_restore save_executing
4492 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4494 scoped_restore preventer
= prevent_dont_repeat ();
4496 /* This pointer will iterate over the list of bpstat's. */
4499 breakpoint_proceeded
= 0;
4500 for (; bs
!= NULL
; bs
= bs
->next
)
4502 struct command_line
*cmd
= NULL
;
4504 /* Take ownership of the BSP's command tree, if it has one.
4506 The command tree could legitimately contain commands like
4507 'step' and 'next', which call clear_proceed_status, which
4508 frees stop_bpstat's command tree. To make sure this doesn't
4509 free the tree we're executing out from under us, we need to
4510 take ownership of the tree ourselves. Since a given bpstat's
4511 commands are only executed once, we don't need to copy it; we
4512 can clear the pointer in the bpstat, and make sure we free
4513 the tree when we're done. */
4514 counted_command_line ccmd
= bs
->commands
;
4515 bs
->commands
= NULL
;
4518 if (command_line_is_silent (cmd
))
4520 /* The action has been already done by bpstat_stop_status. */
4526 execute_control_command (cmd
);
4528 if (breakpoint_proceeded
)
4534 if (breakpoint_proceeded
)
4536 if (current_ui
->async
)
4537 /* If we are in async mode, then the target might be still
4538 running, not stopped at any breakpoint, so nothing for
4539 us to do here -- just return to the event loop. */
4542 /* In sync mode, when execute_control_command returns
4543 we're already standing on the next breakpoint.
4544 Breakpoint commands for that stop were not run, since
4545 execute_command does not run breakpoint commands --
4546 only command_line_handler does, but that one is not
4547 involved in execution of breakpoint commands. So, we
4548 can now execute breakpoint commands. It should be
4549 noted that making execute_command do bpstat actions is
4550 not an option -- in this case we'll have recursive
4551 invocation of bpstat for each breakpoint with a
4552 command, and can easily blow up GDB stack. Instead, we
4553 return true, which will trigger the caller to recall us
4554 with the new stop_bpstat. */
4562 /* Helper for bpstat_do_actions. Get the current thread, if there's
4563 one, is alive and has execution. Return NULL otherwise. */
4565 static thread_info
*
4566 get_bpstat_thread ()
4568 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4571 thread_info
*tp
= inferior_thread ();
4572 if (tp
->state
== THREAD_EXITED
|| tp
->executing ())
4578 bpstat_do_actions (void)
4580 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4583 /* Do any commands attached to breakpoint we are stopped at. */
4584 while ((tp
= get_bpstat_thread ()) != NULL
)
4586 /* Since in sync mode, bpstat_do_actions may resume the
4587 inferior, and only return when it is stopped at the next
4588 breakpoint, we keep doing breakpoint actions until it returns
4589 false to indicate the inferior was not resumed. */
4590 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4594 cleanup_if_error
.release ();
4597 /* Print out the (old or new) value associated with a watchpoint. */
4600 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4603 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4606 struct value_print_options opts
;
4607 get_user_print_options (&opts
);
4608 value_print (val
, stream
, &opts
);
4612 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4613 debugging multiple threads. */
4616 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4618 if (uiout
->is_mi_like_p ())
4623 if (show_thread_that_caused_stop ())
4625 struct thread_info
*thr
= inferior_thread ();
4627 uiout
->text ("Thread ");
4628 uiout
->field_string ("thread-id", print_thread_id (thr
));
4630 const char *name
= thread_name (thr
);
4633 uiout
->text (" \"");
4634 uiout
->field_string ("name", name
);
4638 uiout
->text (" hit ");
4642 /* Generic routine for printing messages indicating why we
4643 stopped. The behavior of this function depends on the value
4644 'print_it' in the bpstat structure. Under some circumstances we
4645 may decide not to print anything here and delegate the task to
4648 static enum print_stop_action
4649 print_bp_stop_message (bpstat
*bs
)
4651 switch (bs
->print_it
)
4654 /* Nothing should be printed for this bpstat entry. */
4655 return PRINT_UNKNOWN
;
4659 /* We still want to print the frame, but we already printed the
4660 relevant messages. */
4661 return PRINT_SRC_AND_LOC
;
4664 case print_it_normal
:
4666 struct breakpoint
*b
= bs
->breakpoint_at
;
4668 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4669 which has since been deleted. */
4671 return PRINT_UNKNOWN
;
4673 /* Normal case. Call the breakpoint's print_it method. */
4674 return b
->ops
->print_it (bs
);
4679 internal_error (__FILE__
, __LINE__
,
4680 _("print_bp_stop_message: unrecognized enum value"));
4685 /* See breakpoint.h. */
4688 print_solib_event (bool is_catchpoint
)
4690 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4691 bool any_added
= !current_program_space
->added_solibs
.empty ();
4695 if (any_added
|| any_deleted
)
4696 current_uiout
->text (_("Stopped due to shared library event:\n"));
4698 current_uiout
->text (_("Stopped due to shared library event (no "
4699 "libraries added or removed)\n"));
4702 if (current_uiout
->is_mi_like_p ())
4703 current_uiout
->field_string ("reason",
4704 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4708 current_uiout
->text (_(" Inferior unloaded "));
4709 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4710 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4712 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4715 current_uiout
->text (" ");
4716 current_uiout
->field_string ("library", name
);
4717 current_uiout
->text ("\n");
4723 current_uiout
->text (_(" Inferior loaded "));
4724 ui_out_emit_list
list_emitter (current_uiout
, "added");
4726 for (so_list
*iter
: current_program_space
->added_solibs
)
4729 current_uiout
->text (" ");
4731 current_uiout
->field_string ("library", iter
->so_name
);
4732 current_uiout
->text ("\n");
4737 /* Print a message indicating what happened. This is called from
4738 normal_stop(). The input to this routine is the head of the bpstat
4739 list - a list of the eventpoints that caused this stop. KIND is
4740 the target_waitkind for the stopping event. This
4741 routine calls the generic print routine for printing a message
4742 about reasons for stopping. This will print (for example) the
4743 "Breakpoint n," part of the output. The return value of this
4746 PRINT_UNKNOWN: Means we printed nothing.
4747 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4748 code to print the location. An example is
4749 "Breakpoint 1, " which should be followed by
4751 PRINT_SRC_ONLY: Means we printed something, but there is no need
4752 to also print the location part of the message.
4753 An example is the catch/throw messages, which
4754 don't require a location appended to the end.
4755 PRINT_NOTHING: We have done some printing and we don't need any
4756 further info to be printed. */
4758 enum print_stop_action
4759 bpstat_print (bpstat
*bs
, int kind
)
4761 enum print_stop_action val
;
4763 /* Maybe another breakpoint in the chain caused us to stop.
4764 (Currently all watchpoints go on the bpstat whether hit or not.
4765 That probably could (should) be changed, provided care is taken
4766 with respect to bpstat_explains_signal). */
4767 for (; bs
; bs
= bs
->next
)
4769 val
= print_bp_stop_message (bs
);
4770 if (val
== PRINT_SRC_ONLY
4771 || val
== PRINT_SRC_AND_LOC
4772 || val
== PRINT_NOTHING
)
4776 /* If we had hit a shared library event breakpoint,
4777 print_bp_stop_message would print out this message. If we hit an
4778 OS-level shared library event, do the same thing. */
4779 if (kind
== TARGET_WAITKIND_LOADED
)
4781 print_solib_event (false);
4782 return PRINT_NOTHING
;
4785 /* We reached the end of the chain, or we got a null BS to start
4786 with and nothing was printed. */
4787 return PRINT_UNKNOWN
;
4790 /* Evaluate the boolean expression EXP and return the result. */
4793 breakpoint_cond_eval (expression
*exp
)
4795 struct value
*mark
= value_mark ();
4796 bool res
= value_true (evaluate_expression (exp
));
4798 value_free_to_mark (mark
);
4802 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4804 bpstat::bpstat (struct bp_location
*bl
, bpstat
***bs_link_pointer
)
4806 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4807 breakpoint_at (bl
->owner
),
4811 print_it (print_it_normal
)
4813 **bs_link_pointer
= this;
4814 *bs_link_pointer
= &next
;
4819 breakpoint_at (NULL
),
4823 print_it (print_it_normal
)
4827 /* The target has stopped with waitstatus WS. Check if any hardware
4828 watchpoints have triggered, according to the target. */
4831 watchpoints_triggered (const target_waitstatus
&ws
)
4833 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4836 if (!stopped_by_watchpoint
)
4838 /* We were not stopped by a watchpoint. Mark all watchpoints
4839 as not triggered. */
4840 for (breakpoint
*b
: all_breakpoints ())
4841 if (is_hardware_watchpoint (b
))
4843 struct watchpoint
*w
= (struct watchpoint
*) b
;
4845 w
->watchpoint_triggered
= watch_triggered_no
;
4851 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4853 /* We were stopped by a watchpoint, but we don't know where.
4854 Mark all watchpoints as unknown. */
4855 for (breakpoint
*b
: all_breakpoints ())
4856 if (is_hardware_watchpoint (b
))
4858 struct watchpoint
*w
= (struct watchpoint
*) b
;
4860 w
->watchpoint_triggered
= watch_triggered_unknown
;
4866 /* The target could report the data address. Mark watchpoints
4867 affected by this data address as triggered, and all others as not
4870 for (breakpoint
*b
: all_breakpoints ())
4871 if (is_hardware_watchpoint (b
))
4873 struct watchpoint
*w
= (struct watchpoint
*) b
;
4875 w
->watchpoint_triggered
= watch_triggered_no
;
4876 for (bp_location
*loc
: b
->locations ())
4878 if (is_masked_watchpoint (b
))
4880 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4881 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4883 if (newaddr
== start
)
4885 w
->watchpoint_triggered
= watch_triggered_yes
;
4889 /* Exact match not required. Within range is sufficient. */
4890 else if (target_watchpoint_addr_within_range
4891 (current_inferior ()->top_target (), addr
, loc
->address
,
4894 w
->watchpoint_triggered
= watch_triggered_yes
;
4903 /* Possible return values for watchpoint_check. */
4904 enum wp_check_result
4906 /* The watchpoint has been deleted. */
4909 /* The value has changed. */
4910 WP_VALUE_CHANGED
= 2,
4912 /* The value has not changed. */
4913 WP_VALUE_NOT_CHANGED
= 3,
4915 /* Ignore this watchpoint, no matter if the value changed or not. */
4919 #define BP_TEMPFLAG 1
4920 #define BP_HARDWAREFLAG 2
4922 /* Evaluate watchpoint condition expression and check if its value
4925 static wp_check_result
4926 watchpoint_check (bpstat
*bs
)
4928 struct watchpoint
*b
;
4929 struct frame_info
*fr
;
4930 int within_current_scope
;
4932 /* BS is built from an existing struct breakpoint. */
4933 gdb_assert (bs
->breakpoint_at
!= NULL
);
4934 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4936 /* If this is a local watchpoint, we only want to check if the
4937 watchpoint frame is in scope if the current thread is the thread
4938 that was used to create the watchpoint. */
4939 if (!watchpoint_in_thread_scope (b
))
4942 if (b
->exp_valid_block
== NULL
)
4943 within_current_scope
= 1;
4946 struct frame_info
*frame
= get_current_frame ();
4947 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4948 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4950 /* stack_frame_destroyed_p() returns a non-zero value if we're
4951 still in the function but the stack frame has already been
4952 invalidated. Since we can't rely on the values of local
4953 variables after the stack has been destroyed, we are treating
4954 the watchpoint in that state as `not changed' without further
4955 checking. Don't mark watchpoints as changed if the current
4956 frame is in an epilogue - even if they are in some other
4957 frame, our view of the stack is likely to be wrong and
4958 frame_find_by_id could error out. */
4959 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4962 fr
= frame_find_by_id (b
->watchpoint_frame
);
4963 within_current_scope
= (fr
!= NULL
);
4965 /* If we've gotten confused in the unwinder, we might have
4966 returned a frame that can't describe this variable. */
4967 if (within_current_scope
)
4969 struct symbol
*function
;
4971 function
= get_frame_function (fr
);
4972 if (function
== NULL
4973 || !contained_in (b
->exp_valid_block
, function
->value_block ()))
4974 within_current_scope
= 0;
4977 if (within_current_scope
)
4978 /* If we end up stopping, the current frame will get selected
4979 in normal_stop. So this call to select_frame won't affect
4984 if (within_current_scope
)
4986 /* We use value_{,free_to_}mark because it could be a *long*
4987 time before we return to the command level and call
4988 free_all_values. We can't call free_all_values because we
4989 might be in the middle of evaluating a function call. */
4992 struct value
*new_val
;
4994 if (is_masked_watchpoint (b
))
4995 /* Since we don't know the exact trigger address (from
4996 stopped_data_address), just tell the user we've triggered
4997 a mask watchpoint. */
4998 return WP_VALUE_CHANGED
;
5000 mark
= value_mark ();
5001 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5004 if (b
->val_bitsize
!= 0)
5005 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5007 /* We use value_equal_contents instead of value_equal because
5008 the latter coerces an array to a pointer, thus comparing just
5009 the address of the array instead of its contents. This is
5010 not what we want. */
5011 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5012 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5015 bs
->old_val
= b
->val
;
5016 b
->val
= release_value (new_val
);
5017 b
->val_valid
= true;
5018 if (new_val
!= NULL
)
5019 value_free_to_mark (mark
);
5020 return WP_VALUE_CHANGED
;
5024 /* Nothing changed. */
5025 value_free_to_mark (mark
);
5026 return WP_VALUE_NOT_CHANGED
;
5031 /* This seems like the only logical thing to do because
5032 if we temporarily ignored the watchpoint, then when
5033 we reenter the block in which it is valid it contains
5034 garbage (in the case of a function, it may have two
5035 garbage values, one before and one after the prologue).
5036 So we can't even detect the first assignment to it and
5037 watch after that (since the garbage may or may not equal
5038 the first value assigned). */
5039 /* We print all the stop information in
5040 breakpoint_ops->print_it, but in this case, by the time we
5041 call breakpoint_ops->print_it this bp will be deleted
5042 already. So we have no choice but print the information
5045 SWITCH_THRU_ALL_UIS ()
5047 struct ui_out
*uiout
= current_uiout
;
5049 if (uiout
->is_mi_like_p ())
5051 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5052 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5053 "left the block in\n"
5054 "which its expression is valid.\n",
5055 signed_field ("wpnum", b
->number
));
5058 /* Make sure the watchpoint's commands aren't executed. */
5060 watchpoint_del_at_next_stop (b
);
5066 /* Return true if it looks like target has stopped due to hitting
5067 breakpoint location BL. This function does not check if we should
5068 stop, only if BL explains the stop. */
5071 bpstat_check_location (const struct bp_location
*bl
,
5072 const address_space
*aspace
, CORE_ADDR bp_addr
,
5073 const target_waitstatus
&ws
)
5075 struct breakpoint
*b
= bl
->owner
;
5077 /* BL is from an existing breakpoint. */
5078 gdb_assert (b
!= NULL
);
5080 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5083 /* Determine if the watched values have actually changed, and we
5084 should stop. If not, set BS->stop to 0. */
5087 bpstat_check_watchpoint (bpstat
*bs
)
5089 const struct bp_location
*bl
;
5090 struct watchpoint
*b
;
5092 /* BS is built for existing struct breakpoint. */
5093 bl
= bs
->bp_location_at
.get ();
5094 gdb_assert (bl
!= NULL
);
5095 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5096 gdb_assert (b
!= NULL
);
5099 int must_check_value
= 0;
5101 if (b
->type
== bp_watchpoint
)
5102 /* For a software watchpoint, we must always check the
5104 must_check_value
= 1;
5105 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5106 /* We have a hardware watchpoint (read, write, or access)
5107 and the target earlier reported an address watched by
5109 must_check_value
= 1;
5110 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5111 && b
->type
== bp_hardware_watchpoint
)
5112 /* We were stopped by a hardware watchpoint, but the target could
5113 not report the data address. We must check the watchpoint's
5114 value. Access and read watchpoints are out of luck; without
5115 a data address, we can't figure it out. */
5116 must_check_value
= 1;
5118 if (must_check_value
)
5124 e
= watchpoint_check (bs
);
5126 catch (const gdb_exception
&ex
)
5128 exception_fprintf (gdb_stderr
, ex
,
5129 "Error evaluating expression "
5130 "for watchpoint %d\n",
5133 SWITCH_THRU_ALL_UIS ()
5135 gdb_printf (_("Watchpoint %d deleted.\n"),
5138 watchpoint_del_at_next_stop (b
);
5145 /* We've already printed what needs to be printed. */
5146 bs
->print_it
= print_it_done
;
5150 bs
->print_it
= print_it_noop
;
5153 case WP_VALUE_CHANGED
:
5154 if (b
->type
== bp_read_watchpoint
)
5156 /* There are two cases to consider here:
5158 1. We're watching the triggered memory for reads.
5159 In that case, trust the target, and always report
5160 the watchpoint hit to the user. Even though
5161 reads don't cause value changes, the value may
5162 have changed since the last time it was read, and
5163 since we're not trapping writes, we will not see
5164 those, and as such we should ignore our notion of
5167 2. We're watching the triggered memory for both
5168 reads and writes. There are two ways this may
5171 2.1. This is a target that can't break on data
5172 reads only, but can break on accesses (reads or
5173 writes), such as e.g., x86. We detect this case
5174 at the time we try to insert read watchpoints.
5176 2.2. Otherwise, the target supports read
5177 watchpoints, but, the user set an access or write
5178 watchpoint watching the same memory as this read
5181 If we're watching memory writes as well as reads,
5182 ignore watchpoint hits when we find that the
5183 value hasn't changed, as reads don't cause
5184 changes. This still gives false positives when
5185 the program writes the same value to memory as
5186 what there was already in memory (we will confuse
5187 it for a read), but it's much better than
5190 int other_write_watchpoint
= 0;
5192 if (bl
->watchpoint_type
== hw_read
)
5194 for (breakpoint
*other_b
: all_breakpoints ())
5195 if (other_b
->type
== bp_hardware_watchpoint
5196 || other_b
->type
== bp_access_watchpoint
)
5198 struct watchpoint
*other_w
=
5199 (struct watchpoint
*) other_b
;
5201 if (other_w
->watchpoint_triggered
5202 == watch_triggered_yes
)
5204 other_write_watchpoint
= 1;
5210 if (other_write_watchpoint
5211 || bl
->watchpoint_type
== hw_access
)
5213 /* We're watching the same memory for writes,
5214 and the value changed since the last time we
5215 updated it, so this trap must be for a write.
5217 bs
->print_it
= print_it_noop
;
5222 case WP_VALUE_NOT_CHANGED
:
5223 if (b
->type
== bp_hardware_watchpoint
5224 || b
->type
== bp_watchpoint
)
5226 /* Don't stop: write watchpoints shouldn't fire if
5227 the value hasn't changed. */
5228 bs
->print_it
= print_it_noop
;
5238 else /* must_check_value == 0 */
5240 /* This is a case where some watchpoint(s) triggered, but
5241 not at the address of this watchpoint, or else no
5242 watchpoint triggered after all. So don't print
5243 anything for this watchpoint. */
5244 bs
->print_it
= print_it_noop
;
5250 /* For breakpoints that are currently marked as telling gdb to stop,
5251 check conditions (condition proper, frame, thread and ignore count)
5252 of breakpoint referred to by BS. If we should not stop for this
5253 breakpoint, set BS->stop to 0. */
5256 bpstat_check_breakpoint_conditions (bpstat
*bs
, thread_info
*thread
)
5258 const struct bp_location
*bl
;
5259 struct breakpoint
*b
;
5261 bool condition_result
= true;
5262 struct expression
*cond
;
5264 gdb_assert (bs
->stop
);
5266 /* BS is built for existing struct breakpoint. */
5267 bl
= bs
->bp_location_at
.get ();
5268 gdb_assert (bl
!= NULL
);
5269 b
= bs
->breakpoint_at
;
5270 gdb_assert (b
!= NULL
);
5272 /* Even if the target evaluated the condition on its end and notified GDB, we
5273 need to do so again since GDB does not know if we stopped due to a
5274 breakpoint or a single step breakpoint. */
5276 if (frame_id_p (b
->frame_id
)
5277 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5283 /* If this is a thread/task-specific breakpoint, don't waste cpu
5284 evaluating the condition if this isn't the specified
5286 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5287 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5293 /* Evaluate extension language breakpoints that have a "stop" method
5295 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5297 if (is_watchpoint (b
))
5299 struct watchpoint
*w
= (struct watchpoint
*) b
;
5301 cond
= w
->cond_exp
.get ();
5304 cond
= bl
->cond
.get ();
5306 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5308 int within_current_scope
= 1;
5309 struct watchpoint
* w
;
5311 /* We use value_mark and value_free_to_mark because it could
5312 be a long time before we return to the command level and
5313 call free_all_values. We can't call free_all_values
5314 because we might be in the middle of evaluating a
5316 struct value
*mark
= value_mark ();
5318 if (is_watchpoint (b
))
5319 w
= (struct watchpoint
*) b
;
5323 /* Need to select the frame, with all that implies so that
5324 the conditions will have the right context. Because we
5325 use the frame, we will not see an inlined function's
5326 variables when we arrive at a breakpoint at the start
5327 of the inlined function; the current frame will be the
5329 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5330 select_frame (get_current_frame ());
5333 struct frame_info
*frame
;
5335 /* For local watchpoint expressions, which particular
5336 instance of a local is being watched matters, so we
5337 keep track of the frame to evaluate the expression
5338 in. To evaluate the condition however, it doesn't
5339 really matter which instantiation of the function
5340 where the condition makes sense triggers the
5341 watchpoint. This allows an expression like "watch
5342 global if q > 10" set in `func', catch writes to
5343 global on all threads that call `func', or catch
5344 writes on all recursive calls of `func' by a single
5345 thread. We simply always evaluate the condition in
5346 the innermost frame that's executing where it makes
5347 sense to evaluate the condition. It seems
5349 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5351 select_frame (frame
);
5353 within_current_scope
= 0;
5355 if (within_current_scope
)
5359 condition_result
= breakpoint_cond_eval (cond
);
5361 catch (const gdb_exception
&ex
)
5363 exception_fprintf (gdb_stderr
, ex
,
5364 "Error in testing breakpoint condition:\n");
5369 warning (_("Watchpoint condition cannot be tested "
5370 "in the current scope"));
5371 /* If we failed to set the right context for this
5372 watchpoint, unconditionally report it. */
5374 /* FIXME-someday, should give breakpoint #. */
5375 value_free_to_mark (mark
);
5378 if (cond
&& !condition_result
)
5382 else if (b
->ignore_count
> 0)
5386 /* Increase the hit count even though we don't stop. */
5388 gdb::observers::breakpoint_modified
.notify (b
);
5392 /* Returns true if we need to track moribund locations of LOC's type
5393 on the current target. */
5396 need_moribund_for_location_type (struct bp_location
*loc
)
5398 return ((loc
->loc_type
== bp_loc_software_breakpoint
5399 && !target_supports_stopped_by_sw_breakpoint ())
5400 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5401 && !target_supports_stopped_by_hw_breakpoint ()));
5404 /* See breakpoint.h. */
5407 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5408 const target_waitstatus
&ws
)
5410 bpstat
*bs_head
= nullptr, **bs_link
= &bs_head
;
5412 for (breakpoint
*b
: all_breakpoints ())
5414 if (!breakpoint_enabled (b
))
5417 for (bp_location
*bl
: b
->locations ())
5419 /* For hardware watchpoints, we look only at the first
5420 location. The watchpoint_check function will work on the
5421 entire expression, not the individual locations. For
5422 read watchpoints, the watchpoints_triggered function has
5423 checked all locations already. */
5424 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5427 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5430 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5433 /* Come here if it's a watchpoint, or if the break address
5436 bpstat
*bs
= new bpstat (bl
, &bs_link
); /* Alloc a bpstat to
5439 /* Assume we stop. Should we find a watchpoint that is not
5440 actually triggered, or if the condition of the breakpoint
5441 evaluates as false, we'll reset 'stop' to 0. */
5445 /* If this is a scope breakpoint, mark the associated
5446 watchpoint as triggered so that we will handle the
5447 out-of-scope event. We'll get to the watchpoint next
5449 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5451 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5453 w
->watchpoint_triggered
= watch_triggered_yes
;
5458 /* Check if a moribund breakpoint explains the stop. */
5459 if (!target_supports_stopped_by_sw_breakpoint ()
5460 || !target_supports_stopped_by_hw_breakpoint ())
5462 for (bp_location
*loc
: moribund_locations
)
5464 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5465 && need_moribund_for_location_type (loc
))
5467 bpstat
*bs
= new bpstat (loc
, &bs_link
);
5468 /* For hits of moribund locations, we should just proceed. */
5471 bs
->print_it
= print_it_noop
;
5479 /* See breakpoint.h. */
5482 bpstat_stop_status (const address_space
*aspace
,
5483 CORE_ADDR bp_addr
, thread_info
*thread
,
5484 const target_waitstatus
&ws
,
5487 struct breakpoint
*b
= NULL
;
5488 /* First item of allocated bpstat's. */
5489 bpstat
*bs_head
= stop_chain
;
5491 int need_remove_insert
;
5494 /* First, build the bpstat chain with locations that explain a
5495 target stop, while being careful to not set the target running,
5496 as that may invalidate locations (in particular watchpoint
5497 locations are recreated). Resuming will happen here with
5498 breakpoint conditions or watchpoint expressions that include
5499 inferior function calls. */
5500 if (bs_head
== NULL
)
5501 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5503 /* A bit of special processing for shlib breakpoints. We need to
5504 process solib loading here, so that the lists of loaded and
5505 unloaded libraries are correct before we handle "catch load" and
5507 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5509 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5511 handle_solib_event ();
5516 /* Now go through the locations that caused the target to stop, and
5517 check whether we're interested in reporting this stop to higher
5518 layers, or whether we should resume the target transparently. */
5522 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5527 b
= bs
->breakpoint_at
;
5528 b
->ops
->check_status (bs
);
5531 bpstat_check_breakpoint_conditions (bs
, thread
);
5537 /* We will stop here. */
5538 if (b
->disposition
== disp_disable
)
5540 --(b
->enable_count
);
5541 if (b
->enable_count
<= 0)
5542 b
->enable_state
= bp_disabled
;
5545 gdb::observers::breakpoint_modified
.notify (b
);
5548 bs
->commands
= b
->commands
;
5549 if (command_line_is_silent (bs
->commands
5550 ? bs
->commands
.get () : NULL
))
5553 b
->ops
->after_condition_true (bs
);
5558 /* Print nothing for this entry if we don't stop or don't
5560 if (!bs
->stop
|| !bs
->print
)
5561 bs
->print_it
= print_it_noop
;
5564 /* If we aren't stopping, the value of some hardware watchpoint may
5565 not have changed, but the intermediate memory locations we are
5566 watching may have. Don't bother if we're stopping; this will get
5568 need_remove_insert
= 0;
5569 if (! bpstat_causes_stop (bs_head
))
5570 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5572 && bs
->breakpoint_at
5573 && is_hardware_watchpoint (bs
->breakpoint_at
))
5575 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5577 update_watchpoint (w
, 0 /* don't reparse. */);
5578 need_remove_insert
= 1;
5581 if (need_remove_insert
)
5582 update_global_location_list (UGLL_MAY_INSERT
);
5583 else if (removed_any
)
5584 update_global_location_list (UGLL_DONT_INSERT
);
5589 /* See breakpoint.h. */
5592 bpstat_stop_status_nowatch (const address_space
*aspace
, CORE_ADDR bp_addr
,
5593 thread_info
*thread
, const target_waitstatus
&ws
)
5595 gdb_assert (!target_stopped_by_watchpoint ());
5597 /* Clear all watchpoints' 'watchpoint_triggered' value from a
5598 previous stop to avoid confusing bpstat_stop_status. */
5599 watchpoints_triggered (ws
);
5601 return bpstat_stop_status (aspace
, bp_addr
, thread
, ws
);
5605 handle_jit_event (CORE_ADDR address
)
5607 struct gdbarch
*gdbarch
;
5609 infrun_debug_printf ("handling bp_jit_event");
5611 /* Switch terminal for any messages produced by
5612 breakpoint_re_set. */
5613 target_terminal::ours_for_output ();
5615 gdbarch
= get_frame_arch (get_current_frame ());
5616 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5617 thus it is expected that its objectfile can be found through
5618 minimal symbol lookup. If it doesn't work (and assert fails), it
5619 most likely means that `jit_breakpoint_re_set` was changes and this
5620 function needs to be updated too. */
5621 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5622 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5623 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5625 target_terminal::inferior ();
5628 /* Prepare WHAT final decision for infrun. */
5630 /* Decide what infrun needs to do with this bpstat. */
5633 bpstat_what (bpstat
*bs_head
)
5635 struct bpstat_what retval
;
5638 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5639 retval
.call_dummy
= STOP_NONE
;
5640 retval
.is_longjmp
= false;
5642 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5644 /* Extract this BS's action. After processing each BS, we check
5645 if its action overrides all we've seem so far. */
5646 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5649 if (bs
->breakpoint_at
== NULL
)
5651 /* I suspect this can happen if it was a momentary
5652 breakpoint which has since been deleted. */
5656 bptype
= bs
->breakpoint_at
->type
;
5663 case bp_hardware_breakpoint
:
5664 case bp_single_step
:
5667 case bp_shlib_event
:
5671 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5673 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5676 this_action
= BPSTAT_WHAT_SINGLE
;
5679 case bp_hardware_watchpoint
:
5680 case bp_read_watchpoint
:
5681 case bp_access_watchpoint
:
5685 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5687 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5691 /* There was a watchpoint, but we're not stopping.
5692 This requires no further action. */
5696 case bp_longjmp_call_dummy
:
5700 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5701 retval
.is_longjmp
= bptype
!= bp_exception
;
5704 this_action
= BPSTAT_WHAT_SINGLE
;
5706 case bp_longjmp_resume
:
5707 case bp_exception_resume
:
5710 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5711 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5714 this_action
= BPSTAT_WHAT_SINGLE
;
5716 case bp_step_resume
:
5718 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5721 /* It is for the wrong frame. */
5722 this_action
= BPSTAT_WHAT_SINGLE
;
5725 case bp_hp_step_resume
:
5727 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5730 /* It is for the wrong frame. */
5731 this_action
= BPSTAT_WHAT_SINGLE
;
5734 case bp_watchpoint_scope
:
5735 case bp_thread_event
:
5736 case bp_overlay_event
:
5737 case bp_longjmp_master
:
5738 case bp_std_terminate_master
:
5739 case bp_exception_master
:
5740 this_action
= BPSTAT_WHAT_SINGLE
;
5746 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5748 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5752 /* Some catchpoints are implemented with breakpoints.
5753 For those, we need to step over the breakpoint. */
5754 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5755 this_action
= BPSTAT_WHAT_SINGLE
;
5759 this_action
= BPSTAT_WHAT_SINGLE
;
5762 /* Make sure the action is stop (silent or noisy),
5763 so infrun.c pops the dummy frame. */
5764 retval
.call_dummy
= STOP_STACK_DUMMY
;
5765 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5767 case bp_std_terminate
:
5768 /* Make sure the action is stop (silent or noisy),
5769 so infrun.c pops the dummy frame. */
5770 retval
.call_dummy
= STOP_STD_TERMINATE
;
5771 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5774 case bp_fast_tracepoint
:
5775 case bp_static_tracepoint
:
5776 /* Tracepoint hits should not be reported back to GDB, and
5777 if one got through somehow, it should have been filtered
5779 internal_error (__FILE__
, __LINE__
,
5780 _("bpstat_what: tracepoint encountered"));
5782 case bp_gnu_ifunc_resolver
:
5783 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5784 this_action
= BPSTAT_WHAT_SINGLE
;
5786 case bp_gnu_ifunc_resolver_return
:
5787 /* The breakpoint will be removed, execution will restart from the
5788 PC of the former breakpoint. */
5789 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5794 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5796 this_action
= BPSTAT_WHAT_SINGLE
;
5800 internal_error (__FILE__
, __LINE__
,
5801 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5804 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5811 bpstat_run_callbacks (bpstat
*bs_head
)
5815 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5817 struct breakpoint
*b
= bs
->breakpoint_at
;
5824 handle_jit_event (bs
->bp_location_at
->address
);
5826 case bp_gnu_ifunc_resolver
:
5827 gnu_ifunc_resolver_stop (b
);
5829 case bp_gnu_ifunc_resolver_return
:
5830 gnu_ifunc_resolver_return_stop (b
);
5836 /* See breakpoint.h. */
5839 bpstat_should_step ()
5841 for (breakpoint
*b
: all_breakpoints ())
5842 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5848 /* See breakpoint.h. */
5851 bpstat_causes_stop (bpstat
*bs
)
5853 for (; bs
!= NULL
; bs
= bs
->next
)
5862 /* Compute a number of spaces suitable to indent the next line
5863 so it starts at the position corresponding to the table column
5864 named COL_NAME in the currently active table of UIOUT. */
5867 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5869 int i
, total_width
, width
, align
;
5873 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5875 if (strcmp (text
, col_name
) == 0)
5878 total_width
+= width
+ 1;
5884 /* Determine if the locations of this breakpoint will have their conditions
5885 evaluated by the target, host or a mix of both. Returns the following:
5887 "host": Host evals condition.
5888 "host or target": Host or Target evals condition.
5889 "target": Target evals condition.
5893 bp_condition_evaluator (struct breakpoint
*b
)
5895 char host_evals
= 0;
5896 char target_evals
= 0;
5901 if (!is_breakpoint (b
))
5904 if (gdb_evaluates_breakpoint_condition_p ()
5905 || !target_supports_evaluation_of_breakpoint_conditions ())
5906 return condition_evaluation_host
;
5908 for (bp_location
*bl
: b
->locations ())
5910 if (bl
->cond_bytecode
)
5916 if (host_evals
&& target_evals
)
5917 return condition_evaluation_both
;
5918 else if (target_evals
)
5919 return condition_evaluation_target
;
5921 return condition_evaluation_host
;
5924 /* Determine the breakpoint location's condition evaluator. This is
5925 similar to bp_condition_evaluator, but for locations. */
5928 bp_location_condition_evaluator (struct bp_location
*bl
)
5930 if (bl
&& !is_breakpoint (bl
->owner
))
5933 if (gdb_evaluates_breakpoint_condition_p ()
5934 || !target_supports_evaluation_of_breakpoint_conditions ())
5935 return condition_evaluation_host
;
5937 if (bl
&& bl
->cond_bytecode
)
5938 return condition_evaluation_target
;
5940 return condition_evaluation_host
;
5943 /* Print the LOC location out of the list of B->LOC locations. */
5946 print_breakpoint_location (struct breakpoint
*b
,
5947 struct bp_location
*loc
)
5949 struct ui_out
*uiout
= current_uiout
;
5951 scoped_restore_current_program_space restore_pspace
;
5953 if (loc
!= NULL
&& loc
->shlib_disabled
)
5957 set_current_program_space (loc
->pspace
);
5959 if (b
->display_canonical
)
5960 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5961 else if (loc
&& loc
->symtab
)
5963 const struct symbol
*sym
= loc
->symbol
;
5967 uiout
->text ("in ");
5968 uiout
->field_string ("func", sym
->print_name (),
5969 function_name_style
.style ());
5971 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5972 uiout
->text ("at ");
5974 uiout
->field_string ("file",
5975 symtab_to_filename_for_display (loc
->symtab
),
5976 file_name_style
.style ());
5979 if (uiout
->is_mi_like_p ())
5980 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5982 uiout
->field_signed ("line", loc
->line_number
);
5988 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5990 uiout
->field_stream ("at", stb
);
5994 uiout
->field_string ("pending",
5995 event_location_to_string (b
->location
.get ()));
5996 /* If extra_string is available, it could be holding a condition
5997 or dprintf arguments. In either case, make sure it is printed,
5998 too, but only for non-MI streams. */
5999 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6001 if (b
->type
== bp_dprintf
)
6005 uiout
->text (b
->extra_string
.get ());
6009 if (loc
&& is_breakpoint (b
)
6010 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6011 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6014 uiout
->field_string ("evaluated-by",
6015 bp_location_condition_evaluator (loc
));
6021 bptype_string (enum bptype type
)
6023 struct ep_type_description
6026 const char *description
;
6028 static struct ep_type_description bptypes
[] =
6030 {bp_none
, "?deleted?"},
6031 {bp_breakpoint
, "breakpoint"},
6032 {bp_hardware_breakpoint
, "hw breakpoint"},
6033 {bp_single_step
, "sw single-step"},
6034 {bp_until
, "until"},
6035 {bp_finish
, "finish"},
6036 {bp_watchpoint
, "watchpoint"},
6037 {bp_hardware_watchpoint
, "hw watchpoint"},
6038 {bp_read_watchpoint
, "read watchpoint"},
6039 {bp_access_watchpoint
, "acc watchpoint"},
6040 {bp_longjmp
, "longjmp"},
6041 {bp_longjmp_resume
, "longjmp resume"},
6042 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6043 {bp_exception
, "exception"},
6044 {bp_exception_resume
, "exception resume"},
6045 {bp_step_resume
, "step resume"},
6046 {bp_hp_step_resume
, "high-priority step resume"},
6047 {bp_watchpoint_scope
, "watchpoint scope"},
6048 {bp_call_dummy
, "call dummy"},
6049 {bp_std_terminate
, "std::terminate"},
6050 {bp_shlib_event
, "shlib events"},
6051 {bp_thread_event
, "thread events"},
6052 {bp_overlay_event
, "overlay events"},
6053 {bp_longjmp_master
, "longjmp master"},
6054 {bp_std_terminate_master
, "std::terminate master"},
6055 {bp_exception_master
, "exception master"},
6056 {bp_catchpoint
, "catchpoint"},
6057 {bp_tracepoint
, "tracepoint"},
6058 {bp_fast_tracepoint
, "fast tracepoint"},
6059 {bp_static_tracepoint
, "static tracepoint"},
6060 {bp_dprintf
, "dprintf"},
6061 {bp_jit_event
, "jit events"},
6062 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6063 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6066 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6067 || ((int) type
!= bptypes
[(int) type
].type
))
6068 internal_error (__FILE__
, __LINE__
,
6069 _("bptypes table does not describe type #%d."),
6072 return bptypes
[(int) type
].description
;
6075 /* For MI, output a field named 'thread-groups' with a list as the value.
6076 For CLI, prefix the list with the string 'inf'. */
6079 output_thread_groups (struct ui_out
*uiout
,
6080 const char *field_name
,
6081 const std::vector
<int> &inf_nums
,
6084 int is_mi
= uiout
->is_mi_like_p ();
6086 /* For backward compatibility, don't display inferiors in CLI unless
6087 there are several. Always display them for MI. */
6088 if (!is_mi
&& mi_only
)
6091 ui_out_emit_list
list_emitter (uiout
, field_name
);
6093 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6099 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6100 uiout
->field_string (NULL
, mi_group
);
6105 uiout
->text (" inf ");
6109 uiout
->text (plongest (inf_nums
[i
]));
6114 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6115 instead of going via breakpoint_ops::print_one. This makes "maint
6116 info breakpoints" show the software breakpoint locations of
6117 catchpoints, which are considered internal implementation
6118 detail. Returns true if RAW_LOC is false and if the breakpoint's
6119 print_one method did something; false otherwise. */
6122 print_one_breakpoint_location (struct breakpoint
*b
,
6123 struct bp_location
*loc
,
6125 struct bp_location
**last_loc
,
6126 int allflag
, bool raw_loc
)
6128 struct command_line
*l
;
6129 static char bpenables
[] = "nynny";
6131 struct ui_out
*uiout
= current_uiout
;
6132 int header_of_multiple
= 0;
6133 int part_of_multiple
= (loc
!= NULL
);
6134 struct value_print_options opts
;
6136 get_user_print_options (&opts
);
6138 gdb_assert (!loc
|| loc_number
!= 0);
6139 /* See comment in print_one_breakpoint concerning treatment of
6140 breakpoints with single disabled location. */
6143 && (b
->loc
->next
!= NULL
6144 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6145 header_of_multiple
= 1;
6153 if (part_of_multiple
)
6154 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6156 uiout
->field_signed ("number", b
->number
);
6160 if (part_of_multiple
)
6161 uiout
->field_skip ("type");
6163 uiout
->field_string ("type", bptype_string (b
->type
));
6167 if (part_of_multiple
)
6168 uiout
->field_skip ("disp");
6170 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6174 /* For locations that are disabled because of an invalid condition,
6175 display "N*" on CLI, where "*" refers to a footnote below the
6176 table. For MI, simply display a "N" without a footnote. */
6177 const char *N
= (uiout
->is_mi_like_p ()) ? "N" : "N*";
6178 if (part_of_multiple
)
6179 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? N
6180 : (loc
->enabled
? "y" : "n")));
6182 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6185 bool result
= false;
6186 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one (b
, last_loc
))
6190 if (is_watchpoint (b
))
6192 struct watchpoint
*w
= (struct watchpoint
*) b
;
6194 /* Field 4, the address, is omitted (which makes the columns
6195 not line up too nicely with the headers, but the effect
6196 is relatively readable). */
6197 if (opts
.addressprint
)
6198 uiout
->field_skip ("addr");
6200 uiout
->field_string ("what", w
->exp_string
.get ());
6202 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6203 || is_ada_exception_catchpoint (b
))
6205 if (opts
.addressprint
)
6208 if (header_of_multiple
)
6209 uiout
->field_string ("addr", "<MULTIPLE>",
6210 metadata_style
.style ());
6211 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6212 uiout
->field_string ("addr", "<PENDING>",
6213 metadata_style
.style ());
6215 uiout
->field_core_addr ("addr",
6216 loc
->gdbarch
, loc
->address
);
6219 if (!header_of_multiple
)
6220 print_breakpoint_location (b
, loc
);
6226 if (loc
!= NULL
&& !header_of_multiple
)
6228 std::vector
<int> inf_nums
;
6231 for (inferior
*inf
: all_inferiors ())
6233 if (inf
->pspace
== loc
->pspace
)
6234 inf_nums
.push_back (inf
->num
);
6237 /* For backward compatibility, don't display inferiors in CLI unless
6238 there are several. Always display for MI. */
6240 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6241 && (program_spaces
.size () > 1
6242 || number_of_inferiors () > 1)
6243 /* LOC is for existing B, it cannot be in
6244 moribund_locations and thus having NULL OWNER. */
6245 && loc
->owner
->type
!= bp_catchpoint
))
6247 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6250 if (!part_of_multiple
)
6252 if (b
->thread
!= -1)
6254 /* FIXME: This seems to be redundant and lost here; see the
6255 "stop only in" line a little further down. */
6256 uiout
->text (" thread ");
6257 uiout
->field_signed ("thread", b
->thread
);
6259 else if (b
->task
!= 0)
6261 uiout
->text (" task ");
6262 uiout
->field_signed ("task", b
->task
);
6268 if (!part_of_multiple
)
6269 b
->ops
->print_one_detail (b
, uiout
);
6271 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6274 uiout
->text ("\tstop only in stack frame at ");
6275 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6277 uiout
->field_core_addr ("frame",
6278 b
->gdbarch
, b
->frame_id
.stack_addr
);
6282 if (!part_of_multiple
&& b
->cond_string
)
6285 if (is_tracepoint (b
))
6286 uiout
->text ("\ttrace only if ");
6288 uiout
->text ("\tstop only if ");
6289 uiout
->field_string ("cond", b
->cond_string
.get ());
6291 /* Print whether the target is doing the breakpoint's condition
6292 evaluation. If GDB is doing the evaluation, don't print anything. */
6293 if (is_breakpoint (b
)
6294 && breakpoint_condition_evaluation_mode ()
6295 == condition_evaluation_target
)
6297 uiout
->message (" (%pF evals)",
6298 string_field ("evaluated-by",
6299 bp_condition_evaluator (b
)));
6304 if (!part_of_multiple
&& b
->thread
!= -1)
6306 /* FIXME should make an annotation for this. */
6307 uiout
->text ("\tstop only in thread ");
6308 if (uiout
->is_mi_like_p ())
6309 uiout
->field_signed ("thread", b
->thread
);
6312 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6314 uiout
->field_string ("thread", print_thread_id (thr
));
6319 if (!part_of_multiple
)
6323 /* FIXME should make an annotation for this. */
6324 if (is_catchpoint (b
))
6325 uiout
->text ("\tcatchpoint");
6326 else if (is_tracepoint (b
))
6327 uiout
->text ("\ttracepoint");
6329 uiout
->text ("\tbreakpoint");
6330 uiout
->text (" already hit ");
6331 uiout
->field_signed ("times", b
->hit_count
);
6332 if (b
->hit_count
== 1)
6333 uiout
->text (" time\n");
6335 uiout
->text (" times\n");
6339 /* Output the count also if it is zero, but only if this is mi. */
6340 if (uiout
->is_mi_like_p ())
6341 uiout
->field_signed ("times", b
->hit_count
);
6345 if (!part_of_multiple
&& b
->ignore_count
)
6348 uiout
->message ("\tignore next %pF hits\n",
6349 signed_field ("ignore", b
->ignore_count
));
6352 /* Note that an enable count of 1 corresponds to "enable once"
6353 behavior, which is reported by the combination of enablement and
6354 disposition, so we don't need to mention it here. */
6355 if (!part_of_multiple
&& b
->enable_count
> 1)
6358 uiout
->text ("\tdisable after ");
6359 /* Tweak the wording to clarify that ignore and enable counts
6360 are distinct, and have additive effect. */
6361 if (b
->ignore_count
)
6362 uiout
->text ("additional ");
6364 uiout
->text ("next ");
6365 uiout
->field_signed ("enable", b
->enable_count
);
6366 uiout
->text (" hits\n");
6369 if (!part_of_multiple
&& is_tracepoint (b
))
6371 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6373 if (tp
->traceframe_usage
)
6375 uiout
->text ("\ttrace buffer usage ");
6376 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6377 uiout
->text (" bytes\n");
6381 l
= b
->commands
? b
->commands
.get () : NULL
;
6382 if (!part_of_multiple
&& l
)
6385 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6386 print_command_lines (uiout
, l
, 4);
6389 if (is_tracepoint (b
))
6391 struct tracepoint
*t
= (struct tracepoint
*) b
;
6393 if (!part_of_multiple
&& t
->pass_count
)
6395 annotate_field (10);
6396 uiout
->text ("\tpass count ");
6397 uiout
->field_signed ("pass", t
->pass_count
);
6398 uiout
->text (" \n");
6401 /* Don't display it when tracepoint or tracepoint location is
6403 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6405 annotate_field (11);
6407 if (uiout
->is_mi_like_p ())
6408 uiout
->field_string ("installed",
6409 loc
->inserted
? "y" : "n");
6415 uiout
->text ("\tnot ");
6416 uiout
->text ("installed on target\n");
6421 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6423 if (is_watchpoint (b
))
6425 struct watchpoint
*w
= (struct watchpoint
*) b
;
6427 uiout
->field_string ("original-location", w
->exp_string
.get ());
6429 else if (b
->location
!= NULL
6430 && event_location_to_string (b
->location
.get ()) != NULL
)
6431 uiout
->field_string ("original-location",
6432 event_location_to_string (b
->location
.get ()));
6438 /* See breakpoint.h. */
6440 bool fix_multi_location_breakpoint_output_globally
= false;
6443 print_one_breakpoint (struct breakpoint
*b
,
6444 struct bp_location
**last_loc
,
6447 struct ui_out
*uiout
= current_uiout
;
6448 bool use_fixed_output
6449 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6450 || fix_multi_location_breakpoint_output_globally
);
6452 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6453 bool printed
= print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
6456 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6458 if (!use_fixed_output
)
6459 bkpt_tuple_emitter
.reset ();
6461 /* If this breakpoint has custom print function,
6462 it's already printed. Otherwise, print individual
6463 locations, if any. */
6464 if (!printed
|| allflag
)
6466 /* If breakpoint has a single location that is disabled, we
6467 print it as if it had several locations, since otherwise it's
6468 hard to represent "breakpoint enabled, location disabled"
6471 Note that while hardware watchpoints have several locations
6472 internally, that's not a property exposed to users.
6474 Likewise, while catchpoints may be implemented with
6475 breakpoints (e.g., catch throw), that's not a property
6476 exposed to users. We do however display the internal
6477 breakpoint locations with "maint info breakpoints". */
6478 if (!is_hardware_watchpoint (b
)
6479 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6480 || is_ada_exception_catchpoint (b
))
6482 || (b
->loc
&& (b
->loc
->next
6484 || b
->loc
->disabled_by_cond
))))
6486 gdb::optional
<ui_out_emit_list
> locations_list
;
6488 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6489 MI record. For later versions, place breakpoint locations in a
6491 if (uiout
->is_mi_like_p () && use_fixed_output
)
6492 locations_list
.emplace (uiout
, "locations");
6495 for (bp_location
*loc
: b
->locations ())
6497 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6498 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6507 breakpoint_address_bits (struct breakpoint
*b
)
6509 int print_address_bits
= 0;
6511 /* Software watchpoints that aren't watching memory don't have an
6512 address to print. */
6513 if (is_no_memory_software_watchpoint (b
))
6516 for (bp_location
*loc
: b
->locations ())
6520 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6521 if (addr_bit
> print_address_bits
)
6522 print_address_bits
= addr_bit
;
6525 return print_address_bits
;
6528 /* See breakpoint.h. */
6531 print_breakpoint (breakpoint
*b
)
6533 struct bp_location
*dummy_loc
= NULL
;
6534 print_one_breakpoint (b
, &dummy_loc
, 0);
6537 /* Return true if this breakpoint was set by the user, false if it is
6538 internal or momentary. */
6541 user_breakpoint_p (struct breakpoint
*b
)
6543 return b
->number
> 0;
6546 /* See breakpoint.h. */
6549 pending_breakpoint_p (struct breakpoint
*b
)
6551 return b
->loc
== NULL
;
6554 /* Print information on breakpoints (including watchpoints and tracepoints).
6556 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6557 understood by number_or_range_parser. Only breakpoints included in this
6558 list are then printed.
6560 If SHOW_INTERNAL is true, print internal breakpoints.
6562 If FILTER is non-NULL, call it on each breakpoint and only include the
6563 ones for which it returns true.
6565 Return the total number of breakpoints listed. */
6568 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6569 bool (*filter
) (const struct breakpoint
*))
6571 struct bp_location
*last_loc
= NULL
;
6572 int nr_printable_breakpoints
;
6573 struct value_print_options opts
;
6574 int print_address_bits
= 0;
6575 int print_type_col_width
= 14;
6576 struct ui_out
*uiout
= current_uiout
;
6577 bool has_disabled_by_cond_location
= false;
6579 get_user_print_options (&opts
);
6581 /* Compute the number of rows in the table, as well as the size
6582 required for address fields. */
6583 nr_printable_breakpoints
= 0;
6584 for (breakpoint
*b
: all_breakpoints ())
6586 /* If we have a filter, only list the breakpoints it accepts. */
6587 if (filter
&& !filter (b
))
6590 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6591 accept. Skip the others. */
6592 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6594 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6596 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6600 if (show_internal
|| user_breakpoint_p (b
))
6602 int addr_bit
, type_len
;
6604 addr_bit
= breakpoint_address_bits (b
);
6605 if (addr_bit
> print_address_bits
)
6606 print_address_bits
= addr_bit
;
6608 type_len
= strlen (bptype_string (b
->type
));
6609 if (type_len
> print_type_col_width
)
6610 print_type_col_width
= type_len
;
6612 nr_printable_breakpoints
++;
6617 ui_out_emit_table
table_emitter (uiout
,
6618 opts
.addressprint
? 6 : 5,
6619 nr_printable_breakpoints
,
6622 if (nr_printable_breakpoints
> 0)
6623 annotate_breakpoints_headers ();
6624 if (nr_printable_breakpoints
> 0)
6626 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6627 if (nr_printable_breakpoints
> 0)
6629 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6630 if (nr_printable_breakpoints
> 0)
6632 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6633 if (nr_printable_breakpoints
> 0)
6635 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6636 if (opts
.addressprint
)
6638 if (nr_printable_breakpoints
> 0)
6640 if (print_address_bits
<= 32)
6641 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6643 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6645 if (nr_printable_breakpoints
> 0)
6647 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6648 uiout
->table_body ();
6649 if (nr_printable_breakpoints
> 0)
6650 annotate_breakpoints_table ();
6652 for (breakpoint
*b
: all_breakpoints ())
6655 /* If we have a filter, only list the breakpoints it accepts. */
6656 if (filter
&& !filter (b
))
6659 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6660 accept. Skip the others. */
6662 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6664 if (show_internal
) /* maintenance info breakpoint */
6666 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6669 else /* all others */
6671 if (!number_is_in_list (bp_num_list
, b
->number
))
6675 /* We only print out user settable breakpoints unless the
6676 show_internal is set. */
6677 if (show_internal
|| user_breakpoint_p (b
))
6679 print_one_breakpoint (b
, &last_loc
, show_internal
);
6680 for (bp_location
*loc
: b
->locations ())
6681 if (loc
->disabled_by_cond
)
6682 has_disabled_by_cond_location
= true;
6687 if (nr_printable_breakpoints
== 0)
6689 /* If there's a filter, let the caller decide how to report
6693 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6694 uiout
->message ("No breakpoints or watchpoints.\n");
6696 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6702 if (last_loc
&& !server_command
)
6703 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6705 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6706 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6710 /* FIXME? Should this be moved up so that it is only called when
6711 there have been breakpoints? */
6712 annotate_breakpoints_table_end ();
6714 return nr_printable_breakpoints
;
6717 /* Display the value of default-collect in a way that is generally
6718 compatible with the breakpoint list. */
6721 default_collect_info (void)
6723 struct ui_out
*uiout
= current_uiout
;
6725 /* If it has no value (which is frequently the case), say nothing; a
6726 message like "No default-collect." gets in user's face when it's
6728 if (default_collect
.empty ())
6731 /* The following phrase lines up nicely with per-tracepoint collect
6733 uiout
->text ("default collect ");
6734 uiout
->field_string ("default-collect", default_collect
);
6735 uiout
->text (" \n");
6739 info_breakpoints_command (const char *args
, int from_tty
)
6741 breakpoint_1 (args
, false, NULL
);
6743 default_collect_info ();
6747 info_watchpoints_command (const char *args
, int from_tty
)
6749 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6750 struct ui_out
*uiout
= current_uiout
;
6752 if (num_printed
== 0)
6754 if (args
== NULL
|| *args
== '\0')
6755 uiout
->message ("No watchpoints.\n");
6757 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6762 maintenance_info_breakpoints (const char *args
, int from_tty
)
6764 breakpoint_1 (args
, true, NULL
);
6766 default_collect_info ();
6770 breakpoint_has_pc (struct breakpoint
*b
,
6771 struct program_space
*pspace
,
6772 CORE_ADDR pc
, struct obj_section
*section
)
6774 for (bp_location
*bl
: b
->locations ())
6776 if (bl
->pspace
== pspace
6777 && bl
->address
== pc
6778 && (!overlay_debugging
|| bl
->section
== section
))
6784 /* Print a message describing any user-breakpoints set at PC. This
6785 concerns with logical breakpoints, so we match program spaces, not
6789 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6790 struct program_space
*pspace
, CORE_ADDR pc
,
6791 struct obj_section
*section
, int thread
)
6795 for (breakpoint
*b
: all_breakpoints ())
6796 others
+= (user_breakpoint_p (b
)
6797 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6802 gdb_printf (_("Note: breakpoint "));
6803 else /* if (others == ???) */
6804 gdb_printf (_("Note: breakpoints "));
6805 for (breakpoint
*b
: all_breakpoints ())
6806 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6809 gdb_printf ("%d", b
->number
);
6810 if (b
->thread
== -1 && thread
!= -1)
6811 gdb_printf (" (all threads)");
6812 else if (b
->thread
!= -1)
6813 gdb_printf (" (thread %d)", b
->thread
);
6814 gdb_printf ("%s%s ",
6815 ((b
->enable_state
== bp_disabled
6816 || b
->enable_state
== bp_call_disabled
)
6820 : ((others
== 1) ? " and" : ""));
6822 current_uiout
->message (_("also set at pc %ps.\n"),
6823 styled_string (address_style
.style (),
6824 paddress (gdbarch
, pc
)));
6829 /* Return true iff it is meaningful to use the address member of LOC.
6830 For some breakpoint types, the locations' address members are
6831 irrelevant and it makes no sense to attempt to compare them to
6832 other addresses (or use them for any other purpose either).
6834 More specifically, software watchpoints and catchpoints that are
6835 not backed by breakpoints always have a zero valued location
6836 address and we don't want to mark breakpoints of any of these types
6837 to be a duplicate of an actual breakpoint location at address
6841 bl_address_is_meaningful (bp_location
*loc
)
6843 return loc
->loc_type
!= bp_loc_other
;
6846 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6847 true if LOC1 and LOC2 represent the same watchpoint location. */
6850 watchpoint_locations_match (struct bp_location
*loc1
,
6851 struct bp_location
*loc2
)
6853 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6854 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6856 /* Both of them must exist. */
6857 gdb_assert (w1
!= NULL
);
6858 gdb_assert (w2
!= NULL
);
6860 /* If the target can evaluate the condition expression in hardware,
6861 then we we need to insert both watchpoints even if they are at
6862 the same place. Otherwise the watchpoint will only trigger when
6863 the condition of whichever watchpoint was inserted evaluates to
6864 true, not giving a chance for GDB to check the condition of the
6865 other watchpoint. */
6867 && target_can_accel_watchpoint_condition (loc1
->address
,
6869 loc1
->watchpoint_type
,
6870 w1
->cond_exp
.get ()))
6872 && target_can_accel_watchpoint_condition (loc2
->address
,
6874 loc2
->watchpoint_type
,
6875 w2
->cond_exp
.get ())))
6878 /* Note that this checks the owner's type, not the location's. In
6879 case the target does not support read watchpoints, but does
6880 support access watchpoints, we'll have bp_read_watchpoint
6881 watchpoints with hw_access locations. Those should be considered
6882 duplicates of hw_read locations. The hw_read locations will
6883 become hw_access locations later. */
6884 return (loc1
->owner
->type
== loc2
->owner
->type
6885 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6886 && loc1
->address
== loc2
->address
6887 && loc1
->length
== loc2
->length
);
6890 /* See breakpoint.h. */
6893 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6894 const address_space
*aspace2
, CORE_ADDR addr2
)
6896 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6897 || aspace1
== aspace2
)
6901 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6902 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6903 matches ASPACE2. On targets that have global breakpoints, the address
6904 space doesn't really matter. */
6907 breakpoint_address_match_range (const address_space
*aspace1
,
6909 int len1
, const address_space
*aspace2
,
6912 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6913 || aspace1
== aspace2
)
6914 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6917 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6918 a ranged breakpoint. In most targets, a match happens only if ASPACE
6919 matches the breakpoint's address space. On targets that have global
6920 breakpoints, the address space doesn't really matter. */
6923 breakpoint_location_address_match (struct bp_location
*bl
,
6924 const address_space
*aspace
,
6927 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6930 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6931 bl
->address
, bl
->length
,
6935 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6936 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6937 match happens only if ASPACE matches the breakpoint's address
6938 space. On targets that have global breakpoints, the address space
6939 doesn't really matter. */
6942 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6943 const address_space
*aspace
,
6944 CORE_ADDR addr
, int len
)
6946 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6947 || bl
->pspace
->aspace
== aspace
)
6949 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6951 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6957 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6958 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6959 true, otherwise returns false. */
6962 tracepoint_locations_match (struct bp_location
*loc1
,
6963 struct bp_location
*loc2
)
6965 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6966 /* Since tracepoint locations are never duplicated with others', tracepoint
6967 locations at the same address of different tracepoints are regarded as
6968 different locations. */
6969 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6974 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6975 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6976 the same location. If SW_HW_BPS_MATCH is true, then software
6977 breakpoint locations and hardware breakpoint locations match,
6978 otherwise they don't. */
6981 breakpoint_locations_match (struct bp_location
*loc1
,
6982 struct bp_location
*loc2
,
6983 bool sw_hw_bps_match
)
6985 int hw_point1
, hw_point2
;
6987 /* Both of them must not be in moribund_locations. */
6988 gdb_assert (loc1
->owner
!= NULL
);
6989 gdb_assert (loc2
->owner
!= NULL
);
6991 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6992 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6994 if (hw_point1
!= hw_point2
)
6997 return watchpoint_locations_match (loc1
, loc2
);
6998 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6999 return tracepoint_locations_match (loc1
, loc2
);
7001 /* We compare bp_location.length in order to cover ranged
7002 breakpoints. Keep this in sync with
7003 bp_location_is_less_than. */
7004 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7005 loc2
->pspace
->aspace
, loc2
->address
)
7006 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7007 && loc1
->length
== loc2
->length
);
7011 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7012 int bnum
, int have_bnum
)
7014 /* The longest string possibly returned by hex_string_custom
7015 is 50 chars. These must be at least that big for safety. */
7019 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7020 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7022 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7023 bnum
, astr1
, astr2
);
7025 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7028 /* Adjust a breakpoint's address to account for architectural
7029 constraints on breakpoint placement. Return the adjusted address.
7030 Note: Very few targets require this kind of adjustment. For most
7031 targets, this function is simply the identity function. */
7034 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7035 CORE_ADDR bpaddr
, enum bptype bptype
)
7037 if (bptype
== bp_watchpoint
7038 || bptype
== bp_hardware_watchpoint
7039 || bptype
== bp_read_watchpoint
7040 || bptype
== bp_access_watchpoint
7041 || bptype
== bp_catchpoint
)
7043 /* Watchpoints and the various bp_catch_* eventpoints should not
7044 have their addresses modified. */
7047 else if (bptype
== bp_single_step
)
7049 /* Single-step breakpoints should not have their addresses
7050 modified. If there's any architectural constrain that
7051 applies to this address, then it should have already been
7052 taken into account when the breakpoint was created in the
7053 first place. If we didn't do this, stepping through e.g.,
7054 Thumb-2 IT blocks would break. */
7059 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7061 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7063 /* Some targets have architectural constraints on the placement
7064 of breakpoint instructions. Obtain the adjusted address. */
7065 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7068 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7070 /* An adjusted breakpoint address can significantly alter
7071 a user's expectations. Print a warning if an adjustment
7073 if (adjusted_bpaddr
!= bpaddr
)
7074 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7076 return adjusted_bpaddr
;
7081 bp_location_from_bp_type (bptype type
)
7086 case bp_single_step
:
7090 case bp_longjmp_resume
:
7091 case bp_longjmp_call_dummy
:
7093 case bp_exception_resume
:
7094 case bp_step_resume
:
7095 case bp_hp_step_resume
:
7096 case bp_watchpoint_scope
:
7098 case bp_std_terminate
:
7099 case bp_shlib_event
:
7100 case bp_thread_event
:
7101 case bp_overlay_event
:
7103 case bp_longjmp_master
:
7104 case bp_std_terminate_master
:
7105 case bp_exception_master
:
7106 case bp_gnu_ifunc_resolver
:
7107 case bp_gnu_ifunc_resolver_return
:
7109 return bp_loc_software_breakpoint
;
7110 case bp_hardware_breakpoint
:
7111 return bp_loc_hardware_breakpoint
;
7112 case bp_hardware_watchpoint
:
7113 case bp_read_watchpoint
:
7114 case bp_access_watchpoint
:
7115 return bp_loc_hardware_watchpoint
;
7119 case bp_fast_tracepoint
:
7120 case bp_static_tracepoint
:
7121 return bp_loc_other
;
7123 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7127 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7129 this->owner
= owner
;
7130 this->cond_bytecode
= NULL
;
7131 this->shlib_disabled
= 0;
7133 this->disabled_by_cond
= false;
7135 this->loc_type
= type
;
7137 if (this->loc_type
== bp_loc_software_breakpoint
7138 || this->loc_type
== bp_loc_hardware_breakpoint
)
7139 mark_breakpoint_location_modified (this);
7144 bp_location::bp_location (breakpoint
*owner
)
7145 : bp_location::bp_location (owner
,
7146 bp_location_from_bp_type (owner
->type
))
7150 /* Allocate a struct bp_location. */
7152 static struct bp_location
*
7153 allocate_bp_location (struct breakpoint
*bpt
)
7155 return bpt
->ops
->allocate_location (bpt
);
7158 /* Decrement reference count. If the reference count reaches 0,
7159 destroy the bp_location. Sets *BLP to NULL. */
7162 decref_bp_location (struct bp_location
**blp
)
7164 bp_location_ref_policy::decref (*blp
);
7168 /* Add breakpoint B at the end of the global breakpoint chain. */
7171 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7173 struct breakpoint
*b1
;
7174 struct breakpoint
*result
= b
.get ();
7176 /* Add this breakpoint to the end of the chain so that a list of
7177 breakpoints will come out in order of increasing numbers. */
7179 b1
= breakpoint_chain
;
7181 breakpoint_chain
= b
.release ();
7186 b1
->next
= b
.release ();
7192 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7195 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7196 struct gdbarch
*gdbarch
,
7198 const struct breakpoint_ops
*ops
)
7200 gdb_assert (ops
!= NULL
);
7204 b
->gdbarch
= gdbarch
;
7205 b
->language
= current_language
->la_language
;
7206 b
->input_radix
= input_radix
;
7207 b
->related_breakpoint
= b
;
7210 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7211 that has type BPTYPE and has no locations as yet. */
7213 static struct breakpoint
*
7214 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7216 const struct breakpoint_ops
*ops
)
7218 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7220 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7221 return add_to_breakpoint_chain (std::move (b
));
7224 /* Initialize loc->function_name. */
7227 set_breakpoint_location_function (struct bp_location
*loc
)
7229 gdb_assert (loc
->owner
!= NULL
);
7231 if (loc
->owner
->type
== bp_breakpoint
7232 || loc
->owner
->type
== bp_hardware_breakpoint
7233 || is_tracepoint (loc
->owner
))
7235 const char *function_name
;
7237 if (loc
->msymbol
!= NULL
7238 && (loc
->msymbol
->type () == mst_text_gnu_ifunc
7239 || loc
->msymbol
->type () == mst_data_gnu_ifunc
))
7241 struct breakpoint
*b
= loc
->owner
;
7243 function_name
= loc
->msymbol
->linkage_name ();
7245 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7246 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7248 /* Create only the whole new breakpoint of this type but do not
7249 mess more complicated breakpoints with multiple locations. */
7250 b
->type
= bp_gnu_ifunc_resolver
;
7251 /* Remember the resolver's address for use by the return
7253 loc
->related_address
= loc
->address
;
7257 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7260 loc
->function_name
= make_unique_xstrdup (function_name
);
7264 /* Attempt to determine architecture of location identified by SAL. */
7266 get_sal_arch (struct symtab_and_line sal
)
7269 return sal
.section
->objfile
->arch ();
7271 return sal
.symtab
->compunit ()->objfile ()->arch ();
7276 /* Low level routine for partially initializing a breakpoint of type
7277 BPTYPE. The newly created breakpoint's address, section, source
7278 file name, and line number are provided by SAL.
7280 It is expected that the caller will complete the initialization of
7281 the newly created breakpoint struct as well as output any status
7282 information regarding the creation of a new breakpoint. */
7285 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7286 struct symtab_and_line sal
, enum bptype bptype
,
7287 const struct breakpoint_ops
*ops
)
7289 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7291 add_location_to_breakpoint (b
, &sal
);
7293 if (bptype
!= bp_catchpoint
)
7294 gdb_assert (sal
.pspace
!= NULL
);
7296 /* Store the program space that was used to set the breakpoint,
7297 except for ordinary breakpoints, which are independent of the
7299 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7300 b
->pspace
= sal
.pspace
;
7303 /* set_raw_breakpoint is a low level routine for allocating and
7304 partially initializing a breakpoint of type BPTYPE. The newly
7305 created breakpoint's address, section, source file name, and line
7306 number are provided by SAL. The newly created and partially
7307 initialized breakpoint is added to the breakpoint chain and
7308 is also returned as the value of this function.
7310 It is expected that the caller will complete the initialization of
7311 the newly created breakpoint struct as well as output any status
7312 information regarding the creation of a new breakpoint. In
7313 particular, set_raw_breakpoint does NOT set the breakpoint
7314 number! Care should be taken to not allow an error to occur
7315 prior to completing the initialization of the breakpoint. If this
7316 should happen, a bogus breakpoint will be left on the chain. */
7318 static struct breakpoint
*
7319 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7320 struct symtab_and_line sal
, enum bptype bptype
,
7321 const struct breakpoint_ops
*ops
)
7323 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7325 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7326 return add_to_breakpoint_chain (std::move (b
));
7329 /* Call this routine when stepping and nexting to enable a breakpoint
7330 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7331 initiated the operation. */
7334 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7336 int thread
= tp
->global_num
;
7338 /* To avoid having to rescan all objfile symbols at every step,
7339 we maintain a list of continually-inserted but always disabled
7340 longjmp "master" breakpoints. Here, we simply create momentary
7341 clones of those and enable them for the requested thread. */
7342 for (breakpoint
*b
: all_breakpoints_safe ())
7343 if (b
->pspace
== current_program_space
7344 && (b
->type
== bp_longjmp_master
7345 || b
->type
== bp_exception_master
))
7347 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7348 struct breakpoint
*clone
;
7350 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7351 after their removal. */
7352 clone
= momentary_breakpoint_from_master (b
, type
,
7353 &momentary_breakpoint_ops
, 1);
7354 clone
->thread
= thread
;
7357 tp
->initiating_frame
= frame
;
7360 /* Delete all longjmp breakpoints from THREAD. */
7362 delete_longjmp_breakpoint (int thread
)
7364 for (breakpoint
*b
: all_breakpoints_safe ())
7365 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7367 if (b
->thread
== thread
)
7368 delete_breakpoint (b
);
7373 delete_longjmp_breakpoint_at_next_stop (int thread
)
7375 for (breakpoint
*b
: all_breakpoints_safe ())
7376 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7378 if (b
->thread
== thread
)
7379 b
->disposition
= disp_del_at_next_stop
;
7383 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7384 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7385 pointer to any of them. Return NULL if this system cannot place longjmp
7389 set_longjmp_breakpoint_for_call_dummy (void)
7391 breakpoint
*retval
= nullptr;
7393 for (breakpoint
*b
: all_breakpoints ())
7394 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7396 struct breakpoint
*new_b
;
7398 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7399 &momentary_breakpoint_ops
,
7401 new_b
->thread
= inferior_thread ()->global_num
;
7403 /* Link NEW_B into the chain of RETVAL breakpoints. */
7405 gdb_assert (new_b
->related_breakpoint
== new_b
);
7408 new_b
->related_breakpoint
= retval
;
7409 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7410 retval
= retval
->related_breakpoint
;
7411 retval
->related_breakpoint
= new_b
;
7417 /* Verify all existing dummy frames and their associated breakpoints for
7418 TP. Remove those which can no longer be found in the current frame
7421 If the unwind fails then there is not sufficient information to discard
7422 dummy frames. In this case, elide the clean up and the dummy frames will
7423 be cleaned up next time this function is called from a location where
7424 unwinding is possible. */
7427 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7429 struct breakpoint
*b
, *b_tmp
;
7431 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7432 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7434 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7436 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7437 chained off b->related_breakpoint. */
7438 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7439 dummy_b
= dummy_b
->related_breakpoint
;
7441 /* If there was no bp_call_dummy breakpoint then there's nothing
7442 more to do. Or, if the dummy frame associated with the
7443 bp_call_dummy is still on the stack then we need to leave this
7444 bp_call_dummy in place. */
7445 if (dummy_b
->type
!= bp_call_dummy
7446 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7449 /* We didn't find the dummy frame on the stack, this could be
7450 because we have longjmp'd to a stack frame that is previous to
7451 the dummy frame, or it could be because the stack unwind is
7452 broken at some point between the longjmp frame and the dummy
7455 Next we figure out why the stack unwind stopped. If it looks
7456 like the unwind is complete then we assume the dummy frame has
7457 been jumped over, however, if the unwind stopped for an
7458 unexpected reason then we assume the stack unwind is currently
7459 broken, and that we will (eventually) return to the dummy
7462 It might be tempting to consider using frame_id_inner here, but
7463 that is not safe. There is no guarantee that the stack frames
7464 we are looking at here are even on the same stack as the
7465 original dummy frame, hence frame_id_inner can't be used. See
7466 the comments on frame_id_inner for more details. */
7467 bool unwind_finished_unexpectedly
= false;
7468 for (struct frame_info
*fi
= get_current_frame (); fi
!= nullptr; )
7470 struct frame_info
*prev
= get_prev_frame (fi
);
7471 if (prev
== nullptr)
7473 /* FI is the last stack frame. Why did this frame not
7475 auto stop_reason
= get_frame_unwind_stop_reason (fi
);
7476 if (stop_reason
!= UNWIND_NO_REASON
7477 && stop_reason
!= UNWIND_OUTERMOST
)
7478 unwind_finished_unexpectedly
= true;
7482 if (unwind_finished_unexpectedly
)
7485 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7487 while (b
->related_breakpoint
!= b
)
7489 if (b_tmp
== b
->related_breakpoint
)
7490 b_tmp
= b
->related_breakpoint
->next
;
7491 delete_breakpoint (b
->related_breakpoint
);
7493 delete_breakpoint (b
);
7498 enable_overlay_breakpoints (void)
7500 for (breakpoint
*b
: all_breakpoints ())
7501 if (b
->type
== bp_overlay_event
)
7503 b
->enable_state
= bp_enabled
;
7504 update_global_location_list (UGLL_MAY_INSERT
);
7505 overlay_events_enabled
= 1;
7510 disable_overlay_breakpoints (void)
7512 for (breakpoint
*b
: all_breakpoints ())
7513 if (b
->type
== bp_overlay_event
)
7515 b
->enable_state
= bp_disabled
;
7516 update_global_location_list (UGLL_DONT_INSERT
);
7517 overlay_events_enabled
= 0;
7521 /* Set an active std::terminate breakpoint for each std::terminate
7522 master breakpoint. */
7524 set_std_terminate_breakpoint (void)
7526 for (breakpoint
*b
: all_breakpoints_safe ())
7527 if (b
->pspace
== current_program_space
7528 && b
->type
== bp_std_terminate_master
)
7530 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7531 &momentary_breakpoint_ops
, 1);
7535 /* Delete all the std::terminate breakpoints. */
7537 delete_std_terminate_breakpoint (void)
7539 for (breakpoint
*b
: all_breakpoints_safe ())
7540 if (b
->type
== bp_std_terminate
)
7541 delete_breakpoint (b
);
7545 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7547 struct breakpoint
*b
;
7549 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7550 &internal_breakpoint_ops
);
7552 b
->enable_state
= bp_enabled
;
7553 /* location has to be used or breakpoint_re_set will delete me. */
7554 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7556 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7561 struct lang_and_radix
7567 /* Create a breakpoint for JIT code registration and unregistration. */
7570 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7572 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7573 &internal_breakpoint_ops
);
7576 /* Remove JIT code registration and unregistration breakpoint(s). */
7579 remove_jit_event_breakpoints (void)
7581 for (breakpoint
*b
: all_breakpoints_safe ())
7582 if (b
->type
== bp_jit_event
7583 && b
->loc
->pspace
== current_program_space
)
7584 delete_breakpoint (b
);
7588 remove_solib_event_breakpoints (void)
7590 for (breakpoint
*b
: all_breakpoints_safe ())
7591 if (b
->type
== bp_shlib_event
7592 && b
->loc
->pspace
== current_program_space
)
7593 delete_breakpoint (b
);
7596 /* See breakpoint.h. */
7599 remove_solib_event_breakpoints_at_next_stop (void)
7601 for (breakpoint
*b
: all_breakpoints_safe ())
7602 if (b
->type
== bp_shlib_event
7603 && b
->loc
->pspace
== current_program_space
)
7604 b
->disposition
= disp_del_at_next_stop
;
7607 /* Helper for create_solib_event_breakpoint /
7608 create_and_insert_solib_event_breakpoint. Allows specifying which
7609 INSERT_MODE to pass through to update_global_location_list. */
7611 static struct breakpoint
*
7612 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7613 enum ugll_insert_mode insert_mode
)
7615 struct breakpoint
*b
;
7617 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7618 &internal_breakpoint_ops
);
7619 update_global_location_list_nothrow (insert_mode
);
7624 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7626 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7629 /* See breakpoint.h. */
7632 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7634 struct breakpoint
*b
;
7636 /* Explicitly tell update_global_location_list to insert
7638 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7639 if (!b
->loc
->inserted
)
7641 delete_breakpoint (b
);
7647 /* Disable any breakpoints that are on code in shared libraries. Only
7648 apply to enabled breakpoints, disabled ones can just stay disabled. */
7651 disable_breakpoints_in_shlibs (void)
7653 for (bp_location
*loc
: all_bp_locations ())
7655 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7656 struct breakpoint
*b
= loc
->owner
;
7658 /* We apply the check to all breakpoints, including disabled for
7659 those with loc->duplicate set. This is so that when breakpoint
7660 becomes enabled, or the duplicate is removed, gdb will try to
7661 insert all breakpoints. If we don't set shlib_disabled here,
7662 we'll try to insert those breakpoints and fail. */
7663 if (((b
->type
== bp_breakpoint
)
7664 || (b
->type
== bp_jit_event
)
7665 || (b
->type
== bp_hardware_breakpoint
)
7666 || (is_tracepoint (b
)))
7667 && loc
->pspace
== current_program_space
7668 && !loc
->shlib_disabled
7669 && solib_name_from_address (loc
->pspace
, loc
->address
)
7672 loc
->shlib_disabled
= 1;
7677 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7678 notification of unloaded_shlib. Only apply to enabled breakpoints,
7679 disabled ones can just stay disabled. */
7682 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7684 int disabled_shlib_breaks
= 0;
7686 for (bp_location
*loc
: all_bp_locations ())
7688 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7689 struct breakpoint
*b
= loc
->owner
;
7691 if (solib
->pspace
== loc
->pspace
7692 && !loc
->shlib_disabled
7693 && (((b
->type
== bp_breakpoint
7694 || b
->type
== bp_jit_event
7695 || b
->type
== bp_hardware_breakpoint
)
7696 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7697 || loc
->loc_type
== bp_loc_software_breakpoint
))
7698 || is_tracepoint (b
))
7699 && solib_contains_address_p (solib
, loc
->address
))
7701 loc
->shlib_disabled
= 1;
7702 /* At this point, we cannot rely on remove_breakpoint
7703 succeeding so we must mark the breakpoint as not inserted
7704 to prevent future errors occurring in remove_breakpoints. */
7707 /* This may cause duplicate notifications for the same breakpoint. */
7708 gdb::observers::breakpoint_modified
.notify (b
);
7710 if (!disabled_shlib_breaks
)
7712 target_terminal::ours_for_output ();
7713 warning (_("Temporarily disabling breakpoints "
7714 "for unloaded shared library \"%s\""),
7717 disabled_shlib_breaks
= 1;
7722 /* Disable any breakpoints and tracepoints in OBJFILE upon
7723 notification of free_objfile. Only apply to enabled breakpoints,
7724 disabled ones can just stay disabled. */
7727 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7729 if (objfile
== NULL
)
7732 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7733 managed by the user with add-symbol-file/remove-symbol-file.
7734 Similarly to how breakpoints in shared libraries are handled in
7735 response to "nosharedlibrary", mark breakpoints in such modules
7736 shlib_disabled so they end up uninserted on the next global
7737 location list update. Shared libraries not loaded by the user
7738 aren't handled here -- they're already handled in
7739 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7740 solib_unloaded observer. We skip objfiles that are not
7741 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7743 if ((objfile
->flags
& OBJF_SHARED
) == 0
7744 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7747 for (breakpoint
*b
: all_breakpoints ())
7749 int bp_modified
= 0;
7751 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7754 for (bp_location
*loc
: b
->locations ())
7756 CORE_ADDR loc_addr
= loc
->address
;
7758 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7759 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7762 if (loc
->shlib_disabled
!= 0)
7765 if (objfile
->pspace
!= loc
->pspace
)
7768 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7769 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7772 if (is_addr_in_objfile (loc_addr
, objfile
))
7774 loc
->shlib_disabled
= 1;
7775 /* At this point, we don't know whether the object was
7776 unmapped from the inferior or not, so leave the
7777 inserted flag alone. We'll handle failure to
7778 uninsert quietly, in case the object was indeed
7781 mark_breakpoint_location_modified (loc
);
7788 gdb::observers::breakpoint_modified
.notify (b
);
7792 /* See breakpoint.h. */
7795 init_catchpoint (struct breakpoint
*b
,
7796 struct gdbarch
*gdbarch
, bool temp
,
7797 const char *cond_string
,
7798 const struct breakpoint_ops
*ops
)
7800 symtab_and_line sal
;
7801 sal
.pspace
= current_program_space
;
7803 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
7805 if (cond_string
== nullptr)
7806 b
->cond_string
.reset ();
7808 b
->cond_string
= make_unique_xstrdup (cond_string
);
7809 b
->disposition
= temp
? disp_del
: disp_donttouch
;
7813 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
7815 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
7816 set_breakpoint_number (internal
, b
);
7817 if (is_tracepoint (b
))
7818 set_tracepoint_count (breakpoint_count
);
7821 gdb::observers::breakpoint_created
.notify (b
);
7824 update_global_location_list (UGLL_MAY_INSERT
);
7828 hw_breakpoint_used_count (void)
7832 for (breakpoint
*b
: all_breakpoints ())
7833 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
7834 for (bp_location
*bl
: b
->locations ())
7836 /* Special types of hardware breakpoints may use more than
7838 i
+= b
->ops
->resources_needed (bl
);
7844 /* Returns the resources B would use if it were a hardware
7848 hw_watchpoint_use_count (struct breakpoint
*b
)
7852 if (!breakpoint_enabled (b
))
7855 for (bp_location
*bl
: b
->locations ())
7857 /* Special types of hardware watchpoints may use more than
7859 i
+= b
->ops
->resources_needed (bl
);
7865 /* Returns the sum the used resources of all hardware watchpoints of
7866 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
7867 the sum of the used resources of all hardware watchpoints of other
7868 types _not_ TYPE. */
7871 hw_watchpoint_used_count_others (struct breakpoint
*except
,
7872 enum bptype type
, int *other_type_used
)
7876 *other_type_used
= 0;
7877 for (breakpoint
*b
: all_breakpoints ())
7881 if (!breakpoint_enabled (b
))
7884 if (b
->type
== type
)
7885 i
+= hw_watchpoint_use_count (b
);
7886 else if (is_hardware_watchpoint (b
))
7887 *other_type_used
= 1;
7894 disable_watchpoints_before_interactive_call_start (void)
7896 for (breakpoint
*b
: all_breakpoints ())
7897 if (is_watchpoint (b
) && breakpoint_enabled (b
))
7899 b
->enable_state
= bp_call_disabled
;
7900 update_global_location_list (UGLL_DONT_INSERT
);
7905 enable_watchpoints_after_interactive_call_stop (void)
7907 for (breakpoint
*b
: all_breakpoints ())
7908 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
7910 b
->enable_state
= bp_enabled
;
7911 update_global_location_list (UGLL_MAY_INSERT
);
7916 disable_breakpoints_before_startup (void)
7918 current_program_space
->executing_startup
= 1;
7919 update_global_location_list (UGLL_DONT_INSERT
);
7923 enable_breakpoints_after_startup (void)
7925 current_program_space
->executing_startup
= 0;
7926 breakpoint_re_set ();
7929 /* Create a new single-step breakpoint for thread THREAD, with no
7932 static struct breakpoint
*
7933 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
7935 std::unique_ptr
<breakpoint
> b (new breakpoint ());
7937 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
7938 &momentary_breakpoint_ops
);
7940 b
->disposition
= disp_donttouch
;
7941 b
->frame_id
= null_frame_id
;
7944 gdb_assert (b
->thread
!= 0);
7946 return add_to_breakpoint_chain (std::move (b
));
7949 /* Set a momentary breakpoint of type TYPE at address specified by
7950 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
7954 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7955 struct frame_id frame_id
, enum bptype type
)
7957 struct breakpoint
*b
;
7959 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
7961 gdb_assert (!frame_id_artificial_p (frame_id
));
7963 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
7964 b
->enable_state
= bp_enabled
;
7965 b
->disposition
= disp_donttouch
;
7966 b
->frame_id
= frame_id
;
7968 b
->thread
= inferior_thread ()->global_num
;
7970 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7972 return breakpoint_up (b
);
7975 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7976 The new breakpoint will have type TYPE, use OPS as its
7977 breakpoint_ops, and will set enabled to LOC_ENABLED. */
7979 static struct breakpoint
*
7980 momentary_breakpoint_from_master (struct breakpoint
*orig
,
7982 const struct breakpoint_ops
*ops
,
7985 struct breakpoint
*copy
;
7987 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
7988 copy
->loc
= allocate_bp_location (copy
);
7989 set_breakpoint_location_function (copy
->loc
);
7991 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7992 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7993 copy
->loc
->address
= orig
->loc
->address
;
7994 copy
->loc
->section
= orig
->loc
->section
;
7995 copy
->loc
->pspace
= orig
->loc
->pspace
;
7996 copy
->loc
->probe
= orig
->loc
->probe
;
7997 copy
->loc
->line_number
= orig
->loc
->line_number
;
7998 copy
->loc
->symtab
= orig
->loc
->symtab
;
7999 copy
->loc
->enabled
= loc_enabled
;
8000 copy
->frame_id
= orig
->frame_id
;
8001 copy
->thread
= orig
->thread
;
8002 copy
->pspace
= orig
->pspace
;
8004 copy
->enable_state
= bp_enabled
;
8005 copy
->disposition
= disp_donttouch
;
8006 copy
->number
= internal_breakpoint_number
--;
8008 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8012 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8016 clone_momentary_breakpoint (struct breakpoint
*orig
)
8018 /* If there's nothing to clone, then return nothing. */
8022 gdb_assert (orig
->ops
== &momentary_breakpoint_ops
);
8023 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8027 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8030 struct symtab_and_line sal
;
8032 sal
= find_pc_line (pc
, 0);
8034 sal
.section
= find_pc_overlay (pc
);
8035 sal
.explicit_pc
= 1;
8037 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8041 /* Tell the user we have just set a breakpoint B. */
8044 mention (struct breakpoint
*b
)
8046 b
->ops
->print_mention (b
);
8047 current_uiout
->text ("\n");
8051 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8053 /* Handle "set breakpoint auto-hw on".
8055 If the explicitly specified breakpoint type is not hardware
8056 breakpoint, check the memory map to see whether the breakpoint
8057 address is in read-only memory.
8059 - location type is not hardware breakpoint, memory is read-only.
8060 We change the type of the location to hardware breakpoint.
8062 - location type is hardware breakpoint, memory is read-write. This
8063 means we've previously made the location hardware one, but then the
8064 memory map changed, so we undo.
8068 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8070 if (automatic_hardware_breakpoints
8071 && bl
->owner
->type
!= bp_hardware_breakpoint
8072 && (bl
->loc_type
== bp_loc_software_breakpoint
8073 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8075 /* When breakpoints are removed, remove_breakpoints will use
8076 location types we've just set here, the only possible problem
8077 is that memory map has changed during running program, but
8078 it's not going to work anyway with current gdb. */
8079 mem_region
*mr
= lookup_mem_region (bl
->address
);
8083 enum bp_loc_type new_type
;
8085 if (mr
->attrib
.mode
!= MEM_RW
)
8086 new_type
= bp_loc_hardware_breakpoint
;
8088 new_type
= bp_loc_software_breakpoint
;
8090 if (new_type
!= bl
->loc_type
)
8092 static bool said
= false;
8094 bl
->loc_type
= new_type
;
8097 gdb_printf (_("Note: automatically using "
8098 "hardware breakpoints for "
8099 "read-only addresses.\n"));
8107 static struct bp_location
*
8108 add_location_to_breakpoint (struct breakpoint
*b
,
8109 const struct symtab_and_line
*sal
)
8111 struct bp_location
*loc
, **tmp
;
8112 CORE_ADDR adjusted_address
;
8113 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8115 if (loc_gdbarch
== NULL
)
8116 loc_gdbarch
= b
->gdbarch
;
8118 /* Adjust the breakpoint's address prior to allocating a location.
8119 Once we call allocate_bp_location(), that mostly uninitialized
8120 location will be placed on the location chain. Adjustment of the
8121 breakpoint may cause target_read_memory() to be called and we do
8122 not want its scan of the location chain to find a breakpoint and
8123 location that's only been partially initialized. */
8124 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8127 /* Sort the locations by their ADDRESS. */
8128 loc
= allocate_bp_location (b
);
8129 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8130 tmp
= &((*tmp
)->next
))
8135 loc
->requested_address
= sal
->pc
;
8136 loc
->address
= adjusted_address
;
8137 loc
->pspace
= sal
->pspace
;
8138 loc
->probe
.prob
= sal
->prob
;
8139 loc
->probe
.objfile
= sal
->objfile
;
8140 gdb_assert (loc
->pspace
!= NULL
);
8141 loc
->section
= sal
->section
;
8142 loc
->gdbarch
= loc_gdbarch
;
8143 loc
->line_number
= sal
->line
;
8144 loc
->symtab
= sal
->symtab
;
8145 loc
->symbol
= sal
->symbol
;
8146 loc
->msymbol
= sal
->msymbol
;
8147 loc
->objfile
= sal
->objfile
;
8149 set_breakpoint_location_function (loc
);
8151 /* While by definition, permanent breakpoints are already present in the
8152 code, we don't mark the location as inserted. Normally one would expect
8153 that GDB could rely on that breakpoint instruction to stop the program,
8154 thus removing the need to insert its own breakpoint, except that executing
8155 the breakpoint instruction can kill the target instead of reporting a
8156 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8157 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8158 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8159 breakpoint be inserted normally results in QEMU knowing about the GDB
8160 breakpoint, and thus trap before the breakpoint instruction is executed.
8161 (If GDB later needs to continue execution past the permanent breakpoint,
8162 it manually increments the PC, thus avoiding executing the breakpoint
8164 if (bp_loc_is_permanent (loc
))
8171 /* Return true if LOC is pointing to a permanent breakpoint,
8172 return false otherwise. */
8175 bp_loc_is_permanent (struct bp_location
*loc
)
8177 gdb_assert (loc
!= NULL
);
8179 /* If we have a non-breakpoint-backed catchpoint or a software
8180 watchpoint, just return 0. We should not attempt to read from
8181 the addresses the locations of these breakpoint types point to.
8182 gdbarch_program_breakpoint_here_p, below, will attempt to read
8184 if (!bl_address_is_meaningful (loc
))
8187 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8188 switch_to_program_space_and_thread (loc
->pspace
);
8189 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8192 /* Build a command list for the dprintf corresponding to the current
8193 settings of the dprintf style options. */
8196 update_dprintf_command_list (struct breakpoint
*b
)
8198 const char *dprintf_args
= b
->extra_string
.get ();
8199 gdb::unique_xmalloc_ptr
<char> printf_line
= nullptr;
8204 dprintf_args
= skip_spaces (dprintf_args
);
8206 /* Allow a comma, as it may have terminated a location, but don't
8208 if (*dprintf_args
== ',')
8210 dprintf_args
= skip_spaces (dprintf_args
);
8212 if (*dprintf_args
!= '"')
8213 error (_("Bad format string, missing '\"'."));
8215 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8216 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8217 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8219 if (dprintf_function
.empty ())
8220 error (_("No function supplied for dprintf call"));
8222 if (!dprintf_channel
.empty ())
8223 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8224 dprintf_function
.c_str (),
8225 dprintf_channel
.c_str (),
8228 printf_line
= xstrprintf ("call (void) %s (%s)",
8229 dprintf_function
.c_str (),
8232 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8234 if (target_can_run_breakpoint_commands ())
8235 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8238 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8239 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8243 internal_error (__FILE__
, __LINE__
,
8244 _("Invalid dprintf style."));
8246 gdb_assert (printf_line
!= NULL
);
8248 /* Manufacture a printf sequence. */
8249 struct command_line
*printf_cmd_line
8250 = new struct command_line (simple_control
, printf_line
.release ());
8251 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8252 command_lines_deleter ()));
8255 /* Update all dprintf commands, making their command lists reflect
8256 current style settings. */
8259 update_dprintf_commands (const char *args
, int from_tty
,
8260 struct cmd_list_element
*c
)
8262 for (breakpoint
*b
: all_breakpoints ())
8263 if (b
->type
== bp_dprintf
)
8264 update_dprintf_command_list (b
);
8267 /* Create a breakpoint with SAL as location. Use LOCATION
8268 as a description of the location, and COND_STRING
8269 as condition expression. If LOCATION is NULL then create an
8270 "address location" from the address in the SAL. */
8273 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8274 gdb::array_view
<const symtab_and_line
> sals
,
8275 event_location_up
&&location
,
8276 gdb::unique_xmalloc_ptr
<char> filter
,
8277 gdb::unique_xmalloc_ptr
<char> cond_string
,
8278 gdb::unique_xmalloc_ptr
<char> extra_string
,
8279 enum bptype type
, enum bpdisp disposition
,
8280 int thread
, int task
, int ignore_count
,
8281 const struct breakpoint_ops
*ops
, int from_tty
,
8282 int enabled
, int internal
, unsigned flags
,
8283 int display_canonical
)
8287 if (type
== bp_hardware_breakpoint
)
8289 int target_resources_ok
;
8291 i
= hw_breakpoint_used_count ();
8292 target_resources_ok
=
8293 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8295 if (target_resources_ok
== 0)
8296 error (_("No hardware breakpoint support in the target."));
8297 else if (target_resources_ok
< 0)
8298 error (_("Hardware breakpoints used exceeds limit."));
8301 gdb_assert (!sals
.empty ());
8303 for (const auto &sal
: sals
)
8305 struct bp_location
*loc
;
8309 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8311 loc_gdbarch
= gdbarch
;
8313 describe_other_breakpoints (loc_gdbarch
,
8314 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8317 if (&sal
== &sals
[0])
8319 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8323 b
->cond_string
= std::move (cond_string
);
8324 b
->extra_string
= std::move (extra_string
);
8325 b
->ignore_count
= ignore_count
;
8326 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8327 b
->disposition
= disposition
;
8329 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8330 b
->loc
->inserted
= 1;
8332 if (type
== bp_static_tracepoint
)
8334 struct tracepoint
*t
= (struct tracepoint
*) b
;
8335 struct static_tracepoint_marker marker
;
8337 if (strace_marker_p (b
))
8339 /* We already know the marker exists, otherwise, we
8340 wouldn't see a sal for it. */
8342 = &event_location_to_string (b
->location
.get ())[3];
8345 p
= skip_spaces (p
);
8347 endp
= skip_to_space (p
);
8349 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8351 gdb_printf (_("Probed static tracepoint "
8353 t
->static_trace_marker_id
.c_str ());
8355 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8357 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8359 gdb_printf (_("Probed static tracepoint "
8361 t
->static_trace_marker_id
.c_str ());
8364 warning (_("Couldn't determine the static "
8365 "tracepoint marker to probe"));
8372 loc
= add_location_to_breakpoint (b
, &sal
);
8373 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8377 /* Do not set breakpoint locations conditions yet. As locations
8378 are inserted, they get sorted based on their addresses. Let
8379 the list stabilize to have reliable location numbers. */
8381 /* Dynamic printf requires and uses additional arguments on the
8382 command line, otherwise it's an error. */
8383 if (type
== bp_dprintf
)
8385 if (b
->extra_string
)
8386 update_dprintf_command_list (b
);
8388 error (_("Format string required"));
8390 else if (b
->extra_string
)
8391 error (_("Garbage '%s' at end of command"), b
->extra_string
.get ());
8395 /* The order of the locations is now stable. Set the location
8396 condition using the location's number. */
8398 for (bp_location
*loc
: b
->locations ())
8400 if (b
->cond_string
!= nullptr)
8401 set_breakpoint_location_condition (b
->cond_string
.get (), loc
,
8402 b
->number
, loc_num
);
8407 b
->display_canonical
= display_canonical
;
8408 if (location
!= NULL
)
8409 b
->location
= std::move (location
);
8411 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8412 b
->filter
= std::move (filter
);
8416 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8417 gdb::array_view
<const symtab_and_line
> sals
,
8418 event_location_up
&&location
,
8419 gdb::unique_xmalloc_ptr
<char> filter
,
8420 gdb::unique_xmalloc_ptr
<char> cond_string
,
8421 gdb::unique_xmalloc_ptr
<char> extra_string
,
8422 enum bptype type
, enum bpdisp disposition
,
8423 int thread
, int task
, int ignore_count
,
8424 const struct breakpoint_ops
*ops
, int from_tty
,
8425 int enabled
, int internal
, unsigned flags
,
8426 int display_canonical
)
8428 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8430 init_breakpoint_sal (b
.get (), gdbarch
,
8431 sals
, std::move (location
),
8433 std::move (cond_string
),
8434 std::move (extra_string
),
8436 thread
, task
, ignore_count
,
8438 enabled
, internal
, flags
,
8441 install_breakpoint (internal
, std::move (b
), 0);
8444 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8445 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8446 value. COND_STRING, if not NULL, specified the condition to be
8447 used for all breakpoints. Essentially the only case where
8448 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8449 function. In that case, it's still not possible to specify
8450 separate conditions for different overloaded functions, so
8451 we take just a single condition string.
8453 NOTE: If the function succeeds, the caller is expected to cleanup
8454 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8455 array contents). If the function fails (error() is called), the
8456 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8457 COND and SALS arrays and each of those arrays contents. */
8460 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8461 struct linespec_result
*canonical
,
8462 gdb::unique_xmalloc_ptr
<char> cond_string
,
8463 gdb::unique_xmalloc_ptr
<char> extra_string
,
8464 enum bptype type
, enum bpdisp disposition
,
8465 int thread
, int task
, int ignore_count
,
8466 const struct breakpoint_ops
*ops
, int from_tty
,
8467 int enabled
, int internal
, unsigned flags
)
8469 if (canonical
->pre_expanded
)
8470 gdb_assert (canonical
->lsals
.size () == 1);
8472 for (const auto &lsal
: canonical
->lsals
)
8474 /* Note that 'location' can be NULL in the case of a plain
8475 'break', without arguments. */
8476 event_location_up location
8477 = (canonical
->location
!= NULL
8478 ? copy_event_location (canonical
->location
.get ()) : NULL
);
8479 gdb::unique_xmalloc_ptr
<char> filter_string
8480 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8482 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8483 std::move (location
),
8484 std::move (filter_string
),
8485 std::move (cond_string
),
8486 std::move (extra_string
),
8488 thread
, task
, ignore_count
, ops
,
8489 from_tty
, enabled
, internal
, flags
,
8490 canonical
->special_display
);
8494 /* Parse LOCATION which is assumed to be a SAL specification possibly
8495 followed by conditionals. On return, SALS contains an array of SAL
8496 addresses found. LOCATION points to the end of the SAL (for
8497 linespec locations).
8499 The array and the line spec strings are allocated on the heap, it is
8500 the caller's responsibility to free them. */
8503 parse_breakpoint_sals (struct event_location
*location
,
8504 struct linespec_result
*canonical
)
8506 struct symtab_and_line cursal
;
8508 if (event_location_type (location
) == LINESPEC_LOCATION
)
8510 const char *spec
= get_linespec_location (location
)->spec_string
;
8514 /* The last displayed codepoint, if it's valid, is our default
8515 breakpoint address. */
8516 if (last_displayed_sal_is_valid ())
8518 /* Set sal's pspace, pc, symtab, and line to the values
8519 corresponding to the last call to print_frame_info.
8520 Be sure to reinitialize LINE with NOTCURRENT == 0
8521 as the breakpoint line number is inappropriate otherwise.
8522 find_pc_line would adjust PC, re-set it back. */
8523 symtab_and_line sal
= get_last_displayed_sal ();
8524 CORE_ADDR pc
= sal
.pc
;
8526 sal
= find_pc_line (pc
, 0);
8528 /* "break" without arguments is equivalent to "break *PC"
8529 where PC is the last displayed codepoint's address. So
8530 make sure to set sal.explicit_pc to prevent GDB from
8531 trying to expand the list of sals to include all other
8532 instances with the same symtab and line. */
8534 sal
.explicit_pc
= 1;
8536 struct linespec_sals lsal
;
8538 lsal
.canonical
= NULL
;
8540 canonical
->lsals
.push_back (std::move (lsal
));
8544 error (_("No default breakpoint address now."));
8548 /* Force almost all breakpoints to be in terms of the
8549 current_source_symtab (which is decode_line_1's default).
8550 This should produce the results we want almost all of the
8551 time while leaving default_breakpoint_* alone.
8553 ObjC: However, don't match an Objective-C method name which
8554 may have a '+' or '-' succeeded by a '['. */
8555 cursal
= get_current_source_symtab_and_line ();
8556 if (last_displayed_sal_is_valid ())
8558 const char *spec
= NULL
;
8560 if (event_location_type (location
) == LINESPEC_LOCATION
)
8561 spec
= get_linespec_location (location
)->spec_string
;
8565 && strchr ("+-", spec
[0]) != NULL
8568 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8569 get_last_displayed_symtab (),
8570 get_last_displayed_line (),
8571 canonical
, NULL
, NULL
);
8576 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8577 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
8581 /* Convert each SAL into a real PC. Verify that the PC can be
8582 inserted as a breakpoint. If it can't throw an error. */
8585 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
8587 for (auto &sal
: sals
)
8588 resolve_sal_pc (&sal
);
8591 /* Fast tracepoints may have restrictions on valid locations. For
8592 instance, a fast tracepoint using a jump instead of a trap will
8593 likely have to overwrite more bytes than a trap would, and so can
8594 only be placed where the instruction is longer than the jump, or a
8595 multi-instruction sequence does not have a jump into the middle of
8599 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8600 gdb::array_view
<const symtab_and_line
> sals
)
8602 for (const auto &sal
: sals
)
8604 struct gdbarch
*sarch
;
8606 sarch
= get_sal_arch (sal
);
8607 /* We fall back to GDBARCH if there is no architecture
8608 associated with SAL. */
8612 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
8613 error (_("May not have a fast tracepoint at %s%s"),
8614 paddress (sarch
, sal
.pc
), msg
.c_str ());
8618 /* Given TOK, a string specification of condition and thread, as
8619 accepted by the 'break' command, extract the condition
8620 string and thread number and set *COND_STRING and *THREAD.
8621 PC identifies the context at which the condition should be parsed.
8622 If no condition is found, *COND_STRING is set to NULL.
8623 If no thread is found, *THREAD is set to -1. */
8626 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
8627 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8628 int *thread
, int *task
,
8629 gdb::unique_xmalloc_ptr
<char> *rest
)
8631 cond_string
->reset ();
8639 const char *end_tok
;
8641 const char *cond_start
= NULL
;
8642 const char *cond_end
= NULL
;
8644 tok
= skip_spaces (tok
);
8646 if ((*tok
== '"' || *tok
== ',') && rest
)
8648 rest
->reset (savestring (tok
, strlen (tok
)));
8652 end_tok
= skip_to_space (tok
);
8654 toklen
= end_tok
- tok
;
8656 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8658 tok
= cond_start
= end_tok
+ 1;
8661 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
8663 catch (const gdb_exception_error
&)
8668 tok
= tok
+ strlen (tok
);
8671 cond_string
->reset (savestring (cond_start
, cond_end
- cond_start
));
8673 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
8678 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8681 struct thread_info
*thr
;
8684 thr
= parse_thread_id (tok
, &tmptok
);
8686 error (_("Junk after thread keyword."));
8687 *thread
= thr
->global_num
;
8690 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8695 *task
= strtol (tok
, &tmptok
, 0);
8697 error (_("Junk after task keyword."));
8698 if (!valid_task_id (*task
))
8699 error (_("Unknown task %d."), *task
);
8704 rest
->reset (savestring (tok
, strlen (tok
)));
8708 error (_("Junk at end of arguments."));
8712 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
8713 succeeds. The parsed values are written to COND_STRING, THREAD,
8714 TASK, and REST. See the comment of 'find_condition_and_thread'
8715 for the description of these parameters and INPUT. */
8718 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
8720 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8721 int *thread
, int *task
,
8722 gdb::unique_xmalloc_ptr
<char> *rest
)
8724 int num_failures
= 0;
8725 for (auto &sal
: sals
)
8727 gdb::unique_xmalloc_ptr
<char> cond
;
8730 gdb::unique_xmalloc_ptr
<char> remaining
;
8732 /* Here we want to parse 'arg' to separate condition from thread
8733 number. But because parsing happens in a context and the
8734 contexts of sals might be different, try each until there is
8735 success. Finding one successful parse is sufficient for our
8736 goal. When setting the breakpoint we'll re-parse the
8737 condition in the context of each sal. */
8740 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
8741 &task_id
, &remaining
);
8742 *cond_string
= std::move (cond
);
8743 *thread
= thread_id
;
8745 *rest
= std::move (remaining
);
8748 catch (const gdb_exception_error
&e
)
8751 /* If no sal remains, do not continue. */
8752 if (num_failures
== sals
.size ())
8758 /* Decode a static tracepoint marker spec. */
8760 static std::vector
<symtab_and_line
>
8761 decode_static_tracepoint_spec (const char **arg_p
)
8763 const char *p
= &(*arg_p
)[3];
8766 p
= skip_spaces (p
);
8768 endp
= skip_to_space (p
);
8770 std::string
marker_str (p
, endp
- p
);
8772 std::vector
<static_tracepoint_marker
> markers
8773 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
8774 if (markers
.empty ())
8775 error (_("No known static tracepoint marker named %s"),
8776 marker_str
.c_str ());
8778 std::vector
<symtab_and_line
> sals
;
8779 sals
.reserve (markers
.size ());
8781 for (const static_tracepoint_marker
&marker
: markers
)
8783 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
8784 sal
.pc
= marker
.address
;
8785 sals
.push_back (sal
);
8792 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
8793 according to IS_TRACEPOINT. */
8795 static const struct breakpoint_ops
*
8796 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
8801 if (location_type
== PROBE_LOCATION
)
8802 return &tracepoint_probe_breakpoint_ops
;
8804 return &vtable_breakpoint_ops
;
8808 if (location_type
== PROBE_LOCATION
)
8809 return &bkpt_probe_breakpoint_ops
;
8811 return &bkpt_breakpoint_ops
;
8815 /* See breakpoint.h. */
8817 const struct breakpoint_ops
*
8818 breakpoint_ops_for_event_location (const struct event_location
*location
,
8821 if (location
!= nullptr)
8822 return breakpoint_ops_for_event_location_type
8823 (event_location_type (location
), is_tracepoint
);
8824 return is_tracepoint
? &vtable_breakpoint_ops
: &bkpt_breakpoint_ops
;
8827 /* See breakpoint.h. */
8830 create_breakpoint (struct gdbarch
*gdbarch
,
8831 struct event_location
*location
,
8832 const char *cond_string
,
8833 int thread
, const char *extra_string
,
8834 bool force_condition
, int parse_extra
,
8835 int tempflag
, enum bptype type_wanted
,
8837 enum auto_boolean pending_break_support
,
8838 const struct breakpoint_ops
*ops
,
8839 int from_tty
, int enabled
, int internal
,
8842 struct linespec_result canonical
;
8845 int prev_bkpt_count
= breakpoint_count
;
8847 gdb_assert (ops
!= NULL
);
8849 /* If extra_string isn't useful, set it to NULL. */
8850 if (extra_string
!= NULL
&& *extra_string
== '\0')
8851 extra_string
= NULL
;
8855 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
8857 catch (const gdb_exception_error
&e
)
8859 /* If caller is interested in rc value from parse, set
8861 if (e
.error
== NOT_FOUND_ERROR
)
8863 /* If pending breakpoint support is turned off, throw
8866 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
8869 exception_print (gdb_stderr
, e
);
8871 /* If pending breakpoint support is auto query and the user
8872 selects no, then simply return the error code. */
8873 if (pending_break_support
== AUTO_BOOLEAN_AUTO
8874 && !nquery (_("Make %s pending on future shared library load? "),
8875 bptype_string (type_wanted
)))
8878 /* At this point, either the user was queried about setting
8879 a pending breakpoint and selected yes, or pending
8880 breakpoint behavior is on and thus a pending breakpoint
8881 is defaulted on behalf of the user. */
8888 if (!pending
&& canonical
.lsals
.empty ())
8891 /* Resolve all line numbers to PC's and verify that the addresses
8892 are ok for the target. */
8895 for (auto &lsal
: canonical
.lsals
)
8896 breakpoint_sals_to_pc (lsal
.sals
);
8899 /* Fast tracepoints may have additional restrictions on location. */
8900 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
8902 for (const auto &lsal
: canonical
.lsals
)
8903 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
8906 /* Verify that condition can be parsed, before setting any
8907 breakpoints. Allocate a separate condition expression for each
8911 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
8912 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
8916 gdb::unique_xmalloc_ptr
<char> rest
;
8917 gdb::unique_xmalloc_ptr
<char> cond
;
8919 const linespec_sals
&lsal
= canonical
.lsals
[0];
8921 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
8922 &cond
, &thread
, &task
, &rest
);
8923 cond_string_copy
= std::move (cond
);
8924 extra_string_copy
= std::move (rest
);
8928 if (type_wanted
!= bp_dprintf
8929 && extra_string
!= NULL
&& *extra_string
!= '\0')
8930 error (_("Garbage '%s' at end of location"), extra_string
);
8932 /* Check the validity of the condition. We should error out
8933 if the condition is invalid at all of the locations and
8934 if it is not forced. In the PARSE_EXTRA case above, this
8935 check is done when parsing the EXTRA_STRING. */
8936 if (cond_string
!= nullptr && !force_condition
)
8938 int num_failures
= 0;
8939 const linespec_sals
&lsal
= canonical
.lsals
[0];
8940 for (const auto &sal
: lsal
.sals
)
8942 const char *cond
= cond_string
;
8945 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
8946 /* One success is sufficient to keep going. */
8949 catch (const gdb_exception_error
&)
8952 /* If this is the last sal, error out. */
8953 if (num_failures
== lsal
.sals
.size ())
8959 /* Create a private copy of condition string. */
8961 cond_string_copy
.reset (xstrdup (cond_string
));
8962 /* Create a private copy of any extra string. */
8964 extra_string_copy
.reset (xstrdup (extra_string
));
8967 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
8968 std::move (cond_string_copy
),
8969 std::move (extra_string_copy
),
8971 tempflag
? disp_del
: disp_donttouch
,
8972 thread
, task
, ignore_count
, ops
,
8973 from_tty
, enabled
, internal
, flags
);
8977 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
8979 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
8980 b
->location
= copy_event_location (location
);
8983 b
->cond_string
= NULL
;
8986 /* Create a private copy of condition string. */
8987 b
->cond_string
.reset (cond_string
!= NULL
8988 ? xstrdup (cond_string
)
8993 /* Create a private copy of any extra string. */
8994 b
->extra_string
.reset (extra_string
!= NULL
8995 ? xstrdup (extra_string
)
8997 b
->ignore_count
= ignore_count
;
8998 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8999 b
->condition_not_parsed
= 1;
9000 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9001 if ((type_wanted
!= bp_breakpoint
9002 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9003 b
->pspace
= current_program_space
;
9005 install_breakpoint (internal
, std::move (b
), 0);
9008 if (canonical
.lsals
.size () > 1)
9010 warning (_("Multiple breakpoints were set.\nUse the "
9011 "\"delete\" command to delete unwanted breakpoints."));
9012 prev_breakpoint_count
= prev_bkpt_count
;
9015 update_global_location_list (UGLL_MAY_INSERT
);
9020 /* Set a breakpoint.
9021 ARG is a string describing breakpoint address,
9022 condition, and thread.
9023 FLAG specifies if a breakpoint is hardware on,
9024 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9028 break_command_1 (const char *arg
, int flag
, int from_tty
)
9030 int tempflag
= flag
& BP_TEMPFLAG
;
9031 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9032 ? bp_hardware_breakpoint
9035 event_location_up location
= string_to_event_location (&arg
, current_language
);
9036 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9037 (location
.get (), false /* is_tracepoint */);
9039 create_breakpoint (get_current_arch (),
9041 NULL
, 0, arg
, false, 1 /* parse arg */,
9042 tempflag
, type_wanted
,
9043 0 /* Ignore count */,
9044 pending_break_support
,
9052 /* Helper function for break_command_1 and disassemble_command. */
9055 resolve_sal_pc (struct symtab_and_line
*sal
)
9059 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9061 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9062 error (_("No line %d in file \"%s\"."),
9063 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9066 /* If this SAL corresponds to a breakpoint inserted using a line
9067 number, then skip the function prologue if necessary. */
9068 if (sal
->explicit_line
)
9069 skip_prologue_sal (sal
);
9072 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9074 const struct blockvector
*bv
;
9075 const struct block
*b
;
9078 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9079 sal
->symtab
->compunit ());
9082 sym
= block_linkage_function (b
);
9085 fixup_symbol_section (sym
, sal
->symtab
->compunit ()->objfile ());
9087 = sym
->obj_section (sal
->symtab
->compunit ()->objfile ());
9091 /* It really is worthwhile to have the section, so we'll
9092 just have to look harder. This case can be executed
9093 if we have line numbers but no functions (as can
9094 happen in assembly source). */
9096 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9097 switch_to_program_space_and_thread (sal
->pspace
);
9099 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9101 sal
->section
= msym
.obj_section ();
9108 break_command (const char *arg
, int from_tty
)
9110 break_command_1 (arg
, 0, from_tty
);
9114 tbreak_command (const char *arg
, int from_tty
)
9116 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9120 hbreak_command (const char *arg
, int from_tty
)
9122 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9126 thbreak_command (const char *arg
, int from_tty
)
9128 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9131 /* The dynamic printf command is mostly like a regular breakpoint, but
9132 with a prewired command list consisting of a single output command,
9133 built from extra arguments supplied on the dprintf command
9137 dprintf_command (const char *arg
, int from_tty
)
9139 event_location_up location
= string_to_event_location (&arg
, current_language
);
9141 /* If non-NULL, ARG should have been advanced past the location;
9142 the next character must be ','. */
9145 if (arg
[0] != ',' || arg
[1] == '\0')
9146 error (_("Format string required"));
9149 /* Skip the comma. */
9154 create_breakpoint (get_current_arch (),
9156 NULL
, 0, arg
, false, 1 /* parse arg */,
9158 0 /* Ignore count */,
9159 pending_break_support
,
9160 &dprintf_breakpoint_ops
,
9168 agent_printf_command (const char *arg
, int from_tty
)
9170 error (_("May only run agent-printf on the target"));
9173 /* Implement the "breakpoint_hit" breakpoint_ops method for
9174 ranged breakpoints. */
9177 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9178 const address_space
*aspace
,
9180 const target_waitstatus
&ws
)
9182 if (ws
.kind () != TARGET_WAITKIND_STOPPED
9183 || ws
.sig () != GDB_SIGNAL_TRAP
)
9186 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9187 bl
->length
, aspace
, bp_addr
);
9190 /* Implement the "resources_needed" breakpoint_ops method for
9191 ranged breakpoints. */
9194 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9196 return target_ranged_break_num_registers ();
9199 /* Implement the "print_it" breakpoint_ops method for
9200 ranged breakpoints. */
9202 static enum print_stop_action
9203 print_it_ranged_breakpoint (bpstat
*bs
)
9205 struct breakpoint
*b
= bs
->breakpoint_at
;
9206 struct bp_location
*bl
= b
->loc
;
9207 struct ui_out
*uiout
= current_uiout
;
9209 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9211 /* Ranged breakpoints have only one location. */
9212 gdb_assert (bl
&& bl
->next
== NULL
);
9214 annotate_breakpoint (b
->number
);
9216 maybe_print_thread_hit_breakpoint (uiout
);
9218 if (b
->disposition
== disp_del
)
9219 uiout
->text ("Temporary ranged breakpoint ");
9221 uiout
->text ("Ranged breakpoint ");
9222 if (uiout
->is_mi_like_p ())
9224 uiout
->field_string ("reason",
9225 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9226 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9228 uiout
->field_signed ("bkptno", b
->number
);
9231 return PRINT_SRC_AND_LOC
;
9234 /* Implement the "print_one" breakpoint_ops method for
9235 ranged breakpoints. */
9238 print_one_ranged_breakpoint (struct breakpoint
*b
,
9239 struct bp_location
**last_loc
)
9241 struct bp_location
*bl
= b
->loc
;
9242 struct value_print_options opts
;
9243 struct ui_out
*uiout
= current_uiout
;
9245 /* Ranged breakpoints have only one location. */
9246 gdb_assert (bl
&& bl
->next
== NULL
);
9248 get_user_print_options (&opts
);
9250 if (opts
.addressprint
)
9251 /* We don't print the address range here, it will be printed later
9252 by print_one_detail_ranged_breakpoint. */
9253 uiout
->field_skip ("addr");
9255 print_breakpoint_location (b
, bl
);
9261 /* Implement the "print_one_detail" breakpoint_ops method for
9262 ranged breakpoints. */
9265 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9266 struct ui_out
*uiout
)
9268 CORE_ADDR address_start
, address_end
;
9269 struct bp_location
*bl
= b
->loc
;
9274 address_start
= bl
->address
;
9275 address_end
= address_start
+ bl
->length
- 1;
9277 uiout
->text ("\taddress range: ");
9278 stb
.printf ("[%s, %s]",
9279 print_core_address (bl
->gdbarch
, address_start
),
9280 print_core_address (bl
->gdbarch
, address_end
));
9281 uiout
->field_stream ("addr", stb
);
9285 /* Implement the "print_mention" breakpoint_ops method for
9286 ranged breakpoints. */
9289 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9291 struct bp_location
*bl
= b
->loc
;
9292 struct ui_out
*uiout
= current_uiout
;
9295 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9297 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9298 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9299 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9302 /* Implement the "print_recreate" breakpoint_ops method for
9303 ranged breakpoints. */
9306 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9308 gdb_printf (fp
, "break-range %s, %s",
9309 event_location_to_string (b
->location
.get ()),
9310 event_location_to_string (b
->location_range_end
.get ()));
9311 print_recreate_thread (b
, fp
);
9314 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9316 static struct breakpoint_ops ranged_breakpoint_ops
;
9318 /* Find the address where the end of the breakpoint range should be
9319 placed, given the SAL of the end of the range. This is so that if
9320 the user provides a line number, the end of the range is set to the
9321 last instruction of the given line. */
9324 find_breakpoint_range_end (struct symtab_and_line sal
)
9328 /* If the user provided a PC value, use it. Otherwise,
9329 find the address of the end of the given location. */
9330 if (sal
.explicit_pc
)
9337 ret
= find_line_pc_range (sal
, &start
, &end
);
9339 error (_("Could not find location of the end of the range."));
9341 /* find_line_pc_range returns the start of the next line. */
9348 /* Implement the "break-range" CLI command. */
9351 break_range_command (const char *arg
, int from_tty
)
9353 const char *arg_start
;
9354 struct linespec_result canonical_start
, canonical_end
;
9355 int bp_count
, can_use_bp
, length
;
9357 struct breakpoint
*b
;
9359 /* We don't support software ranged breakpoints. */
9360 if (target_ranged_break_num_registers () < 0)
9361 error (_("This target does not support hardware ranged breakpoints."));
9363 bp_count
= hw_breakpoint_used_count ();
9364 bp_count
+= target_ranged_break_num_registers ();
9365 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9368 error (_("Hardware breakpoints used exceeds limit."));
9370 arg
= skip_spaces (arg
);
9371 if (arg
== NULL
|| arg
[0] == '\0')
9372 error(_("No address range specified."));
9375 event_location_up start_location
= string_to_event_location (&arg
,
9377 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9380 error (_("Too few arguments."));
9381 else if (canonical_start
.lsals
.empty ())
9382 error (_("Could not find location of the beginning of the range."));
9384 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9386 if (canonical_start
.lsals
.size () > 1
9387 || lsal_start
.sals
.size () != 1)
9388 error (_("Cannot create a ranged breakpoint with multiple locations."));
9390 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9391 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9393 arg
++; /* Skip the comma. */
9394 arg
= skip_spaces (arg
);
9396 /* Parse the end location. */
9400 /* We call decode_line_full directly here instead of using
9401 parse_breakpoint_sals because we need to specify the start location's
9402 symtab and line as the default symtab and line for the end of the
9403 range. This makes it possible to have ranges like "foo.c:27, +14",
9404 where +14 means 14 lines from the start location. */
9405 event_location_up end_location
= string_to_event_location (&arg
,
9407 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9408 sal_start
.symtab
, sal_start
.line
,
9409 &canonical_end
, NULL
, NULL
);
9411 if (canonical_end
.lsals
.empty ())
9412 error (_("Could not find location of the end of the range."));
9414 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9415 if (canonical_end
.lsals
.size () > 1
9416 || lsal_end
.sals
.size () != 1)
9417 error (_("Cannot create a ranged breakpoint with multiple locations."));
9419 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9421 end
= find_breakpoint_range_end (sal_end
);
9422 if (sal_start
.pc
> end
)
9423 error (_("Invalid address range, end precedes start."));
9425 length
= end
- sal_start
.pc
+ 1;
9427 /* Length overflowed. */
9428 error (_("Address range too large."));
9429 else if (length
== 1)
9431 /* This range is simple enough to be handled by
9432 the `hbreak' command. */
9433 hbreak_command (&addr_string_start
[0], 1);
9438 /* Now set up the breakpoint. */
9439 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9440 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9441 set_breakpoint_count (breakpoint_count
+ 1);
9442 b
->number
= breakpoint_count
;
9443 b
->disposition
= disp_donttouch
;
9444 b
->location
= std::move (start_location
);
9445 b
->location_range_end
= std::move (end_location
);
9446 b
->loc
->length
= length
;
9449 gdb::observers::breakpoint_created
.notify (b
);
9450 update_global_location_list (UGLL_MAY_INSERT
);
9453 /* Return non-zero if EXP is verified as constant. Returned zero
9454 means EXP is variable. Also the constant detection may fail for
9455 some constant expressions and in such case still falsely return
9459 watchpoint_exp_is_const (const struct expression
*exp
)
9461 return exp
->op
->constant_p ();
9464 /* Implement the "re_set" method for watchpoints. */
9467 watchpoint::re_set ()
9469 /* Watchpoint can be either on expression using entirely global
9470 variables, or it can be on local variables.
9472 Watchpoints of the first kind are never auto-deleted, and even
9473 persist across program restarts. Since they can use variables
9474 from shared libraries, we need to reparse expression as libraries
9475 are loaded and unloaded.
9477 Watchpoints on local variables can also change meaning as result
9478 of solib event. For example, if a watchpoint uses both a local
9479 and a global variables in expression, it's a local watchpoint,
9480 but unloading of a shared library will make the expression
9481 invalid. This is not a very common use case, but we still
9482 re-evaluate expression, to avoid surprises to the user.
9484 Note that for local watchpoints, we re-evaluate it only if
9485 watchpoints frame id is still valid. If it's not, it means the
9486 watchpoint is out of scope and will be deleted soon. In fact,
9487 I'm not sure we'll ever be called in this case.
9489 If a local watchpoint's frame id is still valid, then
9490 exp_valid_block is likewise valid, and we can safely use it.
9492 Don't do anything about disabled watchpoints, since they will be
9493 reevaluated again when enabled. */
9494 update_watchpoint (this, 1 /* reparse */);
9497 /* Implement the "insert" method for hardware watchpoints. */
9500 watchpoint::insert_location (struct bp_location
*bl
)
9502 int length
= exact
? 1 : bl
->length
;
9504 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9508 /* Implement the "remove" method for hardware watchpoints. */
9511 watchpoint::remove_location (struct bp_location
*bl
,
9512 enum remove_bp_reason reason
)
9514 int length
= exact
? 1 : bl
->length
;
9516 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9521 watchpoint::breakpoint_hit (const struct bp_location
*bl
,
9522 const address_space
*aspace
, CORE_ADDR bp_addr
,
9523 const target_waitstatus
&ws
)
9525 struct breakpoint
*b
= bl
->owner
;
9527 /* Continuable hardware watchpoints are treated as non-existent if the
9528 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9529 some data address). Otherwise gdb won't stop on a break instruction
9530 in the code (not from a breakpoint) when a hardware watchpoint has
9531 been defined. Also skip watchpoints which we know did not trigger
9532 (did not match the data address). */
9533 if (is_hardware_watchpoint (b
)
9534 && watchpoint_triggered
== watch_triggered_no
)
9541 watchpoint::check_status (bpstat
*bs
)
9543 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
9545 bpstat_check_watchpoint (bs
);
9548 /* Implement the "resources_needed" method for hardware
9552 watchpoint::resources_needed (const struct bp_location
*bl
)
9554 int length
= exact
? 1 : bl
->length
;
9556 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9559 /* Implement the "works_in_software_mode" method for hardware
9563 watchpoint::works_in_software_mode () const
9565 /* Read and access watchpoints only work with hardware support. */
9566 return type
== bp_watchpoint
|| type
== bp_hardware_watchpoint
;
9569 enum print_stop_action
9570 watchpoint::print_it (bpstat
*bs
)
9572 struct breakpoint
*b
;
9573 enum print_stop_action result
;
9574 struct ui_out
*uiout
= current_uiout
;
9576 gdb_assert (bs
->bp_location_at
!= NULL
);
9578 b
= bs
->breakpoint_at
;
9580 annotate_watchpoint (b
->number
);
9581 maybe_print_thread_hit_breakpoint (uiout
);
9585 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
9589 case bp_hardware_watchpoint
:
9590 if (uiout
->is_mi_like_p ())
9592 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9594 tuple_emitter
.emplace (uiout
, "value");
9595 uiout
->text ("\nOld value = ");
9596 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9597 uiout
->field_stream ("old", stb
);
9598 uiout
->text ("\nNew value = ");
9599 watchpoint_value_print (val
.get (), &stb
);
9600 uiout
->field_stream ("new", stb
);
9602 /* More than one watchpoint may have been triggered. */
9603 result
= PRINT_UNKNOWN
;
9606 case bp_read_watchpoint
:
9607 if (uiout
->is_mi_like_p ())
9609 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9611 tuple_emitter
.emplace (uiout
, "value");
9612 uiout
->text ("\nValue = ");
9613 watchpoint_value_print (val
.get (), &stb
);
9614 uiout
->field_stream ("value", stb
);
9616 result
= PRINT_UNKNOWN
;
9619 case bp_access_watchpoint
:
9620 if (bs
->old_val
!= NULL
)
9622 if (uiout
->is_mi_like_p ())
9625 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9627 tuple_emitter
.emplace (uiout
, "value");
9628 uiout
->text ("\nOld value = ");
9629 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9630 uiout
->field_stream ("old", stb
);
9631 uiout
->text ("\nNew value = ");
9636 if (uiout
->is_mi_like_p ())
9639 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9640 tuple_emitter
.emplace (uiout
, "value");
9641 uiout
->text ("\nValue = ");
9643 watchpoint_value_print (val
.get (), &stb
);
9644 uiout
->field_stream ("new", stb
);
9646 result
= PRINT_UNKNOWN
;
9649 result
= PRINT_UNKNOWN
;
9655 /* Implement the "print_mention" method for hardware watchpoints. */
9658 watchpoint::print_mention ()
9660 struct ui_out
*uiout
= current_uiout
;
9661 const char *tuple_name
;
9666 uiout
->text ("Watchpoint ");
9669 case bp_hardware_watchpoint
:
9670 uiout
->text ("Hardware watchpoint ");
9673 case bp_read_watchpoint
:
9674 uiout
->text ("Hardware read watchpoint ");
9675 tuple_name
= "hw-rwpt";
9677 case bp_access_watchpoint
:
9678 uiout
->text ("Hardware access (read/write) watchpoint ");
9679 tuple_name
= "hw-awpt";
9682 internal_error (__FILE__
, __LINE__
,
9683 _("Invalid hardware watchpoint type."));
9686 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9687 uiout
->field_signed ("number", number
);
9689 uiout
->field_string ("exp", exp_string
.get ());
9692 /* Implement the "print_recreate" method for watchpoints. */
9695 watchpoint::print_recreate (struct ui_file
*fp
)
9700 case bp_hardware_watchpoint
:
9701 gdb_printf (fp
, "watch");
9703 case bp_read_watchpoint
:
9704 gdb_printf (fp
, "rwatch");
9706 case bp_access_watchpoint
:
9707 gdb_printf (fp
, "awatch");
9710 internal_error (__FILE__
, __LINE__
,
9711 _("Invalid watchpoint type."));
9714 gdb_printf (fp
, " %s", exp_string
.get ());
9715 print_recreate_thread (this, fp
);
9718 /* Implement the "explains_signal" method for watchpoints. */
9721 watchpoint::explains_signal (enum gdb_signal sig
)
9723 /* A software watchpoint cannot cause a signal other than
9725 if (type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
9731 struct masked_watchpoint
: public watchpoint
9733 int insert_location (struct bp_location
*) override
;
9734 int remove_location (struct bp_location
*,
9735 enum remove_bp_reason reason
) override
;
9736 int resources_needed (const struct bp_location
*) override
;
9737 int works_in_software_mode () const override
;
9738 enum print_stop_action
print_it (struct bpstat
*bs
) override
;
9739 void print_one_detail (struct ui_out
*) const override
;
9740 void print_mention () override
;
9741 void print_recreate (struct ui_file
*fp
) override
;
9744 /* Implement the "insert" method for masked hardware watchpoints. */
9747 masked_watchpoint::insert_location (struct bp_location
*bl
)
9749 return target_insert_mask_watchpoint (bl
->address
, hw_wp_mask
,
9750 bl
->watchpoint_type
);
9753 /* Implement the "remove" method for masked hardware watchpoints. */
9756 masked_watchpoint::remove_location (struct bp_location
*bl
,
9757 enum remove_bp_reason reason
)
9759 return target_remove_mask_watchpoint (bl
->address
, hw_wp_mask
,
9760 bl
->watchpoint_type
);
9763 /* Implement the "resources_needed" method for masked hardware
9767 masked_watchpoint::resources_needed (const struct bp_location
*bl
)
9769 return target_masked_watch_num_registers (bl
->address
, hw_wp_mask
);
9772 /* Implement the "works_in_software_mode" method for masked hardware
9776 masked_watchpoint::works_in_software_mode () const
9781 /* Implement the "print_it" method for masked hardware
9784 enum print_stop_action
9785 masked_watchpoint::print_it (bpstat
*bs
)
9787 struct breakpoint
*b
= bs
->breakpoint_at
;
9788 struct ui_out
*uiout
= current_uiout
;
9790 /* Masked watchpoints have only one location. */
9791 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9793 annotate_watchpoint (b
->number
);
9794 maybe_print_thread_hit_breakpoint (uiout
);
9798 case bp_hardware_watchpoint
:
9799 if (uiout
->is_mi_like_p ())
9801 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9804 case bp_read_watchpoint
:
9805 if (uiout
->is_mi_like_p ())
9807 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9810 case bp_access_watchpoint
:
9811 if (uiout
->is_mi_like_p ())
9814 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9817 internal_error (__FILE__
, __LINE__
,
9818 _("Invalid hardware watchpoint type."));
9823 Check the underlying instruction at PC for the memory\n\
9824 address and value which triggered this watchpoint.\n"));
9827 /* More than one watchpoint may have been triggered. */
9828 return PRINT_UNKNOWN
;
9831 /* Implement the "print_one_detail" method for masked hardware
9835 masked_watchpoint::print_one_detail (struct ui_out
*uiout
) const
9837 /* Masked watchpoints have only one location. */
9838 gdb_assert (loc
&& loc
->next
== NULL
);
9840 uiout
->text ("\tmask ");
9841 uiout
->field_core_addr ("mask", loc
->gdbarch
, hw_wp_mask
);
9845 /* Implement the "print_mention" method for masked hardware
9849 masked_watchpoint::print_mention ()
9851 struct ui_out
*uiout
= current_uiout
;
9852 const char *tuple_name
;
9856 case bp_hardware_watchpoint
:
9857 uiout
->text ("Masked hardware watchpoint ");
9860 case bp_read_watchpoint
:
9861 uiout
->text ("Masked hardware read watchpoint ");
9862 tuple_name
= "hw-rwpt";
9864 case bp_access_watchpoint
:
9865 uiout
->text ("Masked hardware access (read/write) watchpoint ");
9866 tuple_name
= "hw-awpt";
9869 internal_error (__FILE__
, __LINE__
,
9870 _("Invalid hardware watchpoint type."));
9873 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9874 uiout
->field_signed ("number", number
);
9876 uiout
->field_string ("exp", exp_string
.get ());
9879 /* Implement the "print_recreate" method for masked hardware
9883 masked_watchpoint::print_recreate (struct ui_file
*fp
)
9887 case bp_hardware_watchpoint
:
9888 gdb_printf (fp
, "watch");
9890 case bp_read_watchpoint
:
9891 gdb_printf (fp
, "rwatch");
9893 case bp_access_watchpoint
:
9894 gdb_printf (fp
, "awatch");
9897 internal_error (__FILE__
, __LINE__
,
9898 _("Invalid hardware watchpoint type."));
9901 gdb_printf (fp
, " %s mask 0x%s", exp_string
.get (),
9902 phex (hw_wp_mask
, sizeof (CORE_ADDR
)));
9903 print_recreate_thread (this, fp
);
9906 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9909 is_masked_watchpoint (const struct breakpoint
*b
)
9911 return dynamic_cast<const masked_watchpoint
*> (b
) != nullptr;
9914 /* accessflag: hw_write: watch write,
9915 hw_read: watch read,
9916 hw_access: watch access (read or write) */
9918 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
9919 bool just_location
, bool internal
)
9921 struct breakpoint
*scope_breakpoint
= NULL
;
9922 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9923 struct value
*result
;
9924 int saved_bitpos
= 0, saved_bitsize
= 0;
9925 const char *exp_start
= NULL
;
9926 const char *exp_end
= NULL
;
9927 const char *tok
, *end_tok
;
9929 const char *cond_start
= NULL
;
9930 const char *cond_end
= NULL
;
9931 enum bptype bp_type
;
9933 /* Flag to indicate whether we are going to use masks for
9934 the hardware watchpoint. */
9935 bool use_mask
= false;
9939 /* Make sure that we actually have parameters to parse. */
9940 if (arg
!= NULL
&& arg
[0] != '\0')
9942 const char *value_start
;
9944 exp_end
= arg
+ strlen (arg
);
9946 /* Look for "parameter value" pairs at the end
9947 of the arguments string. */
9948 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
9950 /* Skip whitespace at the end of the argument list. */
9951 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9954 /* Find the beginning of the last token.
9955 This is the value of the parameter. */
9956 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9958 value_start
= tok
+ 1;
9960 /* Skip whitespace. */
9961 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9966 /* Find the beginning of the second to last token.
9967 This is the parameter itself. */
9968 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9971 toklen
= end_tok
- tok
+ 1;
9973 if (toklen
== 6 && startswith (tok
, "thread"))
9975 struct thread_info
*thr
;
9976 /* At this point we've found a "thread" token, which means
9977 the user is trying to set a watchpoint that triggers
9978 only in a specific thread. */
9982 error(_("You can specify only one thread."));
9984 /* Extract the thread ID from the next token. */
9985 thr
= parse_thread_id (value_start
, &endp
);
9987 /* Check if the user provided a valid thread ID. */
9988 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9989 invalid_thread_id_error (value_start
);
9991 thread
= thr
->global_num
;
9993 else if (toklen
== 4 && startswith (tok
, "task"))
9997 task
= strtol (value_start
, &tmp
, 0);
9998 if (tmp
== value_start
)
9999 error (_("Junk after task keyword."));
10000 if (!valid_task_id (task
))
10001 error (_("Unknown task %d."), task
);
10003 else if (toklen
== 4 && startswith (tok
, "mask"))
10005 /* We've found a "mask" token, which means the user wants to
10006 create a hardware watchpoint that is going to have the mask
10008 struct value
*mask_value
, *mark
;
10011 error(_("You can specify only one mask."));
10013 use_mask
= just_location
= true;
10015 mark
= value_mark ();
10016 mask_value
= parse_to_comma_and_eval (&value_start
);
10017 mask
= value_as_address (mask_value
);
10018 value_free_to_mark (mark
);
10021 /* We didn't recognize what we found. We should stop here. */
10024 /* Truncate the string and get rid of the "parameter value" pair before
10025 the arguments string is parsed by the parse_exp_1 function. */
10032 /* Parse the rest of the arguments. From here on out, everything
10033 is in terms of a newly allocated string instead of the original
10035 std::string
expression (arg
, exp_end
- arg
);
10036 exp_start
= arg
= expression
.c_str ();
10037 innermost_block_tracker tracker
;
10038 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10040 /* Remove trailing whitespace from the expression before saving it.
10041 This makes the eventual display of the expression string a bit
10043 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10046 /* Checking if the expression is not constant. */
10047 if (watchpoint_exp_is_const (exp
.get ()))
10051 len
= exp_end
- exp_start
;
10052 while (len
> 0 && isspace (exp_start
[len
- 1]))
10054 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10057 exp_valid_block
= tracker
.block ();
10058 struct value
*mark
= value_mark ();
10059 struct value
*val_as_value
= nullptr;
10060 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10063 if (val_as_value
!= NULL
&& just_location
)
10065 saved_bitpos
= value_bitpos (val_as_value
);
10066 saved_bitsize
= value_bitsize (val_as_value
);
10074 exp_valid_block
= NULL
;
10075 val
= release_value (value_addr (result
));
10076 value_free_to_mark (mark
);
10080 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10083 error (_("This target does not support masked watchpoints."));
10084 else if (ret
== -2)
10085 error (_("Invalid mask or memory region."));
10088 else if (val_as_value
!= NULL
)
10089 val
= release_value (val_as_value
);
10091 tok
= skip_spaces (arg
);
10092 end_tok
= skip_to_space (tok
);
10094 toklen
= end_tok
- tok
;
10095 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10097 tok
= cond_start
= end_tok
+ 1;
10098 innermost_block_tracker if_tracker
;
10099 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10101 /* The watchpoint expression may not be local, but the condition
10102 may still be. E.g.: `watch global if local > 0'. */
10103 cond_exp_valid_block
= if_tracker
.block ();
10108 error (_("Junk at end of command."));
10110 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10112 /* Save this because create_internal_breakpoint below invalidates
10114 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10116 /* If the expression is "local", then set up a "watchpoint scope"
10117 breakpoint at the point where we've left the scope of the watchpoint
10118 expression. Create the scope breakpoint before the watchpoint, so
10119 that we will encounter it first in bpstat_stop_status. */
10120 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10122 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10124 if (frame_id_p (caller_frame_id
))
10126 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10127 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10130 = create_internal_breakpoint (caller_arch
, caller_pc
,
10131 bp_watchpoint_scope
,
10132 &momentary_breakpoint_ops
);
10134 /* create_internal_breakpoint could invalidate WP_FRAME. */
10137 scope_breakpoint
->enable_state
= bp_enabled
;
10139 /* Automatically delete the breakpoint when it hits. */
10140 scope_breakpoint
->disposition
= disp_del
;
10142 /* Only break in the proper frame (help with recursion). */
10143 scope_breakpoint
->frame_id
= caller_frame_id
;
10145 /* Set the address at which we will stop. */
10146 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10147 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10148 scope_breakpoint
->loc
->address
10149 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10150 scope_breakpoint
->loc
->requested_address
,
10151 scope_breakpoint
->type
);
10155 /* Now set up the breakpoint. We create all watchpoints as hardware
10156 watchpoints here even if hardware watchpoints are turned off, a call
10157 to update_watchpoint later in this function will cause the type to
10158 drop back to bp_watchpoint (software watchpoint) if required. */
10160 if (accessflag
== hw_read
)
10161 bp_type
= bp_read_watchpoint
;
10162 else if (accessflag
== hw_access
)
10163 bp_type
= bp_access_watchpoint
;
10165 bp_type
= bp_hardware_watchpoint
;
10167 std::unique_ptr
<watchpoint
> w
;
10169 w
.reset (new masked_watchpoint ());
10171 w
.reset (new watchpoint ());
10172 init_raw_breakpoint_without_location (w
.get (), nullptr, bp_type
,
10173 &vtable_breakpoint_ops
);
10175 w
->thread
= thread
;
10177 w
->disposition
= disp_donttouch
;
10178 w
->pspace
= current_program_space
;
10179 w
->exp
= std::move (exp
);
10180 w
->exp_valid_block
= exp_valid_block
;
10181 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10184 struct type
*t
= value_type (val
.get ());
10185 CORE_ADDR addr
= value_as_address (val
.get ());
10187 w
->exp_string_reparse
10188 = current_language
->watch_location_expression (t
, addr
);
10190 w
->exp_string
= xstrprintf ("-location %.*s",
10191 (int) (exp_end
- exp_start
), exp_start
);
10194 w
->exp_string
.reset (savestring (exp_start
, exp_end
- exp_start
));
10198 w
->hw_wp_mask
= mask
;
10203 w
->val_bitpos
= saved_bitpos
;
10204 w
->val_bitsize
= saved_bitsize
;
10205 w
->val_valid
= true;
10209 w
->cond_string
.reset (savestring (cond_start
, cond_end
- cond_start
));
10211 w
->cond_string
= 0;
10213 if (frame_id_p (watchpoint_frame
))
10215 w
->watchpoint_frame
= watchpoint_frame
;
10216 w
->watchpoint_thread
= inferior_ptid
;
10220 w
->watchpoint_frame
= null_frame_id
;
10221 w
->watchpoint_thread
= null_ptid
;
10224 if (scope_breakpoint
!= NULL
)
10226 /* The scope breakpoint is related to the watchpoint. We will
10227 need to act on them together. */
10228 w
->related_breakpoint
= scope_breakpoint
;
10229 scope_breakpoint
->related_breakpoint
= w
.get ();
10232 if (!just_location
)
10233 value_free_to_mark (mark
);
10235 /* Finally update the new watchpoint. This creates the locations
10236 that should be inserted. */
10237 update_watchpoint (w
.get (), 1);
10239 install_breakpoint (internal
, std::move (w
), 1);
10242 /* Return count of debug registers needed to watch the given expression.
10243 If the watchpoint cannot be handled in hardware return zero. */
10246 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10248 int found_memory_cnt
= 0;
10250 /* Did the user specifically forbid us to use hardware watchpoints? */
10251 if (!can_use_hw_watchpoints
)
10254 gdb_assert (!vals
.empty ());
10255 struct value
*head
= vals
[0].get ();
10257 /* Make sure that the value of the expression depends only upon
10258 memory contents, and values computed from them within GDB. If we
10259 find any register references or function calls, we can't use a
10260 hardware watchpoint.
10262 The idea here is that evaluating an expression generates a series
10263 of values, one holding the value of every subexpression. (The
10264 expression a*b+c has five subexpressions: a, b, a*b, c, and
10265 a*b+c.) GDB's values hold almost enough information to establish
10266 the criteria given above --- they identify memory lvalues,
10267 register lvalues, computed values, etcetera. So we can evaluate
10268 the expression, and then scan the chain of values that leaves
10269 behind to decide whether we can detect any possible change to the
10270 expression's final value using only hardware watchpoints.
10272 However, I don't think that the values returned by inferior
10273 function calls are special in any way. So this function may not
10274 notice that an expression involving an inferior function call
10275 can't be watched with hardware watchpoints. FIXME. */
10276 for (const value_ref_ptr
&iter
: vals
)
10278 struct value
*v
= iter
.get ();
10280 if (VALUE_LVAL (v
) == lval_memory
)
10282 if (v
!= head
&& value_lazy (v
))
10283 /* A lazy memory lvalue in the chain is one that GDB never
10284 needed to fetch; we either just used its address (e.g.,
10285 `a' in `a.b') or we never needed it at all (e.g., `a'
10286 in `a,b'). This doesn't apply to HEAD; if that is
10287 lazy then it was not readable, but watch it anyway. */
10291 /* Ahh, memory we actually used! Check if we can cover
10292 it with hardware watchpoints. */
10293 struct type
*vtype
= check_typedef (value_type (v
));
10295 /* We only watch structs and arrays if user asked for it
10296 explicitly, never if they just happen to appear in a
10297 middle of some value chain. */
10299 || (vtype
->code () != TYPE_CODE_STRUCT
10300 && vtype
->code () != TYPE_CODE_ARRAY
))
10302 CORE_ADDR vaddr
= value_address (v
);
10306 len
= (target_exact_watchpoints
10307 && is_scalar_type_recursive (vtype
))?
10308 1 : TYPE_LENGTH (value_type (v
));
10310 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10314 found_memory_cnt
+= num_regs
;
10318 else if (VALUE_LVAL (v
) != not_lval
10319 && deprecated_value_modifiable (v
) == 0)
10320 return 0; /* These are values from the history (e.g., $1). */
10321 else if (VALUE_LVAL (v
) == lval_register
)
10322 return 0; /* Cannot watch a register with a HW watchpoint. */
10325 /* The expression itself looks suitable for using a hardware
10326 watchpoint, but give the target machine a chance to reject it. */
10327 return found_memory_cnt
;
10331 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10333 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10336 /* Options for the watch, awatch, and rwatch commands. */
10338 struct watch_options
10340 /* For -location. */
10341 bool location
= false;
10344 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10346 Historically GDB always accepted both '-location' and '-l' flags for
10347 these commands (both flags being synonyms). When converting to the
10348 newer option scheme only '-location' is added here. That's fine (for
10349 backward compatibility) as any non-ambiguous prefix of a flag will be
10350 accepted, so '-l', '-loc', are now all accepted.
10352 What this means is that, if in the future, we add any new flag here
10353 that starts with '-l' then this will break backward compatibility, so
10354 please, don't do that! */
10356 static const gdb::option::option_def watch_option_defs
[] = {
10357 gdb::option::flag_option_def
<watch_options
> {
10359 [] (watch_options
*opt
) { return &opt
->location
; },
10361 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10362 -l can be used as a short form of -location."),
10366 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10369 static gdb::option::option_def_group
10370 make_watch_options_def_group (watch_options
*opts
)
10372 return {{watch_option_defs
}, opts
};
10375 /* A helper function that looks for the "-location" argument and then
10376 calls watch_command_1. */
10379 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10381 watch_options opts
;
10382 auto grp
= make_watch_options_def_group (&opts
);
10383 gdb::option::process_options
10384 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
10385 if (arg
!= nullptr && *arg
== '\0')
10388 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
10391 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10393 watch_command_completer (struct cmd_list_element
*ignore
,
10394 completion_tracker
&tracker
,
10395 const char *text
, const char * /*word*/)
10397 const auto group
= make_watch_options_def_group (nullptr);
10398 if (gdb::option::complete_options
10399 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
10402 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
10403 expression_completer (ignore
, tracker
, text
, word
);
10407 watch_command (const char *arg
, int from_tty
)
10409 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10413 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10415 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10419 rwatch_command (const char *arg
, int from_tty
)
10421 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10425 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10427 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10431 awatch_command (const char *arg
, int from_tty
)
10433 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10437 /* Data for the FSM that manages the until(location)/advance commands
10438 in infcmd.c. Here because it uses the mechanisms of
10441 struct until_break_fsm
: public thread_fsm
10443 /* The thread that was current when the command was executed. */
10446 /* The breakpoint set at the return address in the caller frame,
10447 plus breakpoints at all the destination locations. */
10448 std::vector
<breakpoint_up
> breakpoints
;
10450 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10451 std::vector
<breakpoint_up
> &&breakpoints
)
10452 : thread_fsm (cmd_interp
),
10454 breakpoints (std::move (breakpoints
))
10458 void clean_up (struct thread_info
*thread
) override
;
10459 bool should_stop (struct thread_info
*thread
) override
;
10460 enum async_reply_reason
do_async_reply_reason () override
;
10463 /* Implementation of the 'should_stop' FSM method for the
10464 until(location)/advance commands. */
10467 until_break_fsm::should_stop (struct thread_info
*tp
)
10469 for (const breakpoint_up
&bp
: breakpoints
)
10470 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10471 bp
.get ()) != NULL
)
10480 /* Implementation of the 'clean_up' FSM method for the
10481 until(location)/advance commands. */
10484 until_break_fsm::clean_up (struct thread_info
*)
10486 /* Clean up our temporary breakpoints. */
10487 breakpoints
.clear ();
10488 delete_longjmp_breakpoint (thread
);
10491 /* Implementation of the 'async_reply_reason' FSM method for the
10492 until(location)/advance commands. */
10494 enum async_reply_reason
10495 until_break_fsm::do_async_reply_reason ()
10497 return EXEC_ASYNC_LOCATION_REACHED
;
10501 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10503 struct frame_info
*frame
;
10504 struct gdbarch
*frame_gdbarch
;
10505 struct frame_id stack_frame_id
;
10506 struct frame_id caller_frame_id
;
10508 struct thread_info
*tp
;
10510 clear_proceed_status (0);
10512 /* Set a breakpoint where the user wants it and at return from
10515 event_location_up location
= string_to_event_location (&arg
, current_language
);
10517 std::vector
<symtab_and_line
> sals
10518 = (last_displayed_sal_is_valid ()
10519 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10520 get_last_displayed_symtab (),
10521 get_last_displayed_line ())
10522 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
10526 error (_("Couldn't get information on specified line."));
10529 error (_("Junk at end of arguments."));
10531 tp
= inferior_thread ();
10532 thread
= tp
->global_num
;
10534 /* Note linespec handling above invalidates the frame chain.
10535 Installing a breakpoint also invalidates the frame chain (as it
10536 may need to switch threads), so do any frame handling before
10539 frame
= get_selected_frame (NULL
);
10540 frame_gdbarch
= get_frame_arch (frame
);
10541 stack_frame_id
= get_stack_frame_id (frame
);
10542 caller_frame_id
= frame_unwind_caller_id (frame
);
10544 /* Keep within the current frame, or in frames called by the current
10547 std::vector
<breakpoint_up
> breakpoints
;
10549 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
10551 if (frame_id_p (caller_frame_id
))
10553 struct symtab_and_line sal2
;
10554 struct gdbarch
*caller_gdbarch
;
10556 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10557 sal2
.pc
= frame_unwind_caller_pc (frame
);
10558 caller_gdbarch
= frame_unwind_caller_arch (frame
);
10560 breakpoint_up caller_breakpoint
10561 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
10562 caller_frame_id
, bp_until
);
10563 breakpoints
.emplace_back (std::move (caller_breakpoint
));
10565 set_longjmp_breakpoint (tp
, caller_frame_id
);
10566 lj_deleter
.emplace (thread
);
10569 /* set_momentary_breakpoint could invalidate FRAME. */
10572 /* If the user told us to continue until a specified location, we
10573 don't specify a frame at which we need to stop. Otherwise,
10574 specify the selected frame, because we want to stop only at the
10575 very same frame. */
10576 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
10578 for (symtab_and_line
&sal
: sals
)
10580 resolve_sal_pc (&sal
);
10582 breakpoint_up location_breakpoint
10583 = set_momentary_breakpoint (frame_gdbarch
, sal
,
10584 stop_frame_id
, bp_until
);
10585 breakpoints
.emplace_back (std::move (location_breakpoint
));
10589 (std::unique_ptr
<thread_fsm
>
10590 (new until_break_fsm (command_interp (), tp
->global_num
,
10591 std::move (breakpoints
))));
10594 lj_deleter
->release ();
10596 proceed (-1, GDB_SIGNAL_DEFAULT
);
10600 init_ada_exception_breakpoint (struct breakpoint
*b
,
10601 struct gdbarch
*gdbarch
,
10602 struct symtab_and_line sal
,
10603 const char *addr_string
,
10604 const struct breakpoint_ops
*ops
,
10611 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
10613 loc_gdbarch
= gdbarch
;
10615 describe_other_breakpoints (loc_gdbarch
,
10616 sal
.pspace
, sal
.pc
, sal
.section
, -1);
10617 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10618 version for exception catchpoints, because two catchpoints
10619 used for different exception names will use the same address.
10620 In this case, a "breakpoint ... also set at..." warning is
10621 unproductive. Besides, the warning phrasing is also a bit
10622 inappropriate, we should use the word catchpoint, and tell
10623 the user what type of catchpoint it is. The above is good
10624 enough for now, though. */
10627 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
10629 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
10630 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10631 b
->location
= string_to_event_location (&addr_string
,
10632 language_def (language_ada
));
10633 b
->language
= language_ada
;
10638 /* Compare two breakpoints and return a strcmp-like result. */
10641 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
10643 uintptr_t ua
= (uintptr_t) a
;
10644 uintptr_t ub
= (uintptr_t) b
;
10646 if (a
->number
< b
->number
)
10648 else if (a
->number
> b
->number
)
10651 /* Now sort by address, in case we see, e..g, two breakpoints with
10655 return ua
> ub
? 1 : 0;
10658 /* Delete breakpoints by address or line. */
10661 clear_command (const char *arg
, int from_tty
)
10665 std::vector
<symtab_and_line
> decoded_sals
;
10666 symtab_and_line last_sal
;
10667 gdb::array_view
<symtab_and_line
> sals
;
10671 = decode_line_with_current_source (arg
,
10672 (DECODE_LINE_FUNFIRSTLINE
10673 | DECODE_LINE_LIST_MODE
));
10675 sals
= decoded_sals
;
10679 /* Set sal's line, symtab, pc, and pspace to the values
10680 corresponding to the last call to print_frame_info. If the
10681 codepoint is not valid, this will set all the fields to 0. */
10682 last_sal
= get_last_displayed_sal ();
10683 if (last_sal
.symtab
== 0)
10684 error (_("No source file specified."));
10690 /* We don't call resolve_sal_pc here. That's not as bad as it
10691 seems, because all existing breakpoints typically have both
10692 file/line and pc set. So, if clear is given file/line, we can
10693 match this to existing breakpoint without obtaining pc at all.
10695 We only support clearing given the address explicitly
10696 present in breakpoint table. Say, we've set breakpoint
10697 at file:line. There were several PC values for that file:line,
10698 due to optimization, all in one block.
10700 We've picked one PC value. If "clear" is issued with another
10701 PC corresponding to the same file:line, the breakpoint won't
10702 be cleared. We probably can still clear the breakpoint, but
10703 since the other PC value is never presented to user, user
10704 can only find it by guessing, and it does not seem important
10705 to support that. */
10707 /* For each line spec given, delete bps which correspond to it. Do
10708 it in two passes, solely to preserve the current behavior that
10709 from_tty is forced true if we delete more than one
10712 std::vector
<struct breakpoint
*> found
;
10713 for (const auto &sal
: sals
)
10715 const char *sal_fullname
;
10717 /* If exact pc given, clear bpts at that pc.
10718 If line given (pc == 0), clear all bpts on specified line.
10719 If defaulting, clear all bpts on default line
10722 defaulting sal.pc != 0 tests to do
10727 1 0 <can't happen> */
10729 sal_fullname
= (sal
.symtab
== NULL
10730 ? NULL
: symtab_to_fullname (sal
.symtab
));
10732 /* Find all matching breakpoints and add them to 'found'. */
10733 for (breakpoint
*b
: all_breakpoints ())
10736 /* Are we going to delete b? */
10737 if (b
->type
!= bp_none
&& !is_watchpoint (b
)
10738 && user_breakpoint_p (b
))
10740 for (bp_location
*loc
: b
->locations ())
10742 /* If the user specified file:line, don't allow a PC
10743 match. This matches historical gdb behavior. */
10744 int pc_match
= (!sal
.explicit_line
10746 && (loc
->pspace
== sal
.pspace
)
10747 && (loc
->address
== sal
.pc
)
10748 && (!section_is_overlay (loc
->section
)
10749 || loc
->section
== sal
.section
));
10750 int line_match
= 0;
10752 if ((default_match
|| sal
.explicit_line
)
10753 && loc
->symtab
!= NULL
10754 && sal_fullname
!= NULL
10755 && sal
.pspace
== loc
->pspace
10756 && loc
->line_number
== sal
.line
10757 && filename_cmp (symtab_to_fullname (loc
->symtab
),
10758 sal_fullname
) == 0)
10761 if (pc_match
|| line_match
)
10770 found
.push_back (b
);
10774 /* Now go thru the 'found' chain and delete them. */
10775 if (found
.empty ())
10778 error (_("No breakpoint at %s."), arg
);
10780 error (_("No breakpoint at this line."));
10783 /* Remove duplicates from the vec. */
10784 std::sort (found
.begin (), found
.end (),
10785 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10787 return compare_breakpoints (bp_a
, bp_b
) < 0;
10789 found
.erase (std::unique (found
.begin (), found
.end (),
10790 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10792 return compare_breakpoints (bp_a
, bp_b
) == 0;
10796 if (found
.size () > 1)
10797 from_tty
= 1; /* Always report if deleted more than one. */
10800 if (found
.size () == 1)
10801 gdb_printf (_("Deleted breakpoint "));
10803 gdb_printf (_("Deleted breakpoints "));
10806 for (breakpoint
*iter
: found
)
10809 gdb_printf ("%d ", iter
->number
);
10810 delete_breakpoint (iter
);
10816 /* Delete breakpoint in BS if they are `delete' breakpoints and
10817 all breakpoints that are marked for deletion, whether hit or not.
10818 This is called after any breakpoint is hit, or after errors. */
10821 breakpoint_auto_delete (bpstat
*bs
)
10823 for (; bs
; bs
= bs
->next
)
10824 if (bs
->breakpoint_at
10825 && bs
->breakpoint_at
->disposition
== disp_del
10827 delete_breakpoint (bs
->breakpoint_at
);
10829 for (breakpoint
*b
: all_breakpoints_safe ())
10830 if (b
->disposition
== disp_del_at_next_stop
)
10831 delete_breakpoint (b
);
10834 /* A comparison function for bp_location AP and BP being interfaced to
10835 std::sort. Sort elements primarily by their ADDRESS (no matter what
10836 bl_address_is_meaningful says), secondarily by ordering first
10837 permanent elements and terciarily just ensuring the array is sorted
10838 stable way despite std::sort being an unstable algorithm. */
10841 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
10843 if (a
->address
!= b
->address
)
10844 return a
->address
< b
->address
;
10846 /* Sort locations at the same address by their pspace number, keeping
10847 locations of the same inferior (in a multi-inferior environment)
10850 if (a
->pspace
->num
!= b
->pspace
->num
)
10851 return a
->pspace
->num
< b
->pspace
->num
;
10853 /* Sort permanent breakpoints first. */
10854 if (a
->permanent
!= b
->permanent
)
10855 return a
->permanent
> b
->permanent
;
10857 /* Sort by type in order to make duplicate determination easier.
10858 See update_global_location_list. This is kept in sync with
10859 breakpoint_locations_match. */
10860 if (a
->loc_type
< b
->loc_type
)
10863 /* Likewise, for range-breakpoints, sort by length. */
10864 if (a
->loc_type
== bp_loc_hardware_breakpoint
10865 && b
->loc_type
== bp_loc_hardware_breakpoint
10866 && a
->length
< b
->length
)
10869 /* Make the internal GDB representation stable across GDB runs
10870 where A and B memory inside GDB can differ. Breakpoint locations of
10871 the same type at the same address can be sorted in arbitrary order. */
10873 if (a
->owner
->number
!= b
->owner
->number
)
10874 return a
->owner
->number
< b
->owner
->number
;
10879 /* Set bp_locations_placed_address_before_address_max and
10880 bp_locations_shadow_len_after_address_max according to the current
10881 content of the bp_locations array. */
10884 bp_locations_target_extensions_update (void)
10886 bp_locations_placed_address_before_address_max
= 0;
10887 bp_locations_shadow_len_after_address_max
= 0;
10889 for (bp_location
*bl
: all_bp_locations ())
10891 CORE_ADDR start
, end
, addr
;
10893 if (!bp_location_has_shadow (bl
))
10896 start
= bl
->target_info
.placed_address
;
10897 end
= start
+ bl
->target_info
.shadow_len
;
10899 gdb_assert (bl
->address
>= start
);
10900 addr
= bl
->address
- start
;
10901 if (addr
> bp_locations_placed_address_before_address_max
)
10902 bp_locations_placed_address_before_address_max
= addr
;
10904 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10906 gdb_assert (bl
->address
< end
);
10907 addr
= end
- bl
->address
;
10908 if (addr
> bp_locations_shadow_len_after_address_max
)
10909 bp_locations_shadow_len_after_address_max
= addr
;
10913 /* Download tracepoint locations if they haven't been. */
10916 download_tracepoint_locations (void)
10918 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
10920 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
10922 for (breakpoint
*b
: all_tracepoints ())
10924 struct tracepoint
*t
;
10925 int bp_location_downloaded
= 0;
10927 if ((b
->type
== bp_fast_tracepoint
10928 ? !may_insert_fast_tracepoints
10929 : !may_insert_tracepoints
))
10932 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
10934 if (target_can_download_tracepoint ())
10935 can_download_tracepoint
= TRIBOOL_TRUE
;
10937 can_download_tracepoint
= TRIBOOL_FALSE
;
10940 if (can_download_tracepoint
== TRIBOOL_FALSE
)
10943 for (bp_location
*bl
: b
->locations ())
10945 /* In tracepoint, locations are _never_ duplicated, so
10946 should_be_inserted is equivalent to
10947 unduplicated_should_be_inserted. */
10948 if (!should_be_inserted (bl
) || bl
->inserted
)
10951 switch_to_program_space_and_thread (bl
->pspace
);
10953 target_download_tracepoint (bl
);
10956 bp_location_downloaded
= 1;
10958 t
= (struct tracepoint
*) b
;
10959 t
->number_on_target
= b
->number
;
10960 if (bp_location_downloaded
)
10961 gdb::observers::breakpoint_modified
.notify (b
);
10965 /* Swap the insertion/duplication state between two locations. */
10968 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10970 const int left_inserted
= left
->inserted
;
10971 const int left_duplicate
= left
->duplicate
;
10972 const int left_needs_update
= left
->needs_update
;
10973 const struct bp_target_info left_target_info
= left
->target_info
;
10975 /* Locations of tracepoints can never be duplicated. */
10976 if (is_tracepoint (left
->owner
))
10977 gdb_assert (!left
->duplicate
);
10978 if (is_tracepoint (right
->owner
))
10979 gdb_assert (!right
->duplicate
);
10981 left
->inserted
= right
->inserted
;
10982 left
->duplicate
= right
->duplicate
;
10983 left
->needs_update
= right
->needs_update
;
10984 left
->target_info
= right
->target_info
;
10985 right
->inserted
= left_inserted
;
10986 right
->duplicate
= left_duplicate
;
10987 right
->needs_update
= left_needs_update
;
10988 right
->target_info
= left_target_info
;
10991 /* Force the re-insertion of the locations at ADDRESS. This is called
10992 once a new/deleted/modified duplicate location is found and we are evaluating
10993 conditions on the target's side. Such conditions need to be updated on
10997 force_breakpoint_reinsertion (struct bp_location
*bl
)
10999 CORE_ADDR address
= 0;
11002 address
= bl
->address
;
11003 pspace_num
= bl
->pspace
->num
;
11005 /* This is only meaningful if the target is
11006 evaluating conditions and if the user has
11007 opted for condition evaluation on the target's
11009 if (gdb_evaluates_breakpoint_condition_p ()
11010 || !target_supports_evaluation_of_breakpoint_conditions ())
11013 /* Flag all breakpoint locations with this address and
11014 the same program space as the location
11015 as "its condition has changed". We need to
11016 update the conditions on the target's side. */
11017 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
11019 if (!is_breakpoint (loc
->owner
)
11020 || pspace_num
!= loc
->pspace
->num
)
11023 /* Flag the location appropriately. We use a different state to
11024 let everyone know that we already updated the set of locations
11025 with addr bl->address and program space bl->pspace. This is so
11026 we don't have to keep calling these functions just to mark locations
11027 that have already been marked. */
11028 loc
->condition_changed
= condition_updated
;
11030 /* Free the agent expression bytecode as well. We will compute
11032 loc
->cond_bytecode
.reset ();
11036 /* Called whether new breakpoints are created, or existing breakpoints
11037 deleted, to update the global location list and recompute which
11038 locations are duplicate of which.
11040 The INSERT_MODE flag determines whether locations may not, may, or
11041 shall be inserted now. See 'enum ugll_insert_mode' for more
11045 update_global_location_list (enum ugll_insert_mode insert_mode
)
11047 /* Last breakpoint location address that was marked for update. */
11048 CORE_ADDR last_addr
= 0;
11049 /* Last breakpoint location program space that was marked for update. */
11050 int last_pspace_num
= -1;
11052 /* Used in the duplicates detection below. When iterating over all
11053 bp_locations, points to the first bp_location of a given address.
11054 Breakpoints and watchpoints of different types are never
11055 duplicates of each other. Keep one pointer for each type of
11056 breakpoint/watchpoint, so we only need to loop over all locations
11058 struct bp_location
*bp_loc_first
; /* breakpoint */
11059 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11060 struct bp_location
*awp_loc_first
; /* access watchpoint */
11061 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11063 /* Saved former bp_locations array which we compare against the newly
11064 built bp_locations from the current state of ALL_BREAKPOINTS. */
11065 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
11066 bp_locations
.clear ();
11068 for (breakpoint
*b
: all_breakpoints ())
11069 for (bp_location
*loc
: b
->locations ())
11070 bp_locations
.push_back (loc
);
11072 /* See if we need to "upgrade" a software breakpoint to a hardware
11073 breakpoint. Do this before deciding whether locations are
11074 duplicates. Also do this before sorting because sorting order
11075 depends on location type. */
11076 for (bp_location
*loc
: bp_locations
)
11077 if (!loc
->inserted
&& should_be_inserted (loc
))
11078 handle_automatic_hardware_breakpoints (loc
);
11080 std::sort (bp_locations
.begin (), bp_locations
.end (),
11081 bp_location_is_less_than
);
11083 bp_locations_target_extensions_update ();
11085 /* Identify bp_location instances that are no longer present in the
11086 new list, and therefore should be freed. Note that it's not
11087 necessary that those locations should be removed from inferior --
11088 if there's another location at the same address (previously
11089 marked as duplicate), we don't need to remove/insert the
11092 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11093 and former bp_location array state respectively. */
11096 for (bp_location
*old_loc
: old_locations
)
11098 /* Tells if 'old_loc' is found among the new locations. If
11099 not, we have to free it. */
11100 int found_object
= 0;
11101 /* Tells if the location should remain inserted in the target. */
11102 int keep_in_target
= 0;
11105 /* Skip LOCP entries which will definitely never be needed.
11106 Stop either at or being the one matching OLD_LOC. */
11107 while (loc_i
< bp_locations
.size ()
11108 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11111 for (size_t loc2_i
= loc_i
;
11112 (loc2_i
< bp_locations
.size ()
11113 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11116 /* Check if this is a new/duplicated location or a duplicated
11117 location that had its condition modified. If so, we want to send
11118 its condition to the target if evaluation of conditions is taking
11120 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11121 && (last_addr
!= old_loc
->address
11122 || last_pspace_num
!= old_loc
->pspace
->num
))
11124 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11125 last_pspace_num
= old_loc
->pspace
->num
;
11128 if (bp_locations
[loc2_i
] == old_loc
)
11132 /* We have already handled this address, update it so that we don't
11133 have to go through updates again. */
11134 last_addr
= old_loc
->address
;
11136 /* Target-side condition evaluation: Handle deleted locations. */
11138 force_breakpoint_reinsertion (old_loc
);
11140 /* If this location is no longer present, and inserted, look if
11141 there's maybe a new location at the same address. If so,
11142 mark that one inserted, and don't remove this one. This is
11143 needed so that we don't have a time window where a breakpoint
11144 at certain location is not inserted. */
11146 if (old_loc
->inserted
)
11148 /* If the location is inserted now, we might have to remove
11151 if (found_object
&& should_be_inserted (old_loc
))
11153 /* The location is still present in the location list,
11154 and still should be inserted. Don't do anything. */
11155 keep_in_target
= 1;
11159 /* This location still exists, but it won't be kept in the
11160 target since it may have been disabled. We proceed to
11161 remove its target-side condition. */
11163 /* The location is either no longer present, or got
11164 disabled. See if there's another location at the
11165 same address, in which case we don't need to remove
11166 this one from the target. */
11168 /* OLD_LOC comes from existing struct breakpoint. */
11169 if (bl_address_is_meaningful (old_loc
))
11171 for (size_t loc2_i
= loc_i
;
11172 (loc2_i
< bp_locations
.size ()
11173 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11176 bp_location
*loc2
= bp_locations
[loc2_i
];
11178 if (loc2
== old_loc
)
11181 if (breakpoint_locations_match (loc2
, old_loc
))
11183 /* Read watchpoint locations are switched to
11184 access watchpoints, if the former are not
11185 supported, but the latter are. */
11186 if (is_hardware_watchpoint (old_loc
->owner
))
11188 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11189 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11192 /* loc2 is a duplicated location. We need to check
11193 if it should be inserted in case it will be
11195 if (unduplicated_should_be_inserted (loc2
))
11197 swap_insertion (old_loc
, loc2
);
11198 keep_in_target
= 1;
11206 if (!keep_in_target
)
11208 if (remove_breakpoint (old_loc
))
11210 /* This is just about all we can do. We could keep
11211 this location on the global list, and try to
11212 remove it next time, but there's no particular
11213 reason why we will succeed next time.
11215 Note that at this point, old_loc->owner is still
11216 valid, as delete_breakpoint frees the breakpoint
11217 only after calling us. */
11218 gdb_printf (_("warning: Error removing "
11219 "breakpoint %d\n"),
11220 old_loc
->owner
->number
);
11228 if (removed
&& target_is_non_stop_p ()
11229 && need_moribund_for_location_type (old_loc
))
11231 /* This location was removed from the target. In
11232 non-stop mode, a race condition is possible where
11233 we've removed a breakpoint, but stop events for that
11234 breakpoint are already queued and will arrive later.
11235 We apply an heuristic to be able to distinguish such
11236 SIGTRAPs from other random SIGTRAPs: we keep this
11237 breakpoint location for a bit, and will retire it
11238 after we see some number of events. The theory here
11239 is that reporting of events should, "on the average",
11240 be fair, so after a while we'll see events from all
11241 threads that have anything of interest, and no longer
11242 need to keep this breakpoint location around. We
11243 don't hold locations forever so to reduce chances of
11244 mistaking a non-breakpoint SIGTRAP for a breakpoint
11247 The heuristic failing can be disastrous on
11248 decr_pc_after_break targets.
11250 On decr_pc_after_break targets, like e.g., x86-linux,
11251 if we fail to recognize a late breakpoint SIGTRAP,
11252 because events_till_retirement has reached 0 too
11253 soon, we'll fail to do the PC adjustment, and report
11254 a random SIGTRAP to the user. When the user resumes
11255 the inferior, it will most likely immediately crash
11256 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11257 corrupted, because of being resumed e.g., in the
11258 middle of a multi-byte instruction, or skipped a
11259 one-byte instruction. This was actually seen happen
11260 on native x86-linux, and should be less rare on
11261 targets that do not support new thread events, like
11262 remote, due to the heuristic depending on
11265 Mistaking a random SIGTRAP for a breakpoint trap
11266 causes similar symptoms (PC adjustment applied when
11267 it shouldn't), but then again, playing with SIGTRAPs
11268 behind the debugger's back is asking for trouble.
11270 Since hardware watchpoint traps are always
11271 distinguishable from other traps, so we don't need to
11272 apply keep hardware watchpoint moribund locations
11273 around. We simply always ignore hardware watchpoint
11274 traps we can no longer explain. */
11276 process_stratum_target
*proc_target
= nullptr;
11277 for (inferior
*inf
: all_inferiors ())
11278 if (inf
->pspace
== old_loc
->pspace
)
11280 proc_target
= inf
->process_target ();
11283 if (proc_target
!= nullptr)
11284 old_loc
->events_till_retirement
11285 = 3 * (thread_count (proc_target
) + 1);
11287 old_loc
->events_till_retirement
= 1;
11288 old_loc
->owner
= NULL
;
11290 moribund_locations
.push_back (old_loc
);
11294 old_loc
->owner
= NULL
;
11295 decref_bp_location (&old_loc
);
11300 /* Rescan breakpoints at the same address and section, marking the
11301 first one as "first" and any others as "duplicates". This is so
11302 that the bpt instruction is only inserted once. If we have a
11303 permanent breakpoint at the same place as BPT, make that one the
11304 official one, and the rest as duplicates. Permanent breakpoints
11305 are sorted first for the same address.
11307 Do the same for hardware watchpoints, but also considering the
11308 watchpoint's type (regular/access/read) and length. */
11310 bp_loc_first
= NULL
;
11311 wp_loc_first
= NULL
;
11312 awp_loc_first
= NULL
;
11313 rwp_loc_first
= NULL
;
11315 for (bp_location
*loc
: all_bp_locations ())
11317 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11319 struct bp_location
**loc_first_p
;
11320 breakpoint
*b
= loc
->owner
;
11322 if (!unduplicated_should_be_inserted (loc
)
11323 || !bl_address_is_meaningful (loc
)
11324 /* Don't detect duplicate for tracepoint locations because they are
11325 never duplicated. See the comments in field `duplicate' of
11326 `struct bp_location'. */
11327 || is_tracepoint (b
))
11329 /* Clear the condition modification flag. */
11330 loc
->condition_changed
= condition_unchanged
;
11334 if (b
->type
== bp_hardware_watchpoint
)
11335 loc_first_p
= &wp_loc_first
;
11336 else if (b
->type
== bp_read_watchpoint
)
11337 loc_first_p
= &rwp_loc_first
;
11338 else if (b
->type
== bp_access_watchpoint
)
11339 loc_first_p
= &awp_loc_first
;
11341 loc_first_p
= &bp_loc_first
;
11343 if (*loc_first_p
== NULL
11344 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11345 || !breakpoint_locations_match (loc
, *loc_first_p
))
11347 *loc_first_p
= loc
;
11348 loc
->duplicate
= 0;
11350 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11352 loc
->needs_update
= 1;
11353 /* Clear the condition modification flag. */
11354 loc
->condition_changed
= condition_unchanged
;
11360 /* This and the above ensure the invariant that the first location
11361 is not duplicated, and is the inserted one.
11362 All following are marked as duplicated, and are not inserted. */
11364 swap_insertion (loc
, *loc_first_p
);
11365 loc
->duplicate
= 1;
11367 /* Clear the condition modification flag. */
11368 loc
->condition_changed
= condition_unchanged
;
11371 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11373 if (insert_mode
!= UGLL_DONT_INSERT
)
11374 insert_breakpoint_locations ();
11377 /* Even though the caller told us to not insert new
11378 locations, we may still need to update conditions on the
11379 target's side of breakpoints that were already inserted
11380 if the target is evaluating breakpoint conditions. We
11381 only update conditions for locations that are marked
11383 update_inserted_breakpoint_locations ();
11387 if (insert_mode
!= UGLL_DONT_INSERT
)
11388 download_tracepoint_locations ();
11392 breakpoint_retire_moribund (void)
11394 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11396 struct bp_location
*loc
= moribund_locations
[ix
];
11397 if (--(loc
->events_till_retirement
) == 0)
11399 decref_bp_location (&loc
);
11400 unordered_remove (moribund_locations
, ix
);
11407 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
11412 update_global_location_list (insert_mode
);
11414 catch (const gdb_exception_error
&e
)
11419 /* Clear BKP from a BPS. */
11422 bpstat_remove_bp_location (bpstat
*bps
, struct breakpoint
*bpt
)
11426 for (bs
= bps
; bs
; bs
= bs
->next
)
11427 if (bs
->breakpoint_at
== bpt
)
11429 bs
->breakpoint_at
= NULL
;
11430 bs
->old_val
= NULL
;
11431 /* bs->commands will be freed later. */
11435 /* Callback for iterate_over_threads. */
11437 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11439 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
11441 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11445 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
11449 say_where (struct breakpoint
*b
)
11451 struct value_print_options opts
;
11453 get_user_print_options (&opts
);
11455 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11457 if (b
->loc
== NULL
)
11459 /* For pending locations, the output differs slightly based
11460 on b->extra_string. If this is non-NULL, it contains either
11461 a condition or dprintf arguments. */
11462 if (b
->extra_string
== NULL
)
11464 gdb_printf (_(" (%s) pending."),
11465 event_location_to_string (b
->location
.get ()));
11467 else if (b
->type
== bp_dprintf
)
11469 gdb_printf (_(" (%s,%s) pending."),
11470 event_location_to_string (b
->location
.get ()),
11471 b
->extra_string
.get ());
11475 gdb_printf (_(" (%s %s) pending."),
11476 event_location_to_string (b
->location
.get ()),
11477 b
->extra_string
.get ());
11482 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
11483 gdb_printf (" at %ps",
11484 styled_string (address_style
.style (),
11485 paddress (b
->loc
->gdbarch
,
11486 b
->loc
->address
)));
11487 if (b
->loc
->symtab
!= NULL
)
11489 /* If there is a single location, we can print the location
11491 if (b
->loc
->next
== NULL
)
11493 const char *filename
11494 = symtab_to_filename_for_display (b
->loc
->symtab
);
11495 gdb_printf (": file %ps, line %d.",
11496 styled_string (file_name_style
.style (),
11498 b
->loc
->line_number
);
11501 /* This is not ideal, but each location may have a
11502 different file name, and this at least reflects the
11503 real situation somewhat. */
11504 gdb_printf (": %s.",
11505 event_location_to_string (b
->location
.get ()));
11510 struct bp_location
*loc
= b
->loc
;
11512 for (; loc
; loc
= loc
->next
)
11514 gdb_printf (" (%d locations)", n
);
11519 /* See breakpoint.h. */
11521 bp_location_range
breakpoint::locations ()
11523 return bp_location_range (this->loc
);
11526 static struct bp_location
*
11527 base_breakpoint_allocate_location (struct breakpoint
*self
)
11529 return new bp_location (self
);
11532 struct bp_location
*
11533 breakpoint::allocate_location ()
11535 return new bp_location (this);
11539 base_breakpoint_re_set (struct breakpoint
*b
)
11541 /* Nothing to re-set. */
11544 #define internal_error_pure_virtual_called() \
11545 gdb_assert_not_reached ("pure virtual function called")
11548 base_breakpoint_insert_location (struct bp_location
*bl
)
11550 internal_error_pure_virtual_called ();
11554 breakpoint::insert_location (struct bp_location
*bl
)
11556 internal_error_pure_virtual_called ();
11560 base_breakpoint_remove_location (struct bp_location
*bl
,
11561 enum remove_bp_reason reason
)
11563 internal_error_pure_virtual_called ();
11567 breakpoint::remove_location (struct bp_location
*bl
,
11568 enum remove_bp_reason reason
)
11570 internal_error_pure_virtual_called ();
11574 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
11575 const address_space
*aspace
,
11577 const target_waitstatus
&ws
)
11579 internal_error_pure_virtual_called ();
11583 breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11584 const address_space
*aspace
,
11586 const target_waitstatus
&ws
)
11588 internal_error_pure_virtual_called ();
11592 base_breakpoint_check_status (bpstat
*bs
)
11597 /* A "works_in_software_mode" breakpoint_ops method that just internal
11601 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
11603 internal_error_pure_virtual_called ();
11607 breakpoint::works_in_software_mode () const
11609 internal_error_pure_virtual_called ();
11612 /* A "resources_needed" breakpoint_ops method that just internal
11616 base_breakpoint_resources_needed (const struct bp_location
*bl
)
11618 internal_error_pure_virtual_called ();
11622 breakpoint::resources_needed (const struct bp_location
*bl
)
11624 internal_error_pure_virtual_called ();
11627 static enum print_stop_action
11628 base_breakpoint_print_it (bpstat
*bs
)
11630 internal_error_pure_virtual_called ();
11633 enum print_stop_action
11634 breakpoint::print_it (bpstat
*bs
)
11636 internal_error_pure_virtual_called ();
11640 base_breakpoint_print_one (struct breakpoint
*, struct bp_location
**)
11646 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
11647 struct ui_out
*uiout
)
11653 base_breakpoint_print_mention (struct breakpoint
*b
)
11655 internal_error_pure_virtual_called ();
11659 breakpoint::print_mention ()
11661 internal_error_pure_virtual_called ();
11665 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
11667 internal_error_pure_virtual_called ();
11671 breakpoint::print_recreate (struct ui_file
*fp
)
11673 internal_error_pure_virtual_called ();
11677 base_breakpoint_create_sals_from_location
11678 (struct event_location
*location
,
11679 struct linespec_result
*canonical
,
11680 enum bptype type_wanted
)
11682 internal_error_pure_virtual_called ();
11686 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
11687 struct linespec_result
*c
,
11688 gdb::unique_xmalloc_ptr
<char> cond_string
,
11689 gdb::unique_xmalloc_ptr
<char> extra_string
,
11690 enum bptype type_wanted
,
11691 enum bpdisp disposition
,
11693 int task
, int ignore_count
,
11694 const struct breakpoint_ops
*o
,
11695 int from_tty
, int enabled
,
11696 int internal
, unsigned flags
)
11698 internal_error_pure_virtual_called ();
11701 static std::vector
<symtab_and_line
>
11702 base_breakpoint_decode_location (struct breakpoint
*b
,
11703 struct event_location
*location
,
11704 struct program_space
*search_pspace
)
11706 internal_error_pure_virtual_called ();
11709 std::vector
<symtab_and_line
>
11710 breakpoint::decode_location (struct event_location
*location
,
11711 struct program_space
*search_pspace
)
11713 internal_error_pure_virtual_called ();
11716 /* The default 'explains_signal' method. */
11719 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
11724 /* The default "after_condition_true" method. */
11727 base_breakpoint_after_condition_true (struct bpstat
*bs
)
11729 /* Nothing to do. */
11732 struct breakpoint_ops base_breakpoint_ops
=
11734 base_breakpoint_allocate_location
,
11735 base_breakpoint_re_set
,
11736 base_breakpoint_insert_location
,
11737 base_breakpoint_remove_location
,
11738 base_breakpoint_breakpoint_hit
,
11739 base_breakpoint_check_status
,
11740 base_breakpoint_resources_needed
,
11741 base_breakpoint_works_in_software_mode
,
11742 base_breakpoint_print_it
,
11743 base_breakpoint_print_one
,
11744 base_breakpoint_print_one_detail
,
11745 base_breakpoint_print_mention
,
11746 base_breakpoint_print_recreate
,
11747 base_breakpoint_create_sals_from_location
,
11748 base_breakpoint_create_breakpoints_sal
,
11749 base_breakpoint_decode_location
,
11750 base_breakpoint_explains_signal
,
11751 base_breakpoint_after_condition_true
,
11754 struct breakpoint_ops vtable_breakpoint_ops
=
11756 [] (struct breakpoint
*b
) { return b
->allocate_location (); },
11757 [] (struct breakpoint
*b
) { b
->re_set (); },
11758 [] (struct bp_location
*l
)
11760 return l
->owner
->insert_location (l
);
11762 [] (struct bp_location
*l
, enum remove_bp_reason reason
)
11764 return l
->owner
->remove_location (l
, reason
);
11766 [] (const struct bp_location
*bl
,
11767 const address_space
*aspace
,
11769 const target_waitstatus
&ws
)
11771 return bl
->owner
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
11773 [] (struct bpstat
*bs
) { bs
->breakpoint_at
->check_status (bs
); },
11774 [] (const struct bp_location
*bl
)
11775 { return bl
->owner
->resources_needed (bl
); },
11776 [] (const struct breakpoint
*b
)
11777 { return b
->works_in_software_mode (); },
11778 [] (struct bpstat
*bs
)
11779 { return bs
->breakpoint_at
->print_it (bs
); },
11780 [] (struct breakpoint
*b
, struct bp_location
**bl
)
11781 { return b
->print_one (bl
); },
11782 [] (const struct breakpoint
*b
, struct ui_out
*out
)
11783 { b
->print_one_detail (out
); },
11784 [] (struct breakpoint
*b
) { b
->print_mention (); },
11785 [] (struct breakpoint
*b
, struct ui_file
*fp
)
11786 { b
->print_recreate (fp
); },
11787 create_sals_from_location_default
,
11788 create_breakpoints_sal_default
,
11789 [] (struct breakpoint
*b
,
11790 struct event_location
*location
,
11791 struct program_space
*search_pspace
)
11792 { return b
->decode_location (location
, search_pspace
); },
11793 [] (struct breakpoint
*b
, enum gdb_signal s
)
11794 { return b
->explains_signal (s
); },
11795 [] (struct bpstat
*bs
)
11796 { bs
->breakpoint_at
->after_condition_true (bs
); }
11799 /* Default breakpoint_ops methods. */
11802 bkpt_re_set (struct breakpoint
*b
)
11804 /* FIXME: is this still reachable? */
11805 if (breakpoint_event_location_empty_p (b
))
11807 /* Anything without a location can't be re-set. */
11808 delete_breakpoint (b
);
11812 breakpoint_re_set_default (b
);
11816 bkpt_insert_location (struct bp_location
*bl
)
11818 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
11820 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
11821 bl
->target_info
.placed_address
= addr
;
11823 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11824 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11826 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11830 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
11832 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11833 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11835 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
11839 bkpt_breakpoint_hit (const struct bp_location
*bl
,
11840 const address_space
*aspace
, CORE_ADDR bp_addr
,
11841 const target_waitstatus
&ws
)
11843 if (ws
.kind () != TARGET_WAITKIND_STOPPED
11844 || ws
.sig () != GDB_SIGNAL_TRAP
)
11847 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
11851 if (overlay_debugging
/* unmapped overlay section */
11852 && section_is_overlay (bl
->section
)
11853 && !section_is_mapped (bl
->section
))
11860 dprintf_breakpoint_hit (const struct bp_location
*bl
,
11861 const address_space
*aspace
, CORE_ADDR bp_addr
,
11862 const target_waitstatus
&ws
)
11864 if (dprintf_style
== dprintf_style_agent
11865 && target_can_run_breakpoint_commands ())
11867 /* An agent-style dprintf never causes a stop. If we see a trap
11868 for this address it must be for a breakpoint that happens to
11869 be set at the same address. */
11873 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
11877 bkpt_resources_needed (const struct bp_location
*bl
)
11879 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
11884 static enum print_stop_action
11885 bkpt_print_it (bpstat
*bs
)
11887 struct breakpoint
*b
;
11888 const struct bp_location
*bl
;
11890 struct ui_out
*uiout
= current_uiout
;
11892 gdb_assert (bs
->bp_location_at
!= NULL
);
11894 bl
= bs
->bp_location_at
.get ();
11895 b
= bs
->breakpoint_at
;
11897 bp_temp
= b
->disposition
== disp_del
;
11898 if (bl
->address
!= bl
->requested_address
)
11899 breakpoint_adjustment_warning (bl
->requested_address
,
11902 annotate_breakpoint (b
->number
);
11903 maybe_print_thread_hit_breakpoint (uiout
);
11905 if (uiout
->is_mi_like_p ())
11907 uiout
->field_string ("reason",
11908 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11909 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
11912 uiout
->message ("Temporary breakpoint %pF, ",
11913 signed_field ("bkptno", b
->number
));
11915 uiout
->message ("Breakpoint %pF, ",
11916 signed_field ("bkptno", b
->number
));
11918 return PRINT_SRC_AND_LOC
;
11922 bkpt_print_mention (struct breakpoint
*b
)
11924 if (current_uiout
->is_mi_like_p ())
11929 case bp_breakpoint
:
11930 case bp_gnu_ifunc_resolver
:
11931 if (b
->disposition
== disp_del
)
11932 gdb_printf (_("Temporary breakpoint"));
11934 gdb_printf (_("Breakpoint"));
11935 gdb_printf (_(" %d"), b
->number
);
11936 if (b
->type
== bp_gnu_ifunc_resolver
)
11937 gdb_printf (_(" at gnu-indirect-function resolver"));
11939 case bp_hardware_breakpoint
:
11940 gdb_printf (_("Hardware assisted breakpoint %d"), b
->number
);
11943 gdb_printf (_("Dprintf %d"), b
->number
);
11951 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
11953 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
11954 gdb_printf (fp
, "tbreak");
11955 else if (tp
->type
== bp_breakpoint
)
11956 gdb_printf (fp
, "break");
11957 else if (tp
->type
== bp_hardware_breakpoint
11958 && tp
->disposition
== disp_del
)
11959 gdb_printf (fp
, "thbreak");
11960 else if (tp
->type
== bp_hardware_breakpoint
)
11961 gdb_printf (fp
, "hbreak");
11963 internal_error (__FILE__
, __LINE__
,
11964 _("unhandled breakpoint type %d"), (int) tp
->type
);
11966 gdb_printf (fp
, " %s",
11967 event_location_to_string (tp
->location
.get ()));
11969 /* Print out extra_string if this breakpoint is pending. It might
11970 contain, for example, conditions that were set by the user. */
11971 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
11972 gdb_printf (fp
, " %s", tp
->extra_string
.get ());
11974 print_recreate_thread (tp
, fp
);
11977 static std::vector
<symtab_and_line
>
11978 bkpt_decode_location (struct breakpoint
*b
,
11979 struct event_location
*location
,
11980 struct program_space
*search_pspace
)
11982 return decode_location_default (b
, location
, search_pspace
);
11985 /* Virtual table for internal breakpoints. */
11988 internal_bkpt_re_set (struct breakpoint
*b
)
11992 /* Delete overlay event and longjmp master breakpoints; they
11993 will be reset later by breakpoint_re_set. */
11994 case bp_overlay_event
:
11995 case bp_longjmp_master
:
11996 case bp_std_terminate_master
:
11997 case bp_exception_master
:
11998 delete_breakpoint (b
);
12001 /* This breakpoint is special, it's set up when the inferior
12002 starts and we really don't want to touch it. */
12003 case bp_shlib_event
:
12005 /* Like bp_shlib_event, this breakpoint type is special. Once
12006 it is set up, we do not want to touch it. */
12007 case bp_thread_event
:
12013 internal_bkpt_check_status (bpstat
*bs
)
12015 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12017 /* If requested, stop when the dynamic linker notifies GDB of
12018 events. This allows the user to get control and place
12019 breakpoints in initializer routines for dynamically loaded
12020 objects (among other things). */
12021 bs
->stop
= stop_on_solib_events
;
12022 bs
->print
= stop_on_solib_events
;
12028 static enum print_stop_action
12029 internal_bkpt_print_it (bpstat
*bs
)
12031 struct breakpoint
*b
;
12033 b
= bs
->breakpoint_at
;
12037 case bp_shlib_event
:
12038 /* Did we stop because the user set the stop_on_solib_events
12039 variable? (If so, we report this as a generic, "Stopped due
12040 to shlib event" message.) */
12041 print_solib_event (false);
12044 case bp_thread_event
:
12045 /* Not sure how we will get here.
12046 GDB should not stop for these breakpoints. */
12047 gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
12050 case bp_overlay_event
:
12051 /* By analogy with the thread event, GDB should not stop for these. */
12052 gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12055 case bp_longjmp_master
:
12056 /* These should never be enabled. */
12057 gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12060 case bp_std_terminate_master
:
12061 /* These should never be enabled. */
12062 gdb_printf (_("std::terminate Master Breakpoint: "
12063 "gdb should not stop!\n"));
12066 case bp_exception_master
:
12067 /* These should never be enabled. */
12068 gdb_printf (_("Exception Master Breakpoint: "
12069 "gdb should not stop!\n"));
12073 return PRINT_NOTHING
;
12077 internal_bkpt_print_mention (struct breakpoint
*b
)
12079 /* Nothing to mention. These breakpoints are internal. */
12082 /* Virtual table for momentary breakpoints */
12085 momentary_bkpt_re_set (struct breakpoint
*b
)
12087 /* Keep temporary breakpoints, which can be encountered when we step
12088 over a dlopen call and solib_add is resetting the breakpoints.
12089 Otherwise these should have been blown away via the cleanup chain
12090 or by breakpoint_init_inferior when we rerun the executable. */
12094 momentary_bkpt_check_status (bpstat
*bs
)
12096 /* Nothing. The point of these breakpoints is causing a stop. */
12099 static enum print_stop_action
12100 momentary_bkpt_print_it (bpstat
*bs
)
12102 return PRINT_UNKNOWN
;
12106 momentary_bkpt_print_mention (struct breakpoint
*b
)
12108 /* Nothing to mention. These breakpoints are internal. */
12111 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12113 It gets cleared already on the removal of the first one of such placed
12114 breakpoints. This is OK as they get all removed altogether. */
12116 longjmp_breakpoint::~longjmp_breakpoint ()
12118 thread_info
*tp
= find_thread_global_id (this->thread
);
12121 tp
->initiating_frame
= null_frame_id
;
12124 /* Specific methods for probe breakpoints. */
12127 bkpt_probe_insert_location (struct bp_location
*bl
)
12129 int v
= bkpt_insert_location (bl
);
12133 /* The insertion was successful, now let's set the probe's semaphore
12135 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12142 bkpt_probe_remove_location (struct bp_location
*bl
,
12143 enum remove_bp_reason reason
)
12145 /* Let's clear the semaphore before removing the location. */
12146 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12148 return bkpt_remove_location (bl
, reason
);
12152 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12153 struct linespec_result
*canonical
,
12154 enum bptype type_wanted
)
12156 struct linespec_sals lsal
;
12158 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12160 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12161 canonical
->lsals
.push_back (std::move (lsal
));
12164 static std::vector
<symtab_and_line
>
12165 bkpt_probe_decode_location (struct breakpoint
*b
,
12166 struct event_location
*location
,
12167 struct program_space
*search_pspace
)
12169 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12171 error (_("probe not found"));
12175 /* The breakpoint_ops structure to be used in tracepoints. */
12178 tracepoint::re_set ()
12180 breakpoint_re_set_default (this);
12184 tracepoint::breakpoint_hit (const struct bp_location
*bl
,
12185 const address_space
*aspace
, CORE_ADDR bp_addr
,
12186 const target_waitstatus
&ws
)
12188 /* By definition, the inferior does not report stops at
12194 tracepoint::print_one_detail (struct ui_out
*uiout
) const
12196 if (!static_trace_marker_id
.empty ())
12198 gdb_assert (type
== bp_static_tracepoint
);
12200 uiout
->message ("\tmarker id is %pF\n",
12201 string_field ("static-tracepoint-marker-string-id",
12202 static_trace_marker_id
.c_str ()));
12207 tracepoint::print_mention ()
12209 if (current_uiout
->is_mi_like_p ())
12214 case bp_tracepoint
:
12215 gdb_printf (_("Tracepoint"));
12216 gdb_printf (_(" %d"), number
);
12218 case bp_fast_tracepoint
:
12219 gdb_printf (_("Fast tracepoint"));
12220 gdb_printf (_(" %d"), number
);
12222 case bp_static_tracepoint
:
12223 gdb_printf (_("Static tracepoint"));
12224 gdb_printf (_(" %d"), number
);
12227 internal_error (__FILE__
, __LINE__
,
12228 _("unhandled tracepoint type %d"), (int) type
);
12235 tracepoint::print_recreate (struct ui_file
*fp
)
12237 if (type
== bp_fast_tracepoint
)
12238 gdb_printf (fp
, "ftrace");
12239 else if (type
== bp_static_tracepoint
)
12240 gdb_printf (fp
, "strace");
12241 else if (type
== bp_tracepoint
)
12242 gdb_printf (fp
, "trace");
12244 internal_error (__FILE__
, __LINE__
,
12245 _("unhandled tracepoint type %d"), (int) type
);
12247 gdb_printf (fp
, " %s", event_location_to_string (location
.get ()));
12248 print_recreate_thread (this, fp
);
12251 gdb_printf (fp
, " passcount %d\n", pass_count
);
12254 std::vector
<symtab_and_line
>
12255 tracepoint::decode_location (struct event_location
*location
,
12256 struct program_space
*search_pspace
)
12258 return decode_location_default (this, location
, search_pspace
);
12261 /* Virtual table for tracepoints on static probes. */
12264 tracepoint_probe_create_sals_from_location
12265 (struct event_location
*location
,
12266 struct linespec_result
*canonical
,
12267 enum bptype type_wanted
)
12269 /* We use the same method for breakpoint on probes. */
12270 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
12273 static std::vector
<symtab_and_line
>
12274 tracepoint_probe_decode_location (struct breakpoint
*b
,
12275 struct event_location
*location
,
12276 struct program_space
*search_pspace
)
12278 /* We use the same method for breakpoint on probes. */
12279 return bkpt_probe_decode_location (b
, location
, search_pspace
);
12282 /* Dprintf breakpoint_ops methods. */
12285 dprintf_re_set (struct breakpoint
*b
)
12287 breakpoint_re_set_default (b
);
12289 /* extra_string should never be non-NULL for dprintf. */
12290 gdb_assert (b
->extra_string
!= NULL
);
12292 /* 1 - connect to target 1, that can run breakpoint commands.
12293 2 - create a dprintf, which resolves fine.
12294 3 - disconnect from target 1
12295 4 - connect to target 2, that can NOT run breakpoint commands.
12297 After steps #3/#4, you'll want the dprintf command list to
12298 be updated, because target 1 and 2 may well return different
12299 answers for target_can_run_breakpoint_commands().
12300 Given absence of finer grained resetting, we get to do
12301 it all the time. */
12302 if (b
->extra_string
!= NULL
)
12303 update_dprintf_command_list (b
);
12306 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
12309 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12311 gdb_printf (fp
, "dprintf %s,%s",
12312 event_location_to_string (tp
->location
.get ()),
12313 tp
->extra_string
.get ());
12314 print_recreate_thread (tp
, fp
);
12317 /* Implement the "after_condition_true" breakpoint_ops method for
12320 dprintf's are implemented with regular commands in their command
12321 list, but we run the commands here instead of before presenting the
12322 stop to the user, as dprintf's don't actually cause a stop. This
12323 also makes it so that the commands of multiple dprintfs at the same
12324 address are all handled. */
12327 dprintf_after_condition_true (struct bpstat
*bs
)
12329 /* dprintf's never cause a stop. This wasn't set in the
12330 check_status hook instead because that would make the dprintf's
12331 condition not be evaluated. */
12334 /* Run the command list here. Take ownership of it instead of
12335 copying. We never want these commands to run later in
12336 bpstat_do_actions, if a breakpoint that causes a stop happens to
12337 be set at same address as this dprintf, or even if running the
12338 commands here throws. */
12339 counted_command_line cmds
= std::move (bs
->commands
);
12340 gdb_assert (cmds
!= nullptr);
12341 execute_control_commands (cmds
.get (), 0);
12344 /* The breakpoint_ops structure to be used on static tracepoints with
12348 strace_marker_create_sals_from_location (struct event_location
*location
,
12349 struct linespec_result
*canonical
,
12350 enum bptype type_wanted
)
12352 struct linespec_sals lsal
;
12353 const char *arg_start
, *arg
;
12355 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
12356 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12358 std::string
str (arg_start
, arg
- arg_start
);
12359 const char *ptr
= str
.c_str ();
12360 canonical
->location
12361 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
12364 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12365 canonical
->lsals
.push_back (std::move (lsal
));
12369 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12370 struct linespec_result
*canonical
,
12371 gdb::unique_xmalloc_ptr
<char> cond_string
,
12372 gdb::unique_xmalloc_ptr
<char> extra_string
,
12373 enum bptype type_wanted
,
12374 enum bpdisp disposition
,
12376 int task
, int ignore_count
,
12377 const struct breakpoint_ops
*ops
,
12378 int from_tty
, int enabled
,
12379 int internal
, unsigned flags
)
12381 const linespec_sals
&lsal
= canonical
->lsals
[0];
12383 /* If the user is creating a static tracepoint by marker id
12384 (strace -m MARKER_ID), then store the sals index, so that
12385 breakpoint_re_set can try to match up which of the newly
12386 found markers corresponds to this one, and, don't try to
12387 expand multiple locations for each sal, given than SALS
12388 already should contain all sals for MARKER_ID. */
12390 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12392 event_location_up location
12393 = copy_event_location (canonical
->location
.get ());
12395 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
12396 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
12397 std::move (location
), NULL
,
12398 std::move (cond_string
),
12399 std::move (extra_string
),
12400 type_wanted
, disposition
,
12401 thread
, task
, ignore_count
, ops
,
12402 from_tty
, enabled
, internal
, flags
,
12403 canonical
->special_display
);
12404 /* Given that its possible to have multiple markers with
12405 the same string id, if the user is creating a static
12406 tracepoint by marker id ("strace -m MARKER_ID"), then
12407 store the sals index, so that breakpoint_re_set can
12408 try to match up which of the newly found markers
12409 corresponds to this one */
12410 tp
->static_trace_marker_id_idx
= i
;
12412 install_breakpoint (internal
, std::move (tp
), 0);
12416 static std::vector
<symtab_and_line
>
12417 strace_marker_decode_location (struct breakpoint
*b
,
12418 struct event_location
*location
,
12419 struct program_space
*search_pspace
)
12421 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12422 const char *s
= get_linespec_location (location
)->spec_string
;
12424 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12425 if (sals
.size () > tp
->static_trace_marker_id_idx
)
12427 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
12432 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
12435 static struct breakpoint_ops strace_marker_breakpoint_ops
;
12438 strace_marker_p (struct breakpoint
*b
)
12440 return b
->ops
== &strace_marker_breakpoint_ops
;
12443 /* Delete a breakpoint and clean up all traces of it in the data
12447 delete_breakpoint (struct breakpoint
*bpt
)
12449 gdb_assert (bpt
!= NULL
);
12451 /* Has this bp already been deleted? This can happen because
12452 multiple lists can hold pointers to bp's. bpstat lists are
12455 One example of this happening is a watchpoint's scope bp. When
12456 the scope bp triggers, we notice that the watchpoint is out of
12457 scope, and delete it. We also delete its scope bp. But the
12458 scope bp is marked "auto-deleting", and is already on a bpstat.
12459 That bpstat is then checked for auto-deleting bp's, which are
12462 A real solution to this problem might involve reference counts in
12463 bp's, and/or giving them pointers back to their referencing
12464 bpstat's, and teaching delete_breakpoint to only free a bp's
12465 storage when no more references were extent. A cheaper bandaid
12467 if (bpt
->type
== bp_none
)
12470 /* At least avoid this stale reference until the reference counting
12471 of breakpoints gets resolved. */
12472 if (bpt
->related_breakpoint
!= bpt
)
12474 struct breakpoint
*related
;
12475 struct watchpoint
*w
;
12477 if (bpt
->type
== bp_watchpoint_scope
)
12478 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12479 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12480 w
= (struct watchpoint
*) bpt
;
12484 watchpoint_del_at_next_stop (w
);
12486 /* Unlink bpt from the bpt->related_breakpoint ring. */
12487 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12488 related
= related
->related_breakpoint
);
12489 related
->related_breakpoint
= bpt
->related_breakpoint
;
12490 bpt
->related_breakpoint
= bpt
;
12493 /* watch_command_1 creates a watchpoint but only sets its number if
12494 update_watchpoint succeeds in creating its bp_locations. If there's
12495 a problem in that process, we'll be asked to delete the half-created
12496 watchpoint. In that case, don't announce the deletion. */
12498 gdb::observers::breakpoint_deleted
.notify (bpt
);
12500 if (breakpoint_chain
== bpt
)
12501 breakpoint_chain
= bpt
->next
;
12503 for (breakpoint
*b
: all_breakpoints ())
12504 if (b
->next
== bpt
)
12506 b
->next
= bpt
->next
;
12510 /* Be sure no bpstat's are pointing at the breakpoint after it's
12512 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12513 in all threads for now. Note that we cannot just remove bpstats
12514 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12515 commands are associated with the bpstat; if we remove it here,
12516 then the later call to bpstat_do_actions (&stop_bpstat); in
12517 event-top.c won't do anything, and temporary breakpoints with
12518 commands won't work. */
12520 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12522 /* Now that breakpoint is removed from breakpoint list, update the
12523 global location list. This will remove locations that used to
12524 belong to this breakpoint. Do this before freeing the breakpoint
12525 itself, since remove_breakpoint looks at location's owner. It
12526 might be better design to have location completely
12527 self-contained, but it's not the case now. */
12528 update_global_location_list (UGLL_DONT_INSERT
);
12530 /* On the chance that someone will soon try again to delete this
12531 same bp, we mark it as deleted before freeing its storage. */
12532 bpt
->type
= bp_none
;
12536 /* Iterator function to call a user-provided callback function once
12537 for each of B and its related breakpoints. */
12540 iterate_over_related_breakpoints (struct breakpoint
*b
,
12541 gdb::function_view
<void (breakpoint
*)> function
)
12543 struct breakpoint
*related
;
12548 struct breakpoint
*next
;
12550 /* FUNCTION may delete RELATED. */
12551 next
= related
->related_breakpoint
;
12553 if (next
== related
)
12555 /* RELATED is the last ring entry. */
12556 function (related
);
12558 /* FUNCTION may have deleted it, so we'd never reach back to
12559 B. There's nothing left to do anyway, so just break
12564 function (related
);
12568 while (related
!= b
);
12572 delete_command (const char *arg
, int from_tty
)
12578 int breaks_to_delete
= 0;
12580 /* Delete all breakpoints if no argument. Do not delete
12581 internal breakpoints, these have to be deleted with an
12582 explicit breakpoint number argument. */
12583 for (breakpoint
*b
: all_breakpoints ())
12584 if (user_breakpoint_p (b
))
12586 breaks_to_delete
= 1;
12590 /* Ask user only if there are some breakpoints to delete. */
12592 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
12593 for (breakpoint
*b
: all_breakpoints_safe ())
12594 if (user_breakpoint_p (b
))
12595 delete_breakpoint (b
);
12598 map_breakpoint_numbers
12599 (arg
, [&] (breakpoint
*br
)
12601 iterate_over_related_breakpoints (br
, delete_breakpoint
);
12605 /* Return true if all locations of B bound to PSPACE are pending. If
12606 PSPACE is NULL, all locations of all program spaces are
12610 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
12612 for (bp_location
*loc
: b
->locations ())
12613 if ((pspace
== NULL
12614 || loc
->pspace
== pspace
)
12615 && !loc
->shlib_disabled
12616 && !loc
->pspace
->executing_startup
)
12621 /* Subroutine of update_breakpoint_locations to simplify it.
12622 Return non-zero if multiple fns in list LOC have the same name.
12623 Null names are ignored. */
12626 ambiguous_names_p (struct bp_location
*loc
)
12628 struct bp_location
*l
;
12629 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
12632 for (l
= loc
; l
!= NULL
; l
= l
->next
)
12635 const char *name
= l
->function_name
.get ();
12637 /* Allow for some names to be NULL, ignore them. */
12641 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
12643 /* NOTE: We can assume slot != NULL here because xcalloc never
12653 /* When symbols change, it probably means the sources changed as well,
12654 and it might mean the static tracepoint markers are no longer at
12655 the same address or line numbers they used to be at last we
12656 checked. Losing your static tracepoints whenever you rebuild is
12657 undesirable. This function tries to resync/rematch gdb static
12658 tracepoints with the markers on the target, for static tracepoints
12659 that have not been set by marker id. Static tracepoint that have
12660 been set by marker id are reset by marker id in breakpoint_re_set.
12663 1) For a tracepoint set at a specific address, look for a marker at
12664 the old PC. If one is found there, assume to be the same marker.
12665 If the name / string id of the marker found is different from the
12666 previous known name, assume that means the user renamed the marker
12667 in the sources, and output a warning.
12669 2) For a tracepoint set at a given line number, look for a marker
12670 at the new address of the old line number. If one is found there,
12671 assume to be the same marker. If the name / string id of the
12672 marker found is different from the previous known name, assume that
12673 means the user renamed the marker in the sources, and output a
12676 3) If a marker is no longer found at the same address or line, it
12677 may mean the marker no longer exists. But it may also just mean
12678 the code changed a bit. Maybe the user added a few lines of code
12679 that made the marker move up or down (in line number terms). Ask
12680 the target for info about the marker with the string id as we knew
12681 it. If found, update line number and address in the matching
12682 static tracepoint. This will get confused if there's more than one
12683 marker with the same ID (possible in UST, although unadvised
12684 precisely because it confuses tools). */
12686 static struct symtab_and_line
12687 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
12689 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12690 struct static_tracepoint_marker marker
;
12695 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12697 if (target_static_tracepoint_marker_at (pc
, &marker
))
12699 if (tp
->static_trace_marker_id
!= marker
.str_id
)
12700 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12701 b
->number
, tp
->static_trace_marker_id
.c_str (),
12702 marker
.str_id
.c_str ());
12704 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
12709 /* Old marker wasn't found on target at lineno. Try looking it up
12711 if (!sal
.explicit_pc
12713 && sal
.symtab
!= NULL
12714 && !tp
->static_trace_marker_id
.empty ())
12716 std::vector
<static_tracepoint_marker
> markers
12717 = target_static_tracepoint_markers_by_strid
12718 (tp
->static_trace_marker_id
.c_str ());
12720 if (!markers
.empty ())
12722 struct symbol
*sym
;
12723 struct static_tracepoint_marker
*tpmarker
;
12724 struct ui_out
*uiout
= current_uiout
;
12725 struct explicit_location explicit_loc
;
12727 tpmarker
= &markers
[0];
12729 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
12731 warning (_("marker for static tracepoint %d (%s) not "
12732 "found at previous line number"),
12733 b
->number
, tp
->static_trace_marker_id
.c_str ());
12735 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
12736 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
12737 uiout
->text ("Now in ");
12740 uiout
->field_string ("func", sym
->print_name (),
12741 function_name_style
.style ());
12742 uiout
->text (" at ");
12744 uiout
->field_string ("file",
12745 symtab_to_filename_for_display (sal2
.symtab
),
12746 file_name_style
.style ());
12749 if (uiout
->is_mi_like_p ())
12751 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
12753 uiout
->field_string ("fullname", fullname
);
12756 uiout
->field_signed ("line", sal2
.line
);
12757 uiout
->text ("\n");
12759 b
->loc
->line_number
= sal2
.line
;
12760 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
12762 b
->location
.reset (NULL
);
12763 initialize_explicit_location (&explicit_loc
);
12764 explicit_loc
.source_filename
12765 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
12766 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
12767 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
12768 b
->location
= new_explicit_location (&explicit_loc
);
12770 /* Might be nice to check if function changed, and warn if
12777 /* Returns 1 iff locations A and B are sufficiently same that
12778 we don't need to report breakpoint as changed. */
12781 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
12785 if (a
->address
!= b
->address
)
12788 if (a
->shlib_disabled
!= b
->shlib_disabled
)
12791 if (a
->enabled
!= b
->enabled
)
12794 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
12801 if ((a
== NULL
) != (b
== NULL
))
12807 /* Split all locations of B that are bound to PSPACE out of B's
12808 location list to a separate list and return that list's head. If
12809 PSPACE is NULL, hoist out all locations of B. */
12811 static struct bp_location
*
12812 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
12814 struct bp_location head
;
12815 struct bp_location
*i
= b
->loc
;
12816 struct bp_location
**i_link
= &b
->loc
;
12817 struct bp_location
*hoisted
= &head
;
12819 if (pspace
== NULL
)
12830 if (i
->pspace
== pspace
)
12845 /* Create new breakpoint locations for B (a hardware or software
12846 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
12847 zero, then B is a ranged breakpoint. Only recreates locations for
12848 FILTER_PSPACE. Locations of other program spaces are left
12852 update_breakpoint_locations (struct breakpoint
*b
,
12853 struct program_space
*filter_pspace
,
12854 gdb::array_view
<const symtab_and_line
> sals
,
12855 gdb::array_view
<const symtab_and_line
> sals_end
)
12857 struct bp_location
*existing_locations
;
12859 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
12861 /* Ranged breakpoints have only one start location and one end
12863 b
->enable_state
= bp_disabled
;
12864 gdb_printf (gdb_stderr
,
12865 _("Could not reset ranged breakpoint %d: "
12866 "multiple locations found\n"),
12871 /* If there's no new locations, and all existing locations are
12872 pending, don't do anything. This optimizes the common case where
12873 all locations are in the same shared library, that was unloaded.
12874 We'd like to retain the location, so that when the library is
12875 loaded again, we don't loose the enabled/disabled status of the
12876 individual locations. */
12877 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
12880 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
12882 for (const auto &sal
: sals
)
12884 struct bp_location
*new_loc
;
12886 switch_to_program_space_and_thread (sal
.pspace
);
12888 new_loc
= add_location_to_breakpoint (b
, &sal
);
12890 /* Reparse conditions, they might contain references to the
12892 if (b
->cond_string
!= NULL
)
12896 s
= b
->cond_string
.get ();
12899 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
12900 block_for_pc (sal
.pc
),
12903 catch (const gdb_exception_error
&e
)
12905 new_loc
->disabled_by_cond
= true;
12909 if (!sals_end
.empty ())
12911 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
12913 new_loc
->length
= end
- sals
[0].pc
+ 1;
12917 /* If possible, carry over 'disable' status from existing
12920 struct bp_location
*e
= existing_locations
;
12921 /* If there are multiple breakpoints with the same function name,
12922 e.g. for inline functions, comparing function names won't work.
12923 Instead compare pc addresses; this is just a heuristic as things
12924 may have moved, but in practice it gives the correct answer
12925 often enough until a better solution is found. */
12926 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
12928 for (; e
; e
= e
->next
)
12930 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
12932 if (have_ambiguous_names
)
12934 for (bp_location
*l
: b
->locations ())
12936 /* Ignore software vs hardware location type at
12937 this point, because with "set breakpoint
12938 auto-hw", after a re-set, locations that were
12939 hardware can end up as software, or vice versa.
12940 As mentioned above, this is an heuristic and in
12941 practice should give the correct answer often
12943 if (breakpoint_locations_match (e
, l
, true))
12945 l
->enabled
= e
->enabled
;
12946 l
->disabled_by_cond
= e
->disabled_by_cond
;
12953 for (bp_location
*l
: b
->locations ())
12954 if (l
->function_name
12955 && strcmp (e
->function_name
.get (),
12956 l
->function_name
.get ()) == 0)
12958 l
->enabled
= e
->enabled
;
12959 l
->disabled_by_cond
= e
->disabled_by_cond
;
12967 if (!locations_are_equal (existing_locations
, b
->loc
))
12968 gdb::observers::breakpoint_modified
.notify (b
);
12971 /* Find the SaL locations corresponding to the given LOCATION.
12972 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
12974 static std::vector
<symtab_and_line
>
12975 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
12976 struct program_space
*search_pspace
, int *found
)
12978 struct gdb_exception exception
;
12980 gdb_assert (b
->ops
!= NULL
);
12982 std::vector
<symtab_and_line
> sals
;
12986 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
12988 catch (gdb_exception_error
&e
)
12990 int not_found_and_ok
= 0;
12992 /* For pending breakpoints, it's expected that parsing will
12993 fail until the right shared library is loaded. User has
12994 already told to create pending breakpoints and don't need
12995 extra messages. If breakpoint is in bp_shlib_disabled
12996 state, then user already saw the message about that
12997 breakpoint being disabled, and don't want to see more
12999 if (e
.error
== NOT_FOUND_ERROR
13000 && (b
->condition_not_parsed
13002 && search_pspace
!= NULL
13003 && b
->loc
->pspace
!= search_pspace
)
13004 || (b
->loc
&& b
->loc
->shlib_disabled
)
13005 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13006 || b
->enable_state
== bp_disabled
))
13007 not_found_and_ok
= 1;
13009 if (!not_found_and_ok
)
13011 /* We surely don't want to warn about the same breakpoint
13012 10 times. One solution, implemented here, is disable
13013 the breakpoint on error. Another solution would be to
13014 have separate 'warning emitted' flag. Since this
13015 happens only when a binary has changed, I don't know
13016 which approach is better. */
13017 b
->enable_state
= bp_disabled
;
13021 exception
= std::move (e
);
13024 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13026 for (auto &sal
: sals
)
13027 resolve_sal_pc (&sal
);
13028 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13030 gdb::unique_xmalloc_ptr
<char> cond_string
, extra_string
;
13033 find_condition_and_thread_for_sals (sals
, b
->extra_string
.get (),
13034 &cond_string
, &thread
,
13035 &task
, &extra_string
);
13036 gdb_assert (b
->cond_string
== NULL
);
13038 b
->cond_string
= std::move (cond_string
);
13039 b
->thread
= thread
;
13042 b
->extra_string
= std::move (extra_string
);
13043 b
->condition_not_parsed
= 0;
13046 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13047 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13057 /* The default re_set method, for typical hardware or software
13058 breakpoints. Reevaluate the breakpoint and recreate its
13062 breakpoint_re_set_default (struct breakpoint
*b
)
13064 struct program_space
*filter_pspace
= current_program_space
;
13065 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13068 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13069 filter_pspace
, &found
);
13071 expanded
= std::move (sals
);
13073 if (b
->location_range_end
!= NULL
)
13075 std::vector
<symtab_and_line
> sals_end
13076 = location_to_sals (b
, b
->location_range_end
.get (),
13077 filter_pspace
, &found
);
13079 expanded_end
= std::move (sals_end
);
13082 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13085 /* Default method for creating SALs from an address string. It basically
13086 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13089 create_sals_from_location_default (struct event_location
*location
,
13090 struct linespec_result
*canonical
,
13091 enum bptype type_wanted
)
13093 parse_breakpoint_sals (location
, canonical
);
13096 /* Call create_breakpoints_sal for the given arguments. This is the default
13097 function for the `create_breakpoints_sal' method of
13101 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13102 struct linespec_result
*canonical
,
13103 gdb::unique_xmalloc_ptr
<char> cond_string
,
13104 gdb::unique_xmalloc_ptr
<char> extra_string
,
13105 enum bptype type_wanted
,
13106 enum bpdisp disposition
,
13108 int task
, int ignore_count
,
13109 const struct breakpoint_ops
*ops
,
13110 int from_tty
, int enabled
,
13111 int internal
, unsigned flags
)
13113 create_breakpoints_sal (gdbarch
, canonical
,
13114 std::move (cond_string
),
13115 std::move (extra_string
),
13116 type_wanted
, disposition
,
13117 thread
, task
, ignore_count
, ops
, from_tty
,
13118 enabled
, internal
, flags
);
13121 /* Decode the line represented by S by calling decode_line_full. This is the
13122 default function for the `decode_location' method of breakpoint_ops. */
13124 static std::vector
<symtab_and_line
>
13125 decode_location_default (struct breakpoint
*b
,
13126 struct event_location
*location
,
13127 struct program_space
*search_pspace
)
13129 struct linespec_result canonical
;
13131 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13132 NULL
, 0, &canonical
, multiple_symbols_all
,
13135 /* We should get 0 or 1 resulting SALs. */
13136 gdb_assert (canonical
.lsals
.size () < 2);
13138 if (!canonical
.lsals
.empty ())
13140 const linespec_sals
&lsal
= canonical
.lsals
[0];
13141 return std::move (lsal
.sals
);
13146 /* Reset a breakpoint. */
13149 breakpoint_re_set_one (breakpoint
*b
)
13151 input_radix
= b
->input_radix
;
13152 set_language (b
->language
);
13154 b
->ops
->re_set (b
);
13157 /* Re-set breakpoint locations for the current program space.
13158 Locations bound to other program spaces are left untouched. */
13161 breakpoint_re_set (void)
13164 scoped_restore_current_language save_language
;
13165 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13166 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13168 /* breakpoint_re_set_one sets the current_language to the language
13169 of the breakpoint it is resetting (see prepare_re_set_context)
13170 before re-evaluating the breakpoint's location. This change can
13171 unfortunately get undone by accident if the language_mode is set
13172 to auto, and we either switch frames, or more likely in this context,
13173 we select the current frame.
13175 We prevent this by temporarily turning the language_mode to
13176 language_mode_manual. We restore it once all breakpoints
13177 have been reset. */
13178 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13179 language_mode
= language_mode_manual
;
13181 /* Note: we must not try to insert locations until after all
13182 breakpoints have been re-set. Otherwise, e.g., when re-setting
13183 breakpoint 1, we'd insert the locations of breakpoint 2, which
13184 hadn't been re-set yet, and thus may have stale locations. */
13186 for (breakpoint
*b
: all_breakpoints_safe ())
13190 breakpoint_re_set_one (b
);
13192 catch (const gdb_exception
&ex
)
13194 exception_fprintf (gdb_stderr
, ex
,
13195 "Error in re-setting breakpoint %d: ",
13200 jit_breakpoint_re_set ();
13203 create_overlay_event_breakpoint ();
13204 create_longjmp_master_breakpoint ();
13205 create_std_terminate_master_breakpoint ();
13206 create_exception_master_breakpoint ();
13208 /* Now we can insert. */
13209 update_global_location_list (UGLL_MAY_INSERT
);
13212 /* Reset the thread number of this breakpoint:
13214 - If the breakpoint is for all threads, leave it as-is.
13215 - Else, reset it to the current thread for inferior_ptid. */
13217 breakpoint_re_set_thread (struct breakpoint
*b
)
13219 if (b
->thread
!= -1)
13221 b
->thread
= inferior_thread ()->global_num
;
13223 /* We're being called after following a fork. The new fork is
13224 selected as current, and unless this was a vfork will have a
13225 different program space from the original thread. Reset that
13227 b
->loc
->pspace
= current_program_space
;
13231 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13232 If from_tty is nonzero, it prints a message to that effect,
13233 which ends with a period (no newline). */
13236 set_ignore_count (int bptnum
, int count
, int from_tty
)
13241 for (breakpoint
*b
: all_breakpoints ())
13242 if (b
->number
== bptnum
)
13244 if (is_tracepoint (b
))
13246 if (from_tty
&& count
!= 0)
13247 gdb_printf (_("Ignore count ignored for tracepoint %d."),
13252 b
->ignore_count
= count
;
13256 gdb_printf (_("Will stop next time "
13257 "breakpoint %d is reached."),
13259 else if (count
== 1)
13260 gdb_printf (_("Will ignore next crossing of breakpoint %d."),
13263 gdb_printf (_("Will ignore next %d "
13264 "crossings of breakpoint %d."),
13267 gdb::observers::breakpoint_modified
.notify (b
);
13271 error (_("No breakpoint number %d."), bptnum
);
13274 /* Command to set ignore-count of breakpoint N to COUNT. */
13277 ignore_command (const char *args
, int from_tty
)
13279 const char *p
= args
;
13283 error_no_arg (_("a breakpoint number"));
13285 num
= get_number (&p
);
13287 error (_("bad breakpoint number: '%s'"), args
);
13289 error (_("Second argument (specified ignore-count) is missing."));
13291 set_ignore_count (num
,
13292 longest_to_int (value_as_long (parse_and_eval (p
))),
13299 /* Call FUNCTION on each of the breakpoints with numbers in the range
13300 defined by BP_NUM_RANGE (an inclusive range). */
13303 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13304 gdb::function_view
<void (breakpoint
*)> function
)
13306 if (bp_num_range
.first
== 0)
13308 warning (_("bad breakpoint number at or near '%d'"),
13309 bp_num_range
.first
);
13313 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13315 bool match
= false;
13317 for (breakpoint
*b
: all_breakpoints_safe ())
13318 if (b
->number
== i
)
13325 gdb_printf (_("No breakpoint number %d.\n"), i
);
13330 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13334 map_breakpoint_numbers (const char *args
,
13335 gdb::function_view
<void (breakpoint
*)> function
)
13337 if (args
== NULL
|| *args
== '\0')
13338 error_no_arg (_("one or more breakpoint numbers"));
13340 number_or_range_parser
parser (args
);
13342 while (!parser
.finished ())
13344 int num
= parser
.get_number ();
13345 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13349 /* Return the breakpoint location structure corresponding to the
13350 BP_NUM and LOC_NUM values. */
13352 static struct bp_location
*
13353 find_location_by_number (int bp_num
, int loc_num
)
13355 breakpoint
*b
= get_breakpoint (bp_num
);
13357 if (!b
|| b
->number
!= bp_num
)
13358 error (_("Bad breakpoint number '%d'"), bp_num
);
13361 error (_("Bad breakpoint location number '%d'"), loc_num
);
13364 for (bp_location
*loc
: b
->locations ())
13365 if (++n
== loc_num
)
13368 error (_("Bad breakpoint location number '%d'"), loc_num
);
13371 /* Modes of operation for extract_bp_num. */
13372 enum class extract_bp_kind
13374 /* Extracting a breakpoint number. */
13377 /* Extracting a location number. */
13381 /* Extract a breakpoint or location number (as determined by KIND)
13382 from the string starting at START. TRAILER is a character which
13383 can be found after the number. If you don't want a trailer, use
13384 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13385 string. This always returns a positive integer. */
13388 extract_bp_num (extract_bp_kind kind
, const char *start
,
13389 int trailer
, const char **end_out
= NULL
)
13391 const char *end
= start
;
13392 int num
= get_number_trailer (&end
, trailer
);
13394 error (kind
== extract_bp_kind::bp
13395 ? _("Negative breakpoint number '%.*s'")
13396 : _("Negative breakpoint location number '%.*s'"),
13397 int (end
- start
), start
);
13399 error (kind
== extract_bp_kind::bp
13400 ? _("Bad breakpoint number '%.*s'")
13401 : _("Bad breakpoint location number '%.*s'"),
13402 int (end
- start
), start
);
13404 if (end_out
!= NULL
)
13409 /* Extract a breakpoint or location range (as determined by KIND) in
13410 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13411 representing the (inclusive) range. The returned pair's elements
13412 are always positive integers. */
13414 static std::pair
<int, int>
13415 extract_bp_or_bp_range (extract_bp_kind kind
,
13416 const std::string
&arg
,
13417 std::string::size_type arg_offset
)
13419 std::pair
<int, int> range
;
13420 const char *bp_loc
= &arg
[arg_offset
];
13421 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13422 if (dash
!= std::string::npos
)
13424 /* bp_loc is a range (x-z). */
13425 if (arg
.length () == dash
+ 1)
13426 error (kind
== extract_bp_kind::bp
13427 ? _("Bad breakpoint number at or near: '%s'")
13428 : _("Bad breakpoint location number at or near: '%s'"),
13432 const char *start_first
= bp_loc
;
13433 const char *start_second
= &arg
[dash
+ 1];
13434 range
.first
= extract_bp_num (kind
, start_first
, '-');
13435 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
13437 if (range
.first
> range
.second
)
13438 error (kind
== extract_bp_kind::bp
13439 ? _("Inverted breakpoint range at '%.*s'")
13440 : _("Inverted breakpoint location range at '%.*s'"),
13441 int (end
- start_first
), start_first
);
13445 /* bp_loc is a single value. */
13446 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
13447 range
.second
= range
.first
;
13452 /* Extract the breakpoint/location range specified by ARG. Returns
13453 the breakpoint range in BP_NUM_RANGE, and the location range in
13456 ARG may be in any of the following forms:
13458 x where 'x' is a breakpoint number.
13459 x-y where 'x' and 'y' specify a breakpoint numbers range.
13460 x.y where 'x' is a breakpoint number and 'y' a location number.
13461 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
13462 location number range.
13466 extract_bp_number_and_location (const std::string
&arg
,
13467 std::pair
<int, int> &bp_num_range
,
13468 std::pair
<int, int> &bp_loc_range
)
13470 std::string::size_type dot
= arg
.find ('.');
13472 if (dot
!= std::string::npos
)
13474 /* Handle 'x.y' and 'x.y-z' cases. */
13476 if (arg
.length () == dot
+ 1 || dot
== 0)
13477 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
13480 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
13481 bp_num_range
.second
= bp_num_range
.first
;
13483 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
13488 /* Handle x and x-y cases. */
13490 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
13491 bp_loc_range
.first
= 0;
13492 bp_loc_range
.second
= 0;
13496 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
13497 specifies whether to enable or disable. */
13500 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
13502 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
13505 if (loc
->disabled_by_cond
&& enable
)
13506 error (_("Breakpoint %d's condition is invalid at location %d, "
13507 "cannot enable."), bp_num
, loc_num
);
13509 if (loc
->enabled
!= enable
)
13511 loc
->enabled
= enable
;
13512 mark_breakpoint_location_modified (loc
);
13514 if (target_supports_enable_disable_tracepoint ()
13515 && current_trace_status ()->running
&& loc
->owner
13516 && is_tracepoint (loc
->owner
))
13517 target_disable_tracepoint (loc
);
13519 update_global_location_list (UGLL_DONT_INSERT
);
13521 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13524 /* Enable or disable a range of breakpoint locations. BP_NUM is the
13525 number of the breakpoint, and BP_LOC_RANGE specifies the
13526 (inclusive) range of location numbers of that breakpoint to
13527 enable/disable. ENABLE specifies whether to enable or disable the
13531 enable_disable_breakpoint_location_range (int bp_num
,
13532 std::pair
<int, int> &bp_loc_range
,
13535 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
13536 enable_disable_bp_num_loc (bp_num
, i
, enable
);
13539 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13540 If from_tty is nonzero, it prints a message to that effect,
13541 which ends with a period (no newline). */
13544 disable_breakpoint (struct breakpoint
*bpt
)
13546 /* Never disable a watchpoint scope breakpoint; we want to
13547 hit them when we leave scope so we can delete both the
13548 watchpoint and its scope breakpoint at that time. */
13549 if (bpt
->type
== bp_watchpoint_scope
)
13552 bpt
->enable_state
= bp_disabled
;
13554 /* Mark breakpoint locations modified. */
13555 mark_breakpoint_modified (bpt
);
13557 if (target_supports_enable_disable_tracepoint ()
13558 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13560 for (bp_location
*location
: bpt
->locations ())
13561 target_disable_tracepoint (location
);
13564 update_global_location_list (UGLL_DONT_INSERT
);
13566 gdb::observers::breakpoint_modified
.notify (bpt
);
13569 /* Enable or disable the breakpoint(s) or breakpoint location(s)
13570 specified in ARGS. ARGS may be in any of the formats handled by
13571 extract_bp_number_and_location. ENABLE specifies whether to enable
13572 or disable the breakpoints/locations. */
13575 enable_disable_command (const char *args
, int from_tty
, bool enable
)
13579 for (breakpoint
*bpt
: all_breakpoints ())
13580 if (user_breakpoint_p (bpt
))
13583 enable_breakpoint (bpt
);
13585 disable_breakpoint (bpt
);
13590 std::string num
= extract_arg (&args
);
13592 while (!num
.empty ())
13594 std::pair
<int, int> bp_num_range
, bp_loc_range
;
13596 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
13598 if (bp_loc_range
.first
== bp_loc_range
.second
13599 && bp_loc_range
.first
== 0)
13601 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
13602 map_breakpoint_number_range (bp_num_range
,
13604 ? enable_breakpoint
13605 : disable_breakpoint
);
13609 /* Handle breakpoint ids with formats 'x.y' or
13611 enable_disable_breakpoint_location_range
13612 (bp_num_range
.first
, bp_loc_range
, enable
);
13614 num
= extract_arg (&args
);
13619 /* The disable command disables the specified breakpoints/locations
13620 (or all defined breakpoints) so they're no longer effective in
13621 stopping the inferior. ARGS may be in any of the forms defined in
13622 extract_bp_number_and_location. */
13625 disable_command (const char *args
, int from_tty
)
13627 enable_disable_command (args
, from_tty
, false);
13631 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13634 int target_resources_ok
;
13636 if (bpt
->type
== bp_hardware_breakpoint
)
13639 i
= hw_breakpoint_used_count ();
13640 target_resources_ok
=
13641 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13643 if (target_resources_ok
== 0)
13644 error (_("No hardware breakpoint support in the target."));
13645 else if (target_resources_ok
< 0)
13646 error (_("Hardware breakpoints used exceeds limit."));
13649 if (is_watchpoint (bpt
))
13651 /* Initialize it just to avoid a GCC false warning. */
13652 enum enable_state orig_enable_state
= bp_disabled
;
13656 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13658 orig_enable_state
= bpt
->enable_state
;
13659 bpt
->enable_state
= bp_enabled
;
13660 update_watchpoint (w
, 1 /* reparse */);
13662 catch (const gdb_exception
&e
)
13664 bpt
->enable_state
= orig_enable_state
;
13665 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13671 bpt
->enable_state
= bp_enabled
;
13673 /* Mark breakpoint locations modified. */
13674 mark_breakpoint_modified (bpt
);
13676 if (target_supports_enable_disable_tracepoint ()
13677 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13679 for (bp_location
*location
: bpt
->locations ())
13680 target_enable_tracepoint (location
);
13683 bpt
->disposition
= disposition
;
13684 bpt
->enable_count
= count
;
13685 update_global_location_list (UGLL_MAY_INSERT
);
13687 gdb::observers::breakpoint_modified
.notify (bpt
);
13692 enable_breakpoint (struct breakpoint
*bpt
)
13694 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13697 /* The enable command enables the specified breakpoints/locations (or
13698 all defined breakpoints) so they once again become (or continue to
13699 be) effective in stopping the inferior. ARGS may be in any of the
13700 forms defined in extract_bp_number_and_location. */
13703 enable_command (const char *args
, int from_tty
)
13705 enable_disable_command (args
, from_tty
, true);
13709 enable_once_command (const char *args
, int from_tty
)
13711 map_breakpoint_numbers
13712 (args
, [&] (breakpoint
*b
)
13714 iterate_over_related_breakpoints
13715 (b
, [&] (breakpoint
*bpt
)
13717 enable_breakpoint_disp (bpt
, disp_disable
, 1);
13723 enable_count_command (const char *args
, int from_tty
)
13728 error_no_arg (_("hit count"));
13730 count
= get_number (&args
);
13732 map_breakpoint_numbers
13733 (args
, [&] (breakpoint
*b
)
13735 iterate_over_related_breakpoints
13736 (b
, [&] (breakpoint
*bpt
)
13738 enable_breakpoint_disp (bpt
, disp_disable
, count
);
13744 enable_delete_command (const char *args
, int from_tty
)
13746 map_breakpoint_numbers
13747 (args
, [&] (breakpoint
*b
)
13749 iterate_over_related_breakpoints
13750 (b
, [&] (breakpoint
*bpt
)
13752 enable_breakpoint_disp (bpt
, disp_del
, 1);
13757 /* Invalidate last known value of any hardware watchpoint if
13758 the memory which that value represents has been written to by
13762 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
13763 CORE_ADDR addr
, ssize_t len
,
13764 const bfd_byte
*data
)
13766 for (breakpoint
*bp
: all_breakpoints ())
13767 if (bp
->enable_state
== bp_enabled
13768 && bp
->type
== bp_hardware_watchpoint
)
13770 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
13772 if (wp
->val_valid
&& wp
->val
!= nullptr)
13774 for (bp_location
*loc
: bp
->locations ())
13775 if (loc
->loc_type
== bp_loc_hardware_watchpoint
13776 && loc
->address
+ loc
->length
> addr
13777 && addr
+ len
> loc
->address
)
13780 wp
->val_valid
= false;
13786 /* Create and insert a breakpoint for software single step. */
13789 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
13790 const address_space
*aspace
,
13793 struct thread_info
*tp
= inferior_thread ();
13794 struct symtab_and_line sal
;
13795 CORE_ADDR pc
= next_pc
;
13797 if (tp
->control
.single_step_breakpoints
== NULL
)
13799 tp
->control
.single_step_breakpoints
13800 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
13803 sal
= find_pc_line (pc
, 0);
13805 sal
.section
= find_pc_overlay (pc
);
13806 sal
.explicit_pc
= 1;
13807 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
13809 update_global_location_list (UGLL_INSERT
);
13812 /* Insert single step breakpoints according to the current state. */
13815 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
13817 struct regcache
*regcache
= get_current_regcache ();
13818 std::vector
<CORE_ADDR
> next_pcs
;
13820 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
13822 if (!next_pcs
.empty ())
13824 struct frame_info
*frame
= get_current_frame ();
13825 const address_space
*aspace
= get_frame_address_space (frame
);
13827 for (CORE_ADDR pc
: next_pcs
)
13828 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
13836 /* See breakpoint.h. */
13839 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
13840 const address_space
*aspace
,
13843 for (bp_location
*loc
: bp
->locations ())
13845 && breakpoint_location_address_match (loc
, aspace
, pc
))
13851 /* Check whether a software single-step breakpoint is inserted at
13855 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
13858 for (breakpoint
*bpt
: all_breakpoints ())
13860 if (bpt
->type
== bp_single_step
13861 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
13867 /* Tracepoint-specific operations. */
13869 /* Set tracepoint count to NUM. */
13871 set_tracepoint_count (int num
)
13873 tracepoint_count
= num
;
13874 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
13878 trace_command (const char *arg
, int from_tty
)
13880 event_location_up location
= string_to_event_location (&arg
,
13882 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
13883 (location
.get (), true /* is_tracepoint */);
13885 create_breakpoint (get_current_arch (),
13887 NULL
, 0, arg
, false, 1 /* parse arg */,
13889 bp_tracepoint
/* type_wanted */,
13890 0 /* Ignore count */,
13891 pending_break_support
,
13895 0 /* internal */, 0);
13899 ftrace_command (const char *arg
, int from_tty
)
13901 event_location_up location
= string_to_event_location (&arg
,
13903 create_breakpoint (get_current_arch (),
13905 NULL
, 0, arg
, false, 1 /* parse arg */,
13907 bp_fast_tracepoint
/* type_wanted */,
13908 0 /* Ignore count */,
13909 pending_break_support
,
13910 &vtable_breakpoint_ops
,
13913 0 /* internal */, 0);
13916 /* strace command implementation. Creates a static tracepoint. */
13919 strace_command (const char *arg
, int from_tty
)
13921 struct breakpoint_ops
*ops
;
13922 event_location_up location
;
13924 /* Decide if we are dealing with a static tracepoint marker (`-m'),
13925 or with a normal static tracepoint. */
13926 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
13928 ops
= &strace_marker_breakpoint_ops
;
13929 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
13933 ops
= &vtable_breakpoint_ops
;
13934 location
= string_to_event_location (&arg
, current_language
);
13937 create_breakpoint (get_current_arch (),
13939 NULL
, 0, arg
, false, 1 /* parse arg */,
13941 bp_static_tracepoint
/* type_wanted */,
13942 0 /* Ignore count */,
13943 pending_break_support
,
13947 0 /* internal */, 0);
13950 /* Set up a fake reader function that gets command lines from a linked
13951 list that was acquired during tracepoint uploading. */
13953 static struct uploaded_tp
*this_utp
;
13954 static int next_cmd
;
13957 read_uploaded_action (void)
13959 char *rslt
= nullptr;
13961 if (next_cmd
< this_utp
->cmd_strings
.size ())
13963 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
13970 /* Given information about a tracepoint as recorded on a target (which
13971 can be either a live system or a trace file), attempt to create an
13972 equivalent GDB tracepoint. This is not a reliable process, since
13973 the target does not necessarily have all the information used when
13974 the tracepoint was originally defined. */
13976 struct tracepoint
*
13977 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
13979 const char *addr_str
;
13980 char small_buf
[100];
13981 struct tracepoint
*tp
;
13983 if (utp
->at_string
)
13984 addr_str
= utp
->at_string
.get ();
13987 /* In the absence of a source location, fall back to raw
13988 address. Since there is no way to confirm that the address
13989 means the same thing as when the trace was started, warn the
13991 warning (_("Uploaded tracepoint %d has no "
13992 "source location, using raw address"),
13994 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
13995 addr_str
= small_buf
;
13998 /* There's not much we can do with a sequence of bytecodes. */
13999 if (utp
->cond
&& !utp
->cond_string
)
14000 warning (_("Uploaded tracepoint %d condition "
14001 "has no source form, ignoring it"),
14004 event_location_up location
= string_to_event_location (&addr_str
,
14006 if (!create_breakpoint (get_current_arch (),
14008 utp
->cond_string
.get (), -1, addr_str
,
14009 false /* force_condition */,
14010 0 /* parse cond/thread */,
14012 utp
->type
/* type_wanted */,
14013 0 /* Ignore count */,
14014 pending_break_support
,
14015 &vtable_breakpoint_ops
,
14017 utp
->enabled
/* enabled */,
14019 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14022 /* Get the tracepoint we just created. */
14023 tp
= get_tracepoint (tracepoint_count
);
14024 gdb_assert (tp
!= NULL
);
14028 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14031 trace_pass_command (small_buf
, 0);
14034 /* If we have uploaded versions of the original commands, set up a
14035 special-purpose "reader" function and call the usual command line
14036 reader, then pass the result to the breakpoint command-setting
14038 if (!utp
->cmd_strings
.empty ())
14040 counted_command_line cmd_list
;
14045 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14047 breakpoint_set_commands (tp
, std::move (cmd_list
));
14049 else if (!utp
->actions
.empty ()
14050 || !utp
->step_actions
.empty ())
14051 warning (_("Uploaded tracepoint %d actions "
14052 "have no source form, ignoring them"),
14055 /* Copy any status information that might be available. */
14056 tp
->hit_count
= utp
->hit_count
;
14057 tp
->traceframe_usage
= utp
->traceframe_usage
;
14062 /* Print information on tracepoint number TPNUM_EXP, or all if
14066 info_tracepoints_command (const char *args
, int from_tty
)
14068 struct ui_out
*uiout
= current_uiout
;
14071 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14073 if (num_printed
== 0)
14075 if (args
== NULL
|| *args
== '\0')
14076 uiout
->message ("No tracepoints.\n");
14078 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14081 default_collect_info ();
14084 /* The 'enable trace' command enables tracepoints.
14085 Not supported by all targets. */
14087 enable_trace_command (const char *args
, int from_tty
)
14089 enable_command (args
, from_tty
);
14092 /* The 'disable trace' command disables tracepoints.
14093 Not supported by all targets. */
14095 disable_trace_command (const char *args
, int from_tty
)
14097 disable_command (args
, from_tty
);
14100 /* Remove a tracepoint (or all if no argument). */
14102 delete_trace_command (const char *arg
, int from_tty
)
14108 int breaks_to_delete
= 0;
14110 /* Delete all breakpoints if no argument.
14111 Do not delete internal or call-dummy breakpoints, these
14112 have to be deleted with an explicit breakpoint number
14114 for (breakpoint
*tp
: all_tracepoints ())
14115 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
14117 breaks_to_delete
= 1;
14121 /* Ask user only if there are some breakpoints to delete. */
14123 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14125 for (breakpoint
*b
: all_breakpoints_safe ())
14126 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14127 delete_breakpoint (b
);
14131 map_breakpoint_numbers
14132 (arg
, [&] (breakpoint
*br
)
14134 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14138 /* Helper function for trace_pass_command. */
14141 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14143 tp
->pass_count
= count
;
14144 gdb::observers::breakpoint_modified
.notify (tp
);
14146 gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
14147 tp
->number
, count
);
14150 /* Set passcount for tracepoint.
14152 First command argument is passcount, second is tracepoint number.
14153 If tracepoint number omitted, apply to most recently defined.
14154 Also accepts special argument "all". */
14157 trace_pass_command (const char *args
, int from_tty
)
14159 struct tracepoint
*t1
;
14162 if (args
== 0 || *args
== 0)
14163 error (_("passcount command requires an "
14164 "argument (count + optional TP num)"));
14166 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14168 args
= skip_spaces (args
);
14169 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14171 args
+= 3; /* Skip special argument "all". */
14173 error (_("Junk at end of arguments."));
14175 for (breakpoint
*b
: all_tracepoints ())
14177 t1
= (struct tracepoint
*) b
;
14178 trace_pass_set_count (t1
, count
, from_tty
);
14181 else if (*args
== '\0')
14183 t1
= get_tracepoint_by_number (&args
, NULL
);
14185 trace_pass_set_count (t1
, count
, from_tty
);
14189 number_or_range_parser
parser (args
);
14190 while (!parser
.finished ())
14192 t1
= get_tracepoint_by_number (&args
, &parser
);
14194 trace_pass_set_count (t1
, count
, from_tty
);
14199 struct tracepoint
*
14200 get_tracepoint (int num
)
14202 for (breakpoint
*t
: all_tracepoints ())
14203 if (t
->number
== num
)
14204 return (struct tracepoint
*) t
;
14209 /* Find the tracepoint with the given target-side number (which may be
14210 different from the tracepoint number after disconnecting and
14213 struct tracepoint
*
14214 get_tracepoint_by_number_on_target (int num
)
14216 for (breakpoint
*b
: all_tracepoints ())
14218 struct tracepoint
*t
= (struct tracepoint
*) b
;
14220 if (t
->number_on_target
== num
)
14227 /* Utility: parse a tracepoint number and look it up in the list.
14228 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14229 If the argument is missing, the most recent tracepoint
14230 (tracepoint_count) is returned. */
14232 struct tracepoint
*
14233 get_tracepoint_by_number (const char **arg
,
14234 number_or_range_parser
*parser
)
14237 const char *instring
= arg
== NULL
? NULL
: *arg
;
14239 if (parser
!= NULL
)
14241 gdb_assert (!parser
->finished ());
14242 tpnum
= parser
->get_number ();
14244 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14245 tpnum
= tracepoint_count
;
14247 tpnum
= get_number (arg
);
14251 if (instring
&& *instring
)
14252 gdb_printf (_("bad tracepoint number at or near '%s'\n"),
14255 gdb_printf (_("No previous tracepoint\n"));
14259 for (breakpoint
*t
: all_tracepoints ())
14260 if (t
->number
== tpnum
)
14261 return (struct tracepoint
*) t
;
14263 gdb_printf ("No tracepoint number %d.\n", tpnum
);
14268 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14270 if (b
->thread
!= -1)
14271 gdb_printf (fp
, " thread %d", b
->thread
);
14274 gdb_printf (fp
, " task %d", b
->task
);
14276 gdb_printf (fp
, "\n");
14279 /* Save information on user settable breakpoints (watchpoints, etc) to
14280 a new script file named FILENAME. If FILTER is non-NULL, call it
14281 on each breakpoint and only include the ones for which it returns
14285 save_breakpoints (const char *filename
, int from_tty
,
14286 bool (*filter
) (const struct breakpoint
*))
14289 int extra_trace_bits
= 0;
14291 if (filename
== 0 || *filename
== 0)
14292 error (_("Argument required (file name in which to save)"));
14294 /* See if we have anything to save. */
14295 for (breakpoint
*tp
: all_breakpoints ())
14297 /* Skip internal and momentary breakpoints. */
14298 if (!user_breakpoint_p (tp
))
14301 /* If we have a filter, only save the breakpoints it accepts. */
14302 if (filter
&& !filter (tp
))
14307 if (is_tracepoint (tp
))
14309 extra_trace_bits
= 1;
14311 /* We can stop searching. */
14318 warning (_("Nothing to save."));
14322 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14326 if (!fp
.open (expanded_filename
.get (), "w"))
14327 error (_("Unable to open file '%s' for saving (%s)"),
14328 expanded_filename
.get (), safe_strerror (errno
));
14330 if (extra_trace_bits
)
14331 save_trace_state_variables (&fp
);
14333 for (breakpoint
*tp
: all_breakpoints ())
14335 /* Skip internal and momentary breakpoints. */
14336 if (!user_breakpoint_p (tp
))
14339 /* If we have a filter, only save the breakpoints it accepts. */
14340 if (filter
&& !filter (tp
))
14343 tp
->ops
->print_recreate (tp
, &fp
);
14345 /* Note, we can't rely on tp->number for anything, as we can't
14346 assume the recreated breakpoint numbers will match. Use $bpnum
14349 if (tp
->cond_string
)
14350 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
.get ());
14352 if (tp
->ignore_count
)
14353 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14355 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
14357 fp
.puts (" commands\n");
14359 current_uiout
->redirect (&fp
);
14362 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
14364 catch (const gdb_exception
&ex
)
14366 current_uiout
->redirect (NULL
);
14370 current_uiout
->redirect (NULL
);
14371 fp
.puts (" end\n");
14374 if (tp
->enable_state
== bp_disabled
)
14375 fp
.puts ("disable $bpnum\n");
14377 /* If this is a multi-location breakpoint, check if the locations
14378 should be individually disabled. Watchpoint locations are
14379 special, and not user visible. */
14380 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14384 for (bp_location
*loc
: tp
->locations ())
14387 fp
.printf ("disable $bpnum.%d\n", n
);
14394 if (extra_trace_bits
&& !default_collect
.empty ())
14395 fp
.printf ("set default-collect %s\n", default_collect
.c_str ());
14398 gdb_printf (_("Saved to file '%s'.\n"), expanded_filename
.get ());
14401 /* The `save breakpoints' command. */
14404 save_breakpoints_command (const char *args
, int from_tty
)
14406 save_breakpoints (args
, from_tty
, NULL
);
14409 /* The `save tracepoints' command. */
14412 save_tracepoints_command (const char *args
, int from_tty
)
14414 save_breakpoints (args
, from_tty
, is_tracepoint
);
14418 /* This help string is used to consolidate all the help string for specifying
14419 locations used by several commands. */
14421 #define LOCATION_HELP_STRING \
14422 "Linespecs are colon-separated lists of location parameters, such as\n\
14423 source filename, function name, label name, and line number.\n\
14424 Example: To specify the start of a label named \"the_top\" in the\n\
14425 function \"fact\" in the file \"factorial.c\", use\n\
14426 \"factorial.c:fact:the_top\".\n\
14428 Address locations begin with \"*\" and specify an exact address in the\n\
14429 program. Example: To specify the fourth byte past the start function\n\
14430 \"main\", use \"*main + 4\".\n\
14432 Explicit locations are similar to linespecs but use an option/argument\n\
14433 syntax to specify location parameters.\n\
14434 Example: To specify the start of the label named \"the_top\" in the\n\
14435 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
14436 -function fact -label the_top\".\n\
14438 By default, a specified function is matched against the program's\n\
14439 functions in all scopes. For C++, this means in all namespaces and\n\
14440 classes. For Ada, this means in all packages. E.g., in C++,\n\
14441 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
14442 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
14443 specified name as a complete fully-qualified name instead."
14445 /* This help string is used for the break, hbreak, tbreak and thbreak
14446 commands. It is defined as a macro to prevent duplication.
14447 COMMAND should be a string constant containing the name of the
14450 #define BREAK_ARGS_HELP(command) \
14451 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
14452 \t[-force-condition] [if CONDITION]\n\
14453 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
14454 probe point. Accepted values are `-probe' (for a generic, automatically\n\
14455 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
14456 `-probe-dtrace' (for a DTrace probe).\n\
14457 LOCATION may be a linespec, address, or explicit location as described\n\
14460 With no LOCATION, uses current execution address of the selected\n\
14461 stack frame. This is useful for breaking on return to a stack frame.\n\
14463 THREADNUM is the number from \"info threads\".\n\
14464 CONDITION is a boolean expression.\n\
14466 With the \"-force-condition\" flag, the condition is defined even when\n\
14467 it is invalid for all current locations.\n\
14468 \n" LOCATION_HELP_STRING "\n\n\
14469 Multiple breakpoints at one place are permitted, and useful if their\n\
14470 conditions are different.\n\
14472 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14474 /* List of subcommands for "catch". */
14475 static struct cmd_list_element
*catch_cmdlist
;
14477 /* List of subcommands for "tcatch". */
14478 static struct cmd_list_element
*tcatch_cmdlist
;
14481 add_catch_command (const char *name
, const char *docstring
,
14482 cmd_func_ftype
*func
,
14483 completer_ftype
*completer
,
14484 void *user_data_catch
,
14485 void *user_data_tcatch
)
14487 struct cmd_list_element
*command
;
14489 command
= add_cmd (name
, class_breakpoint
, docstring
,
14491 command
->func
= func
;
14492 command
->set_context (user_data_catch
);
14493 set_cmd_completer (command
, completer
);
14495 command
= add_cmd (name
, class_breakpoint
, docstring
,
14497 command
->func
= func
;
14498 command
->set_context (user_data_tcatch
);
14499 set_cmd_completer (command
, completer
);
14502 /* Zero if any of the breakpoint's locations could be a location where
14503 functions have been inlined, nonzero otherwise. */
14506 is_non_inline_function (struct breakpoint
*b
)
14508 /* The shared library event breakpoint is set on the address of a
14509 non-inline function. */
14510 if (b
->type
== bp_shlib_event
)
14516 /* Nonzero if the specified PC cannot be a location where functions
14517 have been inlined. */
14520 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
14521 const target_waitstatus
&ws
)
14523 for (breakpoint
*b
: all_breakpoints ())
14525 if (!is_non_inline_function (b
))
14528 for (bp_location
*bl
: b
->locations ())
14530 if (!bl
->shlib_disabled
14531 && bpstat_check_location (bl
, aspace
, pc
, ws
))
14539 /* Remove any references to OBJFILE which is going to be freed. */
14542 breakpoint_free_objfile (struct objfile
*objfile
)
14544 for (bp_location
*loc
: all_bp_locations ())
14545 if (loc
->symtab
!= NULL
&& loc
->symtab
->compunit ()->objfile () == objfile
)
14546 loc
->symtab
= NULL
;
14550 initialize_breakpoint_ops (void)
14552 static int initialized
= 0;
14554 struct breakpoint_ops
*ops
;
14560 /* The breakpoint_ops structure to be inherit by all kinds of
14561 breakpoints (real breakpoints, i.e., user "break" breakpoints,
14562 internal and momentary breakpoints, etc.). */
14563 ops
= &bkpt_base_breakpoint_ops
;
14564 *ops
= base_breakpoint_ops
;
14565 ops
->re_set
= bkpt_re_set
;
14566 ops
->insert_location
= bkpt_insert_location
;
14567 ops
->remove_location
= bkpt_remove_location
;
14568 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
14569 ops
->create_sals_from_location
= create_sals_from_location_default
;
14570 ops
->create_breakpoints_sal
= create_breakpoints_sal_default
;
14571 ops
->decode_location
= bkpt_decode_location
;
14573 /* The breakpoint_ops structure to be used in regular breakpoints. */
14574 ops
= &bkpt_breakpoint_ops
;
14575 *ops
= bkpt_base_breakpoint_ops
;
14576 ops
->re_set
= bkpt_re_set
;
14577 ops
->resources_needed
= bkpt_resources_needed
;
14578 ops
->print_it
= bkpt_print_it
;
14579 ops
->print_mention
= bkpt_print_mention
;
14580 ops
->print_recreate
= bkpt_print_recreate
;
14582 /* Ranged breakpoints. */
14583 ops
= &ranged_breakpoint_ops
;
14584 *ops
= bkpt_breakpoint_ops
;
14585 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
14586 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
14587 ops
->print_it
= print_it_ranged_breakpoint
;
14588 ops
->print_one
= print_one_ranged_breakpoint
;
14589 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
14590 ops
->print_mention
= print_mention_ranged_breakpoint
;
14591 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
14593 /* Internal breakpoints. */
14594 ops
= &internal_breakpoint_ops
;
14595 *ops
= bkpt_base_breakpoint_ops
;
14596 ops
->re_set
= internal_bkpt_re_set
;
14597 ops
->check_status
= internal_bkpt_check_status
;
14598 ops
->print_it
= internal_bkpt_print_it
;
14599 ops
->print_mention
= internal_bkpt_print_mention
;
14601 /* Momentary breakpoints. */
14602 ops
= &momentary_breakpoint_ops
;
14603 *ops
= bkpt_base_breakpoint_ops
;
14604 ops
->re_set
= momentary_bkpt_re_set
;
14605 ops
->check_status
= momentary_bkpt_check_status
;
14606 ops
->print_it
= momentary_bkpt_print_it
;
14607 ops
->print_mention
= momentary_bkpt_print_mention
;
14609 /* Probe breakpoints. */
14610 ops
= &bkpt_probe_breakpoint_ops
;
14611 *ops
= bkpt_breakpoint_ops
;
14612 ops
->insert_location
= bkpt_probe_insert_location
;
14613 ops
->remove_location
= bkpt_probe_remove_location
;
14614 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
14615 ops
->decode_location
= bkpt_probe_decode_location
;
14617 /* Probe tracepoints. */
14618 ops
= &tracepoint_probe_breakpoint_ops
;
14619 *ops
= vtable_breakpoint_ops
;
14620 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
14621 ops
->decode_location
= tracepoint_probe_decode_location
;
14623 /* Static tracepoints with marker (`-m'). */
14624 ops
= &strace_marker_breakpoint_ops
;
14625 *ops
= vtable_breakpoint_ops
;
14626 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
14627 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
14628 ops
->decode_location
= strace_marker_decode_location
;
14630 ops
= &dprintf_breakpoint_ops
;
14631 *ops
= bkpt_base_breakpoint_ops
;
14632 ops
->re_set
= dprintf_re_set
;
14633 ops
->resources_needed
= bkpt_resources_needed
;
14634 ops
->print_it
= bkpt_print_it
;
14635 ops
->print_mention
= bkpt_print_mention
;
14636 ops
->print_recreate
= dprintf_print_recreate
;
14637 ops
->after_condition_true
= dprintf_after_condition_true
;
14638 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
14641 /* Chain containing all defined "enable breakpoint" subcommands. */
14643 static struct cmd_list_element
*enablebreaklist
= NULL
;
14645 /* See breakpoint.h. */
14647 cmd_list_element
*commands_cmd_element
= nullptr;
14649 void _initialize_breakpoint ();
14651 _initialize_breakpoint ()
14653 struct cmd_list_element
*c
;
14655 initialize_breakpoint_ops ();
14657 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
14659 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
14661 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
14664 breakpoint_chain
= 0;
14665 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14666 before a breakpoint is set. */
14667 breakpoint_count
= 0;
14669 tracepoint_count
= 0;
14671 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
14672 Set ignore-count of breakpoint number N to COUNT.\n\
14673 Usage is `ignore N COUNT'."));
14675 commands_cmd_element
= add_com ("commands", class_breakpoint
,
14676 commands_command
, _("\
14677 Set commands to be executed when the given breakpoints are hit.\n\
14678 Give a space-separated breakpoint list as argument after \"commands\".\n\
14679 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
14681 With no argument, the targeted breakpoint is the last one set.\n\
14682 The commands themselves follow starting on the next line.\n\
14683 Type a line containing \"end\" to indicate the end of them.\n\
14684 Give \"silent\" as the first line to make the breakpoint silent;\n\
14685 then no output is printed when it is hit, except what the commands print."));
14687 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
14688 static std::string condition_command_help
14689 = gdb::option::build_help (_("\
14690 Specify breakpoint number N to break only if COND is true.\n\
14691 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
14692 is an expression to be evaluated whenever breakpoint N is reached.\n\
14695 %OPTIONS%"), cc_opts
);
14697 c
= add_com ("condition", class_breakpoint
, condition_command
,
14698 condition_command_help
.c_str ());
14699 set_cmd_completer_handle_brkchars (c
, condition_completer
);
14701 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
14702 Set a temporary breakpoint.\n\
14703 Like \"break\" except the breakpoint is only temporary,\n\
14704 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14705 by using \"enable delete\" on the breakpoint number.\n\
14707 BREAK_ARGS_HELP ("tbreak")));
14708 set_cmd_completer (c
, location_completer
);
14710 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
14711 Set a hardware assisted breakpoint.\n\
14712 Like \"break\" except the breakpoint requires hardware support,\n\
14713 some target hardware may not have this support.\n\
14715 BREAK_ARGS_HELP ("hbreak")));
14716 set_cmd_completer (c
, location_completer
);
14718 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
14719 Set a temporary hardware assisted breakpoint.\n\
14720 Like \"hbreak\" except the breakpoint is only temporary,\n\
14721 so it will be deleted when hit.\n\
14723 BREAK_ARGS_HELP ("thbreak")));
14724 set_cmd_completer (c
, location_completer
);
14726 cmd_list_element
*enable_cmd
14727 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
14728 Enable all or some breakpoints.\n\
14729 Usage: enable [BREAKPOINTNUM]...\n\
14730 Give breakpoint numbers (separated by spaces) as arguments.\n\
14731 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14732 This is used to cancel the effect of the \"disable\" command.\n\
14733 With a subcommand you can enable temporarily."),
14734 &enablelist
, 1, &cmdlist
);
14736 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
14738 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
14739 Enable all or some breakpoints.\n\
14740 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
14741 Give breakpoint numbers (separated by spaces) as arguments.\n\
14742 This is used to cancel the effect of the \"disable\" command.\n\
14743 May be abbreviated to simply \"enable\"."),
14744 &enablebreaklist
, 1, &enablelist
);
14746 add_cmd ("once", no_class
, enable_once_command
, _("\
14747 Enable some breakpoints for one hit.\n\
14748 Usage: enable breakpoints once BREAKPOINTNUM...\n\
14749 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14752 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14753 Enable some breakpoints and delete when hit.\n\
14754 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
14755 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14758 add_cmd ("count", no_class
, enable_count_command
, _("\
14759 Enable some breakpoints for COUNT hits.\n\
14760 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
14761 If a breakpoint is hit while enabled in this fashion,\n\
14762 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14765 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14766 Enable some breakpoints and delete when hit.\n\
14767 Usage: enable delete BREAKPOINTNUM...\n\
14768 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14771 add_cmd ("once", no_class
, enable_once_command
, _("\
14772 Enable some breakpoints for one hit.\n\
14773 Usage: enable once BREAKPOINTNUM...\n\
14774 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14777 add_cmd ("count", no_class
, enable_count_command
, _("\
14778 Enable some breakpoints for COUNT hits.\n\
14779 Usage: enable count COUNT BREAKPOINTNUM...\n\
14780 If a breakpoint is hit while enabled in this fashion,\n\
14781 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14784 cmd_list_element
*disable_cmd
14785 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
14786 Disable all or some breakpoints.\n\
14787 Usage: disable [BREAKPOINTNUM]...\n\
14788 Arguments are breakpoint numbers with spaces in between.\n\
14789 To disable all breakpoints, give no argument.\n\
14790 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14791 &disablelist
, 1, &cmdlist
);
14792 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
14793 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
14795 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
14796 Disable all or some breakpoints.\n\
14797 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
14798 Arguments are breakpoint numbers with spaces in between.\n\
14799 To disable all breakpoints, give no argument.\n\
14800 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14801 This command may be abbreviated \"disable\"."),
14804 cmd_list_element
*delete_cmd
14805 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
14806 Delete all or some breakpoints.\n\
14807 Usage: delete [BREAKPOINTNUM]...\n\
14808 Arguments are breakpoint numbers with spaces in between.\n\
14809 To delete all breakpoints, give no argument.\n\
14811 Also a prefix command for deletion of other GDB objects."),
14812 &deletelist
, 1, &cmdlist
);
14813 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
14814 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
14816 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
14817 Delete all or some breakpoints or auto-display expressions.\n\
14818 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
14819 Arguments are breakpoint numbers with spaces in between.\n\
14820 To delete all breakpoints, give no argument.\n\
14821 This command may be abbreviated \"delete\"."),
14824 cmd_list_element
*clear_cmd
14825 = add_com ("clear", class_breakpoint
, clear_command
, _("\
14826 Clear breakpoint at specified location.\n\
14827 Argument may be a linespec, explicit, or address location as described below.\n\
14829 With no argument, clears all breakpoints in the line that the selected frame\n\
14830 is executing in.\n"
14831 "\n" LOCATION_HELP_STRING
"\n\n\
14832 See also the \"delete\" command which clears breakpoints by number."));
14833 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
14835 cmd_list_element
*break_cmd
14836 = add_com ("break", class_breakpoint
, break_command
, _("\
14837 Set breakpoint at specified location.\n"
14838 BREAK_ARGS_HELP ("break")));
14839 set_cmd_completer (break_cmd
, location_completer
);
14841 add_com_alias ("b", break_cmd
, class_run
, 1);
14842 add_com_alias ("br", break_cmd
, class_run
, 1);
14843 add_com_alias ("bre", break_cmd
, class_run
, 1);
14844 add_com_alias ("brea", break_cmd
, class_run
, 1);
14846 cmd_list_element
*info_breakpoints_cmd
14847 = add_info ("breakpoints", info_breakpoints_command
, _("\
14848 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14849 The \"Type\" column indicates one of:\n\
14850 \tbreakpoint - normal breakpoint\n\
14851 \twatchpoint - watchpoint\n\
14852 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14853 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14854 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14855 address and file/line number respectively.\n\
14857 Convenience variable \"$_\" and default examine address for \"x\"\n\
14858 are set to the address of the last breakpoint listed unless the command\n\
14859 is prefixed with \"server \".\n\n\
14860 Convenience variable \"$bpnum\" contains the number of the last\n\
14861 breakpoint set."));
14863 add_info_alias ("b", info_breakpoints_cmd
, 1);
14865 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
14866 Status of all breakpoints, or breakpoint number NUMBER.\n\
14867 The \"Type\" column indicates one of:\n\
14868 \tbreakpoint - normal breakpoint\n\
14869 \twatchpoint - watchpoint\n\
14870 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14871 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14872 \tuntil - internal breakpoint used by the \"until\" command\n\
14873 \tfinish - internal breakpoint used by the \"finish\" command\n\
14874 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14875 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14876 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14877 address and file/line number respectively.\n\
14879 Convenience variable \"$_\" and default examine address for \"x\"\n\
14880 are set to the address of the last breakpoint listed unless the command\n\
14881 is prefixed with \"server \".\n\n\
14882 Convenience variable \"$bpnum\" contains the number of the last\n\
14884 &maintenanceinfolist
);
14886 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
14887 Set catchpoints to catch events."),
14889 0/*allow-unknown*/, &cmdlist
);
14891 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
14892 Set temporary catchpoints to catch events."),
14894 0/*allow-unknown*/, &cmdlist
);
14896 const auto opts
= make_watch_options_def_group (nullptr);
14898 static const std::string watch_help
= gdb::option::build_help (_("\
14899 Set a watchpoint for EXPRESSION.\n\
14900 Usage: watch [-location] EXPRESSION\n\
14905 A watchpoint stops execution of your program whenever the value of\n\
14906 an expression changes."), opts
);
14907 c
= add_com ("watch", class_breakpoint
, watch_command
,
14908 watch_help
.c_str ());
14909 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14911 static const std::string rwatch_help
= gdb::option::build_help (_("\
14912 Set a read watchpoint for EXPRESSION.\n\
14913 Usage: rwatch [-location] EXPRESSION\n\
14918 A read watchpoint stops execution of your program whenever the value of\n\
14919 an expression is read."), opts
);
14920 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
14921 rwatch_help
.c_str ());
14922 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14924 static const std::string awatch_help
= gdb::option::build_help (_("\
14925 Set an access watchpoint for EXPRESSION.\n\
14926 Usage: awatch [-location] EXPRESSION\n\
14931 An access watchpoint stops execution of your program whenever the value\n\
14932 of an expression is either read or written."), opts
);
14933 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
14934 awatch_help
.c_str ());
14935 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14937 add_info ("watchpoints", info_watchpoints_command
, _("\
14938 Status of specified watchpoints (all watchpoints if no argument)."));
14940 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14941 respond to changes - contrary to the description. */
14942 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14943 &can_use_hw_watchpoints
, _("\
14944 Set debugger's willingness to use watchpoint hardware."), _("\
14945 Show debugger's willingness to use watchpoint hardware."), _("\
14946 If zero, gdb will not use hardware for new watchpoints, even if\n\
14947 such is available. (However, any hardware watchpoints that were\n\
14948 created before setting this to nonzero, will continue to use watchpoint\n\
14951 show_can_use_hw_watchpoints
,
14952 &setlist
, &showlist
);
14954 can_use_hw_watchpoints
= 1;
14956 /* Tracepoint manipulation commands. */
14958 cmd_list_element
*trace_cmd
14959 = add_com ("trace", class_breakpoint
, trace_command
, _("\
14960 Set a tracepoint at specified location.\n\
14962 BREAK_ARGS_HELP ("trace") "\n\
14963 Do \"help tracepoints\" for info on other tracepoint commands."));
14964 set_cmd_completer (trace_cmd
, location_completer
);
14966 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
14967 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
14968 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
14969 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
14971 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14972 Set a fast tracepoint at specified location.\n\
14974 BREAK_ARGS_HELP ("ftrace") "\n\
14975 Do \"help tracepoints\" for info on other tracepoint commands."));
14976 set_cmd_completer (c
, location_completer
);
14978 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
14979 Set a static tracepoint at location or marker.\n\
14981 strace [LOCATION] [if CONDITION]\n\
14982 LOCATION may be a linespec, explicit, or address location (described below) \n\
14983 or -m MARKER_ID.\n\n\
14984 If a marker id is specified, probe the marker with that name. With\n\
14985 no LOCATION, uses current execution address of the selected stack frame.\n\
14986 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14987 This collects arbitrary user data passed in the probe point call to the\n\
14988 tracing library. You can inspect it when analyzing the trace buffer,\n\
14989 by printing the $_sdata variable like any other convenience variable.\n\
14991 CONDITION is a boolean expression.\n\
14992 \n" LOCATION_HELP_STRING
"\n\n\
14993 Multiple tracepoints at one place are permitted, and useful if their\n\
14994 conditions are different.\n\
14996 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14997 Do \"help tracepoints\" for info on other tracepoint commands."));
14998 set_cmd_completer (c
, location_completer
);
15000 cmd_list_element
*info_tracepoints_cmd
15001 = add_info ("tracepoints", info_tracepoints_command
, _("\
15002 Status of specified tracepoints (all tracepoints if no argument).\n\
15003 Convenience variable \"$tpnum\" contains the number of the\n\
15004 last tracepoint set."));
15006 add_info_alias ("tp", info_tracepoints_cmd
, 1);
15008 cmd_list_element
*delete_tracepoints_cmd
15009 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15010 Delete specified tracepoints.\n\
15011 Arguments are tracepoint numbers, separated by spaces.\n\
15012 No argument means delete all tracepoints."),
15014 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
15016 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15017 Disable specified tracepoints.\n\
15018 Arguments are tracepoint numbers, separated by spaces.\n\
15019 No argument means disable all tracepoints."),
15021 deprecate_cmd (c
, "disable");
15023 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15024 Enable specified tracepoints.\n\
15025 Arguments are tracepoint numbers, separated by spaces.\n\
15026 No argument means enable all tracepoints."),
15028 deprecate_cmd (c
, "enable");
15030 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15031 Set the passcount for a tracepoint.\n\
15032 The trace will end when the tracepoint has been passed 'count' times.\n\
15033 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15034 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15036 add_basic_prefix_cmd ("save", class_breakpoint
,
15037 _("Save breakpoint definitions as a script."),
15039 0/*allow-unknown*/, &cmdlist
);
15041 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15042 Save current breakpoint definitions as a script.\n\
15043 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15044 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15045 session to restore them."),
15047 set_cmd_completer (c
, filename_completer
);
15049 cmd_list_element
*save_tracepoints_cmd
15050 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15051 Save current tracepoint definitions as a script.\n\
15052 Use the 'source' command in another debug session to restore them."),
15054 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
15056 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
15057 deprecate_cmd (c
, "save tracepoints");
15059 add_setshow_prefix_cmd ("breakpoint", class_maintenance
,
15061 Breakpoint specific settings.\n\
15062 Configure various breakpoint-specific variables such as\n\
15063 pending breakpoint behavior."),
15065 Breakpoint specific settings.\n\
15066 Configure various breakpoint-specific variables such as\n\
15067 pending breakpoint behavior."),
15068 &breakpoint_set_cmdlist
, &breakpoint_show_cmdlist
,
15069 &setlist
, &showlist
);
15071 add_setshow_auto_boolean_cmd ("pending", no_class
,
15072 &pending_break_support
, _("\
15073 Set debugger's behavior regarding pending breakpoints."), _("\
15074 Show debugger's behavior regarding pending breakpoints."), _("\
15075 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15076 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15077 an error. If auto, an unrecognized breakpoint location results in a\n\
15078 user-query to see if a pending breakpoint should be created."),
15080 show_pending_break_support
,
15081 &breakpoint_set_cmdlist
,
15082 &breakpoint_show_cmdlist
);
15084 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15086 add_setshow_boolean_cmd ("auto-hw", no_class
,
15087 &automatic_hardware_breakpoints
, _("\
15088 Set automatic usage of hardware breakpoints."), _("\
15089 Show automatic usage of hardware breakpoints."), _("\
15090 If set, the debugger will automatically use hardware breakpoints for\n\
15091 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15092 a warning will be emitted for such breakpoints."),
15094 show_automatic_hardware_breakpoints
,
15095 &breakpoint_set_cmdlist
,
15096 &breakpoint_show_cmdlist
);
15098 add_setshow_boolean_cmd ("always-inserted", class_support
,
15099 &always_inserted_mode
, _("\
15100 Set mode for inserting breakpoints."), _("\
15101 Show mode for inserting breakpoints."), _("\
15102 When this mode is on, breakpoints are inserted immediately as soon as\n\
15103 they're created, kept inserted even when execution stops, and removed\n\
15104 only when the user deletes them. When this mode is off (the default),\n\
15105 breakpoints are inserted only when execution continues, and removed\n\
15106 when execution stops."),
15108 &show_always_inserted_mode
,
15109 &breakpoint_set_cmdlist
,
15110 &breakpoint_show_cmdlist
);
15112 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15113 condition_evaluation_enums
,
15114 &condition_evaluation_mode_1
, _("\
15115 Set mode of breakpoint condition evaluation."), _("\
15116 Show mode of breakpoint condition evaluation."), _("\
15117 When this is set to \"host\", breakpoint conditions will be\n\
15118 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15119 breakpoint conditions will be downloaded to the target (if the target\n\
15120 supports such feature) and conditions will be evaluated on the target's side.\n\
15121 If this is set to \"auto\" (default), this will be automatically set to\n\
15122 \"target\" if it supports condition evaluation, otherwise it will\n\
15123 be set to \"host\"."),
15124 &set_condition_evaluation_mode
,
15125 &show_condition_evaluation_mode
,
15126 &breakpoint_set_cmdlist
,
15127 &breakpoint_show_cmdlist
);
15129 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15130 Set a breakpoint for an address range.\n\
15131 break-range START-LOCATION, END-LOCATION\n\
15132 where START-LOCATION and END-LOCATION can be one of the following:\n\
15133 LINENUM, for that line in the current file,\n\
15134 FILE:LINENUM, for that line in that file,\n\
15135 +OFFSET, for that number of lines after the current line\n\
15136 or the start of the range\n\
15137 FUNCTION, for the first line in that function,\n\
15138 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15139 *ADDRESS, for the instruction at that address.\n\
15141 The breakpoint will stop execution of the inferior whenever it executes\n\
15142 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15143 range (including START-LOCATION and END-LOCATION)."));
15145 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
15146 Set a dynamic printf at specified location.\n\
15147 dprintf location,format string,arg1,arg2,...\n\
15148 location may be a linespec, explicit, or address location.\n"
15149 "\n" LOCATION_HELP_STRING
));
15150 set_cmd_completer (c
, location_completer
);
15152 add_setshow_enum_cmd ("dprintf-style", class_support
,
15153 dprintf_style_enums
, &dprintf_style
, _("\
15154 Set the style of usage for dynamic printf."), _("\
15155 Show the style of usage for dynamic printf."), _("\
15156 This setting chooses how GDB will do a dynamic printf.\n\
15157 If the value is \"gdb\", then the printing is done by GDB to its own\n\
15158 console, as with the \"printf\" command.\n\
15159 If the value is \"call\", the print is done by calling a function in your\n\
15160 program; by default printf(), but you can choose a different function or\n\
15161 output stream by setting dprintf-function and dprintf-channel."),
15162 update_dprintf_commands
, NULL
,
15163 &setlist
, &showlist
);
15165 add_setshow_string_cmd ("dprintf-function", class_support
,
15166 &dprintf_function
, _("\
15167 Set the function to use for dynamic printf."), _("\
15168 Show the function to use for dynamic printf."), NULL
,
15169 update_dprintf_commands
, NULL
,
15170 &setlist
, &showlist
);
15172 add_setshow_string_cmd ("dprintf-channel", class_support
,
15173 &dprintf_channel
, _("\
15174 Set the channel to use for dynamic printf."), _("\
15175 Show the channel to use for dynamic printf."), NULL
,
15176 update_dprintf_commands
, NULL
,
15177 &setlist
, &showlist
);
15179 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
15180 &disconnected_dprintf
, _("\
15181 Set whether dprintf continues after GDB disconnects."), _("\
15182 Show whether dprintf continues after GDB disconnects."), _("\
15183 Use this to let dprintf commands continue to hit and produce output\n\
15184 even if GDB disconnects or detaches from the target."),
15187 &setlist
, &showlist
);
15189 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
15190 Target agent only formatted printing, like the C \"printf\" function.\n\
15191 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
15192 This supports most C printf format specifications, like %s, %d, etc.\n\
15193 This is useful for formatted output in user-defined commands."));
15195 automatic_hardware_breakpoints
= true;
15197 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
15199 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,