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 /* Iterator for tracepoints only. */
519 #define ALL_TRACEPOINTS(B) \
520 for (B = breakpoint_chain; B; B = B->next) \
521 if (is_tracepoint (B))
523 /* Chains of all breakpoints defined. */
525 static struct breakpoint
*breakpoint_chain
;
527 /* Breakpoint linked list iterator. */
529 using breakpoint_iterator
= next_iterator
<breakpoint
>;
531 /* Breakpoint linked list range. */
533 using breakpoint_range
= next_adapter
<breakpoint
, breakpoint_iterator
>;
535 /* Return a range to iterate over all breakpoints. */
537 static breakpoint_range
540 return breakpoint_range (breakpoint_chain
);
543 /* Breakpoint linked list range, safe against deletion of the current
544 breakpoint while iterating. */
546 using breakpoint_safe_range
= basic_safe_range
<breakpoint_range
>;
548 /* Return a range to iterate over all breakpoints. This range is safe against
549 deletion of the current breakpoint while iterating. */
551 static breakpoint_safe_range
552 all_breakpoints_safe ()
554 return breakpoint_safe_range (all_breakpoints ());
557 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
559 static struct bp_location
**bp_locations
;
561 /* Number of elements of BP_LOCATIONS. */
563 static unsigned bp_locations_count
;
565 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
566 ADDRESS for the current elements of BP_LOCATIONS which get a valid
567 result from bp_location_has_shadow. You can use it for roughly
568 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
569 an address you need to read. */
571 static CORE_ADDR bp_locations_placed_address_before_address_max
;
573 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
574 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
575 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
576 You can use it for roughly limiting the subrange of BP_LOCATIONS to
577 scan for shadow bytes for an address you need to read. */
579 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
581 /* The locations that no longer correspond to any breakpoint, unlinked
582 from the bp_locations array, but for which a hit may still be
583 reported by a target. */
584 static std::vector
<bp_location
*> moribund_locations
;
586 /* Number of last breakpoint made. */
588 static int breakpoint_count
;
590 /* The value of `breakpoint_count' before the last command that
591 created breakpoints. If the last (break-like) command created more
592 than one breakpoint, then the difference between BREAKPOINT_COUNT
593 and PREV_BREAKPOINT_COUNT is more than one. */
594 static int prev_breakpoint_count
;
596 /* Number of last tracepoint made. */
598 static int tracepoint_count
;
600 static struct cmd_list_element
*breakpoint_set_cmdlist
;
601 static struct cmd_list_element
*breakpoint_show_cmdlist
;
602 struct cmd_list_element
*save_cmdlist
;
604 /* See declaration at breakpoint.h. */
607 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
610 for (breakpoint
*b
: all_breakpoints ())
611 if (func (b
, user_data
) != 0)
617 /* Return whether a breakpoint is an active enabled breakpoint. */
619 breakpoint_enabled (struct breakpoint
*b
)
621 return (b
->enable_state
== bp_enabled
);
624 /* Set breakpoint count to NUM. */
627 set_breakpoint_count (int num
)
629 prev_breakpoint_count
= breakpoint_count
;
630 breakpoint_count
= num
;
631 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
634 /* Used by `start_rbreak_breakpoints' below, to record the current
635 breakpoint count before "rbreak" creates any breakpoint. */
636 static int rbreak_start_breakpoint_count
;
638 /* Called at the start an "rbreak" command to record the first
641 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
643 rbreak_start_breakpoint_count
= breakpoint_count
;
646 /* Called at the end of an "rbreak" command to record the last
649 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
651 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
654 /* Used in run_command to zero the hit count when a new run starts. */
657 clear_breakpoint_hit_counts (void)
659 for (breakpoint
*b
: all_breakpoints ())
664 /* Return the breakpoint with the specified number, or NULL
665 if the number does not refer to an existing breakpoint. */
668 get_breakpoint (int num
)
670 for (breakpoint
*b
: all_breakpoints ())
671 if (b
->number
== num
)
679 /* Mark locations as "conditions have changed" in case the target supports
680 evaluating conditions on its side. */
683 mark_breakpoint_modified (struct breakpoint
*b
)
685 struct bp_location
*loc
;
687 /* This is only meaningful if the target is
688 evaluating conditions and if the user has
689 opted for condition evaluation on the target's
691 if (gdb_evaluates_breakpoint_condition_p ()
692 || !target_supports_evaluation_of_breakpoint_conditions ())
695 if (!is_breakpoint (b
))
698 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
699 loc
->condition_changed
= condition_modified
;
702 /* Mark location as "conditions have changed" in case the target supports
703 evaluating conditions on its side. */
706 mark_breakpoint_location_modified (struct bp_location
*loc
)
708 /* This is only meaningful if the target is
709 evaluating conditions and if the user has
710 opted for condition evaluation on the target's
712 if (gdb_evaluates_breakpoint_condition_p ()
713 || !target_supports_evaluation_of_breakpoint_conditions ())
717 if (!is_breakpoint (loc
->owner
))
720 loc
->condition_changed
= condition_modified
;
723 /* Sets the condition-evaluation mode using the static global
724 condition_evaluation_mode. */
727 set_condition_evaluation_mode (const char *args
, int from_tty
,
728 struct cmd_list_element
*c
)
730 const char *old_mode
, *new_mode
;
732 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
733 && !target_supports_evaluation_of_breakpoint_conditions ())
735 condition_evaluation_mode_1
= condition_evaluation_mode
;
736 warning (_("Target does not support breakpoint condition evaluation.\n"
737 "Using host evaluation mode instead."));
741 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
742 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
744 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
745 settings was "auto". */
746 condition_evaluation_mode
= condition_evaluation_mode_1
;
748 /* Only update the mode if the user picked a different one. */
749 if (new_mode
!= old_mode
)
751 struct bp_location
*loc
, **loc_tmp
;
752 /* If the user switched to a different evaluation mode, we
753 need to synch the changes with the target as follows:
755 "host" -> "target": Send all (valid) conditions to the target.
756 "target" -> "host": Remove all the conditions from the target.
759 if (new_mode
== condition_evaluation_target
)
761 /* Mark everything modified and synch conditions with the
763 ALL_BP_LOCATIONS (loc
, loc_tmp
)
764 mark_breakpoint_location_modified (loc
);
768 /* Manually mark non-duplicate locations to synch conditions
769 with the target. We do this to remove all the conditions the
770 target knows about. */
771 ALL_BP_LOCATIONS (loc
, loc_tmp
)
772 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
773 loc
->needs_update
= 1;
777 update_global_location_list (UGLL_MAY_INSERT
);
783 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
784 what "auto" is translating to. */
787 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
788 struct cmd_list_element
*c
, const char *value
)
790 if (condition_evaluation_mode
== condition_evaluation_auto
)
791 fprintf_filtered (file
,
792 _("Breakpoint condition evaluation "
793 "mode is %s (currently %s).\n"),
795 breakpoint_condition_evaluation_mode ());
797 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
801 /* A comparison function for bp_location AP and BP that is used by
802 bsearch. This comparison function only cares about addresses, unlike
803 the more general bp_location_is_less_than function. */
806 bp_locations_compare_addrs (const void *ap
, const void *bp
)
808 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
809 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
811 if (a
->address
== b
->address
)
814 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
817 /* Helper function to skip all bp_locations with addresses
818 less than ADDRESS. It returns the first bp_location that
819 is greater than or equal to ADDRESS. If none is found, just
822 static struct bp_location
**
823 get_first_locp_gte_addr (CORE_ADDR address
)
825 struct bp_location dummy_loc
;
826 struct bp_location
*dummy_locp
= &dummy_loc
;
827 struct bp_location
**locp_found
= NULL
;
829 /* Initialize the dummy location's address field. */
830 dummy_loc
.address
= address
;
832 /* Find a close match to the first location at ADDRESS. */
833 locp_found
= ((struct bp_location
**)
834 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
835 sizeof (struct bp_location
**),
836 bp_locations_compare_addrs
));
838 /* Nothing was found, nothing left to do. */
839 if (locp_found
== NULL
)
842 /* We may have found a location that is at ADDRESS but is not the first in the
843 location's list. Go backwards (if possible) and locate the first one. */
844 while ((locp_found
- 1) >= bp_locations
845 && (*(locp_found
- 1))->address
== address
)
851 /* Parse COND_STRING in the context of LOC and set as the condition
852 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
853 the number of LOC within its owner. In case of parsing error, mark
854 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
857 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
858 int bp_num
, int loc_num
)
860 bool has_junk
= false;
863 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
864 block_for_pc (loc
->address
), 0);
865 if (*cond_string
!= 0)
869 loc
->cond
= std::move (new_exp
);
870 if (loc
->disabled_by_cond
&& loc
->enabled
)
871 printf_filtered (_("Breakpoint %d's condition is now valid at "
872 "location %d, enabling.\n"),
875 loc
->disabled_by_cond
= false;
878 catch (const gdb_exception_error
&e
)
882 /* Warn if a user-enabled location is now becoming disabled-by-cond.
883 BP_NUM is 0 if the breakpoint is being defined for the first
884 time using the "break ... if ..." command, and non-zero if
887 warning (_("failed to validate condition at location %d.%d, "
888 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
890 warning (_("failed to validate condition at location %d, "
891 "disabling:\n %s"), loc_num
, e
.what ());
894 loc
->disabled_by_cond
= true;
898 error (_("Garbage '%s' follows condition"), cond_string
);
902 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
903 int from_tty
, bool force
)
907 xfree (b
->cond_string
);
908 b
->cond_string
= nullptr;
910 if (is_watchpoint (b
))
911 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
915 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
918 if (loc
->disabled_by_cond
&& loc
->enabled
)
919 printf_filtered (_("Breakpoint %d's condition is now valid at "
920 "location %d, enabling.\n"),
922 loc
->disabled_by_cond
= false;
925 /* No need to free the condition agent expression
926 bytecode (if we have one). We will handle this
927 when we go through update_global_location_list. */
932 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
936 if (is_watchpoint (b
))
938 innermost_block_tracker tracker
;
939 const char *arg
= exp
;
940 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
942 error (_("Junk at end of expression"));
943 watchpoint
*w
= static_cast<watchpoint
*> (b
);
944 w
->cond_exp
= std::move (new_exp
);
945 w
->cond_exp_valid_block
= tracker
.block ();
949 /* Parse and set condition expressions. We make two passes.
950 In the first, we parse the condition string to see if it
951 is valid in at least one location. If so, the condition
952 would be accepted. So we go ahead and set the locations'
953 conditions. In case no valid case is found, we throw
954 the error and the condition string will be rejected.
955 This two-pass approach is taken to avoid setting the
956 state of locations in case of a reject. */
957 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
961 const char *arg
= exp
;
962 parse_exp_1 (&arg
, loc
->address
,
963 block_for_pc (loc
->address
), 0);
965 error (_("Junk at end of expression"));
968 catch (const gdb_exception_error
&e
)
970 /* Condition string is invalid. If this happens to
971 be the last loc, abandon (if not forced) or continue
973 if (loc
->next
== nullptr && !force
)
978 /* If we reach here, the condition is valid at some locations. */
980 for (bp_location
*loc
= b
->loc
; loc
!= nullptr;
981 loc
= loc
->next
, loc_num
++)
982 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
985 /* We know that the new condition parsed successfully. The
986 condition string of the breakpoint can be safely updated. */
987 xfree (b
->cond_string
);
988 b
->cond_string
= xstrdup (exp
);
989 b
->condition_not_parsed
= 0;
991 mark_breakpoint_modified (b
);
993 gdb::observers::breakpoint_modified
.notify (b
);
996 /* See breakpoint.h. */
999 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
1002 for (breakpoint
*b
: all_breakpoints ())
1003 if (b
->number
== bpnum
)
1005 /* Check if this breakpoint has a "stop" method implemented in an
1006 extension language. This method and conditions entered into GDB
1007 from the CLI are mutually exclusive. */
1008 const struct extension_language_defn
*extlang
1009 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1011 if (extlang
!= NULL
)
1013 error (_("Only one stop condition allowed. There is currently"
1014 " a %s stop condition defined for this breakpoint."),
1015 ext_lang_capitalized_name (extlang
));
1017 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1019 if (is_breakpoint (b
))
1020 update_global_location_list (UGLL_MAY_INSERT
);
1025 error (_("No breakpoint number %d."), bpnum
);
1028 /* The options for the "condition" command. */
1030 struct condition_command_opts
1033 bool force_condition
= false;
1036 static const gdb::option::option_def condition_command_option_defs
[] = {
1038 gdb::option::flag_option_def
<condition_command_opts
> {
1040 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1041 N_("Set the condition even if it is invalid for all current locations."),
1046 /* Create an option_def_group for the "condition" options, with
1047 CC_OPTS as context. */
1049 static inline gdb::option::option_def_group
1050 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1052 return {{condition_command_option_defs
}, cc_opts
};
1055 /* Completion for the "condition" command. */
1058 condition_completer (struct cmd_list_element
*cmd
,
1059 completion_tracker
&tracker
,
1060 const char *text
, const char * /*word*/)
1062 bool has_no_arguments
= (*text
== '\0');
1063 condition_command_opts cc_opts
;
1064 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1065 if (gdb::option::complete_options
1066 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1069 text
= skip_spaces (text
);
1070 const char *space
= skip_to_space (text
);
1077 tracker
.advance_custom_word_point_by (1);
1078 /* We don't support completion of history indices. */
1079 if (!isdigit (text
[1]))
1080 complete_internalvar (tracker
, &text
[1]);
1084 /* Suggest the "-force" flag if no arguments are given. If
1085 arguments were passed, they either already include the flag,
1086 or we are beyond the point of suggesting it because it's
1087 positionally the first argument. */
1088 if (has_no_arguments
)
1089 gdb::option::complete_on_all_options (tracker
, group
);
1091 /* We're completing the breakpoint number. */
1092 len
= strlen (text
);
1094 for (breakpoint
*b
: all_breakpoints ())
1098 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1100 if (strncmp (number
, text
, len
) == 0)
1101 tracker
.add_completion (make_unique_xstrdup (number
));
1107 /* We're completing the expression part. Skip the breakpoint num. */
1108 const char *exp_start
= skip_spaces (space
);
1109 tracker
.advance_custom_word_point_by (exp_start
- text
);
1111 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1112 expression_completer (cmd
, tracker
, text
, word
);
1115 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1118 condition_command (const char *arg
, int from_tty
)
1124 error_no_arg (_("breakpoint number"));
1128 /* Check if the "-force" flag was passed. */
1129 condition_command_opts cc_opts
;
1130 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1131 gdb::option::process_options
1132 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1134 bnum
= get_number (&p
);
1136 error (_("Bad breakpoint argument: '%s'"), arg
);
1138 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1141 /* Check that COMMAND do not contain commands that are suitable
1142 only for tracepoints and not suitable for ordinary breakpoints.
1143 Throw if any such commands is found. */
1146 check_no_tracepoint_commands (struct command_line
*commands
)
1148 struct command_line
*c
;
1150 for (c
= commands
; c
; c
= c
->next
)
1152 if (c
->control_type
== while_stepping_control
)
1153 error (_("The 'while-stepping' command can "
1154 "only be used for tracepoints"));
1156 check_no_tracepoint_commands (c
->body_list_0
.get ());
1157 check_no_tracepoint_commands (c
->body_list_1
.get ());
1159 /* Not that command parsing removes leading whitespace and comment
1160 lines and also empty lines. So, we only need to check for
1161 command directly. */
1162 if (strstr (c
->line
, "collect ") == c
->line
)
1163 error (_("The 'collect' command can only be used for tracepoints"));
1165 if (strstr (c
->line
, "teval ") == c
->line
)
1166 error (_("The 'teval' command can only be used for tracepoints"));
1170 struct longjmp_breakpoint
: public breakpoint
1172 ~longjmp_breakpoint () override
;
1175 /* Encapsulate tests for different types of tracepoints. */
1178 is_tracepoint_type (bptype type
)
1180 return (type
== bp_tracepoint
1181 || type
== bp_fast_tracepoint
1182 || type
== bp_static_tracepoint
);
1186 is_longjmp_type (bptype type
)
1188 return type
== bp_longjmp
|| type
== bp_exception
;
1191 /* See breakpoint.h. */
1194 is_tracepoint (const struct breakpoint
*b
)
1196 return is_tracepoint_type (b
->type
);
1199 /* Factory function to create an appropriate instance of breakpoint given
1202 static std::unique_ptr
<breakpoint
>
1203 new_breakpoint_from_type (bptype type
)
1207 if (is_tracepoint_type (type
))
1208 b
= new tracepoint ();
1209 else if (is_longjmp_type (type
))
1210 b
= new longjmp_breakpoint ();
1212 b
= new breakpoint ();
1214 return std::unique_ptr
<breakpoint
> (b
);
1217 /* A helper function that validates that COMMANDS are valid for a
1218 breakpoint. This function will throw an exception if a problem is
1222 validate_commands_for_breakpoint (struct breakpoint
*b
,
1223 struct command_line
*commands
)
1225 if (is_tracepoint (b
))
1227 struct tracepoint
*t
= (struct tracepoint
*) b
;
1228 struct command_line
*c
;
1229 struct command_line
*while_stepping
= 0;
1231 /* Reset the while-stepping step count. The previous commands
1232 might have included a while-stepping action, while the new
1236 /* We need to verify that each top-level element of commands is
1237 valid for tracepoints, that there's at most one
1238 while-stepping element, and that the while-stepping's body
1239 has valid tracing commands excluding nested while-stepping.
1240 We also need to validate the tracepoint action line in the
1241 context of the tracepoint --- validate_actionline actually
1242 has side effects, like setting the tracepoint's
1243 while-stepping STEP_COUNT, in addition to checking if the
1244 collect/teval actions parse and make sense in the
1245 tracepoint's context. */
1246 for (c
= commands
; c
; c
= c
->next
)
1248 if (c
->control_type
== while_stepping_control
)
1250 if (b
->type
== bp_fast_tracepoint
)
1251 error (_("The 'while-stepping' command "
1252 "cannot be used for fast tracepoint"));
1253 else if (b
->type
== bp_static_tracepoint
)
1254 error (_("The 'while-stepping' command "
1255 "cannot be used for static tracepoint"));
1258 error (_("The 'while-stepping' command "
1259 "can be used only once"));
1264 validate_actionline (c
->line
, b
);
1268 struct command_line
*c2
;
1270 gdb_assert (while_stepping
->body_list_1
== nullptr);
1271 c2
= while_stepping
->body_list_0
.get ();
1272 for (; c2
; c2
= c2
->next
)
1274 if (c2
->control_type
== while_stepping_control
)
1275 error (_("The 'while-stepping' command cannot be nested"));
1281 check_no_tracepoint_commands (commands
);
1285 /* Return a vector of all the static tracepoints set at ADDR. The
1286 caller is responsible for releasing the vector. */
1288 std::vector
<breakpoint
*>
1289 static_tracepoints_here (CORE_ADDR addr
)
1291 std::vector
<breakpoint
*> found
;
1292 struct bp_location
*loc
;
1294 for (breakpoint
*b
: all_breakpoints ())
1295 if (b
->type
== bp_static_tracepoint
)
1297 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1298 if (loc
->address
== addr
)
1299 found
.push_back (b
);
1305 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1306 validate that only allowed commands are included. */
1309 breakpoint_set_commands (struct breakpoint
*b
,
1310 counted_command_line
&&commands
)
1312 validate_commands_for_breakpoint (b
, commands
.get ());
1314 b
->commands
= std::move (commands
);
1315 gdb::observers::breakpoint_modified
.notify (b
);
1318 /* Set the internal `silent' flag on the breakpoint. Note that this
1319 is not the same as the "silent" that may appear in the breakpoint's
1323 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1325 int old_silent
= b
->silent
;
1328 if (old_silent
!= silent
)
1329 gdb::observers::breakpoint_modified
.notify (b
);
1332 /* Set the thread for this breakpoint. If THREAD is -1, make the
1333 breakpoint work for any thread. */
1336 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1338 int old_thread
= b
->thread
;
1341 if (old_thread
!= thread
)
1342 gdb::observers::breakpoint_modified
.notify (b
);
1345 /* Set the task for this breakpoint. If TASK is 0, make the
1346 breakpoint work for any task. */
1349 breakpoint_set_task (struct breakpoint
*b
, int task
)
1351 int old_task
= b
->task
;
1354 if (old_task
!= task
)
1355 gdb::observers::breakpoint_modified
.notify (b
);
1359 commands_command_1 (const char *arg
, int from_tty
,
1360 struct command_line
*control
)
1362 counted_command_line cmd
;
1363 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1364 NULL after the call to read_command_lines if the user provides an empty
1365 list of command by just typing "end". */
1366 bool cmd_read
= false;
1368 std::string new_arg
;
1370 if (arg
== NULL
|| !*arg
)
1372 /* Argument not explicitly given. Synthesize it. */
1373 if (breakpoint_count
- prev_breakpoint_count
> 1)
1374 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1376 else if (breakpoint_count
> 0)
1377 new_arg
= string_printf ("%d", breakpoint_count
);
1381 /* Create a copy of ARG. This is needed because the "commands"
1382 command may be coming from a script. In that case, the read
1383 line buffer is going to be overwritten in the lambda of
1384 'map_breakpoint_numbers' below when reading the next line
1385 before we are are done parsing the breakpoint numbers. */
1388 arg
= new_arg
.c_str ();
1390 map_breakpoint_numbers
1391 (arg
, [&] (breakpoint
*b
)
1395 gdb_assert (cmd
== NULL
);
1396 if (control
!= NULL
)
1397 cmd
= control
->body_list_0
;
1401 = string_printf (_("Type commands for breakpoint(s) "
1402 "%s, one per line."),
1405 auto do_validate
= [=] (const char *line
)
1407 validate_actionline (line
, b
);
1409 gdb::function_view
<void (const char *)> validator
;
1410 if (is_tracepoint (b
))
1411 validator
= do_validate
;
1413 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1418 /* If a breakpoint was on the list more than once, we don't need to
1420 if (b
->commands
!= cmd
)
1422 validate_commands_for_breakpoint (b
, cmd
.get ());
1424 gdb::observers::breakpoint_modified
.notify (b
);
1430 commands_command (const char *arg
, int from_tty
)
1432 commands_command_1 (arg
, from_tty
, NULL
);
1435 /* Like commands_command, but instead of reading the commands from
1436 input stream, takes them from an already parsed command structure.
1438 This is used by cli-script.c to DTRT with breakpoint commands
1439 that are part of if and while bodies. */
1440 enum command_control_type
1441 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1443 commands_command_1 (arg
, 0, cmd
);
1444 return simple_control
;
1447 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1450 bp_location_has_shadow (struct bp_location
*bl
)
1452 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1456 if (bl
->target_info
.shadow_len
== 0)
1457 /* BL isn't valid, or doesn't shadow memory. */
1462 /* Update BUF, which is LEN bytes read from the target address
1463 MEMADDR, by replacing a memory breakpoint with its shadowed
1466 If READBUF is not NULL, this buffer must not overlap with the of
1467 the breakpoint location's shadow_contents buffer. Otherwise, a
1468 failed assertion internal error will be raised. */
1471 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1472 const gdb_byte
*writebuf_org
,
1473 ULONGEST memaddr
, LONGEST len
,
1474 struct bp_target_info
*target_info
,
1475 struct gdbarch
*gdbarch
)
1477 /* Now do full processing of the found relevant range of elements. */
1478 CORE_ADDR bp_addr
= 0;
1482 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1483 current_program_space
->aspace
, 0))
1485 /* The breakpoint is inserted in a different address space. */
1489 /* Addresses and length of the part of the breakpoint that
1491 bp_addr
= target_info
->placed_address
;
1492 bp_size
= target_info
->shadow_len
;
1494 if (bp_addr
+ bp_size
<= memaddr
)
1496 /* The breakpoint is entirely before the chunk of memory we are
1501 if (bp_addr
>= memaddr
+ len
)
1503 /* The breakpoint is entirely after the chunk of memory we are
1508 /* Offset within shadow_contents. */
1509 if (bp_addr
< memaddr
)
1511 /* Only copy the second part of the breakpoint. */
1512 bp_size
-= memaddr
- bp_addr
;
1513 bptoffset
= memaddr
- bp_addr
;
1517 if (bp_addr
+ bp_size
> memaddr
+ len
)
1519 /* Only copy the first part of the breakpoint. */
1520 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1523 if (readbuf
!= NULL
)
1525 /* Verify that the readbuf buffer does not overlap with the
1526 shadow_contents buffer. */
1527 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1528 || readbuf
>= (target_info
->shadow_contents
1529 + target_info
->shadow_len
));
1531 /* Update the read buffer with this inserted breakpoint's
1533 memcpy (readbuf
+ bp_addr
- memaddr
,
1534 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1538 const unsigned char *bp
;
1539 CORE_ADDR addr
= target_info
->reqstd_address
;
1542 /* Update the shadow with what we want to write to memory. */
1543 memcpy (target_info
->shadow_contents
+ bptoffset
,
1544 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1546 /* Determine appropriate breakpoint contents and size for this
1548 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1550 /* Update the final write buffer with this inserted
1551 breakpoint's INSN. */
1552 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1556 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1557 by replacing any memory breakpoints with their shadowed contents.
1559 If READBUF is not NULL, this buffer must not overlap with any of
1560 the breakpoint location's shadow_contents buffers. Otherwise,
1561 a failed assertion internal error will be raised.
1563 The range of shadowed area by each bp_location is:
1564 bl->address - bp_locations_placed_address_before_address_max
1565 up to bl->address + bp_locations_shadow_len_after_address_max
1566 The range we were requested to resolve shadows for is:
1567 memaddr ... memaddr + len
1568 Thus the safe cutoff boundaries for performance optimization are
1569 memaddr + len <= (bl->address
1570 - bp_locations_placed_address_before_address_max)
1572 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1575 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1576 const gdb_byte
*writebuf_org
,
1577 ULONGEST memaddr
, LONGEST len
)
1579 /* Left boundary, right boundary and median element of our binary
1581 unsigned bc_l
, bc_r
, bc
;
1583 /* Find BC_L which is a leftmost element which may affect BUF
1584 content. It is safe to report lower value but a failure to
1585 report higher one. */
1588 bc_r
= bp_locations_count
;
1589 while (bc_l
+ 1 < bc_r
)
1591 struct bp_location
*bl
;
1593 bc
= (bc_l
+ bc_r
) / 2;
1594 bl
= bp_locations
[bc
];
1596 /* Check first BL->ADDRESS will not overflow due to the added
1597 constant. Then advance the left boundary only if we are sure
1598 the BC element can in no way affect the BUF content (MEMADDR
1599 to MEMADDR + LEN range).
1601 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1602 offset so that we cannot miss a breakpoint with its shadow
1603 range tail still reaching MEMADDR. */
1605 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1607 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1614 /* Due to the binary search above, we need to make sure we pick the
1615 first location that's at BC_L's address. E.g., if there are
1616 multiple locations at the same address, BC_L may end up pointing
1617 at a duplicate location, and miss the "master"/"inserted"
1618 location. Say, given locations L1, L2 and L3 at addresses A and
1621 L1@A, L2@A, L3@B, ...
1623 BC_L could end up pointing at location L2, while the "master"
1624 location could be L1. Since the `loc->inserted' flag is only set
1625 on "master" locations, we'd forget to restore the shadow of L1
1628 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1631 /* Now do full processing of the found relevant range of elements. */
1633 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1635 struct bp_location
*bl
= bp_locations
[bc
];
1637 /* bp_location array has BL->OWNER always non-NULL. */
1638 if (bl
->owner
->type
== bp_none
)
1639 warning (_("reading through apparently deleted breakpoint #%d?"),
1642 /* Performance optimization: any further element can no longer affect BUF
1645 if (bl
->address
>= bp_locations_placed_address_before_address_max
1646 && memaddr
+ len
<= (bl
->address
1647 - bp_locations_placed_address_before_address_max
))
1650 if (!bp_location_has_shadow (bl
))
1653 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1654 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1658 /* See breakpoint.h. */
1661 is_breakpoint (const struct breakpoint
*bpt
)
1663 return (bpt
->type
== bp_breakpoint
1664 || bpt
->type
== bp_hardware_breakpoint
1665 || bpt
->type
== bp_dprintf
);
1668 /* Return true if BPT is of any hardware watchpoint kind. */
1671 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1673 return (bpt
->type
== bp_hardware_watchpoint
1674 || bpt
->type
== bp_read_watchpoint
1675 || bpt
->type
== bp_access_watchpoint
);
1678 /* See breakpoint.h. */
1681 is_watchpoint (const struct breakpoint
*bpt
)
1683 return (is_hardware_watchpoint (bpt
)
1684 || bpt
->type
== bp_watchpoint
);
1687 /* Returns true if the current thread and its running state are safe
1688 to evaluate or update watchpoint B. Watchpoints on local
1689 expressions need to be evaluated in the context of the thread that
1690 was current when the watchpoint was created, and, that thread needs
1691 to be stopped to be able to select the correct frame context.
1692 Watchpoints on global expressions can be evaluated on any thread,
1693 and in any state. It is presently left to the target allowing
1694 memory accesses when threads are running. */
1697 watchpoint_in_thread_scope (struct watchpoint
*b
)
1699 return (b
->pspace
== current_program_space
1700 && (b
->watchpoint_thread
== null_ptid
1701 || (inferior_ptid
== b
->watchpoint_thread
1702 && !inferior_thread ()->executing
)));
1705 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1706 associated bp_watchpoint_scope breakpoint. */
1709 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1711 if (w
->related_breakpoint
!= w
)
1713 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1714 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1715 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1716 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1717 w
->related_breakpoint
= w
;
1719 w
->disposition
= disp_del_at_next_stop
;
1722 /* Extract a bitfield value from value VAL using the bit parameters contained in
1725 static struct value
*
1726 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1728 struct value
*bit_val
;
1733 bit_val
= allocate_value (value_type (val
));
1735 unpack_value_bitfield (bit_val
,
1738 value_contents_for_printing (val
),
1745 /* Allocate a dummy location and add it to B, which must be a software
1746 watchpoint. This is required because even if a software watchpoint
1747 is not watching any memory, bpstat_stop_status requires a location
1748 to be able to report stops. */
1751 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1752 struct program_space
*pspace
)
1754 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1756 b
->loc
= allocate_bp_location (b
);
1757 b
->loc
->pspace
= pspace
;
1758 b
->loc
->address
= -1;
1759 b
->loc
->length
= -1;
1762 /* Returns true if B is a software watchpoint that is not watching any
1763 memory (e.g., "watch $pc"). */
1766 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1768 return (b
->type
== bp_watchpoint
1770 && b
->loc
->next
== NULL
1771 && b
->loc
->address
== -1
1772 && b
->loc
->length
== -1);
1775 /* Assuming that B is a watchpoint:
1776 - Reparse watchpoint expression, if REPARSE is non-zero
1777 - Evaluate expression and store the result in B->val
1778 - Evaluate the condition if there is one, and store the result
1780 - Update the list of values that must be watched in B->loc.
1782 If the watchpoint disposition is disp_del_at_next_stop, then do
1783 nothing. If this is local watchpoint that is out of scope, delete
1786 Even with `set breakpoint always-inserted on' the watchpoints are
1787 removed + inserted on each stop here. Normal breakpoints must
1788 never be removed because they might be missed by a running thread
1789 when debugging in non-stop mode. On the other hand, hardware
1790 watchpoints (is_hardware_watchpoint; processed here) are specific
1791 to each LWP since they are stored in each LWP's hardware debug
1792 registers. Therefore, such LWP must be stopped first in order to
1793 be able to modify its hardware watchpoints.
1795 Hardware watchpoints must be reset exactly once after being
1796 presented to the user. It cannot be done sooner, because it would
1797 reset the data used to present the watchpoint hit to the user. And
1798 it must not be done later because it could display the same single
1799 watchpoint hit during multiple GDB stops. Note that the latter is
1800 relevant only to the hardware watchpoint types bp_read_watchpoint
1801 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1802 not user-visible - its hit is suppressed if the memory content has
1805 The following constraints influence the location where we can reset
1806 hardware watchpoints:
1808 * target_stopped_by_watchpoint and target_stopped_data_address are
1809 called several times when GDB stops.
1812 * Multiple hardware watchpoints can be hit at the same time,
1813 causing GDB to stop. GDB only presents one hardware watchpoint
1814 hit at a time as the reason for stopping, and all the other hits
1815 are presented later, one after the other, each time the user
1816 requests the execution to be resumed. Execution is not resumed
1817 for the threads still having pending hit event stored in
1818 LWP_INFO->STATUS. While the watchpoint is already removed from
1819 the inferior on the first stop the thread hit event is kept being
1820 reported from its cached value by linux_nat_stopped_data_address
1821 until the real thread resume happens after the watchpoint gets
1822 presented and thus its LWP_INFO->STATUS gets reset.
1824 Therefore the hardware watchpoint hit can get safely reset on the
1825 watchpoint removal from inferior. */
1828 update_watchpoint (struct watchpoint
*b
, int reparse
)
1830 int within_current_scope
;
1831 struct frame_id saved_frame_id
;
1834 /* If this is a local watchpoint, we only want to check if the
1835 watchpoint frame is in scope if the current thread is the thread
1836 that was used to create the watchpoint. */
1837 if (!watchpoint_in_thread_scope (b
))
1840 if (b
->disposition
== disp_del_at_next_stop
)
1845 /* Determine if the watchpoint is within scope. */
1846 if (b
->exp_valid_block
== NULL
)
1847 within_current_scope
= 1;
1850 struct frame_info
*fi
= get_current_frame ();
1851 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1852 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1854 /* If we're at a point where the stack has been destroyed
1855 (e.g. in a function epilogue), unwinding may not work
1856 properly. Do not attempt to recreate locations at this
1857 point. See similar comments in watchpoint_check. */
1858 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1861 /* Save the current frame's ID so we can restore it after
1862 evaluating the watchpoint expression on its own frame. */
1863 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1864 took a frame parameter, so that we didn't have to change the
1867 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1869 fi
= frame_find_by_id (b
->watchpoint_frame
);
1870 within_current_scope
= (fi
!= NULL
);
1871 if (within_current_scope
)
1875 /* We don't free locations. They are stored in the bp_location array
1876 and update_global_location_list will eventually delete them and
1877 remove breakpoints if needed. */
1880 if (within_current_scope
&& reparse
)
1885 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1886 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1887 /* If the meaning of expression itself changed, the old value is
1888 no longer relevant. We don't want to report a watchpoint hit
1889 to the user when the old value and the new value may actually
1890 be completely different objects. */
1892 b
->val_valid
= false;
1894 /* Note that unlike with breakpoints, the watchpoint's condition
1895 expression is stored in the breakpoint object, not in the
1896 locations (re)created below. */
1897 if (b
->cond_string
!= NULL
)
1899 b
->cond_exp
.reset ();
1902 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1906 /* If we failed to parse the expression, for example because
1907 it refers to a global variable in a not-yet-loaded shared library,
1908 don't try to insert watchpoint. We don't automatically delete
1909 such watchpoint, though, since failure to parse expression
1910 is different from out-of-scope watchpoint. */
1911 if (!target_has_execution ())
1913 /* Without execution, memory can't change. No use to try and
1914 set watchpoint locations. The watchpoint will be reset when
1915 the target gains execution, through breakpoint_re_set. */
1916 if (!can_use_hw_watchpoints
)
1918 if (b
->ops
->works_in_software_mode (b
))
1919 b
->type
= bp_watchpoint
;
1921 error (_("Can't set read/access watchpoint when "
1922 "hardware watchpoints are disabled."));
1925 else if (within_current_scope
&& b
->exp
)
1927 std::vector
<value_ref_ptr
> val_chain
;
1928 struct value
*v
, *result
;
1929 struct program_space
*frame_pspace
;
1931 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
1934 /* Avoid setting b->val if it's already set. The meaning of
1935 b->val is 'the last value' user saw, and we should update
1936 it only if we reported that last value to user. As it
1937 happens, the code that reports it updates b->val directly.
1938 We don't keep track of the memory value for masked
1940 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1942 if (b
->val_bitsize
!= 0)
1943 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1944 b
->val
= release_value (v
);
1945 b
->val_valid
= true;
1948 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1950 /* Look at each value on the value chain. */
1951 gdb_assert (!val_chain
.empty ());
1952 for (const value_ref_ptr
&iter
: val_chain
)
1956 /* If it's a memory location, and GDB actually needed
1957 its contents to evaluate the expression, then we
1958 must watch it. If the first value returned is
1959 still lazy, that means an error occurred reading it;
1960 watch it anyway in case it becomes readable. */
1961 if (VALUE_LVAL (v
) == lval_memory
1962 && (v
== val_chain
[0] || ! value_lazy (v
)))
1964 struct type
*vtype
= check_typedef (value_type (v
));
1966 /* We only watch structs and arrays if user asked
1967 for it explicitly, never if they just happen to
1968 appear in the middle of some value chain. */
1970 || (vtype
->code () != TYPE_CODE_STRUCT
1971 && vtype
->code () != TYPE_CODE_ARRAY
))
1974 enum target_hw_bp_type type
;
1975 struct bp_location
*loc
, **tmp
;
1976 int bitpos
= 0, bitsize
= 0;
1978 if (value_bitsize (v
) != 0)
1980 /* Extract the bit parameters out from the bitfield
1982 bitpos
= value_bitpos (v
);
1983 bitsize
= value_bitsize (v
);
1985 else if (v
== result
&& b
->val_bitsize
!= 0)
1987 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1988 lvalue whose bit parameters are saved in the fields
1989 VAL_BITPOS and VAL_BITSIZE. */
1990 bitpos
= b
->val_bitpos
;
1991 bitsize
= b
->val_bitsize
;
1994 addr
= value_address (v
);
1997 /* Skip the bytes that don't contain the bitfield. */
2002 if (b
->type
== bp_read_watchpoint
)
2004 else if (b
->type
== bp_access_watchpoint
)
2007 loc
= allocate_bp_location (b
);
2008 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2011 loc
->gdbarch
= value_type (v
)->arch ();
2013 loc
->pspace
= frame_pspace
;
2014 loc
->address
= address_significant (loc
->gdbarch
, addr
);
2018 /* Just cover the bytes that make up the bitfield. */
2019 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2022 loc
->length
= TYPE_LENGTH (value_type (v
));
2024 loc
->watchpoint_type
= type
;
2029 /* Change the type of breakpoint between hardware assisted or
2030 an ordinary watchpoint depending on the hardware support
2031 and free hardware slots. REPARSE is set when the inferior
2036 enum bp_loc_type loc_type
;
2037 struct bp_location
*bl
;
2039 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2043 int i
, target_resources_ok
, other_type_used
;
2046 /* Use an exact watchpoint when there's only one memory region to be
2047 watched, and only one debug register is needed to watch it. */
2048 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2050 /* We need to determine how many resources are already
2051 used for all other hardware watchpoints plus this one
2052 to see if we still have enough resources to also fit
2053 this watchpoint in as well. */
2055 /* If this is a software watchpoint, we try to turn it
2056 to a hardware one -- count resources as if B was of
2057 hardware watchpoint type. */
2059 if (type
== bp_watchpoint
)
2060 type
= bp_hardware_watchpoint
;
2062 /* This watchpoint may or may not have been placed on
2063 the list yet at this point (it won't be in the list
2064 if we're trying to create it for the first time,
2065 through watch_command), so always account for it
2068 /* Count resources used by all watchpoints except B. */
2069 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2071 /* Add in the resources needed for B. */
2072 i
+= hw_watchpoint_use_count (b
);
2075 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2076 if (target_resources_ok
<= 0)
2078 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2080 if (target_resources_ok
== 0 && !sw_mode
)
2081 error (_("Target does not support this type of "
2082 "hardware watchpoint."));
2083 else if (target_resources_ok
< 0 && !sw_mode
)
2084 error (_("There are not enough available hardware "
2085 "resources for this watchpoint."));
2087 /* Downgrade to software watchpoint. */
2088 b
->type
= bp_watchpoint
;
2092 /* If this was a software watchpoint, we've just
2093 found we have enough resources to turn it to a
2094 hardware watchpoint. Otherwise, this is a
2099 else if (!b
->ops
->works_in_software_mode (b
))
2101 if (!can_use_hw_watchpoints
)
2102 error (_("Can't set read/access watchpoint when "
2103 "hardware watchpoints are disabled."));
2105 error (_("Expression cannot be implemented with "
2106 "read/access watchpoint."));
2109 b
->type
= bp_watchpoint
;
2111 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2112 : bp_loc_hardware_watchpoint
);
2113 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
2114 bl
->loc_type
= loc_type
;
2117 /* If a software watchpoint is not watching any memory, then the
2118 above left it without any location set up. But,
2119 bpstat_stop_status requires a location to be able to report
2120 stops, so make sure there's at least a dummy one. */
2121 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2122 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2124 else if (!within_current_scope
)
2126 printf_filtered (_("\
2127 Watchpoint %d deleted because the program has left the block\n\
2128 in which its expression is valid.\n"),
2130 watchpoint_del_at_next_stop (b
);
2133 /* Restore the selected frame. */
2135 select_frame (frame_find_by_id (saved_frame_id
));
2139 /* Returns 1 iff breakpoint location should be
2140 inserted in the inferior. We don't differentiate the type of BL's owner
2141 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2142 breakpoint_ops is not defined, because in insert_bp_location,
2143 tracepoint's insert_location will not be called. */
2145 should_be_inserted (struct bp_location
*bl
)
2147 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2150 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2153 if (!bl
->enabled
|| bl
->disabled_by_cond
2154 || bl
->shlib_disabled
|| bl
->duplicate
)
2157 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2160 /* This is set for example, when we're attached to the parent of a
2161 vfork, and have detached from the child. The child is running
2162 free, and we expect it to do an exec or exit, at which point the
2163 OS makes the parent schedulable again (and the target reports
2164 that the vfork is done). Until the child is done with the shared
2165 memory region, do not insert breakpoints in the parent, otherwise
2166 the child could still trip on the parent's breakpoints. Since
2167 the parent is blocked anyway, it won't miss any breakpoint. */
2168 if (bl
->pspace
->breakpoints_not_allowed
)
2171 /* Don't insert a breakpoint if we're trying to step past its
2172 location, except if the breakpoint is a single-step breakpoint,
2173 and the breakpoint's thread is the thread which is stepping past
2175 if ((bl
->loc_type
== bp_loc_software_breakpoint
2176 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2177 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2179 /* The single-step breakpoint may be inserted at the location
2180 we're trying to step if the instruction branches to itself.
2181 However, the instruction won't be executed at all and it may
2182 break the semantics of the instruction, for example, the
2183 instruction is a conditional branch or updates some flags.
2184 We can't fix it unless GDB is able to emulate the instruction
2185 or switch to displaced stepping. */
2186 && !(bl
->owner
->type
== bp_single_step
2187 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2189 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2190 paddress (bl
->gdbarch
, bl
->address
));
2194 /* Don't insert watchpoints if we're trying to step past the
2195 instruction that triggered one. */
2196 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2197 && stepping_past_nonsteppable_watchpoint ())
2199 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2200 "skipping watchpoint at %s:%d",
2201 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2208 /* Same as should_be_inserted but does the check assuming
2209 that the location is not duplicated. */
2212 unduplicated_should_be_inserted (struct bp_location
*bl
)
2215 const int save_duplicate
= bl
->duplicate
;
2218 result
= should_be_inserted (bl
);
2219 bl
->duplicate
= save_duplicate
;
2223 /* Parses a conditional described by an expression COND into an
2224 agent expression bytecode suitable for evaluation
2225 by the bytecode interpreter. Return NULL if there was
2226 any error during parsing. */
2228 static agent_expr_up
2229 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2234 agent_expr_up aexpr
;
2236 /* We don't want to stop processing, so catch any errors
2237 that may show up. */
2240 aexpr
= gen_eval_for_expr (scope
, cond
);
2243 catch (const gdb_exception_error
&ex
)
2245 /* If we got here, it means the condition could not be parsed to a valid
2246 bytecode expression and thus can't be evaluated on the target's side.
2247 It's no use iterating through the conditions. */
2250 /* We have a valid agent expression. */
2254 /* Based on location BL, create a list of breakpoint conditions to be
2255 passed on to the target. If we have duplicated locations with different
2256 conditions, we will add such conditions to the list. The idea is that the
2257 target will evaluate the list of conditions and will only notify GDB when
2258 one of them is true. */
2261 build_target_condition_list (struct bp_location
*bl
)
2263 struct bp_location
**locp
= NULL
, **loc2p
;
2264 int null_condition_or_parse_error
= 0;
2265 int modified
= bl
->needs_update
;
2266 struct bp_location
*loc
;
2268 /* Release conditions left over from a previous insert. */
2269 bl
->target_info
.conditions
.clear ();
2271 /* This is only meaningful if the target is
2272 evaluating conditions and if the user has
2273 opted for condition evaluation on the target's
2275 if (gdb_evaluates_breakpoint_condition_p ()
2276 || !target_supports_evaluation_of_breakpoint_conditions ())
2279 /* Do a first pass to check for locations with no assigned
2280 conditions or conditions that fail to parse to a valid agent
2281 expression bytecode. If any of these happen, then it's no use to
2282 send conditions to the target since this location will always
2283 trigger and generate a response back to GDB. Note we consider
2284 all locations at the same address irrespective of type, i.e.,
2285 even if the locations aren't considered duplicates (e.g.,
2286 software breakpoint and hardware breakpoint at the same
2288 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2291 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2295 /* Re-parse the conditions since something changed. In that
2296 case we already freed the condition bytecodes (see
2297 force_breakpoint_reinsertion). We just
2298 need to parse the condition to bytecodes again. */
2299 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2303 /* If we have a NULL bytecode expression, it means something
2304 went wrong or we have a null condition expression. */
2305 if (!loc
->cond_bytecode
)
2307 null_condition_or_parse_error
= 1;
2313 /* If any of these happened, it means we will have to evaluate the conditions
2314 for the location's address on gdb's side. It is no use keeping bytecodes
2315 for all the other duplicate locations, thus we free all of them here.
2317 This is so we have a finer control over which locations' conditions are
2318 being evaluated by GDB or the remote stub. */
2319 if (null_condition_or_parse_error
)
2321 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2324 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2326 /* Only go as far as the first NULL bytecode is
2328 if (!loc
->cond_bytecode
)
2331 loc
->cond_bytecode
.reset ();
2336 /* No NULL conditions or failed bytecode generation. Build a
2337 condition list for this location's address. If we have software
2338 and hardware locations at the same address, they aren't
2339 considered duplicates, but we still marge all the conditions
2340 anyway, as it's simpler, and doesn't really make a practical
2342 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2346 && is_breakpoint (loc
->owner
)
2347 && loc
->pspace
->num
== bl
->pspace
->num
2348 && loc
->owner
->enable_state
== bp_enabled
2350 && !loc
->disabled_by_cond
)
2352 /* Add the condition to the vector. This will be used later
2353 to send the conditions to the target. */
2354 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2361 /* Parses a command described by string CMD into an agent expression
2362 bytecode suitable for evaluation by the bytecode interpreter.
2363 Return NULL if there was any error during parsing. */
2365 static agent_expr_up
2366 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2368 const char *cmdrest
;
2369 const char *format_start
, *format_end
;
2370 struct gdbarch
*gdbarch
= get_current_arch ();
2377 if (*cmdrest
== ',')
2379 cmdrest
= skip_spaces (cmdrest
);
2381 if (*cmdrest
++ != '"')
2382 error (_("No format string following the location"));
2384 format_start
= cmdrest
;
2386 format_pieces
fpieces (&cmdrest
);
2388 format_end
= cmdrest
;
2390 if (*cmdrest
++ != '"')
2391 error (_("Bad format string, non-terminated '\"'."));
2393 cmdrest
= skip_spaces (cmdrest
);
2395 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2396 error (_("Invalid argument syntax"));
2398 if (*cmdrest
== ',')
2400 cmdrest
= skip_spaces (cmdrest
);
2402 /* For each argument, make an expression. */
2404 std::vector
<struct expression
*> argvec
;
2405 while (*cmdrest
!= '\0')
2410 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2411 argvec
.push_back (expr
.release ());
2413 if (*cmdrest
== ',')
2417 agent_expr_up aexpr
;
2419 /* We don't want to stop processing, so catch any errors
2420 that may show up. */
2423 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2424 format_start
, format_end
- format_start
,
2425 argvec
.size (), argvec
.data ());
2427 catch (const gdb_exception_error
&ex
)
2429 /* If we got here, it means the command could not be parsed to a valid
2430 bytecode expression and thus can't be evaluated on the target's side.
2431 It's no use iterating through the other commands. */
2434 /* We have a valid agent expression, return it. */
2438 /* Based on location BL, create a list of breakpoint commands to be
2439 passed on to the target. If we have duplicated locations with
2440 different commands, we will add any such to the list. */
2443 build_target_command_list (struct bp_location
*bl
)
2445 struct bp_location
**locp
= NULL
, **loc2p
;
2446 int null_command_or_parse_error
= 0;
2447 int modified
= bl
->needs_update
;
2448 struct bp_location
*loc
;
2450 /* Clear commands left over from a previous insert. */
2451 bl
->target_info
.tcommands
.clear ();
2453 if (!target_can_run_breakpoint_commands ())
2456 /* For now, limit to agent-style dprintf breakpoints. */
2457 if (dprintf_style
!= dprintf_style_agent
)
2460 /* For now, if we have any location at the same address that isn't a
2461 dprintf, don't install the target-side commands, as that would
2462 make the breakpoint not be reported to the core, and we'd lose
2464 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2467 if (is_breakpoint (loc
->owner
)
2468 && loc
->pspace
->num
== bl
->pspace
->num
2469 && loc
->owner
->type
!= bp_dprintf
)
2473 /* Do a first pass to check for locations with no assigned
2474 conditions or conditions that fail to parse to a valid agent expression
2475 bytecode. If any of these happen, then it's no use to send conditions
2476 to the target since this location will always trigger and generate a
2477 response back to GDB. */
2478 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2481 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2485 /* Re-parse the commands since something changed. In that
2486 case we already freed the command bytecodes (see
2487 force_breakpoint_reinsertion). We just
2488 need to parse the command to bytecodes again. */
2490 = parse_cmd_to_aexpr (bl
->address
,
2491 loc
->owner
->extra_string
);
2494 /* If we have a NULL bytecode expression, it means something
2495 went wrong or we have a null command expression. */
2496 if (!loc
->cmd_bytecode
)
2498 null_command_or_parse_error
= 1;
2504 /* If anything failed, then we're not doing target-side commands,
2506 if (null_command_or_parse_error
)
2508 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2511 if (is_breakpoint (loc
->owner
)
2512 && loc
->pspace
->num
== bl
->pspace
->num
)
2514 /* Only go as far as the first NULL bytecode is
2516 if (loc
->cmd_bytecode
== NULL
)
2519 loc
->cmd_bytecode
.reset ();
2524 /* No NULL commands or failed bytecode generation. Build a command
2525 list for all duplicate locations at this location's address.
2526 Note that here we must care for whether the breakpoint location
2527 types are considered duplicates, otherwise, say, if we have a
2528 software and hardware location at the same address, the target
2529 could end up running the commands twice. For the moment, we only
2530 support targets-side commands with dprintf, but it doesn't hurt
2531 to be pedantically correct in case that changes. */
2532 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2535 if (breakpoint_locations_match (bl
, loc
)
2536 && loc
->owner
->extra_string
2537 && is_breakpoint (loc
->owner
)
2538 && loc
->pspace
->num
== bl
->pspace
->num
2539 && loc
->owner
->enable_state
== bp_enabled
2541 && !loc
->disabled_by_cond
)
2543 /* Add the command to the vector. This will be used later
2544 to send the commands to the target. */
2545 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2549 bl
->target_info
.persist
= 0;
2550 /* Maybe flag this location as persistent. */
2551 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2552 bl
->target_info
.persist
= 1;
2555 /* Return the kind of breakpoint on address *ADDR. Get the kind
2556 of breakpoint according to ADDR except single-step breakpoint.
2557 Get the kind of single-step breakpoint according to the current
2561 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2563 if (bl
->owner
->type
== bp_single_step
)
2565 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2566 struct regcache
*regcache
;
2568 regcache
= get_thread_regcache (thr
);
2570 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2574 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2577 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2578 location. Any error messages are printed to TMP_ERROR_STREAM; and
2579 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2580 Returns 0 for success, 1 if the bp_location type is not supported or
2583 NOTE drow/2003-09-09: This routine could be broken down to an
2584 object-style method for each breakpoint or catchpoint type. */
2586 insert_bp_location (struct bp_location
*bl
,
2587 struct ui_file
*tmp_error_stream
,
2588 int *disabled_breaks
,
2589 int *hw_breakpoint_error
,
2590 int *hw_bp_error_explained_already
)
2592 gdb_exception bp_excpt
;
2594 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2597 /* Note we don't initialize bl->target_info, as that wipes out
2598 the breakpoint location's shadow_contents if the breakpoint
2599 is still inserted at that location. This in turn breaks
2600 target_read_memory which depends on these buffers when
2601 a memory read is requested at the breakpoint location:
2602 Once the target_info has been wiped, we fail to see that
2603 we have a breakpoint inserted at that address and thus
2604 read the breakpoint instead of returning the data saved in
2605 the breakpoint location's shadow contents. */
2606 bl
->target_info
.reqstd_address
= bl
->address
;
2607 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2608 bl
->target_info
.length
= bl
->length
;
2610 /* When working with target-side conditions, we must pass all the conditions
2611 for the same breakpoint address down to the target since GDB will not
2612 insert those locations. With a list of breakpoint conditions, the target
2613 can decide when to stop and notify GDB. */
2615 if (is_breakpoint (bl
->owner
))
2617 build_target_condition_list (bl
);
2618 build_target_command_list (bl
);
2619 /* Reset the modification marker. */
2620 bl
->needs_update
= 0;
2623 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2624 set at a read-only address, then a breakpoint location will have
2625 been changed to hardware breakpoint before we get here. If it is
2626 "off" however, error out before actually trying to insert the
2627 breakpoint, with a nicer error message. */
2628 if (bl
->loc_type
== bp_loc_software_breakpoint
2629 && !automatic_hardware_breakpoints
)
2631 mem_region
*mr
= lookup_mem_region (bl
->address
);
2633 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2635 fprintf_unfiltered (tmp_error_stream
,
2636 _("Cannot insert breakpoint %d.\n"
2637 "Cannot set software breakpoint "
2638 "at read-only address %s\n"),
2640 paddress (bl
->gdbarch
, bl
->address
));
2645 if (bl
->loc_type
== bp_loc_software_breakpoint
2646 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2648 /* First check to see if we have to handle an overlay. */
2649 if (overlay_debugging
== ovly_off
2650 || bl
->section
== NULL
2651 || !(section_is_overlay (bl
->section
)))
2653 /* No overlay handling: just set the breakpoint. */
2658 val
= bl
->owner
->ops
->insert_location (bl
);
2660 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2662 catch (gdb_exception
&e
)
2664 bp_excpt
= std::move (e
);
2669 /* This breakpoint is in an overlay section.
2670 Shall we set a breakpoint at the LMA? */
2671 if (!overlay_events_enabled
)
2673 /* Yes -- overlay event support is not active,
2674 so we must try to set a breakpoint at the LMA.
2675 This will not work for a hardware breakpoint. */
2676 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2677 warning (_("hardware breakpoint %d not supported in overlay!"),
2681 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2683 /* Set a software (trap) breakpoint at the LMA. */
2684 bl
->overlay_target_info
= bl
->target_info
;
2685 bl
->overlay_target_info
.reqstd_address
= addr
;
2687 /* No overlay handling: just set the breakpoint. */
2692 bl
->overlay_target_info
.kind
2693 = breakpoint_kind (bl
, &addr
);
2694 bl
->overlay_target_info
.placed_address
= addr
;
2695 val
= target_insert_breakpoint (bl
->gdbarch
,
2696 &bl
->overlay_target_info
);
2699 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2701 catch (gdb_exception
&e
)
2703 bp_excpt
= std::move (e
);
2706 if (bp_excpt
.reason
!= 0)
2707 fprintf_unfiltered (tmp_error_stream
,
2708 "Overlay breakpoint %d "
2709 "failed: in ROM?\n",
2713 /* Shall we set a breakpoint at the VMA? */
2714 if (section_is_mapped (bl
->section
))
2716 /* Yes. This overlay section is mapped into memory. */
2721 val
= bl
->owner
->ops
->insert_location (bl
);
2723 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2725 catch (gdb_exception
&e
)
2727 bp_excpt
= std::move (e
);
2732 /* No. This breakpoint will not be inserted.
2733 No error, but do not mark the bp as 'inserted'. */
2738 if (bp_excpt
.reason
!= 0)
2740 /* Can't set the breakpoint. */
2742 /* In some cases, we might not be able to insert a
2743 breakpoint in a shared library that has already been
2744 removed, but we have not yet processed the shlib unload
2745 event. Unfortunately, some targets that implement
2746 breakpoint insertion themselves can't tell why the
2747 breakpoint insertion failed (e.g., the remote target
2748 doesn't define error codes), so we must treat generic
2749 errors as memory errors. */
2750 if (bp_excpt
.reason
== RETURN_ERROR
2751 && (bp_excpt
.error
== GENERIC_ERROR
2752 || bp_excpt
.error
== MEMORY_ERROR
)
2753 && bl
->loc_type
== bp_loc_software_breakpoint
2754 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2755 || shared_objfile_contains_address_p (bl
->pspace
,
2758 /* See also: disable_breakpoints_in_shlibs. */
2759 bl
->shlib_disabled
= 1;
2760 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2761 if (!*disabled_breaks
)
2763 fprintf_unfiltered (tmp_error_stream
,
2764 "Cannot insert breakpoint %d.\n",
2766 fprintf_unfiltered (tmp_error_stream
,
2767 "Temporarily disabling shared "
2768 "library breakpoints:\n");
2770 *disabled_breaks
= 1;
2771 fprintf_unfiltered (tmp_error_stream
,
2772 "breakpoint #%d\n", bl
->owner
->number
);
2777 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2779 *hw_breakpoint_error
= 1;
2780 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2781 fprintf_unfiltered (tmp_error_stream
,
2782 "Cannot insert hardware breakpoint %d%s",
2784 bp_excpt
.message
? ":" : ".\n");
2785 if (bp_excpt
.message
!= NULL
)
2786 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2791 if (bp_excpt
.message
== NULL
)
2794 = memory_error_message (TARGET_XFER_E_IO
,
2795 bl
->gdbarch
, bl
->address
);
2797 fprintf_unfiltered (tmp_error_stream
,
2798 "Cannot insert breakpoint %d.\n"
2800 bl
->owner
->number
, message
.c_str ());
2804 fprintf_unfiltered (tmp_error_stream
,
2805 "Cannot insert breakpoint %d: %s\n",
2820 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2821 /* NOTE drow/2003-09-08: This state only exists for removing
2822 watchpoints. It's not clear that it's necessary... */
2823 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2827 gdb_assert (bl
->owner
->ops
!= NULL
2828 && bl
->owner
->ops
->insert_location
!= NULL
);
2830 val
= bl
->owner
->ops
->insert_location (bl
);
2832 /* If trying to set a read-watchpoint, and it turns out it's not
2833 supported, try emulating one with an access watchpoint. */
2834 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2836 struct bp_location
*loc
, **loc_temp
;
2838 /* But don't try to insert it, if there's already another
2839 hw_access location that would be considered a duplicate
2841 ALL_BP_LOCATIONS (loc
, loc_temp
)
2843 && loc
->watchpoint_type
== hw_access
2844 && watchpoint_locations_match (bl
, loc
))
2848 bl
->target_info
= loc
->target_info
;
2849 bl
->watchpoint_type
= hw_access
;
2856 bl
->watchpoint_type
= hw_access
;
2857 val
= bl
->owner
->ops
->insert_location (bl
);
2860 /* Back to the original value. */
2861 bl
->watchpoint_type
= hw_read
;
2865 bl
->inserted
= (val
== 0);
2868 else if (bl
->owner
->type
== bp_catchpoint
)
2872 gdb_assert (bl
->owner
->ops
!= NULL
2873 && bl
->owner
->ops
->insert_location
!= NULL
);
2875 val
= bl
->owner
->ops
->insert_location (bl
);
2878 bl
->owner
->enable_state
= bp_disabled
;
2882 Error inserting catchpoint %d: Your system does not support this type\n\
2883 of catchpoint."), bl
->owner
->number
);
2885 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2888 bl
->inserted
= (val
== 0);
2890 /* We've already printed an error message if there was a problem
2891 inserting this catchpoint, and we've disabled the catchpoint,
2892 so just return success. */
2899 /* This function is called when program space PSPACE is about to be
2900 deleted. It takes care of updating breakpoints to not reference
2904 breakpoint_program_space_exit (struct program_space
*pspace
)
2906 struct bp_location
*loc
, **loc_temp
;
2908 /* Remove any breakpoint that was set through this program space. */
2909 for (breakpoint
*b
: all_breakpoints_safe ())
2910 if (b
->pspace
== pspace
)
2911 delete_breakpoint (b
);
2913 /* Breakpoints set through other program spaces could have locations
2914 bound to PSPACE as well. Remove those. */
2915 ALL_BP_LOCATIONS (loc
, loc_temp
)
2917 struct bp_location
*tmp
;
2919 if (loc
->pspace
== pspace
)
2921 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2922 if (loc
->owner
->loc
== loc
)
2923 loc
->owner
->loc
= loc
->next
;
2925 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2926 if (tmp
->next
== loc
)
2928 tmp
->next
= loc
->next
;
2934 /* Now update the global location list to permanently delete the
2935 removed locations above. */
2936 update_global_location_list (UGLL_DONT_INSERT
);
2939 /* Make sure all breakpoints are inserted in inferior.
2940 Throws exception on any error.
2941 A breakpoint that is already inserted won't be inserted
2942 again, so calling this function twice is safe. */
2944 insert_breakpoints (void)
2946 for (breakpoint
*bpt
: all_breakpoints ())
2947 if (is_hardware_watchpoint (bpt
))
2949 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2951 update_watchpoint (w
, 0 /* don't reparse. */);
2954 /* Updating watchpoints creates new locations, so update the global
2955 location list. Explicitly tell ugll to insert locations and
2956 ignore breakpoints_always_inserted_mode. Also,
2957 update_global_location_list tries to "upgrade" software
2958 breakpoints to hardware breakpoints to handle "set breakpoint
2959 auto-hw", so we need to call it even if we don't have new
2961 update_global_location_list (UGLL_INSERT
);
2964 /* Invoke CALLBACK for each of bp_location. */
2967 iterate_over_bp_locations (gdb::function_view
<void (bp_location
*)> callback
)
2969 struct bp_location
*loc
, **loc_tmp
;
2971 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2977 /* This is used when we need to synch breakpoint conditions between GDB and the
2978 target. It is the case with deleting and disabling of breakpoints when using
2979 always-inserted mode. */
2982 update_inserted_breakpoint_locations (void)
2984 struct bp_location
*bl
, **blp_tmp
;
2987 int disabled_breaks
= 0;
2988 int hw_breakpoint_error
= 0;
2989 int hw_bp_details_reported
= 0;
2991 string_file tmp_error_stream
;
2993 /* Explicitly mark the warning -- this will only be printed if
2994 there was an error. */
2995 tmp_error_stream
.puts ("Warning:\n");
2997 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2999 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3001 /* We only want to update software breakpoints and hardware
3003 if (!is_breakpoint (bl
->owner
))
3006 /* We only want to update locations that are already inserted
3007 and need updating. This is to avoid unwanted insertion during
3008 deletion of breakpoints. */
3009 if (!bl
->inserted
|| !bl
->needs_update
)
3012 switch_to_program_space_and_thread (bl
->pspace
);
3014 /* For targets that support global breakpoints, there's no need
3015 to select an inferior to insert breakpoint to. In fact, even
3016 if we aren't attached to any process yet, we should still
3017 insert breakpoints. */
3018 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3019 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3022 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3023 &hw_breakpoint_error
, &hw_bp_details_reported
);
3030 target_terminal::ours_for_output ();
3031 error_stream (tmp_error_stream
);
3035 /* Used when starting or continuing the program. */
3038 insert_breakpoint_locations (void)
3040 struct bp_location
*bl
, **blp_tmp
;
3043 int disabled_breaks
= 0;
3044 int hw_breakpoint_error
= 0;
3045 int hw_bp_error_explained_already
= 0;
3047 string_file tmp_error_stream
;
3049 /* Explicitly mark the warning -- this will only be printed if
3050 there was an error. */
3051 tmp_error_stream
.puts ("Warning:\n");
3053 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3055 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3057 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3060 /* There is no point inserting thread-specific breakpoints if
3061 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3062 has BL->OWNER always non-NULL. */
3063 if (bl
->owner
->thread
!= -1
3064 && !valid_global_thread_id (bl
->owner
->thread
))
3067 switch_to_program_space_and_thread (bl
->pspace
);
3069 /* For targets that support global breakpoints, there's no need
3070 to select an inferior to insert breakpoint to. In fact, even
3071 if we aren't attached to any process yet, we should still
3072 insert breakpoints. */
3073 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3074 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3077 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3078 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3083 /* If we failed to insert all locations of a watchpoint, remove
3084 them, as half-inserted watchpoint is of limited use. */
3085 for (breakpoint
*bpt
: all_breakpoints ())
3087 int some_failed
= 0;
3088 struct bp_location
*loc
;
3090 if (!is_hardware_watchpoint (bpt
))
3093 if (!breakpoint_enabled (bpt
))
3096 if (bpt
->disposition
== disp_del_at_next_stop
)
3099 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3100 if (!loc
->inserted
&& should_be_inserted (loc
))
3107 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3109 remove_breakpoint (loc
);
3111 hw_breakpoint_error
= 1;
3112 tmp_error_stream
.printf ("Could not insert "
3113 "hardware watchpoint %d.\n",
3121 /* If a hardware breakpoint or watchpoint was inserted, add a
3122 message about possibly exhausted resources. */
3123 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3125 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3126 You may have requested too many hardware breakpoints/watchpoints.\n");
3128 target_terminal::ours_for_output ();
3129 error_stream (tmp_error_stream
);
3133 /* Used when the program stops.
3134 Returns zero if successful, or non-zero if there was a problem
3135 removing a breakpoint location. */
3138 remove_breakpoints (void)
3140 struct bp_location
*bl
, **blp_tmp
;
3143 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3145 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3146 val
|= remove_breakpoint (bl
);
3151 /* When a thread exits, remove breakpoints that are related to
3155 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3157 for (breakpoint
*b
: all_breakpoints_safe ())
3159 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3161 b
->disposition
= disp_del_at_next_stop
;
3163 printf_filtered (_("\
3164 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3165 b
->number
, print_thread_id (tp
));
3167 /* Hide it from the user. */
3173 /* See breakpoint.h. */
3176 remove_breakpoints_inf (inferior
*inf
)
3178 struct bp_location
*bl
, **blp_tmp
;
3181 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3183 if (bl
->pspace
!= inf
->pspace
)
3186 if (bl
->inserted
&& !bl
->target_info
.persist
)
3188 val
= remove_breakpoint (bl
);
3195 static int internal_breakpoint_number
= -1;
3197 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3198 If INTERNAL is non-zero, the breakpoint number will be populated
3199 from internal_breakpoint_number and that variable decremented.
3200 Otherwise the breakpoint number will be populated from
3201 breakpoint_count and that value incremented. Internal breakpoints
3202 do not set the internal var bpnum. */
3204 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3207 b
->number
= internal_breakpoint_number
--;
3210 set_breakpoint_count (breakpoint_count
+ 1);
3211 b
->number
= breakpoint_count
;
3215 static struct breakpoint
*
3216 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3217 CORE_ADDR address
, enum bptype type
,
3218 const struct breakpoint_ops
*ops
)
3220 symtab_and_line sal
;
3222 sal
.section
= find_pc_overlay (sal
.pc
);
3223 sal
.pspace
= current_program_space
;
3225 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3226 b
->number
= internal_breakpoint_number
--;
3227 b
->disposition
= disp_donttouch
;
3232 static const char *const longjmp_names
[] =
3234 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3236 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3238 /* Per-objfile data private to breakpoint.c. */
3239 struct breakpoint_objfile_data
3241 /* Minimal symbol for "_ovly_debug_event" (if any). */
3242 struct bound_minimal_symbol overlay_msym
{};
3244 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3245 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3247 /* True if we have looked for longjmp probes. */
3248 int longjmp_searched
= 0;
3250 /* SystemTap probe points for longjmp (if any). These are non-owning
3252 std::vector
<probe
*> longjmp_probes
;
3254 /* Minimal symbol for "std::terminate()" (if any). */
3255 struct bound_minimal_symbol terminate_msym
{};
3257 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3258 struct bound_minimal_symbol exception_msym
{};
3260 /* True if we have looked for exception probes. */
3261 int exception_searched
= 0;
3263 /* SystemTap probe points for unwinding (if any). These are non-owning
3265 std::vector
<probe
*> exception_probes
;
3268 static const struct objfile_key
<breakpoint_objfile_data
>
3269 breakpoint_objfile_key
;
3271 /* Minimal symbol not found sentinel. */
3272 static struct minimal_symbol msym_not_found
;
3274 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3277 msym_not_found_p (const struct minimal_symbol
*msym
)
3279 return msym
== &msym_not_found
;
3282 /* Return per-objfile data needed by breakpoint.c.
3283 Allocate the data if necessary. */
3285 static struct breakpoint_objfile_data
*
3286 get_breakpoint_objfile_data (struct objfile
*objfile
)
3288 struct breakpoint_objfile_data
*bp_objfile_data
;
3290 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3291 if (bp_objfile_data
== NULL
)
3292 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3293 return bp_objfile_data
;
3297 create_overlay_event_breakpoint (void)
3299 const char *const func_name
= "_ovly_debug_event";
3301 for (objfile
*objfile
: current_program_space
->objfiles ())
3303 struct breakpoint
*b
;
3304 struct breakpoint_objfile_data
*bp_objfile_data
;
3306 struct explicit_location explicit_loc
;
3308 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3310 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3313 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3315 struct bound_minimal_symbol m
;
3317 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3318 if (m
.minsym
== NULL
)
3320 /* Avoid future lookups in this objfile. */
3321 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3324 bp_objfile_data
->overlay_msym
= m
;
3327 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3328 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3330 &internal_breakpoint_ops
);
3331 initialize_explicit_location (&explicit_loc
);
3332 explicit_loc
.function_name
= ASTRDUP (func_name
);
3333 b
->location
= new_explicit_location (&explicit_loc
);
3335 if (overlay_debugging
== ovly_auto
)
3337 b
->enable_state
= bp_enabled
;
3338 overlay_events_enabled
= 1;
3342 b
->enable_state
= bp_disabled
;
3343 overlay_events_enabled
= 0;
3348 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3349 true if a breakpoint was installed. */
3352 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3354 struct gdbarch
*gdbarch
= objfile
->arch ();
3355 struct breakpoint_objfile_data
*bp_objfile_data
3356 = get_breakpoint_objfile_data (objfile
);
3358 if (!bp_objfile_data
->longjmp_searched
)
3360 std::vector
<probe
*> ret
3361 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3365 /* We are only interested in checking one element. */
3368 if (!p
->can_evaluate_arguments ())
3370 /* We cannot use the probe interface here,
3371 because it does not know how to evaluate
3376 bp_objfile_data
->longjmp_probes
= ret
;
3377 bp_objfile_data
->longjmp_searched
= 1;
3380 if (bp_objfile_data
->longjmp_probes
.empty ())
3383 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3385 struct breakpoint
*b
;
3387 b
= create_internal_breakpoint (gdbarch
,
3388 p
->get_relocated_address (objfile
),
3390 &internal_breakpoint_ops
);
3391 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3392 b
->enable_state
= bp_disabled
;
3398 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3399 Return true if at least one breakpoint was installed. */
3402 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3404 struct gdbarch
*gdbarch
= objfile
->arch ();
3405 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3408 struct breakpoint_objfile_data
*bp_objfile_data
3409 = get_breakpoint_objfile_data (objfile
);
3410 unsigned int installed_bp
= 0;
3412 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3414 struct breakpoint
*b
;
3415 const char *func_name
;
3417 struct explicit_location explicit_loc
;
3419 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3422 func_name
= longjmp_names
[i
];
3423 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3425 struct bound_minimal_symbol m
;
3427 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3428 if (m
.minsym
== NULL
)
3430 /* Prevent future lookups in this objfile. */
3431 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3434 bp_objfile_data
->longjmp_msym
[i
] = m
;
3437 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3438 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3439 &internal_breakpoint_ops
);
3440 initialize_explicit_location (&explicit_loc
);
3441 explicit_loc
.function_name
= ASTRDUP (func_name
);
3442 b
->location
= new_explicit_location (&explicit_loc
);
3443 b
->enable_state
= bp_disabled
;
3447 return installed_bp
> 0;
3450 /* Create a master longjmp breakpoint. */
3453 create_longjmp_master_breakpoint (void)
3455 scoped_restore_current_program_space restore_pspace
;
3457 for (struct program_space
*pspace
: program_spaces
)
3459 set_current_program_space (pspace
);
3461 for (objfile
*obj
: current_program_space
->objfiles ())
3463 /* Skip separate debug object, it's handled in the loop below. */
3464 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3467 /* Try a probe kind breakpoint on main objfile. */
3468 if (create_longjmp_master_breakpoint_probe (obj
))
3471 /* Try longjmp_names kind breakpoints on main and separate_debug
3473 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3474 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3480 /* Create a master std::terminate breakpoint. */
3482 create_std_terminate_master_breakpoint (void)
3484 const char *const func_name
= "std::terminate()";
3486 scoped_restore_current_program_space restore_pspace
;
3488 for (struct program_space
*pspace
: program_spaces
)
3492 set_current_program_space (pspace
);
3494 for (objfile
*objfile
: current_program_space
->objfiles ())
3496 struct breakpoint
*b
;
3497 struct breakpoint_objfile_data
*bp_objfile_data
;
3498 struct explicit_location explicit_loc
;
3500 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3502 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3505 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3507 struct bound_minimal_symbol m
;
3509 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3510 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3511 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3513 /* Prevent future lookups in this objfile. */
3514 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3517 bp_objfile_data
->terminate_msym
= m
;
3520 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3521 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3522 bp_std_terminate_master
,
3523 &internal_breakpoint_ops
);
3524 initialize_explicit_location (&explicit_loc
);
3525 explicit_loc
.function_name
= ASTRDUP (func_name
);
3526 b
->location
= new_explicit_location (&explicit_loc
);
3527 b
->enable_state
= bp_disabled
;
3532 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3533 probe. Return true if a breakpoint was installed. */
3536 create_exception_master_breakpoint_probe (objfile
*objfile
)
3538 struct breakpoint
*b
;
3539 struct gdbarch
*gdbarch
;
3540 struct breakpoint_objfile_data
*bp_objfile_data
;
3542 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3544 /* We prefer the SystemTap probe point if it exists. */
3545 if (!bp_objfile_data
->exception_searched
)
3547 std::vector
<probe
*> ret
3548 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3552 /* We are only interested in checking one element. */
3555 if (!p
->can_evaluate_arguments ())
3557 /* We cannot use the probe interface here, because it does
3558 not know how to evaluate arguments. */
3562 bp_objfile_data
->exception_probes
= ret
;
3563 bp_objfile_data
->exception_searched
= 1;
3566 if (bp_objfile_data
->exception_probes
.empty ())
3569 gdbarch
= objfile
->arch ();
3571 for (probe
*p
: bp_objfile_data
->exception_probes
)
3573 b
= create_internal_breakpoint (gdbarch
,
3574 p
->get_relocated_address (objfile
),
3575 bp_exception_master
,
3576 &internal_breakpoint_ops
);
3577 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3578 b
->enable_state
= bp_disabled
;
3584 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3585 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3588 create_exception_master_breakpoint_hook (objfile
*objfile
)
3590 const char *const func_name
= "_Unwind_DebugHook";
3591 struct breakpoint
*b
;
3592 struct gdbarch
*gdbarch
;
3593 struct breakpoint_objfile_data
*bp_objfile_data
;
3595 struct explicit_location explicit_loc
;
3597 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3599 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3602 gdbarch
= objfile
->arch ();
3604 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3606 struct bound_minimal_symbol debug_hook
;
3608 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3609 if (debug_hook
.minsym
== NULL
)
3611 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3615 bp_objfile_data
->exception_msym
= debug_hook
;
3618 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3619 addr
= gdbarch_convert_from_func_ptr_addr
3620 (gdbarch
, addr
, current_inferior ()->top_target ());
3621 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3622 &internal_breakpoint_ops
);
3623 initialize_explicit_location (&explicit_loc
);
3624 explicit_loc
.function_name
= ASTRDUP (func_name
);
3625 b
->location
= new_explicit_location (&explicit_loc
);
3626 b
->enable_state
= bp_disabled
;
3631 /* Install a master breakpoint on the unwinder's debug hook. */
3634 create_exception_master_breakpoint (void)
3636 for (objfile
*obj
: current_program_space
->objfiles ())
3638 /* Skip separate debug object. */
3639 if (obj
->separate_debug_objfile_backlink
)
3642 /* Try a probe kind breakpoint. */
3643 if (create_exception_master_breakpoint_probe (obj
))
3646 /* Iterate over main and separate debug objects and try an
3647 _Unwind_DebugHook kind breakpoint. */
3648 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3649 if (create_exception_master_breakpoint_hook (debug_objfile
))
3654 /* Does B have a location spec? */
3657 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3659 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3663 update_breakpoints_after_exec (void)
3665 struct bp_location
*bploc
, **bplocp_tmp
;
3667 /* We're about to delete breakpoints from GDB's lists. If the
3668 INSERTED flag is true, GDB will try to lift the breakpoints by
3669 writing the breakpoints' "shadow contents" back into memory. The
3670 "shadow contents" are NOT valid after an exec, so GDB should not
3671 do that. Instead, the target is responsible from marking
3672 breakpoints out as soon as it detects an exec. We don't do that
3673 here instead, because there may be other attempts to delete
3674 breakpoints after detecting an exec and before reaching here. */
3675 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3676 if (bploc
->pspace
== current_program_space
)
3677 gdb_assert (!bploc
->inserted
);
3679 for (breakpoint
*b
: all_breakpoints_safe ())
3681 if (b
->pspace
!= current_program_space
)
3684 /* Solib breakpoints must be explicitly reset after an exec(). */
3685 if (b
->type
== bp_shlib_event
)
3687 delete_breakpoint (b
);
3691 /* JIT breakpoints must be explicitly reset after an exec(). */
3692 if (b
->type
== bp_jit_event
)
3694 delete_breakpoint (b
);
3698 /* Thread event breakpoints must be set anew after an exec(),
3699 as must overlay event and longjmp master breakpoints. */
3700 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3701 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3702 || b
->type
== bp_exception_master
)
3704 delete_breakpoint (b
);
3708 /* Step-resume breakpoints are meaningless after an exec(). */
3709 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3711 delete_breakpoint (b
);
3715 /* Just like single-step breakpoints. */
3716 if (b
->type
== bp_single_step
)
3718 delete_breakpoint (b
);
3722 /* Longjmp and longjmp-resume breakpoints are also meaningless
3724 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3725 || b
->type
== bp_longjmp_call_dummy
3726 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3728 delete_breakpoint (b
);
3732 if (b
->type
== bp_catchpoint
)
3734 /* For now, none of the bp_catchpoint breakpoints need to
3735 do anything at this point. In the future, if some of
3736 the catchpoints need to something, we will need to add
3737 a new method, and call this method from here. */
3741 /* bp_finish is a special case. The only way we ought to be able
3742 to see one of these when an exec() has happened, is if the user
3743 caught a vfork, and then said "finish". Ordinarily a finish just
3744 carries them to the call-site of the current callee, by setting
3745 a temporary bp there and resuming. But in this case, the finish
3746 will carry them entirely through the vfork & exec.
3748 We don't want to allow a bp_finish to remain inserted now. But
3749 we can't safely delete it, 'cause finish_command has a handle to
3750 the bp on a bpstat, and will later want to delete it. There's a
3751 chance (and I've seen it happen) that if we delete the bp_finish
3752 here, that its storage will get reused by the time finish_command
3753 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3754 We really must allow finish_command to delete a bp_finish.
3756 In the absence of a general solution for the "how do we know
3757 it's safe to delete something others may have handles to?"
3758 problem, what we'll do here is just uninsert the bp_finish, and
3759 let finish_command delete it.
3761 (We know the bp_finish is "doomed" in the sense that it's
3762 momentary, and will be deleted as soon as finish_command sees
3763 the inferior stopped. So it doesn't matter that the bp's
3764 address is probably bogus in the new a.out, unlike e.g., the
3765 solib breakpoints.) */
3767 if (b
->type
== bp_finish
)
3772 /* Without a symbolic address, we have little hope of the
3773 pre-exec() address meaning the same thing in the post-exec()
3775 if (breakpoint_event_location_empty_p (b
))
3777 delete_breakpoint (b
);
3784 detach_breakpoints (ptid_t ptid
)
3786 struct bp_location
*bl
, **blp_tmp
;
3788 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3789 struct inferior
*inf
= current_inferior ();
3791 if (ptid
.pid () == inferior_ptid
.pid ())
3792 error (_("Cannot detach breakpoints of inferior_ptid"));
3794 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3795 inferior_ptid
= ptid
;
3796 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3798 if (bl
->pspace
!= inf
->pspace
)
3801 /* This function must physically remove breakpoints locations
3802 from the specified ptid, without modifying the breakpoint
3803 package's state. Locations of type bp_loc_other are only
3804 maintained at GDB side. So, there is no need to remove
3805 these bp_loc_other locations. Moreover, removing these
3806 would modify the breakpoint package's state. */
3807 if (bl
->loc_type
== bp_loc_other
)
3811 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3817 /* Remove the breakpoint location BL from the current address space.
3818 Note that this is used to detach breakpoints from a child fork.
3819 When we get here, the child isn't in the inferior list, and neither
3820 do we have objects to represent its address space --- we should
3821 *not* look at bl->pspace->aspace here. */
3824 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3828 /* BL is never in moribund_locations by our callers. */
3829 gdb_assert (bl
->owner
!= NULL
);
3831 /* The type of none suggests that owner is actually deleted.
3832 This should not ever happen. */
3833 gdb_assert (bl
->owner
->type
!= bp_none
);
3835 if (bl
->loc_type
== bp_loc_software_breakpoint
3836 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3838 /* "Normal" instruction breakpoint: either the standard
3839 trap-instruction bp (bp_breakpoint), or a
3840 bp_hardware_breakpoint. */
3842 /* First check to see if we have to handle an overlay. */
3843 if (overlay_debugging
== ovly_off
3844 || bl
->section
== NULL
3845 || !(section_is_overlay (bl
->section
)))
3847 /* No overlay handling: just remove the breakpoint. */
3849 /* If we're trying to uninsert a memory breakpoint that we
3850 know is set in a dynamic object that is marked
3851 shlib_disabled, then either the dynamic object was
3852 removed with "remove-symbol-file" or with
3853 "nosharedlibrary". In the former case, we don't know
3854 whether another dynamic object might have loaded over the
3855 breakpoint's address -- the user might well let us know
3856 about it next with add-symbol-file (the whole point of
3857 add-symbol-file is letting the user manually maintain a
3858 list of dynamically loaded objects). If we have the
3859 breakpoint's shadow memory, that is, this is a software
3860 breakpoint managed by GDB, check whether the breakpoint
3861 is still inserted in memory, to avoid overwriting wrong
3862 code with stale saved shadow contents. Note that HW
3863 breakpoints don't have shadow memory, as they're
3864 implemented using a mechanism that is not dependent on
3865 being able to modify the target's memory, and as such
3866 they should always be removed. */
3867 if (bl
->shlib_disabled
3868 && bl
->target_info
.shadow_len
!= 0
3869 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3872 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3876 /* This breakpoint is in an overlay section.
3877 Did we set a breakpoint at the LMA? */
3878 if (!overlay_events_enabled
)
3880 /* Yes -- overlay event support is not active, so we
3881 should have set a breakpoint at the LMA. Remove it.
3883 /* Ignore any failures: if the LMA is in ROM, we will
3884 have already warned when we failed to insert it. */
3885 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3886 target_remove_hw_breakpoint (bl
->gdbarch
,
3887 &bl
->overlay_target_info
);
3889 target_remove_breakpoint (bl
->gdbarch
,
3890 &bl
->overlay_target_info
,
3893 /* Did we set a breakpoint at the VMA?
3894 If so, we will have marked the breakpoint 'inserted'. */
3897 /* Yes -- remove it. Previously we did not bother to
3898 remove the breakpoint if the section had been
3899 unmapped, but let's not rely on that being safe. We
3900 don't know what the overlay manager might do. */
3902 /* However, we should remove *software* breakpoints only
3903 if the section is still mapped, or else we overwrite
3904 wrong code with the saved shadow contents. */
3905 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3906 || section_is_mapped (bl
->section
))
3907 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3913 /* No -- not inserted, so no need to remove. No error. */
3918 /* In some cases, we might not be able to remove a breakpoint in
3919 a shared library that has already been removed, but we have
3920 not yet processed the shlib unload event. Similarly for an
3921 unloaded add-symbol-file object - the user might not yet have
3922 had the chance to remove-symbol-file it. shlib_disabled will
3923 be set if the library/object has already been removed, but
3924 the breakpoint hasn't been uninserted yet, e.g., after
3925 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3926 always-inserted mode. */
3928 && (bl
->loc_type
== bp_loc_software_breakpoint
3929 && (bl
->shlib_disabled
3930 || solib_name_from_address (bl
->pspace
, bl
->address
)
3931 || shared_objfile_contains_address_p (bl
->pspace
,
3937 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3939 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3941 gdb_assert (bl
->owner
->ops
!= NULL
3942 && bl
->owner
->ops
->remove_location
!= NULL
);
3944 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3945 bl
->owner
->ops
->remove_location (bl
, reason
);
3947 /* Failure to remove any of the hardware watchpoints comes here. */
3948 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3949 warning (_("Could not remove hardware watchpoint %d."),
3952 else if (bl
->owner
->type
== bp_catchpoint
3953 && breakpoint_enabled (bl
->owner
)
3956 gdb_assert (bl
->owner
->ops
!= NULL
3957 && bl
->owner
->ops
->remove_location
!= NULL
);
3959 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3963 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3970 remove_breakpoint (struct bp_location
*bl
)
3972 /* BL is never in moribund_locations by our callers. */
3973 gdb_assert (bl
->owner
!= NULL
);
3975 /* The type of none suggests that owner is actually deleted.
3976 This should not ever happen. */
3977 gdb_assert (bl
->owner
->type
!= bp_none
);
3979 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3981 switch_to_program_space_and_thread (bl
->pspace
);
3983 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3986 /* Clear the "inserted" flag in all breakpoints. */
3989 mark_breakpoints_out (void)
3991 struct bp_location
*bl
, **blp_tmp
;
3993 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3994 if (bl
->pspace
== current_program_space
)
3998 /* Clear the "inserted" flag in all breakpoints and delete any
3999 breakpoints which should go away between runs of the program.
4001 Plus other such housekeeping that has to be done for breakpoints
4004 Note: this function gets called at the end of a run (by
4005 generic_mourn_inferior) and when a run begins (by
4006 init_wait_for_inferior). */
4011 breakpoint_init_inferior (enum inf_context context
)
4013 struct program_space
*pspace
= current_program_space
;
4015 /* If breakpoint locations are shared across processes, then there's
4017 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4020 mark_breakpoints_out ();
4022 for (breakpoint
*b
: all_breakpoints_safe ())
4024 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4030 case bp_longjmp_call_dummy
:
4032 /* If the call dummy breakpoint is at the entry point it will
4033 cause problems when the inferior is rerun, so we better get
4036 case bp_watchpoint_scope
:
4038 /* Also get rid of scope breakpoints. */
4040 case bp_shlib_event
:
4042 /* Also remove solib event breakpoints. Their addresses may
4043 have changed since the last time we ran the program.
4044 Actually we may now be debugging against different target;
4045 and so the solib backend that installed this breakpoint may
4046 not be used in by the target. E.g.,
4048 (gdb) file prog-linux
4049 (gdb) run # native linux target
4052 (gdb) file prog-win.exe
4053 (gdb) tar rem :9999 # remote Windows gdbserver.
4056 case bp_step_resume
:
4058 /* Also remove step-resume breakpoints. */
4060 case bp_single_step
:
4062 /* Also remove single-step breakpoints. */
4064 delete_breakpoint (b
);
4068 case bp_hardware_watchpoint
:
4069 case bp_read_watchpoint
:
4070 case bp_access_watchpoint
:
4072 struct watchpoint
*w
= (struct watchpoint
*) b
;
4074 /* Likewise for watchpoints on local expressions. */
4075 if (w
->exp_valid_block
!= NULL
)
4076 delete_breakpoint (b
);
4079 /* Get rid of existing locations, which are no longer
4080 valid. New ones will be created in
4081 update_watchpoint, when the inferior is restarted.
4082 The next update_global_location_list call will
4083 garbage collect them. */
4086 if (context
== inf_starting
)
4088 /* Reset val field to force reread of starting value in
4089 insert_breakpoints. */
4090 w
->val
.reset (nullptr);
4091 w
->val_valid
= false;
4101 /* Get rid of the moribund locations. */
4102 for (bp_location
*bl
: moribund_locations
)
4103 decref_bp_location (&bl
);
4104 moribund_locations
.clear ();
4107 /* These functions concern about actual breakpoints inserted in the
4108 target --- to e.g. check if we need to do decr_pc adjustment or if
4109 we need to hop over the bkpt --- so we check for address space
4110 match, not program space. */
4112 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4113 exists at PC. It returns ordinary_breakpoint_here if it's an
4114 ordinary breakpoint, or permanent_breakpoint_here if it's a
4115 permanent breakpoint.
4116 - When continuing from a location with an ordinary breakpoint, we
4117 actually single step once before calling insert_breakpoints.
4118 - When continuing from a location with a permanent breakpoint, we
4119 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4120 the target, to advance the PC past the breakpoint. */
4122 enum breakpoint_here
4123 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4125 struct bp_location
*bl
, **blp_tmp
;
4126 int any_breakpoint_here
= 0;
4128 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4130 if (bl
->loc_type
!= bp_loc_software_breakpoint
4131 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4134 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4135 if ((breakpoint_enabled (bl
->owner
)
4137 && breakpoint_location_address_match (bl
, aspace
, pc
))
4139 if (overlay_debugging
4140 && section_is_overlay (bl
->section
)
4141 && !section_is_mapped (bl
->section
))
4142 continue; /* unmapped overlay -- can't be a match */
4143 else if (bl
->permanent
)
4144 return permanent_breakpoint_here
;
4146 any_breakpoint_here
= 1;
4150 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4153 /* See breakpoint.h. */
4156 breakpoint_in_range_p (const address_space
*aspace
,
4157 CORE_ADDR addr
, ULONGEST len
)
4159 struct bp_location
*bl
, **blp_tmp
;
4161 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4163 if (bl
->loc_type
!= bp_loc_software_breakpoint
4164 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4167 if ((breakpoint_enabled (bl
->owner
)
4169 && breakpoint_location_address_range_overlap (bl
, aspace
,
4172 if (overlay_debugging
4173 && section_is_overlay (bl
->section
)
4174 && !section_is_mapped (bl
->section
))
4176 /* Unmapped overlay -- can't be a match. */
4187 /* Return true if there's a moribund breakpoint at PC. */
4190 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4192 for (bp_location
*loc
: moribund_locations
)
4193 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4199 /* Returns non-zero iff BL is inserted at PC, in address space
4203 bp_location_inserted_here_p (struct bp_location
*bl
,
4204 const address_space
*aspace
, CORE_ADDR pc
)
4207 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4210 if (overlay_debugging
4211 && section_is_overlay (bl
->section
)
4212 && !section_is_mapped (bl
->section
))
4213 return 0; /* unmapped overlay -- can't be a match */
4220 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4223 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4225 struct bp_location
**blp
, **blp_tmp
= NULL
;
4227 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4229 struct bp_location
*bl
= *blp
;
4231 if (bl
->loc_type
!= bp_loc_software_breakpoint
4232 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4235 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4241 /* This function returns non-zero iff there is a software breakpoint
4245 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4248 struct bp_location
**blp
, **blp_tmp
= NULL
;
4250 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4252 struct bp_location
*bl
= *blp
;
4254 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4257 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4264 /* See breakpoint.h. */
4267 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4270 struct bp_location
**blp
, **blp_tmp
= NULL
;
4272 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4274 struct bp_location
*bl
= *blp
;
4276 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4279 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4287 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4288 CORE_ADDR addr
, ULONGEST len
)
4290 for (breakpoint
*bpt
: all_breakpoints ())
4292 struct bp_location
*loc
;
4294 if (bpt
->type
!= bp_hardware_watchpoint
4295 && bpt
->type
!= bp_access_watchpoint
)
4298 if (!breakpoint_enabled (bpt
))
4301 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4302 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4306 /* Check for intersection. */
4307 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4308 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4316 /* See breakpoint.h. */
4319 is_catchpoint (struct breakpoint
*b
)
4321 return (b
->type
== bp_catchpoint
);
4324 /* Clear a bpstat so that it says we are not at any breakpoint.
4325 Also free any storage that is part of a bpstat. */
4328 bpstat_clear (bpstat
*bsp
)
4345 bpstats::bpstats (const bpstats
&other
)
4347 bp_location_at (other
.bp_location_at
),
4348 breakpoint_at (other
.breakpoint_at
),
4349 commands (other
.commands
),
4350 print (other
.print
),
4352 print_it (other
.print_it
)
4354 if (other
.old_val
!= NULL
)
4355 old_val
= release_value (value_copy (other
.old_val
.get ()));
4358 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4359 is part of the bpstat is copied as well. */
4362 bpstat_copy (bpstat bs
)
4366 bpstat retval
= NULL
;
4371 for (; bs
!= NULL
; bs
= bs
->next
)
4373 tmp
= new bpstats (*bs
);
4376 /* This is the first thing in the chain. */
4386 /* Find the bpstat associated with this breakpoint. */
4389 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4394 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4396 if (bsp
->breakpoint_at
== breakpoint
)
4402 /* See breakpoint.h. */
4405 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4407 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4409 if (bsp
->breakpoint_at
== NULL
)
4411 /* A moribund location can never explain a signal other than
4413 if (sig
== GDB_SIGNAL_TRAP
)
4418 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4427 /* Put in *NUM the breakpoint number of the first breakpoint we are
4428 stopped at. *BSP upon return is a bpstat which points to the
4429 remaining breakpoints stopped at (but which is not guaranteed to be
4430 good for anything but further calls to bpstat_num).
4432 Return 0 if passed a bpstat which does not indicate any breakpoints.
4433 Return -1 if stopped at a breakpoint that has been deleted since
4435 Return 1 otherwise. */
4438 bpstat_num (bpstat
*bsp
, int *num
)
4440 struct breakpoint
*b
;
4443 return 0; /* No more breakpoint values */
4445 /* We assume we'll never have several bpstats that correspond to a
4446 single breakpoint -- otherwise, this function might return the
4447 same number more than once and this will look ugly. */
4448 b
= (*bsp
)->breakpoint_at
;
4449 *bsp
= (*bsp
)->next
;
4451 return -1; /* breakpoint that's been deleted since */
4453 *num
= b
->number
; /* We have its number */
4457 /* See breakpoint.h. */
4460 bpstat_clear_actions (void)
4464 if (inferior_ptid
== null_ptid
)
4467 thread_info
*tp
= inferior_thread ();
4468 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4470 bs
->commands
= NULL
;
4471 bs
->old_val
.reset (nullptr);
4475 /* Called when a command is about to proceed the inferior. */
4478 breakpoint_about_to_proceed (void)
4480 if (inferior_ptid
!= null_ptid
)
4482 struct thread_info
*tp
= inferior_thread ();
4484 /* Allow inferior function calls in breakpoint commands to not
4485 interrupt the command list. When the call finishes
4486 successfully, the inferior will be standing at the same
4487 breakpoint as if nothing happened. */
4488 if (tp
->control
.in_infcall
)
4492 breakpoint_proceeded
= 1;
4495 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4496 or its equivalent. */
4499 command_line_is_silent (struct command_line
*cmd
)
4501 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4504 /* Execute all the commands associated with all the breakpoints at
4505 this location. Any of these commands could cause the process to
4506 proceed beyond this point, etc. We look out for such changes by
4507 checking the global "breakpoint_proceeded" after each command.
4509 Returns true if a breakpoint command resumed the inferior. In that
4510 case, it is the caller's responsibility to recall it again with the
4511 bpstat of the current thread. */
4514 bpstat_do_actions_1 (bpstat
*bsp
)
4519 /* Avoid endless recursion if a `source' command is contained
4521 if (executing_breakpoint_commands
)
4524 scoped_restore save_executing
4525 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4527 scoped_restore preventer
= prevent_dont_repeat ();
4529 /* This pointer will iterate over the list of bpstat's. */
4532 breakpoint_proceeded
= 0;
4533 for (; bs
!= NULL
; bs
= bs
->next
)
4535 struct command_line
*cmd
= NULL
;
4537 /* Take ownership of the BSP's command tree, if it has one.
4539 The command tree could legitimately contain commands like
4540 'step' and 'next', which call clear_proceed_status, which
4541 frees stop_bpstat's command tree. To make sure this doesn't
4542 free the tree we're executing out from under us, we need to
4543 take ownership of the tree ourselves. Since a given bpstat's
4544 commands are only executed once, we don't need to copy it; we
4545 can clear the pointer in the bpstat, and make sure we free
4546 the tree when we're done. */
4547 counted_command_line ccmd
= bs
->commands
;
4548 bs
->commands
= NULL
;
4551 if (command_line_is_silent (cmd
))
4553 /* The action has been already done by bpstat_stop_status. */
4559 execute_control_command (cmd
);
4561 if (breakpoint_proceeded
)
4567 if (breakpoint_proceeded
)
4569 if (current_ui
->async
)
4570 /* If we are in async mode, then the target might be still
4571 running, not stopped at any breakpoint, so nothing for
4572 us to do here -- just return to the event loop. */
4575 /* In sync mode, when execute_control_command returns
4576 we're already standing on the next breakpoint.
4577 Breakpoint commands for that stop were not run, since
4578 execute_command does not run breakpoint commands --
4579 only command_line_handler does, but that one is not
4580 involved in execution of breakpoint commands. So, we
4581 can now execute breakpoint commands. It should be
4582 noted that making execute_command do bpstat actions is
4583 not an option -- in this case we'll have recursive
4584 invocation of bpstat for each breakpoint with a
4585 command, and can easily blow up GDB stack. Instead, we
4586 return true, which will trigger the caller to recall us
4587 with the new stop_bpstat. */
4595 /* Helper for bpstat_do_actions. Get the current thread, if there's
4596 one, is alive and has execution. Return NULL otherwise. */
4598 static thread_info
*
4599 get_bpstat_thread ()
4601 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4604 thread_info
*tp
= inferior_thread ();
4605 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4611 bpstat_do_actions (void)
4613 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4616 /* Do any commands attached to breakpoint we are stopped at. */
4617 while ((tp
= get_bpstat_thread ()) != NULL
)
4619 /* Since in sync mode, bpstat_do_actions may resume the
4620 inferior, and only return when it is stopped at the next
4621 breakpoint, we keep doing breakpoint actions until it returns
4622 false to indicate the inferior was not resumed. */
4623 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4627 cleanup_if_error
.release ();
4630 /* Print out the (old or new) value associated with a watchpoint. */
4633 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4636 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4639 struct value_print_options opts
;
4640 get_user_print_options (&opts
);
4641 value_print (val
, stream
, &opts
);
4645 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4646 debugging multiple threads. */
4649 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4651 if (uiout
->is_mi_like_p ())
4656 if (show_thread_that_caused_stop ())
4659 struct thread_info
*thr
= inferior_thread ();
4661 uiout
->text ("Thread ");
4662 uiout
->field_string ("thread-id", print_thread_id (thr
));
4664 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4667 uiout
->text (" \"");
4668 uiout
->field_string ("name", name
);
4672 uiout
->text (" hit ");
4676 /* Generic routine for printing messages indicating why we
4677 stopped. The behavior of this function depends on the value
4678 'print_it' in the bpstat structure. Under some circumstances we
4679 may decide not to print anything here and delegate the task to
4682 static enum print_stop_action
4683 print_bp_stop_message (bpstat bs
)
4685 switch (bs
->print_it
)
4688 /* Nothing should be printed for this bpstat entry. */
4689 return PRINT_UNKNOWN
;
4693 /* We still want to print the frame, but we already printed the
4694 relevant messages. */
4695 return PRINT_SRC_AND_LOC
;
4698 case print_it_normal
:
4700 struct breakpoint
*b
= bs
->breakpoint_at
;
4702 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4703 which has since been deleted. */
4705 return PRINT_UNKNOWN
;
4707 /* Normal case. Call the breakpoint's print_it method. */
4708 return b
->ops
->print_it (bs
);
4713 internal_error (__FILE__
, __LINE__
,
4714 _("print_bp_stop_message: unrecognized enum value"));
4719 /* A helper function that prints a shared library stopped event. */
4722 print_solib_event (int is_catchpoint
)
4724 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4725 bool any_added
= !current_program_space
->added_solibs
.empty ();
4729 if (any_added
|| any_deleted
)
4730 current_uiout
->text (_("Stopped due to shared library event:\n"));
4732 current_uiout
->text (_("Stopped due to shared library event (no "
4733 "libraries added or removed)\n"));
4736 if (current_uiout
->is_mi_like_p ())
4737 current_uiout
->field_string ("reason",
4738 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4742 current_uiout
->text (_(" Inferior unloaded "));
4743 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4744 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4746 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4749 current_uiout
->text (" ");
4750 current_uiout
->field_string ("library", name
);
4751 current_uiout
->text ("\n");
4757 current_uiout
->text (_(" Inferior loaded "));
4758 ui_out_emit_list
list_emitter (current_uiout
, "added");
4760 for (so_list
*iter
: current_program_space
->added_solibs
)
4763 current_uiout
->text (" ");
4765 current_uiout
->field_string ("library", iter
->so_name
);
4766 current_uiout
->text ("\n");
4771 /* Print a message indicating what happened. This is called from
4772 normal_stop(). The input to this routine is the head of the bpstat
4773 list - a list of the eventpoints that caused this stop. KIND is
4774 the target_waitkind for the stopping event. This
4775 routine calls the generic print routine for printing a message
4776 about reasons for stopping. This will print (for example) the
4777 "Breakpoint n," part of the output. The return value of this
4780 PRINT_UNKNOWN: Means we printed nothing.
4781 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4782 code to print the location. An example is
4783 "Breakpoint 1, " which should be followed by
4785 PRINT_SRC_ONLY: Means we printed something, but there is no need
4786 to also print the location part of the message.
4787 An example is the catch/throw messages, which
4788 don't require a location appended to the end.
4789 PRINT_NOTHING: We have done some printing and we don't need any
4790 further info to be printed. */
4792 enum print_stop_action
4793 bpstat_print (bpstat bs
, int kind
)
4795 enum print_stop_action val
;
4797 /* Maybe another breakpoint in the chain caused us to stop.
4798 (Currently all watchpoints go on the bpstat whether hit or not.
4799 That probably could (should) be changed, provided care is taken
4800 with respect to bpstat_explains_signal). */
4801 for (; bs
; bs
= bs
->next
)
4803 val
= print_bp_stop_message (bs
);
4804 if (val
== PRINT_SRC_ONLY
4805 || val
== PRINT_SRC_AND_LOC
4806 || val
== PRINT_NOTHING
)
4810 /* If we had hit a shared library event breakpoint,
4811 print_bp_stop_message would print out this message. If we hit an
4812 OS-level shared library event, do the same thing. */
4813 if (kind
== TARGET_WAITKIND_LOADED
)
4815 print_solib_event (0);
4816 return PRINT_NOTHING
;
4819 /* We reached the end of the chain, or we got a null BS to start
4820 with and nothing was printed. */
4821 return PRINT_UNKNOWN
;
4824 /* Evaluate the boolean expression EXP and return the result. */
4827 breakpoint_cond_eval (expression
*exp
)
4829 struct value
*mark
= value_mark ();
4830 bool res
= value_true (evaluate_expression (exp
));
4832 value_free_to_mark (mark
);
4836 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4838 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4840 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4841 breakpoint_at (bl
->owner
),
4845 print_it (print_it_normal
)
4847 **bs_link_pointer
= this;
4848 *bs_link_pointer
= &next
;
4853 breakpoint_at (NULL
),
4857 print_it (print_it_normal
)
4861 /* The target has stopped with waitstatus WS. Check if any hardware
4862 watchpoints have triggered, according to the target. */
4865 watchpoints_triggered (struct target_waitstatus
*ws
)
4867 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4870 if (!stopped_by_watchpoint
)
4872 /* We were not stopped by a watchpoint. Mark all watchpoints
4873 as not triggered. */
4874 for (breakpoint
*b
: all_breakpoints ())
4875 if (is_hardware_watchpoint (b
))
4877 struct watchpoint
*w
= (struct watchpoint
*) b
;
4879 w
->watchpoint_triggered
= watch_triggered_no
;
4885 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4887 /* We were stopped by a watchpoint, but we don't know where.
4888 Mark all watchpoints as unknown. */
4889 for (breakpoint
*b
: all_breakpoints ())
4890 if (is_hardware_watchpoint (b
))
4892 struct watchpoint
*w
= (struct watchpoint
*) b
;
4894 w
->watchpoint_triggered
= watch_triggered_unknown
;
4900 /* The target could report the data address. Mark watchpoints
4901 affected by this data address as triggered, and all others as not
4904 for (breakpoint
*b
: all_breakpoints ())
4905 if (is_hardware_watchpoint (b
))
4907 struct watchpoint
*w
= (struct watchpoint
*) b
;
4908 struct bp_location
*loc
;
4910 w
->watchpoint_triggered
= watch_triggered_no
;
4911 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4913 if (is_masked_watchpoint (b
))
4915 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4916 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4918 if (newaddr
== start
)
4920 w
->watchpoint_triggered
= watch_triggered_yes
;
4924 /* Exact match not required. Within range is sufficient. */
4925 else if (target_watchpoint_addr_within_range
4926 (current_inferior ()->top_target (), addr
, loc
->address
,
4929 w
->watchpoint_triggered
= watch_triggered_yes
;
4938 /* Possible return values for watchpoint_check. */
4939 enum wp_check_result
4941 /* The watchpoint has been deleted. */
4944 /* The value has changed. */
4945 WP_VALUE_CHANGED
= 2,
4947 /* The value has not changed. */
4948 WP_VALUE_NOT_CHANGED
= 3,
4950 /* Ignore this watchpoint, no matter if the value changed or not. */
4954 #define BP_TEMPFLAG 1
4955 #define BP_HARDWAREFLAG 2
4957 /* Evaluate watchpoint condition expression and check if its value
4960 static wp_check_result
4961 watchpoint_check (bpstat bs
)
4963 struct watchpoint
*b
;
4964 struct frame_info
*fr
;
4965 int within_current_scope
;
4967 /* BS is built from an existing struct breakpoint. */
4968 gdb_assert (bs
->breakpoint_at
!= NULL
);
4969 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4971 /* If this is a local watchpoint, we only want to check if the
4972 watchpoint frame is in scope if the current thread is the thread
4973 that was used to create the watchpoint. */
4974 if (!watchpoint_in_thread_scope (b
))
4977 if (b
->exp_valid_block
== NULL
)
4978 within_current_scope
= 1;
4981 struct frame_info
*frame
= get_current_frame ();
4982 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4983 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4985 /* stack_frame_destroyed_p() returns a non-zero value if we're
4986 still in the function but the stack frame has already been
4987 invalidated. Since we can't rely on the values of local
4988 variables after the stack has been destroyed, we are treating
4989 the watchpoint in that state as `not changed' without further
4990 checking. Don't mark watchpoints as changed if the current
4991 frame is in an epilogue - even if they are in some other
4992 frame, our view of the stack is likely to be wrong and
4993 frame_find_by_id could error out. */
4994 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4997 fr
= frame_find_by_id (b
->watchpoint_frame
);
4998 within_current_scope
= (fr
!= NULL
);
5000 /* If we've gotten confused in the unwinder, we might have
5001 returned a frame that can't describe this variable. */
5002 if (within_current_scope
)
5004 struct symbol
*function
;
5006 function
= get_frame_function (fr
);
5007 if (function
== NULL
5008 || !contained_in (b
->exp_valid_block
,
5009 SYMBOL_BLOCK_VALUE (function
)))
5010 within_current_scope
= 0;
5013 if (within_current_scope
)
5014 /* If we end up stopping, the current frame will get selected
5015 in normal_stop. So this call to select_frame won't affect
5020 if (within_current_scope
)
5022 /* We use value_{,free_to_}mark because it could be a *long*
5023 time before we return to the command level and call
5024 free_all_values. We can't call free_all_values because we
5025 might be in the middle of evaluating a function call. */
5028 struct value
*new_val
;
5030 if (is_masked_watchpoint (b
))
5031 /* Since we don't know the exact trigger address (from
5032 stopped_data_address), just tell the user we've triggered
5033 a mask watchpoint. */
5034 return WP_VALUE_CHANGED
;
5036 mark
= value_mark ();
5037 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5040 if (b
->val_bitsize
!= 0)
5041 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5043 /* We use value_equal_contents instead of value_equal because
5044 the latter coerces an array to a pointer, thus comparing just
5045 the address of the array instead of its contents. This is
5046 not what we want. */
5047 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5048 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5051 bs
->old_val
= b
->val
;
5052 b
->val
= release_value (new_val
);
5053 b
->val_valid
= true;
5054 if (new_val
!= NULL
)
5055 value_free_to_mark (mark
);
5056 return WP_VALUE_CHANGED
;
5060 /* Nothing changed. */
5061 value_free_to_mark (mark
);
5062 return WP_VALUE_NOT_CHANGED
;
5067 /* This seems like the only logical thing to do because
5068 if we temporarily ignored the watchpoint, then when
5069 we reenter the block in which it is valid it contains
5070 garbage (in the case of a function, it may have two
5071 garbage values, one before and one after the prologue).
5072 So we can't even detect the first assignment to it and
5073 watch after that (since the garbage may or may not equal
5074 the first value assigned). */
5075 /* We print all the stop information in
5076 breakpoint_ops->print_it, but in this case, by the time we
5077 call breakpoint_ops->print_it this bp will be deleted
5078 already. So we have no choice but print the information
5081 SWITCH_THRU_ALL_UIS ()
5083 struct ui_out
*uiout
= current_uiout
;
5085 if (uiout
->is_mi_like_p ())
5087 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5088 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5089 "left the block in\n"
5090 "which its expression is valid.\n",
5091 signed_field ("wpnum", b
->number
));
5094 /* Make sure the watchpoint's commands aren't executed. */
5096 watchpoint_del_at_next_stop (b
);
5102 /* Return true if it looks like target has stopped due to hitting
5103 breakpoint location BL. This function does not check if we should
5104 stop, only if BL explains the stop. */
5107 bpstat_check_location (const struct bp_location
*bl
,
5108 const address_space
*aspace
, CORE_ADDR bp_addr
,
5109 const struct target_waitstatus
*ws
)
5111 struct breakpoint
*b
= bl
->owner
;
5113 /* BL is from an existing breakpoint. */
5114 gdb_assert (b
!= NULL
);
5116 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5119 /* Determine if the watched values have actually changed, and we
5120 should stop. If not, set BS->stop to 0. */
5123 bpstat_check_watchpoint (bpstat bs
)
5125 const struct bp_location
*bl
;
5126 struct watchpoint
*b
;
5128 /* BS is built for existing struct breakpoint. */
5129 bl
= bs
->bp_location_at
.get ();
5130 gdb_assert (bl
!= NULL
);
5131 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5132 gdb_assert (b
!= NULL
);
5135 int must_check_value
= 0;
5137 if (b
->type
== bp_watchpoint
)
5138 /* For a software watchpoint, we must always check the
5140 must_check_value
= 1;
5141 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5142 /* We have a hardware watchpoint (read, write, or access)
5143 and the target earlier reported an address watched by
5145 must_check_value
= 1;
5146 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5147 && b
->type
== bp_hardware_watchpoint
)
5148 /* We were stopped by a hardware watchpoint, but the target could
5149 not report the data address. We must check the watchpoint's
5150 value. Access and read watchpoints are out of luck; without
5151 a data address, we can't figure it out. */
5152 must_check_value
= 1;
5154 if (must_check_value
)
5160 e
= watchpoint_check (bs
);
5162 catch (const gdb_exception
&ex
)
5164 exception_fprintf (gdb_stderr
, ex
,
5165 "Error evaluating expression "
5166 "for watchpoint %d\n",
5169 SWITCH_THRU_ALL_UIS ()
5171 printf_filtered (_("Watchpoint %d deleted.\n"),
5174 watchpoint_del_at_next_stop (b
);
5181 /* We've already printed what needs to be printed. */
5182 bs
->print_it
= print_it_done
;
5186 bs
->print_it
= print_it_noop
;
5189 case WP_VALUE_CHANGED
:
5190 if (b
->type
== bp_read_watchpoint
)
5192 /* There are two cases to consider here:
5194 1. We're watching the triggered memory for reads.
5195 In that case, trust the target, and always report
5196 the watchpoint hit to the user. Even though
5197 reads don't cause value changes, the value may
5198 have changed since the last time it was read, and
5199 since we're not trapping writes, we will not see
5200 those, and as such we should ignore our notion of
5203 2. We're watching the triggered memory for both
5204 reads and writes. There are two ways this may
5207 2.1. This is a target that can't break on data
5208 reads only, but can break on accesses (reads or
5209 writes), such as e.g., x86. We detect this case
5210 at the time we try to insert read watchpoints.
5212 2.2. Otherwise, the target supports read
5213 watchpoints, but, the user set an access or write
5214 watchpoint watching the same memory as this read
5217 If we're watching memory writes as well as reads,
5218 ignore watchpoint hits when we find that the
5219 value hasn't changed, as reads don't cause
5220 changes. This still gives false positives when
5221 the program writes the same value to memory as
5222 what there was already in memory (we will confuse
5223 it for a read), but it's much better than
5226 int other_write_watchpoint
= 0;
5228 if (bl
->watchpoint_type
== hw_read
)
5230 for (breakpoint
*other_b
: all_breakpoints ())
5231 if (other_b
->type
== bp_hardware_watchpoint
5232 || other_b
->type
== bp_access_watchpoint
)
5234 struct watchpoint
*other_w
=
5235 (struct watchpoint
*) other_b
;
5237 if (other_w
->watchpoint_triggered
5238 == watch_triggered_yes
)
5240 other_write_watchpoint
= 1;
5246 if (other_write_watchpoint
5247 || bl
->watchpoint_type
== hw_access
)
5249 /* We're watching the same memory for writes,
5250 and the value changed since the last time we
5251 updated it, so this trap must be for a write.
5253 bs
->print_it
= print_it_noop
;
5258 case WP_VALUE_NOT_CHANGED
:
5259 if (b
->type
== bp_hardware_watchpoint
5260 || b
->type
== bp_watchpoint
)
5262 /* Don't stop: write watchpoints shouldn't fire if
5263 the value hasn't changed. */
5264 bs
->print_it
= print_it_noop
;
5274 else /* must_check_value == 0 */
5276 /* This is a case where some watchpoint(s) triggered, but
5277 not at the address of this watchpoint, or else no
5278 watchpoint triggered after all. So don't print
5279 anything for this watchpoint. */
5280 bs
->print_it
= print_it_noop
;
5286 /* For breakpoints that are currently marked as telling gdb to stop,
5287 check conditions (condition proper, frame, thread and ignore count)
5288 of breakpoint referred to by BS. If we should not stop for this
5289 breakpoint, set BS->stop to 0. */
5292 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5294 const struct bp_location
*bl
;
5295 struct breakpoint
*b
;
5297 bool condition_result
= true;
5298 struct expression
*cond
;
5300 gdb_assert (bs
->stop
);
5302 /* BS is built for existing struct breakpoint. */
5303 bl
= bs
->bp_location_at
.get ();
5304 gdb_assert (bl
!= NULL
);
5305 b
= bs
->breakpoint_at
;
5306 gdb_assert (b
!= NULL
);
5308 /* Even if the target evaluated the condition on its end and notified GDB, we
5309 need to do so again since GDB does not know if we stopped due to a
5310 breakpoint or a single step breakpoint. */
5312 if (frame_id_p (b
->frame_id
)
5313 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5319 /* If this is a thread/task-specific breakpoint, don't waste cpu
5320 evaluating the condition if this isn't the specified
5322 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5323 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5329 /* Evaluate extension language breakpoints that have a "stop" method
5331 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5333 if (is_watchpoint (b
))
5335 struct watchpoint
*w
= (struct watchpoint
*) b
;
5337 cond
= w
->cond_exp
.get ();
5340 cond
= bl
->cond
.get ();
5342 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5344 int within_current_scope
= 1;
5345 struct watchpoint
* w
;
5347 /* We use value_mark and value_free_to_mark because it could
5348 be a long time before we return to the command level and
5349 call free_all_values. We can't call free_all_values
5350 because we might be in the middle of evaluating a
5352 struct value
*mark
= value_mark ();
5354 if (is_watchpoint (b
))
5355 w
= (struct watchpoint
*) b
;
5359 /* Need to select the frame, with all that implies so that
5360 the conditions will have the right context. Because we
5361 use the frame, we will not see an inlined function's
5362 variables when we arrive at a breakpoint at the start
5363 of the inlined function; the current frame will be the
5365 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5366 select_frame (get_current_frame ());
5369 struct frame_info
*frame
;
5371 /* For local watchpoint expressions, which particular
5372 instance of a local is being watched matters, so we
5373 keep track of the frame to evaluate the expression
5374 in. To evaluate the condition however, it doesn't
5375 really matter which instantiation of the function
5376 where the condition makes sense triggers the
5377 watchpoint. This allows an expression like "watch
5378 global if q > 10" set in `func', catch writes to
5379 global on all threads that call `func', or catch
5380 writes on all recursive calls of `func' by a single
5381 thread. We simply always evaluate the condition in
5382 the innermost frame that's executing where it makes
5383 sense to evaluate the condition. It seems
5385 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5387 select_frame (frame
);
5389 within_current_scope
= 0;
5391 if (within_current_scope
)
5395 condition_result
= breakpoint_cond_eval (cond
);
5397 catch (const gdb_exception
&ex
)
5399 exception_fprintf (gdb_stderr
, ex
,
5400 "Error in testing breakpoint condition:\n");
5405 warning (_("Watchpoint condition cannot be tested "
5406 "in the current scope"));
5407 /* If we failed to set the right context for this
5408 watchpoint, unconditionally report it. */
5410 /* FIXME-someday, should give breakpoint #. */
5411 value_free_to_mark (mark
);
5414 if (cond
&& !condition_result
)
5418 else if (b
->ignore_count
> 0)
5422 /* Increase the hit count even though we don't stop. */
5424 gdb::observers::breakpoint_modified
.notify (b
);
5428 /* Returns true if we need to track moribund locations of LOC's type
5429 on the current target. */
5432 need_moribund_for_location_type (struct bp_location
*loc
)
5434 return ((loc
->loc_type
== bp_loc_software_breakpoint
5435 && !target_supports_stopped_by_sw_breakpoint ())
5436 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5437 && !target_supports_stopped_by_hw_breakpoint ()));
5440 /* See breakpoint.h. */
5443 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5444 const struct target_waitstatus
*ws
)
5446 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5448 for (breakpoint
*b
: all_breakpoints ())
5450 if (!breakpoint_enabled (b
))
5453 for (bp_location
*bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5455 /* For hardware watchpoints, we look only at the first
5456 location. The watchpoint_check function will work on the
5457 entire expression, not the individual locations. For
5458 read watchpoints, the watchpoints_triggered function has
5459 checked all locations already. */
5460 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5463 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5466 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5469 /* Come here if it's a watchpoint, or if the break address
5472 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5475 /* Assume we stop. Should we find a watchpoint that is not
5476 actually triggered, or if the condition of the breakpoint
5477 evaluates as false, we'll reset 'stop' to 0. */
5481 /* If this is a scope breakpoint, mark the associated
5482 watchpoint as triggered so that we will handle the
5483 out-of-scope event. We'll get to the watchpoint next
5485 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5487 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5489 w
->watchpoint_triggered
= watch_triggered_yes
;
5494 /* Check if a moribund breakpoint explains the stop. */
5495 if (!target_supports_stopped_by_sw_breakpoint ()
5496 || !target_supports_stopped_by_hw_breakpoint ())
5498 for (bp_location
*loc
: moribund_locations
)
5500 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5501 && need_moribund_for_location_type (loc
))
5503 bpstat bs
= new bpstats (loc
, &bs_link
);
5504 /* For hits of moribund locations, we should just proceed. */
5507 bs
->print_it
= print_it_noop
;
5515 /* See breakpoint.h. */
5518 bpstat_stop_status (const address_space
*aspace
,
5519 CORE_ADDR bp_addr
, thread_info
*thread
,
5520 const struct target_waitstatus
*ws
,
5523 struct breakpoint
*b
= NULL
;
5524 /* First item of allocated bpstat's. */
5525 bpstat bs_head
= stop_chain
;
5527 int need_remove_insert
;
5530 /* First, build the bpstat chain with locations that explain a
5531 target stop, while being careful to not set the target running,
5532 as that may invalidate locations (in particular watchpoint
5533 locations are recreated). Resuming will happen here with
5534 breakpoint conditions or watchpoint expressions that include
5535 inferior function calls. */
5536 if (bs_head
== NULL
)
5537 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5539 /* A bit of special processing for shlib breakpoints. We need to
5540 process solib loading here, so that the lists of loaded and
5541 unloaded libraries are correct before we handle "catch load" and
5543 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5545 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5547 handle_solib_event ();
5552 /* Now go through the locations that caused the target to stop, and
5553 check whether we're interested in reporting this stop to higher
5554 layers, or whether we should resume the target transparently. */
5558 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5563 b
= bs
->breakpoint_at
;
5564 b
->ops
->check_status (bs
);
5567 bpstat_check_breakpoint_conditions (bs
, thread
);
5572 gdb::observers::breakpoint_modified
.notify (b
);
5574 /* We will stop here. */
5575 if (b
->disposition
== disp_disable
)
5577 --(b
->enable_count
);
5578 if (b
->enable_count
<= 0)
5579 b
->enable_state
= bp_disabled
;
5584 bs
->commands
= b
->commands
;
5585 if (command_line_is_silent (bs
->commands
5586 ? bs
->commands
.get () : NULL
))
5589 b
->ops
->after_condition_true (bs
);
5594 /* Print nothing for this entry if we don't stop or don't
5596 if (!bs
->stop
|| !bs
->print
)
5597 bs
->print_it
= print_it_noop
;
5600 /* If we aren't stopping, the value of some hardware watchpoint may
5601 not have changed, but the intermediate memory locations we are
5602 watching may have. Don't bother if we're stopping; this will get
5604 need_remove_insert
= 0;
5605 if (! bpstat_causes_stop (bs_head
))
5606 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5608 && bs
->breakpoint_at
5609 && is_hardware_watchpoint (bs
->breakpoint_at
))
5611 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5613 update_watchpoint (w
, 0 /* don't reparse. */);
5614 need_remove_insert
= 1;
5617 if (need_remove_insert
)
5618 update_global_location_list (UGLL_MAY_INSERT
);
5619 else if (removed_any
)
5620 update_global_location_list (UGLL_DONT_INSERT
);
5626 handle_jit_event (CORE_ADDR address
)
5628 struct gdbarch
*gdbarch
;
5630 infrun_debug_printf ("handling bp_jit_event");
5632 /* Switch terminal for any messages produced by
5633 breakpoint_re_set. */
5634 target_terminal::ours_for_output ();
5636 gdbarch
= get_frame_arch (get_current_frame ());
5637 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5638 thus it is expected that its objectfile can be found through
5639 minimal symbol lookup. If it doesn't work (and assert fails), it
5640 most likely means that `jit_breakpoint_re_set` was changes and this
5641 function needs to be updated too. */
5642 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5643 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5644 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5646 target_terminal::inferior ();
5649 /* Prepare WHAT final decision for infrun. */
5651 /* Decide what infrun needs to do with this bpstat. */
5654 bpstat_what (bpstat bs_head
)
5656 struct bpstat_what retval
;
5659 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5660 retval
.call_dummy
= STOP_NONE
;
5661 retval
.is_longjmp
= false;
5663 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5665 /* Extract this BS's action. After processing each BS, we check
5666 if its action overrides all we've seem so far. */
5667 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5670 if (bs
->breakpoint_at
== NULL
)
5672 /* I suspect this can happen if it was a momentary
5673 breakpoint which has since been deleted. */
5677 bptype
= bs
->breakpoint_at
->type
;
5684 case bp_hardware_breakpoint
:
5685 case bp_single_step
:
5688 case bp_shlib_event
:
5692 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5694 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5697 this_action
= BPSTAT_WHAT_SINGLE
;
5700 case bp_hardware_watchpoint
:
5701 case bp_read_watchpoint
:
5702 case bp_access_watchpoint
:
5706 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5708 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5712 /* There was a watchpoint, but we're not stopping.
5713 This requires no further action. */
5717 case bp_longjmp_call_dummy
:
5721 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5722 retval
.is_longjmp
= bptype
!= bp_exception
;
5725 this_action
= BPSTAT_WHAT_SINGLE
;
5727 case bp_longjmp_resume
:
5728 case bp_exception_resume
:
5731 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5732 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5735 this_action
= BPSTAT_WHAT_SINGLE
;
5737 case bp_step_resume
:
5739 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5742 /* It is for the wrong frame. */
5743 this_action
= BPSTAT_WHAT_SINGLE
;
5746 case bp_hp_step_resume
:
5748 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5751 /* It is for the wrong frame. */
5752 this_action
= BPSTAT_WHAT_SINGLE
;
5755 case bp_watchpoint_scope
:
5756 case bp_thread_event
:
5757 case bp_overlay_event
:
5758 case bp_longjmp_master
:
5759 case bp_std_terminate_master
:
5760 case bp_exception_master
:
5761 this_action
= BPSTAT_WHAT_SINGLE
;
5767 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5769 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5773 /* Some catchpoints are implemented with breakpoints.
5774 For those, we need to step over the breakpoint. */
5775 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5776 this_action
= BPSTAT_WHAT_SINGLE
;
5780 this_action
= BPSTAT_WHAT_SINGLE
;
5783 /* Make sure the action is stop (silent or noisy),
5784 so infrun.c pops the dummy frame. */
5785 retval
.call_dummy
= STOP_STACK_DUMMY
;
5786 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5788 case bp_std_terminate
:
5789 /* Make sure the action is stop (silent or noisy),
5790 so infrun.c pops the dummy frame. */
5791 retval
.call_dummy
= STOP_STD_TERMINATE
;
5792 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5795 case bp_fast_tracepoint
:
5796 case bp_static_tracepoint
:
5797 /* Tracepoint hits should not be reported back to GDB, and
5798 if one got through somehow, it should have been filtered
5800 internal_error (__FILE__
, __LINE__
,
5801 _("bpstat_what: tracepoint encountered"));
5803 case bp_gnu_ifunc_resolver
:
5804 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5805 this_action
= BPSTAT_WHAT_SINGLE
;
5807 case bp_gnu_ifunc_resolver_return
:
5808 /* The breakpoint will be removed, execution will restart from the
5809 PC of the former breakpoint. */
5810 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5815 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5817 this_action
= BPSTAT_WHAT_SINGLE
;
5821 internal_error (__FILE__
, __LINE__
,
5822 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5825 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5832 bpstat_run_callbacks (bpstat bs_head
)
5836 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5838 struct breakpoint
*b
= bs
->breakpoint_at
;
5845 handle_jit_event (bs
->bp_location_at
->address
);
5847 case bp_gnu_ifunc_resolver
:
5848 gnu_ifunc_resolver_stop (b
);
5850 case bp_gnu_ifunc_resolver_return
:
5851 gnu_ifunc_resolver_return_stop (b
);
5857 /* See breakpoint.h. */
5860 bpstat_should_step ()
5862 for (breakpoint
*b
: all_breakpoints ())
5863 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5869 /* See breakpoint.h. */
5872 bpstat_causes_stop (bpstat bs
)
5874 for (; bs
!= NULL
; bs
= bs
->next
)
5883 /* Compute a string of spaces suitable to indent the next line
5884 so it starts at the position corresponding to the table column
5885 named COL_NAME in the currently active table of UIOUT. */
5888 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5890 static char wrap_indent
[80];
5891 int i
, total_width
, width
, align
;
5895 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5897 if (strcmp (text
, col_name
) == 0)
5899 gdb_assert (total_width
< sizeof wrap_indent
);
5900 memset (wrap_indent
, ' ', total_width
);
5901 wrap_indent
[total_width
] = 0;
5906 total_width
+= width
+ 1;
5912 /* Determine if the locations of this breakpoint will have their conditions
5913 evaluated by the target, host or a mix of both. Returns the following:
5915 "host": Host evals condition.
5916 "host or target": Host or Target evals condition.
5917 "target": Target evals condition.
5921 bp_condition_evaluator (struct breakpoint
*b
)
5923 struct bp_location
*bl
;
5924 char host_evals
= 0;
5925 char target_evals
= 0;
5930 if (!is_breakpoint (b
))
5933 if (gdb_evaluates_breakpoint_condition_p ()
5934 || !target_supports_evaluation_of_breakpoint_conditions ())
5935 return condition_evaluation_host
;
5937 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5939 if (bl
->cond_bytecode
)
5945 if (host_evals
&& target_evals
)
5946 return condition_evaluation_both
;
5947 else if (target_evals
)
5948 return condition_evaluation_target
;
5950 return condition_evaluation_host
;
5953 /* Determine the breakpoint location's condition evaluator. This is
5954 similar to bp_condition_evaluator, but for locations. */
5957 bp_location_condition_evaluator (struct bp_location
*bl
)
5959 if (bl
&& !is_breakpoint (bl
->owner
))
5962 if (gdb_evaluates_breakpoint_condition_p ()
5963 || !target_supports_evaluation_of_breakpoint_conditions ())
5964 return condition_evaluation_host
;
5966 if (bl
&& bl
->cond_bytecode
)
5967 return condition_evaluation_target
;
5969 return condition_evaluation_host
;
5972 /* Print the LOC location out of the list of B->LOC locations. */
5975 print_breakpoint_location (struct breakpoint
*b
,
5976 struct bp_location
*loc
)
5978 struct ui_out
*uiout
= current_uiout
;
5980 scoped_restore_current_program_space restore_pspace
;
5982 if (loc
!= NULL
&& loc
->shlib_disabled
)
5986 set_current_program_space (loc
->pspace
);
5988 if (b
->display_canonical
)
5989 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5990 else if (loc
&& loc
->symtab
)
5992 const struct symbol
*sym
= loc
->symbol
;
5996 uiout
->text ("in ");
5997 uiout
->field_string ("func", sym
->print_name (),
5998 function_name_style
.style ());
6000 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6001 uiout
->text ("at ");
6003 uiout
->field_string ("file",
6004 symtab_to_filename_for_display (loc
->symtab
),
6005 file_name_style
.style ());
6008 if (uiout
->is_mi_like_p ())
6009 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6011 uiout
->field_signed ("line", loc
->line_number
);
6017 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6019 uiout
->field_stream ("at", stb
);
6023 uiout
->field_string ("pending",
6024 event_location_to_string (b
->location
.get ()));
6025 /* If extra_string is available, it could be holding a condition
6026 or dprintf arguments. In either case, make sure it is printed,
6027 too, but only for non-MI streams. */
6028 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6030 if (b
->type
== bp_dprintf
)
6034 uiout
->text (b
->extra_string
);
6038 if (loc
&& is_breakpoint (b
)
6039 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6040 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6043 uiout
->field_string ("evaluated-by",
6044 bp_location_condition_evaluator (loc
));
6050 bptype_string (enum bptype type
)
6052 struct ep_type_description
6055 const char *description
;
6057 static struct ep_type_description bptypes
[] =
6059 {bp_none
, "?deleted?"},
6060 {bp_breakpoint
, "breakpoint"},
6061 {bp_hardware_breakpoint
, "hw breakpoint"},
6062 {bp_single_step
, "sw single-step"},
6063 {bp_until
, "until"},
6064 {bp_finish
, "finish"},
6065 {bp_watchpoint
, "watchpoint"},
6066 {bp_hardware_watchpoint
, "hw watchpoint"},
6067 {bp_read_watchpoint
, "read watchpoint"},
6068 {bp_access_watchpoint
, "acc watchpoint"},
6069 {bp_longjmp
, "longjmp"},
6070 {bp_longjmp_resume
, "longjmp resume"},
6071 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6072 {bp_exception
, "exception"},
6073 {bp_exception_resume
, "exception resume"},
6074 {bp_step_resume
, "step resume"},
6075 {bp_hp_step_resume
, "high-priority step resume"},
6076 {bp_watchpoint_scope
, "watchpoint scope"},
6077 {bp_call_dummy
, "call dummy"},
6078 {bp_std_terminate
, "std::terminate"},
6079 {bp_shlib_event
, "shlib events"},
6080 {bp_thread_event
, "thread events"},
6081 {bp_overlay_event
, "overlay events"},
6082 {bp_longjmp_master
, "longjmp master"},
6083 {bp_std_terminate_master
, "std::terminate master"},
6084 {bp_exception_master
, "exception master"},
6085 {bp_catchpoint
, "catchpoint"},
6086 {bp_tracepoint
, "tracepoint"},
6087 {bp_fast_tracepoint
, "fast tracepoint"},
6088 {bp_static_tracepoint
, "static tracepoint"},
6089 {bp_dprintf
, "dprintf"},
6090 {bp_jit_event
, "jit events"},
6091 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6092 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6095 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6096 || ((int) type
!= bptypes
[(int) type
].type
))
6097 internal_error (__FILE__
, __LINE__
,
6098 _("bptypes table does not describe type #%d."),
6101 return bptypes
[(int) type
].description
;
6104 /* For MI, output a field named 'thread-groups' with a list as the value.
6105 For CLI, prefix the list with the string 'inf'. */
6108 output_thread_groups (struct ui_out
*uiout
,
6109 const char *field_name
,
6110 const std::vector
<int> &inf_nums
,
6113 int is_mi
= uiout
->is_mi_like_p ();
6115 /* For backward compatibility, don't display inferiors in CLI unless
6116 there are several. Always display them for MI. */
6117 if (!is_mi
&& mi_only
)
6120 ui_out_emit_list
list_emitter (uiout
, field_name
);
6122 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6128 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6129 uiout
->field_string (NULL
, mi_group
);
6134 uiout
->text (" inf ");
6138 uiout
->text (plongest (inf_nums
[i
]));
6143 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6144 instead of going via breakpoint_ops::print_one. This makes "maint
6145 info breakpoints" show the software breakpoint locations of
6146 catchpoints, which are considered internal implementation
6150 print_one_breakpoint_location (struct breakpoint
*b
,
6151 struct bp_location
*loc
,
6153 struct bp_location
**last_loc
,
6154 int allflag
, bool raw_loc
)
6156 struct command_line
*l
;
6157 static char bpenables
[] = "nynny";
6159 struct ui_out
*uiout
= current_uiout
;
6160 int header_of_multiple
= 0;
6161 int part_of_multiple
= (loc
!= NULL
);
6162 struct value_print_options opts
;
6164 get_user_print_options (&opts
);
6166 gdb_assert (!loc
|| loc_number
!= 0);
6167 /* See comment in print_one_breakpoint concerning treatment of
6168 breakpoints with single disabled location. */
6171 && (b
->loc
->next
!= NULL
6172 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6173 header_of_multiple
= 1;
6181 if (part_of_multiple
)
6182 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6184 uiout
->field_signed ("number", b
->number
);
6188 if (part_of_multiple
)
6189 uiout
->field_skip ("type");
6191 uiout
->field_string ("type", bptype_string (b
->type
));
6195 if (part_of_multiple
)
6196 uiout
->field_skip ("disp");
6198 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6202 /* For locations that are disabled because of an invalid condition,
6203 display "N*" on CLI, where "*" refers to a footnote below the
6204 table. For MI, simply display a "N" without a footnote. */
6205 const char *N
= (uiout
->is_mi_like_p ()) ? "N" : "N*";
6206 if (part_of_multiple
)
6207 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? N
6208 : (loc
->enabled
? "y" : "n")));
6210 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6213 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6214 b
->ops
->print_one (b
, last_loc
);
6217 if (is_watchpoint (b
))
6219 struct watchpoint
*w
= (struct watchpoint
*) b
;
6221 /* Field 4, the address, is omitted (which makes the columns
6222 not line up too nicely with the headers, but the effect
6223 is relatively readable). */
6224 if (opts
.addressprint
)
6225 uiout
->field_skip ("addr");
6227 uiout
->field_string ("what", w
->exp_string
);
6229 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6230 || is_ada_exception_catchpoint (b
))
6232 if (opts
.addressprint
)
6235 if (header_of_multiple
)
6236 uiout
->field_string ("addr", "<MULTIPLE>",
6237 metadata_style
.style ());
6238 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6239 uiout
->field_string ("addr", "<PENDING>",
6240 metadata_style
.style ());
6242 uiout
->field_core_addr ("addr",
6243 loc
->gdbarch
, loc
->address
);
6246 if (!header_of_multiple
)
6247 print_breakpoint_location (b
, loc
);
6253 if (loc
!= NULL
&& !header_of_multiple
)
6255 std::vector
<int> inf_nums
;
6258 for (inferior
*inf
: all_inferiors ())
6260 if (inf
->pspace
== loc
->pspace
)
6261 inf_nums
.push_back (inf
->num
);
6264 /* For backward compatibility, don't display inferiors in CLI unless
6265 there are several. Always display for MI. */
6267 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6268 && (program_spaces
.size () > 1
6269 || number_of_inferiors () > 1)
6270 /* LOC is for existing B, it cannot be in
6271 moribund_locations and thus having NULL OWNER. */
6272 && loc
->owner
->type
!= bp_catchpoint
))
6274 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6277 if (!part_of_multiple
)
6279 if (b
->thread
!= -1)
6281 /* FIXME: This seems to be redundant and lost here; see the
6282 "stop only in" line a little further down. */
6283 uiout
->text (" thread ");
6284 uiout
->field_signed ("thread", b
->thread
);
6286 else if (b
->task
!= 0)
6288 uiout
->text (" task ");
6289 uiout
->field_signed ("task", b
->task
);
6295 if (!part_of_multiple
)
6296 b
->ops
->print_one_detail (b
, uiout
);
6298 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6301 uiout
->text ("\tstop only in stack frame at ");
6302 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6304 uiout
->field_core_addr ("frame",
6305 b
->gdbarch
, b
->frame_id
.stack_addr
);
6309 if (!part_of_multiple
&& b
->cond_string
)
6312 if (is_tracepoint (b
))
6313 uiout
->text ("\ttrace only if ");
6315 uiout
->text ("\tstop only if ");
6316 uiout
->field_string ("cond", b
->cond_string
);
6318 /* Print whether the target is doing the breakpoint's condition
6319 evaluation. If GDB is doing the evaluation, don't print anything. */
6320 if (is_breakpoint (b
)
6321 && breakpoint_condition_evaluation_mode ()
6322 == condition_evaluation_target
)
6324 uiout
->message (" (%pF evals)",
6325 string_field ("evaluated-by",
6326 bp_condition_evaluator (b
)));
6331 if (!part_of_multiple
&& b
->thread
!= -1)
6333 /* FIXME should make an annotation for this. */
6334 uiout
->text ("\tstop only in thread ");
6335 if (uiout
->is_mi_like_p ())
6336 uiout
->field_signed ("thread", b
->thread
);
6339 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6341 uiout
->field_string ("thread", print_thread_id (thr
));
6346 if (!part_of_multiple
)
6350 /* FIXME should make an annotation for this. */
6351 if (is_catchpoint (b
))
6352 uiout
->text ("\tcatchpoint");
6353 else if (is_tracepoint (b
))
6354 uiout
->text ("\ttracepoint");
6356 uiout
->text ("\tbreakpoint");
6357 uiout
->text (" already hit ");
6358 uiout
->field_signed ("times", b
->hit_count
);
6359 if (b
->hit_count
== 1)
6360 uiout
->text (" time\n");
6362 uiout
->text (" times\n");
6366 /* Output the count also if it is zero, but only if this is mi. */
6367 if (uiout
->is_mi_like_p ())
6368 uiout
->field_signed ("times", b
->hit_count
);
6372 if (!part_of_multiple
&& b
->ignore_count
)
6375 uiout
->message ("\tignore next %pF hits\n",
6376 signed_field ("ignore", b
->ignore_count
));
6379 /* Note that an enable count of 1 corresponds to "enable once"
6380 behavior, which is reported by the combination of enablement and
6381 disposition, so we don't need to mention it here. */
6382 if (!part_of_multiple
&& b
->enable_count
> 1)
6385 uiout
->text ("\tdisable after ");
6386 /* Tweak the wording to clarify that ignore and enable counts
6387 are distinct, and have additive effect. */
6388 if (b
->ignore_count
)
6389 uiout
->text ("additional ");
6391 uiout
->text ("next ");
6392 uiout
->field_signed ("enable", b
->enable_count
);
6393 uiout
->text (" hits\n");
6396 if (!part_of_multiple
&& is_tracepoint (b
))
6398 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6400 if (tp
->traceframe_usage
)
6402 uiout
->text ("\ttrace buffer usage ");
6403 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6404 uiout
->text (" bytes\n");
6408 l
= b
->commands
? b
->commands
.get () : NULL
;
6409 if (!part_of_multiple
&& l
)
6412 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6413 print_command_lines (uiout
, l
, 4);
6416 if (is_tracepoint (b
))
6418 struct tracepoint
*t
= (struct tracepoint
*) b
;
6420 if (!part_of_multiple
&& t
->pass_count
)
6422 annotate_field (10);
6423 uiout
->text ("\tpass count ");
6424 uiout
->field_signed ("pass", t
->pass_count
);
6425 uiout
->text (" \n");
6428 /* Don't display it when tracepoint or tracepoint location is
6430 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6432 annotate_field (11);
6434 if (uiout
->is_mi_like_p ())
6435 uiout
->field_string ("installed",
6436 loc
->inserted
? "y" : "n");
6442 uiout
->text ("\tnot ");
6443 uiout
->text ("installed on target\n");
6448 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6450 if (is_watchpoint (b
))
6452 struct watchpoint
*w
= (struct watchpoint
*) b
;
6454 uiout
->field_string ("original-location", w
->exp_string
);
6456 else if (b
->location
!= NULL
6457 && event_location_to_string (b
->location
.get ()) != NULL
)
6458 uiout
->field_string ("original-location",
6459 event_location_to_string (b
->location
.get ()));
6463 /* See breakpoint.h. */
6465 bool fix_multi_location_breakpoint_output_globally
= false;
6468 print_one_breakpoint (struct breakpoint
*b
,
6469 struct bp_location
**last_loc
,
6472 struct ui_out
*uiout
= current_uiout
;
6473 bool use_fixed_output
6474 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6475 || fix_multi_location_breakpoint_output_globally
);
6477 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6478 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6480 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6482 if (!use_fixed_output
)
6483 bkpt_tuple_emitter
.reset ();
6485 /* If this breakpoint has custom print function,
6486 it's already printed. Otherwise, print individual
6487 locations, if any. */
6489 || b
->ops
->print_one
== NULL
6492 /* If breakpoint has a single location that is disabled, we
6493 print it as if it had several locations, since otherwise it's
6494 hard to represent "breakpoint enabled, location disabled"
6497 Note that while hardware watchpoints have several locations
6498 internally, that's not a property exposed to users.
6500 Likewise, while catchpoints may be implemented with
6501 breakpoints (e.g., catch throw), that's not a property
6502 exposed to users. We do however display the internal
6503 breakpoint locations with "maint info breakpoints". */
6504 if (!is_hardware_watchpoint (b
)
6505 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6506 || is_ada_exception_catchpoint (b
))
6508 || (b
->loc
&& (b
->loc
->next
6510 || b
->loc
->disabled_by_cond
))))
6512 gdb::optional
<ui_out_emit_list
> locations_list
;
6514 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6515 MI record. For later versions, place breakpoint locations in a
6517 if (uiout
->is_mi_like_p () && use_fixed_output
)
6518 locations_list
.emplace (uiout
, "locations");
6521 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
, ++n
)
6523 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6524 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6532 breakpoint_address_bits (struct breakpoint
*b
)
6534 int print_address_bits
= 0;
6535 struct bp_location
*loc
;
6537 /* Software watchpoints that aren't watching memory don't have an
6538 address to print. */
6539 if (is_no_memory_software_watchpoint (b
))
6542 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6546 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6547 if (addr_bit
> print_address_bits
)
6548 print_address_bits
= addr_bit
;
6551 return print_address_bits
;
6554 /* See breakpoint.h. */
6557 print_breakpoint (breakpoint
*b
)
6559 struct bp_location
*dummy_loc
= NULL
;
6560 print_one_breakpoint (b
, &dummy_loc
, 0);
6563 /* Return true if this breakpoint was set by the user, false if it is
6564 internal or momentary. */
6567 user_breakpoint_p (struct breakpoint
*b
)
6569 return b
->number
> 0;
6572 /* See breakpoint.h. */
6575 pending_breakpoint_p (struct breakpoint
*b
)
6577 return b
->loc
== NULL
;
6580 /* Print information on breakpoints (including watchpoints and tracepoints).
6582 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6583 understood by number_or_range_parser. Only breakpoints included in this
6584 list are then printed.
6586 If SHOW_INTERNAL is true, print internal breakpoints.
6588 If FILTER is non-NULL, call it on each breakpoint and only include the
6589 ones for which it returns true.
6591 Return the total number of breakpoints listed. */
6594 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6595 bool (*filter
) (const struct breakpoint
*))
6597 struct bp_location
*last_loc
= NULL
;
6598 int nr_printable_breakpoints
;
6599 struct value_print_options opts
;
6600 int print_address_bits
= 0;
6601 int print_type_col_width
= 14;
6602 struct ui_out
*uiout
= current_uiout
;
6603 bool has_disabled_by_cond_location
= false;
6605 get_user_print_options (&opts
);
6607 /* Compute the number of rows in the table, as well as the size
6608 required for address fields. */
6609 nr_printable_breakpoints
= 0;
6610 for (breakpoint
*b
: all_breakpoints ())
6612 /* If we have a filter, only list the breakpoints it accepts. */
6613 if (filter
&& !filter (b
))
6616 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6617 accept. Skip the others. */
6618 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6620 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6622 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6626 if (show_internal
|| user_breakpoint_p (b
))
6628 int addr_bit
, type_len
;
6630 addr_bit
= breakpoint_address_bits (b
);
6631 if (addr_bit
> print_address_bits
)
6632 print_address_bits
= addr_bit
;
6634 type_len
= strlen (bptype_string (b
->type
));
6635 if (type_len
> print_type_col_width
)
6636 print_type_col_width
= type_len
;
6638 nr_printable_breakpoints
++;
6643 ui_out_emit_table
table_emitter (uiout
,
6644 opts
.addressprint
? 6 : 5,
6645 nr_printable_breakpoints
,
6648 if (nr_printable_breakpoints
> 0)
6649 annotate_breakpoints_headers ();
6650 if (nr_printable_breakpoints
> 0)
6652 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6653 if (nr_printable_breakpoints
> 0)
6655 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6656 if (nr_printable_breakpoints
> 0)
6658 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6659 if (nr_printable_breakpoints
> 0)
6661 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6662 if (opts
.addressprint
)
6664 if (nr_printable_breakpoints
> 0)
6666 if (print_address_bits
<= 32)
6667 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6669 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6671 if (nr_printable_breakpoints
> 0)
6673 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6674 uiout
->table_body ();
6675 if (nr_printable_breakpoints
> 0)
6676 annotate_breakpoints_table ();
6678 for (breakpoint
*b
: all_breakpoints ())
6681 /* If we have a filter, only list the breakpoints it accepts. */
6682 if (filter
&& !filter (b
))
6685 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6686 accept. Skip the others. */
6688 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6690 if (show_internal
) /* maintenance info breakpoint */
6692 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6695 else /* all others */
6697 if (!number_is_in_list (bp_num_list
, b
->number
))
6701 /* We only print out user settable breakpoints unless the
6702 show_internal is set. */
6703 if (show_internal
|| user_breakpoint_p (b
))
6705 print_one_breakpoint (b
, &last_loc
, show_internal
);
6706 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
6707 if (loc
->disabled_by_cond
)
6708 has_disabled_by_cond_location
= true;
6713 if (nr_printable_breakpoints
== 0)
6715 /* If there's a filter, let the caller decide how to report
6719 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6720 uiout
->message ("No breakpoints or watchpoints.\n");
6722 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6728 if (last_loc
&& !server_command
)
6729 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6731 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6732 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6736 /* FIXME? Should this be moved up so that it is only called when
6737 there have been breakpoints? */
6738 annotate_breakpoints_table_end ();
6740 return nr_printable_breakpoints
;
6743 /* Display the value of default-collect in a way that is generally
6744 compatible with the breakpoint list. */
6747 default_collect_info (void)
6749 struct ui_out
*uiout
= current_uiout
;
6751 /* If it has no value (which is frequently the case), say nothing; a
6752 message like "No default-collect." gets in user's face when it's
6754 if (!*default_collect
)
6757 /* The following phrase lines up nicely with per-tracepoint collect
6759 uiout
->text ("default collect ");
6760 uiout
->field_string ("default-collect", default_collect
);
6761 uiout
->text (" \n");
6765 info_breakpoints_command (const char *args
, int from_tty
)
6767 breakpoint_1 (args
, false, NULL
);
6769 default_collect_info ();
6773 info_watchpoints_command (const char *args
, int from_tty
)
6775 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6776 struct ui_out
*uiout
= current_uiout
;
6778 if (num_printed
== 0)
6780 if (args
== NULL
|| *args
== '\0')
6781 uiout
->message ("No watchpoints.\n");
6783 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6788 maintenance_info_breakpoints (const char *args
, int from_tty
)
6790 breakpoint_1 (args
, true, NULL
);
6792 default_collect_info ();
6796 breakpoint_has_pc (struct breakpoint
*b
,
6797 struct program_space
*pspace
,
6798 CORE_ADDR pc
, struct obj_section
*section
)
6800 struct bp_location
*bl
= b
->loc
;
6802 for (; bl
; bl
= bl
->next
)
6804 if (bl
->pspace
== pspace
6805 && bl
->address
== pc
6806 && (!overlay_debugging
|| bl
->section
== section
))
6812 /* Print a message describing any user-breakpoints set at PC. This
6813 concerns with logical breakpoints, so we match program spaces, not
6817 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6818 struct program_space
*pspace
, CORE_ADDR pc
,
6819 struct obj_section
*section
, int thread
)
6823 for (breakpoint
*b
: all_breakpoints ())
6824 others
+= (user_breakpoint_p (b
)
6825 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6830 printf_filtered (_("Note: breakpoint "));
6831 else /* if (others == ???) */
6832 printf_filtered (_("Note: breakpoints "));
6833 for (breakpoint
*b
: all_breakpoints ())
6834 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6837 printf_filtered ("%d", b
->number
);
6838 if (b
->thread
== -1 && thread
!= -1)
6839 printf_filtered (" (all threads)");
6840 else if (b
->thread
!= -1)
6841 printf_filtered (" (thread %d)", b
->thread
);
6842 printf_filtered ("%s%s ",
6843 ((b
->enable_state
== bp_disabled
6844 || b
->enable_state
== bp_call_disabled
)
6848 : ((others
== 1) ? " and" : ""));
6850 current_uiout
->message (_("also set at pc %ps.\n"),
6851 styled_string (address_style
.style (),
6852 paddress (gdbarch
, pc
)));
6857 /* Return true iff it is meaningful to use the address member of LOC.
6858 For some breakpoint types, the locations' address members are
6859 irrelevant and it makes no sense to attempt to compare them to
6860 other addresses (or use them for any other purpose either).
6862 More specifically, software watchpoints and catchpoints that are
6863 not backed by breakpoints always have a zero valued location
6864 address and we don't want to mark breakpoints of any of these types
6865 to be a duplicate of an actual breakpoint location at address
6869 bl_address_is_meaningful (bp_location
*loc
)
6871 return loc
->loc_type
!= bp_loc_other
;
6874 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6875 true if LOC1 and LOC2 represent the same watchpoint location. */
6878 watchpoint_locations_match (struct bp_location
*loc1
,
6879 struct bp_location
*loc2
)
6881 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6882 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6884 /* Both of them must exist. */
6885 gdb_assert (w1
!= NULL
);
6886 gdb_assert (w2
!= NULL
);
6888 /* If the target can evaluate the condition expression in hardware,
6889 then we we need to insert both watchpoints even if they are at
6890 the same place. Otherwise the watchpoint will only trigger when
6891 the condition of whichever watchpoint was inserted evaluates to
6892 true, not giving a chance for GDB to check the condition of the
6893 other watchpoint. */
6895 && target_can_accel_watchpoint_condition (loc1
->address
,
6897 loc1
->watchpoint_type
,
6898 w1
->cond_exp
.get ()))
6900 && target_can_accel_watchpoint_condition (loc2
->address
,
6902 loc2
->watchpoint_type
,
6903 w2
->cond_exp
.get ())))
6906 /* Note that this checks the owner's type, not the location's. In
6907 case the target does not support read watchpoints, but does
6908 support access watchpoints, we'll have bp_read_watchpoint
6909 watchpoints with hw_access locations. Those should be considered
6910 duplicates of hw_read locations. The hw_read locations will
6911 become hw_access locations later. */
6912 return (loc1
->owner
->type
== loc2
->owner
->type
6913 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6914 && loc1
->address
== loc2
->address
6915 && loc1
->length
== loc2
->length
);
6918 /* See breakpoint.h. */
6921 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6922 const address_space
*aspace2
, CORE_ADDR addr2
)
6924 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6925 || aspace1
== aspace2
)
6929 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6930 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6931 matches ASPACE2. On targets that have global breakpoints, the address
6932 space doesn't really matter. */
6935 breakpoint_address_match_range (const address_space
*aspace1
,
6937 int len1
, const address_space
*aspace2
,
6940 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6941 || aspace1
== aspace2
)
6942 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6945 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6946 a ranged breakpoint. In most targets, a match happens only if ASPACE
6947 matches the breakpoint's address space. On targets that have global
6948 breakpoints, the address space doesn't really matter. */
6951 breakpoint_location_address_match (struct bp_location
*bl
,
6952 const address_space
*aspace
,
6955 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6958 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6959 bl
->address
, bl
->length
,
6963 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6964 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6965 match happens only if ASPACE matches the breakpoint's address
6966 space. On targets that have global breakpoints, the address space
6967 doesn't really matter. */
6970 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6971 const address_space
*aspace
,
6972 CORE_ADDR addr
, int len
)
6974 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6975 || bl
->pspace
->aspace
== aspace
)
6977 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6979 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6985 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6986 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6987 true, otherwise returns false. */
6990 tracepoint_locations_match (struct bp_location
*loc1
,
6991 struct bp_location
*loc2
)
6993 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6994 /* Since tracepoint locations are never duplicated with others', tracepoint
6995 locations at the same address of different tracepoints are regarded as
6996 different locations. */
6997 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7002 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7003 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
7004 the same location. If SW_HW_BPS_MATCH is true, then software
7005 breakpoint locations and hardware breakpoint locations match,
7006 otherwise they don't. */
7009 breakpoint_locations_match (struct bp_location
*loc1
,
7010 struct bp_location
*loc2
,
7011 bool sw_hw_bps_match
)
7013 int hw_point1
, hw_point2
;
7015 /* Both of them must not be in moribund_locations. */
7016 gdb_assert (loc1
->owner
!= NULL
);
7017 gdb_assert (loc2
->owner
!= NULL
);
7019 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7020 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7022 if (hw_point1
!= hw_point2
)
7025 return watchpoint_locations_match (loc1
, loc2
);
7026 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7027 return tracepoint_locations_match (loc1
, loc2
);
7029 /* We compare bp_location.length in order to cover ranged
7030 breakpoints. Keep this in sync with
7031 bp_location_is_less_than. */
7032 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7033 loc2
->pspace
->aspace
, loc2
->address
)
7034 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7035 && loc1
->length
== loc2
->length
);
7039 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7040 int bnum
, int have_bnum
)
7042 /* The longest string possibly returned by hex_string_custom
7043 is 50 chars. These must be at least that big for safety. */
7047 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7048 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7050 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7051 bnum
, astr1
, astr2
);
7053 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7056 /* Adjust a breakpoint's address to account for architectural
7057 constraints on breakpoint placement. Return the adjusted address.
7058 Note: Very few targets require this kind of adjustment. For most
7059 targets, this function is simply the identity function. */
7062 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7063 CORE_ADDR bpaddr
, enum bptype bptype
)
7065 if (bptype
== bp_watchpoint
7066 || bptype
== bp_hardware_watchpoint
7067 || bptype
== bp_read_watchpoint
7068 || bptype
== bp_access_watchpoint
7069 || bptype
== bp_catchpoint
)
7071 /* Watchpoints and the various bp_catch_* eventpoints should not
7072 have their addresses modified. */
7075 else if (bptype
== bp_single_step
)
7077 /* Single-step breakpoints should not have their addresses
7078 modified. If there's any architectural constrain that
7079 applies to this address, then it should have already been
7080 taken into account when the breakpoint was created in the
7081 first place. If we didn't do this, stepping through e.g.,
7082 Thumb-2 IT blocks would break. */
7087 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7089 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7091 /* Some targets have architectural constraints on the placement
7092 of breakpoint instructions. Obtain the adjusted address. */
7093 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7096 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7098 /* An adjusted breakpoint address can significantly alter
7099 a user's expectations. Print a warning if an adjustment
7101 if (adjusted_bpaddr
!= bpaddr
)
7102 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7104 return adjusted_bpaddr
;
7109 bp_location_from_bp_type (bptype type
)
7114 case bp_single_step
:
7118 case bp_longjmp_resume
:
7119 case bp_longjmp_call_dummy
:
7121 case bp_exception_resume
:
7122 case bp_step_resume
:
7123 case bp_hp_step_resume
:
7124 case bp_watchpoint_scope
:
7126 case bp_std_terminate
:
7127 case bp_shlib_event
:
7128 case bp_thread_event
:
7129 case bp_overlay_event
:
7131 case bp_longjmp_master
:
7132 case bp_std_terminate_master
:
7133 case bp_exception_master
:
7134 case bp_gnu_ifunc_resolver
:
7135 case bp_gnu_ifunc_resolver_return
:
7137 return bp_loc_software_breakpoint
;
7138 case bp_hardware_breakpoint
:
7139 return bp_loc_hardware_breakpoint
;
7140 case bp_hardware_watchpoint
:
7141 case bp_read_watchpoint
:
7142 case bp_access_watchpoint
:
7143 return bp_loc_hardware_watchpoint
;
7147 case bp_fast_tracepoint
:
7148 case bp_static_tracepoint
:
7149 return bp_loc_other
;
7151 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7155 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7157 this->owner
= owner
;
7158 this->cond_bytecode
= NULL
;
7159 this->shlib_disabled
= 0;
7161 this->disabled_by_cond
= false;
7163 this->loc_type
= type
;
7165 if (this->loc_type
== bp_loc_software_breakpoint
7166 || this->loc_type
== bp_loc_hardware_breakpoint
)
7167 mark_breakpoint_location_modified (this);
7172 bp_location::bp_location (breakpoint
*owner
)
7173 : bp_location::bp_location (owner
,
7174 bp_location_from_bp_type (owner
->type
))
7178 /* Allocate a struct bp_location. */
7180 static struct bp_location
*
7181 allocate_bp_location (struct breakpoint
*bpt
)
7183 return bpt
->ops
->allocate_location (bpt
);
7186 /* Decrement reference count. If the reference count reaches 0,
7187 destroy the bp_location. Sets *BLP to NULL. */
7190 decref_bp_location (struct bp_location
**blp
)
7192 bp_location_ref_policy::decref (*blp
);
7196 /* Add breakpoint B at the end of the global breakpoint chain. */
7199 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7201 struct breakpoint
*b1
;
7202 struct breakpoint
*result
= b
.get ();
7204 /* Add this breakpoint to the end of the chain so that a list of
7205 breakpoints will come out in order of increasing numbers. */
7207 b1
= breakpoint_chain
;
7209 breakpoint_chain
= b
.release ();
7214 b1
->next
= b
.release ();
7220 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7223 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7224 struct gdbarch
*gdbarch
,
7226 const struct breakpoint_ops
*ops
)
7228 gdb_assert (ops
!= NULL
);
7232 b
->gdbarch
= gdbarch
;
7233 b
->language
= current_language
->la_language
;
7234 b
->input_radix
= input_radix
;
7235 b
->related_breakpoint
= b
;
7238 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7239 that has type BPTYPE and has no locations as yet. */
7241 static struct breakpoint
*
7242 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7244 const struct breakpoint_ops
*ops
)
7246 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7248 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7249 return add_to_breakpoint_chain (std::move (b
));
7252 /* Initialize loc->function_name. */
7255 set_breakpoint_location_function (struct bp_location
*loc
)
7257 gdb_assert (loc
->owner
!= NULL
);
7259 if (loc
->owner
->type
== bp_breakpoint
7260 || loc
->owner
->type
== bp_hardware_breakpoint
7261 || is_tracepoint (loc
->owner
))
7263 const char *function_name
;
7265 if (loc
->msymbol
!= NULL
7266 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7267 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7269 struct breakpoint
*b
= loc
->owner
;
7271 function_name
= loc
->msymbol
->linkage_name ();
7273 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7274 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7276 /* Create only the whole new breakpoint of this type but do not
7277 mess more complicated breakpoints with multiple locations. */
7278 b
->type
= bp_gnu_ifunc_resolver
;
7279 /* Remember the resolver's address for use by the return
7281 loc
->related_address
= loc
->address
;
7285 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7288 loc
->function_name
= xstrdup (function_name
);
7292 /* Attempt to determine architecture of location identified by SAL. */
7294 get_sal_arch (struct symtab_and_line sal
)
7297 return sal
.section
->objfile
->arch ();
7299 return SYMTAB_OBJFILE (sal
.symtab
)->arch ();
7304 /* Low level routine for partially initializing a breakpoint of type
7305 BPTYPE. The newly created breakpoint's address, section, source
7306 file name, and line number are provided by SAL.
7308 It is expected that the caller will complete the initialization of
7309 the newly created breakpoint struct as well as output any status
7310 information regarding the creation of a new breakpoint. */
7313 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7314 struct symtab_and_line sal
, enum bptype bptype
,
7315 const struct breakpoint_ops
*ops
)
7317 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7319 add_location_to_breakpoint (b
, &sal
);
7321 if (bptype
!= bp_catchpoint
)
7322 gdb_assert (sal
.pspace
!= NULL
);
7324 /* Store the program space that was used to set the breakpoint,
7325 except for ordinary breakpoints, which are independent of the
7327 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7328 b
->pspace
= sal
.pspace
;
7331 /* set_raw_breakpoint is a low level routine for allocating and
7332 partially initializing a breakpoint of type BPTYPE. The newly
7333 created breakpoint's address, section, source file name, and line
7334 number are provided by SAL. The newly created and partially
7335 initialized breakpoint is added to the breakpoint chain and
7336 is also returned as the value of this function.
7338 It is expected that the caller will complete the initialization of
7339 the newly created breakpoint struct as well as output any status
7340 information regarding the creation of a new breakpoint. In
7341 particular, set_raw_breakpoint does NOT set the breakpoint
7342 number! Care should be taken to not allow an error to occur
7343 prior to completing the initialization of the breakpoint. If this
7344 should happen, a bogus breakpoint will be left on the chain. */
7347 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7348 struct symtab_and_line sal
, enum bptype bptype
,
7349 const struct breakpoint_ops
*ops
)
7351 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7353 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7354 return add_to_breakpoint_chain (std::move (b
));
7357 /* Call this routine when stepping and nexting to enable a breakpoint
7358 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7359 initiated the operation. */
7362 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7364 int thread
= tp
->global_num
;
7366 /* To avoid having to rescan all objfile symbols at every step,
7367 we maintain a list of continually-inserted but always disabled
7368 longjmp "master" breakpoints. Here, we simply create momentary
7369 clones of those and enable them for the requested thread. */
7370 for (breakpoint
*b
: all_breakpoints_safe ())
7371 if (b
->pspace
== current_program_space
7372 && (b
->type
== bp_longjmp_master
7373 || b
->type
== bp_exception_master
))
7375 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7376 struct breakpoint
*clone
;
7378 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7379 after their removal. */
7380 clone
= momentary_breakpoint_from_master (b
, type
,
7381 &momentary_breakpoint_ops
, 1);
7382 clone
->thread
= thread
;
7385 tp
->initiating_frame
= frame
;
7388 /* Delete all longjmp breakpoints from THREAD. */
7390 delete_longjmp_breakpoint (int thread
)
7392 for (breakpoint
*b
: all_breakpoints_safe ())
7393 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7395 if (b
->thread
== thread
)
7396 delete_breakpoint (b
);
7401 delete_longjmp_breakpoint_at_next_stop (int thread
)
7403 for (breakpoint
*b
: all_breakpoints_safe ())
7404 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7406 if (b
->thread
== thread
)
7407 b
->disposition
= disp_del_at_next_stop
;
7411 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7412 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7413 pointer to any of them. Return NULL if this system cannot place longjmp
7417 set_longjmp_breakpoint_for_call_dummy (void)
7419 breakpoint
*retval
= nullptr;
7421 for (breakpoint
*b
: all_breakpoints ())
7422 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7424 struct breakpoint
*new_b
;
7426 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7427 &momentary_breakpoint_ops
,
7429 new_b
->thread
= inferior_thread ()->global_num
;
7431 /* Link NEW_B into the chain of RETVAL breakpoints. */
7433 gdb_assert (new_b
->related_breakpoint
== new_b
);
7436 new_b
->related_breakpoint
= retval
;
7437 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7438 retval
= retval
->related_breakpoint
;
7439 retval
->related_breakpoint
= new_b
;
7445 /* Verify all existing dummy frames and their associated breakpoints for
7446 TP. Remove those which can no longer be found in the current frame
7449 You should call this function only at places where it is safe to currently
7450 unwind the whole stack. Failed stack unwind would discard live dummy
7454 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7456 struct breakpoint
*b
, *b_tmp
;
7458 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7459 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7461 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7463 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7464 dummy_b
= dummy_b
->related_breakpoint
;
7465 if (dummy_b
->type
!= bp_call_dummy
7466 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7469 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7471 while (b
->related_breakpoint
!= b
)
7473 if (b_tmp
== b
->related_breakpoint
)
7474 b_tmp
= b
->related_breakpoint
->next
;
7475 delete_breakpoint (b
->related_breakpoint
);
7477 delete_breakpoint (b
);
7482 enable_overlay_breakpoints (void)
7484 for (breakpoint
*b
: all_breakpoints ())
7485 if (b
->type
== bp_overlay_event
)
7487 b
->enable_state
= bp_enabled
;
7488 update_global_location_list (UGLL_MAY_INSERT
);
7489 overlay_events_enabled
= 1;
7494 disable_overlay_breakpoints (void)
7496 for (breakpoint
*b
: all_breakpoints ())
7497 if (b
->type
== bp_overlay_event
)
7499 b
->enable_state
= bp_disabled
;
7500 update_global_location_list (UGLL_DONT_INSERT
);
7501 overlay_events_enabled
= 0;
7505 /* Set an active std::terminate breakpoint for each std::terminate
7506 master breakpoint. */
7508 set_std_terminate_breakpoint (void)
7510 for (breakpoint
*b
: all_breakpoints_safe ())
7511 if (b
->pspace
== current_program_space
7512 && b
->type
== bp_std_terminate_master
)
7514 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7515 &momentary_breakpoint_ops
, 1);
7519 /* Delete all the std::terminate breakpoints. */
7521 delete_std_terminate_breakpoint (void)
7523 for (breakpoint
*b
: all_breakpoints_safe ())
7524 if (b
->type
== bp_std_terminate
)
7525 delete_breakpoint (b
);
7529 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7531 struct breakpoint
*b
;
7533 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7534 &internal_breakpoint_ops
);
7536 b
->enable_state
= bp_enabled
;
7537 /* location has to be used or breakpoint_re_set will delete me. */
7538 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7540 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7545 struct lang_and_radix
7551 /* Create a breakpoint for JIT code registration and unregistration. */
7554 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7556 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7557 &internal_breakpoint_ops
);
7560 /* Remove JIT code registration and unregistration breakpoint(s). */
7563 remove_jit_event_breakpoints (void)
7565 for (breakpoint
*b
: all_breakpoints_safe ())
7566 if (b
->type
== bp_jit_event
7567 && b
->loc
->pspace
== current_program_space
)
7568 delete_breakpoint (b
);
7572 remove_solib_event_breakpoints (void)
7574 for (breakpoint
*b
: all_breakpoints_safe ())
7575 if (b
->type
== bp_shlib_event
7576 && b
->loc
->pspace
== current_program_space
)
7577 delete_breakpoint (b
);
7580 /* See breakpoint.h. */
7583 remove_solib_event_breakpoints_at_next_stop (void)
7585 for (breakpoint
*b
: all_breakpoints_safe ())
7586 if (b
->type
== bp_shlib_event
7587 && b
->loc
->pspace
== current_program_space
)
7588 b
->disposition
= disp_del_at_next_stop
;
7591 /* Helper for create_solib_event_breakpoint /
7592 create_and_insert_solib_event_breakpoint. Allows specifying which
7593 INSERT_MODE to pass through to update_global_location_list. */
7595 static struct breakpoint
*
7596 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7597 enum ugll_insert_mode insert_mode
)
7599 struct breakpoint
*b
;
7601 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7602 &internal_breakpoint_ops
);
7603 update_global_location_list_nothrow (insert_mode
);
7608 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7610 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7613 /* See breakpoint.h. */
7616 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7618 struct breakpoint
*b
;
7620 /* Explicitly tell update_global_location_list to insert
7622 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7623 if (!b
->loc
->inserted
)
7625 delete_breakpoint (b
);
7631 /* Disable any breakpoints that are on code in shared libraries. Only
7632 apply to enabled breakpoints, disabled ones can just stay disabled. */
7635 disable_breakpoints_in_shlibs (void)
7637 struct bp_location
*loc
, **locp_tmp
;
7639 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7641 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7642 struct breakpoint
*b
= loc
->owner
;
7644 /* We apply the check to all breakpoints, including disabled for
7645 those with loc->duplicate set. This is so that when breakpoint
7646 becomes enabled, or the duplicate is removed, gdb will try to
7647 insert all breakpoints. If we don't set shlib_disabled here,
7648 we'll try to insert those breakpoints and fail. */
7649 if (((b
->type
== bp_breakpoint
)
7650 || (b
->type
== bp_jit_event
)
7651 || (b
->type
== bp_hardware_breakpoint
)
7652 || (is_tracepoint (b
)))
7653 && loc
->pspace
== current_program_space
7654 && !loc
->shlib_disabled
7655 && solib_name_from_address (loc
->pspace
, loc
->address
)
7658 loc
->shlib_disabled
= 1;
7663 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7664 notification of unloaded_shlib. Only apply to enabled breakpoints,
7665 disabled ones can just stay disabled. */
7668 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7670 struct bp_location
*loc
, **locp_tmp
;
7671 int disabled_shlib_breaks
= 0;
7673 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7675 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7676 struct breakpoint
*b
= loc
->owner
;
7678 if (solib
->pspace
== loc
->pspace
7679 && !loc
->shlib_disabled
7680 && (((b
->type
== bp_breakpoint
7681 || b
->type
== bp_jit_event
7682 || b
->type
== bp_hardware_breakpoint
)
7683 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7684 || loc
->loc_type
== bp_loc_software_breakpoint
))
7685 || is_tracepoint (b
))
7686 && solib_contains_address_p (solib
, loc
->address
))
7688 loc
->shlib_disabled
= 1;
7689 /* At this point, we cannot rely on remove_breakpoint
7690 succeeding so we must mark the breakpoint as not inserted
7691 to prevent future errors occurring in remove_breakpoints. */
7694 /* This may cause duplicate notifications for the same breakpoint. */
7695 gdb::observers::breakpoint_modified
.notify (b
);
7697 if (!disabled_shlib_breaks
)
7699 target_terminal::ours_for_output ();
7700 warning (_("Temporarily disabling breakpoints "
7701 "for unloaded shared library \"%s\""),
7704 disabled_shlib_breaks
= 1;
7709 /* Disable any breakpoints and tracepoints in OBJFILE upon
7710 notification of free_objfile. Only apply to enabled breakpoints,
7711 disabled ones can just stay disabled. */
7714 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7716 if (objfile
== NULL
)
7719 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7720 managed by the user with add-symbol-file/remove-symbol-file.
7721 Similarly to how breakpoints in shared libraries are handled in
7722 response to "nosharedlibrary", mark breakpoints in such modules
7723 shlib_disabled so they end up uninserted on the next global
7724 location list update. Shared libraries not loaded by the user
7725 aren't handled here -- they're already handled in
7726 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7727 solib_unloaded observer. We skip objfiles that are not
7728 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7730 if ((objfile
->flags
& OBJF_SHARED
) == 0
7731 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7734 for (breakpoint
*b
: all_breakpoints ())
7736 struct bp_location
*loc
;
7737 int bp_modified
= 0;
7739 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7742 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7744 CORE_ADDR loc_addr
= loc
->address
;
7746 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7747 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7750 if (loc
->shlib_disabled
!= 0)
7753 if (objfile
->pspace
!= loc
->pspace
)
7756 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7757 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7760 if (is_addr_in_objfile (loc_addr
, objfile
))
7762 loc
->shlib_disabled
= 1;
7763 /* At this point, we don't know whether the object was
7764 unmapped from the inferior or not, so leave the
7765 inserted flag alone. We'll handle failure to
7766 uninsert quietly, in case the object was indeed
7769 mark_breakpoint_location_modified (loc
);
7776 gdb::observers::breakpoint_modified
.notify (b
);
7780 /* FORK & VFORK catchpoints. */
7782 /* An instance of this type is used to represent a fork or vfork
7783 catchpoint. A breakpoint is really of this type iff its ops pointer points
7784 to CATCH_FORK_BREAKPOINT_OPS. */
7786 struct fork_catchpoint
: public breakpoint
7788 /* Process id of a child process whose forking triggered this
7789 catchpoint. This field is only valid immediately after this
7790 catchpoint has triggered. */
7791 ptid_t forked_inferior_pid
;
7794 /* Implement the "insert" breakpoint_ops method for fork
7798 insert_catch_fork (struct bp_location
*bl
)
7800 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7803 /* Implement the "remove" breakpoint_ops method for fork
7807 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7809 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7812 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7816 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7817 const address_space
*aspace
, CORE_ADDR bp_addr
,
7818 const struct target_waitstatus
*ws
)
7820 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7822 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7825 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7829 /* Implement the "print_it" breakpoint_ops method for fork
7832 static enum print_stop_action
7833 print_it_catch_fork (bpstat bs
)
7835 struct ui_out
*uiout
= current_uiout
;
7836 struct breakpoint
*b
= bs
->breakpoint_at
;
7837 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7839 annotate_catchpoint (b
->number
);
7840 maybe_print_thread_hit_breakpoint (uiout
);
7841 if (b
->disposition
== disp_del
)
7842 uiout
->text ("Temporary catchpoint ");
7844 uiout
->text ("Catchpoint ");
7845 if (uiout
->is_mi_like_p ())
7847 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7848 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7850 uiout
->field_signed ("bkptno", b
->number
);
7851 uiout
->text (" (forked process ");
7852 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7853 uiout
->text ("), ");
7854 return PRINT_SRC_AND_LOC
;
7857 /* Implement the "print_one" breakpoint_ops method for fork
7861 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7863 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7864 struct value_print_options opts
;
7865 struct ui_out
*uiout
= current_uiout
;
7867 get_user_print_options (&opts
);
7869 /* Field 4, the address, is omitted (which makes the columns not
7870 line up too nicely with the headers, but the effect is relatively
7872 if (opts
.addressprint
)
7873 uiout
->field_skip ("addr");
7875 uiout
->text ("fork");
7876 if (c
->forked_inferior_pid
!= null_ptid
)
7878 uiout
->text (", process ");
7879 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7883 if (uiout
->is_mi_like_p ())
7884 uiout
->field_string ("catch-type", "fork");
7887 /* Implement the "print_mention" breakpoint_ops method for fork
7891 print_mention_catch_fork (struct breakpoint
*b
)
7893 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7896 /* Implement the "print_recreate" breakpoint_ops method for fork
7900 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7902 fprintf_unfiltered (fp
, "catch fork");
7903 print_recreate_thread (b
, fp
);
7906 /* The breakpoint_ops structure to be used in fork catchpoints. */
7908 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7910 /* Implement the "insert" breakpoint_ops method for vfork
7914 insert_catch_vfork (struct bp_location
*bl
)
7916 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7919 /* Implement the "remove" breakpoint_ops method for vfork
7923 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7925 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7928 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7932 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7933 const address_space
*aspace
, CORE_ADDR bp_addr
,
7934 const struct target_waitstatus
*ws
)
7936 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7938 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7941 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7945 /* Implement the "print_it" breakpoint_ops method for vfork
7948 static enum print_stop_action
7949 print_it_catch_vfork (bpstat bs
)
7951 struct ui_out
*uiout
= current_uiout
;
7952 struct breakpoint
*b
= bs
->breakpoint_at
;
7953 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7955 annotate_catchpoint (b
->number
);
7956 maybe_print_thread_hit_breakpoint (uiout
);
7957 if (b
->disposition
== disp_del
)
7958 uiout
->text ("Temporary catchpoint ");
7960 uiout
->text ("Catchpoint ");
7961 if (uiout
->is_mi_like_p ())
7963 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7964 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7966 uiout
->field_signed ("bkptno", b
->number
);
7967 uiout
->text (" (vforked process ");
7968 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7969 uiout
->text ("), ");
7970 return PRINT_SRC_AND_LOC
;
7973 /* Implement the "print_one" breakpoint_ops method for vfork
7977 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7979 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7980 struct value_print_options opts
;
7981 struct ui_out
*uiout
= current_uiout
;
7983 get_user_print_options (&opts
);
7984 /* Field 4, the address, is omitted (which makes the columns not
7985 line up too nicely with the headers, but the effect is relatively
7987 if (opts
.addressprint
)
7988 uiout
->field_skip ("addr");
7990 uiout
->text ("vfork");
7991 if (c
->forked_inferior_pid
!= null_ptid
)
7993 uiout
->text (", process ");
7994 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7998 if (uiout
->is_mi_like_p ())
7999 uiout
->field_string ("catch-type", "vfork");
8002 /* Implement the "print_mention" breakpoint_ops method for vfork
8006 print_mention_catch_vfork (struct breakpoint
*b
)
8008 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8011 /* Implement the "print_recreate" breakpoint_ops method for vfork
8015 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8017 fprintf_unfiltered (fp
, "catch vfork");
8018 print_recreate_thread (b
, fp
);
8021 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8023 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8025 /* An instance of this type is used to represent an solib catchpoint.
8026 A breakpoint is really of this type iff its ops pointer points to
8027 CATCH_SOLIB_BREAKPOINT_OPS. */
8029 struct solib_catchpoint
: public breakpoint
8031 ~solib_catchpoint () override
;
8033 /* True for "catch load", false for "catch unload". */
8036 /* Regular expression to match, if any. COMPILED is only valid when
8037 REGEX is non-NULL. */
8039 std::unique_ptr
<compiled_regex
> compiled
;
8042 solib_catchpoint::~solib_catchpoint ()
8044 xfree (this->regex
);
8048 insert_catch_solib (struct bp_location
*ignore
)
8054 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8060 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8061 const address_space
*aspace
,
8063 const struct target_waitstatus
*ws
)
8065 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8067 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8070 for (breakpoint
*other
: all_breakpoints ())
8072 struct bp_location
*other_bl
;
8074 if (other
== bl
->owner
)
8077 if (other
->type
!= bp_shlib_event
)
8080 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8083 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8085 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8094 check_status_catch_solib (struct bpstats
*bs
)
8096 struct solib_catchpoint
*self
8097 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8101 for (so_list
*iter
: current_program_space
->added_solibs
)
8104 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8110 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
8113 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
8119 bs
->print_it
= print_it_noop
;
8122 static enum print_stop_action
8123 print_it_catch_solib (bpstat bs
)
8125 struct breakpoint
*b
= bs
->breakpoint_at
;
8126 struct ui_out
*uiout
= current_uiout
;
8128 annotate_catchpoint (b
->number
);
8129 maybe_print_thread_hit_breakpoint (uiout
);
8130 if (b
->disposition
== disp_del
)
8131 uiout
->text ("Temporary catchpoint ");
8133 uiout
->text ("Catchpoint ");
8134 uiout
->field_signed ("bkptno", b
->number
);
8136 if (uiout
->is_mi_like_p ())
8137 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8138 print_solib_event (1);
8139 return PRINT_SRC_AND_LOC
;
8143 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8145 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8146 struct value_print_options opts
;
8147 struct ui_out
*uiout
= current_uiout
;
8149 get_user_print_options (&opts
);
8150 /* Field 4, the address, is omitted (which makes the columns not
8151 line up too nicely with the headers, but the effect is relatively
8153 if (opts
.addressprint
)
8156 uiout
->field_skip ("addr");
8164 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8166 msg
= _("load of library");
8171 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8173 msg
= _("unload of library");
8175 uiout
->field_string ("what", msg
);
8177 if (uiout
->is_mi_like_p ())
8178 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8182 print_mention_catch_solib (struct breakpoint
*b
)
8184 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8186 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8187 self
->is_load
? "load" : "unload");
8191 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8193 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8195 fprintf_unfiltered (fp
, "%s %s",
8196 b
->disposition
== disp_del
? "tcatch" : "catch",
8197 self
->is_load
? "load" : "unload");
8199 fprintf_unfiltered (fp
, " %s", self
->regex
);
8200 fprintf_unfiltered (fp
, "\n");
8203 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8205 /* See breakpoint.h. */
8208 add_solib_catchpoint (const char *arg
, bool is_load
, bool is_temp
, bool enabled
)
8210 struct gdbarch
*gdbarch
= get_current_arch ();
8214 arg
= skip_spaces (arg
);
8216 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8220 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8221 _("Invalid regexp")));
8222 c
->regex
= xstrdup (arg
);
8225 c
->is_load
= is_load
;
8226 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8227 &catch_solib_breakpoint_ops
);
8229 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8231 install_breakpoint (0, std::move (c
), 1);
8234 /* A helper function that does all the work for "catch load" and
8238 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8239 struct cmd_list_element
*command
)
8241 const int enabled
= 1;
8242 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8244 add_solib_catchpoint (arg
, is_load
, temp
, enabled
);
8248 catch_load_command_1 (const char *arg
, int from_tty
,
8249 struct cmd_list_element
*command
)
8251 catch_load_or_unload (arg
, from_tty
, 1, command
);
8255 catch_unload_command_1 (const char *arg
, int from_tty
,
8256 struct cmd_list_element
*command
)
8258 catch_load_or_unload (arg
, from_tty
, 0, command
);
8261 /* See breakpoint.h. */
8264 init_catchpoint (struct breakpoint
*b
,
8265 struct gdbarch
*gdbarch
, bool temp
,
8266 const char *cond_string
,
8267 const struct breakpoint_ops
*ops
)
8269 symtab_and_line sal
;
8270 sal
.pspace
= current_program_space
;
8272 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8274 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8275 b
->disposition
= temp
? disp_del
: disp_donttouch
;
8279 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8281 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8282 set_breakpoint_number (internal
, b
);
8283 if (is_tracepoint (b
))
8284 set_tracepoint_count (breakpoint_count
);
8287 gdb::observers::breakpoint_created
.notify (b
);
8290 update_global_location_list (UGLL_MAY_INSERT
);
8294 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8295 bool temp
, const char *cond_string
,
8296 const struct breakpoint_ops
*ops
)
8298 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8300 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
, ops
);
8302 c
->forked_inferior_pid
= null_ptid
;
8304 install_breakpoint (0, std::move (c
), 1);
8307 /* Exec catchpoints. */
8309 /* An instance of this type is used to represent an exec catchpoint.
8310 A breakpoint is really of this type iff its ops pointer points to
8311 CATCH_EXEC_BREAKPOINT_OPS. */
8313 struct exec_catchpoint
: public breakpoint
8315 ~exec_catchpoint () override
;
8317 /* Filename of a program whose exec triggered this catchpoint.
8318 This field is only valid immediately after this catchpoint has
8320 char *exec_pathname
;
8323 /* Exec catchpoint destructor. */
8325 exec_catchpoint::~exec_catchpoint ()
8327 xfree (this->exec_pathname
);
8331 insert_catch_exec (struct bp_location
*bl
)
8333 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8337 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8339 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8343 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8344 const address_space
*aspace
, CORE_ADDR bp_addr
,
8345 const struct target_waitstatus
*ws
)
8347 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8349 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8352 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8356 static enum print_stop_action
8357 print_it_catch_exec (bpstat bs
)
8359 struct ui_out
*uiout
= current_uiout
;
8360 struct breakpoint
*b
= bs
->breakpoint_at
;
8361 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8363 annotate_catchpoint (b
->number
);
8364 maybe_print_thread_hit_breakpoint (uiout
);
8365 if (b
->disposition
== disp_del
)
8366 uiout
->text ("Temporary catchpoint ");
8368 uiout
->text ("Catchpoint ");
8369 if (uiout
->is_mi_like_p ())
8371 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8372 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8374 uiout
->field_signed ("bkptno", b
->number
);
8375 uiout
->text (" (exec'd ");
8376 uiout
->field_string ("new-exec", c
->exec_pathname
);
8377 uiout
->text ("), ");
8379 return PRINT_SRC_AND_LOC
;
8383 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8385 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8386 struct value_print_options opts
;
8387 struct ui_out
*uiout
= current_uiout
;
8389 get_user_print_options (&opts
);
8391 /* Field 4, the address, is omitted (which makes the columns
8392 not line up too nicely with the headers, but the effect
8393 is relatively readable). */
8394 if (opts
.addressprint
)
8395 uiout
->field_skip ("addr");
8397 uiout
->text ("exec");
8398 if (c
->exec_pathname
!= NULL
)
8400 uiout
->text (", program \"");
8401 uiout
->field_string ("what", c
->exec_pathname
);
8402 uiout
->text ("\" ");
8405 if (uiout
->is_mi_like_p ())
8406 uiout
->field_string ("catch-type", "exec");
8410 print_mention_catch_exec (struct breakpoint
*b
)
8412 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8415 /* Implement the "print_recreate" breakpoint_ops method for exec
8419 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8421 fprintf_unfiltered (fp
, "catch exec");
8422 print_recreate_thread (b
, fp
);
8425 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8428 hw_breakpoint_used_count (void)
8431 struct bp_location
*bl
;
8433 for (breakpoint
*b
: all_breakpoints ())
8434 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8435 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8437 /* Special types of hardware breakpoints may use more than
8439 i
+= b
->ops
->resources_needed (bl
);
8445 /* Returns the resources B would use if it were a hardware
8449 hw_watchpoint_use_count (struct breakpoint
*b
)
8452 struct bp_location
*bl
;
8454 if (!breakpoint_enabled (b
))
8457 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8459 /* Special types of hardware watchpoints may use more than
8461 i
+= b
->ops
->resources_needed (bl
);
8467 /* Returns the sum the used resources of all hardware watchpoints of
8468 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8469 the sum of the used resources of all hardware watchpoints of other
8470 types _not_ TYPE. */
8473 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8474 enum bptype type
, int *other_type_used
)
8478 *other_type_used
= 0;
8479 for (breakpoint
*b
: all_breakpoints ())
8483 if (!breakpoint_enabled (b
))
8486 if (b
->type
== type
)
8487 i
+= hw_watchpoint_use_count (b
);
8488 else if (is_hardware_watchpoint (b
))
8489 *other_type_used
= 1;
8496 disable_watchpoints_before_interactive_call_start (void)
8498 for (breakpoint
*b
: all_breakpoints ())
8499 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8501 b
->enable_state
= bp_call_disabled
;
8502 update_global_location_list (UGLL_DONT_INSERT
);
8507 enable_watchpoints_after_interactive_call_stop (void)
8509 for (breakpoint
*b
: all_breakpoints ())
8510 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8512 b
->enable_state
= bp_enabled
;
8513 update_global_location_list (UGLL_MAY_INSERT
);
8518 disable_breakpoints_before_startup (void)
8520 current_program_space
->executing_startup
= 1;
8521 update_global_location_list (UGLL_DONT_INSERT
);
8525 enable_breakpoints_after_startup (void)
8527 current_program_space
->executing_startup
= 0;
8528 breakpoint_re_set ();
8531 /* Create a new single-step breakpoint for thread THREAD, with no
8534 static struct breakpoint
*
8535 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8537 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8539 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8540 &momentary_breakpoint_ops
);
8542 b
->disposition
= disp_donttouch
;
8543 b
->frame_id
= null_frame_id
;
8546 gdb_assert (b
->thread
!= 0);
8548 return add_to_breakpoint_chain (std::move (b
));
8551 /* Set a momentary breakpoint of type TYPE at address specified by
8552 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8556 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8557 struct frame_id frame_id
, enum bptype type
)
8559 struct breakpoint
*b
;
8561 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8563 gdb_assert (!frame_id_artificial_p (frame_id
));
8565 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8566 b
->enable_state
= bp_enabled
;
8567 b
->disposition
= disp_donttouch
;
8568 b
->frame_id
= frame_id
;
8570 b
->thread
= inferior_thread ()->global_num
;
8572 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8574 return breakpoint_up (b
);
8577 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8578 The new breakpoint will have type TYPE, use OPS as its
8579 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8581 static struct breakpoint
*
8582 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8584 const struct breakpoint_ops
*ops
,
8587 struct breakpoint
*copy
;
8589 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8590 copy
->loc
= allocate_bp_location (copy
);
8591 set_breakpoint_location_function (copy
->loc
);
8593 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8594 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8595 copy
->loc
->address
= orig
->loc
->address
;
8596 copy
->loc
->section
= orig
->loc
->section
;
8597 copy
->loc
->pspace
= orig
->loc
->pspace
;
8598 copy
->loc
->probe
= orig
->loc
->probe
;
8599 copy
->loc
->line_number
= orig
->loc
->line_number
;
8600 copy
->loc
->symtab
= orig
->loc
->symtab
;
8601 copy
->loc
->enabled
= loc_enabled
;
8602 copy
->frame_id
= orig
->frame_id
;
8603 copy
->thread
= orig
->thread
;
8604 copy
->pspace
= orig
->pspace
;
8606 copy
->enable_state
= bp_enabled
;
8607 copy
->disposition
= disp_donttouch
;
8608 copy
->number
= internal_breakpoint_number
--;
8610 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8614 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8618 clone_momentary_breakpoint (struct breakpoint
*orig
)
8620 /* If there's nothing to clone, then return nothing. */
8624 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8628 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8631 struct symtab_and_line sal
;
8633 sal
= find_pc_line (pc
, 0);
8635 sal
.section
= find_pc_overlay (pc
);
8636 sal
.explicit_pc
= 1;
8638 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8642 /* Tell the user we have just set a breakpoint B. */
8645 mention (struct breakpoint
*b
)
8647 b
->ops
->print_mention (b
);
8648 current_uiout
->text ("\n");
8652 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8654 /* Handle "set breakpoint auto-hw on".
8656 If the explicitly specified breakpoint type is not hardware
8657 breakpoint, check the memory map to see whether the breakpoint
8658 address is in read-only memory.
8660 - location type is not hardware breakpoint, memory is read-only.
8661 We change the type of the location to hardware breakpoint.
8663 - location type is hardware breakpoint, memory is read-write. This
8664 means we've previously made the location hardware one, but then the
8665 memory map changed, so we undo.
8669 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8671 if (automatic_hardware_breakpoints
8672 && bl
->owner
->type
!= bp_hardware_breakpoint
8673 && (bl
->loc_type
== bp_loc_software_breakpoint
8674 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8676 /* When breakpoints are removed, remove_breakpoints will use
8677 location types we've just set here, the only possible problem
8678 is that memory map has changed during running program, but
8679 it's not going to work anyway with current gdb. */
8680 mem_region
*mr
= lookup_mem_region (bl
->address
);
8684 enum bp_loc_type new_type
;
8686 if (mr
->attrib
.mode
!= MEM_RW
)
8687 new_type
= bp_loc_hardware_breakpoint
;
8689 new_type
= bp_loc_software_breakpoint
;
8691 if (new_type
!= bl
->loc_type
)
8693 static bool said
= false;
8695 bl
->loc_type
= new_type
;
8698 fprintf_filtered (gdb_stdout
,
8699 _("Note: automatically using "
8700 "hardware breakpoints for "
8701 "read-only addresses.\n"));
8709 static struct bp_location
*
8710 add_location_to_breakpoint (struct breakpoint
*b
,
8711 const struct symtab_and_line
*sal
)
8713 struct bp_location
*loc
, **tmp
;
8714 CORE_ADDR adjusted_address
;
8715 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8717 if (loc_gdbarch
== NULL
)
8718 loc_gdbarch
= b
->gdbarch
;
8720 /* Adjust the breakpoint's address prior to allocating a location.
8721 Once we call allocate_bp_location(), that mostly uninitialized
8722 location will be placed on the location chain. Adjustment of the
8723 breakpoint may cause target_read_memory() to be called and we do
8724 not want its scan of the location chain to find a breakpoint and
8725 location that's only been partially initialized. */
8726 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8729 /* Sort the locations by their ADDRESS. */
8730 loc
= allocate_bp_location (b
);
8731 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8732 tmp
= &((*tmp
)->next
))
8737 loc
->requested_address
= sal
->pc
;
8738 loc
->address
= adjusted_address
;
8739 loc
->pspace
= sal
->pspace
;
8740 loc
->probe
.prob
= sal
->prob
;
8741 loc
->probe
.objfile
= sal
->objfile
;
8742 gdb_assert (loc
->pspace
!= NULL
);
8743 loc
->section
= sal
->section
;
8744 loc
->gdbarch
= loc_gdbarch
;
8745 loc
->line_number
= sal
->line
;
8746 loc
->symtab
= sal
->symtab
;
8747 loc
->symbol
= sal
->symbol
;
8748 loc
->msymbol
= sal
->msymbol
;
8749 loc
->objfile
= sal
->objfile
;
8751 set_breakpoint_location_function (loc
);
8753 /* While by definition, permanent breakpoints are already present in the
8754 code, we don't mark the location as inserted. Normally one would expect
8755 that GDB could rely on that breakpoint instruction to stop the program,
8756 thus removing the need to insert its own breakpoint, except that executing
8757 the breakpoint instruction can kill the target instead of reporting a
8758 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8759 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8760 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8761 breakpoint be inserted normally results in QEMU knowing about the GDB
8762 breakpoint, and thus trap before the breakpoint instruction is executed.
8763 (If GDB later needs to continue execution past the permanent breakpoint,
8764 it manually increments the PC, thus avoiding executing the breakpoint
8766 if (bp_loc_is_permanent (loc
))
8773 /* Return true if LOC is pointing to a permanent breakpoint,
8774 return false otherwise. */
8777 bp_loc_is_permanent (struct bp_location
*loc
)
8779 gdb_assert (loc
!= NULL
);
8781 /* If we have a non-breakpoint-backed catchpoint or a software
8782 watchpoint, just return 0. We should not attempt to read from
8783 the addresses the locations of these breakpoint types point to.
8784 gdbarch_program_breakpoint_here_p, below, will attempt to read
8786 if (!bl_address_is_meaningful (loc
))
8789 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8790 switch_to_program_space_and_thread (loc
->pspace
);
8791 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8794 /* Build a command list for the dprintf corresponding to the current
8795 settings of the dprintf style options. */
8798 update_dprintf_command_list (struct breakpoint
*b
)
8800 char *dprintf_args
= b
->extra_string
;
8801 char *printf_line
= NULL
;
8806 dprintf_args
= skip_spaces (dprintf_args
);
8808 /* Allow a comma, as it may have terminated a location, but don't
8810 if (*dprintf_args
== ',')
8812 dprintf_args
= skip_spaces (dprintf_args
);
8814 if (*dprintf_args
!= '"')
8815 error (_("Bad format string, missing '\"'."));
8817 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8818 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8819 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8821 if (!dprintf_function
)
8822 error (_("No function supplied for dprintf call"));
8824 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8825 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8830 printf_line
= xstrprintf ("call (void) %s (%s)",
8834 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8836 if (target_can_run_breakpoint_commands ())
8837 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8840 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8841 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8845 internal_error (__FILE__
, __LINE__
,
8846 _("Invalid dprintf style."));
8848 gdb_assert (printf_line
!= NULL
);
8850 /* Manufacture a printf sequence. */
8851 struct command_line
*printf_cmd_line
8852 = new struct command_line (simple_control
, printf_line
);
8853 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8854 command_lines_deleter ()));
8857 /* Update all dprintf commands, making their command lists reflect
8858 current style settings. */
8861 update_dprintf_commands (const char *args
, int from_tty
,
8862 struct cmd_list_element
*c
)
8864 for (breakpoint
*b
: all_breakpoints ())
8865 if (b
->type
== bp_dprintf
)
8866 update_dprintf_command_list (b
);
8869 /* Create a breakpoint with SAL as location. Use LOCATION
8870 as a description of the location, and COND_STRING
8871 as condition expression. If LOCATION is NULL then create an
8872 "address location" from the address in the SAL. */
8875 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8876 gdb::array_view
<const symtab_and_line
> sals
,
8877 event_location_up
&&location
,
8878 gdb::unique_xmalloc_ptr
<char> filter
,
8879 gdb::unique_xmalloc_ptr
<char> cond_string
,
8880 gdb::unique_xmalloc_ptr
<char> extra_string
,
8881 enum bptype type
, enum bpdisp disposition
,
8882 int thread
, int task
, int ignore_count
,
8883 const struct breakpoint_ops
*ops
, int from_tty
,
8884 int enabled
, int internal
, unsigned flags
,
8885 int display_canonical
)
8889 if (type
== bp_hardware_breakpoint
)
8891 int target_resources_ok
;
8893 i
= hw_breakpoint_used_count ();
8894 target_resources_ok
=
8895 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8897 if (target_resources_ok
== 0)
8898 error (_("No hardware breakpoint support in the target."));
8899 else if (target_resources_ok
< 0)
8900 error (_("Hardware breakpoints used exceeds limit."));
8903 gdb_assert (!sals
.empty ());
8905 for (const auto &sal
: sals
)
8907 struct bp_location
*loc
;
8911 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8913 loc_gdbarch
= gdbarch
;
8915 describe_other_breakpoints (loc_gdbarch
,
8916 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8919 if (&sal
== &sals
[0])
8921 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8925 b
->cond_string
= cond_string
.release ();
8926 b
->extra_string
= extra_string
.release ();
8927 b
->ignore_count
= ignore_count
;
8928 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8929 b
->disposition
= disposition
;
8931 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8932 b
->loc
->inserted
= 1;
8934 if (type
== bp_static_tracepoint
)
8936 struct tracepoint
*t
= (struct tracepoint
*) b
;
8937 struct static_tracepoint_marker marker
;
8939 if (strace_marker_p (b
))
8941 /* We already know the marker exists, otherwise, we
8942 wouldn't see a sal for it. */
8944 = &event_location_to_string (b
->location
.get ())[3];
8947 p
= skip_spaces (p
);
8949 endp
= skip_to_space (p
);
8951 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8953 printf_filtered (_("Probed static tracepoint "
8955 t
->static_trace_marker_id
.c_str ());
8957 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8959 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8961 printf_filtered (_("Probed static tracepoint "
8963 t
->static_trace_marker_id
.c_str ());
8966 warning (_("Couldn't determine the static "
8967 "tracepoint marker to probe"));
8974 loc
= add_location_to_breakpoint (b
, &sal
);
8975 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8979 /* Do not set breakpoint locations conditions yet. As locations
8980 are inserted, they get sorted based on their addresses. Let
8981 the list stabilize to have reliable location numbers. */
8983 /* Dynamic printf requires and uses additional arguments on the
8984 command line, otherwise it's an error. */
8985 if (type
== bp_dprintf
)
8987 if (b
->extra_string
)
8988 update_dprintf_command_list (b
);
8990 error (_("Format string required"));
8992 else if (b
->extra_string
)
8993 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8997 /* The order of the locations is now stable. Set the location
8998 condition using the location's number. */
9000 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
9002 if (b
->cond_string
!= nullptr)
9003 set_breakpoint_location_condition (b
->cond_string
, loc
, b
->number
,
9009 b
->display_canonical
= display_canonical
;
9010 if (location
!= NULL
)
9011 b
->location
= std::move (location
);
9013 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9014 b
->filter
= std::move (filter
);
9018 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9019 gdb::array_view
<const symtab_and_line
> sals
,
9020 event_location_up
&&location
,
9021 gdb::unique_xmalloc_ptr
<char> filter
,
9022 gdb::unique_xmalloc_ptr
<char> cond_string
,
9023 gdb::unique_xmalloc_ptr
<char> extra_string
,
9024 enum bptype type
, enum bpdisp disposition
,
9025 int thread
, int task
, int ignore_count
,
9026 const struct breakpoint_ops
*ops
, int from_tty
,
9027 int enabled
, int internal
, unsigned flags
,
9028 int display_canonical
)
9030 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9032 init_breakpoint_sal (b
.get (), gdbarch
,
9033 sals
, std::move (location
),
9035 std::move (cond_string
),
9036 std::move (extra_string
),
9038 thread
, task
, ignore_count
,
9040 enabled
, internal
, flags
,
9043 install_breakpoint (internal
, std::move (b
), 0);
9046 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9047 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9048 value. COND_STRING, if not NULL, specified the condition to be
9049 used for all breakpoints. Essentially the only case where
9050 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9051 function. In that case, it's still not possible to specify
9052 separate conditions for different overloaded functions, so
9053 we take just a single condition string.
9055 NOTE: If the function succeeds, the caller is expected to cleanup
9056 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9057 array contents). If the function fails (error() is called), the
9058 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9059 COND and SALS arrays and each of those arrays contents. */
9062 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9063 struct linespec_result
*canonical
,
9064 gdb::unique_xmalloc_ptr
<char> cond_string
,
9065 gdb::unique_xmalloc_ptr
<char> extra_string
,
9066 enum bptype type
, enum bpdisp disposition
,
9067 int thread
, int task
, int ignore_count
,
9068 const struct breakpoint_ops
*ops
, int from_tty
,
9069 int enabled
, int internal
, unsigned flags
)
9071 if (canonical
->pre_expanded
)
9072 gdb_assert (canonical
->lsals
.size () == 1);
9074 for (const auto &lsal
: canonical
->lsals
)
9076 /* Note that 'location' can be NULL in the case of a plain
9077 'break', without arguments. */
9078 event_location_up location
9079 = (canonical
->location
!= NULL
9080 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9081 gdb::unique_xmalloc_ptr
<char> filter_string
9082 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9084 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9085 std::move (location
),
9086 std::move (filter_string
),
9087 std::move (cond_string
),
9088 std::move (extra_string
),
9090 thread
, task
, ignore_count
, ops
,
9091 from_tty
, enabled
, internal
, flags
,
9092 canonical
->special_display
);
9096 /* Parse LOCATION which is assumed to be a SAL specification possibly
9097 followed by conditionals. On return, SALS contains an array of SAL
9098 addresses found. LOCATION points to the end of the SAL (for
9099 linespec locations).
9101 The array and the line spec strings are allocated on the heap, it is
9102 the caller's responsibility to free them. */
9105 parse_breakpoint_sals (struct event_location
*location
,
9106 struct linespec_result
*canonical
)
9108 struct symtab_and_line cursal
;
9110 if (event_location_type (location
) == LINESPEC_LOCATION
)
9112 const char *spec
= get_linespec_location (location
)->spec_string
;
9116 /* The last displayed codepoint, if it's valid, is our default
9117 breakpoint address. */
9118 if (last_displayed_sal_is_valid ())
9120 /* Set sal's pspace, pc, symtab, and line to the values
9121 corresponding to the last call to print_frame_info.
9122 Be sure to reinitialize LINE with NOTCURRENT == 0
9123 as the breakpoint line number is inappropriate otherwise.
9124 find_pc_line would adjust PC, re-set it back. */
9125 symtab_and_line sal
= get_last_displayed_sal ();
9126 CORE_ADDR pc
= sal
.pc
;
9128 sal
= find_pc_line (pc
, 0);
9130 /* "break" without arguments is equivalent to "break *PC"
9131 where PC is the last displayed codepoint's address. So
9132 make sure to set sal.explicit_pc to prevent GDB from
9133 trying to expand the list of sals to include all other
9134 instances with the same symtab and line. */
9136 sal
.explicit_pc
= 1;
9138 struct linespec_sals lsal
;
9140 lsal
.canonical
= NULL
;
9142 canonical
->lsals
.push_back (std::move (lsal
));
9146 error (_("No default breakpoint address now."));
9150 /* Force almost all breakpoints to be in terms of the
9151 current_source_symtab (which is decode_line_1's default).
9152 This should produce the results we want almost all of the
9153 time while leaving default_breakpoint_* alone.
9155 ObjC: However, don't match an Objective-C method name which
9156 may have a '+' or '-' succeeded by a '['. */
9157 cursal
= get_current_source_symtab_and_line ();
9158 if (last_displayed_sal_is_valid ())
9160 const char *spec
= NULL
;
9162 if (event_location_type (location
) == LINESPEC_LOCATION
)
9163 spec
= get_linespec_location (location
)->spec_string
;
9167 && strchr ("+-", spec
[0]) != NULL
9170 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9171 get_last_displayed_symtab (),
9172 get_last_displayed_line (),
9173 canonical
, NULL
, NULL
);
9178 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9179 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9183 /* Convert each SAL into a real PC. Verify that the PC can be
9184 inserted as a breakpoint. If it can't throw an error. */
9187 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9189 for (auto &sal
: sals
)
9190 resolve_sal_pc (&sal
);
9193 /* Fast tracepoints may have restrictions on valid locations. For
9194 instance, a fast tracepoint using a jump instead of a trap will
9195 likely have to overwrite more bytes than a trap would, and so can
9196 only be placed where the instruction is longer than the jump, or a
9197 multi-instruction sequence does not have a jump into the middle of
9201 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9202 gdb::array_view
<const symtab_and_line
> sals
)
9204 for (const auto &sal
: sals
)
9206 struct gdbarch
*sarch
;
9208 sarch
= get_sal_arch (sal
);
9209 /* We fall back to GDBARCH if there is no architecture
9210 associated with SAL. */
9214 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9215 error (_("May not have a fast tracepoint at %s%s"),
9216 paddress (sarch
, sal
.pc
), msg
.c_str ());
9220 /* Given TOK, a string specification of condition and thread, as
9221 accepted by the 'break' command, extract the condition
9222 string and thread number and set *COND_STRING and *THREAD.
9223 PC identifies the context at which the condition should be parsed.
9224 If no condition is found, *COND_STRING is set to NULL.
9225 If no thread is found, *THREAD is set to -1. */
9228 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9229 char **cond_string
, int *thread
, int *task
,
9232 *cond_string
= NULL
;
9240 const char *end_tok
;
9242 const char *cond_start
= NULL
;
9243 const char *cond_end
= NULL
;
9245 tok
= skip_spaces (tok
);
9247 if ((*tok
== '"' || *tok
== ',') && rest
)
9249 *rest
= savestring (tok
, strlen (tok
));
9253 end_tok
= skip_to_space (tok
);
9255 toklen
= end_tok
- tok
;
9257 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9259 tok
= cond_start
= end_tok
+ 1;
9262 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9264 catch (const gdb_exception_error
&)
9269 tok
= tok
+ strlen (tok
);
9272 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9274 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
9279 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9282 struct thread_info
*thr
;
9285 thr
= parse_thread_id (tok
, &tmptok
);
9287 error (_("Junk after thread keyword."));
9288 *thread
= thr
->global_num
;
9291 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9296 *task
= strtol (tok
, &tmptok
, 0);
9298 error (_("Junk after task keyword."));
9299 if (!valid_task_id (*task
))
9300 error (_("Unknown task %d."), *task
);
9305 *rest
= savestring (tok
, strlen (tok
));
9309 error (_("Junk at end of arguments."));
9313 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
9314 succeeds. The parsed values are written to COND_STRING, THREAD,
9315 TASK, and REST. See the comment of 'find_condition_and_thread'
9316 for the description of these parameters and INPUT. */
9319 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
9320 const char *input
, char **cond_string
,
9321 int *thread
, int *task
, char **rest
)
9323 int num_failures
= 0;
9324 for (auto &sal
: sals
)
9326 char *cond
= nullptr;
9329 char *remaining
= nullptr;
9331 /* Here we want to parse 'arg' to separate condition from thread
9332 number. But because parsing happens in a context and the
9333 contexts of sals might be different, try each until there is
9334 success. Finding one successful parse is sufficient for our
9335 goal. When setting the breakpoint we'll re-parse the
9336 condition in the context of each sal. */
9339 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
9340 &task_id
, &remaining
);
9341 *cond_string
= cond
;
9342 *thread
= thread_id
;
9347 catch (const gdb_exception_error
&e
)
9350 /* If no sal remains, do not continue. */
9351 if (num_failures
== sals
.size ())
9357 /* Decode a static tracepoint marker spec. */
9359 static std::vector
<symtab_and_line
>
9360 decode_static_tracepoint_spec (const char **arg_p
)
9362 const char *p
= &(*arg_p
)[3];
9365 p
= skip_spaces (p
);
9367 endp
= skip_to_space (p
);
9369 std::string
marker_str (p
, endp
- p
);
9371 std::vector
<static_tracepoint_marker
> markers
9372 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9373 if (markers
.empty ())
9374 error (_("No known static tracepoint marker named %s"),
9375 marker_str
.c_str ());
9377 std::vector
<symtab_and_line
> sals
;
9378 sals
.reserve (markers
.size ());
9380 for (const static_tracepoint_marker
&marker
: markers
)
9382 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9383 sal
.pc
= marker
.address
;
9384 sals
.push_back (sal
);
9391 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9392 according to IS_TRACEPOINT. */
9394 static const struct breakpoint_ops
*
9395 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
9400 if (location_type
== PROBE_LOCATION
)
9401 return &tracepoint_probe_breakpoint_ops
;
9403 return &tracepoint_breakpoint_ops
;
9407 if (location_type
== PROBE_LOCATION
)
9408 return &bkpt_probe_breakpoint_ops
;
9410 return &bkpt_breakpoint_ops
;
9414 /* See breakpoint.h. */
9416 const struct breakpoint_ops
*
9417 breakpoint_ops_for_event_location (const struct event_location
*location
,
9420 if (location
!= nullptr)
9421 return breakpoint_ops_for_event_location_type
9422 (event_location_type (location
), is_tracepoint
);
9423 return is_tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
9426 /* See breakpoint.h. */
9429 create_breakpoint (struct gdbarch
*gdbarch
,
9430 struct event_location
*location
,
9431 const char *cond_string
,
9432 int thread
, const char *extra_string
,
9433 bool force_condition
, int parse_extra
,
9434 int tempflag
, enum bptype type_wanted
,
9436 enum auto_boolean pending_break_support
,
9437 const struct breakpoint_ops
*ops
,
9438 int from_tty
, int enabled
, int internal
,
9441 struct linespec_result canonical
;
9444 int prev_bkpt_count
= breakpoint_count
;
9446 gdb_assert (ops
!= NULL
);
9448 /* If extra_string isn't useful, set it to NULL. */
9449 if (extra_string
!= NULL
&& *extra_string
== '\0')
9450 extra_string
= NULL
;
9454 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9456 catch (const gdb_exception_error
&e
)
9458 /* If caller is interested in rc value from parse, set
9460 if (e
.error
== NOT_FOUND_ERROR
)
9462 /* If pending breakpoint support is turned off, throw
9465 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9468 exception_print (gdb_stderr
, e
);
9470 /* If pending breakpoint support is auto query and the user
9471 selects no, then simply return the error code. */
9472 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9473 && !nquery (_("Make %s pending on future shared library load? "),
9474 bptype_string (type_wanted
)))
9477 /* At this point, either the user was queried about setting
9478 a pending breakpoint and selected yes, or pending
9479 breakpoint behavior is on and thus a pending breakpoint
9480 is defaulted on behalf of the user. */
9487 if (!pending
&& canonical
.lsals
.empty ())
9490 /* Resolve all line numbers to PC's and verify that the addresses
9491 are ok for the target. */
9494 for (auto &lsal
: canonical
.lsals
)
9495 breakpoint_sals_to_pc (lsal
.sals
);
9498 /* Fast tracepoints may have additional restrictions on location. */
9499 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9501 for (const auto &lsal
: canonical
.lsals
)
9502 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9505 /* Verify that condition can be parsed, before setting any
9506 breakpoints. Allocate a separate condition expression for each
9510 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9511 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9518 const linespec_sals
&lsal
= canonical
.lsals
[0];
9520 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9521 &cond
, &thread
, &task
, &rest
);
9522 cond_string_copy
.reset (cond
);
9523 extra_string_copy
.reset (rest
);
9527 if (type_wanted
!= bp_dprintf
9528 && extra_string
!= NULL
&& *extra_string
!= '\0')
9529 error (_("Garbage '%s' at end of location"), extra_string
);
9531 /* Check the validity of the condition. We should error out
9532 if the condition is invalid at all of the locations and
9533 if it is not forced. In the PARSE_EXTRA case above, this
9534 check is done when parsing the EXTRA_STRING. */
9535 if (cond_string
!= nullptr && !force_condition
)
9537 int num_failures
= 0;
9538 const linespec_sals
&lsal
= canonical
.lsals
[0];
9539 for (const auto &sal
: lsal
.sals
)
9541 const char *cond
= cond_string
;
9544 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
9545 /* One success is sufficient to keep going. */
9548 catch (const gdb_exception_error
&)
9551 /* If this is the last sal, error out. */
9552 if (num_failures
== lsal
.sals
.size ())
9558 /* Create a private copy of condition string. */
9560 cond_string_copy
.reset (xstrdup (cond_string
));
9561 /* Create a private copy of any extra string. */
9563 extra_string_copy
.reset (xstrdup (extra_string
));
9566 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9567 std::move (cond_string_copy
),
9568 std::move (extra_string_copy
),
9570 tempflag
? disp_del
: disp_donttouch
,
9571 thread
, task
, ignore_count
, ops
,
9572 from_tty
, enabled
, internal
, flags
);
9576 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9578 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9579 b
->location
= copy_event_location (location
);
9582 b
->cond_string
= NULL
;
9585 /* Create a private copy of condition string. */
9586 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9590 /* Create a private copy of any extra string. */
9591 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9592 b
->ignore_count
= ignore_count
;
9593 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9594 b
->condition_not_parsed
= 1;
9595 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9596 if ((type_wanted
!= bp_breakpoint
9597 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9598 b
->pspace
= current_program_space
;
9600 install_breakpoint (internal
, std::move (b
), 0);
9603 if (canonical
.lsals
.size () > 1)
9605 warning (_("Multiple breakpoints were set.\nUse the "
9606 "\"delete\" command to delete unwanted breakpoints."));
9607 prev_breakpoint_count
= prev_bkpt_count
;
9610 update_global_location_list (UGLL_MAY_INSERT
);
9615 /* Set a breakpoint.
9616 ARG is a string describing breakpoint address,
9617 condition, and thread.
9618 FLAG specifies if a breakpoint is hardware on,
9619 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9623 break_command_1 (const char *arg
, int flag
, int from_tty
)
9625 int tempflag
= flag
& BP_TEMPFLAG
;
9626 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9627 ? bp_hardware_breakpoint
9630 event_location_up location
= string_to_event_location (&arg
, current_language
);
9631 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9632 (location
.get (), false /* is_tracepoint */);
9634 create_breakpoint (get_current_arch (),
9636 NULL
, 0, arg
, false, 1 /* parse arg */,
9637 tempflag
, type_wanted
,
9638 0 /* Ignore count */,
9639 pending_break_support
,
9647 /* Helper function for break_command_1 and disassemble_command. */
9650 resolve_sal_pc (struct symtab_and_line
*sal
)
9654 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9656 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9657 error (_("No line %d in file \"%s\"."),
9658 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9661 /* If this SAL corresponds to a breakpoint inserted using a line
9662 number, then skip the function prologue if necessary. */
9663 if (sal
->explicit_line
)
9664 skip_prologue_sal (sal
);
9667 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9669 const struct blockvector
*bv
;
9670 const struct block
*b
;
9673 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9674 SYMTAB_COMPUNIT (sal
->symtab
));
9677 sym
= block_linkage_function (b
);
9680 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9681 sal
->section
= sym
->obj_section (SYMTAB_OBJFILE (sal
->symtab
));
9685 /* It really is worthwhile to have the section, so we'll
9686 just have to look harder. This case can be executed
9687 if we have line numbers but no functions (as can
9688 happen in assembly source). */
9690 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9691 switch_to_program_space_and_thread (sal
->pspace
);
9693 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9695 sal
->section
= msym
.obj_section ();
9702 break_command (const char *arg
, int from_tty
)
9704 break_command_1 (arg
, 0, from_tty
);
9708 tbreak_command (const char *arg
, int from_tty
)
9710 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9714 hbreak_command (const char *arg
, int from_tty
)
9716 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9720 thbreak_command (const char *arg
, int from_tty
)
9722 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9726 stop_command (const char *arg
, int from_tty
)
9728 printf_filtered (_("Specify the type of breakpoint to set.\n\
9729 Usage: stop in <function | address>\n\
9730 stop at <line>\n"));
9734 stopin_command (const char *arg
, int from_tty
)
9740 else if (*arg
!= '*')
9742 const char *argptr
= arg
;
9745 /* Look for a ':'. If this is a line number specification, then
9746 say it is bad, otherwise, it should be an address or
9747 function/method name. */
9748 while (*argptr
&& !hasColon
)
9750 hasColon
= (*argptr
== ':');
9755 badInput
= (*argptr
!= ':'); /* Not a class::method */
9757 badInput
= isdigit (*arg
); /* a simple line number */
9761 printf_filtered (_("Usage: stop in <function | address>\n"));
9763 break_command_1 (arg
, 0, from_tty
);
9767 stopat_command (const char *arg
, int from_tty
)
9771 if (arg
== NULL
|| *arg
== '*') /* no line number */
9775 const char *argptr
= arg
;
9778 /* Look for a ':'. If there is a '::' then get out, otherwise
9779 it is probably a line number. */
9780 while (*argptr
&& !hasColon
)
9782 hasColon
= (*argptr
== ':');
9787 badInput
= (*argptr
== ':'); /* we have class::method */
9789 badInput
= !isdigit (*arg
); /* not a line number */
9793 printf_filtered (_("Usage: stop at LINE\n"));
9795 break_command_1 (arg
, 0, from_tty
);
9798 /* The dynamic printf command is mostly like a regular breakpoint, but
9799 with a prewired command list consisting of a single output command,
9800 built from extra arguments supplied on the dprintf command
9804 dprintf_command (const char *arg
, int from_tty
)
9806 event_location_up location
= string_to_event_location (&arg
, current_language
);
9808 /* If non-NULL, ARG should have been advanced past the location;
9809 the next character must be ','. */
9812 if (arg
[0] != ',' || arg
[1] == '\0')
9813 error (_("Format string required"));
9816 /* Skip the comma. */
9821 create_breakpoint (get_current_arch (),
9823 NULL
, 0, arg
, false, 1 /* parse arg */,
9825 0 /* Ignore count */,
9826 pending_break_support
,
9827 &dprintf_breakpoint_ops
,
9835 agent_printf_command (const char *arg
, int from_tty
)
9837 error (_("May only run agent-printf on the target"));
9840 /* Implement the "breakpoint_hit" breakpoint_ops method for
9841 ranged breakpoints. */
9844 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9845 const address_space
*aspace
,
9847 const struct target_waitstatus
*ws
)
9849 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9850 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9853 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9854 bl
->length
, aspace
, bp_addr
);
9857 /* Implement the "resources_needed" breakpoint_ops method for
9858 ranged breakpoints. */
9861 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9863 return target_ranged_break_num_registers ();
9866 /* Implement the "print_it" breakpoint_ops method for
9867 ranged breakpoints. */
9869 static enum print_stop_action
9870 print_it_ranged_breakpoint (bpstat bs
)
9872 struct breakpoint
*b
= bs
->breakpoint_at
;
9873 struct bp_location
*bl
= b
->loc
;
9874 struct ui_out
*uiout
= current_uiout
;
9876 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9878 /* Ranged breakpoints have only one location. */
9879 gdb_assert (bl
&& bl
->next
== NULL
);
9881 annotate_breakpoint (b
->number
);
9883 maybe_print_thread_hit_breakpoint (uiout
);
9885 if (b
->disposition
== disp_del
)
9886 uiout
->text ("Temporary ranged breakpoint ");
9888 uiout
->text ("Ranged breakpoint ");
9889 if (uiout
->is_mi_like_p ())
9891 uiout
->field_string ("reason",
9892 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9893 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9895 uiout
->field_signed ("bkptno", b
->number
);
9898 return PRINT_SRC_AND_LOC
;
9901 /* Implement the "print_one" breakpoint_ops method for
9902 ranged breakpoints. */
9905 print_one_ranged_breakpoint (struct breakpoint
*b
,
9906 struct bp_location
**last_loc
)
9908 struct bp_location
*bl
= b
->loc
;
9909 struct value_print_options opts
;
9910 struct ui_out
*uiout
= current_uiout
;
9912 /* Ranged breakpoints have only one location. */
9913 gdb_assert (bl
&& bl
->next
== NULL
);
9915 get_user_print_options (&opts
);
9917 if (opts
.addressprint
)
9918 /* We don't print the address range here, it will be printed later
9919 by print_one_detail_ranged_breakpoint. */
9920 uiout
->field_skip ("addr");
9922 print_breakpoint_location (b
, bl
);
9926 /* Implement the "print_one_detail" breakpoint_ops method for
9927 ranged breakpoints. */
9930 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9931 struct ui_out
*uiout
)
9933 CORE_ADDR address_start
, address_end
;
9934 struct bp_location
*bl
= b
->loc
;
9939 address_start
= bl
->address
;
9940 address_end
= address_start
+ bl
->length
- 1;
9942 uiout
->text ("\taddress range: ");
9943 stb
.printf ("[%s, %s]",
9944 print_core_address (bl
->gdbarch
, address_start
),
9945 print_core_address (bl
->gdbarch
, address_end
));
9946 uiout
->field_stream ("addr", stb
);
9950 /* Implement the "print_mention" breakpoint_ops method for
9951 ranged breakpoints. */
9954 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9956 struct bp_location
*bl
= b
->loc
;
9957 struct ui_out
*uiout
= current_uiout
;
9960 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9962 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9963 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9964 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9967 /* Implement the "print_recreate" breakpoint_ops method for
9968 ranged breakpoints. */
9971 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9973 fprintf_unfiltered (fp
, "break-range %s, %s",
9974 event_location_to_string (b
->location
.get ()),
9975 event_location_to_string (b
->location_range_end
.get ()));
9976 print_recreate_thread (b
, fp
);
9979 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9981 static struct breakpoint_ops ranged_breakpoint_ops
;
9983 /* Find the address where the end of the breakpoint range should be
9984 placed, given the SAL of the end of the range. This is so that if
9985 the user provides a line number, the end of the range is set to the
9986 last instruction of the given line. */
9989 find_breakpoint_range_end (struct symtab_and_line sal
)
9993 /* If the user provided a PC value, use it. Otherwise,
9994 find the address of the end of the given location. */
9995 if (sal
.explicit_pc
)
10002 ret
= find_line_pc_range (sal
, &start
, &end
);
10004 error (_("Could not find location of the end of the range."));
10006 /* find_line_pc_range returns the start of the next line. */
10013 /* Implement the "break-range" CLI command. */
10016 break_range_command (const char *arg
, int from_tty
)
10018 const char *arg_start
;
10019 struct linespec_result canonical_start
, canonical_end
;
10020 int bp_count
, can_use_bp
, length
;
10022 struct breakpoint
*b
;
10024 /* We don't support software ranged breakpoints. */
10025 if (target_ranged_break_num_registers () < 0)
10026 error (_("This target does not support hardware ranged breakpoints."));
10028 bp_count
= hw_breakpoint_used_count ();
10029 bp_count
+= target_ranged_break_num_registers ();
10030 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10032 if (can_use_bp
< 0)
10033 error (_("Hardware breakpoints used exceeds limit."));
10035 arg
= skip_spaces (arg
);
10036 if (arg
== NULL
|| arg
[0] == '\0')
10037 error(_("No address range specified."));
10040 event_location_up start_location
= string_to_event_location (&arg
,
10042 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10045 error (_("Too few arguments."));
10046 else if (canonical_start
.lsals
.empty ())
10047 error (_("Could not find location of the beginning of the range."));
10049 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
10051 if (canonical_start
.lsals
.size () > 1
10052 || lsal_start
.sals
.size () != 1)
10053 error (_("Cannot create a ranged breakpoint with multiple locations."));
10055 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
10056 std::string
addr_string_start (arg_start
, arg
- arg_start
);
10058 arg
++; /* Skip the comma. */
10059 arg
= skip_spaces (arg
);
10061 /* Parse the end location. */
10065 /* We call decode_line_full directly here instead of using
10066 parse_breakpoint_sals because we need to specify the start location's
10067 symtab and line as the default symtab and line for the end of the
10068 range. This makes it possible to have ranges like "foo.c:27, +14",
10069 where +14 means 14 lines from the start location. */
10070 event_location_up end_location
= string_to_event_location (&arg
,
10072 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10073 sal_start
.symtab
, sal_start
.line
,
10074 &canonical_end
, NULL
, NULL
);
10076 if (canonical_end
.lsals
.empty ())
10077 error (_("Could not find location of the end of the range."));
10079 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10080 if (canonical_end
.lsals
.size () > 1
10081 || lsal_end
.sals
.size () != 1)
10082 error (_("Cannot create a ranged breakpoint with multiple locations."));
10084 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10086 end
= find_breakpoint_range_end (sal_end
);
10087 if (sal_start
.pc
> end
)
10088 error (_("Invalid address range, end precedes start."));
10090 length
= end
- sal_start
.pc
+ 1;
10092 /* Length overflowed. */
10093 error (_("Address range too large."));
10094 else if (length
== 1)
10096 /* This range is simple enough to be handled by
10097 the `hbreak' command. */
10098 hbreak_command (&addr_string_start
[0], 1);
10103 /* Now set up the breakpoint. */
10104 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10105 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10106 set_breakpoint_count (breakpoint_count
+ 1);
10107 b
->number
= breakpoint_count
;
10108 b
->disposition
= disp_donttouch
;
10109 b
->location
= std::move (start_location
);
10110 b
->location_range_end
= std::move (end_location
);
10111 b
->loc
->length
= length
;
10114 gdb::observers::breakpoint_created
.notify (b
);
10115 update_global_location_list (UGLL_MAY_INSERT
);
10118 /* Return non-zero if EXP is verified as constant. Returned zero
10119 means EXP is variable. Also the constant detection may fail for
10120 some constant expressions and in such case still falsely return
10124 watchpoint_exp_is_const (const struct expression
*exp
)
10126 return exp
->op
->constant_p ();
10129 /* Watchpoint destructor. */
10131 watchpoint::~watchpoint ()
10133 xfree (this->exp_string
);
10134 xfree (this->exp_string_reparse
);
10137 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10140 re_set_watchpoint (struct breakpoint
*b
)
10142 struct watchpoint
*w
= (struct watchpoint
*) b
;
10144 /* Watchpoint can be either on expression using entirely global
10145 variables, or it can be on local variables.
10147 Watchpoints of the first kind are never auto-deleted, and even
10148 persist across program restarts. Since they can use variables
10149 from shared libraries, we need to reparse expression as libraries
10150 are loaded and unloaded.
10152 Watchpoints on local variables can also change meaning as result
10153 of solib event. For example, if a watchpoint uses both a local
10154 and a global variables in expression, it's a local watchpoint,
10155 but unloading of a shared library will make the expression
10156 invalid. This is not a very common use case, but we still
10157 re-evaluate expression, to avoid surprises to the user.
10159 Note that for local watchpoints, we re-evaluate it only if
10160 watchpoints frame id is still valid. If it's not, it means the
10161 watchpoint is out of scope and will be deleted soon. In fact,
10162 I'm not sure we'll ever be called in this case.
10164 If a local watchpoint's frame id is still valid, then
10165 w->exp_valid_block is likewise valid, and we can safely use it.
10167 Don't do anything about disabled watchpoints, since they will be
10168 reevaluated again when enabled. */
10169 update_watchpoint (w
, 1 /* reparse */);
10172 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10175 insert_watchpoint (struct bp_location
*bl
)
10177 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10178 int length
= w
->exact
? 1 : bl
->length
;
10180 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10181 w
->cond_exp
.get ());
10184 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10187 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10189 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10190 int length
= w
->exact
? 1 : bl
->length
;
10192 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10193 w
->cond_exp
.get ());
10197 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10198 const address_space
*aspace
, CORE_ADDR bp_addr
,
10199 const struct target_waitstatus
*ws
)
10201 struct breakpoint
*b
= bl
->owner
;
10202 struct watchpoint
*w
= (struct watchpoint
*) b
;
10204 /* Continuable hardware watchpoints are treated as non-existent if the
10205 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10206 some data address). Otherwise gdb won't stop on a break instruction
10207 in the code (not from a breakpoint) when a hardware watchpoint has
10208 been defined. Also skip watchpoints which we know did not trigger
10209 (did not match the data address). */
10210 if (is_hardware_watchpoint (b
)
10211 && w
->watchpoint_triggered
== watch_triggered_no
)
10218 check_status_watchpoint (bpstat bs
)
10220 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10222 bpstat_check_watchpoint (bs
);
10225 /* Implement the "resources_needed" breakpoint_ops method for
10226 hardware watchpoints. */
10229 resources_needed_watchpoint (const struct bp_location
*bl
)
10231 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10232 int length
= w
->exact
? 1 : bl
->length
;
10234 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10237 /* Implement the "works_in_software_mode" breakpoint_ops method for
10238 hardware watchpoints. */
10241 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10243 /* Read and access watchpoints only work with hardware support. */
10244 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10247 static enum print_stop_action
10248 print_it_watchpoint (bpstat bs
)
10250 struct breakpoint
*b
;
10251 enum print_stop_action result
;
10252 struct watchpoint
*w
;
10253 struct ui_out
*uiout
= current_uiout
;
10255 gdb_assert (bs
->bp_location_at
!= NULL
);
10257 b
= bs
->breakpoint_at
;
10258 w
= (struct watchpoint
*) b
;
10260 annotate_watchpoint (b
->number
);
10261 maybe_print_thread_hit_breakpoint (uiout
);
10265 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10268 case bp_watchpoint
:
10269 case bp_hardware_watchpoint
:
10270 if (uiout
->is_mi_like_p ())
10271 uiout
->field_string
10272 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10274 tuple_emitter
.emplace (uiout
, "value");
10275 uiout
->text ("\nOld value = ");
10276 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10277 uiout
->field_stream ("old", stb
);
10278 uiout
->text ("\nNew value = ");
10279 watchpoint_value_print (w
->val
.get (), &stb
);
10280 uiout
->field_stream ("new", stb
);
10281 uiout
->text ("\n");
10282 /* More than one watchpoint may have been triggered. */
10283 result
= PRINT_UNKNOWN
;
10286 case bp_read_watchpoint
:
10287 if (uiout
->is_mi_like_p ())
10288 uiout
->field_string
10289 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10291 tuple_emitter
.emplace (uiout
, "value");
10292 uiout
->text ("\nValue = ");
10293 watchpoint_value_print (w
->val
.get (), &stb
);
10294 uiout
->field_stream ("value", stb
);
10295 uiout
->text ("\n");
10296 result
= PRINT_UNKNOWN
;
10299 case bp_access_watchpoint
:
10300 if (bs
->old_val
!= NULL
)
10302 if (uiout
->is_mi_like_p ())
10303 uiout
->field_string
10305 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10307 tuple_emitter
.emplace (uiout
, "value");
10308 uiout
->text ("\nOld value = ");
10309 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10310 uiout
->field_stream ("old", stb
);
10311 uiout
->text ("\nNew value = ");
10316 if (uiout
->is_mi_like_p ())
10317 uiout
->field_string
10319 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10320 tuple_emitter
.emplace (uiout
, "value");
10321 uiout
->text ("\nValue = ");
10323 watchpoint_value_print (w
->val
.get (), &stb
);
10324 uiout
->field_stream ("new", stb
);
10325 uiout
->text ("\n");
10326 result
= PRINT_UNKNOWN
;
10329 result
= PRINT_UNKNOWN
;
10335 /* Implement the "print_mention" breakpoint_ops method for hardware
10339 print_mention_watchpoint (struct breakpoint
*b
)
10341 struct watchpoint
*w
= (struct watchpoint
*) b
;
10342 struct ui_out
*uiout
= current_uiout
;
10343 const char *tuple_name
;
10347 case bp_watchpoint
:
10348 uiout
->text ("Watchpoint ");
10349 tuple_name
= "wpt";
10351 case bp_hardware_watchpoint
:
10352 uiout
->text ("Hardware watchpoint ");
10353 tuple_name
= "wpt";
10355 case bp_read_watchpoint
:
10356 uiout
->text ("Hardware read watchpoint ");
10357 tuple_name
= "hw-rwpt";
10359 case bp_access_watchpoint
:
10360 uiout
->text ("Hardware access (read/write) watchpoint ");
10361 tuple_name
= "hw-awpt";
10364 internal_error (__FILE__
, __LINE__
,
10365 _("Invalid hardware watchpoint type."));
10368 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10369 uiout
->field_signed ("number", b
->number
);
10370 uiout
->text (": ");
10371 uiout
->field_string ("exp", w
->exp_string
);
10374 /* Implement the "print_recreate" breakpoint_ops method for
10378 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10380 struct watchpoint
*w
= (struct watchpoint
*) b
;
10384 case bp_watchpoint
:
10385 case bp_hardware_watchpoint
:
10386 fprintf_unfiltered (fp
, "watch");
10388 case bp_read_watchpoint
:
10389 fprintf_unfiltered (fp
, "rwatch");
10391 case bp_access_watchpoint
:
10392 fprintf_unfiltered (fp
, "awatch");
10395 internal_error (__FILE__
, __LINE__
,
10396 _("Invalid watchpoint type."));
10399 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10400 print_recreate_thread (b
, fp
);
10403 /* Implement the "explains_signal" breakpoint_ops method for
10407 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10409 /* A software watchpoint cannot cause a signal other than
10410 GDB_SIGNAL_TRAP. */
10411 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10417 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10419 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10421 /* Implement the "insert" breakpoint_ops method for
10422 masked hardware watchpoints. */
10425 insert_masked_watchpoint (struct bp_location
*bl
)
10427 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10429 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10430 bl
->watchpoint_type
);
10433 /* Implement the "remove" breakpoint_ops method for
10434 masked hardware watchpoints. */
10437 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10439 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10441 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10442 bl
->watchpoint_type
);
10445 /* Implement the "resources_needed" breakpoint_ops method for
10446 masked hardware watchpoints. */
10449 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10451 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10453 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10456 /* Implement the "works_in_software_mode" breakpoint_ops method for
10457 masked hardware watchpoints. */
10460 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10465 /* Implement the "print_it" breakpoint_ops method for
10466 masked hardware watchpoints. */
10468 static enum print_stop_action
10469 print_it_masked_watchpoint (bpstat bs
)
10471 struct breakpoint
*b
= bs
->breakpoint_at
;
10472 struct ui_out
*uiout
= current_uiout
;
10474 /* Masked watchpoints have only one location. */
10475 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10477 annotate_watchpoint (b
->number
);
10478 maybe_print_thread_hit_breakpoint (uiout
);
10482 case bp_hardware_watchpoint
:
10483 if (uiout
->is_mi_like_p ())
10484 uiout
->field_string
10485 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10488 case bp_read_watchpoint
:
10489 if (uiout
->is_mi_like_p ())
10490 uiout
->field_string
10491 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10494 case bp_access_watchpoint
:
10495 if (uiout
->is_mi_like_p ())
10496 uiout
->field_string
10498 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10501 internal_error (__FILE__
, __LINE__
,
10502 _("Invalid hardware watchpoint type."));
10506 uiout
->text (_("\n\
10507 Check the underlying instruction at PC for the memory\n\
10508 address and value which triggered this watchpoint.\n"));
10509 uiout
->text ("\n");
10511 /* More than one watchpoint may have been triggered. */
10512 return PRINT_UNKNOWN
;
10515 /* Implement the "print_one_detail" breakpoint_ops method for
10516 masked hardware watchpoints. */
10519 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10520 struct ui_out
*uiout
)
10522 struct watchpoint
*w
= (struct watchpoint
*) b
;
10524 /* Masked watchpoints have only one location. */
10525 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10527 uiout
->text ("\tmask ");
10528 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10529 uiout
->text ("\n");
10532 /* Implement the "print_mention" breakpoint_ops method for
10533 masked hardware watchpoints. */
10536 print_mention_masked_watchpoint (struct breakpoint
*b
)
10538 struct watchpoint
*w
= (struct watchpoint
*) b
;
10539 struct ui_out
*uiout
= current_uiout
;
10540 const char *tuple_name
;
10544 case bp_hardware_watchpoint
:
10545 uiout
->text ("Masked hardware watchpoint ");
10546 tuple_name
= "wpt";
10548 case bp_read_watchpoint
:
10549 uiout
->text ("Masked hardware read watchpoint ");
10550 tuple_name
= "hw-rwpt";
10552 case bp_access_watchpoint
:
10553 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10554 tuple_name
= "hw-awpt";
10557 internal_error (__FILE__
, __LINE__
,
10558 _("Invalid hardware watchpoint type."));
10561 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10562 uiout
->field_signed ("number", b
->number
);
10563 uiout
->text (": ");
10564 uiout
->field_string ("exp", w
->exp_string
);
10567 /* Implement the "print_recreate" breakpoint_ops method for
10568 masked hardware watchpoints. */
10571 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10573 struct watchpoint
*w
= (struct watchpoint
*) b
;
10577 case bp_hardware_watchpoint
:
10578 fprintf_unfiltered (fp
, "watch");
10580 case bp_read_watchpoint
:
10581 fprintf_unfiltered (fp
, "rwatch");
10583 case bp_access_watchpoint
:
10584 fprintf_unfiltered (fp
, "awatch");
10587 internal_error (__FILE__
, __LINE__
,
10588 _("Invalid hardware watchpoint type."));
10591 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
,
10592 phex (w
->hw_wp_mask
, sizeof (CORE_ADDR
)));
10593 print_recreate_thread (b
, fp
);
10596 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10598 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10600 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10603 is_masked_watchpoint (const struct breakpoint
*b
)
10605 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10608 /* accessflag: hw_write: watch write,
10609 hw_read: watch read,
10610 hw_access: watch access (read or write) */
10612 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10613 bool just_location
, bool internal
)
10615 struct breakpoint
*scope_breakpoint
= NULL
;
10616 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10617 struct value
*result
;
10618 int saved_bitpos
= 0, saved_bitsize
= 0;
10619 const char *exp_start
= NULL
;
10620 const char *exp_end
= NULL
;
10621 const char *tok
, *end_tok
;
10623 const char *cond_start
= NULL
;
10624 const char *cond_end
= NULL
;
10625 enum bptype bp_type
;
10627 /* Flag to indicate whether we are going to use masks for
10628 the hardware watchpoint. */
10629 bool use_mask
= false;
10630 CORE_ADDR mask
= 0;
10632 /* Make sure that we actually have parameters to parse. */
10633 if (arg
!= NULL
&& arg
[0] != '\0')
10635 const char *value_start
;
10637 exp_end
= arg
+ strlen (arg
);
10639 /* Look for "parameter value" pairs at the end
10640 of the arguments string. */
10641 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10643 /* Skip whitespace at the end of the argument list. */
10644 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10647 /* Find the beginning of the last token.
10648 This is the value of the parameter. */
10649 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10651 value_start
= tok
+ 1;
10653 /* Skip whitespace. */
10654 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10659 /* Find the beginning of the second to last token.
10660 This is the parameter itself. */
10661 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10664 toklen
= end_tok
- tok
+ 1;
10666 if (toklen
== 6 && startswith (tok
, "thread"))
10668 struct thread_info
*thr
;
10669 /* At this point we've found a "thread" token, which means
10670 the user is trying to set a watchpoint that triggers
10671 only in a specific thread. */
10675 error(_("You can specify only one thread."));
10677 /* Extract the thread ID from the next token. */
10678 thr
= parse_thread_id (value_start
, &endp
);
10680 /* Check if the user provided a valid thread ID. */
10681 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10682 invalid_thread_id_error (value_start
);
10684 thread
= thr
->global_num
;
10686 else if (toklen
== 4 && startswith (tok
, "mask"))
10688 /* We've found a "mask" token, which means the user wants to
10689 create a hardware watchpoint that is going to have the mask
10691 struct value
*mask_value
, *mark
;
10694 error(_("You can specify only one mask."));
10696 use_mask
= just_location
= true;
10698 mark
= value_mark ();
10699 mask_value
= parse_to_comma_and_eval (&value_start
);
10700 mask
= value_as_address (mask_value
);
10701 value_free_to_mark (mark
);
10704 /* We didn't recognize what we found. We should stop here. */
10707 /* Truncate the string and get rid of the "parameter value" pair before
10708 the arguments string is parsed by the parse_exp_1 function. */
10715 /* Parse the rest of the arguments. From here on out, everything
10716 is in terms of a newly allocated string instead of the original
10718 std::string
expression (arg
, exp_end
- arg
);
10719 exp_start
= arg
= expression
.c_str ();
10720 innermost_block_tracker tracker
;
10721 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10723 /* Remove trailing whitespace from the expression before saving it.
10724 This makes the eventual display of the expression string a bit
10726 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10729 /* Checking if the expression is not constant. */
10730 if (watchpoint_exp_is_const (exp
.get ()))
10734 len
= exp_end
- exp_start
;
10735 while (len
> 0 && isspace (exp_start
[len
- 1]))
10737 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10740 exp_valid_block
= tracker
.block ();
10741 struct value
*mark
= value_mark ();
10742 struct value
*val_as_value
= nullptr;
10743 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10746 if (val_as_value
!= NULL
&& just_location
)
10748 saved_bitpos
= value_bitpos (val_as_value
);
10749 saved_bitsize
= value_bitsize (val_as_value
);
10757 exp_valid_block
= NULL
;
10758 val
= release_value (value_addr (result
));
10759 value_free_to_mark (mark
);
10763 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10766 error (_("This target does not support masked watchpoints."));
10767 else if (ret
== -2)
10768 error (_("Invalid mask or memory region."));
10771 else if (val_as_value
!= NULL
)
10772 val
= release_value (val_as_value
);
10774 tok
= skip_spaces (arg
);
10775 end_tok
= skip_to_space (tok
);
10777 toklen
= end_tok
- tok
;
10778 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10780 tok
= cond_start
= end_tok
+ 1;
10781 innermost_block_tracker if_tracker
;
10782 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10784 /* The watchpoint expression may not be local, but the condition
10785 may still be. E.g.: `watch global if local > 0'. */
10786 cond_exp_valid_block
= if_tracker
.block ();
10791 error (_("Junk at end of command."));
10793 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10795 /* Save this because create_internal_breakpoint below invalidates
10797 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10799 /* If the expression is "local", then set up a "watchpoint scope"
10800 breakpoint at the point where we've left the scope of the watchpoint
10801 expression. Create the scope breakpoint before the watchpoint, so
10802 that we will encounter it first in bpstat_stop_status. */
10803 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10805 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10807 if (frame_id_p (caller_frame_id
))
10809 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10810 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10813 = create_internal_breakpoint (caller_arch
, caller_pc
,
10814 bp_watchpoint_scope
,
10815 &momentary_breakpoint_ops
);
10817 /* create_internal_breakpoint could invalidate WP_FRAME. */
10820 scope_breakpoint
->enable_state
= bp_enabled
;
10822 /* Automatically delete the breakpoint when it hits. */
10823 scope_breakpoint
->disposition
= disp_del
;
10825 /* Only break in the proper frame (help with recursion). */
10826 scope_breakpoint
->frame_id
= caller_frame_id
;
10828 /* Set the address at which we will stop. */
10829 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10830 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10831 scope_breakpoint
->loc
->address
10832 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10833 scope_breakpoint
->loc
->requested_address
,
10834 scope_breakpoint
->type
);
10838 /* Now set up the breakpoint. We create all watchpoints as hardware
10839 watchpoints here even if hardware watchpoints are turned off, a call
10840 to update_watchpoint later in this function will cause the type to
10841 drop back to bp_watchpoint (software watchpoint) if required. */
10843 if (accessflag
== hw_read
)
10844 bp_type
= bp_read_watchpoint
;
10845 else if (accessflag
== hw_access
)
10846 bp_type
= bp_access_watchpoint
;
10848 bp_type
= bp_hardware_watchpoint
;
10850 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10853 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10854 &masked_watchpoint_breakpoint_ops
);
10856 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10857 &watchpoint_breakpoint_ops
);
10858 w
->thread
= thread
;
10859 w
->disposition
= disp_donttouch
;
10860 w
->pspace
= current_program_space
;
10861 w
->exp
= std::move (exp
);
10862 w
->exp_valid_block
= exp_valid_block
;
10863 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10866 struct type
*t
= value_type (val
.get ());
10867 CORE_ADDR addr
= value_as_address (val
.get ());
10869 w
->exp_string_reparse
10870 = current_language
->watch_location_expression (t
, addr
).release ();
10872 w
->exp_string
= xstrprintf ("-location %.*s",
10873 (int) (exp_end
- exp_start
), exp_start
);
10876 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10880 w
->hw_wp_mask
= mask
;
10885 w
->val_bitpos
= saved_bitpos
;
10886 w
->val_bitsize
= saved_bitsize
;
10887 w
->val_valid
= true;
10891 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10893 w
->cond_string
= 0;
10895 if (frame_id_p (watchpoint_frame
))
10897 w
->watchpoint_frame
= watchpoint_frame
;
10898 w
->watchpoint_thread
= inferior_ptid
;
10902 w
->watchpoint_frame
= null_frame_id
;
10903 w
->watchpoint_thread
= null_ptid
;
10906 if (scope_breakpoint
!= NULL
)
10908 /* The scope breakpoint is related to the watchpoint. We will
10909 need to act on them together. */
10910 w
->related_breakpoint
= scope_breakpoint
;
10911 scope_breakpoint
->related_breakpoint
= w
.get ();
10914 if (!just_location
)
10915 value_free_to_mark (mark
);
10917 /* Finally update the new watchpoint. This creates the locations
10918 that should be inserted. */
10919 update_watchpoint (w
.get (), 1);
10921 install_breakpoint (internal
, std::move (w
), 1);
10924 /* Return count of debug registers needed to watch the given expression.
10925 If the watchpoint cannot be handled in hardware return zero. */
10928 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10930 int found_memory_cnt
= 0;
10932 /* Did the user specifically forbid us to use hardware watchpoints? */
10933 if (!can_use_hw_watchpoints
)
10936 gdb_assert (!vals
.empty ());
10937 struct value
*head
= vals
[0].get ();
10939 /* Make sure that the value of the expression depends only upon
10940 memory contents, and values computed from them within GDB. If we
10941 find any register references or function calls, we can't use a
10942 hardware watchpoint.
10944 The idea here is that evaluating an expression generates a series
10945 of values, one holding the value of every subexpression. (The
10946 expression a*b+c has five subexpressions: a, b, a*b, c, and
10947 a*b+c.) GDB's values hold almost enough information to establish
10948 the criteria given above --- they identify memory lvalues,
10949 register lvalues, computed values, etcetera. So we can evaluate
10950 the expression, and then scan the chain of values that leaves
10951 behind to decide whether we can detect any possible change to the
10952 expression's final value using only hardware watchpoints.
10954 However, I don't think that the values returned by inferior
10955 function calls are special in any way. So this function may not
10956 notice that an expression involving an inferior function call
10957 can't be watched with hardware watchpoints. FIXME. */
10958 for (const value_ref_ptr
&iter
: vals
)
10960 struct value
*v
= iter
.get ();
10962 if (VALUE_LVAL (v
) == lval_memory
)
10964 if (v
!= head
&& value_lazy (v
))
10965 /* A lazy memory lvalue in the chain is one that GDB never
10966 needed to fetch; we either just used its address (e.g.,
10967 `a' in `a.b') or we never needed it at all (e.g., `a'
10968 in `a,b'). This doesn't apply to HEAD; if that is
10969 lazy then it was not readable, but watch it anyway. */
10973 /* Ahh, memory we actually used! Check if we can cover
10974 it with hardware watchpoints. */
10975 struct type
*vtype
= check_typedef (value_type (v
));
10977 /* We only watch structs and arrays if user asked for it
10978 explicitly, never if they just happen to appear in a
10979 middle of some value chain. */
10981 || (vtype
->code () != TYPE_CODE_STRUCT
10982 && vtype
->code () != TYPE_CODE_ARRAY
))
10984 CORE_ADDR vaddr
= value_address (v
);
10988 len
= (target_exact_watchpoints
10989 && is_scalar_type_recursive (vtype
))?
10990 1 : TYPE_LENGTH (value_type (v
));
10992 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10996 found_memory_cnt
+= num_regs
;
11000 else if (VALUE_LVAL (v
) != not_lval
11001 && deprecated_value_modifiable (v
) == 0)
11002 return 0; /* These are values from the history (e.g., $1). */
11003 else if (VALUE_LVAL (v
) == lval_register
)
11004 return 0; /* Cannot watch a register with a HW watchpoint. */
11007 /* The expression itself looks suitable for using a hardware
11008 watchpoint, but give the target machine a chance to reject it. */
11009 return found_memory_cnt
;
11013 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11015 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11018 /* Options for the watch, awatch, and rwatch commands. */
11020 struct watch_options
11022 /* For -location. */
11023 bool location
= false;
11026 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
11028 Historically GDB always accepted both '-location' and '-l' flags for
11029 these commands (both flags being synonyms). When converting to the
11030 newer option scheme only '-location' is added here. That's fine (for
11031 backward compatibility) as any non-ambiguous prefix of a flag will be
11032 accepted, so '-l', '-loc', are now all accepted.
11034 What this means is that, if in the future, we add any new flag here
11035 that starts with '-l' then this will break backward compatibility, so
11036 please, don't do that! */
11038 static const gdb::option::option_def watch_option_defs
[] = {
11039 gdb::option::flag_option_def
<watch_options
> {
11041 [] (watch_options
*opt
) { return &opt
->location
; },
11043 This evaluates EXPRESSION and watches the memory to which is refers.\n\
11044 -l can be used as a short form of -location."),
11048 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
11051 static gdb::option::option_def_group
11052 make_watch_options_def_group (watch_options
*opts
)
11054 return {{watch_option_defs
}, opts
};
11057 /* A helper function that looks for the "-location" argument and then
11058 calls watch_command_1. */
11061 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
11063 watch_options opts
;
11064 auto grp
= make_watch_options_def_group (&opts
);
11065 gdb::option::process_options
11066 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
11067 if (arg
!= nullptr && *arg
== '\0')
11070 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
11073 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
11075 watch_command_completer (struct cmd_list_element
*ignore
,
11076 completion_tracker
&tracker
,
11077 const char *text
, const char * /*word*/)
11079 const auto group
= make_watch_options_def_group (nullptr);
11080 if (gdb::option::complete_options
11081 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
11084 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
11085 expression_completer (ignore
, tracker
, text
, word
);
11089 watch_command (const char *arg
, int from_tty
)
11091 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11095 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11097 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11101 rwatch_command (const char *arg
, int from_tty
)
11103 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11107 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11109 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11113 awatch_command (const char *arg
, int from_tty
)
11115 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11119 /* Data for the FSM that manages the until(location)/advance commands
11120 in infcmd.c. Here because it uses the mechanisms of
11123 struct until_break_fsm
: public thread_fsm
11125 /* The thread that was current when the command was executed. */
11128 /* The breakpoint set at the return address in the caller frame,
11129 plus breakpoints at all the destination locations. */
11130 std::vector
<breakpoint_up
> breakpoints
;
11132 until_break_fsm (struct interp
*cmd_interp
, int thread
,
11133 std::vector
<breakpoint_up
> &&breakpoints
)
11134 : thread_fsm (cmd_interp
),
11136 breakpoints (std::move (breakpoints
))
11140 void clean_up (struct thread_info
*thread
) override
;
11141 bool should_stop (struct thread_info
*thread
) override
;
11142 enum async_reply_reason
do_async_reply_reason () override
;
11145 /* Implementation of the 'should_stop' FSM method for the
11146 until(location)/advance commands. */
11149 until_break_fsm::should_stop (struct thread_info
*tp
)
11151 for (const breakpoint_up
&bp
: breakpoints
)
11152 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11153 bp
.get ()) != NULL
)
11162 /* Implementation of the 'clean_up' FSM method for the
11163 until(location)/advance commands. */
11166 until_break_fsm::clean_up (struct thread_info
*)
11168 /* Clean up our temporary breakpoints. */
11169 breakpoints
.clear ();
11170 delete_longjmp_breakpoint (thread
);
11173 /* Implementation of the 'async_reply_reason' FSM method for the
11174 until(location)/advance commands. */
11176 enum async_reply_reason
11177 until_break_fsm::do_async_reply_reason ()
11179 return EXEC_ASYNC_LOCATION_REACHED
;
11183 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11185 struct frame_info
*frame
;
11186 struct gdbarch
*frame_gdbarch
;
11187 struct frame_id stack_frame_id
;
11188 struct frame_id caller_frame_id
;
11190 struct thread_info
*tp
;
11192 clear_proceed_status (0);
11194 /* Set a breakpoint where the user wants it and at return from
11197 event_location_up location
= string_to_event_location (&arg
, current_language
);
11199 std::vector
<symtab_and_line
> sals
11200 = (last_displayed_sal_is_valid ()
11201 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11202 get_last_displayed_symtab (),
11203 get_last_displayed_line ())
11204 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11208 error (_("Couldn't get information on specified line."));
11211 error (_("Junk at end of arguments."));
11213 tp
= inferior_thread ();
11214 thread
= tp
->global_num
;
11216 /* Note linespec handling above invalidates the frame chain.
11217 Installing a breakpoint also invalidates the frame chain (as it
11218 may need to switch threads), so do any frame handling before
11221 frame
= get_selected_frame (NULL
);
11222 frame_gdbarch
= get_frame_arch (frame
);
11223 stack_frame_id
= get_stack_frame_id (frame
);
11224 caller_frame_id
= frame_unwind_caller_id (frame
);
11226 /* Keep within the current frame, or in frames called by the current
11229 std::vector
<breakpoint_up
> breakpoints
;
11231 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11233 if (frame_id_p (caller_frame_id
))
11235 struct symtab_and_line sal2
;
11236 struct gdbarch
*caller_gdbarch
;
11238 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11239 sal2
.pc
= frame_unwind_caller_pc (frame
);
11240 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11242 breakpoint_up caller_breakpoint
11243 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
11244 caller_frame_id
, bp_until
);
11245 breakpoints
.emplace_back (std::move (caller_breakpoint
));
11247 set_longjmp_breakpoint (tp
, caller_frame_id
);
11248 lj_deleter
.emplace (thread
);
11251 /* set_momentary_breakpoint could invalidate FRAME. */
11254 /* If the user told us to continue until a specified location, we
11255 don't specify a frame at which we need to stop. Otherwise,
11256 specify the selected frame, because we want to stop only at the
11257 very same frame. */
11258 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
11260 for (symtab_and_line
&sal
: sals
)
11262 resolve_sal_pc (&sal
);
11264 breakpoint_up location_breakpoint
11265 = set_momentary_breakpoint (frame_gdbarch
, sal
,
11266 stop_frame_id
, bp_until
);
11267 breakpoints
.emplace_back (std::move (location_breakpoint
));
11270 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11271 std::move (breakpoints
));
11274 lj_deleter
->release ();
11276 proceed (-1, GDB_SIGNAL_DEFAULT
);
11279 /* This function attempts to parse an optional "if <cond>" clause
11280 from the arg string. If one is not found, it returns NULL.
11282 Else, it returns a pointer to the condition string. (It does not
11283 attempt to evaluate the string against a particular block.) And,
11284 it updates arg to point to the first character following the parsed
11285 if clause in the arg string. */
11288 ep_parse_optional_if_clause (const char **arg
)
11290 const char *cond_string
;
11292 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11295 /* Skip the "if" keyword. */
11298 /* Skip any extra leading whitespace, and record the start of the
11299 condition string. */
11300 *arg
= skip_spaces (*arg
);
11301 cond_string
= *arg
;
11303 /* Assume that the condition occupies the remainder of the arg
11305 (*arg
) += strlen (cond_string
);
11307 return cond_string
;
11310 /* Commands to deal with catching events, such as signals, exceptions,
11311 process start/exit, etc. */
11315 catch_fork_temporary
, catch_vfork_temporary
,
11316 catch_fork_permanent
, catch_vfork_permanent
11321 catch_fork_command_1 (const char *arg
, int from_tty
,
11322 struct cmd_list_element
*command
)
11324 struct gdbarch
*gdbarch
= get_current_arch ();
11325 const char *cond_string
= NULL
;
11326 catch_fork_kind fork_kind
;
11328 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11329 bool temp
= (fork_kind
== catch_fork_temporary
11330 || fork_kind
== catch_vfork_temporary
);
11334 arg
= skip_spaces (arg
);
11336 /* The allowed syntax is:
11338 catch [v]fork if <cond>
11340 First, check if there's an if clause. */
11341 cond_string
= ep_parse_optional_if_clause (&arg
);
11343 if ((*arg
!= '\0') && !isspace (*arg
))
11344 error (_("Junk at end of arguments."));
11346 /* If this target supports it, create a fork or vfork catchpoint
11347 and enable reporting of such events. */
11350 case catch_fork_temporary
:
11351 case catch_fork_permanent
:
11352 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11353 &catch_fork_breakpoint_ops
);
11355 case catch_vfork_temporary
:
11356 case catch_vfork_permanent
:
11357 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11358 &catch_vfork_breakpoint_ops
);
11361 error (_("unsupported or unknown fork kind; cannot catch it"));
11367 catch_exec_command_1 (const char *arg
, int from_tty
,
11368 struct cmd_list_element
*command
)
11370 struct gdbarch
*gdbarch
= get_current_arch ();
11371 const char *cond_string
= NULL
;
11372 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11376 arg
= skip_spaces (arg
);
11378 /* The allowed syntax is:
11380 catch exec if <cond>
11382 First, check if there's an if clause. */
11383 cond_string
= ep_parse_optional_if_clause (&arg
);
11385 if ((*arg
!= '\0') && !isspace (*arg
))
11386 error (_("Junk at end of arguments."));
11388 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11389 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
,
11390 &catch_exec_breakpoint_ops
);
11391 c
->exec_pathname
= NULL
;
11393 install_breakpoint (0, std::move (c
), 1);
11397 init_ada_exception_breakpoint (struct breakpoint
*b
,
11398 struct gdbarch
*gdbarch
,
11399 struct symtab_and_line sal
,
11400 const char *addr_string
,
11401 const struct breakpoint_ops
*ops
,
11408 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11410 loc_gdbarch
= gdbarch
;
11412 describe_other_breakpoints (loc_gdbarch
,
11413 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11414 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11415 version for exception catchpoints, because two catchpoints
11416 used for different exception names will use the same address.
11417 In this case, a "breakpoint ... also set at..." warning is
11418 unproductive. Besides, the warning phrasing is also a bit
11419 inappropriate, we should use the word catchpoint, and tell
11420 the user what type of catchpoint it is. The above is good
11421 enough for now, though. */
11424 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11426 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11427 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11428 b
->location
= string_to_event_location (&addr_string
,
11429 language_def (language_ada
));
11430 b
->language
= language_ada
;
11435 /* Compare two breakpoints and return a strcmp-like result. */
11438 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11440 uintptr_t ua
= (uintptr_t) a
;
11441 uintptr_t ub
= (uintptr_t) b
;
11443 if (a
->number
< b
->number
)
11445 else if (a
->number
> b
->number
)
11448 /* Now sort by address, in case we see, e..g, two breakpoints with
11452 return ua
> ub
? 1 : 0;
11455 /* Delete breakpoints by address or line. */
11458 clear_command (const char *arg
, int from_tty
)
11462 std::vector
<symtab_and_line
> decoded_sals
;
11463 symtab_and_line last_sal
;
11464 gdb::array_view
<symtab_and_line
> sals
;
11468 = decode_line_with_current_source (arg
,
11469 (DECODE_LINE_FUNFIRSTLINE
11470 | DECODE_LINE_LIST_MODE
));
11472 sals
= decoded_sals
;
11476 /* Set sal's line, symtab, pc, and pspace to the values
11477 corresponding to the last call to print_frame_info. If the
11478 codepoint is not valid, this will set all the fields to 0. */
11479 last_sal
= get_last_displayed_sal ();
11480 if (last_sal
.symtab
== 0)
11481 error (_("No source file specified."));
11487 /* We don't call resolve_sal_pc here. That's not as bad as it
11488 seems, because all existing breakpoints typically have both
11489 file/line and pc set. So, if clear is given file/line, we can
11490 match this to existing breakpoint without obtaining pc at all.
11492 We only support clearing given the address explicitly
11493 present in breakpoint table. Say, we've set breakpoint
11494 at file:line. There were several PC values for that file:line,
11495 due to optimization, all in one block.
11497 We've picked one PC value. If "clear" is issued with another
11498 PC corresponding to the same file:line, the breakpoint won't
11499 be cleared. We probably can still clear the breakpoint, but
11500 since the other PC value is never presented to user, user
11501 can only find it by guessing, and it does not seem important
11502 to support that. */
11504 /* For each line spec given, delete bps which correspond to it. Do
11505 it in two passes, solely to preserve the current behavior that
11506 from_tty is forced true if we delete more than one
11509 std::vector
<struct breakpoint
*> found
;
11510 for (const auto &sal
: sals
)
11512 const char *sal_fullname
;
11514 /* If exact pc given, clear bpts at that pc.
11515 If line given (pc == 0), clear all bpts on specified line.
11516 If defaulting, clear all bpts on default line
11519 defaulting sal.pc != 0 tests to do
11524 1 0 <can't happen> */
11526 sal_fullname
= (sal
.symtab
== NULL
11527 ? NULL
: symtab_to_fullname (sal
.symtab
));
11529 /* Find all matching breakpoints and add them to 'found'. */
11530 for (breakpoint
*b
: all_breakpoints ())
11533 /* Are we going to delete b? */
11534 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11536 struct bp_location
*loc
= b
->loc
;
11537 for (; loc
; loc
= loc
->next
)
11539 /* If the user specified file:line, don't allow a PC
11540 match. This matches historical gdb behavior. */
11541 int pc_match
= (!sal
.explicit_line
11543 && (loc
->pspace
== sal
.pspace
)
11544 && (loc
->address
== sal
.pc
)
11545 && (!section_is_overlay (loc
->section
)
11546 || loc
->section
== sal
.section
));
11547 int line_match
= 0;
11549 if ((default_match
|| sal
.explicit_line
)
11550 && loc
->symtab
!= NULL
11551 && sal_fullname
!= NULL
11552 && sal
.pspace
== loc
->pspace
11553 && loc
->line_number
== sal
.line
11554 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11555 sal_fullname
) == 0)
11558 if (pc_match
|| line_match
)
11567 found
.push_back (b
);
11571 /* Now go thru the 'found' chain and delete them. */
11572 if (found
.empty ())
11575 error (_("No breakpoint at %s."), arg
);
11577 error (_("No breakpoint at this line."));
11580 /* Remove duplicates from the vec. */
11581 std::sort (found
.begin (), found
.end (),
11582 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11584 return compare_breakpoints (bp_a
, bp_b
) < 0;
11586 found
.erase (std::unique (found
.begin (), found
.end (),
11587 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11589 return compare_breakpoints (bp_a
, bp_b
) == 0;
11593 if (found
.size () > 1)
11594 from_tty
= 1; /* Always report if deleted more than one. */
11597 if (found
.size () == 1)
11598 printf_unfiltered (_("Deleted breakpoint "));
11600 printf_unfiltered (_("Deleted breakpoints "));
11603 for (breakpoint
*iter
: found
)
11606 printf_unfiltered ("%d ", iter
->number
);
11607 delete_breakpoint (iter
);
11610 putchar_unfiltered ('\n');
11613 /* Delete breakpoint in BS if they are `delete' breakpoints and
11614 all breakpoints that are marked for deletion, whether hit or not.
11615 This is called after any breakpoint is hit, or after errors. */
11618 breakpoint_auto_delete (bpstat bs
)
11620 for (; bs
; bs
= bs
->next
)
11621 if (bs
->breakpoint_at
11622 && bs
->breakpoint_at
->disposition
== disp_del
11624 delete_breakpoint (bs
->breakpoint_at
);
11626 for (breakpoint
*b
: all_breakpoints_safe ())
11627 if (b
->disposition
== disp_del_at_next_stop
)
11628 delete_breakpoint (b
);
11631 /* A comparison function for bp_location AP and BP being interfaced to
11632 std::sort. Sort elements primarily by their ADDRESS (no matter what
11633 bl_address_is_meaningful says), secondarily by ordering first
11634 permanent elements and terciarily just ensuring the array is sorted
11635 stable way despite std::sort being an unstable algorithm. */
11638 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11640 if (a
->address
!= b
->address
)
11641 return a
->address
< b
->address
;
11643 /* Sort locations at the same address by their pspace number, keeping
11644 locations of the same inferior (in a multi-inferior environment)
11647 if (a
->pspace
->num
!= b
->pspace
->num
)
11648 return a
->pspace
->num
< b
->pspace
->num
;
11650 /* Sort permanent breakpoints first. */
11651 if (a
->permanent
!= b
->permanent
)
11652 return a
->permanent
> b
->permanent
;
11654 /* Sort by type in order to make duplicate determination easier.
11655 See update_global_location_list. This is kept in sync with
11656 breakpoint_locations_match. */
11657 if (a
->loc_type
< b
->loc_type
)
11660 /* Likewise, for range-breakpoints, sort by length. */
11661 if (a
->loc_type
== bp_loc_hardware_breakpoint
11662 && b
->loc_type
== bp_loc_hardware_breakpoint
11663 && a
->length
< b
->length
)
11666 /* Make the internal GDB representation stable across GDB runs
11667 where A and B memory inside GDB can differ. Breakpoint locations of
11668 the same type at the same address can be sorted in arbitrary order. */
11670 if (a
->owner
->number
!= b
->owner
->number
)
11671 return a
->owner
->number
< b
->owner
->number
;
11676 /* Set bp_locations_placed_address_before_address_max and
11677 bp_locations_shadow_len_after_address_max according to the current
11678 content of the bp_locations array. */
11681 bp_locations_target_extensions_update (void)
11683 struct bp_location
*bl
, **blp_tmp
;
11685 bp_locations_placed_address_before_address_max
= 0;
11686 bp_locations_shadow_len_after_address_max
= 0;
11688 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11690 CORE_ADDR start
, end
, addr
;
11692 if (!bp_location_has_shadow (bl
))
11695 start
= bl
->target_info
.placed_address
;
11696 end
= start
+ bl
->target_info
.shadow_len
;
11698 gdb_assert (bl
->address
>= start
);
11699 addr
= bl
->address
- start
;
11700 if (addr
> bp_locations_placed_address_before_address_max
)
11701 bp_locations_placed_address_before_address_max
= addr
;
11703 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11705 gdb_assert (bl
->address
< end
);
11706 addr
= end
- bl
->address
;
11707 if (addr
> bp_locations_shadow_len_after_address_max
)
11708 bp_locations_shadow_len_after_address_max
= addr
;
11712 /* Download tracepoint locations if they haven't been. */
11715 download_tracepoint_locations (void)
11717 struct breakpoint
*b
;
11718 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11720 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11722 ALL_TRACEPOINTS (b
)
11724 struct bp_location
*bl
;
11725 struct tracepoint
*t
;
11726 int bp_location_downloaded
= 0;
11728 if ((b
->type
== bp_fast_tracepoint
11729 ? !may_insert_fast_tracepoints
11730 : !may_insert_tracepoints
))
11733 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11735 if (target_can_download_tracepoint ())
11736 can_download_tracepoint
= TRIBOOL_TRUE
;
11738 can_download_tracepoint
= TRIBOOL_FALSE
;
11741 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11744 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11746 /* In tracepoint, locations are _never_ duplicated, so
11747 should_be_inserted is equivalent to
11748 unduplicated_should_be_inserted. */
11749 if (!should_be_inserted (bl
) || bl
->inserted
)
11752 switch_to_program_space_and_thread (bl
->pspace
);
11754 target_download_tracepoint (bl
);
11757 bp_location_downloaded
= 1;
11759 t
= (struct tracepoint
*) b
;
11760 t
->number_on_target
= b
->number
;
11761 if (bp_location_downloaded
)
11762 gdb::observers::breakpoint_modified
.notify (b
);
11766 /* Swap the insertion/duplication state between two locations. */
11769 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11771 const int left_inserted
= left
->inserted
;
11772 const int left_duplicate
= left
->duplicate
;
11773 const int left_needs_update
= left
->needs_update
;
11774 const struct bp_target_info left_target_info
= left
->target_info
;
11776 /* Locations of tracepoints can never be duplicated. */
11777 if (is_tracepoint (left
->owner
))
11778 gdb_assert (!left
->duplicate
);
11779 if (is_tracepoint (right
->owner
))
11780 gdb_assert (!right
->duplicate
);
11782 left
->inserted
= right
->inserted
;
11783 left
->duplicate
= right
->duplicate
;
11784 left
->needs_update
= right
->needs_update
;
11785 left
->target_info
= right
->target_info
;
11786 right
->inserted
= left_inserted
;
11787 right
->duplicate
= left_duplicate
;
11788 right
->needs_update
= left_needs_update
;
11789 right
->target_info
= left_target_info
;
11792 /* Force the re-insertion of the locations at ADDRESS. This is called
11793 once a new/deleted/modified duplicate location is found and we are evaluating
11794 conditions on the target's side. Such conditions need to be updated on
11798 force_breakpoint_reinsertion (struct bp_location
*bl
)
11800 struct bp_location
**locp
= NULL
, **loc2p
;
11801 struct bp_location
*loc
;
11802 CORE_ADDR address
= 0;
11805 address
= bl
->address
;
11806 pspace_num
= bl
->pspace
->num
;
11808 /* This is only meaningful if the target is
11809 evaluating conditions and if the user has
11810 opted for condition evaluation on the target's
11812 if (gdb_evaluates_breakpoint_condition_p ()
11813 || !target_supports_evaluation_of_breakpoint_conditions ())
11816 /* Flag all breakpoint locations with this address and
11817 the same program space as the location
11818 as "its condition has changed". We need to
11819 update the conditions on the target's side. */
11820 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11824 if (!is_breakpoint (loc
->owner
)
11825 || pspace_num
!= loc
->pspace
->num
)
11828 /* Flag the location appropriately. We use a different state to
11829 let everyone know that we already updated the set of locations
11830 with addr bl->address and program space bl->pspace. This is so
11831 we don't have to keep calling these functions just to mark locations
11832 that have already been marked. */
11833 loc
->condition_changed
= condition_updated
;
11835 /* Free the agent expression bytecode as well. We will compute
11837 loc
->cond_bytecode
.reset ();
11841 /* Called whether new breakpoints are created, or existing breakpoints
11842 deleted, to update the global location list and recompute which
11843 locations are duplicate of which.
11845 The INSERT_MODE flag determines whether locations may not, may, or
11846 shall be inserted now. See 'enum ugll_insert_mode' for more
11850 update_global_location_list (enum ugll_insert_mode insert_mode
)
11852 struct bp_location
**locp
, *loc
;
11853 /* Last breakpoint location address that was marked for update. */
11854 CORE_ADDR last_addr
= 0;
11855 /* Last breakpoint location program space that was marked for update. */
11856 int last_pspace_num
= -1;
11858 /* Used in the duplicates detection below. When iterating over all
11859 bp_locations, points to the first bp_location of a given address.
11860 Breakpoints and watchpoints of different types are never
11861 duplicates of each other. Keep one pointer for each type of
11862 breakpoint/watchpoint, so we only need to loop over all locations
11864 struct bp_location
*bp_loc_first
; /* breakpoint */
11865 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11866 struct bp_location
*awp_loc_first
; /* access watchpoint */
11867 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11869 /* Saved former bp_locations array which we compare against the newly
11870 built bp_locations from the current state of ALL_BREAKPOINTS. */
11871 struct bp_location
**old_locp
;
11872 unsigned old_locations_count
;
11873 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11875 old_locations_count
= bp_locations_count
;
11876 bp_locations
= NULL
;
11877 bp_locations_count
= 0;
11879 for (breakpoint
*b
: all_breakpoints ())
11880 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11881 bp_locations_count
++;
11883 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11884 locp
= bp_locations
;
11885 for (breakpoint
*b
: all_breakpoints ())
11886 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11889 /* See if we need to "upgrade" a software breakpoint to a hardware
11890 breakpoint. Do this before deciding whether locations are
11891 duplicates. Also do this before sorting because sorting order
11892 depends on location type. */
11893 for (locp
= bp_locations
;
11894 locp
< bp_locations
+ bp_locations_count
;
11898 if (!loc
->inserted
&& should_be_inserted (loc
))
11899 handle_automatic_hardware_breakpoints (loc
);
11902 std::sort (bp_locations
, bp_locations
+ bp_locations_count
,
11903 bp_location_is_less_than
);
11905 bp_locations_target_extensions_update ();
11907 /* Identify bp_location instances that are no longer present in the
11908 new list, and therefore should be freed. Note that it's not
11909 necessary that those locations should be removed from inferior --
11910 if there's another location at the same address (previously
11911 marked as duplicate), we don't need to remove/insert the
11914 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11915 and former bp_location array state respectively. */
11917 locp
= bp_locations
;
11918 for (old_locp
= old_locations
.get ();
11919 old_locp
< old_locations
.get () + old_locations_count
;
11922 struct bp_location
*old_loc
= *old_locp
;
11923 struct bp_location
**loc2p
;
11925 /* Tells if 'old_loc' is found among the new locations. If
11926 not, we have to free it. */
11927 int found_object
= 0;
11928 /* Tells if the location should remain inserted in the target. */
11929 int keep_in_target
= 0;
11932 /* Skip LOCP entries which will definitely never be needed.
11933 Stop either at or being the one matching OLD_LOC. */
11934 while (locp
< bp_locations
+ bp_locations_count
11935 && (*locp
)->address
< old_loc
->address
)
11939 (loc2p
< bp_locations
+ bp_locations_count
11940 && (*loc2p
)->address
== old_loc
->address
);
11943 /* Check if this is a new/duplicated location or a duplicated
11944 location that had its condition modified. If so, we want to send
11945 its condition to the target if evaluation of conditions is taking
11947 if ((*loc2p
)->condition_changed
== condition_modified
11948 && (last_addr
!= old_loc
->address
11949 || last_pspace_num
!= old_loc
->pspace
->num
))
11951 force_breakpoint_reinsertion (*loc2p
);
11952 last_pspace_num
= old_loc
->pspace
->num
;
11955 if (*loc2p
== old_loc
)
11959 /* We have already handled this address, update it so that we don't
11960 have to go through updates again. */
11961 last_addr
= old_loc
->address
;
11963 /* Target-side condition evaluation: Handle deleted locations. */
11965 force_breakpoint_reinsertion (old_loc
);
11967 /* If this location is no longer present, and inserted, look if
11968 there's maybe a new location at the same address. If so,
11969 mark that one inserted, and don't remove this one. This is
11970 needed so that we don't have a time window where a breakpoint
11971 at certain location is not inserted. */
11973 if (old_loc
->inserted
)
11975 /* If the location is inserted now, we might have to remove
11978 if (found_object
&& should_be_inserted (old_loc
))
11980 /* The location is still present in the location list,
11981 and still should be inserted. Don't do anything. */
11982 keep_in_target
= 1;
11986 /* This location still exists, but it won't be kept in the
11987 target since it may have been disabled. We proceed to
11988 remove its target-side condition. */
11990 /* The location is either no longer present, or got
11991 disabled. See if there's another location at the
11992 same address, in which case we don't need to remove
11993 this one from the target. */
11995 /* OLD_LOC comes from existing struct breakpoint. */
11996 if (bl_address_is_meaningful (old_loc
))
11999 (loc2p
< bp_locations
+ bp_locations_count
12000 && (*loc2p
)->address
== old_loc
->address
);
12003 struct bp_location
*loc2
= *loc2p
;
12005 if (loc2
== old_loc
)
12008 if (breakpoint_locations_match (loc2
, old_loc
))
12010 /* Read watchpoint locations are switched to
12011 access watchpoints, if the former are not
12012 supported, but the latter are. */
12013 if (is_hardware_watchpoint (old_loc
->owner
))
12015 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12016 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12019 /* loc2 is a duplicated location. We need to check
12020 if it should be inserted in case it will be
12022 if (unduplicated_should_be_inserted (loc2
))
12024 swap_insertion (old_loc
, loc2
);
12025 keep_in_target
= 1;
12033 if (!keep_in_target
)
12035 if (remove_breakpoint (old_loc
))
12037 /* This is just about all we can do. We could keep
12038 this location on the global list, and try to
12039 remove it next time, but there's no particular
12040 reason why we will succeed next time.
12042 Note that at this point, old_loc->owner is still
12043 valid, as delete_breakpoint frees the breakpoint
12044 only after calling us. */
12045 printf_filtered (_("warning: Error removing "
12046 "breakpoint %d\n"),
12047 old_loc
->owner
->number
);
12055 if (removed
&& target_is_non_stop_p ()
12056 && need_moribund_for_location_type (old_loc
))
12058 /* This location was removed from the target. In
12059 non-stop mode, a race condition is possible where
12060 we've removed a breakpoint, but stop events for that
12061 breakpoint are already queued and will arrive later.
12062 We apply an heuristic to be able to distinguish such
12063 SIGTRAPs from other random SIGTRAPs: we keep this
12064 breakpoint location for a bit, and will retire it
12065 after we see some number of events. The theory here
12066 is that reporting of events should, "on the average",
12067 be fair, so after a while we'll see events from all
12068 threads that have anything of interest, and no longer
12069 need to keep this breakpoint location around. We
12070 don't hold locations forever so to reduce chances of
12071 mistaking a non-breakpoint SIGTRAP for a breakpoint
12074 The heuristic failing can be disastrous on
12075 decr_pc_after_break targets.
12077 On decr_pc_after_break targets, like e.g., x86-linux,
12078 if we fail to recognize a late breakpoint SIGTRAP,
12079 because events_till_retirement has reached 0 too
12080 soon, we'll fail to do the PC adjustment, and report
12081 a random SIGTRAP to the user. When the user resumes
12082 the inferior, it will most likely immediately crash
12083 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12084 corrupted, because of being resumed e.g., in the
12085 middle of a multi-byte instruction, or skipped a
12086 one-byte instruction. This was actually seen happen
12087 on native x86-linux, and should be less rare on
12088 targets that do not support new thread events, like
12089 remote, due to the heuristic depending on
12092 Mistaking a random SIGTRAP for a breakpoint trap
12093 causes similar symptoms (PC adjustment applied when
12094 it shouldn't), but then again, playing with SIGTRAPs
12095 behind the debugger's back is asking for trouble.
12097 Since hardware watchpoint traps are always
12098 distinguishable from other traps, so we don't need to
12099 apply keep hardware watchpoint moribund locations
12100 around. We simply always ignore hardware watchpoint
12101 traps we can no longer explain. */
12103 process_stratum_target
*proc_target
= nullptr;
12104 for (inferior
*inf
: all_inferiors ())
12105 if (inf
->pspace
== old_loc
->pspace
)
12107 proc_target
= inf
->process_target ();
12110 if (proc_target
!= nullptr)
12111 old_loc
->events_till_retirement
12112 = 3 * (thread_count (proc_target
) + 1);
12114 old_loc
->events_till_retirement
= 1;
12115 old_loc
->owner
= NULL
;
12117 moribund_locations
.push_back (old_loc
);
12121 old_loc
->owner
= NULL
;
12122 decref_bp_location (&old_loc
);
12127 /* Rescan breakpoints at the same address and section, marking the
12128 first one as "first" and any others as "duplicates". This is so
12129 that the bpt instruction is only inserted once. If we have a
12130 permanent breakpoint at the same place as BPT, make that one the
12131 official one, and the rest as duplicates. Permanent breakpoints
12132 are sorted first for the same address.
12134 Do the same for hardware watchpoints, but also considering the
12135 watchpoint's type (regular/access/read) and length. */
12137 bp_loc_first
= NULL
;
12138 wp_loc_first
= NULL
;
12139 awp_loc_first
= NULL
;
12140 rwp_loc_first
= NULL
;
12141 ALL_BP_LOCATIONS (loc
, locp
)
12143 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12145 struct bp_location
**loc_first_p
;
12146 breakpoint
*b
= loc
->owner
;
12148 if (!unduplicated_should_be_inserted (loc
)
12149 || !bl_address_is_meaningful (loc
)
12150 /* Don't detect duplicate for tracepoint locations because they are
12151 never duplicated. See the comments in field `duplicate' of
12152 `struct bp_location'. */
12153 || is_tracepoint (b
))
12155 /* Clear the condition modification flag. */
12156 loc
->condition_changed
= condition_unchanged
;
12160 if (b
->type
== bp_hardware_watchpoint
)
12161 loc_first_p
= &wp_loc_first
;
12162 else if (b
->type
== bp_read_watchpoint
)
12163 loc_first_p
= &rwp_loc_first
;
12164 else if (b
->type
== bp_access_watchpoint
)
12165 loc_first_p
= &awp_loc_first
;
12167 loc_first_p
= &bp_loc_first
;
12169 if (*loc_first_p
== NULL
12170 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12171 || !breakpoint_locations_match (loc
, *loc_first_p
))
12173 *loc_first_p
= loc
;
12174 loc
->duplicate
= 0;
12176 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12178 loc
->needs_update
= 1;
12179 /* Clear the condition modification flag. */
12180 loc
->condition_changed
= condition_unchanged
;
12186 /* This and the above ensure the invariant that the first location
12187 is not duplicated, and is the inserted one.
12188 All following are marked as duplicated, and are not inserted. */
12190 swap_insertion (loc
, *loc_first_p
);
12191 loc
->duplicate
= 1;
12193 /* Clear the condition modification flag. */
12194 loc
->condition_changed
= condition_unchanged
;
12197 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12199 if (insert_mode
!= UGLL_DONT_INSERT
)
12200 insert_breakpoint_locations ();
12203 /* Even though the caller told us to not insert new
12204 locations, we may still need to update conditions on the
12205 target's side of breakpoints that were already inserted
12206 if the target is evaluating breakpoint conditions. We
12207 only update conditions for locations that are marked
12209 update_inserted_breakpoint_locations ();
12213 if (insert_mode
!= UGLL_DONT_INSERT
)
12214 download_tracepoint_locations ();
12218 breakpoint_retire_moribund (void)
12220 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
12222 struct bp_location
*loc
= moribund_locations
[ix
];
12223 if (--(loc
->events_till_retirement
) == 0)
12225 decref_bp_location (&loc
);
12226 unordered_remove (moribund_locations
, ix
);
12233 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12238 update_global_location_list (insert_mode
);
12240 catch (const gdb_exception_error
&e
)
12245 /* Clear BKP from a BPS. */
12248 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12252 for (bs
= bps
; bs
; bs
= bs
->next
)
12253 if (bs
->breakpoint_at
== bpt
)
12255 bs
->breakpoint_at
= NULL
;
12256 bs
->old_val
= NULL
;
12257 /* bs->commands will be freed later. */
12261 /* Callback for iterate_over_threads. */
12263 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12265 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12267 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12271 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12275 say_where (struct breakpoint
*b
)
12277 struct value_print_options opts
;
12279 get_user_print_options (&opts
);
12281 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12283 if (b
->loc
== NULL
)
12285 /* For pending locations, the output differs slightly based
12286 on b->extra_string. If this is non-NULL, it contains either
12287 a condition or dprintf arguments. */
12288 if (b
->extra_string
== NULL
)
12290 printf_filtered (_(" (%s) pending."),
12291 event_location_to_string (b
->location
.get ()));
12293 else if (b
->type
== bp_dprintf
)
12295 printf_filtered (_(" (%s,%s) pending."),
12296 event_location_to_string (b
->location
.get ()),
12301 printf_filtered (_(" (%s %s) pending."),
12302 event_location_to_string (b
->location
.get ()),
12308 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12309 printf_filtered (" at %ps",
12310 styled_string (address_style
.style (),
12311 paddress (b
->loc
->gdbarch
,
12312 b
->loc
->address
)));
12313 if (b
->loc
->symtab
!= NULL
)
12315 /* If there is a single location, we can print the location
12317 if (b
->loc
->next
== NULL
)
12319 const char *filename
12320 = symtab_to_filename_for_display (b
->loc
->symtab
);
12321 printf_filtered (": file %ps, line %d.",
12322 styled_string (file_name_style
.style (),
12324 b
->loc
->line_number
);
12327 /* This is not ideal, but each location may have a
12328 different file name, and this at least reflects the
12329 real situation somewhat. */
12330 printf_filtered (": %s.",
12331 event_location_to_string (b
->location
.get ()));
12336 struct bp_location
*loc
= b
->loc
;
12338 for (; loc
; loc
= loc
->next
)
12340 printf_filtered (" (%d locations)", n
);
12345 bp_location::~bp_location ()
12347 xfree (function_name
);
12350 /* Destructor for the breakpoint base class. */
12352 breakpoint::~breakpoint ()
12354 xfree (this->cond_string
);
12355 xfree (this->extra_string
);
12358 static struct bp_location
*
12359 base_breakpoint_allocate_location (struct breakpoint
*self
)
12361 return new bp_location (self
);
12365 base_breakpoint_re_set (struct breakpoint
*b
)
12367 /* Nothing to re-set. */
12370 #define internal_error_pure_virtual_called() \
12371 gdb_assert_not_reached ("pure virtual function called")
12374 base_breakpoint_insert_location (struct bp_location
*bl
)
12376 internal_error_pure_virtual_called ();
12380 base_breakpoint_remove_location (struct bp_location
*bl
,
12381 enum remove_bp_reason reason
)
12383 internal_error_pure_virtual_called ();
12387 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12388 const address_space
*aspace
,
12390 const struct target_waitstatus
*ws
)
12392 internal_error_pure_virtual_called ();
12396 base_breakpoint_check_status (bpstat bs
)
12401 /* A "works_in_software_mode" breakpoint_ops method that just internal
12405 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12407 internal_error_pure_virtual_called ();
12410 /* A "resources_needed" breakpoint_ops method that just internal
12414 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12416 internal_error_pure_virtual_called ();
12419 static enum print_stop_action
12420 base_breakpoint_print_it (bpstat bs
)
12422 internal_error_pure_virtual_called ();
12426 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12427 struct ui_out
*uiout
)
12433 base_breakpoint_print_mention (struct breakpoint
*b
)
12435 internal_error_pure_virtual_called ();
12439 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12441 internal_error_pure_virtual_called ();
12445 base_breakpoint_create_sals_from_location
12446 (struct event_location
*location
,
12447 struct linespec_result
*canonical
,
12448 enum bptype type_wanted
)
12450 internal_error_pure_virtual_called ();
12454 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12455 struct linespec_result
*c
,
12456 gdb::unique_xmalloc_ptr
<char> cond_string
,
12457 gdb::unique_xmalloc_ptr
<char> extra_string
,
12458 enum bptype type_wanted
,
12459 enum bpdisp disposition
,
12461 int task
, int ignore_count
,
12462 const struct breakpoint_ops
*o
,
12463 int from_tty
, int enabled
,
12464 int internal
, unsigned flags
)
12466 internal_error_pure_virtual_called ();
12469 static std::vector
<symtab_and_line
>
12470 base_breakpoint_decode_location (struct breakpoint
*b
,
12471 struct event_location
*location
,
12472 struct program_space
*search_pspace
)
12474 internal_error_pure_virtual_called ();
12477 /* The default 'explains_signal' method. */
12480 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12485 /* The default "after_condition_true" method. */
12488 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12490 /* Nothing to do. */
12493 struct breakpoint_ops base_breakpoint_ops
=
12495 base_breakpoint_allocate_location
,
12496 base_breakpoint_re_set
,
12497 base_breakpoint_insert_location
,
12498 base_breakpoint_remove_location
,
12499 base_breakpoint_breakpoint_hit
,
12500 base_breakpoint_check_status
,
12501 base_breakpoint_resources_needed
,
12502 base_breakpoint_works_in_software_mode
,
12503 base_breakpoint_print_it
,
12505 base_breakpoint_print_one_detail
,
12506 base_breakpoint_print_mention
,
12507 base_breakpoint_print_recreate
,
12508 base_breakpoint_create_sals_from_location
,
12509 base_breakpoint_create_breakpoints_sal
,
12510 base_breakpoint_decode_location
,
12511 base_breakpoint_explains_signal
,
12512 base_breakpoint_after_condition_true
,
12515 /* Default breakpoint_ops methods. */
12518 bkpt_re_set (struct breakpoint
*b
)
12520 /* FIXME: is this still reachable? */
12521 if (breakpoint_event_location_empty_p (b
))
12523 /* Anything without a location can't be re-set. */
12524 delete_breakpoint (b
);
12528 breakpoint_re_set_default (b
);
12532 bkpt_insert_location (struct bp_location
*bl
)
12534 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12536 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12537 bl
->target_info
.placed_address
= addr
;
12539 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12540 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12542 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12546 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12548 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12549 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12551 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12555 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12556 const address_space
*aspace
, CORE_ADDR bp_addr
,
12557 const struct target_waitstatus
*ws
)
12559 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12560 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12563 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12567 if (overlay_debugging
/* unmapped overlay section */
12568 && section_is_overlay (bl
->section
)
12569 && !section_is_mapped (bl
->section
))
12576 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12577 const address_space
*aspace
, CORE_ADDR bp_addr
,
12578 const struct target_waitstatus
*ws
)
12580 if (dprintf_style
== dprintf_style_agent
12581 && target_can_run_breakpoint_commands ())
12583 /* An agent-style dprintf never causes a stop. If we see a trap
12584 for this address it must be for a breakpoint that happens to
12585 be set at the same address. */
12589 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12593 bkpt_resources_needed (const struct bp_location
*bl
)
12595 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12600 static enum print_stop_action
12601 bkpt_print_it (bpstat bs
)
12603 struct breakpoint
*b
;
12604 const struct bp_location
*bl
;
12606 struct ui_out
*uiout
= current_uiout
;
12608 gdb_assert (bs
->bp_location_at
!= NULL
);
12610 bl
= bs
->bp_location_at
.get ();
12611 b
= bs
->breakpoint_at
;
12613 bp_temp
= b
->disposition
== disp_del
;
12614 if (bl
->address
!= bl
->requested_address
)
12615 breakpoint_adjustment_warning (bl
->requested_address
,
12618 annotate_breakpoint (b
->number
);
12619 maybe_print_thread_hit_breakpoint (uiout
);
12621 if (uiout
->is_mi_like_p ())
12623 uiout
->field_string ("reason",
12624 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12625 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12628 uiout
->message ("Temporary breakpoint %pF, ",
12629 signed_field ("bkptno", b
->number
));
12631 uiout
->message ("Breakpoint %pF, ",
12632 signed_field ("bkptno", b
->number
));
12634 return PRINT_SRC_AND_LOC
;
12638 bkpt_print_mention (struct breakpoint
*b
)
12640 if (current_uiout
->is_mi_like_p ())
12645 case bp_breakpoint
:
12646 case bp_gnu_ifunc_resolver
:
12647 if (b
->disposition
== disp_del
)
12648 printf_filtered (_("Temporary breakpoint"));
12650 printf_filtered (_("Breakpoint"));
12651 printf_filtered (_(" %d"), b
->number
);
12652 if (b
->type
== bp_gnu_ifunc_resolver
)
12653 printf_filtered (_(" at gnu-indirect-function resolver"));
12655 case bp_hardware_breakpoint
:
12656 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12659 printf_filtered (_("Dprintf %d"), b
->number
);
12667 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12669 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12670 fprintf_unfiltered (fp
, "tbreak");
12671 else if (tp
->type
== bp_breakpoint
)
12672 fprintf_unfiltered (fp
, "break");
12673 else if (tp
->type
== bp_hardware_breakpoint
12674 && tp
->disposition
== disp_del
)
12675 fprintf_unfiltered (fp
, "thbreak");
12676 else if (tp
->type
== bp_hardware_breakpoint
)
12677 fprintf_unfiltered (fp
, "hbreak");
12679 internal_error (__FILE__
, __LINE__
,
12680 _("unhandled breakpoint type %d"), (int) tp
->type
);
12682 fprintf_unfiltered (fp
, " %s",
12683 event_location_to_string (tp
->location
.get ()));
12685 /* Print out extra_string if this breakpoint is pending. It might
12686 contain, for example, conditions that were set by the user. */
12687 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12688 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12690 print_recreate_thread (tp
, fp
);
12694 bkpt_create_sals_from_location (struct event_location
*location
,
12695 struct linespec_result
*canonical
,
12696 enum bptype type_wanted
)
12698 create_sals_from_location_default (location
, canonical
, type_wanted
);
12702 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12703 struct linespec_result
*canonical
,
12704 gdb::unique_xmalloc_ptr
<char> cond_string
,
12705 gdb::unique_xmalloc_ptr
<char> extra_string
,
12706 enum bptype type_wanted
,
12707 enum bpdisp disposition
,
12709 int task
, int ignore_count
,
12710 const struct breakpoint_ops
*ops
,
12711 int from_tty
, int enabled
,
12712 int internal
, unsigned flags
)
12714 create_breakpoints_sal_default (gdbarch
, canonical
,
12715 std::move (cond_string
),
12716 std::move (extra_string
),
12718 disposition
, thread
, task
,
12719 ignore_count
, ops
, from_tty
,
12720 enabled
, internal
, flags
);
12723 static std::vector
<symtab_and_line
>
12724 bkpt_decode_location (struct breakpoint
*b
,
12725 struct event_location
*location
,
12726 struct program_space
*search_pspace
)
12728 return decode_location_default (b
, location
, search_pspace
);
12731 /* Virtual table for internal breakpoints. */
12734 internal_bkpt_re_set (struct breakpoint
*b
)
12738 /* Delete overlay event and longjmp master breakpoints; they
12739 will be reset later by breakpoint_re_set. */
12740 case bp_overlay_event
:
12741 case bp_longjmp_master
:
12742 case bp_std_terminate_master
:
12743 case bp_exception_master
:
12744 delete_breakpoint (b
);
12747 /* This breakpoint is special, it's set up when the inferior
12748 starts and we really don't want to touch it. */
12749 case bp_shlib_event
:
12751 /* Like bp_shlib_event, this breakpoint type is special. Once
12752 it is set up, we do not want to touch it. */
12753 case bp_thread_event
:
12759 internal_bkpt_check_status (bpstat bs
)
12761 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12763 /* If requested, stop when the dynamic linker notifies GDB of
12764 events. This allows the user to get control and place
12765 breakpoints in initializer routines for dynamically loaded
12766 objects (among other things). */
12767 bs
->stop
= stop_on_solib_events
;
12768 bs
->print
= stop_on_solib_events
;
12774 static enum print_stop_action
12775 internal_bkpt_print_it (bpstat bs
)
12777 struct breakpoint
*b
;
12779 b
= bs
->breakpoint_at
;
12783 case bp_shlib_event
:
12784 /* Did we stop because the user set the stop_on_solib_events
12785 variable? (If so, we report this as a generic, "Stopped due
12786 to shlib event" message.) */
12787 print_solib_event (0);
12790 case bp_thread_event
:
12791 /* Not sure how we will get here.
12792 GDB should not stop for these breakpoints. */
12793 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12796 case bp_overlay_event
:
12797 /* By analogy with the thread event, GDB should not stop for these. */
12798 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12801 case bp_longjmp_master
:
12802 /* These should never be enabled. */
12803 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12806 case bp_std_terminate_master
:
12807 /* These should never be enabled. */
12808 printf_filtered (_("std::terminate Master Breakpoint: "
12809 "gdb should not stop!\n"));
12812 case bp_exception_master
:
12813 /* These should never be enabled. */
12814 printf_filtered (_("Exception Master Breakpoint: "
12815 "gdb should not stop!\n"));
12819 return PRINT_NOTHING
;
12823 internal_bkpt_print_mention (struct breakpoint
*b
)
12825 /* Nothing to mention. These breakpoints are internal. */
12828 /* Virtual table for momentary breakpoints */
12831 momentary_bkpt_re_set (struct breakpoint
*b
)
12833 /* Keep temporary breakpoints, which can be encountered when we step
12834 over a dlopen call and solib_add is resetting the breakpoints.
12835 Otherwise these should have been blown away via the cleanup chain
12836 or by breakpoint_init_inferior when we rerun the executable. */
12840 momentary_bkpt_check_status (bpstat bs
)
12842 /* Nothing. The point of these breakpoints is causing a stop. */
12845 static enum print_stop_action
12846 momentary_bkpt_print_it (bpstat bs
)
12848 return PRINT_UNKNOWN
;
12852 momentary_bkpt_print_mention (struct breakpoint
*b
)
12854 /* Nothing to mention. These breakpoints are internal. */
12857 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12859 It gets cleared already on the removal of the first one of such placed
12860 breakpoints. This is OK as they get all removed altogether. */
12862 longjmp_breakpoint::~longjmp_breakpoint ()
12864 thread_info
*tp
= find_thread_global_id (this->thread
);
12867 tp
->initiating_frame
= null_frame_id
;
12870 /* Specific methods for probe breakpoints. */
12873 bkpt_probe_insert_location (struct bp_location
*bl
)
12875 int v
= bkpt_insert_location (bl
);
12879 /* The insertion was successful, now let's set the probe's semaphore
12881 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12888 bkpt_probe_remove_location (struct bp_location
*bl
,
12889 enum remove_bp_reason reason
)
12891 /* Let's clear the semaphore before removing the location. */
12892 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12894 return bkpt_remove_location (bl
, reason
);
12898 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12899 struct linespec_result
*canonical
,
12900 enum bptype type_wanted
)
12902 struct linespec_sals lsal
;
12904 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12906 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12907 canonical
->lsals
.push_back (std::move (lsal
));
12910 static std::vector
<symtab_and_line
>
12911 bkpt_probe_decode_location (struct breakpoint
*b
,
12912 struct event_location
*location
,
12913 struct program_space
*search_pspace
)
12915 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12917 error (_("probe not found"));
12921 /* The breakpoint_ops structure to be used in tracepoints. */
12924 tracepoint_re_set (struct breakpoint
*b
)
12926 breakpoint_re_set_default (b
);
12930 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12931 const address_space
*aspace
, CORE_ADDR bp_addr
,
12932 const struct target_waitstatus
*ws
)
12934 /* By definition, the inferior does not report stops at
12940 tracepoint_print_one_detail (const struct breakpoint
*self
,
12941 struct ui_out
*uiout
)
12943 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12944 if (!tp
->static_trace_marker_id
.empty ())
12946 gdb_assert (self
->type
== bp_static_tracepoint
);
12948 uiout
->message ("\tmarker id is %pF\n",
12949 string_field ("static-tracepoint-marker-string-id",
12950 tp
->static_trace_marker_id
.c_str ()));
12955 tracepoint_print_mention (struct breakpoint
*b
)
12957 if (current_uiout
->is_mi_like_p ())
12962 case bp_tracepoint
:
12963 printf_filtered (_("Tracepoint"));
12964 printf_filtered (_(" %d"), b
->number
);
12966 case bp_fast_tracepoint
:
12967 printf_filtered (_("Fast tracepoint"));
12968 printf_filtered (_(" %d"), b
->number
);
12970 case bp_static_tracepoint
:
12971 printf_filtered (_("Static tracepoint"));
12972 printf_filtered (_(" %d"), b
->number
);
12975 internal_error (__FILE__
, __LINE__
,
12976 _("unhandled tracepoint type %d"), (int) b
->type
);
12983 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12985 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12987 if (self
->type
== bp_fast_tracepoint
)
12988 fprintf_unfiltered (fp
, "ftrace");
12989 else if (self
->type
== bp_static_tracepoint
)
12990 fprintf_unfiltered (fp
, "strace");
12991 else if (self
->type
== bp_tracepoint
)
12992 fprintf_unfiltered (fp
, "trace");
12994 internal_error (__FILE__
, __LINE__
,
12995 _("unhandled tracepoint type %d"), (int) self
->type
);
12997 fprintf_unfiltered (fp
, " %s",
12998 event_location_to_string (self
->location
.get ()));
12999 print_recreate_thread (self
, fp
);
13001 if (tp
->pass_count
)
13002 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13006 tracepoint_create_sals_from_location (struct event_location
*location
,
13007 struct linespec_result
*canonical
,
13008 enum bptype type_wanted
)
13010 create_sals_from_location_default (location
, canonical
, type_wanted
);
13014 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13015 struct linespec_result
*canonical
,
13016 gdb::unique_xmalloc_ptr
<char> cond_string
,
13017 gdb::unique_xmalloc_ptr
<char> extra_string
,
13018 enum bptype type_wanted
,
13019 enum bpdisp disposition
,
13021 int task
, int ignore_count
,
13022 const struct breakpoint_ops
*ops
,
13023 int from_tty
, int enabled
,
13024 int internal
, unsigned flags
)
13026 create_breakpoints_sal_default (gdbarch
, canonical
,
13027 std::move (cond_string
),
13028 std::move (extra_string
),
13030 disposition
, thread
, task
,
13031 ignore_count
, ops
, from_tty
,
13032 enabled
, internal
, flags
);
13035 static std::vector
<symtab_and_line
>
13036 tracepoint_decode_location (struct breakpoint
*b
,
13037 struct event_location
*location
,
13038 struct program_space
*search_pspace
)
13040 return decode_location_default (b
, location
, search_pspace
);
13043 struct breakpoint_ops tracepoint_breakpoint_ops
;
13045 /* Virtual table for tracepoints on static probes. */
13048 tracepoint_probe_create_sals_from_location
13049 (struct event_location
*location
,
13050 struct linespec_result
*canonical
,
13051 enum bptype type_wanted
)
13053 /* We use the same method for breakpoint on probes. */
13054 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13057 static std::vector
<symtab_and_line
>
13058 tracepoint_probe_decode_location (struct breakpoint
*b
,
13059 struct event_location
*location
,
13060 struct program_space
*search_pspace
)
13062 /* We use the same method for breakpoint on probes. */
13063 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13066 /* Dprintf breakpoint_ops methods. */
13069 dprintf_re_set (struct breakpoint
*b
)
13071 breakpoint_re_set_default (b
);
13073 /* extra_string should never be non-NULL for dprintf. */
13074 gdb_assert (b
->extra_string
!= NULL
);
13076 /* 1 - connect to target 1, that can run breakpoint commands.
13077 2 - create a dprintf, which resolves fine.
13078 3 - disconnect from target 1
13079 4 - connect to target 2, that can NOT run breakpoint commands.
13081 After steps #3/#4, you'll want the dprintf command list to
13082 be updated, because target 1 and 2 may well return different
13083 answers for target_can_run_breakpoint_commands().
13084 Given absence of finer grained resetting, we get to do
13085 it all the time. */
13086 if (b
->extra_string
!= NULL
)
13087 update_dprintf_command_list (b
);
13090 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13093 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13095 fprintf_unfiltered (fp
, "dprintf %s,%s",
13096 event_location_to_string (tp
->location
.get ()),
13098 print_recreate_thread (tp
, fp
);
13101 /* Implement the "after_condition_true" breakpoint_ops method for
13104 dprintf's are implemented with regular commands in their command
13105 list, but we run the commands here instead of before presenting the
13106 stop to the user, as dprintf's don't actually cause a stop. This
13107 also makes it so that the commands of multiple dprintfs at the same
13108 address are all handled. */
13111 dprintf_after_condition_true (struct bpstats
*bs
)
13113 struct bpstats tmp_bs
;
13114 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13116 /* dprintf's never cause a stop. This wasn't set in the
13117 check_status hook instead because that would make the dprintf's
13118 condition not be evaluated. */
13121 /* Run the command list here. Take ownership of it instead of
13122 copying. We never want these commands to run later in
13123 bpstat_do_actions, if a breakpoint that causes a stop happens to
13124 be set at same address as this dprintf, or even if running the
13125 commands here throws. */
13126 tmp_bs
.commands
= bs
->commands
;
13127 bs
->commands
= NULL
;
13129 bpstat_do_actions_1 (&tmp_bs_p
);
13131 /* 'tmp_bs.commands' will usually be NULL by now, but
13132 bpstat_do_actions_1 may return early without processing the whole
13136 /* The breakpoint_ops structure to be used on static tracepoints with
13140 strace_marker_create_sals_from_location (struct event_location
*location
,
13141 struct linespec_result
*canonical
,
13142 enum bptype type_wanted
)
13144 struct linespec_sals lsal
;
13145 const char *arg_start
, *arg
;
13147 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
13148 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13150 std::string
str (arg_start
, arg
- arg_start
);
13151 const char *ptr
= str
.c_str ();
13152 canonical
->location
13153 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
13156 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13157 canonical
->lsals
.push_back (std::move (lsal
));
13161 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13162 struct linespec_result
*canonical
,
13163 gdb::unique_xmalloc_ptr
<char> cond_string
,
13164 gdb::unique_xmalloc_ptr
<char> extra_string
,
13165 enum bptype type_wanted
,
13166 enum bpdisp disposition
,
13168 int task
, int ignore_count
,
13169 const struct breakpoint_ops
*ops
,
13170 int from_tty
, int enabled
,
13171 int internal
, unsigned flags
)
13173 const linespec_sals
&lsal
= canonical
->lsals
[0];
13175 /* If the user is creating a static tracepoint by marker id
13176 (strace -m MARKER_ID), then store the sals index, so that
13177 breakpoint_re_set can try to match up which of the newly
13178 found markers corresponds to this one, and, don't try to
13179 expand multiple locations for each sal, given than SALS
13180 already should contain all sals for MARKER_ID. */
13182 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13184 event_location_up location
13185 = copy_event_location (canonical
->location
.get ());
13187 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13188 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13189 std::move (location
), NULL
,
13190 std::move (cond_string
),
13191 std::move (extra_string
),
13192 type_wanted
, disposition
,
13193 thread
, task
, ignore_count
, ops
,
13194 from_tty
, enabled
, internal
, flags
,
13195 canonical
->special_display
);
13196 /* Given that its possible to have multiple markers with
13197 the same string id, if the user is creating a static
13198 tracepoint by marker id ("strace -m MARKER_ID"), then
13199 store the sals index, so that breakpoint_re_set can
13200 try to match up which of the newly found markers
13201 corresponds to this one */
13202 tp
->static_trace_marker_id_idx
= i
;
13204 install_breakpoint (internal
, std::move (tp
), 0);
13208 static std::vector
<symtab_and_line
>
13209 strace_marker_decode_location (struct breakpoint
*b
,
13210 struct event_location
*location
,
13211 struct program_space
*search_pspace
)
13213 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13214 const char *s
= get_linespec_location (location
)->spec_string
;
13216 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13217 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13219 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13224 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
13227 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13230 strace_marker_p (struct breakpoint
*b
)
13232 return b
->ops
== &strace_marker_breakpoint_ops
;
13235 /* Delete a breakpoint and clean up all traces of it in the data
13239 delete_breakpoint (struct breakpoint
*bpt
)
13241 gdb_assert (bpt
!= NULL
);
13243 /* Has this bp already been deleted? This can happen because
13244 multiple lists can hold pointers to bp's. bpstat lists are
13247 One example of this happening is a watchpoint's scope bp. When
13248 the scope bp triggers, we notice that the watchpoint is out of
13249 scope, and delete it. We also delete its scope bp. But the
13250 scope bp is marked "auto-deleting", and is already on a bpstat.
13251 That bpstat is then checked for auto-deleting bp's, which are
13254 A real solution to this problem might involve reference counts in
13255 bp's, and/or giving them pointers back to their referencing
13256 bpstat's, and teaching delete_breakpoint to only free a bp's
13257 storage when no more references were extent. A cheaper bandaid
13259 if (bpt
->type
== bp_none
)
13262 /* At least avoid this stale reference until the reference counting
13263 of breakpoints gets resolved. */
13264 if (bpt
->related_breakpoint
!= bpt
)
13266 struct breakpoint
*related
;
13267 struct watchpoint
*w
;
13269 if (bpt
->type
== bp_watchpoint_scope
)
13270 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13271 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13272 w
= (struct watchpoint
*) bpt
;
13276 watchpoint_del_at_next_stop (w
);
13278 /* Unlink bpt from the bpt->related_breakpoint ring. */
13279 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13280 related
= related
->related_breakpoint
);
13281 related
->related_breakpoint
= bpt
->related_breakpoint
;
13282 bpt
->related_breakpoint
= bpt
;
13285 /* watch_command_1 creates a watchpoint but only sets its number if
13286 update_watchpoint succeeds in creating its bp_locations. If there's
13287 a problem in that process, we'll be asked to delete the half-created
13288 watchpoint. In that case, don't announce the deletion. */
13290 gdb::observers::breakpoint_deleted
.notify (bpt
);
13292 if (breakpoint_chain
== bpt
)
13293 breakpoint_chain
= bpt
->next
;
13295 for (breakpoint
*b
: all_breakpoints ())
13296 if (b
->next
== bpt
)
13298 b
->next
= bpt
->next
;
13302 /* Be sure no bpstat's are pointing at the breakpoint after it's
13304 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13305 in all threads for now. Note that we cannot just remove bpstats
13306 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13307 commands are associated with the bpstat; if we remove it here,
13308 then the later call to bpstat_do_actions (&stop_bpstat); in
13309 event-top.c won't do anything, and temporary breakpoints with
13310 commands won't work. */
13312 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13314 /* Now that breakpoint is removed from breakpoint list, update the
13315 global location list. This will remove locations that used to
13316 belong to this breakpoint. Do this before freeing the breakpoint
13317 itself, since remove_breakpoint looks at location's owner. It
13318 might be better design to have location completely
13319 self-contained, but it's not the case now. */
13320 update_global_location_list (UGLL_DONT_INSERT
);
13322 /* On the chance that someone will soon try again to delete this
13323 same bp, we mark it as deleted before freeing its storage. */
13324 bpt
->type
= bp_none
;
13328 /* Iterator function to call a user-provided callback function once
13329 for each of B and its related breakpoints. */
13332 iterate_over_related_breakpoints (struct breakpoint
*b
,
13333 gdb::function_view
<void (breakpoint
*)> function
)
13335 struct breakpoint
*related
;
13340 struct breakpoint
*next
;
13342 /* FUNCTION may delete RELATED. */
13343 next
= related
->related_breakpoint
;
13345 if (next
== related
)
13347 /* RELATED is the last ring entry. */
13348 function (related
);
13350 /* FUNCTION may have deleted it, so we'd never reach back to
13351 B. There's nothing left to do anyway, so just break
13356 function (related
);
13360 while (related
!= b
);
13364 delete_command (const char *arg
, int from_tty
)
13370 int breaks_to_delete
= 0;
13372 /* Delete all breakpoints if no argument. Do not delete
13373 internal breakpoints, these have to be deleted with an
13374 explicit breakpoint number argument. */
13375 for (breakpoint
*b
: all_breakpoints ())
13376 if (user_breakpoint_p (b
))
13378 breaks_to_delete
= 1;
13382 /* Ask user only if there are some breakpoints to delete. */
13384 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13385 for (breakpoint
*b
: all_breakpoints_safe ())
13386 if (user_breakpoint_p (b
))
13387 delete_breakpoint (b
);
13390 map_breakpoint_numbers
13391 (arg
, [&] (breakpoint
*br
)
13393 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13397 /* Return true if all locations of B bound to PSPACE are pending. If
13398 PSPACE is NULL, all locations of all program spaces are
13402 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13404 struct bp_location
*loc
;
13406 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13407 if ((pspace
== NULL
13408 || loc
->pspace
== pspace
)
13409 && !loc
->shlib_disabled
13410 && !loc
->pspace
->executing_startup
)
13415 /* Subroutine of update_breakpoint_locations to simplify it.
13416 Return non-zero if multiple fns in list LOC have the same name.
13417 Null names are ignored. */
13420 ambiguous_names_p (struct bp_location
*loc
)
13422 struct bp_location
*l
;
13423 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
13426 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13429 const char *name
= l
->function_name
;
13431 /* Allow for some names to be NULL, ignore them. */
13435 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
13437 /* NOTE: We can assume slot != NULL here because xcalloc never
13447 /* When symbols change, it probably means the sources changed as well,
13448 and it might mean the static tracepoint markers are no longer at
13449 the same address or line numbers they used to be at last we
13450 checked. Losing your static tracepoints whenever you rebuild is
13451 undesirable. This function tries to resync/rematch gdb static
13452 tracepoints with the markers on the target, for static tracepoints
13453 that have not been set by marker id. Static tracepoint that have
13454 been set by marker id are reset by marker id in breakpoint_re_set.
13457 1) For a tracepoint set at a specific address, look for a marker at
13458 the old PC. If one is found there, assume to be the same marker.
13459 If the name / string id of the marker found is different from the
13460 previous known name, assume that means the user renamed the marker
13461 in the sources, and output a warning.
13463 2) For a tracepoint set at a given line number, look for a marker
13464 at the new address of the old line number. If one is found there,
13465 assume to be the same marker. If the name / string id of the
13466 marker found is different from the previous known name, assume that
13467 means the user renamed the marker in the sources, and output a
13470 3) If a marker is no longer found at the same address or line, it
13471 may mean the marker no longer exists. But it may also just mean
13472 the code changed a bit. Maybe the user added a few lines of code
13473 that made the marker move up or down (in line number terms). Ask
13474 the target for info about the marker with the string id as we knew
13475 it. If found, update line number and address in the matching
13476 static tracepoint. This will get confused if there's more than one
13477 marker with the same ID (possible in UST, although unadvised
13478 precisely because it confuses tools). */
13480 static struct symtab_and_line
13481 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13483 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13484 struct static_tracepoint_marker marker
;
13489 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13491 if (target_static_tracepoint_marker_at (pc
, &marker
))
13493 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13494 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13495 b
->number
, tp
->static_trace_marker_id
.c_str (),
13496 marker
.str_id
.c_str ());
13498 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13503 /* Old marker wasn't found on target at lineno. Try looking it up
13505 if (!sal
.explicit_pc
13507 && sal
.symtab
!= NULL
13508 && !tp
->static_trace_marker_id
.empty ())
13510 std::vector
<static_tracepoint_marker
> markers
13511 = target_static_tracepoint_markers_by_strid
13512 (tp
->static_trace_marker_id
.c_str ());
13514 if (!markers
.empty ())
13516 struct symbol
*sym
;
13517 struct static_tracepoint_marker
*tpmarker
;
13518 struct ui_out
*uiout
= current_uiout
;
13519 struct explicit_location explicit_loc
;
13521 tpmarker
= &markers
[0];
13523 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13525 warning (_("marker for static tracepoint %d (%s) not "
13526 "found at previous line number"),
13527 b
->number
, tp
->static_trace_marker_id
.c_str ());
13529 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13530 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13531 uiout
->text ("Now in ");
13534 uiout
->field_string ("func", sym
->print_name (),
13535 function_name_style
.style ());
13536 uiout
->text (" at ");
13538 uiout
->field_string ("file",
13539 symtab_to_filename_for_display (sal2
.symtab
),
13540 file_name_style
.style ());
13543 if (uiout
->is_mi_like_p ())
13545 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13547 uiout
->field_string ("fullname", fullname
);
13550 uiout
->field_signed ("line", sal2
.line
);
13551 uiout
->text ("\n");
13553 b
->loc
->line_number
= sal2
.line
;
13554 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13556 b
->location
.reset (NULL
);
13557 initialize_explicit_location (&explicit_loc
);
13558 explicit_loc
.source_filename
13559 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13560 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13561 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13562 b
->location
= new_explicit_location (&explicit_loc
);
13564 /* Might be nice to check if function changed, and warn if
13571 /* Returns 1 iff locations A and B are sufficiently same that
13572 we don't need to report breakpoint as changed. */
13575 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13579 if (a
->address
!= b
->address
)
13582 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13585 if (a
->enabled
!= b
->enabled
)
13588 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
13595 if ((a
== NULL
) != (b
== NULL
))
13601 /* Split all locations of B that are bound to PSPACE out of B's
13602 location list to a separate list and return that list's head. If
13603 PSPACE is NULL, hoist out all locations of B. */
13605 static struct bp_location
*
13606 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13608 struct bp_location head
;
13609 struct bp_location
*i
= b
->loc
;
13610 struct bp_location
**i_link
= &b
->loc
;
13611 struct bp_location
*hoisted
= &head
;
13613 if (pspace
== NULL
)
13624 if (i
->pspace
== pspace
)
13639 /* Create new breakpoint locations for B (a hardware or software
13640 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13641 zero, then B is a ranged breakpoint. Only recreates locations for
13642 FILTER_PSPACE. Locations of other program spaces are left
13646 update_breakpoint_locations (struct breakpoint
*b
,
13647 struct program_space
*filter_pspace
,
13648 gdb::array_view
<const symtab_and_line
> sals
,
13649 gdb::array_view
<const symtab_and_line
> sals_end
)
13651 struct bp_location
*existing_locations
;
13653 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13655 /* Ranged breakpoints have only one start location and one end
13657 b
->enable_state
= bp_disabled
;
13658 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13659 "multiple locations found\n"),
13664 /* If there's no new locations, and all existing locations are
13665 pending, don't do anything. This optimizes the common case where
13666 all locations are in the same shared library, that was unloaded.
13667 We'd like to retain the location, so that when the library is
13668 loaded again, we don't loose the enabled/disabled status of the
13669 individual locations. */
13670 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13673 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13675 for (const auto &sal
: sals
)
13677 struct bp_location
*new_loc
;
13679 switch_to_program_space_and_thread (sal
.pspace
);
13681 new_loc
= add_location_to_breakpoint (b
, &sal
);
13683 /* Reparse conditions, they might contain references to the
13685 if (b
->cond_string
!= NULL
)
13689 s
= b
->cond_string
;
13692 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13693 block_for_pc (sal
.pc
),
13696 catch (const gdb_exception_error
&e
)
13698 new_loc
->disabled_by_cond
= true;
13702 if (!sals_end
.empty ())
13704 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13706 new_loc
->length
= end
- sals
[0].pc
+ 1;
13710 /* If possible, carry over 'disable' status from existing
13713 struct bp_location
*e
= existing_locations
;
13714 /* If there are multiple breakpoints with the same function name,
13715 e.g. for inline functions, comparing function names won't work.
13716 Instead compare pc addresses; this is just a heuristic as things
13717 may have moved, but in practice it gives the correct answer
13718 often enough until a better solution is found. */
13719 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13721 for (; e
; e
= e
->next
)
13723 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
13725 struct bp_location
*l
= b
->loc
;
13726 if (have_ambiguous_names
)
13728 for (; l
; l
= l
->next
)
13730 /* Ignore software vs hardware location type at
13731 this point, because with "set breakpoint
13732 auto-hw", after a re-set, locations that were
13733 hardware can end up as software, or vice versa.
13734 As mentioned above, this is an heuristic and in
13735 practice should give the correct answer often
13737 if (breakpoint_locations_match (e
, l
, true))
13739 l
->enabled
= e
->enabled
;
13740 l
->disabled_by_cond
= e
->disabled_by_cond
;
13747 for (; l
; l
= l
->next
)
13748 if (l
->function_name
13749 && strcmp (e
->function_name
, l
->function_name
) == 0)
13751 l
->enabled
= e
->enabled
;
13752 l
->disabled_by_cond
= e
->disabled_by_cond
;
13760 if (!locations_are_equal (existing_locations
, b
->loc
))
13761 gdb::observers::breakpoint_modified
.notify (b
);
13764 /* Find the SaL locations corresponding to the given LOCATION.
13765 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13767 static std::vector
<symtab_and_line
>
13768 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13769 struct program_space
*search_pspace
, int *found
)
13771 struct gdb_exception exception
;
13773 gdb_assert (b
->ops
!= NULL
);
13775 std::vector
<symtab_and_line
> sals
;
13779 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13781 catch (gdb_exception_error
&e
)
13783 int not_found_and_ok
= 0;
13785 /* For pending breakpoints, it's expected that parsing will
13786 fail until the right shared library is loaded. User has
13787 already told to create pending breakpoints and don't need
13788 extra messages. If breakpoint is in bp_shlib_disabled
13789 state, then user already saw the message about that
13790 breakpoint being disabled, and don't want to see more
13792 if (e
.error
== NOT_FOUND_ERROR
13793 && (b
->condition_not_parsed
13795 && search_pspace
!= NULL
13796 && b
->loc
->pspace
!= search_pspace
)
13797 || (b
->loc
&& b
->loc
->shlib_disabled
)
13798 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13799 || b
->enable_state
== bp_disabled
))
13800 not_found_and_ok
= 1;
13802 if (!not_found_and_ok
)
13804 /* We surely don't want to warn about the same breakpoint
13805 10 times. One solution, implemented here, is disable
13806 the breakpoint on error. Another solution would be to
13807 have separate 'warning emitted' flag. Since this
13808 happens only when a binary has changed, I don't know
13809 which approach is better. */
13810 b
->enable_state
= bp_disabled
;
13814 exception
= std::move (e
);
13817 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13819 for (auto &sal
: sals
)
13820 resolve_sal_pc (&sal
);
13821 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13823 char *cond_string
, *extra_string
;
13826 find_condition_and_thread_for_sals (sals
, b
->extra_string
,
13827 &cond_string
, &thread
,
13828 &task
, &extra_string
);
13829 gdb_assert (b
->cond_string
== NULL
);
13831 b
->cond_string
= cond_string
;
13832 b
->thread
= thread
;
13836 xfree (b
->extra_string
);
13837 b
->extra_string
= extra_string
;
13839 b
->condition_not_parsed
= 0;
13842 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13843 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13853 /* The default re_set method, for typical hardware or software
13854 breakpoints. Reevaluate the breakpoint and recreate its
13858 breakpoint_re_set_default (struct breakpoint
*b
)
13860 struct program_space
*filter_pspace
= current_program_space
;
13861 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13864 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13865 filter_pspace
, &found
);
13867 expanded
= std::move (sals
);
13869 if (b
->location_range_end
!= NULL
)
13871 std::vector
<symtab_and_line
> sals_end
13872 = location_to_sals (b
, b
->location_range_end
.get (),
13873 filter_pspace
, &found
);
13875 expanded_end
= std::move (sals_end
);
13878 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13881 /* Default method for creating SALs from an address string. It basically
13882 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13885 create_sals_from_location_default (struct event_location
*location
,
13886 struct linespec_result
*canonical
,
13887 enum bptype type_wanted
)
13889 parse_breakpoint_sals (location
, canonical
);
13892 /* Call create_breakpoints_sal for the given arguments. This is the default
13893 function for the `create_breakpoints_sal' method of
13897 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13898 struct linespec_result
*canonical
,
13899 gdb::unique_xmalloc_ptr
<char> cond_string
,
13900 gdb::unique_xmalloc_ptr
<char> extra_string
,
13901 enum bptype type_wanted
,
13902 enum bpdisp disposition
,
13904 int task
, int ignore_count
,
13905 const struct breakpoint_ops
*ops
,
13906 int from_tty
, int enabled
,
13907 int internal
, unsigned flags
)
13909 create_breakpoints_sal (gdbarch
, canonical
,
13910 std::move (cond_string
),
13911 std::move (extra_string
),
13912 type_wanted
, disposition
,
13913 thread
, task
, ignore_count
, ops
, from_tty
,
13914 enabled
, internal
, flags
);
13917 /* Decode the line represented by S by calling decode_line_full. This is the
13918 default function for the `decode_location' method of breakpoint_ops. */
13920 static std::vector
<symtab_and_line
>
13921 decode_location_default (struct breakpoint
*b
,
13922 struct event_location
*location
,
13923 struct program_space
*search_pspace
)
13925 struct linespec_result canonical
;
13927 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13928 NULL
, 0, &canonical
, multiple_symbols_all
,
13931 /* We should get 0 or 1 resulting SALs. */
13932 gdb_assert (canonical
.lsals
.size () < 2);
13934 if (!canonical
.lsals
.empty ())
13936 const linespec_sals
&lsal
= canonical
.lsals
[0];
13937 return std::move (lsal
.sals
);
13942 /* Reset a breakpoint. */
13945 breakpoint_re_set_one (breakpoint
*b
)
13947 input_radix
= b
->input_radix
;
13948 set_language (b
->language
);
13950 b
->ops
->re_set (b
);
13953 /* Re-set breakpoint locations for the current program space.
13954 Locations bound to other program spaces are left untouched. */
13957 breakpoint_re_set (void)
13960 scoped_restore_current_language save_language
;
13961 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13962 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13964 /* breakpoint_re_set_one sets the current_language to the language
13965 of the breakpoint it is resetting (see prepare_re_set_context)
13966 before re-evaluating the breakpoint's location. This change can
13967 unfortunately get undone by accident if the language_mode is set
13968 to auto, and we either switch frames, or more likely in this context,
13969 we select the current frame.
13971 We prevent this by temporarily turning the language_mode to
13972 language_mode_manual. We restore it once all breakpoints
13973 have been reset. */
13974 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13975 language_mode
= language_mode_manual
;
13977 /* Note: we must not try to insert locations until after all
13978 breakpoints have been re-set. Otherwise, e.g., when re-setting
13979 breakpoint 1, we'd insert the locations of breakpoint 2, which
13980 hadn't been re-set yet, and thus may have stale locations. */
13982 for (breakpoint
*b
: all_breakpoints_safe ())
13986 breakpoint_re_set_one (b
);
13988 catch (const gdb_exception
&ex
)
13990 exception_fprintf (gdb_stderr
, ex
,
13991 "Error in re-setting breakpoint %d: ",
13996 jit_breakpoint_re_set ();
13999 create_overlay_event_breakpoint ();
14000 create_longjmp_master_breakpoint ();
14001 create_std_terminate_master_breakpoint ();
14002 create_exception_master_breakpoint ();
14004 /* Now we can insert. */
14005 update_global_location_list (UGLL_MAY_INSERT
);
14008 /* Reset the thread number of this breakpoint:
14010 - If the breakpoint is for all threads, leave it as-is.
14011 - Else, reset it to the current thread for inferior_ptid. */
14013 breakpoint_re_set_thread (struct breakpoint
*b
)
14015 if (b
->thread
!= -1)
14017 b
->thread
= inferior_thread ()->global_num
;
14019 /* We're being called after following a fork. The new fork is
14020 selected as current, and unless this was a vfork will have a
14021 different program space from the original thread. Reset that
14023 b
->loc
->pspace
= current_program_space
;
14027 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14028 If from_tty is nonzero, it prints a message to that effect,
14029 which ends with a period (no newline). */
14032 set_ignore_count (int bptnum
, int count
, int from_tty
)
14037 for (breakpoint
*b
: all_breakpoints ())
14038 if (b
->number
== bptnum
)
14040 if (is_tracepoint (b
))
14042 if (from_tty
&& count
!= 0)
14043 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14048 b
->ignore_count
= count
;
14052 printf_filtered (_("Will stop next time "
14053 "breakpoint %d is reached."),
14055 else if (count
== 1)
14056 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14059 printf_filtered (_("Will ignore next %d "
14060 "crossings of breakpoint %d."),
14063 gdb::observers::breakpoint_modified
.notify (b
);
14067 error (_("No breakpoint number %d."), bptnum
);
14070 /* Command to set ignore-count of breakpoint N to COUNT. */
14073 ignore_command (const char *args
, int from_tty
)
14075 const char *p
= args
;
14079 error_no_arg (_("a breakpoint number"));
14081 num
= get_number (&p
);
14083 error (_("bad breakpoint number: '%s'"), args
);
14085 error (_("Second argument (specified ignore-count) is missing."));
14087 set_ignore_count (num
,
14088 longest_to_int (value_as_long (parse_and_eval (p
))),
14091 printf_filtered ("\n");
14095 /* Call FUNCTION on each of the breakpoints with numbers in the range
14096 defined by BP_NUM_RANGE (an inclusive range). */
14099 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
14100 gdb::function_view
<void (breakpoint
*)> function
)
14102 if (bp_num_range
.first
== 0)
14104 warning (_("bad breakpoint number at or near '%d'"),
14105 bp_num_range
.first
);
14109 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
14111 bool match
= false;
14113 for (breakpoint
*b
: all_breakpoints_safe ())
14114 if (b
->number
== i
)
14121 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
14126 /* Call FUNCTION on each of the breakpoints whose numbers are given in
14130 map_breakpoint_numbers (const char *args
,
14131 gdb::function_view
<void (breakpoint
*)> function
)
14133 if (args
== NULL
|| *args
== '\0')
14134 error_no_arg (_("one or more breakpoint numbers"));
14136 number_or_range_parser
parser (args
);
14138 while (!parser
.finished ())
14140 int num
= parser
.get_number ();
14141 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
14145 /* Return the breakpoint location structure corresponding to the
14146 BP_NUM and LOC_NUM values. */
14148 static struct bp_location
*
14149 find_location_by_number (int bp_num
, int loc_num
)
14151 breakpoint
*b
= get_breakpoint (bp_num
);
14153 if (!b
|| b
->number
!= bp_num
)
14154 error (_("Bad breakpoint number '%d'"), bp_num
);
14157 error (_("Bad breakpoint location number '%d'"), loc_num
);
14160 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
14161 if (++n
== loc_num
)
14164 error (_("Bad breakpoint location number '%d'"), loc_num
);
14167 /* Modes of operation for extract_bp_num. */
14168 enum class extract_bp_kind
14170 /* Extracting a breakpoint number. */
14173 /* Extracting a location number. */
14177 /* Extract a breakpoint or location number (as determined by KIND)
14178 from the string starting at START. TRAILER is a character which
14179 can be found after the number. If you don't want a trailer, use
14180 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14181 string. This always returns a positive integer. */
14184 extract_bp_num (extract_bp_kind kind
, const char *start
,
14185 int trailer
, const char **end_out
= NULL
)
14187 const char *end
= start
;
14188 int num
= get_number_trailer (&end
, trailer
);
14190 error (kind
== extract_bp_kind::bp
14191 ? _("Negative breakpoint number '%.*s'")
14192 : _("Negative breakpoint location number '%.*s'"),
14193 int (end
- start
), start
);
14195 error (kind
== extract_bp_kind::bp
14196 ? _("Bad breakpoint number '%.*s'")
14197 : _("Bad breakpoint location number '%.*s'"),
14198 int (end
- start
), start
);
14200 if (end_out
!= NULL
)
14205 /* Extract a breakpoint or location range (as determined by KIND) in
14206 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14207 representing the (inclusive) range. The returned pair's elements
14208 are always positive integers. */
14210 static std::pair
<int, int>
14211 extract_bp_or_bp_range (extract_bp_kind kind
,
14212 const std::string
&arg
,
14213 std::string::size_type arg_offset
)
14215 std::pair
<int, int> range
;
14216 const char *bp_loc
= &arg
[arg_offset
];
14217 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14218 if (dash
!= std::string::npos
)
14220 /* bp_loc is a range (x-z). */
14221 if (arg
.length () == dash
+ 1)
14222 error (kind
== extract_bp_kind::bp
14223 ? _("Bad breakpoint number at or near: '%s'")
14224 : _("Bad breakpoint location number at or near: '%s'"),
14228 const char *start_first
= bp_loc
;
14229 const char *start_second
= &arg
[dash
+ 1];
14230 range
.first
= extract_bp_num (kind
, start_first
, '-');
14231 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14233 if (range
.first
> range
.second
)
14234 error (kind
== extract_bp_kind::bp
14235 ? _("Inverted breakpoint range at '%.*s'")
14236 : _("Inverted breakpoint location range at '%.*s'"),
14237 int (end
- start_first
), start_first
);
14241 /* bp_loc is a single value. */
14242 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14243 range
.second
= range
.first
;
14248 /* Extract the breakpoint/location range specified by ARG. Returns
14249 the breakpoint range in BP_NUM_RANGE, and the location range in
14252 ARG may be in any of the following forms:
14254 x where 'x' is a breakpoint number.
14255 x-y where 'x' and 'y' specify a breakpoint numbers range.
14256 x.y where 'x' is a breakpoint number and 'y' a location number.
14257 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14258 location number range.
14262 extract_bp_number_and_location (const std::string
&arg
,
14263 std::pair
<int, int> &bp_num_range
,
14264 std::pair
<int, int> &bp_loc_range
)
14266 std::string::size_type dot
= arg
.find ('.');
14268 if (dot
!= std::string::npos
)
14270 /* Handle 'x.y' and 'x.y-z' cases. */
14272 if (arg
.length () == dot
+ 1 || dot
== 0)
14273 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14276 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14277 bp_num_range
.second
= bp_num_range
.first
;
14279 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14284 /* Handle x and x-y cases. */
14286 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14287 bp_loc_range
.first
= 0;
14288 bp_loc_range
.second
= 0;
14292 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14293 specifies whether to enable or disable. */
14296 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14298 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14301 if (loc
->disabled_by_cond
&& enable
)
14302 error (_("Breakpoint %d's condition is invalid at location %d, "
14303 "cannot enable."), bp_num
, loc_num
);
14305 if (loc
->enabled
!= enable
)
14307 loc
->enabled
= enable
;
14308 mark_breakpoint_location_modified (loc
);
14310 if (target_supports_enable_disable_tracepoint ()
14311 && current_trace_status ()->running
&& loc
->owner
14312 && is_tracepoint (loc
->owner
))
14313 target_disable_tracepoint (loc
);
14315 update_global_location_list (UGLL_DONT_INSERT
);
14317 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14320 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14321 number of the breakpoint, and BP_LOC_RANGE specifies the
14322 (inclusive) range of location numbers of that breakpoint to
14323 enable/disable. ENABLE specifies whether to enable or disable the
14327 enable_disable_breakpoint_location_range (int bp_num
,
14328 std::pair
<int, int> &bp_loc_range
,
14331 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14332 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14335 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14336 If from_tty is nonzero, it prints a message to that effect,
14337 which ends with a period (no newline). */
14340 disable_breakpoint (struct breakpoint
*bpt
)
14342 /* Never disable a watchpoint scope breakpoint; we want to
14343 hit them when we leave scope so we can delete both the
14344 watchpoint and its scope breakpoint at that time. */
14345 if (bpt
->type
== bp_watchpoint_scope
)
14348 bpt
->enable_state
= bp_disabled
;
14350 /* Mark breakpoint locations modified. */
14351 mark_breakpoint_modified (bpt
);
14353 if (target_supports_enable_disable_tracepoint ()
14354 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14356 struct bp_location
*location
;
14358 for (location
= bpt
->loc
; location
; location
= location
->next
)
14359 target_disable_tracepoint (location
);
14362 update_global_location_list (UGLL_DONT_INSERT
);
14364 gdb::observers::breakpoint_modified
.notify (bpt
);
14367 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14368 specified in ARGS. ARGS may be in any of the formats handled by
14369 extract_bp_number_and_location. ENABLE specifies whether to enable
14370 or disable the breakpoints/locations. */
14373 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14377 for (breakpoint
*bpt
: all_breakpoints ())
14378 if (user_breakpoint_p (bpt
))
14381 enable_breakpoint (bpt
);
14383 disable_breakpoint (bpt
);
14388 std::string num
= extract_arg (&args
);
14390 while (!num
.empty ())
14392 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14394 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14396 if (bp_loc_range
.first
== bp_loc_range
.second
14397 && bp_loc_range
.first
== 0)
14399 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14400 map_breakpoint_number_range (bp_num_range
,
14402 ? enable_breakpoint
14403 : disable_breakpoint
);
14407 /* Handle breakpoint ids with formats 'x.y' or
14409 enable_disable_breakpoint_location_range
14410 (bp_num_range
.first
, bp_loc_range
, enable
);
14412 num
= extract_arg (&args
);
14417 /* The disable command disables the specified breakpoints/locations
14418 (or all defined breakpoints) so they're no longer effective in
14419 stopping the inferior. ARGS may be in any of the forms defined in
14420 extract_bp_number_and_location. */
14423 disable_command (const char *args
, int from_tty
)
14425 enable_disable_command (args
, from_tty
, false);
14429 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14432 int target_resources_ok
;
14434 if (bpt
->type
== bp_hardware_breakpoint
)
14437 i
= hw_breakpoint_used_count ();
14438 target_resources_ok
=
14439 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14441 if (target_resources_ok
== 0)
14442 error (_("No hardware breakpoint support in the target."));
14443 else if (target_resources_ok
< 0)
14444 error (_("Hardware breakpoints used exceeds limit."));
14447 if (is_watchpoint (bpt
))
14449 /* Initialize it just to avoid a GCC false warning. */
14450 enum enable_state orig_enable_state
= bp_disabled
;
14454 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14456 orig_enable_state
= bpt
->enable_state
;
14457 bpt
->enable_state
= bp_enabled
;
14458 update_watchpoint (w
, 1 /* reparse */);
14460 catch (const gdb_exception
&e
)
14462 bpt
->enable_state
= orig_enable_state
;
14463 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14469 bpt
->enable_state
= bp_enabled
;
14471 /* Mark breakpoint locations modified. */
14472 mark_breakpoint_modified (bpt
);
14474 if (target_supports_enable_disable_tracepoint ()
14475 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14477 struct bp_location
*location
;
14479 for (location
= bpt
->loc
; location
; location
= location
->next
)
14480 target_enable_tracepoint (location
);
14483 bpt
->disposition
= disposition
;
14484 bpt
->enable_count
= count
;
14485 update_global_location_list (UGLL_MAY_INSERT
);
14487 gdb::observers::breakpoint_modified
.notify (bpt
);
14492 enable_breakpoint (struct breakpoint
*bpt
)
14494 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14497 /* The enable command enables the specified breakpoints/locations (or
14498 all defined breakpoints) so they once again become (or continue to
14499 be) effective in stopping the inferior. ARGS may be in any of the
14500 forms defined in extract_bp_number_and_location. */
14503 enable_command (const char *args
, int from_tty
)
14505 enable_disable_command (args
, from_tty
, true);
14509 enable_once_command (const char *args
, int from_tty
)
14511 map_breakpoint_numbers
14512 (args
, [&] (breakpoint
*b
)
14514 iterate_over_related_breakpoints
14515 (b
, [&] (breakpoint
*bpt
)
14517 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14523 enable_count_command (const char *args
, int from_tty
)
14528 error_no_arg (_("hit count"));
14530 count
= get_number (&args
);
14532 map_breakpoint_numbers
14533 (args
, [&] (breakpoint
*b
)
14535 iterate_over_related_breakpoints
14536 (b
, [&] (breakpoint
*bpt
)
14538 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14544 enable_delete_command (const char *args
, int from_tty
)
14546 map_breakpoint_numbers
14547 (args
, [&] (breakpoint
*b
)
14549 iterate_over_related_breakpoints
14550 (b
, [&] (breakpoint
*bpt
)
14552 enable_breakpoint_disp (bpt
, disp_del
, 1);
14557 /* Invalidate last known value of any hardware watchpoint if
14558 the memory which that value represents has been written to by
14562 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14563 CORE_ADDR addr
, ssize_t len
,
14564 const bfd_byte
*data
)
14566 for (breakpoint
*bp
: all_breakpoints ())
14567 if (bp
->enable_state
== bp_enabled
14568 && bp
->type
== bp_hardware_watchpoint
)
14570 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14572 if (wp
->val_valid
&& wp
->val
!= nullptr)
14574 struct bp_location
*loc
;
14576 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14577 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14578 && loc
->address
+ loc
->length
> addr
14579 && addr
+ len
> loc
->address
)
14582 wp
->val_valid
= false;
14588 /* Create and insert a breakpoint for software single step. */
14591 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14592 const address_space
*aspace
,
14595 struct thread_info
*tp
= inferior_thread ();
14596 struct symtab_and_line sal
;
14597 CORE_ADDR pc
= next_pc
;
14599 if (tp
->control
.single_step_breakpoints
== NULL
)
14601 tp
->control
.single_step_breakpoints
14602 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14605 sal
= find_pc_line (pc
, 0);
14607 sal
.section
= find_pc_overlay (pc
);
14608 sal
.explicit_pc
= 1;
14609 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14611 update_global_location_list (UGLL_INSERT
);
14614 /* Insert single step breakpoints according to the current state. */
14617 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14619 struct regcache
*regcache
= get_current_regcache ();
14620 std::vector
<CORE_ADDR
> next_pcs
;
14622 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14624 if (!next_pcs
.empty ())
14626 struct frame_info
*frame
= get_current_frame ();
14627 const address_space
*aspace
= get_frame_address_space (frame
);
14629 for (CORE_ADDR pc
: next_pcs
)
14630 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14638 /* See breakpoint.h. */
14641 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14642 const address_space
*aspace
,
14645 struct bp_location
*loc
;
14647 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14649 && breakpoint_location_address_match (loc
, aspace
, pc
))
14655 /* Check whether a software single-step breakpoint is inserted at
14659 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14662 for (breakpoint
*bpt
: all_breakpoints ())
14664 if (bpt
->type
== bp_single_step
14665 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14671 /* Tracepoint-specific operations. */
14673 /* Set tracepoint count to NUM. */
14675 set_tracepoint_count (int num
)
14677 tracepoint_count
= num
;
14678 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14682 trace_command (const char *arg
, int from_tty
)
14684 event_location_up location
= string_to_event_location (&arg
,
14686 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
14687 (location
.get (), true /* is_tracepoint */);
14689 create_breakpoint (get_current_arch (),
14691 NULL
, 0, arg
, false, 1 /* parse arg */,
14693 bp_tracepoint
/* type_wanted */,
14694 0 /* Ignore count */,
14695 pending_break_support
,
14699 0 /* internal */, 0);
14703 ftrace_command (const char *arg
, int from_tty
)
14705 event_location_up location
= string_to_event_location (&arg
,
14707 create_breakpoint (get_current_arch (),
14709 NULL
, 0, arg
, false, 1 /* parse arg */,
14711 bp_fast_tracepoint
/* type_wanted */,
14712 0 /* Ignore count */,
14713 pending_break_support
,
14714 &tracepoint_breakpoint_ops
,
14717 0 /* internal */, 0);
14720 /* strace command implementation. Creates a static tracepoint. */
14723 strace_command (const char *arg
, int from_tty
)
14725 struct breakpoint_ops
*ops
;
14726 event_location_up location
;
14728 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14729 or with a normal static tracepoint. */
14730 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14732 ops
= &strace_marker_breakpoint_ops
;
14733 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14737 ops
= &tracepoint_breakpoint_ops
;
14738 location
= string_to_event_location (&arg
, current_language
);
14741 create_breakpoint (get_current_arch (),
14743 NULL
, 0, arg
, false, 1 /* parse arg */,
14745 bp_static_tracepoint
/* type_wanted */,
14746 0 /* Ignore count */,
14747 pending_break_support
,
14751 0 /* internal */, 0);
14754 /* Set up a fake reader function that gets command lines from a linked
14755 list that was acquired during tracepoint uploading. */
14757 static struct uploaded_tp
*this_utp
;
14758 static int next_cmd
;
14761 read_uploaded_action (void)
14763 char *rslt
= nullptr;
14765 if (next_cmd
< this_utp
->cmd_strings
.size ())
14767 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14774 /* Given information about a tracepoint as recorded on a target (which
14775 can be either a live system or a trace file), attempt to create an
14776 equivalent GDB tracepoint. This is not a reliable process, since
14777 the target does not necessarily have all the information used when
14778 the tracepoint was originally defined. */
14780 struct tracepoint
*
14781 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14783 const char *addr_str
;
14784 char small_buf
[100];
14785 struct tracepoint
*tp
;
14787 if (utp
->at_string
)
14788 addr_str
= utp
->at_string
.get ();
14791 /* In the absence of a source location, fall back to raw
14792 address. Since there is no way to confirm that the address
14793 means the same thing as when the trace was started, warn the
14795 warning (_("Uploaded tracepoint %d has no "
14796 "source location, using raw address"),
14798 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14799 addr_str
= small_buf
;
14802 /* There's not much we can do with a sequence of bytecodes. */
14803 if (utp
->cond
&& !utp
->cond_string
)
14804 warning (_("Uploaded tracepoint %d condition "
14805 "has no source form, ignoring it"),
14808 event_location_up location
= string_to_event_location (&addr_str
,
14810 if (!create_breakpoint (get_current_arch (),
14812 utp
->cond_string
.get (), -1, addr_str
,
14813 false /* force_condition */,
14814 0 /* parse cond/thread */,
14816 utp
->type
/* type_wanted */,
14817 0 /* Ignore count */,
14818 pending_break_support
,
14819 &tracepoint_breakpoint_ops
,
14821 utp
->enabled
/* enabled */,
14823 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14826 /* Get the tracepoint we just created. */
14827 tp
= get_tracepoint (tracepoint_count
);
14828 gdb_assert (tp
!= NULL
);
14832 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14835 trace_pass_command (small_buf
, 0);
14838 /* If we have uploaded versions of the original commands, set up a
14839 special-purpose "reader" function and call the usual command line
14840 reader, then pass the result to the breakpoint command-setting
14842 if (!utp
->cmd_strings
.empty ())
14844 counted_command_line cmd_list
;
14849 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14851 breakpoint_set_commands (tp
, std::move (cmd_list
));
14853 else if (!utp
->actions
.empty ()
14854 || !utp
->step_actions
.empty ())
14855 warning (_("Uploaded tracepoint %d actions "
14856 "have no source form, ignoring them"),
14859 /* Copy any status information that might be available. */
14860 tp
->hit_count
= utp
->hit_count
;
14861 tp
->traceframe_usage
= utp
->traceframe_usage
;
14866 /* Print information on tracepoint number TPNUM_EXP, or all if
14870 info_tracepoints_command (const char *args
, int from_tty
)
14872 struct ui_out
*uiout
= current_uiout
;
14875 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14877 if (num_printed
== 0)
14879 if (args
== NULL
|| *args
== '\0')
14880 uiout
->message ("No tracepoints.\n");
14882 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14885 default_collect_info ();
14888 /* The 'enable trace' command enables tracepoints.
14889 Not supported by all targets. */
14891 enable_trace_command (const char *args
, int from_tty
)
14893 enable_command (args
, from_tty
);
14896 /* The 'disable trace' command disables tracepoints.
14897 Not supported by all targets. */
14899 disable_trace_command (const char *args
, int from_tty
)
14901 disable_command (args
, from_tty
);
14904 /* Remove a tracepoint (or all if no argument). */
14906 delete_trace_command (const char *arg
, int from_tty
)
14912 int breaks_to_delete
= 0;
14915 /* Delete all breakpoints if no argument.
14916 Do not delete internal or call-dummy breakpoints, these
14917 have to be deleted with an explicit breakpoint number
14919 ALL_TRACEPOINTS (tp
)
14920 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
14922 breaks_to_delete
= 1;
14926 /* Ask user only if there are some breakpoints to delete. */
14928 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14930 for (breakpoint
*b
: all_breakpoints_safe ())
14931 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14932 delete_breakpoint (b
);
14936 map_breakpoint_numbers
14937 (arg
, [&] (breakpoint
*br
)
14939 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14943 /* Helper function for trace_pass_command. */
14946 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14948 tp
->pass_count
= count
;
14949 gdb::observers::breakpoint_modified
.notify (tp
);
14951 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14952 tp
->number
, count
);
14955 /* Set passcount for tracepoint.
14957 First command argument is passcount, second is tracepoint number.
14958 If tracepoint number omitted, apply to most recently defined.
14959 Also accepts special argument "all". */
14962 trace_pass_command (const char *args
, int from_tty
)
14964 struct tracepoint
*t1
;
14967 if (args
== 0 || *args
== 0)
14968 error (_("passcount command requires an "
14969 "argument (count + optional TP num)"));
14971 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14973 args
= skip_spaces (args
);
14974 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14976 struct breakpoint
*b
;
14978 args
+= 3; /* Skip special argument "all". */
14980 error (_("Junk at end of arguments."));
14982 ALL_TRACEPOINTS (b
)
14984 t1
= (struct tracepoint
*) b
;
14985 trace_pass_set_count (t1
, count
, from_tty
);
14988 else if (*args
== '\0')
14990 t1
= get_tracepoint_by_number (&args
, NULL
);
14992 trace_pass_set_count (t1
, count
, from_tty
);
14996 number_or_range_parser
parser (args
);
14997 while (!parser
.finished ())
14999 t1
= get_tracepoint_by_number (&args
, &parser
);
15001 trace_pass_set_count (t1
, count
, from_tty
);
15006 struct tracepoint
*
15007 get_tracepoint (int num
)
15009 struct breakpoint
*t
;
15011 ALL_TRACEPOINTS (t
)
15012 if (t
->number
== num
)
15013 return (struct tracepoint
*) t
;
15018 /* Find the tracepoint with the given target-side number (which may be
15019 different from the tracepoint number after disconnecting and
15022 struct tracepoint
*
15023 get_tracepoint_by_number_on_target (int num
)
15025 struct breakpoint
*b
;
15027 ALL_TRACEPOINTS (b
)
15029 struct tracepoint
*t
= (struct tracepoint
*) b
;
15031 if (t
->number_on_target
== num
)
15038 /* Utility: parse a tracepoint number and look it up in the list.
15039 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15040 If the argument is missing, the most recent tracepoint
15041 (tracepoint_count) is returned. */
15043 struct tracepoint
*
15044 get_tracepoint_by_number (const char **arg
,
15045 number_or_range_parser
*parser
)
15047 struct breakpoint
*t
;
15049 const char *instring
= arg
== NULL
? NULL
: *arg
;
15051 if (parser
!= NULL
)
15053 gdb_assert (!parser
->finished ());
15054 tpnum
= parser
->get_number ();
15056 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15057 tpnum
= tracepoint_count
;
15059 tpnum
= get_number (arg
);
15063 if (instring
&& *instring
)
15064 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15067 printf_filtered (_("No previous tracepoint\n"));
15071 ALL_TRACEPOINTS (t
)
15072 if (t
->number
== tpnum
)
15074 return (struct tracepoint
*) t
;
15077 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15082 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15084 if (b
->thread
!= -1)
15085 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15088 fprintf_unfiltered (fp
, " task %d", b
->task
);
15090 fprintf_unfiltered (fp
, "\n");
15093 /* Save information on user settable breakpoints (watchpoints, etc) to
15094 a new script file named FILENAME. If FILTER is non-NULL, call it
15095 on each breakpoint and only include the ones for which it returns
15099 save_breakpoints (const char *filename
, int from_tty
,
15100 bool (*filter
) (const struct breakpoint
*))
15103 int extra_trace_bits
= 0;
15105 if (filename
== 0 || *filename
== 0)
15106 error (_("Argument required (file name in which to save)"));
15108 /* See if we have anything to save. */
15109 for (breakpoint
*tp
: all_breakpoints ())
15111 /* Skip internal and momentary breakpoints. */
15112 if (!user_breakpoint_p (tp
))
15115 /* If we have a filter, only save the breakpoints it accepts. */
15116 if (filter
&& !filter (tp
))
15121 if (is_tracepoint (tp
))
15123 extra_trace_bits
= 1;
15125 /* We can stop searching. */
15132 warning (_("Nothing to save."));
15136 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15140 if (!fp
.open (expanded_filename
.get (), "w"))
15141 error (_("Unable to open file '%s' for saving (%s)"),
15142 expanded_filename
.get (), safe_strerror (errno
));
15144 if (extra_trace_bits
)
15145 save_trace_state_variables (&fp
);
15147 for (breakpoint
*tp
: all_breakpoints ())
15149 /* Skip internal and momentary breakpoints. */
15150 if (!user_breakpoint_p (tp
))
15153 /* If we have a filter, only save the breakpoints it accepts. */
15154 if (filter
&& !filter (tp
))
15157 tp
->ops
->print_recreate (tp
, &fp
);
15159 /* Note, we can't rely on tp->number for anything, as we can't
15160 assume the recreated breakpoint numbers will match. Use $bpnum
15163 if (tp
->cond_string
)
15164 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15166 if (tp
->ignore_count
)
15167 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15169 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15171 fp
.puts (" commands\n");
15173 current_uiout
->redirect (&fp
);
15176 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15178 catch (const gdb_exception
&ex
)
15180 current_uiout
->redirect (NULL
);
15184 current_uiout
->redirect (NULL
);
15185 fp
.puts (" end\n");
15188 if (tp
->enable_state
== bp_disabled
)
15189 fp
.puts ("disable $bpnum\n");
15191 /* If this is a multi-location breakpoint, check if the locations
15192 should be individually disabled. Watchpoint locations are
15193 special, and not user visible. */
15194 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15196 struct bp_location
*loc
;
15199 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15201 fp
.printf ("disable $bpnum.%d\n", n
);
15205 if (extra_trace_bits
&& *default_collect
)
15206 fp
.printf ("set default-collect %s\n", default_collect
);
15209 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15212 /* The `save breakpoints' command. */
15215 save_breakpoints_command (const char *args
, int from_tty
)
15217 save_breakpoints (args
, from_tty
, NULL
);
15220 /* The `save tracepoints' command. */
15223 save_tracepoints_command (const char *args
, int from_tty
)
15225 save_breakpoints (args
, from_tty
, is_tracepoint
);
15228 /* Create a vector of all tracepoints. */
15230 std::vector
<breakpoint
*>
15231 all_tracepoints (void)
15233 std::vector
<breakpoint
*> tp_vec
;
15234 struct breakpoint
*tp
;
15236 ALL_TRACEPOINTS (tp
)
15238 tp_vec
.push_back (tp
);
15245 /* This help string is used to consolidate all the help string for specifying
15246 locations used by several commands. */
15248 #define LOCATION_HELP_STRING \
15249 "Linespecs are colon-separated lists of location parameters, such as\n\
15250 source filename, function name, label name, and line number.\n\
15251 Example: To specify the start of a label named \"the_top\" in the\n\
15252 function \"fact\" in the file \"factorial.c\", use\n\
15253 \"factorial.c:fact:the_top\".\n\
15255 Address locations begin with \"*\" and specify an exact address in the\n\
15256 program. Example: To specify the fourth byte past the start function\n\
15257 \"main\", use \"*main + 4\".\n\
15259 Explicit locations are similar to linespecs but use an option/argument\n\
15260 syntax to specify location parameters.\n\
15261 Example: To specify the start of the label named \"the_top\" in the\n\
15262 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15263 -function fact -label the_top\".\n\
15265 By default, a specified function is matched against the program's\n\
15266 functions in all scopes. For C++, this means in all namespaces and\n\
15267 classes. For Ada, this means in all packages. E.g., in C++,\n\
15268 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15269 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15270 specified name as a complete fully-qualified name instead."
15272 /* This help string is used for the break, hbreak, tbreak and thbreak
15273 commands. It is defined as a macro to prevent duplication.
15274 COMMAND should be a string constant containing the name of the
15277 #define BREAK_ARGS_HELP(command) \
15278 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
15279 \t[-force-condition] [if CONDITION]\n\
15280 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15281 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15282 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15283 `-probe-dtrace' (for a DTrace probe).\n\
15284 LOCATION may be a linespec, address, or explicit location as described\n\
15287 With no LOCATION, uses current execution address of the selected\n\
15288 stack frame. This is useful for breaking on return to a stack frame.\n\
15290 THREADNUM is the number from \"info threads\".\n\
15291 CONDITION is a boolean expression.\n\
15293 With the \"-force-condition\" flag, the condition is defined even when\n\
15294 it is invalid for all current locations.\n\
15295 \n" LOCATION_HELP_STRING "\n\n\
15296 Multiple breakpoints at one place are permitted, and useful if their\n\
15297 conditions are different.\n\
15299 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15301 /* List of subcommands for "catch". */
15302 static struct cmd_list_element
*catch_cmdlist
;
15304 /* List of subcommands for "tcatch". */
15305 static struct cmd_list_element
*tcatch_cmdlist
;
15308 add_catch_command (const char *name
, const char *docstring
,
15309 cmd_const_sfunc_ftype
*sfunc
,
15310 completer_ftype
*completer
,
15311 void *user_data_catch
,
15312 void *user_data_tcatch
)
15314 struct cmd_list_element
*command
;
15316 command
= add_cmd (name
, class_breakpoint
, docstring
,
15318 set_cmd_sfunc (command
, sfunc
);
15319 set_cmd_context (command
, user_data_catch
);
15320 set_cmd_completer (command
, completer
);
15322 command
= add_cmd (name
, class_breakpoint
, docstring
,
15324 set_cmd_sfunc (command
, sfunc
);
15325 set_cmd_context (command
, user_data_tcatch
);
15326 set_cmd_completer (command
, completer
);
15329 struct breakpoint
*
15330 iterate_over_breakpoints (gdb::function_view
<bool (breakpoint
*)> callback
)
15332 for (breakpoint
*b
: all_breakpoints_safe ())
15339 /* Zero if any of the breakpoint's locations could be a location where
15340 functions have been inlined, nonzero otherwise. */
15343 is_non_inline_function (struct breakpoint
*b
)
15345 /* The shared library event breakpoint is set on the address of a
15346 non-inline function. */
15347 if (b
->type
== bp_shlib_event
)
15353 /* Nonzero if the specified PC cannot be a location where functions
15354 have been inlined. */
15357 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15358 const struct target_waitstatus
*ws
)
15360 struct bp_location
*bl
;
15362 for (breakpoint
*b
: all_breakpoints ())
15364 if (!is_non_inline_function (b
))
15367 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15369 if (!bl
->shlib_disabled
15370 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15378 /* Remove any references to OBJFILE which is going to be freed. */
15381 breakpoint_free_objfile (struct objfile
*objfile
)
15383 struct bp_location
**locp
, *loc
;
15385 ALL_BP_LOCATIONS (loc
, locp
)
15386 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15387 loc
->symtab
= NULL
;
15391 initialize_breakpoint_ops (void)
15393 static int initialized
= 0;
15395 struct breakpoint_ops
*ops
;
15401 /* The breakpoint_ops structure to be inherit by all kinds of
15402 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15403 internal and momentary breakpoints, etc.). */
15404 ops
= &bkpt_base_breakpoint_ops
;
15405 *ops
= base_breakpoint_ops
;
15406 ops
->re_set
= bkpt_re_set
;
15407 ops
->insert_location
= bkpt_insert_location
;
15408 ops
->remove_location
= bkpt_remove_location
;
15409 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15410 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15411 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15412 ops
->decode_location
= bkpt_decode_location
;
15414 /* The breakpoint_ops structure to be used in regular breakpoints. */
15415 ops
= &bkpt_breakpoint_ops
;
15416 *ops
= bkpt_base_breakpoint_ops
;
15417 ops
->re_set
= bkpt_re_set
;
15418 ops
->resources_needed
= bkpt_resources_needed
;
15419 ops
->print_it
= bkpt_print_it
;
15420 ops
->print_mention
= bkpt_print_mention
;
15421 ops
->print_recreate
= bkpt_print_recreate
;
15423 /* Ranged breakpoints. */
15424 ops
= &ranged_breakpoint_ops
;
15425 *ops
= bkpt_breakpoint_ops
;
15426 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15427 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15428 ops
->print_it
= print_it_ranged_breakpoint
;
15429 ops
->print_one
= print_one_ranged_breakpoint
;
15430 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15431 ops
->print_mention
= print_mention_ranged_breakpoint
;
15432 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15434 /* Internal breakpoints. */
15435 ops
= &internal_breakpoint_ops
;
15436 *ops
= bkpt_base_breakpoint_ops
;
15437 ops
->re_set
= internal_bkpt_re_set
;
15438 ops
->check_status
= internal_bkpt_check_status
;
15439 ops
->print_it
= internal_bkpt_print_it
;
15440 ops
->print_mention
= internal_bkpt_print_mention
;
15442 /* Momentary breakpoints. */
15443 ops
= &momentary_breakpoint_ops
;
15444 *ops
= bkpt_base_breakpoint_ops
;
15445 ops
->re_set
= momentary_bkpt_re_set
;
15446 ops
->check_status
= momentary_bkpt_check_status
;
15447 ops
->print_it
= momentary_bkpt_print_it
;
15448 ops
->print_mention
= momentary_bkpt_print_mention
;
15450 /* Probe breakpoints. */
15451 ops
= &bkpt_probe_breakpoint_ops
;
15452 *ops
= bkpt_breakpoint_ops
;
15453 ops
->insert_location
= bkpt_probe_insert_location
;
15454 ops
->remove_location
= bkpt_probe_remove_location
;
15455 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15456 ops
->decode_location
= bkpt_probe_decode_location
;
15459 ops
= &watchpoint_breakpoint_ops
;
15460 *ops
= base_breakpoint_ops
;
15461 ops
->re_set
= re_set_watchpoint
;
15462 ops
->insert_location
= insert_watchpoint
;
15463 ops
->remove_location
= remove_watchpoint
;
15464 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15465 ops
->check_status
= check_status_watchpoint
;
15466 ops
->resources_needed
= resources_needed_watchpoint
;
15467 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15468 ops
->print_it
= print_it_watchpoint
;
15469 ops
->print_mention
= print_mention_watchpoint
;
15470 ops
->print_recreate
= print_recreate_watchpoint
;
15471 ops
->explains_signal
= explains_signal_watchpoint
;
15473 /* Masked watchpoints. */
15474 ops
= &masked_watchpoint_breakpoint_ops
;
15475 *ops
= watchpoint_breakpoint_ops
;
15476 ops
->insert_location
= insert_masked_watchpoint
;
15477 ops
->remove_location
= remove_masked_watchpoint
;
15478 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15479 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15480 ops
->print_it
= print_it_masked_watchpoint
;
15481 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15482 ops
->print_mention
= print_mention_masked_watchpoint
;
15483 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15486 ops
= &tracepoint_breakpoint_ops
;
15487 *ops
= base_breakpoint_ops
;
15488 ops
->re_set
= tracepoint_re_set
;
15489 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15490 ops
->print_one_detail
= tracepoint_print_one_detail
;
15491 ops
->print_mention
= tracepoint_print_mention
;
15492 ops
->print_recreate
= tracepoint_print_recreate
;
15493 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15494 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15495 ops
->decode_location
= tracepoint_decode_location
;
15497 /* Probe tracepoints. */
15498 ops
= &tracepoint_probe_breakpoint_ops
;
15499 *ops
= tracepoint_breakpoint_ops
;
15500 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15501 ops
->decode_location
= tracepoint_probe_decode_location
;
15503 /* Static tracepoints with marker (`-m'). */
15504 ops
= &strace_marker_breakpoint_ops
;
15505 *ops
= tracepoint_breakpoint_ops
;
15506 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15507 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15508 ops
->decode_location
= strace_marker_decode_location
;
15510 /* Fork catchpoints. */
15511 ops
= &catch_fork_breakpoint_ops
;
15512 *ops
= base_breakpoint_ops
;
15513 ops
->insert_location
= insert_catch_fork
;
15514 ops
->remove_location
= remove_catch_fork
;
15515 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15516 ops
->print_it
= print_it_catch_fork
;
15517 ops
->print_one
= print_one_catch_fork
;
15518 ops
->print_mention
= print_mention_catch_fork
;
15519 ops
->print_recreate
= print_recreate_catch_fork
;
15521 /* Vfork catchpoints. */
15522 ops
= &catch_vfork_breakpoint_ops
;
15523 *ops
= base_breakpoint_ops
;
15524 ops
->insert_location
= insert_catch_vfork
;
15525 ops
->remove_location
= remove_catch_vfork
;
15526 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15527 ops
->print_it
= print_it_catch_vfork
;
15528 ops
->print_one
= print_one_catch_vfork
;
15529 ops
->print_mention
= print_mention_catch_vfork
;
15530 ops
->print_recreate
= print_recreate_catch_vfork
;
15532 /* Exec catchpoints. */
15533 ops
= &catch_exec_breakpoint_ops
;
15534 *ops
= base_breakpoint_ops
;
15535 ops
->insert_location
= insert_catch_exec
;
15536 ops
->remove_location
= remove_catch_exec
;
15537 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15538 ops
->print_it
= print_it_catch_exec
;
15539 ops
->print_one
= print_one_catch_exec
;
15540 ops
->print_mention
= print_mention_catch_exec
;
15541 ops
->print_recreate
= print_recreate_catch_exec
;
15543 /* Solib-related catchpoints. */
15544 ops
= &catch_solib_breakpoint_ops
;
15545 *ops
= base_breakpoint_ops
;
15546 ops
->insert_location
= insert_catch_solib
;
15547 ops
->remove_location
= remove_catch_solib
;
15548 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15549 ops
->check_status
= check_status_catch_solib
;
15550 ops
->print_it
= print_it_catch_solib
;
15551 ops
->print_one
= print_one_catch_solib
;
15552 ops
->print_mention
= print_mention_catch_solib
;
15553 ops
->print_recreate
= print_recreate_catch_solib
;
15555 ops
= &dprintf_breakpoint_ops
;
15556 *ops
= bkpt_base_breakpoint_ops
;
15557 ops
->re_set
= dprintf_re_set
;
15558 ops
->resources_needed
= bkpt_resources_needed
;
15559 ops
->print_it
= bkpt_print_it
;
15560 ops
->print_mention
= bkpt_print_mention
;
15561 ops
->print_recreate
= dprintf_print_recreate
;
15562 ops
->after_condition_true
= dprintf_after_condition_true
;
15563 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15566 /* Chain containing all defined "enable breakpoint" subcommands. */
15568 static struct cmd_list_element
*enablebreaklist
= NULL
;
15570 /* See breakpoint.h. */
15572 cmd_list_element
*commands_cmd_element
= nullptr;
15574 void _initialize_breakpoint ();
15576 _initialize_breakpoint ()
15578 struct cmd_list_element
*c
;
15580 initialize_breakpoint_ops ();
15582 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
15584 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
15586 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
15589 breakpoint_chain
= 0;
15590 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15591 before a breakpoint is set. */
15592 breakpoint_count
= 0;
15594 tracepoint_count
= 0;
15596 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15597 Set ignore-count of breakpoint number N to COUNT.\n\
15598 Usage is `ignore N COUNT'."));
15600 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15601 commands_command
, _("\
15602 Set commands to be executed when the given breakpoints are hit.\n\
15603 Give a space-separated breakpoint list as argument after \"commands\".\n\
15604 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15606 With no argument, the targeted breakpoint is the last one set.\n\
15607 The commands themselves follow starting on the next line.\n\
15608 Type a line containing \"end\" to indicate the end of them.\n\
15609 Give \"silent\" as the first line to make the breakpoint silent;\n\
15610 then no output is printed when it is hit, except what the commands print."));
15612 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
15613 static std::string condition_command_help
15614 = gdb::option::build_help (_("\
15615 Specify breakpoint number N to break only if COND is true.\n\
15616 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
15617 is an expression to be evaluated whenever breakpoint N is reached.\n\
15620 %OPTIONS%"), cc_opts
);
15622 c
= add_com ("condition", class_breakpoint
, condition_command
,
15623 condition_command_help
.c_str ());
15624 set_cmd_completer_handle_brkchars (c
, condition_completer
);
15626 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15627 Set a temporary breakpoint.\n\
15628 Like \"break\" except the breakpoint is only temporary,\n\
15629 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15630 by using \"enable delete\" on the breakpoint number.\n\
15632 BREAK_ARGS_HELP ("tbreak")));
15633 set_cmd_completer (c
, location_completer
);
15635 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15636 Set a hardware assisted breakpoint.\n\
15637 Like \"break\" except the breakpoint requires hardware support,\n\
15638 some target hardware may not have this support.\n\
15640 BREAK_ARGS_HELP ("hbreak")));
15641 set_cmd_completer (c
, location_completer
);
15643 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15644 Set a temporary hardware assisted breakpoint.\n\
15645 Like \"hbreak\" except the breakpoint is only temporary,\n\
15646 so it will be deleted when hit.\n\
15648 BREAK_ARGS_HELP ("thbreak")));
15649 set_cmd_completer (c
, location_completer
);
15651 cmd_list_element
*enable_cmd
15652 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15653 Enable all or some breakpoints.\n\
15654 Usage: enable [BREAKPOINTNUM]...\n\
15655 Give breakpoint numbers (separated by spaces) as arguments.\n\
15656 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15657 This is used to cancel the effect of the \"disable\" command.\n\
15658 With a subcommand you can enable temporarily."),
15659 &enablelist
, 1, &cmdlist
);
15661 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
15663 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15664 Enable all or some breakpoints.\n\
15665 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15666 Give breakpoint numbers (separated by spaces) as arguments.\n\
15667 This is used to cancel the effect of the \"disable\" command.\n\
15668 May be abbreviated to simply \"enable\"."),
15669 &enablebreaklist
, 1, &enablelist
);
15671 add_cmd ("once", no_class
, enable_once_command
, _("\
15672 Enable some breakpoints for one hit.\n\
15673 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15674 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15677 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15678 Enable some breakpoints and delete when hit.\n\
15679 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15680 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15683 add_cmd ("count", no_class
, enable_count_command
, _("\
15684 Enable some breakpoints for COUNT hits.\n\
15685 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15686 If a breakpoint is hit while enabled in this fashion,\n\
15687 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15690 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15691 Enable some breakpoints and delete when hit.\n\
15692 Usage: enable delete BREAKPOINTNUM...\n\
15693 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15696 add_cmd ("once", no_class
, enable_once_command
, _("\
15697 Enable some breakpoints for one hit.\n\
15698 Usage: enable once BREAKPOINTNUM...\n\
15699 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15702 add_cmd ("count", no_class
, enable_count_command
, _("\
15703 Enable some breakpoints for COUNT hits.\n\
15704 Usage: enable count COUNT BREAKPOINTNUM...\n\
15705 If a breakpoint is hit while enabled in this fashion,\n\
15706 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15709 cmd_list_element
*disable_cmd
15710 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15711 Disable all or some breakpoints.\n\
15712 Usage: disable [BREAKPOINTNUM]...\n\
15713 Arguments are breakpoint numbers with spaces in between.\n\
15714 To disable all breakpoints, give no argument.\n\
15715 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15716 &disablelist
, 1, &cmdlist
);
15717 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
15718 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
15720 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
15721 Disable all or some breakpoints.\n\
15722 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15723 Arguments are breakpoint numbers with spaces in between.\n\
15724 To disable all breakpoints, give no argument.\n\
15725 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15726 This command may be abbreviated \"disable\"."),
15729 cmd_list_element
*delete_cmd
15730 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15731 Delete all or some breakpoints.\n\
15732 Usage: delete [BREAKPOINTNUM]...\n\
15733 Arguments are breakpoint numbers with spaces in between.\n\
15734 To delete all breakpoints, give no argument.\n\
15736 Also a prefix command for deletion of other GDB objects."),
15737 &deletelist
, 1, &cmdlist
);
15738 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
15739 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
15741 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
15742 Delete all or some breakpoints or auto-display expressions.\n\
15743 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15744 Arguments are breakpoint numbers with spaces in between.\n\
15745 To delete all breakpoints, give no argument.\n\
15746 This command may be abbreviated \"delete\"."),
15749 cmd_list_element
*clear_cmd
15750 = add_com ("clear", class_breakpoint
, clear_command
, _("\
15751 Clear breakpoint at specified location.\n\
15752 Argument may be a linespec, explicit, or address location as described below.\n\
15754 With no argument, clears all breakpoints in the line that the selected frame\n\
15755 is executing in.\n"
15756 "\n" LOCATION_HELP_STRING
"\n\n\
15757 See also the \"delete\" command which clears breakpoints by number."));
15758 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
15760 cmd_list_element
*break_cmd
15761 = add_com ("break", class_breakpoint
, break_command
, _("\
15762 Set breakpoint at specified location.\n"
15763 BREAK_ARGS_HELP ("break")));
15764 set_cmd_completer (break_cmd
, location_completer
);
15766 add_com_alias ("b", break_cmd
, class_run
, 1);
15767 add_com_alias ("br", break_cmd
, class_run
, 1);
15768 add_com_alias ("bre", break_cmd
, class_run
, 1);
15769 add_com_alias ("brea", break_cmd
, class_run
, 1);
15773 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15774 Break in function/address or break at a line in the current file."),
15775 &stoplist
, 1, &cmdlist
);
15776 add_cmd ("in", class_breakpoint
, stopin_command
,
15777 _("Break in function or address."), &stoplist
);
15778 add_cmd ("at", class_breakpoint
, stopat_command
,
15779 _("Break at a line in the current file."), &stoplist
);
15780 add_com ("status", class_info
, info_breakpoints_command
, _("\
15781 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15782 The \"Type\" column indicates one of:\n\
15783 \tbreakpoint - normal breakpoint\n\
15784 \twatchpoint - watchpoint\n\
15785 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15786 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15787 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15788 address and file/line number respectively.\n\
15790 Convenience variable \"$_\" and default examine address for \"x\"\n\
15791 are set to the address of the last breakpoint listed unless the command\n\
15792 is prefixed with \"server \".\n\n\
15793 Convenience variable \"$bpnum\" contains the number of the last\n\
15794 breakpoint set."));
15797 cmd_list_element
*info_breakpoints_cmd
15798 = add_info ("breakpoints", info_breakpoints_command
, _("\
15799 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15800 The \"Type\" column indicates one of:\n\
15801 \tbreakpoint - normal breakpoint\n\
15802 \twatchpoint - watchpoint\n\
15803 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15804 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15805 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15806 address and file/line number respectively.\n\
15808 Convenience variable \"$_\" and default examine address for \"x\"\n\
15809 are set to the address of the last breakpoint listed unless the command\n\
15810 is prefixed with \"server \".\n\n\
15811 Convenience variable \"$bpnum\" contains the number of the last\n\
15812 breakpoint set."));
15814 add_info_alias ("b", info_breakpoints_cmd
, 1);
15816 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15817 Status of all breakpoints, or breakpoint number NUMBER.\n\
15818 The \"Type\" column indicates one of:\n\
15819 \tbreakpoint - normal breakpoint\n\
15820 \twatchpoint - watchpoint\n\
15821 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15822 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15823 \tuntil - internal breakpoint used by the \"until\" command\n\
15824 \tfinish - internal breakpoint used by the \"finish\" command\n\
15825 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15826 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15827 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15828 address and file/line number respectively.\n\
15830 Convenience variable \"$_\" and default examine address for \"x\"\n\
15831 are set to the address of the last breakpoint listed unless the command\n\
15832 is prefixed with \"server \".\n\n\
15833 Convenience variable \"$bpnum\" contains the number of the last\n\
15835 &maintenanceinfolist
);
15837 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
15838 Set catchpoints to catch events."),
15840 0/*allow-unknown*/, &cmdlist
);
15842 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
15843 Set temporary catchpoints to catch events."),
15845 0/*allow-unknown*/, &cmdlist
);
15847 add_catch_command ("fork", _("Catch calls to fork."),
15848 catch_fork_command_1
,
15850 (void *) (uintptr_t) catch_fork_permanent
,
15851 (void *) (uintptr_t) catch_fork_temporary
);
15852 add_catch_command ("vfork", _("Catch calls to vfork."),
15853 catch_fork_command_1
,
15855 (void *) (uintptr_t) catch_vfork_permanent
,
15856 (void *) (uintptr_t) catch_vfork_temporary
);
15857 add_catch_command ("exec", _("Catch calls to exec."),
15858 catch_exec_command_1
,
15862 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15863 Usage: catch load [REGEX]\n\
15864 If REGEX is given, only stop for libraries matching the regular expression."),
15865 catch_load_command_1
,
15869 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15870 Usage: catch unload [REGEX]\n\
15871 If REGEX is given, only stop for libraries matching the regular expression."),
15872 catch_unload_command_1
,
15877 const auto opts
= make_watch_options_def_group (nullptr);
15879 static const std::string watch_help
= gdb::option::build_help (_("\
15880 Set a watchpoint for EXPRESSION.\n\
15881 Usage: watch [-location] EXPRESSION\n\
15886 A watchpoint stops execution of your program whenever the value of\n\
15887 an expression changes."), opts
);
15888 c
= add_com ("watch", class_breakpoint
, watch_command
,
15889 watch_help
.c_str ());
15890 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15892 static const std::string rwatch_help
= gdb::option::build_help (_("\
15893 Set a read watchpoint for EXPRESSION.\n\
15894 Usage: rwatch [-location] EXPRESSION\n\
15899 A read watchpoint stops execution of your program whenever the value of\n\
15900 an expression is read."), opts
);
15901 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
15902 rwatch_help
.c_str ());
15903 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15905 static const std::string awatch_help
= gdb::option::build_help (_("\
15906 Set an access watchpoint for EXPRESSION.\n\
15907 Usage: awatch [-location] EXPRESSION\n\
15912 An access watchpoint stops execution of your program whenever the value\n\
15913 of an expression is either read or written."), opts
);
15914 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
15915 awatch_help
.c_str ());
15916 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15918 add_info ("watchpoints", info_watchpoints_command
, _("\
15919 Status of specified watchpoints (all watchpoints if no argument)."));
15921 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15922 respond to changes - contrary to the description. */
15923 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15924 &can_use_hw_watchpoints
, _("\
15925 Set debugger's willingness to use watchpoint hardware."), _("\
15926 Show debugger's willingness to use watchpoint hardware."), _("\
15927 If zero, gdb will not use hardware for new watchpoints, even if\n\
15928 such is available. (However, any hardware watchpoints that were\n\
15929 created before setting this to nonzero, will continue to use watchpoint\n\
15932 show_can_use_hw_watchpoints
,
15933 &setlist
, &showlist
);
15935 can_use_hw_watchpoints
= 1;
15937 /* Tracepoint manipulation commands. */
15939 cmd_list_element
*trace_cmd
15940 = add_com ("trace", class_breakpoint
, trace_command
, _("\
15941 Set a tracepoint at specified location.\n\
15943 BREAK_ARGS_HELP ("trace") "\n\
15944 Do \"help tracepoints\" for info on other tracepoint commands."));
15945 set_cmd_completer (trace_cmd
, location_completer
);
15947 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
15948 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
15949 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
15950 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
15952 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15953 Set a fast tracepoint at specified location.\n\
15955 BREAK_ARGS_HELP ("ftrace") "\n\
15956 Do \"help tracepoints\" for info on other tracepoint commands."));
15957 set_cmd_completer (c
, location_completer
);
15959 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15960 Set a static tracepoint at location or marker.\n\
15962 strace [LOCATION] [if CONDITION]\n\
15963 LOCATION may be a linespec, explicit, or address location (described below) \n\
15964 or -m MARKER_ID.\n\n\
15965 If a marker id is specified, probe the marker with that name. With\n\
15966 no LOCATION, uses current execution address of the selected stack frame.\n\
15967 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15968 This collects arbitrary user data passed in the probe point call to the\n\
15969 tracing library. You can inspect it when analyzing the trace buffer,\n\
15970 by printing the $_sdata variable like any other convenience variable.\n\
15972 CONDITION is a boolean expression.\n\
15973 \n" LOCATION_HELP_STRING
"\n\n\
15974 Multiple tracepoints at one place are permitted, and useful if their\n\
15975 conditions are different.\n\
15977 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15978 Do \"help tracepoints\" for info on other tracepoint commands."));
15979 set_cmd_completer (c
, location_completer
);
15981 cmd_list_element
*info_tracepoints_cmd
15982 = add_info ("tracepoints", info_tracepoints_command
, _("\
15983 Status of specified tracepoints (all tracepoints if no argument).\n\
15984 Convenience variable \"$tpnum\" contains the number of the\n\
15985 last tracepoint set."));
15987 add_info_alias ("tp", info_tracepoints_cmd
, 1);
15989 cmd_list_element
*delete_tracepoints_cmd
15990 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15991 Delete specified tracepoints.\n\
15992 Arguments are tracepoint numbers, separated by spaces.\n\
15993 No argument means delete all tracepoints."),
15995 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
15997 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15998 Disable specified tracepoints.\n\
15999 Arguments are tracepoint numbers, separated by spaces.\n\
16000 No argument means disable all tracepoints."),
16002 deprecate_cmd (c
, "disable");
16004 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16005 Enable specified tracepoints.\n\
16006 Arguments are tracepoint numbers, separated by spaces.\n\
16007 No argument means enable all tracepoints."),
16009 deprecate_cmd (c
, "enable");
16011 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16012 Set the passcount for a tracepoint.\n\
16013 The trace will end when the tracepoint has been passed 'count' times.\n\
16014 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16015 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16017 add_basic_prefix_cmd ("save", class_breakpoint
,
16018 _("Save breakpoint definitions as a script."),
16020 0/*allow-unknown*/, &cmdlist
);
16022 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16023 Save current breakpoint definitions as a script.\n\
16024 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16025 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16026 session to restore them."),
16028 set_cmd_completer (c
, filename_completer
);
16030 cmd_list_element
*save_tracepoints_cmd
16031 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16032 Save current tracepoint definitions as a script.\n\
16033 Use the 'source' command in another debug session to restore them."),
16035 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
16037 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
16038 deprecate_cmd (c
, "save tracepoints");
16040 add_basic_prefix_cmd ("breakpoint", class_maintenance
, _("\
16041 Breakpoint specific settings.\n\
16042 Configure various breakpoint-specific variables such as\n\
16043 pending breakpoint behavior."),
16044 &breakpoint_set_cmdlist
,
16045 0/*allow-unknown*/, &setlist
);
16046 add_show_prefix_cmd ("breakpoint", class_maintenance
, _("\
16047 Breakpoint specific settings.\n\
16048 Configure various breakpoint-specific variables such as\n\
16049 pending breakpoint behavior."),
16050 &breakpoint_show_cmdlist
,
16051 0/*allow-unknown*/, &showlist
);
16053 add_setshow_auto_boolean_cmd ("pending", no_class
,
16054 &pending_break_support
, _("\
16055 Set debugger's behavior regarding pending breakpoints."), _("\
16056 Show debugger's behavior regarding pending breakpoints."), _("\
16057 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16058 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16059 an error. If auto, an unrecognized breakpoint location results in a\n\
16060 user-query to see if a pending breakpoint should be created."),
16062 show_pending_break_support
,
16063 &breakpoint_set_cmdlist
,
16064 &breakpoint_show_cmdlist
);
16066 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16068 add_setshow_boolean_cmd ("auto-hw", no_class
,
16069 &automatic_hardware_breakpoints
, _("\
16070 Set automatic usage of hardware breakpoints."), _("\
16071 Show automatic usage of hardware breakpoints."), _("\
16072 If set, the debugger will automatically use hardware breakpoints for\n\
16073 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16074 a warning will be emitted for such breakpoints."),
16076 show_automatic_hardware_breakpoints
,
16077 &breakpoint_set_cmdlist
,
16078 &breakpoint_show_cmdlist
);
16080 add_setshow_boolean_cmd ("always-inserted", class_support
,
16081 &always_inserted_mode
, _("\
16082 Set mode for inserting breakpoints."), _("\
16083 Show mode for inserting breakpoints."), _("\
16084 When this mode is on, breakpoints are inserted immediately as soon as\n\
16085 they're created, kept inserted even when execution stops, and removed\n\
16086 only when the user deletes them. When this mode is off (the default),\n\
16087 breakpoints are inserted only when execution continues, and removed\n\
16088 when execution stops."),
16090 &show_always_inserted_mode
,
16091 &breakpoint_set_cmdlist
,
16092 &breakpoint_show_cmdlist
);
16094 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16095 condition_evaluation_enums
,
16096 &condition_evaluation_mode_1
, _("\
16097 Set mode of breakpoint condition evaluation."), _("\
16098 Show mode of breakpoint condition evaluation."), _("\
16099 When this is set to \"host\", breakpoint conditions will be\n\
16100 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16101 breakpoint conditions will be downloaded to the target (if the target\n\
16102 supports such feature) and conditions will be evaluated on the target's side.\n\
16103 If this is set to \"auto\" (default), this will be automatically set to\n\
16104 \"target\" if it supports condition evaluation, otherwise it will\n\
16105 be set to \"host\"."),
16106 &set_condition_evaluation_mode
,
16107 &show_condition_evaluation_mode
,
16108 &breakpoint_set_cmdlist
,
16109 &breakpoint_show_cmdlist
);
16111 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16112 Set a breakpoint for an address range.\n\
16113 break-range START-LOCATION, END-LOCATION\n\
16114 where START-LOCATION and END-LOCATION can be one of the following:\n\
16115 LINENUM, for that line in the current file,\n\
16116 FILE:LINENUM, for that line in that file,\n\
16117 +OFFSET, for that number of lines after the current line\n\
16118 or the start of the range\n\
16119 FUNCTION, for the first line in that function,\n\
16120 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16121 *ADDRESS, for the instruction at that address.\n\
16123 The breakpoint will stop execution of the inferior whenever it executes\n\
16124 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16125 range (including START-LOCATION and END-LOCATION)."));
16127 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16128 Set a dynamic printf at specified location.\n\
16129 dprintf location,format string,arg1,arg2,...\n\
16130 location may be a linespec, explicit, or address location.\n"
16131 "\n" LOCATION_HELP_STRING
));
16132 set_cmd_completer (c
, location_completer
);
16134 add_setshow_enum_cmd ("dprintf-style", class_support
,
16135 dprintf_style_enums
, &dprintf_style
, _("\
16136 Set the style of usage for dynamic printf."), _("\
16137 Show the style of usage for dynamic printf."), _("\
16138 This setting chooses how GDB will do a dynamic printf.\n\
16139 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16140 console, as with the \"printf\" command.\n\
16141 If the value is \"call\", the print is done by calling a function in your\n\
16142 program; by default printf(), but you can choose a different function or\n\
16143 output stream by setting dprintf-function and dprintf-channel."),
16144 update_dprintf_commands
, NULL
,
16145 &setlist
, &showlist
);
16147 dprintf_function
= xstrdup ("printf");
16148 add_setshow_string_cmd ("dprintf-function", class_support
,
16149 &dprintf_function
, _("\
16150 Set the function to use for dynamic printf."), _("\
16151 Show the function to use for dynamic printf."), NULL
,
16152 update_dprintf_commands
, NULL
,
16153 &setlist
, &showlist
);
16155 dprintf_channel
= xstrdup ("");
16156 add_setshow_string_cmd ("dprintf-channel", class_support
,
16157 &dprintf_channel
, _("\
16158 Set the channel to use for dynamic printf."), _("\
16159 Show the channel to use for dynamic printf."), NULL
,
16160 update_dprintf_commands
, NULL
,
16161 &setlist
, &showlist
);
16163 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16164 &disconnected_dprintf
, _("\
16165 Set whether dprintf continues after GDB disconnects."), _("\
16166 Show whether dprintf continues after GDB disconnects."), _("\
16167 Use this to let dprintf commands continue to hit and produce output\n\
16168 even if GDB disconnects or detaches from the target."),
16171 &setlist
, &showlist
);
16173 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16174 Target agent only formatted printing, like the C \"printf\" function.\n\
16175 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
16176 This supports most C printf format specifications, like %s, %d, etc.\n\
16177 This is useful for formatted output in user-defined commands."));
16179 automatic_hardware_breakpoints
= true;
16181 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
16183 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,