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 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
545 static struct bp_location
**bp_locations
;
547 /* Number of elements of BP_LOCATIONS. */
549 static unsigned bp_locations_count
;
551 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
552 ADDRESS for the current elements of BP_LOCATIONS which get a valid
553 result from bp_location_has_shadow. You can use it for roughly
554 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
555 an address you need to read. */
557 static CORE_ADDR bp_locations_placed_address_before_address_max
;
559 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
560 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
561 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
562 You can use it for roughly limiting the subrange of BP_LOCATIONS to
563 scan for shadow bytes for an address you need to read. */
565 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
567 /* The locations that no longer correspond to any breakpoint, unlinked
568 from the bp_locations array, but for which a hit may still be
569 reported by a target. */
570 static std::vector
<bp_location
*> moribund_locations
;
572 /* Number of last breakpoint made. */
574 static int breakpoint_count
;
576 /* The value of `breakpoint_count' before the last command that
577 created breakpoints. If the last (break-like) command created more
578 than one breakpoint, then the difference between BREAKPOINT_COUNT
579 and PREV_BREAKPOINT_COUNT is more than one. */
580 static int prev_breakpoint_count
;
582 /* Number of last tracepoint made. */
584 static int tracepoint_count
;
586 static struct cmd_list_element
*breakpoint_set_cmdlist
;
587 static struct cmd_list_element
*breakpoint_show_cmdlist
;
588 struct cmd_list_element
*save_cmdlist
;
590 /* See declaration at breakpoint.h. */
593 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
596 for (breakpoint
*b
: all_breakpoints ())
597 if (func (b
, user_data
) != 0)
603 /* Return whether a breakpoint is an active enabled breakpoint. */
605 breakpoint_enabled (struct breakpoint
*b
)
607 return (b
->enable_state
== bp_enabled
);
610 /* Set breakpoint count to NUM. */
613 set_breakpoint_count (int num
)
615 prev_breakpoint_count
= breakpoint_count
;
616 breakpoint_count
= num
;
617 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
620 /* Used by `start_rbreak_breakpoints' below, to record the current
621 breakpoint count before "rbreak" creates any breakpoint. */
622 static int rbreak_start_breakpoint_count
;
624 /* Called at the start an "rbreak" command to record the first
627 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
629 rbreak_start_breakpoint_count
= breakpoint_count
;
632 /* Called at the end of an "rbreak" command to record the last
635 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
637 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
640 /* Used in run_command to zero the hit count when a new run starts. */
643 clear_breakpoint_hit_counts (void)
645 for (breakpoint
*b
: all_breakpoints ())
650 /* Return the breakpoint with the specified number, or NULL
651 if the number does not refer to an existing breakpoint. */
654 get_breakpoint (int num
)
656 for (breakpoint
*b
: all_breakpoints ())
657 if (b
->number
== num
)
665 /* Mark locations as "conditions have changed" in case the target supports
666 evaluating conditions on its side. */
669 mark_breakpoint_modified (struct breakpoint
*b
)
671 struct bp_location
*loc
;
673 /* This is only meaningful if the target is
674 evaluating conditions and if the user has
675 opted for condition evaluation on the target's
677 if (gdb_evaluates_breakpoint_condition_p ()
678 || !target_supports_evaluation_of_breakpoint_conditions ())
681 if (!is_breakpoint (b
))
684 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
685 loc
->condition_changed
= condition_modified
;
688 /* Mark location as "conditions have changed" in case the target supports
689 evaluating conditions on its side. */
692 mark_breakpoint_location_modified (struct bp_location
*loc
)
694 /* This is only meaningful if the target is
695 evaluating conditions and if the user has
696 opted for condition evaluation on the target's
698 if (gdb_evaluates_breakpoint_condition_p ()
699 || !target_supports_evaluation_of_breakpoint_conditions ())
703 if (!is_breakpoint (loc
->owner
))
706 loc
->condition_changed
= condition_modified
;
709 /* Sets the condition-evaluation mode using the static global
710 condition_evaluation_mode. */
713 set_condition_evaluation_mode (const char *args
, int from_tty
,
714 struct cmd_list_element
*c
)
716 const char *old_mode
, *new_mode
;
718 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
719 && !target_supports_evaluation_of_breakpoint_conditions ())
721 condition_evaluation_mode_1
= condition_evaluation_mode
;
722 warning (_("Target does not support breakpoint condition evaluation.\n"
723 "Using host evaluation mode instead."));
727 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
728 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
730 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
731 settings was "auto". */
732 condition_evaluation_mode
= condition_evaluation_mode_1
;
734 /* Only update the mode if the user picked a different one. */
735 if (new_mode
!= old_mode
)
737 struct bp_location
*loc
, **loc_tmp
;
738 /* If the user switched to a different evaluation mode, we
739 need to synch the changes with the target as follows:
741 "host" -> "target": Send all (valid) conditions to the target.
742 "target" -> "host": Remove all the conditions from the target.
745 if (new_mode
== condition_evaluation_target
)
747 /* Mark everything modified and synch conditions with the
749 ALL_BP_LOCATIONS (loc
, loc_tmp
)
750 mark_breakpoint_location_modified (loc
);
754 /* Manually mark non-duplicate locations to synch conditions
755 with the target. We do this to remove all the conditions the
756 target knows about. */
757 ALL_BP_LOCATIONS (loc
, loc_tmp
)
758 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
759 loc
->needs_update
= 1;
763 update_global_location_list (UGLL_MAY_INSERT
);
769 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
770 what "auto" is translating to. */
773 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
774 struct cmd_list_element
*c
, const char *value
)
776 if (condition_evaluation_mode
== condition_evaluation_auto
)
777 fprintf_filtered (file
,
778 _("Breakpoint condition evaluation "
779 "mode is %s (currently %s).\n"),
781 breakpoint_condition_evaluation_mode ());
783 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
787 /* A comparison function for bp_location AP and BP that is used by
788 bsearch. This comparison function only cares about addresses, unlike
789 the more general bp_location_is_less_than function. */
792 bp_locations_compare_addrs (const void *ap
, const void *bp
)
794 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
795 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
797 if (a
->address
== b
->address
)
800 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
803 /* Helper function to skip all bp_locations with addresses
804 less than ADDRESS. It returns the first bp_location that
805 is greater than or equal to ADDRESS. If none is found, just
808 static struct bp_location
**
809 get_first_locp_gte_addr (CORE_ADDR address
)
811 struct bp_location dummy_loc
;
812 struct bp_location
*dummy_locp
= &dummy_loc
;
813 struct bp_location
**locp_found
= NULL
;
815 /* Initialize the dummy location's address field. */
816 dummy_loc
.address
= address
;
818 /* Find a close match to the first location at ADDRESS. */
819 locp_found
= ((struct bp_location
**)
820 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
821 sizeof (struct bp_location
**),
822 bp_locations_compare_addrs
));
824 /* Nothing was found, nothing left to do. */
825 if (locp_found
== NULL
)
828 /* We may have found a location that is at ADDRESS but is not the first in the
829 location's list. Go backwards (if possible) and locate the first one. */
830 while ((locp_found
- 1) >= bp_locations
831 && (*(locp_found
- 1))->address
== address
)
837 /* Parse COND_STRING in the context of LOC and set as the condition
838 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
839 the number of LOC within its owner. In case of parsing error, mark
840 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
843 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
844 int bp_num
, int loc_num
)
846 bool has_junk
= false;
849 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
850 block_for_pc (loc
->address
), 0);
851 if (*cond_string
!= 0)
855 loc
->cond
= std::move (new_exp
);
856 if (loc
->disabled_by_cond
&& loc
->enabled
)
857 printf_filtered (_("Breakpoint %d's condition is now valid at "
858 "location %d, enabling.\n"),
861 loc
->disabled_by_cond
= false;
864 catch (const gdb_exception_error
&e
)
868 /* Warn if a user-enabled location is now becoming disabled-by-cond.
869 BP_NUM is 0 if the breakpoint is being defined for the first
870 time using the "break ... if ..." command, and non-zero if
873 warning (_("failed to validate condition at location %d.%d, "
874 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
876 warning (_("failed to validate condition at location %d, "
877 "disabling:\n %s"), loc_num
, e
.what ());
880 loc
->disabled_by_cond
= true;
884 error (_("Garbage '%s' follows condition"), cond_string
);
888 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
889 int from_tty
, bool force
)
893 xfree (b
->cond_string
);
894 b
->cond_string
= nullptr;
896 if (is_watchpoint (b
))
897 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
901 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
904 if (loc
->disabled_by_cond
&& loc
->enabled
)
905 printf_filtered (_("Breakpoint %d's condition is now valid at "
906 "location %d, enabling.\n"),
908 loc
->disabled_by_cond
= false;
911 /* No need to free the condition agent expression
912 bytecode (if we have one). We will handle this
913 when we go through update_global_location_list. */
918 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
922 if (is_watchpoint (b
))
924 innermost_block_tracker tracker
;
925 const char *arg
= exp
;
926 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
928 error (_("Junk at end of expression"));
929 watchpoint
*w
= static_cast<watchpoint
*> (b
);
930 w
->cond_exp
= std::move (new_exp
);
931 w
->cond_exp_valid_block
= tracker
.block ();
935 /* Parse and set condition expressions. We make two passes.
936 In the first, we parse the condition string to see if it
937 is valid in at least one location. If so, the condition
938 would be accepted. So we go ahead and set the locations'
939 conditions. In case no valid case is found, we throw
940 the error and the condition string will be rejected.
941 This two-pass approach is taken to avoid setting the
942 state of locations in case of a reject. */
943 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
947 const char *arg
= exp
;
948 parse_exp_1 (&arg
, loc
->address
,
949 block_for_pc (loc
->address
), 0);
951 error (_("Junk at end of expression"));
954 catch (const gdb_exception_error
&e
)
956 /* Condition string is invalid. If this happens to
957 be the last loc, abandon (if not forced) or continue
959 if (loc
->next
== nullptr && !force
)
964 /* If we reach here, the condition is valid at some locations. */
966 for (bp_location
*loc
= b
->loc
; loc
!= nullptr;
967 loc
= loc
->next
, loc_num
++)
968 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
971 /* We know that the new condition parsed successfully. The
972 condition string of the breakpoint can be safely updated. */
973 xfree (b
->cond_string
);
974 b
->cond_string
= xstrdup (exp
);
975 b
->condition_not_parsed
= 0;
977 mark_breakpoint_modified (b
);
979 gdb::observers::breakpoint_modified
.notify (b
);
982 /* See breakpoint.h. */
985 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
988 for (breakpoint
*b
: all_breakpoints ())
989 if (b
->number
== bpnum
)
991 /* Check if this breakpoint has a "stop" method implemented in an
992 extension language. This method and conditions entered into GDB
993 from the CLI are mutually exclusive. */
994 const struct extension_language_defn
*extlang
995 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
999 error (_("Only one stop condition allowed. There is currently"
1000 " a %s stop condition defined for this breakpoint."),
1001 ext_lang_capitalized_name (extlang
));
1003 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1005 if (is_breakpoint (b
))
1006 update_global_location_list (UGLL_MAY_INSERT
);
1011 error (_("No breakpoint number %d."), bpnum
);
1014 /* The options for the "condition" command. */
1016 struct condition_command_opts
1019 bool force_condition
= false;
1022 static const gdb::option::option_def condition_command_option_defs
[] = {
1024 gdb::option::flag_option_def
<condition_command_opts
> {
1026 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1027 N_("Set the condition even if it is invalid for all current locations."),
1032 /* Create an option_def_group for the "condition" options, with
1033 CC_OPTS as context. */
1035 static inline gdb::option::option_def_group
1036 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1038 return {{condition_command_option_defs
}, cc_opts
};
1041 /* Completion for the "condition" command. */
1044 condition_completer (struct cmd_list_element
*cmd
,
1045 completion_tracker
&tracker
,
1046 const char *text
, const char * /*word*/)
1048 bool has_no_arguments
= (*text
== '\0');
1049 condition_command_opts cc_opts
;
1050 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1051 if (gdb::option::complete_options
1052 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1055 text
= skip_spaces (text
);
1056 const char *space
= skip_to_space (text
);
1063 tracker
.advance_custom_word_point_by (1);
1064 /* We don't support completion of history indices. */
1065 if (!isdigit (text
[1]))
1066 complete_internalvar (tracker
, &text
[1]);
1070 /* Suggest the "-force" flag if no arguments are given. If
1071 arguments were passed, they either already include the flag,
1072 or we are beyond the point of suggesting it because it's
1073 positionally the first argument. */
1074 if (has_no_arguments
)
1075 gdb::option::complete_on_all_options (tracker
, group
);
1077 /* We're completing the breakpoint number. */
1078 len
= strlen (text
);
1080 for (breakpoint
*b
: all_breakpoints ())
1084 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1086 if (strncmp (number
, text
, len
) == 0)
1087 tracker
.add_completion (make_unique_xstrdup (number
));
1093 /* We're completing the expression part. Skip the breakpoint num. */
1094 const char *exp_start
= skip_spaces (space
);
1095 tracker
.advance_custom_word_point_by (exp_start
- text
);
1097 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1098 expression_completer (cmd
, tracker
, text
, word
);
1101 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1104 condition_command (const char *arg
, int from_tty
)
1110 error_no_arg (_("breakpoint number"));
1114 /* Check if the "-force" flag was passed. */
1115 condition_command_opts cc_opts
;
1116 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1117 gdb::option::process_options
1118 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1120 bnum
= get_number (&p
);
1122 error (_("Bad breakpoint argument: '%s'"), arg
);
1124 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1127 /* Check that COMMAND do not contain commands that are suitable
1128 only for tracepoints and not suitable for ordinary breakpoints.
1129 Throw if any such commands is found. */
1132 check_no_tracepoint_commands (struct command_line
*commands
)
1134 struct command_line
*c
;
1136 for (c
= commands
; c
; c
= c
->next
)
1138 if (c
->control_type
== while_stepping_control
)
1139 error (_("The 'while-stepping' command can "
1140 "only be used for tracepoints"));
1142 check_no_tracepoint_commands (c
->body_list_0
.get ());
1143 check_no_tracepoint_commands (c
->body_list_1
.get ());
1145 /* Not that command parsing removes leading whitespace and comment
1146 lines and also empty lines. So, we only need to check for
1147 command directly. */
1148 if (strstr (c
->line
, "collect ") == c
->line
)
1149 error (_("The 'collect' command can only be used for tracepoints"));
1151 if (strstr (c
->line
, "teval ") == c
->line
)
1152 error (_("The 'teval' command can only be used for tracepoints"));
1156 struct longjmp_breakpoint
: public breakpoint
1158 ~longjmp_breakpoint () override
;
1161 /* Encapsulate tests for different types of tracepoints. */
1164 is_tracepoint_type (bptype type
)
1166 return (type
== bp_tracepoint
1167 || type
== bp_fast_tracepoint
1168 || type
== bp_static_tracepoint
);
1172 is_longjmp_type (bptype type
)
1174 return type
== bp_longjmp
|| type
== bp_exception
;
1177 /* See breakpoint.h. */
1180 is_tracepoint (const struct breakpoint
*b
)
1182 return is_tracepoint_type (b
->type
);
1185 /* Factory function to create an appropriate instance of breakpoint given
1188 static std::unique_ptr
<breakpoint
>
1189 new_breakpoint_from_type (bptype type
)
1193 if (is_tracepoint_type (type
))
1194 b
= new tracepoint ();
1195 else if (is_longjmp_type (type
))
1196 b
= new longjmp_breakpoint ();
1198 b
= new breakpoint ();
1200 return std::unique_ptr
<breakpoint
> (b
);
1203 /* A helper function that validates that COMMANDS are valid for a
1204 breakpoint. This function will throw an exception if a problem is
1208 validate_commands_for_breakpoint (struct breakpoint
*b
,
1209 struct command_line
*commands
)
1211 if (is_tracepoint (b
))
1213 struct tracepoint
*t
= (struct tracepoint
*) b
;
1214 struct command_line
*c
;
1215 struct command_line
*while_stepping
= 0;
1217 /* Reset the while-stepping step count. The previous commands
1218 might have included a while-stepping action, while the new
1222 /* We need to verify that each top-level element of commands is
1223 valid for tracepoints, that there's at most one
1224 while-stepping element, and that the while-stepping's body
1225 has valid tracing commands excluding nested while-stepping.
1226 We also need to validate the tracepoint action line in the
1227 context of the tracepoint --- validate_actionline actually
1228 has side effects, like setting the tracepoint's
1229 while-stepping STEP_COUNT, in addition to checking if the
1230 collect/teval actions parse and make sense in the
1231 tracepoint's context. */
1232 for (c
= commands
; c
; c
= c
->next
)
1234 if (c
->control_type
== while_stepping_control
)
1236 if (b
->type
== bp_fast_tracepoint
)
1237 error (_("The 'while-stepping' command "
1238 "cannot be used for fast tracepoint"));
1239 else if (b
->type
== bp_static_tracepoint
)
1240 error (_("The 'while-stepping' command "
1241 "cannot be used for static tracepoint"));
1244 error (_("The 'while-stepping' command "
1245 "can be used only once"));
1250 validate_actionline (c
->line
, b
);
1254 struct command_line
*c2
;
1256 gdb_assert (while_stepping
->body_list_1
== nullptr);
1257 c2
= while_stepping
->body_list_0
.get ();
1258 for (; c2
; c2
= c2
->next
)
1260 if (c2
->control_type
== while_stepping_control
)
1261 error (_("The 'while-stepping' command cannot be nested"));
1267 check_no_tracepoint_commands (commands
);
1271 /* Return a vector of all the static tracepoints set at ADDR. The
1272 caller is responsible for releasing the vector. */
1274 std::vector
<breakpoint
*>
1275 static_tracepoints_here (CORE_ADDR addr
)
1277 std::vector
<breakpoint
*> found
;
1278 struct bp_location
*loc
;
1280 for (breakpoint
*b
: all_breakpoints ())
1281 if (b
->type
== bp_static_tracepoint
)
1283 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1284 if (loc
->address
== addr
)
1285 found
.push_back (b
);
1291 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1292 validate that only allowed commands are included. */
1295 breakpoint_set_commands (struct breakpoint
*b
,
1296 counted_command_line
&&commands
)
1298 validate_commands_for_breakpoint (b
, commands
.get ());
1300 b
->commands
= std::move (commands
);
1301 gdb::observers::breakpoint_modified
.notify (b
);
1304 /* Set the internal `silent' flag on the breakpoint. Note that this
1305 is not the same as the "silent" that may appear in the breakpoint's
1309 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1311 int old_silent
= b
->silent
;
1314 if (old_silent
!= silent
)
1315 gdb::observers::breakpoint_modified
.notify (b
);
1318 /* Set the thread for this breakpoint. If THREAD is -1, make the
1319 breakpoint work for any thread. */
1322 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1324 int old_thread
= b
->thread
;
1327 if (old_thread
!= thread
)
1328 gdb::observers::breakpoint_modified
.notify (b
);
1331 /* Set the task for this breakpoint. If TASK is 0, make the
1332 breakpoint work for any task. */
1335 breakpoint_set_task (struct breakpoint
*b
, int task
)
1337 int old_task
= b
->task
;
1340 if (old_task
!= task
)
1341 gdb::observers::breakpoint_modified
.notify (b
);
1345 commands_command_1 (const char *arg
, int from_tty
,
1346 struct command_line
*control
)
1348 counted_command_line cmd
;
1349 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1350 NULL after the call to read_command_lines if the user provides an empty
1351 list of command by just typing "end". */
1352 bool cmd_read
= false;
1354 std::string new_arg
;
1356 if (arg
== NULL
|| !*arg
)
1358 /* Argument not explicitly given. Synthesize it. */
1359 if (breakpoint_count
- prev_breakpoint_count
> 1)
1360 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1362 else if (breakpoint_count
> 0)
1363 new_arg
= string_printf ("%d", breakpoint_count
);
1367 /* Create a copy of ARG. This is needed because the "commands"
1368 command may be coming from a script. In that case, the read
1369 line buffer is going to be overwritten in the lambda of
1370 'map_breakpoint_numbers' below when reading the next line
1371 before we are are done parsing the breakpoint numbers. */
1374 arg
= new_arg
.c_str ();
1376 map_breakpoint_numbers
1377 (arg
, [&] (breakpoint
*b
)
1381 gdb_assert (cmd
== NULL
);
1382 if (control
!= NULL
)
1383 cmd
= control
->body_list_0
;
1387 = string_printf (_("Type commands for breakpoint(s) "
1388 "%s, one per line."),
1391 auto do_validate
= [=] (const char *line
)
1393 validate_actionline (line
, b
);
1395 gdb::function_view
<void (const char *)> validator
;
1396 if (is_tracepoint (b
))
1397 validator
= do_validate
;
1399 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1404 /* If a breakpoint was on the list more than once, we don't need to
1406 if (b
->commands
!= cmd
)
1408 validate_commands_for_breakpoint (b
, cmd
.get ());
1410 gdb::observers::breakpoint_modified
.notify (b
);
1416 commands_command (const char *arg
, int from_tty
)
1418 commands_command_1 (arg
, from_tty
, NULL
);
1421 /* Like commands_command, but instead of reading the commands from
1422 input stream, takes them from an already parsed command structure.
1424 This is used by cli-script.c to DTRT with breakpoint commands
1425 that are part of if and while bodies. */
1426 enum command_control_type
1427 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1429 commands_command_1 (arg
, 0, cmd
);
1430 return simple_control
;
1433 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1436 bp_location_has_shadow (struct bp_location
*bl
)
1438 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1442 if (bl
->target_info
.shadow_len
== 0)
1443 /* BL isn't valid, or doesn't shadow memory. */
1448 /* Update BUF, which is LEN bytes read from the target address
1449 MEMADDR, by replacing a memory breakpoint with its shadowed
1452 If READBUF is not NULL, this buffer must not overlap with the of
1453 the breakpoint location's shadow_contents buffer. Otherwise, a
1454 failed assertion internal error will be raised. */
1457 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1458 const gdb_byte
*writebuf_org
,
1459 ULONGEST memaddr
, LONGEST len
,
1460 struct bp_target_info
*target_info
,
1461 struct gdbarch
*gdbarch
)
1463 /* Now do full processing of the found relevant range of elements. */
1464 CORE_ADDR bp_addr
= 0;
1468 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1469 current_program_space
->aspace
, 0))
1471 /* The breakpoint is inserted in a different address space. */
1475 /* Addresses and length of the part of the breakpoint that
1477 bp_addr
= target_info
->placed_address
;
1478 bp_size
= target_info
->shadow_len
;
1480 if (bp_addr
+ bp_size
<= memaddr
)
1482 /* The breakpoint is entirely before the chunk of memory we are
1487 if (bp_addr
>= memaddr
+ len
)
1489 /* The breakpoint is entirely after the chunk of memory we are
1494 /* Offset within shadow_contents. */
1495 if (bp_addr
< memaddr
)
1497 /* Only copy the second part of the breakpoint. */
1498 bp_size
-= memaddr
- bp_addr
;
1499 bptoffset
= memaddr
- bp_addr
;
1503 if (bp_addr
+ bp_size
> memaddr
+ len
)
1505 /* Only copy the first part of the breakpoint. */
1506 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1509 if (readbuf
!= NULL
)
1511 /* Verify that the readbuf buffer does not overlap with the
1512 shadow_contents buffer. */
1513 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1514 || readbuf
>= (target_info
->shadow_contents
1515 + target_info
->shadow_len
));
1517 /* Update the read buffer with this inserted breakpoint's
1519 memcpy (readbuf
+ bp_addr
- memaddr
,
1520 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1524 const unsigned char *bp
;
1525 CORE_ADDR addr
= target_info
->reqstd_address
;
1528 /* Update the shadow with what we want to write to memory. */
1529 memcpy (target_info
->shadow_contents
+ bptoffset
,
1530 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1532 /* Determine appropriate breakpoint contents and size for this
1534 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1536 /* Update the final write buffer with this inserted
1537 breakpoint's INSN. */
1538 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1542 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1543 by replacing any memory breakpoints with their shadowed contents.
1545 If READBUF is not NULL, this buffer must not overlap with any of
1546 the breakpoint location's shadow_contents buffers. Otherwise,
1547 a failed assertion internal error will be raised.
1549 The range of shadowed area by each bp_location is:
1550 bl->address - bp_locations_placed_address_before_address_max
1551 up to bl->address + bp_locations_shadow_len_after_address_max
1552 The range we were requested to resolve shadows for is:
1553 memaddr ... memaddr + len
1554 Thus the safe cutoff boundaries for performance optimization are
1555 memaddr + len <= (bl->address
1556 - bp_locations_placed_address_before_address_max)
1558 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1561 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1562 const gdb_byte
*writebuf_org
,
1563 ULONGEST memaddr
, LONGEST len
)
1565 /* Left boundary, right boundary and median element of our binary
1567 unsigned bc_l
, bc_r
, bc
;
1569 /* Find BC_L which is a leftmost element which may affect BUF
1570 content. It is safe to report lower value but a failure to
1571 report higher one. */
1574 bc_r
= bp_locations_count
;
1575 while (bc_l
+ 1 < bc_r
)
1577 struct bp_location
*bl
;
1579 bc
= (bc_l
+ bc_r
) / 2;
1580 bl
= bp_locations
[bc
];
1582 /* Check first BL->ADDRESS will not overflow due to the added
1583 constant. Then advance the left boundary only if we are sure
1584 the BC element can in no way affect the BUF content (MEMADDR
1585 to MEMADDR + LEN range).
1587 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1588 offset so that we cannot miss a breakpoint with its shadow
1589 range tail still reaching MEMADDR. */
1591 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1593 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1600 /* Due to the binary search above, we need to make sure we pick the
1601 first location that's at BC_L's address. E.g., if there are
1602 multiple locations at the same address, BC_L may end up pointing
1603 at a duplicate location, and miss the "master"/"inserted"
1604 location. Say, given locations L1, L2 and L3 at addresses A and
1607 L1@A, L2@A, L3@B, ...
1609 BC_L could end up pointing at location L2, while the "master"
1610 location could be L1. Since the `loc->inserted' flag is only set
1611 on "master" locations, we'd forget to restore the shadow of L1
1614 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1617 /* Now do full processing of the found relevant range of elements. */
1619 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1621 struct bp_location
*bl
= bp_locations
[bc
];
1623 /* bp_location array has BL->OWNER always non-NULL. */
1624 if (bl
->owner
->type
== bp_none
)
1625 warning (_("reading through apparently deleted breakpoint #%d?"),
1628 /* Performance optimization: any further element can no longer affect BUF
1631 if (bl
->address
>= bp_locations_placed_address_before_address_max
1632 && memaddr
+ len
<= (bl
->address
1633 - bp_locations_placed_address_before_address_max
))
1636 if (!bp_location_has_shadow (bl
))
1639 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1640 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1644 /* See breakpoint.h. */
1647 is_breakpoint (const struct breakpoint
*bpt
)
1649 return (bpt
->type
== bp_breakpoint
1650 || bpt
->type
== bp_hardware_breakpoint
1651 || bpt
->type
== bp_dprintf
);
1654 /* Return true if BPT is of any hardware watchpoint kind. */
1657 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1659 return (bpt
->type
== bp_hardware_watchpoint
1660 || bpt
->type
== bp_read_watchpoint
1661 || bpt
->type
== bp_access_watchpoint
);
1664 /* See breakpoint.h. */
1667 is_watchpoint (const struct breakpoint
*bpt
)
1669 return (is_hardware_watchpoint (bpt
)
1670 || bpt
->type
== bp_watchpoint
);
1673 /* Returns true if the current thread and its running state are safe
1674 to evaluate or update watchpoint B. Watchpoints on local
1675 expressions need to be evaluated in the context of the thread that
1676 was current when the watchpoint was created, and, that thread needs
1677 to be stopped to be able to select the correct frame context.
1678 Watchpoints on global expressions can be evaluated on any thread,
1679 and in any state. It is presently left to the target allowing
1680 memory accesses when threads are running. */
1683 watchpoint_in_thread_scope (struct watchpoint
*b
)
1685 return (b
->pspace
== current_program_space
1686 && (b
->watchpoint_thread
== null_ptid
1687 || (inferior_ptid
== b
->watchpoint_thread
1688 && !inferior_thread ()->executing
)));
1691 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1692 associated bp_watchpoint_scope breakpoint. */
1695 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1697 if (w
->related_breakpoint
!= w
)
1699 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1700 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1701 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1702 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1703 w
->related_breakpoint
= w
;
1705 w
->disposition
= disp_del_at_next_stop
;
1708 /* Extract a bitfield value from value VAL using the bit parameters contained in
1711 static struct value
*
1712 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1714 struct value
*bit_val
;
1719 bit_val
= allocate_value (value_type (val
));
1721 unpack_value_bitfield (bit_val
,
1724 value_contents_for_printing (val
),
1731 /* Allocate a dummy location and add it to B, which must be a software
1732 watchpoint. This is required because even if a software watchpoint
1733 is not watching any memory, bpstat_stop_status requires a location
1734 to be able to report stops. */
1737 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1738 struct program_space
*pspace
)
1740 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1742 b
->loc
= allocate_bp_location (b
);
1743 b
->loc
->pspace
= pspace
;
1744 b
->loc
->address
= -1;
1745 b
->loc
->length
= -1;
1748 /* Returns true if B is a software watchpoint that is not watching any
1749 memory (e.g., "watch $pc"). */
1752 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1754 return (b
->type
== bp_watchpoint
1756 && b
->loc
->next
== NULL
1757 && b
->loc
->address
== -1
1758 && b
->loc
->length
== -1);
1761 /* Assuming that B is a watchpoint:
1762 - Reparse watchpoint expression, if REPARSE is non-zero
1763 - Evaluate expression and store the result in B->val
1764 - Evaluate the condition if there is one, and store the result
1766 - Update the list of values that must be watched in B->loc.
1768 If the watchpoint disposition is disp_del_at_next_stop, then do
1769 nothing. If this is local watchpoint that is out of scope, delete
1772 Even with `set breakpoint always-inserted on' the watchpoints are
1773 removed + inserted on each stop here. Normal breakpoints must
1774 never be removed because they might be missed by a running thread
1775 when debugging in non-stop mode. On the other hand, hardware
1776 watchpoints (is_hardware_watchpoint; processed here) are specific
1777 to each LWP since they are stored in each LWP's hardware debug
1778 registers. Therefore, such LWP must be stopped first in order to
1779 be able to modify its hardware watchpoints.
1781 Hardware watchpoints must be reset exactly once after being
1782 presented to the user. It cannot be done sooner, because it would
1783 reset the data used to present the watchpoint hit to the user. And
1784 it must not be done later because it could display the same single
1785 watchpoint hit during multiple GDB stops. Note that the latter is
1786 relevant only to the hardware watchpoint types bp_read_watchpoint
1787 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1788 not user-visible - its hit is suppressed if the memory content has
1791 The following constraints influence the location where we can reset
1792 hardware watchpoints:
1794 * target_stopped_by_watchpoint and target_stopped_data_address are
1795 called several times when GDB stops.
1798 * Multiple hardware watchpoints can be hit at the same time,
1799 causing GDB to stop. GDB only presents one hardware watchpoint
1800 hit at a time as the reason for stopping, and all the other hits
1801 are presented later, one after the other, each time the user
1802 requests the execution to be resumed. Execution is not resumed
1803 for the threads still having pending hit event stored in
1804 LWP_INFO->STATUS. While the watchpoint is already removed from
1805 the inferior on the first stop the thread hit event is kept being
1806 reported from its cached value by linux_nat_stopped_data_address
1807 until the real thread resume happens after the watchpoint gets
1808 presented and thus its LWP_INFO->STATUS gets reset.
1810 Therefore the hardware watchpoint hit can get safely reset on the
1811 watchpoint removal from inferior. */
1814 update_watchpoint (struct watchpoint
*b
, int reparse
)
1816 int within_current_scope
;
1817 struct frame_id saved_frame_id
;
1820 /* If this is a local watchpoint, we only want to check if the
1821 watchpoint frame is in scope if the current thread is the thread
1822 that was used to create the watchpoint. */
1823 if (!watchpoint_in_thread_scope (b
))
1826 if (b
->disposition
== disp_del_at_next_stop
)
1831 /* Determine if the watchpoint is within scope. */
1832 if (b
->exp_valid_block
== NULL
)
1833 within_current_scope
= 1;
1836 struct frame_info
*fi
= get_current_frame ();
1837 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1838 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1840 /* If we're at a point where the stack has been destroyed
1841 (e.g. in a function epilogue), unwinding may not work
1842 properly. Do not attempt to recreate locations at this
1843 point. See similar comments in watchpoint_check. */
1844 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1847 /* Save the current frame's ID so we can restore it after
1848 evaluating the watchpoint expression on its own frame. */
1849 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1850 took a frame parameter, so that we didn't have to change the
1853 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1855 fi
= frame_find_by_id (b
->watchpoint_frame
);
1856 within_current_scope
= (fi
!= NULL
);
1857 if (within_current_scope
)
1861 /* We don't free locations. They are stored in the bp_location array
1862 and update_global_location_list will eventually delete them and
1863 remove breakpoints if needed. */
1866 if (within_current_scope
&& reparse
)
1871 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1872 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1873 /* If the meaning of expression itself changed, the old value is
1874 no longer relevant. We don't want to report a watchpoint hit
1875 to the user when the old value and the new value may actually
1876 be completely different objects. */
1878 b
->val_valid
= false;
1880 /* Note that unlike with breakpoints, the watchpoint's condition
1881 expression is stored in the breakpoint object, not in the
1882 locations (re)created below. */
1883 if (b
->cond_string
!= NULL
)
1885 b
->cond_exp
.reset ();
1888 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1892 /* If we failed to parse the expression, for example because
1893 it refers to a global variable in a not-yet-loaded shared library,
1894 don't try to insert watchpoint. We don't automatically delete
1895 such watchpoint, though, since failure to parse expression
1896 is different from out-of-scope watchpoint. */
1897 if (!target_has_execution ())
1899 /* Without execution, memory can't change. No use to try and
1900 set watchpoint locations. The watchpoint will be reset when
1901 the target gains execution, through breakpoint_re_set. */
1902 if (!can_use_hw_watchpoints
)
1904 if (b
->ops
->works_in_software_mode (b
))
1905 b
->type
= bp_watchpoint
;
1907 error (_("Can't set read/access watchpoint when "
1908 "hardware watchpoints are disabled."));
1911 else if (within_current_scope
&& b
->exp
)
1913 std::vector
<value_ref_ptr
> val_chain
;
1914 struct value
*v
, *result
;
1915 struct program_space
*frame_pspace
;
1917 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
1920 /* Avoid setting b->val if it's already set. The meaning of
1921 b->val is 'the last value' user saw, and we should update
1922 it only if we reported that last value to user. As it
1923 happens, the code that reports it updates b->val directly.
1924 We don't keep track of the memory value for masked
1926 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1928 if (b
->val_bitsize
!= 0)
1929 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1930 b
->val
= release_value (v
);
1931 b
->val_valid
= true;
1934 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1936 /* Look at each value on the value chain. */
1937 gdb_assert (!val_chain
.empty ());
1938 for (const value_ref_ptr
&iter
: val_chain
)
1942 /* If it's a memory location, and GDB actually needed
1943 its contents to evaluate the expression, then we
1944 must watch it. If the first value returned is
1945 still lazy, that means an error occurred reading it;
1946 watch it anyway in case it becomes readable. */
1947 if (VALUE_LVAL (v
) == lval_memory
1948 && (v
== val_chain
[0] || ! value_lazy (v
)))
1950 struct type
*vtype
= check_typedef (value_type (v
));
1952 /* We only watch structs and arrays if user asked
1953 for it explicitly, never if they just happen to
1954 appear in the middle of some value chain. */
1956 || (vtype
->code () != TYPE_CODE_STRUCT
1957 && vtype
->code () != TYPE_CODE_ARRAY
))
1960 enum target_hw_bp_type type
;
1961 struct bp_location
*loc
, **tmp
;
1962 int bitpos
= 0, bitsize
= 0;
1964 if (value_bitsize (v
) != 0)
1966 /* Extract the bit parameters out from the bitfield
1968 bitpos
= value_bitpos (v
);
1969 bitsize
= value_bitsize (v
);
1971 else if (v
== result
&& b
->val_bitsize
!= 0)
1973 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1974 lvalue whose bit parameters are saved in the fields
1975 VAL_BITPOS and VAL_BITSIZE. */
1976 bitpos
= b
->val_bitpos
;
1977 bitsize
= b
->val_bitsize
;
1980 addr
= value_address (v
);
1983 /* Skip the bytes that don't contain the bitfield. */
1988 if (b
->type
== bp_read_watchpoint
)
1990 else if (b
->type
== bp_access_watchpoint
)
1993 loc
= allocate_bp_location (b
);
1994 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1997 loc
->gdbarch
= value_type (v
)->arch ();
1999 loc
->pspace
= frame_pspace
;
2000 loc
->address
= address_significant (loc
->gdbarch
, addr
);
2004 /* Just cover the bytes that make up the bitfield. */
2005 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2008 loc
->length
= TYPE_LENGTH (value_type (v
));
2010 loc
->watchpoint_type
= type
;
2015 /* Change the type of breakpoint between hardware assisted or
2016 an ordinary watchpoint depending on the hardware support
2017 and free hardware slots. REPARSE is set when the inferior
2022 enum bp_loc_type loc_type
;
2023 struct bp_location
*bl
;
2025 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2029 int i
, target_resources_ok
, other_type_used
;
2032 /* Use an exact watchpoint when there's only one memory region to be
2033 watched, and only one debug register is needed to watch it. */
2034 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2036 /* We need to determine how many resources are already
2037 used for all other hardware watchpoints plus this one
2038 to see if we still have enough resources to also fit
2039 this watchpoint in as well. */
2041 /* If this is a software watchpoint, we try to turn it
2042 to a hardware one -- count resources as if B was of
2043 hardware watchpoint type. */
2045 if (type
== bp_watchpoint
)
2046 type
= bp_hardware_watchpoint
;
2048 /* This watchpoint may or may not have been placed on
2049 the list yet at this point (it won't be in the list
2050 if we're trying to create it for the first time,
2051 through watch_command), so always account for it
2054 /* Count resources used by all watchpoints except B. */
2055 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2057 /* Add in the resources needed for B. */
2058 i
+= hw_watchpoint_use_count (b
);
2061 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2062 if (target_resources_ok
<= 0)
2064 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2066 if (target_resources_ok
== 0 && !sw_mode
)
2067 error (_("Target does not support this type of "
2068 "hardware watchpoint."));
2069 else if (target_resources_ok
< 0 && !sw_mode
)
2070 error (_("There are not enough available hardware "
2071 "resources for this watchpoint."));
2073 /* Downgrade to software watchpoint. */
2074 b
->type
= bp_watchpoint
;
2078 /* If this was a software watchpoint, we've just
2079 found we have enough resources to turn it to a
2080 hardware watchpoint. Otherwise, this is a
2085 else if (!b
->ops
->works_in_software_mode (b
))
2087 if (!can_use_hw_watchpoints
)
2088 error (_("Can't set read/access watchpoint when "
2089 "hardware watchpoints are disabled."));
2091 error (_("Expression cannot be implemented with "
2092 "read/access watchpoint."));
2095 b
->type
= bp_watchpoint
;
2097 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2098 : bp_loc_hardware_watchpoint
);
2099 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
2100 bl
->loc_type
= loc_type
;
2103 /* If a software watchpoint is not watching any memory, then the
2104 above left it without any location set up. But,
2105 bpstat_stop_status requires a location to be able to report
2106 stops, so make sure there's at least a dummy one. */
2107 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2108 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2110 else if (!within_current_scope
)
2112 printf_filtered (_("\
2113 Watchpoint %d deleted because the program has left the block\n\
2114 in which its expression is valid.\n"),
2116 watchpoint_del_at_next_stop (b
);
2119 /* Restore the selected frame. */
2121 select_frame (frame_find_by_id (saved_frame_id
));
2125 /* Returns 1 iff breakpoint location should be
2126 inserted in the inferior. We don't differentiate the type of BL's owner
2127 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2128 breakpoint_ops is not defined, because in insert_bp_location,
2129 tracepoint's insert_location will not be called. */
2131 should_be_inserted (struct bp_location
*bl
)
2133 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2136 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2139 if (!bl
->enabled
|| bl
->disabled_by_cond
2140 || bl
->shlib_disabled
|| bl
->duplicate
)
2143 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2146 /* This is set for example, when we're attached to the parent of a
2147 vfork, and have detached from the child. The child is running
2148 free, and we expect it to do an exec or exit, at which point the
2149 OS makes the parent schedulable again (and the target reports
2150 that the vfork is done). Until the child is done with the shared
2151 memory region, do not insert breakpoints in the parent, otherwise
2152 the child could still trip on the parent's breakpoints. Since
2153 the parent is blocked anyway, it won't miss any breakpoint. */
2154 if (bl
->pspace
->breakpoints_not_allowed
)
2157 /* Don't insert a breakpoint if we're trying to step past its
2158 location, except if the breakpoint is a single-step breakpoint,
2159 and the breakpoint's thread is the thread which is stepping past
2161 if ((bl
->loc_type
== bp_loc_software_breakpoint
2162 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2163 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2165 /* The single-step breakpoint may be inserted at the location
2166 we're trying to step if the instruction branches to itself.
2167 However, the instruction won't be executed at all and it may
2168 break the semantics of the instruction, for example, the
2169 instruction is a conditional branch or updates some flags.
2170 We can't fix it unless GDB is able to emulate the instruction
2171 or switch to displaced stepping. */
2172 && !(bl
->owner
->type
== bp_single_step
2173 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2175 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2176 paddress (bl
->gdbarch
, bl
->address
));
2180 /* Don't insert watchpoints if we're trying to step past the
2181 instruction that triggered one. */
2182 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2183 && stepping_past_nonsteppable_watchpoint ())
2185 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2186 "skipping watchpoint at %s:%d",
2187 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2194 /* Same as should_be_inserted but does the check assuming
2195 that the location is not duplicated. */
2198 unduplicated_should_be_inserted (struct bp_location
*bl
)
2201 const int save_duplicate
= bl
->duplicate
;
2204 result
= should_be_inserted (bl
);
2205 bl
->duplicate
= save_duplicate
;
2209 /* Parses a conditional described by an expression COND into an
2210 agent expression bytecode suitable for evaluation
2211 by the bytecode interpreter. Return NULL if there was
2212 any error during parsing. */
2214 static agent_expr_up
2215 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2220 agent_expr_up aexpr
;
2222 /* We don't want to stop processing, so catch any errors
2223 that may show up. */
2226 aexpr
= gen_eval_for_expr (scope
, cond
);
2229 catch (const gdb_exception_error
&ex
)
2231 /* If we got here, it means the condition could not be parsed to a valid
2232 bytecode expression and thus can't be evaluated on the target's side.
2233 It's no use iterating through the conditions. */
2236 /* We have a valid agent expression. */
2240 /* Based on location BL, create a list of breakpoint conditions to be
2241 passed on to the target. If we have duplicated locations with different
2242 conditions, we will add such conditions to the list. The idea is that the
2243 target will evaluate the list of conditions and will only notify GDB when
2244 one of them is true. */
2247 build_target_condition_list (struct bp_location
*bl
)
2249 struct bp_location
**locp
= NULL
, **loc2p
;
2250 int null_condition_or_parse_error
= 0;
2251 int modified
= bl
->needs_update
;
2252 struct bp_location
*loc
;
2254 /* Release conditions left over from a previous insert. */
2255 bl
->target_info
.conditions
.clear ();
2257 /* This is only meaningful if the target is
2258 evaluating conditions and if the user has
2259 opted for condition evaluation on the target's
2261 if (gdb_evaluates_breakpoint_condition_p ()
2262 || !target_supports_evaluation_of_breakpoint_conditions ())
2265 /* Do a first pass to check for locations with no assigned
2266 conditions or conditions that fail to parse to a valid agent
2267 expression bytecode. If any of these happen, then it's no use to
2268 send conditions to the target since this location will always
2269 trigger and generate a response back to GDB. Note we consider
2270 all locations at the same address irrespective of type, i.e.,
2271 even if the locations aren't considered duplicates (e.g.,
2272 software breakpoint and hardware breakpoint at the same
2274 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2277 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2281 /* Re-parse the conditions since something changed. In that
2282 case we already freed the condition bytecodes (see
2283 force_breakpoint_reinsertion). We just
2284 need to parse the condition to bytecodes again. */
2285 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2289 /* If we have a NULL bytecode expression, it means something
2290 went wrong or we have a null condition expression. */
2291 if (!loc
->cond_bytecode
)
2293 null_condition_or_parse_error
= 1;
2299 /* If any of these happened, it means we will have to evaluate the conditions
2300 for the location's address on gdb's side. It is no use keeping bytecodes
2301 for all the other duplicate locations, thus we free all of them here.
2303 This is so we have a finer control over which locations' conditions are
2304 being evaluated by GDB or the remote stub. */
2305 if (null_condition_or_parse_error
)
2307 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2310 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2312 /* Only go as far as the first NULL bytecode is
2314 if (!loc
->cond_bytecode
)
2317 loc
->cond_bytecode
.reset ();
2322 /* No NULL conditions or failed bytecode generation. Build a
2323 condition list for this location's address. If we have software
2324 and hardware locations at the same address, they aren't
2325 considered duplicates, but we still marge all the conditions
2326 anyway, as it's simpler, and doesn't really make a practical
2328 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2332 && is_breakpoint (loc
->owner
)
2333 && loc
->pspace
->num
== bl
->pspace
->num
2334 && loc
->owner
->enable_state
== bp_enabled
2336 && !loc
->disabled_by_cond
)
2338 /* Add the condition to the vector. This will be used later
2339 to send the conditions to the target. */
2340 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2347 /* Parses a command described by string CMD into an agent expression
2348 bytecode suitable for evaluation by the bytecode interpreter.
2349 Return NULL if there was any error during parsing. */
2351 static agent_expr_up
2352 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2354 const char *cmdrest
;
2355 const char *format_start
, *format_end
;
2356 struct gdbarch
*gdbarch
= get_current_arch ();
2363 if (*cmdrest
== ',')
2365 cmdrest
= skip_spaces (cmdrest
);
2367 if (*cmdrest
++ != '"')
2368 error (_("No format string following the location"));
2370 format_start
= cmdrest
;
2372 format_pieces
fpieces (&cmdrest
);
2374 format_end
= cmdrest
;
2376 if (*cmdrest
++ != '"')
2377 error (_("Bad format string, non-terminated '\"'."));
2379 cmdrest
= skip_spaces (cmdrest
);
2381 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2382 error (_("Invalid argument syntax"));
2384 if (*cmdrest
== ',')
2386 cmdrest
= skip_spaces (cmdrest
);
2388 /* For each argument, make an expression. */
2390 std::vector
<struct expression
*> argvec
;
2391 while (*cmdrest
!= '\0')
2396 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2397 argvec
.push_back (expr
.release ());
2399 if (*cmdrest
== ',')
2403 agent_expr_up aexpr
;
2405 /* We don't want to stop processing, so catch any errors
2406 that may show up. */
2409 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2410 format_start
, format_end
- format_start
,
2411 argvec
.size (), argvec
.data ());
2413 catch (const gdb_exception_error
&ex
)
2415 /* If we got here, it means the command could not be parsed to a valid
2416 bytecode expression and thus can't be evaluated on the target's side.
2417 It's no use iterating through the other commands. */
2420 /* We have a valid agent expression, return it. */
2424 /* Based on location BL, create a list of breakpoint commands to be
2425 passed on to the target. If we have duplicated locations with
2426 different commands, we will add any such to the list. */
2429 build_target_command_list (struct bp_location
*bl
)
2431 struct bp_location
**locp
= NULL
, **loc2p
;
2432 int null_command_or_parse_error
= 0;
2433 int modified
= bl
->needs_update
;
2434 struct bp_location
*loc
;
2436 /* Clear commands left over from a previous insert. */
2437 bl
->target_info
.tcommands
.clear ();
2439 if (!target_can_run_breakpoint_commands ())
2442 /* For now, limit to agent-style dprintf breakpoints. */
2443 if (dprintf_style
!= dprintf_style_agent
)
2446 /* For now, if we have any location at the same address that isn't a
2447 dprintf, don't install the target-side commands, as that would
2448 make the breakpoint not be reported to the core, and we'd lose
2450 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2453 if (is_breakpoint (loc
->owner
)
2454 && loc
->pspace
->num
== bl
->pspace
->num
2455 && loc
->owner
->type
!= bp_dprintf
)
2459 /* Do a first pass to check for locations with no assigned
2460 conditions or conditions that fail to parse to a valid agent expression
2461 bytecode. If any of these happen, then it's no use to send conditions
2462 to the target since this location will always trigger and generate a
2463 response back to GDB. */
2464 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2467 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2471 /* Re-parse the commands since something changed. In that
2472 case we already freed the command bytecodes (see
2473 force_breakpoint_reinsertion). We just
2474 need to parse the command to bytecodes again. */
2476 = parse_cmd_to_aexpr (bl
->address
,
2477 loc
->owner
->extra_string
);
2480 /* If we have a NULL bytecode expression, it means something
2481 went wrong or we have a null command expression. */
2482 if (!loc
->cmd_bytecode
)
2484 null_command_or_parse_error
= 1;
2490 /* If anything failed, then we're not doing target-side commands,
2492 if (null_command_or_parse_error
)
2494 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2497 if (is_breakpoint (loc
->owner
)
2498 && loc
->pspace
->num
== bl
->pspace
->num
)
2500 /* Only go as far as the first NULL bytecode is
2502 if (loc
->cmd_bytecode
== NULL
)
2505 loc
->cmd_bytecode
.reset ();
2510 /* No NULL commands or failed bytecode generation. Build a command
2511 list for all duplicate locations at this location's address.
2512 Note that here we must care for whether the breakpoint location
2513 types are considered duplicates, otherwise, say, if we have a
2514 software and hardware location at the same address, the target
2515 could end up running the commands twice. For the moment, we only
2516 support targets-side commands with dprintf, but it doesn't hurt
2517 to be pedantically correct in case that changes. */
2518 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2521 if (breakpoint_locations_match (bl
, loc
)
2522 && loc
->owner
->extra_string
2523 && is_breakpoint (loc
->owner
)
2524 && loc
->pspace
->num
== bl
->pspace
->num
2525 && loc
->owner
->enable_state
== bp_enabled
2527 && !loc
->disabled_by_cond
)
2529 /* Add the command to the vector. This will be used later
2530 to send the commands to the target. */
2531 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2535 bl
->target_info
.persist
= 0;
2536 /* Maybe flag this location as persistent. */
2537 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2538 bl
->target_info
.persist
= 1;
2541 /* Return the kind of breakpoint on address *ADDR. Get the kind
2542 of breakpoint according to ADDR except single-step breakpoint.
2543 Get the kind of single-step breakpoint according to the current
2547 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2549 if (bl
->owner
->type
== bp_single_step
)
2551 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2552 struct regcache
*regcache
;
2554 regcache
= get_thread_regcache (thr
);
2556 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2560 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2563 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2564 location. Any error messages are printed to TMP_ERROR_STREAM; and
2565 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2566 Returns 0 for success, 1 if the bp_location type is not supported or
2569 NOTE drow/2003-09-09: This routine could be broken down to an
2570 object-style method for each breakpoint or catchpoint type. */
2572 insert_bp_location (struct bp_location
*bl
,
2573 struct ui_file
*tmp_error_stream
,
2574 int *disabled_breaks
,
2575 int *hw_breakpoint_error
,
2576 int *hw_bp_error_explained_already
)
2578 gdb_exception bp_excpt
;
2580 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2583 /* Note we don't initialize bl->target_info, as that wipes out
2584 the breakpoint location's shadow_contents if the breakpoint
2585 is still inserted at that location. This in turn breaks
2586 target_read_memory which depends on these buffers when
2587 a memory read is requested at the breakpoint location:
2588 Once the target_info has been wiped, we fail to see that
2589 we have a breakpoint inserted at that address and thus
2590 read the breakpoint instead of returning the data saved in
2591 the breakpoint location's shadow contents. */
2592 bl
->target_info
.reqstd_address
= bl
->address
;
2593 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2594 bl
->target_info
.length
= bl
->length
;
2596 /* When working with target-side conditions, we must pass all the conditions
2597 for the same breakpoint address down to the target since GDB will not
2598 insert those locations. With a list of breakpoint conditions, the target
2599 can decide when to stop and notify GDB. */
2601 if (is_breakpoint (bl
->owner
))
2603 build_target_condition_list (bl
);
2604 build_target_command_list (bl
);
2605 /* Reset the modification marker. */
2606 bl
->needs_update
= 0;
2609 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2610 set at a read-only address, then a breakpoint location will have
2611 been changed to hardware breakpoint before we get here. If it is
2612 "off" however, error out before actually trying to insert the
2613 breakpoint, with a nicer error message. */
2614 if (bl
->loc_type
== bp_loc_software_breakpoint
2615 && !automatic_hardware_breakpoints
)
2617 mem_region
*mr
= lookup_mem_region (bl
->address
);
2619 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2621 fprintf_unfiltered (tmp_error_stream
,
2622 _("Cannot insert breakpoint %d.\n"
2623 "Cannot set software breakpoint "
2624 "at read-only address %s\n"),
2626 paddress (bl
->gdbarch
, bl
->address
));
2631 if (bl
->loc_type
== bp_loc_software_breakpoint
2632 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2634 /* First check to see if we have to handle an overlay. */
2635 if (overlay_debugging
== ovly_off
2636 || bl
->section
== NULL
2637 || !(section_is_overlay (bl
->section
)))
2639 /* No overlay handling: just set the breakpoint. */
2644 val
= bl
->owner
->ops
->insert_location (bl
);
2646 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2648 catch (gdb_exception
&e
)
2650 bp_excpt
= std::move (e
);
2655 /* This breakpoint is in an overlay section.
2656 Shall we set a breakpoint at the LMA? */
2657 if (!overlay_events_enabled
)
2659 /* Yes -- overlay event support is not active,
2660 so we must try to set a breakpoint at the LMA.
2661 This will not work for a hardware breakpoint. */
2662 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2663 warning (_("hardware breakpoint %d not supported in overlay!"),
2667 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2669 /* Set a software (trap) breakpoint at the LMA. */
2670 bl
->overlay_target_info
= bl
->target_info
;
2671 bl
->overlay_target_info
.reqstd_address
= addr
;
2673 /* No overlay handling: just set the breakpoint. */
2678 bl
->overlay_target_info
.kind
2679 = breakpoint_kind (bl
, &addr
);
2680 bl
->overlay_target_info
.placed_address
= addr
;
2681 val
= target_insert_breakpoint (bl
->gdbarch
,
2682 &bl
->overlay_target_info
);
2685 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2687 catch (gdb_exception
&e
)
2689 bp_excpt
= std::move (e
);
2692 if (bp_excpt
.reason
!= 0)
2693 fprintf_unfiltered (tmp_error_stream
,
2694 "Overlay breakpoint %d "
2695 "failed: in ROM?\n",
2699 /* Shall we set a breakpoint at the VMA? */
2700 if (section_is_mapped (bl
->section
))
2702 /* Yes. This overlay section is mapped into memory. */
2707 val
= bl
->owner
->ops
->insert_location (bl
);
2709 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2711 catch (gdb_exception
&e
)
2713 bp_excpt
= std::move (e
);
2718 /* No. This breakpoint will not be inserted.
2719 No error, but do not mark the bp as 'inserted'. */
2724 if (bp_excpt
.reason
!= 0)
2726 /* Can't set the breakpoint. */
2728 /* In some cases, we might not be able to insert a
2729 breakpoint in a shared library that has already been
2730 removed, but we have not yet processed the shlib unload
2731 event. Unfortunately, some targets that implement
2732 breakpoint insertion themselves can't tell why the
2733 breakpoint insertion failed (e.g., the remote target
2734 doesn't define error codes), so we must treat generic
2735 errors as memory errors. */
2736 if (bp_excpt
.reason
== RETURN_ERROR
2737 && (bp_excpt
.error
== GENERIC_ERROR
2738 || bp_excpt
.error
== MEMORY_ERROR
)
2739 && bl
->loc_type
== bp_loc_software_breakpoint
2740 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2741 || shared_objfile_contains_address_p (bl
->pspace
,
2744 /* See also: disable_breakpoints_in_shlibs. */
2745 bl
->shlib_disabled
= 1;
2746 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2747 if (!*disabled_breaks
)
2749 fprintf_unfiltered (tmp_error_stream
,
2750 "Cannot insert breakpoint %d.\n",
2752 fprintf_unfiltered (tmp_error_stream
,
2753 "Temporarily disabling shared "
2754 "library breakpoints:\n");
2756 *disabled_breaks
= 1;
2757 fprintf_unfiltered (tmp_error_stream
,
2758 "breakpoint #%d\n", bl
->owner
->number
);
2763 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2765 *hw_breakpoint_error
= 1;
2766 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2767 fprintf_unfiltered (tmp_error_stream
,
2768 "Cannot insert hardware breakpoint %d%s",
2770 bp_excpt
.message
? ":" : ".\n");
2771 if (bp_excpt
.message
!= NULL
)
2772 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2777 if (bp_excpt
.message
== NULL
)
2780 = memory_error_message (TARGET_XFER_E_IO
,
2781 bl
->gdbarch
, bl
->address
);
2783 fprintf_unfiltered (tmp_error_stream
,
2784 "Cannot insert breakpoint %d.\n"
2786 bl
->owner
->number
, message
.c_str ());
2790 fprintf_unfiltered (tmp_error_stream
,
2791 "Cannot insert breakpoint %d: %s\n",
2806 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2807 /* NOTE drow/2003-09-08: This state only exists for removing
2808 watchpoints. It's not clear that it's necessary... */
2809 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2813 gdb_assert (bl
->owner
->ops
!= NULL
2814 && bl
->owner
->ops
->insert_location
!= NULL
);
2816 val
= bl
->owner
->ops
->insert_location (bl
);
2818 /* If trying to set a read-watchpoint, and it turns out it's not
2819 supported, try emulating one with an access watchpoint. */
2820 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2822 struct bp_location
*loc
, **loc_temp
;
2824 /* But don't try to insert it, if there's already another
2825 hw_access location that would be considered a duplicate
2827 ALL_BP_LOCATIONS (loc
, loc_temp
)
2829 && loc
->watchpoint_type
== hw_access
2830 && watchpoint_locations_match (bl
, loc
))
2834 bl
->target_info
= loc
->target_info
;
2835 bl
->watchpoint_type
= hw_access
;
2842 bl
->watchpoint_type
= hw_access
;
2843 val
= bl
->owner
->ops
->insert_location (bl
);
2846 /* Back to the original value. */
2847 bl
->watchpoint_type
= hw_read
;
2851 bl
->inserted
= (val
== 0);
2854 else if (bl
->owner
->type
== bp_catchpoint
)
2858 gdb_assert (bl
->owner
->ops
!= NULL
2859 && bl
->owner
->ops
->insert_location
!= NULL
);
2861 val
= bl
->owner
->ops
->insert_location (bl
);
2864 bl
->owner
->enable_state
= bp_disabled
;
2868 Error inserting catchpoint %d: Your system does not support this type\n\
2869 of catchpoint."), bl
->owner
->number
);
2871 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2874 bl
->inserted
= (val
== 0);
2876 /* We've already printed an error message if there was a problem
2877 inserting this catchpoint, and we've disabled the catchpoint,
2878 so just return success. */
2885 /* This function is called when program space PSPACE is about to be
2886 deleted. It takes care of updating breakpoints to not reference
2890 breakpoint_program_space_exit (struct program_space
*pspace
)
2892 struct breakpoint
*b
, *b_temp
;
2893 struct bp_location
*loc
, **loc_temp
;
2895 /* Remove any breakpoint that was set through this program space. */
2896 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2898 if (b
->pspace
== pspace
)
2899 delete_breakpoint (b
);
2902 /* Breakpoints set through other program spaces could have locations
2903 bound to PSPACE as well. Remove those. */
2904 ALL_BP_LOCATIONS (loc
, loc_temp
)
2906 struct bp_location
*tmp
;
2908 if (loc
->pspace
== pspace
)
2910 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2911 if (loc
->owner
->loc
== loc
)
2912 loc
->owner
->loc
= loc
->next
;
2914 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2915 if (tmp
->next
== loc
)
2917 tmp
->next
= loc
->next
;
2923 /* Now update the global location list to permanently delete the
2924 removed locations above. */
2925 update_global_location_list (UGLL_DONT_INSERT
);
2928 /* Make sure all breakpoints are inserted in inferior.
2929 Throws exception on any error.
2930 A breakpoint that is already inserted won't be inserted
2931 again, so calling this function twice is safe. */
2933 insert_breakpoints (void)
2935 for (breakpoint
*bpt
: all_breakpoints ())
2936 if (is_hardware_watchpoint (bpt
))
2938 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2940 update_watchpoint (w
, 0 /* don't reparse. */);
2943 /* Updating watchpoints creates new locations, so update the global
2944 location list. Explicitly tell ugll to insert locations and
2945 ignore breakpoints_always_inserted_mode. Also,
2946 update_global_location_list tries to "upgrade" software
2947 breakpoints to hardware breakpoints to handle "set breakpoint
2948 auto-hw", so we need to call it even if we don't have new
2950 update_global_location_list (UGLL_INSERT
);
2953 /* Invoke CALLBACK for each of bp_location. */
2956 iterate_over_bp_locations (gdb::function_view
<void (bp_location
*)> callback
)
2958 struct bp_location
*loc
, **loc_tmp
;
2960 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2966 /* This is used when we need to synch breakpoint conditions between GDB and the
2967 target. It is the case with deleting and disabling of breakpoints when using
2968 always-inserted mode. */
2971 update_inserted_breakpoint_locations (void)
2973 struct bp_location
*bl
, **blp_tmp
;
2976 int disabled_breaks
= 0;
2977 int hw_breakpoint_error
= 0;
2978 int hw_bp_details_reported
= 0;
2980 string_file tmp_error_stream
;
2982 /* Explicitly mark the warning -- this will only be printed if
2983 there was an error. */
2984 tmp_error_stream
.puts ("Warning:\n");
2986 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2988 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2990 /* We only want to update software breakpoints and hardware
2992 if (!is_breakpoint (bl
->owner
))
2995 /* We only want to update locations that are already inserted
2996 and need updating. This is to avoid unwanted insertion during
2997 deletion of breakpoints. */
2998 if (!bl
->inserted
|| !bl
->needs_update
)
3001 switch_to_program_space_and_thread (bl
->pspace
);
3003 /* For targets that support global breakpoints, there's no need
3004 to select an inferior to insert breakpoint to. In fact, even
3005 if we aren't attached to any process yet, we should still
3006 insert breakpoints. */
3007 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3008 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3011 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3012 &hw_breakpoint_error
, &hw_bp_details_reported
);
3019 target_terminal::ours_for_output ();
3020 error_stream (tmp_error_stream
);
3024 /* Used when starting or continuing the program. */
3027 insert_breakpoint_locations (void)
3029 struct bp_location
*bl
, **blp_tmp
;
3032 int disabled_breaks
= 0;
3033 int hw_breakpoint_error
= 0;
3034 int hw_bp_error_explained_already
= 0;
3036 string_file tmp_error_stream
;
3038 /* Explicitly mark the warning -- this will only be printed if
3039 there was an error. */
3040 tmp_error_stream
.puts ("Warning:\n");
3042 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3044 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3046 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3049 /* There is no point inserting thread-specific breakpoints if
3050 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3051 has BL->OWNER always non-NULL. */
3052 if (bl
->owner
->thread
!= -1
3053 && !valid_global_thread_id (bl
->owner
->thread
))
3056 switch_to_program_space_and_thread (bl
->pspace
);
3058 /* For targets that support global breakpoints, there's no need
3059 to select an inferior to insert breakpoint to. In fact, even
3060 if we aren't attached to any process yet, we should still
3061 insert breakpoints. */
3062 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3063 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3066 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3067 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3072 /* If we failed to insert all locations of a watchpoint, remove
3073 them, as half-inserted watchpoint is of limited use. */
3074 for (breakpoint
*bpt
: all_breakpoints ())
3076 int some_failed
= 0;
3077 struct bp_location
*loc
;
3079 if (!is_hardware_watchpoint (bpt
))
3082 if (!breakpoint_enabled (bpt
))
3085 if (bpt
->disposition
== disp_del_at_next_stop
)
3088 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3089 if (!loc
->inserted
&& should_be_inserted (loc
))
3096 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3098 remove_breakpoint (loc
);
3100 hw_breakpoint_error
= 1;
3101 tmp_error_stream
.printf ("Could not insert "
3102 "hardware watchpoint %d.\n",
3110 /* If a hardware breakpoint or watchpoint was inserted, add a
3111 message about possibly exhausted resources. */
3112 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3114 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3115 You may have requested too many hardware breakpoints/watchpoints.\n");
3117 target_terminal::ours_for_output ();
3118 error_stream (tmp_error_stream
);
3122 /* Used when the program stops.
3123 Returns zero if successful, or non-zero if there was a problem
3124 removing a breakpoint location. */
3127 remove_breakpoints (void)
3129 struct bp_location
*bl
, **blp_tmp
;
3132 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3134 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3135 val
|= remove_breakpoint (bl
);
3140 /* When a thread exits, remove breakpoints that are related to
3144 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3146 struct breakpoint
*b
, *b_tmp
;
3148 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3150 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3152 b
->disposition
= disp_del_at_next_stop
;
3154 printf_filtered (_("\
3155 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3156 b
->number
, print_thread_id (tp
));
3158 /* Hide it from the user. */
3164 /* See breakpoint.h. */
3167 remove_breakpoints_inf (inferior
*inf
)
3169 struct bp_location
*bl
, **blp_tmp
;
3172 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3174 if (bl
->pspace
!= inf
->pspace
)
3177 if (bl
->inserted
&& !bl
->target_info
.persist
)
3179 val
= remove_breakpoint (bl
);
3186 static int internal_breakpoint_number
= -1;
3188 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3189 If INTERNAL is non-zero, the breakpoint number will be populated
3190 from internal_breakpoint_number and that variable decremented.
3191 Otherwise the breakpoint number will be populated from
3192 breakpoint_count and that value incremented. Internal breakpoints
3193 do not set the internal var bpnum. */
3195 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3198 b
->number
= internal_breakpoint_number
--;
3201 set_breakpoint_count (breakpoint_count
+ 1);
3202 b
->number
= breakpoint_count
;
3206 static struct breakpoint
*
3207 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3208 CORE_ADDR address
, enum bptype type
,
3209 const struct breakpoint_ops
*ops
)
3211 symtab_and_line sal
;
3213 sal
.section
= find_pc_overlay (sal
.pc
);
3214 sal
.pspace
= current_program_space
;
3216 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3217 b
->number
= internal_breakpoint_number
--;
3218 b
->disposition
= disp_donttouch
;
3223 static const char *const longjmp_names
[] =
3225 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3227 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3229 /* Per-objfile data private to breakpoint.c. */
3230 struct breakpoint_objfile_data
3232 /* Minimal symbol for "_ovly_debug_event" (if any). */
3233 struct bound_minimal_symbol overlay_msym
{};
3235 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3236 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3238 /* True if we have looked for longjmp probes. */
3239 int longjmp_searched
= 0;
3241 /* SystemTap probe points for longjmp (if any). These are non-owning
3243 std::vector
<probe
*> longjmp_probes
;
3245 /* Minimal symbol for "std::terminate()" (if any). */
3246 struct bound_minimal_symbol terminate_msym
{};
3248 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3249 struct bound_minimal_symbol exception_msym
{};
3251 /* True if we have looked for exception probes. */
3252 int exception_searched
= 0;
3254 /* SystemTap probe points for unwinding (if any). These are non-owning
3256 std::vector
<probe
*> exception_probes
;
3259 static const struct objfile_key
<breakpoint_objfile_data
>
3260 breakpoint_objfile_key
;
3262 /* Minimal symbol not found sentinel. */
3263 static struct minimal_symbol msym_not_found
;
3265 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3268 msym_not_found_p (const struct minimal_symbol
*msym
)
3270 return msym
== &msym_not_found
;
3273 /* Return per-objfile data needed by breakpoint.c.
3274 Allocate the data if necessary. */
3276 static struct breakpoint_objfile_data
*
3277 get_breakpoint_objfile_data (struct objfile
*objfile
)
3279 struct breakpoint_objfile_data
*bp_objfile_data
;
3281 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3282 if (bp_objfile_data
== NULL
)
3283 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3284 return bp_objfile_data
;
3288 create_overlay_event_breakpoint (void)
3290 const char *const func_name
= "_ovly_debug_event";
3292 for (objfile
*objfile
: current_program_space
->objfiles ())
3294 struct breakpoint
*b
;
3295 struct breakpoint_objfile_data
*bp_objfile_data
;
3297 struct explicit_location explicit_loc
;
3299 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3301 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3304 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3306 struct bound_minimal_symbol m
;
3308 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3309 if (m
.minsym
== NULL
)
3311 /* Avoid future lookups in this objfile. */
3312 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3315 bp_objfile_data
->overlay_msym
= m
;
3318 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3319 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3321 &internal_breakpoint_ops
);
3322 initialize_explicit_location (&explicit_loc
);
3323 explicit_loc
.function_name
= ASTRDUP (func_name
);
3324 b
->location
= new_explicit_location (&explicit_loc
);
3326 if (overlay_debugging
== ovly_auto
)
3328 b
->enable_state
= bp_enabled
;
3329 overlay_events_enabled
= 1;
3333 b
->enable_state
= bp_disabled
;
3334 overlay_events_enabled
= 0;
3339 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3340 true if a breakpoint was installed. */
3343 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3345 struct gdbarch
*gdbarch
= objfile
->arch ();
3346 struct breakpoint_objfile_data
*bp_objfile_data
3347 = get_breakpoint_objfile_data (objfile
);
3349 if (!bp_objfile_data
->longjmp_searched
)
3351 std::vector
<probe
*> ret
3352 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3356 /* We are only interested in checking one element. */
3359 if (!p
->can_evaluate_arguments ())
3361 /* We cannot use the probe interface here,
3362 because it does not know how to evaluate
3367 bp_objfile_data
->longjmp_probes
= ret
;
3368 bp_objfile_data
->longjmp_searched
= 1;
3371 if (bp_objfile_data
->longjmp_probes
.empty ())
3374 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3376 struct breakpoint
*b
;
3378 b
= create_internal_breakpoint (gdbarch
,
3379 p
->get_relocated_address (objfile
),
3381 &internal_breakpoint_ops
);
3382 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3383 b
->enable_state
= bp_disabled
;
3389 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3390 Return true if at least one breakpoint was installed. */
3393 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3395 struct gdbarch
*gdbarch
= objfile
->arch ();
3396 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3399 struct breakpoint_objfile_data
*bp_objfile_data
3400 = get_breakpoint_objfile_data (objfile
);
3401 unsigned int installed_bp
= 0;
3403 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3405 struct breakpoint
*b
;
3406 const char *func_name
;
3408 struct explicit_location explicit_loc
;
3410 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3413 func_name
= longjmp_names
[i
];
3414 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3416 struct bound_minimal_symbol m
;
3418 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3419 if (m
.minsym
== NULL
)
3421 /* Prevent future lookups in this objfile. */
3422 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3425 bp_objfile_data
->longjmp_msym
[i
] = m
;
3428 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3429 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3430 &internal_breakpoint_ops
);
3431 initialize_explicit_location (&explicit_loc
);
3432 explicit_loc
.function_name
= ASTRDUP (func_name
);
3433 b
->location
= new_explicit_location (&explicit_loc
);
3434 b
->enable_state
= bp_disabled
;
3438 return installed_bp
> 0;
3441 /* Create a master longjmp breakpoint. */
3444 create_longjmp_master_breakpoint (void)
3446 scoped_restore_current_program_space restore_pspace
;
3448 for (struct program_space
*pspace
: program_spaces
)
3450 set_current_program_space (pspace
);
3452 for (objfile
*obj
: current_program_space
->objfiles ())
3454 /* Skip separate debug object, it's handled in the loop below. */
3455 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3458 /* Try a probe kind breakpoint on main objfile. */
3459 if (create_longjmp_master_breakpoint_probe (obj
))
3462 /* Try longjmp_names kind breakpoints on main and separate_debug
3464 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3465 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3471 /* Create a master std::terminate breakpoint. */
3473 create_std_terminate_master_breakpoint (void)
3475 const char *const func_name
= "std::terminate()";
3477 scoped_restore_current_program_space restore_pspace
;
3479 for (struct program_space
*pspace
: program_spaces
)
3483 set_current_program_space (pspace
);
3485 for (objfile
*objfile
: current_program_space
->objfiles ())
3487 struct breakpoint
*b
;
3488 struct breakpoint_objfile_data
*bp_objfile_data
;
3489 struct explicit_location explicit_loc
;
3491 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3493 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3496 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3498 struct bound_minimal_symbol m
;
3500 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3501 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3502 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3504 /* Prevent future lookups in this objfile. */
3505 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3508 bp_objfile_data
->terminate_msym
= m
;
3511 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3512 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3513 bp_std_terminate_master
,
3514 &internal_breakpoint_ops
);
3515 initialize_explicit_location (&explicit_loc
);
3516 explicit_loc
.function_name
= ASTRDUP (func_name
);
3517 b
->location
= new_explicit_location (&explicit_loc
);
3518 b
->enable_state
= bp_disabled
;
3523 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3524 probe. Return true if a breakpoint was installed. */
3527 create_exception_master_breakpoint_probe (objfile
*objfile
)
3529 struct breakpoint
*b
;
3530 struct gdbarch
*gdbarch
;
3531 struct breakpoint_objfile_data
*bp_objfile_data
;
3533 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3535 /* We prefer the SystemTap probe point if it exists. */
3536 if (!bp_objfile_data
->exception_searched
)
3538 std::vector
<probe
*> ret
3539 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3543 /* We are only interested in checking one element. */
3546 if (!p
->can_evaluate_arguments ())
3548 /* We cannot use the probe interface here, because it does
3549 not know how to evaluate arguments. */
3553 bp_objfile_data
->exception_probes
= ret
;
3554 bp_objfile_data
->exception_searched
= 1;
3557 if (bp_objfile_data
->exception_probes
.empty ())
3560 gdbarch
= objfile
->arch ();
3562 for (probe
*p
: bp_objfile_data
->exception_probes
)
3564 b
= create_internal_breakpoint (gdbarch
,
3565 p
->get_relocated_address (objfile
),
3566 bp_exception_master
,
3567 &internal_breakpoint_ops
);
3568 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3569 b
->enable_state
= bp_disabled
;
3575 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3576 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3579 create_exception_master_breakpoint_hook (objfile
*objfile
)
3581 const char *const func_name
= "_Unwind_DebugHook";
3582 struct breakpoint
*b
;
3583 struct gdbarch
*gdbarch
;
3584 struct breakpoint_objfile_data
*bp_objfile_data
;
3586 struct explicit_location explicit_loc
;
3588 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3590 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3593 gdbarch
= objfile
->arch ();
3595 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3597 struct bound_minimal_symbol debug_hook
;
3599 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3600 if (debug_hook
.minsym
== NULL
)
3602 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3606 bp_objfile_data
->exception_msym
= debug_hook
;
3609 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3610 addr
= gdbarch_convert_from_func_ptr_addr
3611 (gdbarch
, addr
, current_inferior ()->top_target ());
3612 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3613 &internal_breakpoint_ops
);
3614 initialize_explicit_location (&explicit_loc
);
3615 explicit_loc
.function_name
= ASTRDUP (func_name
);
3616 b
->location
= new_explicit_location (&explicit_loc
);
3617 b
->enable_state
= bp_disabled
;
3622 /* Install a master breakpoint on the unwinder's debug hook. */
3625 create_exception_master_breakpoint (void)
3627 for (objfile
*obj
: current_program_space
->objfiles ())
3629 /* Skip separate debug object. */
3630 if (obj
->separate_debug_objfile_backlink
)
3633 /* Try a probe kind breakpoint. */
3634 if (create_exception_master_breakpoint_probe (obj
))
3637 /* Iterate over main and separate debug objects and try an
3638 _Unwind_DebugHook kind breakpoint. */
3639 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3640 if (create_exception_master_breakpoint_hook (debug_objfile
))
3645 /* Does B have a location spec? */
3648 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3650 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3654 update_breakpoints_after_exec (void)
3656 struct breakpoint
*b
, *b_tmp
;
3657 struct bp_location
*bploc
, **bplocp_tmp
;
3659 /* We're about to delete breakpoints from GDB's lists. If the
3660 INSERTED flag is true, GDB will try to lift the breakpoints by
3661 writing the breakpoints' "shadow contents" back into memory. The
3662 "shadow contents" are NOT valid after an exec, so GDB should not
3663 do that. Instead, the target is responsible from marking
3664 breakpoints out as soon as it detects an exec. We don't do that
3665 here instead, because there may be other attempts to delete
3666 breakpoints after detecting an exec and before reaching here. */
3667 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3668 if (bploc
->pspace
== current_program_space
)
3669 gdb_assert (!bploc
->inserted
);
3671 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3673 if (b
->pspace
!= current_program_space
)
3676 /* Solib breakpoints must be explicitly reset after an exec(). */
3677 if (b
->type
== bp_shlib_event
)
3679 delete_breakpoint (b
);
3683 /* JIT breakpoints must be explicitly reset after an exec(). */
3684 if (b
->type
== bp_jit_event
)
3686 delete_breakpoint (b
);
3690 /* Thread event breakpoints must be set anew after an exec(),
3691 as must overlay event and longjmp master breakpoints. */
3692 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3693 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3694 || b
->type
== bp_exception_master
)
3696 delete_breakpoint (b
);
3700 /* Step-resume breakpoints are meaningless after an exec(). */
3701 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3703 delete_breakpoint (b
);
3707 /* Just like single-step breakpoints. */
3708 if (b
->type
== bp_single_step
)
3710 delete_breakpoint (b
);
3714 /* Longjmp and longjmp-resume breakpoints are also meaningless
3716 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3717 || b
->type
== bp_longjmp_call_dummy
3718 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3720 delete_breakpoint (b
);
3724 if (b
->type
== bp_catchpoint
)
3726 /* For now, none of the bp_catchpoint breakpoints need to
3727 do anything at this point. In the future, if some of
3728 the catchpoints need to something, we will need to add
3729 a new method, and call this method from here. */
3733 /* bp_finish is a special case. The only way we ought to be able
3734 to see one of these when an exec() has happened, is if the user
3735 caught a vfork, and then said "finish". Ordinarily a finish just
3736 carries them to the call-site of the current callee, by setting
3737 a temporary bp there and resuming. But in this case, the finish
3738 will carry them entirely through the vfork & exec.
3740 We don't want to allow a bp_finish to remain inserted now. But
3741 we can't safely delete it, 'cause finish_command has a handle to
3742 the bp on a bpstat, and will later want to delete it. There's a
3743 chance (and I've seen it happen) that if we delete the bp_finish
3744 here, that its storage will get reused by the time finish_command
3745 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3746 We really must allow finish_command to delete a bp_finish.
3748 In the absence of a general solution for the "how do we know
3749 it's safe to delete something others may have handles to?"
3750 problem, what we'll do here is just uninsert the bp_finish, and
3751 let finish_command delete it.
3753 (We know the bp_finish is "doomed" in the sense that it's
3754 momentary, and will be deleted as soon as finish_command sees
3755 the inferior stopped. So it doesn't matter that the bp's
3756 address is probably bogus in the new a.out, unlike e.g., the
3757 solib breakpoints.) */
3759 if (b
->type
== bp_finish
)
3764 /* Without a symbolic address, we have little hope of the
3765 pre-exec() address meaning the same thing in the post-exec()
3767 if (breakpoint_event_location_empty_p (b
))
3769 delete_breakpoint (b
);
3776 detach_breakpoints (ptid_t ptid
)
3778 struct bp_location
*bl
, **blp_tmp
;
3780 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3781 struct inferior
*inf
= current_inferior ();
3783 if (ptid
.pid () == inferior_ptid
.pid ())
3784 error (_("Cannot detach breakpoints of inferior_ptid"));
3786 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3787 inferior_ptid
= ptid
;
3788 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3790 if (bl
->pspace
!= inf
->pspace
)
3793 /* This function must physically remove breakpoints locations
3794 from the specified ptid, without modifying the breakpoint
3795 package's state. Locations of type bp_loc_other are only
3796 maintained at GDB side. So, there is no need to remove
3797 these bp_loc_other locations. Moreover, removing these
3798 would modify the breakpoint package's state. */
3799 if (bl
->loc_type
== bp_loc_other
)
3803 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3809 /* Remove the breakpoint location BL from the current address space.
3810 Note that this is used to detach breakpoints from a child fork.
3811 When we get here, the child isn't in the inferior list, and neither
3812 do we have objects to represent its address space --- we should
3813 *not* look at bl->pspace->aspace here. */
3816 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3820 /* BL is never in moribund_locations by our callers. */
3821 gdb_assert (bl
->owner
!= NULL
);
3823 /* The type of none suggests that owner is actually deleted.
3824 This should not ever happen. */
3825 gdb_assert (bl
->owner
->type
!= bp_none
);
3827 if (bl
->loc_type
== bp_loc_software_breakpoint
3828 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3830 /* "Normal" instruction breakpoint: either the standard
3831 trap-instruction bp (bp_breakpoint), or a
3832 bp_hardware_breakpoint. */
3834 /* First check to see if we have to handle an overlay. */
3835 if (overlay_debugging
== ovly_off
3836 || bl
->section
== NULL
3837 || !(section_is_overlay (bl
->section
)))
3839 /* No overlay handling: just remove the breakpoint. */
3841 /* If we're trying to uninsert a memory breakpoint that we
3842 know is set in a dynamic object that is marked
3843 shlib_disabled, then either the dynamic object was
3844 removed with "remove-symbol-file" or with
3845 "nosharedlibrary". In the former case, we don't know
3846 whether another dynamic object might have loaded over the
3847 breakpoint's address -- the user might well let us know
3848 about it next with add-symbol-file (the whole point of
3849 add-symbol-file is letting the user manually maintain a
3850 list of dynamically loaded objects). If we have the
3851 breakpoint's shadow memory, that is, this is a software
3852 breakpoint managed by GDB, check whether the breakpoint
3853 is still inserted in memory, to avoid overwriting wrong
3854 code with stale saved shadow contents. Note that HW
3855 breakpoints don't have shadow memory, as they're
3856 implemented using a mechanism that is not dependent on
3857 being able to modify the target's memory, and as such
3858 they should always be removed. */
3859 if (bl
->shlib_disabled
3860 && bl
->target_info
.shadow_len
!= 0
3861 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3864 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3868 /* This breakpoint is in an overlay section.
3869 Did we set a breakpoint at the LMA? */
3870 if (!overlay_events_enabled
)
3872 /* Yes -- overlay event support is not active, so we
3873 should have set a breakpoint at the LMA. Remove it.
3875 /* Ignore any failures: if the LMA is in ROM, we will
3876 have already warned when we failed to insert it. */
3877 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3878 target_remove_hw_breakpoint (bl
->gdbarch
,
3879 &bl
->overlay_target_info
);
3881 target_remove_breakpoint (bl
->gdbarch
,
3882 &bl
->overlay_target_info
,
3885 /* Did we set a breakpoint at the VMA?
3886 If so, we will have marked the breakpoint 'inserted'. */
3889 /* Yes -- remove it. Previously we did not bother to
3890 remove the breakpoint if the section had been
3891 unmapped, but let's not rely on that being safe. We
3892 don't know what the overlay manager might do. */
3894 /* However, we should remove *software* breakpoints only
3895 if the section is still mapped, or else we overwrite
3896 wrong code with the saved shadow contents. */
3897 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3898 || section_is_mapped (bl
->section
))
3899 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3905 /* No -- not inserted, so no need to remove. No error. */
3910 /* In some cases, we might not be able to remove a breakpoint in
3911 a shared library that has already been removed, but we have
3912 not yet processed the shlib unload event. Similarly for an
3913 unloaded add-symbol-file object - the user might not yet have
3914 had the chance to remove-symbol-file it. shlib_disabled will
3915 be set if the library/object has already been removed, but
3916 the breakpoint hasn't been uninserted yet, e.g., after
3917 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3918 always-inserted mode. */
3920 && (bl
->loc_type
== bp_loc_software_breakpoint
3921 && (bl
->shlib_disabled
3922 || solib_name_from_address (bl
->pspace
, bl
->address
)
3923 || shared_objfile_contains_address_p (bl
->pspace
,
3929 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3931 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3933 gdb_assert (bl
->owner
->ops
!= NULL
3934 && bl
->owner
->ops
->remove_location
!= NULL
);
3936 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3937 bl
->owner
->ops
->remove_location (bl
, reason
);
3939 /* Failure to remove any of the hardware watchpoints comes here. */
3940 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3941 warning (_("Could not remove hardware watchpoint %d."),
3944 else if (bl
->owner
->type
== bp_catchpoint
3945 && breakpoint_enabled (bl
->owner
)
3948 gdb_assert (bl
->owner
->ops
!= NULL
3949 && bl
->owner
->ops
->remove_location
!= NULL
);
3951 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3955 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3962 remove_breakpoint (struct bp_location
*bl
)
3964 /* BL is never in moribund_locations by our callers. */
3965 gdb_assert (bl
->owner
!= NULL
);
3967 /* The type of none suggests that owner is actually deleted.
3968 This should not ever happen. */
3969 gdb_assert (bl
->owner
->type
!= bp_none
);
3971 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3973 switch_to_program_space_and_thread (bl
->pspace
);
3975 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3978 /* Clear the "inserted" flag in all breakpoints. */
3981 mark_breakpoints_out (void)
3983 struct bp_location
*bl
, **blp_tmp
;
3985 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3986 if (bl
->pspace
== current_program_space
)
3990 /* Clear the "inserted" flag in all breakpoints and delete any
3991 breakpoints which should go away between runs of the program.
3993 Plus other such housekeeping that has to be done for breakpoints
3996 Note: this function gets called at the end of a run (by
3997 generic_mourn_inferior) and when a run begins (by
3998 init_wait_for_inferior). */
4003 breakpoint_init_inferior (enum inf_context context
)
4005 struct breakpoint
*b
, *b_tmp
;
4006 struct program_space
*pspace
= current_program_space
;
4008 /* If breakpoint locations are shared across processes, then there's
4010 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4013 mark_breakpoints_out ();
4015 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4017 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4023 case bp_longjmp_call_dummy
:
4025 /* If the call dummy breakpoint is at the entry point it will
4026 cause problems when the inferior is rerun, so we better get
4029 case bp_watchpoint_scope
:
4031 /* Also get rid of scope breakpoints. */
4033 case bp_shlib_event
:
4035 /* Also remove solib event breakpoints. Their addresses may
4036 have changed since the last time we ran the program.
4037 Actually we may now be debugging against different target;
4038 and so the solib backend that installed this breakpoint may
4039 not be used in by the target. E.g.,
4041 (gdb) file prog-linux
4042 (gdb) run # native linux target
4045 (gdb) file prog-win.exe
4046 (gdb) tar rem :9999 # remote Windows gdbserver.
4049 case bp_step_resume
:
4051 /* Also remove step-resume breakpoints. */
4053 case bp_single_step
:
4055 /* Also remove single-step breakpoints. */
4057 delete_breakpoint (b
);
4061 case bp_hardware_watchpoint
:
4062 case bp_read_watchpoint
:
4063 case bp_access_watchpoint
:
4065 struct watchpoint
*w
= (struct watchpoint
*) b
;
4067 /* Likewise for watchpoints on local expressions. */
4068 if (w
->exp_valid_block
!= NULL
)
4069 delete_breakpoint (b
);
4072 /* Get rid of existing locations, which are no longer
4073 valid. New ones will be created in
4074 update_watchpoint, when the inferior is restarted.
4075 The next update_global_location_list call will
4076 garbage collect them. */
4079 if (context
== inf_starting
)
4081 /* Reset val field to force reread of starting value in
4082 insert_breakpoints. */
4083 w
->val
.reset (nullptr);
4084 w
->val_valid
= false;
4094 /* Get rid of the moribund locations. */
4095 for (bp_location
*bl
: moribund_locations
)
4096 decref_bp_location (&bl
);
4097 moribund_locations
.clear ();
4100 /* These functions concern about actual breakpoints inserted in the
4101 target --- to e.g. check if we need to do decr_pc adjustment or if
4102 we need to hop over the bkpt --- so we check for address space
4103 match, not program space. */
4105 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4106 exists at PC. It returns ordinary_breakpoint_here if it's an
4107 ordinary breakpoint, or permanent_breakpoint_here if it's a
4108 permanent breakpoint.
4109 - When continuing from a location with an ordinary breakpoint, we
4110 actually single step once before calling insert_breakpoints.
4111 - When continuing from a location with a permanent breakpoint, we
4112 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4113 the target, to advance the PC past the breakpoint. */
4115 enum breakpoint_here
4116 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4118 struct bp_location
*bl
, **blp_tmp
;
4119 int any_breakpoint_here
= 0;
4121 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4123 if (bl
->loc_type
!= bp_loc_software_breakpoint
4124 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4127 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4128 if ((breakpoint_enabled (bl
->owner
)
4130 && breakpoint_location_address_match (bl
, aspace
, pc
))
4132 if (overlay_debugging
4133 && section_is_overlay (bl
->section
)
4134 && !section_is_mapped (bl
->section
))
4135 continue; /* unmapped overlay -- can't be a match */
4136 else if (bl
->permanent
)
4137 return permanent_breakpoint_here
;
4139 any_breakpoint_here
= 1;
4143 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4146 /* See breakpoint.h. */
4149 breakpoint_in_range_p (const address_space
*aspace
,
4150 CORE_ADDR addr
, ULONGEST len
)
4152 struct bp_location
*bl
, **blp_tmp
;
4154 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4156 if (bl
->loc_type
!= bp_loc_software_breakpoint
4157 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4160 if ((breakpoint_enabled (bl
->owner
)
4162 && breakpoint_location_address_range_overlap (bl
, aspace
,
4165 if (overlay_debugging
4166 && section_is_overlay (bl
->section
)
4167 && !section_is_mapped (bl
->section
))
4169 /* Unmapped overlay -- can't be a match. */
4180 /* Return true if there's a moribund breakpoint at PC. */
4183 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4185 for (bp_location
*loc
: moribund_locations
)
4186 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4192 /* Returns non-zero iff BL is inserted at PC, in address space
4196 bp_location_inserted_here_p (struct bp_location
*bl
,
4197 const address_space
*aspace
, CORE_ADDR pc
)
4200 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4203 if (overlay_debugging
4204 && section_is_overlay (bl
->section
)
4205 && !section_is_mapped (bl
->section
))
4206 return 0; /* unmapped overlay -- can't be a match */
4213 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4216 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4218 struct bp_location
**blp
, **blp_tmp
= NULL
;
4220 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4222 struct bp_location
*bl
= *blp
;
4224 if (bl
->loc_type
!= bp_loc_software_breakpoint
4225 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4228 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4234 /* This function returns non-zero iff there is a software breakpoint
4238 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4241 struct bp_location
**blp
, **blp_tmp
= NULL
;
4243 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4245 struct bp_location
*bl
= *blp
;
4247 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4250 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4257 /* See breakpoint.h. */
4260 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4263 struct bp_location
**blp
, **blp_tmp
= NULL
;
4265 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4267 struct bp_location
*bl
= *blp
;
4269 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4272 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4280 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4281 CORE_ADDR addr
, ULONGEST len
)
4283 for (breakpoint
*bpt
: all_breakpoints ())
4285 struct bp_location
*loc
;
4287 if (bpt
->type
!= bp_hardware_watchpoint
4288 && bpt
->type
!= bp_access_watchpoint
)
4291 if (!breakpoint_enabled (bpt
))
4294 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4295 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4299 /* Check for intersection. */
4300 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4301 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4309 /* See breakpoint.h. */
4312 is_catchpoint (struct breakpoint
*b
)
4314 return (b
->type
== bp_catchpoint
);
4317 /* Clear a bpstat so that it says we are not at any breakpoint.
4318 Also free any storage that is part of a bpstat. */
4321 bpstat_clear (bpstat
*bsp
)
4338 bpstats::bpstats (const bpstats
&other
)
4340 bp_location_at (other
.bp_location_at
),
4341 breakpoint_at (other
.breakpoint_at
),
4342 commands (other
.commands
),
4343 print (other
.print
),
4345 print_it (other
.print_it
)
4347 if (other
.old_val
!= NULL
)
4348 old_val
= release_value (value_copy (other
.old_val
.get ()));
4351 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4352 is part of the bpstat is copied as well. */
4355 bpstat_copy (bpstat bs
)
4359 bpstat retval
= NULL
;
4364 for (; bs
!= NULL
; bs
= bs
->next
)
4366 tmp
= new bpstats (*bs
);
4369 /* This is the first thing in the chain. */
4379 /* Find the bpstat associated with this breakpoint. */
4382 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4387 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4389 if (bsp
->breakpoint_at
== breakpoint
)
4395 /* See breakpoint.h. */
4398 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4400 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4402 if (bsp
->breakpoint_at
== NULL
)
4404 /* A moribund location can never explain a signal other than
4406 if (sig
== GDB_SIGNAL_TRAP
)
4411 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4420 /* Put in *NUM the breakpoint number of the first breakpoint we are
4421 stopped at. *BSP upon return is a bpstat which points to the
4422 remaining breakpoints stopped at (but which is not guaranteed to be
4423 good for anything but further calls to bpstat_num).
4425 Return 0 if passed a bpstat which does not indicate any breakpoints.
4426 Return -1 if stopped at a breakpoint that has been deleted since
4428 Return 1 otherwise. */
4431 bpstat_num (bpstat
*bsp
, int *num
)
4433 struct breakpoint
*b
;
4436 return 0; /* No more breakpoint values */
4438 /* We assume we'll never have several bpstats that correspond to a
4439 single breakpoint -- otherwise, this function might return the
4440 same number more than once and this will look ugly. */
4441 b
= (*bsp
)->breakpoint_at
;
4442 *bsp
= (*bsp
)->next
;
4444 return -1; /* breakpoint that's been deleted since */
4446 *num
= b
->number
; /* We have its number */
4450 /* See breakpoint.h. */
4453 bpstat_clear_actions (void)
4457 if (inferior_ptid
== null_ptid
)
4460 thread_info
*tp
= inferior_thread ();
4461 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4463 bs
->commands
= NULL
;
4464 bs
->old_val
.reset (nullptr);
4468 /* Called when a command is about to proceed the inferior. */
4471 breakpoint_about_to_proceed (void)
4473 if (inferior_ptid
!= null_ptid
)
4475 struct thread_info
*tp
= inferior_thread ();
4477 /* Allow inferior function calls in breakpoint commands to not
4478 interrupt the command list. When the call finishes
4479 successfully, the inferior will be standing at the same
4480 breakpoint as if nothing happened. */
4481 if (tp
->control
.in_infcall
)
4485 breakpoint_proceeded
= 1;
4488 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4489 or its equivalent. */
4492 command_line_is_silent (struct command_line
*cmd
)
4494 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4497 /* Execute all the commands associated with all the breakpoints at
4498 this location. Any of these commands could cause the process to
4499 proceed beyond this point, etc. We look out for such changes by
4500 checking the global "breakpoint_proceeded" after each command.
4502 Returns true if a breakpoint command resumed the inferior. In that
4503 case, it is the caller's responsibility to recall it again with the
4504 bpstat of the current thread. */
4507 bpstat_do_actions_1 (bpstat
*bsp
)
4512 /* Avoid endless recursion if a `source' command is contained
4514 if (executing_breakpoint_commands
)
4517 scoped_restore save_executing
4518 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4520 scoped_restore preventer
= prevent_dont_repeat ();
4522 /* This pointer will iterate over the list of bpstat's. */
4525 breakpoint_proceeded
= 0;
4526 for (; bs
!= NULL
; bs
= bs
->next
)
4528 struct command_line
*cmd
= NULL
;
4530 /* Take ownership of the BSP's command tree, if it has one.
4532 The command tree could legitimately contain commands like
4533 'step' and 'next', which call clear_proceed_status, which
4534 frees stop_bpstat's command tree. To make sure this doesn't
4535 free the tree we're executing out from under us, we need to
4536 take ownership of the tree ourselves. Since a given bpstat's
4537 commands are only executed once, we don't need to copy it; we
4538 can clear the pointer in the bpstat, and make sure we free
4539 the tree when we're done. */
4540 counted_command_line ccmd
= bs
->commands
;
4541 bs
->commands
= NULL
;
4544 if (command_line_is_silent (cmd
))
4546 /* The action has been already done by bpstat_stop_status. */
4552 execute_control_command (cmd
);
4554 if (breakpoint_proceeded
)
4560 if (breakpoint_proceeded
)
4562 if (current_ui
->async
)
4563 /* If we are in async mode, then the target might be still
4564 running, not stopped at any breakpoint, so nothing for
4565 us to do here -- just return to the event loop. */
4568 /* In sync mode, when execute_control_command returns
4569 we're already standing on the next breakpoint.
4570 Breakpoint commands for that stop were not run, since
4571 execute_command does not run breakpoint commands --
4572 only command_line_handler does, but that one is not
4573 involved in execution of breakpoint commands. So, we
4574 can now execute breakpoint commands. It should be
4575 noted that making execute_command do bpstat actions is
4576 not an option -- in this case we'll have recursive
4577 invocation of bpstat for each breakpoint with a
4578 command, and can easily blow up GDB stack. Instead, we
4579 return true, which will trigger the caller to recall us
4580 with the new stop_bpstat. */
4588 /* Helper for bpstat_do_actions. Get the current thread, if there's
4589 one, is alive and has execution. Return NULL otherwise. */
4591 static thread_info
*
4592 get_bpstat_thread ()
4594 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4597 thread_info
*tp
= inferior_thread ();
4598 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4604 bpstat_do_actions (void)
4606 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4609 /* Do any commands attached to breakpoint we are stopped at. */
4610 while ((tp
= get_bpstat_thread ()) != NULL
)
4612 /* Since in sync mode, bpstat_do_actions may resume the
4613 inferior, and only return when it is stopped at the next
4614 breakpoint, we keep doing breakpoint actions until it returns
4615 false to indicate the inferior was not resumed. */
4616 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4620 cleanup_if_error
.release ();
4623 /* Print out the (old or new) value associated with a watchpoint. */
4626 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4629 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4632 struct value_print_options opts
;
4633 get_user_print_options (&opts
);
4634 value_print (val
, stream
, &opts
);
4638 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4639 debugging multiple threads. */
4642 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4644 if (uiout
->is_mi_like_p ())
4649 if (show_thread_that_caused_stop ())
4652 struct thread_info
*thr
= inferior_thread ();
4654 uiout
->text ("Thread ");
4655 uiout
->field_string ("thread-id", print_thread_id (thr
));
4657 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4660 uiout
->text (" \"");
4661 uiout
->field_string ("name", name
);
4665 uiout
->text (" hit ");
4669 /* Generic routine for printing messages indicating why we
4670 stopped. The behavior of this function depends on the value
4671 'print_it' in the bpstat structure. Under some circumstances we
4672 may decide not to print anything here and delegate the task to
4675 static enum print_stop_action
4676 print_bp_stop_message (bpstat bs
)
4678 switch (bs
->print_it
)
4681 /* Nothing should be printed for this bpstat entry. */
4682 return PRINT_UNKNOWN
;
4686 /* We still want to print the frame, but we already printed the
4687 relevant messages. */
4688 return PRINT_SRC_AND_LOC
;
4691 case print_it_normal
:
4693 struct breakpoint
*b
= bs
->breakpoint_at
;
4695 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4696 which has since been deleted. */
4698 return PRINT_UNKNOWN
;
4700 /* Normal case. Call the breakpoint's print_it method. */
4701 return b
->ops
->print_it (bs
);
4706 internal_error (__FILE__
, __LINE__
,
4707 _("print_bp_stop_message: unrecognized enum value"));
4712 /* A helper function that prints a shared library stopped event. */
4715 print_solib_event (int is_catchpoint
)
4717 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4718 bool any_added
= !current_program_space
->added_solibs
.empty ();
4722 if (any_added
|| any_deleted
)
4723 current_uiout
->text (_("Stopped due to shared library event:\n"));
4725 current_uiout
->text (_("Stopped due to shared library event (no "
4726 "libraries added or removed)\n"));
4729 if (current_uiout
->is_mi_like_p ())
4730 current_uiout
->field_string ("reason",
4731 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4735 current_uiout
->text (_(" Inferior unloaded "));
4736 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4737 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4739 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4742 current_uiout
->text (" ");
4743 current_uiout
->field_string ("library", name
);
4744 current_uiout
->text ("\n");
4750 current_uiout
->text (_(" Inferior loaded "));
4751 ui_out_emit_list
list_emitter (current_uiout
, "added");
4753 for (so_list
*iter
: current_program_space
->added_solibs
)
4756 current_uiout
->text (" ");
4758 current_uiout
->field_string ("library", iter
->so_name
);
4759 current_uiout
->text ("\n");
4764 /* Print a message indicating what happened. This is called from
4765 normal_stop(). The input to this routine is the head of the bpstat
4766 list - a list of the eventpoints that caused this stop. KIND is
4767 the target_waitkind for the stopping event. This
4768 routine calls the generic print routine for printing a message
4769 about reasons for stopping. This will print (for example) the
4770 "Breakpoint n," part of the output. The return value of this
4773 PRINT_UNKNOWN: Means we printed nothing.
4774 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4775 code to print the location. An example is
4776 "Breakpoint 1, " which should be followed by
4778 PRINT_SRC_ONLY: Means we printed something, but there is no need
4779 to also print the location part of the message.
4780 An example is the catch/throw messages, which
4781 don't require a location appended to the end.
4782 PRINT_NOTHING: We have done some printing and we don't need any
4783 further info to be printed. */
4785 enum print_stop_action
4786 bpstat_print (bpstat bs
, int kind
)
4788 enum print_stop_action val
;
4790 /* Maybe another breakpoint in the chain caused us to stop.
4791 (Currently all watchpoints go on the bpstat whether hit or not.
4792 That probably could (should) be changed, provided care is taken
4793 with respect to bpstat_explains_signal). */
4794 for (; bs
; bs
= bs
->next
)
4796 val
= print_bp_stop_message (bs
);
4797 if (val
== PRINT_SRC_ONLY
4798 || val
== PRINT_SRC_AND_LOC
4799 || val
== PRINT_NOTHING
)
4803 /* If we had hit a shared library event breakpoint,
4804 print_bp_stop_message would print out this message. If we hit an
4805 OS-level shared library event, do the same thing. */
4806 if (kind
== TARGET_WAITKIND_LOADED
)
4808 print_solib_event (0);
4809 return PRINT_NOTHING
;
4812 /* We reached the end of the chain, or we got a null BS to start
4813 with and nothing was printed. */
4814 return PRINT_UNKNOWN
;
4817 /* Evaluate the boolean expression EXP and return the result. */
4820 breakpoint_cond_eval (expression
*exp
)
4822 struct value
*mark
= value_mark ();
4823 bool res
= value_true (evaluate_expression (exp
));
4825 value_free_to_mark (mark
);
4829 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4831 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4833 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4834 breakpoint_at (bl
->owner
),
4838 print_it (print_it_normal
)
4840 **bs_link_pointer
= this;
4841 *bs_link_pointer
= &next
;
4846 breakpoint_at (NULL
),
4850 print_it (print_it_normal
)
4854 /* The target has stopped with waitstatus WS. Check if any hardware
4855 watchpoints have triggered, according to the target. */
4858 watchpoints_triggered (struct target_waitstatus
*ws
)
4860 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4863 if (!stopped_by_watchpoint
)
4865 /* We were not stopped by a watchpoint. Mark all watchpoints
4866 as not triggered. */
4867 for (breakpoint
*b
: all_breakpoints ())
4868 if (is_hardware_watchpoint (b
))
4870 struct watchpoint
*w
= (struct watchpoint
*) b
;
4872 w
->watchpoint_triggered
= watch_triggered_no
;
4878 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4880 /* We were stopped by a watchpoint, but we don't know where.
4881 Mark all watchpoints as unknown. */
4882 for (breakpoint
*b
: all_breakpoints ())
4883 if (is_hardware_watchpoint (b
))
4885 struct watchpoint
*w
= (struct watchpoint
*) b
;
4887 w
->watchpoint_triggered
= watch_triggered_unknown
;
4893 /* The target could report the data address. Mark watchpoints
4894 affected by this data address as triggered, and all others as not
4897 for (breakpoint
*b
: all_breakpoints ())
4898 if (is_hardware_watchpoint (b
))
4900 struct watchpoint
*w
= (struct watchpoint
*) b
;
4901 struct bp_location
*loc
;
4903 w
->watchpoint_triggered
= watch_triggered_no
;
4904 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4906 if (is_masked_watchpoint (b
))
4908 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4909 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4911 if (newaddr
== start
)
4913 w
->watchpoint_triggered
= watch_triggered_yes
;
4917 /* Exact match not required. Within range is sufficient. */
4918 else if (target_watchpoint_addr_within_range
4919 (current_inferior ()->top_target (), addr
, loc
->address
,
4922 w
->watchpoint_triggered
= watch_triggered_yes
;
4931 /* Possible return values for watchpoint_check. */
4932 enum wp_check_result
4934 /* The watchpoint has been deleted. */
4937 /* The value has changed. */
4938 WP_VALUE_CHANGED
= 2,
4940 /* The value has not changed. */
4941 WP_VALUE_NOT_CHANGED
= 3,
4943 /* Ignore this watchpoint, no matter if the value changed or not. */
4947 #define BP_TEMPFLAG 1
4948 #define BP_HARDWAREFLAG 2
4950 /* Evaluate watchpoint condition expression and check if its value
4953 static wp_check_result
4954 watchpoint_check (bpstat bs
)
4956 struct watchpoint
*b
;
4957 struct frame_info
*fr
;
4958 int within_current_scope
;
4960 /* BS is built from an existing struct breakpoint. */
4961 gdb_assert (bs
->breakpoint_at
!= NULL
);
4962 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4964 /* If this is a local watchpoint, we only want to check if the
4965 watchpoint frame is in scope if the current thread is the thread
4966 that was used to create the watchpoint. */
4967 if (!watchpoint_in_thread_scope (b
))
4970 if (b
->exp_valid_block
== NULL
)
4971 within_current_scope
= 1;
4974 struct frame_info
*frame
= get_current_frame ();
4975 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4976 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4978 /* stack_frame_destroyed_p() returns a non-zero value if we're
4979 still in the function but the stack frame has already been
4980 invalidated. Since we can't rely on the values of local
4981 variables after the stack has been destroyed, we are treating
4982 the watchpoint in that state as `not changed' without further
4983 checking. Don't mark watchpoints as changed if the current
4984 frame is in an epilogue - even if they are in some other
4985 frame, our view of the stack is likely to be wrong and
4986 frame_find_by_id could error out. */
4987 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4990 fr
= frame_find_by_id (b
->watchpoint_frame
);
4991 within_current_scope
= (fr
!= NULL
);
4993 /* If we've gotten confused in the unwinder, we might have
4994 returned a frame that can't describe this variable. */
4995 if (within_current_scope
)
4997 struct symbol
*function
;
4999 function
= get_frame_function (fr
);
5000 if (function
== NULL
5001 || !contained_in (b
->exp_valid_block
,
5002 SYMBOL_BLOCK_VALUE (function
)))
5003 within_current_scope
= 0;
5006 if (within_current_scope
)
5007 /* If we end up stopping, the current frame will get selected
5008 in normal_stop. So this call to select_frame won't affect
5013 if (within_current_scope
)
5015 /* We use value_{,free_to_}mark because it could be a *long*
5016 time before we return to the command level and call
5017 free_all_values. We can't call free_all_values because we
5018 might be in the middle of evaluating a function call. */
5021 struct value
*new_val
;
5023 if (is_masked_watchpoint (b
))
5024 /* Since we don't know the exact trigger address (from
5025 stopped_data_address), just tell the user we've triggered
5026 a mask watchpoint. */
5027 return WP_VALUE_CHANGED
;
5029 mark
= value_mark ();
5030 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5033 if (b
->val_bitsize
!= 0)
5034 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5036 /* We use value_equal_contents instead of value_equal because
5037 the latter coerces an array to a pointer, thus comparing just
5038 the address of the array instead of its contents. This is
5039 not what we want. */
5040 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5041 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5044 bs
->old_val
= b
->val
;
5045 b
->val
= release_value (new_val
);
5046 b
->val_valid
= true;
5047 if (new_val
!= NULL
)
5048 value_free_to_mark (mark
);
5049 return WP_VALUE_CHANGED
;
5053 /* Nothing changed. */
5054 value_free_to_mark (mark
);
5055 return WP_VALUE_NOT_CHANGED
;
5060 /* This seems like the only logical thing to do because
5061 if we temporarily ignored the watchpoint, then when
5062 we reenter the block in which it is valid it contains
5063 garbage (in the case of a function, it may have two
5064 garbage values, one before and one after the prologue).
5065 So we can't even detect the first assignment to it and
5066 watch after that (since the garbage may or may not equal
5067 the first value assigned). */
5068 /* We print all the stop information in
5069 breakpoint_ops->print_it, but in this case, by the time we
5070 call breakpoint_ops->print_it this bp will be deleted
5071 already. So we have no choice but print the information
5074 SWITCH_THRU_ALL_UIS ()
5076 struct ui_out
*uiout
= current_uiout
;
5078 if (uiout
->is_mi_like_p ())
5080 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5081 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5082 "left the block in\n"
5083 "which its expression is valid.\n",
5084 signed_field ("wpnum", b
->number
));
5087 /* Make sure the watchpoint's commands aren't executed. */
5089 watchpoint_del_at_next_stop (b
);
5095 /* Return true if it looks like target has stopped due to hitting
5096 breakpoint location BL. This function does not check if we should
5097 stop, only if BL explains the stop. */
5100 bpstat_check_location (const struct bp_location
*bl
,
5101 const address_space
*aspace
, CORE_ADDR bp_addr
,
5102 const struct target_waitstatus
*ws
)
5104 struct breakpoint
*b
= bl
->owner
;
5106 /* BL is from an existing breakpoint. */
5107 gdb_assert (b
!= NULL
);
5109 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5112 /* Determine if the watched values have actually changed, and we
5113 should stop. If not, set BS->stop to 0. */
5116 bpstat_check_watchpoint (bpstat bs
)
5118 const struct bp_location
*bl
;
5119 struct watchpoint
*b
;
5121 /* BS is built for existing struct breakpoint. */
5122 bl
= bs
->bp_location_at
.get ();
5123 gdb_assert (bl
!= NULL
);
5124 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5125 gdb_assert (b
!= NULL
);
5128 int must_check_value
= 0;
5130 if (b
->type
== bp_watchpoint
)
5131 /* For a software watchpoint, we must always check the
5133 must_check_value
= 1;
5134 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5135 /* We have a hardware watchpoint (read, write, or access)
5136 and the target earlier reported an address watched by
5138 must_check_value
= 1;
5139 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5140 && b
->type
== bp_hardware_watchpoint
)
5141 /* We were stopped by a hardware watchpoint, but the target could
5142 not report the data address. We must check the watchpoint's
5143 value. Access and read watchpoints are out of luck; without
5144 a data address, we can't figure it out. */
5145 must_check_value
= 1;
5147 if (must_check_value
)
5153 e
= watchpoint_check (bs
);
5155 catch (const gdb_exception
&ex
)
5157 exception_fprintf (gdb_stderr
, ex
,
5158 "Error evaluating expression "
5159 "for watchpoint %d\n",
5162 SWITCH_THRU_ALL_UIS ()
5164 printf_filtered (_("Watchpoint %d deleted.\n"),
5167 watchpoint_del_at_next_stop (b
);
5174 /* We've already printed what needs to be printed. */
5175 bs
->print_it
= print_it_done
;
5179 bs
->print_it
= print_it_noop
;
5182 case WP_VALUE_CHANGED
:
5183 if (b
->type
== bp_read_watchpoint
)
5185 /* There are two cases to consider here:
5187 1. We're watching the triggered memory for reads.
5188 In that case, trust the target, and always report
5189 the watchpoint hit to the user. Even though
5190 reads don't cause value changes, the value may
5191 have changed since the last time it was read, and
5192 since we're not trapping writes, we will not see
5193 those, and as such we should ignore our notion of
5196 2. We're watching the triggered memory for both
5197 reads and writes. There are two ways this may
5200 2.1. This is a target that can't break on data
5201 reads only, but can break on accesses (reads or
5202 writes), such as e.g., x86. We detect this case
5203 at the time we try to insert read watchpoints.
5205 2.2. Otherwise, the target supports read
5206 watchpoints, but, the user set an access or write
5207 watchpoint watching the same memory as this read
5210 If we're watching memory writes as well as reads,
5211 ignore watchpoint hits when we find that the
5212 value hasn't changed, as reads don't cause
5213 changes. This still gives false positives when
5214 the program writes the same value to memory as
5215 what there was already in memory (we will confuse
5216 it for a read), but it's much better than
5219 int other_write_watchpoint
= 0;
5221 if (bl
->watchpoint_type
== hw_read
)
5223 for (breakpoint
*other_b
: all_breakpoints ())
5224 if (other_b
->type
== bp_hardware_watchpoint
5225 || other_b
->type
== bp_access_watchpoint
)
5227 struct watchpoint
*other_w
=
5228 (struct watchpoint
*) other_b
;
5230 if (other_w
->watchpoint_triggered
5231 == watch_triggered_yes
)
5233 other_write_watchpoint
= 1;
5239 if (other_write_watchpoint
5240 || bl
->watchpoint_type
== hw_access
)
5242 /* We're watching the same memory for writes,
5243 and the value changed since the last time we
5244 updated it, so this trap must be for a write.
5246 bs
->print_it
= print_it_noop
;
5251 case WP_VALUE_NOT_CHANGED
:
5252 if (b
->type
== bp_hardware_watchpoint
5253 || b
->type
== bp_watchpoint
)
5255 /* Don't stop: write watchpoints shouldn't fire if
5256 the value hasn't changed. */
5257 bs
->print_it
= print_it_noop
;
5267 else /* must_check_value == 0 */
5269 /* This is a case where some watchpoint(s) triggered, but
5270 not at the address of this watchpoint, or else no
5271 watchpoint triggered after all. So don't print
5272 anything for this watchpoint. */
5273 bs
->print_it
= print_it_noop
;
5279 /* For breakpoints that are currently marked as telling gdb to stop,
5280 check conditions (condition proper, frame, thread and ignore count)
5281 of breakpoint referred to by BS. If we should not stop for this
5282 breakpoint, set BS->stop to 0. */
5285 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5287 const struct bp_location
*bl
;
5288 struct breakpoint
*b
;
5290 bool condition_result
= true;
5291 struct expression
*cond
;
5293 gdb_assert (bs
->stop
);
5295 /* BS is built for existing struct breakpoint. */
5296 bl
= bs
->bp_location_at
.get ();
5297 gdb_assert (bl
!= NULL
);
5298 b
= bs
->breakpoint_at
;
5299 gdb_assert (b
!= NULL
);
5301 /* Even if the target evaluated the condition on its end and notified GDB, we
5302 need to do so again since GDB does not know if we stopped due to a
5303 breakpoint or a single step breakpoint. */
5305 if (frame_id_p (b
->frame_id
)
5306 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5312 /* If this is a thread/task-specific breakpoint, don't waste cpu
5313 evaluating the condition if this isn't the specified
5315 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5316 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5322 /* Evaluate extension language breakpoints that have a "stop" method
5324 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5326 if (is_watchpoint (b
))
5328 struct watchpoint
*w
= (struct watchpoint
*) b
;
5330 cond
= w
->cond_exp
.get ();
5333 cond
= bl
->cond
.get ();
5335 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5337 int within_current_scope
= 1;
5338 struct watchpoint
* w
;
5340 /* We use value_mark and value_free_to_mark because it could
5341 be a long time before we return to the command level and
5342 call free_all_values. We can't call free_all_values
5343 because we might be in the middle of evaluating a
5345 struct value
*mark
= value_mark ();
5347 if (is_watchpoint (b
))
5348 w
= (struct watchpoint
*) b
;
5352 /* Need to select the frame, with all that implies so that
5353 the conditions will have the right context. Because we
5354 use the frame, we will not see an inlined function's
5355 variables when we arrive at a breakpoint at the start
5356 of the inlined function; the current frame will be the
5358 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5359 select_frame (get_current_frame ());
5362 struct frame_info
*frame
;
5364 /* For local watchpoint expressions, which particular
5365 instance of a local is being watched matters, so we
5366 keep track of the frame to evaluate the expression
5367 in. To evaluate the condition however, it doesn't
5368 really matter which instantiation of the function
5369 where the condition makes sense triggers the
5370 watchpoint. This allows an expression like "watch
5371 global if q > 10" set in `func', catch writes to
5372 global on all threads that call `func', or catch
5373 writes on all recursive calls of `func' by a single
5374 thread. We simply always evaluate the condition in
5375 the innermost frame that's executing where it makes
5376 sense to evaluate the condition. It seems
5378 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5380 select_frame (frame
);
5382 within_current_scope
= 0;
5384 if (within_current_scope
)
5388 condition_result
= breakpoint_cond_eval (cond
);
5390 catch (const gdb_exception
&ex
)
5392 exception_fprintf (gdb_stderr
, ex
,
5393 "Error in testing breakpoint condition:\n");
5398 warning (_("Watchpoint condition cannot be tested "
5399 "in the current scope"));
5400 /* If we failed to set the right context for this
5401 watchpoint, unconditionally report it. */
5403 /* FIXME-someday, should give breakpoint #. */
5404 value_free_to_mark (mark
);
5407 if (cond
&& !condition_result
)
5411 else if (b
->ignore_count
> 0)
5415 /* Increase the hit count even though we don't stop. */
5417 gdb::observers::breakpoint_modified
.notify (b
);
5421 /* Returns true if we need to track moribund locations of LOC's type
5422 on the current target. */
5425 need_moribund_for_location_type (struct bp_location
*loc
)
5427 return ((loc
->loc_type
== bp_loc_software_breakpoint
5428 && !target_supports_stopped_by_sw_breakpoint ())
5429 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5430 && !target_supports_stopped_by_hw_breakpoint ()));
5433 /* See breakpoint.h. */
5436 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5437 const struct target_waitstatus
*ws
)
5439 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5441 for (breakpoint
*b
: all_breakpoints ())
5443 if (!breakpoint_enabled (b
))
5446 for (bp_location
*bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5448 /* For hardware watchpoints, we look only at the first
5449 location. The watchpoint_check function will work on the
5450 entire expression, not the individual locations. For
5451 read watchpoints, the watchpoints_triggered function has
5452 checked all locations already. */
5453 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5456 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5459 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5462 /* Come here if it's a watchpoint, or if the break address
5465 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5468 /* Assume we stop. Should we find a watchpoint that is not
5469 actually triggered, or if the condition of the breakpoint
5470 evaluates as false, we'll reset 'stop' to 0. */
5474 /* If this is a scope breakpoint, mark the associated
5475 watchpoint as triggered so that we will handle the
5476 out-of-scope event. We'll get to the watchpoint next
5478 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5480 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5482 w
->watchpoint_triggered
= watch_triggered_yes
;
5487 /* Check if a moribund breakpoint explains the stop. */
5488 if (!target_supports_stopped_by_sw_breakpoint ()
5489 || !target_supports_stopped_by_hw_breakpoint ())
5491 for (bp_location
*loc
: moribund_locations
)
5493 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5494 && need_moribund_for_location_type (loc
))
5496 bpstat bs
= new bpstats (loc
, &bs_link
);
5497 /* For hits of moribund locations, we should just proceed. */
5500 bs
->print_it
= print_it_noop
;
5508 /* See breakpoint.h. */
5511 bpstat_stop_status (const address_space
*aspace
,
5512 CORE_ADDR bp_addr
, thread_info
*thread
,
5513 const struct target_waitstatus
*ws
,
5516 struct breakpoint
*b
= NULL
;
5517 /* First item of allocated bpstat's. */
5518 bpstat bs_head
= stop_chain
;
5520 int need_remove_insert
;
5523 /* First, build the bpstat chain with locations that explain a
5524 target stop, while being careful to not set the target running,
5525 as that may invalidate locations (in particular watchpoint
5526 locations are recreated). Resuming will happen here with
5527 breakpoint conditions or watchpoint expressions that include
5528 inferior function calls. */
5529 if (bs_head
== NULL
)
5530 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5532 /* A bit of special processing for shlib breakpoints. We need to
5533 process solib loading here, so that the lists of loaded and
5534 unloaded libraries are correct before we handle "catch load" and
5536 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5538 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5540 handle_solib_event ();
5545 /* Now go through the locations that caused the target to stop, and
5546 check whether we're interested in reporting this stop to higher
5547 layers, or whether we should resume the target transparently. */
5551 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5556 b
= bs
->breakpoint_at
;
5557 b
->ops
->check_status (bs
);
5560 bpstat_check_breakpoint_conditions (bs
, thread
);
5565 gdb::observers::breakpoint_modified
.notify (b
);
5567 /* We will stop here. */
5568 if (b
->disposition
== disp_disable
)
5570 --(b
->enable_count
);
5571 if (b
->enable_count
<= 0)
5572 b
->enable_state
= bp_disabled
;
5577 bs
->commands
= b
->commands
;
5578 if (command_line_is_silent (bs
->commands
5579 ? bs
->commands
.get () : NULL
))
5582 b
->ops
->after_condition_true (bs
);
5587 /* Print nothing for this entry if we don't stop or don't
5589 if (!bs
->stop
|| !bs
->print
)
5590 bs
->print_it
= print_it_noop
;
5593 /* If we aren't stopping, the value of some hardware watchpoint may
5594 not have changed, but the intermediate memory locations we are
5595 watching may have. Don't bother if we're stopping; this will get
5597 need_remove_insert
= 0;
5598 if (! bpstat_causes_stop (bs_head
))
5599 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5601 && bs
->breakpoint_at
5602 && is_hardware_watchpoint (bs
->breakpoint_at
))
5604 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5606 update_watchpoint (w
, 0 /* don't reparse. */);
5607 need_remove_insert
= 1;
5610 if (need_remove_insert
)
5611 update_global_location_list (UGLL_MAY_INSERT
);
5612 else if (removed_any
)
5613 update_global_location_list (UGLL_DONT_INSERT
);
5619 handle_jit_event (CORE_ADDR address
)
5621 struct gdbarch
*gdbarch
;
5623 infrun_debug_printf ("handling bp_jit_event");
5625 /* Switch terminal for any messages produced by
5626 breakpoint_re_set. */
5627 target_terminal::ours_for_output ();
5629 gdbarch
= get_frame_arch (get_current_frame ());
5630 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5631 thus it is expected that its objectfile can be found through
5632 minimal symbol lookup. If it doesn't work (and assert fails), it
5633 most likely means that `jit_breakpoint_re_set` was changes and this
5634 function needs to be updated too. */
5635 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5636 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5637 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5639 target_terminal::inferior ();
5642 /* Prepare WHAT final decision for infrun. */
5644 /* Decide what infrun needs to do with this bpstat. */
5647 bpstat_what (bpstat bs_head
)
5649 struct bpstat_what retval
;
5652 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5653 retval
.call_dummy
= STOP_NONE
;
5654 retval
.is_longjmp
= false;
5656 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5658 /* Extract this BS's action. After processing each BS, we check
5659 if its action overrides all we've seem so far. */
5660 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5663 if (bs
->breakpoint_at
== NULL
)
5665 /* I suspect this can happen if it was a momentary
5666 breakpoint which has since been deleted. */
5670 bptype
= bs
->breakpoint_at
->type
;
5677 case bp_hardware_breakpoint
:
5678 case bp_single_step
:
5681 case bp_shlib_event
:
5685 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5687 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5690 this_action
= BPSTAT_WHAT_SINGLE
;
5693 case bp_hardware_watchpoint
:
5694 case bp_read_watchpoint
:
5695 case bp_access_watchpoint
:
5699 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5701 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5705 /* There was a watchpoint, but we're not stopping.
5706 This requires no further action. */
5710 case bp_longjmp_call_dummy
:
5714 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5715 retval
.is_longjmp
= bptype
!= bp_exception
;
5718 this_action
= BPSTAT_WHAT_SINGLE
;
5720 case bp_longjmp_resume
:
5721 case bp_exception_resume
:
5724 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5725 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5728 this_action
= BPSTAT_WHAT_SINGLE
;
5730 case bp_step_resume
:
5732 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5735 /* It is for the wrong frame. */
5736 this_action
= BPSTAT_WHAT_SINGLE
;
5739 case bp_hp_step_resume
:
5741 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5744 /* It is for the wrong frame. */
5745 this_action
= BPSTAT_WHAT_SINGLE
;
5748 case bp_watchpoint_scope
:
5749 case bp_thread_event
:
5750 case bp_overlay_event
:
5751 case bp_longjmp_master
:
5752 case bp_std_terminate_master
:
5753 case bp_exception_master
:
5754 this_action
= BPSTAT_WHAT_SINGLE
;
5760 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5762 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5766 /* Some catchpoints are implemented with breakpoints.
5767 For those, we need to step over the breakpoint. */
5768 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5769 this_action
= BPSTAT_WHAT_SINGLE
;
5773 this_action
= BPSTAT_WHAT_SINGLE
;
5776 /* Make sure the action is stop (silent or noisy),
5777 so infrun.c pops the dummy frame. */
5778 retval
.call_dummy
= STOP_STACK_DUMMY
;
5779 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5781 case bp_std_terminate
:
5782 /* Make sure the action is stop (silent or noisy),
5783 so infrun.c pops the dummy frame. */
5784 retval
.call_dummy
= STOP_STD_TERMINATE
;
5785 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5788 case bp_fast_tracepoint
:
5789 case bp_static_tracepoint
:
5790 /* Tracepoint hits should not be reported back to GDB, and
5791 if one got through somehow, it should have been filtered
5793 internal_error (__FILE__
, __LINE__
,
5794 _("bpstat_what: tracepoint encountered"));
5796 case bp_gnu_ifunc_resolver
:
5797 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5798 this_action
= BPSTAT_WHAT_SINGLE
;
5800 case bp_gnu_ifunc_resolver_return
:
5801 /* The breakpoint will be removed, execution will restart from the
5802 PC of the former breakpoint. */
5803 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5808 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5810 this_action
= BPSTAT_WHAT_SINGLE
;
5814 internal_error (__FILE__
, __LINE__
,
5815 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5818 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5825 bpstat_run_callbacks (bpstat bs_head
)
5829 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5831 struct breakpoint
*b
= bs
->breakpoint_at
;
5838 handle_jit_event (bs
->bp_location_at
->address
);
5840 case bp_gnu_ifunc_resolver
:
5841 gnu_ifunc_resolver_stop (b
);
5843 case bp_gnu_ifunc_resolver_return
:
5844 gnu_ifunc_resolver_return_stop (b
);
5850 /* See breakpoint.h. */
5853 bpstat_should_step ()
5855 for (breakpoint
*b
: all_breakpoints ())
5856 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5862 /* See breakpoint.h. */
5865 bpstat_causes_stop (bpstat bs
)
5867 for (; bs
!= NULL
; bs
= bs
->next
)
5876 /* Compute a string of spaces suitable to indent the next line
5877 so it starts at the position corresponding to the table column
5878 named COL_NAME in the currently active table of UIOUT. */
5881 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5883 static char wrap_indent
[80];
5884 int i
, total_width
, width
, align
;
5888 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5890 if (strcmp (text
, col_name
) == 0)
5892 gdb_assert (total_width
< sizeof wrap_indent
);
5893 memset (wrap_indent
, ' ', total_width
);
5894 wrap_indent
[total_width
] = 0;
5899 total_width
+= width
+ 1;
5905 /* Determine if the locations of this breakpoint will have their conditions
5906 evaluated by the target, host or a mix of both. Returns the following:
5908 "host": Host evals condition.
5909 "host or target": Host or Target evals condition.
5910 "target": Target evals condition.
5914 bp_condition_evaluator (struct breakpoint
*b
)
5916 struct bp_location
*bl
;
5917 char host_evals
= 0;
5918 char target_evals
= 0;
5923 if (!is_breakpoint (b
))
5926 if (gdb_evaluates_breakpoint_condition_p ()
5927 || !target_supports_evaluation_of_breakpoint_conditions ())
5928 return condition_evaluation_host
;
5930 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5932 if (bl
->cond_bytecode
)
5938 if (host_evals
&& target_evals
)
5939 return condition_evaluation_both
;
5940 else if (target_evals
)
5941 return condition_evaluation_target
;
5943 return condition_evaluation_host
;
5946 /* Determine the breakpoint location's condition evaluator. This is
5947 similar to bp_condition_evaluator, but for locations. */
5950 bp_location_condition_evaluator (struct bp_location
*bl
)
5952 if (bl
&& !is_breakpoint (bl
->owner
))
5955 if (gdb_evaluates_breakpoint_condition_p ()
5956 || !target_supports_evaluation_of_breakpoint_conditions ())
5957 return condition_evaluation_host
;
5959 if (bl
&& bl
->cond_bytecode
)
5960 return condition_evaluation_target
;
5962 return condition_evaluation_host
;
5965 /* Print the LOC location out of the list of B->LOC locations. */
5968 print_breakpoint_location (struct breakpoint
*b
,
5969 struct bp_location
*loc
)
5971 struct ui_out
*uiout
= current_uiout
;
5973 scoped_restore_current_program_space restore_pspace
;
5975 if (loc
!= NULL
&& loc
->shlib_disabled
)
5979 set_current_program_space (loc
->pspace
);
5981 if (b
->display_canonical
)
5982 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5983 else if (loc
&& loc
->symtab
)
5985 const struct symbol
*sym
= loc
->symbol
;
5989 uiout
->text ("in ");
5990 uiout
->field_string ("func", sym
->print_name (),
5991 function_name_style
.style ());
5993 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5994 uiout
->text ("at ");
5996 uiout
->field_string ("file",
5997 symtab_to_filename_for_display (loc
->symtab
),
5998 file_name_style
.style ());
6001 if (uiout
->is_mi_like_p ())
6002 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6004 uiout
->field_signed ("line", loc
->line_number
);
6010 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6012 uiout
->field_stream ("at", stb
);
6016 uiout
->field_string ("pending",
6017 event_location_to_string (b
->location
.get ()));
6018 /* If extra_string is available, it could be holding a condition
6019 or dprintf arguments. In either case, make sure it is printed,
6020 too, but only for non-MI streams. */
6021 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6023 if (b
->type
== bp_dprintf
)
6027 uiout
->text (b
->extra_string
);
6031 if (loc
&& is_breakpoint (b
)
6032 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6033 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6036 uiout
->field_string ("evaluated-by",
6037 bp_location_condition_evaluator (loc
));
6043 bptype_string (enum bptype type
)
6045 struct ep_type_description
6048 const char *description
;
6050 static struct ep_type_description bptypes
[] =
6052 {bp_none
, "?deleted?"},
6053 {bp_breakpoint
, "breakpoint"},
6054 {bp_hardware_breakpoint
, "hw breakpoint"},
6055 {bp_single_step
, "sw single-step"},
6056 {bp_until
, "until"},
6057 {bp_finish
, "finish"},
6058 {bp_watchpoint
, "watchpoint"},
6059 {bp_hardware_watchpoint
, "hw watchpoint"},
6060 {bp_read_watchpoint
, "read watchpoint"},
6061 {bp_access_watchpoint
, "acc watchpoint"},
6062 {bp_longjmp
, "longjmp"},
6063 {bp_longjmp_resume
, "longjmp resume"},
6064 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6065 {bp_exception
, "exception"},
6066 {bp_exception_resume
, "exception resume"},
6067 {bp_step_resume
, "step resume"},
6068 {bp_hp_step_resume
, "high-priority step resume"},
6069 {bp_watchpoint_scope
, "watchpoint scope"},
6070 {bp_call_dummy
, "call dummy"},
6071 {bp_std_terminate
, "std::terminate"},
6072 {bp_shlib_event
, "shlib events"},
6073 {bp_thread_event
, "thread events"},
6074 {bp_overlay_event
, "overlay events"},
6075 {bp_longjmp_master
, "longjmp master"},
6076 {bp_std_terminate_master
, "std::terminate master"},
6077 {bp_exception_master
, "exception master"},
6078 {bp_catchpoint
, "catchpoint"},
6079 {bp_tracepoint
, "tracepoint"},
6080 {bp_fast_tracepoint
, "fast tracepoint"},
6081 {bp_static_tracepoint
, "static tracepoint"},
6082 {bp_dprintf
, "dprintf"},
6083 {bp_jit_event
, "jit events"},
6084 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6085 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6088 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6089 || ((int) type
!= bptypes
[(int) type
].type
))
6090 internal_error (__FILE__
, __LINE__
,
6091 _("bptypes table does not describe type #%d."),
6094 return bptypes
[(int) type
].description
;
6097 /* For MI, output a field named 'thread-groups' with a list as the value.
6098 For CLI, prefix the list with the string 'inf'. */
6101 output_thread_groups (struct ui_out
*uiout
,
6102 const char *field_name
,
6103 const std::vector
<int> &inf_nums
,
6106 int is_mi
= uiout
->is_mi_like_p ();
6108 /* For backward compatibility, don't display inferiors in CLI unless
6109 there are several. Always display them for MI. */
6110 if (!is_mi
&& mi_only
)
6113 ui_out_emit_list
list_emitter (uiout
, field_name
);
6115 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6121 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6122 uiout
->field_string (NULL
, mi_group
);
6127 uiout
->text (" inf ");
6131 uiout
->text (plongest (inf_nums
[i
]));
6136 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6137 instead of going via breakpoint_ops::print_one. This makes "maint
6138 info breakpoints" show the software breakpoint locations of
6139 catchpoints, which are considered internal implementation
6143 print_one_breakpoint_location (struct breakpoint
*b
,
6144 struct bp_location
*loc
,
6146 struct bp_location
**last_loc
,
6147 int allflag
, bool raw_loc
)
6149 struct command_line
*l
;
6150 static char bpenables
[] = "nynny";
6152 struct ui_out
*uiout
= current_uiout
;
6153 int header_of_multiple
= 0;
6154 int part_of_multiple
= (loc
!= NULL
);
6155 struct value_print_options opts
;
6157 get_user_print_options (&opts
);
6159 gdb_assert (!loc
|| loc_number
!= 0);
6160 /* See comment in print_one_breakpoint concerning treatment of
6161 breakpoints with single disabled location. */
6164 && (b
->loc
->next
!= NULL
6165 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6166 header_of_multiple
= 1;
6174 if (part_of_multiple
)
6175 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6177 uiout
->field_signed ("number", b
->number
);
6181 if (part_of_multiple
)
6182 uiout
->field_skip ("type");
6184 uiout
->field_string ("type", bptype_string (b
->type
));
6188 if (part_of_multiple
)
6189 uiout
->field_skip ("disp");
6191 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6195 /* For locations that are disabled because of an invalid condition,
6196 display "N*" on CLI, where "*" refers to a footnote below the
6197 table. For MI, simply display a "N" without a footnote. */
6198 const char *N
= (uiout
->is_mi_like_p ()) ? "N" : "N*";
6199 if (part_of_multiple
)
6200 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? N
6201 : (loc
->enabled
? "y" : "n")));
6203 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6206 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6207 b
->ops
->print_one (b
, last_loc
);
6210 if (is_watchpoint (b
))
6212 struct watchpoint
*w
= (struct watchpoint
*) b
;
6214 /* Field 4, the address, is omitted (which makes the columns
6215 not line up too nicely with the headers, but the effect
6216 is relatively readable). */
6217 if (opts
.addressprint
)
6218 uiout
->field_skip ("addr");
6220 uiout
->field_string ("what", w
->exp_string
);
6222 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6223 || is_ada_exception_catchpoint (b
))
6225 if (opts
.addressprint
)
6228 if (header_of_multiple
)
6229 uiout
->field_string ("addr", "<MULTIPLE>",
6230 metadata_style
.style ());
6231 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6232 uiout
->field_string ("addr", "<PENDING>",
6233 metadata_style
.style ());
6235 uiout
->field_core_addr ("addr",
6236 loc
->gdbarch
, loc
->address
);
6239 if (!header_of_multiple
)
6240 print_breakpoint_location (b
, loc
);
6246 if (loc
!= NULL
&& !header_of_multiple
)
6248 std::vector
<int> inf_nums
;
6251 for (inferior
*inf
: all_inferiors ())
6253 if (inf
->pspace
== loc
->pspace
)
6254 inf_nums
.push_back (inf
->num
);
6257 /* For backward compatibility, don't display inferiors in CLI unless
6258 there are several. Always display for MI. */
6260 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6261 && (program_spaces
.size () > 1
6262 || number_of_inferiors () > 1)
6263 /* LOC is for existing B, it cannot be in
6264 moribund_locations and thus having NULL OWNER. */
6265 && loc
->owner
->type
!= bp_catchpoint
))
6267 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6270 if (!part_of_multiple
)
6272 if (b
->thread
!= -1)
6274 /* FIXME: This seems to be redundant and lost here; see the
6275 "stop only in" line a little further down. */
6276 uiout
->text (" thread ");
6277 uiout
->field_signed ("thread", b
->thread
);
6279 else if (b
->task
!= 0)
6281 uiout
->text (" task ");
6282 uiout
->field_signed ("task", b
->task
);
6288 if (!part_of_multiple
)
6289 b
->ops
->print_one_detail (b
, uiout
);
6291 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6294 uiout
->text ("\tstop only in stack frame at ");
6295 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6297 uiout
->field_core_addr ("frame",
6298 b
->gdbarch
, b
->frame_id
.stack_addr
);
6302 if (!part_of_multiple
&& b
->cond_string
)
6305 if (is_tracepoint (b
))
6306 uiout
->text ("\ttrace only if ");
6308 uiout
->text ("\tstop only if ");
6309 uiout
->field_string ("cond", b
->cond_string
);
6311 /* Print whether the target is doing the breakpoint's condition
6312 evaluation. If GDB is doing the evaluation, don't print anything. */
6313 if (is_breakpoint (b
)
6314 && breakpoint_condition_evaluation_mode ()
6315 == condition_evaluation_target
)
6317 uiout
->message (" (%pF evals)",
6318 string_field ("evaluated-by",
6319 bp_condition_evaluator (b
)));
6324 if (!part_of_multiple
&& b
->thread
!= -1)
6326 /* FIXME should make an annotation for this. */
6327 uiout
->text ("\tstop only in thread ");
6328 if (uiout
->is_mi_like_p ())
6329 uiout
->field_signed ("thread", b
->thread
);
6332 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6334 uiout
->field_string ("thread", print_thread_id (thr
));
6339 if (!part_of_multiple
)
6343 /* FIXME should make an annotation for this. */
6344 if (is_catchpoint (b
))
6345 uiout
->text ("\tcatchpoint");
6346 else if (is_tracepoint (b
))
6347 uiout
->text ("\ttracepoint");
6349 uiout
->text ("\tbreakpoint");
6350 uiout
->text (" already hit ");
6351 uiout
->field_signed ("times", b
->hit_count
);
6352 if (b
->hit_count
== 1)
6353 uiout
->text (" time\n");
6355 uiout
->text (" times\n");
6359 /* Output the count also if it is zero, but only if this is mi. */
6360 if (uiout
->is_mi_like_p ())
6361 uiout
->field_signed ("times", b
->hit_count
);
6365 if (!part_of_multiple
&& b
->ignore_count
)
6368 uiout
->message ("\tignore next %pF hits\n",
6369 signed_field ("ignore", b
->ignore_count
));
6372 /* Note that an enable count of 1 corresponds to "enable once"
6373 behavior, which is reported by the combination of enablement and
6374 disposition, so we don't need to mention it here. */
6375 if (!part_of_multiple
&& b
->enable_count
> 1)
6378 uiout
->text ("\tdisable after ");
6379 /* Tweak the wording to clarify that ignore and enable counts
6380 are distinct, and have additive effect. */
6381 if (b
->ignore_count
)
6382 uiout
->text ("additional ");
6384 uiout
->text ("next ");
6385 uiout
->field_signed ("enable", b
->enable_count
);
6386 uiout
->text (" hits\n");
6389 if (!part_of_multiple
&& is_tracepoint (b
))
6391 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6393 if (tp
->traceframe_usage
)
6395 uiout
->text ("\ttrace buffer usage ");
6396 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6397 uiout
->text (" bytes\n");
6401 l
= b
->commands
? b
->commands
.get () : NULL
;
6402 if (!part_of_multiple
&& l
)
6405 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6406 print_command_lines (uiout
, l
, 4);
6409 if (is_tracepoint (b
))
6411 struct tracepoint
*t
= (struct tracepoint
*) b
;
6413 if (!part_of_multiple
&& t
->pass_count
)
6415 annotate_field (10);
6416 uiout
->text ("\tpass count ");
6417 uiout
->field_signed ("pass", t
->pass_count
);
6418 uiout
->text (" \n");
6421 /* Don't display it when tracepoint or tracepoint location is
6423 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6425 annotate_field (11);
6427 if (uiout
->is_mi_like_p ())
6428 uiout
->field_string ("installed",
6429 loc
->inserted
? "y" : "n");
6435 uiout
->text ("\tnot ");
6436 uiout
->text ("installed on target\n");
6441 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6443 if (is_watchpoint (b
))
6445 struct watchpoint
*w
= (struct watchpoint
*) b
;
6447 uiout
->field_string ("original-location", w
->exp_string
);
6449 else if (b
->location
!= NULL
6450 && event_location_to_string (b
->location
.get ()) != NULL
)
6451 uiout
->field_string ("original-location",
6452 event_location_to_string (b
->location
.get ()));
6456 /* See breakpoint.h. */
6458 bool fix_multi_location_breakpoint_output_globally
= false;
6461 print_one_breakpoint (struct breakpoint
*b
,
6462 struct bp_location
**last_loc
,
6465 struct ui_out
*uiout
= current_uiout
;
6466 bool use_fixed_output
6467 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6468 || fix_multi_location_breakpoint_output_globally
);
6470 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6471 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6473 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6475 if (!use_fixed_output
)
6476 bkpt_tuple_emitter
.reset ();
6478 /* If this breakpoint has custom print function,
6479 it's already printed. Otherwise, print individual
6480 locations, if any. */
6482 || b
->ops
->print_one
== NULL
6485 /* If breakpoint has a single location that is disabled, we
6486 print it as if it had several locations, since otherwise it's
6487 hard to represent "breakpoint enabled, location disabled"
6490 Note that while hardware watchpoints have several locations
6491 internally, that's not a property exposed to users.
6493 Likewise, while catchpoints may be implemented with
6494 breakpoints (e.g., catch throw), that's not a property
6495 exposed to users. We do however display the internal
6496 breakpoint locations with "maint info breakpoints". */
6497 if (!is_hardware_watchpoint (b
)
6498 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6499 || is_ada_exception_catchpoint (b
))
6501 || (b
->loc
&& (b
->loc
->next
6503 || b
->loc
->disabled_by_cond
))))
6505 gdb::optional
<ui_out_emit_list
> locations_list
;
6507 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6508 MI record. For later versions, place breakpoint locations in a
6510 if (uiout
->is_mi_like_p () && use_fixed_output
)
6511 locations_list
.emplace (uiout
, "locations");
6514 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
, ++n
)
6516 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6517 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6525 breakpoint_address_bits (struct breakpoint
*b
)
6527 int print_address_bits
= 0;
6528 struct bp_location
*loc
;
6530 /* Software watchpoints that aren't watching memory don't have an
6531 address to print. */
6532 if (is_no_memory_software_watchpoint (b
))
6535 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6539 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6540 if (addr_bit
> print_address_bits
)
6541 print_address_bits
= addr_bit
;
6544 return print_address_bits
;
6547 /* See breakpoint.h. */
6550 print_breakpoint (breakpoint
*b
)
6552 struct bp_location
*dummy_loc
= NULL
;
6553 print_one_breakpoint (b
, &dummy_loc
, 0);
6556 /* Return true if this breakpoint was set by the user, false if it is
6557 internal or momentary. */
6560 user_breakpoint_p (struct breakpoint
*b
)
6562 return b
->number
> 0;
6565 /* See breakpoint.h. */
6568 pending_breakpoint_p (struct breakpoint
*b
)
6570 return b
->loc
== NULL
;
6573 /* Print information on breakpoints (including watchpoints and tracepoints).
6575 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6576 understood by number_or_range_parser. Only breakpoints included in this
6577 list are then printed.
6579 If SHOW_INTERNAL is true, print internal breakpoints.
6581 If FILTER is non-NULL, call it on each breakpoint and only include the
6582 ones for which it returns true.
6584 Return the total number of breakpoints listed. */
6587 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6588 bool (*filter
) (const struct breakpoint
*))
6590 struct bp_location
*last_loc
= NULL
;
6591 int nr_printable_breakpoints
;
6592 struct value_print_options opts
;
6593 int print_address_bits
= 0;
6594 int print_type_col_width
= 14;
6595 struct ui_out
*uiout
= current_uiout
;
6596 bool has_disabled_by_cond_location
= false;
6598 get_user_print_options (&opts
);
6600 /* Compute the number of rows in the table, as well as the size
6601 required for address fields. */
6602 nr_printable_breakpoints
= 0;
6603 for (breakpoint
*b
: all_breakpoints ())
6605 /* If we have a filter, only list the breakpoints it accepts. */
6606 if (filter
&& !filter (b
))
6609 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6610 accept. Skip the others. */
6611 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6613 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6615 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6619 if (show_internal
|| user_breakpoint_p (b
))
6621 int addr_bit
, type_len
;
6623 addr_bit
= breakpoint_address_bits (b
);
6624 if (addr_bit
> print_address_bits
)
6625 print_address_bits
= addr_bit
;
6627 type_len
= strlen (bptype_string (b
->type
));
6628 if (type_len
> print_type_col_width
)
6629 print_type_col_width
= type_len
;
6631 nr_printable_breakpoints
++;
6636 ui_out_emit_table
table_emitter (uiout
,
6637 opts
.addressprint
? 6 : 5,
6638 nr_printable_breakpoints
,
6641 if (nr_printable_breakpoints
> 0)
6642 annotate_breakpoints_headers ();
6643 if (nr_printable_breakpoints
> 0)
6645 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6646 if (nr_printable_breakpoints
> 0)
6648 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6649 if (nr_printable_breakpoints
> 0)
6651 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6652 if (nr_printable_breakpoints
> 0)
6654 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6655 if (opts
.addressprint
)
6657 if (nr_printable_breakpoints
> 0)
6659 if (print_address_bits
<= 32)
6660 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6662 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6664 if (nr_printable_breakpoints
> 0)
6666 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6667 uiout
->table_body ();
6668 if (nr_printable_breakpoints
> 0)
6669 annotate_breakpoints_table ();
6671 for (breakpoint
*b
: all_breakpoints ())
6674 /* If we have a filter, only list the breakpoints it accepts. */
6675 if (filter
&& !filter (b
))
6678 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6679 accept. Skip the others. */
6681 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6683 if (show_internal
) /* maintenance info breakpoint */
6685 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6688 else /* all others */
6690 if (!number_is_in_list (bp_num_list
, b
->number
))
6694 /* We only print out user settable breakpoints unless the
6695 show_internal is set. */
6696 if (show_internal
|| user_breakpoint_p (b
))
6698 print_one_breakpoint (b
, &last_loc
, show_internal
);
6699 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
6700 if (loc
->disabled_by_cond
)
6701 has_disabled_by_cond_location
= true;
6706 if (nr_printable_breakpoints
== 0)
6708 /* If there's a filter, let the caller decide how to report
6712 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6713 uiout
->message ("No breakpoints or watchpoints.\n");
6715 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6721 if (last_loc
&& !server_command
)
6722 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6724 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6725 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6729 /* FIXME? Should this be moved up so that it is only called when
6730 there have been breakpoints? */
6731 annotate_breakpoints_table_end ();
6733 return nr_printable_breakpoints
;
6736 /* Display the value of default-collect in a way that is generally
6737 compatible with the breakpoint list. */
6740 default_collect_info (void)
6742 struct ui_out
*uiout
= current_uiout
;
6744 /* If it has no value (which is frequently the case), say nothing; a
6745 message like "No default-collect." gets in user's face when it's
6747 if (!*default_collect
)
6750 /* The following phrase lines up nicely with per-tracepoint collect
6752 uiout
->text ("default collect ");
6753 uiout
->field_string ("default-collect", default_collect
);
6754 uiout
->text (" \n");
6758 info_breakpoints_command (const char *args
, int from_tty
)
6760 breakpoint_1 (args
, false, NULL
);
6762 default_collect_info ();
6766 info_watchpoints_command (const char *args
, int from_tty
)
6768 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6769 struct ui_out
*uiout
= current_uiout
;
6771 if (num_printed
== 0)
6773 if (args
== NULL
|| *args
== '\0')
6774 uiout
->message ("No watchpoints.\n");
6776 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6781 maintenance_info_breakpoints (const char *args
, int from_tty
)
6783 breakpoint_1 (args
, true, NULL
);
6785 default_collect_info ();
6789 breakpoint_has_pc (struct breakpoint
*b
,
6790 struct program_space
*pspace
,
6791 CORE_ADDR pc
, struct obj_section
*section
)
6793 struct bp_location
*bl
= b
->loc
;
6795 for (; bl
; bl
= bl
->next
)
6797 if (bl
->pspace
== pspace
6798 && bl
->address
== pc
6799 && (!overlay_debugging
|| bl
->section
== section
))
6805 /* Print a message describing any user-breakpoints set at PC. This
6806 concerns with logical breakpoints, so we match program spaces, not
6810 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6811 struct program_space
*pspace
, CORE_ADDR pc
,
6812 struct obj_section
*section
, int thread
)
6816 for (breakpoint
*b
: all_breakpoints ())
6817 others
+= (user_breakpoint_p (b
)
6818 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6823 printf_filtered (_("Note: breakpoint "));
6824 else /* if (others == ???) */
6825 printf_filtered (_("Note: breakpoints "));
6826 for (breakpoint
*b
: all_breakpoints ())
6827 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6830 printf_filtered ("%d", b
->number
);
6831 if (b
->thread
== -1 && thread
!= -1)
6832 printf_filtered (" (all threads)");
6833 else if (b
->thread
!= -1)
6834 printf_filtered (" (thread %d)", b
->thread
);
6835 printf_filtered ("%s%s ",
6836 ((b
->enable_state
== bp_disabled
6837 || b
->enable_state
== bp_call_disabled
)
6841 : ((others
== 1) ? " and" : ""));
6843 current_uiout
->message (_("also set at pc %ps.\n"),
6844 styled_string (address_style
.style (),
6845 paddress (gdbarch
, pc
)));
6850 /* Return true iff it is meaningful to use the address member of LOC.
6851 For some breakpoint types, the locations' address members are
6852 irrelevant and it makes no sense to attempt to compare them to
6853 other addresses (or use them for any other purpose either).
6855 More specifically, software watchpoints and catchpoints that are
6856 not backed by breakpoints always have a zero valued location
6857 address and we don't want to mark breakpoints of any of these types
6858 to be a duplicate of an actual breakpoint location at address
6862 bl_address_is_meaningful (bp_location
*loc
)
6864 return loc
->loc_type
!= bp_loc_other
;
6867 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6868 true if LOC1 and LOC2 represent the same watchpoint location. */
6871 watchpoint_locations_match (struct bp_location
*loc1
,
6872 struct bp_location
*loc2
)
6874 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6875 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6877 /* Both of them must exist. */
6878 gdb_assert (w1
!= NULL
);
6879 gdb_assert (w2
!= NULL
);
6881 /* If the target can evaluate the condition expression in hardware,
6882 then we we need to insert both watchpoints even if they are at
6883 the same place. Otherwise the watchpoint will only trigger when
6884 the condition of whichever watchpoint was inserted evaluates to
6885 true, not giving a chance for GDB to check the condition of the
6886 other watchpoint. */
6888 && target_can_accel_watchpoint_condition (loc1
->address
,
6890 loc1
->watchpoint_type
,
6891 w1
->cond_exp
.get ()))
6893 && target_can_accel_watchpoint_condition (loc2
->address
,
6895 loc2
->watchpoint_type
,
6896 w2
->cond_exp
.get ())))
6899 /* Note that this checks the owner's type, not the location's. In
6900 case the target does not support read watchpoints, but does
6901 support access watchpoints, we'll have bp_read_watchpoint
6902 watchpoints with hw_access locations. Those should be considered
6903 duplicates of hw_read locations. The hw_read locations will
6904 become hw_access locations later. */
6905 return (loc1
->owner
->type
== loc2
->owner
->type
6906 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6907 && loc1
->address
== loc2
->address
6908 && loc1
->length
== loc2
->length
);
6911 /* See breakpoint.h. */
6914 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6915 const address_space
*aspace2
, CORE_ADDR addr2
)
6917 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6918 || aspace1
== aspace2
)
6922 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6923 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6924 matches ASPACE2. On targets that have global breakpoints, the address
6925 space doesn't really matter. */
6928 breakpoint_address_match_range (const address_space
*aspace1
,
6930 int len1
, const address_space
*aspace2
,
6933 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6934 || aspace1
== aspace2
)
6935 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6938 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6939 a ranged breakpoint. In most targets, a match happens only if ASPACE
6940 matches the breakpoint's address space. On targets that have global
6941 breakpoints, the address space doesn't really matter. */
6944 breakpoint_location_address_match (struct bp_location
*bl
,
6945 const address_space
*aspace
,
6948 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6951 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6952 bl
->address
, bl
->length
,
6956 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6957 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6958 match happens only if ASPACE matches the breakpoint's address
6959 space. On targets that have global breakpoints, the address space
6960 doesn't really matter. */
6963 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6964 const address_space
*aspace
,
6965 CORE_ADDR addr
, int len
)
6967 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6968 || bl
->pspace
->aspace
== aspace
)
6970 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6972 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6978 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6979 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6980 true, otherwise returns false. */
6983 tracepoint_locations_match (struct bp_location
*loc1
,
6984 struct bp_location
*loc2
)
6986 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6987 /* Since tracepoint locations are never duplicated with others', tracepoint
6988 locations at the same address of different tracepoints are regarded as
6989 different locations. */
6990 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6995 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6996 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6997 the same location. If SW_HW_BPS_MATCH is true, then software
6998 breakpoint locations and hardware breakpoint locations match,
6999 otherwise they don't. */
7002 breakpoint_locations_match (struct bp_location
*loc1
,
7003 struct bp_location
*loc2
,
7004 bool sw_hw_bps_match
)
7006 int hw_point1
, hw_point2
;
7008 /* Both of them must not be in moribund_locations. */
7009 gdb_assert (loc1
->owner
!= NULL
);
7010 gdb_assert (loc2
->owner
!= NULL
);
7012 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7013 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7015 if (hw_point1
!= hw_point2
)
7018 return watchpoint_locations_match (loc1
, loc2
);
7019 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7020 return tracepoint_locations_match (loc1
, loc2
);
7022 /* We compare bp_location.length in order to cover ranged
7023 breakpoints. Keep this in sync with
7024 bp_location_is_less_than. */
7025 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7026 loc2
->pspace
->aspace
, loc2
->address
)
7027 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7028 && loc1
->length
== loc2
->length
);
7032 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7033 int bnum
, int have_bnum
)
7035 /* The longest string possibly returned by hex_string_custom
7036 is 50 chars. These must be at least that big for safety. */
7040 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7041 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7043 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7044 bnum
, astr1
, astr2
);
7046 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7049 /* Adjust a breakpoint's address to account for architectural
7050 constraints on breakpoint placement. Return the adjusted address.
7051 Note: Very few targets require this kind of adjustment. For most
7052 targets, this function is simply the identity function. */
7055 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7056 CORE_ADDR bpaddr
, enum bptype bptype
)
7058 if (bptype
== bp_watchpoint
7059 || bptype
== bp_hardware_watchpoint
7060 || bptype
== bp_read_watchpoint
7061 || bptype
== bp_access_watchpoint
7062 || bptype
== bp_catchpoint
)
7064 /* Watchpoints and the various bp_catch_* eventpoints should not
7065 have their addresses modified. */
7068 else if (bptype
== bp_single_step
)
7070 /* Single-step breakpoints should not have their addresses
7071 modified. If there's any architectural constrain that
7072 applies to this address, then it should have already been
7073 taken into account when the breakpoint was created in the
7074 first place. If we didn't do this, stepping through e.g.,
7075 Thumb-2 IT blocks would break. */
7080 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7082 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7084 /* Some targets have architectural constraints on the placement
7085 of breakpoint instructions. Obtain the adjusted address. */
7086 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7089 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7091 /* An adjusted breakpoint address can significantly alter
7092 a user's expectations. Print a warning if an adjustment
7094 if (adjusted_bpaddr
!= bpaddr
)
7095 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7097 return adjusted_bpaddr
;
7102 bp_location_from_bp_type (bptype type
)
7107 case bp_single_step
:
7111 case bp_longjmp_resume
:
7112 case bp_longjmp_call_dummy
:
7114 case bp_exception_resume
:
7115 case bp_step_resume
:
7116 case bp_hp_step_resume
:
7117 case bp_watchpoint_scope
:
7119 case bp_std_terminate
:
7120 case bp_shlib_event
:
7121 case bp_thread_event
:
7122 case bp_overlay_event
:
7124 case bp_longjmp_master
:
7125 case bp_std_terminate_master
:
7126 case bp_exception_master
:
7127 case bp_gnu_ifunc_resolver
:
7128 case bp_gnu_ifunc_resolver_return
:
7130 return bp_loc_software_breakpoint
;
7131 case bp_hardware_breakpoint
:
7132 return bp_loc_hardware_breakpoint
;
7133 case bp_hardware_watchpoint
:
7134 case bp_read_watchpoint
:
7135 case bp_access_watchpoint
:
7136 return bp_loc_hardware_watchpoint
;
7140 case bp_fast_tracepoint
:
7141 case bp_static_tracepoint
:
7142 return bp_loc_other
;
7144 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7148 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7150 this->owner
= owner
;
7151 this->cond_bytecode
= NULL
;
7152 this->shlib_disabled
= 0;
7154 this->disabled_by_cond
= false;
7156 this->loc_type
= type
;
7158 if (this->loc_type
== bp_loc_software_breakpoint
7159 || this->loc_type
== bp_loc_hardware_breakpoint
)
7160 mark_breakpoint_location_modified (this);
7165 bp_location::bp_location (breakpoint
*owner
)
7166 : bp_location::bp_location (owner
,
7167 bp_location_from_bp_type (owner
->type
))
7171 /* Allocate a struct bp_location. */
7173 static struct bp_location
*
7174 allocate_bp_location (struct breakpoint
*bpt
)
7176 return bpt
->ops
->allocate_location (bpt
);
7179 /* Decrement reference count. If the reference count reaches 0,
7180 destroy the bp_location. Sets *BLP to NULL. */
7183 decref_bp_location (struct bp_location
**blp
)
7185 bp_location_ref_policy::decref (*blp
);
7189 /* Add breakpoint B at the end of the global breakpoint chain. */
7192 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7194 struct breakpoint
*b1
;
7195 struct breakpoint
*result
= b
.get ();
7197 /* Add this breakpoint to the end of the chain so that a list of
7198 breakpoints will come out in order of increasing numbers. */
7200 b1
= breakpoint_chain
;
7202 breakpoint_chain
= b
.release ();
7207 b1
->next
= b
.release ();
7213 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7216 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7217 struct gdbarch
*gdbarch
,
7219 const struct breakpoint_ops
*ops
)
7221 gdb_assert (ops
!= NULL
);
7225 b
->gdbarch
= gdbarch
;
7226 b
->language
= current_language
->la_language
;
7227 b
->input_radix
= input_radix
;
7228 b
->related_breakpoint
= b
;
7231 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7232 that has type BPTYPE and has no locations as yet. */
7234 static struct breakpoint
*
7235 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7237 const struct breakpoint_ops
*ops
)
7239 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7241 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7242 return add_to_breakpoint_chain (std::move (b
));
7245 /* Initialize loc->function_name. */
7248 set_breakpoint_location_function (struct bp_location
*loc
)
7250 gdb_assert (loc
->owner
!= NULL
);
7252 if (loc
->owner
->type
== bp_breakpoint
7253 || loc
->owner
->type
== bp_hardware_breakpoint
7254 || is_tracepoint (loc
->owner
))
7256 const char *function_name
;
7258 if (loc
->msymbol
!= NULL
7259 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7260 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7262 struct breakpoint
*b
= loc
->owner
;
7264 function_name
= loc
->msymbol
->linkage_name ();
7266 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7267 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7269 /* Create only the whole new breakpoint of this type but do not
7270 mess more complicated breakpoints with multiple locations. */
7271 b
->type
= bp_gnu_ifunc_resolver
;
7272 /* Remember the resolver's address for use by the return
7274 loc
->related_address
= loc
->address
;
7278 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7281 loc
->function_name
= xstrdup (function_name
);
7285 /* Attempt to determine architecture of location identified by SAL. */
7287 get_sal_arch (struct symtab_and_line sal
)
7290 return sal
.section
->objfile
->arch ();
7292 return SYMTAB_OBJFILE (sal
.symtab
)->arch ();
7297 /* Low level routine for partially initializing a breakpoint of type
7298 BPTYPE. The newly created breakpoint's address, section, source
7299 file name, and line number are provided by SAL.
7301 It is expected that the caller will complete the initialization of
7302 the newly created breakpoint struct as well as output any status
7303 information regarding the creation of a new breakpoint. */
7306 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7307 struct symtab_and_line sal
, enum bptype bptype
,
7308 const struct breakpoint_ops
*ops
)
7310 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7312 add_location_to_breakpoint (b
, &sal
);
7314 if (bptype
!= bp_catchpoint
)
7315 gdb_assert (sal
.pspace
!= NULL
);
7317 /* Store the program space that was used to set the breakpoint,
7318 except for ordinary breakpoints, which are independent of the
7320 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7321 b
->pspace
= sal
.pspace
;
7324 /* set_raw_breakpoint is a low level routine for allocating and
7325 partially initializing a breakpoint of type BPTYPE. The newly
7326 created breakpoint's address, section, source file name, and line
7327 number are provided by SAL. The newly created and partially
7328 initialized breakpoint is added to the breakpoint chain and
7329 is also returned as the value of this function.
7331 It is expected that the caller will complete the initialization of
7332 the newly created breakpoint struct as well as output any status
7333 information regarding the creation of a new breakpoint. In
7334 particular, set_raw_breakpoint does NOT set the breakpoint
7335 number! Care should be taken to not allow an error to occur
7336 prior to completing the initialization of the breakpoint. If this
7337 should happen, a bogus breakpoint will be left on the chain. */
7340 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7341 struct symtab_and_line sal
, enum bptype bptype
,
7342 const struct breakpoint_ops
*ops
)
7344 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7346 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7347 return add_to_breakpoint_chain (std::move (b
));
7350 /* Call this routine when stepping and nexting to enable a breakpoint
7351 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7352 initiated the operation. */
7355 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7357 struct breakpoint
*b
, *b_tmp
;
7358 int thread
= tp
->global_num
;
7360 /* To avoid having to rescan all objfile symbols at every step,
7361 we maintain a list of continually-inserted but always disabled
7362 longjmp "master" breakpoints. Here, we simply create momentary
7363 clones of those and enable them for the requested thread. */
7364 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7365 if (b
->pspace
== current_program_space
7366 && (b
->type
== bp_longjmp_master
7367 || b
->type
== bp_exception_master
))
7369 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7370 struct breakpoint
*clone
;
7372 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7373 after their removal. */
7374 clone
= momentary_breakpoint_from_master (b
, type
,
7375 &momentary_breakpoint_ops
, 1);
7376 clone
->thread
= thread
;
7379 tp
->initiating_frame
= frame
;
7382 /* Delete all longjmp breakpoints from THREAD. */
7384 delete_longjmp_breakpoint (int thread
)
7386 struct breakpoint
*b
, *b_tmp
;
7388 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7389 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7391 if (b
->thread
== thread
)
7392 delete_breakpoint (b
);
7397 delete_longjmp_breakpoint_at_next_stop (int thread
)
7399 struct breakpoint
*b
, *b_tmp
;
7401 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7402 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7404 if (b
->thread
== thread
)
7405 b
->disposition
= disp_del_at_next_stop
;
7409 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7410 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7411 pointer to any of them. Return NULL if this system cannot place longjmp
7415 set_longjmp_breakpoint_for_call_dummy (void)
7417 breakpoint
*retval
= nullptr;
7419 for (breakpoint
*b
: all_breakpoints ())
7420 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7422 struct breakpoint
*new_b
;
7424 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7425 &momentary_breakpoint_ops
,
7427 new_b
->thread
= inferior_thread ()->global_num
;
7429 /* Link NEW_B into the chain of RETVAL breakpoints. */
7431 gdb_assert (new_b
->related_breakpoint
== new_b
);
7434 new_b
->related_breakpoint
= retval
;
7435 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7436 retval
= retval
->related_breakpoint
;
7437 retval
->related_breakpoint
= new_b
;
7443 /* Verify all existing dummy frames and their associated breakpoints for
7444 TP. Remove those which can no longer be found in the current frame
7447 You should call this function only at places where it is safe to currently
7448 unwind the whole stack. Failed stack unwind would discard live dummy
7452 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7454 struct breakpoint
*b
, *b_tmp
;
7456 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7457 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7459 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7461 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7462 dummy_b
= dummy_b
->related_breakpoint
;
7463 if (dummy_b
->type
!= bp_call_dummy
7464 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7467 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7469 while (b
->related_breakpoint
!= b
)
7471 if (b_tmp
== b
->related_breakpoint
)
7472 b_tmp
= b
->related_breakpoint
->next
;
7473 delete_breakpoint (b
->related_breakpoint
);
7475 delete_breakpoint (b
);
7480 enable_overlay_breakpoints (void)
7482 for (breakpoint
*b
: all_breakpoints ())
7483 if (b
->type
== bp_overlay_event
)
7485 b
->enable_state
= bp_enabled
;
7486 update_global_location_list (UGLL_MAY_INSERT
);
7487 overlay_events_enabled
= 1;
7492 disable_overlay_breakpoints (void)
7494 for (breakpoint
*b
: all_breakpoints ())
7495 if (b
->type
== bp_overlay_event
)
7497 b
->enable_state
= bp_disabled
;
7498 update_global_location_list (UGLL_DONT_INSERT
);
7499 overlay_events_enabled
= 0;
7503 /* Set an active std::terminate breakpoint for each std::terminate
7504 master breakpoint. */
7506 set_std_terminate_breakpoint (void)
7508 struct breakpoint
*b
, *b_tmp
;
7510 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
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 struct breakpoint
*b
, *b_tmp
;
7525 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7526 if (b
->type
== bp_std_terminate
)
7527 delete_breakpoint (b
);
7531 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7533 struct breakpoint
*b
;
7535 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7536 &internal_breakpoint_ops
);
7538 b
->enable_state
= bp_enabled
;
7539 /* location has to be used or breakpoint_re_set will delete me. */
7540 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7542 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7547 struct lang_and_radix
7553 /* Create a breakpoint for JIT code registration and unregistration. */
7556 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7558 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7559 &internal_breakpoint_ops
);
7562 /* Remove JIT code registration and unregistration breakpoint(s). */
7565 remove_jit_event_breakpoints (void)
7567 struct breakpoint
*b
, *b_tmp
;
7569 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7570 if (b
->type
== bp_jit_event
7571 && b
->loc
->pspace
== current_program_space
)
7572 delete_breakpoint (b
);
7576 remove_solib_event_breakpoints (void)
7578 struct breakpoint
*b
, *b_tmp
;
7580 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7581 if (b
->type
== bp_shlib_event
7582 && b
->loc
->pspace
== current_program_space
)
7583 delete_breakpoint (b
);
7586 /* See breakpoint.h. */
7589 remove_solib_event_breakpoints_at_next_stop (void)
7591 struct breakpoint
*b
, *b_tmp
;
7593 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7594 if (b
->type
== bp_shlib_event
7595 && b
->loc
->pspace
== current_program_space
)
7596 b
->disposition
= disp_del_at_next_stop
;
7599 /* Helper for create_solib_event_breakpoint /
7600 create_and_insert_solib_event_breakpoint. Allows specifying which
7601 INSERT_MODE to pass through to update_global_location_list. */
7603 static struct breakpoint
*
7604 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7605 enum ugll_insert_mode insert_mode
)
7607 struct breakpoint
*b
;
7609 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7610 &internal_breakpoint_ops
);
7611 update_global_location_list_nothrow (insert_mode
);
7616 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7618 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7621 /* See breakpoint.h. */
7624 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7626 struct breakpoint
*b
;
7628 /* Explicitly tell update_global_location_list to insert
7630 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7631 if (!b
->loc
->inserted
)
7633 delete_breakpoint (b
);
7639 /* Disable any breakpoints that are on code in shared libraries. Only
7640 apply to enabled breakpoints, disabled ones can just stay disabled. */
7643 disable_breakpoints_in_shlibs (void)
7645 struct bp_location
*loc
, **locp_tmp
;
7647 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7649 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7650 struct breakpoint
*b
= loc
->owner
;
7652 /* We apply the check to all breakpoints, including disabled for
7653 those with loc->duplicate set. This is so that when breakpoint
7654 becomes enabled, or the duplicate is removed, gdb will try to
7655 insert all breakpoints. If we don't set shlib_disabled here,
7656 we'll try to insert those breakpoints and fail. */
7657 if (((b
->type
== bp_breakpoint
)
7658 || (b
->type
== bp_jit_event
)
7659 || (b
->type
== bp_hardware_breakpoint
)
7660 || (is_tracepoint (b
)))
7661 && loc
->pspace
== current_program_space
7662 && !loc
->shlib_disabled
7663 && solib_name_from_address (loc
->pspace
, loc
->address
)
7666 loc
->shlib_disabled
= 1;
7671 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7672 notification of unloaded_shlib. Only apply to enabled breakpoints,
7673 disabled ones can just stay disabled. */
7676 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7678 struct bp_location
*loc
, **locp_tmp
;
7679 int disabled_shlib_breaks
= 0;
7681 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7683 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7684 struct breakpoint
*b
= loc
->owner
;
7686 if (solib
->pspace
== loc
->pspace
7687 && !loc
->shlib_disabled
7688 && (((b
->type
== bp_breakpoint
7689 || b
->type
== bp_jit_event
7690 || b
->type
== bp_hardware_breakpoint
)
7691 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7692 || loc
->loc_type
== bp_loc_software_breakpoint
))
7693 || is_tracepoint (b
))
7694 && solib_contains_address_p (solib
, loc
->address
))
7696 loc
->shlib_disabled
= 1;
7697 /* At this point, we cannot rely on remove_breakpoint
7698 succeeding so we must mark the breakpoint as not inserted
7699 to prevent future errors occurring in remove_breakpoints. */
7702 /* This may cause duplicate notifications for the same breakpoint. */
7703 gdb::observers::breakpoint_modified
.notify (b
);
7705 if (!disabled_shlib_breaks
)
7707 target_terminal::ours_for_output ();
7708 warning (_("Temporarily disabling breakpoints "
7709 "for unloaded shared library \"%s\""),
7712 disabled_shlib_breaks
= 1;
7717 /* Disable any breakpoints and tracepoints in OBJFILE upon
7718 notification of free_objfile. Only apply to enabled breakpoints,
7719 disabled ones can just stay disabled. */
7722 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7724 if (objfile
== NULL
)
7727 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7728 managed by the user with add-symbol-file/remove-symbol-file.
7729 Similarly to how breakpoints in shared libraries are handled in
7730 response to "nosharedlibrary", mark breakpoints in such modules
7731 shlib_disabled so they end up uninserted on the next global
7732 location list update. Shared libraries not loaded by the user
7733 aren't handled here -- they're already handled in
7734 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7735 solib_unloaded observer. We skip objfiles that are not
7736 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7738 if ((objfile
->flags
& OBJF_SHARED
) == 0
7739 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7742 for (breakpoint
*b
: all_breakpoints ())
7744 struct bp_location
*loc
;
7745 int bp_modified
= 0;
7747 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7750 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7752 CORE_ADDR loc_addr
= loc
->address
;
7754 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7755 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7758 if (loc
->shlib_disabled
!= 0)
7761 if (objfile
->pspace
!= loc
->pspace
)
7764 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7765 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7768 if (is_addr_in_objfile (loc_addr
, objfile
))
7770 loc
->shlib_disabled
= 1;
7771 /* At this point, we don't know whether the object was
7772 unmapped from the inferior or not, so leave the
7773 inserted flag alone. We'll handle failure to
7774 uninsert quietly, in case the object was indeed
7777 mark_breakpoint_location_modified (loc
);
7784 gdb::observers::breakpoint_modified
.notify (b
);
7788 /* FORK & VFORK catchpoints. */
7790 /* An instance of this type is used to represent a fork or vfork
7791 catchpoint. A breakpoint is really of this type iff its ops pointer points
7792 to CATCH_FORK_BREAKPOINT_OPS. */
7794 struct fork_catchpoint
: public breakpoint
7796 /* Process id of a child process whose forking triggered this
7797 catchpoint. This field is only valid immediately after this
7798 catchpoint has triggered. */
7799 ptid_t forked_inferior_pid
;
7802 /* Implement the "insert" breakpoint_ops method for fork
7806 insert_catch_fork (struct bp_location
*bl
)
7808 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7811 /* Implement the "remove" breakpoint_ops method for fork
7815 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7817 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7820 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7824 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7825 const address_space
*aspace
, CORE_ADDR bp_addr
,
7826 const struct target_waitstatus
*ws
)
7828 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7830 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7833 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7837 /* Implement the "print_it" breakpoint_ops method for fork
7840 static enum print_stop_action
7841 print_it_catch_fork (bpstat bs
)
7843 struct ui_out
*uiout
= current_uiout
;
7844 struct breakpoint
*b
= bs
->breakpoint_at
;
7845 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7847 annotate_catchpoint (b
->number
);
7848 maybe_print_thread_hit_breakpoint (uiout
);
7849 if (b
->disposition
== disp_del
)
7850 uiout
->text ("Temporary catchpoint ");
7852 uiout
->text ("Catchpoint ");
7853 if (uiout
->is_mi_like_p ())
7855 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7856 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7858 uiout
->field_signed ("bkptno", b
->number
);
7859 uiout
->text (" (forked process ");
7860 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7861 uiout
->text ("), ");
7862 return PRINT_SRC_AND_LOC
;
7865 /* Implement the "print_one" breakpoint_ops method for fork
7869 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7871 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7872 struct value_print_options opts
;
7873 struct ui_out
*uiout
= current_uiout
;
7875 get_user_print_options (&opts
);
7877 /* Field 4, the address, is omitted (which makes the columns not
7878 line up too nicely with the headers, but the effect is relatively
7880 if (opts
.addressprint
)
7881 uiout
->field_skip ("addr");
7883 uiout
->text ("fork");
7884 if (c
->forked_inferior_pid
!= null_ptid
)
7886 uiout
->text (", process ");
7887 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7891 if (uiout
->is_mi_like_p ())
7892 uiout
->field_string ("catch-type", "fork");
7895 /* Implement the "print_mention" breakpoint_ops method for fork
7899 print_mention_catch_fork (struct breakpoint
*b
)
7901 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7904 /* Implement the "print_recreate" breakpoint_ops method for fork
7908 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7910 fprintf_unfiltered (fp
, "catch fork");
7911 print_recreate_thread (b
, fp
);
7914 /* The breakpoint_ops structure to be used in fork catchpoints. */
7916 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7918 /* Implement the "insert" breakpoint_ops method for vfork
7922 insert_catch_vfork (struct bp_location
*bl
)
7924 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7927 /* Implement the "remove" breakpoint_ops method for vfork
7931 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7933 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7936 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7940 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7941 const address_space
*aspace
, CORE_ADDR bp_addr
,
7942 const struct target_waitstatus
*ws
)
7944 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7946 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7949 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7953 /* Implement the "print_it" breakpoint_ops method for vfork
7956 static enum print_stop_action
7957 print_it_catch_vfork (bpstat bs
)
7959 struct ui_out
*uiout
= current_uiout
;
7960 struct breakpoint
*b
= bs
->breakpoint_at
;
7961 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7963 annotate_catchpoint (b
->number
);
7964 maybe_print_thread_hit_breakpoint (uiout
);
7965 if (b
->disposition
== disp_del
)
7966 uiout
->text ("Temporary catchpoint ");
7968 uiout
->text ("Catchpoint ");
7969 if (uiout
->is_mi_like_p ())
7971 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7972 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7974 uiout
->field_signed ("bkptno", b
->number
);
7975 uiout
->text (" (vforked process ");
7976 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7977 uiout
->text ("), ");
7978 return PRINT_SRC_AND_LOC
;
7981 /* Implement the "print_one" breakpoint_ops method for vfork
7985 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7987 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7988 struct value_print_options opts
;
7989 struct ui_out
*uiout
= current_uiout
;
7991 get_user_print_options (&opts
);
7992 /* Field 4, the address, is omitted (which makes the columns not
7993 line up too nicely with the headers, but the effect is relatively
7995 if (opts
.addressprint
)
7996 uiout
->field_skip ("addr");
7998 uiout
->text ("vfork");
7999 if (c
->forked_inferior_pid
!= null_ptid
)
8001 uiout
->text (", process ");
8002 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
8006 if (uiout
->is_mi_like_p ())
8007 uiout
->field_string ("catch-type", "vfork");
8010 /* Implement the "print_mention" breakpoint_ops method for vfork
8014 print_mention_catch_vfork (struct breakpoint
*b
)
8016 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8019 /* Implement the "print_recreate" breakpoint_ops method for vfork
8023 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8025 fprintf_unfiltered (fp
, "catch vfork");
8026 print_recreate_thread (b
, fp
);
8029 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8031 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8033 /* An instance of this type is used to represent an solib catchpoint.
8034 A breakpoint is really of this type iff its ops pointer points to
8035 CATCH_SOLIB_BREAKPOINT_OPS. */
8037 struct solib_catchpoint
: public breakpoint
8039 ~solib_catchpoint () override
;
8041 /* True for "catch load", false for "catch unload". */
8044 /* Regular expression to match, if any. COMPILED is only valid when
8045 REGEX is non-NULL. */
8047 std::unique_ptr
<compiled_regex
> compiled
;
8050 solib_catchpoint::~solib_catchpoint ()
8052 xfree (this->regex
);
8056 insert_catch_solib (struct bp_location
*ignore
)
8062 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8068 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8069 const address_space
*aspace
,
8071 const struct target_waitstatus
*ws
)
8073 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8075 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8078 for (breakpoint
*other
: all_breakpoints ())
8080 struct bp_location
*other_bl
;
8082 if (other
== bl
->owner
)
8085 if (other
->type
!= bp_shlib_event
)
8088 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8091 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8093 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8102 check_status_catch_solib (struct bpstats
*bs
)
8104 struct solib_catchpoint
*self
8105 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8109 for (so_list
*iter
: current_program_space
->added_solibs
)
8112 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8118 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
8121 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
8127 bs
->print_it
= print_it_noop
;
8130 static enum print_stop_action
8131 print_it_catch_solib (bpstat bs
)
8133 struct breakpoint
*b
= bs
->breakpoint_at
;
8134 struct ui_out
*uiout
= current_uiout
;
8136 annotate_catchpoint (b
->number
);
8137 maybe_print_thread_hit_breakpoint (uiout
);
8138 if (b
->disposition
== disp_del
)
8139 uiout
->text ("Temporary catchpoint ");
8141 uiout
->text ("Catchpoint ");
8142 uiout
->field_signed ("bkptno", b
->number
);
8144 if (uiout
->is_mi_like_p ())
8145 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8146 print_solib_event (1);
8147 return PRINT_SRC_AND_LOC
;
8151 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8153 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8154 struct value_print_options opts
;
8155 struct ui_out
*uiout
= current_uiout
;
8157 get_user_print_options (&opts
);
8158 /* Field 4, the address, is omitted (which makes the columns not
8159 line up too nicely with the headers, but the effect is relatively
8161 if (opts
.addressprint
)
8164 uiout
->field_skip ("addr");
8172 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8174 msg
= _("load of library");
8179 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8181 msg
= _("unload of library");
8183 uiout
->field_string ("what", msg
);
8185 if (uiout
->is_mi_like_p ())
8186 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8190 print_mention_catch_solib (struct breakpoint
*b
)
8192 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8194 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8195 self
->is_load
? "load" : "unload");
8199 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8201 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8203 fprintf_unfiltered (fp
, "%s %s",
8204 b
->disposition
== disp_del
? "tcatch" : "catch",
8205 self
->is_load
? "load" : "unload");
8207 fprintf_unfiltered (fp
, " %s", self
->regex
);
8208 fprintf_unfiltered (fp
, "\n");
8211 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8213 /* See breakpoint.h. */
8216 add_solib_catchpoint (const char *arg
, bool is_load
, bool is_temp
, bool enabled
)
8218 struct gdbarch
*gdbarch
= get_current_arch ();
8222 arg
= skip_spaces (arg
);
8224 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8228 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8229 _("Invalid regexp")));
8230 c
->regex
= xstrdup (arg
);
8233 c
->is_load
= is_load
;
8234 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8235 &catch_solib_breakpoint_ops
);
8237 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8239 install_breakpoint (0, std::move (c
), 1);
8242 /* A helper function that does all the work for "catch load" and
8246 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8247 struct cmd_list_element
*command
)
8249 const int enabled
= 1;
8250 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8252 add_solib_catchpoint (arg
, is_load
, temp
, enabled
);
8256 catch_load_command_1 (const char *arg
, int from_tty
,
8257 struct cmd_list_element
*command
)
8259 catch_load_or_unload (arg
, from_tty
, 1, command
);
8263 catch_unload_command_1 (const char *arg
, int from_tty
,
8264 struct cmd_list_element
*command
)
8266 catch_load_or_unload (arg
, from_tty
, 0, command
);
8269 /* See breakpoint.h. */
8272 init_catchpoint (struct breakpoint
*b
,
8273 struct gdbarch
*gdbarch
, bool temp
,
8274 const char *cond_string
,
8275 const struct breakpoint_ops
*ops
)
8277 symtab_and_line sal
;
8278 sal
.pspace
= current_program_space
;
8280 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8282 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8283 b
->disposition
= temp
? disp_del
: disp_donttouch
;
8287 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8289 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8290 set_breakpoint_number (internal
, b
);
8291 if (is_tracepoint (b
))
8292 set_tracepoint_count (breakpoint_count
);
8295 gdb::observers::breakpoint_created
.notify (b
);
8298 update_global_location_list (UGLL_MAY_INSERT
);
8302 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8303 bool temp
, const char *cond_string
,
8304 const struct breakpoint_ops
*ops
)
8306 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8308 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
, ops
);
8310 c
->forked_inferior_pid
= null_ptid
;
8312 install_breakpoint (0, std::move (c
), 1);
8315 /* Exec catchpoints. */
8317 /* An instance of this type is used to represent an exec catchpoint.
8318 A breakpoint is really of this type iff its ops pointer points to
8319 CATCH_EXEC_BREAKPOINT_OPS. */
8321 struct exec_catchpoint
: public breakpoint
8323 ~exec_catchpoint () override
;
8325 /* Filename of a program whose exec triggered this catchpoint.
8326 This field is only valid immediately after this catchpoint has
8328 char *exec_pathname
;
8331 /* Exec catchpoint destructor. */
8333 exec_catchpoint::~exec_catchpoint ()
8335 xfree (this->exec_pathname
);
8339 insert_catch_exec (struct bp_location
*bl
)
8341 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8345 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8347 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8351 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8352 const address_space
*aspace
, CORE_ADDR bp_addr
,
8353 const struct target_waitstatus
*ws
)
8355 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8357 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8360 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8364 static enum print_stop_action
8365 print_it_catch_exec (bpstat bs
)
8367 struct ui_out
*uiout
= current_uiout
;
8368 struct breakpoint
*b
= bs
->breakpoint_at
;
8369 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8371 annotate_catchpoint (b
->number
);
8372 maybe_print_thread_hit_breakpoint (uiout
);
8373 if (b
->disposition
== disp_del
)
8374 uiout
->text ("Temporary catchpoint ");
8376 uiout
->text ("Catchpoint ");
8377 if (uiout
->is_mi_like_p ())
8379 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8380 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8382 uiout
->field_signed ("bkptno", b
->number
);
8383 uiout
->text (" (exec'd ");
8384 uiout
->field_string ("new-exec", c
->exec_pathname
);
8385 uiout
->text ("), ");
8387 return PRINT_SRC_AND_LOC
;
8391 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8393 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8394 struct value_print_options opts
;
8395 struct ui_out
*uiout
= current_uiout
;
8397 get_user_print_options (&opts
);
8399 /* Field 4, the address, is omitted (which makes the columns
8400 not line up too nicely with the headers, but the effect
8401 is relatively readable). */
8402 if (opts
.addressprint
)
8403 uiout
->field_skip ("addr");
8405 uiout
->text ("exec");
8406 if (c
->exec_pathname
!= NULL
)
8408 uiout
->text (", program \"");
8409 uiout
->field_string ("what", c
->exec_pathname
);
8410 uiout
->text ("\" ");
8413 if (uiout
->is_mi_like_p ())
8414 uiout
->field_string ("catch-type", "exec");
8418 print_mention_catch_exec (struct breakpoint
*b
)
8420 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8423 /* Implement the "print_recreate" breakpoint_ops method for exec
8427 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8429 fprintf_unfiltered (fp
, "catch exec");
8430 print_recreate_thread (b
, fp
);
8433 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8436 hw_breakpoint_used_count (void)
8439 struct bp_location
*bl
;
8441 for (breakpoint
*b
: all_breakpoints ())
8442 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8443 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8445 /* Special types of hardware breakpoints may use more than
8447 i
+= b
->ops
->resources_needed (bl
);
8453 /* Returns the resources B would use if it were a hardware
8457 hw_watchpoint_use_count (struct breakpoint
*b
)
8460 struct bp_location
*bl
;
8462 if (!breakpoint_enabled (b
))
8465 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8467 /* Special types of hardware watchpoints may use more than
8469 i
+= b
->ops
->resources_needed (bl
);
8475 /* Returns the sum the used resources of all hardware watchpoints of
8476 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8477 the sum of the used resources of all hardware watchpoints of other
8478 types _not_ TYPE. */
8481 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8482 enum bptype type
, int *other_type_used
)
8486 *other_type_used
= 0;
8487 for (breakpoint
*b
: all_breakpoints ())
8491 if (!breakpoint_enabled (b
))
8494 if (b
->type
== type
)
8495 i
+= hw_watchpoint_use_count (b
);
8496 else if (is_hardware_watchpoint (b
))
8497 *other_type_used
= 1;
8504 disable_watchpoints_before_interactive_call_start (void)
8506 for (breakpoint
*b
: all_breakpoints ())
8507 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8509 b
->enable_state
= bp_call_disabled
;
8510 update_global_location_list (UGLL_DONT_INSERT
);
8515 enable_watchpoints_after_interactive_call_stop (void)
8517 for (breakpoint
*b
: all_breakpoints ())
8518 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8520 b
->enable_state
= bp_enabled
;
8521 update_global_location_list (UGLL_MAY_INSERT
);
8526 disable_breakpoints_before_startup (void)
8528 current_program_space
->executing_startup
= 1;
8529 update_global_location_list (UGLL_DONT_INSERT
);
8533 enable_breakpoints_after_startup (void)
8535 current_program_space
->executing_startup
= 0;
8536 breakpoint_re_set ();
8539 /* Create a new single-step breakpoint for thread THREAD, with no
8542 static struct breakpoint
*
8543 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8545 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8547 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8548 &momentary_breakpoint_ops
);
8550 b
->disposition
= disp_donttouch
;
8551 b
->frame_id
= null_frame_id
;
8554 gdb_assert (b
->thread
!= 0);
8556 return add_to_breakpoint_chain (std::move (b
));
8559 /* Set a momentary breakpoint of type TYPE at address specified by
8560 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8564 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8565 struct frame_id frame_id
, enum bptype type
)
8567 struct breakpoint
*b
;
8569 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8571 gdb_assert (!frame_id_artificial_p (frame_id
));
8573 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8574 b
->enable_state
= bp_enabled
;
8575 b
->disposition
= disp_donttouch
;
8576 b
->frame_id
= frame_id
;
8578 b
->thread
= inferior_thread ()->global_num
;
8580 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8582 return breakpoint_up (b
);
8585 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8586 The new breakpoint will have type TYPE, use OPS as its
8587 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8589 static struct breakpoint
*
8590 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8592 const struct breakpoint_ops
*ops
,
8595 struct breakpoint
*copy
;
8597 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8598 copy
->loc
= allocate_bp_location (copy
);
8599 set_breakpoint_location_function (copy
->loc
);
8601 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8602 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8603 copy
->loc
->address
= orig
->loc
->address
;
8604 copy
->loc
->section
= orig
->loc
->section
;
8605 copy
->loc
->pspace
= orig
->loc
->pspace
;
8606 copy
->loc
->probe
= orig
->loc
->probe
;
8607 copy
->loc
->line_number
= orig
->loc
->line_number
;
8608 copy
->loc
->symtab
= orig
->loc
->symtab
;
8609 copy
->loc
->enabled
= loc_enabled
;
8610 copy
->frame_id
= orig
->frame_id
;
8611 copy
->thread
= orig
->thread
;
8612 copy
->pspace
= orig
->pspace
;
8614 copy
->enable_state
= bp_enabled
;
8615 copy
->disposition
= disp_donttouch
;
8616 copy
->number
= internal_breakpoint_number
--;
8618 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8622 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8626 clone_momentary_breakpoint (struct breakpoint
*orig
)
8628 /* If there's nothing to clone, then return nothing. */
8632 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8636 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8639 struct symtab_and_line sal
;
8641 sal
= find_pc_line (pc
, 0);
8643 sal
.section
= find_pc_overlay (pc
);
8644 sal
.explicit_pc
= 1;
8646 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8650 /* Tell the user we have just set a breakpoint B. */
8653 mention (struct breakpoint
*b
)
8655 b
->ops
->print_mention (b
);
8656 current_uiout
->text ("\n");
8660 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8662 /* Handle "set breakpoint auto-hw on".
8664 If the explicitly specified breakpoint type is not hardware
8665 breakpoint, check the memory map to see whether the breakpoint
8666 address is in read-only memory.
8668 - location type is not hardware breakpoint, memory is read-only.
8669 We change the type of the location to hardware breakpoint.
8671 - location type is hardware breakpoint, memory is read-write. This
8672 means we've previously made the location hardware one, but then the
8673 memory map changed, so we undo.
8677 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8679 if (automatic_hardware_breakpoints
8680 && bl
->owner
->type
!= bp_hardware_breakpoint
8681 && (bl
->loc_type
== bp_loc_software_breakpoint
8682 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8684 /* When breakpoints are removed, remove_breakpoints will use
8685 location types we've just set here, the only possible problem
8686 is that memory map has changed during running program, but
8687 it's not going to work anyway with current gdb. */
8688 mem_region
*mr
= lookup_mem_region (bl
->address
);
8692 enum bp_loc_type new_type
;
8694 if (mr
->attrib
.mode
!= MEM_RW
)
8695 new_type
= bp_loc_hardware_breakpoint
;
8697 new_type
= bp_loc_software_breakpoint
;
8699 if (new_type
!= bl
->loc_type
)
8701 static bool said
= false;
8703 bl
->loc_type
= new_type
;
8706 fprintf_filtered (gdb_stdout
,
8707 _("Note: automatically using "
8708 "hardware breakpoints for "
8709 "read-only addresses.\n"));
8717 static struct bp_location
*
8718 add_location_to_breakpoint (struct breakpoint
*b
,
8719 const struct symtab_and_line
*sal
)
8721 struct bp_location
*loc
, **tmp
;
8722 CORE_ADDR adjusted_address
;
8723 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8725 if (loc_gdbarch
== NULL
)
8726 loc_gdbarch
= b
->gdbarch
;
8728 /* Adjust the breakpoint's address prior to allocating a location.
8729 Once we call allocate_bp_location(), that mostly uninitialized
8730 location will be placed on the location chain. Adjustment of the
8731 breakpoint may cause target_read_memory() to be called and we do
8732 not want its scan of the location chain to find a breakpoint and
8733 location that's only been partially initialized. */
8734 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8737 /* Sort the locations by their ADDRESS. */
8738 loc
= allocate_bp_location (b
);
8739 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8740 tmp
= &((*tmp
)->next
))
8745 loc
->requested_address
= sal
->pc
;
8746 loc
->address
= adjusted_address
;
8747 loc
->pspace
= sal
->pspace
;
8748 loc
->probe
.prob
= sal
->prob
;
8749 loc
->probe
.objfile
= sal
->objfile
;
8750 gdb_assert (loc
->pspace
!= NULL
);
8751 loc
->section
= sal
->section
;
8752 loc
->gdbarch
= loc_gdbarch
;
8753 loc
->line_number
= sal
->line
;
8754 loc
->symtab
= sal
->symtab
;
8755 loc
->symbol
= sal
->symbol
;
8756 loc
->msymbol
= sal
->msymbol
;
8757 loc
->objfile
= sal
->objfile
;
8759 set_breakpoint_location_function (loc
);
8761 /* While by definition, permanent breakpoints are already present in the
8762 code, we don't mark the location as inserted. Normally one would expect
8763 that GDB could rely on that breakpoint instruction to stop the program,
8764 thus removing the need to insert its own breakpoint, except that executing
8765 the breakpoint instruction can kill the target instead of reporting a
8766 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8767 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8768 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8769 breakpoint be inserted normally results in QEMU knowing about the GDB
8770 breakpoint, and thus trap before the breakpoint instruction is executed.
8771 (If GDB later needs to continue execution past the permanent breakpoint,
8772 it manually increments the PC, thus avoiding executing the breakpoint
8774 if (bp_loc_is_permanent (loc
))
8781 /* Return true if LOC is pointing to a permanent breakpoint,
8782 return false otherwise. */
8785 bp_loc_is_permanent (struct bp_location
*loc
)
8787 gdb_assert (loc
!= NULL
);
8789 /* If we have a non-breakpoint-backed catchpoint or a software
8790 watchpoint, just return 0. We should not attempt to read from
8791 the addresses the locations of these breakpoint types point to.
8792 gdbarch_program_breakpoint_here_p, below, will attempt to read
8794 if (!bl_address_is_meaningful (loc
))
8797 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8798 switch_to_program_space_and_thread (loc
->pspace
);
8799 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8802 /* Build a command list for the dprintf corresponding to the current
8803 settings of the dprintf style options. */
8806 update_dprintf_command_list (struct breakpoint
*b
)
8808 char *dprintf_args
= b
->extra_string
;
8809 char *printf_line
= NULL
;
8814 dprintf_args
= skip_spaces (dprintf_args
);
8816 /* Allow a comma, as it may have terminated a location, but don't
8818 if (*dprintf_args
== ',')
8820 dprintf_args
= skip_spaces (dprintf_args
);
8822 if (*dprintf_args
!= '"')
8823 error (_("Bad format string, missing '\"'."));
8825 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8826 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8827 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8829 if (!dprintf_function
)
8830 error (_("No function supplied for dprintf call"));
8832 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8833 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8838 printf_line
= xstrprintf ("call (void) %s (%s)",
8842 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8844 if (target_can_run_breakpoint_commands ())
8845 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8848 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8849 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8853 internal_error (__FILE__
, __LINE__
,
8854 _("Invalid dprintf style."));
8856 gdb_assert (printf_line
!= NULL
);
8858 /* Manufacture a printf sequence. */
8859 struct command_line
*printf_cmd_line
8860 = new struct command_line (simple_control
, printf_line
);
8861 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8862 command_lines_deleter ()));
8865 /* Update all dprintf commands, making their command lists reflect
8866 current style settings. */
8869 update_dprintf_commands (const char *args
, int from_tty
,
8870 struct cmd_list_element
*c
)
8872 for (breakpoint
*b
: all_breakpoints ())
8873 if (b
->type
== bp_dprintf
)
8874 update_dprintf_command_list (b
);
8877 /* Create a breakpoint with SAL as location. Use LOCATION
8878 as a description of the location, and COND_STRING
8879 as condition expression. If LOCATION is NULL then create an
8880 "address location" from the address in the SAL. */
8883 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8884 gdb::array_view
<const symtab_and_line
> sals
,
8885 event_location_up
&&location
,
8886 gdb::unique_xmalloc_ptr
<char> filter
,
8887 gdb::unique_xmalloc_ptr
<char> cond_string
,
8888 gdb::unique_xmalloc_ptr
<char> extra_string
,
8889 enum bptype type
, enum bpdisp disposition
,
8890 int thread
, int task
, int ignore_count
,
8891 const struct breakpoint_ops
*ops
, int from_tty
,
8892 int enabled
, int internal
, unsigned flags
,
8893 int display_canonical
)
8897 if (type
== bp_hardware_breakpoint
)
8899 int target_resources_ok
;
8901 i
= hw_breakpoint_used_count ();
8902 target_resources_ok
=
8903 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8905 if (target_resources_ok
== 0)
8906 error (_("No hardware breakpoint support in the target."));
8907 else if (target_resources_ok
< 0)
8908 error (_("Hardware breakpoints used exceeds limit."));
8911 gdb_assert (!sals
.empty ());
8913 for (const auto &sal
: sals
)
8915 struct bp_location
*loc
;
8919 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8921 loc_gdbarch
= gdbarch
;
8923 describe_other_breakpoints (loc_gdbarch
,
8924 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8927 if (&sal
== &sals
[0])
8929 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8933 b
->cond_string
= cond_string
.release ();
8934 b
->extra_string
= extra_string
.release ();
8935 b
->ignore_count
= ignore_count
;
8936 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8937 b
->disposition
= disposition
;
8939 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8940 b
->loc
->inserted
= 1;
8942 if (type
== bp_static_tracepoint
)
8944 struct tracepoint
*t
= (struct tracepoint
*) b
;
8945 struct static_tracepoint_marker marker
;
8947 if (strace_marker_p (b
))
8949 /* We already know the marker exists, otherwise, we
8950 wouldn't see a sal for it. */
8952 = &event_location_to_string (b
->location
.get ())[3];
8955 p
= skip_spaces (p
);
8957 endp
= skip_to_space (p
);
8959 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8961 printf_filtered (_("Probed static tracepoint "
8963 t
->static_trace_marker_id
.c_str ());
8965 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8967 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8969 printf_filtered (_("Probed static tracepoint "
8971 t
->static_trace_marker_id
.c_str ());
8974 warning (_("Couldn't determine the static "
8975 "tracepoint marker to probe"));
8982 loc
= add_location_to_breakpoint (b
, &sal
);
8983 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8987 /* Do not set breakpoint locations conditions yet. As locations
8988 are inserted, they get sorted based on their addresses. Let
8989 the list stabilize to have reliable location numbers. */
8991 /* Dynamic printf requires and uses additional arguments on the
8992 command line, otherwise it's an error. */
8993 if (type
== bp_dprintf
)
8995 if (b
->extra_string
)
8996 update_dprintf_command_list (b
);
8998 error (_("Format string required"));
9000 else if (b
->extra_string
)
9001 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9005 /* The order of the locations is now stable. Set the location
9006 condition using the location's number. */
9008 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
9010 if (b
->cond_string
!= nullptr)
9011 set_breakpoint_location_condition (b
->cond_string
, loc
, b
->number
,
9017 b
->display_canonical
= display_canonical
;
9018 if (location
!= NULL
)
9019 b
->location
= std::move (location
);
9021 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9022 b
->filter
= std::move (filter
);
9026 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9027 gdb::array_view
<const symtab_and_line
> sals
,
9028 event_location_up
&&location
,
9029 gdb::unique_xmalloc_ptr
<char> filter
,
9030 gdb::unique_xmalloc_ptr
<char> cond_string
,
9031 gdb::unique_xmalloc_ptr
<char> extra_string
,
9032 enum bptype type
, enum bpdisp disposition
,
9033 int thread
, int task
, int ignore_count
,
9034 const struct breakpoint_ops
*ops
, int from_tty
,
9035 int enabled
, int internal
, unsigned flags
,
9036 int display_canonical
)
9038 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9040 init_breakpoint_sal (b
.get (), gdbarch
,
9041 sals
, std::move (location
),
9043 std::move (cond_string
),
9044 std::move (extra_string
),
9046 thread
, task
, ignore_count
,
9048 enabled
, internal
, flags
,
9051 install_breakpoint (internal
, std::move (b
), 0);
9054 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9055 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9056 value. COND_STRING, if not NULL, specified the condition to be
9057 used for all breakpoints. Essentially the only case where
9058 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9059 function. In that case, it's still not possible to specify
9060 separate conditions for different overloaded functions, so
9061 we take just a single condition string.
9063 NOTE: If the function succeeds, the caller is expected to cleanup
9064 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9065 array contents). If the function fails (error() is called), the
9066 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9067 COND and SALS arrays and each of those arrays contents. */
9070 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9071 struct linespec_result
*canonical
,
9072 gdb::unique_xmalloc_ptr
<char> cond_string
,
9073 gdb::unique_xmalloc_ptr
<char> extra_string
,
9074 enum bptype type
, enum bpdisp disposition
,
9075 int thread
, int task
, int ignore_count
,
9076 const struct breakpoint_ops
*ops
, int from_tty
,
9077 int enabled
, int internal
, unsigned flags
)
9079 if (canonical
->pre_expanded
)
9080 gdb_assert (canonical
->lsals
.size () == 1);
9082 for (const auto &lsal
: canonical
->lsals
)
9084 /* Note that 'location' can be NULL in the case of a plain
9085 'break', without arguments. */
9086 event_location_up location
9087 = (canonical
->location
!= NULL
9088 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9089 gdb::unique_xmalloc_ptr
<char> filter_string
9090 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9092 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9093 std::move (location
),
9094 std::move (filter_string
),
9095 std::move (cond_string
),
9096 std::move (extra_string
),
9098 thread
, task
, ignore_count
, ops
,
9099 from_tty
, enabled
, internal
, flags
,
9100 canonical
->special_display
);
9104 /* Parse LOCATION which is assumed to be a SAL specification possibly
9105 followed by conditionals. On return, SALS contains an array of SAL
9106 addresses found. LOCATION points to the end of the SAL (for
9107 linespec locations).
9109 The array and the line spec strings are allocated on the heap, it is
9110 the caller's responsibility to free them. */
9113 parse_breakpoint_sals (struct event_location
*location
,
9114 struct linespec_result
*canonical
)
9116 struct symtab_and_line cursal
;
9118 if (event_location_type (location
) == LINESPEC_LOCATION
)
9120 const char *spec
= get_linespec_location (location
)->spec_string
;
9124 /* The last displayed codepoint, if it's valid, is our default
9125 breakpoint address. */
9126 if (last_displayed_sal_is_valid ())
9128 /* Set sal's pspace, pc, symtab, and line to the values
9129 corresponding to the last call to print_frame_info.
9130 Be sure to reinitialize LINE with NOTCURRENT == 0
9131 as the breakpoint line number is inappropriate otherwise.
9132 find_pc_line would adjust PC, re-set it back. */
9133 symtab_and_line sal
= get_last_displayed_sal ();
9134 CORE_ADDR pc
= sal
.pc
;
9136 sal
= find_pc_line (pc
, 0);
9138 /* "break" without arguments is equivalent to "break *PC"
9139 where PC is the last displayed codepoint's address. So
9140 make sure to set sal.explicit_pc to prevent GDB from
9141 trying to expand the list of sals to include all other
9142 instances with the same symtab and line. */
9144 sal
.explicit_pc
= 1;
9146 struct linespec_sals lsal
;
9148 lsal
.canonical
= NULL
;
9150 canonical
->lsals
.push_back (std::move (lsal
));
9154 error (_("No default breakpoint address now."));
9158 /* Force almost all breakpoints to be in terms of the
9159 current_source_symtab (which is decode_line_1's default).
9160 This should produce the results we want almost all of the
9161 time while leaving default_breakpoint_* alone.
9163 ObjC: However, don't match an Objective-C method name which
9164 may have a '+' or '-' succeeded by a '['. */
9165 cursal
= get_current_source_symtab_and_line ();
9166 if (last_displayed_sal_is_valid ())
9168 const char *spec
= NULL
;
9170 if (event_location_type (location
) == LINESPEC_LOCATION
)
9171 spec
= get_linespec_location (location
)->spec_string
;
9175 && strchr ("+-", spec
[0]) != NULL
9178 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9179 get_last_displayed_symtab (),
9180 get_last_displayed_line (),
9181 canonical
, NULL
, NULL
);
9186 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9187 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9191 /* Convert each SAL into a real PC. Verify that the PC can be
9192 inserted as a breakpoint. If it can't throw an error. */
9195 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9197 for (auto &sal
: sals
)
9198 resolve_sal_pc (&sal
);
9201 /* Fast tracepoints may have restrictions on valid locations. For
9202 instance, a fast tracepoint using a jump instead of a trap will
9203 likely have to overwrite more bytes than a trap would, and so can
9204 only be placed where the instruction is longer than the jump, or a
9205 multi-instruction sequence does not have a jump into the middle of
9209 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9210 gdb::array_view
<const symtab_and_line
> sals
)
9212 for (const auto &sal
: sals
)
9214 struct gdbarch
*sarch
;
9216 sarch
= get_sal_arch (sal
);
9217 /* We fall back to GDBARCH if there is no architecture
9218 associated with SAL. */
9222 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9223 error (_("May not have a fast tracepoint at %s%s"),
9224 paddress (sarch
, sal
.pc
), msg
.c_str ());
9228 /* Given TOK, a string specification of condition and thread, as
9229 accepted by the 'break' command, extract the condition
9230 string and thread number and set *COND_STRING and *THREAD.
9231 PC identifies the context at which the condition should be parsed.
9232 If no condition is found, *COND_STRING is set to NULL.
9233 If no thread is found, *THREAD is set to -1. */
9236 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9237 char **cond_string
, int *thread
, int *task
,
9240 *cond_string
= NULL
;
9248 const char *end_tok
;
9250 const char *cond_start
= NULL
;
9251 const char *cond_end
= NULL
;
9253 tok
= skip_spaces (tok
);
9255 if ((*tok
== '"' || *tok
== ',') && rest
)
9257 *rest
= savestring (tok
, strlen (tok
));
9261 end_tok
= skip_to_space (tok
);
9263 toklen
= end_tok
- tok
;
9265 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9267 tok
= cond_start
= end_tok
+ 1;
9270 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9272 catch (const gdb_exception_error
&)
9277 tok
= tok
+ strlen (tok
);
9280 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9282 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
9287 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9290 struct thread_info
*thr
;
9293 thr
= parse_thread_id (tok
, &tmptok
);
9295 error (_("Junk after thread keyword."));
9296 *thread
= thr
->global_num
;
9299 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9304 *task
= strtol (tok
, &tmptok
, 0);
9306 error (_("Junk after task keyword."));
9307 if (!valid_task_id (*task
))
9308 error (_("Unknown task %d."), *task
);
9313 *rest
= savestring (tok
, strlen (tok
));
9317 error (_("Junk at end of arguments."));
9321 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
9322 succeeds. The parsed values are written to COND_STRING, THREAD,
9323 TASK, and REST. See the comment of 'find_condition_and_thread'
9324 for the description of these parameters and INPUT. */
9327 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
9328 const char *input
, char **cond_string
,
9329 int *thread
, int *task
, char **rest
)
9331 int num_failures
= 0;
9332 for (auto &sal
: sals
)
9334 char *cond
= nullptr;
9337 char *remaining
= nullptr;
9339 /* Here we want to parse 'arg' to separate condition from thread
9340 number. But because parsing happens in a context and the
9341 contexts of sals might be different, try each until there is
9342 success. Finding one successful parse is sufficient for our
9343 goal. When setting the breakpoint we'll re-parse the
9344 condition in the context of each sal. */
9347 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
9348 &task_id
, &remaining
);
9349 *cond_string
= cond
;
9350 *thread
= thread_id
;
9355 catch (const gdb_exception_error
&e
)
9358 /* If no sal remains, do not continue. */
9359 if (num_failures
== sals
.size ())
9365 /* Decode a static tracepoint marker spec. */
9367 static std::vector
<symtab_and_line
>
9368 decode_static_tracepoint_spec (const char **arg_p
)
9370 const char *p
= &(*arg_p
)[3];
9373 p
= skip_spaces (p
);
9375 endp
= skip_to_space (p
);
9377 std::string
marker_str (p
, endp
- p
);
9379 std::vector
<static_tracepoint_marker
> markers
9380 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9381 if (markers
.empty ())
9382 error (_("No known static tracepoint marker named %s"),
9383 marker_str
.c_str ());
9385 std::vector
<symtab_and_line
> sals
;
9386 sals
.reserve (markers
.size ());
9388 for (const static_tracepoint_marker
&marker
: markers
)
9390 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9391 sal
.pc
= marker
.address
;
9392 sals
.push_back (sal
);
9399 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9400 according to IS_TRACEPOINT. */
9402 static const struct breakpoint_ops
*
9403 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
9408 if (location_type
== PROBE_LOCATION
)
9409 return &tracepoint_probe_breakpoint_ops
;
9411 return &tracepoint_breakpoint_ops
;
9415 if (location_type
== PROBE_LOCATION
)
9416 return &bkpt_probe_breakpoint_ops
;
9418 return &bkpt_breakpoint_ops
;
9422 /* See breakpoint.h. */
9424 const struct breakpoint_ops
*
9425 breakpoint_ops_for_event_location (const struct event_location
*location
,
9428 if (location
!= nullptr)
9429 return breakpoint_ops_for_event_location_type
9430 (event_location_type (location
), is_tracepoint
);
9431 return is_tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
9434 /* See breakpoint.h. */
9437 create_breakpoint (struct gdbarch
*gdbarch
,
9438 struct event_location
*location
,
9439 const char *cond_string
,
9440 int thread
, const char *extra_string
,
9441 bool force_condition
, int parse_extra
,
9442 int tempflag
, enum bptype type_wanted
,
9444 enum auto_boolean pending_break_support
,
9445 const struct breakpoint_ops
*ops
,
9446 int from_tty
, int enabled
, int internal
,
9449 struct linespec_result canonical
;
9452 int prev_bkpt_count
= breakpoint_count
;
9454 gdb_assert (ops
!= NULL
);
9456 /* If extra_string isn't useful, set it to NULL. */
9457 if (extra_string
!= NULL
&& *extra_string
== '\0')
9458 extra_string
= NULL
;
9462 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9464 catch (const gdb_exception_error
&e
)
9466 /* If caller is interested in rc value from parse, set
9468 if (e
.error
== NOT_FOUND_ERROR
)
9470 /* If pending breakpoint support is turned off, throw
9473 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9476 exception_print (gdb_stderr
, e
);
9478 /* If pending breakpoint support is auto query and the user
9479 selects no, then simply return the error code. */
9480 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9481 && !nquery (_("Make %s pending on future shared library load? "),
9482 bptype_string (type_wanted
)))
9485 /* At this point, either the user was queried about setting
9486 a pending breakpoint and selected yes, or pending
9487 breakpoint behavior is on and thus a pending breakpoint
9488 is defaulted on behalf of the user. */
9495 if (!pending
&& canonical
.lsals
.empty ())
9498 /* Resolve all line numbers to PC's and verify that the addresses
9499 are ok for the target. */
9502 for (auto &lsal
: canonical
.lsals
)
9503 breakpoint_sals_to_pc (lsal
.sals
);
9506 /* Fast tracepoints may have additional restrictions on location. */
9507 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9509 for (const auto &lsal
: canonical
.lsals
)
9510 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9513 /* Verify that condition can be parsed, before setting any
9514 breakpoints. Allocate a separate condition expression for each
9518 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9519 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9526 const linespec_sals
&lsal
= canonical
.lsals
[0];
9528 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9529 &cond
, &thread
, &task
, &rest
);
9530 cond_string_copy
.reset (cond
);
9531 extra_string_copy
.reset (rest
);
9535 if (type_wanted
!= bp_dprintf
9536 && extra_string
!= NULL
&& *extra_string
!= '\0')
9537 error (_("Garbage '%s' at end of location"), extra_string
);
9539 /* Check the validity of the condition. We should error out
9540 if the condition is invalid at all of the locations and
9541 if it is not forced. In the PARSE_EXTRA case above, this
9542 check is done when parsing the EXTRA_STRING. */
9543 if (cond_string
!= nullptr && !force_condition
)
9545 int num_failures
= 0;
9546 const linespec_sals
&lsal
= canonical
.lsals
[0];
9547 for (const auto &sal
: lsal
.sals
)
9549 const char *cond
= cond_string
;
9552 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
9553 /* One success is sufficient to keep going. */
9556 catch (const gdb_exception_error
&)
9559 /* If this is the last sal, error out. */
9560 if (num_failures
== lsal
.sals
.size ())
9566 /* Create a private copy of condition string. */
9568 cond_string_copy
.reset (xstrdup (cond_string
));
9569 /* Create a private copy of any extra string. */
9571 extra_string_copy
.reset (xstrdup (extra_string
));
9574 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9575 std::move (cond_string_copy
),
9576 std::move (extra_string_copy
),
9578 tempflag
? disp_del
: disp_donttouch
,
9579 thread
, task
, ignore_count
, ops
,
9580 from_tty
, enabled
, internal
, flags
);
9584 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9586 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9587 b
->location
= copy_event_location (location
);
9590 b
->cond_string
= NULL
;
9593 /* Create a private copy of condition string. */
9594 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9598 /* Create a private copy of any extra string. */
9599 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9600 b
->ignore_count
= ignore_count
;
9601 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9602 b
->condition_not_parsed
= 1;
9603 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9604 if ((type_wanted
!= bp_breakpoint
9605 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9606 b
->pspace
= current_program_space
;
9608 install_breakpoint (internal
, std::move (b
), 0);
9611 if (canonical
.lsals
.size () > 1)
9613 warning (_("Multiple breakpoints were set.\nUse the "
9614 "\"delete\" command to delete unwanted breakpoints."));
9615 prev_breakpoint_count
= prev_bkpt_count
;
9618 update_global_location_list (UGLL_MAY_INSERT
);
9623 /* Set a breakpoint.
9624 ARG is a string describing breakpoint address,
9625 condition, and thread.
9626 FLAG specifies if a breakpoint is hardware on,
9627 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9631 break_command_1 (const char *arg
, int flag
, int from_tty
)
9633 int tempflag
= flag
& BP_TEMPFLAG
;
9634 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9635 ? bp_hardware_breakpoint
9638 event_location_up location
= string_to_event_location (&arg
, current_language
);
9639 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9640 (location
.get (), false /* is_tracepoint */);
9642 create_breakpoint (get_current_arch (),
9644 NULL
, 0, arg
, false, 1 /* parse arg */,
9645 tempflag
, type_wanted
,
9646 0 /* Ignore count */,
9647 pending_break_support
,
9655 /* Helper function for break_command_1 and disassemble_command. */
9658 resolve_sal_pc (struct symtab_and_line
*sal
)
9662 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9664 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9665 error (_("No line %d in file \"%s\"."),
9666 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9669 /* If this SAL corresponds to a breakpoint inserted using a line
9670 number, then skip the function prologue if necessary. */
9671 if (sal
->explicit_line
)
9672 skip_prologue_sal (sal
);
9675 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9677 const struct blockvector
*bv
;
9678 const struct block
*b
;
9681 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9682 SYMTAB_COMPUNIT (sal
->symtab
));
9685 sym
= block_linkage_function (b
);
9688 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9689 sal
->section
= sym
->obj_section (SYMTAB_OBJFILE (sal
->symtab
));
9693 /* It really is worthwhile to have the section, so we'll
9694 just have to look harder. This case can be executed
9695 if we have line numbers but no functions (as can
9696 happen in assembly source). */
9698 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9699 switch_to_program_space_and_thread (sal
->pspace
);
9701 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9703 sal
->section
= msym
.obj_section ();
9710 break_command (const char *arg
, int from_tty
)
9712 break_command_1 (arg
, 0, from_tty
);
9716 tbreak_command (const char *arg
, int from_tty
)
9718 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9722 hbreak_command (const char *arg
, int from_tty
)
9724 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9728 thbreak_command (const char *arg
, int from_tty
)
9730 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9734 stop_command (const char *arg
, int from_tty
)
9736 printf_filtered (_("Specify the type of breakpoint to set.\n\
9737 Usage: stop in <function | address>\n\
9738 stop at <line>\n"));
9742 stopin_command (const char *arg
, int from_tty
)
9748 else if (*arg
!= '*')
9750 const char *argptr
= arg
;
9753 /* Look for a ':'. If this is a line number specification, then
9754 say it is bad, otherwise, it should be an address or
9755 function/method name. */
9756 while (*argptr
&& !hasColon
)
9758 hasColon
= (*argptr
== ':');
9763 badInput
= (*argptr
!= ':'); /* Not a class::method */
9765 badInput
= isdigit (*arg
); /* a simple line number */
9769 printf_filtered (_("Usage: stop in <function | address>\n"));
9771 break_command_1 (arg
, 0, from_tty
);
9775 stopat_command (const char *arg
, int from_tty
)
9779 if (arg
== NULL
|| *arg
== '*') /* no line number */
9783 const char *argptr
= arg
;
9786 /* Look for a ':'. If there is a '::' then get out, otherwise
9787 it is probably a line number. */
9788 while (*argptr
&& !hasColon
)
9790 hasColon
= (*argptr
== ':');
9795 badInput
= (*argptr
== ':'); /* we have class::method */
9797 badInput
= !isdigit (*arg
); /* not a line number */
9801 printf_filtered (_("Usage: stop at LINE\n"));
9803 break_command_1 (arg
, 0, from_tty
);
9806 /* The dynamic printf command is mostly like a regular breakpoint, but
9807 with a prewired command list consisting of a single output command,
9808 built from extra arguments supplied on the dprintf command
9812 dprintf_command (const char *arg
, int from_tty
)
9814 event_location_up location
= string_to_event_location (&arg
, current_language
);
9816 /* If non-NULL, ARG should have been advanced past the location;
9817 the next character must be ','. */
9820 if (arg
[0] != ',' || arg
[1] == '\0')
9821 error (_("Format string required"));
9824 /* Skip the comma. */
9829 create_breakpoint (get_current_arch (),
9831 NULL
, 0, arg
, false, 1 /* parse arg */,
9833 0 /* Ignore count */,
9834 pending_break_support
,
9835 &dprintf_breakpoint_ops
,
9843 agent_printf_command (const char *arg
, int from_tty
)
9845 error (_("May only run agent-printf on the target"));
9848 /* Implement the "breakpoint_hit" breakpoint_ops method for
9849 ranged breakpoints. */
9852 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9853 const address_space
*aspace
,
9855 const struct target_waitstatus
*ws
)
9857 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9858 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9861 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9862 bl
->length
, aspace
, bp_addr
);
9865 /* Implement the "resources_needed" breakpoint_ops method for
9866 ranged breakpoints. */
9869 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9871 return target_ranged_break_num_registers ();
9874 /* Implement the "print_it" breakpoint_ops method for
9875 ranged breakpoints. */
9877 static enum print_stop_action
9878 print_it_ranged_breakpoint (bpstat bs
)
9880 struct breakpoint
*b
= bs
->breakpoint_at
;
9881 struct bp_location
*bl
= b
->loc
;
9882 struct ui_out
*uiout
= current_uiout
;
9884 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9886 /* Ranged breakpoints have only one location. */
9887 gdb_assert (bl
&& bl
->next
== NULL
);
9889 annotate_breakpoint (b
->number
);
9891 maybe_print_thread_hit_breakpoint (uiout
);
9893 if (b
->disposition
== disp_del
)
9894 uiout
->text ("Temporary ranged breakpoint ");
9896 uiout
->text ("Ranged breakpoint ");
9897 if (uiout
->is_mi_like_p ())
9899 uiout
->field_string ("reason",
9900 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9901 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9903 uiout
->field_signed ("bkptno", b
->number
);
9906 return PRINT_SRC_AND_LOC
;
9909 /* Implement the "print_one" breakpoint_ops method for
9910 ranged breakpoints. */
9913 print_one_ranged_breakpoint (struct breakpoint
*b
,
9914 struct bp_location
**last_loc
)
9916 struct bp_location
*bl
= b
->loc
;
9917 struct value_print_options opts
;
9918 struct ui_out
*uiout
= current_uiout
;
9920 /* Ranged breakpoints have only one location. */
9921 gdb_assert (bl
&& bl
->next
== NULL
);
9923 get_user_print_options (&opts
);
9925 if (opts
.addressprint
)
9926 /* We don't print the address range here, it will be printed later
9927 by print_one_detail_ranged_breakpoint. */
9928 uiout
->field_skip ("addr");
9930 print_breakpoint_location (b
, bl
);
9934 /* Implement the "print_one_detail" breakpoint_ops method for
9935 ranged breakpoints. */
9938 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9939 struct ui_out
*uiout
)
9941 CORE_ADDR address_start
, address_end
;
9942 struct bp_location
*bl
= b
->loc
;
9947 address_start
= bl
->address
;
9948 address_end
= address_start
+ bl
->length
- 1;
9950 uiout
->text ("\taddress range: ");
9951 stb
.printf ("[%s, %s]",
9952 print_core_address (bl
->gdbarch
, address_start
),
9953 print_core_address (bl
->gdbarch
, address_end
));
9954 uiout
->field_stream ("addr", stb
);
9958 /* Implement the "print_mention" breakpoint_ops method for
9959 ranged breakpoints. */
9962 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9964 struct bp_location
*bl
= b
->loc
;
9965 struct ui_out
*uiout
= current_uiout
;
9968 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9970 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9971 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9972 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9975 /* Implement the "print_recreate" breakpoint_ops method for
9976 ranged breakpoints. */
9979 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9981 fprintf_unfiltered (fp
, "break-range %s, %s",
9982 event_location_to_string (b
->location
.get ()),
9983 event_location_to_string (b
->location_range_end
.get ()));
9984 print_recreate_thread (b
, fp
);
9987 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9989 static struct breakpoint_ops ranged_breakpoint_ops
;
9991 /* Find the address where the end of the breakpoint range should be
9992 placed, given the SAL of the end of the range. This is so that if
9993 the user provides a line number, the end of the range is set to the
9994 last instruction of the given line. */
9997 find_breakpoint_range_end (struct symtab_and_line sal
)
10001 /* If the user provided a PC value, use it. Otherwise,
10002 find the address of the end of the given location. */
10003 if (sal
.explicit_pc
)
10010 ret
= find_line_pc_range (sal
, &start
, &end
);
10012 error (_("Could not find location of the end of the range."));
10014 /* find_line_pc_range returns the start of the next line. */
10021 /* Implement the "break-range" CLI command. */
10024 break_range_command (const char *arg
, int from_tty
)
10026 const char *arg_start
;
10027 struct linespec_result canonical_start
, canonical_end
;
10028 int bp_count
, can_use_bp
, length
;
10030 struct breakpoint
*b
;
10032 /* We don't support software ranged breakpoints. */
10033 if (target_ranged_break_num_registers () < 0)
10034 error (_("This target does not support hardware ranged breakpoints."));
10036 bp_count
= hw_breakpoint_used_count ();
10037 bp_count
+= target_ranged_break_num_registers ();
10038 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10040 if (can_use_bp
< 0)
10041 error (_("Hardware breakpoints used exceeds limit."));
10043 arg
= skip_spaces (arg
);
10044 if (arg
== NULL
|| arg
[0] == '\0')
10045 error(_("No address range specified."));
10048 event_location_up start_location
= string_to_event_location (&arg
,
10050 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10053 error (_("Too few arguments."));
10054 else if (canonical_start
.lsals
.empty ())
10055 error (_("Could not find location of the beginning of the range."));
10057 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
10059 if (canonical_start
.lsals
.size () > 1
10060 || lsal_start
.sals
.size () != 1)
10061 error (_("Cannot create a ranged breakpoint with multiple locations."));
10063 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
10064 std::string
addr_string_start (arg_start
, arg
- arg_start
);
10066 arg
++; /* Skip the comma. */
10067 arg
= skip_spaces (arg
);
10069 /* Parse the end location. */
10073 /* We call decode_line_full directly here instead of using
10074 parse_breakpoint_sals because we need to specify the start location's
10075 symtab and line as the default symtab and line for the end of the
10076 range. This makes it possible to have ranges like "foo.c:27, +14",
10077 where +14 means 14 lines from the start location. */
10078 event_location_up end_location
= string_to_event_location (&arg
,
10080 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10081 sal_start
.symtab
, sal_start
.line
,
10082 &canonical_end
, NULL
, NULL
);
10084 if (canonical_end
.lsals
.empty ())
10085 error (_("Could not find location of the end of the range."));
10087 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10088 if (canonical_end
.lsals
.size () > 1
10089 || lsal_end
.sals
.size () != 1)
10090 error (_("Cannot create a ranged breakpoint with multiple locations."));
10092 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10094 end
= find_breakpoint_range_end (sal_end
);
10095 if (sal_start
.pc
> end
)
10096 error (_("Invalid address range, end precedes start."));
10098 length
= end
- sal_start
.pc
+ 1;
10100 /* Length overflowed. */
10101 error (_("Address range too large."));
10102 else if (length
== 1)
10104 /* This range is simple enough to be handled by
10105 the `hbreak' command. */
10106 hbreak_command (&addr_string_start
[0], 1);
10111 /* Now set up the breakpoint. */
10112 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10113 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10114 set_breakpoint_count (breakpoint_count
+ 1);
10115 b
->number
= breakpoint_count
;
10116 b
->disposition
= disp_donttouch
;
10117 b
->location
= std::move (start_location
);
10118 b
->location_range_end
= std::move (end_location
);
10119 b
->loc
->length
= length
;
10122 gdb::observers::breakpoint_created
.notify (b
);
10123 update_global_location_list (UGLL_MAY_INSERT
);
10126 /* Return non-zero if EXP is verified as constant. Returned zero
10127 means EXP is variable. Also the constant detection may fail for
10128 some constant expressions and in such case still falsely return
10132 watchpoint_exp_is_const (const struct expression
*exp
)
10134 return exp
->op
->constant_p ();
10137 /* Watchpoint destructor. */
10139 watchpoint::~watchpoint ()
10141 xfree (this->exp_string
);
10142 xfree (this->exp_string_reparse
);
10145 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10148 re_set_watchpoint (struct breakpoint
*b
)
10150 struct watchpoint
*w
= (struct watchpoint
*) b
;
10152 /* Watchpoint can be either on expression using entirely global
10153 variables, or it can be on local variables.
10155 Watchpoints of the first kind are never auto-deleted, and even
10156 persist across program restarts. Since they can use variables
10157 from shared libraries, we need to reparse expression as libraries
10158 are loaded and unloaded.
10160 Watchpoints on local variables can also change meaning as result
10161 of solib event. For example, if a watchpoint uses both a local
10162 and a global variables in expression, it's a local watchpoint,
10163 but unloading of a shared library will make the expression
10164 invalid. This is not a very common use case, but we still
10165 re-evaluate expression, to avoid surprises to the user.
10167 Note that for local watchpoints, we re-evaluate it only if
10168 watchpoints frame id is still valid. If it's not, it means the
10169 watchpoint is out of scope and will be deleted soon. In fact,
10170 I'm not sure we'll ever be called in this case.
10172 If a local watchpoint's frame id is still valid, then
10173 w->exp_valid_block is likewise valid, and we can safely use it.
10175 Don't do anything about disabled watchpoints, since they will be
10176 reevaluated again when enabled. */
10177 update_watchpoint (w
, 1 /* reparse */);
10180 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10183 insert_watchpoint (struct bp_location
*bl
)
10185 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10186 int length
= w
->exact
? 1 : bl
->length
;
10188 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10189 w
->cond_exp
.get ());
10192 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10195 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10197 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10198 int length
= w
->exact
? 1 : bl
->length
;
10200 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10201 w
->cond_exp
.get ());
10205 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10206 const address_space
*aspace
, CORE_ADDR bp_addr
,
10207 const struct target_waitstatus
*ws
)
10209 struct breakpoint
*b
= bl
->owner
;
10210 struct watchpoint
*w
= (struct watchpoint
*) b
;
10212 /* Continuable hardware watchpoints are treated as non-existent if the
10213 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10214 some data address). Otherwise gdb won't stop on a break instruction
10215 in the code (not from a breakpoint) when a hardware watchpoint has
10216 been defined. Also skip watchpoints which we know did not trigger
10217 (did not match the data address). */
10218 if (is_hardware_watchpoint (b
)
10219 && w
->watchpoint_triggered
== watch_triggered_no
)
10226 check_status_watchpoint (bpstat bs
)
10228 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10230 bpstat_check_watchpoint (bs
);
10233 /* Implement the "resources_needed" breakpoint_ops method for
10234 hardware watchpoints. */
10237 resources_needed_watchpoint (const struct bp_location
*bl
)
10239 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10240 int length
= w
->exact
? 1 : bl
->length
;
10242 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10245 /* Implement the "works_in_software_mode" breakpoint_ops method for
10246 hardware watchpoints. */
10249 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10251 /* Read and access watchpoints only work with hardware support. */
10252 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10255 static enum print_stop_action
10256 print_it_watchpoint (bpstat bs
)
10258 struct breakpoint
*b
;
10259 enum print_stop_action result
;
10260 struct watchpoint
*w
;
10261 struct ui_out
*uiout
= current_uiout
;
10263 gdb_assert (bs
->bp_location_at
!= NULL
);
10265 b
= bs
->breakpoint_at
;
10266 w
= (struct watchpoint
*) b
;
10268 annotate_watchpoint (b
->number
);
10269 maybe_print_thread_hit_breakpoint (uiout
);
10273 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10276 case bp_watchpoint
:
10277 case bp_hardware_watchpoint
:
10278 if (uiout
->is_mi_like_p ())
10279 uiout
->field_string
10280 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10282 tuple_emitter
.emplace (uiout
, "value");
10283 uiout
->text ("\nOld value = ");
10284 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10285 uiout
->field_stream ("old", stb
);
10286 uiout
->text ("\nNew value = ");
10287 watchpoint_value_print (w
->val
.get (), &stb
);
10288 uiout
->field_stream ("new", stb
);
10289 uiout
->text ("\n");
10290 /* More than one watchpoint may have been triggered. */
10291 result
= PRINT_UNKNOWN
;
10294 case bp_read_watchpoint
:
10295 if (uiout
->is_mi_like_p ())
10296 uiout
->field_string
10297 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10299 tuple_emitter
.emplace (uiout
, "value");
10300 uiout
->text ("\nValue = ");
10301 watchpoint_value_print (w
->val
.get (), &stb
);
10302 uiout
->field_stream ("value", stb
);
10303 uiout
->text ("\n");
10304 result
= PRINT_UNKNOWN
;
10307 case bp_access_watchpoint
:
10308 if (bs
->old_val
!= NULL
)
10310 if (uiout
->is_mi_like_p ())
10311 uiout
->field_string
10313 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10315 tuple_emitter
.emplace (uiout
, "value");
10316 uiout
->text ("\nOld value = ");
10317 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10318 uiout
->field_stream ("old", stb
);
10319 uiout
->text ("\nNew value = ");
10324 if (uiout
->is_mi_like_p ())
10325 uiout
->field_string
10327 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10328 tuple_emitter
.emplace (uiout
, "value");
10329 uiout
->text ("\nValue = ");
10331 watchpoint_value_print (w
->val
.get (), &stb
);
10332 uiout
->field_stream ("new", stb
);
10333 uiout
->text ("\n");
10334 result
= PRINT_UNKNOWN
;
10337 result
= PRINT_UNKNOWN
;
10343 /* Implement the "print_mention" breakpoint_ops method for hardware
10347 print_mention_watchpoint (struct breakpoint
*b
)
10349 struct watchpoint
*w
= (struct watchpoint
*) b
;
10350 struct ui_out
*uiout
= current_uiout
;
10351 const char *tuple_name
;
10355 case bp_watchpoint
:
10356 uiout
->text ("Watchpoint ");
10357 tuple_name
= "wpt";
10359 case bp_hardware_watchpoint
:
10360 uiout
->text ("Hardware watchpoint ");
10361 tuple_name
= "wpt";
10363 case bp_read_watchpoint
:
10364 uiout
->text ("Hardware read watchpoint ");
10365 tuple_name
= "hw-rwpt";
10367 case bp_access_watchpoint
:
10368 uiout
->text ("Hardware access (read/write) watchpoint ");
10369 tuple_name
= "hw-awpt";
10372 internal_error (__FILE__
, __LINE__
,
10373 _("Invalid hardware watchpoint type."));
10376 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10377 uiout
->field_signed ("number", b
->number
);
10378 uiout
->text (": ");
10379 uiout
->field_string ("exp", w
->exp_string
);
10382 /* Implement the "print_recreate" breakpoint_ops method for
10386 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10388 struct watchpoint
*w
= (struct watchpoint
*) b
;
10392 case bp_watchpoint
:
10393 case bp_hardware_watchpoint
:
10394 fprintf_unfiltered (fp
, "watch");
10396 case bp_read_watchpoint
:
10397 fprintf_unfiltered (fp
, "rwatch");
10399 case bp_access_watchpoint
:
10400 fprintf_unfiltered (fp
, "awatch");
10403 internal_error (__FILE__
, __LINE__
,
10404 _("Invalid watchpoint type."));
10407 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10408 print_recreate_thread (b
, fp
);
10411 /* Implement the "explains_signal" breakpoint_ops method for
10415 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10417 /* A software watchpoint cannot cause a signal other than
10418 GDB_SIGNAL_TRAP. */
10419 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10425 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10427 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10429 /* Implement the "insert" breakpoint_ops method for
10430 masked hardware watchpoints. */
10433 insert_masked_watchpoint (struct bp_location
*bl
)
10435 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10437 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10438 bl
->watchpoint_type
);
10441 /* Implement the "remove" breakpoint_ops method for
10442 masked hardware watchpoints. */
10445 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10447 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10449 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10450 bl
->watchpoint_type
);
10453 /* Implement the "resources_needed" breakpoint_ops method for
10454 masked hardware watchpoints. */
10457 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10459 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10461 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10464 /* Implement the "works_in_software_mode" breakpoint_ops method for
10465 masked hardware watchpoints. */
10468 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10473 /* Implement the "print_it" breakpoint_ops method for
10474 masked hardware watchpoints. */
10476 static enum print_stop_action
10477 print_it_masked_watchpoint (bpstat bs
)
10479 struct breakpoint
*b
= bs
->breakpoint_at
;
10480 struct ui_out
*uiout
= current_uiout
;
10482 /* Masked watchpoints have only one location. */
10483 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10485 annotate_watchpoint (b
->number
);
10486 maybe_print_thread_hit_breakpoint (uiout
);
10490 case bp_hardware_watchpoint
:
10491 if (uiout
->is_mi_like_p ())
10492 uiout
->field_string
10493 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10496 case bp_read_watchpoint
:
10497 if (uiout
->is_mi_like_p ())
10498 uiout
->field_string
10499 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10502 case bp_access_watchpoint
:
10503 if (uiout
->is_mi_like_p ())
10504 uiout
->field_string
10506 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10509 internal_error (__FILE__
, __LINE__
,
10510 _("Invalid hardware watchpoint type."));
10514 uiout
->text (_("\n\
10515 Check the underlying instruction at PC for the memory\n\
10516 address and value which triggered this watchpoint.\n"));
10517 uiout
->text ("\n");
10519 /* More than one watchpoint may have been triggered. */
10520 return PRINT_UNKNOWN
;
10523 /* Implement the "print_one_detail" breakpoint_ops method for
10524 masked hardware watchpoints. */
10527 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10528 struct ui_out
*uiout
)
10530 struct watchpoint
*w
= (struct watchpoint
*) b
;
10532 /* Masked watchpoints have only one location. */
10533 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10535 uiout
->text ("\tmask ");
10536 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10537 uiout
->text ("\n");
10540 /* Implement the "print_mention" breakpoint_ops method for
10541 masked hardware watchpoints. */
10544 print_mention_masked_watchpoint (struct breakpoint
*b
)
10546 struct watchpoint
*w
= (struct watchpoint
*) b
;
10547 struct ui_out
*uiout
= current_uiout
;
10548 const char *tuple_name
;
10552 case bp_hardware_watchpoint
:
10553 uiout
->text ("Masked hardware watchpoint ");
10554 tuple_name
= "wpt";
10556 case bp_read_watchpoint
:
10557 uiout
->text ("Masked hardware read watchpoint ");
10558 tuple_name
= "hw-rwpt";
10560 case bp_access_watchpoint
:
10561 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10562 tuple_name
= "hw-awpt";
10565 internal_error (__FILE__
, __LINE__
,
10566 _("Invalid hardware watchpoint type."));
10569 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10570 uiout
->field_signed ("number", b
->number
);
10571 uiout
->text (": ");
10572 uiout
->field_string ("exp", w
->exp_string
);
10575 /* Implement the "print_recreate" breakpoint_ops method for
10576 masked hardware watchpoints. */
10579 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10581 struct watchpoint
*w
= (struct watchpoint
*) b
;
10585 case bp_hardware_watchpoint
:
10586 fprintf_unfiltered (fp
, "watch");
10588 case bp_read_watchpoint
:
10589 fprintf_unfiltered (fp
, "rwatch");
10591 case bp_access_watchpoint
:
10592 fprintf_unfiltered (fp
, "awatch");
10595 internal_error (__FILE__
, __LINE__
,
10596 _("Invalid hardware watchpoint type."));
10599 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
,
10600 phex (w
->hw_wp_mask
, sizeof (CORE_ADDR
)));
10601 print_recreate_thread (b
, fp
);
10604 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10606 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10608 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10611 is_masked_watchpoint (const struct breakpoint
*b
)
10613 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10616 /* accessflag: hw_write: watch write,
10617 hw_read: watch read,
10618 hw_access: watch access (read or write) */
10620 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10621 bool just_location
, bool internal
)
10623 struct breakpoint
*scope_breakpoint
= NULL
;
10624 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10625 struct value
*result
;
10626 int saved_bitpos
= 0, saved_bitsize
= 0;
10627 const char *exp_start
= NULL
;
10628 const char *exp_end
= NULL
;
10629 const char *tok
, *end_tok
;
10631 const char *cond_start
= NULL
;
10632 const char *cond_end
= NULL
;
10633 enum bptype bp_type
;
10635 /* Flag to indicate whether we are going to use masks for
10636 the hardware watchpoint. */
10637 bool use_mask
= false;
10638 CORE_ADDR mask
= 0;
10640 /* Make sure that we actually have parameters to parse. */
10641 if (arg
!= NULL
&& arg
[0] != '\0')
10643 const char *value_start
;
10645 exp_end
= arg
+ strlen (arg
);
10647 /* Look for "parameter value" pairs at the end
10648 of the arguments string. */
10649 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10651 /* Skip whitespace at the end of the argument list. */
10652 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10655 /* Find the beginning of the last token.
10656 This is the value of the parameter. */
10657 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10659 value_start
= tok
+ 1;
10661 /* Skip whitespace. */
10662 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10667 /* Find the beginning of the second to last token.
10668 This is the parameter itself. */
10669 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10672 toklen
= end_tok
- tok
+ 1;
10674 if (toklen
== 6 && startswith (tok
, "thread"))
10676 struct thread_info
*thr
;
10677 /* At this point we've found a "thread" token, which means
10678 the user is trying to set a watchpoint that triggers
10679 only in a specific thread. */
10683 error(_("You can specify only one thread."));
10685 /* Extract the thread ID from the next token. */
10686 thr
= parse_thread_id (value_start
, &endp
);
10688 /* Check if the user provided a valid thread ID. */
10689 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10690 invalid_thread_id_error (value_start
);
10692 thread
= thr
->global_num
;
10694 else if (toklen
== 4 && startswith (tok
, "mask"))
10696 /* We've found a "mask" token, which means the user wants to
10697 create a hardware watchpoint that is going to have the mask
10699 struct value
*mask_value
, *mark
;
10702 error(_("You can specify only one mask."));
10704 use_mask
= just_location
= true;
10706 mark
= value_mark ();
10707 mask_value
= parse_to_comma_and_eval (&value_start
);
10708 mask
= value_as_address (mask_value
);
10709 value_free_to_mark (mark
);
10712 /* We didn't recognize what we found. We should stop here. */
10715 /* Truncate the string and get rid of the "parameter value" pair before
10716 the arguments string is parsed by the parse_exp_1 function. */
10723 /* Parse the rest of the arguments. From here on out, everything
10724 is in terms of a newly allocated string instead of the original
10726 std::string
expression (arg
, exp_end
- arg
);
10727 exp_start
= arg
= expression
.c_str ();
10728 innermost_block_tracker tracker
;
10729 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10731 /* Remove trailing whitespace from the expression before saving it.
10732 This makes the eventual display of the expression string a bit
10734 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10737 /* Checking if the expression is not constant. */
10738 if (watchpoint_exp_is_const (exp
.get ()))
10742 len
= exp_end
- exp_start
;
10743 while (len
> 0 && isspace (exp_start
[len
- 1]))
10745 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10748 exp_valid_block
= tracker
.block ();
10749 struct value
*mark
= value_mark ();
10750 struct value
*val_as_value
= nullptr;
10751 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10754 if (val_as_value
!= NULL
&& just_location
)
10756 saved_bitpos
= value_bitpos (val_as_value
);
10757 saved_bitsize
= value_bitsize (val_as_value
);
10765 exp_valid_block
= NULL
;
10766 val
= release_value (value_addr (result
));
10767 value_free_to_mark (mark
);
10771 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10774 error (_("This target does not support masked watchpoints."));
10775 else if (ret
== -2)
10776 error (_("Invalid mask or memory region."));
10779 else if (val_as_value
!= NULL
)
10780 val
= release_value (val_as_value
);
10782 tok
= skip_spaces (arg
);
10783 end_tok
= skip_to_space (tok
);
10785 toklen
= end_tok
- tok
;
10786 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10788 tok
= cond_start
= end_tok
+ 1;
10789 innermost_block_tracker if_tracker
;
10790 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10792 /* The watchpoint expression may not be local, but the condition
10793 may still be. E.g.: `watch global if local > 0'. */
10794 cond_exp_valid_block
= if_tracker
.block ();
10799 error (_("Junk at end of command."));
10801 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10803 /* Save this because create_internal_breakpoint below invalidates
10805 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10807 /* If the expression is "local", then set up a "watchpoint scope"
10808 breakpoint at the point where we've left the scope of the watchpoint
10809 expression. Create the scope breakpoint before the watchpoint, so
10810 that we will encounter it first in bpstat_stop_status. */
10811 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10813 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10815 if (frame_id_p (caller_frame_id
))
10817 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10818 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10821 = create_internal_breakpoint (caller_arch
, caller_pc
,
10822 bp_watchpoint_scope
,
10823 &momentary_breakpoint_ops
);
10825 /* create_internal_breakpoint could invalidate WP_FRAME. */
10828 scope_breakpoint
->enable_state
= bp_enabled
;
10830 /* Automatically delete the breakpoint when it hits. */
10831 scope_breakpoint
->disposition
= disp_del
;
10833 /* Only break in the proper frame (help with recursion). */
10834 scope_breakpoint
->frame_id
= caller_frame_id
;
10836 /* Set the address at which we will stop. */
10837 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10838 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10839 scope_breakpoint
->loc
->address
10840 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10841 scope_breakpoint
->loc
->requested_address
,
10842 scope_breakpoint
->type
);
10846 /* Now set up the breakpoint. We create all watchpoints as hardware
10847 watchpoints here even if hardware watchpoints are turned off, a call
10848 to update_watchpoint later in this function will cause the type to
10849 drop back to bp_watchpoint (software watchpoint) if required. */
10851 if (accessflag
== hw_read
)
10852 bp_type
= bp_read_watchpoint
;
10853 else if (accessflag
== hw_access
)
10854 bp_type
= bp_access_watchpoint
;
10856 bp_type
= bp_hardware_watchpoint
;
10858 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10861 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10862 &masked_watchpoint_breakpoint_ops
);
10864 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10865 &watchpoint_breakpoint_ops
);
10866 w
->thread
= thread
;
10867 w
->disposition
= disp_donttouch
;
10868 w
->pspace
= current_program_space
;
10869 w
->exp
= std::move (exp
);
10870 w
->exp_valid_block
= exp_valid_block
;
10871 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10874 struct type
*t
= value_type (val
.get ());
10875 CORE_ADDR addr
= value_as_address (val
.get ());
10877 w
->exp_string_reparse
10878 = current_language
->watch_location_expression (t
, addr
).release ();
10880 w
->exp_string
= xstrprintf ("-location %.*s",
10881 (int) (exp_end
- exp_start
), exp_start
);
10884 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10888 w
->hw_wp_mask
= mask
;
10893 w
->val_bitpos
= saved_bitpos
;
10894 w
->val_bitsize
= saved_bitsize
;
10895 w
->val_valid
= true;
10899 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10901 w
->cond_string
= 0;
10903 if (frame_id_p (watchpoint_frame
))
10905 w
->watchpoint_frame
= watchpoint_frame
;
10906 w
->watchpoint_thread
= inferior_ptid
;
10910 w
->watchpoint_frame
= null_frame_id
;
10911 w
->watchpoint_thread
= null_ptid
;
10914 if (scope_breakpoint
!= NULL
)
10916 /* The scope breakpoint is related to the watchpoint. We will
10917 need to act on them together. */
10918 w
->related_breakpoint
= scope_breakpoint
;
10919 scope_breakpoint
->related_breakpoint
= w
.get ();
10922 if (!just_location
)
10923 value_free_to_mark (mark
);
10925 /* Finally update the new watchpoint. This creates the locations
10926 that should be inserted. */
10927 update_watchpoint (w
.get (), 1);
10929 install_breakpoint (internal
, std::move (w
), 1);
10932 /* Return count of debug registers needed to watch the given expression.
10933 If the watchpoint cannot be handled in hardware return zero. */
10936 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10938 int found_memory_cnt
= 0;
10940 /* Did the user specifically forbid us to use hardware watchpoints? */
10941 if (!can_use_hw_watchpoints
)
10944 gdb_assert (!vals
.empty ());
10945 struct value
*head
= vals
[0].get ();
10947 /* Make sure that the value of the expression depends only upon
10948 memory contents, and values computed from them within GDB. If we
10949 find any register references or function calls, we can't use a
10950 hardware watchpoint.
10952 The idea here is that evaluating an expression generates a series
10953 of values, one holding the value of every subexpression. (The
10954 expression a*b+c has five subexpressions: a, b, a*b, c, and
10955 a*b+c.) GDB's values hold almost enough information to establish
10956 the criteria given above --- they identify memory lvalues,
10957 register lvalues, computed values, etcetera. So we can evaluate
10958 the expression, and then scan the chain of values that leaves
10959 behind to decide whether we can detect any possible change to the
10960 expression's final value using only hardware watchpoints.
10962 However, I don't think that the values returned by inferior
10963 function calls are special in any way. So this function may not
10964 notice that an expression involving an inferior function call
10965 can't be watched with hardware watchpoints. FIXME. */
10966 for (const value_ref_ptr
&iter
: vals
)
10968 struct value
*v
= iter
.get ();
10970 if (VALUE_LVAL (v
) == lval_memory
)
10972 if (v
!= head
&& value_lazy (v
))
10973 /* A lazy memory lvalue in the chain is one that GDB never
10974 needed to fetch; we either just used its address (e.g.,
10975 `a' in `a.b') or we never needed it at all (e.g., `a'
10976 in `a,b'). This doesn't apply to HEAD; if that is
10977 lazy then it was not readable, but watch it anyway. */
10981 /* Ahh, memory we actually used! Check if we can cover
10982 it with hardware watchpoints. */
10983 struct type
*vtype
= check_typedef (value_type (v
));
10985 /* We only watch structs and arrays if user asked for it
10986 explicitly, never if they just happen to appear in a
10987 middle of some value chain. */
10989 || (vtype
->code () != TYPE_CODE_STRUCT
10990 && vtype
->code () != TYPE_CODE_ARRAY
))
10992 CORE_ADDR vaddr
= value_address (v
);
10996 len
= (target_exact_watchpoints
10997 && is_scalar_type_recursive (vtype
))?
10998 1 : TYPE_LENGTH (value_type (v
));
11000 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11004 found_memory_cnt
+= num_regs
;
11008 else if (VALUE_LVAL (v
) != not_lval
11009 && deprecated_value_modifiable (v
) == 0)
11010 return 0; /* These are values from the history (e.g., $1). */
11011 else if (VALUE_LVAL (v
) == lval_register
)
11012 return 0; /* Cannot watch a register with a HW watchpoint. */
11015 /* The expression itself looks suitable for using a hardware
11016 watchpoint, but give the target machine a chance to reject it. */
11017 return found_memory_cnt
;
11021 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11023 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11026 /* Options for the watch, awatch, and rwatch commands. */
11028 struct watch_options
11030 /* For -location. */
11031 bool location
= false;
11034 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
11036 Historically GDB always accepted both '-location' and '-l' flags for
11037 these commands (both flags being synonyms). When converting to the
11038 newer option scheme only '-location' is added here. That's fine (for
11039 backward compatibility) as any non-ambiguous prefix of a flag will be
11040 accepted, so '-l', '-loc', are now all accepted.
11042 What this means is that, if in the future, we add any new flag here
11043 that starts with '-l' then this will break backward compatibility, so
11044 please, don't do that! */
11046 static const gdb::option::option_def watch_option_defs
[] = {
11047 gdb::option::flag_option_def
<watch_options
> {
11049 [] (watch_options
*opt
) { return &opt
->location
; },
11051 This evaluates EXPRESSION and watches the memory to which is refers.\n\
11052 -l can be used as a short form of -location."),
11056 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
11059 static gdb::option::option_def_group
11060 make_watch_options_def_group (watch_options
*opts
)
11062 return {{watch_option_defs
}, opts
};
11065 /* A helper function that looks for the "-location" argument and then
11066 calls watch_command_1. */
11069 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
11071 watch_options opts
;
11072 auto grp
= make_watch_options_def_group (&opts
);
11073 gdb::option::process_options
11074 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
11075 if (arg
!= nullptr && *arg
== '\0')
11078 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
11081 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
11083 watch_command_completer (struct cmd_list_element
*ignore
,
11084 completion_tracker
&tracker
,
11085 const char *text
, const char * /*word*/)
11087 const auto group
= make_watch_options_def_group (nullptr);
11088 if (gdb::option::complete_options
11089 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
11092 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
11093 expression_completer (ignore
, tracker
, text
, word
);
11097 watch_command (const char *arg
, int from_tty
)
11099 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11103 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11105 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11109 rwatch_command (const char *arg
, int from_tty
)
11111 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11115 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11117 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11121 awatch_command (const char *arg
, int from_tty
)
11123 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11127 /* Data for the FSM that manages the until(location)/advance commands
11128 in infcmd.c. Here because it uses the mechanisms of
11131 struct until_break_fsm
: public thread_fsm
11133 /* The thread that was current when the command was executed. */
11136 /* The breakpoint set at the return address in the caller frame,
11137 plus breakpoints at all the destination locations. */
11138 std::vector
<breakpoint_up
> breakpoints
;
11140 until_break_fsm (struct interp
*cmd_interp
, int thread
,
11141 std::vector
<breakpoint_up
> &&breakpoints
)
11142 : thread_fsm (cmd_interp
),
11144 breakpoints (std::move (breakpoints
))
11148 void clean_up (struct thread_info
*thread
) override
;
11149 bool should_stop (struct thread_info
*thread
) override
;
11150 enum async_reply_reason
do_async_reply_reason () override
;
11153 /* Implementation of the 'should_stop' FSM method for the
11154 until(location)/advance commands. */
11157 until_break_fsm::should_stop (struct thread_info
*tp
)
11159 for (const breakpoint_up
&bp
: breakpoints
)
11160 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11161 bp
.get ()) != NULL
)
11170 /* Implementation of the 'clean_up' FSM method for the
11171 until(location)/advance commands. */
11174 until_break_fsm::clean_up (struct thread_info
*)
11176 /* Clean up our temporary breakpoints. */
11177 breakpoints
.clear ();
11178 delete_longjmp_breakpoint (thread
);
11181 /* Implementation of the 'async_reply_reason' FSM method for the
11182 until(location)/advance commands. */
11184 enum async_reply_reason
11185 until_break_fsm::do_async_reply_reason ()
11187 return EXEC_ASYNC_LOCATION_REACHED
;
11191 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11193 struct frame_info
*frame
;
11194 struct gdbarch
*frame_gdbarch
;
11195 struct frame_id stack_frame_id
;
11196 struct frame_id caller_frame_id
;
11198 struct thread_info
*tp
;
11200 clear_proceed_status (0);
11202 /* Set a breakpoint where the user wants it and at return from
11205 event_location_up location
= string_to_event_location (&arg
, current_language
);
11207 std::vector
<symtab_and_line
> sals
11208 = (last_displayed_sal_is_valid ()
11209 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11210 get_last_displayed_symtab (),
11211 get_last_displayed_line ())
11212 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11216 error (_("Couldn't get information on specified line."));
11219 error (_("Junk at end of arguments."));
11221 tp
= inferior_thread ();
11222 thread
= tp
->global_num
;
11224 /* Note linespec handling above invalidates the frame chain.
11225 Installing a breakpoint also invalidates the frame chain (as it
11226 may need to switch threads), so do any frame handling before
11229 frame
= get_selected_frame (NULL
);
11230 frame_gdbarch
= get_frame_arch (frame
);
11231 stack_frame_id
= get_stack_frame_id (frame
);
11232 caller_frame_id
= frame_unwind_caller_id (frame
);
11234 /* Keep within the current frame, or in frames called by the current
11237 std::vector
<breakpoint_up
> breakpoints
;
11239 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11241 if (frame_id_p (caller_frame_id
))
11243 struct symtab_and_line sal2
;
11244 struct gdbarch
*caller_gdbarch
;
11246 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11247 sal2
.pc
= frame_unwind_caller_pc (frame
);
11248 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11250 breakpoint_up caller_breakpoint
11251 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
11252 caller_frame_id
, bp_until
);
11253 breakpoints
.emplace_back (std::move (caller_breakpoint
));
11255 set_longjmp_breakpoint (tp
, caller_frame_id
);
11256 lj_deleter
.emplace (thread
);
11259 /* set_momentary_breakpoint could invalidate FRAME. */
11262 /* If the user told us to continue until a specified location, we
11263 don't specify a frame at which we need to stop. Otherwise,
11264 specify the selected frame, because we want to stop only at the
11265 very same frame. */
11266 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
11268 for (symtab_and_line
&sal
: sals
)
11270 resolve_sal_pc (&sal
);
11272 breakpoint_up location_breakpoint
11273 = set_momentary_breakpoint (frame_gdbarch
, sal
,
11274 stop_frame_id
, bp_until
);
11275 breakpoints
.emplace_back (std::move (location_breakpoint
));
11278 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11279 std::move (breakpoints
));
11282 lj_deleter
->release ();
11284 proceed (-1, GDB_SIGNAL_DEFAULT
);
11287 /* This function attempts to parse an optional "if <cond>" clause
11288 from the arg string. If one is not found, it returns NULL.
11290 Else, it returns a pointer to the condition string. (It does not
11291 attempt to evaluate the string against a particular block.) And,
11292 it updates arg to point to the first character following the parsed
11293 if clause in the arg string. */
11296 ep_parse_optional_if_clause (const char **arg
)
11298 const char *cond_string
;
11300 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11303 /* Skip the "if" keyword. */
11306 /* Skip any extra leading whitespace, and record the start of the
11307 condition string. */
11308 *arg
= skip_spaces (*arg
);
11309 cond_string
= *arg
;
11311 /* Assume that the condition occupies the remainder of the arg
11313 (*arg
) += strlen (cond_string
);
11315 return cond_string
;
11318 /* Commands to deal with catching events, such as signals, exceptions,
11319 process start/exit, etc. */
11323 catch_fork_temporary
, catch_vfork_temporary
,
11324 catch_fork_permanent
, catch_vfork_permanent
11329 catch_fork_command_1 (const char *arg
, int from_tty
,
11330 struct cmd_list_element
*command
)
11332 struct gdbarch
*gdbarch
= get_current_arch ();
11333 const char *cond_string
= NULL
;
11334 catch_fork_kind fork_kind
;
11336 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11337 bool temp
= (fork_kind
== catch_fork_temporary
11338 || fork_kind
== catch_vfork_temporary
);
11342 arg
= skip_spaces (arg
);
11344 /* The allowed syntax is:
11346 catch [v]fork if <cond>
11348 First, check if there's an if clause. */
11349 cond_string
= ep_parse_optional_if_clause (&arg
);
11351 if ((*arg
!= '\0') && !isspace (*arg
))
11352 error (_("Junk at end of arguments."));
11354 /* If this target supports it, create a fork or vfork catchpoint
11355 and enable reporting of such events. */
11358 case catch_fork_temporary
:
11359 case catch_fork_permanent
:
11360 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11361 &catch_fork_breakpoint_ops
);
11363 case catch_vfork_temporary
:
11364 case catch_vfork_permanent
:
11365 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11366 &catch_vfork_breakpoint_ops
);
11369 error (_("unsupported or unknown fork kind; cannot catch it"));
11375 catch_exec_command_1 (const char *arg
, int from_tty
,
11376 struct cmd_list_element
*command
)
11378 struct gdbarch
*gdbarch
= get_current_arch ();
11379 const char *cond_string
= NULL
;
11380 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11384 arg
= skip_spaces (arg
);
11386 /* The allowed syntax is:
11388 catch exec if <cond>
11390 First, check if there's an if clause. */
11391 cond_string
= ep_parse_optional_if_clause (&arg
);
11393 if ((*arg
!= '\0') && !isspace (*arg
))
11394 error (_("Junk at end of arguments."));
11396 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11397 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
,
11398 &catch_exec_breakpoint_ops
);
11399 c
->exec_pathname
= NULL
;
11401 install_breakpoint (0, std::move (c
), 1);
11405 init_ada_exception_breakpoint (struct breakpoint
*b
,
11406 struct gdbarch
*gdbarch
,
11407 struct symtab_and_line sal
,
11408 const char *addr_string
,
11409 const struct breakpoint_ops
*ops
,
11416 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11418 loc_gdbarch
= gdbarch
;
11420 describe_other_breakpoints (loc_gdbarch
,
11421 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11422 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11423 version for exception catchpoints, because two catchpoints
11424 used for different exception names will use the same address.
11425 In this case, a "breakpoint ... also set at..." warning is
11426 unproductive. Besides, the warning phrasing is also a bit
11427 inappropriate, we should use the word catchpoint, and tell
11428 the user what type of catchpoint it is. The above is good
11429 enough for now, though. */
11432 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11434 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11435 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11436 b
->location
= string_to_event_location (&addr_string
,
11437 language_def (language_ada
));
11438 b
->language
= language_ada
;
11443 /* Compare two breakpoints and return a strcmp-like result. */
11446 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11448 uintptr_t ua
= (uintptr_t) a
;
11449 uintptr_t ub
= (uintptr_t) b
;
11451 if (a
->number
< b
->number
)
11453 else if (a
->number
> b
->number
)
11456 /* Now sort by address, in case we see, e..g, two breakpoints with
11460 return ua
> ub
? 1 : 0;
11463 /* Delete breakpoints by address or line. */
11466 clear_command (const char *arg
, int from_tty
)
11470 std::vector
<symtab_and_line
> decoded_sals
;
11471 symtab_and_line last_sal
;
11472 gdb::array_view
<symtab_and_line
> sals
;
11476 = decode_line_with_current_source (arg
,
11477 (DECODE_LINE_FUNFIRSTLINE
11478 | DECODE_LINE_LIST_MODE
));
11480 sals
= decoded_sals
;
11484 /* Set sal's line, symtab, pc, and pspace to the values
11485 corresponding to the last call to print_frame_info. If the
11486 codepoint is not valid, this will set all the fields to 0. */
11487 last_sal
= get_last_displayed_sal ();
11488 if (last_sal
.symtab
== 0)
11489 error (_("No source file specified."));
11495 /* We don't call resolve_sal_pc here. That's not as bad as it
11496 seems, because all existing breakpoints typically have both
11497 file/line and pc set. So, if clear is given file/line, we can
11498 match this to existing breakpoint without obtaining pc at all.
11500 We only support clearing given the address explicitly
11501 present in breakpoint table. Say, we've set breakpoint
11502 at file:line. There were several PC values for that file:line,
11503 due to optimization, all in one block.
11505 We've picked one PC value. If "clear" is issued with another
11506 PC corresponding to the same file:line, the breakpoint won't
11507 be cleared. We probably can still clear the breakpoint, but
11508 since the other PC value is never presented to user, user
11509 can only find it by guessing, and it does not seem important
11510 to support that. */
11512 /* For each line spec given, delete bps which correspond to it. Do
11513 it in two passes, solely to preserve the current behavior that
11514 from_tty is forced true if we delete more than one
11517 std::vector
<struct breakpoint
*> found
;
11518 for (const auto &sal
: sals
)
11520 const char *sal_fullname
;
11522 /* If exact pc given, clear bpts at that pc.
11523 If line given (pc == 0), clear all bpts on specified line.
11524 If defaulting, clear all bpts on default line
11527 defaulting sal.pc != 0 tests to do
11532 1 0 <can't happen> */
11534 sal_fullname
= (sal
.symtab
== NULL
11535 ? NULL
: symtab_to_fullname (sal
.symtab
));
11537 /* Find all matching breakpoints and add them to 'found'. */
11538 for (breakpoint
*b
: all_breakpoints ())
11541 /* Are we going to delete b? */
11542 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11544 struct bp_location
*loc
= b
->loc
;
11545 for (; loc
; loc
= loc
->next
)
11547 /* If the user specified file:line, don't allow a PC
11548 match. This matches historical gdb behavior. */
11549 int pc_match
= (!sal
.explicit_line
11551 && (loc
->pspace
== sal
.pspace
)
11552 && (loc
->address
== sal
.pc
)
11553 && (!section_is_overlay (loc
->section
)
11554 || loc
->section
== sal
.section
));
11555 int line_match
= 0;
11557 if ((default_match
|| sal
.explicit_line
)
11558 && loc
->symtab
!= NULL
11559 && sal_fullname
!= NULL
11560 && sal
.pspace
== loc
->pspace
11561 && loc
->line_number
== sal
.line
11562 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11563 sal_fullname
) == 0)
11566 if (pc_match
|| line_match
)
11575 found
.push_back (b
);
11579 /* Now go thru the 'found' chain and delete them. */
11580 if (found
.empty ())
11583 error (_("No breakpoint at %s."), arg
);
11585 error (_("No breakpoint at this line."));
11588 /* Remove duplicates from the vec. */
11589 std::sort (found
.begin (), found
.end (),
11590 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11592 return compare_breakpoints (bp_a
, bp_b
) < 0;
11594 found
.erase (std::unique (found
.begin (), found
.end (),
11595 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11597 return compare_breakpoints (bp_a
, bp_b
) == 0;
11601 if (found
.size () > 1)
11602 from_tty
= 1; /* Always report if deleted more than one. */
11605 if (found
.size () == 1)
11606 printf_unfiltered (_("Deleted breakpoint "));
11608 printf_unfiltered (_("Deleted breakpoints "));
11611 for (breakpoint
*iter
: found
)
11614 printf_unfiltered ("%d ", iter
->number
);
11615 delete_breakpoint (iter
);
11618 putchar_unfiltered ('\n');
11621 /* Delete breakpoint in BS if they are `delete' breakpoints and
11622 all breakpoints that are marked for deletion, whether hit or not.
11623 This is called after any breakpoint is hit, or after errors. */
11626 breakpoint_auto_delete (bpstat bs
)
11628 struct breakpoint
*b
, *b_tmp
;
11630 for (; bs
; bs
= bs
->next
)
11631 if (bs
->breakpoint_at
11632 && bs
->breakpoint_at
->disposition
== disp_del
11634 delete_breakpoint (bs
->breakpoint_at
);
11636 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11638 if (b
->disposition
== disp_del_at_next_stop
)
11639 delete_breakpoint (b
);
11643 /* A comparison function for bp_location AP and BP being interfaced to
11644 std::sort. Sort elements primarily by their ADDRESS (no matter what
11645 bl_address_is_meaningful says), secondarily by ordering first
11646 permanent elements and terciarily just ensuring the array is sorted
11647 stable way despite std::sort being an unstable algorithm. */
11650 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11652 if (a
->address
!= b
->address
)
11653 return a
->address
< b
->address
;
11655 /* Sort locations at the same address by their pspace number, keeping
11656 locations of the same inferior (in a multi-inferior environment)
11659 if (a
->pspace
->num
!= b
->pspace
->num
)
11660 return a
->pspace
->num
< b
->pspace
->num
;
11662 /* Sort permanent breakpoints first. */
11663 if (a
->permanent
!= b
->permanent
)
11664 return a
->permanent
> b
->permanent
;
11666 /* Sort by type in order to make duplicate determination easier.
11667 See update_global_location_list. This is kept in sync with
11668 breakpoint_locations_match. */
11669 if (a
->loc_type
< b
->loc_type
)
11672 /* Likewise, for range-breakpoints, sort by length. */
11673 if (a
->loc_type
== bp_loc_hardware_breakpoint
11674 && b
->loc_type
== bp_loc_hardware_breakpoint
11675 && a
->length
< b
->length
)
11678 /* Make the internal GDB representation stable across GDB runs
11679 where A and B memory inside GDB can differ. Breakpoint locations of
11680 the same type at the same address can be sorted in arbitrary order. */
11682 if (a
->owner
->number
!= b
->owner
->number
)
11683 return a
->owner
->number
< b
->owner
->number
;
11688 /* Set bp_locations_placed_address_before_address_max and
11689 bp_locations_shadow_len_after_address_max according to the current
11690 content of the bp_locations array. */
11693 bp_locations_target_extensions_update (void)
11695 struct bp_location
*bl
, **blp_tmp
;
11697 bp_locations_placed_address_before_address_max
= 0;
11698 bp_locations_shadow_len_after_address_max
= 0;
11700 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11702 CORE_ADDR start
, end
, addr
;
11704 if (!bp_location_has_shadow (bl
))
11707 start
= bl
->target_info
.placed_address
;
11708 end
= start
+ bl
->target_info
.shadow_len
;
11710 gdb_assert (bl
->address
>= start
);
11711 addr
= bl
->address
- start
;
11712 if (addr
> bp_locations_placed_address_before_address_max
)
11713 bp_locations_placed_address_before_address_max
= addr
;
11715 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11717 gdb_assert (bl
->address
< end
);
11718 addr
= end
- bl
->address
;
11719 if (addr
> bp_locations_shadow_len_after_address_max
)
11720 bp_locations_shadow_len_after_address_max
= addr
;
11724 /* Download tracepoint locations if they haven't been. */
11727 download_tracepoint_locations (void)
11729 struct breakpoint
*b
;
11730 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11732 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11734 ALL_TRACEPOINTS (b
)
11736 struct bp_location
*bl
;
11737 struct tracepoint
*t
;
11738 int bp_location_downloaded
= 0;
11740 if ((b
->type
== bp_fast_tracepoint
11741 ? !may_insert_fast_tracepoints
11742 : !may_insert_tracepoints
))
11745 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11747 if (target_can_download_tracepoint ())
11748 can_download_tracepoint
= TRIBOOL_TRUE
;
11750 can_download_tracepoint
= TRIBOOL_FALSE
;
11753 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11756 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11758 /* In tracepoint, locations are _never_ duplicated, so
11759 should_be_inserted is equivalent to
11760 unduplicated_should_be_inserted. */
11761 if (!should_be_inserted (bl
) || bl
->inserted
)
11764 switch_to_program_space_and_thread (bl
->pspace
);
11766 target_download_tracepoint (bl
);
11769 bp_location_downloaded
= 1;
11771 t
= (struct tracepoint
*) b
;
11772 t
->number_on_target
= b
->number
;
11773 if (bp_location_downloaded
)
11774 gdb::observers::breakpoint_modified
.notify (b
);
11778 /* Swap the insertion/duplication state between two locations. */
11781 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11783 const int left_inserted
= left
->inserted
;
11784 const int left_duplicate
= left
->duplicate
;
11785 const int left_needs_update
= left
->needs_update
;
11786 const struct bp_target_info left_target_info
= left
->target_info
;
11788 /* Locations of tracepoints can never be duplicated. */
11789 if (is_tracepoint (left
->owner
))
11790 gdb_assert (!left
->duplicate
);
11791 if (is_tracepoint (right
->owner
))
11792 gdb_assert (!right
->duplicate
);
11794 left
->inserted
= right
->inserted
;
11795 left
->duplicate
= right
->duplicate
;
11796 left
->needs_update
= right
->needs_update
;
11797 left
->target_info
= right
->target_info
;
11798 right
->inserted
= left_inserted
;
11799 right
->duplicate
= left_duplicate
;
11800 right
->needs_update
= left_needs_update
;
11801 right
->target_info
= left_target_info
;
11804 /* Force the re-insertion of the locations at ADDRESS. This is called
11805 once a new/deleted/modified duplicate location is found and we are evaluating
11806 conditions on the target's side. Such conditions need to be updated on
11810 force_breakpoint_reinsertion (struct bp_location
*bl
)
11812 struct bp_location
**locp
= NULL
, **loc2p
;
11813 struct bp_location
*loc
;
11814 CORE_ADDR address
= 0;
11817 address
= bl
->address
;
11818 pspace_num
= bl
->pspace
->num
;
11820 /* This is only meaningful if the target is
11821 evaluating conditions and if the user has
11822 opted for condition evaluation on the target's
11824 if (gdb_evaluates_breakpoint_condition_p ()
11825 || !target_supports_evaluation_of_breakpoint_conditions ())
11828 /* Flag all breakpoint locations with this address and
11829 the same program space as the location
11830 as "its condition has changed". We need to
11831 update the conditions on the target's side. */
11832 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11836 if (!is_breakpoint (loc
->owner
)
11837 || pspace_num
!= loc
->pspace
->num
)
11840 /* Flag the location appropriately. We use a different state to
11841 let everyone know that we already updated the set of locations
11842 with addr bl->address and program space bl->pspace. This is so
11843 we don't have to keep calling these functions just to mark locations
11844 that have already been marked. */
11845 loc
->condition_changed
= condition_updated
;
11847 /* Free the agent expression bytecode as well. We will compute
11849 loc
->cond_bytecode
.reset ();
11853 /* Called whether new breakpoints are created, or existing breakpoints
11854 deleted, to update the global location list and recompute which
11855 locations are duplicate of which.
11857 The INSERT_MODE flag determines whether locations may not, may, or
11858 shall be inserted now. See 'enum ugll_insert_mode' for more
11862 update_global_location_list (enum ugll_insert_mode insert_mode
)
11864 struct bp_location
**locp
, *loc
;
11865 /* Last breakpoint location address that was marked for update. */
11866 CORE_ADDR last_addr
= 0;
11867 /* Last breakpoint location program space that was marked for update. */
11868 int last_pspace_num
= -1;
11870 /* Used in the duplicates detection below. When iterating over all
11871 bp_locations, points to the first bp_location of a given address.
11872 Breakpoints and watchpoints of different types are never
11873 duplicates of each other. Keep one pointer for each type of
11874 breakpoint/watchpoint, so we only need to loop over all locations
11876 struct bp_location
*bp_loc_first
; /* breakpoint */
11877 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11878 struct bp_location
*awp_loc_first
; /* access watchpoint */
11879 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11881 /* Saved former bp_locations array which we compare against the newly
11882 built bp_locations from the current state of ALL_BREAKPOINTS. */
11883 struct bp_location
**old_locp
;
11884 unsigned old_locations_count
;
11885 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11887 old_locations_count
= bp_locations_count
;
11888 bp_locations
= NULL
;
11889 bp_locations_count
= 0;
11891 for (breakpoint
*b
: all_breakpoints ())
11892 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11893 bp_locations_count
++;
11895 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11896 locp
= bp_locations
;
11897 for (breakpoint
*b
: all_breakpoints ())
11898 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11901 /* See if we need to "upgrade" a software breakpoint to a hardware
11902 breakpoint. Do this before deciding whether locations are
11903 duplicates. Also do this before sorting because sorting order
11904 depends on location type. */
11905 for (locp
= bp_locations
;
11906 locp
< bp_locations
+ bp_locations_count
;
11910 if (!loc
->inserted
&& should_be_inserted (loc
))
11911 handle_automatic_hardware_breakpoints (loc
);
11914 std::sort (bp_locations
, bp_locations
+ bp_locations_count
,
11915 bp_location_is_less_than
);
11917 bp_locations_target_extensions_update ();
11919 /* Identify bp_location instances that are no longer present in the
11920 new list, and therefore should be freed. Note that it's not
11921 necessary that those locations should be removed from inferior --
11922 if there's another location at the same address (previously
11923 marked as duplicate), we don't need to remove/insert the
11926 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11927 and former bp_location array state respectively. */
11929 locp
= bp_locations
;
11930 for (old_locp
= old_locations
.get ();
11931 old_locp
< old_locations
.get () + old_locations_count
;
11934 struct bp_location
*old_loc
= *old_locp
;
11935 struct bp_location
**loc2p
;
11937 /* Tells if 'old_loc' is found among the new locations. If
11938 not, we have to free it. */
11939 int found_object
= 0;
11940 /* Tells if the location should remain inserted in the target. */
11941 int keep_in_target
= 0;
11944 /* Skip LOCP entries which will definitely never be needed.
11945 Stop either at or being the one matching OLD_LOC. */
11946 while (locp
< bp_locations
+ bp_locations_count
11947 && (*locp
)->address
< old_loc
->address
)
11951 (loc2p
< bp_locations
+ bp_locations_count
11952 && (*loc2p
)->address
== old_loc
->address
);
11955 /* Check if this is a new/duplicated location or a duplicated
11956 location that had its condition modified. If so, we want to send
11957 its condition to the target if evaluation of conditions is taking
11959 if ((*loc2p
)->condition_changed
== condition_modified
11960 && (last_addr
!= old_loc
->address
11961 || last_pspace_num
!= old_loc
->pspace
->num
))
11963 force_breakpoint_reinsertion (*loc2p
);
11964 last_pspace_num
= old_loc
->pspace
->num
;
11967 if (*loc2p
== old_loc
)
11971 /* We have already handled this address, update it so that we don't
11972 have to go through updates again. */
11973 last_addr
= old_loc
->address
;
11975 /* Target-side condition evaluation: Handle deleted locations. */
11977 force_breakpoint_reinsertion (old_loc
);
11979 /* If this location is no longer present, and inserted, look if
11980 there's maybe a new location at the same address. If so,
11981 mark that one inserted, and don't remove this one. This is
11982 needed so that we don't have a time window where a breakpoint
11983 at certain location is not inserted. */
11985 if (old_loc
->inserted
)
11987 /* If the location is inserted now, we might have to remove
11990 if (found_object
&& should_be_inserted (old_loc
))
11992 /* The location is still present in the location list,
11993 and still should be inserted. Don't do anything. */
11994 keep_in_target
= 1;
11998 /* This location still exists, but it won't be kept in the
11999 target since it may have been disabled. We proceed to
12000 remove its target-side condition. */
12002 /* The location is either no longer present, or got
12003 disabled. See if there's another location at the
12004 same address, in which case we don't need to remove
12005 this one from the target. */
12007 /* OLD_LOC comes from existing struct breakpoint. */
12008 if (bl_address_is_meaningful (old_loc
))
12011 (loc2p
< bp_locations
+ bp_locations_count
12012 && (*loc2p
)->address
== old_loc
->address
);
12015 struct bp_location
*loc2
= *loc2p
;
12017 if (loc2
== old_loc
)
12020 if (breakpoint_locations_match (loc2
, old_loc
))
12022 /* Read watchpoint locations are switched to
12023 access watchpoints, if the former are not
12024 supported, but the latter are. */
12025 if (is_hardware_watchpoint (old_loc
->owner
))
12027 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12028 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12031 /* loc2 is a duplicated location. We need to check
12032 if it should be inserted in case it will be
12034 if (unduplicated_should_be_inserted (loc2
))
12036 swap_insertion (old_loc
, loc2
);
12037 keep_in_target
= 1;
12045 if (!keep_in_target
)
12047 if (remove_breakpoint (old_loc
))
12049 /* This is just about all we can do. We could keep
12050 this location on the global list, and try to
12051 remove it next time, but there's no particular
12052 reason why we will succeed next time.
12054 Note that at this point, old_loc->owner is still
12055 valid, as delete_breakpoint frees the breakpoint
12056 only after calling us. */
12057 printf_filtered (_("warning: Error removing "
12058 "breakpoint %d\n"),
12059 old_loc
->owner
->number
);
12067 if (removed
&& target_is_non_stop_p ()
12068 && need_moribund_for_location_type (old_loc
))
12070 /* This location was removed from the target. In
12071 non-stop mode, a race condition is possible where
12072 we've removed a breakpoint, but stop events for that
12073 breakpoint are already queued and will arrive later.
12074 We apply an heuristic to be able to distinguish such
12075 SIGTRAPs from other random SIGTRAPs: we keep this
12076 breakpoint location for a bit, and will retire it
12077 after we see some number of events. The theory here
12078 is that reporting of events should, "on the average",
12079 be fair, so after a while we'll see events from all
12080 threads that have anything of interest, and no longer
12081 need to keep this breakpoint location around. We
12082 don't hold locations forever so to reduce chances of
12083 mistaking a non-breakpoint SIGTRAP for a breakpoint
12086 The heuristic failing can be disastrous on
12087 decr_pc_after_break targets.
12089 On decr_pc_after_break targets, like e.g., x86-linux,
12090 if we fail to recognize a late breakpoint SIGTRAP,
12091 because events_till_retirement has reached 0 too
12092 soon, we'll fail to do the PC adjustment, and report
12093 a random SIGTRAP to the user. When the user resumes
12094 the inferior, it will most likely immediately crash
12095 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12096 corrupted, because of being resumed e.g., in the
12097 middle of a multi-byte instruction, or skipped a
12098 one-byte instruction. This was actually seen happen
12099 on native x86-linux, and should be less rare on
12100 targets that do not support new thread events, like
12101 remote, due to the heuristic depending on
12104 Mistaking a random SIGTRAP for a breakpoint trap
12105 causes similar symptoms (PC adjustment applied when
12106 it shouldn't), but then again, playing with SIGTRAPs
12107 behind the debugger's back is asking for trouble.
12109 Since hardware watchpoint traps are always
12110 distinguishable from other traps, so we don't need to
12111 apply keep hardware watchpoint moribund locations
12112 around. We simply always ignore hardware watchpoint
12113 traps we can no longer explain. */
12115 process_stratum_target
*proc_target
= nullptr;
12116 for (inferior
*inf
: all_inferiors ())
12117 if (inf
->pspace
== old_loc
->pspace
)
12119 proc_target
= inf
->process_target ();
12122 if (proc_target
!= nullptr)
12123 old_loc
->events_till_retirement
12124 = 3 * (thread_count (proc_target
) + 1);
12126 old_loc
->events_till_retirement
= 1;
12127 old_loc
->owner
= NULL
;
12129 moribund_locations
.push_back (old_loc
);
12133 old_loc
->owner
= NULL
;
12134 decref_bp_location (&old_loc
);
12139 /* Rescan breakpoints at the same address and section, marking the
12140 first one as "first" and any others as "duplicates". This is so
12141 that the bpt instruction is only inserted once. If we have a
12142 permanent breakpoint at the same place as BPT, make that one the
12143 official one, and the rest as duplicates. Permanent breakpoints
12144 are sorted first for the same address.
12146 Do the same for hardware watchpoints, but also considering the
12147 watchpoint's type (regular/access/read) and length. */
12149 bp_loc_first
= NULL
;
12150 wp_loc_first
= NULL
;
12151 awp_loc_first
= NULL
;
12152 rwp_loc_first
= NULL
;
12153 ALL_BP_LOCATIONS (loc
, locp
)
12155 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12157 struct bp_location
**loc_first_p
;
12158 breakpoint
*b
= loc
->owner
;
12160 if (!unduplicated_should_be_inserted (loc
)
12161 || !bl_address_is_meaningful (loc
)
12162 /* Don't detect duplicate for tracepoint locations because they are
12163 never duplicated. See the comments in field `duplicate' of
12164 `struct bp_location'. */
12165 || is_tracepoint (b
))
12167 /* Clear the condition modification flag. */
12168 loc
->condition_changed
= condition_unchanged
;
12172 if (b
->type
== bp_hardware_watchpoint
)
12173 loc_first_p
= &wp_loc_first
;
12174 else if (b
->type
== bp_read_watchpoint
)
12175 loc_first_p
= &rwp_loc_first
;
12176 else if (b
->type
== bp_access_watchpoint
)
12177 loc_first_p
= &awp_loc_first
;
12179 loc_first_p
= &bp_loc_first
;
12181 if (*loc_first_p
== NULL
12182 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12183 || !breakpoint_locations_match (loc
, *loc_first_p
))
12185 *loc_first_p
= loc
;
12186 loc
->duplicate
= 0;
12188 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12190 loc
->needs_update
= 1;
12191 /* Clear the condition modification flag. */
12192 loc
->condition_changed
= condition_unchanged
;
12198 /* This and the above ensure the invariant that the first location
12199 is not duplicated, and is the inserted one.
12200 All following are marked as duplicated, and are not inserted. */
12202 swap_insertion (loc
, *loc_first_p
);
12203 loc
->duplicate
= 1;
12205 /* Clear the condition modification flag. */
12206 loc
->condition_changed
= condition_unchanged
;
12209 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12211 if (insert_mode
!= UGLL_DONT_INSERT
)
12212 insert_breakpoint_locations ();
12215 /* Even though the caller told us to not insert new
12216 locations, we may still need to update conditions on the
12217 target's side of breakpoints that were already inserted
12218 if the target is evaluating breakpoint conditions. We
12219 only update conditions for locations that are marked
12221 update_inserted_breakpoint_locations ();
12225 if (insert_mode
!= UGLL_DONT_INSERT
)
12226 download_tracepoint_locations ();
12230 breakpoint_retire_moribund (void)
12232 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
12234 struct bp_location
*loc
= moribund_locations
[ix
];
12235 if (--(loc
->events_till_retirement
) == 0)
12237 decref_bp_location (&loc
);
12238 unordered_remove (moribund_locations
, ix
);
12245 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12250 update_global_location_list (insert_mode
);
12252 catch (const gdb_exception_error
&e
)
12257 /* Clear BKP from a BPS. */
12260 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12264 for (bs
= bps
; bs
; bs
= bs
->next
)
12265 if (bs
->breakpoint_at
== bpt
)
12267 bs
->breakpoint_at
= NULL
;
12268 bs
->old_val
= NULL
;
12269 /* bs->commands will be freed later. */
12273 /* Callback for iterate_over_threads. */
12275 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12277 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12279 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12283 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12287 say_where (struct breakpoint
*b
)
12289 struct value_print_options opts
;
12291 get_user_print_options (&opts
);
12293 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12295 if (b
->loc
== NULL
)
12297 /* For pending locations, the output differs slightly based
12298 on b->extra_string. If this is non-NULL, it contains either
12299 a condition or dprintf arguments. */
12300 if (b
->extra_string
== NULL
)
12302 printf_filtered (_(" (%s) pending."),
12303 event_location_to_string (b
->location
.get ()));
12305 else if (b
->type
== bp_dprintf
)
12307 printf_filtered (_(" (%s,%s) pending."),
12308 event_location_to_string (b
->location
.get ()),
12313 printf_filtered (_(" (%s %s) pending."),
12314 event_location_to_string (b
->location
.get ()),
12320 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12321 printf_filtered (" at %ps",
12322 styled_string (address_style
.style (),
12323 paddress (b
->loc
->gdbarch
,
12324 b
->loc
->address
)));
12325 if (b
->loc
->symtab
!= NULL
)
12327 /* If there is a single location, we can print the location
12329 if (b
->loc
->next
== NULL
)
12331 const char *filename
12332 = symtab_to_filename_for_display (b
->loc
->symtab
);
12333 printf_filtered (": file %ps, line %d.",
12334 styled_string (file_name_style
.style (),
12336 b
->loc
->line_number
);
12339 /* This is not ideal, but each location may have a
12340 different file name, and this at least reflects the
12341 real situation somewhat. */
12342 printf_filtered (": %s.",
12343 event_location_to_string (b
->location
.get ()));
12348 struct bp_location
*loc
= b
->loc
;
12350 for (; loc
; loc
= loc
->next
)
12352 printf_filtered (" (%d locations)", n
);
12357 bp_location::~bp_location ()
12359 xfree (function_name
);
12362 /* Destructor for the breakpoint base class. */
12364 breakpoint::~breakpoint ()
12366 xfree (this->cond_string
);
12367 xfree (this->extra_string
);
12370 static struct bp_location
*
12371 base_breakpoint_allocate_location (struct breakpoint
*self
)
12373 return new bp_location (self
);
12377 base_breakpoint_re_set (struct breakpoint
*b
)
12379 /* Nothing to re-set. */
12382 #define internal_error_pure_virtual_called() \
12383 gdb_assert_not_reached ("pure virtual function called")
12386 base_breakpoint_insert_location (struct bp_location
*bl
)
12388 internal_error_pure_virtual_called ();
12392 base_breakpoint_remove_location (struct bp_location
*bl
,
12393 enum remove_bp_reason reason
)
12395 internal_error_pure_virtual_called ();
12399 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12400 const address_space
*aspace
,
12402 const struct target_waitstatus
*ws
)
12404 internal_error_pure_virtual_called ();
12408 base_breakpoint_check_status (bpstat bs
)
12413 /* A "works_in_software_mode" breakpoint_ops method that just internal
12417 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12419 internal_error_pure_virtual_called ();
12422 /* A "resources_needed" breakpoint_ops method that just internal
12426 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12428 internal_error_pure_virtual_called ();
12431 static enum print_stop_action
12432 base_breakpoint_print_it (bpstat bs
)
12434 internal_error_pure_virtual_called ();
12438 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12439 struct ui_out
*uiout
)
12445 base_breakpoint_print_mention (struct breakpoint
*b
)
12447 internal_error_pure_virtual_called ();
12451 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12453 internal_error_pure_virtual_called ();
12457 base_breakpoint_create_sals_from_location
12458 (struct event_location
*location
,
12459 struct linespec_result
*canonical
,
12460 enum bptype type_wanted
)
12462 internal_error_pure_virtual_called ();
12466 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12467 struct linespec_result
*c
,
12468 gdb::unique_xmalloc_ptr
<char> cond_string
,
12469 gdb::unique_xmalloc_ptr
<char> extra_string
,
12470 enum bptype type_wanted
,
12471 enum bpdisp disposition
,
12473 int task
, int ignore_count
,
12474 const struct breakpoint_ops
*o
,
12475 int from_tty
, int enabled
,
12476 int internal
, unsigned flags
)
12478 internal_error_pure_virtual_called ();
12481 static std::vector
<symtab_and_line
>
12482 base_breakpoint_decode_location (struct breakpoint
*b
,
12483 struct event_location
*location
,
12484 struct program_space
*search_pspace
)
12486 internal_error_pure_virtual_called ();
12489 /* The default 'explains_signal' method. */
12492 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12497 /* The default "after_condition_true" method. */
12500 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12502 /* Nothing to do. */
12505 struct breakpoint_ops base_breakpoint_ops
=
12507 base_breakpoint_allocate_location
,
12508 base_breakpoint_re_set
,
12509 base_breakpoint_insert_location
,
12510 base_breakpoint_remove_location
,
12511 base_breakpoint_breakpoint_hit
,
12512 base_breakpoint_check_status
,
12513 base_breakpoint_resources_needed
,
12514 base_breakpoint_works_in_software_mode
,
12515 base_breakpoint_print_it
,
12517 base_breakpoint_print_one_detail
,
12518 base_breakpoint_print_mention
,
12519 base_breakpoint_print_recreate
,
12520 base_breakpoint_create_sals_from_location
,
12521 base_breakpoint_create_breakpoints_sal
,
12522 base_breakpoint_decode_location
,
12523 base_breakpoint_explains_signal
,
12524 base_breakpoint_after_condition_true
,
12527 /* Default breakpoint_ops methods. */
12530 bkpt_re_set (struct breakpoint
*b
)
12532 /* FIXME: is this still reachable? */
12533 if (breakpoint_event_location_empty_p (b
))
12535 /* Anything without a location can't be re-set. */
12536 delete_breakpoint (b
);
12540 breakpoint_re_set_default (b
);
12544 bkpt_insert_location (struct bp_location
*bl
)
12546 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12548 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12549 bl
->target_info
.placed_address
= addr
;
12551 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12552 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12554 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12558 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12560 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12561 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12563 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12567 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12568 const address_space
*aspace
, CORE_ADDR bp_addr
,
12569 const struct target_waitstatus
*ws
)
12571 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12572 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12575 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12579 if (overlay_debugging
/* unmapped overlay section */
12580 && section_is_overlay (bl
->section
)
12581 && !section_is_mapped (bl
->section
))
12588 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12589 const address_space
*aspace
, CORE_ADDR bp_addr
,
12590 const struct target_waitstatus
*ws
)
12592 if (dprintf_style
== dprintf_style_agent
12593 && target_can_run_breakpoint_commands ())
12595 /* An agent-style dprintf never causes a stop. If we see a trap
12596 for this address it must be for a breakpoint that happens to
12597 be set at the same address. */
12601 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12605 bkpt_resources_needed (const struct bp_location
*bl
)
12607 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12612 static enum print_stop_action
12613 bkpt_print_it (bpstat bs
)
12615 struct breakpoint
*b
;
12616 const struct bp_location
*bl
;
12618 struct ui_out
*uiout
= current_uiout
;
12620 gdb_assert (bs
->bp_location_at
!= NULL
);
12622 bl
= bs
->bp_location_at
.get ();
12623 b
= bs
->breakpoint_at
;
12625 bp_temp
= b
->disposition
== disp_del
;
12626 if (bl
->address
!= bl
->requested_address
)
12627 breakpoint_adjustment_warning (bl
->requested_address
,
12630 annotate_breakpoint (b
->number
);
12631 maybe_print_thread_hit_breakpoint (uiout
);
12633 if (uiout
->is_mi_like_p ())
12635 uiout
->field_string ("reason",
12636 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12637 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12640 uiout
->message ("Temporary breakpoint %pF, ",
12641 signed_field ("bkptno", b
->number
));
12643 uiout
->message ("Breakpoint %pF, ",
12644 signed_field ("bkptno", b
->number
));
12646 return PRINT_SRC_AND_LOC
;
12650 bkpt_print_mention (struct breakpoint
*b
)
12652 if (current_uiout
->is_mi_like_p ())
12657 case bp_breakpoint
:
12658 case bp_gnu_ifunc_resolver
:
12659 if (b
->disposition
== disp_del
)
12660 printf_filtered (_("Temporary breakpoint"));
12662 printf_filtered (_("Breakpoint"));
12663 printf_filtered (_(" %d"), b
->number
);
12664 if (b
->type
== bp_gnu_ifunc_resolver
)
12665 printf_filtered (_(" at gnu-indirect-function resolver"));
12667 case bp_hardware_breakpoint
:
12668 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12671 printf_filtered (_("Dprintf %d"), b
->number
);
12679 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12681 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12682 fprintf_unfiltered (fp
, "tbreak");
12683 else if (tp
->type
== bp_breakpoint
)
12684 fprintf_unfiltered (fp
, "break");
12685 else if (tp
->type
== bp_hardware_breakpoint
12686 && tp
->disposition
== disp_del
)
12687 fprintf_unfiltered (fp
, "thbreak");
12688 else if (tp
->type
== bp_hardware_breakpoint
)
12689 fprintf_unfiltered (fp
, "hbreak");
12691 internal_error (__FILE__
, __LINE__
,
12692 _("unhandled breakpoint type %d"), (int) tp
->type
);
12694 fprintf_unfiltered (fp
, " %s",
12695 event_location_to_string (tp
->location
.get ()));
12697 /* Print out extra_string if this breakpoint is pending. It might
12698 contain, for example, conditions that were set by the user. */
12699 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12700 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12702 print_recreate_thread (tp
, fp
);
12706 bkpt_create_sals_from_location (struct event_location
*location
,
12707 struct linespec_result
*canonical
,
12708 enum bptype type_wanted
)
12710 create_sals_from_location_default (location
, canonical
, type_wanted
);
12714 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12715 struct linespec_result
*canonical
,
12716 gdb::unique_xmalloc_ptr
<char> cond_string
,
12717 gdb::unique_xmalloc_ptr
<char> extra_string
,
12718 enum bptype type_wanted
,
12719 enum bpdisp disposition
,
12721 int task
, int ignore_count
,
12722 const struct breakpoint_ops
*ops
,
12723 int from_tty
, int enabled
,
12724 int internal
, unsigned flags
)
12726 create_breakpoints_sal_default (gdbarch
, canonical
,
12727 std::move (cond_string
),
12728 std::move (extra_string
),
12730 disposition
, thread
, task
,
12731 ignore_count
, ops
, from_tty
,
12732 enabled
, internal
, flags
);
12735 static std::vector
<symtab_and_line
>
12736 bkpt_decode_location (struct breakpoint
*b
,
12737 struct event_location
*location
,
12738 struct program_space
*search_pspace
)
12740 return decode_location_default (b
, location
, search_pspace
);
12743 /* Virtual table for internal breakpoints. */
12746 internal_bkpt_re_set (struct breakpoint
*b
)
12750 /* Delete overlay event and longjmp master breakpoints; they
12751 will be reset later by breakpoint_re_set. */
12752 case bp_overlay_event
:
12753 case bp_longjmp_master
:
12754 case bp_std_terminate_master
:
12755 case bp_exception_master
:
12756 delete_breakpoint (b
);
12759 /* This breakpoint is special, it's set up when the inferior
12760 starts and we really don't want to touch it. */
12761 case bp_shlib_event
:
12763 /* Like bp_shlib_event, this breakpoint type is special. Once
12764 it is set up, we do not want to touch it. */
12765 case bp_thread_event
:
12771 internal_bkpt_check_status (bpstat bs
)
12773 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12775 /* If requested, stop when the dynamic linker notifies GDB of
12776 events. This allows the user to get control and place
12777 breakpoints in initializer routines for dynamically loaded
12778 objects (among other things). */
12779 bs
->stop
= stop_on_solib_events
;
12780 bs
->print
= stop_on_solib_events
;
12786 static enum print_stop_action
12787 internal_bkpt_print_it (bpstat bs
)
12789 struct breakpoint
*b
;
12791 b
= bs
->breakpoint_at
;
12795 case bp_shlib_event
:
12796 /* Did we stop because the user set the stop_on_solib_events
12797 variable? (If so, we report this as a generic, "Stopped due
12798 to shlib event" message.) */
12799 print_solib_event (0);
12802 case bp_thread_event
:
12803 /* Not sure how we will get here.
12804 GDB should not stop for these breakpoints. */
12805 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12808 case bp_overlay_event
:
12809 /* By analogy with the thread event, GDB should not stop for these. */
12810 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12813 case bp_longjmp_master
:
12814 /* These should never be enabled. */
12815 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12818 case bp_std_terminate_master
:
12819 /* These should never be enabled. */
12820 printf_filtered (_("std::terminate Master Breakpoint: "
12821 "gdb should not stop!\n"));
12824 case bp_exception_master
:
12825 /* These should never be enabled. */
12826 printf_filtered (_("Exception Master Breakpoint: "
12827 "gdb should not stop!\n"));
12831 return PRINT_NOTHING
;
12835 internal_bkpt_print_mention (struct breakpoint
*b
)
12837 /* Nothing to mention. These breakpoints are internal. */
12840 /* Virtual table for momentary breakpoints */
12843 momentary_bkpt_re_set (struct breakpoint
*b
)
12845 /* Keep temporary breakpoints, which can be encountered when we step
12846 over a dlopen call and solib_add is resetting the breakpoints.
12847 Otherwise these should have been blown away via the cleanup chain
12848 or by breakpoint_init_inferior when we rerun the executable. */
12852 momentary_bkpt_check_status (bpstat bs
)
12854 /* Nothing. The point of these breakpoints is causing a stop. */
12857 static enum print_stop_action
12858 momentary_bkpt_print_it (bpstat bs
)
12860 return PRINT_UNKNOWN
;
12864 momentary_bkpt_print_mention (struct breakpoint
*b
)
12866 /* Nothing to mention. These breakpoints are internal. */
12869 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12871 It gets cleared already on the removal of the first one of such placed
12872 breakpoints. This is OK as they get all removed altogether. */
12874 longjmp_breakpoint::~longjmp_breakpoint ()
12876 thread_info
*tp
= find_thread_global_id (this->thread
);
12879 tp
->initiating_frame
= null_frame_id
;
12882 /* Specific methods for probe breakpoints. */
12885 bkpt_probe_insert_location (struct bp_location
*bl
)
12887 int v
= bkpt_insert_location (bl
);
12891 /* The insertion was successful, now let's set the probe's semaphore
12893 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12900 bkpt_probe_remove_location (struct bp_location
*bl
,
12901 enum remove_bp_reason reason
)
12903 /* Let's clear the semaphore before removing the location. */
12904 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12906 return bkpt_remove_location (bl
, reason
);
12910 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12911 struct linespec_result
*canonical
,
12912 enum bptype type_wanted
)
12914 struct linespec_sals lsal
;
12916 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12918 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12919 canonical
->lsals
.push_back (std::move (lsal
));
12922 static std::vector
<symtab_and_line
>
12923 bkpt_probe_decode_location (struct breakpoint
*b
,
12924 struct event_location
*location
,
12925 struct program_space
*search_pspace
)
12927 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12929 error (_("probe not found"));
12933 /* The breakpoint_ops structure to be used in tracepoints. */
12936 tracepoint_re_set (struct breakpoint
*b
)
12938 breakpoint_re_set_default (b
);
12942 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12943 const address_space
*aspace
, CORE_ADDR bp_addr
,
12944 const struct target_waitstatus
*ws
)
12946 /* By definition, the inferior does not report stops at
12952 tracepoint_print_one_detail (const struct breakpoint
*self
,
12953 struct ui_out
*uiout
)
12955 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12956 if (!tp
->static_trace_marker_id
.empty ())
12958 gdb_assert (self
->type
== bp_static_tracepoint
);
12960 uiout
->message ("\tmarker id is %pF\n",
12961 string_field ("static-tracepoint-marker-string-id",
12962 tp
->static_trace_marker_id
.c_str ()));
12967 tracepoint_print_mention (struct breakpoint
*b
)
12969 if (current_uiout
->is_mi_like_p ())
12974 case bp_tracepoint
:
12975 printf_filtered (_("Tracepoint"));
12976 printf_filtered (_(" %d"), b
->number
);
12978 case bp_fast_tracepoint
:
12979 printf_filtered (_("Fast tracepoint"));
12980 printf_filtered (_(" %d"), b
->number
);
12982 case bp_static_tracepoint
:
12983 printf_filtered (_("Static tracepoint"));
12984 printf_filtered (_(" %d"), b
->number
);
12987 internal_error (__FILE__
, __LINE__
,
12988 _("unhandled tracepoint type %d"), (int) b
->type
);
12995 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12997 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12999 if (self
->type
== bp_fast_tracepoint
)
13000 fprintf_unfiltered (fp
, "ftrace");
13001 else if (self
->type
== bp_static_tracepoint
)
13002 fprintf_unfiltered (fp
, "strace");
13003 else if (self
->type
== bp_tracepoint
)
13004 fprintf_unfiltered (fp
, "trace");
13006 internal_error (__FILE__
, __LINE__
,
13007 _("unhandled tracepoint type %d"), (int) self
->type
);
13009 fprintf_unfiltered (fp
, " %s",
13010 event_location_to_string (self
->location
.get ()));
13011 print_recreate_thread (self
, fp
);
13013 if (tp
->pass_count
)
13014 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13018 tracepoint_create_sals_from_location (struct event_location
*location
,
13019 struct linespec_result
*canonical
,
13020 enum bptype type_wanted
)
13022 create_sals_from_location_default (location
, canonical
, type_wanted
);
13026 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13027 struct linespec_result
*canonical
,
13028 gdb::unique_xmalloc_ptr
<char> cond_string
,
13029 gdb::unique_xmalloc_ptr
<char> extra_string
,
13030 enum bptype type_wanted
,
13031 enum bpdisp disposition
,
13033 int task
, int ignore_count
,
13034 const struct breakpoint_ops
*ops
,
13035 int from_tty
, int enabled
,
13036 int internal
, unsigned flags
)
13038 create_breakpoints_sal_default (gdbarch
, canonical
,
13039 std::move (cond_string
),
13040 std::move (extra_string
),
13042 disposition
, thread
, task
,
13043 ignore_count
, ops
, from_tty
,
13044 enabled
, internal
, flags
);
13047 static std::vector
<symtab_and_line
>
13048 tracepoint_decode_location (struct breakpoint
*b
,
13049 struct event_location
*location
,
13050 struct program_space
*search_pspace
)
13052 return decode_location_default (b
, location
, search_pspace
);
13055 struct breakpoint_ops tracepoint_breakpoint_ops
;
13057 /* Virtual table for tracepoints on static probes. */
13060 tracepoint_probe_create_sals_from_location
13061 (struct event_location
*location
,
13062 struct linespec_result
*canonical
,
13063 enum bptype type_wanted
)
13065 /* We use the same method for breakpoint on probes. */
13066 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13069 static std::vector
<symtab_and_line
>
13070 tracepoint_probe_decode_location (struct breakpoint
*b
,
13071 struct event_location
*location
,
13072 struct program_space
*search_pspace
)
13074 /* We use the same method for breakpoint on probes. */
13075 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13078 /* Dprintf breakpoint_ops methods. */
13081 dprintf_re_set (struct breakpoint
*b
)
13083 breakpoint_re_set_default (b
);
13085 /* extra_string should never be non-NULL for dprintf. */
13086 gdb_assert (b
->extra_string
!= NULL
);
13088 /* 1 - connect to target 1, that can run breakpoint commands.
13089 2 - create a dprintf, which resolves fine.
13090 3 - disconnect from target 1
13091 4 - connect to target 2, that can NOT run breakpoint commands.
13093 After steps #3/#4, you'll want the dprintf command list to
13094 be updated, because target 1 and 2 may well return different
13095 answers for target_can_run_breakpoint_commands().
13096 Given absence of finer grained resetting, we get to do
13097 it all the time. */
13098 if (b
->extra_string
!= NULL
)
13099 update_dprintf_command_list (b
);
13102 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13105 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13107 fprintf_unfiltered (fp
, "dprintf %s,%s",
13108 event_location_to_string (tp
->location
.get ()),
13110 print_recreate_thread (tp
, fp
);
13113 /* Implement the "after_condition_true" breakpoint_ops method for
13116 dprintf's are implemented with regular commands in their command
13117 list, but we run the commands here instead of before presenting the
13118 stop to the user, as dprintf's don't actually cause a stop. This
13119 also makes it so that the commands of multiple dprintfs at the same
13120 address are all handled. */
13123 dprintf_after_condition_true (struct bpstats
*bs
)
13125 struct bpstats tmp_bs
;
13126 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13128 /* dprintf's never cause a stop. This wasn't set in the
13129 check_status hook instead because that would make the dprintf's
13130 condition not be evaluated. */
13133 /* Run the command list here. Take ownership of it instead of
13134 copying. We never want these commands to run later in
13135 bpstat_do_actions, if a breakpoint that causes a stop happens to
13136 be set at same address as this dprintf, or even if running the
13137 commands here throws. */
13138 tmp_bs
.commands
= bs
->commands
;
13139 bs
->commands
= NULL
;
13141 bpstat_do_actions_1 (&tmp_bs_p
);
13143 /* 'tmp_bs.commands' will usually be NULL by now, but
13144 bpstat_do_actions_1 may return early without processing the whole
13148 /* The breakpoint_ops structure to be used on static tracepoints with
13152 strace_marker_create_sals_from_location (struct event_location
*location
,
13153 struct linespec_result
*canonical
,
13154 enum bptype type_wanted
)
13156 struct linespec_sals lsal
;
13157 const char *arg_start
, *arg
;
13159 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
13160 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13162 std::string
str (arg_start
, arg
- arg_start
);
13163 const char *ptr
= str
.c_str ();
13164 canonical
->location
13165 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
13168 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13169 canonical
->lsals
.push_back (std::move (lsal
));
13173 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13174 struct linespec_result
*canonical
,
13175 gdb::unique_xmalloc_ptr
<char> cond_string
,
13176 gdb::unique_xmalloc_ptr
<char> extra_string
,
13177 enum bptype type_wanted
,
13178 enum bpdisp disposition
,
13180 int task
, int ignore_count
,
13181 const struct breakpoint_ops
*ops
,
13182 int from_tty
, int enabled
,
13183 int internal
, unsigned flags
)
13185 const linespec_sals
&lsal
= canonical
->lsals
[0];
13187 /* If the user is creating a static tracepoint by marker id
13188 (strace -m MARKER_ID), then store the sals index, so that
13189 breakpoint_re_set can try to match up which of the newly
13190 found markers corresponds to this one, and, don't try to
13191 expand multiple locations for each sal, given than SALS
13192 already should contain all sals for MARKER_ID. */
13194 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13196 event_location_up location
13197 = copy_event_location (canonical
->location
.get ());
13199 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13200 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13201 std::move (location
), NULL
,
13202 std::move (cond_string
),
13203 std::move (extra_string
),
13204 type_wanted
, disposition
,
13205 thread
, task
, ignore_count
, ops
,
13206 from_tty
, enabled
, internal
, flags
,
13207 canonical
->special_display
);
13208 /* Given that its possible to have multiple markers with
13209 the same string id, if the user is creating a static
13210 tracepoint by marker id ("strace -m MARKER_ID"), then
13211 store the sals index, so that breakpoint_re_set can
13212 try to match up which of the newly found markers
13213 corresponds to this one */
13214 tp
->static_trace_marker_id_idx
= i
;
13216 install_breakpoint (internal
, std::move (tp
), 0);
13220 static std::vector
<symtab_and_line
>
13221 strace_marker_decode_location (struct breakpoint
*b
,
13222 struct event_location
*location
,
13223 struct program_space
*search_pspace
)
13225 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13226 const char *s
= get_linespec_location (location
)->spec_string
;
13228 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13229 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13231 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13236 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
13239 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13242 strace_marker_p (struct breakpoint
*b
)
13244 return b
->ops
== &strace_marker_breakpoint_ops
;
13247 /* Delete a breakpoint and clean up all traces of it in the data
13251 delete_breakpoint (struct breakpoint
*bpt
)
13253 gdb_assert (bpt
!= NULL
);
13255 /* Has this bp already been deleted? This can happen because
13256 multiple lists can hold pointers to bp's. bpstat lists are
13259 One example of this happening is a watchpoint's scope bp. When
13260 the scope bp triggers, we notice that the watchpoint is out of
13261 scope, and delete it. We also delete its scope bp. But the
13262 scope bp is marked "auto-deleting", and is already on a bpstat.
13263 That bpstat is then checked for auto-deleting bp's, which are
13266 A real solution to this problem might involve reference counts in
13267 bp's, and/or giving them pointers back to their referencing
13268 bpstat's, and teaching delete_breakpoint to only free a bp's
13269 storage when no more references were extent. A cheaper bandaid
13271 if (bpt
->type
== bp_none
)
13274 /* At least avoid this stale reference until the reference counting
13275 of breakpoints gets resolved. */
13276 if (bpt
->related_breakpoint
!= bpt
)
13278 struct breakpoint
*related
;
13279 struct watchpoint
*w
;
13281 if (bpt
->type
== bp_watchpoint_scope
)
13282 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13283 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13284 w
= (struct watchpoint
*) bpt
;
13288 watchpoint_del_at_next_stop (w
);
13290 /* Unlink bpt from the bpt->related_breakpoint ring. */
13291 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13292 related
= related
->related_breakpoint
);
13293 related
->related_breakpoint
= bpt
->related_breakpoint
;
13294 bpt
->related_breakpoint
= bpt
;
13297 /* watch_command_1 creates a watchpoint but only sets its number if
13298 update_watchpoint succeeds in creating its bp_locations. If there's
13299 a problem in that process, we'll be asked to delete the half-created
13300 watchpoint. In that case, don't announce the deletion. */
13302 gdb::observers::breakpoint_deleted
.notify (bpt
);
13304 if (breakpoint_chain
== bpt
)
13305 breakpoint_chain
= bpt
->next
;
13307 for (breakpoint
*b
: all_breakpoints ())
13308 if (b
->next
== bpt
)
13310 b
->next
= bpt
->next
;
13314 /* Be sure no bpstat's are pointing at the breakpoint after it's
13316 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13317 in all threads for now. Note that we cannot just remove bpstats
13318 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13319 commands are associated with the bpstat; if we remove it here,
13320 then the later call to bpstat_do_actions (&stop_bpstat); in
13321 event-top.c won't do anything, and temporary breakpoints with
13322 commands won't work. */
13324 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13326 /* Now that breakpoint is removed from breakpoint list, update the
13327 global location list. This will remove locations that used to
13328 belong to this breakpoint. Do this before freeing the breakpoint
13329 itself, since remove_breakpoint looks at location's owner. It
13330 might be better design to have location completely
13331 self-contained, but it's not the case now. */
13332 update_global_location_list (UGLL_DONT_INSERT
);
13334 /* On the chance that someone will soon try again to delete this
13335 same bp, we mark it as deleted before freeing its storage. */
13336 bpt
->type
= bp_none
;
13340 /* Iterator function to call a user-provided callback function once
13341 for each of B and its related breakpoints. */
13344 iterate_over_related_breakpoints (struct breakpoint
*b
,
13345 gdb::function_view
<void (breakpoint
*)> function
)
13347 struct breakpoint
*related
;
13352 struct breakpoint
*next
;
13354 /* FUNCTION may delete RELATED. */
13355 next
= related
->related_breakpoint
;
13357 if (next
== related
)
13359 /* RELATED is the last ring entry. */
13360 function (related
);
13362 /* FUNCTION may have deleted it, so we'd never reach back to
13363 B. There's nothing left to do anyway, so just break
13368 function (related
);
13372 while (related
!= b
);
13376 delete_command (const char *arg
, int from_tty
)
13384 int breaks_to_delete
= 0;
13386 /* Delete all breakpoints if no argument. Do not delete
13387 internal breakpoints, these have to be deleted with an
13388 explicit breakpoint number argument. */
13389 for (breakpoint
*b
: all_breakpoints ())
13390 if (user_breakpoint_p (b
))
13392 breaks_to_delete
= 1;
13396 /* Ask user only if there are some breakpoints to delete. */
13398 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13402 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13403 if (user_breakpoint_p (b
))
13404 delete_breakpoint (b
);
13408 map_breakpoint_numbers
13409 (arg
, [&] (breakpoint
*br
)
13411 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13415 /* Return true if all locations of B bound to PSPACE are pending. If
13416 PSPACE is NULL, all locations of all program spaces are
13420 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13422 struct bp_location
*loc
;
13424 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13425 if ((pspace
== NULL
13426 || loc
->pspace
== pspace
)
13427 && !loc
->shlib_disabled
13428 && !loc
->pspace
->executing_startup
)
13433 /* Subroutine of update_breakpoint_locations to simplify it.
13434 Return non-zero if multiple fns in list LOC have the same name.
13435 Null names are ignored. */
13438 ambiguous_names_p (struct bp_location
*loc
)
13440 struct bp_location
*l
;
13441 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
13444 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13447 const char *name
= l
->function_name
;
13449 /* Allow for some names to be NULL, ignore them. */
13453 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
13455 /* NOTE: We can assume slot != NULL here because xcalloc never
13465 /* When symbols change, it probably means the sources changed as well,
13466 and it might mean the static tracepoint markers are no longer at
13467 the same address or line numbers they used to be at last we
13468 checked. Losing your static tracepoints whenever you rebuild is
13469 undesirable. This function tries to resync/rematch gdb static
13470 tracepoints with the markers on the target, for static tracepoints
13471 that have not been set by marker id. Static tracepoint that have
13472 been set by marker id are reset by marker id in breakpoint_re_set.
13475 1) For a tracepoint set at a specific address, look for a marker at
13476 the old PC. If one is found there, assume to be the same marker.
13477 If the name / string id of the marker found is different from the
13478 previous known name, assume that means the user renamed the marker
13479 in the sources, and output a warning.
13481 2) For a tracepoint set at a given line number, look for a marker
13482 at the new address of the old line number. If one is found there,
13483 assume to be the same marker. If the name / string id of the
13484 marker found is different from the previous known name, assume that
13485 means the user renamed the marker in the sources, and output a
13488 3) If a marker is no longer found at the same address or line, it
13489 may mean the marker no longer exists. But it may also just mean
13490 the code changed a bit. Maybe the user added a few lines of code
13491 that made the marker move up or down (in line number terms). Ask
13492 the target for info about the marker with the string id as we knew
13493 it. If found, update line number and address in the matching
13494 static tracepoint. This will get confused if there's more than one
13495 marker with the same ID (possible in UST, although unadvised
13496 precisely because it confuses tools). */
13498 static struct symtab_and_line
13499 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13501 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13502 struct static_tracepoint_marker marker
;
13507 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13509 if (target_static_tracepoint_marker_at (pc
, &marker
))
13511 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13512 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13513 b
->number
, tp
->static_trace_marker_id
.c_str (),
13514 marker
.str_id
.c_str ());
13516 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13521 /* Old marker wasn't found on target at lineno. Try looking it up
13523 if (!sal
.explicit_pc
13525 && sal
.symtab
!= NULL
13526 && !tp
->static_trace_marker_id
.empty ())
13528 std::vector
<static_tracepoint_marker
> markers
13529 = target_static_tracepoint_markers_by_strid
13530 (tp
->static_trace_marker_id
.c_str ());
13532 if (!markers
.empty ())
13534 struct symbol
*sym
;
13535 struct static_tracepoint_marker
*tpmarker
;
13536 struct ui_out
*uiout
= current_uiout
;
13537 struct explicit_location explicit_loc
;
13539 tpmarker
= &markers
[0];
13541 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13543 warning (_("marker for static tracepoint %d (%s) not "
13544 "found at previous line number"),
13545 b
->number
, tp
->static_trace_marker_id
.c_str ());
13547 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13548 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13549 uiout
->text ("Now in ");
13552 uiout
->field_string ("func", sym
->print_name (),
13553 function_name_style
.style ());
13554 uiout
->text (" at ");
13556 uiout
->field_string ("file",
13557 symtab_to_filename_for_display (sal2
.symtab
),
13558 file_name_style
.style ());
13561 if (uiout
->is_mi_like_p ())
13563 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13565 uiout
->field_string ("fullname", fullname
);
13568 uiout
->field_signed ("line", sal2
.line
);
13569 uiout
->text ("\n");
13571 b
->loc
->line_number
= sal2
.line
;
13572 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13574 b
->location
.reset (NULL
);
13575 initialize_explicit_location (&explicit_loc
);
13576 explicit_loc
.source_filename
13577 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13578 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13579 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13580 b
->location
= new_explicit_location (&explicit_loc
);
13582 /* Might be nice to check if function changed, and warn if
13589 /* Returns 1 iff locations A and B are sufficiently same that
13590 we don't need to report breakpoint as changed. */
13593 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13597 if (a
->address
!= b
->address
)
13600 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13603 if (a
->enabled
!= b
->enabled
)
13606 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
13613 if ((a
== NULL
) != (b
== NULL
))
13619 /* Split all locations of B that are bound to PSPACE out of B's
13620 location list to a separate list and return that list's head. If
13621 PSPACE is NULL, hoist out all locations of B. */
13623 static struct bp_location
*
13624 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13626 struct bp_location head
;
13627 struct bp_location
*i
= b
->loc
;
13628 struct bp_location
**i_link
= &b
->loc
;
13629 struct bp_location
*hoisted
= &head
;
13631 if (pspace
== NULL
)
13642 if (i
->pspace
== pspace
)
13657 /* Create new breakpoint locations for B (a hardware or software
13658 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13659 zero, then B is a ranged breakpoint. Only recreates locations for
13660 FILTER_PSPACE. Locations of other program spaces are left
13664 update_breakpoint_locations (struct breakpoint
*b
,
13665 struct program_space
*filter_pspace
,
13666 gdb::array_view
<const symtab_and_line
> sals
,
13667 gdb::array_view
<const symtab_and_line
> sals_end
)
13669 struct bp_location
*existing_locations
;
13671 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13673 /* Ranged breakpoints have only one start location and one end
13675 b
->enable_state
= bp_disabled
;
13676 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13677 "multiple locations found\n"),
13682 /* If there's no new locations, and all existing locations are
13683 pending, don't do anything. This optimizes the common case where
13684 all locations are in the same shared library, that was unloaded.
13685 We'd like to retain the location, so that when the library is
13686 loaded again, we don't loose the enabled/disabled status of the
13687 individual locations. */
13688 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13691 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13693 for (const auto &sal
: sals
)
13695 struct bp_location
*new_loc
;
13697 switch_to_program_space_and_thread (sal
.pspace
);
13699 new_loc
= add_location_to_breakpoint (b
, &sal
);
13701 /* Reparse conditions, they might contain references to the
13703 if (b
->cond_string
!= NULL
)
13707 s
= b
->cond_string
;
13710 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13711 block_for_pc (sal
.pc
),
13714 catch (const gdb_exception_error
&e
)
13716 new_loc
->disabled_by_cond
= true;
13720 if (!sals_end
.empty ())
13722 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13724 new_loc
->length
= end
- sals
[0].pc
+ 1;
13728 /* If possible, carry over 'disable' status from existing
13731 struct bp_location
*e
= existing_locations
;
13732 /* If there are multiple breakpoints with the same function name,
13733 e.g. for inline functions, comparing function names won't work.
13734 Instead compare pc addresses; this is just a heuristic as things
13735 may have moved, but in practice it gives the correct answer
13736 often enough until a better solution is found. */
13737 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13739 for (; e
; e
= e
->next
)
13741 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
13743 struct bp_location
*l
= b
->loc
;
13744 if (have_ambiguous_names
)
13746 for (; l
; l
= l
->next
)
13748 /* Ignore software vs hardware location type at
13749 this point, because with "set breakpoint
13750 auto-hw", after a re-set, locations that were
13751 hardware can end up as software, or vice versa.
13752 As mentioned above, this is an heuristic and in
13753 practice should give the correct answer often
13755 if (breakpoint_locations_match (e
, l
, true))
13757 l
->enabled
= e
->enabled
;
13758 l
->disabled_by_cond
= e
->disabled_by_cond
;
13765 for (; l
; l
= l
->next
)
13766 if (l
->function_name
13767 && strcmp (e
->function_name
, l
->function_name
) == 0)
13769 l
->enabled
= e
->enabled
;
13770 l
->disabled_by_cond
= e
->disabled_by_cond
;
13778 if (!locations_are_equal (existing_locations
, b
->loc
))
13779 gdb::observers::breakpoint_modified
.notify (b
);
13782 /* Find the SaL locations corresponding to the given LOCATION.
13783 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13785 static std::vector
<symtab_and_line
>
13786 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13787 struct program_space
*search_pspace
, int *found
)
13789 struct gdb_exception exception
;
13791 gdb_assert (b
->ops
!= NULL
);
13793 std::vector
<symtab_and_line
> sals
;
13797 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13799 catch (gdb_exception_error
&e
)
13801 int not_found_and_ok
= 0;
13803 /* For pending breakpoints, it's expected that parsing will
13804 fail until the right shared library is loaded. User has
13805 already told to create pending breakpoints and don't need
13806 extra messages. If breakpoint is in bp_shlib_disabled
13807 state, then user already saw the message about that
13808 breakpoint being disabled, and don't want to see more
13810 if (e
.error
== NOT_FOUND_ERROR
13811 && (b
->condition_not_parsed
13813 && search_pspace
!= NULL
13814 && b
->loc
->pspace
!= search_pspace
)
13815 || (b
->loc
&& b
->loc
->shlib_disabled
)
13816 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13817 || b
->enable_state
== bp_disabled
))
13818 not_found_and_ok
= 1;
13820 if (!not_found_and_ok
)
13822 /* We surely don't want to warn about the same breakpoint
13823 10 times. One solution, implemented here, is disable
13824 the breakpoint on error. Another solution would be to
13825 have separate 'warning emitted' flag. Since this
13826 happens only when a binary has changed, I don't know
13827 which approach is better. */
13828 b
->enable_state
= bp_disabled
;
13832 exception
= std::move (e
);
13835 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13837 for (auto &sal
: sals
)
13838 resolve_sal_pc (&sal
);
13839 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13841 char *cond_string
, *extra_string
;
13844 find_condition_and_thread_for_sals (sals
, b
->extra_string
,
13845 &cond_string
, &thread
,
13846 &task
, &extra_string
);
13847 gdb_assert (b
->cond_string
== NULL
);
13849 b
->cond_string
= cond_string
;
13850 b
->thread
= thread
;
13854 xfree (b
->extra_string
);
13855 b
->extra_string
= extra_string
;
13857 b
->condition_not_parsed
= 0;
13860 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13861 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13871 /* The default re_set method, for typical hardware or software
13872 breakpoints. Reevaluate the breakpoint and recreate its
13876 breakpoint_re_set_default (struct breakpoint
*b
)
13878 struct program_space
*filter_pspace
= current_program_space
;
13879 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13882 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13883 filter_pspace
, &found
);
13885 expanded
= std::move (sals
);
13887 if (b
->location_range_end
!= NULL
)
13889 std::vector
<symtab_and_line
> sals_end
13890 = location_to_sals (b
, b
->location_range_end
.get (),
13891 filter_pspace
, &found
);
13893 expanded_end
= std::move (sals_end
);
13896 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13899 /* Default method for creating SALs from an address string. It basically
13900 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13903 create_sals_from_location_default (struct event_location
*location
,
13904 struct linespec_result
*canonical
,
13905 enum bptype type_wanted
)
13907 parse_breakpoint_sals (location
, canonical
);
13910 /* Call create_breakpoints_sal for the given arguments. This is the default
13911 function for the `create_breakpoints_sal' method of
13915 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13916 struct linespec_result
*canonical
,
13917 gdb::unique_xmalloc_ptr
<char> cond_string
,
13918 gdb::unique_xmalloc_ptr
<char> extra_string
,
13919 enum bptype type_wanted
,
13920 enum bpdisp disposition
,
13922 int task
, int ignore_count
,
13923 const struct breakpoint_ops
*ops
,
13924 int from_tty
, int enabled
,
13925 int internal
, unsigned flags
)
13927 create_breakpoints_sal (gdbarch
, canonical
,
13928 std::move (cond_string
),
13929 std::move (extra_string
),
13930 type_wanted
, disposition
,
13931 thread
, task
, ignore_count
, ops
, from_tty
,
13932 enabled
, internal
, flags
);
13935 /* Decode the line represented by S by calling decode_line_full. This is the
13936 default function for the `decode_location' method of breakpoint_ops. */
13938 static std::vector
<symtab_and_line
>
13939 decode_location_default (struct breakpoint
*b
,
13940 struct event_location
*location
,
13941 struct program_space
*search_pspace
)
13943 struct linespec_result canonical
;
13945 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13946 NULL
, 0, &canonical
, multiple_symbols_all
,
13949 /* We should get 0 or 1 resulting SALs. */
13950 gdb_assert (canonical
.lsals
.size () < 2);
13952 if (!canonical
.lsals
.empty ())
13954 const linespec_sals
&lsal
= canonical
.lsals
[0];
13955 return std::move (lsal
.sals
);
13960 /* Reset a breakpoint. */
13963 breakpoint_re_set_one (breakpoint
*b
)
13965 input_radix
= b
->input_radix
;
13966 set_language (b
->language
);
13968 b
->ops
->re_set (b
);
13971 /* Re-set breakpoint locations for the current program space.
13972 Locations bound to other program spaces are left untouched. */
13975 breakpoint_re_set (void)
13977 struct breakpoint
*b
, *b_tmp
;
13980 scoped_restore_current_language save_language
;
13981 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13982 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13984 /* breakpoint_re_set_one sets the current_language to the language
13985 of the breakpoint it is resetting (see prepare_re_set_context)
13986 before re-evaluating the breakpoint's location. This change can
13987 unfortunately get undone by accident if the language_mode is set
13988 to auto, and we either switch frames, or more likely in this context,
13989 we select the current frame.
13991 We prevent this by temporarily turning the language_mode to
13992 language_mode_manual. We restore it once all breakpoints
13993 have been reset. */
13994 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13995 language_mode
= language_mode_manual
;
13997 /* Note: we must not try to insert locations until after all
13998 breakpoints have been re-set. Otherwise, e.g., when re-setting
13999 breakpoint 1, we'd insert the locations of breakpoint 2, which
14000 hadn't been re-set yet, and thus may have stale locations. */
14002 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14006 breakpoint_re_set_one (b
);
14008 catch (const gdb_exception
&ex
)
14010 exception_fprintf (gdb_stderr
, ex
,
14011 "Error in re-setting breakpoint %d: ",
14016 jit_breakpoint_re_set ();
14019 create_overlay_event_breakpoint ();
14020 create_longjmp_master_breakpoint ();
14021 create_std_terminate_master_breakpoint ();
14022 create_exception_master_breakpoint ();
14024 /* Now we can insert. */
14025 update_global_location_list (UGLL_MAY_INSERT
);
14028 /* Reset the thread number of this breakpoint:
14030 - If the breakpoint is for all threads, leave it as-is.
14031 - Else, reset it to the current thread for inferior_ptid. */
14033 breakpoint_re_set_thread (struct breakpoint
*b
)
14035 if (b
->thread
!= -1)
14037 b
->thread
= inferior_thread ()->global_num
;
14039 /* We're being called after following a fork. The new fork is
14040 selected as current, and unless this was a vfork will have a
14041 different program space from the original thread. Reset that
14043 b
->loc
->pspace
= current_program_space
;
14047 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14048 If from_tty is nonzero, it prints a message to that effect,
14049 which ends with a period (no newline). */
14052 set_ignore_count (int bptnum
, int count
, int from_tty
)
14057 for (breakpoint
*b
: all_breakpoints ())
14058 if (b
->number
== bptnum
)
14060 if (is_tracepoint (b
))
14062 if (from_tty
&& count
!= 0)
14063 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14068 b
->ignore_count
= count
;
14072 printf_filtered (_("Will stop next time "
14073 "breakpoint %d is reached."),
14075 else if (count
== 1)
14076 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14079 printf_filtered (_("Will ignore next %d "
14080 "crossings of breakpoint %d."),
14083 gdb::observers::breakpoint_modified
.notify (b
);
14087 error (_("No breakpoint number %d."), bptnum
);
14090 /* Command to set ignore-count of breakpoint N to COUNT. */
14093 ignore_command (const char *args
, int from_tty
)
14095 const char *p
= args
;
14099 error_no_arg (_("a breakpoint number"));
14101 num
= get_number (&p
);
14103 error (_("bad breakpoint number: '%s'"), args
);
14105 error (_("Second argument (specified ignore-count) is missing."));
14107 set_ignore_count (num
,
14108 longest_to_int (value_as_long (parse_and_eval (p
))),
14111 printf_filtered ("\n");
14115 /* Call FUNCTION on each of the breakpoints with numbers in the range
14116 defined by BP_NUM_RANGE (an inclusive range). */
14119 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
14120 gdb::function_view
<void (breakpoint
*)> function
)
14122 if (bp_num_range
.first
== 0)
14124 warning (_("bad breakpoint number at or near '%d'"),
14125 bp_num_range
.first
);
14129 struct breakpoint
*b
, *tmp
;
14131 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
14133 bool match
= false;
14135 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14136 if (b
->number
== i
)
14143 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
14148 /* Call FUNCTION on each of the breakpoints whose numbers are given in
14152 map_breakpoint_numbers (const char *args
,
14153 gdb::function_view
<void (breakpoint
*)> function
)
14155 if (args
== NULL
|| *args
== '\0')
14156 error_no_arg (_("one or more breakpoint numbers"));
14158 number_or_range_parser
parser (args
);
14160 while (!parser
.finished ())
14162 int num
= parser
.get_number ();
14163 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
14167 /* Return the breakpoint location structure corresponding to the
14168 BP_NUM and LOC_NUM values. */
14170 static struct bp_location
*
14171 find_location_by_number (int bp_num
, int loc_num
)
14173 breakpoint
*b
= get_breakpoint (bp_num
);
14175 if (!b
|| b
->number
!= bp_num
)
14176 error (_("Bad breakpoint number '%d'"), bp_num
);
14179 error (_("Bad breakpoint location number '%d'"), loc_num
);
14182 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
14183 if (++n
== loc_num
)
14186 error (_("Bad breakpoint location number '%d'"), loc_num
);
14189 /* Modes of operation for extract_bp_num. */
14190 enum class extract_bp_kind
14192 /* Extracting a breakpoint number. */
14195 /* Extracting a location number. */
14199 /* Extract a breakpoint or location number (as determined by KIND)
14200 from the string starting at START. TRAILER is a character which
14201 can be found after the number. If you don't want a trailer, use
14202 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14203 string. This always returns a positive integer. */
14206 extract_bp_num (extract_bp_kind kind
, const char *start
,
14207 int trailer
, const char **end_out
= NULL
)
14209 const char *end
= start
;
14210 int num
= get_number_trailer (&end
, trailer
);
14212 error (kind
== extract_bp_kind::bp
14213 ? _("Negative breakpoint number '%.*s'")
14214 : _("Negative breakpoint location number '%.*s'"),
14215 int (end
- start
), start
);
14217 error (kind
== extract_bp_kind::bp
14218 ? _("Bad breakpoint number '%.*s'")
14219 : _("Bad breakpoint location number '%.*s'"),
14220 int (end
- start
), start
);
14222 if (end_out
!= NULL
)
14227 /* Extract a breakpoint or location range (as determined by KIND) in
14228 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14229 representing the (inclusive) range. The returned pair's elements
14230 are always positive integers. */
14232 static std::pair
<int, int>
14233 extract_bp_or_bp_range (extract_bp_kind kind
,
14234 const std::string
&arg
,
14235 std::string::size_type arg_offset
)
14237 std::pair
<int, int> range
;
14238 const char *bp_loc
= &arg
[arg_offset
];
14239 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14240 if (dash
!= std::string::npos
)
14242 /* bp_loc is a range (x-z). */
14243 if (arg
.length () == dash
+ 1)
14244 error (kind
== extract_bp_kind::bp
14245 ? _("Bad breakpoint number at or near: '%s'")
14246 : _("Bad breakpoint location number at or near: '%s'"),
14250 const char *start_first
= bp_loc
;
14251 const char *start_second
= &arg
[dash
+ 1];
14252 range
.first
= extract_bp_num (kind
, start_first
, '-');
14253 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14255 if (range
.first
> range
.second
)
14256 error (kind
== extract_bp_kind::bp
14257 ? _("Inverted breakpoint range at '%.*s'")
14258 : _("Inverted breakpoint location range at '%.*s'"),
14259 int (end
- start_first
), start_first
);
14263 /* bp_loc is a single value. */
14264 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14265 range
.second
= range
.first
;
14270 /* Extract the breakpoint/location range specified by ARG. Returns
14271 the breakpoint range in BP_NUM_RANGE, and the location range in
14274 ARG may be in any of the following forms:
14276 x where 'x' is a breakpoint number.
14277 x-y where 'x' and 'y' specify a breakpoint numbers range.
14278 x.y where 'x' is a breakpoint number and 'y' a location number.
14279 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14280 location number range.
14284 extract_bp_number_and_location (const std::string
&arg
,
14285 std::pair
<int, int> &bp_num_range
,
14286 std::pair
<int, int> &bp_loc_range
)
14288 std::string::size_type dot
= arg
.find ('.');
14290 if (dot
!= std::string::npos
)
14292 /* Handle 'x.y' and 'x.y-z' cases. */
14294 if (arg
.length () == dot
+ 1 || dot
== 0)
14295 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14298 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14299 bp_num_range
.second
= bp_num_range
.first
;
14301 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14306 /* Handle x and x-y cases. */
14308 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14309 bp_loc_range
.first
= 0;
14310 bp_loc_range
.second
= 0;
14314 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14315 specifies whether to enable or disable. */
14318 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14320 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14323 if (loc
->disabled_by_cond
&& enable
)
14324 error (_("Breakpoint %d's condition is invalid at location %d, "
14325 "cannot enable."), bp_num
, loc_num
);
14327 if (loc
->enabled
!= enable
)
14329 loc
->enabled
= enable
;
14330 mark_breakpoint_location_modified (loc
);
14332 if (target_supports_enable_disable_tracepoint ()
14333 && current_trace_status ()->running
&& loc
->owner
14334 && is_tracepoint (loc
->owner
))
14335 target_disable_tracepoint (loc
);
14337 update_global_location_list (UGLL_DONT_INSERT
);
14339 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14342 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14343 number of the breakpoint, and BP_LOC_RANGE specifies the
14344 (inclusive) range of location numbers of that breakpoint to
14345 enable/disable. ENABLE specifies whether to enable or disable the
14349 enable_disable_breakpoint_location_range (int bp_num
,
14350 std::pair
<int, int> &bp_loc_range
,
14353 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14354 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14357 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14358 If from_tty is nonzero, it prints a message to that effect,
14359 which ends with a period (no newline). */
14362 disable_breakpoint (struct breakpoint
*bpt
)
14364 /* Never disable a watchpoint scope breakpoint; we want to
14365 hit them when we leave scope so we can delete both the
14366 watchpoint and its scope breakpoint at that time. */
14367 if (bpt
->type
== bp_watchpoint_scope
)
14370 bpt
->enable_state
= bp_disabled
;
14372 /* Mark breakpoint locations modified. */
14373 mark_breakpoint_modified (bpt
);
14375 if (target_supports_enable_disable_tracepoint ()
14376 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14378 struct bp_location
*location
;
14380 for (location
= bpt
->loc
; location
; location
= location
->next
)
14381 target_disable_tracepoint (location
);
14384 update_global_location_list (UGLL_DONT_INSERT
);
14386 gdb::observers::breakpoint_modified
.notify (bpt
);
14389 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14390 specified in ARGS. ARGS may be in any of the formats handled by
14391 extract_bp_number_and_location. ENABLE specifies whether to enable
14392 or disable the breakpoints/locations. */
14395 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14399 for (breakpoint
*bpt
: all_breakpoints ())
14400 if (user_breakpoint_p (bpt
))
14403 enable_breakpoint (bpt
);
14405 disable_breakpoint (bpt
);
14410 std::string num
= extract_arg (&args
);
14412 while (!num
.empty ())
14414 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14416 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14418 if (bp_loc_range
.first
== bp_loc_range
.second
14419 && bp_loc_range
.first
== 0)
14421 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14422 map_breakpoint_number_range (bp_num_range
,
14424 ? enable_breakpoint
14425 : disable_breakpoint
);
14429 /* Handle breakpoint ids with formats 'x.y' or
14431 enable_disable_breakpoint_location_range
14432 (bp_num_range
.first
, bp_loc_range
, enable
);
14434 num
= extract_arg (&args
);
14439 /* The disable command disables the specified breakpoints/locations
14440 (or all defined breakpoints) so they're no longer effective in
14441 stopping the inferior. ARGS may be in any of the forms defined in
14442 extract_bp_number_and_location. */
14445 disable_command (const char *args
, int from_tty
)
14447 enable_disable_command (args
, from_tty
, false);
14451 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14454 int target_resources_ok
;
14456 if (bpt
->type
== bp_hardware_breakpoint
)
14459 i
= hw_breakpoint_used_count ();
14460 target_resources_ok
=
14461 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14463 if (target_resources_ok
== 0)
14464 error (_("No hardware breakpoint support in the target."));
14465 else if (target_resources_ok
< 0)
14466 error (_("Hardware breakpoints used exceeds limit."));
14469 if (is_watchpoint (bpt
))
14471 /* Initialize it just to avoid a GCC false warning. */
14472 enum enable_state orig_enable_state
= bp_disabled
;
14476 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14478 orig_enable_state
= bpt
->enable_state
;
14479 bpt
->enable_state
= bp_enabled
;
14480 update_watchpoint (w
, 1 /* reparse */);
14482 catch (const gdb_exception
&e
)
14484 bpt
->enable_state
= orig_enable_state
;
14485 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14491 bpt
->enable_state
= bp_enabled
;
14493 /* Mark breakpoint locations modified. */
14494 mark_breakpoint_modified (bpt
);
14496 if (target_supports_enable_disable_tracepoint ()
14497 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14499 struct bp_location
*location
;
14501 for (location
= bpt
->loc
; location
; location
= location
->next
)
14502 target_enable_tracepoint (location
);
14505 bpt
->disposition
= disposition
;
14506 bpt
->enable_count
= count
;
14507 update_global_location_list (UGLL_MAY_INSERT
);
14509 gdb::observers::breakpoint_modified
.notify (bpt
);
14514 enable_breakpoint (struct breakpoint
*bpt
)
14516 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14519 /* The enable command enables the specified breakpoints/locations (or
14520 all defined breakpoints) so they once again become (or continue to
14521 be) effective in stopping the inferior. ARGS may be in any of the
14522 forms defined in extract_bp_number_and_location. */
14525 enable_command (const char *args
, int from_tty
)
14527 enable_disable_command (args
, from_tty
, true);
14531 enable_once_command (const char *args
, int from_tty
)
14533 map_breakpoint_numbers
14534 (args
, [&] (breakpoint
*b
)
14536 iterate_over_related_breakpoints
14537 (b
, [&] (breakpoint
*bpt
)
14539 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14545 enable_count_command (const char *args
, int from_tty
)
14550 error_no_arg (_("hit count"));
14552 count
= get_number (&args
);
14554 map_breakpoint_numbers
14555 (args
, [&] (breakpoint
*b
)
14557 iterate_over_related_breakpoints
14558 (b
, [&] (breakpoint
*bpt
)
14560 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14566 enable_delete_command (const char *args
, int from_tty
)
14568 map_breakpoint_numbers
14569 (args
, [&] (breakpoint
*b
)
14571 iterate_over_related_breakpoints
14572 (b
, [&] (breakpoint
*bpt
)
14574 enable_breakpoint_disp (bpt
, disp_del
, 1);
14579 /* Invalidate last known value of any hardware watchpoint if
14580 the memory which that value represents has been written to by
14584 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14585 CORE_ADDR addr
, ssize_t len
,
14586 const bfd_byte
*data
)
14588 for (breakpoint
*bp
: all_breakpoints ())
14589 if (bp
->enable_state
== bp_enabled
14590 && bp
->type
== bp_hardware_watchpoint
)
14592 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14594 if (wp
->val_valid
&& wp
->val
!= nullptr)
14596 struct bp_location
*loc
;
14598 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14599 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14600 && loc
->address
+ loc
->length
> addr
14601 && addr
+ len
> loc
->address
)
14604 wp
->val_valid
= false;
14610 /* Create and insert a breakpoint for software single step. */
14613 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14614 const address_space
*aspace
,
14617 struct thread_info
*tp
= inferior_thread ();
14618 struct symtab_and_line sal
;
14619 CORE_ADDR pc
= next_pc
;
14621 if (tp
->control
.single_step_breakpoints
== NULL
)
14623 tp
->control
.single_step_breakpoints
14624 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14627 sal
= find_pc_line (pc
, 0);
14629 sal
.section
= find_pc_overlay (pc
);
14630 sal
.explicit_pc
= 1;
14631 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14633 update_global_location_list (UGLL_INSERT
);
14636 /* Insert single step breakpoints according to the current state. */
14639 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14641 struct regcache
*regcache
= get_current_regcache ();
14642 std::vector
<CORE_ADDR
> next_pcs
;
14644 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14646 if (!next_pcs
.empty ())
14648 struct frame_info
*frame
= get_current_frame ();
14649 const address_space
*aspace
= get_frame_address_space (frame
);
14651 for (CORE_ADDR pc
: next_pcs
)
14652 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14660 /* See breakpoint.h. */
14663 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14664 const address_space
*aspace
,
14667 struct bp_location
*loc
;
14669 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14671 && breakpoint_location_address_match (loc
, aspace
, pc
))
14677 /* Check whether a software single-step breakpoint is inserted at
14681 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14684 for (breakpoint
*bpt
: all_breakpoints ())
14686 if (bpt
->type
== bp_single_step
14687 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14693 /* Tracepoint-specific operations. */
14695 /* Set tracepoint count to NUM. */
14697 set_tracepoint_count (int num
)
14699 tracepoint_count
= num
;
14700 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14704 trace_command (const char *arg
, int from_tty
)
14706 event_location_up location
= string_to_event_location (&arg
,
14708 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
14709 (location
.get (), true /* is_tracepoint */);
14711 create_breakpoint (get_current_arch (),
14713 NULL
, 0, arg
, false, 1 /* parse arg */,
14715 bp_tracepoint
/* type_wanted */,
14716 0 /* Ignore count */,
14717 pending_break_support
,
14721 0 /* internal */, 0);
14725 ftrace_command (const char *arg
, int from_tty
)
14727 event_location_up location
= string_to_event_location (&arg
,
14729 create_breakpoint (get_current_arch (),
14731 NULL
, 0, arg
, false, 1 /* parse arg */,
14733 bp_fast_tracepoint
/* type_wanted */,
14734 0 /* Ignore count */,
14735 pending_break_support
,
14736 &tracepoint_breakpoint_ops
,
14739 0 /* internal */, 0);
14742 /* strace command implementation. Creates a static tracepoint. */
14745 strace_command (const char *arg
, int from_tty
)
14747 struct breakpoint_ops
*ops
;
14748 event_location_up location
;
14750 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14751 or with a normal static tracepoint. */
14752 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14754 ops
= &strace_marker_breakpoint_ops
;
14755 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14759 ops
= &tracepoint_breakpoint_ops
;
14760 location
= string_to_event_location (&arg
, current_language
);
14763 create_breakpoint (get_current_arch (),
14765 NULL
, 0, arg
, false, 1 /* parse arg */,
14767 bp_static_tracepoint
/* type_wanted */,
14768 0 /* Ignore count */,
14769 pending_break_support
,
14773 0 /* internal */, 0);
14776 /* Set up a fake reader function that gets command lines from a linked
14777 list that was acquired during tracepoint uploading. */
14779 static struct uploaded_tp
*this_utp
;
14780 static int next_cmd
;
14783 read_uploaded_action (void)
14785 char *rslt
= nullptr;
14787 if (next_cmd
< this_utp
->cmd_strings
.size ())
14789 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14796 /* Given information about a tracepoint as recorded on a target (which
14797 can be either a live system or a trace file), attempt to create an
14798 equivalent GDB tracepoint. This is not a reliable process, since
14799 the target does not necessarily have all the information used when
14800 the tracepoint was originally defined. */
14802 struct tracepoint
*
14803 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14805 const char *addr_str
;
14806 char small_buf
[100];
14807 struct tracepoint
*tp
;
14809 if (utp
->at_string
)
14810 addr_str
= utp
->at_string
.get ();
14813 /* In the absence of a source location, fall back to raw
14814 address. Since there is no way to confirm that the address
14815 means the same thing as when the trace was started, warn the
14817 warning (_("Uploaded tracepoint %d has no "
14818 "source location, using raw address"),
14820 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14821 addr_str
= small_buf
;
14824 /* There's not much we can do with a sequence of bytecodes. */
14825 if (utp
->cond
&& !utp
->cond_string
)
14826 warning (_("Uploaded tracepoint %d condition "
14827 "has no source form, ignoring it"),
14830 event_location_up location
= string_to_event_location (&addr_str
,
14832 if (!create_breakpoint (get_current_arch (),
14834 utp
->cond_string
.get (), -1, addr_str
,
14835 false /* force_condition */,
14836 0 /* parse cond/thread */,
14838 utp
->type
/* type_wanted */,
14839 0 /* Ignore count */,
14840 pending_break_support
,
14841 &tracepoint_breakpoint_ops
,
14843 utp
->enabled
/* enabled */,
14845 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14848 /* Get the tracepoint we just created. */
14849 tp
= get_tracepoint (tracepoint_count
);
14850 gdb_assert (tp
!= NULL
);
14854 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14857 trace_pass_command (small_buf
, 0);
14860 /* If we have uploaded versions of the original commands, set up a
14861 special-purpose "reader" function and call the usual command line
14862 reader, then pass the result to the breakpoint command-setting
14864 if (!utp
->cmd_strings
.empty ())
14866 counted_command_line cmd_list
;
14871 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14873 breakpoint_set_commands (tp
, std::move (cmd_list
));
14875 else if (!utp
->actions
.empty ()
14876 || !utp
->step_actions
.empty ())
14877 warning (_("Uploaded tracepoint %d actions "
14878 "have no source form, ignoring them"),
14881 /* Copy any status information that might be available. */
14882 tp
->hit_count
= utp
->hit_count
;
14883 tp
->traceframe_usage
= utp
->traceframe_usage
;
14888 /* Print information on tracepoint number TPNUM_EXP, or all if
14892 info_tracepoints_command (const char *args
, int from_tty
)
14894 struct ui_out
*uiout
= current_uiout
;
14897 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14899 if (num_printed
== 0)
14901 if (args
== NULL
|| *args
== '\0')
14902 uiout
->message ("No tracepoints.\n");
14904 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14907 default_collect_info ();
14910 /* The 'enable trace' command enables tracepoints.
14911 Not supported by all targets. */
14913 enable_trace_command (const char *args
, int from_tty
)
14915 enable_command (args
, from_tty
);
14918 /* The 'disable trace' command disables tracepoints.
14919 Not supported by all targets. */
14921 disable_trace_command (const char *args
, int from_tty
)
14923 disable_command (args
, from_tty
);
14926 /* Remove a tracepoint (or all if no argument). */
14928 delete_trace_command (const char *arg
, int from_tty
)
14930 struct breakpoint
*b
, *b_tmp
;
14936 int breaks_to_delete
= 0;
14938 /* Delete all breakpoints if no argument.
14939 Do not delete internal or call-dummy breakpoints, these
14940 have to be deleted with an explicit breakpoint number
14942 ALL_TRACEPOINTS (b
)
14943 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14945 breaks_to_delete
= 1;
14949 /* Ask user only if there are some breakpoints to delete. */
14951 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14953 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14954 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14955 delete_breakpoint (b
);
14959 map_breakpoint_numbers
14960 (arg
, [&] (breakpoint
*br
)
14962 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14966 /* Helper function for trace_pass_command. */
14969 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14971 tp
->pass_count
= count
;
14972 gdb::observers::breakpoint_modified
.notify (tp
);
14974 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14975 tp
->number
, count
);
14978 /* Set passcount for tracepoint.
14980 First command argument is passcount, second is tracepoint number.
14981 If tracepoint number omitted, apply to most recently defined.
14982 Also accepts special argument "all". */
14985 trace_pass_command (const char *args
, int from_tty
)
14987 struct tracepoint
*t1
;
14990 if (args
== 0 || *args
== 0)
14991 error (_("passcount command requires an "
14992 "argument (count + optional TP num)"));
14994 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14996 args
= skip_spaces (args
);
14997 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14999 struct breakpoint
*b
;
15001 args
+= 3; /* Skip special argument "all". */
15003 error (_("Junk at end of arguments."));
15005 ALL_TRACEPOINTS (b
)
15007 t1
= (struct tracepoint
*) b
;
15008 trace_pass_set_count (t1
, count
, from_tty
);
15011 else if (*args
== '\0')
15013 t1
= get_tracepoint_by_number (&args
, NULL
);
15015 trace_pass_set_count (t1
, count
, from_tty
);
15019 number_or_range_parser
parser (args
);
15020 while (!parser
.finished ())
15022 t1
= get_tracepoint_by_number (&args
, &parser
);
15024 trace_pass_set_count (t1
, count
, from_tty
);
15029 struct tracepoint
*
15030 get_tracepoint (int num
)
15032 struct breakpoint
*t
;
15034 ALL_TRACEPOINTS (t
)
15035 if (t
->number
== num
)
15036 return (struct tracepoint
*) t
;
15041 /* Find the tracepoint with the given target-side number (which may be
15042 different from the tracepoint number after disconnecting and
15045 struct tracepoint
*
15046 get_tracepoint_by_number_on_target (int num
)
15048 struct breakpoint
*b
;
15050 ALL_TRACEPOINTS (b
)
15052 struct tracepoint
*t
= (struct tracepoint
*) b
;
15054 if (t
->number_on_target
== num
)
15061 /* Utility: parse a tracepoint number and look it up in the list.
15062 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15063 If the argument is missing, the most recent tracepoint
15064 (tracepoint_count) is returned. */
15066 struct tracepoint
*
15067 get_tracepoint_by_number (const char **arg
,
15068 number_or_range_parser
*parser
)
15070 struct breakpoint
*t
;
15072 const char *instring
= arg
== NULL
? NULL
: *arg
;
15074 if (parser
!= NULL
)
15076 gdb_assert (!parser
->finished ());
15077 tpnum
= parser
->get_number ();
15079 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15080 tpnum
= tracepoint_count
;
15082 tpnum
= get_number (arg
);
15086 if (instring
&& *instring
)
15087 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15090 printf_filtered (_("No previous tracepoint\n"));
15094 ALL_TRACEPOINTS (t
)
15095 if (t
->number
== tpnum
)
15097 return (struct tracepoint
*) t
;
15100 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15105 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15107 if (b
->thread
!= -1)
15108 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15111 fprintf_unfiltered (fp
, " task %d", b
->task
);
15113 fprintf_unfiltered (fp
, "\n");
15116 /* Save information on user settable breakpoints (watchpoints, etc) to
15117 a new script file named FILENAME. If FILTER is non-NULL, call it
15118 on each breakpoint and only include the ones for which it returns
15122 save_breakpoints (const char *filename
, int from_tty
,
15123 bool (*filter
) (const struct breakpoint
*))
15126 int extra_trace_bits
= 0;
15128 if (filename
== 0 || *filename
== 0)
15129 error (_("Argument required (file name in which to save)"));
15131 /* See if we have anything to save. */
15132 for (breakpoint
*tp
: all_breakpoints ())
15134 /* Skip internal and momentary breakpoints. */
15135 if (!user_breakpoint_p (tp
))
15138 /* If we have a filter, only save the breakpoints it accepts. */
15139 if (filter
&& !filter (tp
))
15144 if (is_tracepoint (tp
))
15146 extra_trace_bits
= 1;
15148 /* We can stop searching. */
15155 warning (_("Nothing to save."));
15159 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15163 if (!fp
.open (expanded_filename
.get (), "w"))
15164 error (_("Unable to open file '%s' for saving (%s)"),
15165 expanded_filename
.get (), safe_strerror (errno
));
15167 if (extra_trace_bits
)
15168 save_trace_state_variables (&fp
);
15170 for (breakpoint
*tp
: all_breakpoints ())
15172 /* Skip internal and momentary breakpoints. */
15173 if (!user_breakpoint_p (tp
))
15176 /* If we have a filter, only save the breakpoints it accepts. */
15177 if (filter
&& !filter (tp
))
15180 tp
->ops
->print_recreate (tp
, &fp
);
15182 /* Note, we can't rely on tp->number for anything, as we can't
15183 assume the recreated breakpoint numbers will match. Use $bpnum
15186 if (tp
->cond_string
)
15187 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15189 if (tp
->ignore_count
)
15190 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15192 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15194 fp
.puts (" commands\n");
15196 current_uiout
->redirect (&fp
);
15199 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15201 catch (const gdb_exception
&ex
)
15203 current_uiout
->redirect (NULL
);
15207 current_uiout
->redirect (NULL
);
15208 fp
.puts (" end\n");
15211 if (tp
->enable_state
== bp_disabled
)
15212 fp
.puts ("disable $bpnum\n");
15214 /* If this is a multi-location breakpoint, check if the locations
15215 should be individually disabled. Watchpoint locations are
15216 special, and not user visible. */
15217 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15219 struct bp_location
*loc
;
15222 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15224 fp
.printf ("disable $bpnum.%d\n", n
);
15228 if (extra_trace_bits
&& *default_collect
)
15229 fp
.printf ("set default-collect %s\n", default_collect
);
15232 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15235 /* The `save breakpoints' command. */
15238 save_breakpoints_command (const char *args
, int from_tty
)
15240 save_breakpoints (args
, from_tty
, NULL
);
15243 /* The `save tracepoints' command. */
15246 save_tracepoints_command (const char *args
, int from_tty
)
15248 save_breakpoints (args
, from_tty
, is_tracepoint
);
15251 /* Create a vector of all tracepoints. */
15253 std::vector
<breakpoint
*>
15254 all_tracepoints (void)
15256 std::vector
<breakpoint
*> tp_vec
;
15257 struct breakpoint
*tp
;
15259 ALL_TRACEPOINTS (tp
)
15261 tp_vec
.push_back (tp
);
15268 /* This help string is used to consolidate all the help string for specifying
15269 locations used by several commands. */
15271 #define LOCATION_HELP_STRING \
15272 "Linespecs are colon-separated lists of location parameters, such as\n\
15273 source filename, function name, label name, and line number.\n\
15274 Example: To specify the start of a label named \"the_top\" in the\n\
15275 function \"fact\" in the file \"factorial.c\", use\n\
15276 \"factorial.c:fact:the_top\".\n\
15278 Address locations begin with \"*\" and specify an exact address in the\n\
15279 program. Example: To specify the fourth byte past the start function\n\
15280 \"main\", use \"*main + 4\".\n\
15282 Explicit locations are similar to linespecs but use an option/argument\n\
15283 syntax to specify location parameters.\n\
15284 Example: To specify the start of the label named \"the_top\" in the\n\
15285 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15286 -function fact -label the_top\".\n\
15288 By default, a specified function is matched against the program's\n\
15289 functions in all scopes. For C++, this means in all namespaces and\n\
15290 classes. For Ada, this means in all packages. E.g., in C++,\n\
15291 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15292 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15293 specified name as a complete fully-qualified name instead."
15295 /* This help string is used for the break, hbreak, tbreak and thbreak
15296 commands. It is defined as a macro to prevent duplication.
15297 COMMAND should be a string constant containing the name of the
15300 #define BREAK_ARGS_HELP(command) \
15301 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
15302 \t[-force-condition] [if CONDITION]\n\
15303 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15304 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15305 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15306 `-probe-dtrace' (for a DTrace probe).\n\
15307 LOCATION may be a linespec, address, or explicit location as described\n\
15310 With no LOCATION, uses current execution address of the selected\n\
15311 stack frame. This is useful for breaking on return to a stack frame.\n\
15313 THREADNUM is the number from \"info threads\".\n\
15314 CONDITION is a boolean expression.\n\
15316 With the \"-force-condition\" flag, the condition is defined even when\n\
15317 it is invalid for all current locations.\n\
15318 \n" LOCATION_HELP_STRING "\n\n\
15319 Multiple breakpoints at one place are permitted, and useful if their\n\
15320 conditions are different.\n\
15322 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15324 /* List of subcommands for "catch". */
15325 static struct cmd_list_element
*catch_cmdlist
;
15327 /* List of subcommands for "tcatch". */
15328 static struct cmd_list_element
*tcatch_cmdlist
;
15331 add_catch_command (const char *name
, const char *docstring
,
15332 cmd_const_sfunc_ftype
*sfunc
,
15333 completer_ftype
*completer
,
15334 void *user_data_catch
,
15335 void *user_data_tcatch
)
15337 struct cmd_list_element
*command
;
15339 command
= add_cmd (name
, class_breakpoint
, docstring
,
15341 set_cmd_sfunc (command
, sfunc
);
15342 set_cmd_context (command
, user_data_catch
);
15343 set_cmd_completer (command
, completer
);
15345 command
= add_cmd (name
, class_breakpoint
, docstring
,
15347 set_cmd_sfunc (command
, sfunc
);
15348 set_cmd_context (command
, user_data_tcatch
);
15349 set_cmd_completer (command
, completer
);
15352 struct breakpoint
*
15353 iterate_over_breakpoints (gdb::function_view
<bool (breakpoint
*)> callback
)
15355 struct breakpoint
*b
, *b_tmp
;
15357 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15366 /* Zero if any of the breakpoint's locations could be a location where
15367 functions have been inlined, nonzero otherwise. */
15370 is_non_inline_function (struct breakpoint
*b
)
15372 /* The shared library event breakpoint is set on the address of a
15373 non-inline function. */
15374 if (b
->type
== bp_shlib_event
)
15380 /* Nonzero if the specified PC cannot be a location where functions
15381 have been inlined. */
15384 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15385 const struct target_waitstatus
*ws
)
15387 struct bp_location
*bl
;
15389 for (breakpoint
*b
: all_breakpoints ())
15391 if (!is_non_inline_function (b
))
15394 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15396 if (!bl
->shlib_disabled
15397 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15405 /* Remove any references to OBJFILE which is going to be freed. */
15408 breakpoint_free_objfile (struct objfile
*objfile
)
15410 struct bp_location
**locp
, *loc
;
15412 ALL_BP_LOCATIONS (loc
, locp
)
15413 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15414 loc
->symtab
= NULL
;
15418 initialize_breakpoint_ops (void)
15420 static int initialized
= 0;
15422 struct breakpoint_ops
*ops
;
15428 /* The breakpoint_ops structure to be inherit by all kinds of
15429 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15430 internal and momentary breakpoints, etc.). */
15431 ops
= &bkpt_base_breakpoint_ops
;
15432 *ops
= base_breakpoint_ops
;
15433 ops
->re_set
= bkpt_re_set
;
15434 ops
->insert_location
= bkpt_insert_location
;
15435 ops
->remove_location
= bkpt_remove_location
;
15436 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15437 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15438 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15439 ops
->decode_location
= bkpt_decode_location
;
15441 /* The breakpoint_ops structure to be used in regular breakpoints. */
15442 ops
= &bkpt_breakpoint_ops
;
15443 *ops
= bkpt_base_breakpoint_ops
;
15444 ops
->re_set
= bkpt_re_set
;
15445 ops
->resources_needed
= bkpt_resources_needed
;
15446 ops
->print_it
= bkpt_print_it
;
15447 ops
->print_mention
= bkpt_print_mention
;
15448 ops
->print_recreate
= bkpt_print_recreate
;
15450 /* Ranged breakpoints. */
15451 ops
= &ranged_breakpoint_ops
;
15452 *ops
= bkpt_breakpoint_ops
;
15453 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15454 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15455 ops
->print_it
= print_it_ranged_breakpoint
;
15456 ops
->print_one
= print_one_ranged_breakpoint
;
15457 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15458 ops
->print_mention
= print_mention_ranged_breakpoint
;
15459 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15461 /* Internal breakpoints. */
15462 ops
= &internal_breakpoint_ops
;
15463 *ops
= bkpt_base_breakpoint_ops
;
15464 ops
->re_set
= internal_bkpt_re_set
;
15465 ops
->check_status
= internal_bkpt_check_status
;
15466 ops
->print_it
= internal_bkpt_print_it
;
15467 ops
->print_mention
= internal_bkpt_print_mention
;
15469 /* Momentary breakpoints. */
15470 ops
= &momentary_breakpoint_ops
;
15471 *ops
= bkpt_base_breakpoint_ops
;
15472 ops
->re_set
= momentary_bkpt_re_set
;
15473 ops
->check_status
= momentary_bkpt_check_status
;
15474 ops
->print_it
= momentary_bkpt_print_it
;
15475 ops
->print_mention
= momentary_bkpt_print_mention
;
15477 /* Probe breakpoints. */
15478 ops
= &bkpt_probe_breakpoint_ops
;
15479 *ops
= bkpt_breakpoint_ops
;
15480 ops
->insert_location
= bkpt_probe_insert_location
;
15481 ops
->remove_location
= bkpt_probe_remove_location
;
15482 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15483 ops
->decode_location
= bkpt_probe_decode_location
;
15486 ops
= &watchpoint_breakpoint_ops
;
15487 *ops
= base_breakpoint_ops
;
15488 ops
->re_set
= re_set_watchpoint
;
15489 ops
->insert_location
= insert_watchpoint
;
15490 ops
->remove_location
= remove_watchpoint
;
15491 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15492 ops
->check_status
= check_status_watchpoint
;
15493 ops
->resources_needed
= resources_needed_watchpoint
;
15494 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15495 ops
->print_it
= print_it_watchpoint
;
15496 ops
->print_mention
= print_mention_watchpoint
;
15497 ops
->print_recreate
= print_recreate_watchpoint
;
15498 ops
->explains_signal
= explains_signal_watchpoint
;
15500 /* Masked watchpoints. */
15501 ops
= &masked_watchpoint_breakpoint_ops
;
15502 *ops
= watchpoint_breakpoint_ops
;
15503 ops
->insert_location
= insert_masked_watchpoint
;
15504 ops
->remove_location
= remove_masked_watchpoint
;
15505 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15506 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15507 ops
->print_it
= print_it_masked_watchpoint
;
15508 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15509 ops
->print_mention
= print_mention_masked_watchpoint
;
15510 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15513 ops
= &tracepoint_breakpoint_ops
;
15514 *ops
= base_breakpoint_ops
;
15515 ops
->re_set
= tracepoint_re_set
;
15516 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15517 ops
->print_one_detail
= tracepoint_print_one_detail
;
15518 ops
->print_mention
= tracepoint_print_mention
;
15519 ops
->print_recreate
= tracepoint_print_recreate
;
15520 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15521 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15522 ops
->decode_location
= tracepoint_decode_location
;
15524 /* Probe tracepoints. */
15525 ops
= &tracepoint_probe_breakpoint_ops
;
15526 *ops
= tracepoint_breakpoint_ops
;
15527 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15528 ops
->decode_location
= tracepoint_probe_decode_location
;
15530 /* Static tracepoints with marker (`-m'). */
15531 ops
= &strace_marker_breakpoint_ops
;
15532 *ops
= tracepoint_breakpoint_ops
;
15533 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15534 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15535 ops
->decode_location
= strace_marker_decode_location
;
15537 /* Fork catchpoints. */
15538 ops
= &catch_fork_breakpoint_ops
;
15539 *ops
= base_breakpoint_ops
;
15540 ops
->insert_location
= insert_catch_fork
;
15541 ops
->remove_location
= remove_catch_fork
;
15542 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15543 ops
->print_it
= print_it_catch_fork
;
15544 ops
->print_one
= print_one_catch_fork
;
15545 ops
->print_mention
= print_mention_catch_fork
;
15546 ops
->print_recreate
= print_recreate_catch_fork
;
15548 /* Vfork catchpoints. */
15549 ops
= &catch_vfork_breakpoint_ops
;
15550 *ops
= base_breakpoint_ops
;
15551 ops
->insert_location
= insert_catch_vfork
;
15552 ops
->remove_location
= remove_catch_vfork
;
15553 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15554 ops
->print_it
= print_it_catch_vfork
;
15555 ops
->print_one
= print_one_catch_vfork
;
15556 ops
->print_mention
= print_mention_catch_vfork
;
15557 ops
->print_recreate
= print_recreate_catch_vfork
;
15559 /* Exec catchpoints. */
15560 ops
= &catch_exec_breakpoint_ops
;
15561 *ops
= base_breakpoint_ops
;
15562 ops
->insert_location
= insert_catch_exec
;
15563 ops
->remove_location
= remove_catch_exec
;
15564 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15565 ops
->print_it
= print_it_catch_exec
;
15566 ops
->print_one
= print_one_catch_exec
;
15567 ops
->print_mention
= print_mention_catch_exec
;
15568 ops
->print_recreate
= print_recreate_catch_exec
;
15570 /* Solib-related catchpoints. */
15571 ops
= &catch_solib_breakpoint_ops
;
15572 *ops
= base_breakpoint_ops
;
15573 ops
->insert_location
= insert_catch_solib
;
15574 ops
->remove_location
= remove_catch_solib
;
15575 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15576 ops
->check_status
= check_status_catch_solib
;
15577 ops
->print_it
= print_it_catch_solib
;
15578 ops
->print_one
= print_one_catch_solib
;
15579 ops
->print_mention
= print_mention_catch_solib
;
15580 ops
->print_recreate
= print_recreate_catch_solib
;
15582 ops
= &dprintf_breakpoint_ops
;
15583 *ops
= bkpt_base_breakpoint_ops
;
15584 ops
->re_set
= dprintf_re_set
;
15585 ops
->resources_needed
= bkpt_resources_needed
;
15586 ops
->print_it
= bkpt_print_it
;
15587 ops
->print_mention
= bkpt_print_mention
;
15588 ops
->print_recreate
= dprintf_print_recreate
;
15589 ops
->after_condition_true
= dprintf_after_condition_true
;
15590 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15593 /* Chain containing all defined "enable breakpoint" subcommands. */
15595 static struct cmd_list_element
*enablebreaklist
= NULL
;
15597 /* See breakpoint.h. */
15599 cmd_list_element
*commands_cmd_element
= nullptr;
15601 void _initialize_breakpoint ();
15603 _initialize_breakpoint ()
15605 struct cmd_list_element
*c
;
15607 initialize_breakpoint_ops ();
15609 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
15611 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
15613 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
15616 breakpoint_chain
= 0;
15617 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15618 before a breakpoint is set. */
15619 breakpoint_count
= 0;
15621 tracepoint_count
= 0;
15623 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15624 Set ignore-count of breakpoint number N to COUNT.\n\
15625 Usage is `ignore N COUNT'."));
15627 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15628 commands_command
, _("\
15629 Set commands to be executed when the given breakpoints are hit.\n\
15630 Give a space-separated breakpoint list as argument after \"commands\".\n\
15631 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15633 With no argument, the targeted breakpoint is the last one set.\n\
15634 The commands themselves follow starting on the next line.\n\
15635 Type a line containing \"end\" to indicate the end of them.\n\
15636 Give \"silent\" as the first line to make the breakpoint silent;\n\
15637 then no output is printed when it is hit, except what the commands print."));
15639 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
15640 static std::string condition_command_help
15641 = gdb::option::build_help (_("\
15642 Specify breakpoint number N to break only if COND is true.\n\
15643 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
15644 is an expression to be evaluated whenever breakpoint N is reached.\n\
15647 %OPTIONS%"), cc_opts
);
15649 c
= add_com ("condition", class_breakpoint
, condition_command
,
15650 condition_command_help
.c_str ());
15651 set_cmd_completer_handle_brkchars (c
, condition_completer
);
15653 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15654 Set a temporary breakpoint.\n\
15655 Like \"break\" except the breakpoint is only temporary,\n\
15656 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15657 by using \"enable delete\" on the breakpoint number.\n\
15659 BREAK_ARGS_HELP ("tbreak")));
15660 set_cmd_completer (c
, location_completer
);
15662 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15663 Set a hardware assisted breakpoint.\n\
15664 Like \"break\" except the breakpoint requires hardware support,\n\
15665 some target hardware may not have this support.\n\
15667 BREAK_ARGS_HELP ("hbreak")));
15668 set_cmd_completer (c
, location_completer
);
15670 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15671 Set a temporary hardware assisted breakpoint.\n\
15672 Like \"hbreak\" except the breakpoint is only temporary,\n\
15673 so it will be deleted when hit.\n\
15675 BREAK_ARGS_HELP ("thbreak")));
15676 set_cmd_completer (c
, location_completer
);
15678 cmd_list_element
*enable_cmd
15679 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15680 Enable all or some breakpoints.\n\
15681 Usage: enable [BREAKPOINTNUM]...\n\
15682 Give breakpoint numbers (separated by spaces) as arguments.\n\
15683 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15684 This is used to cancel the effect of the \"disable\" command.\n\
15685 With a subcommand you can enable temporarily."),
15686 &enablelist
, 1, &cmdlist
);
15688 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
15690 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15691 Enable all or some breakpoints.\n\
15692 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15693 Give breakpoint numbers (separated by spaces) as arguments.\n\
15694 This is used to cancel the effect of the \"disable\" command.\n\
15695 May be abbreviated to simply \"enable\"."),
15696 &enablebreaklist
, 1, &enablelist
);
15698 add_cmd ("once", no_class
, enable_once_command
, _("\
15699 Enable some breakpoints for one hit.\n\
15700 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15701 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15704 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15705 Enable some breakpoints and delete when hit.\n\
15706 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15707 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15710 add_cmd ("count", no_class
, enable_count_command
, _("\
15711 Enable some breakpoints for COUNT hits.\n\
15712 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15713 If a breakpoint is hit while enabled in this fashion,\n\
15714 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15717 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15718 Enable some breakpoints and delete when hit.\n\
15719 Usage: enable delete BREAKPOINTNUM...\n\
15720 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15723 add_cmd ("once", no_class
, enable_once_command
, _("\
15724 Enable some breakpoints for one hit.\n\
15725 Usage: enable once BREAKPOINTNUM...\n\
15726 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15729 add_cmd ("count", no_class
, enable_count_command
, _("\
15730 Enable some breakpoints for COUNT hits.\n\
15731 Usage: enable count COUNT BREAKPOINTNUM...\n\
15732 If a breakpoint is hit while enabled in this fashion,\n\
15733 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15736 cmd_list_element
*disable_cmd
15737 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15738 Disable all or some breakpoints.\n\
15739 Usage: disable [BREAKPOINTNUM]...\n\
15740 Arguments are breakpoint numbers with spaces in between.\n\
15741 To disable all breakpoints, give no argument.\n\
15742 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15743 &disablelist
, 1, &cmdlist
);
15744 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
15745 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
15747 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
15748 Disable all or some breakpoints.\n\
15749 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15750 Arguments are breakpoint numbers with spaces in between.\n\
15751 To disable all breakpoints, give no argument.\n\
15752 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15753 This command may be abbreviated \"disable\"."),
15756 cmd_list_element
*delete_cmd
15757 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15758 Delete all or some breakpoints.\n\
15759 Usage: delete [BREAKPOINTNUM]...\n\
15760 Arguments are breakpoint numbers with spaces in between.\n\
15761 To delete all breakpoints, give no argument.\n\
15763 Also a prefix command for deletion of other GDB objects."),
15764 &deletelist
, 1, &cmdlist
);
15765 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
15766 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
15768 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
15769 Delete all or some breakpoints or auto-display expressions.\n\
15770 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15771 Arguments are breakpoint numbers with spaces in between.\n\
15772 To delete all breakpoints, give no argument.\n\
15773 This command may be abbreviated \"delete\"."),
15776 cmd_list_element
*clear_cmd
15777 = add_com ("clear", class_breakpoint
, clear_command
, _("\
15778 Clear breakpoint at specified location.\n\
15779 Argument may be a linespec, explicit, or address location as described below.\n\
15781 With no argument, clears all breakpoints in the line that the selected frame\n\
15782 is executing in.\n"
15783 "\n" LOCATION_HELP_STRING
"\n\n\
15784 See also the \"delete\" command which clears breakpoints by number."));
15785 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
15787 cmd_list_element
*break_cmd
15788 = add_com ("break", class_breakpoint
, break_command
, _("\
15789 Set breakpoint at specified location.\n"
15790 BREAK_ARGS_HELP ("break")));
15791 set_cmd_completer (break_cmd
, location_completer
);
15793 add_com_alias ("b", break_cmd
, class_run
, 1);
15794 add_com_alias ("br", break_cmd
, class_run
, 1);
15795 add_com_alias ("bre", break_cmd
, class_run
, 1);
15796 add_com_alias ("brea", break_cmd
, class_run
, 1);
15800 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15801 Break in function/address or break at a line in the current file."),
15802 &stoplist
, 1, &cmdlist
);
15803 add_cmd ("in", class_breakpoint
, stopin_command
,
15804 _("Break in function or address."), &stoplist
);
15805 add_cmd ("at", class_breakpoint
, stopat_command
,
15806 _("Break at a line in the current file."), &stoplist
);
15807 add_com ("status", class_info
, info_breakpoints_command
, _("\
15808 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15809 The \"Type\" column indicates one of:\n\
15810 \tbreakpoint - normal breakpoint\n\
15811 \twatchpoint - watchpoint\n\
15812 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15813 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15814 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15815 address and file/line number respectively.\n\
15817 Convenience variable \"$_\" and default examine address for \"x\"\n\
15818 are set to the address of the last breakpoint listed unless the command\n\
15819 is prefixed with \"server \".\n\n\
15820 Convenience variable \"$bpnum\" contains the number of the last\n\
15821 breakpoint set."));
15824 cmd_list_element
*info_breakpoints_cmd
15825 = add_info ("breakpoints", info_breakpoints_command
, _("\
15826 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15827 The \"Type\" column indicates one of:\n\
15828 \tbreakpoint - normal breakpoint\n\
15829 \twatchpoint - watchpoint\n\
15830 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15831 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15832 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15833 address and file/line number respectively.\n\
15835 Convenience variable \"$_\" and default examine address for \"x\"\n\
15836 are set to the address of the last breakpoint listed unless the command\n\
15837 is prefixed with \"server \".\n\n\
15838 Convenience variable \"$bpnum\" contains the number of the last\n\
15839 breakpoint set."));
15841 add_info_alias ("b", info_breakpoints_cmd
, 1);
15843 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15844 Status of all breakpoints, or breakpoint number NUMBER.\n\
15845 The \"Type\" column indicates one of:\n\
15846 \tbreakpoint - normal breakpoint\n\
15847 \twatchpoint - watchpoint\n\
15848 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15849 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15850 \tuntil - internal breakpoint used by the \"until\" command\n\
15851 \tfinish - internal breakpoint used by the \"finish\" command\n\
15852 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15853 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15854 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15855 address and file/line number respectively.\n\
15857 Convenience variable \"$_\" and default examine address for \"x\"\n\
15858 are set to the address of the last breakpoint listed unless the command\n\
15859 is prefixed with \"server \".\n\n\
15860 Convenience variable \"$bpnum\" contains the number of the last\n\
15862 &maintenanceinfolist
);
15864 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
15865 Set catchpoints to catch events."),
15867 0/*allow-unknown*/, &cmdlist
);
15869 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
15870 Set temporary catchpoints to catch events."),
15872 0/*allow-unknown*/, &cmdlist
);
15874 add_catch_command ("fork", _("Catch calls to fork."),
15875 catch_fork_command_1
,
15877 (void *) (uintptr_t) catch_fork_permanent
,
15878 (void *) (uintptr_t) catch_fork_temporary
);
15879 add_catch_command ("vfork", _("Catch calls to vfork."),
15880 catch_fork_command_1
,
15882 (void *) (uintptr_t) catch_vfork_permanent
,
15883 (void *) (uintptr_t) catch_vfork_temporary
);
15884 add_catch_command ("exec", _("Catch calls to exec."),
15885 catch_exec_command_1
,
15889 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15890 Usage: catch load [REGEX]\n\
15891 If REGEX is given, only stop for libraries matching the regular expression."),
15892 catch_load_command_1
,
15896 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15897 Usage: catch unload [REGEX]\n\
15898 If REGEX is given, only stop for libraries matching the regular expression."),
15899 catch_unload_command_1
,
15904 const auto opts
= make_watch_options_def_group (nullptr);
15906 static const std::string watch_help
= gdb::option::build_help (_("\
15907 Set a watchpoint for EXPRESSION.\n\
15908 Usage: watch [-location] EXPRESSION\n\
15913 A watchpoint stops execution of your program whenever the value of\n\
15914 an expression changes."), opts
);
15915 c
= add_com ("watch", class_breakpoint
, watch_command
,
15916 watch_help
.c_str ());
15917 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15919 static const std::string rwatch_help
= gdb::option::build_help (_("\
15920 Set a read watchpoint for EXPRESSION.\n\
15921 Usage: rwatch [-location] EXPRESSION\n\
15926 A read watchpoint stops execution of your program whenever the value of\n\
15927 an expression is read."), opts
);
15928 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
15929 rwatch_help
.c_str ());
15930 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15932 static const std::string awatch_help
= gdb::option::build_help (_("\
15933 Set an access watchpoint for EXPRESSION.\n\
15934 Usage: awatch [-location] EXPRESSION\n\
15939 An access watchpoint stops execution of your program whenever the value\n\
15940 of an expression is either read or written."), opts
);
15941 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
15942 awatch_help
.c_str ());
15943 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15945 add_info ("watchpoints", info_watchpoints_command
, _("\
15946 Status of specified watchpoints (all watchpoints if no argument)."));
15948 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15949 respond to changes - contrary to the description. */
15950 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15951 &can_use_hw_watchpoints
, _("\
15952 Set debugger's willingness to use watchpoint hardware."), _("\
15953 Show debugger's willingness to use watchpoint hardware."), _("\
15954 If zero, gdb will not use hardware for new watchpoints, even if\n\
15955 such is available. (However, any hardware watchpoints that were\n\
15956 created before setting this to nonzero, will continue to use watchpoint\n\
15959 show_can_use_hw_watchpoints
,
15960 &setlist
, &showlist
);
15962 can_use_hw_watchpoints
= 1;
15964 /* Tracepoint manipulation commands. */
15966 cmd_list_element
*trace_cmd
15967 = add_com ("trace", class_breakpoint
, trace_command
, _("\
15968 Set a tracepoint at specified location.\n\
15970 BREAK_ARGS_HELP ("trace") "\n\
15971 Do \"help tracepoints\" for info on other tracepoint commands."));
15972 set_cmd_completer (trace_cmd
, location_completer
);
15974 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
15975 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
15976 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
15977 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
15979 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15980 Set a fast tracepoint at specified location.\n\
15982 BREAK_ARGS_HELP ("ftrace") "\n\
15983 Do \"help tracepoints\" for info on other tracepoint commands."));
15984 set_cmd_completer (c
, location_completer
);
15986 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15987 Set a static tracepoint at location or marker.\n\
15989 strace [LOCATION] [if CONDITION]\n\
15990 LOCATION may be a linespec, explicit, or address location (described below) \n\
15991 or -m MARKER_ID.\n\n\
15992 If a marker id is specified, probe the marker with that name. With\n\
15993 no LOCATION, uses current execution address of the selected stack frame.\n\
15994 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15995 This collects arbitrary user data passed in the probe point call to the\n\
15996 tracing library. You can inspect it when analyzing the trace buffer,\n\
15997 by printing the $_sdata variable like any other convenience variable.\n\
15999 CONDITION is a boolean expression.\n\
16000 \n" LOCATION_HELP_STRING
"\n\n\
16001 Multiple tracepoints at one place are permitted, and useful if their\n\
16002 conditions are different.\n\
16004 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16005 Do \"help tracepoints\" for info on other tracepoint commands."));
16006 set_cmd_completer (c
, location_completer
);
16008 cmd_list_element
*info_tracepoints_cmd
16009 = add_info ("tracepoints", info_tracepoints_command
, _("\
16010 Status of specified tracepoints (all tracepoints if no argument).\n\
16011 Convenience variable \"$tpnum\" contains the number of the\n\
16012 last tracepoint set."));
16014 add_info_alias ("tp", info_tracepoints_cmd
, 1);
16016 cmd_list_element
*delete_tracepoints_cmd
16017 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16018 Delete specified tracepoints.\n\
16019 Arguments are tracepoint numbers, separated by spaces.\n\
16020 No argument means delete all tracepoints."),
16022 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
16024 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16025 Disable specified tracepoints.\n\
16026 Arguments are tracepoint numbers, separated by spaces.\n\
16027 No argument means disable all tracepoints."),
16029 deprecate_cmd (c
, "disable");
16031 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16032 Enable specified tracepoints.\n\
16033 Arguments are tracepoint numbers, separated by spaces.\n\
16034 No argument means enable all tracepoints."),
16036 deprecate_cmd (c
, "enable");
16038 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16039 Set the passcount for a tracepoint.\n\
16040 The trace will end when the tracepoint has been passed 'count' times.\n\
16041 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16042 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16044 add_basic_prefix_cmd ("save", class_breakpoint
,
16045 _("Save breakpoint definitions as a script."),
16047 0/*allow-unknown*/, &cmdlist
);
16049 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16050 Save current breakpoint definitions as a script.\n\
16051 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16052 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16053 session to restore them."),
16055 set_cmd_completer (c
, filename_completer
);
16057 cmd_list_element
*save_tracepoints_cmd
16058 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16059 Save current tracepoint definitions as a script.\n\
16060 Use the 'source' command in another debug session to restore them."),
16062 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
16064 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
16065 deprecate_cmd (c
, "save tracepoints");
16067 add_basic_prefix_cmd ("breakpoint", class_maintenance
, _("\
16068 Breakpoint specific settings.\n\
16069 Configure various breakpoint-specific variables such as\n\
16070 pending breakpoint behavior."),
16071 &breakpoint_set_cmdlist
,
16072 0/*allow-unknown*/, &setlist
);
16073 add_show_prefix_cmd ("breakpoint", class_maintenance
, _("\
16074 Breakpoint specific settings.\n\
16075 Configure various breakpoint-specific variables such as\n\
16076 pending breakpoint behavior."),
16077 &breakpoint_show_cmdlist
,
16078 0/*allow-unknown*/, &showlist
);
16080 add_setshow_auto_boolean_cmd ("pending", no_class
,
16081 &pending_break_support
, _("\
16082 Set debugger's behavior regarding pending breakpoints."), _("\
16083 Show debugger's behavior regarding pending breakpoints."), _("\
16084 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16085 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16086 an error. If auto, an unrecognized breakpoint location results in a\n\
16087 user-query to see if a pending breakpoint should be created."),
16089 show_pending_break_support
,
16090 &breakpoint_set_cmdlist
,
16091 &breakpoint_show_cmdlist
);
16093 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16095 add_setshow_boolean_cmd ("auto-hw", no_class
,
16096 &automatic_hardware_breakpoints
, _("\
16097 Set automatic usage of hardware breakpoints."), _("\
16098 Show automatic usage of hardware breakpoints."), _("\
16099 If set, the debugger will automatically use hardware breakpoints for\n\
16100 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16101 a warning will be emitted for such breakpoints."),
16103 show_automatic_hardware_breakpoints
,
16104 &breakpoint_set_cmdlist
,
16105 &breakpoint_show_cmdlist
);
16107 add_setshow_boolean_cmd ("always-inserted", class_support
,
16108 &always_inserted_mode
, _("\
16109 Set mode for inserting breakpoints."), _("\
16110 Show mode for inserting breakpoints."), _("\
16111 When this mode is on, breakpoints are inserted immediately as soon as\n\
16112 they're created, kept inserted even when execution stops, and removed\n\
16113 only when the user deletes them. When this mode is off (the default),\n\
16114 breakpoints are inserted only when execution continues, and removed\n\
16115 when execution stops."),
16117 &show_always_inserted_mode
,
16118 &breakpoint_set_cmdlist
,
16119 &breakpoint_show_cmdlist
);
16121 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16122 condition_evaluation_enums
,
16123 &condition_evaluation_mode_1
, _("\
16124 Set mode of breakpoint condition evaluation."), _("\
16125 Show mode of breakpoint condition evaluation."), _("\
16126 When this is set to \"host\", breakpoint conditions will be\n\
16127 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16128 breakpoint conditions will be downloaded to the target (if the target\n\
16129 supports such feature) and conditions will be evaluated on the target's side.\n\
16130 If this is set to \"auto\" (default), this will be automatically set to\n\
16131 \"target\" if it supports condition evaluation, otherwise it will\n\
16132 be set to \"host\"."),
16133 &set_condition_evaluation_mode
,
16134 &show_condition_evaluation_mode
,
16135 &breakpoint_set_cmdlist
,
16136 &breakpoint_show_cmdlist
);
16138 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16139 Set a breakpoint for an address range.\n\
16140 break-range START-LOCATION, END-LOCATION\n\
16141 where START-LOCATION and END-LOCATION can be one of the following:\n\
16142 LINENUM, for that line in the current file,\n\
16143 FILE:LINENUM, for that line in that file,\n\
16144 +OFFSET, for that number of lines after the current line\n\
16145 or the start of the range\n\
16146 FUNCTION, for the first line in that function,\n\
16147 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16148 *ADDRESS, for the instruction at that address.\n\
16150 The breakpoint will stop execution of the inferior whenever it executes\n\
16151 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16152 range (including START-LOCATION and END-LOCATION)."));
16154 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16155 Set a dynamic printf at specified location.\n\
16156 dprintf location,format string,arg1,arg2,...\n\
16157 location may be a linespec, explicit, or address location.\n"
16158 "\n" LOCATION_HELP_STRING
));
16159 set_cmd_completer (c
, location_completer
);
16161 add_setshow_enum_cmd ("dprintf-style", class_support
,
16162 dprintf_style_enums
, &dprintf_style
, _("\
16163 Set the style of usage for dynamic printf."), _("\
16164 Show the style of usage for dynamic printf."), _("\
16165 This setting chooses how GDB will do a dynamic printf.\n\
16166 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16167 console, as with the \"printf\" command.\n\
16168 If the value is \"call\", the print is done by calling a function in your\n\
16169 program; by default printf(), but you can choose a different function or\n\
16170 output stream by setting dprintf-function and dprintf-channel."),
16171 update_dprintf_commands
, NULL
,
16172 &setlist
, &showlist
);
16174 dprintf_function
= xstrdup ("printf");
16175 add_setshow_string_cmd ("dprintf-function", class_support
,
16176 &dprintf_function
, _("\
16177 Set the function to use for dynamic printf."), _("\
16178 Show the function to use for dynamic printf."), NULL
,
16179 update_dprintf_commands
, NULL
,
16180 &setlist
, &showlist
);
16182 dprintf_channel
= xstrdup ("");
16183 add_setshow_string_cmd ("dprintf-channel", class_support
,
16184 &dprintf_channel
, _("\
16185 Set the channel to use for dynamic printf."), _("\
16186 Show the channel to use for dynamic printf."), NULL
,
16187 update_dprintf_commands
, NULL
,
16188 &setlist
, &showlist
);
16190 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16191 &disconnected_dprintf
, _("\
16192 Set whether dprintf continues after GDB disconnects."), _("\
16193 Show whether dprintf continues after GDB disconnects."), _("\
16194 Use this to let dprintf commands continue to hit and produce output\n\
16195 even if GDB disconnects or detaches from the target."),
16198 &setlist
, &showlist
);
16200 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16201 Target agent only formatted printing, like the C \"printf\" function.\n\
16202 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
16203 This supports most C printf format specifications, like %s, %d, etc.\n\
16204 This is useful for formatted output in user-defined commands."));
16206 automatic_hardware_breakpoints
= true;
16208 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
16210 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,