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 (struct breakpoint
*);
115 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
117 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
118 const struct symtab_and_line
*);
120 /* This function is used in gdbtk sources and thus can not be made
122 static struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
123 struct symtab_and_line
,
126 static struct breakpoint
*
127 momentary_breakpoint_from_master (struct breakpoint
*orig
,
131 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
133 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
137 static void describe_other_breakpoints (struct gdbarch
*,
138 struct program_space
*, CORE_ADDR
,
139 struct obj_section
*, int);
141 static int watchpoint_locations_match (struct bp_location
*loc1
,
142 struct bp_location
*loc2
);
144 static int breakpoint_locations_match (struct bp_location
*loc1
,
145 struct bp_location
*loc2
,
146 bool sw_hw_bps_match
= false);
148 static int breakpoint_location_address_match (struct bp_location
*bl
,
149 const struct address_space
*aspace
,
152 static int breakpoint_location_address_range_overlap (struct bp_location
*,
153 const address_space
*,
156 static int remove_breakpoint (struct bp_location
*);
157 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
159 static enum print_stop_action
print_bp_stop_message (bpstat
*bs
);
161 static int hw_breakpoint_used_count (void);
163 static int hw_watchpoint_use_count (struct breakpoint
*);
165 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
167 int *other_type_used
);
169 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
172 static void decref_bp_location (struct bp_location
**loc
);
174 static std::vector
<symtab_and_line
> bkpt_probe_decode_location
175 (struct breakpoint
*b
,
176 struct event_location
*location
,
177 struct program_space
*search_pspace
);
179 /* update_global_location_list's modes of operation wrt to whether to
180 insert locations now. */
181 enum ugll_insert_mode
183 /* Don't insert any breakpoint locations into the inferior, only
184 remove already-inserted locations that no longer should be
185 inserted. Functions that delete a breakpoint or breakpoints
186 should specify this mode, so that deleting a breakpoint doesn't
187 have the side effect of inserting the locations of other
188 breakpoints that are marked not-inserted, but should_be_inserted
189 returns true on them.
191 This behavior is useful is situations close to tear-down -- e.g.,
192 after an exec, while the target still has execution, but
193 breakpoint shadows of the previous executable image should *NOT*
194 be restored to the new image; or before detaching, where the
195 target still has execution and wants to delete breakpoints from
196 GDB's lists, and all breakpoints had already been removed from
200 /* May insert breakpoints iff breakpoints_should_be_inserted_now
201 claims breakpoints should be inserted now. */
204 /* Insert locations now, irrespective of
205 breakpoints_should_be_inserted_now. E.g., say all threads are
206 stopped right now, and the user did "continue". We need to
207 insert breakpoints _before_ resuming the target, but
208 UGLL_MAY_INSERT wouldn't insert them, because
209 breakpoints_should_be_inserted_now returns false at that point,
210 as no thread is running yet. */
214 static void update_global_location_list (enum ugll_insert_mode
);
216 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
218 static void insert_breakpoint_locations (void);
220 static void trace_pass_command (const char *, int);
222 static void set_tracepoint_count (int num
);
224 static bool is_masked_watchpoint (const struct breakpoint
*b
);
226 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
229 static int strace_marker_p (struct breakpoint
*b
);
231 static void bkpt_probe_create_sals_from_location
232 (struct event_location
*location
,
233 struct linespec_result
*canonical
);
234 static void tracepoint_probe_create_sals_from_location
235 (struct event_location
*location
,
236 struct linespec_result
*canonical
);
238 const struct breakpoint_ops base_breakpoint_ops
=
240 create_sals_from_location_default
,
241 create_breakpoints_sal
,
244 /* Breakpoints set on probes. */
245 static const struct breakpoint_ops bkpt_probe_breakpoint_ops
=
247 bkpt_probe_create_sals_from_location
,
248 create_breakpoints_sal
,
251 /* Tracepoints set on probes. */
252 static const struct breakpoint_ops tracepoint_probe_breakpoint_ops
=
254 tracepoint_probe_create_sals_from_location
,
255 create_breakpoints_sal
,
258 /* The structure to be used in regular breakpoints. */
259 struct ordinary_breakpoint
: public base_breakpoint
261 int resources_needed (const struct bp_location
*) override
;
262 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
263 void print_mention () override
;
264 void print_recreate (struct ui_file
*fp
) override
;
267 /* Internal breakpoints. */
268 struct internal_breakpoint
: public base_breakpoint
270 void re_set () override
;
271 void check_status (struct bpstat
*bs
) override
;
272 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
273 void print_mention () override
;
276 /* Momentary breakpoints. */
277 struct momentary_breakpoint
: public base_breakpoint
279 void re_set () override
;
280 void check_status (struct bpstat
*bs
) override
;
281 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
282 void print_mention () override
;
285 /* DPrintf breakpoints. */
286 struct dprintf_breakpoint
: public ordinary_breakpoint
288 void re_set () override
;
289 int breakpoint_hit (const struct bp_location
*bl
,
290 const address_space
*aspace
,
292 const target_waitstatus
&ws
) override
;
293 void print_recreate (struct ui_file
*fp
) override
;
294 void after_condition_true (struct bpstat
*bs
) override
;
297 /* Ranged breakpoints. */
298 struct ranged_breakpoint
: public ordinary_breakpoint
300 int breakpoint_hit (const struct bp_location
*bl
,
301 const address_space
*aspace
,
303 const target_waitstatus
&ws
) override
;
304 int resources_needed (const struct bp_location
*) override
;
305 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
306 bool print_one (struct bp_location
**) override
;
307 void print_one_detail (struct ui_out
*) const override
;
308 void print_mention () override
;
309 void print_recreate (struct ui_file
*fp
) override
;
312 /* Static tracepoints with marker (`-m'). */
313 struct static_marker_tracepoint
: public tracepoint
315 std::vector
<symtab_and_line
> decode_location
316 (struct event_location
*location
,
317 struct program_space
*search_pspace
) override
;
320 /* The style in which to perform a dynamic printf. This is a user
321 option because different output options have different tradeoffs;
322 if GDB does the printing, there is better error handling if there
323 is a problem with any of the arguments, but using an inferior
324 function lets you have special-purpose printers and sending of
325 output to the same place as compiled-in print functions. */
327 static const char dprintf_style_gdb
[] = "gdb";
328 static const char dprintf_style_call
[] = "call";
329 static const char dprintf_style_agent
[] = "agent";
330 static const char *const dprintf_style_enums
[] = {
336 static const char *dprintf_style
= dprintf_style_gdb
;
338 /* The function to use for dynamic printf if the preferred style is to
339 call into the inferior. The value is simply a string that is
340 copied into the command, so it can be anything that GDB can
341 evaluate to a callable address, not necessarily a function name. */
343 static std::string dprintf_function
= "printf";
345 /* The channel to use for dynamic printf if the preferred style is to
346 call into the inferior; if a nonempty string, it will be passed to
347 the call as the first argument, with the format string as the
348 second. As with the dprintf function, this can be anything that
349 GDB knows how to evaluate, so in addition to common choices like
350 "stderr", this could be an app-specific expression like
351 "mystreams[curlogger]". */
353 static std::string dprintf_channel
;
355 /* True if dprintf commands should continue to operate even if GDB
357 static bool disconnected_dprintf
= true;
359 struct command_line
*
360 breakpoint_commands (struct breakpoint
*b
)
362 return b
->commands
? b
->commands
.get () : NULL
;
365 /* Flag indicating that a command has proceeded the inferior past the
366 current breakpoint. */
368 static bool breakpoint_proceeded
;
371 bpdisp_text (enum bpdisp disp
)
373 /* NOTE: the following values are a part of MI protocol and
374 represent values of 'disp' field returned when inferior stops at
376 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
378 return bpdisps
[(int) disp
];
381 /* Prototypes for exported functions. */
382 /* If FALSE, gdb will not use hardware support for watchpoints, even
383 if such is available. */
384 static int can_use_hw_watchpoints
;
387 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
388 struct cmd_list_element
*c
,
392 _("Debugger's willingness to use "
393 "watchpoint hardware is %s.\n"),
397 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
398 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
399 for unrecognized breakpoint locations.
400 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
401 static enum auto_boolean pending_break_support
;
403 show_pending_break_support (struct ui_file
*file
, int from_tty
,
404 struct cmd_list_element
*c
,
408 _("Debugger's behavior regarding "
409 "pending breakpoints is %s.\n"),
413 /* If true, gdb will automatically use hardware breakpoints for breakpoints
414 set with "break" but falling in read-only memory.
415 If false, gdb will warn about such breakpoints, but won't automatically
416 use hardware breakpoints. */
417 static bool automatic_hardware_breakpoints
;
419 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
420 struct cmd_list_element
*c
,
424 _("Automatic usage of hardware breakpoints is %s.\n"),
428 /* If on, GDB keeps breakpoints inserted even if the inferior is
429 stopped, and immediately inserts any new breakpoints as soon as
430 they're created. If off (default), GDB keeps breakpoints off of
431 the target as long as possible. That is, it delays inserting
432 breakpoints until the next resume, and removes them again when the
433 target fully stops. This is a bit safer in case GDB crashes while
434 processing user input. */
435 static bool always_inserted_mode
= false;
438 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
439 struct cmd_list_element
*c
, const char *value
)
441 gdb_printf (file
, _("Always inserted breakpoint mode is %s.\n"),
445 /* See breakpoint.h. */
448 breakpoints_should_be_inserted_now (void)
450 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
452 /* If breakpoints are global, they should be inserted even if no
453 thread under gdb's control is running, or even if there are
454 no threads under GDB's control yet. */
459 if (always_inserted_mode
)
461 /* The user wants breakpoints inserted even if all threads
466 for (inferior
*inf
: all_inferiors ())
467 if (inf
->has_execution ()
468 && threads_are_executing (inf
->process_target ()))
471 /* Don't remove breakpoints yet if, even though all threads are
472 stopped, we still have events to process. */
473 for (thread_info
*tp
: all_non_exited_threads ())
474 if (tp
->resumed () && tp
->has_pending_waitstatus ())
480 static const char condition_evaluation_both
[] = "host or target";
482 /* Modes for breakpoint condition evaluation. */
483 static const char condition_evaluation_auto
[] = "auto";
484 static const char condition_evaluation_host
[] = "host";
485 static const char condition_evaluation_target
[] = "target";
486 static const char *const condition_evaluation_enums
[] = {
487 condition_evaluation_auto
,
488 condition_evaluation_host
,
489 condition_evaluation_target
,
493 /* Global that holds the current mode for breakpoint condition evaluation. */
494 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
496 /* Global that we use to display information to the user (gets its value from
497 condition_evaluation_mode_1. */
498 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
500 /* Translate a condition evaluation mode MODE into either "host"
501 or "target". This is used mostly to translate from "auto" to the
502 real setting that is being used. It returns the translated
506 translate_condition_evaluation_mode (const char *mode
)
508 if (mode
== condition_evaluation_auto
)
510 if (target_supports_evaluation_of_breakpoint_conditions ())
511 return condition_evaluation_target
;
513 return condition_evaluation_host
;
519 /* Discovers what condition_evaluation_auto translates to. */
522 breakpoint_condition_evaluation_mode (void)
524 return translate_condition_evaluation_mode (condition_evaluation_mode
);
527 /* Return true if GDB should evaluate breakpoint conditions or false
531 gdb_evaluates_breakpoint_condition_p (void)
533 const char *mode
= breakpoint_condition_evaluation_mode ();
535 return (mode
== condition_evaluation_host
);
538 /* Are we executing breakpoint commands? */
539 static int executing_breakpoint_commands
;
541 /* Are overlay event breakpoints enabled? */
542 static int overlay_events_enabled
;
544 /* See description in breakpoint.h. */
545 bool target_exact_watchpoints
= false;
547 /* Walk the following statement or block through all breakpoints.
548 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
549 current breakpoint. */
551 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
552 for (B = breakpoint_chain; \
553 B ? (TMP=B->next, 1): 0; \
556 /* Chains of all breakpoints defined. */
558 static struct breakpoint
*breakpoint_chain
;
560 /* See breakpoint.h. */
565 return breakpoint_range (breakpoint_chain
);
568 /* See breakpoint.h. */
570 breakpoint_safe_range
571 all_breakpoints_safe ()
573 return breakpoint_safe_range (all_breakpoints ());
576 /* See breakpoint.h. */
581 return tracepoint_range (breakpoint_chain
);
584 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
586 static std::vector
<bp_location
*> bp_locations
;
588 /* See breakpoint.h. */
590 const std::vector
<bp_location
*> &
596 /* Range to iterate over breakpoint locations at a given address. */
598 struct bp_locations_at_addr_range
600 using iterator
= std::vector
<bp_location
*>::iterator
;
602 bp_locations_at_addr_range (CORE_ADDR addr
)
606 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
607 { return loc
->address
< addr_
; }
609 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
610 { return addr_
< loc
->address
; }
613 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
616 m_begin
= it_pair
.first
;
617 m_end
= it_pair
.second
;
620 iterator
begin () const
623 iterator
end () const
631 /* Return a range to iterate over all breakpoint locations exactly at address
634 If it's needed to iterate multiple times on the same range, it's possible
635 to save the range in a local variable and use it multiple times:
637 auto range = all_bp_locations_at_addr (addr);
639 for (bp_location *loc : range)
642 for (bp_location *loc : range)
645 This saves a bit of time, as it avoids re-doing the binary searches to find
646 the range's boundaries. Just remember not to change the bp_locations vector
647 in the mean time, as it could make the range's iterators stale. */
649 static bp_locations_at_addr_range
650 all_bp_locations_at_addr (CORE_ADDR addr
)
652 return bp_locations_at_addr_range (addr
);
655 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
656 ADDRESS for the current elements of BP_LOCATIONS which get a valid
657 result from bp_location_has_shadow. You can use it for roughly
658 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
659 an address you need to read. */
661 static CORE_ADDR bp_locations_placed_address_before_address_max
;
663 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
664 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
665 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
666 You can use it for roughly limiting the subrange of BP_LOCATIONS to
667 scan for shadow bytes for an address you need to read. */
669 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
671 /* The locations that no longer correspond to any breakpoint, unlinked
672 from the bp_locations array, but for which a hit may still be
673 reported by a target. */
674 static std::vector
<bp_location
*> moribund_locations
;
676 /* Number of last breakpoint made. */
678 static int breakpoint_count
;
680 /* The value of `breakpoint_count' before the last command that
681 created breakpoints. If the last (break-like) command created more
682 than one breakpoint, then the difference between BREAKPOINT_COUNT
683 and PREV_BREAKPOINT_COUNT is more than one. */
684 static int prev_breakpoint_count
;
686 /* Number of last tracepoint made. */
688 static int tracepoint_count
;
690 static struct cmd_list_element
*breakpoint_set_cmdlist
;
691 static struct cmd_list_element
*breakpoint_show_cmdlist
;
692 struct cmd_list_element
*save_cmdlist
;
694 /* Return whether a breakpoint is an active enabled breakpoint. */
696 breakpoint_enabled (struct breakpoint
*b
)
698 return (b
->enable_state
== bp_enabled
);
701 /* Set breakpoint count to NUM. */
704 set_breakpoint_count (int num
)
706 prev_breakpoint_count
= breakpoint_count
;
707 breakpoint_count
= num
;
708 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
711 /* Used by `start_rbreak_breakpoints' below, to record the current
712 breakpoint count before "rbreak" creates any breakpoint. */
713 static int rbreak_start_breakpoint_count
;
715 /* Called at the start an "rbreak" command to record the first
718 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
720 rbreak_start_breakpoint_count
= breakpoint_count
;
723 /* Called at the end of an "rbreak" command to record the last
726 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
728 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
731 /* Used in run_command to zero the hit count when a new run starts. */
734 clear_breakpoint_hit_counts (void)
736 for (breakpoint
*b
: all_breakpoints ())
741 /* Return the breakpoint with the specified number, or NULL
742 if the number does not refer to an existing breakpoint. */
745 get_breakpoint (int num
)
747 for (breakpoint
*b
: all_breakpoints ())
748 if (b
->number
== num
)
756 /* Mark locations as "conditions have changed" in case the target supports
757 evaluating conditions on its side. */
760 mark_breakpoint_modified (struct breakpoint
*b
)
762 /* This is only meaningful if the target is
763 evaluating conditions and if the user has
764 opted for condition evaluation on the target's
766 if (gdb_evaluates_breakpoint_condition_p ()
767 || !target_supports_evaluation_of_breakpoint_conditions ())
770 if (!is_breakpoint (b
))
773 for (bp_location
*loc
: b
->locations ())
774 loc
->condition_changed
= condition_modified
;
777 /* Mark location as "conditions have changed" in case the target supports
778 evaluating conditions on its side. */
781 mark_breakpoint_location_modified (struct bp_location
*loc
)
783 /* This is only meaningful if the target is
784 evaluating conditions and if the user has
785 opted for condition evaluation on the target's
787 if (gdb_evaluates_breakpoint_condition_p ()
788 || !target_supports_evaluation_of_breakpoint_conditions ())
792 if (!is_breakpoint (loc
->owner
))
795 loc
->condition_changed
= condition_modified
;
798 /* Sets the condition-evaluation mode using the static global
799 condition_evaluation_mode. */
802 set_condition_evaluation_mode (const char *args
, int from_tty
,
803 struct cmd_list_element
*c
)
805 const char *old_mode
, *new_mode
;
807 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
808 && !target_supports_evaluation_of_breakpoint_conditions ())
810 condition_evaluation_mode_1
= condition_evaluation_mode
;
811 warning (_("Target does not support breakpoint condition evaluation.\n"
812 "Using host evaluation mode instead."));
816 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
817 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
819 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
820 settings was "auto". */
821 condition_evaluation_mode
= condition_evaluation_mode_1
;
823 /* Only update the mode if the user picked a different one. */
824 if (new_mode
!= old_mode
)
826 /* If the user switched to a different evaluation mode, we
827 need to synch the changes with the target as follows:
829 "host" -> "target": Send all (valid) conditions to the target.
830 "target" -> "host": Remove all the conditions from the target.
833 if (new_mode
== condition_evaluation_target
)
835 /* Mark everything modified and synch conditions with the
837 for (bp_location
*loc
: all_bp_locations ())
838 mark_breakpoint_location_modified (loc
);
842 /* Manually mark non-duplicate locations to synch conditions
843 with the target. We do this to remove all the conditions the
844 target knows about. */
845 for (bp_location
*loc
: all_bp_locations ())
846 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
847 loc
->needs_update
= 1;
851 update_global_location_list (UGLL_MAY_INSERT
);
857 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
858 what "auto" is translating to. */
861 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
862 struct cmd_list_element
*c
, const char *value
)
864 if (condition_evaluation_mode
== condition_evaluation_auto
)
866 _("Breakpoint condition evaluation "
867 "mode is %s (currently %s).\n"),
869 breakpoint_condition_evaluation_mode ());
871 gdb_printf (file
, _("Breakpoint condition evaluation mode is %s.\n"),
875 /* Parse COND_STRING in the context of LOC and set as the condition
876 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
877 the number of LOC within its owner. In case of parsing error, mark
878 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
881 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
882 int bp_num
, int loc_num
)
884 bool has_junk
= false;
887 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
888 block_for_pc (loc
->address
), 0);
889 if (*cond_string
!= 0)
893 loc
->cond
= std::move (new_exp
);
894 if (loc
->disabled_by_cond
&& loc
->enabled
)
895 gdb_printf (_("Breakpoint %d's condition is now valid at "
896 "location %d, enabling.\n"),
899 loc
->disabled_by_cond
= false;
902 catch (const gdb_exception_error
&e
)
906 /* Warn if a user-enabled location is now becoming disabled-by-cond.
907 BP_NUM is 0 if the breakpoint is being defined for the first
908 time using the "break ... if ..." command, and non-zero if
911 warning (_("failed to validate condition at location %d.%d, "
912 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
914 warning (_("failed to validate condition at location %d, "
915 "disabling:\n %s"), loc_num
, e
.what ());
918 loc
->disabled_by_cond
= true;
922 error (_("Garbage '%s' follows condition"), cond_string
);
926 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
927 int from_tty
, bool force
)
931 b
->cond_string
.reset ();
933 if (is_watchpoint (b
))
934 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
938 for (bp_location
*loc
: b
->locations ())
941 if (loc
->disabled_by_cond
&& loc
->enabled
)
942 gdb_printf (_("Breakpoint %d's condition is now valid at "
943 "location %d, enabling.\n"),
945 loc
->disabled_by_cond
= false;
948 /* No need to free the condition agent expression
949 bytecode (if we have one). We will handle this
950 when we go through update_global_location_list. */
955 gdb_printf (_("Breakpoint %d now unconditional.\n"), b
->number
);
959 if (is_watchpoint (b
))
961 innermost_block_tracker tracker
;
962 const char *arg
= exp
;
963 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
965 error (_("Junk at end of expression"));
966 watchpoint
*w
= static_cast<watchpoint
*> (b
);
967 w
->cond_exp
= std::move (new_exp
);
968 w
->cond_exp_valid_block
= tracker
.block ();
972 /* Parse and set condition expressions. We make two passes.
973 In the first, we parse the condition string to see if it
974 is valid in at least one location. If so, the condition
975 would be accepted. So we go ahead and set the locations'
976 conditions. In case no valid case is found, we throw
977 the error and the condition string will be rejected.
978 This two-pass approach is taken to avoid setting the
979 state of locations in case of a reject. */
980 for (bp_location
*loc
: b
->locations ())
984 const char *arg
= exp
;
985 parse_exp_1 (&arg
, loc
->address
,
986 block_for_pc (loc
->address
), 0);
988 error (_("Junk at end of expression"));
991 catch (const gdb_exception_error
&e
)
993 /* Condition string is invalid. If this happens to
994 be the last loc, abandon (if not forced) or continue
996 if (loc
->next
== nullptr && !force
)
1001 /* If we reach here, the condition is valid at some locations. */
1003 for (bp_location
*loc
: b
->locations ())
1005 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
1010 /* We know that the new condition parsed successfully. The
1011 condition string of the breakpoint can be safely updated. */
1012 b
->cond_string
= make_unique_xstrdup (exp
);
1013 b
->condition_not_parsed
= 0;
1015 mark_breakpoint_modified (b
);
1017 gdb::observers::breakpoint_modified
.notify (b
);
1020 /* See breakpoint.h. */
1023 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
1026 for (breakpoint
*b
: all_breakpoints ())
1027 if (b
->number
== bpnum
)
1029 /* Check if this breakpoint has a "stop" method implemented in an
1030 extension language. This method and conditions entered into GDB
1031 from the CLI are mutually exclusive. */
1032 const struct extension_language_defn
*extlang
1033 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1035 if (extlang
!= NULL
)
1037 error (_("Only one stop condition allowed. There is currently"
1038 " a %s stop condition defined for this breakpoint."),
1039 ext_lang_capitalized_name (extlang
));
1041 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1043 if (is_breakpoint (b
))
1044 update_global_location_list (UGLL_MAY_INSERT
);
1049 error (_("No breakpoint number %d."), bpnum
);
1052 /* The options for the "condition" command. */
1054 struct condition_command_opts
1057 bool force_condition
= false;
1060 static const gdb::option::option_def condition_command_option_defs
[] = {
1062 gdb::option::flag_option_def
<condition_command_opts
> {
1064 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1065 N_("Set the condition even if it is invalid for all current locations."),
1070 /* Create an option_def_group for the "condition" options, with
1071 CC_OPTS as context. */
1073 static inline gdb::option::option_def_group
1074 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1076 return {{condition_command_option_defs
}, cc_opts
};
1079 /* Completion for the "condition" command. */
1082 condition_completer (struct cmd_list_element
*cmd
,
1083 completion_tracker
&tracker
,
1084 const char *text
, const char * /*word*/)
1086 bool has_no_arguments
= (*text
== '\0');
1087 condition_command_opts cc_opts
;
1088 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1089 if (gdb::option::complete_options
1090 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1093 text
= skip_spaces (text
);
1094 const char *space
= skip_to_space (text
);
1101 tracker
.advance_custom_word_point_by (1);
1102 /* We don't support completion of history indices. */
1103 if (!isdigit (text
[1]))
1104 complete_internalvar (tracker
, &text
[1]);
1108 /* Suggest the "-force" flag if no arguments are given. If
1109 arguments were passed, they either already include the flag,
1110 or we are beyond the point of suggesting it because it's
1111 positionally the first argument. */
1112 if (has_no_arguments
)
1113 gdb::option::complete_on_all_options (tracker
, group
);
1115 /* We're completing the breakpoint number. */
1116 len
= strlen (text
);
1118 for (breakpoint
*b
: all_breakpoints ())
1122 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1124 if (strncmp (number
, text
, len
) == 0)
1125 tracker
.add_completion (make_unique_xstrdup (number
));
1131 /* We're completing the expression part. Skip the breakpoint num. */
1132 const char *exp_start
= skip_spaces (space
);
1133 tracker
.advance_custom_word_point_by (exp_start
- text
);
1135 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1136 expression_completer (cmd
, tracker
, text
, word
);
1139 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1142 condition_command (const char *arg
, int from_tty
)
1148 error_no_arg (_("breakpoint number"));
1152 /* Check if the "-force" flag was passed. */
1153 condition_command_opts cc_opts
;
1154 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1155 gdb::option::process_options
1156 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1158 bnum
= get_number (&p
);
1160 error (_("Bad breakpoint argument: '%s'"), arg
);
1162 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1165 /* Check that COMMAND do not contain commands that are suitable
1166 only for tracepoints and not suitable for ordinary breakpoints.
1167 Throw if any such commands is found. */
1170 check_no_tracepoint_commands (struct command_line
*commands
)
1172 struct command_line
*c
;
1174 for (c
= commands
; c
; c
= c
->next
)
1176 if (c
->control_type
== while_stepping_control
)
1177 error (_("The 'while-stepping' command can "
1178 "only be used for tracepoints"));
1180 check_no_tracepoint_commands (c
->body_list_0
.get ());
1181 check_no_tracepoint_commands (c
->body_list_1
.get ());
1183 /* Not that command parsing removes leading whitespace and comment
1184 lines and also empty lines. So, we only need to check for
1185 command directly. */
1186 if (strstr (c
->line
, "collect ") == c
->line
)
1187 error (_("The 'collect' command can only be used for tracepoints"));
1189 if (strstr (c
->line
, "teval ") == c
->line
)
1190 error (_("The 'teval' command can only be used for tracepoints"));
1194 struct longjmp_breakpoint
: public momentary_breakpoint
1196 ~longjmp_breakpoint () override
;
1199 /* Encapsulate tests for different types of tracepoints. */
1202 is_tracepoint_type (bptype type
)
1204 return (type
== bp_tracepoint
1205 || type
== bp_fast_tracepoint
1206 || type
== bp_static_tracepoint
1207 || type
== bp_static_marker_tracepoint
);
1210 /* See breakpoint.h. */
1213 is_tracepoint (const struct breakpoint
*b
)
1215 return is_tracepoint_type (b
->type
);
1218 /* Factory function to create an appropriate instance of breakpoint given
1221 static std::unique_ptr
<breakpoint
>
1222 new_breakpoint_from_type (bptype type
)
1229 case bp_hardware_breakpoint
:
1230 b
= new ordinary_breakpoint ();
1233 case bp_fast_tracepoint
:
1234 case bp_static_tracepoint
:
1236 b
= new tracepoint ();
1239 case bp_static_marker_tracepoint
:
1240 b
= new static_marker_tracepoint ();
1244 b
= new dprintf_breakpoint ();
1247 case bp_overlay_event
:
1248 case bp_longjmp_master
:
1249 case bp_std_terminate_master
:
1250 case bp_exception_master
:
1251 case bp_thread_event
:
1253 case bp_shlib_event
:
1254 b
= new internal_breakpoint ();
1259 b
= new longjmp_breakpoint ();
1262 case bp_watchpoint_scope
:
1264 case bp_gnu_ifunc_resolver_return
:
1265 case bp_step_resume
:
1266 case bp_hp_step_resume
:
1267 case bp_longjmp_resume
:
1268 case bp_longjmp_call_dummy
:
1269 case bp_exception_resume
:
1272 case bp_std_terminate
:
1273 b
= new momentary_breakpoint ();
1277 gdb_assert_not_reached ("invalid type");
1280 return std::unique_ptr
<breakpoint
> (b
);
1283 /* A helper function that validates that COMMANDS are valid for a
1284 breakpoint. This function will throw an exception if a problem is
1288 validate_commands_for_breakpoint (struct breakpoint
*b
,
1289 struct command_line
*commands
)
1291 if (is_tracepoint (b
))
1293 struct tracepoint
*t
= (struct tracepoint
*) b
;
1294 struct command_line
*c
;
1295 struct command_line
*while_stepping
= 0;
1297 /* Reset the while-stepping step count. The previous commands
1298 might have included a while-stepping action, while the new
1302 /* We need to verify that each top-level element of commands is
1303 valid for tracepoints, that there's at most one
1304 while-stepping element, and that the while-stepping's body
1305 has valid tracing commands excluding nested while-stepping.
1306 We also need to validate the tracepoint action line in the
1307 context of the tracepoint --- validate_actionline actually
1308 has side effects, like setting the tracepoint's
1309 while-stepping STEP_COUNT, in addition to checking if the
1310 collect/teval actions parse and make sense in the
1311 tracepoint's context. */
1312 for (c
= commands
; c
; c
= c
->next
)
1314 if (c
->control_type
== while_stepping_control
)
1316 if (b
->type
== bp_fast_tracepoint
)
1317 error (_("The 'while-stepping' command "
1318 "cannot be used for fast tracepoint"));
1319 else if (b
->type
== bp_static_tracepoint
1320 || b
->type
== bp_static_marker_tracepoint
)
1321 error (_("The 'while-stepping' command "
1322 "cannot be used for static tracepoint"));
1325 error (_("The 'while-stepping' command "
1326 "can be used only once"));
1331 validate_actionline (c
->line
, b
);
1335 struct command_line
*c2
;
1337 gdb_assert (while_stepping
->body_list_1
== nullptr);
1338 c2
= while_stepping
->body_list_0
.get ();
1339 for (; c2
; c2
= c2
->next
)
1341 if (c2
->control_type
== while_stepping_control
)
1342 error (_("The 'while-stepping' command cannot be nested"));
1348 check_no_tracepoint_commands (commands
);
1352 /* Return a vector of all the static tracepoints set at ADDR. The
1353 caller is responsible for releasing the vector. */
1355 std::vector
<breakpoint
*>
1356 static_tracepoints_here (CORE_ADDR addr
)
1358 std::vector
<breakpoint
*> found
;
1360 for (breakpoint
*b
: all_breakpoints ())
1361 if (b
->type
== bp_static_tracepoint
1362 || b
->type
== bp_static_marker_tracepoint
)
1364 for (bp_location
*loc
: b
->locations ())
1365 if (loc
->address
== addr
)
1366 found
.push_back (b
);
1372 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1373 validate that only allowed commands are included. */
1376 breakpoint_set_commands (struct breakpoint
*b
,
1377 counted_command_line
&&commands
)
1379 validate_commands_for_breakpoint (b
, commands
.get ());
1381 b
->commands
= std::move (commands
);
1382 gdb::observers::breakpoint_modified
.notify (b
);
1385 /* Set the internal `silent' flag on the breakpoint. Note that this
1386 is not the same as the "silent" that may appear in the breakpoint's
1390 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1392 int old_silent
= b
->silent
;
1395 if (old_silent
!= silent
)
1396 gdb::observers::breakpoint_modified
.notify (b
);
1399 /* Set the thread for this breakpoint. If THREAD is -1, make the
1400 breakpoint work for any thread. */
1403 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1405 int old_thread
= b
->thread
;
1408 if (old_thread
!= thread
)
1409 gdb::observers::breakpoint_modified
.notify (b
);
1412 /* Set the task for this breakpoint. If TASK is 0, make the
1413 breakpoint work for any task. */
1416 breakpoint_set_task (struct breakpoint
*b
, int task
)
1418 int old_task
= b
->task
;
1421 if (old_task
!= task
)
1422 gdb::observers::breakpoint_modified
.notify (b
);
1426 commands_command_1 (const char *arg
, int from_tty
,
1427 struct command_line
*control
)
1429 counted_command_line cmd
;
1430 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1431 NULL after the call to read_command_lines if the user provides an empty
1432 list of command by just typing "end". */
1433 bool cmd_read
= false;
1435 std::string new_arg
;
1437 if (arg
== NULL
|| !*arg
)
1439 /* Argument not explicitly given. Synthesize it. */
1440 if (breakpoint_count
- prev_breakpoint_count
> 1)
1441 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1443 else if (breakpoint_count
> 0)
1444 new_arg
= string_printf ("%d", breakpoint_count
);
1448 /* Create a copy of ARG. This is needed because the "commands"
1449 command may be coming from a script. In that case, the read
1450 line buffer is going to be overwritten in the lambda of
1451 'map_breakpoint_numbers' below when reading the next line
1452 before we are are done parsing the breakpoint numbers. */
1455 arg
= new_arg
.c_str ();
1457 map_breakpoint_numbers
1458 (arg
, [&] (breakpoint
*b
)
1462 gdb_assert (cmd
== NULL
);
1463 if (control
!= NULL
)
1464 cmd
= control
->body_list_0
;
1468 = string_printf (_("Type commands for breakpoint(s) "
1469 "%s, one per line."),
1472 auto do_validate
= [=] (const char *line
)
1474 validate_actionline (line
, b
);
1476 gdb::function_view
<void (const char *)> validator
;
1477 if (is_tracepoint (b
))
1478 validator
= do_validate
;
1480 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1485 /* If a breakpoint was on the list more than once, we don't need to
1487 if (b
->commands
!= cmd
)
1489 validate_commands_for_breakpoint (b
, cmd
.get ());
1491 gdb::observers::breakpoint_modified
.notify (b
);
1497 commands_command (const char *arg
, int from_tty
)
1499 commands_command_1 (arg
, from_tty
, NULL
);
1502 /* Like commands_command, but instead of reading the commands from
1503 input stream, takes them from an already parsed command structure.
1505 This is used by cli-script.c to DTRT with breakpoint commands
1506 that are part of if and while bodies. */
1507 enum command_control_type
1508 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1510 commands_command_1 (arg
, 0, cmd
);
1511 return simple_control
;
1514 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1517 bp_location_has_shadow (struct bp_location
*bl
)
1519 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1523 if (bl
->target_info
.shadow_len
== 0)
1524 /* BL isn't valid, or doesn't shadow memory. */
1529 /* Update BUF, which is LEN bytes read from the target address
1530 MEMADDR, by replacing a memory breakpoint with its shadowed
1533 If READBUF is not NULL, this buffer must not overlap with the of
1534 the breakpoint location's shadow_contents buffer. Otherwise, a
1535 failed assertion internal error will be raised. */
1538 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1539 const gdb_byte
*writebuf_org
,
1540 ULONGEST memaddr
, LONGEST len
,
1541 struct bp_target_info
*target_info
,
1542 struct gdbarch
*gdbarch
)
1544 /* Now do full processing of the found relevant range of elements. */
1545 CORE_ADDR bp_addr
= 0;
1549 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1550 current_program_space
->aspace
, 0))
1552 /* The breakpoint is inserted in a different address space. */
1556 /* Addresses and length of the part of the breakpoint that
1558 bp_addr
= target_info
->placed_address
;
1559 bp_size
= target_info
->shadow_len
;
1561 if (bp_addr
+ bp_size
<= memaddr
)
1563 /* The breakpoint is entirely before the chunk of memory we are
1568 if (bp_addr
>= memaddr
+ len
)
1570 /* The breakpoint is entirely after the chunk of memory we are
1575 /* Offset within shadow_contents. */
1576 if (bp_addr
< memaddr
)
1578 /* Only copy the second part of the breakpoint. */
1579 bp_size
-= memaddr
- bp_addr
;
1580 bptoffset
= memaddr
- bp_addr
;
1584 if (bp_addr
+ bp_size
> memaddr
+ len
)
1586 /* Only copy the first part of the breakpoint. */
1587 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1590 if (readbuf
!= NULL
)
1592 /* Verify that the readbuf buffer does not overlap with the
1593 shadow_contents buffer. */
1594 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1595 || readbuf
>= (target_info
->shadow_contents
1596 + target_info
->shadow_len
));
1598 /* Update the read buffer with this inserted breakpoint's
1600 memcpy (readbuf
+ bp_addr
- memaddr
,
1601 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1605 const unsigned char *bp
;
1606 CORE_ADDR addr
= target_info
->reqstd_address
;
1609 /* Update the shadow with what we want to write to memory. */
1610 memcpy (target_info
->shadow_contents
+ bptoffset
,
1611 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1613 /* Determine appropriate breakpoint contents and size for this
1615 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1617 /* Update the final write buffer with this inserted
1618 breakpoint's INSN. */
1619 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1623 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1624 by replacing any memory breakpoints with their shadowed contents.
1626 If READBUF is not NULL, this buffer must not overlap with any of
1627 the breakpoint location's shadow_contents buffers. Otherwise,
1628 a failed assertion internal error will be raised.
1630 The range of shadowed area by each bp_location is:
1631 bl->address - bp_locations_placed_address_before_address_max
1632 up to bl->address + bp_locations_shadow_len_after_address_max
1633 The range we were requested to resolve shadows for is:
1634 memaddr ... memaddr + len
1635 Thus the safe cutoff boundaries for performance optimization are
1636 memaddr + len <= (bl->address
1637 - bp_locations_placed_address_before_address_max)
1639 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1642 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1643 const gdb_byte
*writebuf_org
,
1644 ULONGEST memaddr
, LONGEST len
)
1646 /* Left boundary, right boundary and median element of our binary
1648 unsigned bc_l
, bc_r
, bc
;
1650 /* Find BC_L which is a leftmost element which may affect BUF
1651 content. It is safe to report lower value but a failure to
1652 report higher one. */
1655 bc_r
= bp_locations
.size ();
1656 while (bc_l
+ 1 < bc_r
)
1658 struct bp_location
*bl
;
1660 bc
= (bc_l
+ bc_r
) / 2;
1661 bl
= bp_locations
[bc
];
1663 /* Check first BL->ADDRESS will not overflow due to the added
1664 constant. Then advance the left boundary only if we are sure
1665 the BC element can in no way affect the BUF content (MEMADDR
1666 to MEMADDR + LEN range).
1668 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1669 offset so that we cannot miss a breakpoint with its shadow
1670 range tail still reaching MEMADDR. */
1672 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1674 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1681 /* Due to the binary search above, we need to make sure we pick the
1682 first location that's at BC_L's address. E.g., if there are
1683 multiple locations at the same address, BC_L may end up pointing
1684 at a duplicate location, and miss the "master"/"inserted"
1685 location. Say, given locations L1, L2 and L3 at addresses A and
1688 L1@A, L2@A, L3@B, ...
1690 BC_L could end up pointing at location L2, while the "master"
1691 location could be L1. Since the `loc->inserted' flag is only set
1692 on "master" locations, we'd forget to restore the shadow of L1
1695 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1698 /* Now do full processing of the found relevant range of elements. */
1700 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1702 struct bp_location
*bl
= bp_locations
[bc
];
1704 /* bp_location array has BL->OWNER always non-NULL. */
1705 if (bl
->owner
->type
== bp_none
)
1706 warning (_("reading through apparently deleted breakpoint #%d?"),
1709 /* Performance optimization: any further element can no longer affect BUF
1712 if (bl
->address
>= bp_locations_placed_address_before_address_max
1715 - bp_locations_placed_address_before_address_max
)))
1718 if (!bp_location_has_shadow (bl
))
1721 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1722 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1726 /* See breakpoint.h. */
1729 is_breakpoint (const struct breakpoint
*bpt
)
1731 return (bpt
->type
== bp_breakpoint
1732 || bpt
->type
== bp_hardware_breakpoint
1733 || bpt
->type
== bp_dprintf
);
1736 /* Return true if BPT is of any hardware watchpoint kind. */
1739 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1741 return (bpt
->type
== bp_hardware_watchpoint
1742 || bpt
->type
== bp_read_watchpoint
1743 || bpt
->type
== bp_access_watchpoint
);
1746 /* See breakpoint.h. */
1749 is_watchpoint (const struct breakpoint
*bpt
)
1751 return (is_hardware_watchpoint (bpt
)
1752 || bpt
->type
== bp_watchpoint
);
1755 /* Returns true if the current thread and its running state are safe
1756 to evaluate or update watchpoint B. Watchpoints on local
1757 expressions need to be evaluated in the context of the thread that
1758 was current when the watchpoint was created, and, that thread needs
1759 to be stopped to be able to select the correct frame context.
1760 Watchpoints on global expressions can be evaluated on any thread,
1761 and in any state. It is presently left to the target allowing
1762 memory accesses when threads are running. */
1765 watchpoint_in_thread_scope (struct watchpoint
*b
)
1767 return (b
->pspace
== current_program_space
1768 && (b
->watchpoint_thread
== null_ptid
1769 || (inferior_ptid
== b
->watchpoint_thread
1770 && !inferior_thread ()->executing ())));
1773 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1774 associated bp_watchpoint_scope breakpoint. */
1777 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1779 if (w
->related_breakpoint
!= w
)
1781 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1782 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1783 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1784 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1785 w
->related_breakpoint
= w
;
1787 w
->disposition
= disp_del_at_next_stop
;
1790 /* Extract a bitfield value from value VAL using the bit parameters contained in
1793 static struct value
*
1794 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1796 struct value
*bit_val
;
1801 bit_val
= allocate_value (value_type (val
));
1803 unpack_value_bitfield (bit_val
,
1806 value_contents_for_printing (val
).data (),
1813 /* Allocate a dummy location and add it to B, which must be a software
1814 watchpoint. This is required because even if a software watchpoint
1815 is not watching any memory, bpstat_stop_status requires a location
1816 to be able to report stops. */
1819 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1820 struct program_space
*pspace
)
1822 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1824 b
->loc
= b
->allocate_location ();
1825 b
->loc
->pspace
= pspace
;
1826 b
->loc
->address
= -1;
1827 b
->loc
->length
= -1;
1830 /* Returns true if B is a software watchpoint that is not watching any
1831 memory (e.g., "watch $pc"). */
1834 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1836 return (b
->type
== bp_watchpoint
1838 && b
->loc
->next
== NULL
1839 && b
->loc
->address
== -1
1840 && b
->loc
->length
== -1);
1843 /* Assuming that B is a watchpoint:
1844 - Reparse watchpoint expression, if REPARSE is non-zero
1845 - Evaluate expression and store the result in B->val
1846 - Evaluate the condition if there is one, and store the result
1848 - Update the list of values that must be watched in B->loc.
1850 If the watchpoint disposition is disp_del_at_next_stop, then do
1851 nothing. If this is local watchpoint that is out of scope, delete
1854 Even with `set breakpoint always-inserted on' the watchpoints are
1855 removed + inserted on each stop here. Normal breakpoints must
1856 never be removed because they might be missed by a running thread
1857 when debugging in non-stop mode. On the other hand, hardware
1858 watchpoints (is_hardware_watchpoint; processed here) are specific
1859 to each LWP since they are stored in each LWP's hardware debug
1860 registers. Therefore, such LWP must be stopped first in order to
1861 be able to modify its hardware watchpoints.
1863 Hardware watchpoints must be reset exactly once after being
1864 presented to the user. It cannot be done sooner, because it would
1865 reset the data used to present the watchpoint hit to the user. And
1866 it must not be done later because it could display the same single
1867 watchpoint hit during multiple GDB stops. Note that the latter is
1868 relevant only to the hardware watchpoint types bp_read_watchpoint
1869 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1870 not user-visible - its hit is suppressed if the memory content has
1873 The following constraints influence the location where we can reset
1874 hardware watchpoints:
1876 * target_stopped_by_watchpoint and target_stopped_data_address are
1877 called several times when GDB stops.
1880 * Multiple hardware watchpoints can be hit at the same time,
1881 causing GDB to stop. GDB only presents one hardware watchpoint
1882 hit at a time as the reason for stopping, and all the other hits
1883 are presented later, one after the other, each time the user
1884 requests the execution to be resumed. Execution is not resumed
1885 for the threads still having pending hit event stored in
1886 LWP_INFO->STATUS. While the watchpoint is already removed from
1887 the inferior on the first stop the thread hit event is kept being
1888 reported from its cached value by linux_nat_stopped_data_address
1889 until the real thread resume happens after the watchpoint gets
1890 presented and thus its LWP_INFO->STATUS gets reset.
1892 Therefore the hardware watchpoint hit can get safely reset on the
1893 watchpoint removal from inferior. */
1896 update_watchpoint (struct watchpoint
*b
, int reparse
)
1898 int within_current_scope
;
1899 struct frame_id saved_frame_id
;
1902 /* If this is a local watchpoint, we only want to check if the
1903 watchpoint frame is in scope if the current thread is the thread
1904 that was used to create the watchpoint. */
1905 if (!watchpoint_in_thread_scope (b
))
1908 if (b
->disposition
== disp_del_at_next_stop
)
1913 /* Determine if the watchpoint is within scope. */
1914 if (b
->exp_valid_block
== NULL
)
1915 within_current_scope
= 1;
1918 struct frame_info
*fi
= get_current_frame ();
1919 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1920 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1922 /* If we're at a point where the stack has been destroyed
1923 (e.g. in a function epilogue), unwinding may not work
1924 properly. Do not attempt to recreate locations at this
1925 point. See similar comments in watchpoint_check. */
1926 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1929 /* Save the current frame's ID so we can restore it after
1930 evaluating the watchpoint expression on its own frame. */
1931 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1932 took a frame parameter, so that we didn't have to change the
1935 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1937 fi
= frame_find_by_id (b
->watchpoint_frame
);
1938 within_current_scope
= (fi
!= NULL
);
1939 if (within_current_scope
)
1943 /* We don't free locations. They are stored in the bp_location array
1944 and update_global_location_list will eventually delete them and
1945 remove breakpoints if needed. */
1948 if (within_current_scope
&& reparse
)
1953 s
= (b
->exp_string_reparse
1954 ? b
->exp_string_reparse
.get ()
1955 : b
->exp_string
.get ());
1956 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1957 /* If the meaning of expression itself changed, the old value is
1958 no longer relevant. We don't want to report a watchpoint hit
1959 to the user when the old value and the new value may actually
1960 be completely different objects. */
1962 b
->val_valid
= false;
1964 /* Note that unlike with breakpoints, the watchpoint's condition
1965 expression is stored in the breakpoint object, not in the
1966 locations (re)created below. */
1967 if (b
->cond_string
!= NULL
)
1969 b
->cond_exp
.reset ();
1971 s
= b
->cond_string
.get ();
1972 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1976 /* If we failed to parse the expression, for example because
1977 it refers to a global variable in a not-yet-loaded shared library,
1978 don't try to insert watchpoint. We don't automatically delete
1979 such watchpoint, though, since failure to parse expression
1980 is different from out-of-scope watchpoint. */
1981 if (!target_has_execution ())
1983 /* Without execution, memory can't change. No use to try and
1984 set watchpoint locations. The watchpoint will be reset when
1985 the target gains execution, through breakpoint_re_set. */
1986 if (!can_use_hw_watchpoints
)
1988 if (b
->works_in_software_mode ())
1989 b
->type
= bp_watchpoint
;
1991 error (_("Can't set read/access watchpoint when "
1992 "hardware watchpoints are disabled."));
1995 else if (within_current_scope
&& b
->exp
)
1997 std::vector
<value_ref_ptr
> val_chain
;
1998 struct value
*v
, *result
;
1999 struct program_space
*frame_pspace
;
2001 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
2004 /* Avoid setting b->val if it's already set. The meaning of
2005 b->val is 'the last value' user saw, and we should update
2006 it only if we reported that last value to user. As it
2007 happens, the code that reports it updates b->val directly.
2008 We don't keep track of the memory value for masked
2010 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
2012 if (b
->val_bitsize
!= 0)
2013 v
= extract_bitfield_from_watchpoint_value (b
, v
);
2014 b
->val
= release_value (v
);
2015 b
->val_valid
= true;
2018 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
2020 /* Look at each value on the value chain. */
2021 gdb_assert (!val_chain
.empty ());
2022 for (const value_ref_ptr
&iter
: val_chain
)
2026 /* If it's a memory location, and GDB actually needed
2027 its contents to evaluate the expression, then we
2028 must watch it. If the first value returned is
2029 still lazy, that means an error occurred reading it;
2030 watch it anyway in case it becomes readable. */
2031 if (VALUE_LVAL (v
) == lval_memory
2032 && (v
== val_chain
[0] || ! value_lazy (v
)))
2034 struct type
*vtype
= check_typedef (value_type (v
));
2036 /* We only watch structs and arrays if user asked
2037 for it explicitly, never if they just happen to
2038 appear in the middle of some value chain. */
2040 || (vtype
->code () != TYPE_CODE_STRUCT
2041 && vtype
->code () != TYPE_CODE_ARRAY
))
2044 enum target_hw_bp_type type
;
2045 struct bp_location
*loc
, **tmp
;
2046 int bitpos
= 0, bitsize
= 0;
2048 if (value_bitsize (v
) != 0)
2050 /* Extract the bit parameters out from the bitfield
2052 bitpos
= value_bitpos (v
);
2053 bitsize
= value_bitsize (v
);
2055 else if (v
== result
&& b
->val_bitsize
!= 0)
2057 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
2058 lvalue whose bit parameters are saved in the fields
2059 VAL_BITPOS and VAL_BITSIZE. */
2060 bitpos
= b
->val_bitpos
;
2061 bitsize
= b
->val_bitsize
;
2064 addr
= value_address (v
);
2067 /* Skip the bytes that don't contain the bitfield. */
2072 if (b
->type
== bp_read_watchpoint
)
2074 else if (b
->type
== bp_access_watchpoint
)
2077 loc
= b
->allocate_location ();
2078 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2081 loc
->gdbarch
= value_type (v
)->arch ();
2083 loc
->pspace
= frame_pspace
;
2084 loc
->address
= address_significant (loc
->gdbarch
, addr
);
2088 /* Just cover the bytes that make up the bitfield. */
2089 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2092 loc
->length
= TYPE_LENGTH (value_type (v
));
2094 loc
->watchpoint_type
= type
;
2099 /* Change the type of breakpoint between hardware assisted or
2100 an ordinary watchpoint depending on the hardware support
2101 and free hardware slots. REPARSE is set when the inferior
2106 enum bp_loc_type loc_type
;
2108 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2112 int i
, target_resources_ok
, other_type_used
;
2115 /* Use an exact watchpoint when there's only one memory region to be
2116 watched, and only one debug register is needed to watch it. */
2117 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2119 /* We need to determine how many resources are already
2120 used for all other hardware watchpoints plus this one
2121 to see if we still have enough resources to also fit
2122 this watchpoint in as well. */
2124 /* If this is a software watchpoint, we try to turn it
2125 to a hardware one -- count resources as if B was of
2126 hardware watchpoint type. */
2128 if (type
== bp_watchpoint
)
2129 type
= bp_hardware_watchpoint
;
2131 /* This watchpoint may or may not have been placed on
2132 the list yet at this point (it won't be in the list
2133 if we're trying to create it for the first time,
2134 through watch_command), so always account for it
2137 /* Count resources used by all watchpoints except B. */
2138 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2140 /* Add in the resources needed for B. */
2141 i
+= hw_watchpoint_use_count (b
);
2144 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2145 if (target_resources_ok
<= 0)
2147 bool sw_mode
= b
->works_in_software_mode ();
2149 if (target_resources_ok
== 0 && !sw_mode
)
2150 error (_("Target does not support this type of "
2151 "hardware watchpoint."));
2152 else if (target_resources_ok
< 0 && !sw_mode
)
2153 error (_("There are not enough available hardware "
2154 "resources for this watchpoint."));
2156 /* Downgrade to software watchpoint. */
2157 b
->type
= bp_watchpoint
;
2161 /* If this was a software watchpoint, we've just
2162 found we have enough resources to turn it to a
2163 hardware watchpoint. Otherwise, this is a
2168 else if (!b
->works_in_software_mode ())
2170 if (!can_use_hw_watchpoints
)
2171 error (_("Can't set read/access watchpoint when "
2172 "hardware watchpoints are disabled."));
2174 error (_("Expression cannot be implemented with "
2175 "read/access watchpoint."));
2178 b
->type
= bp_watchpoint
;
2180 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2181 : bp_loc_hardware_watchpoint
);
2182 for (bp_location
*bl
: b
->locations ())
2183 bl
->loc_type
= loc_type
;
2186 /* If a software watchpoint is not watching any memory, then the
2187 above left it without any location set up. But,
2188 bpstat_stop_status requires a location to be able to report
2189 stops, so make sure there's at least a dummy one. */
2190 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2191 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2193 else if (!within_current_scope
)
2196 Watchpoint %d deleted because the program has left the block\n\
2197 in which its expression is valid.\n"),
2199 watchpoint_del_at_next_stop (b
);
2202 /* Restore the selected frame. */
2204 select_frame (frame_find_by_id (saved_frame_id
));
2208 /* Returns 1 iff breakpoint location should be
2209 inserted in the inferior. We don't differentiate the type of BL's owner
2210 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2211 breakpoint_ops is not defined, because in insert_bp_location,
2212 tracepoint's insert_location will not be called. */
2214 should_be_inserted (struct bp_location
*bl
)
2216 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2219 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2222 if (!bl
->enabled
|| bl
->disabled_by_cond
2223 || bl
->shlib_disabled
|| bl
->duplicate
)
2226 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2229 /* This is set for example, when we're attached to the parent of a
2230 vfork, and have detached from the child. The child is running
2231 free, and we expect it to do an exec or exit, at which point the
2232 OS makes the parent schedulable again (and the target reports
2233 that the vfork is done). Until the child is done with the shared
2234 memory region, do not insert breakpoints in the parent, otherwise
2235 the child could still trip on the parent's breakpoints. Since
2236 the parent is blocked anyway, it won't miss any breakpoint. */
2237 if (bl
->pspace
->breakpoints_not_allowed
)
2240 /* Don't insert a breakpoint if we're trying to step past its
2241 location, except if the breakpoint is a single-step breakpoint,
2242 and the breakpoint's thread is the thread which is stepping past
2244 if ((bl
->loc_type
== bp_loc_software_breakpoint
2245 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2246 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2248 /* The single-step breakpoint may be inserted at the location
2249 we're trying to step if the instruction branches to itself.
2250 However, the instruction won't be executed at all and it may
2251 break the semantics of the instruction, for example, the
2252 instruction is a conditional branch or updates some flags.
2253 We can't fix it unless GDB is able to emulate the instruction
2254 or switch to displaced stepping. */
2255 && !(bl
->owner
->type
== bp_single_step
2256 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2258 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2259 paddress (bl
->gdbarch
, bl
->address
));
2263 /* Don't insert watchpoints if we're trying to step past the
2264 instruction that triggered one. */
2265 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2266 && stepping_past_nonsteppable_watchpoint ())
2268 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2269 "skipping watchpoint at %s:%d",
2270 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2277 /* Same as should_be_inserted but does the check assuming
2278 that the location is not duplicated. */
2281 unduplicated_should_be_inserted (struct bp_location
*bl
)
2284 const int save_duplicate
= bl
->duplicate
;
2287 result
= should_be_inserted (bl
);
2288 bl
->duplicate
= save_duplicate
;
2292 /* Parses a conditional described by an expression COND into an
2293 agent expression bytecode suitable for evaluation
2294 by the bytecode interpreter. Return NULL if there was
2295 any error during parsing. */
2297 static agent_expr_up
2298 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2303 agent_expr_up aexpr
;
2305 /* We don't want to stop processing, so catch any errors
2306 that may show up. */
2309 aexpr
= gen_eval_for_expr (scope
, cond
);
2312 catch (const gdb_exception_error
&ex
)
2314 /* If we got here, it means the condition could not be parsed to a valid
2315 bytecode expression and thus can't be evaluated on the target's side.
2316 It's no use iterating through the conditions. */
2319 /* We have a valid agent expression. */
2323 /* Based on location BL, create a list of breakpoint conditions to be
2324 passed on to the target. If we have duplicated locations with different
2325 conditions, we will add such conditions to the list. The idea is that the
2326 target will evaluate the list of conditions and will only notify GDB when
2327 one of them is true. */
2330 build_target_condition_list (struct bp_location
*bl
)
2332 int null_condition_or_parse_error
= 0;
2333 int modified
= bl
->needs_update
;
2335 /* Release conditions left over from a previous insert. */
2336 bl
->target_info
.conditions
.clear ();
2338 /* This is only meaningful if the target is
2339 evaluating conditions and if the user has
2340 opted for condition evaluation on the target's
2342 if (gdb_evaluates_breakpoint_condition_p ()
2343 || !target_supports_evaluation_of_breakpoint_conditions ())
2346 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2348 /* Do a first pass to check for locations with no assigned
2349 conditions or conditions that fail to parse to a valid agent
2350 expression bytecode. If any of these happen, then it's no use to
2351 send conditions to the target since this location will always
2352 trigger and generate a response back to GDB. Note we consider
2353 all locations at the same address irrespective of type, i.e.,
2354 even if the locations aren't considered duplicates (e.g.,
2355 software breakpoint and hardware breakpoint at the same
2357 for (bp_location
*loc
: loc_range
)
2359 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2363 /* Re-parse the conditions since something changed. In that
2364 case we already freed the condition bytecodes (see
2365 force_breakpoint_reinsertion). We just
2366 need to parse the condition to bytecodes again. */
2367 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2371 /* If we have a NULL bytecode expression, it means something
2372 went wrong or we have a null condition expression. */
2373 if (!loc
->cond_bytecode
)
2375 null_condition_or_parse_error
= 1;
2381 /* If any of these happened, it means we will have to evaluate the conditions
2382 for the location's address on gdb's side. It is no use keeping bytecodes
2383 for all the other duplicate locations, thus we free all of them here.
2385 This is so we have a finer control over which locations' conditions are
2386 being evaluated by GDB or the remote stub. */
2387 if (null_condition_or_parse_error
)
2389 for (bp_location
*loc
: loc_range
)
2391 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2393 /* Only go as far as the first NULL bytecode is
2395 if (!loc
->cond_bytecode
)
2398 loc
->cond_bytecode
.reset ();
2403 /* No NULL conditions or failed bytecode generation. Build a
2404 condition list for this location's address. If we have software
2405 and hardware locations at the same address, they aren't
2406 considered duplicates, but we still marge all the conditions
2407 anyway, as it's simpler, and doesn't really make a practical
2409 for (bp_location
*loc
: loc_range
)
2411 && is_breakpoint (loc
->owner
)
2412 && loc
->pspace
->num
== bl
->pspace
->num
2413 && loc
->owner
->enable_state
== bp_enabled
2415 && !loc
->disabled_by_cond
)
2417 /* Add the condition to the vector. This will be used later
2418 to send the conditions to the target. */
2419 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2425 /* Parses a command described by string CMD into an agent expression
2426 bytecode suitable for evaluation by the bytecode interpreter.
2427 Return NULL if there was any error during parsing. */
2429 static agent_expr_up
2430 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2432 const char *cmdrest
;
2433 const char *format_start
, *format_end
;
2434 struct gdbarch
*gdbarch
= get_current_arch ();
2441 if (*cmdrest
== ',')
2443 cmdrest
= skip_spaces (cmdrest
);
2445 if (*cmdrest
++ != '"')
2446 error (_("No format string following the location"));
2448 format_start
= cmdrest
;
2450 format_pieces
fpieces (&cmdrest
);
2452 format_end
= cmdrest
;
2454 if (*cmdrest
++ != '"')
2455 error (_("Bad format string, non-terminated '\"'."));
2457 cmdrest
= skip_spaces (cmdrest
);
2459 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2460 error (_("Invalid argument syntax"));
2462 if (*cmdrest
== ',')
2464 cmdrest
= skip_spaces (cmdrest
);
2466 /* For each argument, make an expression. */
2468 std::vector
<struct expression
*> argvec
;
2469 while (*cmdrest
!= '\0')
2474 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2475 argvec
.push_back (expr
.release ());
2477 if (*cmdrest
== ',')
2481 agent_expr_up aexpr
;
2483 /* We don't want to stop processing, so catch any errors
2484 that may show up. */
2487 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2488 format_start
, format_end
- format_start
,
2489 argvec
.size (), argvec
.data ());
2491 catch (const gdb_exception_error
&ex
)
2493 /* If we got here, it means the command could not be parsed to a valid
2494 bytecode expression and thus can't be evaluated on the target's side.
2495 It's no use iterating through the other commands. */
2498 /* We have a valid agent expression, return it. */
2502 /* Based on location BL, create a list of breakpoint commands to be
2503 passed on to the target. If we have duplicated locations with
2504 different commands, we will add any such to the list. */
2507 build_target_command_list (struct bp_location
*bl
)
2509 int null_command_or_parse_error
= 0;
2510 int modified
= bl
->needs_update
;
2512 /* Clear commands left over from a previous insert. */
2513 bl
->target_info
.tcommands
.clear ();
2515 if (!target_can_run_breakpoint_commands ())
2518 /* For now, limit to agent-style dprintf breakpoints. */
2519 if (dprintf_style
!= dprintf_style_agent
)
2522 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2524 /* For now, if we have any location at the same address that isn't a
2525 dprintf, don't install the target-side commands, as that would
2526 make the breakpoint not be reported to the core, and we'd lose
2528 for (bp_location
*loc
: loc_range
)
2529 if (is_breakpoint (loc
->owner
)
2530 && loc
->pspace
->num
== bl
->pspace
->num
2531 && loc
->owner
->type
!= bp_dprintf
)
2534 /* Do a first pass to check for locations with no assigned
2535 conditions or conditions that fail to parse to a valid agent expression
2536 bytecode. If any of these happen, then it's no use to send conditions
2537 to the target since this location will always trigger and generate a
2538 response back to GDB. */
2539 for (bp_location
*loc
: loc_range
)
2541 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2545 /* Re-parse the commands since something changed. In that
2546 case we already freed the command bytecodes (see
2547 force_breakpoint_reinsertion). We just
2548 need to parse the command to bytecodes again. */
2550 = parse_cmd_to_aexpr (bl
->address
,
2551 loc
->owner
->extra_string
.get ());
2554 /* If we have a NULL bytecode expression, it means something
2555 went wrong or we have a null command expression. */
2556 if (!loc
->cmd_bytecode
)
2558 null_command_or_parse_error
= 1;
2564 /* If anything failed, then we're not doing target-side commands,
2566 if (null_command_or_parse_error
)
2568 for (bp_location
*loc
: loc_range
)
2569 if (is_breakpoint (loc
->owner
)
2570 && loc
->pspace
->num
== bl
->pspace
->num
)
2572 /* Only go as far as the first NULL bytecode is
2574 if (loc
->cmd_bytecode
== NULL
)
2577 loc
->cmd_bytecode
.reset ();
2581 /* No NULL commands or failed bytecode generation. Build a command
2582 list for all duplicate locations at this location's address.
2583 Note that here we must care for whether the breakpoint location
2584 types are considered duplicates, otherwise, say, if we have a
2585 software and hardware location at the same address, the target
2586 could end up running the commands twice. For the moment, we only
2587 support targets-side commands with dprintf, but it doesn't hurt
2588 to be pedantically correct in case that changes. */
2589 for (bp_location
*loc
: loc_range
)
2590 if (breakpoint_locations_match (bl
, loc
)
2591 && loc
->owner
->extra_string
2592 && is_breakpoint (loc
->owner
)
2593 && loc
->pspace
->num
== bl
->pspace
->num
2594 && loc
->owner
->enable_state
== bp_enabled
2596 && !loc
->disabled_by_cond
)
2598 /* Add the command to the vector. This will be used later
2599 to send the commands to the target. */
2600 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2603 bl
->target_info
.persist
= 0;
2604 /* Maybe flag this location as persistent. */
2605 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2606 bl
->target_info
.persist
= 1;
2609 /* Return the kind of breakpoint on address *ADDR. Get the kind
2610 of breakpoint according to ADDR except single-step breakpoint.
2611 Get the kind of single-step breakpoint according to the current
2615 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2617 if (bl
->owner
->type
== bp_single_step
)
2619 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2620 struct regcache
*regcache
;
2622 regcache
= get_thread_regcache (thr
);
2624 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2628 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2631 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2632 location. Any error messages are printed to TMP_ERROR_STREAM; and
2633 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2634 Returns 0 for success, 1 if the bp_location type is not supported or
2637 NOTE drow/2003-09-09: This routine could be broken down to an
2638 object-style method for each breakpoint or catchpoint type. */
2640 insert_bp_location (struct bp_location
*bl
,
2641 struct ui_file
*tmp_error_stream
,
2642 int *disabled_breaks
,
2643 int *hw_breakpoint_error
,
2644 int *hw_bp_error_explained_already
)
2646 gdb_exception bp_excpt
;
2648 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2651 /* Note we don't initialize bl->target_info, as that wipes out
2652 the breakpoint location's shadow_contents if the breakpoint
2653 is still inserted at that location. This in turn breaks
2654 target_read_memory which depends on these buffers when
2655 a memory read is requested at the breakpoint location:
2656 Once the target_info has been wiped, we fail to see that
2657 we have a breakpoint inserted at that address and thus
2658 read the breakpoint instead of returning the data saved in
2659 the breakpoint location's shadow contents. */
2660 bl
->target_info
.reqstd_address
= bl
->address
;
2661 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2662 bl
->target_info
.length
= bl
->length
;
2664 /* When working with target-side conditions, we must pass all the conditions
2665 for the same breakpoint address down to the target since GDB will not
2666 insert those locations. With a list of breakpoint conditions, the target
2667 can decide when to stop and notify GDB. */
2669 if (is_breakpoint (bl
->owner
))
2671 build_target_condition_list (bl
);
2672 build_target_command_list (bl
);
2673 /* Reset the modification marker. */
2674 bl
->needs_update
= 0;
2677 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2678 set at a read-only address, then a breakpoint location will have
2679 been changed to hardware breakpoint before we get here. If it is
2680 "off" however, error out before actually trying to insert the
2681 breakpoint, with a nicer error message. */
2682 if (bl
->loc_type
== bp_loc_software_breakpoint
2683 && !automatic_hardware_breakpoints
)
2685 mem_region
*mr
= lookup_mem_region (bl
->address
);
2687 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2689 gdb_printf (tmp_error_stream
,
2690 _("Cannot insert breakpoint %d.\n"
2691 "Cannot set software breakpoint "
2692 "at read-only address %s\n"),
2694 paddress (bl
->gdbarch
, bl
->address
));
2699 if (bl
->loc_type
== bp_loc_software_breakpoint
2700 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2702 /* First check to see if we have to handle an overlay. */
2703 if (overlay_debugging
== ovly_off
2704 || bl
->section
== NULL
2705 || !(section_is_overlay (bl
->section
)))
2707 /* No overlay handling: just set the breakpoint. */
2712 val
= bl
->owner
->insert_location (bl
);
2714 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2716 catch (gdb_exception
&e
)
2718 bp_excpt
= std::move (e
);
2723 /* This breakpoint is in an overlay section.
2724 Shall we set a breakpoint at the LMA? */
2725 if (!overlay_events_enabled
)
2727 /* Yes -- overlay event support is not active,
2728 so we must try to set a breakpoint at the LMA.
2729 This will not work for a hardware breakpoint. */
2730 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2731 warning (_("hardware breakpoint %d not supported in overlay!"),
2735 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2737 /* Set a software (trap) breakpoint at the LMA. */
2738 bl
->overlay_target_info
= bl
->target_info
;
2739 bl
->overlay_target_info
.reqstd_address
= addr
;
2741 /* No overlay handling: just set the breakpoint. */
2746 bl
->overlay_target_info
.kind
2747 = breakpoint_kind (bl
, &addr
);
2748 bl
->overlay_target_info
.placed_address
= addr
;
2749 val
= target_insert_breakpoint (bl
->gdbarch
,
2750 &bl
->overlay_target_info
);
2753 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2755 catch (gdb_exception
&e
)
2757 bp_excpt
= std::move (e
);
2760 if (bp_excpt
.reason
!= 0)
2761 gdb_printf (tmp_error_stream
,
2762 "Overlay breakpoint %d "
2763 "failed: in ROM?\n",
2767 /* Shall we set a breakpoint at the VMA? */
2768 if (section_is_mapped (bl
->section
))
2770 /* Yes. This overlay section is mapped into memory. */
2775 val
= bl
->owner
->insert_location (bl
);
2777 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2779 catch (gdb_exception
&e
)
2781 bp_excpt
= std::move (e
);
2786 /* No. This breakpoint will not be inserted.
2787 No error, but do not mark the bp as 'inserted'. */
2792 if (bp_excpt
.reason
!= 0)
2794 /* Can't set the breakpoint. */
2796 /* If the target has closed then it will have deleted any
2797 breakpoints inserted within the target inferior, as a result
2798 any further attempts to interact with the breakpoint objects
2799 is not possible. Just rethrow the error. */
2800 if (bp_excpt
.error
== TARGET_CLOSE_ERROR
)
2802 gdb_assert (bl
->owner
!= nullptr);
2804 /* In some cases, we might not be able to insert a
2805 breakpoint in a shared library that has already been
2806 removed, but we have not yet processed the shlib unload
2807 event. Unfortunately, some targets that implement
2808 breakpoint insertion themselves can't tell why the
2809 breakpoint insertion failed (e.g., the remote target
2810 doesn't define error codes), so we must treat generic
2811 errors as memory errors. */
2812 if (bp_excpt
.reason
== RETURN_ERROR
2813 && (bp_excpt
.error
== GENERIC_ERROR
2814 || bp_excpt
.error
== MEMORY_ERROR
)
2815 && bl
->loc_type
== bp_loc_software_breakpoint
2816 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2817 || shared_objfile_contains_address_p (bl
->pspace
,
2820 /* See also: disable_breakpoints_in_shlibs. */
2821 bl
->shlib_disabled
= 1;
2822 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2823 if (!*disabled_breaks
)
2825 gdb_printf (tmp_error_stream
,
2826 "Cannot insert breakpoint %d.\n",
2828 gdb_printf (tmp_error_stream
,
2829 "Temporarily disabling shared "
2830 "library breakpoints:\n");
2832 *disabled_breaks
= 1;
2833 gdb_printf (tmp_error_stream
,
2834 "breakpoint #%d\n", bl
->owner
->number
);
2839 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2841 *hw_breakpoint_error
= 1;
2842 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2843 gdb_printf (tmp_error_stream
,
2844 "Cannot insert hardware breakpoint %d%s",
2846 bp_excpt
.message
? ":" : ".\n");
2847 if (bp_excpt
.message
!= NULL
)
2848 gdb_printf (tmp_error_stream
, "%s.\n",
2853 if (bp_excpt
.message
== NULL
)
2856 = memory_error_message (TARGET_XFER_E_IO
,
2857 bl
->gdbarch
, bl
->address
);
2859 gdb_printf (tmp_error_stream
,
2860 "Cannot insert breakpoint %d.\n"
2862 bl
->owner
->number
, message
.c_str ());
2866 gdb_printf (tmp_error_stream
,
2867 "Cannot insert breakpoint %d: %s\n",
2882 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2883 /* NOTE drow/2003-09-08: This state only exists for removing
2884 watchpoints. It's not clear that it's necessary... */
2885 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2889 val
= bl
->owner
->insert_location (bl
);
2891 /* If trying to set a read-watchpoint, and it turns out it's not
2892 supported, try emulating one with an access watchpoint. */
2893 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2895 /* But don't try to insert it, if there's already another
2896 hw_access location that would be considered a duplicate
2898 for (bp_location
*loc
: all_bp_locations ())
2900 && loc
->watchpoint_type
== hw_access
2901 && watchpoint_locations_match (bl
, loc
))
2905 bl
->target_info
= loc
->target_info
;
2906 bl
->watchpoint_type
= hw_access
;
2913 bl
->watchpoint_type
= hw_access
;
2914 val
= bl
->owner
->insert_location (bl
);
2917 /* Back to the original value. */
2918 bl
->watchpoint_type
= hw_read
;
2922 bl
->inserted
= (val
== 0);
2925 else if (bl
->owner
->type
== bp_catchpoint
)
2929 val
= bl
->owner
->insert_location (bl
);
2932 bl
->owner
->enable_state
= bp_disabled
;
2936 Error inserting catchpoint %d: Your system does not support this type\n\
2937 of catchpoint."), bl
->owner
->number
);
2939 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2942 bl
->inserted
= (val
== 0);
2944 /* We've already printed an error message if there was a problem
2945 inserting this catchpoint, and we've disabled the catchpoint,
2946 so just return success. */
2953 /* This function is called when program space PSPACE is about to be
2954 deleted. It takes care of updating breakpoints to not reference
2958 breakpoint_program_space_exit (struct program_space
*pspace
)
2960 /* Remove any breakpoint that was set through this program space. */
2961 for (breakpoint
*b
: all_breakpoints_safe ())
2962 if (b
->pspace
== pspace
)
2963 delete_breakpoint (b
);
2965 /* Breakpoints set through other program spaces could have locations
2966 bound to PSPACE as well. Remove those. */
2967 for (bp_location
*loc
: all_bp_locations ())
2969 struct bp_location
*tmp
;
2971 if (loc
->pspace
== pspace
)
2973 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2974 if (loc
->owner
->loc
== loc
)
2975 loc
->owner
->loc
= loc
->next
;
2977 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2978 if (tmp
->next
== loc
)
2980 tmp
->next
= loc
->next
;
2986 /* Now update the global location list to permanently delete the
2987 removed locations above. */
2988 update_global_location_list (UGLL_DONT_INSERT
);
2991 /* Make sure all breakpoints are inserted in inferior.
2992 Throws exception on any error.
2993 A breakpoint that is already inserted won't be inserted
2994 again, so calling this function twice is safe. */
2996 insert_breakpoints (void)
2998 for (breakpoint
*bpt
: all_breakpoints ())
2999 if (is_hardware_watchpoint (bpt
))
3001 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
3003 update_watchpoint (w
, 0 /* don't reparse. */);
3006 /* Updating watchpoints creates new locations, so update the global
3007 location list. Explicitly tell ugll to insert locations and
3008 ignore breakpoints_always_inserted_mode. Also,
3009 update_global_location_list tries to "upgrade" software
3010 breakpoints to hardware breakpoints to handle "set breakpoint
3011 auto-hw", so we need to call it even if we don't have new
3013 update_global_location_list (UGLL_INSERT
);
3016 /* This is used when we need to synch breakpoint conditions between GDB and the
3017 target. It is the case with deleting and disabling of breakpoints when using
3018 always-inserted mode. */
3021 update_inserted_breakpoint_locations (void)
3025 int disabled_breaks
= 0;
3026 int hw_breakpoint_error
= 0;
3027 int hw_bp_details_reported
= 0;
3029 string_file tmp_error_stream
;
3031 /* Explicitly mark the warning -- this will only be printed if
3032 there was an error. */
3033 tmp_error_stream
.puts ("Warning:\n");
3035 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3037 for (bp_location
*bl
: all_bp_locations ())
3039 /* We only want to update software breakpoints and hardware
3041 if (!is_breakpoint (bl
->owner
))
3044 /* We only want to update locations that are already inserted
3045 and need updating. This is to avoid unwanted insertion during
3046 deletion of breakpoints. */
3047 if (!bl
->inserted
|| !bl
->needs_update
)
3050 switch_to_program_space_and_thread (bl
->pspace
);
3052 /* For targets that support global breakpoints, there's no need
3053 to select an inferior to insert breakpoint to. In fact, even
3054 if we aren't attached to any process yet, we should still
3055 insert breakpoints. */
3056 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3057 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3060 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3061 &hw_breakpoint_error
, &hw_bp_details_reported
);
3068 target_terminal::ours_for_output ();
3069 error_stream (tmp_error_stream
);
3073 /* Used when starting or continuing the program. */
3076 insert_breakpoint_locations (void)
3080 int disabled_breaks
= 0;
3081 int hw_breakpoint_error
= 0;
3082 int hw_bp_error_explained_already
= 0;
3084 string_file tmp_error_stream
;
3086 /* Explicitly mark the warning -- this will only be printed if
3087 there was an error. */
3088 tmp_error_stream
.puts ("Warning:\n");
3090 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3092 for (bp_location
*bl
: all_bp_locations ())
3094 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3097 /* There is no point inserting thread-specific breakpoints if
3098 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3099 has BL->OWNER always non-NULL. */
3100 if (bl
->owner
->thread
!= -1
3101 && !valid_global_thread_id (bl
->owner
->thread
))
3104 switch_to_program_space_and_thread (bl
->pspace
);
3106 /* For targets that support global breakpoints, there's no need
3107 to select an inferior to insert breakpoint to. In fact, even
3108 if we aren't attached to any process yet, we should still
3109 insert breakpoints. */
3110 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3111 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3114 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3115 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3120 /* If we failed to insert all locations of a watchpoint, remove
3121 them, as half-inserted watchpoint is of limited use. */
3122 for (breakpoint
*bpt
: all_breakpoints ())
3124 int some_failed
= 0;
3126 if (!is_hardware_watchpoint (bpt
))
3129 if (!breakpoint_enabled (bpt
))
3132 if (bpt
->disposition
== disp_del_at_next_stop
)
3135 for (bp_location
*loc
: bpt
->locations ())
3136 if (!loc
->inserted
&& should_be_inserted (loc
))
3144 for (bp_location
*loc
: bpt
->locations ())
3146 remove_breakpoint (loc
);
3148 hw_breakpoint_error
= 1;
3149 tmp_error_stream
.printf ("Could not insert "
3150 "hardware watchpoint %d.\n",
3158 /* If a hardware breakpoint or watchpoint was inserted, add a
3159 message about possibly exhausted resources. */
3160 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3162 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3163 You may have requested too many hardware breakpoints/watchpoints.\n");
3165 target_terminal::ours_for_output ();
3166 error_stream (tmp_error_stream
);
3170 /* Used when the program stops.
3171 Returns zero if successful, or non-zero if there was a problem
3172 removing a breakpoint location. */
3175 remove_breakpoints (void)
3179 for (bp_location
*bl
: all_bp_locations ())
3180 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3181 val
|= remove_breakpoint (bl
);
3186 /* When a thread exits, remove breakpoints that are related to
3190 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3192 for (breakpoint
*b
: all_breakpoints_safe ())
3194 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3196 b
->disposition
= disp_del_at_next_stop
;
3199 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3200 b
->number
, print_thread_id (tp
));
3202 /* Hide it from the user. */
3208 /* See breakpoint.h. */
3211 remove_breakpoints_inf (inferior
*inf
)
3215 for (bp_location
*bl
: all_bp_locations ())
3217 if (bl
->pspace
!= inf
->pspace
)
3220 if (bl
->inserted
&& !bl
->target_info
.persist
)
3222 val
= remove_breakpoint (bl
);
3229 static int internal_breakpoint_number
= -1;
3231 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3232 If INTERNAL is non-zero, the breakpoint number will be populated
3233 from internal_breakpoint_number and that variable decremented.
3234 Otherwise the breakpoint number will be populated from
3235 breakpoint_count and that value incremented. Internal breakpoints
3236 do not set the internal var bpnum. */
3238 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3241 b
->number
= internal_breakpoint_number
--;
3244 set_breakpoint_count (breakpoint_count
+ 1);
3245 b
->number
= breakpoint_count
;
3249 static struct breakpoint
*
3250 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3251 CORE_ADDR address
, enum bptype type
)
3253 symtab_and_line sal
;
3255 sal
.section
= find_pc_overlay (sal
.pc
);
3256 sal
.pspace
= current_program_space
;
3258 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
);
3259 b
->number
= internal_breakpoint_number
--;
3260 b
->disposition
= disp_donttouch
;
3265 static const char *const longjmp_names
[] =
3267 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3269 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3271 /* Per-objfile data private to breakpoint.c. */
3272 struct breakpoint_objfile_data
3274 /* Minimal symbol for "_ovly_debug_event" (if any). */
3275 struct bound_minimal_symbol overlay_msym
;
3277 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3278 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3280 /* True if we have looked for longjmp probes. */
3281 int longjmp_searched
= 0;
3283 /* SystemTap probe points for longjmp (if any). These are non-owning
3285 std::vector
<probe
*> longjmp_probes
;
3287 /* Minimal symbol for "std::terminate()" (if any). */
3288 struct bound_minimal_symbol terminate_msym
;
3290 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3291 struct bound_minimal_symbol exception_msym
;
3293 /* True if we have looked for exception probes. */
3294 int exception_searched
= 0;
3296 /* SystemTap probe points for unwinding (if any). These are non-owning
3298 std::vector
<probe
*> exception_probes
;
3301 static const struct objfile_key
<breakpoint_objfile_data
>
3302 breakpoint_objfile_key
;
3304 /* Minimal symbol not found sentinel. */
3305 static struct minimal_symbol msym_not_found
;
3307 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3310 msym_not_found_p (const struct minimal_symbol
*msym
)
3312 return msym
== &msym_not_found
;
3315 /* Return per-objfile data needed by breakpoint.c.
3316 Allocate the data if necessary. */
3318 static struct breakpoint_objfile_data
*
3319 get_breakpoint_objfile_data (struct objfile
*objfile
)
3321 struct breakpoint_objfile_data
*bp_objfile_data
;
3323 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3324 if (bp_objfile_data
== NULL
)
3325 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3326 return bp_objfile_data
;
3330 create_overlay_event_breakpoint (void)
3332 const char *const func_name
= "_ovly_debug_event";
3334 for (objfile
*objfile
: current_program_space
->objfiles ())
3336 struct breakpoint
*b
;
3337 struct breakpoint_objfile_data
*bp_objfile_data
;
3339 struct explicit_location explicit_loc
;
3341 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3343 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3346 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3348 struct bound_minimal_symbol m
;
3350 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3351 if (m
.minsym
== NULL
)
3353 /* Avoid future lookups in this objfile. */
3354 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3357 bp_objfile_data
->overlay_msym
= m
;
3360 addr
= bp_objfile_data
->overlay_msym
.value_address ();
3361 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3363 initialize_explicit_location (&explicit_loc
);
3364 explicit_loc
.function_name
= ASTRDUP (func_name
);
3365 b
->location
= new_explicit_location (&explicit_loc
);
3367 if (overlay_debugging
== ovly_auto
)
3369 b
->enable_state
= bp_enabled
;
3370 overlay_events_enabled
= 1;
3374 b
->enable_state
= bp_disabled
;
3375 overlay_events_enabled
= 0;
3380 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3381 true if a breakpoint was installed. */
3384 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3386 struct gdbarch
*gdbarch
= objfile
->arch ();
3387 struct breakpoint_objfile_data
*bp_objfile_data
3388 = get_breakpoint_objfile_data (objfile
);
3390 if (!bp_objfile_data
->longjmp_searched
)
3392 std::vector
<probe
*> ret
3393 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3397 /* We are only interested in checking one element. */
3400 if (!p
->can_evaluate_arguments ())
3402 /* We cannot use the probe interface here,
3403 because it does not know how to evaluate
3408 bp_objfile_data
->longjmp_probes
= ret
;
3409 bp_objfile_data
->longjmp_searched
= 1;
3412 if (bp_objfile_data
->longjmp_probes
.empty ())
3415 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3417 struct breakpoint
*b
;
3419 b
= create_internal_breakpoint (gdbarch
,
3420 p
->get_relocated_address (objfile
),
3422 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3423 b
->enable_state
= bp_disabled
;
3429 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3430 Return true if at least one breakpoint was installed. */
3433 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3435 struct gdbarch
*gdbarch
= objfile
->arch ();
3436 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3439 struct breakpoint_objfile_data
*bp_objfile_data
3440 = get_breakpoint_objfile_data (objfile
);
3441 unsigned int installed_bp
= 0;
3443 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3445 struct breakpoint
*b
;
3446 const char *func_name
;
3448 struct explicit_location explicit_loc
;
3450 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3453 func_name
= longjmp_names
[i
];
3454 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3456 struct bound_minimal_symbol m
;
3458 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3459 if (m
.minsym
== NULL
)
3461 /* Prevent future lookups in this objfile. */
3462 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3465 bp_objfile_data
->longjmp_msym
[i
] = m
;
3468 addr
= bp_objfile_data
->longjmp_msym
[i
].value_address ();
3469 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
);
3470 initialize_explicit_location (&explicit_loc
);
3471 explicit_loc
.function_name
= ASTRDUP (func_name
);
3472 b
->location
= new_explicit_location (&explicit_loc
);
3473 b
->enable_state
= bp_disabled
;
3477 return installed_bp
> 0;
3480 /* Create a master longjmp breakpoint. */
3483 create_longjmp_master_breakpoint (void)
3485 scoped_restore_current_program_space restore_pspace
;
3487 for (struct program_space
*pspace
: program_spaces
)
3489 set_current_program_space (pspace
);
3491 for (objfile
*obj
: current_program_space
->objfiles ())
3493 /* Skip separate debug object, it's handled in the loop below. */
3494 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3497 /* Try a probe kind breakpoint on main objfile. */
3498 if (create_longjmp_master_breakpoint_probe (obj
))
3501 /* Try longjmp_names kind breakpoints on main and separate_debug
3503 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3504 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3510 /* Create a master std::terminate breakpoint. */
3512 create_std_terminate_master_breakpoint (void)
3514 const char *const func_name
= "std::terminate()";
3516 scoped_restore_current_program_space restore_pspace
;
3518 for (struct program_space
*pspace
: program_spaces
)
3522 set_current_program_space (pspace
);
3524 for (objfile
*objfile
: current_program_space
->objfiles ())
3526 struct breakpoint
*b
;
3527 struct breakpoint_objfile_data
*bp_objfile_data
;
3528 struct explicit_location explicit_loc
;
3530 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3532 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3535 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3537 struct bound_minimal_symbol m
;
3539 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3540 if (m
.minsym
== NULL
|| (m
.minsym
->type () != mst_text
3541 && m
.minsym
->type () != mst_file_text
))
3543 /* Prevent future lookups in this objfile. */
3544 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3547 bp_objfile_data
->terminate_msym
= m
;
3550 addr
= bp_objfile_data
->terminate_msym
.value_address ();
3551 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3552 bp_std_terminate_master
);
3553 initialize_explicit_location (&explicit_loc
);
3554 explicit_loc
.function_name
= ASTRDUP (func_name
);
3555 b
->location
= new_explicit_location (&explicit_loc
);
3556 b
->enable_state
= bp_disabled
;
3561 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3562 probe. Return true if a breakpoint was installed. */
3565 create_exception_master_breakpoint_probe (objfile
*objfile
)
3567 struct breakpoint
*b
;
3568 struct gdbarch
*gdbarch
;
3569 struct breakpoint_objfile_data
*bp_objfile_data
;
3571 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3573 /* We prefer the SystemTap probe point if it exists. */
3574 if (!bp_objfile_data
->exception_searched
)
3576 std::vector
<probe
*> ret
3577 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3581 /* We are only interested in checking one element. */
3584 if (!p
->can_evaluate_arguments ())
3586 /* We cannot use the probe interface here, because it does
3587 not know how to evaluate arguments. */
3591 bp_objfile_data
->exception_probes
= ret
;
3592 bp_objfile_data
->exception_searched
= 1;
3595 if (bp_objfile_data
->exception_probes
.empty ())
3598 gdbarch
= objfile
->arch ();
3600 for (probe
*p
: bp_objfile_data
->exception_probes
)
3602 b
= create_internal_breakpoint (gdbarch
,
3603 p
->get_relocated_address (objfile
),
3604 bp_exception_master
);
3605 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3606 b
->enable_state
= bp_disabled
;
3612 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3613 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3616 create_exception_master_breakpoint_hook (objfile
*objfile
)
3618 const char *const func_name
= "_Unwind_DebugHook";
3619 struct breakpoint
*b
;
3620 struct gdbarch
*gdbarch
;
3621 struct breakpoint_objfile_data
*bp_objfile_data
;
3623 struct explicit_location explicit_loc
;
3625 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3627 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3630 gdbarch
= objfile
->arch ();
3632 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3634 struct bound_minimal_symbol debug_hook
;
3636 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3637 if (debug_hook
.minsym
== NULL
)
3639 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3643 bp_objfile_data
->exception_msym
= debug_hook
;
3646 addr
= bp_objfile_data
->exception_msym
.value_address ();
3647 addr
= gdbarch_convert_from_func_ptr_addr
3648 (gdbarch
, addr
, current_inferior ()->top_target ());
3649 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
);
3650 initialize_explicit_location (&explicit_loc
);
3651 explicit_loc
.function_name
= ASTRDUP (func_name
);
3652 b
->location
= new_explicit_location (&explicit_loc
);
3653 b
->enable_state
= bp_disabled
;
3658 /* Install a master breakpoint on the unwinder's debug hook. */
3661 create_exception_master_breakpoint (void)
3663 for (objfile
*obj
: current_program_space
->objfiles ())
3665 /* Skip separate debug object. */
3666 if (obj
->separate_debug_objfile_backlink
)
3669 /* Try a probe kind breakpoint. */
3670 if (create_exception_master_breakpoint_probe (obj
))
3673 /* Iterate over main and separate debug objects and try an
3674 _Unwind_DebugHook kind breakpoint. */
3675 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3676 if (create_exception_master_breakpoint_hook (debug_objfile
))
3681 /* Does B have a location spec? */
3684 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3686 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3690 update_breakpoints_after_exec (void)
3692 /* We're about to delete breakpoints from GDB's lists. If the
3693 INSERTED flag is true, GDB will try to lift the breakpoints by
3694 writing the breakpoints' "shadow contents" back into memory. The
3695 "shadow contents" are NOT valid after an exec, so GDB should not
3696 do that. Instead, the target is responsible from marking
3697 breakpoints out as soon as it detects an exec. We don't do that
3698 here instead, because there may be other attempts to delete
3699 breakpoints after detecting an exec and before reaching here. */
3700 for (bp_location
*bploc
: all_bp_locations ())
3701 if (bploc
->pspace
== current_program_space
)
3702 gdb_assert (!bploc
->inserted
);
3704 for (breakpoint
*b
: all_breakpoints_safe ())
3706 if (b
->pspace
!= current_program_space
)
3709 /* Solib breakpoints must be explicitly reset after an exec(). */
3710 if (b
->type
== bp_shlib_event
)
3712 delete_breakpoint (b
);
3716 /* JIT breakpoints must be explicitly reset after an exec(). */
3717 if (b
->type
== bp_jit_event
)
3719 delete_breakpoint (b
);
3723 /* Thread event breakpoints must be set anew after an exec(),
3724 as must overlay event and longjmp master breakpoints. */
3725 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3726 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3727 || b
->type
== bp_exception_master
)
3729 delete_breakpoint (b
);
3733 /* Step-resume breakpoints are meaningless after an exec(). */
3734 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3736 delete_breakpoint (b
);
3740 /* Just like single-step breakpoints. */
3741 if (b
->type
== bp_single_step
)
3743 delete_breakpoint (b
);
3747 /* Longjmp and longjmp-resume breakpoints are also meaningless
3749 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3750 || b
->type
== bp_longjmp_call_dummy
3751 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3753 delete_breakpoint (b
);
3757 if (b
->type
== bp_catchpoint
)
3759 /* For now, none of the bp_catchpoint breakpoints need to
3760 do anything at this point. In the future, if some of
3761 the catchpoints need to something, we will need to add
3762 a new method, and call this method from here. */
3766 /* bp_finish is a special case. The only way we ought to be able
3767 to see one of these when an exec() has happened, is if the user
3768 caught a vfork, and then said "finish". Ordinarily a finish just
3769 carries them to the call-site of the current callee, by setting
3770 a temporary bp there and resuming. But in this case, the finish
3771 will carry them entirely through the vfork & exec.
3773 We don't want to allow a bp_finish to remain inserted now. But
3774 we can't safely delete it, 'cause finish_command has a handle to
3775 the bp on a bpstat, and will later want to delete it. There's a
3776 chance (and I've seen it happen) that if we delete the bp_finish
3777 here, that its storage will get reused by the time finish_command
3778 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3779 We really must allow finish_command to delete a bp_finish.
3781 In the absence of a general solution for the "how do we know
3782 it's safe to delete something others may have handles to?"
3783 problem, what we'll do here is just uninsert the bp_finish, and
3784 let finish_command delete it.
3786 (We know the bp_finish is "doomed" in the sense that it's
3787 momentary, and will be deleted as soon as finish_command sees
3788 the inferior stopped. So it doesn't matter that the bp's
3789 address is probably bogus in the new a.out, unlike e.g., the
3790 solib breakpoints.) */
3792 if (b
->type
== bp_finish
)
3797 /* Without a symbolic address, we have little hope of the
3798 pre-exec() address meaning the same thing in the post-exec()
3800 if (breakpoint_event_location_empty_p (b
))
3802 delete_breakpoint (b
);
3809 detach_breakpoints (ptid_t ptid
)
3812 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3813 struct inferior
*inf
= current_inferior ();
3815 if (ptid
.pid () == inferior_ptid
.pid ())
3816 error (_("Cannot detach breakpoints of inferior_ptid"));
3818 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3819 inferior_ptid
= ptid
;
3820 for (bp_location
*bl
: all_bp_locations ())
3822 if (bl
->pspace
!= inf
->pspace
)
3825 /* This function must physically remove breakpoints locations
3826 from the specified ptid, without modifying the breakpoint
3827 package's state. Locations of type bp_loc_other are only
3828 maintained at GDB side. So, there is no need to remove
3829 these bp_loc_other locations. Moreover, removing these
3830 would modify the breakpoint package's state. */
3831 if (bl
->loc_type
== bp_loc_other
)
3835 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3841 /* Remove the breakpoint location BL from the current address space.
3842 Note that this is used to detach breakpoints from a child fork.
3843 When we get here, the child isn't in the inferior list, and neither
3844 do we have objects to represent its address space --- we should
3845 *not* look at bl->pspace->aspace here. */
3848 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3852 /* BL is never in moribund_locations by our callers. */
3853 gdb_assert (bl
->owner
!= NULL
);
3855 /* The type of none suggests that owner is actually deleted.
3856 This should not ever happen. */
3857 gdb_assert (bl
->owner
->type
!= bp_none
);
3859 if (bl
->loc_type
== bp_loc_software_breakpoint
3860 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3862 /* "Normal" instruction breakpoint: either the standard
3863 trap-instruction bp (bp_breakpoint), or a
3864 bp_hardware_breakpoint. */
3866 /* First check to see if we have to handle an overlay. */
3867 if (overlay_debugging
== ovly_off
3868 || bl
->section
== NULL
3869 || !(section_is_overlay (bl
->section
)))
3871 /* No overlay handling: just remove the breakpoint. */
3873 /* If we're trying to uninsert a memory breakpoint that we
3874 know is set in a dynamic object that is marked
3875 shlib_disabled, then either the dynamic object was
3876 removed with "remove-symbol-file" or with
3877 "nosharedlibrary". In the former case, we don't know
3878 whether another dynamic object might have loaded over the
3879 breakpoint's address -- the user might well let us know
3880 about it next with add-symbol-file (the whole point of
3881 add-symbol-file is letting the user manually maintain a
3882 list of dynamically loaded objects). If we have the
3883 breakpoint's shadow memory, that is, this is a software
3884 breakpoint managed by GDB, check whether the breakpoint
3885 is still inserted in memory, to avoid overwriting wrong
3886 code with stale saved shadow contents. Note that HW
3887 breakpoints don't have shadow memory, as they're
3888 implemented using a mechanism that is not dependent on
3889 being able to modify the target's memory, and as such
3890 they should always be removed. */
3891 if (bl
->shlib_disabled
3892 && bl
->target_info
.shadow_len
!= 0
3893 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3896 val
= bl
->owner
->remove_location (bl
, reason
);
3900 /* This breakpoint is in an overlay section.
3901 Did we set a breakpoint at the LMA? */
3902 if (!overlay_events_enabled
)
3904 /* Yes -- overlay event support is not active, so we
3905 should have set a breakpoint at the LMA. Remove it.
3907 /* Ignore any failures: if the LMA is in ROM, we will
3908 have already warned when we failed to insert it. */
3909 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3910 target_remove_hw_breakpoint (bl
->gdbarch
,
3911 &bl
->overlay_target_info
);
3913 target_remove_breakpoint (bl
->gdbarch
,
3914 &bl
->overlay_target_info
,
3917 /* Did we set a breakpoint at the VMA?
3918 If so, we will have marked the breakpoint 'inserted'. */
3921 /* Yes -- remove it. Previously we did not bother to
3922 remove the breakpoint if the section had been
3923 unmapped, but let's not rely on that being safe. We
3924 don't know what the overlay manager might do. */
3926 /* However, we should remove *software* breakpoints only
3927 if the section is still mapped, or else we overwrite
3928 wrong code with the saved shadow contents. */
3929 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3930 || section_is_mapped (bl
->section
))
3931 val
= bl
->owner
->remove_location (bl
, reason
);
3937 /* No -- not inserted, so no need to remove. No error. */
3942 /* In some cases, we might not be able to remove a breakpoint in
3943 a shared library that has already been removed, but we have
3944 not yet processed the shlib unload event. Similarly for an
3945 unloaded add-symbol-file object - the user might not yet have
3946 had the chance to remove-symbol-file it. shlib_disabled will
3947 be set if the library/object has already been removed, but
3948 the breakpoint hasn't been uninserted yet, e.g., after
3949 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3950 always-inserted mode. */
3952 && (bl
->loc_type
== bp_loc_software_breakpoint
3953 && (bl
->shlib_disabled
3954 || solib_name_from_address (bl
->pspace
, bl
->address
)
3955 || shared_objfile_contains_address_p (bl
->pspace
,
3961 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3963 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3965 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3966 bl
->owner
->remove_location (bl
, reason
);
3968 /* Failure to remove any of the hardware watchpoints comes here. */
3969 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3970 warning (_("Could not remove hardware watchpoint %d."),
3973 else if (bl
->owner
->type
== bp_catchpoint
3974 && breakpoint_enabled (bl
->owner
)
3977 val
= bl
->owner
->remove_location (bl
, reason
);
3981 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3988 remove_breakpoint (struct bp_location
*bl
)
3990 /* BL is never in moribund_locations by our callers. */
3991 gdb_assert (bl
->owner
!= NULL
);
3993 /* The type of none suggests that owner is actually deleted.
3994 This should not ever happen. */
3995 gdb_assert (bl
->owner
->type
!= bp_none
);
3997 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3999 switch_to_program_space_and_thread (bl
->pspace
);
4001 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
4004 /* Clear the "inserted" flag in all breakpoints. */
4007 mark_breakpoints_out (void)
4009 for (bp_location
*bl
: all_bp_locations ())
4010 if (bl
->pspace
== current_program_space
)
4014 /* Clear the "inserted" flag in all breakpoints and delete any
4015 breakpoints which should go away between runs of the program.
4017 Plus other such housekeeping that has to be done for breakpoints
4020 Note: this function gets called at the end of a run (by
4021 generic_mourn_inferior) and when a run begins (by
4022 init_wait_for_inferior). */
4027 breakpoint_init_inferior (enum inf_context context
)
4029 struct program_space
*pspace
= current_program_space
;
4031 /* If breakpoint locations are shared across processes, then there's
4033 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4036 mark_breakpoints_out ();
4038 for (breakpoint
*b
: all_breakpoints_safe ())
4040 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4046 case bp_longjmp_call_dummy
:
4048 /* If the call dummy breakpoint is at the entry point it will
4049 cause problems when the inferior is rerun, so we better get
4052 case bp_watchpoint_scope
:
4054 /* Also get rid of scope breakpoints. */
4056 case bp_shlib_event
:
4058 /* Also remove solib event breakpoints. Their addresses may
4059 have changed since the last time we ran the program.
4060 Actually we may now be debugging against different target;
4061 and so the solib backend that installed this breakpoint may
4062 not be used in by the target. E.g.,
4064 (gdb) file prog-linux
4065 (gdb) run # native linux target
4068 (gdb) file prog-win.exe
4069 (gdb) tar rem :9999 # remote Windows gdbserver.
4072 case bp_step_resume
:
4074 /* Also remove step-resume breakpoints. */
4076 case bp_single_step
:
4078 /* Also remove single-step breakpoints. */
4080 delete_breakpoint (b
);
4084 case bp_hardware_watchpoint
:
4085 case bp_read_watchpoint
:
4086 case bp_access_watchpoint
:
4088 struct watchpoint
*w
= (struct watchpoint
*) b
;
4090 /* Likewise for watchpoints on local expressions. */
4091 if (w
->exp_valid_block
!= NULL
)
4092 delete_breakpoint (b
);
4095 /* Get rid of existing locations, which are no longer
4096 valid. New ones will be created in
4097 update_watchpoint, when the inferior is restarted.
4098 The next update_global_location_list call will
4099 garbage collect them. */
4102 if (context
== inf_starting
)
4104 /* Reset val field to force reread of starting value in
4105 insert_breakpoints. */
4106 w
->val
.reset (nullptr);
4107 w
->val_valid
= false;
4117 /* Get rid of the moribund locations. */
4118 for (bp_location
*bl
: moribund_locations
)
4119 decref_bp_location (&bl
);
4120 moribund_locations
.clear ();
4123 /* These functions concern about actual breakpoints inserted in the
4124 target --- to e.g. check if we need to do decr_pc adjustment or if
4125 we need to hop over the bkpt --- so we check for address space
4126 match, not program space. */
4128 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4129 exists at PC. It returns ordinary_breakpoint_here if it's an
4130 ordinary breakpoint, or permanent_breakpoint_here if it's a
4131 permanent breakpoint.
4132 - When continuing from a location with an ordinary breakpoint, we
4133 actually single step once before calling insert_breakpoints.
4134 - When continuing from a location with a permanent breakpoint, we
4135 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4136 the target, to advance the PC past the breakpoint. */
4138 enum breakpoint_here
4139 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4141 int any_breakpoint_here
= 0;
4143 for (bp_location
*bl
: all_bp_locations ())
4145 if (bl
->loc_type
!= bp_loc_software_breakpoint
4146 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4149 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4150 if ((breakpoint_enabled (bl
->owner
)
4152 && breakpoint_location_address_match (bl
, aspace
, pc
))
4154 if (overlay_debugging
4155 && section_is_overlay (bl
->section
)
4156 && !section_is_mapped (bl
->section
))
4157 continue; /* unmapped overlay -- can't be a match */
4158 else if (bl
->permanent
)
4159 return permanent_breakpoint_here
;
4161 any_breakpoint_here
= 1;
4165 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4168 /* See breakpoint.h. */
4171 breakpoint_in_range_p (const address_space
*aspace
,
4172 CORE_ADDR addr
, ULONGEST len
)
4174 for (bp_location
*bl
: all_bp_locations ())
4176 if (bl
->loc_type
!= bp_loc_software_breakpoint
4177 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4180 if ((breakpoint_enabled (bl
->owner
)
4182 && breakpoint_location_address_range_overlap (bl
, aspace
,
4185 if (overlay_debugging
4186 && section_is_overlay (bl
->section
)
4187 && !section_is_mapped (bl
->section
))
4189 /* Unmapped overlay -- can't be a match. */
4200 /* Return true if there's a moribund breakpoint at PC. */
4203 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4205 for (bp_location
*loc
: moribund_locations
)
4206 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4212 /* Returns non-zero iff BL is inserted at PC, in address space
4216 bp_location_inserted_here_p (struct bp_location
*bl
,
4217 const address_space
*aspace
, CORE_ADDR pc
)
4220 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4223 if (overlay_debugging
4224 && section_is_overlay (bl
->section
)
4225 && !section_is_mapped (bl
->section
))
4226 return 0; /* unmapped overlay -- can't be a match */
4233 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4236 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4238 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4240 if (bl
->loc_type
!= bp_loc_software_breakpoint
4241 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4244 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4250 /* This function returns non-zero iff there is a software breakpoint
4254 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4257 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4259 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4262 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4269 /* See breakpoint.h. */
4272 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4275 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4277 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4280 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4288 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4289 CORE_ADDR addr
, ULONGEST len
)
4291 for (breakpoint
*bpt
: all_breakpoints ())
4293 if (bpt
->type
!= bp_hardware_watchpoint
4294 && bpt
->type
!= bp_access_watchpoint
)
4297 if (!breakpoint_enabled (bpt
))
4300 for (bp_location
*loc
: bpt
->locations ())
4301 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4305 /* Check for intersection. */
4306 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4307 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4315 /* See breakpoint.h. */
4318 is_catchpoint (struct breakpoint
*b
)
4320 return (b
->type
== bp_catchpoint
);
4323 /* Clear a bpstat so that it says we are not at any breakpoint.
4324 Also free any storage that is part of a bpstat. */
4327 bpstat_clear (bpstat
**bsp
)
4344 bpstat::bpstat (const bpstat
&other
)
4346 bp_location_at (other
.bp_location_at
),
4347 breakpoint_at (other
.breakpoint_at
),
4348 commands (other
.commands
),
4349 print (other
.print
),
4351 print_it (other
.print_it
)
4353 if (other
.old_val
!= NULL
)
4354 old_val
= release_value (value_copy (other
.old_val
.get ()));
4357 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4358 is part of the bpstat is copied as well. */
4361 bpstat_copy (bpstat
*bs
)
4363 bpstat
*p
= nullptr;
4365 bpstat
*retval
= nullptr;
4370 for (; bs
!= NULL
; bs
= bs
->next
)
4372 tmp
= new bpstat (*bs
);
4375 /* This is the first thing in the chain. */
4385 /* Find the bpstat associated with this breakpoint. */
4388 bpstat_find_breakpoint (bpstat
*bsp
, struct breakpoint
*breakpoint
)
4393 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4395 if (bsp
->breakpoint_at
== breakpoint
)
4401 /* See breakpoint.h. */
4404 bpstat_explains_signal (bpstat
*bsp
, enum gdb_signal sig
)
4406 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4408 if (bsp
->breakpoint_at
== NULL
)
4410 /* A moribund location can never explain a signal other than
4412 if (sig
== GDB_SIGNAL_TRAP
)
4417 if (bsp
->breakpoint_at
->explains_signal (sig
))
4425 /* Put in *NUM the breakpoint number of the first breakpoint we are
4426 stopped at. *BSP upon return is a bpstat which points to the
4427 remaining breakpoints stopped at (but which is not guaranteed to be
4428 good for anything but further calls to bpstat_num).
4430 Return 0 if passed a bpstat which does not indicate any breakpoints.
4431 Return -1 if stopped at a breakpoint that has been deleted since
4433 Return 1 otherwise. */
4436 bpstat_num (bpstat
**bsp
, int *num
)
4438 struct breakpoint
*b
;
4441 return 0; /* No more breakpoint values */
4443 /* We assume we'll never have several bpstats that correspond to a
4444 single breakpoint -- otherwise, this function might return the
4445 same number more than once and this will look ugly. */
4446 b
= (*bsp
)->breakpoint_at
;
4447 *bsp
= (*bsp
)->next
;
4449 return -1; /* breakpoint that's been deleted since */
4451 *num
= b
->number
; /* We have its number */
4455 /* See breakpoint.h. */
4458 bpstat_clear_actions (void)
4462 if (inferior_ptid
== null_ptid
)
4465 thread_info
*tp
= inferior_thread ();
4466 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4468 bs
->commands
= NULL
;
4469 bs
->old_val
.reset (nullptr);
4473 /* Called when a command is about to proceed the inferior. */
4476 breakpoint_about_to_proceed (void)
4478 if (inferior_ptid
!= null_ptid
)
4480 struct thread_info
*tp
= inferior_thread ();
4482 /* Allow inferior function calls in breakpoint commands to not
4483 interrupt the command list. When the call finishes
4484 successfully, the inferior will be standing at the same
4485 breakpoint as if nothing happened. */
4486 if (tp
->control
.in_infcall
)
4490 breakpoint_proceeded
= 1;
4493 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4494 or its equivalent. */
4497 command_line_is_silent (struct command_line
*cmd
)
4499 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4502 /* Execute all the commands associated with all the breakpoints at
4503 this location. Any of these commands could cause the process to
4504 proceed beyond this point, etc. We look out for such changes by
4505 checking the global "breakpoint_proceeded" after each command.
4507 Returns true if a breakpoint command resumed the inferior. In that
4508 case, it is the caller's responsibility to recall it again with the
4509 bpstat of the current thread. */
4512 bpstat_do_actions_1 (bpstat
**bsp
)
4517 /* Avoid endless recursion if a `source' command is contained
4519 if (executing_breakpoint_commands
)
4522 scoped_restore save_executing
4523 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4525 scoped_restore preventer
= prevent_dont_repeat ();
4527 /* This pointer will iterate over the list of bpstat's. */
4530 breakpoint_proceeded
= 0;
4531 for (; bs
!= NULL
; bs
= bs
->next
)
4533 struct command_line
*cmd
= NULL
;
4535 /* Take ownership of the BSP's command tree, if it has one.
4537 The command tree could legitimately contain commands like
4538 'step' and 'next', which call clear_proceed_status, which
4539 frees stop_bpstat's command tree. To make sure this doesn't
4540 free the tree we're executing out from under us, we need to
4541 take ownership of the tree ourselves. Since a given bpstat's
4542 commands are only executed once, we don't need to copy it; we
4543 can clear the pointer in the bpstat, and make sure we free
4544 the tree when we're done. */
4545 counted_command_line ccmd
= bs
->commands
;
4546 bs
->commands
= NULL
;
4549 if (command_line_is_silent (cmd
))
4551 /* The action has been already done by bpstat_stop_status. */
4557 execute_control_command (cmd
);
4559 if (breakpoint_proceeded
)
4565 if (breakpoint_proceeded
)
4567 if (current_ui
->async
)
4568 /* If we are in async mode, then the target might be still
4569 running, not stopped at any breakpoint, so nothing for
4570 us to do here -- just return to the event loop. */
4573 /* In sync mode, when execute_control_command returns
4574 we're already standing on the next breakpoint.
4575 Breakpoint commands for that stop were not run, since
4576 execute_command does not run breakpoint commands --
4577 only command_line_handler does, but that one is not
4578 involved in execution of breakpoint commands. So, we
4579 can now execute breakpoint commands. It should be
4580 noted that making execute_command do bpstat actions is
4581 not an option -- in this case we'll have recursive
4582 invocation of bpstat for each breakpoint with a
4583 command, and can easily blow up GDB stack. Instead, we
4584 return true, which will trigger the caller to recall us
4585 with the new stop_bpstat. */
4593 /* Helper for bpstat_do_actions. Get the current thread, if there's
4594 one, is alive and has execution. Return NULL otherwise. */
4596 static thread_info
*
4597 get_bpstat_thread ()
4599 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4602 thread_info
*tp
= inferior_thread ();
4603 if (tp
->state
== THREAD_EXITED
|| tp
->executing ())
4609 bpstat_do_actions (void)
4611 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4614 /* Do any commands attached to breakpoint we are stopped at. */
4615 while ((tp
= get_bpstat_thread ()) != NULL
)
4617 /* Since in sync mode, bpstat_do_actions may resume the
4618 inferior, and only return when it is stopped at the next
4619 breakpoint, we keep doing breakpoint actions until it returns
4620 false to indicate the inferior was not resumed. */
4621 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4625 cleanup_if_error
.release ();
4628 /* Print out the (old or new) value associated with a watchpoint. */
4631 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4634 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4637 struct value_print_options opts
;
4638 get_user_print_options (&opts
);
4639 value_print (val
, stream
, &opts
);
4643 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4644 debugging multiple threads. */
4647 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4649 if (uiout
->is_mi_like_p ())
4654 if (show_thread_that_caused_stop ())
4656 struct thread_info
*thr
= inferior_thread ();
4658 uiout
->text ("Thread ");
4659 uiout
->field_string ("thread-id", print_thread_id (thr
));
4661 const char *name
= thread_name (thr
);
4664 uiout
->text (" \"");
4665 uiout
->field_string ("name", name
);
4669 uiout
->text (" hit ");
4673 /* Generic routine for printing messages indicating why we
4674 stopped. The behavior of this function depends on the value
4675 'print_it' in the bpstat structure. Under some circumstances we
4676 may decide not to print anything here and delegate the task to
4679 static enum print_stop_action
4680 print_bp_stop_message (bpstat
*bs
)
4682 switch (bs
->print_it
)
4685 /* Nothing should be printed for this bpstat entry. */
4686 return PRINT_UNKNOWN
;
4690 /* We still want to print the frame, but we already printed the
4691 relevant messages. */
4692 return PRINT_SRC_AND_LOC
;
4695 case print_it_normal
:
4697 struct breakpoint
*b
= bs
->breakpoint_at
;
4699 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4700 which has since been deleted. */
4702 return PRINT_UNKNOWN
;
4704 /* Normal case. Call the breakpoint's print_it method. */
4705 return b
->print_it (bs
);
4710 internal_error (__FILE__
, __LINE__
,
4711 _("print_bp_stop_message: unrecognized enum value"));
4716 /* See breakpoint.h. */
4719 print_solib_event (bool is_catchpoint
)
4721 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4722 bool any_added
= !current_program_space
->added_solibs
.empty ();
4726 if (any_added
|| any_deleted
)
4727 current_uiout
->text (_("Stopped due to shared library event:\n"));
4729 current_uiout
->text (_("Stopped due to shared library event (no "
4730 "libraries added or removed)\n"));
4733 if (current_uiout
->is_mi_like_p ())
4734 current_uiout
->field_string ("reason",
4735 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4739 current_uiout
->text (_(" Inferior unloaded "));
4740 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4741 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4743 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4746 current_uiout
->text (" ");
4747 current_uiout
->field_string ("library", name
);
4748 current_uiout
->text ("\n");
4754 current_uiout
->text (_(" Inferior loaded "));
4755 ui_out_emit_list
list_emitter (current_uiout
, "added");
4757 for (so_list
*iter
: current_program_space
->added_solibs
)
4760 current_uiout
->text (" ");
4762 current_uiout
->field_string ("library", iter
->so_name
);
4763 current_uiout
->text ("\n");
4768 /* Print a message indicating what happened. This is called from
4769 normal_stop(). The input to this routine is the head of the bpstat
4770 list - a list of the eventpoints that caused this stop. KIND is
4771 the target_waitkind for the stopping event. This
4772 routine calls the generic print routine for printing a message
4773 about reasons for stopping. This will print (for example) the
4774 "Breakpoint n," part of the output. The return value of this
4777 PRINT_UNKNOWN: Means we printed nothing.
4778 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4779 code to print the location. An example is
4780 "Breakpoint 1, " which should be followed by
4782 PRINT_SRC_ONLY: Means we printed something, but there is no need
4783 to also print the location part of the message.
4784 An example is the catch/throw messages, which
4785 don't require a location appended to the end.
4786 PRINT_NOTHING: We have done some printing and we don't need any
4787 further info to be printed. */
4789 enum print_stop_action
4790 bpstat_print (bpstat
*bs
, int kind
)
4792 enum print_stop_action val
;
4794 /* Maybe another breakpoint in the chain caused us to stop.
4795 (Currently all watchpoints go on the bpstat whether hit or not.
4796 That probably could (should) be changed, provided care is taken
4797 with respect to bpstat_explains_signal). */
4798 for (; bs
; bs
= bs
->next
)
4800 val
= print_bp_stop_message (bs
);
4801 if (val
== PRINT_SRC_ONLY
4802 || val
== PRINT_SRC_AND_LOC
4803 || val
== PRINT_NOTHING
)
4807 /* If we had hit a shared library event breakpoint,
4808 print_bp_stop_message would print out this message. If we hit an
4809 OS-level shared library event, do the same thing. */
4810 if (kind
== TARGET_WAITKIND_LOADED
)
4812 print_solib_event (false);
4813 return PRINT_NOTHING
;
4816 /* We reached the end of the chain, or we got a null BS to start
4817 with and nothing was printed. */
4818 return PRINT_UNKNOWN
;
4821 /* Evaluate the boolean expression EXP and return the result. */
4824 breakpoint_cond_eval (expression
*exp
)
4826 struct value
*mark
= value_mark ();
4827 bool res
= value_true (evaluate_expression (exp
));
4829 value_free_to_mark (mark
);
4833 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4835 bpstat::bpstat (struct bp_location
*bl
, bpstat
***bs_link_pointer
)
4837 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4838 breakpoint_at (bl
->owner
),
4842 print_it (print_it_normal
)
4844 **bs_link_pointer
= this;
4845 *bs_link_pointer
= &next
;
4850 breakpoint_at (NULL
),
4854 print_it (print_it_normal
)
4858 /* The target has stopped with waitstatus WS. Check if any hardware
4859 watchpoints have triggered, according to the target. */
4862 watchpoints_triggered (const target_waitstatus
&ws
)
4864 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4867 if (!stopped_by_watchpoint
)
4869 /* We were not stopped by a watchpoint. Mark all watchpoints
4870 as not triggered. */
4871 for (breakpoint
*b
: all_breakpoints ())
4872 if (is_hardware_watchpoint (b
))
4874 struct watchpoint
*w
= (struct watchpoint
*) b
;
4876 w
->watchpoint_triggered
= watch_triggered_no
;
4882 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4884 /* We were stopped by a watchpoint, but we don't know where.
4885 Mark all watchpoints as unknown. */
4886 for (breakpoint
*b
: all_breakpoints ())
4887 if (is_hardware_watchpoint (b
))
4889 struct watchpoint
*w
= (struct watchpoint
*) b
;
4891 w
->watchpoint_triggered
= watch_triggered_unknown
;
4897 /* The target could report the data address. Mark watchpoints
4898 affected by this data address as triggered, and all others as not
4901 for (breakpoint
*b
: all_breakpoints ())
4902 if (is_hardware_watchpoint (b
))
4904 struct watchpoint
*w
= (struct watchpoint
*) b
;
4906 w
->watchpoint_triggered
= watch_triggered_no
;
4907 for (bp_location
*loc
: b
->locations ())
4909 if (is_masked_watchpoint (b
))
4911 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4912 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4914 if (newaddr
== start
)
4916 w
->watchpoint_triggered
= watch_triggered_yes
;
4920 /* Exact match not required. Within range is sufficient. */
4921 else if (target_watchpoint_addr_within_range
4922 (current_inferior ()->top_target (), addr
, loc
->address
,
4925 w
->watchpoint_triggered
= watch_triggered_yes
;
4934 /* Possible return values for watchpoint_check. */
4935 enum wp_check_result
4937 /* The watchpoint has been deleted. */
4940 /* The value has changed. */
4941 WP_VALUE_CHANGED
= 2,
4943 /* The value has not changed. */
4944 WP_VALUE_NOT_CHANGED
= 3,
4946 /* Ignore this watchpoint, no matter if the value changed or not. */
4950 #define BP_TEMPFLAG 1
4951 #define BP_HARDWAREFLAG 2
4953 /* Evaluate watchpoint condition expression and check if its value
4956 static wp_check_result
4957 watchpoint_check (bpstat
*bs
)
4959 struct watchpoint
*b
;
4960 struct frame_info
*fr
;
4961 int within_current_scope
;
4963 /* BS is built from an existing struct breakpoint. */
4964 gdb_assert (bs
->breakpoint_at
!= NULL
);
4965 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4967 /* If this is a local watchpoint, we only want to check if the
4968 watchpoint frame is in scope if the current thread is the thread
4969 that was used to create the watchpoint. */
4970 if (!watchpoint_in_thread_scope (b
))
4973 if (b
->exp_valid_block
== NULL
)
4974 within_current_scope
= 1;
4977 struct frame_info
*frame
= get_current_frame ();
4978 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4979 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4981 /* stack_frame_destroyed_p() returns a non-zero value if we're
4982 still in the function but the stack frame has already been
4983 invalidated. Since we can't rely on the values of local
4984 variables after the stack has been destroyed, we are treating
4985 the watchpoint in that state as `not changed' without further
4986 checking. Don't mark watchpoints as changed if the current
4987 frame is in an epilogue - even if they are in some other
4988 frame, our view of the stack is likely to be wrong and
4989 frame_find_by_id could error out. */
4990 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4993 fr
= frame_find_by_id (b
->watchpoint_frame
);
4994 within_current_scope
= (fr
!= NULL
);
4996 /* If we've gotten confused in the unwinder, we might have
4997 returned a frame that can't describe this variable. */
4998 if (within_current_scope
)
5000 struct symbol
*function
;
5002 function
= get_frame_function (fr
);
5003 if (function
== NULL
5004 || !contained_in (b
->exp_valid_block
, function
->value_block ()))
5005 within_current_scope
= 0;
5008 if (within_current_scope
)
5009 /* If we end up stopping, the current frame will get selected
5010 in normal_stop. So this call to select_frame won't affect
5015 if (within_current_scope
)
5017 /* We use value_{,free_to_}mark because it could be a *long*
5018 time before we return to the command level and call
5019 free_all_values. We can't call free_all_values because we
5020 might be in the middle of evaluating a function call. */
5023 struct value
*new_val
;
5025 if (is_masked_watchpoint (b
))
5026 /* Since we don't know the exact trigger address (from
5027 stopped_data_address), just tell the user we've triggered
5028 a mask watchpoint. */
5029 return WP_VALUE_CHANGED
;
5031 mark
= value_mark ();
5032 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5035 if (b
->val_bitsize
!= 0)
5036 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5038 /* We use value_equal_contents instead of value_equal because
5039 the latter coerces an array to a pointer, thus comparing just
5040 the address of the array instead of its contents. This is
5041 not what we want. */
5042 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5043 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5046 bs
->old_val
= b
->val
;
5047 b
->val
= release_value (new_val
);
5048 b
->val_valid
= true;
5049 if (new_val
!= NULL
)
5050 value_free_to_mark (mark
);
5051 return WP_VALUE_CHANGED
;
5055 /* Nothing changed. */
5056 value_free_to_mark (mark
);
5057 return WP_VALUE_NOT_CHANGED
;
5062 /* This seems like the only logical thing to do because
5063 if we temporarily ignored the watchpoint, then when
5064 we reenter the block in which it is valid it contains
5065 garbage (in the case of a function, it may have two
5066 garbage values, one before and one after the prologue).
5067 So we can't even detect the first assignment to it and
5068 watch after that (since the garbage may or may not equal
5069 the first value assigned). */
5070 /* We print all the stop information in
5071 breakpointprint_it, but in this case, by the time we
5072 call breakpoint->print_it this bp will be deleted
5073 already. So we have no choice but print the information
5076 SWITCH_THRU_ALL_UIS ()
5078 struct ui_out
*uiout
= current_uiout
;
5080 if (uiout
->is_mi_like_p ())
5082 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5083 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5084 "left the block in\n"
5085 "which its expression is valid.\n",
5086 signed_field ("wpnum", b
->number
));
5089 /* Make sure the watchpoint's commands aren't executed. */
5091 watchpoint_del_at_next_stop (b
);
5097 /* Return true if it looks like target has stopped due to hitting
5098 breakpoint location BL. This function does not check if we should
5099 stop, only if BL explains the stop. */
5102 bpstat_check_location (const struct bp_location
*bl
,
5103 const address_space
*aspace
, CORE_ADDR bp_addr
,
5104 const target_waitstatus
&ws
)
5106 struct breakpoint
*b
= bl
->owner
;
5108 /* BL is from an existing breakpoint. */
5109 gdb_assert (b
!= NULL
);
5111 return b
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5114 /* Determine if the watched values have actually changed, and we
5115 should stop. If not, set BS->stop to 0. */
5118 bpstat_check_watchpoint (bpstat
*bs
)
5120 const struct bp_location
*bl
;
5121 struct watchpoint
*b
;
5123 /* BS is built for existing struct breakpoint. */
5124 bl
= bs
->bp_location_at
.get ();
5125 gdb_assert (bl
!= NULL
);
5126 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5127 gdb_assert (b
!= NULL
);
5130 int must_check_value
= 0;
5132 if (b
->type
== bp_watchpoint
)
5133 /* For a software watchpoint, we must always check the
5135 must_check_value
= 1;
5136 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5137 /* We have a hardware watchpoint (read, write, or access)
5138 and the target earlier reported an address watched by
5140 must_check_value
= 1;
5141 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5142 && b
->type
== bp_hardware_watchpoint
)
5143 /* We were stopped by a hardware watchpoint, but the target could
5144 not report the data address. We must check the watchpoint's
5145 value. Access and read watchpoints are out of luck; without
5146 a data address, we can't figure it out. */
5147 must_check_value
= 1;
5149 if (must_check_value
)
5155 e
= watchpoint_check (bs
);
5157 catch (const gdb_exception
&ex
)
5159 exception_fprintf (gdb_stderr
, ex
,
5160 "Error evaluating expression "
5161 "for watchpoint %d\n",
5164 SWITCH_THRU_ALL_UIS ()
5166 gdb_printf (_("Watchpoint %d deleted.\n"),
5169 watchpoint_del_at_next_stop (b
);
5176 /* We've already printed what needs to be printed. */
5177 bs
->print_it
= print_it_done
;
5181 bs
->print_it
= print_it_noop
;
5184 case WP_VALUE_CHANGED
:
5185 if (b
->type
== bp_read_watchpoint
)
5187 /* There are two cases to consider here:
5189 1. We're watching the triggered memory for reads.
5190 In that case, trust the target, and always report
5191 the watchpoint hit to the user. Even though
5192 reads don't cause value changes, the value may
5193 have changed since the last time it was read, and
5194 since we're not trapping writes, we will not see
5195 those, and as such we should ignore our notion of
5198 2. We're watching the triggered memory for both
5199 reads and writes. There are two ways this may
5202 2.1. This is a target that can't break on data
5203 reads only, but can break on accesses (reads or
5204 writes), such as e.g., x86. We detect this case
5205 at the time we try to insert read watchpoints.
5207 2.2. Otherwise, the target supports read
5208 watchpoints, but, the user set an access or write
5209 watchpoint watching the same memory as this read
5212 If we're watching memory writes as well as reads,
5213 ignore watchpoint hits when we find that the
5214 value hasn't changed, as reads don't cause
5215 changes. This still gives false positives when
5216 the program writes the same value to memory as
5217 what there was already in memory (we will confuse
5218 it for a read), but it's much better than
5221 int other_write_watchpoint
= 0;
5223 if (bl
->watchpoint_type
== hw_read
)
5225 for (breakpoint
*other_b
: all_breakpoints ())
5226 if (other_b
->type
== bp_hardware_watchpoint
5227 || other_b
->type
== bp_access_watchpoint
)
5229 struct watchpoint
*other_w
=
5230 (struct watchpoint
*) other_b
;
5232 if (other_w
->watchpoint_triggered
5233 == watch_triggered_yes
)
5235 other_write_watchpoint
= 1;
5241 if (other_write_watchpoint
5242 || bl
->watchpoint_type
== hw_access
)
5244 /* We're watching the same memory for writes,
5245 and the value changed since the last time we
5246 updated it, so this trap must be for a write.
5248 bs
->print_it
= print_it_noop
;
5253 case WP_VALUE_NOT_CHANGED
:
5254 if (b
->type
== bp_hardware_watchpoint
5255 || b
->type
== bp_watchpoint
)
5257 /* Don't stop: write watchpoints shouldn't fire if
5258 the value hasn't changed. */
5259 bs
->print_it
= print_it_noop
;
5269 else /* must_check_value == 0 */
5271 /* This is a case where some watchpoint(s) triggered, but
5272 not at the address of this watchpoint, or else no
5273 watchpoint triggered after all. So don't print
5274 anything for this watchpoint. */
5275 bs
->print_it
= print_it_noop
;
5281 /* For breakpoints that are currently marked as telling gdb to stop,
5282 check conditions (condition proper, frame, thread and ignore count)
5283 of breakpoint referred to by BS. If we should not stop for this
5284 breakpoint, set BS->stop to 0. */
5287 bpstat_check_breakpoint_conditions (bpstat
*bs
, thread_info
*thread
)
5289 const struct bp_location
*bl
;
5290 struct breakpoint
*b
;
5292 bool condition_result
= true;
5293 struct expression
*cond
;
5295 gdb_assert (bs
->stop
);
5297 /* BS is built for existing struct breakpoint. */
5298 bl
= bs
->bp_location_at
.get ();
5299 gdb_assert (bl
!= NULL
);
5300 b
= bs
->breakpoint_at
;
5301 gdb_assert (b
!= NULL
);
5303 /* Even if the target evaluated the condition on its end and notified GDB, we
5304 need to do so again since GDB does not know if we stopped due to a
5305 breakpoint or a single step breakpoint. */
5307 if (frame_id_p (b
->frame_id
)
5308 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5314 /* If this is a thread/task-specific breakpoint, don't waste cpu
5315 evaluating the condition if this isn't the specified
5317 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5318 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5324 /* Evaluate extension language breakpoints that have a "stop" method
5326 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5328 if (is_watchpoint (b
))
5330 struct watchpoint
*w
= (struct watchpoint
*) b
;
5332 cond
= w
->cond_exp
.get ();
5335 cond
= bl
->cond
.get ();
5337 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5339 int within_current_scope
= 1;
5340 struct watchpoint
* w
;
5342 /* We use value_mark and value_free_to_mark because it could
5343 be a long time before we return to the command level and
5344 call free_all_values. We can't call free_all_values
5345 because we might be in the middle of evaluating a
5347 struct value
*mark
= value_mark ();
5349 if (is_watchpoint (b
))
5350 w
= (struct watchpoint
*) b
;
5354 /* Need to select the frame, with all that implies so that
5355 the conditions will have the right context. Because we
5356 use the frame, we will not see an inlined function's
5357 variables when we arrive at a breakpoint at the start
5358 of the inlined function; the current frame will be the
5360 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5361 select_frame (get_current_frame ());
5364 struct frame_info
*frame
;
5366 /* For local watchpoint expressions, which particular
5367 instance of a local is being watched matters, so we
5368 keep track of the frame to evaluate the expression
5369 in. To evaluate the condition however, it doesn't
5370 really matter which instantiation of the function
5371 where the condition makes sense triggers the
5372 watchpoint. This allows an expression like "watch
5373 global if q > 10" set in `func', catch writes to
5374 global on all threads that call `func', or catch
5375 writes on all recursive calls of `func' by a single
5376 thread. We simply always evaluate the condition in
5377 the innermost frame that's executing where it makes
5378 sense to evaluate the condition. It seems
5380 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5382 select_frame (frame
);
5384 within_current_scope
= 0;
5386 if (within_current_scope
)
5390 condition_result
= breakpoint_cond_eval (cond
);
5392 catch (const gdb_exception
&ex
)
5394 exception_fprintf (gdb_stderr
, ex
,
5395 "Error in testing breakpoint condition:\n");
5400 warning (_("Watchpoint condition cannot be tested "
5401 "in the current scope"));
5402 /* If we failed to set the right context for this
5403 watchpoint, unconditionally report it. */
5405 /* FIXME-someday, should give breakpoint #. */
5406 value_free_to_mark (mark
);
5409 if (cond
&& !condition_result
)
5413 else if (b
->ignore_count
> 0)
5417 /* Increase the hit count even though we don't stop. */
5419 gdb::observers::breakpoint_modified
.notify (b
);
5423 /* Returns true if we need to track moribund locations of LOC's type
5424 on the current target. */
5427 need_moribund_for_location_type (struct bp_location
*loc
)
5429 return ((loc
->loc_type
== bp_loc_software_breakpoint
5430 && !target_supports_stopped_by_sw_breakpoint ())
5431 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5432 && !target_supports_stopped_by_hw_breakpoint ()));
5435 /* See breakpoint.h. */
5438 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5439 const target_waitstatus
&ws
)
5441 bpstat
*bs_head
= nullptr, **bs_link
= &bs_head
;
5443 for (breakpoint
*b
: all_breakpoints ())
5445 if (!breakpoint_enabled (b
))
5448 for (bp_location
*bl
: b
->locations ())
5450 /* For hardware watchpoints, we look only at the first
5451 location. The watchpoint_check function will work on the
5452 entire expression, not the individual locations. For
5453 read watchpoints, the watchpoints_triggered function has
5454 checked all locations already. */
5455 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5458 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5461 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5464 /* Come here if it's a watchpoint, or if the break address
5467 bpstat
*bs
= new bpstat (bl
, &bs_link
); /* Alloc a bpstat to
5470 /* Assume we stop. Should we find a watchpoint that is not
5471 actually triggered, or if the condition of the breakpoint
5472 evaluates as false, we'll reset 'stop' to 0. */
5476 /* If this is a scope breakpoint, mark the associated
5477 watchpoint as triggered so that we will handle the
5478 out-of-scope event. We'll get to the watchpoint next
5480 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5482 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5484 w
->watchpoint_triggered
= watch_triggered_yes
;
5489 /* Check if a moribund breakpoint explains the stop. */
5490 if (!target_supports_stopped_by_sw_breakpoint ()
5491 || !target_supports_stopped_by_hw_breakpoint ())
5493 for (bp_location
*loc
: moribund_locations
)
5495 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5496 && need_moribund_for_location_type (loc
))
5498 bpstat
*bs
= new bpstat (loc
, &bs_link
);
5499 /* For hits of moribund locations, we should just proceed. */
5502 bs
->print_it
= print_it_noop
;
5510 /* See breakpoint.h. */
5513 bpstat_stop_status (const address_space
*aspace
,
5514 CORE_ADDR bp_addr
, thread_info
*thread
,
5515 const target_waitstatus
&ws
,
5518 struct breakpoint
*b
= NULL
;
5519 /* First item of allocated bpstat's. */
5520 bpstat
*bs_head
= stop_chain
;
5522 int need_remove_insert
;
5525 /* First, build the bpstat chain with locations that explain a
5526 target stop, while being careful to not set the target running,
5527 as that may invalidate locations (in particular watchpoint
5528 locations are recreated). Resuming will happen here with
5529 breakpoint conditions or watchpoint expressions that include
5530 inferior function calls. */
5531 if (bs_head
== NULL
)
5532 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5534 /* A bit of special processing for shlib breakpoints. We need to
5535 process solib loading here, so that the lists of loaded and
5536 unloaded libraries are correct before we handle "catch load" and
5538 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5540 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5542 handle_solib_event ();
5547 /* Now go through the locations that caused the target to stop, and
5548 check whether we're interested in reporting this stop to higher
5549 layers, or whether we should resume the target transparently. */
5553 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5558 b
= bs
->breakpoint_at
;
5559 b
->check_status (bs
);
5562 bpstat_check_breakpoint_conditions (bs
, thread
);
5568 /* We will stop here. */
5569 if (b
->disposition
== disp_disable
)
5571 --(b
->enable_count
);
5572 if (b
->enable_count
<= 0)
5573 b
->enable_state
= bp_disabled
;
5576 gdb::observers::breakpoint_modified
.notify (b
);
5579 bs
->commands
= b
->commands
;
5580 if (command_line_is_silent (bs
->commands
5581 ? bs
->commands
.get () : NULL
))
5584 b
->after_condition_true (bs
);
5589 /* Print nothing for this entry if we don't stop or don't
5591 if (!bs
->stop
|| !bs
->print
)
5592 bs
->print_it
= print_it_noop
;
5595 /* If we aren't stopping, the value of some hardware watchpoint may
5596 not have changed, but the intermediate memory locations we are
5597 watching may have. Don't bother if we're stopping; this will get
5599 need_remove_insert
= 0;
5600 if (! bpstat_causes_stop (bs_head
))
5601 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5603 && bs
->breakpoint_at
5604 && is_hardware_watchpoint (bs
->breakpoint_at
))
5606 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5608 update_watchpoint (w
, 0 /* don't reparse. */);
5609 need_remove_insert
= 1;
5612 if (need_remove_insert
)
5613 update_global_location_list (UGLL_MAY_INSERT
);
5614 else if (removed_any
)
5615 update_global_location_list (UGLL_DONT_INSERT
);
5620 /* See breakpoint.h. */
5623 bpstat_stop_status_nowatch (const address_space
*aspace
, CORE_ADDR bp_addr
,
5624 thread_info
*thread
, const target_waitstatus
&ws
)
5626 gdb_assert (!target_stopped_by_watchpoint ());
5628 /* Clear all watchpoints' 'watchpoint_triggered' value from a
5629 previous stop to avoid confusing bpstat_stop_status. */
5630 watchpoints_triggered (ws
);
5632 return bpstat_stop_status (aspace
, bp_addr
, thread
, ws
);
5636 handle_jit_event (CORE_ADDR address
)
5638 struct gdbarch
*gdbarch
;
5640 infrun_debug_printf ("handling bp_jit_event");
5642 /* Switch terminal for any messages produced by
5643 breakpoint_re_set. */
5644 target_terminal::ours_for_output ();
5646 gdbarch
= get_frame_arch (get_current_frame ());
5647 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5648 thus it is expected that its objectfile can be found through
5649 minimal symbol lookup. If it doesn't work (and assert fails), it
5650 most likely means that `jit_breakpoint_re_set` was changes and this
5651 function needs to be updated too. */
5652 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5653 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5654 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5656 target_terminal::inferior ();
5659 /* Prepare WHAT final decision for infrun. */
5661 /* Decide what infrun needs to do with this bpstat. */
5664 bpstat_what (bpstat
*bs_head
)
5666 struct bpstat_what retval
;
5669 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5670 retval
.call_dummy
= STOP_NONE
;
5671 retval
.is_longjmp
= false;
5673 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5675 /* Extract this BS's action. After processing each BS, we check
5676 if its action overrides all we've seem so far. */
5677 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5680 if (bs
->breakpoint_at
== NULL
)
5682 /* I suspect this can happen if it was a momentary
5683 breakpoint which has since been deleted. */
5687 bptype
= bs
->breakpoint_at
->type
;
5694 case bp_hardware_breakpoint
:
5695 case bp_single_step
:
5698 case bp_shlib_event
:
5702 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5704 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5707 this_action
= BPSTAT_WHAT_SINGLE
;
5710 case bp_hardware_watchpoint
:
5711 case bp_read_watchpoint
:
5712 case bp_access_watchpoint
:
5716 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5718 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5722 /* There was a watchpoint, but we're not stopping.
5723 This requires no further action. */
5727 case bp_longjmp_call_dummy
:
5731 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5732 retval
.is_longjmp
= bptype
!= bp_exception
;
5735 this_action
= BPSTAT_WHAT_SINGLE
;
5737 case bp_longjmp_resume
:
5738 case bp_exception_resume
:
5741 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5742 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5745 this_action
= BPSTAT_WHAT_SINGLE
;
5747 case bp_step_resume
:
5749 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5752 /* It is for the wrong frame. */
5753 this_action
= BPSTAT_WHAT_SINGLE
;
5756 case bp_hp_step_resume
:
5758 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5761 /* It is for the wrong frame. */
5762 this_action
= BPSTAT_WHAT_SINGLE
;
5765 case bp_watchpoint_scope
:
5766 case bp_thread_event
:
5767 case bp_overlay_event
:
5768 case bp_longjmp_master
:
5769 case bp_std_terminate_master
:
5770 case bp_exception_master
:
5771 this_action
= BPSTAT_WHAT_SINGLE
;
5777 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5779 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5783 /* Some catchpoints are implemented with breakpoints.
5784 For those, we need to step over the breakpoint. */
5785 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5786 this_action
= BPSTAT_WHAT_SINGLE
;
5790 this_action
= BPSTAT_WHAT_SINGLE
;
5793 /* Make sure the action is stop (silent or noisy),
5794 so infrun.c pops the dummy frame. */
5795 retval
.call_dummy
= STOP_STACK_DUMMY
;
5796 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5798 case bp_std_terminate
:
5799 /* Make sure the action is stop (silent or noisy),
5800 so infrun.c pops the dummy frame. */
5801 retval
.call_dummy
= STOP_STD_TERMINATE
;
5802 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5805 case bp_fast_tracepoint
:
5806 case bp_static_tracepoint
:
5807 case bp_static_marker_tracepoint
:
5808 /* Tracepoint hits should not be reported back to GDB, and
5809 if one got through somehow, it should have been filtered
5811 internal_error (__FILE__
, __LINE__
,
5812 _("bpstat_what: tracepoint encountered"));
5814 case bp_gnu_ifunc_resolver
:
5815 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5816 this_action
= BPSTAT_WHAT_SINGLE
;
5818 case bp_gnu_ifunc_resolver_return
:
5819 /* The breakpoint will be removed, execution will restart from the
5820 PC of the former breakpoint. */
5821 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5826 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5828 this_action
= BPSTAT_WHAT_SINGLE
;
5832 internal_error (__FILE__
, __LINE__
,
5833 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5836 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5843 bpstat_run_callbacks (bpstat
*bs_head
)
5847 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5849 struct breakpoint
*b
= bs
->breakpoint_at
;
5856 handle_jit_event (bs
->bp_location_at
->address
);
5858 case bp_gnu_ifunc_resolver
:
5859 gnu_ifunc_resolver_stop (b
);
5861 case bp_gnu_ifunc_resolver_return
:
5862 gnu_ifunc_resolver_return_stop (b
);
5868 /* See breakpoint.h. */
5871 bpstat_should_step ()
5873 for (breakpoint
*b
: all_breakpoints ())
5874 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5880 /* See breakpoint.h. */
5883 bpstat_causes_stop (bpstat
*bs
)
5885 for (; bs
!= NULL
; bs
= bs
->next
)
5894 /* Compute a number of spaces suitable to indent the next line
5895 so it starts at the position corresponding to the table column
5896 named COL_NAME in the currently active table of UIOUT. */
5899 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5901 int i
, total_width
, width
, align
;
5905 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5907 if (strcmp (text
, col_name
) == 0)
5910 total_width
+= width
+ 1;
5916 /* Determine if the locations of this breakpoint will have their conditions
5917 evaluated by the target, host or a mix of both. Returns the following:
5919 "host": Host evals condition.
5920 "host or target": Host or Target evals condition.
5921 "target": Target evals condition.
5925 bp_condition_evaluator (struct breakpoint
*b
)
5927 char host_evals
= 0;
5928 char target_evals
= 0;
5933 if (!is_breakpoint (b
))
5936 if (gdb_evaluates_breakpoint_condition_p ()
5937 || !target_supports_evaluation_of_breakpoint_conditions ())
5938 return condition_evaluation_host
;
5940 for (bp_location
*bl
: b
->locations ())
5942 if (bl
->cond_bytecode
)
5948 if (host_evals
&& target_evals
)
5949 return condition_evaluation_both
;
5950 else if (target_evals
)
5951 return condition_evaluation_target
;
5953 return condition_evaluation_host
;
5956 /* Determine the breakpoint location's condition evaluator. This is
5957 similar to bp_condition_evaluator, but for locations. */
5960 bp_location_condition_evaluator (struct bp_location
*bl
)
5962 if (bl
&& !is_breakpoint (bl
->owner
))
5965 if (gdb_evaluates_breakpoint_condition_p ()
5966 || !target_supports_evaluation_of_breakpoint_conditions ())
5967 return condition_evaluation_host
;
5969 if (bl
&& bl
->cond_bytecode
)
5970 return condition_evaluation_target
;
5972 return condition_evaluation_host
;
5975 /* Print the LOC location out of the list of B->LOC locations. */
5978 print_breakpoint_location (struct breakpoint
*b
,
5979 struct bp_location
*loc
)
5981 struct ui_out
*uiout
= current_uiout
;
5983 scoped_restore_current_program_space restore_pspace
;
5985 if (loc
!= NULL
&& loc
->shlib_disabled
)
5989 set_current_program_space (loc
->pspace
);
5991 if (b
->display_canonical
)
5992 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5993 else if (loc
&& loc
->symtab
)
5995 const struct symbol
*sym
= loc
->symbol
;
5999 uiout
->text ("in ");
6000 uiout
->field_string ("func", sym
->print_name (),
6001 function_name_style
.style ());
6003 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6004 uiout
->text ("at ");
6006 uiout
->field_string ("file",
6007 symtab_to_filename_for_display (loc
->symtab
),
6008 file_name_style
.style ());
6011 if (uiout
->is_mi_like_p ())
6012 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6014 uiout
->field_signed ("line", loc
->line_number
);
6020 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6022 uiout
->field_stream ("at", stb
);
6026 uiout
->field_string ("pending",
6027 event_location_to_string (b
->location
.get ()));
6028 /* If extra_string is available, it could be holding a condition
6029 or dprintf arguments. In either case, make sure it is printed,
6030 too, but only for non-MI streams. */
6031 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6033 if (b
->type
== bp_dprintf
)
6037 uiout
->text (b
->extra_string
.get ());
6041 if (loc
&& is_breakpoint (b
)
6042 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6043 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6046 uiout
->field_string ("evaluated-by",
6047 bp_location_condition_evaluator (loc
));
6053 bptype_string (enum bptype type
)
6055 struct ep_type_description
6058 const char *description
;
6060 static struct ep_type_description bptypes
[] =
6062 {bp_none
, "?deleted?"},
6063 {bp_breakpoint
, "breakpoint"},
6064 {bp_hardware_breakpoint
, "hw breakpoint"},
6065 {bp_single_step
, "sw single-step"},
6066 {bp_until
, "until"},
6067 {bp_finish
, "finish"},
6068 {bp_watchpoint
, "watchpoint"},
6069 {bp_hardware_watchpoint
, "hw watchpoint"},
6070 {bp_read_watchpoint
, "read watchpoint"},
6071 {bp_access_watchpoint
, "acc watchpoint"},
6072 {bp_longjmp
, "longjmp"},
6073 {bp_longjmp_resume
, "longjmp resume"},
6074 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6075 {bp_exception
, "exception"},
6076 {bp_exception_resume
, "exception resume"},
6077 {bp_step_resume
, "step resume"},
6078 {bp_hp_step_resume
, "high-priority step resume"},
6079 {bp_watchpoint_scope
, "watchpoint scope"},
6080 {bp_call_dummy
, "call dummy"},
6081 {bp_std_terminate
, "std::terminate"},
6082 {bp_shlib_event
, "shlib events"},
6083 {bp_thread_event
, "thread events"},
6084 {bp_overlay_event
, "overlay events"},
6085 {bp_longjmp_master
, "longjmp master"},
6086 {bp_std_terminate_master
, "std::terminate master"},
6087 {bp_exception_master
, "exception master"},
6088 {bp_catchpoint
, "catchpoint"},
6089 {bp_tracepoint
, "tracepoint"},
6090 {bp_fast_tracepoint
, "fast tracepoint"},
6091 {bp_static_tracepoint
, "static tracepoint"},
6092 {bp_static_marker_tracepoint
, "static marker tracepoint"},
6093 {bp_dprintf
, "dprintf"},
6094 {bp_jit_event
, "jit events"},
6095 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6096 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6099 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6100 || ((int) type
!= bptypes
[(int) type
].type
))
6101 internal_error (__FILE__
, __LINE__
,
6102 _("bptypes table does not describe type #%d."),
6105 return bptypes
[(int) type
].description
;
6108 /* For MI, output a field named 'thread-groups' with a list as the value.
6109 For CLI, prefix the list with the string 'inf'. */
6112 output_thread_groups (struct ui_out
*uiout
,
6113 const char *field_name
,
6114 const std::vector
<int> &inf_nums
,
6117 int is_mi
= uiout
->is_mi_like_p ();
6119 /* For backward compatibility, don't display inferiors in CLI unless
6120 there are several. Always display them for MI. */
6121 if (!is_mi
&& mi_only
)
6124 ui_out_emit_list
list_emitter (uiout
, field_name
);
6126 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6132 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6133 uiout
->field_string (NULL
, mi_group
);
6138 uiout
->text (" inf ");
6142 uiout
->text (plongest (inf_nums
[i
]));
6147 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6148 instead of going via breakpoint_ops::print_one. This makes "maint
6149 info breakpoints" show the software breakpoint locations of
6150 catchpoints, which are considered internal implementation
6151 detail. Returns true if RAW_LOC is false and if the breakpoint's
6152 print_one method did something; false otherwise. */
6155 print_one_breakpoint_location (struct breakpoint
*b
,
6156 struct bp_location
*loc
,
6158 struct bp_location
**last_loc
,
6159 int allflag
, bool raw_loc
)
6161 struct command_line
*l
;
6162 static char bpenables
[] = "nynny";
6164 struct ui_out
*uiout
= current_uiout
;
6165 int header_of_multiple
= 0;
6166 int part_of_multiple
= (loc
!= NULL
);
6167 struct value_print_options opts
;
6169 get_user_print_options (&opts
);
6171 gdb_assert (!loc
|| loc_number
!= 0);
6172 /* See comment in print_one_breakpoint concerning treatment of
6173 breakpoints with single disabled location. */
6176 && (b
->loc
->next
!= NULL
6177 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6178 header_of_multiple
= 1;
6186 if (part_of_multiple
)
6187 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6189 uiout
->field_signed ("number", b
->number
);
6193 if (part_of_multiple
)
6194 uiout
->field_skip ("type");
6196 uiout
->field_string ("type", bptype_string (b
->type
));
6200 if (part_of_multiple
)
6201 uiout
->field_skip ("disp");
6203 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6207 /* For locations that are disabled because of an invalid condition,
6208 display "N*" on CLI, where "*" refers to a footnote below the
6209 table. For MI, simply display a "N" without a footnote. */
6210 const char *N
= (uiout
->is_mi_like_p ()) ? "N" : "N*";
6211 if (part_of_multiple
)
6212 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? N
6213 : (loc
->enabled
? "y" : "n")));
6215 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6218 bool result
= false;
6219 if (!raw_loc
&& b
->print_one (last_loc
))
6223 if (is_watchpoint (b
))
6225 struct watchpoint
*w
= (struct watchpoint
*) b
;
6227 /* Field 4, the address, is omitted (which makes the columns
6228 not line up too nicely with the headers, but the effect
6229 is relatively readable). */
6230 if (opts
.addressprint
)
6231 uiout
->field_skip ("addr");
6233 uiout
->field_string ("what", w
->exp_string
.get ());
6235 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6236 || is_ada_exception_catchpoint (b
))
6238 if (opts
.addressprint
)
6241 if (header_of_multiple
)
6242 uiout
->field_string ("addr", "<MULTIPLE>",
6243 metadata_style
.style ());
6244 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6245 uiout
->field_string ("addr", "<PENDING>",
6246 metadata_style
.style ());
6248 uiout
->field_core_addr ("addr",
6249 loc
->gdbarch
, loc
->address
);
6252 if (!header_of_multiple
)
6253 print_breakpoint_location (b
, loc
);
6259 if (loc
!= NULL
&& !header_of_multiple
)
6261 std::vector
<int> inf_nums
;
6264 for (inferior
*inf
: all_inferiors ())
6266 if (inf
->pspace
== loc
->pspace
)
6267 inf_nums
.push_back (inf
->num
);
6270 /* For backward compatibility, don't display inferiors in CLI unless
6271 there are several. Always display for MI. */
6273 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6274 && (program_spaces
.size () > 1
6275 || number_of_inferiors () > 1)
6276 /* LOC is for existing B, it cannot be in
6277 moribund_locations and thus having NULL OWNER. */
6278 && loc
->owner
->type
!= bp_catchpoint
))
6280 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6283 if (!part_of_multiple
)
6285 if (b
->thread
!= -1)
6287 /* FIXME: This seems to be redundant and lost here; see the
6288 "stop only in" line a little further down. */
6289 uiout
->text (" thread ");
6290 uiout
->field_signed ("thread", b
->thread
);
6292 else if (b
->task
!= 0)
6294 uiout
->text (" task ");
6295 uiout
->field_signed ("task", b
->task
);
6301 if (!part_of_multiple
)
6302 b
->print_one_detail (uiout
);
6304 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6307 uiout
->text ("\tstop only in stack frame at ");
6308 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6310 uiout
->field_core_addr ("frame",
6311 b
->gdbarch
, b
->frame_id
.stack_addr
);
6315 if (!part_of_multiple
&& b
->cond_string
)
6318 if (is_tracepoint (b
))
6319 uiout
->text ("\ttrace only if ");
6321 uiout
->text ("\tstop only if ");
6322 uiout
->field_string ("cond", b
->cond_string
.get ());
6324 /* Print whether the target is doing the breakpoint's condition
6325 evaluation. If GDB is doing the evaluation, don't print anything. */
6326 if (is_breakpoint (b
)
6327 && breakpoint_condition_evaluation_mode ()
6328 == condition_evaluation_target
)
6330 uiout
->message (" (%pF evals)",
6331 string_field ("evaluated-by",
6332 bp_condition_evaluator (b
)));
6337 if (!part_of_multiple
&& b
->thread
!= -1)
6339 /* FIXME should make an annotation for this. */
6340 uiout
->text ("\tstop only in thread ");
6341 if (uiout
->is_mi_like_p ())
6342 uiout
->field_signed ("thread", b
->thread
);
6345 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6347 uiout
->field_string ("thread", print_thread_id (thr
));
6352 if (!part_of_multiple
)
6356 /* FIXME should make an annotation for this. */
6357 if (is_catchpoint (b
))
6358 uiout
->text ("\tcatchpoint");
6359 else if (is_tracepoint (b
))
6360 uiout
->text ("\ttracepoint");
6362 uiout
->text ("\tbreakpoint");
6363 uiout
->text (" already hit ");
6364 uiout
->field_signed ("times", b
->hit_count
);
6365 if (b
->hit_count
== 1)
6366 uiout
->text (" time\n");
6368 uiout
->text (" times\n");
6372 /* Output the count also if it is zero, but only if this is mi. */
6373 if (uiout
->is_mi_like_p ())
6374 uiout
->field_signed ("times", b
->hit_count
);
6378 if (!part_of_multiple
&& b
->ignore_count
)
6381 uiout
->message ("\tignore next %pF hits\n",
6382 signed_field ("ignore", b
->ignore_count
));
6385 /* Note that an enable count of 1 corresponds to "enable once"
6386 behavior, which is reported by the combination of enablement and
6387 disposition, so we don't need to mention it here. */
6388 if (!part_of_multiple
&& b
->enable_count
> 1)
6391 uiout
->text ("\tdisable after ");
6392 /* Tweak the wording to clarify that ignore and enable counts
6393 are distinct, and have additive effect. */
6394 if (b
->ignore_count
)
6395 uiout
->text ("additional ");
6397 uiout
->text ("next ");
6398 uiout
->field_signed ("enable", b
->enable_count
);
6399 uiout
->text (" hits\n");
6402 if (!part_of_multiple
&& is_tracepoint (b
))
6404 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6406 if (tp
->traceframe_usage
)
6408 uiout
->text ("\ttrace buffer usage ");
6409 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6410 uiout
->text (" bytes\n");
6414 l
= b
->commands
? b
->commands
.get () : NULL
;
6415 if (!part_of_multiple
&& l
)
6418 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6419 print_command_lines (uiout
, l
, 4);
6422 if (is_tracepoint (b
))
6424 struct tracepoint
*t
= (struct tracepoint
*) b
;
6426 if (!part_of_multiple
&& t
->pass_count
)
6428 annotate_field (10);
6429 uiout
->text ("\tpass count ");
6430 uiout
->field_signed ("pass", t
->pass_count
);
6431 uiout
->text (" \n");
6434 /* Don't display it when tracepoint or tracepoint location is
6436 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6438 annotate_field (11);
6440 if (uiout
->is_mi_like_p ())
6441 uiout
->field_string ("installed",
6442 loc
->inserted
? "y" : "n");
6448 uiout
->text ("\tnot ");
6449 uiout
->text ("installed on target\n");
6454 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6456 if (is_watchpoint (b
))
6458 struct watchpoint
*w
= (struct watchpoint
*) b
;
6460 uiout
->field_string ("original-location", w
->exp_string
.get ());
6462 else if (b
->location
!= NULL
6463 && event_location_to_string (b
->location
.get ()) != NULL
)
6464 uiout
->field_string ("original-location",
6465 event_location_to_string (b
->location
.get ()));
6471 /* See breakpoint.h. */
6473 bool fix_multi_location_breakpoint_output_globally
= false;
6476 print_one_breakpoint (struct breakpoint
*b
,
6477 struct bp_location
**last_loc
,
6480 struct ui_out
*uiout
= current_uiout
;
6481 bool use_fixed_output
6482 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6483 || fix_multi_location_breakpoint_output_globally
);
6485 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6486 bool printed
= print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
6489 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6491 if (!use_fixed_output
)
6492 bkpt_tuple_emitter
.reset ();
6494 /* If this breakpoint has custom print function,
6495 it's already printed. Otherwise, print individual
6496 locations, if any. */
6497 if (!printed
|| allflag
)
6499 /* If breakpoint has a single location that is disabled, we
6500 print it as if it had several locations, since otherwise it's
6501 hard to represent "breakpoint enabled, location disabled"
6504 Note that while hardware watchpoints have several locations
6505 internally, that's not a property exposed to users.
6507 Likewise, while catchpoints may be implemented with
6508 breakpoints (e.g., catch throw), that's not a property
6509 exposed to users. We do however display the internal
6510 breakpoint locations with "maint info breakpoints". */
6511 if (!is_hardware_watchpoint (b
)
6512 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6513 || is_ada_exception_catchpoint (b
))
6515 || (b
->loc
&& (b
->loc
->next
6517 || b
->loc
->disabled_by_cond
))))
6519 gdb::optional
<ui_out_emit_list
> locations_list
;
6521 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6522 MI record. For later versions, place breakpoint locations in a
6524 if (uiout
->is_mi_like_p () && use_fixed_output
)
6525 locations_list
.emplace (uiout
, "locations");
6528 for (bp_location
*loc
: b
->locations ())
6530 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6531 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6540 breakpoint_address_bits (struct breakpoint
*b
)
6542 int print_address_bits
= 0;
6544 /* Software watchpoints that aren't watching memory don't have an
6545 address to print. */
6546 if (is_no_memory_software_watchpoint (b
))
6549 for (bp_location
*loc
: b
->locations ())
6553 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6554 if (addr_bit
> print_address_bits
)
6555 print_address_bits
= addr_bit
;
6558 return print_address_bits
;
6561 /* See breakpoint.h. */
6564 print_breakpoint (breakpoint
*b
)
6566 struct bp_location
*dummy_loc
= NULL
;
6567 print_one_breakpoint (b
, &dummy_loc
, 0);
6570 /* Return true if this breakpoint was set by the user, false if it is
6571 internal or momentary. */
6574 user_breakpoint_p (struct breakpoint
*b
)
6576 return b
->number
> 0;
6579 /* See breakpoint.h. */
6582 pending_breakpoint_p (struct breakpoint
*b
)
6584 return b
->loc
== NULL
;
6587 /* Print information on breakpoints (including watchpoints and tracepoints).
6589 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6590 understood by number_or_range_parser. Only breakpoints included in this
6591 list are then printed.
6593 If SHOW_INTERNAL is true, print internal breakpoints.
6595 If FILTER is non-NULL, call it on each breakpoint and only include the
6596 ones for which it returns true.
6598 Return the total number of breakpoints listed. */
6601 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6602 bool (*filter
) (const struct breakpoint
*))
6604 struct bp_location
*last_loc
= NULL
;
6605 int nr_printable_breakpoints
;
6606 struct value_print_options opts
;
6607 int print_address_bits
= 0;
6608 int print_type_col_width
= 14;
6609 struct ui_out
*uiout
= current_uiout
;
6610 bool has_disabled_by_cond_location
= false;
6612 get_user_print_options (&opts
);
6614 /* Compute the number of rows in the table, as well as the size
6615 required for address fields. */
6616 nr_printable_breakpoints
= 0;
6617 for (breakpoint
*b
: all_breakpoints ())
6619 /* If we have a filter, only list the breakpoints it accepts. */
6620 if (filter
&& !filter (b
))
6623 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6624 accept. Skip the others. */
6625 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6627 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6629 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6633 if (show_internal
|| user_breakpoint_p (b
))
6635 int addr_bit
, type_len
;
6637 addr_bit
= breakpoint_address_bits (b
);
6638 if (addr_bit
> print_address_bits
)
6639 print_address_bits
= addr_bit
;
6641 type_len
= strlen (bptype_string (b
->type
));
6642 if (type_len
> print_type_col_width
)
6643 print_type_col_width
= type_len
;
6645 nr_printable_breakpoints
++;
6650 ui_out_emit_table
table_emitter (uiout
,
6651 opts
.addressprint
? 6 : 5,
6652 nr_printable_breakpoints
,
6655 if (nr_printable_breakpoints
> 0)
6656 annotate_breakpoints_headers ();
6657 if (nr_printable_breakpoints
> 0)
6659 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6660 if (nr_printable_breakpoints
> 0)
6662 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6663 if (nr_printable_breakpoints
> 0)
6665 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6666 if (nr_printable_breakpoints
> 0)
6668 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6669 if (opts
.addressprint
)
6671 if (nr_printable_breakpoints
> 0)
6673 if (print_address_bits
<= 32)
6674 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6676 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6678 if (nr_printable_breakpoints
> 0)
6680 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6681 uiout
->table_body ();
6682 if (nr_printable_breakpoints
> 0)
6683 annotate_breakpoints_table ();
6685 for (breakpoint
*b
: all_breakpoints ())
6688 /* If we have a filter, only list the breakpoints it accepts. */
6689 if (filter
&& !filter (b
))
6692 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6693 accept. Skip the others. */
6695 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6697 if (show_internal
) /* maintenance info breakpoint */
6699 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6702 else /* all others */
6704 if (!number_is_in_list (bp_num_list
, b
->number
))
6708 /* We only print out user settable breakpoints unless the
6709 show_internal is set. */
6710 if (show_internal
|| user_breakpoint_p (b
))
6712 print_one_breakpoint (b
, &last_loc
, show_internal
);
6713 for (bp_location
*loc
: b
->locations ())
6714 if (loc
->disabled_by_cond
)
6715 has_disabled_by_cond_location
= true;
6720 if (nr_printable_breakpoints
== 0)
6722 /* If there's a filter, let the caller decide how to report
6726 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6727 uiout
->message ("No breakpoints or watchpoints.\n");
6729 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6735 if (last_loc
&& !server_command
)
6736 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6738 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6739 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6743 /* FIXME? Should this be moved up so that it is only called when
6744 there have been breakpoints? */
6745 annotate_breakpoints_table_end ();
6747 return nr_printable_breakpoints
;
6750 /* Display the value of default-collect in a way that is generally
6751 compatible with the breakpoint list. */
6754 default_collect_info (void)
6756 struct ui_out
*uiout
= current_uiout
;
6758 /* If it has no value (which is frequently the case), say nothing; a
6759 message like "No default-collect." gets in user's face when it's
6761 if (default_collect
.empty ())
6764 /* The following phrase lines up nicely with per-tracepoint collect
6766 uiout
->text ("default collect ");
6767 uiout
->field_string ("default-collect", default_collect
);
6768 uiout
->text (" \n");
6772 info_breakpoints_command (const char *args
, int from_tty
)
6774 breakpoint_1 (args
, false, NULL
);
6776 default_collect_info ();
6780 info_watchpoints_command (const char *args
, int from_tty
)
6782 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6783 struct ui_out
*uiout
= current_uiout
;
6785 if (num_printed
== 0)
6787 if (args
== NULL
|| *args
== '\0')
6788 uiout
->message ("No watchpoints.\n");
6790 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6795 maintenance_info_breakpoints (const char *args
, int from_tty
)
6797 breakpoint_1 (args
, true, NULL
);
6799 default_collect_info ();
6803 breakpoint_has_pc (struct breakpoint
*b
,
6804 struct program_space
*pspace
,
6805 CORE_ADDR pc
, struct obj_section
*section
)
6807 for (bp_location
*bl
: b
->locations ())
6809 if (bl
->pspace
== pspace
6810 && bl
->address
== pc
6811 && (!overlay_debugging
|| bl
->section
== section
))
6817 /* Print a message describing any user-breakpoints set at PC. This
6818 concerns with logical breakpoints, so we match program spaces, not
6822 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6823 struct program_space
*pspace
, CORE_ADDR pc
,
6824 struct obj_section
*section
, int thread
)
6828 for (breakpoint
*b
: all_breakpoints ())
6829 others
+= (user_breakpoint_p (b
)
6830 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6835 gdb_printf (_("Note: breakpoint "));
6836 else /* if (others == ???) */
6837 gdb_printf (_("Note: breakpoints "));
6838 for (breakpoint
*b
: all_breakpoints ())
6839 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6842 gdb_printf ("%d", b
->number
);
6843 if (b
->thread
== -1 && thread
!= -1)
6844 gdb_printf (" (all threads)");
6845 else if (b
->thread
!= -1)
6846 gdb_printf (" (thread %d)", b
->thread
);
6847 gdb_printf ("%s%s ",
6848 ((b
->enable_state
== bp_disabled
6849 || b
->enable_state
== bp_call_disabled
)
6853 : ((others
== 1) ? " and" : ""));
6855 current_uiout
->message (_("also set at pc %ps.\n"),
6856 styled_string (address_style
.style (),
6857 paddress (gdbarch
, pc
)));
6862 /* Return true iff it is meaningful to use the address member of LOC.
6863 For some breakpoint types, the locations' address members are
6864 irrelevant and it makes no sense to attempt to compare them to
6865 other addresses (or use them for any other purpose either).
6867 More specifically, software watchpoints and catchpoints that are
6868 not backed by breakpoints always have a zero valued location
6869 address and we don't want to mark breakpoints of any of these types
6870 to be a duplicate of an actual breakpoint location at address
6874 bl_address_is_meaningful (bp_location
*loc
)
6876 return loc
->loc_type
!= bp_loc_other
;
6879 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6880 true if LOC1 and LOC2 represent the same watchpoint location. */
6883 watchpoint_locations_match (struct bp_location
*loc1
,
6884 struct bp_location
*loc2
)
6886 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6887 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6889 /* Both of them must exist. */
6890 gdb_assert (w1
!= NULL
);
6891 gdb_assert (w2
!= NULL
);
6893 /* If the target can evaluate the condition expression in hardware,
6894 then we we need to insert both watchpoints even if they are at
6895 the same place. Otherwise the watchpoint will only trigger when
6896 the condition of whichever watchpoint was inserted evaluates to
6897 true, not giving a chance for GDB to check the condition of the
6898 other watchpoint. */
6900 && target_can_accel_watchpoint_condition (loc1
->address
,
6902 loc1
->watchpoint_type
,
6903 w1
->cond_exp
.get ()))
6905 && target_can_accel_watchpoint_condition (loc2
->address
,
6907 loc2
->watchpoint_type
,
6908 w2
->cond_exp
.get ())))
6911 /* Note that this checks the owner's type, not the location's. In
6912 case the target does not support read watchpoints, but does
6913 support access watchpoints, we'll have bp_read_watchpoint
6914 watchpoints with hw_access locations. Those should be considered
6915 duplicates of hw_read locations. The hw_read locations will
6916 become hw_access locations later. */
6917 return (loc1
->owner
->type
== loc2
->owner
->type
6918 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6919 && loc1
->address
== loc2
->address
6920 && loc1
->length
== loc2
->length
);
6923 /* See breakpoint.h. */
6926 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6927 const address_space
*aspace2
, CORE_ADDR addr2
)
6929 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6930 || aspace1
== aspace2
)
6934 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6935 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6936 matches ASPACE2. On targets that have global breakpoints, the address
6937 space doesn't really matter. */
6940 breakpoint_address_match_range (const address_space
*aspace1
,
6942 int len1
, const address_space
*aspace2
,
6945 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6946 || aspace1
== aspace2
)
6947 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6950 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6951 a ranged breakpoint. In most targets, a match happens only if ASPACE
6952 matches the breakpoint's address space. On targets that have global
6953 breakpoints, the address space doesn't really matter. */
6956 breakpoint_location_address_match (struct bp_location
*bl
,
6957 const address_space
*aspace
,
6960 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6963 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6964 bl
->address
, bl
->length
,
6968 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6969 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6970 match happens only if ASPACE matches the breakpoint's address
6971 space. On targets that have global breakpoints, the address space
6972 doesn't really matter. */
6975 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6976 const address_space
*aspace
,
6977 CORE_ADDR addr
, int len
)
6979 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6980 || bl
->pspace
->aspace
== aspace
)
6982 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6984 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6990 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6991 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6992 true, otherwise returns false. */
6995 tracepoint_locations_match (struct bp_location
*loc1
,
6996 struct bp_location
*loc2
)
6998 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6999 /* Since tracepoint locations are never duplicated with others', tracepoint
7000 locations at the same address of different tracepoints are regarded as
7001 different locations. */
7002 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7007 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7008 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
7009 the same location. If SW_HW_BPS_MATCH is true, then software
7010 breakpoint locations and hardware breakpoint locations match,
7011 otherwise they don't. */
7014 breakpoint_locations_match (struct bp_location
*loc1
,
7015 struct bp_location
*loc2
,
7016 bool sw_hw_bps_match
)
7018 int hw_point1
, hw_point2
;
7020 /* Both of them must not be in moribund_locations. */
7021 gdb_assert (loc1
->owner
!= NULL
);
7022 gdb_assert (loc2
->owner
!= NULL
);
7024 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7025 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7027 if (hw_point1
!= hw_point2
)
7030 return watchpoint_locations_match (loc1
, loc2
);
7031 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7032 return tracepoint_locations_match (loc1
, loc2
);
7034 /* We compare bp_location.length in order to cover ranged
7035 breakpoints. Keep this in sync with
7036 bp_location_is_less_than. */
7037 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7038 loc2
->pspace
->aspace
, loc2
->address
)
7039 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7040 && loc1
->length
== loc2
->length
);
7044 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7045 int bnum
, int have_bnum
)
7047 /* The longest string possibly returned by hex_string_custom
7048 is 50 chars. These must be at least that big for safety. */
7052 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7053 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7055 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7056 bnum
, astr1
, astr2
);
7058 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7061 /* Adjust a breakpoint's address to account for architectural
7062 constraints on breakpoint placement. Return the adjusted address.
7063 Note: Very few targets require this kind of adjustment. For most
7064 targets, this function is simply the identity function. */
7067 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7068 CORE_ADDR bpaddr
, enum bptype bptype
)
7070 if (bptype
== bp_watchpoint
7071 || bptype
== bp_hardware_watchpoint
7072 || bptype
== bp_read_watchpoint
7073 || bptype
== bp_access_watchpoint
7074 || bptype
== bp_catchpoint
)
7076 /* Watchpoints and the various bp_catch_* eventpoints should not
7077 have their addresses modified. */
7080 else if (bptype
== bp_single_step
)
7082 /* Single-step breakpoints should not have their addresses
7083 modified. If there's any architectural constrain that
7084 applies to this address, then it should have already been
7085 taken into account when the breakpoint was created in the
7086 first place. If we didn't do this, stepping through e.g.,
7087 Thumb-2 IT blocks would break. */
7092 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7094 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7096 /* Some targets have architectural constraints on the placement
7097 of breakpoint instructions. Obtain the adjusted address. */
7098 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7101 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7103 /* An adjusted breakpoint address can significantly alter
7104 a user's expectations. Print a warning if an adjustment
7106 if (adjusted_bpaddr
!= bpaddr
)
7107 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7109 return adjusted_bpaddr
;
7114 bp_location_from_bp_type (bptype type
)
7119 case bp_single_step
:
7123 case bp_longjmp_resume
:
7124 case bp_longjmp_call_dummy
:
7126 case bp_exception_resume
:
7127 case bp_step_resume
:
7128 case bp_hp_step_resume
:
7129 case bp_watchpoint_scope
:
7131 case bp_std_terminate
:
7132 case bp_shlib_event
:
7133 case bp_thread_event
:
7134 case bp_overlay_event
:
7136 case bp_longjmp_master
:
7137 case bp_std_terminate_master
:
7138 case bp_exception_master
:
7139 case bp_gnu_ifunc_resolver
:
7140 case bp_gnu_ifunc_resolver_return
:
7142 return bp_loc_software_breakpoint
;
7143 case bp_hardware_breakpoint
:
7144 return bp_loc_hardware_breakpoint
;
7145 case bp_hardware_watchpoint
:
7146 case bp_read_watchpoint
:
7147 case bp_access_watchpoint
:
7148 return bp_loc_hardware_watchpoint
;
7152 case bp_fast_tracepoint
:
7153 case bp_static_tracepoint
:
7154 case bp_static_marker_tracepoint
:
7155 return bp_loc_other
;
7157 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7161 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7163 this->owner
= owner
;
7164 this->cond_bytecode
= NULL
;
7165 this->shlib_disabled
= 0;
7167 this->disabled_by_cond
= false;
7169 this->loc_type
= type
;
7171 if (this->loc_type
== bp_loc_software_breakpoint
7172 || this->loc_type
== bp_loc_hardware_breakpoint
)
7173 mark_breakpoint_location_modified (this);
7178 bp_location::bp_location (breakpoint
*owner
)
7179 : bp_location::bp_location (owner
,
7180 bp_location_from_bp_type (owner
->type
))
7184 /* Decrement reference count. If the reference count reaches 0,
7185 destroy the bp_location. Sets *BLP to NULL. */
7188 decref_bp_location (struct bp_location
**blp
)
7190 bp_location_ref_policy::decref (*blp
);
7194 /* Add breakpoint B at the end of the global breakpoint chain. */
7197 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7199 struct breakpoint
*b1
;
7200 struct breakpoint
*result
= b
.get ();
7202 /* Add this breakpoint to the end of the chain so that a list of
7203 breakpoints will come out in order of increasing numbers. */
7205 b1
= breakpoint_chain
;
7207 breakpoint_chain
= b
.release ();
7212 b1
->next
= b
.release ();
7218 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7221 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7222 struct gdbarch
*gdbarch
,
7226 b
->gdbarch
= gdbarch
;
7227 b
->language
= current_language
->la_language
;
7228 b
->input_radix
= input_radix
;
7229 b
->related_breakpoint
= b
;
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 (bptype
);
7241 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
);
7242 return add_to_breakpoint_chain (std::move (b
));
7245 /* Initialize loc->function_name. */
7248 set_breakpoint_location_function (struct bp_location
*loc
)
7250 gdb_assert (loc
->owner
!= NULL
);
7252 if (loc
->owner
->type
== bp_breakpoint
7253 || loc
->owner
->type
== bp_hardware_breakpoint
7254 || is_tracepoint (loc
->owner
))
7256 const char *function_name
;
7258 if (loc
->msymbol
!= NULL
7259 && (loc
->msymbol
->type () == mst_text_gnu_ifunc
7260 || loc
->msymbol
->type () == mst_data_gnu_ifunc
))
7262 struct breakpoint
*b
= loc
->owner
;
7264 function_name
= loc
->msymbol
->linkage_name ();
7266 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7267 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7269 /* Create only the whole new breakpoint of this type but do not
7270 mess more complicated breakpoints with multiple locations. */
7271 b
->type
= bp_gnu_ifunc_resolver
;
7272 /* Remember the resolver's address for use by the return
7274 loc
->related_address
= loc
->address
;
7278 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7281 loc
->function_name
= make_unique_xstrdup (function_name
);
7285 /* Attempt to determine architecture of location identified by SAL. */
7287 get_sal_arch (struct symtab_and_line sal
)
7290 return sal
.section
->objfile
->arch ();
7292 return sal
.symtab
->compunit ()->objfile ()->arch ();
7297 /* Low level routine for partially initializing a breakpoint of type
7298 BPTYPE. The newly created breakpoint's address, section, source
7299 file name, and line number are provided by SAL.
7301 It is expected that the caller will complete the initialization of
7302 the newly created breakpoint struct as well as output any status
7303 information regarding the creation of a new breakpoint. */
7306 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7307 struct symtab_and_line sal
, enum bptype bptype
)
7309 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
);
7311 add_location_to_breakpoint (b
, &sal
);
7313 if (bptype
!= bp_catchpoint
)
7314 gdb_assert (sal
.pspace
!= NULL
);
7316 /* Store the program space that was used to set the breakpoint,
7317 except for ordinary breakpoints, which are independent of the
7319 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7320 b
->pspace
= sal
.pspace
;
7323 /* set_raw_breakpoint is a low level routine for allocating and
7324 partially initializing a breakpoint of type BPTYPE. The newly
7325 created breakpoint's address, section, source file name, and line
7326 number are provided by SAL. The newly created and partially
7327 initialized breakpoint is added to the breakpoint chain and
7328 is also returned as the value of this function.
7330 It is expected that the caller will complete the initialization of
7331 the newly created breakpoint struct as well as output any status
7332 information regarding the creation of a new breakpoint. In
7333 particular, set_raw_breakpoint does NOT set the breakpoint
7334 number! Care should be taken to not allow an error to occur
7335 prior to completing the initialization of the breakpoint. If this
7336 should happen, a bogus breakpoint will be left on the chain. */
7338 static struct breakpoint
*
7339 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7340 struct symtab_and_line sal
, enum bptype bptype
)
7342 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7344 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
);
7345 return add_to_breakpoint_chain (std::move (b
));
7348 /* Call this routine when stepping and nexting to enable a breakpoint
7349 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7350 initiated the operation. */
7353 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7355 int thread
= tp
->global_num
;
7357 /* To avoid having to rescan all objfile symbols at every step,
7358 we maintain a list of continually-inserted but always disabled
7359 longjmp "master" breakpoints. Here, we simply create momentary
7360 clones of those and enable them for the requested thread. */
7361 for (breakpoint
*b
: all_breakpoints_safe ())
7362 if (b
->pspace
== current_program_space
7363 && (b
->type
== bp_longjmp_master
7364 || b
->type
== bp_exception_master
))
7366 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7367 struct breakpoint
*clone
;
7369 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7370 after their removal. */
7371 clone
= momentary_breakpoint_from_master (b
, type
, 1);
7372 clone
->thread
= thread
;
7375 tp
->initiating_frame
= frame
;
7378 /* Delete all longjmp breakpoints from THREAD. */
7380 delete_longjmp_breakpoint (int thread
)
7382 for (breakpoint
*b
: all_breakpoints_safe ())
7383 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7385 if (b
->thread
== thread
)
7386 delete_breakpoint (b
);
7391 delete_longjmp_breakpoint_at_next_stop (int thread
)
7393 for (breakpoint
*b
: all_breakpoints_safe ())
7394 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7396 if (b
->thread
== thread
)
7397 b
->disposition
= disp_del_at_next_stop
;
7401 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7402 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7403 pointer to any of them. Return NULL if this system cannot place longjmp
7407 set_longjmp_breakpoint_for_call_dummy (void)
7409 breakpoint
*retval
= nullptr;
7411 for (breakpoint
*b
: all_breakpoints ())
7412 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7414 struct breakpoint
*new_b
;
7416 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7418 new_b
->thread
= inferior_thread ()->global_num
;
7420 /* Link NEW_B into the chain of RETVAL breakpoints. */
7422 gdb_assert (new_b
->related_breakpoint
== new_b
);
7425 new_b
->related_breakpoint
= retval
;
7426 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7427 retval
= retval
->related_breakpoint
;
7428 retval
->related_breakpoint
= new_b
;
7434 /* Verify all existing dummy frames and their associated breakpoints for
7435 TP. Remove those which can no longer be found in the current frame
7438 If the unwind fails then there is not sufficient information to discard
7439 dummy frames. In this case, elide the clean up and the dummy frames will
7440 be cleaned up next time this function is called from a location where
7441 unwinding is possible. */
7444 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7446 struct breakpoint
*b
, *b_tmp
;
7448 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7449 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7451 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7453 /* Find the bp_call_dummy breakpoint in the list of breakpoints
7454 chained off b->related_breakpoint. */
7455 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7456 dummy_b
= dummy_b
->related_breakpoint
;
7458 /* If there was no bp_call_dummy breakpoint then there's nothing
7459 more to do. Or, if the dummy frame associated with the
7460 bp_call_dummy is still on the stack then we need to leave this
7461 bp_call_dummy in place. */
7462 if (dummy_b
->type
!= bp_call_dummy
7463 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7466 /* We didn't find the dummy frame on the stack, this could be
7467 because we have longjmp'd to a stack frame that is previous to
7468 the dummy frame, or it could be because the stack unwind is
7469 broken at some point between the longjmp frame and the dummy
7472 Next we figure out why the stack unwind stopped. If it looks
7473 like the unwind is complete then we assume the dummy frame has
7474 been jumped over, however, if the unwind stopped for an
7475 unexpected reason then we assume the stack unwind is currently
7476 broken, and that we will (eventually) return to the dummy
7479 It might be tempting to consider using frame_id_inner here, but
7480 that is not safe. There is no guarantee that the stack frames
7481 we are looking at here are even on the same stack as the
7482 original dummy frame, hence frame_id_inner can't be used. See
7483 the comments on frame_id_inner for more details. */
7484 bool unwind_finished_unexpectedly
= false;
7485 for (struct frame_info
*fi
= get_current_frame (); fi
!= nullptr; )
7487 struct frame_info
*prev
= get_prev_frame (fi
);
7488 if (prev
== nullptr)
7490 /* FI is the last stack frame. Why did this frame not
7492 auto stop_reason
= get_frame_unwind_stop_reason (fi
);
7493 if (stop_reason
!= UNWIND_NO_REASON
7494 && stop_reason
!= UNWIND_OUTERMOST
)
7495 unwind_finished_unexpectedly
= true;
7499 if (unwind_finished_unexpectedly
)
7502 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7504 while (b
->related_breakpoint
!= b
)
7506 if (b_tmp
== b
->related_breakpoint
)
7507 b_tmp
= b
->related_breakpoint
->next
;
7508 delete_breakpoint (b
->related_breakpoint
);
7510 delete_breakpoint (b
);
7515 enable_overlay_breakpoints (void)
7517 for (breakpoint
*b
: all_breakpoints ())
7518 if (b
->type
== bp_overlay_event
)
7520 b
->enable_state
= bp_enabled
;
7521 update_global_location_list (UGLL_MAY_INSERT
);
7522 overlay_events_enabled
= 1;
7527 disable_overlay_breakpoints (void)
7529 for (breakpoint
*b
: all_breakpoints ())
7530 if (b
->type
== bp_overlay_event
)
7532 b
->enable_state
= bp_disabled
;
7533 update_global_location_list (UGLL_DONT_INSERT
);
7534 overlay_events_enabled
= 0;
7538 /* Set an active std::terminate breakpoint for each std::terminate
7539 master breakpoint. */
7541 set_std_terminate_breakpoint (void)
7543 for (breakpoint
*b
: all_breakpoints_safe ())
7544 if (b
->pspace
== current_program_space
7545 && b
->type
== bp_std_terminate_master
)
7547 momentary_breakpoint_from_master (b
, bp_std_terminate
, 1);
7551 /* Delete all the std::terminate breakpoints. */
7553 delete_std_terminate_breakpoint (void)
7555 for (breakpoint
*b
: all_breakpoints_safe ())
7556 if (b
->type
== bp_std_terminate
)
7557 delete_breakpoint (b
);
7561 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7563 struct breakpoint
*b
;
7565 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
7567 b
->enable_state
= bp_enabled
;
7568 /* location has to be used or breakpoint_re_set will delete me. */
7569 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7571 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7576 struct lang_and_radix
7582 /* Create a breakpoint for JIT code registration and unregistration. */
7585 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7587 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
7590 /* Remove JIT code registration and unregistration breakpoint(s). */
7593 remove_jit_event_breakpoints (void)
7595 for (breakpoint
*b
: all_breakpoints_safe ())
7596 if (b
->type
== bp_jit_event
7597 && b
->loc
->pspace
== current_program_space
)
7598 delete_breakpoint (b
);
7602 remove_solib_event_breakpoints (void)
7604 for (breakpoint
*b
: all_breakpoints_safe ())
7605 if (b
->type
== bp_shlib_event
7606 && b
->loc
->pspace
== current_program_space
)
7607 delete_breakpoint (b
);
7610 /* See breakpoint.h. */
7613 remove_solib_event_breakpoints_at_next_stop (void)
7615 for (breakpoint
*b
: all_breakpoints_safe ())
7616 if (b
->type
== bp_shlib_event
7617 && b
->loc
->pspace
== current_program_space
)
7618 b
->disposition
= disp_del_at_next_stop
;
7621 /* Helper for create_solib_event_breakpoint /
7622 create_and_insert_solib_event_breakpoint. Allows specifying which
7623 INSERT_MODE to pass through to update_global_location_list. */
7625 static struct breakpoint
*
7626 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7627 enum ugll_insert_mode insert_mode
)
7629 struct breakpoint
*b
;
7631 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
7632 update_global_location_list_nothrow (insert_mode
);
7637 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7639 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7642 /* See breakpoint.h. */
7645 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7647 struct breakpoint
*b
;
7649 /* Explicitly tell update_global_location_list to insert
7651 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7652 if (!b
->loc
->inserted
)
7654 delete_breakpoint (b
);
7660 /* Disable any breakpoints that are on code in shared libraries. Only
7661 apply to enabled breakpoints, disabled ones can just stay disabled. */
7664 disable_breakpoints_in_shlibs (void)
7666 for (bp_location
*loc
: all_bp_locations ())
7668 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7669 struct breakpoint
*b
= loc
->owner
;
7671 /* We apply the check to all breakpoints, including disabled for
7672 those with loc->duplicate set. This is so that when breakpoint
7673 becomes enabled, or the duplicate is removed, gdb will try to
7674 insert all breakpoints. If we don't set shlib_disabled here,
7675 we'll try to insert those breakpoints and fail. */
7676 if (((b
->type
== bp_breakpoint
)
7677 || (b
->type
== bp_jit_event
)
7678 || (b
->type
== bp_hardware_breakpoint
)
7679 || (is_tracepoint (b
)))
7680 && loc
->pspace
== current_program_space
7681 && !loc
->shlib_disabled
7682 && solib_name_from_address (loc
->pspace
, loc
->address
)
7685 loc
->shlib_disabled
= 1;
7690 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7691 notification of unloaded_shlib. Only apply to enabled breakpoints,
7692 disabled ones can just stay disabled. */
7695 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7697 int disabled_shlib_breaks
= 0;
7699 for (bp_location
*loc
: all_bp_locations ())
7701 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7702 struct breakpoint
*b
= loc
->owner
;
7704 if (solib
->pspace
== loc
->pspace
7705 && !loc
->shlib_disabled
7706 && (((b
->type
== bp_breakpoint
7707 || b
->type
== bp_jit_event
7708 || b
->type
== bp_hardware_breakpoint
)
7709 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7710 || loc
->loc_type
== bp_loc_software_breakpoint
))
7711 || is_tracepoint (b
))
7712 && solib_contains_address_p (solib
, loc
->address
))
7714 loc
->shlib_disabled
= 1;
7715 /* At this point, we cannot rely on remove_breakpoint
7716 succeeding so we must mark the breakpoint as not inserted
7717 to prevent future errors occurring in remove_breakpoints. */
7720 /* This may cause duplicate notifications for the same breakpoint. */
7721 gdb::observers::breakpoint_modified
.notify (b
);
7723 if (!disabled_shlib_breaks
)
7725 target_terminal::ours_for_output ();
7726 warning (_("Temporarily disabling breakpoints "
7727 "for unloaded shared library \"%s\""),
7730 disabled_shlib_breaks
= 1;
7735 /* Disable any breakpoints and tracepoints in OBJFILE upon
7736 notification of free_objfile. Only apply to enabled breakpoints,
7737 disabled ones can just stay disabled. */
7740 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7742 if (objfile
== NULL
)
7745 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7746 managed by the user with add-symbol-file/remove-symbol-file.
7747 Similarly to how breakpoints in shared libraries are handled in
7748 response to "nosharedlibrary", mark breakpoints in such modules
7749 shlib_disabled so they end up uninserted on the next global
7750 location list update. Shared libraries not loaded by the user
7751 aren't handled here -- they're already handled in
7752 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7753 solib_unloaded observer. We skip objfiles that are not
7754 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7756 if ((objfile
->flags
& OBJF_SHARED
) == 0
7757 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7760 for (breakpoint
*b
: all_breakpoints ())
7762 int bp_modified
= 0;
7764 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7767 for (bp_location
*loc
: b
->locations ())
7769 CORE_ADDR loc_addr
= loc
->address
;
7771 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7772 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7775 if (loc
->shlib_disabled
!= 0)
7778 if (objfile
->pspace
!= loc
->pspace
)
7781 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7782 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7785 if (is_addr_in_objfile (loc_addr
, objfile
))
7787 loc
->shlib_disabled
= 1;
7788 /* At this point, we don't know whether the object was
7789 unmapped from the inferior or not, so leave the
7790 inserted flag alone. We'll handle failure to
7791 uninsert quietly, in case the object was indeed
7794 mark_breakpoint_location_modified (loc
);
7801 gdb::observers::breakpoint_modified
.notify (b
);
7805 /* See breakpoint.h. */
7808 init_catchpoint (struct breakpoint
*b
,
7809 struct gdbarch
*gdbarch
, bool temp
,
7810 const char *cond_string
)
7812 symtab_and_line sal
;
7813 sal
.pspace
= current_program_space
;
7815 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
);
7817 if (cond_string
== nullptr)
7818 b
->cond_string
.reset ();
7820 b
->cond_string
= make_unique_xstrdup (cond_string
);
7821 b
->disposition
= temp
? disp_del
: disp_donttouch
;
7825 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
7827 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
7828 set_breakpoint_number (internal
, b
);
7829 if (is_tracepoint (b
))
7830 set_tracepoint_count (breakpoint_count
);
7833 gdb::observers::breakpoint_created
.notify (b
);
7836 update_global_location_list (UGLL_MAY_INSERT
);
7840 hw_breakpoint_used_count (void)
7844 for (breakpoint
*b
: all_breakpoints ())
7845 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
7846 for (bp_location
*bl
: b
->locations ())
7848 /* Special types of hardware breakpoints may use more than
7850 i
+= b
->resources_needed (bl
);
7856 /* Returns the resources B would use if it were a hardware
7860 hw_watchpoint_use_count (struct breakpoint
*b
)
7864 if (!breakpoint_enabled (b
))
7867 for (bp_location
*bl
: b
->locations ())
7869 /* Special types of hardware watchpoints may use more than
7871 i
+= b
->resources_needed (bl
);
7877 /* Returns the sum the used resources of all hardware watchpoints of
7878 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
7879 the sum of the used resources of all hardware watchpoints of other
7880 types _not_ TYPE. */
7883 hw_watchpoint_used_count_others (struct breakpoint
*except
,
7884 enum bptype type
, int *other_type_used
)
7888 *other_type_used
= 0;
7889 for (breakpoint
*b
: all_breakpoints ())
7893 if (!breakpoint_enabled (b
))
7896 if (b
->type
== type
)
7897 i
+= hw_watchpoint_use_count (b
);
7898 else if (is_hardware_watchpoint (b
))
7899 *other_type_used
= 1;
7906 disable_watchpoints_before_interactive_call_start (void)
7908 for (breakpoint
*b
: all_breakpoints ())
7909 if (is_watchpoint (b
) && breakpoint_enabled (b
))
7911 b
->enable_state
= bp_call_disabled
;
7912 update_global_location_list (UGLL_DONT_INSERT
);
7917 enable_watchpoints_after_interactive_call_stop (void)
7919 for (breakpoint
*b
: all_breakpoints ())
7920 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
7922 b
->enable_state
= bp_enabled
;
7923 update_global_location_list (UGLL_MAY_INSERT
);
7928 disable_breakpoints_before_startup (void)
7930 current_program_space
->executing_startup
= 1;
7931 update_global_location_list (UGLL_DONT_INSERT
);
7935 enable_breakpoints_after_startup (void)
7937 current_program_space
->executing_startup
= 0;
7938 breakpoint_re_set ();
7941 /* Create a new single-step breakpoint for thread THREAD, with no
7944 static struct breakpoint
*
7945 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
7947 std::unique_ptr
<breakpoint
> b (new momentary_breakpoint ());
7949 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
);
7951 b
->disposition
= disp_donttouch
;
7952 b
->frame_id
= null_frame_id
;
7955 gdb_assert (b
->thread
!= 0);
7957 return add_to_breakpoint_chain (std::move (b
));
7960 /* Set a momentary breakpoint of type TYPE at address specified by
7961 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
7965 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
7966 struct frame_id frame_id
, enum bptype type
)
7968 struct breakpoint
*b
;
7970 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
7972 gdb_assert (!frame_id_artificial_p (frame_id
));
7974 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
7975 b
->enable_state
= bp_enabled
;
7976 b
->disposition
= disp_donttouch
;
7977 b
->frame_id
= frame_id
;
7979 b
->thread
= inferior_thread ()->global_num
;
7981 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7983 return breakpoint_up (b
);
7986 /* Make a momentary breakpoint based on the master breakpoint ORIG.
7987 The new breakpoint will have type TYPE, use OPS as its
7988 breakpoint_ops, and will set enabled to LOC_ENABLED. */
7990 static struct breakpoint
*
7991 momentary_breakpoint_from_master (struct breakpoint
*orig
,
7995 struct breakpoint
*copy
;
7997 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
);
7998 copy
->loc
= copy
->allocate_location ();
7999 set_breakpoint_location_function (copy
->loc
);
8001 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8002 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8003 copy
->loc
->address
= orig
->loc
->address
;
8004 copy
->loc
->section
= orig
->loc
->section
;
8005 copy
->loc
->pspace
= orig
->loc
->pspace
;
8006 copy
->loc
->probe
= orig
->loc
->probe
;
8007 copy
->loc
->line_number
= orig
->loc
->line_number
;
8008 copy
->loc
->symtab
= orig
->loc
->symtab
;
8009 copy
->loc
->enabled
= loc_enabled
;
8010 copy
->frame_id
= orig
->frame_id
;
8011 copy
->thread
= orig
->thread
;
8012 copy
->pspace
= orig
->pspace
;
8014 copy
->enable_state
= bp_enabled
;
8015 copy
->disposition
= disp_donttouch
;
8016 copy
->number
= internal_breakpoint_number
--;
8018 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8022 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8026 clone_momentary_breakpoint (struct breakpoint
*orig
)
8028 /* If there's nothing to clone, then return nothing. */
8032 return momentary_breakpoint_from_master (orig
, orig
->type
, 0);
8036 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8039 struct symtab_and_line sal
;
8041 sal
= find_pc_line (pc
, 0);
8043 sal
.section
= find_pc_overlay (pc
);
8044 sal
.explicit_pc
= 1;
8046 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8050 /* Tell the user we have just set a breakpoint B. */
8053 mention (struct breakpoint
*b
)
8055 b
->print_mention ();
8056 current_uiout
->text ("\n");
8060 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8062 /* Handle "set breakpoint auto-hw on".
8064 If the explicitly specified breakpoint type is not hardware
8065 breakpoint, check the memory map to see whether the breakpoint
8066 address is in read-only memory.
8068 - location type is not hardware breakpoint, memory is read-only.
8069 We change the type of the location to hardware breakpoint.
8071 - location type is hardware breakpoint, memory is read-write. This
8072 means we've previously made the location hardware one, but then the
8073 memory map changed, so we undo.
8077 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8079 if (automatic_hardware_breakpoints
8080 && bl
->owner
->type
!= bp_hardware_breakpoint
8081 && (bl
->loc_type
== bp_loc_software_breakpoint
8082 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8084 /* When breakpoints are removed, remove_breakpoints will use
8085 location types we've just set here, the only possible problem
8086 is that memory map has changed during running program, but
8087 it's not going to work anyway with current gdb. */
8088 mem_region
*mr
= lookup_mem_region (bl
->address
);
8092 enum bp_loc_type new_type
;
8094 if (mr
->attrib
.mode
!= MEM_RW
)
8095 new_type
= bp_loc_hardware_breakpoint
;
8097 new_type
= bp_loc_software_breakpoint
;
8099 if (new_type
!= bl
->loc_type
)
8101 static bool said
= false;
8103 bl
->loc_type
= new_type
;
8106 gdb_printf (_("Note: automatically using "
8107 "hardware breakpoints for "
8108 "read-only addresses.\n"));
8116 static struct bp_location
*
8117 add_location_to_breakpoint (struct breakpoint
*b
,
8118 const struct symtab_and_line
*sal
)
8120 struct bp_location
*loc
, **tmp
;
8121 CORE_ADDR adjusted_address
;
8122 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8124 if (loc_gdbarch
== NULL
)
8125 loc_gdbarch
= b
->gdbarch
;
8127 /* Adjust the breakpoint's address prior to allocating a location.
8128 Once we call allocate_location(), that mostly uninitialized
8129 location will be placed on the location chain. Adjustment of the
8130 breakpoint may cause target_read_memory() to be called and we do
8131 not want its scan of the location chain to find a breakpoint and
8132 location that's only been partially initialized. */
8133 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8136 /* Sort the locations by their ADDRESS. */
8137 loc
= b
->allocate_location ();
8138 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8139 tmp
= &((*tmp
)->next
))
8144 loc
->requested_address
= sal
->pc
;
8145 loc
->address
= adjusted_address
;
8146 loc
->pspace
= sal
->pspace
;
8147 loc
->probe
.prob
= sal
->prob
;
8148 loc
->probe
.objfile
= sal
->objfile
;
8149 gdb_assert (loc
->pspace
!= NULL
);
8150 loc
->section
= sal
->section
;
8151 loc
->gdbarch
= loc_gdbarch
;
8152 loc
->line_number
= sal
->line
;
8153 loc
->symtab
= sal
->symtab
;
8154 loc
->symbol
= sal
->symbol
;
8155 loc
->msymbol
= sal
->msymbol
;
8156 loc
->objfile
= sal
->objfile
;
8158 set_breakpoint_location_function (loc
);
8160 /* While by definition, permanent breakpoints are already present in the
8161 code, we don't mark the location as inserted. Normally one would expect
8162 that GDB could rely on that breakpoint instruction to stop the program,
8163 thus removing the need to insert its own breakpoint, except that executing
8164 the breakpoint instruction can kill the target instead of reporting a
8165 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8166 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8167 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8168 breakpoint be inserted normally results in QEMU knowing about the GDB
8169 breakpoint, and thus trap before the breakpoint instruction is executed.
8170 (If GDB later needs to continue execution past the permanent breakpoint,
8171 it manually increments the PC, thus avoiding executing the breakpoint
8173 if (bp_loc_is_permanent (loc
))
8180 /* Return true if LOC is pointing to a permanent breakpoint,
8181 return false otherwise. */
8184 bp_loc_is_permanent (struct bp_location
*loc
)
8186 gdb_assert (loc
!= NULL
);
8188 /* If we have a non-breakpoint-backed catchpoint or a software
8189 watchpoint, just return 0. We should not attempt to read from
8190 the addresses the locations of these breakpoint types point to.
8191 gdbarch_program_breakpoint_here_p, below, will attempt to read
8193 if (!bl_address_is_meaningful (loc
))
8196 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8197 switch_to_program_space_and_thread (loc
->pspace
);
8198 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8201 /* Build a command list for the dprintf corresponding to the current
8202 settings of the dprintf style options. */
8205 update_dprintf_command_list (struct breakpoint
*b
)
8207 const char *dprintf_args
= b
->extra_string
.get ();
8208 gdb::unique_xmalloc_ptr
<char> printf_line
= nullptr;
8213 dprintf_args
= skip_spaces (dprintf_args
);
8215 /* Allow a comma, as it may have terminated a location, but don't
8217 if (*dprintf_args
== ',')
8219 dprintf_args
= skip_spaces (dprintf_args
);
8221 if (*dprintf_args
!= '"')
8222 error (_("Bad format string, missing '\"'."));
8224 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8225 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8226 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8228 if (dprintf_function
.empty ())
8229 error (_("No function supplied for dprintf call"));
8231 if (!dprintf_channel
.empty ())
8232 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8233 dprintf_function
.c_str (),
8234 dprintf_channel
.c_str (),
8237 printf_line
= xstrprintf ("call (void) %s (%s)",
8238 dprintf_function
.c_str (),
8241 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8243 if (target_can_run_breakpoint_commands ())
8244 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8247 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8248 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8252 internal_error (__FILE__
, __LINE__
,
8253 _("Invalid dprintf style."));
8255 gdb_assert (printf_line
!= NULL
);
8257 /* Manufacture a printf sequence. */
8258 struct command_line
*printf_cmd_line
8259 = new struct command_line (simple_control
, printf_line
.release ());
8260 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8261 command_lines_deleter ()));
8264 /* Update all dprintf commands, making their command lists reflect
8265 current style settings. */
8268 update_dprintf_commands (const char *args
, int from_tty
,
8269 struct cmd_list_element
*c
)
8271 for (breakpoint
*b
: all_breakpoints ())
8272 if (b
->type
== bp_dprintf
)
8273 update_dprintf_command_list (b
);
8276 /* Create a breakpoint with SAL as location. Use LOCATION
8277 as a description of the location, and COND_STRING
8278 as condition expression. If LOCATION is NULL then create an
8279 "address location" from the address in the SAL. */
8282 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8283 gdb::array_view
<const symtab_and_line
> sals
,
8284 event_location_up
&&location
,
8285 gdb::unique_xmalloc_ptr
<char> filter
,
8286 gdb::unique_xmalloc_ptr
<char> cond_string
,
8287 gdb::unique_xmalloc_ptr
<char> extra_string
,
8288 enum bptype type
, enum bpdisp disposition
,
8289 int thread
, int task
, int ignore_count
,
8290 const struct breakpoint_ops
*ops
, int from_tty
,
8291 int enabled
, int internal
, unsigned flags
,
8292 int display_canonical
)
8296 if (type
== bp_hardware_breakpoint
)
8298 int target_resources_ok
;
8300 i
= hw_breakpoint_used_count ();
8301 target_resources_ok
=
8302 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8304 if (target_resources_ok
== 0)
8305 error (_("No hardware breakpoint support in the target."));
8306 else if (target_resources_ok
< 0)
8307 error (_("Hardware breakpoints used exceeds limit."));
8310 gdb_assert (!sals
.empty ());
8312 for (const auto &sal
: sals
)
8314 struct bp_location
*loc
;
8318 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8320 loc_gdbarch
= gdbarch
;
8322 describe_other_breakpoints (loc_gdbarch
,
8323 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8326 if (&sal
== &sals
[0])
8328 init_raw_breakpoint (b
, gdbarch
, sal
, type
);
8332 b
->cond_string
= std::move (cond_string
);
8333 b
->extra_string
= std::move (extra_string
);
8334 b
->ignore_count
= ignore_count
;
8335 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8336 b
->disposition
= disposition
;
8338 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8339 b
->loc
->inserted
= 1;
8341 if (type
== bp_static_tracepoint
8342 || type
== bp_static_marker_tracepoint
)
8344 struct tracepoint
*t
= (struct tracepoint
*) b
;
8345 struct static_tracepoint_marker marker
;
8347 if (strace_marker_p (b
))
8349 /* We already know the marker exists, otherwise, we
8350 wouldn't see a sal for it. */
8352 = &event_location_to_string (b
->location
.get ())[3];
8355 p
= skip_spaces (p
);
8357 endp
= skip_to_space (p
);
8359 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8361 gdb_printf (_("Probed static tracepoint "
8363 t
->static_trace_marker_id
.c_str ());
8365 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8367 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8369 gdb_printf (_("Probed static tracepoint "
8371 t
->static_trace_marker_id
.c_str ());
8374 warning (_("Couldn't determine the static "
8375 "tracepoint marker to probe"));
8382 loc
= add_location_to_breakpoint (b
, &sal
);
8383 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8387 /* Do not set breakpoint locations conditions yet. As locations
8388 are inserted, they get sorted based on their addresses. Let
8389 the list stabilize to have reliable location numbers. */
8391 /* Dynamic printf requires and uses additional arguments on the
8392 command line, otherwise it's an error. */
8393 if (type
== bp_dprintf
)
8395 if (b
->extra_string
)
8396 update_dprintf_command_list (b
);
8398 error (_("Format string required"));
8400 else if (b
->extra_string
)
8401 error (_("Garbage '%s' at end of command"), b
->extra_string
.get ());
8405 /* The order of the locations is now stable. Set the location
8406 condition using the location's number. */
8408 for (bp_location
*loc
: b
->locations ())
8410 if (b
->cond_string
!= nullptr)
8411 set_breakpoint_location_condition (b
->cond_string
.get (), loc
,
8412 b
->number
, loc_num
);
8417 b
->display_canonical
= display_canonical
;
8418 if (location
!= NULL
)
8419 b
->location
= std::move (location
);
8421 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8422 b
->filter
= std::move (filter
);
8426 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8427 gdb::array_view
<const symtab_and_line
> sals
,
8428 event_location_up
&&location
,
8429 gdb::unique_xmalloc_ptr
<char> filter
,
8430 gdb::unique_xmalloc_ptr
<char> cond_string
,
8431 gdb::unique_xmalloc_ptr
<char> extra_string
,
8432 enum bptype type
, enum bpdisp disposition
,
8433 int thread
, int task
, int ignore_count
,
8434 const struct breakpoint_ops
*ops
, int from_tty
,
8435 int enabled
, int internal
, unsigned flags
,
8436 int display_canonical
)
8438 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8440 init_breakpoint_sal (b
.get (), gdbarch
,
8441 sals
, std::move (location
),
8443 std::move (cond_string
),
8444 std::move (extra_string
),
8446 thread
, task
, ignore_count
,
8448 enabled
, internal
, flags
,
8451 install_breakpoint (internal
, std::move (b
), 0);
8454 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8455 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8456 value. COND_STRING, if not NULL, specified the condition to be
8457 used for all breakpoints. Essentially the only case where
8458 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8459 function. In that case, it's still not possible to specify
8460 separate conditions for different overloaded functions, so
8461 we take just a single condition string.
8463 NOTE: If the function succeeds, the caller is expected to cleanup
8464 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8465 array contents). If the function fails (error() is called), the
8466 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8467 COND and SALS arrays and each of those arrays contents. */
8470 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8471 struct linespec_result
*canonical
,
8472 gdb::unique_xmalloc_ptr
<char> cond_string
,
8473 gdb::unique_xmalloc_ptr
<char> extra_string
,
8474 enum bptype type
, enum bpdisp disposition
,
8475 int thread
, int task
, int ignore_count
,
8476 const struct breakpoint_ops
*ops
, int from_tty
,
8477 int enabled
, int internal
, unsigned flags
)
8479 if (canonical
->pre_expanded
)
8480 gdb_assert (canonical
->lsals
.size () == 1);
8482 for (const auto &lsal
: canonical
->lsals
)
8484 /* Note that 'location' can be NULL in the case of a plain
8485 'break', without arguments. */
8486 event_location_up location
8487 = (canonical
->location
!= NULL
8488 ? copy_event_location (canonical
->location
.get ()) : NULL
);
8489 gdb::unique_xmalloc_ptr
<char> filter_string
8490 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8492 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8493 std::move (location
),
8494 std::move (filter_string
),
8495 std::move (cond_string
),
8496 std::move (extra_string
),
8498 thread
, task
, ignore_count
, ops
,
8499 from_tty
, enabled
, internal
, flags
,
8500 canonical
->special_display
);
8504 /* Parse LOCATION which is assumed to be a SAL specification possibly
8505 followed by conditionals. On return, SALS contains an array of SAL
8506 addresses found. LOCATION points to the end of the SAL (for
8507 linespec locations).
8509 The array and the line spec strings are allocated on the heap, it is
8510 the caller's responsibility to free them. */
8513 parse_breakpoint_sals (struct event_location
*location
,
8514 struct linespec_result
*canonical
)
8516 struct symtab_and_line cursal
;
8518 if (event_location_type (location
) == LINESPEC_LOCATION
)
8520 const char *spec
= get_linespec_location (location
)->spec_string
;
8524 /* The last displayed codepoint, if it's valid, is our default
8525 breakpoint address. */
8526 if (last_displayed_sal_is_valid ())
8528 /* Set sal's pspace, pc, symtab, and line to the values
8529 corresponding to the last call to print_frame_info.
8530 Be sure to reinitialize LINE with NOTCURRENT == 0
8531 as the breakpoint line number is inappropriate otherwise.
8532 find_pc_line would adjust PC, re-set it back. */
8533 symtab_and_line sal
= get_last_displayed_sal ();
8534 CORE_ADDR pc
= sal
.pc
;
8536 sal
= find_pc_line (pc
, 0);
8538 /* "break" without arguments is equivalent to "break *PC"
8539 where PC is the last displayed codepoint's address. So
8540 make sure to set sal.explicit_pc to prevent GDB from
8541 trying to expand the list of sals to include all other
8542 instances with the same symtab and line. */
8544 sal
.explicit_pc
= 1;
8546 struct linespec_sals lsal
;
8548 lsal
.canonical
= NULL
;
8550 canonical
->lsals
.push_back (std::move (lsal
));
8554 error (_("No default breakpoint address now."));
8558 /* Force almost all breakpoints to be in terms of the
8559 current_source_symtab (which is decode_line_1's default).
8560 This should produce the results we want almost all of the
8561 time while leaving default_breakpoint_* alone.
8563 ObjC: However, don't match an Objective-C method name which
8564 may have a '+' or '-' succeeded by a '['. */
8565 cursal
= get_current_source_symtab_and_line ();
8566 if (last_displayed_sal_is_valid ())
8568 const char *spec
= NULL
;
8570 if (event_location_type (location
) == LINESPEC_LOCATION
)
8571 spec
= get_linespec_location (location
)->spec_string
;
8575 && strchr ("+-", spec
[0]) != NULL
8578 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8579 get_last_displayed_symtab (),
8580 get_last_displayed_line (),
8581 canonical
, NULL
, NULL
);
8586 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
8587 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
8591 /* Convert each SAL into a real PC. Verify that the PC can be
8592 inserted as a breakpoint. If it can't throw an error. */
8595 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
8597 for (auto &sal
: sals
)
8598 resolve_sal_pc (&sal
);
8601 /* Fast tracepoints may have restrictions on valid locations. For
8602 instance, a fast tracepoint using a jump instead of a trap will
8603 likely have to overwrite more bytes than a trap would, and so can
8604 only be placed where the instruction is longer than the jump, or a
8605 multi-instruction sequence does not have a jump into the middle of
8609 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
8610 gdb::array_view
<const symtab_and_line
> sals
)
8612 for (const auto &sal
: sals
)
8614 struct gdbarch
*sarch
;
8616 sarch
= get_sal_arch (sal
);
8617 /* We fall back to GDBARCH if there is no architecture
8618 associated with SAL. */
8622 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
8623 error (_("May not have a fast tracepoint at %s%s"),
8624 paddress (sarch
, sal
.pc
), msg
.c_str ());
8628 /* Given TOK, a string specification of condition and thread, as
8629 accepted by the 'break' command, extract the condition
8630 string and thread number and set *COND_STRING and *THREAD.
8631 PC identifies the context at which the condition should be parsed.
8632 If no condition is found, *COND_STRING is set to NULL.
8633 If no thread is found, *THREAD is set to -1. */
8636 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
8637 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8638 int *thread
, int *task
,
8639 gdb::unique_xmalloc_ptr
<char> *rest
)
8641 cond_string
->reset ();
8649 const char *end_tok
;
8651 const char *cond_start
= NULL
;
8652 const char *cond_end
= NULL
;
8654 tok
= skip_spaces (tok
);
8656 if ((*tok
== '"' || *tok
== ',') && rest
)
8658 rest
->reset (savestring (tok
, strlen (tok
)));
8662 end_tok
= skip_to_space (tok
);
8664 toklen
= end_tok
- tok
;
8666 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
8668 tok
= cond_start
= end_tok
+ 1;
8671 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
8673 catch (const gdb_exception_error
&)
8678 tok
= tok
+ strlen (tok
);
8681 cond_string
->reset (savestring (cond_start
, cond_end
- cond_start
));
8683 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
8688 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
8691 struct thread_info
*thr
;
8694 thr
= parse_thread_id (tok
, &tmptok
);
8696 error (_("Junk after thread keyword."));
8697 *thread
= thr
->global_num
;
8700 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
8705 *task
= strtol (tok
, &tmptok
, 0);
8707 error (_("Junk after task keyword."));
8708 if (!valid_task_id (*task
))
8709 error (_("Unknown task %d."), *task
);
8714 rest
->reset (savestring (tok
, strlen (tok
)));
8718 error (_("Junk at end of arguments."));
8722 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
8723 succeeds. The parsed values are written to COND_STRING, THREAD,
8724 TASK, and REST. See the comment of 'find_condition_and_thread'
8725 for the description of these parameters and INPUT. */
8728 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
8730 gdb::unique_xmalloc_ptr
<char> *cond_string
,
8731 int *thread
, int *task
,
8732 gdb::unique_xmalloc_ptr
<char> *rest
)
8734 int num_failures
= 0;
8735 for (auto &sal
: sals
)
8737 gdb::unique_xmalloc_ptr
<char> cond
;
8740 gdb::unique_xmalloc_ptr
<char> remaining
;
8742 /* Here we want to parse 'arg' to separate condition from thread
8743 number. But because parsing happens in a context and the
8744 contexts of sals might be different, try each until there is
8745 success. Finding one successful parse is sufficient for our
8746 goal. When setting the breakpoint we'll re-parse the
8747 condition in the context of each sal. */
8750 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
8751 &task_id
, &remaining
);
8752 *cond_string
= std::move (cond
);
8753 *thread
= thread_id
;
8755 *rest
= std::move (remaining
);
8758 catch (const gdb_exception_error
&e
)
8761 /* If no sal remains, do not continue. */
8762 if (num_failures
== sals
.size ())
8768 /* Decode a static tracepoint marker spec. */
8770 static std::vector
<symtab_and_line
>
8771 decode_static_tracepoint_spec (const char **arg_p
)
8773 const char *p
= &(*arg_p
)[3];
8776 p
= skip_spaces (p
);
8778 endp
= skip_to_space (p
);
8780 std::string
marker_str (p
, endp
- p
);
8782 std::vector
<static_tracepoint_marker
> markers
8783 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
8784 if (markers
.empty ())
8785 error (_("No known static tracepoint marker named %s"),
8786 marker_str
.c_str ());
8788 std::vector
<symtab_and_line
> sals
;
8789 sals
.reserve (markers
.size ());
8791 for (const static_tracepoint_marker
&marker
: markers
)
8793 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
8794 sal
.pc
= marker
.address
;
8795 sals
.push_back (sal
);
8802 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
8803 according to IS_TRACEPOINT. */
8805 static const struct breakpoint_ops
*
8806 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
8811 if (location_type
== PROBE_LOCATION
)
8812 return &tracepoint_probe_breakpoint_ops
;
8814 return &base_breakpoint_ops
;
8818 if (location_type
== PROBE_LOCATION
)
8819 return &bkpt_probe_breakpoint_ops
;
8821 return &base_breakpoint_ops
;
8825 /* See breakpoint.h. */
8827 const struct breakpoint_ops
*
8828 breakpoint_ops_for_event_location (const struct event_location
*location
,
8831 if (location
!= nullptr)
8832 return breakpoint_ops_for_event_location_type
8833 (event_location_type (location
), is_tracepoint
);
8834 return &base_breakpoint_ops
;
8837 /* See breakpoint.h. */
8840 create_breakpoint (struct gdbarch
*gdbarch
,
8841 struct event_location
*location
,
8842 const char *cond_string
,
8843 int thread
, const char *extra_string
,
8844 bool force_condition
, int parse_extra
,
8845 int tempflag
, enum bptype type_wanted
,
8847 enum auto_boolean pending_break_support
,
8848 const struct breakpoint_ops
*ops
,
8849 int from_tty
, int enabled
, int internal
,
8852 struct linespec_result canonical
;
8855 int prev_bkpt_count
= breakpoint_count
;
8857 gdb_assert (ops
!= NULL
);
8859 /* If extra_string isn't useful, set it to NULL. */
8860 if (extra_string
!= NULL
&& *extra_string
== '\0')
8861 extra_string
= NULL
;
8865 ops
->create_sals_from_location (location
, &canonical
);
8867 catch (const gdb_exception_error
&e
)
8869 /* If caller is interested in rc value from parse, set
8871 if (e
.error
== NOT_FOUND_ERROR
)
8873 /* If pending breakpoint support is turned off, throw
8876 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
8879 exception_print (gdb_stderr
, e
);
8881 /* If pending breakpoint support is auto query and the user
8882 selects no, then simply return the error code. */
8883 if (pending_break_support
== AUTO_BOOLEAN_AUTO
8884 && !nquery (_("Make %s pending on future shared library load? "),
8885 bptype_string (type_wanted
)))
8888 /* At this point, either the user was queried about setting
8889 a pending breakpoint and selected yes, or pending
8890 breakpoint behavior is on and thus a pending breakpoint
8891 is defaulted on behalf of the user. */
8898 if (!pending
&& canonical
.lsals
.empty ())
8901 /* Resolve all line numbers to PC's and verify that the addresses
8902 are ok for the target. */
8905 for (auto &lsal
: canonical
.lsals
)
8906 breakpoint_sals_to_pc (lsal
.sals
);
8909 /* Fast tracepoints may have additional restrictions on location. */
8910 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
8912 for (const auto &lsal
: canonical
.lsals
)
8913 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
8916 /* Verify that condition can be parsed, before setting any
8917 breakpoints. Allocate a separate condition expression for each
8921 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
8922 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
8926 gdb::unique_xmalloc_ptr
<char> rest
;
8927 gdb::unique_xmalloc_ptr
<char> cond
;
8929 const linespec_sals
&lsal
= canonical
.lsals
[0];
8931 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
8932 &cond
, &thread
, &task
, &rest
);
8933 cond_string_copy
= std::move (cond
);
8934 extra_string_copy
= std::move (rest
);
8938 if (type_wanted
!= bp_dprintf
8939 && extra_string
!= NULL
&& *extra_string
!= '\0')
8940 error (_("Garbage '%s' at end of location"), extra_string
);
8942 /* Check the validity of the condition. We should error out
8943 if the condition is invalid at all of the locations and
8944 if it is not forced. In the PARSE_EXTRA case above, this
8945 check is done when parsing the EXTRA_STRING. */
8946 if (cond_string
!= nullptr && !force_condition
)
8948 int num_failures
= 0;
8949 const linespec_sals
&lsal
= canonical
.lsals
[0];
8950 for (const auto &sal
: lsal
.sals
)
8952 const char *cond
= cond_string
;
8955 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
8956 /* One success is sufficient to keep going. */
8959 catch (const gdb_exception_error
&)
8962 /* If this is the last sal, error out. */
8963 if (num_failures
== lsal
.sals
.size ())
8969 /* Create a private copy of condition string. */
8971 cond_string_copy
.reset (xstrdup (cond_string
));
8972 /* Create a private copy of any extra string. */
8974 extra_string_copy
.reset (xstrdup (extra_string
));
8977 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
8978 std::move (cond_string_copy
),
8979 std::move (extra_string_copy
),
8981 tempflag
? disp_del
: disp_donttouch
,
8982 thread
, task
, ignore_count
, ops
,
8983 from_tty
, enabled
, internal
, flags
);
8987 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
8989 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
);
8990 b
->location
= copy_event_location (location
);
8993 b
->cond_string
= NULL
;
8996 /* Create a private copy of condition string. */
8997 b
->cond_string
.reset (cond_string
!= NULL
8998 ? xstrdup (cond_string
)
9003 /* Create a private copy of any extra string. */
9004 b
->extra_string
.reset (extra_string
!= NULL
9005 ? xstrdup (extra_string
)
9007 b
->ignore_count
= ignore_count
;
9008 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9009 b
->condition_not_parsed
= 1;
9010 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9011 if ((type_wanted
!= bp_breakpoint
9012 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9013 b
->pspace
= current_program_space
;
9015 install_breakpoint (internal
, std::move (b
), 0);
9018 if (canonical
.lsals
.size () > 1)
9020 warning (_("Multiple breakpoints were set.\nUse the "
9021 "\"delete\" command to delete unwanted breakpoints."));
9022 prev_breakpoint_count
= prev_bkpt_count
;
9025 update_global_location_list (UGLL_MAY_INSERT
);
9030 /* Set a breakpoint.
9031 ARG is a string describing breakpoint address,
9032 condition, and thread.
9033 FLAG specifies if a breakpoint is hardware on,
9034 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9038 break_command_1 (const char *arg
, int flag
, int from_tty
)
9040 int tempflag
= flag
& BP_TEMPFLAG
;
9041 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9042 ? bp_hardware_breakpoint
9045 event_location_up location
= string_to_event_location (&arg
, current_language
);
9046 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9047 (location
.get (), false /* is_tracepoint */);
9049 create_breakpoint (get_current_arch (),
9051 NULL
, 0, arg
, false, 1 /* parse arg */,
9052 tempflag
, type_wanted
,
9053 0 /* Ignore count */,
9054 pending_break_support
,
9062 /* Helper function for break_command_1 and disassemble_command. */
9065 resolve_sal_pc (struct symtab_and_line
*sal
)
9069 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9071 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9072 error (_("No line %d in file \"%s\"."),
9073 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9076 /* If this SAL corresponds to a breakpoint inserted using a line
9077 number, then skip the function prologue if necessary. */
9078 if (sal
->explicit_line
)
9079 skip_prologue_sal (sal
);
9082 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9084 const struct blockvector
*bv
;
9085 const struct block
*b
;
9088 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9089 sal
->symtab
->compunit ());
9092 sym
= block_linkage_function (b
);
9095 fixup_symbol_section (sym
, sal
->symtab
->compunit ()->objfile ());
9097 = sym
->obj_section (sal
->symtab
->compunit ()->objfile ());
9101 /* It really is worthwhile to have the section, so we'll
9102 just have to look harder. This case can be executed
9103 if we have line numbers but no functions (as can
9104 happen in assembly source). */
9106 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9107 switch_to_program_space_and_thread (sal
->pspace
);
9109 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9111 sal
->section
= msym
.obj_section ();
9118 break_command (const char *arg
, int from_tty
)
9120 break_command_1 (arg
, 0, from_tty
);
9124 tbreak_command (const char *arg
, int from_tty
)
9126 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9130 hbreak_command (const char *arg
, int from_tty
)
9132 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9136 thbreak_command (const char *arg
, int from_tty
)
9138 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9141 /* The dynamic printf command is mostly like a regular breakpoint, but
9142 with a prewired command list consisting of a single output command,
9143 built from extra arguments supplied on the dprintf command
9147 dprintf_command (const char *arg
, int from_tty
)
9149 event_location_up location
= string_to_event_location (&arg
, current_language
);
9151 /* If non-NULL, ARG should have been advanced past the location;
9152 the next character must be ','. */
9155 if (arg
[0] != ',' || arg
[1] == '\0')
9156 error (_("Format string required"));
9159 /* Skip the comma. */
9164 create_breakpoint (get_current_arch (),
9166 NULL
, 0, arg
, false, 1 /* parse arg */,
9168 0 /* Ignore count */,
9169 pending_break_support
,
9170 &base_breakpoint_ops
,
9178 agent_printf_command (const char *arg
, int from_tty
)
9180 error (_("May only run agent-printf on the target"));
9183 /* Implement the "breakpoint_hit" method for ranged breakpoints. */
9186 ranged_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
9187 const address_space
*aspace
,
9189 const target_waitstatus
&ws
)
9191 if (ws
.kind () != TARGET_WAITKIND_STOPPED
9192 || ws
.sig () != GDB_SIGNAL_TRAP
)
9195 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9196 bl
->length
, aspace
, bp_addr
);
9199 /* Implement the "resources_needed" method for ranged breakpoints. */
9202 ranged_breakpoint::resources_needed (const struct bp_location
*bl
)
9204 return target_ranged_break_num_registers ();
9207 /* Implement the "print_it" method for ranged breakpoints. */
9209 enum print_stop_action
9210 ranged_breakpoint::print_it (const bpstat
*bs
) const
9212 struct bp_location
*bl
= loc
;
9213 struct ui_out
*uiout
= current_uiout
;
9215 gdb_assert (type
== bp_hardware_breakpoint
);
9217 /* Ranged breakpoints have only one location. */
9218 gdb_assert (bl
&& bl
->next
== NULL
);
9220 annotate_breakpoint (number
);
9222 maybe_print_thread_hit_breakpoint (uiout
);
9224 if (disposition
== disp_del
)
9225 uiout
->text ("Temporary ranged breakpoint ");
9227 uiout
->text ("Ranged breakpoint ");
9228 if (uiout
->is_mi_like_p ())
9230 uiout
->field_string ("reason",
9231 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9232 uiout
->field_string ("disp", bpdisp_text (disposition
));
9234 uiout
->field_signed ("bkptno", number
);
9237 return PRINT_SRC_AND_LOC
;
9240 /* Implement the "print_one" method for ranged breakpoints. */
9243 ranged_breakpoint::print_one (struct bp_location
**last_loc
)
9245 struct bp_location
*bl
= loc
;
9246 struct value_print_options opts
;
9247 struct ui_out
*uiout
= current_uiout
;
9249 /* Ranged breakpoints have only one location. */
9250 gdb_assert (bl
&& bl
->next
== NULL
);
9252 get_user_print_options (&opts
);
9254 if (opts
.addressprint
)
9255 /* We don't print the address range here, it will be printed later
9256 by print_one_detail_ranged_breakpoint. */
9257 uiout
->field_skip ("addr");
9259 print_breakpoint_location (this, bl
);
9265 /* Implement the "print_one_detail" method for ranged breakpoints. */
9268 ranged_breakpoint::print_one_detail (struct ui_out
*uiout
) const
9270 CORE_ADDR address_start
, address_end
;
9271 struct bp_location
*bl
= loc
;
9276 address_start
= bl
->address
;
9277 address_end
= address_start
+ bl
->length
- 1;
9279 uiout
->text ("\taddress range: ");
9280 stb
.printf ("[%s, %s]",
9281 print_core_address (bl
->gdbarch
, address_start
),
9282 print_core_address (bl
->gdbarch
, address_end
));
9283 uiout
->field_stream ("addr", stb
);
9287 /* Implement the "print_mention" method for ranged breakpoints. */
9290 ranged_breakpoint::print_mention ()
9292 struct bp_location
*bl
= loc
;
9293 struct ui_out
*uiout
= current_uiout
;
9296 gdb_assert (type
== bp_hardware_breakpoint
);
9298 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9299 number
, paddress (bl
->gdbarch
, bl
->address
),
9300 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9303 /* Implement the "print_recreate" method for ranged breakpoints. */
9306 ranged_breakpoint::print_recreate (struct ui_file
*fp
)
9308 gdb_printf (fp
, "break-range %s, %s",
9309 event_location_to_string (location
.get ()),
9310 event_location_to_string (location_range_end
.get ()));
9311 print_recreate_thread (fp
);
9314 /* Find the address where the end of the breakpoint range should be
9315 placed, given the SAL of the end of the range. This is so that if
9316 the user provides a line number, the end of the range is set to the
9317 last instruction of the given line. */
9320 find_breakpoint_range_end (struct symtab_and_line sal
)
9324 /* If the user provided a PC value, use it. Otherwise,
9325 find the address of the end of the given location. */
9326 if (sal
.explicit_pc
)
9333 ret
= find_line_pc_range (sal
, &start
, &end
);
9335 error (_("Could not find location of the end of the range."));
9337 /* find_line_pc_range returns the start of the next line. */
9344 /* Implement the "break-range" CLI command. */
9347 break_range_command (const char *arg
, int from_tty
)
9349 const char *arg_start
;
9350 struct linespec_result canonical_start
, canonical_end
;
9351 int bp_count
, can_use_bp
, length
;
9353 struct breakpoint
*b
;
9355 /* We don't support software ranged breakpoints. */
9356 if (target_ranged_break_num_registers () < 0)
9357 error (_("This target does not support hardware ranged breakpoints."));
9359 bp_count
= hw_breakpoint_used_count ();
9360 bp_count
+= target_ranged_break_num_registers ();
9361 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9364 error (_("Hardware breakpoints used exceeds limit."));
9366 arg
= skip_spaces (arg
);
9367 if (arg
== NULL
|| arg
[0] == '\0')
9368 error(_("No address range specified."));
9371 event_location_up start_location
= string_to_event_location (&arg
,
9373 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9376 error (_("Too few arguments."));
9377 else if (canonical_start
.lsals
.empty ())
9378 error (_("Could not find location of the beginning of the range."));
9380 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9382 if (canonical_start
.lsals
.size () > 1
9383 || lsal_start
.sals
.size () != 1)
9384 error (_("Cannot create a ranged breakpoint with multiple locations."));
9386 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9387 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9389 arg
++; /* Skip the comma. */
9390 arg
= skip_spaces (arg
);
9392 /* Parse the end location. */
9396 /* We call decode_line_full directly here instead of using
9397 parse_breakpoint_sals because we need to specify the start location's
9398 symtab and line as the default symtab and line for the end of the
9399 range. This makes it possible to have ranges like "foo.c:27, +14",
9400 where +14 means 14 lines from the start location. */
9401 event_location_up end_location
= string_to_event_location (&arg
,
9403 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9404 sal_start
.symtab
, sal_start
.line
,
9405 &canonical_end
, NULL
, NULL
);
9407 if (canonical_end
.lsals
.empty ())
9408 error (_("Could not find location of the end of the range."));
9410 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9411 if (canonical_end
.lsals
.size () > 1
9412 || lsal_end
.sals
.size () != 1)
9413 error (_("Cannot create a ranged breakpoint with multiple locations."));
9415 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9417 end
= find_breakpoint_range_end (sal_end
);
9418 if (sal_start
.pc
> end
)
9419 error (_("Invalid address range, end precedes start."));
9421 length
= end
- sal_start
.pc
+ 1;
9423 /* Length overflowed. */
9424 error (_("Address range too large."));
9425 else if (length
== 1)
9427 /* This range is simple enough to be handled by
9428 the `hbreak' command. */
9429 hbreak_command (&addr_string_start
[0], 1);
9434 /* Now set up the breakpoint. */
9435 std::unique_ptr
<breakpoint
> br (new ranged_breakpoint ());
9436 init_raw_breakpoint (br
.get (), get_current_arch (),
9437 sal_start
, bp_hardware_breakpoint
);
9438 b
= add_to_breakpoint_chain (std::move (br
));
9440 set_breakpoint_count (breakpoint_count
+ 1);
9441 b
->number
= breakpoint_count
;
9442 b
->disposition
= disp_donttouch
;
9443 b
->location
= std::move (start_location
);
9444 b
->location_range_end
= std::move (end_location
);
9445 b
->loc
->length
= length
;
9448 gdb::observers::breakpoint_created
.notify (b
);
9449 update_global_location_list (UGLL_MAY_INSERT
);
9452 /* Return non-zero if EXP is verified as constant. Returned zero
9453 means EXP is variable. Also the constant detection may fail for
9454 some constant expressions and in such case still falsely return
9458 watchpoint_exp_is_const (const struct expression
*exp
)
9460 return exp
->op
->constant_p ();
9463 /* Implement the "re_set" method for watchpoints. */
9466 watchpoint::re_set ()
9468 /* Watchpoint can be either on expression using entirely global
9469 variables, or it can be on local variables.
9471 Watchpoints of the first kind are never auto-deleted, and even
9472 persist across program restarts. Since they can use variables
9473 from shared libraries, we need to reparse expression as libraries
9474 are loaded and unloaded.
9476 Watchpoints on local variables can also change meaning as result
9477 of solib event. For example, if a watchpoint uses both a local
9478 and a global variables in expression, it's a local watchpoint,
9479 but unloading of a shared library will make the expression
9480 invalid. This is not a very common use case, but we still
9481 re-evaluate expression, to avoid surprises to the user.
9483 Note that for local watchpoints, we re-evaluate it only if
9484 watchpoints frame id is still valid. If it's not, it means the
9485 watchpoint is out of scope and will be deleted soon. In fact,
9486 I'm not sure we'll ever be called in this case.
9488 If a local watchpoint's frame id is still valid, then
9489 exp_valid_block is likewise valid, and we can safely use it.
9491 Don't do anything about disabled watchpoints, since they will be
9492 reevaluated again when enabled. */
9493 update_watchpoint (this, 1 /* reparse */);
9496 /* Implement the "insert" method for hardware watchpoints. */
9499 watchpoint::insert_location (struct bp_location
*bl
)
9501 int length
= exact
? 1 : bl
->length
;
9503 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9507 /* Implement the "remove" method for hardware watchpoints. */
9510 watchpoint::remove_location (struct bp_location
*bl
,
9511 enum remove_bp_reason reason
)
9513 int length
= exact
? 1 : bl
->length
;
9515 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
9520 watchpoint::breakpoint_hit (const struct bp_location
*bl
,
9521 const address_space
*aspace
, CORE_ADDR bp_addr
,
9522 const target_waitstatus
&ws
)
9524 struct breakpoint
*b
= bl
->owner
;
9526 /* Continuable hardware watchpoints are treated as non-existent if the
9527 reason we stopped wasn't a hardware watchpoint (we didn't stop on
9528 some data address). Otherwise gdb won't stop on a break instruction
9529 in the code (not from a breakpoint) when a hardware watchpoint has
9530 been defined. Also skip watchpoints which we know did not trigger
9531 (did not match the data address). */
9532 if (is_hardware_watchpoint (b
)
9533 && watchpoint_triggered
== watch_triggered_no
)
9540 watchpoint::check_status (bpstat
*bs
)
9542 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
9544 bpstat_check_watchpoint (bs
);
9547 /* Implement the "resources_needed" method for hardware
9551 watchpoint::resources_needed (const struct bp_location
*bl
)
9553 int length
= exact
? 1 : bl
->length
;
9555 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
9558 /* Implement the "works_in_software_mode" method for hardware
9562 watchpoint::works_in_software_mode () const
9564 /* Read and access watchpoints only work with hardware support. */
9565 return type
== bp_watchpoint
|| type
== bp_hardware_watchpoint
;
9568 enum print_stop_action
9569 watchpoint::print_it (const bpstat
*bs
) const
9571 struct breakpoint
*b
;
9572 enum print_stop_action result
;
9573 struct ui_out
*uiout
= current_uiout
;
9575 gdb_assert (bs
->bp_location_at
!= NULL
);
9577 b
= bs
->breakpoint_at
;
9579 annotate_watchpoint (b
->number
);
9580 maybe_print_thread_hit_breakpoint (uiout
);
9584 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
9588 case bp_hardware_watchpoint
:
9589 if (uiout
->is_mi_like_p ())
9591 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9593 tuple_emitter
.emplace (uiout
, "value");
9594 uiout
->text ("\nOld value = ");
9595 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9596 uiout
->field_stream ("old", stb
);
9597 uiout
->text ("\nNew value = ");
9598 watchpoint_value_print (val
.get (), &stb
);
9599 uiout
->field_stream ("new", stb
);
9601 /* More than one watchpoint may have been triggered. */
9602 result
= PRINT_UNKNOWN
;
9605 case bp_read_watchpoint
:
9606 if (uiout
->is_mi_like_p ())
9608 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9610 tuple_emitter
.emplace (uiout
, "value");
9611 uiout
->text ("\nValue = ");
9612 watchpoint_value_print (val
.get (), &stb
);
9613 uiout
->field_stream ("value", stb
);
9615 result
= PRINT_UNKNOWN
;
9618 case bp_access_watchpoint
:
9619 if (bs
->old_val
!= NULL
)
9621 if (uiout
->is_mi_like_p ())
9624 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9626 tuple_emitter
.emplace (uiout
, "value");
9627 uiout
->text ("\nOld value = ");
9628 watchpoint_value_print (bs
->old_val
.get (), &stb
);
9629 uiout
->field_stream ("old", stb
);
9630 uiout
->text ("\nNew value = ");
9635 if (uiout
->is_mi_like_p ())
9638 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9639 tuple_emitter
.emplace (uiout
, "value");
9640 uiout
->text ("\nValue = ");
9642 watchpoint_value_print (val
.get (), &stb
);
9643 uiout
->field_stream ("new", stb
);
9645 result
= PRINT_UNKNOWN
;
9648 result
= PRINT_UNKNOWN
;
9654 /* Implement the "print_mention" method for hardware watchpoints. */
9657 watchpoint::print_mention ()
9659 struct ui_out
*uiout
= current_uiout
;
9660 const char *tuple_name
;
9665 uiout
->text ("Watchpoint ");
9668 case bp_hardware_watchpoint
:
9669 uiout
->text ("Hardware watchpoint ");
9672 case bp_read_watchpoint
:
9673 uiout
->text ("Hardware read watchpoint ");
9674 tuple_name
= "hw-rwpt";
9676 case bp_access_watchpoint
:
9677 uiout
->text ("Hardware access (read/write) watchpoint ");
9678 tuple_name
= "hw-awpt";
9681 internal_error (__FILE__
, __LINE__
,
9682 _("Invalid hardware watchpoint type."));
9685 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9686 uiout
->field_signed ("number", number
);
9688 uiout
->field_string ("exp", exp_string
.get ());
9691 /* Implement the "print_recreate" method for watchpoints. */
9694 watchpoint::print_recreate (struct ui_file
*fp
)
9699 case bp_hardware_watchpoint
:
9700 gdb_printf (fp
, "watch");
9702 case bp_read_watchpoint
:
9703 gdb_printf (fp
, "rwatch");
9705 case bp_access_watchpoint
:
9706 gdb_printf (fp
, "awatch");
9709 internal_error (__FILE__
, __LINE__
,
9710 _("Invalid watchpoint type."));
9713 gdb_printf (fp
, " %s", exp_string
.get ());
9714 print_recreate_thread (fp
);
9717 /* Implement the "explains_signal" method for watchpoints. */
9720 watchpoint::explains_signal (enum gdb_signal sig
)
9722 /* A software watchpoint cannot cause a signal other than
9724 if (type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
9730 struct masked_watchpoint
: public watchpoint
9732 int insert_location (struct bp_location
*) override
;
9733 int remove_location (struct bp_location
*,
9734 enum remove_bp_reason reason
) override
;
9735 int resources_needed (const struct bp_location
*) override
;
9736 bool works_in_software_mode () const override
;
9737 enum print_stop_action
print_it (const bpstat
*bs
) const override
;
9738 void print_one_detail (struct ui_out
*) const override
;
9739 void print_mention () override
;
9740 void print_recreate (struct ui_file
*fp
) override
;
9743 /* Implement the "insert" method for masked hardware watchpoints. */
9746 masked_watchpoint::insert_location (struct bp_location
*bl
)
9748 return target_insert_mask_watchpoint (bl
->address
, hw_wp_mask
,
9749 bl
->watchpoint_type
);
9752 /* Implement the "remove" method for masked hardware watchpoints. */
9755 masked_watchpoint::remove_location (struct bp_location
*bl
,
9756 enum remove_bp_reason reason
)
9758 return target_remove_mask_watchpoint (bl
->address
, hw_wp_mask
,
9759 bl
->watchpoint_type
);
9762 /* Implement the "resources_needed" method for masked hardware
9766 masked_watchpoint::resources_needed (const struct bp_location
*bl
)
9768 return target_masked_watch_num_registers (bl
->address
, hw_wp_mask
);
9771 /* Implement the "works_in_software_mode" method for masked hardware
9775 masked_watchpoint::works_in_software_mode () const
9780 /* Implement the "print_it" method for masked hardware
9783 enum print_stop_action
9784 masked_watchpoint::print_it (const bpstat
*bs
) const
9786 struct breakpoint
*b
= bs
->breakpoint_at
;
9787 struct ui_out
*uiout
= current_uiout
;
9789 /* Masked watchpoints have only one location. */
9790 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
9792 annotate_watchpoint (b
->number
);
9793 maybe_print_thread_hit_breakpoint (uiout
);
9797 case bp_hardware_watchpoint
:
9798 if (uiout
->is_mi_like_p ())
9800 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
9803 case bp_read_watchpoint
:
9804 if (uiout
->is_mi_like_p ())
9806 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
9809 case bp_access_watchpoint
:
9810 if (uiout
->is_mi_like_p ())
9813 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
9816 internal_error (__FILE__
, __LINE__
,
9817 _("Invalid hardware watchpoint type."));
9822 Check the underlying instruction at PC for the memory\n\
9823 address and value which triggered this watchpoint.\n"));
9826 /* More than one watchpoint may have been triggered. */
9827 return PRINT_UNKNOWN
;
9830 /* Implement the "print_one_detail" method for masked hardware
9834 masked_watchpoint::print_one_detail (struct ui_out
*uiout
) const
9836 /* Masked watchpoints have only one location. */
9837 gdb_assert (loc
&& loc
->next
== NULL
);
9839 uiout
->text ("\tmask ");
9840 uiout
->field_core_addr ("mask", loc
->gdbarch
, hw_wp_mask
);
9844 /* Implement the "print_mention" method for masked hardware
9848 masked_watchpoint::print_mention ()
9850 struct ui_out
*uiout
= current_uiout
;
9851 const char *tuple_name
;
9855 case bp_hardware_watchpoint
:
9856 uiout
->text ("Masked hardware watchpoint ");
9859 case bp_read_watchpoint
:
9860 uiout
->text ("Masked hardware read watchpoint ");
9861 tuple_name
= "hw-rwpt";
9863 case bp_access_watchpoint
:
9864 uiout
->text ("Masked hardware access (read/write) watchpoint ");
9865 tuple_name
= "hw-awpt";
9868 internal_error (__FILE__
, __LINE__
,
9869 _("Invalid hardware watchpoint type."));
9872 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
9873 uiout
->field_signed ("number", number
);
9875 uiout
->field_string ("exp", exp_string
.get ());
9878 /* Implement the "print_recreate" method for masked hardware
9882 masked_watchpoint::print_recreate (struct ui_file
*fp
)
9886 case bp_hardware_watchpoint
:
9887 gdb_printf (fp
, "watch");
9889 case bp_read_watchpoint
:
9890 gdb_printf (fp
, "rwatch");
9892 case bp_access_watchpoint
:
9893 gdb_printf (fp
, "awatch");
9896 internal_error (__FILE__
, __LINE__
,
9897 _("Invalid hardware watchpoint type."));
9900 gdb_printf (fp
, " %s mask 0x%s", exp_string
.get (),
9901 phex (hw_wp_mask
, sizeof (CORE_ADDR
)));
9902 print_recreate_thread (fp
);
9905 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
9908 is_masked_watchpoint (const struct breakpoint
*b
)
9910 return dynamic_cast<const masked_watchpoint
*> (b
) != nullptr;
9913 /* accessflag: hw_write: watch write,
9914 hw_read: watch read,
9915 hw_access: watch access (read or write) */
9917 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
9918 bool just_location
, bool internal
)
9920 struct breakpoint
*scope_breakpoint
= NULL
;
9921 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
9922 struct value
*result
;
9923 int saved_bitpos
= 0, saved_bitsize
= 0;
9924 const char *exp_start
= NULL
;
9925 const char *exp_end
= NULL
;
9926 const char *tok
, *end_tok
;
9928 const char *cond_start
= NULL
;
9929 const char *cond_end
= NULL
;
9930 enum bptype bp_type
;
9932 /* Flag to indicate whether we are going to use masks for
9933 the hardware watchpoint. */
9934 bool use_mask
= false;
9938 /* Make sure that we actually have parameters to parse. */
9939 if (arg
!= NULL
&& arg
[0] != '\0')
9941 const char *value_start
;
9943 exp_end
= arg
+ strlen (arg
);
9945 /* Look for "parameter value" pairs at the end
9946 of the arguments string. */
9947 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
9949 /* Skip whitespace at the end of the argument list. */
9950 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9953 /* Find the beginning of the last token.
9954 This is the value of the parameter. */
9955 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9957 value_start
= tok
+ 1;
9959 /* Skip whitespace. */
9960 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
9965 /* Find the beginning of the second to last token.
9966 This is the parameter itself. */
9967 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
9970 toklen
= end_tok
- tok
+ 1;
9972 if (toklen
== 6 && startswith (tok
, "thread"))
9974 struct thread_info
*thr
;
9975 /* At this point we've found a "thread" token, which means
9976 the user is trying to set a watchpoint that triggers
9977 only in a specific thread. */
9981 error(_("You can specify only one thread."));
9983 /* Extract the thread ID from the next token. */
9984 thr
= parse_thread_id (value_start
, &endp
);
9986 /* Check if the user provided a valid thread ID. */
9987 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
9988 invalid_thread_id_error (value_start
);
9990 thread
= thr
->global_num
;
9992 else if (toklen
== 4 && startswith (tok
, "task"))
9996 task
= strtol (value_start
, &tmp
, 0);
9997 if (tmp
== value_start
)
9998 error (_("Junk after task keyword."));
9999 if (!valid_task_id (task
))
10000 error (_("Unknown task %d."), task
);
10002 else if (toklen
== 4 && startswith (tok
, "mask"))
10004 /* We've found a "mask" token, which means the user wants to
10005 create a hardware watchpoint that is going to have the mask
10007 struct value
*mask_value
, *mark
;
10010 error(_("You can specify only one mask."));
10012 use_mask
= just_location
= true;
10014 mark
= value_mark ();
10015 mask_value
= parse_to_comma_and_eval (&value_start
);
10016 mask
= value_as_address (mask_value
);
10017 value_free_to_mark (mark
);
10020 /* We didn't recognize what we found. We should stop here. */
10023 /* Truncate the string and get rid of the "parameter value" pair before
10024 the arguments string is parsed by the parse_exp_1 function. */
10031 /* Parse the rest of the arguments. From here on out, everything
10032 is in terms of a newly allocated string instead of the original
10034 std::string
expression (arg
, exp_end
- arg
);
10035 exp_start
= arg
= expression
.c_str ();
10036 innermost_block_tracker tracker
;
10037 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10039 /* Remove trailing whitespace from the expression before saving it.
10040 This makes the eventual display of the expression string a bit
10042 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10045 /* Checking if the expression is not constant. */
10046 if (watchpoint_exp_is_const (exp
.get ()))
10050 len
= exp_end
- exp_start
;
10051 while (len
> 0 && isspace (exp_start
[len
- 1]))
10053 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10056 exp_valid_block
= tracker
.block ();
10057 struct value
*mark
= value_mark ();
10058 struct value
*val_as_value
= nullptr;
10059 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10062 if (val_as_value
!= NULL
&& just_location
)
10064 saved_bitpos
= value_bitpos (val_as_value
);
10065 saved_bitsize
= value_bitsize (val_as_value
);
10073 exp_valid_block
= NULL
;
10074 val
= release_value (value_addr (result
));
10075 value_free_to_mark (mark
);
10079 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10082 error (_("This target does not support masked watchpoints."));
10083 else if (ret
== -2)
10084 error (_("Invalid mask or memory region."));
10087 else if (val_as_value
!= NULL
)
10088 val
= release_value (val_as_value
);
10090 tok
= skip_spaces (arg
);
10091 end_tok
= skip_to_space (tok
);
10093 toklen
= end_tok
- tok
;
10094 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10096 tok
= cond_start
= end_tok
+ 1;
10097 innermost_block_tracker if_tracker
;
10098 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10100 /* The watchpoint expression may not be local, but the condition
10101 may still be. E.g.: `watch global if local > 0'. */
10102 cond_exp_valid_block
= if_tracker
.block ();
10107 error (_("Junk at end of command."));
10109 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10111 /* Save this because create_internal_breakpoint below invalidates
10113 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10115 /* If the expression is "local", then set up a "watchpoint scope"
10116 breakpoint at the point where we've left the scope of the watchpoint
10117 expression. Create the scope breakpoint before the watchpoint, so
10118 that we will encounter it first in bpstat_stop_status. */
10119 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10121 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10123 if (frame_id_p (caller_frame_id
))
10125 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10126 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10129 = create_internal_breakpoint (caller_arch
, caller_pc
,
10130 bp_watchpoint_scope
);
10132 /* create_internal_breakpoint could invalidate WP_FRAME. */
10135 scope_breakpoint
->enable_state
= bp_enabled
;
10137 /* Automatically delete the breakpoint when it hits. */
10138 scope_breakpoint
->disposition
= disp_del
;
10140 /* Only break in the proper frame (help with recursion). */
10141 scope_breakpoint
->frame_id
= caller_frame_id
;
10143 /* Set the address at which we will stop. */
10144 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10145 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10146 scope_breakpoint
->loc
->address
10147 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10148 scope_breakpoint
->loc
->requested_address
,
10149 scope_breakpoint
->type
);
10153 /* Now set up the breakpoint. We create all watchpoints as hardware
10154 watchpoints here even if hardware watchpoints are turned off, a call
10155 to update_watchpoint later in this function will cause the type to
10156 drop back to bp_watchpoint (software watchpoint) if required. */
10158 if (accessflag
== hw_read
)
10159 bp_type
= bp_read_watchpoint
;
10160 else if (accessflag
== hw_access
)
10161 bp_type
= bp_access_watchpoint
;
10163 bp_type
= bp_hardware_watchpoint
;
10165 std::unique_ptr
<watchpoint
> w
;
10167 w
.reset (new masked_watchpoint ());
10169 w
.reset (new watchpoint ());
10170 init_raw_breakpoint_without_location (w
.get (), nullptr, bp_type
);
10172 w
->thread
= thread
;
10174 w
->disposition
= disp_donttouch
;
10175 w
->pspace
= current_program_space
;
10176 w
->exp
= std::move (exp
);
10177 w
->exp_valid_block
= exp_valid_block
;
10178 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10181 struct type
*t
= value_type (val
.get ());
10182 CORE_ADDR addr
= value_as_address (val
.get ());
10184 w
->exp_string_reparse
10185 = current_language
->watch_location_expression (t
, addr
);
10187 w
->exp_string
= xstrprintf ("-location %.*s",
10188 (int) (exp_end
- exp_start
), exp_start
);
10191 w
->exp_string
.reset (savestring (exp_start
, exp_end
- exp_start
));
10195 w
->hw_wp_mask
= mask
;
10200 w
->val_bitpos
= saved_bitpos
;
10201 w
->val_bitsize
= saved_bitsize
;
10202 w
->val_valid
= true;
10206 w
->cond_string
.reset (savestring (cond_start
, cond_end
- cond_start
));
10208 w
->cond_string
= 0;
10210 if (frame_id_p (watchpoint_frame
))
10212 w
->watchpoint_frame
= watchpoint_frame
;
10213 w
->watchpoint_thread
= inferior_ptid
;
10217 w
->watchpoint_frame
= null_frame_id
;
10218 w
->watchpoint_thread
= null_ptid
;
10221 if (scope_breakpoint
!= NULL
)
10223 /* The scope breakpoint is related to the watchpoint. We will
10224 need to act on them together. */
10225 w
->related_breakpoint
= scope_breakpoint
;
10226 scope_breakpoint
->related_breakpoint
= w
.get ();
10229 if (!just_location
)
10230 value_free_to_mark (mark
);
10232 /* Finally update the new watchpoint. This creates the locations
10233 that should be inserted. */
10234 update_watchpoint (w
.get (), 1);
10236 install_breakpoint (internal
, std::move (w
), 1);
10239 /* Return count of debug registers needed to watch the given expression.
10240 If the watchpoint cannot be handled in hardware return zero. */
10243 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10245 int found_memory_cnt
= 0;
10247 /* Did the user specifically forbid us to use hardware watchpoints? */
10248 if (!can_use_hw_watchpoints
)
10251 gdb_assert (!vals
.empty ());
10252 struct value
*head
= vals
[0].get ();
10254 /* Make sure that the value of the expression depends only upon
10255 memory contents, and values computed from them within GDB. If we
10256 find any register references or function calls, we can't use a
10257 hardware watchpoint.
10259 The idea here is that evaluating an expression generates a series
10260 of values, one holding the value of every subexpression. (The
10261 expression a*b+c has five subexpressions: a, b, a*b, c, and
10262 a*b+c.) GDB's values hold almost enough information to establish
10263 the criteria given above --- they identify memory lvalues,
10264 register lvalues, computed values, etcetera. So we can evaluate
10265 the expression, and then scan the chain of values that leaves
10266 behind to decide whether we can detect any possible change to the
10267 expression's final value using only hardware watchpoints.
10269 However, I don't think that the values returned by inferior
10270 function calls are special in any way. So this function may not
10271 notice that an expression involving an inferior function call
10272 can't be watched with hardware watchpoints. FIXME. */
10273 for (const value_ref_ptr
&iter
: vals
)
10275 struct value
*v
= iter
.get ();
10277 if (VALUE_LVAL (v
) == lval_memory
)
10279 if (v
!= head
&& value_lazy (v
))
10280 /* A lazy memory lvalue in the chain is one that GDB never
10281 needed to fetch; we either just used its address (e.g.,
10282 `a' in `a.b') or we never needed it at all (e.g., `a'
10283 in `a,b'). This doesn't apply to HEAD; if that is
10284 lazy then it was not readable, but watch it anyway. */
10288 /* Ahh, memory we actually used! Check if we can cover
10289 it with hardware watchpoints. */
10290 struct type
*vtype
= check_typedef (value_type (v
));
10292 /* We only watch structs and arrays if user asked for it
10293 explicitly, never if they just happen to appear in a
10294 middle of some value chain. */
10296 || (vtype
->code () != TYPE_CODE_STRUCT
10297 && vtype
->code () != TYPE_CODE_ARRAY
))
10299 CORE_ADDR vaddr
= value_address (v
);
10303 len
= (target_exact_watchpoints
10304 && is_scalar_type_recursive (vtype
))?
10305 1 : TYPE_LENGTH (value_type (v
));
10307 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10311 found_memory_cnt
+= num_regs
;
10315 else if (VALUE_LVAL (v
) != not_lval
10316 && deprecated_value_modifiable (v
) == 0)
10317 return 0; /* These are values from the history (e.g., $1). */
10318 else if (VALUE_LVAL (v
) == lval_register
)
10319 return 0; /* Cannot watch a register with a HW watchpoint. */
10322 /* The expression itself looks suitable for using a hardware
10323 watchpoint, but give the target machine a chance to reject it. */
10324 return found_memory_cnt
;
10328 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10330 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10333 /* Options for the watch, awatch, and rwatch commands. */
10335 struct watch_options
10337 /* For -location. */
10338 bool location
= false;
10341 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10343 Historically GDB always accepted both '-location' and '-l' flags for
10344 these commands (both flags being synonyms). When converting to the
10345 newer option scheme only '-location' is added here. That's fine (for
10346 backward compatibility) as any non-ambiguous prefix of a flag will be
10347 accepted, so '-l', '-loc', are now all accepted.
10349 What this means is that, if in the future, we add any new flag here
10350 that starts with '-l' then this will break backward compatibility, so
10351 please, don't do that! */
10353 static const gdb::option::option_def watch_option_defs
[] = {
10354 gdb::option::flag_option_def
<watch_options
> {
10356 [] (watch_options
*opt
) { return &opt
->location
; },
10358 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10359 -l can be used as a short form of -location."),
10363 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10366 static gdb::option::option_def_group
10367 make_watch_options_def_group (watch_options
*opts
)
10369 return {{watch_option_defs
}, opts
};
10372 /* A helper function that looks for the "-location" argument and then
10373 calls watch_command_1. */
10376 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10378 watch_options opts
;
10379 auto grp
= make_watch_options_def_group (&opts
);
10380 gdb::option::process_options
10381 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
10382 if (arg
!= nullptr && *arg
== '\0')
10385 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
10388 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10390 watch_command_completer (struct cmd_list_element
*ignore
,
10391 completion_tracker
&tracker
,
10392 const char *text
, const char * /*word*/)
10394 const auto group
= make_watch_options_def_group (nullptr);
10395 if (gdb::option::complete_options
10396 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
10399 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
10400 expression_completer (ignore
, tracker
, text
, word
);
10404 watch_command (const char *arg
, int from_tty
)
10406 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10410 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10412 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10416 rwatch_command (const char *arg
, int from_tty
)
10418 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10422 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10424 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10428 awatch_command (const char *arg
, int from_tty
)
10430 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10434 /* Data for the FSM that manages the until(location)/advance commands
10435 in infcmd.c. Here because it uses the mechanisms of
10438 struct until_break_fsm
: public thread_fsm
10440 /* The thread that was current when the command was executed. */
10443 /* The breakpoint set at the return address in the caller frame,
10444 plus breakpoints at all the destination locations. */
10445 std::vector
<breakpoint_up
> breakpoints
;
10447 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10448 std::vector
<breakpoint_up
> &&breakpoints
)
10449 : thread_fsm (cmd_interp
),
10451 breakpoints (std::move (breakpoints
))
10455 void clean_up (struct thread_info
*thread
) override
;
10456 bool should_stop (struct thread_info
*thread
) override
;
10457 enum async_reply_reason
do_async_reply_reason () override
;
10460 /* Implementation of the 'should_stop' FSM method for the
10461 until(location)/advance commands. */
10464 until_break_fsm::should_stop (struct thread_info
*tp
)
10466 for (const breakpoint_up
&bp
: breakpoints
)
10467 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10468 bp
.get ()) != NULL
)
10477 /* Implementation of the 'clean_up' FSM method for the
10478 until(location)/advance commands. */
10481 until_break_fsm::clean_up (struct thread_info
*)
10483 /* Clean up our temporary breakpoints. */
10484 breakpoints
.clear ();
10485 delete_longjmp_breakpoint (thread
);
10488 /* Implementation of the 'async_reply_reason' FSM method for the
10489 until(location)/advance commands. */
10491 enum async_reply_reason
10492 until_break_fsm::do_async_reply_reason ()
10494 return EXEC_ASYNC_LOCATION_REACHED
;
10498 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10500 struct frame_info
*frame
;
10501 struct gdbarch
*frame_gdbarch
;
10502 struct frame_id stack_frame_id
;
10503 struct frame_id caller_frame_id
;
10505 struct thread_info
*tp
;
10507 clear_proceed_status (0);
10509 /* Set a breakpoint where the user wants it and at return from
10512 event_location_up location
= string_to_event_location (&arg
, current_language
);
10514 std::vector
<symtab_and_line
> sals
10515 = (last_displayed_sal_is_valid ()
10516 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10517 get_last_displayed_symtab (),
10518 get_last_displayed_line ())
10519 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
10523 error (_("Couldn't get information on specified line."));
10526 error (_("Junk at end of arguments."));
10528 tp
= inferior_thread ();
10529 thread
= tp
->global_num
;
10531 /* Note linespec handling above invalidates the frame chain.
10532 Installing a breakpoint also invalidates the frame chain (as it
10533 may need to switch threads), so do any frame handling before
10536 frame
= get_selected_frame (NULL
);
10537 frame_gdbarch
= get_frame_arch (frame
);
10538 stack_frame_id
= get_stack_frame_id (frame
);
10539 caller_frame_id
= frame_unwind_caller_id (frame
);
10541 /* Keep within the current frame, or in frames called by the current
10544 std::vector
<breakpoint_up
> breakpoints
;
10546 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
10548 if (frame_id_p (caller_frame_id
))
10550 struct symtab_and_line sal2
;
10551 struct gdbarch
*caller_gdbarch
;
10553 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
10554 sal2
.pc
= frame_unwind_caller_pc (frame
);
10555 caller_gdbarch
= frame_unwind_caller_arch (frame
);
10557 breakpoint_up caller_breakpoint
10558 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
10559 caller_frame_id
, bp_until
);
10560 breakpoints
.emplace_back (std::move (caller_breakpoint
));
10562 set_longjmp_breakpoint (tp
, caller_frame_id
);
10563 lj_deleter
.emplace (thread
);
10566 /* set_momentary_breakpoint could invalidate FRAME. */
10569 /* If the user told us to continue until a specified location, we
10570 don't specify a frame at which we need to stop. Otherwise,
10571 specify the selected frame, because we want to stop only at the
10572 very same frame. */
10573 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
10575 for (symtab_and_line
&sal
: sals
)
10577 resolve_sal_pc (&sal
);
10579 breakpoint_up location_breakpoint
10580 = set_momentary_breakpoint (frame_gdbarch
, sal
,
10581 stop_frame_id
, bp_until
);
10582 breakpoints
.emplace_back (std::move (location_breakpoint
));
10586 (std::unique_ptr
<thread_fsm
>
10587 (new until_break_fsm (command_interp (), tp
->global_num
,
10588 std::move (breakpoints
))));
10591 lj_deleter
->release ();
10593 proceed (-1, GDB_SIGNAL_DEFAULT
);
10597 init_ada_exception_breakpoint (struct breakpoint
*b
,
10598 struct gdbarch
*gdbarch
,
10599 struct symtab_and_line sal
,
10600 const char *addr_string
,
10607 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
10609 loc_gdbarch
= gdbarch
;
10611 describe_other_breakpoints (loc_gdbarch
,
10612 sal
.pspace
, sal
.pc
, sal
.section
, -1);
10613 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
10614 version for exception catchpoints, because two catchpoints
10615 used for different exception names will use the same address.
10616 In this case, a "breakpoint ... also set at..." warning is
10617 unproductive. Besides, the warning phrasing is also a bit
10618 inappropriate, we should use the word catchpoint, and tell
10619 the user what type of catchpoint it is. The above is good
10620 enough for now, though. */
10623 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
);
10625 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
10626 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
10627 b
->location
= string_to_event_location (&addr_string
,
10628 language_def (language_ada
));
10629 b
->language
= language_ada
;
10634 /* Compare two breakpoints and return a strcmp-like result. */
10637 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
10639 uintptr_t ua
= (uintptr_t) a
;
10640 uintptr_t ub
= (uintptr_t) b
;
10642 if (a
->number
< b
->number
)
10644 else if (a
->number
> b
->number
)
10647 /* Now sort by address, in case we see, e..g, two breakpoints with
10651 return ua
> ub
? 1 : 0;
10654 /* Delete breakpoints by address or line. */
10657 clear_command (const char *arg
, int from_tty
)
10661 std::vector
<symtab_and_line
> decoded_sals
;
10662 symtab_and_line last_sal
;
10663 gdb::array_view
<symtab_and_line
> sals
;
10667 = decode_line_with_current_source (arg
,
10668 (DECODE_LINE_FUNFIRSTLINE
10669 | DECODE_LINE_LIST_MODE
));
10671 sals
= decoded_sals
;
10675 /* Set sal's line, symtab, pc, and pspace to the values
10676 corresponding to the last call to print_frame_info. If the
10677 codepoint is not valid, this will set all the fields to 0. */
10678 last_sal
= get_last_displayed_sal ();
10679 if (last_sal
.symtab
== 0)
10680 error (_("No source file specified."));
10686 /* We don't call resolve_sal_pc here. That's not as bad as it
10687 seems, because all existing breakpoints typically have both
10688 file/line and pc set. So, if clear is given file/line, we can
10689 match this to existing breakpoint without obtaining pc at all.
10691 We only support clearing given the address explicitly
10692 present in breakpoint table. Say, we've set breakpoint
10693 at file:line. There were several PC values for that file:line,
10694 due to optimization, all in one block.
10696 We've picked one PC value. If "clear" is issued with another
10697 PC corresponding to the same file:line, the breakpoint won't
10698 be cleared. We probably can still clear the breakpoint, but
10699 since the other PC value is never presented to user, user
10700 can only find it by guessing, and it does not seem important
10701 to support that. */
10703 /* For each line spec given, delete bps which correspond to it. Do
10704 it in two passes, solely to preserve the current behavior that
10705 from_tty is forced true if we delete more than one
10708 std::vector
<struct breakpoint
*> found
;
10709 for (const auto &sal
: sals
)
10711 const char *sal_fullname
;
10713 /* If exact pc given, clear bpts at that pc.
10714 If line given (pc == 0), clear all bpts on specified line.
10715 If defaulting, clear all bpts on default line
10718 defaulting sal.pc != 0 tests to do
10723 1 0 <can't happen> */
10725 sal_fullname
= (sal
.symtab
== NULL
10726 ? NULL
: symtab_to_fullname (sal
.symtab
));
10728 /* Find all matching breakpoints and add them to 'found'. */
10729 for (breakpoint
*b
: all_breakpoints ())
10732 /* Are we going to delete b? */
10733 if (b
->type
!= bp_none
&& !is_watchpoint (b
)
10734 && user_breakpoint_p (b
))
10736 for (bp_location
*loc
: b
->locations ())
10738 /* If the user specified file:line, don't allow a PC
10739 match. This matches historical gdb behavior. */
10740 int pc_match
= (!sal
.explicit_line
10742 && (loc
->pspace
== sal
.pspace
)
10743 && (loc
->address
== sal
.pc
)
10744 && (!section_is_overlay (loc
->section
)
10745 || loc
->section
== sal
.section
));
10746 int line_match
= 0;
10748 if ((default_match
|| sal
.explicit_line
)
10749 && loc
->symtab
!= NULL
10750 && sal_fullname
!= NULL
10751 && sal
.pspace
== loc
->pspace
10752 && loc
->line_number
== sal
.line
10753 && filename_cmp (symtab_to_fullname (loc
->symtab
),
10754 sal_fullname
) == 0)
10757 if (pc_match
|| line_match
)
10766 found
.push_back (b
);
10770 /* Now go thru the 'found' chain and delete them. */
10771 if (found
.empty ())
10774 error (_("No breakpoint at %s."), arg
);
10776 error (_("No breakpoint at this line."));
10779 /* Remove duplicates from the vec. */
10780 std::sort (found
.begin (), found
.end (),
10781 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10783 return compare_breakpoints (bp_a
, bp_b
) < 0;
10785 found
.erase (std::unique (found
.begin (), found
.end (),
10786 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
10788 return compare_breakpoints (bp_a
, bp_b
) == 0;
10792 if (found
.size () > 1)
10793 from_tty
= 1; /* Always report if deleted more than one. */
10796 if (found
.size () == 1)
10797 gdb_printf (_("Deleted breakpoint "));
10799 gdb_printf (_("Deleted breakpoints "));
10802 for (breakpoint
*iter
: found
)
10805 gdb_printf ("%d ", iter
->number
);
10806 delete_breakpoint (iter
);
10812 /* Delete breakpoint in BS if they are `delete' breakpoints and
10813 all breakpoints that are marked for deletion, whether hit or not.
10814 This is called after any breakpoint is hit, or after errors. */
10817 breakpoint_auto_delete (bpstat
*bs
)
10819 for (; bs
; bs
= bs
->next
)
10820 if (bs
->breakpoint_at
10821 && bs
->breakpoint_at
->disposition
== disp_del
10823 delete_breakpoint (bs
->breakpoint_at
);
10825 for (breakpoint
*b
: all_breakpoints_safe ())
10826 if (b
->disposition
== disp_del_at_next_stop
)
10827 delete_breakpoint (b
);
10830 /* A comparison function for bp_location AP and BP being interfaced to
10831 std::sort. Sort elements primarily by their ADDRESS (no matter what
10832 bl_address_is_meaningful says), secondarily by ordering first
10833 permanent elements and terciarily just ensuring the array is sorted
10834 stable way despite std::sort being an unstable algorithm. */
10837 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
10839 if (a
->address
!= b
->address
)
10840 return a
->address
< b
->address
;
10842 /* Sort locations at the same address by their pspace number, keeping
10843 locations of the same inferior (in a multi-inferior environment)
10846 if (a
->pspace
->num
!= b
->pspace
->num
)
10847 return a
->pspace
->num
< b
->pspace
->num
;
10849 /* Sort permanent breakpoints first. */
10850 if (a
->permanent
!= b
->permanent
)
10851 return a
->permanent
> b
->permanent
;
10853 /* Sort by type in order to make duplicate determination easier.
10854 See update_global_location_list. This is kept in sync with
10855 breakpoint_locations_match. */
10856 if (a
->loc_type
< b
->loc_type
)
10859 /* Likewise, for range-breakpoints, sort by length. */
10860 if (a
->loc_type
== bp_loc_hardware_breakpoint
10861 && b
->loc_type
== bp_loc_hardware_breakpoint
10862 && a
->length
< b
->length
)
10865 /* Make the internal GDB representation stable across GDB runs
10866 where A and B memory inside GDB can differ. Breakpoint locations of
10867 the same type at the same address can be sorted in arbitrary order. */
10869 if (a
->owner
->number
!= b
->owner
->number
)
10870 return a
->owner
->number
< b
->owner
->number
;
10875 /* Set bp_locations_placed_address_before_address_max and
10876 bp_locations_shadow_len_after_address_max according to the current
10877 content of the bp_locations array. */
10880 bp_locations_target_extensions_update (void)
10882 bp_locations_placed_address_before_address_max
= 0;
10883 bp_locations_shadow_len_after_address_max
= 0;
10885 for (bp_location
*bl
: all_bp_locations ())
10887 CORE_ADDR start
, end
, addr
;
10889 if (!bp_location_has_shadow (bl
))
10892 start
= bl
->target_info
.placed_address
;
10893 end
= start
+ bl
->target_info
.shadow_len
;
10895 gdb_assert (bl
->address
>= start
);
10896 addr
= bl
->address
- start
;
10897 if (addr
> bp_locations_placed_address_before_address_max
)
10898 bp_locations_placed_address_before_address_max
= addr
;
10900 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
10902 gdb_assert (bl
->address
< end
);
10903 addr
= end
- bl
->address
;
10904 if (addr
> bp_locations_shadow_len_after_address_max
)
10905 bp_locations_shadow_len_after_address_max
= addr
;
10909 /* Download tracepoint locations if they haven't been. */
10912 download_tracepoint_locations (void)
10914 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
10916 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
10918 for (breakpoint
*b
: all_tracepoints ())
10920 struct tracepoint
*t
;
10921 int bp_location_downloaded
= 0;
10923 if ((b
->type
== bp_fast_tracepoint
10924 ? !may_insert_fast_tracepoints
10925 : !may_insert_tracepoints
))
10928 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
10930 if (target_can_download_tracepoint ())
10931 can_download_tracepoint
= TRIBOOL_TRUE
;
10933 can_download_tracepoint
= TRIBOOL_FALSE
;
10936 if (can_download_tracepoint
== TRIBOOL_FALSE
)
10939 for (bp_location
*bl
: b
->locations ())
10941 /* In tracepoint, locations are _never_ duplicated, so
10942 should_be_inserted is equivalent to
10943 unduplicated_should_be_inserted. */
10944 if (!should_be_inserted (bl
) || bl
->inserted
)
10947 switch_to_program_space_and_thread (bl
->pspace
);
10949 target_download_tracepoint (bl
);
10952 bp_location_downloaded
= 1;
10954 t
= (struct tracepoint
*) b
;
10955 t
->number_on_target
= b
->number
;
10956 if (bp_location_downloaded
)
10957 gdb::observers::breakpoint_modified
.notify (b
);
10961 /* Swap the insertion/duplication state between two locations. */
10964 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
10966 const int left_inserted
= left
->inserted
;
10967 const int left_duplicate
= left
->duplicate
;
10968 const int left_needs_update
= left
->needs_update
;
10969 const struct bp_target_info left_target_info
= left
->target_info
;
10971 /* Locations of tracepoints can never be duplicated. */
10972 if (is_tracepoint (left
->owner
))
10973 gdb_assert (!left
->duplicate
);
10974 if (is_tracepoint (right
->owner
))
10975 gdb_assert (!right
->duplicate
);
10977 left
->inserted
= right
->inserted
;
10978 left
->duplicate
= right
->duplicate
;
10979 left
->needs_update
= right
->needs_update
;
10980 left
->target_info
= right
->target_info
;
10981 right
->inserted
= left_inserted
;
10982 right
->duplicate
= left_duplicate
;
10983 right
->needs_update
= left_needs_update
;
10984 right
->target_info
= left_target_info
;
10987 /* Force the re-insertion of the locations at ADDRESS. This is called
10988 once a new/deleted/modified duplicate location is found and we are evaluating
10989 conditions on the target's side. Such conditions need to be updated on
10993 force_breakpoint_reinsertion (struct bp_location
*bl
)
10995 CORE_ADDR address
= 0;
10998 address
= bl
->address
;
10999 pspace_num
= bl
->pspace
->num
;
11001 /* This is only meaningful if the target is
11002 evaluating conditions and if the user has
11003 opted for condition evaluation on the target's
11005 if (gdb_evaluates_breakpoint_condition_p ()
11006 || !target_supports_evaluation_of_breakpoint_conditions ())
11009 /* Flag all breakpoint locations with this address and
11010 the same program space as the location
11011 as "its condition has changed". We need to
11012 update the conditions on the target's side. */
11013 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
11015 if (!is_breakpoint (loc
->owner
)
11016 || pspace_num
!= loc
->pspace
->num
)
11019 /* Flag the location appropriately. We use a different state to
11020 let everyone know that we already updated the set of locations
11021 with addr bl->address and program space bl->pspace. This is so
11022 we don't have to keep calling these functions just to mark locations
11023 that have already been marked. */
11024 loc
->condition_changed
= condition_updated
;
11026 /* Free the agent expression bytecode as well. We will compute
11028 loc
->cond_bytecode
.reset ();
11032 /* Called whether new breakpoints are created, or existing breakpoints
11033 deleted, to update the global location list and recompute which
11034 locations are duplicate of which.
11036 The INSERT_MODE flag determines whether locations may not, may, or
11037 shall be inserted now. See 'enum ugll_insert_mode' for more
11041 update_global_location_list (enum ugll_insert_mode insert_mode
)
11043 /* Last breakpoint location address that was marked for update. */
11044 CORE_ADDR last_addr
= 0;
11045 /* Last breakpoint location program space that was marked for update. */
11046 int last_pspace_num
= -1;
11048 /* Used in the duplicates detection below. When iterating over all
11049 bp_locations, points to the first bp_location of a given address.
11050 Breakpoints and watchpoints of different types are never
11051 duplicates of each other. Keep one pointer for each type of
11052 breakpoint/watchpoint, so we only need to loop over all locations
11054 struct bp_location
*bp_loc_first
; /* breakpoint */
11055 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11056 struct bp_location
*awp_loc_first
; /* access watchpoint */
11057 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11059 /* Saved former bp_locations array which we compare against the newly
11060 built bp_locations from the current state of ALL_BREAKPOINTS. */
11061 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
11062 bp_locations
.clear ();
11064 for (breakpoint
*b
: all_breakpoints ())
11065 for (bp_location
*loc
: b
->locations ())
11066 bp_locations
.push_back (loc
);
11068 /* See if we need to "upgrade" a software breakpoint to a hardware
11069 breakpoint. Do this before deciding whether locations are
11070 duplicates. Also do this before sorting because sorting order
11071 depends on location type. */
11072 for (bp_location
*loc
: bp_locations
)
11073 if (!loc
->inserted
&& should_be_inserted (loc
))
11074 handle_automatic_hardware_breakpoints (loc
);
11076 std::sort (bp_locations
.begin (), bp_locations
.end (),
11077 bp_location_is_less_than
);
11079 bp_locations_target_extensions_update ();
11081 /* Identify bp_location instances that are no longer present in the
11082 new list, and therefore should be freed. Note that it's not
11083 necessary that those locations should be removed from inferior --
11084 if there's another location at the same address (previously
11085 marked as duplicate), we don't need to remove/insert the
11088 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11089 and former bp_location array state respectively. */
11092 for (bp_location
*old_loc
: old_locations
)
11094 /* Tells if 'old_loc' is found among the new locations. If
11095 not, we have to free it. */
11096 int found_object
= 0;
11097 /* Tells if the location should remain inserted in the target. */
11098 int keep_in_target
= 0;
11101 /* Skip LOCP entries which will definitely never be needed.
11102 Stop either at or being the one matching OLD_LOC. */
11103 while (loc_i
< bp_locations
.size ()
11104 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11107 for (size_t loc2_i
= loc_i
;
11108 (loc2_i
< bp_locations
.size ()
11109 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11112 /* Check if this is a new/duplicated location or a duplicated
11113 location that had its condition modified. If so, we want to send
11114 its condition to the target if evaluation of conditions is taking
11116 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11117 && (last_addr
!= old_loc
->address
11118 || last_pspace_num
!= old_loc
->pspace
->num
))
11120 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11121 last_pspace_num
= old_loc
->pspace
->num
;
11124 if (bp_locations
[loc2_i
] == old_loc
)
11128 /* We have already handled this address, update it so that we don't
11129 have to go through updates again. */
11130 last_addr
= old_loc
->address
;
11132 /* Target-side condition evaluation: Handle deleted locations. */
11134 force_breakpoint_reinsertion (old_loc
);
11136 /* If this location is no longer present, and inserted, look if
11137 there's maybe a new location at the same address. If so,
11138 mark that one inserted, and don't remove this one. This is
11139 needed so that we don't have a time window where a breakpoint
11140 at certain location is not inserted. */
11142 if (old_loc
->inserted
)
11144 /* If the location is inserted now, we might have to remove
11147 if (found_object
&& should_be_inserted (old_loc
))
11149 /* The location is still present in the location list,
11150 and still should be inserted. Don't do anything. */
11151 keep_in_target
= 1;
11155 /* This location still exists, but it won't be kept in the
11156 target since it may have been disabled. We proceed to
11157 remove its target-side condition. */
11159 /* The location is either no longer present, or got
11160 disabled. See if there's another location at the
11161 same address, in which case we don't need to remove
11162 this one from the target. */
11164 /* OLD_LOC comes from existing struct breakpoint. */
11165 if (bl_address_is_meaningful (old_loc
))
11167 for (size_t loc2_i
= loc_i
;
11168 (loc2_i
< bp_locations
.size ()
11169 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11172 bp_location
*loc2
= bp_locations
[loc2_i
];
11174 if (loc2
== old_loc
)
11177 if (breakpoint_locations_match (loc2
, old_loc
))
11179 /* Read watchpoint locations are switched to
11180 access watchpoints, if the former are not
11181 supported, but the latter are. */
11182 if (is_hardware_watchpoint (old_loc
->owner
))
11184 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11185 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11188 /* loc2 is a duplicated location. We need to check
11189 if it should be inserted in case it will be
11191 if (unduplicated_should_be_inserted (loc2
))
11193 swap_insertion (old_loc
, loc2
);
11194 keep_in_target
= 1;
11202 if (!keep_in_target
)
11204 if (remove_breakpoint (old_loc
))
11206 /* This is just about all we can do. We could keep
11207 this location on the global list, and try to
11208 remove it next time, but there's no particular
11209 reason why we will succeed next time.
11211 Note that at this point, old_loc->owner is still
11212 valid, as delete_breakpoint frees the breakpoint
11213 only after calling us. */
11214 gdb_printf (_("warning: Error removing "
11215 "breakpoint %d\n"),
11216 old_loc
->owner
->number
);
11224 if (removed
&& target_is_non_stop_p ()
11225 && need_moribund_for_location_type (old_loc
))
11227 /* This location was removed from the target. In
11228 non-stop mode, a race condition is possible where
11229 we've removed a breakpoint, but stop events for that
11230 breakpoint are already queued and will arrive later.
11231 We apply an heuristic to be able to distinguish such
11232 SIGTRAPs from other random SIGTRAPs: we keep this
11233 breakpoint location for a bit, and will retire it
11234 after we see some number of events. The theory here
11235 is that reporting of events should, "on the average",
11236 be fair, so after a while we'll see events from all
11237 threads that have anything of interest, and no longer
11238 need to keep this breakpoint location around. We
11239 don't hold locations forever so to reduce chances of
11240 mistaking a non-breakpoint SIGTRAP for a breakpoint
11243 The heuristic failing can be disastrous on
11244 decr_pc_after_break targets.
11246 On decr_pc_after_break targets, like e.g., x86-linux,
11247 if we fail to recognize a late breakpoint SIGTRAP,
11248 because events_till_retirement has reached 0 too
11249 soon, we'll fail to do the PC adjustment, and report
11250 a random SIGTRAP to the user. When the user resumes
11251 the inferior, it will most likely immediately crash
11252 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11253 corrupted, because of being resumed e.g., in the
11254 middle of a multi-byte instruction, or skipped a
11255 one-byte instruction. This was actually seen happen
11256 on native x86-linux, and should be less rare on
11257 targets that do not support new thread events, like
11258 remote, due to the heuristic depending on
11261 Mistaking a random SIGTRAP for a breakpoint trap
11262 causes similar symptoms (PC adjustment applied when
11263 it shouldn't), but then again, playing with SIGTRAPs
11264 behind the debugger's back is asking for trouble.
11266 Since hardware watchpoint traps are always
11267 distinguishable from other traps, so we don't need to
11268 apply keep hardware watchpoint moribund locations
11269 around. We simply always ignore hardware watchpoint
11270 traps we can no longer explain. */
11272 process_stratum_target
*proc_target
= nullptr;
11273 for (inferior
*inf
: all_inferiors ())
11274 if (inf
->pspace
== old_loc
->pspace
)
11276 proc_target
= inf
->process_target ();
11279 if (proc_target
!= nullptr)
11280 old_loc
->events_till_retirement
11281 = 3 * (thread_count (proc_target
) + 1);
11283 old_loc
->events_till_retirement
= 1;
11284 old_loc
->owner
= NULL
;
11286 moribund_locations
.push_back (old_loc
);
11290 old_loc
->owner
= NULL
;
11291 decref_bp_location (&old_loc
);
11296 /* Rescan breakpoints at the same address and section, marking the
11297 first one as "first" and any others as "duplicates". This is so
11298 that the bpt instruction is only inserted once. If we have a
11299 permanent breakpoint at the same place as BPT, make that one the
11300 official one, and the rest as duplicates. Permanent breakpoints
11301 are sorted first for the same address.
11303 Do the same for hardware watchpoints, but also considering the
11304 watchpoint's type (regular/access/read) and length. */
11306 bp_loc_first
= NULL
;
11307 wp_loc_first
= NULL
;
11308 awp_loc_first
= NULL
;
11309 rwp_loc_first
= NULL
;
11311 for (bp_location
*loc
: all_bp_locations ())
11313 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11315 struct bp_location
**loc_first_p
;
11316 breakpoint
*b
= loc
->owner
;
11318 if (!unduplicated_should_be_inserted (loc
)
11319 || !bl_address_is_meaningful (loc
)
11320 /* Don't detect duplicate for tracepoint locations because they are
11321 never duplicated. See the comments in field `duplicate' of
11322 `struct bp_location'. */
11323 || is_tracepoint (b
))
11325 /* Clear the condition modification flag. */
11326 loc
->condition_changed
= condition_unchanged
;
11330 if (b
->type
== bp_hardware_watchpoint
)
11331 loc_first_p
= &wp_loc_first
;
11332 else if (b
->type
== bp_read_watchpoint
)
11333 loc_first_p
= &rwp_loc_first
;
11334 else if (b
->type
== bp_access_watchpoint
)
11335 loc_first_p
= &awp_loc_first
;
11337 loc_first_p
= &bp_loc_first
;
11339 if (*loc_first_p
== NULL
11340 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11341 || !breakpoint_locations_match (loc
, *loc_first_p
))
11343 *loc_first_p
= loc
;
11344 loc
->duplicate
= 0;
11346 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11348 loc
->needs_update
= 1;
11349 /* Clear the condition modification flag. */
11350 loc
->condition_changed
= condition_unchanged
;
11356 /* This and the above ensure the invariant that the first location
11357 is not duplicated, and is the inserted one.
11358 All following are marked as duplicated, and are not inserted. */
11360 swap_insertion (loc
, *loc_first_p
);
11361 loc
->duplicate
= 1;
11363 /* Clear the condition modification flag. */
11364 loc
->condition_changed
= condition_unchanged
;
11367 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11369 if (insert_mode
!= UGLL_DONT_INSERT
)
11370 insert_breakpoint_locations ();
11373 /* Even though the caller told us to not insert new
11374 locations, we may still need to update conditions on the
11375 target's side of breakpoints that were already inserted
11376 if the target is evaluating breakpoint conditions. We
11377 only update conditions for locations that are marked
11379 update_inserted_breakpoint_locations ();
11383 if (insert_mode
!= UGLL_DONT_INSERT
)
11384 download_tracepoint_locations ();
11388 breakpoint_retire_moribund (void)
11390 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11392 struct bp_location
*loc
= moribund_locations
[ix
];
11393 if (--(loc
->events_till_retirement
) == 0)
11395 decref_bp_location (&loc
);
11396 unordered_remove (moribund_locations
, ix
);
11403 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
11408 update_global_location_list (insert_mode
);
11410 catch (const gdb_exception_error
&e
)
11415 /* Clear BKP from a BPS. */
11418 bpstat_remove_bp_location (bpstat
*bps
, struct breakpoint
*bpt
)
11422 for (bs
= bps
; bs
; bs
= bs
->next
)
11423 if (bs
->breakpoint_at
== bpt
)
11425 bs
->breakpoint_at
= NULL
;
11426 bs
->old_val
= NULL
;
11427 /* bs->commands will be freed later. */
11431 /* Callback for iterate_over_threads. */
11433 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
11435 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
11437 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
11441 /* Helper for breakpoint and tracepoint breakpoint->mention
11445 say_where (struct breakpoint
*b
)
11447 struct value_print_options opts
;
11449 get_user_print_options (&opts
);
11451 /* i18n: cagney/2005-02-11: Below needs to be merged into a
11453 if (b
->loc
== NULL
)
11455 /* For pending locations, the output differs slightly based
11456 on b->extra_string. If this is non-NULL, it contains either
11457 a condition or dprintf arguments. */
11458 if (b
->extra_string
== NULL
)
11460 gdb_printf (_(" (%s) pending."),
11461 event_location_to_string (b
->location
.get ()));
11463 else if (b
->type
== bp_dprintf
)
11465 gdb_printf (_(" (%s,%s) pending."),
11466 event_location_to_string (b
->location
.get ()),
11467 b
->extra_string
.get ());
11471 gdb_printf (_(" (%s %s) pending."),
11472 event_location_to_string (b
->location
.get ()),
11473 b
->extra_string
.get ());
11478 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
11479 gdb_printf (" at %ps",
11480 styled_string (address_style
.style (),
11481 paddress (b
->loc
->gdbarch
,
11482 b
->loc
->address
)));
11483 if (b
->loc
->symtab
!= NULL
)
11485 /* If there is a single location, we can print the location
11487 if (b
->loc
->next
== NULL
)
11489 const char *filename
11490 = symtab_to_filename_for_display (b
->loc
->symtab
);
11491 gdb_printf (": file %ps, line %d.",
11492 styled_string (file_name_style
.style (),
11494 b
->loc
->line_number
);
11497 /* This is not ideal, but each location may have a
11498 different file name, and this at least reflects the
11499 real situation somewhat. */
11500 gdb_printf (": %s.",
11501 event_location_to_string (b
->location
.get ()));
11506 struct bp_location
*loc
= b
->loc
;
11508 for (; loc
; loc
= loc
->next
)
11510 gdb_printf (" (%d locations)", n
);
11515 /* See breakpoint.h. */
11517 bp_location_range
breakpoint::locations ()
11519 return bp_location_range (this->loc
);
11522 struct bp_location
*
11523 breakpoint::allocate_location ()
11525 return new bp_location (this);
11528 #define internal_error_pure_virtual_called() \
11529 gdb_assert_not_reached ("pure virtual function called")
11532 breakpoint::insert_location (struct bp_location
*bl
)
11534 internal_error_pure_virtual_called ();
11538 breakpoint::remove_location (struct bp_location
*bl
,
11539 enum remove_bp_reason reason
)
11541 internal_error_pure_virtual_called ();
11545 breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11546 const address_space
*aspace
,
11548 const target_waitstatus
&ws
)
11550 internal_error_pure_virtual_called ();
11554 breakpoint::resources_needed (const struct bp_location
*bl
)
11556 internal_error_pure_virtual_called ();
11559 enum print_stop_action
11560 breakpoint::print_it (const bpstat
*bs
) const
11562 internal_error_pure_virtual_called ();
11566 breakpoint::print_mention ()
11568 internal_error_pure_virtual_called ();
11572 breakpoint::print_recreate (struct ui_file
*fp
)
11574 internal_error_pure_virtual_called ();
11577 std::vector
<symtab_and_line
>
11578 breakpoint::decode_location (struct event_location
*location
,
11579 struct program_space
*search_pspace
)
11581 internal_error_pure_virtual_called ();
11584 /* Default breakpoint_ops methods. */
11587 base_breakpoint::re_set ()
11589 /* FIXME: is this still reachable? */
11590 if (breakpoint_event_location_empty_p (this))
11592 /* Anything without a location can't be re-set. */
11593 delete_breakpoint (this);
11597 breakpoint_re_set_default (this);
11601 base_breakpoint::insert_location (struct bp_location
*bl
)
11603 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
11605 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
11606 bl
->target_info
.placed_address
= addr
;
11609 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11610 result
= target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11612 result
= target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11614 if (result
== 0 && bl
->probe
.prob
!= nullptr)
11616 /* The insertion was successful, now let's set the probe's semaphore
11618 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11625 base_breakpoint::remove_location (struct bp_location
*bl
,
11626 enum remove_bp_reason reason
)
11628 if (bl
->probe
.prob
!= nullptr)
11630 /* Let's clear the semaphore before removing the location. */
11631 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
11634 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
11635 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
11637 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
11641 base_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11642 const address_space
*aspace
,
11644 const target_waitstatus
&ws
)
11646 if (ws
.kind () != TARGET_WAITKIND_STOPPED
11647 || ws
.sig () != GDB_SIGNAL_TRAP
)
11650 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
11654 if (overlay_debugging
/* unmapped overlay section */
11655 && section_is_overlay (bl
->section
)
11656 && !section_is_mapped (bl
->section
))
11663 dprintf_breakpoint::breakpoint_hit (const struct bp_location
*bl
,
11664 const address_space
*aspace
,
11666 const target_waitstatus
&ws
)
11668 if (dprintf_style
== dprintf_style_agent
11669 && target_can_run_breakpoint_commands ())
11671 /* An agent-style dprintf never causes a stop. If we see a trap
11672 for this address it must be for a breakpoint that happens to
11673 be set at the same address. */
11677 return this->ordinary_breakpoint::breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
11681 ordinary_breakpoint::resources_needed (const struct bp_location
*bl
)
11683 gdb_assert (type
== bp_hardware_breakpoint
);
11688 enum print_stop_action
11689 ordinary_breakpoint::print_it (const bpstat
*bs
) const
11691 const struct bp_location
*bl
;
11693 struct ui_out
*uiout
= current_uiout
;
11695 bl
= bs
->bp_location_at
.get ();
11697 bp_temp
= disposition
== disp_del
;
11698 if (bl
->address
!= bl
->requested_address
)
11699 breakpoint_adjustment_warning (bl
->requested_address
,
11702 annotate_breakpoint (number
);
11703 maybe_print_thread_hit_breakpoint (uiout
);
11705 if (uiout
->is_mi_like_p ())
11707 uiout
->field_string ("reason",
11708 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11709 uiout
->field_string ("disp", bpdisp_text (disposition
));
11712 uiout
->message ("Temporary breakpoint %pF, ",
11713 signed_field ("bkptno", number
));
11715 uiout
->message ("Breakpoint %pF, ",
11716 signed_field ("bkptno", number
));
11718 return PRINT_SRC_AND_LOC
;
11722 ordinary_breakpoint::print_mention ()
11724 if (current_uiout
->is_mi_like_p ())
11729 case bp_breakpoint
:
11730 case bp_gnu_ifunc_resolver
:
11731 if (disposition
== disp_del
)
11732 gdb_printf (_("Temporary breakpoint"));
11734 gdb_printf (_("Breakpoint"));
11735 gdb_printf (_(" %d"), number
);
11736 if (type
== bp_gnu_ifunc_resolver
)
11737 gdb_printf (_(" at gnu-indirect-function resolver"));
11739 case bp_hardware_breakpoint
:
11740 gdb_printf (_("Hardware assisted breakpoint %d"), number
);
11743 gdb_printf (_("Dprintf %d"), number
);
11751 ordinary_breakpoint::print_recreate (struct ui_file
*fp
)
11753 if (type
== bp_breakpoint
&& disposition
== disp_del
)
11754 gdb_printf (fp
, "tbreak");
11755 else if (type
== bp_breakpoint
)
11756 gdb_printf (fp
, "break");
11757 else if (type
== bp_hardware_breakpoint
11758 && disposition
== disp_del
)
11759 gdb_printf (fp
, "thbreak");
11760 else if (type
== bp_hardware_breakpoint
)
11761 gdb_printf (fp
, "hbreak");
11763 internal_error (__FILE__
, __LINE__
,
11764 _("unhandled breakpoint type %d"), (int) type
);
11766 gdb_printf (fp
, " %s", event_location_to_string (location
.get ()));
11768 /* Print out extra_string if this breakpoint is pending. It might
11769 contain, for example, conditions that were set by the user. */
11770 if (loc
== NULL
&& extra_string
!= NULL
)
11771 gdb_printf (fp
, " %s", extra_string
.get ());
11773 print_recreate_thread (fp
);
11776 std::vector
<symtab_and_line
>
11777 base_breakpoint::decode_location (struct event_location
*location
,
11778 struct program_space
*search_pspace
)
11780 if (event_location_type (location
) == PROBE_LOCATION
)
11781 return bkpt_probe_decode_location (this, location
, search_pspace
);
11783 return decode_location_default (this, location
, search_pspace
);
11786 /* Virtual table for internal breakpoints. */
11789 internal_breakpoint::re_set ()
11793 /* Delete overlay event and longjmp master breakpoints; they
11794 will be reset later by breakpoint_re_set. */
11795 case bp_overlay_event
:
11796 case bp_longjmp_master
:
11797 case bp_std_terminate_master
:
11798 case bp_exception_master
:
11799 delete_breakpoint (this);
11802 /* This breakpoint is special, it's set up when the inferior
11803 starts and we really don't want to touch it. */
11804 case bp_shlib_event
:
11806 /* Like bp_shlib_event, this breakpoint type is special. Once
11807 it is set up, we do not want to touch it. */
11808 case bp_thread_event
:
11814 internal_breakpoint::check_status (bpstat
*bs
)
11816 if (type
== bp_shlib_event
)
11818 /* If requested, stop when the dynamic linker notifies GDB of
11819 events. This allows the user to get control and place
11820 breakpoints in initializer routines for dynamically loaded
11821 objects (among other things). */
11822 bs
->stop
= stop_on_solib_events
;
11823 bs
->print
= stop_on_solib_events
;
11829 enum print_stop_action
11830 internal_breakpoint::print_it (const bpstat
*bs
) const
11834 case bp_shlib_event
:
11835 /* Did we stop because the user set the stop_on_solib_events
11836 variable? (If so, we report this as a generic, "Stopped due
11837 to shlib event" message.) */
11838 print_solib_event (false);
11841 case bp_thread_event
:
11842 /* Not sure how we will get here.
11843 GDB should not stop for these breakpoints. */
11844 gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n"));
11847 case bp_overlay_event
:
11848 /* By analogy with the thread event, GDB should not stop for these. */
11849 gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n"));
11852 case bp_longjmp_master
:
11853 /* These should never be enabled. */
11854 gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
11857 case bp_std_terminate_master
:
11858 /* These should never be enabled. */
11859 gdb_printf (_("std::terminate Master Breakpoint: "
11860 "gdb should not stop!\n"));
11863 case bp_exception_master
:
11864 /* These should never be enabled. */
11865 gdb_printf (_("Exception Master Breakpoint: "
11866 "gdb should not stop!\n"));
11870 return PRINT_NOTHING
;
11874 internal_breakpoint::print_mention ()
11876 /* Nothing to mention. These breakpoints are internal. */
11879 /* Virtual table for momentary breakpoints */
11882 momentary_breakpoint::re_set ()
11884 /* Keep temporary breakpoints, which can be encountered when we step
11885 over a dlopen call and solib_add is resetting the breakpoints.
11886 Otherwise these should have been blown away via the cleanup chain
11887 or by breakpoint_init_inferior when we rerun the executable. */
11891 momentary_breakpoint::check_status (bpstat
*bs
)
11893 /* Nothing. The point of these breakpoints is causing a stop. */
11896 enum print_stop_action
11897 momentary_breakpoint::print_it (const bpstat
*bs
) const
11899 return PRINT_UNKNOWN
;
11903 momentary_breakpoint::print_mention ()
11905 /* Nothing to mention. These breakpoints are internal. */
11908 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
11910 It gets cleared already on the removal of the first one of such placed
11911 breakpoints. This is OK as they get all removed altogether. */
11913 longjmp_breakpoint::~longjmp_breakpoint ()
11915 thread_info
*tp
= find_thread_global_id (this->thread
);
11918 tp
->initiating_frame
= null_frame_id
;
11922 bkpt_probe_create_sals_from_location (struct event_location
*location
,
11923 struct linespec_result
*canonical
)
11926 struct linespec_sals lsal
;
11928 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
11930 = xstrdup (event_location_to_string (canonical
->location
.get ()));
11931 canonical
->lsals
.push_back (std::move (lsal
));
11934 static std::vector
<symtab_and_line
>
11935 bkpt_probe_decode_location (struct breakpoint
*b
,
11936 struct event_location
*location
,
11937 struct program_space
*search_pspace
)
11939 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
11941 error (_("probe not found"));
11945 /* The breakpoint_ops structure to be used in tracepoints. */
11948 tracepoint::re_set ()
11950 breakpoint_re_set_default (this);
11954 tracepoint::breakpoint_hit (const struct bp_location
*bl
,
11955 const address_space
*aspace
, CORE_ADDR bp_addr
,
11956 const target_waitstatus
&ws
)
11958 /* By definition, the inferior does not report stops at
11964 tracepoint::print_one_detail (struct ui_out
*uiout
) const
11966 if (!static_trace_marker_id
.empty ())
11968 gdb_assert (type
== bp_static_tracepoint
11969 || type
== bp_static_marker_tracepoint
);
11971 uiout
->message ("\tmarker id is %pF\n",
11972 string_field ("static-tracepoint-marker-string-id",
11973 static_trace_marker_id
.c_str ()));
11978 tracepoint::print_mention ()
11980 if (current_uiout
->is_mi_like_p ())
11985 case bp_tracepoint
:
11986 gdb_printf (_("Tracepoint"));
11987 gdb_printf (_(" %d"), number
);
11989 case bp_fast_tracepoint
:
11990 gdb_printf (_("Fast tracepoint"));
11991 gdb_printf (_(" %d"), number
);
11993 case bp_static_tracepoint
:
11994 case bp_static_marker_tracepoint
:
11995 gdb_printf (_("Static tracepoint"));
11996 gdb_printf (_(" %d"), number
);
11999 internal_error (__FILE__
, __LINE__
,
12000 _("unhandled tracepoint type %d"), (int) type
);
12007 tracepoint::print_recreate (struct ui_file
*fp
)
12009 if (type
== bp_fast_tracepoint
)
12010 gdb_printf (fp
, "ftrace");
12011 else if (type
== bp_static_tracepoint
12012 || type
== bp_static_marker_tracepoint
)
12013 gdb_printf (fp
, "strace");
12014 else if (type
== bp_tracepoint
)
12015 gdb_printf (fp
, "trace");
12017 internal_error (__FILE__
, __LINE__
,
12018 _("unhandled tracepoint type %d"), (int) type
);
12020 gdb_printf (fp
, " %s", event_location_to_string (location
.get ()));
12021 print_recreate_thread (fp
);
12024 gdb_printf (fp
, " passcount %d\n", pass_count
);
12027 std::vector
<symtab_and_line
>
12028 tracepoint::decode_location (struct event_location
*location
,
12029 struct program_space
*search_pspace
)
12031 if (event_location_type (location
) == PROBE_LOCATION
)
12032 return bkpt_probe_decode_location (this, location
, search_pspace
);
12034 return decode_location_default (this, location
, search_pspace
);
12037 /* Virtual table for tracepoints on static probes. */
12040 tracepoint_probe_create_sals_from_location
12041 (struct event_location
*location
,
12042 struct linespec_result
*canonical
)
12044 /* We use the same method for breakpoint on probes. */
12045 bkpt_probe_create_sals_from_location (location
, canonical
);
12049 dprintf_breakpoint::re_set ()
12051 breakpoint_re_set_default (this);
12053 /* extra_string should never be non-NULL for dprintf. */
12054 gdb_assert (extra_string
!= NULL
);
12056 /* 1 - connect to target 1, that can run breakpoint commands.
12057 2 - create a dprintf, which resolves fine.
12058 3 - disconnect from target 1
12059 4 - connect to target 2, that can NOT run breakpoint commands.
12061 After steps #3/#4, you'll want the dprintf command list to
12062 be updated, because target 1 and 2 may well return different
12063 answers for target_can_run_breakpoint_commands().
12064 Given absence of finer grained resetting, we get to do
12065 it all the time. */
12066 if (extra_string
!= NULL
)
12067 update_dprintf_command_list (this);
12070 /* Implement the "print_recreate" method for dprintf. */
12073 dprintf_breakpoint::print_recreate (struct ui_file
*fp
)
12075 gdb_printf (fp
, "dprintf %s,%s",
12076 event_location_to_string (location
.get ()),
12077 extra_string
.get ());
12078 print_recreate_thread (fp
);
12081 /* Implement the "after_condition_true" method for dprintf.
12083 dprintf's are implemented with regular commands in their command
12084 list, but we run the commands here instead of before presenting the
12085 stop to the user, as dprintf's don't actually cause a stop. This
12086 also makes it so that the commands of multiple dprintfs at the same
12087 address are all handled. */
12090 dprintf_breakpoint::after_condition_true (struct bpstat
*bs
)
12092 /* dprintf's never cause a stop. This wasn't set in the
12093 check_status hook instead because that would make the dprintf's
12094 condition not be evaluated. */
12097 /* Run the command list here. Take ownership of it instead of
12098 copying. We never want these commands to run later in
12099 bpstat_do_actions, if a breakpoint that causes a stop happens to
12100 be set at same address as this dprintf, or even if running the
12101 commands here throws. */
12102 counted_command_line cmds
= std::move (bs
->commands
);
12103 gdb_assert (cmds
!= nullptr);
12104 execute_control_commands (cmds
.get (), 0);
12107 /* The breakpoint_ops structure to be used on static tracepoints with
12111 strace_marker_create_sals_from_location (struct event_location
*location
,
12112 struct linespec_result
*canonical
)
12114 struct linespec_sals lsal
;
12115 const char *arg_start
, *arg
;
12117 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
12118 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12120 std::string
str (arg_start
, arg
- arg_start
);
12121 const char *ptr
= str
.c_str ();
12122 canonical
->location
12123 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
12126 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12127 canonical
->lsals
.push_back (std::move (lsal
));
12131 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12132 struct linespec_result
*canonical
,
12133 gdb::unique_xmalloc_ptr
<char> cond_string
,
12134 gdb::unique_xmalloc_ptr
<char> extra_string
,
12135 enum bptype type_wanted
,
12136 enum bpdisp disposition
,
12138 int task
, int ignore_count
,
12139 const struct breakpoint_ops
*ops
,
12140 int from_tty
, int enabled
,
12141 int internal
, unsigned flags
)
12143 const linespec_sals
&lsal
= canonical
->lsals
[0];
12145 /* If the user is creating a static tracepoint by marker id
12146 (strace -m MARKER_ID), then store the sals index, so that
12147 breakpoint_re_set can try to match up which of the newly
12148 found markers corresponds to this one, and, don't try to
12149 expand multiple locations for each sal, given than SALS
12150 already should contain all sals for MARKER_ID. */
12152 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12154 event_location_up location
12155 = copy_event_location (canonical
->location
.get ());
12157 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
12158 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
12159 std::move (location
), NULL
,
12160 std::move (cond_string
),
12161 std::move (extra_string
),
12162 type_wanted
, disposition
,
12163 thread
, task
, ignore_count
, ops
,
12164 from_tty
, enabled
, internal
, flags
,
12165 canonical
->special_display
);
12166 /* Given that its possible to have multiple markers with
12167 the same string id, if the user is creating a static
12168 tracepoint by marker id ("strace -m MARKER_ID"), then
12169 store the sals index, so that breakpoint_re_set can
12170 try to match up which of the newly found markers
12171 corresponds to this one */
12172 tp
->static_trace_marker_id_idx
= i
;
12174 install_breakpoint (internal
, std::move (tp
), 0);
12178 std::vector
<symtab_and_line
>
12179 static_marker_tracepoint::decode_location (struct event_location
*location
,
12180 struct program_space
*search_pspace
)
12182 const char *s
= get_linespec_location (location
)->spec_string
;
12184 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12185 if (sals
.size () > static_trace_marker_id_idx
)
12187 sals
[0] = sals
[static_trace_marker_id_idx
];
12192 error (_("marker %s not found"), static_trace_marker_id
.c_str ());
12195 /* Static tracepoints with marker (`-m'). */
12196 static struct breakpoint_ops strace_marker_breakpoint_ops
=
12198 strace_marker_create_sals_from_location
,
12199 strace_marker_create_breakpoints_sal
,
12203 strace_marker_p (struct breakpoint
*b
)
12205 return b
->type
== bp_static_marker_tracepoint
;
12208 /* Delete a breakpoint and clean up all traces of it in the data
12212 delete_breakpoint (struct breakpoint
*bpt
)
12214 gdb_assert (bpt
!= NULL
);
12216 /* Has this bp already been deleted? This can happen because
12217 multiple lists can hold pointers to bp's. bpstat lists are
12220 One example of this happening is a watchpoint's scope bp. When
12221 the scope bp triggers, we notice that the watchpoint is out of
12222 scope, and delete it. We also delete its scope bp. But the
12223 scope bp is marked "auto-deleting", and is already on a bpstat.
12224 That bpstat is then checked for auto-deleting bp's, which are
12227 A real solution to this problem might involve reference counts in
12228 bp's, and/or giving them pointers back to their referencing
12229 bpstat's, and teaching delete_breakpoint to only free a bp's
12230 storage when no more references were extent. A cheaper bandaid
12232 if (bpt
->type
== bp_none
)
12235 /* At least avoid this stale reference until the reference counting
12236 of breakpoints gets resolved. */
12237 if (bpt
->related_breakpoint
!= bpt
)
12239 struct breakpoint
*related
;
12240 struct watchpoint
*w
;
12242 if (bpt
->type
== bp_watchpoint_scope
)
12243 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
12244 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
12245 w
= (struct watchpoint
*) bpt
;
12249 watchpoint_del_at_next_stop (w
);
12251 /* Unlink bpt from the bpt->related_breakpoint ring. */
12252 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
12253 related
= related
->related_breakpoint
);
12254 related
->related_breakpoint
= bpt
->related_breakpoint
;
12255 bpt
->related_breakpoint
= bpt
;
12258 /* watch_command_1 creates a watchpoint but only sets its number if
12259 update_watchpoint succeeds in creating its bp_locations. If there's
12260 a problem in that process, we'll be asked to delete the half-created
12261 watchpoint. In that case, don't announce the deletion. */
12263 gdb::observers::breakpoint_deleted
.notify (bpt
);
12265 if (breakpoint_chain
== bpt
)
12266 breakpoint_chain
= bpt
->next
;
12268 for (breakpoint
*b
: all_breakpoints ())
12269 if (b
->next
== bpt
)
12271 b
->next
= bpt
->next
;
12275 /* Be sure no bpstat's are pointing at the breakpoint after it's
12277 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
12278 in all threads for now. Note that we cannot just remove bpstats
12279 pointing at bpt from the stop_bpstat list entirely, as breakpoint
12280 commands are associated with the bpstat; if we remove it here,
12281 then the later call to bpstat_do_actions (&stop_bpstat); in
12282 event-top.c won't do anything, and temporary breakpoints with
12283 commands won't work. */
12285 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
12287 /* Now that breakpoint is removed from breakpoint list, update the
12288 global location list. This will remove locations that used to
12289 belong to this breakpoint. Do this before freeing the breakpoint
12290 itself, since remove_breakpoint looks at location's owner. It
12291 might be better design to have location completely
12292 self-contained, but it's not the case now. */
12293 update_global_location_list (UGLL_DONT_INSERT
);
12295 /* On the chance that someone will soon try again to delete this
12296 same bp, we mark it as deleted before freeing its storage. */
12297 bpt
->type
= bp_none
;
12301 /* Iterator function to call a user-provided callback function once
12302 for each of B and its related breakpoints. */
12305 iterate_over_related_breakpoints (struct breakpoint
*b
,
12306 gdb::function_view
<void (breakpoint
*)> function
)
12308 struct breakpoint
*related
;
12313 struct breakpoint
*next
;
12315 /* FUNCTION may delete RELATED. */
12316 next
= related
->related_breakpoint
;
12318 if (next
== related
)
12320 /* RELATED is the last ring entry. */
12321 function (related
);
12323 /* FUNCTION may have deleted it, so we'd never reach back to
12324 B. There's nothing left to do anyway, so just break
12329 function (related
);
12333 while (related
!= b
);
12337 delete_command (const char *arg
, int from_tty
)
12343 int breaks_to_delete
= 0;
12345 /* Delete all breakpoints if no argument. Do not delete
12346 internal breakpoints, these have to be deleted with an
12347 explicit breakpoint number argument. */
12348 for (breakpoint
*b
: all_breakpoints ())
12349 if (user_breakpoint_p (b
))
12351 breaks_to_delete
= 1;
12355 /* Ask user only if there are some breakpoints to delete. */
12357 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
12358 for (breakpoint
*b
: all_breakpoints_safe ())
12359 if (user_breakpoint_p (b
))
12360 delete_breakpoint (b
);
12363 map_breakpoint_numbers
12364 (arg
, [&] (breakpoint
*br
)
12366 iterate_over_related_breakpoints (br
, delete_breakpoint
);
12370 /* Return true if all locations of B bound to PSPACE are pending. If
12371 PSPACE is NULL, all locations of all program spaces are
12375 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
12377 for (bp_location
*loc
: b
->locations ())
12378 if ((pspace
== NULL
12379 || loc
->pspace
== pspace
)
12380 && !loc
->shlib_disabled
12381 && !loc
->pspace
->executing_startup
)
12386 /* Subroutine of update_breakpoint_locations to simplify it.
12387 Return non-zero if multiple fns in list LOC have the same name.
12388 Null names are ignored. */
12391 ambiguous_names_p (struct bp_location
*loc
)
12393 struct bp_location
*l
;
12394 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
12397 for (l
= loc
; l
!= NULL
; l
= l
->next
)
12400 const char *name
= l
->function_name
.get ();
12402 /* Allow for some names to be NULL, ignore them. */
12406 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
12408 /* NOTE: We can assume slot != NULL here because xcalloc never
12418 /* When symbols change, it probably means the sources changed as well,
12419 and it might mean the static tracepoint markers are no longer at
12420 the same address or line numbers they used to be at last we
12421 checked. Losing your static tracepoints whenever you rebuild is
12422 undesirable. This function tries to resync/rematch gdb static
12423 tracepoints with the markers on the target, for static tracepoints
12424 that have not been set by marker id. Static tracepoint that have
12425 been set by marker id are reset by marker id in breakpoint_re_set.
12428 1) For a tracepoint set at a specific address, look for a marker at
12429 the old PC. If one is found there, assume to be the same marker.
12430 If the name / string id of the marker found is different from the
12431 previous known name, assume that means the user renamed the marker
12432 in the sources, and output a warning.
12434 2) For a tracepoint set at a given line number, look for a marker
12435 at the new address of the old line number. If one is found there,
12436 assume to be the same marker. If the name / string id of the
12437 marker found is different from the previous known name, assume that
12438 means the user renamed the marker in the sources, and output a
12441 3) If a marker is no longer found at the same address or line, it
12442 may mean the marker no longer exists. But it may also just mean
12443 the code changed a bit. Maybe the user added a few lines of code
12444 that made the marker move up or down (in line number terms). Ask
12445 the target for info about the marker with the string id as we knew
12446 it. If found, update line number and address in the matching
12447 static tracepoint. This will get confused if there's more than one
12448 marker with the same ID (possible in UST, although unadvised
12449 precisely because it confuses tools). */
12451 static struct symtab_and_line
12452 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
12454 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12455 struct static_tracepoint_marker marker
;
12460 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
12462 if (target_static_tracepoint_marker_at (pc
, &marker
))
12464 if (tp
->static_trace_marker_id
!= marker
.str_id
)
12465 warning (_("static tracepoint %d changed probed marker from %s to %s"),
12466 b
->number
, tp
->static_trace_marker_id
.c_str (),
12467 marker
.str_id
.c_str ());
12469 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
12474 /* Old marker wasn't found on target at lineno. Try looking it up
12476 if (!sal
.explicit_pc
12478 && sal
.symtab
!= NULL
12479 && !tp
->static_trace_marker_id
.empty ())
12481 std::vector
<static_tracepoint_marker
> markers
12482 = target_static_tracepoint_markers_by_strid
12483 (tp
->static_trace_marker_id
.c_str ());
12485 if (!markers
.empty ())
12487 struct symbol
*sym
;
12488 struct static_tracepoint_marker
*tpmarker
;
12489 struct ui_out
*uiout
= current_uiout
;
12490 struct explicit_location explicit_loc
;
12492 tpmarker
= &markers
[0];
12494 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
12496 warning (_("marker for static tracepoint %d (%s) not "
12497 "found at previous line number"),
12498 b
->number
, tp
->static_trace_marker_id
.c_str ());
12500 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
12501 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
12502 uiout
->text ("Now in ");
12505 uiout
->field_string ("func", sym
->print_name (),
12506 function_name_style
.style ());
12507 uiout
->text (" at ");
12509 uiout
->field_string ("file",
12510 symtab_to_filename_for_display (sal2
.symtab
),
12511 file_name_style
.style ());
12514 if (uiout
->is_mi_like_p ())
12516 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
12518 uiout
->field_string ("fullname", fullname
);
12521 uiout
->field_signed ("line", sal2
.line
);
12522 uiout
->text ("\n");
12524 b
->loc
->line_number
= sal2
.line
;
12525 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
12527 b
->location
.reset (NULL
);
12528 initialize_explicit_location (&explicit_loc
);
12529 explicit_loc
.source_filename
12530 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
12531 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
12532 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
12533 b
->location
= new_explicit_location (&explicit_loc
);
12535 /* Might be nice to check if function changed, and warn if
12542 /* Returns 1 iff locations A and B are sufficiently same that
12543 we don't need to report breakpoint as changed. */
12546 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
12550 if (a
->address
!= b
->address
)
12553 if (a
->shlib_disabled
!= b
->shlib_disabled
)
12556 if (a
->enabled
!= b
->enabled
)
12559 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
12566 if ((a
== NULL
) != (b
== NULL
))
12572 /* Split all locations of B that are bound to PSPACE out of B's
12573 location list to a separate list and return that list's head. If
12574 PSPACE is NULL, hoist out all locations of B. */
12576 static struct bp_location
*
12577 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
12579 struct bp_location head
;
12580 struct bp_location
*i
= b
->loc
;
12581 struct bp_location
**i_link
= &b
->loc
;
12582 struct bp_location
*hoisted
= &head
;
12584 if (pspace
== NULL
)
12595 if (i
->pspace
== pspace
)
12610 /* Create new breakpoint locations for B (a hardware or software
12611 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
12612 zero, then B is a ranged breakpoint. Only recreates locations for
12613 FILTER_PSPACE. Locations of other program spaces are left
12617 update_breakpoint_locations (struct breakpoint
*b
,
12618 struct program_space
*filter_pspace
,
12619 gdb::array_view
<const symtab_and_line
> sals
,
12620 gdb::array_view
<const symtab_and_line
> sals_end
)
12622 struct bp_location
*existing_locations
;
12624 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
12626 /* Ranged breakpoints have only one start location and one end
12628 b
->enable_state
= bp_disabled
;
12629 gdb_printf (gdb_stderr
,
12630 _("Could not reset ranged breakpoint %d: "
12631 "multiple locations found\n"),
12636 /* If there's no new locations, and all existing locations are
12637 pending, don't do anything. This optimizes the common case where
12638 all locations are in the same shared library, that was unloaded.
12639 We'd like to retain the location, so that when the library is
12640 loaded again, we don't loose the enabled/disabled status of the
12641 individual locations. */
12642 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
12645 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
12647 for (const auto &sal
: sals
)
12649 struct bp_location
*new_loc
;
12651 switch_to_program_space_and_thread (sal
.pspace
);
12653 new_loc
= add_location_to_breakpoint (b
, &sal
);
12655 /* Reparse conditions, they might contain references to the
12657 if (b
->cond_string
!= NULL
)
12661 s
= b
->cond_string
.get ();
12664 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
12665 block_for_pc (sal
.pc
),
12668 catch (const gdb_exception_error
&e
)
12670 new_loc
->disabled_by_cond
= true;
12674 if (!sals_end
.empty ())
12676 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
12678 new_loc
->length
= end
- sals
[0].pc
+ 1;
12682 /* If possible, carry over 'disable' status from existing
12685 struct bp_location
*e
= existing_locations
;
12686 /* If there are multiple breakpoints with the same function name,
12687 e.g. for inline functions, comparing function names won't work.
12688 Instead compare pc addresses; this is just a heuristic as things
12689 may have moved, but in practice it gives the correct answer
12690 often enough until a better solution is found. */
12691 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
12693 for (; e
; e
= e
->next
)
12695 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
12697 if (have_ambiguous_names
)
12699 for (bp_location
*l
: b
->locations ())
12701 /* Ignore software vs hardware location type at
12702 this point, because with "set breakpoint
12703 auto-hw", after a re-set, locations that were
12704 hardware can end up as software, or vice versa.
12705 As mentioned above, this is an heuristic and in
12706 practice should give the correct answer often
12708 if (breakpoint_locations_match (e
, l
, true))
12710 l
->enabled
= e
->enabled
;
12711 l
->disabled_by_cond
= e
->disabled_by_cond
;
12718 for (bp_location
*l
: b
->locations ())
12719 if (l
->function_name
12720 && strcmp (e
->function_name
.get (),
12721 l
->function_name
.get ()) == 0)
12723 l
->enabled
= e
->enabled
;
12724 l
->disabled_by_cond
= e
->disabled_by_cond
;
12732 if (!locations_are_equal (existing_locations
, b
->loc
))
12733 gdb::observers::breakpoint_modified
.notify (b
);
12736 /* Find the SaL locations corresponding to the given LOCATION.
12737 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
12739 static std::vector
<symtab_and_line
>
12740 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
12741 struct program_space
*search_pspace
, int *found
)
12743 struct gdb_exception exception
;
12745 std::vector
<symtab_and_line
> sals
;
12749 sals
= b
->decode_location (location
, search_pspace
);
12751 catch (gdb_exception_error
&e
)
12753 int not_found_and_ok
= 0;
12755 /* For pending breakpoints, it's expected that parsing will
12756 fail until the right shared library is loaded. User has
12757 already told to create pending breakpoints and don't need
12758 extra messages. If breakpoint is in bp_shlib_disabled
12759 state, then user already saw the message about that
12760 breakpoint being disabled, and don't want to see more
12762 if (e
.error
== NOT_FOUND_ERROR
12763 && (b
->condition_not_parsed
12765 && search_pspace
!= NULL
12766 && b
->loc
->pspace
!= search_pspace
)
12767 || (b
->loc
&& b
->loc
->shlib_disabled
)
12768 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
12769 || b
->enable_state
== bp_disabled
))
12770 not_found_and_ok
= 1;
12772 if (!not_found_and_ok
)
12774 /* We surely don't want to warn about the same breakpoint
12775 10 times. One solution, implemented here, is disable
12776 the breakpoint on error. Another solution would be to
12777 have separate 'warning emitted' flag. Since this
12778 happens only when a binary has changed, I don't know
12779 which approach is better. */
12780 b
->enable_state
= bp_disabled
;
12784 exception
= std::move (e
);
12787 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
12789 for (auto &sal
: sals
)
12790 resolve_sal_pc (&sal
);
12791 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
12793 gdb::unique_xmalloc_ptr
<char> cond_string
, extra_string
;
12796 find_condition_and_thread_for_sals (sals
, b
->extra_string
.get (),
12797 &cond_string
, &thread
,
12798 &task
, &extra_string
);
12799 gdb_assert (b
->cond_string
== NULL
);
12801 b
->cond_string
= std::move (cond_string
);
12802 b
->thread
= thread
;
12805 b
->extra_string
= std::move (extra_string
);
12806 b
->condition_not_parsed
= 0;
12809 if (b
->type
== bp_static_tracepoint
)
12810 sals
[0] = update_static_tracepoint (b
, sals
[0]);
12820 /* The default re_set method, for typical hardware or software
12821 breakpoints. Reevaluate the breakpoint and recreate its
12825 breakpoint_re_set_default (struct breakpoint
*b
)
12827 struct program_space
*filter_pspace
= current_program_space
;
12828 std::vector
<symtab_and_line
> expanded
, expanded_end
;
12831 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
12832 filter_pspace
, &found
);
12834 expanded
= std::move (sals
);
12836 if (b
->location_range_end
!= NULL
)
12838 std::vector
<symtab_and_line
> sals_end
12839 = location_to_sals (b
, b
->location_range_end
.get (),
12840 filter_pspace
, &found
);
12842 expanded_end
= std::move (sals_end
);
12845 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
12848 /* Default method for creating SALs from an address string. It basically
12849 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
12852 create_sals_from_location_default (struct event_location
*location
,
12853 struct linespec_result
*canonical
)
12855 parse_breakpoint_sals (location
, canonical
);
12858 /* Decode the line represented by S by calling decode_line_full. This is the
12859 default function for the `decode_location' method of breakpoint_ops. */
12861 static std::vector
<symtab_and_line
>
12862 decode_location_default (struct breakpoint
*b
,
12863 struct event_location
*location
,
12864 struct program_space
*search_pspace
)
12866 struct linespec_result canonical
;
12868 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
12869 NULL
, 0, &canonical
, multiple_symbols_all
,
12872 /* We should get 0 or 1 resulting SALs. */
12873 gdb_assert (canonical
.lsals
.size () < 2);
12875 if (!canonical
.lsals
.empty ())
12877 const linespec_sals
&lsal
= canonical
.lsals
[0];
12878 return std::move (lsal
.sals
);
12883 /* Reset a breakpoint. */
12886 breakpoint_re_set_one (breakpoint
*b
)
12888 input_radix
= b
->input_radix
;
12889 set_language (b
->language
);
12894 /* Re-set breakpoint locations for the current program space.
12895 Locations bound to other program spaces are left untouched. */
12898 breakpoint_re_set (void)
12901 scoped_restore_current_language save_language
;
12902 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
12903 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
12905 /* breakpoint_re_set_one sets the current_language to the language
12906 of the breakpoint it is resetting (see prepare_re_set_context)
12907 before re-evaluating the breakpoint's location. This change can
12908 unfortunately get undone by accident if the language_mode is set
12909 to auto, and we either switch frames, or more likely in this context,
12910 we select the current frame.
12912 We prevent this by temporarily turning the language_mode to
12913 language_mode_manual. We restore it once all breakpoints
12914 have been reset. */
12915 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
12916 language_mode
= language_mode_manual
;
12918 /* Note: we must not try to insert locations until after all
12919 breakpoints have been re-set. Otherwise, e.g., when re-setting
12920 breakpoint 1, we'd insert the locations of breakpoint 2, which
12921 hadn't been re-set yet, and thus may have stale locations. */
12923 for (breakpoint
*b
: all_breakpoints_safe ())
12927 breakpoint_re_set_one (b
);
12929 catch (const gdb_exception
&ex
)
12931 exception_fprintf (gdb_stderr
, ex
,
12932 "Error in re-setting breakpoint %d: ",
12937 jit_breakpoint_re_set ();
12940 create_overlay_event_breakpoint ();
12941 create_longjmp_master_breakpoint ();
12942 create_std_terminate_master_breakpoint ();
12943 create_exception_master_breakpoint ();
12945 /* Now we can insert. */
12946 update_global_location_list (UGLL_MAY_INSERT
);
12949 /* Reset the thread number of this breakpoint:
12951 - If the breakpoint is for all threads, leave it as-is.
12952 - Else, reset it to the current thread for inferior_ptid. */
12954 breakpoint_re_set_thread (struct breakpoint
*b
)
12956 if (b
->thread
!= -1)
12958 b
->thread
= inferior_thread ()->global_num
;
12960 /* We're being called after following a fork. The new fork is
12961 selected as current, and unless this was a vfork will have a
12962 different program space from the original thread. Reset that
12964 b
->loc
->pspace
= current_program_space
;
12968 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
12969 If from_tty is nonzero, it prints a message to that effect,
12970 which ends with a period (no newline). */
12973 set_ignore_count (int bptnum
, int count
, int from_tty
)
12978 for (breakpoint
*b
: all_breakpoints ())
12979 if (b
->number
== bptnum
)
12981 if (is_tracepoint (b
))
12983 if (from_tty
&& count
!= 0)
12984 gdb_printf (_("Ignore count ignored for tracepoint %d."),
12989 b
->ignore_count
= count
;
12993 gdb_printf (_("Will stop next time "
12994 "breakpoint %d is reached."),
12996 else if (count
== 1)
12997 gdb_printf (_("Will ignore next crossing of breakpoint %d."),
13000 gdb_printf (_("Will ignore next %d "
13001 "crossings of breakpoint %d."),
13004 gdb::observers::breakpoint_modified
.notify (b
);
13008 error (_("No breakpoint number %d."), bptnum
);
13011 /* Command to set ignore-count of breakpoint N to COUNT. */
13014 ignore_command (const char *args
, int from_tty
)
13016 const char *p
= args
;
13020 error_no_arg (_("a breakpoint number"));
13022 num
= get_number (&p
);
13024 error (_("bad breakpoint number: '%s'"), args
);
13026 error (_("Second argument (specified ignore-count) is missing."));
13028 set_ignore_count (num
,
13029 longest_to_int (value_as_long (parse_and_eval (p
))),
13036 /* Call FUNCTION on each of the breakpoints with numbers in the range
13037 defined by BP_NUM_RANGE (an inclusive range). */
13040 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13041 gdb::function_view
<void (breakpoint
*)> function
)
13043 if (bp_num_range
.first
== 0)
13045 warning (_("bad breakpoint number at or near '%d'"),
13046 bp_num_range
.first
);
13050 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13052 bool match
= false;
13054 for (breakpoint
*b
: all_breakpoints_safe ())
13055 if (b
->number
== i
)
13062 gdb_printf (_("No breakpoint number %d.\n"), i
);
13067 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13071 map_breakpoint_numbers (const char *args
,
13072 gdb::function_view
<void (breakpoint
*)> function
)
13074 if (args
== NULL
|| *args
== '\0')
13075 error_no_arg (_("one or more breakpoint numbers"));
13077 number_or_range_parser
parser (args
);
13079 while (!parser
.finished ())
13081 int num
= parser
.get_number ();
13082 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13086 /* Return the breakpoint location structure corresponding to the
13087 BP_NUM and LOC_NUM values. */
13089 static struct bp_location
*
13090 find_location_by_number (int bp_num
, int loc_num
)
13092 breakpoint
*b
= get_breakpoint (bp_num
);
13094 if (!b
|| b
->number
!= bp_num
)
13095 error (_("Bad breakpoint number '%d'"), bp_num
);
13098 error (_("Bad breakpoint location number '%d'"), loc_num
);
13101 for (bp_location
*loc
: b
->locations ())
13102 if (++n
== loc_num
)
13105 error (_("Bad breakpoint location number '%d'"), loc_num
);
13108 /* Modes of operation for extract_bp_num. */
13109 enum class extract_bp_kind
13111 /* Extracting a breakpoint number. */
13114 /* Extracting a location number. */
13118 /* Extract a breakpoint or location number (as determined by KIND)
13119 from the string starting at START. TRAILER is a character which
13120 can be found after the number. If you don't want a trailer, use
13121 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13122 string. This always returns a positive integer. */
13125 extract_bp_num (extract_bp_kind kind
, const char *start
,
13126 int trailer
, const char **end_out
= NULL
)
13128 const char *end
= start
;
13129 int num
= get_number_trailer (&end
, trailer
);
13131 error (kind
== extract_bp_kind::bp
13132 ? _("Negative breakpoint number '%.*s'")
13133 : _("Negative breakpoint location number '%.*s'"),
13134 int (end
- start
), start
);
13136 error (kind
== extract_bp_kind::bp
13137 ? _("Bad breakpoint number '%.*s'")
13138 : _("Bad breakpoint location number '%.*s'"),
13139 int (end
- start
), start
);
13141 if (end_out
!= NULL
)
13146 /* Extract a breakpoint or location range (as determined by KIND) in
13147 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13148 representing the (inclusive) range. The returned pair's elements
13149 are always positive integers. */
13151 static std::pair
<int, int>
13152 extract_bp_or_bp_range (extract_bp_kind kind
,
13153 const std::string
&arg
,
13154 std::string::size_type arg_offset
)
13156 std::pair
<int, int> range
;
13157 const char *bp_loc
= &arg
[arg_offset
];
13158 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13159 if (dash
!= std::string::npos
)
13161 /* bp_loc is a range (x-z). */
13162 if (arg
.length () == dash
+ 1)
13163 error (kind
== extract_bp_kind::bp
13164 ? _("Bad breakpoint number at or near: '%s'")
13165 : _("Bad breakpoint location number at or near: '%s'"),
13169 const char *start_first
= bp_loc
;
13170 const char *start_second
= &arg
[dash
+ 1];
13171 range
.first
= extract_bp_num (kind
, start_first
, '-');
13172 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
13174 if (range
.first
> range
.second
)
13175 error (kind
== extract_bp_kind::bp
13176 ? _("Inverted breakpoint range at '%.*s'")
13177 : _("Inverted breakpoint location range at '%.*s'"),
13178 int (end
- start_first
), start_first
);
13182 /* bp_loc is a single value. */
13183 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
13184 range
.second
= range
.first
;
13189 /* Extract the breakpoint/location range specified by ARG. Returns
13190 the breakpoint range in BP_NUM_RANGE, and the location range in
13193 ARG may be in any of the following forms:
13195 x where 'x' is a breakpoint number.
13196 x-y where 'x' and 'y' specify a breakpoint numbers range.
13197 x.y where 'x' is a breakpoint number and 'y' a location number.
13198 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
13199 location number range.
13203 extract_bp_number_and_location (const std::string
&arg
,
13204 std::pair
<int, int> &bp_num_range
,
13205 std::pair
<int, int> &bp_loc_range
)
13207 std::string::size_type dot
= arg
.find ('.');
13209 if (dot
!= std::string::npos
)
13211 /* Handle 'x.y' and 'x.y-z' cases. */
13213 if (arg
.length () == dot
+ 1 || dot
== 0)
13214 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
13217 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
13218 bp_num_range
.second
= bp_num_range
.first
;
13220 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
13225 /* Handle x and x-y cases. */
13227 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
13228 bp_loc_range
.first
= 0;
13229 bp_loc_range
.second
= 0;
13233 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
13234 specifies whether to enable or disable. */
13237 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
13239 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
13242 if (loc
->disabled_by_cond
&& enable
)
13243 error (_("Breakpoint %d's condition is invalid at location %d, "
13244 "cannot enable."), bp_num
, loc_num
);
13246 if (loc
->enabled
!= enable
)
13248 loc
->enabled
= enable
;
13249 mark_breakpoint_location_modified (loc
);
13251 if (target_supports_enable_disable_tracepoint ()
13252 && current_trace_status ()->running
&& loc
->owner
13253 && is_tracepoint (loc
->owner
))
13254 target_disable_tracepoint (loc
);
13256 update_global_location_list (UGLL_DONT_INSERT
);
13258 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
13261 /* Enable or disable a range of breakpoint locations. BP_NUM is the
13262 number of the breakpoint, and BP_LOC_RANGE specifies the
13263 (inclusive) range of location numbers of that breakpoint to
13264 enable/disable. ENABLE specifies whether to enable or disable the
13268 enable_disable_breakpoint_location_range (int bp_num
,
13269 std::pair
<int, int> &bp_loc_range
,
13272 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
13273 enable_disable_bp_num_loc (bp_num
, i
, enable
);
13276 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13277 If from_tty is nonzero, it prints a message to that effect,
13278 which ends with a period (no newline). */
13281 disable_breakpoint (struct breakpoint
*bpt
)
13283 /* Never disable a watchpoint scope breakpoint; we want to
13284 hit them when we leave scope so we can delete both the
13285 watchpoint and its scope breakpoint at that time. */
13286 if (bpt
->type
== bp_watchpoint_scope
)
13289 bpt
->enable_state
= bp_disabled
;
13291 /* Mark breakpoint locations modified. */
13292 mark_breakpoint_modified (bpt
);
13294 if (target_supports_enable_disable_tracepoint ()
13295 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13297 for (bp_location
*location
: bpt
->locations ())
13298 target_disable_tracepoint (location
);
13301 update_global_location_list (UGLL_DONT_INSERT
);
13303 gdb::observers::breakpoint_modified
.notify (bpt
);
13306 /* Enable or disable the breakpoint(s) or breakpoint location(s)
13307 specified in ARGS. ARGS may be in any of the formats handled by
13308 extract_bp_number_and_location. ENABLE specifies whether to enable
13309 or disable the breakpoints/locations. */
13312 enable_disable_command (const char *args
, int from_tty
, bool enable
)
13316 for (breakpoint
*bpt
: all_breakpoints ())
13317 if (user_breakpoint_p (bpt
))
13320 enable_breakpoint (bpt
);
13322 disable_breakpoint (bpt
);
13327 std::string num
= extract_arg (&args
);
13329 while (!num
.empty ())
13331 std::pair
<int, int> bp_num_range
, bp_loc_range
;
13333 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
13335 if (bp_loc_range
.first
== bp_loc_range
.second
13336 && bp_loc_range
.first
== 0)
13338 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
13339 map_breakpoint_number_range (bp_num_range
,
13341 ? enable_breakpoint
13342 : disable_breakpoint
);
13346 /* Handle breakpoint ids with formats 'x.y' or
13348 enable_disable_breakpoint_location_range
13349 (bp_num_range
.first
, bp_loc_range
, enable
);
13351 num
= extract_arg (&args
);
13356 /* The disable command disables the specified breakpoints/locations
13357 (or all defined breakpoints) so they're no longer effective in
13358 stopping the inferior. ARGS may be in any of the forms defined in
13359 extract_bp_number_and_location. */
13362 disable_command (const char *args
, int from_tty
)
13364 enable_disable_command (args
, from_tty
, false);
13368 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
13371 int target_resources_ok
;
13373 if (bpt
->type
== bp_hardware_breakpoint
)
13376 i
= hw_breakpoint_used_count ();
13377 target_resources_ok
=
13378 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
13380 if (target_resources_ok
== 0)
13381 error (_("No hardware breakpoint support in the target."));
13382 else if (target_resources_ok
< 0)
13383 error (_("Hardware breakpoints used exceeds limit."));
13386 if (is_watchpoint (bpt
))
13388 /* Initialize it just to avoid a GCC false warning. */
13389 enum enable_state orig_enable_state
= bp_disabled
;
13393 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
13395 orig_enable_state
= bpt
->enable_state
;
13396 bpt
->enable_state
= bp_enabled
;
13397 update_watchpoint (w
, 1 /* reparse */);
13399 catch (const gdb_exception
&e
)
13401 bpt
->enable_state
= orig_enable_state
;
13402 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
13408 bpt
->enable_state
= bp_enabled
;
13410 /* Mark breakpoint locations modified. */
13411 mark_breakpoint_modified (bpt
);
13413 if (target_supports_enable_disable_tracepoint ()
13414 && current_trace_status ()->running
&& is_tracepoint (bpt
))
13416 for (bp_location
*location
: bpt
->locations ())
13417 target_enable_tracepoint (location
);
13420 bpt
->disposition
= disposition
;
13421 bpt
->enable_count
= count
;
13422 update_global_location_list (UGLL_MAY_INSERT
);
13424 gdb::observers::breakpoint_modified
.notify (bpt
);
13429 enable_breakpoint (struct breakpoint
*bpt
)
13431 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
13434 /* The enable command enables the specified breakpoints/locations (or
13435 all defined breakpoints) so they once again become (or continue to
13436 be) effective in stopping the inferior. ARGS may be in any of the
13437 forms defined in extract_bp_number_and_location. */
13440 enable_command (const char *args
, int from_tty
)
13442 enable_disable_command (args
, from_tty
, true);
13446 enable_once_command (const char *args
, int from_tty
)
13448 map_breakpoint_numbers
13449 (args
, [&] (breakpoint
*b
)
13451 iterate_over_related_breakpoints
13452 (b
, [&] (breakpoint
*bpt
)
13454 enable_breakpoint_disp (bpt
, disp_disable
, 1);
13460 enable_count_command (const char *args
, int from_tty
)
13465 error_no_arg (_("hit count"));
13467 count
= get_number (&args
);
13469 map_breakpoint_numbers
13470 (args
, [&] (breakpoint
*b
)
13472 iterate_over_related_breakpoints
13473 (b
, [&] (breakpoint
*bpt
)
13475 enable_breakpoint_disp (bpt
, disp_disable
, count
);
13481 enable_delete_command (const char *args
, int from_tty
)
13483 map_breakpoint_numbers
13484 (args
, [&] (breakpoint
*b
)
13486 iterate_over_related_breakpoints
13487 (b
, [&] (breakpoint
*bpt
)
13489 enable_breakpoint_disp (bpt
, disp_del
, 1);
13494 /* Invalidate last known value of any hardware watchpoint if
13495 the memory which that value represents has been written to by
13499 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
13500 CORE_ADDR addr
, ssize_t len
,
13501 const bfd_byte
*data
)
13503 for (breakpoint
*bp
: all_breakpoints ())
13504 if (bp
->enable_state
== bp_enabled
13505 && bp
->type
== bp_hardware_watchpoint
)
13507 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
13509 if (wp
->val_valid
&& wp
->val
!= nullptr)
13511 for (bp_location
*loc
: bp
->locations ())
13512 if (loc
->loc_type
== bp_loc_hardware_watchpoint
13513 && loc
->address
+ loc
->length
> addr
13514 && addr
+ len
> loc
->address
)
13517 wp
->val_valid
= false;
13523 /* Create and insert a breakpoint for software single step. */
13526 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
13527 const address_space
*aspace
,
13530 struct thread_info
*tp
= inferior_thread ();
13531 struct symtab_and_line sal
;
13532 CORE_ADDR pc
= next_pc
;
13534 if (tp
->control
.single_step_breakpoints
== NULL
)
13536 tp
->control
.single_step_breakpoints
13537 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
13540 sal
= find_pc_line (pc
, 0);
13542 sal
.section
= find_pc_overlay (pc
);
13543 sal
.explicit_pc
= 1;
13544 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
13546 update_global_location_list (UGLL_INSERT
);
13549 /* Insert single step breakpoints according to the current state. */
13552 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
13554 struct regcache
*regcache
= get_current_regcache ();
13555 std::vector
<CORE_ADDR
> next_pcs
;
13557 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
13559 if (!next_pcs
.empty ())
13561 struct frame_info
*frame
= get_current_frame ();
13562 const address_space
*aspace
= get_frame_address_space (frame
);
13564 for (CORE_ADDR pc
: next_pcs
)
13565 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
13573 /* See breakpoint.h. */
13576 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
13577 const address_space
*aspace
,
13580 for (bp_location
*loc
: bp
->locations ())
13582 && breakpoint_location_address_match (loc
, aspace
, pc
))
13588 /* Check whether a software single-step breakpoint is inserted at
13592 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
13595 for (breakpoint
*bpt
: all_breakpoints ())
13597 if (bpt
->type
== bp_single_step
13598 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
13604 /* Tracepoint-specific operations. */
13606 /* Set tracepoint count to NUM. */
13608 set_tracepoint_count (int num
)
13610 tracepoint_count
= num
;
13611 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
13615 trace_command (const char *arg
, int from_tty
)
13617 event_location_up location
= string_to_event_location (&arg
,
13619 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
13620 (location
.get (), true /* is_tracepoint */);
13622 create_breakpoint (get_current_arch (),
13624 NULL
, 0, arg
, false, 1 /* parse arg */,
13626 bp_tracepoint
/* type_wanted */,
13627 0 /* Ignore count */,
13628 pending_break_support
,
13632 0 /* internal */, 0);
13636 ftrace_command (const char *arg
, int from_tty
)
13638 event_location_up location
= string_to_event_location (&arg
,
13640 create_breakpoint (get_current_arch (),
13642 NULL
, 0, arg
, false, 1 /* parse arg */,
13644 bp_fast_tracepoint
/* type_wanted */,
13645 0 /* Ignore count */,
13646 pending_break_support
,
13647 &base_breakpoint_ops
,
13650 0 /* internal */, 0);
13653 /* strace command implementation. Creates a static tracepoint. */
13656 strace_command (const char *arg
, int from_tty
)
13658 const struct breakpoint_ops
*ops
;
13659 event_location_up location
;
13662 /* Decide if we are dealing with a static tracepoint marker (`-m'),
13663 or with a normal static tracepoint. */
13664 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
13666 ops
= &strace_marker_breakpoint_ops
;
13667 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
13668 type
= bp_static_marker_tracepoint
;
13672 ops
= &base_breakpoint_ops
;
13673 location
= string_to_event_location (&arg
, current_language
);
13674 type
= bp_static_tracepoint
;
13677 create_breakpoint (get_current_arch (),
13679 NULL
, 0, arg
, false, 1 /* parse arg */,
13681 type
/* type_wanted */,
13682 0 /* Ignore count */,
13683 pending_break_support
,
13687 0 /* internal */, 0);
13690 /* Set up a fake reader function that gets command lines from a linked
13691 list that was acquired during tracepoint uploading. */
13693 static struct uploaded_tp
*this_utp
;
13694 static int next_cmd
;
13697 read_uploaded_action (void)
13699 char *rslt
= nullptr;
13701 if (next_cmd
< this_utp
->cmd_strings
.size ())
13703 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
13710 /* Given information about a tracepoint as recorded on a target (which
13711 can be either a live system or a trace file), attempt to create an
13712 equivalent GDB tracepoint. This is not a reliable process, since
13713 the target does not necessarily have all the information used when
13714 the tracepoint was originally defined. */
13716 struct tracepoint
*
13717 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
13719 const char *addr_str
;
13720 char small_buf
[100];
13721 struct tracepoint
*tp
;
13723 if (utp
->at_string
)
13724 addr_str
= utp
->at_string
.get ();
13727 /* In the absence of a source location, fall back to raw
13728 address. Since there is no way to confirm that the address
13729 means the same thing as when the trace was started, warn the
13731 warning (_("Uploaded tracepoint %d has no "
13732 "source location, using raw address"),
13734 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
13735 addr_str
= small_buf
;
13738 /* There's not much we can do with a sequence of bytecodes. */
13739 if (utp
->cond
&& !utp
->cond_string
)
13740 warning (_("Uploaded tracepoint %d condition "
13741 "has no source form, ignoring it"),
13744 event_location_up location
= string_to_event_location (&addr_str
,
13746 if (!create_breakpoint (get_current_arch (),
13748 utp
->cond_string
.get (), -1, addr_str
,
13749 false /* force_condition */,
13750 0 /* parse cond/thread */,
13752 utp
->type
/* type_wanted */,
13753 0 /* Ignore count */,
13754 pending_break_support
,
13755 &base_breakpoint_ops
,
13757 utp
->enabled
/* enabled */,
13759 CREATE_BREAKPOINT_FLAGS_INSERTED
))
13762 /* Get the tracepoint we just created. */
13763 tp
= get_tracepoint (tracepoint_count
);
13764 gdb_assert (tp
!= NULL
);
13768 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
13771 trace_pass_command (small_buf
, 0);
13774 /* If we have uploaded versions of the original commands, set up a
13775 special-purpose "reader" function and call the usual command line
13776 reader, then pass the result to the breakpoint command-setting
13778 if (!utp
->cmd_strings
.empty ())
13780 counted_command_line cmd_list
;
13785 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
13787 breakpoint_set_commands (tp
, std::move (cmd_list
));
13789 else if (!utp
->actions
.empty ()
13790 || !utp
->step_actions
.empty ())
13791 warning (_("Uploaded tracepoint %d actions "
13792 "have no source form, ignoring them"),
13795 /* Copy any status information that might be available. */
13796 tp
->hit_count
= utp
->hit_count
;
13797 tp
->traceframe_usage
= utp
->traceframe_usage
;
13802 /* Print information on tracepoint number TPNUM_EXP, or all if
13806 info_tracepoints_command (const char *args
, int from_tty
)
13808 struct ui_out
*uiout
= current_uiout
;
13811 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
13813 if (num_printed
== 0)
13815 if (args
== NULL
|| *args
== '\0')
13816 uiout
->message ("No tracepoints.\n");
13818 uiout
->message ("No tracepoint matching '%s'.\n", args
);
13821 default_collect_info ();
13824 /* The 'enable trace' command enables tracepoints.
13825 Not supported by all targets. */
13827 enable_trace_command (const char *args
, int from_tty
)
13829 enable_command (args
, from_tty
);
13832 /* The 'disable trace' command disables tracepoints.
13833 Not supported by all targets. */
13835 disable_trace_command (const char *args
, int from_tty
)
13837 disable_command (args
, from_tty
);
13840 /* Remove a tracepoint (or all if no argument). */
13842 delete_trace_command (const char *arg
, int from_tty
)
13848 int breaks_to_delete
= 0;
13850 /* Delete all breakpoints if no argument.
13851 Do not delete internal or call-dummy breakpoints, these
13852 have to be deleted with an explicit breakpoint number
13854 for (breakpoint
*tp
: all_tracepoints ())
13855 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
13857 breaks_to_delete
= 1;
13861 /* Ask user only if there are some breakpoints to delete. */
13863 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
13865 for (breakpoint
*b
: all_breakpoints_safe ())
13866 if (is_tracepoint (b
) && user_breakpoint_p (b
))
13867 delete_breakpoint (b
);
13871 map_breakpoint_numbers
13872 (arg
, [&] (breakpoint
*br
)
13874 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13878 /* Helper function for trace_pass_command. */
13881 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
13883 tp
->pass_count
= count
;
13884 gdb::observers::breakpoint_modified
.notify (tp
);
13886 gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
13887 tp
->number
, count
);
13890 /* Set passcount for tracepoint.
13892 First command argument is passcount, second is tracepoint number.
13893 If tracepoint number omitted, apply to most recently defined.
13894 Also accepts special argument "all". */
13897 trace_pass_command (const char *args
, int from_tty
)
13899 struct tracepoint
*t1
;
13902 if (args
== 0 || *args
== 0)
13903 error (_("passcount command requires an "
13904 "argument (count + optional TP num)"));
13906 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
13908 args
= skip_spaces (args
);
13909 if (*args
&& strncasecmp (args
, "all", 3) == 0)
13911 args
+= 3; /* Skip special argument "all". */
13913 error (_("Junk at end of arguments."));
13915 for (breakpoint
*b
: all_tracepoints ())
13917 t1
= (struct tracepoint
*) b
;
13918 trace_pass_set_count (t1
, count
, from_tty
);
13921 else if (*args
== '\0')
13923 t1
= get_tracepoint_by_number (&args
, NULL
);
13925 trace_pass_set_count (t1
, count
, from_tty
);
13929 number_or_range_parser
parser (args
);
13930 while (!parser
.finished ())
13932 t1
= get_tracepoint_by_number (&args
, &parser
);
13934 trace_pass_set_count (t1
, count
, from_tty
);
13939 struct tracepoint
*
13940 get_tracepoint (int num
)
13942 for (breakpoint
*t
: all_tracepoints ())
13943 if (t
->number
== num
)
13944 return (struct tracepoint
*) t
;
13949 /* Find the tracepoint with the given target-side number (which may be
13950 different from the tracepoint number after disconnecting and
13953 struct tracepoint
*
13954 get_tracepoint_by_number_on_target (int num
)
13956 for (breakpoint
*b
: all_tracepoints ())
13958 struct tracepoint
*t
= (struct tracepoint
*) b
;
13960 if (t
->number_on_target
== num
)
13967 /* Utility: parse a tracepoint number and look it up in the list.
13968 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
13969 If the argument is missing, the most recent tracepoint
13970 (tracepoint_count) is returned. */
13972 struct tracepoint
*
13973 get_tracepoint_by_number (const char **arg
,
13974 number_or_range_parser
*parser
)
13977 const char *instring
= arg
== NULL
? NULL
: *arg
;
13979 if (parser
!= NULL
)
13981 gdb_assert (!parser
->finished ());
13982 tpnum
= parser
->get_number ();
13984 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
13985 tpnum
= tracepoint_count
;
13987 tpnum
= get_number (arg
);
13991 if (instring
&& *instring
)
13992 gdb_printf (_("bad tracepoint number at or near '%s'\n"),
13995 gdb_printf (_("No previous tracepoint\n"));
13999 for (breakpoint
*t
: all_tracepoints ())
14000 if (t
->number
== tpnum
)
14001 return (struct tracepoint
*) t
;
14003 gdb_printf ("No tracepoint number %d.\n", tpnum
);
14008 breakpoint::print_recreate_thread (struct ui_file
*fp
) const
14011 gdb_printf (fp
, " thread %d", thread
);
14014 gdb_printf (fp
, " task %d", task
);
14016 gdb_printf (fp
, "\n");
14019 /* Save information on user settable breakpoints (watchpoints, etc) to
14020 a new script file named FILENAME. If FILTER is non-NULL, call it
14021 on each breakpoint and only include the ones for which it returns
14025 save_breakpoints (const char *filename
, int from_tty
,
14026 bool (*filter
) (const struct breakpoint
*))
14029 int extra_trace_bits
= 0;
14031 if (filename
== 0 || *filename
== 0)
14032 error (_("Argument required (file name in which to save)"));
14034 /* See if we have anything to save. */
14035 for (breakpoint
*tp
: all_breakpoints ())
14037 /* Skip internal and momentary breakpoints. */
14038 if (!user_breakpoint_p (tp
))
14041 /* If we have a filter, only save the breakpoints it accepts. */
14042 if (filter
&& !filter (tp
))
14047 if (is_tracepoint (tp
))
14049 extra_trace_bits
= 1;
14051 /* We can stop searching. */
14058 warning (_("Nothing to save."));
14062 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14066 if (!fp
.open (expanded_filename
.get (), "w"))
14067 error (_("Unable to open file '%s' for saving (%s)"),
14068 expanded_filename
.get (), safe_strerror (errno
));
14070 if (extra_trace_bits
)
14071 save_trace_state_variables (&fp
);
14073 for (breakpoint
*tp
: all_breakpoints ())
14075 /* Skip internal and momentary breakpoints. */
14076 if (!user_breakpoint_p (tp
))
14079 /* If we have a filter, only save the breakpoints it accepts. */
14080 if (filter
&& !filter (tp
))
14083 tp
->print_recreate (&fp
);
14085 /* Note, we can't rely on tp->number for anything, as we can't
14086 assume the recreated breakpoint numbers will match. Use $bpnum
14089 if (tp
->cond_string
)
14090 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
.get ());
14092 if (tp
->ignore_count
)
14093 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14095 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
14097 fp
.puts (" commands\n");
14099 current_uiout
->redirect (&fp
);
14102 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
14104 catch (const gdb_exception
&ex
)
14106 current_uiout
->redirect (NULL
);
14110 current_uiout
->redirect (NULL
);
14111 fp
.puts (" end\n");
14114 if (tp
->enable_state
== bp_disabled
)
14115 fp
.puts ("disable $bpnum\n");
14117 /* If this is a multi-location breakpoint, check if the locations
14118 should be individually disabled. Watchpoint locations are
14119 special, and not user visible. */
14120 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14124 for (bp_location
*loc
: tp
->locations ())
14127 fp
.printf ("disable $bpnum.%d\n", n
);
14134 if (extra_trace_bits
&& !default_collect
.empty ())
14135 fp
.printf ("set default-collect %s\n", default_collect
.c_str ());
14138 gdb_printf (_("Saved to file '%s'.\n"), expanded_filename
.get ());
14141 /* The `save breakpoints' command. */
14144 save_breakpoints_command (const char *args
, int from_tty
)
14146 save_breakpoints (args
, from_tty
, NULL
);
14149 /* The `save tracepoints' command. */
14152 save_tracepoints_command (const char *args
, int from_tty
)
14154 save_breakpoints (args
, from_tty
, is_tracepoint
);
14158 /* This help string is used to consolidate all the help string for specifying
14159 locations used by several commands. */
14161 #define LOCATION_HELP_STRING \
14162 "Linespecs are colon-separated lists of location parameters, such as\n\
14163 source filename, function name, label name, and line number.\n\
14164 Example: To specify the start of a label named \"the_top\" in the\n\
14165 function \"fact\" in the file \"factorial.c\", use\n\
14166 \"factorial.c:fact:the_top\".\n\
14168 Address locations begin with \"*\" and specify an exact address in the\n\
14169 program. Example: To specify the fourth byte past the start function\n\
14170 \"main\", use \"*main + 4\".\n\
14172 Explicit locations are similar to linespecs but use an option/argument\n\
14173 syntax to specify location parameters.\n\
14174 Example: To specify the start of the label named \"the_top\" in the\n\
14175 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
14176 -function fact -label the_top\".\n\
14178 By default, a specified function is matched against the program's\n\
14179 functions in all scopes. For C++, this means in all namespaces and\n\
14180 classes. For Ada, this means in all packages. E.g., in C++,\n\
14181 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
14182 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
14183 specified name as a complete fully-qualified name instead."
14185 /* This help string is used for the break, hbreak, tbreak and thbreak
14186 commands. It is defined as a macro to prevent duplication.
14187 COMMAND should be a string constant containing the name of the
14190 #define BREAK_ARGS_HELP(command) \
14191 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
14192 \t[-force-condition] [if CONDITION]\n\
14193 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
14194 probe point. Accepted values are `-probe' (for a generic, automatically\n\
14195 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
14196 `-probe-dtrace' (for a DTrace probe).\n\
14197 LOCATION may be a linespec, address, or explicit location as described\n\
14200 With no LOCATION, uses current execution address of the selected\n\
14201 stack frame. This is useful for breaking on return to a stack frame.\n\
14203 THREADNUM is the number from \"info threads\".\n\
14204 CONDITION is a boolean expression.\n\
14206 With the \"-force-condition\" flag, the condition is defined even when\n\
14207 it is invalid for all current locations.\n\
14208 \n" LOCATION_HELP_STRING "\n\n\
14209 Multiple breakpoints at one place are permitted, and useful if their\n\
14210 conditions are different.\n\
14212 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
14214 /* List of subcommands for "catch". */
14215 static struct cmd_list_element
*catch_cmdlist
;
14217 /* List of subcommands for "tcatch". */
14218 static struct cmd_list_element
*tcatch_cmdlist
;
14221 add_catch_command (const char *name
, const char *docstring
,
14222 cmd_func_ftype
*func
,
14223 completer_ftype
*completer
,
14224 void *user_data_catch
,
14225 void *user_data_tcatch
)
14227 struct cmd_list_element
*command
;
14229 command
= add_cmd (name
, class_breakpoint
, docstring
,
14231 command
->func
= func
;
14232 command
->set_context (user_data_catch
);
14233 set_cmd_completer (command
, completer
);
14235 command
= add_cmd (name
, class_breakpoint
, docstring
,
14237 command
->func
= func
;
14238 command
->set_context (user_data_tcatch
);
14239 set_cmd_completer (command
, completer
);
14242 /* Zero if any of the breakpoint's locations could be a location where
14243 functions have been inlined, nonzero otherwise. */
14246 is_non_inline_function (struct breakpoint
*b
)
14248 /* The shared library event breakpoint is set on the address of a
14249 non-inline function. */
14250 if (b
->type
== bp_shlib_event
)
14256 /* Nonzero if the specified PC cannot be a location where functions
14257 have been inlined. */
14260 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
14261 const target_waitstatus
&ws
)
14263 for (breakpoint
*b
: all_breakpoints ())
14265 if (!is_non_inline_function (b
))
14268 for (bp_location
*bl
: b
->locations ())
14270 if (!bl
->shlib_disabled
14271 && bpstat_check_location (bl
, aspace
, pc
, ws
))
14279 /* Remove any references to OBJFILE which is going to be freed. */
14282 breakpoint_free_objfile (struct objfile
*objfile
)
14284 for (bp_location
*loc
: all_bp_locations ())
14285 if (loc
->symtab
!= NULL
&& loc
->symtab
->compunit ()->objfile () == objfile
)
14286 loc
->symtab
= NULL
;
14289 /* Chain containing all defined "enable breakpoint" subcommands. */
14291 static struct cmd_list_element
*enablebreaklist
= NULL
;
14293 /* See breakpoint.h. */
14295 cmd_list_element
*commands_cmd_element
= nullptr;
14297 void _initialize_breakpoint ();
14299 _initialize_breakpoint ()
14301 struct cmd_list_element
*c
;
14303 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
14305 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
14307 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
14310 breakpoint_chain
= 0;
14311 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
14312 before a breakpoint is set. */
14313 breakpoint_count
= 0;
14315 tracepoint_count
= 0;
14317 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
14318 Set ignore-count of breakpoint number N to COUNT.\n\
14319 Usage is `ignore N COUNT'."));
14321 commands_cmd_element
= add_com ("commands", class_breakpoint
,
14322 commands_command
, _("\
14323 Set commands to be executed when the given breakpoints are hit.\n\
14324 Give a space-separated breakpoint list as argument after \"commands\".\n\
14325 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
14327 With no argument, the targeted breakpoint is the last one set.\n\
14328 The commands themselves follow starting on the next line.\n\
14329 Type a line containing \"end\" to indicate the end of them.\n\
14330 Give \"silent\" as the first line to make the breakpoint silent;\n\
14331 then no output is printed when it is hit, except what the commands print."));
14333 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
14334 static std::string condition_command_help
14335 = gdb::option::build_help (_("\
14336 Specify breakpoint number N to break only if COND is true.\n\
14337 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
14338 is an expression to be evaluated whenever breakpoint N is reached.\n\
14341 %OPTIONS%"), cc_opts
);
14343 c
= add_com ("condition", class_breakpoint
, condition_command
,
14344 condition_command_help
.c_str ());
14345 set_cmd_completer_handle_brkchars (c
, condition_completer
);
14347 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
14348 Set a temporary breakpoint.\n\
14349 Like \"break\" except the breakpoint is only temporary,\n\
14350 so it will be deleted when hit. Equivalent to \"break\" followed\n\
14351 by using \"enable delete\" on the breakpoint number.\n\
14353 BREAK_ARGS_HELP ("tbreak")));
14354 set_cmd_completer (c
, location_completer
);
14356 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
14357 Set a hardware assisted breakpoint.\n\
14358 Like \"break\" except the breakpoint requires hardware support,\n\
14359 some target hardware may not have this support.\n\
14361 BREAK_ARGS_HELP ("hbreak")));
14362 set_cmd_completer (c
, location_completer
);
14364 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
14365 Set a temporary hardware assisted breakpoint.\n\
14366 Like \"hbreak\" except the breakpoint is only temporary,\n\
14367 so it will be deleted when hit.\n\
14369 BREAK_ARGS_HELP ("thbreak")));
14370 set_cmd_completer (c
, location_completer
);
14372 cmd_list_element
*enable_cmd
14373 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
14374 Enable all or some breakpoints.\n\
14375 Usage: enable [BREAKPOINTNUM]...\n\
14376 Give breakpoint numbers (separated by spaces) as arguments.\n\
14377 With no subcommand, breakpoints are enabled until you command otherwise.\n\
14378 This is used to cancel the effect of the \"disable\" command.\n\
14379 With a subcommand you can enable temporarily."),
14380 &enablelist
, 1, &cmdlist
);
14382 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
14384 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
14385 Enable all or some breakpoints.\n\
14386 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
14387 Give breakpoint numbers (separated by spaces) as arguments.\n\
14388 This is used to cancel the effect of the \"disable\" command.\n\
14389 May be abbreviated to simply \"enable\"."),
14390 &enablebreaklist
, 1, &enablelist
);
14392 add_cmd ("once", no_class
, enable_once_command
, _("\
14393 Enable some breakpoints for one hit.\n\
14394 Usage: enable breakpoints once BREAKPOINTNUM...\n\
14395 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14398 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14399 Enable some breakpoints and delete when hit.\n\
14400 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
14401 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14404 add_cmd ("count", no_class
, enable_count_command
, _("\
14405 Enable some breakpoints for COUNT hits.\n\
14406 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
14407 If a breakpoint is hit while enabled in this fashion,\n\
14408 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14411 add_cmd ("delete", no_class
, enable_delete_command
, _("\
14412 Enable some breakpoints and delete when hit.\n\
14413 Usage: enable delete BREAKPOINTNUM...\n\
14414 If a breakpoint is hit while enabled in this fashion, it is deleted."),
14417 add_cmd ("once", no_class
, enable_once_command
, _("\
14418 Enable some breakpoints for one hit.\n\
14419 Usage: enable once BREAKPOINTNUM...\n\
14420 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
14423 add_cmd ("count", no_class
, enable_count_command
, _("\
14424 Enable some breakpoints for COUNT hits.\n\
14425 Usage: enable count COUNT BREAKPOINTNUM...\n\
14426 If a breakpoint is hit while enabled in this fashion,\n\
14427 the count is decremented; when it reaches zero, the breakpoint is disabled."),
14430 cmd_list_element
*disable_cmd
14431 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
14432 Disable all or some breakpoints.\n\
14433 Usage: disable [BREAKPOINTNUM]...\n\
14434 Arguments are breakpoint numbers with spaces in between.\n\
14435 To disable all breakpoints, give no argument.\n\
14436 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
14437 &disablelist
, 1, &cmdlist
);
14438 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
14439 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
14441 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
14442 Disable all or some breakpoints.\n\
14443 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
14444 Arguments are breakpoint numbers with spaces in between.\n\
14445 To disable all breakpoints, give no argument.\n\
14446 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
14447 This command may be abbreviated \"disable\"."),
14450 cmd_list_element
*delete_cmd
14451 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
14452 Delete all or some breakpoints.\n\
14453 Usage: delete [BREAKPOINTNUM]...\n\
14454 Arguments are breakpoint numbers with spaces in between.\n\
14455 To delete all breakpoints, give no argument.\n\
14457 Also a prefix command for deletion of other GDB objects."),
14458 &deletelist
, 1, &cmdlist
);
14459 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
14460 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
14462 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
14463 Delete all or some breakpoints or auto-display expressions.\n\
14464 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
14465 Arguments are breakpoint numbers with spaces in between.\n\
14466 To delete all breakpoints, give no argument.\n\
14467 This command may be abbreviated \"delete\"."),
14470 cmd_list_element
*clear_cmd
14471 = add_com ("clear", class_breakpoint
, clear_command
, _("\
14472 Clear breakpoint at specified location.\n\
14473 Argument may be a linespec, explicit, or address location as described below.\n\
14475 With no argument, clears all breakpoints in the line that the selected frame\n\
14476 is executing in.\n"
14477 "\n" LOCATION_HELP_STRING
"\n\n\
14478 See also the \"delete\" command which clears breakpoints by number."));
14479 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
14481 cmd_list_element
*break_cmd
14482 = add_com ("break", class_breakpoint
, break_command
, _("\
14483 Set breakpoint at specified location.\n"
14484 BREAK_ARGS_HELP ("break")));
14485 set_cmd_completer (break_cmd
, location_completer
);
14487 add_com_alias ("b", break_cmd
, class_run
, 1);
14488 add_com_alias ("br", break_cmd
, class_run
, 1);
14489 add_com_alias ("bre", break_cmd
, class_run
, 1);
14490 add_com_alias ("brea", break_cmd
, class_run
, 1);
14492 cmd_list_element
*info_breakpoints_cmd
14493 = add_info ("breakpoints", info_breakpoints_command
, _("\
14494 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
14495 The \"Type\" column indicates one of:\n\
14496 \tbreakpoint - normal breakpoint\n\
14497 \twatchpoint - watchpoint\n\
14498 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14499 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14500 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14501 address and file/line number respectively.\n\
14503 Convenience variable \"$_\" and default examine address for \"x\"\n\
14504 are set to the address of the last breakpoint listed unless the command\n\
14505 is prefixed with \"server \".\n\n\
14506 Convenience variable \"$bpnum\" contains the number of the last\n\
14507 breakpoint set."));
14509 add_info_alias ("b", info_breakpoints_cmd
, 1);
14511 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
14512 Status of all breakpoints, or breakpoint number NUMBER.\n\
14513 The \"Type\" column indicates one of:\n\
14514 \tbreakpoint - normal breakpoint\n\
14515 \twatchpoint - watchpoint\n\
14516 \tlongjmp - internal breakpoint used to step through longjmp()\n\
14517 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
14518 \tuntil - internal breakpoint used by the \"until\" command\n\
14519 \tfinish - internal breakpoint used by the \"finish\" command\n\
14520 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
14521 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
14522 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
14523 address and file/line number respectively.\n\
14525 Convenience variable \"$_\" and default examine address for \"x\"\n\
14526 are set to the address of the last breakpoint listed unless the command\n\
14527 is prefixed with \"server \".\n\n\
14528 Convenience variable \"$bpnum\" contains the number of the last\n\
14530 &maintenanceinfolist
);
14532 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
14533 Set catchpoints to catch events."),
14535 0/*allow-unknown*/, &cmdlist
);
14537 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
14538 Set temporary catchpoints to catch events."),
14540 0/*allow-unknown*/, &cmdlist
);
14542 const auto opts
= make_watch_options_def_group (nullptr);
14544 static const std::string watch_help
= gdb::option::build_help (_("\
14545 Set a watchpoint for EXPRESSION.\n\
14546 Usage: watch [-location] EXPRESSION\n\
14551 A watchpoint stops execution of your program whenever the value of\n\
14552 an expression changes."), opts
);
14553 c
= add_com ("watch", class_breakpoint
, watch_command
,
14554 watch_help
.c_str ());
14555 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14557 static const std::string rwatch_help
= gdb::option::build_help (_("\
14558 Set a read watchpoint for EXPRESSION.\n\
14559 Usage: rwatch [-location] EXPRESSION\n\
14564 A read watchpoint stops execution of your program whenever the value of\n\
14565 an expression is read."), opts
);
14566 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
14567 rwatch_help
.c_str ());
14568 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14570 static const std::string awatch_help
= gdb::option::build_help (_("\
14571 Set an access watchpoint for EXPRESSION.\n\
14572 Usage: awatch [-location] EXPRESSION\n\
14577 An access watchpoint stops execution of your program whenever the value\n\
14578 of an expression is either read or written."), opts
);
14579 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
14580 awatch_help
.c_str ());
14581 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
14583 add_info ("watchpoints", info_watchpoints_command
, _("\
14584 Status of specified watchpoints (all watchpoints if no argument)."));
14586 /* XXX: cagney/2005-02-23: This should be a boolean, and should
14587 respond to changes - contrary to the description. */
14588 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
14589 &can_use_hw_watchpoints
, _("\
14590 Set debugger's willingness to use watchpoint hardware."), _("\
14591 Show debugger's willingness to use watchpoint hardware."), _("\
14592 If zero, gdb will not use hardware for new watchpoints, even if\n\
14593 such is available. (However, any hardware watchpoints that were\n\
14594 created before setting this to nonzero, will continue to use watchpoint\n\
14597 show_can_use_hw_watchpoints
,
14598 &setlist
, &showlist
);
14600 can_use_hw_watchpoints
= 1;
14602 /* Tracepoint manipulation commands. */
14604 cmd_list_element
*trace_cmd
14605 = add_com ("trace", class_breakpoint
, trace_command
, _("\
14606 Set a tracepoint at specified location.\n\
14608 BREAK_ARGS_HELP ("trace") "\n\
14609 Do \"help tracepoints\" for info on other tracepoint commands."));
14610 set_cmd_completer (trace_cmd
, location_completer
);
14612 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
14613 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
14614 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
14615 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
14617 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
14618 Set a fast tracepoint at specified location.\n\
14620 BREAK_ARGS_HELP ("ftrace") "\n\
14621 Do \"help tracepoints\" for info on other tracepoint commands."));
14622 set_cmd_completer (c
, location_completer
);
14624 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
14625 Set a static tracepoint at location or marker.\n\
14627 strace [LOCATION] [if CONDITION]\n\
14628 LOCATION may be a linespec, explicit, or address location (described below) \n\
14629 or -m MARKER_ID.\n\n\
14630 If a marker id is specified, probe the marker with that name. With\n\
14631 no LOCATION, uses current execution address of the selected stack frame.\n\
14632 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
14633 This collects arbitrary user data passed in the probe point call to the\n\
14634 tracing library. You can inspect it when analyzing the trace buffer,\n\
14635 by printing the $_sdata variable like any other convenience variable.\n\
14637 CONDITION is a boolean expression.\n\
14638 \n" LOCATION_HELP_STRING
"\n\n\
14639 Multiple tracepoints at one place are permitted, and useful if their\n\
14640 conditions are different.\n\
14642 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
14643 Do \"help tracepoints\" for info on other tracepoint commands."));
14644 set_cmd_completer (c
, location_completer
);
14646 cmd_list_element
*info_tracepoints_cmd
14647 = add_info ("tracepoints", info_tracepoints_command
, _("\
14648 Status of specified tracepoints (all tracepoints if no argument).\n\
14649 Convenience variable \"$tpnum\" contains the number of the\n\
14650 last tracepoint set."));
14652 add_info_alias ("tp", info_tracepoints_cmd
, 1);
14654 cmd_list_element
*delete_tracepoints_cmd
14655 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
14656 Delete specified tracepoints.\n\
14657 Arguments are tracepoint numbers, separated by spaces.\n\
14658 No argument means delete all tracepoints."),
14660 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
14662 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
14663 Disable specified tracepoints.\n\
14664 Arguments are tracepoint numbers, separated by spaces.\n\
14665 No argument means disable all tracepoints."),
14667 deprecate_cmd (c
, "disable");
14669 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
14670 Enable specified tracepoints.\n\
14671 Arguments are tracepoint numbers, separated by spaces.\n\
14672 No argument means enable all tracepoints."),
14674 deprecate_cmd (c
, "enable");
14676 add_com ("passcount", class_trace
, trace_pass_command
, _("\
14677 Set the passcount for a tracepoint.\n\
14678 The trace will end when the tracepoint has been passed 'count' times.\n\
14679 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
14680 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
14682 add_basic_prefix_cmd ("save", class_breakpoint
,
14683 _("Save breakpoint definitions as a script."),
14685 0/*allow-unknown*/, &cmdlist
);
14687 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
14688 Save current breakpoint definitions as a script.\n\
14689 This includes all types of breakpoints (breakpoints, watchpoints,\n\
14690 catchpoints, tracepoints). Use the 'source' command in another debug\n\
14691 session to restore them."),
14693 set_cmd_completer (c
, filename_completer
);
14695 cmd_list_element
*save_tracepoints_cmd
14696 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
14697 Save current tracepoint definitions as a script.\n\
14698 Use the 'source' command in another debug session to restore them."),
14700 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
14702 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
14703 deprecate_cmd (c
, "save tracepoints");
14705 add_setshow_prefix_cmd ("breakpoint", class_maintenance
,
14707 Breakpoint specific settings.\n\
14708 Configure various breakpoint-specific variables such as\n\
14709 pending breakpoint behavior."),
14711 Breakpoint specific settings.\n\
14712 Configure various breakpoint-specific variables such as\n\
14713 pending breakpoint behavior."),
14714 &breakpoint_set_cmdlist
, &breakpoint_show_cmdlist
,
14715 &setlist
, &showlist
);
14717 add_setshow_auto_boolean_cmd ("pending", no_class
,
14718 &pending_break_support
, _("\
14719 Set debugger's behavior regarding pending breakpoints."), _("\
14720 Show debugger's behavior regarding pending breakpoints."), _("\
14721 If on, an unrecognized breakpoint location will cause gdb to create a\n\
14722 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
14723 an error. If auto, an unrecognized breakpoint location results in a\n\
14724 user-query to see if a pending breakpoint should be created."),
14726 show_pending_break_support
,
14727 &breakpoint_set_cmdlist
,
14728 &breakpoint_show_cmdlist
);
14730 pending_break_support
= AUTO_BOOLEAN_AUTO
;
14732 add_setshow_boolean_cmd ("auto-hw", no_class
,
14733 &automatic_hardware_breakpoints
, _("\
14734 Set automatic usage of hardware breakpoints."), _("\
14735 Show automatic usage of hardware breakpoints."), _("\
14736 If set, the debugger will automatically use hardware breakpoints for\n\
14737 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
14738 a warning will be emitted for such breakpoints."),
14740 show_automatic_hardware_breakpoints
,
14741 &breakpoint_set_cmdlist
,
14742 &breakpoint_show_cmdlist
);
14744 add_setshow_boolean_cmd ("always-inserted", class_support
,
14745 &always_inserted_mode
, _("\
14746 Set mode for inserting breakpoints."), _("\
14747 Show mode for inserting breakpoints."), _("\
14748 When this mode is on, breakpoints are inserted immediately as soon as\n\
14749 they're created, kept inserted even when execution stops, and removed\n\
14750 only when the user deletes them. When this mode is off (the default),\n\
14751 breakpoints are inserted only when execution continues, and removed\n\
14752 when execution stops."),
14754 &show_always_inserted_mode
,
14755 &breakpoint_set_cmdlist
,
14756 &breakpoint_show_cmdlist
);
14758 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
14759 condition_evaluation_enums
,
14760 &condition_evaluation_mode_1
, _("\
14761 Set mode of breakpoint condition evaluation."), _("\
14762 Show mode of breakpoint condition evaluation."), _("\
14763 When this is set to \"host\", breakpoint conditions will be\n\
14764 evaluated on the host's side by GDB. When it is set to \"target\",\n\
14765 breakpoint conditions will be downloaded to the target (if the target\n\
14766 supports such feature) and conditions will be evaluated on the target's side.\n\
14767 If this is set to \"auto\" (default), this will be automatically set to\n\
14768 \"target\" if it supports condition evaluation, otherwise it will\n\
14769 be set to \"host\"."),
14770 &set_condition_evaluation_mode
,
14771 &show_condition_evaluation_mode
,
14772 &breakpoint_set_cmdlist
,
14773 &breakpoint_show_cmdlist
);
14775 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
14776 Set a breakpoint for an address range.\n\
14777 break-range START-LOCATION, END-LOCATION\n\
14778 where START-LOCATION and END-LOCATION can be one of the following:\n\
14779 LINENUM, for that line in the current file,\n\
14780 FILE:LINENUM, for that line in that file,\n\
14781 +OFFSET, for that number of lines after the current line\n\
14782 or the start of the range\n\
14783 FUNCTION, for the first line in that function,\n\
14784 FILE:FUNCTION, to distinguish among like-named static functions.\n\
14785 *ADDRESS, for the instruction at that address.\n\
14787 The breakpoint will stop execution of the inferior whenever it executes\n\
14788 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
14789 range (including START-LOCATION and END-LOCATION)."));
14791 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
14792 Set a dynamic printf at specified location.\n\
14793 dprintf location,format string,arg1,arg2,...\n\
14794 location may be a linespec, explicit, or address location.\n"
14795 "\n" LOCATION_HELP_STRING
));
14796 set_cmd_completer (c
, location_completer
);
14798 add_setshow_enum_cmd ("dprintf-style", class_support
,
14799 dprintf_style_enums
, &dprintf_style
, _("\
14800 Set the style of usage for dynamic printf."), _("\
14801 Show the style of usage for dynamic printf."), _("\
14802 This setting chooses how GDB will do a dynamic printf.\n\
14803 If the value is \"gdb\", then the printing is done by GDB to its own\n\
14804 console, as with the \"printf\" command.\n\
14805 If the value is \"call\", the print is done by calling a function in your\n\
14806 program; by default printf(), but you can choose a different function or\n\
14807 output stream by setting dprintf-function and dprintf-channel."),
14808 update_dprintf_commands
, NULL
,
14809 &setlist
, &showlist
);
14811 add_setshow_string_cmd ("dprintf-function", class_support
,
14812 &dprintf_function
, _("\
14813 Set the function to use for dynamic printf."), _("\
14814 Show the function to use for dynamic printf."), NULL
,
14815 update_dprintf_commands
, NULL
,
14816 &setlist
, &showlist
);
14818 add_setshow_string_cmd ("dprintf-channel", class_support
,
14819 &dprintf_channel
, _("\
14820 Set the channel to use for dynamic printf."), _("\
14821 Show the channel to use for dynamic printf."), NULL
,
14822 update_dprintf_commands
, NULL
,
14823 &setlist
, &showlist
);
14825 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
14826 &disconnected_dprintf
, _("\
14827 Set whether dprintf continues after GDB disconnects."), _("\
14828 Show whether dprintf continues after GDB disconnects."), _("\
14829 Use this to let dprintf commands continue to hit and produce output\n\
14830 even if GDB disconnects or detaches from the target."),
14833 &setlist
, &showlist
);
14835 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
14836 Target agent only formatted printing, like the C \"printf\" function.\n\
14837 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
14838 This supports most C printf format specifications, like %s, %d, etc.\n\
14839 This is useful for formatted output in user-defined commands."));
14841 automatic_hardware_breakpoints
= true;
14843 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
14845 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,