1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2021 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 "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 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 style in which to perform a dynamic printf. This is a user
257 option because different output options have different tradeoffs;
258 if GDB does the printing, there is better error handling if there
259 is a problem with any of the arguments, but using an inferior
260 function lets you have special-purpose printers and sending of
261 output to the same place as compiled-in print functions. */
263 static const char dprintf_style_gdb
[] = "gdb";
264 static const char dprintf_style_call
[] = "call";
265 static const char dprintf_style_agent
[] = "agent";
266 static const char *const dprintf_style_enums
[] = {
272 static const char *dprintf_style
= dprintf_style_gdb
;
274 /* The function to use for dynamic printf if the preferred style is to
275 call into the inferior. The value is simply a string that is
276 copied into the command, so it can be anything that GDB can
277 evaluate to a callable address, not necessarily a function name. */
279 static char *dprintf_function
;
281 /* The channel to use for dynamic printf if the preferred style is to
282 call into the inferior; if a nonempty string, it will be passed to
283 the call as the first argument, with the format string as the
284 second. As with the dprintf function, this can be anything that
285 GDB knows how to evaluate, so in addition to common choices like
286 "stderr", this could be an app-specific expression like
287 "mystreams[curlogger]". */
289 static char *dprintf_channel
;
291 /* True if dprintf commands should continue to operate even if GDB
293 static bool disconnected_dprintf
= true;
295 struct command_line
*
296 breakpoint_commands (struct breakpoint
*b
)
298 return b
->commands
? b
->commands
.get () : NULL
;
301 /* Flag indicating that a command has proceeded the inferior past the
302 current breakpoint. */
304 static bool breakpoint_proceeded
;
307 bpdisp_text (enum bpdisp disp
)
309 /* NOTE: the following values are a part of MI protocol and
310 represent values of 'disp' field returned when inferior stops at
312 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
314 return bpdisps
[(int) disp
];
317 /* Prototypes for exported functions. */
318 /* If FALSE, gdb will not use hardware support for watchpoints, even
319 if such is available. */
320 static int can_use_hw_watchpoints
;
323 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
324 struct cmd_list_element
*c
,
327 fprintf_filtered (file
,
328 _("Debugger's willingness to use "
329 "watchpoint hardware is %s.\n"),
333 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
334 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
335 for unrecognized breakpoint locations.
336 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
337 static enum auto_boolean pending_break_support
;
339 show_pending_break_support (struct ui_file
*file
, int from_tty
,
340 struct cmd_list_element
*c
,
343 fprintf_filtered (file
,
344 _("Debugger's behavior regarding "
345 "pending breakpoints is %s.\n"),
349 /* If true, gdb will automatically use hardware breakpoints for breakpoints
350 set with "break" but falling in read-only memory.
351 If false, gdb will warn about such breakpoints, but won't automatically
352 use hardware breakpoints. */
353 static bool automatic_hardware_breakpoints
;
355 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
356 struct cmd_list_element
*c
,
359 fprintf_filtered (file
,
360 _("Automatic usage of hardware breakpoints is %s.\n"),
364 /* If on, GDB keeps breakpoints inserted even if the inferior is
365 stopped, and immediately inserts any new breakpoints as soon as
366 they're created. If off (default), GDB keeps breakpoints off of
367 the target as long as possible. That is, it delays inserting
368 breakpoints until the next resume, and removes them again when the
369 target fully stops. This is a bit safer in case GDB crashes while
370 processing user input. */
371 static bool always_inserted_mode
= false;
374 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
375 struct cmd_list_element
*c
, const char *value
)
377 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
381 /* See breakpoint.h. */
384 breakpoints_should_be_inserted_now (void)
386 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
388 /* If breakpoints are global, they should be inserted even if no
389 thread under gdb's control is running, or even if there are
390 no threads under GDB's control yet. */
395 if (always_inserted_mode
)
397 /* The user wants breakpoints inserted even if all threads
402 for (inferior
*inf
: all_inferiors ())
403 if (inf
->has_execution ()
404 && threads_are_executing (inf
->process_target ()))
407 /* Don't remove breakpoints yet if, even though all threads are
408 stopped, we still have events to process. */
409 for (thread_info
*tp
: all_non_exited_threads ())
410 if (tp
->resumed () && tp
->has_pending_waitstatus ())
416 static const char condition_evaluation_both
[] = "host or target";
418 /* Modes for breakpoint condition evaluation. */
419 static const char condition_evaluation_auto
[] = "auto";
420 static const char condition_evaluation_host
[] = "host";
421 static const char condition_evaluation_target
[] = "target";
422 static const char *const condition_evaluation_enums
[] = {
423 condition_evaluation_auto
,
424 condition_evaluation_host
,
425 condition_evaluation_target
,
429 /* Global that holds the current mode for breakpoint condition evaluation. */
430 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
432 /* Global that we use to display information to the user (gets its value from
433 condition_evaluation_mode_1. */
434 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
436 /* Translate a condition evaluation mode MODE into either "host"
437 or "target". This is used mostly to translate from "auto" to the
438 real setting that is being used. It returns the translated
442 translate_condition_evaluation_mode (const char *mode
)
444 if (mode
== condition_evaluation_auto
)
446 if (target_supports_evaluation_of_breakpoint_conditions ())
447 return condition_evaluation_target
;
449 return condition_evaluation_host
;
455 /* Discovers what condition_evaluation_auto translates to. */
458 breakpoint_condition_evaluation_mode (void)
460 return translate_condition_evaluation_mode (condition_evaluation_mode
);
463 /* Return true if GDB should evaluate breakpoint conditions or false
467 gdb_evaluates_breakpoint_condition_p (void)
469 const char *mode
= breakpoint_condition_evaluation_mode ();
471 return (mode
== condition_evaluation_host
);
474 /* Are we executing breakpoint commands? */
475 static int executing_breakpoint_commands
;
477 /* Are overlay event breakpoints enabled? */
478 static int overlay_events_enabled
;
480 /* See description in breakpoint.h. */
481 bool target_exact_watchpoints
= false;
483 /* Walk the following statement or block through all breakpoints.
484 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
485 current breakpoint. */
487 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
488 for (B = breakpoint_chain; \
489 B ? (TMP=B->next, 1): 0; \
492 /* Chains of all breakpoints defined. */
494 static struct breakpoint
*breakpoint_chain
;
496 /* See breakpoint.h. */
501 return breakpoint_range (breakpoint_chain
);
504 /* See breakpoint.h. */
506 breakpoint_safe_range
507 all_breakpoints_safe ()
509 return breakpoint_safe_range (all_breakpoints ());
512 /* See breakpoint.h. */
517 return tracepoint_range (breakpoint_chain
);
520 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
522 static std::vector
<bp_location
*> bp_locations
;
524 /* See breakpoint.h. */
526 const std::vector
<bp_location
*> &
532 /* Range to iterate over breakpoint locations at a given address. */
534 struct bp_locations_at_addr_range
536 using iterator
= std::vector
<bp_location
*>::iterator
;
538 bp_locations_at_addr_range (CORE_ADDR addr
)
542 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
543 { return loc
->address
< addr_
; }
545 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
546 { return addr_
< loc
->address
; }
549 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
552 m_begin
= it_pair
.first
;
553 m_end
= it_pair
.second
;
556 iterator
begin () const
559 iterator
end () const
567 /* Return a range to iterate over all breakpoint locations exactly at address
570 If it's needed to iterate multiple times on the same range, it's possible
571 to save the range in a local variable and use it multiple times:
573 auto range = all_bp_locations_at_addr (addr);
575 for (bp_location *loc : range)
578 for (bp_location *loc : range)
581 This saves a bit of time, as it avoids re-doing the binary searches to find
582 the range's boundaries. Just remember not to change the bp_locations vector
583 in the mean time, as it could make the range's iterators stale. */
585 static bp_locations_at_addr_range
586 all_bp_locations_at_addr (CORE_ADDR addr
)
588 return bp_locations_at_addr_range (addr
);
591 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
592 ADDRESS for the current elements of BP_LOCATIONS which get a valid
593 result from bp_location_has_shadow. You can use it for roughly
594 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
595 an address you need to read. */
597 static CORE_ADDR bp_locations_placed_address_before_address_max
;
599 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
600 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
601 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
602 You can use it for roughly limiting the subrange of BP_LOCATIONS to
603 scan for shadow bytes for an address you need to read. */
605 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
607 /* The locations that no longer correspond to any breakpoint, unlinked
608 from the bp_locations array, but for which a hit may still be
609 reported by a target. */
610 static std::vector
<bp_location
*> moribund_locations
;
612 /* Number of last breakpoint made. */
614 static int breakpoint_count
;
616 /* The value of `breakpoint_count' before the last command that
617 created breakpoints. If the last (break-like) command created more
618 than one breakpoint, then the difference between BREAKPOINT_COUNT
619 and PREV_BREAKPOINT_COUNT is more than one. */
620 static int prev_breakpoint_count
;
622 /* Number of last tracepoint made. */
624 static int tracepoint_count
;
626 static struct cmd_list_element
*breakpoint_set_cmdlist
;
627 static struct cmd_list_element
*breakpoint_show_cmdlist
;
628 struct cmd_list_element
*save_cmdlist
;
630 /* Return whether a breakpoint is an active enabled breakpoint. */
632 breakpoint_enabled (struct breakpoint
*b
)
634 return (b
->enable_state
== bp_enabled
);
637 /* Set breakpoint count to NUM. */
640 set_breakpoint_count (int num
)
642 prev_breakpoint_count
= breakpoint_count
;
643 breakpoint_count
= num
;
644 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
647 /* Used by `start_rbreak_breakpoints' below, to record the current
648 breakpoint count before "rbreak" creates any breakpoint. */
649 static int rbreak_start_breakpoint_count
;
651 /* Called at the start an "rbreak" command to record the first
654 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
656 rbreak_start_breakpoint_count
= breakpoint_count
;
659 /* Called at the end of an "rbreak" command to record the last
662 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
664 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
667 /* Used in run_command to zero the hit count when a new run starts. */
670 clear_breakpoint_hit_counts (void)
672 for (breakpoint
*b
: all_breakpoints ())
677 /* Return the breakpoint with the specified number, or NULL
678 if the number does not refer to an existing breakpoint. */
681 get_breakpoint (int num
)
683 for (breakpoint
*b
: all_breakpoints ())
684 if (b
->number
== num
)
692 /* Mark locations as "conditions have changed" in case the target supports
693 evaluating conditions on its side. */
696 mark_breakpoint_modified (struct breakpoint
*b
)
698 /* This is only meaningful if the target is
699 evaluating conditions and if the user has
700 opted for condition evaluation on the target's
702 if (gdb_evaluates_breakpoint_condition_p ()
703 || !target_supports_evaluation_of_breakpoint_conditions ())
706 if (!is_breakpoint (b
))
709 for (bp_location
*loc
: b
->locations ())
710 loc
->condition_changed
= condition_modified
;
713 /* Mark location as "conditions have changed" in case the target supports
714 evaluating conditions on its side. */
717 mark_breakpoint_location_modified (struct bp_location
*loc
)
719 /* This is only meaningful if the target is
720 evaluating conditions and if the user has
721 opted for condition evaluation on the target's
723 if (gdb_evaluates_breakpoint_condition_p ()
724 || !target_supports_evaluation_of_breakpoint_conditions ())
728 if (!is_breakpoint (loc
->owner
))
731 loc
->condition_changed
= condition_modified
;
734 /* Sets the condition-evaluation mode using the static global
735 condition_evaluation_mode. */
738 set_condition_evaluation_mode (const char *args
, int from_tty
,
739 struct cmd_list_element
*c
)
741 const char *old_mode
, *new_mode
;
743 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
744 && !target_supports_evaluation_of_breakpoint_conditions ())
746 condition_evaluation_mode_1
= condition_evaluation_mode
;
747 warning (_("Target does not support breakpoint condition evaluation.\n"
748 "Using host evaluation mode instead."));
752 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
753 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
755 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
756 settings was "auto". */
757 condition_evaluation_mode
= condition_evaluation_mode_1
;
759 /* Only update the mode if the user picked a different one. */
760 if (new_mode
!= old_mode
)
762 /* If the user switched to a different evaluation mode, we
763 need to synch the changes with the target as follows:
765 "host" -> "target": Send all (valid) conditions to the target.
766 "target" -> "host": Remove all the conditions from the target.
769 if (new_mode
== condition_evaluation_target
)
771 /* Mark everything modified and synch conditions with the
773 for (bp_location
*loc
: all_bp_locations ())
774 mark_breakpoint_location_modified (loc
);
778 /* Manually mark non-duplicate locations to synch conditions
779 with the target. We do this to remove all the conditions the
780 target knows about. */
781 for (bp_location
*loc
: all_bp_locations ())
782 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
783 loc
->needs_update
= 1;
787 update_global_location_list (UGLL_MAY_INSERT
);
793 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
794 what "auto" is translating to. */
797 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
798 struct cmd_list_element
*c
, const char *value
)
800 if (condition_evaluation_mode
== condition_evaluation_auto
)
801 fprintf_filtered (file
,
802 _("Breakpoint condition evaluation "
803 "mode is %s (currently %s).\n"),
805 breakpoint_condition_evaluation_mode ());
807 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
811 /* Parse COND_STRING in the context of LOC and set as the condition
812 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
813 the number of LOC within its owner. In case of parsing error, mark
814 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
817 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
818 int bp_num
, int loc_num
)
820 bool has_junk
= false;
823 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
824 block_for_pc (loc
->address
), 0);
825 if (*cond_string
!= 0)
829 loc
->cond
= std::move (new_exp
);
830 if (loc
->disabled_by_cond
&& loc
->enabled
)
831 printf_filtered (_("Breakpoint %d's condition is now valid at "
832 "location %d, enabling.\n"),
835 loc
->disabled_by_cond
= false;
838 catch (const gdb_exception_error
&e
)
842 /* Warn if a user-enabled location is now becoming disabled-by-cond.
843 BP_NUM is 0 if the breakpoint is being defined for the first
844 time using the "break ... if ..." command, and non-zero if
847 warning (_("failed to validate condition at location %d.%d, "
848 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
850 warning (_("failed to validate condition at location %d, "
851 "disabling:\n %s"), loc_num
, e
.what ());
854 loc
->disabled_by_cond
= true;
858 error (_("Garbage '%s' follows condition"), cond_string
);
862 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
863 int from_tty
, bool force
)
867 xfree (b
->cond_string
);
868 b
->cond_string
= nullptr;
870 if (is_watchpoint (b
))
871 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
875 for (bp_location
*loc
: b
->locations ())
878 if (loc
->disabled_by_cond
&& loc
->enabled
)
879 printf_filtered (_("Breakpoint %d's condition is now valid at "
880 "location %d, enabling.\n"),
882 loc
->disabled_by_cond
= false;
885 /* No need to free the condition agent expression
886 bytecode (if we have one). We will handle this
887 when we go through update_global_location_list. */
892 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
896 if (is_watchpoint (b
))
898 innermost_block_tracker tracker
;
899 const char *arg
= exp
;
900 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
902 error (_("Junk at end of expression"));
903 watchpoint
*w
= static_cast<watchpoint
*> (b
);
904 w
->cond_exp
= std::move (new_exp
);
905 w
->cond_exp_valid_block
= tracker
.block ();
909 /* Parse and set condition expressions. We make two passes.
910 In the first, we parse the condition string to see if it
911 is valid in at least one location. If so, the condition
912 would be accepted. So we go ahead and set the locations'
913 conditions. In case no valid case is found, we throw
914 the error and the condition string will be rejected.
915 This two-pass approach is taken to avoid setting the
916 state of locations in case of a reject. */
917 for (bp_location
*loc
: b
->locations ())
921 const char *arg
= exp
;
922 parse_exp_1 (&arg
, loc
->address
,
923 block_for_pc (loc
->address
), 0);
925 error (_("Junk at end of expression"));
928 catch (const gdb_exception_error
&e
)
930 /* Condition string is invalid. If this happens to
931 be the last loc, abandon (if not forced) or continue
933 if (loc
->next
== nullptr && !force
)
938 /* If we reach here, the condition is valid at some locations. */
940 for (bp_location
*loc
: b
->locations ())
942 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
947 /* We know that the new condition parsed successfully. The
948 condition string of the breakpoint can be safely updated. */
949 xfree (b
->cond_string
);
950 b
->cond_string
= xstrdup (exp
);
951 b
->condition_not_parsed
= 0;
953 mark_breakpoint_modified (b
);
955 gdb::observers::breakpoint_modified
.notify (b
);
958 /* See breakpoint.h. */
961 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
964 for (breakpoint
*b
: all_breakpoints ())
965 if (b
->number
== bpnum
)
967 /* Check if this breakpoint has a "stop" method implemented in an
968 extension language. This method and conditions entered into GDB
969 from the CLI are mutually exclusive. */
970 const struct extension_language_defn
*extlang
971 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
975 error (_("Only one stop condition allowed. There is currently"
976 " a %s stop condition defined for this breakpoint."),
977 ext_lang_capitalized_name (extlang
));
979 set_breakpoint_condition (b
, exp
, from_tty
, force
);
981 if (is_breakpoint (b
))
982 update_global_location_list (UGLL_MAY_INSERT
);
987 error (_("No breakpoint number %d."), bpnum
);
990 /* The options for the "condition" command. */
992 struct condition_command_opts
995 bool force_condition
= false;
998 static const gdb::option::option_def condition_command_option_defs
[] = {
1000 gdb::option::flag_option_def
<condition_command_opts
> {
1002 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1003 N_("Set the condition even if it is invalid for all current locations."),
1008 /* Create an option_def_group for the "condition" options, with
1009 CC_OPTS as context. */
1011 static inline gdb::option::option_def_group
1012 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1014 return {{condition_command_option_defs
}, cc_opts
};
1017 /* Completion for the "condition" command. */
1020 condition_completer (struct cmd_list_element
*cmd
,
1021 completion_tracker
&tracker
,
1022 const char *text
, const char * /*word*/)
1024 bool has_no_arguments
= (*text
== '\0');
1025 condition_command_opts cc_opts
;
1026 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1027 if (gdb::option::complete_options
1028 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1031 text
= skip_spaces (text
);
1032 const char *space
= skip_to_space (text
);
1039 tracker
.advance_custom_word_point_by (1);
1040 /* We don't support completion of history indices. */
1041 if (!isdigit (text
[1]))
1042 complete_internalvar (tracker
, &text
[1]);
1046 /* Suggest the "-force" flag if no arguments are given. If
1047 arguments were passed, they either already include the flag,
1048 or we are beyond the point of suggesting it because it's
1049 positionally the first argument. */
1050 if (has_no_arguments
)
1051 gdb::option::complete_on_all_options (tracker
, group
);
1053 /* We're completing the breakpoint number. */
1054 len
= strlen (text
);
1056 for (breakpoint
*b
: all_breakpoints ())
1060 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1062 if (strncmp (number
, text
, len
) == 0)
1063 tracker
.add_completion (make_unique_xstrdup (number
));
1069 /* We're completing the expression part. Skip the breakpoint num. */
1070 const char *exp_start
= skip_spaces (space
);
1071 tracker
.advance_custom_word_point_by (exp_start
- text
);
1073 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1074 expression_completer (cmd
, tracker
, text
, word
);
1077 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1080 condition_command (const char *arg
, int from_tty
)
1086 error_no_arg (_("breakpoint number"));
1090 /* Check if the "-force" flag was passed. */
1091 condition_command_opts cc_opts
;
1092 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1093 gdb::option::process_options
1094 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1096 bnum
= get_number (&p
);
1098 error (_("Bad breakpoint argument: '%s'"), arg
);
1100 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1103 /* Check that COMMAND do not contain commands that are suitable
1104 only for tracepoints and not suitable for ordinary breakpoints.
1105 Throw if any such commands is found. */
1108 check_no_tracepoint_commands (struct command_line
*commands
)
1110 struct command_line
*c
;
1112 for (c
= commands
; c
; c
= c
->next
)
1114 if (c
->control_type
== while_stepping_control
)
1115 error (_("The 'while-stepping' command can "
1116 "only be used for tracepoints"));
1118 check_no_tracepoint_commands (c
->body_list_0
.get ());
1119 check_no_tracepoint_commands (c
->body_list_1
.get ());
1121 /* Not that command parsing removes leading whitespace and comment
1122 lines and also empty lines. So, we only need to check for
1123 command directly. */
1124 if (strstr (c
->line
, "collect ") == c
->line
)
1125 error (_("The 'collect' command can only be used for tracepoints"));
1127 if (strstr (c
->line
, "teval ") == c
->line
)
1128 error (_("The 'teval' command can only be used for tracepoints"));
1132 struct longjmp_breakpoint
: public breakpoint
1134 ~longjmp_breakpoint () override
;
1137 /* Encapsulate tests for different types of tracepoints. */
1140 is_tracepoint_type (bptype type
)
1142 return (type
== bp_tracepoint
1143 || type
== bp_fast_tracepoint
1144 || type
== bp_static_tracepoint
);
1148 is_longjmp_type (bptype type
)
1150 return type
== bp_longjmp
|| type
== bp_exception
;
1153 /* See breakpoint.h. */
1156 is_tracepoint (const struct breakpoint
*b
)
1158 return is_tracepoint_type (b
->type
);
1161 /* Factory function to create an appropriate instance of breakpoint given
1164 static std::unique_ptr
<breakpoint
>
1165 new_breakpoint_from_type (bptype type
)
1169 if (is_tracepoint_type (type
))
1170 b
= new tracepoint ();
1171 else if (is_longjmp_type (type
))
1172 b
= new longjmp_breakpoint ();
1174 b
= new breakpoint ();
1176 return std::unique_ptr
<breakpoint
> (b
);
1179 /* A helper function that validates that COMMANDS are valid for a
1180 breakpoint. This function will throw an exception if a problem is
1184 validate_commands_for_breakpoint (struct breakpoint
*b
,
1185 struct command_line
*commands
)
1187 if (is_tracepoint (b
))
1189 struct tracepoint
*t
= (struct tracepoint
*) b
;
1190 struct command_line
*c
;
1191 struct command_line
*while_stepping
= 0;
1193 /* Reset the while-stepping step count. The previous commands
1194 might have included a while-stepping action, while the new
1198 /* We need to verify that each top-level element of commands is
1199 valid for tracepoints, that there's at most one
1200 while-stepping element, and that the while-stepping's body
1201 has valid tracing commands excluding nested while-stepping.
1202 We also need to validate the tracepoint action line in the
1203 context of the tracepoint --- validate_actionline actually
1204 has side effects, like setting the tracepoint's
1205 while-stepping STEP_COUNT, in addition to checking if the
1206 collect/teval actions parse and make sense in the
1207 tracepoint's context. */
1208 for (c
= commands
; c
; c
= c
->next
)
1210 if (c
->control_type
== while_stepping_control
)
1212 if (b
->type
== bp_fast_tracepoint
)
1213 error (_("The 'while-stepping' command "
1214 "cannot be used for fast tracepoint"));
1215 else if (b
->type
== bp_static_tracepoint
)
1216 error (_("The 'while-stepping' command "
1217 "cannot be used for static tracepoint"));
1220 error (_("The 'while-stepping' command "
1221 "can be used only once"));
1226 validate_actionline (c
->line
, b
);
1230 struct command_line
*c2
;
1232 gdb_assert (while_stepping
->body_list_1
== nullptr);
1233 c2
= while_stepping
->body_list_0
.get ();
1234 for (; c2
; c2
= c2
->next
)
1236 if (c2
->control_type
== while_stepping_control
)
1237 error (_("The 'while-stepping' command cannot be nested"));
1243 check_no_tracepoint_commands (commands
);
1247 /* Return a vector of all the static tracepoints set at ADDR. The
1248 caller is responsible for releasing the vector. */
1250 std::vector
<breakpoint
*>
1251 static_tracepoints_here (CORE_ADDR addr
)
1253 std::vector
<breakpoint
*> found
;
1255 for (breakpoint
*b
: all_breakpoints ())
1256 if (b
->type
== bp_static_tracepoint
)
1258 for (bp_location
*loc
: b
->locations ())
1259 if (loc
->address
== addr
)
1260 found
.push_back (b
);
1266 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1267 validate that only allowed commands are included. */
1270 breakpoint_set_commands (struct breakpoint
*b
,
1271 counted_command_line
&&commands
)
1273 validate_commands_for_breakpoint (b
, commands
.get ());
1275 b
->commands
= std::move (commands
);
1276 gdb::observers::breakpoint_modified
.notify (b
);
1279 /* Set the internal `silent' flag on the breakpoint. Note that this
1280 is not the same as the "silent" that may appear in the breakpoint's
1284 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1286 int old_silent
= b
->silent
;
1289 if (old_silent
!= silent
)
1290 gdb::observers::breakpoint_modified
.notify (b
);
1293 /* Set the thread for this breakpoint. If THREAD is -1, make the
1294 breakpoint work for any thread. */
1297 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1299 int old_thread
= b
->thread
;
1302 if (old_thread
!= thread
)
1303 gdb::observers::breakpoint_modified
.notify (b
);
1306 /* Set the task for this breakpoint. If TASK is 0, make the
1307 breakpoint work for any task. */
1310 breakpoint_set_task (struct breakpoint
*b
, int task
)
1312 int old_task
= b
->task
;
1315 if (old_task
!= task
)
1316 gdb::observers::breakpoint_modified
.notify (b
);
1320 commands_command_1 (const char *arg
, int from_tty
,
1321 struct command_line
*control
)
1323 counted_command_line cmd
;
1324 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1325 NULL after the call to read_command_lines if the user provides an empty
1326 list of command by just typing "end". */
1327 bool cmd_read
= false;
1329 std::string new_arg
;
1331 if (arg
== NULL
|| !*arg
)
1333 /* Argument not explicitly given. Synthesize it. */
1334 if (breakpoint_count
- prev_breakpoint_count
> 1)
1335 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1337 else if (breakpoint_count
> 0)
1338 new_arg
= string_printf ("%d", breakpoint_count
);
1342 /* Create a copy of ARG. This is needed because the "commands"
1343 command may be coming from a script. In that case, the read
1344 line buffer is going to be overwritten in the lambda of
1345 'map_breakpoint_numbers' below when reading the next line
1346 before we are are done parsing the breakpoint numbers. */
1349 arg
= new_arg
.c_str ();
1351 map_breakpoint_numbers
1352 (arg
, [&] (breakpoint
*b
)
1356 gdb_assert (cmd
== NULL
);
1357 if (control
!= NULL
)
1358 cmd
= control
->body_list_0
;
1362 = string_printf (_("Type commands for breakpoint(s) "
1363 "%s, one per line."),
1366 auto do_validate
= [=] (const char *line
)
1368 validate_actionline (line
, b
);
1370 gdb::function_view
<void (const char *)> validator
;
1371 if (is_tracepoint (b
))
1372 validator
= do_validate
;
1374 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1379 /* If a breakpoint was on the list more than once, we don't need to
1381 if (b
->commands
!= cmd
)
1383 validate_commands_for_breakpoint (b
, cmd
.get ());
1385 gdb::observers::breakpoint_modified
.notify (b
);
1391 commands_command (const char *arg
, int from_tty
)
1393 commands_command_1 (arg
, from_tty
, NULL
);
1396 /* Like commands_command, but instead of reading the commands from
1397 input stream, takes them from an already parsed command structure.
1399 This is used by cli-script.c to DTRT with breakpoint commands
1400 that are part of if and while bodies. */
1401 enum command_control_type
1402 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1404 commands_command_1 (arg
, 0, cmd
);
1405 return simple_control
;
1408 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1411 bp_location_has_shadow (struct bp_location
*bl
)
1413 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1417 if (bl
->target_info
.shadow_len
== 0)
1418 /* BL isn't valid, or doesn't shadow memory. */
1423 /* Update BUF, which is LEN bytes read from the target address
1424 MEMADDR, by replacing a memory breakpoint with its shadowed
1427 If READBUF is not NULL, this buffer must not overlap with the of
1428 the breakpoint location's shadow_contents buffer. Otherwise, a
1429 failed assertion internal error will be raised. */
1432 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1433 const gdb_byte
*writebuf_org
,
1434 ULONGEST memaddr
, LONGEST len
,
1435 struct bp_target_info
*target_info
,
1436 struct gdbarch
*gdbarch
)
1438 /* Now do full processing of the found relevant range of elements. */
1439 CORE_ADDR bp_addr
= 0;
1443 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1444 current_program_space
->aspace
, 0))
1446 /* The breakpoint is inserted in a different address space. */
1450 /* Addresses and length of the part of the breakpoint that
1452 bp_addr
= target_info
->placed_address
;
1453 bp_size
= target_info
->shadow_len
;
1455 if (bp_addr
+ bp_size
<= memaddr
)
1457 /* The breakpoint is entirely before the chunk of memory we are
1462 if (bp_addr
>= memaddr
+ len
)
1464 /* The breakpoint is entirely after the chunk of memory we are
1469 /* Offset within shadow_contents. */
1470 if (bp_addr
< memaddr
)
1472 /* Only copy the second part of the breakpoint. */
1473 bp_size
-= memaddr
- bp_addr
;
1474 bptoffset
= memaddr
- bp_addr
;
1478 if (bp_addr
+ bp_size
> memaddr
+ len
)
1480 /* Only copy the first part of the breakpoint. */
1481 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1484 if (readbuf
!= NULL
)
1486 /* Verify that the readbuf buffer does not overlap with the
1487 shadow_contents buffer. */
1488 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1489 || readbuf
>= (target_info
->shadow_contents
1490 + target_info
->shadow_len
));
1492 /* Update the read buffer with this inserted breakpoint's
1494 memcpy (readbuf
+ bp_addr
- memaddr
,
1495 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1499 const unsigned char *bp
;
1500 CORE_ADDR addr
= target_info
->reqstd_address
;
1503 /* Update the shadow with what we want to write to memory. */
1504 memcpy (target_info
->shadow_contents
+ bptoffset
,
1505 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1507 /* Determine appropriate breakpoint contents and size for this
1509 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1511 /* Update the final write buffer with this inserted
1512 breakpoint's INSN. */
1513 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1517 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1518 by replacing any memory breakpoints with their shadowed contents.
1520 If READBUF is not NULL, this buffer must not overlap with any of
1521 the breakpoint location's shadow_contents buffers. Otherwise,
1522 a failed assertion internal error will be raised.
1524 The range of shadowed area by each bp_location is:
1525 bl->address - bp_locations_placed_address_before_address_max
1526 up to bl->address + bp_locations_shadow_len_after_address_max
1527 The range we were requested to resolve shadows for is:
1528 memaddr ... memaddr + len
1529 Thus the safe cutoff boundaries for performance optimization are
1530 memaddr + len <= (bl->address
1531 - bp_locations_placed_address_before_address_max)
1533 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1536 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1537 const gdb_byte
*writebuf_org
,
1538 ULONGEST memaddr
, LONGEST len
)
1540 /* Left boundary, right boundary and median element of our binary
1542 unsigned bc_l
, bc_r
, bc
;
1544 /* Find BC_L which is a leftmost element which may affect BUF
1545 content. It is safe to report lower value but a failure to
1546 report higher one. */
1549 bc_r
= bp_locations
.size ();
1550 while (bc_l
+ 1 < bc_r
)
1552 struct bp_location
*bl
;
1554 bc
= (bc_l
+ bc_r
) / 2;
1555 bl
= bp_locations
[bc
];
1557 /* Check first BL->ADDRESS will not overflow due to the added
1558 constant. Then advance the left boundary only if we are sure
1559 the BC element can in no way affect the BUF content (MEMADDR
1560 to MEMADDR + LEN range).
1562 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1563 offset so that we cannot miss a breakpoint with its shadow
1564 range tail still reaching MEMADDR. */
1566 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1568 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1575 /* Due to the binary search above, we need to make sure we pick the
1576 first location that's at BC_L's address. E.g., if there are
1577 multiple locations at the same address, BC_L may end up pointing
1578 at a duplicate location, and miss the "master"/"inserted"
1579 location. Say, given locations L1, L2 and L3 at addresses A and
1582 L1@A, L2@A, L3@B, ...
1584 BC_L could end up pointing at location L2, while the "master"
1585 location could be L1. Since the `loc->inserted' flag is only set
1586 on "master" locations, we'd forget to restore the shadow of L1
1589 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1592 /* Now do full processing of the found relevant range of elements. */
1594 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1596 struct bp_location
*bl
= bp_locations
[bc
];
1598 /* bp_location array has BL->OWNER always non-NULL. */
1599 if (bl
->owner
->type
== bp_none
)
1600 warning (_("reading through apparently deleted breakpoint #%d?"),
1603 /* Performance optimization: any further element can no longer affect BUF
1606 if (bl
->address
>= bp_locations_placed_address_before_address_max
1609 - bp_locations_placed_address_before_address_max
)))
1612 if (!bp_location_has_shadow (bl
))
1615 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1616 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1620 /* See breakpoint.h. */
1623 is_breakpoint (const struct breakpoint
*bpt
)
1625 return (bpt
->type
== bp_breakpoint
1626 || bpt
->type
== bp_hardware_breakpoint
1627 || bpt
->type
== bp_dprintf
);
1630 /* Return true if BPT is of any hardware watchpoint kind. */
1633 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1635 return (bpt
->type
== bp_hardware_watchpoint
1636 || bpt
->type
== bp_read_watchpoint
1637 || bpt
->type
== bp_access_watchpoint
);
1640 /* See breakpoint.h. */
1643 is_watchpoint (const struct breakpoint
*bpt
)
1645 return (is_hardware_watchpoint (bpt
)
1646 || bpt
->type
== bp_watchpoint
);
1649 /* Returns true if the current thread and its running state are safe
1650 to evaluate or update watchpoint B. Watchpoints on local
1651 expressions need to be evaluated in the context of the thread that
1652 was current when the watchpoint was created, and, that thread needs
1653 to be stopped to be able to select the correct frame context.
1654 Watchpoints on global expressions can be evaluated on any thread,
1655 and in any state. It is presently left to the target allowing
1656 memory accesses when threads are running. */
1659 watchpoint_in_thread_scope (struct watchpoint
*b
)
1661 return (b
->pspace
== current_program_space
1662 && (b
->watchpoint_thread
== null_ptid
1663 || (inferior_ptid
== b
->watchpoint_thread
1664 && !inferior_thread ()->executing ())));
1667 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1668 associated bp_watchpoint_scope breakpoint. */
1671 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1673 if (w
->related_breakpoint
!= w
)
1675 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1676 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1677 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1678 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1679 w
->related_breakpoint
= w
;
1681 w
->disposition
= disp_del_at_next_stop
;
1684 /* Extract a bitfield value from value VAL using the bit parameters contained in
1687 static struct value
*
1688 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1690 struct value
*bit_val
;
1695 bit_val
= allocate_value (value_type (val
));
1697 unpack_value_bitfield (bit_val
,
1700 value_contents_for_printing (val
),
1707 /* Allocate a dummy location and add it to B, which must be a software
1708 watchpoint. This is required because even if a software watchpoint
1709 is not watching any memory, bpstat_stop_status requires a location
1710 to be able to report stops. */
1713 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1714 struct program_space
*pspace
)
1716 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1718 b
->loc
= allocate_bp_location (b
);
1719 b
->loc
->pspace
= pspace
;
1720 b
->loc
->address
= -1;
1721 b
->loc
->length
= -1;
1724 /* Returns true if B is a software watchpoint that is not watching any
1725 memory (e.g., "watch $pc"). */
1728 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1730 return (b
->type
== bp_watchpoint
1732 && b
->loc
->next
== NULL
1733 && b
->loc
->address
== -1
1734 && b
->loc
->length
== -1);
1737 /* Assuming that B is a watchpoint:
1738 - Reparse watchpoint expression, if REPARSE is non-zero
1739 - Evaluate expression and store the result in B->val
1740 - Evaluate the condition if there is one, and store the result
1742 - Update the list of values that must be watched in B->loc.
1744 If the watchpoint disposition is disp_del_at_next_stop, then do
1745 nothing. If this is local watchpoint that is out of scope, delete
1748 Even with `set breakpoint always-inserted on' the watchpoints are
1749 removed + inserted on each stop here. Normal breakpoints must
1750 never be removed because they might be missed by a running thread
1751 when debugging in non-stop mode. On the other hand, hardware
1752 watchpoints (is_hardware_watchpoint; processed here) are specific
1753 to each LWP since they are stored in each LWP's hardware debug
1754 registers. Therefore, such LWP must be stopped first in order to
1755 be able to modify its hardware watchpoints.
1757 Hardware watchpoints must be reset exactly once after being
1758 presented to the user. It cannot be done sooner, because it would
1759 reset the data used to present the watchpoint hit to the user. And
1760 it must not be done later because it could display the same single
1761 watchpoint hit during multiple GDB stops. Note that the latter is
1762 relevant only to the hardware watchpoint types bp_read_watchpoint
1763 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1764 not user-visible - its hit is suppressed if the memory content has
1767 The following constraints influence the location where we can reset
1768 hardware watchpoints:
1770 * target_stopped_by_watchpoint and target_stopped_data_address are
1771 called several times when GDB stops.
1774 * Multiple hardware watchpoints can be hit at the same time,
1775 causing GDB to stop. GDB only presents one hardware watchpoint
1776 hit at a time as the reason for stopping, and all the other hits
1777 are presented later, one after the other, each time the user
1778 requests the execution to be resumed. Execution is not resumed
1779 for the threads still having pending hit event stored in
1780 LWP_INFO->STATUS. While the watchpoint is already removed from
1781 the inferior on the first stop the thread hit event is kept being
1782 reported from its cached value by linux_nat_stopped_data_address
1783 until the real thread resume happens after the watchpoint gets
1784 presented and thus its LWP_INFO->STATUS gets reset.
1786 Therefore the hardware watchpoint hit can get safely reset on the
1787 watchpoint removal from inferior. */
1790 update_watchpoint (struct watchpoint
*b
, int reparse
)
1792 int within_current_scope
;
1793 struct frame_id saved_frame_id
;
1796 /* If this is a local watchpoint, we only want to check if the
1797 watchpoint frame is in scope if the current thread is the thread
1798 that was used to create the watchpoint. */
1799 if (!watchpoint_in_thread_scope (b
))
1802 if (b
->disposition
== disp_del_at_next_stop
)
1807 /* Determine if the watchpoint is within scope. */
1808 if (b
->exp_valid_block
== NULL
)
1809 within_current_scope
= 1;
1812 struct frame_info
*fi
= get_current_frame ();
1813 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1814 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1816 /* If we're at a point where the stack has been destroyed
1817 (e.g. in a function epilogue), unwinding may not work
1818 properly. Do not attempt to recreate locations at this
1819 point. See similar comments in watchpoint_check. */
1820 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1823 /* Save the current frame's ID so we can restore it after
1824 evaluating the watchpoint expression on its own frame. */
1825 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1826 took a frame parameter, so that we didn't have to change the
1829 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1831 fi
= frame_find_by_id (b
->watchpoint_frame
);
1832 within_current_scope
= (fi
!= NULL
);
1833 if (within_current_scope
)
1837 /* We don't free locations. They are stored in the bp_location array
1838 and update_global_location_list will eventually delete them and
1839 remove breakpoints if needed. */
1842 if (within_current_scope
&& reparse
)
1847 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1848 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1849 /* If the meaning of expression itself changed, the old value is
1850 no longer relevant. We don't want to report a watchpoint hit
1851 to the user when the old value and the new value may actually
1852 be completely different objects. */
1854 b
->val_valid
= false;
1856 /* Note that unlike with breakpoints, the watchpoint's condition
1857 expression is stored in the breakpoint object, not in the
1858 locations (re)created below. */
1859 if (b
->cond_string
!= NULL
)
1861 b
->cond_exp
.reset ();
1864 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1868 /* If we failed to parse the expression, for example because
1869 it refers to a global variable in a not-yet-loaded shared library,
1870 don't try to insert watchpoint. We don't automatically delete
1871 such watchpoint, though, since failure to parse expression
1872 is different from out-of-scope watchpoint. */
1873 if (!target_has_execution ())
1875 /* Without execution, memory can't change. No use to try and
1876 set watchpoint locations. The watchpoint will be reset when
1877 the target gains execution, through breakpoint_re_set. */
1878 if (!can_use_hw_watchpoints
)
1880 if (b
->ops
->works_in_software_mode (b
))
1881 b
->type
= bp_watchpoint
;
1883 error (_("Can't set read/access watchpoint when "
1884 "hardware watchpoints are disabled."));
1887 else if (within_current_scope
&& b
->exp
)
1889 std::vector
<value_ref_ptr
> val_chain
;
1890 struct value
*v
, *result
;
1891 struct program_space
*frame_pspace
;
1893 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
1896 /* Avoid setting b->val if it's already set. The meaning of
1897 b->val is 'the last value' user saw, and we should update
1898 it only if we reported that last value to user. As it
1899 happens, the code that reports it updates b->val directly.
1900 We don't keep track of the memory value for masked
1902 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1904 if (b
->val_bitsize
!= 0)
1905 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1906 b
->val
= release_value (v
);
1907 b
->val_valid
= true;
1910 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1912 /* Look at each value on the value chain. */
1913 gdb_assert (!val_chain
.empty ());
1914 for (const value_ref_ptr
&iter
: val_chain
)
1918 /* If it's a memory location, and GDB actually needed
1919 its contents to evaluate the expression, then we
1920 must watch it. If the first value returned is
1921 still lazy, that means an error occurred reading it;
1922 watch it anyway in case it becomes readable. */
1923 if (VALUE_LVAL (v
) == lval_memory
1924 && (v
== val_chain
[0] || ! value_lazy (v
)))
1926 struct type
*vtype
= check_typedef (value_type (v
));
1928 /* We only watch structs and arrays if user asked
1929 for it explicitly, never if they just happen to
1930 appear in the middle of some value chain. */
1932 || (vtype
->code () != TYPE_CODE_STRUCT
1933 && vtype
->code () != TYPE_CODE_ARRAY
))
1936 enum target_hw_bp_type type
;
1937 struct bp_location
*loc
, **tmp
;
1938 int bitpos
= 0, bitsize
= 0;
1940 if (value_bitsize (v
) != 0)
1942 /* Extract the bit parameters out from the bitfield
1944 bitpos
= value_bitpos (v
);
1945 bitsize
= value_bitsize (v
);
1947 else if (v
== result
&& b
->val_bitsize
!= 0)
1949 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1950 lvalue whose bit parameters are saved in the fields
1951 VAL_BITPOS and VAL_BITSIZE. */
1952 bitpos
= b
->val_bitpos
;
1953 bitsize
= b
->val_bitsize
;
1956 addr
= value_address (v
);
1959 /* Skip the bytes that don't contain the bitfield. */
1964 if (b
->type
== bp_read_watchpoint
)
1966 else if (b
->type
== bp_access_watchpoint
)
1969 loc
= allocate_bp_location (b
);
1970 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1973 loc
->gdbarch
= value_type (v
)->arch ();
1975 loc
->pspace
= frame_pspace
;
1976 loc
->address
= address_significant (loc
->gdbarch
, addr
);
1980 /* Just cover the bytes that make up the bitfield. */
1981 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1984 loc
->length
= TYPE_LENGTH (value_type (v
));
1986 loc
->watchpoint_type
= type
;
1991 /* Change the type of breakpoint between hardware assisted or
1992 an ordinary watchpoint depending on the hardware support
1993 and free hardware slots. REPARSE is set when the inferior
1998 enum bp_loc_type loc_type
;
2000 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2004 int i
, target_resources_ok
, other_type_used
;
2007 /* Use an exact watchpoint when there's only one memory region to be
2008 watched, and only one debug register is needed to watch it. */
2009 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2011 /* We need to determine how many resources are already
2012 used for all other hardware watchpoints plus this one
2013 to see if we still have enough resources to also fit
2014 this watchpoint in as well. */
2016 /* If this is a software watchpoint, we try to turn it
2017 to a hardware one -- count resources as if B was of
2018 hardware watchpoint type. */
2020 if (type
== bp_watchpoint
)
2021 type
= bp_hardware_watchpoint
;
2023 /* This watchpoint may or may not have been placed on
2024 the list yet at this point (it won't be in the list
2025 if we're trying to create it for the first time,
2026 through watch_command), so always account for it
2029 /* Count resources used by all watchpoints except B. */
2030 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2032 /* Add in the resources needed for B. */
2033 i
+= hw_watchpoint_use_count (b
);
2036 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2037 if (target_resources_ok
<= 0)
2039 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2041 if (target_resources_ok
== 0 && !sw_mode
)
2042 error (_("Target does not support this type of "
2043 "hardware watchpoint."));
2044 else if (target_resources_ok
< 0 && !sw_mode
)
2045 error (_("There are not enough available hardware "
2046 "resources for this watchpoint."));
2048 /* Downgrade to software watchpoint. */
2049 b
->type
= bp_watchpoint
;
2053 /* If this was a software watchpoint, we've just
2054 found we have enough resources to turn it to a
2055 hardware watchpoint. Otherwise, this is a
2060 else if (!b
->ops
->works_in_software_mode (b
))
2062 if (!can_use_hw_watchpoints
)
2063 error (_("Can't set read/access watchpoint when "
2064 "hardware watchpoints are disabled."));
2066 error (_("Expression cannot be implemented with "
2067 "read/access watchpoint."));
2070 b
->type
= bp_watchpoint
;
2072 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2073 : bp_loc_hardware_watchpoint
);
2074 for (bp_location
*bl
: b
->locations ())
2075 bl
->loc_type
= loc_type
;
2078 /* If a software watchpoint is not watching any memory, then the
2079 above left it without any location set up. But,
2080 bpstat_stop_status requires a location to be able to report
2081 stops, so make sure there's at least a dummy one. */
2082 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2083 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2085 else if (!within_current_scope
)
2087 printf_filtered (_("\
2088 Watchpoint %d deleted because the program has left the block\n\
2089 in which its expression is valid.\n"),
2091 watchpoint_del_at_next_stop (b
);
2094 /* Restore the selected frame. */
2096 select_frame (frame_find_by_id (saved_frame_id
));
2100 /* Returns 1 iff breakpoint location should be
2101 inserted in the inferior. We don't differentiate the type of BL's owner
2102 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2103 breakpoint_ops is not defined, because in insert_bp_location,
2104 tracepoint's insert_location will not be called. */
2106 should_be_inserted (struct bp_location
*bl
)
2108 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2111 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2114 if (!bl
->enabled
|| bl
->disabled_by_cond
2115 || bl
->shlib_disabled
|| bl
->duplicate
)
2118 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2121 /* This is set for example, when we're attached to the parent of a
2122 vfork, and have detached from the child. The child is running
2123 free, and we expect it to do an exec or exit, at which point the
2124 OS makes the parent schedulable again (and the target reports
2125 that the vfork is done). Until the child is done with the shared
2126 memory region, do not insert breakpoints in the parent, otherwise
2127 the child could still trip on the parent's breakpoints. Since
2128 the parent is blocked anyway, it won't miss any breakpoint. */
2129 if (bl
->pspace
->breakpoints_not_allowed
)
2132 /* Don't insert a breakpoint if we're trying to step past its
2133 location, except if the breakpoint is a single-step breakpoint,
2134 and the breakpoint's thread is the thread which is stepping past
2136 if ((bl
->loc_type
== bp_loc_software_breakpoint
2137 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2138 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2140 /* The single-step breakpoint may be inserted at the location
2141 we're trying to step if the instruction branches to itself.
2142 However, the instruction won't be executed at all and it may
2143 break the semantics of the instruction, for example, the
2144 instruction is a conditional branch or updates some flags.
2145 We can't fix it unless GDB is able to emulate the instruction
2146 or switch to displaced stepping. */
2147 && !(bl
->owner
->type
== bp_single_step
2148 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2150 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2151 paddress (bl
->gdbarch
, bl
->address
));
2155 /* Don't insert watchpoints if we're trying to step past the
2156 instruction that triggered one. */
2157 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2158 && stepping_past_nonsteppable_watchpoint ())
2160 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2161 "skipping watchpoint at %s:%d",
2162 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2169 /* Same as should_be_inserted but does the check assuming
2170 that the location is not duplicated. */
2173 unduplicated_should_be_inserted (struct bp_location
*bl
)
2176 const int save_duplicate
= bl
->duplicate
;
2179 result
= should_be_inserted (bl
);
2180 bl
->duplicate
= save_duplicate
;
2184 /* Parses a conditional described by an expression COND into an
2185 agent expression bytecode suitable for evaluation
2186 by the bytecode interpreter. Return NULL if there was
2187 any error during parsing. */
2189 static agent_expr_up
2190 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2195 agent_expr_up aexpr
;
2197 /* We don't want to stop processing, so catch any errors
2198 that may show up. */
2201 aexpr
= gen_eval_for_expr (scope
, cond
);
2204 catch (const gdb_exception_error
&ex
)
2206 /* If we got here, it means the condition could not be parsed to a valid
2207 bytecode expression and thus can't be evaluated on the target's side.
2208 It's no use iterating through the conditions. */
2211 /* We have a valid agent expression. */
2215 /* Based on location BL, create a list of breakpoint conditions to be
2216 passed on to the target. If we have duplicated locations with different
2217 conditions, we will add such conditions to the list. The idea is that the
2218 target will evaluate the list of conditions and will only notify GDB when
2219 one of them is true. */
2222 build_target_condition_list (struct bp_location
*bl
)
2224 int null_condition_or_parse_error
= 0;
2225 int modified
= bl
->needs_update
;
2227 /* Release conditions left over from a previous insert. */
2228 bl
->target_info
.conditions
.clear ();
2230 /* This is only meaningful if the target is
2231 evaluating conditions and if the user has
2232 opted for condition evaluation on the target's
2234 if (gdb_evaluates_breakpoint_condition_p ()
2235 || !target_supports_evaluation_of_breakpoint_conditions ())
2238 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2240 /* Do a first pass to check for locations with no assigned
2241 conditions or conditions that fail to parse to a valid agent
2242 expression bytecode. If any of these happen, then it's no use to
2243 send conditions to the target since this location will always
2244 trigger and generate a response back to GDB. Note we consider
2245 all locations at the same address irrespective of type, i.e.,
2246 even if the locations aren't considered duplicates (e.g.,
2247 software breakpoint and hardware breakpoint at the same
2249 for (bp_location
*loc
: loc_range
)
2251 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2255 /* Re-parse the conditions since something changed. In that
2256 case we already freed the condition bytecodes (see
2257 force_breakpoint_reinsertion). We just
2258 need to parse the condition to bytecodes again. */
2259 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2263 /* If we have a NULL bytecode expression, it means something
2264 went wrong or we have a null condition expression. */
2265 if (!loc
->cond_bytecode
)
2267 null_condition_or_parse_error
= 1;
2273 /* If any of these happened, it means we will have to evaluate the conditions
2274 for the location's address on gdb's side. It is no use keeping bytecodes
2275 for all the other duplicate locations, thus we free all of them here.
2277 This is so we have a finer control over which locations' conditions are
2278 being evaluated by GDB or the remote stub. */
2279 if (null_condition_or_parse_error
)
2281 for (bp_location
*loc
: loc_range
)
2283 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2285 /* Only go as far as the first NULL bytecode is
2287 if (!loc
->cond_bytecode
)
2290 loc
->cond_bytecode
.reset ();
2295 /* No NULL conditions or failed bytecode generation. Build a
2296 condition list for this location's address. If we have software
2297 and hardware locations at the same address, they aren't
2298 considered duplicates, but we still marge all the conditions
2299 anyway, as it's simpler, and doesn't really make a practical
2301 for (bp_location
*loc
: loc_range
)
2303 && is_breakpoint (loc
->owner
)
2304 && loc
->pspace
->num
== bl
->pspace
->num
2305 && loc
->owner
->enable_state
== bp_enabled
2307 && !loc
->disabled_by_cond
)
2309 /* Add the condition to the vector. This will be used later
2310 to send the conditions to the target. */
2311 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2317 /* Parses a command described by string CMD into an agent expression
2318 bytecode suitable for evaluation by the bytecode interpreter.
2319 Return NULL if there was any error during parsing. */
2321 static agent_expr_up
2322 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2324 const char *cmdrest
;
2325 const char *format_start
, *format_end
;
2326 struct gdbarch
*gdbarch
= get_current_arch ();
2333 if (*cmdrest
== ',')
2335 cmdrest
= skip_spaces (cmdrest
);
2337 if (*cmdrest
++ != '"')
2338 error (_("No format string following the location"));
2340 format_start
= cmdrest
;
2342 format_pieces
fpieces (&cmdrest
);
2344 format_end
= cmdrest
;
2346 if (*cmdrest
++ != '"')
2347 error (_("Bad format string, non-terminated '\"'."));
2349 cmdrest
= skip_spaces (cmdrest
);
2351 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2352 error (_("Invalid argument syntax"));
2354 if (*cmdrest
== ',')
2356 cmdrest
= skip_spaces (cmdrest
);
2358 /* For each argument, make an expression. */
2360 std::vector
<struct expression
*> argvec
;
2361 while (*cmdrest
!= '\0')
2366 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2367 argvec
.push_back (expr
.release ());
2369 if (*cmdrest
== ',')
2373 agent_expr_up aexpr
;
2375 /* We don't want to stop processing, so catch any errors
2376 that may show up. */
2379 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2380 format_start
, format_end
- format_start
,
2381 argvec
.size (), argvec
.data ());
2383 catch (const gdb_exception_error
&ex
)
2385 /* If we got here, it means the command could not be parsed to a valid
2386 bytecode expression and thus can't be evaluated on the target's side.
2387 It's no use iterating through the other commands. */
2390 /* We have a valid agent expression, return it. */
2394 /* Based on location BL, create a list of breakpoint commands to be
2395 passed on to the target. If we have duplicated locations with
2396 different commands, we will add any such to the list. */
2399 build_target_command_list (struct bp_location
*bl
)
2401 int null_command_or_parse_error
= 0;
2402 int modified
= bl
->needs_update
;
2404 /* Clear commands left over from a previous insert. */
2405 bl
->target_info
.tcommands
.clear ();
2407 if (!target_can_run_breakpoint_commands ())
2410 /* For now, limit to agent-style dprintf breakpoints. */
2411 if (dprintf_style
!= dprintf_style_agent
)
2414 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2416 /* For now, if we have any location at the same address that isn't a
2417 dprintf, don't install the target-side commands, as that would
2418 make the breakpoint not be reported to the core, and we'd lose
2420 for (bp_location
*loc
: loc_range
)
2421 if (is_breakpoint (loc
->owner
)
2422 && loc
->pspace
->num
== bl
->pspace
->num
2423 && loc
->owner
->type
!= bp_dprintf
)
2426 /* Do a first pass to check for locations with no assigned
2427 conditions or conditions that fail to parse to a valid agent expression
2428 bytecode. If any of these happen, then it's no use to send conditions
2429 to the target since this location will always trigger and generate a
2430 response back to GDB. */
2431 for (bp_location
*loc
: loc_range
)
2433 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2437 /* Re-parse the commands since something changed. In that
2438 case we already freed the command bytecodes (see
2439 force_breakpoint_reinsertion). We just
2440 need to parse the command to bytecodes again. */
2442 = parse_cmd_to_aexpr (bl
->address
,
2443 loc
->owner
->extra_string
);
2446 /* If we have a NULL bytecode expression, it means something
2447 went wrong or we have a null command expression. */
2448 if (!loc
->cmd_bytecode
)
2450 null_command_or_parse_error
= 1;
2456 /* If anything failed, then we're not doing target-side commands,
2458 if (null_command_or_parse_error
)
2460 for (bp_location
*loc
: loc_range
)
2461 if (is_breakpoint (loc
->owner
)
2462 && loc
->pspace
->num
== bl
->pspace
->num
)
2464 /* Only go as far as the first NULL bytecode is
2466 if (loc
->cmd_bytecode
== NULL
)
2469 loc
->cmd_bytecode
.reset ();
2473 /* No NULL commands or failed bytecode generation. Build a command
2474 list for all duplicate locations at this location's address.
2475 Note that here we must care for whether the breakpoint location
2476 types are considered duplicates, otherwise, say, if we have a
2477 software and hardware location at the same address, the target
2478 could end up running the commands twice. For the moment, we only
2479 support targets-side commands with dprintf, but it doesn't hurt
2480 to be pedantically correct in case that changes. */
2481 for (bp_location
*loc
: loc_range
)
2482 if (breakpoint_locations_match (bl
, loc
)
2483 && loc
->owner
->extra_string
2484 && is_breakpoint (loc
->owner
)
2485 && loc
->pspace
->num
== bl
->pspace
->num
2486 && loc
->owner
->enable_state
== bp_enabled
2488 && !loc
->disabled_by_cond
)
2490 /* Add the command to the vector. This will be used later
2491 to send the commands to the target. */
2492 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2495 bl
->target_info
.persist
= 0;
2496 /* Maybe flag this location as persistent. */
2497 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2498 bl
->target_info
.persist
= 1;
2501 /* Return the kind of breakpoint on address *ADDR. Get the kind
2502 of breakpoint according to ADDR except single-step breakpoint.
2503 Get the kind of single-step breakpoint according to the current
2507 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2509 if (bl
->owner
->type
== bp_single_step
)
2511 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2512 struct regcache
*regcache
;
2514 regcache
= get_thread_regcache (thr
);
2516 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2520 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2523 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2524 location. Any error messages are printed to TMP_ERROR_STREAM; and
2525 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2526 Returns 0 for success, 1 if the bp_location type is not supported or
2529 NOTE drow/2003-09-09: This routine could be broken down to an
2530 object-style method for each breakpoint or catchpoint type. */
2532 insert_bp_location (struct bp_location
*bl
,
2533 struct ui_file
*tmp_error_stream
,
2534 int *disabled_breaks
,
2535 int *hw_breakpoint_error
,
2536 int *hw_bp_error_explained_already
)
2538 gdb_exception bp_excpt
;
2540 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2543 /* Note we don't initialize bl->target_info, as that wipes out
2544 the breakpoint location's shadow_contents if the breakpoint
2545 is still inserted at that location. This in turn breaks
2546 target_read_memory which depends on these buffers when
2547 a memory read is requested at the breakpoint location:
2548 Once the target_info has been wiped, we fail to see that
2549 we have a breakpoint inserted at that address and thus
2550 read the breakpoint instead of returning the data saved in
2551 the breakpoint location's shadow contents. */
2552 bl
->target_info
.reqstd_address
= bl
->address
;
2553 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2554 bl
->target_info
.length
= bl
->length
;
2556 /* When working with target-side conditions, we must pass all the conditions
2557 for the same breakpoint address down to the target since GDB will not
2558 insert those locations. With a list of breakpoint conditions, the target
2559 can decide when to stop and notify GDB. */
2561 if (is_breakpoint (bl
->owner
))
2563 build_target_condition_list (bl
);
2564 build_target_command_list (bl
);
2565 /* Reset the modification marker. */
2566 bl
->needs_update
= 0;
2569 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2570 set at a read-only address, then a breakpoint location will have
2571 been changed to hardware breakpoint before we get here. If it is
2572 "off" however, error out before actually trying to insert the
2573 breakpoint, with a nicer error message. */
2574 if (bl
->loc_type
== bp_loc_software_breakpoint
2575 && !automatic_hardware_breakpoints
)
2577 mem_region
*mr
= lookup_mem_region (bl
->address
);
2579 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2581 fprintf_unfiltered (tmp_error_stream
,
2582 _("Cannot insert breakpoint %d.\n"
2583 "Cannot set software breakpoint "
2584 "at read-only address %s\n"),
2586 paddress (bl
->gdbarch
, bl
->address
));
2591 if (bl
->loc_type
== bp_loc_software_breakpoint
2592 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2594 /* First check to see if we have to handle an overlay. */
2595 if (overlay_debugging
== ovly_off
2596 || bl
->section
== NULL
2597 || !(section_is_overlay (bl
->section
)))
2599 /* No overlay handling: just set the breakpoint. */
2604 val
= bl
->owner
->ops
->insert_location (bl
);
2606 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2608 catch (gdb_exception
&e
)
2610 bp_excpt
= std::move (e
);
2615 /* This breakpoint is in an overlay section.
2616 Shall we set a breakpoint at the LMA? */
2617 if (!overlay_events_enabled
)
2619 /* Yes -- overlay event support is not active,
2620 so we must try to set a breakpoint at the LMA.
2621 This will not work for a hardware breakpoint. */
2622 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2623 warning (_("hardware breakpoint %d not supported in overlay!"),
2627 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2629 /* Set a software (trap) breakpoint at the LMA. */
2630 bl
->overlay_target_info
= bl
->target_info
;
2631 bl
->overlay_target_info
.reqstd_address
= addr
;
2633 /* No overlay handling: just set the breakpoint. */
2638 bl
->overlay_target_info
.kind
2639 = breakpoint_kind (bl
, &addr
);
2640 bl
->overlay_target_info
.placed_address
= addr
;
2641 val
= target_insert_breakpoint (bl
->gdbarch
,
2642 &bl
->overlay_target_info
);
2645 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2647 catch (gdb_exception
&e
)
2649 bp_excpt
= std::move (e
);
2652 if (bp_excpt
.reason
!= 0)
2653 fprintf_unfiltered (tmp_error_stream
,
2654 "Overlay breakpoint %d "
2655 "failed: in ROM?\n",
2659 /* Shall we set a breakpoint at the VMA? */
2660 if (section_is_mapped (bl
->section
))
2662 /* Yes. This overlay section is mapped into memory. */
2667 val
= bl
->owner
->ops
->insert_location (bl
);
2669 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2671 catch (gdb_exception
&e
)
2673 bp_excpt
= std::move (e
);
2678 /* No. This breakpoint will not be inserted.
2679 No error, but do not mark the bp as 'inserted'. */
2684 if (bp_excpt
.reason
!= 0)
2686 /* Can't set the breakpoint. */
2688 /* If the target has closed then it will have deleted any
2689 breakpoints inserted within the target inferior, as a result
2690 any further attempts to interact with the breakpoint objects
2691 is not possible. Just rethrow the error. */
2692 if (bp_excpt
.error
== TARGET_CLOSE_ERROR
)
2694 gdb_assert (bl
->owner
!= nullptr);
2696 /* In some cases, we might not be able to insert a
2697 breakpoint in a shared library that has already been
2698 removed, but we have not yet processed the shlib unload
2699 event. Unfortunately, some targets that implement
2700 breakpoint insertion themselves can't tell why the
2701 breakpoint insertion failed (e.g., the remote target
2702 doesn't define error codes), so we must treat generic
2703 errors as memory errors. */
2704 if (bp_excpt
.reason
== RETURN_ERROR
2705 && (bp_excpt
.error
== GENERIC_ERROR
2706 || bp_excpt
.error
== MEMORY_ERROR
)
2707 && bl
->loc_type
== bp_loc_software_breakpoint
2708 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2709 || shared_objfile_contains_address_p (bl
->pspace
,
2712 /* See also: disable_breakpoints_in_shlibs. */
2713 bl
->shlib_disabled
= 1;
2714 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2715 if (!*disabled_breaks
)
2717 fprintf_unfiltered (tmp_error_stream
,
2718 "Cannot insert breakpoint %d.\n",
2720 fprintf_unfiltered (tmp_error_stream
,
2721 "Temporarily disabling shared "
2722 "library breakpoints:\n");
2724 *disabled_breaks
= 1;
2725 fprintf_unfiltered (tmp_error_stream
,
2726 "breakpoint #%d\n", bl
->owner
->number
);
2731 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2733 *hw_breakpoint_error
= 1;
2734 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2735 fprintf_unfiltered (tmp_error_stream
,
2736 "Cannot insert hardware breakpoint %d%s",
2738 bp_excpt
.message
? ":" : ".\n");
2739 if (bp_excpt
.message
!= NULL
)
2740 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2745 if (bp_excpt
.message
== NULL
)
2748 = memory_error_message (TARGET_XFER_E_IO
,
2749 bl
->gdbarch
, bl
->address
);
2751 fprintf_unfiltered (tmp_error_stream
,
2752 "Cannot insert breakpoint %d.\n"
2754 bl
->owner
->number
, message
.c_str ());
2758 fprintf_unfiltered (tmp_error_stream
,
2759 "Cannot insert breakpoint %d: %s\n",
2774 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2775 /* NOTE drow/2003-09-08: This state only exists for removing
2776 watchpoints. It's not clear that it's necessary... */
2777 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2781 gdb_assert (bl
->owner
->ops
!= NULL
2782 && bl
->owner
->ops
->insert_location
!= NULL
);
2784 val
= bl
->owner
->ops
->insert_location (bl
);
2786 /* If trying to set a read-watchpoint, and it turns out it's not
2787 supported, try emulating one with an access watchpoint. */
2788 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2790 /* But don't try to insert it, if there's already another
2791 hw_access location that would be considered a duplicate
2793 for (bp_location
*loc
: all_bp_locations ())
2795 && loc
->watchpoint_type
== hw_access
2796 && watchpoint_locations_match (bl
, loc
))
2800 bl
->target_info
= loc
->target_info
;
2801 bl
->watchpoint_type
= hw_access
;
2808 bl
->watchpoint_type
= hw_access
;
2809 val
= bl
->owner
->ops
->insert_location (bl
);
2812 /* Back to the original value. */
2813 bl
->watchpoint_type
= hw_read
;
2817 bl
->inserted
= (val
== 0);
2820 else if (bl
->owner
->type
== bp_catchpoint
)
2824 gdb_assert (bl
->owner
->ops
!= NULL
2825 && bl
->owner
->ops
->insert_location
!= NULL
);
2827 val
= bl
->owner
->ops
->insert_location (bl
);
2830 bl
->owner
->enable_state
= bp_disabled
;
2834 Error inserting catchpoint %d: Your system does not support this type\n\
2835 of catchpoint."), bl
->owner
->number
);
2837 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2840 bl
->inserted
= (val
== 0);
2842 /* We've already printed an error message if there was a problem
2843 inserting this catchpoint, and we've disabled the catchpoint,
2844 so just return success. */
2851 /* This function is called when program space PSPACE is about to be
2852 deleted. It takes care of updating breakpoints to not reference
2856 breakpoint_program_space_exit (struct program_space
*pspace
)
2858 /* Remove any breakpoint that was set through this program space. */
2859 for (breakpoint
*b
: all_breakpoints_safe ())
2860 if (b
->pspace
== pspace
)
2861 delete_breakpoint (b
);
2863 /* Breakpoints set through other program spaces could have locations
2864 bound to PSPACE as well. Remove those. */
2865 for (bp_location
*loc
: all_bp_locations ())
2867 struct bp_location
*tmp
;
2869 if (loc
->pspace
== pspace
)
2871 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2872 if (loc
->owner
->loc
== loc
)
2873 loc
->owner
->loc
= loc
->next
;
2875 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2876 if (tmp
->next
== loc
)
2878 tmp
->next
= loc
->next
;
2884 /* Now update the global location list to permanently delete the
2885 removed locations above. */
2886 update_global_location_list (UGLL_DONT_INSERT
);
2889 /* Make sure all breakpoints are inserted in inferior.
2890 Throws exception on any error.
2891 A breakpoint that is already inserted won't be inserted
2892 again, so calling this function twice is safe. */
2894 insert_breakpoints (void)
2896 for (breakpoint
*bpt
: all_breakpoints ())
2897 if (is_hardware_watchpoint (bpt
))
2899 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2901 update_watchpoint (w
, 0 /* don't reparse. */);
2904 /* Updating watchpoints creates new locations, so update the global
2905 location list. Explicitly tell ugll to insert locations and
2906 ignore breakpoints_always_inserted_mode. Also,
2907 update_global_location_list tries to "upgrade" software
2908 breakpoints to hardware breakpoints to handle "set breakpoint
2909 auto-hw", so we need to call it even if we don't have new
2911 update_global_location_list (UGLL_INSERT
);
2914 /* This is used when we need to synch breakpoint conditions between GDB and the
2915 target. It is the case with deleting and disabling of breakpoints when using
2916 always-inserted mode. */
2919 update_inserted_breakpoint_locations (void)
2923 int disabled_breaks
= 0;
2924 int hw_breakpoint_error
= 0;
2925 int hw_bp_details_reported
= 0;
2927 string_file tmp_error_stream
;
2929 /* Explicitly mark the warning -- this will only be printed if
2930 there was an error. */
2931 tmp_error_stream
.puts ("Warning:\n");
2933 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2935 for (bp_location
*bl
: all_bp_locations ())
2937 /* We only want to update software breakpoints and hardware
2939 if (!is_breakpoint (bl
->owner
))
2942 /* We only want to update locations that are already inserted
2943 and need updating. This is to avoid unwanted insertion during
2944 deletion of breakpoints. */
2945 if (!bl
->inserted
|| !bl
->needs_update
)
2948 switch_to_program_space_and_thread (bl
->pspace
);
2950 /* For targets that support global breakpoints, there's no need
2951 to select an inferior to insert breakpoint to. In fact, even
2952 if we aren't attached to any process yet, we should still
2953 insert breakpoints. */
2954 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2955 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
2958 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2959 &hw_breakpoint_error
, &hw_bp_details_reported
);
2966 target_terminal::ours_for_output ();
2967 error_stream (tmp_error_stream
);
2971 /* Used when starting or continuing the program. */
2974 insert_breakpoint_locations (void)
2978 int disabled_breaks
= 0;
2979 int hw_breakpoint_error
= 0;
2980 int hw_bp_error_explained_already
= 0;
2982 string_file tmp_error_stream
;
2984 /* Explicitly mark the warning -- this will only be printed if
2985 there was an error. */
2986 tmp_error_stream
.puts ("Warning:\n");
2988 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2990 for (bp_location
*bl
: all_bp_locations ())
2992 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2995 /* There is no point inserting thread-specific breakpoints if
2996 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2997 has BL->OWNER always non-NULL. */
2998 if (bl
->owner
->thread
!= -1
2999 && !valid_global_thread_id (bl
->owner
->thread
))
3002 switch_to_program_space_and_thread (bl
->pspace
);
3004 /* For targets that support global breakpoints, there's no need
3005 to select an inferior to insert breakpoint to. In fact, even
3006 if we aren't attached to any process yet, we should still
3007 insert breakpoints. */
3008 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3009 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3012 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3013 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3018 /* If we failed to insert all locations of a watchpoint, remove
3019 them, as half-inserted watchpoint is of limited use. */
3020 for (breakpoint
*bpt
: all_breakpoints ())
3022 int some_failed
= 0;
3024 if (!is_hardware_watchpoint (bpt
))
3027 if (!breakpoint_enabled (bpt
))
3030 if (bpt
->disposition
== disp_del_at_next_stop
)
3033 for (bp_location
*loc
: bpt
->locations ())
3034 if (!loc
->inserted
&& should_be_inserted (loc
))
3042 for (bp_location
*loc
: bpt
->locations ())
3044 remove_breakpoint (loc
);
3046 hw_breakpoint_error
= 1;
3047 tmp_error_stream
.printf ("Could not insert "
3048 "hardware watchpoint %d.\n",
3056 /* If a hardware breakpoint or watchpoint was inserted, add a
3057 message about possibly exhausted resources. */
3058 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3060 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3061 You may have requested too many hardware breakpoints/watchpoints.\n");
3063 target_terminal::ours_for_output ();
3064 error_stream (tmp_error_stream
);
3068 /* Used when the program stops.
3069 Returns zero if successful, or non-zero if there was a problem
3070 removing a breakpoint location. */
3073 remove_breakpoints (void)
3077 for (bp_location
*bl
: all_bp_locations ())
3078 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3079 val
|= remove_breakpoint (bl
);
3084 /* When a thread exits, remove breakpoints that are related to
3088 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3090 for (breakpoint
*b
: all_breakpoints_safe ())
3092 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3094 b
->disposition
= disp_del_at_next_stop
;
3096 printf_filtered (_("\
3097 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3098 b
->number
, print_thread_id (tp
));
3100 /* Hide it from the user. */
3106 /* See breakpoint.h. */
3109 remove_breakpoints_inf (inferior
*inf
)
3113 for (bp_location
*bl
: all_bp_locations ())
3115 if (bl
->pspace
!= inf
->pspace
)
3118 if (bl
->inserted
&& !bl
->target_info
.persist
)
3120 val
= remove_breakpoint (bl
);
3127 static int internal_breakpoint_number
= -1;
3129 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3130 If INTERNAL is non-zero, the breakpoint number will be populated
3131 from internal_breakpoint_number and that variable decremented.
3132 Otherwise the breakpoint number will be populated from
3133 breakpoint_count and that value incremented. Internal breakpoints
3134 do not set the internal var bpnum. */
3136 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3139 b
->number
= internal_breakpoint_number
--;
3142 set_breakpoint_count (breakpoint_count
+ 1);
3143 b
->number
= breakpoint_count
;
3147 static struct breakpoint
*
3148 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3149 CORE_ADDR address
, enum bptype type
,
3150 const struct breakpoint_ops
*ops
)
3152 symtab_and_line sal
;
3154 sal
.section
= find_pc_overlay (sal
.pc
);
3155 sal
.pspace
= current_program_space
;
3157 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3158 b
->number
= internal_breakpoint_number
--;
3159 b
->disposition
= disp_donttouch
;
3164 static const char *const longjmp_names
[] =
3166 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3168 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3170 /* Per-objfile data private to breakpoint.c. */
3171 struct breakpoint_objfile_data
3173 /* Minimal symbol for "_ovly_debug_event" (if any). */
3174 struct bound_minimal_symbol overlay_msym
{};
3176 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3177 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3179 /* True if we have looked for longjmp probes. */
3180 int longjmp_searched
= 0;
3182 /* SystemTap probe points for longjmp (if any). These are non-owning
3184 std::vector
<probe
*> longjmp_probes
;
3186 /* Minimal symbol for "std::terminate()" (if any). */
3187 struct bound_minimal_symbol terminate_msym
{};
3189 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3190 struct bound_minimal_symbol exception_msym
{};
3192 /* True if we have looked for exception probes. */
3193 int exception_searched
= 0;
3195 /* SystemTap probe points for unwinding (if any). These are non-owning
3197 std::vector
<probe
*> exception_probes
;
3200 static const struct objfile_key
<breakpoint_objfile_data
>
3201 breakpoint_objfile_key
;
3203 /* Minimal symbol not found sentinel. */
3204 static struct minimal_symbol msym_not_found
;
3206 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3209 msym_not_found_p (const struct minimal_symbol
*msym
)
3211 return msym
== &msym_not_found
;
3214 /* Return per-objfile data needed by breakpoint.c.
3215 Allocate the data if necessary. */
3217 static struct breakpoint_objfile_data
*
3218 get_breakpoint_objfile_data (struct objfile
*objfile
)
3220 struct breakpoint_objfile_data
*bp_objfile_data
;
3222 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3223 if (bp_objfile_data
== NULL
)
3224 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3225 return bp_objfile_data
;
3229 create_overlay_event_breakpoint (void)
3231 const char *const func_name
= "_ovly_debug_event";
3233 for (objfile
*objfile
: current_program_space
->objfiles ())
3235 struct breakpoint
*b
;
3236 struct breakpoint_objfile_data
*bp_objfile_data
;
3238 struct explicit_location explicit_loc
;
3240 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3242 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3245 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3247 struct bound_minimal_symbol m
;
3249 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3250 if (m
.minsym
== NULL
)
3252 /* Avoid future lookups in this objfile. */
3253 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3256 bp_objfile_data
->overlay_msym
= m
;
3259 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3260 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3262 &internal_breakpoint_ops
);
3263 initialize_explicit_location (&explicit_loc
);
3264 explicit_loc
.function_name
= ASTRDUP (func_name
);
3265 b
->location
= new_explicit_location (&explicit_loc
);
3267 if (overlay_debugging
== ovly_auto
)
3269 b
->enable_state
= bp_enabled
;
3270 overlay_events_enabled
= 1;
3274 b
->enable_state
= bp_disabled
;
3275 overlay_events_enabled
= 0;
3280 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3281 true if a breakpoint was installed. */
3284 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3286 struct gdbarch
*gdbarch
= objfile
->arch ();
3287 struct breakpoint_objfile_data
*bp_objfile_data
3288 = get_breakpoint_objfile_data (objfile
);
3290 if (!bp_objfile_data
->longjmp_searched
)
3292 std::vector
<probe
*> ret
3293 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3297 /* We are only interested in checking one element. */
3300 if (!p
->can_evaluate_arguments ())
3302 /* We cannot use the probe interface here,
3303 because it does not know how to evaluate
3308 bp_objfile_data
->longjmp_probes
= ret
;
3309 bp_objfile_data
->longjmp_searched
= 1;
3312 if (bp_objfile_data
->longjmp_probes
.empty ())
3315 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3317 struct breakpoint
*b
;
3319 b
= create_internal_breakpoint (gdbarch
,
3320 p
->get_relocated_address (objfile
),
3322 &internal_breakpoint_ops
);
3323 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3324 b
->enable_state
= bp_disabled
;
3330 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3331 Return true if at least one breakpoint was installed. */
3334 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3336 struct gdbarch
*gdbarch
= objfile
->arch ();
3337 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3340 struct breakpoint_objfile_data
*bp_objfile_data
3341 = get_breakpoint_objfile_data (objfile
);
3342 unsigned int installed_bp
= 0;
3344 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3346 struct breakpoint
*b
;
3347 const char *func_name
;
3349 struct explicit_location explicit_loc
;
3351 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3354 func_name
= longjmp_names
[i
];
3355 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3357 struct bound_minimal_symbol m
;
3359 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3360 if (m
.minsym
== NULL
)
3362 /* Prevent future lookups in this objfile. */
3363 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3366 bp_objfile_data
->longjmp_msym
[i
] = m
;
3369 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3370 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3371 &internal_breakpoint_ops
);
3372 initialize_explicit_location (&explicit_loc
);
3373 explicit_loc
.function_name
= ASTRDUP (func_name
);
3374 b
->location
= new_explicit_location (&explicit_loc
);
3375 b
->enable_state
= bp_disabled
;
3379 return installed_bp
> 0;
3382 /* Create a master longjmp breakpoint. */
3385 create_longjmp_master_breakpoint (void)
3387 scoped_restore_current_program_space restore_pspace
;
3389 for (struct program_space
*pspace
: program_spaces
)
3391 set_current_program_space (pspace
);
3393 for (objfile
*obj
: current_program_space
->objfiles ())
3395 /* Skip separate debug object, it's handled in the loop below. */
3396 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3399 /* Try a probe kind breakpoint on main objfile. */
3400 if (create_longjmp_master_breakpoint_probe (obj
))
3403 /* Try longjmp_names kind breakpoints on main and separate_debug
3405 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3406 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3412 /* Create a master std::terminate breakpoint. */
3414 create_std_terminate_master_breakpoint (void)
3416 const char *const func_name
= "std::terminate()";
3418 scoped_restore_current_program_space restore_pspace
;
3420 for (struct program_space
*pspace
: program_spaces
)
3424 set_current_program_space (pspace
);
3426 for (objfile
*objfile
: current_program_space
->objfiles ())
3428 struct breakpoint
*b
;
3429 struct breakpoint_objfile_data
*bp_objfile_data
;
3430 struct explicit_location explicit_loc
;
3432 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3434 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3437 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3439 struct bound_minimal_symbol m
;
3441 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3442 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3443 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3445 /* Prevent future lookups in this objfile. */
3446 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3449 bp_objfile_data
->terminate_msym
= m
;
3452 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3453 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3454 bp_std_terminate_master
,
3455 &internal_breakpoint_ops
);
3456 initialize_explicit_location (&explicit_loc
);
3457 explicit_loc
.function_name
= ASTRDUP (func_name
);
3458 b
->location
= new_explicit_location (&explicit_loc
);
3459 b
->enable_state
= bp_disabled
;
3464 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3465 probe. Return true if a breakpoint was installed. */
3468 create_exception_master_breakpoint_probe (objfile
*objfile
)
3470 struct breakpoint
*b
;
3471 struct gdbarch
*gdbarch
;
3472 struct breakpoint_objfile_data
*bp_objfile_data
;
3474 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3476 /* We prefer the SystemTap probe point if it exists. */
3477 if (!bp_objfile_data
->exception_searched
)
3479 std::vector
<probe
*> ret
3480 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3484 /* We are only interested in checking one element. */
3487 if (!p
->can_evaluate_arguments ())
3489 /* We cannot use the probe interface here, because it does
3490 not know how to evaluate arguments. */
3494 bp_objfile_data
->exception_probes
= ret
;
3495 bp_objfile_data
->exception_searched
= 1;
3498 if (bp_objfile_data
->exception_probes
.empty ())
3501 gdbarch
= objfile
->arch ();
3503 for (probe
*p
: bp_objfile_data
->exception_probes
)
3505 b
= create_internal_breakpoint (gdbarch
,
3506 p
->get_relocated_address (objfile
),
3507 bp_exception_master
,
3508 &internal_breakpoint_ops
);
3509 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3510 b
->enable_state
= bp_disabled
;
3516 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3517 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3520 create_exception_master_breakpoint_hook (objfile
*objfile
)
3522 const char *const func_name
= "_Unwind_DebugHook";
3523 struct breakpoint
*b
;
3524 struct gdbarch
*gdbarch
;
3525 struct breakpoint_objfile_data
*bp_objfile_data
;
3527 struct explicit_location explicit_loc
;
3529 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3531 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3534 gdbarch
= objfile
->arch ();
3536 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3538 struct bound_minimal_symbol debug_hook
;
3540 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3541 if (debug_hook
.minsym
== NULL
)
3543 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3547 bp_objfile_data
->exception_msym
= debug_hook
;
3550 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3551 addr
= gdbarch_convert_from_func_ptr_addr
3552 (gdbarch
, addr
, current_inferior ()->top_target ());
3553 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3554 &internal_breakpoint_ops
);
3555 initialize_explicit_location (&explicit_loc
);
3556 explicit_loc
.function_name
= ASTRDUP (func_name
);
3557 b
->location
= new_explicit_location (&explicit_loc
);
3558 b
->enable_state
= bp_disabled
;
3563 /* Install a master breakpoint on the unwinder's debug hook. */
3566 create_exception_master_breakpoint (void)
3568 for (objfile
*obj
: current_program_space
->objfiles ())
3570 /* Skip separate debug object. */
3571 if (obj
->separate_debug_objfile_backlink
)
3574 /* Try a probe kind breakpoint. */
3575 if (create_exception_master_breakpoint_probe (obj
))
3578 /* Iterate over main and separate debug objects and try an
3579 _Unwind_DebugHook kind breakpoint. */
3580 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3581 if (create_exception_master_breakpoint_hook (debug_objfile
))
3586 /* Does B have a location spec? */
3589 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3591 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3595 update_breakpoints_after_exec (void)
3597 /* We're about to delete breakpoints from GDB's lists. If the
3598 INSERTED flag is true, GDB will try to lift the breakpoints by
3599 writing the breakpoints' "shadow contents" back into memory. The
3600 "shadow contents" are NOT valid after an exec, so GDB should not
3601 do that. Instead, the target is responsible from marking
3602 breakpoints out as soon as it detects an exec. We don't do that
3603 here instead, because there may be other attempts to delete
3604 breakpoints after detecting an exec and before reaching here. */
3605 for (bp_location
*bploc
: all_bp_locations ())
3606 if (bploc
->pspace
== current_program_space
)
3607 gdb_assert (!bploc
->inserted
);
3609 for (breakpoint
*b
: all_breakpoints_safe ())
3611 if (b
->pspace
!= current_program_space
)
3614 /* Solib breakpoints must be explicitly reset after an exec(). */
3615 if (b
->type
== bp_shlib_event
)
3617 delete_breakpoint (b
);
3621 /* JIT breakpoints must be explicitly reset after an exec(). */
3622 if (b
->type
== bp_jit_event
)
3624 delete_breakpoint (b
);
3628 /* Thread event breakpoints must be set anew after an exec(),
3629 as must overlay event and longjmp master breakpoints. */
3630 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3631 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3632 || b
->type
== bp_exception_master
)
3634 delete_breakpoint (b
);
3638 /* Step-resume breakpoints are meaningless after an exec(). */
3639 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3641 delete_breakpoint (b
);
3645 /* Just like single-step breakpoints. */
3646 if (b
->type
== bp_single_step
)
3648 delete_breakpoint (b
);
3652 /* Longjmp and longjmp-resume breakpoints are also meaningless
3654 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3655 || b
->type
== bp_longjmp_call_dummy
3656 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3658 delete_breakpoint (b
);
3662 if (b
->type
== bp_catchpoint
)
3664 /* For now, none of the bp_catchpoint breakpoints need to
3665 do anything at this point. In the future, if some of
3666 the catchpoints need to something, we will need to add
3667 a new method, and call this method from here. */
3671 /* bp_finish is a special case. The only way we ought to be able
3672 to see one of these when an exec() has happened, is if the user
3673 caught a vfork, and then said "finish". Ordinarily a finish just
3674 carries them to the call-site of the current callee, by setting
3675 a temporary bp there and resuming. But in this case, the finish
3676 will carry them entirely through the vfork & exec.
3678 We don't want to allow a bp_finish to remain inserted now. But
3679 we can't safely delete it, 'cause finish_command has a handle to
3680 the bp on a bpstat, and will later want to delete it. There's a
3681 chance (and I've seen it happen) that if we delete the bp_finish
3682 here, that its storage will get reused by the time finish_command
3683 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3684 We really must allow finish_command to delete a bp_finish.
3686 In the absence of a general solution for the "how do we know
3687 it's safe to delete something others may have handles to?"
3688 problem, what we'll do here is just uninsert the bp_finish, and
3689 let finish_command delete it.
3691 (We know the bp_finish is "doomed" in the sense that it's
3692 momentary, and will be deleted as soon as finish_command sees
3693 the inferior stopped. So it doesn't matter that the bp's
3694 address is probably bogus in the new a.out, unlike e.g., the
3695 solib breakpoints.) */
3697 if (b
->type
== bp_finish
)
3702 /* Without a symbolic address, we have little hope of the
3703 pre-exec() address meaning the same thing in the post-exec()
3705 if (breakpoint_event_location_empty_p (b
))
3707 delete_breakpoint (b
);
3714 detach_breakpoints (ptid_t ptid
)
3717 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3718 struct inferior
*inf
= current_inferior ();
3720 if (ptid
.pid () == inferior_ptid
.pid ())
3721 error (_("Cannot detach breakpoints of inferior_ptid"));
3723 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3724 inferior_ptid
= ptid
;
3725 for (bp_location
*bl
: all_bp_locations ())
3727 if (bl
->pspace
!= inf
->pspace
)
3730 /* This function must physically remove breakpoints locations
3731 from the specified ptid, without modifying the breakpoint
3732 package's state. Locations of type bp_loc_other are only
3733 maintained at GDB side. So, there is no need to remove
3734 these bp_loc_other locations. Moreover, removing these
3735 would modify the breakpoint package's state. */
3736 if (bl
->loc_type
== bp_loc_other
)
3740 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3746 /* Remove the breakpoint location BL from the current address space.
3747 Note that this is used to detach breakpoints from a child fork.
3748 When we get here, the child isn't in the inferior list, and neither
3749 do we have objects to represent its address space --- we should
3750 *not* look at bl->pspace->aspace here. */
3753 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3757 /* BL is never in moribund_locations by our callers. */
3758 gdb_assert (bl
->owner
!= NULL
);
3760 /* The type of none suggests that owner is actually deleted.
3761 This should not ever happen. */
3762 gdb_assert (bl
->owner
->type
!= bp_none
);
3764 if (bl
->loc_type
== bp_loc_software_breakpoint
3765 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3767 /* "Normal" instruction breakpoint: either the standard
3768 trap-instruction bp (bp_breakpoint), or a
3769 bp_hardware_breakpoint. */
3771 /* First check to see if we have to handle an overlay. */
3772 if (overlay_debugging
== ovly_off
3773 || bl
->section
== NULL
3774 || !(section_is_overlay (bl
->section
)))
3776 /* No overlay handling: just remove the breakpoint. */
3778 /* If we're trying to uninsert a memory breakpoint that we
3779 know is set in a dynamic object that is marked
3780 shlib_disabled, then either the dynamic object was
3781 removed with "remove-symbol-file" or with
3782 "nosharedlibrary". In the former case, we don't know
3783 whether another dynamic object might have loaded over the
3784 breakpoint's address -- the user might well let us know
3785 about it next with add-symbol-file (the whole point of
3786 add-symbol-file is letting the user manually maintain a
3787 list of dynamically loaded objects). If we have the
3788 breakpoint's shadow memory, that is, this is a software
3789 breakpoint managed by GDB, check whether the breakpoint
3790 is still inserted in memory, to avoid overwriting wrong
3791 code with stale saved shadow contents. Note that HW
3792 breakpoints don't have shadow memory, as they're
3793 implemented using a mechanism that is not dependent on
3794 being able to modify the target's memory, and as such
3795 they should always be removed. */
3796 if (bl
->shlib_disabled
3797 && bl
->target_info
.shadow_len
!= 0
3798 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3801 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3805 /* This breakpoint is in an overlay section.
3806 Did we set a breakpoint at the LMA? */
3807 if (!overlay_events_enabled
)
3809 /* Yes -- overlay event support is not active, so we
3810 should have set a breakpoint at the LMA. Remove it.
3812 /* Ignore any failures: if the LMA is in ROM, we will
3813 have already warned when we failed to insert it. */
3814 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3815 target_remove_hw_breakpoint (bl
->gdbarch
,
3816 &bl
->overlay_target_info
);
3818 target_remove_breakpoint (bl
->gdbarch
,
3819 &bl
->overlay_target_info
,
3822 /* Did we set a breakpoint at the VMA?
3823 If so, we will have marked the breakpoint 'inserted'. */
3826 /* Yes -- remove it. Previously we did not bother to
3827 remove the breakpoint if the section had been
3828 unmapped, but let's not rely on that being safe. We
3829 don't know what the overlay manager might do. */
3831 /* However, we should remove *software* breakpoints only
3832 if the section is still mapped, or else we overwrite
3833 wrong code with the saved shadow contents. */
3834 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3835 || section_is_mapped (bl
->section
))
3836 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3842 /* No -- not inserted, so no need to remove. No error. */
3847 /* In some cases, we might not be able to remove a breakpoint in
3848 a shared library that has already been removed, but we have
3849 not yet processed the shlib unload event. Similarly for an
3850 unloaded add-symbol-file object - the user might not yet have
3851 had the chance to remove-symbol-file it. shlib_disabled will
3852 be set if the library/object has already been removed, but
3853 the breakpoint hasn't been uninserted yet, e.g., after
3854 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3855 always-inserted mode. */
3857 && (bl
->loc_type
== bp_loc_software_breakpoint
3858 && (bl
->shlib_disabled
3859 || solib_name_from_address (bl
->pspace
, bl
->address
)
3860 || shared_objfile_contains_address_p (bl
->pspace
,
3866 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3868 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3870 gdb_assert (bl
->owner
->ops
!= NULL
3871 && bl
->owner
->ops
->remove_location
!= NULL
);
3873 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3874 bl
->owner
->ops
->remove_location (bl
, reason
);
3876 /* Failure to remove any of the hardware watchpoints comes here. */
3877 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3878 warning (_("Could not remove hardware watchpoint %d."),
3881 else if (bl
->owner
->type
== bp_catchpoint
3882 && breakpoint_enabled (bl
->owner
)
3885 gdb_assert (bl
->owner
->ops
!= NULL
3886 && bl
->owner
->ops
->remove_location
!= NULL
);
3888 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3892 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3899 remove_breakpoint (struct bp_location
*bl
)
3901 /* BL is never in moribund_locations by our callers. */
3902 gdb_assert (bl
->owner
!= NULL
);
3904 /* The type of none suggests that owner is actually deleted.
3905 This should not ever happen. */
3906 gdb_assert (bl
->owner
->type
!= bp_none
);
3908 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3910 switch_to_program_space_and_thread (bl
->pspace
);
3912 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3915 /* Clear the "inserted" flag in all breakpoints. */
3918 mark_breakpoints_out (void)
3920 for (bp_location
*bl
: all_bp_locations ())
3921 if (bl
->pspace
== current_program_space
)
3925 /* Clear the "inserted" flag in all breakpoints and delete any
3926 breakpoints which should go away between runs of the program.
3928 Plus other such housekeeping that has to be done for breakpoints
3931 Note: this function gets called at the end of a run (by
3932 generic_mourn_inferior) and when a run begins (by
3933 init_wait_for_inferior). */
3938 breakpoint_init_inferior (enum inf_context context
)
3940 struct program_space
*pspace
= current_program_space
;
3942 /* If breakpoint locations are shared across processes, then there's
3944 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3947 mark_breakpoints_out ();
3949 for (breakpoint
*b
: all_breakpoints_safe ())
3951 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3957 case bp_longjmp_call_dummy
:
3959 /* If the call dummy breakpoint is at the entry point it will
3960 cause problems when the inferior is rerun, so we better get
3963 case bp_watchpoint_scope
:
3965 /* Also get rid of scope breakpoints. */
3967 case bp_shlib_event
:
3969 /* Also remove solib event breakpoints. Their addresses may
3970 have changed since the last time we ran the program.
3971 Actually we may now be debugging against different target;
3972 and so the solib backend that installed this breakpoint may
3973 not be used in by the target. E.g.,
3975 (gdb) file prog-linux
3976 (gdb) run # native linux target
3979 (gdb) file prog-win.exe
3980 (gdb) tar rem :9999 # remote Windows gdbserver.
3983 case bp_step_resume
:
3985 /* Also remove step-resume breakpoints. */
3987 case bp_single_step
:
3989 /* Also remove single-step breakpoints. */
3991 delete_breakpoint (b
);
3995 case bp_hardware_watchpoint
:
3996 case bp_read_watchpoint
:
3997 case bp_access_watchpoint
:
3999 struct watchpoint
*w
= (struct watchpoint
*) b
;
4001 /* Likewise for watchpoints on local expressions. */
4002 if (w
->exp_valid_block
!= NULL
)
4003 delete_breakpoint (b
);
4006 /* Get rid of existing locations, which are no longer
4007 valid. New ones will be created in
4008 update_watchpoint, when the inferior is restarted.
4009 The next update_global_location_list call will
4010 garbage collect them. */
4013 if (context
== inf_starting
)
4015 /* Reset val field to force reread of starting value in
4016 insert_breakpoints. */
4017 w
->val
.reset (nullptr);
4018 w
->val_valid
= false;
4028 /* Get rid of the moribund locations. */
4029 for (bp_location
*bl
: moribund_locations
)
4030 decref_bp_location (&bl
);
4031 moribund_locations
.clear ();
4034 /* These functions concern about actual breakpoints inserted in the
4035 target --- to e.g. check if we need to do decr_pc adjustment or if
4036 we need to hop over the bkpt --- so we check for address space
4037 match, not program space. */
4039 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4040 exists at PC. It returns ordinary_breakpoint_here if it's an
4041 ordinary breakpoint, or permanent_breakpoint_here if it's a
4042 permanent breakpoint.
4043 - When continuing from a location with an ordinary breakpoint, we
4044 actually single step once before calling insert_breakpoints.
4045 - When continuing from a location with a permanent breakpoint, we
4046 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4047 the target, to advance the PC past the breakpoint. */
4049 enum breakpoint_here
4050 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4052 int any_breakpoint_here
= 0;
4054 for (bp_location
*bl
: all_bp_locations ())
4056 if (bl
->loc_type
!= bp_loc_software_breakpoint
4057 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4060 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4061 if ((breakpoint_enabled (bl
->owner
)
4063 && breakpoint_location_address_match (bl
, aspace
, pc
))
4065 if (overlay_debugging
4066 && section_is_overlay (bl
->section
)
4067 && !section_is_mapped (bl
->section
))
4068 continue; /* unmapped overlay -- can't be a match */
4069 else if (bl
->permanent
)
4070 return permanent_breakpoint_here
;
4072 any_breakpoint_here
= 1;
4076 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4079 /* See breakpoint.h. */
4082 breakpoint_in_range_p (const address_space
*aspace
,
4083 CORE_ADDR addr
, ULONGEST len
)
4085 for (bp_location
*bl
: all_bp_locations ())
4087 if (bl
->loc_type
!= bp_loc_software_breakpoint
4088 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4091 if ((breakpoint_enabled (bl
->owner
)
4093 && breakpoint_location_address_range_overlap (bl
, aspace
,
4096 if (overlay_debugging
4097 && section_is_overlay (bl
->section
)
4098 && !section_is_mapped (bl
->section
))
4100 /* Unmapped overlay -- can't be a match. */
4111 /* Return true if there's a moribund breakpoint at PC. */
4114 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4116 for (bp_location
*loc
: moribund_locations
)
4117 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4123 /* Returns non-zero iff BL is inserted at PC, in address space
4127 bp_location_inserted_here_p (struct bp_location
*bl
,
4128 const address_space
*aspace
, CORE_ADDR pc
)
4131 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4134 if (overlay_debugging
4135 && section_is_overlay (bl
->section
)
4136 && !section_is_mapped (bl
->section
))
4137 return 0; /* unmapped overlay -- can't be a match */
4144 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4147 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4149 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4151 if (bl
->loc_type
!= bp_loc_software_breakpoint
4152 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4155 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4161 /* This function returns non-zero iff there is a software breakpoint
4165 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4168 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4170 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4173 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4180 /* See breakpoint.h. */
4183 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4186 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4188 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4191 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4199 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4200 CORE_ADDR addr
, ULONGEST len
)
4202 for (breakpoint
*bpt
: all_breakpoints ())
4204 if (bpt
->type
!= bp_hardware_watchpoint
4205 && bpt
->type
!= bp_access_watchpoint
)
4208 if (!breakpoint_enabled (bpt
))
4211 for (bp_location
*loc
: bpt
->locations ())
4212 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4216 /* Check for intersection. */
4217 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4218 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4226 /* See breakpoint.h. */
4229 is_catchpoint (struct breakpoint
*b
)
4231 return (b
->type
== bp_catchpoint
);
4234 /* Clear a bpstat so that it says we are not at any breakpoint.
4235 Also free any storage that is part of a bpstat. */
4238 bpstat_clear (bpstat
*bsp
)
4255 bpstats::bpstats (const bpstats
&other
)
4257 bp_location_at (other
.bp_location_at
),
4258 breakpoint_at (other
.breakpoint_at
),
4259 commands (other
.commands
),
4260 print (other
.print
),
4262 print_it (other
.print_it
)
4264 if (other
.old_val
!= NULL
)
4265 old_val
= release_value (value_copy (other
.old_val
.get ()));
4268 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4269 is part of the bpstat is copied as well. */
4272 bpstat_copy (bpstat bs
)
4276 bpstat retval
= NULL
;
4281 for (; bs
!= NULL
; bs
= bs
->next
)
4283 tmp
= new bpstats (*bs
);
4286 /* This is the first thing in the chain. */
4296 /* Find the bpstat associated with this breakpoint. */
4299 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4304 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4306 if (bsp
->breakpoint_at
== breakpoint
)
4312 /* See breakpoint.h. */
4315 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4317 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4319 if (bsp
->breakpoint_at
== NULL
)
4321 /* A moribund location can never explain a signal other than
4323 if (sig
== GDB_SIGNAL_TRAP
)
4328 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4337 /* Put in *NUM the breakpoint number of the first breakpoint we are
4338 stopped at. *BSP upon return is a bpstat which points to the
4339 remaining breakpoints stopped at (but which is not guaranteed to be
4340 good for anything but further calls to bpstat_num).
4342 Return 0 if passed a bpstat which does not indicate any breakpoints.
4343 Return -1 if stopped at a breakpoint that has been deleted since
4345 Return 1 otherwise. */
4348 bpstat_num (bpstat
*bsp
, int *num
)
4350 struct breakpoint
*b
;
4353 return 0; /* No more breakpoint values */
4355 /* We assume we'll never have several bpstats that correspond to a
4356 single breakpoint -- otherwise, this function might return the
4357 same number more than once and this will look ugly. */
4358 b
= (*bsp
)->breakpoint_at
;
4359 *bsp
= (*bsp
)->next
;
4361 return -1; /* breakpoint that's been deleted since */
4363 *num
= b
->number
; /* We have its number */
4367 /* See breakpoint.h. */
4370 bpstat_clear_actions (void)
4374 if (inferior_ptid
== null_ptid
)
4377 thread_info
*tp
= inferior_thread ();
4378 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4380 bs
->commands
= NULL
;
4381 bs
->old_val
.reset (nullptr);
4385 /* Called when a command is about to proceed the inferior. */
4388 breakpoint_about_to_proceed (void)
4390 if (inferior_ptid
!= null_ptid
)
4392 struct thread_info
*tp
= inferior_thread ();
4394 /* Allow inferior function calls in breakpoint commands to not
4395 interrupt the command list. When the call finishes
4396 successfully, the inferior will be standing at the same
4397 breakpoint as if nothing happened. */
4398 if (tp
->control
.in_infcall
)
4402 breakpoint_proceeded
= 1;
4405 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4406 or its equivalent. */
4409 command_line_is_silent (struct command_line
*cmd
)
4411 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4414 /* Execute all the commands associated with all the breakpoints at
4415 this location. Any of these commands could cause the process to
4416 proceed beyond this point, etc. We look out for such changes by
4417 checking the global "breakpoint_proceeded" after each command.
4419 Returns true if a breakpoint command resumed the inferior. In that
4420 case, it is the caller's responsibility to recall it again with the
4421 bpstat of the current thread. */
4424 bpstat_do_actions_1 (bpstat
*bsp
)
4429 /* Avoid endless recursion if a `source' command is contained
4431 if (executing_breakpoint_commands
)
4434 scoped_restore save_executing
4435 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4437 scoped_restore preventer
= prevent_dont_repeat ();
4439 /* This pointer will iterate over the list of bpstat's. */
4442 breakpoint_proceeded
= 0;
4443 for (; bs
!= NULL
; bs
= bs
->next
)
4445 struct command_line
*cmd
= NULL
;
4447 /* Take ownership of the BSP's command tree, if it has one.
4449 The command tree could legitimately contain commands like
4450 'step' and 'next', which call clear_proceed_status, which
4451 frees stop_bpstat's command tree. To make sure this doesn't
4452 free the tree we're executing out from under us, we need to
4453 take ownership of the tree ourselves. Since a given bpstat's
4454 commands are only executed once, we don't need to copy it; we
4455 can clear the pointer in the bpstat, and make sure we free
4456 the tree when we're done. */
4457 counted_command_line ccmd
= bs
->commands
;
4458 bs
->commands
= NULL
;
4461 if (command_line_is_silent (cmd
))
4463 /* The action has been already done by bpstat_stop_status. */
4469 execute_control_command (cmd
);
4471 if (breakpoint_proceeded
)
4477 if (breakpoint_proceeded
)
4479 if (current_ui
->async
)
4480 /* If we are in async mode, then the target might be still
4481 running, not stopped at any breakpoint, so nothing for
4482 us to do here -- just return to the event loop. */
4485 /* In sync mode, when execute_control_command returns
4486 we're already standing on the next breakpoint.
4487 Breakpoint commands for that stop were not run, since
4488 execute_command does not run breakpoint commands --
4489 only command_line_handler does, but that one is not
4490 involved in execution of breakpoint commands. So, we
4491 can now execute breakpoint commands. It should be
4492 noted that making execute_command do bpstat actions is
4493 not an option -- in this case we'll have recursive
4494 invocation of bpstat for each breakpoint with a
4495 command, and can easily blow up GDB stack. Instead, we
4496 return true, which will trigger the caller to recall us
4497 with the new stop_bpstat. */
4505 /* Helper for bpstat_do_actions. Get the current thread, if there's
4506 one, is alive and has execution. Return NULL otherwise. */
4508 static thread_info
*
4509 get_bpstat_thread ()
4511 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4514 thread_info
*tp
= inferior_thread ();
4515 if (tp
->state
== THREAD_EXITED
|| tp
->executing ())
4521 bpstat_do_actions (void)
4523 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4526 /* Do any commands attached to breakpoint we are stopped at. */
4527 while ((tp
= get_bpstat_thread ()) != NULL
)
4529 /* Since in sync mode, bpstat_do_actions may resume the
4530 inferior, and only return when it is stopped at the next
4531 breakpoint, we keep doing breakpoint actions until it returns
4532 false to indicate the inferior was not resumed. */
4533 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4537 cleanup_if_error
.release ();
4540 /* Print out the (old or new) value associated with a watchpoint. */
4543 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4546 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4549 struct value_print_options opts
;
4550 get_user_print_options (&opts
);
4551 value_print (val
, stream
, &opts
);
4555 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4556 debugging multiple threads. */
4559 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4561 if (uiout
->is_mi_like_p ())
4566 if (show_thread_that_caused_stop ())
4568 struct thread_info
*thr
= inferior_thread ();
4570 uiout
->text ("Thread ");
4571 uiout
->field_string ("thread-id", print_thread_id (thr
));
4573 const char *name
= thread_name (thr
);
4576 uiout
->text (" \"");
4577 uiout
->field_string ("name", name
);
4581 uiout
->text (" hit ");
4585 /* Generic routine for printing messages indicating why we
4586 stopped. The behavior of this function depends on the value
4587 'print_it' in the bpstat structure. Under some circumstances we
4588 may decide not to print anything here and delegate the task to
4591 static enum print_stop_action
4592 print_bp_stop_message (bpstat bs
)
4594 switch (bs
->print_it
)
4597 /* Nothing should be printed for this bpstat entry. */
4598 return PRINT_UNKNOWN
;
4602 /* We still want to print the frame, but we already printed the
4603 relevant messages. */
4604 return PRINT_SRC_AND_LOC
;
4607 case print_it_normal
:
4609 struct breakpoint
*b
= bs
->breakpoint_at
;
4611 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4612 which has since been deleted. */
4614 return PRINT_UNKNOWN
;
4616 /* Normal case. Call the breakpoint's print_it method. */
4617 return b
->ops
->print_it (bs
);
4622 internal_error (__FILE__
, __LINE__
,
4623 _("print_bp_stop_message: unrecognized enum value"));
4628 /* A helper function that prints a shared library stopped event. */
4631 print_solib_event (int is_catchpoint
)
4633 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4634 bool any_added
= !current_program_space
->added_solibs
.empty ();
4638 if (any_added
|| any_deleted
)
4639 current_uiout
->text (_("Stopped due to shared library event:\n"));
4641 current_uiout
->text (_("Stopped due to shared library event (no "
4642 "libraries added or removed)\n"));
4645 if (current_uiout
->is_mi_like_p ())
4646 current_uiout
->field_string ("reason",
4647 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4651 current_uiout
->text (_(" Inferior unloaded "));
4652 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4653 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4655 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4658 current_uiout
->text (" ");
4659 current_uiout
->field_string ("library", name
);
4660 current_uiout
->text ("\n");
4666 current_uiout
->text (_(" Inferior loaded "));
4667 ui_out_emit_list
list_emitter (current_uiout
, "added");
4669 for (so_list
*iter
: current_program_space
->added_solibs
)
4672 current_uiout
->text (" ");
4674 current_uiout
->field_string ("library", iter
->so_name
);
4675 current_uiout
->text ("\n");
4680 /* Print a message indicating what happened. This is called from
4681 normal_stop(). The input to this routine is the head of the bpstat
4682 list - a list of the eventpoints that caused this stop. KIND is
4683 the target_waitkind for the stopping event. This
4684 routine calls the generic print routine for printing a message
4685 about reasons for stopping. This will print (for example) the
4686 "Breakpoint n," part of the output. The return value of this
4689 PRINT_UNKNOWN: Means we printed nothing.
4690 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4691 code to print the location. An example is
4692 "Breakpoint 1, " which should be followed by
4694 PRINT_SRC_ONLY: Means we printed something, but there is no need
4695 to also print the location part of the message.
4696 An example is the catch/throw messages, which
4697 don't require a location appended to the end.
4698 PRINT_NOTHING: We have done some printing and we don't need any
4699 further info to be printed. */
4701 enum print_stop_action
4702 bpstat_print (bpstat bs
, int kind
)
4704 enum print_stop_action val
;
4706 /* Maybe another breakpoint in the chain caused us to stop.
4707 (Currently all watchpoints go on the bpstat whether hit or not.
4708 That probably could (should) be changed, provided care is taken
4709 with respect to bpstat_explains_signal). */
4710 for (; bs
; bs
= bs
->next
)
4712 val
= print_bp_stop_message (bs
);
4713 if (val
== PRINT_SRC_ONLY
4714 || val
== PRINT_SRC_AND_LOC
4715 || val
== PRINT_NOTHING
)
4719 /* If we had hit a shared library event breakpoint,
4720 print_bp_stop_message would print out this message. If we hit an
4721 OS-level shared library event, do the same thing. */
4722 if (kind
== TARGET_WAITKIND_LOADED
)
4724 print_solib_event (0);
4725 return PRINT_NOTHING
;
4728 /* We reached the end of the chain, or we got a null BS to start
4729 with and nothing was printed. */
4730 return PRINT_UNKNOWN
;
4733 /* Evaluate the boolean expression EXP and return the result. */
4736 breakpoint_cond_eval (expression
*exp
)
4738 struct value
*mark
= value_mark ();
4739 bool res
= value_true (evaluate_expression (exp
));
4741 value_free_to_mark (mark
);
4745 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4747 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4749 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4750 breakpoint_at (bl
->owner
),
4754 print_it (print_it_normal
)
4756 **bs_link_pointer
= this;
4757 *bs_link_pointer
= &next
;
4762 breakpoint_at (NULL
),
4766 print_it (print_it_normal
)
4770 /* The target has stopped with waitstatus WS. Check if any hardware
4771 watchpoints have triggered, according to the target. */
4774 watchpoints_triggered (struct target_waitstatus
*ws
)
4776 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4779 if (!stopped_by_watchpoint
)
4781 /* We were not stopped by a watchpoint. Mark all watchpoints
4782 as not triggered. */
4783 for (breakpoint
*b
: all_breakpoints ())
4784 if (is_hardware_watchpoint (b
))
4786 struct watchpoint
*w
= (struct watchpoint
*) b
;
4788 w
->watchpoint_triggered
= watch_triggered_no
;
4794 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4796 /* We were stopped by a watchpoint, but we don't know where.
4797 Mark all watchpoints as unknown. */
4798 for (breakpoint
*b
: all_breakpoints ())
4799 if (is_hardware_watchpoint (b
))
4801 struct watchpoint
*w
= (struct watchpoint
*) b
;
4803 w
->watchpoint_triggered
= watch_triggered_unknown
;
4809 /* The target could report the data address. Mark watchpoints
4810 affected by this data address as triggered, and all others as not
4813 for (breakpoint
*b
: all_breakpoints ())
4814 if (is_hardware_watchpoint (b
))
4816 struct watchpoint
*w
= (struct watchpoint
*) b
;
4818 w
->watchpoint_triggered
= watch_triggered_no
;
4819 for (bp_location
*loc
: b
->locations ())
4821 if (is_masked_watchpoint (b
))
4823 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4824 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4826 if (newaddr
== start
)
4828 w
->watchpoint_triggered
= watch_triggered_yes
;
4832 /* Exact match not required. Within range is sufficient. */
4833 else if (target_watchpoint_addr_within_range
4834 (current_inferior ()->top_target (), addr
, loc
->address
,
4837 w
->watchpoint_triggered
= watch_triggered_yes
;
4846 /* Possible return values for watchpoint_check. */
4847 enum wp_check_result
4849 /* The watchpoint has been deleted. */
4852 /* The value has changed. */
4853 WP_VALUE_CHANGED
= 2,
4855 /* The value has not changed. */
4856 WP_VALUE_NOT_CHANGED
= 3,
4858 /* Ignore this watchpoint, no matter if the value changed or not. */
4862 #define BP_TEMPFLAG 1
4863 #define BP_HARDWAREFLAG 2
4865 /* Evaluate watchpoint condition expression and check if its value
4868 static wp_check_result
4869 watchpoint_check (bpstat bs
)
4871 struct watchpoint
*b
;
4872 struct frame_info
*fr
;
4873 int within_current_scope
;
4875 /* BS is built from an existing struct breakpoint. */
4876 gdb_assert (bs
->breakpoint_at
!= NULL
);
4877 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4879 /* If this is a local watchpoint, we only want to check if the
4880 watchpoint frame is in scope if the current thread is the thread
4881 that was used to create the watchpoint. */
4882 if (!watchpoint_in_thread_scope (b
))
4885 if (b
->exp_valid_block
== NULL
)
4886 within_current_scope
= 1;
4889 struct frame_info
*frame
= get_current_frame ();
4890 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4891 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4893 /* stack_frame_destroyed_p() returns a non-zero value if we're
4894 still in the function but the stack frame has already been
4895 invalidated. Since we can't rely on the values of local
4896 variables after the stack has been destroyed, we are treating
4897 the watchpoint in that state as `not changed' without further
4898 checking. Don't mark watchpoints as changed if the current
4899 frame is in an epilogue - even if they are in some other
4900 frame, our view of the stack is likely to be wrong and
4901 frame_find_by_id could error out. */
4902 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4905 fr
= frame_find_by_id (b
->watchpoint_frame
);
4906 within_current_scope
= (fr
!= NULL
);
4908 /* If we've gotten confused in the unwinder, we might have
4909 returned a frame that can't describe this variable. */
4910 if (within_current_scope
)
4912 struct symbol
*function
;
4914 function
= get_frame_function (fr
);
4915 if (function
== NULL
4916 || !contained_in (b
->exp_valid_block
,
4917 SYMBOL_BLOCK_VALUE (function
)))
4918 within_current_scope
= 0;
4921 if (within_current_scope
)
4922 /* If we end up stopping, the current frame will get selected
4923 in normal_stop. So this call to select_frame won't affect
4928 if (within_current_scope
)
4930 /* We use value_{,free_to_}mark because it could be a *long*
4931 time before we return to the command level and call
4932 free_all_values. We can't call free_all_values because we
4933 might be in the middle of evaluating a function call. */
4936 struct value
*new_val
;
4938 if (is_masked_watchpoint (b
))
4939 /* Since we don't know the exact trigger address (from
4940 stopped_data_address), just tell the user we've triggered
4941 a mask watchpoint. */
4942 return WP_VALUE_CHANGED
;
4944 mark
= value_mark ();
4945 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
4948 if (b
->val_bitsize
!= 0)
4949 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4951 /* We use value_equal_contents instead of value_equal because
4952 the latter coerces an array to a pointer, thus comparing just
4953 the address of the array instead of its contents. This is
4954 not what we want. */
4955 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4956 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
4959 bs
->old_val
= b
->val
;
4960 b
->val
= release_value (new_val
);
4961 b
->val_valid
= true;
4962 if (new_val
!= NULL
)
4963 value_free_to_mark (mark
);
4964 return WP_VALUE_CHANGED
;
4968 /* Nothing changed. */
4969 value_free_to_mark (mark
);
4970 return WP_VALUE_NOT_CHANGED
;
4975 /* This seems like the only logical thing to do because
4976 if we temporarily ignored the watchpoint, then when
4977 we reenter the block in which it is valid it contains
4978 garbage (in the case of a function, it may have two
4979 garbage values, one before and one after the prologue).
4980 So we can't even detect the first assignment to it and
4981 watch after that (since the garbage may or may not equal
4982 the first value assigned). */
4983 /* We print all the stop information in
4984 breakpoint_ops->print_it, but in this case, by the time we
4985 call breakpoint_ops->print_it this bp will be deleted
4986 already. So we have no choice but print the information
4989 SWITCH_THRU_ALL_UIS ()
4991 struct ui_out
*uiout
= current_uiout
;
4993 if (uiout
->is_mi_like_p ())
4995 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4996 uiout
->message ("\nWatchpoint %pF deleted because the program has "
4997 "left the block in\n"
4998 "which its expression is valid.\n",
4999 signed_field ("wpnum", b
->number
));
5002 /* Make sure the watchpoint's commands aren't executed. */
5004 watchpoint_del_at_next_stop (b
);
5010 /* Return true if it looks like target has stopped due to hitting
5011 breakpoint location BL. This function does not check if we should
5012 stop, only if BL explains the stop. */
5015 bpstat_check_location (const struct bp_location
*bl
,
5016 const address_space
*aspace
, CORE_ADDR bp_addr
,
5017 const struct target_waitstatus
*ws
)
5019 struct breakpoint
*b
= bl
->owner
;
5021 /* BL is from an existing breakpoint. */
5022 gdb_assert (b
!= NULL
);
5024 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5027 /* Determine if the watched values have actually changed, and we
5028 should stop. If not, set BS->stop to 0. */
5031 bpstat_check_watchpoint (bpstat bs
)
5033 const struct bp_location
*bl
;
5034 struct watchpoint
*b
;
5036 /* BS is built for existing struct breakpoint. */
5037 bl
= bs
->bp_location_at
.get ();
5038 gdb_assert (bl
!= NULL
);
5039 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5040 gdb_assert (b
!= NULL
);
5043 int must_check_value
= 0;
5045 if (b
->type
== bp_watchpoint
)
5046 /* For a software watchpoint, we must always check the
5048 must_check_value
= 1;
5049 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5050 /* We have a hardware watchpoint (read, write, or access)
5051 and the target earlier reported an address watched by
5053 must_check_value
= 1;
5054 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5055 && b
->type
== bp_hardware_watchpoint
)
5056 /* We were stopped by a hardware watchpoint, but the target could
5057 not report the data address. We must check the watchpoint's
5058 value. Access and read watchpoints are out of luck; without
5059 a data address, we can't figure it out. */
5060 must_check_value
= 1;
5062 if (must_check_value
)
5068 e
= watchpoint_check (bs
);
5070 catch (const gdb_exception
&ex
)
5072 exception_fprintf (gdb_stderr
, ex
,
5073 "Error evaluating expression "
5074 "for watchpoint %d\n",
5077 SWITCH_THRU_ALL_UIS ()
5079 printf_filtered (_("Watchpoint %d deleted.\n"),
5082 watchpoint_del_at_next_stop (b
);
5089 /* We've already printed what needs to be printed. */
5090 bs
->print_it
= print_it_done
;
5094 bs
->print_it
= print_it_noop
;
5097 case WP_VALUE_CHANGED
:
5098 if (b
->type
== bp_read_watchpoint
)
5100 /* There are two cases to consider here:
5102 1. We're watching the triggered memory for reads.
5103 In that case, trust the target, and always report
5104 the watchpoint hit to the user. Even though
5105 reads don't cause value changes, the value may
5106 have changed since the last time it was read, and
5107 since we're not trapping writes, we will not see
5108 those, and as such we should ignore our notion of
5111 2. We're watching the triggered memory for both
5112 reads and writes. There are two ways this may
5115 2.1. This is a target that can't break on data
5116 reads only, but can break on accesses (reads or
5117 writes), such as e.g., x86. We detect this case
5118 at the time we try to insert read watchpoints.
5120 2.2. Otherwise, the target supports read
5121 watchpoints, but, the user set an access or write
5122 watchpoint watching the same memory as this read
5125 If we're watching memory writes as well as reads,
5126 ignore watchpoint hits when we find that the
5127 value hasn't changed, as reads don't cause
5128 changes. This still gives false positives when
5129 the program writes the same value to memory as
5130 what there was already in memory (we will confuse
5131 it for a read), but it's much better than
5134 int other_write_watchpoint
= 0;
5136 if (bl
->watchpoint_type
== hw_read
)
5138 for (breakpoint
*other_b
: all_breakpoints ())
5139 if (other_b
->type
== bp_hardware_watchpoint
5140 || other_b
->type
== bp_access_watchpoint
)
5142 struct watchpoint
*other_w
=
5143 (struct watchpoint
*) other_b
;
5145 if (other_w
->watchpoint_triggered
5146 == watch_triggered_yes
)
5148 other_write_watchpoint
= 1;
5154 if (other_write_watchpoint
5155 || bl
->watchpoint_type
== hw_access
)
5157 /* We're watching the same memory for writes,
5158 and the value changed since the last time we
5159 updated it, so this trap must be for a write.
5161 bs
->print_it
= print_it_noop
;
5166 case WP_VALUE_NOT_CHANGED
:
5167 if (b
->type
== bp_hardware_watchpoint
5168 || b
->type
== bp_watchpoint
)
5170 /* Don't stop: write watchpoints shouldn't fire if
5171 the value hasn't changed. */
5172 bs
->print_it
= print_it_noop
;
5182 else /* must_check_value == 0 */
5184 /* This is a case where some watchpoint(s) triggered, but
5185 not at the address of this watchpoint, or else no
5186 watchpoint triggered after all. So don't print
5187 anything for this watchpoint. */
5188 bs
->print_it
= print_it_noop
;
5194 /* For breakpoints that are currently marked as telling gdb to stop,
5195 check conditions (condition proper, frame, thread and ignore count)
5196 of breakpoint referred to by BS. If we should not stop for this
5197 breakpoint, set BS->stop to 0. */
5200 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5202 const struct bp_location
*bl
;
5203 struct breakpoint
*b
;
5205 bool condition_result
= true;
5206 struct expression
*cond
;
5208 gdb_assert (bs
->stop
);
5210 /* BS is built for existing struct breakpoint. */
5211 bl
= bs
->bp_location_at
.get ();
5212 gdb_assert (bl
!= NULL
);
5213 b
= bs
->breakpoint_at
;
5214 gdb_assert (b
!= NULL
);
5216 /* Even if the target evaluated the condition on its end and notified GDB, we
5217 need to do so again since GDB does not know if we stopped due to a
5218 breakpoint or a single step breakpoint. */
5220 if (frame_id_p (b
->frame_id
)
5221 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5227 /* If this is a thread/task-specific breakpoint, don't waste cpu
5228 evaluating the condition if this isn't the specified
5230 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5231 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5237 /* Evaluate extension language breakpoints that have a "stop" method
5239 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5241 if (is_watchpoint (b
))
5243 struct watchpoint
*w
= (struct watchpoint
*) b
;
5245 cond
= w
->cond_exp
.get ();
5248 cond
= bl
->cond
.get ();
5250 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5252 int within_current_scope
= 1;
5253 struct watchpoint
* w
;
5255 /* We use value_mark and value_free_to_mark because it could
5256 be a long time before we return to the command level and
5257 call free_all_values. We can't call free_all_values
5258 because we might be in the middle of evaluating a
5260 struct value
*mark
= value_mark ();
5262 if (is_watchpoint (b
))
5263 w
= (struct watchpoint
*) b
;
5267 /* Need to select the frame, with all that implies so that
5268 the conditions will have the right context. Because we
5269 use the frame, we will not see an inlined function's
5270 variables when we arrive at a breakpoint at the start
5271 of the inlined function; the current frame will be the
5273 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5274 select_frame (get_current_frame ());
5277 struct frame_info
*frame
;
5279 /* For local watchpoint expressions, which particular
5280 instance of a local is being watched matters, so we
5281 keep track of the frame to evaluate the expression
5282 in. To evaluate the condition however, it doesn't
5283 really matter which instantiation of the function
5284 where the condition makes sense triggers the
5285 watchpoint. This allows an expression like "watch
5286 global if q > 10" set in `func', catch writes to
5287 global on all threads that call `func', or catch
5288 writes on all recursive calls of `func' by a single
5289 thread. We simply always evaluate the condition in
5290 the innermost frame that's executing where it makes
5291 sense to evaluate the condition. It seems
5293 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5295 select_frame (frame
);
5297 within_current_scope
= 0;
5299 if (within_current_scope
)
5303 condition_result
= breakpoint_cond_eval (cond
);
5305 catch (const gdb_exception
&ex
)
5307 exception_fprintf (gdb_stderr
, ex
,
5308 "Error in testing breakpoint condition:\n");
5313 warning (_("Watchpoint condition cannot be tested "
5314 "in the current scope"));
5315 /* If we failed to set the right context for this
5316 watchpoint, unconditionally report it. */
5318 /* FIXME-someday, should give breakpoint #. */
5319 value_free_to_mark (mark
);
5322 if (cond
&& !condition_result
)
5326 else if (b
->ignore_count
> 0)
5330 /* Increase the hit count even though we don't stop. */
5332 gdb::observers::breakpoint_modified
.notify (b
);
5336 /* Returns true if we need to track moribund locations of LOC's type
5337 on the current target. */
5340 need_moribund_for_location_type (struct bp_location
*loc
)
5342 return ((loc
->loc_type
== bp_loc_software_breakpoint
5343 && !target_supports_stopped_by_sw_breakpoint ())
5344 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5345 && !target_supports_stopped_by_hw_breakpoint ()));
5348 /* See breakpoint.h. */
5351 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5352 const struct target_waitstatus
*ws
)
5354 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5356 for (breakpoint
*b
: all_breakpoints ())
5358 if (!breakpoint_enabled (b
))
5361 for (bp_location
*bl
: b
->locations ())
5363 /* For hardware watchpoints, we look only at the first
5364 location. The watchpoint_check function will work on the
5365 entire expression, not the individual locations. For
5366 read watchpoints, the watchpoints_triggered function has
5367 checked all locations already. */
5368 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5371 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5374 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5377 /* Come here if it's a watchpoint, or if the break address
5380 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5383 /* Assume we stop. Should we find a watchpoint that is not
5384 actually triggered, or if the condition of the breakpoint
5385 evaluates as false, we'll reset 'stop' to 0. */
5389 /* If this is a scope breakpoint, mark the associated
5390 watchpoint as triggered so that we will handle the
5391 out-of-scope event. We'll get to the watchpoint next
5393 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5395 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5397 w
->watchpoint_triggered
= watch_triggered_yes
;
5402 /* Check if a moribund breakpoint explains the stop. */
5403 if (!target_supports_stopped_by_sw_breakpoint ()
5404 || !target_supports_stopped_by_hw_breakpoint ())
5406 for (bp_location
*loc
: moribund_locations
)
5408 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5409 && need_moribund_for_location_type (loc
))
5411 bpstat bs
= new bpstats (loc
, &bs_link
);
5412 /* For hits of moribund locations, we should just proceed. */
5415 bs
->print_it
= print_it_noop
;
5423 /* See breakpoint.h. */
5426 bpstat_stop_status (const address_space
*aspace
,
5427 CORE_ADDR bp_addr
, thread_info
*thread
,
5428 const struct target_waitstatus
*ws
,
5431 struct breakpoint
*b
= NULL
;
5432 /* First item of allocated bpstat's. */
5433 bpstat bs_head
= stop_chain
;
5435 int need_remove_insert
;
5438 /* First, build the bpstat chain with locations that explain a
5439 target stop, while being careful to not set the target running,
5440 as that may invalidate locations (in particular watchpoint
5441 locations are recreated). Resuming will happen here with
5442 breakpoint conditions or watchpoint expressions that include
5443 inferior function calls. */
5444 if (bs_head
== NULL
)
5445 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5447 /* A bit of special processing for shlib breakpoints. We need to
5448 process solib loading here, so that the lists of loaded and
5449 unloaded libraries are correct before we handle "catch load" and
5451 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5453 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5455 handle_solib_event ();
5460 /* Now go through the locations that caused the target to stop, and
5461 check whether we're interested in reporting this stop to higher
5462 layers, or whether we should resume the target transparently. */
5466 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5471 b
= bs
->breakpoint_at
;
5472 b
->ops
->check_status (bs
);
5475 bpstat_check_breakpoint_conditions (bs
, thread
);
5481 /* We will stop here. */
5482 if (b
->disposition
== disp_disable
)
5484 --(b
->enable_count
);
5485 if (b
->enable_count
<= 0)
5486 b
->enable_state
= bp_disabled
;
5489 gdb::observers::breakpoint_modified
.notify (b
);
5492 bs
->commands
= b
->commands
;
5493 if (command_line_is_silent (bs
->commands
5494 ? bs
->commands
.get () : NULL
))
5497 b
->ops
->after_condition_true (bs
);
5502 /* Print nothing for this entry if we don't stop or don't
5504 if (!bs
->stop
|| !bs
->print
)
5505 bs
->print_it
= print_it_noop
;
5508 /* If we aren't stopping, the value of some hardware watchpoint may
5509 not have changed, but the intermediate memory locations we are
5510 watching may have. Don't bother if we're stopping; this will get
5512 need_remove_insert
= 0;
5513 if (! bpstat_causes_stop (bs_head
))
5514 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5516 && bs
->breakpoint_at
5517 && is_hardware_watchpoint (bs
->breakpoint_at
))
5519 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5521 update_watchpoint (w
, 0 /* don't reparse. */);
5522 need_remove_insert
= 1;
5525 if (need_remove_insert
)
5526 update_global_location_list (UGLL_MAY_INSERT
);
5527 else if (removed_any
)
5528 update_global_location_list (UGLL_DONT_INSERT
);
5534 handle_jit_event (CORE_ADDR address
)
5536 struct gdbarch
*gdbarch
;
5538 infrun_debug_printf ("handling bp_jit_event");
5540 /* Switch terminal for any messages produced by
5541 breakpoint_re_set. */
5542 target_terminal::ours_for_output ();
5544 gdbarch
= get_frame_arch (get_current_frame ());
5545 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5546 thus it is expected that its objectfile can be found through
5547 minimal symbol lookup. If it doesn't work (and assert fails), it
5548 most likely means that `jit_breakpoint_re_set` was changes and this
5549 function needs to be updated too. */
5550 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5551 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5552 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5554 target_terminal::inferior ();
5557 /* Prepare WHAT final decision for infrun. */
5559 /* Decide what infrun needs to do with this bpstat. */
5562 bpstat_what (bpstat bs_head
)
5564 struct bpstat_what retval
;
5567 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5568 retval
.call_dummy
= STOP_NONE
;
5569 retval
.is_longjmp
= false;
5571 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5573 /* Extract this BS's action. After processing each BS, we check
5574 if its action overrides all we've seem so far. */
5575 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5578 if (bs
->breakpoint_at
== NULL
)
5580 /* I suspect this can happen if it was a momentary
5581 breakpoint which has since been deleted. */
5585 bptype
= bs
->breakpoint_at
->type
;
5592 case bp_hardware_breakpoint
:
5593 case bp_single_step
:
5596 case bp_shlib_event
:
5600 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5602 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5605 this_action
= BPSTAT_WHAT_SINGLE
;
5608 case bp_hardware_watchpoint
:
5609 case bp_read_watchpoint
:
5610 case bp_access_watchpoint
:
5614 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5616 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5620 /* There was a watchpoint, but we're not stopping.
5621 This requires no further action. */
5625 case bp_longjmp_call_dummy
:
5629 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5630 retval
.is_longjmp
= bptype
!= bp_exception
;
5633 this_action
= BPSTAT_WHAT_SINGLE
;
5635 case bp_longjmp_resume
:
5636 case bp_exception_resume
:
5639 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5640 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5643 this_action
= BPSTAT_WHAT_SINGLE
;
5645 case bp_step_resume
:
5647 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5650 /* It is for the wrong frame. */
5651 this_action
= BPSTAT_WHAT_SINGLE
;
5654 case bp_hp_step_resume
:
5656 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5659 /* It is for the wrong frame. */
5660 this_action
= BPSTAT_WHAT_SINGLE
;
5663 case bp_watchpoint_scope
:
5664 case bp_thread_event
:
5665 case bp_overlay_event
:
5666 case bp_longjmp_master
:
5667 case bp_std_terminate_master
:
5668 case bp_exception_master
:
5669 this_action
= BPSTAT_WHAT_SINGLE
;
5675 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5677 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5681 /* Some catchpoints are implemented with breakpoints.
5682 For those, we need to step over the breakpoint. */
5683 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5684 this_action
= BPSTAT_WHAT_SINGLE
;
5688 this_action
= BPSTAT_WHAT_SINGLE
;
5691 /* Make sure the action is stop (silent or noisy),
5692 so infrun.c pops the dummy frame. */
5693 retval
.call_dummy
= STOP_STACK_DUMMY
;
5694 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5696 case bp_std_terminate
:
5697 /* Make sure the action is stop (silent or noisy),
5698 so infrun.c pops the dummy frame. */
5699 retval
.call_dummy
= STOP_STD_TERMINATE
;
5700 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5703 case bp_fast_tracepoint
:
5704 case bp_static_tracepoint
:
5705 /* Tracepoint hits should not be reported back to GDB, and
5706 if one got through somehow, it should have been filtered
5708 internal_error (__FILE__
, __LINE__
,
5709 _("bpstat_what: tracepoint encountered"));
5711 case bp_gnu_ifunc_resolver
:
5712 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5713 this_action
= BPSTAT_WHAT_SINGLE
;
5715 case bp_gnu_ifunc_resolver_return
:
5716 /* The breakpoint will be removed, execution will restart from the
5717 PC of the former breakpoint. */
5718 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5723 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5725 this_action
= BPSTAT_WHAT_SINGLE
;
5729 internal_error (__FILE__
, __LINE__
,
5730 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5733 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5740 bpstat_run_callbacks (bpstat bs_head
)
5744 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5746 struct breakpoint
*b
= bs
->breakpoint_at
;
5753 handle_jit_event (bs
->bp_location_at
->address
);
5755 case bp_gnu_ifunc_resolver
:
5756 gnu_ifunc_resolver_stop (b
);
5758 case bp_gnu_ifunc_resolver_return
:
5759 gnu_ifunc_resolver_return_stop (b
);
5765 /* See breakpoint.h. */
5768 bpstat_should_step ()
5770 for (breakpoint
*b
: all_breakpoints ())
5771 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5777 /* See breakpoint.h. */
5780 bpstat_causes_stop (bpstat bs
)
5782 for (; bs
!= NULL
; bs
= bs
->next
)
5791 /* Compute a string of spaces suitable to indent the next line
5792 so it starts at the position corresponding to the table column
5793 named COL_NAME in the currently active table of UIOUT. */
5796 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5798 static char wrap_indent
[80];
5799 int i
, total_width
, width
, align
;
5803 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5805 if (strcmp (text
, col_name
) == 0)
5807 gdb_assert (total_width
< sizeof wrap_indent
);
5808 memset (wrap_indent
, ' ', total_width
);
5809 wrap_indent
[total_width
] = 0;
5814 total_width
+= width
+ 1;
5820 /* Determine if the locations of this breakpoint will have their conditions
5821 evaluated by the target, host or a mix of both. Returns the following:
5823 "host": Host evals condition.
5824 "host or target": Host or Target evals condition.
5825 "target": Target evals condition.
5829 bp_condition_evaluator (struct breakpoint
*b
)
5831 char host_evals
= 0;
5832 char target_evals
= 0;
5837 if (!is_breakpoint (b
))
5840 if (gdb_evaluates_breakpoint_condition_p ()
5841 || !target_supports_evaluation_of_breakpoint_conditions ())
5842 return condition_evaluation_host
;
5844 for (bp_location
*bl
: b
->locations ())
5846 if (bl
->cond_bytecode
)
5852 if (host_evals
&& target_evals
)
5853 return condition_evaluation_both
;
5854 else if (target_evals
)
5855 return condition_evaluation_target
;
5857 return condition_evaluation_host
;
5860 /* Determine the breakpoint location's condition evaluator. This is
5861 similar to bp_condition_evaluator, but for locations. */
5864 bp_location_condition_evaluator (struct bp_location
*bl
)
5866 if (bl
&& !is_breakpoint (bl
->owner
))
5869 if (gdb_evaluates_breakpoint_condition_p ()
5870 || !target_supports_evaluation_of_breakpoint_conditions ())
5871 return condition_evaluation_host
;
5873 if (bl
&& bl
->cond_bytecode
)
5874 return condition_evaluation_target
;
5876 return condition_evaluation_host
;
5879 /* Print the LOC location out of the list of B->LOC locations. */
5882 print_breakpoint_location (struct breakpoint
*b
,
5883 struct bp_location
*loc
)
5885 struct ui_out
*uiout
= current_uiout
;
5887 scoped_restore_current_program_space restore_pspace
;
5889 if (loc
!= NULL
&& loc
->shlib_disabled
)
5893 set_current_program_space (loc
->pspace
);
5895 if (b
->display_canonical
)
5896 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5897 else if (loc
&& loc
->symtab
)
5899 const struct symbol
*sym
= loc
->symbol
;
5903 uiout
->text ("in ");
5904 uiout
->field_string ("func", sym
->print_name (),
5905 function_name_style
.style ());
5907 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5908 uiout
->text ("at ");
5910 uiout
->field_string ("file",
5911 symtab_to_filename_for_display (loc
->symtab
),
5912 file_name_style
.style ());
5915 if (uiout
->is_mi_like_p ())
5916 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5918 uiout
->field_signed ("line", loc
->line_number
);
5924 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5926 uiout
->field_stream ("at", stb
);
5930 uiout
->field_string ("pending",
5931 event_location_to_string (b
->location
.get ()));
5932 /* If extra_string is available, it could be holding a condition
5933 or dprintf arguments. In either case, make sure it is printed,
5934 too, but only for non-MI streams. */
5935 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5937 if (b
->type
== bp_dprintf
)
5941 uiout
->text (b
->extra_string
);
5945 if (loc
&& is_breakpoint (b
)
5946 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5947 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5950 uiout
->field_string ("evaluated-by",
5951 bp_location_condition_evaluator (loc
));
5957 bptype_string (enum bptype type
)
5959 struct ep_type_description
5962 const char *description
;
5964 static struct ep_type_description bptypes
[] =
5966 {bp_none
, "?deleted?"},
5967 {bp_breakpoint
, "breakpoint"},
5968 {bp_hardware_breakpoint
, "hw breakpoint"},
5969 {bp_single_step
, "sw single-step"},
5970 {bp_until
, "until"},
5971 {bp_finish
, "finish"},
5972 {bp_watchpoint
, "watchpoint"},
5973 {bp_hardware_watchpoint
, "hw watchpoint"},
5974 {bp_read_watchpoint
, "read watchpoint"},
5975 {bp_access_watchpoint
, "acc watchpoint"},
5976 {bp_longjmp
, "longjmp"},
5977 {bp_longjmp_resume
, "longjmp resume"},
5978 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5979 {bp_exception
, "exception"},
5980 {bp_exception_resume
, "exception resume"},
5981 {bp_step_resume
, "step resume"},
5982 {bp_hp_step_resume
, "high-priority step resume"},
5983 {bp_watchpoint_scope
, "watchpoint scope"},
5984 {bp_call_dummy
, "call dummy"},
5985 {bp_std_terminate
, "std::terminate"},
5986 {bp_shlib_event
, "shlib events"},
5987 {bp_thread_event
, "thread events"},
5988 {bp_overlay_event
, "overlay events"},
5989 {bp_longjmp_master
, "longjmp master"},
5990 {bp_std_terminate_master
, "std::terminate master"},
5991 {bp_exception_master
, "exception master"},
5992 {bp_catchpoint
, "catchpoint"},
5993 {bp_tracepoint
, "tracepoint"},
5994 {bp_fast_tracepoint
, "fast tracepoint"},
5995 {bp_static_tracepoint
, "static tracepoint"},
5996 {bp_dprintf
, "dprintf"},
5997 {bp_jit_event
, "jit events"},
5998 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5999 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6002 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6003 || ((int) type
!= bptypes
[(int) type
].type
))
6004 internal_error (__FILE__
, __LINE__
,
6005 _("bptypes table does not describe type #%d."),
6008 return bptypes
[(int) type
].description
;
6011 /* For MI, output a field named 'thread-groups' with a list as the value.
6012 For CLI, prefix the list with the string 'inf'. */
6015 output_thread_groups (struct ui_out
*uiout
,
6016 const char *field_name
,
6017 const std::vector
<int> &inf_nums
,
6020 int is_mi
= uiout
->is_mi_like_p ();
6022 /* For backward compatibility, don't display inferiors in CLI unless
6023 there are several. Always display them for MI. */
6024 if (!is_mi
&& mi_only
)
6027 ui_out_emit_list
list_emitter (uiout
, field_name
);
6029 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6035 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6036 uiout
->field_string (NULL
, mi_group
);
6041 uiout
->text (" inf ");
6045 uiout
->text (plongest (inf_nums
[i
]));
6050 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6051 instead of going via breakpoint_ops::print_one. This makes "maint
6052 info breakpoints" show the software breakpoint locations of
6053 catchpoints, which are considered internal implementation
6057 print_one_breakpoint_location (struct breakpoint
*b
,
6058 struct bp_location
*loc
,
6060 struct bp_location
**last_loc
,
6061 int allflag
, bool raw_loc
)
6063 struct command_line
*l
;
6064 static char bpenables
[] = "nynny";
6066 struct ui_out
*uiout
= current_uiout
;
6067 int header_of_multiple
= 0;
6068 int part_of_multiple
= (loc
!= NULL
);
6069 struct value_print_options opts
;
6071 get_user_print_options (&opts
);
6073 gdb_assert (!loc
|| loc_number
!= 0);
6074 /* See comment in print_one_breakpoint concerning treatment of
6075 breakpoints with single disabled location. */
6078 && (b
->loc
->next
!= NULL
6079 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6080 header_of_multiple
= 1;
6088 if (part_of_multiple
)
6089 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6091 uiout
->field_signed ("number", b
->number
);
6095 if (part_of_multiple
)
6096 uiout
->field_skip ("type");
6098 uiout
->field_string ("type", bptype_string (b
->type
));
6102 if (part_of_multiple
)
6103 uiout
->field_skip ("disp");
6105 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6109 /* For locations that are disabled because of an invalid condition,
6110 display "N*" on CLI, where "*" refers to a footnote below the
6111 table. For MI, simply display a "N" without a footnote. */
6112 const char *N
= (uiout
->is_mi_like_p ()) ? "N" : "N*";
6113 if (part_of_multiple
)
6114 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? N
6115 : (loc
->enabled
? "y" : "n")));
6117 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6120 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6121 b
->ops
->print_one (b
, last_loc
);
6124 if (is_watchpoint (b
))
6126 struct watchpoint
*w
= (struct watchpoint
*) b
;
6128 /* Field 4, the address, is omitted (which makes the columns
6129 not line up too nicely with the headers, but the effect
6130 is relatively readable). */
6131 if (opts
.addressprint
)
6132 uiout
->field_skip ("addr");
6134 uiout
->field_string ("what", w
->exp_string
);
6136 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6137 || is_ada_exception_catchpoint (b
))
6139 if (opts
.addressprint
)
6142 if (header_of_multiple
)
6143 uiout
->field_string ("addr", "<MULTIPLE>",
6144 metadata_style
.style ());
6145 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6146 uiout
->field_string ("addr", "<PENDING>",
6147 metadata_style
.style ());
6149 uiout
->field_core_addr ("addr",
6150 loc
->gdbarch
, loc
->address
);
6153 if (!header_of_multiple
)
6154 print_breakpoint_location (b
, loc
);
6160 if (loc
!= NULL
&& !header_of_multiple
)
6162 std::vector
<int> inf_nums
;
6165 for (inferior
*inf
: all_inferiors ())
6167 if (inf
->pspace
== loc
->pspace
)
6168 inf_nums
.push_back (inf
->num
);
6171 /* For backward compatibility, don't display inferiors in CLI unless
6172 there are several. Always display for MI. */
6174 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6175 && (program_spaces
.size () > 1
6176 || number_of_inferiors () > 1)
6177 /* LOC is for existing B, it cannot be in
6178 moribund_locations and thus having NULL OWNER. */
6179 && loc
->owner
->type
!= bp_catchpoint
))
6181 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6184 if (!part_of_multiple
)
6186 if (b
->thread
!= -1)
6188 /* FIXME: This seems to be redundant and lost here; see the
6189 "stop only in" line a little further down. */
6190 uiout
->text (" thread ");
6191 uiout
->field_signed ("thread", b
->thread
);
6193 else if (b
->task
!= 0)
6195 uiout
->text (" task ");
6196 uiout
->field_signed ("task", b
->task
);
6202 if (!part_of_multiple
)
6203 b
->ops
->print_one_detail (b
, uiout
);
6205 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6208 uiout
->text ("\tstop only in stack frame at ");
6209 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6211 uiout
->field_core_addr ("frame",
6212 b
->gdbarch
, b
->frame_id
.stack_addr
);
6216 if (!part_of_multiple
&& b
->cond_string
)
6219 if (is_tracepoint (b
))
6220 uiout
->text ("\ttrace only if ");
6222 uiout
->text ("\tstop only if ");
6223 uiout
->field_string ("cond", b
->cond_string
);
6225 /* Print whether the target is doing the breakpoint's condition
6226 evaluation. If GDB is doing the evaluation, don't print anything. */
6227 if (is_breakpoint (b
)
6228 && breakpoint_condition_evaluation_mode ()
6229 == condition_evaluation_target
)
6231 uiout
->message (" (%pF evals)",
6232 string_field ("evaluated-by",
6233 bp_condition_evaluator (b
)));
6238 if (!part_of_multiple
&& b
->thread
!= -1)
6240 /* FIXME should make an annotation for this. */
6241 uiout
->text ("\tstop only in thread ");
6242 if (uiout
->is_mi_like_p ())
6243 uiout
->field_signed ("thread", b
->thread
);
6246 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6248 uiout
->field_string ("thread", print_thread_id (thr
));
6253 if (!part_of_multiple
)
6257 /* FIXME should make an annotation for this. */
6258 if (is_catchpoint (b
))
6259 uiout
->text ("\tcatchpoint");
6260 else if (is_tracepoint (b
))
6261 uiout
->text ("\ttracepoint");
6263 uiout
->text ("\tbreakpoint");
6264 uiout
->text (" already hit ");
6265 uiout
->field_signed ("times", b
->hit_count
);
6266 if (b
->hit_count
== 1)
6267 uiout
->text (" time\n");
6269 uiout
->text (" times\n");
6273 /* Output the count also if it is zero, but only if this is mi. */
6274 if (uiout
->is_mi_like_p ())
6275 uiout
->field_signed ("times", b
->hit_count
);
6279 if (!part_of_multiple
&& b
->ignore_count
)
6282 uiout
->message ("\tignore next %pF hits\n",
6283 signed_field ("ignore", b
->ignore_count
));
6286 /* Note that an enable count of 1 corresponds to "enable once"
6287 behavior, which is reported by the combination of enablement and
6288 disposition, so we don't need to mention it here. */
6289 if (!part_of_multiple
&& b
->enable_count
> 1)
6292 uiout
->text ("\tdisable after ");
6293 /* Tweak the wording to clarify that ignore and enable counts
6294 are distinct, and have additive effect. */
6295 if (b
->ignore_count
)
6296 uiout
->text ("additional ");
6298 uiout
->text ("next ");
6299 uiout
->field_signed ("enable", b
->enable_count
);
6300 uiout
->text (" hits\n");
6303 if (!part_of_multiple
&& is_tracepoint (b
))
6305 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6307 if (tp
->traceframe_usage
)
6309 uiout
->text ("\ttrace buffer usage ");
6310 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6311 uiout
->text (" bytes\n");
6315 l
= b
->commands
? b
->commands
.get () : NULL
;
6316 if (!part_of_multiple
&& l
)
6319 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6320 print_command_lines (uiout
, l
, 4);
6323 if (is_tracepoint (b
))
6325 struct tracepoint
*t
= (struct tracepoint
*) b
;
6327 if (!part_of_multiple
&& t
->pass_count
)
6329 annotate_field (10);
6330 uiout
->text ("\tpass count ");
6331 uiout
->field_signed ("pass", t
->pass_count
);
6332 uiout
->text (" \n");
6335 /* Don't display it when tracepoint or tracepoint location is
6337 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6339 annotate_field (11);
6341 if (uiout
->is_mi_like_p ())
6342 uiout
->field_string ("installed",
6343 loc
->inserted
? "y" : "n");
6349 uiout
->text ("\tnot ");
6350 uiout
->text ("installed on target\n");
6355 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6357 if (is_watchpoint (b
))
6359 struct watchpoint
*w
= (struct watchpoint
*) b
;
6361 uiout
->field_string ("original-location", w
->exp_string
);
6363 else if (b
->location
!= NULL
6364 && event_location_to_string (b
->location
.get ()) != NULL
)
6365 uiout
->field_string ("original-location",
6366 event_location_to_string (b
->location
.get ()));
6370 /* See breakpoint.h. */
6372 bool fix_multi_location_breakpoint_output_globally
= false;
6375 print_one_breakpoint (struct breakpoint
*b
,
6376 struct bp_location
**last_loc
,
6379 struct ui_out
*uiout
= current_uiout
;
6380 bool use_fixed_output
6381 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6382 || fix_multi_location_breakpoint_output_globally
);
6384 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6385 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6387 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6389 if (!use_fixed_output
)
6390 bkpt_tuple_emitter
.reset ();
6392 /* If this breakpoint has custom print function,
6393 it's already printed. Otherwise, print individual
6394 locations, if any. */
6396 || b
->ops
->print_one
== NULL
6399 /* If breakpoint has a single location that is disabled, we
6400 print it as if it had several locations, since otherwise it's
6401 hard to represent "breakpoint enabled, location disabled"
6404 Note that while hardware watchpoints have several locations
6405 internally, that's not a property exposed to users.
6407 Likewise, while catchpoints may be implemented with
6408 breakpoints (e.g., catch throw), that's not a property
6409 exposed to users. We do however display the internal
6410 breakpoint locations with "maint info breakpoints". */
6411 if (!is_hardware_watchpoint (b
)
6412 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6413 || is_ada_exception_catchpoint (b
))
6415 || (b
->loc
&& (b
->loc
->next
6417 || b
->loc
->disabled_by_cond
))))
6419 gdb::optional
<ui_out_emit_list
> locations_list
;
6421 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6422 MI record. For later versions, place breakpoint locations in a
6424 if (uiout
->is_mi_like_p () && use_fixed_output
)
6425 locations_list
.emplace (uiout
, "locations");
6428 for (bp_location
*loc
: b
->locations ())
6430 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6431 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6440 breakpoint_address_bits (struct breakpoint
*b
)
6442 int print_address_bits
= 0;
6444 /* Software watchpoints that aren't watching memory don't have an
6445 address to print. */
6446 if (is_no_memory_software_watchpoint (b
))
6449 for (bp_location
*loc
: b
->locations ())
6453 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6454 if (addr_bit
> print_address_bits
)
6455 print_address_bits
= addr_bit
;
6458 return print_address_bits
;
6461 /* See breakpoint.h. */
6464 print_breakpoint (breakpoint
*b
)
6466 struct bp_location
*dummy_loc
= NULL
;
6467 print_one_breakpoint (b
, &dummy_loc
, 0);
6470 /* Return true if this breakpoint was set by the user, false if it is
6471 internal or momentary. */
6474 user_breakpoint_p (struct breakpoint
*b
)
6476 return b
->number
> 0;
6479 /* See breakpoint.h. */
6482 pending_breakpoint_p (struct breakpoint
*b
)
6484 return b
->loc
== NULL
;
6487 /* Print information on breakpoints (including watchpoints and tracepoints).
6489 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6490 understood by number_or_range_parser. Only breakpoints included in this
6491 list are then printed.
6493 If SHOW_INTERNAL is true, print internal breakpoints.
6495 If FILTER is non-NULL, call it on each breakpoint and only include the
6496 ones for which it returns true.
6498 Return the total number of breakpoints listed. */
6501 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6502 bool (*filter
) (const struct breakpoint
*))
6504 struct bp_location
*last_loc
= NULL
;
6505 int nr_printable_breakpoints
;
6506 struct value_print_options opts
;
6507 int print_address_bits
= 0;
6508 int print_type_col_width
= 14;
6509 struct ui_out
*uiout
= current_uiout
;
6510 bool has_disabled_by_cond_location
= false;
6512 get_user_print_options (&opts
);
6514 /* Compute the number of rows in the table, as well as the size
6515 required for address fields. */
6516 nr_printable_breakpoints
= 0;
6517 for (breakpoint
*b
: all_breakpoints ())
6519 /* If we have a filter, only list the breakpoints it accepts. */
6520 if (filter
&& !filter (b
))
6523 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6524 accept. Skip the others. */
6525 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6527 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6529 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6533 if (show_internal
|| user_breakpoint_p (b
))
6535 int addr_bit
, type_len
;
6537 addr_bit
= breakpoint_address_bits (b
);
6538 if (addr_bit
> print_address_bits
)
6539 print_address_bits
= addr_bit
;
6541 type_len
= strlen (bptype_string (b
->type
));
6542 if (type_len
> print_type_col_width
)
6543 print_type_col_width
= type_len
;
6545 nr_printable_breakpoints
++;
6550 ui_out_emit_table
table_emitter (uiout
,
6551 opts
.addressprint
? 6 : 5,
6552 nr_printable_breakpoints
,
6555 if (nr_printable_breakpoints
> 0)
6556 annotate_breakpoints_headers ();
6557 if (nr_printable_breakpoints
> 0)
6559 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6560 if (nr_printable_breakpoints
> 0)
6562 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6563 if (nr_printable_breakpoints
> 0)
6565 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6566 if (nr_printable_breakpoints
> 0)
6568 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6569 if (opts
.addressprint
)
6571 if (nr_printable_breakpoints
> 0)
6573 if (print_address_bits
<= 32)
6574 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6576 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6578 if (nr_printable_breakpoints
> 0)
6580 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6581 uiout
->table_body ();
6582 if (nr_printable_breakpoints
> 0)
6583 annotate_breakpoints_table ();
6585 for (breakpoint
*b
: all_breakpoints ())
6588 /* If we have a filter, only list the breakpoints it accepts. */
6589 if (filter
&& !filter (b
))
6592 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6593 accept. Skip the others. */
6595 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6597 if (show_internal
) /* maintenance info breakpoint */
6599 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6602 else /* all others */
6604 if (!number_is_in_list (bp_num_list
, b
->number
))
6608 /* We only print out user settable breakpoints unless the
6609 show_internal is set. */
6610 if (show_internal
|| user_breakpoint_p (b
))
6612 print_one_breakpoint (b
, &last_loc
, show_internal
);
6613 for (bp_location
*loc
: b
->locations ())
6614 if (loc
->disabled_by_cond
)
6615 has_disabled_by_cond_location
= true;
6620 if (nr_printable_breakpoints
== 0)
6622 /* If there's a filter, let the caller decide how to report
6626 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6627 uiout
->message ("No breakpoints or watchpoints.\n");
6629 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6635 if (last_loc
&& !server_command
)
6636 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6638 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6639 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6643 /* FIXME? Should this be moved up so that it is only called when
6644 there have been breakpoints? */
6645 annotate_breakpoints_table_end ();
6647 return nr_printable_breakpoints
;
6650 /* Display the value of default-collect in a way that is generally
6651 compatible with the breakpoint list. */
6654 default_collect_info (void)
6656 struct ui_out
*uiout
= current_uiout
;
6658 /* If it has no value (which is frequently the case), say nothing; a
6659 message like "No default-collect." gets in user's face when it's
6661 if (!*default_collect
)
6664 /* The following phrase lines up nicely with per-tracepoint collect
6666 uiout
->text ("default collect ");
6667 uiout
->field_string ("default-collect", default_collect
);
6668 uiout
->text (" \n");
6672 info_breakpoints_command (const char *args
, int from_tty
)
6674 breakpoint_1 (args
, false, NULL
);
6676 default_collect_info ();
6680 info_watchpoints_command (const char *args
, int from_tty
)
6682 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6683 struct ui_out
*uiout
= current_uiout
;
6685 if (num_printed
== 0)
6687 if (args
== NULL
|| *args
== '\0')
6688 uiout
->message ("No watchpoints.\n");
6690 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6695 maintenance_info_breakpoints (const char *args
, int from_tty
)
6697 breakpoint_1 (args
, true, NULL
);
6699 default_collect_info ();
6703 breakpoint_has_pc (struct breakpoint
*b
,
6704 struct program_space
*pspace
,
6705 CORE_ADDR pc
, struct obj_section
*section
)
6707 for (bp_location
*bl
: b
->locations ())
6709 if (bl
->pspace
== pspace
6710 && bl
->address
== pc
6711 && (!overlay_debugging
|| bl
->section
== section
))
6717 /* Print a message describing any user-breakpoints set at PC. This
6718 concerns with logical breakpoints, so we match program spaces, not
6722 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6723 struct program_space
*pspace
, CORE_ADDR pc
,
6724 struct obj_section
*section
, int thread
)
6728 for (breakpoint
*b
: all_breakpoints ())
6729 others
+= (user_breakpoint_p (b
)
6730 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6735 printf_filtered (_("Note: breakpoint "));
6736 else /* if (others == ???) */
6737 printf_filtered (_("Note: breakpoints "));
6738 for (breakpoint
*b
: all_breakpoints ())
6739 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6742 printf_filtered ("%d", b
->number
);
6743 if (b
->thread
== -1 && thread
!= -1)
6744 printf_filtered (" (all threads)");
6745 else if (b
->thread
!= -1)
6746 printf_filtered (" (thread %d)", b
->thread
);
6747 printf_filtered ("%s%s ",
6748 ((b
->enable_state
== bp_disabled
6749 || b
->enable_state
== bp_call_disabled
)
6753 : ((others
== 1) ? " and" : ""));
6755 current_uiout
->message (_("also set at pc %ps.\n"),
6756 styled_string (address_style
.style (),
6757 paddress (gdbarch
, pc
)));
6762 /* Return true iff it is meaningful to use the address member of LOC.
6763 For some breakpoint types, the locations' address members are
6764 irrelevant and it makes no sense to attempt to compare them to
6765 other addresses (or use them for any other purpose either).
6767 More specifically, software watchpoints and catchpoints that are
6768 not backed by breakpoints always have a zero valued location
6769 address and we don't want to mark breakpoints of any of these types
6770 to be a duplicate of an actual breakpoint location at address
6774 bl_address_is_meaningful (bp_location
*loc
)
6776 return loc
->loc_type
!= bp_loc_other
;
6779 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6780 true if LOC1 and LOC2 represent the same watchpoint location. */
6783 watchpoint_locations_match (struct bp_location
*loc1
,
6784 struct bp_location
*loc2
)
6786 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6787 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6789 /* Both of them must exist. */
6790 gdb_assert (w1
!= NULL
);
6791 gdb_assert (w2
!= NULL
);
6793 /* If the target can evaluate the condition expression in hardware,
6794 then we we need to insert both watchpoints even if they are at
6795 the same place. Otherwise the watchpoint will only trigger when
6796 the condition of whichever watchpoint was inserted evaluates to
6797 true, not giving a chance for GDB to check the condition of the
6798 other watchpoint. */
6800 && target_can_accel_watchpoint_condition (loc1
->address
,
6802 loc1
->watchpoint_type
,
6803 w1
->cond_exp
.get ()))
6805 && target_can_accel_watchpoint_condition (loc2
->address
,
6807 loc2
->watchpoint_type
,
6808 w2
->cond_exp
.get ())))
6811 /* Note that this checks the owner's type, not the location's. In
6812 case the target does not support read watchpoints, but does
6813 support access watchpoints, we'll have bp_read_watchpoint
6814 watchpoints with hw_access locations. Those should be considered
6815 duplicates of hw_read locations. The hw_read locations will
6816 become hw_access locations later. */
6817 return (loc1
->owner
->type
== loc2
->owner
->type
6818 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6819 && loc1
->address
== loc2
->address
6820 && loc1
->length
== loc2
->length
);
6823 /* See breakpoint.h. */
6826 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6827 const address_space
*aspace2
, CORE_ADDR addr2
)
6829 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6830 || aspace1
== aspace2
)
6834 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6835 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6836 matches ASPACE2. On targets that have global breakpoints, the address
6837 space doesn't really matter. */
6840 breakpoint_address_match_range (const address_space
*aspace1
,
6842 int len1
, const address_space
*aspace2
,
6845 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6846 || aspace1
== aspace2
)
6847 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6850 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6851 a ranged breakpoint. In most targets, a match happens only if ASPACE
6852 matches the breakpoint's address space. On targets that have global
6853 breakpoints, the address space doesn't really matter. */
6856 breakpoint_location_address_match (struct bp_location
*bl
,
6857 const address_space
*aspace
,
6860 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6863 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6864 bl
->address
, bl
->length
,
6868 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6869 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6870 match happens only if ASPACE matches the breakpoint's address
6871 space. On targets that have global breakpoints, the address space
6872 doesn't really matter. */
6875 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6876 const address_space
*aspace
,
6877 CORE_ADDR addr
, int len
)
6879 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6880 || bl
->pspace
->aspace
== aspace
)
6882 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6884 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6890 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6891 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6892 true, otherwise returns false. */
6895 tracepoint_locations_match (struct bp_location
*loc1
,
6896 struct bp_location
*loc2
)
6898 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6899 /* Since tracepoint locations are never duplicated with others', tracepoint
6900 locations at the same address of different tracepoints are regarded as
6901 different locations. */
6902 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6907 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6908 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6909 the same location. If SW_HW_BPS_MATCH is true, then software
6910 breakpoint locations and hardware breakpoint locations match,
6911 otherwise they don't. */
6914 breakpoint_locations_match (struct bp_location
*loc1
,
6915 struct bp_location
*loc2
,
6916 bool sw_hw_bps_match
)
6918 int hw_point1
, hw_point2
;
6920 /* Both of them must not be in moribund_locations. */
6921 gdb_assert (loc1
->owner
!= NULL
);
6922 gdb_assert (loc2
->owner
!= NULL
);
6924 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6925 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6927 if (hw_point1
!= hw_point2
)
6930 return watchpoint_locations_match (loc1
, loc2
);
6931 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6932 return tracepoint_locations_match (loc1
, loc2
);
6934 /* We compare bp_location.length in order to cover ranged
6935 breakpoints. Keep this in sync with
6936 bp_location_is_less_than. */
6937 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6938 loc2
->pspace
->aspace
, loc2
->address
)
6939 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
6940 && loc1
->length
== loc2
->length
);
6944 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6945 int bnum
, int have_bnum
)
6947 /* The longest string possibly returned by hex_string_custom
6948 is 50 chars. These must be at least that big for safety. */
6952 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6953 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6955 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6956 bnum
, astr1
, astr2
);
6958 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6961 /* Adjust a breakpoint's address to account for architectural
6962 constraints on breakpoint placement. Return the adjusted address.
6963 Note: Very few targets require this kind of adjustment. For most
6964 targets, this function is simply the identity function. */
6967 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6968 CORE_ADDR bpaddr
, enum bptype bptype
)
6970 if (bptype
== bp_watchpoint
6971 || bptype
== bp_hardware_watchpoint
6972 || bptype
== bp_read_watchpoint
6973 || bptype
== bp_access_watchpoint
6974 || bptype
== bp_catchpoint
)
6976 /* Watchpoints and the various bp_catch_* eventpoints should not
6977 have their addresses modified. */
6980 else if (bptype
== bp_single_step
)
6982 /* Single-step breakpoints should not have their addresses
6983 modified. If there's any architectural constrain that
6984 applies to this address, then it should have already been
6985 taken into account when the breakpoint was created in the
6986 first place. If we didn't do this, stepping through e.g.,
6987 Thumb-2 IT blocks would break. */
6992 CORE_ADDR adjusted_bpaddr
= bpaddr
;
6994 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
6996 /* Some targets have architectural constraints on the placement
6997 of breakpoint instructions. Obtain the adjusted address. */
6998 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7001 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7003 /* An adjusted breakpoint address can significantly alter
7004 a user's expectations. Print a warning if an adjustment
7006 if (adjusted_bpaddr
!= bpaddr
)
7007 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7009 return adjusted_bpaddr
;
7014 bp_location_from_bp_type (bptype type
)
7019 case bp_single_step
:
7023 case bp_longjmp_resume
:
7024 case bp_longjmp_call_dummy
:
7026 case bp_exception_resume
:
7027 case bp_step_resume
:
7028 case bp_hp_step_resume
:
7029 case bp_watchpoint_scope
:
7031 case bp_std_terminate
:
7032 case bp_shlib_event
:
7033 case bp_thread_event
:
7034 case bp_overlay_event
:
7036 case bp_longjmp_master
:
7037 case bp_std_terminate_master
:
7038 case bp_exception_master
:
7039 case bp_gnu_ifunc_resolver
:
7040 case bp_gnu_ifunc_resolver_return
:
7042 return bp_loc_software_breakpoint
;
7043 case bp_hardware_breakpoint
:
7044 return bp_loc_hardware_breakpoint
;
7045 case bp_hardware_watchpoint
:
7046 case bp_read_watchpoint
:
7047 case bp_access_watchpoint
:
7048 return bp_loc_hardware_watchpoint
;
7052 case bp_fast_tracepoint
:
7053 case bp_static_tracepoint
:
7054 return bp_loc_other
;
7056 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7060 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7062 this->owner
= owner
;
7063 this->cond_bytecode
= NULL
;
7064 this->shlib_disabled
= 0;
7066 this->disabled_by_cond
= false;
7068 this->loc_type
= type
;
7070 if (this->loc_type
== bp_loc_software_breakpoint
7071 || this->loc_type
== bp_loc_hardware_breakpoint
)
7072 mark_breakpoint_location_modified (this);
7077 bp_location::bp_location (breakpoint
*owner
)
7078 : bp_location::bp_location (owner
,
7079 bp_location_from_bp_type (owner
->type
))
7083 /* Allocate a struct bp_location. */
7085 static struct bp_location
*
7086 allocate_bp_location (struct breakpoint
*bpt
)
7088 return bpt
->ops
->allocate_location (bpt
);
7091 /* Decrement reference count. If the reference count reaches 0,
7092 destroy the bp_location. Sets *BLP to NULL. */
7095 decref_bp_location (struct bp_location
**blp
)
7097 bp_location_ref_policy::decref (*blp
);
7101 /* Add breakpoint B at the end of the global breakpoint chain. */
7104 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7106 struct breakpoint
*b1
;
7107 struct breakpoint
*result
= b
.get ();
7109 /* Add this breakpoint to the end of the chain so that a list of
7110 breakpoints will come out in order of increasing numbers. */
7112 b1
= breakpoint_chain
;
7114 breakpoint_chain
= b
.release ();
7119 b1
->next
= b
.release ();
7125 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7128 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7129 struct gdbarch
*gdbarch
,
7131 const struct breakpoint_ops
*ops
)
7133 gdb_assert (ops
!= NULL
);
7137 b
->gdbarch
= gdbarch
;
7138 b
->language
= current_language
->la_language
;
7139 b
->input_radix
= input_radix
;
7140 b
->related_breakpoint
= b
;
7143 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7144 that has type BPTYPE and has no locations as yet. */
7146 static struct breakpoint
*
7147 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7149 const struct breakpoint_ops
*ops
)
7151 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7153 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7154 return add_to_breakpoint_chain (std::move (b
));
7157 /* Initialize loc->function_name. */
7160 set_breakpoint_location_function (struct bp_location
*loc
)
7162 gdb_assert (loc
->owner
!= NULL
);
7164 if (loc
->owner
->type
== bp_breakpoint
7165 || loc
->owner
->type
== bp_hardware_breakpoint
7166 || is_tracepoint (loc
->owner
))
7168 const char *function_name
;
7170 if (loc
->msymbol
!= NULL
7171 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7172 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7174 struct breakpoint
*b
= loc
->owner
;
7176 function_name
= loc
->msymbol
->linkage_name ();
7178 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7179 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7181 /* Create only the whole new breakpoint of this type but do not
7182 mess more complicated breakpoints with multiple locations. */
7183 b
->type
= bp_gnu_ifunc_resolver
;
7184 /* Remember the resolver's address for use by the return
7186 loc
->related_address
= loc
->address
;
7190 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7193 loc
->function_name
= xstrdup (function_name
);
7197 /* Attempt to determine architecture of location identified by SAL. */
7199 get_sal_arch (struct symtab_and_line sal
)
7202 return sal
.section
->objfile
->arch ();
7204 return SYMTAB_OBJFILE (sal
.symtab
)->arch ();
7209 /* Low level routine for partially initializing a breakpoint of type
7210 BPTYPE. The newly created breakpoint's address, section, source
7211 file name, and line number are provided by SAL.
7213 It is expected that the caller will complete the initialization of
7214 the newly created breakpoint struct as well as output any status
7215 information regarding the creation of a new breakpoint. */
7218 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7219 struct symtab_and_line sal
, enum bptype bptype
,
7220 const struct breakpoint_ops
*ops
)
7222 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7224 add_location_to_breakpoint (b
, &sal
);
7226 if (bptype
!= bp_catchpoint
)
7227 gdb_assert (sal
.pspace
!= NULL
);
7229 /* Store the program space that was used to set the breakpoint,
7230 except for ordinary breakpoints, which are independent of the
7232 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7233 b
->pspace
= sal
.pspace
;
7236 /* set_raw_breakpoint is a low level routine for allocating and
7237 partially initializing a breakpoint of type BPTYPE. The newly
7238 created breakpoint's address, section, source file name, and line
7239 number are provided by SAL. The newly created and partially
7240 initialized breakpoint is added to the breakpoint chain and
7241 is also returned as the value of this function.
7243 It is expected that the caller will complete the initialization of
7244 the newly created breakpoint struct as well as output any status
7245 information regarding the creation of a new breakpoint. In
7246 particular, set_raw_breakpoint does NOT set the breakpoint
7247 number! Care should be taken to not allow an error to occur
7248 prior to completing the initialization of the breakpoint. If this
7249 should happen, a bogus breakpoint will be left on the chain. */
7252 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7253 struct symtab_and_line sal
, enum bptype bptype
,
7254 const struct breakpoint_ops
*ops
)
7256 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7258 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7259 return add_to_breakpoint_chain (std::move (b
));
7262 /* Call this routine when stepping and nexting to enable a breakpoint
7263 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7264 initiated the operation. */
7267 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7269 int thread
= tp
->global_num
;
7271 /* To avoid having to rescan all objfile symbols at every step,
7272 we maintain a list of continually-inserted but always disabled
7273 longjmp "master" breakpoints. Here, we simply create momentary
7274 clones of those and enable them for the requested thread. */
7275 for (breakpoint
*b
: all_breakpoints_safe ())
7276 if (b
->pspace
== current_program_space
7277 && (b
->type
== bp_longjmp_master
7278 || b
->type
== bp_exception_master
))
7280 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7281 struct breakpoint
*clone
;
7283 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7284 after their removal. */
7285 clone
= momentary_breakpoint_from_master (b
, type
,
7286 &momentary_breakpoint_ops
, 1);
7287 clone
->thread
= thread
;
7290 tp
->initiating_frame
= frame
;
7293 /* Delete all longjmp breakpoints from THREAD. */
7295 delete_longjmp_breakpoint (int thread
)
7297 for (breakpoint
*b
: all_breakpoints_safe ())
7298 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7300 if (b
->thread
== thread
)
7301 delete_breakpoint (b
);
7306 delete_longjmp_breakpoint_at_next_stop (int thread
)
7308 for (breakpoint
*b
: all_breakpoints_safe ())
7309 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7311 if (b
->thread
== thread
)
7312 b
->disposition
= disp_del_at_next_stop
;
7316 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7317 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7318 pointer to any of them. Return NULL if this system cannot place longjmp
7322 set_longjmp_breakpoint_for_call_dummy (void)
7324 breakpoint
*retval
= nullptr;
7326 for (breakpoint
*b
: all_breakpoints ())
7327 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7329 struct breakpoint
*new_b
;
7331 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7332 &momentary_breakpoint_ops
,
7334 new_b
->thread
= inferior_thread ()->global_num
;
7336 /* Link NEW_B into the chain of RETVAL breakpoints. */
7338 gdb_assert (new_b
->related_breakpoint
== new_b
);
7341 new_b
->related_breakpoint
= retval
;
7342 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7343 retval
= retval
->related_breakpoint
;
7344 retval
->related_breakpoint
= new_b
;
7350 /* Verify all existing dummy frames and their associated breakpoints for
7351 TP. Remove those which can no longer be found in the current frame
7354 If the unwind fails then there is not sufficient information to discard
7355 dummy frames. In this case, elide the clean up and the dummy frames will
7356 be cleaned up next time this function is called from a location where
7357 unwinding is possible. */
7360 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7362 struct breakpoint
*b
, *b_tmp
;
7364 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7365 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7367 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7369 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7370 chained off b->related_breakpoint. */
7371 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7372 dummy_b
= dummy_b
->related_breakpoint
;
7374 /* If there was no bp_call_dummy breakpoint then there's nothing
7375 more to do. Or, if the dummy frame associated with the
7376 bp_call_dummy is still on the stack then we need to leave this
7377 bp_call_dummy in place. */
7378 if (dummy_b
->type
!= bp_call_dummy
7379 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7382 /* We didn't find the dummy frame on the stack, this could be
7383 because we have longjmp'd to a stack frame that is previous to
7384 the dummy frame, or it could be because the stack unwind is
7385 broken at some point between the longjmp frame and the dummy
7388 Next we figure out why the stack unwind stopped. If it looks
7389 like the unwind is complete then we assume the dummy frame has
7390 been jumped over, however, if the unwind stopped for an
7391 unexpected reason then we assume the stack unwind is currently
7392 broken, and that we will (eventually) return to the dummy
7395 It might be tempting to consider using frame_id_inner here, but
7396 that is not safe. There is no guarantee that the stack frames
7397 we are looking at here are even on the same stack as the
7398 original dummy frame, hence frame_id_inner can't be used. See
7399 the comments on frame_id_inner for more details. */
7400 bool unwind_finished_unexpectedly
= false;
7401 for (struct frame_info
*fi
= get_current_frame (); fi
!= nullptr; )
7403 struct frame_info
*prev
= get_prev_frame (fi
);
7404 if (prev
== nullptr)
7406 /* FI is the last stack frame. Why did this frame not
7408 auto stop_reason
= get_frame_unwind_stop_reason (fi
);
7409 if (stop_reason
!= UNWIND_NO_REASON
7410 && stop_reason
!= UNWIND_OUTERMOST
)
7411 unwind_finished_unexpectedly
= true;
7415 if (unwind_finished_unexpectedly
)
7418 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7420 while (b
->related_breakpoint
!= b
)
7422 if (b_tmp
== b
->related_breakpoint
)
7423 b_tmp
= b
->related_breakpoint
->next
;
7424 delete_breakpoint (b
->related_breakpoint
);
7426 delete_breakpoint (b
);
7431 enable_overlay_breakpoints (void)
7433 for (breakpoint
*b
: all_breakpoints ())
7434 if (b
->type
== bp_overlay_event
)
7436 b
->enable_state
= bp_enabled
;
7437 update_global_location_list (UGLL_MAY_INSERT
);
7438 overlay_events_enabled
= 1;
7443 disable_overlay_breakpoints (void)
7445 for (breakpoint
*b
: all_breakpoints ())
7446 if (b
->type
== bp_overlay_event
)
7448 b
->enable_state
= bp_disabled
;
7449 update_global_location_list (UGLL_DONT_INSERT
);
7450 overlay_events_enabled
= 0;
7454 /* Set an active std::terminate breakpoint for each std::terminate
7455 master breakpoint. */
7457 set_std_terminate_breakpoint (void)
7459 for (breakpoint
*b
: all_breakpoints_safe ())
7460 if (b
->pspace
== current_program_space
7461 && b
->type
== bp_std_terminate_master
)
7463 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7464 &momentary_breakpoint_ops
, 1);
7468 /* Delete all the std::terminate breakpoints. */
7470 delete_std_terminate_breakpoint (void)
7472 for (breakpoint
*b
: all_breakpoints_safe ())
7473 if (b
->type
== bp_std_terminate
)
7474 delete_breakpoint (b
);
7478 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7480 struct breakpoint
*b
;
7482 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7483 &internal_breakpoint_ops
);
7485 b
->enable_state
= bp_enabled
;
7486 /* location has to be used or breakpoint_re_set will delete me. */
7487 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7489 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7494 struct lang_and_radix
7500 /* Create a breakpoint for JIT code registration and unregistration. */
7503 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7505 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7506 &internal_breakpoint_ops
);
7509 /* Remove JIT code registration and unregistration breakpoint(s). */
7512 remove_jit_event_breakpoints (void)
7514 for (breakpoint
*b
: all_breakpoints_safe ())
7515 if (b
->type
== bp_jit_event
7516 && b
->loc
->pspace
== current_program_space
)
7517 delete_breakpoint (b
);
7521 remove_solib_event_breakpoints (void)
7523 for (breakpoint
*b
: all_breakpoints_safe ())
7524 if (b
->type
== bp_shlib_event
7525 && b
->loc
->pspace
== current_program_space
)
7526 delete_breakpoint (b
);
7529 /* See breakpoint.h. */
7532 remove_solib_event_breakpoints_at_next_stop (void)
7534 for (breakpoint
*b
: all_breakpoints_safe ())
7535 if (b
->type
== bp_shlib_event
7536 && b
->loc
->pspace
== current_program_space
)
7537 b
->disposition
= disp_del_at_next_stop
;
7540 /* Helper for create_solib_event_breakpoint /
7541 create_and_insert_solib_event_breakpoint. Allows specifying which
7542 INSERT_MODE to pass through to update_global_location_list. */
7544 static struct breakpoint
*
7545 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7546 enum ugll_insert_mode insert_mode
)
7548 struct breakpoint
*b
;
7550 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7551 &internal_breakpoint_ops
);
7552 update_global_location_list_nothrow (insert_mode
);
7557 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7559 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7562 /* See breakpoint.h. */
7565 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7567 struct breakpoint
*b
;
7569 /* Explicitly tell update_global_location_list to insert
7571 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7572 if (!b
->loc
->inserted
)
7574 delete_breakpoint (b
);
7580 /* Disable any breakpoints that are on code in shared libraries. Only
7581 apply to enabled breakpoints, disabled ones can just stay disabled. */
7584 disable_breakpoints_in_shlibs (void)
7586 for (bp_location
*loc
: all_bp_locations ())
7588 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7589 struct breakpoint
*b
= loc
->owner
;
7591 /* We apply the check to all breakpoints, including disabled for
7592 those with loc->duplicate set. This is so that when breakpoint
7593 becomes enabled, or the duplicate is removed, gdb will try to
7594 insert all breakpoints. If we don't set shlib_disabled here,
7595 we'll try to insert those breakpoints and fail. */
7596 if (((b
->type
== bp_breakpoint
)
7597 || (b
->type
== bp_jit_event
)
7598 || (b
->type
== bp_hardware_breakpoint
)
7599 || (is_tracepoint (b
)))
7600 && loc
->pspace
== current_program_space
7601 && !loc
->shlib_disabled
7602 && solib_name_from_address (loc
->pspace
, loc
->address
)
7605 loc
->shlib_disabled
= 1;
7610 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7611 notification of unloaded_shlib. Only apply to enabled breakpoints,
7612 disabled ones can just stay disabled. */
7615 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7617 int disabled_shlib_breaks
= 0;
7619 for (bp_location
*loc
: all_bp_locations ())
7621 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7622 struct breakpoint
*b
= loc
->owner
;
7624 if (solib
->pspace
== loc
->pspace
7625 && !loc
->shlib_disabled
7626 && (((b
->type
== bp_breakpoint
7627 || b
->type
== bp_jit_event
7628 || b
->type
== bp_hardware_breakpoint
)
7629 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7630 || loc
->loc_type
== bp_loc_software_breakpoint
))
7631 || is_tracepoint (b
))
7632 && solib_contains_address_p (solib
, loc
->address
))
7634 loc
->shlib_disabled
= 1;
7635 /* At this point, we cannot rely on remove_breakpoint
7636 succeeding so we must mark the breakpoint as not inserted
7637 to prevent future errors occurring in remove_breakpoints. */
7640 /* This may cause duplicate notifications for the same breakpoint. */
7641 gdb::observers::breakpoint_modified
.notify (b
);
7643 if (!disabled_shlib_breaks
)
7645 target_terminal::ours_for_output ();
7646 warning (_("Temporarily disabling breakpoints "
7647 "for unloaded shared library \"%s\""),
7650 disabled_shlib_breaks
= 1;
7655 /* Disable any breakpoints and tracepoints in OBJFILE upon
7656 notification of free_objfile. Only apply to enabled breakpoints,
7657 disabled ones can just stay disabled. */
7660 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7662 if (objfile
== NULL
)
7665 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7666 managed by the user with add-symbol-file/remove-symbol-file.
7667 Similarly to how breakpoints in shared libraries are handled in
7668 response to "nosharedlibrary", mark breakpoints in such modules
7669 shlib_disabled so they end up uninserted on the next global
7670 location list update. Shared libraries not loaded by the user
7671 aren't handled here -- they're already handled in
7672 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7673 solib_unloaded observer. We skip objfiles that are not
7674 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7676 if ((objfile
->flags
& OBJF_SHARED
) == 0
7677 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7680 for (breakpoint
*b
: all_breakpoints ())
7682 int bp_modified
= 0;
7684 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7687 for (bp_location
*loc
: b
->locations ())
7689 CORE_ADDR loc_addr
= loc
->address
;
7691 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7692 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7695 if (loc
->shlib_disabled
!= 0)
7698 if (objfile
->pspace
!= loc
->pspace
)
7701 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7702 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7705 if (is_addr_in_objfile (loc_addr
, objfile
))
7707 loc
->shlib_disabled
= 1;
7708 /* At this point, we don't know whether the object was
7709 unmapped from the inferior or not, so leave the
7710 inserted flag alone. We'll handle failure to
7711 uninsert quietly, in case the object was indeed
7714 mark_breakpoint_location_modified (loc
);
7721 gdb::observers::breakpoint_modified
.notify (b
);
7725 /* FORK & VFORK catchpoints. */
7727 /* An instance of this type is used to represent a fork or vfork
7728 catchpoint. A breakpoint is really of this type iff its ops pointer points
7729 to CATCH_FORK_BREAKPOINT_OPS. */
7731 struct fork_catchpoint
: public breakpoint
7733 /* Process id of a child process whose forking triggered this
7734 catchpoint. This field is only valid immediately after this
7735 catchpoint has triggered. */
7736 ptid_t forked_inferior_pid
;
7739 /* Implement the "insert" breakpoint_ops method for fork
7743 insert_catch_fork (struct bp_location
*bl
)
7745 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7748 /* Implement the "remove" breakpoint_ops method for fork
7752 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7754 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7757 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7761 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7762 const address_space
*aspace
, CORE_ADDR bp_addr
,
7763 const struct target_waitstatus
*ws
)
7765 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7767 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7770 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7774 /* Implement the "print_it" breakpoint_ops method for fork
7777 static enum print_stop_action
7778 print_it_catch_fork (bpstat bs
)
7780 struct ui_out
*uiout
= current_uiout
;
7781 struct breakpoint
*b
= bs
->breakpoint_at
;
7782 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7784 annotate_catchpoint (b
->number
);
7785 maybe_print_thread_hit_breakpoint (uiout
);
7786 if (b
->disposition
== disp_del
)
7787 uiout
->text ("Temporary catchpoint ");
7789 uiout
->text ("Catchpoint ");
7790 if (uiout
->is_mi_like_p ())
7792 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7793 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7795 uiout
->field_signed ("bkptno", b
->number
);
7796 uiout
->text (" (forked process ");
7797 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7798 uiout
->text ("), ");
7799 return PRINT_SRC_AND_LOC
;
7802 /* Implement the "print_one" breakpoint_ops method for fork
7806 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7808 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7809 struct value_print_options opts
;
7810 struct ui_out
*uiout
= current_uiout
;
7812 get_user_print_options (&opts
);
7814 /* Field 4, the address, is omitted (which makes the columns not
7815 line up too nicely with the headers, but the effect is relatively
7817 if (opts
.addressprint
)
7818 uiout
->field_skip ("addr");
7820 uiout
->text ("fork");
7821 if (c
->forked_inferior_pid
!= null_ptid
)
7823 uiout
->text (", process ");
7824 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7828 if (uiout
->is_mi_like_p ())
7829 uiout
->field_string ("catch-type", "fork");
7832 /* Implement the "print_mention" breakpoint_ops method for fork
7836 print_mention_catch_fork (struct breakpoint
*b
)
7838 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7841 /* Implement the "print_recreate" breakpoint_ops method for fork
7845 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7847 fprintf_unfiltered (fp
, "catch fork");
7848 print_recreate_thread (b
, fp
);
7851 /* The breakpoint_ops structure to be used in fork catchpoints. */
7853 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7855 /* Implement the "insert" breakpoint_ops method for vfork
7859 insert_catch_vfork (struct bp_location
*bl
)
7861 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7864 /* Implement the "remove" breakpoint_ops method for vfork
7868 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7870 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7873 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7877 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7878 const address_space
*aspace
, CORE_ADDR bp_addr
,
7879 const struct target_waitstatus
*ws
)
7881 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7883 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7886 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7890 /* Implement the "print_it" breakpoint_ops method for vfork
7893 static enum print_stop_action
7894 print_it_catch_vfork (bpstat bs
)
7896 struct ui_out
*uiout
= current_uiout
;
7897 struct breakpoint
*b
= bs
->breakpoint_at
;
7898 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7900 annotate_catchpoint (b
->number
);
7901 maybe_print_thread_hit_breakpoint (uiout
);
7902 if (b
->disposition
== disp_del
)
7903 uiout
->text ("Temporary catchpoint ");
7905 uiout
->text ("Catchpoint ");
7906 if (uiout
->is_mi_like_p ())
7908 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7909 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7911 uiout
->field_signed ("bkptno", b
->number
);
7912 uiout
->text (" (vforked process ");
7913 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7914 uiout
->text ("), ");
7915 return PRINT_SRC_AND_LOC
;
7918 /* Implement the "print_one" breakpoint_ops method for vfork
7922 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7924 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7925 struct value_print_options opts
;
7926 struct ui_out
*uiout
= current_uiout
;
7928 get_user_print_options (&opts
);
7929 /* Field 4, the address, is omitted (which makes the columns not
7930 line up too nicely with the headers, but the effect is relatively
7932 if (opts
.addressprint
)
7933 uiout
->field_skip ("addr");
7935 uiout
->text ("vfork");
7936 if (c
->forked_inferior_pid
!= null_ptid
)
7938 uiout
->text (", process ");
7939 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7943 if (uiout
->is_mi_like_p ())
7944 uiout
->field_string ("catch-type", "vfork");
7947 /* Implement the "print_mention" breakpoint_ops method for vfork
7951 print_mention_catch_vfork (struct breakpoint
*b
)
7953 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7956 /* Implement the "print_recreate" breakpoint_ops method for vfork
7960 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7962 fprintf_unfiltered (fp
, "catch vfork");
7963 print_recreate_thread (b
, fp
);
7966 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7968 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7970 /* An instance of this type is used to represent an solib catchpoint.
7971 A breakpoint is really of this type iff its ops pointer points to
7972 CATCH_SOLIB_BREAKPOINT_OPS. */
7974 struct solib_catchpoint
: public breakpoint
7976 ~solib_catchpoint () override
;
7978 /* True for "catch load", false for "catch unload". */
7981 /* Regular expression to match, if any. COMPILED is only valid when
7982 REGEX is non-NULL. */
7984 std::unique_ptr
<compiled_regex
> compiled
;
7987 solib_catchpoint::~solib_catchpoint ()
7989 xfree (this->regex
);
7993 insert_catch_solib (struct bp_location
*ignore
)
7999 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8005 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8006 const address_space
*aspace
,
8008 const struct target_waitstatus
*ws
)
8010 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8012 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8015 for (breakpoint
*other
: all_breakpoints ())
8017 if (other
== bl
->owner
)
8020 if (other
->type
!= bp_shlib_event
)
8023 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8026 for (bp_location
*other_bl
: other
->locations ())
8028 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8037 check_status_catch_solib (struct bpstats
*bs
)
8039 struct solib_catchpoint
*self
8040 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8044 for (so_list
*iter
: current_program_space
->added_solibs
)
8047 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8053 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
8056 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
8062 bs
->print_it
= print_it_noop
;
8065 static enum print_stop_action
8066 print_it_catch_solib (bpstat bs
)
8068 struct breakpoint
*b
= bs
->breakpoint_at
;
8069 struct ui_out
*uiout
= current_uiout
;
8071 annotate_catchpoint (b
->number
);
8072 maybe_print_thread_hit_breakpoint (uiout
);
8073 if (b
->disposition
== disp_del
)
8074 uiout
->text ("Temporary catchpoint ");
8076 uiout
->text ("Catchpoint ");
8077 uiout
->field_signed ("bkptno", b
->number
);
8079 if (uiout
->is_mi_like_p ())
8080 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8081 print_solib_event (1);
8082 return PRINT_SRC_AND_LOC
;
8086 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8088 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8089 struct value_print_options opts
;
8090 struct ui_out
*uiout
= current_uiout
;
8092 get_user_print_options (&opts
);
8093 /* Field 4, the address, is omitted (which makes the columns not
8094 line up too nicely with the headers, but the effect is relatively
8096 if (opts
.addressprint
)
8099 uiout
->field_skip ("addr");
8107 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8109 msg
= _("load of library");
8114 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8116 msg
= _("unload of library");
8118 uiout
->field_string ("what", msg
);
8120 if (uiout
->is_mi_like_p ())
8121 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8125 print_mention_catch_solib (struct breakpoint
*b
)
8127 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8129 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8130 self
->is_load
? "load" : "unload");
8134 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8136 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8138 fprintf_unfiltered (fp
, "%s %s",
8139 b
->disposition
== disp_del
? "tcatch" : "catch",
8140 self
->is_load
? "load" : "unload");
8142 fprintf_unfiltered (fp
, " %s", self
->regex
);
8143 fprintf_unfiltered (fp
, "\n");
8146 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8148 /* See breakpoint.h. */
8151 add_solib_catchpoint (const char *arg
, bool is_load
, bool is_temp
, bool enabled
)
8153 struct gdbarch
*gdbarch
= get_current_arch ();
8157 arg
= skip_spaces (arg
);
8159 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8163 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8164 _("Invalid regexp")));
8165 c
->regex
= xstrdup (arg
);
8168 c
->is_load
= is_load
;
8169 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8170 &catch_solib_breakpoint_ops
);
8172 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8174 install_breakpoint (0, std::move (c
), 1);
8177 /* A helper function that does all the work for "catch load" and
8181 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8182 struct cmd_list_element
*command
)
8184 const int enabled
= 1;
8185 bool temp
= command
->context () == CATCH_TEMPORARY
;
8187 add_solib_catchpoint (arg
, is_load
, temp
, enabled
);
8191 catch_load_command_1 (const char *arg
, int from_tty
,
8192 struct cmd_list_element
*command
)
8194 catch_load_or_unload (arg
, from_tty
, 1, command
);
8198 catch_unload_command_1 (const char *arg
, int from_tty
,
8199 struct cmd_list_element
*command
)
8201 catch_load_or_unload (arg
, from_tty
, 0, command
);
8204 /* See breakpoint.h. */
8207 init_catchpoint (struct breakpoint
*b
,
8208 struct gdbarch
*gdbarch
, bool temp
,
8209 const char *cond_string
,
8210 const struct breakpoint_ops
*ops
)
8212 symtab_and_line sal
;
8213 sal
.pspace
= current_program_space
;
8215 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8217 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8218 b
->disposition
= temp
? disp_del
: disp_donttouch
;
8222 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8224 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8225 set_breakpoint_number (internal
, b
);
8226 if (is_tracepoint (b
))
8227 set_tracepoint_count (breakpoint_count
);
8230 gdb::observers::breakpoint_created
.notify (b
);
8233 update_global_location_list (UGLL_MAY_INSERT
);
8237 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8238 bool temp
, const char *cond_string
,
8239 const struct breakpoint_ops
*ops
)
8241 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8243 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
, ops
);
8245 c
->forked_inferior_pid
= null_ptid
;
8247 install_breakpoint (0, std::move (c
), 1);
8250 /* Exec catchpoints. */
8252 /* An instance of this type is used to represent an exec catchpoint.
8253 A breakpoint is really of this type iff its ops pointer points to
8254 CATCH_EXEC_BREAKPOINT_OPS. */
8256 struct exec_catchpoint
: public breakpoint
8258 ~exec_catchpoint () override
;
8260 /* Filename of a program whose exec triggered this catchpoint.
8261 This field is only valid immediately after this catchpoint has
8263 char *exec_pathname
;
8266 /* Exec catchpoint destructor. */
8268 exec_catchpoint::~exec_catchpoint ()
8270 xfree (this->exec_pathname
);
8274 insert_catch_exec (struct bp_location
*bl
)
8276 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8280 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8282 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8286 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8287 const address_space
*aspace
, CORE_ADDR bp_addr
,
8288 const struct target_waitstatus
*ws
)
8290 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8292 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8295 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8299 static enum print_stop_action
8300 print_it_catch_exec (bpstat bs
)
8302 struct ui_out
*uiout
= current_uiout
;
8303 struct breakpoint
*b
= bs
->breakpoint_at
;
8304 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8306 annotate_catchpoint (b
->number
);
8307 maybe_print_thread_hit_breakpoint (uiout
);
8308 if (b
->disposition
== disp_del
)
8309 uiout
->text ("Temporary catchpoint ");
8311 uiout
->text ("Catchpoint ");
8312 if (uiout
->is_mi_like_p ())
8314 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8315 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8317 uiout
->field_signed ("bkptno", b
->number
);
8318 uiout
->text (" (exec'd ");
8319 uiout
->field_string ("new-exec", c
->exec_pathname
);
8320 uiout
->text ("), ");
8322 return PRINT_SRC_AND_LOC
;
8326 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8328 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8329 struct value_print_options opts
;
8330 struct ui_out
*uiout
= current_uiout
;
8332 get_user_print_options (&opts
);
8334 /* Field 4, the address, is omitted (which makes the columns
8335 not line up too nicely with the headers, but the effect
8336 is relatively readable). */
8337 if (opts
.addressprint
)
8338 uiout
->field_skip ("addr");
8340 uiout
->text ("exec");
8341 if (c
->exec_pathname
!= NULL
)
8343 uiout
->text (", program \"");
8344 uiout
->field_string ("what", c
->exec_pathname
);
8345 uiout
->text ("\" ");
8348 if (uiout
->is_mi_like_p ())
8349 uiout
->field_string ("catch-type", "exec");
8353 print_mention_catch_exec (struct breakpoint
*b
)
8355 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8358 /* Implement the "print_recreate" breakpoint_ops method for exec
8362 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8364 fprintf_unfiltered (fp
, "catch exec");
8365 print_recreate_thread (b
, fp
);
8368 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8371 hw_breakpoint_used_count (void)
8375 for (breakpoint
*b
: all_breakpoints ())
8376 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8377 for (bp_location
*bl
: b
->locations ())
8379 /* Special types of hardware breakpoints may use more than
8381 i
+= b
->ops
->resources_needed (bl
);
8387 /* Returns the resources B would use if it were a hardware
8391 hw_watchpoint_use_count (struct breakpoint
*b
)
8395 if (!breakpoint_enabled (b
))
8398 for (bp_location
*bl
: b
->locations ())
8400 /* Special types of hardware watchpoints may use more than
8402 i
+= b
->ops
->resources_needed (bl
);
8408 /* Returns the sum the used resources of all hardware watchpoints of
8409 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8410 the sum of the used resources of all hardware watchpoints of other
8411 types _not_ TYPE. */
8414 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8415 enum bptype type
, int *other_type_used
)
8419 *other_type_used
= 0;
8420 for (breakpoint
*b
: all_breakpoints ())
8424 if (!breakpoint_enabled (b
))
8427 if (b
->type
== type
)
8428 i
+= hw_watchpoint_use_count (b
);
8429 else if (is_hardware_watchpoint (b
))
8430 *other_type_used
= 1;
8437 disable_watchpoints_before_interactive_call_start (void)
8439 for (breakpoint
*b
: all_breakpoints ())
8440 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8442 b
->enable_state
= bp_call_disabled
;
8443 update_global_location_list (UGLL_DONT_INSERT
);
8448 enable_watchpoints_after_interactive_call_stop (void)
8450 for (breakpoint
*b
: all_breakpoints ())
8451 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8453 b
->enable_state
= bp_enabled
;
8454 update_global_location_list (UGLL_MAY_INSERT
);
8459 disable_breakpoints_before_startup (void)
8461 current_program_space
->executing_startup
= 1;
8462 update_global_location_list (UGLL_DONT_INSERT
);
8466 enable_breakpoints_after_startup (void)
8468 current_program_space
->executing_startup
= 0;
8469 breakpoint_re_set ();
8472 /* Create a new single-step breakpoint for thread THREAD, with no
8475 static struct breakpoint
*
8476 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8478 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8480 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8481 &momentary_breakpoint_ops
);
8483 b
->disposition
= disp_donttouch
;
8484 b
->frame_id
= null_frame_id
;
8487 gdb_assert (b
->thread
!= 0);
8489 return add_to_breakpoint_chain (std::move (b
));
8492 /* Set a momentary breakpoint of type TYPE at address specified by
8493 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8497 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8498 struct frame_id frame_id
, enum bptype type
)
8500 struct breakpoint
*b
;
8502 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8504 gdb_assert (!frame_id_artificial_p (frame_id
));
8506 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8507 b
->enable_state
= bp_enabled
;
8508 b
->disposition
= disp_donttouch
;
8509 b
->frame_id
= frame_id
;
8511 b
->thread
= inferior_thread ()->global_num
;
8513 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8515 return breakpoint_up (b
);
8518 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8519 The new breakpoint will have type TYPE, use OPS as its
8520 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8522 static struct breakpoint
*
8523 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8525 const struct breakpoint_ops
*ops
,
8528 struct breakpoint
*copy
;
8530 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8531 copy
->loc
= allocate_bp_location (copy
);
8532 set_breakpoint_location_function (copy
->loc
);
8534 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8535 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8536 copy
->loc
->address
= orig
->loc
->address
;
8537 copy
->loc
->section
= orig
->loc
->section
;
8538 copy
->loc
->pspace
= orig
->loc
->pspace
;
8539 copy
->loc
->probe
= orig
->loc
->probe
;
8540 copy
->loc
->line_number
= orig
->loc
->line_number
;
8541 copy
->loc
->symtab
= orig
->loc
->symtab
;
8542 copy
->loc
->enabled
= loc_enabled
;
8543 copy
->frame_id
= orig
->frame_id
;
8544 copy
->thread
= orig
->thread
;
8545 copy
->pspace
= orig
->pspace
;
8547 copy
->enable_state
= bp_enabled
;
8548 copy
->disposition
= disp_donttouch
;
8549 copy
->number
= internal_breakpoint_number
--;
8551 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8555 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8559 clone_momentary_breakpoint (struct breakpoint
*orig
)
8561 /* If there's nothing to clone, then return nothing. */
8565 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8569 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8572 struct symtab_and_line sal
;
8574 sal
= find_pc_line (pc
, 0);
8576 sal
.section
= find_pc_overlay (pc
);
8577 sal
.explicit_pc
= 1;
8579 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8583 /* Tell the user we have just set a breakpoint B. */
8586 mention (struct breakpoint
*b
)
8588 b
->ops
->print_mention (b
);
8589 current_uiout
->text ("\n");
8593 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8595 /* Handle "set breakpoint auto-hw on".
8597 If the explicitly specified breakpoint type is not hardware
8598 breakpoint, check the memory map to see whether the breakpoint
8599 address is in read-only memory.
8601 - location type is not hardware breakpoint, memory is read-only.
8602 We change the type of the location to hardware breakpoint.
8604 - location type is hardware breakpoint, memory is read-write. This
8605 means we've previously made the location hardware one, but then the
8606 memory map changed, so we undo.
8610 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8612 if (automatic_hardware_breakpoints
8613 && bl
->owner
->type
!= bp_hardware_breakpoint
8614 && (bl
->loc_type
== bp_loc_software_breakpoint
8615 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8617 /* When breakpoints are removed, remove_breakpoints will use
8618 location types we've just set here, the only possible problem
8619 is that memory map has changed during running program, but
8620 it's not going to work anyway with current gdb. */
8621 mem_region
*mr
= lookup_mem_region (bl
->address
);
8625 enum bp_loc_type new_type
;
8627 if (mr
->attrib
.mode
!= MEM_RW
)
8628 new_type
= bp_loc_hardware_breakpoint
;
8630 new_type
= bp_loc_software_breakpoint
;
8632 if (new_type
!= bl
->loc_type
)
8634 static bool said
= false;
8636 bl
->loc_type
= new_type
;
8639 fprintf_filtered (gdb_stdout
,
8640 _("Note: automatically using "
8641 "hardware breakpoints for "
8642 "read-only addresses.\n"));
8650 static struct bp_location
*
8651 add_location_to_breakpoint (struct breakpoint
*b
,
8652 const struct symtab_and_line
*sal
)
8654 struct bp_location
*loc
, **tmp
;
8655 CORE_ADDR adjusted_address
;
8656 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8658 if (loc_gdbarch
== NULL
)
8659 loc_gdbarch
= b
->gdbarch
;
8661 /* Adjust the breakpoint's address prior to allocating a location.
8662 Once we call allocate_bp_location(), that mostly uninitialized
8663 location will be placed on the location chain. Adjustment of the
8664 breakpoint may cause target_read_memory() to be called and we do
8665 not want its scan of the location chain to find a breakpoint and
8666 location that's only been partially initialized. */
8667 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8670 /* Sort the locations by their ADDRESS. */
8671 loc
= allocate_bp_location (b
);
8672 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8673 tmp
= &((*tmp
)->next
))
8678 loc
->requested_address
= sal
->pc
;
8679 loc
->address
= adjusted_address
;
8680 loc
->pspace
= sal
->pspace
;
8681 loc
->probe
.prob
= sal
->prob
;
8682 loc
->probe
.objfile
= sal
->objfile
;
8683 gdb_assert (loc
->pspace
!= NULL
);
8684 loc
->section
= sal
->section
;
8685 loc
->gdbarch
= loc_gdbarch
;
8686 loc
->line_number
= sal
->line
;
8687 loc
->symtab
= sal
->symtab
;
8688 loc
->symbol
= sal
->symbol
;
8689 loc
->msymbol
= sal
->msymbol
;
8690 loc
->objfile
= sal
->objfile
;
8692 set_breakpoint_location_function (loc
);
8694 /* While by definition, permanent breakpoints are already present in the
8695 code, we don't mark the location as inserted. Normally one would expect
8696 that GDB could rely on that breakpoint instruction to stop the program,
8697 thus removing the need to insert its own breakpoint, except that executing
8698 the breakpoint instruction can kill the target instead of reporting a
8699 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8700 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8701 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8702 breakpoint be inserted normally results in QEMU knowing about the GDB
8703 breakpoint, and thus trap before the breakpoint instruction is executed.
8704 (If GDB later needs to continue execution past the permanent breakpoint,
8705 it manually increments the PC, thus avoiding executing the breakpoint
8707 if (bp_loc_is_permanent (loc
))
8714 /* Return true if LOC is pointing to a permanent breakpoint,
8715 return false otherwise. */
8718 bp_loc_is_permanent (struct bp_location
*loc
)
8720 gdb_assert (loc
!= NULL
);
8722 /* If we have a non-breakpoint-backed catchpoint or a software
8723 watchpoint, just return 0. We should not attempt to read from
8724 the addresses the locations of these breakpoint types point to.
8725 gdbarch_program_breakpoint_here_p, below, will attempt to read
8727 if (!bl_address_is_meaningful (loc
))
8730 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8731 switch_to_program_space_and_thread (loc
->pspace
);
8732 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8735 /* Build a command list for the dprintf corresponding to the current
8736 settings of the dprintf style options. */
8739 update_dprintf_command_list (struct breakpoint
*b
)
8741 char *dprintf_args
= b
->extra_string
;
8742 char *printf_line
= NULL
;
8747 dprintf_args
= skip_spaces (dprintf_args
);
8749 /* Allow a comma, as it may have terminated a location, but don't
8751 if (*dprintf_args
== ',')
8753 dprintf_args
= skip_spaces (dprintf_args
);
8755 if (*dprintf_args
!= '"')
8756 error (_("Bad format string, missing '\"'."));
8758 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8759 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8760 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8762 if (!dprintf_function
)
8763 error (_("No function supplied for dprintf call"));
8765 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8766 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8771 printf_line
= xstrprintf ("call (void) %s (%s)",
8775 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8777 if (target_can_run_breakpoint_commands ())
8778 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8781 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8782 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8786 internal_error (__FILE__
, __LINE__
,
8787 _("Invalid dprintf style."));
8789 gdb_assert (printf_line
!= NULL
);
8791 /* Manufacture a printf sequence. */
8792 struct command_line
*printf_cmd_line
8793 = new struct command_line (simple_control
, printf_line
);
8794 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8795 command_lines_deleter ()));
8798 /* Update all dprintf commands, making their command lists reflect
8799 current style settings. */
8802 update_dprintf_commands (const char *args
, int from_tty
,
8803 struct cmd_list_element
*c
)
8805 for (breakpoint
*b
: all_breakpoints ())
8806 if (b
->type
== bp_dprintf
)
8807 update_dprintf_command_list (b
);
8810 /* Create a breakpoint with SAL as location. Use LOCATION
8811 as a description of the location, and COND_STRING
8812 as condition expression. If LOCATION is NULL then create an
8813 "address location" from the address in the SAL. */
8816 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8817 gdb::array_view
<const symtab_and_line
> sals
,
8818 event_location_up
&&location
,
8819 gdb::unique_xmalloc_ptr
<char> filter
,
8820 gdb::unique_xmalloc_ptr
<char> cond_string
,
8821 gdb::unique_xmalloc_ptr
<char> extra_string
,
8822 enum bptype type
, enum bpdisp disposition
,
8823 int thread
, int task
, int ignore_count
,
8824 const struct breakpoint_ops
*ops
, int from_tty
,
8825 int enabled
, int internal
, unsigned flags
,
8826 int display_canonical
)
8830 if (type
== bp_hardware_breakpoint
)
8832 int target_resources_ok
;
8834 i
= hw_breakpoint_used_count ();
8835 target_resources_ok
=
8836 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8838 if (target_resources_ok
== 0)
8839 error (_("No hardware breakpoint support in the target."));
8840 else if (target_resources_ok
< 0)
8841 error (_("Hardware breakpoints used exceeds limit."));
8844 gdb_assert (!sals
.empty ());
8846 for (const auto &sal
: sals
)
8848 struct bp_location
*loc
;
8852 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8854 loc_gdbarch
= gdbarch
;
8856 describe_other_breakpoints (loc_gdbarch
,
8857 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8860 if (&sal
== &sals
[0])
8862 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8866 b
->cond_string
= cond_string
.release ();
8867 b
->extra_string
= extra_string
.release ();
8868 b
->ignore_count
= ignore_count
;
8869 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8870 b
->disposition
= disposition
;
8872 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8873 b
->loc
->inserted
= 1;
8875 if (type
== bp_static_tracepoint
)
8877 struct tracepoint
*t
= (struct tracepoint
*) b
;
8878 struct static_tracepoint_marker marker
;
8880 if (strace_marker_p (b
))
8882 /* We already know the marker exists, otherwise, we
8883 wouldn't see a sal for it. */
8885 = &event_location_to_string (b
->location
.get ())[3];
8888 p
= skip_spaces (p
);
8890 endp
= skip_to_space (p
);
8892 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8894 printf_filtered (_("Probed static tracepoint "
8896 t
->static_trace_marker_id
.c_str ());
8898 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8900 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8902 printf_filtered (_("Probed static tracepoint "
8904 t
->static_trace_marker_id
.c_str ());
8907 warning (_("Couldn't determine the static "
8908 "tracepoint marker to probe"));
8915 loc
= add_location_to_breakpoint (b
, &sal
);
8916 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8920 /* Do not set breakpoint locations conditions yet. As locations
8921 are inserted, they get sorted based on their addresses. Let
8922 the list stabilize to have reliable location numbers. */
8924 /* Dynamic printf requires and uses additional arguments on the
8925 command line, otherwise it's an error. */
8926 if (type
== bp_dprintf
)
8928 if (b
->extra_string
)
8929 update_dprintf_command_list (b
);
8931 error (_("Format string required"));
8933 else if (b
->extra_string
)
8934 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8938 /* The order of the locations is now stable. Set the location
8939 condition using the location's number. */
8941 for (bp_location
*loc
: b
->locations ())
8943 if (b
->cond_string
!= nullptr)
8944 set_breakpoint_location_condition (b
->cond_string
, loc
, b
->number
,
8950 b
->display_canonical
= display_canonical
;
8951 if (location
!= NULL
)
8952 b
->location
= std::move (location
);
8954 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8955 b
->filter
= std::move (filter
);
8959 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8960 gdb::array_view
<const symtab_and_line
> sals
,
8961 event_location_up
&&location
,
8962 gdb::unique_xmalloc_ptr
<char> filter
,
8963 gdb::unique_xmalloc_ptr
<char> cond_string
,
8964 gdb::unique_xmalloc_ptr
<char> extra_string
,
8965 enum bptype type
, enum bpdisp disposition
,
8966 int thread
, int task
, int ignore_count
,
8967 const struct breakpoint_ops
*ops
, int from_tty
,
8968 int enabled
, int internal
, unsigned flags
,
8969 int display_canonical
)
8971 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8973 init_breakpoint_sal (b
.get (), gdbarch
,
8974 sals
, std::move (location
),
8976 std::move (cond_string
),
8977 std::move (extra_string
),
8979 thread
, task
, ignore_count
,
8981 enabled
, internal
, flags
,
8984 install_breakpoint (internal
, std::move (b
), 0);
8987 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8988 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8989 value. COND_STRING, if not NULL, specified the condition to be
8990 used for all breakpoints. Essentially the only case where
8991 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8992 function. In that case, it's still not possible to specify
8993 separate conditions for different overloaded functions, so
8994 we take just a single condition string.
8996 NOTE: If the function succeeds, the caller is expected to cleanup
8997 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8998 array contents). If the function fails (error() is called), the
8999 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9000 COND and SALS arrays and each of those arrays contents. */
9003 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9004 struct linespec_result
*canonical
,
9005 gdb::unique_xmalloc_ptr
<char> cond_string
,
9006 gdb::unique_xmalloc_ptr
<char> extra_string
,
9007 enum bptype type
, enum bpdisp disposition
,
9008 int thread
, int task
, int ignore_count
,
9009 const struct breakpoint_ops
*ops
, int from_tty
,
9010 int enabled
, int internal
, unsigned flags
)
9012 if (canonical
->pre_expanded
)
9013 gdb_assert (canonical
->lsals
.size () == 1);
9015 for (const auto &lsal
: canonical
->lsals
)
9017 /* Note that 'location' can be NULL in the case of a plain
9018 'break', without arguments. */
9019 event_location_up location
9020 = (canonical
->location
!= NULL
9021 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9022 gdb::unique_xmalloc_ptr
<char> filter_string
9023 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9025 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9026 std::move (location
),
9027 std::move (filter_string
),
9028 std::move (cond_string
),
9029 std::move (extra_string
),
9031 thread
, task
, ignore_count
, ops
,
9032 from_tty
, enabled
, internal
, flags
,
9033 canonical
->special_display
);
9037 /* Parse LOCATION which is assumed to be a SAL specification possibly
9038 followed by conditionals. On return, SALS contains an array of SAL
9039 addresses found. LOCATION points to the end of the SAL (for
9040 linespec locations).
9042 The array and the line spec strings are allocated on the heap, it is
9043 the caller's responsibility to free them. */
9046 parse_breakpoint_sals (struct event_location
*location
,
9047 struct linespec_result
*canonical
)
9049 struct symtab_and_line cursal
;
9051 if (event_location_type (location
) == LINESPEC_LOCATION
)
9053 const char *spec
= get_linespec_location (location
)->spec_string
;
9057 /* The last displayed codepoint, if it's valid, is our default
9058 breakpoint address. */
9059 if (last_displayed_sal_is_valid ())
9061 /* Set sal's pspace, pc, symtab, and line to the values
9062 corresponding to the last call to print_frame_info.
9063 Be sure to reinitialize LINE with NOTCURRENT == 0
9064 as the breakpoint line number is inappropriate otherwise.
9065 find_pc_line would adjust PC, re-set it back. */
9066 symtab_and_line sal
= get_last_displayed_sal ();
9067 CORE_ADDR pc
= sal
.pc
;
9069 sal
= find_pc_line (pc
, 0);
9071 /* "break" without arguments is equivalent to "break *PC"
9072 where PC is the last displayed codepoint's address. So
9073 make sure to set sal.explicit_pc to prevent GDB from
9074 trying to expand the list of sals to include all other
9075 instances with the same symtab and line. */
9077 sal
.explicit_pc
= 1;
9079 struct linespec_sals lsal
;
9081 lsal
.canonical
= NULL
;
9083 canonical
->lsals
.push_back (std::move (lsal
));
9087 error (_("No default breakpoint address now."));
9091 /* Force almost all breakpoints to be in terms of the
9092 current_source_symtab (which is decode_line_1's default).
9093 This should produce the results we want almost all of the
9094 time while leaving default_breakpoint_* alone.
9096 ObjC: However, don't match an Objective-C method name which
9097 may have a '+' or '-' succeeded by a '['. */
9098 cursal
= get_current_source_symtab_and_line ();
9099 if (last_displayed_sal_is_valid ())
9101 const char *spec
= NULL
;
9103 if (event_location_type (location
) == LINESPEC_LOCATION
)
9104 spec
= get_linespec_location (location
)->spec_string
;
9108 && strchr ("+-", spec
[0]) != NULL
9111 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9112 get_last_displayed_symtab (),
9113 get_last_displayed_line (),
9114 canonical
, NULL
, NULL
);
9119 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9120 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9124 /* Convert each SAL into a real PC. Verify that the PC can be
9125 inserted as a breakpoint. If it can't throw an error. */
9128 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9130 for (auto &sal
: sals
)
9131 resolve_sal_pc (&sal
);
9134 /* Fast tracepoints may have restrictions on valid locations. For
9135 instance, a fast tracepoint using a jump instead of a trap will
9136 likely have to overwrite more bytes than a trap would, and so can
9137 only be placed where the instruction is longer than the jump, or a
9138 multi-instruction sequence does not have a jump into the middle of
9142 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9143 gdb::array_view
<const symtab_and_line
> sals
)
9145 for (const auto &sal
: sals
)
9147 struct gdbarch
*sarch
;
9149 sarch
= get_sal_arch (sal
);
9150 /* We fall back to GDBARCH if there is no architecture
9151 associated with SAL. */
9155 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9156 error (_("May not have a fast tracepoint at %s%s"),
9157 paddress (sarch
, sal
.pc
), msg
.c_str ());
9161 /* Given TOK, a string specification of condition and thread, as
9162 accepted by the 'break' command, extract the condition
9163 string and thread number and set *COND_STRING and *THREAD.
9164 PC identifies the context at which the condition should be parsed.
9165 If no condition is found, *COND_STRING is set to NULL.
9166 If no thread is found, *THREAD is set to -1. */
9169 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9170 char **cond_string
, int *thread
, int *task
,
9173 *cond_string
= NULL
;
9181 const char *end_tok
;
9183 const char *cond_start
= NULL
;
9184 const char *cond_end
= NULL
;
9186 tok
= skip_spaces (tok
);
9188 if ((*tok
== '"' || *tok
== ',') && rest
)
9190 *rest
= savestring (tok
, strlen (tok
));
9194 end_tok
= skip_to_space (tok
);
9196 toklen
= end_tok
- tok
;
9198 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9200 tok
= cond_start
= end_tok
+ 1;
9203 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9205 catch (const gdb_exception_error
&)
9210 tok
= tok
+ strlen (tok
);
9213 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9215 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
9220 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9223 struct thread_info
*thr
;
9226 thr
= parse_thread_id (tok
, &tmptok
);
9228 error (_("Junk after thread keyword."));
9229 *thread
= thr
->global_num
;
9232 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9237 *task
= strtol (tok
, &tmptok
, 0);
9239 error (_("Junk after task keyword."));
9240 if (!valid_task_id (*task
))
9241 error (_("Unknown task %d."), *task
);
9246 *rest
= savestring (tok
, strlen (tok
));
9250 error (_("Junk at end of arguments."));
9254 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
9255 succeeds. The parsed values are written to COND_STRING, THREAD,
9256 TASK, and REST. See the comment of 'find_condition_and_thread'
9257 for the description of these parameters and INPUT. */
9260 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
9261 const char *input
, char **cond_string
,
9262 int *thread
, int *task
, char **rest
)
9264 int num_failures
= 0;
9265 for (auto &sal
: sals
)
9267 char *cond
= nullptr;
9270 char *remaining
= nullptr;
9272 /* Here we want to parse 'arg' to separate condition from thread
9273 number. But because parsing happens in a context and the
9274 contexts of sals might be different, try each until there is
9275 success. Finding one successful parse is sufficient for our
9276 goal. When setting the breakpoint we'll re-parse the
9277 condition in the context of each sal. */
9280 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
9281 &task_id
, &remaining
);
9282 *cond_string
= cond
;
9283 *thread
= thread_id
;
9288 catch (const gdb_exception_error
&e
)
9291 /* If no sal remains, do not continue. */
9292 if (num_failures
== sals
.size ())
9298 /* Decode a static tracepoint marker spec. */
9300 static std::vector
<symtab_and_line
>
9301 decode_static_tracepoint_spec (const char **arg_p
)
9303 const char *p
= &(*arg_p
)[3];
9306 p
= skip_spaces (p
);
9308 endp
= skip_to_space (p
);
9310 std::string
marker_str (p
, endp
- p
);
9312 std::vector
<static_tracepoint_marker
> markers
9313 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9314 if (markers
.empty ())
9315 error (_("No known static tracepoint marker named %s"),
9316 marker_str
.c_str ());
9318 std::vector
<symtab_and_line
> sals
;
9319 sals
.reserve (markers
.size ());
9321 for (const static_tracepoint_marker
&marker
: markers
)
9323 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9324 sal
.pc
= marker
.address
;
9325 sals
.push_back (sal
);
9332 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9333 according to IS_TRACEPOINT. */
9335 static const struct breakpoint_ops
*
9336 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
9341 if (location_type
== PROBE_LOCATION
)
9342 return &tracepoint_probe_breakpoint_ops
;
9344 return &tracepoint_breakpoint_ops
;
9348 if (location_type
== PROBE_LOCATION
)
9349 return &bkpt_probe_breakpoint_ops
;
9351 return &bkpt_breakpoint_ops
;
9355 /* See breakpoint.h. */
9357 const struct breakpoint_ops
*
9358 breakpoint_ops_for_event_location (const struct event_location
*location
,
9361 if (location
!= nullptr)
9362 return breakpoint_ops_for_event_location_type
9363 (event_location_type (location
), is_tracepoint
);
9364 return is_tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
9367 /* See breakpoint.h. */
9370 create_breakpoint (struct gdbarch
*gdbarch
,
9371 struct event_location
*location
,
9372 const char *cond_string
,
9373 int thread
, const char *extra_string
,
9374 bool force_condition
, int parse_extra
,
9375 int tempflag
, enum bptype type_wanted
,
9377 enum auto_boolean pending_break_support
,
9378 const struct breakpoint_ops
*ops
,
9379 int from_tty
, int enabled
, int internal
,
9382 struct linespec_result canonical
;
9385 int prev_bkpt_count
= breakpoint_count
;
9387 gdb_assert (ops
!= NULL
);
9389 /* If extra_string isn't useful, set it to NULL. */
9390 if (extra_string
!= NULL
&& *extra_string
== '\0')
9391 extra_string
= NULL
;
9395 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9397 catch (const gdb_exception_error
&e
)
9399 /* If caller is interested in rc value from parse, set
9401 if (e
.error
== NOT_FOUND_ERROR
)
9403 /* If pending breakpoint support is turned off, throw
9406 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9409 exception_print (gdb_stderr
, e
);
9411 /* If pending breakpoint support is auto query and the user
9412 selects no, then simply return the error code. */
9413 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9414 && !nquery (_("Make %s pending on future shared library load? "),
9415 bptype_string (type_wanted
)))
9418 /* At this point, either the user was queried about setting
9419 a pending breakpoint and selected yes, or pending
9420 breakpoint behavior is on and thus a pending breakpoint
9421 is defaulted on behalf of the user. */
9428 if (!pending
&& canonical
.lsals
.empty ())
9431 /* Resolve all line numbers to PC's and verify that the addresses
9432 are ok for the target. */
9435 for (auto &lsal
: canonical
.lsals
)
9436 breakpoint_sals_to_pc (lsal
.sals
);
9439 /* Fast tracepoints may have additional restrictions on location. */
9440 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9442 for (const auto &lsal
: canonical
.lsals
)
9443 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9446 /* Verify that condition can be parsed, before setting any
9447 breakpoints. Allocate a separate condition expression for each
9451 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9452 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9459 const linespec_sals
&lsal
= canonical
.lsals
[0];
9461 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9462 &cond
, &thread
, &task
, &rest
);
9463 cond_string_copy
.reset (cond
);
9464 extra_string_copy
.reset (rest
);
9468 if (type_wanted
!= bp_dprintf
9469 && extra_string
!= NULL
&& *extra_string
!= '\0')
9470 error (_("Garbage '%s' at end of location"), extra_string
);
9472 /* Check the validity of the condition. We should error out
9473 if the condition is invalid at all of the locations and
9474 if it is not forced. In the PARSE_EXTRA case above, this
9475 check is done when parsing the EXTRA_STRING. */
9476 if (cond_string
!= nullptr && !force_condition
)
9478 int num_failures
= 0;
9479 const linespec_sals
&lsal
= canonical
.lsals
[0];
9480 for (const auto &sal
: lsal
.sals
)
9482 const char *cond
= cond_string
;
9485 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
9486 /* One success is sufficient to keep going. */
9489 catch (const gdb_exception_error
&)
9492 /* If this is the last sal, error out. */
9493 if (num_failures
== lsal
.sals
.size ())
9499 /* Create a private copy of condition string. */
9501 cond_string_copy
.reset (xstrdup (cond_string
));
9502 /* Create a private copy of any extra string. */
9504 extra_string_copy
.reset (xstrdup (extra_string
));
9507 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9508 std::move (cond_string_copy
),
9509 std::move (extra_string_copy
),
9511 tempflag
? disp_del
: disp_donttouch
,
9512 thread
, task
, ignore_count
, ops
,
9513 from_tty
, enabled
, internal
, flags
);
9517 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9519 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9520 b
->location
= copy_event_location (location
);
9523 b
->cond_string
= NULL
;
9526 /* Create a private copy of condition string. */
9527 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9531 /* Create a private copy of any extra string. */
9532 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9533 b
->ignore_count
= ignore_count
;
9534 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9535 b
->condition_not_parsed
= 1;
9536 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9537 if ((type_wanted
!= bp_breakpoint
9538 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9539 b
->pspace
= current_program_space
;
9541 install_breakpoint (internal
, std::move (b
), 0);
9544 if (canonical
.lsals
.size () > 1)
9546 warning (_("Multiple breakpoints were set.\nUse the "
9547 "\"delete\" command to delete unwanted breakpoints."));
9548 prev_breakpoint_count
= prev_bkpt_count
;
9551 update_global_location_list (UGLL_MAY_INSERT
);
9556 /* Set a breakpoint.
9557 ARG is a string describing breakpoint address,
9558 condition, and thread.
9559 FLAG specifies if a breakpoint is hardware on,
9560 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9564 break_command_1 (const char *arg
, int flag
, int from_tty
)
9566 int tempflag
= flag
& BP_TEMPFLAG
;
9567 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9568 ? bp_hardware_breakpoint
9571 event_location_up location
= string_to_event_location (&arg
, current_language
);
9572 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9573 (location
.get (), false /* is_tracepoint */);
9575 create_breakpoint (get_current_arch (),
9577 NULL
, 0, arg
, false, 1 /* parse arg */,
9578 tempflag
, type_wanted
,
9579 0 /* Ignore count */,
9580 pending_break_support
,
9588 /* Helper function for break_command_1 and disassemble_command. */
9591 resolve_sal_pc (struct symtab_and_line
*sal
)
9595 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9597 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9598 error (_("No line %d in file \"%s\"."),
9599 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9602 /* If this SAL corresponds to a breakpoint inserted using a line
9603 number, then skip the function prologue if necessary. */
9604 if (sal
->explicit_line
)
9605 skip_prologue_sal (sal
);
9608 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9610 const struct blockvector
*bv
;
9611 const struct block
*b
;
9614 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9615 SYMTAB_COMPUNIT (sal
->symtab
));
9618 sym
= block_linkage_function (b
);
9621 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9622 sal
->section
= sym
->obj_section (SYMTAB_OBJFILE (sal
->symtab
));
9626 /* It really is worthwhile to have the section, so we'll
9627 just have to look harder. This case can be executed
9628 if we have line numbers but no functions (as can
9629 happen in assembly source). */
9631 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9632 switch_to_program_space_and_thread (sal
->pspace
);
9634 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9636 sal
->section
= msym
.obj_section ();
9643 break_command (const char *arg
, int from_tty
)
9645 break_command_1 (arg
, 0, from_tty
);
9649 tbreak_command (const char *arg
, int from_tty
)
9651 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9655 hbreak_command (const char *arg
, int from_tty
)
9657 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9661 thbreak_command (const char *arg
, int from_tty
)
9663 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9667 stop_command (const char *arg
, int from_tty
)
9669 printf_filtered (_("Specify the type of breakpoint to set.\n\
9670 Usage: stop in <function | address>\n\
9671 stop at <line>\n"));
9675 stopin_command (const char *arg
, int from_tty
)
9681 else if (*arg
!= '*')
9683 const char *argptr
= arg
;
9686 /* Look for a ':'. If this is a line number specification, then
9687 say it is bad, otherwise, it should be an address or
9688 function/method name. */
9689 while (*argptr
&& !hasColon
)
9691 hasColon
= (*argptr
== ':');
9696 badInput
= (*argptr
!= ':'); /* Not a class::method */
9698 badInput
= isdigit (*arg
); /* a simple line number */
9702 printf_filtered (_("Usage: stop in <function | address>\n"));
9704 break_command_1 (arg
, 0, from_tty
);
9708 stopat_command (const char *arg
, int from_tty
)
9712 if (arg
== NULL
|| *arg
== '*') /* no line number */
9716 const char *argptr
= arg
;
9719 /* Look for a ':'. If there is a '::' then get out, otherwise
9720 it is probably a line number. */
9721 while (*argptr
&& !hasColon
)
9723 hasColon
= (*argptr
== ':');
9728 badInput
= (*argptr
== ':'); /* we have class::method */
9730 badInput
= !isdigit (*arg
); /* not a line number */
9734 printf_filtered (_("Usage: stop at LINE\n"));
9736 break_command_1 (arg
, 0, from_tty
);
9739 /* The dynamic printf command is mostly like a regular breakpoint, but
9740 with a prewired command list consisting of a single output command,
9741 built from extra arguments supplied on the dprintf command
9745 dprintf_command (const char *arg
, int from_tty
)
9747 event_location_up location
= string_to_event_location (&arg
, current_language
);
9749 /* If non-NULL, ARG should have been advanced past the location;
9750 the next character must be ','. */
9753 if (arg
[0] != ',' || arg
[1] == '\0')
9754 error (_("Format string required"));
9757 /* Skip the comma. */
9762 create_breakpoint (get_current_arch (),
9764 NULL
, 0, arg
, false, 1 /* parse arg */,
9766 0 /* Ignore count */,
9767 pending_break_support
,
9768 &dprintf_breakpoint_ops
,
9776 agent_printf_command (const char *arg
, int from_tty
)
9778 error (_("May only run agent-printf on the target"));
9781 /* Implement the "breakpoint_hit" breakpoint_ops method for
9782 ranged breakpoints. */
9785 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9786 const address_space
*aspace
,
9788 const struct target_waitstatus
*ws
)
9790 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9791 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9794 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9795 bl
->length
, aspace
, bp_addr
);
9798 /* Implement the "resources_needed" breakpoint_ops method for
9799 ranged breakpoints. */
9802 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9804 return target_ranged_break_num_registers ();
9807 /* Implement the "print_it" breakpoint_ops method for
9808 ranged breakpoints. */
9810 static enum print_stop_action
9811 print_it_ranged_breakpoint (bpstat bs
)
9813 struct breakpoint
*b
= bs
->breakpoint_at
;
9814 struct bp_location
*bl
= b
->loc
;
9815 struct ui_out
*uiout
= current_uiout
;
9817 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9819 /* Ranged breakpoints have only one location. */
9820 gdb_assert (bl
&& bl
->next
== NULL
);
9822 annotate_breakpoint (b
->number
);
9824 maybe_print_thread_hit_breakpoint (uiout
);
9826 if (b
->disposition
== disp_del
)
9827 uiout
->text ("Temporary ranged breakpoint ");
9829 uiout
->text ("Ranged breakpoint ");
9830 if (uiout
->is_mi_like_p ())
9832 uiout
->field_string ("reason",
9833 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9834 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9836 uiout
->field_signed ("bkptno", b
->number
);
9839 return PRINT_SRC_AND_LOC
;
9842 /* Implement the "print_one" breakpoint_ops method for
9843 ranged breakpoints. */
9846 print_one_ranged_breakpoint (struct breakpoint
*b
,
9847 struct bp_location
**last_loc
)
9849 struct bp_location
*bl
= b
->loc
;
9850 struct value_print_options opts
;
9851 struct ui_out
*uiout
= current_uiout
;
9853 /* Ranged breakpoints have only one location. */
9854 gdb_assert (bl
&& bl
->next
== NULL
);
9856 get_user_print_options (&opts
);
9858 if (opts
.addressprint
)
9859 /* We don't print the address range here, it will be printed later
9860 by print_one_detail_ranged_breakpoint. */
9861 uiout
->field_skip ("addr");
9863 print_breakpoint_location (b
, bl
);
9867 /* Implement the "print_one_detail" breakpoint_ops method for
9868 ranged breakpoints. */
9871 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9872 struct ui_out
*uiout
)
9874 CORE_ADDR address_start
, address_end
;
9875 struct bp_location
*bl
= b
->loc
;
9880 address_start
= bl
->address
;
9881 address_end
= address_start
+ bl
->length
- 1;
9883 uiout
->text ("\taddress range: ");
9884 stb
.printf ("[%s, %s]",
9885 print_core_address (bl
->gdbarch
, address_start
),
9886 print_core_address (bl
->gdbarch
, address_end
));
9887 uiout
->field_stream ("addr", stb
);
9891 /* Implement the "print_mention" breakpoint_ops method for
9892 ranged breakpoints. */
9895 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9897 struct bp_location
*bl
= b
->loc
;
9898 struct ui_out
*uiout
= current_uiout
;
9901 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9903 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9904 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9905 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9908 /* Implement the "print_recreate" breakpoint_ops method for
9909 ranged breakpoints. */
9912 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9914 fprintf_unfiltered (fp
, "break-range %s, %s",
9915 event_location_to_string (b
->location
.get ()),
9916 event_location_to_string (b
->location_range_end
.get ()));
9917 print_recreate_thread (b
, fp
);
9920 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9922 static struct breakpoint_ops ranged_breakpoint_ops
;
9924 /* Find the address where the end of the breakpoint range should be
9925 placed, given the SAL of the end of the range. This is so that if
9926 the user provides a line number, the end of the range is set to the
9927 last instruction of the given line. */
9930 find_breakpoint_range_end (struct symtab_and_line sal
)
9934 /* If the user provided a PC value, use it. Otherwise,
9935 find the address of the end of the given location. */
9936 if (sal
.explicit_pc
)
9943 ret
= find_line_pc_range (sal
, &start
, &end
);
9945 error (_("Could not find location of the end of the range."));
9947 /* find_line_pc_range returns the start of the next line. */
9954 /* Implement the "break-range" CLI command. */
9957 break_range_command (const char *arg
, int from_tty
)
9959 const char *arg_start
;
9960 struct linespec_result canonical_start
, canonical_end
;
9961 int bp_count
, can_use_bp
, length
;
9963 struct breakpoint
*b
;
9965 /* We don't support software ranged breakpoints. */
9966 if (target_ranged_break_num_registers () < 0)
9967 error (_("This target does not support hardware ranged breakpoints."));
9969 bp_count
= hw_breakpoint_used_count ();
9970 bp_count
+= target_ranged_break_num_registers ();
9971 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9974 error (_("Hardware breakpoints used exceeds limit."));
9976 arg
= skip_spaces (arg
);
9977 if (arg
== NULL
|| arg
[0] == '\0')
9978 error(_("No address range specified."));
9981 event_location_up start_location
= string_to_event_location (&arg
,
9983 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9986 error (_("Too few arguments."));
9987 else if (canonical_start
.lsals
.empty ())
9988 error (_("Could not find location of the beginning of the range."));
9990 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9992 if (canonical_start
.lsals
.size () > 1
9993 || lsal_start
.sals
.size () != 1)
9994 error (_("Cannot create a ranged breakpoint with multiple locations."));
9996 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9997 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9999 arg
++; /* Skip the comma. */
10000 arg
= skip_spaces (arg
);
10002 /* Parse the end location. */
10006 /* We call decode_line_full directly here instead of using
10007 parse_breakpoint_sals because we need to specify the start location's
10008 symtab and line as the default symtab and line for the end of the
10009 range. This makes it possible to have ranges like "foo.c:27, +14",
10010 where +14 means 14 lines from the start location. */
10011 event_location_up end_location
= string_to_event_location (&arg
,
10013 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10014 sal_start
.symtab
, sal_start
.line
,
10015 &canonical_end
, NULL
, NULL
);
10017 if (canonical_end
.lsals
.empty ())
10018 error (_("Could not find location of the end of the range."));
10020 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10021 if (canonical_end
.lsals
.size () > 1
10022 || lsal_end
.sals
.size () != 1)
10023 error (_("Cannot create a ranged breakpoint with multiple locations."));
10025 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10027 end
= find_breakpoint_range_end (sal_end
);
10028 if (sal_start
.pc
> end
)
10029 error (_("Invalid address range, end precedes start."));
10031 length
= end
- sal_start
.pc
+ 1;
10033 /* Length overflowed. */
10034 error (_("Address range too large."));
10035 else if (length
== 1)
10037 /* This range is simple enough to be handled by
10038 the `hbreak' command. */
10039 hbreak_command (&addr_string_start
[0], 1);
10044 /* Now set up the breakpoint. */
10045 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10046 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10047 set_breakpoint_count (breakpoint_count
+ 1);
10048 b
->number
= breakpoint_count
;
10049 b
->disposition
= disp_donttouch
;
10050 b
->location
= std::move (start_location
);
10051 b
->location_range_end
= std::move (end_location
);
10052 b
->loc
->length
= length
;
10055 gdb::observers::breakpoint_created
.notify (b
);
10056 update_global_location_list (UGLL_MAY_INSERT
);
10059 /* Return non-zero if EXP is verified as constant. Returned zero
10060 means EXP is variable. Also the constant detection may fail for
10061 some constant expressions and in such case still falsely return
10065 watchpoint_exp_is_const (const struct expression
*exp
)
10067 return exp
->op
->constant_p ();
10070 /* Watchpoint destructor. */
10072 watchpoint::~watchpoint ()
10074 xfree (this->exp_string
);
10075 xfree (this->exp_string_reparse
);
10078 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10081 re_set_watchpoint (struct breakpoint
*b
)
10083 struct watchpoint
*w
= (struct watchpoint
*) b
;
10085 /* Watchpoint can be either on expression using entirely global
10086 variables, or it can be on local variables.
10088 Watchpoints of the first kind are never auto-deleted, and even
10089 persist across program restarts. Since they can use variables
10090 from shared libraries, we need to reparse expression as libraries
10091 are loaded and unloaded.
10093 Watchpoints on local variables can also change meaning as result
10094 of solib event. For example, if a watchpoint uses both a local
10095 and a global variables in expression, it's a local watchpoint,
10096 but unloading of a shared library will make the expression
10097 invalid. This is not a very common use case, but we still
10098 re-evaluate expression, to avoid surprises to the user.
10100 Note that for local watchpoints, we re-evaluate it only if
10101 watchpoints frame id is still valid. If it's not, it means the
10102 watchpoint is out of scope and will be deleted soon. In fact,
10103 I'm not sure we'll ever be called in this case.
10105 If a local watchpoint's frame id is still valid, then
10106 w->exp_valid_block is likewise valid, and we can safely use it.
10108 Don't do anything about disabled watchpoints, since they will be
10109 reevaluated again when enabled. */
10110 update_watchpoint (w
, 1 /* reparse */);
10113 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10116 insert_watchpoint (struct bp_location
*bl
)
10118 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10119 int length
= w
->exact
? 1 : bl
->length
;
10121 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10122 w
->cond_exp
.get ());
10125 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10128 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10130 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10131 int length
= w
->exact
? 1 : bl
->length
;
10133 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10134 w
->cond_exp
.get ());
10138 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10139 const address_space
*aspace
, CORE_ADDR bp_addr
,
10140 const struct target_waitstatus
*ws
)
10142 struct breakpoint
*b
= bl
->owner
;
10143 struct watchpoint
*w
= (struct watchpoint
*) b
;
10145 /* Continuable hardware watchpoints are treated as non-existent if the
10146 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10147 some data address). Otherwise gdb won't stop on a break instruction
10148 in the code (not from a breakpoint) when a hardware watchpoint has
10149 been defined. Also skip watchpoints which we know did not trigger
10150 (did not match the data address). */
10151 if (is_hardware_watchpoint (b
)
10152 && w
->watchpoint_triggered
== watch_triggered_no
)
10159 check_status_watchpoint (bpstat bs
)
10161 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10163 bpstat_check_watchpoint (bs
);
10166 /* Implement the "resources_needed" breakpoint_ops method for
10167 hardware watchpoints. */
10170 resources_needed_watchpoint (const struct bp_location
*bl
)
10172 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10173 int length
= w
->exact
? 1 : bl
->length
;
10175 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10178 /* Implement the "works_in_software_mode" breakpoint_ops method for
10179 hardware watchpoints. */
10182 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10184 /* Read and access watchpoints only work with hardware support. */
10185 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10188 static enum print_stop_action
10189 print_it_watchpoint (bpstat bs
)
10191 struct breakpoint
*b
;
10192 enum print_stop_action result
;
10193 struct watchpoint
*w
;
10194 struct ui_out
*uiout
= current_uiout
;
10196 gdb_assert (bs
->bp_location_at
!= NULL
);
10198 b
= bs
->breakpoint_at
;
10199 w
= (struct watchpoint
*) b
;
10201 annotate_watchpoint (b
->number
);
10202 maybe_print_thread_hit_breakpoint (uiout
);
10206 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10209 case bp_watchpoint
:
10210 case bp_hardware_watchpoint
:
10211 if (uiout
->is_mi_like_p ())
10212 uiout
->field_string
10213 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10215 tuple_emitter
.emplace (uiout
, "value");
10216 uiout
->text ("\nOld value = ");
10217 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10218 uiout
->field_stream ("old", stb
);
10219 uiout
->text ("\nNew value = ");
10220 watchpoint_value_print (w
->val
.get (), &stb
);
10221 uiout
->field_stream ("new", stb
);
10222 uiout
->text ("\n");
10223 /* More than one watchpoint may have been triggered. */
10224 result
= PRINT_UNKNOWN
;
10227 case bp_read_watchpoint
:
10228 if (uiout
->is_mi_like_p ())
10229 uiout
->field_string
10230 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10232 tuple_emitter
.emplace (uiout
, "value");
10233 uiout
->text ("\nValue = ");
10234 watchpoint_value_print (w
->val
.get (), &stb
);
10235 uiout
->field_stream ("value", stb
);
10236 uiout
->text ("\n");
10237 result
= PRINT_UNKNOWN
;
10240 case bp_access_watchpoint
:
10241 if (bs
->old_val
!= NULL
)
10243 if (uiout
->is_mi_like_p ())
10244 uiout
->field_string
10246 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10248 tuple_emitter
.emplace (uiout
, "value");
10249 uiout
->text ("\nOld value = ");
10250 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10251 uiout
->field_stream ("old", stb
);
10252 uiout
->text ("\nNew value = ");
10257 if (uiout
->is_mi_like_p ())
10258 uiout
->field_string
10260 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10261 tuple_emitter
.emplace (uiout
, "value");
10262 uiout
->text ("\nValue = ");
10264 watchpoint_value_print (w
->val
.get (), &stb
);
10265 uiout
->field_stream ("new", stb
);
10266 uiout
->text ("\n");
10267 result
= PRINT_UNKNOWN
;
10270 result
= PRINT_UNKNOWN
;
10276 /* Implement the "print_mention" breakpoint_ops method for hardware
10280 print_mention_watchpoint (struct breakpoint
*b
)
10282 struct watchpoint
*w
= (struct watchpoint
*) b
;
10283 struct ui_out
*uiout
= current_uiout
;
10284 const char *tuple_name
;
10288 case bp_watchpoint
:
10289 uiout
->text ("Watchpoint ");
10290 tuple_name
= "wpt";
10292 case bp_hardware_watchpoint
:
10293 uiout
->text ("Hardware watchpoint ");
10294 tuple_name
= "wpt";
10296 case bp_read_watchpoint
:
10297 uiout
->text ("Hardware read watchpoint ");
10298 tuple_name
= "hw-rwpt";
10300 case bp_access_watchpoint
:
10301 uiout
->text ("Hardware access (read/write) watchpoint ");
10302 tuple_name
= "hw-awpt";
10305 internal_error (__FILE__
, __LINE__
,
10306 _("Invalid hardware watchpoint type."));
10309 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10310 uiout
->field_signed ("number", b
->number
);
10311 uiout
->text (": ");
10312 uiout
->field_string ("exp", w
->exp_string
);
10315 /* Implement the "print_recreate" breakpoint_ops method for
10319 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10321 struct watchpoint
*w
= (struct watchpoint
*) b
;
10325 case bp_watchpoint
:
10326 case bp_hardware_watchpoint
:
10327 fprintf_unfiltered (fp
, "watch");
10329 case bp_read_watchpoint
:
10330 fprintf_unfiltered (fp
, "rwatch");
10332 case bp_access_watchpoint
:
10333 fprintf_unfiltered (fp
, "awatch");
10336 internal_error (__FILE__
, __LINE__
,
10337 _("Invalid watchpoint type."));
10340 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10341 print_recreate_thread (b
, fp
);
10344 /* Implement the "explains_signal" breakpoint_ops method for
10348 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10350 /* A software watchpoint cannot cause a signal other than
10351 GDB_SIGNAL_TRAP. */
10352 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10358 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10360 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10362 /* Implement the "insert" breakpoint_ops method for
10363 masked hardware watchpoints. */
10366 insert_masked_watchpoint (struct bp_location
*bl
)
10368 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10370 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10371 bl
->watchpoint_type
);
10374 /* Implement the "remove" breakpoint_ops method for
10375 masked hardware watchpoints. */
10378 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10380 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10382 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10383 bl
->watchpoint_type
);
10386 /* Implement the "resources_needed" breakpoint_ops method for
10387 masked hardware watchpoints. */
10390 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10392 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10394 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10397 /* Implement the "works_in_software_mode" breakpoint_ops method for
10398 masked hardware watchpoints. */
10401 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10406 /* Implement the "print_it" breakpoint_ops method for
10407 masked hardware watchpoints. */
10409 static enum print_stop_action
10410 print_it_masked_watchpoint (bpstat bs
)
10412 struct breakpoint
*b
= bs
->breakpoint_at
;
10413 struct ui_out
*uiout
= current_uiout
;
10415 /* Masked watchpoints have only one location. */
10416 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10418 annotate_watchpoint (b
->number
);
10419 maybe_print_thread_hit_breakpoint (uiout
);
10423 case bp_hardware_watchpoint
:
10424 if (uiout
->is_mi_like_p ())
10425 uiout
->field_string
10426 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10429 case bp_read_watchpoint
:
10430 if (uiout
->is_mi_like_p ())
10431 uiout
->field_string
10432 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10435 case bp_access_watchpoint
:
10436 if (uiout
->is_mi_like_p ())
10437 uiout
->field_string
10439 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10442 internal_error (__FILE__
, __LINE__
,
10443 _("Invalid hardware watchpoint type."));
10447 uiout
->text (_("\n\
10448 Check the underlying instruction at PC for the memory\n\
10449 address and value which triggered this watchpoint.\n"));
10450 uiout
->text ("\n");
10452 /* More than one watchpoint may have been triggered. */
10453 return PRINT_UNKNOWN
;
10456 /* Implement the "print_one_detail" breakpoint_ops method for
10457 masked hardware watchpoints. */
10460 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10461 struct ui_out
*uiout
)
10463 struct watchpoint
*w
= (struct watchpoint
*) b
;
10465 /* Masked watchpoints have only one location. */
10466 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10468 uiout
->text ("\tmask ");
10469 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10470 uiout
->text ("\n");
10473 /* Implement the "print_mention" breakpoint_ops method for
10474 masked hardware watchpoints. */
10477 print_mention_masked_watchpoint (struct breakpoint
*b
)
10479 struct watchpoint
*w
= (struct watchpoint
*) b
;
10480 struct ui_out
*uiout
= current_uiout
;
10481 const char *tuple_name
;
10485 case bp_hardware_watchpoint
:
10486 uiout
->text ("Masked hardware watchpoint ");
10487 tuple_name
= "wpt";
10489 case bp_read_watchpoint
:
10490 uiout
->text ("Masked hardware read watchpoint ");
10491 tuple_name
= "hw-rwpt";
10493 case bp_access_watchpoint
:
10494 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10495 tuple_name
= "hw-awpt";
10498 internal_error (__FILE__
, __LINE__
,
10499 _("Invalid hardware watchpoint type."));
10502 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10503 uiout
->field_signed ("number", b
->number
);
10504 uiout
->text (": ");
10505 uiout
->field_string ("exp", w
->exp_string
);
10508 /* Implement the "print_recreate" breakpoint_ops method for
10509 masked hardware watchpoints. */
10512 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10514 struct watchpoint
*w
= (struct watchpoint
*) b
;
10518 case bp_hardware_watchpoint
:
10519 fprintf_unfiltered (fp
, "watch");
10521 case bp_read_watchpoint
:
10522 fprintf_unfiltered (fp
, "rwatch");
10524 case bp_access_watchpoint
:
10525 fprintf_unfiltered (fp
, "awatch");
10528 internal_error (__FILE__
, __LINE__
,
10529 _("Invalid hardware watchpoint type."));
10532 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
,
10533 phex (w
->hw_wp_mask
, sizeof (CORE_ADDR
)));
10534 print_recreate_thread (b
, fp
);
10537 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10539 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10541 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10544 is_masked_watchpoint (const struct breakpoint
*b
)
10546 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10549 /* accessflag: hw_write: watch write,
10550 hw_read: watch read,
10551 hw_access: watch access (read or write) */
10553 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10554 bool just_location
, bool internal
)
10556 struct breakpoint
*scope_breakpoint
= NULL
;
10557 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10558 struct value
*result
;
10559 int saved_bitpos
= 0, saved_bitsize
= 0;
10560 const char *exp_start
= NULL
;
10561 const char *exp_end
= NULL
;
10562 const char *tok
, *end_tok
;
10564 const char *cond_start
= NULL
;
10565 const char *cond_end
= NULL
;
10566 enum bptype bp_type
;
10568 /* Flag to indicate whether we are going to use masks for
10569 the hardware watchpoint. */
10570 bool use_mask
= false;
10571 CORE_ADDR mask
= 0;
10573 /* Make sure that we actually have parameters to parse. */
10574 if (arg
!= NULL
&& arg
[0] != '\0')
10576 const char *value_start
;
10578 exp_end
= arg
+ strlen (arg
);
10580 /* Look for "parameter value" pairs at the end
10581 of the arguments string. */
10582 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10584 /* Skip whitespace at the end of the argument list. */
10585 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10588 /* Find the beginning of the last token.
10589 This is the value of the parameter. */
10590 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10592 value_start
= tok
+ 1;
10594 /* Skip whitespace. */
10595 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10600 /* Find the beginning of the second to last token.
10601 This is the parameter itself. */
10602 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10605 toklen
= end_tok
- tok
+ 1;
10607 if (toklen
== 6 && startswith (tok
, "thread"))
10609 struct thread_info
*thr
;
10610 /* At this point we've found a "thread" token, which means
10611 the user is trying to set a watchpoint that triggers
10612 only in a specific thread. */
10616 error(_("You can specify only one thread."));
10618 /* Extract the thread ID from the next token. */
10619 thr
= parse_thread_id (value_start
, &endp
);
10621 /* Check if the user provided a valid thread ID. */
10622 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10623 invalid_thread_id_error (value_start
);
10625 thread
= thr
->global_num
;
10627 else if (toklen
== 4 && startswith (tok
, "mask"))
10629 /* We've found a "mask" token, which means the user wants to
10630 create a hardware watchpoint that is going to have the mask
10632 struct value
*mask_value
, *mark
;
10635 error(_("You can specify only one mask."));
10637 use_mask
= just_location
= true;
10639 mark
= value_mark ();
10640 mask_value
= parse_to_comma_and_eval (&value_start
);
10641 mask
= value_as_address (mask_value
);
10642 value_free_to_mark (mark
);
10645 /* We didn't recognize what we found. We should stop here. */
10648 /* Truncate the string and get rid of the "parameter value" pair before
10649 the arguments string is parsed by the parse_exp_1 function. */
10656 /* Parse the rest of the arguments. From here on out, everything
10657 is in terms of a newly allocated string instead of the original
10659 std::string
expression (arg
, exp_end
- arg
);
10660 exp_start
= arg
= expression
.c_str ();
10661 innermost_block_tracker tracker
;
10662 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10664 /* Remove trailing whitespace from the expression before saving it.
10665 This makes the eventual display of the expression string a bit
10667 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10670 /* Checking if the expression is not constant. */
10671 if (watchpoint_exp_is_const (exp
.get ()))
10675 len
= exp_end
- exp_start
;
10676 while (len
> 0 && isspace (exp_start
[len
- 1]))
10678 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10681 exp_valid_block
= tracker
.block ();
10682 struct value
*mark
= value_mark ();
10683 struct value
*val_as_value
= nullptr;
10684 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10687 if (val_as_value
!= NULL
&& just_location
)
10689 saved_bitpos
= value_bitpos (val_as_value
);
10690 saved_bitsize
= value_bitsize (val_as_value
);
10698 exp_valid_block
= NULL
;
10699 val
= release_value (value_addr (result
));
10700 value_free_to_mark (mark
);
10704 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10707 error (_("This target does not support masked watchpoints."));
10708 else if (ret
== -2)
10709 error (_("Invalid mask or memory region."));
10712 else if (val_as_value
!= NULL
)
10713 val
= release_value (val_as_value
);
10715 tok
= skip_spaces (arg
);
10716 end_tok
= skip_to_space (tok
);
10718 toklen
= end_tok
- tok
;
10719 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10721 tok
= cond_start
= end_tok
+ 1;
10722 innermost_block_tracker if_tracker
;
10723 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10725 /* The watchpoint expression may not be local, but the condition
10726 may still be. E.g.: `watch global if local > 0'. */
10727 cond_exp_valid_block
= if_tracker
.block ();
10732 error (_("Junk at end of command."));
10734 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10736 /* Save this because create_internal_breakpoint below invalidates
10738 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10740 /* If the expression is "local", then set up a "watchpoint scope"
10741 breakpoint at the point where we've left the scope of the watchpoint
10742 expression. Create the scope breakpoint before the watchpoint, so
10743 that we will encounter it first in bpstat_stop_status. */
10744 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10746 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10748 if (frame_id_p (caller_frame_id
))
10750 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10751 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10754 = create_internal_breakpoint (caller_arch
, caller_pc
,
10755 bp_watchpoint_scope
,
10756 &momentary_breakpoint_ops
);
10758 /* create_internal_breakpoint could invalidate WP_FRAME. */
10761 scope_breakpoint
->enable_state
= bp_enabled
;
10763 /* Automatically delete the breakpoint when it hits. */
10764 scope_breakpoint
->disposition
= disp_del
;
10766 /* Only break in the proper frame (help with recursion). */
10767 scope_breakpoint
->frame_id
= caller_frame_id
;
10769 /* Set the address at which we will stop. */
10770 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10771 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10772 scope_breakpoint
->loc
->address
10773 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10774 scope_breakpoint
->loc
->requested_address
,
10775 scope_breakpoint
->type
);
10779 /* Now set up the breakpoint. We create all watchpoints as hardware
10780 watchpoints here even if hardware watchpoints are turned off, a call
10781 to update_watchpoint later in this function will cause the type to
10782 drop back to bp_watchpoint (software watchpoint) if required. */
10784 if (accessflag
== hw_read
)
10785 bp_type
= bp_read_watchpoint
;
10786 else if (accessflag
== hw_access
)
10787 bp_type
= bp_access_watchpoint
;
10789 bp_type
= bp_hardware_watchpoint
;
10791 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10794 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10795 &masked_watchpoint_breakpoint_ops
);
10797 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10798 &watchpoint_breakpoint_ops
);
10799 w
->thread
= thread
;
10800 w
->disposition
= disp_donttouch
;
10801 w
->pspace
= current_program_space
;
10802 w
->exp
= std::move (exp
);
10803 w
->exp_valid_block
= exp_valid_block
;
10804 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10807 struct type
*t
= value_type (val
.get ());
10808 CORE_ADDR addr
= value_as_address (val
.get ());
10810 w
->exp_string_reparse
10811 = current_language
->watch_location_expression (t
, addr
).release ();
10813 w
->exp_string
= xstrprintf ("-location %.*s",
10814 (int) (exp_end
- exp_start
), exp_start
);
10817 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10821 w
->hw_wp_mask
= mask
;
10826 w
->val_bitpos
= saved_bitpos
;
10827 w
->val_bitsize
= saved_bitsize
;
10828 w
->val_valid
= true;
10832 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10834 w
->cond_string
= 0;
10836 if (frame_id_p (watchpoint_frame
))
10838 w
->watchpoint_frame
= watchpoint_frame
;
10839 w
->watchpoint_thread
= inferior_ptid
;
10843 w
->watchpoint_frame
= null_frame_id
;
10844 w
->watchpoint_thread
= null_ptid
;
10847 if (scope_breakpoint
!= NULL
)
10849 /* The scope breakpoint is related to the watchpoint. We will
10850 need to act on them together. */
10851 w
->related_breakpoint
= scope_breakpoint
;
10852 scope_breakpoint
->related_breakpoint
= w
.get ();
10855 if (!just_location
)
10856 value_free_to_mark (mark
);
10858 /* Finally update the new watchpoint. This creates the locations
10859 that should be inserted. */
10860 update_watchpoint (w
.get (), 1);
10862 install_breakpoint (internal
, std::move (w
), 1);
10865 /* Return count of debug registers needed to watch the given expression.
10866 If the watchpoint cannot be handled in hardware return zero. */
10869 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10871 int found_memory_cnt
= 0;
10873 /* Did the user specifically forbid us to use hardware watchpoints? */
10874 if (!can_use_hw_watchpoints
)
10877 gdb_assert (!vals
.empty ());
10878 struct value
*head
= vals
[0].get ();
10880 /* Make sure that the value of the expression depends only upon
10881 memory contents, and values computed from them within GDB. If we
10882 find any register references or function calls, we can't use a
10883 hardware watchpoint.
10885 The idea here is that evaluating an expression generates a series
10886 of values, one holding the value of every subexpression. (The
10887 expression a*b+c has five subexpressions: a, b, a*b, c, and
10888 a*b+c.) GDB's values hold almost enough information to establish
10889 the criteria given above --- they identify memory lvalues,
10890 register lvalues, computed values, etcetera. So we can evaluate
10891 the expression, and then scan the chain of values that leaves
10892 behind to decide whether we can detect any possible change to the
10893 expression's final value using only hardware watchpoints.
10895 However, I don't think that the values returned by inferior
10896 function calls are special in any way. So this function may not
10897 notice that an expression involving an inferior function call
10898 can't be watched with hardware watchpoints. FIXME. */
10899 for (const value_ref_ptr
&iter
: vals
)
10901 struct value
*v
= iter
.get ();
10903 if (VALUE_LVAL (v
) == lval_memory
)
10905 if (v
!= head
&& value_lazy (v
))
10906 /* A lazy memory lvalue in the chain is one that GDB never
10907 needed to fetch; we either just used its address (e.g.,
10908 `a' in `a.b') or we never needed it at all (e.g., `a'
10909 in `a,b'). This doesn't apply to HEAD; if that is
10910 lazy then it was not readable, but watch it anyway. */
10914 /* Ahh, memory we actually used! Check if we can cover
10915 it with hardware watchpoints. */
10916 struct type
*vtype
= check_typedef (value_type (v
));
10918 /* We only watch structs and arrays if user asked for it
10919 explicitly, never if they just happen to appear in a
10920 middle of some value chain. */
10922 || (vtype
->code () != TYPE_CODE_STRUCT
10923 && vtype
->code () != TYPE_CODE_ARRAY
))
10925 CORE_ADDR vaddr
= value_address (v
);
10929 len
= (target_exact_watchpoints
10930 && is_scalar_type_recursive (vtype
))?
10931 1 : TYPE_LENGTH (value_type (v
));
10933 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10937 found_memory_cnt
+= num_regs
;
10941 else if (VALUE_LVAL (v
) != not_lval
10942 && deprecated_value_modifiable (v
) == 0)
10943 return 0; /* These are values from the history (e.g., $1). */
10944 else if (VALUE_LVAL (v
) == lval_register
)
10945 return 0; /* Cannot watch a register with a HW watchpoint. */
10948 /* The expression itself looks suitable for using a hardware
10949 watchpoint, but give the target machine a chance to reject it. */
10950 return found_memory_cnt
;
10954 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10956 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10959 /* Options for the watch, awatch, and rwatch commands. */
10961 struct watch_options
10963 /* For -location. */
10964 bool location
= false;
10967 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10969 Historically GDB always accepted both '-location' and '-l' flags for
10970 these commands (both flags being synonyms). When converting to the
10971 newer option scheme only '-location' is added here. That's fine (for
10972 backward compatibility) as any non-ambiguous prefix of a flag will be
10973 accepted, so '-l', '-loc', are now all accepted.
10975 What this means is that, if in the future, we add any new flag here
10976 that starts with '-l' then this will break backward compatibility, so
10977 please, don't do that! */
10979 static const gdb::option::option_def watch_option_defs
[] = {
10980 gdb::option::flag_option_def
<watch_options
> {
10982 [] (watch_options
*opt
) { return &opt
->location
; },
10984 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10985 -l can be used as a short form of -location."),
10989 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10992 static gdb::option::option_def_group
10993 make_watch_options_def_group (watch_options
*opts
)
10995 return {{watch_option_defs
}, opts
};
10998 /* A helper function that looks for the "-location" argument and then
10999 calls watch_command_1. */
11002 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
11004 watch_options opts
;
11005 auto grp
= make_watch_options_def_group (&opts
);
11006 gdb::option::process_options
11007 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
11008 if (arg
!= nullptr && *arg
== '\0')
11011 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
11014 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
11016 watch_command_completer (struct cmd_list_element
*ignore
,
11017 completion_tracker
&tracker
,
11018 const char *text
, const char * /*word*/)
11020 const auto group
= make_watch_options_def_group (nullptr);
11021 if (gdb::option::complete_options
11022 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
11025 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
11026 expression_completer (ignore
, tracker
, text
, word
);
11030 watch_command (const char *arg
, int from_tty
)
11032 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11036 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11038 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11042 rwatch_command (const char *arg
, int from_tty
)
11044 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11048 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11050 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11054 awatch_command (const char *arg
, int from_tty
)
11056 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11060 /* Data for the FSM that manages the until(location)/advance commands
11061 in infcmd.c. Here because it uses the mechanisms of
11064 struct until_break_fsm
: public thread_fsm
11066 /* The thread that was current when the command was executed. */
11069 /* The breakpoint set at the return address in the caller frame,
11070 plus breakpoints at all the destination locations. */
11071 std::vector
<breakpoint_up
> breakpoints
;
11073 until_break_fsm (struct interp
*cmd_interp
, int thread
,
11074 std::vector
<breakpoint_up
> &&breakpoints
)
11075 : thread_fsm (cmd_interp
),
11077 breakpoints (std::move (breakpoints
))
11081 void clean_up (struct thread_info
*thread
) override
;
11082 bool should_stop (struct thread_info
*thread
) override
;
11083 enum async_reply_reason
do_async_reply_reason () override
;
11086 /* Implementation of the 'should_stop' FSM method for the
11087 until(location)/advance commands. */
11090 until_break_fsm::should_stop (struct thread_info
*tp
)
11092 for (const breakpoint_up
&bp
: breakpoints
)
11093 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11094 bp
.get ()) != NULL
)
11103 /* Implementation of the 'clean_up' FSM method for the
11104 until(location)/advance commands. */
11107 until_break_fsm::clean_up (struct thread_info
*)
11109 /* Clean up our temporary breakpoints. */
11110 breakpoints
.clear ();
11111 delete_longjmp_breakpoint (thread
);
11114 /* Implementation of the 'async_reply_reason' FSM method for the
11115 until(location)/advance commands. */
11117 enum async_reply_reason
11118 until_break_fsm::do_async_reply_reason ()
11120 return EXEC_ASYNC_LOCATION_REACHED
;
11124 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11126 struct frame_info
*frame
;
11127 struct gdbarch
*frame_gdbarch
;
11128 struct frame_id stack_frame_id
;
11129 struct frame_id caller_frame_id
;
11131 struct thread_info
*tp
;
11133 clear_proceed_status (0);
11135 /* Set a breakpoint where the user wants it and at return from
11138 event_location_up location
= string_to_event_location (&arg
, current_language
);
11140 std::vector
<symtab_and_line
> sals
11141 = (last_displayed_sal_is_valid ()
11142 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11143 get_last_displayed_symtab (),
11144 get_last_displayed_line ())
11145 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11149 error (_("Couldn't get information on specified line."));
11152 error (_("Junk at end of arguments."));
11154 tp
= inferior_thread ();
11155 thread
= tp
->global_num
;
11157 /* Note linespec handling above invalidates the frame chain.
11158 Installing a breakpoint also invalidates the frame chain (as it
11159 may need to switch threads), so do any frame handling before
11162 frame
= get_selected_frame (NULL
);
11163 frame_gdbarch
= get_frame_arch (frame
);
11164 stack_frame_id
= get_stack_frame_id (frame
);
11165 caller_frame_id
= frame_unwind_caller_id (frame
);
11167 /* Keep within the current frame, or in frames called by the current
11170 std::vector
<breakpoint_up
> breakpoints
;
11172 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11174 if (frame_id_p (caller_frame_id
))
11176 struct symtab_and_line sal2
;
11177 struct gdbarch
*caller_gdbarch
;
11179 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11180 sal2
.pc
= frame_unwind_caller_pc (frame
);
11181 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11183 breakpoint_up caller_breakpoint
11184 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
11185 caller_frame_id
, bp_until
);
11186 breakpoints
.emplace_back (std::move (caller_breakpoint
));
11188 set_longjmp_breakpoint (tp
, caller_frame_id
);
11189 lj_deleter
.emplace (thread
);
11192 /* set_momentary_breakpoint could invalidate FRAME. */
11195 /* If the user told us to continue until a specified location, we
11196 don't specify a frame at which we need to stop. Otherwise,
11197 specify the selected frame, because we want to stop only at the
11198 very same frame. */
11199 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
11201 for (symtab_and_line
&sal
: sals
)
11203 resolve_sal_pc (&sal
);
11205 breakpoint_up location_breakpoint
11206 = set_momentary_breakpoint (frame_gdbarch
, sal
,
11207 stop_frame_id
, bp_until
);
11208 breakpoints
.emplace_back (std::move (location_breakpoint
));
11211 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11212 std::move (breakpoints
));
11215 lj_deleter
->release ();
11217 proceed (-1, GDB_SIGNAL_DEFAULT
);
11220 /* This function attempts to parse an optional "if <cond>" clause
11221 from the arg string. If one is not found, it returns NULL.
11223 Else, it returns a pointer to the condition string. (It does not
11224 attempt to evaluate the string against a particular block.) And,
11225 it updates arg to point to the first character following the parsed
11226 if clause in the arg string. */
11229 ep_parse_optional_if_clause (const char **arg
)
11231 const char *cond_string
;
11233 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11236 /* Skip the "if" keyword. */
11239 /* Skip any extra leading whitespace, and record the start of the
11240 condition string. */
11241 *arg
= skip_spaces (*arg
);
11242 cond_string
= *arg
;
11244 /* Assume that the condition occupies the remainder of the arg
11246 (*arg
) += strlen (cond_string
);
11248 return cond_string
;
11251 /* Commands to deal with catching events, such as signals, exceptions,
11252 process start/exit, etc. */
11256 catch_fork_temporary
, catch_vfork_temporary
,
11257 catch_fork_permanent
, catch_vfork_permanent
11262 catch_fork_command_1 (const char *arg
, int from_tty
,
11263 struct cmd_list_element
*command
)
11265 struct gdbarch
*gdbarch
= get_current_arch ();
11266 const char *cond_string
= NULL
;
11267 catch_fork_kind fork_kind
;
11269 fork_kind
= (catch_fork_kind
) (uintptr_t) command
->context ();
11270 bool temp
= (fork_kind
== catch_fork_temporary
11271 || fork_kind
== catch_vfork_temporary
);
11275 arg
= skip_spaces (arg
);
11277 /* The allowed syntax is:
11279 catch [v]fork if <cond>
11281 First, check if there's an if clause. */
11282 cond_string
= ep_parse_optional_if_clause (&arg
);
11284 if ((*arg
!= '\0') && !isspace (*arg
))
11285 error (_("Junk at end of arguments."));
11287 /* If this target supports it, create a fork or vfork catchpoint
11288 and enable reporting of such events. */
11291 case catch_fork_temporary
:
11292 case catch_fork_permanent
:
11293 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11294 &catch_fork_breakpoint_ops
);
11296 case catch_vfork_temporary
:
11297 case catch_vfork_permanent
:
11298 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11299 &catch_vfork_breakpoint_ops
);
11302 error (_("unsupported or unknown fork kind; cannot catch it"));
11308 catch_exec_command_1 (const char *arg
, int from_tty
,
11309 struct cmd_list_element
*command
)
11311 struct gdbarch
*gdbarch
= get_current_arch ();
11312 const char *cond_string
= NULL
;
11313 bool temp
= command
->context () == CATCH_TEMPORARY
;
11317 arg
= skip_spaces (arg
);
11319 /* The allowed syntax is:
11321 catch exec if <cond>
11323 First, check if there's an if clause. */
11324 cond_string
= ep_parse_optional_if_clause (&arg
);
11326 if ((*arg
!= '\0') && !isspace (*arg
))
11327 error (_("Junk at end of arguments."));
11329 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11330 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
,
11331 &catch_exec_breakpoint_ops
);
11332 c
->exec_pathname
= NULL
;
11334 install_breakpoint (0, std::move (c
), 1);
11338 init_ada_exception_breakpoint (struct breakpoint
*b
,
11339 struct gdbarch
*gdbarch
,
11340 struct symtab_and_line sal
,
11341 const char *addr_string
,
11342 const struct breakpoint_ops
*ops
,
11349 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11351 loc_gdbarch
= gdbarch
;
11353 describe_other_breakpoints (loc_gdbarch
,
11354 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11355 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11356 version for exception catchpoints, because two catchpoints
11357 used for different exception names will use the same address.
11358 In this case, a "breakpoint ... also set at..." warning is
11359 unproductive. Besides, the warning phrasing is also a bit
11360 inappropriate, we should use the word catchpoint, and tell
11361 the user what type of catchpoint it is. The above is good
11362 enough for now, though. */
11365 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11367 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11368 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11369 b
->location
= string_to_event_location (&addr_string
,
11370 language_def (language_ada
));
11371 b
->language
= language_ada
;
11376 /* Compare two breakpoints and return a strcmp-like result. */
11379 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11381 uintptr_t ua
= (uintptr_t) a
;
11382 uintptr_t ub
= (uintptr_t) b
;
11384 if (a
->number
< b
->number
)
11386 else if (a
->number
> b
->number
)
11389 /* Now sort by address, in case we see, e..g, two breakpoints with
11393 return ua
> ub
? 1 : 0;
11396 /* Delete breakpoints by address or line. */
11399 clear_command (const char *arg
, int from_tty
)
11403 std::vector
<symtab_and_line
> decoded_sals
;
11404 symtab_and_line last_sal
;
11405 gdb::array_view
<symtab_and_line
> sals
;
11409 = decode_line_with_current_source (arg
,
11410 (DECODE_LINE_FUNFIRSTLINE
11411 | DECODE_LINE_LIST_MODE
));
11413 sals
= decoded_sals
;
11417 /* Set sal's line, symtab, pc, and pspace to the values
11418 corresponding to the last call to print_frame_info. If the
11419 codepoint is not valid, this will set all the fields to 0. */
11420 last_sal
= get_last_displayed_sal ();
11421 if (last_sal
.symtab
== 0)
11422 error (_("No source file specified."));
11428 /* We don't call resolve_sal_pc here. That's not as bad as it
11429 seems, because all existing breakpoints typically have both
11430 file/line and pc set. So, if clear is given file/line, we can
11431 match this to existing breakpoint without obtaining pc at all.
11433 We only support clearing given the address explicitly
11434 present in breakpoint table. Say, we've set breakpoint
11435 at file:line. There were several PC values for that file:line,
11436 due to optimization, all in one block.
11438 We've picked one PC value. If "clear" is issued with another
11439 PC corresponding to the same file:line, the breakpoint won't
11440 be cleared. We probably can still clear the breakpoint, but
11441 since the other PC value is never presented to user, user
11442 can only find it by guessing, and it does not seem important
11443 to support that. */
11445 /* For each line spec given, delete bps which correspond to it. Do
11446 it in two passes, solely to preserve the current behavior that
11447 from_tty is forced true if we delete more than one
11450 std::vector
<struct breakpoint
*> found
;
11451 for (const auto &sal
: sals
)
11453 const char *sal_fullname
;
11455 /* If exact pc given, clear bpts at that pc.
11456 If line given (pc == 0), clear all bpts on specified line.
11457 If defaulting, clear all bpts on default line
11460 defaulting sal.pc != 0 tests to do
11465 1 0 <can't happen> */
11467 sal_fullname
= (sal
.symtab
== NULL
11468 ? NULL
: symtab_to_fullname (sal
.symtab
));
11470 /* Find all matching breakpoints and add them to 'found'. */
11471 for (breakpoint
*b
: all_breakpoints ())
11474 /* Are we going to delete b? */
11475 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11477 for (bp_location
*loc
: b
->locations ())
11479 /* If the user specified file:line, don't allow a PC
11480 match. This matches historical gdb behavior. */
11481 int pc_match
= (!sal
.explicit_line
11483 && (loc
->pspace
== sal
.pspace
)
11484 && (loc
->address
== sal
.pc
)
11485 && (!section_is_overlay (loc
->section
)
11486 || loc
->section
== sal
.section
));
11487 int line_match
= 0;
11489 if ((default_match
|| sal
.explicit_line
)
11490 && loc
->symtab
!= NULL
11491 && sal_fullname
!= NULL
11492 && sal
.pspace
== loc
->pspace
11493 && loc
->line_number
== sal
.line
11494 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11495 sal_fullname
) == 0)
11498 if (pc_match
|| line_match
)
11507 found
.push_back (b
);
11511 /* Now go thru the 'found' chain and delete them. */
11512 if (found
.empty ())
11515 error (_("No breakpoint at %s."), arg
);
11517 error (_("No breakpoint at this line."));
11520 /* Remove duplicates from the vec. */
11521 std::sort (found
.begin (), found
.end (),
11522 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11524 return compare_breakpoints (bp_a
, bp_b
) < 0;
11526 found
.erase (std::unique (found
.begin (), found
.end (),
11527 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11529 return compare_breakpoints (bp_a
, bp_b
) == 0;
11533 if (found
.size () > 1)
11534 from_tty
= 1; /* Always report if deleted more than one. */
11537 if (found
.size () == 1)
11538 printf_unfiltered (_("Deleted breakpoint "));
11540 printf_unfiltered (_("Deleted breakpoints "));
11543 for (breakpoint
*iter
: found
)
11546 printf_unfiltered ("%d ", iter
->number
);
11547 delete_breakpoint (iter
);
11550 putchar_unfiltered ('\n');
11553 /* Delete breakpoint in BS if they are `delete' breakpoints and
11554 all breakpoints that are marked for deletion, whether hit or not.
11555 This is called after any breakpoint is hit, or after errors. */
11558 breakpoint_auto_delete (bpstat bs
)
11560 for (; bs
; bs
= bs
->next
)
11561 if (bs
->breakpoint_at
11562 && bs
->breakpoint_at
->disposition
== disp_del
11564 delete_breakpoint (bs
->breakpoint_at
);
11566 for (breakpoint
*b
: all_breakpoints_safe ())
11567 if (b
->disposition
== disp_del_at_next_stop
)
11568 delete_breakpoint (b
);
11571 /* A comparison function for bp_location AP and BP being interfaced to
11572 std::sort. Sort elements primarily by their ADDRESS (no matter what
11573 bl_address_is_meaningful says), secondarily by ordering first
11574 permanent elements and terciarily just ensuring the array is sorted
11575 stable way despite std::sort being an unstable algorithm. */
11578 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11580 if (a
->address
!= b
->address
)
11581 return a
->address
< b
->address
;
11583 /* Sort locations at the same address by their pspace number, keeping
11584 locations of the same inferior (in a multi-inferior environment)
11587 if (a
->pspace
->num
!= b
->pspace
->num
)
11588 return a
->pspace
->num
< b
->pspace
->num
;
11590 /* Sort permanent breakpoints first. */
11591 if (a
->permanent
!= b
->permanent
)
11592 return a
->permanent
> b
->permanent
;
11594 /* Sort by type in order to make duplicate determination easier.
11595 See update_global_location_list. This is kept in sync with
11596 breakpoint_locations_match. */
11597 if (a
->loc_type
< b
->loc_type
)
11600 /* Likewise, for range-breakpoints, sort by length. */
11601 if (a
->loc_type
== bp_loc_hardware_breakpoint
11602 && b
->loc_type
== bp_loc_hardware_breakpoint
11603 && a
->length
< b
->length
)
11606 /* Make the internal GDB representation stable across GDB runs
11607 where A and B memory inside GDB can differ. Breakpoint locations of
11608 the same type at the same address can be sorted in arbitrary order. */
11610 if (a
->owner
->number
!= b
->owner
->number
)
11611 return a
->owner
->number
< b
->owner
->number
;
11616 /* Set bp_locations_placed_address_before_address_max and
11617 bp_locations_shadow_len_after_address_max according to the current
11618 content of the bp_locations array. */
11621 bp_locations_target_extensions_update (void)
11623 bp_locations_placed_address_before_address_max
= 0;
11624 bp_locations_shadow_len_after_address_max
= 0;
11626 for (bp_location
*bl
: all_bp_locations ())
11628 CORE_ADDR start
, end
, addr
;
11630 if (!bp_location_has_shadow (bl
))
11633 start
= bl
->target_info
.placed_address
;
11634 end
= start
+ bl
->target_info
.shadow_len
;
11636 gdb_assert (bl
->address
>= start
);
11637 addr
= bl
->address
- start
;
11638 if (addr
> bp_locations_placed_address_before_address_max
)
11639 bp_locations_placed_address_before_address_max
= addr
;
11641 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11643 gdb_assert (bl
->address
< end
);
11644 addr
= end
- bl
->address
;
11645 if (addr
> bp_locations_shadow_len_after_address_max
)
11646 bp_locations_shadow_len_after_address_max
= addr
;
11650 /* Download tracepoint locations if they haven't been. */
11653 download_tracepoint_locations (void)
11655 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11657 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11659 for (breakpoint
*b
: all_tracepoints ())
11661 struct tracepoint
*t
;
11662 int bp_location_downloaded
= 0;
11664 if ((b
->type
== bp_fast_tracepoint
11665 ? !may_insert_fast_tracepoints
11666 : !may_insert_tracepoints
))
11669 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11671 if (target_can_download_tracepoint ())
11672 can_download_tracepoint
= TRIBOOL_TRUE
;
11674 can_download_tracepoint
= TRIBOOL_FALSE
;
11677 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11680 for (bp_location
*bl
: b
->locations ())
11682 /* In tracepoint, locations are _never_ duplicated, so
11683 should_be_inserted is equivalent to
11684 unduplicated_should_be_inserted. */
11685 if (!should_be_inserted (bl
) || bl
->inserted
)
11688 switch_to_program_space_and_thread (bl
->pspace
);
11690 target_download_tracepoint (bl
);
11693 bp_location_downloaded
= 1;
11695 t
= (struct tracepoint
*) b
;
11696 t
->number_on_target
= b
->number
;
11697 if (bp_location_downloaded
)
11698 gdb::observers::breakpoint_modified
.notify (b
);
11702 /* Swap the insertion/duplication state between two locations. */
11705 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11707 const int left_inserted
= left
->inserted
;
11708 const int left_duplicate
= left
->duplicate
;
11709 const int left_needs_update
= left
->needs_update
;
11710 const struct bp_target_info left_target_info
= left
->target_info
;
11712 /* Locations of tracepoints can never be duplicated. */
11713 if (is_tracepoint (left
->owner
))
11714 gdb_assert (!left
->duplicate
);
11715 if (is_tracepoint (right
->owner
))
11716 gdb_assert (!right
->duplicate
);
11718 left
->inserted
= right
->inserted
;
11719 left
->duplicate
= right
->duplicate
;
11720 left
->needs_update
= right
->needs_update
;
11721 left
->target_info
= right
->target_info
;
11722 right
->inserted
= left_inserted
;
11723 right
->duplicate
= left_duplicate
;
11724 right
->needs_update
= left_needs_update
;
11725 right
->target_info
= left_target_info
;
11728 /* Force the re-insertion of the locations at ADDRESS. This is called
11729 once a new/deleted/modified duplicate location is found and we are evaluating
11730 conditions on the target's side. Such conditions need to be updated on
11734 force_breakpoint_reinsertion (struct bp_location
*bl
)
11736 CORE_ADDR address
= 0;
11739 address
= bl
->address
;
11740 pspace_num
= bl
->pspace
->num
;
11742 /* This is only meaningful if the target is
11743 evaluating conditions and if the user has
11744 opted for condition evaluation on the target's
11746 if (gdb_evaluates_breakpoint_condition_p ()
11747 || !target_supports_evaluation_of_breakpoint_conditions ())
11750 /* Flag all breakpoint locations with this address and
11751 the same program space as the location
11752 as "its condition has changed". We need to
11753 update the conditions on the target's side. */
11754 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
11756 if (!is_breakpoint (loc
->owner
)
11757 || pspace_num
!= loc
->pspace
->num
)
11760 /* Flag the location appropriately. We use a different state to
11761 let everyone know that we already updated the set of locations
11762 with addr bl->address and program space bl->pspace. This is so
11763 we don't have to keep calling these functions just to mark locations
11764 that have already been marked. */
11765 loc
->condition_changed
= condition_updated
;
11767 /* Free the agent expression bytecode as well. We will compute
11769 loc
->cond_bytecode
.reset ();
11773 /* Called whether new breakpoints are created, or existing breakpoints
11774 deleted, to update the global location list and recompute which
11775 locations are duplicate of which.
11777 The INSERT_MODE flag determines whether locations may not, may, or
11778 shall be inserted now. See 'enum ugll_insert_mode' for more
11782 update_global_location_list (enum ugll_insert_mode insert_mode
)
11784 /* Last breakpoint location address that was marked for update. */
11785 CORE_ADDR last_addr
= 0;
11786 /* Last breakpoint location program space that was marked for update. */
11787 int last_pspace_num
= -1;
11789 /* Used in the duplicates detection below. When iterating over all
11790 bp_locations, points to the first bp_location of a given address.
11791 Breakpoints and watchpoints of different types are never
11792 duplicates of each other. Keep one pointer for each type of
11793 breakpoint/watchpoint, so we only need to loop over all locations
11795 struct bp_location
*bp_loc_first
; /* breakpoint */
11796 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11797 struct bp_location
*awp_loc_first
; /* access watchpoint */
11798 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11800 /* Saved former bp_locations array which we compare against the newly
11801 built bp_locations from the current state of ALL_BREAKPOINTS. */
11802 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
11803 bp_locations
.clear ();
11805 for (breakpoint
*b
: all_breakpoints ())
11806 for (bp_location
*loc
: b
->locations ())
11807 bp_locations
.push_back (loc
);
11809 /* See if we need to "upgrade" a software breakpoint to a hardware
11810 breakpoint. Do this before deciding whether locations are
11811 duplicates. Also do this before sorting because sorting order
11812 depends on location type. */
11813 for (bp_location
*loc
: bp_locations
)
11814 if (!loc
->inserted
&& should_be_inserted (loc
))
11815 handle_automatic_hardware_breakpoints (loc
);
11817 std::sort (bp_locations
.begin (), bp_locations
.end (),
11818 bp_location_is_less_than
);
11820 bp_locations_target_extensions_update ();
11822 /* Identify bp_location instances that are no longer present in the
11823 new list, and therefore should be freed. Note that it's not
11824 necessary that those locations should be removed from inferior --
11825 if there's another location at the same address (previously
11826 marked as duplicate), we don't need to remove/insert the
11829 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11830 and former bp_location array state respectively. */
11833 for (bp_location
*old_loc
: old_locations
)
11835 /* Tells if 'old_loc' is found among the new locations. If
11836 not, we have to free it. */
11837 int found_object
= 0;
11838 /* Tells if the location should remain inserted in the target. */
11839 int keep_in_target
= 0;
11842 /* Skip LOCP entries which will definitely never be needed.
11843 Stop either at or being the one matching OLD_LOC. */
11844 while (loc_i
< bp_locations
.size ()
11845 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11848 for (size_t loc2_i
= loc_i
;
11849 (loc2_i
< bp_locations
.size ()
11850 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11853 /* Check if this is a new/duplicated location or a duplicated
11854 location that had its condition modified. If so, we want to send
11855 its condition to the target if evaluation of conditions is taking
11857 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11858 && (last_addr
!= old_loc
->address
11859 || last_pspace_num
!= old_loc
->pspace
->num
))
11861 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11862 last_pspace_num
= old_loc
->pspace
->num
;
11865 if (bp_locations
[loc2_i
] == old_loc
)
11869 /* We have already handled this address, update it so that we don't
11870 have to go through updates again. */
11871 last_addr
= old_loc
->address
;
11873 /* Target-side condition evaluation: Handle deleted locations. */
11875 force_breakpoint_reinsertion (old_loc
);
11877 /* If this location is no longer present, and inserted, look if
11878 there's maybe a new location at the same address. If so,
11879 mark that one inserted, and don't remove this one. This is
11880 needed so that we don't have a time window where a breakpoint
11881 at certain location is not inserted. */
11883 if (old_loc
->inserted
)
11885 /* If the location is inserted now, we might have to remove
11888 if (found_object
&& should_be_inserted (old_loc
))
11890 /* The location is still present in the location list,
11891 and still should be inserted. Don't do anything. */
11892 keep_in_target
= 1;
11896 /* This location still exists, but it won't be kept in the
11897 target since it may have been disabled. We proceed to
11898 remove its target-side condition. */
11900 /* The location is either no longer present, or got
11901 disabled. See if there's another location at the
11902 same address, in which case we don't need to remove
11903 this one from the target. */
11905 /* OLD_LOC comes from existing struct breakpoint. */
11906 if (bl_address_is_meaningful (old_loc
))
11908 for (size_t loc2_i
= loc_i
;
11909 (loc2_i
< bp_locations
.size ()
11910 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11913 bp_location
*loc2
= bp_locations
[loc2_i
];
11915 if (loc2
== old_loc
)
11918 if (breakpoint_locations_match (loc2
, old_loc
))
11920 /* Read watchpoint locations are switched to
11921 access watchpoints, if the former are not
11922 supported, but the latter are. */
11923 if (is_hardware_watchpoint (old_loc
->owner
))
11925 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11926 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11929 /* loc2 is a duplicated location. We need to check
11930 if it should be inserted in case it will be
11932 if (unduplicated_should_be_inserted (loc2
))
11934 swap_insertion (old_loc
, loc2
);
11935 keep_in_target
= 1;
11943 if (!keep_in_target
)
11945 if (remove_breakpoint (old_loc
))
11947 /* This is just about all we can do. We could keep
11948 this location on the global list, and try to
11949 remove it next time, but there's no particular
11950 reason why we will succeed next time.
11952 Note that at this point, old_loc->owner is still
11953 valid, as delete_breakpoint frees the breakpoint
11954 only after calling us. */
11955 printf_filtered (_("warning: Error removing "
11956 "breakpoint %d\n"),
11957 old_loc
->owner
->number
);
11965 if (removed
&& target_is_non_stop_p ()
11966 && need_moribund_for_location_type (old_loc
))
11968 /* This location was removed from the target. In
11969 non-stop mode, a race condition is possible where
11970 we've removed a breakpoint, but stop events for that
11971 breakpoint are already queued and will arrive later.
11972 We apply an heuristic to be able to distinguish such
11973 SIGTRAPs from other random SIGTRAPs: we keep this
11974 breakpoint location for a bit, and will retire it
11975 after we see some number of events. The theory here
11976 is that reporting of events should, "on the average",
11977 be fair, so after a while we'll see events from all
11978 threads that have anything of interest, and no longer
11979 need to keep this breakpoint location around. We
11980 don't hold locations forever so to reduce chances of
11981 mistaking a non-breakpoint SIGTRAP for a breakpoint
11984 The heuristic failing can be disastrous on
11985 decr_pc_after_break targets.
11987 On decr_pc_after_break targets, like e.g., x86-linux,
11988 if we fail to recognize a late breakpoint SIGTRAP,
11989 because events_till_retirement has reached 0 too
11990 soon, we'll fail to do the PC adjustment, and report
11991 a random SIGTRAP to the user. When the user resumes
11992 the inferior, it will most likely immediately crash
11993 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11994 corrupted, because of being resumed e.g., in the
11995 middle of a multi-byte instruction, or skipped a
11996 one-byte instruction. This was actually seen happen
11997 on native x86-linux, and should be less rare on
11998 targets that do not support new thread events, like
11999 remote, due to the heuristic depending on
12002 Mistaking a random SIGTRAP for a breakpoint trap
12003 causes similar symptoms (PC adjustment applied when
12004 it shouldn't), but then again, playing with SIGTRAPs
12005 behind the debugger's back is asking for trouble.
12007 Since hardware watchpoint traps are always
12008 distinguishable from other traps, so we don't need to
12009 apply keep hardware watchpoint moribund locations
12010 around. We simply always ignore hardware watchpoint
12011 traps we can no longer explain. */
12013 process_stratum_target
*proc_target
= nullptr;
12014 for (inferior
*inf
: all_inferiors ())
12015 if (inf
->pspace
== old_loc
->pspace
)
12017 proc_target
= inf
->process_target ();
12020 if (proc_target
!= nullptr)
12021 old_loc
->events_till_retirement
12022 = 3 * (thread_count (proc_target
) + 1);
12024 old_loc
->events_till_retirement
= 1;
12025 old_loc
->owner
= NULL
;
12027 moribund_locations
.push_back (old_loc
);
12031 old_loc
->owner
= NULL
;
12032 decref_bp_location (&old_loc
);
12037 /* Rescan breakpoints at the same address and section, marking the
12038 first one as "first" and any others as "duplicates". This is so
12039 that the bpt instruction is only inserted once. If we have a
12040 permanent breakpoint at the same place as BPT, make that one the
12041 official one, and the rest as duplicates. Permanent breakpoints
12042 are sorted first for the same address.
12044 Do the same for hardware watchpoints, but also considering the
12045 watchpoint's type (regular/access/read) and length. */
12047 bp_loc_first
= NULL
;
12048 wp_loc_first
= NULL
;
12049 awp_loc_first
= NULL
;
12050 rwp_loc_first
= NULL
;
12052 for (bp_location
*loc
: all_bp_locations ())
12054 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12056 struct bp_location
**loc_first_p
;
12057 breakpoint
*b
= loc
->owner
;
12059 if (!unduplicated_should_be_inserted (loc
)
12060 || !bl_address_is_meaningful (loc
)
12061 /* Don't detect duplicate for tracepoint locations because they are
12062 never duplicated. See the comments in field `duplicate' of
12063 `struct bp_location'. */
12064 || is_tracepoint (b
))
12066 /* Clear the condition modification flag. */
12067 loc
->condition_changed
= condition_unchanged
;
12071 if (b
->type
== bp_hardware_watchpoint
)
12072 loc_first_p
= &wp_loc_first
;
12073 else if (b
->type
== bp_read_watchpoint
)
12074 loc_first_p
= &rwp_loc_first
;
12075 else if (b
->type
== bp_access_watchpoint
)
12076 loc_first_p
= &awp_loc_first
;
12078 loc_first_p
= &bp_loc_first
;
12080 if (*loc_first_p
== NULL
12081 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12082 || !breakpoint_locations_match (loc
, *loc_first_p
))
12084 *loc_first_p
= loc
;
12085 loc
->duplicate
= 0;
12087 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12089 loc
->needs_update
= 1;
12090 /* Clear the condition modification flag. */
12091 loc
->condition_changed
= condition_unchanged
;
12097 /* This and the above ensure the invariant that the first location
12098 is not duplicated, and is the inserted one.
12099 All following are marked as duplicated, and are not inserted. */
12101 swap_insertion (loc
, *loc_first_p
);
12102 loc
->duplicate
= 1;
12104 /* Clear the condition modification flag. */
12105 loc
->condition_changed
= condition_unchanged
;
12108 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12110 if (insert_mode
!= UGLL_DONT_INSERT
)
12111 insert_breakpoint_locations ();
12114 /* Even though the caller told us to not insert new
12115 locations, we may still need to update conditions on the
12116 target's side of breakpoints that were already inserted
12117 if the target is evaluating breakpoint conditions. We
12118 only update conditions for locations that are marked
12120 update_inserted_breakpoint_locations ();
12124 if (insert_mode
!= UGLL_DONT_INSERT
)
12125 download_tracepoint_locations ();
12129 breakpoint_retire_moribund (void)
12131 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
12133 struct bp_location
*loc
= moribund_locations
[ix
];
12134 if (--(loc
->events_till_retirement
) == 0)
12136 decref_bp_location (&loc
);
12137 unordered_remove (moribund_locations
, ix
);
12144 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12149 update_global_location_list (insert_mode
);
12151 catch (const gdb_exception_error
&e
)
12156 /* Clear BKP from a BPS. */
12159 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12163 for (bs
= bps
; bs
; bs
= bs
->next
)
12164 if (bs
->breakpoint_at
== bpt
)
12166 bs
->breakpoint_at
= NULL
;
12167 bs
->old_val
= NULL
;
12168 /* bs->commands will be freed later. */
12172 /* Callback for iterate_over_threads. */
12174 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12176 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12178 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12182 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12186 say_where (struct breakpoint
*b
)
12188 struct value_print_options opts
;
12190 get_user_print_options (&opts
);
12192 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12194 if (b
->loc
== NULL
)
12196 /* For pending locations, the output differs slightly based
12197 on b->extra_string. If this is non-NULL, it contains either
12198 a condition or dprintf arguments. */
12199 if (b
->extra_string
== NULL
)
12201 printf_filtered (_(" (%s) pending."),
12202 event_location_to_string (b
->location
.get ()));
12204 else if (b
->type
== bp_dprintf
)
12206 printf_filtered (_(" (%s,%s) pending."),
12207 event_location_to_string (b
->location
.get ()),
12212 printf_filtered (_(" (%s %s) pending."),
12213 event_location_to_string (b
->location
.get ()),
12219 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12220 printf_filtered (" at %ps",
12221 styled_string (address_style
.style (),
12222 paddress (b
->loc
->gdbarch
,
12223 b
->loc
->address
)));
12224 if (b
->loc
->symtab
!= NULL
)
12226 /* If there is a single location, we can print the location
12228 if (b
->loc
->next
== NULL
)
12230 const char *filename
12231 = symtab_to_filename_for_display (b
->loc
->symtab
);
12232 printf_filtered (": file %ps, line %d.",
12233 styled_string (file_name_style
.style (),
12235 b
->loc
->line_number
);
12238 /* This is not ideal, but each location may have a
12239 different file name, and this at least reflects the
12240 real situation somewhat. */
12241 printf_filtered (": %s.",
12242 event_location_to_string (b
->location
.get ()));
12247 struct bp_location
*loc
= b
->loc
;
12249 for (; loc
; loc
= loc
->next
)
12251 printf_filtered (" (%d locations)", n
);
12256 bp_location::~bp_location ()
12258 xfree (function_name
);
12261 /* Destructor for the breakpoint base class. */
12263 breakpoint::~breakpoint ()
12265 xfree (this->cond_string
);
12266 xfree (this->extra_string
);
12269 /* See breakpoint.h. */
12271 bp_location_range
breakpoint::locations ()
12273 return bp_location_range (this->loc
);
12276 static struct bp_location
*
12277 base_breakpoint_allocate_location (struct breakpoint
*self
)
12279 return new bp_location (self
);
12283 base_breakpoint_re_set (struct breakpoint
*b
)
12285 /* Nothing to re-set. */
12288 #define internal_error_pure_virtual_called() \
12289 gdb_assert_not_reached ("pure virtual function called")
12292 base_breakpoint_insert_location (struct bp_location
*bl
)
12294 internal_error_pure_virtual_called ();
12298 base_breakpoint_remove_location (struct bp_location
*bl
,
12299 enum remove_bp_reason reason
)
12301 internal_error_pure_virtual_called ();
12305 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12306 const address_space
*aspace
,
12308 const struct target_waitstatus
*ws
)
12310 internal_error_pure_virtual_called ();
12314 base_breakpoint_check_status (bpstat bs
)
12319 /* A "works_in_software_mode" breakpoint_ops method that just internal
12323 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12325 internal_error_pure_virtual_called ();
12328 /* A "resources_needed" breakpoint_ops method that just internal
12332 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12334 internal_error_pure_virtual_called ();
12337 static enum print_stop_action
12338 base_breakpoint_print_it (bpstat bs
)
12340 internal_error_pure_virtual_called ();
12344 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12345 struct ui_out
*uiout
)
12351 base_breakpoint_print_mention (struct breakpoint
*b
)
12353 internal_error_pure_virtual_called ();
12357 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12359 internal_error_pure_virtual_called ();
12363 base_breakpoint_create_sals_from_location
12364 (struct event_location
*location
,
12365 struct linespec_result
*canonical
,
12366 enum bptype type_wanted
)
12368 internal_error_pure_virtual_called ();
12372 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12373 struct linespec_result
*c
,
12374 gdb::unique_xmalloc_ptr
<char> cond_string
,
12375 gdb::unique_xmalloc_ptr
<char> extra_string
,
12376 enum bptype type_wanted
,
12377 enum bpdisp disposition
,
12379 int task
, int ignore_count
,
12380 const struct breakpoint_ops
*o
,
12381 int from_tty
, int enabled
,
12382 int internal
, unsigned flags
)
12384 internal_error_pure_virtual_called ();
12387 static std::vector
<symtab_and_line
>
12388 base_breakpoint_decode_location (struct breakpoint
*b
,
12389 struct event_location
*location
,
12390 struct program_space
*search_pspace
)
12392 internal_error_pure_virtual_called ();
12395 /* The default 'explains_signal' method. */
12398 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12403 /* The default "after_condition_true" method. */
12406 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12408 /* Nothing to do. */
12411 struct breakpoint_ops base_breakpoint_ops
=
12413 base_breakpoint_allocate_location
,
12414 base_breakpoint_re_set
,
12415 base_breakpoint_insert_location
,
12416 base_breakpoint_remove_location
,
12417 base_breakpoint_breakpoint_hit
,
12418 base_breakpoint_check_status
,
12419 base_breakpoint_resources_needed
,
12420 base_breakpoint_works_in_software_mode
,
12421 base_breakpoint_print_it
,
12423 base_breakpoint_print_one_detail
,
12424 base_breakpoint_print_mention
,
12425 base_breakpoint_print_recreate
,
12426 base_breakpoint_create_sals_from_location
,
12427 base_breakpoint_create_breakpoints_sal
,
12428 base_breakpoint_decode_location
,
12429 base_breakpoint_explains_signal
,
12430 base_breakpoint_after_condition_true
,
12433 /* Default breakpoint_ops methods. */
12436 bkpt_re_set (struct breakpoint
*b
)
12438 /* FIXME: is this still reachable? */
12439 if (breakpoint_event_location_empty_p (b
))
12441 /* Anything without a location can't be re-set. */
12442 delete_breakpoint (b
);
12446 breakpoint_re_set_default (b
);
12450 bkpt_insert_location (struct bp_location
*bl
)
12452 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12454 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12455 bl
->target_info
.placed_address
= addr
;
12457 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12458 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12460 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12464 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12466 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12467 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12469 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12473 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12474 const address_space
*aspace
, CORE_ADDR bp_addr
,
12475 const struct target_waitstatus
*ws
)
12477 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12478 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12481 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12485 if (overlay_debugging
/* unmapped overlay section */
12486 && section_is_overlay (bl
->section
)
12487 && !section_is_mapped (bl
->section
))
12494 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12495 const address_space
*aspace
, CORE_ADDR bp_addr
,
12496 const struct target_waitstatus
*ws
)
12498 if (dprintf_style
== dprintf_style_agent
12499 && target_can_run_breakpoint_commands ())
12501 /* An agent-style dprintf never causes a stop. If we see a trap
12502 for this address it must be for a breakpoint that happens to
12503 be set at the same address. */
12507 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12511 bkpt_resources_needed (const struct bp_location
*bl
)
12513 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12518 static enum print_stop_action
12519 bkpt_print_it (bpstat bs
)
12521 struct breakpoint
*b
;
12522 const struct bp_location
*bl
;
12524 struct ui_out
*uiout
= current_uiout
;
12526 gdb_assert (bs
->bp_location_at
!= NULL
);
12528 bl
= bs
->bp_location_at
.get ();
12529 b
= bs
->breakpoint_at
;
12531 bp_temp
= b
->disposition
== disp_del
;
12532 if (bl
->address
!= bl
->requested_address
)
12533 breakpoint_adjustment_warning (bl
->requested_address
,
12536 annotate_breakpoint (b
->number
);
12537 maybe_print_thread_hit_breakpoint (uiout
);
12539 if (uiout
->is_mi_like_p ())
12541 uiout
->field_string ("reason",
12542 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12543 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12546 uiout
->message ("Temporary breakpoint %pF, ",
12547 signed_field ("bkptno", b
->number
));
12549 uiout
->message ("Breakpoint %pF, ",
12550 signed_field ("bkptno", b
->number
));
12552 return PRINT_SRC_AND_LOC
;
12556 bkpt_print_mention (struct breakpoint
*b
)
12558 if (current_uiout
->is_mi_like_p ())
12563 case bp_breakpoint
:
12564 case bp_gnu_ifunc_resolver
:
12565 if (b
->disposition
== disp_del
)
12566 printf_filtered (_("Temporary breakpoint"));
12568 printf_filtered (_("Breakpoint"));
12569 printf_filtered (_(" %d"), b
->number
);
12570 if (b
->type
== bp_gnu_ifunc_resolver
)
12571 printf_filtered (_(" at gnu-indirect-function resolver"));
12573 case bp_hardware_breakpoint
:
12574 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12577 printf_filtered (_("Dprintf %d"), b
->number
);
12585 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12587 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12588 fprintf_unfiltered (fp
, "tbreak");
12589 else if (tp
->type
== bp_breakpoint
)
12590 fprintf_unfiltered (fp
, "break");
12591 else if (tp
->type
== bp_hardware_breakpoint
12592 && tp
->disposition
== disp_del
)
12593 fprintf_unfiltered (fp
, "thbreak");
12594 else if (tp
->type
== bp_hardware_breakpoint
)
12595 fprintf_unfiltered (fp
, "hbreak");
12597 internal_error (__FILE__
, __LINE__
,
12598 _("unhandled breakpoint type %d"), (int) tp
->type
);
12600 fprintf_unfiltered (fp
, " %s",
12601 event_location_to_string (tp
->location
.get ()));
12603 /* Print out extra_string if this breakpoint is pending. It might
12604 contain, for example, conditions that were set by the user. */
12605 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12606 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12608 print_recreate_thread (tp
, fp
);
12612 bkpt_create_sals_from_location (struct event_location
*location
,
12613 struct linespec_result
*canonical
,
12614 enum bptype type_wanted
)
12616 create_sals_from_location_default (location
, canonical
, type_wanted
);
12620 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12621 struct linespec_result
*canonical
,
12622 gdb::unique_xmalloc_ptr
<char> cond_string
,
12623 gdb::unique_xmalloc_ptr
<char> extra_string
,
12624 enum bptype type_wanted
,
12625 enum bpdisp disposition
,
12627 int task
, int ignore_count
,
12628 const struct breakpoint_ops
*ops
,
12629 int from_tty
, int enabled
,
12630 int internal
, unsigned flags
)
12632 create_breakpoints_sal_default (gdbarch
, canonical
,
12633 std::move (cond_string
),
12634 std::move (extra_string
),
12636 disposition
, thread
, task
,
12637 ignore_count
, ops
, from_tty
,
12638 enabled
, internal
, flags
);
12641 static std::vector
<symtab_and_line
>
12642 bkpt_decode_location (struct breakpoint
*b
,
12643 struct event_location
*location
,
12644 struct program_space
*search_pspace
)
12646 return decode_location_default (b
, location
, search_pspace
);
12649 /* Virtual table for internal breakpoints. */
12652 internal_bkpt_re_set (struct breakpoint
*b
)
12656 /* Delete overlay event and longjmp master breakpoints; they
12657 will be reset later by breakpoint_re_set. */
12658 case bp_overlay_event
:
12659 case bp_longjmp_master
:
12660 case bp_std_terminate_master
:
12661 case bp_exception_master
:
12662 delete_breakpoint (b
);
12665 /* This breakpoint is special, it's set up when the inferior
12666 starts and we really don't want to touch it. */
12667 case bp_shlib_event
:
12669 /* Like bp_shlib_event, this breakpoint type is special. Once
12670 it is set up, we do not want to touch it. */
12671 case bp_thread_event
:
12677 internal_bkpt_check_status (bpstat bs
)
12679 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12681 /* If requested, stop when the dynamic linker notifies GDB of
12682 events. This allows the user to get control and place
12683 breakpoints in initializer routines for dynamically loaded
12684 objects (among other things). */
12685 bs
->stop
= stop_on_solib_events
;
12686 bs
->print
= stop_on_solib_events
;
12692 static enum print_stop_action
12693 internal_bkpt_print_it (bpstat bs
)
12695 struct breakpoint
*b
;
12697 b
= bs
->breakpoint_at
;
12701 case bp_shlib_event
:
12702 /* Did we stop because the user set the stop_on_solib_events
12703 variable? (If so, we report this as a generic, "Stopped due
12704 to shlib event" message.) */
12705 print_solib_event (0);
12708 case bp_thread_event
:
12709 /* Not sure how we will get here.
12710 GDB should not stop for these breakpoints. */
12711 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12714 case bp_overlay_event
:
12715 /* By analogy with the thread event, GDB should not stop for these. */
12716 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12719 case bp_longjmp_master
:
12720 /* These should never be enabled. */
12721 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12724 case bp_std_terminate_master
:
12725 /* These should never be enabled. */
12726 printf_filtered (_("std::terminate Master Breakpoint: "
12727 "gdb should not stop!\n"));
12730 case bp_exception_master
:
12731 /* These should never be enabled. */
12732 printf_filtered (_("Exception Master Breakpoint: "
12733 "gdb should not stop!\n"));
12737 return PRINT_NOTHING
;
12741 internal_bkpt_print_mention (struct breakpoint
*b
)
12743 /* Nothing to mention. These breakpoints are internal. */
12746 /* Virtual table for momentary breakpoints */
12749 momentary_bkpt_re_set (struct breakpoint
*b
)
12751 /* Keep temporary breakpoints, which can be encountered when we step
12752 over a dlopen call and solib_add is resetting the breakpoints.
12753 Otherwise these should have been blown away via the cleanup chain
12754 or by breakpoint_init_inferior when we rerun the executable. */
12758 momentary_bkpt_check_status (bpstat bs
)
12760 /* Nothing. The point of these breakpoints is causing a stop. */
12763 static enum print_stop_action
12764 momentary_bkpt_print_it (bpstat bs
)
12766 return PRINT_UNKNOWN
;
12770 momentary_bkpt_print_mention (struct breakpoint
*b
)
12772 /* Nothing to mention. These breakpoints are internal. */
12775 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12777 It gets cleared already on the removal of the first one of such placed
12778 breakpoints. This is OK as they get all removed altogether. */
12780 longjmp_breakpoint::~longjmp_breakpoint ()
12782 thread_info
*tp
= find_thread_global_id (this->thread
);
12785 tp
->initiating_frame
= null_frame_id
;
12788 /* Specific methods for probe breakpoints. */
12791 bkpt_probe_insert_location (struct bp_location
*bl
)
12793 int v
= bkpt_insert_location (bl
);
12797 /* The insertion was successful, now let's set the probe's semaphore
12799 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12806 bkpt_probe_remove_location (struct bp_location
*bl
,
12807 enum remove_bp_reason reason
)
12809 /* Let's clear the semaphore before removing the location. */
12810 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12812 return bkpt_remove_location (bl
, reason
);
12816 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12817 struct linespec_result
*canonical
,
12818 enum bptype type_wanted
)
12820 struct linespec_sals lsal
;
12822 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12824 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12825 canonical
->lsals
.push_back (std::move (lsal
));
12828 static std::vector
<symtab_and_line
>
12829 bkpt_probe_decode_location (struct breakpoint
*b
,
12830 struct event_location
*location
,
12831 struct program_space
*search_pspace
)
12833 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12835 error (_("probe not found"));
12839 /* The breakpoint_ops structure to be used in tracepoints. */
12842 tracepoint_re_set (struct breakpoint
*b
)
12844 breakpoint_re_set_default (b
);
12848 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12849 const address_space
*aspace
, CORE_ADDR bp_addr
,
12850 const struct target_waitstatus
*ws
)
12852 /* By definition, the inferior does not report stops at
12858 tracepoint_print_one_detail (const struct breakpoint
*self
,
12859 struct ui_out
*uiout
)
12861 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12862 if (!tp
->static_trace_marker_id
.empty ())
12864 gdb_assert (self
->type
== bp_static_tracepoint
);
12866 uiout
->message ("\tmarker id is %pF\n",
12867 string_field ("static-tracepoint-marker-string-id",
12868 tp
->static_trace_marker_id
.c_str ()));
12873 tracepoint_print_mention (struct breakpoint
*b
)
12875 if (current_uiout
->is_mi_like_p ())
12880 case bp_tracepoint
:
12881 printf_filtered (_("Tracepoint"));
12882 printf_filtered (_(" %d"), b
->number
);
12884 case bp_fast_tracepoint
:
12885 printf_filtered (_("Fast tracepoint"));
12886 printf_filtered (_(" %d"), b
->number
);
12888 case bp_static_tracepoint
:
12889 printf_filtered (_("Static tracepoint"));
12890 printf_filtered (_(" %d"), b
->number
);
12893 internal_error (__FILE__
, __LINE__
,
12894 _("unhandled tracepoint type %d"), (int) b
->type
);
12901 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12903 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12905 if (self
->type
== bp_fast_tracepoint
)
12906 fprintf_unfiltered (fp
, "ftrace");
12907 else if (self
->type
== bp_static_tracepoint
)
12908 fprintf_unfiltered (fp
, "strace");
12909 else if (self
->type
== bp_tracepoint
)
12910 fprintf_unfiltered (fp
, "trace");
12912 internal_error (__FILE__
, __LINE__
,
12913 _("unhandled tracepoint type %d"), (int) self
->type
);
12915 fprintf_unfiltered (fp
, " %s",
12916 event_location_to_string (self
->location
.get ()));
12917 print_recreate_thread (self
, fp
);
12919 if (tp
->pass_count
)
12920 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12924 tracepoint_create_sals_from_location (struct event_location
*location
,
12925 struct linespec_result
*canonical
,
12926 enum bptype type_wanted
)
12928 create_sals_from_location_default (location
, canonical
, type_wanted
);
12932 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12933 struct linespec_result
*canonical
,
12934 gdb::unique_xmalloc_ptr
<char> cond_string
,
12935 gdb::unique_xmalloc_ptr
<char> extra_string
,
12936 enum bptype type_wanted
,
12937 enum bpdisp disposition
,
12939 int task
, int ignore_count
,
12940 const struct breakpoint_ops
*ops
,
12941 int from_tty
, int enabled
,
12942 int internal
, unsigned flags
)
12944 create_breakpoints_sal_default (gdbarch
, canonical
,
12945 std::move (cond_string
),
12946 std::move (extra_string
),
12948 disposition
, thread
, task
,
12949 ignore_count
, ops
, from_tty
,
12950 enabled
, internal
, flags
);
12953 static std::vector
<symtab_and_line
>
12954 tracepoint_decode_location (struct breakpoint
*b
,
12955 struct event_location
*location
,
12956 struct program_space
*search_pspace
)
12958 return decode_location_default (b
, location
, search_pspace
);
12961 struct breakpoint_ops tracepoint_breakpoint_ops
;
12963 /* Virtual table for tracepoints on static probes. */
12966 tracepoint_probe_create_sals_from_location
12967 (struct event_location
*location
,
12968 struct linespec_result
*canonical
,
12969 enum bptype type_wanted
)
12971 /* We use the same method for breakpoint on probes. */
12972 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
12975 static std::vector
<symtab_and_line
>
12976 tracepoint_probe_decode_location (struct breakpoint
*b
,
12977 struct event_location
*location
,
12978 struct program_space
*search_pspace
)
12980 /* We use the same method for breakpoint on probes. */
12981 return bkpt_probe_decode_location (b
, location
, search_pspace
);
12984 /* Dprintf breakpoint_ops methods. */
12987 dprintf_re_set (struct breakpoint
*b
)
12989 breakpoint_re_set_default (b
);
12991 /* extra_string should never be non-NULL for dprintf. */
12992 gdb_assert (b
->extra_string
!= NULL
);
12994 /* 1 - connect to target 1, that can run breakpoint commands.
12995 2 - create a dprintf, which resolves fine.
12996 3 - disconnect from target 1
12997 4 - connect to target 2, that can NOT run breakpoint commands.
12999 After steps #3/#4, you'll want the dprintf command list to
13000 be updated, because target 1 and 2 may well return different
13001 answers for target_can_run_breakpoint_commands().
13002 Given absence of finer grained resetting, we get to do
13003 it all the time. */
13004 if (b
->extra_string
!= NULL
)
13005 update_dprintf_command_list (b
);
13008 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13011 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13013 fprintf_unfiltered (fp
, "dprintf %s,%s",
13014 event_location_to_string (tp
->location
.get ()),
13016 print_recreate_thread (tp
, fp
);
13019 /* Implement the "after_condition_true" breakpoint_ops method for
13022 dprintf's are implemented with regular commands in their command
13023 list, but we run the commands here instead of before presenting the
13024 stop to the user, as dprintf's don't actually cause a stop. This
13025 also makes it so that the commands of multiple dprintfs at the same
13026 address are all handled. */
13029 dprintf_after_condition_true (struct bpstats
*bs
)
13031 struct bpstats tmp_bs
;
13032 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13034 /* dprintf's never cause a stop. This wasn't set in the
13035 check_status hook instead because that would make the dprintf's
13036 condition not be evaluated. */
13039 /* Run the command list here. Take ownership of it instead of
13040 copying. We never want these commands to run later in
13041 bpstat_do_actions, if a breakpoint that causes a stop happens to
13042 be set at same address as this dprintf, or even if running the
13043 commands here throws. */
13044 tmp_bs
.commands
= bs
->commands
;
13045 bs
->commands
= NULL
;
13047 bpstat_do_actions_1 (&tmp_bs_p
);
13049 /* 'tmp_bs.commands' will usually be NULL by now, but
13050 bpstat_do_actions_1 may return early without processing the whole
13054 /* The breakpoint_ops structure to be used on static tracepoints with
13058 strace_marker_create_sals_from_location (struct event_location
*location
,
13059 struct linespec_result
*canonical
,
13060 enum bptype type_wanted
)
13062 struct linespec_sals lsal
;
13063 const char *arg_start
, *arg
;
13065 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
13066 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13068 std::string
str (arg_start
, arg
- arg_start
);
13069 const char *ptr
= str
.c_str ();
13070 canonical
->location
13071 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
13074 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13075 canonical
->lsals
.push_back (std::move (lsal
));
13079 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13080 struct linespec_result
*canonical
,
13081 gdb::unique_xmalloc_ptr
<char> cond_string
,
13082 gdb::unique_xmalloc_ptr
<char> extra_string
,
13083 enum bptype type_wanted
,
13084 enum bpdisp disposition
,
13086 int task
, int ignore_count
,
13087 const struct breakpoint_ops
*ops
,
13088 int from_tty
, int enabled
,
13089 int internal
, unsigned flags
)
13091 const linespec_sals
&lsal
= canonical
->lsals
[0];
13093 /* If the user is creating a static tracepoint by marker id
13094 (strace -m MARKER_ID), then store the sals index, so that
13095 breakpoint_re_set can try to match up which of the newly
13096 found markers corresponds to this one, and, don't try to
13097 expand multiple locations for each sal, given than SALS
13098 already should contain all sals for MARKER_ID. */
13100 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13102 event_location_up location
13103 = copy_event_location (canonical
->location
.get ());
13105 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13106 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13107 std::move (location
), NULL
,
13108 std::move (cond_string
),
13109 std::move (extra_string
),
13110 type_wanted
, disposition
,
13111 thread
, task
, ignore_count
, ops
,
13112 from_tty
, enabled
, internal
, flags
,
13113 canonical
->special_display
);
13114 /* Given that its possible to have multiple markers with
13115 the same string id, if the user is creating a static
13116 tracepoint by marker id ("strace -m MARKER_ID"), then
13117 store the sals index, so that breakpoint_re_set can
13118 try to match up which of the newly found markers
13119 corresponds to this one */
13120 tp
->static_trace_marker_id_idx
= i
;
13122 install_breakpoint (internal
, std::move (tp
), 0);
13126 static std::vector
<symtab_and_line
>
13127 strace_marker_decode_location (struct breakpoint
*b
,
13128 struct event_location
*location
,
13129 struct program_space
*search_pspace
)
13131 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13132 const char *s
= get_linespec_location (location
)->spec_string
;
13134 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13135 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13137 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13142 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
13145 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13148 strace_marker_p (struct breakpoint
*b
)
13150 return b
->ops
== &strace_marker_breakpoint_ops
;
13153 /* Delete a breakpoint and clean up all traces of it in the data
13157 delete_breakpoint (struct breakpoint
*bpt
)
13159 gdb_assert (bpt
!= NULL
);
13161 /* Has this bp already been deleted? This can happen because
13162 multiple lists can hold pointers to bp's. bpstat lists are
13165 One example of this happening is a watchpoint's scope bp. When
13166 the scope bp triggers, we notice that the watchpoint is out of
13167 scope, and delete it. We also delete its scope bp. But the
13168 scope bp is marked "auto-deleting", and is already on a bpstat.
13169 That bpstat is then checked for auto-deleting bp's, which are
13172 A real solution to this problem might involve reference counts in
13173 bp's, and/or giving them pointers back to their referencing
13174 bpstat's, and teaching delete_breakpoint to only free a bp's
13175 storage when no more references were extent. A cheaper bandaid
13177 if (bpt
->type
== bp_none
)
13180 /* At least avoid this stale reference until the reference counting
13181 of breakpoints gets resolved. */
13182 if (bpt
->related_breakpoint
!= bpt
)
13184 struct breakpoint
*related
;
13185 struct watchpoint
*w
;
13187 if (bpt
->type
== bp_watchpoint_scope
)
13188 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13189 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13190 w
= (struct watchpoint
*) bpt
;
13194 watchpoint_del_at_next_stop (w
);
13196 /* Unlink bpt from the bpt->related_breakpoint ring. */
13197 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13198 related
= related
->related_breakpoint
);
13199 related
->related_breakpoint
= bpt
->related_breakpoint
;
13200 bpt
->related_breakpoint
= bpt
;
13203 /* watch_command_1 creates a watchpoint but only sets its number if
13204 update_watchpoint succeeds in creating its bp_locations. If there's
13205 a problem in that process, we'll be asked to delete the half-created
13206 watchpoint. In that case, don't announce the deletion. */
13208 gdb::observers::breakpoint_deleted
.notify (bpt
);
13210 if (breakpoint_chain
== bpt
)
13211 breakpoint_chain
= bpt
->next
;
13213 for (breakpoint
*b
: all_breakpoints ())
13214 if (b
->next
== bpt
)
13216 b
->next
= bpt
->next
;
13220 /* Be sure no bpstat's are pointing at the breakpoint after it's
13222 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13223 in all threads for now. Note that we cannot just remove bpstats
13224 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13225 commands are associated with the bpstat; if we remove it here,
13226 then the later call to bpstat_do_actions (&stop_bpstat); in
13227 event-top.c won't do anything, and temporary breakpoints with
13228 commands won't work. */
13230 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13232 /* Now that breakpoint is removed from breakpoint list, update the
13233 global location list. This will remove locations that used to
13234 belong to this breakpoint. Do this before freeing the breakpoint
13235 itself, since remove_breakpoint looks at location's owner. It
13236 might be better design to have location completely
13237 self-contained, but it's not the case now. */
13238 update_global_location_list (UGLL_DONT_INSERT
);
13240 /* On the chance that someone will soon try again to delete this
13241 same bp, we mark it as deleted before freeing its storage. */
13242 bpt
->type
= bp_none
;
13246 /* Iterator function to call a user-provided callback function once
13247 for each of B and its related breakpoints. */
13250 iterate_over_related_breakpoints (struct breakpoint
*b
,
13251 gdb::function_view
<void (breakpoint
*)> function
)
13253 struct breakpoint
*related
;
13258 struct breakpoint
*next
;
13260 /* FUNCTION may delete RELATED. */
13261 next
= related
->related_breakpoint
;
13263 if (next
== related
)
13265 /* RELATED is the last ring entry. */
13266 function (related
);
13268 /* FUNCTION may have deleted it, so we'd never reach back to
13269 B. There's nothing left to do anyway, so just break
13274 function (related
);
13278 while (related
!= b
);
13282 delete_command (const char *arg
, int from_tty
)
13288 int breaks_to_delete
= 0;
13290 /* Delete all breakpoints if no argument. Do not delete
13291 internal breakpoints, these have to be deleted with an
13292 explicit breakpoint number argument. */
13293 for (breakpoint
*b
: all_breakpoints ())
13294 if (user_breakpoint_p (b
))
13296 breaks_to_delete
= 1;
13300 /* Ask user only if there are some breakpoints to delete. */
13302 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13303 for (breakpoint
*b
: all_breakpoints_safe ())
13304 if (user_breakpoint_p (b
))
13305 delete_breakpoint (b
);
13308 map_breakpoint_numbers
13309 (arg
, [&] (breakpoint
*br
)
13311 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13315 /* Return true if all locations of B bound to PSPACE are pending. If
13316 PSPACE is NULL, all locations of all program spaces are
13320 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13322 for (bp_location
*loc
: b
->locations ())
13323 if ((pspace
== NULL
13324 || loc
->pspace
== pspace
)
13325 && !loc
->shlib_disabled
13326 && !loc
->pspace
->executing_startup
)
13331 /* Subroutine of update_breakpoint_locations to simplify it.
13332 Return non-zero if multiple fns in list LOC have the same name.
13333 Null names are ignored. */
13336 ambiguous_names_p (struct bp_location
*loc
)
13338 struct bp_location
*l
;
13339 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
13342 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13345 const char *name
= l
->function_name
;
13347 /* Allow for some names to be NULL, ignore them. */
13351 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
13353 /* NOTE: We can assume slot != NULL here because xcalloc never
13363 /* When symbols change, it probably means the sources changed as well,
13364 and it might mean the static tracepoint markers are no longer at
13365 the same address or line numbers they used to be at last we
13366 checked. Losing your static tracepoints whenever you rebuild is
13367 undesirable. This function tries to resync/rematch gdb static
13368 tracepoints with the markers on the target, for static tracepoints
13369 that have not been set by marker id. Static tracepoint that have
13370 been set by marker id are reset by marker id in breakpoint_re_set.
13373 1) For a tracepoint set at a specific address, look for a marker at
13374 the old PC. If one is found there, assume to be the same marker.
13375 If the name / string id of the marker found is different from the
13376 previous known name, assume that means the user renamed the marker
13377 in the sources, and output a warning.
13379 2) For a tracepoint set at a given line number, look for a marker
13380 at the new address of the old line number. If one is found there,
13381 assume to be the same marker. If the name / string id of the
13382 marker found is different from the previous known name, assume that
13383 means the user renamed the marker in the sources, and output a
13386 3) If a marker is no longer found at the same address or line, it
13387 may mean the marker no longer exists. But it may also just mean
13388 the code changed a bit. Maybe the user added a few lines of code
13389 that made the marker move up or down (in line number terms). Ask
13390 the target for info about the marker with the string id as we knew
13391 it. If found, update line number and address in the matching
13392 static tracepoint. This will get confused if there's more than one
13393 marker with the same ID (possible in UST, although unadvised
13394 precisely because it confuses tools). */
13396 static struct symtab_and_line
13397 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13399 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13400 struct static_tracepoint_marker marker
;
13405 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13407 if (target_static_tracepoint_marker_at (pc
, &marker
))
13409 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13410 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13411 b
->number
, tp
->static_trace_marker_id
.c_str (),
13412 marker
.str_id
.c_str ());
13414 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13419 /* Old marker wasn't found on target at lineno. Try looking it up
13421 if (!sal
.explicit_pc
13423 && sal
.symtab
!= NULL
13424 && !tp
->static_trace_marker_id
.empty ())
13426 std::vector
<static_tracepoint_marker
> markers
13427 = target_static_tracepoint_markers_by_strid
13428 (tp
->static_trace_marker_id
.c_str ());
13430 if (!markers
.empty ())
13432 struct symbol
*sym
;
13433 struct static_tracepoint_marker
*tpmarker
;
13434 struct ui_out
*uiout
= current_uiout
;
13435 struct explicit_location explicit_loc
;
13437 tpmarker
= &markers
[0];
13439 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13441 warning (_("marker for static tracepoint %d (%s) not "
13442 "found at previous line number"),
13443 b
->number
, tp
->static_trace_marker_id
.c_str ());
13445 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13446 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13447 uiout
->text ("Now in ");
13450 uiout
->field_string ("func", sym
->print_name (),
13451 function_name_style
.style ());
13452 uiout
->text (" at ");
13454 uiout
->field_string ("file",
13455 symtab_to_filename_for_display (sal2
.symtab
),
13456 file_name_style
.style ());
13459 if (uiout
->is_mi_like_p ())
13461 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13463 uiout
->field_string ("fullname", fullname
);
13466 uiout
->field_signed ("line", sal2
.line
);
13467 uiout
->text ("\n");
13469 b
->loc
->line_number
= sal2
.line
;
13470 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13472 b
->location
.reset (NULL
);
13473 initialize_explicit_location (&explicit_loc
);
13474 explicit_loc
.source_filename
13475 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13476 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13477 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13478 b
->location
= new_explicit_location (&explicit_loc
);
13480 /* Might be nice to check if function changed, and warn if
13487 /* Returns 1 iff locations A and B are sufficiently same that
13488 we don't need to report breakpoint as changed. */
13491 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13495 if (a
->address
!= b
->address
)
13498 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13501 if (a
->enabled
!= b
->enabled
)
13504 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
13511 if ((a
== NULL
) != (b
== NULL
))
13517 /* Split all locations of B that are bound to PSPACE out of B's
13518 location list to a separate list and return that list's head. If
13519 PSPACE is NULL, hoist out all locations of B. */
13521 static struct bp_location
*
13522 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13524 struct bp_location head
;
13525 struct bp_location
*i
= b
->loc
;
13526 struct bp_location
**i_link
= &b
->loc
;
13527 struct bp_location
*hoisted
= &head
;
13529 if (pspace
== NULL
)
13540 if (i
->pspace
== pspace
)
13555 /* Create new breakpoint locations for B (a hardware or software
13556 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13557 zero, then B is a ranged breakpoint. Only recreates locations for
13558 FILTER_PSPACE. Locations of other program spaces are left
13562 update_breakpoint_locations (struct breakpoint
*b
,
13563 struct program_space
*filter_pspace
,
13564 gdb::array_view
<const symtab_and_line
> sals
,
13565 gdb::array_view
<const symtab_and_line
> sals_end
)
13567 struct bp_location
*existing_locations
;
13569 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13571 /* Ranged breakpoints have only one start location and one end
13573 b
->enable_state
= bp_disabled
;
13574 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13575 "multiple locations found\n"),
13580 /* If there's no new locations, and all existing locations are
13581 pending, don't do anything. This optimizes the common case where
13582 all locations are in the same shared library, that was unloaded.
13583 We'd like to retain the location, so that when the library is
13584 loaded again, we don't loose the enabled/disabled status of the
13585 individual locations. */
13586 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13589 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13591 for (const auto &sal
: sals
)
13593 struct bp_location
*new_loc
;
13595 switch_to_program_space_and_thread (sal
.pspace
);
13597 new_loc
= add_location_to_breakpoint (b
, &sal
);
13599 /* Reparse conditions, they might contain references to the
13601 if (b
->cond_string
!= NULL
)
13605 s
= b
->cond_string
;
13608 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13609 block_for_pc (sal
.pc
),
13612 catch (const gdb_exception_error
&e
)
13614 new_loc
->disabled_by_cond
= true;
13618 if (!sals_end
.empty ())
13620 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13622 new_loc
->length
= end
- sals
[0].pc
+ 1;
13626 /* If possible, carry over 'disable' status from existing
13629 struct bp_location
*e
= existing_locations
;
13630 /* If there are multiple breakpoints with the same function name,
13631 e.g. for inline functions, comparing function names won't work.
13632 Instead compare pc addresses; this is just a heuristic as things
13633 may have moved, but in practice it gives the correct answer
13634 often enough until a better solution is found. */
13635 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13637 for (; e
; e
= e
->next
)
13639 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
13641 if (have_ambiguous_names
)
13643 for (bp_location
*l
: b
->locations ())
13645 /* Ignore software vs hardware location type at
13646 this point, because with "set breakpoint
13647 auto-hw", after a re-set, locations that were
13648 hardware can end up as software, or vice versa.
13649 As mentioned above, this is an heuristic and in
13650 practice should give the correct answer often
13652 if (breakpoint_locations_match (e
, l
, true))
13654 l
->enabled
= e
->enabled
;
13655 l
->disabled_by_cond
= e
->disabled_by_cond
;
13662 for (bp_location
*l
: b
->locations ())
13663 if (l
->function_name
13664 && strcmp (e
->function_name
, l
->function_name
) == 0)
13666 l
->enabled
= e
->enabled
;
13667 l
->disabled_by_cond
= e
->disabled_by_cond
;
13675 if (!locations_are_equal (existing_locations
, b
->loc
))
13676 gdb::observers::breakpoint_modified
.notify (b
);
13679 /* Find the SaL locations corresponding to the given LOCATION.
13680 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13682 static std::vector
<symtab_and_line
>
13683 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13684 struct program_space
*search_pspace
, int *found
)
13686 struct gdb_exception exception
;
13688 gdb_assert (b
->ops
!= NULL
);
13690 std::vector
<symtab_and_line
> sals
;
13694 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13696 catch (gdb_exception_error
&e
)
13698 int not_found_and_ok
= 0;
13700 /* For pending breakpoints, it's expected that parsing will
13701 fail until the right shared library is loaded. User has
13702 already told to create pending breakpoints and don't need
13703 extra messages. If breakpoint is in bp_shlib_disabled
13704 state, then user already saw the message about that
13705 breakpoint being disabled, and don't want to see more
13707 if (e
.error
== NOT_FOUND_ERROR
13708 && (b
->condition_not_parsed
13710 && search_pspace
!= NULL
13711 && b
->loc
->pspace
!= search_pspace
)
13712 || (b
->loc
&& b
->loc
->shlib_disabled
)
13713 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13714 || b
->enable_state
== bp_disabled
))
13715 not_found_and_ok
= 1;
13717 if (!not_found_and_ok
)
13719 /* We surely don't want to warn about the same breakpoint
13720 10 times. One solution, implemented here, is disable
13721 the breakpoint on error. Another solution would be to
13722 have separate 'warning emitted' flag. Since this
13723 happens only when a binary has changed, I don't know
13724 which approach is better. */
13725 b
->enable_state
= bp_disabled
;
13729 exception
= std::move (e
);
13732 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13734 for (auto &sal
: sals
)
13735 resolve_sal_pc (&sal
);
13736 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13738 char *cond_string
, *extra_string
;
13741 find_condition_and_thread_for_sals (sals
, b
->extra_string
,
13742 &cond_string
, &thread
,
13743 &task
, &extra_string
);
13744 gdb_assert (b
->cond_string
== NULL
);
13746 b
->cond_string
= cond_string
;
13747 b
->thread
= thread
;
13751 xfree (b
->extra_string
);
13752 b
->extra_string
= extra_string
;
13754 b
->condition_not_parsed
= 0;
13757 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13758 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13768 /* The default re_set method, for typical hardware or software
13769 breakpoints. Reevaluate the breakpoint and recreate its
13773 breakpoint_re_set_default (struct breakpoint
*b
)
13775 struct program_space
*filter_pspace
= current_program_space
;
13776 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13779 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13780 filter_pspace
, &found
);
13782 expanded
= std::move (sals
);
13784 if (b
->location_range_end
!= NULL
)
13786 std::vector
<symtab_and_line
> sals_end
13787 = location_to_sals (b
, b
->location_range_end
.get (),
13788 filter_pspace
, &found
);
13790 expanded_end
= std::move (sals_end
);
13793 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13796 /* Default method for creating SALs from an address string. It basically
13797 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13800 create_sals_from_location_default (struct event_location
*location
,
13801 struct linespec_result
*canonical
,
13802 enum bptype type_wanted
)
13804 parse_breakpoint_sals (location
, canonical
);
13807 /* Call create_breakpoints_sal for the given arguments. This is the default
13808 function for the `create_breakpoints_sal' method of
13812 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13813 struct linespec_result
*canonical
,
13814 gdb::unique_xmalloc_ptr
<char> cond_string
,
13815 gdb::unique_xmalloc_ptr
<char> extra_string
,
13816 enum bptype type_wanted
,
13817 enum bpdisp disposition
,
13819 int task
, int ignore_count
,
13820 const struct breakpoint_ops
*ops
,
13821 int from_tty
, int enabled
,
13822 int internal
, unsigned flags
)
13824 create_breakpoints_sal (gdbarch
, canonical
,
13825 std::move (cond_string
),
13826 std::move (extra_string
),
13827 type_wanted
, disposition
,
13828 thread
, task
, ignore_count
, ops
, from_tty
,
13829 enabled
, internal
, flags
);
13832 /* Decode the line represented by S by calling decode_line_full. This is the
13833 default function for the `decode_location' method of breakpoint_ops. */
13835 static std::vector
<symtab_and_line
>
13836 decode_location_default (struct breakpoint
*b
,
13837 struct event_location
*location
,
13838 struct program_space
*search_pspace
)
13840 struct linespec_result canonical
;
13842 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13843 NULL
, 0, &canonical
, multiple_symbols_all
,
13846 /* We should get 0 or 1 resulting SALs. */
13847 gdb_assert (canonical
.lsals
.size () < 2);
13849 if (!canonical
.lsals
.empty ())
13851 const linespec_sals
&lsal
= canonical
.lsals
[0];
13852 return std::move (lsal
.sals
);
13857 /* Reset a breakpoint. */
13860 breakpoint_re_set_one (breakpoint
*b
)
13862 input_radix
= b
->input_radix
;
13863 set_language (b
->language
);
13865 b
->ops
->re_set (b
);
13868 /* Re-set breakpoint locations for the current program space.
13869 Locations bound to other program spaces are left untouched. */
13872 breakpoint_re_set (void)
13875 scoped_restore_current_language save_language
;
13876 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13877 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13879 /* breakpoint_re_set_one sets the current_language to the language
13880 of the breakpoint it is resetting (see prepare_re_set_context)
13881 before re-evaluating the breakpoint's location. This change can
13882 unfortunately get undone by accident if the language_mode is set
13883 to auto, and we either switch frames, or more likely in this context,
13884 we select the current frame.
13886 We prevent this by temporarily turning the language_mode to
13887 language_mode_manual. We restore it once all breakpoints
13888 have been reset. */
13889 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13890 language_mode
= language_mode_manual
;
13892 /* Note: we must not try to insert locations until after all
13893 breakpoints have been re-set. Otherwise, e.g., when re-setting
13894 breakpoint 1, we'd insert the locations of breakpoint 2, which
13895 hadn't been re-set yet, and thus may have stale locations. */
13897 for (breakpoint
*b
: all_breakpoints_safe ())
13901 breakpoint_re_set_one (b
);
13903 catch (const gdb_exception
&ex
)
13905 exception_fprintf (gdb_stderr
, ex
,
13906 "Error in re-setting breakpoint %d: ",
13911 jit_breakpoint_re_set ();
13914 create_overlay_event_breakpoint ();
13915 create_longjmp_master_breakpoint ();
13916 create_std_terminate_master_breakpoint ();
13917 create_exception_master_breakpoint ();
13919 /* Now we can insert. */
13920 update_global_location_list (UGLL_MAY_INSERT
);
13923 /* Reset the thread number of this breakpoint:
13925 - If the breakpoint is for all threads, leave it as-is.
13926 - Else, reset it to the current thread for inferior_ptid. */
13928 breakpoint_re_set_thread (struct breakpoint
*b
)
13930 if (b
->thread
!= -1)
13932 b
->thread
= inferior_thread ()->global_num
;
13934 /* We're being called after following a fork. The new fork is
13935 selected as current, and unless this was a vfork will have a
13936 different program space from the original thread. Reset that
13938 b
->loc
->pspace
= current_program_space
;
13942 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13943 If from_tty is nonzero, it prints a message to that effect,
13944 which ends with a period (no newline). */
13947 set_ignore_count (int bptnum
, int count
, int from_tty
)
13952 for (breakpoint
*b
: all_breakpoints ())
13953 if (b
->number
== bptnum
)
13955 if (is_tracepoint (b
))
13957 if (from_tty
&& count
!= 0)
13958 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13963 b
->ignore_count
= count
;
13967 printf_filtered (_("Will stop next time "
13968 "breakpoint %d is reached."),
13970 else if (count
== 1)
13971 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13974 printf_filtered (_("Will ignore next %d "
13975 "crossings of breakpoint %d."),
13978 gdb::observers::breakpoint_modified
.notify (b
);
13982 error (_("No breakpoint number %d."), bptnum
);
13985 /* Command to set ignore-count of breakpoint N to COUNT. */
13988 ignore_command (const char *args
, int from_tty
)
13990 const char *p
= args
;
13994 error_no_arg (_("a breakpoint number"));
13996 num
= get_number (&p
);
13998 error (_("bad breakpoint number: '%s'"), args
);
14000 error (_("Second argument (specified ignore-count) is missing."));
14002 set_ignore_count (num
,
14003 longest_to_int (value_as_long (parse_and_eval (p
))),
14006 printf_filtered ("\n");
14010 /* Call FUNCTION on each of the breakpoints with numbers in the range
14011 defined by BP_NUM_RANGE (an inclusive range). */
14014 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
14015 gdb::function_view
<void (breakpoint
*)> function
)
14017 if (bp_num_range
.first
== 0)
14019 warning (_("bad breakpoint number at or near '%d'"),
14020 bp_num_range
.first
);
14024 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
14026 bool match
= false;
14028 for (breakpoint
*b
: all_breakpoints_safe ())
14029 if (b
->number
== i
)
14036 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
14041 /* Call FUNCTION on each of the breakpoints whose numbers are given in
14045 map_breakpoint_numbers (const char *args
,
14046 gdb::function_view
<void (breakpoint
*)> function
)
14048 if (args
== NULL
|| *args
== '\0')
14049 error_no_arg (_("one or more breakpoint numbers"));
14051 number_or_range_parser
parser (args
);
14053 while (!parser
.finished ())
14055 int num
= parser
.get_number ();
14056 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
14060 /* Return the breakpoint location structure corresponding to the
14061 BP_NUM and LOC_NUM values. */
14063 static struct bp_location
*
14064 find_location_by_number (int bp_num
, int loc_num
)
14066 breakpoint
*b
= get_breakpoint (bp_num
);
14068 if (!b
|| b
->number
!= bp_num
)
14069 error (_("Bad breakpoint number '%d'"), bp_num
);
14072 error (_("Bad breakpoint location number '%d'"), loc_num
);
14075 for (bp_location
*loc
: b
->locations ())
14076 if (++n
== loc_num
)
14079 error (_("Bad breakpoint location number '%d'"), loc_num
);
14082 /* Modes of operation for extract_bp_num. */
14083 enum class extract_bp_kind
14085 /* Extracting a breakpoint number. */
14088 /* Extracting a location number. */
14092 /* Extract a breakpoint or location number (as determined by KIND)
14093 from the string starting at START. TRAILER is a character which
14094 can be found after the number. If you don't want a trailer, use
14095 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14096 string. This always returns a positive integer. */
14099 extract_bp_num (extract_bp_kind kind
, const char *start
,
14100 int trailer
, const char **end_out
= NULL
)
14102 const char *end
= start
;
14103 int num
= get_number_trailer (&end
, trailer
);
14105 error (kind
== extract_bp_kind::bp
14106 ? _("Negative breakpoint number '%.*s'")
14107 : _("Negative breakpoint location number '%.*s'"),
14108 int (end
- start
), start
);
14110 error (kind
== extract_bp_kind::bp
14111 ? _("Bad breakpoint number '%.*s'")
14112 : _("Bad breakpoint location number '%.*s'"),
14113 int (end
- start
), start
);
14115 if (end_out
!= NULL
)
14120 /* Extract a breakpoint or location range (as determined by KIND) in
14121 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14122 representing the (inclusive) range. The returned pair's elements
14123 are always positive integers. */
14125 static std::pair
<int, int>
14126 extract_bp_or_bp_range (extract_bp_kind kind
,
14127 const std::string
&arg
,
14128 std::string::size_type arg_offset
)
14130 std::pair
<int, int> range
;
14131 const char *bp_loc
= &arg
[arg_offset
];
14132 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14133 if (dash
!= std::string::npos
)
14135 /* bp_loc is a range (x-z). */
14136 if (arg
.length () == dash
+ 1)
14137 error (kind
== extract_bp_kind::bp
14138 ? _("Bad breakpoint number at or near: '%s'")
14139 : _("Bad breakpoint location number at or near: '%s'"),
14143 const char *start_first
= bp_loc
;
14144 const char *start_second
= &arg
[dash
+ 1];
14145 range
.first
= extract_bp_num (kind
, start_first
, '-');
14146 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14148 if (range
.first
> range
.second
)
14149 error (kind
== extract_bp_kind::bp
14150 ? _("Inverted breakpoint range at '%.*s'")
14151 : _("Inverted breakpoint location range at '%.*s'"),
14152 int (end
- start_first
), start_first
);
14156 /* bp_loc is a single value. */
14157 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14158 range
.second
= range
.first
;
14163 /* Extract the breakpoint/location range specified by ARG. Returns
14164 the breakpoint range in BP_NUM_RANGE, and the location range in
14167 ARG may be in any of the following forms:
14169 x where 'x' is a breakpoint number.
14170 x-y where 'x' and 'y' specify a breakpoint numbers range.
14171 x.y where 'x' is a breakpoint number and 'y' a location number.
14172 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14173 location number range.
14177 extract_bp_number_and_location (const std::string
&arg
,
14178 std::pair
<int, int> &bp_num_range
,
14179 std::pair
<int, int> &bp_loc_range
)
14181 std::string::size_type dot
= arg
.find ('.');
14183 if (dot
!= std::string::npos
)
14185 /* Handle 'x.y' and 'x.y-z' cases. */
14187 if (arg
.length () == dot
+ 1 || dot
== 0)
14188 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14191 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14192 bp_num_range
.second
= bp_num_range
.first
;
14194 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14199 /* Handle x and x-y cases. */
14201 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14202 bp_loc_range
.first
= 0;
14203 bp_loc_range
.second
= 0;
14207 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14208 specifies whether to enable or disable. */
14211 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14213 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14216 if (loc
->disabled_by_cond
&& enable
)
14217 error (_("Breakpoint %d's condition is invalid at location %d, "
14218 "cannot enable."), bp_num
, loc_num
);
14220 if (loc
->enabled
!= enable
)
14222 loc
->enabled
= enable
;
14223 mark_breakpoint_location_modified (loc
);
14225 if (target_supports_enable_disable_tracepoint ()
14226 && current_trace_status ()->running
&& loc
->owner
14227 && is_tracepoint (loc
->owner
))
14228 target_disable_tracepoint (loc
);
14230 update_global_location_list (UGLL_DONT_INSERT
);
14232 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14235 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14236 number of the breakpoint, and BP_LOC_RANGE specifies the
14237 (inclusive) range of location numbers of that breakpoint to
14238 enable/disable. ENABLE specifies whether to enable or disable the
14242 enable_disable_breakpoint_location_range (int bp_num
,
14243 std::pair
<int, int> &bp_loc_range
,
14246 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14247 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14250 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14251 If from_tty is nonzero, it prints a message to that effect,
14252 which ends with a period (no newline). */
14255 disable_breakpoint (struct breakpoint
*bpt
)
14257 /* Never disable a watchpoint scope breakpoint; we want to
14258 hit them when we leave scope so we can delete both the
14259 watchpoint and its scope breakpoint at that time. */
14260 if (bpt
->type
== bp_watchpoint_scope
)
14263 bpt
->enable_state
= bp_disabled
;
14265 /* Mark breakpoint locations modified. */
14266 mark_breakpoint_modified (bpt
);
14268 if (target_supports_enable_disable_tracepoint ()
14269 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14271 for (bp_location
*location
: bpt
->locations ())
14272 target_disable_tracepoint (location
);
14275 update_global_location_list (UGLL_DONT_INSERT
);
14277 gdb::observers::breakpoint_modified
.notify (bpt
);
14280 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14281 specified in ARGS. ARGS may be in any of the formats handled by
14282 extract_bp_number_and_location. ENABLE specifies whether to enable
14283 or disable the breakpoints/locations. */
14286 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14290 for (breakpoint
*bpt
: all_breakpoints ())
14291 if (user_breakpoint_p (bpt
))
14294 enable_breakpoint (bpt
);
14296 disable_breakpoint (bpt
);
14301 std::string num
= extract_arg (&args
);
14303 while (!num
.empty ())
14305 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14307 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14309 if (bp_loc_range
.first
== bp_loc_range
.second
14310 && bp_loc_range
.first
== 0)
14312 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14313 map_breakpoint_number_range (bp_num_range
,
14315 ? enable_breakpoint
14316 : disable_breakpoint
);
14320 /* Handle breakpoint ids with formats 'x.y' or
14322 enable_disable_breakpoint_location_range
14323 (bp_num_range
.first
, bp_loc_range
, enable
);
14325 num
= extract_arg (&args
);
14330 /* The disable command disables the specified breakpoints/locations
14331 (or all defined breakpoints) so they're no longer effective in
14332 stopping the inferior. ARGS may be in any of the forms defined in
14333 extract_bp_number_and_location. */
14336 disable_command (const char *args
, int from_tty
)
14338 enable_disable_command (args
, from_tty
, false);
14342 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14345 int target_resources_ok
;
14347 if (bpt
->type
== bp_hardware_breakpoint
)
14350 i
= hw_breakpoint_used_count ();
14351 target_resources_ok
=
14352 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14354 if (target_resources_ok
== 0)
14355 error (_("No hardware breakpoint support in the target."));
14356 else if (target_resources_ok
< 0)
14357 error (_("Hardware breakpoints used exceeds limit."));
14360 if (is_watchpoint (bpt
))
14362 /* Initialize it just to avoid a GCC false warning. */
14363 enum enable_state orig_enable_state
= bp_disabled
;
14367 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14369 orig_enable_state
= bpt
->enable_state
;
14370 bpt
->enable_state
= bp_enabled
;
14371 update_watchpoint (w
, 1 /* reparse */);
14373 catch (const gdb_exception
&e
)
14375 bpt
->enable_state
= orig_enable_state
;
14376 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14382 bpt
->enable_state
= bp_enabled
;
14384 /* Mark breakpoint locations modified. */
14385 mark_breakpoint_modified (bpt
);
14387 if (target_supports_enable_disable_tracepoint ()
14388 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14390 for (bp_location
*location
: bpt
->locations ())
14391 target_enable_tracepoint (location
);
14394 bpt
->disposition
= disposition
;
14395 bpt
->enable_count
= count
;
14396 update_global_location_list (UGLL_MAY_INSERT
);
14398 gdb::observers::breakpoint_modified
.notify (bpt
);
14403 enable_breakpoint (struct breakpoint
*bpt
)
14405 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14408 /* The enable command enables the specified breakpoints/locations (or
14409 all defined breakpoints) so they once again become (or continue to
14410 be) effective in stopping the inferior. ARGS may be in any of the
14411 forms defined in extract_bp_number_and_location. */
14414 enable_command (const char *args
, int from_tty
)
14416 enable_disable_command (args
, from_tty
, true);
14420 enable_once_command (const char *args
, int from_tty
)
14422 map_breakpoint_numbers
14423 (args
, [&] (breakpoint
*b
)
14425 iterate_over_related_breakpoints
14426 (b
, [&] (breakpoint
*bpt
)
14428 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14434 enable_count_command (const char *args
, int from_tty
)
14439 error_no_arg (_("hit count"));
14441 count
= get_number (&args
);
14443 map_breakpoint_numbers
14444 (args
, [&] (breakpoint
*b
)
14446 iterate_over_related_breakpoints
14447 (b
, [&] (breakpoint
*bpt
)
14449 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14455 enable_delete_command (const char *args
, int from_tty
)
14457 map_breakpoint_numbers
14458 (args
, [&] (breakpoint
*b
)
14460 iterate_over_related_breakpoints
14461 (b
, [&] (breakpoint
*bpt
)
14463 enable_breakpoint_disp (bpt
, disp_del
, 1);
14468 /* Invalidate last known value of any hardware watchpoint if
14469 the memory which that value represents has been written to by
14473 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14474 CORE_ADDR addr
, ssize_t len
,
14475 const bfd_byte
*data
)
14477 for (breakpoint
*bp
: all_breakpoints ())
14478 if (bp
->enable_state
== bp_enabled
14479 && bp
->type
== bp_hardware_watchpoint
)
14481 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14483 if (wp
->val_valid
&& wp
->val
!= nullptr)
14485 for (bp_location
*loc
: bp
->locations ())
14486 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14487 && loc
->address
+ loc
->length
> addr
14488 && addr
+ len
> loc
->address
)
14491 wp
->val_valid
= false;
14497 /* Create and insert a breakpoint for software single step. */
14500 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14501 const address_space
*aspace
,
14504 struct thread_info
*tp
= inferior_thread ();
14505 struct symtab_and_line sal
;
14506 CORE_ADDR pc
= next_pc
;
14508 if (tp
->control
.single_step_breakpoints
== NULL
)
14510 tp
->control
.single_step_breakpoints
14511 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14514 sal
= find_pc_line (pc
, 0);
14516 sal
.section
= find_pc_overlay (pc
);
14517 sal
.explicit_pc
= 1;
14518 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14520 update_global_location_list (UGLL_INSERT
);
14523 /* Insert single step breakpoints according to the current state. */
14526 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14528 struct regcache
*regcache
= get_current_regcache ();
14529 std::vector
<CORE_ADDR
> next_pcs
;
14531 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14533 if (!next_pcs
.empty ())
14535 struct frame_info
*frame
= get_current_frame ();
14536 const address_space
*aspace
= get_frame_address_space (frame
);
14538 for (CORE_ADDR pc
: next_pcs
)
14539 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14547 /* See breakpoint.h. */
14550 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14551 const address_space
*aspace
,
14554 for (bp_location
*loc
: bp
->locations ())
14556 && breakpoint_location_address_match (loc
, aspace
, pc
))
14562 /* Check whether a software single-step breakpoint is inserted at
14566 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14569 for (breakpoint
*bpt
: all_breakpoints ())
14571 if (bpt
->type
== bp_single_step
14572 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14578 /* Tracepoint-specific operations. */
14580 /* Set tracepoint count to NUM. */
14582 set_tracepoint_count (int num
)
14584 tracepoint_count
= num
;
14585 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14589 trace_command (const char *arg
, int from_tty
)
14591 event_location_up location
= string_to_event_location (&arg
,
14593 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
14594 (location
.get (), true /* is_tracepoint */);
14596 create_breakpoint (get_current_arch (),
14598 NULL
, 0, arg
, false, 1 /* parse arg */,
14600 bp_tracepoint
/* type_wanted */,
14601 0 /* Ignore count */,
14602 pending_break_support
,
14606 0 /* internal */, 0);
14610 ftrace_command (const char *arg
, int from_tty
)
14612 event_location_up location
= string_to_event_location (&arg
,
14614 create_breakpoint (get_current_arch (),
14616 NULL
, 0, arg
, false, 1 /* parse arg */,
14618 bp_fast_tracepoint
/* type_wanted */,
14619 0 /* Ignore count */,
14620 pending_break_support
,
14621 &tracepoint_breakpoint_ops
,
14624 0 /* internal */, 0);
14627 /* strace command implementation. Creates a static tracepoint. */
14630 strace_command (const char *arg
, int from_tty
)
14632 struct breakpoint_ops
*ops
;
14633 event_location_up location
;
14635 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14636 or with a normal static tracepoint. */
14637 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14639 ops
= &strace_marker_breakpoint_ops
;
14640 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14644 ops
= &tracepoint_breakpoint_ops
;
14645 location
= string_to_event_location (&arg
, current_language
);
14648 create_breakpoint (get_current_arch (),
14650 NULL
, 0, arg
, false, 1 /* parse arg */,
14652 bp_static_tracepoint
/* type_wanted */,
14653 0 /* Ignore count */,
14654 pending_break_support
,
14658 0 /* internal */, 0);
14661 /* Set up a fake reader function that gets command lines from a linked
14662 list that was acquired during tracepoint uploading. */
14664 static struct uploaded_tp
*this_utp
;
14665 static int next_cmd
;
14668 read_uploaded_action (void)
14670 char *rslt
= nullptr;
14672 if (next_cmd
< this_utp
->cmd_strings
.size ())
14674 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14681 /* Given information about a tracepoint as recorded on a target (which
14682 can be either a live system or a trace file), attempt to create an
14683 equivalent GDB tracepoint. This is not a reliable process, since
14684 the target does not necessarily have all the information used when
14685 the tracepoint was originally defined. */
14687 struct tracepoint
*
14688 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14690 const char *addr_str
;
14691 char small_buf
[100];
14692 struct tracepoint
*tp
;
14694 if (utp
->at_string
)
14695 addr_str
= utp
->at_string
.get ();
14698 /* In the absence of a source location, fall back to raw
14699 address. Since there is no way to confirm that the address
14700 means the same thing as when the trace was started, warn the
14702 warning (_("Uploaded tracepoint %d has no "
14703 "source location, using raw address"),
14705 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14706 addr_str
= small_buf
;
14709 /* There's not much we can do with a sequence of bytecodes. */
14710 if (utp
->cond
&& !utp
->cond_string
)
14711 warning (_("Uploaded tracepoint %d condition "
14712 "has no source form, ignoring it"),
14715 event_location_up location
= string_to_event_location (&addr_str
,
14717 if (!create_breakpoint (get_current_arch (),
14719 utp
->cond_string
.get (), -1, addr_str
,
14720 false /* force_condition */,
14721 0 /* parse cond/thread */,
14723 utp
->type
/* type_wanted */,
14724 0 /* Ignore count */,
14725 pending_break_support
,
14726 &tracepoint_breakpoint_ops
,
14728 utp
->enabled
/* enabled */,
14730 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14733 /* Get the tracepoint we just created. */
14734 tp
= get_tracepoint (tracepoint_count
);
14735 gdb_assert (tp
!= NULL
);
14739 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14742 trace_pass_command (small_buf
, 0);
14745 /* If we have uploaded versions of the original commands, set up a
14746 special-purpose "reader" function and call the usual command line
14747 reader, then pass the result to the breakpoint command-setting
14749 if (!utp
->cmd_strings
.empty ())
14751 counted_command_line cmd_list
;
14756 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14758 breakpoint_set_commands (tp
, std::move (cmd_list
));
14760 else if (!utp
->actions
.empty ()
14761 || !utp
->step_actions
.empty ())
14762 warning (_("Uploaded tracepoint %d actions "
14763 "have no source form, ignoring them"),
14766 /* Copy any status information that might be available. */
14767 tp
->hit_count
= utp
->hit_count
;
14768 tp
->traceframe_usage
= utp
->traceframe_usage
;
14773 /* Print information on tracepoint number TPNUM_EXP, or all if
14777 info_tracepoints_command (const char *args
, int from_tty
)
14779 struct ui_out
*uiout
= current_uiout
;
14782 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14784 if (num_printed
== 0)
14786 if (args
== NULL
|| *args
== '\0')
14787 uiout
->message ("No tracepoints.\n");
14789 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14792 default_collect_info ();
14795 /* The 'enable trace' command enables tracepoints.
14796 Not supported by all targets. */
14798 enable_trace_command (const char *args
, int from_tty
)
14800 enable_command (args
, from_tty
);
14803 /* The 'disable trace' command disables tracepoints.
14804 Not supported by all targets. */
14806 disable_trace_command (const char *args
, int from_tty
)
14808 disable_command (args
, from_tty
);
14811 /* Remove a tracepoint (or all if no argument). */
14813 delete_trace_command (const char *arg
, int from_tty
)
14819 int breaks_to_delete
= 0;
14821 /* Delete all breakpoints if no argument.
14822 Do not delete internal or call-dummy breakpoints, these
14823 have to be deleted with an explicit breakpoint number
14825 for (breakpoint
*tp
: all_tracepoints ())
14826 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
14828 breaks_to_delete
= 1;
14832 /* Ask user only if there are some breakpoints to delete. */
14834 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14836 for (breakpoint
*b
: all_breakpoints_safe ())
14837 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14838 delete_breakpoint (b
);
14842 map_breakpoint_numbers
14843 (arg
, [&] (breakpoint
*br
)
14845 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14849 /* Helper function for trace_pass_command. */
14852 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14854 tp
->pass_count
= count
;
14855 gdb::observers::breakpoint_modified
.notify (tp
);
14857 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14858 tp
->number
, count
);
14861 /* Set passcount for tracepoint.
14863 First command argument is passcount, second is tracepoint number.
14864 If tracepoint number omitted, apply to most recently defined.
14865 Also accepts special argument "all". */
14868 trace_pass_command (const char *args
, int from_tty
)
14870 struct tracepoint
*t1
;
14873 if (args
== 0 || *args
== 0)
14874 error (_("passcount command requires an "
14875 "argument (count + optional TP num)"));
14877 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14879 args
= skip_spaces (args
);
14880 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14882 args
+= 3; /* Skip special argument "all". */
14884 error (_("Junk at end of arguments."));
14886 for (breakpoint
*b
: all_tracepoints ())
14888 t1
= (struct tracepoint
*) b
;
14889 trace_pass_set_count (t1
, count
, from_tty
);
14892 else if (*args
== '\0')
14894 t1
= get_tracepoint_by_number (&args
, NULL
);
14896 trace_pass_set_count (t1
, count
, from_tty
);
14900 number_or_range_parser
parser (args
);
14901 while (!parser
.finished ())
14903 t1
= get_tracepoint_by_number (&args
, &parser
);
14905 trace_pass_set_count (t1
, count
, from_tty
);
14910 struct tracepoint
*
14911 get_tracepoint (int num
)
14913 for (breakpoint
*t
: all_tracepoints ())
14914 if (t
->number
== num
)
14915 return (struct tracepoint
*) t
;
14920 /* Find the tracepoint with the given target-side number (which may be
14921 different from the tracepoint number after disconnecting and
14924 struct tracepoint
*
14925 get_tracepoint_by_number_on_target (int num
)
14927 for (breakpoint
*b
: all_tracepoints ())
14929 struct tracepoint
*t
= (struct tracepoint
*) b
;
14931 if (t
->number_on_target
== num
)
14938 /* Utility: parse a tracepoint number and look it up in the list.
14939 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14940 If the argument is missing, the most recent tracepoint
14941 (tracepoint_count) is returned. */
14943 struct tracepoint
*
14944 get_tracepoint_by_number (const char **arg
,
14945 number_or_range_parser
*parser
)
14948 const char *instring
= arg
== NULL
? NULL
: *arg
;
14950 if (parser
!= NULL
)
14952 gdb_assert (!parser
->finished ());
14953 tpnum
= parser
->get_number ();
14955 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14956 tpnum
= tracepoint_count
;
14958 tpnum
= get_number (arg
);
14962 if (instring
&& *instring
)
14963 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14966 printf_filtered (_("No previous tracepoint\n"));
14970 for (breakpoint
*t
: all_tracepoints ())
14971 if (t
->number
== tpnum
)
14972 return (struct tracepoint
*) t
;
14974 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
14979 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14981 if (b
->thread
!= -1)
14982 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
14985 fprintf_unfiltered (fp
, " task %d", b
->task
);
14987 fprintf_unfiltered (fp
, "\n");
14990 /* Save information on user settable breakpoints (watchpoints, etc) to
14991 a new script file named FILENAME. If FILTER is non-NULL, call it
14992 on each breakpoint and only include the ones for which it returns
14996 save_breakpoints (const char *filename
, int from_tty
,
14997 bool (*filter
) (const struct breakpoint
*))
15000 int extra_trace_bits
= 0;
15002 if (filename
== 0 || *filename
== 0)
15003 error (_("Argument required (file name in which to save)"));
15005 /* See if we have anything to save. */
15006 for (breakpoint
*tp
: all_breakpoints ())
15008 /* Skip internal and momentary breakpoints. */
15009 if (!user_breakpoint_p (tp
))
15012 /* If we have a filter, only save the breakpoints it accepts. */
15013 if (filter
&& !filter (tp
))
15018 if (is_tracepoint (tp
))
15020 extra_trace_bits
= 1;
15022 /* We can stop searching. */
15029 warning (_("Nothing to save."));
15033 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15037 if (!fp
.open (expanded_filename
.get (), "w"))
15038 error (_("Unable to open file '%s' for saving (%s)"),
15039 expanded_filename
.get (), safe_strerror (errno
));
15041 if (extra_trace_bits
)
15042 save_trace_state_variables (&fp
);
15044 for (breakpoint
*tp
: all_breakpoints ())
15046 /* Skip internal and momentary breakpoints. */
15047 if (!user_breakpoint_p (tp
))
15050 /* If we have a filter, only save the breakpoints it accepts. */
15051 if (filter
&& !filter (tp
))
15054 tp
->ops
->print_recreate (tp
, &fp
);
15056 /* Note, we can't rely on tp->number for anything, as we can't
15057 assume the recreated breakpoint numbers will match. Use $bpnum
15060 if (tp
->cond_string
)
15061 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15063 if (tp
->ignore_count
)
15064 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15066 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15068 fp
.puts (" commands\n");
15070 current_uiout
->redirect (&fp
);
15073 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15075 catch (const gdb_exception
&ex
)
15077 current_uiout
->redirect (NULL
);
15081 current_uiout
->redirect (NULL
);
15082 fp
.puts (" end\n");
15085 if (tp
->enable_state
== bp_disabled
)
15086 fp
.puts ("disable $bpnum\n");
15088 /* If this is a multi-location breakpoint, check if the locations
15089 should be individually disabled. Watchpoint locations are
15090 special, and not user visible. */
15091 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15095 for (bp_location
*loc
: tp
->locations ())
15098 fp
.printf ("disable $bpnum.%d\n", n
);
15105 if (extra_trace_bits
&& *default_collect
)
15106 fp
.printf ("set default-collect %s\n", default_collect
);
15109 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15112 /* The `save breakpoints' command. */
15115 save_breakpoints_command (const char *args
, int from_tty
)
15117 save_breakpoints (args
, from_tty
, NULL
);
15120 /* The `save tracepoints' command. */
15123 save_tracepoints_command (const char *args
, int from_tty
)
15125 save_breakpoints (args
, from_tty
, is_tracepoint
);
15129 /* This help string is used to consolidate all the help string for specifying
15130 locations used by several commands. */
15132 #define LOCATION_HELP_STRING \
15133 "Linespecs are colon-separated lists of location parameters, such as\n\
15134 source filename, function name, label name, and line number.\n\
15135 Example: To specify the start of a label named \"the_top\" in the\n\
15136 function \"fact\" in the file \"factorial.c\", use\n\
15137 \"factorial.c:fact:the_top\".\n\
15139 Address locations begin with \"*\" and specify an exact address in the\n\
15140 program. Example: To specify the fourth byte past the start function\n\
15141 \"main\", use \"*main + 4\".\n\
15143 Explicit locations are similar to linespecs but use an option/argument\n\
15144 syntax to specify location parameters.\n\
15145 Example: To specify the start of the label named \"the_top\" in the\n\
15146 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15147 -function fact -label the_top\".\n\
15149 By default, a specified function is matched against the program's\n\
15150 functions in all scopes. For C++, this means in all namespaces and\n\
15151 classes. For Ada, this means in all packages. E.g., in C++,\n\
15152 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15153 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15154 specified name as a complete fully-qualified name instead."
15156 /* This help string is used for the break, hbreak, tbreak and thbreak
15157 commands. It is defined as a macro to prevent duplication.
15158 COMMAND should be a string constant containing the name of the
15161 #define BREAK_ARGS_HELP(command) \
15162 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
15163 \t[-force-condition] [if CONDITION]\n\
15164 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15165 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15166 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15167 `-probe-dtrace' (for a DTrace probe).\n\
15168 LOCATION may be a linespec, address, or explicit location as described\n\
15171 With no LOCATION, uses current execution address of the selected\n\
15172 stack frame. This is useful for breaking on return to a stack frame.\n\
15174 THREADNUM is the number from \"info threads\".\n\
15175 CONDITION is a boolean expression.\n\
15177 With the \"-force-condition\" flag, the condition is defined even when\n\
15178 it is invalid for all current locations.\n\
15179 \n" LOCATION_HELP_STRING "\n\n\
15180 Multiple breakpoints at one place are permitted, and useful if their\n\
15181 conditions are different.\n\
15183 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15185 /* List of subcommands for "catch". */
15186 static struct cmd_list_element
*catch_cmdlist
;
15188 /* List of subcommands for "tcatch". */
15189 static struct cmd_list_element
*tcatch_cmdlist
;
15192 add_catch_command (const char *name
, const char *docstring
,
15193 cmd_func_ftype
*func
,
15194 completer_ftype
*completer
,
15195 void *user_data_catch
,
15196 void *user_data_tcatch
)
15198 struct cmd_list_element
*command
;
15200 command
= add_cmd (name
, class_breakpoint
, docstring
,
15202 command
->func
= func
;
15203 command
->set_context (user_data_catch
);
15204 set_cmd_completer (command
, completer
);
15206 command
= add_cmd (name
, class_breakpoint
, docstring
,
15208 command
->func
= func
;
15209 command
->set_context (user_data_tcatch
);
15210 set_cmd_completer (command
, completer
);
15213 /* Zero if any of the breakpoint's locations could be a location where
15214 functions have been inlined, nonzero otherwise. */
15217 is_non_inline_function (struct breakpoint
*b
)
15219 /* The shared library event breakpoint is set on the address of a
15220 non-inline function. */
15221 if (b
->type
== bp_shlib_event
)
15227 /* Nonzero if the specified PC cannot be a location where functions
15228 have been inlined. */
15231 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15232 const struct target_waitstatus
*ws
)
15234 for (breakpoint
*b
: all_breakpoints ())
15236 if (!is_non_inline_function (b
))
15239 for (bp_location
*bl
: b
->locations ())
15241 if (!bl
->shlib_disabled
15242 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15250 /* Remove any references to OBJFILE which is going to be freed. */
15253 breakpoint_free_objfile (struct objfile
*objfile
)
15255 for (bp_location
*loc
: all_bp_locations ())
15256 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15257 loc
->symtab
= NULL
;
15261 initialize_breakpoint_ops (void)
15263 static int initialized
= 0;
15265 struct breakpoint_ops
*ops
;
15271 /* The breakpoint_ops structure to be inherit by all kinds of
15272 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15273 internal and momentary breakpoints, etc.). */
15274 ops
= &bkpt_base_breakpoint_ops
;
15275 *ops
= base_breakpoint_ops
;
15276 ops
->re_set
= bkpt_re_set
;
15277 ops
->insert_location
= bkpt_insert_location
;
15278 ops
->remove_location
= bkpt_remove_location
;
15279 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15280 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15281 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15282 ops
->decode_location
= bkpt_decode_location
;
15284 /* The breakpoint_ops structure to be used in regular breakpoints. */
15285 ops
= &bkpt_breakpoint_ops
;
15286 *ops
= bkpt_base_breakpoint_ops
;
15287 ops
->re_set
= bkpt_re_set
;
15288 ops
->resources_needed
= bkpt_resources_needed
;
15289 ops
->print_it
= bkpt_print_it
;
15290 ops
->print_mention
= bkpt_print_mention
;
15291 ops
->print_recreate
= bkpt_print_recreate
;
15293 /* Ranged breakpoints. */
15294 ops
= &ranged_breakpoint_ops
;
15295 *ops
= bkpt_breakpoint_ops
;
15296 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15297 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15298 ops
->print_it
= print_it_ranged_breakpoint
;
15299 ops
->print_one
= print_one_ranged_breakpoint
;
15300 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15301 ops
->print_mention
= print_mention_ranged_breakpoint
;
15302 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15304 /* Internal breakpoints. */
15305 ops
= &internal_breakpoint_ops
;
15306 *ops
= bkpt_base_breakpoint_ops
;
15307 ops
->re_set
= internal_bkpt_re_set
;
15308 ops
->check_status
= internal_bkpt_check_status
;
15309 ops
->print_it
= internal_bkpt_print_it
;
15310 ops
->print_mention
= internal_bkpt_print_mention
;
15312 /* Momentary breakpoints. */
15313 ops
= &momentary_breakpoint_ops
;
15314 *ops
= bkpt_base_breakpoint_ops
;
15315 ops
->re_set
= momentary_bkpt_re_set
;
15316 ops
->check_status
= momentary_bkpt_check_status
;
15317 ops
->print_it
= momentary_bkpt_print_it
;
15318 ops
->print_mention
= momentary_bkpt_print_mention
;
15320 /* Probe breakpoints. */
15321 ops
= &bkpt_probe_breakpoint_ops
;
15322 *ops
= bkpt_breakpoint_ops
;
15323 ops
->insert_location
= bkpt_probe_insert_location
;
15324 ops
->remove_location
= bkpt_probe_remove_location
;
15325 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15326 ops
->decode_location
= bkpt_probe_decode_location
;
15329 ops
= &watchpoint_breakpoint_ops
;
15330 *ops
= base_breakpoint_ops
;
15331 ops
->re_set
= re_set_watchpoint
;
15332 ops
->insert_location
= insert_watchpoint
;
15333 ops
->remove_location
= remove_watchpoint
;
15334 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15335 ops
->check_status
= check_status_watchpoint
;
15336 ops
->resources_needed
= resources_needed_watchpoint
;
15337 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15338 ops
->print_it
= print_it_watchpoint
;
15339 ops
->print_mention
= print_mention_watchpoint
;
15340 ops
->print_recreate
= print_recreate_watchpoint
;
15341 ops
->explains_signal
= explains_signal_watchpoint
;
15343 /* Masked watchpoints. */
15344 ops
= &masked_watchpoint_breakpoint_ops
;
15345 *ops
= watchpoint_breakpoint_ops
;
15346 ops
->insert_location
= insert_masked_watchpoint
;
15347 ops
->remove_location
= remove_masked_watchpoint
;
15348 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15349 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15350 ops
->print_it
= print_it_masked_watchpoint
;
15351 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15352 ops
->print_mention
= print_mention_masked_watchpoint
;
15353 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15356 ops
= &tracepoint_breakpoint_ops
;
15357 *ops
= base_breakpoint_ops
;
15358 ops
->re_set
= tracepoint_re_set
;
15359 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15360 ops
->print_one_detail
= tracepoint_print_one_detail
;
15361 ops
->print_mention
= tracepoint_print_mention
;
15362 ops
->print_recreate
= tracepoint_print_recreate
;
15363 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15364 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15365 ops
->decode_location
= tracepoint_decode_location
;
15367 /* Probe tracepoints. */
15368 ops
= &tracepoint_probe_breakpoint_ops
;
15369 *ops
= tracepoint_breakpoint_ops
;
15370 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15371 ops
->decode_location
= tracepoint_probe_decode_location
;
15373 /* Static tracepoints with marker (`-m'). */
15374 ops
= &strace_marker_breakpoint_ops
;
15375 *ops
= tracepoint_breakpoint_ops
;
15376 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15377 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15378 ops
->decode_location
= strace_marker_decode_location
;
15380 /* Fork catchpoints. */
15381 ops
= &catch_fork_breakpoint_ops
;
15382 *ops
= base_breakpoint_ops
;
15383 ops
->insert_location
= insert_catch_fork
;
15384 ops
->remove_location
= remove_catch_fork
;
15385 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15386 ops
->print_it
= print_it_catch_fork
;
15387 ops
->print_one
= print_one_catch_fork
;
15388 ops
->print_mention
= print_mention_catch_fork
;
15389 ops
->print_recreate
= print_recreate_catch_fork
;
15391 /* Vfork catchpoints. */
15392 ops
= &catch_vfork_breakpoint_ops
;
15393 *ops
= base_breakpoint_ops
;
15394 ops
->insert_location
= insert_catch_vfork
;
15395 ops
->remove_location
= remove_catch_vfork
;
15396 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15397 ops
->print_it
= print_it_catch_vfork
;
15398 ops
->print_one
= print_one_catch_vfork
;
15399 ops
->print_mention
= print_mention_catch_vfork
;
15400 ops
->print_recreate
= print_recreate_catch_vfork
;
15402 /* Exec catchpoints. */
15403 ops
= &catch_exec_breakpoint_ops
;
15404 *ops
= base_breakpoint_ops
;
15405 ops
->insert_location
= insert_catch_exec
;
15406 ops
->remove_location
= remove_catch_exec
;
15407 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15408 ops
->print_it
= print_it_catch_exec
;
15409 ops
->print_one
= print_one_catch_exec
;
15410 ops
->print_mention
= print_mention_catch_exec
;
15411 ops
->print_recreate
= print_recreate_catch_exec
;
15413 /* Solib-related catchpoints. */
15414 ops
= &catch_solib_breakpoint_ops
;
15415 *ops
= base_breakpoint_ops
;
15416 ops
->insert_location
= insert_catch_solib
;
15417 ops
->remove_location
= remove_catch_solib
;
15418 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15419 ops
->check_status
= check_status_catch_solib
;
15420 ops
->print_it
= print_it_catch_solib
;
15421 ops
->print_one
= print_one_catch_solib
;
15422 ops
->print_mention
= print_mention_catch_solib
;
15423 ops
->print_recreate
= print_recreate_catch_solib
;
15425 ops
= &dprintf_breakpoint_ops
;
15426 *ops
= bkpt_base_breakpoint_ops
;
15427 ops
->re_set
= dprintf_re_set
;
15428 ops
->resources_needed
= bkpt_resources_needed
;
15429 ops
->print_it
= bkpt_print_it
;
15430 ops
->print_mention
= bkpt_print_mention
;
15431 ops
->print_recreate
= dprintf_print_recreate
;
15432 ops
->after_condition_true
= dprintf_after_condition_true
;
15433 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15436 /* Chain containing all defined "enable breakpoint" subcommands. */
15438 static struct cmd_list_element
*enablebreaklist
= NULL
;
15440 /* See breakpoint.h. */
15442 cmd_list_element
*commands_cmd_element
= nullptr;
15444 void _initialize_breakpoint ();
15446 _initialize_breakpoint ()
15448 struct cmd_list_element
*c
;
15450 initialize_breakpoint_ops ();
15452 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
15454 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
15456 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
15459 breakpoint_chain
= 0;
15460 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15461 before a breakpoint is set. */
15462 breakpoint_count
= 0;
15464 tracepoint_count
= 0;
15466 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15467 Set ignore-count of breakpoint number N to COUNT.\n\
15468 Usage is `ignore N COUNT'."));
15470 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15471 commands_command
, _("\
15472 Set commands to be executed when the given breakpoints are hit.\n\
15473 Give a space-separated breakpoint list as argument after \"commands\".\n\
15474 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15476 With no argument, the targeted breakpoint is the last one set.\n\
15477 The commands themselves follow starting on the next line.\n\
15478 Type a line containing \"end\" to indicate the end of them.\n\
15479 Give \"silent\" as the first line to make the breakpoint silent;\n\
15480 then no output is printed when it is hit, except what the commands print."));
15482 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
15483 static std::string condition_command_help
15484 = gdb::option::build_help (_("\
15485 Specify breakpoint number N to break only if COND is true.\n\
15486 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
15487 is an expression to be evaluated whenever breakpoint N is reached.\n\
15490 %OPTIONS%"), cc_opts
);
15492 c
= add_com ("condition", class_breakpoint
, condition_command
,
15493 condition_command_help
.c_str ());
15494 set_cmd_completer_handle_brkchars (c
, condition_completer
);
15496 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15497 Set a temporary breakpoint.\n\
15498 Like \"break\" except the breakpoint is only temporary,\n\
15499 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15500 by using \"enable delete\" on the breakpoint number.\n\
15502 BREAK_ARGS_HELP ("tbreak")));
15503 set_cmd_completer (c
, location_completer
);
15505 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15506 Set a hardware assisted breakpoint.\n\
15507 Like \"break\" except the breakpoint requires hardware support,\n\
15508 some target hardware may not have this support.\n\
15510 BREAK_ARGS_HELP ("hbreak")));
15511 set_cmd_completer (c
, location_completer
);
15513 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15514 Set a temporary hardware assisted breakpoint.\n\
15515 Like \"hbreak\" except the breakpoint is only temporary,\n\
15516 so it will be deleted when hit.\n\
15518 BREAK_ARGS_HELP ("thbreak")));
15519 set_cmd_completer (c
, location_completer
);
15521 cmd_list_element
*enable_cmd
15522 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15523 Enable all or some breakpoints.\n\
15524 Usage: enable [BREAKPOINTNUM]...\n\
15525 Give breakpoint numbers (separated by spaces) as arguments.\n\
15526 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15527 This is used to cancel the effect of the \"disable\" command.\n\
15528 With a subcommand you can enable temporarily."),
15529 &enablelist
, 1, &cmdlist
);
15531 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
15533 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15534 Enable all or some breakpoints.\n\
15535 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15536 Give breakpoint numbers (separated by spaces) as arguments.\n\
15537 This is used to cancel the effect of the \"disable\" command.\n\
15538 May be abbreviated to simply \"enable\"."),
15539 &enablebreaklist
, 1, &enablelist
);
15541 add_cmd ("once", no_class
, enable_once_command
, _("\
15542 Enable some breakpoints for one hit.\n\
15543 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15544 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15547 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15548 Enable some breakpoints and delete when hit.\n\
15549 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15550 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15553 add_cmd ("count", no_class
, enable_count_command
, _("\
15554 Enable some breakpoints for COUNT hits.\n\
15555 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15556 If a breakpoint is hit while enabled in this fashion,\n\
15557 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15560 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15561 Enable some breakpoints and delete when hit.\n\
15562 Usage: enable delete BREAKPOINTNUM...\n\
15563 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15566 add_cmd ("once", no_class
, enable_once_command
, _("\
15567 Enable some breakpoints for one hit.\n\
15568 Usage: enable once BREAKPOINTNUM...\n\
15569 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15572 add_cmd ("count", no_class
, enable_count_command
, _("\
15573 Enable some breakpoints for COUNT hits.\n\
15574 Usage: enable count COUNT BREAKPOINTNUM...\n\
15575 If a breakpoint is hit while enabled in this fashion,\n\
15576 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15579 cmd_list_element
*disable_cmd
15580 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15581 Disable all or some breakpoints.\n\
15582 Usage: disable [BREAKPOINTNUM]...\n\
15583 Arguments are breakpoint numbers with spaces in between.\n\
15584 To disable all breakpoints, give no argument.\n\
15585 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15586 &disablelist
, 1, &cmdlist
);
15587 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
15588 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
15590 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
15591 Disable all or some breakpoints.\n\
15592 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15593 Arguments are breakpoint numbers with spaces in between.\n\
15594 To disable all breakpoints, give no argument.\n\
15595 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15596 This command may be abbreviated \"disable\"."),
15599 cmd_list_element
*delete_cmd
15600 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15601 Delete all or some breakpoints.\n\
15602 Usage: delete [BREAKPOINTNUM]...\n\
15603 Arguments are breakpoint numbers with spaces in between.\n\
15604 To delete all breakpoints, give no argument.\n\
15606 Also a prefix command for deletion of other GDB objects."),
15607 &deletelist
, 1, &cmdlist
);
15608 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
15609 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
15611 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
15612 Delete all or some breakpoints or auto-display expressions.\n\
15613 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15614 Arguments are breakpoint numbers with spaces in between.\n\
15615 To delete all breakpoints, give no argument.\n\
15616 This command may be abbreviated \"delete\"."),
15619 cmd_list_element
*clear_cmd
15620 = add_com ("clear", class_breakpoint
, clear_command
, _("\
15621 Clear breakpoint at specified location.\n\
15622 Argument may be a linespec, explicit, or address location as described below.\n\
15624 With no argument, clears all breakpoints in the line that the selected frame\n\
15625 is executing in.\n"
15626 "\n" LOCATION_HELP_STRING
"\n\n\
15627 See also the \"delete\" command which clears breakpoints by number."));
15628 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
15630 cmd_list_element
*break_cmd
15631 = add_com ("break", class_breakpoint
, break_command
, _("\
15632 Set breakpoint at specified location.\n"
15633 BREAK_ARGS_HELP ("break")));
15634 set_cmd_completer (break_cmd
, location_completer
);
15636 add_com_alias ("b", break_cmd
, class_run
, 1);
15637 add_com_alias ("br", break_cmd
, class_run
, 1);
15638 add_com_alias ("bre", break_cmd
, class_run
, 1);
15639 add_com_alias ("brea", break_cmd
, class_run
, 1);
15643 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15644 Break in function/address or break at a line in the current file."),
15645 &stoplist
, 1, &cmdlist
);
15646 add_cmd ("in", class_breakpoint
, stopin_command
,
15647 _("Break in function or address."), &stoplist
);
15648 add_cmd ("at", class_breakpoint
, stopat_command
,
15649 _("Break at a line in the current file."), &stoplist
);
15650 add_com ("status", class_info
, info_breakpoints_command
, _("\
15651 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15652 The \"Type\" column indicates one of:\n\
15653 \tbreakpoint - normal breakpoint\n\
15654 \twatchpoint - watchpoint\n\
15655 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15656 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15657 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15658 address and file/line number respectively.\n\
15660 Convenience variable \"$_\" and default examine address for \"x\"\n\
15661 are set to the address of the last breakpoint listed unless the command\n\
15662 is prefixed with \"server \".\n\n\
15663 Convenience variable \"$bpnum\" contains the number of the last\n\
15664 breakpoint set."));
15667 cmd_list_element
*info_breakpoints_cmd
15668 = add_info ("breakpoints", info_breakpoints_command
, _("\
15669 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15670 The \"Type\" column indicates one of:\n\
15671 \tbreakpoint - normal breakpoint\n\
15672 \twatchpoint - watchpoint\n\
15673 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15674 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15675 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15676 address and file/line number respectively.\n\
15678 Convenience variable \"$_\" and default examine address for \"x\"\n\
15679 are set to the address of the last breakpoint listed unless the command\n\
15680 is prefixed with \"server \".\n\n\
15681 Convenience variable \"$bpnum\" contains the number of the last\n\
15682 breakpoint set."));
15684 add_info_alias ("b", info_breakpoints_cmd
, 1);
15686 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15687 Status of all breakpoints, or breakpoint number NUMBER.\n\
15688 The \"Type\" column indicates one of:\n\
15689 \tbreakpoint - normal breakpoint\n\
15690 \twatchpoint - watchpoint\n\
15691 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15692 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15693 \tuntil - internal breakpoint used by the \"until\" command\n\
15694 \tfinish - internal breakpoint used by the \"finish\" command\n\
15695 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15696 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15697 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15698 address and file/line number respectively.\n\
15700 Convenience variable \"$_\" and default examine address for \"x\"\n\
15701 are set to the address of the last breakpoint listed unless the command\n\
15702 is prefixed with \"server \".\n\n\
15703 Convenience variable \"$bpnum\" contains the number of the last\n\
15705 &maintenanceinfolist
);
15707 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
15708 Set catchpoints to catch events."),
15710 0/*allow-unknown*/, &cmdlist
);
15712 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
15713 Set temporary catchpoints to catch events."),
15715 0/*allow-unknown*/, &cmdlist
);
15717 add_catch_command ("fork", _("Catch calls to fork."),
15718 catch_fork_command_1
,
15720 (void *) (uintptr_t) catch_fork_permanent
,
15721 (void *) (uintptr_t) catch_fork_temporary
);
15722 add_catch_command ("vfork", _("Catch calls to vfork."),
15723 catch_fork_command_1
,
15725 (void *) (uintptr_t) catch_vfork_permanent
,
15726 (void *) (uintptr_t) catch_vfork_temporary
);
15727 add_catch_command ("exec", _("Catch calls to exec."),
15728 catch_exec_command_1
,
15732 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15733 Usage: catch load [REGEX]\n\
15734 If REGEX is given, only stop for libraries matching the regular expression."),
15735 catch_load_command_1
,
15739 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15740 Usage: catch unload [REGEX]\n\
15741 If REGEX is given, only stop for libraries matching the regular expression."),
15742 catch_unload_command_1
,
15747 const auto opts
= make_watch_options_def_group (nullptr);
15749 static const std::string watch_help
= gdb::option::build_help (_("\
15750 Set a watchpoint for EXPRESSION.\n\
15751 Usage: watch [-location] EXPRESSION\n\
15756 A watchpoint stops execution of your program whenever the value of\n\
15757 an expression changes."), opts
);
15758 c
= add_com ("watch", class_breakpoint
, watch_command
,
15759 watch_help
.c_str ());
15760 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15762 static const std::string rwatch_help
= gdb::option::build_help (_("\
15763 Set a read watchpoint for EXPRESSION.\n\
15764 Usage: rwatch [-location] EXPRESSION\n\
15769 A read watchpoint stops execution of your program whenever the value of\n\
15770 an expression is read."), opts
);
15771 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
15772 rwatch_help
.c_str ());
15773 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15775 static const std::string awatch_help
= gdb::option::build_help (_("\
15776 Set an access watchpoint for EXPRESSION.\n\
15777 Usage: awatch [-location] EXPRESSION\n\
15782 An access watchpoint stops execution of your program whenever the value\n\
15783 of an expression is either read or written."), opts
);
15784 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
15785 awatch_help
.c_str ());
15786 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15788 add_info ("watchpoints", info_watchpoints_command
, _("\
15789 Status of specified watchpoints (all watchpoints if no argument)."));
15791 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15792 respond to changes - contrary to the description. */
15793 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15794 &can_use_hw_watchpoints
, _("\
15795 Set debugger's willingness to use watchpoint hardware."), _("\
15796 Show debugger's willingness to use watchpoint hardware."), _("\
15797 If zero, gdb will not use hardware for new watchpoints, even if\n\
15798 such is available. (However, any hardware watchpoints that were\n\
15799 created before setting this to nonzero, will continue to use watchpoint\n\
15802 show_can_use_hw_watchpoints
,
15803 &setlist
, &showlist
);
15805 can_use_hw_watchpoints
= 1;
15807 /* Tracepoint manipulation commands. */
15809 cmd_list_element
*trace_cmd
15810 = add_com ("trace", class_breakpoint
, trace_command
, _("\
15811 Set a tracepoint at specified location.\n\
15813 BREAK_ARGS_HELP ("trace") "\n\
15814 Do \"help tracepoints\" for info on other tracepoint commands."));
15815 set_cmd_completer (trace_cmd
, location_completer
);
15817 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
15818 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
15819 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
15820 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
15822 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15823 Set a fast tracepoint at specified location.\n\
15825 BREAK_ARGS_HELP ("ftrace") "\n\
15826 Do \"help tracepoints\" for info on other tracepoint commands."));
15827 set_cmd_completer (c
, location_completer
);
15829 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15830 Set a static tracepoint at location or marker.\n\
15832 strace [LOCATION] [if CONDITION]\n\
15833 LOCATION may be a linespec, explicit, or address location (described below) \n\
15834 or -m MARKER_ID.\n\n\
15835 If a marker id is specified, probe the marker with that name. With\n\
15836 no LOCATION, uses current execution address of the selected stack frame.\n\
15837 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15838 This collects arbitrary user data passed in the probe point call to the\n\
15839 tracing library. You can inspect it when analyzing the trace buffer,\n\
15840 by printing the $_sdata variable like any other convenience variable.\n\
15842 CONDITION is a boolean expression.\n\
15843 \n" LOCATION_HELP_STRING
"\n\n\
15844 Multiple tracepoints at one place are permitted, and useful if their\n\
15845 conditions are different.\n\
15847 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15848 Do \"help tracepoints\" for info on other tracepoint commands."));
15849 set_cmd_completer (c
, location_completer
);
15851 cmd_list_element
*info_tracepoints_cmd
15852 = add_info ("tracepoints", info_tracepoints_command
, _("\
15853 Status of specified tracepoints (all tracepoints if no argument).\n\
15854 Convenience variable \"$tpnum\" contains the number of the\n\
15855 last tracepoint set."));
15857 add_info_alias ("tp", info_tracepoints_cmd
, 1);
15859 cmd_list_element
*delete_tracepoints_cmd
15860 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15861 Delete specified tracepoints.\n\
15862 Arguments are tracepoint numbers, separated by spaces.\n\
15863 No argument means delete all tracepoints."),
15865 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
15867 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15868 Disable specified tracepoints.\n\
15869 Arguments are tracepoint numbers, separated by spaces.\n\
15870 No argument means disable all tracepoints."),
15872 deprecate_cmd (c
, "disable");
15874 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15875 Enable specified tracepoints.\n\
15876 Arguments are tracepoint numbers, separated by spaces.\n\
15877 No argument means enable all tracepoints."),
15879 deprecate_cmd (c
, "enable");
15881 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15882 Set the passcount for a tracepoint.\n\
15883 The trace will end when the tracepoint has been passed 'count' times.\n\
15884 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15885 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15887 add_basic_prefix_cmd ("save", class_breakpoint
,
15888 _("Save breakpoint definitions as a script."),
15890 0/*allow-unknown*/, &cmdlist
);
15892 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15893 Save current breakpoint definitions as a script.\n\
15894 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15895 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15896 session to restore them."),
15898 set_cmd_completer (c
, filename_completer
);
15900 cmd_list_element
*save_tracepoints_cmd
15901 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15902 Save current tracepoint definitions as a script.\n\
15903 Use the 'source' command in another debug session to restore them."),
15905 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
15907 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
15908 deprecate_cmd (c
, "save tracepoints");
15910 add_basic_prefix_cmd ("breakpoint", class_maintenance
, _("\
15911 Breakpoint specific settings.\n\
15912 Configure various breakpoint-specific variables such as\n\
15913 pending breakpoint behavior."),
15914 &breakpoint_set_cmdlist
,
15915 0/*allow-unknown*/, &setlist
);
15916 add_show_prefix_cmd ("breakpoint", class_maintenance
, _("\
15917 Breakpoint specific settings.\n\
15918 Configure various breakpoint-specific variables such as\n\
15919 pending breakpoint behavior."),
15920 &breakpoint_show_cmdlist
,
15921 0/*allow-unknown*/, &showlist
);
15923 add_setshow_auto_boolean_cmd ("pending", no_class
,
15924 &pending_break_support
, _("\
15925 Set debugger's behavior regarding pending breakpoints."), _("\
15926 Show debugger's behavior regarding pending breakpoints."), _("\
15927 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15928 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15929 an error. If auto, an unrecognized breakpoint location results in a\n\
15930 user-query to see if a pending breakpoint should be created."),
15932 show_pending_break_support
,
15933 &breakpoint_set_cmdlist
,
15934 &breakpoint_show_cmdlist
);
15936 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15938 add_setshow_boolean_cmd ("auto-hw", no_class
,
15939 &automatic_hardware_breakpoints
, _("\
15940 Set automatic usage of hardware breakpoints."), _("\
15941 Show automatic usage of hardware breakpoints."), _("\
15942 If set, the debugger will automatically use hardware breakpoints for\n\
15943 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15944 a warning will be emitted for such breakpoints."),
15946 show_automatic_hardware_breakpoints
,
15947 &breakpoint_set_cmdlist
,
15948 &breakpoint_show_cmdlist
);
15950 add_setshow_boolean_cmd ("always-inserted", class_support
,
15951 &always_inserted_mode
, _("\
15952 Set mode for inserting breakpoints."), _("\
15953 Show mode for inserting breakpoints."), _("\
15954 When this mode is on, breakpoints are inserted immediately as soon as\n\
15955 they're created, kept inserted even when execution stops, and removed\n\
15956 only when the user deletes them. When this mode is off (the default),\n\
15957 breakpoints are inserted only when execution continues, and removed\n\
15958 when execution stops."),
15960 &show_always_inserted_mode
,
15961 &breakpoint_set_cmdlist
,
15962 &breakpoint_show_cmdlist
);
15964 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15965 condition_evaluation_enums
,
15966 &condition_evaluation_mode_1
, _("\
15967 Set mode of breakpoint condition evaluation."), _("\
15968 Show mode of breakpoint condition evaluation."), _("\
15969 When this is set to \"host\", breakpoint conditions will be\n\
15970 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15971 breakpoint conditions will be downloaded to the target (if the target\n\
15972 supports such feature) and conditions will be evaluated on the target's side.\n\
15973 If this is set to \"auto\" (default), this will be automatically set to\n\
15974 \"target\" if it supports condition evaluation, otherwise it will\n\
15975 be set to \"host\"."),
15976 &set_condition_evaluation_mode
,
15977 &show_condition_evaluation_mode
,
15978 &breakpoint_set_cmdlist
,
15979 &breakpoint_show_cmdlist
);
15981 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15982 Set a breakpoint for an address range.\n\
15983 break-range START-LOCATION, END-LOCATION\n\
15984 where START-LOCATION and END-LOCATION can be one of the following:\n\
15985 LINENUM, for that line in the current file,\n\
15986 FILE:LINENUM, for that line in that file,\n\
15987 +OFFSET, for that number of lines after the current line\n\
15988 or the start of the range\n\
15989 FUNCTION, for the first line in that function,\n\
15990 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15991 *ADDRESS, for the instruction at that address.\n\
15993 The breakpoint will stop execution of the inferior whenever it executes\n\
15994 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15995 range (including START-LOCATION and END-LOCATION)."));
15997 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
15998 Set a dynamic printf at specified location.\n\
15999 dprintf location,format string,arg1,arg2,...\n\
16000 location may be a linespec, explicit, or address location.\n"
16001 "\n" LOCATION_HELP_STRING
));
16002 set_cmd_completer (c
, location_completer
);
16004 add_setshow_enum_cmd ("dprintf-style", class_support
,
16005 dprintf_style_enums
, &dprintf_style
, _("\
16006 Set the style of usage for dynamic printf."), _("\
16007 Show the style of usage for dynamic printf."), _("\
16008 This setting chooses how GDB will do a dynamic printf.\n\
16009 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16010 console, as with the \"printf\" command.\n\
16011 If the value is \"call\", the print is done by calling a function in your\n\
16012 program; by default printf(), but you can choose a different function or\n\
16013 output stream by setting dprintf-function and dprintf-channel."),
16014 update_dprintf_commands
, NULL
,
16015 &setlist
, &showlist
);
16017 dprintf_function
= xstrdup ("printf");
16018 add_setshow_string_cmd ("dprintf-function", class_support
,
16019 &dprintf_function
, _("\
16020 Set the function to use for dynamic printf."), _("\
16021 Show the function to use for dynamic printf."), NULL
,
16022 update_dprintf_commands
, NULL
,
16023 &setlist
, &showlist
);
16025 dprintf_channel
= xstrdup ("");
16026 add_setshow_string_cmd ("dprintf-channel", class_support
,
16027 &dprintf_channel
, _("\
16028 Set the channel to use for dynamic printf."), _("\
16029 Show the channel to use for dynamic printf."), NULL
,
16030 update_dprintf_commands
, NULL
,
16031 &setlist
, &showlist
);
16033 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16034 &disconnected_dprintf
, _("\
16035 Set whether dprintf continues after GDB disconnects."), _("\
16036 Show whether dprintf continues after GDB disconnects."), _("\
16037 Use this to let dprintf commands continue to hit and produce output\n\
16038 even if GDB disconnects or detaches from the target."),
16041 &setlist
, &showlist
);
16043 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16044 Target agent only formatted printing, like the C \"printf\" function.\n\
16045 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
16046 This supports most C printf format specifications, like %s, %d, etc.\n\
16047 This is useful for formatted output in user-defined commands."));
16049 automatic_hardware_breakpoints
= true;
16051 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
16053 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,