1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
48 #include "cli/cli-script.h"
52 #include "observable.h"
58 #include "parser-defs.h"
59 #include "gdbsupport/gdb_regex.h"
61 #include "cli/cli-utils.h"
64 #include "dummy-frame.h"
66 #include "gdbsupport/format.h"
67 #include "thread-fsm.h"
68 #include "tid-parse.h"
69 #include "cli/cli-style.h"
70 #include "cli/cli-decode.h"
72 /* readline include files */
73 #include "readline/tilde.h"
75 /* readline defines this. */
78 #include "mi/mi-common.h"
79 #include "extension.h"
81 #include "progspace-and-thread.h"
82 #include "gdbsupport/array-view.h"
83 #include "gdbsupport/gdb_optional.h"
85 /* Prototypes for local functions. */
87 static void map_breakpoint_numbers (const char *,
88 gdb::function_view
<void (breakpoint
*)>);
90 static void breakpoint_re_set_default (struct breakpoint
*);
93 create_sals_from_location_default (struct event_location
*location
,
94 struct linespec_result
*canonical
);
96 static void create_breakpoints_sal (struct gdbarch
*,
97 struct linespec_result
*,
98 gdb::unique_xmalloc_ptr
<char>,
99 gdb::unique_xmalloc_ptr
<char>,
101 enum bpdisp
, int, int,
103 const struct breakpoint_ops
*,
104 int, int, int, unsigned);
106 static std::vector
<symtab_and_line
> decode_location_default
107 (struct breakpoint
*b
, struct event_location
*location
,
108 struct program_space
*search_pspace
);
110 static int can_use_hardware_watchpoint
111 (const std::vector
<value_ref_ptr
> &vals
);
113 static void mention (const breakpoint
*);
115 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
117 /* This function is used in gdbtk sources and thus can not be made
119 static struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
120 struct symtab_and_line
,
123 static struct breakpoint
*
124 momentary_breakpoint_from_master (struct breakpoint
*orig
,
128 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
130 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
134 static void describe_other_breakpoints (struct gdbarch
*,
135 struct program_space
*, CORE_ADDR
,
136 struct obj_section
*, int);
138 static int watchpoint_locations_match (struct bp_location
*loc1
,
139 struct bp_location
*loc2
);
141 static int breakpoint_locations_match (struct bp_location
*loc1
,
142 struct bp_location
*loc2
,
143 bool sw_hw_bps_match
= false);
145 static int breakpoint_location_address_match (struct bp_location
*bl
,
146 const struct address_space
*aspace
,
149 static int breakpoint_location_address_range_overlap (struct bp_location
*,
150 const address_space
*,
153 static int remove_breakpoint (struct bp_location
*);
154 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
156 static enum print_stop_action
print_bp_stop_message (bpstat
*bs
);
158 static int hw_breakpoint_used_count (void);
160 static int hw_watchpoint_use_count (struct breakpoint
*);
162 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
164 int *other_type_used
);
166 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
169 static void decref_bp_location (struct bp_location
**loc
);
171 static std::vector
<symtab_and_line
> bkpt_probe_decode_location
172 (struct breakpoint
*b
,
173 struct event_location
*location
,
174 struct program_space
*search_pspace
);
176 /* update_global_location_list's modes of operation wrt to whether to
177 insert locations now. */
178 enum ugll_insert_mode
180 /* Don't insert any breakpoint locations into the inferior, only
181 remove already-inserted locations that no longer should be
182 inserted. Functions that delete a breakpoint or breakpoints
183 should specify this mode, so that deleting a breakpoint doesn't
184 have the side effect of inserting the locations of other
185 breakpoints that are marked not-inserted, but should_be_inserted
186 returns true on them.
188 This behavior is useful is situations close to tear-down -- e.g.,
189 after an exec, while the target still has execution, but
190 breakpoint shadows of the previous executable image should *NOT*
191 be restored to the new image; or before detaching, where the
192 target still has execution and wants to delete breakpoints from
193 GDB's lists, and all breakpoints had already been removed from
197 /* May insert breakpoints iff breakpoints_should_be_inserted_now
198 claims breakpoints should be inserted now. */
201 /* Insert locations now, irrespective of
202 breakpoints_should_be_inserted_now. E.g., say all threads are
203 stopped right now, and the user did "continue". We need to
204 insert breakpoints _before_ resuming the target, but
205 UGLL_MAY_INSERT wouldn't insert them, because
206 breakpoints_should_be_inserted_now returns false at that point,
207 as no thread is running yet. */
211 static void update_global_location_list (enum ugll_insert_mode
);
213 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
215 static void insert_breakpoint_locations (void);
217 static void trace_pass_command (const char *, int);
219 static void set_tracepoint_count (int num
);
221 static bool is_masked_watchpoint (const struct breakpoint
*b
);
223 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
226 static int strace_marker_p (struct breakpoint
*b
);
228 static void bkpt_probe_create_sals_from_location
229 (struct event_location
*location
,
230 struct linespec_result
*canonical
);
231 static void tracepoint_probe_create_sals_from_location
232 (struct event_location
*location
,
233 struct linespec_result
*canonical
);
235 const struct breakpoint_ops base_breakpoint_ops
=
237 create_sals_from_location_default
,
238 create_breakpoints_sal
,
241 /* Breakpoints set on probes. */
242 static const struct breakpoint_ops bkpt_probe_breakpoint_ops
=
244 bkpt_probe_create_sals_from_location
,
245 create_breakpoints_sal
,
248 /* Tracepoints set on probes. */
249 static const struct breakpoint_ops tracepoint_probe_breakpoint_ops
=
251 tracepoint_probe_create_sals_from_location
,
252 create_breakpoints_sal
,
255 /* The structure to be used in regular breakpoints. */
256 struct ordinary_breakpoint
: public base_breakpoint
258 using base_breakpoint::base_breakpoint
;
260 int resources_needed (const struct bp_location
*) override
;
261 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
262 void print_mention () const override
;
263 void print_recreate (struct ui_file
*fp
) const override
;
266 /* Internal breakpoints. */
267 struct internal_breakpoint
: public base_breakpoint
269 using base_breakpoint::base_breakpoint
;
271 void re_set () override
;
272 void check_status (struct bpstat
*bs
) override
;
273 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
274 void print_mention () const override
;
277 /* Momentary breakpoints. */
278 struct momentary_breakpoint
: public base_breakpoint
280 using base_breakpoint::base_breakpoint
;
282 void re_set () override
;
283 void check_status (struct bpstat
*bs
) override
;
284 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
285 void print_mention () const override
;
288 /* DPrintf breakpoints. */
289 struct dprintf_breakpoint
: public ordinary_breakpoint
291 using ordinary_breakpoint::ordinary_breakpoint
;
293 void re_set () override
;
294 int breakpoint_hit (const struct bp_location
*bl
,
295 const address_space
*aspace
,
297 const target_waitstatus
&ws
) override
;
298 void print_recreate (struct ui_file
*fp
) const override
;
299 void after_condition_true (struct bpstat
*bs
) override
;
302 /* Ranged breakpoints. */
303 struct ranged_breakpoint
: public ordinary_breakpoint
305 explicit ranged_breakpoint (struct gdbarch
*gdbarch
)
306 : ordinary_breakpoint (gdbarch
, bp_hardware_breakpoint
)
310 int breakpoint_hit (const struct bp_location
*bl
,
311 const address_space
*aspace
,
313 const target_waitstatus
&ws
) override
;
314 int resources_needed (const struct bp_location
*) override
;
315 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
316 bool print_one (bp_location
**) const override
;
317 void print_one_detail (struct ui_out
*) const override
;
318 void print_mention () const override
;
319 void print_recreate (struct ui_file
*fp
) const override
;
322 /* Static tracepoints with marker (`-m'). */
323 struct static_marker_tracepoint
: public tracepoint
325 using tracepoint::tracepoint
;
327 std::vector
<symtab_and_line
> decode_location
328 (struct event_location
*location
,
329 struct program_space
*search_pspace
) override
;
332 /* The style in which to perform a dynamic printf. This is a user
333 option because different output options have different tradeoffs;
334 if GDB does the printing, there is better error handling if there
335 is a problem with any of the arguments, but using an inferior
336 function lets you have special-purpose printers and sending of
337 output to the same place as compiled-in print functions. */
339 static const char dprintf_style_gdb
[] = "gdb";
340 static const char dprintf_style_call
[] = "call";
341 static const char dprintf_style_agent
[] = "agent";
342 static const char *const dprintf_style_enums
[] = {
348 static const char *dprintf_style
= dprintf_style_gdb
;
350 /* The function to use for dynamic printf if the preferred style is to
351 call into the inferior. The value is simply a string that is
352 copied into the command, so it can be anything that GDB can
353 evaluate to a callable address, not necessarily a function name. */
355 static std::string dprintf_function
= "printf";
357 /* The channel to use for dynamic printf if the preferred style is to
358 call into the inferior; if a nonempty string, it will be passed to
359 the call as the first argument, with the format string as the
360 second. As with the dprintf function, this can be anything that
361 GDB knows how to evaluate, so in addition to common choices like
362 "stderr", this could be an app-specific expression like
363 "mystreams[curlogger]". */
365 static std::string dprintf_channel
;
367 /* True if dprintf commands should continue to operate even if GDB
369 static bool disconnected_dprintf
= true;
371 struct command_line
*
372 breakpoint_commands (struct breakpoint
*b
)
374 return b
->commands
? b
->commands
.get () : NULL
;
377 /* Flag indicating that a command has proceeded the inferior past the
378 current breakpoint. */
380 static bool breakpoint_proceeded
;
383 bpdisp_text (enum bpdisp disp
)
385 /* NOTE: the following values are a part of MI protocol and
386 represent values of 'disp' field returned when inferior stops at
388 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
390 return bpdisps
[(int) disp
];
393 /* Prototypes for exported functions. */
394 /* If FALSE, gdb will not use hardware support for watchpoints, even
395 if such is available. */
396 static int can_use_hw_watchpoints
;
399 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
400 struct cmd_list_element
*c
,
404 _("Debugger's willingness to use "
405 "watchpoint hardware is %s.\n"),
409 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
410 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
411 for unrecognized breakpoint locations.
412 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
413 static enum auto_boolean pending_break_support
;
415 show_pending_break_support (struct ui_file
*file
, int from_tty
,
416 struct cmd_list_element
*c
,
420 _("Debugger's behavior regarding "
421 "pending breakpoints is %s.\n"),
425 /* If true, gdb will automatically use hardware breakpoints for breakpoints
426 set with "break" but falling in read-only memory.
427 If false, gdb will warn about such breakpoints, but won't automatically
428 use hardware breakpoints. */
429 static bool automatic_hardware_breakpoints
;
431 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
432 struct cmd_list_element
*c
,
436 _("Automatic usage of hardware breakpoints is %s.\n"),
440 /* If on, GDB keeps breakpoints inserted even if the inferior is
441 stopped, and immediately inserts any new breakpoints as soon as
442 they're created. If off (default), GDB keeps breakpoints off of
443 the target as long as possible. That is, it delays inserting
444 breakpoints until the next resume, and removes them again when the
445 target fully stops. This is a bit safer in case GDB crashes while
446 processing user input. */
447 static bool always_inserted_mode
= false;
450 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
451 struct cmd_list_element
*c
, const char *value
)
453 gdb_printf (file
, _("Always inserted breakpoint mode is %s.\n"),
457 /* See breakpoint.h. */
460 breakpoints_should_be_inserted_now (void)
462 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
464 /* If breakpoints are global, they should be inserted even if no
465 thread under gdb's control is running, or even if there are
466 no threads under GDB's control yet. */
471 if (always_inserted_mode
)
473 /* The user wants breakpoints inserted even if all threads
478 for (inferior
*inf
: all_inferiors ())
479 if (inf
->has_execution ()
480 && threads_are_executing (inf
->process_target ()))
483 /* Don't remove breakpoints yet if, even though all threads are
484 stopped, we still have events to process. */
485 for (thread_info
*tp
: all_non_exited_threads ())
486 if (tp
->resumed () && tp
->has_pending_waitstatus ())
492 static const char condition_evaluation_both
[] = "host or target";
494 /* Modes for breakpoint condition evaluation. */
495 static const char condition_evaluation_auto
[] = "auto";
496 static const char condition_evaluation_host
[] = "host";
497 static const char condition_evaluation_target
[] = "target";
498 static const char *const condition_evaluation_enums
[] = {
499 condition_evaluation_auto
,
500 condition_evaluation_host
,
501 condition_evaluation_target
,
505 /* Global that holds the current mode for breakpoint condition evaluation. */
506 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
508 /* Global that we use to display information to the user (gets its value from
509 condition_evaluation_mode_1. */
510 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
512 /* Translate a condition evaluation mode MODE into either "host"
513 or "target". This is used mostly to translate from "auto" to the
514 real setting that is being used. It returns the translated
518 translate_condition_evaluation_mode (const char *mode
)
520 if (mode
== condition_evaluation_auto
)
522 if (target_supports_evaluation_of_breakpoint_conditions ())
523 return condition_evaluation_target
;
525 return condition_evaluation_host
;
531 /* Discovers what condition_evaluation_auto translates to. */
534 breakpoint_condition_evaluation_mode (void)
536 return translate_condition_evaluation_mode (condition_evaluation_mode
);
539 /* Return true if GDB should evaluate breakpoint conditions or false
543 gdb_evaluates_breakpoint_condition_p (void)
545 const char *mode
= breakpoint_condition_evaluation_mode ();
547 return (mode
== condition_evaluation_host
);
550 /* Are we executing breakpoint commands? */
551 static int executing_breakpoint_commands
;
553 /* Are overlay event breakpoints enabled? */
554 static int overlay_events_enabled
;
556 /* See description in breakpoint.h. */
557 bool target_exact_watchpoints
= false;
559 /* Walk the following statement or block through all breakpoints.
560 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
561 current breakpoint. */
563 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
564 for (B = breakpoint_chain; \
565 B ? (TMP=B->next, 1): 0; \
568 /* Chains of all breakpoints defined. */
570 static struct breakpoint
*breakpoint_chain
;
572 /* See breakpoint.h. */
577 return breakpoint_range (breakpoint_chain
);
580 /* See breakpoint.h. */
582 breakpoint_safe_range
583 all_breakpoints_safe ()
585 return breakpoint_safe_range (all_breakpoints ());
588 /* See breakpoint.h. */
593 return tracepoint_range (breakpoint_chain
);
596 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
598 static std::vector
<bp_location
*> bp_locations
;
600 /* See breakpoint.h. */
602 const std::vector
<bp_location
*> &
608 /* Range to iterate over breakpoint locations at a given address. */
610 struct bp_locations_at_addr_range
612 using iterator
= std::vector
<bp_location
*>::iterator
;
614 bp_locations_at_addr_range (CORE_ADDR addr
)
618 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
619 { return loc
->address
< addr_
; }
621 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
622 { return addr_
< loc
->address
; }
625 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
628 m_begin
= it_pair
.first
;
629 m_end
= it_pair
.second
;
632 iterator
begin () const
635 iterator
end () const
643 /* Return a range to iterate over all breakpoint locations exactly at address
646 If it's needed to iterate multiple times on the same range, it's possible
647 to save the range in a local variable and use it multiple times:
649 auto range = all_bp_locations_at_addr (addr);
651 for (bp_location *loc : range)
654 for (bp_location *loc : range)
657 This saves a bit of time, as it avoids re-doing the binary searches to find
658 the range's boundaries. Just remember not to change the bp_locations vector
659 in the mean time, as it could make the range's iterators stale. */
661 static bp_locations_at_addr_range
662 all_bp_locations_at_addr (CORE_ADDR addr
)
664 return bp_locations_at_addr_range (addr
);
667 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
668 ADDRESS for the current elements of BP_LOCATIONS which get a valid
669 result from bp_location_has_shadow. You can use it for roughly
670 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
671 an address you need to read. */
673 static CORE_ADDR bp_locations_placed_address_before_address_max
;
675 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
676 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
677 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
678 You can use it for roughly limiting the subrange of BP_LOCATIONS to
679 scan for shadow bytes for an address you need to read. */
681 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
683 /* The locations that no longer correspond to any breakpoint, unlinked
684 from the bp_locations array, but for which a hit may still be
685 reported by a target. */
686 static std::vector
<bp_location
*> moribund_locations
;
688 /* Number of last breakpoint made. */
690 static int breakpoint_count
;
692 /* The value of `breakpoint_count' before the last command that
693 created breakpoints. If the last (break-like) command created more
694 than one breakpoint, then the difference between BREAKPOINT_COUNT
695 and PREV_BREAKPOINT_COUNT is more than one. */
696 static int prev_breakpoint_count
;
698 /* Number of last tracepoint made. */
700 static int tracepoint_count
;
702 static struct cmd_list_element
*breakpoint_set_cmdlist
;
703 static struct cmd_list_element
*breakpoint_show_cmdlist
;
704 struct cmd_list_element
*save_cmdlist
;
706 /* Return whether a breakpoint is an active enabled breakpoint. */
708 breakpoint_enabled (struct breakpoint
*b
)
710 return (b
->enable_state
== bp_enabled
);
713 /* Set breakpoint count to NUM. */
716 set_breakpoint_count (int num
)
718 prev_breakpoint_count
= breakpoint_count
;
719 breakpoint_count
= num
;
720 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
723 /* Used by `start_rbreak_breakpoints' below, to record the current
724 breakpoint count before "rbreak" creates any breakpoint. */
725 static int rbreak_start_breakpoint_count
;
727 /* Called at the start an "rbreak" command to record the first
730 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
732 rbreak_start_breakpoint_count
= breakpoint_count
;
735 /* Called at the end of an "rbreak" command to record the last
738 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
740 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
743 /* Used in run_command to zero the hit count when a new run starts. */
746 clear_breakpoint_hit_counts (void)
748 for (breakpoint
*b
: all_breakpoints ())
753 /* Return the breakpoint with the specified number, or NULL
754 if the number does not refer to an existing breakpoint. */
757 get_breakpoint (int num
)
759 for (breakpoint
*b
: all_breakpoints ())
760 if (b
->number
== num
)
768 /* Mark locations as "conditions have changed" in case the target supports
769 evaluating conditions on its side. */
772 mark_breakpoint_modified (struct breakpoint
*b
)
774 /* This is only meaningful if the target is
775 evaluating conditions and if the user has
776 opted for condition evaluation on the target's
778 if (gdb_evaluates_breakpoint_condition_p ()
779 || !target_supports_evaluation_of_breakpoint_conditions ())
782 if (!is_breakpoint (b
))
785 for (bp_location
*loc
: b
->locations ())
786 loc
->condition_changed
= condition_modified
;
789 /* Mark location as "conditions have changed" in case the target supports
790 evaluating conditions on its side. */
793 mark_breakpoint_location_modified (struct bp_location
*loc
)
795 /* This is only meaningful if the target is
796 evaluating conditions and if the user has
797 opted for condition evaluation on the target's
799 if (gdb_evaluates_breakpoint_condition_p ()
800 || !target_supports_evaluation_of_breakpoint_conditions ())
804 if (!is_breakpoint (loc
->owner
))
807 loc
->condition_changed
= condition_modified
;
810 /* Sets the condition-evaluation mode using the static global
811 condition_evaluation_mode. */
814 set_condition_evaluation_mode (const char *args
, int from_tty
,
815 struct cmd_list_element
*c
)
817 const char *old_mode
, *new_mode
;
819 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
820 && !target_supports_evaluation_of_breakpoint_conditions ())
822 condition_evaluation_mode_1
= condition_evaluation_mode
;
823 warning (_("Target does not support breakpoint condition evaluation.\n"
824 "Using host evaluation mode instead."));
828 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
829 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
831 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
832 settings was "auto". */
833 condition_evaluation_mode
= condition_evaluation_mode_1
;
835 /* Only update the mode if the user picked a different one. */
836 if (new_mode
!= old_mode
)
838 /* If the user switched to a different evaluation mode, we
839 need to synch the changes with the target as follows:
841 "host" -> "target": Send all (valid) conditions to the target.
842 "target" -> "host": Remove all the conditions from the target.
845 if (new_mode
== condition_evaluation_target
)
847 /* Mark everything modified and synch conditions with the
849 for (bp_location
*loc
: all_bp_locations ())
850 mark_breakpoint_location_modified (loc
);
854 /* Manually mark non-duplicate locations to synch conditions
855 with the target. We do this to remove all the conditions the
856 target knows about. */
857 for (bp_location
*loc
: all_bp_locations ())
858 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
859 loc
->needs_update
= 1;
863 update_global_location_list (UGLL_MAY_INSERT
);
869 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
870 what "auto" is translating to. */
873 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
874 struct cmd_list_element
*c
, const char *value
)
876 if (condition_evaluation_mode
== condition_evaluation_auto
)
878 _("Breakpoint condition evaluation "
879 "mode is %s (currently %s).\n"),
881 breakpoint_condition_evaluation_mode ());
883 gdb_printf (file
, _("Breakpoint condition evaluation mode is %s.\n"),
887 /* Parse COND_STRING in the context of LOC and set as the condition
888 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
889 the number of LOC within its owner. In case of parsing error, mark
890 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
893 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
894 int bp_num
, int loc_num
)
896 bool has_junk
= false;
899 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
900 block_for_pc (loc
->address
), 0);
901 if (*cond_string
!= 0)
905 loc
->cond
= std::move (new_exp
);
906 if (loc
->disabled_by_cond
&& loc
->enabled
)
907 gdb_printf (_("Breakpoint %d's condition is now valid at "
908 "location %d, enabling.\n"),
911 loc
->disabled_by_cond
= false;
914 catch (const gdb_exception_error
&e
)
918 /* Warn if a user-enabled location is now becoming disabled-by-cond.
919 BP_NUM is 0 if the breakpoint is being defined for the first
920 time using the "break ... if ..." command, and non-zero if
923 warning (_("failed to validate condition at location %d.%d, "
924 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
926 warning (_("failed to validate condition at location %d, "
927 "disabling:\n %s"), loc_num
, e
.what ());
930 loc
->disabled_by_cond
= true;
934 error (_("Garbage '%s' follows condition"), cond_string
);
938 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
939 int from_tty
, bool force
)
943 b
->cond_string
.reset ();
945 if (is_watchpoint (b
))
946 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
950 for (bp_location
*loc
: b
->locations ())
953 if (loc
->disabled_by_cond
&& loc
->enabled
)
954 gdb_printf (_("Breakpoint %d's condition is now valid at "
955 "location %d, enabling.\n"),
957 loc
->disabled_by_cond
= false;
960 /* No need to free the condition agent expression
961 bytecode (if we have one). We will handle this
962 when we go through update_global_location_list. */
967 gdb_printf (_("Breakpoint %d now unconditional.\n"), b
->number
);
971 if (is_watchpoint (b
))
973 innermost_block_tracker tracker
;
974 const char *arg
= exp
;
975 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
977 error (_("Junk at end of expression"));
978 watchpoint
*w
= static_cast<watchpoint
*> (b
);
979 w
->cond_exp
= std::move (new_exp
);
980 w
->cond_exp_valid_block
= tracker
.block ();
984 /* Parse and set condition expressions. We make two passes.
985 In the first, we parse the condition string to see if it
986 is valid in at least one location. If so, the condition
987 would be accepted. So we go ahead and set the locations'
988 conditions. In case no valid case is found, we throw
989 the error and the condition string will be rejected.
990 This two-pass approach is taken to avoid setting the
991 state of locations in case of a reject. */
992 for (bp_location
*loc
: b
->locations ())
996 const char *arg
= exp
;
997 parse_exp_1 (&arg
, loc
->address
,
998 block_for_pc (loc
->address
), 0);
1000 error (_("Junk at end of expression"));
1003 catch (const gdb_exception_error
&e
)
1005 /* Condition string is invalid. If this happens to
1006 be the last loc, abandon (if not forced) or continue
1008 if (loc
->next
== nullptr && !force
)
1013 /* If we reach here, the condition is valid at some locations. */
1015 for (bp_location
*loc
: b
->locations ())
1017 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
1022 /* We know that the new condition parsed successfully. The
1023 condition string of the breakpoint can be safely updated. */
1024 b
->cond_string
= make_unique_xstrdup (exp
);
1025 b
->condition_not_parsed
= 0;
1027 mark_breakpoint_modified (b
);
1029 gdb::observers::breakpoint_modified
.notify (b
);
1032 /* See breakpoint.h. */
1035 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
1038 for (breakpoint
*b
: all_breakpoints ())
1039 if (b
->number
== bpnum
)
1041 /* Check if this breakpoint has a "stop" method implemented in an
1042 extension language. This method and conditions entered into GDB
1043 from the CLI are mutually exclusive. */
1044 const struct extension_language_defn
*extlang
1045 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1047 if (extlang
!= NULL
)
1049 error (_("Only one stop condition allowed. There is currently"
1050 " a %s stop condition defined for this breakpoint."),
1051 ext_lang_capitalized_name (extlang
));
1053 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1055 if (is_breakpoint (b
))
1056 update_global_location_list (UGLL_MAY_INSERT
);
1061 error (_("No breakpoint number %d."), bpnum
);
1064 /* The options for the "condition" command. */
1066 struct condition_command_opts
1069 bool force_condition
= false;
1072 static const gdb::option::option_def condition_command_option_defs
[] = {
1074 gdb::option::flag_option_def
<condition_command_opts
> {
1076 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1077 N_("Set the condition even if it is invalid for all current locations."),
1082 /* Create an option_def_group for the "condition" options, with
1083 CC_OPTS as context. */
1085 static inline gdb::option::option_def_group
1086 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1088 return {{condition_command_option_defs
}, cc_opts
};
1091 /* Completion for the "condition" command. */
1094 condition_completer (struct cmd_list_element
*cmd
,
1095 completion_tracker
&tracker
,
1096 const char *text
, const char * /*word*/)
1098 bool has_no_arguments
= (*text
== '\0');
1099 condition_command_opts cc_opts
;
1100 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1101 if (gdb::option::complete_options
1102 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1105 text
= skip_spaces (text
);
1106 const char *space
= skip_to_space (text
);
1113 tracker
.advance_custom_word_point_by (1);
1114 /* We don't support completion of history indices. */
1115 if (!isdigit (text
[1]))
1116 complete_internalvar (tracker
, &text
[1]);
1120 /* Suggest the "-force" flag if no arguments are given. If
1121 arguments were passed, they either already include the flag,
1122 or we are beyond the point of suggesting it because it's
1123 positionally the first argument. */
1124 if (has_no_arguments
)
1125 gdb::option::complete_on_all_options (tracker
, group
);
1127 /* We're completing the breakpoint number. */
1128 len
= strlen (text
);
1130 for (breakpoint
*b
: all_breakpoints ())
1134 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1136 if (strncmp (number
, text
, len
) == 0)
1137 tracker
.add_completion (make_unique_xstrdup (number
));
1143 /* We're completing the expression part. Skip the breakpoint num. */
1144 const char *exp_start
= skip_spaces (space
);
1145 tracker
.advance_custom_word_point_by (exp_start
- text
);
1147 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1148 expression_completer (cmd
, tracker
, text
, word
);
1151 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1154 condition_command (const char *arg
, int from_tty
)
1160 error_no_arg (_("breakpoint number"));
1164 /* Check if the "-force" flag was passed. */
1165 condition_command_opts cc_opts
;
1166 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1167 gdb::option::process_options
1168 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1170 bnum
= get_number (&p
);
1172 error (_("Bad breakpoint argument: '%s'"), arg
);
1174 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1177 /* Check that COMMAND do not contain commands that are suitable
1178 only for tracepoints and not suitable for ordinary breakpoints.
1179 Throw if any such commands is found. */
1182 check_no_tracepoint_commands (struct command_line
*commands
)
1184 struct command_line
*c
;
1186 for (c
= commands
; c
; c
= c
->next
)
1188 if (c
->control_type
== while_stepping_control
)
1189 error (_("The 'while-stepping' command can "
1190 "only be used for tracepoints"));
1192 check_no_tracepoint_commands (c
->body_list_0
.get ());
1193 check_no_tracepoint_commands (c
->body_list_1
.get ());
1195 /* Not that command parsing removes leading whitespace and comment
1196 lines and also empty lines. So, we only need to check for
1197 command directly. */
1198 if (strstr (c
->line
, "collect ") == c
->line
)
1199 error (_("The 'collect' command can only be used for tracepoints"));
1201 if (strstr (c
->line
, "teval ") == c
->line
)
1202 error (_("The 'teval' command can only be used for tracepoints"));
1206 struct longjmp_breakpoint
: public momentary_breakpoint
1208 using momentary_breakpoint::momentary_breakpoint
;
1210 ~longjmp_breakpoint () override
;
1213 /* Encapsulate tests for different types of tracepoints. */
1216 is_tracepoint_type (bptype type
)
1218 return (type
== bp_tracepoint
1219 || type
== bp_fast_tracepoint
1220 || type
== bp_static_tracepoint
1221 || type
== bp_static_marker_tracepoint
);
1224 /* See breakpoint.h. */
1227 is_tracepoint (const struct breakpoint
*b
)
1229 return is_tracepoint_type (b
->type
);
1232 /* Factory function to create an appropriate instance of breakpoint given
1235 static std::unique_ptr
<breakpoint
>
1236 new_breakpoint_from_type (struct gdbarch
*gdbarch
, bptype type
)
1243 case bp_hardware_breakpoint
:
1244 b
= new ordinary_breakpoint (gdbarch
, type
);
1247 case bp_fast_tracepoint
:
1248 case bp_static_tracepoint
:
1250 b
= new tracepoint (gdbarch
, type
);
1253 case bp_static_marker_tracepoint
:
1254 b
= new static_marker_tracepoint (gdbarch
, type
);
1258 b
= new dprintf_breakpoint (gdbarch
, type
);
1261 case bp_overlay_event
:
1262 case bp_longjmp_master
:
1263 case bp_std_terminate_master
:
1264 case bp_exception_master
:
1265 case bp_thread_event
:
1267 case bp_shlib_event
:
1268 b
= new internal_breakpoint (gdbarch
, type
);
1273 b
= new longjmp_breakpoint (gdbarch
, type
);
1276 case bp_watchpoint_scope
:
1278 case bp_gnu_ifunc_resolver_return
:
1279 case bp_step_resume
:
1280 case bp_hp_step_resume
:
1281 case bp_longjmp_resume
:
1282 case bp_longjmp_call_dummy
:
1283 case bp_exception_resume
:
1286 case bp_std_terminate
:
1287 b
= new momentary_breakpoint (gdbarch
, type
);
1291 gdb_assert_not_reached ("invalid type");
1294 return std::unique_ptr
<breakpoint
> (b
);
1297 /* A helper function that validates that COMMANDS are valid for a
1298 breakpoint. This function will throw an exception if a problem is
1302 validate_commands_for_breakpoint (struct breakpoint
*b
,
1303 struct command_line
*commands
)
1305 if (is_tracepoint (b
))
1307 struct tracepoint
*t
= (struct tracepoint
*) b
;
1308 struct command_line
*c
;
1309 struct command_line
*while_stepping
= 0;
1311 /* Reset the while-stepping step count. The previous commands
1312 might have included a while-stepping action, while the new
1316 /* We need to verify that each top-level element of commands is
1317 valid for tracepoints, that there's at most one
1318 while-stepping element, and that the while-stepping's body
1319 has valid tracing commands excluding nested while-stepping.
1320 We also need to validate the tracepoint action line in the
1321 context of the tracepoint --- validate_actionline actually
1322 has side effects, like setting the tracepoint's
1323 while-stepping STEP_COUNT, in addition to checking if the
1324 collect/teval actions parse and make sense in the
1325 tracepoint's context. */
1326 for (c
= commands
; c
; c
= c
->next
)
1328 if (c
->control_type
== while_stepping_control
)
1330 if (b
->type
== bp_fast_tracepoint
)
1331 error (_("The 'while-stepping' command "
1332 "cannot be used for fast tracepoint"));
1333 else if (b
->type
== bp_static_tracepoint
1334 || b
->type
== bp_static_marker_tracepoint
)
1335 error (_("The 'while-stepping' command "
1336 "cannot be used for static tracepoint"));
1339 error (_("The 'while-stepping' command "
1340 "can be used only once"));
1345 validate_actionline (c
->line
, b
);
1349 struct command_line
*c2
;
1351 gdb_assert (while_stepping
->body_list_1
== nullptr);
1352 c2
= while_stepping
->body_list_0
.get ();
1353 for (; c2
; c2
= c2
->next
)
1355 if (c2
->control_type
== while_stepping_control
)
1356 error (_("The 'while-stepping' command cannot be nested"));
1362 check_no_tracepoint_commands (commands
);
1366 /* Return a vector of all the static tracepoints set at ADDR. The
1367 caller is responsible for releasing the vector. */
1369 std::vector
<breakpoint
*>
1370 static_tracepoints_here (CORE_ADDR addr
)
1372 std::vector
<breakpoint
*> found
;
1374 for (breakpoint
*b
: all_breakpoints ())
1375 if (b
->type
== bp_static_tracepoint
1376 || b
->type
== bp_static_marker_tracepoint
)
1378 for (bp_location
*loc
: b
->locations ())
1379 if (loc
->address
== addr
)
1380 found
.push_back (b
);
1386 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1387 validate that only allowed commands are included. */
1390 breakpoint_set_commands (struct breakpoint
*b
,
1391 counted_command_line
&&commands
)
1393 validate_commands_for_breakpoint (b
, commands
.get ());
1395 b
->commands
= std::move (commands
);
1396 gdb::observers::breakpoint_modified
.notify (b
);
1399 /* Set the internal `silent' flag on the breakpoint. Note that this
1400 is not the same as the "silent" that may appear in the breakpoint's
1404 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1406 int old_silent
= b
->silent
;
1409 if (old_silent
!= silent
)
1410 gdb::observers::breakpoint_modified
.notify (b
);
1413 /* Set the thread for this breakpoint. If THREAD is -1, make the
1414 breakpoint work for any thread. */
1417 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1419 int old_thread
= b
->thread
;
1422 if (old_thread
!= thread
)
1423 gdb::observers::breakpoint_modified
.notify (b
);
1426 /* Set the task for this breakpoint. If TASK is 0, make the
1427 breakpoint work for any task. */
1430 breakpoint_set_task (struct breakpoint
*b
, int task
)
1432 int old_task
= b
->task
;
1435 if (old_task
!= task
)
1436 gdb::observers::breakpoint_modified
.notify (b
);
1440 commands_command_1 (const char *arg
, int from_tty
,
1441 struct command_line
*control
)
1443 counted_command_line cmd
;
1444 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1445 NULL after the call to read_command_lines if the user provides an empty
1446 list of command by just typing "end". */
1447 bool cmd_read
= false;
1449 std::string new_arg
;
1451 if (arg
== NULL
|| !*arg
)
1453 /* Argument not explicitly given. Synthesize it. */
1454 if (breakpoint_count
- prev_breakpoint_count
> 1)
1455 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1457 else if (breakpoint_count
> 0)
1458 new_arg
= string_printf ("%d", breakpoint_count
);
1462 /* Create a copy of ARG. This is needed because the "commands"
1463 command may be coming from a script. In that case, the read
1464 line buffer is going to be overwritten in the lambda of
1465 'map_breakpoint_numbers' below when reading the next line
1466 before we are are done parsing the breakpoint numbers. */
1469 arg
= new_arg
.c_str ();
1471 map_breakpoint_numbers
1472 (arg
, [&] (breakpoint
*b
)
1476 gdb_assert (cmd
== NULL
);
1477 if (control
!= NULL
)
1478 cmd
= control
->body_list_0
;
1482 = string_printf (_("Type commands for breakpoint(s) "
1483 "%s, one per line."),
1486 auto do_validate
= [=] (const char *line
)
1488 validate_actionline (line
, b
);
1490 gdb::function_view
<void (const char *)> validator
;
1491 if (is_tracepoint (b
))
1492 validator
= do_validate
;
1494 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1499 /* If a breakpoint was on the list more than once, we don't need to
1501 if (b
->commands
!= cmd
)
1503 validate_commands_for_breakpoint (b
, cmd
.get ());
1505 gdb::observers::breakpoint_modified
.notify (b
);
1511 commands_command (const char *arg
, int from_tty
)
1513 commands_command_1 (arg
, from_tty
, NULL
);
1516 /* Like commands_command, but instead of reading the commands from
1517 input stream, takes them from an already parsed command structure.
1519 This is used by cli-script.c to DTRT with breakpoint commands
1520 that are part of if and while bodies. */
1521 enum command_control_type
1522 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1524 commands_command_1 (arg
, 0, cmd
);
1525 return simple_control
;
1528 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1531 bp_location_has_shadow (struct bp_location
*bl
)
1533 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1537 if (bl
->target_info
.shadow_len
== 0)
1538 /* BL isn't valid, or doesn't shadow memory. */
1543 /* Update BUF, which is LEN bytes read from the target address
1544 MEMADDR, by replacing a memory breakpoint with its shadowed
1547 If READBUF is not NULL, this buffer must not overlap with the of
1548 the breakpoint location's shadow_contents buffer. Otherwise, a
1549 failed assertion internal error will be raised. */
1552 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1553 const gdb_byte
*writebuf_org
,
1554 ULONGEST memaddr
, LONGEST len
,
1555 struct bp_target_info
*target_info
,
1556 struct gdbarch
*gdbarch
)
1558 /* Now do full processing of the found relevant range of elements. */
1559 CORE_ADDR bp_addr
= 0;
1563 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1564 current_program_space
->aspace
, 0))
1566 /* The breakpoint is inserted in a different address space. */
1570 /* Addresses and length of the part of the breakpoint that
1572 bp_addr
= target_info
->placed_address
;
1573 bp_size
= target_info
->shadow_len
;
1575 if (bp_addr
+ bp_size
<= memaddr
)
1577 /* The breakpoint is entirely before the chunk of memory we are
1582 if (bp_addr
>= memaddr
+ len
)
1584 /* The breakpoint is entirely after the chunk of memory we are
1589 /* Offset within shadow_contents. */
1590 if (bp_addr
< memaddr
)
1592 /* Only copy the second part of the breakpoint. */
1593 bp_size
-= memaddr
- bp_addr
;
1594 bptoffset
= memaddr
- bp_addr
;
1598 if (bp_addr
+ bp_size
> memaddr
+ len
)
1600 /* Only copy the first part of the breakpoint. */
1601 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1604 if (readbuf
!= NULL
)
1606 /* Verify that the readbuf buffer does not overlap with the
1607 shadow_contents buffer. */
1608 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1609 || readbuf
>= (target_info
->shadow_contents
1610 + target_info
->shadow_len
));
1612 /* Update the read buffer with this inserted breakpoint's
1614 memcpy (readbuf
+ bp_addr
- memaddr
,
1615 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1619 const unsigned char *bp
;
1620 CORE_ADDR addr
= target_info
->reqstd_address
;
1623 /* Update the shadow with what we want to write to memory. */
1624 memcpy (target_info
->shadow_contents
+ bptoffset
,
1625 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1627 /* Determine appropriate breakpoint contents and size for this
1629 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1631 /* Update the final write buffer with this inserted
1632 breakpoint's INSN. */
1633 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1637 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1638 by replacing any memory breakpoints with their shadowed contents.
1640 If READBUF is not NULL, this buffer must not overlap with any of
1641 the breakpoint location's shadow_contents buffers. Otherwise,
1642 a failed assertion internal error will be raised.
1644 The range of shadowed area by each bp_location is:
1645 bl->address - bp_locations_placed_address_before_address_max
1646 up to bl->address + bp_locations_shadow_len_after_address_max
1647 The range we were requested to resolve shadows for is:
1648 memaddr ... memaddr + len
1649 Thus the safe cutoff boundaries for performance optimization are
1650 memaddr + len <= (bl->address
1651 - bp_locations_placed_address_before_address_max)
1653 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1656 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1657 const gdb_byte
*writebuf_org
,
1658 ULONGEST memaddr
, LONGEST len
)
1660 /* Left boundary, right boundary and median element of our binary
1662 unsigned bc_l
, bc_r
, bc
;
1664 /* Find BC_L which is a leftmost element which may affect BUF
1665 content. It is safe to report lower value but a failure to
1666 report higher one. */
1669 bc_r
= bp_locations
.size ();
1670 while (bc_l
+ 1 < bc_r
)
1672 struct bp_location
*bl
;
1674 bc
= (bc_l
+ bc_r
) / 2;
1675 bl
= bp_locations
[bc
];
1677 /* Check first BL->ADDRESS will not overflow due to the added
1678 constant. Then advance the left boundary only if we are sure
1679 the BC element can in no way affect the BUF content (MEMADDR
1680 to MEMADDR + LEN range).
1682 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1683 offset so that we cannot miss a breakpoint with its shadow
1684 range tail still reaching MEMADDR. */
1686 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1688 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1695 /* Due to the binary search above, we need to make sure we pick the
1696 first location that's at BC_L's address. E.g., if there are
1697 multiple locations at the same address, BC_L may end up pointing
1698 at a duplicate location, and miss the "master"/"inserted"
1699 location. Say, given locations L1, L2 and L3 at addresses A and
1702 L1@A, L2@A, L3@B, ...
1704 BC_L could end up pointing at location L2, while the "master"
1705 location could be L1. Since the `loc->inserted' flag is only set
1706 on "master" locations, we'd forget to restore the shadow of L1
1709 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1712 /* Now do full processing of the found relevant range of elements. */
1714 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1716 struct bp_location
*bl
= bp_locations
[bc
];
1718 /* bp_location array has BL->OWNER always non-NULL. */
1719 if (bl
->owner
->type
== bp_none
)
1720 warning (_("reading through apparently deleted breakpoint #%d?"),
1723 /* Performance optimization: any further element can no longer affect BUF
1726 if (bl
->address
>= bp_locations_placed_address_before_address_max
1729 - bp_locations_placed_address_before_address_max
)))
1732 if (!bp_location_has_shadow (bl
))
1735 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1736 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1740 /* See breakpoint.h. */
1743 is_breakpoint (const struct breakpoint
*bpt
)
1745 return (bpt
->type
== bp_breakpoint
1746 || bpt
->type
== bp_hardware_breakpoint
1747 || bpt
->type
== bp_dprintf
);
1750 /* Return true if BPT is of any hardware watchpoint kind. */
1753 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1755 return (bpt
->type
== bp_hardware_watchpoint
1756 || bpt
->type
== bp_read_watchpoint
1757 || bpt
->type
== bp_access_watchpoint
);
1760 /* See breakpoint.h. */
1763 is_watchpoint (const struct breakpoint
*bpt
)
1765 return (is_hardware_watchpoint (bpt
)
1766 || bpt
->type
== bp_watchpoint
);
1769 /* Returns true if the current thread and its running state are safe
1770 to evaluate or update watchpoint B. Watchpoints on local
1771 expressions need to be evaluated in the context of the thread that
1772 was current when the watchpoint was created, and, that thread needs
1773 to be stopped to be able to select the correct frame context.
1774 Watchpoints on global expressions can be evaluated on any thread,
1775 and in any state. It is presently left to the target allowing
1776 memory accesses when threads are running. */
1779 watchpoint_in_thread_scope (struct watchpoint
*b
)
1781 return (b
->pspace
== current_program_space
1782 && (b
->watchpoint_thread
== null_ptid
1783 || (inferior_ptid
== b
->watchpoint_thread
1784 && !inferior_thread ()->executing ())));
1787 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1788 associated bp_watchpoint_scope breakpoint. */
1791 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1793 if (w
->related_breakpoint
!= w
)
1795 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1796 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1797 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1798 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1799 w
->related_breakpoint
= w
;
1801 w
->disposition
= disp_del_at_next_stop
;
1804 /* Extract a bitfield value from value VAL using the bit parameters contained in
1807 static struct value
*
1808 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1810 struct value
*bit_val
;
1815 bit_val
= allocate_value (value_type (val
));
1817 unpack_value_bitfield (bit_val
,
1820 value_contents_for_printing (val
).data (),
1827 /* Allocate a dummy location and add it to B, which must be a software
1828 watchpoint. This is required because even if a software watchpoint
1829 is not watching any memory, bpstat_stop_status requires a location
1830 to be able to report stops. */
1833 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1834 struct program_space
*pspace
)
1836 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1838 b
->loc
= b
->allocate_location ();
1839 b
->loc
->pspace
= pspace
;
1840 b
->loc
->address
= -1;
1841 b
->loc
->length
= -1;
1844 /* Returns true if B is a software watchpoint that is not watching any
1845 memory (e.g., "watch $pc"). */
1848 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1850 return (b
->type
== bp_watchpoint
1852 && b
->loc
->next
== NULL
1853 && b
->loc
->address
== -1
1854 && b
->loc
->length
== -1);
1857 /* Assuming that B is a watchpoint:
1858 - Reparse watchpoint expression, if REPARSE is non-zero
1859 - Evaluate expression and store the result in B->val
1860 - Evaluate the condition if there is one, and store the result
1862 - Update the list of values that must be watched in B->loc.
1864 If the watchpoint disposition is disp_del_at_next_stop, then do
1865 nothing. If this is local watchpoint that is out of scope, delete
1868 Even with `set breakpoint always-inserted on' the watchpoints are
1869 removed + inserted on each stop here. Normal breakpoints must
1870 never be removed because they might be missed by a running thread
1871 when debugging in non-stop mode. On the other hand, hardware
1872 watchpoints (is_hardware_watchpoint; processed here) are specific
1873 to each LWP since they are stored in each LWP's hardware debug
1874 registers. Therefore, such LWP must be stopped first in order to
1875 be able to modify its hardware watchpoints.
1877 Hardware watchpoints must be reset exactly once after being
1878 presented to the user. It cannot be done sooner, because it would
1879 reset the data used to present the watchpoint hit to the user. And
1880 it must not be done later because it could display the same single
1881 watchpoint hit during multiple GDB stops. Note that the latter is
1882 relevant only to the hardware watchpoint types bp_read_watchpoint
1883 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1884 not user-visible - its hit is suppressed if the memory content has
1887 The following constraints influence the location where we can reset
1888 hardware watchpoints:
1890 * target_stopped_by_watchpoint and target_stopped_data_address are
1891 called several times when GDB stops.
1894 * Multiple hardware watchpoints can be hit at the same time,
1895 causing GDB to stop. GDB only presents one hardware watchpoint
1896 hit at a time as the reason for stopping, and all the other hits
1897 are presented later, one after the other, each time the user
1898 requests the execution to be resumed. Execution is not resumed
1899 for the threads still having pending hit event stored in
1900 LWP_INFO->STATUS. While the watchpoint is already removed from
1901 the inferior on the first stop the thread hit event is kept being
1902 reported from its cached value by linux_nat_stopped_data_address
1903 until the real thread resume happens after the watchpoint gets
1904 presented and thus its LWP_INFO->STATUS gets reset.
1906 Therefore the hardware watchpoint hit can get safely reset on the
1907 watchpoint removal from inferior. */
1910 update_watchpoint (struct watchpoint
*b
, int reparse
)
1912 int within_current_scope
;
1913 struct frame_id saved_frame_id
;
1916 /* If this is a local watchpoint, we only want to check if the
1917 watchpoint frame is in scope if the current thread is the thread
1918 that was used to create the watchpoint. */
1919 if (!watchpoint_in_thread_scope (b
))
1922 if (b
->disposition
== disp_del_at_next_stop
)
1927 /* Determine if the watchpoint is within scope. */
1928 if (b
->exp_valid_block
== NULL
)
1929 within_current_scope
= 1;
1932 struct frame_info
*fi
= get_current_frame ();
1933 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1934 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1936 /* If we're at a point where the stack has been destroyed
1937 (e.g. in a function epilogue), unwinding may not work
1938 properly. Do not attempt to recreate locations at this
1939 point. See similar comments in watchpoint_check. */
1940 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1943 /* Save the current frame's ID so we can restore it after
1944 evaluating the watchpoint expression on its own frame. */
1945 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1946 took a frame parameter, so that we didn't have to change the
1949 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1951 fi
= frame_find_by_id (b
->watchpoint_frame
);
1952 within_current_scope
= (fi
!= NULL
);
1953 if (within_current_scope
)
1957 /* We don't free locations. They are stored in the bp_location array
1958 and update_global_location_list will eventually delete them and
1959 remove breakpoints if needed. */
1962 if (within_current_scope
&& reparse
)
1967 s
= (b
->exp_string_reparse
1968 ? b
->exp_string_reparse
.get ()
1969 : b
->exp_string
.get ());
1970 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1971 /* If the meaning of expression itself changed, the old value is
1972 no longer relevant. We don't want to report a watchpoint hit
1973 to the user when the old value and the new value may actually
1974 be completely different objects. */
1976 b
->val_valid
= false;
1978 /* Note that unlike with breakpoints, the watchpoint's condition
1979 expression is stored in the breakpoint object, not in the
1980 locations (re)created below. */
1981 if (b
->cond_string
!= NULL
)
1983 b
->cond_exp
.reset ();
1985 s
= b
->cond_string
.get ();
1986 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1990 /* If we failed to parse the expression, for example because
1991 it refers to a global variable in a not-yet-loaded shared library,
1992 don't try to insert watchpoint. We don't automatically delete
1993 such watchpoint, though, since failure to parse expression
1994 is different from out-of-scope watchpoint. */
1995 if (!target_has_execution ())
1997 /* Without execution, memory can't change. No use to try and
1998 set watchpoint locations. The watchpoint will be reset when
1999 the target gains execution, through breakpoint_re_set. */
2000 if (!can_use_hw_watchpoints
)
2002 if (b
->works_in_software_mode ())
2003 b
->type
= bp_watchpoint
;
2005 error (_("Can't set read/access watchpoint when "
2006 "hardware watchpoints are disabled."));
2009 else if (within_current_scope
&& b
->exp
)
2011 std::vector
<value_ref_ptr
> val_chain
;
2012 struct value
*v
, *result
;
2013 struct program_space
*frame_pspace
;
2015 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
2018 /* Avoid setting b->val if it's already set. The meaning of
2019 b->val is 'the last value' user saw, and we should update
2020 it only if we reported that last value to user. As it
2021 happens, the code that reports it updates b->val directly.
2022 We don't keep track of the memory value for masked
2024 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
2026 if (b
->val_bitsize
!= 0)
2027 v
= extract_bitfield_from_watchpoint_value (b
, v
);
2028 b
->val
= release_value (v
);
2029 b
->val_valid
= true;
2032 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
2034 /* Look at each value on the value chain. */
2035 gdb_assert (!val_chain
.empty ());
2036 for (const value_ref_ptr
&iter
: val_chain
)
2040 /* If it's a memory location, and GDB actually needed
2041 its contents to evaluate the expression, then we
2042 must watch it. If the first value returned is
2043 still lazy, that means an error occurred reading it;
2044 watch it anyway in case it becomes readable. */
2045 if (VALUE_LVAL (v
) == lval_memory
2046 && (v
== val_chain
[0] || ! value_lazy (v
)))
2048 struct type
*vtype
= check_typedef (value_type (v
));
2050 /* We only watch structs and arrays if user asked
2051 for it explicitly, never if they just happen to
2052 appear in the middle of some value chain. */
2054 || (vtype
->code () != TYPE_CODE_STRUCT
2055 && vtype
->code () != TYPE_CODE_ARRAY
))
2058 enum target_hw_bp_type type
;
2059 struct bp_location
*loc
, **tmp
;
2060 int bitpos
= 0, bitsize
= 0;
2062 if (value_bitsize (v
) != 0)
2064 /* Extract the bit parameters out from the bitfield
2066 bitpos
= value_bitpos (v
);
2067 bitsize
= value_bitsize (v
);
2069 else if (v
== result
&& b
->val_bitsize
!= 0)
2071 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2072 lvalue whose bit parameters are saved in the fields
2073 VAL_BITPOS and VAL_BITSIZE. */
2074 bitpos
= b
->val_bitpos
;
2075 bitsize
= b
->val_bitsize
;
2078 addr
= value_address (v
);
2081 /* Skip the bytes that don't contain the bitfield. */
2086 if (b
->type
== bp_read_watchpoint
)
2088 else if (b
->type
== bp_access_watchpoint
)
2091 loc
= b
->allocate_location ();
2092 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2095 loc
->gdbarch
= value_type (v
)->arch ();
2097 loc
->pspace
= frame_pspace
;
2098 loc
->address
= address_significant (loc
->gdbarch
, addr
);
2102 /* Just cover the bytes that make up the bitfield. */
2103 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2106 loc
->length
= TYPE_LENGTH (value_type (v
));
2108 loc
->watchpoint_type
= type
;
2113 /* Change the type of breakpoint between hardware assisted or
2114 an ordinary watchpoint depending on the hardware support
2115 and free hardware slots. REPARSE is set when the inferior
2120 enum bp_loc_type loc_type
;
2122 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2126 int i
, target_resources_ok
, other_type_used
;
2129 /* Use an exact watchpoint when there's only one memory region to be
2130 watched, and only one debug register is needed to watch it. */
2131 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2133 /* We need to determine how many resources are already
2134 used for all other hardware watchpoints plus this one
2135 to see if we still have enough resources to also fit
2136 this watchpoint in as well. */
2138 /* If this is a software watchpoint, we try to turn it
2139 to a hardware one -- count resources as if B was of
2140 hardware watchpoint type. */
2142 if (type
== bp_watchpoint
)
2143 type
= bp_hardware_watchpoint
;
2145 /* This watchpoint may or may not have been placed on
2146 the list yet at this point (it won't be in the list
2147 if we're trying to create it for the first time,
2148 through watch_command), so always account for it
2151 /* Count resources used by all watchpoints except B. */
2152 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2154 /* Add in the resources needed for B. */
2155 i
+= hw_watchpoint_use_count (b
);
2158 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2159 if (target_resources_ok
<= 0)
2161 bool sw_mode
= b
->works_in_software_mode ();
2163 if (target_resources_ok
== 0 && !sw_mode
)
2164 error (_("Target does not support this type of "
2165 "hardware watchpoint."));
2166 else if (target_resources_ok
< 0 && !sw_mode
)
2167 error (_("There are not enough available hardware "
2168 "resources for this watchpoint."));
2170 /* Downgrade to software watchpoint. */
2171 b
->type
= bp_watchpoint
;
2175 /* If this was a software watchpoint, we've just
2176 found we have enough resources to turn it to a
2177 hardware watchpoint. Otherwise, this is a
2182 else if (!b
->works_in_software_mode ())
2184 if (!can_use_hw_watchpoints
)
2185 error (_("Can't set read/access watchpoint when "
2186 "hardware watchpoints are disabled."));
2188 error (_("Expression cannot be implemented with "
2189 "read/access watchpoint."));
2192 b
->type
= bp_watchpoint
;
2194 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2195 : bp_loc_hardware_watchpoint
);
2196 for (bp_location
*bl
: b
->locations ())
2197 bl
->loc_type
= loc_type
;
2200 /* If a software watchpoint is not watching any memory, then the
2201 above left it without any location set up. But,
2202 bpstat_stop_status requires a location to be able to report
2203 stops, so make sure there's at least a dummy one. */
2204 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2205 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2207 else if (!within_current_scope
)
2210 Watchpoint %d deleted because the program has left the block\n\
2211 in which its expression is valid.\n"),
2213 watchpoint_del_at_next_stop (b
);
2216 /* Restore the selected frame. */
2218 select_frame (frame_find_by_id (saved_frame_id
));
2222 /* Returns 1 iff breakpoint location should be
2223 inserted in the inferior. We don't differentiate the type of BL's owner
2224 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2225 breakpoint_ops is not defined, because in insert_bp_location,
2226 tracepoint's insert_location will not be called. */
2228 should_be_inserted (struct bp_location
*bl
)
2230 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2233 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2236 if (!bl
->enabled
|| bl
->disabled_by_cond
2237 || bl
->shlib_disabled
|| bl
->duplicate
)
2240 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2243 /* This is set for example, when we're attached to the parent of a
2244 vfork, and have detached from the child. The child is running
2245 free, and we expect it to do an exec or exit, at which point the
2246 OS makes the parent schedulable again (and the target reports
2247 that the vfork is done). Until the child is done with the shared
2248 memory region, do not insert breakpoints in the parent, otherwise
2249 the child could still trip on the parent's breakpoints. Since
2250 the parent is blocked anyway, it won't miss any breakpoint. */
2251 if (bl
->pspace
->breakpoints_not_allowed
)
2254 /* Don't insert a breakpoint if we're trying to step past its
2255 location, except if the breakpoint is a single-step breakpoint,
2256 and the breakpoint's thread is the thread which is stepping past
2258 if ((bl
->loc_type
== bp_loc_software_breakpoint
2259 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2260 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2262 /* The single-step breakpoint may be inserted at the location
2263 we're trying to step if the instruction branches to itself.
2264 However, the instruction won't be executed at all and it may
2265 break the semantics of the instruction, for example, the
2266 instruction is a conditional branch or updates some flags.
2267 We can't fix it unless GDB is able to emulate the instruction
2268 or switch to displaced stepping. */
2269 && !(bl
->owner
->type
== bp_single_step
2270 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2272 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2273 paddress (bl
->gdbarch
, bl
->address
));
2277 /* Don't insert watchpoints if we're trying to step past the
2278 instruction that triggered one. */
2279 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2280 && stepping_past_nonsteppable_watchpoint ())
2282 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2283 "skipping watchpoint at %s:%d",
2284 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2291 /* Same as should_be_inserted but does the check assuming
2292 that the location is not duplicated. */
2295 unduplicated_should_be_inserted (struct bp_location
*bl
)
2298 const int save_duplicate
= bl
->duplicate
;
2301 result
= should_be_inserted (bl
);
2302 bl
->duplicate
= save_duplicate
;
2306 /* Parses a conditional described by an expression COND into an
2307 agent expression bytecode suitable for evaluation
2308 by the bytecode interpreter. Return NULL if there was
2309 any error during parsing. */
2311 static agent_expr_up
2312 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2317 agent_expr_up aexpr
;
2319 /* We don't want to stop processing, so catch any errors
2320 that may show up. */
2323 aexpr
= gen_eval_for_expr (scope
, cond
);
2326 catch (const gdb_exception_error
&ex
)
2328 /* If we got here, it means the condition could not be parsed to a valid
2329 bytecode expression and thus can't be evaluated on the target's side.
2330 It's no use iterating through the conditions. */
2333 /* We have a valid agent expression. */
2337 /* Based on location BL, create a list of breakpoint conditions to be
2338 passed on to the target. If we have duplicated locations with different
2339 conditions, we will add such conditions to the list. The idea is that the
2340 target will evaluate the list of conditions and will only notify GDB when
2341 one of them is true. */
2344 build_target_condition_list (struct bp_location
*bl
)
2346 int null_condition_or_parse_error
= 0;
2347 int modified
= bl
->needs_update
;
2349 /* Release conditions left over from a previous insert. */
2350 bl
->target_info
.conditions
.clear ();
2352 /* This is only meaningful if the target is
2353 evaluating conditions and if the user has
2354 opted for condition evaluation on the target's
2356 if (gdb_evaluates_breakpoint_condition_p ()
2357 || !target_supports_evaluation_of_breakpoint_conditions ())
2360 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2362 /* Do a first pass to check for locations with no assigned
2363 conditions or conditions that fail to parse to a valid agent
2364 expression bytecode. If any of these happen, then it's no use to
2365 send conditions to the target since this location will always
2366 trigger and generate a response back to GDB. Note we consider
2367 all locations at the same address irrespective of type, i.e.,
2368 even if the locations aren't considered duplicates (e.g.,
2369 software breakpoint and hardware breakpoint at the same
2371 for (bp_location
*loc
: loc_range
)
2373 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2377 /* Re-parse the conditions since something changed. In that
2378 case we already freed the condition bytecodes (see
2379 force_breakpoint_reinsertion). We just
2380 need to parse the condition to bytecodes again. */
2381 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2385 /* If we have a NULL bytecode expression, it means something
2386 went wrong or we have a null condition expression. */
2387 if (!loc
->cond_bytecode
)
2389 null_condition_or_parse_error
= 1;
2395 /* If any of these happened, it means we will have to evaluate the conditions
2396 for the location's address on gdb's side. It is no use keeping bytecodes
2397 for all the other duplicate locations, thus we free all of them here.
2399 This is so we have a finer control over which locations' conditions are
2400 being evaluated by GDB or the remote stub. */
2401 if (null_condition_or_parse_error
)
2403 for (bp_location
*loc
: loc_range
)
2405 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2407 /* Only go as far as the first NULL bytecode is
2409 if (!loc
->cond_bytecode
)
2412 loc
->cond_bytecode
.reset ();
2417 /* No NULL conditions or failed bytecode generation. Build a
2418 condition list for this location's address. If we have software
2419 and hardware locations at the same address, they aren't
2420 considered duplicates, but we still marge all the conditions
2421 anyway, as it's simpler, and doesn't really make a practical
2423 for (bp_location
*loc
: loc_range
)
2425 && is_breakpoint (loc
->owner
)
2426 && loc
->pspace
->num
== bl
->pspace
->num
2427 && loc
->owner
->enable_state
== bp_enabled
2429 && !loc
->disabled_by_cond
)
2431 /* Add the condition to the vector. This will be used later
2432 to send the conditions to the target. */
2433 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2439 /* Parses a command described by string CMD into an agent expression
2440 bytecode suitable for evaluation by the bytecode interpreter.
2441 Return NULL if there was any error during parsing. */
2443 static agent_expr_up
2444 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2446 const char *cmdrest
;
2447 const char *format_start
, *format_end
;
2448 struct gdbarch
*gdbarch
= get_current_arch ();
2455 if (*cmdrest
== ',')
2457 cmdrest
= skip_spaces (cmdrest
);
2459 if (*cmdrest
++ != '"')
2460 error (_("No format string following the location"));
2462 format_start
= cmdrest
;
2464 format_pieces
fpieces (&cmdrest
);
2466 format_end
= cmdrest
;
2468 if (*cmdrest
++ != '"')
2469 error (_("Bad format string, non-terminated '\"'."));
2471 cmdrest
= skip_spaces (cmdrest
);
2473 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2474 error (_("Invalid argument syntax"));
2476 if (*cmdrest
== ',')
2478 cmdrest
= skip_spaces (cmdrest
);
2480 /* For each argument, make an expression. */
2482 std::vector
<struct expression
*> argvec
;
2483 while (*cmdrest
!= '\0')
2488 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2489 argvec
.push_back (expr
.release ());
2491 if (*cmdrest
== ',')
2495 agent_expr_up aexpr
;
2497 /* We don't want to stop processing, so catch any errors
2498 that may show up. */
2501 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2502 format_start
, format_end
- format_start
,
2503 argvec
.size (), argvec
.data ());
2505 catch (const gdb_exception_error
&ex
)
2507 /* If we got here, it means the command could not be parsed to a valid
2508 bytecode expression and thus can't be evaluated on the target's side.
2509 It's no use iterating through the other commands. */
2512 /* We have a valid agent expression, return it. */
2516 /* Based on location BL, create a list of breakpoint commands to be
2517 passed on to the target. If we have duplicated locations with
2518 different commands, we will add any such to the list. */
2521 build_target_command_list (struct bp_location
*bl
)
2523 int null_command_or_parse_error
= 0;
2524 int modified
= bl
->needs_update
;
2526 /* Clear commands left over from a previous insert. */
2527 bl
->target_info
.tcommands
.clear ();
2529 if (!target_can_run_breakpoint_commands ())
2532 /* For now, limit to agent-style dprintf breakpoints. */
2533 if (dprintf_style
!= dprintf_style_agent
)
2536 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2538 /* For now, if we have any location at the same address that isn't a
2539 dprintf, don't install the target-side commands, as that would
2540 make the breakpoint not be reported to the core, and we'd lose
2542 for (bp_location
*loc
: loc_range
)
2543 if (is_breakpoint (loc
->owner
)
2544 && loc
->pspace
->num
== bl
->pspace
->num
2545 && loc
->owner
->type
!= bp_dprintf
)
2548 /* Do a first pass to check for locations with no assigned
2549 conditions or conditions that fail to parse to a valid agent expression
2550 bytecode. If any of these happen, then it's no use to send conditions
2551 to the target since this location will always trigger and generate a
2552 response back to GDB. */
2553 for (bp_location
*loc
: loc_range
)
2555 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2559 /* Re-parse the commands since something changed. In that
2560 case we already freed the command bytecodes (see
2561 force_breakpoint_reinsertion). We just
2562 need to parse the command to bytecodes again. */
2564 = parse_cmd_to_aexpr (bl
->address
,
2565 loc
->owner
->extra_string
.get ());
2568 /* If we have a NULL bytecode expression, it means something
2569 went wrong or we have a null command expression. */
2570 if (!loc
->cmd_bytecode
)
2572 null_command_or_parse_error
= 1;
2578 /* If anything failed, then we're not doing target-side commands,
2580 if (null_command_or_parse_error
)
2582 for (bp_location
*loc
: loc_range
)
2583 if (is_breakpoint (loc
->owner
)
2584 && loc
->pspace
->num
== bl
->pspace
->num
)
2586 /* Only go as far as the first NULL bytecode is
2588 if (loc
->cmd_bytecode
== NULL
)
2591 loc
->cmd_bytecode
.reset ();
2595 /* No NULL commands or failed bytecode generation. Build a command
2596 list for all duplicate locations at this location's address.
2597 Note that here we must care for whether the breakpoint location
2598 types are considered duplicates, otherwise, say, if we have a
2599 software and hardware location at the same address, the target
2600 could end up running the commands twice. For the moment, we only
2601 support targets-side commands with dprintf, but it doesn't hurt
2602 to be pedantically correct in case that changes. */
2603 for (bp_location
*loc
: loc_range
)
2604 if (breakpoint_locations_match (bl
, loc
)
2605 && loc
->owner
->extra_string
2606 && is_breakpoint (loc
->owner
)
2607 && loc
->pspace
->num
== bl
->pspace
->num
2608 && loc
->owner
->enable_state
== bp_enabled
2610 && !loc
->disabled_by_cond
)
2612 /* Add the command to the vector. This will be used later
2613 to send the commands to the target. */
2614 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2617 bl
->target_info
.persist
= 0;
2618 /* Maybe flag this location as persistent. */
2619 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2620 bl
->target_info
.persist
= 1;
2623 /* Return the kind of breakpoint on address *ADDR. Get the kind
2624 of breakpoint according to ADDR except single-step breakpoint.
2625 Get the kind of single-step breakpoint according to the current
2629 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2631 if (bl
->owner
->type
== bp_single_step
)
2633 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2634 struct regcache
*regcache
;
2636 regcache
= get_thread_regcache (thr
);
2638 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2642 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2645 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2646 location. Any error messages are printed to TMP_ERROR_STREAM; and
2647 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2648 Returns 0 for success, 1 if the bp_location type is not supported or
2651 NOTE drow/2003-09-09: This routine could be broken down to an
2652 object-style method for each breakpoint or catchpoint type. */
2654 insert_bp_location (struct bp_location
*bl
,
2655 struct ui_file
*tmp_error_stream
,
2656 int *disabled_breaks
,
2657 int *hw_breakpoint_error
,
2658 int *hw_bp_error_explained_already
)
2660 gdb_exception bp_excpt
;
2662 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2665 /* Note we don't initialize bl->target_info, as that wipes out
2666 the breakpoint location's shadow_contents if the breakpoint
2667 is still inserted at that location. This in turn breaks
2668 target_read_memory which depends on these buffers when
2669 a memory read is requested at the breakpoint location:
2670 Once the target_info has been wiped, we fail to see that
2671 we have a breakpoint inserted at that address and thus
2672 read the breakpoint instead of returning the data saved in
2673 the breakpoint location's shadow contents. */
2674 bl
->target_info
.reqstd_address
= bl
->address
;
2675 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2676 bl
->target_info
.length
= bl
->length
;
2678 /* When working with target-side conditions, we must pass all the conditions
2679 for the same breakpoint address down to the target since GDB will not
2680 insert those locations. With a list of breakpoint conditions, the target
2681 can decide when to stop and notify GDB. */
2683 if (is_breakpoint (bl
->owner
))
2685 build_target_condition_list (bl
);
2686 build_target_command_list (bl
);
2687 /* Reset the modification marker. */
2688 bl
->needs_update
= 0;
2691 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2692 set at a read-only address, then a breakpoint location will have
2693 been changed to hardware breakpoint before we get here. If it is
2694 "off" however, error out before actually trying to insert the
2695 breakpoint, with a nicer error message. */
2696 if (bl
->loc_type
== bp_loc_software_breakpoint
2697 && !automatic_hardware_breakpoints
)
2699 mem_region
*mr
= lookup_mem_region (bl
->address
);
2701 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2703 gdb_printf (tmp_error_stream
,
2704 _("Cannot insert breakpoint %d.\n"
2705 "Cannot set software breakpoint "
2706 "at read-only address %s\n"),
2708 paddress (bl
->gdbarch
, bl
->address
));
2713 if (bl
->loc_type
== bp_loc_software_breakpoint
2714 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2716 /* First check to see if we have to handle an overlay. */
2717 if (overlay_debugging
== ovly_off
2718 || bl
->section
== NULL
2719 || !(section_is_overlay (bl
->section
)))
2721 /* No overlay handling: just set the breakpoint. */
2726 val
= bl
->owner
->insert_location (bl
);
2728 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2730 catch (gdb_exception
&e
)
2732 bp_excpt
= std::move (e
);
2737 /* This breakpoint is in an overlay section.
2738 Shall we set a breakpoint at the LMA? */
2739 if (!overlay_events_enabled
)
2741 /* Yes -- overlay event support is not active,
2742 so we must try to set a breakpoint at the LMA.
2743 This will not work for a hardware breakpoint. */
2744 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2745 warning (_("hardware breakpoint %d not supported in overlay!"),
2749 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2751 /* Set a software (trap) breakpoint at the LMA. */
2752 bl
->overlay_target_info
= bl
->target_info
;
2753 bl
->overlay_target_info
.reqstd_address
= addr
;
2755 /* No overlay handling: just set the breakpoint. */
2760 bl
->overlay_target_info
.kind
2761 = breakpoint_kind (bl
, &addr
);
2762 bl
->overlay_target_info
.placed_address
= addr
;
2763 val
= target_insert_breakpoint (bl
->gdbarch
,
2764 &bl
->overlay_target_info
);
2767 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2769 catch (gdb_exception
&e
)
2771 bp_excpt
= std::move (e
);
2774 if (bp_excpt
.reason
!= 0)
2775 gdb_printf (tmp_error_stream
,
2776 "Overlay breakpoint %d "
2777 "failed: in ROM?\n",
2781 /* Shall we set a breakpoint at the VMA? */
2782 if (section_is_mapped (bl
->section
))
2784 /* Yes. This overlay section is mapped into memory. */
2789 val
= bl
->owner
->insert_location (bl
);
2791 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2793 catch (gdb_exception
&e
)
2795 bp_excpt
= std::move (e
);
2800 /* No. This breakpoint will not be inserted.
2801 No error, but do not mark the bp as 'inserted'. */
2806 if (bp_excpt
.reason
!= 0)
2808 /* Can't set the breakpoint. */
2810 /* If the target has closed then it will have deleted any
2811 breakpoints inserted within the target inferior, as a result
2812 any further attempts to interact with the breakpoint objects
2813 is not possible. Just rethrow the error. */
2814 if (bp_excpt
.error
== TARGET_CLOSE_ERROR
)
2816 gdb_assert (bl
->owner
!= nullptr);
2818 /* In some cases, we might not be able to insert a
2819 breakpoint in a shared library that has already been
2820 removed, but we have not yet processed the shlib unload
2821 event. Unfortunately, some targets that implement
2822 breakpoint insertion themselves can't tell why the
2823 breakpoint insertion failed (e.g., the remote target
2824 doesn't define error codes), so we must treat generic
2825 errors as memory errors. */
2826 if (bp_excpt
.reason
== RETURN_ERROR
2827 && (bp_excpt
.error
== GENERIC_ERROR
2828 || bp_excpt
.error
== MEMORY_ERROR
)
2829 && bl
->loc_type
== bp_loc_software_breakpoint
2830 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2831 || shared_objfile_contains_address_p (bl
->pspace
,
2834 /* See also: disable_breakpoints_in_shlibs. */
2835 bl
->shlib_disabled
= 1;
2836 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2837 if (!*disabled_breaks
)
2839 gdb_printf (tmp_error_stream
,
2840 "Cannot insert breakpoint %d.\n",
2842 gdb_printf (tmp_error_stream
,
2843 "Temporarily disabling shared "
2844 "library breakpoints:\n");
2846 *disabled_breaks
= 1;
2847 gdb_printf (tmp_error_stream
,
2848 "breakpoint #%d\n", bl
->owner
->number
);
2853 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2855 *hw_breakpoint_error
= 1;
2856 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2857 gdb_printf (tmp_error_stream
,
2858 "Cannot insert hardware breakpoint %d%s",
2860 bp_excpt
.message
? ":" : ".\n");
2861 if (bp_excpt
.message
!= NULL
)
2862 gdb_printf (tmp_error_stream
, "%s.\n",
2867 if (bp_excpt
.message
== NULL
)
2870 = memory_error_message (TARGET_XFER_E_IO
,
2871 bl
->gdbarch
, bl
->address
);
2873 gdb_printf (tmp_error_stream
,
2874 "Cannot insert breakpoint %d.\n"
2876 bl
->owner
->number
, message
.c_str ());
2880 gdb_printf (tmp_error_stream
,
2881 "Cannot insert breakpoint %d: %s\n",
2896 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2897 /* NOTE drow/2003-09-08: This state only exists for removing
2898 watchpoints. It's not clear that it's necessary... */
2899 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2903 val
= bl
->owner
->insert_location (bl
);
2905 /* If trying to set a read-watchpoint, and it turns out it's not
2906 supported, try emulating one with an access watchpoint. */
2907 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2909 /* But don't try to insert it, if there's already another
2910 hw_access location that would be considered a duplicate
2912 for (bp_location
*loc
: all_bp_locations ())
2914 && loc
->watchpoint_type
== hw_access
2915 && watchpoint_locations_match (bl
, loc
))
2919 bl
->target_info
= loc
->target_info
;
2920 bl
->watchpoint_type
= hw_access
;
2927 bl
->watchpoint_type
= hw_access
;
2928 val
= bl
->owner
->insert_location (bl
);
2931 /* Back to the original value. */
2932 bl
->watchpoint_type
= hw_read
;
2936 bl
->inserted
= (val
== 0);
2939 else if (bl
->owner
->type
== bp_catchpoint
)
2943 val
= bl
->owner
->insert_location (bl
);
2946 bl
->owner
->enable_state
= bp_disabled
;
2950 Error inserting catchpoint %d: Your system does not support this type\n\
2951 of catchpoint."), bl
->owner
->number
);
2953 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2956 bl
->inserted
= (val
== 0);
2958 /* We've already printed an error message if there was a problem
2959 inserting this catchpoint, and we've disabled the catchpoint,
2960 so just return success. */
2967 /* This function is called when program space PSPACE is about to be
2968 deleted. It takes care of updating breakpoints to not reference
2972 breakpoint_program_space_exit (struct program_space
*pspace
)
2974 /* Remove any breakpoint that was set through this program space. */
2975 for (breakpoint
*b
: all_breakpoints_safe ())
2976 if (b
->pspace
== pspace
)
2977 delete_breakpoint (b
);
2979 /* Breakpoints set through other program spaces could have locations
2980 bound to PSPACE as well. Remove those. */
2981 for (bp_location
*loc
: all_bp_locations ())
2983 struct bp_location
*tmp
;
2985 if (loc
->pspace
== pspace
)
2987 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2988 if (loc
->owner
->loc
== loc
)
2989 loc
->owner
->loc
= loc
->next
;
2991 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2992 if (tmp
->next
== loc
)
2994 tmp
->next
= loc
->next
;
3000 /* Now update the global location list to permanently delete the
3001 removed locations above. */
3002 update_global_location_list (UGLL_DONT_INSERT
);
3005 /* Make sure all breakpoints are inserted in inferior.
3006 Throws exception on any error.
3007 A breakpoint that is already inserted won't be inserted
3008 again, so calling this function twice is safe. */
3010 insert_breakpoints (void)
3012 for (breakpoint
*bpt
: all_breakpoints ())
3013 if (is_hardware_watchpoint (bpt
))
3015 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3017 update_watchpoint (w
, 0 /* don't reparse. */);
3020 /* Updating watchpoints creates new locations, so update the global
3021 location list. Explicitly tell ugll to insert locations and
3022 ignore breakpoints_always_inserted_mode. Also,
3023 update_global_location_list tries to "upgrade" software
3024 breakpoints to hardware breakpoints to handle "set breakpoint
3025 auto-hw", so we need to call it even if we don't have new
3027 update_global_location_list (UGLL_INSERT
);
3030 /* This is used when we need to synch breakpoint conditions between GDB and the
3031 target. It is the case with deleting and disabling of breakpoints when using
3032 always-inserted mode. */
3035 update_inserted_breakpoint_locations (void)
3039 int disabled_breaks
= 0;
3040 int hw_breakpoint_error
= 0;
3041 int hw_bp_details_reported
= 0;
3043 string_file tmp_error_stream
;
3045 /* Explicitly mark the warning -- this will only be printed if
3046 there was an error. */
3047 tmp_error_stream
.puts ("Warning:\n");
3049 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3051 for (bp_location
*bl
: all_bp_locations ())
3053 /* We only want to update software breakpoints and hardware
3055 if (!is_breakpoint (bl
->owner
))
3058 /* We only want to update locations that are already inserted
3059 and need updating. This is to avoid unwanted insertion during
3060 deletion of breakpoints. */
3061 if (!bl
->inserted
|| !bl
->needs_update
)
3064 switch_to_program_space_and_thread (bl
->pspace
);
3066 /* For targets that support global breakpoints, there's no need
3067 to select an inferior to insert breakpoint to. In fact, even
3068 if we aren't attached to any process yet, we should still
3069 insert breakpoints. */
3070 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3071 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3074 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3075 &hw_breakpoint_error
, &hw_bp_details_reported
);
3082 target_terminal::ours_for_output ();
3083 error_stream (tmp_error_stream
);
3087 /* Used when starting or continuing the program. */
3090 insert_breakpoint_locations (void)
3094 int disabled_breaks
= 0;
3095 int hw_breakpoint_error
= 0;
3096 int hw_bp_error_explained_already
= 0;
3098 string_file tmp_error_stream
;
3100 /* Explicitly mark the warning -- this will only be printed if
3101 there was an error. */
3102 tmp_error_stream
.puts ("Warning:\n");
3104 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3106 for (bp_location
*bl
: all_bp_locations ())
3108 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3111 /* There is no point inserting thread-specific breakpoints if
3112 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3113 has BL->OWNER always non-NULL. */
3114 if (bl
->owner
->thread
!= -1
3115 && !valid_global_thread_id (bl
->owner
->thread
))
3118 switch_to_program_space_and_thread (bl
->pspace
);
3120 /* For targets that support global breakpoints, there's no need
3121 to select an inferior to insert breakpoint to. In fact, even
3122 if we aren't attached to any process yet, we should still
3123 insert breakpoints. */
3124 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3125 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3128 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3129 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3134 /* If we failed to insert all locations of a watchpoint, remove
3135 them, as half-inserted watchpoint is of limited use. */
3136 for (breakpoint
*bpt
: all_breakpoints ())
3138 int some_failed
= 0;
3140 if (!is_hardware_watchpoint (bpt
))
3143 if (!breakpoint_enabled (bpt
))
3146 if (bpt
->disposition
== disp_del_at_next_stop
)
3149 for (bp_location
*loc
: bpt
->locations ())
3150 if (!loc
->inserted
&& should_be_inserted (loc
))
3158 for (bp_location
*loc
: bpt
->locations ())
3160 remove_breakpoint (loc
);
3162 hw_breakpoint_error
= 1;
3163 tmp_error_stream
.printf ("Could not insert "
3164 "hardware watchpoint %d.\n",
3172 /* If a hardware breakpoint or watchpoint was inserted, add a
3173 message about possibly exhausted resources. */
3174 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3176 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3177 You may have requested too many hardware breakpoints/watchpoints.\n");
3179 target_terminal::ours_for_output ();
3180 error_stream (tmp_error_stream
);
3184 /* Used when the program stops.
3185 Returns zero if successful, or non-zero if there was a problem
3186 removing a breakpoint location. */
3189 remove_breakpoints (void)
3193 for (bp_location
*bl
: all_bp_locations ())
3194 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3195 val
|= remove_breakpoint (bl
);
3200 /* When a thread exits, remove breakpoints that are related to
3204 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3206 for (breakpoint
*b
: all_breakpoints_safe ())
3208 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3210 b
->disposition
= disp_del_at_next_stop
;
3213 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3214 b
->number
, print_thread_id (tp
));
3216 /* Hide it from the user. */
3222 /* See breakpoint.h. */
3225 remove_breakpoints_inf (inferior
*inf
)
3229 for (bp_location
*bl
: all_bp_locations ())
3231 if (bl
->pspace
!= inf
->pspace
)
3234 if (bl
->inserted
&& !bl
->target_info
.persist
)
3236 val
= remove_breakpoint (bl
);
3243 static int internal_breakpoint_number
= -1;
3245 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3246 If INTERNAL is non-zero, the breakpoint number will be populated
3247 from internal_breakpoint_number and that variable decremented.
3248 Otherwise the breakpoint number will be populated from
3249 breakpoint_count and that value incremented. Internal breakpoints
3250 do not set the internal var bpnum. */
3252 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3255 b
->number
= internal_breakpoint_number
--;
3258 set_breakpoint_count (breakpoint_count
+ 1);
3259 b
->number
= breakpoint_count
;
3263 static struct breakpoint
*
3264 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3265 CORE_ADDR address
, enum bptype type
)
3267 symtab_and_line sal
;
3269 sal
.section
= find_pc_overlay (sal
.pc
);
3270 sal
.pspace
= current_program_space
;
3272 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
);
3273 b
->number
= internal_breakpoint_number
--;
3274 b
->disposition
= disp_donttouch
;
3279 static const char *const longjmp_names
[] =
3281 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3283 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3285 /* Per-objfile data private to breakpoint.c. */
3286 struct breakpoint_objfile_data
3288 /* Minimal symbol for "_ovly_debug_event" (if any). */
3289 struct bound_minimal_symbol overlay_msym
;
3291 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3292 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3294 /* True if we have looked for longjmp probes. */
3295 int longjmp_searched
= 0;
3297 /* SystemTap probe points for longjmp (if any). These are non-owning
3299 std::vector
<probe
*> longjmp_probes
;
3301 /* Minimal symbol for "std::terminate()" (if any). */
3302 struct bound_minimal_symbol terminate_msym
;
3304 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3305 struct bound_minimal_symbol exception_msym
;
3307 /* True if we have looked for exception probes. */
3308 int exception_searched
= 0;
3310 /* SystemTap probe points for unwinding (if any). These are non-owning
3312 std::vector
<probe
*> exception_probes
;
3315 static const struct objfile_key
<breakpoint_objfile_data
>
3316 breakpoint_objfile_key
;
3318 /* Minimal symbol not found sentinel. */
3319 static struct minimal_symbol msym_not_found
;
3321 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3324 msym_not_found_p (const struct minimal_symbol
*msym
)
3326 return msym
== &msym_not_found
;
3329 /* Return per-objfile data needed by breakpoint.c.
3330 Allocate the data if necessary. */
3332 static struct breakpoint_objfile_data
*
3333 get_breakpoint_objfile_data (struct objfile
*objfile
)
3335 struct breakpoint_objfile_data
*bp_objfile_data
;
3337 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3338 if (bp_objfile_data
== NULL
)
3339 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3340 return bp_objfile_data
;
3344 create_overlay_event_breakpoint (void)
3346 const char *const func_name
= "_ovly_debug_event";
3348 for (objfile
*objfile
: current_program_space
->objfiles ())
3350 struct breakpoint
*b
;
3351 struct breakpoint_objfile_data
*bp_objfile_data
;
3353 struct explicit_location explicit_loc
;
3355 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3357 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3360 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3362 struct bound_minimal_symbol m
;
3364 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3365 if (m
.minsym
== NULL
)
3367 /* Avoid future lookups in this objfile. */
3368 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3371 bp_objfile_data
->overlay_msym
= m
;
3374 addr
= bp_objfile_data
->overlay_msym
.value_address ();
3375 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3377 initialize_explicit_location (&explicit_loc
);
3378 explicit_loc
.function_name
= ASTRDUP (func_name
);
3379 b
->location
= new_explicit_location (&explicit_loc
);
3381 if (overlay_debugging
== ovly_auto
)
3383 b
->enable_state
= bp_enabled
;
3384 overlay_events_enabled
= 1;
3388 b
->enable_state
= bp_disabled
;
3389 overlay_events_enabled
= 0;
3394 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3395 true if a breakpoint was installed. */
3398 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3400 struct gdbarch
*gdbarch
= objfile
->arch ();
3401 struct breakpoint_objfile_data
*bp_objfile_data
3402 = get_breakpoint_objfile_data (objfile
);
3404 if (!bp_objfile_data
->longjmp_searched
)
3406 std::vector
<probe
*> ret
3407 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3411 /* We are only interested in checking one element. */
3414 if (!p
->can_evaluate_arguments ())
3416 /* We cannot use the probe interface here,
3417 because it does not know how to evaluate
3422 bp_objfile_data
->longjmp_probes
= ret
;
3423 bp_objfile_data
->longjmp_searched
= 1;
3426 if (bp_objfile_data
->longjmp_probes
.empty ())
3429 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3431 struct breakpoint
*b
;
3433 b
= create_internal_breakpoint (gdbarch
,
3434 p
->get_relocated_address (objfile
),
3436 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3437 b
->enable_state
= bp_disabled
;
3443 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3444 Return true if at least one breakpoint was installed. */
3447 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3449 struct gdbarch
*gdbarch
= objfile
->arch ();
3450 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3453 struct breakpoint_objfile_data
*bp_objfile_data
3454 = get_breakpoint_objfile_data (objfile
);
3455 unsigned int installed_bp
= 0;
3457 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3459 struct breakpoint
*b
;
3460 const char *func_name
;
3462 struct explicit_location explicit_loc
;
3464 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3467 func_name
= longjmp_names
[i
];
3468 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3470 struct bound_minimal_symbol m
;
3472 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3473 if (m
.minsym
== NULL
)
3475 /* Prevent future lookups in this objfile. */
3476 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3479 bp_objfile_data
->longjmp_msym
[i
] = m
;
3482 addr
= bp_objfile_data
->longjmp_msym
[i
].value_address ();
3483 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
3484 initialize_explicit_location (&explicit_loc
);
3485 explicit_loc
.function_name
= ASTRDUP (func_name
);
3486 b
->location
= new_explicit_location (&explicit_loc
);
3487 b
->enable_state
= bp_disabled
;
3491 return installed_bp
> 0;
3494 /* Create a master longjmp breakpoint. */
3497 create_longjmp_master_breakpoint (void)
3499 scoped_restore_current_program_space restore_pspace
;
3501 for (struct program_space
*pspace
: program_spaces
)
3503 set_current_program_space (pspace
);
3505 for (objfile
*obj
: current_program_space
->objfiles ())
3507 /* Skip separate debug object, it's handled in the loop below. */
3508 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3511 /* Try a probe kind breakpoint on main objfile. */
3512 if (create_longjmp_master_breakpoint_probe (obj
))
3515 /* Try longjmp_names kind breakpoints on main and separate_debug
3517 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3518 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3524 /* Create a master std::terminate breakpoint. */
3526 create_std_terminate_master_breakpoint (void)
3528 const char *const func_name
= "std::terminate()";
3530 scoped_restore_current_program_space restore_pspace
;
3532 for (struct program_space
*pspace
: program_spaces
)
3536 set_current_program_space (pspace
);
3538 for (objfile
*objfile
: current_program_space
->objfiles ())
3540 struct breakpoint
*b
;
3541 struct breakpoint_objfile_data
*bp_objfile_data
;
3542 struct explicit_location explicit_loc
;
3544 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3546 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3549 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3551 struct bound_minimal_symbol m
;
3553 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3554 if (m
.minsym
== NULL
|| (m
.minsym
->type () != mst_text
3555 && m
.minsym
->type () != mst_file_text
))
3557 /* Prevent future lookups in this objfile. */
3558 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3561 bp_objfile_data
->terminate_msym
= m
;
3564 addr
= bp_objfile_data
->terminate_msym
.value_address ();
3565 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3566 bp_std_terminate_master
);
3567 initialize_explicit_location (&explicit_loc
);
3568 explicit_loc
.function_name
= ASTRDUP (func_name
);
3569 b
->location
= new_explicit_location (&explicit_loc
);
3570 b
->enable_state
= bp_disabled
;
3575 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3576 probe. Return true if a breakpoint was installed. */
3579 create_exception_master_breakpoint_probe (objfile
*objfile
)
3581 struct breakpoint
*b
;
3582 struct gdbarch
*gdbarch
;
3583 struct breakpoint_objfile_data
*bp_objfile_data
;
3585 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3587 /* We prefer the SystemTap probe point if it exists. */
3588 if (!bp_objfile_data
->exception_searched
)
3590 std::vector
<probe
*> ret
3591 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3595 /* We are only interested in checking one element. */
3598 if (!p
->can_evaluate_arguments ())
3600 /* We cannot use the probe interface here, because it does
3601 not know how to evaluate arguments. */
3605 bp_objfile_data
->exception_probes
= ret
;
3606 bp_objfile_data
->exception_searched
= 1;
3609 if (bp_objfile_data
->exception_probes
.empty ())
3612 gdbarch
= objfile
->arch ();
3614 for (probe
*p
: bp_objfile_data
->exception_probes
)
3616 b
= create_internal_breakpoint (gdbarch
,
3617 p
->get_relocated_address (objfile
),
3618 bp_exception_master
);
3619 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3620 b
->enable_state
= bp_disabled
;
3626 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3627 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3630 create_exception_master_breakpoint_hook (objfile
*objfile
)
3632 const char *const func_name
= "_Unwind_DebugHook";
3633 struct breakpoint
*b
;
3634 struct gdbarch
*gdbarch
;
3635 struct breakpoint_objfile_data
*bp_objfile_data
;
3637 struct explicit_location explicit_loc
;
3639 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3641 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3644 gdbarch
= objfile
->arch ();
3646 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3648 struct bound_minimal_symbol debug_hook
;
3650 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3651 if (debug_hook
.minsym
== NULL
)
3653 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3657 bp_objfile_data
->exception_msym
= debug_hook
;
3660 addr
= bp_objfile_data
->exception_msym
.value_address ();
3661 addr
= gdbarch_convert_from_func_ptr_addr
3662 (gdbarch
, addr
, current_inferior ()->top_target ());
3663 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
3664 initialize_explicit_location (&explicit_loc
);
3665 explicit_loc
.function_name
= ASTRDUP (func_name
);
3666 b
->location
= new_explicit_location (&explicit_loc
);
3667 b
->enable_state
= bp_disabled
;
3672 /* Install a master breakpoint on the unwinder's debug hook. */
3675 create_exception_master_breakpoint (void)
3677 for (objfile
*obj
: current_program_space
->objfiles ())
3679 /* Skip separate debug object. */
3680 if (obj
->separate_debug_objfile_backlink
)
3683 /* Try a probe kind breakpoint. */
3684 if (create_exception_master_breakpoint_probe (obj
))
3687 /* Iterate over main and separate debug objects and try an
3688 _Unwind_DebugHook kind breakpoint. */
3689 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3690 if (create_exception_master_breakpoint_hook (debug_objfile
))
3695 /* Does B have a location spec? */
3698 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3700 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3704 update_breakpoints_after_exec (void)
3706 /* We're about to delete breakpoints from GDB's lists. If the
3707 INSERTED flag is true, GDB will try to lift the breakpoints by
3708 writing the breakpoints' "shadow contents" back into memory. The
3709 "shadow contents" are NOT valid after an exec, so GDB should not
3710 do that. Instead, the target is responsible from marking
3711 breakpoints out as soon as it detects an exec. We don't do that
3712 here instead, because there may be other attempts to delete
3713 breakpoints after detecting an exec and before reaching here. */
3714 for (bp_location
*bploc
: all_bp_locations ())
3715 if (bploc
->pspace
== current_program_space
)
3716 gdb_assert (!bploc
->inserted
);
3718 for (breakpoint
*b
: all_breakpoints_safe ())
3720 if (b
->pspace
!= current_program_space
)
3723 /* Solib breakpoints must be explicitly reset after an exec(). */
3724 if (b
->type
== bp_shlib_event
)
3726 delete_breakpoint (b
);
3730 /* JIT breakpoints must be explicitly reset after an exec(). */
3731 if (b
->type
== bp_jit_event
)
3733 delete_breakpoint (b
);
3737 /* Thread event breakpoints must be set anew after an exec(),
3738 as must overlay event and longjmp master breakpoints. */
3739 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3740 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3741 || b
->type
== bp_exception_master
)
3743 delete_breakpoint (b
);
3747 /* Step-resume breakpoints are meaningless after an exec(). */
3748 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3750 delete_breakpoint (b
);
3754 /* Just like single-step breakpoints. */
3755 if (b
->type
== bp_single_step
)
3757 delete_breakpoint (b
);
3761 /* Longjmp and longjmp-resume breakpoints are also meaningless
3763 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3764 || b
->type
== bp_longjmp_call_dummy
3765 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3767 delete_breakpoint (b
);
3771 if (b
->type
== bp_catchpoint
)
3773 /* For now, none of the bp_catchpoint breakpoints need to
3774 do anything at this point. In the future, if some of
3775 the catchpoints need to something, we will need to add
3776 a new method, and call this method from here. */
3780 /* bp_finish is a special case. The only way we ought to be able
3781 to see one of these when an exec() has happened, is if the user
3782 caught a vfork, and then said "finish". Ordinarily a finish just
3783 carries them to the call-site of the current callee, by setting
3784 a temporary bp there and resuming. But in this case, the finish
3785 will carry them entirely through the vfork & exec.
3787 We don't want to allow a bp_finish to remain inserted now. But
3788 we can't safely delete it, 'cause finish_command has a handle to
3789 the bp on a bpstat, and will later want to delete it. There's a
3790 chance (and I've seen it happen) that if we delete the bp_finish
3791 here, that its storage will get reused by the time finish_command
3792 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3793 We really must allow finish_command to delete a bp_finish.
3795 In the absence of a general solution for the "how do we know
3796 it's safe to delete something others may have handles to?"
3797 problem, what we'll do here is just uninsert the bp_finish, and
3798 let finish_command delete it.
3800 (We know the bp_finish is "doomed" in the sense that it's
3801 momentary, and will be deleted as soon as finish_command sees
3802 the inferior stopped. So it doesn't matter that the bp's
3803 address is probably bogus in the new a.out, unlike e.g., the
3804 solib breakpoints.) */
3806 if (b
->type
== bp_finish
)
3811 /* Without a symbolic address, we have little hope of the
3812 pre-exec() address meaning the same thing in the post-exec()
3814 if (breakpoint_event_location_empty_p (b
))
3816 delete_breakpoint (b
);
3823 detach_breakpoints (ptid_t ptid
)
3826 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3827 struct inferior
*inf
= current_inferior ();
3829 if (ptid
.pid () == inferior_ptid
.pid ())
3830 error (_("Cannot detach breakpoints of inferior_ptid"));
3832 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3833 inferior_ptid
= ptid
;
3834 for (bp_location
*bl
: all_bp_locations ())
3836 if (bl
->pspace
!= inf
->pspace
)
3839 /* This function must physically remove breakpoints locations
3840 from the specified ptid, without modifying the breakpoint
3841 package's state. Locations of type bp_loc_other are only
3842 maintained at GDB side. So, there is no need to remove
3843 these bp_loc_other locations. Moreover, removing these
3844 would modify the breakpoint package's state. */
3845 if (bl
->loc_type
== bp_loc_other
)
3849 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3855 /* Remove the breakpoint location BL from the current address space.
3856 Note that this is used to detach breakpoints from a child fork.
3857 When we get here, the child isn't in the inferior list, and neither
3858 do we have objects to represent its address space --- we should
3859 *not* look at bl->pspace->aspace here. */
3862 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3866 /* BL is never in moribund_locations by our callers. */
3867 gdb_assert (bl
->owner
!= NULL
);
3869 /* The type of none suggests that owner is actually deleted.
3870 This should not ever happen. */
3871 gdb_assert (bl
->owner
->type
!= bp_none
);
3873 if (bl
->loc_type
== bp_loc_software_breakpoint
3874 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3876 /* "Normal" instruction breakpoint: either the standard
3877 trap-instruction bp (bp_breakpoint), or a
3878 bp_hardware_breakpoint. */
3880 /* First check to see if we have to handle an overlay. */
3881 if (overlay_debugging
== ovly_off
3882 || bl
->section
== NULL
3883 || !(section_is_overlay (bl
->section
)))
3885 /* No overlay handling: just remove the breakpoint. */
3887 /* If we're trying to uninsert a memory breakpoint that we
3888 know is set in a dynamic object that is marked
3889 shlib_disabled, then either the dynamic object was
3890 removed with "remove-symbol-file" or with
3891 "nosharedlibrary". In the former case, we don't know
3892 whether another dynamic object might have loaded over the
3893 breakpoint's address -- the user might well let us know
3894 about it next with add-symbol-file (the whole point of
3895 add-symbol-file is letting the user manually maintain a
3896 list of dynamically loaded objects). If we have the
3897 breakpoint's shadow memory, that is, this is a software
3898 breakpoint managed by GDB, check whether the breakpoint
3899 is still inserted in memory, to avoid overwriting wrong
3900 code with stale saved shadow contents. Note that HW
3901 breakpoints don't have shadow memory, as they're
3902 implemented using a mechanism that is not dependent on
3903 being able to modify the target's memory, and as such
3904 they should always be removed. */
3905 if (bl
->shlib_disabled
3906 && bl
->target_info
.shadow_len
!= 0
3907 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3910 val
= bl
->owner
->remove_location (bl
, reason
);
3914 /* This breakpoint is in an overlay section.
3915 Did we set a breakpoint at the LMA? */
3916 if (!overlay_events_enabled
)
3918 /* Yes -- overlay event support is not active, so we
3919 should have set a breakpoint at the LMA. Remove it.
3921 /* Ignore any failures: if the LMA is in ROM, we will
3922 have already warned when we failed to insert it. */
3923 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3924 target_remove_hw_breakpoint (bl
->gdbarch
,
3925 &bl
->overlay_target_info
);
3927 target_remove_breakpoint (bl
->gdbarch
,
3928 &bl
->overlay_target_info
,
3931 /* Did we set a breakpoint at the VMA?
3932 If so, we will have marked the breakpoint 'inserted'. */
3935 /* Yes -- remove it. Previously we did not bother to
3936 remove the breakpoint if the section had been
3937 unmapped, but let's not rely on that being safe. We
3938 don't know what the overlay manager might do. */
3940 /* However, we should remove *software* breakpoints only
3941 if the section is still mapped, or else we overwrite
3942 wrong code with the saved shadow contents. */
3943 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3944 || section_is_mapped (bl
->section
))
3945 val
= bl
->owner
->remove_location (bl
, reason
);
3951 /* No -- not inserted, so no need to remove. No error. */
3956 /* In some cases, we might not be able to remove a breakpoint in
3957 a shared library that has already been removed, but we have
3958 not yet processed the shlib unload event. Similarly for an
3959 unloaded add-symbol-file object - the user might not yet have
3960 had the chance to remove-symbol-file it. shlib_disabled will
3961 be set if the library/object has already been removed, but
3962 the breakpoint hasn't been uninserted yet, e.g., after
3963 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3964 always-inserted mode. */
3966 && (bl
->loc_type
== bp_loc_software_breakpoint
3967 && (bl
->shlib_disabled
3968 || solib_name_from_address (bl
->pspace
, bl
->address
)
3969 || shared_objfile_contains_address_p (bl
->pspace
,
3975 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3977 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3979 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3980 bl
->owner
->remove_location (bl
, reason
);
3982 /* Failure to remove any of the hardware watchpoints comes here. */
3983 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3984 warning (_("Could not remove hardware watchpoint %d."),
3987 else if (bl
->owner
->type
== bp_catchpoint
3988 && breakpoint_enabled (bl
->owner
)
3991 val
= bl
->owner
->remove_location (bl
, reason
);
3995 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
4002 remove_breakpoint (struct bp_location
*bl
)
4004 /* BL is never in moribund_locations by our callers. */
4005 gdb_assert (bl
->owner
!= NULL
);
4007 /* The type of none suggests that owner is actually deleted.
4008 This should not ever happen. */
4009 gdb_assert (bl
->owner
->type
!= bp_none
);
4011 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
4013 switch_to_program_space_and_thread (bl
->pspace
);
4015 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4018 /* Clear the "inserted" flag in all breakpoints. */
4021 mark_breakpoints_out (void)
4023 for (bp_location
*bl
: all_bp_locations ())
4024 if (bl
->pspace
== current_program_space
)
4028 /* Clear the "inserted" flag in all breakpoints and delete any
4029 breakpoints which should go away between runs of the program.
4031 Plus other such housekeeping that has to be done for breakpoints
4034 Note: this function gets called at the end of a run (by
4035 generic_mourn_inferior) and when a run begins (by
4036 init_wait_for_inferior). */
4041 breakpoint_init_inferior (enum inf_context context
)
4043 struct program_space
*pspace
= current_program_space
;
4045 /* If breakpoint locations are shared across processes, then there's
4047 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4050 mark_breakpoints_out ();
4052 for (breakpoint
*b
: all_breakpoints_safe ())
4054 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4060 case bp_longjmp_call_dummy
:
4062 /* If the call dummy breakpoint is at the entry point it will
4063 cause problems when the inferior is rerun, so we better get
4066 case bp_watchpoint_scope
:
4068 /* Also get rid of scope breakpoints. */
4070 case bp_shlib_event
:
4072 /* Also remove solib event breakpoints. Their addresses may
4073 have changed since the last time we ran the program.
4074 Actually we may now be debugging against different target;
4075 and so the solib backend that installed this breakpoint may
4076 not be used in by the target. E.g.,
4078 (gdb) file prog-linux
4079 (gdb) run # native linux target
4082 (gdb) file prog-win.exe
4083 (gdb) tar rem :9999 # remote Windows gdbserver.
4086 case bp_step_resume
:
4088 /* Also remove step-resume breakpoints. */
4090 case bp_single_step
:
4092 /* Also remove single-step breakpoints. */
4094 delete_breakpoint (b
);
4098 case bp_hardware_watchpoint
:
4099 case bp_read_watchpoint
:
4100 case bp_access_watchpoint
:
4102 struct watchpoint
*w
= (struct watchpoint
*) b
;
4104 /* Likewise for watchpoints on local expressions. */
4105 if (w
->exp_valid_block
!= NULL
)
4106 delete_breakpoint (b
);
4109 /* Get rid of existing locations, which are no longer
4110 valid. New ones will be created in
4111 update_watchpoint, when the inferior is restarted.
4112 The next update_global_location_list call will
4113 garbage collect them. */
4116 if (context
== inf_starting
)
4118 /* Reset val field to force reread of starting value in
4119 insert_breakpoints. */
4120 w
->val
.reset (nullptr);
4121 w
->val_valid
= false;
4131 /* Get rid of the moribund locations. */
4132 for (bp_location
*bl
: moribund_locations
)
4133 decref_bp_location (&bl
);
4134 moribund_locations
.clear ();
4137 /* These functions concern about actual breakpoints inserted in the
4138 target --- to e.g. check if we need to do decr_pc adjustment or if
4139 we need to hop over the bkpt --- so we check for address space
4140 match, not program space. */
4142 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4143 exists at PC. It returns ordinary_breakpoint_here if it's an
4144 ordinary breakpoint, or permanent_breakpoint_here if it's a
4145 permanent breakpoint.
4146 - When continuing from a location with an ordinary breakpoint, we
4147 actually single step once before calling insert_breakpoints.
4148 - When continuing from a location with a permanent breakpoint, we
4149 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4150 the target, to advance the PC past the breakpoint. */
4152 enum breakpoint_here
4153 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4155 int any_breakpoint_here
= 0;
4157 for (bp_location
*bl
: all_bp_locations ())
4159 if (bl
->loc_type
!= bp_loc_software_breakpoint
4160 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4163 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4164 if ((breakpoint_enabled (bl
->owner
)
4166 && breakpoint_location_address_match (bl
, aspace
, pc
))
4168 if (overlay_debugging
4169 && section_is_overlay (bl
->section
)
4170 && !section_is_mapped (bl
->section
))
4171 continue; /* unmapped overlay -- can't be a match */
4172 else if (bl
->permanent
)
4173 return permanent_breakpoint_here
;
4175 any_breakpoint_here
= 1;
4179 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4182 /* See breakpoint.h. */
4185 breakpoint_in_range_p (const address_space
*aspace
,
4186 CORE_ADDR addr
, ULONGEST len
)
4188 for (bp_location
*bl
: all_bp_locations ())
4190 if (bl
->loc_type
!= bp_loc_software_breakpoint
4191 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4194 if ((breakpoint_enabled (bl
->owner
)
4196 && breakpoint_location_address_range_overlap (bl
, aspace
,
4199 if (overlay_debugging
4200 && section_is_overlay (bl
->section
)
4201 && !section_is_mapped (bl
->section
))
4203 /* Unmapped overlay -- can't be a match. */
4214 /* Return true if there's a moribund breakpoint at PC. */
4217 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4219 for (bp_location
*loc
: moribund_locations
)
4220 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4226 /* Returns non-zero iff BL is inserted at PC, in address space
4230 bp_location_inserted_here_p (struct bp_location
*bl
,
4231 const address_space
*aspace
, CORE_ADDR pc
)
4234 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4237 if (overlay_debugging
4238 && section_is_overlay (bl
->section
)
4239 && !section_is_mapped (bl
->section
))
4240 return 0; /* unmapped overlay -- can't be a match */
4247 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4250 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4252 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4254 if (bl
->loc_type
!= bp_loc_software_breakpoint
4255 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4258 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4264 /* This function returns non-zero iff there is a software breakpoint
4268 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4271 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4273 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4276 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4283 /* See breakpoint.h. */
4286 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4289 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4291 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4294 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4302 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4303 CORE_ADDR addr
, ULONGEST len
)
4305 for (breakpoint
*bpt
: all_breakpoints ())
4307 if (bpt
->type
!= bp_hardware_watchpoint
4308 && bpt
->type
!= bp_access_watchpoint
)
4311 if (!breakpoint_enabled (bpt
))
4314 for (bp_location
*loc
: bpt
->locations ())
4315 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4319 /* Check for intersection. */
4320 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4321 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4329 /* See breakpoint.h. */
4332 is_catchpoint (struct breakpoint
*b
)
4334 return (b
->type
== bp_catchpoint
);
4337 /* Clear a bpstat so that it says we are not at any breakpoint.
4338 Also free any storage that is part of a bpstat. */
4341 bpstat_clear (bpstat
**bsp
)
4358 bpstat::bpstat (const bpstat
&other
)
4360 bp_location_at (other
.bp_location_at
),
4361 breakpoint_at (other
.breakpoint_at
),
4362 commands (other
.commands
),
4363 print (other
.print
),
4365 print_it (other
.print_it
)
4367 if (other
.old_val
!= NULL
)
4368 old_val
= release_value (value_copy (other
.old_val
.get ()));
4371 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4372 is part of the bpstat is copied as well. */
4375 bpstat_copy (bpstat
*bs
)
4377 bpstat
*p
= nullptr;
4379 bpstat
*retval
= nullptr;
4384 for (; bs
!= NULL
; bs
= bs
->next
)
4386 tmp
= new bpstat (*bs
);
4389 /* This is the first thing in the chain. */
4399 /* Find the bpstat associated with this breakpoint. */
4402 bpstat_find_breakpoint (bpstat
*bsp
, struct breakpoint
*breakpoint
)
4407 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4409 if (bsp
->breakpoint_at
== breakpoint
)
4415 /* See breakpoint.h. */
4418 bpstat_explains_signal (bpstat
*bsp
, enum gdb_signal sig
)
4420 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4422 if (bsp
->breakpoint_at
== NULL
)
4424 /* A moribund location can never explain a signal other than
4426 if (sig
== GDB_SIGNAL_TRAP
)
4431 if (bsp
->breakpoint_at
->explains_signal (sig
))
4439 /* Put in *NUM the breakpoint number of the first breakpoint we are
4440 stopped at. *BSP upon return is a bpstat which points to the
4441 remaining breakpoints stopped at (but which is not guaranteed to be
4442 good for anything but further calls to bpstat_num).
4444 Return 0 if passed a bpstat which does not indicate any breakpoints.
4445 Return -1 if stopped at a breakpoint that has been deleted since
4447 Return 1 otherwise. */
4450 bpstat_num (bpstat
**bsp
, int *num
)
4452 struct breakpoint
*b
;
4455 return 0; /* No more breakpoint values */
4457 /* We assume we'll never have several bpstats that correspond to a
4458 single breakpoint -- otherwise, this function might return the
4459 same number more than once and this will look ugly. */
4460 b
= (*bsp
)->breakpoint_at
;
4461 *bsp
= (*bsp
)->next
;
4463 return -1; /* breakpoint that's been deleted since */
4465 *num
= b
->number
; /* We have its number */
4469 /* See breakpoint.h. */
4472 bpstat_clear_actions (void)
4476 if (inferior_ptid
== null_ptid
)
4479 thread_info
*tp
= inferior_thread ();
4480 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4482 bs
->commands
= NULL
;
4483 bs
->old_val
.reset (nullptr);
4487 /* Called when a command is about to proceed the inferior. */
4490 breakpoint_about_to_proceed (void)
4492 if (inferior_ptid
!= null_ptid
)
4494 struct thread_info
*tp
= inferior_thread ();
4496 /* Allow inferior function calls in breakpoint commands to not
4497 interrupt the command list. When the call finishes
4498 successfully, the inferior will be standing at the same
4499 breakpoint as if nothing happened. */
4500 if (tp
->control
.in_infcall
)
4504 breakpoint_proceeded
= 1;
4507 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4508 or its equivalent. */
4511 command_line_is_silent (struct command_line
*cmd
)
4513 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4516 /* Execute all the commands associated with all the breakpoints at
4517 this location. Any of these commands could cause the process to
4518 proceed beyond this point, etc. We look out for such changes by
4519 checking the global "breakpoint_proceeded" after each command.
4521 Returns true if a breakpoint command resumed the inferior. In that
4522 case, it is the caller's responsibility to recall it again with the
4523 bpstat of the current thread. */
4526 bpstat_do_actions_1 (bpstat
**bsp
)
4531 /* Avoid endless recursion if a `source' command is contained
4533 if (executing_breakpoint_commands
)
4536 scoped_restore save_executing
4537 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4539 scoped_restore preventer
= prevent_dont_repeat ();
4541 /* This pointer will iterate over the list of bpstat's. */
4544 breakpoint_proceeded
= 0;
4545 for (; bs
!= NULL
; bs
= bs
->next
)
4547 struct command_line
*cmd
= NULL
;
4549 /* Take ownership of the BSP's command tree, if it has one.
4551 The command tree could legitimately contain commands like
4552 'step' and 'next', which call clear_proceed_status, which
4553 frees stop_bpstat's command tree. To make sure this doesn't
4554 free the tree we're executing out from under us, we need to
4555 take ownership of the tree ourselves. Since a given bpstat's
4556 commands are only executed once, we don't need to copy it; we
4557 can clear the pointer in the bpstat, and make sure we free
4558 the tree when we're done. */
4559 counted_command_line ccmd
= bs
->commands
;
4560 bs
->commands
= NULL
;
4563 if (command_line_is_silent (cmd
))
4565 /* The action has been already done by bpstat_stop_status. */
4571 execute_control_command (cmd
);
4573 if (breakpoint_proceeded
)
4579 if (breakpoint_proceeded
)
4581 if (current_ui
->async
)
4582 /* If we are in async mode, then the target might be still
4583 running, not stopped at any breakpoint, so nothing for
4584 us to do here -- just return to the event loop. */
4587 /* In sync mode, when execute_control_command returns
4588 we're already standing on the next breakpoint.
4589 Breakpoint commands for that stop were not run, since
4590 execute_command does not run breakpoint commands --
4591 only command_line_handler does, but that one is not
4592 involved in execution of breakpoint commands. So, we
4593 can now execute breakpoint commands. It should be
4594 noted that making execute_command do bpstat actions is
4595 not an option -- in this case we'll have recursive
4596 invocation of bpstat for each breakpoint with a
4597 command, and can easily blow up GDB stack. Instead, we
4598 return true, which will trigger the caller to recall us
4599 with the new stop_bpstat. */
4607 /* Helper for bpstat_do_actions. Get the current thread, if there's
4608 one, is alive and has execution. Return NULL otherwise. */
4610 static thread_info
*
4611 get_bpstat_thread ()
4613 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4616 thread_info
*tp
= inferior_thread ();
4617 if (tp
->state
== THREAD_EXITED
|| tp
->executing ())
4623 bpstat_do_actions (void)
4625 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4628 /* Do any commands attached to breakpoint we are stopped at. */
4629 while ((tp
= get_bpstat_thread ()) != NULL
)
4631 /* Since in sync mode, bpstat_do_actions may resume the
4632 inferior, and only return when it is stopped at the next
4633 breakpoint, we keep doing breakpoint actions until it returns
4634 false to indicate the inferior was not resumed. */
4635 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4639 cleanup_if_error
.release ();
4642 /* Print out the (old or new) value associated with a watchpoint. */
4645 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4648 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4651 struct value_print_options opts
;
4652 get_user_print_options (&opts
);
4653 value_print (val
, stream
, &opts
);
4657 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4658 debugging multiple threads. */
4661 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4663 if (uiout
->is_mi_like_p ())
4668 if (show_thread_that_caused_stop ())
4670 struct thread_info
*thr
= inferior_thread ();
4672 uiout
->text ("Thread ");
4673 uiout
->field_string ("thread-id", print_thread_id (thr
));
4675 const char *name
= thread_name (thr
);
4678 uiout
->text (" \"");
4679 uiout
->field_string ("name", name
);
4683 uiout
->text (" hit ");
4687 /* Generic routine for printing messages indicating why we
4688 stopped. The behavior of this function depends on the value
4689 'print_it' in the bpstat structure. Under some circumstances we
4690 may decide not to print anything here and delegate the task to
4693 static enum print_stop_action
4694 print_bp_stop_message (bpstat
*bs
)
4696 switch (bs
->print_it
)
4699 /* Nothing should be printed for this bpstat entry. */
4700 return PRINT_UNKNOWN
;
4704 /* We still want to print the frame, but we already printed the
4705 relevant messages. */
4706 return PRINT_SRC_AND_LOC
;
4709 case print_it_normal
:
4711 struct breakpoint
*b
= bs
->breakpoint_at
;
4713 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4714 which has since been deleted. */
4716 return PRINT_UNKNOWN
;
4718 /* Normal case. Call the breakpoint's print_it method. */
4719 return b
->print_it (bs
);
4724 internal_error (__FILE__
, __LINE__
,
4725 _("print_bp_stop_message: unrecognized enum value"));
4730 /* See breakpoint.h. */
4733 print_solib_event (bool is_catchpoint
)
4735 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4736 bool any_added
= !current_program_space
->added_solibs
.empty ();
4740 if (any_added
|| any_deleted
)
4741 current_uiout
->text (_("Stopped due to shared library event:\n"));
4743 current_uiout
->text (_("Stopped due to shared library event (no "
4744 "libraries added or removed)\n"));
4747 if (current_uiout
->is_mi_like_p ())
4748 current_uiout
->field_string ("reason",
4749 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4753 current_uiout
->text (_(" Inferior unloaded "));
4754 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4755 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4757 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4760 current_uiout
->text (" ");
4761 current_uiout
->field_string ("library", name
);
4762 current_uiout
->text ("\n");
4768 current_uiout
->text (_(" Inferior loaded "));
4769 ui_out_emit_list
list_emitter (current_uiout
, "added");
4771 for (so_list
*iter
: current_program_space
->added_solibs
)
4774 current_uiout
->text (" ");
4776 current_uiout
->field_string ("library", iter
->so_name
);
4777 current_uiout
->text ("\n");
4782 /* Print a message indicating what happened. This is called from
4783 normal_stop(). The input to this routine is the head of the bpstat
4784 list - a list of the eventpoints that caused this stop. KIND is
4785 the target_waitkind for the stopping event. This
4786 routine calls the generic print routine for printing a message
4787 about reasons for stopping. This will print (for example) the
4788 "Breakpoint n," part of the output. The return value of this
4791 PRINT_UNKNOWN: Means we printed nothing.
4792 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4793 code to print the location. An example is
4794 "Breakpoint 1, " which should be followed by
4796 PRINT_SRC_ONLY: Means we printed something, but there is no need
4797 to also print the location part of the message.
4798 An example is the catch/throw messages, which
4799 don't require a location appended to the end.
4800 PRINT_NOTHING: We have done some printing and we don't need any
4801 further info to be printed. */
4803 enum print_stop_action
4804 bpstat_print (bpstat
*bs
, int kind
)
4806 enum print_stop_action val
;
4808 /* Maybe another breakpoint in the chain caused us to stop.
4809 (Currently all watchpoints go on the bpstat whether hit or not.
4810 That probably could (should) be changed, provided care is taken
4811 with respect to bpstat_explains_signal). */
4812 for (; bs
; bs
= bs
->next
)
4814 val
= print_bp_stop_message (bs
);
4815 if (val
== PRINT_SRC_ONLY
4816 || val
== PRINT_SRC_AND_LOC
4817 || val
== PRINT_NOTHING
)
4821 /* If we had hit a shared library event breakpoint,
4822 print_bp_stop_message would print out this message. If we hit an
4823 OS-level shared library event, do the same thing. */
4824 if (kind
== TARGET_WAITKIND_LOADED
)
4826 print_solib_event (false);
4827 return PRINT_NOTHING
;
4830 /* We reached the end of the chain, or we got a null BS to start
4831 with and nothing was printed. */
4832 return PRINT_UNKNOWN
;
4835 /* Evaluate the boolean expression EXP and return the result. */
4838 breakpoint_cond_eval (expression
*exp
)
4840 struct value
*mark
= value_mark ();
4841 bool res
= value_true (evaluate_expression (exp
));
4843 value_free_to_mark (mark
);
4847 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4849 bpstat::bpstat (struct bp_location
*bl
, bpstat
***bs_link_pointer
)
4851 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4852 breakpoint_at (bl
->owner
),
4856 print_it (print_it_normal
)
4858 **bs_link_pointer
= this;
4859 *bs_link_pointer
= &next
;
4864 breakpoint_at (NULL
),
4868 print_it (print_it_normal
)
4872 /* The target has stopped with waitstatus WS. Check if any hardware
4873 watchpoints have triggered, according to the target. */
4876 watchpoints_triggered (const target_waitstatus
&ws
)
4878 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4881 if (!stopped_by_watchpoint
)
4883 /* We were not stopped by a watchpoint. Mark all watchpoints
4884 as not triggered. */
4885 for (breakpoint
*b
: all_breakpoints ())
4886 if (is_hardware_watchpoint (b
))
4888 struct watchpoint
*w
= (struct watchpoint
*) b
;
4890 w
->watchpoint_triggered
= watch_triggered_no
;
4896 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4898 /* We were stopped by a watchpoint, but we don't know where.
4899 Mark all watchpoints as unknown. */
4900 for (breakpoint
*b
: all_breakpoints ())
4901 if (is_hardware_watchpoint (b
))
4903 struct watchpoint
*w
= (struct watchpoint
*) b
;
4905 w
->watchpoint_triggered
= watch_triggered_unknown
;
4911 /* The target could report the data address. Mark watchpoints
4912 affected by this data address as triggered, and all others as not
4915 for (breakpoint
*b
: all_breakpoints ())
4916 if (is_hardware_watchpoint (b
))
4918 struct watchpoint
*w
= (struct watchpoint
*) b
;
4920 w
->watchpoint_triggered
= watch_triggered_no
;
4921 for (bp_location
*loc
: b
->locations ())
4923 if (is_masked_watchpoint (b
))
4925 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4926 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4928 if (newaddr
== start
)
4930 w
->watchpoint_triggered
= watch_triggered_yes
;
4934 /* Exact match not required. Within range is sufficient. */
4935 else if (target_watchpoint_addr_within_range
4936 (current_inferior ()->top_target (), addr
, loc
->address
,
4939 w
->watchpoint_triggered
= watch_triggered_yes
;
4948 /* Possible return values for watchpoint_check. */
4949 enum wp_check_result
4951 /* The watchpoint has been deleted. */
4954 /* The value has changed. */
4955 WP_VALUE_CHANGED
= 2,
4957 /* The value has not changed. */
4958 WP_VALUE_NOT_CHANGED
= 3,
4960 /* Ignore this watchpoint, no matter if the value changed or not. */
4964 #define BP_TEMPFLAG 1
4965 #define BP_HARDWAREFLAG 2
4967 /* Evaluate watchpoint condition expression and check if its value
4970 static wp_check_result
4971 watchpoint_check (bpstat
*bs
)
4973 struct watchpoint
*b
;
4974 struct frame_info
*fr
;
4975 int within_current_scope
;
4977 /* BS is built from an existing struct breakpoint. */
4978 gdb_assert (bs
->breakpoint_at
!= NULL
);
4979 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4981 /* If this is a local watchpoint, we only want to check if the
4982 watchpoint frame is in scope if the current thread is the thread
4983 that was used to create the watchpoint. */
4984 if (!watchpoint_in_thread_scope (b
))
4987 if (b
->exp_valid_block
== NULL
)
4988 within_current_scope
= 1;
4991 struct frame_info
*frame
= get_current_frame ();
4992 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4993 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4995 /* stack_frame_destroyed_p() returns a non-zero value if we're
4996 still in the function but the stack frame has already been
4997 invalidated. Since we can't rely on the values of local
4998 variables after the stack has been destroyed, we are treating
4999 the watchpoint in that state as `not changed' without further
5000 checking. Don't mark watchpoints as changed if the current
5001 frame is in an epilogue - even if they are in some other
5002 frame, our view of the stack is likely to be wrong and
5003 frame_find_by_id could error out. */
5004 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5007 fr
= frame_find_by_id (b
->watchpoint_frame
);
5008 within_current_scope
= (fr
!= NULL
);
5010 /* If we've gotten confused in the unwinder, we might have
5011 returned a frame that can't describe this variable. */
5012 if (within_current_scope
)
5014 struct symbol
*function
;
5016 function
= get_frame_function (fr
);
5017 if (function
== NULL
5018 || !contained_in (b
->exp_valid_block
, function
->value_block ()))
5019 within_current_scope
= 0;
5022 if (within_current_scope
)
5023 /* If we end up stopping, the current frame will get selected
5024 in normal_stop. So this call to select_frame won't affect
5029 if (within_current_scope
)
5031 /* We use value_{,free_to_}mark because it could be a *long*
5032 time before we return to the command level and call
5033 free_all_values. We can't call free_all_values because we
5034 might be in the middle of evaluating a function call. */
5037 struct value
*new_val
;
5039 if (is_masked_watchpoint (b
))
5040 /* Since we don't know the exact trigger address (from
5041 stopped_data_address), just tell the user we've triggered
5042 a mask watchpoint. */
5043 return WP_VALUE_CHANGED
;
5045 mark
= value_mark ();
5046 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5049 if (b
->val_bitsize
!= 0)
5050 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5052 /* We use value_equal_contents instead of value_equal because
5053 the latter coerces an array to a pointer, thus comparing just
5054 the address of the array instead of its contents. This is
5055 not what we want. */
5056 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5057 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5060 bs
->old_val
= b
->val
;
5061 b
->val
= release_value (new_val
);
5062 b
->val_valid
= true;
5063 if (new_val
!= NULL
)
5064 value_free_to_mark (mark
);
5065 return WP_VALUE_CHANGED
;
5069 /* Nothing changed. */
5070 value_free_to_mark (mark
);
5071 return WP_VALUE_NOT_CHANGED
;
5076 /* This seems like the only logical thing to do because
5077 if we temporarily ignored the watchpoint, then when
5078 we reenter the block in which it is valid it contains
5079 garbage (in the case of a function, it may have two
5080 garbage values, one before and one after the prologue).
5081 So we can't even detect the first assignment to it and
5082 watch after that (since the garbage may or may not equal
5083 the first value assigned). */
5084 /* We print all the stop information in
5085 breakpointprint_it, but in this case, by the time we
5086 call breakpoint->print_it this bp will be deleted
5087 already. So we have no choice but print the information
5090 SWITCH_THRU_ALL_UIS ()
5092 struct ui_out
*uiout
= current_uiout
;
5094 if (uiout
->is_mi_like_p ())
5096 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5097 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5098 "left the block in\n"
5099 "which its expression is valid.\n",
5100 signed_field ("wpnum", b
->number
));
5103 /* Make sure the watchpoint's commands aren't executed. */
5105 watchpoint_del_at_next_stop (b
);
5111 /* Return true if it looks like target has stopped due to hitting
5112 breakpoint location BL. This function does not check if we should
5113 stop, only if BL explains the stop. */
5116 bpstat_check_location (const struct bp_location
*bl
,
5117 const address_space
*aspace
, CORE_ADDR bp_addr
,
5118 const target_waitstatus
&ws
)
5120 struct breakpoint
*b
= bl
->owner
;
5122 /* BL is from an existing breakpoint. */
5123 gdb_assert (b
!= NULL
);
5125 return b
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5128 /* Determine if the watched values have actually changed, and we
5129 should stop. If not, set BS->stop to 0. */
5132 bpstat_check_watchpoint (bpstat
*bs
)
5134 const struct bp_location
*bl
;
5135 struct watchpoint
*b
;
5137 /* BS is built for existing struct breakpoint. */
5138 bl
= bs
->bp_location_at
.get ();
5139 gdb_assert (bl
!= NULL
);
5140 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5141 gdb_assert (b
!= NULL
);
5144 int must_check_value
= 0;
5146 if (b
->type
== bp_watchpoint
)
5147 /* For a software watchpoint, we must always check the
5149 must_check_value
= 1;
5150 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5151 /* We have a hardware watchpoint (read, write, or access)
5152 and the target earlier reported an address watched by
5154 must_check_value
= 1;
5155 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5156 && b
->type
== bp_hardware_watchpoint
)
5157 /* We were stopped by a hardware watchpoint, but the target could
5158 not report the data address. We must check the watchpoint's
5159 value. Access and read watchpoints are out of luck; without
5160 a data address, we can't figure it out. */
5161 must_check_value
= 1;
5163 if (must_check_value
)
5169 e
= watchpoint_check (bs
);
5171 catch (const gdb_exception
&ex
)
5173 exception_fprintf (gdb_stderr
, ex
,
5174 "Error evaluating expression "
5175 "for watchpoint %d\n",
5178 SWITCH_THRU_ALL_UIS ()
5180 gdb_printf (_("Watchpoint %d deleted.\n"),
5183 watchpoint_del_at_next_stop (b
);
5190 /* We've already printed what needs to be printed. */
5191 bs
->print_it
= print_it_done
;
5195 bs
->print_it
= print_it_noop
;
5198 case WP_VALUE_CHANGED
:
5199 if (b
->type
== bp_read_watchpoint
)
5201 /* There are two cases to consider here:
5203 1. We're watching the triggered memory for reads.
5204 In that case, trust the target, and always report
5205 the watchpoint hit to the user. Even though
5206 reads don't cause value changes, the value may
5207 have changed since the last time it was read, and
5208 since we're not trapping writes, we will not see
5209 those, and as such we should ignore our notion of
5212 2. We're watching the triggered memory for both
5213 reads and writes. There are two ways this may
5216 2.1. This is a target that can't break on data
5217 reads only, but can break on accesses (reads or
5218 writes), such as e.g., x86. We detect this case
5219 at the time we try to insert read watchpoints.
5221 2.2. Otherwise, the target supports read
5222 watchpoints, but, the user set an access or write
5223 watchpoint watching the same memory as this read
5226 If we're watching memory writes as well as reads,
5227 ignore watchpoint hits when we find that the
5228 value hasn't changed, as reads don't cause
5229 changes. This still gives false positives when
5230 the program writes the same value to memory as
5231 what there was already in memory (we will confuse
5232 it for a read), but it's much better than
5235 int other_write_watchpoint
= 0;
5237 if (bl
->watchpoint_type
== hw_read
)
5239 for (breakpoint
*other_b
: all_breakpoints ())
5240 if (other_b
->type
== bp_hardware_watchpoint
5241 || other_b
->type
== bp_access_watchpoint
)
5243 struct watchpoint
*other_w
=
5244 (struct watchpoint
*) other_b
;
5246 if (other_w
->watchpoint_triggered
5247 == watch_triggered_yes
)
5249 other_write_watchpoint
= 1;
5255 if (other_write_watchpoint
5256 || bl
->watchpoint_type
== hw_access
)
5258 /* We're watching the same memory for writes,
5259 and the value changed since the last time we
5260 updated it, so this trap must be for a write.
5262 bs
->print_it
= print_it_noop
;
5267 case WP_VALUE_NOT_CHANGED
:
5268 if (b
->type
== bp_hardware_watchpoint
5269 || b
->type
== bp_watchpoint
)
5271 /* Don't stop: write watchpoints shouldn't fire if
5272 the value hasn't changed. */
5273 bs
->print_it
= print_it_noop
;
5283 else /* must_check_value == 0 */
5285 /* This is a case where some watchpoint(s) triggered, but
5286 not at the address of this watchpoint, or else no
5287 watchpoint triggered after all. So don't print
5288 anything for this watchpoint. */
5289 bs
->print_it
= print_it_noop
;
5295 /* For breakpoints that are currently marked as telling gdb to stop,
5296 check conditions (condition proper, frame, thread and ignore count)
5297 of breakpoint referred to by BS. If we should not stop for this
5298 breakpoint, set BS->stop to 0. */
5301 bpstat_check_breakpoint_conditions (bpstat
*bs
, thread_info
*thread
)
5303 const struct bp_location
*bl
;
5304 struct breakpoint
*b
;
5306 bool condition_result
= true;
5307 struct expression
*cond
;
5309 gdb_assert (bs
->stop
);
5311 /* BS is built for existing struct breakpoint. */
5312 bl
= bs
->bp_location_at
.get ();
5313 gdb_assert (bl
!= NULL
);
5314 b
= bs
->breakpoint_at
;
5315 gdb_assert (b
!= NULL
);
5317 /* Even if the target evaluated the condition on its end and notified GDB, we
5318 need to do so again since GDB does not know if we stopped due to a
5319 breakpoint or a single step breakpoint. */
5321 if (frame_id_p (b
->frame_id
)
5322 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5328 /* If this is a thread/task-specific breakpoint, don't waste cpu
5329 evaluating the condition if this isn't the specified
5331 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5332 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5338 /* Evaluate extension language breakpoints that have a "stop" method
5340 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5342 if (is_watchpoint (b
))
5344 struct watchpoint
*w
= (struct watchpoint
*) b
;
5346 cond
= w
->cond_exp
.get ();
5349 cond
= bl
->cond
.get ();
5351 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5353 int within_current_scope
= 1;
5354 struct watchpoint
* w
;
5356 /* We use value_mark and value_free_to_mark because it could
5357 be a long time before we return to the command level and
5358 call free_all_values. We can't call free_all_values
5359 because we might be in the middle of evaluating a
5361 struct value
*mark
= value_mark ();
5363 if (is_watchpoint (b
))
5364 w
= (struct watchpoint
*) b
;
5368 /* Need to select the frame, with all that implies so that
5369 the conditions will have the right context. Because we
5370 use the frame, we will not see an inlined function's
5371 variables when we arrive at a breakpoint at the start
5372 of the inlined function; the current frame will be the
5374 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5375 select_frame (get_current_frame ());
5378 struct frame_info
*frame
;
5380 /* For local watchpoint expressions, which particular
5381 instance of a local is being watched matters, so we
5382 keep track of the frame to evaluate the expression
5383 in. To evaluate the condition however, it doesn't
5384 really matter which instantiation of the function
5385 where the condition makes sense triggers the
5386 watchpoint. This allows an expression like "watch
5387 global if q > 10" set in `func', catch writes to
5388 global on all threads that call `func', or catch
5389 writes on all recursive calls of `func' by a single
5390 thread. We simply always evaluate the condition in
5391 the innermost frame that's executing where it makes
5392 sense to evaluate the condition. It seems
5394 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5396 select_frame (frame
);
5398 within_current_scope
= 0;
5400 if (within_current_scope
)
5404 condition_result
= breakpoint_cond_eval (cond
);
5406 catch (const gdb_exception
&ex
)
5408 exception_fprintf (gdb_stderr
, ex
,
5409 "Error in testing breakpoint condition:\n");
5414 warning (_("Watchpoint condition cannot be tested "
5415 "in the current scope"));
5416 /* If we failed to set the right context for this
5417 watchpoint, unconditionally report it. */
5419 /* FIXME-someday, should give breakpoint #. */
5420 value_free_to_mark (mark
);
5423 if (cond
&& !condition_result
)
5427 else if (b
->ignore_count
> 0)
5431 /* Increase the hit count even though we don't stop. */
5433 gdb::observers::breakpoint_modified
.notify (b
);
5437 /* Returns true if we need to track moribund locations of LOC's type
5438 on the current target. */
5441 need_moribund_for_location_type (struct bp_location
*loc
)
5443 return ((loc
->loc_type
== bp_loc_software_breakpoint
5444 && !target_supports_stopped_by_sw_breakpoint ())
5445 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5446 && !target_supports_stopped_by_hw_breakpoint ()));
5449 /* See breakpoint.h. */
5452 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5453 const target_waitstatus
&ws
)
5455 bpstat
*bs_head
= nullptr, **bs_link
= &bs_head
;
5457 for (breakpoint
*b
: all_breakpoints ())
5459 if (!breakpoint_enabled (b
))
5462 for (bp_location
*bl
: b
->locations ())
5464 /* For hardware watchpoints, we look only at the first
5465 location. The watchpoint_check function will work on the
5466 entire expression, not the individual locations. For
5467 read watchpoints, the watchpoints_triggered function has
5468 checked all locations already. */
5469 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5472 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5475 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5478 /* Come here if it's a watchpoint, or if the break address
5481 bpstat
*bs
= new bpstat (bl
, &bs_link
); /* Alloc a bpstat to
5484 /* Assume we stop. Should we find a watchpoint that is not
5485 actually triggered, or if the condition of the breakpoint
5486 evaluates as false, we'll reset 'stop' to 0. */
5490 /* If this is a scope breakpoint, mark the associated
5491 watchpoint as triggered so that we will handle the
5492 out-of-scope event. We'll get to the watchpoint next
5494 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5496 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5498 w
->watchpoint_triggered
= watch_triggered_yes
;
5503 /* Check if a moribund breakpoint explains the stop. */
5504 if (!target_supports_stopped_by_sw_breakpoint ()
5505 || !target_supports_stopped_by_hw_breakpoint ())
5507 for (bp_location
*loc
: moribund_locations
)
5509 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5510 && need_moribund_for_location_type (loc
))
5512 bpstat
*bs
= new bpstat (loc
, &bs_link
);
5513 /* For hits of moribund locations, we should just proceed. */
5516 bs
->print_it
= print_it_noop
;
5524 /* See breakpoint.h. */
5527 bpstat_stop_status (const address_space
*aspace
,
5528 CORE_ADDR bp_addr
, thread_info
*thread
,
5529 const target_waitstatus
&ws
,
5532 struct breakpoint
*b
= NULL
;
5533 /* First item of allocated bpstat's. */
5534 bpstat
*bs_head
= stop_chain
;
5536 int need_remove_insert
;
5539 /* First, build the bpstat chain with locations that explain a
5540 target stop, while being careful to not set the target running,
5541 as that may invalidate locations (in particular watchpoint
5542 locations are recreated). Resuming will happen here with
5543 breakpoint conditions or watchpoint expressions that include
5544 inferior function calls. */
5545 if (bs_head
== NULL
)
5546 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5548 /* A bit of special processing for shlib breakpoints. We need to
5549 process solib loading here, so that the lists of loaded and
5550 unloaded libraries are correct before we handle "catch load" and
5552 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5554 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5556 handle_solib_event ();
5561 /* Now go through the locations that caused the target to stop, and
5562 check whether we're interested in reporting this stop to higher
5563 layers, or whether we should resume the target transparently. */
5567 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5572 b
= bs
->breakpoint_at
;
5573 b
->check_status (bs
);
5576 bpstat_check_breakpoint_conditions (bs
, thread
);
5582 /* We will stop here. */
5583 if (b
->disposition
== disp_disable
)
5585 --(b
->enable_count
);
5586 if (b
->enable_count
<= 0)
5587 b
->enable_state
= bp_disabled
;
5590 gdb::observers::breakpoint_modified
.notify (b
);
5593 bs
->commands
= b
->commands
;
5594 if (command_line_is_silent (bs
->commands
5595 ? bs
->commands
.get () : NULL
))
5598 b
->after_condition_true (bs
);
5603 /* Print nothing for this entry if we don't stop or don't
5605 if (!bs
->stop
|| !bs
->print
)
5606 bs
->print_it
= print_it_noop
;
5609 /* If we aren't stopping, the value of some hardware watchpoint may
5610 not have changed, but the intermediate memory locations we are
5611 watching may have. Don't bother if we're stopping; this will get
5613 need_remove_insert
= 0;
5614 if (! bpstat_causes_stop (bs_head
))
5615 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5617 && bs
->breakpoint_at
5618 && is_hardware_watchpoint (bs
->breakpoint_at
))
5620 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5622 update_watchpoint (w
, 0 /* don't reparse. */);
5623 need_remove_insert
= 1;
5626 if (need_remove_insert
)
5627 update_global_location_list (UGLL_MAY_INSERT
);
5628 else if (removed_any
)
5629 update_global_location_list (UGLL_DONT_INSERT
);
5634 /* See breakpoint.h. */
5637 bpstat_stop_status_nowatch (const address_space
*aspace
, CORE_ADDR bp_addr
,
5638 thread_info
*thread
, const target_waitstatus
&ws
)
5640 gdb_assert (!target_stopped_by_watchpoint ());
5642 /* Clear all watchpoints' 'watchpoint_triggered' value from a
5643 previous stop to avoid confusing bpstat_stop_status. */
5644 watchpoints_triggered (ws
);
5646 return bpstat_stop_status (aspace
, bp_addr
, thread
, ws
);
5650 handle_jit_event (CORE_ADDR address
)
5652 struct gdbarch
*gdbarch
;
5654 infrun_debug_printf ("handling bp_jit_event");
5656 /* Switch terminal for any messages produced by
5657 breakpoint_re_set. */
5658 target_terminal::ours_for_output ();
5660 gdbarch
= get_frame_arch (get_current_frame ());
5661 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5662 thus it is expected that its objectfile can be found through
5663 minimal symbol lookup. If it doesn't work (and assert fails), it
5664 most likely means that `jit_breakpoint_re_set` was changes and this
5665 function needs to be updated too. */
5666 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5667 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5668 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5670 target_terminal::inferior ();
5673 /* Prepare WHAT final decision for infrun. */
5675 /* Decide what infrun needs to do with this bpstat. */
5678 bpstat_what (bpstat
*bs_head
)
5680 struct bpstat_what retval
;
5683 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5684 retval
.call_dummy
= STOP_NONE
;
5685 retval
.is_longjmp
= false;
5687 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5689 /* Extract this BS's action. After processing each BS, we check
5690 if its action overrides all we've seem so far. */
5691 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5694 if (bs
->breakpoint_at
== NULL
)
5696 /* I suspect this can happen if it was a momentary
5697 breakpoint which has since been deleted. */
5701 bptype
= bs
->breakpoint_at
->type
;
5708 case bp_hardware_breakpoint
:
5709 case bp_single_step
:
5712 case bp_shlib_event
:
5716 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5718 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5721 this_action
= BPSTAT_WHAT_SINGLE
;
5724 case bp_hardware_watchpoint
:
5725 case bp_read_watchpoint
:
5726 case bp_access_watchpoint
:
5730 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5732 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5736 /* There was a watchpoint, but we're not stopping.
5737 This requires no further action. */
5741 case bp_longjmp_call_dummy
:
5745 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5746 retval
.is_longjmp
= bptype
!= bp_exception
;
5749 this_action
= BPSTAT_WHAT_SINGLE
;
5751 case bp_longjmp_resume
:
5752 case bp_exception_resume
:
5755 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5756 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5759 this_action
= BPSTAT_WHAT_SINGLE
;
5761 case bp_step_resume
:
5763 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5766 /* It is for the wrong frame. */
5767 this_action
= BPSTAT_WHAT_SINGLE
;
5770 case bp_hp_step_resume
:
5772 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5775 /* It is for the wrong frame. */
5776 this_action
= BPSTAT_WHAT_SINGLE
;
5779 case bp_watchpoint_scope
:
5780 case bp_thread_event
:
5781 case bp_overlay_event
:
5782 case bp_longjmp_master
:
5783 case bp_std_terminate_master
:
5784 case bp_exception_master
:
5785 this_action
= BPSTAT_WHAT_SINGLE
;
5791 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5793 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5797 /* Some catchpoints are implemented with breakpoints.
5798 For those, we need to step over the breakpoint. */
5799 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5800 this_action
= BPSTAT_WHAT_SINGLE
;
5804 this_action
= BPSTAT_WHAT_SINGLE
;
5807 /* Make sure the action is stop (silent or noisy),
5808 so infrun.c pops the dummy frame. */
5809 retval
.call_dummy
= STOP_STACK_DUMMY
;
5810 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5812 case bp_std_terminate
:
5813 /* Make sure the action is stop (silent or noisy),
5814 so infrun.c pops the dummy frame. */
5815 retval
.call_dummy
= STOP_STD_TERMINATE
;
5816 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5819 case bp_fast_tracepoint
:
5820 case bp_static_tracepoint
:
5821 case bp_static_marker_tracepoint
:
5822 /* Tracepoint hits should not be reported back to GDB, and
5823 if one got through somehow, it should have been filtered
5825 internal_error (__FILE__
, __LINE__
,
5826 _("bpstat_what: tracepoint encountered"));
5828 case bp_gnu_ifunc_resolver
:
5829 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5830 this_action
= BPSTAT_WHAT_SINGLE
;
5832 case bp_gnu_ifunc_resolver_return
:
5833 /* The breakpoint will be removed, execution will restart from the
5834 PC of the former breakpoint. */
5835 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5840 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5842 this_action
= BPSTAT_WHAT_SINGLE
;
5846 internal_error (__FILE__
, __LINE__
,
5847 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5850 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5857 bpstat_run_callbacks (bpstat
*bs_head
)
5861 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5863 struct breakpoint
*b
= bs
->breakpoint_at
;
5870 handle_jit_event (bs
->bp_location_at
->address
);
5872 case bp_gnu_ifunc_resolver
:
5873 gnu_ifunc_resolver_stop (b
);
5875 case bp_gnu_ifunc_resolver_return
:
5876 gnu_ifunc_resolver_return_stop (b
);
5882 /* See breakpoint.h. */
5885 bpstat_should_step ()
5887 for (breakpoint
*b
: all_breakpoints ())
5888 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5894 /* See breakpoint.h. */
5897 bpstat_causes_stop (bpstat
*bs
)
5899 for (; bs
!= NULL
; bs
= bs
->next
)
5908 /* Compute a number of spaces suitable to indent the next line
5909 so it starts at the position corresponding to the table column
5910 named COL_NAME in the currently active table of UIOUT. */
5913 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5915 int i
, total_width
, width
, align
;
5919 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5921 if (strcmp (text
, col_name
) == 0)
5924 total_width
+= width
+ 1;
5930 /* Determine if the locations of this breakpoint will have their conditions
5931 evaluated by the target, host or a mix of both. Returns the following:
5933 "host": Host evals condition.
5934 "host or target": Host or Target evals condition.
5935 "target": Target evals condition.
5939 bp_condition_evaluator (const breakpoint
*b
)
5941 char host_evals
= 0;
5942 char target_evals
= 0;
5947 if (!is_breakpoint (b
))
5950 if (gdb_evaluates_breakpoint_condition_p ()
5951 || !target_supports_evaluation_of_breakpoint_conditions ())
5952 return condition_evaluation_host
;
5954 for (bp_location
*bl
: b
->locations ())
5956 if (bl
->cond_bytecode
)
5962 if (host_evals
&& target_evals
)
5963 return condition_evaluation_both
;
5964 else if (target_evals
)
5965 return condition_evaluation_target
;
5967 return condition_evaluation_host
;
5970 /* Determine the breakpoint location's condition evaluator. This is
5971 similar to bp_condition_evaluator, but for locations. */
5974 bp_location_condition_evaluator (struct bp_location
*bl
)
5976 if (bl
&& !is_breakpoint (bl
->owner
))
5979 if (gdb_evaluates_breakpoint_condition_p ()
5980 || !target_supports_evaluation_of_breakpoint_conditions ())
5981 return condition_evaluation_host
;
5983 if (bl
&& bl
->cond_bytecode
)
5984 return condition_evaluation_target
;
5986 return condition_evaluation_host
;
5989 /* Print the LOC location out of the list of B->LOC locations. */
5992 print_breakpoint_location (const breakpoint
*b
,
5993 struct bp_location
*loc
)
5995 struct ui_out
*uiout
= current_uiout
;
5997 scoped_restore_current_program_space restore_pspace
;
5999 if (loc
!= NULL
&& loc
->shlib_disabled
)
6003 set_current_program_space (loc
->pspace
);
6005 if (b
->display_canonical
)
6006 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
6007 else if (loc
&& loc
->symtab
)
6009 const struct symbol
*sym
= loc
->symbol
;
6013 uiout
->text ("in ");
6014 uiout
->field_string ("func", sym
->print_name (),
6015 function_name_style
.style ());
6017 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6018 uiout
->text ("at ");
6020 uiout
->field_string ("file",
6021 symtab_to_filename_for_display (loc
->symtab
),
6022 file_name_style
.style ());
6025 if (uiout
->is_mi_like_p ())
6026 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6028 uiout
->field_signed ("line", loc
->line_number
);
6034 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6036 uiout
->field_stream ("at", stb
);
6040 uiout
->field_string ("pending",
6041 event_location_to_string (b
->location
.get ()));
6042 /* If extra_string is available, it could be holding a condition
6043 or dprintf arguments. In either case, make sure it is printed,
6044 too, but only for non-MI streams. */
6045 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6047 if (b
->type
== bp_dprintf
)
6051 uiout
->text (b
->extra_string
.get ());
6055 if (loc
&& is_breakpoint (b
)
6056 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6057 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6060 uiout
->field_string ("evaluated-by",
6061 bp_location_condition_evaluator (loc
));
6067 bptype_string (enum bptype type
)
6069 struct ep_type_description
6072 const char *description
;
6074 static struct ep_type_description bptypes
[] =
6076 {bp_none
, "?deleted?"},
6077 {bp_breakpoint
, "breakpoint"},
6078 {bp_hardware_breakpoint
, "hw breakpoint"},
6079 {bp_single_step
, "sw single-step"},
6080 {bp_until
, "until"},
6081 {bp_finish
, "finish"},
6082 {bp_watchpoint
, "watchpoint"},
6083 {bp_hardware_watchpoint
, "hw watchpoint"},
6084 {bp_read_watchpoint
, "read watchpoint"},
6085 {bp_access_watchpoint
, "acc watchpoint"},
6086 {bp_longjmp
, "longjmp"},
6087 {bp_longjmp_resume
, "longjmp resume"},
6088 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6089 {bp_exception
, "exception"},
6090 {bp_exception_resume
, "exception resume"},
6091 {bp_step_resume
, "step resume"},
6092 {bp_hp_step_resume
, "high-priority step resume"},
6093 {bp_watchpoint_scope
, "watchpoint scope"},
6094 {bp_call_dummy
, "call dummy"},
6095 {bp_std_terminate
, "std::terminate"},
6096 {bp_shlib_event
, "shlib events"},
6097 {bp_thread_event
, "thread events"},
6098 {bp_overlay_event
, "overlay events"},
6099 {bp_longjmp_master
, "longjmp master"},
6100 {bp_std_terminate_master
, "std::terminate master"},
6101 {bp_exception_master
, "exception master"},
6102 {bp_catchpoint
, "catchpoint"},
6103 {bp_tracepoint
, "tracepoint"},
6104 {bp_fast_tracepoint
, "fast tracepoint"},
6105 {bp_static_tracepoint
, "static tracepoint"},
6106 {bp_static_marker_tracepoint
, "static marker tracepoint"},
6107 {bp_dprintf
, "dprintf"},
6108 {bp_jit_event
, "jit events"},
6109 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6110 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6113 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6114 || ((int) type
!= bptypes
[(int) type
].type
))
6115 internal_error (__FILE__
, __LINE__
,
6116 _("bptypes table does not describe type #%d."),
6119 return bptypes
[(int) type
].description
;
6122 /* For MI, output a field named 'thread-groups' with a list as the value.
6123 For CLI, prefix the list with the string 'inf'. */
6126 output_thread_groups (struct ui_out
*uiout
,
6127 const char *field_name
,
6128 const std::vector
<int> &inf_nums
,
6131 int is_mi
= uiout
->is_mi_like_p ();
6133 /* For backward compatibility, don't display inferiors in CLI unless
6134 there are several. Always display them for MI. */
6135 if (!is_mi
&& mi_only
)
6138 ui_out_emit_list
list_emitter (uiout
, field_name
);
6140 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6146 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6147 uiout
->field_string (NULL
, mi_group
);
6152 uiout
->text (" inf ");
6156 uiout
->text (plongest (inf_nums
[i
]));
6161 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6162 instead of going via breakpoint_ops::print_one. This makes "maint
6163 info breakpoints" show the software breakpoint locations of
6164 catchpoints, which are considered internal implementation
6165 detail. Returns true if RAW_LOC is false and if the breakpoint's
6166 print_one method did something; false otherwise. */
6169 print_one_breakpoint_location (struct breakpoint
*b
,
6170 struct bp_location
*loc
,
6172 struct bp_location
**last_loc
,
6173 int allflag
, bool raw_loc
)
6175 struct command_line
*l
;
6176 static char bpenables
[] = "nynny";
6178 struct ui_out
*uiout
= current_uiout
;
6179 int header_of_multiple
= 0;
6180 int part_of_multiple
= (loc
!= NULL
);
6181 struct value_print_options opts
;
6183 get_user_print_options (&opts
);
6185 gdb_assert (!loc
|| loc_number
!= 0);
6186 /* See comment in print_one_breakpoint concerning treatment of
6187 breakpoints with single disabled location. */
6190 && (b
->loc
->next
!= NULL
6191 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6192 header_of_multiple
= 1;
6200 if (part_of_multiple
)
6201 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6203 uiout
->field_signed ("number", b
->number
);
6207 if (part_of_multiple
)
6208 uiout
->field_skip ("type");
6210 uiout
->field_string ("type", bptype_string (b
->type
));
6214 if (part_of_multiple
)
6215 uiout
->field_skip ("disp");
6217 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6221 /* For locations that are disabled because of an invalid condition,
6222 display "N*" on CLI, where "*" refers to a footnote below the
6223 table. For MI, simply display a "N" without a footnote. */
6224 const char *N
= (uiout
->is_mi_like_p ()) ? "N" : "N*";
6225 if (part_of_multiple
)
6226 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? N
6227 : (loc
->enabled
? "y" : "n")));
6229 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6232 bool result
= false;
6233 if (!raw_loc
&& b
->print_one (last_loc
))
6237 if (is_watchpoint (b
))
6239 struct watchpoint
*w
= (struct watchpoint
*) b
;
6241 /* Field 4, the address, is omitted (which makes the columns
6242 not line up too nicely with the headers, but the effect
6243 is relatively readable). */
6244 if (opts
.addressprint
)
6245 uiout
->field_skip ("addr");
6247 uiout
->field_string ("what", w
->exp_string
.get ());
6249 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6250 || is_ada_exception_catchpoint (b
))
6252 if (opts
.addressprint
)
6255 if (header_of_multiple
)
6256 uiout
->field_string ("addr", "<MULTIPLE>",
6257 metadata_style
.style ());
6258 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6259 uiout
->field_string ("addr", "<PENDING>",
6260 metadata_style
.style ());
6262 uiout
->field_core_addr ("addr",
6263 loc
->gdbarch
, loc
->address
);
6266 if (!header_of_multiple
)
6267 print_breakpoint_location (b
, loc
);
6273 if (loc
!= NULL
&& !header_of_multiple
)
6275 std::vector
<int> inf_nums
;
6278 for (inferior
*inf
: all_inferiors ())
6280 if (inf
->pspace
== loc
->pspace
)
6281 inf_nums
.push_back (inf
->num
);
6284 /* For backward compatibility, don't display inferiors in CLI unless
6285 there are several. Always display for MI. */
6287 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6288 && (program_spaces
.size () > 1
6289 || number_of_inferiors () > 1)
6290 /* LOC is for existing B, it cannot be in
6291 moribund_locations and thus having NULL OWNER. */
6292 && loc
->owner
->type
!= bp_catchpoint
))
6294 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6297 if (!part_of_multiple
)
6299 if (b
->thread
!= -1)
6301 /* FIXME: This seems to be redundant and lost here; see the
6302 "stop only in" line a little further down. */
6303 uiout
->text (" thread ");
6304 uiout
->field_signed ("thread", b
->thread
);
6306 else if (b
->task
!= 0)
6308 uiout
->text (" task ");
6309 uiout
->field_signed ("task", b
->task
);
6315 if (!part_of_multiple
)
6316 b
->print_one_detail (uiout
);
6318 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6321 uiout
->text ("\tstop only in stack frame at ");
6322 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6324 uiout
->field_core_addr ("frame",
6325 b
->gdbarch
, b
->frame_id
.stack_addr
);
6329 if (!part_of_multiple
&& b
->cond_string
)
6332 if (is_tracepoint (b
))
6333 uiout
->text ("\ttrace only if ");
6335 uiout
->text ("\tstop only if ");
6336 uiout
->field_string ("cond", b
->cond_string
.get ());
6338 /* Print whether the target is doing the breakpoint's condition
6339 evaluation. If GDB is doing the evaluation, don't print anything. */
6340 if (is_breakpoint (b
)
6341 && breakpoint_condition_evaluation_mode ()
6342 == condition_evaluation_target
)
6344 uiout
->message (" (%pF evals)",
6345 string_field ("evaluated-by",
6346 bp_condition_evaluator (b
)));
6351 if (!part_of_multiple
&& b
->thread
!= -1)
6353 /* FIXME should make an annotation for this. */
6354 uiout
->text ("\tstop only in thread ");
6355 if (uiout
->is_mi_like_p ())
6356 uiout
->field_signed ("thread", b
->thread
);
6359 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6361 uiout
->field_string ("thread", print_thread_id (thr
));
6366 if (!part_of_multiple
)
6370 /* FIXME should make an annotation for this. */
6371 if (is_catchpoint (b
))
6372 uiout
->text ("\tcatchpoint");
6373 else if (is_tracepoint (b
))
6374 uiout
->text ("\ttracepoint");
6376 uiout
->text ("\tbreakpoint");
6377 uiout
->text (" already hit ");
6378 uiout
->field_signed ("times", b
->hit_count
);
6379 if (b
->hit_count
== 1)
6380 uiout
->text (" time\n");
6382 uiout
->text (" times\n");
6386 /* Output the count also if it is zero, but only if this is mi. */
6387 if (uiout
->is_mi_like_p ())
6388 uiout
->field_signed ("times", b
->hit_count
);
6392 if (!part_of_multiple
&& b
->ignore_count
)
6395 uiout
->message ("\tignore next %pF hits\n",
6396 signed_field ("ignore", b
->ignore_count
));
6399 /* Note that an enable count of 1 corresponds to "enable once"
6400 behavior, which is reported by the combination of enablement and
6401 disposition, so we don't need to mention it here. */
6402 if (!part_of_multiple
&& b
->enable_count
> 1)
6405 uiout
->text ("\tdisable after ");
6406 /* Tweak the wording to clarify that ignore and enable counts
6407 are distinct, and have additive effect. */
6408 if (b
->ignore_count
)
6409 uiout
->text ("additional ");
6411 uiout
->text ("next ");
6412 uiout
->field_signed ("enable", b
->enable_count
);
6413 uiout
->text (" hits\n");
6416 if (!part_of_multiple
&& is_tracepoint (b
))
6418 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6420 if (tp
->traceframe_usage
)
6422 uiout
->text ("\ttrace buffer usage ");
6423 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6424 uiout
->text (" bytes\n");
6428 l
= b
->commands
? b
->commands
.get () : NULL
;
6429 if (!part_of_multiple
&& l
)
6432 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6433 print_command_lines (uiout
, l
, 4);
6436 if (is_tracepoint (b
))
6438 struct tracepoint
*t
= (struct tracepoint
*) b
;
6440 if (!part_of_multiple
&& t
->pass_count
)
6442 annotate_field (10);
6443 uiout
->text ("\tpass count ");
6444 uiout
->field_signed ("pass", t
->pass_count
);
6445 uiout
->text (" \n");
6448 /* Don't display it when tracepoint or tracepoint location is
6450 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6452 annotate_field (11);
6454 if (uiout
->is_mi_like_p ())
6455 uiout
->field_string ("installed",
6456 loc
->inserted
? "y" : "n");
6462 uiout
->text ("\tnot ");
6463 uiout
->text ("installed on target\n");
6468 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6470 if (is_watchpoint (b
))
6472 struct watchpoint
*w
= (struct watchpoint
*) b
;
6474 uiout
->field_string ("original-location", w
->exp_string
.get ());
6476 else if (b
->location
!= NULL
6477 && event_location_to_string (b
->location
.get ()) != NULL
)
6478 uiout
->field_string ("original-location",
6479 event_location_to_string (b
->location
.get ()));
6485 /* See breakpoint.h. */
6487 bool fix_multi_location_breakpoint_output_globally
= false;
6490 print_one_breakpoint (struct breakpoint
*b
,
6491 struct bp_location
**last_loc
,
6494 struct ui_out
*uiout
= current_uiout
;
6495 bool use_fixed_output
6496 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6497 || fix_multi_location_breakpoint_output_globally
);
6499 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6500 bool printed
= print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
6503 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6505 if (!use_fixed_output
)
6506 bkpt_tuple_emitter
.reset ();
6508 /* If this breakpoint has custom print function,
6509 it's already printed. Otherwise, print individual
6510 locations, if any. */
6511 if (!printed
|| allflag
)
6513 /* If breakpoint has a single location that is disabled, we
6514 print it as if it had several locations, since otherwise it's
6515 hard to represent "breakpoint enabled, location disabled"
6518 Note that while hardware watchpoints have several locations
6519 internally, that's not a property exposed to users.
6521 Likewise, while catchpoints may be implemented with
6522 breakpoints (e.g., catch throw), that's not a property
6523 exposed to users. We do however display the internal
6524 breakpoint locations with "maint info breakpoints". */
6525 if (!is_hardware_watchpoint (b
)
6526 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6527 || is_ada_exception_catchpoint (b
))
6529 || (b
->loc
&& (b
->loc
->next
6531 || b
->loc
->disabled_by_cond
))))
6533 gdb::optional
<ui_out_emit_list
> locations_list
;
6535 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6536 MI record. For later versions, place breakpoint locations in a
6538 if (uiout
->is_mi_like_p () && use_fixed_output
)
6539 locations_list
.emplace (uiout
, "locations");
6542 for (bp_location
*loc
: b
->locations ())
6544 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6545 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6554 breakpoint_address_bits (struct breakpoint
*b
)
6556 int print_address_bits
= 0;
6558 /* Software watchpoints that aren't watching memory don't have an
6559 address to print. */
6560 if (is_no_memory_software_watchpoint (b
))
6563 for (bp_location
*loc
: b
->locations ())
6567 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6568 if (addr_bit
> print_address_bits
)
6569 print_address_bits
= addr_bit
;
6572 return print_address_bits
;
6575 /* See breakpoint.h. */
6578 print_breakpoint (breakpoint
*b
)
6580 struct bp_location
*dummy_loc
= NULL
;
6581 print_one_breakpoint (b
, &dummy_loc
, 0);
6584 /* Return true if this breakpoint was set by the user, false if it is
6585 internal or momentary. */
6588 user_breakpoint_p (struct breakpoint
*b
)
6590 return b
->number
> 0;
6593 /* See breakpoint.h. */
6596 pending_breakpoint_p (struct breakpoint
*b
)
6598 return b
->loc
== NULL
;
6601 /* Print information on breakpoints (including watchpoints and tracepoints).
6603 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6604 understood by number_or_range_parser. Only breakpoints included in this
6605 list are then printed.
6607 If SHOW_INTERNAL is true, print internal breakpoints.
6609 If FILTER is non-NULL, call it on each breakpoint and only include the
6610 ones for which it returns true.
6612 Return the total number of breakpoints listed. */
6615 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6616 bool (*filter
) (const struct breakpoint
*))
6618 struct bp_location
*last_loc
= NULL
;
6619 int nr_printable_breakpoints
;
6620 struct value_print_options opts
;
6621 int print_address_bits
= 0;
6622 int print_type_col_width
= 14;
6623 struct ui_out
*uiout
= current_uiout
;
6624 bool has_disabled_by_cond_location
= false;
6626 get_user_print_options (&opts
);
6628 /* Compute the number of rows in the table, as well as the size
6629 required for address fields. */
6630 nr_printable_breakpoints
= 0;
6631 for (breakpoint
*b
: all_breakpoints ())
6633 /* If we have a filter, only list the breakpoints it accepts. */
6634 if (filter
&& !filter (b
))
6637 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6638 accept. Skip the others. */
6639 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6641 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6643 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6647 if (show_internal
|| user_breakpoint_p (b
))
6649 int addr_bit
, type_len
;
6651 addr_bit
= breakpoint_address_bits (b
);
6652 if (addr_bit
> print_address_bits
)
6653 print_address_bits
= addr_bit
;
6655 type_len
= strlen (bptype_string (b
->type
));
6656 if (type_len
> print_type_col_width
)
6657 print_type_col_width
= type_len
;
6659 nr_printable_breakpoints
++;
6664 ui_out_emit_table
table_emitter (uiout
,
6665 opts
.addressprint
? 6 : 5,
6666 nr_printable_breakpoints
,
6669 if (nr_printable_breakpoints
> 0)
6670 annotate_breakpoints_headers ();
6671 if (nr_printable_breakpoints
> 0)
6673 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6674 if (nr_printable_breakpoints
> 0)
6676 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6677 if (nr_printable_breakpoints
> 0)
6679 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6680 if (nr_printable_breakpoints
> 0)
6682 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6683 if (opts
.addressprint
)
6685 if (nr_printable_breakpoints
> 0)
6687 if (print_address_bits
<= 32)
6688 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6690 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6692 if (nr_printable_breakpoints
> 0)
6694 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6695 uiout
->table_body ();
6696 if (nr_printable_breakpoints
> 0)
6697 annotate_breakpoints_table ();
6699 for (breakpoint
*b
: all_breakpoints ())
6702 /* If we have a filter, only list the breakpoints it accepts. */
6703 if (filter
&& !filter (b
))
6706 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6707 accept. Skip the others. */
6709 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6711 if (show_internal
) /* maintenance info breakpoint */
6713 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6716 else /* all others */
6718 if (!number_is_in_list (bp_num_list
, b
->number
))
6722 /* We only print out user settable breakpoints unless the
6723 show_internal is set. */
6724 if (show_internal
|| user_breakpoint_p (b
))
6726 print_one_breakpoint (b
, &last_loc
, show_internal
);
6727 for (bp_location
*loc
: b
->locations ())
6728 if (loc
->disabled_by_cond
)
6729 has_disabled_by_cond_location
= true;
6734 if (nr_printable_breakpoints
== 0)
6736 /* If there's a filter, let the caller decide how to report
6740 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6741 uiout
->message ("No breakpoints or watchpoints.\n");
6743 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6749 if (last_loc
&& !server_command
)
6750 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6752 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6753 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6757 /* FIXME? Should this be moved up so that it is only called when
6758 there have been breakpoints? */
6759 annotate_breakpoints_table_end ();
6761 return nr_printable_breakpoints
;
6764 /* Display the value of default-collect in a way that is generally
6765 compatible with the breakpoint list. */
6768 default_collect_info (void)
6770 struct ui_out
*uiout
= current_uiout
;
6772 /* If it has no value (which is frequently the case), say nothing; a
6773 message like "No default-collect." gets in user's face when it's
6775 if (default_collect
.empty ())
6778 /* The following phrase lines up nicely with per-tracepoint collect
6780 uiout
->text ("default collect ");
6781 uiout
->field_string ("default-collect", default_collect
);
6782 uiout
->text (" \n");
6786 info_breakpoints_command (const char *args
, int from_tty
)
6788 breakpoint_1 (args
, false, NULL
);
6790 default_collect_info ();
6794 info_watchpoints_command (const char *args
, int from_tty
)
6796 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6797 struct ui_out
*uiout
= current_uiout
;
6799 if (num_printed
== 0)
6801 if (args
== NULL
|| *args
== '\0')
6802 uiout
->message ("No watchpoints.\n");
6804 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6809 maintenance_info_breakpoints (const char *args
, int from_tty
)
6811 breakpoint_1 (args
, true, NULL
);
6813 default_collect_info ();
6817 breakpoint_has_pc (struct breakpoint
*b
,
6818 struct program_space
*pspace
,
6819 CORE_ADDR pc
, struct obj_section
*section
)
6821 for (bp_location
*bl
: b
->locations ())
6823 if (bl
->pspace
== pspace
6824 && bl
->address
== pc
6825 && (!overlay_debugging
|| bl
->section
== section
))
6831 /* Print a message describing any user-breakpoints set at PC. This
6832 concerns with logical breakpoints, so we match program spaces, not
6836 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6837 struct program_space
*pspace
, CORE_ADDR pc
,
6838 struct obj_section
*section
, int thread
)
6842 for (breakpoint
*b
: all_breakpoints ())
6843 others
+= (user_breakpoint_p (b
)
6844 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6849 gdb_printf (_("Note: breakpoint "));
6850 else /* if (others == ???) */
6851 gdb_printf (_("Note: breakpoints "));
6852 for (breakpoint
*b
: all_breakpoints ())
6853 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6856 gdb_printf ("%d", b
->number
);
6857 if (b
->thread
== -1 && thread
!= -1)
6858 gdb_printf (" (all threads)");
6859 else if (b
->thread
!= -1)
6860 gdb_printf (" (thread %d)", b
->thread
);
6861 gdb_printf ("%s%s ",
6862 ((b
->enable_state
== bp_disabled
6863 || b
->enable_state
== bp_call_disabled
)
6867 : ((others
== 1) ? " and" : ""));
6869 current_uiout
->message (_("also set at pc %ps.\n"),
6870 styled_string (address_style
.style (),
6871 paddress (gdbarch
, pc
)));
6876 /* Return true iff it is meaningful to use the address member of LOC.
6877 For some breakpoint types, the locations' address members are
6878 irrelevant and it makes no sense to attempt to compare them to
6879 other addresses (or use them for any other purpose either).
6881 More specifically, software watchpoints and catchpoints that are
6882 not backed by breakpoints always have a zero valued location
6883 address and we don't want to mark breakpoints of any of these types
6884 to be a duplicate of an actual breakpoint location at address
6888 bl_address_is_meaningful (bp_location
*loc
)
6890 return loc
->loc_type
!= bp_loc_other
;
6893 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6894 true if LOC1 and LOC2 represent the same watchpoint location. */
6897 watchpoint_locations_match (struct bp_location
*loc1
,
6898 struct bp_location
*loc2
)
6900 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6901 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6903 /* Both of them must exist. */
6904 gdb_assert (w1
!= NULL
);
6905 gdb_assert (w2
!= NULL
);
6907 /* If the target can evaluate the condition expression in hardware,
6908 then we we need to insert both watchpoints even if they are at
6909 the same place. Otherwise the watchpoint will only trigger when
6910 the condition of whichever watchpoint was inserted evaluates to
6911 true, not giving a chance for GDB to check the condition of the
6912 other watchpoint. */
6914 && target_can_accel_watchpoint_condition (loc1
->address
,
6916 loc1
->watchpoint_type
,
6917 w1
->cond_exp
.get ()))
6919 && target_can_accel_watchpoint_condition (loc2
->address
,
6921 loc2
->watchpoint_type
,
6922 w2
->cond_exp
.get ())))
6925 /* Note that this checks the owner's type, not the location's. In
6926 case the target does not support read watchpoints, but does
6927 support access watchpoints, we'll have bp_read_watchpoint
6928 watchpoints with hw_access locations. Those should be considered
6929 duplicates of hw_read locations. The hw_read locations will
6930 become hw_access locations later. */
6931 return (loc1
->owner
->type
== loc2
->owner
->type
6932 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6933 && loc1
->address
== loc2
->address
6934 && loc1
->length
== loc2
->length
);
6937 /* See breakpoint.h. */
6940 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6941 const address_space
*aspace2
, CORE_ADDR addr2
)
6943 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6944 || aspace1
== aspace2
)
6948 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6949 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6950 matches ASPACE2. On targets that have global breakpoints, the address
6951 space doesn't really matter. */
6954 breakpoint_address_match_range (const address_space
*aspace1
,
6956 int len1
, const address_space
*aspace2
,
6959 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6960 || aspace1
== aspace2
)
6961 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6964 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6965 a ranged breakpoint. In most targets, a match happens only if ASPACE
6966 matches the breakpoint's address space. On targets that have global
6967 breakpoints, the address space doesn't really matter. */
6970 breakpoint_location_address_match (struct bp_location
*bl
,
6971 const address_space
*aspace
,
6974 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6977 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6978 bl
->address
, bl
->length
,
6982 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6983 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6984 match happens only if ASPACE matches the breakpoint's address
6985 space. On targets that have global breakpoints, the address space
6986 doesn't really matter. */
6989 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6990 const address_space
*aspace
,
6991 CORE_ADDR addr
, int len
)
6993 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6994 || bl
->pspace
->aspace
== aspace
)
6996 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6998 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7004 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7005 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7006 true, otherwise returns false. */
7009 tracepoint_locations_match (struct bp_location
*loc1
,
7010 struct bp_location
*loc2
)
7012 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7013 /* Since tracepoint locations are never duplicated with others', tracepoint
7014 locations at the same address of different tracepoints are regarded as
7015 different locations. */
7016 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7021 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7022 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
7023 the same location. If SW_HW_BPS_MATCH is true, then software
7024 breakpoint locations and hardware breakpoint locations match,
7025 otherwise they don't. */
7028 breakpoint_locations_match (struct bp_location
*loc1
,
7029 struct bp_location
*loc2
,
7030 bool sw_hw_bps_match
)
7032 int hw_point1
, hw_point2
;
7034 /* Both of them must not be in moribund_locations. */
7035 gdb_assert (loc1
->owner
!= NULL
);
7036 gdb_assert (loc2
->owner
!= NULL
);
7038 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7039 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7041 if (hw_point1
!= hw_point2
)
7044 return watchpoint_locations_match (loc1
, loc2
);
7045 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7046 return tracepoint_locations_match (loc1
, loc2
);
7048 /* We compare bp_location.length in order to cover ranged
7049 breakpoints. Keep this in sync with
7050 bp_location_is_less_than. */
7051 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7052 loc2
->pspace
->aspace
, loc2
->address
)
7053 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7054 && loc1
->length
== loc2
->length
);
7058 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7059 int bnum
, int have_bnum
)
7061 /* The longest string possibly returned by hex_string_custom
7062 is 50 chars. These must be at least that big for safety. */
7066 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7067 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7069 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7070 bnum
, astr1
, astr2
);
7072 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7075 /* Adjust a breakpoint's address to account for architectural
7076 constraints on breakpoint placement. Return the adjusted address.
7077 Note: Very few targets require this kind of adjustment. For most
7078 targets, this function is simply the identity function. */
7081 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7082 CORE_ADDR bpaddr
, enum bptype bptype
)
7084 if (bptype
== bp_watchpoint
7085 || bptype
== bp_hardware_watchpoint
7086 || bptype
== bp_read_watchpoint
7087 || bptype
== bp_access_watchpoint
7088 || bptype
== bp_catchpoint
)
7090 /* Watchpoints and the various bp_catch_* eventpoints should not
7091 have their addresses modified. */
7094 else if (bptype
== bp_single_step
)
7096 /* Single-step breakpoints should not have their addresses
7097 modified. If there's any architectural constrain that
7098 applies to this address, then it should have already been
7099 taken into account when the breakpoint was created in the
7100 first place. If we didn't do this, stepping through e.g.,
7101 Thumb-2 IT blocks would break. */
7106 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7108 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7110 /* Some targets have architectural constraints on the placement
7111 of breakpoint instructions. Obtain the adjusted address. */
7112 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7115 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7117 /* An adjusted breakpoint address can significantly alter
7118 a user's expectations. Print a warning if an adjustment
7120 if (adjusted_bpaddr
!= bpaddr
)
7121 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7123 return adjusted_bpaddr
;
7128 bp_location_from_bp_type (bptype type
)
7133 case bp_single_step
:
7137 case bp_longjmp_resume
:
7138 case bp_longjmp_call_dummy
:
7140 case bp_exception_resume
:
7141 case bp_step_resume
:
7142 case bp_hp_step_resume
:
7143 case bp_watchpoint_scope
:
7145 case bp_std_terminate
:
7146 case bp_shlib_event
:
7147 case bp_thread_event
:
7148 case bp_overlay_event
:
7150 case bp_longjmp_master
:
7151 case bp_std_terminate_master
:
7152 case bp_exception_master
:
7153 case bp_gnu_ifunc_resolver
:
7154 case bp_gnu_ifunc_resolver_return
:
7156 return bp_loc_software_breakpoint
;
7157 case bp_hardware_breakpoint
:
7158 return bp_loc_hardware_breakpoint
;
7159 case bp_hardware_watchpoint
:
7160 case bp_read_watchpoint
:
7161 case bp_access_watchpoint
:
7162 return bp_loc_hardware_watchpoint
;
7166 case bp_fast_tracepoint
:
7167 case bp_static_tracepoint
:
7168 case bp_static_marker_tracepoint
:
7169 return bp_loc_other
;
7171 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7175 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7177 this->owner
= owner
;
7178 this->cond_bytecode
= NULL
;
7179 this->shlib_disabled
= 0;
7181 this->disabled_by_cond
= false;
7183 this->loc_type
= type
;
7185 if (this->loc_type
== bp_loc_software_breakpoint
7186 || this->loc_type
== bp_loc_hardware_breakpoint
)
7187 mark_breakpoint_location_modified (this);
7192 bp_location::bp_location (breakpoint
*owner
)
7193 : bp_location::bp_location (owner
,
7194 bp_location_from_bp_type (owner
->type
))
7198 /* Decrement reference count. If the reference count reaches 0,
7199 destroy the bp_location. Sets *BLP to NULL. */
7202 decref_bp_location (struct bp_location
**blp
)
7204 bp_location_ref_policy::decref (*blp
);
7208 /* Add breakpoint B at the end of the global breakpoint chain. */
7211 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7213 struct breakpoint
*b1
;
7214 struct breakpoint
*result
= b
.get ();
7216 /* Add this breakpoint to the end of the chain so that a list of
7217 breakpoints will come out in order of increasing numbers. */
7219 b1
= breakpoint_chain
;
7221 breakpoint_chain
= b
.release ();
7226 b1
->next
= b
.release ();
7232 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7233 that has type BPTYPE and has no locations as yet. */
7235 static struct breakpoint
*
7236 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7239 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (gdbarch
, bptype
);
7241 return add_to_breakpoint_chain (std::move (b
));
7244 /* Initialize loc->function_name. */
7247 set_breakpoint_location_function (struct bp_location
*loc
)
7249 gdb_assert (loc
->owner
!= NULL
);
7251 if (loc
->owner
->type
== bp_breakpoint
7252 || loc
->owner
->type
== bp_hardware_breakpoint
7253 || is_tracepoint (loc
->owner
))
7255 const char *function_name
;
7257 if (loc
->msymbol
!= NULL
7258 && (loc
->msymbol
->type () == mst_text_gnu_ifunc
7259 || loc
->msymbol
->type () == mst_data_gnu_ifunc
))
7261 struct breakpoint
*b
= loc
->owner
;
7263 function_name
= loc
->msymbol
->linkage_name ();
7265 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7266 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7268 /* Create only the whole new breakpoint of this type but do not
7269 mess more complicated breakpoints with multiple locations. */
7270 b
->type
= bp_gnu_ifunc_resolver
;
7271 /* Remember the resolver's address for use by the return
7273 loc
->related_address
= loc
->address
;
7277 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7280 loc
->function_name
= make_unique_xstrdup (function_name
);
7284 /* Attempt to determine architecture of location identified by SAL. */
7286 get_sal_arch (struct symtab_and_line sal
)
7289 return sal
.section
->objfile
->arch ();
7291 return sal
.symtab
->compunit ()->objfile ()->arch ();
7296 /* Low level routine for partially initializing a breakpoint of type
7297 BPTYPE. The newly created breakpoint's address, section, source
7298 file name, and line number are provided by SAL.
7300 It is expected that the caller will complete the initialization of
7301 the newly created breakpoint struct as well as output any status
7302 information regarding the creation of a new breakpoint. */
7305 init_raw_breakpoint (struct breakpoint
*b
, struct symtab_and_line sal
,
7308 b
->add_location (sal
);
7310 if (bptype
!= bp_catchpoint
)
7311 gdb_assert (sal
.pspace
!= NULL
);
7313 /* Store the program space that was used to set the breakpoint,
7314 except for ordinary breakpoints, which are independent of the
7316 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7317 b
->pspace
= sal
.pspace
;
7320 /* set_raw_breakpoint is a low level routine for allocating and
7321 partially initializing a breakpoint of type BPTYPE. The newly
7322 created breakpoint's address, section, source file name, and line
7323 number are provided by SAL. The newly created and partially
7324 initialized breakpoint is added to the breakpoint chain and
7325 is also returned as the value of this function.
7327 It is expected that the caller will complete the initialization of
7328 the newly created breakpoint struct as well as output any status
7329 information regarding the creation of a new breakpoint. In
7330 particular, set_raw_breakpoint does NOT set the breakpoint
7331 number! Care should be taken to not allow an error to occur
7332 prior to completing the initialization of the breakpoint. If this
7333 should happen, a bogus breakpoint will be left on the chain. */
7335 static struct breakpoint
*
7336 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7337 struct symtab_and_line sal
, enum bptype bptype
)
7339 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (gdbarch
, bptype
);
7341 init_raw_breakpoint (b
.get (), sal
, bptype
);
7342 return add_to_breakpoint_chain (std::move (b
));
7345 /* Call this routine when stepping and nexting to enable a breakpoint
7346 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7347 initiated the operation. */
7350 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7352 int thread
= tp
->global_num
;
7354 /* To avoid having to rescan all objfile symbols at every step,
7355 we maintain a list of continually-inserted but always disabled
7356 longjmp "master" breakpoints. Here, we simply create momentary
7357 clones of those and enable them for the requested thread. */
7358 for (breakpoint
*b
: all_breakpoints_safe ())
7359 if (b
->pspace
== current_program_space
7360 && (b
->type
== bp_longjmp_master
7361 || b
->type
== bp_exception_master
))
7363 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7364 struct breakpoint
*clone
;
7366 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7367 after their removal. */
7368 clone
= momentary_breakpoint_from_master (b
, type
, 1);
7369 clone
->thread
= thread
;
7372 tp
->initiating_frame
= frame
;
7375 /* Delete all longjmp breakpoints from THREAD. */
7377 delete_longjmp_breakpoint (int thread
)
7379 for (breakpoint
*b
: all_breakpoints_safe ())
7380 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7382 if (b
->thread
== thread
)
7383 delete_breakpoint (b
);
7388 delete_longjmp_breakpoint_at_next_stop (int thread
)
7390 for (breakpoint
*b
: all_breakpoints_safe ())
7391 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7393 if (b
->thread
== thread
)
7394 b
->disposition
= disp_del_at_next_stop
;
7398 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7399 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7400 pointer to any of them. Return NULL if this system cannot place longjmp
7404 set_longjmp_breakpoint_for_call_dummy (void)
7406 breakpoint
*retval
= nullptr;
7408 for (breakpoint
*b
: all_breakpoints ())
7409 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7411 struct breakpoint
*new_b
;
7413 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7415 new_b
->thread
= inferior_thread ()->global_num
;
7417 /* Link NEW_B into the chain of RETVAL breakpoints. */
7419 gdb_assert (new_b
->related_breakpoint
== new_b
);
7422 new_b
->related_breakpoint
= retval
;
7423 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7424 retval
= retval
->related_breakpoint
;
7425 retval
->related_breakpoint
= new_b
;
7431 /* Verify all existing dummy frames and their associated breakpoints for
7432 TP. Remove those which can no longer be found in the current frame
7435 If the unwind fails then there is not sufficient information to discard
7436 dummy frames. In this case, elide the clean up and the dummy frames will
7437 be cleaned up next time this function is called from a location where
7438 unwinding is possible. */
7441 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7443 struct breakpoint
*b
, *b_tmp
;
7445 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7446 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7448 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7450 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7451 chained off b->related_breakpoint. */
7452 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7453 dummy_b
= dummy_b
->related_breakpoint
;
7455 /* If there was no bp_call_dummy breakpoint then there's nothing
7456 more to do. Or, if the dummy frame associated with the
7457 bp_call_dummy is still on the stack then we need to leave this
7458 bp_call_dummy in place. */
7459 if (dummy_b
->type
!= bp_call_dummy
7460 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7463 /* We didn't find the dummy frame on the stack, this could be
7464 because we have longjmp'd to a stack frame that is previous to
7465 the dummy frame, or it could be because the stack unwind is
7466 broken at some point between the longjmp frame and the dummy
7469 Next we figure out why the stack unwind stopped. If it looks
7470 like the unwind is complete then we assume the dummy frame has
7471 been jumped over, however, if the unwind stopped for an
7472 unexpected reason then we assume the stack unwind is currently
7473 broken, and that we will (eventually) return to the dummy
7476 It might be tempting to consider using frame_id_inner here, but
7477 that is not safe. There is no guarantee that the stack frames
7478 we are looking at here are even on the same stack as the
7479 original dummy frame, hence frame_id_inner can't be used. See
7480 the comments on frame_id_inner for more details. */
7481 bool unwind_finished_unexpectedly
= false;
7482 for (struct frame_info
*fi
= get_current_frame (); fi
!= nullptr; )
7484 struct frame_info
*prev
= get_prev_frame (fi
);
7485 if (prev
== nullptr)
7487 /* FI is the last stack frame. Why did this frame not
7489 auto stop_reason
= get_frame_unwind_stop_reason (fi
);
7490 if (stop_reason
!= UNWIND_NO_REASON
7491 && stop_reason
!= UNWIND_OUTERMOST
)
7492 unwind_finished_unexpectedly
= true;
7496 if (unwind_finished_unexpectedly
)
7499 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7501 while (b
->related_breakpoint
!= b
)
7503 if (b_tmp
== b
->related_breakpoint
)
7504 b_tmp
= b
->related_breakpoint
->next
;
7505 delete_breakpoint (b
->related_breakpoint
);
7507 delete_breakpoint (b
);
7512 enable_overlay_breakpoints (void)
7514 for (breakpoint
*b
: all_breakpoints ())
7515 if (b
->type
== bp_overlay_event
)
7517 b
->enable_state
= bp_enabled
;
7518 update_global_location_list (UGLL_MAY_INSERT
);
7519 overlay_events_enabled
= 1;
7524 disable_overlay_breakpoints (void)
7526 for (breakpoint
*b
: all_breakpoints ())
7527 if (b
->type
== bp_overlay_event
)
7529 b
->enable_state
= bp_disabled
;
7530 update_global_location_list (UGLL_DONT_INSERT
);
7531 overlay_events_enabled
= 0;
7535 /* Set an active std::terminate breakpoint for each std::terminate
7536 master breakpoint. */
7538 set_std_terminate_breakpoint (void)
7540 for (breakpoint
*b
: all_breakpoints_safe ())
7541 if (b
->pspace
== current_program_space
7542 && b
->type
== bp_std_terminate_master
)
7544 momentary_breakpoint_from_master (b
, bp_std_terminate
, 1);
7548 /* Delete all the std::terminate breakpoints. */
7550 delete_std_terminate_breakpoint (void)
7552 for (breakpoint
*b
: all_breakpoints_safe ())
7553 if (b
->type
== bp_std_terminate
)
7554 delete_breakpoint (b
);
7558 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7560 struct breakpoint
*b
;
7562 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
7564 b
->enable_state
= bp_enabled
;
7565 /* location has to be used or breakpoint_re_set will delete me. */
7566 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7568 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7573 struct lang_and_radix
7579 /* Create a breakpoint for JIT code registration and unregistration. */
7582 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7584 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
7587 /* Remove JIT code registration and unregistration breakpoint(s). */
7590 remove_jit_event_breakpoints (void)
7592 for (breakpoint
*b
: all_breakpoints_safe ())
7593 if (b
->type
== bp_jit_event
7594 && b
->loc
->pspace
== current_program_space
)
7595 delete_breakpoint (b
);
7599 remove_solib_event_breakpoints (void)
7601 for (breakpoint
*b
: all_breakpoints_safe ())
7602 if (b
->type
== bp_shlib_event
7603 && b
->loc
->pspace
== current_program_space
)
7604 delete_breakpoint (b
);
7607 /* See breakpoint.h. */
7610 remove_solib_event_breakpoints_at_next_stop (void)
7612 for (breakpoint
*b
: all_breakpoints_safe ())
7613 if (b
->type
== bp_shlib_event
7614 && b
->loc
->pspace
== current_program_space
)
7615 b
->disposition
= disp_del_at_next_stop
;
7618 /* Helper for create_solib_event_breakpoint /
7619 create_and_insert_solib_event_breakpoint. Allows specifying which
7620 INSERT_MODE to pass through to update_global_location_list. */
7622 static struct breakpoint
*
7623 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7624 enum ugll_insert_mode insert_mode
)
7626 struct breakpoint
*b
;
7628 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
7629 update_global_location_list_nothrow (insert_mode
);
7634 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7636 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7639 /* See breakpoint.h. */
7642 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7644 struct breakpoint
*b
;
7646 /* Explicitly tell update_global_location_list to insert
7648 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7649 if (!b
->loc
->inserted
)
7651 delete_breakpoint (b
);
7657 /* Disable any breakpoints that are on code in shared libraries. Only
7658 apply to enabled breakpoints, disabled ones can just stay disabled. */
7661 disable_breakpoints_in_shlibs (void)
7663 for (bp_location
*loc
: all_bp_locations ())
7665 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7666 struct breakpoint
*b
= loc
->owner
;
7668 /* We apply the check to all breakpoints, including disabled for
7669 those with loc->duplicate set. This is so that when breakpoint
7670 becomes enabled, or the duplicate is removed, gdb will try to
7671 insert all breakpoints. If we don't set shlib_disabled here,
7672 we'll try to insert those breakpoints and fail. */
7673 if (((b
->type
== bp_breakpoint
)
7674 || (b
->type
== bp_jit_event
)
7675 || (b
->type
== bp_hardware_breakpoint
)
7676 || (is_tracepoint (b
)))
7677 && loc
->pspace
== current_program_space
7678 && !loc
->shlib_disabled
7679 && solib_name_from_address (loc
->pspace
, loc
->address
)
7682 loc
->shlib_disabled
= 1;
7687 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7688 notification of unloaded_shlib. Only apply to enabled breakpoints,
7689 disabled ones can just stay disabled. */
7692 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7694 int disabled_shlib_breaks
= 0;
7696 for (bp_location
*loc
: all_bp_locations ())
7698 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7699 struct breakpoint
*b
= loc
->owner
;
7701 if (solib
->pspace
== loc
->pspace
7702 && !loc
->shlib_disabled
7703 && (((b
->type
== bp_breakpoint
7704 || b
->type
== bp_jit_event
7705 || b
->type
== bp_hardware_breakpoint
)
7706 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7707 || loc
->loc_type
== bp_loc_software_breakpoint
))
7708 || is_tracepoint (b
))
7709 && solib_contains_address_p (solib
, loc
->address
))
7711 loc
->shlib_disabled
= 1;
7712 /* At this point, we cannot rely on remove_breakpoint
7713 succeeding so we must mark the breakpoint as not inserted
7714 to prevent future errors occurring in remove_breakpoints. */
7717 /* This may cause duplicate notifications for the same breakpoint. */
7718 gdb::observers::breakpoint_modified
.notify (b
);
7720 if (!disabled_shlib_breaks
)
7722 target_terminal::ours_for_output ();
7723 warning (_("Temporarily disabling breakpoints "
7724 "for unloaded shared library \"%s\""),
7727 disabled_shlib_breaks
= 1;
7732 /* Disable any breakpoints and tracepoints in OBJFILE upon
7733 notification of free_objfile. Only apply to enabled breakpoints,
7734 disabled ones can just stay disabled. */
7737 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7739 if (objfile
== NULL
)
7742 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7743 managed by the user with add-symbol-file/remove-symbol-file.
7744 Similarly to how breakpoints in shared libraries are handled in
7745 response to "nosharedlibrary", mark breakpoints in such modules
7746 shlib_disabled so they end up uninserted on the next global
7747 location list update. Shared libraries not loaded by the user
7748 aren't handled here -- they're already handled in
7749 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7750 solib_unloaded observer. We skip objfiles that are not
7751 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7753 if ((objfile
->flags
& OBJF_SHARED
) == 0
7754 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7757 for (breakpoint
*b
: all_breakpoints ())
7759 int bp_modified
= 0;
7761 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7764 for (bp_location
*loc
: b
->locations ())
7766 CORE_ADDR loc_addr
= loc
->address
;
7768 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7769 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7772 if (loc
->shlib_disabled
!= 0)
7775 if (objfile
->pspace
!= loc
->pspace
)
7778 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7779 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7782 if (is_addr_in_objfile (loc_addr
, objfile
))
7784 loc
->shlib_disabled
= 1;
7785 /* At this point, we don't know whether the object was
7786 unmapped from the inferior or not, so leave the
7787 inserted flag alone. We'll handle failure to
7788 uninsert quietly, in case the object was indeed
7791 mark_breakpoint_location_modified (loc
);
7798 gdb::observers::breakpoint_modified
.notify (b
);
7802 /* See breakpoint.h. */
7804 catchpoint::catchpoint (struct gdbarch
*gdbarch
, bool temp
,
7805 const char *cond_string_
)
7806 : base_breakpoint (gdbarch
, bp_catchpoint
)
7808 symtab_and_line sal
;
7809 sal
.pspace
= current_program_space
;
7811 init_raw_breakpoint (this, sal
, bp_catchpoint
);
7813 if (cond_string_
!= nullptr)
7814 cond_string
= make_unique_xstrdup (cond_string_
);
7815 disposition
= temp
? disp_del
: disp_donttouch
;
7819 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
7821 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
7822 set_breakpoint_number (internal
, b
);
7823 if (is_tracepoint (b
))
7824 set_tracepoint_count (breakpoint_count
);
7827 gdb::observers::breakpoint_created
.notify (b
);
7830 update_global_location_list (UGLL_MAY_INSERT
);
7834 hw_breakpoint_used_count (void)
7838 for (breakpoint
*b
: all_breakpoints ())
7839 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
7840 for (bp_location
*bl
: b
->locations ())
7842 /* Special types of hardware breakpoints may use more than
7844 i
+= b
->resources_needed (bl
);
7850 /* Returns the resources B would use if it were a hardware
7854 hw_watchpoint_use_count (struct breakpoint
*b
)
7858 if (!breakpoint_enabled (b
))
7861 for (bp_location
*bl
: b
->locations ())
7863 /* Special types of hardware watchpoints may use more than
7865 i
+= b
->resources_needed (bl
);
7871 /* Returns the sum the used resources of all hardware watchpoints of
7872 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
7873 the sum of the used resources of all hardware watchpoints of other
7874 types _not_ TYPE. */
7877 hw_watchpoint_used_count_others (struct breakpoint
*except
,
7878 enum bptype type
, int *other_type_used
)
7882 *other_type_used
= 0;
7883 for (breakpoint
*b
: all_breakpoints ())
7887 if (!breakpoint_enabled (b
))
7890 if (b
->type
== type
)
7891 i
+= hw_watchpoint_use_count (b
);
7892 else if (is_hardware_watchpoint (b
))
7893 *other_type_used
= 1;
7900 disable_watchpoints_before_interactive_call_start (void)
7902 for (breakpoint
*b
: all_breakpoints ())
7903 if (is_watchpoint (b
) && breakpoint_enabled (b
))
7905 b
->enable_state
= bp_call_disabled
;
7906 update_global_location_list (UGLL_DONT_INSERT
);
7911 enable_watchpoints_after_interactive_call_stop (void)
7913 for (breakpoint
*b
: all_breakpoints ())
7914 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
7916 b
->enable_state
= bp_enabled
;
7917 update_global_location_list (UGLL_MAY_INSERT
);
7922 disable_breakpoints_before_startup (void)
7924 current_program_space
->executing_startup
= 1;
7925 update_global_location_list (UGLL_DONT_INSERT
);
7929 enable_breakpoints_after_startup (void)
7931 current_program_space
->executing_startup
= 0;
7932 breakpoint_re_set ();
7935 /* Create a new single-step breakpoint for thread THREAD, with no
7938 static struct breakpoint
*
7939 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
7941 std::unique_ptr
<breakpoint
> b (new momentary_breakpoint (gdbarch
,
7944 b
->disposition
= disp_donttouch
;
7945 b
->frame_id
= null_frame_id
;
7948 gdb_assert (b
->thread
!= 0);
7950 return add_to_breakpoint_chain (std::move (b
));
7953 /* Set a momentary breakpoint of type TYPE at address specified by
7954 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
7958 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7959 struct frame_id frame_id
, enum bptype type
)
7961 struct breakpoint
*b
;
7963 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
7965 gdb_assert (!frame_id_artificial_p (frame_id
));
7967 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7968 b
->enable_state
= bp_enabled
;
7969 b
->disposition
= disp_donttouch
;
7970 b
->frame_id
= frame_id
;
7972 b
->thread
= inferior_thread ()->global_num
;
7974 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7976 return breakpoint_up (b
);
7979 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7980 The new breakpoint will have type TYPE, use OPS as its
7981 breakpoint_ops, and will set enabled to LOC_ENABLED. */
7983 static struct breakpoint
*
7984 momentary_breakpoint_from_master (struct breakpoint
*orig
,
7988 struct breakpoint
*copy
;
7990 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
);
7991 copy
->loc
= copy
->allocate_location ();
7992 set_breakpoint_location_function (copy
->loc
);
7994 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
7995 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
7996 copy
->loc
->address
= orig
->loc
->address
;
7997 copy
->loc
->section
= orig
->loc
->section
;
7998 copy
->loc
->pspace
= orig
->loc
->pspace
;
7999 copy
->loc
->probe
= orig
->loc
->probe
;
8000 copy
->loc
->line_number
= orig
->loc
->line_number
;
8001 copy
->loc
->symtab
= orig
->loc
->symtab
;
8002 copy
->loc
->enabled
= loc_enabled
;
8003 copy
->frame_id
= orig
->frame_id
;
8004 copy
->thread
= orig
->thread
;
8005 copy
->pspace
= orig
->pspace
;
8007 copy
->enable_state
= bp_enabled
;
8008 copy
->disposition
= disp_donttouch
;
8009 copy
->number
= internal_breakpoint_number
--;
8011 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8015 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8019 clone_momentary_breakpoint (struct breakpoint
*orig
)
8021 /* If there's nothing to clone, then return nothing. */
8025 return momentary_breakpoint_from_master (orig
, orig
->type
, 0);
8029 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8032 struct symtab_and_line sal
;
8034 sal
= find_pc_line (pc
, 0);
8036 sal
.section
= find_pc_overlay (pc
);
8037 sal
.explicit_pc
= 1;
8039 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8043 /* Tell the user we have just set a breakpoint B. */
8046 mention (const breakpoint
*b
)
8048 b
->print_mention ();
8049 current_uiout
->text ("\n");
8053 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8055 /* Handle "set breakpoint auto-hw on".
8057 If the explicitly specified breakpoint type is not hardware
8058 breakpoint, check the memory map to see whether the breakpoint
8059 address is in read-only memory.
8061 - location type is not hardware breakpoint, memory is read-only.
8062 We change the type of the location to hardware breakpoint.
8064 - location type is hardware breakpoint, memory is read-write. This
8065 means we've previously made the location hardware one, but then the
8066 memory map changed, so we undo.
8070 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8072 if (automatic_hardware_breakpoints
8073 && bl
->owner
->type
!= bp_hardware_breakpoint
8074 && (bl
->loc_type
== bp_loc_software_breakpoint
8075 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8077 /* When breakpoints are removed, remove_breakpoints will use
8078 location types we've just set here, the only possible problem
8079 is that memory map has changed during running program, but
8080 it's not going to work anyway with current gdb. */
8081 mem_region
*mr
= lookup_mem_region (bl
->address
);
8085 enum bp_loc_type new_type
;
8087 if (mr
->attrib
.mode
!= MEM_RW
)
8088 new_type
= bp_loc_hardware_breakpoint
;
8090 new_type
= bp_loc_software_breakpoint
;
8092 if (new_type
!= bl
->loc_type
)
8094 static bool said
= false;
8096 bl
->loc_type
= new_type
;
8099 gdb_printf (_("Note: automatically using "
8100 "hardware breakpoints for "
8101 "read-only addresses.\n"));
8110 breakpoint::add_location (const symtab_and_line
&sal
)
8112 struct bp_location
*new_loc
, **tmp
;
8113 CORE_ADDR adjusted_address
;
8114 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8116 if (loc_gdbarch
== NULL
)
8117 loc_gdbarch
= gdbarch
;
8119 /* Adjust the breakpoint's address prior to allocating a location.
8120 Once we call allocate_location(), that mostly uninitialized
8121 location will be placed on the location chain. Adjustment of the
8122 breakpoint may cause target_read_memory() to be called and we do
8123 not want its scan of the location chain to find a breakpoint and
8124 location that's only been partially initialized. */
8125 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8128 /* Sort the locations by their ADDRESS. */
8129 new_loc
= allocate_location ();
8130 for (tmp
= &(loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8131 tmp
= &((*tmp
)->next
))
8133 new_loc
->next
= *tmp
;
8136 new_loc
->requested_address
= sal
.pc
;
8137 new_loc
->address
= adjusted_address
;
8138 new_loc
->pspace
= sal
.pspace
;
8139 new_loc
->probe
.prob
= sal
.prob
;
8140 new_loc
->probe
.objfile
= sal
.objfile
;
8141 gdb_assert (new_loc
->pspace
!= NULL
);
8142 new_loc
->section
= sal
.section
;
8143 new_loc
->gdbarch
= loc_gdbarch
;
8144 new_loc
->line_number
= sal
.line
;
8145 new_loc
->symtab
= sal
.symtab
;
8146 new_loc
->symbol
= sal
.symbol
;
8147 new_loc
->msymbol
= sal
.msymbol
;
8148 new_loc
->objfile
= sal
.objfile
;
8150 set_breakpoint_location_function (new_loc
);
8152 /* While by definition, permanent breakpoints are already present in the
8153 code, we don't mark the location as inserted. Normally one would expect
8154 that GDB could rely on that breakpoint instruction to stop the program,
8155 thus removing the need to insert its own breakpoint, except that executing
8156 the breakpoint instruction can kill the target instead of reporting a
8157 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8158 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8159 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8160 breakpoint be inserted normally results in QEMU knowing about the GDB
8161 breakpoint, and thus trap before the breakpoint instruction is executed.
8162 (If GDB later needs to continue execution past the permanent breakpoint,
8163 it manually increments the PC, thus avoiding executing the breakpoint
8165 if (bp_loc_is_permanent (new_loc
))
8166 new_loc
->permanent
= 1;
8172 /* Return true if LOC is pointing to a permanent breakpoint,
8173 return false otherwise. */
8176 bp_loc_is_permanent (struct bp_location
*loc
)
8178 gdb_assert (loc
!= NULL
);
8180 /* If we have a non-breakpoint-backed catchpoint or a software
8181 watchpoint, just return 0. We should not attempt to read from
8182 the addresses the locations of these breakpoint types point to.
8183 gdbarch_program_breakpoint_here_p, below, will attempt to read
8185 if (!bl_address_is_meaningful (loc
))
8188 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8189 switch_to_program_space_and_thread (loc
->pspace
);
8190 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8193 /* Build a command list for the dprintf corresponding to the current
8194 settings of the dprintf style options. */
8197 update_dprintf_command_list (struct breakpoint
*b
)
8199 const char *dprintf_args
= b
->extra_string
.get ();
8200 gdb::unique_xmalloc_ptr
<char> printf_line
= nullptr;
8205 dprintf_args
= skip_spaces (dprintf_args
);
8207 /* Allow a comma, as it may have terminated a location, but don't
8209 if (*dprintf_args
== ',')
8211 dprintf_args
= skip_spaces (dprintf_args
);
8213 if (*dprintf_args
!= '"')
8214 error (_("Bad format string, missing '\"'."));
8216 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8217 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8218 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8220 if (dprintf_function
.empty ())
8221 error (_("No function supplied for dprintf call"));
8223 if (!dprintf_channel
.empty ())
8224 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8225 dprintf_function
.c_str (),
8226 dprintf_channel
.c_str (),
8229 printf_line
= xstrprintf ("call (void) %s (%s)",
8230 dprintf_function
.c_str (),
8233 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8235 if (target_can_run_breakpoint_commands ())
8236 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8239 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8240 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8244 internal_error (__FILE__
, __LINE__
,
8245 _("Invalid dprintf style."));
8247 gdb_assert (printf_line
!= NULL
);
8249 /* Manufacture a printf sequence. */
8250 struct command_line
*printf_cmd_line
8251 = new struct command_line (simple_control
, printf_line
.release ());
8252 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8253 command_lines_deleter ()));
8256 /* Update all dprintf commands, making their command lists reflect
8257 current style settings. */
8260 update_dprintf_commands (const char *args
, int from_tty
,
8261 struct cmd_list_element
*c
)
8263 for (breakpoint
*b
: all_breakpoints ())
8264 if (b
->type
== bp_dprintf
)
8265 update_dprintf_command_list (b
);
8268 /* Create a breakpoint with SAL as location. Use LOCATION
8269 as a description of the location, and COND_STRING
8270 as condition expression. If LOCATION is NULL then create an
8271 "address location" from the address in the SAL. */
8274 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8275 gdb::array_view
<const symtab_and_line
> sals
,
8276 event_location_up
&&location
,
8277 gdb::unique_xmalloc_ptr
<char> filter
,
8278 gdb::unique_xmalloc_ptr
<char> cond_string
,
8279 gdb::unique_xmalloc_ptr
<char> extra_string
,
8280 enum bptype type
, enum bpdisp disposition
,
8281 int thread
, int task
, int ignore_count
,
8282 const struct breakpoint_ops
*ops
, int from_tty
,
8283 int enabled
, int internal
, unsigned flags
,
8284 int display_canonical
)
8288 if (type
== bp_hardware_breakpoint
)
8290 int target_resources_ok
;
8292 i
= hw_breakpoint_used_count ();
8293 target_resources_ok
=
8294 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8296 if (target_resources_ok
== 0)
8297 error (_("No hardware breakpoint support in the target."));
8298 else if (target_resources_ok
< 0)
8299 error (_("Hardware breakpoints used exceeds limit."));
8302 gdb_assert (!sals
.empty ());
8304 for (const auto &sal
: sals
)
8306 struct bp_location
*loc
;
8310 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8312 loc_gdbarch
= gdbarch
;
8314 describe_other_breakpoints (loc_gdbarch
,
8315 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8318 if (&sal
== &sals
[0])
8320 init_raw_breakpoint (b
, sal
, type
);
8324 b
->cond_string
= std::move (cond_string
);
8325 b
->extra_string
= std::move (extra_string
);
8326 b
->ignore_count
= ignore_count
;
8327 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8328 b
->disposition
= disposition
;
8330 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8331 b
->loc
->inserted
= 1;
8333 if (type
== bp_static_tracepoint
8334 || type
== bp_static_marker_tracepoint
)
8336 struct tracepoint
*t
= (struct tracepoint
*) b
;
8337 struct static_tracepoint_marker marker
;
8339 if (strace_marker_p (b
))
8341 /* We already know the marker exists, otherwise, we
8342 wouldn't see a sal for it. */
8344 = &event_location_to_string (b
->location
.get ())[3];
8347 p
= skip_spaces (p
);
8349 endp
= skip_to_space (p
);
8351 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8353 gdb_printf (_("Probed static tracepoint "
8355 t
->static_trace_marker_id
.c_str ());
8357 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8359 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8361 gdb_printf (_("Probed static tracepoint "
8363 t
->static_trace_marker_id
.c_str ());
8366 warning (_("Couldn't determine the static "
8367 "tracepoint marker to probe"));
8374 loc
= b
->add_location (sal
);
8375 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8379 /* Do not set breakpoint locations conditions yet. As locations
8380 are inserted, they get sorted based on their addresses. Let
8381 the list stabilize to have reliable location numbers. */
8383 /* Dynamic printf requires and uses additional arguments on the
8384 command line, otherwise it's an error. */
8385 if (type
== bp_dprintf
)
8387 if (b
->extra_string
)
8388 update_dprintf_command_list (b
);
8390 error (_("Format string required"));
8392 else if (b
->extra_string
)
8393 error (_("Garbage '%s' at end of command"), b
->extra_string
.get ());
8397 /* The order of the locations is now stable. Set the location
8398 condition using the location's number. */
8400 for (bp_location
*loc
: b
->locations ())
8402 if (b
->cond_string
!= nullptr)
8403 set_breakpoint_location_condition (b
->cond_string
.get (), loc
,
8404 b
->number
, loc_num
);
8409 b
->display_canonical
= display_canonical
;
8410 if (location
!= NULL
)
8411 b
->location
= std::move (location
);
8413 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8414 b
->filter
= std::move (filter
);
8418 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8419 gdb::array_view
<const symtab_and_line
> sals
,
8420 event_location_up
&&location
,
8421 gdb::unique_xmalloc_ptr
<char> filter
,
8422 gdb::unique_xmalloc_ptr
<char> cond_string
,
8423 gdb::unique_xmalloc_ptr
<char> extra_string
,
8424 enum bptype type
, enum bpdisp disposition
,
8425 int thread
, int task
, int ignore_count
,
8426 const struct breakpoint_ops
*ops
, int from_tty
,
8427 int enabled
, int internal
, unsigned flags
,
8428 int display_canonical
)
8430 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (gdbarch
, type
);
8432 init_breakpoint_sal (b
.get (), gdbarch
,
8433 sals
, std::move (location
),
8435 std::move (cond_string
),
8436 std::move (extra_string
),
8438 thread
, task
, ignore_count
,
8440 enabled
, internal
, flags
,
8443 install_breakpoint (internal
, std::move (b
), 0);
8446 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8447 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8448 value. COND_STRING, if not NULL, specified the condition to be
8449 used for all breakpoints. Essentially the only case where
8450 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8451 function. In that case, it's still not possible to specify
8452 separate conditions for different overloaded functions, so
8453 we take just a single condition string.
8455 NOTE: If the function succeeds, the caller is expected to cleanup
8456 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8457 array contents). If the function fails (error() is called), the
8458 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8459 COND and SALS arrays and each of those arrays contents. */
8462 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8463 struct linespec_result
*canonical
,
8464 gdb::unique_xmalloc_ptr
<char> cond_string
,
8465 gdb::unique_xmalloc_ptr
<char> extra_string
,
8466 enum bptype type
, enum bpdisp disposition
,
8467 int thread
, int task
, int ignore_count
,
8468 const struct breakpoint_ops
*ops
, int from_tty
,
8469 int enabled
, int internal
, unsigned flags
)
8471 if (canonical
->pre_expanded
)
8472 gdb_assert (canonical
->lsals
.size () == 1);
8474 for (const auto &lsal
: canonical
->lsals
)
8476 /* Note that 'location' can be NULL in the case of a plain
8477 'break', without arguments. */
8478 event_location_up location
8479 = (canonical
->location
!= NULL
8480 ? copy_event_location (canonical
->location
.get ()) : NULL
);
8481 gdb::unique_xmalloc_ptr
<char> filter_string
8482 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8484 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8485 std::move (location
),
8486 std::move (filter_string
),
8487 std::move (cond_string
),
8488 std::move (extra_string
),
8490 thread
, task
, ignore_count
, ops
,
8491 from_tty
, enabled
, internal
, flags
,
8492 canonical
->special_display
);
8496 /* Parse LOCATION which is assumed to be a SAL specification possibly
8497 followed by conditionals. On return, SALS contains an array of SAL
8498 addresses found. LOCATION points to the end of the SAL (for
8499 linespec locations).
8501 The array and the line spec strings are allocated on the heap, it is
8502 the caller's responsibility to free them. */
8505 parse_breakpoint_sals (struct event_location
*location
,
8506 struct linespec_result
*canonical
)
8508 struct symtab_and_line cursal
;
8510 if (event_location_type (location
) == LINESPEC_LOCATION
)
8512 const char *spec
= get_linespec_location (location
)->spec_string
;
8516 /* The last displayed codepoint, if it's valid, is our default
8517 breakpoint address. */
8518 if (last_displayed_sal_is_valid ())
8520 /* Set sal's pspace, pc, symtab, and line to the values
8521 corresponding to the last call to print_frame_info.
8522 Be sure to reinitialize LINE with NOTCURRENT == 0
8523 as the breakpoint line number is inappropriate otherwise.
8524 find_pc_line would adjust PC, re-set it back. */
8525 symtab_and_line sal
= get_last_displayed_sal ();
8526 CORE_ADDR pc
= sal
.pc
;
8528 sal
= find_pc_line (pc
, 0);
8530 /* "break" without arguments is equivalent to "break *PC"
8531 where PC is the last displayed codepoint's address. So
8532 make sure to set sal.explicit_pc to prevent GDB from
8533 trying to expand the list of sals to include all other
8534 instances with the same symtab and line. */
8536 sal
.explicit_pc
= 1;
8538 struct linespec_sals lsal
;
8540 lsal
.canonical
= NULL
;
8542 canonical
->lsals
.push_back (std::move (lsal
));
8546 error (_("No default breakpoint address now."));
8550 /* Force almost all breakpoints to be in terms of the
8551 current_source_symtab (which is decode_line_1's default).
8552 This should produce the results we want almost all of the
8553 time while leaving default_breakpoint_* alone.
8555 ObjC: However, don't match an Objective-C method name which
8556 may have a '+' or '-' succeeded by a '['. */
8557 cursal
= get_current_source_symtab_and_line ();
8558 if (last_displayed_sal_is_valid ())
8560 const char *spec
= NULL
;
8562 if (event_location_type (location
) == LINESPEC_LOCATION
)
8563 spec
= get_linespec_location (location
)->spec_string
;
8567 && strchr ("+-", spec
[0]) != NULL
8570 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8571 get_last_displayed_symtab (),
8572 get_last_displayed_line (),
8573 canonical
, NULL
, NULL
);
8578 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8579 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
8583 /* Convert each SAL into a real PC. Verify that the PC can be
8584 inserted as a breakpoint. If it can't throw an error. */
8587 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
8589 for (auto &sal
: sals
)
8590 resolve_sal_pc (&sal
);
8593 /* Fast tracepoints may have restrictions on valid locations. For
8594 instance, a fast tracepoint using a jump instead of a trap will
8595 likely have to overwrite more bytes than a trap would, and so can
8596 only be placed where the instruction is longer than the jump, or a
8597 multi-instruction sequence does not have a jump into the middle of
8601 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8602 gdb::array_view
<const symtab_and_line
> sals
)
8604 for (const auto &sal
: sals
)
8606 struct gdbarch
*sarch
;
8608 sarch
= get_sal_arch (sal
);
8609 /* We fall back to GDBARCH if there is no architecture
8610 associated with SAL. */
8614 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
8615 error (_("May not have a fast tracepoint at %s%s"),
8616 paddress (sarch
, sal
.pc
), msg
.c_str ());
8620 /* Given TOK, a string specification of condition and thread, as
8621 accepted by the 'break' command, extract the condition
8622 string and thread number and set *COND_STRING and *THREAD.
8623 PC identifies the context at which the condition should be parsed.
8624 If no condition is found, *COND_STRING is set to NULL.
8625 If no thread is found, *THREAD is set to -1. */
8628 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
8629 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8630 int *thread
, int *task
,
8631 gdb::unique_xmalloc_ptr
<char> *rest
)
8633 cond_string
->reset ();
8641 const char *end_tok
;
8643 const char *cond_start
= NULL
;
8644 const char *cond_end
= NULL
;
8646 tok
= skip_spaces (tok
);
8648 if ((*tok
== '"' || *tok
== ',') && rest
)
8650 rest
->reset (savestring (tok
, strlen (tok
)));
8654 end_tok
= skip_to_space (tok
);
8656 toklen
= end_tok
- tok
;
8658 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8660 tok
= cond_start
= end_tok
+ 1;
8663 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
8665 catch (const gdb_exception_error
&)
8670 tok
= tok
+ strlen (tok
);
8673 cond_string
->reset (savestring (cond_start
, cond_end
- cond_start
));
8675 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
8680 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8683 struct thread_info
*thr
;
8686 thr
= parse_thread_id (tok
, &tmptok
);
8688 error (_("Junk after thread keyword."));
8689 *thread
= thr
->global_num
;
8692 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8697 *task
= strtol (tok
, &tmptok
, 0);
8699 error (_("Junk after task keyword."));
8700 if (!valid_task_id (*task
))
8701 error (_("Unknown task %d."), *task
);
8706 rest
->reset (savestring (tok
, strlen (tok
)));
8710 error (_("Junk at end of arguments."));
8714 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
8715 succeeds. The parsed values are written to COND_STRING, THREAD,
8716 TASK, and REST. See the comment of 'find_condition_and_thread'
8717 for the description of these parameters and INPUT. */
8720 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
8722 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8723 int *thread
, int *task
,
8724 gdb::unique_xmalloc_ptr
<char> *rest
)
8726 int num_failures
= 0;
8727 for (auto &sal
: sals
)
8729 gdb::unique_xmalloc_ptr
<char> cond
;
8732 gdb::unique_xmalloc_ptr
<char> remaining
;
8734 /* Here we want to parse 'arg' to separate condition from thread
8735 number. But because parsing happens in a context and the
8736 contexts of sals might be different, try each until there is
8737 success. Finding one successful parse is sufficient for our
8738 goal. When setting the breakpoint we'll re-parse the
8739 condition in the context of each sal. */
8742 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
8743 &task_id
, &remaining
);
8744 *cond_string
= std::move (cond
);
8745 *thread
= thread_id
;
8747 *rest
= std::move (remaining
);
8750 catch (const gdb_exception_error
&e
)
8753 /* If no sal remains, do not continue. */
8754 if (num_failures
== sals
.size ())
8760 /* Decode a static tracepoint marker spec. */
8762 static std::vector
<symtab_and_line
>
8763 decode_static_tracepoint_spec (const char **arg_p
)
8765 const char *p
= &(*arg_p
)[3];
8768 p
= skip_spaces (p
);
8770 endp
= skip_to_space (p
);
8772 std::string
marker_str (p
, endp
- p
);
8774 std::vector
<static_tracepoint_marker
> markers
8775 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
8776 if (markers
.empty ())
8777 error (_("No known static tracepoint marker named %s"),
8778 marker_str
.c_str ());
8780 std::vector
<symtab_and_line
> sals
;
8781 sals
.reserve (markers
.size ());
8783 for (const static_tracepoint_marker
&marker
: markers
)
8785 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
8786 sal
.pc
= marker
.address
;
8787 sals
.push_back (sal
);
8794 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
8795 according to IS_TRACEPOINT. */
8797 static const struct breakpoint_ops
*
8798 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
8803 if (location_type
== PROBE_LOCATION
)
8804 return &tracepoint_probe_breakpoint_ops
;
8806 return &base_breakpoint_ops
;
8810 if (location_type
== PROBE_LOCATION
)
8811 return &bkpt_probe_breakpoint_ops
;
8813 return &base_breakpoint_ops
;
8817 /* See breakpoint.h. */
8819 const struct breakpoint_ops
*
8820 breakpoint_ops_for_event_location (const struct event_location
*location
,
8823 if (location
!= nullptr)
8824 return breakpoint_ops_for_event_location_type
8825 (event_location_type (location
), is_tracepoint
);
8826 return &base_breakpoint_ops
;
8829 /* See breakpoint.h. */
8832 create_breakpoint (struct gdbarch
*gdbarch
,
8833 struct event_location
*location
,
8834 const char *cond_string
,
8835 int thread
, const char *extra_string
,
8836 bool force_condition
, int parse_extra
,
8837 int tempflag
, enum bptype type_wanted
,
8839 enum auto_boolean pending_break_support
,
8840 const struct breakpoint_ops
*ops
,
8841 int from_tty
, int enabled
, int internal
,
8844 struct linespec_result canonical
;
8847 int prev_bkpt_count
= breakpoint_count
;
8849 gdb_assert (ops
!= NULL
);
8851 /* If extra_string isn't useful, set it to NULL. */
8852 if (extra_string
!= NULL
&& *extra_string
== '\0')
8853 extra_string
= NULL
;
8857 ops
->create_sals_from_location (location
, &canonical
);
8859 catch (const gdb_exception_error
&e
)
8861 /* If caller is interested in rc value from parse, set
8863 if (e
.error
== NOT_FOUND_ERROR
)
8865 /* If pending breakpoint support is turned off, throw
8868 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
8871 exception_print (gdb_stderr
, e
);
8873 /* If pending breakpoint support is auto query and the user
8874 selects no, then simply return the error code. */
8875 if (pending_break_support
== AUTO_BOOLEAN_AUTO
8876 && !nquery (_("Make %s pending on future shared library load? "),
8877 bptype_string (type_wanted
)))
8880 /* At this point, either the user was queried about setting
8881 a pending breakpoint and selected yes, or pending
8882 breakpoint behavior is on and thus a pending breakpoint
8883 is defaulted on behalf of the user. */
8890 if (!pending
&& canonical
.lsals
.empty ())
8893 /* Resolve all line numbers to PC's and verify that the addresses
8894 are ok for the target. */
8897 for (auto &lsal
: canonical
.lsals
)
8898 breakpoint_sals_to_pc (lsal
.sals
);
8901 /* Fast tracepoints may have additional restrictions on location. */
8902 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
8904 for (const auto &lsal
: canonical
.lsals
)
8905 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
8908 /* Verify that condition can be parsed, before setting any
8909 breakpoints. Allocate a separate condition expression for each
8913 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
8914 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
8918 gdb::unique_xmalloc_ptr
<char> rest
;
8919 gdb::unique_xmalloc_ptr
<char> cond
;
8921 const linespec_sals
&lsal
= canonical
.lsals
[0];
8923 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
8924 &cond
, &thread
, &task
, &rest
);
8925 cond_string_copy
= std::move (cond
);
8926 extra_string_copy
= std::move (rest
);
8930 if (type_wanted
!= bp_dprintf
8931 && extra_string
!= NULL
&& *extra_string
!= '\0')
8932 error (_("Garbage '%s' at end of location"), extra_string
);
8934 /* Check the validity of the condition. We should error out
8935 if the condition is invalid at all of the locations and
8936 if it is not forced. In the PARSE_EXTRA case above, this
8937 check is done when parsing the EXTRA_STRING. */
8938 if (cond_string
!= nullptr && !force_condition
)
8940 int num_failures
= 0;
8941 const linespec_sals
&lsal
= canonical
.lsals
[0];
8942 for (const auto &sal
: lsal
.sals
)
8944 const char *cond
= cond_string
;
8947 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
8948 /* One success is sufficient to keep going. */
8951 catch (const gdb_exception_error
&)
8954 /* If this is the last sal, error out. */
8955 if (num_failures
== lsal
.sals
.size ())
8961 /* Create a private copy of condition string. */
8963 cond_string_copy
.reset (xstrdup (cond_string
));
8964 /* Create a private copy of any extra string. */
8966 extra_string_copy
.reset (xstrdup (extra_string
));
8969 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
8970 std::move (cond_string_copy
),
8971 std::move (extra_string_copy
),
8973 tempflag
? disp_del
: disp_donttouch
,
8974 thread
, task
, ignore_count
, ops
,
8975 from_tty
, enabled
, internal
, flags
);
8979 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (gdbarch
,
8981 b
->location
= copy_event_location (location
);
8984 b
->cond_string
= NULL
;
8987 /* Create a private copy of condition string. */
8988 b
->cond_string
.reset (cond_string
!= NULL
8989 ? xstrdup (cond_string
)
8994 /* Create a private copy of any extra string. */
8995 b
->extra_string
.reset (extra_string
!= NULL
8996 ? xstrdup (extra_string
)
8998 b
->ignore_count
= ignore_count
;
8999 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9000 b
->condition_not_parsed
= 1;
9001 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9002 if ((type_wanted
!= bp_breakpoint
9003 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9004 b
->pspace
= current_program_space
;
9006 install_breakpoint (internal
, std::move (b
), 0);
9009 if (canonical
.lsals
.size () > 1)
9011 warning (_("Multiple breakpoints were set.\nUse the "
9012 "\"delete\" command to delete unwanted breakpoints."));
9013 prev_breakpoint_count
= prev_bkpt_count
;
9016 update_global_location_list (UGLL_MAY_INSERT
);
9021 /* Set a breakpoint.
9022 ARG is a string describing breakpoint address,
9023 condition, and thread.
9024 FLAG specifies if a breakpoint is hardware on,
9025 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9029 break_command_1 (const char *arg
, int flag
, int from_tty
)
9031 int tempflag
= flag
& BP_TEMPFLAG
;
9032 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9033 ? bp_hardware_breakpoint
9036 event_location_up location
= string_to_event_location (&arg
, current_language
);
9037 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9038 (location
.get (), false /* is_tracepoint */);
9040 create_breakpoint (get_current_arch (),
9042 NULL
, 0, arg
, false, 1 /* parse arg */,
9043 tempflag
, type_wanted
,
9044 0 /* Ignore count */,
9045 pending_break_support
,
9053 /* Helper function for break_command_1 and disassemble_command. */
9056 resolve_sal_pc (struct symtab_and_line
*sal
)
9060 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9062 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9063 error (_("No line %d in file \"%s\"."),
9064 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9067 /* If this SAL corresponds to a breakpoint inserted using a line
9068 number, then skip the function prologue if necessary. */
9069 if (sal
->explicit_line
)
9070 skip_prologue_sal (sal
);
9073 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9075 const struct blockvector
*bv
;
9076 const struct block
*b
;
9079 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9080 sal
->symtab
->compunit ());
9083 sym
= block_linkage_function (b
);
9086 fixup_symbol_section (sym
, sal
->symtab
->compunit ()->objfile ());
9088 = sym
->obj_section (sal
->symtab
->compunit ()->objfile ());
9092 /* It really is worthwhile to have the section, so we'll
9093 just have to look harder. This case can be executed
9094 if we have line numbers but no functions (as can
9095 happen in assembly source). */
9097 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9098 switch_to_program_space_and_thread (sal
->pspace
);
9100 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9102 sal
->section
= msym
.obj_section ();
9109 break_command (const char *arg
, int from_tty
)
9111 break_command_1 (arg
, 0, from_tty
);
9115 tbreak_command (const char *arg
, int from_tty
)
9117 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9121 hbreak_command (const char *arg
, int from_tty
)
9123 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9127 thbreak_command (const char *arg
, int from_tty
)
9129 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9132 /* The dynamic printf command is mostly like a regular breakpoint, but
9133 with a prewired command list consisting of a single output command,
9134 built from extra arguments supplied on the dprintf command
9138 dprintf_command (const char *arg
, int from_tty
)
9140 event_location_up location
= string_to_event_location (&arg
, current_language
);
9142 /* If non-NULL, ARG should have been advanced past the location;
9143 the next character must be ','. */
9146 if (arg
[0] != ',' || arg
[1] == '\0')
9147 error (_("Format string required"));
9150 /* Skip the comma. */
9155 create_breakpoint (get_current_arch (),
9157 NULL
, 0, arg
, false, 1 /* parse arg */,
9159 0 /* Ignore count */,
9160 pending_break_support
,
9161 &base_breakpoint_ops
,
9169 agent_printf_command (const char *arg
, int from_tty
)
9171 error (_("May only run agent-printf on the target"));
9174 /* Implement the "breakpoint_hit" method for ranged breakpoints. */
9177 ranged_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
9178 const address_space
*aspace
,
9180 const target_waitstatus
&ws
)
9182 if (ws
.kind () != TARGET_WAITKIND_STOPPED
9183 || ws
.sig () != GDB_SIGNAL_TRAP
)
9186 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9187 bl
->length
, aspace
, bp_addr
);
9190 /* Implement the "resources_needed" method for ranged breakpoints. */
9193 ranged_breakpoint::resources_needed (const struct bp_location
*bl
)
9195 return target_ranged_break_num_registers ();
9198 /* Implement the "print_it" method for ranged breakpoints. */
9200 enum print_stop_action
9201 ranged_breakpoint::print_it (const bpstat
*bs
) const
9203 struct bp_location
*bl
= loc
;
9204 struct ui_out
*uiout
= current_uiout
;
9206 gdb_assert (type
== bp_hardware_breakpoint
);
9208 /* Ranged breakpoints have only one location. */
9209 gdb_assert (bl
&& bl
->next
== NULL
);
9211 annotate_breakpoint (number
);
9213 maybe_print_thread_hit_breakpoint (uiout
);
9215 if (disposition
== disp_del
)
9216 uiout
->text ("Temporary ranged breakpoint ");
9218 uiout
->text ("Ranged breakpoint ");
9219 if (uiout
->is_mi_like_p ())
9221 uiout
->field_string ("reason",
9222 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9223 uiout
->field_string ("disp", bpdisp_text (disposition
));
9225 uiout
->field_signed ("bkptno", number
);
9228 return PRINT_SRC_AND_LOC
;
9231 /* Implement the "print_one" method for ranged breakpoints. */
9234 ranged_breakpoint::print_one (bp_location
**last_loc
) const
9236 struct bp_location
*bl
= loc
;
9237 struct value_print_options opts
;
9238 struct ui_out
*uiout
= current_uiout
;
9240 /* Ranged breakpoints have only one location. */
9241 gdb_assert (bl
&& bl
->next
== NULL
);
9243 get_user_print_options (&opts
);
9245 if (opts
.addressprint
)
9246 /* We don't print the address range here, it will be printed later
9247 by print_one_detail_ranged_breakpoint. */
9248 uiout
->field_skip ("addr");
9250 print_breakpoint_location (this, bl
);
9256 /* Implement the "print_one_detail" method for ranged breakpoints. */
9259 ranged_breakpoint::print_one_detail (struct ui_out
*uiout
) const
9261 CORE_ADDR address_start
, address_end
;
9262 struct bp_location
*bl
= loc
;
9267 address_start
= bl
->address
;
9268 address_end
= address_start
+ bl
->length
- 1;
9270 uiout
->text ("\taddress range: ");
9271 stb
.printf ("[%s, %s]",
9272 print_core_address (bl
->gdbarch
, address_start
),
9273 print_core_address (bl
->gdbarch
, address_end
));
9274 uiout
->field_stream ("addr", stb
);
9278 /* Implement the "print_mention" method for ranged breakpoints. */
9281 ranged_breakpoint::print_mention () const
9283 struct bp_location
*bl
= loc
;
9284 struct ui_out
*uiout
= current_uiout
;
9287 gdb_assert (type
== bp_hardware_breakpoint
);
9289 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9290 number
, paddress (bl
->gdbarch
, bl
->address
),
9291 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9294 /* Implement the "print_recreate" method for ranged breakpoints. */
9297 ranged_breakpoint::print_recreate (struct ui_file
*fp
) const
9299 gdb_printf (fp
, "break-range %s, %s",
9300 event_location_to_string (location
.get ()),
9301 event_location_to_string (location_range_end
.get ()));
9302 print_recreate_thread (fp
);
9305 /* Find the address where the end of the breakpoint range should be
9306 placed, given the SAL of the end of the range. This is so that if
9307 the user provides a line number, the end of the range is set to the
9308 last instruction of the given line. */
9311 find_breakpoint_range_end (struct symtab_and_line sal
)
9315 /* If the user provided a PC value, use it. Otherwise,
9316 find the address of the end of the given location. */
9317 if (sal
.explicit_pc
)
9324 ret
= find_line_pc_range (sal
, &start
, &end
);
9326 error (_("Could not find location of the end of the range."));
9328 /* find_line_pc_range returns the start of the next line. */
9335 /* Implement the "break-range" CLI command. */
9338 break_range_command (const char *arg
, int from_tty
)
9340 const char *arg_start
;
9341 struct linespec_result canonical_start
, canonical_end
;
9342 int bp_count
, can_use_bp
, length
;
9344 struct breakpoint
*b
;
9346 /* We don't support software ranged breakpoints. */
9347 if (target_ranged_break_num_registers () < 0)
9348 error (_("This target does not support hardware ranged breakpoints."));
9350 bp_count
= hw_breakpoint_used_count ();
9351 bp_count
+= target_ranged_break_num_registers ();
9352 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9355 error (_("Hardware breakpoints used exceeds limit."));
9357 arg
= skip_spaces (arg
);
9358 if (arg
== NULL
|| arg
[0] == '\0')
9359 error(_("No address range specified."));
9362 event_location_up start_location
= string_to_event_location (&arg
,
9364 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9367 error (_("Too few arguments."));
9368 else if (canonical_start
.lsals
.empty ())
9369 error (_("Could not find location of the beginning of the range."));
9371 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9373 if (canonical_start
.lsals
.size () > 1
9374 || lsal_start
.sals
.size () != 1)
9375 error (_("Cannot create a ranged breakpoint with multiple locations."));
9377 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9378 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9380 arg
++; /* Skip the comma. */
9381 arg
= skip_spaces (arg
);
9383 /* Parse the end location. */
9387 /* We call decode_line_full directly here instead of using
9388 parse_breakpoint_sals because we need to specify the start location's
9389 symtab and line as the default symtab and line for the end of the
9390 range. This makes it possible to have ranges like "foo.c:27, +14",
9391 where +14 means 14 lines from the start location. */
9392 event_location_up end_location
= string_to_event_location (&arg
,
9394 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9395 sal_start
.symtab
, sal_start
.line
,
9396 &canonical_end
, NULL
, NULL
);
9398 if (canonical_end
.lsals
.empty ())
9399 error (_("Could not find location of the end of the range."));
9401 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9402 if (canonical_end
.lsals
.size () > 1
9403 || lsal_end
.sals
.size () != 1)
9404 error (_("Cannot create a ranged breakpoint with multiple locations."));
9406 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9408 end
= find_breakpoint_range_end (sal_end
);
9409 if (sal_start
.pc
> end
)
9410 error (_("Invalid address range, end precedes start."));
9412 length
= end
- sal_start
.pc
+ 1;
9414 /* Length overflowed. */
9415 error (_("Address range too large."));
9416 else if (length
== 1)
9418 /* This range is simple enough to be handled by
9419 the `hbreak' command. */
9420 hbreak_command (&addr_string_start
[0], 1);
9425 /* Now set up the breakpoint. */
9426 std::unique_ptr
<breakpoint
> br (new ranged_breakpoint (get_current_arch ()));
9427 init_raw_breakpoint (br
.get (), sal_start
, bp_hardware_breakpoint
);
9428 b
= add_to_breakpoint_chain (std::move (br
));
9430 set_breakpoint_count (breakpoint_count
+ 1);
9431 b
->number
= breakpoint_count
;
9432 b
->disposition
= disp_donttouch
;
9433 b
->location
= std::move (start_location
);
9434 b
->location_range_end
= std::move (end_location
);
9435 b
->loc
->length
= length
;
9438 gdb::observers::breakpoint_created
.notify (b
);
9439 update_global_location_list (UGLL_MAY_INSERT
);
9442 /* Return non-zero if EXP is verified as constant. Returned zero
9443 means EXP is variable. Also the constant detection may fail for
9444 some constant expressions and in such case still falsely return
9448 watchpoint_exp_is_const (const struct expression
*exp
)
9450 return exp
->op
->constant_p ();
9453 /* Implement the "re_set" method for watchpoints. */
9456 watchpoint::re_set ()
9458 /* Watchpoint can be either on expression using entirely global
9459 variables, or it can be on local variables.
9461 Watchpoints of the first kind are never auto-deleted, and even
9462 persist across program restarts. Since they can use variables
9463 from shared libraries, we need to reparse expression as libraries
9464 are loaded and unloaded.
9466 Watchpoints on local variables can also change meaning as result
9467 of solib event. For example, if a watchpoint uses both a local
9468 and a global variables in expression, it's a local watchpoint,
9469 but unloading of a shared library will make the expression
9470 invalid. This is not a very common use case, but we still
9471 re-evaluate expression, to avoid surprises to the user.
9473 Note that for local watchpoints, we re-evaluate it only if
9474 watchpoints frame id is still valid. If it's not, it means the
9475 watchpoint is out of scope and will be deleted soon. In fact,
9476 I'm not sure we'll ever be called in this case.
9478 If a local watchpoint's frame id is still valid, then
9479 exp_valid_block is likewise valid, and we can safely use it.
9481 Don't do anything about disabled watchpoints, since they will be
9482 reevaluated again when enabled. */
9483 update_watchpoint (this, 1 /* reparse */);
9486 /* Implement the "insert" method for hardware watchpoints. */
9489 watchpoint::insert_location (struct bp_location
*bl
)
9491 int length
= exact
? 1 : bl
->length
;
9493 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9497 /* Implement the "remove" method for hardware watchpoints. */
9500 watchpoint::remove_location (struct bp_location
*bl
,
9501 enum remove_bp_reason reason
)
9503 int length
= exact
? 1 : bl
->length
;
9505 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9510 watchpoint::breakpoint_hit (const struct bp_location
*bl
,
9511 const address_space
*aspace
, CORE_ADDR bp_addr
,
9512 const target_waitstatus
&ws
)
9514 struct breakpoint
*b
= bl
->owner
;
9516 /* Continuable hardware watchpoints are treated as non-existent if the
9517 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9518 some data address). Otherwise gdb won't stop on a break instruction
9519 in the code (not from a breakpoint) when a hardware watchpoint has
9520 been defined. Also skip watchpoints which we know did not trigger
9521 (did not match the data address). */
9522 if (is_hardware_watchpoint (b
)
9523 && watchpoint_triggered
== watch_triggered_no
)
9530 watchpoint::check_status (bpstat
*bs
)
9532 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
9534 bpstat_check_watchpoint (bs
);
9537 /* Implement the "resources_needed" method for hardware
9541 watchpoint::resources_needed (const struct bp_location
*bl
)
9543 int length
= exact
? 1 : bl
->length
;
9545 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9548 /* Implement the "works_in_software_mode" method for hardware
9552 watchpoint::works_in_software_mode () const
9554 /* Read and access watchpoints only work with hardware support. */
9555 return type
== bp_watchpoint
|| type
== bp_hardware_watchpoint
;
9558 enum print_stop_action
9559 watchpoint::print_it (const bpstat
*bs
) const
9561 struct breakpoint
*b
;
9562 enum print_stop_action result
;
9563 struct ui_out
*uiout
= current_uiout
;
9565 gdb_assert (bs
->bp_location_at
!= NULL
);
9567 b
= bs
->breakpoint_at
;
9569 annotate_watchpoint (b
->number
);
9570 maybe_print_thread_hit_breakpoint (uiout
);
9574 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
9578 case bp_hardware_watchpoint
:
9579 if (uiout
->is_mi_like_p ())
9581 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9583 tuple_emitter
.emplace (uiout
, "value");
9584 uiout
->text ("\nOld value = ");
9585 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9586 uiout
->field_stream ("old", stb
);
9587 uiout
->text ("\nNew value = ");
9588 watchpoint_value_print (val
.get (), &stb
);
9589 uiout
->field_stream ("new", stb
);
9591 /* More than one watchpoint may have been triggered. */
9592 result
= PRINT_UNKNOWN
;
9595 case bp_read_watchpoint
:
9596 if (uiout
->is_mi_like_p ())
9598 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9600 tuple_emitter
.emplace (uiout
, "value");
9601 uiout
->text ("\nValue = ");
9602 watchpoint_value_print (val
.get (), &stb
);
9603 uiout
->field_stream ("value", stb
);
9605 result
= PRINT_UNKNOWN
;
9608 case bp_access_watchpoint
:
9609 if (bs
->old_val
!= NULL
)
9611 if (uiout
->is_mi_like_p ())
9614 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9616 tuple_emitter
.emplace (uiout
, "value");
9617 uiout
->text ("\nOld value = ");
9618 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9619 uiout
->field_stream ("old", stb
);
9620 uiout
->text ("\nNew value = ");
9625 if (uiout
->is_mi_like_p ())
9628 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9629 tuple_emitter
.emplace (uiout
, "value");
9630 uiout
->text ("\nValue = ");
9632 watchpoint_value_print (val
.get (), &stb
);
9633 uiout
->field_stream ("new", stb
);
9635 result
= PRINT_UNKNOWN
;
9638 result
= PRINT_UNKNOWN
;
9644 /* Implement the "print_mention" method for hardware watchpoints. */
9647 watchpoint::print_mention () const
9649 struct ui_out
*uiout
= current_uiout
;
9650 const char *tuple_name
;
9655 uiout
->text ("Watchpoint ");
9658 case bp_hardware_watchpoint
:
9659 uiout
->text ("Hardware watchpoint ");
9662 case bp_read_watchpoint
:
9663 uiout
->text ("Hardware read watchpoint ");
9664 tuple_name
= "hw-rwpt";
9666 case bp_access_watchpoint
:
9667 uiout
->text ("Hardware access (read/write) watchpoint ");
9668 tuple_name
= "hw-awpt";
9671 internal_error (__FILE__
, __LINE__
,
9672 _("Invalid hardware watchpoint type."));
9675 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9676 uiout
->field_signed ("number", number
);
9678 uiout
->field_string ("exp", exp_string
.get ());
9681 /* Implement the "print_recreate" method for watchpoints. */
9684 watchpoint::print_recreate (struct ui_file
*fp
) const
9689 case bp_hardware_watchpoint
:
9690 gdb_printf (fp
, "watch");
9692 case bp_read_watchpoint
:
9693 gdb_printf (fp
, "rwatch");
9695 case bp_access_watchpoint
:
9696 gdb_printf (fp
, "awatch");
9699 internal_error (__FILE__
, __LINE__
,
9700 _("Invalid watchpoint type."));
9703 gdb_printf (fp
, " %s", exp_string
.get ());
9704 print_recreate_thread (fp
);
9707 /* Implement the "explains_signal" method for watchpoints. */
9710 watchpoint::explains_signal (enum gdb_signal sig
)
9712 /* A software watchpoint cannot cause a signal other than
9714 if (type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
9720 struct masked_watchpoint
: public watchpoint
9722 using watchpoint::watchpoint
;
9724 int insert_location (struct bp_location
*) override
;
9725 int remove_location (struct bp_location
*,
9726 enum remove_bp_reason reason
) override
;
9727 int resources_needed (const struct bp_location
*) override
;
9728 bool works_in_software_mode () const override
;
9729 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
9730 void print_one_detail (struct ui_out
*) const override
;
9731 void print_mention () const override
;
9732 void print_recreate (struct ui_file
*fp
) const override
;
9735 /* Implement the "insert" method for masked hardware watchpoints. */
9738 masked_watchpoint::insert_location (struct bp_location
*bl
)
9740 return target_insert_mask_watchpoint (bl
->address
, hw_wp_mask
,
9741 bl
->watchpoint_type
);
9744 /* Implement the "remove" method for masked hardware watchpoints. */
9747 masked_watchpoint::remove_location (struct bp_location
*bl
,
9748 enum remove_bp_reason reason
)
9750 return target_remove_mask_watchpoint (bl
->address
, hw_wp_mask
,
9751 bl
->watchpoint_type
);
9754 /* Implement the "resources_needed" method for masked hardware
9758 masked_watchpoint::resources_needed (const struct bp_location
*bl
)
9760 return target_masked_watch_num_registers (bl
->address
, hw_wp_mask
);
9763 /* Implement the "works_in_software_mode" method for masked hardware
9767 masked_watchpoint::works_in_software_mode () const
9772 /* Implement the "print_it" method for masked hardware
9775 enum print_stop_action
9776 masked_watchpoint::print_it (const bpstat
*bs
) const
9778 struct breakpoint
*b
= bs
->breakpoint_at
;
9779 struct ui_out
*uiout
= current_uiout
;
9781 /* Masked watchpoints have only one location. */
9782 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9784 annotate_watchpoint (b
->number
);
9785 maybe_print_thread_hit_breakpoint (uiout
);
9789 case bp_hardware_watchpoint
:
9790 if (uiout
->is_mi_like_p ())
9792 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9795 case bp_read_watchpoint
:
9796 if (uiout
->is_mi_like_p ())
9798 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9801 case bp_access_watchpoint
:
9802 if (uiout
->is_mi_like_p ())
9805 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9808 internal_error (__FILE__
, __LINE__
,
9809 _("Invalid hardware watchpoint type."));
9814 Check the underlying instruction at PC for the memory\n\
9815 address and value which triggered this watchpoint.\n"));
9818 /* More than one watchpoint may have been triggered. */
9819 return PRINT_UNKNOWN
;
9822 /* Implement the "print_one_detail" method for masked hardware
9826 masked_watchpoint::print_one_detail (struct ui_out
*uiout
) const
9828 /* Masked watchpoints have only one location. */
9829 gdb_assert (loc
&& loc
->next
== NULL
);
9831 uiout
->text ("\tmask ");
9832 uiout
->field_core_addr ("mask", loc
->gdbarch
, hw_wp_mask
);
9836 /* Implement the "print_mention" method for masked hardware
9840 masked_watchpoint::print_mention () const
9842 struct ui_out
*uiout
= current_uiout
;
9843 const char *tuple_name
;
9847 case bp_hardware_watchpoint
:
9848 uiout
->text ("Masked hardware watchpoint ");
9851 case bp_read_watchpoint
:
9852 uiout
->text ("Masked hardware read watchpoint ");
9853 tuple_name
= "hw-rwpt";
9855 case bp_access_watchpoint
:
9856 uiout
->text ("Masked hardware access (read/write) watchpoint ");
9857 tuple_name
= "hw-awpt";
9860 internal_error (__FILE__
, __LINE__
,
9861 _("Invalid hardware watchpoint type."));
9864 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9865 uiout
->field_signed ("number", number
);
9867 uiout
->field_string ("exp", exp_string
.get ());
9870 /* Implement the "print_recreate" method for masked hardware
9874 masked_watchpoint::print_recreate (struct ui_file
*fp
) const
9878 case bp_hardware_watchpoint
:
9879 gdb_printf (fp
, "watch");
9881 case bp_read_watchpoint
:
9882 gdb_printf (fp
, "rwatch");
9884 case bp_access_watchpoint
:
9885 gdb_printf (fp
, "awatch");
9888 internal_error (__FILE__
, __LINE__
,
9889 _("Invalid hardware watchpoint type."));
9892 gdb_printf (fp
, " %s mask 0x%s", exp_string
.get (),
9893 phex (hw_wp_mask
, sizeof (CORE_ADDR
)));
9894 print_recreate_thread (fp
);
9897 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9900 is_masked_watchpoint (const struct breakpoint
*b
)
9902 return dynamic_cast<const masked_watchpoint
*> (b
) != nullptr;
9905 /* accessflag: hw_write: watch write,
9906 hw_read: watch read,
9907 hw_access: watch access (read or write) */
9909 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
9910 bool just_location
, bool internal
)
9912 struct breakpoint
*scope_breakpoint
= NULL
;
9913 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9914 struct value
*result
;
9915 int saved_bitpos
= 0, saved_bitsize
= 0;
9916 const char *exp_start
= NULL
;
9917 const char *exp_end
= NULL
;
9918 const char *tok
, *end_tok
;
9920 const char *cond_start
= NULL
;
9921 const char *cond_end
= NULL
;
9922 enum bptype bp_type
;
9924 /* Flag to indicate whether we are going to use masks for
9925 the hardware watchpoint. */
9926 bool use_mask
= false;
9930 /* Make sure that we actually have parameters to parse. */
9931 if (arg
!= NULL
&& arg
[0] != '\0')
9933 const char *value_start
;
9935 exp_end
= arg
+ strlen (arg
);
9937 /* Look for "parameter value" pairs at the end
9938 of the arguments string. */
9939 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
9941 /* Skip whitespace at the end of the argument list. */
9942 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9945 /* Find the beginning of the last token.
9946 This is the value of the parameter. */
9947 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9949 value_start
= tok
+ 1;
9951 /* Skip whitespace. */
9952 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9957 /* Find the beginning of the second to last token.
9958 This is the parameter itself. */
9959 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9962 toklen
= end_tok
- tok
+ 1;
9964 if (toklen
== 6 && startswith (tok
, "thread"))
9966 struct thread_info
*thr
;
9967 /* At this point we've found a "thread" token, which means
9968 the user is trying to set a watchpoint that triggers
9969 only in a specific thread. */
9973 error(_("You can specify only one thread."));
9975 /* Extract the thread ID from the next token. */
9976 thr
= parse_thread_id (value_start
, &endp
);
9978 /* Check if the user provided a valid thread ID. */
9979 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9980 invalid_thread_id_error (value_start
);
9982 thread
= thr
->global_num
;
9984 else if (toklen
== 4 && startswith (tok
, "task"))
9988 task
= strtol (value_start
, &tmp
, 0);
9989 if (tmp
== value_start
)
9990 error (_("Junk after task keyword."));
9991 if (!valid_task_id (task
))
9992 error (_("Unknown task %d."), task
);
9994 else if (toklen
== 4 && startswith (tok
, "mask"))
9996 /* We've found a "mask" token, which means the user wants to
9997 create a hardware watchpoint that is going to have the mask
9999 struct value
*mask_value
, *mark
;
10002 error(_("You can specify only one mask."));
10004 use_mask
= just_location
= true;
10006 mark
= value_mark ();
10007 mask_value
= parse_to_comma_and_eval (&value_start
);
10008 mask
= value_as_address (mask_value
);
10009 value_free_to_mark (mark
);
10012 /* We didn't recognize what we found. We should stop here. */
10015 /* Truncate the string and get rid of the "parameter value" pair before
10016 the arguments string is parsed by the parse_exp_1 function. */
10023 /* Parse the rest of the arguments. From here on out, everything
10024 is in terms of a newly allocated string instead of the original
10026 std::string
expression (arg
, exp_end
- arg
);
10027 exp_start
= arg
= expression
.c_str ();
10028 innermost_block_tracker tracker
;
10029 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10031 /* Remove trailing whitespace from the expression before saving it.
10032 This makes the eventual display of the expression string a bit
10034 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10037 /* Checking if the expression is not constant. */
10038 if (watchpoint_exp_is_const (exp
.get ()))
10042 len
= exp_end
- exp_start
;
10043 while (len
> 0 && isspace (exp_start
[len
- 1]))
10045 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10048 exp_valid_block
= tracker
.block ();
10049 struct value
*mark
= value_mark ();
10050 struct value
*val_as_value
= nullptr;
10051 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10054 if (val_as_value
!= NULL
&& just_location
)
10056 saved_bitpos
= value_bitpos (val_as_value
);
10057 saved_bitsize
= value_bitsize (val_as_value
);
10065 exp_valid_block
= NULL
;
10066 val
= release_value (value_addr (result
));
10067 value_free_to_mark (mark
);
10071 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10074 error (_("This target does not support masked watchpoints."));
10075 else if (ret
== -2)
10076 error (_("Invalid mask or memory region."));
10079 else if (val_as_value
!= NULL
)
10080 val
= release_value (val_as_value
);
10082 tok
= skip_spaces (arg
);
10083 end_tok
= skip_to_space (tok
);
10085 toklen
= end_tok
- tok
;
10086 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10088 tok
= cond_start
= end_tok
+ 1;
10089 innermost_block_tracker if_tracker
;
10090 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10092 /* The watchpoint expression may not be local, but the condition
10093 may still be. E.g.: `watch global if local > 0'. */
10094 cond_exp_valid_block
= if_tracker
.block ();
10099 error (_("Junk at end of command."));
10101 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10103 /* Save this because create_internal_breakpoint below invalidates
10105 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10107 /* If the expression is "local", then set up a "watchpoint scope"
10108 breakpoint at the point where we've left the scope of the watchpoint
10109 expression. Create the scope breakpoint before the watchpoint, so
10110 that we will encounter it first in bpstat_stop_status. */
10111 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10113 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10115 if (frame_id_p (caller_frame_id
))
10117 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10118 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10121 = create_internal_breakpoint (caller_arch
, caller_pc
,
10122 bp_watchpoint_scope
);
10124 /* create_internal_breakpoint could invalidate WP_FRAME. */
10127 scope_breakpoint
->enable_state
= bp_enabled
;
10129 /* Automatically delete the breakpoint when it hits. */
10130 scope_breakpoint
->disposition
= disp_del
;
10132 /* Only break in the proper frame (help with recursion). */
10133 scope_breakpoint
->frame_id
= caller_frame_id
;
10135 /* Set the address at which we will stop. */
10136 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10137 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10138 scope_breakpoint
->loc
->address
10139 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10140 scope_breakpoint
->loc
->requested_address
,
10141 scope_breakpoint
->type
);
10145 /* Now set up the breakpoint. We create all watchpoints as hardware
10146 watchpoints here even if hardware watchpoints are turned off, a call
10147 to update_watchpoint later in this function will cause the type to
10148 drop back to bp_watchpoint (software watchpoint) if required. */
10150 if (accessflag
== hw_read
)
10151 bp_type
= bp_read_watchpoint
;
10152 else if (accessflag
== hw_access
)
10153 bp_type
= bp_access_watchpoint
;
10155 bp_type
= bp_hardware_watchpoint
;
10157 std::unique_ptr
<watchpoint
> w
;
10159 w
.reset (new masked_watchpoint (nullptr, bp_type
));
10161 w
.reset (new watchpoint (nullptr, bp_type
));
10163 w
->thread
= thread
;
10165 w
->disposition
= disp_donttouch
;
10166 w
->pspace
= current_program_space
;
10167 w
->exp
= std::move (exp
);
10168 w
->exp_valid_block
= exp_valid_block
;
10169 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10172 struct type
*t
= value_type (val
.get ());
10173 CORE_ADDR addr
= value_as_address (val
.get ());
10175 w
->exp_string_reparse
10176 = current_language
->watch_location_expression (t
, addr
);
10178 w
->exp_string
= xstrprintf ("-location %.*s",
10179 (int) (exp_end
- exp_start
), exp_start
);
10182 w
->exp_string
.reset (savestring (exp_start
, exp_end
- exp_start
));
10186 w
->hw_wp_mask
= mask
;
10191 w
->val_bitpos
= saved_bitpos
;
10192 w
->val_bitsize
= saved_bitsize
;
10193 w
->val_valid
= true;
10197 w
->cond_string
.reset (savestring (cond_start
, cond_end
- cond_start
));
10199 w
->cond_string
= 0;
10201 if (frame_id_p (watchpoint_frame
))
10203 w
->watchpoint_frame
= watchpoint_frame
;
10204 w
->watchpoint_thread
= inferior_ptid
;
10208 w
->watchpoint_frame
= null_frame_id
;
10209 w
->watchpoint_thread
= null_ptid
;
10212 if (scope_breakpoint
!= NULL
)
10214 /* The scope breakpoint is related to the watchpoint. We will
10215 need to act on them together. */
10216 w
->related_breakpoint
= scope_breakpoint
;
10217 scope_breakpoint
->related_breakpoint
= w
.get ();
10220 if (!just_location
)
10221 value_free_to_mark (mark
);
10223 /* Finally update the new watchpoint. This creates the locations
10224 that should be inserted. */
10225 update_watchpoint (w
.get (), 1);
10227 install_breakpoint (internal
, std::move (w
), 1);
10230 /* Return count of debug registers needed to watch the given expression.
10231 If the watchpoint cannot be handled in hardware return zero. */
10234 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10236 int found_memory_cnt
= 0;
10238 /* Did the user specifically forbid us to use hardware watchpoints? */
10239 if (!can_use_hw_watchpoints
)
10242 gdb_assert (!vals
.empty ());
10243 struct value
*head
= vals
[0].get ();
10245 /* Make sure that the value of the expression depends only upon
10246 memory contents, and values computed from them within GDB. If we
10247 find any register references or function calls, we can't use a
10248 hardware watchpoint.
10250 The idea here is that evaluating an expression generates a series
10251 of values, one holding the value of every subexpression. (The
10252 expression a*b+c has five subexpressions: a, b, a*b, c, and
10253 a*b+c.) GDB's values hold almost enough information to establish
10254 the criteria given above --- they identify memory lvalues,
10255 register lvalues, computed values, etcetera. So we can evaluate
10256 the expression, and then scan the chain of values that leaves
10257 behind to decide whether we can detect any possible change to the
10258 expression's final value using only hardware watchpoints.
10260 However, I don't think that the values returned by inferior
10261 function calls are special in any way. So this function may not
10262 notice that an expression involving an inferior function call
10263 can't be watched with hardware watchpoints. FIXME. */
10264 for (const value_ref_ptr
&iter
: vals
)
10266 struct value
*v
= iter
.get ();
10268 if (VALUE_LVAL (v
) == lval_memory
)
10270 if (v
!= head
&& value_lazy (v
))
10271 /* A lazy memory lvalue in the chain is one that GDB never
10272 needed to fetch; we either just used its address (e.g.,
10273 `a' in `a.b') or we never needed it at all (e.g., `a'
10274 in `a,b'). This doesn't apply to HEAD; if that is
10275 lazy then it was not readable, but watch it anyway. */
10279 /* Ahh, memory we actually used! Check if we can cover
10280 it with hardware watchpoints. */
10281 struct type
*vtype
= check_typedef (value_type (v
));
10283 /* We only watch structs and arrays if user asked for it
10284 explicitly, never if they just happen to appear in a
10285 middle of some value chain. */
10287 || (vtype
->code () != TYPE_CODE_STRUCT
10288 && vtype
->code () != TYPE_CODE_ARRAY
))
10290 CORE_ADDR vaddr
= value_address (v
);
10294 len
= (target_exact_watchpoints
10295 && is_scalar_type_recursive (vtype
))?
10296 1 : TYPE_LENGTH (value_type (v
));
10298 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10302 found_memory_cnt
+= num_regs
;
10306 else if (VALUE_LVAL (v
) != not_lval
10307 && deprecated_value_modifiable (v
) == 0)
10308 return 0; /* These are values from the history (e.g., $1). */
10309 else if (VALUE_LVAL (v
) == lval_register
)
10310 return 0; /* Cannot watch a register with a HW watchpoint. */
10313 /* The expression itself looks suitable for using a hardware
10314 watchpoint, but give the target machine a chance to reject it. */
10315 return found_memory_cnt
;
10319 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10321 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10324 /* Options for the watch, awatch, and rwatch commands. */
10326 struct watch_options
10328 /* For -location. */
10329 bool location
= false;
10332 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10334 Historically GDB always accepted both '-location' and '-l' flags for
10335 these commands (both flags being synonyms). When converting to the
10336 newer option scheme only '-location' is added here. That's fine (for
10337 backward compatibility) as any non-ambiguous prefix of a flag will be
10338 accepted, so '-l', '-loc', are now all accepted.
10340 What this means is that, if in the future, we add any new flag here
10341 that starts with '-l' then this will break backward compatibility, so
10342 please, don't do that! */
10344 static const gdb::option::option_def watch_option_defs
[] = {
10345 gdb::option::flag_option_def
<watch_options
> {
10347 [] (watch_options
*opt
) { return &opt
->location
; },
10349 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10350 -l can be used as a short form of -location."),
10354 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10357 static gdb::option::option_def_group
10358 make_watch_options_def_group (watch_options
*opts
)
10360 return {{watch_option_defs
}, opts
};
10363 /* A helper function that looks for the "-location" argument and then
10364 calls watch_command_1. */
10367 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10369 watch_options opts
;
10370 auto grp
= make_watch_options_def_group (&opts
);
10371 gdb::option::process_options
10372 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
10373 if (arg
!= nullptr && *arg
== '\0')
10376 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
10379 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10381 watch_command_completer (struct cmd_list_element
*ignore
,
10382 completion_tracker
&tracker
,
10383 const char *text
, const char * /*word*/)
10385 const auto group
= make_watch_options_def_group (nullptr);
10386 if (gdb::option::complete_options
10387 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
10390 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
10391 expression_completer (ignore
, tracker
, text
, word
);
10395 watch_command (const char *arg
, int from_tty
)
10397 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10401 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10403 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10407 rwatch_command (const char *arg
, int from_tty
)
10409 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10413 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10415 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10419 awatch_command (const char *arg
, int from_tty
)
10421 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10425 /* Data for the FSM that manages the until(location)/advance commands
10426 in infcmd.c. Here because it uses the mechanisms of
10429 struct until_break_fsm
: public thread_fsm
10431 /* The thread that was current when the command was executed. */
10434 /* The breakpoint set at the return address in the caller frame,
10435 plus breakpoints at all the destination locations. */
10436 std::vector
<breakpoint_up
> breakpoints
;
10438 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10439 std::vector
<breakpoint_up
> &&breakpoints
)
10440 : thread_fsm (cmd_interp
),
10442 breakpoints (std::move (breakpoints
))
10446 void clean_up (struct thread_info
*thread
) override
;
10447 bool should_stop (struct thread_info
*thread
) override
;
10448 enum async_reply_reason
do_async_reply_reason () override
;
10451 /* Implementation of the 'should_stop' FSM method for the
10452 until(location)/advance commands. */
10455 until_break_fsm::should_stop (struct thread_info
*tp
)
10457 for (const breakpoint_up
&bp
: breakpoints
)
10458 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10459 bp
.get ()) != NULL
)
10468 /* Implementation of the 'clean_up' FSM method for the
10469 until(location)/advance commands. */
10472 until_break_fsm::clean_up (struct thread_info
*)
10474 /* Clean up our temporary breakpoints. */
10475 breakpoints
.clear ();
10476 delete_longjmp_breakpoint (thread
);
10479 /* Implementation of the 'async_reply_reason' FSM method for the
10480 until(location)/advance commands. */
10482 enum async_reply_reason
10483 until_break_fsm::do_async_reply_reason ()
10485 return EXEC_ASYNC_LOCATION_REACHED
;
10489 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10491 struct frame_info
*frame
;
10492 struct gdbarch
*frame_gdbarch
;
10493 struct frame_id stack_frame_id
;
10494 struct frame_id caller_frame_id
;
10496 struct thread_info
*tp
;
10498 clear_proceed_status (0);
10500 /* Set a breakpoint where the user wants it and at return from
10503 event_location_up location
= string_to_event_location (&arg
, current_language
);
10505 std::vector
<symtab_and_line
> sals
10506 = (last_displayed_sal_is_valid ()
10507 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10508 get_last_displayed_symtab (),
10509 get_last_displayed_line ())
10510 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
10514 error (_("Couldn't get information on specified line."));
10517 error (_("Junk at end of arguments."));
10519 tp
= inferior_thread ();
10520 thread
= tp
->global_num
;
10522 /* Note linespec handling above invalidates the frame chain.
10523 Installing a breakpoint also invalidates the frame chain (as it
10524 may need to switch threads), so do any frame handling before
10527 frame
= get_selected_frame (NULL
);
10528 frame_gdbarch
= get_frame_arch (frame
);
10529 stack_frame_id
= get_stack_frame_id (frame
);
10530 caller_frame_id
= frame_unwind_caller_id (frame
);
10532 /* Keep within the current frame, or in frames called by the current
10535 std::vector
<breakpoint_up
> breakpoints
;
10537 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
10539 if (frame_id_p (caller_frame_id
))
10541 struct symtab_and_line sal2
;
10542 struct gdbarch
*caller_gdbarch
;
10544 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10545 sal2
.pc
= frame_unwind_caller_pc (frame
);
10546 caller_gdbarch
= frame_unwind_caller_arch (frame
);
10548 breakpoint_up caller_breakpoint
10549 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
10550 caller_frame_id
, bp_until
);
10551 breakpoints
.emplace_back (std::move (caller_breakpoint
));
10553 set_longjmp_breakpoint (tp
, caller_frame_id
);
10554 lj_deleter
.emplace (thread
);
10557 /* set_momentary_breakpoint could invalidate FRAME. */
10560 /* If the user told us to continue until a specified location, we
10561 don't specify a frame at which we need to stop. Otherwise,
10562 specify the selected frame, because we want to stop only at the
10563 very same frame. */
10564 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
10566 for (symtab_and_line
&sal
: sals
)
10568 resolve_sal_pc (&sal
);
10570 breakpoint_up location_breakpoint
10571 = set_momentary_breakpoint (frame_gdbarch
, sal
,
10572 stop_frame_id
, bp_until
);
10573 breakpoints
.emplace_back (std::move (location_breakpoint
));
10577 (std::unique_ptr
<thread_fsm
>
10578 (new until_break_fsm (command_interp (), tp
->global_num
,
10579 std::move (breakpoints
))));
10582 lj_deleter
->release ();
10584 proceed (-1, GDB_SIGNAL_DEFAULT
);
10588 init_ada_exception_breakpoint (struct breakpoint
*b
,
10589 struct gdbarch
*gdbarch
,
10590 struct symtab_and_line sal
,
10591 const char *addr_string
,
10598 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
10600 loc_gdbarch
= gdbarch
;
10602 describe_other_breakpoints (loc_gdbarch
,
10603 sal
.pspace
, sal
.pc
, sal
.section
, -1);
10604 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10605 version for exception catchpoints, because two catchpoints
10606 used for different exception names will use the same address.
10607 In this case, a "breakpoint ... also set at..." warning is
10608 unproductive. Besides, the warning phrasing is also a bit
10609 inappropriate, we should use the word catchpoint, and tell
10610 the user what type of catchpoint it is. The above is good
10611 enough for now, though. */
10614 init_raw_breakpoint (b
, sal
, bp_catchpoint
);
10616 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
10617 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10618 b
->location
= string_to_event_location (&addr_string
,
10619 language_def (language_ada
));
10620 b
->language
= language_ada
;
10625 /* Compare two breakpoints and return a strcmp-like result. */
10628 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
10630 uintptr_t ua
= (uintptr_t) a
;
10631 uintptr_t ub
= (uintptr_t) b
;
10633 if (a
->number
< b
->number
)
10635 else if (a
->number
> b
->number
)
10638 /* Now sort by address, in case we see, e..g, two breakpoints with
10642 return ua
> ub
? 1 : 0;
10645 /* Delete breakpoints by address or line. */
10648 clear_command (const char *arg
, int from_tty
)
10652 std::vector
<symtab_and_line
> decoded_sals
;
10653 symtab_and_line last_sal
;
10654 gdb::array_view
<symtab_and_line
> sals
;
10658 = decode_line_with_current_source (arg
,
10659 (DECODE_LINE_FUNFIRSTLINE
10660 | DECODE_LINE_LIST_MODE
));
10662 sals
= decoded_sals
;
10666 /* Set sal's line, symtab, pc, and pspace to the values
10667 corresponding to the last call to print_frame_info. If the
10668 codepoint is not valid, this will set all the fields to 0. */
10669 last_sal
= get_last_displayed_sal ();
10670 if (last_sal
.symtab
== 0)
10671 error (_("No source file specified."));
10677 /* We don't call resolve_sal_pc here. That's not as bad as it
10678 seems, because all existing breakpoints typically have both
10679 file/line and pc set. So, if clear is given file/line, we can
10680 match this to existing breakpoint without obtaining pc at all.
10682 We only support clearing given the address explicitly
10683 present in breakpoint table. Say, we've set breakpoint
10684 at file:line. There were several PC values for that file:line,
10685 due to optimization, all in one block.
10687 We've picked one PC value. If "clear" is issued with another
10688 PC corresponding to the same file:line, the breakpoint won't
10689 be cleared. We probably can still clear the breakpoint, but
10690 since the other PC value is never presented to user, user
10691 can only find it by guessing, and it does not seem important
10692 to support that. */
10694 /* For each line spec given, delete bps which correspond to it. Do
10695 it in two passes, solely to preserve the current behavior that
10696 from_tty is forced true if we delete more than one
10699 std::vector
<struct breakpoint
*> found
;
10700 for (const auto &sal
: sals
)
10702 const char *sal_fullname
;
10704 /* If exact pc given, clear bpts at that pc.
10705 If line given (pc == 0), clear all bpts on specified line.
10706 If defaulting, clear all bpts on default line
10709 defaulting sal.pc != 0 tests to do
10714 1 0 <can't happen> */
10716 sal_fullname
= (sal
.symtab
== NULL
10717 ? NULL
: symtab_to_fullname (sal
.symtab
));
10719 /* Find all matching breakpoints and add them to 'found'. */
10720 for (breakpoint
*b
: all_breakpoints ())
10723 /* Are we going to delete b? */
10724 if (b
->type
!= bp_none
&& !is_watchpoint (b
)
10725 && user_breakpoint_p (b
))
10727 for (bp_location
*loc
: b
->locations ())
10729 /* If the user specified file:line, don't allow a PC
10730 match. This matches historical gdb behavior. */
10731 int pc_match
= (!sal
.explicit_line
10733 && (loc
->pspace
== sal
.pspace
)
10734 && (loc
->address
== sal
.pc
)
10735 && (!section_is_overlay (loc
->section
)
10736 || loc
->section
== sal
.section
));
10737 int line_match
= 0;
10739 if ((default_match
|| sal
.explicit_line
)
10740 && loc
->symtab
!= NULL
10741 && sal_fullname
!= NULL
10742 && sal
.pspace
== loc
->pspace
10743 && loc
->line_number
== sal
.line
10744 && filename_cmp (symtab_to_fullname (loc
->symtab
),
10745 sal_fullname
) == 0)
10748 if (pc_match
|| line_match
)
10757 found
.push_back (b
);
10761 /* Now go thru the 'found' chain and delete them. */
10762 if (found
.empty ())
10765 error (_("No breakpoint at %s."), arg
);
10767 error (_("No breakpoint at this line."));
10770 /* Remove duplicates from the vec. */
10771 std::sort (found
.begin (), found
.end (),
10772 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10774 return compare_breakpoints (bp_a
, bp_b
) < 0;
10776 found
.erase (std::unique (found
.begin (), found
.end (),
10777 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10779 return compare_breakpoints (bp_a
, bp_b
) == 0;
10783 if (found
.size () > 1)
10784 from_tty
= 1; /* Always report if deleted more than one. */
10787 if (found
.size () == 1)
10788 gdb_printf (_("Deleted breakpoint "));
10790 gdb_printf (_("Deleted breakpoints "));
10793 for (breakpoint
*iter
: found
)
10796 gdb_printf ("%d ", iter
->number
);
10797 delete_breakpoint (iter
);
10803 /* Delete breakpoint in BS if they are `delete' breakpoints and
10804 all breakpoints that are marked for deletion, whether hit or not.
10805 This is called after any breakpoint is hit, or after errors. */
10808 breakpoint_auto_delete (bpstat
*bs
)
10810 for (; bs
; bs
= bs
->next
)
10811 if (bs
->breakpoint_at
10812 && bs
->breakpoint_at
->disposition
== disp_del
10814 delete_breakpoint (bs
->breakpoint_at
);
10816 for (breakpoint
*b
: all_breakpoints_safe ())
10817 if (b
->disposition
== disp_del_at_next_stop
)
10818 delete_breakpoint (b
);
10821 /* A comparison function for bp_location AP and BP being interfaced to
10822 std::sort. Sort elements primarily by their ADDRESS (no matter what
10823 bl_address_is_meaningful says), secondarily by ordering first
10824 permanent elements and terciarily just ensuring the array is sorted
10825 stable way despite std::sort being an unstable algorithm. */
10828 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
10830 if (a
->address
!= b
->address
)
10831 return a
->address
< b
->address
;
10833 /* Sort locations at the same address by their pspace number, keeping
10834 locations of the same inferior (in a multi-inferior environment)
10837 if (a
->pspace
->num
!= b
->pspace
->num
)
10838 return a
->pspace
->num
< b
->pspace
->num
;
10840 /* Sort permanent breakpoints first. */
10841 if (a
->permanent
!= b
->permanent
)
10842 return a
->permanent
> b
->permanent
;
10844 /* Sort by type in order to make duplicate determination easier.
10845 See update_global_location_list. This is kept in sync with
10846 breakpoint_locations_match. */
10847 if (a
->loc_type
< b
->loc_type
)
10850 /* Likewise, for range-breakpoints, sort by length. */
10851 if (a
->loc_type
== bp_loc_hardware_breakpoint
10852 && b
->loc_type
== bp_loc_hardware_breakpoint
10853 && a
->length
< b
->length
)
10856 /* Make the internal GDB representation stable across GDB runs
10857 where A and B memory inside GDB can differ. Breakpoint locations of
10858 the same type at the same address can be sorted in arbitrary order. */
10860 if (a
->owner
->number
!= b
->owner
->number
)
10861 return a
->owner
->number
< b
->owner
->number
;
10866 /* Set bp_locations_placed_address_before_address_max and
10867 bp_locations_shadow_len_after_address_max according to the current
10868 content of the bp_locations array. */
10871 bp_locations_target_extensions_update (void)
10873 bp_locations_placed_address_before_address_max
= 0;
10874 bp_locations_shadow_len_after_address_max
= 0;
10876 for (bp_location
*bl
: all_bp_locations ())
10878 CORE_ADDR start
, end
, addr
;
10880 if (!bp_location_has_shadow (bl
))
10883 start
= bl
->target_info
.placed_address
;
10884 end
= start
+ bl
->target_info
.shadow_len
;
10886 gdb_assert (bl
->address
>= start
);
10887 addr
= bl
->address
- start
;
10888 if (addr
> bp_locations_placed_address_before_address_max
)
10889 bp_locations_placed_address_before_address_max
= addr
;
10891 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10893 gdb_assert (bl
->address
< end
);
10894 addr
= end
- bl
->address
;
10895 if (addr
> bp_locations_shadow_len_after_address_max
)
10896 bp_locations_shadow_len_after_address_max
= addr
;
10900 /* Download tracepoint locations if they haven't been. */
10903 download_tracepoint_locations (void)
10905 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
10907 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
10909 for (breakpoint
*b
: all_tracepoints ())
10911 struct tracepoint
*t
;
10912 int bp_location_downloaded
= 0;
10914 if ((b
->type
== bp_fast_tracepoint
10915 ? !may_insert_fast_tracepoints
10916 : !may_insert_tracepoints
))
10919 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
10921 if (target_can_download_tracepoint ())
10922 can_download_tracepoint
= TRIBOOL_TRUE
;
10924 can_download_tracepoint
= TRIBOOL_FALSE
;
10927 if (can_download_tracepoint
== TRIBOOL_FALSE
)
10930 for (bp_location
*bl
: b
->locations ())
10932 /* In tracepoint, locations are _never_ duplicated, so
10933 should_be_inserted is equivalent to
10934 unduplicated_should_be_inserted. */
10935 if (!should_be_inserted (bl
) || bl
->inserted
)
10938 switch_to_program_space_and_thread (bl
->pspace
);
10940 target_download_tracepoint (bl
);
10943 bp_location_downloaded
= 1;
10945 t
= (struct tracepoint
*) b
;
10946 t
->number_on_target
= b
->number
;
10947 if (bp_location_downloaded
)
10948 gdb::observers::breakpoint_modified
.notify (b
);
10952 /* Swap the insertion/duplication state between two locations. */
10955 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10957 const int left_inserted
= left
->inserted
;
10958 const int left_duplicate
= left
->duplicate
;
10959 const int left_needs_update
= left
->needs_update
;
10960 const struct bp_target_info left_target_info
= left
->target_info
;
10962 /* Locations of tracepoints can never be duplicated. */
10963 if (is_tracepoint (left
->owner
))
10964 gdb_assert (!left
->duplicate
);
10965 if (is_tracepoint (right
->owner
))
10966 gdb_assert (!right
->duplicate
);
10968 left
->inserted
= right
->inserted
;
10969 left
->duplicate
= right
->duplicate
;
10970 left
->needs_update
= right
->needs_update
;
10971 left
->target_info
= right
->target_info
;
10972 right
->inserted
= left_inserted
;
10973 right
->duplicate
= left_duplicate
;
10974 right
->needs_update
= left_needs_update
;
10975 right
->target_info
= left_target_info
;
10978 /* Force the re-insertion of the locations at ADDRESS. This is called
10979 once a new/deleted/modified duplicate location is found and we are evaluating
10980 conditions on the target's side. Such conditions need to be updated on
10984 force_breakpoint_reinsertion (struct bp_location
*bl
)
10986 CORE_ADDR address
= 0;
10989 address
= bl
->address
;
10990 pspace_num
= bl
->pspace
->num
;
10992 /* This is only meaningful if the target is
10993 evaluating conditions and if the user has
10994 opted for condition evaluation on the target's
10996 if (gdb_evaluates_breakpoint_condition_p ()
10997 || !target_supports_evaluation_of_breakpoint_conditions ())
11000 /* Flag all breakpoint locations with this address and
11001 the same program space as the location
11002 as "its condition has changed". We need to
11003 update the conditions on the target's side. */
11004 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
11006 if (!is_breakpoint (loc
->owner
)
11007 || pspace_num
!= loc
->pspace
->num
)
11010 /* Flag the location appropriately. We use a different state to
11011 let everyone know that we already updated the set of locations
11012 with addr bl->address and program space bl->pspace. This is so
11013 we don't have to keep calling these functions just to mark locations
11014 that have already been marked. */
11015 loc
->condition_changed
= condition_updated
;
11017 /* Free the agent expression bytecode as well. We will compute
11019 loc
->cond_bytecode
.reset ();
11023 /* Called whether new breakpoints are created, or existing breakpoints
11024 deleted, to update the global location list and recompute which
11025 locations are duplicate of which.
11027 The INSERT_MODE flag determines whether locations may not, may, or
11028 shall be inserted now. See 'enum ugll_insert_mode' for more
11032 update_global_location_list (enum ugll_insert_mode insert_mode
)
11034 /* Last breakpoint location address that was marked for update. */
11035 CORE_ADDR last_addr
= 0;
11036 /* Last breakpoint location program space that was marked for update. */
11037 int last_pspace_num
= -1;
11039 /* Used in the duplicates detection below. When iterating over all
11040 bp_locations, points to the first bp_location of a given address.
11041 Breakpoints and watchpoints of different types are never
11042 duplicates of each other. Keep one pointer for each type of
11043 breakpoint/watchpoint, so we only need to loop over all locations
11045 struct bp_location
*bp_loc_first
; /* breakpoint */
11046 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11047 struct bp_location
*awp_loc_first
; /* access watchpoint */
11048 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11050 /* Saved former bp_locations array which we compare against the newly
11051 built bp_locations from the current state of ALL_BREAKPOINTS. */
11052 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
11053 bp_locations
.clear ();
11055 for (breakpoint
*b
: all_breakpoints ())
11056 for (bp_location
*loc
: b
->locations ())
11057 bp_locations
.push_back (loc
);
11059 /* See if we need to "upgrade" a software breakpoint to a hardware
11060 breakpoint. Do this before deciding whether locations are
11061 duplicates. Also do this before sorting because sorting order
11062 depends on location type. */
11063 for (bp_location
*loc
: bp_locations
)
11064 if (!loc
->inserted
&& should_be_inserted (loc
))
11065 handle_automatic_hardware_breakpoints (loc
);
11067 std::sort (bp_locations
.begin (), bp_locations
.end (),
11068 bp_location_is_less_than
);
11070 bp_locations_target_extensions_update ();
11072 /* Identify bp_location instances that are no longer present in the
11073 new list, and therefore should be freed. Note that it's not
11074 necessary that those locations should be removed from inferior --
11075 if there's another location at the same address (previously
11076 marked as duplicate), we don't need to remove/insert the
11079 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11080 and former bp_location array state respectively. */
11083 for (bp_location
*old_loc
: old_locations
)
11085 /* Tells if 'old_loc' is found among the new locations. If
11086 not, we have to free it. */
11087 int found_object
= 0;
11088 /* Tells if the location should remain inserted in the target. */
11089 int keep_in_target
= 0;
11092 /* Skip LOCP entries which will definitely never be needed.
11093 Stop either at or being the one matching OLD_LOC. */
11094 while (loc_i
< bp_locations
.size ()
11095 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11098 for (size_t loc2_i
= loc_i
;
11099 (loc2_i
< bp_locations
.size ()
11100 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11103 /* Check if this is a new/duplicated location or a duplicated
11104 location that had its condition modified. If so, we want to send
11105 its condition to the target if evaluation of conditions is taking
11107 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11108 && (last_addr
!= old_loc
->address
11109 || last_pspace_num
!= old_loc
->pspace
->num
))
11111 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11112 last_pspace_num
= old_loc
->pspace
->num
;
11115 if (bp_locations
[loc2_i
] == old_loc
)
11119 /* We have already handled this address, update it so that we don't
11120 have to go through updates again. */
11121 last_addr
= old_loc
->address
;
11123 /* Target-side condition evaluation: Handle deleted locations. */
11125 force_breakpoint_reinsertion (old_loc
);
11127 /* If this location is no longer present, and inserted, look if
11128 there's maybe a new location at the same address. If so,
11129 mark that one inserted, and don't remove this one. This is
11130 needed so that we don't have a time window where a breakpoint
11131 at certain location is not inserted. */
11133 if (old_loc
->inserted
)
11135 /* If the location is inserted now, we might have to remove
11138 if (found_object
&& should_be_inserted (old_loc
))
11140 /* The location is still present in the location list,
11141 and still should be inserted. Don't do anything. */
11142 keep_in_target
= 1;
11146 /* This location still exists, but it won't be kept in the
11147 target since it may have been disabled. We proceed to
11148 remove its target-side condition. */
11150 /* The location is either no longer present, or got
11151 disabled. See if there's another location at the
11152 same address, in which case we don't need to remove
11153 this one from the target. */
11155 /* OLD_LOC comes from existing struct breakpoint. */
11156 if (bl_address_is_meaningful (old_loc
))
11158 for (size_t loc2_i
= loc_i
;
11159 (loc2_i
< bp_locations
.size ()
11160 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11163 bp_location
*loc2
= bp_locations
[loc2_i
];
11165 if (loc2
== old_loc
)
11168 if (breakpoint_locations_match (loc2
, old_loc
))
11170 /* Read watchpoint locations are switched to
11171 access watchpoints, if the former are not
11172 supported, but the latter are. */
11173 if (is_hardware_watchpoint (old_loc
->owner
))
11175 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11176 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11179 /* loc2 is a duplicated location. We need to check
11180 if it should be inserted in case it will be
11182 if (unduplicated_should_be_inserted (loc2
))
11184 swap_insertion (old_loc
, loc2
);
11185 keep_in_target
= 1;
11193 if (!keep_in_target
)
11195 if (remove_breakpoint (old_loc
))
11197 /* This is just about all we can do. We could keep
11198 this location on the global list, and try to
11199 remove it next time, but there's no particular
11200 reason why we will succeed next time.
11202 Note that at this point, old_loc->owner is still
11203 valid, as delete_breakpoint frees the breakpoint
11204 only after calling us. */
11205 gdb_printf (_("warning: Error removing "
11206 "breakpoint %d\n"),
11207 old_loc
->owner
->number
);
11215 if (removed
&& target_is_non_stop_p ()
11216 && need_moribund_for_location_type (old_loc
))
11218 /* This location was removed from the target. In
11219 non-stop mode, a race condition is possible where
11220 we've removed a breakpoint, but stop events for that
11221 breakpoint are already queued and will arrive later.
11222 We apply an heuristic to be able to distinguish such
11223 SIGTRAPs from other random SIGTRAPs: we keep this
11224 breakpoint location for a bit, and will retire it
11225 after we see some number of events. The theory here
11226 is that reporting of events should, "on the average",
11227 be fair, so after a while we'll see events from all
11228 threads that have anything of interest, and no longer
11229 need to keep this breakpoint location around. We
11230 don't hold locations forever so to reduce chances of
11231 mistaking a non-breakpoint SIGTRAP for a breakpoint
11234 The heuristic failing can be disastrous on
11235 decr_pc_after_break targets.
11237 On decr_pc_after_break targets, like e.g., x86-linux,
11238 if we fail to recognize a late breakpoint SIGTRAP,
11239 because events_till_retirement has reached 0 too
11240 soon, we'll fail to do the PC adjustment, and report
11241 a random SIGTRAP to the user. When the user resumes
11242 the inferior, it will most likely immediately crash
11243 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11244 corrupted, because of being resumed e.g., in the
11245 middle of a multi-byte instruction, or skipped a
11246 one-byte instruction. This was actually seen happen
11247 on native x86-linux, and should be less rare on
11248 targets that do not support new thread events, like
11249 remote, due to the heuristic depending on
11252 Mistaking a random SIGTRAP for a breakpoint trap
11253 causes similar symptoms (PC adjustment applied when
11254 it shouldn't), but then again, playing with SIGTRAPs
11255 behind the debugger's back is asking for trouble.
11257 Since hardware watchpoint traps are always
11258 distinguishable from other traps, so we don't need to
11259 apply keep hardware watchpoint moribund locations
11260 around. We simply always ignore hardware watchpoint
11261 traps we can no longer explain. */
11263 process_stratum_target
*proc_target
= nullptr;
11264 for (inferior
*inf
: all_inferiors ())
11265 if (inf
->pspace
== old_loc
->pspace
)
11267 proc_target
= inf
->process_target ();
11270 if (proc_target
!= nullptr)
11271 old_loc
->events_till_retirement
11272 = 3 * (thread_count (proc_target
) + 1);
11274 old_loc
->events_till_retirement
= 1;
11275 old_loc
->owner
= NULL
;
11277 moribund_locations
.push_back (old_loc
);
11281 old_loc
->owner
= NULL
;
11282 decref_bp_location (&old_loc
);
11287 /* Rescan breakpoints at the same address and section, marking the
11288 first one as "first" and any others as "duplicates". This is so
11289 that the bpt instruction is only inserted once. If we have a
11290 permanent breakpoint at the same place as BPT, make that one the
11291 official one, and the rest as duplicates. Permanent breakpoints
11292 are sorted first for the same address.
11294 Do the same for hardware watchpoints, but also considering the
11295 watchpoint's type (regular/access/read) and length. */
11297 bp_loc_first
= NULL
;
11298 wp_loc_first
= NULL
;
11299 awp_loc_first
= NULL
;
11300 rwp_loc_first
= NULL
;
11302 for (bp_location
*loc
: all_bp_locations ())
11304 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11306 struct bp_location
**loc_first_p
;
11307 breakpoint
*b
= loc
->owner
;
11309 if (!unduplicated_should_be_inserted (loc
)
11310 || !bl_address_is_meaningful (loc
)
11311 /* Don't detect duplicate for tracepoint locations because they are
11312 never duplicated. See the comments in field `duplicate' of
11313 `struct bp_location'. */
11314 || is_tracepoint (b
))
11316 /* Clear the condition modification flag. */
11317 loc
->condition_changed
= condition_unchanged
;
11321 if (b
->type
== bp_hardware_watchpoint
)
11322 loc_first_p
= &wp_loc_first
;
11323 else if (b
->type
== bp_read_watchpoint
)
11324 loc_first_p
= &rwp_loc_first
;
11325 else if (b
->type
== bp_access_watchpoint
)
11326 loc_first_p
= &awp_loc_first
;
11328 loc_first_p
= &bp_loc_first
;
11330 if (*loc_first_p
== NULL
11331 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11332 || !breakpoint_locations_match (loc
, *loc_first_p
))
11334 *loc_first_p
= loc
;
11335 loc
->duplicate
= 0;
11337 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11339 loc
->needs_update
= 1;
11340 /* Clear the condition modification flag. */
11341 loc
->condition_changed
= condition_unchanged
;
11347 /* This and the above ensure the invariant that the first location
11348 is not duplicated, and is the inserted one.
11349 All following are marked as duplicated, and are not inserted. */
11351 swap_insertion (loc
, *loc_first_p
);
11352 loc
->duplicate
= 1;
11354 /* Clear the condition modification flag. */
11355 loc
->condition_changed
= condition_unchanged
;
11358 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11360 if (insert_mode
!= UGLL_DONT_INSERT
)
11361 insert_breakpoint_locations ();
11364 /* Even though the caller told us to not insert new
11365 locations, we may still need to update conditions on the
11366 target's side of breakpoints that were already inserted
11367 if the target is evaluating breakpoint conditions. We
11368 only update conditions for locations that are marked
11370 update_inserted_breakpoint_locations ();
11374 if (insert_mode
!= UGLL_DONT_INSERT
)
11375 download_tracepoint_locations ();
11379 breakpoint_retire_moribund (void)
11381 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11383 struct bp_location
*loc
= moribund_locations
[ix
];
11384 if (--(loc
->events_till_retirement
) == 0)
11386 decref_bp_location (&loc
);
11387 unordered_remove (moribund_locations
, ix
);
11394 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
11399 update_global_location_list (insert_mode
);
11401 catch (const gdb_exception_error
&e
)
11406 /* Clear BKP from a BPS. */
11409 bpstat_remove_bp_location (bpstat
*bps
, struct breakpoint
*bpt
)
11413 for (bs
= bps
; bs
; bs
= bs
->next
)
11414 if (bs
->breakpoint_at
== bpt
)
11416 bs
->breakpoint_at
= NULL
;
11417 bs
->old_val
= NULL
;
11418 /* bs->commands will be freed later. */
11422 /* Callback for iterate_over_threads. */
11424 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11426 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
11428 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11432 /* Helper for breakpoint and tracepoint breakpoint->mention
11436 say_where (const breakpoint
*b
)
11438 struct value_print_options opts
;
11440 get_user_print_options (&opts
);
11442 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11444 if (b
->loc
== NULL
)
11446 /* For pending locations, the output differs slightly based
11447 on b->extra_string. If this is non-NULL, it contains either
11448 a condition or dprintf arguments. */
11449 if (b
->extra_string
== NULL
)
11451 gdb_printf (_(" (%s) pending."),
11452 event_location_to_string (b
->location
.get ()));
11454 else if (b
->type
== bp_dprintf
)
11456 gdb_printf (_(" (%s,%s) pending."),
11457 event_location_to_string (b
->location
.get ()),
11458 b
->extra_string
.get ());
11462 gdb_printf (_(" (%s %s) pending."),
11463 event_location_to_string (b
->location
.get ()),
11464 b
->extra_string
.get ());
11469 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
11470 gdb_printf (" at %ps",
11471 styled_string (address_style
.style (),
11472 paddress (b
->loc
->gdbarch
,
11473 b
->loc
->address
)));
11474 if (b
->loc
->symtab
!= NULL
)
11476 /* If there is a single location, we can print the location
11478 if (b
->loc
->next
== NULL
)
11480 const char *filename
11481 = symtab_to_filename_for_display (b
->loc
->symtab
);
11482 gdb_printf (": file %ps, line %d.",
11483 styled_string (file_name_style
.style (),
11485 b
->loc
->line_number
);
11488 /* This is not ideal, but each location may have a
11489 different file name, and this at least reflects the
11490 real situation somewhat. */
11491 gdb_printf (": %s.",
11492 event_location_to_string (b
->location
.get ()));
11497 struct bp_location
*loc
= b
->loc
;
11499 for (; loc
; loc
= loc
->next
)
11501 gdb_printf (" (%d locations)", n
);
11506 /* See breakpoint.h. */
11508 bp_location_range
breakpoint::locations () const
11510 return bp_location_range (this->loc
);
11513 struct bp_location
*
11514 breakpoint::allocate_location ()
11516 return new bp_location (this);
11519 #define internal_error_pure_virtual_called() \
11520 gdb_assert_not_reached ("pure virtual function called")
11523 breakpoint::insert_location (struct bp_location
*bl
)
11525 internal_error_pure_virtual_called ();
11529 breakpoint::remove_location (struct bp_location
*bl
,
11530 enum remove_bp_reason reason
)
11532 internal_error_pure_virtual_called ();
11536 breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11537 const address_space
*aspace
,
11539 const target_waitstatus
&ws
)
11541 internal_error_pure_virtual_called ();
11545 breakpoint::resources_needed (const struct bp_location
*bl
)
11547 internal_error_pure_virtual_called ();
11550 enum print_stop_action
11551 breakpoint::print_it (const bpstat
*bs
) const
11553 internal_error_pure_virtual_called ();
11557 breakpoint::print_mention () const
11559 internal_error_pure_virtual_called ();
11563 breakpoint::print_recreate (struct ui_file
*fp
) const
11565 internal_error_pure_virtual_called ();
11568 std::vector
<symtab_and_line
>
11569 breakpoint::decode_location (struct event_location
*location
,
11570 struct program_space
*search_pspace
)
11572 internal_error_pure_virtual_called ();
11575 /* Default breakpoint_ops methods. */
11578 base_breakpoint::re_set ()
11580 /* FIXME: is this still reachable? */
11581 if (breakpoint_event_location_empty_p (this))
11583 /* Anything without a location can't be re-set. */
11584 delete_breakpoint (this);
11588 breakpoint_re_set_default (this);
11592 base_breakpoint::insert_location (struct bp_location
*bl
)
11594 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
11596 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
11597 bl
->target_info
.placed_address
= addr
;
11600 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11601 result
= target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11603 result
= target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11605 if (result
== 0 && bl
->probe
.prob
!= nullptr)
11607 /* The insertion was successful, now let's set the probe's semaphore
11609 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11616 base_breakpoint::remove_location (struct bp_location
*bl
,
11617 enum remove_bp_reason reason
)
11619 if (bl
->probe
.prob
!= nullptr)
11621 /* Let's clear the semaphore before removing the location. */
11622 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11625 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11626 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11628 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
11632 base_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11633 const address_space
*aspace
,
11635 const target_waitstatus
&ws
)
11637 if (ws
.kind () != TARGET_WAITKIND_STOPPED
11638 || ws
.sig () != GDB_SIGNAL_TRAP
)
11641 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
11645 if (overlay_debugging
/* unmapped overlay section */
11646 && section_is_overlay (bl
->section
)
11647 && !section_is_mapped (bl
->section
))
11654 dprintf_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11655 const address_space
*aspace
,
11657 const target_waitstatus
&ws
)
11659 if (dprintf_style
== dprintf_style_agent
11660 && target_can_run_breakpoint_commands ())
11662 /* An agent-style dprintf never causes a stop. If we see a trap
11663 for this address it must be for a breakpoint that happens to
11664 be set at the same address. */
11668 return this->ordinary_breakpoint::breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
11672 ordinary_breakpoint::resources_needed (const struct bp_location
*bl
)
11674 gdb_assert (type
== bp_hardware_breakpoint
);
11679 enum print_stop_action
11680 ordinary_breakpoint::print_it (const bpstat
*bs
) const
11682 const struct bp_location
*bl
;
11684 struct ui_out
*uiout
= current_uiout
;
11686 bl
= bs
->bp_location_at
.get ();
11688 bp_temp
= disposition
== disp_del
;
11689 if (bl
->address
!= bl
->requested_address
)
11690 breakpoint_adjustment_warning (bl
->requested_address
,
11693 annotate_breakpoint (number
);
11694 maybe_print_thread_hit_breakpoint (uiout
);
11696 if (uiout
->is_mi_like_p ())
11698 uiout
->field_string ("reason",
11699 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11700 uiout
->field_string ("disp", bpdisp_text (disposition
));
11703 uiout
->message ("Temporary breakpoint %pF, ",
11704 signed_field ("bkptno", number
));
11706 uiout
->message ("Breakpoint %pF, ",
11707 signed_field ("bkptno", number
));
11709 return PRINT_SRC_AND_LOC
;
11713 ordinary_breakpoint::print_mention () const
11715 if (current_uiout
->is_mi_like_p ())
11720 case bp_breakpoint
:
11721 case bp_gnu_ifunc_resolver
:
11722 if (disposition
== disp_del
)
11723 gdb_printf (_("Temporary breakpoint"));
11725 gdb_printf (_("Breakpoint"));
11726 gdb_printf (_(" %d"), number
);
11727 if (type
== bp_gnu_ifunc_resolver
)
11728 gdb_printf (_(" at gnu-indirect-function resolver"));
11730 case bp_hardware_breakpoint
:
11731 gdb_printf (_("Hardware assisted breakpoint %d"), number
);
11734 gdb_printf (_("Dprintf %d"), number
);
11742 ordinary_breakpoint::print_recreate (struct ui_file
*fp
) const
11744 if (type
== bp_breakpoint
&& disposition
== disp_del
)
11745 gdb_printf (fp
, "tbreak");
11746 else if (type
== bp_breakpoint
)
11747 gdb_printf (fp
, "break");
11748 else if (type
== bp_hardware_breakpoint
11749 && disposition
== disp_del
)
11750 gdb_printf (fp
, "thbreak");
11751 else if (type
== bp_hardware_breakpoint
)
11752 gdb_printf (fp
, "hbreak");
11754 internal_error (__FILE__
, __LINE__
,
11755 _("unhandled breakpoint type %d"), (int) type
);
11757 gdb_printf (fp
, " %s", event_location_to_string (location
.get ()));
11759 /* Print out extra_string if this breakpoint is pending. It might
11760 contain, for example, conditions that were set by the user. */
11761 if (loc
== NULL
&& extra_string
!= NULL
)
11762 gdb_printf (fp
, " %s", extra_string
.get ());
11764 print_recreate_thread (fp
);
11767 std::vector
<symtab_and_line
>
11768 base_breakpoint::decode_location (struct event_location
*location
,
11769 struct program_space
*search_pspace
)
11771 if (event_location_type (location
) == PROBE_LOCATION
)
11772 return bkpt_probe_decode_location (this, location
, search_pspace
);
11774 return decode_location_default (this, location
, search_pspace
);
11777 /* Virtual table for internal breakpoints. */
11780 internal_breakpoint::re_set ()
11784 /* Delete overlay event and longjmp master breakpoints; they
11785 will be reset later by breakpoint_re_set. */
11786 case bp_overlay_event
:
11787 case bp_longjmp_master
:
11788 case bp_std_terminate_master
:
11789 case bp_exception_master
:
11790 delete_breakpoint (this);
11793 /* This breakpoint is special, it's set up when the inferior
11794 starts and we really don't want to touch it. */
11795 case bp_shlib_event
:
11797 /* Like bp_shlib_event, this breakpoint type is special. Once
11798 it is set up, we do not want to touch it. */
11799 case bp_thread_event
:
11805 internal_breakpoint::check_status (bpstat
*bs
)
11807 if (type
== bp_shlib_event
)
11809 /* If requested, stop when the dynamic linker notifies GDB of
11810 events. This allows the user to get control and place
11811 breakpoints in initializer routines for dynamically loaded
11812 objects (among other things). */
11813 bs
->stop
= stop_on_solib_events
;
11814 bs
->print
= stop_on_solib_events
;
11820 enum print_stop_action
11821 internal_breakpoint::print_it (const bpstat
*bs
) const
11825 case bp_shlib_event
:
11826 /* Did we stop because the user set the stop_on_solib_events
11827 variable? (If so, we report this as a generic, "Stopped due
11828 to shlib event" message.) */
11829 print_solib_event (false);
11832 case bp_thread_event
:
11833 /* Not sure how we will get here.
11834 GDB should not stop for these breakpoints. */
11835 gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
11838 case bp_overlay_event
:
11839 /* By analogy with the thread event, GDB should not stop for these. */
11840 gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11843 case bp_longjmp_master
:
11844 /* These should never be enabled. */
11845 gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11848 case bp_std_terminate_master
:
11849 /* These should never be enabled. */
11850 gdb_printf (_("std::terminate Master Breakpoint: "
11851 "gdb should not stop!\n"));
11854 case bp_exception_master
:
11855 /* These should never be enabled. */
11856 gdb_printf (_("Exception Master Breakpoint: "
11857 "gdb should not stop!\n"));
11861 return PRINT_NOTHING
;
11865 internal_breakpoint::print_mention () const
11867 /* Nothing to mention. These breakpoints are internal. */
11870 /* Virtual table for momentary breakpoints */
11873 momentary_breakpoint::re_set ()
11875 /* Keep temporary breakpoints, which can be encountered when we step
11876 over a dlopen call and solib_add is resetting the breakpoints.
11877 Otherwise these should have been blown away via the cleanup chain
11878 or by breakpoint_init_inferior when we rerun the executable. */
11882 momentary_breakpoint::check_status (bpstat
*bs
)
11884 /* Nothing. The point of these breakpoints is causing a stop. */
11887 enum print_stop_action
11888 momentary_breakpoint::print_it (const bpstat
*bs
) const
11890 return PRINT_UNKNOWN
;
11894 momentary_breakpoint::print_mention () const
11896 /* Nothing to mention. These breakpoints are internal. */
11899 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
11901 It gets cleared already on the removal of the first one of such placed
11902 breakpoints. This is OK as they get all removed altogether. */
11904 longjmp_breakpoint::~longjmp_breakpoint ()
11906 thread_info
*tp
= find_thread_global_id (this->thread
);
11909 tp
->initiating_frame
= null_frame_id
;
11913 bkpt_probe_create_sals_from_location (struct event_location
*location
,
11914 struct linespec_result
*canonical
)
11917 struct linespec_sals lsal
;
11919 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
11921 = xstrdup (event_location_to_string (canonical
->location
.get ()));
11922 canonical
->lsals
.push_back (std::move (lsal
));
11925 static std::vector
<symtab_and_line
>
11926 bkpt_probe_decode_location (struct breakpoint
*b
,
11927 struct event_location
*location
,
11928 struct program_space
*search_pspace
)
11930 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
11932 error (_("probe not found"));
11936 /* The breakpoint_ops structure to be used in tracepoints. */
11939 tracepoint::re_set ()
11941 breakpoint_re_set_default (this);
11945 tracepoint::breakpoint_hit (const struct bp_location
*bl
,
11946 const address_space
*aspace
, CORE_ADDR bp_addr
,
11947 const target_waitstatus
&ws
)
11949 /* By definition, the inferior does not report stops at
11955 tracepoint::print_one_detail (struct ui_out
*uiout
) const
11957 if (!static_trace_marker_id
.empty ())
11959 gdb_assert (type
== bp_static_tracepoint
11960 || type
== bp_static_marker_tracepoint
);
11962 uiout
->message ("\tmarker id is %pF\n",
11963 string_field ("static-tracepoint-marker-string-id",
11964 static_trace_marker_id
.c_str ()));
11969 tracepoint::print_mention () const
11971 if (current_uiout
->is_mi_like_p ())
11976 case bp_tracepoint
:
11977 gdb_printf (_("Tracepoint"));
11978 gdb_printf (_(" %d"), number
);
11980 case bp_fast_tracepoint
:
11981 gdb_printf (_("Fast tracepoint"));
11982 gdb_printf (_(" %d"), number
);
11984 case bp_static_tracepoint
:
11985 case bp_static_marker_tracepoint
:
11986 gdb_printf (_("Static tracepoint"));
11987 gdb_printf (_(" %d"), number
);
11990 internal_error (__FILE__
, __LINE__
,
11991 _("unhandled tracepoint type %d"), (int) type
);
11998 tracepoint::print_recreate (struct ui_file
*fp
) const
12000 if (type
== bp_fast_tracepoint
)
12001 gdb_printf (fp
, "ftrace");
12002 else if (type
== bp_static_tracepoint
12003 || type
== bp_static_marker_tracepoint
)
12004 gdb_printf (fp
, "strace");
12005 else if (type
== bp_tracepoint
)
12006 gdb_printf (fp
, "trace");
12008 internal_error (__FILE__
, __LINE__
,
12009 _("unhandled tracepoint type %d"), (int) type
);
12011 gdb_printf (fp
, " %s", event_location_to_string (location
.get ()));
12012 print_recreate_thread (fp
);
12015 gdb_printf (fp
, " passcount %d\n", pass_count
);
12018 std::vector
<symtab_and_line
>
12019 tracepoint::decode_location (struct event_location
*location
,
12020 struct program_space
*search_pspace
)
12022 if (event_location_type (location
) == PROBE_LOCATION
)
12023 return bkpt_probe_decode_location (this, location
, search_pspace
);
12025 return decode_location_default (this, location
, search_pspace
);
12028 /* Virtual table for tracepoints on static probes. */
12031 tracepoint_probe_create_sals_from_location
12032 (struct event_location
*location
,
12033 struct linespec_result
*canonical
)
12035 /* We use the same method for breakpoint on probes. */
12036 bkpt_probe_create_sals_from_location (location
, canonical
);
12040 dprintf_breakpoint::re_set ()
12042 breakpoint_re_set_default (this);
12044 /* extra_string should never be non-NULL for dprintf. */
12045 gdb_assert (extra_string
!= NULL
);
12047 /* 1 - connect to target 1, that can run breakpoint commands.
12048 2 - create a dprintf, which resolves fine.
12049 3 - disconnect from target 1
12050 4 - connect to target 2, that can NOT run breakpoint commands.
12052 After steps #3/#4, you'll want the dprintf command list to
12053 be updated, because target 1 and 2 may well return different
12054 answers for target_can_run_breakpoint_commands().
12055 Given absence of finer grained resetting, we get to do
12056 it all the time. */
12057 if (extra_string
!= NULL
)
12058 update_dprintf_command_list (this);
12061 /* Implement the "print_recreate" method for dprintf. */
12064 dprintf_breakpoint::print_recreate (struct ui_file
*fp
) const
12066 gdb_printf (fp
, "dprintf %s,%s",
12067 event_location_to_string (location
.get ()),
12068 extra_string
.get ());
12069 print_recreate_thread (fp
);
12072 /* Implement the "after_condition_true" method for dprintf.
12074 dprintf's are implemented with regular commands in their command
12075 list, but we run the commands here instead of before presenting the
12076 stop to the user, as dprintf's don't actually cause a stop. This
12077 also makes it so that the commands of multiple dprintfs at the same
12078 address are all handled. */
12081 dprintf_breakpoint::after_condition_true (struct bpstat
*bs
)
12083 /* dprintf's never cause a stop. This wasn't set in the
12084 check_status hook instead because that would make the dprintf's
12085 condition not be evaluated. */
12088 /* Run the command list here. Take ownership of it instead of
12089 copying. We never want these commands to run later in
12090 bpstat_do_actions, if a breakpoint that causes a stop happens to
12091 be set at same address as this dprintf, or even if running the
12092 commands here throws. */
12093 counted_command_line cmds
= std::move (bs
->commands
);
12094 gdb_assert (cmds
!= nullptr);
12095 execute_control_commands (cmds
.get (), 0);
12098 /* The breakpoint_ops structure to be used on static tracepoints with
12102 strace_marker_create_sals_from_location (struct event_location
*location
,
12103 struct linespec_result
*canonical
)
12105 struct linespec_sals lsal
;
12106 const char *arg_start
, *arg
;
12108 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
12109 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12111 std::string
str (arg_start
, arg
- arg_start
);
12112 const char *ptr
= str
.c_str ();
12113 canonical
->location
12114 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
12117 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12118 canonical
->lsals
.push_back (std::move (lsal
));
12122 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12123 struct linespec_result
*canonical
,
12124 gdb::unique_xmalloc_ptr
<char> cond_string
,
12125 gdb::unique_xmalloc_ptr
<char> extra_string
,
12126 enum bptype type_wanted
,
12127 enum bpdisp disposition
,
12129 int task
, int ignore_count
,
12130 const struct breakpoint_ops
*ops
,
12131 int from_tty
, int enabled
,
12132 int internal
, unsigned flags
)
12134 const linespec_sals
&lsal
= canonical
->lsals
[0];
12136 /* If the user is creating a static tracepoint by marker id
12137 (strace -m MARKER_ID), then store the sals index, so that
12138 breakpoint_re_set can try to match up which of the newly
12139 found markers corresponds to this one, and, don't try to
12140 expand multiple locations for each sal, given than SALS
12141 already should contain all sals for MARKER_ID. */
12143 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12145 event_location_up location
12146 = copy_event_location (canonical
->location
.get ());
12148 std::unique_ptr
<tracepoint
> tp (new tracepoint (gdbarch
,
12150 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
12151 std::move (location
), NULL
,
12152 std::move (cond_string
),
12153 std::move (extra_string
),
12154 type_wanted
, disposition
,
12155 thread
, task
, ignore_count
, ops
,
12156 from_tty
, enabled
, internal
, flags
,
12157 canonical
->special_display
);
12158 /* Given that its possible to have multiple markers with
12159 the same string id, if the user is creating a static
12160 tracepoint by marker id ("strace -m MARKER_ID"), then
12161 store the sals index, so that breakpoint_re_set can
12162 try to match up which of the newly found markers
12163 corresponds to this one */
12164 tp
->static_trace_marker_id_idx
= i
;
12166 install_breakpoint (internal
, std::move (tp
), 0);
12170 std::vector
<symtab_and_line
>
12171 static_marker_tracepoint::decode_location (struct event_location
*location
,
12172 struct program_space
*search_pspace
)
12174 const char *s
= get_linespec_location (location
)->spec_string
;
12176 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12177 if (sals
.size () > static_trace_marker_id_idx
)
12179 sals
[0] = sals
[static_trace_marker_id_idx
];
12184 error (_("marker %s not found"), static_trace_marker_id
.c_str ());
12187 /* Static tracepoints with marker (`-m'). */
12188 static struct breakpoint_ops strace_marker_breakpoint_ops
=
12190 strace_marker_create_sals_from_location
,
12191 strace_marker_create_breakpoints_sal
,
12195 strace_marker_p (struct breakpoint
*b
)
12197 return b
->type
== bp_static_marker_tracepoint
;
12200 /* Delete a breakpoint and clean up all traces of it in the data
12204 delete_breakpoint (struct breakpoint
*bpt
)
12206 gdb_assert (bpt
!= NULL
);
12208 /* Has this bp already been deleted? This can happen because
12209 multiple lists can hold pointers to bp's. bpstat lists are
12212 One example of this happening is a watchpoint's scope bp. When
12213 the scope bp triggers, we notice that the watchpoint is out of
12214 scope, and delete it. We also delete its scope bp. But the
12215 scope bp is marked "auto-deleting", and is already on a bpstat.
12216 That bpstat is then checked for auto-deleting bp's, which are
12219 A real solution to this problem might involve reference counts in
12220 bp's, and/or giving them pointers back to their referencing
12221 bpstat's, and teaching delete_breakpoint to only free a bp's
12222 storage when no more references were extent. A cheaper bandaid
12224 if (bpt
->type
== bp_none
)
12227 /* At least avoid this stale reference until the reference counting
12228 of breakpoints gets resolved. */
12229 if (bpt
->related_breakpoint
!= bpt
)
12231 struct breakpoint
*related
;
12232 struct watchpoint
*w
;
12234 if (bpt
->type
== bp_watchpoint_scope
)
12235 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12236 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12237 w
= (struct watchpoint
*) bpt
;
12241 watchpoint_del_at_next_stop (w
);
12243 /* Unlink bpt from the bpt->related_breakpoint ring. */
12244 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12245 related
= related
->related_breakpoint
);
12246 related
->related_breakpoint
= bpt
->related_breakpoint
;
12247 bpt
->related_breakpoint
= bpt
;
12250 /* watch_command_1 creates a watchpoint but only sets its number if
12251 update_watchpoint succeeds in creating its bp_locations. If there's
12252 a problem in that process, we'll be asked to delete the half-created
12253 watchpoint. In that case, don't announce the deletion. */
12255 gdb::observers::breakpoint_deleted
.notify (bpt
);
12257 if (breakpoint_chain
== bpt
)
12258 breakpoint_chain
= bpt
->next
;
12260 for (breakpoint
*b
: all_breakpoints ())
12261 if (b
->next
== bpt
)
12263 b
->next
= bpt
->next
;
12267 /* Be sure no bpstat's are pointing at the breakpoint after it's
12269 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12270 in all threads for now. Note that we cannot just remove bpstats
12271 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12272 commands are associated with the bpstat; if we remove it here,
12273 then the later call to bpstat_do_actions (&stop_bpstat); in
12274 event-top.c won't do anything, and temporary breakpoints with
12275 commands won't work. */
12277 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12279 /* Now that breakpoint is removed from breakpoint list, update the
12280 global location list. This will remove locations that used to
12281 belong to this breakpoint. Do this before freeing the breakpoint
12282 itself, since remove_breakpoint looks at location's owner. It
12283 might be better design to have location completely
12284 self-contained, but it's not the case now. */
12285 update_global_location_list (UGLL_DONT_INSERT
);
12287 /* On the chance that someone will soon try again to delete this
12288 same bp, we mark it as deleted before freeing its storage. */
12289 bpt
->type
= bp_none
;
12293 /* Iterator function to call a user-provided callback function once
12294 for each of B and its related breakpoints. */
12297 iterate_over_related_breakpoints (struct breakpoint
*b
,
12298 gdb::function_view
<void (breakpoint
*)> function
)
12300 struct breakpoint
*related
;
12305 struct breakpoint
*next
;
12307 /* FUNCTION may delete RELATED. */
12308 next
= related
->related_breakpoint
;
12310 if (next
== related
)
12312 /* RELATED is the last ring entry. */
12313 function (related
);
12315 /* FUNCTION may have deleted it, so we'd never reach back to
12316 B. There's nothing left to do anyway, so just break
12321 function (related
);
12325 while (related
!= b
);
12329 delete_command (const char *arg
, int from_tty
)
12335 int breaks_to_delete
= 0;
12337 /* Delete all breakpoints if no argument. Do not delete
12338 internal breakpoints, these have to be deleted with an
12339 explicit breakpoint number argument. */
12340 for (breakpoint
*b
: all_breakpoints ())
12341 if (user_breakpoint_p (b
))
12343 breaks_to_delete
= 1;
12347 /* Ask user only if there are some breakpoints to delete. */
12349 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
12350 for (breakpoint
*b
: all_breakpoints_safe ())
12351 if (user_breakpoint_p (b
))
12352 delete_breakpoint (b
);
12355 map_breakpoint_numbers
12356 (arg
, [&] (breakpoint
*br
)
12358 iterate_over_related_breakpoints (br
, delete_breakpoint
);
12362 /* Return true if all locations of B bound to PSPACE are pending. If
12363 PSPACE is NULL, all locations of all program spaces are
12367 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
12369 for (bp_location
*loc
: b
->locations ())
12370 if ((pspace
== NULL
12371 || loc
->pspace
== pspace
)
12372 && !loc
->shlib_disabled
12373 && !loc
->pspace
->executing_startup
)
12378 /* Subroutine of update_breakpoint_locations to simplify it.
12379 Return non-zero if multiple fns in list LOC have the same name.
12380 Null names are ignored. */
12383 ambiguous_names_p (struct bp_location
*loc
)
12385 struct bp_location
*l
;
12386 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
12389 for (l
= loc
; l
!= NULL
; l
= l
->next
)
12392 const char *name
= l
->function_name
.get ();
12394 /* Allow for some names to be NULL, ignore them. */
12398 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
12400 /* NOTE: We can assume slot != NULL here because xcalloc never
12410 /* When symbols change, it probably means the sources changed as well,
12411 and it might mean the static tracepoint markers are no longer at
12412 the same address or line numbers they used to be at last we
12413 checked. Losing your static tracepoints whenever you rebuild is
12414 undesirable. This function tries to resync/rematch gdb static
12415 tracepoints with the markers on the target, for static tracepoints
12416 that have not been set by marker id. Static tracepoint that have
12417 been set by marker id are reset by marker id in breakpoint_re_set.
12420 1) For a tracepoint set at a specific address, look for a marker at
12421 the old PC. If one is found there, assume to be the same marker.
12422 If the name / string id of the marker found is different from the
12423 previous known name, assume that means the user renamed the marker
12424 in the sources, and output a warning.
12426 2) For a tracepoint set at a given line number, look for a marker
12427 at the new address of the old line number. If one is found there,
12428 assume to be the same marker. If the name / string id of the
12429 marker found is different from the previous known name, assume that
12430 means the user renamed the marker in the sources, and output a
12433 3) If a marker is no longer found at the same address or line, it
12434 may mean the marker no longer exists. But it may also just mean
12435 the code changed a bit. Maybe the user added a few lines of code
12436 that made the marker move up or down (in line number terms). Ask
12437 the target for info about the marker with the string id as we knew
12438 it. If found, update line number and address in the matching
12439 static tracepoint. This will get confused if there's more than one
12440 marker with the same ID (possible in UST, although unadvised
12441 precisely because it confuses tools). */
12443 static struct symtab_and_line
12444 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
12446 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12447 struct static_tracepoint_marker marker
;
12452 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12454 if (target_static_tracepoint_marker_at (pc
, &marker
))
12456 if (tp
->static_trace_marker_id
!= marker
.str_id
)
12457 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12458 b
->number
, tp
->static_trace_marker_id
.c_str (),
12459 marker
.str_id
.c_str ());
12461 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
12466 /* Old marker wasn't found on target at lineno. Try looking it up
12468 if (!sal
.explicit_pc
12470 && sal
.symtab
!= NULL
12471 && !tp
->static_trace_marker_id
.empty ())
12473 std::vector
<static_tracepoint_marker
> markers
12474 = target_static_tracepoint_markers_by_strid
12475 (tp
->static_trace_marker_id
.c_str ());
12477 if (!markers
.empty ())
12479 struct symbol
*sym
;
12480 struct static_tracepoint_marker
*tpmarker
;
12481 struct ui_out
*uiout
= current_uiout
;
12482 struct explicit_location explicit_loc
;
12484 tpmarker
= &markers
[0];
12486 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
12488 warning (_("marker for static tracepoint %d (%s) not "
12489 "found at previous line number"),
12490 b
->number
, tp
->static_trace_marker_id
.c_str ());
12492 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
12493 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
12494 uiout
->text ("Now in ");
12497 uiout
->field_string ("func", sym
->print_name (),
12498 function_name_style
.style ());
12499 uiout
->text (" at ");
12501 uiout
->field_string ("file",
12502 symtab_to_filename_for_display (sal2
.symtab
),
12503 file_name_style
.style ());
12506 if (uiout
->is_mi_like_p ())
12508 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
12510 uiout
->field_string ("fullname", fullname
);
12513 uiout
->field_signed ("line", sal2
.line
);
12514 uiout
->text ("\n");
12516 b
->loc
->line_number
= sal2
.line
;
12517 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
12519 b
->location
.reset (NULL
);
12520 initialize_explicit_location (&explicit_loc
);
12521 explicit_loc
.source_filename
12522 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
12523 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
12524 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
12525 b
->location
= new_explicit_location (&explicit_loc
);
12527 /* Might be nice to check if function changed, and warn if
12534 /* Returns 1 iff locations A and B are sufficiently same that
12535 we don't need to report breakpoint as changed. */
12538 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
12542 if (a
->address
!= b
->address
)
12545 if (a
->shlib_disabled
!= b
->shlib_disabled
)
12548 if (a
->enabled
!= b
->enabled
)
12551 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
12558 if ((a
== NULL
) != (b
== NULL
))
12564 /* Split all locations of B that are bound to PSPACE out of B's
12565 location list to a separate list and return that list's head. If
12566 PSPACE is NULL, hoist out all locations of B. */
12568 static struct bp_location
*
12569 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
12571 struct bp_location head
;
12572 struct bp_location
*i
= b
->loc
;
12573 struct bp_location
**i_link
= &b
->loc
;
12574 struct bp_location
*hoisted
= &head
;
12576 if (pspace
== NULL
)
12587 if (i
->pspace
== pspace
)
12602 /* Create new breakpoint locations for B (a hardware or software
12603 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
12604 zero, then B is a ranged breakpoint. Only recreates locations for
12605 FILTER_PSPACE. Locations of other program spaces are left
12609 update_breakpoint_locations (struct breakpoint
*b
,
12610 struct program_space
*filter_pspace
,
12611 gdb::array_view
<const symtab_and_line
> sals
,
12612 gdb::array_view
<const symtab_and_line
> sals_end
)
12614 struct bp_location
*existing_locations
;
12616 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
12618 /* Ranged breakpoints have only one start location and one end
12620 b
->enable_state
= bp_disabled
;
12621 gdb_printf (gdb_stderr
,
12622 _("Could not reset ranged breakpoint %d: "
12623 "multiple locations found\n"),
12628 /* If there's no new locations, and all existing locations are
12629 pending, don't do anything. This optimizes the common case where
12630 all locations are in the same shared library, that was unloaded.
12631 We'd like to retain the location, so that when the library is
12632 loaded again, we don't loose the enabled/disabled status of the
12633 individual locations. */
12634 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
12637 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
12639 for (const auto &sal
: sals
)
12641 struct bp_location
*new_loc
;
12643 switch_to_program_space_and_thread (sal
.pspace
);
12645 new_loc
= b
->add_location (sal
);
12647 /* Reparse conditions, they might contain references to the
12649 if (b
->cond_string
!= NULL
)
12653 s
= b
->cond_string
.get ();
12656 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
12657 block_for_pc (sal
.pc
),
12660 catch (const gdb_exception_error
&e
)
12662 new_loc
->disabled_by_cond
= true;
12666 if (!sals_end
.empty ())
12668 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
12670 new_loc
->length
= end
- sals
[0].pc
+ 1;
12674 /* If possible, carry over 'disable' status from existing
12677 struct bp_location
*e
= existing_locations
;
12678 /* If there are multiple breakpoints with the same function name,
12679 e.g. for inline functions, comparing function names won't work.
12680 Instead compare pc addresses; this is just a heuristic as things
12681 may have moved, but in practice it gives the correct answer
12682 often enough until a better solution is found. */
12683 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
12685 for (; e
; e
= e
->next
)
12687 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
12689 if (have_ambiguous_names
)
12691 for (bp_location
*l
: b
->locations ())
12693 /* Ignore software vs hardware location type at
12694 this point, because with "set breakpoint
12695 auto-hw", after a re-set, locations that were
12696 hardware can end up as software, or vice versa.
12697 As mentioned above, this is an heuristic and in
12698 practice should give the correct answer often
12700 if (breakpoint_locations_match (e
, l
, true))
12702 l
->enabled
= e
->enabled
;
12703 l
->disabled_by_cond
= e
->disabled_by_cond
;
12710 for (bp_location
*l
: b
->locations ())
12711 if (l
->function_name
12712 && strcmp (e
->function_name
.get (),
12713 l
->function_name
.get ()) == 0)
12715 l
->enabled
= e
->enabled
;
12716 l
->disabled_by_cond
= e
->disabled_by_cond
;
12724 if (!locations_are_equal (existing_locations
, b
->loc
))
12725 gdb::observers::breakpoint_modified
.notify (b
);
12728 /* Find the SaL locations corresponding to the given LOCATION.
12729 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
12731 static std::vector
<symtab_and_line
>
12732 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
12733 struct program_space
*search_pspace
, int *found
)
12735 struct gdb_exception exception
;
12737 std::vector
<symtab_and_line
> sals
;
12741 sals
= b
->decode_location (location
, search_pspace
);
12743 catch (gdb_exception_error
&e
)
12745 int not_found_and_ok
= 0;
12747 /* For pending breakpoints, it's expected that parsing will
12748 fail until the right shared library is loaded. User has
12749 already told to create pending breakpoints and don't need
12750 extra messages. If breakpoint is in bp_shlib_disabled
12751 state, then user already saw the message about that
12752 breakpoint being disabled, and don't want to see more
12754 if (e
.error
== NOT_FOUND_ERROR
12755 && (b
->condition_not_parsed
12757 && search_pspace
!= NULL
12758 && b
->loc
->pspace
!= search_pspace
)
12759 || (b
->loc
&& b
->loc
->shlib_disabled
)
12760 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
12761 || b
->enable_state
== bp_disabled
))
12762 not_found_and_ok
= 1;
12764 if (!not_found_and_ok
)
12766 /* We surely don't want to warn about the same breakpoint
12767 10 times. One solution, implemented here, is disable
12768 the breakpoint on error. Another solution would be to
12769 have separate 'warning emitted' flag. Since this
12770 happens only when a binary has changed, I don't know
12771 which approach is better. */
12772 b
->enable_state
= bp_disabled
;
12776 exception
= std::move (e
);
12779 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
12781 for (auto &sal
: sals
)
12782 resolve_sal_pc (&sal
);
12783 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
12785 gdb::unique_xmalloc_ptr
<char> cond_string
, extra_string
;
12788 find_condition_and_thread_for_sals (sals
, b
->extra_string
.get (),
12789 &cond_string
, &thread
,
12790 &task
, &extra_string
);
12791 gdb_assert (b
->cond_string
== NULL
);
12793 b
->cond_string
= std::move (cond_string
);
12794 b
->thread
= thread
;
12797 b
->extra_string
= std::move (extra_string
);
12798 b
->condition_not_parsed
= 0;
12801 if (b
->type
== bp_static_tracepoint
)
12802 sals
[0] = update_static_tracepoint (b
, sals
[0]);
12812 /* The default re_set method, for typical hardware or software
12813 breakpoints. Reevaluate the breakpoint and recreate its
12817 breakpoint_re_set_default (struct breakpoint
*b
)
12819 struct program_space
*filter_pspace
= current_program_space
;
12820 std::vector
<symtab_and_line
> expanded
, expanded_end
;
12823 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
12824 filter_pspace
, &found
);
12826 expanded
= std::move (sals
);
12828 if (b
->location_range_end
!= NULL
)
12830 std::vector
<symtab_and_line
> sals_end
12831 = location_to_sals (b
, b
->location_range_end
.get (),
12832 filter_pspace
, &found
);
12834 expanded_end
= std::move (sals_end
);
12837 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
12840 /* Default method for creating SALs from an address string. It basically
12841 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
12844 create_sals_from_location_default (struct event_location
*location
,
12845 struct linespec_result
*canonical
)
12847 parse_breakpoint_sals (location
, canonical
);
12850 /* Decode the line represented by S by calling decode_line_full. This is the
12851 default function for the `decode_location' method of breakpoint_ops. */
12853 static std::vector
<symtab_and_line
>
12854 decode_location_default (struct breakpoint
*b
,
12855 struct event_location
*location
,
12856 struct program_space
*search_pspace
)
12858 struct linespec_result canonical
;
12860 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
12861 NULL
, 0, &canonical
, multiple_symbols_all
,
12864 /* We should get 0 or 1 resulting SALs. */
12865 gdb_assert (canonical
.lsals
.size () < 2);
12867 if (!canonical
.lsals
.empty ())
12869 const linespec_sals
&lsal
= canonical
.lsals
[0];
12870 return std::move (lsal
.sals
);
12875 /* Reset a breakpoint. */
12878 breakpoint_re_set_one (breakpoint
*b
)
12880 input_radix
= b
->input_radix
;
12881 set_language (b
->language
);
12886 /* Re-set breakpoint locations for the current program space.
12887 Locations bound to other program spaces are left untouched. */
12890 breakpoint_re_set (void)
12893 scoped_restore_current_language save_language
;
12894 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
12895 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
12897 /* breakpoint_re_set_one sets the current_language to the language
12898 of the breakpoint it is resetting (see prepare_re_set_context)
12899 before re-evaluating the breakpoint's location. This change can
12900 unfortunately get undone by accident if the language_mode is set
12901 to auto, and we either switch frames, or more likely in this context,
12902 we select the current frame.
12904 We prevent this by temporarily turning the language_mode to
12905 language_mode_manual. We restore it once all breakpoints
12906 have been reset. */
12907 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
12908 language_mode
= language_mode_manual
;
12910 /* Note: we must not try to insert locations until after all
12911 breakpoints have been re-set. Otherwise, e.g., when re-setting
12912 breakpoint 1, we'd insert the locations of breakpoint 2, which
12913 hadn't been re-set yet, and thus may have stale locations. */
12915 for (breakpoint
*b
: all_breakpoints_safe ())
12919 breakpoint_re_set_one (b
);
12921 catch (const gdb_exception
&ex
)
12923 exception_fprintf (gdb_stderr
, ex
,
12924 "Error in re-setting breakpoint %d: ",
12929 jit_breakpoint_re_set ();
12932 create_overlay_event_breakpoint ();
12933 create_longjmp_master_breakpoint ();
12934 create_std_terminate_master_breakpoint ();
12935 create_exception_master_breakpoint ();
12937 /* Now we can insert. */
12938 update_global_location_list (UGLL_MAY_INSERT
);
12941 /* Reset the thread number of this breakpoint:
12943 - If the breakpoint is for all threads, leave it as-is.
12944 - Else, reset it to the current thread for inferior_ptid. */
12946 breakpoint_re_set_thread (struct breakpoint
*b
)
12948 if (b
->thread
!= -1)
12950 b
->thread
= inferior_thread ()->global_num
;
12952 /* We're being called after following a fork. The new fork is
12953 selected as current, and unless this was a vfork will have a
12954 different program space from the original thread. Reset that
12956 b
->loc
->pspace
= current_program_space
;
12960 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12961 If from_tty is nonzero, it prints a message to that effect,
12962 which ends with a period (no newline). */
12965 set_ignore_count (int bptnum
, int count
, int from_tty
)
12970 for (breakpoint
*b
: all_breakpoints ())
12971 if (b
->number
== bptnum
)
12973 if (is_tracepoint (b
))
12975 if (from_tty
&& count
!= 0)
12976 gdb_printf (_("Ignore count ignored for tracepoint %d."),
12981 b
->ignore_count
= count
;
12985 gdb_printf (_("Will stop next time "
12986 "breakpoint %d is reached."),
12988 else if (count
== 1)
12989 gdb_printf (_("Will ignore next crossing of breakpoint %d."),
12992 gdb_printf (_("Will ignore next %d "
12993 "crossings of breakpoint %d."),
12996 gdb::observers::breakpoint_modified
.notify (b
);
13000 error (_("No breakpoint number %d."), bptnum
);
13003 /* Command to set ignore-count of breakpoint N to COUNT. */
13006 ignore_command (const char *args
, int from_tty
)
13008 const char *p
= args
;
13012 error_no_arg (_("a breakpoint number"));
13014 num
= get_number (&p
);
13016 error (_("bad breakpoint number: '%s'"), args
);
13018 error (_("Second argument (specified ignore-count) is missing."));
13020 set_ignore_count (num
,
13021 longest_to_int (value_as_long (parse_and_eval (p
))),
13028 /* Call FUNCTION on each of the breakpoints with numbers in the range
13029 defined by BP_NUM_RANGE (an inclusive range). */
13032 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13033 gdb::function_view
<void (breakpoint
*)> function
)
13035 if (bp_num_range
.first
== 0)
13037 warning (_("bad breakpoint number at or near '%d'"),
13038 bp_num_range
.first
);
13042 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13044 bool match
= false;
13046 for (breakpoint
*b
: all_breakpoints_safe ())
13047 if (b
->number
== i
)
13054 gdb_printf (_("No breakpoint number %d.\n"), i
);
13059 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13063 map_breakpoint_numbers (const char *args
,
13064 gdb::function_view
<void (breakpoint
*)> function
)
13066 if (args
== NULL
|| *args
== '\0')
13067 error_no_arg (_("one or more breakpoint numbers"));
13069 number_or_range_parser
parser (args
);
13071 while (!parser
.finished ())
13073 int num
= parser
.get_number ();
13074 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13078 /* Return the breakpoint location structure corresponding to the
13079 BP_NUM and LOC_NUM values. */
13081 static struct bp_location
*
13082 find_location_by_number (int bp_num
, int loc_num
)
13084 breakpoint
*b
= get_breakpoint (bp_num
);
13086 if (!b
|| b
->number
!= bp_num
)
13087 error (_("Bad breakpoint number '%d'"), bp_num
);
13090 error (_("Bad breakpoint location number '%d'"), loc_num
);
13093 for (bp_location
*loc
: b
->locations ())
13094 if (++n
== loc_num
)
13097 error (_("Bad breakpoint location number '%d'"), loc_num
);
13100 /* Modes of operation for extract_bp_num. */
13101 enum class extract_bp_kind
13103 /* Extracting a breakpoint number. */
13106 /* Extracting a location number. */
13110 /* Extract a breakpoint or location number (as determined by KIND)
13111 from the string starting at START. TRAILER is a character which
13112 can be found after the number. If you don't want a trailer, use
13113 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13114 string. This always returns a positive integer. */
13117 extract_bp_num (extract_bp_kind kind
, const char *start
,
13118 int trailer
, const char **end_out
= NULL
)
13120 const char *end
= start
;
13121 int num
= get_number_trailer (&end
, trailer
);
13123 error (kind
== extract_bp_kind::bp
13124 ? _("Negative breakpoint number '%.*s'")
13125 : _("Negative breakpoint location number '%.*s'"),
13126 int (end
- start
), start
);
13128 error (kind
== extract_bp_kind::bp
13129 ? _("Bad breakpoint number '%.*s'")
13130 : _("Bad breakpoint location number '%.*s'"),
13131 int (end
- start
), start
);
13133 if (end_out
!= NULL
)
13138 /* Extract a breakpoint or location range (as determined by KIND) in
13139 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13140 representing the (inclusive) range. The returned pair's elements
13141 are always positive integers. */
13143 static std::pair
<int, int>
13144 extract_bp_or_bp_range (extract_bp_kind kind
,
13145 const std::string
&arg
,
13146 std::string::size_type arg_offset
)
13148 std::pair
<int, int> range
;
13149 const char *bp_loc
= &arg
[arg_offset
];
13150 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13151 if (dash
!= std::string::npos
)
13153 /* bp_loc is a range (x-z). */
13154 if (arg
.length () == dash
+ 1)
13155 error (kind
== extract_bp_kind::bp
13156 ? _("Bad breakpoint number at or near: '%s'")
13157 : _("Bad breakpoint location number at or near: '%s'"),
13161 const char *start_first
= bp_loc
;
13162 const char *start_second
= &arg
[dash
+ 1];
13163 range
.first
= extract_bp_num (kind
, start_first
, '-');
13164 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
13166 if (range
.first
> range
.second
)
13167 error (kind
== extract_bp_kind::bp
13168 ? _("Inverted breakpoint range at '%.*s'")
13169 : _("Inverted breakpoint location range at '%.*s'"),
13170 int (end
- start_first
), start_first
);
13174 /* bp_loc is a single value. */
13175 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
13176 range
.second
= range
.first
;
13181 /* Extract the breakpoint/location range specified by ARG. Returns
13182 the breakpoint range in BP_NUM_RANGE, and the location range in
13185 ARG may be in any of the following forms:
13187 x where 'x' is a breakpoint number.
13188 x-y where 'x' and 'y' specify a breakpoint numbers range.
13189 x.y where 'x' is a breakpoint number and 'y' a location number.
13190 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
13191 location number range.
13195 extract_bp_number_and_location (const std::string
&arg
,
13196 std::pair
<int, int> &bp_num_range
,
13197 std::pair
<int, int> &bp_loc_range
)
13199 std::string::size_type dot
= arg
.find ('.');
13201 if (dot
!= std::string::npos
)
13203 /* Handle 'x.y' and 'x.y-z' cases. */
13205 if (arg
.length () == dot
+ 1 || dot
== 0)
13206 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
13209 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
13210 bp_num_range
.second
= bp_num_range
.first
;
13212 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
13217 /* Handle x and x-y cases. */
13219 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
13220 bp_loc_range
.first
= 0;
13221 bp_loc_range
.second
= 0;
13225 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
13226 specifies whether to enable or disable. */
13229 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
13231 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
13234 if (loc
->disabled_by_cond
&& enable
)
13235 error (_("Breakpoint %d's condition is invalid at location %d, "
13236 "cannot enable."), bp_num
, loc_num
);
13238 if (loc
->enabled
!= enable
)
13240 loc
->enabled
= enable
;
13241 mark_breakpoint_location_modified (loc
);
13243 if (target_supports_enable_disable_tracepoint ()
13244 && current_trace_status ()->running
&& loc
->owner
13245 && is_tracepoint (loc
->owner
))
13246 target_disable_tracepoint (loc
);
13248 update_global_location_list (UGLL_DONT_INSERT
);
13250 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13253 /* Enable or disable a range of breakpoint locations. BP_NUM is the
13254 number of the breakpoint, and BP_LOC_RANGE specifies the
13255 (inclusive) range of location numbers of that breakpoint to
13256 enable/disable. ENABLE specifies whether to enable or disable the
13260 enable_disable_breakpoint_location_range (int bp_num
,
13261 std::pair
<int, int> &bp_loc_range
,
13264 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
13265 enable_disable_bp_num_loc (bp_num
, i
, enable
);
13268 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13269 If from_tty is nonzero, it prints a message to that effect,
13270 which ends with a period (no newline). */
13273 disable_breakpoint (struct breakpoint
*bpt
)
13275 /* Never disable a watchpoint scope breakpoint; we want to
13276 hit them when we leave scope so we can delete both the
13277 watchpoint and its scope breakpoint at that time. */
13278 if (bpt
->type
== bp_watchpoint_scope
)
13281 bpt
->enable_state
= bp_disabled
;
13283 /* Mark breakpoint locations modified. */
13284 mark_breakpoint_modified (bpt
);
13286 if (target_supports_enable_disable_tracepoint ()
13287 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13289 for (bp_location
*location
: bpt
->locations ())
13290 target_disable_tracepoint (location
);
13293 update_global_location_list (UGLL_DONT_INSERT
);
13295 gdb::observers::breakpoint_modified
.notify (bpt
);
13298 /* Enable or disable the breakpoint(s) or breakpoint location(s)
13299 specified in ARGS. ARGS may be in any of the formats handled by
13300 extract_bp_number_and_location. ENABLE specifies whether to enable
13301 or disable the breakpoints/locations. */
13304 enable_disable_command (const char *args
, int from_tty
, bool enable
)
13308 for (breakpoint
*bpt
: all_breakpoints ())
13309 if (user_breakpoint_p (bpt
))
13312 enable_breakpoint (bpt
);
13314 disable_breakpoint (bpt
);
13319 std::string num
= extract_arg (&args
);
13321 while (!num
.empty ())
13323 std::pair
<int, int> bp_num_range
, bp_loc_range
;
13325 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
13327 if (bp_loc_range
.first
== bp_loc_range
.second
13328 && bp_loc_range
.first
== 0)
13330 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
13331 map_breakpoint_number_range (bp_num_range
,
13333 ? enable_breakpoint
13334 : disable_breakpoint
);
13338 /* Handle breakpoint ids with formats 'x.y' or
13340 enable_disable_breakpoint_location_range
13341 (bp_num_range
.first
, bp_loc_range
, enable
);
13343 num
= extract_arg (&args
);
13348 /* The disable command disables the specified breakpoints/locations
13349 (or all defined breakpoints) so they're no longer effective in
13350 stopping the inferior. ARGS may be in any of the forms defined in
13351 extract_bp_number_and_location. */
13354 disable_command (const char *args
, int from_tty
)
13356 enable_disable_command (args
, from_tty
, false);
13360 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13363 int target_resources_ok
;
13365 if (bpt
->type
== bp_hardware_breakpoint
)
13368 i
= hw_breakpoint_used_count ();
13369 target_resources_ok
=
13370 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13372 if (target_resources_ok
== 0)
13373 error (_("No hardware breakpoint support in the target."));
13374 else if (target_resources_ok
< 0)
13375 error (_("Hardware breakpoints used exceeds limit."));
13378 if (is_watchpoint (bpt
))
13380 /* Initialize it just to avoid a GCC false warning. */
13381 enum enable_state orig_enable_state
= bp_disabled
;
13385 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13387 orig_enable_state
= bpt
->enable_state
;
13388 bpt
->enable_state
= bp_enabled
;
13389 update_watchpoint (w
, 1 /* reparse */);
13391 catch (const gdb_exception
&e
)
13393 bpt
->enable_state
= orig_enable_state
;
13394 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13400 bpt
->enable_state
= bp_enabled
;
13402 /* Mark breakpoint locations modified. */
13403 mark_breakpoint_modified (bpt
);
13405 if (target_supports_enable_disable_tracepoint ()
13406 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13408 for (bp_location
*location
: bpt
->locations ())
13409 target_enable_tracepoint (location
);
13412 bpt
->disposition
= disposition
;
13413 bpt
->enable_count
= count
;
13414 update_global_location_list (UGLL_MAY_INSERT
);
13416 gdb::observers::breakpoint_modified
.notify (bpt
);
13421 enable_breakpoint (struct breakpoint
*bpt
)
13423 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13426 /* The enable command enables the specified breakpoints/locations (or
13427 all defined breakpoints) so they once again become (or continue to
13428 be) effective in stopping the inferior. ARGS may be in any of the
13429 forms defined in extract_bp_number_and_location. */
13432 enable_command (const char *args
, int from_tty
)
13434 enable_disable_command (args
, from_tty
, true);
13438 enable_once_command (const char *args
, int from_tty
)
13440 map_breakpoint_numbers
13441 (args
, [&] (breakpoint
*b
)
13443 iterate_over_related_breakpoints
13444 (b
, [&] (breakpoint
*bpt
)
13446 enable_breakpoint_disp (bpt
, disp_disable
, 1);
13452 enable_count_command (const char *args
, int from_tty
)
13457 error_no_arg (_("hit count"));
13459 count
= get_number (&args
);
13461 map_breakpoint_numbers
13462 (args
, [&] (breakpoint
*b
)
13464 iterate_over_related_breakpoints
13465 (b
, [&] (breakpoint
*bpt
)
13467 enable_breakpoint_disp (bpt
, disp_disable
, count
);
13473 enable_delete_command (const char *args
, int from_tty
)
13475 map_breakpoint_numbers
13476 (args
, [&] (breakpoint
*b
)
13478 iterate_over_related_breakpoints
13479 (b
, [&] (breakpoint
*bpt
)
13481 enable_breakpoint_disp (bpt
, disp_del
, 1);
13486 /* Invalidate last known value of any hardware watchpoint if
13487 the memory which that value represents has been written to by
13491 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
13492 CORE_ADDR addr
, ssize_t len
,
13493 const bfd_byte
*data
)
13495 for (breakpoint
*bp
: all_breakpoints ())
13496 if (bp
->enable_state
== bp_enabled
13497 && bp
->type
== bp_hardware_watchpoint
)
13499 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
13501 if (wp
->val_valid
&& wp
->val
!= nullptr)
13503 for (bp_location
*loc
: bp
->locations ())
13504 if (loc
->loc_type
== bp_loc_hardware_watchpoint
13505 && loc
->address
+ loc
->length
> addr
13506 && addr
+ len
> loc
->address
)
13509 wp
->val_valid
= false;
13515 /* Create and insert a breakpoint for software single step. */
13518 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
13519 const address_space
*aspace
,
13522 struct thread_info
*tp
= inferior_thread ();
13523 struct symtab_and_line sal
;
13524 CORE_ADDR pc
= next_pc
;
13526 if (tp
->control
.single_step_breakpoints
== NULL
)
13528 tp
->control
.single_step_breakpoints
13529 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
13532 sal
= find_pc_line (pc
, 0);
13534 sal
.section
= find_pc_overlay (pc
);
13535 sal
.explicit_pc
= 1;
13536 tp
->control
.single_step_breakpoints
->add_location (sal
);
13538 update_global_location_list (UGLL_INSERT
);
13541 /* Insert single step breakpoints according to the current state. */
13544 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
13546 struct regcache
*regcache
= get_current_regcache ();
13547 std::vector
<CORE_ADDR
> next_pcs
;
13549 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
13551 if (!next_pcs
.empty ())
13553 struct frame_info
*frame
= get_current_frame ();
13554 const address_space
*aspace
= get_frame_address_space (frame
);
13556 for (CORE_ADDR pc
: next_pcs
)
13557 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
13565 /* See breakpoint.h. */
13568 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
13569 const address_space
*aspace
,
13572 for (bp_location
*loc
: bp
->locations ())
13574 && breakpoint_location_address_match (loc
, aspace
, pc
))
13580 /* Check whether a software single-step breakpoint is inserted at
13584 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
13587 for (breakpoint
*bpt
: all_breakpoints ())
13589 if (bpt
->type
== bp_single_step
13590 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
13596 /* Tracepoint-specific operations. */
13598 /* Set tracepoint count to NUM. */
13600 set_tracepoint_count (int num
)
13602 tracepoint_count
= num
;
13603 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
13607 trace_command (const char *arg
, int from_tty
)
13609 event_location_up location
= string_to_event_location (&arg
,
13611 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
13612 (location
.get (), true /* is_tracepoint */);
13614 create_breakpoint (get_current_arch (),
13616 NULL
, 0, arg
, false, 1 /* parse arg */,
13618 bp_tracepoint
/* type_wanted */,
13619 0 /* Ignore count */,
13620 pending_break_support
,
13624 0 /* internal */, 0);
13628 ftrace_command (const char *arg
, int from_tty
)
13630 event_location_up location
= string_to_event_location (&arg
,
13632 create_breakpoint (get_current_arch (),
13634 NULL
, 0, arg
, false, 1 /* parse arg */,
13636 bp_fast_tracepoint
/* type_wanted */,
13637 0 /* Ignore count */,
13638 pending_break_support
,
13639 &base_breakpoint_ops
,
13642 0 /* internal */, 0);
13645 /* strace command implementation. Creates a static tracepoint. */
13648 strace_command (const char *arg
, int from_tty
)
13650 const struct breakpoint_ops
*ops
;
13651 event_location_up location
;
13654 /* Decide if we are dealing with a static tracepoint marker (`-m'),
13655 or with a normal static tracepoint. */
13656 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
13658 ops
= &strace_marker_breakpoint_ops
;
13659 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
13660 type
= bp_static_marker_tracepoint
;
13664 ops
= &base_breakpoint_ops
;
13665 location
= string_to_event_location (&arg
, current_language
);
13666 type
= bp_static_tracepoint
;
13669 create_breakpoint (get_current_arch (),
13671 NULL
, 0, arg
, false, 1 /* parse arg */,
13673 type
/* type_wanted */,
13674 0 /* Ignore count */,
13675 pending_break_support
,
13679 0 /* internal */, 0);
13682 /* Set up a fake reader function that gets command lines from a linked
13683 list that was acquired during tracepoint uploading. */
13685 static struct uploaded_tp
*this_utp
;
13686 static int next_cmd
;
13689 read_uploaded_action (void)
13691 char *rslt
= nullptr;
13693 if (next_cmd
< this_utp
->cmd_strings
.size ())
13695 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
13702 /* Given information about a tracepoint as recorded on a target (which
13703 can be either a live system or a trace file), attempt to create an
13704 equivalent GDB tracepoint. This is not a reliable process, since
13705 the target does not necessarily have all the information used when
13706 the tracepoint was originally defined. */
13708 struct tracepoint
*
13709 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
13711 const char *addr_str
;
13712 char small_buf
[100];
13713 struct tracepoint
*tp
;
13715 if (utp
->at_string
)
13716 addr_str
= utp
->at_string
.get ();
13719 /* In the absence of a source location, fall back to raw
13720 address. Since there is no way to confirm that the address
13721 means the same thing as when the trace was started, warn the
13723 warning (_("Uploaded tracepoint %d has no "
13724 "source location, using raw address"),
13726 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
13727 addr_str
= small_buf
;
13730 /* There's not much we can do with a sequence of bytecodes. */
13731 if (utp
->cond
&& !utp
->cond_string
)
13732 warning (_("Uploaded tracepoint %d condition "
13733 "has no source form, ignoring it"),
13736 event_location_up location
= string_to_event_location (&addr_str
,
13738 if (!create_breakpoint (get_current_arch (),
13740 utp
->cond_string
.get (), -1, addr_str
,
13741 false /* force_condition */,
13742 0 /* parse cond/thread */,
13744 utp
->type
/* type_wanted */,
13745 0 /* Ignore count */,
13746 pending_break_support
,
13747 &base_breakpoint_ops
,
13749 utp
->enabled
/* enabled */,
13751 CREATE_BREAKPOINT_FLAGS_INSERTED
))
13754 /* Get the tracepoint we just created. */
13755 tp
= get_tracepoint (tracepoint_count
);
13756 gdb_assert (tp
!= NULL
);
13760 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
13763 trace_pass_command (small_buf
, 0);
13766 /* If we have uploaded versions of the original commands, set up a
13767 special-purpose "reader" function and call the usual command line
13768 reader, then pass the result to the breakpoint command-setting
13770 if (!utp
->cmd_strings
.empty ())
13772 counted_command_line cmd_list
;
13777 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
13779 breakpoint_set_commands (tp
, std::move (cmd_list
));
13781 else if (!utp
->actions
.empty ()
13782 || !utp
->step_actions
.empty ())
13783 warning (_("Uploaded tracepoint %d actions "
13784 "have no source form, ignoring them"),
13787 /* Copy any status information that might be available. */
13788 tp
->hit_count
= utp
->hit_count
;
13789 tp
->traceframe_usage
= utp
->traceframe_usage
;
13794 /* Print information on tracepoint number TPNUM_EXP, or all if
13798 info_tracepoints_command (const char *args
, int from_tty
)
13800 struct ui_out
*uiout
= current_uiout
;
13803 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
13805 if (num_printed
== 0)
13807 if (args
== NULL
|| *args
== '\0')
13808 uiout
->message ("No tracepoints.\n");
13810 uiout
->message ("No tracepoint matching '%s'.\n", args
);
13813 default_collect_info ();
13816 /* The 'enable trace' command enables tracepoints.
13817 Not supported by all targets. */
13819 enable_trace_command (const char *args
, int from_tty
)
13821 enable_command (args
, from_tty
);
13824 /* The 'disable trace' command disables tracepoints.
13825 Not supported by all targets. */
13827 disable_trace_command (const char *args
, int from_tty
)
13829 disable_command (args
, from_tty
);
13832 /* Remove a tracepoint (or all if no argument). */
13834 delete_trace_command (const char *arg
, int from_tty
)
13840 int breaks_to_delete
= 0;
13842 /* Delete all breakpoints if no argument.
13843 Do not delete internal or call-dummy breakpoints, these
13844 have to be deleted with an explicit breakpoint number
13846 for (breakpoint
*tp
: all_tracepoints ())
13847 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
13849 breaks_to_delete
= 1;
13853 /* Ask user only if there are some breakpoints to delete. */
13855 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
13857 for (breakpoint
*b
: all_breakpoints_safe ())
13858 if (is_tracepoint (b
) && user_breakpoint_p (b
))
13859 delete_breakpoint (b
);
13863 map_breakpoint_numbers
13864 (arg
, [&] (breakpoint
*br
)
13866 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13870 /* Helper function for trace_pass_command. */
13873 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
13875 tp
->pass_count
= count
;
13876 gdb::observers::breakpoint_modified
.notify (tp
);
13878 gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
13879 tp
->number
, count
);
13882 /* Set passcount for tracepoint.
13884 First command argument is passcount, second is tracepoint number.
13885 If tracepoint number omitted, apply to most recently defined.
13886 Also accepts special argument "all". */
13889 trace_pass_command (const char *args
, int from_tty
)
13891 struct tracepoint
*t1
;
13894 if (args
== 0 || *args
== 0)
13895 error (_("passcount command requires an "
13896 "argument (count + optional TP num)"));
13898 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
13900 args
= skip_spaces (args
);
13901 if (*args
&& strncasecmp (args
, "all", 3) == 0)
13903 args
+= 3; /* Skip special argument "all". */
13905 error (_("Junk at end of arguments."));
13907 for (breakpoint
*b
: all_tracepoints ())
13909 t1
= (struct tracepoint
*) b
;
13910 trace_pass_set_count (t1
, count
, from_tty
);
13913 else if (*args
== '\0')
13915 t1
= get_tracepoint_by_number (&args
, NULL
);
13917 trace_pass_set_count (t1
, count
, from_tty
);
13921 number_or_range_parser
parser (args
);
13922 while (!parser
.finished ())
13924 t1
= get_tracepoint_by_number (&args
, &parser
);
13926 trace_pass_set_count (t1
, count
, from_tty
);
13931 struct tracepoint
*
13932 get_tracepoint (int num
)
13934 for (breakpoint
*t
: all_tracepoints ())
13935 if (t
->number
== num
)
13936 return (struct tracepoint
*) t
;
13941 /* Find the tracepoint with the given target-side number (which may be
13942 different from the tracepoint number after disconnecting and
13945 struct tracepoint
*
13946 get_tracepoint_by_number_on_target (int num
)
13948 for (breakpoint
*b
: all_tracepoints ())
13950 struct tracepoint
*t
= (struct tracepoint
*) b
;
13952 if (t
->number_on_target
== num
)
13959 /* Utility: parse a tracepoint number and look it up in the list.
13960 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13961 If the argument is missing, the most recent tracepoint
13962 (tracepoint_count) is returned. */
13964 struct tracepoint
*
13965 get_tracepoint_by_number (const char **arg
,
13966 number_or_range_parser
*parser
)
13969 const char *instring
= arg
== NULL
? NULL
: *arg
;
13971 if (parser
!= NULL
)
13973 gdb_assert (!parser
->finished ());
13974 tpnum
= parser
->get_number ();
13976 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
13977 tpnum
= tracepoint_count
;
13979 tpnum
= get_number (arg
);
13983 if (instring
&& *instring
)
13984 gdb_printf (_("bad tracepoint number at or near '%s'\n"),
13987 gdb_printf (_("No previous tracepoint\n"));
13991 for (breakpoint
*t
: all_tracepoints ())
13992 if (t
->number
== tpnum
)
13993 return (struct tracepoint
*) t
;
13995 gdb_printf ("No tracepoint number %d.\n", tpnum
);
14000 breakpoint::print_recreate_thread (struct ui_file
*fp
) const
14003 gdb_printf (fp
, " thread %d", thread
);
14006 gdb_printf (fp
, " task %d", task
);
14008 gdb_printf (fp
, "\n");
14011 /* Save information on user settable breakpoints (watchpoints, etc) to
14012 a new script file named FILENAME. If FILTER is non-NULL, call it
14013 on each breakpoint and only include the ones for which it returns
14017 save_breakpoints (const char *filename
, int from_tty
,
14018 bool (*filter
) (const struct breakpoint
*))
14021 int extra_trace_bits
= 0;
14023 if (filename
== 0 || *filename
== 0)
14024 error (_("Argument required (file name in which to save)"));
14026 /* See if we have anything to save. */
14027 for (breakpoint
*tp
: all_breakpoints ())
14029 /* Skip internal and momentary breakpoints. */
14030 if (!user_breakpoint_p (tp
))
14033 /* If we have a filter, only save the breakpoints it accepts. */
14034 if (filter
&& !filter (tp
))
14039 if (is_tracepoint (tp
))
14041 extra_trace_bits
= 1;
14043 /* We can stop searching. */
14050 warning (_("Nothing to save."));
14054 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14058 if (!fp
.open (expanded_filename
.get (), "w"))
14059 error (_("Unable to open file '%s' for saving (%s)"),
14060 expanded_filename
.get (), safe_strerror (errno
));
14062 if (extra_trace_bits
)
14063 save_trace_state_variables (&fp
);
14065 for (breakpoint
*tp
: all_breakpoints ())
14067 /* Skip internal and momentary breakpoints. */
14068 if (!user_breakpoint_p (tp
))
14071 /* If we have a filter, only save the breakpoints it accepts. */
14072 if (filter
&& !filter (tp
))
14075 tp
->print_recreate (&fp
);
14077 /* Note, we can't rely on tp->number for anything, as we can't
14078 assume the recreated breakpoint numbers will match. Use $bpnum
14081 if (tp
->cond_string
)
14082 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
.get ());
14084 if (tp
->ignore_count
)
14085 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14087 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
14089 fp
.puts (" commands\n");
14091 current_uiout
->redirect (&fp
);
14094 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
14096 catch (const gdb_exception
&ex
)
14098 current_uiout
->redirect (NULL
);
14102 current_uiout
->redirect (NULL
);
14103 fp
.puts (" end\n");
14106 if (tp
->enable_state
== bp_disabled
)
14107 fp
.puts ("disable $bpnum\n");
14109 /* If this is a multi-location breakpoint, check if the locations
14110 should be individually disabled. Watchpoint locations are
14111 special, and not user visible. */
14112 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14116 for (bp_location
*loc
: tp
->locations ())
14119 fp
.printf ("disable $bpnum.%d\n", n
);
14126 if (extra_trace_bits
&& !default_collect
.empty ())
14127 fp
.printf ("set default-collect %s\n", default_collect
.c_str ());
14130 gdb_printf (_("Saved to file '%s'.\n"), expanded_filename
.get ());
14133 /* The `save breakpoints' command. */
14136 save_breakpoints_command (const char *args
, int from_tty
)
14138 save_breakpoints (args
, from_tty
, NULL
);
14141 /* The `save tracepoints' command. */
14144 save_tracepoints_command (const char *args
, int from_tty
)
14146 save_breakpoints (args
, from_tty
, is_tracepoint
);
14150 /* This help string is used to consolidate all the help string for specifying
14151 locations used by several commands. */
14153 #define LOCATION_HELP_STRING \
14154 "Linespecs are colon-separated lists of location parameters, such as\n\
14155 source filename, function name, label name, and line number.\n\
14156 Example: To specify the start of a label named \"the_top\" in the\n\
14157 function \"fact\" in the file \"factorial.c\", use\n\
14158 \"factorial.c:fact:the_top\".\n\
14160 Address locations begin with \"*\" and specify an exact address in the\n\
14161 program. Example: To specify the fourth byte past the start function\n\
14162 \"main\", use \"*main + 4\".\n\
14164 Explicit locations are similar to linespecs but use an option/argument\n\
14165 syntax to specify location parameters.\n\
14166 Example: To specify the start of the label named \"the_top\" in the\n\
14167 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
14168 -function fact -label the_top\".\n\
14170 By default, a specified function is matched against the program's\n\
14171 functions in all scopes. For C++, this means in all namespaces and\n\
14172 classes. For Ada, this means in all packages. E.g., in C++,\n\
14173 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
14174 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
14175 specified name as a complete fully-qualified name instead."
14177 /* This help string is used for the break, hbreak, tbreak and thbreak
14178 commands. It is defined as a macro to prevent duplication.
14179 COMMAND should be a string constant containing the name of the
14182 #define BREAK_ARGS_HELP(command) \
14183 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
14184 \t[-force-condition] [if CONDITION]\n\
14185 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
14186 probe point. Accepted values are `-probe' (for a generic, automatically\n\
14187 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
14188 `-probe-dtrace' (for a DTrace probe).\n\
14189 LOCATION may be a linespec, address, or explicit location as described\n\
14192 With no LOCATION, uses current execution address of the selected\n\
14193 stack frame. This is useful for breaking on return to a stack frame.\n\
14195 THREADNUM is the number from \"info threads\".\n\
14196 CONDITION is a boolean expression.\n\
14198 With the \"-force-condition\" flag, the condition is defined even when\n\
14199 it is invalid for all current locations.\n\
14200 \n" LOCATION_HELP_STRING "\n\n\
14201 Multiple breakpoints at one place are permitted, and useful if their\n\
14202 conditions are different.\n\
14204 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14206 /* List of subcommands for "catch". */
14207 static struct cmd_list_element
*catch_cmdlist
;
14209 /* List of subcommands for "tcatch". */
14210 static struct cmd_list_element
*tcatch_cmdlist
;
14213 add_catch_command (const char *name
, const char *docstring
,
14214 cmd_func_ftype
*func
,
14215 completer_ftype
*completer
,
14216 void *user_data_catch
,
14217 void *user_data_tcatch
)
14219 struct cmd_list_element
*command
;
14221 command
= add_cmd (name
, class_breakpoint
, docstring
,
14223 command
->func
= func
;
14224 command
->set_context (user_data_catch
);
14225 set_cmd_completer (command
, completer
);
14227 command
= add_cmd (name
, class_breakpoint
, docstring
,
14229 command
->func
= func
;
14230 command
->set_context (user_data_tcatch
);
14231 set_cmd_completer (command
, completer
);
14234 /* Zero if any of the breakpoint's locations could be a location where
14235 functions have been inlined, nonzero otherwise. */
14238 is_non_inline_function (struct breakpoint
*b
)
14240 /* The shared library event breakpoint is set on the address of a
14241 non-inline function. */
14242 if (b
->type
== bp_shlib_event
)
14248 /* Nonzero if the specified PC cannot be a location where functions
14249 have been inlined. */
14252 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
14253 const target_waitstatus
&ws
)
14255 for (breakpoint
*b
: all_breakpoints ())
14257 if (!is_non_inline_function (b
))
14260 for (bp_location
*bl
: b
->locations ())
14262 if (!bl
->shlib_disabled
14263 && bpstat_check_location (bl
, aspace
, pc
, ws
))
14271 /* Remove any references to OBJFILE which is going to be freed. */
14274 breakpoint_free_objfile (struct objfile
*objfile
)
14276 for (bp_location
*loc
: all_bp_locations ())
14277 if (loc
->symtab
!= NULL
&& loc
->symtab
->compunit ()->objfile () == objfile
)
14278 loc
->symtab
= NULL
;
14281 /* Chain containing all defined "enable breakpoint" subcommands. */
14283 static struct cmd_list_element
*enablebreaklist
= NULL
;
14285 /* See breakpoint.h. */
14287 cmd_list_element
*commands_cmd_element
= nullptr;
14289 void _initialize_breakpoint ();
14291 _initialize_breakpoint ()
14293 struct cmd_list_element
*c
;
14295 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
14297 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
14299 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
14302 breakpoint_chain
= 0;
14303 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14304 before a breakpoint is set. */
14305 breakpoint_count
= 0;
14307 tracepoint_count
= 0;
14309 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
14310 Set ignore-count of breakpoint number N to COUNT.\n\
14311 Usage is `ignore N COUNT'."));
14313 commands_cmd_element
= add_com ("commands", class_breakpoint
,
14314 commands_command
, _("\
14315 Set commands to be executed when the given breakpoints are hit.\n\
14316 Give a space-separated breakpoint list as argument after \"commands\".\n\
14317 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
14319 With no argument, the targeted breakpoint is the last one set.\n\
14320 The commands themselves follow starting on the next line.\n\
14321 Type a line containing \"end\" to indicate the end of them.\n\
14322 Give \"silent\" as the first line to make the breakpoint silent;\n\
14323 then no output is printed when it is hit, except what the commands print."));
14325 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
14326 static std::string condition_command_help
14327 = gdb::option::build_help (_("\
14328 Specify breakpoint number N to break only if COND is true.\n\
14329 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
14330 is an expression to be evaluated whenever breakpoint N is reached.\n\
14333 %OPTIONS%"), cc_opts
);
14335 c
= add_com ("condition", class_breakpoint
, condition_command
,
14336 condition_command_help
.c_str ());
14337 set_cmd_completer_handle_brkchars (c
, condition_completer
);
14339 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
14340 Set a temporary breakpoint.\n\
14341 Like \"break\" except the breakpoint is only temporary,\n\
14342 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14343 by using \"enable delete\" on the breakpoint number.\n\
14345 BREAK_ARGS_HELP ("tbreak")));
14346 set_cmd_completer (c
, location_completer
);
14348 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
14349 Set a hardware assisted breakpoint.\n\
14350 Like \"break\" except the breakpoint requires hardware support,\n\
14351 some target hardware may not have this support.\n\
14353 BREAK_ARGS_HELP ("hbreak")));
14354 set_cmd_completer (c
, location_completer
);
14356 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
14357 Set a temporary hardware assisted breakpoint.\n\
14358 Like \"hbreak\" except the breakpoint is only temporary,\n\
14359 so it will be deleted when hit.\n\
14361 BREAK_ARGS_HELP ("thbreak")));
14362 set_cmd_completer (c
, location_completer
);
14364 cmd_list_element
*enable_cmd
14365 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
14366 Enable all or some breakpoints.\n\
14367 Usage: enable [BREAKPOINTNUM]...\n\
14368 Give breakpoint numbers (separated by spaces) as arguments.\n\
14369 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14370 This is used to cancel the effect of the \"disable\" command.\n\
14371 With a subcommand you can enable temporarily."),
14372 &enablelist
, 1, &cmdlist
);
14374 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
14376 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
14377 Enable all or some breakpoints.\n\
14378 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
14379 Give breakpoint numbers (separated by spaces) as arguments.\n\
14380 This is used to cancel the effect of the \"disable\" command.\n\
14381 May be abbreviated to simply \"enable\"."),
14382 &enablebreaklist
, 1, &enablelist
);
14384 add_cmd ("once", no_class
, enable_once_command
, _("\
14385 Enable some breakpoints for one hit.\n\
14386 Usage: enable breakpoints once BREAKPOINTNUM...\n\
14387 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14390 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14391 Enable some breakpoints and delete when hit.\n\
14392 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
14393 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14396 add_cmd ("count", no_class
, enable_count_command
, _("\
14397 Enable some breakpoints for COUNT hits.\n\
14398 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
14399 If a breakpoint is hit while enabled in this fashion,\n\
14400 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14403 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14404 Enable some breakpoints and delete when hit.\n\
14405 Usage: enable delete BREAKPOINTNUM...\n\
14406 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14409 add_cmd ("once", no_class
, enable_once_command
, _("\
14410 Enable some breakpoints for one hit.\n\
14411 Usage: enable once BREAKPOINTNUM...\n\
14412 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14415 add_cmd ("count", no_class
, enable_count_command
, _("\
14416 Enable some breakpoints for COUNT hits.\n\
14417 Usage: enable count COUNT BREAKPOINTNUM...\n\
14418 If a breakpoint is hit while enabled in this fashion,\n\
14419 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14422 cmd_list_element
*disable_cmd
14423 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
14424 Disable all or some breakpoints.\n\
14425 Usage: disable [BREAKPOINTNUM]...\n\
14426 Arguments are breakpoint numbers with spaces in between.\n\
14427 To disable all breakpoints, give no argument.\n\
14428 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14429 &disablelist
, 1, &cmdlist
);
14430 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
14431 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
14433 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
14434 Disable all or some breakpoints.\n\
14435 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
14436 Arguments are breakpoint numbers with spaces in between.\n\
14437 To disable all breakpoints, give no argument.\n\
14438 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14439 This command may be abbreviated \"disable\"."),
14442 cmd_list_element
*delete_cmd
14443 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
14444 Delete all or some breakpoints.\n\
14445 Usage: delete [BREAKPOINTNUM]...\n\
14446 Arguments are breakpoint numbers with spaces in between.\n\
14447 To delete all breakpoints, give no argument.\n\
14449 Also a prefix command for deletion of other GDB objects."),
14450 &deletelist
, 1, &cmdlist
);
14451 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
14452 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
14454 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
14455 Delete all or some breakpoints or auto-display expressions.\n\
14456 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
14457 Arguments are breakpoint numbers with spaces in between.\n\
14458 To delete all breakpoints, give no argument.\n\
14459 This command may be abbreviated \"delete\"."),
14462 cmd_list_element
*clear_cmd
14463 = add_com ("clear", class_breakpoint
, clear_command
, _("\
14464 Clear breakpoint at specified location.\n\
14465 Argument may be a linespec, explicit, or address location as described below.\n\
14467 With no argument, clears all breakpoints in the line that the selected frame\n\
14468 is executing in.\n"
14469 "\n" LOCATION_HELP_STRING
"\n\n\
14470 See also the \"delete\" command which clears breakpoints by number."));
14471 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
14473 cmd_list_element
*break_cmd
14474 = add_com ("break", class_breakpoint
, break_command
, _("\
14475 Set breakpoint at specified location.\n"
14476 BREAK_ARGS_HELP ("break")));
14477 set_cmd_completer (break_cmd
, location_completer
);
14479 add_com_alias ("b", break_cmd
, class_run
, 1);
14480 add_com_alias ("br", break_cmd
, class_run
, 1);
14481 add_com_alias ("bre", break_cmd
, class_run
, 1);
14482 add_com_alias ("brea", break_cmd
, class_run
, 1);
14484 cmd_list_element
*info_breakpoints_cmd
14485 = add_info ("breakpoints", info_breakpoints_command
, _("\
14486 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14487 The \"Type\" column indicates one of:\n\
14488 \tbreakpoint - normal breakpoint\n\
14489 \twatchpoint - watchpoint\n\
14490 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14491 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14492 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14493 address and file/line number respectively.\n\
14495 Convenience variable \"$_\" and default examine address for \"x\"\n\
14496 are set to the address of the last breakpoint listed unless the command\n\
14497 is prefixed with \"server \".\n\n\
14498 Convenience variable \"$bpnum\" contains the number of the last\n\
14499 breakpoint set."));
14501 add_info_alias ("b", info_breakpoints_cmd
, 1);
14503 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
14504 Status of all breakpoints, or breakpoint number NUMBER.\n\
14505 The \"Type\" column indicates one of:\n\
14506 \tbreakpoint - normal breakpoint\n\
14507 \twatchpoint - watchpoint\n\
14508 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14509 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14510 \tuntil - internal breakpoint used by the \"until\" command\n\
14511 \tfinish - internal breakpoint used by the \"finish\" command\n\
14512 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14513 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14514 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14515 address and file/line number respectively.\n\
14517 Convenience variable \"$_\" and default examine address for \"x\"\n\
14518 are set to the address of the last breakpoint listed unless the command\n\
14519 is prefixed with \"server \".\n\n\
14520 Convenience variable \"$bpnum\" contains the number of the last\n\
14522 &maintenanceinfolist
);
14524 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
14525 Set catchpoints to catch events."),
14527 0/*allow-unknown*/, &cmdlist
);
14529 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
14530 Set temporary catchpoints to catch events."),
14532 0/*allow-unknown*/, &cmdlist
);
14534 const auto opts
= make_watch_options_def_group (nullptr);
14536 static const std::string watch_help
= gdb::option::build_help (_("\
14537 Set a watchpoint for EXPRESSION.\n\
14538 Usage: watch [-location] EXPRESSION\n\
14543 A watchpoint stops execution of your program whenever the value of\n\
14544 an expression changes."), opts
);
14545 c
= add_com ("watch", class_breakpoint
, watch_command
,
14546 watch_help
.c_str ());
14547 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14549 static const std::string rwatch_help
= gdb::option::build_help (_("\
14550 Set a read watchpoint for EXPRESSION.\n\
14551 Usage: rwatch [-location] EXPRESSION\n\
14556 A read watchpoint stops execution of your program whenever the value of\n\
14557 an expression is read."), opts
);
14558 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
14559 rwatch_help
.c_str ());
14560 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14562 static const std::string awatch_help
= gdb::option::build_help (_("\
14563 Set an access watchpoint for EXPRESSION.\n\
14564 Usage: awatch [-location] EXPRESSION\n\
14569 An access watchpoint stops execution of your program whenever the value\n\
14570 of an expression is either read or written."), opts
);
14571 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
14572 awatch_help
.c_str ());
14573 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14575 add_info ("watchpoints", info_watchpoints_command
, _("\
14576 Status of specified watchpoints (all watchpoints if no argument)."));
14578 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14579 respond to changes - contrary to the description. */
14580 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14581 &can_use_hw_watchpoints
, _("\
14582 Set debugger's willingness to use watchpoint hardware."), _("\
14583 Show debugger's willingness to use watchpoint hardware."), _("\
14584 If zero, gdb will not use hardware for new watchpoints, even if\n\
14585 such is available. (However, any hardware watchpoints that were\n\
14586 created before setting this to nonzero, will continue to use watchpoint\n\
14589 show_can_use_hw_watchpoints
,
14590 &setlist
, &showlist
);
14592 can_use_hw_watchpoints
= 1;
14594 /* Tracepoint manipulation commands. */
14596 cmd_list_element
*trace_cmd
14597 = add_com ("trace", class_breakpoint
, trace_command
, _("\
14598 Set a tracepoint at specified location.\n\
14600 BREAK_ARGS_HELP ("trace") "\n\
14601 Do \"help tracepoints\" for info on other tracepoint commands."));
14602 set_cmd_completer (trace_cmd
, location_completer
);
14604 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
14605 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
14606 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
14607 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
14609 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14610 Set a fast tracepoint at specified location.\n\
14612 BREAK_ARGS_HELP ("ftrace") "\n\
14613 Do \"help tracepoints\" for info on other tracepoint commands."));
14614 set_cmd_completer (c
, location_completer
);
14616 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
14617 Set a static tracepoint at location or marker.\n\
14619 strace [LOCATION] [if CONDITION]\n\
14620 LOCATION may be a linespec, explicit, or address location (described below) \n\
14621 or -m MARKER_ID.\n\n\
14622 If a marker id is specified, probe the marker with that name. With\n\
14623 no LOCATION, uses current execution address of the selected stack frame.\n\
14624 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14625 This collects arbitrary user data passed in the probe point call to the\n\
14626 tracing library. You can inspect it when analyzing the trace buffer,\n\
14627 by printing the $_sdata variable like any other convenience variable.\n\
14629 CONDITION is a boolean expression.\n\
14630 \n" LOCATION_HELP_STRING
"\n\n\
14631 Multiple tracepoints at one place are permitted, and useful if their\n\
14632 conditions are different.\n\
14634 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14635 Do \"help tracepoints\" for info on other tracepoint commands."));
14636 set_cmd_completer (c
, location_completer
);
14638 cmd_list_element
*info_tracepoints_cmd
14639 = add_info ("tracepoints", info_tracepoints_command
, _("\
14640 Status of specified tracepoints (all tracepoints if no argument).\n\
14641 Convenience variable \"$tpnum\" contains the number of the\n\
14642 last tracepoint set."));
14644 add_info_alias ("tp", info_tracepoints_cmd
, 1);
14646 cmd_list_element
*delete_tracepoints_cmd
14647 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
14648 Delete specified tracepoints.\n\
14649 Arguments are tracepoint numbers, separated by spaces.\n\
14650 No argument means delete all tracepoints."),
14652 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
14654 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
14655 Disable specified tracepoints.\n\
14656 Arguments are tracepoint numbers, separated by spaces.\n\
14657 No argument means disable all tracepoints."),
14659 deprecate_cmd (c
, "disable");
14661 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
14662 Enable specified tracepoints.\n\
14663 Arguments are tracepoint numbers, separated by spaces.\n\
14664 No argument means enable all tracepoints."),
14666 deprecate_cmd (c
, "enable");
14668 add_com ("passcount", class_trace
, trace_pass_command
, _("\
14669 Set the passcount for a tracepoint.\n\
14670 The trace will end when the tracepoint has been passed 'count' times.\n\
14671 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14672 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14674 add_basic_prefix_cmd ("save", class_breakpoint
,
14675 _("Save breakpoint definitions as a script."),
14677 0/*allow-unknown*/, &cmdlist
);
14679 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
14680 Save current breakpoint definitions as a script.\n\
14681 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14682 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14683 session to restore them."),
14685 set_cmd_completer (c
, filename_completer
);
14687 cmd_list_element
*save_tracepoints_cmd
14688 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
14689 Save current tracepoint definitions as a script.\n\
14690 Use the 'source' command in another debug session to restore them."),
14692 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
14694 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
14695 deprecate_cmd (c
, "save tracepoints");
14697 add_setshow_prefix_cmd ("breakpoint", class_maintenance
,
14699 Breakpoint specific settings.\n\
14700 Configure various breakpoint-specific variables such as\n\
14701 pending breakpoint behavior."),
14703 Breakpoint specific settings.\n\
14704 Configure various breakpoint-specific variables such as\n\
14705 pending breakpoint behavior."),
14706 &breakpoint_set_cmdlist
, &breakpoint_show_cmdlist
,
14707 &setlist
, &showlist
);
14709 add_setshow_auto_boolean_cmd ("pending", no_class
,
14710 &pending_break_support
, _("\
14711 Set debugger's behavior regarding pending breakpoints."), _("\
14712 Show debugger's behavior regarding pending breakpoints."), _("\
14713 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14714 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14715 an error. If auto, an unrecognized breakpoint location results in a\n\
14716 user-query to see if a pending breakpoint should be created."),
14718 show_pending_break_support
,
14719 &breakpoint_set_cmdlist
,
14720 &breakpoint_show_cmdlist
);
14722 pending_break_support
= AUTO_BOOLEAN_AUTO
;
14724 add_setshow_boolean_cmd ("auto-hw", no_class
,
14725 &automatic_hardware_breakpoints
, _("\
14726 Set automatic usage of hardware breakpoints."), _("\
14727 Show automatic usage of hardware breakpoints."), _("\
14728 If set, the debugger will automatically use hardware breakpoints for\n\
14729 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14730 a warning will be emitted for such breakpoints."),
14732 show_automatic_hardware_breakpoints
,
14733 &breakpoint_set_cmdlist
,
14734 &breakpoint_show_cmdlist
);
14736 add_setshow_boolean_cmd ("always-inserted", class_support
,
14737 &always_inserted_mode
, _("\
14738 Set mode for inserting breakpoints."), _("\
14739 Show mode for inserting breakpoints."), _("\
14740 When this mode is on, breakpoints are inserted immediately as soon as\n\
14741 they're created, kept inserted even when execution stops, and removed\n\
14742 only when the user deletes them. When this mode is off (the default),\n\
14743 breakpoints are inserted only when execution continues, and removed\n\
14744 when execution stops."),
14746 &show_always_inserted_mode
,
14747 &breakpoint_set_cmdlist
,
14748 &breakpoint_show_cmdlist
);
14750 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
14751 condition_evaluation_enums
,
14752 &condition_evaluation_mode_1
, _("\
14753 Set mode of breakpoint condition evaluation."), _("\
14754 Show mode of breakpoint condition evaluation."), _("\
14755 When this is set to \"host\", breakpoint conditions will be\n\
14756 evaluated on the host's side by GDB. When it is set to \"target\",\n\
14757 breakpoint conditions will be downloaded to the target (if the target\n\
14758 supports such feature) and conditions will be evaluated on the target's side.\n\
14759 If this is set to \"auto\" (default), this will be automatically set to\n\
14760 \"target\" if it supports condition evaluation, otherwise it will\n\
14761 be set to \"host\"."),
14762 &set_condition_evaluation_mode
,
14763 &show_condition_evaluation_mode
,
14764 &breakpoint_set_cmdlist
,
14765 &breakpoint_show_cmdlist
);
14767 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
14768 Set a breakpoint for an address range.\n\
14769 break-range START-LOCATION, END-LOCATION\n\
14770 where START-LOCATION and END-LOCATION can be one of the following:\n\
14771 LINENUM, for that line in the current file,\n\
14772 FILE:LINENUM, for that line in that file,\n\
14773 +OFFSET, for that number of lines after the current line\n\
14774 or the start of the range\n\
14775 FUNCTION, for the first line in that function,\n\
14776 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14777 *ADDRESS, for the instruction at that address.\n\
14779 The breakpoint will stop execution of the inferior whenever it executes\n\
14780 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14781 range (including START-LOCATION and END-LOCATION)."));
14783 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
14784 Set a dynamic printf at specified location.\n\
14785 dprintf location,format string,arg1,arg2,...\n\
14786 location may be a linespec, explicit, or address location.\n"
14787 "\n" LOCATION_HELP_STRING
));
14788 set_cmd_completer (c
, location_completer
);
14790 add_setshow_enum_cmd ("dprintf-style", class_support
,
14791 dprintf_style_enums
, &dprintf_style
, _("\
14792 Set the style of usage for dynamic printf."), _("\
14793 Show the style of usage for dynamic printf."), _("\
14794 This setting chooses how GDB will do a dynamic printf.\n\
14795 If the value is \"gdb\", then the printing is done by GDB to its own\n\
14796 console, as with the \"printf\" command.\n\
14797 If the value is \"call\", the print is done by calling a function in your\n\
14798 program; by default printf(), but you can choose a different function or\n\
14799 output stream by setting dprintf-function and dprintf-channel."),
14800 update_dprintf_commands
, NULL
,
14801 &setlist
, &showlist
);
14803 add_setshow_string_cmd ("dprintf-function", class_support
,
14804 &dprintf_function
, _("\
14805 Set the function to use for dynamic printf."), _("\
14806 Show the function to use for dynamic printf."), NULL
,
14807 update_dprintf_commands
, NULL
,
14808 &setlist
, &showlist
);
14810 add_setshow_string_cmd ("dprintf-channel", class_support
,
14811 &dprintf_channel
, _("\
14812 Set the channel to use for dynamic printf."), _("\
14813 Show the channel to use for dynamic printf."), NULL
,
14814 update_dprintf_commands
, NULL
,
14815 &setlist
, &showlist
);
14817 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
14818 &disconnected_dprintf
, _("\
14819 Set whether dprintf continues after GDB disconnects."), _("\
14820 Show whether dprintf continues after GDB disconnects."), _("\
14821 Use this to let dprintf commands continue to hit and produce output\n\
14822 even if GDB disconnects or detaches from the target."),
14825 &setlist
, &showlist
);
14827 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
14828 Target agent only formatted printing, like the C \"printf\" function.\n\
14829 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
14830 This supports most C printf format specifications, like %s, %d, etc.\n\
14831 This is useful for formatted output in user-defined commands."));
14833 automatic_hardware_breakpoints
= true;
14835 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
14837 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,