1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2021 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
48 #include "cli/cli-script.h"
52 #include "observable.h"
58 #include "parser-defs.h"
59 #include "gdb_regex.h"
61 #include "cli/cli-utils.h"
64 #include "dummy-frame.h"
66 #include "gdbsupport/format.h"
67 #include "thread-fsm.h"
68 #include "tid-parse.h"
69 #include "cli/cli-style.h"
71 /* readline include files */
72 #include "readline/tilde.h"
74 /* readline defines this. */
77 #include "mi/mi-common.h"
78 #include "extension.h"
80 #include "progspace-and-thread.h"
81 #include "gdbsupport/array-view.h"
82 #include "gdbsupport/gdb_optional.h"
84 /* Prototypes for local functions. */
86 static void map_breakpoint_numbers (const char *,
87 gdb::function_view
<void (breakpoint
*)>);
89 static void breakpoint_re_set_default (struct breakpoint
*);
92 create_sals_from_location_default (struct event_location
*location
,
93 struct linespec_result
*canonical
,
94 enum bptype type_wanted
);
96 static void create_breakpoints_sal_default (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 const struct breakpoint_ops
*);
118 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
119 const struct symtab_and_line
*);
121 /* This function is used in gdbtk sources and thus can not be made
123 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
124 struct symtab_and_line
,
126 const struct breakpoint_ops
*);
128 static struct breakpoint
*
129 momentary_breakpoint_from_master (struct breakpoint
*orig
,
131 const struct breakpoint_ops
*ops
,
134 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
136 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
140 static void describe_other_breakpoints (struct gdbarch
*,
141 struct program_space
*, CORE_ADDR
,
142 struct obj_section
*, int);
144 static int watchpoint_locations_match (struct bp_location
*loc1
,
145 struct bp_location
*loc2
);
147 static int breakpoint_locations_match (struct bp_location
*loc1
,
148 struct bp_location
*loc2
,
149 bool sw_hw_bps_match
= false);
151 static int breakpoint_location_address_match (struct bp_location
*bl
,
152 const struct address_space
*aspace
,
155 static int breakpoint_location_address_range_overlap (struct bp_location
*,
156 const address_space
*,
159 static int remove_breakpoint (struct bp_location
*);
160 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
162 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
164 static int hw_breakpoint_used_count (void);
166 static int hw_watchpoint_use_count (struct breakpoint
*);
168 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
170 int *other_type_used
);
172 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
175 static void decref_bp_location (struct bp_location
**loc
);
177 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
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 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
232 that are implemented on top of software or hardware breakpoints
233 (user breakpoints, internal and momentary breakpoints, etc.). */
234 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
236 /* Internal breakpoints class type. */
237 static struct breakpoint_ops internal_breakpoint_ops
;
239 /* Momentary breakpoints class type. */
240 static struct breakpoint_ops momentary_breakpoint_ops
;
242 /* The breakpoint_ops structure to be used in regular user created
244 struct breakpoint_ops bkpt_breakpoint_ops
;
246 /* Breakpoints set on probes. */
247 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
249 /* Tracepoints set on probes. */
250 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
252 /* Dynamic printf class type. */
253 struct breakpoint_ops dprintf_breakpoint_ops
;
255 /* The style in which to perform a dynamic printf. This is a user
256 option because different output options have different tradeoffs;
257 if GDB does the printing, there is better error handling if there
258 is a problem with any of the arguments, but using an inferior
259 function lets you have special-purpose printers and sending of
260 output to the same place as compiled-in print functions. */
262 static const char dprintf_style_gdb
[] = "gdb";
263 static const char dprintf_style_call
[] = "call";
264 static const char dprintf_style_agent
[] = "agent";
265 static const char *const dprintf_style_enums
[] = {
271 static const char *dprintf_style
= dprintf_style_gdb
;
273 /* The function to use for dynamic printf if the preferred style is to
274 call into the inferior. The value is simply a string that is
275 copied into the command, so it can be anything that GDB can
276 evaluate to a callable address, not necessarily a function name. */
278 static char *dprintf_function
;
280 /* The channel to use for dynamic printf if the preferred style is to
281 call into the inferior; if a nonempty string, it will be passed to
282 the call as the first argument, with the format string as the
283 second. As with the dprintf function, this can be anything that
284 GDB knows how to evaluate, so in addition to common choices like
285 "stderr", this could be an app-specific expression like
286 "mystreams[curlogger]". */
288 static char *dprintf_channel
;
290 /* True if dprintf commands should continue to operate even if GDB
292 static bool disconnected_dprintf
= true;
294 struct command_line
*
295 breakpoint_commands (struct breakpoint
*b
)
297 return b
->commands
? b
->commands
.get () : NULL
;
300 /* Flag indicating that a command has proceeded the inferior past the
301 current breakpoint. */
303 static bool breakpoint_proceeded
;
306 bpdisp_text (enum bpdisp disp
)
308 /* NOTE: the following values are a part of MI protocol and
309 represent values of 'disp' field returned when inferior stops at
311 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
313 return bpdisps
[(int) disp
];
316 /* Prototypes for exported functions. */
317 /* If FALSE, gdb will not use hardware support for watchpoints, even
318 if such is available. */
319 static int can_use_hw_watchpoints
;
322 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
323 struct cmd_list_element
*c
,
326 fprintf_filtered (file
,
327 _("Debugger's willingness to use "
328 "watchpoint hardware is %s.\n"),
332 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
333 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
334 for unrecognized breakpoint locations.
335 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
336 static enum auto_boolean pending_break_support
;
338 show_pending_break_support (struct ui_file
*file
, int from_tty
,
339 struct cmd_list_element
*c
,
342 fprintf_filtered (file
,
343 _("Debugger's behavior regarding "
344 "pending breakpoints is %s.\n"),
348 /* If true, gdb will automatically use hardware breakpoints for breakpoints
349 set with "break" but falling in read-only memory.
350 If false, gdb will warn about such breakpoints, but won't automatically
351 use hardware breakpoints. */
352 static bool automatic_hardware_breakpoints
;
354 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
355 struct cmd_list_element
*c
,
358 fprintf_filtered (file
,
359 _("Automatic usage of hardware breakpoints is %s.\n"),
363 /* If on, GDB keeps breakpoints inserted even if the inferior is
364 stopped, and immediately inserts any new breakpoints as soon as
365 they're created. If off (default), GDB keeps breakpoints off of
366 the target as long as possible. That is, it delays inserting
367 breakpoints until the next resume, and removes them again when the
368 target fully stops. This is a bit safer in case GDB crashes while
369 processing user input. */
370 static bool always_inserted_mode
= false;
373 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
374 struct cmd_list_element
*c
, const char *value
)
376 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
380 /* See breakpoint.h. */
383 breakpoints_should_be_inserted_now (void)
385 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
387 /* If breakpoints are global, they should be inserted even if no
388 thread under gdb's control is running, or even if there are
389 no threads under GDB's control yet. */
394 if (always_inserted_mode
)
396 /* The user wants breakpoints inserted even if all threads
401 for (inferior
*inf
: all_inferiors ())
402 if (inf
->has_execution ()
403 && threads_are_executing (inf
->process_target ()))
406 /* Don't remove breakpoints yet if, even though all threads are
407 stopped, we still have events to process. */
408 for (thread_info
*tp
: all_non_exited_threads ())
410 && tp
->suspend
.waitstatus_pending_p
)
416 static const char condition_evaluation_both
[] = "host or target";
418 /* Modes for breakpoint condition evaluation. */
419 static const char condition_evaluation_auto
[] = "auto";
420 static const char condition_evaluation_host
[] = "host";
421 static const char condition_evaluation_target
[] = "target";
422 static const char *const condition_evaluation_enums
[] = {
423 condition_evaluation_auto
,
424 condition_evaluation_host
,
425 condition_evaluation_target
,
429 /* Global that holds the current mode for breakpoint condition evaluation. */
430 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
432 /* Global that we use to display information to the user (gets its value from
433 condition_evaluation_mode_1. */
434 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
436 /* Translate a condition evaluation mode MODE into either "host"
437 or "target". This is used mostly to translate from "auto" to the
438 real setting that is being used. It returns the translated
442 translate_condition_evaluation_mode (const char *mode
)
444 if (mode
== condition_evaluation_auto
)
446 if (target_supports_evaluation_of_breakpoint_conditions ())
447 return condition_evaluation_target
;
449 return condition_evaluation_host
;
455 /* Discovers what condition_evaluation_auto translates to. */
458 breakpoint_condition_evaluation_mode (void)
460 return translate_condition_evaluation_mode (condition_evaluation_mode
);
463 /* Return true if GDB should evaluate breakpoint conditions or false
467 gdb_evaluates_breakpoint_condition_p (void)
469 const char *mode
= breakpoint_condition_evaluation_mode ();
471 return (mode
== condition_evaluation_host
);
474 /* Are we executing breakpoint commands? */
475 static int executing_breakpoint_commands
;
477 /* Are overlay event breakpoints enabled? */
478 static int overlay_events_enabled
;
480 /* See description in breakpoint.h. */
481 bool target_exact_watchpoints
= false;
483 /* Walk the following statement or block through all breakpoints.
484 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
485 current breakpoint. */
487 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
488 for (B = breakpoint_chain; \
489 B ? (TMP=B->next, 1): 0; \
492 /* Chains of all breakpoints defined. */
494 static struct breakpoint
*breakpoint_chain
;
496 /* Breakpoint linked list range. */
498 using breakpoint_range
= next_adapter
<breakpoint
, breakpoint_iterator
>;
500 /* Return a range to iterate over all breakpoints. */
502 static breakpoint_range
505 return breakpoint_range (breakpoint_chain
);
508 /* Breakpoint linked list range, safe against deletion of the current
509 breakpoint while iterating. */
511 using breakpoint_safe_range
= basic_safe_range
<breakpoint_range
>;
513 /* Return a range to iterate over all breakpoints. This range is safe against
514 deletion of the current breakpoint while iterating. */
516 static breakpoint_safe_range
517 all_breakpoints_safe ()
519 return breakpoint_safe_range (all_breakpoints ());
522 /* See breakpoint.h. */
527 return tracepoint_range (breakpoint_chain
);
530 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
532 static std::vector
<bp_location
*> bp_locations
;
534 static const std::vector
<bp_location
*> &
540 /* Range to iterate over breakpoint locations at a given address. */
542 struct bp_locations_at_addr_range
544 using iterator
= std::vector
<bp_location
*>::iterator
;
546 bp_locations_at_addr_range (CORE_ADDR addr
)
550 bool operator() (const bp_location
*loc
, CORE_ADDR addr_
) const
551 { return loc
->address
< addr_
; }
553 bool operator() (CORE_ADDR addr_
, const bp_location
*loc
) const
554 { return addr_
< loc
->address
; }
557 auto it_pair
= std::equal_range (bp_locations
.begin (), bp_locations
.end (),
560 m_begin
= it_pair
.first
;
561 m_end
= it_pair
.second
;
564 iterator
begin () const
567 iterator
end () const
575 /* Return a range to iterate over all breakpoint locations exactly at address
578 If it's needed to iterate multiple times on the same range, it's possible
579 to save the range in a local variable and use it multiple times:
581 auto range = all_bp_locations_at_addr (addr);
583 for (bp_location *loc : range)
586 for (bp_location *loc : range)
589 This saves a bit of time, as it avoids re-doing the binary searches to find
590 the range's boundaries. Just remember not to change the bp_locations vector
591 in the mean time, as it could make the range's iterators stale. */
593 static bp_locations_at_addr_range
594 all_bp_locations_at_addr (CORE_ADDR addr
)
596 return bp_locations_at_addr_range (addr
);
599 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
600 ADDRESS for the current elements of BP_LOCATIONS which get a valid
601 result from bp_location_has_shadow. You can use it for roughly
602 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
603 an address you need to read. */
605 static CORE_ADDR bp_locations_placed_address_before_address_max
;
607 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
608 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
609 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
610 You can use it for roughly limiting the subrange of BP_LOCATIONS to
611 scan for shadow bytes for an address you need to read. */
613 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
615 /* The locations that no longer correspond to any breakpoint, unlinked
616 from the bp_locations array, but for which a hit may still be
617 reported by a target. */
618 static std::vector
<bp_location
*> moribund_locations
;
620 /* Number of last breakpoint made. */
622 static int breakpoint_count
;
624 /* The value of `breakpoint_count' before the last command that
625 created breakpoints. If the last (break-like) command created more
626 than one breakpoint, then the difference between BREAKPOINT_COUNT
627 and PREV_BREAKPOINT_COUNT is more than one. */
628 static int prev_breakpoint_count
;
630 /* Number of last tracepoint made. */
632 static int tracepoint_count
;
634 static struct cmd_list_element
*breakpoint_set_cmdlist
;
635 static struct cmd_list_element
*breakpoint_show_cmdlist
;
636 struct cmd_list_element
*save_cmdlist
;
638 /* See declaration at breakpoint.h. */
641 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
644 for (breakpoint
*b
: all_breakpoints ())
645 if (func (b
, user_data
) != 0)
651 /* Return whether a breakpoint is an active enabled breakpoint. */
653 breakpoint_enabled (struct breakpoint
*b
)
655 return (b
->enable_state
== bp_enabled
);
658 /* Set breakpoint count to NUM. */
661 set_breakpoint_count (int num
)
663 prev_breakpoint_count
= breakpoint_count
;
664 breakpoint_count
= num
;
665 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
668 /* Used by `start_rbreak_breakpoints' below, to record the current
669 breakpoint count before "rbreak" creates any breakpoint. */
670 static int rbreak_start_breakpoint_count
;
672 /* Called at the start an "rbreak" command to record the first
675 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
677 rbreak_start_breakpoint_count
= breakpoint_count
;
680 /* Called at the end of an "rbreak" command to record the last
683 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
685 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
688 /* Used in run_command to zero the hit count when a new run starts. */
691 clear_breakpoint_hit_counts (void)
693 for (breakpoint
*b
: all_breakpoints ())
698 /* Return the breakpoint with the specified number, or NULL
699 if the number does not refer to an existing breakpoint. */
702 get_breakpoint (int num
)
704 for (breakpoint
*b
: all_breakpoints ())
705 if (b
->number
== num
)
713 /* Mark locations as "conditions have changed" in case the target supports
714 evaluating conditions on its side. */
717 mark_breakpoint_modified (struct breakpoint
*b
)
719 /* This is only meaningful if the target is
720 evaluating conditions and if the user has
721 opted for condition evaluation on the target's
723 if (gdb_evaluates_breakpoint_condition_p ()
724 || !target_supports_evaluation_of_breakpoint_conditions ())
727 if (!is_breakpoint (b
))
730 for (bp_location
*loc
: b
->locations ())
731 loc
->condition_changed
= condition_modified
;
734 /* Mark location as "conditions have changed" in case the target supports
735 evaluating conditions on its side. */
738 mark_breakpoint_location_modified (struct bp_location
*loc
)
740 /* This is only meaningful if the target is
741 evaluating conditions and if the user has
742 opted for condition evaluation on the target's
744 if (gdb_evaluates_breakpoint_condition_p ()
745 || !target_supports_evaluation_of_breakpoint_conditions ())
749 if (!is_breakpoint (loc
->owner
))
752 loc
->condition_changed
= condition_modified
;
755 /* Sets the condition-evaluation mode using the static global
756 condition_evaluation_mode. */
759 set_condition_evaluation_mode (const char *args
, int from_tty
,
760 struct cmd_list_element
*c
)
762 const char *old_mode
, *new_mode
;
764 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
765 && !target_supports_evaluation_of_breakpoint_conditions ())
767 condition_evaluation_mode_1
= condition_evaluation_mode
;
768 warning (_("Target does not support breakpoint condition evaluation.\n"
769 "Using host evaluation mode instead."));
773 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
774 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
776 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
777 settings was "auto". */
778 condition_evaluation_mode
= condition_evaluation_mode_1
;
780 /* Only update the mode if the user picked a different one. */
781 if (new_mode
!= old_mode
)
783 /* If the user switched to a different evaluation mode, we
784 need to synch the changes with the target as follows:
786 "host" -> "target": Send all (valid) conditions to the target.
787 "target" -> "host": Remove all the conditions from the target.
790 if (new_mode
== condition_evaluation_target
)
792 /* Mark everything modified and synch conditions with the
794 for (bp_location
*loc
: all_bp_locations ())
795 mark_breakpoint_location_modified (loc
);
799 /* Manually mark non-duplicate locations to synch conditions
800 with the target. We do this to remove all the conditions the
801 target knows about. */
802 for (bp_location
*loc
: all_bp_locations ())
803 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
804 loc
->needs_update
= 1;
808 update_global_location_list (UGLL_MAY_INSERT
);
814 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
815 what "auto" is translating to. */
818 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
819 struct cmd_list_element
*c
, const char *value
)
821 if (condition_evaluation_mode
== condition_evaluation_auto
)
822 fprintf_filtered (file
,
823 _("Breakpoint condition evaluation "
824 "mode is %s (currently %s).\n"),
826 breakpoint_condition_evaluation_mode ());
828 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
832 /* Parse COND_STRING in the context of LOC and set as the condition
833 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
834 the number of LOC within its owner. In case of parsing error, mark
835 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
838 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
839 int bp_num
, int loc_num
)
841 bool has_junk
= false;
844 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
845 block_for_pc (loc
->address
), 0);
846 if (*cond_string
!= 0)
850 loc
->cond
= std::move (new_exp
);
851 if (loc
->disabled_by_cond
&& loc
->enabled
)
852 printf_filtered (_("Breakpoint %d's condition is now valid at "
853 "location %d, enabling.\n"),
856 loc
->disabled_by_cond
= false;
859 catch (const gdb_exception_error
&e
)
863 /* Warn if a user-enabled location is now becoming disabled-by-cond.
864 BP_NUM is 0 if the breakpoint is being defined for the first
865 time using the "break ... if ..." command, and non-zero if
868 warning (_("failed to validate condition at location %d.%d, "
869 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
871 warning (_("failed to validate condition at location %d, "
872 "disabling:\n %s"), loc_num
, e
.what ());
875 loc
->disabled_by_cond
= true;
879 error (_("Garbage '%s' follows condition"), cond_string
);
883 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
884 int from_tty
, bool force
)
888 xfree (b
->cond_string
);
889 b
->cond_string
= nullptr;
891 if (is_watchpoint (b
))
892 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
896 for (bp_location
*loc
: b
->locations ())
899 if (loc
->disabled_by_cond
&& loc
->enabled
)
900 printf_filtered (_("Breakpoint %d's condition is now valid at "
901 "location %d, enabling.\n"),
903 loc
->disabled_by_cond
= false;
906 /* No need to free the condition agent expression
907 bytecode (if we have one). We will handle this
908 when we go through update_global_location_list. */
913 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
917 if (is_watchpoint (b
))
919 innermost_block_tracker tracker
;
920 const char *arg
= exp
;
921 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
923 error (_("Junk at end of expression"));
924 watchpoint
*w
= static_cast<watchpoint
*> (b
);
925 w
->cond_exp
= std::move (new_exp
);
926 w
->cond_exp_valid_block
= tracker
.block ();
930 /* Parse and set condition expressions. We make two passes.
931 In the first, we parse the condition string to see if it
932 is valid in at least one location. If so, the condition
933 would be accepted. So we go ahead and set the locations'
934 conditions. In case no valid case is found, we throw
935 the error and the condition string will be rejected.
936 This two-pass approach is taken to avoid setting the
937 state of locations in case of a reject. */
938 for (bp_location
*loc
: b
->locations ())
942 const char *arg
= exp
;
943 parse_exp_1 (&arg
, loc
->address
,
944 block_for_pc (loc
->address
), 0);
946 error (_("Junk at end of expression"));
949 catch (const gdb_exception_error
&e
)
951 /* Condition string is invalid. If this happens to
952 be the last loc, abandon (if not forced) or continue
954 if (loc
->next
== nullptr && !force
)
959 /* If we reach here, the condition is valid at some locations. */
961 for (bp_location
*loc
: b
->locations ())
963 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
968 /* We know that the new condition parsed successfully. The
969 condition string of the breakpoint can be safely updated. */
970 xfree (b
->cond_string
);
971 b
->cond_string
= xstrdup (exp
);
972 b
->condition_not_parsed
= 0;
974 mark_breakpoint_modified (b
);
976 gdb::observers::breakpoint_modified
.notify (b
);
979 /* See breakpoint.h. */
982 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
985 for (breakpoint
*b
: all_breakpoints ())
986 if (b
->number
== bpnum
)
988 /* Check if this breakpoint has a "stop" method implemented in an
989 extension language. This method and conditions entered into GDB
990 from the CLI are mutually exclusive. */
991 const struct extension_language_defn
*extlang
992 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
996 error (_("Only one stop condition allowed. There is currently"
997 " a %s stop condition defined for this breakpoint."),
998 ext_lang_capitalized_name (extlang
));
1000 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1002 if (is_breakpoint (b
))
1003 update_global_location_list (UGLL_MAY_INSERT
);
1008 error (_("No breakpoint number %d."), bpnum
);
1011 /* The options for the "condition" command. */
1013 struct condition_command_opts
1016 bool force_condition
= false;
1019 static const gdb::option::option_def condition_command_option_defs
[] = {
1021 gdb::option::flag_option_def
<condition_command_opts
> {
1023 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1024 N_("Set the condition even if it is invalid for all current locations."),
1029 /* Create an option_def_group for the "condition" options, with
1030 CC_OPTS as context. */
1032 static inline gdb::option::option_def_group
1033 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1035 return {{condition_command_option_defs
}, cc_opts
};
1038 /* Completion for the "condition" command. */
1041 condition_completer (struct cmd_list_element
*cmd
,
1042 completion_tracker
&tracker
,
1043 const char *text
, const char * /*word*/)
1045 bool has_no_arguments
= (*text
== '\0');
1046 condition_command_opts cc_opts
;
1047 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1048 if (gdb::option::complete_options
1049 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1052 text
= skip_spaces (text
);
1053 const char *space
= skip_to_space (text
);
1060 tracker
.advance_custom_word_point_by (1);
1061 /* We don't support completion of history indices. */
1062 if (!isdigit (text
[1]))
1063 complete_internalvar (tracker
, &text
[1]);
1067 /* Suggest the "-force" flag if no arguments are given. If
1068 arguments were passed, they either already include the flag,
1069 or we are beyond the point of suggesting it because it's
1070 positionally the first argument. */
1071 if (has_no_arguments
)
1072 gdb::option::complete_on_all_options (tracker
, group
);
1074 /* We're completing the breakpoint number. */
1075 len
= strlen (text
);
1077 for (breakpoint
*b
: all_breakpoints ())
1081 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1083 if (strncmp (number
, text
, len
) == 0)
1084 tracker
.add_completion (make_unique_xstrdup (number
));
1090 /* We're completing the expression part. Skip the breakpoint num. */
1091 const char *exp_start
= skip_spaces (space
);
1092 tracker
.advance_custom_word_point_by (exp_start
- text
);
1094 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1095 expression_completer (cmd
, tracker
, text
, word
);
1098 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1101 condition_command (const char *arg
, int from_tty
)
1107 error_no_arg (_("breakpoint number"));
1111 /* Check if the "-force" flag was passed. */
1112 condition_command_opts cc_opts
;
1113 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1114 gdb::option::process_options
1115 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1117 bnum
= get_number (&p
);
1119 error (_("Bad breakpoint argument: '%s'"), arg
);
1121 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1124 /* Check that COMMAND do not contain commands that are suitable
1125 only for tracepoints and not suitable for ordinary breakpoints.
1126 Throw if any such commands is found. */
1129 check_no_tracepoint_commands (struct command_line
*commands
)
1131 struct command_line
*c
;
1133 for (c
= commands
; c
; c
= c
->next
)
1135 if (c
->control_type
== while_stepping_control
)
1136 error (_("The 'while-stepping' command can "
1137 "only be used for tracepoints"));
1139 check_no_tracepoint_commands (c
->body_list_0
.get ());
1140 check_no_tracepoint_commands (c
->body_list_1
.get ());
1142 /* Not that command parsing removes leading whitespace and comment
1143 lines and also empty lines. So, we only need to check for
1144 command directly. */
1145 if (strstr (c
->line
, "collect ") == c
->line
)
1146 error (_("The 'collect' command can only be used for tracepoints"));
1148 if (strstr (c
->line
, "teval ") == c
->line
)
1149 error (_("The 'teval' command can only be used for tracepoints"));
1153 struct longjmp_breakpoint
: public breakpoint
1155 ~longjmp_breakpoint () override
;
1158 /* Encapsulate tests for different types of tracepoints. */
1161 is_tracepoint_type (bptype type
)
1163 return (type
== bp_tracepoint
1164 || type
== bp_fast_tracepoint
1165 || type
== bp_static_tracepoint
);
1169 is_longjmp_type (bptype type
)
1171 return type
== bp_longjmp
|| type
== bp_exception
;
1174 /* See breakpoint.h. */
1177 is_tracepoint (const struct breakpoint
*b
)
1179 return is_tracepoint_type (b
->type
);
1182 /* Factory function to create an appropriate instance of breakpoint given
1185 static std::unique_ptr
<breakpoint
>
1186 new_breakpoint_from_type (bptype type
)
1190 if (is_tracepoint_type (type
))
1191 b
= new tracepoint ();
1192 else if (is_longjmp_type (type
))
1193 b
= new longjmp_breakpoint ();
1195 b
= new breakpoint ();
1197 return std::unique_ptr
<breakpoint
> (b
);
1200 /* A helper function that validates that COMMANDS are valid for a
1201 breakpoint. This function will throw an exception if a problem is
1205 validate_commands_for_breakpoint (struct breakpoint
*b
,
1206 struct command_line
*commands
)
1208 if (is_tracepoint (b
))
1210 struct tracepoint
*t
= (struct tracepoint
*) b
;
1211 struct command_line
*c
;
1212 struct command_line
*while_stepping
= 0;
1214 /* Reset the while-stepping step count. The previous commands
1215 might have included a while-stepping action, while the new
1219 /* We need to verify that each top-level element of commands is
1220 valid for tracepoints, that there's at most one
1221 while-stepping element, and that the while-stepping's body
1222 has valid tracing commands excluding nested while-stepping.
1223 We also need to validate the tracepoint action line in the
1224 context of the tracepoint --- validate_actionline actually
1225 has side effects, like setting the tracepoint's
1226 while-stepping STEP_COUNT, in addition to checking if the
1227 collect/teval actions parse and make sense in the
1228 tracepoint's context. */
1229 for (c
= commands
; c
; c
= c
->next
)
1231 if (c
->control_type
== while_stepping_control
)
1233 if (b
->type
== bp_fast_tracepoint
)
1234 error (_("The 'while-stepping' command "
1235 "cannot be used for fast tracepoint"));
1236 else if (b
->type
== bp_static_tracepoint
)
1237 error (_("The 'while-stepping' command "
1238 "cannot be used for static tracepoint"));
1241 error (_("The 'while-stepping' command "
1242 "can be used only once"));
1247 validate_actionline (c
->line
, b
);
1251 struct command_line
*c2
;
1253 gdb_assert (while_stepping
->body_list_1
== nullptr);
1254 c2
= while_stepping
->body_list_0
.get ();
1255 for (; c2
; c2
= c2
->next
)
1257 if (c2
->control_type
== while_stepping_control
)
1258 error (_("The 'while-stepping' command cannot be nested"));
1264 check_no_tracepoint_commands (commands
);
1268 /* Return a vector of all the static tracepoints set at ADDR. The
1269 caller is responsible for releasing the vector. */
1271 std::vector
<breakpoint
*>
1272 static_tracepoints_here (CORE_ADDR addr
)
1274 std::vector
<breakpoint
*> found
;
1276 for (breakpoint
*b
: all_breakpoints ())
1277 if (b
->type
== bp_static_tracepoint
)
1279 for (bp_location
*loc
: b
->locations ())
1280 if (loc
->address
== addr
)
1281 found
.push_back (b
);
1287 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1288 validate that only allowed commands are included. */
1291 breakpoint_set_commands (struct breakpoint
*b
,
1292 counted_command_line
&&commands
)
1294 validate_commands_for_breakpoint (b
, commands
.get ());
1296 b
->commands
= std::move (commands
);
1297 gdb::observers::breakpoint_modified
.notify (b
);
1300 /* Set the internal `silent' flag on the breakpoint. Note that this
1301 is not the same as the "silent" that may appear in the breakpoint's
1305 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1307 int old_silent
= b
->silent
;
1310 if (old_silent
!= silent
)
1311 gdb::observers::breakpoint_modified
.notify (b
);
1314 /* Set the thread for this breakpoint. If THREAD is -1, make the
1315 breakpoint work for any thread. */
1318 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1320 int old_thread
= b
->thread
;
1323 if (old_thread
!= thread
)
1324 gdb::observers::breakpoint_modified
.notify (b
);
1327 /* Set the task for this breakpoint. If TASK is 0, make the
1328 breakpoint work for any task. */
1331 breakpoint_set_task (struct breakpoint
*b
, int task
)
1333 int old_task
= b
->task
;
1336 if (old_task
!= task
)
1337 gdb::observers::breakpoint_modified
.notify (b
);
1341 commands_command_1 (const char *arg
, int from_tty
,
1342 struct command_line
*control
)
1344 counted_command_line cmd
;
1345 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1346 NULL after the call to read_command_lines if the user provides an empty
1347 list of command by just typing "end". */
1348 bool cmd_read
= false;
1350 std::string new_arg
;
1352 if (arg
== NULL
|| !*arg
)
1354 /* Argument not explicitly given. Synthesize it. */
1355 if (breakpoint_count
- prev_breakpoint_count
> 1)
1356 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1358 else if (breakpoint_count
> 0)
1359 new_arg
= string_printf ("%d", breakpoint_count
);
1363 /* Create a copy of ARG. This is needed because the "commands"
1364 command may be coming from a script. In that case, the read
1365 line buffer is going to be overwritten in the lambda of
1366 'map_breakpoint_numbers' below when reading the next line
1367 before we are are done parsing the breakpoint numbers. */
1370 arg
= new_arg
.c_str ();
1372 map_breakpoint_numbers
1373 (arg
, [&] (breakpoint
*b
)
1377 gdb_assert (cmd
== NULL
);
1378 if (control
!= NULL
)
1379 cmd
= control
->body_list_0
;
1383 = string_printf (_("Type commands for breakpoint(s) "
1384 "%s, one per line."),
1387 auto do_validate
= [=] (const char *line
)
1389 validate_actionline (line
, b
);
1391 gdb::function_view
<void (const char *)> validator
;
1392 if (is_tracepoint (b
))
1393 validator
= do_validate
;
1395 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1400 /* If a breakpoint was on the list more than once, we don't need to
1402 if (b
->commands
!= cmd
)
1404 validate_commands_for_breakpoint (b
, cmd
.get ());
1406 gdb::observers::breakpoint_modified
.notify (b
);
1412 commands_command (const char *arg
, int from_tty
)
1414 commands_command_1 (arg
, from_tty
, NULL
);
1417 /* Like commands_command, but instead of reading the commands from
1418 input stream, takes them from an already parsed command structure.
1420 This is used by cli-script.c to DTRT with breakpoint commands
1421 that are part of if and while bodies. */
1422 enum command_control_type
1423 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1425 commands_command_1 (arg
, 0, cmd
);
1426 return simple_control
;
1429 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1432 bp_location_has_shadow (struct bp_location
*bl
)
1434 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1438 if (bl
->target_info
.shadow_len
== 0)
1439 /* BL isn't valid, or doesn't shadow memory. */
1444 /* Update BUF, which is LEN bytes read from the target address
1445 MEMADDR, by replacing a memory breakpoint with its shadowed
1448 If READBUF is not NULL, this buffer must not overlap with the of
1449 the breakpoint location's shadow_contents buffer. Otherwise, a
1450 failed assertion internal error will be raised. */
1453 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1454 const gdb_byte
*writebuf_org
,
1455 ULONGEST memaddr
, LONGEST len
,
1456 struct bp_target_info
*target_info
,
1457 struct gdbarch
*gdbarch
)
1459 /* Now do full processing of the found relevant range of elements. */
1460 CORE_ADDR bp_addr
= 0;
1464 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1465 current_program_space
->aspace
, 0))
1467 /* The breakpoint is inserted in a different address space. */
1471 /* Addresses and length of the part of the breakpoint that
1473 bp_addr
= target_info
->placed_address
;
1474 bp_size
= target_info
->shadow_len
;
1476 if (bp_addr
+ bp_size
<= memaddr
)
1478 /* The breakpoint is entirely before the chunk of memory we are
1483 if (bp_addr
>= memaddr
+ len
)
1485 /* The breakpoint is entirely after the chunk of memory we are
1490 /* Offset within shadow_contents. */
1491 if (bp_addr
< memaddr
)
1493 /* Only copy the second part of the breakpoint. */
1494 bp_size
-= memaddr
- bp_addr
;
1495 bptoffset
= memaddr
- bp_addr
;
1499 if (bp_addr
+ bp_size
> memaddr
+ len
)
1501 /* Only copy the first part of the breakpoint. */
1502 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1505 if (readbuf
!= NULL
)
1507 /* Verify that the readbuf buffer does not overlap with the
1508 shadow_contents buffer. */
1509 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1510 || readbuf
>= (target_info
->shadow_contents
1511 + target_info
->shadow_len
));
1513 /* Update the read buffer with this inserted breakpoint's
1515 memcpy (readbuf
+ bp_addr
- memaddr
,
1516 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1520 const unsigned char *bp
;
1521 CORE_ADDR addr
= target_info
->reqstd_address
;
1524 /* Update the shadow with what we want to write to memory. */
1525 memcpy (target_info
->shadow_contents
+ bptoffset
,
1526 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1528 /* Determine appropriate breakpoint contents and size for this
1530 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1532 /* Update the final write buffer with this inserted
1533 breakpoint's INSN. */
1534 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1538 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1539 by replacing any memory breakpoints with their shadowed contents.
1541 If READBUF is not NULL, this buffer must not overlap with any of
1542 the breakpoint location's shadow_contents buffers. Otherwise,
1543 a failed assertion internal error will be raised.
1545 The range of shadowed area by each bp_location is:
1546 bl->address - bp_locations_placed_address_before_address_max
1547 up to bl->address + bp_locations_shadow_len_after_address_max
1548 The range we were requested to resolve shadows for is:
1549 memaddr ... memaddr + len
1550 Thus the safe cutoff boundaries for performance optimization are
1551 memaddr + len <= (bl->address
1552 - bp_locations_placed_address_before_address_max)
1554 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1557 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1558 const gdb_byte
*writebuf_org
,
1559 ULONGEST memaddr
, LONGEST len
)
1561 /* Left boundary, right boundary and median element of our binary
1563 unsigned bc_l
, bc_r
, bc
;
1565 /* Find BC_L which is a leftmost element which may affect BUF
1566 content. It is safe to report lower value but a failure to
1567 report higher one. */
1570 bc_r
= bp_locations
.size ();
1571 while (bc_l
+ 1 < bc_r
)
1573 struct bp_location
*bl
;
1575 bc
= (bc_l
+ bc_r
) / 2;
1576 bl
= bp_locations
[bc
];
1578 /* Check first BL->ADDRESS will not overflow due to the added
1579 constant. Then advance the left boundary only if we are sure
1580 the BC element can in no way affect the BUF content (MEMADDR
1581 to MEMADDR + LEN range).
1583 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1584 offset so that we cannot miss a breakpoint with its shadow
1585 range tail still reaching MEMADDR. */
1587 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1589 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1596 /* Due to the binary search above, we need to make sure we pick the
1597 first location that's at BC_L's address. E.g., if there are
1598 multiple locations at the same address, BC_L may end up pointing
1599 at a duplicate location, and miss the "master"/"inserted"
1600 location. Say, given locations L1, L2 and L3 at addresses A and
1603 L1@A, L2@A, L3@B, ...
1605 BC_L could end up pointing at location L2, while the "master"
1606 location could be L1. Since the `loc->inserted' flag is only set
1607 on "master" locations, we'd forget to restore the shadow of L1
1610 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1613 /* Now do full processing of the found relevant range of elements. */
1615 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1617 struct bp_location
*bl
= bp_locations
[bc
];
1619 /* bp_location array has BL->OWNER always non-NULL. */
1620 if (bl
->owner
->type
== bp_none
)
1621 warning (_("reading through apparently deleted breakpoint #%d?"),
1624 /* Performance optimization: any further element can no longer affect BUF
1627 if (bl
->address
>= bp_locations_placed_address_before_address_max
1628 && memaddr
+ len
<= (bl
->address
1629 - bp_locations_placed_address_before_address_max
))
1632 if (!bp_location_has_shadow (bl
))
1635 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1636 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1640 /* See breakpoint.h. */
1643 is_breakpoint (const struct breakpoint
*bpt
)
1645 return (bpt
->type
== bp_breakpoint
1646 || bpt
->type
== bp_hardware_breakpoint
1647 || bpt
->type
== bp_dprintf
);
1650 /* Return true if BPT is of any hardware watchpoint kind. */
1653 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1655 return (bpt
->type
== bp_hardware_watchpoint
1656 || bpt
->type
== bp_read_watchpoint
1657 || bpt
->type
== bp_access_watchpoint
);
1660 /* See breakpoint.h. */
1663 is_watchpoint (const struct breakpoint
*bpt
)
1665 return (is_hardware_watchpoint (bpt
)
1666 || bpt
->type
== bp_watchpoint
);
1669 /* Returns true if the current thread and its running state are safe
1670 to evaluate or update watchpoint B. Watchpoints on local
1671 expressions need to be evaluated in the context of the thread that
1672 was current when the watchpoint was created, and, that thread needs
1673 to be stopped to be able to select the correct frame context.
1674 Watchpoints on global expressions can be evaluated on any thread,
1675 and in any state. It is presently left to the target allowing
1676 memory accesses when threads are running. */
1679 watchpoint_in_thread_scope (struct watchpoint
*b
)
1681 return (b
->pspace
== current_program_space
1682 && (b
->watchpoint_thread
== null_ptid
1683 || (inferior_ptid
== b
->watchpoint_thread
1684 && !inferior_thread ()->executing
)));
1687 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1688 associated bp_watchpoint_scope breakpoint. */
1691 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1693 if (w
->related_breakpoint
!= w
)
1695 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1696 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1697 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1698 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1699 w
->related_breakpoint
= w
;
1701 w
->disposition
= disp_del_at_next_stop
;
1704 /* Extract a bitfield value from value VAL using the bit parameters contained in
1707 static struct value
*
1708 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1710 struct value
*bit_val
;
1715 bit_val
= allocate_value (value_type (val
));
1717 unpack_value_bitfield (bit_val
,
1720 value_contents_for_printing (val
),
1727 /* Allocate a dummy location and add it to B, which must be a software
1728 watchpoint. This is required because even if a software watchpoint
1729 is not watching any memory, bpstat_stop_status requires a location
1730 to be able to report stops. */
1733 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1734 struct program_space
*pspace
)
1736 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1738 b
->loc
= allocate_bp_location (b
);
1739 b
->loc
->pspace
= pspace
;
1740 b
->loc
->address
= -1;
1741 b
->loc
->length
= -1;
1744 /* Returns true if B is a software watchpoint that is not watching any
1745 memory (e.g., "watch $pc"). */
1748 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1750 return (b
->type
== bp_watchpoint
1752 && b
->loc
->next
== NULL
1753 && b
->loc
->address
== -1
1754 && b
->loc
->length
== -1);
1757 /* Assuming that B is a watchpoint:
1758 - Reparse watchpoint expression, if REPARSE is non-zero
1759 - Evaluate expression and store the result in B->val
1760 - Evaluate the condition if there is one, and store the result
1762 - Update the list of values that must be watched in B->loc.
1764 If the watchpoint disposition is disp_del_at_next_stop, then do
1765 nothing. If this is local watchpoint that is out of scope, delete
1768 Even with `set breakpoint always-inserted on' the watchpoints are
1769 removed + inserted on each stop here. Normal breakpoints must
1770 never be removed because they might be missed by a running thread
1771 when debugging in non-stop mode. On the other hand, hardware
1772 watchpoints (is_hardware_watchpoint; processed here) are specific
1773 to each LWP since they are stored in each LWP's hardware debug
1774 registers. Therefore, such LWP must be stopped first in order to
1775 be able to modify its hardware watchpoints.
1777 Hardware watchpoints must be reset exactly once after being
1778 presented to the user. It cannot be done sooner, because it would
1779 reset the data used to present the watchpoint hit to the user. And
1780 it must not be done later because it could display the same single
1781 watchpoint hit during multiple GDB stops. Note that the latter is
1782 relevant only to the hardware watchpoint types bp_read_watchpoint
1783 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1784 not user-visible - its hit is suppressed if the memory content has
1787 The following constraints influence the location where we can reset
1788 hardware watchpoints:
1790 * target_stopped_by_watchpoint and target_stopped_data_address are
1791 called several times when GDB stops.
1794 * Multiple hardware watchpoints can be hit at the same time,
1795 causing GDB to stop. GDB only presents one hardware watchpoint
1796 hit at a time as the reason for stopping, and all the other hits
1797 are presented later, one after the other, each time the user
1798 requests the execution to be resumed. Execution is not resumed
1799 for the threads still having pending hit event stored in
1800 LWP_INFO->STATUS. While the watchpoint is already removed from
1801 the inferior on the first stop the thread hit event is kept being
1802 reported from its cached value by linux_nat_stopped_data_address
1803 until the real thread resume happens after the watchpoint gets
1804 presented and thus its LWP_INFO->STATUS gets reset.
1806 Therefore the hardware watchpoint hit can get safely reset on the
1807 watchpoint removal from inferior. */
1810 update_watchpoint (struct watchpoint
*b
, int reparse
)
1812 int within_current_scope
;
1813 struct frame_id saved_frame_id
;
1816 /* If this is a local watchpoint, we only want to check if the
1817 watchpoint frame is in scope if the current thread is the thread
1818 that was used to create the watchpoint. */
1819 if (!watchpoint_in_thread_scope (b
))
1822 if (b
->disposition
== disp_del_at_next_stop
)
1827 /* Determine if the watchpoint is within scope. */
1828 if (b
->exp_valid_block
== NULL
)
1829 within_current_scope
= 1;
1832 struct frame_info
*fi
= get_current_frame ();
1833 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1834 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1836 /* If we're at a point where the stack has been destroyed
1837 (e.g. in a function epilogue), unwinding may not work
1838 properly. Do not attempt to recreate locations at this
1839 point. See similar comments in watchpoint_check. */
1840 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1843 /* Save the current frame's ID so we can restore it after
1844 evaluating the watchpoint expression on its own frame. */
1845 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1846 took a frame parameter, so that we didn't have to change the
1849 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1851 fi
= frame_find_by_id (b
->watchpoint_frame
);
1852 within_current_scope
= (fi
!= NULL
);
1853 if (within_current_scope
)
1857 /* We don't free locations. They are stored in the bp_location array
1858 and update_global_location_list will eventually delete them and
1859 remove breakpoints if needed. */
1862 if (within_current_scope
&& reparse
)
1867 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1868 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1869 /* If the meaning of expression itself changed, the old value is
1870 no longer relevant. We don't want to report a watchpoint hit
1871 to the user when the old value and the new value may actually
1872 be completely different objects. */
1874 b
->val_valid
= false;
1876 /* Note that unlike with breakpoints, the watchpoint's condition
1877 expression is stored in the breakpoint object, not in the
1878 locations (re)created below. */
1879 if (b
->cond_string
!= NULL
)
1881 b
->cond_exp
.reset ();
1884 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1888 /* If we failed to parse the expression, for example because
1889 it refers to a global variable in a not-yet-loaded shared library,
1890 don't try to insert watchpoint. We don't automatically delete
1891 such watchpoint, though, since failure to parse expression
1892 is different from out-of-scope watchpoint. */
1893 if (!target_has_execution ())
1895 /* Without execution, memory can't change. No use to try and
1896 set watchpoint locations. The watchpoint will be reset when
1897 the target gains execution, through breakpoint_re_set. */
1898 if (!can_use_hw_watchpoints
)
1900 if (b
->ops
->works_in_software_mode (b
))
1901 b
->type
= bp_watchpoint
;
1903 error (_("Can't set read/access watchpoint when "
1904 "hardware watchpoints are disabled."));
1907 else if (within_current_scope
&& b
->exp
)
1909 std::vector
<value_ref_ptr
> val_chain
;
1910 struct value
*v
, *result
;
1911 struct program_space
*frame_pspace
;
1913 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
1916 /* Avoid setting b->val if it's already set. The meaning of
1917 b->val is 'the last value' user saw, and we should update
1918 it only if we reported that last value to user. As it
1919 happens, the code that reports it updates b->val directly.
1920 We don't keep track of the memory value for masked
1922 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1924 if (b
->val_bitsize
!= 0)
1925 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1926 b
->val
= release_value (v
);
1927 b
->val_valid
= true;
1930 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1932 /* Look at each value on the value chain. */
1933 gdb_assert (!val_chain
.empty ());
1934 for (const value_ref_ptr
&iter
: val_chain
)
1938 /* If it's a memory location, and GDB actually needed
1939 its contents to evaluate the expression, then we
1940 must watch it. If the first value returned is
1941 still lazy, that means an error occurred reading it;
1942 watch it anyway in case it becomes readable. */
1943 if (VALUE_LVAL (v
) == lval_memory
1944 && (v
== val_chain
[0] || ! value_lazy (v
)))
1946 struct type
*vtype
= check_typedef (value_type (v
));
1948 /* We only watch structs and arrays if user asked
1949 for it explicitly, never if they just happen to
1950 appear in the middle of some value chain. */
1952 || (vtype
->code () != TYPE_CODE_STRUCT
1953 && vtype
->code () != TYPE_CODE_ARRAY
))
1956 enum target_hw_bp_type type
;
1957 struct bp_location
*loc
, **tmp
;
1958 int bitpos
= 0, bitsize
= 0;
1960 if (value_bitsize (v
) != 0)
1962 /* Extract the bit parameters out from the bitfield
1964 bitpos
= value_bitpos (v
);
1965 bitsize
= value_bitsize (v
);
1967 else if (v
== result
&& b
->val_bitsize
!= 0)
1969 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1970 lvalue whose bit parameters are saved in the fields
1971 VAL_BITPOS and VAL_BITSIZE. */
1972 bitpos
= b
->val_bitpos
;
1973 bitsize
= b
->val_bitsize
;
1976 addr
= value_address (v
);
1979 /* Skip the bytes that don't contain the bitfield. */
1984 if (b
->type
== bp_read_watchpoint
)
1986 else if (b
->type
== bp_access_watchpoint
)
1989 loc
= allocate_bp_location (b
);
1990 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1993 loc
->gdbarch
= value_type (v
)->arch ();
1995 loc
->pspace
= frame_pspace
;
1996 loc
->address
= address_significant (loc
->gdbarch
, addr
);
2000 /* Just cover the bytes that make up the bitfield. */
2001 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2004 loc
->length
= TYPE_LENGTH (value_type (v
));
2006 loc
->watchpoint_type
= type
;
2011 /* Change the type of breakpoint between hardware assisted or
2012 an ordinary watchpoint depending on the hardware support
2013 and free hardware slots. REPARSE is set when the inferior
2018 enum bp_loc_type loc_type
;
2020 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2024 int i
, target_resources_ok
, other_type_used
;
2027 /* Use an exact watchpoint when there's only one memory region to be
2028 watched, and only one debug register is needed to watch it. */
2029 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2031 /* We need to determine how many resources are already
2032 used for all other hardware watchpoints plus this one
2033 to see if we still have enough resources to also fit
2034 this watchpoint in as well. */
2036 /* If this is a software watchpoint, we try to turn it
2037 to a hardware one -- count resources as if B was of
2038 hardware watchpoint type. */
2040 if (type
== bp_watchpoint
)
2041 type
= bp_hardware_watchpoint
;
2043 /* This watchpoint may or may not have been placed on
2044 the list yet at this point (it won't be in the list
2045 if we're trying to create it for the first time,
2046 through watch_command), so always account for it
2049 /* Count resources used by all watchpoints except B. */
2050 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2052 /* Add in the resources needed for B. */
2053 i
+= hw_watchpoint_use_count (b
);
2056 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2057 if (target_resources_ok
<= 0)
2059 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2061 if (target_resources_ok
== 0 && !sw_mode
)
2062 error (_("Target does not support this type of "
2063 "hardware watchpoint."));
2064 else if (target_resources_ok
< 0 && !sw_mode
)
2065 error (_("There are not enough available hardware "
2066 "resources for this watchpoint."));
2068 /* Downgrade to software watchpoint. */
2069 b
->type
= bp_watchpoint
;
2073 /* If this was a software watchpoint, we've just
2074 found we have enough resources to turn it to a
2075 hardware watchpoint. Otherwise, this is a
2080 else if (!b
->ops
->works_in_software_mode (b
))
2082 if (!can_use_hw_watchpoints
)
2083 error (_("Can't set read/access watchpoint when "
2084 "hardware watchpoints are disabled."));
2086 error (_("Expression cannot be implemented with "
2087 "read/access watchpoint."));
2090 b
->type
= bp_watchpoint
;
2092 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2093 : bp_loc_hardware_watchpoint
);
2094 for (bp_location
*bl
: b
->locations ())
2095 bl
->loc_type
= loc_type
;
2098 /* If a software watchpoint is not watching any memory, then the
2099 above left it without any location set up. But,
2100 bpstat_stop_status requires a location to be able to report
2101 stops, so make sure there's at least a dummy one. */
2102 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2103 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2105 else if (!within_current_scope
)
2107 printf_filtered (_("\
2108 Watchpoint %d deleted because the program has left the block\n\
2109 in which its expression is valid.\n"),
2111 watchpoint_del_at_next_stop (b
);
2114 /* Restore the selected frame. */
2116 select_frame (frame_find_by_id (saved_frame_id
));
2120 /* Returns 1 iff breakpoint location should be
2121 inserted in the inferior. We don't differentiate the type of BL's owner
2122 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2123 breakpoint_ops is not defined, because in insert_bp_location,
2124 tracepoint's insert_location will not be called. */
2126 should_be_inserted (struct bp_location
*bl
)
2128 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2131 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2134 if (!bl
->enabled
|| bl
->disabled_by_cond
2135 || bl
->shlib_disabled
|| bl
->duplicate
)
2138 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2141 /* This is set for example, when we're attached to the parent of a
2142 vfork, and have detached from the child. The child is running
2143 free, and we expect it to do an exec or exit, at which point the
2144 OS makes the parent schedulable again (and the target reports
2145 that the vfork is done). Until the child is done with the shared
2146 memory region, do not insert breakpoints in the parent, otherwise
2147 the child could still trip on the parent's breakpoints. Since
2148 the parent is blocked anyway, it won't miss any breakpoint. */
2149 if (bl
->pspace
->breakpoints_not_allowed
)
2152 /* Don't insert a breakpoint if we're trying to step past its
2153 location, except if the breakpoint is a single-step breakpoint,
2154 and the breakpoint's thread is the thread which is stepping past
2156 if ((bl
->loc_type
== bp_loc_software_breakpoint
2157 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2158 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2160 /* The single-step breakpoint may be inserted at the location
2161 we're trying to step if the instruction branches to itself.
2162 However, the instruction won't be executed at all and it may
2163 break the semantics of the instruction, for example, the
2164 instruction is a conditional branch or updates some flags.
2165 We can't fix it unless GDB is able to emulate the instruction
2166 or switch to displaced stepping. */
2167 && !(bl
->owner
->type
== bp_single_step
2168 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2170 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2171 paddress (bl
->gdbarch
, bl
->address
));
2175 /* Don't insert watchpoints if we're trying to step past the
2176 instruction that triggered one. */
2177 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2178 && stepping_past_nonsteppable_watchpoint ())
2180 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2181 "skipping watchpoint at %s:%d",
2182 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2189 /* Same as should_be_inserted but does the check assuming
2190 that the location is not duplicated. */
2193 unduplicated_should_be_inserted (struct bp_location
*bl
)
2196 const int save_duplicate
= bl
->duplicate
;
2199 result
= should_be_inserted (bl
);
2200 bl
->duplicate
= save_duplicate
;
2204 /* Parses a conditional described by an expression COND into an
2205 agent expression bytecode suitable for evaluation
2206 by the bytecode interpreter. Return NULL if there was
2207 any error during parsing. */
2209 static agent_expr_up
2210 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2215 agent_expr_up aexpr
;
2217 /* We don't want to stop processing, so catch any errors
2218 that may show up. */
2221 aexpr
= gen_eval_for_expr (scope
, cond
);
2224 catch (const gdb_exception_error
&ex
)
2226 /* If we got here, it means the condition could not be parsed to a valid
2227 bytecode expression and thus can't be evaluated on the target's side.
2228 It's no use iterating through the conditions. */
2231 /* We have a valid agent expression. */
2235 /* Based on location BL, create a list of breakpoint conditions to be
2236 passed on to the target. If we have duplicated locations with different
2237 conditions, we will add such conditions to the list. The idea is that the
2238 target will evaluate the list of conditions and will only notify GDB when
2239 one of them is true. */
2242 build_target_condition_list (struct bp_location
*bl
)
2244 int null_condition_or_parse_error
= 0;
2245 int modified
= bl
->needs_update
;
2247 /* Release conditions left over from a previous insert. */
2248 bl
->target_info
.conditions
.clear ();
2250 /* This is only meaningful if the target is
2251 evaluating conditions and if the user has
2252 opted for condition evaluation on the target's
2254 if (gdb_evaluates_breakpoint_condition_p ()
2255 || !target_supports_evaluation_of_breakpoint_conditions ())
2258 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2260 /* Do a first pass to check for locations with no assigned
2261 conditions or conditions that fail to parse to a valid agent
2262 expression bytecode. If any of these happen, then it's no use to
2263 send conditions to the target since this location will always
2264 trigger and generate a response back to GDB. Note we consider
2265 all locations at the same address irrespective of type, i.e.,
2266 even if the locations aren't considered duplicates (e.g.,
2267 software breakpoint and hardware breakpoint at the same
2269 for (bp_location
*loc
: loc_range
)
2271 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2275 /* Re-parse the conditions since something changed. In that
2276 case we already freed the condition bytecodes (see
2277 force_breakpoint_reinsertion). We just
2278 need to parse the condition to bytecodes again. */
2279 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2283 /* If we have a NULL bytecode expression, it means something
2284 went wrong or we have a null condition expression. */
2285 if (!loc
->cond_bytecode
)
2287 null_condition_or_parse_error
= 1;
2293 /* If any of these happened, it means we will have to evaluate the conditions
2294 for the location's address on gdb's side. It is no use keeping bytecodes
2295 for all the other duplicate locations, thus we free all of them here.
2297 This is so we have a finer control over which locations' conditions are
2298 being evaluated by GDB or the remote stub. */
2299 if (null_condition_or_parse_error
)
2301 for (bp_location
*loc
: loc_range
)
2303 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2305 /* Only go as far as the first NULL bytecode is
2307 if (!loc
->cond_bytecode
)
2310 loc
->cond_bytecode
.reset ();
2315 /* No NULL conditions or failed bytecode generation. Build a
2316 condition list for this location's address. If we have software
2317 and hardware locations at the same address, they aren't
2318 considered duplicates, but we still marge all the conditions
2319 anyway, as it's simpler, and doesn't really make a practical
2321 for (bp_location
*loc
: loc_range
)
2323 && is_breakpoint (loc
->owner
)
2324 && loc
->pspace
->num
== bl
->pspace
->num
2325 && loc
->owner
->enable_state
== bp_enabled
2327 && !loc
->disabled_by_cond
)
2329 /* Add the condition to the vector. This will be used later
2330 to send the conditions to the target. */
2331 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2337 /* Parses a command described by string CMD into an agent expression
2338 bytecode suitable for evaluation by the bytecode interpreter.
2339 Return NULL if there was any error during parsing. */
2341 static agent_expr_up
2342 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2344 const char *cmdrest
;
2345 const char *format_start
, *format_end
;
2346 struct gdbarch
*gdbarch
= get_current_arch ();
2353 if (*cmdrest
== ',')
2355 cmdrest
= skip_spaces (cmdrest
);
2357 if (*cmdrest
++ != '"')
2358 error (_("No format string following the location"));
2360 format_start
= cmdrest
;
2362 format_pieces
fpieces (&cmdrest
);
2364 format_end
= cmdrest
;
2366 if (*cmdrest
++ != '"')
2367 error (_("Bad format string, non-terminated '\"'."));
2369 cmdrest
= skip_spaces (cmdrest
);
2371 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2372 error (_("Invalid argument syntax"));
2374 if (*cmdrest
== ',')
2376 cmdrest
= skip_spaces (cmdrest
);
2378 /* For each argument, make an expression. */
2380 std::vector
<struct expression
*> argvec
;
2381 while (*cmdrest
!= '\0')
2386 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2387 argvec
.push_back (expr
.release ());
2389 if (*cmdrest
== ',')
2393 agent_expr_up aexpr
;
2395 /* We don't want to stop processing, so catch any errors
2396 that may show up. */
2399 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2400 format_start
, format_end
- format_start
,
2401 argvec
.size (), argvec
.data ());
2403 catch (const gdb_exception_error
&ex
)
2405 /* If we got here, it means the command could not be parsed to a valid
2406 bytecode expression and thus can't be evaluated on the target's side.
2407 It's no use iterating through the other commands. */
2410 /* We have a valid agent expression, return it. */
2414 /* Based on location BL, create a list of breakpoint commands to be
2415 passed on to the target. If we have duplicated locations with
2416 different commands, we will add any such to the list. */
2419 build_target_command_list (struct bp_location
*bl
)
2421 int null_command_or_parse_error
= 0;
2422 int modified
= bl
->needs_update
;
2424 /* Clear commands left over from a previous insert. */
2425 bl
->target_info
.tcommands
.clear ();
2427 if (!target_can_run_breakpoint_commands ())
2430 /* For now, limit to agent-style dprintf breakpoints. */
2431 if (dprintf_style
!= dprintf_style_agent
)
2434 auto loc_range
= all_bp_locations_at_addr (bl
->address
);
2436 /* For now, if we have any location at the same address that isn't a
2437 dprintf, don't install the target-side commands, as that would
2438 make the breakpoint not be reported to the core, and we'd lose
2440 for (bp_location
*loc
: loc_range
)
2441 if (is_breakpoint (loc
->owner
)
2442 && loc
->pspace
->num
== bl
->pspace
->num
2443 && loc
->owner
->type
!= bp_dprintf
)
2446 /* Do a first pass to check for locations with no assigned
2447 conditions or conditions that fail to parse to a valid agent expression
2448 bytecode. If any of these happen, then it's no use to send conditions
2449 to the target since this location will always trigger and generate a
2450 response back to GDB. */
2451 for (bp_location
*loc
: loc_range
)
2453 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2457 /* Re-parse the commands since something changed. In that
2458 case we already freed the command bytecodes (see
2459 force_breakpoint_reinsertion). We just
2460 need to parse the command to bytecodes again. */
2462 = parse_cmd_to_aexpr (bl
->address
,
2463 loc
->owner
->extra_string
);
2466 /* If we have a NULL bytecode expression, it means something
2467 went wrong or we have a null command expression. */
2468 if (!loc
->cmd_bytecode
)
2470 null_command_or_parse_error
= 1;
2476 /* If anything failed, then we're not doing target-side commands,
2478 if (null_command_or_parse_error
)
2480 for (bp_location
*loc
: loc_range
)
2481 if (is_breakpoint (loc
->owner
)
2482 && loc
->pspace
->num
== bl
->pspace
->num
)
2484 /* Only go as far as the first NULL bytecode is
2486 if (loc
->cmd_bytecode
== NULL
)
2489 loc
->cmd_bytecode
.reset ();
2493 /* No NULL commands or failed bytecode generation. Build a command
2494 list for all duplicate locations at this location's address.
2495 Note that here we must care for whether the breakpoint location
2496 types are considered duplicates, otherwise, say, if we have a
2497 software and hardware location at the same address, the target
2498 could end up running the commands twice. For the moment, we only
2499 support targets-side commands with dprintf, but it doesn't hurt
2500 to be pedantically correct in case that changes. */
2501 for (bp_location
*loc
: loc_range
)
2502 if (breakpoint_locations_match (bl
, loc
)
2503 && loc
->owner
->extra_string
2504 && is_breakpoint (loc
->owner
)
2505 && loc
->pspace
->num
== bl
->pspace
->num
2506 && loc
->owner
->enable_state
== bp_enabled
2508 && !loc
->disabled_by_cond
)
2510 /* Add the command to the vector. This will be used later
2511 to send the commands to the target. */
2512 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2515 bl
->target_info
.persist
= 0;
2516 /* Maybe flag this location as persistent. */
2517 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2518 bl
->target_info
.persist
= 1;
2521 /* Return the kind of breakpoint on address *ADDR. Get the kind
2522 of breakpoint according to ADDR except single-step breakpoint.
2523 Get the kind of single-step breakpoint according to the current
2527 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2529 if (bl
->owner
->type
== bp_single_step
)
2531 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2532 struct regcache
*regcache
;
2534 regcache
= get_thread_regcache (thr
);
2536 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2540 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2543 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2544 location. Any error messages are printed to TMP_ERROR_STREAM; and
2545 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2546 Returns 0 for success, 1 if the bp_location type is not supported or
2549 NOTE drow/2003-09-09: This routine could be broken down to an
2550 object-style method for each breakpoint or catchpoint type. */
2552 insert_bp_location (struct bp_location
*bl
,
2553 struct ui_file
*tmp_error_stream
,
2554 int *disabled_breaks
,
2555 int *hw_breakpoint_error
,
2556 int *hw_bp_error_explained_already
)
2558 gdb_exception bp_excpt
;
2560 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2563 /* Note we don't initialize bl->target_info, as that wipes out
2564 the breakpoint location's shadow_contents if the breakpoint
2565 is still inserted at that location. This in turn breaks
2566 target_read_memory which depends on these buffers when
2567 a memory read is requested at the breakpoint location:
2568 Once the target_info has been wiped, we fail to see that
2569 we have a breakpoint inserted at that address and thus
2570 read the breakpoint instead of returning the data saved in
2571 the breakpoint location's shadow contents. */
2572 bl
->target_info
.reqstd_address
= bl
->address
;
2573 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2574 bl
->target_info
.length
= bl
->length
;
2576 /* When working with target-side conditions, we must pass all the conditions
2577 for the same breakpoint address down to the target since GDB will not
2578 insert those locations. With a list of breakpoint conditions, the target
2579 can decide when to stop and notify GDB. */
2581 if (is_breakpoint (bl
->owner
))
2583 build_target_condition_list (bl
);
2584 build_target_command_list (bl
);
2585 /* Reset the modification marker. */
2586 bl
->needs_update
= 0;
2589 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2590 set at a read-only address, then a breakpoint location will have
2591 been changed to hardware breakpoint before we get here. If it is
2592 "off" however, error out before actually trying to insert the
2593 breakpoint, with a nicer error message. */
2594 if (bl
->loc_type
== bp_loc_software_breakpoint
2595 && !automatic_hardware_breakpoints
)
2597 mem_region
*mr
= lookup_mem_region (bl
->address
);
2599 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2601 fprintf_unfiltered (tmp_error_stream
,
2602 _("Cannot insert breakpoint %d.\n"
2603 "Cannot set software breakpoint "
2604 "at read-only address %s\n"),
2606 paddress (bl
->gdbarch
, bl
->address
));
2611 if (bl
->loc_type
== bp_loc_software_breakpoint
2612 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2614 /* First check to see if we have to handle an overlay. */
2615 if (overlay_debugging
== ovly_off
2616 || bl
->section
== NULL
2617 || !(section_is_overlay (bl
->section
)))
2619 /* No overlay handling: just set the breakpoint. */
2624 val
= bl
->owner
->ops
->insert_location (bl
);
2626 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2628 catch (gdb_exception
&e
)
2630 bp_excpt
= std::move (e
);
2635 /* This breakpoint is in an overlay section.
2636 Shall we set a breakpoint at the LMA? */
2637 if (!overlay_events_enabled
)
2639 /* Yes -- overlay event support is not active,
2640 so we must try to set a breakpoint at the LMA.
2641 This will not work for a hardware breakpoint. */
2642 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2643 warning (_("hardware breakpoint %d not supported in overlay!"),
2647 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2649 /* Set a software (trap) breakpoint at the LMA. */
2650 bl
->overlay_target_info
= bl
->target_info
;
2651 bl
->overlay_target_info
.reqstd_address
= addr
;
2653 /* No overlay handling: just set the breakpoint. */
2658 bl
->overlay_target_info
.kind
2659 = breakpoint_kind (bl
, &addr
);
2660 bl
->overlay_target_info
.placed_address
= addr
;
2661 val
= target_insert_breakpoint (bl
->gdbarch
,
2662 &bl
->overlay_target_info
);
2665 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2667 catch (gdb_exception
&e
)
2669 bp_excpt
= std::move (e
);
2672 if (bp_excpt
.reason
!= 0)
2673 fprintf_unfiltered (tmp_error_stream
,
2674 "Overlay breakpoint %d "
2675 "failed: in ROM?\n",
2679 /* Shall we set a breakpoint at the VMA? */
2680 if (section_is_mapped (bl
->section
))
2682 /* Yes. This overlay section is mapped into memory. */
2687 val
= bl
->owner
->ops
->insert_location (bl
);
2689 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2691 catch (gdb_exception
&e
)
2693 bp_excpt
= std::move (e
);
2698 /* No. This breakpoint will not be inserted.
2699 No error, but do not mark the bp as 'inserted'. */
2704 if (bp_excpt
.reason
!= 0)
2706 /* Can't set the breakpoint. */
2708 /* In some cases, we might not be able to insert a
2709 breakpoint in a shared library that has already been
2710 removed, but we have not yet processed the shlib unload
2711 event. Unfortunately, some targets that implement
2712 breakpoint insertion themselves can't tell why the
2713 breakpoint insertion failed (e.g., the remote target
2714 doesn't define error codes), so we must treat generic
2715 errors as memory errors. */
2716 if (bp_excpt
.reason
== RETURN_ERROR
2717 && (bp_excpt
.error
== GENERIC_ERROR
2718 || bp_excpt
.error
== MEMORY_ERROR
)
2719 && bl
->loc_type
== bp_loc_software_breakpoint
2720 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2721 || shared_objfile_contains_address_p (bl
->pspace
,
2724 /* See also: disable_breakpoints_in_shlibs. */
2725 bl
->shlib_disabled
= 1;
2726 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2727 if (!*disabled_breaks
)
2729 fprintf_unfiltered (tmp_error_stream
,
2730 "Cannot insert breakpoint %d.\n",
2732 fprintf_unfiltered (tmp_error_stream
,
2733 "Temporarily disabling shared "
2734 "library breakpoints:\n");
2736 *disabled_breaks
= 1;
2737 fprintf_unfiltered (tmp_error_stream
,
2738 "breakpoint #%d\n", bl
->owner
->number
);
2743 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2745 *hw_breakpoint_error
= 1;
2746 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2747 fprintf_unfiltered (tmp_error_stream
,
2748 "Cannot insert hardware breakpoint %d%s",
2750 bp_excpt
.message
? ":" : ".\n");
2751 if (bp_excpt
.message
!= NULL
)
2752 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2757 if (bp_excpt
.message
== NULL
)
2760 = memory_error_message (TARGET_XFER_E_IO
,
2761 bl
->gdbarch
, bl
->address
);
2763 fprintf_unfiltered (tmp_error_stream
,
2764 "Cannot insert breakpoint %d.\n"
2766 bl
->owner
->number
, message
.c_str ());
2770 fprintf_unfiltered (tmp_error_stream
,
2771 "Cannot insert breakpoint %d: %s\n",
2786 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2787 /* NOTE drow/2003-09-08: This state only exists for removing
2788 watchpoints. It's not clear that it's necessary... */
2789 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2793 gdb_assert (bl
->owner
->ops
!= NULL
2794 && bl
->owner
->ops
->insert_location
!= NULL
);
2796 val
= bl
->owner
->ops
->insert_location (bl
);
2798 /* If trying to set a read-watchpoint, and it turns out it's not
2799 supported, try emulating one with an access watchpoint. */
2800 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2802 /* But don't try to insert it, if there's already another
2803 hw_access location that would be considered a duplicate
2805 for (bp_location
*loc
: all_bp_locations ())
2807 && loc
->watchpoint_type
== hw_access
2808 && watchpoint_locations_match (bl
, loc
))
2812 bl
->target_info
= loc
->target_info
;
2813 bl
->watchpoint_type
= hw_access
;
2820 bl
->watchpoint_type
= hw_access
;
2821 val
= bl
->owner
->ops
->insert_location (bl
);
2824 /* Back to the original value. */
2825 bl
->watchpoint_type
= hw_read
;
2829 bl
->inserted
= (val
== 0);
2832 else if (bl
->owner
->type
== bp_catchpoint
)
2836 gdb_assert (bl
->owner
->ops
!= NULL
2837 && bl
->owner
->ops
->insert_location
!= NULL
);
2839 val
= bl
->owner
->ops
->insert_location (bl
);
2842 bl
->owner
->enable_state
= bp_disabled
;
2846 Error inserting catchpoint %d: Your system does not support this type\n\
2847 of catchpoint."), bl
->owner
->number
);
2849 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2852 bl
->inserted
= (val
== 0);
2854 /* We've already printed an error message if there was a problem
2855 inserting this catchpoint, and we've disabled the catchpoint,
2856 so just return success. */
2863 /* This function is called when program space PSPACE is about to be
2864 deleted. It takes care of updating breakpoints to not reference
2868 breakpoint_program_space_exit (struct program_space
*pspace
)
2870 /* Remove any breakpoint that was set through this program space. */
2871 for (breakpoint
*b
: all_breakpoints_safe ())
2872 if (b
->pspace
== pspace
)
2873 delete_breakpoint (b
);
2875 /* Breakpoints set through other program spaces could have locations
2876 bound to PSPACE as well. Remove those. */
2877 for (bp_location
*loc
: all_bp_locations ())
2879 struct bp_location
*tmp
;
2881 if (loc
->pspace
== pspace
)
2883 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2884 if (loc
->owner
->loc
== loc
)
2885 loc
->owner
->loc
= loc
->next
;
2887 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2888 if (tmp
->next
== loc
)
2890 tmp
->next
= loc
->next
;
2896 /* Now update the global location list to permanently delete the
2897 removed locations above. */
2898 update_global_location_list (UGLL_DONT_INSERT
);
2901 /* Make sure all breakpoints are inserted in inferior.
2902 Throws exception on any error.
2903 A breakpoint that is already inserted won't be inserted
2904 again, so calling this function twice is safe. */
2906 insert_breakpoints (void)
2908 for (breakpoint
*bpt
: all_breakpoints ())
2909 if (is_hardware_watchpoint (bpt
))
2911 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2913 update_watchpoint (w
, 0 /* don't reparse. */);
2916 /* Updating watchpoints creates new locations, so update the global
2917 location list. Explicitly tell ugll to insert locations and
2918 ignore breakpoints_always_inserted_mode. Also,
2919 update_global_location_list tries to "upgrade" software
2920 breakpoints to hardware breakpoints to handle "set breakpoint
2921 auto-hw", so we need to call it even if we don't have new
2923 update_global_location_list (UGLL_INSERT
);
2926 /* Invoke CALLBACK for each of bp_location. */
2929 iterate_over_bp_locations (gdb::function_view
<void (bp_location
*)> callback
)
2931 for (bp_location
*loc
: all_bp_locations ())
2935 /* This is used when we need to synch breakpoint conditions between GDB and the
2936 target. It is the case with deleting and disabling of breakpoints when using
2937 always-inserted mode. */
2940 update_inserted_breakpoint_locations (void)
2944 int disabled_breaks
= 0;
2945 int hw_breakpoint_error
= 0;
2946 int hw_bp_details_reported
= 0;
2948 string_file tmp_error_stream
;
2950 /* Explicitly mark the warning -- this will only be printed if
2951 there was an error. */
2952 tmp_error_stream
.puts ("Warning:\n");
2954 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2956 for (bp_location
*bl
: all_bp_locations ())
2958 /* We only want to update software breakpoints and hardware
2960 if (!is_breakpoint (bl
->owner
))
2963 /* We only want to update locations that are already inserted
2964 and need updating. This is to avoid unwanted insertion during
2965 deletion of breakpoints. */
2966 if (!bl
->inserted
|| !bl
->needs_update
)
2969 switch_to_program_space_and_thread (bl
->pspace
);
2971 /* For targets that support global breakpoints, there's no need
2972 to select an inferior to insert breakpoint to. In fact, even
2973 if we aren't attached to any process yet, we should still
2974 insert breakpoints. */
2975 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2976 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
2979 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2980 &hw_breakpoint_error
, &hw_bp_details_reported
);
2987 target_terminal::ours_for_output ();
2988 error_stream (tmp_error_stream
);
2992 /* Used when starting or continuing the program. */
2995 insert_breakpoint_locations (void)
2999 int disabled_breaks
= 0;
3000 int hw_breakpoint_error
= 0;
3001 int hw_bp_error_explained_already
= 0;
3003 string_file tmp_error_stream
;
3005 /* Explicitly mark the warning -- this will only be printed if
3006 there was an error. */
3007 tmp_error_stream
.puts ("Warning:\n");
3009 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3011 for (bp_location
*bl
: all_bp_locations ())
3013 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3016 /* There is no point inserting thread-specific breakpoints if
3017 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3018 has BL->OWNER always non-NULL. */
3019 if (bl
->owner
->thread
!= -1
3020 && !valid_global_thread_id (bl
->owner
->thread
))
3023 switch_to_program_space_and_thread (bl
->pspace
);
3025 /* For targets that support global breakpoints, there's no need
3026 to select an inferior to insert breakpoint to. In fact, even
3027 if we aren't attached to any process yet, we should still
3028 insert breakpoints. */
3029 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3030 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3033 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3034 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3039 /* If we failed to insert all locations of a watchpoint, remove
3040 them, as half-inserted watchpoint is of limited use. */
3041 for (breakpoint
*bpt
: all_breakpoints ())
3043 int some_failed
= 0;
3045 if (!is_hardware_watchpoint (bpt
))
3048 if (!breakpoint_enabled (bpt
))
3051 if (bpt
->disposition
== disp_del_at_next_stop
)
3054 for (bp_location
*loc
: bpt
->locations ())
3055 if (!loc
->inserted
&& should_be_inserted (loc
))
3063 for (bp_location
*loc
: bpt
->locations ())
3065 remove_breakpoint (loc
);
3067 hw_breakpoint_error
= 1;
3068 tmp_error_stream
.printf ("Could not insert "
3069 "hardware watchpoint %d.\n",
3077 /* If a hardware breakpoint or watchpoint was inserted, add a
3078 message about possibly exhausted resources. */
3079 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3081 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3082 You may have requested too many hardware breakpoints/watchpoints.\n");
3084 target_terminal::ours_for_output ();
3085 error_stream (tmp_error_stream
);
3089 /* Used when the program stops.
3090 Returns zero if successful, or non-zero if there was a problem
3091 removing a breakpoint location. */
3094 remove_breakpoints (void)
3098 for (bp_location
*bl
: all_bp_locations ())
3100 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3101 val
|= remove_breakpoint (bl
);
3106 /* When a thread exits, remove breakpoints that are related to
3110 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3112 for (breakpoint
*b
: all_breakpoints_safe ())
3114 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3116 b
->disposition
= disp_del_at_next_stop
;
3118 printf_filtered (_("\
3119 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3120 b
->number
, print_thread_id (tp
));
3122 /* Hide it from the user. */
3128 /* See breakpoint.h. */
3131 remove_breakpoints_inf (inferior
*inf
)
3135 for (bp_location
*bl
: all_bp_locations ())
3137 if (bl
->pspace
!= inf
->pspace
)
3140 if (bl
->inserted
&& !bl
->target_info
.persist
)
3142 val
= remove_breakpoint (bl
);
3149 static int internal_breakpoint_number
= -1;
3151 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3152 If INTERNAL is non-zero, the breakpoint number will be populated
3153 from internal_breakpoint_number and that variable decremented.
3154 Otherwise the breakpoint number will be populated from
3155 breakpoint_count and that value incremented. Internal breakpoints
3156 do not set the internal var bpnum. */
3158 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3161 b
->number
= internal_breakpoint_number
--;
3164 set_breakpoint_count (breakpoint_count
+ 1);
3165 b
->number
= breakpoint_count
;
3169 static struct breakpoint
*
3170 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3171 CORE_ADDR address
, enum bptype type
,
3172 const struct breakpoint_ops
*ops
)
3174 symtab_and_line sal
;
3176 sal
.section
= find_pc_overlay (sal
.pc
);
3177 sal
.pspace
= current_program_space
;
3179 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3180 b
->number
= internal_breakpoint_number
--;
3181 b
->disposition
= disp_donttouch
;
3186 static const char *const longjmp_names
[] =
3188 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3190 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3192 /* Per-objfile data private to breakpoint.c. */
3193 struct breakpoint_objfile_data
3195 /* Minimal symbol for "_ovly_debug_event" (if any). */
3196 struct bound_minimal_symbol overlay_msym
{};
3198 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3199 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3201 /* True if we have looked for longjmp probes. */
3202 int longjmp_searched
= 0;
3204 /* SystemTap probe points for longjmp (if any). These are non-owning
3206 std::vector
<probe
*> longjmp_probes
;
3208 /* Minimal symbol for "std::terminate()" (if any). */
3209 struct bound_minimal_symbol terminate_msym
{};
3211 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3212 struct bound_minimal_symbol exception_msym
{};
3214 /* True if we have looked for exception probes. */
3215 int exception_searched
= 0;
3217 /* SystemTap probe points for unwinding (if any). These are non-owning
3219 std::vector
<probe
*> exception_probes
;
3222 static const struct objfile_key
<breakpoint_objfile_data
>
3223 breakpoint_objfile_key
;
3225 /* Minimal symbol not found sentinel. */
3226 static struct minimal_symbol msym_not_found
;
3228 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3231 msym_not_found_p (const struct minimal_symbol
*msym
)
3233 return msym
== &msym_not_found
;
3236 /* Return per-objfile data needed by breakpoint.c.
3237 Allocate the data if necessary. */
3239 static struct breakpoint_objfile_data
*
3240 get_breakpoint_objfile_data (struct objfile
*objfile
)
3242 struct breakpoint_objfile_data
*bp_objfile_data
;
3244 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3245 if (bp_objfile_data
== NULL
)
3246 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3247 return bp_objfile_data
;
3251 create_overlay_event_breakpoint (void)
3253 const char *const func_name
= "_ovly_debug_event";
3255 for (objfile
*objfile
: current_program_space
->objfiles ())
3257 struct breakpoint
*b
;
3258 struct breakpoint_objfile_data
*bp_objfile_data
;
3260 struct explicit_location explicit_loc
;
3262 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3264 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3267 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3269 struct bound_minimal_symbol m
;
3271 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3272 if (m
.minsym
== NULL
)
3274 /* Avoid future lookups in this objfile. */
3275 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3278 bp_objfile_data
->overlay_msym
= m
;
3281 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3282 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3284 &internal_breakpoint_ops
);
3285 initialize_explicit_location (&explicit_loc
);
3286 explicit_loc
.function_name
= ASTRDUP (func_name
);
3287 b
->location
= new_explicit_location (&explicit_loc
);
3289 if (overlay_debugging
== ovly_auto
)
3291 b
->enable_state
= bp_enabled
;
3292 overlay_events_enabled
= 1;
3296 b
->enable_state
= bp_disabled
;
3297 overlay_events_enabled
= 0;
3302 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3303 true if a breakpoint was installed. */
3306 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3308 struct gdbarch
*gdbarch
= objfile
->arch ();
3309 struct breakpoint_objfile_data
*bp_objfile_data
3310 = get_breakpoint_objfile_data (objfile
);
3312 if (!bp_objfile_data
->longjmp_searched
)
3314 std::vector
<probe
*> ret
3315 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3319 /* We are only interested in checking one element. */
3322 if (!p
->can_evaluate_arguments ())
3324 /* We cannot use the probe interface here,
3325 because it does not know how to evaluate
3330 bp_objfile_data
->longjmp_probes
= ret
;
3331 bp_objfile_data
->longjmp_searched
= 1;
3334 if (bp_objfile_data
->longjmp_probes
.empty ())
3337 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3339 struct breakpoint
*b
;
3341 b
= create_internal_breakpoint (gdbarch
,
3342 p
->get_relocated_address (objfile
),
3344 &internal_breakpoint_ops
);
3345 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3346 b
->enable_state
= bp_disabled
;
3352 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3353 Return true if at least one breakpoint was installed. */
3356 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3358 struct gdbarch
*gdbarch
= objfile
->arch ();
3359 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3362 struct breakpoint_objfile_data
*bp_objfile_data
3363 = get_breakpoint_objfile_data (objfile
);
3364 unsigned int installed_bp
= 0;
3366 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3368 struct breakpoint
*b
;
3369 const char *func_name
;
3371 struct explicit_location explicit_loc
;
3373 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3376 func_name
= longjmp_names
[i
];
3377 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3379 struct bound_minimal_symbol m
;
3381 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3382 if (m
.minsym
== NULL
)
3384 /* Prevent future lookups in this objfile. */
3385 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3388 bp_objfile_data
->longjmp_msym
[i
] = m
;
3391 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3392 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3393 &internal_breakpoint_ops
);
3394 initialize_explicit_location (&explicit_loc
);
3395 explicit_loc
.function_name
= ASTRDUP (func_name
);
3396 b
->location
= new_explicit_location (&explicit_loc
);
3397 b
->enable_state
= bp_disabled
;
3401 return installed_bp
> 0;
3404 /* Create a master longjmp breakpoint. */
3407 create_longjmp_master_breakpoint (void)
3409 scoped_restore_current_program_space restore_pspace
;
3411 for (struct program_space
*pspace
: program_spaces
)
3413 set_current_program_space (pspace
);
3415 for (objfile
*obj
: current_program_space
->objfiles ())
3417 /* Skip separate debug object, it's handled in the loop below. */
3418 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3421 /* Try a probe kind breakpoint on main objfile. */
3422 if (create_longjmp_master_breakpoint_probe (obj
))
3425 /* Try longjmp_names kind breakpoints on main and separate_debug
3427 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3428 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3434 /* Create a master std::terminate breakpoint. */
3436 create_std_terminate_master_breakpoint (void)
3438 const char *const func_name
= "std::terminate()";
3440 scoped_restore_current_program_space restore_pspace
;
3442 for (struct program_space
*pspace
: program_spaces
)
3446 set_current_program_space (pspace
);
3448 for (objfile
*objfile
: current_program_space
->objfiles ())
3450 struct breakpoint
*b
;
3451 struct breakpoint_objfile_data
*bp_objfile_data
;
3452 struct explicit_location explicit_loc
;
3454 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3456 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3459 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3461 struct bound_minimal_symbol m
;
3463 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3464 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3465 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3467 /* Prevent future lookups in this objfile. */
3468 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3471 bp_objfile_data
->terminate_msym
= m
;
3474 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3475 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3476 bp_std_terminate_master
,
3477 &internal_breakpoint_ops
);
3478 initialize_explicit_location (&explicit_loc
);
3479 explicit_loc
.function_name
= ASTRDUP (func_name
);
3480 b
->location
= new_explicit_location (&explicit_loc
);
3481 b
->enable_state
= bp_disabled
;
3486 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3487 probe. Return true if a breakpoint was installed. */
3490 create_exception_master_breakpoint_probe (objfile
*objfile
)
3492 struct breakpoint
*b
;
3493 struct gdbarch
*gdbarch
;
3494 struct breakpoint_objfile_data
*bp_objfile_data
;
3496 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3498 /* We prefer the SystemTap probe point if it exists. */
3499 if (!bp_objfile_data
->exception_searched
)
3501 std::vector
<probe
*> ret
3502 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3506 /* We are only interested in checking one element. */
3509 if (!p
->can_evaluate_arguments ())
3511 /* We cannot use the probe interface here, because it does
3512 not know how to evaluate arguments. */
3516 bp_objfile_data
->exception_probes
= ret
;
3517 bp_objfile_data
->exception_searched
= 1;
3520 if (bp_objfile_data
->exception_probes
.empty ())
3523 gdbarch
= objfile
->arch ();
3525 for (probe
*p
: bp_objfile_data
->exception_probes
)
3527 b
= create_internal_breakpoint (gdbarch
,
3528 p
->get_relocated_address (objfile
),
3529 bp_exception_master
,
3530 &internal_breakpoint_ops
);
3531 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3532 b
->enable_state
= bp_disabled
;
3538 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3539 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3542 create_exception_master_breakpoint_hook (objfile
*objfile
)
3544 const char *const func_name
= "_Unwind_DebugHook";
3545 struct breakpoint
*b
;
3546 struct gdbarch
*gdbarch
;
3547 struct breakpoint_objfile_data
*bp_objfile_data
;
3549 struct explicit_location explicit_loc
;
3551 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3553 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3556 gdbarch
= objfile
->arch ();
3558 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3560 struct bound_minimal_symbol debug_hook
;
3562 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3563 if (debug_hook
.minsym
== NULL
)
3565 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3569 bp_objfile_data
->exception_msym
= debug_hook
;
3572 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3573 addr
= gdbarch_convert_from_func_ptr_addr
3574 (gdbarch
, addr
, current_inferior ()->top_target ());
3575 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3576 &internal_breakpoint_ops
);
3577 initialize_explicit_location (&explicit_loc
);
3578 explicit_loc
.function_name
= ASTRDUP (func_name
);
3579 b
->location
= new_explicit_location (&explicit_loc
);
3580 b
->enable_state
= bp_disabled
;
3585 /* Install a master breakpoint on the unwinder's debug hook. */
3588 create_exception_master_breakpoint (void)
3590 for (objfile
*obj
: current_program_space
->objfiles ())
3592 /* Skip separate debug object. */
3593 if (obj
->separate_debug_objfile_backlink
)
3596 /* Try a probe kind breakpoint. */
3597 if (create_exception_master_breakpoint_probe (obj
))
3600 /* Iterate over main and separate debug objects and try an
3601 _Unwind_DebugHook kind breakpoint. */
3602 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3603 if (create_exception_master_breakpoint_hook (debug_objfile
))
3608 /* Does B have a location spec? */
3611 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3613 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3617 update_breakpoints_after_exec (void)
3619 /* We're about to delete breakpoints from GDB's lists. If the
3620 INSERTED flag is true, GDB will try to lift the breakpoints by
3621 writing the breakpoints' "shadow contents" back into memory. The
3622 "shadow contents" are NOT valid after an exec, so GDB should not
3623 do that. Instead, the target is responsible from marking
3624 breakpoints out as soon as it detects an exec. We don't do that
3625 here instead, because there may be other attempts to delete
3626 breakpoints after detecting an exec and before reaching here. */
3627 for (bp_location
*bploc
: all_bp_locations ())
3628 if (bploc
->pspace
== current_program_space
)
3629 gdb_assert (!bploc
->inserted
);
3631 for (breakpoint
*b
: all_breakpoints_safe ())
3633 if (b
->pspace
!= current_program_space
)
3636 /* Solib breakpoints must be explicitly reset after an exec(). */
3637 if (b
->type
== bp_shlib_event
)
3639 delete_breakpoint (b
);
3643 /* JIT breakpoints must be explicitly reset after an exec(). */
3644 if (b
->type
== bp_jit_event
)
3646 delete_breakpoint (b
);
3650 /* Thread event breakpoints must be set anew after an exec(),
3651 as must overlay event and longjmp master breakpoints. */
3652 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3653 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3654 || b
->type
== bp_exception_master
)
3656 delete_breakpoint (b
);
3660 /* Step-resume breakpoints are meaningless after an exec(). */
3661 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3663 delete_breakpoint (b
);
3667 /* Just like single-step breakpoints. */
3668 if (b
->type
== bp_single_step
)
3670 delete_breakpoint (b
);
3674 /* Longjmp and longjmp-resume breakpoints are also meaningless
3676 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3677 || b
->type
== bp_longjmp_call_dummy
3678 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3680 delete_breakpoint (b
);
3684 if (b
->type
== bp_catchpoint
)
3686 /* For now, none of the bp_catchpoint breakpoints need to
3687 do anything at this point. In the future, if some of
3688 the catchpoints need to something, we will need to add
3689 a new method, and call this method from here. */
3693 /* bp_finish is a special case. The only way we ought to be able
3694 to see one of these when an exec() has happened, is if the user
3695 caught a vfork, and then said "finish". Ordinarily a finish just
3696 carries them to the call-site of the current callee, by setting
3697 a temporary bp there and resuming. But in this case, the finish
3698 will carry them entirely through the vfork & exec.
3700 We don't want to allow a bp_finish to remain inserted now. But
3701 we can't safely delete it, 'cause finish_command has a handle to
3702 the bp on a bpstat, and will later want to delete it. There's a
3703 chance (and I've seen it happen) that if we delete the bp_finish
3704 here, that its storage will get reused by the time finish_command
3705 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3706 We really must allow finish_command to delete a bp_finish.
3708 In the absence of a general solution for the "how do we know
3709 it's safe to delete something others may have handles to?"
3710 problem, what we'll do here is just uninsert the bp_finish, and
3711 let finish_command delete it.
3713 (We know the bp_finish is "doomed" in the sense that it's
3714 momentary, and will be deleted as soon as finish_command sees
3715 the inferior stopped. So it doesn't matter that the bp's
3716 address is probably bogus in the new a.out, unlike e.g., the
3717 solib breakpoints.) */
3719 if (b
->type
== bp_finish
)
3724 /* Without a symbolic address, we have little hope of the
3725 pre-exec() address meaning the same thing in the post-exec()
3727 if (breakpoint_event_location_empty_p (b
))
3729 delete_breakpoint (b
);
3736 detach_breakpoints (ptid_t ptid
)
3739 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3740 struct inferior
*inf
= current_inferior ();
3742 if (ptid
.pid () == inferior_ptid
.pid ())
3743 error (_("Cannot detach breakpoints of inferior_ptid"));
3745 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3746 inferior_ptid
= ptid
;
3747 for (bp_location
*bl
: all_bp_locations ())
3749 if (bl
->pspace
!= inf
->pspace
)
3752 /* This function must physically remove breakpoints locations
3753 from the specified ptid, without modifying the breakpoint
3754 package's state. Locations of type bp_loc_other are only
3755 maintained at GDB side. So, there is no need to remove
3756 these bp_loc_other locations. Moreover, removing these
3757 would modify the breakpoint package's state. */
3758 if (bl
->loc_type
== bp_loc_other
)
3762 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3768 /* Remove the breakpoint location BL from the current address space.
3769 Note that this is used to detach breakpoints from a child fork.
3770 When we get here, the child isn't in the inferior list, and neither
3771 do we have objects to represent its address space --- we should
3772 *not* look at bl->pspace->aspace here. */
3775 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3779 /* BL is never in moribund_locations by our callers. */
3780 gdb_assert (bl
->owner
!= NULL
);
3782 /* The type of none suggests that owner is actually deleted.
3783 This should not ever happen. */
3784 gdb_assert (bl
->owner
->type
!= bp_none
);
3786 if (bl
->loc_type
== bp_loc_software_breakpoint
3787 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3789 /* "Normal" instruction breakpoint: either the standard
3790 trap-instruction bp (bp_breakpoint), or a
3791 bp_hardware_breakpoint. */
3793 /* First check to see if we have to handle an overlay. */
3794 if (overlay_debugging
== ovly_off
3795 || bl
->section
== NULL
3796 || !(section_is_overlay (bl
->section
)))
3798 /* No overlay handling: just remove the breakpoint. */
3800 /* If we're trying to uninsert a memory breakpoint that we
3801 know is set in a dynamic object that is marked
3802 shlib_disabled, then either the dynamic object was
3803 removed with "remove-symbol-file" or with
3804 "nosharedlibrary". In the former case, we don't know
3805 whether another dynamic object might have loaded over the
3806 breakpoint's address -- the user might well let us know
3807 about it next with add-symbol-file (the whole point of
3808 add-symbol-file is letting the user manually maintain a
3809 list of dynamically loaded objects). If we have the
3810 breakpoint's shadow memory, that is, this is a software
3811 breakpoint managed by GDB, check whether the breakpoint
3812 is still inserted in memory, to avoid overwriting wrong
3813 code with stale saved shadow contents. Note that HW
3814 breakpoints don't have shadow memory, as they're
3815 implemented using a mechanism that is not dependent on
3816 being able to modify the target's memory, and as such
3817 they should always be removed. */
3818 if (bl
->shlib_disabled
3819 && bl
->target_info
.shadow_len
!= 0
3820 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3823 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3827 /* This breakpoint is in an overlay section.
3828 Did we set a breakpoint at the LMA? */
3829 if (!overlay_events_enabled
)
3831 /* Yes -- overlay event support is not active, so we
3832 should have set a breakpoint at the LMA. Remove it.
3834 /* Ignore any failures: if the LMA is in ROM, we will
3835 have already warned when we failed to insert it. */
3836 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3837 target_remove_hw_breakpoint (bl
->gdbarch
,
3838 &bl
->overlay_target_info
);
3840 target_remove_breakpoint (bl
->gdbarch
,
3841 &bl
->overlay_target_info
,
3844 /* Did we set a breakpoint at the VMA?
3845 If so, we will have marked the breakpoint 'inserted'. */
3848 /* Yes -- remove it. Previously we did not bother to
3849 remove the breakpoint if the section had been
3850 unmapped, but let's not rely on that being safe. We
3851 don't know what the overlay manager might do. */
3853 /* However, we should remove *software* breakpoints only
3854 if the section is still mapped, or else we overwrite
3855 wrong code with the saved shadow contents. */
3856 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3857 || section_is_mapped (bl
->section
))
3858 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3864 /* No -- not inserted, so no need to remove. No error. */
3869 /* In some cases, we might not be able to remove a breakpoint in
3870 a shared library that has already been removed, but we have
3871 not yet processed the shlib unload event. Similarly for an
3872 unloaded add-symbol-file object - the user might not yet have
3873 had the chance to remove-symbol-file it. shlib_disabled will
3874 be set if the library/object has already been removed, but
3875 the breakpoint hasn't been uninserted yet, e.g., after
3876 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3877 always-inserted mode. */
3879 && (bl
->loc_type
== bp_loc_software_breakpoint
3880 && (bl
->shlib_disabled
3881 || solib_name_from_address (bl
->pspace
, bl
->address
)
3882 || shared_objfile_contains_address_p (bl
->pspace
,
3888 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3890 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3892 gdb_assert (bl
->owner
->ops
!= NULL
3893 && bl
->owner
->ops
->remove_location
!= NULL
);
3895 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3896 bl
->owner
->ops
->remove_location (bl
, reason
);
3898 /* Failure to remove any of the hardware watchpoints comes here. */
3899 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3900 warning (_("Could not remove hardware watchpoint %d."),
3903 else if (bl
->owner
->type
== bp_catchpoint
3904 && breakpoint_enabled (bl
->owner
)
3907 gdb_assert (bl
->owner
->ops
!= NULL
3908 && bl
->owner
->ops
->remove_location
!= NULL
);
3910 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3914 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3921 remove_breakpoint (struct bp_location
*bl
)
3923 /* BL is never in moribund_locations by our callers. */
3924 gdb_assert (bl
->owner
!= NULL
);
3926 /* The type of none suggests that owner is actually deleted.
3927 This should not ever happen. */
3928 gdb_assert (bl
->owner
->type
!= bp_none
);
3930 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3932 switch_to_program_space_and_thread (bl
->pspace
);
3934 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3937 /* Clear the "inserted" flag in all breakpoints. */
3940 mark_breakpoints_out (void)
3942 for (bp_location
*bl
: all_bp_locations ())
3943 if (bl
->pspace
== current_program_space
)
3947 /* Clear the "inserted" flag in all breakpoints and delete any
3948 breakpoints which should go away between runs of the program.
3950 Plus other such housekeeping that has to be done for breakpoints
3953 Note: this function gets called at the end of a run (by
3954 generic_mourn_inferior) and when a run begins (by
3955 init_wait_for_inferior). */
3960 breakpoint_init_inferior (enum inf_context context
)
3962 struct program_space
*pspace
= current_program_space
;
3964 /* If breakpoint locations are shared across processes, then there's
3966 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3969 mark_breakpoints_out ();
3971 for (breakpoint
*b
: all_breakpoints_safe ())
3973 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3979 case bp_longjmp_call_dummy
:
3981 /* If the call dummy breakpoint is at the entry point it will
3982 cause problems when the inferior is rerun, so we better get
3985 case bp_watchpoint_scope
:
3987 /* Also get rid of scope breakpoints. */
3989 case bp_shlib_event
:
3991 /* Also remove solib event breakpoints. Their addresses may
3992 have changed since the last time we ran the program.
3993 Actually we may now be debugging against different target;
3994 and so the solib backend that installed this breakpoint may
3995 not be used in by the target. E.g.,
3997 (gdb) file prog-linux
3998 (gdb) run # native linux target
4001 (gdb) file prog-win.exe
4002 (gdb) tar rem :9999 # remote Windows gdbserver.
4005 case bp_step_resume
:
4007 /* Also remove step-resume breakpoints. */
4009 case bp_single_step
:
4011 /* Also remove single-step breakpoints. */
4013 delete_breakpoint (b
);
4017 case bp_hardware_watchpoint
:
4018 case bp_read_watchpoint
:
4019 case bp_access_watchpoint
:
4021 struct watchpoint
*w
= (struct watchpoint
*) b
;
4023 /* Likewise for watchpoints on local expressions. */
4024 if (w
->exp_valid_block
!= NULL
)
4025 delete_breakpoint (b
);
4028 /* Get rid of existing locations, which are no longer
4029 valid. New ones will be created in
4030 update_watchpoint, when the inferior is restarted.
4031 The next update_global_location_list call will
4032 garbage collect them. */
4035 if (context
== inf_starting
)
4037 /* Reset val field to force reread of starting value in
4038 insert_breakpoints. */
4039 w
->val
.reset (nullptr);
4040 w
->val_valid
= false;
4050 /* Get rid of the moribund locations. */
4051 for (bp_location
*bl
: moribund_locations
)
4052 decref_bp_location (&bl
);
4053 moribund_locations
.clear ();
4056 /* These functions concern about actual breakpoints inserted in the
4057 target --- to e.g. check if we need to do decr_pc adjustment or if
4058 we need to hop over the bkpt --- so we check for address space
4059 match, not program space. */
4061 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4062 exists at PC. It returns ordinary_breakpoint_here if it's an
4063 ordinary breakpoint, or permanent_breakpoint_here if it's a
4064 permanent breakpoint.
4065 - When continuing from a location with an ordinary breakpoint, we
4066 actually single step once before calling insert_breakpoints.
4067 - When continuing from a location with a permanent breakpoint, we
4068 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4069 the target, to advance the PC past the breakpoint. */
4071 enum breakpoint_here
4072 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4074 int any_breakpoint_here
= 0;
4076 for (bp_location
*bl
: all_bp_locations ())
4078 if (bl
->loc_type
!= bp_loc_software_breakpoint
4079 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4082 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4083 if ((breakpoint_enabled (bl
->owner
)
4085 && breakpoint_location_address_match (bl
, aspace
, pc
))
4087 if (overlay_debugging
4088 && section_is_overlay (bl
->section
)
4089 && !section_is_mapped (bl
->section
))
4090 continue; /* unmapped overlay -- can't be a match */
4091 else if (bl
->permanent
)
4092 return permanent_breakpoint_here
;
4094 any_breakpoint_here
= 1;
4098 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4101 /* See breakpoint.h. */
4104 breakpoint_in_range_p (const address_space
*aspace
,
4105 CORE_ADDR addr
, ULONGEST len
)
4107 for (bp_location
*bl
: all_bp_locations ())
4109 if (bl
->loc_type
!= bp_loc_software_breakpoint
4110 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4113 if ((breakpoint_enabled (bl
->owner
)
4115 && breakpoint_location_address_range_overlap (bl
, aspace
,
4118 if (overlay_debugging
4119 && section_is_overlay (bl
->section
)
4120 && !section_is_mapped (bl
->section
))
4122 /* Unmapped overlay -- can't be a match. */
4133 /* Return true if there's a moribund breakpoint at PC. */
4136 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4138 for (bp_location
*loc
: moribund_locations
)
4139 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4145 /* Returns non-zero iff BL is inserted at PC, in address space
4149 bp_location_inserted_here_p (struct bp_location
*bl
,
4150 const address_space
*aspace
, CORE_ADDR pc
)
4153 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4156 if (overlay_debugging
4157 && section_is_overlay (bl
->section
)
4158 && !section_is_mapped (bl
->section
))
4159 return 0; /* unmapped overlay -- can't be a match */
4166 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4169 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4171 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4173 if (bl
->loc_type
!= bp_loc_software_breakpoint
4174 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4177 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4183 /* This function returns non-zero iff there is a software breakpoint
4187 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4190 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4192 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4195 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4202 /* See breakpoint.h. */
4205 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4208 for (bp_location
*bl
: all_bp_locations_at_addr (pc
))
4210 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4213 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4221 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4222 CORE_ADDR addr
, ULONGEST len
)
4224 for (breakpoint
*bpt
: all_breakpoints ())
4226 if (bpt
->type
!= bp_hardware_watchpoint
4227 && bpt
->type
!= bp_access_watchpoint
)
4230 if (!breakpoint_enabled (bpt
))
4233 for (bp_location
*loc
: bpt
->locations ())
4234 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4238 /* Check for intersection. */
4239 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4240 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4248 /* See breakpoint.h. */
4251 is_catchpoint (struct breakpoint
*b
)
4253 return (b
->type
== bp_catchpoint
);
4256 /* Clear a bpstat so that it says we are not at any breakpoint.
4257 Also free any storage that is part of a bpstat. */
4260 bpstat_clear (bpstat
*bsp
)
4277 bpstats::bpstats (const bpstats
&other
)
4279 bp_location_at (other
.bp_location_at
),
4280 breakpoint_at (other
.breakpoint_at
),
4281 commands (other
.commands
),
4282 print (other
.print
),
4284 print_it (other
.print_it
)
4286 if (other
.old_val
!= NULL
)
4287 old_val
= release_value (value_copy (other
.old_val
.get ()));
4290 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4291 is part of the bpstat is copied as well. */
4294 bpstat_copy (bpstat bs
)
4298 bpstat retval
= NULL
;
4303 for (; bs
!= NULL
; bs
= bs
->next
)
4305 tmp
= new bpstats (*bs
);
4308 /* This is the first thing in the chain. */
4318 /* Find the bpstat associated with this breakpoint. */
4321 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4326 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4328 if (bsp
->breakpoint_at
== breakpoint
)
4334 /* See breakpoint.h. */
4337 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4339 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4341 if (bsp
->breakpoint_at
== NULL
)
4343 /* A moribund location can never explain a signal other than
4345 if (sig
== GDB_SIGNAL_TRAP
)
4350 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4359 /* Put in *NUM the breakpoint number of the first breakpoint we are
4360 stopped at. *BSP upon return is a bpstat which points to the
4361 remaining breakpoints stopped at (but which is not guaranteed to be
4362 good for anything but further calls to bpstat_num).
4364 Return 0 if passed a bpstat which does not indicate any breakpoints.
4365 Return -1 if stopped at a breakpoint that has been deleted since
4367 Return 1 otherwise. */
4370 bpstat_num (bpstat
*bsp
, int *num
)
4372 struct breakpoint
*b
;
4375 return 0; /* No more breakpoint values */
4377 /* We assume we'll never have several bpstats that correspond to a
4378 single breakpoint -- otherwise, this function might return the
4379 same number more than once and this will look ugly. */
4380 b
= (*bsp
)->breakpoint_at
;
4381 *bsp
= (*bsp
)->next
;
4383 return -1; /* breakpoint that's been deleted since */
4385 *num
= b
->number
; /* We have its number */
4389 /* See breakpoint.h. */
4392 bpstat_clear_actions (void)
4396 if (inferior_ptid
== null_ptid
)
4399 thread_info
*tp
= inferior_thread ();
4400 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4402 bs
->commands
= NULL
;
4403 bs
->old_val
.reset (nullptr);
4407 /* Called when a command is about to proceed the inferior. */
4410 breakpoint_about_to_proceed (void)
4412 if (inferior_ptid
!= null_ptid
)
4414 struct thread_info
*tp
= inferior_thread ();
4416 /* Allow inferior function calls in breakpoint commands to not
4417 interrupt the command list. When the call finishes
4418 successfully, the inferior will be standing at the same
4419 breakpoint as if nothing happened. */
4420 if (tp
->control
.in_infcall
)
4424 breakpoint_proceeded
= 1;
4427 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4428 or its equivalent. */
4431 command_line_is_silent (struct command_line
*cmd
)
4433 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4436 /* Execute all the commands associated with all the breakpoints at
4437 this location. Any of these commands could cause the process to
4438 proceed beyond this point, etc. We look out for such changes by
4439 checking the global "breakpoint_proceeded" after each command.
4441 Returns true if a breakpoint command resumed the inferior. In that
4442 case, it is the caller's responsibility to recall it again with the
4443 bpstat of the current thread. */
4446 bpstat_do_actions_1 (bpstat
*bsp
)
4451 /* Avoid endless recursion if a `source' command is contained
4453 if (executing_breakpoint_commands
)
4456 scoped_restore save_executing
4457 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4459 scoped_restore preventer
= prevent_dont_repeat ();
4461 /* This pointer will iterate over the list of bpstat's. */
4464 breakpoint_proceeded
= 0;
4465 for (; bs
!= NULL
; bs
= bs
->next
)
4467 struct command_line
*cmd
= NULL
;
4469 /* Take ownership of the BSP's command tree, if it has one.
4471 The command tree could legitimately contain commands like
4472 'step' and 'next', which call clear_proceed_status, which
4473 frees stop_bpstat's command tree. To make sure this doesn't
4474 free the tree we're executing out from under us, we need to
4475 take ownership of the tree ourselves. Since a given bpstat's
4476 commands are only executed once, we don't need to copy it; we
4477 can clear the pointer in the bpstat, and make sure we free
4478 the tree when we're done. */
4479 counted_command_line ccmd
= bs
->commands
;
4480 bs
->commands
= NULL
;
4483 if (command_line_is_silent (cmd
))
4485 /* The action has been already done by bpstat_stop_status. */
4491 execute_control_command (cmd
);
4493 if (breakpoint_proceeded
)
4499 if (breakpoint_proceeded
)
4501 if (current_ui
->async
)
4502 /* If we are in async mode, then the target might be still
4503 running, not stopped at any breakpoint, so nothing for
4504 us to do here -- just return to the event loop. */
4507 /* In sync mode, when execute_control_command returns
4508 we're already standing on the next breakpoint.
4509 Breakpoint commands for that stop were not run, since
4510 execute_command does not run breakpoint commands --
4511 only command_line_handler does, but that one is not
4512 involved in execution of breakpoint commands. So, we
4513 can now execute breakpoint commands. It should be
4514 noted that making execute_command do bpstat actions is
4515 not an option -- in this case we'll have recursive
4516 invocation of bpstat for each breakpoint with a
4517 command, and can easily blow up GDB stack. Instead, we
4518 return true, which will trigger the caller to recall us
4519 with the new stop_bpstat. */
4527 /* Helper for bpstat_do_actions. Get the current thread, if there's
4528 one, is alive and has execution. Return NULL otherwise. */
4530 static thread_info
*
4531 get_bpstat_thread ()
4533 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4536 thread_info
*tp
= inferior_thread ();
4537 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4543 bpstat_do_actions (void)
4545 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4548 /* Do any commands attached to breakpoint we are stopped at. */
4549 while ((tp
= get_bpstat_thread ()) != NULL
)
4551 /* Since in sync mode, bpstat_do_actions may resume the
4552 inferior, and only return when it is stopped at the next
4553 breakpoint, we keep doing breakpoint actions until it returns
4554 false to indicate the inferior was not resumed. */
4555 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4559 cleanup_if_error
.release ();
4562 /* Print out the (old or new) value associated with a watchpoint. */
4565 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4568 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4571 struct value_print_options opts
;
4572 get_user_print_options (&opts
);
4573 value_print (val
, stream
, &opts
);
4577 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4578 debugging multiple threads. */
4581 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4583 if (uiout
->is_mi_like_p ())
4588 if (show_thread_that_caused_stop ())
4591 struct thread_info
*thr
= inferior_thread ();
4593 uiout
->text ("Thread ");
4594 uiout
->field_string ("thread-id", print_thread_id (thr
));
4596 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4599 uiout
->text (" \"");
4600 uiout
->field_string ("name", name
);
4604 uiout
->text (" hit ");
4608 /* Generic routine for printing messages indicating why we
4609 stopped. The behavior of this function depends on the value
4610 'print_it' in the bpstat structure. Under some circumstances we
4611 may decide not to print anything here and delegate the task to
4614 static enum print_stop_action
4615 print_bp_stop_message (bpstat bs
)
4617 switch (bs
->print_it
)
4620 /* Nothing should be printed for this bpstat entry. */
4621 return PRINT_UNKNOWN
;
4625 /* We still want to print the frame, but we already printed the
4626 relevant messages. */
4627 return PRINT_SRC_AND_LOC
;
4630 case print_it_normal
:
4632 struct breakpoint
*b
= bs
->breakpoint_at
;
4634 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4635 which has since been deleted. */
4637 return PRINT_UNKNOWN
;
4639 /* Normal case. Call the breakpoint's print_it method. */
4640 return b
->ops
->print_it (bs
);
4645 internal_error (__FILE__
, __LINE__
,
4646 _("print_bp_stop_message: unrecognized enum value"));
4651 /* A helper function that prints a shared library stopped event. */
4654 print_solib_event (int is_catchpoint
)
4656 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4657 bool any_added
= !current_program_space
->added_solibs
.empty ();
4661 if (any_added
|| any_deleted
)
4662 current_uiout
->text (_("Stopped due to shared library event:\n"));
4664 current_uiout
->text (_("Stopped due to shared library event (no "
4665 "libraries added or removed)\n"));
4668 if (current_uiout
->is_mi_like_p ())
4669 current_uiout
->field_string ("reason",
4670 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4674 current_uiout
->text (_(" Inferior unloaded "));
4675 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4676 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4678 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4681 current_uiout
->text (" ");
4682 current_uiout
->field_string ("library", name
);
4683 current_uiout
->text ("\n");
4689 current_uiout
->text (_(" Inferior loaded "));
4690 ui_out_emit_list
list_emitter (current_uiout
, "added");
4692 for (so_list
*iter
: current_program_space
->added_solibs
)
4695 current_uiout
->text (" ");
4697 current_uiout
->field_string ("library", iter
->so_name
);
4698 current_uiout
->text ("\n");
4703 /* Print a message indicating what happened. This is called from
4704 normal_stop(). The input to this routine is the head of the bpstat
4705 list - a list of the eventpoints that caused this stop. KIND is
4706 the target_waitkind for the stopping event. This
4707 routine calls the generic print routine for printing a message
4708 about reasons for stopping. This will print (for example) the
4709 "Breakpoint n," part of the output. The return value of this
4712 PRINT_UNKNOWN: Means we printed nothing.
4713 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4714 code to print the location. An example is
4715 "Breakpoint 1, " which should be followed by
4717 PRINT_SRC_ONLY: Means we printed something, but there is no need
4718 to also print the location part of the message.
4719 An example is the catch/throw messages, which
4720 don't require a location appended to the end.
4721 PRINT_NOTHING: We have done some printing and we don't need any
4722 further info to be printed. */
4724 enum print_stop_action
4725 bpstat_print (bpstat bs
, int kind
)
4727 enum print_stop_action val
;
4729 /* Maybe another breakpoint in the chain caused us to stop.
4730 (Currently all watchpoints go on the bpstat whether hit or not.
4731 That probably could (should) be changed, provided care is taken
4732 with respect to bpstat_explains_signal). */
4733 for (; bs
; bs
= bs
->next
)
4735 val
= print_bp_stop_message (bs
);
4736 if (val
== PRINT_SRC_ONLY
4737 || val
== PRINT_SRC_AND_LOC
4738 || val
== PRINT_NOTHING
)
4742 /* If we had hit a shared library event breakpoint,
4743 print_bp_stop_message would print out this message. If we hit an
4744 OS-level shared library event, do the same thing. */
4745 if (kind
== TARGET_WAITKIND_LOADED
)
4747 print_solib_event (0);
4748 return PRINT_NOTHING
;
4751 /* We reached the end of the chain, or we got a null BS to start
4752 with and nothing was printed. */
4753 return PRINT_UNKNOWN
;
4756 /* Evaluate the boolean expression EXP and return the result. */
4759 breakpoint_cond_eval (expression
*exp
)
4761 struct value
*mark
= value_mark ();
4762 bool res
= value_true (evaluate_expression (exp
));
4764 value_free_to_mark (mark
);
4768 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4770 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4772 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4773 breakpoint_at (bl
->owner
),
4777 print_it (print_it_normal
)
4779 **bs_link_pointer
= this;
4780 *bs_link_pointer
= &next
;
4785 breakpoint_at (NULL
),
4789 print_it (print_it_normal
)
4793 /* The target has stopped with waitstatus WS. Check if any hardware
4794 watchpoints have triggered, according to the target. */
4797 watchpoints_triggered (struct target_waitstatus
*ws
)
4799 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4802 if (!stopped_by_watchpoint
)
4804 /* We were not stopped by a watchpoint. Mark all watchpoints
4805 as not triggered. */
4806 for (breakpoint
*b
: all_breakpoints ())
4807 if (is_hardware_watchpoint (b
))
4809 struct watchpoint
*w
= (struct watchpoint
*) b
;
4811 w
->watchpoint_triggered
= watch_triggered_no
;
4817 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4819 /* We were stopped by a watchpoint, but we don't know where.
4820 Mark all watchpoints as unknown. */
4821 for (breakpoint
*b
: all_breakpoints ())
4822 if (is_hardware_watchpoint (b
))
4824 struct watchpoint
*w
= (struct watchpoint
*) b
;
4826 w
->watchpoint_triggered
= watch_triggered_unknown
;
4832 /* The target could report the data address. Mark watchpoints
4833 affected by this data address as triggered, and all others as not
4836 for (breakpoint
*b
: all_breakpoints ())
4837 if (is_hardware_watchpoint (b
))
4839 struct watchpoint
*w
= (struct watchpoint
*) b
;
4841 w
->watchpoint_triggered
= watch_triggered_no
;
4842 for (bp_location
*loc
: b
->locations ())
4844 if (is_masked_watchpoint (b
))
4846 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4847 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4849 if (newaddr
== start
)
4851 w
->watchpoint_triggered
= watch_triggered_yes
;
4855 /* Exact match not required. Within range is sufficient. */
4856 else if (target_watchpoint_addr_within_range
4857 (current_inferior ()->top_target (), addr
, loc
->address
,
4860 w
->watchpoint_triggered
= watch_triggered_yes
;
4869 /* Possible return values for watchpoint_check. */
4870 enum wp_check_result
4872 /* The watchpoint has been deleted. */
4875 /* The value has changed. */
4876 WP_VALUE_CHANGED
= 2,
4878 /* The value has not changed. */
4879 WP_VALUE_NOT_CHANGED
= 3,
4881 /* Ignore this watchpoint, no matter if the value changed or not. */
4885 #define BP_TEMPFLAG 1
4886 #define BP_HARDWAREFLAG 2
4888 /* Evaluate watchpoint condition expression and check if its value
4891 static wp_check_result
4892 watchpoint_check (bpstat bs
)
4894 struct watchpoint
*b
;
4895 struct frame_info
*fr
;
4896 int within_current_scope
;
4898 /* BS is built from an existing struct breakpoint. */
4899 gdb_assert (bs
->breakpoint_at
!= NULL
);
4900 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4902 /* If this is a local watchpoint, we only want to check if the
4903 watchpoint frame is in scope if the current thread is the thread
4904 that was used to create the watchpoint. */
4905 if (!watchpoint_in_thread_scope (b
))
4908 if (b
->exp_valid_block
== NULL
)
4909 within_current_scope
= 1;
4912 struct frame_info
*frame
= get_current_frame ();
4913 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4914 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4916 /* stack_frame_destroyed_p() returns a non-zero value if we're
4917 still in the function but the stack frame has already been
4918 invalidated. Since we can't rely on the values of local
4919 variables after the stack has been destroyed, we are treating
4920 the watchpoint in that state as `not changed' without further
4921 checking. Don't mark watchpoints as changed if the current
4922 frame is in an epilogue - even if they are in some other
4923 frame, our view of the stack is likely to be wrong and
4924 frame_find_by_id could error out. */
4925 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4928 fr
= frame_find_by_id (b
->watchpoint_frame
);
4929 within_current_scope
= (fr
!= NULL
);
4931 /* If we've gotten confused in the unwinder, we might have
4932 returned a frame that can't describe this variable. */
4933 if (within_current_scope
)
4935 struct symbol
*function
;
4937 function
= get_frame_function (fr
);
4938 if (function
== NULL
4939 || !contained_in (b
->exp_valid_block
,
4940 SYMBOL_BLOCK_VALUE (function
)))
4941 within_current_scope
= 0;
4944 if (within_current_scope
)
4945 /* If we end up stopping, the current frame will get selected
4946 in normal_stop. So this call to select_frame won't affect
4951 if (within_current_scope
)
4953 /* We use value_{,free_to_}mark because it could be a *long*
4954 time before we return to the command level and call
4955 free_all_values. We can't call free_all_values because we
4956 might be in the middle of evaluating a function call. */
4959 struct value
*new_val
;
4961 if (is_masked_watchpoint (b
))
4962 /* Since we don't know the exact trigger address (from
4963 stopped_data_address), just tell the user we've triggered
4964 a mask watchpoint. */
4965 return WP_VALUE_CHANGED
;
4967 mark
= value_mark ();
4968 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
4971 if (b
->val_bitsize
!= 0)
4972 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4974 /* We use value_equal_contents instead of value_equal because
4975 the latter coerces an array to a pointer, thus comparing just
4976 the address of the array instead of its contents. This is
4977 not what we want. */
4978 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4979 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
4982 bs
->old_val
= b
->val
;
4983 b
->val
= release_value (new_val
);
4984 b
->val_valid
= true;
4985 if (new_val
!= NULL
)
4986 value_free_to_mark (mark
);
4987 return WP_VALUE_CHANGED
;
4991 /* Nothing changed. */
4992 value_free_to_mark (mark
);
4993 return WP_VALUE_NOT_CHANGED
;
4998 /* This seems like the only logical thing to do because
4999 if we temporarily ignored the watchpoint, then when
5000 we reenter the block in which it is valid it contains
5001 garbage (in the case of a function, it may have two
5002 garbage values, one before and one after the prologue).
5003 So we can't even detect the first assignment to it and
5004 watch after that (since the garbage may or may not equal
5005 the first value assigned). */
5006 /* We print all the stop information in
5007 breakpoint_ops->print_it, but in this case, by the time we
5008 call breakpoint_ops->print_it this bp will be deleted
5009 already. So we have no choice but print the information
5012 SWITCH_THRU_ALL_UIS ()
5014 struct ui_out
*uiout
= current_uiout
;
5016 if (uiout
->is_mi_like_p ())
5018 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5019 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5020 "left the block in\n"
5021 "which its expression is valid.\n",
5022 signed_field ("wpnum", b
->number
));
5025 /* Make sure the watchpoint's commands aren't executed. */
5027 watchpoint_del_at_next_stop (b
);
5033 /* Return true if it looks like target has stopped due to hitting
5034 breakpoint location BL. This function does not check if we should
5035 stop, only if BL explains the stop. */
5038 bpstat_check_location (const struct bp_location
*bl
,
5039 const address_space
*aspace
, CORE_ADDR bp_addr
,
5040 const struct target_waitstatus
*ws
)
5042 struct breakpoint
*b
= bl
->owner
;
5044 /* BL is from an existing breakpoint. */
5045 gdb_assert (b
!= NULL
);
5047 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5050 /* Determine if the watched values have actually changed, and we
5051 should stop. If not, set BS->stop to 0. */
5054 bpstat_check_watchpoint (bpstat bs
)
5056 const struct bp_location
*bl
;
5057 struct watchpoint
*b
;
5059 /* BS is built for existing struct breakpoint. */
5060 bl
= bs
->bp_location_at
.get ();
5061 gdb_assert (bl
!= NULL
);
5062 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5063 gdb_assert (b
!= NULL
);
5066 int must_check_value
= 0;
5068 if (b
->type
== bp_watchpoint
)
5069 /* For a software watchpoint, we must always check the
5071 must_check_value
= 1;
5072 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5073 /* We have a hardware watchpoint (read, write, or access)
5074 and the target earlier reported an address watched by
5076 must_check_value
= 1;
5077 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5078 && b
->type
== bp_hardware_watchpoint
)
5079 /* We were stopped by a hardware watchpoint, but the target could
5080 not report the data address. We must check the watchpoint's
5081 value. Access and read watchpoints are out of luck; without
5082 a data address, we can't figure it out. */
5083 must_check_value
= 1;
5085 if (must_check_value
)
5091 e
= watchpoint_check (bs
);
5093 catch (const gdb_exception
&ex
)
5095 exception_fprintf (gdb_stderr
, ex
,
5096 "Error evaluating expression "
5097 "for watchpoint %d\n",
5100 SWITCH_THRU_ALL_UIS ()
5102 printf_filtered (_("Watchpoint %d deleted.\n"),
5105 watchpoint_del_at_next_stop (b
);
5112 /* We've already printed what needs to be printed. */
5113 bs
->print_it
= print_it_done
;
5117 bs
->print_it
= print_it_noop
;
5120 case WP_VALUE_CHANGED
:
5121 if (b
->type
== bp_read_watchpoint
)
5123 /* There are two cases to consider here:
5125 1. We're watching the triggered memory for reads.
5126 In that case, trust the target, and always report
5127 the watchpoint hit to the user. Even though
5128 reads don't cause value changes, the value may
5129 have changed since the last time it was read, and
5130 since we're not trapping writes, we will not see
5131 those, and as such we should ignore our notion of
5134 2. We're watching the triggered memory for both
5135 reads and writes. There are two ways this may
5138 2.1. This is a target that can't break on data
5139 reads only, but can break on accesses (reads or
5140 writes), such as e.g., x86. We detect this case
5141 at the time we try to insert read watchpoints.
5143 2.2. Otherwise, the target supports read
5144 watchpoints, but, the user set an access or write
5145 watchpoint watching the same memory as this read
5148 If we're watching memory writes as well as reads,
5149 ignore watchpoint hits when we find that the
5150 value hasn't changed, as reads don't cause
5151 changes. This still gives false positives when
5152 the program writes the same value to memory as
5153 what there was already in memory (we will confuse
5154 it for a read), but it's much better than
5157 int other_write_watchpoint
= 0;
5159 if (bl
->watchpoint_type
== hw_read
)
5161 for (breakpoint
*other_b
: all_breakpoints ())
5162 if (other_b
->type
== bp_hardware_watchpoint
5163 || other_b
->type
== bp_access_watchpoint
)
5165 struct watchpoint
*other_w
=
5166 (struct watchpoint
*) other_b
;
5168 if (other_w
->watchpoint_triggered
5169 == watch_triggered_yes
)
5171 other_write_watchpoint
= 1;
5177 if (other_write_watchpoint
5178 || bl
->watchpoint_type
== hw_access
)
5180 /* We're watching the same memory for writes,
5181 and the value changed since the last time we
5182 updated it, so this trap must be for a write.
5184 bs
->print_it
= print_it_noop
;
5189 case WP_VALUE_NOT_CHANGED
:
5190 if (b
->type
== bp_hardware_watchpoint
5191 || b
->type
== bp_watchpoint
)
5193 /* Don't stop: write watchpoints shouldn't fire if
5194 the value hasn't changed. */
5195 bs
->print_it
= print_it_noop
;
5205 else /* must_check_value == 0 */
5207 /* This is a case where some watchpoint(s) triggered, but
5208 not at the address of this watchpoint, or else no
5209 watchpoint triggered after all. So don't print
5210 anything for this watchpoint. */
5211 bs
->print_it
= print_it_noop
;
5217 /* For breakpoints that are currently marked as telling gdb to stop,
5218 check conditions (condition proper, frame, thread and ignore count)
5219 of breakpoint referred to by BS. If we should not stop for this
5220 breakpoint, set BS->stop to 0. */
5223 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5225 const struct bp_location
*bl
;
5226 struct breakpoint
*b
;
5228 bool condition_result
= true;
5229 struct expression
*cond
;
5231 gdb_assert (bs
->stop
);
5233 /* BS is built for existing struct breakpoint. */
5234 bl
= bs
->bp_location_at
.get ();
5235 gdb_assert (bl
!= NULL
);
5236 b
= bs
->breakpoint_at
;
5237 gdb_assert (b
!= NULL
);
5239 /* Even if the target evaluated the condition on its end and notified GDB, we
5240 need to do so again since GDB does not know if we stopped due to a
5241 breakpoint or a single step breakpoint. */
5243 if (frame_id_p (b
->frame_id
)
5244 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5250 /* If this is a thread/task-specific breakpoint, don't waste cpu
5251 evaluating the condition if this isn't the specified
5253 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5254 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5260 /* Evaluate extension language breakpoints that have a "stop" method
5262 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5264 if (is_watchpoint (b
))
5266 struct watchpoint
*w
= (struct watchpoint
*) b
;
5268 cond
= w
->cond_exp
.get ();
5271 cond
= bl
->cond
.get ();
5273 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5275 int within_current_scope
= 1;
5276 struct watchpoint
* w
;
5278 /* We use value_mark and value_free_to_mark because it could
5279 be a long time before we return to the command level and
5280 call free_all_values. We can't call free_all_values
5281 because we might be in the middle of evaluating a
5283 struct value
*mark
= value_mark ();
5285 if (is_watchpoint (b
))
5286 w
= (struct watchpoint
*) b
;
5290 /* Need to select the frame, with all that implies so that
5291 the conditions will have the right context. Because we
5292 use the frame, we will not see an inlined function's
5293 variables when we arrive at a breakpoint at the start
5294 of the inlined function; the current frame will be the
5296 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5297 select_frame (get_current_frame ());
5300 struct frame_info
*frame
;
5302 /* For local watchpoint expressions, which particular
5303 instance of a local is being watched matters, so we
5304 keep track of the frame to evaluate the expression
5305 in. To evaluate the condition however, it doesn't
5306 really matter which instantiation of the function
5307 where the condition makes sense triggers the
5308 watchpoint. This allows an expression like "watch
5309 global if q > 10" set in `func', catch writes to
5310 global on all threads that call `func', or catch
5311 writes on all recursive calls of `func' by a single
5312 thread. We simply always evaluate the condition in
5313 the innermost frame that's executing where it makes
5314 sense to evaluate the condition. It seems
5316 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5318 select_frame (frame
);
5320 within_current_scope
= 0;
5322 if (within_current_scope
)
5326 condition_result
= breakpoint_cond_eval (cond
);
5328 catch (const gdb_exception
&ex
)
5330 exception_fprintf (gdb_stderr
, ex
,
5331 "Error in testing breakpoint condition:\n");
5336 warning (_("Watchpoint condition cannot be tested "
5337 "in the current scope"));
5338 /* If we failed to set the right context for this
5339 watchpoint, unconditionally report it. */
5341 /* FIXME-someday, should give breakpoint #. */
5342 value_free_to_mark (mark
);
5345 if (cond
&& !condition_result
)
5349 else if (b
->ignore_count
> 0)
5353 /* Increase the hit count even though we don't stop. */
5355 gdb::observers::breakpoint_modified
.notify (b
);
5359 /* Returns true if we need to track moribund locations of LOC's type
5360 on the current target. */
5363 need_moribund_for_location_type (struct bp_location
*loc
)
5365 return ((loc
->loc_type
== bp_loc_software_breakpoint
5366 && !target_supports_stopped_by_sw_breakpoint ())
5367 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5368 && !target_supports_stopped_by_hw_breakpoint ()));
5371 /* See breakpoint.h. */
5374 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5375 const struct target_waitstatus
*ws
)
5377 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5379 for (breakpoint
*b
: all_breakpoints ())
5381 if (!breakpoint_enabled (b
))
5384 for (bp_location
*bl
: b
->locations ())
5386 /* For hardware watchpoints, we look only at the first
5387 location. The watchpoint_check function will work on the
5388 entire expression, not the individual locations. For
5389 read watchpoints, the watchpoints_triggered function has
5390 checked all locations already. */
5391 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5394 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5397 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5400 /* Come here if it's a watchpoint, or if the break address
5403 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5406 /* Assume we stop. Should we find a watchpoint that is not
5407 actually triggered, or if the condition of the breakpoint
5408 evaluates as false, we'll reset 'stop' to 0. */
5412 /* If this is a scope breakpoint, mark the associated
5413 watchpoint as triggered so that we will handle the
5414 out-of-scope event. We'll get to the watchpoint next
5416 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5418 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5420 w
->watchpoint_triggered
= watch_triggered_yes
;
5425 /* Check if a moribund breakpoint explains the stop. */
5426 if (!target_supports_stopped_by_sw_breakpoint ()
5427 || !target_supports_stopped_by_hw_breakpoint ())
5429 for (bp_location
*loc
: moribund_locations
)
5431 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5432 && need_moribund_for_location_type (loc
))
5434 bpstat bs
= new bpstats (loc
, &bs_link
);
5435 /* For hits of moribund locations, we should just proceed. */
5438 bs
->print_it
= print_it_noop
;
5446 /* See breakpoint.h. */
5449 bpstat_stop_status (const address_space
*aspace
,
5450 CORE_ADDR bp_addr
, thread_info
*thread
,
5451 const struct target_waitstatus
*ws
,
5454 struct breakpoint
*b
= NULL
;
5455 /* First item of allocated bpstat's. */
5456 bpstat bs_head
= stop_chain
;
5458 int need_remove_insert
;
5461 /* First, build the bpstat chain with locations that explain a
5462 target stop, while being careful to not set the target running,
5463 as that may invalidate locations (in particular watchpoint
5464 locations are recreated). Resuming will happen here with
5465 breakpoint conditions or watchpoint expressions that include
5466 inferior function calls. */
5467 if (bs_head
== NULL
)
5468 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5470 /* A bit of special processing for shlib breakpoints. We need to
5471 process solib loading here, so that the lists of loaded and
5472 unloaded libraries are correct before we handle "catch load" and
5474 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5476 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5478 handle_solib_event ();
5483 /* Now go through the locations that caused the target to stop, and
5484 check whether we're interested in reporting this stop to higher
5485 layers, or whether we should resume the target transparently. */
5489 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5494 b
= bs
->breakpoint_at
;
5495 b
->ops
->check_status (bs
);
5498 bpstat_check_breakpoint_conditions (bs
, thread
);
5503 gdb::observers::breakpoint_modified
.notify (b
);
5505 /* We will stop here. */
5506 if (b
->disposition
== disp_disable
)
5508 --(b
->enable_count
);
5509 if (b
->enable_count
<= 0)
5510 b
->enable_state
= bp_disabled
;
5515 bs
->commands
= b
->commands
;
5516 if (command_line_is_silent (bs
->commands
5517 ? bs
->commands
.get () : NULL
))
5520 b
->ops
->after_condition_true (bs
);
5525 /* Print nothing for this entry if we don't stop or don't
5527 if (!bs
->stop
|| !bs
->print
)
5528 bs
->print_it
= print_it_noop
;
5531 /* If we aren't stopping, the value of some hardware watchpoint may
5532 not have changed, but the intermediate memory locations we are
5533 watching may have. Don't bother if we're stopping; this will get
5535 need_remove_insert
= 0;
5536 if (! bpstat_causes_stop (bs_head
))
5537 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5539 && bs
->breakpoint_at
5540 && is_hardware_watchpoint (bs
->breakpoint_at
))
5542 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5544 update_watchpoint (w
, 0 /* don't reparse. */);
5545 need_remove_insert
= 1;
5548 if (need_remove_insert
)
5549 update_global_location_list (UGLL_MAY_INSERT
);
5550 else if (removed_any
)
5551 update_global_location_list (UGLL_DONT_INSERT
);
5557 handle_jit_event (CORE_ADDR address
)
5559 struct gdbarch
*gdbarch
;
5561 infrun_debug_printf ("handling bp_jit_event");
5563 /* Switch terminal for any messages produced by
5564 breakpoint_re_set. */
5565 target_terminal::ours_for_output ();
5567 gdbarch
= get_frame_arch (get_current_frame ());
5568 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5569 thus it is expected that its objectfile can be found through
5570 minimal symbol lookup. If it doesn't work (and assert fails), it
5571 most likely means that `jit_breakpoint_re_set` was changes and this
5572 function needs to be updated too. */
5573 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5574 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5575 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5577 target_terminal::inferior ();
5580 /* Prepare WHAT final decision for infrun. */
5582 /* Decide what infrun needs to do with this bpstat. */
5585 bpstat_what (bpstat bs_head
)
5587 struct bpstat_what retval
;
5590 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5591 retval
.call_dummy
= STOP_NONE
;
5592 retval
.is_longjmp
= false;
5594 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5596 /* Extract this BS's action. After processing each BS, we check
5597 if its action overrides all we've seem so far. */
5598 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5601 if (bs
->breakpoint_at
== NULL
)
5603 /* I suspect this can happen if it was a momentary
5604 breakpoint which has since been deleted. */
5608 bptype
= bs
->breakpoint_at
->type
;
5615 case bp_hardware_breakpoint
:
5616 case bp_single_step
:
5619 case bp_shlib_event
:
5623 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5625 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5628 this_action
= BPSTAT_WHAT_SINGLE
;
5631 case bp_hardware_watchpoint
:
5632 case bp_read_watchpoint
:
5633 case bp_access_watchpoint
:
5637 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5639 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5643 /* There was a watchpoint, but we're not stopping.
5644 This requires no further action. */
5648 case bp_longjmp_call_dummy
:
5652 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5653 retval
.is_longjmp
= bptype
!= bp_exception
;
5656 this_action
= BPSTAT_WHAT_SINGLE
;
5658 case bp_longjmp_resume
:
5659 case bp_exception_resume
:
5662 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5663 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5666 this_action
= BPSTAT_WHAT_SINGLE
;
5668 case bp_step_resume
:
5670 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5673 /* It is for the wrong frame. */
5674 this_action
= BPSTAT_WHAT_SINGLE
;
5677 case bp_hp_step_resume
:
5679 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5682 /* It is for the wrong frame. */
5683 this_action
= BPSTAT_WHAT_SINGLE
;
5686 case bp_watchpoint_scope
:
5687 case bp_thread_event
:
5688 case bp_overlay_event
:
5689 case bp_longjmp_master
:
5690 case bp_std_terminate_master
:
5691 case bp_exception_master
:
5692 this_action
= BPSTAT_WHAT_SINGLE
;
5698 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5700 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5704 /* Some catchpoints are implemented with breakpoints.
5705 For those, we need to step over the breakpoint. */
5706 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5707 this_action
= BPSTAT_WHAT_SINGLE
;
5711 this_action
= BPSTAT_WHAT_SINGLE
;
5714 /* Make sure the action is stop (silent or noisy),
5715 so infrun.c pops the dummy frame. */
5716 retval
.call_dummy
= STOP_STACK_DUMMY
;
5717 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5719 case bp_std_terminate
:
5720 /* Make sure the action is stop (silent or noisy),
5721 so infrun.c pops the dummy frame. */
5722 retval
.call_dummy
= STOP_STD_TERMINATE
;
5723 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5726 case bp_fast_tracepoint
:
5727 case bp_static_tracepoint
:
5728 /* Tracepoint hits should not be reported back to GDB, and
5729 if one got through somehow, it should have been filtered
5731 internal_error (__FILE__
, __LINE__
,
5732 _("bpstat_what: tracepoint encountered"));
5734 case bp_gnu_ifunc_resolver
:
5735 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5736 this_action
= BPSTAT_WHAT_SINGLE
;
5738 case bp_gnu_ifunc_resolver_return
:
5739 /* The breakpoint will be removed, execution will restart from the
5740 PC of the former breakpoint. */
5741 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5746 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5748 this_action
= BPSTAT_WHAT_SINGLE
;
5752 internal_error (__FILE__
, __LINE__
,
5753 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5756 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5763 bpstat_run_callbacks (bpstat bs_head
)
5767 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5769 struct breakpoint
*b
= bs
->breakpoint_at
;
5776 handle_jit_event (bs
->bp_location_at
->address
);
5778 case bp_gnu_ifunc_resolver
:
5779 gnu_ifunc_resolver_stop (b
);
5781 case bp_gnu_ifunc_resolver_return
:
5782 gnu_ifunc_resolver_return_stop (b
);
5788 /* See breakpoint.h. */
5791 bpstat_should_step ()
5793 for (breakpoint
*b
: all_breakpoints ())
5794 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5800 /* See breakpoint.h. */
5803 bpstat_causes_stop (bpstat bs
)
5805 for (; bs
!= NULL
; bs
= bs
->next
)
5814 /* Compute a string of spaces suitable to indent the next line
5815 so it starts at the position corresponding to the table column
5816 named COL_NAME in the currently active table of UIOUT. */
5819 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5821 static char wrap_indent
[80];
5822 int i
, total_width
, width
, align
;
5826 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5828 if (strcmp (text
, col_name
) == 0)
5830 gdb_assert (total_width
< sizeof wrap_indent
);
5831 memset (wrap_indent
, ' ', total_width
);
5832 wrap_indent
[total_width
] = 0;
5837 total_width
+= width
+ 1;
5843 /* Determine if the locations of this breakpoint will have their conditions
5844 evaluated by the target, host or a mix of both. Returns the following:
5846 "host": Host evals condition.
5847 "host or target": Host or Target evals condition.
5848 "target": Target evals condition.
5852 bp_condition_evaluator (struct breakpoint
*b
)
5854 char host_evals
= 0;
5855 char target_evals
= 0;
5860 if (!is_breakpoint (b
))
5863 if (gdb_evaluates_breakpoint_condition_p ()
5864 || !target_supports_evaluation_of_breakpoint_conditions ())
5865 return condition_evaluation_host
;
5867 for (bp_location
*bl
: b
->locations ())
5869 if (bl
->cond_bytecode
)
5875 if (host_evals
&& target_evals
)
5876 return condition_evaluation_both
;
5877 else if (target_evals
)
5878 return condition_evaluation_target
;
5880 return condition_evaluation_host
;
5883 /* Determine the breakpoint location's condition evaluator. This is
5884 similar to bp_condition_evaluator, but for locations. */
5887 bp_location_condition_evaluator (struct bp_location
*bl
)
5889 if (bl
&& !is_breakpoint (bl
->owner
))
5892 if (gdb_evaluates_breakpoint_condition_p ()
5893 || !target_supports_evaluation_of_breakpoint_conditions ())
5894 return condition_evaluation_host
;
5896 if (bl
&& bl
->cond_bytecode
)
5897 return condition_evaluation_target
;
5899 return condition_evaluation_host
;
5902 /* Print the LOC location out of the list of B->LOC locations. */
5905 print_breakpoint_location (struct breakpoint
*b
,
5906 struct bp_location
*loc
)
5908 struct ui_out
*uiout
= current_uiout
;
5910 scoped_restore_current_program_space restore_pspace
;
5912 if (loc
!= NULL
&& loc
->shlib_disabled
)
5916 set_current_program_space (loc
->pspace
);
5918 if (b
->display_canonical
)
5919 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5920 else if (loc
&& loc
->symtab
)
5922 const struct symbol
*sym
= loc
->symbol
;
5926 uiout
->text ("in ");
5927 uiout
->field_string ("func", sym
->print_name (),
5928 function_name_style
.style ());
5930 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5931 uiout
->text ("at ");
5933 uiout
->field_string ("file",
5934 symtab_to_filename_for_display (loc
->symtab
),
5935 file_name_style
.style ());
5938 if (uiout
->is_mi_like_p ())
5939 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5941 uiout
->field_signed ("line", loc
->line_number
);
5947 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5949 uiout
->field_stream ("at", stb
);
5953 uiout
->field_string ("pending",
5954 event_location_to_string (b
->location
.get ()));
5955 /* If extra_string is available, it could be holding a condition
5956 or dprintf arguments. In either case, make sure it is printed,
5957 too, but only for non-MI streams. */
5958 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5960 if (b
->type
== bp_dprintf
)
5964 uiout
->text (b
->extra_string
);
5968 if (loc
&& is_breakpoint (b
)
5969 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5970 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5973 uiout
->field_string ("evaluated-by",
5974 bp_location_condition_evaluator (loc
));
5980 bptype_string (enum bptype type
)
5982 struct ep_type_description
5985 const char *description
;
5987 static struct ep_type_description bptypes
[] =
5989 {bp_none
, "?deleted?"},
5990 {bp_breakpoint
, "breakpoint"},
5991 {bp_hardware_breakpoint
, "hw breakpoint"},
5992 {bp_single_step
, "sw single-step"},
5993 {bp_until
, "until"},
5994 {bp_finish
, "finish"},
5995 {bp_watchpoint
, "watchpoint"},
5996 {bp_hardware_watchpoint
, "hw watchpoint"},
5997 {bp_read_watchpoint
, "read watchpoint"},
5998 {bp_access_watchpoint
, "acc watchpoint"},
5999 {bp_longjmp
, "longjmp"},
6000 {bp_longjmp_resume
, "longjmp resume"},
6001 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6002 {bp_exception
, "exception"},
6003 {bp_exception_resume
, "exception resume"},
6004 {bp_step_resume
, "step resume"},
6005 {bp_hp_step_resume
, "high-priority step resume"},
6006 {bp_watchpoint_scope
, "watchpoint scope"},
6007 {bp_call_dummy
, "call dummy"},
6008 {bp_std_terminate
, "std::terminate"},
6009 {bp_shlib_event
, "shlib events"},
6010 {bp_thread_event
, "thread events"},
6011 {bp_overlay_event
, "overlay events"},
6012 {bp_longjmp_master
, "longjmp master"},
6013 {bp_std_terminate_master
, "std::terminate master"},
6014 {bp_exception_master
, "exception master"},
6015 {bp_catchpoint
, "catchpoint"},
6016 {bp_tracepoint
, "tracepoint"},
6017 {bp_fast_tracepoint
, "fast tracepoint"},
6018 {bp_static_tracepoint
, "static tracepoint"},
6019 {bp_dprintf
, "dprintf"},
6020 {bp_jit_event
, "jit events"},
6021 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6022 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6025 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6026 || ((int) type
!= bptypes
[(int) type
].type
))
6027 internal_error (__FILE__
, __LINE__
,
6028 _("bptypes table does not describe type #%d."),
6031 return bptypes
[(int) type
].description
;
6034 /* For MI, output a field named 'thread-groups' with a list as the value.
6035 For CLI, prefix the list with the string 'inf'. */
6038 output_thread_groups (struct ui_out
*uiout
,
6039 const char *field_name
,
6040 const std::vector
<int> &inf_nums
,
6043 int is_mi
= uiout
->is_mi_like_p ();
6045 /* For backward compatibility, don't display inferiors in CLI unless
6046 there are several. Always display them for MI. */
6047 if (!is_mi
&& mi_only
)
6050 ui_out_emit_list
list_emitter (uiout
, field_name
);
6052 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6058 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6059 uiout
->field_string (NULL
, mi_group
);
6064 uiout
->text (" inf ");
6068 uiout
->text (plongest (inf_nums
[i
]));
6073 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6074 instead of going via breakpoint_ops::print_one. This makes "maint
6075 info breakpoints" show the software breakpoint locations of
6076 catchpoints, which are considered internal implementation
6080 print_one_breakpoint_location (struct breakpoint
*b
,
6081 struct bp_location
*loc
,
6083 struct bp_location
**last_loc
,
6084 int allflag
, bool raw_loc
)
6086 struct command_line
*l
;
6087 static char bpenables
[] = "nynny";
6089 struct ui_out
*uiout
= current_uiout
;
6090 int header_of_multiple
= 0;
6091 int part_of_multiple
= (loc
!= NULL
);
6092 struct value_print_options opts
;
6094 get_user_print_options (&opts
);
6096 gdb_assert (!loc
|| loc_number
!= 0);
6097 /* See comment in print_one_breakpoint concerning treatment of
6098 breakpoints with single disabled location. */
6101 && (b
->loc
->next
!= NULL
6102 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6103 header_of_multiple
= 1;
6111 if (part_of_multiple
)
6112 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6114 uiout
->field_signed ("number", b
->number
);
6118 if (part_of_multiple
)
6119 uiout
->field_skip ("type");
6121 uiout
->field_string ("type", bptype_string (b
->type
));
6125 if (part_of_multiple
)
6126 uiout
->field_skip ("disp");
6128 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6132 /* For locations that are disabled because of an invalid condition,
6133 display "N*" on CLI, where "*" refers to a footnote below the
6134 table. For MI, simply display a "N" without a footnote. */
6135 const char *N
= (uiout
->is_mi_like_p ()) ? "N" : "N*";
6136 if (part_of_multiple
)
6137 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? N
6138 : (loc
->enabled
? "y" : "n")));
6140 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6143 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6144 b
->ops
->print_one (b
, last_loc
);
6147 if (is_watchpoint (b
))
6149 struct watchpoint
*w
= (struct watchpoint
*) b
;
6151 /* Field 4, the address, is omitted (which makes the columns
6152 not line up too nicely with the headers, but the effect
6153 is relatively readable). */
6154 if (opts
.addressprint
)
6155 uiout
->field_skip ("addr");
6157 uiout
->field_string ("what", w
->exp_string
);
6159 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6160 || is_ada_exception_catchpoint (b
))
6162 if (opts
.addressprint
)
6165 if (header_of_multiple
)
6166 uiout
->field_string ("addr", "<MULTIPLE>",
6167 metadata_style
.style ());
6168 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6169 uiout
->field_string ("addr", "<PENDING>",
6170 metadata_style
.style ());
6172 uiout
->field_core_addr ("addr",
6173 loc
->gdbarch
, loc
->address
);
6176 if (!header_of_multiple
)
6177 print_breakpoint_location (b
, loc
);
6183 if (loc
!= NULL
&& !header_of_multiple
)
6185 std::vector
<int> inf_nums
;
6188 for (inferior
*inf
: all_inferiors ())
6190 if (inf
->pspace
== loc
->pspace
)
6191 inf_nums
.push_back (inf
->num
);
6194 /* For backward compatibility, don't display inferiors in CLI unless
6195 there are several. Always display for MI. */
6197 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6198 && (program_spaces
.size () > 1
6199 || number_of_inferiors () > 1)
6200 /* LOC is for existing B, it cannot be in
6201 moribund_locations and thus having NULL OWNER. */
6202 && loc
->owner
->type
!= bp_catchpoint
))
6204 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6207 if (!part_of_multiple
)
6209 if (b
->thread
!= -1)
6211 /* FIXME: This seems to be redundant and lost here; see the
6212 "stop only in" line a little further down. */
6213 uiout
->text (" thread ");
6214 uiout
->field_signed ("thread", b
->thread
);
6216 else if (b
->task
!= 0)
6218 uiout
->text (" task ");
6219 uiout
->field_signed ("task", b
->task
);
6225 if (!part_of_multiple
)
6226 b
->ops
->print_one_detail (b
, uiout
);
6228 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6231 uiout
->text ("\tstop only in stack frame at ");
6232 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6234 uiout
->field_core_addr ("frame",
6235 b
->gdbarch
, b
->frame_id
.stack_addr
);
6239 if (!part_of_multiple
&& b
->cond_string
)
6242 if (is_tracepoint (b
))
6243 uiout
->text ("\ttrace only if ");
6245 uiout
->text ("\tstop only if ");
6246 uiout
->field_string ("cond", b
->cond_string
);
6248 /* Print whether the target is doing the breakpoint's condition
6249 evaluation. If GDB is doing the evaluation, don't print anything. */
6250 if (is_breakpoint (b
)
6251 && breakpoint_condition_evaluation_mode ()
6252 == condition_evaluation_target
)
6254 uiout
->message (" (%pF evals)",
6255 string_field ("evaluated-by",
6256 bp_condition_evaluator (b
)));
6261 if (!part_of_multiple
&& b
->thread
!= -1)
6263 /* FIXME should make an annotation for this. */
6264 uiout
->text ("\tstop only in thread ");
6265 if (uiout
->is_mi_like_p ())
6266 uiout
->field_signed ("thread", b
->thread
);
6269 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6271 uiout
->field_string ("thread", print_thread_id (thr
));
6276 if (!part_of_multiple
)
6280 /* FIXME should make an annotation for this. */
6281 if (is_catchpoint (b
))
6282 uiout
->text ("\tcatchpoint");
6283 else if (is_tracepoint (b
))
6284 uiout
->text ("\ttracepoint");
6286 uiout
->text ("\tbreakpoint");
6287 uiout
->text (" already hit ");
6288 uiout
->field_signed ("times", b
->hit_count
);
6289 if (b
->hit_count
== 1)
6290 uiout
->text (" time\n");
6292 uiout
->text (" times\n");
6296 /* Output the count also if it is zero, but only if this is mi. */
6297 if (uiout
->is_mi_like_p ())
6298 uiout
->field_signed ("times", b
->hit_count
);
6302 if (!part_of_multiple
&& b
->ignore_count
)
6305 uiout
->message ("\tignore next %pF hits\n",
6306 signed_field ("ignore", b
->ignore_count
));
6309 /* Note that an enable count of 1 corresponds to "enable once"
6310 behavior, which is reported by the combination of enablement and
6311 disposition, so we don't need to mention it here. */
6312 if (!part_of_multiple
&& b
->enable_count
> 1)
6315 uiout
->text ("\tdisable after ");
6316 /* Tweak the wording to clarify that ignore and enable counts
6317 are distinct, and have additive effect. */
6318 if (b
->ignore_count
)
6319 uiout
->text ("additional ");
6321 uiout
->text ("next ");
6322 uiout
->field_signed ("enable", b
->enable_count
);
6323 uiout
->text (" hits\n");
6326 if (!part_of_multiple
&& is_tracepoint (b
))
6328 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6330 if (tp
->traceframe_usage
)
6332 uiout
->text ("\ttrace buffer usage ");
6333 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6334 uiout
->text (" bytes\n");
6338 l
= b
->commands
? b
->commands
.get () : NULL
;
6339 if (!part_of_multiple
&& l
)
6342 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6343 print_command_lines (uiout
, l
, 4);
6346 if (is_tracepoint (b
))
6348 struct tracepoint
*t
= (struct tracepoint
*) b
;
6350 if (!part_of_multiple
&& t
->pass_count
)
6352 annotate_field (10);
6353 uiout
->text ("\tpass count ");
6354 uiout
->field_signed ("pass", t
->pass_count
);
6355 uiout
->text (" \n");
6358 /* Don't display it when tracepoint or tracepoint location is
6360 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6362 annotate_field (11);
6364 if (uiout
->is_mi_like_p ())
6365 uiout
->field_string ("installed",
6366 loc
->inserted
? "y" : "n");
6372 uiout
->text ("\tnot ");
6373 uiout
->text ("installed on target\n");
6378 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6380 if (is_watchpoint (b
))
6382 struct watchpoint
*w
= (struct watchpoint
*) b
;
6384 uiout
->field_string ("original-location", w
->exp_string
);
6386 else if (b
->location
!= NULL
6387 && event_location_to_string (b
->location
.get ()) != NULL
)
6388 uiout
->field_string ("original-location",
6389 event_location_to_string (b
->location
.get ()));
6393 /* See breakpoint.h. */
6395 bool fix_multi_location_breakpoint_output_globally
= false;
6398 print_one_breakpoint (struct breakpoint
*b
,
6399 struct bp_location
**last_loc
,
6402 struct ui_out
*uiout
= current_uiout
;
6403 bool use_fixed_output
6404 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6405 || fix_multi_location_breakpoint_output_globally
);
6407 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6408 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6410 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6412 if (!use_fixed_output
)
6413 bkpt_tuple_emitter
.reset ();
6415 /* If this breakpoint has custom print function,
6416 it's already printed. Otherwise, print individual
6417 locations, if any. */
6419 || b
->ops
->print_one
== NULL
6422 /* If breakpoint has a single location that is disabled, we
6423 print it as if it had several locations, since otherwise it's
6424 hard to represent "breakpoint enabled, location disabled"
6427 Note that while hardware watchpoints have several locations
6428 internally, that's not a property exposed to users.
6430 Likewise, while catchpoints may be implemented with
6431 breakpoints (e.g., catch throw), that's not a property
6432 exposed to users. We do however display the internal
6433 breakpoint locations with "maint info breakpoints". */
6434 if (!is_hardware_watchpoint (b
)
6435 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6436 || is_ada_exception_catchpoint (b
))
6438 || (b
->loc
&& (b
->loc
->next
6440 || b
->loc
->disabled_by_cond
))))
6442 gdb::optional
<ui_out_emit_list
> locations_list
;
6444 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6445 MI record. For later versions, place breakpoint locations in a
6447 if (uiout
->is_mi_like_p () && use_fixed_output
)
6448 locations_list
.emplace (uiout
, "locations");
6451 for (bp_location
*loc
: b
->locations ())
6453 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6454 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6463 breakpoint_address_bits (struct breakpoint
*b
)
6465 int print_address_bits
= 0;
6467 /* Software watchpoints that aren't watching memory don't have an
6468 address to print. */
6469 if (is_no_memory_software_watchpoint (b
))
6472 for (bp_location
*loc
: b
->locations ())
6476 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6477 if (addr_bit
> print_address_bits
)
6478 print_address_bits
= addr_bit
;
6481 return print_address_bits
;
6484 /* See breakpoint.h. */
6487 print_breakpoint (breakpoint
*b
)
6489 struct bp_location
*dummy_loc
= NULL
;
6490 print_one_breakpoint (b
, &dummy_loc
, 0);
6493 /* Return true if this breakpoint was set by the user, false if it is
6494 internal or momentary. */
6497 user_breakpoint_p (struct breakpoint
*b
)
6499 return b
->number
> 0;
6502 /* See breakpoint.h. */
6505 pending_breakpoint_p (struct breakpoint
*b
)
6507 return b
->loc
== NULL
;
6510 /* Print information on breakpoints (including watchpoints and tracepoints).
6512 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6513 understood by number_or_range_parser. Only breakpoints included in this
6514 list are then printed.
6516 If SHOW_INTERNAL is true, print internal breakpoints.
6518 If FILTER is non-NULL, call it on each breakpoint and only include the
6519 ones for which it returns true.
6521 Return the total number of breakpoints listed. */
6524 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6525 bool (*filter
) (const struct breakpoint
*))
6527 struct bp_location
*last_loc
= NULL
;
6528 int nr_printable_breakpoints
;
6529 struct value_print_options opts
;
6530 int print_address_bits
= 0;
6531 int print_type_col_width
= 14;
6532 struct ui_out
*uiout
= current_uiout
;
6533 bool has_disabled_by_cond_location
= false;
6535 get_user_print_options (&opts
);
6537 /* Compute the number of rows in the table, as well as the size
6538 required for address fields. */
6539 nr_printable_breakpoints
= 0;
6540 for (breakpoint
*b
: all_breakpoints ())
6542 /* If we have a filter, only list the breakpoints it accepts. */
6543 if (filter
&& !filter (b
))
6546 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6547 accept. Skip the others. */
6548 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6550 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6552 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6556 if (show_internal
|| user_breakpoint_p (b
))
6558 int addr_bit
, type_len
;
6560 addr_bit
= breakpoint_address_bits (b
);
6561 if (addr_bit
> print_address_bits
)
6562 print_address_bits
= addr_bit
;
6564 type_len
= strlen (bptype_string (b
->type
));
6565 if (type_len
> print_type_col_width
)
6566 print_type_col_width
= type_len
;
6568 nr_printable_breakpoints
++;
6573 ui_out_emit_table
table_emitter (uiout
,
6574 opts
.addressprint
? 6 : 5,
6575 nr_printable_breakpoints
,
6578 if (nr_printable_breakpoints
> 0)
6579 annotate_breakpoints_headers ();
6580 if (nr_printable_breakpoints
> 0)
6582 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6583 if (nr_printable_breakpoints
> 0)
6585 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6586 if (nr_printable_breakpoints
> 0)
6588 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6589 if (nr_printable_breakpoints
> 0)
6591 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6592 if (opts
.addressprint
)
6594 if (nr_printable_breakpoints
> 0)
6596 if (print_address_bits
<= 32)
6597 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6599 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6601 if (nr_printable_breakpoints
> 0)
6603 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6604 uiout
->table_body ();
6605 if (nr_printable_breakpoints
> 0)
6606 annotate_breakpoints_table ();
6608 for (breakpoint
*b
: all_breakpoints ())
6611 /* If we have a filter, only list the breakpoints it accepts. */
6612 if (filter
&& !filter (b
))
6615 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6616 accept. Skip the others. */
6618 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6620 if (show_internal
) /* maintenance info breakpoint */
6622 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6625 else /* all others */
6627 if (!number_is_in_list (bp_num_list
, b
->number
))
6631 /* We only print out user settable breakpoints unless the
6632 show_internal is set. */
6633 if (show_internal
|| user_breakpoint_p (b
))
6635 print_one_breakpoint (b
, &last_loc
, show_internal
);
6636 for (bp_location
*loc
: b
->locations ())
6637 if (loc
->disabled_by_cond
)
6638 has_disabled_by_cond_location
= true;
6643 if (nr_printable_breakpoints
== 0)
6645 /* If there's a filter, let the caller decide how to report
6649 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6650 uiout
->message ("No breakpoints or watchpoints.\n");
6652 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6658 if (last_loc
&& !server_command
)
6659 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6661 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6662 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6666 /* FIXME? Should this be moved up so that it is only called when
6667 there have been breakpoints? */
6668 annotate_breakpoints_table_end ();
6670 return nr_printable_breakpoints
;
6673 /* Display the value of default-collect in a way that is generally
6674 compatible with the breakpoint list. */
6677 default_collect_info (void)
6679 struct ui_out
*uiout
= current_uiout
;
6681 /* If it has no value (which is frequently the case), say nothing; a
6682 message like "No default-collect." gets in user's face when it's
6684 if (!*default_collect
)
6687 /* The following phrase lines up nicely with per-tracepoint collect
6689 uiout
->text ("default collect ");
6690 uiout
->field_string ("default-collect", default_collect
);
6691 uiout
->text (" \n");
6695 info_breakpoints_command (const char *args
, int from_tty
)
6697 breakpoint_1 (args
, false, NULL
);
6699 default_collect_info ();
6703 info_watchpoints_command (const char *args
, int from_tty
)
6705 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6706 struct ui_out
*uiout
= current_uiout
;
6708 if (num_printed
== 0)
6710 if (args
== NULL
|| *args
== '\0')
6711 uiout
->message ("No watchpoints.\n");
6713 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6718 maintenance_info_breakpoints (const char *args
, int from_tty
)
6720 breakpoint_1 (args
, true, NULL
);
6722 default_collect_info ();
6726 breakpoint_has_pc (struct breakpoint
*b
,
6727 struct program_space
*pspace
,
6728 CORE_ADDR pc
, struct obj_section
*section
)
6730 for (bp_location
*bl
: b
->locations ())
6732 if (bl
->pspace
== pspace
6733 && bl
->address
== pc
6734 && (!overlay_debugging
|| bl
->section
== section
))
6740 /* Print a message describing any user-breakpoints set at PC. This
6741 concerns with logical breakpoints, so we match program spaces, not
6745 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6746 struct program_space
*pspace
, CORE_ADDR pc
,
6747 struct obj_section
*section
, int thread
)
6751 for (breakpoint
*b
: all_breakpoints ())
6752 others
+= (user_breakpoint_p (b
)
6753 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6758 printf_filtered (_("Note: breakpoint "));
6759 else /* if (others == ???) */
6760 printf_filtered (_("Note: breakpoints "));
6761 for (breakpoint
*b
: all_breakpoints ())
6762 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6765 printf_filtered ("%d", b
->number
);
6766 if (b
->thread
== -1 && thread
!= -1)
6767 printf_filtered (" (all threads)");
6768 else if (b
->thread
!= -1)
6769 printf_filtered (" (thread %d)", b
->thread
);
6770 printf_filtered ("%s%s ",
6771 ((b
->enable_state
== bp_disabled
6772 || b
->enable_state
== bp_call_disabled
)
6776 : ((others
== 1) ? " and" : ""));
6778 current_uiout
->message (_("also set at pc %ps.\n"),
6779 styled_string (address_style
.style (),
6780 paddress (gdbarch
, pc
)));
6785 /* Return true iff it is meaningful to use the address member of LOC.
6786 For some breakpoint types, the locations' address members are
6787 irrelevant and it makes no sense to attempt to compare them to
6788 other addresses (or use them for any other purpose either).
6790 More specifically, software watchpoints and catchpoints that are
6791 not backed by breakpoints always have a zero valued location
6792 address and we don't want to mark breakpoints of any of these types
6793 to be a duplicate of an actual breakpoint location at address
6797 bl_address_is_meaningful (bp_location
*loc
)
6799 return loc
->loc_type
!= bp_loc_other
;
6802 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6803 true if LOC1 and LOC2 represent the same watchpoint location. */
6806 watchpoint_locations_match (struct bp_location
*loc1
,
6807 struct bp_location
*loc2
)
6809 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6810 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6812 /* Both of them must exist. */
6813 gdb_assert (w1
!= NULL
);
6814 gdb_assert (w2
!= NULL
);
6816 /* If the target can evaluate the condition expression in hardware,
6817 then we we need to insert both watchpoints even if they are at
6818 the same place. Otherwise the watchpoint will only trigger when
6819 the condition of whichever watchpoint was inserted evaluates to
6820 true, not giving a chance for GDB to check the condition of the
6821 other watchpoint. */
6823 && target_can_accel_watchpoint_condition (loc1
->address
,
6825 loc1
->watchpoint_type
,
6826 w1
->cond_exp
.get ()))
6828 && target_can_accel_watchpoint_condition (loc2
->address
,
6830 loc2
->watchpoint_type
,
6831 w2
->cond_exp
.get ())))
6834 /* Note that this checks the owner's type, not the location's. In
6835 case the target does not support read watchpoints, but does
6836 support access watchpoints, we'll have bp_read_watchpoint
6837 watchpoints with hw_access locations. Those should be considered
6838 duplicates of hw_read locations. The hw_read locations will
6839 become hw_access locations later. */
6840 return (loc1
->owner
->type
== loc2
->owner
->type
6841 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6842 && loc1
->address
== loc2
->address
6843 && loc1
->length
== loc2
->length
);
6846 /* See breakpoint.h. */
6849 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6850 const address_space
*aspace2
, CORE_ADDR addr2
)
6852 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6853 || aspace1
== aspace2
)
6857 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6858 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6859 matches ASPACE2. On targets that have global breakpoints, the address
6860 space doesn't really matter. */
6863 breakpoint_address_match_range (const address_space
*aspace1
,
6865 int len1
, const address_space
*aspace2
,
6868 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6869 || aspace1
== aspace2
)
6870 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6873 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6874 a ranged breakpoint. In most targets, a match happens only if ASPACE
6875 matches the breakpoint's address space. On targets that have global
6876 breakpoints, the address space doesn't really matter. */
6879 breakpoint_location_address_match (struct bp_location
*bl
,
6880 const address_space
*aspace
,
6883 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6886 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6887 bl
->address
, bl
->length
,
6891 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6892 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6893 match happens only if ASPACE matches the breakpoint's address
6894 space. On targets that have global breakpoints, the address space
6895 doesn't really matter. */
6898 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6899 const address_space
*aspace
,
6900 CORE_ADDR addr
, int len
)
6902 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6903 || bl
->pspace
->aspace
== aspace
)
6905 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6907 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6913 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6914 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6915 true, otherwise returns false. */
6918 tracepoint_locations_match (struct bp_location
*loc1
,
6919 struct bp_location
*loc2
)
6921 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6922 /* Since tracepoint locations are never duplicated with others', tracepoint
6923 locations at the same address of different tracepoints are regarded as
6924 different locations. */
6925 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6930 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6931 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6932 the same location. If SW_HW_BPS_MATCH is true, then software
6933 breakpoint locations and hardware breakpoint locations match,
6934 otherwise they don't. */
6937 breakpoint_locations_match (struct bp_location
*loc1
,
6938 struct bp_location
*loc2
,
6939 bool sw_hw_bps_match
)
6941 int hw_point1
, hw_point2
;
6943 /* Both of them must not be in moribund_locations. */
6944 gdb_assert (loc1
->owner
!= NULL
);
6945 gdb_assert (loc2
->owner
!= NULL
);
6947 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6948 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6950 if (hw_point1
!= hw_point2
)
6953 return watchpoint_locations_match (loc1
, loc2
);
6954 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6955 return tracepoint_locations_match (loc1
, loc2
);
6957 /* We compare bp_location.length in order to cover ranged
6958 breakpoints. Keep this in sync with
6959 bp_location_is_less_than. */
6960 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6961 loc2
->pspace
->aspace
, loc2
->address
)
6962 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
6963 && loc1
->length
== loc2
->length
);
6967 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6968 int bnum
, int have_bnum
)
6970 /* The longest string possibly returned by hex_string_custom
6971 is 50 chars. These must be at least that big for safety. */
6975 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6976 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6978 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6979 bnum
, astr1
, astr2
);
6981 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6984 /* Adjust a breakpoint's address to account for architectural
6985 constraints on breakpoint placement. Return the adjusted address.
6986 Note: Very few targets require this kind of adjustment. For most
6987 targets, this function is simply the identity function. */
6990 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6991 CORE_ADDR bpaddr
, enum bptype bptype
)
6993 if (bptype
== bp_watchpoint
6994 || bptype
== bp_hardware_watchpoint
6995 || bptype
== bp_read_watchpoint
6996 || bptype
== bp_access_watchpoint
6997 || bptype
== bp_catchpoint
)
6999 /* Watchpoints and the various bp_catch_* eventpoints should not
7000 have their addresses modified. */
7003 else if (bptype
== bp_single_step
)
7005 /* Single-step breakpoints should not have their addresses
7006 modified. If there's any architectural constrain that
7007 applies to this address, then it should have already been
7008 taken into account when the breakpoint was created in the
7009 first place. If we didn't do this, stepping through e.g.,
7010 Thumb-2 IT blocks would break. */
7015 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7017 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7019 /* Some targets have architectural constraints on the placement
7020 of breakpoint instructions. Obtain the adjusted address. */
7021 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7024 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7026 /* An adjusted breakpoint address can significantly alter
7027 a user's expectations. Print a warning if an adjustment
7029 if (adjusted_bpaddr
!= bpaddr
)
7030 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7032 return adjusted_bpaddr
;
7037 bp_location_from_bp_type (bptype type
)
7042 case bp_single_step
:
7046 case bp_longjmp_resume
:
7047 case bp_longjmp_call_dummy
:
7049 case bp_exception_resume
:
7050 case bp_step_resume
:
7051 case bp_hp_step_resume
:
7052 case bp_watchpoint_scope
:
7054 case bp_std_terminate
:
7055 case bp_shlib_event
:
7056 case bp_thread_event
:
7057 case bp_overlay_event
:
7059 case bp_longjmp_master
:
7060 case bp_std_terminate_master
:
7061 case bp_exception_master
:
7062 case bp_gnu_ifunc_resolver
:
7063 case bp_gnu_ifunc_resolver_return
:
7065 return bp_loc_software_breakpoint
;
7066 case bp_hardware_breakpoint
:
7067 return bp_loc_hardware_breakpoint
;
7068 case bp_hardware_watchpoint
:
7069 case bp_read_watchpoint
:
7070 case bp_access_watchpoint
:
7071 return bp_loc_hardware_watchpoint
;
7075 case bp_fast_tracepoint
:
7076 case bp_static_tracepoint
:
7077 return bp_loc_other
;
7079 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7083 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7085 this->owner
= owner
;
7086 this->cond_bytecode
= NULL
;
7087 this->shlib_disabled
= 0;
7089 this->disabled_by_cond
= false;
7091 this->loc_type
= type
;
7093 if (this->loc_type
== bp_loc_software_breakpoint
7094 || this->loc_type
== bp_loc_hardware_breakpoint
)
7095 mark_breakpoint_location_modified (this);
7100 bp_location::bp_location (breakpoint
*owner
)
7101 : bp_location::bp_location (owner
,
7102 bp_location_from_bp_type (owner
->type
))
7106 /* Allocate a struct bp_location. */
7108 static struct bp_location
*
7109 allocate_bp_location (struct breakpoint
*bpt
)
7111 return bpt
->ops
->allocate_location (bpt
);
7114 /* Decrement reference count. If the reference count reaches 0,
7115 destroy the bp_location. Sets *BLP to NULL. */
7118 decref_bp_location (struct bp_location
**blp
)
7120 bp_location_ref_policy::decref (*blp
);
7124 /* Add breakpoint B at the end of the global breakpoint chain. */
7127 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7129 struct breakpoint
*b1
;
7130 struct breakpoint
*result
= b
.get ();
7132 /* Add this breakpoint to the end of the chain so that a list of
7133 breakpoints will come out in order of increasing numbers. */
7135 b1
= breakpoint_chain
;
7137 breakpoint_chain
= b
.release ();
7142 b1
->next
= b
.release ();
7148 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7151 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7152 struct gdbarch
*gdbarch
,
7154 const struct breakpoint_ops
*ops
)
7156 gdb_assert (ops
!= NULL
);
7160 b
->gdbarch
= gdbarch
;
7161 b
->language
= current_language
->la_language
;
7162 b
->input_radix
= input_radix
;
7163 b
->related_breakpoint
= b
;
7166 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7167 that has type BPTYPE and has no locations as yet. */
7169 static struct breakpoint
*
7170 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7172 const struct breakpoint_ops
*ops
)
7174 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7176 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7177 return add_to_breakpoint_chain (std::move (b
));
7180 /* Initialize loc->function_name. */
7183 set_breakpoint_location_function (struct bp_location
*loc
)
7185 gdb_assert (loc
->owner
!= NULL
);
7187 if (loc
->owner
->type
== bp_breakpoint
7188 || loc
->owner
->type
== bp_hardware_breakpoint
7189 || is_tracepoint (loc
->owner
))
7191 const char *function_name
;
7193 if (loc
->msymbol
!= NULL
7194 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7195 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7197 struct breakpoint
*b
= loc
->owner
;
7199 function_name
= loc
->msymbol
->linkage_name ();
7201 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7202 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7204 /* Create only the whole new breakpoint of this type but do not
7205 mess more complicated breakpoints with multiple locations. */
7206 b
->type
= bp_gnu_ifunc_resolver
;
7207 /* Remember the resolver's address for use by the return
7209 loc
->related_address
= loc
->address
;
7213 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7216 loc
->function_name
= xstrdup (function_name
);
7220 /* Attempt to determine architecture of location identified by SAL. */
7222 get_sal_arch (struct symtab_and_line sal
)
7225 return sal
.section
->objfile
->arch ();
7227 return SYMTAB_OBJFILE (sal
.symtab
)->arch ();
7232 /* Low level routine for partially initializing a breakpoint of type
7233 BPTYPE. The newly created breakpoint's address, section, source
7234 file name, and line number are provided by SAL.
7236 It is expected that the caller will complete the initialization of
7237 the newly created breakpoint struct as well as output any status
7238 information regarding the creation of a new breakpoint. */
7241 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7242 struct symtab_and_line sal
, enum bptype bptype
,
7243 const struct breakpoint_ops
*ops
)
7245 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7247 add_location_to_breakpoint (b
, &sal
);
7249 if (bptype
!= bp_catchpoint
)
7250 gdb_assert (sal
.pspace
!= NULL
);
7252 /* Store the program space that was used to set the breakpoint,
7253 except for ordinary breakpoints, which are independent of the
7255 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7256 b
->pspace
= sal
.pspace
;
7259 /* set_raw_breakpoint is a low level routine for allocating and
7260 partially initializing a breakpoint of type BPTYPE. The newly
7261 created breakpoint's address, section, source file name, and line
7262 number are provided by SAL. The newly created and partially
7263 initialized breakpoint is added to the breakpoint chain and
7264 is also returned as the value of this function.
7266 It is expected that the caller will complete the initialization of
7267 the newly created breakpoint struct as well as output any status
7268 information regarding the creation of a new breakpoint. In
7269 particular, set_raw_breakpoint does NOT set the breakpoint
7270 number! Care should be taken to not allow an error to occur
7271 prior to completing the initialization of the breakpoint. If this
7272 should happen, a bogus breakpoint will be left on the chain. */
7275 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7276 struct symtab_and_line sal
, enum bptype bptype
,
7277 const struct breakpoint_ops
*ops
)
7279 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7281 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7282 return add_to_breakpoint_chain (std::move (b
));
7285 /* Call this routine when stepping and nexting to enable a breakpoint
7286 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7287 initiated the operation. */
7290 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7292 int thread
= tp
->global_num
;
7294 /* To avoid having to rescan all objfile symbols at every step,
7295 we maintain a list of continually-inserted but always disabled
7296 longjmp "master" breakpoints. Here, we simply create momentary
7297 clones of those and enable them for the requested thread. */
7298 for (breakpoint
*b
: all_breakpoints_safe ())
7299 if (b
->pspace
== current_program_space
7300 && (b
->type
== bp_longjmp_master
7301 || b
->type
== bp_exception_master
))
7303 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7304 struct breakpoint
*clone
;
7306 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7307 after their removal. */
7308 clone
= momentary_breakpoint_from_master (b
, type
,
7309 &momentary_breakpoint_ops
, 1);
7310 clone
->thread
= thread
;
7313 tp
->initiating_frame
= frame
;
7316 /* Delete all longjmp breakpoints from THREAD. */
7318 delete_longjmp_breakpoint (int thread
)
7320 for (breakpoint
*b
: all_breakpoints_safe ())
7321 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7323 if (b
->thread
== thread
)
7324 delete_breakpoint (b
);
7329 delete_longjmp_breakpoint_at_next_stop (int thread
)
7331 for (breakpoint
*b
: all_breakpoints_safe ())
7332 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7334 if (b
->thread
== thread
)
7335 b
->disposition
= disp_del_at_next_stop
;
7339 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7340 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7341 pointer to any of them. Return NULL if this system cannot place longjmp
7345 set_longjmp_breakpoint_for_call_dummy (void)
7347 breakpoint
*retval
= nullptr;
7349 for (breakpoint
*b
: all_breakpoints ())
7350 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7352 struct breakpoint
*new_b
;
7354 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7355 &momentary_breakpoint_ops
,
7357 new_b
->thread
= inferior_thread ()->global_num
;
7359 /* Link NEW_B into the chain of RETVAL breakpoints. */
7361 gdb_assert (new_b
->related_breakpoint
== new_b
);
7364 new_b
->related_breakpoint
= retval
;
7365 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7366 retval
= retval
->related_breakpoint
;
7367 retval
->related_breakpoint
= new_b
;
7373 /* Verify all existing dummy frames and their associated breakpoints for
7374 TP. Remove those which can no longer be found in the current frame
7377 You should call this function only at places where it is safe to currently
7378 unwind the whole stack. Failed stack unwind would discard live dummy
7382 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7384 struct breakpoint
*b
, *b_tmp
;
7386 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7387 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7389 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7391 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7392 dummy_b
= dummy_b
->related_breakpoint
;
7393 if (dummy_b
->type
!= bp_call_dummy
7394 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7397 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7399 while (b
->related_breakpoint
!= b
)
7401 if (b_tmp
== b
->related_breakpoint
)
7402 b_tmp
= b
->related_breakpoint
->next
;
7403 delete_breakpoint (b
->related_breakpoint
);
7405 delete_breakpoint (b
);
7410 enable_overlay_breakpoints (void)
7412 for (breakpoint
*b
: all_breakpoints ())
7413 if (b
->type
== bp_overlay_event
)
7415 b
->enable_state
= bp_enabled
;
7416 update_global_location_list (UGLL_MAY_INSERT
);
7417 overlay_events_enabled
= 1;
7422 disable_overlay_breakpoints (void)
7424 for (breakpoint
*b
: all_breakpoints ())
7425 if (b
->type
== bp_overlay_event
)
7427 b
->enable_state
= bp_disabled
;
7428 update_global_location_list (UGLL_DONT_INSERT
);
7429 overlay_events_enabled
= 0;
7433 /* Set an active std::terminate breakpoint for each std::terminate
7434 master breakpoint. */
7436 set_std_terminate_breakpoint (void)
7438 for (breakpoint
*b
: all_breakpoints_safe ())
7439 if (b
->pspace
== current_program_space
7440 && b
->type
== bp_std_terminate_master
)
7442 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7443 &momentary_breakpoint_ops
, 1);
7447 /* Delete all the std::terminate breakpoints. */
7449 delete_std_terminate_breakpoint (void)
7451 for (breakpoint
*b
: all_breakpoints_safe ())
7452 if (b
->type
== bp_std_terminate
)
7453 delete_breakpoint (b
);
7457 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7459 struct breakpoint
*b
;
7461 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7462 &internal_breakpoint_ops
);
7464 b
->enable_state
= bp_enabled
;
7465 /* location has to be used or breakpoint_re_set will delete me. */
7466 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7468 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7473 struct lang_and_radix
7479 /* Create a breakpoint for JIT code registration and unregistration. */
7482 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7484 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7485 &internal_breakpoint_ops
);
7488 /* Remove JIT code registration and unregistration breakpoint(s). */
7491 remove_jit_event_breakpoints (void)
7493 for (breakpoint
*b
: all_breakpoints_safe ())
7494 if (b
->type
== bp_jit_event
7495 && b
->loc
->pspace
== current_program_space
)
7496 delete_breakpoint (b
);
7500 remove_solib_event_breakpoints (void)
7502 for (breakpoint
*b
: all_breakpoints_safe ())
7503 if (b
->type
== bp_shlib_event
7504 && b
->loc
->pspace
== current_program_space
)
7505 delete_breakpoint (b
);
7508 /* See breakpoint.h. */
7511 remove_solib_event_breakpoints_at_next_stop (void)
7513 for (breakpoint
*b
: all_breakpoints_safe ())
7514 if (b
->type
== bp_shlib_event
7515 && b
->loc
->pspace
== current_program_space
)
7516 b
->disposition
= disp_del_at_next_stop
;
7519 /* Helper for create_solib_event_breakpoint /
7520 create_and_insert_solib_event_breakpoint. Allows specifying which
7521 INSERT_MODE to pass through to update_global_location_list. */
7523 static struct breakpoint
*
7524 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7525 enum ugll_insert_mode insert_mode
)
7527 struct breakpoint
*b
;
7529 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7530 &internal_breakpoint_ops
);
7531 update_global_location_list_nothrow (insert_mode
);
7536 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7538 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7541 /* See breakpoint.h. */
7544 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7546 struct breakpoint
*b
;
7548 /* Explicitly tell update_global_location_list to insert
7550 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7551 if (!b
->loc
->inserted
)
7553 delete_breakpoint (b
);
7559 /* Disable any breakpoints that are on code in shared libraries. Only
7560 apply to enabled breakpoints, disabled ones can just stay disabled. */
7563 disable_breakpoints_in_shlibs (void)
7565 for (bp_location
*loc
: all_bp_locations ())
7567 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7568 struct breakpoint
*b
= loc
->owner
;
7570 /* We apply the check to all breakpoints, including disabled for
7571 those with loc->duplicate set. This is so that when breakpoint
7572 becomes enabled, or the duplicate is removed, gdb will try to
7573 insert all breakpoints. If we don't set shlib_disabled here,
7574 we'll try to insert those breakpoints and fail. */
7575 if (((b
->type
== bp_breakpoint
)
7576 || (b
->type
== bp_jit_event
)
7577 || (b
->type
== bp_hardware_breakpoint
)
7578 || (is_tracepoint (b
)))
7579 && loc
->pspace
== current_program_space
7580 && !loc
->shlib_disabled
7581 && solib_name_from_address (loc
->pspace
, loc
->address
)
7584 loc
->shlib_disabled
= 1;
7589 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7590 notification of unloaded_shlib. Only apply to enabled breakpoints,
7591 disabled ones can just stay disabled. */
7594 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7596 int disabled_shlib_breaks
= 0;
7598 for (bp_location
*loc
: all_bp_locations ())
7600 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7601 struct breakpoint
*b
= loc
->owner
;
7603 if (solib
->pspace
== loc
->pspace
7604 && !loc
->shlib_disabled
7605 && (((b
->type
== bp_breakpoint
7606 || b
->type
== bp_jit_event
7607 || b
->type
== bp_hardware_breakpoint
)
7608 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7609 || loc
->loc_type
== bp_loc_software_breakpoint
))
7610 || is_tracepoint (b
))
7611 && solib_contains_address_p (solib
, loc
->address
))
7613 loc
->shlib_disabled
= 1;
7614 /* At this point, we cannot rely on remove_breakpoint
7615 succeeding so we must mark the breakpoint as not inserted
7616 to prevent future errors occurring in remove_breakpoints. */
7619 /* This may cause duplicate notifications for the same breakpoint. */
7620 gdb::observers::breakpoint_modified
.notify (b
);
7622 if (!disabled_shlib_breaks
)
7624 target_terminal::ours_for_output ();
7625 warning (_("Temporarily disabling breakpoints "
7626 "for unloaded shared library \"%s\""),
7629 disabled_shlib_breaks
= 1;
7634 /* Disable any breakpoints and tracepoints in OBJFILE upon
7635 notification of free_objfile. Only apply to enabled breakpoints,
7636 disabled ones can just stay disabled. */
7639 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7641 if (objfile
== NULL
)
7644 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7645 managed by the user with add-symbol-file/remove-symbol-file.
7646 Similarly to how breakpoints in shared libraries are handled in
7647 response to "nosharedlibrary", mark breakpoints in such modules
7648 shlib_disabled so they end up uninserted on the next global
7649 location list update. Shared libraries not loaded by the user
7650 aren't handled here -- they're already handled in
7651 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7652 solib_unloaded observer. We skip objfiles that are not
7653 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7655 if ((objfile
->flags
& OBJF_SHARED
) == 0
7656 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7659 for (breakpoint
*b
: all_breakpoints ())
7661 int bp_modified
= 0;
7663 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7666 for (bp_location
*loc
: b
->locations ())
7668 CORE_ADDR loc_addr
= loc
->address
;
7670 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7671 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7674 if (loc
->shlib_disabled
!= 0)
7677 if (objfile
->pspace
!= loc
->pspace
)
7680 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7681 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7684 if (is_addr_in_objfile (loc_addr
, objfile
))
7686 loc
->shlib_disabled
= 1;
7687 /* At this point, we don't know whether the object was
7688 unmapped from the inferior or not, so leave the
7689 inserted flag alone. We'll handle failure to
7690 uninsert quietly, in case the object was indeed
7693 mark_breakpoint_location_modified (loc
);
7700 gdb::observers::breakpoint_modified
.notify (b
);
7704 /* FORK & VFORK catchpoints. */
7706 /* An instance of this type is used to represent a fork or vfork
7707 catchpoint. A breakpoint is really of this type iff its ops pointer points
7708 to CATCH_FORK_BREAKPOINT_OPS. */
7710 struct fork_catchpoint
: public breakpoint
7712 /* Process id of a child process whose forking triggered this
7713 catchpoint. This field is only valid immediately after this
7714 catchpoint has triggered. */
7715 ptid_t forked_inferior_pid
;
7718 /* Implement the "insert" breakpoint_ops method for fork
7722 insert_catch_fork (struct bp_location
*bl
)
7724 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7727 /* Implement the "remove" breakpoint_ops method for fork
7731 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7733 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7736 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7740 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7741 const address_space
*aspace
, CORE_ADDR bp_addr
,
7742 const struct target_waitstatus
*ws
)
7744 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7746 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7749 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7753 /* Implement the "print_it" breakpoint_ops method for fork
7756 static enum print_stop_action
7757 print_it_catch_fork (bpstat bs
)
7759 struct ui_out
*uiout
= current_uiout
;
7760 struct breakpoint
*b
= bs
->breakpoint_at
;
7761 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7763 annotate_catchpoint (b
->number
);
7764 maybe_print_thread_hit_breakpoint (uiout
);
7765 if (b
->disposition
== disp_del
)
7766 uiout
->text ("Temporary catchpoint ");
7768 uiout
->text ("Catchpoint ");
7769 if (uiout
->is_mi_like_p ())
7771 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7772 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7774 uiout
->field_signed ("bkptno", b
->number
);
7775 uiout
->text (" (forked process ");
7776 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7777 uiout
->text ("), ");
7778 return PRINT_SRC_AND_LOC
;
7781 /* Implement the "print_one" breakpoint_ops method for fork
7785 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7787 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7788 struct value_print_options opts
;
7789 struct ui_out
*uiout
= current_uiout
;
7791 get_user_print_options (&opts
);
7793 /* Field 4, the address, is omitted (which makes the columns not
7794 line up too nicely with the headers, but the effect is relatively
7796 if (opts
.addressprint
)
7797 uiout
->field_skip ("addr");
7799 uiout
->text ("fork");
7800 if (c
->forked_inferior_pid
!= null_ptid
)
7802 uiout
->text (", process ");
7803 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7807 if (uiout
->is_mi_like_p ())
7808 uiout
->field_string ("catch-type", "fork");
7811 /* Implement the "print_mention" breakpoint_ops method for fork
7815 print_mention_catch_fork (struct breakpoint
*b
)
7817 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7820 /* Implement the "print_recreate" breakpoint_ops method for fork
7824 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7826 fprintf_unfiltered (fp
, "catch fork");
7827 print_recreate_thread (b
, fp
);
7830 /* The breakpoint_ops structure to be used in fork catchpoints. */
7832 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7834 /* Implement the "insert" breakpoint_ops method for vfork
7838 insert_catch_vfork (struct bp_location
*bl
)
7840 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7843 /* Implement the "remove" breakpoint_ops method for vfork
7847 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7849 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7852 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7856 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7857 const address_space
*aspace
, CORE_ADDR bp_addr
,
7858 const struct target_waitstatus
*ws
)
7860 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7862 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7865 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7869 /* Implement the "print_it" breakpoint_ops method for vfork
7872 static enum print_stop_action
7873 print_it_catch_vfork (bpstat bs
)
7875 struct ui_out
*uiout
= current_uiout
;
7876 struct breakpoint
*b
= bs
->breakpoint_at
;
7877 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7879 annotate_catchpoint (b
->number
);
7880 maybe_print_thread_hit_breakpoint (uiout
);
7881 if (b
->disposition
== disp_del
)
7882 uiout
->text ("Temporary catchpoint ");
7884 uiout
->text ("Catchpoint ");
7885 if (uiout
->is_mi_like_p ())
7887 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7888 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7890 uiout
->field_signed ("bkptno", b
->number
);
7891 uiout
->text (" (vforked process ");
7892 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7893 uiout
->text ("), ");
7894 return PRINT_SRC_AND_LOC
;
7897 /* Implement the "print_one" breakpoint_ops method for vfork
7901 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7903 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7904 struct value_print_options opts
;
7905 struct ui_out
*uiout
= current_uiout
;
7907 get_user_print_options (&opts
);
7908 /* Field 4, the address, is omitted (which makes the columns not
7909 line up too nicely with the headers, but the effect is relatively
7911 if (opts
.addressprint
)
7912 uiout
->field_skip ("addr");
7914 uiout
->text ("vfork");
7915 if (c
->forked_inferior_pid
!= null_ptid
)
7917 uiout
->text (", process ");
7918 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7922 if (uiout
->is_mi_like_p ())
7923 uiout
->field_string ("catch-type", "vfork");
7926 /* Implement the "print_mention" breakpoint_ops method for vfork
7930 print_mention_catch_vfork (struct breakpoint
*b
)
7932 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7935 /* Implement the "print_recreate" breakpoint_ops method for vfork
7939 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7941 fprintf_unfiltered (fp
, "catch vfork");
7942 print_recreate_thread (b
, fp
);
7945 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7947 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7949 /* An instance of this type is used to represent an solib catchpoint.
7950 A breakpoint is really of this type iff its ops pointer points to
7951 CATCH_SOLIB_BREAKPOINT_OPS. */
7953 struct solib_catchpoint
: public breakpoint
7955 ~solib_catchpoint () override
;
7957 /* True for "catch load", false for "catch unload". */
7960 /* Regular expression to match, if any. COMPILED is only valid when
7961 REGEX is non-NULL. */
7963 std::unique_ptr
<compiled_regex
> compiled
;
7966 solib_catchpoint::~solib_catchpoint ()
7968 xfree (this->regex
);
7972 insert_catch_solib (struct bp_location
*ignore
)
7978 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
7984 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7985 const address_space
*aspace
,
7987 const struct target_waitstatus
*ws
)
7989 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7991 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7994 for (breakpoint
*other
: all_breakpoints ())
7996 if (other
== bl
->owner
)
7999 if (other
->type
!= bp_shlib_event
)
8002 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8005 for (bp_location
*other_bl
: other
->locations ())
8007 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8016 check_status_catch_solib (struct bpstats
*bs
)
8018 struct solib_catchpoint
*self
8019 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8023 for (so_list
*iter
: current_program_space
->added_solibs
)
8026 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8032 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
8035 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
8041 bs
->print_it
= print_it_noop
;
8044 static enum print_stop_action
8045 print_it_catch_solib (bpstat bs
)
8047 struct breakpoint
*b
= bs
->breakpoint_at
;
8048 struct ui_out
*uiout
= current_uiout
;
8050 annotate_catchpoint (b
->number
);
8051 maybe_print_thread_hit_breakpoint (uiout
);
8052 if (b
->disposition
== disp_del
)
8053 uiout
->text ("Temporary catchpoint ");
8055 uiout
->text ("Catchpoint ");
8056 uiout
->field_signed ("bkptno", b
->number
);
8058 if (uiout
->is_mi_like_p ())
8059 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8060 print_solib_event (1);
8061 return PRINT_SRC_AND_LOC
;
8065 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8067 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8068 struct value_print_options opts
;
8069 struct ui_out
*uiout
= current_uiout
;
8071 get_user_print_options (&opts
);
8072 /* Field 4, the address, is omitted (which makes the columns not
8073 line up too nicely with the headers, but the effect is relatively
8075 if (opts
.addressprint
)
8078 uiout
->field_skip ("addr");
8086 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8088 msg
= _("load of library");
8093 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8095 msg
= _("unload of library");
8097 uiout
->field_string ("what", msg
);
8099 if (uiout
->is_mi_like_p ())
8100 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8104 print_mention_catch_solib (struct breakpoint
*b
)
8106 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8108 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8109 self
->is_load
? "load" : "unload");
8113 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8115 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8117 fprintf_unfiltered (fp
, "%s %s",
8118 b
->disposition
== disp_del
? "tcatch" : "catch",
8119 self
->is_load
? "load" : "unload");
8121 fprintf_unfiltered (fp
, " %s", self
->regex
);
8122 fprintf_unfiltered (fp
, "\n");
8125 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8127 /* See breakpoint.h. */
8130 add_solib_catchpoint (const char *arg
, bool is_load
, bool is_temp
, bool enabled
)
8132 struct gdbarch
*gdbarch
= get_current_arch ();
8136 arg
= skip_spaces (arg
);
8138 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8142 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8143 _("Invalid regexp")));
8144 c
->regex
= xstrdup (arg
);
8147 c
->is_load
= is_load
;
8148 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8149 &catch_solib_breakpoint_ops
);
8151 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8153 install_breakpoint (0, std::move (c
), 1);
8156 /* A helper function that does all the work for "catch load" and
8160 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8161 struct cmd_list_element
*command
)
8163 const int enabled
= 1;
8164 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8166 add_solib_catchpoint (arg
, is_load
, temp
, enabled
);
8170 catch_load_command_1 (const char *arg
, int from_tty
,
8171 struct cmd_list_element
*command
)
8173 catch_load_or_unload (arg
, from_tty
, 1, command
);
8177 catch_unload_command_1 (const char *arg
, int from_tty
,
8178 struct cmd_list_element
*command
)
8180 catch_load_or_unload (arg
, from_tty
, 0, command
);
8183 /* See breakpoint.h. */
8186 init_catchpoint (struct breakpoint
*b
,
8187 struct gdbarch
*gdbarch
, bool temp
,
8188 const char *cond_string
,
8189 const struct breakpoint_ops
*ops
)
8191 symtab_and_line sal
;
8192 sal
.pspace
= current_program_space
;
8194 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8196 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8197 b
->disposition
= temp
? disp_del
: disp_donttouch
;
8201 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8203 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8204 set_breakpoint_number (internal
, b
);
8205 if (is_tracepoint (b
))
8206 set_tracepoint_count (breakpoint_count
);
8209 gdb::observers::breakpoint_created
.notify (b
);
8212 update_global_location_list (UGLL_MAY_INSERT
);
8216 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8217 bool temp
, const char *cond_string
,
8218 const struct breakpoint_ops
*ops
)
8220 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8222 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
, ops
);
8224 c
->forked_inferior_pid
= null_ptid
;
8226 install_breakpoint (0, std::move (c
), 1);
8229 /* Exec catchpoints. */
8231 /* An instance of this type is used to represent an exec catchpoint.
8232 A breakpoint is really of this type iff its ops pointer points to
8233 CATCH_EXEC_BREAKPOINT_OPS. */
8235 struct exec_catchpoint
: public breakpoint
8237 ~exec_catchpoint () override
;
8239 /* Filename of a program whose exec triggered this catchpoint.
8240 This field is only valid immediately after this catchpoint has
8242 char *exec_pathname
;
8245 /* Exec catchpoint destructor. */
8247 exec_catchpoint::~exec_catchpoint ()
8249 xfree (this->exec_pathname
);
8253 insert_catch_exec (struct bp_location
*bl
)
8255 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8259 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8261 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8265 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8266 const address_space
*aspace
, CORE_ADDR bp_addr
,
8267 const struct target_waitstatus
*ws
)
8269 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8271 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8274 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8278 static enum print_stop_action
8279 print_it_catch_exec (bpstat bs
)
8281 struct ui_out
*uiout
= current_uiout
;
8282 struct breakpoint
*b
= bs
->breakpoint_at
;
8283 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8285 annotate_catchpoint (b
->number
);
8286 maybe_print_thread_hit_breakpoint (uiout
);
8287 if (b
->disposition
== disp_del
)
8288 uiout
->text ("Temporary catchpoint ");
8290 uiout
->text ("Catchpoint ");
8291 if (uiout
->is_mi_like_p ())
8293 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8294 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8296 uiout
->field_signed ("bkptno", b
->number
);
8297 uiout
->text (" (exec'd ");
8298 uiout
->field_string ("new-exec", c
->exec_pathname
);
8299 uiout
->text ("), ");
8301 return PRINT_SRC_AND_LOC
;
8305 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8307 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8308 struct value_print_options opts
;
8309 struct ui_out
*uiout
= current_uiout
;
8311 get_user_print_options (&opts
);
8313 /* Field 4, the address, is omitted (which makes the columns
8314 not line up too nicely with the headers, but the effect
8315 is relatively readable). */
8316 if (opts
.addressprint
)
8317 uiout
->field_skip ("addr");
8319 uiout
->text ("exec");
8320 if (c
->exec_pathname
!= NULL
)
8322 uiout
->text (", program \"");
8323 uiout
->field_string ("what", c
->exec_pathname
);
8324 uiout
->text ("\" ");
8327 if (uiout
->is_mi_like_p ())
8328 uiout
->field_string ("catch-type", "exec");
8332 print_mention_catch_exec (struct breakpoint
*b
)
8334 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8337 /* Implement the "print_recreate" breakpoint_ops method for exec
8341 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8343 fprintf_unfiltered (fp
, "catch exec");
8344 print_recreate_thread (b
, fp
);
8347 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8350 hw_breakpoint_used_count (void)
8354 for (breakpoint
*b
: all_breakpoints ())
8355 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8356 for (bp_location
*bl
: b
->locations ())
8358 /* Special types of hardware breakpoints may use more than
8360 i
+= b
->ops
->resources_needed (bl
);
8366 /* Returns the resources B would use if it were a hardware
8370 hw_watchpoint_use_count (struct breakpoint
*b
)
8374 if (!breakpoint_enabled (b
))
8377 for (bp_location
*bl
: b
->locations ())
8379 /* Special types of hardware watchpoints may use more than
8381 i
+= b
->ops
->resources_needed (bl
);
8387 /* Returns the sum the used resources of all hardware watchpoints of
8388 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8389 the sum of the used resources of all hardware watchpoints of other
8390 types _not_ TYPE. */
8393 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8394 enum bptype type
, int *other_type_used
)
8398 *other_type_used
= 0;
8399 for (breakpoint
*b
: all_breakpoints ())
8403 if (!breakpoint_enabled (b
))
8406 if (b
->type
== type
)
8407 i
+= hw_watchpoint_use_count (b
);
8408 else if (is_hardware_watchpoint (b
))
8409 *other_type_used
= 1;
8416 disable_watchpoints_before_interactive_call_start (void)
8418 for (breakpoint
*b
: all_breakpoints ())
8419 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8421 b
->enable_state
= bp_call_disabled
;
8422 update_global_location_list (UGLL_DONT_INSERT
);
8427 enable_watchpoints_after_interactive_call_stop (void)
8429 for (breakpoint
*b
: all_breakpoints ())
8430 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8432 b
->enable_state
= bp_enabled
;
8433 update_global_location_list (UGLL_MAY_INSERT
);
8438 disable_breakpoints_before_startup (void)
8440 current_program_space
->executing_startup
= 1;
8441 update_global_location_list (UGLL_DONT_INSERT
);
8445 enable_breakpoints_after_startup (void)
8447 current_program_space
->executing_startup
= 0;
8448 breakpoint_re_set ();
8451 /* Create a new single-step breakpoint for thread THREAD, with no
8454 static struct breakpoint
*
8455 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8457 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8459 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8460 &momentary_breakpoint_ops
);
8462 b
->disposition
= disp_donttouch
;
8463 b
->frame_id
= null_frame_id
;
8466 gdb_assert (b
->thread
!= 0);
8468 return add_to_breakpoint_chain (std::move (b
));
8471 /* Set a momentary breakpoint of type TYPE at address specified by
8472 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8476 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8477 struct frame_id frame_id
, enum bptype type
)
8479 struct breakpoint
*b
;
8481 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8483 gdb_assert (!frame_id_artificial_p (frame_id
));
8485 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8486 b
->enable_state
= bp_enabled
;
8487 b
->disposition
= disp_donttouch
;
8488 b
->frame_id
= frame_id
;
8490 b
->thread
= inferior_thread ()->global_num
;
8492 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8494 return breakpoint_up (b
);
8497 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8498 The new breakpoint will have type TYPE, use OPS as its
8499 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8501 static struct breakpoint
*
8502 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8504 const struct breakpoint_ops
*ops
,
8507 struct breakpoint
*copy
;
8509 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8510 copy
->loc
= allocate_bp_location (copy
);
8511 set_breakpoint_location_function (copy
->loc
);
8513 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8514 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8515 copy
->loc
->address
= orig
->loc
->address
;
8516 copy
->loc
->section
= orig
->loc
->section
;
8517 copy
->loc
->pspace
= orig
->loc
->pspace
;
8518 copy
->loc
->probe
= orig
->loc
->probe
;
8519 copy
->loc
->line_number
= orig
->loc
->line_number
;
8520 copy
->loc
->symtab
= orig
->loc
->symtab
;
8521 copy
->loc
->enabled
= loc_enabled
;
8522 copy
->frame_id
= orig
->frame_id
;
8523 copy
->thread
= orig
->thread
;
8524 copy
->pspace
= orig
->pspace
;
8526 copy
->enable_state
= bp_enabled
;
8527 copy
->disposition
= disp_donttouch
;
8528 copy
->number
= internal_breakpoint_number
--;
8530 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8534 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8538 clone_momentary_breakpoint (struct breakpoint
*orig
)
8540 /* If there's nothing to clone, then return nothing. */
8544 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8548 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8551 struct symtab_and_line sal
;
8553 sal
= find_pc_line (pc
, 0);
8555 sal
.section
= find_pc_overlay (pc
);
8556 sal
.explicit_pc
= 1;
8558 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8562 /* Tell the user we have just set a breakpoint B. */
8565 mention (struct breakpoint
*b
)
8567 b
->ops
->print_mention (b
);
8568 current_uiout
->text ("\n");
8572 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8574 /* Handle "set breakpoint auto-hw on".
8576 If the explicitly specified breakpoint type is not hardware
8577 breakpoint, check the memory map to see whether the breakpoint
8578 address is in read-only memory.
8580 - location type is not hardware breakpoint, memory is read-only.
8581 We change the type of the location to hardware breakpoint.
8583 - location type is hardware breakpoint, memory is read-write. This
8584 means we've previously made the location hardware one, but then the
8585 memory map changed, so we undo.
8589 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8591 if (automatic_hardware_breakpoints
8592 && bl
->owner
->type
!= bp_hardware_breakpoint
8593 && (bl
->loc_type
== bp_loc_software_breakpoint
8594 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8596 /* When breakpoints are removed, remove_breakpoints will use
8597 location types we've just set here, the only possible problem
8598 is that memory map has changed during running program, but
8599 it's not going to work anyway with current gdb. */
8600 mem_region
*mr
= lookup_mem_region (bl
->address
);
8604 enum bp_loc_type new_type
;
8606 if (mr
->attrib
.mode
!= MEM_RW
)
8607 new_type
= bp_loc_hardware_breakpoint
;
8609 new_type
= bp_loc_software_breakpoint
;
8611 if (new_type
!= bl
->loc_type
)
8613 static bool said
= false;
8615 bl
->loc_type
= new_type
;
8618 fprintf_filtered (gdb_stdout
,
8619 _("Note: automatically using "
8620 "hardware breakpoints for "
8621 "read-only addresses.\n"));
8629 static struct bp_location
*
8630 add_location_to_breakpoint (struct breakpoint
*b
,
8631 const struct symtab_and_line
*sal
)
8633 struct bp_location
*loc
, **tmp
;
8634 CORE_ADDR adjusted_address
;
8635 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8637 if (loc_gdbarch
== NULL
)
8638 loc_gdbarch
= b
->gdbarch
;
8640 /* Adjust the breakpoint's address prior to allocating a location.
8641 Once we call allocate_bp_location(), that mostly uninitialized
8642 location will be placed on the location chain. Adjustment of the
8643 breakpoint may cause target_read_memory() to be called and we do
8644 not want its scan of the location chain to find a breakpoint and
8645 location that's only been partially initialized. */
8646 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8649 /* Sort the locations by their ADDRESS. */
8650 loc
= allocate_bp_location (b
);
8651 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8652 tmp
= &((*tmp
)->next
))
8657 loc
->requested_address
= sal
->pc
;
8658 loc
->address
= adjusted_address
;
8659 loc
->pspace
= sal
->pspace
;
8660 loc
->probe
.prob
= sal
->prob
;
8661 loc
->probe
.objfile
= sal
->objfile
;
8662 gdb_assert (loc
->pspace
!= NULL
);
8663 loc
->section
= sal
->section
;
8664 loc
->gdbarch
= loc_gdbarch
;
8665 loc
->line_number
= sal
->line
;
8666 loc
->symtab
= sal
->symtab
;
8667 loc
->symbol
= sal
->symbol
;
8668 loc
->msymbol
= sal
->msymbol
;
8669 loc
->objfile
= sal
->objfile
;
8671 set_breakpoint_location_function (loc
);
8673 /* While by definition, permanent breakpoints are already present in the
8674 code, we don't mark the location as inserted. Normally one would expect
8675 that GDB could rely on that breakpoint instruction to stop the program,
8676 thus removing the need to insert its own breakpoint, except that executing
8677 the breakpoint instruction can kill the target instead of reporting a
8678 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8679 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8680 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8681 breakpoint be inserted normally results in QEMU knowing about the GDB
8682 breakpoint, and thus trap before the breakpoint instruction is executed.
8683 (If GDB later needs to continue execution past the permanent breakpoint,
8684 it manually increments the PC, thus avoiding executing the breakpoint
8686 if (bp_loc_is_permanent (loc
))
8693 /* Return true if LOC is pointing to a permanent breakpoint,
8694 return false otherwise. */
8697 bp_loc_is_permanent (struct bp_location
*loc
)
8699 gdb_assert (loc
!= NULL
);
8701 /* If we have a non-breakpoint-backed catchpoint or a software
8702 watchpoint, just return 0. We should not attempt to read from
8703 the addresses the locations of these breakpoint types point to.
8704 gdbarch_program_breakpoint_here_p, below, will attempt to read
8706 if (!bl_address_is_meaningful (loc
))
8709 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8710 switch_to_program_space_and_thread (loc
->pspace
);
8711 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8714 /* Build a command list for the dprintf corresponding to the current
8715 settings of the dprintf style options. */
8718 update_dprintf_command_list (struct breakpoint
*b
)
8720 char *dprintf_args
= b
->extra_string
;
8721 char *printf_line
= NULL
;
8726 dprintf_args
= skip_spaces (dprintf_args
);
8728 /* Allow a comma, as it may have terminated a location, but don't
8730 if (*dprintf_args
== ',')
8732 dprintf_args
= skip_spaces (dprintf_args
);
8734 if (*dprintf_args
!= '"')
8735 error (_("Bad format string, missing '\"'."));
8737 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8738 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8739 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8741 if (!dprintf_function
)
8742 error (_("No function supplied for dprintf call"));
8744 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8745 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8750 printf_line
= xstrprintf ("call (void) %s (%s)",
8754 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8756 if (target_can_run_breakpoint_commands ())
8757 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8760 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8761 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8765 internal_error (__FILE__
, __LINE__
,
8766 _("Invalid dprintf style."));
8768 gdb_assert (printf_line
!= NULL
);
8770 /* Manufacture a printf sequence. */
8771 struct command_line
*printf_cmd_line
8772 = new struct command_line (simple_control
, printf_line
);
8773 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8774 command_lines_deleter ()));
8777 /* Update all dprintf commands, making their command lists reflect
8778 current style settings. */
8781 update_dprintf_commands (const char *args
, int from_tty
,
8782 struct cmd_list_element
*c
)
8784 for (breakpoint
*b
: all_breakpoints ())
8785 if (b
->type
== bp_dprintf
)
8786 update_dprintf_command_list (b
);
8789 /* Create a breakpoint with SAL as location. Use LOCATION
8790 as a description of the location, and COND_STRING
8791 as condition expression. If LOCATION is NULL then create an
8792 "address location" from the address in the SAL. */
8795 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8796 gdb::array_view
<const symtab_and_line
> sals
,
8797 event_location_up
&&location
,
8798 gdb::unique_xmalloc_ptr
<char> filter
,
8799 gdb::unique_xmalloc_ptr
<char> cond_string
,
8800 gdb::unique_xmalloc_ptr
<char> extra_string
,
8801 enum bptype type
, enum bpdisp disposition
,
8802 int thread
, int task
, int ignore_count
,
8803 const struct breakpoint_ops
*ops
, int from_tty
,
8804 int enabled
, int internal
, unsigned flags
,
8805 int display_canonical
)
8809 if (type
== bp_hardware_breakpoint
)
8811 int target_resources_ok
;
8813 i
= hw_breakpoint_used_count ();
8814 target_resources_ok
=
8815 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8817 if (target_resources_ok
== 0)
8818 error (_("No hardware breakpoint support in the target."));
8819 else if (target_resources_ok
< 0)
8820 error (_("Hardware breakpoints used exceeds limit."));
8823 gdb_assert (!sals
.empty ());
8825 for (const auto &sal
: sals
)
8827 struct bp_location
*loc
;
8831 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8833 loc_gdbarch
= gdbarch
;
8835 describe_other_breakpoints (loc_gdbarch
,
8836 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8839 if (&sal
== &sals
[0])
8841 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8845 b
->cond_string
= cond_string
.release ();
8846 b
->extra_string
= extra_string
.release ();
8847 b
->ignore_count
= ignore_count
;
8848 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8849 b
->disposition
= disposition
;
8851 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8852 b
->loc
->inserted
= 1;
8854 if (type
== bp_static_tracepoint
)
8856 struct tracepoint
*t
= (struct tracepoint
*) b
;
8857 struct static_tracepoint_marker marker
;
8859 if (strace_marker_p (b
))
8861 /* We already know the marker exists, otherwise, we
8862 wouldn't see a sal for it. */
8864 = &event_location_to_string (b
->location
.get ())[3];
8867 p
= skip_spaces (p
);
8869 endp
= skip_to_space (p
);
8871 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8873 printf_filtered (_("Probed static tracepoint "
8875 t
->static_trace_marker_id
.c_str ());
8877 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8879 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8881 printf_filtered (_("Probed static tracepoint "
8883 t
->static_trace_marker_id
.c_str ());
8886 warning (_("Couldn't determine the static "
8887 "tracepoint marker to probe"));
8894 loc
= add_location_to_breakpoint (b
, &sal
);
8895 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8899 /* Do not set breakpoint locations conditions yet. As locations
8900 are inserted, they get sorted based on their addresses. Let
8901 the list stabilize to have reliable location numbers. */
8903 /* Dynamic printf requires and uses additional arguments on the
8904 command line, otherwise it's an error. */
8905 if (type
== bp_dprintf
)
8907 if (b
->extra_string
)
8908 update_dprintf_command_list (b
);
8910 error (_("Format string required"));
8912 else if (b
->extra_string
)
8913 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8917 /* The order of the locations is now stable. Set the location
8918 condition using the location's number. */
8920 for (bp_location
*loc
: b
->locations ())
8922 if (b
->cond_string
!= nullptr)
8923 set_breakpoint_location_condition (b
->cond_string
, loc
, b
->number
,
8929 b
->display_canonical
= display_canonical
;
8930 if (location
!= NULL
)
8931 b
->location
= std::move (location
);
8933 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8934 b
->filter
= std::move (filter
);
8938 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8939 gdb::array_view
<const symtab_and_line
> sals
,
8940 event_location_up
&&location
,
8941 gdb::unique_xmalloc_ptr
<char> filter
,
8942 gdb::unique_xmalloc_ptr
<char> cond_string
,
8943 gdb::unique_xmalloc_ptr
<char> extra_string
,
8944 enum bptype type
, enum bpdisp disposition
,
8945 int thread
, int task
, int ignore_count
,
8946 const struct breakpoint_ops
*ops
, int from_tty
,
8947 int enabled
, int internal
, unsigned flags
,
8948 int display_canonical
)
8950 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8952 init_breakpoint_sal (b
.get (), gdbarch
,
8953 sals
, std::move (location
),
8955 std::move (cond_string
),
8956 std::move (extra_string
),
8958 thread
, task
, ignore_count
,
8960 enabled
, internal
, flags
,
8963 install_breakpoint (internal
, std::move (b
), 0);
8966 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8967 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8968 value. COND_STRING, if not NULL, specified the condition to be
8969 used for all breakpoints. Essentially the only case where
8970 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8971 function. In that case, it's still not possible to specify
8972 separate conditions for different overloaded functions, so
8973 we take just a single condition string.
8975 NOTE: If the function succeeds, the caller is expected to cleanup
8976 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8977 array contents). If the function fails (error() is called), the
8978 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8979 COND and SALS arrays and each of those arrays contents. */
8982 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8983 struct linespec_result
*canonical
,
8984 gdb::unique_xmalloc_ptr
<char> cond_string
,
8985 gdb::unique_xmalloc_ptr
<char> extra_string
,
8986 enum bptype type
, enum bpdisp disposition
,
8987 int thread
, int task
, int ignore_count
,
8988 const struct breakpoint_ops
*ops
, int from_tty
,
8989 int enabled
, int internal
, unsigned flags
)
8991 if (canonical
->pre_expanded
)
8992 gdb_assert (canonical
->lsals
.size () == 1);
8994 for (const auto &lsal
: canonical
->lsals
)
8996 /* Note that 'location' can be NULL in the case of a plain
8997 'break', without arguments. */
8998 event_location_up location
8999 = (canonical
->location
!= NULL
9000 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9001 gdb::unique_xmalloc_ptr
<char> filter_string
9002 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9004 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9005 std::move (location
),
9006 std::move (filter_string
),
9007 std::move (cond_string
),
9008 std::move (extra_string
),
9010 thread
, task
, ignore_count
, ops
,
9011 from_tty
, enabled
, internal
, flags
,
9012 canonical
->special_display
);
9016 /* Parse LOCATION which is assumed to be a SAL specification possibly
9017 followed by conditionals. On return, SALS contains an array of SAL
9018 addresses found. LOCATION points to the end of the SAL (for
9019 linespec locations).
9021 The array and the line spec strings are allocated on the heap, it is
9022 the caller's responsibility to free them. */
9025 parse_breakpoint_sals (struct event_location
*location
,
9026 struct linespec_result
*canonical
)
9028 struct symtab_and_line cursal
;
9030 if (event_location_type (location
) == LINESPEC_LOCATION
)
9032 const char *spec
= get_linespec_location (location
)->spec_string
;
9036 /* The last displayed codepoint, if it's valid, is our default
9037 breakpoint address. */
9038 if (last_displayed_sal_is_valid ())
9040 /* Set sal's pspace, pc, symtab, and line to the values
9041 corresponding to the last call to print_frame_info.
9042 Be sure to reinitialize LINE with NOTCURRENT == 0
9043 as the breakpoint line number is inappropriate otherwise.
9044 find_pc_line would adjust PC, re-set it back. */
9045 symtab_and_line sal
= get_last_displayed_sal ();
9046 CORE_ADDR pc
= sal
.pc
;
9048 sal
= find_pc_line (pc
, 0);
9050 /* "break" without arguments is equivalent to "break *PC"
9051 where PC is the last displayed codepoint's address. So
9052 make sure to set sal.explicit_pc to prevent GDB from
9053 trying to expand the list of sals to include all other
9054 instances with the same symtab and line. */
9056 sal
.explicit_pc
= 1;
9058 struct linespec_sals lsal
;
9060 lsal
.canonical
= NULL
;
9062 canonical
->lsals
.push_back (std::move (lsal
));
9066 error (_("No default breakpoint address now."));
9070 /* Force almost all breakpoints to be in terms of the
9071 current_source_symtab (which is decode_line_1's default).
9072 This should produce the results we want almost all of the
9073 time while leaving default_breakpoint_* alone.
9075 ObjC: However, don't match an Objective-C method name which
9076 may have a '+' or '-' succeeded by a '['. */
9077 cursal
= get_current_source_symtab_and_line ();
9078 if (last_displayed_sal_is_valid ())
9080 const char *spec
= NULL
;
9082 if (event_location_type (location
) == LINESPEC_LOCATION
)
9083 spec
= get_linespec_location (location
)->spec_string
;
9087 && strchr ("+-", spec
[0]) != NULL
9090 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9091 get_last_displayed_symtab (),
9092 get_last_displayed_line (),
9093 canonical
, NULL
, NULL
);
9098 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9099 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9103 /* Convert each SAL into a real PC. Verify that the PC can be
9104 inserted as a breakpoint. If it can't throw an error. */
9107 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9109 for (auto &sal
: sals
)
9110 resolve_sal_pc (&sal
);
9113 /* Fast tracepoints may have restrictions on valid locations. For
9114 instance, a fast tracepoint using a jump instead of a trap will
9115 likely have to overwrite more bytes than a trap would, and so can
9116 only be placed where the instruction is longer than the jump, or a
9117 multi-instruction sequence does not have a jump into the middle of
9121 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9122 gdb::array_view
<const symtab_and_line
> sals
)
9124 for (const auto &sal
: sals
)
9126 struct gdbarch
*sarch
;
9128 sarch
= get_sal_arch (sal
);
9129 /* We fall back to GDBARCH if there is no architecture
9130 associated with SAL. */
9134 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9135 error (_("May not have a fast tracepoint at %s%s"),
9136 paddress (sarch
, sal
.pc
), msg
.c_str ());
9140 /* Given TOK, a string specification of condition and thread, as
9141 accepted by the 'break' command, extract the condition
9142 string and thread number and set *COND_STRING and *THREAD.
9143 PC identifies the context at which the condition should be parsed.
9144 If no condition is found, *COND_STRING is set to NULL.
9145 If no thread is found, *THREAD is set to -1. */
9148 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9149 char **cond_string
, int *thread
, int *task
,
9152 *cond_string
= NULL
;
9160 const char *end_tok
;
9162 const char *cond_start
= NULL
;
9163 const char *cond_end
= NULL
;
9165 tok
= skip_spaces (tok
);
9167 if ((*tok
== '"' || *tok
== ',') && rest
)
9169 *rest
= savestring (tok
, strlen (tok
));
9173 end_tok
= skip_to_space (tok
);
9175 toklen
= end_tok
- tok
;
9177 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9179 tok
= cond_start
= end_tok
+ 1;
9182 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9184 catch (const gdb_exception_error
&)
9189 tok
= tok
+ strlen (tok
);
9192 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9194 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
9199 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9202 struct thread_info
*thr
;
9205 thr
= parse_thread_id (tok
, &tmptok
);
9207 error (_("Junk after thread keyword."));
9208 *thread
= thr
->global_num
;
9211 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9216 *task
= strtol (tok
, &tmptok
, 0);
9218 error (_("Junk after task keyword."));
9219 if (!valid_task_id (*task
))
9220 error (_("Unknown task %d."), *task
);
9225 *rest
= savestring (tok
, strlen (tok
));
9229 error (_("Junk at end of arguments."));
9233 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
9234 succeeds. The parsed values are written to COND_STRING, THREAD,
9235 TASK, and REST. See the comment of 'find_condition_and_thread'
9236 for the description of these parameters and INPUT. */
9239 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
9240 const char *input
, char **cond_string
,
9241 int *thread
, int *task
, char **rest
)
9243 int num_failures
= 0;
9244 for (auto &sal
: sals
)
9246 char *cond
= nullptr;
9249 char *remaining
= nullptr;
9251 /* Here we want to parse 'arg' to separate condition from thread
9252 number. But because parsing happens in a context and the
9253 contexts of sals might be different, try each until there is
9254 success. Finding one successful parse is sufficient for our
9255 goal. When setting the breakpoint we'll re-parse the
9256 condition in the context of each sal. */
9259 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
9260 &task_id
, &remaining
);
9261 *cond_string
= cond
;
9262 *thread
= thread_id
;
9267 catch (const gdb_exception_error
&e
)
9270 /* If no sal remains, do not continue. */
9271 if (num_failures
== sals
.size ())
9277 /* Decode a static tracepoint marker spec. */
9279 static std::vector
<symtab_and_line
>
9280 decode_static_tracepoint_spec (const char **arg_p
)
9282 const char *p
= &(*arg_p
)[3];
9285 p
= skip_spaces (p
);
9287 endp
= skip_to_space (p
);
9289 std::string
marker_str (p
, endp
- p
);
9291 std::vector
<static_tracepoint_marker
> markers
9292 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9293 if (markers
.empty ())
9294 error (_("No known static tracepoint marker named %s"),
9295 marker_str
.c_str ());
9297 std::vector
<symtab_and_line
> sals
;
9298 sals
.reserve (markers
.size ());
9300 for (const static_tracepoint_marker
&marker
: markers
)
9302 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9303 sal
.pc
= marker
.address
;
9304 sals
.push_back (sal
);
9311 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9312 according to IS_TRACEPOINT. */
9314 static const struct breakpoint_ops
*
9315 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
9320 if (location_type
== PROBE_LOCATION
)
9321 return &tracepoint_probe_breakpoint_ops
;
9323 return &tracepoint_breakpoint_ops
;
9327 if (location_type
== PROBE_LOCATION
)
9328 return &bkpt_probe_breakpoint_ops
;
9330 return &bkpt_breakpoint_ops
;
9334 /* See breakpoint.h. */
9336 const struct breakpoint_ops
*
9337 breakpoint_ops_for_event_location (const struct event_location
*location
,
9340 if (location
!= nullptr)
9341 return breakpoint_ops_for_event_location_type
9342 (event_location_type (location
), is_tracepoint
);
9343 return is_tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
9346 /* See breakpoint.h. */
9349 create_breakpoint (struct gdbarch
*gdbarch
,
9350 struct event_location
*location
,
9351 const char *cond_string
,
9352 int thread
, const char *extra_string
,
9353 bool force_condition
, int parse_extra
,
9354 int tempflag
, enum bptype type_wanted
,
9356 enum auto_boolean pending_break_support
,
9357 const struct breakpoint_ops
*ops
,
9358 int from_tty
, int enabled
, int internal
,
9361 struct linespec_result canonical
;
9364 int prev_bkpt_count
= breakpoint_count
;
9366 gdb_assert (ops
!= NULL
);
9368 /* If extra_string isn't useful, set it to NULL. */
9369 if (extra_string
!= NULL
&& *extra_string
== '\0')
9370 extra_string
= NULL
;
9374 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9376 catch (const gdb_exception_error
&e
)
9378 /* If caller is interested in rc value from parse, set
9380 if (e
.error
== NOT_FOUND_ERROR
)
9382 /* If pending breakpoint support is turned off, throw
9385 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9388 exception_print (gdb_stderr
, e
);
9390 /* If pending breakpoint support is auto query and the user
9391 selects no, then simply return the error code. */
9392 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9393 && !nquery (_("Make %s pending on future shared library load? "),
9394 bptype_string (type_wanted
)))
9397 /* At this point, either the user was queried about setting
9398 a pending breakpoint and selected yes, or pending
9399 breakpoint behavior is on and thus a pending breakpoint
9400 is defaulted on behalf of the user. */
9407 if (!pending
&& canonical
.lsals
.empty ())
9410 /* Resolve all line numbers to PC's and verify that the addresses
9411 are ok for the target. */
9414 for (auto &lsal
: canonical
.lsals
)
9415 breakpoint_sals_to_pc (lsal
.sals
);
9418 /* Fast tracepoints may have additional restrictions on location. */
9419 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9421 for (const auto &lsal
: canonical
.lsals
)
9422 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9425 /* Verify that condition can be parsed, before setting any
9426 breakpoints. Allocate a separate condition expression for each
9430 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9431 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9438 const linespec_sals
&lsal
= canonical
.lsals
[0];
9440 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9441 &cond
, &thread
, &task
, &rest
);
9442 cond_string_copy
.reset (cond
);
9443 extra_string_copy
.reset (rest
);
9447 if (type_wanted
!= bp_dprintf
9448 && extra_string
!= NULL
&& *extra_string
!= '\0')
9449 error (_("Garbage '%s' at end of location"), extra_string
);
9451 /* Check the validity of the condition. We should error out
9452 if the condition is invalid at all of the locations and
9453 if it is not forced. In the PARSE_EXTRA case above, this
9454 check is done when parsing the EXTRA_STRING. */
9455 if (cond_string
!= nullptr && !force_condition
)
9457 int num_failures
= 0;
9458 const linespec_sals
&lsal
= canonical
.lsals
[0];
9459 for (const auto &sal
: lsal
.sals
)
9461 const char *cond
= cond_string
;
9464 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
9465 /* One success is sufficient to keep going. */
9468 catch (const gdb_exception_error
&)
9471 /* If this is the last sal, error out. */
9472 if (num_failures
== lsal
.sals
.size ())
9478 /* Create a private copy of condition string. */
9480 cond_string_copy
.reset (xstrdup (cond_string
));
9481 /* Create a private copy of any extra string. */
9483 extra_string_copy
.reset (xstrdup (extra_string
));
9486 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9487 std::move (cond_string_copy
),
9488 std::move (extra_string_copy
),
9490 tempflag
? disp_del
: disp_donttouch
,
9491 thread
, task
, ignore_count
, ops
,
9492 from_tty
, enabled
, internal
, flags
);
9496 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9498 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9499 b
->location
= copy_event_location (location
);
9502 b
->cond_string
= NULL
;
9505 /* Create a private copy of condition string. */
9506 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9510 /* Create a private copy of any extra string. */
9511 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9512 b
->ignore_count
= ignore_count
;
9513 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9514 b
->condition_not_parsed
= 1;
9515 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9516 if ((type_wanted
!= bp_breakpoint
9517 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9518 b
->pspace
= current_program_space
;
9520 install_breakpoint (internal
, std::move (b
), 0);
9523 if (canonical
.lsals
.size () > 1)
9525 warning (_("Multiple breakpoints were set.\nUse the "
9526 "\"delete\" command to delete unwanted breakpoints."));
9527 prev_breakpoint_count
= prev_bkpt_count
;
9530 update_global_location_list (UGLL_MAY_INSERT
);
9535 /* Set a breakpoint.
9536 ARG is a string describing breakpoint address,
9537 condition, and thread.
9538 FLAG specifies if a breakpoint is hardware on,
9539 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9543 break_command_1 (const char *arg
, int flag
, int from_tty
)
9545 int tempflag
= flag
& BP_TEMPFLAG
;
9546 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9547 ? bp_hardware_breakpoint
9550 event_location_up location
= string_to_event_location (&arg
, current_language
);
9551 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9552 (location
.get (), false /* is_tracepoint */);
9554 create_breakpoint (get_current_arch (),
9556 NULL
, 0, arg
, false, 1 /* parse arg */,
9557 tempflag
, type_wanted
,
9558 0 /* Ignore count */,
9559 pending_break_support
,
9567 /* Helper function for break_command_1 and disassemble_command. */
9570 resolve_sal_pc (struct symtab_and_line
*sal
)
9574 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9576 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9577 error (_("No line %d in file \"%s\"."),
9578 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9581 /* If this SAL corresponds to a breakpoint inserted using a line
9582 number, then skip the function prologue if necessary. */
9583 if (sal
->explicit_line
)
9584 skip_prologue_sal (sal
);
9587 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9589 const struct blockvector
*bv
;
9590 const struct block
*b
;
9593 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9594 SYMTAB_COMPUNIT (sal
->symtab
));
9597 sym
= block_linkage_function (b
);
9600 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9601 sal
->section
= sym
->obj_section (SYMTAB_OBJFILE (sal
->symtab
));
9605 /* It really is worthwhile to have the section, so we'll
9606 just have to look harder. This case can be executed
9607 if we have line numbers but no functions (as can
9608 happen in assembly source). */
9610 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9611 switch_to_program_space_and_thread (sal
->pspace
);
9613 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9615 sal
->section
= msym
.obj_section ();
9622 break_command (const char *arg
, int from_tty
)
9624 break_command_1 (arg
, 0, from_tty
);
9628 tbreak_command (const char *arg
, int from_tty
)
9630 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9634 hbreak_command (const char *arg
, int from_tty
)
9636 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9640 thbreak_command (const char *arg
, int from_tty
)
9642 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9646 stop_command (const char *arg
, int from_tty
)
9648 printf_filtered (_("Specify the type of breakpoint to set.\n\
9649 Usage: stop in <function | address>\n\
9650 stop at <line>\n"));
9654 stopin_command (const char *arg
, int from_tty
)
9660 else if (*arg
!= '*')
9662 const char *argptr
= arg
;
9665 /* Look for a ':'. If this is a line number specification, then
9666 say it is bad, otherwise, it should be an address or
9667 function/method name. */
9668 while (*argptr
&& !hasColon
)
9670 hasColon
= (*argptr
== ':');
9675 badInput
= (*argptr
!= ':'); /* Not a class::method */
9677 badInput
= isdigit (*arg
); /* a simple line number */
9681 printf_filtered (_("Usage: stop in <function | address>\n"));
9683 break_command_1 (arg
, 0, from_tty
);
9687 stopat_command (const char *arg
, int from_tty
)
9691 if (arg
== NULL
|| *arg
== '*') /* no line number */
9695 const char *argptr
= arg
;
9698 /* Look for a ':'. If there is a '::' then get out, otherwise
9699 it is probably a line number. */
9700 while (*argptr
&& !hasColon
)
9702 hasColon
= (*argptr
== ':');
9707 badInput
= (*argptr
== ':'); /* we have class::method */
9709 badInput
= !isdigit (*arg
); /* not a line number */
9713 printf_filtered (_("Usage: stop at LINE\n"));
9715 break_command_1 (arg
, 0, from_tty
);
9718 /* The dynamic printf command is mostly like a regular breakpoint, but
9719 with a prewired command list consisting of a single output command,
9720 built from extra arguments supplied on the dprintf command
9724 dprintf_command (const char *arg
, int from_tty
)
9726 event_location_up location
= string_to_event_location (&arg
, current_language
);
9728 /* If non-NULL, ARG should have been advanced past the location;
9729 the next character must be ','. */
9732 if (arg
[0] != ',' || arg
[1] == '\0')
9733 error (_("Format string required"));
9736 /* Skip the comma. */
9741 create_breakpoint (get_current_arch (),
9743 NULL
, 0, arg
, false, 1 /* parse arg */,
9745 0 /* Ignore count */,
9746 pending_break_support
,
9747 &dprintf_breakpoint_ops
,
9755 agent_printf_command (const char *arg
, int from_tty
)
9757 error (_("May only run agent-printf on the target"));
9760 /* Implement the "breakpoint_hit" breakpoint_ops method for
9761 ranged breakpoints. */
9764 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9765 const address_space
*aspace
,
9767 const struct target_waitstatus
*ws
)
9769 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9770 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9773 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9774 bl
->length
, aspace
, bp_addr
);
9777 /* Implement the "resources_needed" breakpoint_ops method for
9778 ranged breakpoints. */
9781 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9783 return target_ranged_break_num_registers ();
9786 /* Implement the "print_it" breakpoint_ops method for
9787 ranged breakpoints. */
9789 static enum print_stop_action
9790 print_it_ranged_breakpoint (bpstat bs
)
9792 struct breakpoint
*b
= bs
->breakpoint_at
;
9793 struct bp_location
*bl
= b
->loc
;
9794 struct ui_out
*uiout
= current_uiout
;
9796 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9798 /* Ranged breakpoints have only one location. */
9799 gdb_assert (bl
&& bl
->next
== NULL
);
9801 annotate_breakpoint (b
->number
);
9803 maybe_print_thread_hit_breakpoint (uiout
);
9805 if (b
->disposition
== disp_del
)
9806 uiout
->text ("Temporary ranged breakpoint ");
9808 uiout
->text ("Ranged breakpoint ");
9809 if (uiout
->is_mi_like_p ())
9811 uiout
->field_string ("reason",
9812 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9813 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9815 uiout
->field_signed ("bkptno", b
->number
);
9818 return PRINT_SRC_AND_LOC
;
9821 /* Implement the "print_one" breakpoint_ops method for
9822 ranged breakpoints. */
9825 print_one_ranged_breakpoint (struct breakpoint
*b
,
9826 struct bp_location
**last_loc
)
9828 struct bp_location
*bl
= b
->loc
;
9829 struct value_print_options opts
;
9830 struct ui_out
*uiout
= current_uiout
;
9832 /* Ranged breakpoints have only one location. */
9833 gdb_assert (bl
&& bl
->next
== NULL
);
9835 get_user_print_options (&opts
);
9837 if (opts
.addressprint
)
9838 /* We don't print the address range here, it will be printed later
9839 by print_one_detail_ranged_breakpoint. */
9840 uiout
->field_skip ("addr");
9842 print_breakpoint_location (b
, bl
);
9846 /* Implement the "print_one_detail" breakpoint_ops method for
9847 ranged breakpoints. */
9850 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9851 struct ui_out
*uiout
)
9853 CORE_ADDR address_start
, address_end
;
9854 struct bp_location
*bl
= b
->loc
;
9859 address_start
= bl
->address
;
9860 address_end
= address_start
+ bl
->length
- 1;
9862 uiout
->text ("\taddress range: ");
9863 stb
.printf ("[%s, %s]",
9864 print_core_address (bl
->gdbarch
, address_start
),
9865 print_core_address (bl
->gdbarch
, address_end
));
9866 uiout
->field_stream ("addr", stb
);
9870 /* Implement the "print_mention" breakpoint_ops method for
9871 ranged breakpoints. */
9874 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9876 struct bp_location
*bl
= b
->loc
;
9877 struct ui_out
*uiout
= current_uiout
;
9880 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9882 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9883 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9884 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9887 /* Implement the "print_recreate" breakpoint_ops method for
9888 ranged breakpoints. */
9891 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9893 fprintf_unfiltered (fp
, "break-range %s, %s",
9894 event_location_to_string (b
->location
.get ()),
9895 event_location_to_string (b
->location_range_end
.get ()));
9896 print_recreate_thread (b
, fp
);
9899 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9901 static struct breakpoint_ops ranged_breakpoint_ops
;
9903 /* Find the address where the end of the breakpoint range should be
9904 placed, given the SAL of the end of the range. This is so that if
9905 the user provides a line number, the end of the range is set to the
9906 last instruction of the given line. */
9909 find_breakpoint_range_end (struct symtab_and_line sal
)
9913 /* If the user provided a PC value, use it. Otherwise,
9914 find the address of the end of the given location. */
9915 if (sal
.explicit_pc
)
9922 ret
= find_line_pc_range (sal
, &start
, &end
);
9924 error (_("Could not find location of the end of the range."));
9926 /* find_line_pc_range returns the start of the next line. */
9933 /* Implement the "break-range" CLI command. */
9936 break_range_command (const char *arg
, int from_tty
)
9938 const char *arg_start
;
9939 struct linespec_result canonical_start
, canonical_end
;
9940 int bp_count
, can_use_bp
, length
;
9942 struct breakpoint
*b
;
9944 /* We don't support software ranged breakpoints. */
9945 if (target_ranged_break_num_registers () < 0)
9946 error (_("This target does not support hardware ranged breakpoints."));
9948 bp_count
= hw_breakpoint_used_count ();
9949 bp_count
+= target_ranged_break_num_registers ();
9950 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9953 error (_("Hardware breakpoints used exceeds limit."));
9955 arg
= skip_spaces (arg
);
9956 if (arg
== NULL
|| arg
[0] == '\0')
9957 error(_("No address range specified."));
9960 event_location_up start_location
= string_to_event_location (&arg
,
9962 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9965 error (_("Too few arguments."));
9966 else if (canonical_start
.lsals
.empty ())
9967 error (_("Could not find location of the beginning of the range."));
9969 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9971 if (canonical_start
.lsals
.size () > 1
9972 || lsal_start
.sals
.size () != 1)
9973 error (_("Cannot create a ranged breakpoint with multiple locations."));
9975 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9976 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9978 arg
++; /* Skip the comma. */
9979 arg
= skip_spaces (arg
);
9981 /* Parse the end location. */
9985 /* We call decode_line_full directly here instead of using
9986 parse_breakpoint_sals because we need to specify the start location's
9987 symtab and line as the default symtab and line for the end of the
9988 range. This makes it possible to have ranges like "foo.c:27, +14",
9989 where +14 means 14 lines from the start location. */
9990 event_location_up end_location
= string_to_event_location (&arg
,
9992 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9993 sal_start
.symtab
, sal_start
.line
,
9994 &canonical_end
, NULL
, NULL
);
9996 if (canonical_end
.lsals
.empty ())
9997 error (_("Could not find location of the end of the range."));
9999 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10000 if (canonical_end
.lsals
.size () > 1
10001 || lsal_end
.sals
.size () != 1)
10002 error (_("Cannot create a ranged breakpoint with multiple locations."));
10004 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10006 end
= find_breakpoint_range_end (sal_end
);
10007 if (sal_start
.pc
> end
)
10008 error (_("Invalid address range, end precedes start."));
10010 length
= end
- sal_start
.pc
+ 1;
10012 /* Length overflowed. */
10013 error (_("Address range too large."));
10014 else if (length
== 1)
10016 /* This range is simple enough to be handled by
10017 the `hbreak' command. */
10018 hbreak_command (&addr_string_start
[0], 1);
10023 /* Now set up the breakpoint. */
10024 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10025 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10026 set_breakpoint_count (breakpoint_count
+ 1);
10027 b
->number
= breakpoint_count
;
10028 b
->disposition
= disp_donttouch
;
10029 b
->location
= std::move (start_location
);
10030 b
->location_range_end
= std::move (end_location
);
10031 b
->loc
->length
= length
;
10034 gdb::observers::breakpoint_created
.notify (b
);
10035 update_global_location_list (UGLL_MAY_INSERT
);
10038 /* Return non-zero if EXP is verified as constant. Returned zero
10039 means EXP is variable. Also the constant detection may fail for
10040 some constant expressions and in such case still falsely return
10044 watchpoint_exp_is_const (const struct expression
*exp
)
10046 return exp
->op
->constant_p ();
10049 /* Watchpoint destructor. */
10051 watchpoint::~watchpoint ()
10053 xfree (this->exp_string
);
10054 xfree (this->exp_string_reparse
);
10057 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10060 re_set_watchpoint (struct breakpoint
*b
)
10062 struct watchpoint
*w
= (struct watchpoint
*) b
;
10064 /* Watchpoint can be either on expression using entirely global
10065 variables, or it can be on local variables.
10067 Watchpoints of the first kind are never auto-deleted, and even
10068 persist across program restarts. Since they can use variables
10069 from shared libraries, we need to reparse expression as libraries
10070 are loaded and unloaded.
10072 Watchpoints on local variables can also change meaning as result
10073 of solib event. For example, if a watchpoint uses both a local
10074 and a global variables in expression, it's a local watchpoint,
10075 but unloading of a shared library will make the expression
10076 invalid. This is not a very common use case, but we still
10077 re-evaluate expression, to avoid surprises to the user.
10079 Note that for local watchpoints, we re-evaluate it only if
10080 watchpoints frame id is still valid. If it's not, it means the
10081 watchpoint is out of scope and will be deleted soon. In fact,
10082 I'm not sure we'll ever be called in this case.
10084 If a local watchpoint's frame id is still valid, then
10085 w->exp_valid_block is likewise valid, and we can safely use it.
10087 Don't do anything about disabled watchpoints, since they will be
10088 reevaluated again when enabled. */
10089 update_watchpoint (w
, 1 /* reparse */);
10092 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10095 insert_watchpoint (struct bp_location
*bl
)
10097 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10098 int length
= w
->exact
? 1 : bl
->length
;
10100 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10101 w
->cond_exp
.get ());
10104 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10107 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10109 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10110 int length
= w
->exact
? 1 : bl
->length
;
10112 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10113 w
->cond_exp
.get ());
10117 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10118 const address_space
*aspace
, CORE_ADDR bp_addr
,
10119 const struct target_waitstatus
*ws
)
10121 struct breakpoint
*b
= bl
->owner
;
10122 struct watchpoint
*w
= (struct watchpoint
*) b
;
10124 /* Continuable hardware watchpoints are treated as non-existent if the
10125 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10126 some data address). Otherwise gdb won't stop on a break instruction
10127 in the code (not from a breakpoint) when a hardware watchpoint has
10128 been defined. Also skip watchpoints which we know did not trigger
10129 (did not match the data address). */
10130 if (is_hardware_watchpoint (b
)
10131 && w
->watchpoint_triggered
== watch_triggered_no
)
10138 check_status_watchpoint (bpstat bs
)
10140 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10142 bpstat_check_watchpoint (bs
);
10145 /* Implement the "resources_needed" breakpoint_ops method for
10146 hardware watchpoints. */
10149 resources_needed_watchpoint (const struct bp_location
*bl
)
10151 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10152 int length
= w
->exact
? 1 : bl
->length
;
10154 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10157 /* Implement the "works_in_software_mode" breakpoint_ops method for
10158 hardware watchpoints. */
10161 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10163 /* Read and access watchpoints only work with hardware support. */
10164 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10167 static enum print_stop_action
10168 print_it_watchpoint (bpstat bs
)
10170 struct breakpoint
*b
;
10171 enum print_stop_action result
;
10172 struct watchpoint
*w
;
10173 struct ui_out
*uiout
= current_uiout
;
10175 gdb_assert (bs
->bp_location_at
!= NULL
);
10177 b
= bs
->breakpoint_at
;
10178 w
= (struct watchpoint
*) b
;
10180 annotate_watchpoint (b
->number
);
10181 maybe_print_thread_hit_breakpoint (uiout
);
10185 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10188 case bp_watchpoint
:
10189 case bp_hardware_watchpoint
:
10190 if (uiout
->is_mi_like_p ())
10191 uiout
->field_string
10192 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10194 tuple_emitter
.emplace (uiout
, "value");
10195 uiout
->text ("\nOld value = ");
10196 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10197 uiout
->field_stream ("old", stb
);
10198 uiout
->text ("\nNew value = ");
10199 watchpoint_value_print (w
->val
.get (), &stb
);
10200 uiout
->field_stream ("new", stb
);
10201 uiout
->text ("\n");
10202 /* More than one watchpoint may have been triggered. */
10203 result
= PRINT_UNKNOWN
;
10206 case bp_read_watchpoint
:
10207 if (uiout
->is_mi_like_p ())
10208 uiout
->field_string
10209 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10211 tuple_emitter
.emplace (uiout
, "value");
10212 uiout
->text ("\nValue = ");
10213 watchpoint_value_print (w
->val
.get (), &stb
);
10214 uiout
->field_stream ("value", stb
);
10215 uiout
->text ("\n");
10216 result
= PRINT_UNKNOWN
;
10219 case bp_access_watchpoint
:
10220 if (bs
->old_val
!= NULL
)
10222 if (uiout
->is_mi_like_p ())
10223 uiout
->field_string
10225 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10227 tuple_emitter
.emplace (uiout
, "value");
10228 uiout
->text ("\nOld value = ");
10229 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10230 uiout
->field_stream ("old", stb
);
10231 uiout
->text ("\nNew value = ");
10236 if (uiout
->is_mi_like_p ())
10237 uiout
->field_string
10239 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10240 tuple_emitter
.emplace (uiout
, "value");
10241 uiout
->text ("\nValue = ");
10243 watchpoint_value_print (w
->val
.get (), &stb
);
10244 uiout
->field_stream ("new", stb
);
10245 uiout
->text ("\n");
10246 result
= PRINT_UNKNOWN
;
10249 result
= PRINT_UNKNOWN
;
10255 /* Implement the "print_mention" breakpoint_ops method for hardware
10259 print_mention_watchpoint (struct breakpoint
*b
)
10261 struct watchpoint
*w
= (struct watchpoint
*) b
;
10262 struct ui_out
*uiout
= current_uiout
;
10263 const char *tuple_name
;
10267 case bp_watchpoint
:
10268 uiout
->text ("Watchpoint ");
10269 tuple_name
= "wpt";
10271 case bp_hardware_watchpoint
:
10272 uiout
->text ("Hardware watchpoint ");
10273 tuple_name
= "wpt";
10275 case bp_read_watchpoint
:
10276 uiout
->text ("Hardware read watchpoint ");
10277 tuple_name
= "hw-rwpt";
10279 case bp_access_watchpoint
:
10280 uiout
->text ("Hardware access (read/write) watchpoint ");
10281 tuple_name
= "hw-awpt";
10284 internal_error (__FILE__
, __LINE__
,
10285 _("Invalid hardware watchpoint type."));
10288 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10289 uiout
->field_signed ("number", b
->number
);
10290 uiout
->text (": ");
10291 uiout
->field_string ("exp", w
->exp_string
);
10294 /* Implement the "print_recreate" breakpoint_ops method for
10298 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10300 struct watchpoint
*w
= (struct watchpoint
*) b
;
10304 case bp_watchpoint
:
10305 case bp_hardware_watchpoint
:
10306 fprintf_unfiltered (fp
, "watch");
10308 case bp_read_watchpoint
:
10309 fprintf_unfiltered (fp
, "rwatch");
10311 case bp_access_watchpoint
:
10312 fprintf_unfiltered (fp
, "awatch");
10315 internal_error (__FILE__
, __LINE__
,
10316 _("Invalid watchpoint type."));
10319 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10320 print_recreate_thread (b
, fp
);
10323 /* Implement the "explains_signal" breakpoint_ops method for
10327 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10329 /* A software watchpoint cannot cause a signal other than
10330 GDB_SIGNAL_TRAP. */
10331 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10337 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10339 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10341 /* Implement the "insert" breakpoint_ops method for
10342 masked hardware watchpoints. */
10345 insert_masked_watchpoint (struct bp_location
*bl
)
10347 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10349 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10350 bl
->watchpoint_type
);
10353 /* Implement the "remove" breakpoint_ops method for
10354 masked hardware watchpoints. */
10357 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10359 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10361 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10362 bl
->watchpoint_type
);
10365 /* Implement the "resources_needed" breakpoint_ops method for
10366 masked hardware watchpoints. */
10369 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10371 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10373 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10376 /* Implement the "works_in_software_mode" breakpoint_ops method for
10377 masked hardware watchpoints. */
10380 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10385 /* Implement the "print_it" breakpoint_ops method for
10386 masked hardware watchpoints. */
10388 static enum print_stop_action
10389 print_it_masked_watchpoint (bpstat bs
)
10391 struct breakpoint
*b
= bs
->breakpoint_at
;
10392 struct ui_out
*uiout
= current_uiout
;
10394 /* Masked watchpoints have only one location. */
10395 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10397 annotate_watchpoint (b
->number
);
10398 maybe_print_thread_hit_breakpoint (uiout
);
10402 case bp_hardware_watchpoint
:
10403 if (uiout
->is_mi_like_p ())
10404 uiout
->field_string
10405 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10408 case bp_read_watchpoint
:
10409 if (uiout
->is_mi_like_p ())
10410 uiout
->field_string
10411 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10414 case bp_access_watchpoint
:
10415 if (uiout
->is_mi_like_p ())
10416 uiout
->field_string
10418 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10421 internal_error (__FILE__
, __LINE__
,
10422 _("Invalid hardware watchpoint type."));
10426 uiout
->text (_("\n\
10427 Check the underlying instruction at PC for the memory\n\
10428 address and value which triggered this watchpoint.\n"));
10429 uiout
->text ("\n");
10431 /* More than one watchpoint may have been triggered. */
10432 return PRINT_UNKNOWN
;
10435 /* Implement the "print_one_detail" breakpoint_ops method for
10436 masked hardware watchpoints. */
10439 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10440 struct ui_out
*uiout
)
10442 struct watchpoint
*w
= (struct watchpoint
*) b
;
10444 /* Masked watchpoints have only one location. */
10445 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10447 uiout
->text ("\tmask ");
10448 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10449 uiout
->text ("\n");
10452 /* Implement the "print_mention" breakpoint_ops method for
10453 masked hardware watchpoints. */
10456 print_mention_masked_watchpoint (struct breakpoint
*b
)
10458 struct watchpoint
*w
= (struct watchpoint
*) b
;
10459 struct ui_out
*uiout
= current_uiout
;
10460 const char *tuple_name
;
10464 case bp_hardware_watchpoint
:
10465 uiout
->text ("Masked hardware watchpoint ");
10466 tuple_name
= "wpt";
10468 case bp_read_watchpoint
:
10469 uiout
->text ("Masked hardware read watchpoint ");
10470 tuple_name
= "hw-rwpt";
10472 case bp_access_watchpoint
:
10473 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10474 tuple_name
= "hw-awpt";
10477 internal_error (__FILE__
, __LINE__
,
10478 _("Invalid hardware watchpoint type."));
10481 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10482 uiout
->field_signed ("number", b
->number
);
10483 uiout
->text (": ");
10484 uiout
->field_string ("exp", w
->exp_string
);
10487 /* Implement the "print_recreate" breakpoint_ops method for
10488 masked hardware watchpoints. */
10491 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10493 struct watchpoint
*w
= (struct watchpoint
*) b
;
10497 case bp_hardware_watchpoint
:
10498 fprintf_unfiltered (fp
, "watch");
10500 case bp_read_watchpoint
:
10501 fprintf_unfiltered (fp
, "rwatch");
10503 case bp_access_watchpoint
:
10504 fprintf_unfiltered (fp
, "awatch");
10507 internal_error (__FILE__
, __LINE__
,
10508 _("Invalid hardware watchpoint type."));
10511 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
,
10512 phex (w
->hw_wp_mask
, sizeof (CORE_ADDR
)));
10513 print_recreate_thread (b
, fp
);
10516 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10518 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10520 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10523 is_masked_watchpoint (const struct breakpoint
*b
)
10525 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10528 /* accessflag: hw_write: watch write,
10529 hw_read: watch read,
10530 hw_access: watch access (read or write) */
10532 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10533 bool just_location
, bool internal
)
10535 struct breakpoint
*scope_breakpoint
= NULL
;
10536 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10537 struct value
*result
;
10538 int saved_bitpos
= 0, saved_bitsize
= 0;
10539 const char *exp_start
= NULL
;
10540 const char *exp_end
= NULL
;
10541 const char *tok
, *end_tok
;
10543 const char *cond_start
= NULL
;
10544 const char *cond_end
= NULL
;
10545 enum bptype bp_type
;
10547 /* Flag to indicate whether we are going to use masks for
10548 the hardware watchpoint. */
10549 bool use_mask
= false;
10550 CORE_ADDR mask
= 0;
10552 /* Make sure that we actually have parameters to parse. */
10553 if (arg
!= NULL
&& arg
[0] != '\0')
10555 const char *value_start
;
10557 exp_end
= arg
+ strlen (arg
);
10559 /* Look for "parameter value" pairs at the end
10560 of the arguments string. */
10561 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10563 /* Skip whitespace at the end of the argument list. */
10564 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10567 /* Find the beginning of the last token.
10568 This is the value of the parameter. */
10569 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10571 value_start
= tok
+ 1;
10573 /* Skip whitespace. */
10574 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10579 /* Find the beginning of the second to last token.
10580 This is the parameter itself. */
10581 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10584 toklen
= end_tok
- tok
+ 1;
10586 if (toklen
== 6 && startswith (tok
, "thread"))
10588 struct thread_info
*thr
;
10589 /* At this point we've found a "thread" token, which means
10590 the user is trying to set a watchpoint that triggers
10591 only in a specific thread. */
10595 error(_("You can specify only one thread."));
10597 /* Extract the thread ID from the next token. */
10598 thr
= parse_thread_id (value_start
, &endp
);
10600 /* Check if the user provided a valid thread ID. */
10601 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10602 invalid_thread_id_error (value_start
);
10604 thread
= thr
->global_num
;
10606 else if (toklen
== 4 && startswith (tok
, "mask"))
10608 /* We've found a "mask" token, which means the user wants to
10609 create a hardware watchpoint that is going to have the mask
10611 struct value
*mask_value
, *mark
;
10614 error(_("You can specify only one mask."));
10616 use_mask
= just_location
= true;
10618 mark
= value_mark ();
10619 mask_value
= parse_to_comma_and_eval (&value_start
);
10620 mask
= value_as_address (mask_value
);
10621 value_free_to_mark (mark
);
10624 /* We didn't recognize what we found. We should stop here. */
10627 /* Truncate the string and get rid of the "parameter value" pair before
10628 the arguments string is parsed by the parse_exp_1 function. */
10635 /* Parse the rest of the arguments. From here on out, everything
10636 is in terms of a newly allocated string instead of the original
10638 std::string
expression (arg
, exp_end
- arg
);
10639 exp_start
= arg
= expression
.c_str ();
10640 innermost_block_tracker tracker
;
10641 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10643 /* Remove trailing whitespace from the expression before saving it.
10644 This makes the eventual display of the expression string a bit
10646 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10649 /* Checking if the expression is not constant. */
10650 if (watchpoint_exp_is_const (exp
.get ()))
10654 len
= exp_end
- exp_start
;
10655 while (len
> 0 && isspace (exp_start
[len
- 1]))
10657 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10660 exp_valid_block
= tracker
.block ();
10661 struct value
*mark
= value_mark ();
10662 struct value
*val_as_value
= nullptr;
10663 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10666 if (val_as_value
!= NULL
&& just_location
)
10668 saved_bitpos
= value_bitpos (val_as_value
);
10669 saved_bitsize
= value_bitsize (val_as_value
);
10677 exp_valid_block
= NULL
;
10678 val
= release_value (value_addr (result
));
10679 value_free_to_mark (mark
);
10683 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10686 error (_("This target does not support masked watchpoints."));
10687 else if (ret
== -2)
10688 error (_("Invalid mask or memory region."));
10691 else if (val_as_value
!= NULL
)
10692 val
= release_value (val_as_value
);
10694 tok
= skip_spaces (arg
);
10695 end_tok
= skip_to_space (tok
);
10697 toklen
= end_tok
- tok
;
10698 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10700 tok
= cond_start
= end_tok
+ 1;
10701 innermost_block_tracker if_tracker
;
10702 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10704 /* The watchpoint expression may not be local, but the condition
10705 may still be. E.g.: `watch global if local > 0'. */
10706 cond_exp_valid_block
= if_tracker
.block ();
10711 error (_("Junk at end of command."));
10713 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10715 /* Save this because create_internal_breakpoint below invalidates
10717 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10719 /* If the expression is "local", then set up a "watchpoint scope"
10720 breakpoint at the point where we've left the scope of the watchpoint
10721 expression. Create the scope breakpoint before the watchpoint, so
10722 that we will encounter it first in bpstat_stop_status. */
10723 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10725 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10727 if (frame_id_p (caller_frame_id
))
10729 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10730 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10733 = create_internal_breakpoint (caller_arch
, caller_pc
,
10734 bp_watchpoint_scope
,
10735 &momentary_breakpoint_ops
);
10737 /* create_internal_breakpoint could invalidate WP_FRAME. */
10740 scope_breakpoint
->enable_state
= bp_enabled
;
10742 /* Automatically delete the breakpoint when it hits. */
10743 scope_breakpoint
->disposition
= disp_del
;
10745 /* Only break in the proper frame (help with recursion). */
10746 scope_breakpoint
->frame_id
= caller_frame_id
;
10748 /* Set the address at which we will stop. */
10749 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10750 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10751 scope_breakpoint
->loc
->address
10752 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10753 scope_breakpoint
->loc
->requested_address
,
10754 scope_breakpoint
->type
);
10758 /* Now set up the breakpoint. We create all watchpoints as hardware
10759 watchpoints here even if hardware watchpoints are turned off, a call
10760 to update_watchpoint later in this function will cause the type to
10761 drop back to bp_watchpoint (software watchpoint) if required. */
10763 if (accessflag
== hw_read
)
10764 bp_type
= bp_read_watchpoint
;
10765 else if (accessflag
== hw_access
)
10766 bp_type
= bp_access_watchpoint
;
10768 bp_type
= bp_hardware_watchpoint
;
10770 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10773 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10774 &masked_watchpoint_breakpoint_ops
);
10776 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10777 &watchpoint_breakpoint_ops
);
10778 w
->thread
= thread
;
10779 w
->disposition
= disp_donttouch
;
10780 w
->pspace
= current_program_space
;
10781 w
->exp
= std::move (exp
);
10782 w
->exp_valid_block
= exp_valid_block
;
10783 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10786 struct type
*t
= value_type (val
.get ());
10787 CORE_ADDR addr
= value_as_address (val
.get ());
10789 w
->exp_string_reparse
10790 = current_language
->watch_location_expression (t
, addr
).release ();
10792 w
->exp_string
= xstrprintf ("-location %.*s",
10793 (int) (exp_end
- exp_start
), exp_start
);
10796 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10800 w
->hw_wp_mask
= mask
;
10805 w
->val_bitpos
= saved_bitpos
;
10806 w
->val_bitsize
= saved_bitsize
;
10807 w
->val_valid
= true;
10811 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10813 w
->cond_string
= 0;
10815 if (frame_id_p (watchpoint_frame
))
10817 w
->watchpoint_frame
= watchpoint_frame
;
10818 w
->watchpoint_thread
= inferior_ptid
;
10822 w
->watchpoint_frame
= null_frame_id
;
10823 w
->watchpoint_thread
= null_ptid
;
10826 if (scope_breakpoint
!= NULL
)
10828 /* The scope breakpoint is related to the watchpoint. We will
10829 need to act on them together. */
10830 w
->related_breakpoint
= scope_breakpoint
;
10831 scope_breakpoint
->related_breakpoint
= w
.get ();
10834 if (!just_location
)
10835 value_free_to_mark (mark
);
10837 /* Finally update the new watchpoint. This creates the locations
10838 that should be inserted. */
10839 update_watchpoint (w
.get (), 1);
10841 install_breakpoint (internal
, std::move (w
), 1);
10844 /* Return count of debug registers needed to watch the given expression.
10845 If the watchpoint cannot be handled in hardware return zero. */
10848 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10850 int found_memory_cnt
= 0;
10852 /* Did the user specifically forbid us to use hardware watchpoints? */
10853 if (!can_use_hw_watchpoints
)
10856 gdb_assert (!vals
.empty ());
10857 struct value
*head
= vals
[0].get ();
10859 /* Make sure that the value of the expression depends only upon
10860 memory contents, and values computed from them within GDB. If we
10861 find any register references or function calls, we can't use a
10862 hardware watchpoint.
10864 The idea here is that evaluating an expression generates a series
10865 of values, one holding the value of every subexpression. (The
10866 expression a*b+c has five subexpressions: a, b, a*b, c, and
10867 a*b+c.) GDB's values hold almost enough information to establish
10868 the criteria given above --- they identify memory lvalues,
10869 register lvalues, computed values, etcetera. So we can evaluate
10870 the expression, and then scan the chain of values that leaves
10871 behind to decide whether we can detect any possible change to the
10872 expression's final value using only hardware watchpoints.
10874 However, I don't think that the values returned by inferior
10875 function calls are special in any way. So this function may not
10876 notice that an expression involving an inferior function call
10877 can't be watched with hardware watchpoints. FIXME. */
10878 for (const value_ref_ptr
&iter
: vals
)
10880 struct value
*v
= iter
.get ();
10882 if (VALUE_LVAL (v
) == lval_memory
)
10884 if (v
!= head
&& value_lazy (v
))
10885 /* A lazy memory lvalue in the chain is one that GDB never
10886 needed to fetch; we either just used its address (e.g.,
10887 `a' in `a.b') or we never needed it at all (e.g., `a'
10888 in `a,b'). This doesn't apply to HEAD; if that is
10889 lazy then it was not readable, but watch it anyway. */
10893 /* Ahh, memory we actually used! Check if we can cover
10894 it with hardware watchpoints. */
10895 struct type
*vtype
= check_typedef (value_type (v
));
10897 /* We only watch structs and arrays if user asked for it
10898 explicitly, never if they just happen to appear in a
10899 middle of some value chain. */
10901 || (vtype
->code () != TYPE_CODE_STRUCT
10902 && vtype
->code () != TYPE_CODE_ARRAY
))
10904 CORE_ADDR vaddr
= value_address (v
);
10908 len
= (target_exact_watchpoints
10909 && is_scalar_type_recursive (vtype
))?
10910 1 : TYPE_LENGTH (value_type (v
));
10912 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10916 found_memory_cnt
+= num_regs
;
10920 else if (VALUE_LVAL (v
) != not_lval
10921 && deprecated_value_modifiable (v
) == 0)
10922 return 0; /* These are values from the history (e.g., $1). */
10923 else if (VALUE_LVAL (v
) == lval_register
)
10924 return 0; /* Cannot watch a register with a HW watchpoint. */
10927 /* The expression itself looks suitable for using a hardware
10928 watchpoint, but give the target machine a chance to reject it. */
10929 return found_memory_cnt
;
10933 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10935 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10938 /* Options for the watch, awatch, and rwatch commands. */
10940 struct watch_options
10942 /* For -location. */
10943 bool location
= false;
10946 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10948 Historically GDB always accepted both '-location' and '-l' flags for
10949 these commands (both flags being synonyms). When converting to the
10950 newer option scheme only '-location' is added here. That's fine (for
10951 backward compatibility) as any non-ambiguous prefix of a flag will be
10952 accepted, so '-l', '-loc', are now all accepted.
10954 What this means is that, if in the future, we add any new flag here
10955 that starts with '-l' then this will break backward compatibility, so
10956 please, don't do that! */
10958 static const gdb::option::option_def watch_option_defs
[] = {
10959 gdb::option::flag_option_def
<watch_options
> {
10961 [] (watch_options
*opt
) { return &opt
->location
; },
10963 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10964 -l can be used as a short form of -location."),
10968 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
10971 static gdb::option::option_def_group
10972 make_watch_options_def_group (watch_options
*opts
)
10974 return {{watch_option_defs
}, opts
};
10977 /* A helper function that looks for the "-location" argument and then
10978 calls watch_command_1. */
10981 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10983 watch_options opts
;
10984 auto grp
= make_watch_options_def_group (&opts
);
10985 gdb::option::process_options
10986 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
10987 if (arg
!= nullptr && *arg
== '\0')
10990 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
10993 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
10995 watch_command_completer (struct cmd_list_element
*ignore
,
10996 completion_tracker
&tracker
,
10997 const char *text
, const char * /*word*/)
10999 const auto group
= make_watch_options_def_group (nullptr);
11000 if (gdb::option::complete_options
11001 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
11004 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
11005 expression_completer (ignore
, tracker
, text
, word
);
11009 watch_command (const char *arg
, int from_tty
)
11011 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11015 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11017 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11021 rwatch_command (const char *arg
, int from_tty
)
11023 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11027 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11029 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11033 awatch_command (const char *arg
, int from_tty
)
11035 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11039 /* Data for the FSM that manages the until(location)/advance commands
11040 in infcmd.c. Here because it uses the mechanisms of
11043 struct until_break_fsm
: public thread_fsm
11045 /* The thread that was current when the command was executed. */
11048 /* The breakpoint set at the return address in the caller frame,
11049 plus breakpoints at all the destination locations. */
11050 std::vector
<breakpoint_up
> breakpoints
;
11052 until_break_fsm (struct interp
*cmd_interp
, int thread
,
11053 std::vector
<breakpoint_up
> &&breakpoints
)
11054 : thread_fsm (cmd_interp
),
11056 breakpoints (std::move (breakpoints
))
11060 void clean_up (struct thread_info
*thread
) override
;
11061 bool should_stop (struct thread_info
*thread
) override
;
11062 enum async_reply_reason
do_async_reply_reason () override
;
11065 /* Implementation of the 'should_stop' FSM method for the
11066 until(location)/advance commands. */
11069 until_break_fsm::should_stop (struct thread_info
*tp
)
11071 for (const breakpoint_up
&bp
: breakpoints
)
11072 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11073 bp
.get ()) != NULL
)
11082 /* Implementation of the 'clean_up' FSM method for the
11083 until(location)/advance commands. */
11086 until_break_fsm::clean_up (struct thread_info
*)
11088 /* Clean up our temporary breakpoints. */
11089 breakpoints
.clear ();
11090 delete_longjmp_breakpoint (thread
);
11093 /* Implementation of the 'async_reply_reason' FSM method for the
11094 until(location)/advance commands. */
11096 enum async_reply_reason
11097 until_break_fsm::do_async_reply_reason ()
11099 return EXEC_ASYNC_LOCATION_REACHED
;
11103 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11105 struct frame_info
*frame
;
11106 struct gdbarch
*frame_gdbarch
;
11107 struct frame_id stack_frame_id
;
11108 struct frame_id caller_frame_id
;
11110 struct thread_info
*tp
;
11112 clear_proceed_status (0);
11114 /* Set a breakpoint where the user wants it and at return from
11117 event_location_up location
= string_to_event_location (&arg
, current_language
);
11119 std::vector
<symtab_and_line
> sals
11120 = (last_displayed_sal_is_valid ()
11121 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11122 get_last_displayed_symtab (),
11123 get_last_displayed_line ())
11124 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11128 error (_("Couldn't get information on specified line."));
11131 error (_("Junk at end of arguments."));
11133 tp
= inferior_thread ();
11134 thread
= tp
->global_num
;
11136 /* Note linespec handling above invalidates the frame chain.
11137 Installing a breakpoint also invalidates the frame chain (as it
11138 may need to switch threads), so do any frame handling before
11141 frame
= get_selected_frame (NULL
);
11142 frame_gdbarch
= get_frame_arch (frame
);
11143 stack_frame_id
= get_stack_frame_id (frame
);
11144 caller_frame_id
= frame_unwind_caller_id (frame
);
11146 /* Keep within the current frame, or in frames called by the current
11149 std::vector
<breakpoint_up
> breakpoints
;
11151 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11153 if (frame_id_p (caller_frame_id
))
11155 struct symtab_and_line sal2
;
11156 struct gdbarch
*caller_gdbarch
;
11158 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11159 sal2
.pc
= frame_unwind_caller_pc (frame
);
11160 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11162 breakpoint_up caller_breakpoint
11163 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
11164 caller_frame_id
, bp_until
);
11165 breakpoints
.emplace_back (std::move (caller_breakpoint
));
11167 set_longjmp_breakpoint (tp
, caller_frame_id
);
11168 lj_deleter
.emplace (thread
);
11171 /* set_momentary_breakpoint could invalidate FRAME. */
11174 /* If the user told us to continue until a specified location, we
11175 don't specify a frame at which we need to stop. Otherwise,
11176 specify the selected frame, because we want to stop only at the
11177 very same frame. */
11178 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
11180 for (symtab_and_line
&sal
: sals
)
11182 resolve_sal_pc (&sal
);
11184 breakpoint_up location_breakpoint
11185 = set_momentary_breakpoint (frame_gdbarch
, sal
,
11186 stop_frame_id
, bp_until
);
11187 breakpoints
.emplace_back (std::move (location_breakpoint
));
11190 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11191 std::move (breakpoints
));
11194 lj_deleter
->release ();
11196 proceed (-1, GDB_SIGNAL_DEFAULT
);
11199 /* This function attempts to parse an optional "if <cond>" clause
11200 from the arg string. If one is not found, it returns NULL.
11202 Else, it returns a pointer to the condition string. (It does not
11203 attempt to evaluate the string against a particular block.) And,
11204 it updates arg to point to the first character following the parsed
11205 if clause in the arg string. */
11208 ep_parse_optional_if_clause (const char **arg
)
11210 const char *cond_string
;
11212 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11215 /* Skip the "if" keyword. */
11218 /* Skip any extra leading whitespace, and record the start of the
11219 condition string. */
11220 *arg
= skip_spaces (*arg
);
11221 cond_string
= *arg
;
11223 /* Assume that the condition occupies the remainder of the arg
11225 (*arg
) += strlen (cond_string
);
11227 return cond_string
;
11230 /* Commands to deal with catching events, such as signals, exceptions,
11231 process start/exit, etc. */
11235 catch_fork_temporary
, catch_vfork_temporary
,
11236 catch_fork_permanent
, catch_vfork_permanent
11241 catch_fork_command_1 (const char *arg
, int from_tty
,
11242 struct cmd_list_element
*command
)
11244 struct gdbarch
*gdbarch
= get_current_arch ();
11245 const char *cond_string
= NULL
;
11246 catch_fork_kind fork_kind
;
11248 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11249 bool temp
= (fork_kind
== catch_fork_temporary
11250 || fork_kind
== catch_vfork_temporary
);
11254 arg
= skip_spaces (arg
);
11256 /* The allowed syntax is:
11258 catch [v]fork if <cond>
11260 First, check if there's an if clause. */
11261 cond_string
= ep_parse_optional_if_clause (&arg
);
11263 if ((*arg
!= '\0') && !isspace (*arg
))
11264 error (_("Junk at end of arguments."));
11266 /* If this target supports it, create a fork or vfork catchpoint
11267 and enable reporting of such events. */
11270 case catch_fork_temporary
:
11271 case catch_fork_permanent
:
11272 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11273 &catch_fork_breakpoint_ops
);
11275 case catch_vfork_temporary
:
11276 case catch_vfork_permanent
:
11277 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11278 &catch_vfork_breakpoint_ops
);
11281 error (_("unsupported or unknown fork kind; cannot catch it"));
11287 catch_exec_command_1 (const char *arg
, int from_tty
,
11288 struct cmd_list_element
*command
)
11290 struct gdbarch
*gdbarch
= get_current_arch ();
11291 const char *cond_string
= NULL
;
11292 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11296 arg
= skip_spaces (arg
);
11298 /* The allowed syntax is:
11300 catch exec if <cond>
11302 First, check if there's an if clause. */
11303 cond_string
= ep_parse_optional_if_clause (&arg
);
11305 if ((*arg
!= '\0') && !isspace (*arg
))
11306 error (_("Junk at end of arguments."));
11308 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11309 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
,
11310 &catch_exec_breakpoint_ops
);
11311 c
->exec_pathname
= NULL
;
11313 install_breakpoint (0, std::move (c
), 1);
11317 init_ada_exception_breakpoint (struct breakpoint
*b
,
11318 struct gdbarch
*gdbarch
,
11319 struct symtab_and_line sal
,
11320 const char *addr_string
,
11321 const struct breakpoint_ops
*ops
,
11328 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11330 loc_gdbarch
= gdbarch
;
11332 describe_other_breakpoints (loc_gdbarch
,
11333 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11334 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11335 version for exception catchpoints, because two catchpoints
11336 used for different exception names will use the same address.
11337 In this case, a "breakpoint ... also set at..." warning is
11338 unproductive. Besides, the warning phrasing is also a bit
11339 inappropriate, we should use the word catchpoint, and tell
11340 the user what type of catchpoint it is. The above is good
11341 enough for now, though. */
11344 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11346 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11347 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11348 b
->location
= string_to_event_location (&addr_string
,
11349 language_def (language_ada
));
11350 b
->language
= language_ada
;
11355 /* Compare two breakpoints and return a strcmp-like result. */
11358 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11360 uintptr_t ua
= (uintptr_t) a
;
11361 uintptr_t ub
= (uintptr_t) b
;
11363 if (a
->number
< b
->number
)
11365 else if (a
->number
> b
->number
)
11368 /* Now sort by address, in case we see, e..g, two breakpoints with
11372 return ua
> ub
? 1 : 0;
11375 /* Delete breakpoints by address or line. */
11378 clear_command (const char *arg
, int from_tty
)
11382 std::vector
<symtab_and_line
> decoded_sals
;
11383 symtab_and_line last_sal
;
11384 gdb::array_view
<symtab_and_line
> sals
;
11388 = decode_line_with_current_source (arg
,
11389 (DECODE_LINE_FUNFIRSTLINE
11390 | DECODE_LINE_LIST_MODE
));
11392 sals
= decoded_sals
;
11396 /* Set sal's line, symtab, pc, and pspace to the values
11397 corresponding to the last call to print_frame_info. If the
11398 codepoint is not valid, this will set all the fields to 0. */
11399 last_sal
= get_last_displayed_sal ();
11400 if (last_sal
.symtab
== 0)
11401 error (_("No source file specified."));
11407 /* We don't call resolve_sal_pc here. That's not as bad as it
11408 seems, because all existing breakpoints typically have both
11409 file/line and pc set. So, if clear is given file/line, we can
11410 match this to existing breakpoint without obtaining pc at all.
11412 We only support clearing given the address explicitly
11413 present in breakpoint table. Say, we've set breakpoint
11414 at file:line. There were several PC values for that file:line,
11415 due to optimization, all in one block.
11417 We've picked one PC value. If "clear" is issued with another
11418 PC corresponding to the same file:line, the breakpoint won't
11419 be cleared. We probably can still clear the breakpoint, but
11420 since the other PC value is never presented to user, user
11421 can only find it by guessing, and it does not seem important
11422 to support that. */
11424 /* For each line spec given, delete bps which correspond to it. Do
11425 it in two passes, solely to preserve the current behavior that
11426 from_tty is forced true if we delete more than one
11429 std::vector
<struct breakpoint
*> found
;
11430 for (const auto &sal
: sals
)
11432 const char *sal_fullname
;
11434 /* If exact pc given, clear bpts at that pc.
11435 If line given (pc == 0), clear all bpts on specified line.
11436 If defaulting, clear all bpts on default line
11439 defaulting sal.pc != 0 tests to do
11444 1 0 <can't happen> */
11446 sal_fullname
= (sal
.symtab
== NULL
11447 ? NULL
: symtab_to_fullname (sal
.symtab
));
11449 /* Find all matching breakpoints and add them to 'found'. */
11450 for (breakpoint
*b
: all_breakpoints ())
11453 /* Are we going to delete b? */
11454 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11456 for (bp_location
*loc
: b
->locations ())
11458 /* If the user specified file:line, don't allow a PC
11459 match. This matches historical gdb behavior. */
11460 int pc_match
= (!sal
.explicit_line
11462 && (loc
->pspace
== sal
.pspace
)
11463 && (loc
->address
== sal
.pc
)
11464 && (!section_is_overlay (loc
->section
)
11465 || loc
->section
== sal
.section
));
11466 int line_match
= 0;
11468 if ((default_match
|| sal
.explicit_line
)
11469 && loc
->symtab
!= NULL
11470 && sal_fullname
!= NULL
11471 && sal
.pspace
== loc
->pspace
11472 && loc
->line_number
== sal
.line
11473 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11474 sal_fullname
) == 0)
11477 if (pc_match
|| line_match
)
11486 found
.push_back (b
);
11490 /* Now go thru the 'found' chain and delete them. */
11491 if (found
.empty ())
11494 error (_("No breakpoint at %s."), arg
);
11496 error (_("No breakpoint at this line."));
11499 /* Remove duplicates from the vec. */
11500 std::sort (found
.begin (), found
.end (),
11501 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11503 return compare_breakpoints (bp_a
, bp_b
) < 0;
11505 found
.erase (std::unique (found
.begin (), found
.end (),
11506 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11508 return compare_breakpoints (bp_a
, bp_b
) == 0;
11512 if (found
.size () > 1)
11513 from_tty
= 1; /* Always report if deleted more than one. */
11516 if (found
.size () == 1)
11517 printf_unfiltered (_("Deleted breakpoint "));
11519 printf_unfiltered (_("Deleted breakpoints "));
11522 for (breakpoint
*iter
: found
)
11525 printf_unfiltered ("%d ", iter
->number
);
11526 delete_breakpoint (iter
);
11529 putchar_unfiltered ('\n');
11532 /* Delete breakpoint in BS if they are `delete' breakpoints and
11533 all breakpoints that are marked for deletion, whether hit or not.
11534 This is called after any breakpoint is hit, or after errors. */
11537 breakpoint_auto_delete (bpstat bs
)
11539 for (; bs
; bs
= bs
->next
)
11540 if (bs
->breakpoint_at
11541 && bs
->breakpoint_at
->disposition
== disp_del
11543 delete_breakpoint (bs
->breakpoint_at
);
11545 for (breakpoint
*b
: all_breakpoints_safe ())
11546 if (b
->disposition
== disp_del_at_next_stop
)
11547 delete_breakpoint (b
);
11550 /* A comparison function for bp_location AP and BP being interfaced to
11551 std::sort. Sort elements primarily by their ADDRESS (no matter what
11552 bl_address_is_meaningful says), secondarily by ordering first
11553 permanent elements and terciarily just ensuring the array is sorted
11554 stable way despite std::sort being an unstable algorithm. */
11557 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11559 if (a
->address
!= b
->address
)
11560 return a
->address
< b
->address
;
11562 /* Sort locations at the same address by their pspace number, keeping
11563 locations of the same inferior (in a multi-inferior environment)
11566 if (a
->pspace
->num
!= b
->pspace
->num
)
11567 return a
->pspace
->num
< b
->pspace
->num
;
11569 /* Sort permanent breakpoints first. */
11570 if (a
->permanent
!= b
->permanent
)
11571 return a
->permanent
> b
->permanent
;
11573 /* Sort by type in order to make duplicate determination easier.
11574 See update_global_location_list. This is kept in sync with
11575 breakpoint_locations_match. */
11576 if (a
->loc_type
< b
->loc_type
)
11579 /* Likewise, for range-breakpoints, sort by length. */
11580 if (a
->loc_type
== bp_loc_hardware_breakpoint
11581 && b
->loc_type
== bp_loc_hardware_breakpoint
11582 && a
->length
< b
->length
)
11585 /* Make the internal GDB representation stable across GDB runs
11586 where A and B memory inside GDB can differ. Breakpoint locations of
11587 the same type at the same address can be sorted in arbitrary order. */
11589 if (a
->owner
->number
!= b
->owner
->number
)
11590 return a
->owner
->number
< b
->owner
->number
;
11595 /* Set bp_locations_placed_address_before_address_max and
11596 bp_locations_shadow_len_after_address_max according to the current
11597 content of the bp_locations array. */
11600 bp_locations_target_extensions_update (void)
11602 bp_locations_placed_address_before_address_max
= 0;
11603 bp_locations_shadow_len_after_address_max
= 0;
11605 for (bp_location
*bl
: all_bp_locations ())
11607 CORE_ADDR start
, end
, addr
;
11609 if (!bp_location_has_shadow (bl
))
11612 start
= bl
->target_info
.placed_address
;
11613 end
= start
+ bl
->target_info
.shadow_len
;
11615 gdb_assert (bl
->address
>= start
);
11616 addr
= bl
->address
- start
;
11617 if (addr
> bp_locations_placed_address_before_address_max
)
11618 bp_locations_placed_address_before_address_max
= addr
;
11620 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11622 gdb_assert (bl
->address
< end
);
11623 addr
= end
- bl
->address
;
11624 if (addr
> bp_locations_shadow_len_after_address_max
)
11625 bp_locations_shadow_len_after_address_max
= addr
;
11629 /* Download tracepoint locations if they haven't been. */
11632 download_tracepoint_locations (void)
11634 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11636 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11638 for (breakpoint
*b
: all_tracepoints ())
11640 struct tracepoint
*t
;
11641 int bp_location_downloaded
= 0;
11643 if ((b
->type
== bp_fast_tracepoint
11644 ? !may_insert_fast_tracepoints
11645 : !may_insert_tracepoints
))
11648 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11650 if (target_can_download_tracepoint ())
11651 can_download_tracepoint
= TRIBOOL_TRUE
;
11653 can_download_tracepoint
= TRIBOOL_FALSE
;
11656 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11659 for (bp_location
*bl
: b
->locations ())
11661 /* In tracepoint, locations are _never_ duplicated, so
11662 should_be_inserted is equivalent to
11663 unduplicated_should_be_inserted. */
11664 if (!should_be_inserted (bl
) || bl
->inserted
)
11667 switch_to_program_space_and_thread (bl
->pspace
);
11669 target_download_tracepoint (bl
);
11672 bp_location_downloaded
= 1;
11674 t
= (struct tracepoint
*) b
;
11675 t
->number_on_target
= b
->number
;
11676 if (bp_location_downloaded
)
11677 gdb::observers::breakpoint_modified
.notify (b
);
11681 /* Swap the insertion/duplication state between two locations. */
11684 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11686 const int left_inserted
= left
->inserted
;
11687 const int left_duplicate
= left
->duplicate
;
11688 const int left_needs_update
= left
->needs_update
;
11689 const struct bp_target_info left_target_info
= left
->target_info
;
11691 /* Locations of tracepoints can never be duplicated. */
11692 if (is_tracepoint (left
->owner
))
11693 gdb_assert (!left
->duplicate
);
11694 if (is_tracepoint (right
->owner
))
11695 gdb_assert (!right
->duplicate
);
11697 left
->inserted
= right
->inserted
;
11698 left
->duplicate
= right
->duplicate
;
11699 left
->needs_update
= right
->needs_update
;
11700 left
->target_info
= right
->target_info
;
11701 right
->inserted
= left_inserted
;
11702 right
->duplicate
= left_duplicate
;
11703 right
->needs_update
= left_needs_update
;
11704 right
->target_info
= left_target_info
;
11707 /* Force the re-insertion of the locations at ADDRESS. This is called
11708 once a new/deleted/modified duplicate location is found and we are evaluating
11709 conditions on the target's side. Such conditions need to be updated on
11713 force_breakpoint_reinsertion (struct bp_location
*bl
)
11715 CORE_ADDR address
= 0;
11718 address
= bl
->address
;
11719 pspace_num
= bl
->pspace
->num
;
11721 /* This is only meaningful if the target is
11722 evaluating conditions and if the user has
11723 opted for condition evaluation on the target's
11725 if (gdb_evaluates_breakpoint_condition_p ()
11726 || !target_supports_evaluation_of_breakpoint_conditions ())
11729 /* Flag all breakpoint locations with this address and
11730 the same program space as the location
11731 as "its condition has changed". We need to
11732 update the conditions on the target's side. */
11733 for (bp_location
*loc
: all_bp_locations_at_addr (address
))
11735 if (!is_breakpoint (loc
->owner
)
11736 || pspace_num
!= loc
->pspace
->num
)
11739 /* Flag the location appropriately. We use a different state to
11740 let everyone know that we already updated the set of locations
11741 with addr bl->address and program space bl->pspace. This is so
11742 we don't have to keep calling these functions just to mark locations
11743 that have already been marked. */
11744 loc
->condition_changed
= condition_updated
;
11746 /* Free the agent expression bytecode as well. We will compute
11748 loc
->cond_bytecode
.reset ();
11752 /* Called whether new breakpoints are created, or existing breakpoints
11753 deleted, to update the global location list and recompute which
11754 locations are duplicate of which.
11756 The INSERT_MODE flag determines whether locations may not, may, or
11757 shall be inserted now. See 'enum ugll_insert_mode' for more
11761 update_global_location_list (enum ugll_insert_mode insert_mode
)
11763 /* Last breakpoint location address that was marked for update. */
11764 CORE_ADDR last_addr
= 0;
11765 /* Last breakpoint location program space that was marked for update. */
11766 int last_pspace_num
= -1;
11768 /* Used in the duplicates detection below. When iterating over all
11769 bp_locations, points to the first bp_location of a given address.
11770 Breakpoints and watchpoints of different types are never
11771 duplicates of each other. Keep one pointer for each type of
11772 breakpoint/watchpoint, so we only need to loop over all locations
11774 struct bp_location
*bp_loc_first
; /* breakpoint */
11775 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11776 struct bp_location
*awp_loc_first
; /* access watchpoint */
11777 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11779 /* Saved former bp_locations array which we compare against the newly
11780 built bp_locations from the current state of ALL_BREAKPOINTS. */
11781 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
11782 bp_locations
.clear ();
11784 for (breakpoint
*b
: all_breakpoints ())
11785 for (bp_location
*loc
: b
->locations ())
11786 bp_locations
.push_back (loc
);
11788 /* See if we need to "upgrade" a software breakpoint to a hardware
11789 breakpoint. Do this before deciding whether locations are
11790 duplicates. Also do this before sorting because sorting order
11791 depends on location type. */
11792 for (bp_location
*loc
: bp_locations
)
11793 if (!loc
->inserted
&& should_be_inserted (loc
))
11794 handle_automatic_hardware_breakpoints (loc
);
11796 std::sort (bp_locations
.begin (), bp_locations
.end (),
11797 bp_location_is_less_than
);
11799 bp_locations_target_extensions_update ();
11801 /* Identify bp_location instances that are no longer present in the
11802 new list, and therefore should be freed. Note that it's not
11803 necessary that those locations should be removed from inferior --
11804 if there's another location at the same address (previously
11805 marked as duplicate), we don't need to remove/insert the
11808 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11809 and former bp_location array state respectively. */
11812 for (bp_location
*old_loc
: old_locations
)
11814 /* Tells if 'old_loc' is found among the new locations. If
11815 not, we have to free it. */
11816 int found_object
= 0;
11817 /* Tells if the location should remain inserted in the target. */
11818 int keep_in_target
= 0;
11821 /* Skip LOCP entries which will definitely never be needed.
11822 Stop either at or being the one matching OLD_LOC. */
11823 while (loc_i
< bp_locations
.size ()
11824 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11827 for (size_t loc2_i
= loc_i
;
11828 (loc2_i
< bp_locations
.size ()
11829 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11832 /* Check if this is a new/duplicated location or a duplicated
11833 location that had its condition modified. If so, we want to send
11834 its condition to the target if evaluation of conditions is taking
11836 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11837 && (last_addr
!= old_loc
->address
11838 || last_pspace_num
!= old_loc
->pspace
->num
))
11840 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11841 last_pspace_num
= old_loc
->pspace
->num
;
11844 if (bp_locations
[loc2_i
] == old_loc
)
11848 /* We have already handled this address, update it so that we don't
11849 have to go through updates again. */
11850 last_addr
= old_loc
->address
;
11852 /* Target-side condition evaluation: Handle deleted locations. */
11854 force_breakpoint_reinsertion (old_loc
);
11856 /* If this location is no longer present, and inserted, look if
11857 there's maybe a new location at the same address. If so,
11858 mark that one inserted, and don't remove this one. This is
11859 needed so that we don't have a time window where a breakpoint
11860 at certain location is not inserted. */
11862 if (old_loc
->inserted
)
11864 /* If the location is inserted now, we might have to remove
11867 if (found_object
&& should_be_inserted (old_loc
))
11869 /* The location is still present in the location list,
11870 and still should be inserted. Don't do anything. */
11871 keep_in_target
= 1;
11875 /* This location still exists, but it won't be kept in the
11876 target since it may have been disabled. We proceed to
11877 remove its target-side condition. */
11879 /* The location is either no longer present, or got
11880 disabled. See if there's another location at the
11881 same address, in which case we don't need to remove
11882 this one from the target. */
11884 /* OLD_LOC comes from existing struct breakpoint. */
11885 if (bl_address_is_meaningful (old_loc
))
11887 for (size_t loc2_i
= loc_i
;
11888 (loc2_i
< bp_locations
.size ()
11889 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11892 bp_location
*loc2
= bp_locations
[loc2_i
];
11894 if (loc2
== old_loc
)
11897 if (breakpoint_locations_match (loc2
, old_loc
))
11899 /* Read watchpoint locations are switched to
11900 access watchpoints, if the former are not
11901 supported, but the latter are. */
11902 if (is_hardware_watchpoint (old_loc
->owner
))
11904 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11905 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11908 /* loc2 is a duplicated location. We need to check
11909 if it should be inserted in case it will be
11911 if (unduplicated_should_be_inserted (loc2
))
11913 swap_insertion (old_loc
, loc2
);
11914 keep_in_target
= 1;
11922 if (!keep_in_target
)
11924 if (remove_breakpoint (old_loc
))
11926 /* This is just about all we can do. We could keep
11927 this location on the global list, and try to
11928 remove it next time, but there's no particular
11929 reason why we will succeed next time.
11931 Note that at this point, old_loc->owner is still
11932 valid, as delete_breakpoint frees the breakpoint
11933 only after calling us. */
11934 printf_filtered (_("warning: Error removing "
11935 "breakpoint %d\n"),
11936 old_loc
->owner
->number
);
11944 if (removed
&& target_is_non_stop_p ()
11945 && need_moribund_for_location_type (old_loc
))
11947 /* This location was removed from the target. In
11948 non-stop mode, a race condition is possible where
11949 we've removed a breakpoint, but stop events for that
11950 breakpoint are already queued and will arrive later.
11951 We apply an heuristic to be able to distinguish such
11952 SIGTRAPs from other random SIGTRAPs: we keep this
11953 breakpoint location for a bit, and will retire it
11954 after we see some number of events. The theory here
11955 is that reporting of events should, "on the average",
11956 be fair, so after a while we'll see events from all
11957 threads that have anything of interest, and no longer
11958 need to keep this breakpoint location around. We
11959 don't hold locations forever so to reduce chances of
11960 mistaking a non-breakpoint SIGTRAP for a breakpoint
11963 The heuristic failing can be disastrous on
11964 decr_pc_after_break targets.
11966 On decr_pc_after_break targets, like e.g., x86-linux,
11967 if we fail to recognize a late breakpoint SIGTRAP,
11968 because events_till_retirement has reached 0 too
11969 soon, we'll fail to do the PC adjustment, and report
11970 a random SIGTRAP to the user. When the user resumes
11971 the inferior, it will most likely immediately crash
11972 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11973 corrupted, because of being resumed e.g., in the
11974 middle of a multi-byte instruction, or skipped a
11975 one-byte instruction. This was actually seen happen
11976 on native x86-linux, and should be less rare on
11977 targets that do not support new thread events, like
11978 remote, due to the heuristic depending on
11981 Mistaking a random SIGTRAP for a breakpoint trap
11982 causes similar symptoms (PC adjustment applied when
11983 it shouldn't), but then again, playing with SIGTRAPs
11984 behind the debugger's back is asking for trouble.
11986 Since hardware watchpoint traps are always
11987 distinguishable from other traps, so we don't need to
11988 apply keep hardware watchpoint moribund locations
11989 around. We simply always ignore hardware watchpoint
11990 traps we can no longer explain. */
11992 process_stratum_target
*proc_target
= nullptr;
11993 for (inferior
*inf
: all_inferiors ())
11994 if (inf
->pspace
== old_loc
->pspace
)
11996 proc_target
= inf
->process_target ();
11999 if (proc_target
!= nullptr)
12000 old_loc
->events_till_retirement
12001 = 3 * (thread_count (proc_target
) + 1);
12003 old_loc
->events_till_retirement
= 1;
12004 old_loc
->owner
= NULL
;
12006 moribund_locations
.push_back (old_loc
);
12010 old_loc
->owner
= NULL
;
12011 decref_bp_location (&old_loc
);
12016 /* Rescan breakpoints at the same address and section, marking the
12017 first one as "first" and any others as "duplicates". This is so
12018 that the bpt instruction is only inserted once. If we have a
12019 permanent breakpoint at the same place as BPT, make that one the
12020 official one, and the rest as duplicates. Permanent breakpoints
12021 are sorted first for the same address.
12023 Do the same for hardware watchpoints, but also considering the
12024 watchpoint's type (regular/access/read) and length. */
12026 bp_loc_first
= NULL
;
12027 wp_loc_first
= NULL
;
12028 awp_loc_first
= NULL
;
12029 rwp_loc_first
= NULL
;
12031 for (bp_location
*loc
: all_bp_locations ())
12033 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12035 struct bp_location
**loc_first_p
;
12036 breakpoint
*b
= loc
->owner
;
12038 if (!unduplicated_should_be_inserted (loc
)
12039 || !bl_address_is_meaningful (loc
)
12040 /* Don't detect duplicate for tracepoint locations because they are
12041 never duplicated. See the comments in field `duplicate' of
12042 `struct bp_location'. */
12043 || is_tracepoint (b
))
12045 /* Clear the condition modification flag. */
12046 loc
->condition_changed
= condition_unchanged
;
12050 if (b
->type
== bp_hardware_watchpoint
)
12051 loc_first_p
= &wp_loc_first
;
12052 else if (b
->type
== bp_read_watchpoint
)
12053 loc_first_p
= &rwp_loc_first
;
12054 else if (b
->type
== bp_access_watchpoint
)
12055 loc_first_p
= &awp_loc_first
;
12057 loc_first_p
= &bp_loc_first
;
12059 if (*loc_first_p
== NULL
12060 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12061 || !breakpoint_locations_match (loc
, *loc_first_p
))
12063 *loc_first_p
= loc
;
12064 loc
->duplicate
= 0;
12066 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12068 loc
->needs_update
= 1;
12069 /* Clear the condition modification flag. */
12070 loc
->condition_changed
= condition_unchanged
;
12076 /* This and the above ensure the invariant that the first location
12077 is not duplicated, and is the inserted one.
12078 All following are marked as duplicated, and are not inserted. */
12080 swap_insertion (loc
, *loc_first_p
);
12081 loc
->duplicate
= 1;
12083 /* Clear the condition modification flag. */
12084 loc
->condition_changed
= condition_unchanged
;
12087 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12089 if (insert_mode
!= UGLL_DONT_INSERT
)
12090 insert_breakpoint_locations ();
12093 /* Even though the caller told us to not insert new
12094 locations, we may still need to update conditions on the
12095 target's side of breakpoints that were already inserted
12096 if the target is evaluating breakpoint conditions. We
12097 only update conditions for locations that are marked
12099 update_inserted_breakpoint_locations ();
12103 if (insert_mode
!= UGLL_DONT_INSERT
)
12104 download_tracepoint_locations ();
12108 breakpoint_retire_moribund (void)
12110 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
12112 struct bp_location
*loc
= moribund_locations
[ix
];
12113 if (--(loc
->events_till_retirement
) == 0)
12115 decref_bp_location (&loc
);
12116 unordered_remove (moribund_locations
, ix
);
12123 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12128 update_global_location_list (insert_mode
);
12130 catch (const gdb_exception_error
&e
)
12135 /* Clear BKP from a BPS. */
12138 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12142 for (bs
= bps
; bs
; bs
= bs
->next
)
12143 if (bs
->breakpoint_at
== bpt
)
12145 bs
->breakpoint_at
= NULL
;
12146 bs
->old_val
= NULL
;
12147 /* bs->commands will be freed later. */
12151 /* Callback for iterate_over_threads. */
12153 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12155 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12157 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12161 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12165 say_where (struct breakpoint
*b
)
12167 struct value_print_options opts
;
12169 get_user_print_options (&opts
);
12171 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12173 if (b
->loc
== NULL
)
12175 /* For pending locations, the output differs slightly based
12176 on b->extra_string. If this is non-NULL, it contains either
12177 a condition or dprintf arguments. */
12178 if (b
->extra_string
== NULL
)
12180 printf_filtered (_(" (%s) pending."),
12181 event_location_to_string (b
->location
.get ()));
12183 else if (b
->type
== bp_dprintf
)
12185 printf_filtered (_(" (%s,%s) pending."),
12186 event_location_to_string (b
->location
.get ()),
12191 printf_filtered (_(" (%s %s) pending."),
12192 event_location_to_string (b
->location
.get ()),
12198 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12199 printf_filtered (" at %ps",
12200 styled_string (address_style
.style (),
12201 paddress (b
->loc
->gdbarch
,
12202 b
->loc
->address
)));
12203 if (b
->loc
->symtab
!= NULL
)
12205 /* If there is a single location, we can print the location
12207 if (b
->loc
->next
== NULL
)
12209 const char *filename
12210 = symtab_to_filename_for_display (b
->loc
->symtab
);
12211 printf_filtered (": file %ps, line %d.",
12212 styled_string (file_name_style
.style (),
12214 b
->loc
->line_number
);
12217 /* This is not ideal, but each location may have a
12218 different file name, and this at least reflects the
12219 real situation somewhat. */
12220 printf_filtered (": %s.",
12221 event_location_to_string (b
->location
.get ()));
12226 struct bp_location
*loc
= b
->loc
;
12228 for (; loc
; loc
= loc
->next
)
12230 printf_filtered (" (%d locations)", n
);
12235 bp_location::~bp_location ()
12237 xfree (function_name
);
12240 /* Destructor for the breakpoint base class. */
12242 breakpoint::~breakpoint ()
12244 xfree (this->cond_string
);
12245 xfree (this->extra_string
);
12248 /* See breakpoint.h. */
12250 bp_locations_range
breakpoint::locations ()
12252 return bp_locations_range (this->loc
);
12255 static struct bp_location
*
12256 base_breakpoint_allocate_location (struct breakpoint
*self
)
12258 return new bp_location (self
);
12262 base_breakpoint_re_set (struct breakpoint
*b
)
12264 /* Nothing to re-set. */
12267 #define internal_error_pure_virtual_called() \
12268 gdb_assert_not_reached ("pure virtual function called")
12271 base_breakpoint_insert_location (struct bp_location
*bl
)
12273 internal_error_pure_virtual_called ();
12277 base_breakpoint_remove_location (struct bp_location
*bl
,
12278 enum remove_bp_reason reason
)
12280 internal_error_pure_virtual_called ();
12284 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12285 const address_space
*aspace
,
12287 const struct target_waitstatus
*ws
)
12289 internal_error_pure_virtual_called ();
12293 base_breakpoint_check_status (bpstat bs
)
12298 /* A "works_in_software_mode" breakpoint_ops method that just internal
12302 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12304 internal_error_pure_virtual_called ();
12307 /* A "resources_needed" breakpoint_ops method that just internal
12311 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12313 internal_error_pure_virtual_called ();
12316 static enum print_stop_action
12317 base_breakpoint_print_it (bpstat bs
)
12319 internal_error_pure_virtual_called ();
12323 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12324 struct ui_out
*uiout
)
12330 base_breakpoint_print_mention (struct breakpoint
*b
)
12332 internal_error_pure_virtual_called ();
12336 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12338 internal_error_pure_virtual_called ();
12342 base_breakpoint_create_sals_from_location
12343 (struct event_location
*location
,
12344 struct linespec_result
*canonical
,
12345 enum bptype type_wanted
)
12347 internal_error_pure_virtual_called ();
12351 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12352 struct linespec_result
*c
,
12353 gdb::unique_xmalloc_ptr
<char> cond_string
,
12354 gdb::unique_xmalloc_ptr
<char> extra_string
,
12355 enum bptype type_wanted
,
12356 enum bpdisp disposition
,
12358 int task
, int ignore_count
,
12359 const struct breakpoint_ops
*o
,
12360 int from_tty
, int enabled
,
12361 int internal
, unsigned flags
)
12363 internal_error_pure_virtual_called ();
12366 static std::vector
<symtab_and_line
>
12367 base_breakpoint_decode_location (struct breakpoint
*b
,
12368 struct event_location
*location
,
12369 struct program_space
*search_pspace
)
12371 internal_error_pure_virtual_called ();
12374 /* The default 'explains_signal' method. */
12377 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12382 /* The default "after_condition_true" method. */
12385 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12387 /* Nothing to do. */
12390 struct breakpoint_ops base_breakpoint_ops
=
12392 base_breakpoint_allocate_location
,
12393 base_breakpoint_re_set
,
12394 base_breakpoint_insert_location
,
12395 base_breakpoint_remove_location
,
12396 base_breakpoint_breakpoint_hit
,
12397 base_breakpoint_check_status
,
12398 base_breakpoint_resources_needed
,
12399 base_breakpoint_works_in_software_mode
,
12400 base_breakpoint_print_it
,
12402 base_breakpoint_print_one_detail
,
12403 base_breakpoint_print_mention
,
12404 base_breakpoint_print_recreate
,
12405 base_breakpoint_create_sals_from_location
,
12406 base_breakpoint_create_breakpoints_sal
,
12407 base_breakpoint_decode_location
,
12408 base_breakpoint_explains_signal
,
12409 base_breakpoint_after_condition_true
,
12412 /* Default breakpoint_ops methods. */
12415 bkpt_re_set (struct breakpoint
*b
)
12417 /* FIXME: is this still reachable? */
12418 if (breakpoint_event_location_empty_p (b
))
12420 /* Anything without a location can't be re-set. */
12421 delete_breakpoint (b
);
12425 breakpoint_re_set_default (b
);
12429 bkpt_insert_location (struct bp_location
*bl
)
12431 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12433 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12434 bl
->target_info
.placed_address
= addr
;
12436 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12437 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12439 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12443 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12445 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12446 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12448 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12452 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12453 const address_space
*aspace
, CORE_ADDR bp_addr
,
12454 const struct target_waitstatus
*ws
)
12456 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12457 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12460 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12464 if (overlay_debugging
/* unmapped overlay section */
12465 && section_is_overlay (bl
->section
)
12466 && !section_is_mapped (bl
->section
))
12473 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12474 const address_space
*aspace
, CORE_ADDR bp_addr
,
12475 const struct target_waitstatus
*ws
)
12477 if (dprintf_style
== dprintf_style_agent
12478 && target_can_run_breakpoint_commands ())
12480 /* An agent-style dprintf never causes a stop. If we see a trap
12481 for this address it must be for a breakpoint that happens to
12482 be set at the same address. */
12486 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12490 bkpt_resources_needed (const struct bp_location
*bl
)
12492 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12497 static enum print_stop_action
12498 bkpt_print_it (bpstat bs
)
12500 struct breakpoint
*b
;
12501 const struct bp_location
*bl
;
12503 struct ui_out
*uiout
= current_uiout
;
12505 gdb_assert (bs
->bp_location_at
!= NULL
);
12507 bl
= bs
->bp_location_at
.get ();
12508 b
= bs
->breakpoint_at
;
12510 bp_temp
= b
->disposition
== disp_del
;
12511 if (bl
->address
!= bl
->requested_address
)
12512 breakpoint_adjustment_warning (bl
->requested_address
,
12515 annotate_breakpoint (b
->number
);
12516 maybe_print_thread_hit_breakpoint (uiout
);
12518 if (uiout
->is_mi_like_p ())
12520 uiout
->field_string ("reason",
12521 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12522 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12525 uiout
->message ("Temporary breakpoint %pF, ",
12526 signed_field ("bkptno", b
->number
));
12528 uiout
->message ("Breakpoint %pF, ",
12529 signed_field ("bkptno", b
->number
));
12531 return PRINT_SRC_AND_LOC
;
12535 bkpt_print_mention (struct breakpoint
*b
)
12537 if (current_uiout
->is_mi_like_p ())
12542 case bp_breakpoint
:
12543 case bp_gnu_ifunc_resolver
:
12544 if (b
->disposition
== disp_del
)
12545 printf_filtered (_("Temporary breakpoint"));
12547 printf_filtered (_("Breakpoint"));
12548 printf_filtered (_(" %d"), b
->number
);
12549 if (b
->type
== bp_gnu_ifunc_resolver
)
12550 printf_filtered (_(" at gnu-indirect-function resolver"));
12552 case bp_hardware_breakpoint
:
12553 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12556 printf_filtered (_("Dprintf %d"), b
->number
);
12564 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12566 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12567 fprintf_unfiltered (fp
, "tbreak");
12568 else if (tp
->type
== bp_breakpoint
)
12569 fprintf_unfiltered (fp
, "break");
12570 else if (tp
->type
== bp_hardware_breakpoint
12571 && tp
->disposition
== disp_del
)
12572 fprintf_unfiltered (fp
, "thbreak");
12573 else if (tp
->type
== bp_hardware_breakpoint
)
12574 fprintf_unfiltered (fp
, "hbreak");
12576 internal_error (__FILE__
, __LINE__
,
12577 _("unhandled breakpoint type %d"), (int) tp
->type
);
12579 fprintf_unfiltered (fp
, " %s",
12580 event_location_to_string (tp
->location
.get ()));
12582 /* Print out extra_string if this breakpoint is pending. It might
12583 contain, for example, conditions that were set by the user. */
12584 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12585 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12587 print_recreate_thread (tp
, fp
);
12591 bkpt_create_sals_from_location (struct event_location
*location
,
12592 struct linespec_result
*canonical
,
12593 enum bptype type_wanted
)
12595 create_sals_from_location_default (location
, canonical
, type_wanted
);
12599 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12600 struct linespec_result
*canonical
,
12601 gdb::unique_xmalloc_ptr
<char> cond_string
,
12602 gdb::unique_xmalloc_ptr
<char> extra_string
,
12603 enum bptype type_wanted
,
12604 enum bpdisp disposition
,
12606 int task
, int ignore_count
,
12607 const struct breakpoint_ops
*ops
,
12608 int from_tty
, int enabled
,
12609 int internal
, unsigned flags
)
12611 create_breakpoints_sal_default (gdbarch
, canonical
,
12612 std::move (cond_string
),
12613 std::move (extra_string
),
12615 disposition
, thread
, task
,
12616 ignore_count
, ops
, from_tty
,
12617 enabled
, internal
, flags
);
12620 static std::vector
<symtab_and_line
>
12621 bkpt_decode_location (struct breakpoint
*b
,
12622 struct event_location
*location
,
12623 struct program_space
*search_pspace
)
12625 return decode_location_default (b
, location
, search_pspace
);
12628 /* Virtual table for internal breakpoints. */
12631 internal_bkpt_re_set (struct breakpoint
*b
)
12635 /* Delete overlay event and longjmp master breakpoints; they
12636 will be reset later by breakpoint_re_set. */
12637 case bp_overlay_event
:
12638 case bp_longjmp_master
:
12639 case bp_std_terminate_master
:
12640 case bp_exception_master
:
12641 delete_breakpoint (b
);
12644 /* This breakpoint is special, it's set up when the inferior
12645 starts and we really don't want to touch it. */
12646 case bp_shlib_event
:
12648 /* Like bp_shlib_event, this breakpoint type is special. Once
12649 it is set up, we do not want to touch it. */
12650 case bp_thread_event
:
12656 internal_bkpt_check_status (bpstat bs
)
12658 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12660 /* If requested, stop when the dynamic linker notifies GDB of
12661 events. This allows the user to get control and place
12662 breakpoints in initializer routines for dynamically loaded
12663 objects (among other things). */
12664 bs
->stop
= stop_on_solib_events
;
12665 bs
->print
= stop_on_solib_events
;
12671 static enum print_stop_action
12672 internal_bkpt_print_it (bpstat bs
)
12674 struct breakpoint
*b
;
12676 b
= bs
->breakpoint_at
;
12680 case bp_shlib_event
:
12681 /* Did we stop because the user set the stop_on_solib_events
12682 variable? (If so, we report this as a generic, "Stopped due
12683 to shlib event" message.) */
12684 print_solib_event (0);
12687 case bp_thread_event
:
12688 /* Not sure how we will get here.
12689 GDB should not stop for these breakpoints. */
12690 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12693 case bp_overlay_event
:
12694 /* By analogy with the thread event, GDB should not stop for these. */
12695 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12698 case bp_longjmp_master
:
12699 /* These should never be enabled. */
12700 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12703 case bp_std_terminate_master
:
12704 /* These should never be enabled. */
12705 printf_filtered (_("std::terminate Master Breakpoint: "
12706 "gdb should not stop!\n"));
12709 case bp_exception_master
:
12710 /* These should never be enabled. */
12711 printf_filtered (_("Exception Master Breakpoint: "
12712 "gdb should not stop!\n"));
12716 return PRINT_NOTHING
;
12720 internal_bkpt_print_mention (struct breakpoint
*b
)
12722 /* Nothing to mention. These breakpoints are internal. */
12725 /* Virtual table for momentary breakpoints */
12728 momentary_bkpt_re_set (struct breakpoint
*b
)
12730 /* Keep temporary breakpoints, which can be encountered when we step
12731 over a dlopen call and solib_add is resetting the breakpoints.
12732 Otherwise these should have been blown away via the cleanup chain
12733 or by breakpoint_init_inferior when we rerun the executable. */
12737 momentary_bkpt_check_status (bpstat bs
)
12739 /* Nothing. The point of these breakpoints is causing a stop. */
12742 static enum print_stop_action
12743 momentary_bkpt_print_it (bpstat bs
)
12745 return PRINT_UNKNOWN
;
12749 momentary_bkpt_print_mention (struct breakpoint
*b
)
12751 /* Nothing to mention. These breakpoints are internal. */
12754 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12756 It gets cleared already on the removal of the first one of such placed
12757 breakpoints. This is OK as they get all removed altogether. */
12759 longjmp_breakpoint::~longjmp_breakpoint ()
12761 thread_info
*tp
= find_thread_global_id (this->thread
);
12764 tp
->initiating_frame
= null_frame_id
;
12767 /* Specific methods for probe breakpoints. */
12770 bkpt_probe_insert_location (struct bp_location
*bl
)
12772 int v
= bkpt_insert_location (bl
);
12776 /* The insertion was successful, now let's set the probe's semaphore
12778 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12785 bkpt_probe_remove_location (struct bp_location
*bl
,
12786 enum remove_bp_reason reason
)
12788 /* Let's clear the semaphore before removing the location. */
12789 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12791 return bkpt_remove_location (bl
, reason
);
12795 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12796 struct linespec_result
*canonical
,
12797 enum bptype type_wanted
)
12799 struct linespec_sals lsal
;
12801 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12803 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12804 canonical
->lsals
.push_back (std::move (lsal
));
12807 static std::vector
<symtab_and_line
>
12808 bkpt_probe_decode_location (struct breakpoint
*b
,
12809 struct event_location
*location
,
12810 struct program_space
*search_pspace
)
12812 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12814 error (_("probe not found"));
12818 /* The breakpoint_ops structure to be used in tracepoints. */
12821 tracepoint_re_set (struct breakpoint
*b
)
12823 breakpoint_re_set_default (b
);
12827 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12828 const address_space
*aspace
, CORE_ADDR bp_addr
,
12829 const struct target_waitstatus
*ws
)
12831 /* By definition, the inferior does not report stops at
12837 tracepoint_print_one_detail (const struct breakpoint
*self
,
12838 struct ui_out
*uiout
)
12840 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12841 if (!tp
->static_trace_marker_id
.empty ())
12843 gdb_assert (self
->type
== bp_static_tracepoint
);
12845 uiout
->message ("\tmarker id is %pF\n",
12846 string_field ("static-tracepoint-marker-string-id",
12847 tp
->static_trace_marker_id
.c_str ()));
12852 tracepoint_print_mention (struct breakpoint
*b
)
12854 if (current_uiout
->is_mi_like_p ())
12859 case bp_tracepoint
:
12860 printf_filtered (_("Tracepoint"));
12861 printf_filtered (_(" %d"), b
->number
);
12863 case bp_fast_tracepoint
:
12864 printf_filtered (_("Fast tracepoint"));
12865 printf_filtered (_(" %d"), b
->number
);
12867 case bp_static_tracepoint
:
12868 printf_filtered (_("Static tracepoint"));
12869 printf_filtered (_(" %d"), b
->number
);
12872 internal_error (__FILE__
, __LINE__
,
12873 _("unhandled tracepoint type %d"), (int) b
->type
);
12880 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12882 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12884 if (self
->type
== bp_fast_tracepoint
)
12885 fprintf_unfiltered (fp
, "ftrace");
12886 else if (self
->type
== bp_static_tracepoint
)
12887 fprintf_unfiltered (fp
, "strace");
12888 else if (self
->type
== bp_tracepoint
)
12889 fprintf_unfiltered (fp
, "trace");
12891 internal_error (__FILE__
, __LINE__
,
12892 _("unhandled tracepoint type %d"), (int) self
->type
);
12894 fprintf_unfiltered (fp
, " %s",
12895 event_location_to_string (self
->location
.get ()));
12896 print_recreate_thread (self
, fp
);
12898 if (tp
->pass_count
)
12899 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12903 tracepoint_create_sals_from_location (struct event_location
*location
,
12904 struct linespec_result
*canonical
,
12905 enum bptype type_wanted
)
12907 create_sals_from_location_default (location
, canonical
, type_wanted
);
12911 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12912 struct linespec_result
*canonical
,
12913 gdb::unique_xmalloc_ptr
<char> cond_string
,
12914 gdb::unique_xmalloc_ptr
<char> extra_string
,
12915 enum bptype type_wanted
,
12916 enum bpdisp disposition
,
12918 int task
, int ignore_count
,
12919 const struct breakpoint_ops
*ops
,
12920 int from_tty
, int enabled
,
12921 int internal
, unsigned flags
)
12923 create_breakpoints_sal_default (gdbarch
, canonical
,
12924 std::move (cond_string
),
12925 std::move (extra_string
),
12927 disposition
, thread
, task
,
12928 ignore_count
, ops
, from_tty
,
12929 enabled
, internal
, flags
);
12932 static std::vector
<symtab_and_line
>
12933 tracepoint_decode_location (struct breakpoint
*b
,
12934 struct event_location
*location
,
12935 struct program_space
*search_pspace
)
12937 return decode_location_default (b
, location
, search_pspace
);
12940 struct breakpoint_ops tracepoint_breakpoint_ops
;
12942 /* Virtual table for tracepoints on static probes. */
12945 tracepoint_probe_create_sals_from_location
12946 (struct event_location
*location
,
12947 struct linespec_result
*canonical
,
12948 enum bptype type_wanted
)
12950 /* We use the same method for breakpoint on probes. */
12951 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
12954 static std::vector
<symtab_and_line
>
12955 tracepoint_probe_decode_location (struct breakpoint
*b
,
12956 struct event_location
*location
,
12957 struct program_space
*search_pspace
)
12959 /* We use the same method for breakpoint on probes. */
12960 return bkpt_probe_decode_location (b
, location
, search_pspace
);
12963 /* Dprintf breakpoint_ops methods. */
12966 dprintf_re_set (struct breakpoint
*b
)
12968 breakpoint_re_set_default (b
);
12970 /* extra_string should never be non-NULL for dprintf. */
12971 gdb_assert (b
->extra_string
!= NULL
);
12973 /* 1 - connect to target 1, that can run breakpoint commands.
12974 2 - create a dprintf, which resolves fine.
12975 3 - disconnect from target 1
12976 4 - connect to target 2, that can NOT run breakpoint commands.
12978 After steps #3/#4, you'll want the dprintf command list to
12979 be updated, because target 1 and 2 may well return different
12980 answers for target_can_run_breakpoint_commands().
12981 Given absence of finer grained resetting, we get to do
12982 it all the time. */
12983 if (b
->extra_string
!= NULL
)
12984 update_dprintf_command_list (b
);
12987 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
12990 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12992 fprintf_unfiltered (fp
, "dprintf %s,%s",
12993 event_location_to_string (tp
->location
.get ()),
12995 print_recreate_thread (tp
, fp
);
12998 /* Implement the "after_condition_true" breakpoint_ops method for
13001 dprintf's are implemented with regular commands in their command
13002 list, but we run the commands here instead of before presenting the
13003 stop to the user, as dprintf's don't actually cause a stop. This
13004 also makes it so that the commands of multiple dprintfs at the same
13005 address are all handled. */
13008 dprintf_after_condition_true (struct bpstats
*bs
)
13010 struct bpstats tmp_bs
;
13011 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13013 /* dprintf's never cause a stop. This wasn't set in the
13014 check_status hook instead because that would make the dprintf's
13015 condition not be evaluated. */
13018 /* Run the command list here. Take ownership of it instead of
13019 copying. We never want these commands to run later in
13020 bpstat_do_actions, if a breakpoint that causes a stop happens to
13021 be set at same address as this dprintf, or even if running the
13022 commands here throws. */
13023 tmp_bs
.commands
= bs
->commands
;
13024 bs
->commands
= NULL
;
13026 bpstat_do_actions_1 (&tmp_bs_p
);
13028 /* 'tmp_bs.commands' will usually be NULL by now, but
13029 bpstat_do_actions_1 may return early without processing the whole
13033 /* The breakpoint_ops structure to be used on static tracepoints with
13037 strace_marker_create_sals_from_location (struct event_location
*location
,
13038 struct linespec_result
*canonical
,
13039 enum bptype type_wanted
)
13041 struct linespec_sals lsal
;
13042 const char *arg_start
, *arg
;
13044 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
13045 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13047 std::string
str (arg_start
, arg
- arg_start
);
13048 const char *ptr
= str
.c_str ();
13049 canonical
->location
13050 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
13053 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13054 canonical
->lsals
.push_back (std::move (lsal
));
13058 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13059 struct linespec_result
*canonical
,
13060 gdb::unique_xmalloc_ptr
<char> cond_string
,
13061 gdb::unique_xmalloc_ptr
<char> extra_string
,
13062 enum bptype type_wanted
,
13063 enum bpdisp disposition
,
13065 int task
, int ignore_count
,
13066 const struct breakpoint_ops
*ops
,
13067 int from_tty
, int enabled
,
13068 int internal
, unsigned flags
)
13070 const linespec_sals
&lsal
= canonical
->lsals
[0];
13072 /* If the user is creating a static tracepoint by marker id
13073 (strace -m MARKER_ID), then store the sals index, so that
13074 breakpoint_re_set can try to match up which of the newly
13075 found markers corresponds to this one, and, don't try to
13076 expand multiple locations for each sal, given than SALS
13077 already should contain all sals for MARKER_ID. */
13079 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13081 event_location_up location
13082 = copy_event_location (canonical
->location
.get ());
13084 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13085 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13086 std::move (location
), NULL
,
13087 std::move (cond_string
),
13088 std::move (extra_string
),
13089 type_wanted
, disposition
,
13090 thread
, task
, ignore_count
, ops
,
13091 from_tty
, enabled
, internal
, flags
,
13092 canonical
->special_display
);
13093 /* Given that its possible to have multiple markers with
13094 the same string id, if the user is creating a static
13095 tracepoint by marker id ("strace -m MARKER_ID"), then
13096 store the sals index, so that breakpoint_re_set can
13097 try to match up which of the newly found markers
13098 corresponds to this one */
13099 tp
->static_trace_marker_id_idx
= i
;
13101 install_breakpoint (internal
, std::move (tp
), 0);
13105 static std::vector
<symtab_and_line
>
13106 strace_marker_decode_location (struct breakpoint
*b
,
13107 struct event_location
*location
,
13108 struct program_space
*search_pspace
)
13110 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13111 const char *s
= get_linespec_location (location
)->spec_string
;
13113 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13114 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13116 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13121 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
13124 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13127 strace_marker_p (struct breakpoint
*b
)
13129 return b
->ops
== &strace_marker_breakpoint_ops
;
13132 /* Delete a breakpoint and clean up all traces of it in the data
13136 delete_breakpoint (struct breakpoint
*bpt
)
13138 gdb_assert (bpt
!= NULL
);
13140 /* Has this bp already been deleted? This can happen because
13141 multiple lists can hold pointers to bp's. bpstat lists are
13144 One example of this happening is a watchpoint's scope bp. When
13145 the scope bp triggers, we notice that the watchpoint is out of
13146 scope, and delete it. We also delete its scope bp. But the
13147 scope bp is marked "auto-deleting", and is already on a bpstat.
13148 That bpstat is then checked for auto-deleting bp's, which are
13151 A real solution to this problem might involve reference counts in
13152 bp's, and/or giving them pointers back to their referencing
13153 bpstat's, and teaching delete_breakpoint to only free a bp's
13154 storage when no more references were extent. A cheaper bandaid
13156 if (bpt
->type
== bp_none
)
13159 /* At least avoid this stale reference until the reference counting
13160 of breakpoints gets resolved. */
13161 if (bpt
->related_breakpoint
!= bpt
)
13163 struct breakpoint
*related
;
13164 struct watchpoint
*w
;
13166 if (bpt
->type
== bp_watchpoint_scope
)
13167 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13168 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13169 w
= (struct watchpoint
*) bpt
;
13173 watchpoint_del_at_next_stop (w
);
13175 /* Unlink bpt from the bpt->related_breakpoint ring. */
13176 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13177 related
= related
->related_breakpoint
);
13178 related
->related_breakpoint
= bpt
->related_breakpoint
;
13179 bpt
->related_breakpoint
= bpt
;
13182 /* watch_command_1 creates a watchpoint but only sets its number if
13183 update_watchpoint succeeds in creating its bp_locations. If there's
13184 a problem in that process, we'll be asked to delete the half-created
13185 watchpoint. In that case, don't announce the deletion. */
13187 gdb::observers::breakpoint_deleted
.notify (bpt
);
13189 if (breakpoint_chain
== bpt
)
13190 breakpoint_chain
= bpt
->next
;
13192 for (breakpoint
*b
: all_breakpoints ())
13193 if (b
->next
== bpt
)
13195 b
->next
= bpt
->next
;
13199 /* Be sure no bpstat's are pointing at the breakpoint after it's
13201 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13202 in all threads for now. Note that we cannot just remove bpstats
13203 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13204 commands are associated with the bpstat; if we remove it here,
13205 then the later call to bpstat_do_actions (&stop_bpstat); in
13206 event-top.c won't do anything, and temporary breakpoints with
13207 commands won't work. */
13209 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13211 /* Now that breakpoint is removed from breakpoint list, update the
13212 global location list. This will remove locations that used to
13213 belong to this breakpoint. Do this before freeing the breakpoint
13214 itself, since remove_breakpoint looks at location's owner. It
13215 might be better design to have location completely
13216 self-contained, but it's not the case now. */
13217 update_global_location_list (UGLL_DONT_INSERT
);
13219 /* On the chance that someone will soon try again to delete this
13220 same bp, we mark it as deleted before freeing its storage. */
13221 bpt
->type
= bp_none
;
13225 /* Iterator function to call a user-provided callback function once
13226 for each of B and its related breakpoints. */
13229 iterate_over_related_breakpoints (struct breakpoint
*b
,
13230 gdb::function_view
<void (breakpoint
*)> function
)
13232 struct breakpoint
*related
;
13237 struct breakpoint
*next
;
13239 /* FUNCTION may delete RELATED. */
13240 next
= related
->related_breakpoint
;
13242 if (next
== related
)
13244 /* RELATED is the last ring entry. */
13245 function (related
);
13247 /* FUNCTION may have deleted it, so we'd never reach back to
13248 B. There's nothing left to do anyway, so just break
13253 function (related
);
13257 while (related
!= b
);
13261 delete_command (const char *arg
, int from_tty
)
13267 int breaks_to_delete
= 0;
13269 /* Delete all breakpoints if no argument. Do not delete
13270 internal breakpoints, these have to be deleted with an
13271 explicit breakpoint number argument. */
13272 for (breakpoint
*b
: all_breakpoints ())
13273 if (user_breakpoint_p (b
))
13275 breaks_to_delete
= 1;
13279 /* Ask user only if there are some breakpoints to delete. */
13281 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13282 for (breakpoint
*b
: all_breakpoints_safe ())
13283 if (user_breakpoint_p (b
))
13284 delete_breakpoint (b
);
13287 map_breakpoint_numbers
13288 (arg
, [&] (breakpoint
*br
)
13290 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13294 /* Return true if all locations of B bound to PSPACE are pending. If
13295 PSPACE is NULL, all locations of all program spaces are
13299 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13301 for (bp_location
*loc
: b
->locations ())
13302 if ((pspace
== NULL
13303 || loc
->pspace
== pspace
)
13304 && !loc
->shlib_disabled
13305 && !loc
->pspace
->executing_startup
)
13310 /* Subroutine of update_breakpoint_locations to simplify it.
13311 Return non-zero if multiple fns in list LOC have the same name.
13312 Null names are ignored. */
13315 ambiguous_names_p (struct bp_location
*loc
)
13317 struct bp_location
*l
;
13318 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
13321 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13324 const char *name
= l
->function_name
;
13326 /* Allow for some names to be NULL, ignore them. */
13330 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
13332 /* NOTE: We can assume slot != NULL here because xcalloc never
13342 /* When symbols change, it probably means the sources changed as well,
13343 and it might mean the static tracepoint markers are no longer at
13344 the same address or line numbers they used to be at last we
13345 checked. Losing your static tracepoints whenever you rebuild is
13346 undesirable. This function tries to resync/rematch gdb static
13347 tracepoints with the markers on the target, for static tracepoints
13348 that have not been set by marker id. Static tracepoint that have
13349 been set by marker id are reset by marker id in breakpoint_re_set.
13352 1) For a tracepoint set at a specific address, look for a marker at
13353 the old PC. If one is found there, assume to be the same marker.
13354 If the name / string id of the marker found is different from the
13355 previous known name, assume that means the user renamed the marker
13356 in the sources, and output a warning.
13358 2) For a tracepoint set at a given line number, look for a marker
13359 at the new address of the old line number. If one is found there,
13360 assume to be the same marker. If the name / string id of the
13361 marker found is different from the previous known name, assume that
13362 means the user renamed the marker in the sources, and output a
13365 3) If a marker is no longer found at the same address or line, it
13366 may mean the marker no longer exists. But it may also just mean
13367 the code changed a bit. Maybe the user added a few lines of code
13368 that made the marker move up or down (in line number terms). Ask
13369 the target for info about the marker with the string id as we knew
13370 it. If found, update line number and address in the matching
13371 static tracepoint. This will get confused if there's more than one
13372 marker with the same ID (possible in UST, although unadvised
13373 precisely because it confuses tools). */
13375 static struct symtab_and_line
13376 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13378 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13379 struct static_tracepoint_marker marker
;
13384 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13386 if (target_static_tracepoint_marker_at (pc
, &marker
))
13388 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13389 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13390 b
->number
, tp
->static_trace_marker_id
.c_str (),
13391 marker
.str_id
.c_str ());
13393 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13398 /* Old marker wasn't found on target at lineno. Try looking it up
13400 if (!sal
.explicit_pc
13402 && sal
.symtab
!= NULL
13403 && !tp
->static_trace_marker_id
.empty ())
13405 std::vector
<static_tracepoint_marker
> markers
13406 = target_static_tracepoint_markers_by_strid
13407 (tp
->static_trace_marker_id
.c_str ());
13409 if (!markers
.empty ())
13411 struct symbol
*sym
;
13412 struct static_tracepoint_marker
*tpmarker
;
13413 struct ui_out
*uiout
= current_uiout
;
13414 struct explicit_location explicit_loc
;
13416 tpmarker
= &markers
[0];
13418 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13420 warning (_("marker for static tracepoint %d (%s) not "
13421 "found at previous line number"),
13422 b
->number
, tp
->static_trace_marker_id
.c_str ());
13424 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13425 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13426 uiout
->text ("Now in ");
13429 uiout
->field_string ("func", sym
->print_name (),
13430 function_name_style
.style ());
13431 uiout
->text (" at ");
13433 uiout
->field_string ("file",
13434 symtab_to_filename_for_display (sal2
.symtab
),
13435 file_name_style
.style ());
13438 if (uiout
->is_mi_like_p ())
13440 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13442 uiout
->field_string ("fullname", fullname
);
13445 uiout
->field_signed ("line", sal2
.line
);
13446 uiout
->text ("\n");
13448 b
->loc
->line_number
= sal2
.line
;
13449 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13451 b
->location
.reset (NULL
);
13452 initialize_explicit_location (&explicit_loc
);
13453 explicit_loc
.source_filename
13454 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13455 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13456 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13457 b
->location
= new_explicit_location (&explicit_loc
);
13459 /* Might be nice to check if function changed, and warn if
13466 /* Returns 1 iff locations A and B are sufficiently same that
13467 we don't need to report breakpoint as changed. */
13470 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13474 if (a
->address
!= b
->address
)
13477 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13480 if (a
->enabled
!= b
->enabled
)
13483 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
13490 if ((a
== NULL
) != (b
== NULL
))
13496 /* Split all locations of B that are bound to PSPACE out of B's
13497 location list to a separate list and return that list's head. If
13498 PSPACE is NULL, hoist out all locations of B. */
13500 static struct bp_location
*
13501 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13503 struct bp_location head
;
13504 struct bp_location
*i
= b
->loc
;
13505 struct bp_location
**i_link
= &b
->loc
;
13506 struct bp_location
*hoisted
= &head
;
13508 if (pspace
== NULL
)
13519 if (i
->pspace
== pspace
)
13534 /* Create new breakpoint locations for B (a hardware or software
13535 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13536 zero, then B is a ranged breakpoint. Only recreates locations for
13537 FILTER_PSPACE. Locations of other program spaces are left
13541 update_breakpoint_locations (struct breakpoint
*b
,
13542 struct program_space
*filter_pspace
,
13543 gdb::array_view
<const symtab_and_line
> sals
,
13544 gdb::array_view
<const symtab_and_line
> sals_end
)
13546 struct bp_location
*existing_locations
;
13548 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13550 /* Ranged breakpoints have only one start location and one end
13552 b
->enable_state
= bp_disabled
;
13553 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13554 "multiple locations found\n"),
13559 /* If there's no new locations, and all existing locations are
13560 pending, don't do anything. This optimizes the common case where
13561 all locations are in the same shared library, that was unloaded.
13562 We'd like to retain the location, so that when the library is
13563 loaded again, we don't loose the enabled/disabled status of the
13564 individual locations. */
13565 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13568 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13570 for (const auto &sal
: sals
)
13572 struct bp_location
*new_loc
;
13574 switch_to_program_space_and_thread (sal
.pspace
);
13576 new_loc
= add_location_to_breakpoint (b
, &sal
);
13578 /* Reparse conditions, they might contain references to the
13580 if (b
->cond_string
!= NULL
)
13584 s
= b
->cond_string
;
13587 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13588 block_for_pc (sal
.pc
),
13591 catch (const gdb_exception_error
&e
)
13593 new_loc
->disabled_by_cond
= true;
13597 if (!sals_end
.empty ())
13599 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13601 new_loc
->length
= end
- sals
[0].pc
+ 1;
13605 /* If possible, carry over 'disable' status from existing
13608 struct bp_location
*e
= existing_locations
;
13609 /* If there are multiple breakpoints with the same function name,
13610 e.g. for inline functions, comparing function names won't work.
13611 Instead compare pc addresses; this is just a heuristic as things
13612 may have moved, but in practice it gives the correct answer
13613 often enough until a better solution is found. */
13614 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13616 for (; e
; e
= e
->next
)
13618 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
13620 if (have_ambiguous_names
)
13622 for (bp_location
*l
: b
->locations ())
13624 /* Ignore software vs hardware location type at
13625 this point, because with "set breakpoint
13626 auto-hw", after a re-set, locations that were
13627 hardware can end up as software, or vice versa.
13628 As mentioned above, this is an heuristic and in
13629 practice should give the correct answer often
13631 if (breakpoint_locations_match (e
, l
, true))
13633 l
->enabled
= e
->enabled
;
13634 l
->disabled_by_cond
= e
->disabled_by_cond
;
13641 for (bp_location
*l
: b
->locations ())
13642 if (l
->function_name
13643 && strcmp (e
->function_name
, l
->function_name
) == 0)
13645 l
->enabled
= e
->enabled
;
13646 l
->disabled_by_cond
= e
->disabled_by_cond
;
13654 if (!locations_are_equal (existing_locations
, b
->loc
))
13655 gdb::observers::breakpoint_modified
.notify (b
);
13658 /* Find the SaL locations corresponding to the given LOCATION.
13659 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13661 static std::vector
<symtab_and_line
>
13662 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13663 struct program_space
*search_pspace
, int *found
)
13665 struct gdb_exception exception
;
13667 gdb_assert (b
->ops
!= NULL
);
13669 std::vector
<symtab_and_line
> sals
;
13673 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13675 catch (gdb_exception_error
&e
)
13677 int not_found_and_ok
= 0;
13679 /* For pending breakpoints, it's expected that parsing will
13680 fail until the right shared library is loaded. User has
13681 already told to create pending breakpoints and don't need
13682 extra messages. If breakpoint is in bp_shlib_disabled
13683 state, then user already saw the message about that
13684 breakpoint being disabled, and don't want to see more
13686 if (e
.error
== NOT_FOUND_ERROR
13687 && (b
->condition_not_parsed
13689 && search_pspace
!= NULL
13690 && b
->loc
->pspace
!= search_pspace
)
13691 || (b
->loc
&& b
->loc
->shlib_disabled
)
13692 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13693 || b
->enable_state
== bp_disabled
))
13694 not_found_and_ok
= 1;
13696 if (!not_found_and_ok
)
13698 /* We surely don't want to warn about the same breakpoint
13699 10 times. One solution, implemented here, is disable
13700 the breakpoint on error. Another solution would be to
13701 have separate 'warning emitted' flag. Since this
13702 happens only when a binary has changed, I don't know
13703 which approach is better. */
13704 b
->enable_state
= bp_disabled
;
13708 exception
= std::move (e
);
13711 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13713 for (auto &sal
: sals
)
13714 resolve_sal_pc (&sal
);
13715 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13717 char *cond_string
, *extra_string
;
13720 find_condition_and_thread_for_sals (sals
, b
->extra_string
,
13721 &cond_string
, &thread
,
13722 &task
, &extra_string
);
13723 gdb_assert (b
->cond_string
== NULL
);
13725 b
->cond_string
= cond_string
;
13726 b
->thread
= thread
;
13730 xfree (b
->extra_string
);
13731 b
->extra_string
= extra_string
;
13733 b
->condition_not_parsed
= 0;
13736 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13737 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13747 /* The default re_set method, for typical hardware or software
13748 breakpoints. Reevaluate the breakpoint and recreate its
13752 breakpoint_re_set_default (struct breakpoint
*b
)
13754 struct program_space
*filter_pspace
= current_program_space
;
13755 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13758 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13759 filter_pspace
, &found
);
13761 expanded
= std::move (sals
);
13763 if (b
->location_range_end
!= NULL
)
13765 std::vector
<symtab_and_line
> sals_end
13766 = location_to_sals (b
, b
->location_range_end
.get (),
13767 filter_pspace
, &found
);
13769 expanded_end
= std::move (sals_end
);
13772 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13775 /* Default method for creating SALs from an address string. It basically
13776 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13779 create_sals_from_location_default (struct event_location
*location
,
13780 struct linespec_result
*canonical
,
13781 enum bptype type_wanted
)
13783 parse_breakpoint_sals (location
, canonical
);
13786 /* Call create_breakpoints_sal for the given arguments. This is the default
13787 function for the `create_breakpoints_sal' method of
13791 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13792 struct linespec_result
*canonical
,
13793 gdb::unique_xmalloc_ptr
<char> cond_string
,
13794 gdb::unique_xmalloc_ptr
<char> extra_string
,
13795 enum bptype type_wanted
,
13796 enum bpdisp disposition
,
13798 int task
, int ignore_count
,
13799 const struct breakpoint_ops
*ops
,
13800 int from_tty
, int enabled
,
13801 int internal
, unsigned flags
)
13803 create_breakpoints_sal (gdbarch
, canonical
,
13804 std::move (cond_string
),
13805 std::move (extra_string
),
13806 type_wanted
, disposition
,
13807 thread
, task
, ignore_count
, ops
, from_tty
,
13808 enabled
, internal
, flags
);
13811 /* Decode the line represented by S by calling decode_line_full. This is the
13812 default function for the `decode_location' method of breakpoint_ops. */
13814 static std::vector
<symtab_and_line
>
13815 decode_location_default (struct breakpoint
*b
,
13816 struct event_location
*location
,
13817 struct program_space
*search_pspace
)
13819 struct linespec_result canonical
;
13821 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13822 NULL
, 0, &canonical
, multiple_symbols_all
,
13825 /* We should get 0 or 1 resulting SALs. */
13826 gdb_assert (canonical
.lsals
.size () < 2);
13828 if (!canonical
.lsals
.empty ())
13830 const linespec_sals
&lsal
= canonical
.lsals
[0];
13831 return std::move (lsal
.sals
);
13836 /* Reset a breakpoint. */
13839 breakpoint_re_set_one (breakpoint
*b
)
13841 input_radix
= b
->input_radix
;
13842 set_language (b
->language
);
13844 b
->ops
->re_set (b
);
13847 /* Re-set breakpoint locations for the current program space.
13848 Locations bound to other program spaces are left untouched. */
13851 breakpoint_re_set (void)
13854 scoped_restore_current_language save_language
;
13855 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13856 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13858 /* breakpoint_re_set_one sets the current_language to the language
13859 of the breakpoint it is resetting (see prepare_re_set_context)
13860 before re-evaluating the breakpoint's location. This change can
13861 unfortunately get undone by accident if the language_mode is set
13862 to auto, and we either switch frames, or more likely in this context,
13863 we select the current frame.
13865 We prevent this by temporarily turning the language_mode to
13866 language_mode_manual. We restore it once all breakpoints
13867 have been reset. */
13868 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13869 language_mode
= language_mode_manual
;
13871 /* Note: we must not try to insert locations until after all
13872 breakpoints have been re-set. Otherwise, e.g., when re-setting
13873 breakpoint 1, we'd insert the locations of breakpoint 2, which
13874 hadn't been re-set yet, and thus may have stale locations. */
13876 for (breakpoint
*b
: all_breakpoints_safe ())
13880 breakpoint_re_set_one (b
);
13882 catch (const gdb_exception
&ex
)
13884 exception_fprintf (gdb_stderr
, ex
,
13885 "Error in re-setting breakpoint %d: ",
13890 jit_breakpoint_re_set ();
13893 create_overlay_event_breakpoint ();
13894 create_longjmp_master_breakpoint ();
13895 create_std_terminate_master_breakpoint ();
13896 create_exception_master_breakpoint ();
13898 /* Now we can insert. */
13899 update_global_location_list (UGLL_MAY_INSERT
);
13902 /* Reset the thread number of this breakpoint:
13904 - If the breakpoint is for all threads, leave it as-is.
13905 - Else, reset it to the current thread for inferior_ptid. */
13907 breakpoint_re_set_thread (struct breakpoint
*b
)
13909 if (b
->thread
!= -1)
13911 b
->thread
= inferior_thread ()->global_num
;
13913 /* We're being called after following a fork. The new fork is
13914 selected as current, and unless this was a vfork will have a
13915 different program space from the original thread. Reset that
13917 b
->loc
->pspace
= current_program_space
;
13921 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13922 If from_tty is nonzero, it prints a message to that effect,
13923 which ends with a period (no newline). */
13926 set_ignore_count (int bptnum
, int count
, int from_tty
)
13931 for (breakpoint
*b
: all_breakpoints ())
13932 if (b
->number
== bptnum
)
13934 if (is_tracepoint (b
))
13936 if (from_tty
&& count
!= 0)
13937 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13942 b
->ignore_count
= count
;
13946 printf_filtered (_("Will stop next time "
13947 "breakpoint %d is reached."),
13949 else if (count
== 1)
13950 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13953 printf_filtered (_("Will ignore next %d "
13954 "crossings of breakpoint %d."),
13957 gdb::observers::breakpoint_modified
.notify (b
);
13961 error (_("No breakpoint number %d."), bptnum
);
13964 /* Command to set ignore-count of breakpoint N to COUNT. */
13967 ignore_command (const char *args
, int from_tty
)
13969 const char *p
= args
;
13973 error_no_arg (_("a breakpoint number"));
13975 num
= get_number (&p
);
13977 error (_("bad breakpoint number: '%s'"), args
);
13979 error (_("Second argument (specified ignore-count) is missing."));
13981 set_ignore_count (num
,
13982 longest_to_int (value_as_long (parse_and_eval (p
))),
13985 printf_filtered ("\n");
13989 /* Call FUNCTION on each of the breakpoints with numbers in the range
13990 defined by BP_NUM_RANGE (an inclusive range). */
13993 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13994 gdb::function_view
<void (breakpoint
*)> function
)
13996 if (bp_num_range
.first
== 0)
13998 warning (_("bad breakpoint number at or near '%d'"),
13999 bp_num_range
.first
);
14003 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
14005 bool match
= false;
14007 for (breakpoint
*b
: all_breakpoints_safe ())
14008 if (b
->number
== i
)
14015 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
14020 /* Call FUNCTION on each of the breakpoints whose numbers are given in
14024 map_breakpoint_numbers (const char *args
,
14025 gdb::function_view
<void (breakpoint
*)> function
)
14027 if (args
== NULL
|| *args
== '\0')
14028 error_no_arg (_("one or more breakpoint numbers"));
14030 number_or_range_parser
parser (args
);
14032 while (!parser
.finished ())
14034 int num
= parser
.get_number ();
14035 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
14039 /* Return the breakpoint location structure corresponding to the
14040 BP_NUM and LOC_NUM values. */
14042 static struct bp_location
*
14043 find_location_by_number (int bp_num
, int loc_num
)
14045 breakpoint
*b
= get_breakpoint (bp_num
);
14047 if (!b
|| b
->number
!= bp_num
)
14048 error (_("Bad breakpoint number '%d'"), bp_num
);
14051 error (_("Bad breakpoint location number '%d'"), loc_num
);
14054 for (bp_location
*loc
: b
->locations ())
14055 if (++n
== loc_num
)
14058 error (_("Bad breakpoint location number '%d'"), loc_num
);
14061 /* Modes of operation for extract_bp_num. */
14062 enum class extract_bp_kind
14064 /* Extracting a breakpoint number. */
14067 /* Extracting a location number. */
14071 /* Extract a breakpoint or location number (as determined by KIND)
14072 from the string starting at START. TRAILER is a character which
14073 can be found after the number. If you don't want a trailer, use
14074 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14075 string. This always returns a positive integer. */
14078 extract_bp_num (extract_bp_kind kind
, const char *start
,
14079 int trailer
, const char **end_out
= NULL
)
14081 const char *end
= start
;
14082 int num
= get_number_trailer (&end
, trailer
);
14084 error (kind
== extract_bp_kind::bp
14085 ? _("Negative breakpoint number '%.*s'")
14086 : _("Negative breakpoint location number '%.*s'"),
14087 int (end
- start
), start
);
14089 error (kind
== extract_bp_kind::bp
14090 ? _("Bad breakpoint number '%.*s'")
14091 : _("Bad breakpoint location number '%.*s'"),
14092 int (end
- start
), start
);
14094 if (end_out
!= NULL
)
14099 /* Extract a breakpoint or location range (as determined by KIND) in
14100 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14101 representing the (inclusive) range. The returned pair's elements
14102 are always positive integers. */
14104 static std::pair
<int, int>
14105 extract_bp_or_bp_range (extract_bp_kind kind
,
14106 const std::string
&arg
,
14107 std::string::size_type arg_offset
)
14109 std::pair
<int, int> range
;
14110 const char *bp_loc
= &arg
[arg_offset
];
14111 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14112 if (dash
!= std::string::npos
)
14114 /* bp_loc is a range (x-z). */
14115 if (arg
.length () == dash
+ 1)
14116 error (kind
== extract_bp_kind::bp
14117 ? _("Bad breakpoint number at or near: '%s'")
14118 : _("Bad breakpoint location number at or near: '%s'"),
14122 const char *start_first
= bp_loc
;
14123 const char *start_second
= &arg
[dash
+ 1];
14124 range
.first
= extract_bp_num (kind
, start_first
, '-');
14125 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14127 if (range
.first
> range
.second
)
14128 error (kind
== extract_bp_kind::bp
14129 ? _("Inverted breakpoint range at '%.*s'")
14130 : _("Inverted breakpoint location range at '%.*s'"),
14131 int (end
- start_first
), start_first
);
14135 /* bp_loc is a single value. */
14136 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14137 range
.second
= range
.first
;
14142 /* Extract the breakpoint/location range specified by ARG. Returns
14143 the breakpoint range in BP_NUM_RANGE, and the location range in
14146 ARG may be in any of the following forms:
14148 x where 'x' is a breakpoint number.
14149 x-y where 'x' and 'y' specify a breakpoint numbers range.
14150 x.y where 'x' is a breakpoint number and 'y' a location number.
14151 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14152 location number range.
14156 extract_bp_number_and_location (const std::string
&arg
,
14157 std::pair
<int, int> &bp_num_range
,
14158 std::pair
<int, int> &bp_loc_range
)
14160 std::string::size_type dot
= arg
.find ('.');
14162 if (dot
!= std::string::npos
)
14164 /* Handle 'x.y' and 'x.y-z' cases. */
14166 if (arg
.length () == dot
+ 1 || dot
== 0)
14167 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14170 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14171 bp_num_range
.second
= bp_num_range
.first
;
14173 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14178 /* Handle x and x-y cases. */
14180 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14181 bp_loc_range
.first
= 0;
14182 bp_loc_range
.second
= 0;
14186 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14187 specifies whether to enable or disable. */
14190 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14192 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14195 if (loc
->disabled_by_cond
&& enable
)
14196 error (_("Breakpoint %d's condition is invalid at location %d, "
14197 "cannot enable."), bp_num
, loc_num
);
14199 if (loc
->enabled
!= enable
)
14201 loc
->enabled
= enable
;
14202 mark_breakpoint_location_modified (loc
);
14204 if (target_supports_enable_disable_tracepoint ()
14205 && current_trace_status ()->running
&& loc
->owner
14206 && is_tracepoint (loc
->owner
))
14207 target_disable_tracepoint (loc
);
14209 update_global_location_list (UGLL_DONT_INSERT
);
14211 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14214 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14215 number of the breakpoint, and BP_LOC_RANGE specifies the
14216 (inclusive) range of location numbers of that breakpoint to
14217 enable/disable. ENABLE specifies whether to enable or disable the
14221 enable_disable_breakpoint_location_range (int bp_num
,
14222 std::pair
<int, int> &bp_loc_range
,
14225 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14226 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14229 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14230 If from_tty is nonzero, it prints a message to that effect,
14231 which ends with a period (no newline). */
14234 disable_breakpoint (struct breakpoint
*bpt
)
14236 /* Never disable a watchpoint scope breakpoint; we want to
14237 hit them when we leave scope so we can delete both the
14238 watchpoint and its scope breakpoint at that time. */
14239 if (bpt
->type
== bp_watchpoint_scope
)
14242 bpt
->enable_state
= bp_disabled
;
14244 /* Mark breakpoint locations modified. */
14245 mark_breakpoint_modified (bpt
);
14247 if (target_supports_enable_disable_tracepoint ()
14248 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14250 for (bp_location
*location
: bpt
->locations ())
14251 target_disable_tracepoint (location
);
14254 update_global_location_list (UGLL_DONT_INSERT
);
14256 gdb::observers::breakpoint_modified
.notify (bpt
);
14259 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14260 specified in ARGS. ARGS may be in any of the formats handled by
14261 extract_bp_number_and_location. ENABLE specifies whether to enable
14262 or disable the breakpoints/locations. */
14265 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14269 for (breakpoint
*bpt
: all_breakpoints ())
14270 if (user_breakpoint_p (bpt
))
14273 enable_breakpoint (bpt
);
14275 disable_breakpoint (bpt
);
14280 std::string num
= extract_arg (&args
);
14282 while (!num
.empty ())
14284 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14286 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14288 if (bp_loc_range
.first
== bp_loc_range
.second
14289 && bp_loc_range
.first
== 0)
14291 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14292 map_breakpoint_number_range (bp_num_range
,
14294 ? enable_breakpoint
14295 : disable_breakpoint
);
14299 /* Handle breakpoint ids with formats 'x.y' or
14301 enable_disable_breakpoint_location_range
14302 (bp_num_range
.first
, bp_loc_range
, enable
);
14304 num
= extract_arg (&args
);
14309 /* The disable command disables the specified breakpoints/locations
14310 (or all defined breakpoints) so they're no longer effective in
14311 stopping the inferior. ARGS may be in any of the forms defined in
14312 extract_bp_number_and_location. */
14315 disable_command (const char *args
, int from_tty
)
14317 enable_disable_command (args
, from_tty
, false);
14321 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14324 int target_resources_ok
;
14326 if (bpt
->type
== bp_hardware_breakpoint
)
14329 i
= hw_breakpoint_used_count ();
14330 target_resources_ok
=
14331 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14333 if (target_resources_ok
== 0)
14334 error (_("No hardware breakpoint support in the target."));
14335 else if (target_resources_ok
< 0)
14336 error (_("Hardware breakpoints used exceeds limit."));
14339 if (is_watchpoint (bpt
))
14341 /* Initialize it just to avoid a GCC false warning. */
14342 enum enable_state orig_enable_state
= bp_disabled
;
14346 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14348 orig_enable_state
= bpt
->enable_state
;
14349 bpt
->enable_state
= bp_enabled
;
14350 update_watchpoint (w
, 1 /* reparse */);
14352 catch (const gdb_exception
&e
)
14354 bpt
->enable_state
= orig_enable_state
;
14355 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14361 bpt
->enable_state
= bp_enabled
;
14363 /* Mark breakpoint locations modified. */
14364 mark_breakpoint_modified (bpt
);
14366 if (target_supports_enable_disable_tracepoint ()
14367 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14369 for (bp_location
*location
: bpt
->locations ())
14370 target_enable_tracepoint (location
);
14373 bpt
->disposition
= disposition
;
14374 bpt
->enable_count
= count
;
14375 update_global_location_list (UGLL_MAY_INSERT
);
14377 gdb::observers::breakpoint_modified
.notify (bpt
);
14382 enable_breakpoint (struct breakpoint
*bpt
)
14384 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14387 /* The enable command enables the specified breakpoints/locations (or
14388 all defined breakpoints) so they once again become (or continue to
14389 be) effective in stopping the inferior. ARGS may be in any of the
14390 forms defined in extract_bp_number_and_location. */
14393 enable_command (const char *args
, int from_tty
)
14395 enable_disable_command (args
, from_tty
, true);
14399 enable_once_command (const char *args
, int from_tty
)
14401 map_breakpoint_numbers
14402 (args
, [&] (breakpoint
*b
)
14404 iterate_over_related_breakpoints
14405 (b
, [&] (breakpoint
*bpt
)
14407 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14413 enable_count_command (const char *args
, int from_tty
)
14418 error_no_arg (_("hit count"));
14420 count
= get_number (&args
);
14422 map_breakpoint_numbers
14423 (args
, [&] (breakpoint
*b
)
14425 iterate_over_related_breakpoints
14426 (b
, [&] (breakpoint
*bpt
)
14428 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14434 enable_delete_command (const char *args
, int from_tty
)
14436 map_breakpoint_numbers
14437 (args
, [&] (breakpoint
*b
)
14439 iterate_over_related_breakpoints
14440 (b
, [&] (breakpoint
*bpt
)
14442 enable_breakpoint_disp (bpt
, disp_del
, 1);
14447 /* Invalidate last known value of any hardware watchpoint if
14448 the memory which that value represents has been written to by
14452 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14453 CORE_ADDR addr
, ssize_t len
,
14454 const bfd_byte
*data
)
14456 for (breakpoint
*bp
: all_breakpoints ())
14457 if (bp
->enable_state
== bp_enabled
14458 && bp
->type
== bp_hardware_watchpoint
)
14460 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14462 if (wp
->val_valid
&& wp
->val
!= nullptr)
14464 for (bp_location
*loc
: bp
->locations ())
14465 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14466 && loc
->address
+ loc
->length
> addr
14467 && addr
+ len
> loc
->address
)
14470 wp
->val_valid
= false;
14476 /* Create and insert a breakpoint for software single step. */
14479 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14480 const address_space
*aspace
,
14483 struct thread_info
*tp
= inferior_thread ();
14484 struct symtab_and_line sal
;
14485 CORE_ADDR pc
= next_pc
;
14487 if (tp
->control
.single_step_breakpoints
== NULL
)
14489 tp
->control
.single_step_breakpoints
14490 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14493 sal
= find_pc_line (pc
, 0);
14495 sal
.section
= find_pc_overlay (pc
);
14496 sal
.explicit_pc
= 1;
14497 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14499 update_global_location_list (UGLL_INSERT
);
14502 /* Insert single step breakpoints according to the current state. */
14505 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14507 struct regcache
*regcache
= get_current_regcache ();
14508 std::vector
<CORE_ADDR
> next_pcs
;
14510 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14512 if (!next_pcs
.empty ())
14514 struct frame_info
*frame
= get_current_frame ();
14515 const address_space
*aspace
= get_frame_address_space (frame
);
14517 for (CORE_ADDR pc
: next_pcs
)
14518 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14526 /* See breakpoint.h. */
14529 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14530 const address_space
*aspace
,
14533 for (bp_location
*loc
: bp
->locations ())
14535 && breakpoint_location_address_match (loc
, aspace
, pc
))
14541 /* Check whether a software single-step breakpoint is inserted at
14545 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14548 for (breakpoint
*bpt
: all_breakpoints ())
14550 if (bpt
->type
== bp_single_step
14551 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14557 /* Tracepoint-specific operations. */
14559 /* Set tracepoint count to NUM. */
14561 set_tracepoint_count (int num
)
14563 tracepoint_count
= num
;
14564 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14568 trace_command (const char *arg
, int from_tty
)
14570 event_location_up location
= string_to_event_location (&arg
,
14572 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
14573 (location
.get (), true /* is_tracepoint */);
14575 create_breakpoint (get_current_arch (),
14577 NULL
, 0, arg
, false, 1 /* parse arg */,
14579 bp_tracepoint
/* type_wanted */,
14580 0 /* Ignore count */,
14581 pending_break_support
,
14585 0 /* internal */, 0);
14589 ftrace_command (const char *arg
, int from_tty
)
14591 event_location_up location
= string_to_event_location (&arg
,
14593 create_breakpoint (get_current_arch (),
14595 NULL
, 0, arg
, false, 1 /* parse arg */,
14597 bp_fast_tracepoint
/* type_wanted */,
14598 0 /* Ignore count */,
14599 pending_break_support
,
14600 &tracepoint_breakpoint_ops
,
14603 0 /* internal */, 0);
14606 /* strace command implementation. Creates a static tracepoint. */
14609 strace_command (const char *arg
, int from_tty
)
14611 struct breakpoint_ops
*ops
;
14612 event_location_up location
;
14614 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14615 or with a normal static tracepoint. */
14616 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14618 ops
= &strace_marker_breakpoint_ops
;
14619 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14623 ops
= &tracepoint_breakpoint_ops
;
14624 location
= string_to_event_location (&arg
, current_language
);
14627 create_breakpoint (get_current_arch (),
14629 NULL
, 0, arg
, false, 1 /* parse arg */,
14631 bp_static_tracepoint
/* type_wanted */,
14632 0 /* Ignore count */,
14633 pending_break_support
,
14637 0 /* internal */, 0);
14640 /* Set up a fake reader function that gets command lines from a linked
14641 list that was acquired during tracepoint uploading. */
14643 static struct uploaded_tp
*this_utp
;
14644 static int next_cmd
;
14647 read_uploaded_action (void)
14649 char *rslt
= nullptr;
14651 if (next_cmd
< this_utp
->cmd_strings
.size ())
14653 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14660 /* Given information about a tracepoint as recorded on a target (which
14661 can be either a live system or a trace file), attempt to create an
14662 equivalent GDB tracepoint. This is not a reliable process, since
14663 the target does not necessarily have all the information used when
14664 the tracepoint was originally defined. */
14666 struct tracepoint
*
14667 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14669 const char *addr_str
;
14670 char small_buf
[100];
14671 struct tracepoint
*tp
;
14673 if (utp
->at_string
)
14674 addr_str
= utp
->at_string
.get ();
14677 /* In the absence of a source location, fall back to raw
14678 address. Since there is no way to confirm that the address
14679 means the same thing as when the trace was started, warn the
14681 warning (_("Uploaded tracepoint %d has no "
14682 "source location, using raw address"),
14684 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14685 addr_str
= small_buf
;
14688 /* There's not much we can do with a sequence of bytecodes. */
14689 if (utp
->cond
&& !utp
->cond_string
)
14690 warning (_("Uploaded tracepoint %d condition "
14691 "has no source form, ignoring it"),
14694 event_location_up location
= string_to_event_location (&addr_str
,
14696 if (!create_breakpoint (get_current_arch (),
14698 utp
->cond_string
.get (), -1, addr_str
,
14699 false /* force_condition */,
14700 0 /* parse cond/thread */,
14702 utp
->type
/* type_wanted */,
14703 0 /* Ignore count */,
14704 pending_break_support
,
14705 &tracepoint_breakpoint_ops
,
14707 utp
->enabled
/* enabled */,
14709 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14712 /* Get the tracepoint we just created. */
14713 tp
= get_tracepoint (tracepoint_count
);
14714 gdb_assert (tp
!= NULL
);
14718 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14721 trace_pass_command (small_buf
, 0);
14724 /* If we have uploaded versions of the original commands, set up a
14725 special-purpose "reader" function and call the usual command line
14726 reader, then pass the result to the breakpoint command-setting
14728 if (!utp
->cmd_strings
.empty ())
14730 counted_command_line cmd_list
;
14735 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14737 breakpoint_set_commands (tp
, std::move (cmd_list
));
14739 else if (!utp
->actions
.empty ()
14740 || !utp
->step_actions
.empty ())
14741 warning (_("Uploaded tracepoint %d actions "
14742 "have no source form, ignoring them"),
14745 /* Copy any status information that might be available. */
14746 tp
->hit_count
= utp
->hit_count
;
14747 tp
->traceframe_usage
= utp
->traceframe_usage
;
14752 /* Print information on tracepoint number TPNUM_EXP, or all if
14756 info_tracepoints_command (const char *args
, int from_tty
)
14758 struct ui_out
*uiout
= current_uiout
;
14761 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14763 if (num_printed
== 0)
14765 if (args
== NULL
|| *args
== '\0')
14766 uiout
->message ("No tracepoints.\n");
14768 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14771 default_collect_info ();
14774 /* The 'enable trace' command enables tracepoints.
14775 Not supported by all targets. */
14777 enable_trace_command (const char *args
, int from_tty
)
14779 enable_command (args
, from_tty
);
14782 /* The 'disable trace' command disables tracepoints.
14783 Not supported by all targets. */
14785 disable_trace_command (const char *args
, int from_tty
)
14787 disable_command (args
, from_tty
);
14790 /* Remove a tracepoint (or all if no argument). */
14792 delete_trace_command (const char *arg
, int from_tty
)
14798 int breaks_to_delete
= 0;
14800 /* Delete all breakpoints if no argument.
14801 Do not delete internal or call-dummy breakpoints, these
14802 have to be deleted with an explicit breakpoint number
14804 for (breakpoint
*tp
: all_tracepoints ())
14805 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
14807 breaks_to_delete
= 1;
14811 /* Ask user only if there are some breakpoints to delete. */
14813 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14815 for (breakpoint
*b
: all_breakpoints_safe ())
14816 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14817 delete_breakpoint (b
);
14821 map_breakpoint_numbers
14822 (arg
, [&] (breakpoint
*br
)
14824 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14828 /* Helper function for trace_pass_command. */
14831 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14833 tp
->pass_count
= count
;
14834 gdb::observers::breakpoint_modified
.notify (tp
);
14836 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14837 tp
->number
, count
);
14840 /* Set passcount for tracepoint.
14842 First command argument is passcount, second is tracepoint number.
14843 If tracepoint number omitted, apply to most recently defined.
14844 Also accepts special argument "all". */
14847 trace_pass_command (const char *args
, int from_tty
)
14849 struct tracepoint
*t1
;
14852 if (args
== 0 || *args
== 0)
14853 error (_("passcount command requires an "
14854 "argument (count + optional TP num)"));
14856 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14858 args
= skip_spaces (args
);
14859 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14861 args
+= 3; /* Skip special argument "all". */
14863 error (_("Junk at end of arguments."));
14865 for (breakpoint
*b
: all_tracepoints ())
14867 t1
= (struct tracepoint
*) b
;
14868 trace_pass_set_count (t1
, count
, from_tty
);
14871 else if (*args
== '\0')
14873 t1
= get_tracepoint_by_number (&args
, NULL
);
14875 trace_pass_set_count (t1
, count
, from_tty
);
14879 number_or_range_parser
parser (args
);
14880 while (!parser
.finished ())
14882 t1
= get_tracepoint_by_number (&args
, &parser
);
14884 trace_pass_set_count (t1
, count
, from_tty
);
14889 struct tracepoint
*
14890 get_tracepoint (int num
)
14892 for (breakpoint
*t
: all_tracepoints ())
14893 if (t
->number
== num
)
14894 return (struct tracepoint
*) t
;
14899 /* Find the tracepoint with the given target-side number (which may be
14900 different from the tracepoint number after disconnecting and
14903 struct tracepoint
*
14904 get_tracepoint_by_number_on_target (int num
)
14906 for (breakpoint
*b
: all_tracepoints ())
14908 struct tracepoint
*t
= (struct tracepoint
*) b
;
14910 if (t
->number_on_target
== num
)
14917 /* Utility: parse a tracepoint number and look it up in the list.
14918 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14919 If the argument is missing, the most recent tracepoint
14920 (tracepoint_count) is returned. */
14922 struct tracepoint
*
14923 get_tracepoint_by_number (const char **arg
,
14924 number_or_range_parser
*parser
)
14927 const char *instring
= arg
== NULL
? NULL
: *arg
;
14929 if (parser
!= NULL
)
14931 gdb_assert (!parser
->finished ());
14932 tpnum
= parser
->get_number ();
14934 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14935 tpnum
= tracepoint_count
;
14937 tpnum
= get_number (arg
);
14941 if (instring
&& *instring
)
14942 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14945 printf_filtered (_("No previous tracepoint\n"));
14949 for (breakpoint
*t
: all_tracepoints ())
14950 if (t
->number
== tpnum
)
14952 return (struct tracepoint
*) t
;
14955 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
14960 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14962 if (b
->thread
!= -1)
14963 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
14966 fprintf_unfiltered (fp
, " task %d", b
->task
);
14968 fprintf_unfiltered (fp
, "\n");
14971 /* Save information on user settable breakpoints (watchpoints, etc) to
14972 a new script file named FILENAME. If FILTER is non-NULL, call it
14973 on each breakpoint and only include the ones for which it returns
14977 save_breakpoints (const char *filename
, int from_tty
,
14978 bool (*filter
) (const struct breakpoint
*))
14981 int extra_trace_bits
= 0;
14983 if (filename
== 0 || *filename
== 0)
14984 error (_("Argument required (file name in which to save)"));
14986 /* See if we have anything to save. */
14987 for (breakpoint
*tp
: all_breakpoints ())
14989 /* Skip internal and momentary breakpoints. */
14990 if (!user_breakpoint_p (tp
))
14993 /* If we have a filter, only save the breakpoints it accepts. */
14994 if (filter
&& !filter (tp
))
14999 if (is_tracepoint (tp
))
15001 extra_trace_bits
= 1;
15003 /* We can stop searching. */
15010 warning (_("Nothing to save."));
15014 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15018 if (!fp
.open (expanded_filename
.get (), "w"))
15019 error (_("Unable to open file '%s' for saving (%s)"),
15020 expanded_filename
.get (), safe_strerror (errno
));
15022 if (extra_trace_bits
)
15023 save_trace_state_variables (&fp
);
15025 for (breakpoint
*tp
: all_breakpoints ())
15027 /* Skip internal and momentary breakpoints. */
15028 if (!user_breakpoint_p (tp
))
15031 /* If we have a filter, only save the breakpoints it accepts. */
15032 if (filter
&& !filter (tp
))
15035 tp
->ops
->print_recreate (tp
, &fp
);
15037 /* Note, we can't rely on tp->number for anything, as we can't
15038 assume the recreated breakpoint numbers will match. Use $bpnum
15041 if (tp
->cond_string
)
15042 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15044 if (tp
->ignore_count
)
15045 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15047 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15049 fp
.puts (" commands\n");
15051 current_uiout
->redirect (&fp
);
15054 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15056 catch (const gdb_exception
&ex
)
15058 current_uiout
->redirect (NULL
);
15062 current_uiout
->redirect (NULL
);
15063 fp
.puts (" end\n");
15066 if (tp
->enable_state
== bp_disabled
)
15067 fp
.puts ("disable $bpnum\n");
15069 /* If this is a multi-location breakpoint, check if the locations
15070 should be individually disabled. Watchpoint locations are
15071 special, and not user visible. */
15072 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15076 for (bp_location
*loc
: tp
->locations ())
15079 fp
.printf ("disable $bpnum.%d\n", n
);
15086 if (extra_trace_bits
&& *default_collect
)
15087 fp
.printf ("set default-collect %s\n", default_collect
);
15090 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15093 /* The `save breakpoints' command. */
15096 save_breakpoints_command (const char *args
, int from_tty
)
15098 save_breakpoints (args
, from_tty
, NULL
);
15101 /* The `save tracepoints' command. */
15104 save_tracepoints_command (const char *args
, int from_tty
)
15106 save_breakpoints (args
, from_tty
, is_tracepoint
);
15110 /* This help string is used to consolidate all the help string for specifying
15111 locations used by several commands. */
15113 #define LOCATION_HELP_STRING \
15114 "Linespecs are colon-separated lists of location parameters, such as\n\
15115 source filename, function name, label name, and line number.\n\
15116 Example: To specify the start of a label named \"the_top\" in the\n\
15117 function \"fact\" in the file \"factorial.c\", use\n\
15118 \"factorial.c:fact:the_top\".\n\
15120 Address locations begin with \"*\" and specify an exact address in the\n\
15121 program. Example: To specify the fourth byte past the start function\n\
15122 \"main\", use \"*main + 4\".\n\
15124 Explicit locations are similar to linespecs but use an option/argument\n\
15125 syntax to specify location parameters.\n\
15126 Example: To specify the start of the label named \"the_top\" in the\n\
15127 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15128 -function fact -label the_top\".\n\
15130 By default, a specified function is matched against the program's\n\
15131 functions in all scopes. For C++, this means in all namespaces and\n\
15132 classes. For Ada, this means in all packages. E.g., in C++,\n\
15133 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15134 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15135 specified name as a complete fully-qualified name instead."
15137 /* This help string is used for the break, hbreak, tbreak and thbreak
15138 commands. It is defined as a macro to prevent duplication.
15139 COMMAND should be a string constant containing the name of the
15142 #define BREAK_ARGS_HELP(command) \
15143 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
15144 \t[-force-condition] [if CONDITION]\n\
15145 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15146 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15147 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15148 `-probe-dtrace' (for a DTrace probe).\n\
15149 LOCATION may be a linespec, address, or explicit location as described\n\
15152 With no LOCATION, uses current execution address of the selected\n\
15153 stack frame. This is useful for breaking on return to a stack frame.\n\
15155 THREADNUM is the number from \"info threads\".\n\
15156 CONDITION is a boolean expression.\n\
15158 With the \"-force-condition\" flag, the condition is defined even when\n\
15159 it is invalid for all current locations.\n\
15160 \n" LOCATION_HELP_STRING "\n\n\
15161 Multiple breakpoints at one place are permitted, and useful if their\n\
15162 conditions are different.\n\
15164 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15166 /* List of subcommands for "catch". */
15167 static struct cmd_list_element
*catch_cmdlist
;
15169 /* List of subcommands for "tcatch". */
15170 static struct cmd_list_element
*tcatch_cmdlist
;
15173 add_catch_command (const char *name
, const char *docstring
,
15174 cmd_const_sfunc_ftype
*sfunc
,
15175 completer_ftype
*completer
,
15176 void *user_data_catch
,
15177 void *user_data_tcatch
)
15179 struct cmd_list_element
*command
;
15181 command
= add_cmd (name
, class_breakpoint
, docstring
,
15183 set_cmd_sfunc (command
, sfunc
);
15184 set_cmd_context (command
, user_data_catch
);
15185 set_cmd_completer (command
, completer
);
15187 command
= add_cmd (name
, class_breakpoint
, docstring
,
15189 set_cmd_sfunc (command
, sfunc
);
15190 set_cmd_context (command
, user_data_tcatch
);
15191 set_cmd_completer (command
, completer
);
15194 struct breakpoint
*
15195 iterate_over_breakpoints (gdb::function_view
<bool (breakpoint
*)> callback
)
15197 for (breakpoint
*b
: all_breakpoints_safe ())
15204 /* Zero if any of the breakpoint's locations could be a location where
15205 functions have been inlined, nonzero otherwise. */
15208 is_non_inline_function (struct breakpoint
*b
)
15210 /* The shared library event breakpoint is set on the address of a
15211 non-inline function. */
15212 if (b
->type
== bp_shlib_event
)
15218 /* Nonzero if the specified PC cannot be a location where functions
15219 have been inlined. */
15222 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15223 const struct target_waitstatus
*ws
)
15225 for (breakpoint
*b
: all_breakpoints ())
15227 if (!is_non_inline_function (b
))
15230 for (bp_location
*bl
: b
->locations ())
15232 if (!bl
->shlib_disabled
15233 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15241 /* Remove any references to OBJFILE which is going to be freed. */
15244 breakpoint_free_objfile (struct objfile
*objfile
)
15246 for (bp_location
*loc
: all_bp_locations ())
15247 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15248 loc
->symtab
= NULL
;
15252 initialize_breakpoint_ops (void)
15254 static int initialized
= 0;
15256 struct breakpoint_ops
*ops
;
15262 /* The breakpoint_ops structure to be inherit by all kinds of
15263 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15264 internal and momentary breakpoints, etc.). */
15265 ops
= &bkpt_base_breakpoint_ops
;
15266 *ops
= base_breakpoint_ops
;
15267 ops
->re_set
= bkpt_re_set
;
15268 ops
->insert_location
= bkpt_insert_location
;
15269 ops
->remove_location
= bkpt_remove_location
;
15270 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15271 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15272 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15273 ops
->decode_location
= bkpt_decode_location
;
15275 /* The breakpoint_ops structure to be used in regular breakpoints. */
15276 ops
= &bkpt_breakpoint_ops
;
15277 *ops
= bkpt_base_breakpoint_ops
;
15278 ops
->re_set
= bkpt_re_set
;
15279 ops
->resources_needed
= bkpt_resources_needed
;
15280 ops
->print_it
= bkpt_print_it
;
15281 ops
->print_mention
= bkpt_print_mention
;
15282 ops
->print_recreate
= bkpt_print_recreate
;
15284 /* Ranged breakpoints. */
15285 ops
= &ranged_breakpoint_ops
;
15286 *ops
= bkpt_breakpoint_ops
;
15287 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15288 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15289 ops
->print_it
= print_it_ranged_breakpoint
;
15290 ops
->print_one
= print_one_ranged_breakpoint
;
15291 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15292 ops
->print_mention
= print_mention_ranged_breakpoint
;
15293 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15295 /* Internal breakpoints. */
15296 ops
= &internal_breakpoint_ops
;
15297 *ops
= bkpt_base_breakpoint_ops
;
15298 ops
->re_set
= internal_bkpt_re_set
;
15299 ops
->check_status
= internal_bkpt_check_status
;
15300 ops
->print_it
= internal_bkpt_print_it
;
15301 ops
->print_mention
= internal_bkpt_print_mention
;
15303 /* Momentary breakpoints. */
15304 ops
= &momentary_breakpoint_ops
;
15305 *ops
= bkpt_base_breakpoint_ops
;
15306 ops
->re_set
= momentary_bkpt_re_set
;
15307 ops
->check_status
= momentary_bkpt_check_status
;
15308 ops
->print_it
= momentary_bkpt_print_it
;
15309 ops
->print_mention
= momentary_bkpt_print_mention
;
15311 /* Probe breakpoints. */
15312 ops
= &bkpt_probe_breakpoint_ops
;
15313 *ops
= bkpt_breakpoint_ops
;
15314 ops
->insert_location
= bkpt_probe_insert_location
;
15315 ops
->remove_location
= bkpt_probe_remove_location
;
15316 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15317 ops
->decode_location
= bkpt_probe_decode_location
;
15320 ops
= &watchpoint_breakpoint_ops
;
15321 *ops
= base_breakpoint_ops
;
15322 ops
->re_set
= re_set_watchpoint
;
15323 ops
->insert_location
= insert_watchpoint
;
15324 ops
->remove_location
= remove_watchpoint
;
15325 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15326 ops
->check_status
= check_status_watchpoint
;
15327 ops
->resources_needed
= resources_needed_watchpoint
;
15328 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15329 ops
->print_it
= print_it_watchpoint
;
15330 ops
->print_mention
= print_mention_watchpoint
;
15331 ops
->print_recreate
= print_recreate_watchpoint
;
15332 ops
->explains_signal
= explains_signal_watchpoint
;
15334 /* Masked watchpoints. */
15335 ops
= &masked_watchpoint_breakpoint_ops
;
15336 *ops
= watchpoint_breakpoint_ops
;
15337 ops
->insert_location
= insert_masked_watchpoint
;
15338 ops
->remove_location
= remove_masked_watchpoint
;
15339 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15340 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15341 ops
->print_it
= print_it_masked_watchpoint
;
15342 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15343 ops
->print_mention
= print_mention_masked_watchpoint
;
15344 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15347 ops
= &tracepoint_breakpoint_ops
;
15348 *ops
= base_breakpoint_ops
;
15349 ops
->re_set
= tracepoint_re_set
;
15350 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15351 ops
->print_one_detail
= tracepoint_print_one_detail
;
15352 ops
->print_mention
= tracepoint_print_mention
;
15353 ops
->print_recreate
= tracepoint_print_recreate
;
15354 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15355 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15356 ops
->decode_location
= tracepoint_decode_location
;
15358 /* Probe tracepoints. */
15359 ops
= &tracepoint_probe_breakpoint_ops
;
15360 *ops
= tracepoint_breakpoint_ops
;
15361 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15362 ops
->decode_location
= tracepoint_probe_decode_location
;
15364 /* Static tracepoints with marker (`-m'). */
15365 ops
= &strace_marker_breakpoint_ops
;
15366 *ops
= tracepoint_breakpoint_ops
;
15367 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15368 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15369 ops
->decode_location
= strace_marker_decode_location
;
15371 /* Fork catchpoints. */
15372 ops
= &catch_fork_breakpoint_ops
;
15373 *ops
= base_breakpoint_ops
;
15374 ops
->insert_location
= insert_catch_fork
;
15375 ops
->remove_location
= remove_catch_fork
;
15376 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15377 ops
->print_it
= print_it_catch_fork
;
15378 ops
->print_one
= print_one_catch_fork
;
15379 ops
->print_mention
= print_mention_catch_fork
;
15380 ops
->print_recreate
= print_recreate_catch_fork
;
15382 /* Vfork catchpoints. */
15383 ops
= &catch_vfork_breakpoint_ops
;
15384 *ops
= base_breakpoint_ops
;
15385 ops
->insert_location
= insert_catch_vfork
;
15386 ops
->remove_location
= remove_catch_vfork
;
15387 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15388 ops
->print_it
= print_it_catch_vfork
;
15389 ops
->print_one
= print_one_catch_vfork
;
15390 ops
->print_mention
= print_mention_catch_vfork
;
15391 ops
->print_recreate
= print_recreate_catch_vfork
;
15393 /* Exec catchpoints. */
15394 ops
= &catch_exec_breakpoint_ops
;
15395 *ops
= base_breakpoint_ops
;
15396 ops
->insert_location
= insert_catch_exec
;
15397 ops
->remove_location
= remove_catch_exec
;
15398 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15399 ops
->print_it
= print_it_catch_exec
;
15400 ops
->print_one
= print_one_catch_exec
;
15401 ops
->print_mention
= print_mention_catch_exec
;
15402 ops
->print_recreate
= print_recreate_catch_exec
;
15404 /* Solib-related catchpoints. */
15405 ops
= &catch_solib_breakpoint_ops
;
15406 *ops
= base_breakpoint_ops
;
15407 ops
->insert_location
= insert_catch_solib
;
15408 ops
->remove_location
= remove_catch_solib
;
15409 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15410 ops
->check_status
= check_status_catch_solib
;
15411 ops
->print_it
= print_it_catch_solib
;
15412 ops
->print_one
= print_one_catch_solib
;
15413 ops
->print_mention
= print_mention_catch_solib
;
15414 ops
->print_recreate
= print_recreate_catch_solib
;
15416 ops
= &dprintf_breakpoint_ops
;
15417 *ops
= bkpt_base_breakpoint_ops
;
15418 ops
->re_set
= dprintf_re_set
;
15419 ops
->resources_needed
= bkpt_resources_needed
;
15420 ops
->print_it
= bkpt_print_it
;
15421 ops
->print_mention
= bkpt_print_mention
;
15422 ops
->print_recreate
= dprintf_print_recreate
;
15423 ops
->after_condition_true
= dprintf_after_condition_true
;
15424 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15427 /* Chain containing all defined "enable breakpoint" subcommands. */
15429 static struct cmd_list_element
*enablebreaklist
= NULL
;
15431 /* See breakpoint.h. */
15433 cmd_list_element
*commands_cmd_element
= nullptr;
15435 void _initialize_breakpoint ();
15437 _initialize_breakpoint ()
15439 struct cmd_list_element
*c
;
15441 initialize_breakpoint_ops ();
15443 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
15445 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
15447 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
15450 breakpoint_chain
= 0;
15451 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15452 before a breakpoint is set. */
15453 breakpoint_count
= 0;
15455 tracepoint_count
= 0;
15457 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15458 Set ignore-count of breakpoint number N to COUNT.\n\
15459 Usage is `ignore N COUNT'."));
15461 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15462 commands_command
, _("\
15463 Set commands to be executed when the given breakpoints are hit.\n\
15464 Give a space-separated breakpoint list as argument after \"commands\".\n\
15465 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15467 With no argument, the targeted breakpoint is the last one set.\n\
15468 The commands themselves follow starting on the next line.\n\
15469 Type a line containing \"end\" to indicate the end of them.\n\
15470 Give \"silent\" as the first line to make the breakpoint silent;\n\
15471 then no output is printed when it is hit, except what the commands print."));
15473 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
15474 static std::string condition_command_help
15475 = gdb::option::build_help (_("\
15476 Specify breakpoint number N to break only if COND is true.\n\
15477 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
15478 is an expression to be evaluated whenever breakpoint N is reached.\n\
15481 %OPTIONS%"), cc_opts
);
15483 c
= add_com ("condition", class_breakpoint
, condition_command
,
15484 condition_command_help
.c_str ());
15485 set_cmd_completer_handle_brkchars (c
, condition_completer
);
15487 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15488 Set a temporary breakpoint.\n\
15489 Like \"break\" except the breakpoint is only temporary,\n\
15490 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15491 by using \"enable delete\" on the breakpoint number.\n\
15493 BREAK_ARGS_HELP ("tbreak")));
15494 set_cmd_completer (c
, location_completer
);
15496 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15497 Set a hardware assisted breakpoint.\n\
15498 Like \"break\" except the breakpoint requires hardware support,\n\
15499 some target hardware may not have this support.\n\
15501 BREAK_ARGS_HELP ("hbreak")));
15502 set_cmd_completer (c
, location_completer
);
15504 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15505 Set a temporary hardware assisted breakpoint.\n\
15506 Like \"hbreak\" except the breakpoint is only temporary,\n\
15507 so it will be deleted when hit.\n\
15509 BREAK_ARGS_HELP ("thbreak")));
15510 set_cmd_completer (c
, location_completer
);
15512 cmd_list_element
*enable_cmd
15513 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15514 Enable all or some breakpoints.\n\
15515 Usage: enable [BREAKPOINTNUM]...\n\
15516 Give breakpoint numbers (separated by spaces) as arguments.\n\
15517 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15518 This is used to cancel the effect of the \"disable\" command.\n\
15519 With a subcommand you can enable temporarily."),
15520 &enablelist
, 1, &cmdlist
);
15522 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
15524 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15525 Enable all or some breakpoints.\n\
15526 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15527 Give breakpoint numbers (separated by spaces) as arguments.\n\
15528 This is used to cancel the effect of the \"disable\" command.\n\
15529 May be abbreviated to simply \"enable\"."),
15530 &enablebreaklist
, 1, &enablelist
);
15532 add_cmd ("once", no_class
, enable_once_command
, _("\
15533 Enable some breakpoints for one hit.\n\
15534 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15535 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15538 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15539 Enable some breakpoints and delete when hit.\n\
15540 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15541 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15544 add_cmd ("count", no_class
, enable_count_command
, _("\
15545 Enable some breakpoints for COUNT hits.\n\
15546 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15547 If a breakpoint is hit while enabled in this fashion,\n\
15548 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15551 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15552 Enable some breakpoints and delete when hit.\n\
15553 Usage: enable delete BREAKPOINTNUM...\n\
15554 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15557 add_cmd ("once", no_class
, enable_once_command
, _("\
15558 Enable some breakpoints for one hit.\n\
15559 Usage: enable once BREAKPOINTNUM...\n\
15560 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15563 add_cmd ("count", no_class
, enable_count_command
, _("\
15564 Enable some breakpoints for COUNT hits.\n\
15565 Usage: enable count COUNT BREAKPOINTNUM...\n\
15566 If a breakpoint is hit while enabled in this fashion,\n\
15567 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15570 cmd_list_element
*disable_cmd
15571 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15572 Disable all or some breakpoints.\n\
15573 Usage: disable [BREAKPOINTNUM]...\n\
15574 Arguments are breakpoint numbers with spaces in between.\n\
15575 To disable all breakpoints, give no argument.\n\
15576 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15577 &disablelist
, 1, &cmdlist
);
15578 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
15579 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
15581 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
15582 Disable all or some breakpoints.\n\
15583 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15584 Arguments are breakpoint numbers with spaces in between.\n\
15585 To disable all breakpoints, give no argument.\n\
15586 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15587 This command may be abbreviated \"disable\"."),
15590 cmd_list_element
*delete_cmd
15591 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15592 Delete all or some breakpoints.\n\
15593 Usage: delete [BREAKPOINTNUM]...\n\
15594 Arguments are breakpoint numbers with spaces in between.\n\
15595 To delete all breakpoints, give no argument.\n\
15597 Also a prefix command for deletion of other GDB objects."),
15598 &deletelist
, 1, &cmdlist
);
15599 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
15600 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
15602 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
15603 Delete all or some breakpoints or auto-display expressions.\n\
15604 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15605 Arguments are breakpoint numbers with spaces in between.\n\
15606 To delete all breakpoints, give no argument.\n\
15607 This command may be abbreviated \"delete\"."),
15610 cmd_list_element
*clear_cmd
15611 = add_com ("clear", class_breakpoint
, clear_command
, _("\
15612 Clear breakpoint at specified location.\n\
15613 Argument may be a linespec, explicit, or address location as described below.\n\
15615 With no argument, clears all breakpoints in the line that the selected frame\n\
15616 is executing in.\n"
15617 "\n" LOCATION_HELP_STRING
"\n\n\
15618 See also the \"delete\" command which clears breakpoints by number."));
15619 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
15621 cmd_list_element
*break_cmd
15622 = add_com ("break", class_breakpoint
, break_command
, _("\
15623 Set breakpoint at specified location.\n"
15624 BREAK_ARGS_HELP ("break")));
15625 set_cmd_completer (break_cmd
, location_completer
);
15627 add_com_alias ("b", break_cmd
, class_run
, 1);
15628 add_com_alias ("br", break_cmd
, class_run
, 1);
15629 add_com_alias ("bre", break_cmd
, class_run
, 1);
15630 add_com_alias ("brea", break_cmd
, class_run
, 1);
15634 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15635 Break in function/address or break at a line in the current file."),
15636 &stoplist
, 1, &cmdlist
);
15637 add_cmd ("in", class_breakpoint
, stopin_command
,
15638 _("Break in function or address."), &stoplist
);
15639 add_cmd ("at", class_breakpoint
, stopat_command
,
15640 _("Break at a line in the current file."), &stoplist
);
15641 add_com ("status", class_info
, info_breakpoints_command
, _("\
15642 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15643 The \"Type\" column indicates one of:\n\
15644 \tbreakpoint - normal breakpoint\n\
15645 \twatchpoint - watchpoint\n\
15646 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15647 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15648 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15649 address and file/line number respectively.\n\
15651 Convenience variable \"$_\" and default examine address for \"x\"\n\
15652 are set to the address of the last breakpoint listed unless the command\n\
15653 is prefixed with \"server \".\n\n\
15654 Convenience variable \"$bpnum\" contains the number of the last\n\
15655 breakpoint set."));
15658 cmd_list_element
*info_breakpoints_cmd
15659 = add_info ("breakpoints", info_breakpoints_command
, _("\
15660 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15661 The \"Type\" column indicates one of:\n\
15662 \tbreakpoint - normal breakpoint\n\
15663 \twatchpoint - watchpoint\n\
15664 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15665 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15666 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15667 address and file/line number respectively.\n\
15669 Convenience variable \"$_\" and default examine address for \"x\"\n\
15670 are set to the address of the last breakpoint listed unless the command\n\
15671 is prefixed with \"server \".\n\n\
15672 Convenience variable \"$bpnum\" contains the number of the last\n\
15673 breakpoint set."));
15675 add_info_alias ("b", info_breakpoints_cmd
, 1);
15677 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15678 Status of all breakpoints, or breakpoint number NUMBER.\n\
15679 The \"Type\" column indicates one of:\n\
15680 \tbreakpoint - normal breakpoint\n\
15681 \twatchpoint - watchpoint\n\
15682 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15683 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15684 \tuntil - internal breakpoint used by the \"until\" command\n\
15685 \tfinish - internal breakpoint used by the \"finish\" command\n\
15686 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15687 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15688 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15689 address and file/line number respectively.\n\
15691 Convenience variable \"$_\" and default examine address for \"x\"\n\
15692 are set to the address of the last breakpoint listed unless the command\n\
15693 is prefixed with \"server \".\n\n\
15694 Convenience variable \"$bpnum\" contains the number of the last\n\
15696 &maintenanceinfolist
);
15698 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
15699 Set catchpoints to catch events."),
15701 0/*allow-unknown*/, &cmdlist
);
15703 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
15704 Set temporary catchpoints to catch events."),
15706 0/*allow-unknown*/, &cmdlist
);
15708 add_catch_command ("fork", _("Catch calls to fork."),
15709 catch_fork_command_1
,
15711 (void *) (uintptr_t) catch_fork_permanent
,
15712 (void *) (uintptr_t) catch_fork_temporary
);
15713 add_catch_command ("vfork", _("Catch calls to vfork."),
15714 catch_fork_command_1
,
15716 (void *) (uintptr_t) catch_vfork_permanent
,
15717 (void *) (uintptr_t) catch_vfork_temporary
);
15718 add_catch_command ("exec", _("Catch calls to exec."),
15719 catch_exec_command_1
,
15723 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15724 Usage: catch load [REGEX]\n\
15725 If REGEX is given, only stop for libraries matching the regular expression."),
15726 catch_load_command_1
,
15730 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15731 Usage: catch unload [REGEX]\n\
15732 If REGEX is given, only stop for libraries matching the regular expression."),
15733 catch_unload_command_1
,
15738 const auto opts
= make_watch_options_def_group (nullptr);
15740 static const std::string watch_help
= gdb::option::build_help (_("\
15741 Set a watchpoint for EXPRESSION.\n\
15742 Usage: watch [-location] EXPRESSION\n\
15747 A watchpoint stops execution of your program whenever the value of\n\
15748 an expression changes."), opts
);
15749 c
= add_com ("watch", class_breakpoint
, watch_command
,
15750 watch_help
.c_str ());
15751 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15753 static const std::string rwatch_help
= gdb::option::build_help (_("\
15754 Set a read watchpoint for EXPRESSION.\n\
15755 Usage: rwatch [-location] EXPRESSION\n\
15760 A read watchpoint stops execution of your program whenever the value of\n\
15761 an expression is read."), opts
);
15762 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
15763 rwatch_help
.c_str ());
15764 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15766 static const std::string awatch_help
= gdb::option::build_help (_("\
15767 Set an access watchpoint for EXPRESSION.\n\
15768 Usage: awatch [-location] EXPRESSION\n\
15773 An access watchpoint stops execution of your program whenever the value\n\
15774 of an expression is either read or written."), opts
);
15775 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
15776 awatch_help
.c_str ());
15777 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15779 add_info ("watchpoints", info_watchpoints_command
, _("\
15780 Status of specified watchpoints (all watchpoints if no argument)."));
15782 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15783 respond to changes - contrary to the description. */
15784 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15785 &can_use_hw_watchpoints
, _("\
15786 Set debugger's willingness to use watchpoint hardware."), _("\
15787 Show debugger's willingness to use watchpoint hardware."), _("\
15788 If zero, gdb will not use hardware for new watchpoints, even if\n\
15789 such is available. (However, any hardware watchpoints that were\n\
15790 created before setting this to nonzero, will continue to use watchpoint\n\
15793 show_can_use_hw_watchpoints
,
15794 &setlist
, &showlist
);
15796 can_use_hw_watchpoints
= 1;
15798 /* Tracepoint manipulation commands. */
15800 cmd_list_element
*trace_cmd
15801 = add_com ("trace", class_breakpoint
, trace_command
, _("\
15802 Set a tracepoint at specified location.\n\
15804 BREAK_ARGS_HELP ("trace") "\n\
15805 Do \"help tracepoints\" for info on other tracepoint commands."));
15806 set_cmd_completer (trace_cmd
, location_completer
);
15808 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
15809 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
15810 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
15811 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
15813 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15814 Set a fast tracepoint at specified location.\n\
15816 BREAK_ARGS_HELP ("ftrace") "\n\
15817 Do \"help tracepoints\" for info on other tracepoint commands."));
15818 set_cmd_completer (c
, location_completer
);
15820 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15821 Set a static tracepoint at location or marker.\n\
15823 strace [LOCATION] [if CONDITION]\n\
15824 LOCATION may be a linespec, explicit, or address location (described below) \n\
15825 or -m MARKER_ID.\n\n\
15826 If a marker id is specified, probe the marker with that name. With\n\
15827 no LOCATION, uses current execution address of the selected stack frame.\n\
15828 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15829 This collects arbitrary user data passed in the probe point call to the\n\
15830 tracing library. You can inspect it when analyzing the trace buffer,\n\
15831 by printing the $_sdata variable like any other convenience variable.\n\
15833 CONDITION is a boolean expression.\n\
15834 \n" LOCATION_HELP_STRING
"\n\n\
15835 Multiple tracepoints at one place are permitted, and useful if their\n\
15836 conditions are different.\n\
15838 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15839 Do \"help tracepoints\" for info on other tracepoint commands."));
15840 set_cmd_completer (c
, location_completer
);
15842 cmd_list_element
*info_tracepoints_cmd
15843 = add_info ("tracepoints", info_tracepoints_command
, _("\
15844 Status of specified tracepoints (all tracepoints if no argument).\n\
15845 Convenience variable \"$tpnum\" contains the number of the\n\
15846 last tracepoint set."));
15848 add_info_alias ("tp", info_tracepoints_cmd
, 1);
15850 cmd_list_element
*delete_tracepoints_cmd
15851 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15852 Delete specified tracepoints.\n\
15853 Arguments are tracepoint numbers, separated by spaces.\n\
15854 No argument means delete all tracepoints."),
15856 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
15858 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15859 Disable specified tracepoints.\n\
15860 Arguments are tracepoint numbers, separated by spaces.\n\
15861 No argument means disable all tracepoints."),
15863 deprecate_cmd (c
, "disable");
15865 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15866 Enable specified tracepoints.\n\
15867 Arguments are tracepoint numbers, separated by spaces.\n\
15868 No argument means enable all tracepoints."),
15870 deprecate_cmd (c
, "enable");
15872 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15873 Set the passcount for a tracepoint.\n\
15874 The trace will end when the tracepoint has been passed 'count' times.\n\
15875 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15876 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15878 add_basic_prefix_cmd ("save", class_breakpoint
,
15879 _("Save breakpoint definitions as a script."),
15881 0/*allow-unknown*/, &cmdlist
);
15883 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15884 Save current breakpoint definitions as a script.\n\
15885 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15886 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15887 session to restore them."),
15889 set_cmd_completer (c
, filename_completer
);
15891 cmd_list_element
*save_tracepoints_cmd
15892 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15893 Save current tracepoint definitions as a script.\n\
15894 Use the 'source' command in another debug session to restore them."),
15896 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
15898 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
15899 deprecate_cmd (c
, "save tracepoints");
15901 add_basic_prefix_cmd ("breakpoint", class_maintenance
, _("\
15902 Breakpoint specific settings.\n\
15903 Configure various breakpoint-specific variables such as\n\
15904 pending breakpoint behavior."),
15905 &breakpoint_set_cmdlist
,
15906 0/*allow-unknown*/, &setlist
);
15907 add_show_prefix_cmd ("breakpoint", class_maintenance
, _("\
15908 Breakpoint specific settings.\n\
15909 Configure various breakpoint-specific variables such as\n\
15910 pending breakpoint behavior."),
15911 &breakpoint_show_cmdlist
,
15912 0/*allow-unknown*/, &showlist
);
15914 add_setshow_auto_boolean_cmd ("pending", no_class
,
15915 &pending_break_support
, _("\
15916 Set debugger's behavior regarding pending breakpoints."), _("\
15917 Show debugger's behavior regarding pending breakpoints."), _("\
15918 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15919 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15920 an error. If auto, an unrecognized breakpoint location results in a\n\
15921 user-query to see if a pending breakpoint should be created."),
15923 show_pending_break_support
,
15924 &breakpoint_set_cmdlist
,
15925 &breakpoint_show_cmdlist
);
15927 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15929 add_setshow_boolean_cmd ("auto-hw", no_class
,
15930 &automatic_hardware_breakpoints
, _("\
15931 Set automatic usage of hardware breakpoints."), _("\
15932 Show automatic usage of hardware breakpoints."), _("\
15933 If set, the debugger will automatically use hardware breakpoints for\n\
15934 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15935 a warning will be emitted for such breakpoints."),
15937 show_automatic_hardware_breakpoints
,
15938 &breakpoint_set_cmdlist
,
15939 &breakpoint_show_cmdlist
);
15941 add_setshow_boolean_cmd ("always-inserted", class_support
,
15942 &always_inserted_mode
, _("\
15943 Set mode for inserting breakpoints."), _("\
15944 Show mode for inserting breakpoints."), _("\
15945 When this mode is on, breakpoints are inserted immediately as soon as\n\
15946 they're created, kept inserted even when execution stops, and removed\n\
15947 only when the user deletes them. When this mode is off (the default),\n\
15948 breakpoints are inserted only when execution continues, and removed\n\
15949 when execution stops."),
15951 &show_always_inserted_mode
,
15952 &breakpoint_set_cmdlist
,
15953 &breakpoint_show_cmdlist
);
15955 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15956 condition_evaluation_enums
,
15957 &condition_evaluation_mode_1
, _("\
15958 Set mode of breakpoint condition evaluation."), _("\
15959 Show mode of breakpoint condition evaluation."), _("\
15960 When this is set to \"host\", breakpoint conditions will be\n\
15961 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15962 breakpoint conditions will be downloaded to the target (if the target\n\
15963 supports such feature) and conditions will be evaluated on the target's side.\n\
15964 If this is set to \"auto\" (default), this will be automatically set to\n\
15965 \"target\" if it supports condition evaluation, otherwise it will\n\
15966 be set to \"host\"."),
15967 &set_condition_evaluation_mode
,
15968 &show_condition_evaluation_mode
,
15969 &breakpoint_set_cmdlist
,
15970 &breakpoint_show_cmdlist
);
15972 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15973 Set a breakpoint for an address range.\n\
15974 break-range START-LOCATION, END-LOCATION\n\
15975 where START-LOCATION and END-LOCATION can be one of the following:\n\
15976 LINENUM, for that line in the current file,\n\
15977 FILE:LINENUM, for that line in that file,\n\
15978 +OFFSET, for that number of lines after the current line\n\
15979 or the start of the range\n\
15980 FUNCTION, for the first line in that function,\n\
15981 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15982 *ADDRESS, for the instruction at that address.\n\
15984 The breakpoint will stop execution of the inferior whenever it executes\n\
15985 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15986 range (including START-LOCATION and END-LOCATION)."));
15988 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
15989 Set a dynamic printf at specified location.\n\
15990 dprintf location,format string,arg1,arg2,...\n\
15991 location may be a linespec, explicit, or address location.\n"
15992 "\n" LOCATION_HELP_STRING
));
15993 set_cmd_completer (c
, location_completer
);
15995 add_setshow_enum_cmd ("dprintf-style", class_support
,
15996 dprintf_style_enums
, &dprintf_style
, _("\
15997 Set the style of usage for dynamic printf."), _("\
15998 Show the style of usage for dynamic printf."), _("\
15999 This setting chooses how GDB will do a dynamic printf.\n\
16000 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16001 console, as with the \"printf\" command.\n\
16002 If the value is \"call\", the print is done by calling a function in your\n\
16003 program; by default printf(), but you can choose a different function or\n\
16004 output stream by setting dprintf-function and dprintf-channel."),
16005 update_dprintf_commands
, NULL
,
16006 &setlist
, &showlist
);
16008 dprintf_function
= xstrdup ("printf");
16009 add_setshow_string_cmd ("dprintf-function", class_support
,
16010 &dprintf_function
, _("\
16011 Set the function to use for dynamic printf."), _("\
16012 Show the function to use for dynamic printf."), NULL
,
16013 update_dprintf_commands
, NULL
,
16014 &setlist
, &showlist
);
16016 dprintf_channel
= xstrdup ("");
16017 add_setshow_string_cmd ("dprintf-channel", class_support
,
16018 &dprintf_channel
, _("\
16019 Set the channel to use for dynamic printf."), _("\
16020 Show the channel to use for dynamic printf."), NULL
,
16021 update_dprintf_commands
, NULL
,
16022 &setlist
, &showlist
);
16024 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16025 &disconnected_dprintf
, _("\
16026 Set whether dprintf continues after GDB disconnects."), _("\
16027 Show whether dprintf continues after GDB disconnects."), _("\
16028 Use this to let dprintf commands continue to hit and produce output\n\
16029 even if GDB disconnects or detaches from the target."),
16032 &setlist
, &showlist
);
16034 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16035 Target agent only formatted printing, like the C \"printf\" function.\n\
16036 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
16037 This supports most C printf format specifications, like %s, %d, etc.\n\
16038 This is useful for formatted output in user-defined commands."));
16040 automatic_hardware_breakpoints
= true;
16042 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
16044 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,