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 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
228 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
231 static int strace_marker_p (struct breakpoint
*b
);
233 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
234 that are implemented on top of software or hardware breakpoints
235 (user breakpoints, internal and momentary breakpoints, etc.). */
236 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
238 /* Internal breakpoints class type. */
239 static struct breakpoint_ops internal_breakpoint_ops
;
241 /* Momentary breakpoints class type. */
242 static struct breakpoint_ops momentary_breakpoint_ops
;
244 /* The breakpoint_ops structure to be used in regular user created
246 struct breakpoint_ops bkpt_breakpoint_ops
;
248 /* Breakpoints set on probes. */
249 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
251 /* Tracepoints set on probes. */
252 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
254 /* Dynamic printf class type. */
255 struct breakpoint_ops dprintf_breakpoint_ops
;
257 /* The style in which to perform a dynamic printf. This is a user
258 option because different output options have different tradeoffs;
259 if GDB does the printing, there is better error handling if there
260 is a problem with any of the arguments, but using an inferior
261 function lets you have special-purpose printers and sending of
262 output to the same place as compiled-in print functions. */
264 static const char dprintf_style_gdb
[] = "gdb";
265 static const char dprintf_style_call
[] = "call";
266 static const char dprintf_style_agent
[] = "agent";
267 static const char *const dprintf_style_enums
[] = {
273 static const char *dprintf_style
= dprintf_style_gdb
;
275 /* The function to use for dynamic printf if the preferred style is to
276 call into the inferior. The value is simply a string that is
277 copied into the command, so it can be anything that GDB can
278 evaluate to a callable address, not necessarily a function name. */
280 static char *dprintf_function
;
282 /* The channel to use for dynamic printf if the preferred style is to
283 call into the inferior; if a nonempty string, it will be passed to
284 the call as the first argument, with the format string as the
285 second. As with the dprintf function, this can be anything that
286 GDB knows how to evaluate, so in addition to common choices like
287 "stderr", this could be an app-specific expression like
288 "mystreams[curlogger]". */
290 static char *dprintf_channel
;
292 /* True if dprintf commands should continue to operate even if GDB
294 static bool disconnected_dprintf
= true;
296 struct command_line
*
297 breakpoint_commands (struct breakpoint
*b
)
299 return b
->commands
? b
->commands
.get () : NULL
;
302 /* Flag indicating that a command has proceeded the inferior past the
303 current breakpoint. */
305 static bool breakpoint_proceeded
;
308 bpdisp_text (enum bpdisp disp
)
310 /* NOTE: the following values are a part of MI protocol and
311 represent values of 'disp' field returned when inferior stops at
313 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
315 return bpdisps
[(int) disp
];
318 /* Prototypes for exported functions. */
319 /* If FALSE, gdb will not use hardware support for watchpoints, even
320 if such is available. */
321 static int can_use_hw_watchpoints
;
324 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
325 struct cmd_list_element
*c
,
328 fprintf_filtered (file
,
329 _("Debugger's willingness to use "
330 "watchpoint hardware is %s.\n"),
334 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
335 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
336 for unrecognized breakpoint locations.
337 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
338 static enum auto_boolean pending_break_support
;
340 show_pending_break_support (struct ui_file
*file
, int from_tty
,
341 struct cmd_list_element
*c
,
344 fprintf_filtered (file
,
345 _("Debugger's behavior regarding "
346 "pending breakpoints is %s.\n"),
350 /* If true, gdb will automatically use hardware breakpoints for breakpoints
351 set with "break" but falling in read-only memory.
352 If false, gdb will warn about such breakpoints, but won't automatically
353 use hardware breakpoints. */
354 static bool automatic_hardware_breakpoints
;
356 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
357 struct cmd_list_element
*c
,
360 fprintf_filtered (file
,
361 _("Automatic usage of hardware breakpoints is %s.\n"),
365 /* If on, GDB keeps breakpoints inserted even if the inferior is
366 stopped, and immediately inserts any new breakpoints as soon as
367 they're created. If off (default), GDB keeps breakpoints off of
368 the target as long as possible. That is, it delays inserting
369 breakpoints until the next resume, and removes them again when the
370 target fully stops. This is a bit safer in case GDB crashes while
371 processing user input. */
372 static bool always_inserted_mode
= false;
375 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
376 struct cmd_list_element
*c
, const char *value
)
378 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
382 /* See breakpoint.h. */
385 breakpoints_should_be_inserted_now (void)
387 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
389 /* If breakpoints are global, they should be inserted even if no
390 thread under gdb's control is running, or even if there are
391 no threads under GDB's control yet. */
396 if (always_inserted_mode
)
398 /* The user wants breakpoints inserted even if all threads
403 for (inferior
*inf
: all_inferiors ())
404 if (inf
->has_execution ()
405 && threads_are_executing (inf
->process_target ()))
408 /* Don't remove breakpoints yet if, even though all threads are
409 stopped, we still have events to process. */
410 for (thread_info
*tp
: all_non_exited_threads ())
412 && tp
->suspend
.waitstatus_pending_p
)
418 static const char condition_evaluation_both
[] = "host or target";
420 /* Modes for breakpoint condition evaluation. */
421 static const char condition_evaluation_auto
[] = "auto";
422 static const char condition_evaluation_host
[] = "host";
423 static const char condition_evaluation_target
[] = "target";
424 static const char *const condition_evaluation_enums
[] = {
425 condition_evaluation_auto
,
426 condition_evaluation_host
,
427 condition_evaluation_target
,
431 /* Global that holds the current mode for breakpoint condition evaluation. */
432 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
434 /* Global that we use to display information to the user (gets its value from
435 condition_evaluation_mode_1. */
436 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
438 /* Translate a condition evaluation mode MODE into either "host"
439 or "target". This is used mostly to translate from "auto" to the
440 real setting that is being used. It returns the translated
444 translate_condition_evaluation_mode (const char *mode
)
446 if (mode
== condition_evaluation_auto
)
448 if (target_supports_evaluation_of_breakpoint_conditions ())
449 return condition_evaluation_target
;
451 return condition_evaluation_host
;
457 /* Discovers what condition_evaluation_auto translates to. */
460 breakpoint_condition_evaluation_mode (void)
462 return translate_condition_evaluation_mode (condition_evaluation_mode
);
465 /* Return true if GDB should evaluate breakpoint conditions or false
469 gdb_evaluates_breakpoint_condition_p (void)
471 const char *mode
= breakpoint_condition_evaluation_mode ();
473 return (mode
== condition_evaluation_host
);
476 /* Are we executing breakpoint commands? */
477 static int executing_breakpoint_commands
;
479 /* Are overlay event breakpoints enabled? */
480 static int overlay_events_enabled
;
482 /* See description in breakpoint.h. */
483 bool target_exact_watchpoints
= false;
485 /* Walk the following statement or block through all breakpoints.
486 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
487 current breakpoint. */
489 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
490 for (B = breakpoint_chain; \
491 B ? (TMP=B->next, 1): 0; \
494 /* Similar iterator for the low-level breakpoints. SAFE variant is
495 not provided so update_global_location_list must not be called
496 while executing the block of ALL_BP_LOCATIONS. */
498 #define ALL_BP_LOCATIONS(B,BP_TMP) \
499 for (BP_TMP = bp_locations; \
500 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
503 /* Iterates through locations with address ADDRESS for the currently selected
504 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
505 to where the loop should start from.
506 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
507 appropriate location to start with. */
509 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
510 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
511 BP_LOCP_TMP = BP_LOCP_START; \
513 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
514 && (*BP_LOCP_TMP)->address == ADDRESS); \
517 /* Chains of all breakpoints defined. */
519 static struct breakpoint
*breakpoint_chain
;
521 /* Breakpoint linked list range. */
523 using breakpoint_range
= next_adapter
<breakpoint
, breakpoint_iterator
>;
525 /* Return a range to iterate over all breakpoints. */
527 static breakpoint_range
530 return breakpoint_range (breakpoint_chain
);
533 /* Breakpoint linked list range, safe against deletion of the current
534 breakpoint while iterating. */
536 using breakpoint_safe_range
= basic_safe_range
<breakpoint_range
>;
538 /* Return a range to iterate over all breakpoints. This range is safe against
539 deletion of the current breakpoint while iterating. */
541 static breakpoint_safe_range
542 all_breakpoints_safe ()
544 return breakpoint_safe_range (all_breakpoints ());
547 /* See breakpoint.h. */
552 return tracepoint_range (breakpoint_chain
);
555 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
557 static struct bp_location
**bp_locations
;
559 /* Number of elements of BP_LOCATIONS. */
561 static unsigned bp_locations_count
;
563 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
564 ADDRESS for the current elements of BP_LOCATIONS which get a valid
565 result from bp_location_has_shadow. You can use it for roughly
566 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
567 an address you need to read. */
569 static CORE_ADDR bp_locations_placed_address_before_address_max
;
571 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
572 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
573 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
574 You can use it for roughly limiting the subrange of BP_LOCATIONS to
575 scan for shadow bytes for an address you need to read. */
577 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
579 /* The locations that no longer correspond to any breakpoint, unlinked
580 from the bp_locations array, but for which a hit may still be
581 reported by a target. */
582 static std::vector
<bp_location
*> moribund_locations
;
584 /* Number of last breakpoint made. */
586 static int breakpoint_count
;
588 /* The value of `breakpoint_count' before the last command that
589 created breakpoints. If the last (break-like) command created more
590 than one breakpoint, then the difference between BREAKPOINT_COUNT
591 and PREV_BREAKPOINT_COUNT is more than one. */
592 static int prev_breakpoint_count
;
594 /* Number of last tracepoint made. */
596 static int tracepoint_count
;
598 static struct cmd_list_element
*breakpoint_set_cmdlist
;
599 static struct cmd_list_element
*breakpoint_show_cmdlist
;
600 struct cmd_list_element
*save_cmdlist
;
602 /* See declaration at breakpoint.h. */
605 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
608 for (breakpoint
*b
: all_breakpoints ())
609 if (func (b
, user_data
) != 0)
615 /* Return whether a breakpoint is an active enabled breakpoint. */
617 breakpoint_enabled (struct breakpoint
*b
)
619 return (b
->enable_state
== bp_enabled
);
622 /* Set breakpoint count to NUM. */
625 set_breakpoint_count (int num
)
627 prev_breakpoint_count
= breakpoint_count
;
628 breakpoint_count
= num
;
629 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
632 /* Used by `start_rbreak_breakpoints' below, to record the current
633 breakpoint count before "rbreak" creates any breakpoint. */
634 static int rbreak_start_breakpoint_count
;
636 /* Called at the start an "rbreak" command to record the first
639 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
641 rbreak_start_breakpoint_count
= breakpoint_count
;
644 /* Called at the end of an "rbreak" command to record the last
647 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
649 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
652 /* Used in run_command to zero the hit count when a new run starts. */
655 clear_breakpoint_hit_counts (void)
657 for (breakpoint
*b
: all_breakpoints ())
662 /* Return the breakpoint with the specified number, or NULL
663 if the number does not refer to an existing breakpoint. */
666 get_breakpoint (int num
)
668 for (breakpoint
*b
: all_breakpoints ())
669 if (b
->number
== num
)
677 /* Mark locations as "conditions have changed" in case the target supports
678 evaluating conditions on its side. */
681 mark_breakpoint_modified (struct breakpoint
*b
)
683 /* This is only meaningful if the target is
684 evaluating conditions and if the user has
685 opted for condition evaluation on the target's
687 if (gdb_evaluates_breakpoint_condition_p ()
688 || !target_supports_evaluation_of_breakpoint_conditions ())
691 if (!is_breakpoint (b
))
694 for (bp_location
*loc
: b
->locations ())
695 loc
->condition_changed
= condition_modified
;
698 /* Mark location as "conditions have changed" in case the target supports
699 evaluating conditions on its side. */
702 mark_breakpoint_location_modified (struct bp_location
*loc
)
704 /* This is only meaningful if the target is
705 evaluating conditions and if the user has
706 opted for condition evaluation on the target's
708 if (gdb_evaluates_breakpoint_condition_p ()
709 || !target_supports_evaluation_of_breakpoint_conditions ())
713 if (!is_breakpoint (loc
->owner
))
716 loc
->condition_changed
= condition_modified
;
719 /* Sets the condition-evaluation mode using the static global
720 condition_evaluation_mode. */
723 set_condition_evaluation_mode (const char *args
, int from_tty
,
724 struct cmd_list_element
*c
)
726 const char *old_mode
, *new_mode
;
728 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
729 && !target_supports_evaluation_of_breakpoint_conditions ())
731 condition_evaluation_mode_1
= condition_evaluation_mode
;
732 warning (_("Target does not support breakpoint condition evaluation.\n"
733 "Using host evaluation mode instead."));
737 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
738 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
740 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
741 settings was "auto". */
742 condition_evaluation_mode
= condition_evaluation_mode_1
;
744 /* Only update the mode if the user picked a different one. */
745 if (new_mode
!= old_mode
)
747 struct bp_location
*loc
, **loc_tmp
;
748 /* If the user switched to a different evaluation mode, we
749 need to synch the changes with the target as follows:
751 "host" -> "target": Send all (valid) conditions to the target.
752 "target" -> "host": Remove all the conditions from the target.
755 if (new_mode
== condition_evaluation_target
)
757 /* Mark everything modified and synch conditions with the
759 ALL_BP_LOCATIONS (loc
, loc_tmp
)
760 mark_breakpoint_location_modified (loc
);
764 /* Manually mark non-duplicate locations to synch conditions
765 with the target. We do this to remove all the conditions the
766 target knows about. */
767 ALL_BP_LOCATIONS (loc
, loc_tmp
)
768 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
769 loc
->needs_update
= 1;
773 update_global_location_list (UGLL_MAY_INSERT
);
779 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
780 what "auto" is translating to. */
783 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
784 struct cmd_list_element
*c
, const char *value
)
786 if (condition_evaluation_mode
== condition_evaluation_auto
)
787 fprintf_filtered (file
,
788 _("Breakpoint condition evaluation "
789 "mode is %s (currently %s).\n"),
791 breakpoint_condition_evaluation_mode ());
793 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
797 /* A comparison function for bp_location AP and BP that is used by
798 bsearch. This comparison function only cares about addresses, unlike
799 the more general bp_location_is_less_than function. */
802 bp_locations_compare_addrs (const void *ap
, const void *bp
)
804 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
805 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
807 if (a
->address
== b
->address
)
810 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
813 /* Helper function to skip all bp_locations with addresses
814 less than ADDRESS. It returns the first bp_location that
815 is greater than or equal to ADDRESS. If none is found, just
818 static struct bp_location
**
819 get_first_locp_gte_addr (CORE_ADDR address
)
821 struct bp_location dummy_loc
;
822 struct bp_location
*dummy_locp
= &dummy_loc
;
823 struct bp_location
**locp_found
= NULL
;
825 /* Initialize the dummy location's address field. */
826 dummy_loc
.address
= address
;
828 /* Find a close match to the first location at ADDRESS. */
829 locp_found
= ((struct bp_location
**)
830 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
831 sizeof (struct bp_location
**),
832 bp_locations_compare_addrs
));
834 /* Nothing was found, nothing left to do. */
835 if (locp_found
== NULL
)
838 /* We may have found a location that is at ADDRESS but is not the first in the
839 location's list. Go backwards (if possible) and locate the first one. */
840 while ((locp_found
- 1) >= bp_locations
841 && (*(locp_found
- 1))->address
== address
)
847 /* Parse COND_STRING in the context of LOC and set as the condition
848 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
849 the number of LOC within its owner. In case of parsing error, mark
850 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
853 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
854 int bp_num
, int loc_num
)
856 bool has_junk
= false;
859 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
860 block_for_pc (loc
->address
), 0);
861 if (*cond_string
!= 0)
865 loc
->cond
= std::move (new_exp
);
866 if (loc
->disabled_by_cond
&& loc
->enabled
)
867 printf_filtered (_("Breakpoint %d's condition is now valid at "
868 "location %d, enabling.\n"),
871 loc
->disabled_by_cond
= false;
874 catch (const gdb_exception_error
&e
)
878 /* Warn if a user-enabled location is now becoming disabled-by-cond.
879 BP_NUM is 0 if the breakpoint is being defined for the first
880 time using the "break ... if ..." command, and non-zero if
883 warning (_("failed to validate condition at location %d.%d, "
884 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
886 warning (_("failed to validate condition at location %d, "
887 "disabling:\n %s"), loc_num
, e
.what ());
890 loc
->disabled_by_cond
= true;
894 error (_("Garbage '%s' follows condition"), cond_string
);
898 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
899 int from_tty
, bool force
)
903 xfree (b
->cond_string
);
904 b
->cond_string
= nullptr;
906 if (is_watchpoint (b
))
907 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
911 for (bp_location
*loc
: b
->locations ())
914 if (loc
->disabled_by_cond
&& loc
->enabled
)
915 printf_filtered (_("Breakpoint %d's condition is now valid at "
916 "location %d, enabling.\n"),
918 loc
->disabled_by_cond
= false;
921 /* No need to free the condition agent expression
922 bytecode (if we have one). We will handle this
923 when we go through update_global_location_list. */
928 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
932 if (is_watchpoint (b
))
934 innermost_block_tracker tracker
;
935 const char *arg
= exp
;
936 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
938 error (_("Junk at end of expression"));
939 watchpoint
*w
= static_cast<watchpoint
*> (b
);
940 w
->cond_exp
= std::move (new_exp
);
941 w
->cond_exp_valid_block
= tracker
.block ();
945 /* Parse and set condition expressions. We make two passes.
946 In the first, we parse the condition string to see if it
947 is valid in at least one location. If so, the condition
948 would be accepted. So we go ahead and set the locations'
949 conditions. In case no valid case is found, we throw
950 the error and the condition string will be rejected.
951 This two-pass approach is taken to avoid setting the
952 state of locations in case of a reject. */
953 for (bp_location
*loc
: b
->locations ())
957 const char *arg
= exp
;
958 parse_exp_1 (&arg
, loc
->address
,
959 block_for_pc (loc
->address
), 0);
961 error (_("Junk at end of expression"));
964 catch (const gdb_exception_error
&e
)
966 /* Condition string is invalid. If this happens to
967 be the last loc, abandon (if not forced) or continue
969 if (loc
->next
== nullptr && !force
)
974 /* If we reach here, the condition is valid at some locations. */
976 for (bp_location
*loc
: b
->locations ())
978 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
983 /* We know that the new condition parsed successfully. The
984 condition string of the breakpoint can be safely updated. */
985 xfree (b
->cond_string
);
986 b
->cond_string
= xstrdup (exp
);
987 b
->condition_not_parsed
= 0;
989 mark_breakpoint_modified (b
);
991 gdb::observers::breakpoint_modified
.notify (b
);
994 /* See breakpoint.h. */
997 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
1000 for (breakpoint
*b
: all_breakpoints ())
1001 if (b
->number
== bpnum
)
1003 /* Check if this breakpoint has a "stop" method implemented in an
1004 extension language. This method and conditions entered into GDB
1005 from the CLI are mutually exclusive. */
1006 const struct extension_language_defn
*extlang
1007 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1009 if (extlang
!= NULL
)
1011 error (_("Only one stop condition allowed. There is currently"
1012 " a %s stop condition defined for this breakpoint."),
1013 ext_lang_capitalized_name (extlang
));
1015 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1017 if (is_breakpoint (b
))
1018 update_global_location_list (UGLL_MAY_INSERT
);
1023 error (_("No breakpoint number %d."), bpnum
);
1026 /* The options for the "condition" command. */
1028 struct condition_command_opts
1031 bool force_condition
= false;
1034 static const gdb::option::option_def condition_command_option_defs
[] = {
1036 gdb::option::flag_option_def
<condition_command_opts
> {
1038 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1039 N_("Set the condition even if it is invalid for all current locations."),
1044 /* Create an option_def_group for the "condition" options, with
1045 CC_OPTS as context. */
1047 static inline gdb::option::option_def_group
1048 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1050 return {{condition_command_option_defs
}, cc_opts
};
1053 /* Completion for the "condition" command. */
1056 condition_completer (struct cmd_list_element
*cmd
,
1057 completion_tracker
&tracker
,
1058 const char *text
, const char * /*word*/)
1060 bool has_no_arguments
= (*text
== '\0');
1061 condition_command_opts cc_opts
;
1062 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1063 if (gdb::option::complete_options
1064 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1067 text
= skip_spaces (text
);
1068 const char *space
= skip_to_space (text
);
1075 tracker
.advance_custom_word_point_by (1);
1076 /* We don't support completion of history indices. */
1077 if (!isdigit (text
[1]))
1078 complete_internalvar (tracker
, &text
[1]);
1082 /* Suggest the "-force" flag if no arguments are given. If
1083 arguments were passed, they either already include the flag,
1084 or we are beyond the point of suggesting it because it's
1085 positionally the first argument. */
1086 if (has_no_arguments
)
1087 gdb::option::complete_on_all_options (tracker
, group
);
1089 /* We're completing the breakpoint number. */
1090 len
= strlen (text
);
1092 for (breakpoint
*b
: all_breakpoints ())
1096 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1098 if (strncmp (number
, text
, len
) == 0)
1099 tracker
.add_completion (make_unique_xstrdup (number
));
1105 /* We're completing the expression part. Skip the breakpoint num. */
1106 const char *exp_start
= skip_spaces (space
);
1107 tracker
.advance_custom_word_point_by (exp_start
- text
);
1109 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1110 expression_completer (cmd
, tracker
, text
, word
);
1113 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1116 condition_command (const char *arg
, int from_tty
)
1122 error_no_arg (_("breakpoint number"));
1126 /* Check if the "-force" flag was passed. */
1127 condition_command_opts cc_opts
;
1128 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1129 gdb::option::process_options
1130 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1132 bnum
= get_number (&p
);
1134 error (_("Bad breakpoint argument: '%s'"), arg
);
1136 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1139 /* Check that COMMAND do not contain commands that are suitable
1140 only for tracepoints and not suitable for ordinary breakpoints.
1141 Throw if any such commands is found. */
1144 check_no_tracepoint_commands (struct command_line
*commands
)
1146 struct command_line
*c
;
1148 for (c
= commands
; c
; c
= c
->next
)
1150 if (c
->control_type
== while_stepping_control
)
1151 error (_("The 'while-stepping' command can "
1152 "only be used for tracepoints"));
1154 check_no_tracepoint_commands (c
->body_list_0
.get ());
1155 check_no_tracepoint_commands (c
->body_list_1
.get ());
1157 /* Not that command parsing removes leading whitespace and comment
1158 lines and also empty lines. So, we only need to check for
1159 command directly. */
1160 if (strstr (c
->line
, "collect ") == c
->line
)
1161 error (_("The 'collect' command can only be used for tracepoints"));
1163 if (strstr (c
->line
, "teval ") == c
->line
)
1164 error (_("The 'teval' command can only be used for tracepoints"));
1168 struct longjmp_breakpoint
: public breakpoint
1170 ~longjmp_breakpoint () override
;
1173 /* Encapsulate tests for different types of tracepoints. */
1176 is_tracepoint_type (bptype type
)
1178 return (type
== bp_tracepoint
1179 || type
== bp_fast_tracepoint
1180 || type
== bp_static_tracepoint
);
1184 is_longjmp_type (bptype type
)
1186 return type
== bp_longjmp
|| type
== bp_exception
;
1189 /* See breakpoint.h. */
1192 is_tracepoint (const struct breakpoint
*b
)
1194 return is_tracepoint_type (b
->type
);
1197 /* Factory function to create an appropriate instance of breakpoint given
1200 static std::unique_ptr
<breakpoint
>
1201 new_breakpoint_from_type (bptype type
)
1205 if (is_tracepoint_type (type
))
1206 b
= new tracepoint ();
1207 else if (is_longjmp_type (type
))
1208 b
= new longjmp_breakpoint ();
1210 b
= new breakpoint ();
1212 return std::unique_ptr
<breakpoint
> (b
);
1215 /* A helper function that validates that COMMANDS are valid for a
1216 breakpoint. This function will throw an exception if a problem is
1220 validate_commands_for_breakpoint (struct breakpoint
*b
,
1221 struct command_line
*commands
)
1223 if (is_tracepoint (b
))
1225 struct tracepoint
*t
= (struct tracepoint
*) b
;
1226 struct command_line
*c
;
1227 struct command_line
*while_stepping
= 0;
1229 /* Reset the while-stepping step count. The previous commands
1230 might have included a while-stepping action, while the new
1234 /* We need to verify that each top-level element of commands is
1235 valid for tracepoints, that there's at most one
1236 while-stepping element, and that the while-stepping's body
1237 has valid tracing commands excluding nested while-stepping.
1238 We also need to validate the tracepoint action line in the
1239 context of the tracepoint --- validate_actionline actually
1240 has side effects, like setting the tracepoint's
1241 while-stepping STEP_COUNT, in addition to checking if the
1242 collect/teval actions parse and make sense in the
1243 tracepoint's context. */
1244 for (c
= commands
; c
; c
= c
->next
)
1246 if (c
->control_type
== while_stepping_control
)
1248 if (b
->type
== bp_fast_tracepoint
)
1249 error (_("The 'while-stepping' command "
1250 "cannot be used for fast tracepoint"));
1251 else if (b
->type
== bp_static_tracepoint
)
1252 error (_("The 'while-stepping' command "
1253 "cannot be used for static tracepoint"));
1256 error (_("The 'while-stepping' command "
1257 "can be used only once"));
1262 validate_actionline (c
->line
, b
);
1266 struct command_line
*c2
;
1268 gdb_assert (while_stepping
->body_list_1
== nullptr);
1269 c2
= while_stepping
->body_list_0
.get ();
1270 for (; c2
; c2
= c2
->next
)
1272 if (c2
->control_type
== while_stepping_control
)
1273 error (_("The 'while-stepping' command cannot be nested"));
1279 check_no_tracepoint_commands (commands
);
1283 /* Return a vector of all the static tracepoints set at ADDR. The
1284 caller is responsible for releasing the vector. */
1286 std::vector
<breakpoint
*>
1287 static_tracepoints_here (CORE_ADDR addr
)
1289 std::vector
<breakpoint
*> found
;
1291 for (breakpoint
*b
: all_breakpoints ())
1292 if (b
->type
== bp_static_tracepoint
)
1294 for (bp_location
*loc
: b
->locations ())
1295 if (loc
->address
== addr
)
1296 found
.push_back (b
);
1302 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1303 validate that only allowed commands are included. */
1306 breakpoint_set_commands (struct breakpoint
*b
,
1307 counted_command_line
&&commands
)
1309 validate_commands_for_breakpoint (b
, commands
.get ());
1311 b
->commands
= std::move (commands
);
1312 gdb::observers::breakpoint_modified
.notify (b
);
1315 /* Set the internal `silent' flag on the breakpoint. Note that this
1316 is not the same as the "silent" that may appear in the breakpoint's
1320 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1322 int old_silent
= b
->silent
;
1325 if (old_silent
!= silent
)
1326 gdb::observers::breakpoint_modified
.notify (b
);
1329 /* Set the thread for this breakpoint. If THREAD is -1, make the
1330 breakpoint work for any thread. */
1333 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1335 int old_thread
= b
->thread
;
1338 if (old_thread
!= thread
)
1339 gdb::observers::breakpoint_modified
.notify (b
);
1342 /* Set the task for this breakpoint. If TASK is 0, make the
1343 breakpoint work for any task. */
1346 breakpoint_set_task (struct breakpoint
*b
, int task
)
1348 int old_task
= b
->task
;
1351 if (old_task
!= task
)
1352 gdb::observers::breakpoint_modified
.notify (b
);
1356 commands_command_1 (const char *arg
, int from_tty
,
1357 struct command_line
*control
)
1359 counted_command_line cmd
;
1360 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1361 NULL after the call to read_command_lines if the user provides an empty
1362 list of command by just typing "end". */
1363 bool cmd_read
= false;
1365 std::string new_arg
;
1367 if (arg
== NULL
|| !*arg
)
1369 /* Argument not explicitly given. Synthesize it. */
1370 if (breakpoint_count
- prev_breakpoint_count
> 1)
1371 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1373 else if (breakpoint_count
> 0)
1374 new_arg
= string_printf ("%d", breakpoint_count
);
1378 /* Create a copy of ARG. This is needed because the "commands"
1379 command may be coming from a script. In that case, the read
1380 line buffer is going to be overwritten in the lambda of
1381 'map_breakpoint_numbers' below when reading the next line
1382 before we are are done parsing the breakpoint numbers. */
1385 arg
= new_arg
.c_str ();
1387 map_breakpoint_numbers
1388 (arg
, [&] (breakpoint
*b
)
1392 gdb_assert (cmd
== NULL
);
1393 if (control
!= NULL
)
1394 cmd
= control
->body_list_0
;
1398 = string_printf (_("Type commands for breakpoint(s) "
1399 "%s, one per line."),
1402 auto do_validate
= [=] (const char *line
)
1404 validate_actionline (line
, b
);
1406 gdb::function_view
<void (const char *)> validator
;
1407 if (is_tracepoint (b
))
1408 validator
= do_validate
;
1410 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1415 /* If a breakpoint was on the list more than once, we don't need to
1417 if (b
->commands
!= cmd
)
1419 validate_commands_for_breakpoint (b
, cmd
.get ());
1421 gdb::observers::breakpoint_modified
.notify (b
);
1427 commands_command (const char *arg
, int from_tty
)
1429 commands_command_1 (arg
, from_tty
, NULL
);
1432 /* Like commands_command, but instead of reading the commands from
1433 input stream, takes them from an already parsed command structure.
1435 This is used by cli-script.c to DTRT with breakpoint commands
1436 that are part of if and while bodies. */
1437 enum command_control_type
1438 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1440 commands_command_1 (arg
, 0, cmd
);
1441 return simple_control
;
1444 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1447 bp_location_has_shadow (struct bp_location
*bl
)
1449 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1453 if (bl
->target_info
.shadow_len
== 0)
1454 /* BL isn't valid, or doesn't shadow memory. */
1459 /* Update BUF, which is LEN bytes read from the target address
1460 MEMADDR, by replacing a memory breakpoint with its shadowed
1463 If READBUF is not NULL, this buffer must not overlap with the of
1464 the breakpoint location's shadow_contents buffer. Otherwise, a
1465 failed assertion internal error will be raised. */
1468 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1469 const gdb_byte
*writebuf_org
,
1470 ULONGEST memaddr
, LONGEST len
,
1471 struct bp_target_info
*target_info
,
1472 struct gdbarch
*gdbarch
)
1474 /* Now do full processing of the found relevant range of elements. */
1475 CORE_ADDR bp_addr
= 0;
1479 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1480 current_program_space
->aspace
, 0))
1482 /* The breakpoint is inserted in a different address space. */
1486 /* Addresses and length of the part of the breakpoint that
1488 bp_addr
= target_info
->placed_address
;
1489 bp_size
= target_info
->shadow_len
;
1491 if (bp_addr
+ bp_size
<= memaddr
)
1493 /* The breakpoint is entirely before the chunk of memory we are
1498 if (bp_addr
>= memaddr
+ len
)
1500 /* The breakpoint is entirely after the chunk of memory we are
1505 /* Offset within shadow_contents. */
1506 if (bp_addr
< memaddr
)
1508 /* Only copy the second part of the breakpoint. */
1509 bp_size
-= memaddr
- bp_addr
;
1510 bptoffset
= memaddr
- bp_addr
;
1514 if (bp_addr
+ bp_size
> memaddr
+ len
)
1516 /* Only copy the first part of the breakpoint. */
1517 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1520 if (readbuf
!= NULL
)
1522 /* Verify that the readbuf buffer does not overlap with the
1523 shadow_contents buffer. */
1524 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1525 || readbuf
>= (target_info
->shadow_contents
1526 + target_info
->shadow_len
));
1528 /* Update the read buffer with this inserted breakpoint's
1530 memcpy (readbuf
+ bp_addr
- memaddr
,
1531 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1535 const unsigned char *bp
;
1536 CORE_ADDR addr
= target_info
->reqstd_address
;
1539 /* Update the shadow with what we want to write to memory. */
1540 memcpy (target_info
->shadow_contents
+ bptoffset
,
1541 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1543 /* Determine appropriate breakpoint contents and size for this
1545 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1547 /* Update the final write buffer with this inserted
1548 breakpoint's INSN. */
1549 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1553 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1554 by replacing any memory breakpoints with their shadowed contents.
1556 If READBUF is not NULL, this buffer must not overlap with any of
1557 the breakpoint location's shadow_contents buffers. Otherwise,
1558 a failed assertion internal error will be raised.
1560 The range of shadowed area by each bp_location is:
1561 bl->address - bp_locations_placed_address_before_address_max
1562 up to bl->address + bp_locations_shadow_len_after_address_max
1563 The range we were requested to resolve shadows for is:
1564 memaddr ... memaddr + len
1565 Thus the safe cutoff boundaries for performance optimization are
1566 memaddr + len <= (bl->address
1567 - bp_locations_placed_address_before_address_max)
1569 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1572 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1573 const gdb_byte
*writebuf_org
,
1574 ULONGEST memaddr
, LONGEST len
)
1576 /* Left boundary, right boundary and median element of our binary
1578 unsigned bc_l
, bc_r
, bc
;
1580 /* Find BC_L which is a leftmost element which may affect BUF
1581 content. It is safe to report lower value but a failure to
1582 report higher one. */
1585 bc_r
= bp_locations_count
;
1586 while (bc_l
+ 1 < bc_r
)
1588 struct bp_location
*bl
;
1590 bc
= (bc_l
+ bc_r
) / 2;
1591 bl
= bp_locations
[bc
];
1593 /* Check first BL->ADDRESS will not overflow due to the added
1594 constant. Then advance the left boundary only if we are sure
1595 the BC element can in no way affect the BUF content (MEMADDR
1596 to MEMADDR + LEN range).
1598 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1599 offset so that we cannot miss a breakpoint with its shadow
1600 range tail still reaching MEMADDR. */
1602 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1604 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1611 /* Due to the binary search above, we need to make sure we pick the
1612 first location that's at BC_L's address. E.g., if there are
1613 multiple locations at the same address, BC_L may end up pointing
1614 at a duplicate location, and miss the "master"/"inserted"
1615 location. Say, given locations L1, L2 and L3 at addresses A and
1618 L1@A, L2@A, L3@B, ...
1620 BC_L could end up pointing at location L2, while the "master"
1621 location could be L1. Since the `loc->inserted' flag is only set
1622 on "master" locations, we'd forget to restore the shadow of L1
1625 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1628 /* Now do full processing of the found relevant range of elements. */
1630 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1632 struct bp_location
*bl
= bp_locations
[bc
];
1634 /* bp_location array has BL->OWNER always non-NULL. */
1635 if (bl
->owner
->type
== bp_none
)
1636 warning (_("reading through apparently deleted breakpoint #%d?"),
1639 /* Performance optimization: any further element can no longer affect BUF
1642 if (bl
->address
>= bp_locations_placed_address_before_address_max
1643 && memaddr
+ len
<= (bl
->address
1644 - bp_locations_placed_address_before_address_max
))
1647 if (!bp_location_has_shadow (bl
))
1650 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1651 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1655 /* See breakpoint.h. */
1658 is_breakpoint (const struct breakpoint
*bpt
)
1660 return (bpt
->type
== bp_breakpoint
1661 || bpt
->type
== bp_hardware_breakpoint
1662 || bpt
->type
== bp_dprintf
);
1665 /* Return true if BPT is of any hardware watchpoint kind. */
1668 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1670 return (bpt
->type
== bp_hardware_watchpoint
1671 || bpt
->type
== bp_read_watchpoint
1672 || bpt
->type
== bp_access_watchpoint
);
1675 /* See breakpoint.h. */
1678 is_watchpoint (const struct breakpoint
*bpt
)
1680 return (is_hardware_watchpoint (bpt
)
1681 || bpt
->type
== bp_watchpoint
);
1684 /* Returns true if the current thread and its running state are safe
1685 to evaluate or update watchpoint B. Watchpoints on local
1686 expressions need to be evaluated in the context of the thread that
1687 was current when the watchpoint was created, and, that thread needs
1688 to be stopped to be able to select the correct frame context.
1689 Watchpoints on global expressions can be evaluated on any thread,
1690 and in any state. It is presently left to the target allowing
1691 memory accesses when threads are running. */
1694 watchpoint_in_thread_scope (struct watchpoint
*b
)
1696 return (b
->pspace
== current_program_space
1697 && (b
->watchpoint_thread
== null_ptid
1698 || (inferior_ptid
== b
->watchpoint_thread
1699 && !inferior_thread ()->executing
)));
1702 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1703 associated bp_watchpoint_scope breakpoint. */
1706 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1708 if (w
->related_breakpoint
!= w
)
1710 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1711 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1712 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1713 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1714 w
->related_breakpoint
= w
;
1716 w
->disposition
= disp_del_at_next_stop
;
1719 /* Extract a bitfield value from value VAL using the bit parameters contained in
1722 static struct value
*
1723 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1725 struct value
*bit_val
;
1730 bit_val
= allocate_value (value_type (val
));
1732 unpack_value_bitfield (bit_val
,
1735 value_contents_for_printing (val
),
1742 /* Allocate a dummy location and add it to B, which must be a software
1743 watchpoint. This is required because even if a software watchpoint
1744 is not watching any memory, bpstat_stop_status requires a location
1745 to be able to report stops. */
1748 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1749 struct program_space
*pspace
)
1751 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1753 b
->loc
= allocate_bp_location (b
);
1754 b
->loc
->pspace
= pspace
;
1755 b
->loc
->address
= -1;
1756 b
->loc
->length
= -1;
1759 /* Returns true if B is a software watchpoint that is not watching any
1760 memory (e.g., "watch $pc"). */
1763 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1765 return (b
->type
== bp_watchpoint
1767 && b
->loc
->next
== NULL
1768 && b
->loc
->address
== -1
1769 && b
->loc
->length
== -1);
1772 /* Assuming that B is a watchpoint:
1773 - Reparse watchpoint expression, if REPARSE is non-zero
1774 - Evaluate expression and store the result in B->val
1775 - Evaluate the condition if there is one, and store the result
1777 - Update the list of values that must be watched in B->loc.
1779 If the watchpoint disposition is disp_del_at_next_stop, then do
1780 nothing. If this is local watchpoint that is out of scope, delete
1783 Even with `set breakpoint always-inserted on' the watchpoints are
1784 removed + inserted on each stop here. Normal breakpoints must
1785 never be removed because they might be missed by a running thread
1786 when debugging in non-stop mode. On the other hand, hardware
1787 watchpoints (is_hardware_watchpoint; processed here) are specific
1788 to each LWP since they are stored in each LWP's hardware debug
1789 registers. Therefore, such LWP must be stopped first in order to
1790 be able to modify its hardware watchpoints.
1792 Hardware watchpoints must be reset exactly once after being
1793 presented to the user. It cannot be done sooner, because it would
1794 reset the data used to present the watchpoint hit to the user. And
1795 it must not be done later because it could display the same single
1796 watchpoint hit during multiple GDB stops. Note that the latter is
1797 relevant only to the hardware watchpoint types bp_read_watchpoint
1798 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1799 not user-visible - its hit is suppressed if the memory content has
1802 The following constraints influence the location where we can reset
1803 hardware watchpoints:
1805 * target_stopped_by_watchpoint and target_stopped_data_address are
1806 called several times when GDB stops.
1809 * Multiple hardware watchpoints can be hit at the same time,
1810 causing GDB to stop. GDB only presents one hardware watchpoint
1811 hit at a time as the reason for stopping, and all the other hits
1812 are presented later, one after the other, each time the user
1813 requests the execution to be resumed. Execution is not resumed
1814 for the threads still having pending hit event stored in
1815 LWP_INFO->STATUS. While the watchpoint is already removed from
1816 the inferior on the first stop the thread hit event is kept being
1817 reported from its cached value by linux_nat_stopped_data_address
1818 until the real thread resume happens after the watchpoint gets
1819 presented and thus its LWP_INFO->STATUS gets reset.
1821 Therefore the hardware watchpoint hit can get safely reset on the
1822 watchpoint removal from inferior. */
1825 update_watchpoint (struct watchpoint
*b
, int reparse
)
1827 int within_current_scope
;
1828 struct frame_id saved_frame_id
;
1831 /* If this is a local watchpoint, we only want to check if the
1832 watchpoint frame is in scope if the current thread is the thread
1833 that was used to create the watchpoint. */
1834 if (!watchpoint_in_thread_scope (b
))
1837 if (b
->disposition
== disp_del_at_next_stop
)
1842 /* Determine if the watchpoint is within scope. */
1843 if (b
->exp_valid_block
== NULL
)
1844 within_current_scope
= 1;
1847 struct frame_info
*fi
= get_current_frame ();
1848 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1849 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1851 /* If we're at a point where the stack has been destroyed
1852 (e.g. in a function epilogue), unwinding may not work
1853 properly. Do not attempt to recreate locations at this
1854 point. See similar comments in watchpoint_check. */
1855 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1858 /* Save the current frame's ID so we can restore it after
1859 evaluating the watchpoint expression on its own frame. */
1860 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1861 took a frame parameter, so that we didn't have to change the
1864 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1866 fi
= frame_find_by_id (b
->watchpoint_frame
);
1867 within_current_scope
= (fi
!= NULL
);
1868 if (within_current_scope
)
1872 /* We don't free locations. They are stored in the bp_location array
1873 and update_global_location_list will eventually delete them and
1874 remove breakpoints if needed. */
1877 if (within_current_scope
&& reparse
)
1882 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1883 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1884 /* If the meaning of expression itself changed, the old value is
1885 no longer relevant. We don't want to report a watchpoint hit
1886 to the user when the old value and the new value may actually
1887 be completely different objects. */
1889 b
->val_valid
= false;
1891 /* Note that unlike with breakpoints, the watchpoint's condition
1892 expression is stored in the breakpoint object, not in the
1893 locations (re)created below. */
1894 if (b
->cond_string
!= NULL
)
1896 b
->cond_exp
.reset ();
1899 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1903 /* If we failed to parse the expression, for example because
1904 it refers to a global variable in a not-yet-loaded shared library,
1905 don't try to insert watchpoint. We don't automatically delete
1906 such watchpoint, though, since failure to parse expression
1907 is different from out-of-scope watchpoint. */
1908 if (!target_has_execution ())
1910 /* Without execution, memory can't change. No use to try and
1911 set watchpoint locations. The watchpoint will be reset when
1912 the target gains execution, through breakpoint_re_set. */
1913 if (!can_use_hw_watchpoints
)
1915 if (b
->ops
->works_in_software_mode (b
))
1916 b
->type
= bp_watchpoint
;
1918 error (_("Can't set read/access watchpoint when "
1919 "hardware watchpoints are disabled."));
1922 else if (within_current_scope
&& b
->exp
)
1924 std::vector
<value_ref_ptr
> val_chain
;
1925 struct value
*v
, *result
;
1926 struct program_space
*frame_pspace
;
1928 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
1931 /* Avoid setting b->val if it's already set. The meaning of
1932 b->val is 'the last value' user saw, and we should update
1933 it only if we reported that last value to user. As it
1934 happens, the code that reports it updates b->val directly.
1935 We don't keep track of the memory value for masked
1937 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1939 if (b
->val_bitsize
!= 0)
1940 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1941 b
->val
= release_value (v
);
1942 b
->val_valid
= true;
1945 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1947 /* Look at each value on the value chain. */
1948 gdb_assert (!val_chain
.empty ());
1949 for (const value_ref_ptr
&iter
: val_chain
)
1953 /* If it's a memory location, and GDB actually needed
1954 its contents to evaluate the expression, then we
1955 must watch it. If the first value returned is
1956 still lazy, that means an error occurred reading it;
1957 watch it anyway in case it becomes readable. */
1958 if (VALUE_LVAL (v
) == lval_memory
1959 && (v
== val_chain
[0] || ! value_lazy (v
)))
1961 struct type
*vtype
= check_typedef (value_type (v
));
1963 /* We only watch structs and arrays if user asked
1964 for it explicitly, never if they just happen to
1965 appear in the middle of some value chain. */
1967 || (vtype
->code () != TYPE_CODE_STRUCT
1968 && vtype
->code () != TYPE_CODE_ARRAY
))
1971 enum target_hw_bp_type type
;
1972 struct bp_location
*loc
, **tmp
;
1973 int bitpos
= 0, bitsize
= 0;
1975 if (value_bitsize (v
) != 0)
1977 /* Extract the bit parameters out from the bitfield
1979 bitpos
= value_bitpos (v
);
1980 bitsize
= value_bitsize (v
);
1982 else if (v
== result
&& b
->val_bitsize
!= 0)
1984 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1985 lvalue whose bit parameters are saved in the fields
1986 VAL_BITPOS and VAL_BITSIZE. */
1987 bitpos
= b
->val_bitpos
;
1988 bitsize
= b
->val_bitsize
;
1991 addr
= value_address (v
);
1994 /* Skip the bytes that don't contain the bitfield. */
1999 if (b
->type
== bp_read_watchpoint
)
2001 else if (b
->type
== bp_access_watchpoint
)
2004 loc
= allocate_bp_location (b
);
2005 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2008 loc
->gdbarch
= value_type (v
)->arch ();
2010 loc
->pspace
= frame_pspace
;
2011 loc
->address
= address_significant (loc
->gdbarch
, addr
);
2015 /* Just cover the bytes that make up the bitfield. */
2016 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2019 loc
->length
= TYPE_LENGTH (value_type (v
));
2021 loc
->watchpoint_type
= type
;
2026 /* Change the type of breakpoint between hardware assisted or
2027 an ordinary watchpoint depending on the hardware support
2028 and free hardware slots. REPARSE is set when the inferior
2033 enum bp_loc_type loc_type
;
2035 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2039 int i
, target_resources_ok
, other_type_used
;
2042 /* Use an exact watchpoint when there's only one memory region to be
2043 watched, and only one debug register is needed to watch it. */
2044 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2046 /* We need to determine how many resources are already
2047 used for all other hardware watchpoints plus this one
2048 to see if we still have enough resources to also fit
2049 this watchpoint in as well. */
2051 /* If this is a software watchpoint, we try to turn it
2052 to a hardware one -- count resources as if B was of
2053 hardware watchpoint type. */
2055 if (type
== bp_watchpoint
)
2056 type
= bp_hardware_watchpoint
;
2058 /* This watchpoint may or may not have been placed on
2059 the list yet at this point (it won't be in the list
2060 if we're trying to create it for the first time,
2061 through watch_command), so always account for it
2064 /* Count resources used by all watchpoints except B. */
2065 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2067 /* Add in the resources needed for B. */
2068 i
+= hw_watchpoint_use_count (b
);
2071 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2072 if (target_resources_ok
<= 0)
2074 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2076 if (target_resources_ok
== 0 && !sw_mode
)
2077 error (_("Target does not support this type of "
2078 "hardware watchpoint."));
2079 else if (target_resources_ok
< 0 && !sw_mode
)
2080 error (_("There are not enough available hardware "
2081 "resources for this watchpoint."));
2083 /* Downgrade to software watchpoint. */
2084 b
->type
= bp_watchpoint
;
2088 /* If this was a software watchpoint, we've just
2089 found we have enough resources to turn it to a
2090 hardware watchpoint. Otherwise, this is a
2095 else if (!b
->ops
->works_in_software_mode (b
))
2097 if (!can_use_hw_watchpoints
)
2098 error (_("Can't set read/access watchpoint when "
2099 "hardware watchpoints are disabled."));
2101 error (_("Expression cannot be implemented with "
2102 "read/access watchpoint."));
2105 b
->type
= bp_watchpoint
;
2107 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2108 : bp_loc_hardware_watchpoint
);
2109 for (bp_location
*bl
: b
->locations ())
2110 bl
->loc_type
= loc_type
;
2113 /* If a software watchpoint is not watching any memory, then the
2114 above left it without any location set up. But,
2115 bpstat_stop_status requires a location to be able to report
2116 stops, so make sure there's at least a dummy one. */
2117 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2118 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2120 else if (!within_current_scope
)
2122 printf_filtered (_("\
2123 Watchpoint %d deleted because the program has left the block\n\
2124 in which its expression is valid.\n"),
2126 watchpoint_del_at_next_stop (b
);
2129 /* Restore the selected frame. */
2131 select_frame (frame_find_by_id (saved_frame_id
));
2135 /* Returns 1 iff breakpoint location should be
2136 inserted in the inferior. We don't differentiate the type of BL's owner
2137 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2138 breakpoint_ops is not defined, because in insert_bp_location,
2139 tracepoint's insert_location will not be called. */
2141 should_be_inserted (struct bp_location
*bl
)
2143 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2146 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2149 if (!bl
->enabled
|| bl
->disabled_by_cond
2150 || bl
->shlib_disabled
|| bl
->duplicate
)
2153 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2156 /* This is set for example, when we're attached to the parent of a
2157 vfork, and have detached from the child. The child is running
2158 free, and we expect it to do an exec or exit, at which point the
2159 OS makes the parent schedulable again (and the target reports
2160 that the vfork is done). Until the child is done with the shared
2161 memory region, do not insert breakpoints in the parent, otherwise
2162 the child could still trip on the parent's breakpoints. Since
2163 the parent is blocked anyway, it won't miss any breakpoint. */
2164 if (bl
->pspace
->breakpoints_not_allowed
)
2167 /* Don't insert a breakpoint if we're trying to step past its
2168 location, except if the breakpoint is a single-step breakpoint,
2169 and the breakpoint's thread is the thread which is stepping past
2171 if ((bl
->loc_type
== bp_loc_software_breakpoint
2172 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2173 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2175 /* The single-step breakpoint may be inserted at the location
2176 we're trying to step if the instruction branches to itself.
2177 However, the instruction won't be executed at all and it may
2178 break the semantics of the instruction, for example, the
2179 instruction is a conditional branch or updates some flags.
2180 We can't fix it unless GDB is able to emulate the instruction
2181 or switch to displaced stepping. */
2182 && !(bl
->owner
->type
== bp_single_step
2183 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2185 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2186 paddress (bl
->gdbarch
, bl
->address
));
2190 /* Don't insert watchpoints if we're trying to step past the
2191 instruction that triggered one. */
2192 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2193 && stepping_past_nonsteppable_watchpoint ())
2195 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2196 "skipping watchpoint at %s:%d",
2197 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2204 /* Same as should_be_inserted but does the check assuming
2205 that the location is not duplicated. */
2208 unduplicated_should_be_inserted (struct bp_location
*bl
)
2211 const int save_duplicate
= bl
->duplicate
;
2214 result
= should_be_inserted (bl
);
2215 bl
->duplicate
= save_duplicate
;
2219 /* Parses a conditional described by an expression COND into an
2220 agent expression bytecode suitable for evaluation
2221 by the bytecode interpreter. Return NULL if there was
2222 any error during parsing. */
2224 static agent_expr_up
2225 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2230 agent_expr_up aexpr
;
2232 /* We don't want to stop processing, so catch any errors
2233 that may show up. */
2236 aexpr
= gen_eval_for_expr (scope
, cond
);
2239 catch (const gdb_exception_error
&ex
)
2241 /* If we got here, it means the condition could not be parsed to a valid
2242 bytecode expression and thus can't be evaluated on the target's side.
2243 It's no use iterating through the conditions. */
2246 /* We have a valid agent expression. */
2250 /* Based on location BL, create a list of breakpoint conditions to be
2251 passed on to the target. If we have duplicated locations with different
2252 conditions, we will add such conditions to the list. The idea is that the
2253 target will evaluate the list of conditions and will only notify GDB when
2254 one of them is true. */
2257 build_target_condition_list (struct bp_location
*bl
)
2259 struct bp_location
**locp
= NULL
, **loc2p
;
2260 int null_condition_or_parse_error
= 0;
2261 int modified
= bl
->needs_update
;
2262 struct bp_location
*loc
;
2264 /* Release conditions left over from a previous insert. */
2265 bl
->target_info
.conditions
.clear ();
2267 /* This is only meaningful if the target is
2268 evaluating conditions and if the user has
2269 opted for condition evaluation on the target's
2271 if (gdb_evaluates_breakpoint_condition_p ()
2272 || !target_supports_evaluation_of_breakpoint_conditions ())
2275 /* Do a first pass to check for locations with no assigned
2276 conditions or conditions that fail to parse to a valid agent
2277 expression bytecode. If any of these happen, then it's no use to
2278 send conditions to the target since this location will always
2279 trigger and generate a response back to GDB. Note we consider
2280 all locations at the same address irrespective of type, i.e.,
2281 even if the locations aren't considered duplicates (e.g.,
2282 software breakpoint and hardware breakpoint at the same
2284 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2287 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2291 /* Re-parse the conditions since something changed. In that
2292 case we already freed the condition bytecodes (see
2293 force_breakpoint_reinsertion). We just
2294 need to parse the condition to bytecodes again. */
2295 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2299 /* If we have a NULL bytecode expression, it means something
2300 went wrong or we have a null condition expression. */
2301 if (!loc
->cond_bytecode
)
2303 null_condition_or_parse_error
= 1;
2309 /* If any of these happened, it means we will have to evaluate the conditions
2310 for the location's address on gdb's side. It is no use keeping bytecodes
2311 for all the other duplicate locations, thus we free all of them here.
2313 This is so we have a finer control over which locations' conditions are
2314 being evaluated by GDB or the remote stub. */
2315 if (null_condition_or_parse_error
)
2317 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2320 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2322 /* Only go as far as the first NULL bytecode is
2324 if (!loc
->cond_bytecode
)
2327 loc
->cond_bytecode
.reset ();
2332 /* No NULL conditions or failed bytecode generation. Build a
2333 condition list for this location's address. If we have software
2334 and hardware locations at the same address, they aren't
2335 considered duplicates, but we still marge all the conditions
2336 anyway, as it's simpler, and doesn't really make a practical
2338 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2342 && is_breakpoint (loc
->owner
)
2343 && loc
->pspace
->num
== bl
->pspace
->num
2344 && loc
->owner
->enable_state
== bp_enabled
2346 && !loc
->disabled_by_cond
)
2348 /* Add the condition to the vector. This will be used later
2349 to send the conditions to the target. */
2350 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2357 /* Parses a command described by string CMD into an agent expression
2358 bytecode suitable for evaluation by the bytecode interpreter.
2359 Return NULL if there was any error during parsing. */
2361 static agent_expr_up
2362 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2364 const char *cmdrest
;
2365 const char *format_start
, *format_end
;
2366 struct gdbarch
*gdbarch
= get_current_arch ();
2373 if (*cmdrest
== ',')
2375 cmdrest
= skip_spaces (cmdrest
);
2377 if (*cmdrest
++ != '"')
2378 error (_("No format string following the location"));
2380 format_start
= cmdrest
;
2382 format_pieces
fpieces (&cmdrest
);
2384 format_end
= cmdrest
;
2386 if (*cmdrest
++ != '"')
2387 error (_("Bad format string, non-terminated '\"'."));
2389 cmdrest
= skip_spaces (cmdrest
);
2391 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2392 error (_("Invalid argument syntax"));
2394 if (*cmdrest
== ',')
2396 cmdrest
= skip_spaces (cmdrest
);
2398 /* For each argument, make an expression. */
2400 std::vector
<struct expression
*> argvec
;
2401 while (*cmdrest
!= '\0')
2406 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2407 argvec
.push_back (expr
.release ());
2409 if (*cmdrest
== ',')
2413 agent_expr_up aexpr
;
2415 /* We don't want to stop processing, so catch any errors
2416 that may show up. */
2419 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2420 format_start
, format_end
- format_start
,
2421 argvec
.size (), argvec
.data ());
2423 catch (const gdb_exception_error
&ex
)
2425 /* If we got here, it means the command could not be parsed to a valid
2426 bytecode expression and thus can't be evaluated on the target's side.
2427 It's no use iterating through the other commands. */
2430 /* We have a valid agent expression, return it. */
2434 /* Based on location BL, create a list of breakpoint commands to be
2435 passed on to the target. If we have duplicated locations with
2436 different commands, we will add any such to the list. */
2439 build_target_command_list (struct bp_location
*bl
)
2441 struct bp_location
**locp
= NULL
, **loc2p
;
2442 int null_command_or_parse_error
= 0;
2443 int modified
= bl
->needs_update
;
2444 struct bp_location
*loc
;
2446 /* Clear commands left over from a previous insert. */
2447 bl
->target_info
.tcommands
.clear ();
2449 if (!target_can_run_breakpoint_commands ())
2452 /* For now, limit to agent-style dprintf breakpoints. */
2453 if (dprintf_style
!= dprintf_style_agent
)
2456 /* For now, if we have any location at the same address that isn't a
2457 dprintf, don't install the target-side commands, as that would
2458 make the breakpoint not be reported to the core, and we'd lose
2460 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2463 if (is_breakpoint (loc
->owner
)
2464 && loc
->pspace
->num
== bl
->pspace
->num
2465 && loc
->owner
->type
!= bp_dprintf
)
2469 /* Do a first pass to check for locations with no assigned
2470 conditions or conditions that fail to parse to a valid agent expression
2471 bytecode. If any of these happen, then it's no use to send conditions
2472 to the target since this location will always trigger and generate a
2473 response back to GDB. */
2474 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2477 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2481 /* Re-parse the commands since something changed. In that
2482 case we already freed the command bytecodes (see
2483 force_breakpoint_reinsertion). We just
2484 need to parse the command to bytecodes again. */
2486 = parse_cmd_to_aexpr (bl
->address
,
2487 loc
->owner
->extra_string
);
2490 /* If we have a NULL bytecode expression, it means something
2491 went wrong or we have a null command expression. */
2492 if (!loc
->cmd_bytecode
)
2494 null_command_or_parse_error
= 1;
2500 /* If anything failed, then we're not doing target-side commands,
2502 if (null_command_or_parse_error
)
2504 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2507 if (is_breakpoint (loc
->owner
)
2508 && loc
->pspace
->num
== bl
->pspace
->num
)
2510 /* Only go as far as the first NULL bytecode is
2512 if (loc
->cmd_bytecode
== NULL
)
2515 loc
->cmd_bytecode
.reset ();
2520 /* No NULL commands or failed bytecode generation. Build a command
2521 list for all duplicate locations at this location's address.
2522 Note that here we must care for whether the breakpoint location
2523 types are considered duplicates, otherwise, say, if we have a
2524 software and hardware location at the same address, the target
2525 could end up running the commands twice. For the moment, we only
2526 support targets-side commands with dprintf, but it doesn't hurt
2527 to be pedantically correct in case that changes. */
2528 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2531 if (breakpoint_locations_match (bl
, loc
)
2532 && loc
->owner
->extra_string
2533 && is_breakpoint (loc
->owner
)
2534 && loc
->pspace
->num
== bl
->pspace
->num
2535 && loc
->owner
->enable_state
== bp_enabled
2537 && !loc
->disabled_by_cond
)
2539 /* Add the command to the vector. This will be used later
2540 to send the commands to the target. */
2541 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2545 bl
->target_info
.persist
= 0;
2546 /* Maybe flag this location as persistent. */
2547 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2548 bl
->target_info
.persist
= 1;
2551 /* Return the kind of breakpoint on address *ADDR. Get the kind
2552 of breakpoint according to ADDR except single-step breakpoint.
2553 Get the kind of single-step breakpoint according to the current
2557 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2559 if (bl
->owner
->type
== bp_single_step
)
2561 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2562 struct regcache
*regcache
;
2564 regcache
= get_thread_regcache (thr
);
2566 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2570 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2573 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2574 location. Any error messages are printed to TMP_ERROR_STREAM; and
2575 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2576 Returns 0 for success, 1 if the bp_location type is not supported or
2579 NOTE drow/2003-09-09: This routine could be broken down to an
2580 object-style method for each breakpoint or catchpoint type. */
2582 insert_bp_location (struct bp_location
*bl
,
2583 struct ui_file
*tmp_error_stream
,
2584 int *disabled_breaks
,
2585 int *hw_breakpoint_error
,
2586 int *hw_bp_error_explained_already
)
2588 gdb_exception bp_excpt
;
2590 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2593 /* Note we don't initialize bl->target_info, as that wipes out
2594 the breakpoint location's shadow_contents if the breakpoint
2595 is still inserted at that location. This in turn breaks
2596 target_read_memory which depends on these buffers when
2597 a memory read is requested at the breakpoint location:
2598 Once the target_info has been wiped, we fail to see that
2599 we have a breakpoint inserted at that address and thus
2600 read the breakpoint instead of returning the data saved in
2601 the breakpoint location's shadow contents. */
2602 bl
->target_info
.reqstd_address
= bl
->address
;
2603 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2604 bl
->target_info
.length
= bl
->length
;
2606 /* When working with target-side conditions, we must pass all the conditions
2607 for the same breakpoint address down to the target since GDB will not
2608 insert those locations. With a list of breakpoint conditions, the target
2609 can decide when to stop and notify GDB. */
2611 if (is_breakpoint (bl
->owner
))
2613 build_target_condition_list (bl
);
2614 build_target_command_list (bl
);
2615 /* Reset the modification marker. */
2616 bl
->needs_update
= 0;
2619 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2620 set at a read-only address, then a breakpoint location will have
2621 been changed to hardware breakpoint before we get here. If it is
2622 "off" however, error out before actually trying to insert the
2623 breakpoint, with a nicer error message. */
2624 if (bl
->loc_type
== bp_loc_software_breakpoint
2625 && !automatic_hardware_breakpoints
)
2627 mem_region
*mr
= lookup_mem_region (bl
->address
);
2629 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2631 fprintf_unfiltered (tmp_error_stream
,
2632 _("Cannot insert breakpoint %d.\n"
2633 "Cannot set software breakpoint "
2634 "at read-only address %s\n"),
2636 paddress (bl
->gdbarch
, bl
->address
));
2641 if (bl
->loc_type
== bp_loc_software_breakpoint
2642 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2644 /* First check to see if we have to handle an overlay. */
2645 if (overlay_debugging
== ovly_off
2646 || bl
->section
== NULL
2647 || !(section_is_overlay (bl
->section
)))
2649 /* No overlay handling: just set the breakpoint. */
2654 val
= bl
->owner
->ops
->insert_location (bl
);
2656 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2658 catch (gdb_exception
&e
)
2660 bp_excpt
= std::move (e
);
2665 /* This breakpoint is in an overlay section.
2666 Shall we set a breakpoint at the LMA? */
2667 if (!overlay_events_enabled
)
2669 /* Yes -- overlay event support is not active,
2670 so we must try to set a breakpoint at the LMA.
2671 This will not work for a hardware breakpoint. */
2672 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2673 warning (_("hardware breakpoint %d not supported in overlay!"),
2677 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2679 /* Set a software (trap) breakpoint at the LMA. */
2680 bl
->overlay_target_info
= bl
->target_info
;
2681 bl
->overlay_target_info
.reqstd_address
= addr
;
2683 /* No overlay handling: just set the breakpoint. */
2688 bl
->overlay_target_info
.kind
2689 = breakpoint_kind (bl
, &addr
);
2690 bl
->overlay_target_info
.placed_address
= addr
;
2691 val
= target_insert_breakpoint (bl
->gdbarch
,
2692 &bl
->overlay_target_info
);
2695 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2697 catch (gdb_exception
&e
)
2699 bp_excpt
= std::move (e
);
2702 if (bp_excpt
.reason
!= 0)
2703 fprintf_unfiltered (tmp_error_stream
,
2704 "Overlay breakpoint %d "
2705 "failed: in ROM?\n",
2709 /* Shall we set a breakpoint at the VMA? */
2710 if (section_is_mapped (bl
->section
))
2712 /* Yes. This overlay section is mapped into memory. */
2717 val
= bl
->owner
->ops
->insert_location (bl
);
2719 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2721 catch (gdb_exception
&e
)
2723 bp_excpt
= std::move (e
);
2728 /* No. This breakpoint will not be inserted.
2729 No error, but do not mark the bp as 'inserted'. */
2734 if (bp_excpt
.reason
!= 0)
2736 /* Can't set the breakpoint. */
2738 /* In some cases, we might not be able to insert a
2739 breakpoint in a shared library that has already been
2740 removed, but we have not yet processed the shlib unload
2741 event. Unfortunately, some targets that implement
2742 breakpoint insertion themselves can't tell why the
2743 breakpoint insertion failed (e.g., the remote target
2744 doesn't define error codes), so we must treat generic
2745 errors as memory errors. */
2746 if (bp_excpt
.reason
== RETURN_ERROR
2747 && (bp_excpt
.error
== GENERIC_ERROR
2748 || bp_excpt
.error
== MEMORY_ERROR
)
2749 && bl
->loc_type
== bp_loc_software_breakpoint
2750 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2751 || shared_objfile_contains_address_p (bl
->pspace
,
2754 /* See also: disable_breakpoints_in_shlibs. */
2755 bl
->shlib_disabled
= 1;
2756 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2757 if (!*disabled_breaks
)
2759 fprintf_unfiltered (tmp_error_stream
,
2760 "Cannot insert breakpoint %d.\n",
2762 fprintf_unfiltered (tmp_error_stream
,
2763 "Temporarily disabling shared "
2764 "library breakpoints:\n");
2766 *disabled_breaks
= 1;
2767 fprintf_unfiltered (tmp_error_stream
,
2768 "breakpoint #%d\n", bl
->owner
->number
);
2773 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2775 *hw_breakpoint_error
= 1;
2776 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2777 fprintf_unfiltered (tmp_error_stream
,
2778 "Cannot insert hardware breakpoint %d%s",
2780 bp_excpt
.message
? ":" : ".\n");
2781 if (bp_excpt
.message
!= NULL
)
2782 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2787 if (bp_excpt
.message
== NULL
)
2790 = memory_error_message (TARGET_XFER_E_IO
,
2791 bl
->gdbarch
, bl
->address
);
2793 fprintf_unfiltered (tmp_error_stream
,
2794 "Cannot insert breakpoint %d.\n"
2796 bl
->owner
->number
, message
.c_str ());
2800 fprintf_unfiltered (tmp_error_stream
,
2801 "Cannot insert breakpoint %d: %s\n",
2816 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2817 /* NOTE drow/2003-09-08: This state only exists for removing
2818 watchpoints. It's not clear that it's necessary... */
2819 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2823 gdb_assert (bl
->owner
->ops
!= NULL
2824 && bl
->owner
->ops
->insert_location
!= NULL
);
2826 val
= bl
->owner
->ops
->insert_location (bl
);
2828 /* If trying to set a read-watchpoint, and it turns out it's not
2829 supported, try emulating one with an access watchpoint. */
2830 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2832 struct bp_location
*loc
, **loc_temp
;
2834 /* But don't try to insert it, if there's already another
2835 hw_access location that would be considered a duplicate
2837 ALL_BP_LOCATIONS (loc
, loc_temp
)
2839 && loc
->watchpoint_type
== hw_access
2840 && watchpoint_locations_match (bl
, loc
))
2844 bl
->target_info
= loc
->target_info
;
2845 bl
->watchpoint_type
= hw_access
;
2852 bl
->watchpoint_type
= hw_access
;
2853 val
= bl
->owner
->ops
->insert_location (bl
);
2856 /* Back to the original value. */
2857 bl
->watchpoint_type
= hw_read
;
2861 bl
->inserted
= (val
== 0);
2864 else if (bl
->owner
->type
== bp_catchpoint
)
2868 gdb_assert (bl
->owner
->ops
!= NULL
2869 && bl
->owner
->ops
->insert_location
!= NULL
);
2871 val
= bl
->owner
->ops
->insert_location (bl
);
2874 bl
->owner
->enable_state
= bp_disabled
;
2878 Error inserting catchpoint %d: Your system does not support this type\n\
2879 of catchpoint."), bl
->owner
->number
);
2881 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2884 bl
->inserted
= (val
== 0);
2886 /* We've already printed an error message if there was a problem
2887 inserting this catchpoint, and we've disabled the catchpoint,
2888 so just return success. */
2895 /* This function is called when program space PSPACE is about to be
2896 deleted. It takes care of updating breakpoints to not reference
2900 breakpoint_program_space_exit (struct program_space
*pspace
)
2902 struct bp_location
*loc
, **loc_temp
;
2904 /* Remove any breakpoint that was set through this program space. */
2905 for (breakpoint
*b
: all_breakpoints_safe ())
2906 if (b
->pspace
== pspace
)
2907 delete_breakpoint (b
);
2909 /* Breakpoints set through other program spaces could have locations
2910 bound to PSPACE as well. Remove those. */
2911 ALL_BP_LOCATIONS (loc
, loc_temp
)
2913 struct bp_location
*tmp
;
2915 if (loc
->pspace
== pspace
)
2917 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2918 if (loc
->owner
->loc
== loc
)
2919 loc
->owner
->loc
= loc
->next
;
2921 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2922 if (tmp
->next
== loc
)
2924 tmp
->next
= loc
->next
;
2930 /* Now update the global location list to permanently delete the
2931 removed locations above. */
2932 update_global_location_list (UGLL_DONT_INSERT
);
2935 /* Make sure all breakpoints are inserted in inferior.
2936 Throws exception on any error.
2937 A breakpoint that is already inserted won't be inserted
2938 again, so calling this function twice is safe. */
2940 insert_breakpoints (void)
2942 for (breakpoint
*bpt
: all_breakpoints ())
2943 if (is_hardware_watchpoint (bpt
))
2945 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2947 update_watchpoint (w
, 0 /* don't reparse. */);
2950 /* Updating watchpoints creates new locations, so update the global
2951 location list. Explicitly tell ugll to insert locations and
2952 ignore breakpoints_always_inserted_mode. Also,
2953 update_global_location_list tries to "upgrade" software
2954 breakpoints to hardware breakpoints to handle "set breakpoint
2955 auto-hw", so we need to call it even if we don't have new
2957 update_global_location_list (UGLL_INSERT
);
2960 /* Invoke CALLBACK for each of bp_location. */
2963 iterate_over_bp_locations (gdb::function_view
<void (bp_location
*)> callback
)
2965 struct bp_location
*loc
, **loc_tmp
;
2967 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2973 /* This is used when we need to synch breakpoint conditions between GDB and the
2974 target. It is the case with deleting and disabling of breakpoints when using
2975 always-inserted mode. */
2978 update_inserted_breakpoint_locations (void)
2980 struct bp_location
*bl
, **blp_tmp
;
2983 int disabled_breaks
= 0;
2984 int hw_breakpoint_error
= 0;
2985 int hw_bp_details_reported
= 0;
2987 string_file tmp_error_stream
;
2989 /* Explicitly mark the warning -- this will only be printed if
2990 there was an error. */
2991 tmp_error_stream
.puts ("Warning:\n");
2993 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2995 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2997 /* We only want to update software breakpoints and hardware
2999 if (!is_breakpoint (bl
->owner
))
3002 /* We only want to update locations that are already inserted
3003 and need updating. This is to avoid unwanted insertion during
3004 deletion of breakpoints. */
3005 if (!bl
->inserted
|| !bl
->needs_update
)
3008 switch_to_program_space_and_thread (bl
->pspace
);
3010 /* For targets that support global breakpoints, there's no need
3011 to select an inferior to insert breakpoint to. In fact, even
3012 if we aren't attached to any process yet, we should still
3013 insert breakpoints. */
3014 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3015 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3018 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3019 &hw_breakpoint_error
, &hw_bp_details_reported
);
3026 target_terminal::ours_for_output ();
3027 error_stream (tmp_error_stream
);
3031 /* Used when starting or continuing the program. */
3034 insert_breakpoint_locations (void)
3036 struct bp_location
*bl
, **blp_tmp
;
3039 int disabled_breaks
= 0;
3040 int hw_breakpoint_error
= 0;
3041 int hw_bp_error_explained_already
= 0;
3043 string_file tmp_error_stream
;
3045 /* Explicitly mark the warning -- this will only be printed if
3046 there was an error. */
3047 tmp_error_stream
.puts ("Warning:\n");
3049 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3051 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3053 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3056 /* There is no point inserting thread-specific breakpoints if
3057 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3058 has BL->OWNER always non-NULL. */
3059 if (bl
->owner
->thread
!= -1
3060 && !valid_global_thread_id (bl
->owner
->thread
))
3063 switch_to_program_space_and_thread (bl
->pspace
);
3065 /* For targets that support global breakpoints, there's no need
3066 to select an inferior to insert breakpoint to. In fact, even
3067 if we aren't attached to any process yet, we should still
3068 insert breakpoints. */
3069 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3070 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3073 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3074 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3079 /* If we failed to insert all locations of a watchpoint, remove
3080 them, as half-inserted watchpoint is of limited use. */
3081 for (breakpoint
*bpt
: all_breakpoints ())
3083 int some_failed
= 0;
3085 if (!is_hardware_watchpoint (bpt
))
3088 if (!breakpoint_enabled (bpt
))
3091 if (bpt
->disposition
== disp_del_at_next_stop
)
3094 for (bp_location
*loc
: bpt
->locations ())
3095 if (!loc
->inserted
&& should_be_inserted (loc
))
3103 for (bp_location
*loc
: bpt
->locations ())
3105 remove_breakpoint (loc
);
3107 hw_breakpoint_error
= 1;
3108 tmp_error_stream
.printf ("Could not insert "
3109 "hardware watchpoint %d.\n",
3117 /* If a hardware breakpoint or watchpoint was inserted, add a
3118 message about possibly exhausted resources. */
3119 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3121 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3122 You may have requested too many hardware breakpoints/watchpoints.\n");
3124 target_terminal::ours_for_output ();
3125 error_stream (tmp_error_stream
);
3129 /* Used when the program stops.
3130 Returns zero if successful, or non-zero if there was a problem
3131 removing a breakpoint location. */
3134 remove_breakpoints (void)
3136 struct bp_location
*bl
, **blp_tmp
;
3139 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3141 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3142 val
|= remove_breakpoint (bl
);
3147 /* When a thread exits, remove breakpoints that are related to
3151 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3153 for (breakpoint
*b
: all_breakpoints_safe ())
3155 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3157 b
->disposition
= disp_del_at_next_stop
;
3159 printf_filtered (_("\
3160 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3161 b
->number
, print_thread_id (tp
));
3163 /* Hide it from the user. */
3169 /* See breakpoint.h. */
3172 remove_breakpoints_inf (inferior
*inf
)
3174 struct bp_location
*bl
, **blp_tmp
;
3177 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3179 if (bl
->pspace
!= inf
->pspace
)
3182 if (bl
->inserted
&& !bl
->target_info
.persist
)
3184 val
= remove_breakpoint (bl
);
3191 static int internal_breakpoint_number
= -1;
3193 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3194 If INTERNAL is non-zero, the breakpoint number will be populated
3195 from internal_breakpoint_number and that variable decremented.
3196 Otherwise the breakpoint number will be populated from
3197 breakpoint_count and that value incremented. Internal breakpoints
3198 do not set the internal var bpnum. */
3200 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3203 b
->number
= internal_breakpoint_number
--;
3206 set_breakpoint_count (breakpoint_count
+ 1);
3207 b
->number
= breakpoint_count
;
3211 static struct breakpoint
*
3212 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3213 CORE_ADDR address
, enum bptype type
,
3214 const struct breakpoint_ops
*ops
)
3216 symtab_and_line sal
;
3218 sal
.section
= find_pc_overlay (sal
.pc
);
3219 sal
.pspace
= current_program_space
;
3221 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3222 b
->number
= internal_breakpoint_number
--;
3223 b
->disposition
= disp_donttouch
;
3228 static const char *const longjmp_names
[] =
3230 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3232 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3234 /* Per-objfile data private to breakpoint.c. */
3235 struct breakpoint_objfile_data
3237 /* Minimal symbol for "_ovly_debug_event" (if any). */
3238 struct bound_minimal_symbol overlay_msym
{};
3240 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3241 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3243 /* True if we have looked for longjmp probes. */
3244 int longjmp_searched
= 0;
3246 /* SystemTap probe points for longjmp (if any). These are non-owning
3248 std::vector
<probe
*> longjmp_probes
;
3250 /* Minimal symbol for "std::terminate()" (if any). */
3251 struct bound_minimal_symbol terminate_msym
{};
3253 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3254 struct bound_minimal_symbol exception_msym
{};
3256 /* True if we have looked for exception probes. */
3257 int exception_searched
= 0;
3259 /* SystemTap probe points for unwinding (if any). These are non-owning
3261 std::vector
<probe
*> exception_probes
;
3264 static const struct objfile_key
<breakpoint_objfile_data
>
3265 breakpoint_objfile_key
;
3267 /* Minimal symbol not found sentinel. */
3268 static struct minimal_symbol msym_not_found
;
3270 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3273 msym_not_found_p (const struct minimal_symbol
*msym
)
3275 return msym
== &msym_not_found
;
3278 /* Return per-objfile data needed by breakpoint.c.
3279 Allocate the data if necessary. */
3281 static struct breakpoint_objfile_data
*
3282 get_breakpoint_objfile_data (struct objfile
*objfile
)
3284 struct breakpoint_objfile_data
*bp_objfile_data
;
3286 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3287 if (bp_objfile_data
== NULL
)
3288 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3289 return bp_objfile_data
;
3293 create_overlay_event_breakpoint (void)
3295 const char *const func_name
= "_ovly_debug_event";
3297 for (objfile
*objfile
: current_program_space
->objfiles ())
3299 struct breakpoint
*b
;
3300 struct breakpoint_objfile_data
*bp_objfile_data
;
3302 struct explicit_location explicit_loc
;
3304 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3306 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3309 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3311 struct bound_minimal_symbol m
;
3313 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3314 if (m
.minsym
== NULL
)
3316 /* Avoid future lookups in this objfile. */
3317 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3320 bp_objfile_data
->overlay_msym
= m
;
3323 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3324 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3326 &internal_breakpoint_ops
);
3327 initialize_explicit_location (&explicit_loc
);
3328 explicit_loc
.function_name
= ASTRDUP (func_name
);
3329 b
->location
= new_explicit_location (&explicit_loc
);
3331 if (overlay_debugging
== ovly_auto
)
3333 b
->enable_state
= bp_enabled
;
3334 overlay_events_enabled
= 1;
3338 b
->enable_state
= bp_disabled
;
3339 overlay_events_enabled
= 0;
3344 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3345 true if a breakpoint was installed. */
3348 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3350 struct gdbarch
*gdbarch
= objfile
->arch ();
3351 struct breakpoint_objfile_data
*bp_objfile_data
3352 = get_breakpoint_objfile_data (objfile
);
3354 if (!bp_objfile_data
->longjmp_searched
)
3356 std::vector
<probe
*> ret
3357 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3361 /* We are only interested in checking one element. */
3364 if (!p
->can_evaluate_arguments ())
3366 /* We cannot use the probe interface here,
3367 because it does not know how to evaluate
3372 bp_objfile_data
->longjmp_probes
= ret
;
3373 bp_objfile_data
->longjmp_searched
= 1;
3376 if (bp_objfile_data
->longjmp_probes
.empty ())
3379 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3381 struct breakpoint
*b
;
3383 b
= create_internal_breakpoint (gdbarch
,
3384 p
->get_relocated_address (objfile
),
3386 &internal_breakpoint_ops
);
3387 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3388 b
->enable_state
= bp_disabled
;
3394 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3395 Return true if at least one breakpoint was installed. */
3398 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3400 struct gdbarch
*gdbarch
= objfile
->arch ();
3401 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3404 struct breakpoint_objfile_data
*bp_objfile_data
3405 = get_breakpoint_objfile_data (objfile
);
3406 unsigned int installed_bp
= 0;
3408 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3410 struct breakpoint
*b
;
3411 const char *func_name
;
3413 struct explicit_location explicit_loc
;
3415 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3418 func_name
= longjmp_names
[i
];
3419 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3421 struct bound_minimal_symbol m
;
3423 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3424 if (m
.minsym
== NULL
)
3426 /* Prevent future lookups in this objfile. */
3427 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3430 bp_objfile_data
->longjmp_msym
[i
] = m
;
3433 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3434 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3435 &internal_breakpoint_ops
);
3436 initialize_explicit_location (&explicit_loc
);
3437 explicit_loc
.function_name
= ASTRDUP (func_name
);
3438 b
->location
= new_explicit_location (&explicit_loc
);
3439 b
->enable_state
= bp_disabled
;
3443 return installed_bp
> 0;
3446 /* Create a master longjmp breakpoint. */
3449 create_longjmp_master_breakpoint (void)
3451 scoped_restore_current_program_space restore_pspace
;
3453 for (struct program_space
*pspace
: program_spaces
)
3455 set_current_program_space (pspace
);
3457 for (objfile
*obj
: current_program_space
->objfiles ())
3459 /* Skip separate debug object, it's handled in the loop below. */
3460 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3463 /* Try a probe kind breakpoint on main objfile. */
3464 if (create_longjmp_master_breakpoint_probe (obj
))
3467 /* Try longjmp_names kind breakpoints on main and separate_debug
3469 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3470 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3476 /* Create a master std::terminate breakpoint. */
3478 create_std_terminate_master_breakpoint (void)
3480 const char *const func_name
= "std::terminate()";
3482 scoped_restore_current_program_space restore_pspace
;
3484 for (struct program_space
*pspace
: program_spaces
)
3488 set_current_program_space (pspace
);
3490 for (objfile
*objfile
: current_program_space
->objfiles ())
3492 struct breakpoint
*b
;
3493 struct breakpoint_objfile_data
*bp_objfile_data
;
3494 struct explicit_location explicit_loc
;
3496 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3498 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3501 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3503 struct bound_minimal_symbol m
;
3505 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3506 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3507 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3509 /* Prevent future lookups in this objfile. */
3510 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3513 bp_objfile_data
->terminate_msym
= m
;
3516 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3517 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3518 bp_std_terminate_master
,
3519 &internal_breakpoint_ops
);
3520 initialize_explicit_location (&explicit_loc
);
3521 explicit_loc
.function_name
= ASTRDUP (func_name
);
3522 b
->location
= new_explicit_location (&explicit_loc
);
3523 b
->enable_state
= bp_disabled
;
3528 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3529 probe. Return true if a breakpoint was installed. */
3532 create_exception_master_breakpoint_probe (objfile
*objfile
)
3534 struct breakpoint
*b
;
3535 struct gdbarch
*gdbarch
;
3536 struct breakpoint_objfile_data
*bp_objfile_data
;
3538 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3540 /* We prefer the SystemTap probe point if it exists. */
3541 if (!bp_objfile_data
->exception_searched
)
3543 std::vector
<probe
*> ret
3544 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3548 /* We are only interested in checking one element. */
3551 if (!p
->can_evaluate_arguments ())
3553 /* We cannot use the probe interface here, because it does
3554 not know how to evaluate arguments. */
3558 bp_objfile_data
->exception_probes
= ret
;
3559 bp_objfile_data
->exception_searched
= 1;
3562 if (bp_objfile_data
->exception_probes
.empty ())
3565 gdbarch
= objfile
->arch ();
3567 for (probe
*p
: bp_objfile_data
->exception_probes
)
3569 b
= create_internal_breakpoint (gdbarch
,
3570 p
->get_relocated_address (objfile
),
3571 bp_exception_master
,
3572 &internal_breakpoint_ops
);
3573 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3574 b
->enable_state
= bp_disabled
;
3580 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3581 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3584 create_exception_master_breakpoint_hook (objfile
*objfile
)
3586 const char *const func_name
= "_Unwind_DebugHook";
3587 struct breakpoint
*b
;
3588 struct gdbarch
*gdbarch
;
3589 struct breakpoint_objfile_data
*bp_objfile_data
;
3591 struct explicit_location explicit_loc
;
3593 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3595 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3598 gdbarch
= objfile
->arch ();
3600 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3602 struct bound_minimal_symbol debug_hook
;
3604 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3605 if (debug_hook
.minsym
== NULL
)
3607 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3611 bp_objfile_data
->exception_msym
= debug_hook
;
3614 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3615 addr
= gdbarch_convert_from_func_ptr_addr
3616 (gdbarch
, addr
, current_inferior ()->top_target ());
3617 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3618 &internal_breakpoint_ops
);
3619 initialize_explicit_location (&explicit_loc
);
3620 explicit_loc
.function_name
= ASTRDUP (func_name
);
3621 b
->location
= new_explicit_location (&explicit_loc
);
3622 b
->enable_state
= bp_disabled
;
3627 /* Install a master breakpoint on the unwinder's debug hook. */
3630 create_exception_master_breakpoint (void)
3632 for (objfile
*obj
: current_program_space
->objfiles ())
3634 /* Skip separate debug object. */
3635 if (obj
->separate_debug_objfile_backlink
)
3638 /* Try a probe kind breakpoint. */
3639 if (create_exception_master_breakpoint_probe (obj
))
3642 /* Iterate over main and separate debug objects and try an
3643 _Unwind_DebugHook kind breakpoint. */
3644 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3645 if (create_exception_master_breakpoint_hook (debug_objfile
))
3650 /* Does B have a location spec? */
3653 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3655 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3659 update_breakpoints_after_exec (void)
3661 struct bp_location
*bploc
, **bplocp_tmp
;
3663 /* We're about to delete breakpoints from GDB's lists. If the
3664 INSERTED flag is true, GDB will try to lift the breakpoints by
3665 writing the breakpoints' "shadow contents" back into memory. The
3666 "shadow contents" are NOT valid after an exec, so GDB should not
3667 do that. Instead, the target is responsible from marking
3668 breakpoints out as soon as it detects an exec. We don't do that
3669 here instead, because there may be other attempts to delete
3670 breakpoints after detecting an exec and before reaching here. */
3671 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3672 if (bploc
->pspace
== current_program_space
)
3673 gdb_assert (!bploc
->inserted
);
3675 for (breakpoint
*b
: all_breakpoints_safe ())
3677 if (b
->pspace
!= current_program_space
)
3680 /* Solib breakpoints must be explicitly reset after an exec(). */
3681 if (b
->type
== bp_shlib_event
)
3683 delete_breakpoint (b
);
3687 /* JIT breakpoints must be explicitly reset after an exec(). */
3688 if (b
->type
== bp_jit_event
)
3690 delete_breakpoint (b
);
3694 /* Thread event breakpoints must be set anew after an exec(),
3695 as must overlay event and longjmp master breakpoints. */
3696 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3697 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3698 || b
->type
== bp_exception_master
)
3700 delete_breakpoint (b
);
3704 /* Step-resume breakpoints are meaningless after an exec(). */
3705 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3707 delete_breakpoint (b
);
3711 /* Just like single-step breakpoints. */
3712 if (b
->type
== bp_single_step
)
3714 delete_breakpoint (b
);
3718 /* Longjmp and longjmp-resume breakpoints are also meaningless
3720 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3721 || b
->type
== bp_longjmp_call_dummy
3722 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3724 delete_breakpoint (b
);
3728 if (b
->type
== bp_catchpoint
)
3730 /* For now, none of the bp_catchpoint breakpoints need to
3731 do anything at this point. In the future, if some of
3732 the catchpoints need to something, we will need to add
3733 a new method, and call this method from here. */
3737 /* bp_finish is a special case. The only way we ought to be able
3738 to see one of these when an exec() has happened, is if the user
3739 caught a vfork, and then said "finish". Ordinarily a finish just
3740 carries them to the call-site of the current callee, by setting
3741 a temporary bp there and resuming. But in this case, the finish
3742 will carry them entirely through the vfork & exec.
3744 We don't want to allow a bp_finish to remain inserted now. But
3745 we can't safely delete it, 'cause finish_command has a handle to
3746 the bp on a bpstat, and will later want to delete it. There's a
3747 chance (and I've seen it happen) that if we delete the bp_finish
3748 here, that its storage will get reused by the time finish_command
3749 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3750 We really must allow finish_command to delete a bp_finish.
3752 In the absence of a general solution for the "how do we know
3753 it's safe to delete something others may have handles to?"
3754 problem, what we'll do here is just uninsert the bp_finish, and
3755 let finish_command delete it.
3757 (We know the bp_finish is "doomed" in the sense that it's
3758 momentary, and will be deleted as soon as finish_command sees
3759 the inferior stopped. So it doesn't matter that the bp's
3760 address is probably bogus in the new a.out, unlike e.g., the
3761 solib breakpoints.) */
3763 if (b
->type
== bp_finish
)
3768 /* Without a symbolic address, we have little hope of the
3769 pre-exec() address meaning the same thing in the post-exec()
3771 if (breakpoint_event_location_empty_p (b
))
3773 delete_breakpoint (b
);
3780 detach_breakpoints (ptid_t ptid
)
3782 struct bp_location
*bl
, **blp_tmp
;
3784 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3785 struct inferior
*inf
= current_inferior ();
3787 if (ptid
.pid () == inferior_ptid
.pid ())
3788 error (_("Cannot detach breakpoints of inferior_ptid"));
3790 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3791 inferior_ptid
= ptid
;
3792 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3794 if (bl
->pspace
!= inf
->pspace
)
3797 /* This function must physically remove breakpoints locations
3798 from the specified ptid, without modifying the breakpoint
3799 package's state. Locations of type bp_loc_other are only
3800 maintained at GDB side. So, there is no need to remove
3801 these bp_loc_other locations. Moreover, removing these
3802 would modify the breakpoint package's state. */
3803 if (bl
->loc_type
== bp_loc_other
)
3807 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3813 /* Remove the breakpoint location BL from the current address space.
3814 Note that this is used to detach breakpoints from a child fork.
3815 When we get here, the child isn't in the inferior list, and neither
3816 do we have objects to represent its address space --- we should
3817 *not* look at bl->pspace->aspace here. */
3820 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3824 /* BL is never in moribund_locations by our callers. */
3825 gdb_assert (bl
->owner
!= NULL
);
3827 /* The type of none suggests that owner is actually deleted.
3828 This should not ever happen. */
3829 gdb_assert (bl
->owner
->type
!= bp_none
);
3831 if (bl
->loc_type
== bp_loc_software_breakpoint
3832 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3834 /* "Normal" instruction breakpoint: either the standard
3835 trap-instruction bp (bp_breakpoint), or a
3836 bp_hardware_breakpoint. */
3838 /* First check to see if we have to handle an overlay. */
3839 if (overlay_debugging
== ovly_off
3840 || bl
->section
== NULL
3841 || !(section_is_overlay (bl
->section
)))
3843 /* No overlay handling: just remove the breakpoint. */
3845 /* If we're trying to uninsert a memory breakpoint that we
3846 know is set in a dynamic object that is marked
3847 shlib_disabled, then either the dynamic object was
3848 removed with "remove-symbol-file" or with
3849 "nosharedlibrary". In the former case, we don't know
3850 whether another dynamic object might have loaded over the
3851 breakpoint's address -- the user might well let us know
3852 about it next with add-symbol-file (the whole point of
3853 add-symbol-file is letting the user manually maintain a
3854 list of dynamically loaded objects). If we have the
3855 breakpoint's shadow memory, that is, this is a software
3856 breakpoint managed by GDB, check whether the breakpoint
3857 is still inserted in memory, to avoid overwriting wrong
3858 code with stale saved shadow contents. Note that HW
3859 breakpoints don't have shadow memory, as they're
3860 implemented using a mechanism that is not dependent on
3861 being able to modify the target's memory, and as such
3862 they should always be removed. */
3863 if (bl
->shlib_disabled
3864 && bl
->target_info
.shadow_len
!= 0
3865 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3868 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3872 /* This breakpoint is in an overlay section.
3873 Did we set a breakpoint at the LMA? */
3874 if (!overlay_events_enabled
)
3876 /* Yes -- overlay event support is not active, so we
3877 should have set a breakpoint at the LMA. Remove it.
3879 /* Ignore any failures: if the LMA is in ROM, we will
3880 have already warned when we failed to insert it. */
3881 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3882 target_remove_hw_breakpoint (bl
->gdbarch
,
3883 &bl
->overlay_target_info
);
3885 target_remove_breakpoint (bl
->gdbarch
,
3886 &bl
->overlay_target_info
,
3889 /* Did we set a breakpoint at the VMA?
3890 If so, we will have marked the breakpoint 'inserted'. */
3893 /* Yes -- remove it. Previously we did not bother to
3894 remove the breakpoint if the section had been
3895 unmapped, but let's not rely on that being safe. We
3896 don't know what the overlay manager might do. */
3898 /* However, we should remove *software* breakpoints only
3899 if the section is still mapped, or else we overwrite
3900 wrong code with the saved shadow contents. */
3901 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3902 || section_is_mapped (bl
->section
))
3903 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3909 /* No -- not inserted, so no need to remove. No error. */
3914 /* In some cases, we might not be able to remove a breakpoint in
3915 a shared library that has already been removed, but we have
3916 not yet processed the shlib unload event. Similarly for an
3917 unloaded add-symbol-file object - the user might not yet have
3918 had the chance to remove-symbol-file it. shlib_disabled will
3919 be set if the library/object has already been removed, but
3920 the breakpoint hasn't been uninserted yet, e.g., after
3921 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3922 always-inserted mode. */
3924 && (bl
->loc_type
== bp_loc_software_breakpoint
3925 && (bl
->shlib_disabled
3926 || solib_name_from_address (bl
->pspace
, bl
->address
)
3927 || shared_objfile_contains_address_p (bl
->pspace
,
3933 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3935 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3937 gdb_assert (bl
->owner
->ops
!= NULL
3938 && bl
->owner
->ops
->remove_location
!= NULL
);
3940 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3941 bl
->owner
->ops
->remove_location (bl
, reason
);
3943 /* Failure to remove any of the hardware watchpoints comes here. */
3944 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3945 warning (_("Could not remove hardware watchpoint %d."),
3948 else if (bl
->owner
->type
== bp_catchpoint
3949 && breakpoint_enabled (bl
->owner
)
3952 gdb_assert (bl
->owner
->ops
!= NULL
3953 && bl
->owner
->ops
->remove_location
!= NULL
);
3955 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3959 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3966 remove_breakpoint (struct bp_location
*bl
)
3968 /* BL is never in moribund_locations by our callers. */
3969 gdb_assert (bl
->owner
!= NULL
);
3971 /* The type of none suggests that owner is actually deleted.
3972 This should not ever happen. */
3973 gdb_assert (bl
->owner
->type
!= bp_none
);
3975 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3977 switch_to_program_space_and_thread (bl
->pspace
);
3979 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3982 /* Clear the "inserted" flag in all breakpoints. */
3985 mark_breakpoints_out (void)
3987 struct bp_location
*bl
, **blp_tmp
;
3989 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3990 if (bl
->pspace
== current_program_space
)
3994 /* Clear the "inserted" flag in all breakpoints and delete any
3995 breakpoints which should go away between runs of the program.
3997 Plus other such housekeeping that has to be done for breakpoints
4000 Note: this function gets called at the end of a run (by
4001 generic_mourn_inferior) and when a run begins (by
4002 init_wait_for_inferior). */
4007 breakpoint_init_inferior (enum inf_context context
)
4009 struct program_space
*pspace
= current_program_space
;
4011 /* If breakpoint locations are shared across processes, then there's
4013 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4016 mark_breakpoints_out ();
4018 for (breakpoint
*b
: all_breakpoints_safe ())
4020 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4026 case bp_longjmp_call_dummy
:
4028 /* If the call dummy breakpoint is at the entry point it will
4029 cause problems when the inferior is rerun, so we better get
4032 case bp_watchpoint_scope
:
4034 /* Also get rid of scope breakpoints. */
4036 case bp_shlib_event
:
4038 /* Also remove solib event breakpoints. Their addresses may
4039 have changed since the last time we ran the program.
4040 Actually we may now be debugging against different target;
4041 and so the solib backend that installed this breakpoint may
4042 not be used in by the target. E.g.,
4044 (gdb) file prog-linux
4045 (gdb) run # native linux target
4048 (gdb) file prog-win.exe
4049 (gdb) tar rem :9999 # remote Windows gdbserver.
4052 case bp_step_resume
:
4054 /* Also remove step-resume breakpoints. */
4056 case bp_single_step
:
4058 /* Also remove single-step breakpoints. */
4060 delete_breakpoint (b
);
4064 case bp_hardware_watchpoint
:
4065 case bp_read_watchpoint
:
4066 case bp_access_watchpoint
:
4068 struct watchpoint
*w
= (struct watchpoint
*) b
;
4070 /* Likewise for watchpoints on local expressions. */
4071 if (w
->exp_valid_block
!= NULL
)
4072 delete_breakpoint (b
);
4075 /* Get rid of existing locations, which are no longer
4076 valid. New ones will be created in
4077 update_watchpoint, when the inferior is restarted.
4078 The next update_global_location_list call will
4079 garbage collect them. */
4082 if (context
== inf_starting
)
4084 /* Reset val field to force reread of starting value in
4085 insert_breakpoints. */
4086 w
->val
.reset (nullptr);
4087 w
->val_valid
= false;
4097 /* Get rid of the moribund locations. */
4098 for (bp_location
*bl
: moribund_locations
)
4099 decref_bp_location (&bl
);
4100 moribund_locations
.clear ();
4103 /* These functions concern about actual breakpoints inserted in the
4104 target --- to e.g. check if we need to do decr_pc adjustment or if
4105 we need to hop over the bkpt --- so we check for address space
4106 match, not program space. */
4108 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4109 exists at PC. It returns ordinary_breakpoint_here if it's an
4110 ordinary breakpoint, or permanent_breakpoint_here if it's a
4111 permanent breakpoint.
4112 - When continuing from a location with an ordinary breakpoint, we
4113 actually single step once before calling insert_breakpoints.
4114 - When continuing from a location with a permanent breakpoint, we
4115 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4116 the target, to advance the PC past the breakpoint. */
4118 enum breakpoint_here
4119 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4121 struct bp_location
*bl
, **blp_tmp
;
4122 int any_breakpoint_here
= 0;
4124 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4126 if (bl
->loc_type
!= bp_loc_software_breakpoint
4127 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4130 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4131 if ((breakpoint_enabled (bl
->owner
)
4133 && breakpoint_location_address_match (bl
, aspace
, pc
))
4135 if (overlay_debugging
4136 && section_is_overlay (bl
->section
)
4137 && !section_is_mapped (bl
->section
))
4138 continue; /* unmapped overlay -- can't be a match */
4139 else if (bl
->permanent
)
4140 return permanent_breakpoint_here
;
4142 any_breakpoint_here
= 1;
4146 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4149 /* See breakpoint.h. */
4152 breakpoint_in_range_p (const address_space
*aspace
,
4153 CORE_ADDR addr
, ULONGEST len
)
4155 struct bp_location
*bl
, **blp_tmp
;
4157 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4159 if (bl
->loc_type
!= bp_loc_software_breakpoint
4160 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4163 if ((breakpoint_enabled (bl
->owner
)
4165 && breakpoint_location_address_range_overlap (bl
, aspace
,
4168 if (overlay_debugging
4169 && section_is_overlay (bl
->section
)
4170 && !section_is_mapped (bl
->section
))
4172 /* Unmapped overlay -- can't be a match. */
4183 /* Return true if there's a moribund breakpoint at PC. */
4186 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4188 for (bp_location
*loc
: moribund_locations
)
4189 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4195 /* Returns non-zero iff BL is inserted at PC, in address space
4199 bp_location_inserted_here_p (struct bp_location
*bl
,
4200 const address_space
*aspace
, CORE_ADDR pc
)
4203 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4206 if (overlay_debugging
4207 && section_is_overlay (bl
->section
)
4208 && !section_is_mapped (bl
->section
))
4209 return 0; /* unmapped overlay -- can't be a match */
4216 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4219 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4221 struct bp_location
**blp
, **blp_tmp
= NULL
;
4223 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4225 struct bp_location
*bl
= *blp
;
4227 if (bl
->loc_type
!= bp_loc_software_breakpoint
4228 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4231 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4237 /* This function returns non-zero iff there is a software breakpoint
4241 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4244 struct bp_location
**blp
, **blp_tmp
= NULL
;
4246 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4248 struct bp_location
*bl
= *blp
;
4250 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4253 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4260 /* See breakpoint.h. */
4263 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4266 struct bp_location
**blp
, **blp_tmp
= NULL
;
4268 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4270 struct bp_location
*bl
= *blp
;
4272 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4275 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4283 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4284 CORE_ADDR addr
, ULONGEST len
)
4286 for (breakpoint
*bpt
: all_breakpoints ())
4288 if (bpt
->type
!= bp_hardware_watchpoint
4289 && bpt
->type
!= bp_access_watchpoint
)
4292 if (!breakpoint_enabled (bpt
))
4295 for (bp_location
*loc
: bpt
->locations ())
4296 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4300 /* Check for intersection. */
4301 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4302 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4310 /* See breakpoint.h. */
4313 is_catchpoint (struct breakpoint
*b
)
4315 return (b
->type
== bp_catchpoint
);
4318 /* Clear a bpstat so that it says we are not at any breakpoint.
4319 Also free any storage that is part of a bpstat. */
4322 bpstat_clear (bpstat
*bsp
)
4339 bpstats::bpstats (const bpstats
&other
)
4341 bp_location_at (other
.bp_location_at
),
4342 breakpoint_at (other
.breakpoint_at
),
4343 commands (other
.commands
),
4344 print (other
.print
),
4346 print_it (other
.print_it
)
4348 if (other
.old_val
!= NULL
)
4349 old_val
= release_value (value_copy (other
.old_val
.get ()));
4352 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4353 is part of the bpstat is copied as well. */
4356 bpstat_copy (bpstat bs
)
4360 bpstat retval
= NULL
;
4365 for (; bs
!= NULL
; bs
= bs
->next
)
4367 tmp
= new bpstats (*bs
);
4370 /* This is the first thing in the chain. */
4380 /* Find the bpstat associated with this breakpoint. */
4383 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4388 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4390 if (bsp
->breakpoint_at
== breakpoint
)
4396 /* See breakpoint.h. */
4399 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4401 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4403 if (bsp
->breakpoint_at
== NULL
)
4405 /* A moribund location can never explain a signal other than
4407 if (sig
== GDB_SIGNAL_TRAP
)
4412 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4421 /* Put in *NUM the breakpoint number of the first breakpoint we are
4422 stopped at. *BSP upon return is a bpstat which points to the
4423 remaining breakpoints stopped at (but which is not guaranteed to be
4424 good for anything but further calls to bpstat_num).
4426 Return 0 if passed a bpstat which does not indicate any breakpoints.
4427 Return -1 if stopped at a breakpoint that has been deleted since
4429 Return 1 otherwise. */
4432 bpstat_num (bpstat
*bsp
, int *num
)
4434 struct breakpoint
*b
;
4437 return 0; /* No more breakpoint values */
4439 /* We assume we'll never have several bpstats that correspond to a
4440 single breakpoint -- otherwise, this function might return the
4441 same number more than once and this will look ugly. */
4442 b
= (*bsp
)->breakpoint_at
;
4443 *bsp
= (*bsp
)->next
;
4445 return -1; /* breakpoint that's been deleted since */
4447 *num
= b
->number
; /* We have its number */
4451 /* See breakpoint.h. */
4454 bpstat_clear_actions (void)
4458 if (inferior_ptid
== null_ptid
)
4461 thread_info
*tp
= inferior_thread ();
4462 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4464 bs
->commands
= NULL
;
4465 bs
->old_val
.reset (nullptr);
4469 /* Called when a command is about to proceed the inferior. */
4472 breakpoint_about_to_proceed (void)
4474 if (inferior_ptid
!= null_ptid
)
4476 struct thread_info
*tp
= inferior_thread ();
4478 /* Allow inferior function calls in breakpoint commands to not
4479 interrupt the command list. When the call finishes
4480 successfully, the inferior will be standing at the same
4481 breakpoint as if nothing happened. */
4482 if (tp
->control
.in_infcall
)
4486 breakpoint_proceeded
= 1;
4489 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4490 or its equivalent. */
4493 command_line_is_silent (struct command_line
*cmd
)
4495 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4498 /* Execute all the commands associated with all the breakpoints at
4499 this location. Any of these commands could cause the process to
4500 proceed beyond this point, etc. We look out for such changes by
4501 checking the global "breakpoint_proceeded" after each command.
4503 Returns true if a breakpoint command resumed the inferior. In that
4504 case, it is the caller's responsibility to recall it again with the
4505 bpstat of the current thread. */
4508 bpstat_do_actions_1 (bpstat
*bsp
)
4513 /* Avoid endless recursion if a `source' command is contained
4515 if (executing_breakpoint_commands
)
4518 scoped_restore save_executing
4519 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4521 scoped_restore preventer
= prevent_dont_repeat ();
4523 /* This pointer will iterate over the list of bpstat's. */
4526 breakpoint_proceeded
= 0;
4527 for (; bs
!= NULL
; bs
= bs
->next
)
4529 struct command_line
*cmd
= NULL
;
4531 /* Take ownership of the BSP's command tree, if it has one.
4533 The command tree could legitimately contain commands like
4534 'step' and 'next', which call clear_proceed_status, which
4535 frees stop_bpstat's command tree. To make sure this doesn't
4536 free the tree we're executing out from under us, we need to
4537 take ownership of the tree ourselves. Since a given bpstat's
4538 commands are only executed once, we don't need to copy it; we
4539 can clear the pointer in the bpstat, and make sure we free
4540 the tree when we're done. */
4541 counted_command_line ccmd
= bs
->commands
;
4542 bs
->commands
= NULL
;
4545 if (command_line_is_silent (cmd
))
4547 /* The action has been already done by bpstat_stop_status. */
4553 execute_control_command (cmd
);
4555 if (breakpoint_proceeded
)
4561 if (breakpoint_proceeded
)
4563 if (current_ui
->async
)
4564 /* If we are in async mode, then the target might be still
4565 running, not stopped at any breakpoint, so nothing for
4566 us to do here -- just return to the event loop. */
4569 /* In sync mode, when execute_control_command returns
4570 we're already standing on the next breakpoint.
4571 Breakpoint commands for that stop were not run, since
4572 execute_command does not run breakpoint commands --
4573 only command_line_handler does, but that one is not
4574 involved in execution of breakpoint commands. So, we
4575 can now execute breakpoint commands. It should be
4576 noted that making execute_command do bpstat actions is
4577 not an option -- in this case we'll have recursive
4578 invocation of bpstat for each breakpoint with a
4579 command, and can easily blow up GDB stack. Instead, we
4580 return true, which will trigger the caller to recall us
4581 with the new stop_bpstat. */
4589 /* Helper for bpstat_do_actions. Get the current thread, if there's
4590 one, is alive and has execution. Return NULL otherwise. */
4592 static thread_info
*
4593 get_bpstat_thread ()
4595 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4598 thread_info
*tp
= inferior_thread ();
4599 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4605 bpstat_do_actions (void)
4607 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4610 /* Do any commands attached to breakpoint we are stopped at. */
4611 while ((tp
= get_bpstat_thread ()) != NULL
)
4613 /* Since in sync mode, bpstat_do_actions may resume the
4614 inferior, and only return when it is stopped at the next
4615 breakpoint, we keep doing breakpoint actions until it returns
4616 false to indicate the inferior was not resumed. */
4617 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4621 cleanup_if_error
.release ();
4624 /* Print out the (old or new) value associated with a watchpoint. */
4627 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4630 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4633 struct value_print_options opts
;
4634 get_user_print_options (&opts
);
4635 value_print (val
, stream
, &opts
);
4639 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4640 debugging multiple threads. */
4643 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4645 if (uiout
->is_mi_like_p ())
4650 if (show_thread_that_caused_stop ())
4653 struct thread_info
*thr
= inferior_thread ();
4655 uiout
->text ("Thread ");
4656 uiout
->field_string ("thread-id", print_thread_id (thr
));
4658 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4661 uiout
->text (" \"");
4662 uiout
->field_string ("name", name
);
4666 uiout
->text (" hit ");
4670 /* Generic routine for printing messages indicating why we
4671 stopped. The behavior of this function depends on the value
4672 'print_it' in the bpstat structure. Under some circumstances we
4673 may decide not to print anything here and delegate the task to
4676 static enum print_stop_action
4677 print_bp_stop_message (bpstat bs
)
4679 switch (bs
->print_it
)
4682 /* Nothing should be printed for this bpstat entry. */
4683 return PRINT_UNKNOWN
;
4687 /* We still want to print the frame, but we already printed the
4688 relevant messages. */
4689 return PRINT_SRC_AND_LOC
;
4692 case print_it_normal
:
4694 struct breakpoint
*b
= bs
->breakpoint_at
;
4696 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4697 which has since been deleted. */
4699 return PRINT_UNKNOWN
;
4701 /* Normal case. Call the breakpoint's print_it method. */
4702 return b
->ops
->print_it (bs
);
4707 internal_error (__FILE__
, __LINE__
,
4708 _("print_bp_stop_message: unrecognized enum value"));
4713 /* A helper function that prints a shared library stopped event. */
4716 print_solib_event (int is_catchpoint
)
4718 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4719 bool any_added
= !current_program_space
->added_solibs
.empty ();
4723 if (any_added
|| any_deleted
)
4724 current_uiout
->text (_("Stopped due to shared library event:\n"));
4726 current_uiout
->text (_("Stopped due to shared library event (no "
4727 "libraries added or removed)\n"));
4730 if (current_uiout
->is_mi_like_p ())
4731 current_uiout
->field_string ("reason",
4732 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4736 current_uiout
->text (_(" Inferior unloaded "));
4737 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4738 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4740 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4743 current_uiout
->text (" ");
4744 current_uiout
->field_string ("library", name
);
4745 current_uiout
->text ("\n");
4751 current_uiout
->text (_(" Inferior loaded "));
4752 ui_out_emit_list
list_emitter (current_uiout
, "added");
4754 for (so_list
*iter
: current_program_space
->added_solibs
)
4757 current_uiout
->text (" ");
4759 current_uiout
->field_string ("library", iter
->so_name
);
4760 current_uiout
->text ("\n");
4765 /* Print a message indicating what happened. This is called from
4766 normal_stop(). The input to this routine is the head of the bpstat
4767 list - a list of the eventpoints that caused this stop. KIND is
4768 the target_waitkind for the stopping event. This
4769 routine calls the generic print routine for printing a message
4770 about reasons for stopping. This will print (for example) the
4771 "Breakpoint n," part of the output. The return value of this
4774 PRINT_UNKNOWN: Means we printed nothing.
4775 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4776 code to print the location. An example is
4777 "Breakpoint 1, " which should be followed by
4779 PRINT_SRC_ONLY: Means we printed something, but there is no need
4780 to also print the location part of the message.
4781 An example is the catch/throw messages, which
4782 don't require a location appended to the end.
4783 PRINT_NOTHING: We have done some printing and we don't need any
4784 further info to be printed. */
4786 enum print_stop_action
4787 bpstat_print (bpstat bs
, int kind
)
4789 enum print_stop_action val
;
4791 /* Maybe another breakpoint in the chain caused us to stop.
4792 (Currently all watchpoints go on the bpstat whether hit or not.
4793 That probably could (should) be changed, provided care is taken
4794 with respect to bpstat_explains_signal). */
4795 for (; bs
; bs
= bs
->next
)
4797 val
= print_bp_stop_message (bs
);
4798 if (val
== PRINT_SRC_ONLY
4799 || val
== PRINT_SRC_AND_LOC
4800 || val
== PRINT_NOTHING
)
4804 /* If we had hit a shared library event breakpoint,
4805 print_bp_stop_message would print out this message. If we hit an
4806 OS-level shared library event, do the same thing. */
4807 if (kind
== TARGET_WAITKIND_LOADED
)
4809 print_solib_event (0);
4810 return PRINT_NOTHING
;
4813 /* We reached the end of the chain, or we got a null BS to start
4814 with and nothing was printed. */
4815 return PRINT_UNKNOWN
;
4818 /* Evaluate the boolean expression EXP and return the result. */
4821 breakpoint_cond_eval (expression
*exp
)
4823 struct value
*mark
= value_mark ();
4824 bool res
= value_true (evaluate_expression (exp
));
4826 value_free_to_mark (mark
);
4830 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4832 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4834 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4835 breakpoint_at (bl
->owner
),
4839 print_it (print_it_normal
)
4841 **bs_link_pointer
= this;
4842 *bs_link_pointer
= &next
;
4847 breakpoint_at (NULL
),
4851 print_it (print_it_normal
)
4855 /* The target has stopped with waitstatus WS. Check if any hardware
4856 watchpoints have triggered, according to the target. */
4859 watchpoints_triggered (struct target_waitstatus
*ws
)
4861 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4864 if (!stopped_by_watchpoint
)
4866 /* We were not stopped by a watchpoint. Mark all watchpoints
4867 as not triggered. */
4868 for (breakpoint
*b
: all_breakpoints ())
4869 if (is_hardware_watchpoint (b
))
4871 struct watchpoint
*w
= (struct watchpoint
*) b
;
4873 w
->watchpoint_triggered
= watch_triggered_no
;
4879 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4881 /* We were stopped by a watchpoint, but we don't know where.
4882 Mark all watchpoints as unknown. */
4883 for (breakpoint
*b
: all_breakpoints ())
4884 if (is_hardware_watchpoint (b
))
4886 struct watchpoint
*w
= (struct watchpoint
*) b
;
4888 w
->watchpoint_triggered
= watch_triggered_unknown
;
4894 /* The target could report the data address. Mark watchpoints
4895 affected by this data address as triggered, and all others as not
4898 for (breakpoint
*b
: all_breakpoints ())
4899 if (is_hardware_watchpoint (b
))
4901 struct watchpoint
*w
= (struct watchpoint
*) b
;
4903 w
->watchpoint_triggered
= watch_triggered_no
;
4904 for (bp_location
*loc
: b
->locations ())
4906 if (is_masked_watchpoint (b
))
4908 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4909 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4911 if (newaddr
== start
)
4913 w
->watchpoint_triggered
= watch_triggered_yes
;
4917 /* Exact match not required. Within range is sufficient. */
4918 else if (target_watchpoint_addr_within_range
4919 (current_inferior ()->top_target (), addr
, loc
->address
,
4922 w
->watchpoint_triggered
= watch_triggered_yes
;
4931 /* Possible return values for watchpoint_check. */
4932 enum wp_check_result
4934 /* The watchpoint has been deleted. */
4937 /* The value has changed. */
4938 WP_VALUE_CHANGED
= 2,
4940 /* The value has not changed. */
4941 WP_VALUE_NOT_CHANGED
= 3,
4943 /* Ignore this watchpoint, no matter if the value changed or not. */
4947 #define BP_TEMPFLAG 1
4948 #define BP_HARDWAREFLAG 2
4950 /* Evaluate watchpoint condition expression and check if its value
4953 static wp_check_result
4954 watchpoint_check (bpstat bs
)
4956 struct watchpoint
*b
;
4957 struct frame_info
*fr
;
4958 int within_current_scope
;
4960 /* BS is built from an existing struct breakpoint. */
4961 gdb_assert (bs
->breakpoint_at
!= NULL
);
4962 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4964 /* If this is a local watchpoint, we only want to check if the
4965 watchpoint frame is in scope if the current thread is the thread
4966 that was used to create the watchpoint. */
4967 if (!watchpoint_in_thread_scope (b
))
4970 if (b
->exp_valid_block
== NULL
)
4971 within_current_scope
= 1;
4974 struct frame_info
*frame
= get_current_frame ();
4975 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4976 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4978 /* stack_frame_destroyed_p() returns a non-zero value if we're
4979 still in the function but the stack frame has already been
4980 invalidated. Since we can't rely on the values of local
4981 variables after the stack has been destroyed, we are treating
4982 the watchpoint in that state as `not changed' without further
4983 checking. Don't mark watchpoints as changed if the current
4984 frame is in an epilogue - even if they are in some other
4985 frame, our view of the stack is likely to be wrong and
4986 frame_find_by_id could error out. */
4987 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4990 fr
= frame_find_by_id (b
->watchpoint_frame
);
4991 within_current_scope
= (fr
!= NULL
);
4993 /* If we've gotten confused in the unwinder, we might have
4994 returned a frame that can't describe this variable. */
4995 if (within_current_scope
)
4997 struct symbol
*function
;
4999 function
= get_frame_function (fr
);
5000 if (function
== NULL
5001 || !contained_in (b
->exp_valid_block
,
5002 SYMBOL_BLOCK_VALUE (function
)))
5003 within_current_scope
= 0;
5006 if (within_current_scope
)
5007 /* If we end up stopping, the current frame will get selected
5008 in normal_stop. So this call to select_frame won't affect
5013 if (within_current_scope
)
5015 /* We use value_{,free_to_}mark because it could be a *long*
5016 time before we return to the command level and call
5017 free_all_values. We can't call free_all_values because we
5018 might be in the middle of evaluating a function call. */
5021 struct value
*new_val
;
5023 if (is_masked_watchpoint (b
))
5024 /* Since we don't know the exact trigger address (from
5025 stopped_data_address), just tell the user we've triggered
5026 a mask watchpoint. */
5027 return WP_VALUE_CHANGED
;
5029 mark
= value_mark ();
5030 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5033 if (b
->val_bitsize
!= 0)
5034 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5036 /* We use value_equal_contents instead of value_equal because
5037 the latter coerces an array to a pointer, thus comparing just
5038 the address of the array instead of its contents. This is
5039 not what we want. */
5040 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5041 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5044 bs
->old_val
= b
->val
;
5045 b
->val
= release_value (new_val
);
5046 b
->val_valid
= true;
5047 if (new_val
!= NULL
)
5048 value_free_to_mark (mark
);
5049 return WP_VALUE_CHANGED
;
5053 /* Nothing changed. */
5054 value_free_to_mark (mark
);
5055 return WP_VALUE_NOT_CHANGED
;
5060 /* This seems like the only logical thing to do because
5061 if we temporarily ignored the watchpoint, then when
5062 we reenter the block in which it is valid it contains
5063 garbage (in the case of a function, it may have two
5064 garbage values, one before and one after the prologue).
5065 So we can't even detect the first assignment to it and
5066 watch after that (since the garbage may or may not equal
5067 the first value assigned). */
5068 /* We print all the stop information in
5069 breakpoint_ops->print_it, but in this case, by the time we
5070 call breakpoint_ops->print_it this bp will be deleted
5071 already. So we have no choice but print the information
5074 SWITCH_THRU_ALL_UIS ()
5076 struct ui_out
*uiout
= current_uiout
;
5078 if (uiout
->is_mi_like_p ())
5080 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5081 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5082 "left the block in\n"
5083 "which its expression is valid.\n",
5084 signed_field ("wpnum", b
->number
));
5087 /* Make sure the watchpoint's commands aren't executed. */
5089 watchpoint_del_at_next_stop (b
);
5095 /* Return true if it looks like target has stopped due to hitting
5096 breakpoint location BL. This function does not check if we should
5097 stop, only if BL explains the stop. */
5100 bpstat_check_location (const struct bp_location
*bl
,
5101 const address_space
*aspace
, CORE_ADDR bp_addr
,
5102 const struct target_waitstatus
*ws
)
5104 struct breakpoint
*b
= bl
->owner
;
5106 /* BL is from an existing breakpoint. */
5107 gdb_assert (b
!= NULL
);
5109 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5112 /* Determine if the watched values have actually changed, and we
5113 should stop. If not, set BS->stop to 0. */
5116 bpstat_check_watchpoint (bpstat bs
)
5118 const struct bp_location
*bl
;
5119 struct watchpoint
*b
;
5121 /* BS is built for existing struct breakpoint. */
5122 bl
= bs
->bp_location_at
.get ();
5123 gdb_assert (bl
!= NULL
);
5124 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5125 gdb_assert (b
!= NULL
);
5128 int must_check_value
= 0;
5130 if (b
->type
== bp_watchpoint
)
5131 /* For a software watchpoint, we must always check the
5133 must_check_value
= 1;
5134 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5135 /* We have a hardware watchpoint (read, write, or access)
5136 and the target earlier reported an address watched by
5138 must_check_value
= 1;
5139 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5140 && b
->type
== bp_hardware_watchpoint
)
5141 /* We were stopped by a hardware watchpoint, but the target could
5142 not report the data address. We must check the watchpoint's
5143 value. Access and read watchpoints are out of luck; without
5144 a data address, we can't figure it out. */
5145 must_check_value
= 1;
5147 if (must_check_value
)
5153 e
= watchpoint_check (bs
);
5155 catch (const gdb_exception
&ex
)
5157 exception_fprintf (gdb_stderr
, ex
,
5158 "Error evaluating expression "
5159 "for watchpoint %d\n",
5162 SWITCH_THRU_ALL_UIS ()
5164 printf_filtered (_("Watchpoint %d deleted.\n"),
5167 watchpoint_del_at_next_stop (b
);
5174 /* We've already printed what needs to be printed. */
5175 bs
->print_it
= print_it_done
;
5179 bs
->print_it
= print_it_noop
;
5182 case WP_VALUE_CHANGED
:
5183 if (b
->type
== bp_read_watchpoint
)
5185 /* There are two cases to consider here:
5187 1. We're watching the triggered memory for reads.
5188 In that case, trust the target, and always report
5189 the watchpoint hit to the user. Even though
5190 reads don't cause value changes, the value may
5191 have changed since the last time it was read, and
5192 since we're not trapping writes, we will not see
5193 those, and as such we should ignore our notion of
5196 2. We're watching the triggered memory for both
5197 reads and writes. There are two ways this may
5200 2.1. This is a target that can't break on data
5201 reads only, but can break on accesses (reads or
5202 writes), such as e.g., x86. We detect this case
5203 at the time we try to insert read watchpoints.
5205 2.2. Otherwise, the target supports read
5206 watchpoints, but, the user set an access or write
5207 watchpoint watching the same memory as this read
5210 If we're watching memory writes as well as reads,
5211 ignore watchpoint hits when we find that the
5212 value hasn't changed, as reads don't cause
5213 changes. This still gives false positives when
5214 the program writes the same value to memory as
5215 what there was already in memory (we will confuse
5216 it for a read), but it's much better than
5219 int other_write_watchpoint
= 0;
5221 if (bl
->watchpoint_type
== hw_read
)
5223 for (breakpoint
*other_b
: all_breakpoints ())
5224 if (other_b
->type
== bp_hardware_watchpoint
5225 || other_b
->type
== bp_access_watchpoint
)
5227 struct watchpoint
*other_w
=
5228 (struct watchpoint
*) other_b
;
5230 if (other_w
->watchpoint_triggered
5231 == watch_triggered_yes
)
5233 other_write_watchpoint
= 1;
5239 if (other_write_watchpoint
5240 || bl
->watchpoint_type
== hw_access
)
5242 /* We're watching the same memory for writes,
5243 and the value changed since the last time we
5244 updated it, so this trap must be for a write.
5246 bs
->print_it
= print_it_noop
;
5251 case WP_VALUE_NOT_CHANGED
:
5252 if (b
->type
== bp_hardware_watchpoint
5253 || b
->type
== bp_watchpoint
)
5255 /* Don't stop: write watchpoints shouldn't fire if
5256 the value hasn't changed. */
5257 bs
->print_it
= print_it_noop
;
5267 else /* must_check_value == 0 */
5269 /* This is a case where some watchpoint(s) triggered, but
5270 not at the address of this watchpoint, or else no
5271 watchpoint triggered after all. So don't print
5272 anything for this watchpoint. */
5273 bs
->print_it
= print_it_noop
;
5279 /* For breakpoints that are currently marked as telling gdb to stop,
5280 check conditions (condition proper, frame, thread and ignore count)
5281 of breakpoint referred to by BS. If we should not stop for this
5282 breakpoint, set BS->stop to 0. */
5285 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5287 const struct bp_location
*bl
;
5288 struct breakpoint
*b
;
5290 bool condition_result
= true;
5291 struct expression
*cond
;
5293 gdb_assert (bs
->stop
);
5295 /* BS is built for existing struct breakpoint. */
5296 bl
= bs
->bp_location_at
.get ();
5297 gdb_assert (bl
!= NULL
);
5298 b
= bs
->breakpoint_at
;
5299 gdb_assert (b
!= NULL
);
5301 /* Even if the target evaluated the condition on its end and notified GDB, we
5302 need to do so again since GDB does not know if we stopped due to a
5303 breakpoint or a single step breakpoint. */
5305 if (frame_id_p (b
->frame_id
)
5306 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5312 /* If this is a thread/task-specific breakpoint, don't waste cpu
5313 evaluating the condition if this isn't the specified
5315 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5316 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5322 /* Evaluate extension language breakpoints that have a "stop" method
5324 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5326 if (is_watchpoint (b
))
5328 struct watchpoint
*w
= (struct watchpoint
*) b
;
5330 cond
= w
->cond_exp
.get ();
5333 cond
= bl
->cond
.get ();
5335 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5337 int within_current_scope
= 1;
5338 struct watchpoint
* w
;
5340 /* We use value_mark and value_free_to_mark because it could
5341 be a long time before we return to the command level and
5342 call free_all_values. We can't call free_all_values
5343 because we might be in the middle of evaluating a
5345 struct value
*mark
= value_mark ();
5347 if (is_watchpoint (b
))
5348 w
= (struct watchpoint
*) b
;
5352 /* Need to select the frame, with all that implies so that
5353 the conditions will have the right context. Because we
5354 use the frame, we will not see an inlined function's
5355 variables when we arrive at a breakpoint at the start
5356 of the inlined function; the current frame will be the
5358 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5359 select_frame (get_current_frame ());
5362 struct frame_info
*frame
;
5364 /* For local watchpoint expressions, which particular
5365 instance of a local is being watched matters, so we
5366 keep track of the frame to evaluate the expression
5367 in. To evaluate the condition however, it doesn't
5368 really matter which instantiation of the function
5369 where the condition makes sense triggers the
5370 watchpoint. This allows an expression like "watch
5371 global if q > 10" set in `func', catch writes to
5372 global on all threads that call `func', or catch
5373 writes on all recursive calls of `func' by a single
5374 thread. We simply always evaluate the condition in
5375 the innermost frame that's executing where it makes
5376 sense to evaluate the condition. It seems
5378 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5380 select_frame (frame
);
5382 within_current_scope
= 0;
5384 if (within_current_scope
)
5388 condition_result
= breakpoint_cond_eval (cond
);
5390 catch (const gdb_exception
&ex
)
5392 exception_fprintf (gdb_stderr
, ex
,
5393 "Error in testing breakpoint condition:\n");
5398 warning (_("Watchpoint condition cannot be tested "
5399 "in the current scope"));
5400 /* If we failed to set the right context for this
5401 watchpoint, unconditionally report it. */
5403 /* FIXME-someday, should give breakpoint #. */
5404 value_free_to_mark (mark
);
5407 if (cond
&& !condition_result
)
5411 else if (b
->ignore_count
> 0)
5415 /* Increase the hit count even though we don't stop. */
5417 gdb::observers::breakpoint_modified
.notify (b
);
5421 /* Returns true if we need to track moribund locations of LOC's type
5422 on the current target. */
5425 need_moribund_for_location_type (struct bp_location
*loc
)
5427 return ((loc
->loc_type
== bp_loc_software_breakpoint
5428 && !target_supports_stopped_by_sw_breakpoint ())
5429 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5430 && !target_supports_stopped_by_hw_breakpoint ()));
5433 /* See breakpoint.h. */
5436 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5437 const struct target_waitstatus
*ws
)
5439 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5441 for (breakpoint
*b
: all_breakpoints ())
5443 if (!breakpoint_enabled (b
))
5446 for (bp_location
*bl
: b
->locations ())
5448 /* For hardware watchpoints, we look only at the first
5449 location. The watchpoint_check function will work on the
5450 entire expression, not the individual locations. For
5451 read watchpoints, the watchpoints_triggered function has
5452 checked all locations already. */
5453 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5456 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5459 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5462 /* Come here if it's a watchpoint, or if the break address
5465 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5468 /* Assume we stop. Should we find a watchpoint that is not
5469 actually triggered, or if the condition of the breakpoint
5470 evaluates as false, we'll reset 'stop' to 0. */
5474 /* If this is a scope breakpoint, mark the associated
5475 watchpoint as triggered so that we will handle the
5476 out-of-scope event. We'll get to the watchpoint next
5478 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5480 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5482 w
->watchpoint_triggered
= watch_triggered_yes
;
5487 /* Check if a moribund breakpoint explains the stop. */
5488 if (!target_supports_stopped_by_sw_breakpoint ()
5489 || !target_supports_stopped_by_hw_breakpoint ())
5491 for (bp_location
*loc
: moribund_locations
)
5493 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5494 && need_moribund_for_location_type (loc
))
5496 bpstat bs
= new bpstats (loc
, &bs_link
);
5497 /* For hits of moribund locations, we should just proceed. */
5500 bs
->print_it
= print_it_noop
;
5508 /* See breakpoint.h. */
5511 bpstat_stop_status (const address_space
*aspace
,
5512 CORE_ADDR bp_addr
, thread_info
*thread
,
5513 const struct target_waitstatus
*ws
,
5516 struct breakpoint
*b
= NULL
;
5517 /* First item of allocated bpstat's. */
5518 bpstat bs_head
= stop_chain
;
5520 int need_remove_insert
;
5523 /* First, build the bpstat chain with locations that explain a
5524 target stop, while being careful to not set the target running,
5525 as that may invalidate locations (in particular watchpoint
5526 locations are recreated). Resuming will happen here with
5527 breakpoint conditions or watchpoint expressions that include
5528 inferior function calls. */
5529 if (bs_head
== NULL
)
5530 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5532 /* A bit of special processing for shlib breakpoints. We need to
5533 process solib loading here, so that the lists of loaded and
5534 unloaded libraries are correct before we handle "catch load" and
5536 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5538 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5540 handle_solib_event ();
5545 /* Now go through the locations that caused the target to stop, and
5546 check whether we're interested in reporting this stop to higher
5547 layers, or whether we should resume the target transparently. */
5551 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5556 b
= bs
->breakpoint_at
;
5557 b
->ops
->check_status (bs
);
5560 bpstat_check_breakpoint_conditions (bs
, thread
);
5565 gdb::observers::breakpoint_modified
.notify (b
);
5567 /* We will stop here. */
5568 if (b
->disposition
== disp_disable
)
5570 --(b
->enable_count
);
5571 if (b
->enable_count
<= 0)
5572 b
->enable_state
= bp_disabled
;
5577 bs
->commands
= b
->commands
;
5578 if (command_line_is_silent (bs
->commands
5579 ? bs
->commands
.get () : NULL
))
5582 b
->ops
->after_condition_true (bs
);
5587 /* Print nothing for this entry if we don't stop or don't
5589 if (!bs
->stop
|| !bs
->print
)
5590 bs
->print_it
= print_it_noop
;
5593 /* If we aren't stopping, the value of some hardware watchpoint may
5594 not have changed, but the intermediate memory locations we are
5595 watching may have. Don't bother if we're stopping; this will get
5597 need_remove_insert
= 0;
5598 if (! bpstat_causes_stop (bs_head
))
5599 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5601 && bs
->breakpoint_at
5602 && is_hardware_watchpoint (bs
->breakpoint_at
))
5604 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5606 update_watchpoint (w
, 0 /* don't reparse. */);
5607 need_remove_insert
= 1;
5610 if (need_remove_insert
)
5611 update_global_location_list (UGLL_MAY_INSERT
);
5612 else if (removed_any
)
5613 update_global_location_list (UGLL_DONT_INSERT
);
5619 handle_jit_event (CORE_ADDR address
)
5621 struct gdbarch
*gdbarch
;
5623 infrun_debug_printf ("handling bp_jit_event");
5625 /* Switch terminal for any messages produced by
5626 breakpoint_re_set. */
5627 target_terminal::ours_for_output ();
5629 gdbarch
= get_frame_arch (get_current_frame ());
5630 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5631 thus it is expected that its objectfile can be found through
5632 minimal symbol lookup. If it doesn't work (and assert fails), it
5633 most likely means that `jit_breakpoint_re_set` was changes and this
5634 function needs to be updated too. */
5635 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5636 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5637 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5639 target_terminal::inferior ();
5642 /* Prepare WHAT final decision for infrun. */
5644 /* Decide what infrun needs to do with this bpstat. */
5647 bpstat_what (bpstat bs_head
)
5649 struct bpstat_what retval
;
5652 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5653 retval
.call_dummy
= STOP_NONE
;
5654 retval
.is_longjmp
= false;
5656 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5658 /* Extract this BS's action. After processing each BS, we check
5659 if its action overrides all we've seem so far. */
5660 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5663 if (bs
->breakpoint_at
== NULL
)
5665 /* I suspect this can happen if it was a momentary
5666 breakpoint which has since been deleted. */
5670 bptype
= bs
->breakpoint_at
->type
;
5677 case bp_hardware_breakpoint
:
5678 case bp_single_step
:
5681 case bp_shlib_event
:
5685 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5687 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5690 this_action
= BPSTAT_WHAT_SINGLE
;
5693 case bp_hardware_watchpoint
:
5694 case bp_read_watchpoint
:
5695 case bp_access_watchpoint
:
5699 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5701 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5705 /* There was a watchpoint, but we're not stopping.
5706 This requires no further action. */
5710 case bp_longjmp_call_dummy
:
5714 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5715 retval
.is_longjmp
= bptype
!= bp_exception
;
5718 this_action
= BPSTAT_WHAT_SINGLE
;
5720 case bp_longjmp_resume
:
5721 case bp_exception_resume
:
5724 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5725 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5728 this_action
= BPSTAT_WHAT_SINGLE
;
5730 case bp_step_resume
:
5732 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5735 /* It is for the wrong frame. */
5736 this_action
= BPSTAT_WHAT_SINGLE
;
5739 case bp_hp_step_resume
:
5741 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5744 /* It is for the wrong frame. */
5745 this_action
= BPSTAT_WHAT_SINGLE
;
5748 case bp_watchpoint_scope
:
5749 case bp_thread_event
:
5750 case bp_overlay_event
:
5751 case bp_longjmp_master
:
5752 case bp_std_terminate_master
:
5753 case bp_exception_master
:
5754 this_action
= BPSTAT_WHAT_SINGLE
;
5760 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5762 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5766 /* Some catchpoints are implemented with breakpoints.
5767 For those, we need to step over the breakpoint. */
5768 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5769 this_action
= BPSTAT_WHAT_SINGLE
;
5773 this_action
= BPSTAT_WHAT_SINGLE
;
5776 /* Make sure the action is stop (silent or noisy),
5777 so infrun.c pops the dummy frame. */
5778 retval
.call_dummy
= STOP_STACK_DUMMY
;
5779 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5781 case bp_std_terminate
:
5782 /* Make sure the action is stop (silent or noisy),
5783 so infrun.c pops the dummy frame. */
5784 retval
.call_dummy
= STOP_STD_TERMINATE
;
5785 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5788 case bp_fast_tracepoint
:
5789 case bp_static_tracepoint
:
5790 /* Tracepoint hits should not be reported back to GDB, and
5791 if one got through somehow, it should have been filtered
5793 internal_error (__FILE__
, __LINE__
,
5794 _("bpstat_what: tracepoint encountered"));
5796 case bp_gnu_ifunc_resolver
:
5797 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5798 this_action
= BPSTAT_WHAT_SINGLE
;
5800 case bp_gnu_ifunc_resolver_return
:
5801 /* The breakpoint will be removed, execution will restart from the
5802 PC of the former breakpoint. */
5803 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5808 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5810 this_action
= BPSTAT_WHAT_SINGLE
;
5814 internal_error (__FILE__
, __LINE__
,
5815 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5818 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5825 bpstat_run_callbacks (bpstat bs_head
)
5829 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5831 struct breakpoint
*b
= bs
->breakpoint_at
;
5838 handle_jit_event (bs
->bp_location_at
->address
);
5840 case bp_gnu_ifunc_resolver
:
5841 gnu_ifunc_resolver_stop (b
);
5843 case bp_gnu_ifunc_resolver_return
:
5844 gnu_ifunc_resolver_return_stop (b
);
5850 /* See breakpoint.h. */
5853 bpstat_should_step ()
5855 for (breakpoint
*b
: all_breakpoints ())
5856 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5862 /* See breakpoint.h. */
5865 bpstat_causes_stop (bpstat bs
)
5867 for (; bs
!= NULL
; bs
= bs
->next
)
5876 /* Compute a string of spaces suitable to indent the next line
5877 so it starts at the position corresponding to the table column
5878 named COL_NAME in the currently active table of UIOUT. */
5881 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5883 static char wrap_indent
[80];
5884 int i
, total_width
, width
, align
;
5888 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5890 if (strcmp (text
, col_name
) == 0)
5892 gdb_assert (total_width
< sizeof wrap_indent
);
5893 memset (wrap_indent
, ' ', total_width
);
5894 wrap_indent
[total_width
] = 0;
5899 total_width
+= width
+ 1;
5905 /* Determine if the locations of this breakpoint will have their conditions
5906 evaluated by the target, host or a mix of both. Returns the following:
5908 "host": Host evals condition.
5909 "host or target": Host or Target evals condition.
5910 "target": Target evals condition.
5914 bp_condition_evaluator (struct breakpoint
*b
)
5916 char host_evals
= 0;
5917 char target_evals
= 0;
5922 if (!is_breakpoint (b
))
5925 if (gdb_evaluates_breakpoint_condition_p ()
5926 || !target_supports_evaluation_of_breakpoint_conditions ())
5927 return condition_evaluation_host
;
5929 for (bp_location
*bl
: b
->locations ())
5931 if (bl
->cond_bytecode
)
5937 if (host_evals
&& target_evals
)
5938 return condition_evaluation_both
;
5939 else if (target_evals
)
5940 return condition_evaluation_target
;
5942 return condition_evaluation_host
;
5945 /* Determine the breakpoint location's condition evaluator. This is
5946 similar to bp_condition_evaluator, but for locations. */
5949 bp_location_condition_evaluator (struct bp_location
*bl
)
5951 if (bl
&& !is_breakpoint (bl
->owner
))
5954 if (gdb_evaluates_breakpoint_condition_p ()
5955 || !target_supports_evaluation_of_breakpoint_conditions ())
5956 return condition_evaluation_host
;
5958 if (bl
&& bl
->cond_bytecode
)
5959 return condition_evaluation_target
;
5961 return condition_evaluation_host
;
5964 /* Print the LOC location out of the list of B->LOC locations. */
5967 print_breakpoint_location (struct breakpoint
*b
,
5968 struct bp_location
*loc
)
5970 struct ui_out
*uiout
= current_uiout
;
5972 scoped_restore_current_program_space restore_pspace
;
5974 if (loc
!= NULL
&& loc
->shlib_disabled
)
5978 set_current_program_space (loc
->pspace
);
5980 if (b
->display_canonical
)
5981 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5982 else if (loc
&& loc
->symtab
)
5984 const struct symbol
*sym
= loc
->symbol
;
5988 uiout
->text ("in ");
5989 uiout
->field_string ("func", sym
->print_name (),
5990 function_name_style
.style ());
5992 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5993 uiout
->text ("at ");
5995 uiout
->field_string ("file",
5996 symtab_to_filename_for_display (loc
->symtab
),
5997 file_name_style
.style ());
6000 if (uiout
->is_mi_like_p ())
6001 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6003 uiout
->field_signed ("line", loc
->line_number
);
6009 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6011 uiout
->field_stream ("at", stb
);
6015 uiout
->field_string ("pending",
6016 event_location_to_string (b
->location
.get ()));
6017 /* If extra_string is available, it could be holding a condition
6018 or dprintf arguments. In either case, make sure it is printed,
6019 too, but only for non-MI streams. */
6020 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6022 if (b
->type
== bp_dprintf
)
6026 uiout
->text (b
->extra_string
);
6030 if (loc
&& is_breakpoint (b
)
6031 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6032 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6035 uiout
->field_string ("evaluated-by",
6036 bp_location_condition_evaluator (loc
));
6042 bptype_string (enum bptype type
)
6044 struct ep_type_description
6047 const char *description
;
6049 static struct ep_type_description bptypes
[] =
6051 {bp_none
, "?deleted?"},
6052 {bp_breakpoint
, "breakpoint"},
6053 {bp_hardware_breakpoint
, "hw breakpoint"},
6054 {bp_single_step
, "sw single-step"},
6055 {bp_until
, "until"},
6056 {bp_finish
, "finish"},
6057 {bp_watchpoint
, "watchpoint"},
6058 {bp_hardware_watchpoint
, "hw watchpoint"},
6059 {bp_read_watchpoint
, "read watchpoint"},
6060 {bp_access_watchpoint
, "acc watchpoint"},
6061 {bp_longjmp
, "longjmp"},
6062 {bp_longjmp_resume
, "longjmp resume"},
6063 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6064 {bp_exception
, "exception"},
6065 {bp_exception_resume
, "exception resume"},
6066 {bp_step_resume
, "step resume"},
6067 {bp_hp_step_resume
, "high-priority step resume"},
6068 {bp_watchpoint_scope
, "watchpoint scope"},
6069 {bp_call_dummy
, "call dummy"},
6070 {bp_std_terminate
, "std::terminate"},
6071 {bp_shlib_event
, "shlib events"},
6072 {bp_thread_event
, "thread events"},
6073 {bp_overlay_event
, "overlay events"},
6074 {bp_longjmp_master
, "longjmp master"},
6075 {bp_std_terminate_master
, "std::terminate master"},
6076 {bp_exception_master
, "exception master"},
6077 {bp_catchpoint
, "catchpoint"},
6078 {bp_tracepoint
, "tracepoint"},
6079 {bp_fast_tracepoint
, "fast tracepoint"},
6080 {bp_static_tracepoint
, "static tracepoint"},
6081 {bp_dprintf
, "dprintf"},
6082 {bp_jit_event
, "jit events"},
6083 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6084 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6087 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6088 || ((int) type
!= bptypes
[(int) type
].type
))
6089 internal_error (__FILE__
, __LINE__
,
6090 _("bptypes table does not describe type #%d."),
6093 return bptypes
[(int) type
].description
;
6096 /* For MI, output a field named 'thread-groups' with a list as the value.
6097 For CLI, prefix the list with the string 'inf'. */
6100 output_thread_groups (struct ui_out
*uiout
,
6101 const char *field_name
,
6102 const std::vector
<int> &inf_nums
,
6105 int is_mi
= uiout
->is_mi_like_p ();
6107 /* For backward compatibility, don't display inferiors in CLI unless
6108 there are several. Always display them for MI. */
6109 if (!is_mi
&& mi_only
)
6112 ui_out_emit_list
list_emitter (uiout
, field_name
);
6114 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6120 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6121 uiout
->field_string (NULL
, mi_group
);
6126 uiout
->text (" inf ");
6130 uiout
->text (plongest (inf_nums
[i
]));
6135 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6136 instead of going via breakpoint_ops::print_one. This makes "maint
6137 info breakpoints" show the software breakpoint locations of
6138 catchpoints, which are considered internal implementation
6142 print_one_breakpoint_location (struct breakpoint
*b
,
6143 struct bp_location
*loc
,
6145 struct bp_location
**last_loc
,
6146 int allflag
, bool raw_loc
)
6148 struct command_line
*l
;
6149 static char bpenables
[] = "nynny";
6151 struct ui_out
*uiout
= current_uiout
;
6152 int header_of_multiple
= 0;
6153 int part_of_multiple
= (loc
!= NULL
);
6154 struct value_print_options opts
;
6156 get_user_print_options (&opts
);
6158 gdb_assert (!loc
|| loc_number
!= 0);
6159 /* See comment in print_one_breakpoint concerning treatment of
6160 breakpoints with single disabled location. */
6163 && (b
->loc
->next
!= NULL
6164 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6165 header_of_multiple
= 1;
6173 if (part_of_multiple
)
6174 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6176 uiout
->field_signed ("number", b
->number
);
6180 if (part_of_multiple
)
6181 uiout
->field_skip ("type");
6183 uiout
->field_string ("type", bptype_string (b
->type
));
6187 if (part_of_multiple
)
6188 uiout
->field_skip ("disp");
6190 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6194 /* For locations that are disabled because of an invalid condition,
6195 display "N*" on CLI, where "*" refers to a footnote below the
6196 table. For MI, simply display a "N" without a footnote. */
6197 const char *N
= (uiout
->is_mi_like_p ()) ? "N" : "N*";
6198 if (part_of_multiple
)
6199 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? N
6200 : (loc
->enabled
? "y" : "n")));
6202 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6205 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6206 b
->ops
->print_one (b
, last_loc
);
6209 if (is_watchpoint (b
))
6211 struct watchpoint
*w
= (struct watchpoint
*) b
;
6213 /* Field 4, the address, is omitted (which makes the columns
6214 not line up too nicely with the headers, but the effect
6215 is relatively readable). */
6216 if (opts
.addressprint
)
6217 uiout
->field_skip ("addr");
6219 uiout
->field_string ("what", w
->exp_string
);
6221 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6222 || is_ada_exception_catchpoint (b
))
6224 if (opts
.addressprint
)
6227 if (header_of_multiple
)
6228 uiout
->field_string ("addr", "<MULTIPLE>",
6229 metadata_style
.style ());
6230 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6231 uiout
->field_string ("addr", "<PENDING>",
6232 metadata_style
.style ());
6234 uiout
->field_core_addr ("addr",
6235 loc
->gdbarch
, loc
->address
);
6238 if (!header_of_multiple
)
6239 print_breakpoint_location (b
, loc
);
6245 if (loc
!= NULL
&& !header_of_multiple
)
6247 std::vector
<int> inf_nums
;
6250 for (inferior
*inf
: all_inferiors ())
6252 if (inf
->pspace
== loc
->pspace
)
6253 inf_nums
.push_back (inf
->num
);
6256 /* For backward compatibility, don't display inferiors in CLI unless
6257 there are several. Always display for MI. */
6259 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6260 && (program_spaces
.size () > 1
6261 || number_of_inferiors () > 1)
6262 /* LOC is for existing B, it cannot be in
6263 moribund_locations and thus having NULL OWNER. */
6264 && loc
->owner
->type
!= bp_catchpoint
))
6266 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6269 if (!part_of_multiple
)
6271 if (b
->thread
!= -1)
6273 /* FIXME: This seems to be redundant and lost here; see the
6274 "stop only in" line a little further down. */
6275 uiout
->text (" thread ");
6276 uiout
->field_signed ("thread", b
->thread
);
6278 else if (b
->task
!= 0)
6280 uiout
->text (" task ");
6281 uiout
->field_signed ("task", b
->task
);
6287 if (!part_of_multiple
)
6288 b
->ops
->print_one_detail (b
, uiout
);
6290 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6293 uiout
->text ("\tstop only in stack frame at ");
6294 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6296 uiout
->field_core_addr ("frame",
6297 b
->gdbarch
, b
->frame_id
.stack_addr
);
6301 if (!part_of_multiple
&& b
->cond_string
)
6304 if (is_tracepoint (b
))
6305 uiout
->text ("\ttrace only if ");
6307 uiout
->text ("\tstop only if ");
6308 uiout
->field_string ("cond", b
->cond_string
);
6310 /* Print whether the target is doing the breakpoint's condition
6311 evaluation. If GDB is doing the evaluation, don't print anything. */
6312 if (is_breakpoint (b
)
6313 && breakpoint_condition_evaluation_mode ()
6314 == condition_evaluation_target
)
6316 uiout
->message (" (%pF evals)",
6317 string_field ("evaluated-by",
6318 bp_condition_evaluator (b
)));
6323 if (!part_of_multiple
&& b
->thread
!= -1)
6325 /* FIXME should make an annotation for this. */
6326 uiout
->text ("\tstop only in thread ");
6327 if (uiout
->is_mi_like_p ())
6328 uiout
->field_signed ("thread", b
->thread
);
6331 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6333 uiout
->field_string ("thread", print_thread_id (thr
));
6338 if (!part_of_multiple
)
6342 /* FIXME should make an annotation for this. */
6343 if (is_catchpoint (b
))
6344 uiout
->text ("\tcatchpoint");
6345 else if (is_tracepoint (b
))
6346 uiout
->text ("\ttracepoint");
6348 uiout
->text ("\tbreakpoint");
6349 uiout
->text (" already hit ");
6350 uiout
->field_signed ("times", b
->hit_count
);
6351 if (b
->hit_count
== 1)
6352 uiout
->text (" time\n");
6354 uiout
->text (" times\n");
6358 /* Output the count also if it is zero, but only if this is mi. */
6359 if (uiout
->is_mi_like_p ())
6360 uiout
->field_signed ("times", b
->hit_count
);
6364 if (!part_of_multiple
&& b
->ignore_count
)
6367 uiout
->message ("\tignore next %pF hits\n",
6368 signed_field ("ignore", b
->ignore_count
));
6371 /* Note that an enable count of 1 corresponds to "enable once"
6372 behavior, which is reported by the combination of enablement and
6373 disposition, so we don't need to mention it here. */
6374 if (!part_of_multiple
&& b
->enable_count
> 1)
6377 uiout
->text ("\tdisable after ");
6378 /* Tweak the wording to clarify that ignore and enable counts
6379 are distinct, and have additive effect. */
6380 if (b
->ignore_count
)
6381 uiout
->text ("additional ");
6383 uiout
->text ("next ");
6384 uiout
->field_signed ("enable", b
->enable_count
);
6385 uiout
->text (" hits\n");
6388 if (!part_of_multiple
&& is_tracepoint (b
))
6390 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6392 if (tp
->traceframe_usage
)
6394 uiout
->text ("\ttrace buffer usage ");
6395 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6396 uiout
->text (" bytes\n");
6400 l
= b
->commands
? b
->commands
.get () : NULL
;
6401 if (!part_of_multiple
&& l
)
6404 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6405 print_command_lines (uiout
, l
, 4);
6408 if (is_tracepoint (b
))
6410 struct tracepoint
*t
= (struct tracepoint
*) b
;
6412 if (!part_of_multiple
&& t
->pass_count
)
6414 annotate_field (10);
6415 uiout
->text ("\tpass count ");
6416 uiout
->field_signed ("pass", t
->pass_count
);
6417 uiout
->text (" \n");
6420 /* Don't display it when tracepoint or tracepoint location is
6422 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6424 annotate_field (11);
6426 if (uiout
->is_mi_like_p ())
6427 uiout
->field_string ("installed",
6428 loc
->inserted
? "y" : "n");
6434 uiout
->text ("\tnot ");
6435 uiout
->text ("installed on target\n");
6440 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6442 if (is_watchpoint (b
))
6444 struct watchpoint
*w
= (struct watchpoint
*) b
;
6446 uiout
->field_string ("original-location", w
->exp_string
);
6448 else if (b
->location
!= NULL
6449 && event_location_to_string (b
->location
.get ()) != NULL
)
6450 uiout
->field_string ("original-location",
6451 event_location_to_string (b
->location
.get ()));
6455 /* See breakpoint.h. */
6457 bool fix_multi_location_breakpoint_output_globally
= false;
6460 print_one_breakpoint (struct breakpoint
*b
,
6461 struct bp_location
**last_loc
,
6464 struct ui_out
*uiout
= current_uiout
;
6465 bool use_fixed_output
6466 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6467 || fix_multi_location_breakpoint_output_globally
);
6469 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6470 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6472 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6474 if (!use_fixed_output
)
6475 bkpt_tuple_emitter
.reset ();
6477 /* If this breakpoint has custom print function,
6478 it's already printed. Otherwise, print individual
6479 locations, if any. */
6481 || b
->ops
->print_one
== NULL
6484 /* If breakpoint has a single location that is disabled, we
6485 print it as if it had several locations, since otherwise it's
6486 hard to represent "breakpoint enabled, location disabled"
6489 Note that while hardware watchpoints have several locations
6490 internally, that's not a property exposed to users.
6492 Likewise, while catchpoints may be implemented with
6493 breakpoints (e.g., catch throw), that's not a property
6494 exposed to users. We do however display the internal
6495 breakpoint locations with "maint info breakpoints". */
6496 if (!is_hardware_watchpoint (b
)
6497 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6498 || is_ada_exception_catchpoint (b
))
6500 || (b
->loc
&& (b
->loc
->next
6502 || b
->loc
->disabled_by_cond
))))
6504 gdb::optional
<ui_out_emit_list
> locations_list
;
6506 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6507 MI record. For later versions, place breakpoint locations in a
6509 if (uiout
->is_mi_like_p () && use_fixed_output
)
6510 locations_list
.emplace (uiout
, "locations");
6513 for (bp_location
*loc
: b
->locations ())
6515 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6516 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6525 breakpoint_address_bits (struct breakpoint
*b
)
6527 int print_address_bits
= 0;
6529 /* Software watchpoints that aren't watching memory don't have an
6530 address to print. */
6531 if (is_no_memory_software_watchpoint (b
))
6534 for (bp_location
*loc
: b
->locations ())
6538 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6539 if (addr_bit
> print_address_bits
)
6540 print_address_bits
= addr_bit
;
6543 return print_address_bits
;
6546 /* See breakpoint.h. */
6549 print_breakpoint (breakpoint
*b
)
6551 struct bp_location
*dummy_loc
= NULL
;
6552 print_one_breakpoint (b
, &dummy_loc
, 0);
6555 /* Return true if this breakpoint was set by the user, false if it is
6556 internal or momentary. */
6559 user_breakpoint_p (struct breakpoint
*b
)
6561 return b
->number
> 0;
6564 /* See breakpoint.h. */
6567 pending_breakpoint_p (struct breakpoint
*b
)
6569 return b
->loc
== NULL
;
6572 /* Print information on breakpoints (including watchpoints and tracepoints).
6574 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6575 understood by number_or_range_parser. Only breakpoints included in this
6576 list are then printed.
6578 If SHOW_INTERNAL is true, print internal breakpoints.
6580 If FILTER is non-NULL, call it on each breakpoint and only include the
6581 ones for which it returns true.
6583 Return the total number of breakpoints listed. */
6586 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6587 bool (*filter
) (const struct breakpoint
*))
6589 struct bp_location
*last_loc
= NULL
;
6590 int nr_printable_breakpoints
;
6591 struct value_print_options opts
;
6592 int print_address_bits
= 0;
6593 int print_type_col_width
= 14;
6594 struct ui_out
*uiout
= current_uiout
;
6595 bool has_disabled_by_cond_location
= false;
6597 get_user_print_options (&opts
);
6599 /* Compute the number of rows in the table, as well as the size
6600 required for address fields. */
6601 nr_printable_breakpoints
= 0;
6602 for (breakpoint
*b
: all_breakpoints ())
6604 /* If we have a filter, only list the breakpoints it accepts. */
6605 if (filter
&& !filter (b
))
6608 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6609 accept. Skip the others. */
6610 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6612 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6614 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6618 if (show_internal
|| user_breakpoint_p (b
))
6620 int addr_bit
, type_len
;
6622 addr_bit
= breakpoint_address_bits (b
);
6623 if (addr_bit
> print_address_bits
)
6624 print_address_bits
= addr_bit
;
6626 type_len
= strlen (bptype_string (b
->type
));
6627 if (type_len
> print_type_col_width
)
6628 print_type_col_width
= type_len
;
6630 nr_printable_breakpoints
++;
6635 ui_out_emit_table
table_emitter (uiout
,
6636 opts
.addressprint
? 6 : 5,
6637 nr_printable_breakpoints
,
6640 if (nr_printable_breakpoints
> 0)
6641 annotate_breakpoints_headers ();
6642 if (nr_printable_breakpoints
> 0)
6644 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6645 if (nr_printable_breakpoints
> 0)
6647 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6648 if (nr_printable_breakpoints
> 0)
6650 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6651 if (nr_printable_breakpoints
> 0)
6653 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6654 if (opts
.addressprint
)
6656 if (nr_printable_breakpoints
> 0)
6658 if (print_address_bits
<= 32)
6659 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6661 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6663 if (nr_printable_breakpoints
> 0)
6665 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6666 uiout
->table_body ();
6667 if (nr_printable_breakpoints
> 0)
6668 annotate_breakpoints_table ();
6670 for (breakpoint
*b
: all_breakpoints ())
6673 /* If we have a filter, only list the breakpoints it accepts. */
6674 if (filter
&& !filter (b
))
6677 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6678 accept. Skip the others. */
6680 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6682 if (show_internal
) /* maintenance info breakpoint */
6684 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6687 else /* all others */
6689 if (!number_is_in_list (bp_num_list
, b
->number
))
6693 /* We only print out user settable breakpoints unless the
6694 show_internal is set. */
6695 if (show_internal
|| user_breakpoint_p (b
))
6697 print_one_breakpoint (b
, &last_loc
, show_internal
);
6698 for (bp_location
*loc
: b
->locations ())
6699 if (loc
->disabled_by_cond
)
6700 has_disabled_by_cond_location
= true;
6705 if (nr_printable_breakpoints
== 0)
6707 /* If there's a filter, let the caller decide how to report
6711 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6712 uiout
->message ("No breakpoints or watchpoints.\n");
6714 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6720 if (last_loc
&& !server_command
)
6721 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6723 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6724 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6728 /* FIXME? Should this be moved up so that it is only called when
6729 there have been breakpoints? */
6730 annotate_breakpoints_table_end ();
6732 return nr_printable_breakpoints
;
6735 /* Display the value of default-collect in a way that is generally
6736 compatible with the breakpoint list. */
6739 default_collect_info (void)
6741 struct ui_out
*uiout
= current_uiout
;
6743 /* If it has no value (which is frequently the case), say nothing; a
6744 message like "No default-collect." gets in user's face when it's
6746 if (!*default_collect
)
6749 /* The following phrase lines up nicely with per-tracepoint collect
6751 uiout
->text ("default collect ");
6752 uiout
->field_string ("default-collect", default_collect
);
6753 uiout
->text (" \n");
6757 info_breakpoints_command (const char *args
, int from_tty
)
6759 breakpoint_1 (args
, false, NULL
);
6761 default_collect_info ();
6765 info_watchpoints_command (const char *args
, int from_tty
)
6767 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6768 struct ui_out
*uiout
= current_uiout
;
6770 if (num_printed
== 0)
6772 if (args
== NULL
|| *args
== '\0')
6773 uiout
->message ("No watchpoints.\n");
6775 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6780 maintenance_info_breakpoints (const char *args
, int from_tty
)
6782 breakpoint_1 (args
, true, NULL
);
6784 default_collect_info ();
6788 breakpoint_has_pc (struct breakpoint
*b
,
6789 struct program_space
*pspace
,
6790 CORE_ADDR pc
, struct obj_section
*section
)
6792 for (bp_location
*bl
: b
->locations ())
6794 if (bl
->pspace
== pspace
6795 && bl
->address
== pc
6796 && (!overlay_debugging
|| bl
->section
== section
))
6802 /* Print a message describing any user-breakpoints set at PC. This
6803 concerns with logical breakpoints, so we match program spaces, not
6807 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6808 struct program_space
*pspace
, CORE_ADDR pc
,
6809 struct obj_section
*section
, int thread
)
6813 for (breakpoint
*b
: all_breakpoints ())
6814 others
+= (user_breakpoint_p (b
)
6815 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6820 printf_filtered (_("Note: breakpoint "));
6821 else /* if (others == ???) */
6822 printf_filtered (_("Note: breakpoints "));
6823 for (breakpoint
*b
: all_breakpoints ())
6824 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6827 printf_filtered ("%d", b
->number
);
6828 if (b
->thread
== -1 && thread
!= -1)
6829 printf_filtered (" (all threads)");
6830 else if (b
->thread
!= -1)
6831 printf_filtered (" (thread %d)", b
->thread
);
6832 printf_filtered ("%s%s ",
6833 ((b
->enable_state
== bp_disabled
6834 || b
->enable_state
== bp_call_disabled
)
6838 : ((others
== 1) ? " and" : ""));
6840 current_uiout
->message (_("also set at pc %ps.\n"),
6841 styled_string (address_style
.style (),
6842 paddress (gdbarch
, pc
)));
6847 /* Return true iff it is meaningful to use the address member of LOC.
6848 For some breakpoint types, the locations' address members are
6849 irrelevant and it makes no sense to attempt to compare them to
6850 other addresses (or use them for any other purpose either).
6852 More specifically, software watchpoints and catchpoints that are
6853 not backed by breakpoints always have a zero valued location
6854 address and we don't want to mark breakpoints of any of these types
6855 to be a duplicate of an actual breakpoint location at address
6859 bl_address_is_meaningful (bp_location
*loc
)
6861 return loc
->loc_type
!= bp_loc_other
;
6864 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6865 true if LOC1 and LOC2 represent the same watchpoint location. */
6868 watchpoint_locations_match (struct bp_location
*loc1
,
6869 struct bp_location
*loc2
)
6871 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6872 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6874 /* Both of them must exist. */
6875 gdb_assert (w1
!= NULL
);
6876 gdb_assert (w2
!= NULL
);
6878 /* If the target can evaluate the condition expression in hardware,
6879 then we we need to insert both watchpoints even if they are at
6880 the same place. Otherwise the watchpoint will only trigger when
6881 the condition of whichever watchpoint was inserted evaluates to
6882 true, not giving a chance for GDB to check the condition of the
6883 other watchpoint. */
6885 && target_can_accel_watchpoint_condition (loc1
->address
,
6887 loc1
->watchpoint_type
,
6888 w1
->cond_exp
.get ()))
6890 && target_can_accel_watchpoint_condition (loc2
->address
,
6892 loc2
->watchpoint_type
,
6893 w2
->cond_exp
.get ())))
6896 /* Note that this checks the owner's type, not the location's. In
6897 case the target does not support read watchpoints, but does
6898 support access watchpoints, we'll have bp_read_watchpoint
6899 watchpoints with hw_access locations. Those should be considered
6900 duplicates of hw_read locations. The hw_read locations will
6901 become hw_access locations later. */
6902 return (loc1
->owner
->type
== loc2
->owner
->type
6903 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6904 && loc1
->address
== loc2
->address
6905 && loc1
->length
== loc2
->length
);
6908 /* See breakpoint.h. */
6911 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6912 const address_space
*aspace2
, CORE_ADDR addr2
)
6914 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6915 || aspace1
== aspace2
)
6919 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6920 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6921 matches ASPACE2. On targets that have global breakpoints, the address
6922 space doesn't really matter. */
6925 breakpoint_address_match_range (const address_space
*aspace1
,
6927 int len1
, const address_space
*aspace2
,
6930 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6931 || aspace1
== aspace2
)
6932 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6935 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6936 a ranged breakpoint. In most targets, a match happens only if ASPACE
6937 matches the breakpoint's address space. On targets that have global
6938 breakpoints, the address space doesn't really matter. */
6941 breakpoint_location_address_match (struct bp_location
*bl
,
6942 const address_space
*aspace
,
6945 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6948 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6949 bl
->address
, bl
->length
,
6953 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6954 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6955 match happens only if ASPACE matches the breakpoint's address
6956 space. On targets that have global breakpoints, the address space
6957 doesn't really matter. */
6960 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6961 const address_space
*aspace
,
6962 CORE_ADDR addr
, int len
)
6964 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6965 || bl
->pspace
->aspace
== aspace
)
6967 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6969 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6975 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6976 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6977 true, otherwise returns false. */
6980 tracepoint_locations_match (struct bp_location
*loc1
,
6981 struct bp_location
*loc2
)
6983 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6984 /* Since tracepoint locations are never duplicated with others', tracepoint
6985 locations at the same address of different tracepoints are regarded as
6986 different locations. */
6987 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6992 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6993 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6994 the same location. If SW_HW_BPS_MATCH is true, then software
6995 breakpoint locations and hardware breakpoint locations match,
6996 otherwise they don't. */
6999 breakpoint_locations_match (struct bp_location
*loc1
,
7000 struct bp_location
*loc2
,
7001 bool sw_hw_bps_match
)
7003 int hw_point1
, hw_point2
;
7005 /* Both of them must not be in moribund_locations. */
7006 gdb_assert (loc1
->owner
!= NULL
);
7007 gdb_assert (loc2
->owner
!= NULL
);
7009 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7010 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7012 if (hw_point1
!= hw_point2
)
7015 return watchpoint_locations_match (loc1
, loc2
);
7016 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7017 return tracepoint_locations_match (loc1
, loc2
);
7019 /* We compare bp_location.length in order to cover ranged
7020 breakpoints. Keep this in sync with
7021 bp_location_is_less_than. */
7022 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7023 loc2
->pspace
->aspace
, loc2
->address
)
7024 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7025 && loc1
->length
== loc2
->length
);
7029 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7030 int bnum
, int have_bnum
)
7032 /* The longest string possibly returned by hex_string_custom
7033 is 50 chars. These must be at least that big for safety. */
7037 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7038 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7040 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7041 bnum
, astr1
, astr2
);
7043 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7046 /* Adjust a breakpoint's address to account for architectural
7047 constraints on breakpoint placement. Return the adjusted address.
7048 Note: Very few targets require this kind of adjustment. For most
7049 targets, this function is simply the identity function. */
7052 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7053 CORE_ADDR bpaddr
, enum bptype bptype
)
7055 if (bptype
== bp_watchpoint
7056 || bptype
== bp_hardware_watchpoint
7057 || bptype
== bp_read_watchpoint
7058 || bptype
== bp_access_watchpoint
7059 || bptype
== bp_catchpoint
)
7061 /* Watchpoints and the various bp_catch_* eventpoints should not
7062 have their addresses modified. */
7065 else if (bptype
== bp_single_step
)
7067 /* Single-step breakpoints should not have their addresses
7068 modified. If there's any architectural constrain that
7069 applies to this address, then it should have already been
7070 taken into account when the breakpoint was created in the
7071 first place. If we didn't do this, stepping through e.g.,
7072 Thumb-2 IT blocks would break. */
7077 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7079 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7081 /* Some targets have architectural constraints on the placement
7082 of breakpoint instructions. Obtain the adjusted address. */
7083 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7086 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7088 /* An adjusted breakpoint address can significantly alter
7089 a user's expectations. Print a warning if an adjustment
7091 if (adjusted_bpaddr
!= bpaddr
)
7092 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7094 return adjusted_bpaddr
;
7099 bp_location_from_bp_type (bptype type
)
7104 case bp_single_step
:
7108 case bp_longjmp_resume
:
7109 case bp_longjmp_call_dummy
:
7111 case bp_exception_resume
:
7112 case bp_step_resume
:
7113 case bp_hp_step_resume
:
7114 case bp_watchpoint_scope
:
7116 case bp_std_terminate
:
7117 case bp_shlib_event
:
7118 case bp_thread_event
:
7119 case bp_overlay_event
:
7121 case bp_longjmp_master
:
7122 case bp_std_terminate_master
:
7123 case bp_exception_master
:
7124 case bp_gnu_ifunc_resolver
:
7125 case bp_gnu_ifunc_resolver_return
:
7127 return bp_loc_software_breakpoint
;
7128 case bp_hardware_breakpoint
:
7129 return bp_loc_hardware_breakpoint
;
7130 case bp_hardware_watchpoint
:
7131 case bp_read_watchpoint
:
7132 case bp_access_watchpoint
:
7133 return bp_loc_hardware_watchpoint
;
7137 case bp_fast_tracepoint
:
7138 case bp_static_tracepoint
:
7139 return bp_loc_other
;
7141 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7145 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7147 this->owner
= owner
;
7148 this->cond_bytecode
= NULL
;
7149 this->shlib_disabled
= 0;
7151 this->disabled_by_cond
= false;
7153 this->loc_type
= type
;
7155 if (this->loc_type
== bp_loc_software_breakpoint
7156 || this->loc_type
== bp_loc_hardware_breakpoint
)
7157 mark_breakpoint_location_modified (this);
7162 bp_location::bp_location (breakpoint
*owner
)
7163 : bp_location::bp_location (owner
,
7164 bp_location_from_bp_type (owner
->type
))
7168 /* Allocate a struct bp_location. */
7170 static struct bp_location
*
7171 allocate_bp_location (struct breakpoint
*bpt
)
7173 return bpt
->ops
->allocate_location (bpt
);
7176 /* Decrement reference count. If the reference count reaches 0,
7177 destroy the bp_location. Sets *BLP to NULL. */
7180 decref_bp_location (struct bp_location
**blp
)
7182 bp_location_ref_policy::decref (*blp
);
7186 /* Add breakpoint B at the end of the global breakpoint chain. */
7189 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7191 struct breakpoint
*b1
;
7192 struct breakpoint
*result
= b
.get ();
7194 /* Add this breakpoint to the end of the chain so that a list of
7195 breakpoints will come out in order of increasing numbers. */
7197 b1
= breakpoint_chain
;
7199 breakpoint_chain
= b
.release ();
7204 b1
->next
= b
.release ();
7210 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7213 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7214 struct gdbarch
*gdbarch
,
7216 const struct breakpoint_ops
*ops
)
7218 gdb_assert (ops
!= NULL
);
7222 b
->gdbarch
= gdbarch
;
7223 b
->language
= current_language
->la_language
;
7224 b
->input_radix
= input_radix
;
7225 b
->related_breakpoint
= b
;
7228 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7229 that has type BPTYPE and has no locations as yet. */
7231 static struct breakpoint
*
7232 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7234 const struct breakpoint_ops
*ops
)
7236 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7238 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7239 return add_to_breakpoint_chain (std::move (b
));
7242 /* Initialize loc->function_name. */
7245 set_breakpoint_location_function (struct bp_location
*loc
)
7247 gdb_assert (loc
->owner
!= NULL
);
7249 if (loc
->owner
->type
== bp_breakpoint
7250 || loc
->owner
->type
== bp_hardware_breakpoint
7251 || is_tracepoint (loc
->owner
))
7253 const char *function_name
;
7255 if (loc
->msymbol
!= NULL
7256 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7257 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7259 struct breakpoint
*b
= loc
->owner
;
7261 function_name
= loc
->msymbol
->linkage_name ();
7263 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7264 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7266 /* Create only the whole new breakpoint of this type but do not
7267 mess more complicated breakpoints with multiple locations. */
7268 b
->type
= bp_gnu_ifunc_resolver
;
7269 /* Remember the resolver's address for use by the return
7271 loc
->related_address
= loc
->address
;
7275 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7278 loc
->function_name
= xstrdup (function_name
);
7282 /* Attempt to determine architecture of location identified by SAL. */
7284 get_sal_arch (struct symtab_and_line sal
)
7287 return sal
.section
->objfile
->arch ();
7289 return SYMTAB_OBJFILE (sal
.symtab
)->arch ();
7294 /* Low level routine for partially initializing a breakpoint of type
7295 BPTYPE. The newly created breakpoint's address, section, source
7296 file name, and line number are provided by SAL.
7298 It is expected that the caller will complete the initialization of
7299 the newly created breakpoint struct as well as output any status
7300 information regarding the creation of a new breakpoint. */
7303 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7304 struct symtab_and_line sal
, enum bptype bptype
,
7305 const struct breakpoint_ops
*ops
)
7307 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7309 add_location_to_breakpoint (b
, &sal
);
7311 if (bptype
!= bp_catchpoint
)
7312 gdb_assert (sal
.pspace
!= NULL
);
7314 /* Store the program space that was used to set the breakpoint,
7315 except for ordinary breakpoints, which are independent of the
7317 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7318 b
->pspace
= sal
.pspace
;
7321 /* set_raw_breakpoint is a low level routine for allocating and
7322 partially initializing a breakpoint of type BPTYPE. The newly
7323 created breakpoint's address, section, source file name, and line
7324 number are provided by SAL. The newly created and partially
7325 initialized breakpoint is added to the breakpoint chain and
7326 is also returned as the value of this function.
7328 It is expected that the caller will complete the initialization of
7329 the newly created breakpoint struct as well as output any status
7330 information regarding the creation of a new breakpoint. In
7331 particular, set_raw_breakpoint does NOT set the breakpoint
7332 number! Care should be taken to not allow an error to occur
7333 prior to completing the initialization of the breakpoint. If this
7334 should happen, a bogus breakpoint will be left on the chain. */
7337 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7338 struct symtab_and_line sal
, enum bptype bptype
,
7339 const struct breakpoint_ops
*ops
)
7341 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7343 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7344 return add_to_breakpoint_chain (std::move (b
));
7347 /* Call this routine when stepping and nexting to enable a breakpoint
7348 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7349 initiated the operation. */
7352 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7354 int thread
= tp
->global_num
;
7356 /* To avoid having to rescan all objfile symbols at every step,
7357 we maintain a list of continually-inserted but always disabled
7358 longjmp "master" breakpoints. Here, we simply create momentary
7359 clones of those and enable them for the requested thread. */
7360 for (breakpoint
*b
: all_breakpoints_safe ())
7361 if (b
->pspace
== current_program_space
7362 && (b
->type
== bp_longjmp_master
7363 || b
->type
== bp_exception_master
))
7365 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7366 struct breakpoint
*clone
;
7368 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7369 after their removal. */
7370 clone
= momentary_breakpoint_from_master (b
, type
,
7371 &momentary_breakpoint_ops
, 1);
7372 clone
->thread
= thread
;
7375 tp
->initiating_frame
= frame
;
7378 /* Delete all longjmp breakpoints from THREAD. */
7380 delete_longjmp_breakpoint (int thread
)
7382 for (breakpoint
*b
: all_breakpoints_safe ())
7383 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7385 if (b
->thread
== thread
)
7386 delete_breakpoint (b
);
7391 delete_longjmp_breakpoint_at_next_stop (int thread
)
7393 for (breakpoint
*b
: all_breakpoints_safe ())
7394 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7396 if (b
->thread
== thread
)
7397 b
->disposition
= disp_del_at_next_stop
;
7401 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7402 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7403 pointer to any of them. Return NULL if this system cannot place longjmp
7407 set_longjmp_breakpoint_for_call_dummy (void)
7409 breakpoint
*retval
= nullptr;
7411 for (breakpoint
*b
: all_breakpoints ())
7412 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7414 struct breakpoint
*new_b
;
7416 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7417 &momentary_breakpoint_ops
,
7419 new_b
->thread
= inferior_thread ()->global_num
;
7421 /* Link NEW_B into the chain of RETVAL breakpoints. */
7423 gdb_assert (new_b
->related_breakpoint
== new_b
);
7426 new_b
->related_breakpoint
= retval
;
7427 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7428 retval
= retval
->related_breakpoint
;
7429 retval
->related_breakpoint
= new_b
;
7435 /* Verify all existing dummy frames and their associated breakpoints for
7436 TP. Remove those which can no longer be found in the current frame
7439 You should call this function only at places where it is safe to currently
7440 unwind the whole stack. Failed stack unwind would discard live dummy
7444 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7446 struct breakpoint
*b
, *b_tmp
;
7448 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7449 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7451 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7453 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7454 dummy_b
= dummy_b
->related_breakpoint
;
7455 if (dummy_b
->type
!= bp_call_dummy
7456 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7459 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7461 while (b
->related_breakpoint
!= b
)
7463 if (b_tmp
== b
->related_breakpoint
)
7464 b_tmp
= b
->related_breakpoint
->next
;
7465 delete_breakpoint (b
->related_breakpoint
);
7467 delete_breakpoint (b
);
7472 enable_overlay_breakpoints (void)
7474 for (breakpoint
*b
: all_breakpoints ())
7475 if (b
->type
== bp_overlay_event
)
7477 b
->enable_state
= bp_enabled
;
7478 update_global_location_list (UGLL_MAY_INSERT
);
7479 overlay_events_enabled
= 1;
7484 disable_overlay_breakpoints (void)
7486 for (breakpoint
*b
: all_breakpoints ())
7487 if (b
->type
== bp_overlay_event
)
7489 b
->enable_state
= bp_disabled
;
7490 update_global_location_list (UGLL_DONT_INSERT
);
7491 overlay_events_enabled
= 0;
7495 /* Set an active std::terminate breakpoint for each std::terminate
7496 master breakpoint. */
7498 set_std_terminate_breakpoint (void)
7500 for (breakpoint
*b
: all_breakpoints_safe ())
7501 if (b
->pspace
== current_program_space
7502 && b
->type
== bp_std_terminate_master
)
7504 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7505 &momentary_breakpoint_ops
, 1);
7509 /* Delete all the std::terminate breakpoints. */
7511 delete_std_terminate_breakpoint (void)
7513 for (breakpoint
*b
: all_breakpoints_safe ())
7514 if (b
->type
== bp_std_terminate
)
7515 delete_breakpoint (b
);
7519 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7521 struct breakpoint
*b
;
7523 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7524 &internal_breakpoint_ops
);
7526 b
->enable_state
= bp_enabled
;
7527 /* location has to be used or breakpoint_re_set will delete me. */
7528 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7530 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7535 struct lang_and_radix
7541 /* Create a breakpoint for JIT code registration and unregistration. */
7544 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7546 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7547 &internal_breakpoint_ops
);
7550 /* Remove JIT code registration and unregistration breakpoint(s). */
7553 remove_jit_event_breakpoints (void)
7555 for (breakpoint
*b
: all_breakpoints_safe ())
7556 if (b
->type
== bp_jit_event
7557 && b
->loc
->pspace
== current_program_space
)
7558 delete_breakpoint (b
);
7562 remove_solib_event_breakpoints (void)
7564 for (breakpoint
*b
: all_breakpoints_safe ())
7565 if (b
->type
== bp_shlib_event
7566 && b
->loc
->pspace
== current_program_space
)
7567 delete_breakpoint (b
);
7570 /* See breakpoint.h. */
7573 remove_solib_event_breakpoints_at_next_stop (void)
7575 for (breakpoint
*b
: all_breakpoints_safe ())
7576 if (b
->type
== bp_shlib_event
7577 && b
->loc
->pspace
== current_program_space
)
7578 b
->disposition
= disp_del_at_next_stop
;
7581 /* Helper for create_solib_event_breakpoint /
7582 create_and_insert_solib_event_breakpoint. Allows specifying which
7583 INSERT_MODE to pass through to update_global_location_list. */
7585 static struct breakpoint
*
7586 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7587 enum ugll_insert_mode insert_mode
)
7589 struct breakpoint
*b
;
7591 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7592 &internal_breakpoint_ops
);
7593 update_global_location_list_nothrow (insert_mode
);
7598 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7600 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7603 /* See breakpoint.h. */
7606 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7608 struct breakpoint
*b
;
7610 /* Explicitly tell update_global_location_list to insert
7612 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7613 if (!b
->loc
->inserted
)
7615 delete_breakpoint (b
);
7621 /* Disable any breakpoints that are on code in shared libraries. Only
7622 apply to enabled breakpoints, disabled ones can just stay disabled. */
7625 disable_breakpoints_in_shlibs (void)
7627 struct bp_location
*loc
, **locp_tmp
;
7629 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7631 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7632 struct breakpoint
*b
= loc
->owner
;
7634 /* We apply the check to all breakpoints, including disabled for
7635 those with loc->duplicate set. This is so that when breakpoint
7636 becomes enabled, or the duplicate is removed, gdb will try to
7637 insert all breakpoints. If we don't set shlib_disabled here,
7638 we'll try to insert those breakpoints and fail. */
7639 if (((b
->type
== bp_breakpoint
)
7640 || (b
->type
== bp_jit_event
)
7641 || (b
->type
== bp_hardware_breakpoint
)
7642 || (is_tracepoint (b
)))
7643 && loc
->pspace
== current_program_space
7644 && !loc
->shlib_disabled
7645 && solib_name_from_address (loc
->pspace
, loc
->address
)
7648 loc
->shlib_disabled
= 1;
7653 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7654 notification of unloaded_shlib. Only apply to enabled breakpoints,
7655 disabled ones can just stay disabled. */
7658 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7660 struct bp_location
*loc
, **locp_tmp
;
7661 int disabled_shlib_breaks
= 0;
7663 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7665 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7666 struct breakpoint
*b
= loc
->owner
;
7668 if (solib
->pspace
== loc
->pspace
7669 && !loc
->shlib_disabled
7670 && (((b
->type
== bp_breakpoint
7671 || b
->type
== bp_jit_event
7672 || b
->type
== bp_hardware_breakpoint
)
7673 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7674 || loc
->loc_type
== bp_loc_software_breakpoint
))
7675 || is_tracepoint (b
))
7676 && solib_contains_address_p (solib
, loc
->address
))
7678 loc
->shlib_disabled
= 1;
7679 /* At this point, we cannot rely on remove_breakpoint
7680 succeeding so we must mark the breakpoint as not inserted
7681 to prevent future errors occurring in remove_breakpoints. */
7684 /* This may cause duplicate notifications for the same breakpoint. */
7685 gdb::observers::breakpoint_modified
.notify (b
);
7687 if (!disabled_shlib_breaks
)
7689 target_terminal::ours_for_output ();
7690 warning (_("Temporarily disabling breakpoints "
7691 "for unloaded shared library \"%s\""),
7694 disabled_shlib_breaks
= 1;
7699 /* Disable any breakpoints and tracepoints in OBJFILE upon
7700 notification of free_objfile. Only apply to enabled breakpoints,
7701 disabled ones can just stay disabled. */
7704 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7706 if (objfile
== NULL
)
7709 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7710 managed by the user with add-symbol-file/remove-symbol-file.
7711 Similarly to how breakpoints in shared libraries are handled in
7712 response to "nosharedlibrary", mark breakpoints in such modules
7713 shlib_disabled so they end up uninserted on the next global
7714 location list update. Shared libraries not loaded by the user
7715 aren't handled here -- they're already handled in
7716 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7717 solib_unloaded observer. We skip objfiles that are not
7718 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7720 if ((objfile
->flags
& OBJF_SHARED
) == 0
7721 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7724 for (breakpoint
*b
: all_breakpoints ())
7726 int bp_modified
= 0;
7728 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7731 for (bp_location
*loc
: b
->locations ())
7733 CORE_ADDR loc_addr
= loc
->address
;
7735 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7736 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7739 if (loc
->shlib_disabled
!= 0)
7742 if (objfile
->pspace
!= loc
->pspace
)
7745 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7746 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7749 if (is_addr_in_objfile (loc_addr
, objfile
))
7751 loc
->shlib_disabled
= 1;
7752 /* At this point, we don't know whether the object was
7753 unmapped from the inferior or not, so leave the
7754 inserted flag alone. We'll handle failure to
7755 uninsert quietly, in case the object was indeed
7758 mark_breakpoint_location_modified (loc
);
7765 gdb::observers::breakpoint_modified
.notify (b
);
7769 /* FORK & VFORK catchpoints. */
7771 /* An instance of this type is used to represent a fork or vfork
7772 catchpoint. A breakpoint is really of this type iff its ops pointer points
7773 to CATCH_FORK_BREAKPOINT_OPS. */
7775 struct fork_catchpoint
: public breakpoint
7777 /* Process id of a child process whose forking triggered this
7778 catchpoint. This field is only valid immediately after this
7779 catchpoint has triggered. */
7780 ptid_t forked_inferior_pid
;
7783 /* Implement the "insert" breakpoint_ops method for fork
7787 insert_catch_fork (struct bp_location
*bl
)
7789 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7792 /* Implement the "remove" breakpoint_ops method for fork
7796 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7798 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7801 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7805 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7806 const address_space
*aspace
, CORE_ADDR bp_addr
,
7807 const struct target_waitstatus
*ws
)
7809 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7811 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7814 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7818 /* Implement the "print_it" breakpoint_ops method for fork
7821 static enum print_stop_action
7822 print_it_catch_fork (bpstat bs
)
7824 struct ui_out
*uiout
= current_uiout
;
7825 struct breakpoint
*b
= bs
->breakpoint_at
;
7826 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7828 annotate_catchpoint (b
->number
);
7829 maybe_print_thread_hit_breakpoint (uiout
);
7830 if (b
->disposition
== disp_del
)
7831 uiout
->text ("Temporary catchpoint ");
7833 uiout
->text ("Catchpoint ");
7834 if (uiout
->is_mi_like_p ())
7836 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7837 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7839 uiout
->field_signed ("bkptno", b
->number
);
7840 uiout
->text (" (forked process ");
7841 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7842 uiout
->text ("), ");
7843 return PRINT_SRC_AND_LOC
;
7846 /* Implement the "print_one" breakpoint_ops method for fork
7850 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7852 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7853 struct value_print_options opts
;
7854 struct ui_out
*uiout
= current_uiout
;
7856 get_user_print_options (&opts
);
7858 /* Field 4, the address, is omitted (which makes the columns not
7859 line up too nicely with the headers, but the effect is relatively
7861 if (opts
.addressprint
)
7862 uiout
->field_skip ("addr");
7864 uiout
->text ("fork");
7865 if (c
->forked_inferior_pid
!= null_ptid
)
7867 uiout
->text (", process ");
7868 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7872 if (uiout
->is_mi_like_p ())
7873 uiout
->field_string ("catch-type", "fork");
7876 /* Implement the "print_mention" breakpoint_ops method for fork
7880 print_mention_catch_fork (struct breakpoint
*b
)
7882 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7885 /* Implement the "print_recreate" breakpoint_ops method for fork
7889 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7891 fprintf_unfiltered (fp
, "catch fork");
7892 print_recreate_thread (b
, fp
);
7895 /* The breakpoint_ops structure to be used in fork catchpoints. */
7897 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7899 /* Implement the "insert" breakpoint_ops method for vfork
7903 insert_catch_vfork (struct bp_location
*bl
)
7905 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7908 /* Implement the "remove" breakpoint_ops method for vfork
7912 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7914 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7917 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7921 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7922 const address_space
*aspace
, CORE_ADDR bp_addr
,
7923 const struct target_waitstatus
*ws
)
7925 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7927 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7930 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7934 /* Implement the "print_it" breakpoint_ops method for vfork
7937 static enum print_stop_action
7938 print_it_catch_vfork (bpstat bs
)
7940 struct ui_out
*uiout
= current_uiout
;
7941 struct breakpoint
*b
= bs
->breakpoint_at
;
7942 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7944 annotate_catchpoint (b
->number
);
7945 maybe_print_thread_hit_breakpoint (uiout
);
7946 if (b
->disposition
== disp_del
)
7947 uiout
->text ("Temporary catchpoint ");
7949 uiout
->text ("Catchpoint ");
7950 if (uiout
->is_mi_like_p ())
7952 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7953 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7955 uiout
->field_signed ("bkptno", b
->number
);
7956 uiout
->text (" (vforked process ");
7957 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7958 uiout
->text ("), ");
7959 return PRINT_SRC_AND_LOC
;
7962 /* Implement the "print_one" breakpoint_ops method for vfork
7966 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7968 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7969 struct value_print_options opts
;
7970 struct ui_out
*uiout
= current_uiout
;
7972 get_user_print_options (&opts
);
7973 /* Field 4, the address, is omitted (which makes the columns not
7974 line up too nicely with the headers, but the effect is relatively
7976 if (opts
.addressprint
)
7977 uiout
->field_skip ("addr");
7979 uiout
->text ("vfork");
7980 if (c
->forked_inferior_pid
!= null_ptid
)
7982 uiout
->text (", process ");
7983 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7987 if (uiout
->is_mi_like_p ())
7988 uiout
->field_string ("catch-type", "vfork");
7991 /* Implement the "print_mention" breakpoint_ops method for vfork
7995 print_mention_catch_vfork (struct breakpoint
*b
)
7997 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8000 /* Implement the "print_recreate" breakpoint_ops method for vfork
8004 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8006 fprintf_unfiltered (fp
, "catch vfork");
8007 print_recreate_thread (b
, fp
);
8010 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8012 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8014 /* An instance of this type is used to represent an solib catchpoint.
8015 A breakpoint is really of this type iff its ops pointer points to
8016 CATCH_SOLIB_BREAKPOINT_OPS. */
8018 struct solib_catchpoint
: public breakpoint
8020 ~solib_catchpoint () override
;
8022 /* True for "catch load", false for "catch unload". */
8025 /* Regular expression to match, if any. COMPILED is only valid when
8026 REGEX is non-NULL. */
8028 std::unique_ptr
<compiled_regex
> compiled
;
8031 solib_catchpoint::~solib_catchpoint ()
8033 xfree (this->regex
);
8037 insert_catch_solib (struct bp_location
*ignore
)
8043 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8049 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8050 const address_space
*aspace
,
8052 const struct target_waitstatus
*ws
)
8054 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8056 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8059 for (breakpoint
*other
: all_breakpoints ())
8061 if (other
== bl
->owner
)
8064 if (other
->type
!= bp_shlib_event
)
8067 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8070 for (bp_location
*other_bl
: other
->locations ())
8072 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8081 check_status_catch_solib (struct bpstats
*bs
)
8083 struct solib_catchpoint
*self
8084 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8088 for (so_list
*iter
: current_program_space
->added_solibs
)
8091 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8097 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
8100 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
8106 bs
->print_it
= print_it_noop
;
8109 static enum print_stop_action
8110 print_it_catch_solib (bpstat bs
)
8112 struct breakpoint
*b
= bs
->breakpoint_at
;
8113 struct ui_out
*uiout
= current_uiout
;
8115 annotate_catchpoint (b
->number
);
8116 maybe_print_thread_hit_breakpoint (uiout
);
8117 if (b
->disposition
== disp_del
)
8118 uiout
->text ("Temporary catchpoint ");
8120 uiout
->text ("Catchpoint ");
8121 uiout
->field_signed ("bkptno", b
->number
);
8123 if (uiout
->is_mi_like_p ())
8124 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8125 print_solib_event (1);
8126 return PRINT_SRC_AND_LOC
;
8130 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8132 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8133 struct value_print_options opts
;
8134 struct ui_out
*uiout
= current_uiout
;
8136 get_user_print_options (&opts
);
8137 /* Field 4, the address, is omitted (which makes the columns not
8138 line up too nicely with the headers, but the effect is relatively
8140 if (opts
.addressprint
)
8143 uiout
->field_skip ("addr");
8151 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8153 msg
= _("load of library");
8158 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8160 msg
= _("unload of library");
8162 uiout
->field_string ("what", msg
);
8164 if (uiout
->is_mi_like_p ())
8165 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8169 print_mention_catch_solib (struct breakpoint
*b
)
8171 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8173 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8174 self
->is_load
? "load" : "unload");
8178 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8180 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8182 fprintf_unfiltered (fp
, "%s %s",
8183 b
->disposition
== disp_del
? "tcatch" : "catch",
8184 self
->is_load
? "load" : "unload");
8186 fprintf_unfiltered (fp
, " %s", self
->regex
);
8187 fprintf_unfiltered (fp
, "\n");
8190 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8192 /* See breakpoint.h. */
8195 add_solib_catchpoint (const char *arg
, bool is_load
, bool is_temp
, bool enabled
)
8197 struct gdbarch
*gdbarch
= get_current_arch ();
8201 arg
= skip_spaces (arg
);
8203 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8207 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8208 _("Invalid regexp")));
8209 c
->regex
= xstrdup (arg
);
8212 c
->is_load
= is_load
;
8213 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8214 &catch_solib_breakpoint_ops
);
8216 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8218 install_breakpoint (0, std::move (c
), 1);
8221 /* A helper function that does all the work for "catch load" and
8225 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8226 struct cmd_list_element
*command
)
8228 const int enabled
= 1;
8229 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8231 add_solib_catchpoint (arg
, is_load
, temp
, enabled
);
8235 catch_load_command_1 (const char *arg
, int from_tty
,
8236 struct cmd_list_element
*command
)
8238 catch_load_or_unload (arg
, from_tty
, 1, command
);
8242 catch_unload_command_1 (const char *arg
, int from_tty
,
8243 struct cmd_list_element
*command
)
8245 catch_load_or_unload (arg
, from_tty
, 0, command
);
8248 /* See breakpoint.h. */
8251 init_catchpoint (struct breakpoint
*b
,
8252 struct gdbarch
*gdbarch
, bool temp
,
8253 const char *cond_string
,
8254 const struct breakpoint_ops
*ops
)
8256 symtab_and_line sal
;
8257 sal
.pspace
= current_program_space
;
8259 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8261 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8262 b
->disposition
= temp
? disp_del
: disp_donttouch
;
8266 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8268 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8269 set_breakpoint_number (internal
, b
);
8270 if (is_tracepoint (b
))
8271 set_tracepoint_count (breakpoint_count
);
8274 gdb::observers::breakpoint_created
.notify (b
);
8277 update_global_location_list (UGLL_MAY_INSERT
);
8281 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8282 bool temp
, const char *cond_string
,
8283 const struct breakpoint_ops
*ops
)
8285 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8287 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
, ops
);
8289 c
->forked_inferior_pid
= null_ptid
;
8291 install_breakpoint (0, std::move (c
), 1);
8294 /* Exec catchpoints. */
8296 /* An instance of this type is used to represent an exec catchpoint.
8297 A breakpoint is really of this type iff its ops pointer points to
8298 CATCH_EXEC_BREAKPOINT_OPS. */
8300 struct exec_catchpoint
: public breakpoint
8302 ~exec_catchpoint () override
;
8304 /* Filename of a program whose exec triggered this catchpoint.
8305 This field is only valid immediately after this catchpoint has
8307 char *exec_pathname
;
8310 /* Exec catchpoint destructor. */
8312 exec_catchpoint::~exec_catchpoint ()
8314 xfree (this->exec_pathname
);
8318 insert_catch_exec (struct bp_location
*bl
)
8320 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8324 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8326 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8330 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8331 const address_space
*aspace
, CORE_ADDR bp_addr
,
8332 const struct target_waitstatus
*ws
)
8334 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8336 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8339 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8343 static enum print_stop_action
8344 print_it_catch_exec (bpstat bs
)
8346 struct ui_out
*uiout
= current_uiout
;
8347 struct breakpoint
*b
= bs
->breakpoint_at
;
8348 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8350 annotate_catchpoint (b
->number
);
8351 maybe_print_thread_hit_breakpoint (uiout
);
8352 if (b
->disposition
== disp_del
)
8353 uiout
->text ("Temporary catchpoint ");
8355 uiout
->text ("Catchpoint ");
8356 if (uiout
->is_mi_like_p ())
8358 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8359 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8361 uiout
->field_signed ("bkptno", b
->number
);
8362 uiout
->text (" (exec'd ");
8363 uiout
->field_string ("new-exec", c
->exec_pathname
);
8364 uiout
->text ("), ");
8366 return PRINT_SRC_AND_LOC
;
8370 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8372 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8373 struct value_print_options opts
;
8374 struct ui_out
*uiout
= current_uiout
;
8376 get_user_print_options (&opts
);
8378 /* Field 4, the address, is omitted (which makes the columns
8379 not line up too nicely with the headers, but the effect
8380 is relatively readable). */
8381 if (opts
.addressprint
)
8382 uiout
->field_skip ("addr");
8384 uiout
->text ("exec");
8385 if (c
->exec_pathname
!= NULL
)
8387 uiout
->text (", program \"");
8388 uiout
->field_string ("what", c
->exec_pathname
);
8389 uiout
->text ("\" ");
8392 if (uiout
->is_mi_like_p ())
8393 uiout
->field_string ("catch-type", "exec");
8397 print_mention_catch_exec (struct breakpoint
*b
)
8399 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8402 /* Implement the "print_recreate" breakpoint_ops method for exec
8406 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8408 fprintf_unfiltered (fp
, "catch exec");
8409 print_recreate_thread (b
, fp
);
8412 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8415 hw_breakpoint_used_count (void)
8419 for (breakpoint
*b
: all_breakpoints ())
8420 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8421 for (bp_location
*bl
: b
->locations ())
8423 /* Special types of hardware breakpoints may use more than
8425 i
+= b
->ops
->resources_needed (bl
);
8431 /* Returns the resources B would use if it were a hardware
8435 hw_watchpoint_use_count (struct breakpoint
*b
)
8439 if (!breakpoint_enabled (b
))
8442 for (bp_location
*bl
: b
->locations ())
8444 /* Special types of hardware watchpoints may use more than
8446 i
+= b
->ops
->resources_needed (bl
);
8452 /* Returns the sum the used resources of all hardware watchpoints of
8453 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8454 the sum of the used resources of all hardware watchpoints of other
8455 types _not_ TYPE. */
8458 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8459 enum bptype type
, int *other_type_used
)
8463 *other_type_used
= 0;
8464 for (breakpoint
*b
: all_breakpoints ())
8468 if (!breakpoint_enabled (b
))
8471 if (b
->type
== type
)
8472 i
+= hw_watchpoint_use_count (b
);
8473 else if (is_hardware_watchpoint (b
))
8474 *other_type_used
= 1;
8481 disable_watchpoints_before_interactive_call_start (void)
8483 for (breakpoint
*b
: all_breakpoints ())
8484 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8486 b
->enable_state
= bp_call_disabled
;
8487 update_global_location_list (UGLL_DONT_INSERT
);
8492 enable_watchpoints_after_interactive_call_stop (void)
8494 for (breakpoint
*b
: all_breakpoints ())
8495 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8497 b
->enable_state
= bp_enabled
;
8498 update_global_location_list (UGLL_MAY_INSERT
);
8503 disable_breakpoints_before_startup (void)
8505 current_program_space
->executing_startup
= 1;
8506 update_global_location_list (UGLL_DONT_INSERT
);
8510 enable_breakpoints_after_startup (void)
8512 current_program_space
->executing_startup
= 0;
8513 breakpoint_re_set ();
8516 /* Create a new single-step breakpoint for thread THREAD, with no
8519 static struct breakpoint
*
8520 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8522 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8524 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8525 &momentary_breakpoint_ops
);
8527 b
->disposition
= disp_donttouch
;
8528 b
->frame_id
= null_frame_id
;
8531 gdb_assert (b
->thread
!= 0);
8533 return add_to_breakpoint_chain (std::move (b
));
8536 /* Set a momentary breakpoint of type TYPE at address specified by
8537 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8541 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8542 struct frame_id frame_id
, enum bptype type
)
8544 struct breakpoint
*b
;
8546 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8548 gdb_assert (!frame_id_artificial_p (frame_id
));
8550 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8551 b
->enable_state
= bp_enabled
;
8552 b
->disposition
= disp_donttouch
;
8553 b
->frame_id
= frame_id
;
8555 b
->thread
= inferior_thread ()->global_num
;
8557 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8559 return breakpoint_up (b
);
8562 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8563 The new breakpoint will have type TYPE, use OPS as its
8564 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8566 static struct breakpoint
*
8567 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8569 const struct breakpoint_ops
*ops
,
8572 struct breakpoint
*copy
;
8574 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8575 copy
->loc
= allocate_bp_location (copy
);
8576 set_breakpoint_location_function (copy
->loc
);
8578 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8579 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8580 copy
->loc
->address
= orig
->loc
->address
;
8581 copy
->loc
->section
= orig
->loc
->section
;
8582 copy
->loc
->pspace
= orig
->loc
->pspace
;
8583 copy
->loc
->probe
= orig
->loc
->probe
;
8584 copy
->loc
->line_number
= orig
->loc
->line_number
;
8585 copy
->loc
->symtab
= orig
->loc
->symtab
;
8586 copy
->loc
->enabled
= loc_enabled
;
8587 copy
->frame_id
= orig
->frame_id
;
8588 copy
->thread
= orig
->thread
;
8589 copy
->pspace
= orig
->pspace
;
8591 copy
->enable_state
= bp_enabled
;
8592 copy
->disposition
= disp_donttouch
;
8593 copy
->number
= internal_breakpoint_number
--;
8595 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8599 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8603 clone_momentary_breakpoint (struct breakpoint
*orig
)
8605 /* If there's nothing to clone, then return nothing. */
8609 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8613 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8616 struct symtab_and_line sal
;
8618 sal
= find_pc_line (pc
, 0);
8620 sal
.section
= find_pc_overlay (pc
);
8621 sal
.explicit_pc
= 1;
8623 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8627 /* Tell the user we have just set a breakpoint B. */
8630 mention (struct breakpoint
*b
)
8632 b
->ops
->print_mention (b
);
8633 current_uiout
->text ("\n");
8637 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8639 /* Handle "set breakpoint auto-hw on".
8641 If the explicitly specified breakpoint type is not hardware
8642 breakpoint, check the memory map to see whether the breakpoint
8643 address is in read-only memory.
8645 - location type is not hardware breakpoint, memory is read-only.
8646 We change the type of the location to hardware breakpoint.
8648 - location type is hardware breakpoint, memory is read-write. This
8649 means we've previously made the location hardware one, but then the
8650 memory map changed, so we undo.
8654 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8656 if (automatic_hardware_breakpoints
8657 && bl
->owner
->type
!= bp_hardware_breakpoint
8658 && (bl
->loc_type
== bp_loc_software_breakpoint
8659 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8661 /* When breakpoints are removed, remove_breakpoints will use
8662 location types we've just set here, the only possible problem
8663 is that memory map has changed during running program, but
8664 it's not going to work anyway with current gdb. */
8665 mem_region
*mr
= lookup_mem_region (bl
->address
);
8669 enum bp_loc_type new_type
;
8671 if (mr
->attrib
.mode
!= MEM_RW
)
8672 new_type
= bp_loc_hardware_breakpoint
;
8674 new_type
= bp_loc_software_breakpoint
;
8676 if (new_type
!= bl
->loc_type
)
8678 static bool said
= false;
8680 bl
->loc_type
= new_type
;
8683 fprintf_filtered (gdb_stdout
,
8684 _("Note: automatically using "
8685 "hardware breakpoints for "
8686 "read-only addresses.\n"));
8694 static struct bp_location
*
8695 add_location_to_breakpoint (struct breakpoint
*b
,
8696 const struct symtab_and_line
*sal
)
8698 struct bp_location
*loc
, **tmp
;
8699 CORE_ADDR adjusted_address
;
8700 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8702 if (loc_gdbarch
== NULL
)
8703 loc_gdbarch
= b
->gdbarch
;
8705 /* Adjust the breakpoint's address prior to allocating a location.
8706 Once we call allocate_bp_location(), that mostly uninitialized
8707 location will be placed on the location chain. Adjustment of the
8708 breakpoint may cause target_read_memory() to be called and we do
8709 not want its scan of the location chain to find a breakpoint and
8710 location that's only been partially initialized. */
8711 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8714 /* Sort the locations by their ADDRESS. */
8715 loc
= allocate_bp_location (b
);
8716 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8717 tmp
= &((*tmp
)->next
))
8722 loc
->requested_address
= sal
->pc
;
8723 loc
->address
= adjusted_address
;
8724 loc
->pspace
= sal
->pspace
;
8725 loc
->probe
.prob
= sal
->prob
;
8726 loc
->probe
.objfile
= sal
->objfile
;
8727 gdb_assert (loc
->pspace
!= NULL
);
8728 loc
->section
= sal
->section
;
8729 loc
->gdbarch
= loc_gdbarch
;
8730 loc
->line_number
= sal
->line
;
8731 loc
->symtab
= sal
->symtab
;
8732 loc
->symbol
= sal
->symbol
;
8733 loc
->msymbol
= sal
->msymbol
;
8734 loc
->objfile
= sal
->objfile
;
8736 set_breakpoint_location_function (loc
);
8738 /* While by definition, permanent breakpoints are already present in the
8739 code, we don't mark the location as inserted. Normally one would expect
8740 that GDB could rely on that breakpoint instruction to stop the program,
8741 thus removing the need to insert its own breakpoint, except that executing
8742 the breakpoint instruction can kill the target instead of reporting a
8743 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8744 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8745 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8746 breakpoint be inserted normally results in QEMU knowing about the GDB
8747 breakpoint, and thus trap before the breakpoint instruction is executed.
8748 (If GDB later needs to continue execution past the permanent breakpoint,
8749 it manually increments the PC, thus avoiding executing the breakpoint
8751 if (bp_loc_is_permanent (loc
))
8758 /* Return true if LOC is pointing to a permanent breakpoint,
8759 return false otherwise. */
8762 bp_loc_is_permanent (struct bp_location
*loc
)
8764 gdb_assert (loc
!= NULL
);
8766 /* If we have a non-breakpoint-backed catchpoint or a software
8767 watchpoint, just return 0. We should not attempt to read from
8768 the addresses the locations of these breakpoint types point to.
8769 gdbarch_program_breakpoint_here_p, below, will attempt to read
8771 if (!bl_address_is_meaningful (loc
))
8774 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8775 switch_to_program_space_and_thread (loc
->pspace
);
8776 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8779 /* Build a command list for the dprintf corresponding to the current
8780 settings of the dprintf style options. */
8783 update_dprintf_command_list (struct breakpoint
*b
)
8785 char *dprintf_args
= b
->extra_string
;
8786 char *printf_line
= NULL
;
8791 dprintf_args
= skip_spaces (dprintf_args
);
8793 /* Allow a comma, as it may have terminated a location, but don't
8795 if (*dprintf_args
== ',')
8797 dprintf_args
= skip_spaces (dprintf_args
);
8799 if (*dprintf_args
!= '"')
8800 error (_("Bad format string, missing '\"'."));
8802 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8803 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8804 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8806 if (!dprintf_function
)
8807 error (_("No function supplied for dprintf call"));
8809 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8810 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8815 printf_line
= xstrprintf ("call (void) %s (%s)",
8819 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8821 if (target_can_run_breakpoint_commands ())
8822 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8825 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8826 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8830 internal_error (__FILE__
, __LINE__
,
8831 _("Invalid dprintf style."));
8833 gdb_assert (printf_line
!= NULL
);
8835 /* Manufacture a printf sequence. */
8836 struct command_line
*printf_cmd_line
8837 = new struct command_line (simple_control
, printf_line
);
8838 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8839 command_lines_deleter ()));
8842 /* Update all dprintf commands, making their command lists reflect
8843 current style settings. */
8846 update_dprintf_commands (const char *args
, int from_tty
,
8847 struct cmd_list_element
*c
)
8849 for (breakpoint
*b
: all_breakpoints ())
8850 if (b
->type
== bp_dprintf
)
8851 update_dprintf_command_list (b
);
8854 /* Create a breakpoint with SAL as location. Use LOCATION
8855 as a description of the location, and COND_STRING
8856 as condition expression. If LOCATION is NULL then create an
8857 "address location" from the address in the SAL. */
8860 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8861 gdb::array_view
<const symtab_and_line
> sals
,
8862 event_location_up
&&location
,
8863 gdb::unique_xmalloc_ptr
<char> filter
,
8864 gdb::unique_xmalloc_ptr
<char> cond_string
,
8865 gdb::unique_xmalloc_ptr
<char> extra_string
,
8866 enum bptype type
, enum bpdisp disposition
,
8867 int thread
, int task
, int ignore_count
,
8868 const struct breakpoint_ops
*ops
, int from_tty
,
8869 int enabled
, int internal
, unsigned flags
,
8870 int display_canonical
)
8874 if (type
== bp_hardware_breakpoint
)
8876 int target_resources_ok
;
8878 i
= hw_breakpoint_used_count ();
8879 target_resources_ok
=
8880 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8882 if (target_resources_ok
== 0)
8883 error (_("No hardware breakpoint support in the target."));
8884 else if (target_resources_ok
< 0)
8885 error (_("Hardware breakpoints used exceeds limit."));
8888 gdb_assert (!sals
.empty ());
8890 for (const auto &sal
: sals
)
8892 struct bp_location
*loc
;
8896 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8898 loc_gdbarch
= gdbarch
;
8900 describe_other_breakpoints (loc_gdbarch
,
8901 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8904 if (&sal
== &sals
[0])
8906 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8910 b
->cond_string
= cond_string
.release ();
8911 b
->extra_string
= extra_string
.release ();
8912 b
->ignore_count
= ignore_count
;
8913 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8914 b
->disposition
= disposition
;
8916 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8917 b
->loc
->inserted
= 1;
8919 if (type
== bp_static_tracepoint
)
8921 struct tracepoint
*t
= (struct tracepoint
*) b
;
8922 struct static_tracepoint_marker marker
;
8924 if (strace_marker_p (b
))
8926 /* We already know the marker exists, otherwise, we
8927 wouldn't see a sal for it. */
8929 = &event_location_to_string (b
->location
.get ())[3];
8932 p
= skip_spaces (p
);
8934 endp
= skip_to_space (p
);
8936 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8938 printf_filtered (_("Probed static tracepoint "
8940 t
->static_trace_marker_id
.c_str ());
8942 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8944 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8946 printf_filtered (_("Probed static tracepoint "
8948 t
->static_trace_marker_id
.c_str ());
8951 warning (_("Couldn't determine the static "
8952 "tracepoint marker to probe"));
8959 loc
= add_location_to_breakpoint (b
, &sal
);
8960 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8964 /* Do not set breakpoint locations conditions yet. As locations
8965 are inserted, they get sorted based on their addresses. Let
8966 the list stabilize to have reliable location numbers. */
8968 /* Dynamic printf requires and uses additional arguments on the
8969 command line, otherwise it's an error. */
8970 if (type
== bp_dprintf
)
8972 if (b
->extra_string
)
8973 update_dprintf_command_list (b
);
8975 error (_("Format string required"));
8977 else if (b
->extra_string
)
8978 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8982 /* The order of the locations is now stable. Set the location
8983 condition using the location's number. */
8985 for (bp_location
*loc
: b
->locations ())
8987 if (b
->cond_string
!= nullptr)
8988 set_breakpoint_location_condition (b
->cond_string
, loc
, b
->number
,
8994 b
->display_canonical
= display_canonical
;
8995 if (location
!= NULL
)
8996 b
->location
= std::move (location
);
8998 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8999 b
->filter
= std::move (filter
);
9003 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9004 gdb::array_view
<const symtab_and_line
> sals
,
9005 event_location_up
&&location
,
9006 gdb::unique_xmalloc_ptr
<char> filter
,
9007 gdb::unique_xmalloc_ptr
<char> cond_string
,
9008 gdb::unique_xmalloc_ptr
<char> extra_string
,
9009 enum bptype type
, enum bpdisp disposition
,
9010 int thread
, int task
, int ignore_count
,
9011 const struct breakpoint_ops
*ops
, int from_tty
,
9012 int enabled
, int internal
, unsigned flags
,
9013 int display_canonical
)
9015 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9017 init_breakpoint_sal (b
.get (), gdbarch
,
9018 sals
, std::move (location
),
9020 std::move (cond_string
),
9021 std::move (extra_string
),
9023 thread
, task
, ignore_count
,
9025 enabled
, internal
, flags
,
9028 install_breakpoint (internal
, std::move (b
), 0);
9031 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9032 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9033 value. COND_STRING, if not NULL, specified the condition to be
9034 used for all breakpoints. Essentially the only case where
9035 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9036 function. In that case, it's still not possible to specify
9037 separate conditions for different overloaded functions, so
9038 we take just a single condition string.
9040 NOTE: If the function succeeds, the caller is expected to cleanup
9041 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9042 array contents). If the function fails (error() is called), the
9043 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9044 COND and SALS arrays and each of those arrays contents. */
9047 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9048 struct linespec_result
*canonical
,
9049 gdb::unique_xmalloc_ptr
<char> cond_string
,
9050 gdb::unique_xmalloc_ptr
<char> extra_string
,
9051 enum bptype type
, enum bpdisp disposition
,
9052 int thread
, int task
, int ignore_count
,
9053 const struct breakpoint_ops
*ops
, int from_tty
,
9054 int enabled
, int internal
, unsigned flags
)
9056 if (canonical
->pre_expanded
)
9057 gdb_assert (canonical
->lsals
.size () == 1);
9059 for (const auto &lsal
: canonical
->lsals
)
9061 /* Note that 'location' can be NULL in the case of a plain
9062 'break', without arguments. */
9063 event_location_up location
9064 = (canonical
->location
!= NULL
9065 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9066 gdb::unique_xmalloc_ptr
<char> filter_string
9067 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9069 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9070 std::move (location
),
9071 std::move (filter_string
),
9072 std::move (cond_string
),
9073 std::move (extra_string
),
9075 thread
, task
, ignore_count
, ops
,
9076 from_tty
, enabled
, internal
, flags
,
9077 canonical
->special_display
);
9081 /* Parse LOCATION which is assumed to be a SAL specification possibly
9082 followed by conditionals. On return, SALS contains an array of SAL
9083 addresses found. LOCATION points to the end of the SAL (for
9084 linespec locations).
9086 The array and the line spec strings are allocated on the heap, it is
9087 the caller's responsibility to free them. */
9090 parse_breakpoint_sals (struct event_location
*location
,
9091 struct linespec_result
*canonical
)
9093 struct symtab_and_line cursal
;
9095 if (event_location_type (location
) == LINESPEC_LOCATION
)
9097 const char *spec
= get_linespec_location (location
)->spec_string
;
9101 /* The last displayed codepoint, if it's valid, is our default
9102 breakpoint address. */
9103 if (last_displayed_sal_is_valid ())
9105 /* Set sal's pspace, pc, symtab, and line to the values
9106 corresponding to the last call to print_frame_info.
9107 Be sure to reinitialize LINE with NOTCURRENT == 0
9108 as the breakpoint line number is inappropriate otherwise.
9109 find_pc_line would adjust PC, re-set it back. */
9110 symtab_and_line sal
= get_last_displayed_sal ();
9111 CORE_ADDR pc
= sal
.pc
;
9113 sal
= find_pc_line (pc
, 0);
9115 /* "break" without arguments is equivalent to "break *PC"
9116 where PC is the last displayed codepoint's address. So
9117 make sure to set sal.explicit_pc to prevent GDB from
9118 trying to expand the list of sals to include all other
9119 instances with the same symtab and line. */
9121 sal
.explicit_pc
= 1;
9123 struct linespec_sals lsal
;
9125 lsal
.canonical
= NULL
;
9127 canonical
->lsals
.push_back (std::move (lsal
));
9131 error (_("No default breakpoint address now."));
9135 /* Force almost all breakpoints to be in terms of the
9136 current_source_symtab (which is decode_line_1's default).
9137 This should produce the results we want almost all of the
9138 time while leaving default_breakpoint_* alone.
9140 ObjC: However, don't match an Objective-C method name which
9141 may have a '+' or '-' succeeded by a '['. */
9142 cursal
= get_current_source_symtab_and_line ();
9143 if (last_displayed_sal_is_valid ())
9145 const char *spec
= NULL
;
9147 if (event_location_type (location
) == LINESPEC_LOCATION
)
9148 spec
= get_linespec_location (location
)->spec_string
;
9152 && strchr ("+-", spec
[0]) != NULL
9155 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9156 get_last_displayed_symtab (),
9157 get_last_displayed_line (),
9158 canonical
, NULL
, NULL
);
9163 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9164 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9168 /* Convert each SAL into a real PC. Verify that the PC can be
9169 inserted as a breakpoint. If it can't throw an error. */
9172 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9174 for (auto &sal
: sals
)
9175 resolve_sal_pc (&sal
);
9178 /* Fast tracepoints may have restrictions on valid locations. For
9179 instance, a fast tracepoint using a jump instead of a trap will
9180 likely have to overwrite more bytes than a trap would, and so can
9181 only be placed where the instruction is longer than the jump, or a
9182 multi-instruction sequence does not have a jump into the middle of
9186 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9187 gdb::array_view
<const symtab_and_line
> sals
)
9189 for (const auto &sal
: sals
)
9191 struct gdbarch
*sarch
;
9193 sarch
= get_sal_arch (sal
);
9194 /* We fall back to GDBARCH if there is no architecture
9195 associated with SAL. */
9199 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9200 error (_("May not have a fast tracepoint at %s%s"),
9201 paddress (sarch
, sal
.pc
), msg
.c_str ());
9205 /* Given TOK, a string specification of condition and thread, as
9206 accepted by the 'break' command, extract the condition
9207 string and thread number and set *COND_STRING and *THREAD.
9208 PC identifies the context at which the condition should be parsed.
9209 If no condition is found, *COND_STRING is set to NULL.
9210 If no thread is found, *THREAD is set to -1. */
9213 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9214 char **cond_string
, int *thread
, int *task
,
9217 *cond_string
= NULL
;
9225 const char *end_tok
;
9227 const char *cond_start
= NULL
;
9228 const char *cond_end
= NULL
;
9230 tok
= skip_spaces (tok
);
9232 if ((*tok
== '"' || *tok
== ',') && rest
)
9234 *rest
= savestring (tok
, strlen (tok
));
9238 end_tok
= skip_to_space (tok
);
9240 toklen
= end_tok
- tok
;
9242 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9244 tok
= cond_start
= end_tok
+ 1;
9247 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9249 catch (const gdb_exception_error
&)
9254 tok
= tok
+ strlen (tok
);
9257 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9259 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
9264 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9267 struct thread_info
*thr
;
9270 thr
= parse_thread_id (tok
, &tmptok
);
9272 error (_("Junk after thread keyword."));
9273 *thread
= thr
->global_num
;
9276 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9281 *task
= strtol (tok
, &tmptok
, 0);
9283 error (_("Junk after task keyword."));
9284 if (!valid_task_id (*task
))
9285 error (_("Unknown task %d."), *task
);
9290 *rest
= savestring (tok
, strlen (tok
));
9294 error (_("Junk at end of arguments."));
9298 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
9299 succeeds. The parsed values are written to COND_STRING, THREAD,
9300 TASK, and REST. See the comment of 'find_condition_and_thread'
9301 for the description of these parameters and INPUT. */
9304 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
9305 const char *input
, char **cond_string
,
9306 int *thread
, int *task
, char **rest
)
9308 int num_failures
= 0;
9309 for (auto &sal
: sals
)
9311 char *cond
= nullptr;
9314 char *remaining
= nullptr;
9316 /* Here we want to parse 'arg' to separate condition from thread
9317 number. But because parsing happens in a context and the
9318 contexts of sals might be different, try each until there is
9319 success. Finding one successful parse is sufficient for our
9320 goal. When setting the breakpoint we'll re-parse the
9321 condition in the context of each sal. */
9324 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
9325 &task_id
, &remaining
);
9326 *cond_string
= cond
;
9327 *thread
= thread_id
;
9332 catch (const gdb_exception_error
&e
)
9335 /* If no sal remains, do not continue. */
9336 if (num_failures
== sals
.size ())
9342 /* Decode a static tracepoint marker spec. */
9344 static std::vector
<symtab_and_line
>
9345 decode_static_tracepoint_spec (const char **arg_p
)
9347 const char *p
= &(*arg_p
)[3];
9350 p
= skip_spaces (p
);
9352 endp
= skip_to_space (p
);
9354 std::string
marker_str (p
, endp
- p
);
9356 std::vector
<static_tracepoint_marker
> markers
9357 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9358 if (markers
.empty ())
9359 error (_("No known static tracepoint marker named %s"),
9360 marker_str
.c_str ());
9362 std::vector
<symtab_and_line
> sals
;
9363 sals
.reserve (markers
.size ());
9365 for (const static_tracepoint_marker
&marker
: markers
)
9367 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9368 sal
.pc
= marker
.address
;
9369 sals
.push_back (sal
);
9376 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9377 according to IS_TRACEPOINT. */
9379 static const struct breakpoint_ops
*
9380 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
9385 if (location_type
== PROBE_LOCATION
)
9386 return &tracepoint_probe_breakpoint_ops
;
9388 return &tracepoint_breakpoint_ops
;
9392 if (location_type
== PROBE_LOCATION
)
9393 return &bkpt_probe_breakpoint_ops
;
9395 return &bkpt_breakpoint_ops
;
9399 /* See breakpoint.h. */
9401 const struct breakpoint_ops
*
9402 breakpoint_ops_for_event_location (const struct event_location
*location
,
9405 if (location
!= nullptr)
9406 return breakpoint_ops_for_event_location_type
9407 (event_location_type (location
), is_tracepoint
);
9408 return is_tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
9411 /* See breakpoint.h. */
9414 create_breakpoint (struct gdbarch
*gdbarch
,
9415 struct event_location
*location
,
9416 const char *cond_string
,
9417 int thread
, const char *extra_string
,
9418 bool force_condition
, int parse_extra
,
9419 int tempflag
, enum bptype type_wanted
,
9421 enum auto_boolean pending_break_support
,
9422 const struct breakpoint_ops
*ops
,
9423 int from_tty
, int enabled
, int internal
,
9426 struct linespec_result canonical
;
9429 int prev_bkpt_count
= breakpoint_count
;
9431 gdb_assert (ops
!= NULL
);
9433 /* If extra_string isn't useful, set it to NULL. */
9434 if (extra_string
!= NULL
&& *extra_string
== '\0')
9435 extra_string
= NULL
;
9439 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9441 catch (const gdb_exception_error
&e
)
9443 /* If caller is interested in rc value from parse, set
9445 if (e
.error
== NOT_FOUND_ERROR
)
9447 /* If pending breakpoint support is turned off, throw
9450 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9453 exception_print (gdb_stderr
, e
);
9455 /* If pending breakpoint support is auto query and the user
9456 selects no, then simply return the error code. */
9457 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9458 && !nquery (_("Make %s pending on future shared library load? "),
9459 bptype_string (type_wanted
)))
9462 /* At this point, either the user was queried about setting
9463 a pending breakpoint and selected yes, or pending
9464 breakpoint behavior is on and thus a pending breakpoint
9465 is defaulted on behalf of the user. */
9472 if (!pending
&& canonical
.lsals
.empty ())
9475 /* Resolve all line numbers to PC's and verify that the addresses
9476 are ok for the target. */
9479 for (auto &lsal
: canonical
.lsals
)
9480 breakpoint_sals_to_pc (lsal
.sals
);
9483 /* Fast tracepoints may have additional restrictions on location. */
9484 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9486 for (const auto &lsal
: canonical
.lsals
)
9487 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9490 /* Verify that condition can be parsed, before setting any
9491 breakpoints. Allocate a separate condition expression for each
9495 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9496 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9503 const linespec_sals
&lsal
= canonical
.lsals
[0];
9505 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9506 &cond
, &thread
, &task
, &rest
);
9507 cond_string_copy
.reset (cond
);
9508 extra_string_copy
.reset (rest
);
9512 if (type_wanted
!= bp_dprintf
9513 && extra_string
!= NULL
&& *extra_string
!= '\0')
9514 error (_("Garbage '%s' at end of location"), extra_string
);
9516 /* Check the validity of the condition. We should error out
9517 if the condition is invalid at all of the locations and
9518 if it is not forced. In the PARSE_EXTRA case above, this
9519 check is done when parsing the EXTRA_STRING. */
9520 if (cond_string
!= nullptr && !force_condition
)
9522 int num_failures
= 0;
9523 const linespec_sals
&lsal
= canonical
.lsals
[0];
9524 for (const auto &sal
: lsal
.sals
)
9526 const char *cond
= cond_string
;
9529 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
9530 /* One success is sufficient to keep going. */
9533 catch (const gdb_exception_error
&)
9536 /* If this is the last sal, error out. */
9537 if (num_failures
== lsal
.sals
.size ())
9543 /* Create a private copy of condition string. */
9545 cond_string_copy
.reset (xstrdup (cond_string
));
9546 /* Create a private copy of any extra string. */
9548 extra_string_copy
.reset (xstrdup (extra_string
));
9551 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9552 std::move (cond_string_copy
),
9553 std::move (extra_string_copy
),
9555 tempflag
? disp_del
: disp_donttouch
,
9556 thread
, task
, ignore_count
, ops
,
9557 from_tty
, enabled
, internal
, flags
);
9561 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9563 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9564 b
->location
= copy_event_location (location
);
9567 b
->cond_string
= NULL
;
9570 /* Create a private copy of condition string. */
9571 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9575 /* Create a private copy of any extra string. */
9576 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9577 b
->ignore_count
= ignore_count
;
9578 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9579 b
->condition_not_parsed
= 1;
9580 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9581 if ((type_wanted
!= bp_breakpoint
9582 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9583 b
->pspace
= current_program_space
;
9585 install_breakpoint (internal
, std::move (b
), 0);
9588 if (canonical
.lsals
.size () > 1)
9590 warning (_("Multiple breakpoints were set.\nUse the "
9591 "\"delete\" command to delete unwanted breakpoints."));
9592 prev_breakpoint_count
= prev_bkpt_count
;
9595 update_global_location_list (UGLL_MAY_INSERT
);
9600 /* Set a breakpoint.
9601 ARG is a string describing breakpoint address,
9602 condition, and thread.
9603 FLAG specifies if a breakpoint is hardware on,
9604 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9608 break_command_1 (const char *arg
, int flag
, int from_tty
)
9610 int tempflag
= flag
& BP_TEMPFLAG
;
9611 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9612 ? bp_hardware_breakpoint
9615 event_location_up location
= string_to_event_location (&arg
, current_language
);
9616 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9617 (location
.get (), false /* is_tracepoint */);
9619 create_breakpoint (get_current_arch (),
9621 NULL
, 0, arg
, false, 1 /* parse arg */,
9622 tempflag
, type_wanted
,
9623 0 /* Ignore count */,
9624 pending_break_support
,
9632 /* Helper function for break_command_1 and disassemble_command. */
9635 resolve_sal_pc (struct symtab_and_line
*sal
)
9639 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9641 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9642 error (_("No line %d in file \"%s\"."),
9643 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9646 /* If this SAL corresponds to a breakpoint inserted using a line
9647 number, then skip the function prologue if necessary. */
9648 if (sal
->explicit_line
)
9649 skip_prologue_sal (sal
);
9652 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9654 const struct blockvector
*bv
;
9655 const struct block
*b
;
9658 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9659 SYMTAB_COMPUNIT (sal
->symtab
));
9662 sym
= block_linkage_function (b
);
9665 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9666 sal
->section
= sym
->obj_section (SYMTAB_OBJFILE (sal
->symtab
));
9670 /* It really is worthwhile to have the section, so we'll
9671 just have to look harder. This case can be executed
9672 if we have line numbers but no functions (as can
9673 happen in assembly source). */
9675 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9676 switch_to_program_space_and_thread (sal
->pspace
);
9678 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9680 sal
->section
= msym
.obj_section ();
9687 break_command (const char *arg
, int from_tty
)
9689 break_command_1 (arg
, 0, from_tty
);
9693 tbreak_command (const char *arg
, int from_tty
)
9695 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9699 hbreak_command (const char *arg
, int from_tty
)
9701 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9705 thbreak_command (const char *arg
, int from_tty
)
9707 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9711 stop_command (const char *arg
, int from_tty
)
9713 printf_filtered (_("Specify the type of breakpoint to set.\n\
9714 Usage: stop in <function | address>\n\
9715 stop at <line>\n"));
9719 stopin_command (const char *arg
, int from_tty
)
9725 else if (*arg
!= '*')
9727 const char *argptr
= arg
;
9730 /* Look for a ':'. If this is a line number specification, then
9731 say it is bad, otherwise, it should be an address or
9732 function/method name. */
9733 while (*argptr
&& !hasColon
)
9735 hasColon
= (*argptr
== ':');
9740 badInput
= (*argptr
!= ':'); /* Not a class::method */
9742 badInput
= isdigit (*arg
); /* a simple line number */
9746 printf_filtered (_("Usage: stop in <function | address>\n"));
9748 break_command_1 (arg
, 0, from_tty
);
9752 stopat_command (const char *arg
, int from_tty
)
9756 if (arg
== NULL
|| *arg
== '*') /* no line number */
9760 const char *argptr
= arg
;
9763 /* Look for a ':'. If there is a '::' then get out, otherwise
9764 it is probably a line number. */
9765 while (*argptr
&& !hasColon
)
9767 hasColon
= (*argptr
== ':');
9772 badInput
= (*argptr
== ':'); /* we have class::method */
9774 badInput
= !isdigit (*arg
); /* not a line number */
9778 printf_filtered (_("Usage: stop at LINE\n"));
9780 break_command_1 (arg
, 0, from_tty
);
9783 /* The dynamic printf command is mostly like a regular breakpoint, but
9784 with a prewired command list consisting of a single output command,
9785 built from extra arguments supplied on the dprintf command
9789 dprintf_command (const char *arg
, int from_tty
)
9791 event_location_up location
= string_to_event_location (&arg
, current_language
);
9793 /* If non-NULL, ARG should have been advanced past the location;
9794 the next character must be ','. */
9797 if (arg
[0] != ',' || arg
[1] == '\0')
9798 error (_("Format string required"));
9801 /* Skip the comma. */
9806 create_breakpoint (get_current_arch (),
9808 NULL
, 0, arg
, false, 1 /* parse arg */,
9810 0 /* Ignore count */,
9811 pending_break_support
,
9812 &dprintf_breakpoint_ops
,
9820 agent_printf_command (const char *arg
, int from_tty
)
9822 error (_("May only run agent-printf on the target"));
9825 /* Implement the "breakpoint_hit" breakpoint_ops method for
9826 ranged breakpoints. */
9829 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9830 const address_space
*aspace
,
9832 const struct target_waitstatus
*ws
)
9834 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9835 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9838 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9839 bl
->length
, aspace
, bp_addr
);
9842 /* Implement the "resources_needed" breakpoint_ops method for
9843 ranged breakpoints. */
9846 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9848 return target_ranged_break_num_registers ();
9851 /* Implement the "print_it" breakpoint_ops method for
9852 ranged breakpoints. */
9854 static enum print_stop_action
9855 print_it_ranged_breakpoint (bpstat bs
)
9857 struct breakpoint
*b
= bs
->breakpoint_at
;
9858 struct bp_location
*bl
= b
->loc
;
9859 struct ui_out
*uiout
= current_uiout
;
9861 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9863 /* Ranged breakpoints have only one location. */
9864 gdb_assert (bl
&& bl
->next
== NULL
);
9866 annotate_breakpoint (b
->number
);
9868 maybe_print_thread_hit_breakpoint (uiout
);
9870 if (b
->disposition
== disp_del
)
9871 uiout
->text ("Temporary ranged breakpoint ");
9873 uiout
->text ("Ranged breakpoint ");
9874 if (uiout
->is_mi_like_p ())
9876 uiout
->field_string ("reason",
9877 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9878 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9880 uiout
->field_signed ("bkptno", b
->number
);
9883 return PRINT_SRC_AND_LOC
;
9886 /* Implement the "print_one" breakpoint_ops method for
9887 ranged breakpoints. */
9890 print_one_ranged_breakpoint (struct breakpoint
*b
,
9891 struct bp_location
**last_loc
)
9893 struct bp_location
*bl
= b
->loc
;
9894 struct value_print_options opts
;
9895 struct ui_out
*uiout
= current_uiout
;
9897 /* Ranged breakpoints have only one location. */
9898 gdb_assert (bl
&& bl
->next
== NULL
);
9900 get_user_print_options (&opts
);
9902 if (opts
.addressprint
)
9903 /* We don't print the address range here, it will be printed later
9904 by print_one_detail_ranged_breakpoint. */
9905 uiout
->field_skip ("addr");
9907 print_breakpoint_location (b
, bl
);
9911 /* Implement the "print_one_detail" breakpoint_ops method for
9912 ranged breakpoints. */
9915 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9916 struct ui_out
*uiout
)
9918 CORE_ADDR address_start
, address_end
;
9919 struct bp_location
*bl
= b
->loc
;
9924 address_start
= bl
->address
;
9925 address_end
= address_start
+ bl
->length
- 1;
9927 uiout
->text ("\taddress range: ");
9928 stb
.printf ("[%s, %s]",
9929 print_core_address (bl
->gdbarch
, address_start
),
9930 print_core_address (bl
->gdbarch
, address_end
));
9931 uiout
->field_stream ("addr", stb
);
9935 /* Implement the "print_mention" breakpoint_ops method for
9936 ranged breakpoints. */
9939 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9941 struct bp_location
*bl
= b
->loc
;
9942 struct ui_out
*uiout
= current_uiout
;
9945 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9947 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9948 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9949 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9952 /* Implement the "print_recreate" breakpoint_ops method for
9953 ranged breakpoints. */
9956 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9958 fprintf_unfiltered (fp
, "break-range %s, %s",
9959 event_location_to_string (b
->location
.get ()),
9960 event_location_to_string (b
->location_range_end
.get ()));
9961 print_recreate_thread (b
, fp
);
9964 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9966 static struct breakpoint_ops ranged_breakpoint_ops
;
9968 /* Find the address where the end of the breakpoint range should be
9969 placed, given the SAL of the end of the range. This is so that if
9970 the user provides a line number, the end of the range is set to the
9971 last instruction of the given line. */
9974 find_breakpoint_range_end (struct symtab_and_line sal
)
9978 /* If the user provided a PC value, use it. Otherwise,
9979 find the address of the end of the given location. */
9980 if (sal
.explicit_pc
)
9987 ret
= find_line_pc_range (sal
, &start
, &end
);
9989 error (_("Could not find location of the end of the range."));
9991 /* find_line_pc_range returns the start of the next line. */
9998 /* Implement the "break-range" CLI command. */
10001 break_range_command (const char *arg
, int from_tty
)
10003 const char *arg_start
;
10004 struct linespec_result canonical_start
, canonical_end
;
10005 int bp_count
, can_use_bp
, length
;
10007 struct breakpoint
*b
;
10009 /* We don't support software ranged breakpoints. */
10010 if (target_ranged_break_num_registers () < 0)
10011 error (_("This target does not support hardware ranged breakpoints."));
10013 bp_count
= hw_breakpoint_used_count ();
10014 bp_count
+= target_ranged_break_num_registers ();
10015 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10017 if (can_use_bp
< 0)
10018 error (_("Hardware breakpoints used exceeds limit."));
10020 arg
= skip_spaces (arg
);
10021 if (arg
== NULL
|| arg
[0] == '\0')
10022 error(_("No address range specified."));
10025 event_location_up start_location
= string_to_event_location (&arg
,
10027 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10030 error (_("Too few arguments."));
10031 else if (canonical_start
.lsals
.empty ())
10032 error (_("Could not find location of the beginning of the range."));
10034 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
10036 if (canonical_start
.lsals
.size () > 1
10037 || lsal_start
.sals
.size () != 1)
10038 error (_("Cannot create a ranged breakpoint with multiple locations."));
10040 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
10041 std::string
addr_string_start (arg_start
, arg
- arg_start
);
10043 arg
++; /* Skip the comma. */
10044 arg
= skip_spaces (arg
);
10046 /* Parse the end location. */
10050 /* We call decode_line_full directly here instead of using
10051 parse_breakpoint_sals because we need to specify the start location's
10052 symtab and line as the default symtab and line for the end of the
10053 range. This makes it possible to have ranges like "foo.c:27, +14",
10054 where +14 means 14 lines from the start location. */
10055 event_location_up end_location
= string_to_event_location (&arg
,
10057 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10058 sal_start
.symtab
, sal_start
.line
,
10059 &canonical_end
, NULL
, NULL
);
10061 if (canonical_end
.lsals
.empty ())
10062 error (_("Could not find location of the end of the range."));
10064 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10065 if (canonical_end
.lsals
.size () > 1
10066 || lsal_end
.sals
.size () != 1)
10067 error (_("Cannot create a ranged breakpoint with multiple locations."));
10069 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10071 end
= find_breakpoint_range_end (sal_end
);
10072 if (sal_start
.pc
> end
)
10073 error (_("Invalid address range, end precedes start."));
10075 length
= end
- sal_start
.pc
+ 1;
10077 /* Length overflowed. */
10078 error (_("Address range too large."));
10079 else if (length
== 1)
10081 /* This range is simple enough to be handled by
10082 the `hbreak' command. */
10083 hbreak_command (&addr_string_start
[0], 1);
10088 /* Now set up the breakpoint. */
10089 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10090 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10091 set_breakpoint_count (breakpoint_count
+ 1);
10092 b
->number
= breakpoint_count
;
10093 b
->disposition
= disp_donttouch
;
10094 b
->location
= std::move (start_location
);
10095 b
->location_range_end
= std::move (end_location
);
10096 b
->loc
->length
= length
;
10099 gdb::observers::breakpoint_created
.notify (b
);
10100 update_global_location_list (UGLL_MAY_INSERT
);
10103 /* Return non-zero if EXP is verified as constant. Returned zero
10104 means EXP is variable. Also the constant detection may fail for
10105 some constant expressions and in such case still falsely return
10109 watchpoint_exp_is_const (const struct expression
*exp
)
10111 return exp
->op
->constant_p ();
10114 /* Watchpoint destructor. */
10116 watchpoint::~watchpoint ()
10118 xfree (this->exp_string
);
10119 xfree (this->exp_string_reparse
);
10122 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10125 re_set_watchpoint (struct breakpoint
*b
)
10127 struct watchpoint
*w
= (struct watchpoint
*) b
;
10129 /* Watchpoint can be either on expression using entirely global
10130 variables, or it can be on local variables.
10132 Watchpoints of the first kind are never auto-deleted, and even
10133 persist across program restarts. Since they can use variables
10134 from shared libraries, we need to reparse expression as libraries
10135 are loaded and unloaded.
10137 Watchpoints on local variables can also change meaning as result
10138 of solib event. For example, if a watchpoint uses both a local
10139 and a global variables in expression, it's a local watchpoint,
10140 but unloading of a shared library will make the expression
10141 invalid. This is not a very common use case, but we still
10142 re-evaluate expression, to avoid surprises to the user.
10144 Note that for local watchpoints, we re-evaluate it only if
10145 watchpoints frame id is still valid. If it's not, it means the
10146 watchpoint is out of scope and will be deleted soon. In fact,
10147 I'm not sure we'll ever be called in this case.
10149 If a local watchpoint's frame id is still valid, then
10150 w->exp_valid_block is likewise valid, and we can safely use it.
10152 Don't do anything about disabled watchpoints, since they will be
10153 reevaluated again when enabled. */
10154 update_watchpoint (w
, 1 /* reparse */);
10157 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10160 insert_watchpoint (struct bp_location
*bl
)
10162 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10163 int length
= w
->exact
? 1 : bl
->length
;
10165 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10166 w
->cond_exp
.get ());
10169 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10172 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10174 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10175 int length
= w
->exact
? 1 : bl
->length
;
10177 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10178 w
->cond_exp
.get ());
10182 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10183 const address_space
*aspace
, CORE_ADDR bp_addr
,
10184 const struct target_waitstatus
*ws
)
10186 struct breakpoint
*b
= bl
->owner
;
10187 struct watchpoint
*w
= (struct watchpoint
*) b
;
10189 /* Continuable hardware watchpoints are treated as non-existent if the
10190 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10191 some data address). Otherwise gdb won't stop on a break instruction
10192 in the code (not from a breakpoint) when a hardware watchpoint has
10193 been defined. Also skip watchpoints which we know did not trigger
10194 (did not match the data address). */
10195 if (is_hardware_watchpoint (b
)
10196 && w
->watchpoint_triggered
== watch_triggered_no
)
10203 check_status_watchpoint (bpstat bs
)
10205 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10207 bpstat_check_watchpoint (bs
);
10210 /* Implement the "resources_needed" breakpoint_ops method for
10211 hardware watchpoints. */
10214 resources_needed_watchpoint (const struct bp_location
*bl
)
10216 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10217 int length
= w
->exact
? 1 : bl
->length
;
10219 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10222 /* Implement the "works_in_software_mode" breakpoint_ops method for
10223 hardware watchpoints. */
10226 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10228 /* Read and access watchpoints only work with hardware support. */
10229 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10232 static enum print_stop_action
10233 print_it_watchpoint (bpstat bs
)
10235 struct breakpoint
*b
;
10236 enum print_stop_action result
;
10237 struct watchpoint
*w
;
10238 struct ui_out
*uiout
= current_uiout
;
10240 gdb_assert (bs
->bp_location_at
!= NULL
);
10242 b
= bs
->breakpoint_at
;
10243 w
= (struct watchpoint
*) b
;
10245 annotate_watchpoint (b
->number
);
10246 maybe_print_thread_hit_breakpoint (uiout
);
10250 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10253 case bp_watchpoint
:
10254 case bp_hardware_watchpoint
:
10255 if (uiout
->is_mi_like_p ())
10256 uiout
->field_string
10257 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10259 tuple_emitter
.emplace (uiout
, "value");
10260 uiout
->text ("\nOld value = ");
10261 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10262 uiout
->field_stream ("old", stb
);
10263 uiout
->text ("\nNew value = ");
10264 watchpoint_value_print (w
->val
.get (), &stb
);
10265 uiout
->field_stream ("new", stb
);
10266 uiout
->text ("\n");
10267 /* More than one watchpoint may have been triggered. */
10268 result
= PRINT_UNKNOWN
;
10271 case bp_read_watchpoint
:
10272 if (uiout
->is_mi_like_p ())
10273 uiout
->field_string
10274 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10276 tuple_emitter
.emplace (uiout
, "value");
10277 uiout
->text ("\nValue = ");
10278 watchpoint_value_print (w
->val
.get (), &stb
);
10279 uiout
->field_stream ("value", stb
);
10280 uiout
->text ("\n");
10281 result
= PRINT_UNKNOWN
;
10284 case bp_access_watchpoint
:
10285 if (bs
->old_val
!= NULL
)
10287 if (uiout
->is_mi_like_p ())
10288 uiout
->field_string
10290 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10292 tuple_emitter
.emplace (uiout
, "value");
10293 uiout
->text ("\nOld value = ");
10294 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10295 uiout
->field_stream ("old", stb
);
10296 uiout
->text ("\nNew value = ");
10301 if (uiout
->is_mi_like_p ())
10302 uiout
->field_string
10304 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10305 tuple_emitter
.emplace (uiout
, "value");
10306 uiout
->text ("\nValue = ");
10308 watchpoint_value_print (w
->val
.get (), &stb
);
10309 uiout
->field_stream ("new", stb
);
10310 uiout
->text ("\n");
10311 result
= PRINT_UNKNOWN
;
10314 result
= PRINT_UNKNOWN
;
10320 /* Implement the "print_mention" breakpoint_ops method for hardware
10324 print_mention_watchpoint (struct breakpoint
*b
)
10326 struct watchpoint
*w
= (struct watchpoint
*) b
;
10327 struct ui_out
*uiout
= current_uiout
;
10328 const char *tuple_name
;
10332 case bp_watchpoint
:
10333 uiout
->text ("Watchpoint ");
10334 tuple_name
= "wpt";
10336 case bp_hardware_watchpoint
:
10337 uiout
->text ("Hardware watchpoint ");
10338 tuple_name
= "wpt";
10340 case bp_read_watchpoint
:
10341 uiout
->text ("Hardware read watchpoint ");
10342 tuple_name
= "hw-rwpt";
10344 case bp_access_watchpoint
:
10345 uiout
->text ("Hardware access (read/write) watchpoint ");
10346 tuple_name
= "hw-awpt";
10349 internal_error (__FILE__
, __LINE__
,
10350 _("Invalid hardware watchpoint type."));
10353 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10354 uiout
->field_signed ("number", b
->number
);
10355 uiout
->text (": ");
10356 uiout
->field_string ("exp", w
->exp_string
);
10359 /* Implement the "print_recreate" breakpoint_ops method for
10363 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10365 struct watchpoint
*w
= (struct watchpoint
*) b
;
10369 case bp_watchpoint
:
10370 case bp_hardware_watchpoint
:
10371 fprintf_unfiltered (fp
, "watch");
10373 case bp_read_watchpoint
:
10374 fprintf_unfiltered (fp
, "rwatch");
10376 case bp_access_watchpoint
:
10377 fprintf_unfiltered (fp
, "awatch");
10380 internal_error (__FILE__
, __LINE__
,
10381 _("Invalid watchpoint type."));
10384 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10385 print_recreate_thread (b
, fp
);
10388 /* Implement the "explains_signal" breakpoint_ops method for
10392 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10394 /* A software watchpoint cannot cause a signal other than
10395 GDB_SIGNAL_TRAP. */
10396 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10402 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10404 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10406 /* Implement the "insert" breakpoint_ops method for
10407 masked hardware watchpoints. */
10410 insert_masked_watchpoint (struct bp_location
*bl
)
10412 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10414 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10415 bl
->watchpoint_type
);
10418 /* Implement the "remove" breakpoint_ops method for
10419 masked hardware watchpoints. */
10422 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10424 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10426 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10427 bl
->watchpoint_type
);
10430 /* Implement the "resources_needed" breakpoint_ops method for
10431 masked hardware watchpoints. */
10434 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10436 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10438 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10441 /* Implement the "works_in_software_mode" breakpoint_ops method for
10442 masked hardware watchpoints. */
10445 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10450 /* Implement the "print_it" breakpoint_ops method for
10451 masked hardware watchpoints. */
10453 static enum print_stop_action
10454 print_it_masked_watchpoint (bpstat bs
)
10456 struct breakpoint
*b
= bs
->breakpoint_at
;
10457 struct ui_out
*uiout
= current_uiout
;
10459 /* Masked watchpoints have only one location. */
10460 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10462 annotate_watchpoint (b
->number
);
10463 maybe_print_thread_hit_breakpoint (uiout
);
10467 case bp_hardware_watchpoint
:
10468 if (uiout
->is_mi_like_p ())
10469 uiout
->field_string
10470 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10473 case bp_read_watchpoint
:
10474 if (uiout
->is_mi_like_p ())
10475 uiout
->field_string
10476 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10479 case bp_access_watchpoint
:
10480 if (uiout
->is_mi_like_p ())
10481 uiout
->field_string
10483 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10486 internal_error (__FILE__
, __LINE__
,
10487 _("Invalid hardware watchpoint type."));
10491 uiout
->text (_("\n\
10492 Check the underlying instruction at PC for the memory\n\
10493 address and value which triggered this watchpoint.\n"));
10494 uiout
->text ("\n");
10496 /* More than one watchpoint may have been triggered. */
10497 return PRINT_UNKNOWN
;
10500 /* Implement the "print_one_detail" breakpoint_ops method for
10501 masked hardware watchpoints. */
10504 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10505 struct ui_out
*uiout
)
10507 struct watchpoint
*w
= (struct watchpoint
*) b
;
10509 /* Masked watchpoints have only one location. */
10510 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10512 uiout
->text ("\tmask ");
10513 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10514 uiout
->text ("\n");
10517 /* Implement the "print_mention" breakpoint_ops method for
10518 masked hardware watchpoints. */
10521 print_mention_masked_watchpoint (struct breakpoint
*b
)
10523 struct watchpoint
*w
= (struct watchpoint
*) b
;
10524 struct ui_out
*uiout
= current_uiout
;
10525 const char *tuple_name
;
10529 case bp_hardware_watchpoint
:
10530 uiout
->text ("Masked hardware watchpoint ");
10531 tuple_name
= "wpt";
10533 case bp_read_watchpoint
:
10534 uiout
->text ("Masked hardware read watchpoint ");
10535 tuple_name
= "hw-rwpt";
10537 case bp_access_watchpoint
:
10538 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10539 tuple_name
= "hw-awpt";
10542 internal_error (__FILE__
, __LINE__
,
10543 _("Invalid hardware watchpoint type."));
10546 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10547 uiout
->field_signed ("number", b
->number
);
10548 uiout
->text (": ");
10549 uiout
->field_string ("exp", w
->exp_string
);
10552 /* Implement the "print_recreate" breakpoint_ops method for
10553 masked hardware watchpoints. */
10556 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10558 struct watchpoint
*w
= (struct watchpoint
*) b
;
10562 case bp_hardware_watchpoint
:
10563 fprintf_unfiltered (fp
, "watch");
10565 case bp_read_watchpoint
:
10566 fprintf_unfiltered (fp
, "rwatch");
10568 case bp_access_watchpoint
:
10569 fprintf_unfiltered (fp
, "awatch");
10572 internal_error (__FILE__
, __LINE__
,
10573 _("Invalid hardware watchpoint type."));
10576 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
,
10577 phex (w
->hw_wp_mask
, sizeof (CORE_ADDR
)));
10578 print_recreate_thread (b
, fp
);
10581 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10583 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10585 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10588 is_masked_watchpoint (const struct breakpoint
*b
)
10590 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10593 /* accessflag: hw_write: watch write,
10594 hw_read: watch read,
10595 hw_access: watch access (read or write) */
10597 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10598 bool just_location
, bool internal
)
10600 struct breakpoint
*scope_breakpoint
= NULL
;
10601 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10602 struct value
*result
;
10603 int saved_bitpos
= 0, saved_bitsize
= 0;
10604 const char *exp_start
= NULL
;
10605 const char *exp_end
= NULL
;
10606 const char *tok
, *end_tok
;
10608 const char *cond_start
= NULL
;
10609 const char *cond_end
= NULL
;
10610 enum bptype bp_type
;
10612 /* Flag to indicate whether we are going to use masks for
10613 the hardware watchpoint. */
10614 bool use_mask
= false;
10615 CORE_ADDR mask
= 0;
10617 /* Make sure that we actually have parameters to parse. */
10618 if (arg
!= NULL
&& arg
[0] != '\0')
10620 const char *value_start
;
10622 exp_end
= arg
+ strlen (arg
);
10624 /* Look for "parameter value" pairs at the end
10625 of the arguments string. */
10626 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10628 /* Skip whitespace at the end of the argument list. */
10629 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10632 /* Find the beginning of the last token.
10633 This is the value of the parameter. */
10634 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10636 value_start
= tok
+ 1;
10638 /* Skip whitespace. */
10639 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10644 /* Find the beginning of the second to last token.
10645 This is the parameter itself. */
10646 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10649 toklen
= end_tok
- tok
+ 1;
10651 if (toklen
== 6 && startswith (tok
, "thread"))
10653 struct thread_info
*thr
;
10654 /* At this point we've found a "thread" token, which means
10655 the user is trying to set a watchpoint that triggers
10656 only in a specific thread. */
10660 error(_("You can specify only one thread."));
10662 /* Extract the thread ID from the next token. */
10663 thr
= parse_thread_id (value_start
, &endp
);
10665 /* Check if the user provided a valid thread ID. */
10666 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10667 invalid_thread_id_error (value_start
);
10669 thread
= thr
->global_num
;
10671 else if (toklen
== 4 && startswith (tok
, "mask"))
10673 /* We've found a "mask" token, which means the user wants to
10674 create a hardware watchpoint that is going to have the mask
10676 struct value
*mask_value
, *mark
;
10679 error(_("You can specify only one mask."));
10681 use_mask
= just_location
= true;
10683 mark
= value_mark ();
10684 mask_value
= parse_to_comma_and_eval (&value_start
);
10685 mask
= value_as_address (mask_value
);
10686 value_free_to_mark (mark
);
10689 /* We didn't recognize what we found. We should stop here. */
10692 /* Truncate the string and get rid of the "parameter value" pair before
10693 the arguments string is parsed by the parse_exp_1 function. */
10700 /* Parse the rest of the arguments. From here on out, everything
10701 is in terms of a newly allocated string instead of the original
10703 std::string
expression (arg
, exp_end
- arg
);
10704 exp_start
= arg
= expression
.c_str ();
10705 innermost_block_tracker tracker
;
10706 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10708 /* Remove trailing whitespace from the expression before saving it.
10709 This makes the eventual display of the expression string a bit
10711 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10714 /* Checking if the expression is not constant. */
10715 if (watchpoint_exp_is_const (exp
.get ()))
10719 len
= exp_end
- exp_start
;
10720 while (len
> 0 && isspace (exp_start
[len
- 1]))
10722 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10725 exp_valid_block
= tracker
.block ();
10726 struct value
*mark
= value_mark ();
10727 struct value
*val_as_value
= nullptr;
10728 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10731 if (val_as_value
!= NULL
&& just_location
)
10733 saved_bitpos
= value_bitpos (val_as_value
);
10734 saved_bitsize
= value_bitsize (val_as_value
);
10742 exp_valid_block
= NULL
;
10743 val
= release_value (value_addr (result
));
10744 value_free_to_mark (mark
);
10748 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10751 error (_("This target does not support masked watchpoints."));
10752 else if (ret
== -2)
10753 error (_("Invalid mask or memory region."));
10756 else if (val_as_value
!= NULL
)
10757 val
= release_value (val_as_value
);
10759 tok
= skip_spaces (arg
);
10760 end_tok
= skip_to_space (tok
);
10762 toklen
= end_tok
- tok
;
10763 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10765 tok
= cond_start
= end_tok
+ 1;
10766 innermost_block_tracker if_tracker
;
10767 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10769 /* The watchpoint expression may not be local, but the condition
10770 may still be. E.g.: `watch global if local > 0'. */
10771 cond_exp_valid_block
= if_tracker
.block ();
10776 error (_("Junk at end of command."));
10778 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10780 /* Save this because create_internal_breakpoint below invalidates
10782 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10784 /* If the expression is "local", then set up a "watchpoint scope"
10785 breakpoint at the point where we've left the scope of the watchpoint
10786 expression. Create the scope breakpoint before the watchpoint, so
10787 that we will encounter it first in bpstat_stop_status. */
10788 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10790 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10792 if (frame_id_p (caller_frame_id
))
10794 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10795 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10798 = create_internal_breakpoint (caller_arch
, caller_pc
,
10799 bp_watchpoint_scope
,
10800 &momentary_breakpoint_ops
);
10802 /* create_internal_breakpoint could invalidate WP_FRAME. */
10805 scope_breakpoint
->enable_state
= bp_enabled
;
10807 /* Automatically delete the breakpoint when it hits. */
10808 scope_breakpoint
->disposition
= disp_del
;
10810 /* Only break in the proper frame (help with recursion). */
10811 scope_breakpoint
->frame_id
= caller_frame_id
;
10813 /* Set the address at which we will stop. */
10814 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10815 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10816 scope_breakpoint
->loc
->address
10817 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10818 scope_breakpoint
->loc
->requested_address
,
10819 scope_breakpoint
->type
);
10823 /* Now set up the breakpoint. We create all watchpoints as hardware
10824 watchpoints here even if hardware watchpoints are turned off, a call
10825 to update_watchpoint later in this function will cause the type to
10826 drop back to bp_watchpoint (software watchpoint) if required. */
10828 if (accessflag
== hw_read
)
10829 bp_type
= bp_read_watchpoint
;
10830 else if (accessflag
== hw_access
)
10831 bp_type
= bp_access_watchpoint
;
10833 bp_type
= bp_hardware_watchpoint
;
10835 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10838 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10839 &masked_watchpoint_breakpoint_ops
);
10841 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10842 &watchpoint_breakpoint_ops
);
10843 w
->thread
= thread
;
10844 w
->disposition
= disp_donttouch
;
10845 w
->pspace
= current_program_space
;
10846 w
->exp
= std::move (exp
);
10847 w
->exp_valid_block
= exp_valid_block
;
10848 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10851 struct type
*t
= value_type (val
.get ());
10852 CORE_ADDR addr
= value_as_address (val
.get ());
10854 w
->exp_string_reparse
10855 = current_language
->watch_location_expression (t
, addr
).release ();
10857 w
->exp_string
= xstrprintf ("-location %.*s",
10858 (int) (exp_end
- exp_start
), exp_start
);
10861 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10865 w
->hw_wp_mask
= mask
;
10870 w
->val_bitpos
= saved_bitpos
;
10871 w
->val_bitsize
= saved_bitsize
;
10872 w
->val_valid
= true;
10876 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10878 w
->cond_string
= 0;
10880 if (frame_id_p (watchpoint_frame
))
10882 w
->watchpoint_frame
= watchpoint_frame
;
10883 w
->watchpoint_thread
= inferior_ptid
;
10887 w
->watchpoint_frame
= null_frame_id
;
10888 w
->watchpoint_thread
= null_ptid
;
10891 if (scope_breakpoint
!= NULL
)
10893 /* The scope breakpoint is related to the watchpoint. We will
10894 need to act on them together. */
10895 w
->related_breakpoint
= scope_breakpoint
;
10896 scope_breakpoint
->related_breakpoint
= w
.get ();
10899 if (!just_location
)
10900 value_free_to_mark (mark
);
10902 /* Finally update the new watchpoint. This creates the locations
10903 that should be inserted. */
10904 update_watchpoint (w
.get (), 1);
10906 install_breakpoint (internal
, std::move (w
), 1);
10909 /* Return count of debug registers needed to watch the given expression.
10910 If the watchpoint cannot be handled in hardware return zero. */
10913 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10915 int found_memory_cnt
= 0;
10917 /* Did the user specifically forbid us to use hardware watchpoints? */
10918 if (!can_use_hw_watchpoints
)
10921 gdb_assert (!vals
.empty ());
10922 struct value
*head
= vals
[0].get ();
10924 /* Make sure that the value of the expression depends only upon
10925 memory contents, and values computed from them within GDB. If we
10926 find any register references or function calls, we can't use a
10927 hardware watchpoint.
10929 The idea here is that evaluating an expression generates a series
10930 of values, one holding the value of every subexpression. (The
10931 expression a*b+c has five subexpressions: a, b, a*b, c, and
10932 a*b+c.) GDB's values hold almost enough information to establish
10933 the criteria given above --- they identify memory lvalues,
10934 register lvalues, computed values, etcetera. So we can evaluate
10935 the expression, and then scan the chain of values that leaves
10936 behind to decide whether we can detect any possible change to the
10937 expression's final value using only hardware watchpoints.
10939 However, I don't think that the values returned by inferior
10940 function calls are special in any way. So this function may not
10941 notice that an expression involving an inferior function call
10942 can't be watched with hardware watchpoints. FIXME. */
10943 for (const value_ref_ptr
&iter
: vals
)
10945 struct value
*v
= iter
.get ();
10947 if (VALUE_LVAL (v
) == lval_memory
)
10949 if (v
!= head
&& value_lazy (v
))
10950 /* A lazy memory lvalue in the chain is one that GDB never
10951 needed to fetch; we either just used its address (e.g.,
10952 `a' in `a.b') or we never needed it at all (e.g., `a'
10953 in `a,b'). This doesn't apply to HEAD; if that is
10954 lazy then it was not readable, but watch it anyway. */
10958 /* Ahh, memory we actually used! Check if we can cover
10959 it with hardware watchpoints. */
10960 struct type
*vtype
= check_typedef (value_type (v
));
10962 /* We only watch structs and arrays if user asked for it
10963 explicitly, never if they just happen to appear in a
10964 middle of some value chain. */
10966 || (vtype
->code () != TYPE_CODE_STRUCT
10967 && vtype
->code () != TYPE_CODE_ARRAY
))
10969 CORE_ADDR vaddr
= value_address (v
);
10973 len
= (target_exact_watchpoints
10974 && is_scalar_type_recursive (vtype
))?
10975 1 : TYPE_LENGTH (value_type (v
));
10977 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10981 found_memory_cnt
+= num_regs
;
10985 else if (VALUE_LVAL (v
) != not_lval
10986 && deprecated_value_modifiable (v
) == 0)
10987 return 0; /* These are values from the history (e.g., $1). */
10988 else if (VALUE_LVAL (v
) == lval_register
)
10989 return 0; /* Cannot watch a register with a HW watchpoint. */
10992 /* The expression itself looks suitable for using a hardware
10993 watchpoint, but give the target machine a chance to reject it. */
10994 return found_memory_cnt
;
10998 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11000 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11003 /* Options for the watch, awatch, and rwatch commands. */
11005 struct watch_options
11007 /* For -location. */
11008 bool location
= false;
11011 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
11013 Historically GDB always accepted both '-location' and '-l' flags for
11014 these commands (both flags being synonyms). When converting to the
11015 newer option scheme only '-location' is added here. That's fine (for
11016 backward compatibility) as any non-ambiguous prefix of a flag will be
11017 accepted, so '-l', '-loc', are now all accepted.
11019 What this means is that, if in the future, we add any new flag here
11020 that starts with '-l' then this will break backward compatibility, so
11021 please, don't do that! */
11023 static const gdb::option::option_def watch_option_defs
[] = {
11024 gdb::option::flag_option_def
<watch_options
> {
11026 [] (watch_options
*opt
) { return &opt
->location
; },
11028 This evaluates EXPRESSION and watches the memory to which is refers.\n\
11029 -l can be used as a short form of -location."),
11033 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
11036 static gdb::option::option_def_group
11037 make_watch_options_def_group (watch_options
*opts
)
11039 return {{watch_option_defs
}, opts
};
11042 /* A helper function that looks for the "-location" argument and then
11043 calls watch_command_1. */
11046 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
11048 watch_options opts
;
11049 auto grp
= make_watch_options_def_group (&opts
);
11050 gdb::option::process_options
11051 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
11052 if (arg
!= nullptr && *arg
== '\0')
11055 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
11058 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
11060 watch_command_completer (struct cmd_list_element
*ignore
,
11061 completion_tracker
&tracker
,
11062 const char *text
, const char * /*word*/)
11064 const auto group
= make_watch_options_def_group (nullptr);
11065 if (gdb::option::complete_options
11066 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
11069 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
11070 expression_completer (ignore
, tracker
, text
, word
);
11074 watch_command (const char *arg
, int from_tty
)
11076 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11080 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11082 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11086 rwatch_command (const char *arg
, int from_tty
)
11088 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11092 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11094 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11098 awatch_command (const char *arg
, int from_tty
)
11100 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11104 /* Data for the FSM that manages the until(location)/advance commands
11105 in infcmd.c. Here because it uses the mechanisms of
11108 struct until_break_fsm
: public thread_fsm
11110 /* The thread that was current when the command was executed. */
11113 /* The breakpoint set at the return address in the caller frame,
11114 plus breakpoints at all the destination locations. */
11115 std::vector
<breakpoint_up
> breakpoints
;
11117 until_break_fsm (struct interp
*cmd_interp
, int thread
,
11118 std::vector
<breakpoint_up
> &&breakpoints
)
11119 : thread_fsm (cmd_interp
),
11121 breakpoints (std::move (breakpoints
))
11125 void clean_up (struct thread_info
*thread
) override
;
11126 bool should_stop (struct thread_info
*thread
) override
;
11127 enum async_reply_reason
do_async_reply_reason () override
;
11130 /* Implementation of the 'should_stop' FSM method for the
11131 until(location)/advance commands. */
11134 until_break_fsm::should_stop (struct thread_info
*tp
)
11136 for (const breakpoint_up
&bp
: breakpoints
)
11137 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11138 bp
.get ()) != NULL
)
11147 /* Implementation of the 'clean_up' FSM method for the
11148 until(location)/advance commands. */
11151 until_break_fsm::clean_up (struct thread_info
*)
11153 /* Clean up our temporary breakpoints. */
11154 breakpoints
.clear ();
11155 delete_longjmp_breakpoint (thread
);
11158 /* Implementation of the 'async_reply_reason' FSM method for the
11159 until(location)/advance commands. */
11161 enum async_reply_reason
11162 until_break_fsm::do_async_reply_reason ()
11164 return EXEC_ASYNC_LOCATION_REACHED
;
11168 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11170 struct frame_info
*frame
;
11171 struct gdbarch
*frame_gdbarch
;
11172 struct frame_id stack_frame_id
;
11173 struct frame_id caller_frame_id
;
11175 struct thread_info
*tp
;
11177 clear_proceed_status (0);
11179 /* Set a breakpoint where the user wants it and at return from
11182 event_location_up location
= string_to_event_location (&arg
, current_language
);
11184 std::vector
<symtab_and_line
> sals
11185 = (last_displayed_sal_is_valid ()
11186 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11187 get_last_displayed_symtab (),
11188 get_last_displayed_line ())
11189 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11193 error (_("Couldn't get information on specified line."));
11196 error (_("Junk at end of arguments."));
11198 tp
= inferior_thread ();
11199 thread
= tp
->global_num
;
11201 /* Note linespec handling above invalidates the frame chain.
11202 Installing a breakpoint also invalidates the frame chain (as it
11203 may need to switch threads), so do any frame handling before
11206 frame
= get_selected_frame (NULL
);
11207 frame_gdbarch
= get_frame_arch (frame
);
11208 stack_frame_id
= get_stack_frame_id (frame
);
11209 caller_frame_id
= frame_unwind_caller_id (frame
);
11211 /* Keep within the current frame, or in frames called by the current
11214 std::vector
<breakpoint_up
> breakpoints
;
11216 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11218 if (frame_id_p (caller_frame_id
))
11220 struct symtab_and_line sal2
;
11221 struct gdbarch
*caller_gdbarch
;
11223 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11224 sal2
.pc
= frame_unwind_caller_pc (frame
);
11225 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11227 breakpoint_up caller_breakpoint
11228 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
11229 caller_frame_id
, bp_until
);
11230 breakpoints
.emplace_back (std::move (caller_breakpoint
));
11232 set_longjmp_breakpoint (tp
, caller_frame_id
);
11233 lj_deleter
.emplace (thread
);
11236 /* set_momentary_breakpoint could invalidate FRAME. */
11239 /* If the user told us to continue until a specified location, we
11240 don't specify a frame at which we need to stop. Otherwise,
11241 specify the selected frame, because we want to stop only at the
11242 very same frame. */
11243 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
11245 for (symtab_and_line
&sal
: sals
)
11247 resolve_sal_pc (&sal
);
11249 breakpoint_up location_breakpoint
11250 = set_momentary_breakpoint (frame_gdbarch
, sal
,
11251 stop_frame_id
, bp_until
);
11252 breakpoints
.emplace_back (std::move (location_breakpoint
));
11255 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11256 std::move (breakpoints
));
11259 lj_deleter
->release ();
11261 proceed (-1, GDB_SIGNAL_DEFAULT
);
11264 /* This function attempts to parse an optional "if <cond>" clause
11265 from the arg string. If one is not found, it returns NULL.
11267 Else, it returns a pointer to the condition string. (It does not
11268 attempt to evaluate the string against a particular block.) And,
11269 it updates arg to point to the first character following the parsed
11270 if clause in the arg string. */
11273 ep_parse_optional_if_clause (const char **arg
)
11275 const char *cond_string
;
11277 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11280 /* Skip the "if" keyword. */
11283 /* Skip any extra leading whitespace, and record the start of the
11284 condition string. */
11285 *arg
= skip_spaces (*arg
);
11286 cond_string
= *arg
;
11288 /* Assume that the condition occupies the remainder of the arg
11290 (*arg
) += strlen (cond_string
);
11292 return cond_string
;
11295 /* Commands to deal with catching events, such as signals, exceptions,
11296 process start/exit, etc. */
11300 catch_fork_temporary
, catch_vfork_temporary
,
11301 catch_fork_permanent
, catch_vfork_permanent
11306 catch_fork_command_1 (const char *arg
, int from_tty
,
11307 struct cmd_list_element
*command
)
11309 struct gdbarch
*gdbarch
= get_current_arch ();
11310 const char *cond_string
= NULL
;
11311 catch_fork_kind fork_kind
;
11313 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11314 bool temp
= (fork_kind
== catch_fork_temporary
11315 || fork_kind
== catch_vfork_temporary
);
11319 arg
= skip_spaces (arg
);
11321 /* The allowed syntax is:
11323 catch [v]fork if <cond>
11325 First, check if there's an if clause. */
11326 cond_string
= ep_parse_optional_if_clause (&arg
);
11328 if ((*arg
!= '\0') && !isspace (*arg
))
11329 error (_("Junk at end of arguments."));
11331 /* If this target supports it, create a fork or vfork catchpoint
11332 and enable reporting of such events. */
11335 case catch_fork_temporary
:
11336 case catch_fork_permanent
:
11337 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11338 &catch_fork_breakpoint_ops
);
11340 case catch_vfork_temporary
:
11341 case catch_vfork_permanent
:
11342 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11343 &catch_vfork_breakpoint_ops
);
11346 error (_("unsupported or unknown fork kind; cannot catch it"));
11352 catch_exec_command_1 (const char *arg
, int from_tty
,
11353 struct cmd_list_element
*command
)
11355 struct gdbarch
*gdbarch
= get_current_arch ();
11356 const char *cond_string
= NULL
;
11357 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11361 arg
= skip_spaces (arg
);
11363 /* The allowed syntax is:
11365 catch exec if <cond>
11367 First, check if there's an if clause. */
11368 cond_string
= ep_parse_optional_if_clause (&arg
);
11370 if ((*arg
!= '\0') && !isspace (*arg
))
11371 error (_("Junk at end of arguments."));
11373 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11374 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
,
11375 &catch_exec_breakpoint_ops
);
11376 c
->exec_pathname
= NULL
;
11378 install_breakpoint (0, std::move (c
), 1);
11382 init_ada_exception_breakpoint (struct breakpoint
*b
,
11383 struct gdbarch
*gdbarch
,
11384 struct symtab_and_line sal
,
11385 const char *addr_string
,
11386 const struct breakpoint_ops
*ops
,
11393 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11395 loc_gdbarch
= gdbarch
;
11397 describe_other_breakpoints (loc_gdbarch
,
11398 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11399 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11400 version for exception catchpoints, because two catchpoints
11401 used for different exception names will use the same address.
11402 In this case, a "breakpoint ... also set at..." warning is
11403 unproductive. Besides, the warning phrasing is also a bit
11404 inappropriate, we should use the word catchpoint, and tell
11405 the user what type of catchpoint it is. The above is good
11406 enough for now, though. */
11409 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11411 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11412 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11413 b
->location
= string_to_event_location (&addr_string
,
11414 language_def (language_ada
));
11415 b
->language
= language_ada
;
11420 /* Compare two breakpoints and return a strcmp-like result. */
11423 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11425 uintptr_t ua
= (uintptr_t) a
;
11426 uintptr_t ub
= (uintptr_t) b
;
11428 if (a
->number
< b
->number
)
11430 else if (a
->number
> b
->number
)
11433 /* Now sort by address, in case we see, e..g, two breakpoints with
11437 return ua
> ub
? 1 : 0;
11440 /* Delete breakpoints by address or line. */
11443 clear_command (const char *arg
, int from_tty
)
11447 std::vector
<symtab_and_line
> decoded_sals
;
11448 symtab_and_line last_sal
;
11449 gdb::array_view
<symtab_and_line
> sals
;
11453 = decode_line_with_current_source (arg
,
11454 (DECODE_LINE_FUNFIRSTLINE
11455 | DECODE_LINE_LIST_MODE
));
11457 sals
= decoded_sals
;
11461 /* Set sal's line, symtab, pc, and pspace to the values
11462 corresponding to the last call to print_frame_info. If the
11463 codepoint is not valid, this will set all the fields to 0. */
11464 last_sal
= get_last_displayed_sal ();
11465 if (last_sal
.symtab
== 0)
11466 error (_("No source file specified."));
11472 /* We don't call resolve_sal_pc here. That's not as bad as it
11473 seems, because all existing breakpoints typically have both
11474 file/line and pc set. So, if clear is given file/line, we can
11475 match this to existing breakpoint without obtaining pc at all.
11477 We only support clearing given the address explicitly
11478 present in breakpoint table. Say, we've set breakpoint
11479 at file:line. There were several PC values for that file:line,
11480 due to optimization, all in one block.
11482 We've picked one PC value. If "clear" is issued with another
11483 PC corresponding to the same file:line, the breakpoint won't
11484 be cleared. We probably can still clear the breakpoint, but
11485 since the other PC value is never presented to user, user
11486 can only find it by guessing, and it does not seem important
11487 to support that. */
11489 /* For each line spec given, delete bps which correspond to it. Do
11490 it in two passes, solely to preserve the current behavior that
11491 from_tty is forced true if we delete more than one
11494 std::vector
<struct breakpoint
*> found
;
11495 for (const auto &sal
: sals
)
11497 const char *sal_fullname
;
11499 /* If exact pc given, clear bpts at that pc.
11500 If line given (pc == 0), clear all bpts on specified line.
11501 If defaulting, clear all bpts on default line
11504 defaulting sal.pc != 0 tests to do
11509 1 0 <can't happen> */
11511 sal_fullname
= (sal
.symtab
== NULL
11512 ? NULL
: symtab_to_fullname (sal
.symtab
));
11514 /* Find all matching breakpoints and add them to 'found'. */
11515 for (breakpoint
*b
: all_breakpoints ())
11518 /* Are we going to delete b? */
11519 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11521 for (bp_location
*loc
: b
->locations ())
11523 /* If the user specified file:line, don't allow a PC
11524 match. This matches historical gdb behavior. */
11525 int pc_match
= (!sal
.explicit_line
11527 && (loc
->pspace
== sal
.pspace
)
11528 && (loc
->address
== sal
.pc
)
11529 && (!section_is_overlay (loc
->section
)
11530 || loc
->section
== sal
.section
));
11531 int line_match
= 0;
11533 if ((default_match
|| sal
.explicit_line
)
11534 && loc
->symtab
!= NULL
11535 && sal_fullname
!= NULL
11536 && sal
.pspace
== loc
->pspace
11537 && loc
->line_number
== sal
.line
11538 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11539 sal_fullname
) == 0)
11542 if (pc_match
|| line_match
)
11551 found
.push_back (b
);
11555 /* Now go thru the 'found' chain and delete them. */
11556 if (found
.empty ())
11559 error (_("No breakpoint at %s."), arg
);
11561 error (_("No breakpoint at this line."));
11564 /* Remove duplicates from the vec. */
11565 std::sort (found
.begin (), found
.end (),
11566 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11568 return compare_breakpoints (bp_a
, bp_b
) < 0;
11570 found
.erase (std::unique (found
.begin (), found
.end (),
11571 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11573 return compare_breakpoints (bp_a
, bp_b
) == 0;
11577 if (found
.size () > 1)
11578 from_tty
= 1; /* Always report if deleted more than one. */
11581 if (found
.size () == 1)
11582 printf_unfiltered (_("Deleted breakpoint "));
11584 printf_unfiltered (_("Deleted breakpoints "));
11587 for (breakpoint
*iter
: found
)
11590 printf_unfiltered ("%d ", iter
->number
);
11591 delete_breakpoint (iter
);
11594 putchar_unfiltered ('\n');
11597 /* Delete breakpoint in BS if they are `delete' breakpoints and
11598 all breakpoints that are marked for deletion, whether hit or not.
11599 This is called after any breakpoint is hit, or after errors. */
11602 breakpoint_auto_delete (bpstat bs
)
11604 for (; bs
; bs
= bs
->next
)
11605 if (bs
->breakpoint_at
11606 && bs
->breakpoint_at
->disposition
== disp_del
11608 delete_breakpoint (bs
->breakpoint_at
);
11610 for (breakpoint
*b
: all_breakpoints_safe ())
11611 if (b
->disposition
== disp_del_at_next_stop
)
11612 delete_breakpoint (b
);
11615 /* A comparison function for bp_location AP and BP being interfaced to
11616 std::sort. Sort elements primarily by their ADDRESS (no matter what
11617 bl_address_is_meaningful says), secondarily by ordering first
11618 permanent elements and terciarily just ensuring the array is sorted
11619 stable way despite std::sort being an unstable algorithm. */
11622 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11624 if (a
->address
!= b
->address
)
11625 return a
->address
< b
->address
;
11627 /* Sort locations at the same address by their pspace number, keeping
11628 locations of the same inferior (in a multi-inferior environment)
11631 if (a
->pspace
->num
!= b
->pspace
->num
)
11632 return a
->pspace
->num
< b
->pspace
->num
;
11634 /* Sort permanent breakpoints first. */
11635 if (a
->permanent
!= b
->permanent
)
11636 return a
->permanent
> b
->permanent
;
11638 /* Sort by type in order to make duplicate determination easier.
11639 See update_global_location_list. This is kept in sync with
11640 breakpoint_locations_match. */
11641 if (a
->loc_type
< b
->loc_type
)
11644 /* Likewise, for range-breakpoints, sort by length. */
11645 if (a
->loc_type
== bp_loc_hardware_breakpoint
11646 && b
->loc_type
== bp_loc_hardware_breakpoint
11647 && a
->length
< b
->length
)
11650 /* Make the internal GDB representation stable across GDB runs
11651 where A and B memory inside GDB can differ. Breakpoint locations of
11652 the same type at the same address can be sorted in arbitrary order. */
11654 if (a
->owner
->number
!= b
->owner
->number
)
11655 return a
->owner
->number
< b
->owner
->number
;
11660 /* Set bp_locations_placed_address_before_address_max and
11661 bp_locations_shadow_len_after_address_max according to the current
11662 content of the bp_locations array. */
11665 bp_locations_target_extensions_update (void)
11667 struct bp_location
*bl
, **blp_tmp
;
11669 bp_locations_placed_address_before_address_max
= 0;
11670 bp_locations_shadow_len_after_address_max
= 0;
11672 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11674 CORE_ADDR start
, end
, addr
;
11676 if (!bp_location_has_shadow (bl
))
11679 start
= bl
->target_info
.placed_address
;
11680 end
= start
+ bl
->target_info
.shadow_len
;
11682 gdb_assert (bl
->address
>= start
);
11683 addr
= bl
->address
- start
;
11684 if (addr
> bp_locations_placed_address_before_address_max
)
11685 bp_locations_placed_address_before_address_max
= addr
;
11687 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11689 gdb_assert (bl
->address
< end
);
11690 addr
= end
- bl
->address
;
11691 if (addr
> bp_locations_shadow_len_after_address_max
)
11692 bp_locations_shadow_len_after_address_max
= addr
;
11696 /* Download tracepoint locations if they haven't been. */
11699 download_tracepoint_locations (void)
11701 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11703 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11705 for (breakpoint
*b
: all_tracepoints ())
11707 struct tracepoint
*t
;
11708 int bp_location_downloaded
= 0;
11710 if ((b
->type
== bp_fast_tracepoint
11711 ? !may_insert_fast_tracepoints
11712 : !may_insert_tracepoints
))
11715 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11717 if (target_can_download_tracepoint ())
11718 can_download_tracepoint
= TRIBOOL_TRUE
;
11720 can_download_tracepoint
= TRIBOOL_FALSE
;
11723 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11726 for (bp_location
*bl
: b
->locations ())
11728 /* In tracepoint, locations are _never_ duplicated, so
11729 should_be_inserted is equivalent to
11730 unduplicated_should_be_inserted. */
11731 if (!should_be_inserted (bl
) || bl
->inserted
)
11734 switch_to_program_space_and_thread (bl
->pspace
);
11736 target_download_tracepoint (bl
);
11739 bp_location_downloaded
= 1;
11741 t
= (struct tracepoint
*) b
;
11742 t
->number_on_target
= b
->number
;
11743 if (bp_location_downloaded
)
11744 gdb::observers::breakpoint_modified
.notify (b
);
11748 /* Swap the insertion/duplication state between two locations. */
11751 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11753 const int left_inserted
= left
->inserted
;
11754 const int left_duplicate
= left
->duplicate
;
11755 const int left_needs_update
= left
->needs_update
;
11756 const struct bp_target_info left_target_info
= left
->target_info
;
11758 /* Locations of tracepoints can never be duplicated. */
11759 if (is_tracepoint (left
->owner
))
11760 gdb_assert (!left
->duplicate
);
11761 if (is_tracepoint (right
->owner
))
11762 gdb_assert (!right
->duplicate
);
11764 left
->inserted
= right
->inserted
;
11765 left
->duplicate
= right
->duplicate
;
11766 left
->needs_update
= right
->needs_update
;
11767 left
->target_info
= right
->target_info
;
11768 right
->inserted
= left_inserted
;
11769 right
->duplicate
= left_duplicate
;
11770 right
->needs_update
= left_needs_update
;
11771 right
->target_info
= left_target_info
;
11774 /* Force the re-insertion of the locations at ADDRESS. This is called
11775 once a new/deleted/modified duplicate location is found and we are evaluating
11776 conditions on the target's side. Such conditions need to be updated on
11780 force_breakpoint_reinsertion (struct bp_location
*bl
)
11782 struct bp_location
**locp
= NULL
, **loc2p
;
11783 struct bp_location
*loc
;
11784 CORE_ADDR address
= 0;
11787 address
= bl
->address
;
11788 pspace_num
= bl
->pspace
->num
;
11790 /* This is only meaningful if the target is
11791 evaluating conditions and if the user has
11792 opted for condition evaluation on the target's
11794 if (gdb_evaluates_breakpoint_condition_p ()
11795 || !target_supports_evaluation_of_breakpoint_conditions ())
11798 /* Flag all breakpoint locations with this address and
11799 the same program space as the location
11800 as "its condition has changed". We need to
11801 update the conditions on the target's side. */
11802 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11806 if (!is_breakpoint (loc
->owner
)
11807 || pspace_num
!= loc
->pspace
->num
)
11810 /* Flag the location appropriately. We use a different state to
11811 let everyone know that we already updated the set of locations
11812 with addr bl->address and program space bl->pspace. This is so
11813 we don't have to keep calling these functions just to mark locations
11814 that have already been marked. */
11815 loc
->condition_changed
= condition_updated
;
11817 /* Free the agent expression bytecode as well. We will compute
11819 loc
->cond_bytecode
.reset ();
11823 /* Called whether new breakpoints are created, or existing breakpoints
11824 deleted, to update the global location list and recompute which
11825 locations are duplicate of which.
11827 The INSERT_MODE flag determines whether locations may not, may, or
11828 shall be inserted now. See 'enum ugll_insert_mode' for more
11832 update_global_location_list (enum ugll_insert_mode insert_mode
)
11834 struct bp_location
**locp
;
11835 /* Last breakpoint location address that was marked for update. */
11836 CORE_ADDR last_addr
= 0;
11837 /* Last breakpoint location program space that was marked for update. */
11838 int last_pspace_num
= -1;
11840 /* Used in the duplicates detection below. When iterating over all
11841 bp_locations, points to the first bp_location of a given address.
11842 Breakpoints and watchpoints of different types are never
11843 duplicates of each other. Keep one pointer for each type of
11844 breakpoint/watchpoint, so we only need to loop over all locations
11846 struct bp_location
*bp_loc_first
; /* breakpoint */
11847 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11848 struct bp_location
*awp_loc_first
; /* access watchpoint */
11849 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11851 /* Saved former bp_locations array which we compare against the newly
11852 built bp_locations from the current state of ALL_BREAKPOINTS. */
11853 struct bp_location
**old_locp
;
11854 unsigned old_locations_count
;
11855 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11857 old_locations_count
= bp_locations_count
;
11858 bp_locations
= NULL
;
11859 bp_locations_count
= 0;
11861 for (breakpoint
*b
: all_breakpoints ())
11862 for (bp_location
*loc ATTRIBUTE_UNUSED
: b
->locations ())
11863 bp_locations_count
++;
11865 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11866 locp
= bp_locations
;
11867 for (breakpoint
*b
: all_breakpoints ())
11868 for (bp_location
*loc
: b
->locations ())
11871 /* See if we need to "upgrade" a software breakpoint to a hardware
11872 breakpoint. Do this before deciding whether locations are
11873 duplicates. Also do this before sorting because sorting order
11874 depends on location type. */
11875 for (locp
= bp_locations
;
11876 locp
< bp_locations
+ bp_locations_count
;
11879 bp_location
*loc
= *locp
;
11880 if (!loc
->inserted
&& should_be_inserted (loc
))
11881 handle_automatic_hardware_breakpoints (loc
);
11884 std::sort (bp_locations
, bp_locations
+ bp_locations_count
,
11885 bp_location_is_less_than
);
11887 bp_locations_target_extensions_update ();
11889 /* Identify bp_location instances that are no longer present in the
11890 new list, and therefore should be freed. Note that it's not
11891 necessary that those locations should be removed from inferior --
11892 if there's another location at the same address (previously
11893 marked as duplicate), we don't need to remove/insert the
11896 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11897 and former bp_location array state respectively. */
11899 locp
= bp_locations
;
11900 for (old_locp
= old_locations
.get ();
11901 old_locp
< old_locations
.get () + old_locations_count
;
11904 struct bp_location
*old_loc
= *old_locp
;
11905 struct bp_location
**loc2p
;
11907 /* Tells if 'old_loc' is found among the new locations. If
11908 not, we have to free it. */
11909 int found_object
= 0;
11910 /* Tells if the location should remain inserted in the target. */
11911 int keep_in_target
= 0;
11914 /* Skip LOCP entries which will definitely never be needed.
11915 Stop either at or being the one matching OLD_LOC. */
11916 while (locp
< bp_locations
+ bp_locations_count
11917 && (*locp
)->address
< old_loc
->address
)
11921 (loc2p
< bp_locations
+ bp_locations_count
11922 && (*loc2p
)->address
== old_loc
->address
);
11925 /* Check if this is a new/duplicated location or a duplicated
11926 location that had its condition modified. If so, we want to send
11927 its condition to the target if evaluation of conditions is taking
11929 if ((*loc2p
)->condition_changed
== condition_modified
11930 && (last_addr
!= old_loc
->address
11931 || last_pspace_num
!= old_loc
->pspace
->num
))
11933 force_breakpoint_reinsertion (*loc2p
);
11934 last_pspace_num
= old_loc
->pspace
->num
;
11937 if (*loc2p
== old_loc
)
11941 /* We have already handled this address, update it so that we don't
11942 have to go through updates again. */
11943 last_addr
= old_loc
->address
;
11945 /* Target-side condition evaluation: Handle deleted locations. */
11947 force_breakpoint_reinsertion (old_loc
);
11949 /* If this location is no longer present, and inserted, look if
11950 there's maybe a new location at the same address. If so,
11951 mark that one inserted, and don't remove this one. This is
11952 needed so that we don't have a time window where a breakpoint
11953 at certain location is not inserted. */
11955 if (old_loc
->inserted
)
11957 /* If the location is inserted now, we might have to remove
11960 if (found_object
&& should_be_inserted (old_loc
))
11962 /* The location is still present in the location list,
11963 and still should be inserted. Don't do anything. */
11964 keep_in_target
= 1;
11968 /* This location still exists, but it won't be kept in the
11969 target since it may have been disabled. We proceed to
11970 remove its target-side condition. */
11972 /* The location is either no longer present, or got
11973 disabled. See if there's another location at the
11974 same address, in which case we don't need to remove
11975 this one from the target. */
11977 /* OLD_LOC comes from existing struct breakpoint. */
11978 if (bl_address_is_meaningful (old_loc
))
11981 (loc2p
< bp_locations
+ bp_locations_count
11982 && (*loc2p
)->address
== old_loc
->address
);
11985 struct bp_location
*loc2
= *loc2p
;
11987 if (loc2
== old_loc
)
11990 if (breakpoint_locations_match (loc2
, old_loc
))
11992 /* Read watchpoint locations are switched to
11993 access watchpoints, if the former are not
11994 supported, but the latter are. */
11995 if (is_hardware_watchpoint (old_loc
->owner
))
11997 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11998 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12001 /* loc2 is a duplicated location. We need to check
12002 if it should be inserted in case it will be
12004 if (unduplicated_should_be_inserted (loc2
))
12006 swap_insertion (old_loc
, loc2
);
12007 keep_in_target
= 1;
12015 if (!keep_in_target
)
12017 if (remove_breakpoint (old_loc
))
12019 /* This is just about all we can do. We could keep
12020 this location on the global list, and try to
12021 remove it next time, but there's no particular
12022 reason why we will succeed next time.
12024 Note that at this point, old_loc->owner is still
12025 valid, as delete_breakpoint frees the breakpoint
12026 only after calling us. */
12027 printf_filtered (_("warning: Error removing "
12028 "breakpoint %d\n"),
12029 old_loc
->owner
->number
);
12037 if (removed
&& target_is_non_stop_p ()
12038 && need_moribund_for_location_type (old_loc
))
12040 /* This location was removed from the target. In
12041 non-stop mode, a race condition is possible where
12042 we've removed a breakpoint, but stop events for that
12043 breakpoint are already queued and will arrive later.
12044 We apply an heuristic to be able to distinguish such
12045 SIGTRAPs from other random SIGTRAPs: we keep this
12046 breakpoint location for a bit, and will retire it
12047 after we see some number of events. The theory here
12048 is that reporting of events should, "on the average",
12049 be fair, so after a while we'll see events from all
12050 threads that have anything of interest, and no longer
12051 need to keep this breakpoint location around. We
12052 don't hold locations forever so to reduce chances of
12053 mistaking a non-breakpoint SIGTRAP for a breakpoint
12056 The heuristic failing can be disastrous on
12057 decr_pc_after_break targets.
12059 On decr_pc_after_break targets, like e.g., x86-linux,
12060 if we fail to recognize a late breakpoint SIGTRAP,
12061 because events_till_retirement has reached 0 too
12062 soon, we'll fail to do the PC adjustment, and report
12063 a random SIGTRAP to the user. When the user resumes
12064 the inferior, it will most likely immediately crash
12065 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12066 corrupted, because of being resumed e.g., in the
12067 middle of a multi-byte instruction, or skipped a
12068 one-byte instruction. This was actually seen happen
12069 on native x86-linux, and should be less rare on
12070 targets that do not support new thread events, like
12071 remote, due to the heuristic depending on
12074 Mistaking a random SIGTRAP for a breakpoint trap
12075 causes similar symptoms (PC adjustment applied when
12076 it shouldn't), but then again, playing with SIGTRAPs
12077 behind the debugger's back is asking for trouble.
12079 Since hardware watchpoint traps are always
12080 distinguishable from other traps, so we don't need to
12081 apply keep hardware watchpoint moribund locations
12082 around. We simply always ignore hardware watchpoint
12083 traps we can no longer explain. */
12085 process_stratum_target
*proc_target
= nullptr;
12086 for (inferior
*inf
: all_inferiors ())
12087 if (inf
->pspace
== old_loc
->pspace
)
12089 proc_target
= inf
->process_target ();
12092 if (proc_target
!= nullptr)
12093 old_loc
->events_till_retirement
12094 = 3 * (thread_count (proc_target
) + 1);
12096 old_loc
->events_till_retirement
= 1;
12097 old_loc
->owner
= NULL
;
12099 moribund_locations
.push_back (old_loc
);
12103 old_loc
->owner
= NULL
;
12104 decref_bp_location (&old_loc
);
12109 /* Rescan breakpoints at the same address and section, marking the
12110 first one as "first" and any others as "duplicates". This is so
12111 that the bpt instruction is only inserted once. If we have a
12112 permanent breakpoint at the same place as BPT, make that one the
12113 official one, and the rest as duplicates. Permanent breakpoints
12114 are sorted first for the same address.
12116 Do the same for hardware watchpoints, but also considering the
12117 watchpoint's type (regular/access/read) and length. */
12119 bp_loc_first
= NULL
;
12120 wp_loc_first
= NULL
;
12121 awp_loc_first
= NULL
;
12122 rwp_loc_first
= NULL
;
12125 ALL_BP_LOCATIONS (loc
, locp
)
12127 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12129 struct bp_location
**loc_first_p
;
12130 breakpoint
*b
= loc
->owner
;
12132 if (!unduplicated_should_be_inserted (loc
)
12133 || !bl_address_is_meaningful (loc
)
12134 /* Don't detect duplicate for tracepoint locations because they are
12135 never duplicated. See the comments in field `duplicate' of
12136 `struct bp_location'. */
12137 || is_tracepoint (b
))
12139 /* Clear the condition modification flag. */
12140 loc
->condition_changed
= condition_unchanged
;
12144 if (b
->type
== bp_hardware_watchpoint
)
12145 loc_first_p
= &wp_loc_first
;
12146 else if (b
->type
== bp_read_watchpoint
)
12147 loc_first_p
= &rwp_loc_first
;
12148 else if (b
->type
== bp_access_watchpoint
)
12149 loc_first_p
= &awp_loc_first
;
12151 loc_first_p
= &bp_loc_first
;
12153 if (*loc_first_p
== NULL
12154 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12155 || !breakpoint_locations_match (loc
, *loc_first_p
))
12157 *loc_first_p
= loc
;
12158 loc
->duplicate
= 0;
12160 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12162 loc
->needs_update
= 1;
12163 /* Clear the condition modification flag. */
12164 loc
->condition_changed
= condition_unchanged
;
12170 /* This and the above ensure the invariant that the first location
12171 is not duplicated, and is the inserted one.
12172 All following are marked as duplicated, and are not inserted. */
12174 swap_insertion (loc
, *loc_first_p
);
12175 loc
->duplicate
= 1;
12177 /* Clear the condition modification flag. */
12178 loc
->condition_changed
= condition_unchanged
;
12181 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12183 if (insert_mode
!= UGLL_DONT_INSERT
)
12184 insert_breakpoint_locations ();
12187 /* Even though the caller told us to not insert new
12188 locations, we may still need to update conditions on the
12189 target's side of breakpoints that were already inserted
12190 if the target is evaluating breakpoint conditions. We
12191 only update conditions for locations that are marked
12193 update_inserted_breakpoint_locations ();
12197 if (insert_mode
!= UGLL_DONT_INSERT
)
12198 download_tracepoint_locations ();
12202 breakpoint_retire_moribund (void)
12204 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
12206 struct bp_location
*loc
= moribund_locations
[ix
];
12207 if (--(loc
->events_till_retirement
) == 0)
12209 decref_bp_location (&loc
);
12210 unordered_remove (moribund_locations
, ix
);
12217 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12222 update_global_location_list (insert_mode
);
12224 catch (const gdb_exception_error
&e
)
12229 /* Clear BKP from a BPS. */
12232 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12236 for (bs
= bps
; bs
; bs
= bs
->next
)
12237 if (bs
->breakpoint_at
== bpt
)
12239 bs
->breakpoint_at
= NULL
;
12240 bs
->old_val
= NULL
;
12241 /* bs->commands will be freed later. */
12245 /* Callback for iterate_over_threads. */
12247 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12249 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12251 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12255 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12259 say_where (struct breakpoint
*b
)
12261 struct value_print_options opts
;
12263 get_user_print_options (&opts
);
12265 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12267 if (b
->loc
== NULL
)
12269 /* For pending locations, the output differs slightly based
12270 on b->extra_string. If this is non-NULL, it contains either
12271 a condition or dprintf arguments. */
12272 if (b
->extra_string
== NULL
)
12274 printf_filtered (_(" (%s) pending."),
12275 event_location_to_string (b
->location
.get ()));
12277 else if (b
->type
== bp_dprintf
)
12279 printf_filtered (_(" (%s,%s) pending."),
12280 event_location_to_string (b
->location
.get ()),
12285 printf_filtered (_(" (%s %s) pending."),
12286 event_location_to_string (b
->location
.get ()),
12292 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12293 printf_filtered (" at %ps",
12294 styled_string (address_style
.style (),
12295 paddress (b
->loc
->gdbarch
,
12296 b
->loc
->address
)));
12297 if (b
->loc
->symtab
!= NULL
)
12299 /* If there is a single location, we can print the location
12301 if (b
->loc
->next
== NULL
)
12303 const char *filename
12304 = symtab_to_filename_for_display (b
->loc
->symtab
);
12305 printf_filtered (": file %ps, line %d.",
12306 styled_string (file_name_style
.style (),
12308 b
->loc
->line_number
);
12311 /* This is not ideal, but each location may have a
12312 different file name, and this at least reflects the
12313 real situation somewhat. */
12314 printf_filtered (": %s.",
12315 event_location_to_string (b
->location
.get ()));
12320 struct bp_location
*loc
= b
->loc
;
12322 for (; loc
; loc
= loc
->next
)
12324 printf_filtered (" (%d locations)", n
);
12329 bp_location::~bp_location ()
12331 xfree (function_name
);
12334 /* Destructor for the breakpoint base class. */
12336 breakpoint::~breakpoint ()
12338 xfree (this->cond_string
);
12339 xfree (this->extra_string
);
12342 /* See breakpoint.h. */
12344 bp_locations_range
breakpoint::locations ()
12346 return bp_locations_range (this->loc
);
12349 static struct bp_location
*
12350 base_breakpoint_allocate_location (struct breakpoint
*self
)
12352 return new bp_location (self
);
12356 base_breakpoint_re_set (struct breakpoint
*b
)
12358 /* Nothing to re-set. */
12361 #define internal_error_pure_virtual_called() \
12362 gdb_assert_not_reached ("pure virtual function called")
12365 base_breakpoint_insert_location (struct bp_location
*bl
)
12367 internal_error_pure_virtual_called ();
12371 base_breakpoint_remove_location (struct bp_location
*bl
,
12372 enum remove_bp_reason reason
)
12374 internal_error_pure_virtual_called ();
12378 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12379 const address_space
*aspace
,
12381 const struct target_waitstatus
*ws
)
12383 internal_error_pure_virtual_called ();
12387 base_breakpoint_check_status (bpstat bs
)
12392 /* A "works_in_software_mode" breakpoint_ops method that just internal
12396 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12398 internal_error_pure_virtual_called ();
12401 /* A "resources_needed" breakpoint_ops method that just internal
12405 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12407 internal_error_pure_virtual_called ();
12410 static enum print_stop_action
12411 base_breakpoint_print_it (bpstat bs
)
12413 internal_error_pure_virtual_called ();
12417 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12418 struct ui_out
*uiout
)
12424 base_breakpoint_print_mention (struct breakpoint
*b
)
12426 internal_error_pure_virtual_called ();
12430 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12432 internal_error_pure_virtual_called ();
12436 base_breakpoint_create_sals_from_location
12437 (struct event_location
*location
,
12438 struct linespec_result
*canonical
,
12439 enum bptype type_wanted
)
12441 internal_error_pure_virtual_called ();
12445 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12446 struct linespec_result
*c
,
12447 gdb::unique_xmalloc_ptr
<char> cond_string
,
12448 gdb::unique_xmalloc_ptr
<char> extra_string
,
12449 enum bptype type_wanted
,
12450 enum bpdisp disposition
,
12452 int task
, int ignore_count
,
12453 const struct breakpoint_ops
*o
,
12454 int from_tty
, int enabled
,
12455 int internal
, unsigned flags
)
12457 internal_error_pure_virtual_called ();
12460 static std::vector
<symtab_and_line
>
12461 base_breakpoint_decode_location (struct breakpoint
*b
,
12462 struct event_location
*location
,
12463 struct program_space
*search_pspace
)
12465 internal_error_pure_virtual_called ();
12468 /* The default 'explains_signal' method. */
12471 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12476 /* The default "after_condition_true" method. */
12479 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12481 /* Nothing to do. */
12484 struct breakpoint_ops base_breakpoint_ops
=
12486 base_breakpoint_allocate_location
,
12487 base_breakpoint_re_set
,
12488 base_breakpoint_insert_location
,
12489 base_breakpoint_remove_location
,
12490 base_breakpoint_breakpoint_hit
,
12491 base_breakpoint_check_status
,
12492 base_breakpoint_resources_needed
,
12493 base_breakpoint_works_in_software_mode
,
12494 base_breakpoint_print_it
,
12496 base_breakpoint_print_one_detail
,
12497 base_breakpoint_print_mention
,
12498 base_breakpoint_print_recreate
,
12499 base_breakpoint_create_sals_from_location
,
12500 base_breakpoint_create_breakpoints_sal
,
12501 base_breakpoint_decode_location
,
12502 base_breakpoint_explains_signal
,
12503 base_breakpoint_after_condition_true
,
12506 /* Default breakpoint_ops methods. */
12509 bkpt_re_set (struct breakpoint
*b
)
12511 /* FIXME: is this still reachable? */
12512 if (breakpoint_event_location_empty_p (b
))
12514 /* Anything without a location can't be re-set. */
12515 delete_breakpoint (b
);
12519 breakpoint_re_set_default (b
);
12523 bkpt_insert_location (struct bp_location
*bl
)
12525 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12527 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12528 bl
->target_info
.placed_address
= addr
;
12530 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12531 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12533 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12537 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12539 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12540 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12542 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12546 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12547 const address_space
*aspace
, CORE_ADDR bp_addr
,
12548 const struct target_waitstatus
*ws
)
12550 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12551 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12554 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12558 if (overlay_debugging
/* unmapped overlay section */
12559 && section_is_overlay (bl
->section
)
12560 && !section_is_mapped (bl
->section
))
12567 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12568 const address_space
*aspace
, CORE_ADDR bp_addr
,
12569 const struct target_waitstatus
*ws
)
12571 if (dprintf_style
== dprintf_style_agent
12572 && target_can_run_breakpoint_commands ())
12574 /* An agent-style dprintf never causes a stop. If we see a trap
12575 for this address it must be for a breakpoint that happens to
12576 be set at the same address. */
12580 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12584 bkpt_resources_needed (const struct bp_location
*bl
)
12586 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12591 static enum print_stop_action
12592 bkpt_print_it (bpstat bs
)
12594 struct breakpoint
*b
;
12595 const struct bp_location
*bl
;
12597 struct ui_out
*uiout
= current_uiout
;
12599 gdb_assert (bs
->bp_location_at
!= NULL
);
12601 bl
= bs
->bp_location_at
.get ();
12602 b
= bs
->breakpoint_at
;
12604 bp_temp
= b
->disposition
== disp_del
;
12605 if (bl
->address
!= bl
->requested_address
)
12606 breakpoint_adjustment_warning (bl
->requested_address
,
12609 annotate_breakpoint (b
->number
);
12610 maybe_print_thread_hit_breakpoint (uiout
);
12612 if (uiout
->is_mi_like_p ())
12614 uiout
->field_string ("reason",
12615 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12616 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12619 uiout
->message ("Temporary breakpoint %pF, ",
12620 signed_field ("bkptno", b
->number
));
12622 uiout
->message ("Breakpoint %pF, ",
12623 signed_field ("bkptno", b
->number
));
12625 return PRINT_SRC_AND_LOC
;
12629 bkpt_print_mention (struct breakpoint
*b
)
12631 if (current_uiout
->is_mi_like_p ())
12636 case bp_breakpoint
:
12637 case bp_gnu_ifunc_resolver
:
12638 if (b
->disposition
== disp_del
)
12639 printf_filtered (_("Temporary breakpoint"));
12641 printf_filtered (_("Breakpoint"));
12642 printf_filtered (_(" %d"), b
->number
);
12643 if (b
->type
== bp_gnu_ifunc_resolver
)
12644 printf_filtered (_(" at gnu-indirect-function resolver"));
12646 case bp_hardware_breakpoint
:
12647 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12650 printf_filtered (_("Dprintf %d"), b
->number
);
12658 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12660 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12661 fprintf_unfiltered (fp
, "tbreak");
12662 else if (tp
->type
== bp_breakpoint
)
12663 fprintf_unfiltered (fp
, "break");
12664 else if (tp
->type
== bp_hardware_breakpoint
12665 && tp
->disposition
== disp_del
)
12666 fprintf_unfiltered (fp
, "thbreak");
12667 else if (tp
->type
== bp_hardware_breakpoint
)
12668 fprintf_unfiltered (fp
, "hbreak");
12670 internal_error (__FILE__
, __LINE__
,
12671 _("unhandled breakpoint type %d"), (int) tp
->type
);
12673 fprintf_unfiltered (fp
, " %s",
12674 event_location_to_string (tp
->location
.get ()));
12676 /* Print out extra_string if this breakpoint is pending. It might
12677 contain, for example, conditions that were set by the user. */
12678 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12679 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12681 print_recreate_thread (tp
, fp
);
12685 bkpt_create_sals_from_location (struct event_location
*location
,
12686 struct linespec_result
*canonical
,
12687 enum bptype type_wanted
)
12689 create_sals_from_location_default (location
, canonical
, type_wanted
);
12693 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12694 struct linespec_result
*canonical
,
12695 gdb::unique_xmalloc_ptr
<char> cond_string
,
12696 gdb::unique_xmalloc_ptr
<char> extra_string
,
12697 enum bptype type_wanted
,
12698 enum bpdisp disposition
,
12700 int task
, int ignore_count
,
12701 const struct breakpoint_ops
*ops
,
12702 int from_tty
, int enabled
,
12703 int internal
, unsigned flags
)
12705 create_breakpoints_sal_default (gdbarch
, canonical
,
12706 std::move (cond_string
),
12707 std::move (extra_string
),
12709 disposition
, thread
, task
,
12710 ignore_count
, ops
, from_tty
,
12711 enabled
, internal
, flags
);
12714 static std::vector
<symtab_and_line
>
12715 bkpt_decode_location (struct breakpoint
*b
,
12716 struct event_location
*location
,
12717 struct program_space
*search_pspace
)
12719 return decode_location_default (b
, location
, search_pspace
);
12722 /* Virtual table for internal breakpoints. */
12725 internal_bkpt_re_set (struct breakpoint
*b
)
12729 /* Delete overlay event and longjmp master breakpoints; they
12730 will be reset later by breakpoint_re_set. */
12731 case bp_overlay_event
:
12732 case bp_longjmp_master
:
12733 case bp_std_terminate_master
:
12734 case bp_exception_master
:
12735 delete_breakpoint (b
);
12738 /* This breakpoint is special, it's set up when the inferior
12739 starts and we really don't want to touch it. */
12740 case bp_shlib_event
:
12742 /* Like bp_shlib_event, this breakpoint type is special. Once
12743 it is set up, we do not want to touch it. */
12744 case bp_thread_event
:
12750 internal_bkpt_check_status (bpstat bs
)
12752 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12754 /* If requested, stop when the dynamic linker notifies GDB of
12755 events. This allows the user to get control and place
12756 breakpoints in initializer routines for dynamically loaded
12757 objects (among other things). */
12758 bs
->stop
= stop_on_solib_events
;
12759 bs
->print
= stop_on_solib_events
;
12765 static enum print_stop_action
12766 internal_bkpt_print_it (bpstat bs
)
12768 struct breakpoint
*b
;
12770 b
= bs
->breakpoint_at
;
12774 case bp_shlib_event
:
12775 /* Did we stop because the user set the stop_on_solib_events
12776 variable? (If so, we report this as a generic, "Stopped due
12777 to shlib event" message.) */
12778 print_solib_event (0);
12781 case bp_thread_event
:
12782 /* Not sure how we will get here.
12783 GDB should not stop for these breakpoints. */
12784 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12787 case bp_overlay_event
:
12788 /* By analogy with the thread event, GDB should not stop for these. */
12789 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12792 case bp_longjmp_master
:
12793 /* These should never be enabled. */
12794 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12797 case bp_std_terminate_master
:
12798 /* These should never be enabled. */
12799 printf_filtered (_("std::terminate Master Breakpoint: "
12800 "gdb should not stop!\n"));
12803 case bp_exception_master
:
12804 /* These should never be enabled. */
12805 printf_filtered (_("Exception Master Breakpoint: "
12806 "gdb should not stop!\n"));
12810 return PRINT_NOTHING
;
12814 internal_bkpt_print_mention (struct breakpoint
*b
)
12816 /* Nothing to mention. These breakpoints are internal. */
12819 /* Virtual table for momentary breakpoints */
12822 momentary_bkpt_re_set (struct breakpoint
*b
)
12824 /* Keep temporary breakpoints, which can be encountered when we step
12825 over a dlopen call and solib_add is resetting the breakpoints.
12826 Otherwise these should have been blown away via the cleanup chain
12827 or by breakpoint_init_inferior when we rerun the executable. */
12831 momentary_bkpt_check_status (bpstat bs
)
12833 /* Nothing. The point of these breakpoints is causing a stop. */
12836 static enum print_stop_action
12837 momentary_bkpt_print_it (bpstat bs
)
12839 return PRINT_UNKNOWN
;
12843 momentary_bkpt_print_mention (struct breakpoint
*b
)
12845 /* Nothing to mention. These breakpoints are internal. */
12848 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12850 It gets cleared already on the removal of the first one of such placed
12851 breakpoints. This is OK as they get all removed altogether. */
12853 longjmp_breakpoint::~longjmp_breakpoint ()
12855 thread_info
*tp
= find_thread_global_id (this->thread
);
12858 tp
->initiating_frame
= null_frame_id
;
12861 /* Specific methods for probe breakpoints. */
12864 bkpt_probe_insert_location (struct bp_location
*bl
)
12866 int v
= bkpt_insert_location (bl
);
12870 /* The insertion was successful, now let's set the probe's semaphore
12872 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12879 bkpt_probe_remove_location (struct bp_location
*bl
,
12880 enum remove_bp_reason reason
)
12882 /* Let's clear the semaphore before removing the location. */
12883 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12885 return bkpt_remove_location (bl
, reason
);
12889 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12890 struct linespec_result
*canonical
,
12891 enum bptype type_wanted
)
12893 struct linespec_sals lsal
;
12895 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12897 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12898 canonical
->lsals
.push_back (std::move (lsal
));
12901 static std::vector
<symtab_and_line
>
12902 bkpt_probe_decode_location (struct breakpoint
*b
,
12903 struct event_location
*location
,
12904 struct program_space
*search_pspace
)
12906 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12908 error (_("probe not found"));
12912 /* The breakpoint_ops structure to be used in tracepoints. */
12915 tracepoint_re_set (struct breakpoint
*b
)
12917 breakpoint_re_set_default (b
);
12921 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12922 const address_space
*aspace
, CORE_ADDR bp_addr
,
12923 const struct target_waitstatus
*ws
)
12925 /* By definition, the inferior does not report stops at
12931 tracepoint_print_one_detail (const struct breakpoint
*self
,
12932 struct ui_out
*uiout
)
12934 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12935 if (!tp
->static_trace_marker_id
.empty ())
12937 gdb_assert (self
->type
== bp_static_tracepoint
);
12939 uiout
->message ("\tmarker id is %pF\n",
12940 string_field ("static-tracepoint-marker-string-id",
12941 tp
->static_trace_marker_id
.c_str ()));
12946 tracepoint_print_mention (struct breakpoint
*b
)
12948 if (current_uiout
->is_mi_like_p ())
12953 case bp_tracepoint
:
12954 printf_filtered (_("Tracepoint"));
12955 printf_filtered (_(" %d"), b
->number
);
12957 case bp_fast_tracepoint
:
12958 printf_filtered (_("Fast tracepoint"));
12959 printf_filtered (_(" %d"), b
->number
);
12961 case bp_static_tracepoint
:
12962 printf_filtered (_("Static tracepoint"));
12963 printf_filtered (_(" %d"), b
->number
);
12966 internal_error (__FILE__
, __LINE__
,
12967 _("unhandled tracepoint type %d"), (int) b
->type
);
12974 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12976 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12978 if (self
->type
== bp_fast_tracepoint
)
12979 fprintf_unfiltered (fp
, "ftrace");
12980 else if (self
->type
== bp_static_tracepoint
)
12981 fprintf_unfiltered (fp
, "strace");
12982 else if (self
->type
== bp_tracepoint
)
12983 fprintf_unfiltered (fp
, "trace");
12985 internal_error (__FILE__
, __LINE__
,
12986 _("unhandled tracepoint type %d"), (int) self
->type
);
12988 fprintf_unfiltered (fp
, " %s",
12989 event_location_to_string (self
->location
.get ()));
12990 print_recreate_thread (self
, fp
);
12992 if (tp
->pass_count
)
12993 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12997 tracepoint_create_sals_from_location (struct event_location
*location
,
12998 struct linespec_result
*canonical
,
12999 enum bptype type_wanted
)
13001 create_sals_from_location_default (location
, canonical
, type_wanted
);
13005 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13006 struct linespec_result
*canonical
,
13007 gdb::unique_xmalloc_ptr
<char> cond_string
,
13008 gdb::unique_xmalloc_ptr
<char> extra_string
,
13009 enum bptype type_wanted
,
13010 enum bpdisp disposition
,
13012 int task
, int ignore_count
,
13013 const struct breakpoint_ops
*ops
,
13014 int from_tty
, int enabled
,
13015 int internal
, unsigned flags
)
13017 create_breakpoints_sal_default (gdbarch
, canonical
,
13018 std::move (cond_string
),
13019 std::move (extra_string
),
13021 disposition
, thread
, task
,
13022 ignore_count
, ops
, from_tty
,
13023 enabled
, internal
, flags
);
13026 static std::vector
<symtab_and_line
>
13027 tracepoint_decode_location (struct breakpoint
*b
,
13028 struct event_location
*location
,
13029 struct program_space
*search_pspace
)
13031 return decode_location_default (b
, location
, search_pspace
);
13034 struct breakpoint_ops tracepoint_breakpoint_ops
;
13036 /* Virtual table for tracepoints on static probes. */
13039 tracepoint_probe_create_sals_from_location
13040 (struct event_location
*location
,
13041 struct linespec_result
*canonical
,
13042 enum bptype type_wanted
)
13044 /* We use the same method for breakpoint on probes. */
13045 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13048 static std::vector
<symtab_and_line
>
13049 tracepoint_probe_decode_location (struct breakpoint
*b
,
13050 struct event_location
*location
,
13051 struct program_space
*search_pspace
)
13053 /* We use the same method for breakpoint on probes. */
13054 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13057 /* Dprintf breakpoint_ops methods. */
13060 dprintf_re_set (struct breakpoint
*b
)
13062 breakpoint_re_set_default (b
);
13064 /* extra_string should never be non-NULL for dprintf. */
13065 gdb_assert (b
->extra_string
!= NULL
);
13067 /* 1 - connect to target 1, that can run breakpoint commands.
13068 2 - create a dprintf, which resolves fine.
13069 3 - disconnect from target 1
13070 4 - connect to target 2, that can NOT run breakpoint commands.
13072 After steps #3/#4, you'll want the dprintf command list to
13073 be updated, because target 1 and 2 may well return different
13074 answers for target_can_run_breakpoint_commands().
13075 Given absence of finer grained resetting, we get to do
13076 it all the time. */
13077 if (b
->extra_string
!= NULL
)
13078 update_dprintf_command_list (b
);
13081 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13084 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13086 fprintf_unfiltered (fp
, "dprintf %s,%s",
13087 event_location_to_string (tp
->location
.get ()),
13089 print_recreate_thread (tp
, fp
);
13092 /* Implement the "after_condition_true" breakpoint_ops method for
13095 dprintf's are implemented with regular commands in their command
13096 list, but we run the commands here instead of before presenting the
13097 stop to the user, as dprintf's don't actually cause a stop. This
13098 also makes it so that the commands of multiple dprintfs at the same
13099 address are all handled. */
13102 dprintf_after_condition_true (struct bpstats
*bs
)
13104 struct bpstats tmp_bs
;
13105 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13107 /* dprintf's never cause a stop. This wasn't set in the
13108 check_status hook instead because that would make the dprintf's
13109 condition not be evaluated. */
13112 /* Run the command list here. Take ownership of it instead of
13113 copying. We never want these commands to run later in
13114 bpstat_do_actions, if a breakpoint that causes a stop happens to
13115 be set at same address as this dprintf, or even if running the
13116 commands here throws. */
13117 tmp_bs
.commands
= bs
->commands
;
13118 bs
->commands
= NULL
;
13120 bpstat_do_actions_1 (&tmp_bs_p
);
13122 /* 'tmp_bs.commands' will usually be NULL by now, but
13123 bpstat_do_actions_1 may return early without processing the whole
13127 /* The breakpoint_ops structure to be used on static tracepoints with
13131 strace_marker_create_sals_from_location (struct event_location
*location
,
13132 struct linespec_result
*canonical
,
13133 enum bptype type_wanted
)
13135 struct linespec_sals lsal
;
13136 const char *arg_start
, *arg
;
13138 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
13139 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13141 std::string
str (arg_start
, arg
- arg_start
);
13142 const char *ptr
= str
.c_str ();
13143 canonical
->location
13144 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
13147 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13148 canonical
->lsals
.push_back (std::move (lsal
));
13152 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13153 struct linespec_result
*canonical
,
13154 gdb::unique_xmalloc_ptr
<char> cond_string
,
13155 gdb::unique_xmalloc_ptr
<char> extra_string
,
13156 enum bptype type_wanted
,
13157 enum bpdisp disposition
,
13159 int task
, int ignore_count
,
13160 const struct breakpoint_ops
*ops
,
13161 int from_tty
, int enabled
,
13162 int internal
, unsigned flags
)
13164 const linespec_sals
&lsal
= canonical
->lsals
[0];
13166 /* If the user is creating a static tracepoint by marker id
13167 (strace -m MARKER_ID), then store the sals index, so that
13168 breakpoint_re_set can try to match up which of the newly
13169 found markers corresponds to this one, and, don't try to
13170 expand multiple locations for each sal, given than SALS
13171 already should contain all sals for MARKER_ID. */
13173 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13175 event_location_up location
13176 = copy_event_location (canonical
->location
.get ());
13178 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13179 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13180 std::move (location
), NULL
,
13181 std::move (cond_string
),
13182 std::move (extra_string
),
13183 type_wanted
, disposition
,
13184 thread
, task
, ignore_count
, ops
,
13185 from_tty
, enabled
, internal
, flags
,
13186 canonical
->special_display
);
13187 /* Given that its possible to have multiple markers with
13188 the same string id, if the user is creating a static
13189 tracepoint by marker id ("strace -m MARKER_ID"), then
13190 store the sals index, so that breakpoint_re_set can
13191 try to match up which of the newly found markers
13192 corresponds to this one */
13193 tp
->static_trace_marker_id_idx
= i
;
13195 install_breakpoint (internal
, std::move (tp
), 0);
13199 static std::vector
<symtab_and_line
>
13200 strace_marker_decode_location (struct breakpoint
*b
,
13201 struct event_location
*location
,
13202 struct program_space
*search_pspace
)
13204 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13205 const char *s
= get_linespec_location (location
)->spec_string
;
13207 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13208 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13210 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13215 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
13218 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13221 strace_marker_p (struct breakpoint
*b
)
13223 return b
->ops
== &strace_marker_breakpoint_ops
;
13226 /* Delete a breakpoint and clean up all traces of it in the data
13230 delete_breakpoint (struct breakpoint
*bpt
)
13232 gdb_assert (bpt
!= NULL
);
13234 /* Has this bp already been deleted? This can happen because
13235 multiple lists can hold pointers to bp's. bpstat lists are
13238 One example of this happening is a watchpoint's scope bp. When
13239 the scope bp triggers, we notice that the watchpoint is out of
13240 scope, and delete it. We also delete its scope bp. But the
13241 scope bp is marked "auto-deleting", and is already on a bpstat.
13242 That bpstat is then checked for auto-deleting bp's, which are
13245 A real solution to this problem might involve reference counts in
13246 bp's, and/or giving them pointers back to their referencing
13247 bpstat's, and teaching delete_breakpoint to only free a bp's
13248 storage when no more references were extent. A cheaper bandaid
13250 if (bpt
->type
== bp_none
)
13253 /* At least avoid this stale reference until the reference counting
13254 of breakpoints gets resolved. */
13255 if (bpt
->related_breakpoint
!= bpt
)
13257 struct breakpoint
*related
;
13258 struct watchpoint
*w
;
13260 if (bpt
->type
== bp_watchpoint_scope
)
13261 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13262 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13263 w
= (struct watchpoint
*) bpt
;
13267 watchpoint_del_at_next_stop (w
);
13269 /* Unlink bpt from the bpt->related_breakpoint ring. */
13270 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13271 related
= related
->related_breakpoint
);
13272 related
->related_breakpoint
= bpt
->related_breakpoint
;
13273 bpt
->related_breakpoint
= bpt
;
13276 /* watch_command_1 creates a watchpoint but only sets its number if
13277 update_watchpoint succeeds in creating its bp_locations. If there's
13278 a problem in that process, we'll be asked to delete the half-created
13279 watchpoint. In that case, don't announce the deletion. */
13281 gdb::observers::breakpoint_deleted
.notify (bpt
);
13283 if (breakpoint_chain
== bpt
)
13284 breakpoint_chain
= bpt
->next
;
13286 for (breakpoint
*b
: all_breakpoints ())
13287 if (b
->next
== bpt
)
13289 b
->next
= bpt
->next
;
13293 /* Be sure no bpstat's are pointing at the breakpoint after it's
13295 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13296 in all threads for now. Note that we cannot just remove bpstats
13297 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13298 commands are associated with the bpstat; if we remove it here,
13299 then the later call to bpstat_do_actions (&stop_bpstat); in
13300 event-top.c won't do anything, and temporary breakpoints with
13301 commands won't work. */
13303 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13305 /* Now that breakpoint is removed from breakpoint list, update the
13306 global location list. This will remove locations that used to
13307 belong to this breakpoint. Do this before freeing the breakpoint
13308 itself, since remove_breakpoint looks at location's owner. It
13309 might be better design to have location completely
13310 self-contained, but it's not the case now. */
13311 update_global_location_list (UGLL_DONT_INSERT
);
13313 /* On the chance that someone will soon try again to delete this
13314 same bp, we mark it as deleted before freeing its storage. */
13315 bpt
->type
= bp_none
;
13319 /* Iterator function to call a user-provided callback function once
13320 for each of B and its related breakpoints. */
13323 iterate_over_related_breakpoints (struct breakpoint
*b
,
13324 gdb::function_view
<void (breakpoint
*)> function
)
13326 struct breakpoint
*related
;
13331 struct breakpoint
*next
;
13333 /* FUNCTION may delete RELATED. */
13334 next
= related
->related_breakpoint
;
13336 if (next
== related
)
13338 /* RELATED is the last ring entry. */
13339 function (related
);
13341 /* FUNCTION may have deleted it, so we'd never reach back to
13342 B. There's nothing left to do anyway, so just break
13347 function (related
);
13351 while (related
!= b
);
13355 delete_command (const char *arg
, int from_tty
)
13361 int breaks_to_delete
= 0;
13363 /* Delete all breakpoints if no argument. Do not delete
13364 internal breakpoints, these have to be deleted with an
13365 explicit breakpoint number argument. */
13366 for (breakpoint
*b
: all_breakpoints ())
13367 if (user_breakpoint_p (b
))
13369 breaks_to_delete
= 1;
13373 /* Ask user only if there are some breakpoints to delete. */
13375 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13376 for (breakpoint
*b
: all_breakpoints_safe ())
13377 if (user_breakpoint_p (b
))
13378 delete_breakpoint (b
);
13381 map_breakpoint_numbers
13382 (arg
, [&] (breakpoint
*br
)
13384 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13388 /* Return true if all locations of B bound to PSPACE are pending. If
13389 PSPACE is NULL, all locations of all program spaces are
13393 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13395 for (bp_location
*loc
: b
->locations ())
13396 if ((pspace
== NULL
13397 || loc
->pspace
== pspace
)
13398 && !loc
->shlib_disabled
13399 && !loc
->pspace
->executing_startup
)
13404 /* Subroutine of update_breakpoint_locations to simplify it.
13405 Return non-zero if multiple fns in list LOC have the same name.
13406 Null names are ignored. */
13409 ambiguous_names_p (struct bp_location
*loc
)
13411 struct bp_location
*l
;
13412 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
13415 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13418 const char *name
= l
->function_name
;
13420 /* Allow for some names to be NULL, ignore them. */
13424 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
13426 /* NOTE: We can assume slot != NULL here because xcalloc never
13436 /* When symbols change, it probably means the sources changed as well,
13437 and it might mean the static tracepoint markers are no longer at
13438 the same address or line numbers they used to be at last we
13439 checked. Losing your static tracepoints whenever you rebuild is
13440 undesirable. This function tries to resync/rematch gdb static
13441 tracepoints with the markers on the target, for static tracepoints
13442 that have not been set by marker id. Static tracepoint that have
13443 been set by marker id are reset by marker id in breakpoint_re_set.
13446 1) For a tracepoint set at a specific address, look for a marker at
13447 the old PC. If one is found there, assume to be the same marker.
13448 If the name / string id of the marker found is different from the
13449 previous known name, assume that means the user renamed the marker
13450 in the sources, and output a warning.
13452 2) For a tracepoint set at a given line number, look for a marker
13453 at the new address of the old line number. If one is found there,
13454 assume to be the same marker. If the name / string id of the
13455 marker found is different from the previous known name, assume that
13456 means the user renamed the marker in the sources, and output a
13459 3) If a marker is no longer found at the same address or line, it
13460 may mean the marker no longer exists. But it may also just mean
13461 the code changed a bit. Maybe the user added a few lines of code
13462 that made the marker move up or down (in line number terms). Ask
13463 the target for info about the marker with the string id as we knew
13464 it. If found, update line number and address in the matching
13465 static tracepoint. This will get confused if there's more than one
13466 marker with the same ID (possible in UST, although unadvised
13467 precisely because it confuses tools). */
13469 static struct symtab_and_line
13470 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13472 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13473 struct static_tracepoint_marker marker
;
13478 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13480 if (target_static_tracepoint_marker_at (pc
, &marker
))
13482 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13483 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13484 b
->number
, tp
->static_trace_marker_id
.c_str (),
13485 marker
.str_id
.c_str ());
13487 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13492 /* Old marker wasn't found on target at lineno. Try looking it up
13494 if (!sal
.explicit_pc
13496 && sal
.symtab
!= NULL
13497 && !tp
->static_trace_marker_id
.empty ())
13499 std::vector
<static_tracepoint_marker
> markers
13500 = target_static_tracepoint_markers_by_strid
13501 (tp
->static_trace_marker_id
.c_str ());
13503 if (!markers
.empty ())
13505 struct symbol
*sym
;
13506 struct static_tracepoint_marker
*tpmarker
;
13507 struct ui_out
*uiout
= current_uiout
;
13508 struct explicit_location explicit_loc
;
13510 tpmarker
= &markers
[0];
13512 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13514 warning (_("marker for static tracepoint %d (%s) not "
13515 "found at previous line number"),
13516 b
->number
, tp
->static_trace_marker_id
.c_str ());
13518 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13519 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13520 uiout
->text ("Now in ");
13523 uiout
->field_string ("func", sym
->print_name (),
13524 function_name_style
.style ());
13525 uiout
->text (" at ");
13527 uiout
->field_string ("file",
13528 symtab_to_filename_for_display (sal2
.symtab
),
13529 file_name_style
.style ());
13532 if (uiout
->is_mi_like_p ())
13534 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13536 uiout
->field_string ("fullname", fullname
);
13539 uiout
->field_signed ("line", sal2
.line
);
13540 uiout
->text ("\n");
13542 b
->loc
->line_number
= sal2
.line
;
13543 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13545 b
->location
.reset (NULL
);
13546 initialize_explicit_location (&explicit_loc
);
13547 explicit_loc
.source_filename
13548 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13549 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13550 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13551 b
->location
= new_explicit_location (&explicit_loc
);
13553 /* Might be nice to check if function changed, and warn if
13560 /* Returns 1 iff locations A and B are sufficiently same that
13561 we don't need to report breakpoint as changed. */
13564 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13568 if (a
->address
!= b
->address
)
13571 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13574 if (a
->enabled
!= b
->enabled
)
13577 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
13584 if ((a
== NULL
) != (b
== NULL
))
13590 /* Split all locations of B that are bound to PSPACE out of B's
13591 location list to a separate list and return that list's head. If
13592 PSPACE is NULL, hoist out all locations of B. */
13594 static struct bp_location
*
13595 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13597 struct bp_location head
;
13598 struct bp_location
*i
= b
->loc
;
13599 struct bp_location
**i_link
= &b
->loc
;
13600 struct bp_location
*hoisted
= &head
;
13602 if (pspace
== NULL
)
13613 if (i
->pspace
== pspace
)
13628 /* Create new breakpoint locations for B (a hardware or software
13629 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13630 zero, then B is a ranged breakpoint. Only recreates locations for
13631 FILTER_PSPACE. Locations of other program spaces are left
13635 update_breakpoint_locations (struct breakpoint
*b
,
13636 struct program_space
*filter_pspace
,
13637 gdb::array_view
<const symtab_and_line
> sals
,
13638 gdb::array_view
<const symtab_and_line
> sals_end
)
13640 struct bp_location
*existing_locations
;
13642 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13644 /* Ranged breakpoints have only one start location and one end
13646 b
->enable_state
= bp_disabled
;
13647 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13648 "multiple locations found\n"),
13653 /* If there's no new locations, and all existing locations are
13654 pending, don't do anything. This optimizes the common case where
13655 all locations are in the same shared library, that was unloaded.
13656 We'd like to retain the location, so that when the library is
13657 loaded again, we don't loose the enabled/disabled status of the
13658 individual locations. */
13659 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13662 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13664 for (const auto &sal
: sals
)
13666 struct bp_location
*new_loc
;
13668 switch_to_program_space_and_thread (sal
.pspace
);
13670 new_loc
= add_location_to_breakpoint (b
, &sal
);
13672 /* Reparse conditions, they might contain references to the
13674 if (b
->cond_string
!= NULL
)
13678 s
= b
->cond_string
;
13681 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13682 block_for_pc (sal
.pc
),
13685 catch (const gdb_exception_error
&e
)
13687 new_loc
->disabled_by_cond
= true;
13691 if (!sals_end
.empty ())
13693 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13695 new_loc
->length
= end
- sals
[0].pc
+ 1;
13699 /* If possible, carry over 'disable' status from existing
13702 struct bp_location
*e
= existing_locations
;
13703 /* If there are multiple breakpoints with the same function name,
13704 e.g. for inline functions, comparing function names won't work.
13705 Instead compare pc addresses; this is just a heuristic as things
13706 may have moved, but in practice it gives the correct answer
13707 often enough until a better solution is found. */
13708 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13710 for (; e
; e
= e
->next
)
13712 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
13714 if (have_ambiguous_names
)
13716 for (bp_location
*l
: b
->locations ())
13718 /* Ignore software vs hardware location type at
13719 this point, because with "set breakpoint
13720 auto-hw", after a re-set, locations that were
13721 hardware can end up as software, or vice versa.
13722 As mentioned above, this is an heuristic and in
13723 practice should give the correct answer often
13725 if (breakpoint_locations_match (e
, l
, true))
13727 l
->enabled
= e
->enabled
;
13728 l
->disabled_by_cond
= e
->disabled_by_cond
;
13735 for (bp_location
*l
: b
->locations ())
13736 if (l
->function_name
13737 && strcmp (e
->function_name
, l
->function_name
) == 0)
13739 l
->enabled
= e
->enabled
;
13740 l
->disabled_by_cond
= e
->disabled_by_cond
;
13748 if (!locations_are_equal (existing_locations
, b
->loc
))
13749 gdb::observers::breakpoint_modified
.notify (b
);
13752 /* Find the SaL locations corresponding to the given LOCATION.
13753 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13755 static std::vector
<symtab_and_line
>
13756 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13757 struct program_space
*search_pspace
, int *found
)
13759 struct gdb_exception exception
;
13761 gdb_assert (b
->ops
!= NULL
);
13763 std::vector
<symtab_and_line
> sals
;
13767 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13769 catch (gdb_exception_error
&e
)
13771 int not_found_and_ok
= 0;
13773 /* For pending breakpoints, it's expected that parsing will
13774 fail until the right shared library is loaded. User has
13775 already told to create pending breakpoints and don't need
13776 extra messages. If breakpoint is in bp_shlib_disabled
13777 state, then user already saw the message about that
13778 breakpoint being disabled, and don't want to see more
13780 if (e
.error
== NOT_FOUND_ERROR
13781 && (b
->condition_not_parsed
13783 && search_pspace
!= NULL
13784 && b
->loc
->pspace
!= search_pspace
)
13785 || (b
->loc
&& b
->loc
->shlib_disabled
)
13786 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13787 || b
->enable_state
== bp_disabled
))
13788 not_found_and_ok
= 1;
13790 if (!not_found_and_ok
)
13792 /* We surely don't want to warn about the same breakpoint
13793 10 times. One solution, implemented here, is disable
13794 the breakpoint on error. Another solution would be to
13795 have separate 'warning emitted' flag. Since this
13796 happens only when a binary has changed, I don't know
13797 which approach is better. */
13798 b
->enable_state
= bp_disabled
;
13802 exception
= std::move (e
);
13805 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13807 for (auto &sal
: sals
)
13808 resolve_sal_pc (&sal
);
13809 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13811 char *cond_string
, *extra_string
;
13814 find_condition_and_thread_for_sals (sals
, b
->extra_string
,
13815 &cond_string
, &thread
,
13816 &task
, &extra_string
);
13817 gdb_assert (b
->cond_string
== NULL
);
13819 b
->cond_string
= cond_string
;
13820 b
->thread
= thread
;
13824 xfree (b
->extra_string
);
13825 b
->extra_string
= extra_string
;
13827 b
->condition_not_parsed
= 0;
13830 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13831 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13841 /* The default re_set method, for typical hardware or software
13842 breakpoints. Reevaluate the breakpoint and recreate its
13846 breakpoint_re_set_default (struct breakpoint
*b
)
13848 struct program_space
*filter_pspace
= current_program_space
;
13849 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13852 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13853 filter_pspace
, &found
);
13855 expanded
= std::move (sals
);
13857 if (b
->location_range_end
!= NULL
)
13859 std::vector
<symtab_and_line
> sals_end
13860 = location_to_sals (b
, b
->location_range_end
.get (),
13861 filter_pspace
, &found
);
13863 expanded_end
= std::move (sals_end
);
13866 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13869 /* Default method for creating SALs from an address string. It basically
13870 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13873 create_sals_from_location_default (struct event_location
*location
,
13874 struct linespec_result
*canonical
,
13875 enum bptype type_wanted
)
13877 parse_breakpoint_sals (location
, canonical
);
13880 /* Call create_breakpoints_sal for the given arguments. This is the default
13881 function for the `create_breakpoints_sal' method of
13885 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13886 struct linespec_result
*canonical
,
13887 gdb::unique_xmalloc_ptr
<char> cond_string
,
13888 gdb::unique_xmalloc_ptr
<char> extra_string
,
13889 enum bptype type_wanted
,
13890 enum bpdisp disposition
,
13892 int task
, int ignore_count
,
13893 const struct breakpoint_ops
*ops
,
13894 int from_tty
, int enabled
,
13895 int internal
, unsigned flags
)
13897 create_breakpoints_sal (gdbarch
, canonical
,
13898 std::move (cond_string
),
13899 std::move (extra_string
),
13900 type_wanted
, disposition
,
13901 thread
, task
, ignore_count
, ops
, from_tty
,
13902 enabled
, internal
, flags
);
13905 /* Decode the line represented by S by calling decode_line_full. This is the
13906 default function for the `decode_location' method of breakpoint_ops. */
13908 static std::vector
<symtab_and_line
>
13909 decode_location_default (struct breakpoint
*b
,
13910 struct event_location
*location
,
13911 struct program_space
*search_pspace
)
13913 struct linespec_result canonical
;
13915 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13916 NULL
, 0, &canonical
, multiple_symbols_all
,
13919 /* We should get 0 or 1 resulting SALs. */
13920 gdb_assert (canonical
.lsals
.size () < 2);
13922 if (!canonical
.lsals
.empty ())
13924 const linespec_sals
&lsal
= canonical
.lsals
[0];
13925 return std::move (lsal
.sals
);
13930 /* Reset a breakpoint. */
13933 breakpoint_re_set_one (breakpoint
*b
)
13935 input_radix
= b
->input_radix
;
13936 set_language (b
->language
);
13938 b
->ops
->re_set (b
);
13941 /* Re-set breakpoint locations for the current program space.
13942 Locations bound to other program spaces are left untouched. */
13945 breakpoint_re_set (void)
13948 scoped_restore_current_language save_language
;
13949 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13950 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13952 /* breakpoint_re_set_one sets the current_language to the language
13953 of the breakpoint it is resetting (see prepare_re_set_context)
13954 before re-evaluating the breakpoint's location. This change can
13955 unfortunately get undone by accident if the language_mode is set
13956 to auto, and we either switch frames, or more likely in this context,
13957 we select the current frame.
13959 We prevent this by temporarily turning the language_mode to
13960 language_mode_manual. We restore it once all breakpoints
13961 have been reset. */
13962 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13963 language_mode
= language_mode_manual
;
13965 /* Note: we must not try to insert locations until after all
13966 breakpoints have been re-set. Otherwise, e.g., when re-setting
13967 breakpoint 1, we'd insert the locations of breakpoint 2, which
13968 hadn't been re-set yet, and thus may have stale locations. */
13970 for (breakpoint
*b
: all_breakpoints_safe ())
13974 breakpoint_re_set_one (b
);
13976 catch (const gdb_exception
&ex
)
13978 exception_fprintf (gdb_stderr
, ex
,
13979 "Error in re-setting breakpoint %d: ",
13984 jit_breakpoint_re_set ();
13987 create_overlay_event_breakpoint ();
13988 create_longjmp_master_breakpoint ();
13989 create_std_terminate_master_breakpoint ();
13990 create_exception_master_breakpoint ();
13992 /* Now we can insert. */
13993 update_global_location_list (UGLL_MAY_INSERT
);
13996 /* Reset the thread number of this breakpoint:
13998 - If the breakpoint is for all threads, leave it as-is.
13999 - Else, reset it to the current thread for inferior_ptid. */
14001 breakpoint_re_set_thread (struct breakpoint
*b
)
14003 if (b
->thread
!= -1)
14005 b
->thread
= inferior_thread ()->global_num
;
14007 /* We're being called after following a fork. The new fork is
14008 selected as current, and unless this was a vfork will have a
14009 different program space from the original thread. Reset that
14011 b
->loc
->pspace
= current_program_space
;
14015 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14016 If from_tty is nonzero, it prints a message to that effect,
14017 which ends with a period (no newline). */
14020 set_ignore_count (int bptnum
, int count
, int from_tty
)
14025 for (breakpoint
*b
: all_breakpoints ())
14026 if (b
->number
== bptnum
)
14028 if (is_tracepoint (b
))
14030 if (from_tty
&& count
!= 0)
14031 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14036 b
->ignore_count
= count
;
14040 printf_filtered (_("Will stop next time "
14041 "breakpoint %d is reached."),
14043 else if (count
== 1)
14044 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14047 printf_filtered (_("Will ignore next %d "
14048 "crossings of breakpoint %d."),
14051 gdb::observers::breakpoint_modified
.notify (b
);
14055 error (_("No breakpoint number %d."), bptnum
);
14058 /* Command to set ignore-count of breakpoint N to COUNT. */
14061 ignore_command (const char *args
, int from_tty
)
14063 const char *p
= args
;
14067 error_no_arg (_("a breakpoint number"));
14069 num
= get_number (&p
);
14071 error (_("bad breakpoint number: '%s'"), args
);
14073 error (_("Second argument (specified ignore-count) is missing."));
14075 set_ignore_count (num
,
14076 longest_to_int (value_as_long (parse_and_eval (p
))),
14079 printf_filtered ("\n");
14083 /* Call FUNCTION on each of the breakpoints with numbers in the range
14084 defined by BP_NUM_RANGE (an inclusive range). */
14087 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
14088 gdb::function_view
<void (breakpoint
*)> function
)
14090 if (bp_num_range
.first
== 0)
14092 warning (_("bad breakpoint number at or near '%d'"),
14093 bp_num_range
.first
);
14097 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
14099 bool match
= false;
14101 for (breakpoint
*b
: all_breakpoints_safe ())
14102 if (b
->number
== i
)
14109 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
14114 /* Call FUNCTION on each of the breakpoints whose numbers are given in
14118 map_breakpoint_numbers (const char *args
,
14119 gdb::function_view
<void (breakpoint
*)> function
)
14121 if (args
== NULL
|| *args
== '\0')
14122 error_no_arg (_("one or more breakpoint numbers"));
14124 number_or_range_parser
parser (args
);
14126 while (!parser
.finished ())
14128 int num
= parser
.get_number ();
14129 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
14133 /* Return the breakpoint location structure corresponding to the
14134 BP_NUM and LOC_NUM values. */
14136 static struct bp_location
*
14137 find_location_by_number (int bp_num
, int loc_num
)
14139 breakpoint
*b
= get_breakpoint (bp_num
);
14141 if (!b
|| b
->number
!= bp_num
)
14142 error (_("Bad breakpoint number '%d'"), bp_num
);
14145 error (_("Bad breakpoint location number '%d'"), loc_num
);
14148 for (bp_location
*loc
: b
->locations ())
14149 if (++n
== loc_num
)
14152 error (_("Bad breakpoint location number '%d'"), loc_num
);
14155 /* Modes of operation for extract_bp_num. */
14156 enum class extract_bp_kind
14158 /* Extracting a breakpoint number. */
14161 /* Extracting a location number. */
14165 /* Extract a breakpoint or location number (as determined by KIND)
14166 from the string starting at START. TRAILER is a character which
14167 can be found after the number. If you don't want a trailer, use
14168 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14169 string. This always returns a positive integer. */
14172 extract_bp_num (extract_bp_kind kind
, const char *start
,
14173 int trailer
, const char **end_out
= NULL
)
14175 const char *end
= start
;
14176 int num
= get_number_trailer (&end
, trailer
);
14178 error (kind
== extract_bp_kind::bp
14179 ? _("Negative breakpoint number '%.*s'")
14180 : _("Negative breakpoint location number '%.*s'"),
14181 int (end
- start
), start
);
14183 error (kind
== extract_bp_kind::bp
14184 ? _("Bad breakpoint number '%.*s'")
14185 : _("Bad breakpoint location number '%.*s'"),
14186 int (end
- start
), start
);
14188 if (end_out
!= NULL
)
14193 /* Extract a breakpoint or location range (as determined by KIND) in
14194 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14195 representing the (inclusive) range. The returned pair's elements
14196 are always positive integers. */
14198 static std::pair
<int, int>
14199 extract_bp_or_bp_range (extract_bp_kind kind
,
14200 const std::string
&arg
,
14201 std::string::size_type arg_offset
)
14203 std::pair
<int, int> range
;
14204 const char *bp_loc
= &arg
[arg_offset
];
14205 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14206 if (dash
!= std::string::npos
)
14208 /* bp_loc is a range (x-z). */
14209 if (arg
.length () == dash
+ 1)
14210 error (kind
== extract_bp_kind::bp
14211 ? _("Bad breakpoint number at or near: '%s'")
14212 : _("Bad breakpoint location number at or near: '%s'"),
14216 const char *start_first
= bp_loc
;
14217 const char *start_second
= &arg
[dash
+ 1];
14218 range
.first
= extract_bp_num (kind
, start_first
, '-');
14219 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14221 if (range
.first
> range
.second
)
14222 error (kind
== extract_bp_kind::bp
14223 ? _("Inverted breakpoint range at '%.*s'")
14224 : _("Inverted breakpoint location range at '%.*s'"),
14225 int (end
- start_first
), start_first
);
14229 /* bp_loc is a single value. */
14230 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14231 range
.second
= range
.first
;
14236 /* Extract the breakpoint/location range specified by ARG. Returns
14237 the breakpoint range in BP_NUM_RANGE, and the location range in
14240 ARG may be in any of the following forms:
14242 x where 'x' is a breakpoint number.
14243 x-y where 'x' and 'y' specify a breakpoint numbers range.
14244 x.y where 'x' is a breakpoint number and 'y' a location number.
14245 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14246 location number range.
14250 extract_bp_number_and_location (const std::string
&arg
,
14251 std::pair
<int, int> &bp_num_range
,
14252 std::pair
<int, int> &bp_loc_range
)
14254 std::string::size_type dot
= arg
.find ('.');
14256 if (dot
!= std::string::npos
)
14258 /* Handle 'x.y' and 'x.y-z' cases. */
14260 if (arg
.length () == dot
+ 1 || dot
== 0)
14261 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14264 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14265 bp_num_range
.second
= bp_num_range
.first
;
14267 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14272 /* Handle x and x-y cases. */
14274 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14275 bp_loc_range
.first
= 0;
14276 bp_loc_range
.second
= 0;
14280 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14281 specifies whether to enable or disable. */
14284 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14286 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14289 if (loc
->disabled_by_cond
&& enable
)
14290 error (_("Breakpoint %d's condition is invalid at location %d, "
14291 "cannot enable."), bp_num
, loc_num
);
14293 if (loc
->enabled
!= enable
)
14295 loc
->enabled
= enable
;
14296 mark_breakpoint_location_modified (loc
);
14298 if (target_supports_enable_disable_tracepoint ()
14299 && current_trace_status ()->running
&& loc
->owner
14300 && is_tracepoint (loc
->owner
))
14301 target_disable_tracepoint (loc
);
14303 update_global_location_list (UGLL_DONT_INSERT
);
14305 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14308 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14309 number of the breakpoint, and BP_LOC_RANGE specifies the
14310 (inclusive) range of location numbers of that breakpoint to
14311 enable/disable. ENABLE specifies whether to enable or disable the
14315 enable_disable_breakpoint_location_range (int bp_num
,
14316 std::pair
<int, int> &bp_loc_range
,
14319 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14320 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14323 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14324 If from_tty is nonzero, it prints a message to that effect,
14325 which ends with a period (no newline). */
14328 disable_breakpoint (struct breakpoint
*bpt
)
14330 /* Never disable a watchpoint scope breakpoint; we want to
14331 hit them when we leave scope so we can delete both the
14332 watchpoint and its scope breakpoint at that time. */
14333 if (bpt
->type
== bp_watchpoint_scope
)
14336 bpt
->enable_state
= bp_disabled
;
14338 /* Mark breakpoint locations modified. */
14339 mark_breakpoint_modified (bpt
);
14341 if (target_supports_enable_disable_tracepoint ()
14342 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14344 for (bp_location
*location
: bpt
->locations ())
14345 target_disable_tracepoint (location
);
14348 update_global_location_list (UGLL_DONT_INSERT
);
14350 gdb::observers::breakpoint_modified
.notify (bpt
);
14353 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14354 specified in ARGS. ARGS may be in any of the formats handled by
14355 extract_bp_number_and_location. ENABLE specifies whether to enable
14356 or disable the breakpoints/locations. */
14359 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14363 for (breakpoint
*bpt
: all_breakpoints ())
14364 if (user_breakpoint_p (bpt
))
14367 enable_breakpoint (bpt
);
14369 disable_breakpoint (bpt
);
14374 std::string num
= extract_arg (&args
);
14376 while (!num
.empty ())
14378 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14380 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14382 if (bp_loc_range
.first
== bp_loc_range
.second
14383 && bp_loc_range
.first
== 0)
14385 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14386 map_breakpoint_number_range (bp_num_range
,
14388 ? enable_breakpoint
14389 : disable_breakpoint
);
14393 /* Handle breakpoint ids with formats 'x.y' or
14395 enable_disable_breakpoint_location_range
14396 (bp_num_range
.first
, bp_loc_range
, enable
);
14398 num
= extract_arg (&args
);
14403 /* The disable command disables the specified breakpoints/locations
14404 (or all defined breakpoints) so they're no longer effective in
14405 stopping the inferior. ARGS may be in any of the forms defined in
14406 extract_bp_number_and_location. */
14409 disable_command (const char *args
, int from_tty
)
14411 enable_disable_command (args
, from_tty
, false);
14415 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14418 int target_resources_ok
;
14420 if (bpt
->type
== bp_hardware_breakpoint
)
14423 i
= hw_breakpoint_used_count ();
14424 target_resources_ok
=
14425 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14427 if (target_resources_ok
== 0)
14428 error (_("No hardware breakpoint support in the target."));
14429 else if (target_resources_ok
< 0)
14430 error (_("Hardware breakpoints used exceeds limit."));
14433 if (is_watchpoint (bpt
))
14435 /* Initialize it just to avoid a GCC false warning. */
14436 enum enable_state orig_enable_state
= bp_disabled
;
14440 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14442 orig_enable_state
= bpt
->enable_state
;
14443 bpt
->enable_state
= bp_enabled
;
14444 update_watchpoint (w
, 1 /* reparse */);
14446 catch (const gdb_exception
&e
)
14448 bpt
->enable_state
= orig_enable_state
;
14449 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14455 bpt
->enable_state
= bp_enabled
;
14457 /* Mark breakpoint locations modified. */
14458 mark_breakpoint_modified (bpt
);
14460 if (target_supports_enable_disable_tracepoint ()
14461 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14463 for (bp_location
*location
: bpt
->locations ())
14464 target_enable_tracepoint (location
);
14467 bpt
->disposition
= disposition
;
14468 bpt
->enable_count
= count
;
14469 update_global_location_list (UGLL_MAY_INSERT
);
14471 gdb::observers::breakpoint_modified
.notify (bpt
);
14476 enable_breakpoint (struct breakpoint
*bpt
)
14478 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14481 /* The enable command enables the specified breakpoints/locations (or
14482 all defined breakpoints) so they once again become (or continue to
14483 be) effective in stopping the inferior. ARGS may be in any of the
14484 forms defined in extract_bp_number_and_location. */
14487 enable_command (const char *args
, int from_tty
)
14489 enable_disable_command (args
, from_tty
, true);
14493 enable_once_command (const char *args
, int from_tty
)
14495 map_breakpoint_numbers
14496 (args
, [&] (breakpoint
*b
)
14498 iterate_over_related_breakpoints
14499 (b
, [&] (breakpoint
*bpt
)
14501 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14507 enable_count_command (const char *args
, int from_tty
)
14512 error_no_arg (_("hit count"));
14514 count
= get_number (&args
);
14516 map_breakpoint_numbers
14517 (args
, [&] (breakpoint
*b
)
14519 iterate_over_related_breakpoints
14520 (b
, [&] (breakpoint
*bpt
)
14522 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14528 enable_delete_command (const char *args
, int from_tty
)
14530 map_breakpoint_numbers
14531 (args
, [&] (breakpoint
*b
)
14533 iterate_over_related_breakpoints
14534 (b
, [&] (breakpoint
*bpt
)
14536 enable_breakpoint_disp (bpt
, disp_del
, 1);
14541 /* Invalidate last known value of any hardware watchpoint if
14542 the memory which that value represents has been written to by
14546 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14547 CORE_ADDR addr
, ssize_t len
,
14548 const bfd_byte
*data
)
14550 for (breakpoint
*bp
: all_breakpoints ())
14551 if (bp
->enable_state
== bp_enabled
14552 && bp
->type
== bp_hardware_watchpoint
)
14554 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14556 if (wp
->val_valid
&& wp
->val
!= nullptr)
14558 for (bp_location
*loc
: bp
->locations ())
14559 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14560 && loc
->address
+ loc
->length
> addr
14561 && addr
+ len
> loc
->address
)
14564 wp
->val_valid
= false;
14570 /* Create and insert a breakpoint for software single step. */
14573 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14574 const address_space
*aspace
,
14577 struct thread_info
*tp
= inferior_thread ();
14578 struct symtab_and_line sal
;
14579 CORE_ADDR pc
= next_pc
;
14581 if (tp
->control
.single_step_breakpoints
== NULL
)
14583 tp
->control
.single_step_breakpoints
14584 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14587 sal
= find_pc_line (pc
, 0);
14589 sal
.section
= find_pc_overlay (pc
);
14590 sal
.explicit_pc
= 1;
14591 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14593 update_global_location_list (UGLL_INSERT
);
14596 /* Insert single step breakpoints according to the current state. */
14599 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14601 struct regcache
*regcache
= get_current_regcache ();
14602 std::vector
<CORE_ADDR
> next_pcs
;
14604 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14606 if (!next_pcs
.empty ())
14608 struct frame_info
*frame
= get_current_frame ();
14609 const address_space
*aspace
= get_frame_address_space (frame
);
14611 for (CORE_ADDR pc
: next_pcs
)
14612 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14620 /* See breakpoint.h. */
14623 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14624 const address_space
*aspace
,
14627 for (bp_location
*loc
: bp
->locations ())
14629 && breakpoint_location_address_match (loc
, aspace
, pc
))
14635 /* Check whether a software single-step breakpoint is inserted at
14639 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14642 for (breakpoint
*bpt
: all_breakpoints ())
14644 if (bpt
->type
== bp_single_step
14645 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14651 /* Tracepoint-specific operations. */
14653 /* Set tracepoint count to NUM. */
14655 set_tracepoint_count (int num
)
14657 tracepoint_count
= num
;
14658 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14662 trace_command (const char *arg
, int from_tty
)
14664 event_location_up location
= string_to_event_location (&arg
,
14666 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
14667 (location
.get (), true /* is_tracepoint */);
14669 create_breakpoint (get_current_arch (),
14671 NULL
, 0, arg
, false, 1 /* parse arg */,
14673 bp_tracepoint
/* type_wanted */,
14674 0 /* Ignore count */,
14675 pending_break_support
,
14679 0 /* internal */, 0);
14683 ftrace_command (const char *arg
, int from_tty
)
14685 event_location_up location
= string_to_event_location (&arg
,
14687 create_breakpoint (get_current_arch (),
14689 NULL
, 0, arg
, false, 1 /* parse arg */,
14691 bp_fast_tracepoint
/* type_wanted */,
14692 0 /* Ignore count */,
14693 pending_break_support
,
14694 &tracepoint_breakpoint_ops
,
14697 0 /* internal */, 0);
14700 /* strace command implementation. Creates a static tracepoint. */
14703 strace_command (const char *arg
, int from_tty
)
14705 struct breakpoint_ops
*ops
;
14706 event_location_up location
;
14708 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14709 or with a normal static tracepoint. */
14710 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14712 ops
= &strace_marker_breakpoint_ops
;
14713 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14717 ops
= &tracepoint_breakpoint_ops
;
14718 location
= string_to_event_location (&arg
, current_language
);
14721 create_breakpoint (get_current_arch (),
14723 NULL
, 0, arg
, false, 1 /* parse arg */,
14725 bp_static_tracepoint
/* type_wanted */,
14726 0 /* Ignore count */,
14727 pending_break_support
,
14731 0 /* internal */, 0);
14734 /* Set up a fake reader function that gets command lines from a linked
14735 list that was acquired during tracepoint uploading. */
14737 static struct uploaded_tp
*this_utp
;
14738 static int next_cmd
;
14741 read_uploaded_action (void)
14743 char *rslt
= nullptr;
14745 if (next_cmd
< this_utp
->cmd_strings
.size ())
14747 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14754 /* Given information about a tracepoint as recorded on a target (which
14755 can be either a live system or a trace file), attempt to create an
14756 equivalent GDB tracepoint. This is not a reliable process, since
14757 the target does not necessarily have all the information used when
14758 the tracepoint was originally defined. */
14760 struct tracepoint
*
14761 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14763 const char *addr_str
;
14764 char small_buf
[100];
14765 struct tracepoint
*tp
;
14767 if (utp
->at_string
)
14768 addr_str
= utp
->at_string
.get ();
14771 /* In the absence of a source location, fall back to raw
14772 address. Since there is no way to confirm that the address
14773 means the same thing as when the trace was started, warn the
14775 warning (_("Uploaded tracepoint %d has no "
14776 "source location, using raw address"),
14778 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14779 addr_str
= small_buf
;
14782 /* There's not much we can do with a sequence of bytecodes. */
14783 if (utp
->cond
&& !utp
->cond_string
)
14784 warning (_("Uploaded tracepoint %d condition "
14785 "has no source form, ignoring it"),
14788 event_location_up location
= string_to_event_location (&addr_str
,
14790 if (!create_breakpoint (get_current_arch (),
14792 utp
->cond_string
.get (), -1, addr_str
,
14793 false /* force_condition */,
14794 0 /* parse cond/thread */,
14796 utp
->type
/* type_wanted */,
14797 0 /* Ignore count */,
14798 pending_break_support
,
14799 &tracepoint_breakpoint_ops
,
14801 utp
->enabled
/* enabled */,
14803 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14806 /* Get the tracepoint we just created. */
14807 tp
= get_tracepoint (tracepoint_count
);
14808 gdb_assert (tp
!= NULL
);
14812 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14815 trace_pass_command (small_buf
, 0);
14818 /* If we have uploaded versions of the original commands, set up a
14819 special-purpose "reader" function and call the usual command line
14820 reader, then pass the result to the breakpoint command-setting
14822 if (!utp
->cmd_strings
.empty ())
14824 counted_command_line cmd_list
;
14829 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14831 breakpoint_set_commands (tp
, std::move (cmd_list
));
14833 else if (!utp
->actions
.empty ()
14834 || !utp
->step_actions
.empty ())
14835 warning (_("Uploaded tracepoint %d actions "
14836 "have no source form, ignoring them"),
14839 /* Copy any status information that might be available. */
14840 tp
->hit_count
= utp
->hit_count
;
14841 tp
->traceframe_usage
= utp
->traceframe_usage
;
14846 /* Print information on tracepoint number TPNUM_EXP, or all if
14850 info_tracepoints_command (const char *args
, int from_tty
)
14852 struct ui_out
*uiout
= current_uiout
;
14855 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14857 if (num_printed
== 0)
14859 if (args
== NULL
|| *args
== '\0')
14860 uiout
->message ("No tracepoints.\n");
14862 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14865 default_collect_info ();
14868 /* The 'enable trace' command enables tracepoints.
14869 Not supported by all targets. */
14871 enable_trace_command (const char *args
, int from_tty
)
14873 enable_command (args
, from_tty
);
14876 /* The 'disable trace' command disables tracepoints.
14877 Not supported by all targets. */
14879 disable_trace_command (const char *args
, int from_tty
)
14881 disable_command (args
, from_tty
);
14884 /* Remove a tracepoint (or all if no argument). */
14886 delete_trace_command (const char *arg
, int from_tty
)
14892 int breaks_to_delete
= 0;
14894 /* Delete all breakpoints if no argument.
14895 Do not delete internal or call-dummy breakpoints, these
14896 have to be deleted with an explicit breakpoint number
14898 for (breakpoint
*tp
: all_tracepoints ())
14899 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
14901 breaks_to_delete
= 1;
14905 /* Ask user only if there are some breakpoints to delete. */
14907 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14909 for (breakpoint
*b
: all_breakpoints_safe ())
14910 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14911 delete_breakpoint (b
);
14915 map_breakpoint_numbers
14916 (arg
, [&] (breakpoint
*br
)
14918 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14922 /* Helper function for trace_pass_command. */
14925 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14927 tp
->pass_count
= count
;
14928 gdb::observers::breakpoint_modified
.notify (tp
);
14930 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14931 tp
->number
, count
);
14934 /* Set passcount for tracepoint.
14936 First command argument is passcount, second is tracepoint number.
14937 If tracepoint number omitted, apply to most recently defined.
14938 Also accepts special argument "all". */
14941 trace_pass_command (const char *args
, int from_tty
)
14943 struct tracepoint
*t1
;
14946 if (args
== 0 || *args
== 0)
14947 error (_("passcount command requires an "
14948 "argument (count + optional TP num)"));
14950 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14952 args
= skip_spaces (args
);
14953 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14955 args
+= 3; /* Skip special argument "all". */
14957 error (_("Junk at end of arguments."));
14959 for (breakpoint
*b
: all_tracepoints ())
14961 t1
= (struct tracepoint
*) b
;
14962 trace_pass_set_count (t1
, count
, from_tty
);
14965 else if (*args
== '\0')
14967 t1
= get_tracepoint_by_number (&args
, NULL
);
14969 trace_pass_set_count (t1
, count
, from_tty
);
14973 number_or_range_parser
parser (args
);
14974 while (!parser
.finished ())
14976 t1
= get_tracepoint_by_number (&args
, &parser
);
14978 trace_pass_set_count (t1
, count
, from_tty
);
14983 struct tracepoint
*
14984 get_tracepoint (int num
)
14986 for (breakpoint
*t
: all_tracepoints ())
14987 if (t
->number
== num
)
14988 return (struct tracepoint
*) t
;
14993 /* Find the tracepoint with the given target-side number (which may be
14994 different from the tracepoint number after disconnecting and
14997 struct tracepoint
*
14998 get_tracepoint_by_number_on_target (int num
)
15000 for (breakpoint
*b
: all_tracepoints ())
15002 struct tracepoint
*t
= (struct tracepoint
*) b
;
15004 if (t
->number_on_target
== num
)
15011 /* Utility: parse a tracepoint number and look it up in the list.
15012 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15013 If the argument is missing, the most recent tracepoint
15014 (tracepoint_count) is returned. */
15016 struct tracepoint
*
15017 get_tracepoint_by_number (const char **arg
,
15018 number_or_range_parser
*parser
)
15021 const char *instring
= arg
== NULL
? NULL
: *arg
;
15023 if (parser
!= NULL
)
15025 gdb_assert (!parser
->finished ());
15026 tpnum
= parser
->get_number ();
15028 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15029 tpnum
= tracepoint_count
;
15031 tpnum
= get_number (arg
);
15035 if (instring
&& *instring
)
15036 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15039 printf_filtered (_("No previous tracepoint\n"));
15043 for (breakpoint
*t
: all_tracepoints ())
15044 if (t
->number
== tpnum
)
15046 return (struct tracepoint
*) t
;
15049 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15054 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15056 if (b
->thread
!= -1)
15057 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15060 fprintf_unfiltered (fp
, " task %d", b
->task
);
15062 fprintf_unfiltered (fp
, "\n");
15065 /* Save information on user settable breakpoints (watchpoints, etc) to
15066 a new script file named FILENAME. If FILTER is non-NULL, call it
15067 on each breakpoint and only include the ones for which it returns
15071 save_breakpoints (const char *filename
, int from_tty
,
15072 bool (*filter
) (const struct breakpoint
*))
15075 int extra_trace_bits
= 0;
15077 if (filename
== 0 || *filename
== 0)
15078 error (_("Argument required (file name in which to save)"));
15080 /* See if we have anything to save. */
15081 for (breakpoint
*tp
: all_breakpoints ())
15083 /* Skip internal and momentary breakpoints. */
15084 if (!user_breakpoint_p (tp
))
15087 /* If we have a filter, only save the breakpoints it accepts. */
15088 if (filter
&& !filter (tp
))
15093 if (is_tracepoint (tp
))
15095 extra_trace_bits
= 1;
15097 /* We can stop searching. */
15104 warning (_("Nothing to save."));
15108 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15112 if (!fp
.open (expanded_filename
.get (), "w"))
15113 error (_("Unable to open file '%s' for saving (%s)"),
15114 expanded_filename
.get (), safe_strerror (errno
));
15116 if (extra_trace_bits
)
15117 save_trace_state_variables (&fp
);
15119 for (breakpoint
*tp
: all_breakpoints ())
15121 /* Skip internal and momentary breakpoints. */
15122 if (!user_breakpoint_p (tp
))
15125 /* If we have a filter, only save the breakpoints it accepts. */
15126 if (filter
&& !filter (tp
))
15129 tp
->ops
->print_recreate (tp
, &fp
);
15131 /* Note, we can't rely on tp->number for anything, as we can't
15132 assume the recreated breakpoint numbers will match. Use $bpnum
15135 if (tp
->cond_string
)
15136 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15138 if (tp
->ignore_count
)
15139 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15141 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15143 fp
.puts (" commands\n");
15145 current_uiout
->redirect (&fp
);
15148 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15150 catch (const gdb_exception
&ex
)
15152 current_uiout
->redirect (NULL
);
15156 current_uiout
->redirect (NULL
);
15157 fp
.puts (" end\n");
15160 if (tp
->enable_state
== bp_disabled
)
15161 fp
.puts ("disable $bpnum\n");
15163 /* If this is a multi-location breakpoint, check if the locations
15164 should be individually disabled. Watchpoint locations are
15165 special, and not user visible. */
15166 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15170 for (bp_location
*loc
: tp
->locations ())
15173 fp
.printf ("disable $bpnum.%d\n", n
);
15180 if (extra_trace_bits
&& *default_collect
)
15181 fp
.printf ("set default-collect %s\n", default_collect
);
15184 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15187 /* The `save breakpoints' command. */
15190 save_breakpoints_command (const char *args
, int from_tty
)
15192 save_breakpoints (args
, from_tty
, NULL
);
15195 /* The `save tracepoints' command. */
15198 save_tracepoints_command (const char *args
, int from_tty
)
15200 save_breakpoints (args
, from_tty
, is_tracepoint
);
15204 /* This help string is used to consolidate all the help string for specifying
15205 locations used by several commands. */
15207 #define LOCATION_HELP_STRING \
15208 "Linespecs are colon-separated lists of location parameters, such as\n\
15209 source filename, function name, label name, and line number.\n\
15210 Example: To specify the start of a label named \"the_top\" in the\n\
15211 function \"fact\" in the file \"factorial.c\", use\n\
15212 \"factorial.c:fact:the_top\".\n\
15214 Address locations begin with \"*\" and specify an exact address in the\n\
15215 program. Example: To specify the fourth byte past the start function\n\
15216 \"main\", use \"*main + 4\".\n\
15218 Explicit locations are similar to linespecs but use an option/argument\n\
15219 syntax to specify location parameters.\n\
15220 Example: To specify the start of the label named \"the_top\" in the\n\
15221 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15222 -function fact -label the_top\".\n\
15224 By default, a specified function is matched against the program's\n\
15225 functions in all scopes. For C++, this means in all namespaces and\n\
15226 classes. For Ada, this means in all packages. E.g., in C++,\n\
15227 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15228 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15229 specified name as a complete fully-qualified name instead."
15231 /* This help string is used for the break, hbreak, tbreak and thbreak
15232 commands. It is defined as a macro to prevent duplication.
15233 COMMAND should be a string constant containing the name of the
15236 #define BREAK_ARGS_HELP(command) \
15237 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
15238 \t[-force-condition] [if CONDITION]\n\
15239 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15240 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15241 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15242 `-probe-dtrace' (for a DTrace probe).\n\
15243 LOCATION may be a linespec, address, or explicit location as described\n\
15246 With no LOCATION, uses current execution address of the selected\n\
15247 stack frame. This is useful for breaking on return to a stack frame.\n\
15249 THREADNUM is the number from \"info threads\".\n\
15250 CONDITION is a boolean expression.\n\
15252 With the \"-force-condition\" flag, the condition is defined even when\n\
15253 it is invalid for all current locations.\n\
15254 \n" LOCATION_HELP_STRING "\n\n\
15255 Multiple breakpoints at one place are permitted, and useful if their\n\
15256 conditions are different.\n\
15258 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15260 /* List of subcommands for "catch". */
15261 static struct cmd_list_element
*catch_cmdlist
;
15263 /* List of subcommands for "tcatch". */
15264 static struct cmd_list_element
*tcatch_cmdlist
;
15267 add_catch_command (const char *name
, const char *docstring
,
15268 cmd_const_sfunc_ftype
*sfunc
,
15269 completer_ftype
*completer
,
15270 void *user_data_catch
,
15271 void *user_data_tcatch
)
15273 struct cmd_list_element
*command
;
15275 command
= add_cmd (name
, class_breakpoint
, docstring
,
15277 set_cmd_sfunc (command
, sfunc
);
15278 set_cmd_context (command
, user_data_catch
);
15279 set_cmd_completer (command
, completer
);
15281 command
= add_cmd (name
, class_breakpoint
, docstring
,
15283 set_cmd_sfunc (command
, sfunc
);
15284 set_cmd_context (command
, user_data_tcatch
);
15285 set_cmd_completer (command
, completer
);
15288 struct breakpoint
*
15289 iterate_over_breakpoints (gdb::function_view
<bool (breakpoint
*)> callback
)
15291 for (breakpoint
*b
: all_breakpoints_safe ())
15298 /* Zero if any of the breakpoint's locations could be a location where
15299 functions have been inlined, nonzero otherwise. */
15302 is_non_inline_function (struct breakpoint
*b
)
15304 /* The shared library event breakpoint is set on the address of a
15305 non-inline function. */
15306 if (b
->type
== bp_shlib_event
)
15312 /* Nonzero if the specified PC cannot be a location where functions
15313 have been inlined. */
15316 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15317 const struct target_waitstatus
*ws
)
15319 for (breakpoint
*b
: all_breakpoints ())
15321 if (!is_non_inline_function (b
))
15324 for (bp_location
*bl
: b
->locations ())
15326 if (!bl
->shlib_disabled
15327 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15335 /* Remove any references to OBJFILE which is going to be freed. */
15338 breakpoint_free_objfile (struct objfile
*objfile
)
15340 struct bp_location
**locp
, *loc
;
15342 ALL_BP_LOCATIONS (loc
, locp
)
15343 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15344 loc
->symtab
= NULL
;
15348 initialize_breakpoint_ops (void)
15350 static int initialized
= 0;
15352 struct breakpoint_ops
*ops
;
15358 /* The breakpoint_ops structure to be inherit by all kinds of
15359 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15360 internal and momentary breakpoints, etc.). */
15361 ops
= &bkpt_base_breakpoint_ops
;
15362 *ops
= base_breakpoint_ops
;
15363 ops
->re_set
= bkpt_re_set
;
15364 ops
->insert_location
= bkpt_insert_location
;
15365 ops
->remove_location
= bkpt_remove_location
;
15366 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15367 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15368 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15369 ops
->decode_location
= bkpt_decode_location
;
15371 /* The breakpoint_ops structure to be used in regular breakpoints. */
15372 ops
= &bkpt_breakpoint_ops
;
15373 *ops
= bkpt_base_breakpoint_ops
;
15374 ops
->re_set
= bkpt_re_set
;
15375 ops
->resources_needed
= bkpt_resources_needed
;
15376 ops
->print_it
= bkpt_print_it
;
15377 ops
->print_mention
= bkpt_print_mention
;
15378 ops
->print_recreate
= bkpt_print_recreate
;
15380 /* Ranged breakpoints. */
15381 ops
= &ranged_breakpoint_ops
;
15382 *ops
= bkpt_breakpoint_ops
;
15383 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15384 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15385 ops
->print_it
= print_it_ranged_breakpoint
;
15386 ops
->print_one
= print_one_ranged_breakpoint
;
15387 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15388 ops
->print_mention
= print_mention_ranged_breakpoint
;
15389 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15391 /* Internal breakpoints. */
15392 ops
= &internal_breakpoint_ops
;
15393 *ops
= bkpt_base_breakpoint_ops
;
15394 ops
->re_set
= internal_bkpt_re_set
;
15395 ops
->check_status
= internal_bkpt_check_status
;
15396 ops
->print_it
= internal_bkpt_print_it
;
15397 ops
->print_mention
= internal_bkpt_print_mention
;
15399 /* Momentary breakpoints. */
15400 ops
= &momentary_breakpoint_ops
;
15401 *ops
= bkpt_base_breakpoint_ops
;
15402 ops
->re_set
= momentary_bkpt_re_set
;
15403 ops
->check_status
= momentary_bkpt_check_status
;
15404 ops
->print_it
= momentary_bkpt_print_it
;
15405 ops
->print_mention
= momentary_bkpt_print_mention
;
15407 /* Probe breakpoints. */
15408 ops
= &bkpt_probe_breakpoint_ops
;
15409 *ops
= bkpt_breakpoint_ops
;
15410 ops
->insert_location
= bkpt_probe_insert_location
;
15411 ops
->remove_location
= bkpt_probe_remove_location
;
15412 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15413 ops
->decode_location
= bkpt_probe_decode_location
;
15416 ops
= &watchpoint_breakpoint_ops
;
15417 *ops
= base_breakpoint_ops
;
15418 ops
->re_set
= re_set_watchpoint
;
15419 ops
->insert_location
= insert_watchpoint
;
15420 ops
->remove_location
= remove_watchpoint
;
15421 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15422 ops
->check_status
= check_status_watchpoint
;
15423 ops
->resources_needed
= resources_needed_watchpoint
;
15424 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15425 ops
->print_it
= print_it_watchpoint
;
15426 ops
->print_mention
= print_mention_watchpoint
;
15427 ops
->print_recreate
= print_recreate_watchpoint
;
15428 ops
->explains_signal
= explains_signal_watchpoint
;
15430 /* Masked watchpoints. */
15431 ops
= &masked_watchpoint_breakpoint_ops
;
15432 *ops
= watchpoint_breakpoint_ops
;
15433 ops
->insert_location
= insert_masked_watchpoint
;
15434 ops
->remove_location
= remove_masked_watchpoint
;
15435 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15436 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15437 ops
->print_it
= print_it_masked_watchpoint
;
15438 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15439 ops
->print_mention
= print_mention_masked_watchpoint
;
15440 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15443 ops
= &tracepoint_breakpoint_ops
;
15444 *ops
= base_breakpoint_ops
;
15445 ops
->re_set
= tracepoint_re_set
;
15446 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15447 ops
->print_one_detail
= tracepoint_print_one_detail
;
15448 ops
->print_mention
= tracepoint_print_mention
;
15449 ops
->print_recreate
= tracepoint_print_recreate
;
15450 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15451 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15452 ops
->decode_location
= tracepoint_decode_location
;
15454 /* Probe tracepoints. */
15455 ops
= &tracepoint_probe_breakpoint_ops
;
15456 *ops
= tracepoint_breakpoint_ops
;
15457 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15458 ops
->decode_location
= tracepoint_probe_decode_location
;
15460 /* Static tracepoints with marker (`-m'). */
15461 ops
= &strace_marker_breakpoint_ops
;
15462 *ops
= tracepoint_breakpoint_ops
;
15463 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15464 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15465 ops
->decode_location
= strace_marker_decode_location
;
15467 /* Fork catchpoints. */
15468 ops
= &catch_fork_breakpoint_ops
;
15469 *ops
= base_breakpoint_ops
;
15470 ops
->insert_location
= insert_catch_fork
;
15471 ops
->remove_location
= remove_catch_fork
;
15472 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15473 ops
->print_it
= print_it_catch_fork
;
15474 ops
->print_one
= print_one_catch_fork
;
15475 ops
->print_mention
= print_mention_catch_fork
;
15476 ops
->print_recreate
= print_recreate_catch_fork
;
15478 /* Vfork catchpoints. */
15479 ops
= &catch_vfork_breakpoint_ops
;
15480 *ops
= base_breakpoint_ops
;
15481 ops
->insert_location
= insert_catch_vfork
;
15482 ops
->remove_location
= remove_catch_vfork
;
15483 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15484 ops
->print_it
= print_it_catch_vfork
;
15485 ops
->print_one
= print_one_catch_vfork
;
15486 ops
->print_mention
= print_mention_catch_vfork
;
15487 ops
->print_recreate
= print_recreate_catch_vfork
;
15489 /* Exec catchpoints. */
15490 ops
= &catch_exec_breakpoint_ops
;
15491 *ops
= base_breakpoint_ops
;
15492 ops
->insert_location
= insert_catch_exec
;
15493 ops
->remove_location
= remove_catch_exec
;
15494 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15495 ops
->print_it
= print_it_catch_exec
;
15496 ops
->print_one
= print_one_catch_exec
;
15497 ops
->print_mention
= print_mention_catch_exec
;
15498 ops
->print_recreate
= print_recreate_catch_exec
;
15500 /* Solib-related catchpoints. */
15501 ops
= &catch_solib_breakpoint_ops
;
15502 *ops
= base_breakpoint_ops
;
15503 ops
->insert_location
= insert_catch_solib
;
15504 ops
->remove_location
= remove_catch_solib
;
15505 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15506 ops
->check_status
= check_status_catch_solib
;
15507 ops
->print_it
= print_it_catch_solib
;
15508 ops
->print_one
= print_one_catch_solib
;
15509 ops
->print_mention
= print_mention_catch_solib
;
15510 ops
->print_recreate
= print_recreate_catch_solib
;
15512 ops
= &dprintf_breakpoint_ops
;
15513 *ops
= bkpt_base_breakpoint_ops
;
15514 ops
->re_set
= dprintf_re_set
;
15515 ops
->resources_needed
= bkpt_resources_needed
;
15516 ops
->print_it
= bkpt_print_it
;
15517 ops
->print_mention
= bkpt_print_mention
;
15518 ops
->print_recreate
= dprintf_print_recreate
;
15519 ops
->after_condition_true
= dprintf_after_condition_true
;
15520 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15523 /* Chain containing all defined "enable breakpoint" subcommands. */
15525 static struct cmd_list_element
*enablebreaklist
= NULL
;
15527 /* See breakpoint.h. */
15529 cmd_list_element
*commands_cmd_element
= nullptr;
15531 void _initialize_breakpoint ();
15533 _initialize_breakpoint ()
15535 struct cmd_list_element
*c
;
15537 initialize_breakpoint_ops ();
15539 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
15541 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
15543 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
15546 breakpoint_chain
= 0;
15547 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15548 before a breakpoint is set. */
15549 breakpoint_count
= 0;
15551 tracepoint_count
= 0;
15553 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15554 Set ignore-count of breakpoint number N to COUNT.\n\
15555 Usage is `ignore N COUNT'."));
15557 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15558 commands_command
, _("\
15559 Set commands to be executed when the given breakpoints are hit.\n\
15560 Give a space-separated breakpoint list as argument after \"commands\".\n\
15561 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15563 With no argument, the targeted breakpoint is the last one set.\n\
15564 The commands themselves follow starting on the next line.\n\
15565 Type a line containing \"end\" to indicate the end of them.\n\
15566 Give \"silent\" as the first line to make the breakpoint silent;\n\
15567 then no output is printed when it is hit, except what the commands print."));
15569 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
15570 static std::string condition_command_help
15571 = gdb::option::build_help (_("\
15572 Specify breakpoint number N to break only if COND is true.\n\
15573 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
15574 is an expression to be evaluated whenever breakpoint N is reached.\n\
15577 %OPTIONS%"), cc_opts
);
15579 c
= add_com ("condition", class_breakpoint
, condition_command
,
15580 condition_command_help
.c_str ());
15581 set_cmd_completer_handle_brkchars (c
, condition_completer
);
15583 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15584 Set a temporary breakpoint.\n\
15585 Like \"break\" except the breakpoint is only temporary,\n\
15586 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15587 by using \"enable delete\" on the breakpoint number.\n\
15589 BREAK_ARGS_HELP ("tbreak")));
15590 set_cmd_completer (c
, location_completer
);
15592 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15593 Set a hardware assisted breakpoint.\n\
15594 Like \"break\" except the breakpoint requires hardware support,\n\
15595 some target hardware may not have this support.\n\
15597 BREAK_ARGS_HELP ("hbreak")));
15598 set_cmd_completer (c
, location_completer
);
15600 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15601 Set a temporary hardware assisted breakpoint.\n\
15602 Like \"hbreak\" except the breakpoint is only temporary,\n\
15603 so it will be deleted when hit.\n\
15605 BREAK_ARGS_HELP ("thbreak")));
15606 set_cmd_completer (c
, location_completer
);
15608 cmd_list_element
*enable_cmd
15609 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15610 Enable all or some breakpoints.\n\
15611 Usage: enable [BREAKPOINTNUM]...\n\
15612 Give breakpoint numbers (separated by spaces) as arguments.\n\
15613 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15614 This is used to cancel the effect of the \"disable\" command.\n\
15615 With a subcommand you can enable temporarily."),
15616 &enablelist
, 1, &cmdlist
);
15618 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
15620 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15621 Enable all or some breakpoints.\n\
15622 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15623 Give breakpoint numbers (separated by spaces) as arguments.\n\
15624 This is used to cancel the effect of the \"disable\" command.\n\
15625 May be abbreviated to simply \"enable\"."),
15626 &enablebreaklist
, 1, &enablelist
);
15628 add_cmd ("once", no_class
, enable_once_command
, _("\
15629 Enable some breakpoints for one hit.\n\
15630 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15631 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15634 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15635 Enable some breakpoints and delete when hit.\n\
15636 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15637 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15640 add_cmd ("count", no_class
, enable_count_command
, _("\
15641 Enable some breakpoints for COUNT hits.\n\
15642 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15643 If a breakpoint is hit while enabled in this fashion,\n\
15644 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15647 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15648 Enable some breakpoints and delete when hit.\n\
15649 Usage: enable delete BREAKPOINTNUM...\n\
15650 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15653 add_cmd ("once", no_class
, enable_once_command
, _("\
15654 Enable some breakpoints for one hit.\n\
15655 Usage: enable once BREAKPOINTNUM...\n\
15656 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15659 add_cmd ("count", no_class
, enable_count_command
, _("\
15660 Enable some breakpoints for COUNT hits.\n\
15661 Usage: enable count COUNT BREAKPOINTNUM...\n\
15662 If a breakpoint is hit while enabled in this fashion,\n\
15663 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15666 cmd_list_element
*disable_cmd
15667 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15668 Disable all or some breakpoints.\n\
15669 Usage: disable [BREAKPOINTNUM]...\n\
15670 Arguments are breakpoint numbers with spaces in between.\n\
15671 To disable all breakpoints, give no argument.\n\
15672 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15673 &disablelist
, 1, &cmdlist
);
15674 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
15675 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
15677 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
15678 Disable all or some breakpoints.\n\
15679 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15680 Arguments are breakpoint numbers with spaces in between.\n\
15681 To disable all breakpoints, give no argument.\n\
15682 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15683 This command may be abbreviated \"disable\"."),
15686 cmd_list_element
*delete_cmd
15687 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15688 Delete all or some breakpoints.\n\
15689 Usage: delete [BREAKPOINTNUM]...\n\
15690 Arguments are breakpoint numbers with spaces in between.\n\
15691 To delete all breakpoints, give no argument.\n\
15693 Also a prefix command for deletion of other GDB objects."),
15694 &deletelist
, 1, &cmdlist
);
15695 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
15696 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
15698 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
15699 Delete all or some breakpoints or auto-display expressions.\n\
15700 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15701 Arguments are breakpoint numbers with spaces in between.\n\
15702 To delete all breakpoints, give no argument.\n\
15703 This command may be abbreviated \"delete\"."),
15706 cmd_list_element
*clear_cmd
15707 = add_com ("clear", class_breakpoint
, clear_command
, _("\
15708 Clear breakpoint at specified location.\n\
15709 Argument may be a linespec, explicit, or address location as described below.\n\
15711 With no argument, clears all breakpoints in the line that the selected frame\n\
15712 is executing in.\n"
15713 "\n" LOCATION_HELP_STRING
"\n\n\
15714 See also the \"delete\" command which clears breakpoints by number."));
15715 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
15717 cmd_list_element
*break_cmd
15718 = add_com ("break", class_breakpoint
, break_command
, _("\
15719 Set breakpoint at specified location.\n"
15720 BREAK_ARGS_HELP ("break")));
15721 set_cmd_completer (break_cmd
, location_completer
);
15723 add_com_alias ("b", break_cmd
, class_run
, 1);
15724 add_com_alias ("br", break_cmd
, class_run
, 1);
15725 add_com_alias ("bre", break_cmd
, class_run
, 1);
15726 add_com_alias ("brea", break_cmd
, class_run
, 1);
15730 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15731 Break in function/address or break at a line in the current file."),
15732 &stoplist
, 1, &cmdlist
);
15733 add_cmd ("in", class_breakpoint
, stopin_command
,
15734 _("Break in function or address."), &stoplist
);
15735 add_cmd ("at", class_breakpoint
, stopat_command
,
15736 _("Break at a line in the current file."), &stoplist
);
15737 add_com ("status", class_info
, info_breakpoints_command
, _("\
15738 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15739 The \"Type\" column indicates one of:\n\
15740 \tbreakpoint - normal breakpoint\n\
15741 \twatchpoint - watchpoint\n\
15742 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15743 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15744 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15745 address and file/line number respectively.\n\
15747 Convenience variable \"$_\" and default examine address for \"x\"\n\
15748 are set to the address of the last breakpoint listed unless the command\n\
15749 is prefixed with \"server \".\n\n\
15750 Convenience variable \"$bpnum\" contains the number of the last\n\
15751 breakpoint set."));
15754 cmd_list_element
*info_breakpoints_cmd
15755 = add_info ("breakpoints", info_breakpoints_command
, _("\
15756 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15757 The \"Type\" column indicates one of:\n\
15758 \tbreakpoint - normal breakpoint\n\
15759 \twatchpoint - watchpoint\n\
15760 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15761 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15762 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15763 address and file/line number respectively.\n\
15765 Convenience variable \"$_\" and default examine address for \"x\"\n\
15766 are set to the address of the last breakpoint listed unless the command\n\
15767 is prefixed with \"server \".\n\n\
15768 Convenience variable \"$bpnum\" contains the number of the last\n\
15769 breakpoint set."));
15771 add_info_alias ("b", info_breakpoints_cmd
, 1);
15773 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15774 Status of all breakpoints, or breakpoint number NUMBER.\n\
15775 The \"Type\" column indicates one of:\n\
15776 \tbreakpoint - normal breakpoint\n\
15777 \twatchpoint - watchpoint\n\
15778 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15779 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15780 \tuntil - internal breakpoint used by the \"until\" command\n\
15781 \tfinish - internal breakpoint used by the \"finish\" command\n\
15782 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15783 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15784 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15785 address and file/line number respectively.\n\
15787 Convenience variable \"$_\" and default examine address for \"x\"\n\
15788 are set to the address of the last breakpoint listed unless the command\n\
15789 is prefixed with \"server \".\n\n\
15790 Convenience variable \"$bpnum\" contains the number of the last\n\
15792 &maintenanceinfolist
);
15794 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
15795 Set catchpoints to catch events."),
15797 0/*allow-unknown*/, &cmdlist
);
15799 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
15800 Set temporary catchpoints to catch events."),
15802 0/*allow-unknown*/, &cmdlist
);
15804 add_catch_command ("fork", _("Catch calls to fork."),
15805 catch_fork_command_1
,
15807 (void *) (uintptr_t) catch_fork_permanent
,
15808 (void *) (uintptr_t) catch_fork_temporary
);
15809 add_catch_command ("vfork", _("Catch calls to vfork."),
15810 catch_fork_command_1
,
15812 (void *) (uintptr_t) catch_vfork_permanent
,
15813 (void *) (uintptr_t) catch_vfork_temporary
);
15814 add_catch_command ("exec", _("Catch calls to exec."),
15815 catch_exec_command_1
,
15819 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15820 Usage: catch load [REGEX]\n\
15821 If REGEX is given, only stop for libraries matching the regular expression."),
15822 catch_load_command_1
,
15826 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15827 Usage: catch unload [REGEX]\n\
15828 If REGEX is given, only stop for libraries matching the regular expression."),
15829 catch_unload_command_1
,
15834 const auto opts
= make_watch_options_def_group (nullptr);
15836 static const std::string watch_help
= gdb::option::build_help (_("\
15837 Set a watchpoint for EXPRESSION.\n\
15838 Usage: watch [-location] EXPRESSION\n\
15843 A watchpoint stops execution of your program whenever the value of\n\
15844 an expression changes."), opts
);
15845 c
= add_com ("watch", class_breakpoint
, watch_command
,
15846 watch_help
.c_str ());
15847 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15849 static const std::string rwatch_help
= gdb::option::build_help (_("\
15850 Set a read watchpoint for EXPRESSION.\n\
15851 Usage: rwatch [-location] EXPRESSION\n\
15856 A read watchpoint stops execution of your program whenever the value of\n\
15857 an expression is read."), opts
);
15858 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
15859 rwatch_help
.c_str ());
15860 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15862 static const std::string awatch_help
= gdb::option::build_help (_("\
15863 Set an access watchpoint for EXPRESSION.\n\
15864 Usage: awatch [-location] EXPRESSION\n\
15869 An access watchpoint stops execution of your program whenever the value\n\
15870 of an expression is either read or written."), opts
);
15871 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
15872 awatch_help
.c_str ());
15873 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15875 add_info ("watchpoints", info_watchpoints_command
, _("\
15876 Status of specified watchpoints (all watchpoints if no argument)."));
15878 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15879 respond to changes - contrary to the description. */
15880 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15881 &can_use_hw_watchpoints
, _("\
15882 Set debugger's willingness to use watchpoint hardware."), _("\
15883 Show debugger's willingness to use watchpoint hardware."), _("\
15884 If zero, gdb will not use hardware for new watchpoints, even if\n\
15885 such is available. (However, any hardware watchpoints that were\n\
15886 created before setting this to nonzero, will continue to use watchpoint\n\
15889 show_can_use_hw_watchpoints
,
15890 &setlist
, &showlist
);
15892 can_use_hw_watchpoints
= 1;
15894 /* Tracepoint manipulation commands. */
15896 cmd_list_element
*trace_cmd
15897 = add_com ("trace", class_breakpoint
, trace_command
, _("\
15898 Set a tracepoint at specified location.\n\
15900 BREAK_ARGS_HELP ("trace") "\n\
15901 Do \"help tracepoints\" for info on other tracepoint commands."));
15902 set_cmd_completer (trace_cmd
, location_completer
);
15904 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
15905 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
15906 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
15907 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
15909 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15910 Set a fast tracepoint at specified location.\n\
15912 BREAK_ARGS_HELP ("ftrace") "\n\
15913 Do \"help tracepoints\" for info on other tracepoint commands."));
15914 set_cmd_completer (c
, location_completer
);
15916 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15917 Set a static tracepoint at location or marker.\n\
15919 strace [LOCATION] [if CONDITION]\n\
15920 LOCATION may be a linespec, explicit, or address location (described below) \n\
15921 or -m MARKER_ID.\n\n\
15922 If a marker id is specified, probe the marker with that name. With\n\
15923 no LOCATION, uses current execution address of the selected stack frame.\n\
15924 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15925 This collects arbitrary user data passed in the probe point call to the\n\
15926 tracing library. You can inspect it when analyzing the trace buffer,\n\
15927 by printing the $_sdata variable like any other convenience variable.\n\
15929 CONDITION is a boolean expression.\n\
15930 \n" LOCATION_HELP_STRING
"\n\n\
15931 Multiple tracepoints at one place are permitted, and useful if their\n\
15932 conditions are different.\n\
15934 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15935 Do \"help tracepoints\" for info on other tracepoint commands."));
15936 set_cmd_completer (c
, location_completer
);
15938 cmd_list_element
*info_tracepoints_cmd
15939 = add_info ("tracepoints", info_tracepoints_command
, _("\
15940 Status of specified tracepoints (all tracepoints if no argument).\n\
15941 Convenience variable \"$tpnum\" contains the number of the\n\
15942 last tracepoint set."));
15944 add_info_alias ("tp", info_tracepoints_cmd
, 1);
15946 cmd_list_element
*delete_tracepoints_cmd
15947 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15948 Delete specified tracepoints.\n\
15949 Arguments are tracepoint numbers, separated by spaces.\n\
15950 No argument means delete all tracepoints."),
15952 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
15954 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15955 Disable specified tracepoints.\n\
15956 Arguments are tracepoint numbers, separated by spaces.\n\
15957 No argument means disable all tracepoints."),
15959 deprecate_cmd (c
, "disable");
15961 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15962 Enable specified tracepoints.\n\
15963 Arguments are tracepoint numbers, separated by spaces.\n\
15964 No argument means enable all tracepoints."),
15966 deprecate_cmd (c
, "enable");
15968 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15969 Set the passcount for a tracepoint.\n\
15970 The trace will end when the tracepoint has been passed 'count' times.\n\
15971 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15972 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15974 add_basic_prefix_cmd ("save", class_breakpoint
,
15975 _("Save breakpoint definitions as a script."),
15977 0/*allow-unknown*/, &cmdlist
);
15979 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15980 Save current breakpoint definitions as a script.\n\
15981 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15982 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15983 session to restore them."),
15985 set_cmd_completer (c
, filename_completer
);
15987 cmd_list_element
*save_tracepoints_cmd
15988 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15989 Save current tracepoint definitions as a script.\n\
15990 Use the 'source' command in another debug session to restore them."),
15992 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
15994 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
15995 deprecate_cmd (c
, "save tracepoints");
15997 add_basic_prefix_cmd ("breakpoint", class_maintenance
, _("\
15998 Breakpoint specific settings.\n\
15999 Configure various breakpoint-specific variables such as\n\
16000 pending breakpoint behavior."),
16001 &breakpoint_set_cmdlist
,
16002 0/*allow-unknown*/, &setlist
);
16003 add_show_prefix_cmd ("breakpoint", class_maintenance
, _("\
16004 Breakpoint specific settings.\n\
16005 Configure various breakpoint-specific variables such as\n\
16006 pending breakpoint behavior."),
16007 &breakpoint_show_cmdlist
,
16008 0/*allow-unknown*/, &showlist
);
16010 add_setshow_auto_boolean_cmd ("pending", no_class
,
16011 &pending_break_support
, _("\
16012 Set debugger's behavior regarding pending breakpoints."), _("\
16013 Show debugger's behavior regarding pending breakpoints."), _("\
16014 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16015 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16016 an error. If auto, an unrecognized breakpoint location results in a\n\
16017 user-query to see if a pending breakpoint should be created."),
16019 show_pending_break_support
,
16020 &breakpoint_set_cmdlist
,
16021 &breakpoint_show_cmdlist
);
16023 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16025 add_setshow_boolean_cmd ("auto-hw", no_class
,
16026 &automatic_hardware_breakpoints
, _("\
16027 Set automatic usage of hardware breakpoints."), _("\
16028 Show automatic usage of hardware breakpoints."), _("\
16029 If set, the debugger will automatically use hardware breakpoints for\n\
16030 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16031 a warning will be emitted for such breakpoints."),
16033 show_automatic_hardware_breakpoints
,
16034 &breakpoint_set_cmdlist
,
16035 &breakpoint_show_cmdlist
);
16037 add_setshow_boolean_cmd ("always-inserted", class_support
,
16038 &always_inserted_mode
, _("\
16039 Set mode for inserting breakpoints."), _("\
16040 Show mode for inserting breakpoints."), _("\
16041 When this mode is on, breakpoints are inserted immediately as soon as\n\
16042 they're created, kept inserted even when execution stops, and removed\n\
16043 only when the user deletes them. When this mode is off (the default),\n\
16044 breakpoints are inserted only when execution continues, and removed\n\
16045 when execution stops."),
16047 &show_always_inserted_mode
,
16048 &breakpoint_set_cmdlist
,
16049 &breakpoint_show_cmdlist
);
16051 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16052 condition_evaluation_enums
,
16053 &condition_evaluation_mode_1
, _("\
16054 Set mode of breakpoint condition evaluation."), _("\
16055 Show mode of breakpoint condition evaluation."), _("\
16056 When this is set to \"host\", breakpoint conditions will be\n\
16057 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16058 breakpoint conditions will be downloaded to the target (if the target\n\
16059 supports such feature) and conditions will be evaluated on the target's side.\n\
16060 If this is set to \"auto\" (default), this will be automatically set to\n\
16061 \"target\" if it supports condition evaluation, otherwise it will\n\
16062 be set to \"host\"."),
16063 &set_condition_evaluation_mode
,
16064 &show_condition_evaluation_mode
,
16065 &breakpoint_set_cmdlist
,
16066 &breakpoint_show_cmdlist
);
16068 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16069 Set a breakpoint for an address range.\n\
16070 break-range START-LOCATION, END-LOCATION\n\
16071 where START-LOCATION and END-LOCATION can be one of the following:\n\
16072 LINENUM, for that line in the current file,\n\
16073 FILE:LINENUM, for that line in that file,\n\
16074 +OFFSET, for that number of lines after the current line\n\
16075 or the start of the range\n\
16076 FUNCTION, for the first line in that function,\n\
16077 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16078 *ADDRESS, for the instruction at that address.\n\
16080 The breakpoint will stop execution of the inferior whenever it executes\n\
16081 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16082 range (including START-LOCATION and END-LOCATION)."));
16084 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16085 Set a dynamic printf at specified location.\n\
16086 dprintf location,format string,arg1,arg2,...\n\
16087 location may be a linespec, explicit, or address location.\n"
16088 "\n" LOCATION_HELP_STRING
));
16089 set_cmd_completer (c
, location_completer
);
16091 add_setshow_enum_cmd ("dprintf-style", class_support
,
16092 dprintf_style_enums
, &dprintf_style
, _("\
16093 Set the style of usage for dynamic printf."), _("\
16094 Show the style of usage for dynamic printf."), _("\
16095 This setting chooses how GDB will do a dynamic printf.\n\
16096 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16097 console, as with the \"printf\" command.\n\
16098 If the value is \"call\", the print is done by calling a function in your\n\
16099 program; by default printf(), but you can choose a different function or\n\
16100 output stream by setting dprintf-function and dprintf-channel."),
16101 update_dprintf_commands
, NULL
,
16102 &setlist
, &showlist
);
16104 dprintf_function
= xstrdup ("printf");
16105 add_setshow_string_cmd ("dprintf-function", class_support
,
16106 &dprintf_function
, _("\
16107 Set the function to use for dynamic printf."), _("\
16108 Show the function to use for dynamic printf."), NULL
,
16109 update_dprintf_commands
, NULL
,
16110 &setlist
, &showlist
);
16112 dprintf_channel
= xstrdup ("");
16113 add_setshow_string_cmd ("dprintf-channel", class_support
,
16114 &dprintf_channel
, _("\
16115 Set the channel to use for dynamic printf."), _("\
16116 Show the channel to use for dynamic printf."), NULL
,
16117 update_dprintf_commands
, NULL
,
16118 &setlist
, &showlist
);
16120 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16121 &disconnected_dprintf
, _("\
16122 Set whether dprintf continues after GDB disconnects."), _("\
16123 Show whether dprintf continues after GDB disconnects."), _("\
16124 Use this to let dprintf commands continue to hit and produce output\n\
16125 even if GDB disconnects or detaches from the target."),
16128 &setlist
, &showlist
);
16130 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16131 Target agent only formatted printing, like the C \"printf\" function.\n\
16132 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
16133 This supports most C printf format specifications, like %s, %d, etc.\n\
16134 This is useful for formatted output in user-defined commands."));
16136 automatic_hardware_breakpoints
= true;
16138 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
16140 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,