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(B) for (B = breakpoint_chain; B; B = B->next)
491 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
492 for (B = breakpoint_chain; \
493 B ? (TMP=B->next, 1): 0; \
496 /* Similar iterator for the low-level breakpoints. SAFE variant is
497 not provided so update_global_location_list must not be called
498 while executing the block of ALL_BP_LOCATIONS. */
500 #define ALL_BP_LOCATIONS(B,BP_TMP) \
501 for (BP_TMP = bp_locations; \
502 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
505 /* Iterates through locations with address ADDRESS for the currently selected
506 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
507 to where the loop should start from.
508 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
509 appropriate location to start with. */
511 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
512 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
513 BP_LOCP_TMP = BP_LOCP_START; \
515 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
516 && (*BP_LOCP_TMP)->address == ADDRESS); \
519 /* Iterator for tracepoints only. */
521 #define ALL_TRACEPOINTS(B) \
522 for (B = breakpoint_chain; B; B = B->next) \
523 if (is_tracepoint (B))
525 /* Chains of all breakpoints defined. */
527 static struct breakpoint
*breakpoint_chain
;
529 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
531 static struct bp_location
**bp_locations
;
533 /* Number of elements of BP_LOCATIONS. */
535 static unsigned bp_locations_count
;
537 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
538 ADDRESS for the current elements of BP_LOCATIONS which get a valid
539 result from bp_location_has_shadow. You can use it for roughly
540 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
541 an address you need to read. */
543 static CORE_ADDR bp_locations_placed_address_before_address_max
;
545 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
546 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
547 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
548 You can use it for roughly limiting the subrange of BP_LOCATIONS to
549 scan for shadow bytes for an address you need to read. */
551 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
553 /* The locations that no longer correspond to any breakpoint, unlinked
554 from the bp_locations array, but for which a hit may still be
555 reported by a target. */
556 static std::vector
<bp_location
*> moribund_locations
;
558 /* Number of last breakpoint made. */
560 static int breakpoint_count
;
562 /* The value of `breakpoint_count' before the last command that
563 created breakpoints. If the last (break-like) command created more
564 than one breakpoint, then the difference between BREAKPOINT_COUNT
565 and PREV_BREAKPOINT_COUNT is more than one. */
566 static int prev_breakpoint_count
;
568 /* Number of last tracepoint made. */
570 static int tracepoint_count
;
572 static struct cmd_list_element
*breakpoint_set_cmdlist
;
573 static struct cmd_list_element
*breakpoint_show_cmdlist
;
574 struct cmd_list_element
*save_cmdlist
;
576 /* See declaration at breakpoint.h. */
579 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
582 struct breakpoint
*b
= NULL
;
586 if (func (b
, user_data
) != 0)
593 /* Return whether a breakpoint is an active enabled breakpoint. */
595 breakpoint_enabled (struct breakpoint
*b
)
597 return (b
->enable_state
== bp_enabled
);
600 /* Set breakpoint count to NUM. */
603 set_breakpoint_count (int num
)
605 prev_breakpoint_count
= breakpoint_count
;
606 breakpoint_count
= num
;
607 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
610 /* Used by `start_rbreak_breakpoints' below, to record the current
611 breakpoint count before "rbreak" creates any breakpoint. */
612 static int rbreak_start_breakpoint_count
;
614 /* Called at the start an "rbreak" command to record the first
617 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
619 rbreak_start_breakpoint_count
= breakpoint_count
;
622 /* Called at the end of an "rbreak" command to record the last
625 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
627 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
630 /* Used in run_command to zero the hit count when a new run starts. */
633 clear_breakpoint_hit_counts (void)
635 struct breakpoint
*b
;
642 /* Return the breakpoint with the specified number, or NULL
643 if the number does not refer to an existing breakpoint. */
646 get_breakpoint (int num
)
648 struct breakpoint
*b
;
651 if (b
->number
== num
)
659 /* Mark locations as "conditions have changed" in case the target supports
660 evaluating conditions on its side. */
663 mark_breakpoint_modified (struct breakpoint
*b
)
665 struct bp_location
*loc
;
667 /* This is only meaningful if the target is
668 evaluating conditions and if the user has
669 opted for condition evaluation on the target's
671 if (gdb_evaluates_breakpoint_condition_p ()
672 || !target_supports_evaluation_of_breakpoint_conditions ())
675 if (!is_breakpoint (b
))
678 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
679 loc
->condition_changed
= condition_modified
;
682 /* Mark location as "conditions have changed" in case the target supports
683 evaluating conditions on its side. */
686 mark_breakpoint_location_modified (struct bp_location
*loc
)
688 /* This is only meaningful if the target is
689 evaluating conditions and if the user has
690 opted for condition evaluation on the target's
692 if (gdb_evaluates_breakpoint_condition_p ()
693 || !target_supports_evaluation_of_breakpoint_conditions ())
697 if (!is_breakpoint (loc
->owner
))
700 loc
->condition_changed
= condition_modified
;
703 /* Sets the condition-evaluation mode using the static global
704 condition_evaluation_mode. */
707 set_condition_evaluation_mode (const char *args
, int from_tty
,
708 struct cmd_list_element
*c
)
710 const char *old_mode
, *new_mode
;
712 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
713 && !target_supports_evaluation_of_breakpoint_conditions ())
715 condition_evaluation_mode_1
= condition_evaluation_mode
;
716 warning (_("Target does not support breakpoint condition evaluation.\n"
717 "Using host evaluation mode instead."));
721 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
722 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
724 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
725 settings was "auto". */
726 condition_evaluation_mode
= condition_evaluation_mode_1
;
728 /* Only update the mode if the user picked a different one. */
729 if (new_mode
!= old_mode
)
731 struct bp_location
*loc
, **loc_tmp
;
732 /* If the user switched to a different evaluation mode, we
733 need to synch the changes with the target as follows:
735 "host" -> "target": Send all (valid) conditions to the target.
736 "target" -> "host": Remove all the conditions from the target.
739 if (new_mode
== condition_evaluation_target
)
741 /* Mark everything modified and synch conditions with the
743 ALL_BP_LOCATIONS (loc
, loc_tmp
)
744 mark_breakpoint_location_modified (loc
);
748 /* Manually mark non-duplicate locations to synch conditions
749 with the target. We do this to remove all the conditions the
750 target knows about. */
751 ALL_BP_LOCATIONS (loc
, loc_tmp
)
752 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
753 loc
->needs_update
= 1;
757 update_global_location_list (UGLL_MAY_INSERT
);
763 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
764 what "auto" is translating to. */
767 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
768 struct cmd_list_element
*c
, const char *value
)
770 if (condition_evaluation_mode
== condition_evaluation_auto
)
771 fprintf_filtered (file
,
772 _("Breakpoint condition evaluation "
773 "mode is %s (currently %s).\n"),
775 breakpoint_condition_evaluation_mode ());
777 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
781 /* A comparison function for bp_location AP and BP that is used by
782 bsearch. This comparison function only cares about addresses, unlike
783 the more general bp_location_is_less_than function. */
786 bp_locations_compare_addrs (const void *ap
, const void *bp
)
788 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
789 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
791 if (a
->address
== b
->address
)
794 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
797 /* Helper function to skip all bp_locations with addresses
798 less than ADDRESS. It returns the first bp_location that
799 is greater than or equal to ADDRESS. If none is found, just
802 static struct bp_location
**
803 get_first_locp_gte_addr (CORE_ADDR address
)
805 struct bp_location dummy_loc
;
806 struct bp_location
*dummy_locp
= &dummy_loc
;
807 struct bp_location
**locp_found
= NULL
;
809 /* Initialize the dummy location's address field. */
810 dummy_loc
.address
= address
;
812 /* Find a close match to the first location at ADDRESS. */
813 locp_found
= ((struct bp_location
**)
814 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
815 sizeof (struct bp_location
**),
816 bp_locations_compare_addrs
));
818 /* Nothing was found, nothing left to do. */
819 if (locp_found
== NULL
)
822 /* We may have found a location that is at ADDRESS but is not the first in the
823 location's list. Go backwards (if possible) and locate the first one. */
824 while ((locp_found
- 1) >= bp_locations
825 && (*(locp_found
- 1))->address
== address
)
831 /* Parse COND_STRING in the context of LOC and set as the condition
832 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
833 the number of LOC within its owner. In case of parsing error, mark
834 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
837 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
838 int bp_num
, int loc_num
)
840 bool has_junk
= false;
843 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
844 block_for_pc (loc
->address
), 0);
845 if (*cond_string
!= 0)
849 loc
->cond
= std::move (new_exp
);
850 if (loc
->disabled_by_cond
&& loc
->enabled
)
851 printf_filtered (_("Breakpoint %d's condition is now valid at "
852 "location %d, enabling.\n"),
855 loc
->disabled_by_cond
= false;
858 catch (const gdb_exception_error
&e
)
862 /* Warn if a user-enabled location is now becoming disabled-by-cond.
863 BP_NUM is 0 if the breakpoint is being defined for the first
864 time using the "break ... if ..." command, and non-zero if
867 warning (_("failed to validate condition at location %d.%d, "
868 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
870 warning (_("failed to validate condition at location %d, "
871 "disabling:\n %s"), loc_num
, e
.what ());
874 loc
->disabled_by_cond
= true;
878 error (_("Garbage '%s' follows condition"), cond_string
);
882 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
883 int from_tty
, bool force
)
887 xfree (b
->cond_string
);
888 b
->cond_string
= nullptr;
890 if (is_watchpoint (b
))
891 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
895 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
898 if (loc
->disabled_by_cond
&& loc
->enabled
)
899 printf_filtered (_("Breakpoint %d's condition is now valid at "
900 "location %d, enabling.\n"),
902 loc
->disabled_by_cond
= false;
905 /* No need to free the condition agent expression
906 bytecode (if we have one). We will handle this
907 when we go through update_global_location_list. */
912 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
916 if (is_watchpoint (b
))
918 innermost_block_tracker tracker
;
919 const char *arg
= exp
;
920 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
922 error (_("Junk at end of expression"));
923 watchpoint
*w
= static_cast<watchpoint
*> (b
);
924 w
->cond_exp
= std::move (new_exp
);
925 w
->cond_exp_valid_block
= tracker
.block ();
929 /* Parse and set condition expressions. We make two passes.
930 In the first, we parse the condition string to see if it
931 is valid in at least one location. If so, the condition
932 would be accepted. So we go ahead and set the locations'
933 conditions. In case no valid case is found, we throw
934 the error and the condition string will be rejected.
935 This two-pass approach is taken to avoid setting the
936 state of locations in case of a reject. */
937 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
941 const char *arg
= exp
;
942 parse_exp_1 (&arg
, loc
->address
,
943 block_for_pc (loc
->address
), 0);
945 error (_("Junk at end of expression"));
948 catch (const gdb_exception_error
&e
)
950 /* Condition string is invalid. If this happens to
951 be the last loc, abandon (if not forced) or continue
953 if (loc
->next
== nullptr && !force
)
958 /* If we reach here, the condition is valid at some locations. */
960 for (bp_location
*loc
= b
->loc
; loc
!= nullptr;
961 loc
= loc
->next
, loc_num
++)
962 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
965 /* We know that the new condition parsed successfully. The
966 condition string of the breakpoint can be safely updated. */
967 xfree (b
->cond_string
);
968 b
->cond_string
= xstrdup (exp
);
969 b
->condition_not_parsed
= 0;
971 mark_breakpoint_modified (b
);
973 gdb::observers::breakpoint_modified
.notify (b
);
976 /* See breakpoint.h. */
979 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
982 struct breakpoint
*b
;
984 if (b
->number
== bpnum
)
986 /* Check if this breakpoint has a "stop" method implemented in an
987 extension language. This method and conditions entered into GDB
988 from the CLI are mutually exclusive. */
989 const struct extension_language_defn
*extlang
990 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
994 error (_("Only one stop condition allowed. There is currently"
995 " a %s stop condition defined for this breakpoint."),
996 ext_lang_capitalized_name (extlang
));
998 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1000 if (is_breakpoint (b
))
1001 update_global_location_list (UGLL_MAY_INSERT
);
1006 error (_("No breakpoint number %d."), bpnum
);
1009 /* The options for the "condition" command. */
1011 struct condition_command_opts
1014 bool force_condition
= false;
1017 static const gdb::option::option_def condition_command_option_defs
[] = {
1019 gdb::option::flag_option_def
<condition_command_opts
> {
1021 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1022 N_("Set the condition even if it is invalid for all current locations."),
1027 /* Create an option_def_group for the "condition" options, with
1028 CC_OPTS as context. */
1030 static inline gdb::option::option_def_group
1031 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1033 return {{condition_command_option_defs
}, cc_opts
};
1036 /* Completion for the "condition" command. */
1039 condition_completer (struct cmd_list_element
*cmd
,
1040 completion_tracker
&tracker
,
1041 const char *text
, const char * /*word*/)
1043 bool has_no_arguments
= (*text
== '\0');
1044 condition_command_opts cc_opts
;
1045 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1046 if (gdb::option::complete_options
1047 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1050 text
= skip_spaces (text
);
1051 const char *space
= skip_to_space (text
);
1055 struct breakpoint
*b
;
1059 tracker
.advance_custom_word_point_by (1);
1060 /* We don't support completion of history indices. */
1061 if (!isdigit (text
[1]))
1062 complete_internalvar (tracker
, &text
[1]);
1066 /* Suggest the "-force" flag if no arguments are given. If
1067 arguments were passed, they either already include the flag,
1068 or we are beyond the point of suggesting it because it's
1069 positionally the first argument. */
1070 if (has_no_arguments
)
1071 gdb::option::complete_on_all_options (tracker
, group
);
1073 /* We're completing the breakpoint number. */
1074 len
= strlen (text
);
1080 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1082 if (strncmp (number
, text
, len
) == 0)
1083 tracker
.add_completion (make_unique_xstrdup (number
));
1089 /* We're completing the expression part. Skip the breakpoint num. */
1090 const char *exp_start
= skip_spaces (space
);
1091 tracker
.advance_custom_word_point_by (exp_start
- text
);
1093 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1094 expression_completer (cmd
, tracker
, text
, word
);
1097 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1100 condition_command (const char *arg
, int from_tty
)
1106 error_no_arg (_("breakpoint number"));
1110 /* Check if the "-force" flag was passed. */
1111 condition_command_opts cc_opts
;
1112 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1113 gdb::option::process_options
1114 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1116 bnum
= get_number (&p
);
1118 error (_("Bad breakpoint argument: '%s'"), arg
);
1120 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1123 /* Check that COMMAND do not contain commands that are suitable
1124 only for tracepoints and not suitable for ordinary breakpoints.
1125 Throw if any such commands is found. */
1128 check_no_tracepoint_commands (struct command_line
*commands
)
1130 struct command_line
*c
;
1132 for (c
= commands
; c
; c
= c
->next
)
1134 if (c
->control_type
== while_stepping_control
)
1135 error (_("The 'while-stepping' command can "
1136 "only be used for tracepoints"));
1138 check_no_tracepoint_commands (c
->body_list_0
.get ());
1139 check_no_tracepoint_commands (c
->body_list_1
.get ());
1141 /* Not that command parsing removes leading whitespace and comment
1142 lines and also empty lines. So, we only need to check for
1143 command directly. */
1144 if (strstr (c
->line
, "collect ") == c
->line
)
1145 error (_("The 'collect' command can only be used for tracepoints"));
1147 if (strstr (c
->line
, "teval ") == c
->line
)
1148 error (_("The 'teval' command can only be used for tracepoints"));
1152 struct longjmp_breakpoint
: public breakpoint
1154 ~longjmp_breakpoint () override
;
1157 /* Encapsulate tests for different types of tracepoints. */
1160 is_tracepoint_type (bptype type
)
1162 return (type
== bp_tracepoint
1163 || type
== bp_fast_tracepoint
1164 || type
== bp_static_tracepoint
);
1168 is_longjmp_type (bptype type
)
1170 return type
== bp_longjmp
|| type
== bp_exception
;
1173 /* See breakpoint.h. */
1176 is_tracepoint (const struct breakpoint
*b
)
1178 return is_tracepoint_type (b
->type
);
1181 /* Factory function to create an appropriate instance of breakpoint given
1184 static std::unique_ptr
<breakpoint
>
1185 new_breakpoint_from_type (bptype type
)
1189 if (is_tracepoint_type (type
))
1190 b
= new tracepoint ();
1191 else if (is_longjmp_type (type
))
1192 b
= new longjmp_breakpoint ();
1194 b
= new breakpoint ();
1196 return std::unique_ptr
<breakpoint
> (b
);
1199 /* A helper function that validates that COMMANDS are valid for a
1200 breakpoint. This function will throw an exception if a problem is
1204 validate_commands_for_breakpoint (struct breakpoint
*b
,
1205 struct command_line
*commands
)
1207 if (is_tracepoint (b
))
1209 struct tracepoint
*t
= (struct tracepoint
*) b
;
1210 struct command_line
*c
;
1211 struct command_line
*while_stepping
= 0;
1213 /* Reset the while-stepping step count. The previous commands
1214 might have included a while-stepping action, while the new
1218 /* We need to verify that each top-level element of commands is
1219 valid for tracepoints, that there's at most one
1220 while-stepping element, and that the while-stepping's body
1221 has valid tracing commands excluding nested while-stepping.
1222 We also need to validate the tracepoint action line in the
1223 context of the tracepoint --- validate_actionline actually
1224 has side effects, like setting the tracepoint's
1225 while-stepping STEP_COUNT, in addition to checking if the
1226 collect/teval actions parse and make sense in the
1227 tracepoint's context. */
1228 for (c
= commands
; c
; c
= c
->next
)
1230 if (c
->control_type
== while_stepping_control
)
1232 if (b
->type
== bp_fast_tracepoint
)
1233 error (_("The 'while-stepping' command "
1234 "cannot be used for fast tracepoint"));
1235 else if (b
->type
== bp_static_tracepoint
)
1236 error (_("The 'while-stepping' command "
1237 "cannot be used for static tracepoint"));
1240 error (_("The 'while-stepping' command "
1241 "can be used only once"));
1246 validate_actionline (c
->line
, b
);
1250 struct command_line
*c2
;
1252 gdb_assert (while_stepping
->body_list_1
== nullptr);
1253 c2
= while_stepping
->body_list_0
.get ();
1254 for (; c2
; c2
= c2
->next
)
1256 if (c2
->control_type
== while_stepping_control
)
1257 error (_("The 'while-stepping' command cannot be nested"));
1263 check_no_tracepoint_commands (commands
);
1267 /* Return a vector of all the static tracepoints set at ADDR. The
1268 caller is responsible for releasing the vector. */
1270 std::vector
<breakpoint
*>
1271 static_tracepoints_here (CORE_ADDR addr
)
1273 struct breakpoint
*b
;
1274 std::vector
<breakpoint
*> found
;
1275 struct bp_location
*loc
;
1278 if (b
->type
== bp_static_tracepoint
)
1280 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1281 if (loc
->address
== addr
)
1282 found
.push_back (b
);
1288 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1289 validate that only allowed commands are included. */
1292 breakpoint_set_commands (struct breakpoint
*b
,
1293 counted_command_line
&&commands
)
1295 validate_commands_for_breakpoint (b
, commands
.get ());
1297 b
->commands
= std::move (commands
);
1298 gdb::observers::breakpoint_modified
.notify (b
);
1301 /* Set the internal `silent' flag on the breakpoint. Note that this
1302 is not the same as the "silent" that may appear in the breakpoint's
1306 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1308 int old_silent
= b
->silent
;
1311 if (old_silent
!= silent
)
1312 gdb::observers::breakpoint_modified
.notify (b
);
1315 /* Set the thread for this breakpoint. If THREAD is -1, make the
1316 breakpoint work for any thread. */
1319 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1321 int old_thread
= b
->thread
;
1324 if (old_thread
!= thread
)
1325 gdb::observers::breakpoint_modified
.notify (b
);
1328 /* Set the task for this breakpoint. If TASK is 0, make the
1329 breakpoint work for any task. */
1332 breakpoint_set_task (struct breakpoint
*b
, int task
)
1334 int old_task
= b
->task
;
1337 if (old_task
!= task
)
1338 gdb::observers::breakpoint_modified
.notify (b
);
1342 commands_command_1 (const char *arg
, int from_tty
,
1343 struct command_line
*control
)
1345 counted_command_line cmd
;
1346 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1347 NULL after the call to read_command_lines if the user provides an empty
1348 list of command by just typing "end". */
1349 bool cmd_read
= false;
1351 std::string new_arg
;
1353 if (arg
== NULL
|| !*arg
)
1355 /* Argument not explicitly given. Synthesize it. */
1356 if (breakpoint_count
- prev_breakpoint_count
> 1)
1357 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1359 else if (breakpoint_count
> 0)
1360 new_arg
= string_printf ("%d", breakpoint_count
);
1364 /* Create a copy of ARG. This is needed because the "commands"
1365 command may be coming from a script. In that case, the read
1366 line buffer is going to be overwritten in the lambda of
1367 'map_breakpoint_numbers' below when reading the next line
1368 before we are are done parsing the breakpoint numbers. */
1371 arg
= new_arg
.c_str ();
1373 map_breakpoint_numbers
1374 (arg
, [&] (breakpoint
*b
)
1378 gdb_assert (cmd
== NULL
);
1379 if (control
!= NULL
)
1380 cmd
= control
->body_list_0
;
1384 = string_printf (_("Type commands for breakpoint(s) "
1385 "%s, one per line."),
1388 auto do_validate
= [=] (const char *line
)
1390 validate_actionline (line
, b
);
1392 gdb::function_view
<void (const char *)> validator
;
1393 if (is_tracepoint (b
))
1394 validator
= do_validate
;
1396 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1401 /* If a breakpoint was on the list more than once, we don't need to
1403 if (b
->commands
!= cmd
)
1405 validate_commands_for_breakpoint (b
, cmd
.get ());
1407 gdb::observers::breakpoint_modified
.notify (b
);
1413 commands_command (const char *arg
, int from_tty
)
1415 commands_command_1 (arg
, from_tty
, NULL
);
1418 /* Like commands_command, but instead of reading the commands from
1419 input stream, takes them from an already parsed command structure.
1421 This is used by cli-script.c to DTRT with breakpoint commands
1422 that are part of if and while bodies. */
1423 enum command_control_type
1424 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1426 commands_command_1 (arg
, 0, cmd
);
1427 return simple_control
;
1430 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1433 bp_location_has_shadow (struct bp_location
*bl
)
1435 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1439 if (bl
->target_info
.shadow_len
== 0)
1440 /* BL isn't valid, or doesn't shadow memory. */
1445 /* Update BUF, which is LEN bytes read from the target address
1446 MEMADDR, by replacing a memory breakpoint with its shadowed
1449 If READBUF is not NULL, this buffer must not overlap with the of
1450 the breakpoint location's shadow_contents buffer. Otherwise, a
1451 failed assertion internal error will be raised. */
1454 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1455 const gdb_byte
*writebuf_org
,
1456 ULONGEST memaddr
, LONGEST len
,
1457 struct bp_target_info
*target_info
,
1458 struct gdbarch
*gdbarch
)
1460 /* Now do full processing of the found relevant range of elements. */
1461 CORE_ADDR bp_addr
= 0;
1465 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1466 current_program_space
->aspace
, 0))
1468 /* The breakpoint is inserted in a different address space. */
1472 /* Addresses and length of the part of the breakpoint that
1474 bp_addr
= target_info
->placed_address
;
1475 bp_size
= target_info
->shadow_len
;
1477 if (bp_addr
+ bp_size
<= memaddr
)
1479 /* The breakpoint is entirely before the chunk of memory we are
1484 if (bp_addr
>= memaddr
+ len
)
1486 /* The breakpoint is entirely after the chunk of memory we are
1491 /* Offset within shadow_contents. */
1492 if (bp_addr
< memaddr
)
1494 /* Only copy the second part of the breakpoint. */
1495 bp_size
-= memaddr
- bp_addr
;
1496 bptoffset
= memaddr
- bp_addr
;
1500 if (bp_addr
+ bp_size
> memaddr
+ len
)
1502 /* Only copy the first part of the breakpoint. */
1503 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1506 if (readbuf
!= NULL
)
1508 /* Verify that the readbuf buffer does not overlap with the
1509 shadow_contents buffer. */
1510 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1511 || readbuf
>= (target_info
->shadow_contents
1512 + target_info
->shadow_len
));
1514 /* Update the read buffer with this inserted breakpoint's
1516 memcpy (readbuf
+ bp_addr
- memaddr
,
1517 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1521 const unsigned char *bp
;
1522 CORE_ADDR addr
= target_info
->reqstd_address
;
1525 /* Update the shadow with what we want to write to memory. */
1526 memcpy (target_info
->shadow_contents
+ bptoffset
,
1527 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1529 /* Determine appropriate breakpoint contents and size for this
1531 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1533 /* Update the final write buffer with this inserted
1534 breakpoint's INSN. */
1535 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1539 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1540 by replacing any memory breakpoints with their shadowed contents.
1542 If READBUF is not NULL, this buffer must not overlap with any of
1543 the breakpoint location's shadow_contents buffers. Otherwise,
1544 a failed assertion internal error will be raised.
1546 The range of shadowed area by each bp_location is:
1547 bl->address - bp_locations_placed_address_before_address_max
1548 up to bl->address + bp_locations_shadow_len_after_address_max
1549 The range we were requested to resolve shadows for is:
1550 memaddr ... memaddr + len
1551 Thus the safe cutoff boundaries for performance optimization are
1552 memaddr + len <= (bl->address
1553 - bp_locations_placed_address_before_address_max)
1555 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1558 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1559 const gdb_byte
*writebuf_org
,
1560 ULONGEST memaddr
, LONGEST len
)
1562 /* Left boundary, right boundary and median element of our binary
1564 unsigned bc_l
, bc_r
, bc
;
1566 /* Find BC_L which is a leftmost element which may affect BUF
1567 content. It is safe to report lower value but a failure to
1568 report higher one. */
1571 bc_r
= bp_locations_count
;
1572 while (bc_l
+ 1 < bc_r
)
1574 struct bp_location
*bl
;
1576 bc
= (bc_l
+ bc_r
) / 2;
1577 bl
= bp_locations
[bc
];
1579 /* Check first BL->ADDRESS will not overflow due to the added
1580 constant. Then advance the left boundary only if we are sure
1581 the BC element can in no way affect the BUF content (MEMADDR
1582 to MEMADDR + LEN range).
1584 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1585 offset so that we cannot miss a breakpoint with its shadow
1586 range tail still reaching MEMADDR. */
1588 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1590 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1597 /* Due to the binary search above, we need to make sure we pick the
1598 first location that's at BC_L's address. E.g., if there are
1599 multiple locations at the same address, BC_L may end up pointing
1600 at a duplicate location, and miss the "master"/"inserted"
1601 location. Say, given locations L1, L2 and L3 at addresses A and
1604 L1@A, L2@A, L3@B, ...
1606 BC_L could end up pointing at location L2, while the "master"
1607 location could be L1. Since the `loc->inserted' flag is only set
1608 on "master" locations, we'd forget to restore the shadow of L1
1611 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1614 /* Now do full processing of the found relevant range of elements. */
1616 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1618 struct bp_location
*bl
= bp_locations
[bc
];
1620 /* bp_location array has BL->OWNER always non-NULL. */
1621 if (bl
->owner
->type
== bp_none
)
1622 warning (_("reading through apparently deleted breakpoint #%d?"),
1625 /* Performance optimization: any further element can no longer affect BUF
1628 if (bl
->address
>= bp_locations_placed_address_before_address_max
1629 && memaddr
+ len
<= (bl
->address
1630 - bp_locations_placed_address_before_address_max
))
1633 if (!bp_location_has_shadow (bl
))
1636 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1637 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1641 /* See breakpoint.h. */
1644 is_breakpoint (const struct breakpoint
*bpt
)
1646 return (bpt
->type
== bp_breakpoint
1647 || bpt
->type
== bp_hardware_breakpoint
1648 || bpt
->type
== bp_dprintf
);
1651 /* Return true if BPT is of any hardware watchpoint kind. */
1654 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1656 return (bpt
->type
== bp_hardware_watchpoint
1657 || bpt
->type
== bp_read_watchpoint
1658 || bpt
->type
== bp_access_watchpoint
);
1661 /* See breakpoint.h. */
1664 is_watchpoint (const struct breakpoint
*bpt
)
1666 return (is_hardware_watchpoint (bpt
)
1667 || bpt
->type
== bp_watchpoint
);
1670 /* Returns true if the current thread and its running state are safe
1671 to evaluate or update watchpoint B. Watchpoints on local
1672 expressions need to be evaluated in the context of the thread that
1673 was current when the watchpoint was created, and, that thread needs
1674 to be stopped to be able to select the correct frame context.
1675 Watchpoints on global expressions can be evaluated on any thread,
1676 and in any state. It is presently left to the target allowing
1677 memory accesses when threads are running. */
1680 watchpoint_in_thread_scope (struct watchpoint
*b
)
1682 return (b
->pspace
== current_program_space
1683 && (b
->watchpoint_thread
== null_ptid
1684 || (inferior_ptid
== b
->watchpoint_thread
1685 && !inferior_thread ()->executing
)));
1688 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1689 associated bp_watchpoint_scope breakpoint. */
1692 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1694 if (w
->related_breakpoint
!= w
)
1696 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1697 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1698 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1699 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1700 w
->related_breakpoint
= w
;
1702 w
->disposition
= disp_del_at_next_stop
;
1705 /* Extract a bitfield value from value VAL using the bit parameters contained in
1708 static struct value
*
1709 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1711 struct value
*bit_val
;
1716 bit_val
= allocate_value (value_type (val
));
1718 unpack_value_bitfield (bit_val
,
1721 value_contents_for_printing (val
),
1728 /* Allocate a dummy location and add it to B, which must be a software
1729 watchpoint. This is required because even if a software watchpoint
1730 is not watching any memory, bpstat_stop_status requires a location
1731 to be able to report stops. */
1734 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1735 struct program_space
*pspace
)
1737 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1739 b
->loc
= allocate_bp_location (b
);
1740 b
->loc
->pspace
= pspace
;
1741 b
->loc
->address
= -1;
1742 b
->loc
->length
= -1;
1745 /* Returns true if B is a software watchpoint that is not watching any
1746 memory (e.g., "watch $pc"). */
1749 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1751 return (b
->type
== bp_watchpoint
1753 && b
->loc
->next
== NULL
1754 && b
->loc
->address
== -1
1755 && b
->loc
->length
== -1);
1758 /* Assuming that B is a watchpoint:
1759 - Reparse watchpoint expression, if REPARSE is non-zero
1760 - Evaluate expression and store the result in B->val
1761 - Evaluate the condition if there is one, and store the result
1763 - Update the list of values that must be watched in B->loc.
1765 If the watchpoint disposition is disp_del_at_next_stop, then do
1766 nothing. If this is local watchpoint that is out of scope, delete
1769 Even with `set breakpoint always-inserted on' the watchpoints are
1770 removed + inserted on each stop here. Normal breakpoints must
1771 never be removed because they might be missed by a running thread
1772 when debugging in non-stop mode. On the other hand, hardware
1773 watchpoints (is_hardware_watchpoint; processed here) are specific
1774 to each LWP since they are stored in each LWP's hardware debug
1775 registers. Therefore, such LWP must be stopped first in order to
1776 be able to modify its hardware watchpoints.
1778 Hardware watchpoints must be reset exactly once after being
1779 presented to the user. It cannot be done sooner, because it would
1780 reset the data used to present the watchpoint hit to the user. And
1781 it must not be done later because it could display the same single
1782 watchpoint hit during multiple GDB stops. Note that the latter is
1783 relevant only to the hardware watchpoint types bp_read_watchpoint
1784 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1785 not user-visible - its hit is suppressed if the memory content has
1788 The following constraints influence the location where we can reset
1789 hardware watchpoints:
1791 * target_stopped_by_watchpoint and target_stopped_data_address are
1792 called several times when GDB stops.
1795 * Multiple hardware watchpoints can be hit at the same time,
1796 causing GDB to stop. GDB only presents one hardware watchpoint
1797 hit at a time as the reason for stopping, and all the other hits
1798 are presented later, one after the other, each time the user
1799 requests the execution to be resumed. Execution is not resumed
1800 for the threads still having pending hit event stored in
1801 LWP_INFO->STATUS. While the watchpoint is already removed from
1802 the inferior on the first stop the thread hit event is kept being
1803 reported from its cached value by linux_nat_stopped_data_address
1804 until the real thread resume happens after the watchpoint gets
1805 presented and thus its LWP_INFO->STATUS gets reset.
1807 Therefore the hardware watchpoint hit can get safely reset on the
1808 watchpoint removal from inferior. */
1811 update_watchpoint (struct watchpoint
*b
, int reparse
)
1813 int within_current_scope
;
1814 struct frame_id saved_frame_id
;
1817 /* If this is a local watchpoint, we only want to check if the
1818 watchpoint frame is in scope if the current thread is the thread
1819 that was used to create the watchpoint. */
1820 if (!watchpoint_in_thread_scope (b
))
1823 if (b
->disposition
== disp_del_at_next_stop
)
1828 /* Determine if the watchpoint is within scope. */
1829 if (b
->exp_valid_block
== NULL
)
1830 within_current_scope
= 1;
1833 struct frame_info
*fi
= get_current_frame ();
1834 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1835 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1837 /* If we're at a point where the stack has been destroyed
1838 (e.g. in a function epilogue), unwinding may not work
1839 properly. Do not attempt to recreate locations at this
1840 point. See similar comments in watchpoint_check. */
1841 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1844 /* Save the current frame's ID so we can restore it after
1845 evaluating the watchpoint expression on its own frame. */
1846 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1847 took a frame parameter, so that we didn't have to change the
1850 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1852 fi
= frame_find_by_id (b
->watchpoint_frame
);
1853 within_current_scope
= (fi
!= NULL
);
1854 if (within_current_scope
)
1858 /* We don't free locations. They are stored in the bp_location array
1859 and update_global_location_list will eventually delete them and
1860 remove breakpoints if needed. */
1863 if (within_current_scope
&& reparse
)
1868 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1869 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1870 /* If the meaning of expression itself changed, the old value is
1871 no longer relevant. We don't want to report a watchpoint hit
1872 to the user when the old value and the new value may actually
1873 be completely different objects. */
1875 b
->val_valid
= false;
1877 /* Note that unlike with breakpoints, the watchpoint's condition
1878 expression is stored in the breakpoint object, not in the
1879 locations (re)created below. */
1880 if (b
->cond_string
!= NULL
)
1882 b
->cond_exp
.reset ();
1885 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1889 /* If we failed to parse the expression, for example because
1890 it refers to a global variable in a not-yet-loaded shared library,
1891 don't try to insert watchpoint. We don't automatically delete
1892 such watchpoint, though, since failure to parse expression
1893 is different from out-of-scope watchpoint. */
1894 if (!target_has_execution ())
1896 /* Without execution, memory can't change. No use to try and
1897 set watchpoint locations. The watchpoint will be reset when
1898 the target gains execution, through breakpoint_re_set. */
1899 if (!can_use_hw_watchpoints
)
1901 if (b
->ops
->works_in_software_mode (b
))
1902 b
->type
= bp_watchpoint
;
1904 error (_("Can't set read/access watchpoint when "
1905 "hardware watchpoints are disabled."));
1908 else if (within_current_scope
&& b
->exp
)
1910 std::vector
<value_ref_ptr
> val_chain
;
1911 struct value
*v
, *result
;
1912 struct program_space
*frame_pspace
;
1914 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
1917 /* Avoid setting b->val if it's already set. The meaning of
1918 b->val is 'the last value' user saw, and we should update
1919 it only if we reported that last value to user. As it
1920 happens, the code that reports it updates b->val directly.
1921 We don't keep track of the memory value for masked
1923 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1925 if (b
->val_bitsize
!= 0)
1926 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1927 b
->val
= release_value (v
);
1928 b
->val_valid
= true;
1931 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1933 /* Look at each value on the value chain. */
1934 gdb_assert (!val_chain
.empty ());
1935 for (const value_ref_ptr
&iter
: val_chain
)
1939 /* If it's a memory location, and GDB actually needed
1940 its contents to evaluate the expression, then we
1941 must watch it. If the first value returned is
1942 still lazy, that means an error occurred reading it;
1943 watch it anyway in case it becomes readable. */
1944 if (VALUE_LVAL (v
) == lval_memory
1945 && (v
== val_chain
[0] || ! value_lazy (v
)))
1947 struct type
*vtype
= check_typedef (value_type (v
));
1949 /* We only watch structs and arrays if user asked
1950 for it explicitly, never if they just happen to
1951 appear in the middle of some value chain. */
1953 || (vtype
->code () != TYPE_CODE_STRUCT
1954 && vtype
->code () != TYPE_CODE_ARRAY
))
1957 enum target_hw_bp_type type
;
1958 struct bp_location
*loc
, **tmp
;
1959 int bitpos
= 0, bitsize
= 0;
1961 if (value_bitsize (v
) != 0)
1963 /* Extract the bit parameters out from the bitfield
1965 bitpos
= value_bitpos (v
);
1966 bitsize
= value_bitsize (v
);
1968 else if (v
== result
&& b
->val_bitsize
!= 0)
1970 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1971 lvalue whose bit parameters are saved in the fields
1972 VAL_BITPOS and VAL_BITSIZE. */
1973 bitpos
= b
->val_bitpos
;
1974 bitsize
= b
->val_bitsize
;
1977 addr
= value_address (v
);
1980 /* Skip the bytes that don't contain the bitfield. */
1985 if (b
->type
== bp_read_watchpoint
)
1987 else if (b
->type
== bp_access_watchpoint
)
1990 loc
= allocate_bp_location (b
);
1991 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1994 loc
->gdbarch
= value_type (v
)->arch ();
1996 loc
->pspace
= frame_pspace
;
1997 loc
->address
= address_significant (loc
->gdbarch
, addr
);
2001 /* Just cover the bytes that make up the bitfield. */
2002 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2005 loc
->length
= TYPE_LENGTH (value_type (v
));
2007 loc
->watchpoint_type
= type
;
2012 /* Change the type of breakpoint between hardware assisted or
2013 an ordinary watchpoint depending on the hardware support
2014 and free hardware slots. REPARSE is set when the inferior
2019 enum bp_loc_type loc_type
;
2020 struct bp_location
*bl
;
2022 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2026 int i
, target_resources_ok
, other_type_used
;
2029 /* Use an exact watchpoint when there's only one memory region to be
2030 watched, and only one debug register is needed to watch it. */
2031 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2033 /* We need to determine how many resources are already
2034 used for all other hardware watchpoints plus this one
2035 to see if we still have enough resources to also fit
2036 this watchpoint in as well. */
2038 /* If this is a software watchpoint, we try to turn it
2039 to a hardware one -- count resources as if B was of
2040 hardware watchpoint type. */
2042 if (type
== bp_watchpoint
)
2043 type
= bp_hardware_watchpoint
;
2045 /* This watchpoint may or may not have been placed on
2046 the list yet at this point (it won't be in the list
2047 if we're trying to create it for the first time,
2048 through watch_command), so always account for it
2051 /* Count resources used by all watchpoints except B. */
2052 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2054 /* Add in the resources needed for B. */
2055 i
+= hw_watchpoint_use_count (b
);
2058 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2059 if (target_resources_ok
<= 0)
2061 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2063 if (target_resources_ok
== 0 && !sw_mode
)
2064 error (_("Target does not support this type of "
2065 "hardware watchpoint."));
2066 else if (target_resources_ok
< 0 && !sw_mode
)
2067 error (_("There are not enough available hardware "
2068 "resources for this watchpoint."));
2070 /* Downgrade to software watchpoint. */
2071 b
->type
= bp_watchpoint
;
2075 /* If this was a software watchpoint, we've just
2076 found we have enough resources to turn it to a
2077 hardware watchpoint. Otherwise, this is a
2082 else if (!b
->ops
->works_in_software_mode (b
))
2084 if (!can_use_hw_watchpoints
)
2085 error (_("Can't set read/access watchpoint when "
2086 "hardware watchpoints are disabled."));
2088 error (_("Expression cannot be implemented with "
2089 "read/access watchpoint."));
2092 b
->type
= bp_watchpoint
;
2094 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2095 : bp_loc_hardware_watchpoint
);
2096 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
2097 bl
->loc_type
= loc_type
;
2100 /* If a software watchpoint is not watching any memory, then the
2101 above left it without any location set up. But,
2102 bpstat_stop_status requires a location to be able to report
2103 stops, so make sure there's at least a dummy one. */
2104 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2105 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2107 else if (!within_current_scope
)
2109 printf_filtered (_("\
2110 Watchpoint %d deleted because the program has left the block\n\
2111 in which its expression is valid.\n"),
2113 watchpoint_del_at_next_stop (b
);
2116 /* Restore the selected frame. */
2118 select_frame (frame_find_by_id (saved_frame_id
));
2122 /* Returns 1 iff breakpoint location should be
2123 inserted in the inferior. We don't differentiate the type of BL's owner
2124 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2125 breakpoint_ops is not defined, because in insert_bp_location,
2126 tracepoint's insert_location will not be called. */
2128 should_be_inserted (struct bp_location
*bl
)
2130 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2133 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2136 if (!bl
->enabled
|| bl
->disabled_by_cond
2137 || bl
->shlib_disabled
|| bl
->duplicate
)
2140 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2143 /* This is set for example, when we're attached to the parent of a
2144 vfork, and have detached from the child. The child is running
2145 free, and we expect it to do an exec or exit, at which point the
2146 OS makes the parent schedulable again (and the target reports
2147 that the vfork is done). Until the child is done with the shared
2148 memory region, do not insert breakpoints in the parent, otherwise
2149 the child could still trip on the parent's breakpoints. Since
2150 the parent is blocked anyway, it won't miss any breakpoint. */
2151 if (bl
->pspace
->breakpoints_not_allowed
)
2154 /* Don't insert a breakpoint if we're trying to step past its
2155 location, except if the breakpoint is a single-step breakpoint,
2156 and the breakpoint's thread is the thread which is stepping past
2158 if ((bl
->loc_type
== bp_loc_software_breakpoint
2159 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2160 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2162 /* The single-step breakpoint may be inserted at the location
2163 we're trying to step if the instruction branches to itself.
2164 However, the instruction won't be executed at all and it may
2165 break the semantics of the instruction, for example, the
2166 instruction is a conditional branch or updates some flags.
2167 We can't fix it unless GDB is able to emulate the instruction
2168 or switch to displaced stepping. */
2169 && !(bl
->owner
->type
== bp_single_step
2170 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2172 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2173 paddress (bl
->gdbarch
, bl
->address
));
2177 /* Don't insert watchpoints if we're trying to step past the
2178 instruction that triggered one. */
2179 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2180 && stepping_past_nonsteppable_watchpoint ())
2182 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2183 "skipping watchpoint at %s:%d",
2184 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2191 /* Same as should_be_inserted but does the check assuming
2192 that the location is not duplicated. */
2195 unduplicated_should_be_inserted (struct bp_location
*bl
)
2198 const int save_duplicate
= bl
->duplicate
;
2201 result
= should_be_inserted (bl
);
2202 bl
->duplicate
= save_duplicate
;
2206 /* Parses a conditional described by an expression COND into an
2207 agent expression bytecode suitable for evaluation
2208 by the bytecode interpreter. Return NULL if there was
2209 any error during parsing. */
2211 static agent_expr_up
2212 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2217 agent_expr_up aexpr
;
2219 /* We don't want to stop processing, so catch any errors
2220 that may show up. */
2223 aexpr
= gen_eval_for_expr (scope
, cond
);
2226 catch (const gdb_exception_error
&ex
)
2228 /* If we got here, it means the condition could not be parsed to a valid
2229 bytecode expression and thus can't be evaluated on the target's side.
2230 It's no use iterating through the conditions. */
2233 /* We have a valid agent expression. */
2237 /* Based on location BL, create a list of breakpoint conditions to be
2238 passed on to the target. If we have duplicated locations with different
2239 conditions, we will add such conditions to the list. The idea is that the
2240 target will evaluate the list of conditions and will only notify GDB when
2241 one of them is true. */
2244 build_target_condition_list (struct bp_location
*bl
)
2246 struct bp_location
**locp
= NULL
, **loc2p
;
2247 int null_condition_or_parse_error
= 0;
2248 int modified
= bl
->needs_update
;
2249 struct bp_location
*loc
;
2251 /* Release conditions left over from a previous insert. */
2252 bl
->target_info
.conditions
.clear ();
2254 /* This is only meaningful if the target is
2255 evaluating conditions and if the user has
2256 opted for condition evaluation on the target's
2258 if (gdb_evaluates_breakpoint_condition_p ()
2259 || !target_supports_evaluation_of_breakpoint_conditions ())
2262 /* Do a first pass to check for locations with no assigned
2263 conditions or conditions that fail to parse to a valid agent
2264 expression bytecode. If any of these happen, then it's no use to
2265 send conditions to the target since this location will always
2266 trigger and generate a response back to GDB. Note we consider
2267 all locations at the same address irrespective of type, i.e.,
2268 even if the locations aren't considered duplicates (e.g.,
2269 software breakpoint and hardware breakpoint at the same
2271 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2274 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2278 /* Re-parse the conditions since something changed. In that
2279 case we already freed the condition bytecodes (see
2280 force_breakpoint_reinsertion). We just
2281 need to parse the condition to bytecodes again. */
2282 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2286 /* If we have a NULL bytecode expression, it means something
2287 went wrong or we have a null condition expression. */
2288 if (!loc
->cond_bytecode
)
2290 null_condition_or_parse_error
= 1;
2296 /* If any of these happened, it means we will have to evaluate the conditions
2297 for the location's address on gdb's side. It is no use keeping bytecodes
2298 for all the other duplicate locations, thus we free all of them here.
2300 This is so we have a finer control over which locations' conditions are
2301 being evaluated by GDB or the remote stub. */
2302 if (null_condition_or_parse_error
)
2304 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2307 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2309 /* Only go as far as the first NULL bytecode is
2311 if (!loc
->cond_bytecode
)
2314 loc
->cond_bytecode
.reset ();
2319 /* No NULL conditions or failed bytecode generation. Build a
2320 condition list for this location's address. If we have software
2321 and hardware locations at the same address, they aren't
2322 considered duplicates, but we still marge all the conditions
2323 anyway, as it's simpler, and doesn't really make a practical
2325 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2329 && is_breakpoint (loc
->owner
)
2330 && loc
->pspace
->num
== bl
->pspace
->num
2331 && loc
->owner
->enable_state
== bp_enabled
2333 && !loc
->disabled_by_cond
)
2335 /* Add the condition to the vector. This will be used later
2336 to send the conditions to the target. */
2337 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2344 /* Parses a command described by string CMD into an agent expression
2345 bytecode suitable for evaluation by the bytecode interpreter.
2346 Return NULL if there was any error during parsing. */
2348 static agent_expr_up
2349 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2351 const char *cmdrest
;
2352 const char *format_start
, *format_end
;
2353 struct gdbarch
*gdbarch
= get_current_arch ();
2360 if (*cmdrest
== ',')
2362 cmdrest
= skip_spaces (cmdrest
);
2364 if (*cmdrest
++ != '"')
2365 error (_("No format string following the location"));
2367 format_start
= cmdrest
;
2369 format_pieces
fpieces (&cmdrest
);
2371 format_end
= cmdrest
;
2373 if (*cmdrest
++ != '"')
2374 error (_("Bad format string, non-terminated '\"'."));
2376 cmdrest
= skip_spaces (cmdrest
);
2378 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2379 error (_("Invalid argument syntax"));
2381 if (*cmdrest
== ',')
2383 cmdrest
= skip_spaces (cmdrest
);
2385 /* For each argument, make an expression. */
2387 std::vector
<struct expression
*> argvec
;
2388 while (*cmdrest
!= '\0')
2393 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2394 argvec
.push_back (expr
.release ());
2396 if (*cmdrest
== ',')
2400 agent_expr_up aexpr
;
2402 /* We don't want to stop processing, so catch any errors
2403 that may show up. */
2406 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2407 format_start
, format_end
- format_start
,
2408 argvec
.size (), argvec
.data ());
2410 catch (const gdb_exception_error
&ex
)
2412 /* If we got here, it means the command could not be parsed to a valid
2413 bytecode expression and thus can't be evaluated on the target's side.
2414 It's no use iterating through the other commands. */
2417 /* We have a valid agent expression, return it. */
2421 /* Based on location BL, create a list of breakpoint commands to be
2422 passed on to the target. If we have duplicated locations with
2423 different commands, we will add any such to the list. */
2426 build_target_command_list (struct bp_location
*bl
)
2428 struct bp_location
**locp
= NULL
, **loc2p
;
2429 int null_command_or_parse_error
= 0;
2430 int modified
= bl
->needs_update
;
2431 struct bp_location
*loc
;
2433 /* Clear commands left over from a previous insert. */
2434 bl
->target_info
.tcommands
.clear ();
2436 if (!target_can_run_breakpoint_commands ())
2439 /* For now, limit to agent-style dprintf breakpoints. */
2440 if (dprintf_style
!= dprintf_style_agent
)
2443 /* For now, if we have any location at the same address that isn't a
2444 dprintf, don't install the target-side commands, as that would
2445 make the breakpoint not be reported to the core, and we'd lose
2447 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2450 if (is_breakpoint (loc
->owner
)
2451 && loc
->pspace
->num
== bl
->pspace
->num
2452 && loc
->owner
->type
!= bp_dprintf
)
2456 /* Do a first pass to check for locations with no assigned
2457 conditions or conditions that fail to parse to a valid agent expression
2458 bytecode. If any of these happen, then it's no use to send conditions
2459 to the target since this location will always trigger and generate a
2460 response back to GDB. */
2461 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2464 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2468 /* Re-parse the commands since something changed. In that
2469 case we already freed the command bytecodes (see
2470 force_breakpoint_reinsertion). We just
2471 need to parse the command to bytecodes again. */
2473 = parse_cmd_to_aexpr (bl
->address
,
2474 loc
->owner
->extra_string
);
2477 /* If we have a NULL bytecode expression, it means something
2478 went wrong or we have a null command expression. */
2479 if (!loc
->cmd_bytecode
)
2481 null_command_or_parse_error
= 1;
2487 /* If anything failed, then we're not doing target-side commands,
2489 if (null_command_or_parse_error
)
2491 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2494 if (is_breakpoint (loc
->owner
)
2495 && loc
->pspace
->num
== bl
->pspace
->num
)
2497 /* Only go as far as the first NULL bytecode is
2499 if (loc
->cmd_bytecode
== NULL
)
2502 loc
->cmd_bytecode
.reset ();
2507 /* No NULL commands or failed bytecode generation. Build a command
2508 list for all duplicate locations at this location's address.
2509 Note that here we must care for whether the breakpoint location
2510 types are considered duplicates, otherwise, say, if we have a
2511 software and hardware location at the same address, the target
2512 could end up running the commands twice. For the moment, we only
2513 support targets-side commands with dprintf, but it doesn't hurt
2514 to be pedantically correct in case that changes. */
2515 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2518 if (breakpoint_locations_match (bl
, loc
)
2519 && loc
->owner
->extra_string
2520 && is_breakpoint (loc
->owner
)
2521 && loc
->pspace
->num
== bl
->pspace
->num
2522 && loc
->owner
->enable_state
== bp_enabled
2524 && !loc
->disabled_by_cond
)
2526 /* Add the command to the vector. This will be used later
2527 to send the commands to the target. */
2528 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2532 bl
->target_info
.persist
= 0;
2533 /* Maybe flag this location as persistent. */
2534 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2535 bl
->target_info
.persist
= 1;
2538 /* Return the kind of breakpoint on address *ADDR. Get the kind
2539 of breakpoint according to ADDR except single-step breakpoint.
2540 Get the kind of single-step breakpoint according to the current
2544 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2546 if (bl
->owner
->type
== bp_single_step
)
2548 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2549 struct regcache
*regcache
;
2551 regcache
= get_thread_regcache (thr
);
2553 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2557 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2560 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2561 location. Any error messages are printed to TMP_ERROR_STREAM; and
2562 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2563 Returns 0 for success, 1 if the bp_location type is not supported or
2566 NOTE drow/2003-09-09: This routine could be broken down to an
2567 object-style method for each breakpoint or catchpoint type. */
2569 insert_bp_location (struct bp_location
*bl
,
2570 struct ui_file
*tmp_error_stream
,
2571 int *disabled_breaks
,
2572 int *hw_breakpoint_error
,
2573 int *hw_bp_error_explained_already
)
2575 gdb_exception bp_excpt
;
2577 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2580 /* Note we don't initialize bl->target_info, as that wipes out
2581 the breakpoint location's shadow_contents if the breakpoint
2582 is still inserted at that location. This in turn breaks
2583 target_read_memory which depends on these buffers when
2584 a memory read is requested at the breakpoint location:
2585 Once the target_info has been wiped, we fail to see that
2586 we have a breakpoint inserted at that address and thus
2587 read the breakpoint instead of returning the data saved in
2588 the breakpoint location's shadow contents. */
2589 bl
->target_info
.reqstd_address
= bl
->address
;
2590 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2591 bl
->target_info
.length
= bl
->length
;
2593 /* When working with target-side conditions, we must pass all the conditions
2594 for the same breakpoint address down to the target since GDB will not
2595 insert those locations. With a list of breakpoint conditions, the target
2596 can decide when to stop and notify GDB. */
2598 if (is_breakpoint (bl
->owner
))
2600 build_target_condition_list (bl
);
2601 build_target_command_list (bl
);
2602 /* Reset the modification marker. */
2603 bl
->needs_update
= 0;
2606 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2607 set at a read-only address, then a breakpoint location will have
2608 been changed to hardware breakpoint before we get here. If it is
2609 "off" however, error out before actually trying to insert the
2610 breakpoint, with a nicer error message. */
2611 if (bl
->loc_type
== bp_loc_software_breakpoint
2612 && !automatic_hardware_breakpoints
)
2614 mem_region
*mr
= lookup_mem_region (bl
->address
);
2616 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2618 fprintf_unfiltered (tmp_error_stream
,
2619 _("Cannot insert breakpoint %d.\n"
2620 "Cannot set software breakpoint "
2621 "at read-only address %s\n"),
2623 paddress (bl
->gdbarch
, bl
->address
));
2628 if (bl
->loc_type
== bp_loc_software_breakpoint
2629 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2631 /* First check to see if we have to handle an overlay. */
2632 if (overlay_debugging
== ovly_off
2633 || bl
->section
== NULL
2634 || !(section_is_overlay (bl
->section
)))
2636 /* No overlay handling: just set the breakpoint. */
2641 val
= bl
->owner
->ops
->insert_location (bl
);
2643 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2645 catch (gdb_exception
&e
)
2647 bp_excpt
= std::move (e
);
2652 /* This breakpoint is in an overlay section.
2653 Shall we set a breakpoint at the LMA? */
2654 if (!overlay_events_enabled
)
2656 /* Yes -- overlay event support is not active,
2657 so we must try to set a breakpoint at the LMA.
2658 This will not work for a hardware breakpoint. */
2659 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2660 warning (_("hardware breakpoint %d not supported in overlay!"),
2664 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2666 /* Set a software (trap) breakpoint at the LMA. */
2667 bl
->overlay_target_info
= bl
->target_info
;
2668 bl
->overlay_target_info
.reqstd_address
= addr
;
2670 /* No overlay handling: just set the breakpoint. */
2675 bl
->overlay_target_info
.kind
2676 = breakpoint_kind (bl
, &addr
);
2677 bl
->overlay_target_info
.placed_address
= addr
;
2678 val
= target_insert_breakpoint (bl
->gdbarch
,
2679 &bl
->overlay_target_info
);
2682 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2684 catch (gdb_exception
&e
)
2686 bp_excpt
= std::move (e
);
2689 if (bp_excpt
.reason
!= 0)
2690 fprintf_unfiltered (tmp_error_stream
,
2691 "Overlay breakpoint %d "
2692 "failed: in ROM?\n",
2696 /* Shall we set a breakpoint at the VMA? */
2697 if (section_is_mapped (bl
->section
))
2699 /* Yes. This overlay section is mapped into memory. */
2704 val
= bl
->owner
->ops
->insert_location (bl
);
2706 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2708 catch (gdb_exception
&e
)
2710 bp_excpt
= std::move (e
);
2715 /* No. This breakpoint will not be inserted.
2716 No error, but do not mark the bp as 'inserted'. */
2721 if (bp_excpt
.reason
!= 0)
2723 /* Can't set the breakpoint. */
2725 /* In some cases, we might not be able to insert a
2726 breakpoint in a shared library that has already been
2727 removed, but we have not yet processed the shlib unload
2728 event. Unfortunately, some targets that implement
2729 breakpoint insertion themselves can't tell why the
2730 breakpoint insertion failed (e.g., the remote target
2731 doesn't define error codes), so we must treat generic
2732 errors as memory errors. */
2733 if (bp_excpt
.reason
== RETURN_ERROR
2734 && (bp_excpt
.error
== GENERIC_ERROR
2735 || bp_excpt
.error
== MEMORY_ERROR
)
2736 && bl
->loc_type
== bp_loc_software_breakpoint
2737 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2738 || shared_objfile_contains_address_p (bl
->pspace
,
2741 /* See also: disable_breakpoints_in_shlibs. */
2742 bl
->shlib_disabled
= 1;
2743 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2744 if (!*disabled_breaks
)
2746 fprintf_unfiltered (tmp_error_stream
,
2747 "Cannot insert breakpoint %d.\n",
2749 fprintf_unfiltered (tmp_error_stream
,
2750 "Temporarily disabling shared "
2751 "library breakpoints:\n");
2753 *disabled_breaks
= 1;
2754 fprintf_unfiltered (tmp_error_stream
,
2755 "breakpoint #%d\n", bl
->owner
->number
);
2760 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2762 *hw_breakpoint_error
= 1;
2763 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2764 fprintf_unfiltered (tmp_error_stream
,
2765 "Cannot insert hardware breakpoint %d%s",
2767 bp_excpt
.message
? ":" : ".\n");
2768 if (bp_excpt
.message
!= NULL
)
2769 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2774 if (bp_excpt
.message
== NULL
)
2777 = memory_error_message (TARGET_XFER_E_IO
,
2778 bl
->gdbarch
, bl
->address
);
2780 fprintf_unfiltered (tmp_error_stream
,
2781 "Cannot insert breakpoint %d.\n"
2783 bl
->owner
->number
, message
.c_str ());
2787 fprintf_unfiltered (tmp_error_stream
,
2788 "Cannot insert breakpoint %d: %s\n",
2803 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2804 /* NOTE drow/2003-09-08: This state only exists for removing
2805 watchpoints. It's not clear that it's necessary... */
2806 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2810 gdb_assert (bl
->owner
->ops
!= NULL
2811 && bl
->owner
->ops
->insert_location
!= NULL
);
2813 val
= bl
->owner
->ops
->insert_location (bl
);
2815 /* If trying to set a read-watchpoint, and it turns out it's not
2816 supported, try emulating one with an access watchpoint. */
2817 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2819 struct bp_location
*loc
, **loc_temp
;
2821 /* But don't try to insert it, if there's already another
2822 hw_access location that would be considered a duplicate
2824 ALL_BP_LOCATIONS (loc
, loc_temp
)
2826 && loc
->watchpoint_type
== hw_access
2827 && watchpoint_locations_match (bl
, loc
))
2831 bl
->target_info
= loc
->target_info
;
2832 bl
->watchpoint_type
= hw_access
;
2839 bl
->watchpoint_type
= hw_access
;
2840 val
= bl
->owner
->ops
->insert_location (bl
);
2843 /* Back to the original value. */
2844 bl
->watchpoint_type
= hw_read
;
2848 bl
->inserted
= (val
== 0);
2851 else if (bl
->owner
->type
== bp_catchpoint
)
2855 gdb_assert (bl
->owner
->ops
!= NULL
2856 && bl
->owner
->ops
->insert_location
!= NULL
);
2858 val
= bl
->owner
->ops
->insert_location (bl
);
2861 bl
->owner
->enable_state
= bp_disabled
;
2865 Error inserting catchpoint %d: Your system does not support this type\n\
2866 of catchpoint."), bl
->owner
->number
);
2868 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2871 bl
->inserted
= (val
== 0);
2873 /* We've already printed an error message if there was a problem
2874 inserting this catchpoint, and we've disabled the catchpoint,
2875 so just return success. */
2882 /* This function is called when program space PSPACE is about to be
2883 deleted. It takes care of updating breakpoints to not reference
2887 breakpoint_program_space_exit (struct program_space
*pspace
)
2889 struct breakpoint
*b
, *b_temp
;
2890 struct bp_location
*loc
, **loc_temp
;
2892 /* Remove any breakpoint that was set through this program space. */
2893 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2895 if (b
->pspace
== pspace
)
2896 delete_breakpoint (b
);
2899 /* Breakpoints set through other program spaces could have locations
2900 bound to PSPACE as well. Remove those. */
2901 ALL_BP_LOCATIONS (loc
, loc_temp
)
2903 struct bp_location
*tmp
;
2905 if (loc
->pspace
== pspace
)
2907 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2908 if (loc
->owner
->loc
== loc
)
2909 loc
->owner
->loc
= loc
->next
;
2911 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2912 if (tmp
->next
== loc
)
2914 tmp
->next
= loc
->next
;
2920 /* Now update the global location list to permanently delete the
2921 removed locations above. */
2922 update_global_location_list (UGLL_DONT_INSERT
);
2925 /* Make sure all breakpoints are inserted in inferior.
2926 Throws exception on any error.
2927 A breakpoint that is already inserted won't be inserted
2928 again, so calling this function twice is safe. */
2930 insert_breakpoints (void)
2932 struct breakpoint
*bpt
;
2934 ALL_BREAKPOINTS (bpt
)
2935 if (is_hardware_watchpoint (bpt
))
2937 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2939 update_watchpoint (w
, 0 /* don't reparse. */);
2942 /* Updating watchpoints creates new locations, so update the global
2943 location list. Explicitly tell ugll to insert locations and
2944 ignore breakpoints_always_inserted_mode. Also,
2945 update_global_location_list tries to "upgrade" software
2946 breakpoints to hardware breakpoints to handle "set breakpoint
2947 auto-hw", so we need to call it even if we don't have new
2949 update_global_location_list (UGLL_INSERT
);
2952 /* Invoke CALLBACK for each of bp_location. */
2955 iterate_over_bp_locations (gdb::function_view
<void (bp_location
*)> callback
)
2957 struct bp_location
*loc
, **loc_tmp
;
2959 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2965 /* This is used when we need to synch breakpoint conditions between GDB and the
2966 target. It is the case with deleting and disabling of breakpoints when using
2967 always-inserted mode. */
2970 update_inserted_breakpoint_locations (void)
2972 struct bp_location
*bl
, **blp_tmp
;
2975 int disabled_breaks
= 0;
2976 int hw_breakpoint_error
= 0;
2977 int hw_bp_details_reported
= 0;
2979 string_file tmp_error_stream
;
2981 /* Explicitly mark the warning -- this will only be printed if
2982 there was an error. */
2983 tmp_error_stream
.puts ("Warning:\n");
2985 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2987 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2989 /* We only want to update software breakpoints and hardware
2991 if (!is_breakpoint (bl
->owner
))
2994 /* We only want to update locations that are already inserted
2995 and need updating. This is to avoid unwanted insertion during
2996 deletion of breakpoints. */
2997 if (!bl
->inserted
|| !bl
->needs_update
)
3000 switch_to_program_space_and_thread (bl
->pspace
);
3002 /* For targets that support global breakpoints, there's no need
3003 to select an inferior to insert breakpoint to. In fact, even
3004 if we aren't attached to any process yet, we should still
3005 insert breakpoints. */
3006 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3007 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3010 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3011 &hw_breakpoint_error
, &hw_bp_details_reported
);
3018 target_terminal::ours_for_output ();
3019 error_stream (tmp_error_stream
);
3023 /* Used when starting or continuing the program. */
3026 insert_breakpoint_locations (void)
3028 struct breakpoint
*bpt
;
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 ALL_BREAKPOINTS (bpt
)
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 struct breakpoint
*bpt
;
4285 ALL_BREAKPOINTS (bpt
)
4287 struct bp_location
*loc
;
4289 if (bpt
->type
!= bp_hardware_watchpoint
4290 && bpt
->type
!= bp_access_watchpoint
)
4293 if (!breakpoint_enabled (bpt
))
4296 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4297 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4301 /* Check for intersection. */
4302 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4303 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4311 /* See breakpoint.h. */
4314 is_catchpoint (struct breakpoint
*b
)
4316 return (b
->type
== bp_catchpoint
);
4319 /* Clear a bpstat so that it says we are not at any breakpoint.
4320 Also free any storage that is part of a bpstat. */
4323 bpstat_clear (bpstat
*bsp
)
4340 bpstats::bpstats (const bpstats
&other
)
4342 bp_location_at (other
.bp_location_at
),
4343 breakpoint_at (other
.breakpoint_at
),
4344 commands (other
.commands
),
4345 print (other
.print
),
4347 print_it (other
.print_it
)
4349 if (other
.old_val
!= NULL
)
4350 old_val
= release_value (value_copy (other
.old_val
.get ()));
4353 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4354 is part of the bpstat is copied as well. */
4357 bpstat_copy (bpstat bs
)
4361 bpstat retval
= NULL
;
4366 for (; bs
!= NULL
; bs
= bs
->next
)
4368 tmp
= new bpstats (*bs
);
4371 /* This is the first thing in the chain. */
4381 /* Find the bpstat associated with this breakpoint. */
4384 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4389 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4391 if (bsp
->breakpoint_at
== breakpoint
)
4397 /* See breakpoint.h. */
4400 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4402 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4404 if (bsp
->breakpoint_at
== NULL
)
4406 /* A moribund location can never explain a signal other than
4408 if (sig
== GDB_SIGNAL_TRAP
)
4413 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4422 /* Put in *NUM the breakpoint number of the first breakpoint we are
4423 stopped at. *BSP upon return is a bpstat which points to the
4424 remaining breakpoints stopped at (but which is not guaranteed to be
4425 good for anything but further calls to bpstat_num).
4427 Return 0 if passed a bpstat which does not indicate any breakpoints.
4428 Return -1 if stopped at a breakpoint that has been deleted since
4430 Return 1 otherwise. */
4433 bpstat_num (bpstat
*bsp
, int *num
)
4435 struct breakpoint
*b
;
4438 return 0; /* No more breakpoint values */
4440 /* We assume we'll never have several bpstats that correspond to a
4441 single breakpoint -- otherwise, this function might return the
4442 same number more than once and this will look ugly. */
4443 b
= (*bsp
)->breakpoint_at
;
4444 *bsp
= (*bsp
)->next
;
4446 return -1; /* breakpoint that's been deleted since */
4448 *num
= b
->number
; /* We have its number */
4452 /* See breakpoint.h. */
4455 bpstat_clear_actions (void)
4459 if (inferior_ptid
== null_ptid
)
4462 thread_info
*tp
= inferior_thread ();
4463 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4465 bs
->commands
= NULL
;
4466 bs
->old_val
.reset (nullptr);
4470 /* Called when a command is about to proceed the inferior. */
4473 breakpoint_about_to_proceed (void)
4475 if (inferior_ptid
!= null_ptid
)
4477 struct thread_info
*tp
= inferior_thread ();
4479 /* Allow inferior function calls in breakpoint commands to not
4480 interrupt the command list. When the call finishes
4481 successfully, the inferior will be standing at the same
4482 breakpoint as if nothing happened. */
4483 if (tp
->control
.in_infcall
)
4487 breakpoint_proceeded
= 1;
4490 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4491 or its equivalent. */
4494 command_line_is_silent (struct command_line
*cmd
)
4496 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4499 /* Execute all the commands associated with all the breakpoints at
4500 this location. Any of these commands could cause the process to
4501 proceed beyond this point, etc. We look out for such changes by
4502 checking the global "breakpoint_proceeded" after each command.
4504 Returns true if a breakpoint command resumed the inferior. In that
4505 case, it is the caller's responsibility to recall it again with the
4506 bpstat of the current thread. */
4509 bpstat_do_actions_1 (bpstat
*bsp
)
4514 /* Avoid endless recursion if a `source' command is contained
4516 if (executing_breakpoint_commands
)
4519 scoped_restore save_executing
4520 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4522 scoped_restore preventer
= prevent_dont_repeat ();
4524 /* This pointer will iterate over the list of bpstat's. */
4527 breakpoint_proceeded
= 0;
4528 for (; bs
!= NULL
; bs
= bs
->next
)
4530 struct command_line
*cmd
= NULL
;
4532 /* Take ownership of the BSP's command tree, if it has one.
4534 The command tree could legitimately contain commands like
4535 'step' and 'next', which call clear_proceed_status, which
4536 frees stop_bpstat's command tree. To make sure this doesn't
4537 free the tree we're executing out from under us, we need to
4538 take ownership of the tree ourselves. Since a given bpstat's
4539 commands are only executed once, we don't need to copy it; we
4540 can clear the pointer in the bpstat, and make sure we free
4541 the tree when we're done. */
4542 counted_command_line ccmd
= bs
->commands
;
4543 bs
->commands
= NULL
;
4546 if (command_line_is_silent (cmd
))
4548 /* The action has been already done by bpstat_stop_status. */
4554 execute_control_command (cmd
);
4556 if (breakpoint_proceeded
)
4562 if (breakpoint_proceeded
)
4564 if (current_ui
->async
)
4565 /* If we are in async mode, then the target might be still
4566 running, not stopped at any breakpoint, so nothing for
4567 us to do here -- just return to the event loop. */
4570 /* In sync mode, when execute_control_command returns
4571 we're already standing on the next breakpoint.
4572 Breakpoint commands for that stop were not run, since
4573 execute_command does not run breakpoint commands --
4574 only command_line_handler does, but that one is not
4575 involved in execution of breakpoint commands. So, we
4576 can now execute breakpoint commands. It should be
4577 noted that making execute_command do bpstat actions is
4578 not an option -- in this case we'll have recursive
4579 invocation of bpstat for each breakpoint with a
4580 command, and can easily blow up GDB stack. Instead, we
4581 return true, which will trigger the caller to recall us
4582 with the new stop_bpstat. */
4590 /* Helper for bpstat_do_actions. Get the current thread, if there's
4591 one, is alive and has execution. Return NULL otherwise. */
4593 static thread_info
*
4594 get_bpstat_thread ()
4596 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4599 thread_info
*tp
= inferior_thread ();
4600 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4606 bpstat_do_actions (void)
4608 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4611 /* Do any commands attached to breakpoint we are stopped at. */
4612 while ((tp
= get_bpstat_thread ()) != NULL
)
4614 /* Since in sync mode, bpstat_do_actions may resume the
4615 inferior, and only return when it is stopped at the next
4616 breakpoint, we keep doing breakpoint actions until it returns
4617 false to indicate the inferior was not resumed. */
4618 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4622 cleanup_if_error
.release ();
4625 /* Print out the (old or new) value associated with a watchpoint. */
4628 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4631 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4634 struct value_print_options opts
;
4635 get_user_print_options (&opts
);
4636 value_print (val
, stream
, &opts
);
4640 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4641 debugging multiple threads. */
4644 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4646 if (uiout
->is_mi_like_p ())
4651 if (show_thread_that_caused_stop ())
4654 struct thread_info
*thr
= inferior_thread ();
4656 uiout
->text ("Thread ");
4657 uiout
->field_string ("thread-id", print_thread_id (thr
));
4659 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4662 uiout
->text (" \"");
4663 uiout
->field_string ("name", name
);
4667 uiout
->text (" hit ");
4671 /* Generic routine for printing messages indicating why we
4672 stopped. The behavior of this function depends on the value
4673 'print_it' in the bpstat structure. Under some circumstances we
4674 may decide not to print anything here and delegate the task to
4677 static enum print_stop_action
4678 print_bp_stop_message (bpstat bs
)
4680 switch (bs
->print_it
)
4683 /* Nothing should be printed for this bpstat entry. */
4684 return PRINT_UNKNOWN
;
4688 /* We still want to print the frame, but we already printed the
4689 relevant messages. */
4690 return PRINT_SRC_AND_LOC
;
4693 case print_it_normal
:
4695 struct breakpoint
*b
= bs
->breakpoint_at
;
4697 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4698 which has since been deleted. */
4700 return PRINT_UNKNOWN
;
4702 /* Normal case. Call the breakpoint's print_it method. */
4703 return b
->ops
->print_it (bs
);
4708 internal_error (__FILE__
, __LINE__
,
4709 _("print_bp_stop_message: unrecognized enum value"));
4714 /* A helper function that prints a shared library stopped event. */
4717 print_solib_event (int is_catchpoint
)
4719 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4720 bool any_added
= !current_program_space
->added_solibs
.empty ();
4724 if (any_added
|| any_deleted
)
4725 current_uiout
->text (_("Stopped due to shared library event:\n"));
4727 current_uiout
->text (_("Stopped due to shared library event (no "
4728 "libraries added or removed)\n"));
4731 if (current_uiout
->is_mi_like_p ())
4732 current_uiout
->field_string ("reason",
4733 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4737 current_uiout
->text (_(" Inferior unloaded "));
4738 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4739 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4741 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4744 current_uiout
->text (" ");
4745 current_uiout
->field_string ("library", name
);
4746 current_uiout
->text ("\n");
4752 current_uiout
->text (_(" Inferior loaded "));
4753 ui_out_emit_list
list_emitter (current_uiout
, "added");
4755 for (so_list
*iter
: current_program_space
->added_solibs
)
4758 current_uiout
->text (" ");
4760 current_uiout
->field_string ("library", iter
->so_name
);
4761 current_uiout
->text ("\n");
4766 /* Print a message indicating what happened. This is called from
4767 normal_stop(). The input to this routine is the head of the bpstat
4768 list - a list of the eventpoints that caused this stop. KIND is
4769 the target_waitkind for the stopping event. This
4770 routine calls the generic print routine for printing a message
4771 about reasons for stopping. This will print (for example) the
4772 "Breakpoint n," part of the output. The return value of this
4775 PRINT_UNKNOWN: Means we printed nothing.
4776 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4777 code to print the location. An example is
4778 "Breakpoint 1, " which should be followed by
4780 PRINT_SRC_ONLY: Means we printed something, but there is no need
4781 to also print the location part of the message.
4782 An example is the catch/throw messages, which
4783 don't require a location appended to the end.
4784 PRINT_NOTHING: We have done some printing and we don't need any
4785 further info to be printed. */
4787 enum print_stop_action
4788 bpstat_print (bpstat bs
, int kind
)
4790 enum print_stop_action val
;
4792 /* Maybe another breakpoint in the chain caused us to stop.
4793 (Currently all watchpoints go on the bpstat whether hit or not.
4794 That probably could (should) be changed, provided care is taken
4795 with respect to bpstat_explains_signal). */
4796 for (; bs
; bs
= bs
->next
)
4798 val
= print_bp_stop_message (bs
);
4799 if (val
== PRINT_SRC_ONLY
4800 || val
== PRINT_SRC_AND_LOC
4801 || val
== PRINT_NOTHING
)
4805 /* If we had hit a shared library event breakpoint,
4806 print_bp_stop_message would print out this message. If we hit an
4807 OS-level shared library event, do the same thing. */
4808 if (kind
== TARGET_WAITKIND_LOADED
)
4810 print_solib_event (0);
4811 return PRINT_NOTHING
;
4814 /* We reached the end of the chain, or we got a null BS to start
4815 with and nothing was printed. */
4816 return PRINT_UNKNOWN
;
4819 /* Evaluate the boolean expression EXP and return the result. */
4822 breakpoint_cond_eval (expression
*exp
)
4824 struct value
*mark
= value_mark ();
4825 bool res
= value_true (evaluate_expression (exp
));
4827 value_free_to_mark (mark
);
4831 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4833 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4835 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4836 breakpoint_at (bl
->owner
),
4840 print_it (print_it_normal
)
4842 **bs_link_pointer
= this;
4843 *bs_link_pointer
= &next
;
4848 breakpoint_at (NULL
),
4852 print_it (print_it_normal
)
4856 /* The target has stopped with waitstatus WS. Check if any hardware
4857 watchpoints have triggered, according to the target. */
4860 watchpoints_triggered (struct target_waitstatus
*ws
)
4862 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4864 struct breakpoint
*b
;
4866 if (!stopped_by_watchpoint
)
4868 /* We were not stopped by a watchpoint. Mark all watchpoints
4869 as not triggered. */
4871 if (is_hardware_watchpoint (b
))
4873 struct watchpoint
*w
= (struct watchpoint
*) b
;
4875 w
->watchpoint_triggered
= watch_triggered_no
;
4881 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4883 /* We were stopped by a watchpoint, but we don't know where.
4884 Mark all watchpoints as unknown. */
4886 if (is_hardware_watchpoint (b
))
4888 struct watchpoint
*w
= (struct watchpoint
*) b
;
4890 w
->watchpoint_triggered
= watch_triggered_unknown
;
4896 /* The target could report the data address. Mark watchpoints
4897 affected by this data address as triggered, and all others as not
4901 if (is_hardware_watchpoint (b
))
4903 struct watchpoint
*w
= (struct watchpoint
*) b
;
4904 struct bp_location
*loc
;
4906 w
->watchpoint_triggered
= watch_triggered_no
;
4907 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4909 if (is_masked_watchpoint (b
))
4911 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4912 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4914 if (newaddr
== start
)
4916 w
->watchpoint_triggered
= watch_triggered_yes
;
4920 /* Exact match not required. Within range is sufficient. */
4921 else if (target_watchpoint_addr_within_range
4922 (current_inferior ()->top_target (), addr
, loc
->address
,
4925 w
->watchpoint_triggered
= watch_triggered_yes
;
4934 /* Possible return values for watchpoint_check. */
4935 enum wp_check_result
4937 /* The watchpoint has been deleted. */
4940 /* The value has changed. */
4941 WP_VALUE_CHANGED
= 2,
4943 /* The value has not changed. */
4944 WP_VALUE_NOT_CHANGED
= 3,
4946 /* Ignore this watchpoint, no matter if the value changed or not. */
4950 #define BP_TEMPFLAG 1
4951 #define BP_HARDWAREFLAG 2
4953 /* Evaluate watchpoint condition expression and check if its value
4956 static wp_check_result
4957 watchpoint_check (bpstat bs
)
4959 struct watchpoint
*b
;
4960 struct frame_info
*fr
;
4961 int within_current_scope
;
4963 /* BS is built from an existing struct breakpoint. */
4964 gdb_assert (bs
->breakpoint_at
!= NULL
);
4965 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4967 /* If this is a local watchpoint, we only want to check if the
4968 watchpoint frame is in scope if the current thread is the thread
4969 that was used to create the watchpoint. */
4970 if (!watchpoint_in_thread_scope (b
))
4973 if (b
->exp_valid_block
== NULL
)
4974 within_current_scope
= 1;
4977 struct frame_info
*frame
= get_current_frame ();
4978 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4979 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4981 /* stack_frame_destroyed_p() returns a non-zero value if we're
4982 still in the function but the stack frame has already been
4983 invalidated. Since we can't rely on the values of local
4984 variables after the stack has been destroyed, we are treating
4985 the watchpoint in that state as `not changed' without further
4986 checking. Don't mark watchpoints as changed if the current
4987 frame is in an epilogue - even if they are in some other
4988 frame, our view of the stack is likely to be wrong and
4989 frame_find_by_id could error out. */
4990 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4993 fr
= frame_find_by_id (b
->watchpoint_frame
);
4994 within_current_scope
= (fr
!= NULL
);
4996 /* If we've gotten confused in the unwinder, we might have
4997 returned a frame that can't describe this variable. */
4998 if (within_current_scope
)
5000 struct symbol
*function
;
5002 function
= get_frame_function (fr
);
5003 if (function
== NULL
5004 || !contained_in (b
->exp_valid_block
,
5005 SYMBOL_BLOCK_VALUE (function
)))
5006 within_current_scope
= 0;
5009 if (within_current_scope
)
5010 /* If we end up stopping, the current frame will get selected
5011 in normal_stop. So this call to select_frame won't affect
5016 if (within_current_scope
)
5018 /* We use value_{,free_to_}mark because it could be a *long*
5019 time before we return to the command level and call
5020 free_all_values. We can't call free_all_values because we
5021 might be in the middle of evaluating a function call. */
5024 struct value
*new_val
;
5026 if (is_masked_watchpoint (b
))
5027 /* Since we don't know the exact trigger address (from
5028 stopped_data_address), just tell the user we've triggered
5029 a mask watchpoint. */
5030 return WP_VALUE_CHANGED
;
5032 mark
= value_mark ();
5033 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5036 if (b
->val_bitsize
!= 0)
5037 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5039 /* We use value_equal_contents instead of value_equal because
5040 the latter coerces an array to a pointer, thus comparing just
5041 the address of the array instead of its contents. This is
5042 not what we want. */
5043 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5044 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5047 bs
->old_val
= b
->val
;
5048 b
->val
= release_value (new_val
);
5049 b
->val_valid
= true;
5050 if (new_val
!= NULL
)
5051 value_free_to_mark (mark
);
5052 return WP_VALUE_CHANGED
;
5056 /* Nothing changed. */
5057 value_free_to_mark (mark
);
5058 return WP_VALUE_NOT_CHANGED
;
5063 /* This seems like the only logical thing to do because
5064 if we temporarily ignored the watchpoint, then when
5065 we reenter the block in which it is valid it contains
5066 garbage (in the case of a function, it may have two
5067 garbage values, one before and one after the prologue).
5068 So we can't even detect the first assignment to it and
5069 watch after that (since the garbage may or may not equal
5070 the first value assigned). */
5071 /* We print all the stop information in
5072 breakpoint_ops->print_it, but in this case, by the time we
5073 call breakpoint_ops->print_it this bp will be deleted
5074 already. So we have no choice but print the information
5077 SWITCH_THRU_ALL_UIS ()
5079 struct ui_out
*uiout
= current_uiout
;
5081 if (uiout
->is_mi_like_p ())
5083 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5084 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5085 "left the block in\n"
5086 "which its expression is valid.\n",
5087 signed_field ("wpnum", b
->number
));
5090 /* Make sure the watchpoint's commands aren't executed. */
5092 watchpoint_del_at_next_stop (b
);
5098 /* Return true if it looks like target has stopped due to hitting
5099 breakpoint location BL. This function does not check if we should
5100 stop, only if BL explains the stop. */
5103 bpstat_check_location (const struct bp_location
*bl
,
5104 const address_space
*aspace
, CORE_ADDR bp_addr
,
5105 const struct target_waitstatus
*ws
)
5107 struct breakpoint
*b
= bl
->owner
;
5109 /* BL is from an existing breakpoint. */
5110 gdb_assert (b
!= NULL
);
5112 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5115 /* Determine if the watched values have actually changed, and we
5116 should stop. If not, set BS->stop to 0. */
5119 bpstat_check_watchpoint (bpstat bs
)
5121 const struct bp_location
*bl
;
5122 struct watchpoint
*b
;
5124 /* BS is built for existing struct breakpoint. */
5125 bl
= bs
->bp_location_at
.get ();
5126 gdb_assert (bl
!= NULL
);
5127 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5128 gdb_assert (b
!= NULL
);
5131 int must_check_value
= 0;
5133 if (b
->type
== bp_watchpoint
)
5134 /* For a software watchpoint, we must always check the
5136 must_check_value
= 1;
5137 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5138 /* We have a hardware watchpoint (read, write, or access)
5139 and the target earlier reported an address watched by
5141 must_check_value
= 1;
5142 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5143 && b
->type
== bp_hardware_watchpoint
)
5144 /* We were stopped by a hardware watchpoint, but the target could
5145 not report the data address. We must check the watchpoint's
5146 value. Access and read watchpoints are out of luck; without
5147 a data address, we can't figure it out. */
5148 must_check_value
= 1;
5150 if (must_check_value
)
5156 e
= watchpoint_check (bs
);
5158 catch (const gdb_exception
&ex
)
5160 exception_fprintf (gdb_stderr
, ex
,
5161 "Error evaluating expression "
5162 "for watchpoint %d\n",
5165 SWITCH_THRU_ALL_UIS ()
5167 printf_filtered (_("Watchpoint %d deleted.\n"),
5170 watchpoint_del_at_next_stop (b
);
5177 /* We've already printed what needs to be printed. */
5178 bs
->print_it
= print_it_done
;
5182 bs
->print_it
= print_it_noop
;
5185 case WP_VALUE_CHANGED
:
5186 if (b
->type
== bp_read_watchpoint
)
5188 /* There are two cases to consider here:
5190 1. We're watching the triggered memory for reads.
5191 In that case, trust the target, and always report
5192 the watchpoint hit to the user. Even though
5193 reads don't cause value changes, the value may
5194 have changed since the last time it was read, and
5195 since we're not trapping writes, we will not see
5196 those, and as such we should ignore our notion of
5199 2. We're watching the triggered memory for both
5200 reads and writes. There are two ways this may
5203 2.1. This is a target that can't break on data
5204 reads only, but can break on accesses (reads or
5205 writes), such as e.g., x86. We detect this case
5206 at the time we try to insert read watchpoints.
5208 2.2. Otherwise, the target supports read
5209 watchpoints, but, the user set an access or write
5210 watchpoint watching the same memory as this read
5213 If we're watching memory writes as well as reads,
5214 ignore watchpoint hits when we find that the
5215 value hasn't changed, as reads don't cause
5216 changes. This still gives false positives when
5217 the program writes the same value to memory as
5218 what there was already in memory (we will confuse
5219 it for a read), but it's much better than
5222 int other_write_watchpoint
= 0;
5224 if (bl
->watchpoint_type
== hw_read
)
5226 struct breakpoint
*other_b
;
5228 ALL_BREAKPOINTS (other_b
)
5229 if (other_b
->type
== bp_hardware_watchpoint
5230 || other_b
->type
== bp_access_watchpoint
)
5232 struct watchpoint
*other_w
=
5233 (struct watchpoint
*) other_b
;
5235 if (other_w
->watchpoint_triggered
5236 == watch_triggered_yes
)
5238 other_write_watchpoint
= 1;
5244 if (other_write_watchpoint
5245 || bl
->watchpoint_type
== hw_access
)
5247 /* We're watching the same memory for writes,
5248 and the value changed since the last time we
5249 updated it, so this trap must be for a write.
5251 bs
->print_it
= print_it_noop
;
5256 case WP_VALUE_NOT_CHANGED
:
5257 if (b
->type
== bp_hardware_watchpoint
5258 || b
->type
== bp_watchpoint
)
5260 /* Don't stop: write watchpoints shouldn't fire if
5261 the value hasn't changed. */
5262 bs
->print_it
= print_it_noop
;
5272 else /* must_check_value == 0 */
5274 /* This is a case where some watchpoint(s) triggered, but
5275 not at the address of this watchpoint, or else no
5276 watchpoint triggered after all. So don't print
5277 anything for this watchpoint. */
5278 bs
->print_it
= print_it_noop
;
5284 /* For breakpoints that are currently marked as telling gdb to stop,
5285 check conditions (condition proper, frame, thread and ignore count)
5286 of breakpoint referred to by BS. If we should not stop for this
5287 breakpoint, set BS->stop to 0. */
5290 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5292 const struct bp_location
*bl
;
5293 struct breakpoint
*b
;
5295 bool condition_result
= true;
5296 struct expression
*cond
;
5298 gdb_assert (bs
->stop
);
5300 /* BS is built for existing struct breakpoint. */
5301 bl
= bs
->bp_location_at
.get ();
5302 gdb_assert (bl
!= NULL
);
5303 b
= bs
->breakpoint_at
;
5304 gdb_assert (b
!= NULL
);
5306 /* Even if the target evaluated the condition on its end and notified GDB, we
5307 need to do so again since GDB does not know if we stopped due to a
5308 breakpoint or a single step breakpoint. */
5310 if (frame_id_p (b
->frame_id
)
5311 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5317 /* If this is a thread/task-specific breakpoint, don't waste cpu
5318 evaluating the condition if this isn't the specified
5320 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5321 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5327 /* Evaluate extension language breakpoints that have a "stop" method
5329 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5331 if (is_watchpoint (b
))
5333 struct watchpoint
*w
= (struct watchpoint
*) b
;
5335 cond
= w
->cond_exp
.get ();
5338 cond
= bl
->cond
.get ();
5340 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5342 int within_current_scope
= 1;
5343 struct watchpoint
* w
;
5345 /* We use value_mark and value_free_to_mark because it could
5346 be a long time before we return to the command level and
5347 call free_all_values. We can't call free_all_values
5348 because we might be in the middle of evaluating a
5350 struct value
*mark
= value_mark ();
5352 if (is_watchpoint (b
))
5353 w
= (struct watchpoint
*) b
;
5357 /* Need to select the frame, with all that implies so that
5358 the conditions will have the right context. Because we
5359 use the frame, we will not see an inlined function's
5360 variables when we arrive at a breakpoint at the start
5361 of the inlined function; the current frame will be the
5363 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5364 select_frame (get_current_frame ());
5367 struct frame_info
*frame
;
5369 /* For local watchpoint expressions, which particular
5370 instance of a local is being watched matters, so we
5371 keep track of the frame to evaluate the expression
5372 in. To evaluate the condition however, it doesn't
5373 really matter which instantiation of the function
5374 where the condition makes sense triggers the
5375 watchpoint. This allows an expression like "watch
5376 global if q > 10" set in `func', catch writes to
5377 global on all threads that call `func', or catch
5378 writes on all recursive calls of `func' by a single
5379 thread. We simply always evaluate the condition in
5380 the innermost frame that's executing where it makes
5381 sense to evaluate the condition. It seems
5383 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5385 select_frame (frame
);
5387 within_current_scope
= 0;
5389 if (within_current_scope
)
5393 condition_result
= breakpoint_cond_eval (cond
);
5395 catch (const gdb_exception
&ex
)
5397 exception_fprintf (gdb_stderr
, ex
,
5398 "Error in testing breakpoint condition:\n");
5403 warning (_("Watchpoint condition cannot be tested "
5404 "in the current scope"));
5405 /* If we failed to set the right context for this
5406 watchpoint, unconditionally report it. */
5408 /* FIXME-someday, should give breakpoint #. */
5409 value_free_to_mark (mark
);
5412 if (cond
&& !condition_result
)
5416 else if (b
->ignore_count
> 0)
5420 /* Increase the hit count even though we don't stop. */
5422 gdb::observers::breakpoint_modified
.notify (b
);
5426 /* Returns true if we need to track moribund locations of LOC's type
5427 on the current target. */
5430 need_moribund_for_location_type (struct bp_location
*loc
)
5432 return ((loc
->loc_type
== bp_loc_software_breakpoint
5433 && !target_supports_stopped_by_sw_breakpoint ())
5434 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5435 && !target_supports_stopped_by_hw_breakpoint ()));
5438 /* See breakpoint.h. */
5441 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5442 const struct target_waitstatus
*ws
)
5444 struct breakpoint
*b
;
5445 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5449 if (!breakpoint_enabled (b
))
5452 for (bp_location
*bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5454 /* For hardware watchpoints, we look only at the first
5455 location. The watchpoint_check function will work on the
5456 entire expression, not the individual locations. For
5457 read watchpoints, the watchpoints_triggered function has
5458 checked all locations already. */
5459 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5462 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5465 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5468 /* Come here if it's a watchpoint, or if the break address
5471 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5474 /* Assume we stop. Should we find a watchpoint that is not
5475 actually triggered, or if the condition of the breakpoint
5476 evaluates as false, we'll reset 'stop' to 0. */
5480 /* If this is a scope breakpoint, mark the associated
5481 watchpoint as triggered so that we will handle the
5482 out-of-scope event. We'll get to the watchpoint next
5484 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5486 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5488 w
->watchpoint_triggered
= watch_triggered_yes
;
5493 /* Check if a moribund breakpoint explains the stop. */
5494 if (!target_supports_stopped_by_sw_breakpoint ()
5495 || !target_supports_stopped_by_hw_breakpoint ())
5497 for (bp_location
*loc
: moribund_locations
)
5499 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5500 && need_moribund_for_location_type (loc
))
5502 bpstat bs
= new bpstats (loc
, &bs_link
);
5503 /* For hits of moribund locations, we should just proceed. */
5506 bs
->print_it
= print_it_noop
;
5514 /* See breakpoint.h. */
5517 bpstat_stop_status (const address_space
*aspace
,
5518 CORE_ADDR bp_addr
, thread_info
*thread
,
5519 const struct target_waitstatus
*ws
,
5522 struct breakpoint
*b
= NULL
;
5523 /* First item of allocated bpstat's. */
5524 bpstat bs_head
= stop_chain
;
5526 int need_remove_insert
;
5529 /* First, build the bpstat chain with locations that explain a
5530 target stop, while being careful to not set the target running,
5531 as that may invalidate locations (in particular watchpoint
5532 locations are recreated). Resuming will happen here with
5533 breakpoint conditions or watchpoint expressions that include
5534 inferior function calls. */
5535 if (bs_head
== NULL
)
5536 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5538 /* A bit of special processing for shlib breakpoints. We need to
5539 process solib loading here, so that the lists of loaded and
5540 unloaded libraries are correct before we handle "catch load" and
5542 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5544 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5546 handle_solib_event ();
5551 /* Now go through the locations that caused the target to stop, and
5552 check whether we're interested in reporting this stop to higher
5553 layers, or whether we should resume the target transparently. */
5557 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5562 b
= bs
->breakpoint_at
;
5563 b
->ops
->check_status (bs
);
5566 bpstat_check_breakpoint_conditions (bs
, thread
);
5571 gdb::observers::breakpoint_modified
.notify (b
);
5573 /* We will stop here. */
5574 if (b
->disposition
== disp_disable
)
5576 --(b
->enable_count
);
5577 if (b
->enable_count
<= 0)
5578 b
->enable_state
= bp_disabled
;
5583 bs
->commands
= b
->commands
;
5584 if (command_line_is_silent (bs
->commands
5585 ? bs
->commands
.get () : NULL
))
5588 b
->ops
->after_condition_true (bs
);
5593 /* Print nothing for this entry if we don't stop or don't
5595 if (!bs
->stop
|| !bs
->print
)
5596 bs
->print_it
= print_it_noop
;
5599 /* If we aren't stopping, the value of some hardware watchpoint may
5600 not have changed, but the intermediate memory locations we are
5601 watching may have. Don't bother if we're stopping; this will get
5603 need_remove_insert
= 0;
5604 if (! bpstat_causes_stop (bs_head
))
5605 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5607 && bs
->breakpoint_at
5608 && is_hardware_watchpoint (bs
->breakpoint_at
))
5610 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5612 update_watchpoint (w
, 0 /* don't reparse. */);
5613 need_remove_insert
= 1;
5616 if (need_remove_insert
)
5617 update_global_location_list (UGLL_MAY_INSERT
);
5618 else if (removed_any
)
5619 update_global_location_list (UGLL_DONT_INSERT
);
5625 handle_jit_event (CORE_ADDR address
)
5627 struct gdbarch
*gdbarch
;
5629 infrun_debug_printf ("handling bp_jit_event");
5631 /* Switch terminal for any messages produced by
5632 breakpoint_re_set. */
5633 target_terminal::ours_for_output ();
5635 gdbarch
= get_frame_arch (get_current_frame ());
5636 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5637 thus it is expected that its objectfile can be found through
5638 minimal symbol lookup. If it doesn't work (and assert fails), it
5639 most likely means that `jit_breakpoint_re_set` was changes and this
5640 function needs to be updated too. */
5641 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5642 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5643 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5645 target_terminal::inferior ();
5648 /* Prepare WHAT final decision for infrun. */
5650 /* Decide what infrun needs to do with this bpstat. */
5653 bpstat_what (bpstat bs_head
)
5655 struct bpstat_what retval
;
5658 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5659 retval
.call_dummy
= STOP_NONE
;
5660 retval
.is_longjmp
= false;
5662 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5664 /* Extract this BS's action. After processing each BS, we check
5665 if its action overrides all we've seem so far. */
5666 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5669 if (bs
->breakpoint_at
== NULL
)
5671 /* I suspect this can happen if it was a momentary
5672 breakpoint which has since been deleted. */
5676 bptype
= bs
->breakpoint_at
->type
;
5683 case bp_hardware_breakpoint
:
5684 case bp_single_step
:
5687 case bp_shlib_event
:
5691 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5693 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5696 this_action
= BPSTAT_WHAT_SINGLE
;
5699 case bp_hardware_watchpoint
:
5700 case bp_read_watchpoint
:
5701 case bp_access_watchpoint
:
5705 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5707 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5711 /* There was a watchpoint, but we're not stopping.
5712 This requires no further action. */
5716 case bp_longjmp_call_dummy
:
5720 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5721 retval
.is_longjmp
= bptype
!= bp_exception
;
5724 this_action
= BPSTAT_WHAT_SINGLE
;
5726 case bp_longjmp_resume
:
5727 case bp_exception_resume
:
5730 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5731 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5734 this_action
= BPSTAT_WHAT_SINGLE
;
5736 case bp_step_resume
:
5738 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5741 /* It is for the wrong frame. */
5742 this_action
= BPSTAT_WHAT_SINGLE
;
5745 case bp_hp_step_resume
:
5747 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5750 /* It is for the wrong frame. */
5751 this_action
= BPSTAT_WHAT_SINGLE
;
5754 case bp_watchpoint_scope
:
5755 case bp_thread_event
:
5756 case bp_overlay_event
:
5757 case bp_longjmp_master
:
5758 case bp_std_terminate_master
:
5759 case bp_exception_master
:
5760 this_action
= BPSTAT_WHAT_SINGLE
;
5766 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5768 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5772 /* Some catchpoints are implemented with breakpoints.
5773 For those, we need to step over the breakpoint. */
5774 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5775 this_action
= BPSTAT_WHAT_SINGLE
;
5779 this_action
= BPSTAT_WHAT_SINGLE
;
5782 /* Make sure the action is stop (silent or noisy),
5783 so infrun.c pops the dummy frame. */
5784 retval
.call_dummy
= STOP_STACK_DUMMY
;
5785 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5787 case bp_std_terminate
:
5788 /* Make sure the action is stop (silent or noisy),
5789 so infrun.c pops the dummy frame. */
5790 retval
.call_dummy
= STOP_STD_TERMINATE
;
5791 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5794 case bp_fast_tracepoint
:
5795 case bp_static_tracepoint
:
5796 /* Tracepoint hits should not be reported back to GDB, and
5797 if one got through somehow, it should have been filtered
5799 internal_error (__FILE__
, __LINE__
,
5800 _("bpstat_what: tracepoint encountered"));
5802 case bp_gnu_ifunc_resolver
:
5803 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5804 this_action
= BPSTAT_WHAT_SINGLE
;
5806 case bp_gnu_ifunc_resolver_return
:
5807 /* The breakpoint will be removed, execution will restart from the
5808 PC of the former breakpoint. */
5809 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5814 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5816 this_action
= BPSTAT_WHAT_SINGLE
;
5820 internal_error (__FILE__
, __LINE__
,
5821 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5824 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5831 bpstat_run_callbacks (bpstat bs_head
)
5835 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5837 struct breakpoint
*b
= bs
->breakpoint_at
;
5844 handle_jit_event (bs
->bp_location_at
->address
);
5846 case bp_gnu_ifunc_resolver
:
5847 gnu_ifunc_resolver_stop (b
);
5849 case bp_gnu_ifunc_resolver_return
:
5850 gnu_ifunc_resolver_return_stop (b
);
5856 /* See breakpoint.h. */
5859 bpstat_should_step ()
5861 struct breakpoint
*b
;
5864 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5869 /* See breakpoint.h. */
5872 bpstat_causes_stop (bpstat bs
)
5874 for (; bs
!= NULL
; bs
= bs
->next
)
5883 /* Compute a string of spaces suitable to indent the next line
5884 so it starts at the position corresponding to the table column
5885 named COL_NAME in the currently active table of UIOUT. */
5888 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5890 static char wrap_indent
[80];
5891 int i
, total_width
, width
, align
;
5895 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5897 if (strcmp (text
, col_name
) == 0)
5899 gdb_assert (total_width
< sizeof wrap_indent
);
5900 memset (wrap_indent
, ' ', total_width
);
5901 wrap_indent
[total_width
] = 0;
5906 total_width
+= width
+ 1;
5912 /* Determine if the locations of this breakpoint will have their conditions
5913 evaluated by the target, host or a mix of both. Returns the following:
5915 "host": Host evals condition.
5916 "host or target": Host or Target evals condition.
5917 "target": Target evals condition.
5921 bp_condition_evaluator (struct breakpoint
*b
)
5923 struct bp_location
*bl
;
5924 char host_evals
= 0;
5925 char target_evals
= 0;
5930 if (!is_breakpoint (b
))
5933 if (gdb_evaluates_breakpoint_condition_p ()
5934 || !target_supports_evaluation_of_breakpoint_conditions ())
5935 return condition_evaluation_host
;
5937 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5939 if (bl
->cond_bytecode
)
5945 if (host_evals
&& target_evals
)
5946 return condition_evaluation_both
;
5947 else if (target_evals
)
5948 return condition_evaluation_target
;
5950 return condition_evaluation_host
;
5953 /* Determine the breakpoint location's condition evaluator. This is
5954 similar to bp_condition_evaluator, but for locations. */
5957 bp_location_condition_evaluator (struct bp_location
*bl
)
5959 if (bl
&& !is_breakpoint (bl
->owner
))
5962 if (gdb_evaluates_breakpoint_condition_p ()
5963 || !target_supports_evaluation_of_breakpoint_conditions ())
5964 return condition_evaluation_host
;
5966 if (bl
&& bl
->cond_bytecode
)
5967 return condition_evaluation_target
;
5969 return condition_evaluation_host
;
5972 /* Print the LOC location out of the list of B->LOC locations. */
5975 print_breakpoint_location (struct breakpoint
*b
,
5976 struct bp_location
*loc
)
5978 struct ui_out
*uiout
= current_uiout
;
5980 scoped_restore_current_program_space restore_pspace
;
5982 if (loc
!= NULL
&& loc
->shlib_disabled
)
5986 set_current_program_space (loc
->pspace
);
5988 if (b
->display_canonical
)
5989 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5990 else if (loc
&& loc
->symtab
)
5992 const struct symbol
*sym
= loc
->symbol
;
5996 uiout
->text ("in ");
5997 uiout
->field_string ("func", sym
->print_name (),
5998 function_name_style
.style ());
6000 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6001 uiout
->text ("at ");
6003 uiout
->field_string ("file",
6004 symtab_to_filename_for_display (loc
->symtab
),
6005 file_name_style
.style ());
6008 if (uiout
->is_mi_like_p ())
6009 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6011 uiout
->field_signed ("line", loc
->line_number
);
6017 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6019 uiout
->field_stream ("at", stb
);
6023 uiout
->field_string ("pending",
6024 event_location_to_string (b
->location
.get ()));
6025 /* If extra_string is available, it could be holding a condition
6026 or dprintf arguments. In either case, make sure it is printed,
6027 too, but only for non-MI streams. */
6028 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6030 if (b
->type
== bp_dprintf
)
6034 uiout
->text (b
->extra_string
);
6038 if (loc
&& is_breakpoint (b
)
6039 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6040 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6043 uiout
->field_string ("evaluated-by",
6044 bp_location_condition_evaluator (loc
));
6050 bptype_string (enum bptype type
)
6052 struct ep_type_description
6055 const char *description
;
6057 static struct ep_type_description bptypes
[] =
6059 {bp_none
, "?deleted?"},
6060 {bp_breakpoint
, "breakpoint"},
6061 {bp_hardware_breakpoint
, "hw breakpoint"},
6062 {bp_single_step
, "sw single-step"},
6063 {bp_until
, "until"},
6064 {bp_finish
, "finish"},
6065 {bp_watchpoint
, "watchpoint"},
6066 {bp_hardware_watchpoint
, "hw watchpoint"},
6067 {bp_read_watchpoint
, "read watchpoint"},
6068 {bp_access_watchpoint
, "acc watchpoint"},
6069 {bp_longjmp
, "longjmp"},
6070 {bp_longjmp_resume
, "longjmp resume"},
6071 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6072 {bp_exception
, "exception"},
6073 {bp_exception_resume
, "exception resume"},
6074 {bp_step_resume
, "step resume"},
6075 {bp_hp_step_resume
, "high-priority step resume"},
6076 {bp_watchpoint_scope
, "watchpoint scope"},
6077 {bp_call_dummy
, "call dummy"},
6078 {bp_std_terminate
, "std::terminate"},
6079 {bp_shlib_event
, "shlib events"},
6080 {bp_thread_event
, "thread events"},
6081 {bp_overlay_event
, "overlay events"},
6082 {bp_longjmp_master
, "longjmp master"},
6083 {bp_std_terminate_master
, "std::terminate master"},
6084 {bp_exception_master
, "exception master"},
6085 {bp_catchpoint
, "catchpoint"},
6086 {bp_tracepoint
, "tracepoint"},
6087 {bp_fast_tracepoint
, "fast tracepoint"},
6088 {bp_static_tracepoint
, "static tracepoint"},
6089 {bp_dprintf
, "dprintf"},
6090 {bp_jit_event
, "jit events"},
6091 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6092 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6095 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6096 || ((int) type
!= bptypes
[(int) type
].type
))
6097 internal_error (__FILE__
, __LINE__
,
6098 _("bptypes table does not describe type #%d."),
6101 return bptypes
[(int) type
].description
;
6104 /* For MI, output a field named 'thread-groups' with a list as the value.
6105 For CLI, prefix the list with the string 'inf'. */
6108 output_thread_groups (struct ui_out
*uiout
,
6109 const char *field_name
,
6110 const std::vector
<int> &inf_nums
,
6113 int is_mi
= uiout
->is_mi_like_p ();
6115 /* For backward compatibility, don't display inferiors in CLI unless
6116 there are several. Always display them for MI. */
6117 if (!is_mi
&& mi_only
)
6120 ui_out_emit_list
list_emitter (uiout
, field_name
);
6122 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6128 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6129 uiout
->field_string (NULL
, mi_group
);
6134 uiout
->text (" inf ");
6138 uiout
->text (plongest (inf_nums
[i
]));
6143 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6144 instead of going via breakpoint_ops::print_one. This makes "maint
6145 info breakpoints" show the software breakpoint locations of
6146 catchpoints, which are considered internal implementation
6150 print_one_breakpoint_location (struct breakpoint
*b
,
6151 struct bp_location
*loc
,
6153 struct bp_location
**last_loc
,
6154 int allflag
, bool raw_loc
)
6156 struct command_line
*l
;
6157 static char bpenables
[] = "nynny";
6159 struct ui_out
*uiout
= current_uiout
;
6160 int header_of_multiple
= 0;
6161 int part_of_multiple
= (loc
!= NULL
);
6162 struct value_print_options opts
;
6164 get_user_print_options (&opts
);
6166 gdb_assert (!loc
|| loc_number
!= 0);
6167 /* See comment in print_one_breakpoint concerning treatment of
6168 breakpoints with single disabled location. */
6171 && (b
->loc
->next
!= NULL
6172 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6173 header_of_multiple
= 1;
6181 if (part_of_multiple
)
6182 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6184 uiout
->field_signed ("number", b
->number
);
6188 if (part_of_multiple
)
6189 uiout
->field_skip ("type");
6191 uiout
->field_string ("type", bptype_string (b
->type
));
6195 if (part_of_multiple
)
6196 uiout
->field_skip ("disp");
6198 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6202 /* For locations that are disabled because of an invalid condition,
6203 display "N*" on CLI, where "*" refers to a footnote below the
6204 table. For MI, simply display a "N" without a footnote. */
6205 const char *N
= (uiout
->is_mi_like_p ()) ? "N" : "N*";
6206 if (part_of_multiple
)
6207 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? N
6208 : (loc
->enabled
? "y" : "n")));
6210 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6213 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6214 b
->ops
->print_one (b
, last_loc
);
6217 if (is_watchpoint (b
))
6219 struct watchpoint
*w
= (struct watchpoint
*) b
;
6221 /* Field 4, the address, is omitted (which makes the columns
6222 not line up too nicely with the headers, but the effect
6223 is relatively readable). */
6224 if (opts
.addressprint
)
6225 uiout
->field_skip ("addr");
6227 uiout
->field_string ("what", w
->exp_string
);
6229 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6230 || is_ada_exception_catchpoint (b
))
6232 if (opts
.addressprint
)
6235 if (header_of_multiple
)
6236 uiout
->field_string ("addr", "<MULTIPLE>",
6237 metadata_style
.style ());
6238 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6239 uiout
->field_string ("addr", "<PENDING>",
6240 metadata_style
.style ());
6242 uiout
->field_core_addr ("addr",
6243 loc
->gdbarch
, loc
->address
);
6246 if (!header_of_multiple
)
6247 print_breakpoint_location (b
, loc
);
6253 if (loc
!= NULL
&& !header_of_multiple
)
6255 std::vector
<int> inf_nums
;
6258 for (inferior
*inf
: all_inferiors ())
6260 if (inf
->pspace
== loc
->pspace
)
6261 inf_nums
.push_back (inf
->num
);
6264 /* For backward compatibility, don't display inferiors in CLI unless
6265 there are several. Always display for MI. */
6267 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6268 && (program_spaces
.size () > 1
6269 || number_of_inferiors () > 1)
6270 /* LOC is for existing B, it cannot be in
6271 moribund_locations and thus having NULL OWNER. */
6272 && loc
->owner
->type
!= bp_catchpoint
))
6274 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6277 if (!part_of_multiple
)
6279 if (b
->thread
!= -1)
6281 /* FIXME: This seems to be redundant and lost here; see the
6282 "stop only in" line a little further down. */
6283 uiout
->text (" thread ");
6284 uiout
->field_signed ("thread", b
->thread
);
6286 else if (b
->task
!= 0)
6288 uiout
->text (" task ");
6289 uiout
->field_signed ("task", b
->task
);
6295 if (!part_of_multiple
)
6296 b
->ops
->print_one_detail (b
, uiout
);
6298 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6301 uiout
->text ("\tstop only in stack frame at ");
6302 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6304 uiout
->field_core_addr ("frame",
6305 b
->gdbarch
, b
->frame_id
.stack_addr
);
6309 if (!part_of_multiple
&& b
->cond_string
)
6312 if (is_tracepoint (b
))
6313 uiout
->text ("\ttrace only if ");
6315 uiout
->text ("\tstop only if ");
6316 uiout
->field_string ("cond", b
->cond_string
);
6318 /* Print whether the target is doing the breakpoint's condition
6319 evaluation. If GDB is doing the evaluation, don't print anything. */
6320 if (is_breakpoint (b
)
6321 && breakpoint_condition_evaluation_mode ()
6322 == condition_evaluation_target
)
6324 uiout
->message (" (%pF evals)",
6325 string_field ("evaluated-by",
6326 bp_condition_evaluator (b
)));
6331 if (!part_of_multiple
&& b
->thread
!= -1)
6333 /* FIXME should make an annotation for this. */
6334 uiout
->text ("\tstop only in thread ");
6335 if (uiout
->is_mi_like_p ())
6336 uiout
->field_signed ("thread", b
->thread
);
6339 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6341 uiout
->field_string ("thread", print_thread_id (thr
));
6346 if (!part_of_multiple
)
6350 /* FIXME should make an annotation for this. */
6351 if (is_catchpoint (b
))
6352 uiout
->text ("\tcatchpoint");
6353 else if (is_tracepoint (b
))
6354 uiout
->text ("\ttracepoint");
6356 uiout
->text ("\tbreakpoint");
6357 uiout
->text (" already hit ");
6358 uiout
->field_signed ("times", b
->hit_count
);
6359 if (b
->hit_count
== 1)
6360 uiout
->text (" time\n");
6362 uiout
->text (" times\n");
6366 /* Output the count also if it is zero, but only if this is mi. */
6367 if (uiout
->is_mi_like_p ())
6368 uiout
->field_signed ("times", b
->hit_count
);
6372 if (!part_of_multiple
&& b
->ignore_count
)
6375 uiout
->message ("\tignore next %pF hits\n",
6376 signed_field ("ignore", b
->ignore_count
));
6379 /* Note that an enable count of 1 corresponds to "enable once"
6380 behavior, which is reported by the combination of enablement and
6381 disposition, so we don't need to mention it here. */
6382 if (!part_of_multiple
&& b
->enable_count
> 1)
6385 uiout
->text ("\tdisable after ");
6386 /* Tweak the wording to clarify that ignore and enable counts
6387 are distinct, and have additive effect. */
6388 if (b
->ignore_count
)
6389 uiout
->text ("additional ");
6391 uiout
->text ("next ");
6392 uiout
->field_signed ("enable", b
->enable_count
);
6393 uiout
->text (" hits\n");
6396 if (!part_of_multiple
&& is_tracepoint (b
))
6398 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6400 if (tp
->traceframe_usage
)
6402 uiout
->text ("\ttrace buffer usage ");
6403 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6404 uiout
->text (" bytes\n");
6408 l
= b
->commands
? b
->commands
.get () : NULL
;
6409 if (!part_of_multiple
&& l
)
6412 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6413 print_command_lines (uiout
, l
, 4);
6416 if (is_tracepoint (b
))
6418 struct tracepoint
*t
= (struct tracepoint
*) b
;
6420 if (!part_of_multiple
&& t
->pass_count
)
6422 annotate_field (10);
6423 uiout
->text ("\tpass count ");
6424 uiout
->field_signed ("pass", t
->pass_count
);
6425 uiout
->text (" \n");
6428 /* Don't display it when tracepoint or tracepoint location is
6430 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6432 annotate_field (11);
6434 if (uiout
->is_mi_like_p ())
6435 uiout
->field_string ("installed",
6436 loc
->inserted
? "y" : "n");
6442 uiout
->text ("\tnot ");
6443 uiout
->text ("installed on target\n");
6448 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6450 if (is_watchpoint (b
))
6452 struct watchpoint
*w
= (struct watchpoint
*) b
;
6454 uiout
->field_string ("original-location", w
->exp_string
);
6456 else if (b
->location
!= NULL
6457 && event_location_to_string (b
->location
.get ()) != NULL
)
6458 uiout
->field_string ("original-location",
6459 event_location_to_string (b
->location
.get ()));
6463 /* See breakpoint.h. */
6465 bool fix_multi_location_breakpoint_output_globally
= false;
6468 print_one_breakpoint (struct breakpoint
*b
,
6469 struct bp_location
**last_loc
,
6472 struct ui_out
*uiout
= current_uiout
;
6473 bool use_fixed_output
6474 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6475 || fix_multi_location_breakpoint_output_globally
);
6477 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6478 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6480 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6482 if (!use_fixed_output
)
6483 bkpt_tuple_emitter
.reset ();
6485 /* If this breakpoint has custom print function,
6486 it's already printed. Otherwise, print individual
6487 locations, if any. */
6489 || b
->ops
->print_one
== NULL
6492 /* If breakpoint has a single location that is disabled, we
6493 print it as if it had several locations, since otherwise it's
6494 hard to represent "breakpoint enabled, location disabled"
6497 Note that while hardware watchpoints have several locations
6498 internally, that's not a property exposed to users.
6500 Likewise, while catchpoints may be implemented with
6501 breakpoints (e.g., catch throw), that's not a property
6502 exposed to users. We do however display the internal
6503 breakpoint locations with "maint info breakpoints". */
6504 if (!is_hardware_watchpoint (b
)
6505 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6506 || is_ada_exception_catchpoint (b
))
6508 || (b
->loc
&& (b
->loc
->next
6510 || b
->loc
->disabled_by_cond
))))
6512 gdb::optional
<ui_out_emit_list
> locations_list
;
6514 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6515 MI record. For later versions, place breakpoint locations in a
6517 if (uiout
->is_mi_like_p () && use_fixed_output
)
6518 locations_list
.emplace (uiout
, "locations");
6521 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
, ++n
)
6523 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6524 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6532 breakpoint_address_bits (struct breakpoint
*b
)
6534 int print_address_bits
= 0;
6535 struct bp_location
*loc
;
6537 /* Software watchpoints that aren't watching memory don't have an
6538 address to print. */
6539 if (is_no_memory_software_watchpoint (b
))
6542 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6546 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6547 if (addr_bit
> print_address_bits
)
6548 print_address_bits
= addr_bit
;
6551 return print_address_bits
;
6554 /* See breakpoint.h. */
6557 print_breakpoint (breakpoint
*b
)
6559 struct bp_location
*dummy_loc
= NULL
;
6560 print_one_breakpoint (b
, &dummy_loc
, 0);
6563 /* Return true if this breakpoint was set by the user, false if it is
6564 internal or momentary. */
6567 user_breakpoint_p (struct breakpoint
*b
)
6569 return b
->number
> 0;
6572 /* See breakpoint.h. */
6575 pending_breakpoint_p (struct breakpoint
*b
)
6577 return b
->loc
== NULL
;
6580 /* Print information on breakpoints (including watchpoints and tracepoints).
6582 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6583 understood by number_or_range_parser. Only breakpoints included in this
6584 list are then printed.
6586 If SHOW_INTERNAL is true, print internal breakpoints.
6588 If FILTER is non-NULL, call it on each breakpoint and only include the
6589 ones for which it returns true.
6591 Return the total number of breakpoints listed. */
6594 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6595 bool (*filter
) (const struct breakpoint
*))
6597 struct breakpoint
*b
;
6598 struct bp_location
*last_loc
= NULL
;
6599 int nr_printable_breakpoints
;
6600 struct value_print_options opts
;
6601 int print_address_bits
= 0;
6602 int print_type_col_width
= 14;
6603 struct ui_out
*uiout
= current_uiout
;
6604 bool has_disabled_by_cond_location
= false;
6606 get_user_print_options (&opts
);
6608 /* Compute the number of rows in the table, as well as the size
6609 required for address fields. */
6610 nr_printable_breakpoints
= 0;
6613 /* If we have a filter, only list the breakpoints it accepts. */
6614 if (filter
&& !filter (b
))
6617 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6618 accept. Skip the others. */
6619 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6621 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6623 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6627 if (show_internal
|| user_breakpoint_p (b
))
6629 int addr_bit
, type_len
;
6631 addr_bit
= breakpoint_address_bits (b
);
6632 if (addr_bit
> print_address_bits
)
6633 print_address_bits
= addr_bit
;
6635 type_len
= strlen (bptype_string (b
->type
));
6636 if (type_len
> print_type_col_width
)
6637 print_type_col_width
= type_len
;
6639 nr_printable_breakpoints
++;
6644 ui_out_emit_table
table_emitter (uiout
,
6645 opts
.addressprint
? 6 : 5,
6646 nr_printable_breakpoints
,
6649 if (nr_printable_breakpoints
> 0)
6650 annotate_breakpoints_headers ();
6651 if (nr_printable_breakpoints
> 0)
6653 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6654 if (nr_printable_breakpoints
> 0)
6656 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6657 if (nr_printable_breakpoints
> 0)
6659 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6660 if (nr_printable_breakpoints
> 0)
6662 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6663 if (opts
.addressprint
)
6665 if (nr_printable_breakpoints
> 0)
6667 if (print_address_bits
<= 32)
6668 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6670 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6672 if (nr_printable_breakpoints
> 0)
6674 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6675 uiout
->table_body ();
6676 if (nr_printable_breakpoints
> 0)
6677 annotate_breakpoints_table ();
6682 /* If we have a filter, only list the breakpoints it accepts. */
6683 if (filter
&& !filter (b
))
6686 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6687 accept. Skip the others. */
6689 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6691 if (show_internal
) /* maintenance info breakpoint */
6693 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6696 else /* all others */
6698 if (!number_is_in_list (bp_num_list
, b
->number
))
6702 /* We only print out user settable breakpoints unless the
6703 show_internal is set. */
6704 if (show_internal
|| user_breakpoint_p (b
))
6706 print_one_breakpoint (b
, &last_loc
, show_internal
);
6707 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
6708 if (loc
->disabled_by_cond
)
6709 has_disabled_by_cond_location
= true;
6714 if (nr_printable_breakpoints
== 0)
6716 /* If there's a filter, let the caller decide how to report
6720 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6721 uiout
->message ("No breakpoints or watchpoints.\n");
6723 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6729 if (last_loc
&& !server_command
)
6730 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6732 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6733 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6737 /* FIXME? Should this be moved up so that it is only called when
6738 there have been breakpoints? */
6739 annotate_breakpoints_table_end ();
6741 return nr_printable_breakpoints
;
6744 /* Display the value of default-collect in a way that is generally
6745 compatible with the breakpoint list. */
6748 default_collect_info (void)
6750 struct ui_out
*uiout
= current_uiout
;
6752 /* If it has no value (which is frequently the case), say nothing; a
6753 message like "No default-collect." gets in user's face when it's
6755 if (!*default_collect
)
6758 /* The following phrase lines up nicely with per-tracepoint collect
6760 uiout
->text ("default collect ");
6761 uiout
->field_string ("default-collect", default_collect
);
6762 uiout
->text (" \n");
6766 info_breakpoints_command (const char *args
, int from_tty
)
6768 breakpoint_1 (args
, false, NULL
);
6770 default_collect_info ();
6774 info_watchpoints_command (const char *args
, int from_tty
)
6776 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6777 struct ui_out
*uiout
= current_uiout
;
6779 if (num_printed
== 0)
6781 if (args
== NULL
|| *args
== '\0')
6782 uiout
->message ("No watchpoints.\n");
6784 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6789 maintenance_info_breakpoints (const char *args
, int from_tty
)
6791 breakpoint_1 (args
, true, NULL
);
6793 default_collect_info ();
6797 breakpoint_has_pc (struct breakpoint
*b
,
6798 struct program_space
*pspace
,
6799 CORE_ADDR pc
, struct obj_section
*section
)
6801 struct bp_location
*bl
= b
->loc
;
6803 for (; bl
; bl
= bl
->next
)
6805 if (bl
->pspace
== pspace
6806 && bl
->address
== pc
6807 && (!overlay_debugging
|| bl
->section
== section
))
6813 /* Print a message describing any user-breakpoints set at PC. This
6814 concerns with logical breakpoints, so we match program spaces, not
6818 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6819 struct program_space
*pspace
, CORE_ADDR pc
,
6820 struct obj_section
*section
, int thread
)
6823 struct breakpoint
*b
;
6826 others
+= (user_breakpoint_p (b
)
6827 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6831 printf_filtered (_("Note: breakpoint "));
6832 else /* if (others == ???) */
6833 printf_filtered (_("Note: breakpoints "));
6835 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6838 printf_filtered ("%d", b
->number
);
6839 if (b
->thread
== -1 && thread
!= -1)
6840 printf_filtered (" (all threads)");
6841 else if (b
->thread
!= -1)
6842 printf_filtered (" (thread %d)", b
->thread
);
6843 printf_filtered ("%s%s ",
6844 ((b
->enable_state
== bp_disabled
6845 || b
->enable_state
== bp_call_disabled
)
6849 : ((others
== 1) ? " and" : ""));
6851 current_uiout
->message (_("also set at pc %ps.\n"),
6852 styled_string (address_style
.style (),
6853 paddress (gdbarch
, pc
)));
6858 /* Return true iff it is meaningful to use the address member of LOC.
6859 For some breakpoint types, the locations' address members are
6860 irrelevant and it makes no sense to attempt to compare them to
6861 other addresses (or use them for any other purpose either).
6863 More specifically, software watchpoints and catchpoints that are
6864 not backed by breakpoints always have a zero valued location
6865 address and we don't want to mark breakpoints of any of these types
6866 to be a duplicate of an actual breakpoint location at address
6870 bl_address_is_meaningful (bp_location
*loc
)
6872 return loc
->loc_type
!= bp_loc_other
;
6875 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6876 true if LOC1 and LOC2 represent the same watchpoint location. */
6879 watchpoint_locations_match (struct bp_location
*loc1
,
6880 struct bp_location
*loc2
)
6882 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6883 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6885 /* Both of them must exist. */
6886 gdb_assert (w1
!= NULL
);
6887 gdb_assert (w2
!= NULL
);
6889 /* If the target can evaluate the condition expression in hardware,
6890 then we we need to insert both watchpoints even if they are at
6891 the same place. Otherwise the watchpoint will only trigger when
6892 the condition of whichever watchpoint was inserted evaluates to
6893 true, not giving a chance for GDB to check the condition of the
6894 other watchpoint. */
6896 && target_can_accel_watchpoint_condition (loc1
->address
,
6898 loc1
->watchpoint_type
,
6899 w1
->cond_exp
.get ()))
6901 && target_can_accel_watchpoint_condition (loc2
->address
,
6903 loc2
->watchpoint_type
,
6904 w2
->cond_exp
.get ())))
6907 /* Note that this checks the owner's type, not the location's. In
6908 case the target does not support read watchpoints, but does
6909 support access watchpoints, we'll have bp_read_watchpoint
6910 watchpoints with hw_access locations. Those should be considered
6911 duplicates of hw_read locations. The hw_read locations will
6912 become hw_access locations later. */
6913 return (loc1
->owner
->type
== loc2
->owner
->type
6914 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6915 && loc1
->address
== loc2
->address
6916 && loc1
->length
== loc2
->length
);
6919 /* See breakpoint.h. */
6922 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6923 const address_space
*aspace2
, CORE_ADDR addr2
)
6925 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6926 || aspace1
== aspace2
)
6930 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6931 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6932 matches ASPACE2. On targets that have global breakpoints, the address
6933 space doesn't really matter. */
6936 breakpoint_address_match_range (const address_space
*aspace1
,
6938 int len1
, const address_space
*aspace2
,
6941 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6942 || aspace1
== aspace2
)
6943 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6946 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6947 a ranged breakpoint. In most targets, a match happens only if ASPACE
6948 matches the breakpoint's address space. On targets that have global
6949 breakpoints, the address space doesn't really matter. */
6952 breakpoint_location_address_match (struct bp_location
*bl
,
6953 const address_space
*aspace
,
6956 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6959 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6960 bl
->address
, bl
->length
,
6964 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6965 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6966 match happens only if ASPACE matches the breakpoint's address
6967 space. On targets that have global breakpoints, the address space
6968 doesn't really matter. */
6971 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6972 const address_space
*aspace
,
6973 CORE_ADDR addr
, int len
)
6975 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6976 || bl
->pspace
->aspace
== aspace
)
6978 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6980 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6986 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6987 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6988 true, otherwise returns false. */
6991 tracepoint_locations_match (struct bp_location
*loc1
,
6992 struct bp_location
*loc2
)
6994 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6995 /* Since tracepoint locations are never duplicated with others', tracepoint
6996 locations at the same address of different tracepoints are regarded as
6997 different locations. */
6998 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7003 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7004 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
7005 the same location. If SW_HW_BPS_MATCH is true, then software
7006 breakpoint locations and hardware breakpoint locations match,
7007 otherwise they don't. */
7010 breakpoint_locations_match (struct bp_location
*loc1
,
7011 struct bp_location
*loc2
,
7012 bool sw_hw_bps_match
)
7014 int hw_point1
, hw_point2
;
7016 /* Both of them must not be in moribund_locations. */
7017 gdb_assert (loc1
->owner
!= NULL
);
7018 gdb_assert (loc2
->owner
!= NULL
);
7020 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7021 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7023 if (hw_point1
!= hw_point2
)
7026 return watchpoint_locations_match (loc1
, loc2
);
7027 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7028 return tracepoint_locations_match (loc1
, loc2
);
7030 /* We compare bp_location.length in order to cover ranged
7031 breakpoints. Keep this in sync with
7032 bp_location_is_less_than. */
7033 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7034 loc2
->pspace
->aspace
, loc2
->address
)
7035 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
7036 && loc1
->length
== loc2
->length
);
7040 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7041 int bnum
, int have_bnum
)
7043 /* The longest string possibly returned by hex_string_custom
7044 is 50 chars. These must be at least that big for safety. */
7048 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7049 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7051 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7052 bnum
, astr1
, astr2
);
7054 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7057 /* Adjust a breakpoint's address to account for architectural
7058 constraints on breakpoint placement. Return the adjusted address.
7059 Note: Very few targets require this kind of adjustment. For most
7060 targets, this function is simply the identity function. */
7063 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7064 CORE_ADDR bpaddr
, enum bptype bptype
)
7066 if (bptype
== bp_watchpoint
7067 || bptype
== bp_hardware_watchpoint
7068 || bptype
== bp_read_watchpoint
7069 || bptype
== bp_access_watchpoint
7070 || bptype
== bp_catchpoint
)
7072 /* Watchpoints and the various bp_catch_* eventpoints should not
7073 have their addresses modified. */
7076 else if (bptype
== bp_single_step
)
7078 /* Single-step breakpoints should not have their addresses
7079 modified. If there's any architectural constrain that
7080 applies to this address, then it should have already been
7081 taken into account when the breakpoint was created in the
7082 first place. If we didn't do this, stepping through e.g.,
7083 Thumb-2 IT blocks would break. */
7088 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7090 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7092 /* Some targets have architectural constraints on the placement
7093 of breakpoint instructions. Obtain the adjusted address. */
7094 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7097 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7099 /* An adjusted breakpoint address can significantly alter
7100 a user's expectations. Print a warning if an adjustment
7102 if (adjusted_bpaddr
!= bpaddr
)
7103 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7105 return adjusted_bpaddr
;
7110 bp_location_from_bp_type (bptype type
)
7115 case bp_single_step
:
7119 case bp_longjmp_resume
:
7120 case bp_longjmp_call_dummy
:
7122 case bp_exception_resume
:
7123 case bp_step_resume
:
7124 case bp_hp_step_resume
:
7125 case bp_watchpoint_scope
:
7127 case bp_std_terminate
:
7128 case bp_shlib_event
:
7129 case bp_thread_event
:
7130 case bp_overlay_event
:
7132 case bp_longjmp_master
:
7133 case bp_std_terminate_master
:
7134 case bp_exception_master
:
7135 case bp_gnu_ifunc_resolver
:
7136 case bp_gnu_ifunc_resolver_return
:
7138 return bp_loc_software_breakpoint
;
7139 case bp_hardware_breakpoint
:
7140 return bp_loc_hardware_breakpoint
;
7141 case bp_hardware_watchpoint
:
7142 case bp_read_watchpoint
:
7143 case bp_access_watchpoint
:
7144 return bp_loc_hardware_watchpoint
;
7148 case bp_fast_tracepoint
:
7149 case bp_static_tracepoint
:
7150 return bp_loc_other
;
7152 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7156 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7158 this->owner
= owner
;
7159 this->cond_bytecode
= NULL
;
7160 this->shlib_disabled
= 0;
7162 this->disabled_by_cond
= false;
7164 this->loc_type
= type
;
7166 if (this->loc_type
== bp_loc_software_breakpoint
7167 || this->loc_type
== bp_loc_hardware_breakpoint
)
7168 mark_breakpoint_location_modified (this);
7173 bp_location::bp_location (breakpoint
*owner
)
7174 : bp_location::bp_location (owner
,
7175 bp_location_from_bp_type (owner
->type
))
7179 /* Allocate a struct bp_location. */
7181 static struct bp_location
*
7182 allocate_bp_location (struct breakpoint
*bpt
)
7184 return bpt
->ops
->allocate_location (bpt
);
7187 /* Decrement reference count. If the reference count reaches 0,
7188 destroy the bp_location. Sets *BLP to NULL. */
7191 decref_bp_location (struct bp_location
**blp
)
7193 bp_location_ref_policy::decref (*blp
);
7197 /* Add breakpoint B at the end of the global breakpoint chain. */
7200 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7202 struct breakpoint
*b1
;
7203 struct breakpoint
*result
= b
.get ();
7205 /* Add this breakpoint to the end of the chain so that a list of
7206 breakpoints will come out in order of increasing numbers. */
7208 b1
= breakpoint_chain
;
7210 breakpoint_chain
= b
.release ();
7215 b1
->next
= b
.release ();
7221 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7224 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7225 struct gdbarch
*gdbarch
,
7227 const struct breakpoint_ops
*ops
)
7229 gdb_assert (ops
!= NULL
);
7233 b
->gdbarch
= gdbarch
;
7234 b
->language
= current_language
->la_language
;
7235 b
->input_radix
= input_radix
;
7236 b
->related_breakpoint
= b
;
7239 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7240 that has type BPTYPE and has no locations as yet. */
7242 static struct breakpoint
*
7243 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7245 const struct breakpoint_ops
*ops
)
7247 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7249 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7250 return add_to_breakpoint_chain (std::move (b
));
7253 /* Initialize loc->function_name. */
7256 set_breakpoint_location_function (struct bp_location
*loc
)
7258 gdb_assert (loc
->owner
!= NULL
);
7260 if (loc
->owner
->type
== bp_breakpoint
7261 || loc
->owner
->type
== bp_hardware_breakpoint
7262 || is_tracepoint (loc
->owner
))
7264 const char *function_name
;
7266 if (loc
->msymbol
!= NULL
7267 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7268 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7270 struct breakpoint
*b
= loc
->owner
;
7272 function_name
= loc
->msymbol
->linkage_name ();
7274 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7275 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7277 /* Create only the whole new breakpoint of this type but do not
7278 mess more complicated breakpoints with multiple locations. */
7279 b
->type
= bp_gnu_ifunc_resolver
;
7280 /* Remember the resolver's address for use by the return
7282 loc
->related_address
= loc
->address
;
7286 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7289 loc
->function_name
= xstrdup (function_name
);
7293 /* Attempt to determine architecture of location identified by SAL. */
7295 get_sal_arch (struct symtab_and_line sal
)
7298 return sal
.section
->objfile
->arch ();
7300 return SYMTAB_OBJFILE (sal
.symtab
)->arch ();
7305 /* Low level routine for partially initializing a breakpoint of type
7306 BPTYPE. The newly created breakpoint's address, section, source
7307 file name, and line number are provided by SAL.
7309 It is expected that the caller will complete the initialization of
7310 the newly created breakpoint struct as well as output any status
7311 information regarding the creation of a new breakpoint. */
7314 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7315 struct symtab_and_line sal
, enum bptype bptype
,
7316 const struct breakpoint_ops
*ops
)
7318 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7320 add_location_to_breakpoint (b
, &sal
);
7322 if (bptype
!= bp_catchpoint
)
7323 gdb_assert (sal
.pspace
!= NULL
);
7325 /* Store the program space that was used to set the breakpoint,
7326 except for ordinary breakpoints, which are independent of the
7328 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7329 b
->pspace
= sal
.pspace
;
7332 /* set_raw_breakpoint is a low level routine for allocating and
7333 partially initializing a breakpoint of type BPTYPE. The newly
7334 created breakpoint's address, section, source file name, and line
7335 number are provided by SAL. The newly created and partially
7336 initialized breakpoint is added to the breakpoint chain and
7337 is also returned as the value of this function.
7339 It is expected that the caller will complete the initialization of
7340 the newly created breakpoint struct as well as output any status
7341 information regarding the creation of a new breakpoint. In
7342 particular, set_raw_breakpoint does NOT set the breakpoint
7343 number! Care should be taken to not allow an error to occur
7344 prior to completing the initialization of the breakpoint. If this
7345 should happen, a bogus breakpoint will be left on the chain. */
7348 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7349 struct symtab_and_line sal
, enum bptype bptype
,
7350 const struct breakpoint_ops
*ops
)
7352 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7354 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7355 return add_to_breakpoint_chain (std::move (b
));
7358 /* Call this routine when stepping and nexting to enable a breakpoint
7359 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7360 initiated the operation. */
7363 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7365 struct breakpoint
*b
, *b_tmp
;
7366 int thread
= tp
->global_num
;
7368 /* To avoid having to rescan all objfile symbols at every step,
7369 we maintain a list of continually-inserted but always disabled
7370 longjmp "master" breakpoints. Here, we simply create momentary
7371 clones of those and enable them for the requested thread. */
7372 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7373 if (b
->pspace
== current_program_space
7374 && (b
->type
== bp_longjmp_master
7375 || b
->type
== bp_exception_master
))
7377 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7378 struct breakpoint
*clone
;
7380 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7381 after their removal. */
7382 clone
= momentary_breakpoint_from_master (b
, type
,
7383 &momentary_breakpoint_ops
, 1);
7384 clone
->thread
= thread
;
7387 tp
->initiating_frame
= frame
;
7390 /* Delete all longjmp breakpoints from THREAD. */
7392 delete_longjmp_breakpoint (int thread
)
7394 struct breakpoint
*b
, *b_tmp
;
7396 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7397 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7399 if (b
->thread
== thread
)
7400 delete_breakpoint (b
);
7405 delete_longjmp_breakpoint_at_next_stop (int thread
)
7407 struct breakpoint
*b
, *b_tmp
;
7409 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7410 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7412 if (b
->thread
== thread
)
7413 b
->disposition
= disp_del_at_next_stop
;
7417 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7418 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7419 pointer to any of them. Return NULL if this system cannot place longjmp
7423 set_longjmp_breakpoint_for_call_dummy (void)
7425 struct breakpoint
*b
, *retval
= NULL
;
7428 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7430 struct breakpoint
*new_b
;
7432 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7433 &momentary_breakpoint_ops
,
7435 new_b
->thread
= inferior_thread ()->global_num
;
7437 /* Link NEW_B into the chain of RETVAL breakpoints. */
7439 gdb_assert (new_b
->related_breakpoint
== new_b
);
7442 new_b
->related_breakpoint
= retval
;
7443 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7444 retval
= retval
->related_breakpoint
;
7445 retval
->related_breakpoint
= new_b
;
7451 /* Verify all existing dummy frames and their associated breakpoints for
7452 TP. Remove those which can no longer be found in the current frame
7455 You should call this function only at places where it is safe to currently
7456 unwind the whole stack. Failed stack unwind would discard live dummy
7460 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7462 struct breakpoint
*b
, *b_tmp
;
7464 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7465 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7467 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7469 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7470 dummy_b
= dummy_b
->related_breakpoint
;
7471 if (dummy_b
->type
!= bp_call_dummy
7472 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7475 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7477 while (b
->related_breakpoint
!= b
)
7479 if (b_tmp
== b
->related_breakpoint
)
7480 b_tmp
= b
->related_breakpoint
->next
;
7481 delete_breakpoint (b
->related_breakpoint
);
7483 delete_breakpoint (b
);
7488 enable_overlay_breakpoints (void)
7490 struct breakpoint
*b
;
7493 if (b
->type
== bp_overlay_event
)
7495 b
->enable_state
= bp_enabled
;
7496 update_global_location_list (UGLL_MAY_INSERT
);
7497 overlay_events_enabled
= 1;
7502 disable_overlay_breakpoints (void)
7504 struct breakpoint
*b
;
7507 if (b
->type
== bp_overlay_event
)
7509 b
->enable_state
= bp_disabled
;
7510 update_global_location_list (UGLL_DONT_INSERT
);
7511 overlay_events_enabled
= 0;
7515 /* Set an active std::terminate breakpoint for each std::terminate
7516 master breakpoint. */
7518 set_std_terminate_breakpoint (void)
7520 struct breakpoint
*b
, *b_tmp
;
7522 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7523 if (b
->pspace
== current_program_space
7524 && b
->type
== bp_std_terminate_master
)
7526 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7527 &momentary_breakpoint_ops
, 1);
7531 /* Delete all the std::terminate breakpoints. */
7533 delete_std_terminate_breakpoint (void)
7535 struct breakpoint
*b
, *b_tmp
;
7537 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7538 if (b
->type
== bp_std_terminate
)
7539 delete_breakpoint (b
);
7543 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7545 struct breakpoint
*b
;
7547 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7548 &internal_breakpoint_ops
);
7550 b
->enable_state
= bp_enabled
;
7551 /* location has to be used or breakpoint_re_set will delete me. */
7552 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7554 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7559 struct lang_and_radix
7565 /* Create a breakpoint for JIT code registration and unregistration. */
7568 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7570 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7571 &internal_breakpoint_ops
);
7574 /* Remove JIT code registration and unregistration breakpoint(s). */
7577 remove_jit_event_breakpoints (void)
7579 struct breakpoint
*b
, *b_tmp
;
7581 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7582 if (b
->type
== bp_jit_event
7583 && b
->loc
->pspace
== current_program_space
)
7584 delete_breakpoint (b
);
7588 remove_solib_event_breakpoints (void)
7590 struct breakpoint
*b
, *b_tmp
;
7592 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7593 if (b
->type
== bp_shlib_event
7594 && b
->loc
->pspace
== current_program_space
)
7595 delete_breakpoint (b
);
7598 /* See breakpoint.h. */
7601 remove_solib_event_breakpoints_at_next_stop (void)
7603 struct breakpoint
*b
, *b_tmp
;
7605 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7606 if (b
->type
== bp_shlib_event
7607 && b
->loc
->pspace
== current_program_space
)
7608 b
->disposition
= disp_del_at_next_stop
;
7611 /* Helper for create_solib_event_breakpoint /
7612 create_and_insert_solib_event_breakpoint. Allows specifying which
7613 INSERT_MODE to pass through to update_global_location_list. */
7615 static struct breakpoint
*
7616 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7617 enum ugll_insert_mode insert_mode
)
7619 struct breakpoint
*b
;
7621 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7622 &internal_breakpoint_ops
);
7623 update_global_location_list_nothrow (insert_mode
);
7628 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7630 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7633 /* See breakpoint.h. */
7636 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7638 struct breakpoint
*b
;
7640 /* Explicitly tell update_global_location_list to insert
7642 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7643 if (!b
->loc
->inserted
)
7645 delete_breakpoint (b
);
7651 /* Disable any breakpoints that are on code in shared libraries. Only
7652 apply to enabled breakpoints, disabled ones can just stay disabled. */
7655 disable_breakpoints_in_shlibs (void)
7657 struct bp_location
*loc
, **locp_tmp
;
7659 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7661 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7662 struct breakpoint
*b
= loc
->owner
;
7664 /* We apply the check to all breakpoints, including disabled for
7665 those with loc->duplicate set. This is so that when breakpoint
7666 becomes enabled, or the duplicate is removed, gdb will try to
7667 insert all breakpoints. If we don't set shlib_disabled here,
7668 we'll try to insert those breakpoints and fail. */
7669 if (((b
->type
== bp_breakpoint
)
7670 || (b
->type
== bp_jit_event
)
7671 || (b
->type
== bp_hardware_breakpoint
)
7672 || (is_tracepoint (b
)))
7673 && loc
->pspace
== current_program_space
7674 && !loc
->shlib_disabled
7675 && solib_name_from_address (loc
->pspace
, loc
->address
)
7678 loc
->shlib_disabled
= 1;
7683 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7684 notification of unloaded_shlib. Only apply to enabled breakpoints,
7685 disabled ones can just stay disabled. */
7688 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7690 struct bp_location
*loc
, **locp_tmp
;
7691 int disabled_shlib_breaks
= 0;
7693 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7695 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7696 struct breakpoint
*b
= loc
->owner
;
7698 if (solib
->pspace
== loc
->pspace
7699 && !loc
->shlib_disabled
7700 && (((b
->type
== bp_breakpoint
7701 || b
->type
== bp_jit_event
7702 || b
->type
== bp_hardware_breakpoint
)
7703 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7704 || loc
->loc_type
== bp_loc_software_breakpoint
))
7705 || is_tracepoint (b
))
7706 && solib_contains_address_p (solib
, loc
->address
))
7708 loc
->shlib_disabled
= 1;
7709 /* At this point, we cannot rely on remove_breakpoint
7710 succeeding so we must mark the breakpoint as not inserted
7711 to prevent future errors occurring in remove_breakpoints. */
7714 /* This may cause duplicate notifications for the same breakpoint. */
7715 gdb::observers::breakpoint_modified
.notify (b
);
7717 if (!disabled_shlib_breaks
)
7719 target_terminal::ours_for_output ();
7720 warning (_("Temporarily disabling breakpoints "
7721 "for unloaded shared library \"%s\""),
7724 disabled_shlib_breaks
= 1;
7729 /* Disable any breakpoints and tracepoints in OBJFILE upon
7730 notification of free_objfile. Only apply to enabled breakpoints,
7731 disabled ones can just stay disabled. */
7734 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7736 struct breakpoint
*b
;
7738 if (objfile
== NULL
)
7741 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7742 managed by the user with add-symbol-file/remove-symbol-file.
7743 Similarly to how breakpoints in shared libraries are handled in
7744 response to "nosharedlibrary", mark breakpoints in such modules
7745 shlib_disabled so they end up uninserted on the next global
7746 location list update. Shared libraries not loaded by the user
7747 aren't handled here -- they're already handled in
7748 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7749 solib_unloaded observer. We skip objfiles that are not
7750 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7752 if ((objfile
->flags
& OBJF_SHARED
) == 0
7753 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7758 struct bp_location
*loc
;
7759 int bp_modified
= 0;
7761 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7764 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7766 CORE_ADDR loc_addr
= loc
->address
;
7768 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7769 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7772 if (loc
->shlib_disabled
!= 0)
7775 if (objfile
->pspace
!= loc
->pspace
)
7778 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7779 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7782 if (is_addr_in_objfile (loc_addr
, objfile
))
7784 loc
->shlib_disabled
= 1;
7785 /* At this point, we don't know whether the object was
7786 unmapped from the inferior or not, so leave the
7787 inserted flag alone. We'll handle failure to
7788 uninsert quietly, in case the object was indeed
7791 mark_breakpoint_location_modified (loc
);
7798 gdb::observers::breakpoint_modified
.notify (b
);
7802 /* FORK & VFORK catchpoints. */
7804 /* An instance of this type is used to represent a fork or vfork
7805 catchpoint. A breakpoint is really of this type iff its ops pointer points
7806 to CATCH_FORK_BREAKPOINT_OPS. */
7808 struct fork_catchpoint
: public breakpoint
7810 /* Process id of a child process whose forking triggered this
7811 catchpoint. This field is only valid immediately after this
7812 catchpoint has triggered. */
7813 ptid_t forked_inferior_pid
;
7816 /* Implement the "insert" breakpoint_ops method for fork
7820 insert_catch_fork (struct bp_location
*bl
)
7822 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7825 /* Implement the "remove" breakpoint_ops method for fork
7829 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7831 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7834 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7838 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7839 const address_space
*aspace
, CORE_ADDR bp_addr
,
7840 const struct target_waitstatus
*ws
)
7842 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7844 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7847 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7851 /* Implement the "print_it" breakpoint_ops method for fork
7854 static enum print_stop_action
7855 print_it_catch_fork (bpstat bs
)
7857 struct ui_out
*uiout
= current_uiout
;
7858 struct breakpoint
*b
= bs
->breakpoint_at
;
7859 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7861 annotate_catchpoint (b
->number
);
7862 maybe_print_thread_hit_breakpoint (uiout
);
7863 if (b
->disposition
== disp_del
)
7864 uiout
->text ("Temporary catchpoint ");
7866 uiout
->text ("Catchpoint ");
7867 if (uiout
->is_mi_like_p ())
7869 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7870 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7872 uiout
->field_signed ("bkptno", b
->number
);
7873 uiout
->text (" (forked process ");
7874 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7875 uiout
->text ("), ");
7876 return PRINT_SRC_AND_LOC
;
7879 /* Implement the "print_one" breakpoint_ops method for fork
7883 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7885 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7886 struct value_print_options opts
;
7887 struct ui_out
*uiout
= current_uiout
;
7889 get_user_print_options (&opts
);
7891 /* Field 4, the address, is omitted (which makes the columns not
7892 line up too nicely with the headers, but the effect is relatively
7894 if (opts
.addressprint
)
7895 uiout
->field_skip ("addr");
7897 uiout
->text ("fork");
7898 if (c
->forked_inferior_pid
!= null_ptid
)
7900 uiout
->text (", process ");
7901 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7905 if (uiout
->is_mi_like_p ())
7906 uiout
->field_string ("catch-type", "fork");
7909 /* Implement the "print_mention" breakpoint_ops method for fork
7913 print_mention_catch_fork (struct breakpoint
*b
)
7915 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7918 /* Implement the "print_recreate" breakpoint_ops method for fork
7922 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7924 fprintf_unfiltered (fp
, "catch fork");
7925 print_recreate_thread (b
, fp
);
7928 /* The breakpoint_ops structure to be used in fork catchpoints. */
7930 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7932 /* Implement the "insert" breakpoint_ops method for vfork
7936 insert_catch_vfork (struct bp_location
*bl
)
7938 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7941 /* Implement the "remove" breakpoint_ops method for vfork
7945 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7947 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7950 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7954 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7955 const address_space
*aspace
, CORE_ADDR bp_addr
,
7956 const struct target_waitstatus
*ws
)
7958 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7960 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7963 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7967 /* Implement the "print_it" breakpoint_ops method for vfork
7970 static enum print_stop_action
7971 print_it_catch_vfork (bpstat bs
)
7973 struct ui_out
*uiout
= current_uiout
;
7974 struct breakpoint
*b
= bs
->breakpoint_at
;
7975 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7977 annotate_catchpoint (b
->number
);
7978 maybe_print_thread_hit_breakpoint (uiout
);
7979 if (b
->disposition
== disp_del
)
7980 uiout
->text ("Temporary catchpoint ");
7982 uiout
->text ("Catchpoint ");
7983 if (uiout
->is_mi_like_p ())
7985 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7986 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7988 uiout
->field_signed ("bkptno", b
->number
);
7989 uiout
->text (" (vforked process ");
7990 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7991 uiout
->text ("), ");
7992 return PRINT_SRC_AND_LOC
;
7995 /* Implement the "print_one" breakpoint_ops method for vfork
7999 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8001 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8002 struct value_print_options opts
;
8003 struct ui_out
*uiout
= current_uiout
;
8005 get_user_print_options (&opts
);
8006 /* Field 4, the address, is omitted (which makes the columns not
8007 line up too nicely with the headers, but the effect is relatively
8009 if (opts
.addressprint
)
8010 uiout
->field_skip ("addr");
8012 uiout
->text ("vfork");
8013 if (c
->forked_inferior_pid
!= null_ptid
)
8015 uiout
->text (", process ");
8016 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
8020 if (uiout
->is_mi_like_p ())
8021 uiout
->field_string ("catch-type", "vfork");
8024 /* Implement the "print_mention" breakpoint_ops method for vfork
8028 print_mention_catch_vfork (struct breakpoint
*b
)
8030 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8033 /* Implement the "print_recreate" breakpoint_ops method for vfork
8037 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8039 fprintf_unfiltered (fp
, "catch vfork");
8040 print_recreate_thread (b
, fp
);
8043 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8045 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8047 /* An instance of this type is used to represent an solib catchpoint.
8048 A breakpoint is really of this type iff its ops pointer points to
8049 CATCH_SOLIB_BREAKPOINT_OPS. */
8051 struct solib_catchpoint
: public breakpoint
8053 ~solib_catchpoint () override
;
8055 /* True for "catch load", false for "catch unload". */
8058 /* Regular expression to match, if any. COMPILED is only valid when
8059 REGEX is non-NULL. */
8061 std::unique_ptr
<compiled_regex
> compiled
;
8064 solib_catchpoint::~solib_catchpoint ()
8066 xfree (this->regex
);
8070 insert_catch_solib (struct bp_location
*ignore
)
8076 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8082 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8083 const address_space
*aspace
,
8085 const struct target_waitstatus
*ws
)
8087 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8088 struct breakpoint
*other
;
8090 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8093 ALL_BREAKPOINTS (other
)
8095 struct bp_location
*other_bl
;
8097 if (other
== bl
->owner
)
8100 if (other
->type
!= bp_shlib_event
)
8103 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8106 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8108 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8117 check_status_catch_solib (struct bpstats
*bs
)
8119 struct solib_catchpoint
*self
8120 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8124 for (so_list
*iter
: current_program_space
->added_solibs
)
8127 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8133 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
8136 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
8142 bs
->print_it
= print_it_noop
;
8145 static enum print_stop_action
8146 print_it_catch_solib (bpstat bs
)
8148 struct breakpoint
*b
= bs
->breakpoint_at
;
8149 struct ui_out
*uiout
= current_uiout
;
8151 annotate_catchpoint (b
->number
);
8152 maybe_print_thread_hit_breakpoint (uiout
);
8153 if (b
->disposition
== disp_del
)
8154 uiout
->text ("Temporary catchpoint ");
8156 uiout
->text ("Catchpoint ");
8157 uiout
->field_signed ("bkptno", b
->number
);
8159 if (uiout
->is_mi_like_p ())
8160 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8161 print_solib_event (1);
8162 return PRINT_SRC_AND_LOC
;
8166 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8168 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8169 struct value_print_options opts
;
8170 struct ui_out
*uiout
= current_uiout
;
8172 get_user_print_options (&opts
);
8173 /* Field 4, the address, is omitted (which makes the columns not
8174 line up too nicely with the headers, but the effect is relatively
8176 if (opts
.addressprint
)
8179 uiout
->field_skip ("addr");
8187 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8189 msg
= _("load of library");
8194 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8196 msg
= _("unload of library");
8198 uiout
->field_string ("what", msg
);
8200 if (uiout
->is_mi_like_p ())
8201 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8205 print_mention_catch_solib (struct breakpoint
*b
)
8207 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8209 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8210 self
->is_load
? "load" : "unload");
8214 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8216 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8218 fprintf_unfiltered (fp
, "%s %s",
8219 b
->disposition
== disp_del
? "tcatch" : "catch",
8220 self
->is_load
? "load" : "unload");
8222 fprintf_unfiltered (fp
, " %s", self
->regex
);
8223 fprintf_unfiltered (fp
, "\n");
8226 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8228 /* See breakpoint.h. */
8231 add_solib_catchpoint (const char *arg
, bool is_load
, bool is_temp
, bool enabled
)
8233 struct gdbarch
*gdbarch
= get_current_arch ();
8237 arg
= skip_spaces (arg
);
8239 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8243 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8244 _("Invalid regexp")));
8245 c
->regex
= xstrdup (arg
);
8248 c
->is_load
= is_load
;
8249 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8250 &catch_solib_breakpoint_ops
);
8252 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8254 install_breakpoint (0, std::move (c
), 1);
8257 /* A helper function that does all the work for "catch load" and
8261 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8262 struct cmd_list_element
*command
)
8264 const int enabled
= 1;
8265 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8267 add_solib_catchpoint (arg
, is_load
, temp
, enabled
);
8271 catch_load_command_1 (const char *arg
, int from_tty
,
8272 struct cmd_list_element
*command
)
8274 catch_load_or_unload (arg
, from_tty
, 1, command
);
8278 catch_unload_command_1 (const char *arg
, int from_tty
,
8279 struct cmd_list_element
*command
)
8281 catch_load_or_unload (arg
, from_tty
, 0, command
);
8284 /* See breakpoint.h. */
8287 init_catchpoint (struct breakpoint
*b
,
8288 struct gdbarch
*gdbarch
, bool temp
,
8289 const char *cond_string
,
8290 const struct breakpoint_ops
*ops
)
8292 symtab_and_line sal
;
8293 sal
.pspace
= current_program_space
;
8295 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8297 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8298 b
->disposition
= temp
? disp_del
: disp_donttouch
;
8302 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8304 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8305 set_breakpoint_number (internal
, b
);
8306 if (is_tracepoint (b
))
8307 set_tracepoint_count (breakpoint_count
);
8310 gdb::observers::breakpoint_created
.notify (b
);
8313 update_global_location_list (UGLL_MAY_INSERT
);
8317 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8318 bool temp
, const char *cond_string
,
8319 const struct breakpoint_ops
*ops
)
8321 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8323 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
, ops
);
8325 c
->forked_inferior_pid
= null_ptid
;
8327 install_breakpoint (0, std::move (c
), 1);
8330 /* Exec catchpoints. */
8332 /* An instance of this type is used to represent an exec catchpoint.
8333 A breakpoint is really of this type iff its ops pointer points to
8334 CATCH_EXEC_BREAKPOINT_OPS. */
8336 struct exec_catchpoint
: public breakpoint
8338 ~exec_catchpoint () override
;
8340 /* Filename of a program whose exec triggered this catchpoint.
8341 This field is only valid immediately after this catchpoint has
8343 char *exec_pathname
;
8346 /* Exec catchpoint destructor. */
8348 exec_catchpoint::~exec_catchpoint ()
8350 xfree (this->exec_pathname
);
8354 insert_catch_exec (struct bp_location
*bl
)
8356 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8360 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8362 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8366 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8367 const address_space
*aspace
, CORE_ADDR bp_addr
,
8368 const struct target_waitstatus
*ws
)
8370 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8372 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8375 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8379 static enum print_stop_action
8380 print_it_catch_exec (bpstat bs
)
8382 struct ui_out
*uiout
= current_uiout
;
8383 struct breakpoint
*b
= bs
->breakpoint_at
;
8384 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8386 annotate_catchpoint (b
->number
);
8387 maybe_print_thread_hit_breakpoint (uiout
);
8388 if (b
->disposition
== disp_del
)
8389 uiout
->text ("Temporary catchpoint ");
8391 uiout
->text ("Catchpoint ");
8392 if (uiout
->is_mi_like_p ())
8394 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8395 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8397 uiout
->field_signed ("bkptno", b
->number
);
8398 uiout
->text (" (exec'd ");
8399 uiout
->field_string ("new-exec", c
->exec_pathname
);
8400 uiout
->text ("), ");
8402 return PRINT_SRC_AND_LOC
;
8406 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8408 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8409 struct value_print_options opts
;
8410 struct ui_out
*uiout
= current_uiout
;
8412 get_user_print_options (&opts
);
8414 /* Field 4, the address, is omitted (which makes the columns
8415 not line up too nicely with the headers, but the effect
8416 is relatively readable). */
8417 if (opts
.addressprint
)
8418 uiout
->field_skip ("addr");
8420 uiout
->text ("exec");
8421 if (c
->exec_pathname
!= NULL
)
8423 uiout
->text (", program \"");
8424 uiout
->field_string ("what", c
->exec_pathname
);
8425 uiout
->text ("\" ");
8428 if (uiout
->is_mi_like_p ())
8429 uiout
->field_string ("catch-type", "exec");
8433 print_mention_catch_exec (struct breakpoint
*b
)
8435 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8438 /* Implement the "print_recreate" breakpoint_ops method for exec
8442 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8444 fprintf_unfiltered (fp
, "catch exec");
8445 print_recreate_thread (b
, fp
);
8448 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8451 hw_breakpoint_used_count (void)
8454 struct breakpoint
*b
;
8455 struct bp_location
*bl
;
8459 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8460 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8462 /* Special types of hardware breakpoints may use more than
8464 i
+= b
->ops
->resources_needed (bl
);
8471 /* Returns the resources B would use if it were a hardware
8475 hw_watchpoint_use_count (struct breakpoint
*b
)
8478 struct bp_location
*bl
;
8480 if (!breakpoint_enabled (b
))
8483 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8485 /* Special types of hardware watchpoints may use more than
8487 i
+= b
->ops
->resources_needed (bl
);
8493 /* Returns the sum the used resources of all hardware watchpoints of
8494 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8495 the sum of the used resources of all hardware watchpoints of other
8496 types _not_ TYPE. */
8499 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8500 enum bptype type
, int *other_type_used
)
8503 struct breakpoint
*b
;
8505 *other_type_used
= 0;
8510 if (!breakpoint_enabled (b
))
8513 if (b
->type
== type
)
8514 i
+= hw_watchpoint_use_count (b
);
8515 else if (is_hardware_watchpoint (b
))
8516 *other_type_used
= 1;
8523 disable_watchpoints_before_interactive_call_start (void)
8525 struct breakpoint
*b
;
8529 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8531 b
->enable_state
= bp_call_disabled
;
8532 update_global_location_list (UGLL_DONT_INSERT
);
8538 enable_watchpoints_after_interactive_call_stop (void)
8540 struct breakpoint
*b
;
8544 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8546 b
->enable_state
= bp_enabled
;
8547 update_global_location_list (UGLL_MAY_INSERT
);
8553 disable_breakpoints_before_startup (void)
8555 current_program_space
->executing_startup
= 1;
8556 update_global_location_list (UGLL_DONT_INSERT
);
8560 enable_breakpoints_after_startup (void)
8562 current_program_space
->executing_startup
= 0;
8563 breakpoint_re_set ();
8566 /* Create a new single-step breakpoint for thread THREAD, with no
8569 static struct breakpoint
*
8570 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8572 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8574 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8575 &momentary_breakpoint_ops
);
8577 b
->disposition
= disp_donttouch
;
8578 b
->frame_id
= null_frame_id
;
8581 gdb_assert (b
->thread
!= 0);
8583 return add_to_breakpoint_chain (std::move (b
));
8586 /* Set a momentary breakpoint of type TYPE at address specified by
8587 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8591 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8592 struct frame_id frame_id
, enum bptype type
)
8594 struct breakpoint
*b
;
8596 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8598 gdb_assert (!frame_id_artificial_p (frame_id
));
8600 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8601 b
->enable_state
= bp_enabled
;
8602 b
->disposition
= disp_donttouch
;
8603 b
->frame_id
= frame_id
;
8605 b
->thread
= inferior_thread ()->global_num
;
8607 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8609 return breakpoint_up (b
);
8612 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8613 The new breakpoint will have type TYPE, use OPS as its
8614 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8616 static struct breakpoint
*
8617 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8619 const struct breakpoint_ops
*ops
,
8622 struct breakpoint
*copy
;
8624 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8625 copy
->loc
= allocate_bp_location (copy
);
8626 set_breakpoint_location_function (copy
->loc
);
8628 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8629 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8630 copy
->loc
->address
= orig
->loc
->address
;
8631 copy
->loc
->section
= orig
->loc
->section
;
8632 copy
->loc
->pspace
= orig
->loc
->pspace
;
8633 copy
->loc
->probe
= orig
->loc
->probe
;
8634 copy
->loc
->line_number
= orig
->loc
->line_number
;
8635 copy
->loc
->symtab
= orig
->loc
->symtab
;
8636 copy
->loc
->enabled
= loc_enabled
;
8637 copy
->frame_id
= orig
->frame_id
;
8638 copy
->thread
= orig
->thread
;
8639 copy
->pspace
= orig
->pspace
;
8641 copy
->enable_state
= bp_enabled
;
8642 copy
->disposition
= disp_donttouch
;
8643 copy
->number
= internal_breakpoint_number
--;
8645 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8649 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8653 clone_momentary_breakpoint (struct breakpoint
*orig
)
8655 /* If there's nothing to clone, then return nothing. */
8659 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8663 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8666 struct symtab_and_line sal
;
8668 sal
= find_pc_line (pc
, 0);
8670 sal
.section
= find_pc_overlay (pc
);
8671 sal
.explicit_pc
= 1;
8673 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8677 /* Tell the user we have just set a breakpoint B. */
8680 mention (struct breakpoint
*b
)
8682 b
->ops
->print_mention (b
);
8683 current_uiout
->text ("\n");
8687 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8689 /* Handle "set breakpoint auto-hw on".
8691 If the explicitly specified breakpoint type is not hardware
8692 breakpoint, check the memory map to see whether the breakpoint
8693 address is in read-only memory.
8695 - location type is not hardware breakpoint, memory is read-only.
8696 We change the type of the location to hardware breakpoint.
8698 - location type is hardware breakpoint, memory is read-write. This
8699 means we've previously made the location hardware one, but then the
8700 memory map changed, so we undo.
8704 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8706 if (automatic_hardware_breakpoints
8707 && bl
->owner
->type
!= bp_hardware_breakpoint
8708 && (bl
->loc_type
== bp_loc_software_breakpoint
8709 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8711 /* When breakpoints are removed, remove_breakpoints will use
8712 location types we've just set here, the only possible problem
8713 is that memory map has changed during running program, but
8714 it's not going to work anyway with current gdb. */
8715 mem_region
*mr
= lookup_mem_region (bl
->address
);
8719 enum bp_loc_type new_type
;
8721 if (mr
->attrib
.mode
!= MEM_RW
)
8722 new_type
= bp_loc_hardware_breakpoint
;
8724 new_type
= bp_loc_software_breakpoint
;
8726 if (new_type
!= bl
->loc_type
)
8728 static bool said
= false;
8730 bl
->loc_type
= new_type
;
8733 fprintf_filtered (gdb_stdout
,
8734 _("Note: automatically using "
8735 "hardware breakpoints for "
8736 "read-only addresses.\n"));
8744 static struct bp_location
*
8745 add_location_to_breakpoint (struct breakpoint
*b
,
8746 const struct symtab_and_line
*sal
)
8748 struct bp_location
*loc
, **tmp
;
8749 CORE_ADDR adjusted_address
;
8750 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8752 if (loc_gdbarch
== NULL
)
8753 loc_gdbarch
= b
->gdbarch
;
8755 /* Adjust the breakpoint's address prior to allocating a location.
8756 Once we call allocate_bp_location(), that mostly uninitialized
8757 location will be placed on the location chain. Adjustment of the
8758 breakpoint may cause target_read_memory() to be called and we do
8759 not want its scan of the location chain to find a breakpoint and
8760 location that's only been partially initialized. */
8761 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8764 /* Sort the locations by their ADDRESS. */
8765 loc
= allocate_bp_location (b
);
8766 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8767 tmp
= &((*tmp
)->next
))
8772 loc
->requested_address
= sal
->pc
;
8773 loc
->address
= adjusted_address
;
8774 loc
->pspace
= sal
->pspace
;
8775 loc
->probe
.prob
= sal
->prob
;
8776 loc
->probe
.objfile
= sal
->objfile
;
8777 gdb_assert (loc
->pspace
!= NULL
);
8778 loc
->section
= sal
->section
;
8779 loc
->gdbarch
= loc_gdbarch
;
8780 loc
->line_number
= sal
->line
;
8781 loc
->symtab
= sal
->symtab
;
8782 loc
->symbol
= sal
->symbol
;
8783 loc
->msymbol
= sal
->msymbol
;
8784 loc
->objfile
= sal
->objfile
;
8786 set_breakpoint_location_function (loc
);
8788 /* While by definition, permanent breakpoints are already present in the
8789 code, we don't mark the location as inserted. Normally one would expect
8790 that GDB could rely on that breakpoint instruction to stop the program,
8791 thus removing the need to insert its own breakpoint, except that executing
8792 the breakpoint instruction can kill the target instead of reporting a
8793 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8794 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8795 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8796 breakpoint be inserted normally results in QEMU knowing about the GDB
8797 breakpoint, and thus trap before the breakpoint instruction is executed.
8798 (If GDB later needs to continue execution past the permanent breakpoint,
8799 it manually increments the PC, thus avoiding executing the breakpoint
8801 if (bp_loc_is_permanent (loc
))
8808 /* Return true if LOC is pointing to a permanent breakpoint,
8809 return false otherwise. */
8812 bp_loc_is_permanent (struct bp_location
*loc
)
8814 gdb_assert (loc
!= NULL
);
8816 /* If we have a non-breakpoint-backed catchpoint or a software
8817 watchpoint, just return 0. We should not attempt to read from
8818 the addresses the locations of these breakpoint types point to.
8819 gdbarch_program_breakpoint_here_p, below, will attempt to read
8821 if (!bl_address_is_meaningful (loc
))
8824 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8825 switch_to_program_space_and_thread (loc
->pspace
);
8826 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8829 /* Build a command list for the dprintf corresponding to the current
8830 settings of the dprintf style options. */
8833 update_dprintf_command_list (struct breakpoint
*b
)
8835 char *dprintf_args
= b
->extra_string
;
8836 char *printf_line
= NULL
;
8841 dprintf_args
= skip_spaces (dprintf_args
);
8843 /* Allow a comma, as it may have terminated a location, but don't
8845 if (*dprintf_args
== ',')
8847 dprintf_args
= skip_spaces (dprintf_args
);
8849 if (*dprintf_args
!= '"')
8850 error (_("Bad format string, missing '\"'."));
8852 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8853 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8854 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8856 if (!dprintf_function
)
8857 error (_("No function supplied for dprintf call"));
8859 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8860 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8865 printf_line
= xstrprintf ("call (void) %s (%s)",
8869 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8871 if (target_can_run_breakpoint_commands ())
8872 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8875 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8876 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8880 internal_error (__FILE__
, __LINE__
,
8881 _("Invalid dprintf style."));
8883 gdb_assert (printf_line
!= NULL
);
8885 /* Manufacture a printf sequence. */
8886 struct command_line
*printf_cmd_line
8887 = new struct command_line (simple_control
, printf_line
);
8888 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8889 command_lines_deleter ()));
8892 /* Update all dprintf commands, making their command lists reflect
8893 current style settings. */
8896 update_dprintf_commands (const char *args
, int from_tty
,
8897 struct cmd_list_element
*c
)
8899 struct breakpoint
*b
;
8903 if (b
->type
== bp_dprintf
)
8904 update_dprintf_command_list (b
);
8908 /* Create a breakpoint with SAL as location. Use LOCATION
8909 as a description of the location, and COND_STRING
8910 as condition expression. If LOCATION is NULL then create an
8911 "address location" from the address in the SAL. */
8914 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8915 gdb::array_view
<const symtab_and_line
> sals
,
8916 event_location_up
&&location
,
8917 gdb::unique_xmalloc_ptr
<char> filter
,
8918 gdb::unique_xmalloc_ptr
<char> cond_string
,
8919 gdb::unique_xmalloc_ptr
<char> extra_string
,
8920 enum bptype type
, enum bpdisp disposition
,
8921 int thread
, int task
, int ignore_count
,
8922 const struct breakpoint_ops
*ops
, int from_tty
,
8923 int enabled
, int internal
, unsigned flags
,
8924 int display_canonical
)
8928 if (type
== bp_hardware_breakpoint
)
8930 int target_resources_ok
;
8932 i
= hw_breakpoint_used_count ();
8933 target_resources_ok
=
8934 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8936 if (target_resources_ok
== 0)
8937 error (_("No hardware breakpoint support in the target."));
8938 else if (target_resources_ok
< 0)
8939 error (_("Hardware breakpoints used exceeds limit."));
8942 gdb_assert (!sals
.empty ());
8944 for (const auto &sal
: sals
)
8946 struct bp_location
*loc
;
8950 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8952 loc_gdbarch
= gdbarch
;
8954 describe_other_breakpoints (loc_gdbarch
,
8955 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8958 if (&sal
== &sals
[0])
8960 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8964 b
->cond_string
= cond_string
.release ();
8965 b
->extra_string
= extra_string
.release ();
8966 b
->ignore_count
= ignore_count
;
8967 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8968 b
->disposition
= disposition
;
8970 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8971 b
->loc
->inserted
= 1;
8973 if (type
== bp_static_tracepoint
)
8975 struct tracepoint
*t
= (struct tracepoint
*) b
;
8976 struct static_tracepoint_marker marker
;
8978 if (strace_marker_p (b
))
8980 /* We already know the marker exists, otherwise, we
8981 wouldn't see a sal for it. */
8983 = &event_location_to_string (b
->location
.get ())[3];
8986 p
= skip_spaces (p
);
8988 endp
= skip_to_space (p
);
8990 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8992 printf_filtered (_("Probed static tracepoint "
8994 t
->static_trace_marker_id
.c_str ());
8996 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8998 t
->static_trace_marker_id
= std::move (marker
.str_id
);
9000 printf_filtered (_("Probed static tracepoint "
9002 t
->static_trace_marker_id
.c_str ());
9005 warning (_("Couldn't determine the static "
9006 "tracepoint marker to probe"));
9013 loc
= add_location_to_breakpoint (b
, &sal
);
9014 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9018 /* Do not set breakpoint locations conditions yet. As locations
9019 are inserted, they get sorted based on their addresses. Let
9020 the list stabilize to have reliable location numbers. */
9022 /* Dynamic printf requires and uses additional arguments on the
9023 command line, otherwise it's an error. */
9024 if (type
== bp_dprintf
)
9026 if (b
->extra_string
)
9027 update_dprintf_command_list (b
);
9029 error (_("Format string required"));
9031 else if (b
->extra_string
)
9032 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9036 /* The order of the locations is now stable. Set the location
9037 condition using the location's number. */
9039 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
9041 if (b
->cond_string
!= nullptr)
9042 set_breakpoint_location_condition (b
->cond_string
, loc
, b
->number
,
9048 b
->display_canonical
= display_canonical
;
9049 if (location
!= NULL
)
9050 b
->location
= std::move (location
);
9052 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9053 b
->filter
= std::move (filter
);
9057 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9058 gdb::array_view
<const symtab_and_line
> sals
,
9059 event_location_up
&&location
,
9060 gdb::unique_xmalloc_ptr
<char> filter
,
9061 gdb::unique_xmalloc_ptr
<char> cond_string
,
9062 gdb::unique_xmalloc_ptr
<char> extra_string
,
9063 enum bptype type
, enum bpdisp disposition
,
9064 int thread
, int task
, int ignore_count
,
9065 const struct breakpoint_ops
*ops
, int from_tty
,
9066 int enabled
, int internal
, unsigned flags
,
9067 int display_canonical
)
9069 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9071 init_breakpoint_sal (b
.get (), gdbarch
,
9072 sals
, std::move (location
),
9074 std::move (cond_string
),
9075 std::move (extra_string
),
9077 thread
, task
, ignore_count
,
9079 enabled
, internal
, flags
,
9082 install_breakpoint (internal
, std::move (b
), 0);
9085 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9086 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9087 value. COND_STRING, if not NULL, specified the condition to be
9088 used for all breakpoints. Essentially the only case where
9089 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9090 function. In that case, it's still not possible to specify
9091 separate conditions for different overloaded functions, so
9092 we take just a single condition string.
9094 NOTE: If the function succeeds, the caller is expected to cleanup
9095 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9096 array contents). If the function fails (error() is called), the
9097 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9098 COND and SALS arrays and each of those arrays contents. */
9101 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9102 struct linespec_result
*canonical
,
9103 gdb::unique_xmalloc_ptr
<char> cond_string
,
9104 gdb::unique_xmalloc_ptr
<char> extra_string
,
9105 enum bptype type
, enum bpdisp disposition
,
9106 int thread
, int task
, int ignore_count
,
9107 const struct breakpoint_ops
*ops
, int from_tty
,
9108 int enabled
, int internal
, unsigned flags
)
9110 if (canonical
->pre_expanded
)
9111 gdb_assert (canonical
->lsals
.size () == 1);
9113 for (const auto &lsal
: canonical
->lsals
)
9115 /* Note that 'location' can be NULL in the case of a plain
9116 'break', without arguments. */
9117 event_location_up location
9118 = (canonical
->location
!= NULL
9119 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9120 gdb::unique_xmalloc_ptr
<char> filter_string
9121 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9123 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9124 std::move (location
),
9125 std::move (filter_string
),
9126 std::move (cond_string
),
9127 std::move (extra_string
),
9129 thread
, task
, ignore_count
, ops
,
9130 from_tty
, enabled
, internal
, flags
,
9131 canonical
->special_display
);
9135 /* Parse LOCATION which is assumed to be a SAL specification possibly
9136 followed by conditionals. On return, SALS contains an array of SAL
9137 addresses found. LOCATION points to the end of the SAL (for
9138 linespec locations).
9140 The array and the line spec strings are allocated on the heap, it is
9141 the caller's responsibility to free them. */
9144 parse_breakpoint_sals (struct event_location
*location
,
9145 struct linespec_result
*canonical
)
9147 struct symtab_and_line cursal
;
9149 if (event_location_type (location
) == LINESPEC_LOCATION
)
9151 const char *spec
= get_linespec_location (location
)->spec_string
;
9155 /* The last displayed codepoint, if it's valid, is our default
9156 breakpoint address. */
9157 if (last_displayed_sal_is_valid ())
9159 /* Set sal's pspace, pc, symtab, and line to the values
9160 corresponding to the last call to print_frame_info.
9161 Be sure to reinitialize LINE with NOTCURRENT == 0
9162 as the breakpoint line number is inappropriate otherwise.
9163 find_pc_line would adjust PC, re-set it back. */
9164 symtab_and_line sal
= get_last_displayed_sal ();
9165 CORE_ADDR pc
= sal
.pc
;
9167 sal
= find_pc_line (pc
, 0);
9169 /* "break" without arguments is equivalent to "break *PC"
9170 where PC is the last displayed codepoint's address. So
9171 make sure to set sal.explicit_pc to prevent GDB from
9172 trying to expand the list of sals to include all other
9173 instances with the same symtab and line. */
9175 sal
.explicit_pc
= 1;
9177 struct linespec_sals lsal
;
9179 lsal
.canonical
= NULL
;
9181 canonical
->lsals
.push_back (std::move (lsal
));
9185 error (_("No default breakpoint address now."));
9189 /* Force almost all breakpoints to be in terms of the
9190 current_source_symtab (which is decode_line_1's default).
9191 This should produce the results we want almost all of the
9192 time while leaving default_breakpoint_* alone.
9194 ObjC: However, don't match an Objective-C method name which
9195 may have a '+' or '-' succeeded by a '['. */
9196 cursal
= get_current_source_symtab_and_line ();
9197 if (last_displayed_sal_is_valid ())
9199 const char *spec
= NULL
;
9201 if (event_location_type (location
) == LINESPEC_LOCATION
)
9202 spec
= get_linespec_location (location
)->spec_string
;
9206 && strchr ("+-", spec
[0]) != NULL
9209 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9210 get_last_displayed_symtab (),
9211 get_last_displayed_line (),
9212 canonical
, NULL
, NULL
);
9217 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9218 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9222 /* Convert each SAL into a real PC. Verify that the PC can be
9223 inserted as a breakpoint. If it can't throw an error. */
9226 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9228 for (auto &sal
: sals
)
9229 resolve_sal_pc (&sal
);
9232 /* Fast tracepoints may have restrictions on valid locations. For
9233 instance, a fast tracepoint using a jump instead of a trap will
9234 likely have to overwrite more bytes than a trap would, and so can
9235 only be placed where the instruction is longer than the jump, or a
9236 multi-instruction sequence does not have a jump into the middle of
9240 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9241 gdb::array_view
<const symtab_and_line
> sals
)
9243 for (const auto &sal
: sals
)
9245 struct gdbarch
*sarch
;
9247 sarch
= get_sal_arch (sal
);
9248 /* We fall back to GDBARCH if there is no architecture
9249 associated with SAL. */
9253 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9254 error (_("May not have a fast tracepoint at %s%s"),
9255 paddress (sarch
, sal
.pc
), msg
.c_str ());
9259 /* Given TOK, a string specification of condition and thread, as
9260 accepted by the 'break' command, extract the condition
9261 string and thread number and set *COND_STRING and *THREAD.
9262 PC identifies the context at which the condition should be parsed.
9263 If no condition is found, *COND_STRING is set to NULL.
9264 If no thread is found, *THREAD is set to -1. */
9267 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9268 char **cond_string
, int *thread
, int *task
,
9271 *cond_string
= NULL
;
9279 const char *end_tok
;
9281 const char *cond_start
= NULL
;
9282 const char *cond_end
= NULL
;
9284 tok
= skip_spaces (tok
);
9286 if ((*tok
== '"' || *tok
== ',') && rest
)
9288 *rest
= savestring (tok
, strlen (tok
));
9292 end_tok
= skip_to_space (tok
);
9294 toklen
= end_tok
- tok
;
9296 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9298 tok
= cond_start
= end_tok
+ 1;
9301 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9303 catch (const gdb_exception_error
&)
9308 tok
= tok
+ strlen (tok
);
9311 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9313 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
9318 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9321 struct thread_info
*thr
;
9324 thr
= parse_thread_id (tok
, &tmptok
);
9326 error (_("Junk after thread keyword."));
9327 *thread
= thr
->global_num
;
9330 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9335 *task
= strtol (tok
, &tmptok
, 0);
9337 error (_("Junk after task keyword."));
9338 if (!valid_task_id (*task
))
9339 error (_("Unknown task %d."), *task
);
9344 *rest
= savestring (tok
, strlen (tok
));
9348 error (_("Junk at end of arguments."));
9352 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
9353 succeeds. The parsed values are written to COND_STRING, THREAD,
9354 TASK, and REST. See the comment of 'find_condition_and_thread'
9355 for the description of these parameters and INPUT. */
9358 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
9359 const char *input
, char **cond_string
,
9360 int *thread
, int *task
, char **rest
)
9362 int num_failures
= 0;
9363 for (auto &sal
: sals
)
9365 char *cond
= nullptr;
9368 char *remaining
= nullptr;
9370 /* Here we want to parse 'arg' to separate condition from thread
9371 number. But because parsing happens in a context and the
9372 contexts of sals might be different, try each until there is
9373 success. Finding one successful parse is sufficient for our
9374 goal. When setting the breakpoint we'll re-parse the
9375 condition in the context of each sal. */
9378 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
9379 &task_id
, &remaining
);
9380 *cond_string
= cond
;
9381 *thread
= thread_id
;
9386 catch (const gdb_exception_error
&e
)
9389 /* If no sal remains, do not continue. */
9390 if (num_failures
== sals
.size ())
9396 /* Decode a static tracepoint marker spec. */
9398 static std::vector
<symtab_and_line
>
9399 decode_static_tracepoint_spec (const char **arg_p
)
9401 const char *p
= &(*arg_p
)[3];
9404 p
= skip_spaces (p
);
9406 endp
= skip_to_space (p
);
9408 std::string
marker_str (p
, endp
- p
);
9410 std::vector
<static_tracepoint_marker
> markers
9411 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9412 if (markers
.empty ())
9413 error (_("No known static tracepoint marker named %s"),
9414 marker_str
.c_str ());
9416 std::vector
<symtab_and_line
> sals
;
9417 sals
.reserve (markers
.size ());
9419 for (const static_tracepoint_marker
&marker
: markers
)
9421 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9422 sal
.pc
= marker
.address
;
9423 sals
.push_back (sal
);
9430 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9431 according to IS_TRACEPOINT. */
9433 static const struct breakpoint_ops
*
9434 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
9439 if (location_type
== PROBE_LOCATION
)
9440 return &tracepoint_probe_breakpoint_ops
;
9442 return &tracepoint_breakpoint_ops
;
9446 if (location_type
== PROBE_LOCATION
)
9447 return &bkpt_probe_breakpoint_ops
;
9449 return &bkpt_breakpoint_ops
;
9453 /* See breakpoint.h. */
9455 const struct breakpoint_ops
*
9456 breakpoint_ops_for_event_location (const struct event_location
*location
,
9459 if (location
!= nullptr)
9460 return breakpoint_ops_for_event_location_type
9461 (event_location_type (location
), is_tracepoint
);
9462 return is_tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
9465 /* See breakpoint.h. */
9468 create_breakpoint (struct gdbarch
*gdbarch
,
9469 struct event_location
*location
,
9470 const char *cond_string
,
9471 int thread
, const char *extra_string
,
9472 bool force_condition
, int parse_extra
,
9473 int tempflag
, enum bptype type_wanted
,
9475 enum auto_boolean pending_break_support
,
9476 const struct breakpoint_ops
*ops
,
9477 int from_tty
, int enabled
, int internal
,
9480 struct linespec_result canonical
;
9483 int prev_bkpt_count
= breakpoint_count
;
9485 gdb_assert (ops
!= NULL
);
9487 /* If extra_string isn't useful, set it to NULL. */
9488 if (extra_string
!= NULL
&& *extra_string
== '\0')
9489 extra_string
= NULL
;
9493 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9495 catch (const gdb_exception_error
&e
)
9497 /* If caller is interested in rc value from parse, set
9499 if (e
.error
== NOT_FOUND_ERROR
)
9501 /* If pending breakpoint support is turned off, throw
9504 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9507 exception_print (gdb_stderr
, e
);
9509 /* If pending breakpoint support is auto query and the user
9510 selects no, then simply return the error code. */
9511 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9512 && !nquery (_("Make %s pending on future shared library load? "),
9513 bptype_string (type_wanted
)))
9516 /* At this point, either the user was queried about setting
9517 a pending breakpoint and selected yes, or pending
9518 breakpoint behavior is on and thus a pending breakpoint
9519 is defaulted on behalf of the user. */
9526 if (!pending
&& canonical
.lsals
.empty ())
9529 /* Resolve all line numbers to PC's and verify that the addresses
9530 are ok for the target. */
9533 for (auto &lsal
: canonical
.lsals
)
9534 breakpoint_sals_to_pc (lsal
.sals
);
9537 /* Fast tracepoints may have additional restrictions on location. */
9538 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9540 for (const auto &lsal
: canonical
.lsals
)
9541 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9544 /* Verify that condition can be parsed, before setting any
9545 breakpoints. Allocate a separate condition expression for each
9549 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9550 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9557 const linespec_sals
&lsal
= canonical
.lsals
[0];
9559 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9560 &cond
, &thread
, &task
, &rest
);
9561 cond_string_copy
.reset (cond
);
9562 extra_string_copy
.reset (rest
);
9566 if (type_wanted
!= bp_dprintf
9567 && extra_string
!= NULL
&& *extra_string
!= '\0')
9568 error (_("Garbage '%s' at end of location"), extra_string
);
9570 /* Check the validity of the condition. We should error out
9571 if the condition is invalid at all of the locations and
9572 if it is not forced. In the PARSE_EXTRA case above, this
9573 check is done when parsing the EXTRA_STRING. */
9574 if (cond_string
!= nullptr && !force_condition
)
9576 int num_failures
= 0;
9577 const linespec_sals
&lsal
= canonical
.lsals
[0];
9578 for (const auto &sal
: lsal
.sals
)
9580 const char *cond
= cond_string
;
9583 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
9584 /* One success is sufficient to keep going. */
9587 catch (const gdb_exception_error
&)
9590 /* If this is the last sal, error out. */
9591 if (num_failures
== lsal
.sals
.size ())
9597 /* Create a private copy of condition string. */
9599 cond_string_copy
.reset (xstrdup (cond_string
));
9600 /* Create a private copy of any extra string. */
9602 extra_string_copy
.reset (xstrdup (extra_string
));
9605 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9606 std::move (cond_string_copy
),
9607 std::move (extra_string_copy
),
9609 tempflag
? disp_del
: disp_donttouch
,
9610 thread
, task
, ignore_count
, ops
,
9611 from_tty
, enabled
, internal
, flags
);
9615 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9617 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9618 b
->location
= copy_event_location (location
);
9621 b
->cond_string
= NULL
;
9624 /* Create a private copy of condition string. */
9625 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9629 /* Create a private copy of any extra string. */
9630 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9631 b
->ignore_count
= ignore_count
;
9632 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9633 b
->condition_not_parsed
= 1;
9634 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9635 if ((type_wanted
!= bp_breakpoint
9636 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9637 b
->pspace
= current_program_space
;
9639 install_breakpoint (internal
, std::move (b
), 0);
9642 if (canonical
.lsals
.size () > 1)
9644 warning (_("Multiple breakpoints were set.\nUse the "
9645 "\"delete\" command to delete unwanted breakpoints."));
9646 prev_breakpoint_count
= prev_bkpt_count
;
9649 update_global_location_list (UGLL_MAY_INSERT
);
9654 /* Set a breakpoint.
9655 ARG is a string describing breakpoint address,
9656 condition, and thread.
9657 FLAG specifies if a breakpoint is hardware on,
9658 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9662 break_command_1 (const char *arg
, int flag
, int from_tty
)
9664 int tempflag
= flag
& BP_TEMPFLAG
;
9665 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9666 ? bp_hardware_breakpoint
9669 event_location_up location
= string_to_event_location (&arg
, current_language
);
9670 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9671 (location
.get (), false /* is_tracepoint */);
9673 create_breakpoint (get_current_arch (),
9675 NULL
, 0, arg
, false, 1 /* parse arg */,
9676 tempflag
, type_wanted
,
9677 0 /* Ignore count */,
9678 pending_break_support
,
9686 /* Helper function for break_command_1 and disassemble_command. */
9689 resolve_sal_pc (struct symtab_and_line
*sal
)
9693 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9695 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9696 error (_("No line %d in file \"%s\"."),
9697 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9700 /* If this SAL corresponds to a breakpoint inserted using a line
9701 number, then skip the function prologue if necessary. */
9702 if (sal
->explicit_line
)
9703 skip_prologue_sal (sal
);
9706 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9708 const struct blockvector
*bv
;
9709 const struct block
*b
;
9712 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9713 SYMTAB_COMPUNIT (sal
->symtab
));
9716 sym
= block_linkage_function (b
);
9719 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9720 sal
->section
= sym
->obj_section (SYMTAB_OBJFILE (sal
->symtab
));
9724 /* It really is worthwhile to have the section, so we'll
9725 just have to look harder. This case can be executed
9726 if we have line numbers but no functions (as can
9727 happen in assembly source). */
9729 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9730 switch_to_program_space_and_thread (sal
->pspace
);
9732 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9734 sal
->section
= msym
.obj_section ();
9741 break_command (const char *arg
, int from_tty
)
9743 break_command_1 (arg
, 0, from_tty
);
9747 tbreak_command (const char *arg
, int from_tty
)
9749 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9753 hbreak_command (const char *arg
, int from_tty
)
9755 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9759 thbreak_command (const char *arg
, int from_tty
)
9761 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9765 stop_command (const char *arg
, int from_tty
)
9767 printf_filtered (_("Specify the type of breakpoint to set.\n\
9768 Usage: stop in <function | address>\n\
9769 stop at <line>\n"));
9773 stopin_command (const char *arg
, int from_tty
)
9779 else if (*arg
!= '*')
9781 const char *argptr
= arg
;
9784 /* Look for a ':'. If this is a line number specification, then
9785 say it is bad, otherwise, it should be an address or
9786 function/method name. */
9787 while (*argptr
&& !hasColon
)
9789 hasColon
= (*argptr
== ':');
9794 badInput
= (*argptr
!= ':'); /* Not a class::method */
9796 badInput
= isdigit (*arg
); /* a simple line number */
9800 printf_filtered (_("Usage: stop in <function | address>\n"));
9802 break_command_1 (arg
, 0, from_tty
);
9806 stopat_command (const char *arg
, int from_tty
)
9810 if (arg
== NULL
|| *arg
== '*') /* no line number */
9814 const char *argptr
= arg
;
9817 /* Look for a ':'. If there is a '::' then get out, otherwise
9818 it is probably a line number. */
9819 while (*argptr
&& !hasColon
)
9821 hasColon
= (*argptr
== ':');
9826 badInput
= (*argptr
== ':'); /* we have class::method */
9828 badInput
= !isdigit (*arg
); /* not a line number */
9832 printf_filtered (_("Usage: stop at LINE\n"));
9834 break_command_1 (arg
, 0, from_tty
);
9837 /* The dynamic printf command is mostly like a regular breakpoint, but
9838 with a prewired command list consisting of a single output command,
9839 built from extra arguments supplied on the dprintf command
9843 dprintf_command (const char *arg
, int from_tty
)
9845 event_location_up location
= string_to_event_location (&arg
, current_language
);
9847 /* If non-NULL, ARG should have been advanced past the location;
9848 the next character must be ','. */
9851 if (arg
[0] != ',' || arg
[1] == '\0')
9852 error (_("Format string required"));
9855 /* Skip the comma. */
9860 create_breakpoint (get_current_arch (),
9862 NULL
, 0, arg
, false, 1 /* parse arg */,
9864 0 /* Ignore count */,
9865 pending_break_support
,
9866 &dprintf_breakpoint_ops
,
9874 agent_printf_command (const char *arg
, int from_tty
)
9876 error (_("May only run agent-printf on the target"));
9879 /* Implement the "breakpoint_hit" breakpoint_ops method for
9880 ranged breakpoints. */
9883 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9884 const address_space
*aspace
,
9886 const struct target_waitstatus
*ws
)
9888 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9889 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9892 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9893 bl
->length
, aspace
, bp_addr
);
9896 /* Implement the "resources_needed" breakpoint_ops method for
9897 ranged breakpoints. */
9900 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9902 return target_ranged_break_num_registers ();
9905 /* Implement the "print_it" breakpoint_ops method for
9906 ranged breakpoints. */
9908 static enum print_stop_action
9909 print_it_ranged_breakpoint (bpstat bs
)
9911 struct breakpoint
*b
= bs
->breakpoint_at
;
9912 struct bp_location
*bl
= b
->loc
;
9913 struct ui_out
*uiout
= current_uiout
;
9915 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9917 /* Ranged breakpoints have only one location. */
9918 gdb_assert (bl
&& bl
->next
== NULL
);
9920 annotate_breakpoint (b
->number
);
9922 maybe_print_thread_hit_breakpoint (uiout
);
9924 if (b
->disposition
== disp_del
)
9925 uiout
->text ("Temporary ranged breakpoint ");
9927 uiout
->text ("Ranged breakpoint ");
9928 if (uiout
->is_mi_like_p ())
9930 uiout
->field_string ("reason",
9931 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9932 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9934 uiout
->field_signed ("bkptno", b
->number
);
9937 return PRINT_SRC_AND_LOC
;
9940 /* Implement the "print_one" breakpoint_ops method for
9941 ranged breakpoints. */
9944 print_one_ranged_breakpoint (struct breakpoint
*b
,
9945 struct bp_location
**last_loc
)
9947 struct bp_location
*bl
= b
->loc
;
9948 struct value_print_options opts
;
9949 struct ui_out
*uiout
= current_uiout
;
9951 /* Ranged breakpoints have only one location. */
9952 gdb_assert (bl
&& bl
->next
== NULL
);
9954 get_user_print_options (&opts
);
9956 if (opts
.addressprint
)
9957 /* We don't print the address range here, it will be printed later
9958 by print_one_detail_ranged_breakpoint. */
9959 uiout
->field_skip ("addr");
9961 print_breakpoint_location (b
, bl
);
9965 /* Implement the "print_one_detail" breakpoint_ops method for
9966 ranged breakpoints. */
9969 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9970 struct ui_out
*uiout
)
9972 CORE_ADDR address_start
, address_end
;
9973 struct bp_location
*bl
= b
->loc
;
9978 address_start
= bl
->address
;
9979 address_end
= address_start
+ bl
->length
- 1;
9981 uiout
->text ("\taddress range: ");
9982 stb
.printf ("[%s, %s]",
9983 print_core_address (bl
->gdbarch
, address_start
),
9984 print_core_address (bl
->gdbarch
, address_end
));
9985 uiout
->field_stream ("addr", stb
);
9989 /* Implement the "print_mention" breakpoint_ops method for
9990 ranged breakpoints. */
9993 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9995 struct bp_location
*bl
= b
->loc
;
9996 struct ui_out
*uiout
= current_uiout
;
9999 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10001 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10002 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10003 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10006 /* Implement the "print_recreate" breakpoint_ops method for
10007 ranged breakpoints. */
10010 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10012 fprintf_unfiltered (fp
, "break-range %s, %s",
10013 event_location_to_string (b
->location
.get ()),
10014 event_location_to_string (b
->location_range_end
.get ()));
10015 print_recreate_thread (b
, fp
);
10018 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10020 static struct breakpoint_ops ranged_breakpoint_ops
;
10022 /* Find the address where the end of the breakpoint range should be
10023 placed, given the SAL of the end of the range. This is so that if
10024 the user provides a line number, the end of the range is set to the
10025 last instruction of the given line. */
10028 find_breakpoint_range_end (struct symtab_and_line sal
)
10032 /* If the user provided a PC value, use it. Otherwise,
10033 find the address of the end of the given location. */
10034 if (sal
.explicit_pc
)
10041 ret
= find_line_pc_range (sal
, &start
, &end
);
10043 error (_("Could not find location of the end of the range."));
10045 /* find_line_pc_range returns the start of the next line. */
10052 /* Implement the "break-range" CLI command. */
10055 break_range_command (const char *arg
, int from_tty
)
10057 const char *arg_start
;
10058 struct linespec_result canonical_start
, canonical_end
;
10059 int bp_count
, can_use_bp
, length
;
10061 struct breakpoint
*b
;
10063 /* We don't support software ranged breakpoints. */
10064 if (target_ranged_break_num_registers () < 0)
10065 error (_("This target does not support hardware ranged breakpoints."));
10067 bp_count
= hw_breakpoint_used_count ();
10068 bp_count
+= target_ranged_break_num_registers ();
10069 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10071 if (can_use_bp
< 0)
10072 error (_("Hardware breakpoints used exceeds limit."));
10074 arg
= skip_spaces (arg
);
10075 if (arg
== NULL
|| arg
[0] == '\0')
10076 error(_("No address range specified."));
10079 event_location_up start_location
= string_to_event_location (&arg
,
10081 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10084 error (_("Too few arguments."));
10085 else if (canonical_start
.lsals
.empty ())
10086 error (_("Could not find location of the beginning of the range."));
10088 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
10090 if (canonical_start
.lsals
.size () > 1
10091 || lsal_start
.sals
.size () != 1)
10092 error (_("Cannot create a ranged breakpoint with multiple locations."));
10094 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
10095 std::string
addr_string_start (arg_start
, arg
- arg_start
);
10097 arg
++; /* Skip the comma. */
10098 arg
= skip_spaces (arg
);
10100 /* Parse the end location. */
10104 /* We call decode_line_full directly here instead of using
10105 parse_breakpoint_sals because we need to specify the start location's
10106 symtab and line as the default symtab and line for the end of the
10107 range. This makes it possible to have ranges like "foo.c:27, +14",
10108 where +14 means 14 lines from the start location. */
10109 event_location_up end_location
= string_to_event_location (&arg
,
10111 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10112 sal_start
.symtab
, sal_start
.line
,
10113 &canonical_end
, NULL
, NULL
);
10115 if (canonical_end
.lsals
.empty ())
10116 error (_("Could not find location of the end of the range."));
10118 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10119 if (canonical_end
.lsals
.size () > 1
10120 || lsal_end
.sals
.size () != 1)
10121 error (_("Cannot create a ranged breakpoint with multiple locations."));
10123 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10125 end
= find_breakpoint_range_end (sal_end
);
10126 if (sal_start
.pc
> end
)
10127 error (_("Invalid address range, end precedes start."));
10129 length
= end
- sal_start
.pc
+ 1;
10131 /* Length overflowed. */
10132 error (_("Address range too large."));
10133 else if (length
== 1)
10135 /* This range is simple enough to be handled by
10136 the `hbreak' command. */
10137 hbreak_command (&addr_string_start
[0], 1);
10142 /* Now set up the breakpoint. */
10143 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10144 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10145 set_breakpoint_count (breakpoint_count
+ 1);
10146 b
->number
= breakpoint_count
;
10147 b
->disposition
= disp_donttouch
;
10148 b
->location
= std::move (start_location
);
10149 b
->location_range_end
= std::move (end_location
);
10150 b
->loc
->length
= length
;
10153 gdb::observers::breakpoint_created
.notify (b
);
10154 update_global_location_list (UGLL_MAY_INSERT
);
10157 /* Return non-zero if EXP is verified as constant. Returned zero
10158 means EXP is variable. Also the constant detection may fail for
10159 some constant expressions and in such case still falsely return
10163 watchpoint_exp_is_const (const struct expression
*exp
)
10165 return exp
->op
->constant_p ();
10168 /* Watchpoint destructor. */
10170 watchpoint::~watchpoint ()
10172 xfree (this->exp_string
);
10173 xfree (this->exp_string_reparse
);
10176 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10179 re_set_watchpoint (struct breakpoint
*b
)
10181 struct watchpoint
*w
= (struct watchpoint
*) b
;
10183 /* Watchpoint can be either on expression using entirely global
10184 variables, or it can be on local variables.
10186 Watchpoints of the first kind are never auto-deleted, and even
10187 persist across program restarts. Since they can use variables
10188 from shared libraries, we need to reparse expression as libraries
10189 are loaded and unloaded.
10191 Watchpoints on local variables can also change meaning as result
10192 of solib event. For example, if a watchpoint uses both a local
10193 and a global variables in expression, it's a local watchpoint,
10194 but unloading of a shared library will make the expression
10195 invalid. This is not a very common use case, but we still
10196 re-evaluate expression, to avoid surprises to the user.
10198 Note that for local watchpoints, we re-evaluate it only if
10199 watchpoints frame id is still valid. If it's not, it means the
10200 watchpoint is out of scope and will be deleted soon. In fact,
10201 I'm not sure we'll ever be called in this case.
10203 If a local watchpoint's frame id is still valid, then
10204 w->exp_valid_block is likewise valid, and we can safely use it.
10206 Don't do anything about disabled watchpoints, since they will be
10207 reevaluated again when enabled. */
10208 update_watchpoint (w
, 1 /* reparse */);
10211 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10214 insert_watchpoint (struct bp_location
*bl
)
10216 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10217 int length
= w
->exact
? 1 : bl
->length
;
10219 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10220 w
->cond_exp
.get ());
10223 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10226 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10228 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10229 int length
= w
->exact
? 1 : bl
->length
;
10231 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10232 w
->cond_exp
.get ());
10236 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10237 const address_space
*aspace
, CORE_ADDR bp_addr
,
10238 const struct target_waitstatus
*ws
)
10240 struct breakpoint
*b
= bl
->owner
;
10241 struct watchpoint
*w
= (struct watchpoint
*) b
;
10243 /* Continuable hardware watchpoints are treated as non-existent if the
10244 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10245 some data address). Otherwise gdb won't stop on a break instruction
10246 in the code (not from a breakpoint) when a hardware watchpoint has
10247 been defined. Also skip watchpoints which we know did not trigger
10248 (did not match the data address). */
10249 if (is_hardware_watchpoint (b
)
10250 && w
->watchpoint_triggered
== watch_triggered_no
)
10257 check_status_watchpoint (bpstat bs
)
10259 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10261 bpstat_check_watchpoint (bs
);
10264 /* Implement the "resources_needed" breakpoint_ops method for
10265 hardware watchpoints. */
10268 resources_needed_watchpoint (const struct bp_location
*bl
)
10270 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10271 int length
= w
->exact
? 1 : bl
->length
;
10273 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10276 /* Implement the "works_in_software_mode" breakpoint_ops method for
10277 hardware watchpoints. */
10280 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10282 /* Read and access watchpoints only work with hardware support. */
10283 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10286 static enum print_stop_action
10287 print_it_watchpoint (bpstat bs
)
10289 struct breakpoint
*b
;
10290 enum print_stop_action result
;
10291 struct watchpoint
*w
;
10292 struct ui_out
*uiout
= current_uiout
;
10294 gdb_assert (bs
->bp_location_at
!= NULL
);
10296 b
= bs
->breakpoint_at
;
10297 w
= (struct watchpoint
*) b
;
10299 annotate_watchpoint (b
->number
);
10300 maybe_print_thread_hit_breakpoint (uiout
);
10304 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10307 case bp_watchpoint
:
10308 case bp_hardware_watchpoint
:
10309 if (uiout
->is_mi_like_p ())
10310 uiout
->field_string
10311 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10313 tuple_emitter
.emplace (uiout
, "value");
10314 uiout
->text ("\nOld value = ");
10315 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10316 uiout
->field_stream ("old", stb
);
10317 uiout
->text ("\nNew value = ");
10318 watchpoint_value_print (w
->val
.get (), &stb
);
10319 uiout
->field_stream ("new", stb
);
10320 uiout
->text ("\n");
10321 /* More than one watchpoint may have been triggered. */
10322 result
= PRINT_UNKNOWN
;
10325 case bp_read_watchpoint
:
10326 if (uiout
->is_mi_like_p ())
10327 uiout
->field_string
10328 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10330 tuple_emitter
.emplace (uiout
, "value");
10331 uiout
->text ("\nValue = ");
10332 watchpoint_value_print (w
->val
.get (), &stb
);
10333 uiout
->field_stream ("value", stb
);
10334 uiout
->text ("\n");
10335 result
= PRINT_UNKNOWN
;
10338 case bp_access_watchpoint
:
10339 if (bs
->old_val
!= NULL
)
10341 if (uiout
->is_mi_like_p ())
10342 uiout
->field_string
10344 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10346 tuple_emitter
.emplace (uiout
, "value");
10347 uiout
->text ("\nOld value = ");
10348 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10349 uiout
->field_stream ("old", stb
);
10350 uiout
->text ("\nNew value = ");
10355 if (uiout
->is_mi_like_p ())
10356 uiout
->field_string
10358 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10359 tuple_emitter
.emplace (uiout
, "value");
10360 uiout
->text ("\nValue = ");
10362 watchpoint_value_print (w
->val
.get (), &stb
);
10363 uiout
->field_stream ("new", stb
);
10364 uiout
->text ("\n");
10365 result
= PRINT_UNKNOWN
;
10368 result
= PRINT_UNKNOWN
;
10374 /* Implement the "print_mention" breakpoint_ops method for hardware
10378 print_mention_watchpoint (struct breakpoint
*b
)
10380 struct watchpoint
*w
= (struct watchpoint
*) b
;
10381 struct ui_out
*uiout
= current_uiout
;
10382 const char *tuple_name
;
10386 case bp_watchpoint
:
10387 uiout
->text ("Watchpoint ");
10388 tuple_name
= "wpt";
10390 case bp_hardware_watchpoint
:
10391 uiout
->text ("Hardware watchpoint ");
10392 tuple_name
= "wpt";
10394 case bp_read_watchpoint
:
10395 uiout
->text ("Hardware read watchpoint ");
10396 tuple_name
= "hw-rwpt";
10398 case bp_access_watchpoint
:
10399 uiout
->text ("Hardware access (read/write) watchpoint ");
10400 tuple_name
= "hw-awpt";
10403 internal_error (__FILE__
, __LINE__
,
10404 _("Invalid hardware watchpoint type."));
10407 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10408 uiout
->field_signed ("number", b
->number
);
10409 uiout
->text (": ");
10410 uiout
->field_string ("exp", w
->exp_string
);
10413 /* Implement the "print_recreate" breakpoint_ops method for
10417 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10419 struct watchpoint
*w
= (struct watchpoint
*) b
;
10423 case bp_watchpoint
:
10424 case bp_hardware_watchpoint
:
10425 fprintf_unfiltered (fp
, "watch");
10427 case bp_read_watchpoint
:
10428 fprintf_unfiltered (fp
, "rwatch");
10430 case bp_access_watchpoint
:
10431 fprintf_unfiltered (fp
, "awatch");
10434 internal_error (__FILE__
, __LINE__
,
10435 _("Invalid watchpoint type."));
10438 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10439 print_recreate_thread (b
, fp
);
10442 /* Implement the "explains_signal" breakpoint_ops method for
10446 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10448 /* A software watchpoint cannot cause a signal other than
10449 GDB_SIGNAL_TRAP. */
10450 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10456 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10458 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10460 /* Implement the "insert" breakpoint_ops method for
10461 masked hardware watchpoints. */
10464 insert_masked_watchpoint (struct bp_location
*bl
)
10466 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10468 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10469 bl
->watchpoint_type
);
10472 /* Implement the "remove" breakpoint_ops method for
10473 masked hardware watchpoints. */
10476 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10478 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10480 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10481 bl
->watchpoint_type
);
10484 /* Implement the "resources_needed" breakpoint_ops method for
10485 masked hardware watchpoints. */
10488 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10490 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10492 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10495 /* Implement the "works_in_software_mode" breakpoint_ops method for
10496 masked hardware watchpoints. */
10499 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10504 /* Implement the "print_it" breakpoint_ops method for
10505 masked hardware watchpoints. */
10507 static enum print_stop_action
10508 print_it_masked_watchpoint (bpstat bs
)
10510 struct breakpoint
*b
= bs
->breakpoint_at
;
10511 struct ui_out
*uiout
= current_uiout
;
10513 /* Masked watchpoints have only one location. */
10514 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10516 annotate_watchpoint (b
->number
);
10517 maybe_print_thread_hit_breakpoint (uiout
);
10521 case bp_hardware_watchpoint
:
10522 if (uiout
->is_mi_like_p ())
10523 uiout
->field_string
10524 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10527 case bp_read_watchpoint
:
10528 if (uiout
->is_mi_like_p ())
10529 uiout
->field_string
10530 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10533 case bp_access_watchpoint
:
10534 if (uiout
->is_mi_like_p ())
10535 uiout
->field_string
10537 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10540 internal_error (__FILE__
, __LINE__
,
10541 _("Invalid hardware watchpoint type."));
10545 uiout
->text (_("\n\
10546 Check the underlying instruction at PC for the memory\n\
10547 address and value which triggered this watchpoint.\n"));
10548 uiout
->text ("\n");
10550 /* More than one watchpoint may have been triggered. */
10551 return PRINT_UNKNOWN
;
10554 /* Implement the "print_one_detail" breakpoint_ops method for
10555 masked hardware watchpoints. */
10558 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10559 struct ui_out
*uiout
)
10561 struct watchpoint
*w
= (struct watchpoint
*) b
;
10563 /* Masked watchpoints have only one location. */
10564 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10566 uiout
->text ("\tmask ");
10567 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10568 uiout
->text ("\n");
10571 /* Implement the "print_mention" breakpoint_ops method for
10572 masked hardware watchpoints. */
10575 print_mention_masked_watchpoint (struct breakpoint
*b
)
10577 struct watchpoint
*w
= (struct watchpoint
*) b
;
10578 struct ui_out
*uiout
= current_uiout
;
10579 const char *tuple_name
;
10583 case bp_hardware_watchpoint
:
10584 uiout
->text ("Masked hardware watchpoint ");
10585 tuple_name
= "wpt";
10587 case bp_read_watchpoint
:
10588 uiout
->text ("Masked hardware read watchpoint ");
10589 tuple_name
= "hw-rwpt";
10591 case bp_access_watchpoint
:
10592 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10593 tuple_name
= "hw-awpt";
10596 internal_error (__FILE__
, __LINE__
,
10597 _("Invalid hardware watchpoint type."));
10600 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10601 uiout
->field_signed ("number", b
->number
);
10602 uiout
->text (": ");
10603 uiout
->field_string ("exp", w
->exp_string
);
10606 /* Implement the "print_recreate" breakpoint_ops method for
10607 masked hardware watchpoints. */
10610 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10612 struct watchpoint
*w
= (struct watchpoint
*) b
;
10616 case bp_hardware_watchpoint
:
10617 fprintf_unfiltered (fp
, "watch");
10619 case bp_read_watchpoint
:
10620 fprintf_unfiltered (fp
, "rwatch");
10622 case bp_access_watchpoint
:
10623 fprintf_unfiltered (fp
, "awatch");
10626 internal_error (__FILE__
, __LINE__
,
10627 _("Invalid hardware watchpoint type."));
10630 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
,
10631 phex (w
->hw_wp_mask
, sizeof (CORE_ADDR
)));
10632 print_recreate_thread (b
, fp
);
10635 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10637 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10639 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10642 is_masked_watchpoint (const struct breakpoint
*b
)
10644 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10647 /* accessflag: hw_write: watch write,
10648 hw_read: watch read,
10649 hw_access: watch access (read or write) */
10651 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10652 bool just_location
, bool internal
)
10654 struct breakpoint
*scope_breakpoint
= NULL
;
10655 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10656 struct value
*result
;
10657 int saved_bitpos
= 0, saved_bitsize
= 0;
10658 const char *exp_start
= NULL
;
10659 const char *exp_end
= NULL
;
10660 const char *tok
, *end_tok
;
10662 const char *cond_start
= NULL
;
10663 const char *cond_end
= NULL
;
10664 enum bptype bp_type
;
10666 /* Flag to indicate whether we are going to use masks for
10667 the hardware watchpoint. */
10668 bool use_mask
= false;
10669 CORE_ADDR mask
= 0;
10671 /* Make sure that we actually have parameters to parse. */
10672 if (arg
!= NULL
&& arg
[0] != '\0')
10674 const char *value_start
;
10676 exp_end
= arg
+ strlen (arg
);
10678 /* Look for "parameter value" pairs at the end
10679 of the arguments string. */
10680 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10682 /* Skip whitespace at the end of the argument list. */
10683 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10686 /* Find the beginning of the last token.
10687 This is the value of the parameter. */
10688 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10690 value_start
= tok
+ 1;
10692 /* Skip whitespace. */
10693 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10698 /* Find the beginning of the second to last token.
10699 This is the parameter itself. */
10700 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10703 toklen
= end_tok
- tok
+ 1;
10705 if (toklen
== 6 && startswith (tok
, "thread"))
10707 struct thread_info
*thr
;
10708 /* At this point we've found a "thread" token, which means
10709 the user is trying to set a watchpoint that triggers
10710 only in a specific thread. */
10714 error(_("You can specify only one thread."));
10716 /* Extract the thread ID from the next token. */
10717 thr
= parse_thread_id (value_start
, &endp
);
10719 /* Check if the user provided a valid thread ID. */
10720 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10721 invalid_thread_id_error (value_start
);
10723 thread
= thr
->global_num
;
10725 else if (toklen
== 4 && startswith (tok
, "mask"))
10727 /* We've found a "mask" token, which means the user wants to
10728 create a hardware watchpoint that is going to have the mask
10730 struct value
*mask_value
, *mark
;
10733 error(_("You can specify only one mask."));
10735 use_mask
= just_location
= true;
10737 mark
= value_mark ();
10738 mask_value
= parse_to_comma_and_eval (&value_start
);
10739 mask
= value_as_address (mask_value
);
10740 value_free_to_mark (mark
);
10743 /* We didn't recognize what we found. We should stop here. */
10746 /* Truncate the string and get rid of the "parameter value" pair before
10747 the arguments string is parsed by the parse_exp_1 function. */
10754 /* Parse the rest of the arguments. From here on out, everything
10755 is in terms of a newly allocated string instead of the original
10757 std::string
expression (arg
, exp_end
- arg
);
10758 exp_start
= arg
= expression
.c_str ();
10759 innermost_block_tracker tracker
;
10760 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10762 /* Remove trailing whitespace from the expression before saving it.
10763 This makes the eventual display of the expression string a bit
10765 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10768 /* Checking if the expression is not constant. */
10769 if (watchpoint_exp_is_const (exp
.get ()))
10773 len
= exp_end
- exp_start
;
10774 while (len
> 0 && isspace (exp_start
[len
- 1]))
10776 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10779 exp_valid_block
= tracker
.block ();
10780 struct value
*mark
= value_mark ();
10781 struct value
*val_as_value
= nullptr;
10782 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10785 if (val_as_value
!= NULL
&& just_location
)
10787 saved_bitpos
= value_bitpos (val_as_value
);
10788 saved_bitsize
= value_bitsize (val_as_value
);
10796 exp_valid_block
= NULL
;
10797 val
= release_value (value_addr (result
));
10798 value_free_to_mark (mark
);
10802 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10805 error (_("This target does not support masked watchpoints."));
10806 else if (ret
== -2)
10807 error (_("Invalid mask or memory region."));
10810 else if (val_as_value
!= NULL
)
10811 val
= release_value (val_as_value
);
10813 tok
= skip_spaces (arg
);
10814 end_tok
= skip_to_space (tok
);
10816 toklen
= end_tok
- tok
;
10817 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10819 tok
= cond_start
= end_tok
+ 1;
10820 innermost_block_tracker if_tracker
;
10821 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10823 /* The watchpoint expression may not be local, but the condition
10824 may still be. E.g.: `watch global if local > 0'. */
10825 cond_exp_valid_block
= if_tracker
.block ();
10830 error (_("Junk at end of command."));
10832 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10834 /* Save this because create_internal_breakpoint below invalidates
10836 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10838 /* If the expression is "local", then set up a "watchpoint scope"
10839 breakpoint at the point where we've left the scope of the watchpoint
10840 expression. Create the scope breakpoint before the watchpoint, so
10841 that we will encounter it first in bpstat_stop_status. */
10842 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10844 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10846 if (frame_id_p (caller_frame_id
))
10848 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10849 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10852 = create_internal_breakpoint (caller_arch
, caller_pc
,
10853 bp_watchpoint_scope
,
10854 &momentary_breakpoint_ops
);
10856 /* create_internal_breakpoint could invalidate WP_FRAME. */
10859 scope_breakpoint
->enable_state
= bp_enabled
;
10861 /* Automatically delete the breakpoint when it hits. */
10862 scope_breakpoint
->disposition
= disp_del
;
10864 /* Only break in the proper frame (help with recursion). */
10865 scope_breakpoint
->frame_id
= caller_frame_id
;
10867 /* Set the address at which we will stop. */
10868 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10869 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10870 scope_breakpoint
->loc
->address
10871 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10872 scope_breakpoint
->loc
->requested_address
,
10873 scope_breakpoint
->type
);
10877 /* Now set up the breakpoint. We create all watchpoints as hardware
10878 watchpoints here even if hardware watchpoints are turned off, a call
10879 to update_watchpoint later in this function will cause the type to
10880 drop back to bp_watchpoint (software watchpoint) if required. */
10882 if (accessflag
== hw_read
)
10883 bp_type
= bp_read_watchpoint
;
10884 else if (accessflag
== hw_access
)
10885 bp_type
= bp_access_watchpoint
;
10887 bp_type
= bp_hardware_watchpoint
;
10889 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10892 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10893 &masked_watchpoint_breakpoint_ops
);
10895 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10896 &watchpoint_breakpoint_ops
);
10897 w
->thread
= thread
;
10898 w
->disposition
= disp_donttouch
;
10899 w
->pspace
= current_program_space
;
10900 w
->exp
= std::move (exp
);
10901 w
->exp_valid_block
= exp_valid_block
;
10902 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10905 struct type
*t
= value_type (val
.get ());
10906 CORE_ADDR addr
= value_as_address (val
.get ());
10908 w
->exp_string_reparse
10909 = current_language
->watch_location_expression (t
, addr
).release ();
10911 w
->exp_string
= xstrprintf ("-location %.*s",
10912 (int) (exp_end
- exp_start
), exp_start
);
10915 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10919 w
->hw_wp_mask
= mask
;
10924 w
->val_bitpos
= saved_bitpos
;
10925 w
->val_bitsize
= saved_bitsize
;
10926 w
->val_valid
= true;
10930 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10932 w
->cond_string
= 0;
10934 if (frame_id_p (watchpoint_frame
))
10936 w
->watchpoint_frame
= watchpoint_frame
;
10937 w
->watchpoint_thread
= inferior_ptid
;
10941 w
->watchpoint_frame
= null_frame_id
;
10942 w
->watchpoint_thread
= null_ptid
;
10945 if (scope_breakpoint
!= NULL
)
10947 /* The scope breakpoint is related to the watchpoint. We will
10948 need to act on them together. */
10949 w
->related_breakpoint
= scope_breakpoint
;
10950 scope_breakpoint
->related_breakpoint
= w
.get ();
10953 if (!just_location
)
10954 value_free_to_mark (mark
);
10956 /* Finally update the new watchpoint. This creates the locations
10957 that should be inserted. */
10958 update_watchpoint (w
.get (), 1);
10960 install_breakpoint (internal
, std::move (w
), 1);
10963 /* Return count of debug registers needed to watch the given expression.
10964 If the watchpoint cannot be handled in hardware return zero. */
10967 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10969 int found_memory_cnt
= 0;
10971 /* Did the user specifically forbid us to use hardware watchpoints? */
10972 if (!can_use_hw_watchpoints
)
10975 gdb_assert (!vals
.empty ());
10976 struct value
*head
= vals
[0].get ();
10978 /* Make sure that the value of the expression depends only upon
10979 memory contents, and values computed from them within GDB. If we
10980 find any register references or function calls, we can't use a
10981 hardware watchpoint.
10983 The idea here is that evaluating an expression generates a series
10984 of values, one holding the value of every subexpression. (The
10985 expression a*b+c has five subexpressions: a, b, a*b, c, and
10986 a*b+c.) GDB's values hold almost enough information to establish
10987 the criteria given above --- they identify memory lvalues,
10988 register lvalues, computed values, etcetera. So we can evaluate
10989 the expression, and then scan the chain of values that leaves
10990 behind to decide whether we can detect any possible change to the
10991 expression's final value using only hardware watchpoints.
10993 However, I don't think that the values returned by inferior
10994 function calls are special in any way. So this function may not
10995 notice that an expression involving an inferior function call
10996 can't be watched with hardware watchpoints. FIXME. */
10997 for (const value_ref_ptr
&iter
: vals
)
10999 struct value
*v
= iter
.get ();
11001 if (VALUE_LVAL (v
) == lval_memory
)
11003 if (v
!= head
&& value_lazy (v
))
11004 /* A lazy memory lvalue in the chain is one that GDB never
11005 needed to fetch; we either just used its address (e.g.,
11006 `a' in `a.b') or we never needed it at all (e.g., `a'
11007 in `a,b'). This doesn't apply to HEAD; if that is
11008 lazy then it was not readable, but watch it anyway. */
11012 /* Ahh, memory we actually used! Check if we can cover
11013 it with hardware watchpoints. */
11014 struct type
*vtype
= check_typedef (value_type (v
));
11016 /* We only watch structs and arrays if user asked for it
11017 explicitly, never if they just happen to appear in a
11018 middle of some value chain. */
11020 || (vtype
->code () != TYPE_CODE_STRUCT
11021 && vtype
->code () != TYPE_CODE_ARRAY
))
11023 CORE_ADDR vaddr
= value_address (v
);
11027 len
= (target_exact_watchpoints
11028 && is_scalar_type_recursive (vtype
))?
11029 1 : TYPE_LENGTH (value_type (v
));
11031 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11035 found_memory_cnt
+= num_regs
;
11039 else if (VALUE_LVAL (v
) != not_lval
11040 && deprecated_value_modifiable (v
) == 0)
11041 return 0; /* These are values from the history (e.g., $1). */
11042 else if (VALUE_LVAL (v
) == lval_register
)
11043 return 0; /* Cannot watch a register with a HW watchpoint. */
11046 /* The expression itself looks suitable for using a hardware
11047 watchpoint, but give the target machine a chance to reject it. */
11048 return found_memory_cnt
;
11052 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11054 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11057 /* Options for the watch, awatch, and rwatch commands. */
11059 struct watch_options
11061 /* For -location. */
11062 bool location
= false;
11065 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
11067 Historically GDB always accepted both '-location' and '-l' flags for
11068 these commands (both flags being synonyms). When converting to the
11069 newer option scheme only '-location' is added here. That's fine (for
11070 backward compatibility) as any non-ambiguous prefix of a flag will be
11071 accepted, so '-l', '-loc', are now all accepted.
11073 What this means is that, if in the future, we add any new flag here
11074 that starts with '-l' then this will break backward compatibility, so
11075 please, don't do that! */
11077 static const gdb::option::option_def watch_option_defs
[] = {
11078 gdb::option::flag_option_def
<watch_options
> {
11080 [] (watch_options
*opt
) { return &opt
->location
; },
11082 This evaluates EXPRESSION and watches the memory to which is refers.\n\
11083 -l can be used as a short form of -location."),
11087 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
11090 static gdb::option::option_def_group
11091 make_watch_options_def_group (watch_options
*opts
)
11093 return {{watch_option_defs
}, opts
};
11096 /* A helper function that looks for the "-location" argument and then
11097 calls watch_command_1. */
11100 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
11102 watch_options opts
;
11103 auto grp
= make_watch_options_def_group (&opts
);
11104 gdb::option::process_options
11105 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
11106 if (arg
!= nullptr && *arg
== '\0')
11109 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
11112 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
11114 watch_command_completer (struct cmd_list_element
*ignore
,
11115 completion_tracker
&tracker
,
11116 const char *text
, const char * /*word*/)
11118 const auto group
= make_watch_options_def_group (nullptr);
11119 if (gdb::option::complete_options
11120 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
11123 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
11124 expression_completer (ignore
, tracker
, text
, word
);
11128 watch_command (const char *arg
, int from_tty
)
11130 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11134 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11136 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11140 rwatch_command (const char *arg
, int from_tty
)
11142 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11146 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11148 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11152 awatch_command (const char *arg
, int from_tty
)
11154 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11158 /* Data for the FSM that manages the until(location)/advance commands
11159 in infcmd.c. Here because it uses the mechanisms of
11162 struct until_break_fsm
: public thread_fsm
11164 /* The thread that was current when the command was executed. */
11167 /* The breakpoint set at the return address in the caller frame,
11168 plus breakpoints at all the destination locations. */
11169 std::vector
<breakpoint_up
> breakpoints
;
11171 until_break_fsm (struct interp
*cmd_interp
, int thread
,
11172 std::vector
<breakpoint_up
> &&breakpoints
)
11173 : thread_fsm (cmd_interp
),
11175 breakpoints (std::move (breakpoints
))
11179 void clean_up (struct thread_info
*thread
) override
;
11180 bool should_stop (struct thread_info
*thread
) override
;
11181 enum async_reply_reason
do_async_reply_reason () override
;
11184 /* Implementation of the 'should_stop' FSM method for the
11185 until(location)/advance commands. */
11188 until_break_fsm::should_stop (struct thread_info
*tp
)
11190 for (const breakpoint_up
&bp
: breakpoints
)
11191 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11192 bp
.get ()) != NULL
)
11201 /* Implementation of the 'clean_up' FSM method for the
11202 until(location)/advance commands. */
11205 until_break_fsm::clean_up (struct thread_info
*)
11207 /* Clean up our temporary breakpoints. */
11208 breakpoints
.clear ();
11209 delete_longjmp_breakpoint (thread
);
11212 /* Implementation of the 'async_reply_reason' FSM method for the
11213 until(location)/advance commands. */
11215 enum async_reply_reason
11216 until_break_fsm::do_async_reply_reason ()
11218 return EXEC_ASYNC_LOCATION_REACHED
;
11222 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11224 struct frame_info
*frame
;
11225 struct gdbarch
*frame_gdbarch
;
11226 struct frame_id stack_frame_id
;
11227 struct frame_id caller_frame_id
;
11229 struct thread_info
*tp
;
11231 clear_proceed_status (0);
11233 /* Set a breakpoint where the user wants it and at return from
11236 event_location_up location
= string_to_event_location (&arg
, current_language
);
11238 std::vector
<symtab_and_line
> sals
11239 = (last_displayed_sal_is_valid ()
11240 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11241 get_last_displayed_symtab (),
11242 get_last_displayed_line ())
11243 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11247 error (_("Couldn't get information on specified line."));
11250 error (_("Junk at end of arguments."));
11252 tp
= inferior_thread ();
11253 thread
= tp
->global_num
;
11255 /* Note linespec handling above invalidates the frame chain.
11256 Installing a breakpoint also invalidates the frame chain (as it
11257 may need to switch threads), so do any frame handling before
11260 frame
= get_selected_frame (NULL
);
11261 frame_gdbarch
= get_frame_arch (frame
);
11262 stack_frame_id
= get_stack_frame_id (frame
);
11263 caller_frame_id
= frame_unwind_caller_id (frame
);
11265 /* Keep within the current frame, or in frames called by the current
11268 std::vector
<breakpoint_up
> breakpoints
;
11270 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11272 if (frame_id_p (caller_frame_id
))
11274 struct symtab_and_line sal2
;
11275 struct gdbarch
*caller_gdbarch
;
11277 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11278 sal2
.pc
= frame_unwind_caller_pc (frame
);
11279 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11281 breakpoint_up caller_breakpoint
11282 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
11283 caller_frame_id
, bp_until
);
11284 breakpoints
.emplace_back (std::move (caller_breakpoint
));
11286 set_longjmp_breakpoint (tp
, caller_frame_id
);
11287 lj_deleter
.emplace (thread
);
11290 /* set_momentary_breakpoint could invalidate FRAME. */
11293 /* If the user told us to continue until a specified location, we
11294 don't specify a frame at which we need to stop. Otherwise,
11295 specify the selected frame, because we want to stop only at the
11296 very same frame. */
11297 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
11299 for (symtab_and_line
&sal
: sals
)
11301 resolve_sal_pc (&sal
);
11303 breakpoint_up location_breakpoint
11304 = set_momentary_breakpoint (frame_gdbarch
, sal
,
11305 stop_frame_id
, bp_until
);
11306 breakpoints
.emplace_back (std::move (location_breakpoint
));
11309 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11310 std::move (breakpoints
));
11313 lj_deleter
->release ();
11315 proceed (-1, GDB_SIGNAL_DEFAULT
);
11318 /* This function attempts to parse an optional "if <cond>" clause
11319 from the arg string. If one is not found, it returns NULL.
11321 Else, it returns a pointer to the condition string. (It does not
11322 attempt to evaluate the string against a particular block.) And,
11323 it updates arg to point to the first character following the parsed
11324 if clause in the arg string. */
11327 ep_parse_optional_if_clause (const char **arg
)
11329 const char *cond_string
;
11331 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11334 /* Skip the "if" keyword. */
11337 /* Skip any extra leading whitespace, and record the start of the
11338 condition string. */
11339 *arg
= skip_spaces (*arg
);
11340 cond_string
= *arg
;
11342 /* Assume that the condition occupies the remainder of the arg
11344 (*arg
) += strlen (cond_string
);
11346 return cond_string
;
11349 /* Commands to deal with catching events, such as signals, exceptions,
11350 process start/exit, etc. */
11354 catch_fork_temporary
, catch_vfork_temporary
,
11355 catch_fork_permanent
, catch_vfork_permanent
11360 catch_fork_command_1 (const char *arg
, int from_tty
,
11361 struct cmd_list_element
*command
)
11363 struct gdbarch
*gdbarch
= get_current_arch ();
11364 const char *cond_string
= NULL
;
11365 catch_fork_kind fork_kind
;
11367 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11368 bool temp
= (fork_kind
== catch_fork_temporary
11369 || fork_kind
== catch_vfork_temporary
);
11373 arg
= skip_spaces (arg
);
11375 /* The allowed syntax is:
11377 catch [v]fork if <cond>
11379 First, check if there's an if clause. */
11380 cond_string
= ep_parse_optional_if_clause (&arg
);
11382 if ((*arg
!= '\0') && !isspace (*arg
))
11383 error (_("Junk at end of arguments."));
11385 /* If this target supports it, create a fork or vfork catchpoint
11386 and enable reporting of such events. */
11389 case catch_fork_temporary
:
11390 case catch_fork_permanent
:
11391 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11392 &catch_fork_breakpoint_ops
);
11394 case catch_vfork_temporary
:
11395 case catch_vfork_permanent
:
11396 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11397 &catch_vfork_breakpoint_ops
);
11400 error (_("unsupported or unknown fork kind; cannot catch it"));
11406 catch_exec_command_1 (const char *arg
, int from_tty
,
11407 struct cmd_list_element
*command
)
11409 struct gdbarch
*gdbarch
= get_current_arch ();
11410 const char *cond_string
= NULL
;
11411 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11415 arg
= skip_spaces (arg
);
11417 /* The allowed syntax is:
11419 catch exec if <cond>
11421 First, check if there's an if clause. */
11422 cond_string
= ep_parse_optional_if_clause (&arg
);
11424 if ((*arg
!= '\0') && !isspace (*arg
))
11425 error (_("Junk at end of arguments."));
11427 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11428 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
,
11429 &catch_exec_breakpoint_ops
);
11430 c
->exec_pathname
= NULL
;
11432 install_breakpoint (0, std::move (c
), 1);
11436 init_ada_exception_breakpoint (struct breakpoint
*b
,
11437 struct gdbarch
*gdbarch
,
11438 struct symtab_and_line sal
,
11439 const char *addr_string
,
11440 const struct breakpoint_ops
*ops
,
11447 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11449 loc_gdbarch
= gdbarch
;
11451 describe_other_breakpoints (loc_gdbarch
,
11452 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11453 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11454 version for exception catchpoints, because two catchpoints
11455 used for different exception names will use the same address.
11456 In this case, a "breakpoint ... also set at..." warning is
11457 unproductive. Besides, the warning phrasing is also a bit
11458 inappropriate, we should use the word catchpoint, and tell
11459 the user what type of catchpoint it is. The above is good
11460 enough for now, though. */
11463 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11465 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11466 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11467 b
->location
= string_to_event_location (&addr_string
,
11468 language_def (language_ada
));
11469 b
->language
= language_ada
;
11474 /* Compare two breakpoints and return a strcmp-like result. */
11477 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11479 uintptr_t ua
= (uintptr_t) a
;
11480 uintptr_t ub
= (uintptr_t) b
;
11482 if (a
->number
< b
->number
)
11484 else if (a
->number
> b
->number
)
11487 /* Now sort by address, in case we see, e..g, two breakpoints with
11491 return ua
> ub
? 1 : 0;
11494 /* Delete breakpoints by address or line. */
11497 clear_command (const char *arg
, int from_tty
)
11499 struct breakpoint
*b
;
11502 std::vector
<symtab_and_line
> decoded_sals
;
11503 symtab_and_line last_sal
;
11504 gdb::array_view
<symtab_and_line
> sals
;
11508 = decode_line_with_current_source (arg
,
11509 (DECODE_LINE_FUNFIRSTLINE
11510 | DECODE_LINE_LIST_MODE
));
11512 sals
= decoded_sals
;
11516 /* Set sal's line, symtab, pc, and pspace to the values
11517 corresponding to the last call to print_frame_info. If the
11518 codepoint is not valid, this will set all the fields to 0. */
11519 last_sal
= get_last_displayed_sal ();
11520 if (last_sal
.symtab
== 0)
11521 error (_("No source file specified."));
11527 /* We don't call resolve_sal_pc here. That's not as bad as it
11528 seems, because all existing breakpoints typically have both
11529 file/line and pc set. So, if clear is given file/line, we can
11530 match this to existing breakpoint without obtaining pc at all.
11532 We only support clearing given the address explicitly
11533 present in breakpoint table. Say, we've set breakpoint
11534 at file:line. There were several PC values for that file:line,
11535 due to optimization, all in one block.
11537 We've picked one PC value. If "clear" is issued with another
11538 PC corresponding to the same file:line, the breakpoint won't
11539 be cleared. We probably can still clear the breakpoint, but
11540 since the other PC value is never presented to user, user
11541 can only find it by guessing, and it does not seem important
11542 to support that. */
11544 /* For each line spec given, delete bps which correspond to it. Do
11545 it in two passes, solely to preserve the current behavior that
11546 from_tty is forced true if we delete more than one
11549 std::vector
<struct breakpoint
*> found
;
11550 for (const auto &sal
: sals
)
11552 const char *sal_fullname
;
11554 /* If exact pc given, clear bpts at that pc.
11555 If line given (pc == 0), clear all bpts on specified line.
11556 If defaulting, clear all bpts on default line
11559 defaulting sal.pc != 0 tests to do
11564 1 0 <can't happen> */
11566 sal_fullname
= (sal
.symtab
== NULL
11567 ? NULL
: symtab_to_fullname (sal
.symtab
));
11569 /* Find all matching breakpoints and add them to 'found'. */
11570 ALL_BREAKPOINTS (b
)
11573 /* Are we going to delete b? */
11574 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11576 struct bp_location
*loc
= b
->loc
;
11577 for (; loc
; loc
= loc
->next
)
11579 /* If the user specified file:line, don't allow a PC
11580 match. This matches historical gdb behavior. */
11581 int pc_match
= (!sal
.explicit_line
11583 && (loc
->pspace
== sal
.pspace
)
11584 && (loc
->address
== sal
.pc
)
11585 && (!section_is_overlay (loc
->section
)
11586 || loc
->section
== sal
.section
));
11587 int line_match
= 0;
11589 if ((default_match
|| sal
.explicit_line
)
11590 && loc
->symtab
!= NULL
11591 && sal_fullname
!= NULL
11592 && sal
.pspace
== loc
->pspace
11593 && loc
->line_number
== sal
.line
11594 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11595 sal_fullname
) == 0)
11598 if (pc_match
|| line_match
)
11607 found
.push_back (b
);
11611 /* Now go thru the 'found' chain and delete them. */
11612 if (found
.empty ())
11615 error (_("No breakpoint at %s."), arg
);
11617 error (_("No breakpoint at this line."));
11620 /* Remove duplicates from the vec. */
11621 std::sort (found
.begin (), found
.end (),
11622 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11624 return compare_breakpoints (bp_a
, bp_b
) < 0;
11626 found
.erase (std::unique (found
.begin (), found
.end (),
11627 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11629 return compare_breakpoints (bp_a
, bp_b
) == 0;
11633 if (found
.size () > 1)
11634 from_tty
= 1; /* Always report if deleted more than one. */
11637 if (found
.size () == 1)
11638 printf_unfiltered (_("Deleted breakpoint "));
11640 printf_unfiltered (_("Deleted breakpoints "));
11643 for (breakpoint
*iter
: found
)
11646 printf_unfiltered ("%d ", iter
->number
);
11647 delete_breakpoint (iter
);
11650 putchar_unfiltered ('\n');
11653 /* Delete breakpoint in BS if they are `delete' breakpoints and
11654 all breakpoints that are marked for deletion, whether hit or not.
11655 This is called after any breakpoint is hit, or after errors. */
11658 breakpoint_auto_delete (bpstat bs
)
11660 struct breakpoint
*b
, *b_tmp
;
11662 for (; bs
; bs
= bs
->next
)
11663 if (bs
->breakpoint_at
11664 && bs
->breakpoint_at
->disposition
== disp_del
11666 delete_breakpoint (bs
->breakpoint_at
);
11668 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11670 if (b
->disposition
== disp_del_at_next_stop
)
11671 delete_breakpoint (b
);
11675 /* A comparison function for bp_location AP and BP being interfaced to
11676 std::sort. Sort elements primarily by their ADDRESS (no matter what
11677 bl_address_is_meaningful says), secondarily by ordering first
11678 permanent elements and terciarily just ensuring the array is sorted
11679 stable way despite std::sort being an unstable algorithm. */
11682 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11684 if (a
->address
!= b
->address
)
11685 return a
->address
< b
->address
;
11687 /* Sort locations at the same address by their pspace number, keeping
11688 locations of the same inferior (in a multi-inferior environment)
11691 if (a
->pspace
->num
!= b
->pspace
->num
)
11692 return a
->pspace
->num
< b
->pspace
->num
;
11694 /* Sort permanent breakpoints first. */
11695 if (a
->permanent
!= b
->permanent
)
11696 return a
->permanent
> b
->permanent
;
11698 /* Sort by type in order to make duplicate determination easier.
11699 See update_global_location_list. This is kept in sync with
11700 breakpoint_locations_match. */
11701 if (a
->loc_type
< b
->loc_type
)
11704 /* Likewise, for range-breakpoints, sort by length. */
11705 if (a
->loc_type
== bp_loc_hardware_breakpoint
11706 && b
->loc_type
== bp_loc_hardware_breakpoint
11707 && a
->length
< b
->length
)
11710 /* Make the internal GDB representation stable across GDB runs
11711 where A and B memory inside GDB can differ. Breakpoint locations of
11712 the same type at the same address can be sorted in arbitrary order. */
11714 if (a
->owner
->number
!= b
->owner
->number
)
11715 return a
->owner
->number
< b
->owner
->number
;
11720 /* Set bp_locations_placed_address_before_address_max and
11721 bp_locations_shadow_len_after_address_max according to the current
11722 content of the bp_locations array. */
11725 bp_locations_target_extensions_update (void)
11727 struct bp_location
*bl
, **blp_tmp
;
11729 bp_locations_placed_address_before_address_max
= 0;
11730 bp_locations_shadow_len_after_address_max
= 0;
11732 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11734 CORE_ADDR start
, end
, addr
;
11736 if (!bp_location_has_shadow (bl
))
11739 start
= bl
->target_info
.placed_address
;
11740 end
= start
+ bl
->target_info
.shadow_len
;
11742 gdb_assert (bl
->address
>= start
);
11743 addr
= bl
->address
- start
;
11744 if (addr
> bp_locations_placed_address_before_address_max
)
11745 bp_locations_placed_address_before_address_max
= addr
;
11747 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11749 gdb_assert (bl
->address
< end
);
11750 addr
= end
- bl
->address
;
11751 if (addr
> bp_locations_shadow_len_after_address_max
)
11752 bp_locations_shadow_len_after_address_max
= addr
;
11756 /* Download tracepoint locations if they haven't been. */
11759 download_tracepoint_locations (void)
11761 struct breakpoint
*b
;
11762 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11764 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11766 ALL_TRACEPOINTS (b
)
11768 struct bp_location
*bl
;
11769 struct tracepoint
*t
;
11770 int bp_location_downloaded
= 0;
11772 if ((b
->type
== bp_fast_tracepoint
11773 ? !may_insert_fast_tracepoints
11774 : !may_insert_tracepoints
))
11777 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11779 if (target_can_download_tracepoint ())
11780 can_download_tracepoint
= TRIBOOL_TRUE
;
11782 can_download_tracepoint
= TRIBOOL_FALSE
;
11785 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11788 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11790 /* In tracepoint, locations are _never_ duplicated, so
11791 should_be_inserted is equivalent to
11792 unduplicated_should_be_inserted. */
11793 if (!should_be_inserted (bl
) || bl
->inserted
)
11796 switch_to_program_space_and_thread (bl
->pspace
);
11798 target_download_tracepoint (bl
);
11801 bp_location_downloaded
= 1;
11803 t
= (struct tracepoint
*) b
;
11804 t
->number_on_target
= b
->number
;
11805 if (bp_location_downloaded
)
11806 gdb::observers::breakpoint_modified
.notify (b
);
11810 /* Swap the insertion/duplication state between two locations. */
11813 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11815 const int left_inserted
= left
->inserted
;
11816 const int left_duplicate
= left
->duplicate
;
11817 const int left_needs_update
= left
->needs_update
;
11818 const struct bp_target_info left_target_info
= left
->target_info
;
11820 /* Locations of tracepoints can never be duplicated. */
11821 if (is_tracepoint (left
->owner
))
11822 gdb_assert (!left
->duplicate
);
11823 if (is_tracepoint (right
->owner
))
11824 gdb_assert (!right
->duplicate
);
11826 left
->inserted
= right
->inserted
;
11827 left
->duplicate
= right
->duplicate
;
11828 left
->needs_update
= right
->needs_update
;
11829 left
->target_info
= right
->target_info
;
11830 right
->inserted
= left_inserted
;
11831 right
->duplicate
= left_duplicate
;
11832 right
->needs_update
= left_needs_update
;
11833 right
->target_info
= left_target_info
;
11836 /* Force the re-insertion of the locations at ADDRESS. This is called
11837 once a new/deleted/modified duplicate location is found and we are evaluating
11838 conditions on the target's side. Such conditions need to be updated on
11842 force_breakpoint_reinsertion (struct bp_location
*bl
)
11844 struct bp_location
**locp
= NULL
, **loc2p
;
11845 struct bp_location
*loc
;
11846 CORE_ADDR address
= 0;
11849 address
= bl
->address
;
11850 pspace_num
= bl
->pspace
->num
;
11852 /* This is only meaningful if the target is
11853 evaluating conditions and if the user has
11854 opted for condition evaluation on the target's
11856 if (gdb_evaluates_breakpoint_condition_p ()
11857 || !target_supports_evaluation_of_breakpoint_conditions ())
11860 /* Flag all breakpoint locations with this address and
11861 the same program space as the location
11862 as "its condition has changed". We need to
11863 update the conditions on the target's side. */
11864 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11868 if (!is_breakpoint (loc
->owner
)
11869 || pspace_num
!= loc
->pspace
->num
)
11872 /* Flag the location appropriately. We use a different state to
11873 let everyone know that we already updated the set of locations
11874 with addr bl->address and program space bl->pspace. This is so
11875 we don't have to keep calling these functions just to mark locations
11876 that have already been marked. */
11877 loc
->condition_changed
= condition_updated
;
11879 /* Free the agent expression bytecode as well. We will compute
11881 loc
->cond_bytecode
.reset ();
11885 /* Called whether new breakpoints are created, or existing breakpoints
11886 deleted, to update the global location list and recompute which
11887 locations are duplicate of which.
11889 The INSERT_MODE flag determines whether locations may not, may, or
11890 shall be inserted now. See 'enum ugll_insert_mode' for more
11894 update_global_location_list (enum ugll_insert_mode insert_mode
)
11896 struct breakpoint
*b
;
11897 struct bp_location
**locp
, *loc
;
11898 /* Last breakpoint location address that was marked for update. */
11899 CORE_ADDR last_addr
= 0;
11900 /* Last breakpoint location program space that was marked for update. */
11901 int last_pspace_num
= -1;
11903 /* Used in the duplicates detection below. When iterating over all
11904 bp_locations, points to the first bp_location of a given address.
11905 Breakpoints and watchpoints of different types are never
11906 duplicates of each other. Keep one pointer for each type of
11907 breakpoint/watchpoint, so we only need to loop over all locations
11909 struct bp_location
*bp_loc_first
; /* breakpoint */
11910 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11911 struct bp_location
*awp_loc_first
; /* access watchpoint */
11912 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11914 /* Saved former bp_locations array which we compare against the newly
11915 built bp_locations from the current state of ALL_BREAKPOINTS. */
11916 struct bp_location
**old_locp
;
11917 unsigned old_locations_count
;
11918 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11920 old_locations_count
= bp_locations_count
;
11921 bp_locations
= NULL
;
11922 bp_locations_count
= 0;
11924 ALL_BREAKPOINTS (b
)
11925 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11926 bp_locations_count
++;
11928 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11929 locp
= bp_locations
;
11930 ALL_BREAKPOINTS (b
)
11931 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11934 /* See if we need to "upgrade" a software breakpoint to a hardware
11935 breakpoint. Do this before deciding whether locations are
11936 duplicates. Also do this before sorting because sorting order
11937 depends on location type. */
11938 for (locp
= bp_locations
;
11939 locp
< bp_locations
+ bp_locations_count
;
11943 if (!loc
->inserted
&& should_be_inserted (loc
))
11944 handle_automatic_hardware_breakpoints (loc
);
11947 std::sort (bp_locations
, bp_locations
+ bp_locations_count
,
11948 bp_location_is_less_than
);
11950 bp_locations_target_extensions_update ();
11952 /* Identify bp_location instances that are no longer present in the
11953 new list, and therefore should be freed. Note that it's not
11954 necessary that those locations should be removed from inferior --
11955 if there's another location at the same address (previously
11956 marked as duplicate), we don't need to remove/insert the
11959 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11960 and former bp_location array state respectively. */
11962 locp
= bp_locations
;
11963 for (old_locp
= old_locations
.get ();
11964 old_locp
< old_locations
.get () + old_locations_count
;
11967 struct bp_location
*old_loc
= *old_locp
;
11968 struct bp_location
**loc2p
;
11970 /* Tells if 'old_loc' is found among the new locations. If
11971 not, we have to free it. */
11972 int found_object
= 0;
11973 /* Tells if the location should remain inserted in the target. */
11974 int keep_in_target
= 0;
11977 /* Skip LOCP entries which will definitely never be needed.
11978 Stop either at or being the one matching OLD_LOC. */
11979 while (locp
< bp_locations
+ bp_locations_count
11980 && (*locp
)->address
< old_loc
->address
)
11984 (loc2p
< bp_locations
+ bp_locations_count
11985 && (*loc2p
)->address
== old_loc
->address
);
11988 /* Check if this is a new/duplicated location or a duplicated
11989 location that had its condition modified. If so, we want to send
11990 its condition to the target if evaluation of conditions is taking
11992 if ((*loc2p
)->condition_changed
== condition_modified
11993 && (last_addr
!= old_loc
->address
11994 || last_pspace_num
!= old_loc
->pspace
->num
))
11996 force_breakpoint_reinsertion (*loc2p
);
11997 last_pspace_num
= old_loc
->pspace
->num
;
12000 if (*loc2p
== old_loc
)
12004 /* We have already handled this address, update it so that we don't
12005 have to go through updates again. */
12006 last_addr
= old_loc
->address
;
12008 /* Target-side condition evaluation: Handle deleted locations. */
12010 force_breakpoint_reinsertion (old_loc
);
12012 /* If this location is no longer present, and inserted, look if
12013 there's maybe a new location at the same address. If so,
12014 mark that one inserted, and don't remove this one. This is
12015 needed so that we don't have a time window where a breakpoint
12016 at certain location is not inserted. */
12018 if (old_loc
->inserted
)
12020 /* If the location is inserted now, we might have to remove
12023 if (found_object
&& should_be_inserted (old_loc
))
12025 /* The location is still present in the location list,
12026 and still should be inserted. Don't do anything. */
12027 keep_in_target
= 1;
12031 /* This location still exists, but it won't be kept in the
12032 target since it may have been disabled. We proceed to
12033 remove its target-side condition. */
12035 /* The location is either no longer present, or got
12036 disabled. See if there's another location at the
12037 same address, in which case we don't need to remove
12038 this one from the target. */
12040 /* OLD_LOC comes from existing struct breakpoint. */
12041 if (bl_address_is_meaningful (old_loc
))
12044 (loc2p
< bp_locations
+ bp_locations_count
12045 && (*loc2p
)->address
== old_loc
->address
);
12048 struct bp_location
*loc2
= *loc2p
;
12050 if (loc2
== old_loc
)
12053 if (breakpoint_locations_match (loc2
, old_loc
))
12055 /* Read watchpoint locations are switched to
12056 access watchpoints, if the former are not
12057 supported, but the latter are. */
12058 if (is_hardware_watchpoint (old_loc
->owner
))
12060 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12061 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12064 /* loc2 is a duplicated location. We need to check
12065 if it should be inserted in case it will be
12067 if (unduplicated_should_be_inserted (loc2
))
12069 swap_insertion (old_loc
, loc2
);
12070 keep_in_target
= 1;
12078 if (!keep_in_target
)
12080 if (remove_breakpoint (old_loc
))
12082 /* This is just about all we can do. We could keep
12083 this location on the global list, and try to
12084 remove it next time, but there's no particular
12085 reason why we will succeed next time.
12087 Note that at this point, old_loc->owner is still
12088 valid, as delete_breakpoint frees the breakpoint
12089 only after calling us. */
12090 printf_filtered (_("warning: Error removing "
12091 "breakpoint %d\n"),
12092 old_loc
->owner
->number
);
12100 if (removed
&& target_is_non_stop_p ()
12101 && need_moribund_for_location_type (old_loc
))
12103 /* This location was removed from the target. In
12104 non-stop mode, a race condition is possible where
12105 we've removed a breakpoint, but stop events for that
12106 breakpoint are already queued and will arrive later.
12107 We apply an heuristic to be able to distinguish such
12108 SIGTRAPs from other random SIGTRAPs: we keep this
12109 breakpoint location for a bit, and will retire it
12110 after we see some number of events. The theory here
12111 is that reporting of events should, "on the average",
12112 be fair, so after a while we'll see events from all
12113 threads that have anything of interest, and no longer
12114 need to keep this breakpoint location around. We
12115 don't hold locations forever so to reduce chances of
12116 mistaking a non-breakpoint SIGTRAP for a breakpoint
12119 The heuristic failing can be disastrous on
12120 decr_pc_after_break targets.
12122 On decr_pc_after_break targets, like e.g., x86-linux,
12123 if we fail to recognize a late breakpoint SIGTRAP,
12124 because events_till_retirement has reached 0 too
12125 soon, we'll fail to do the PC adjustment, and report
12126 a random SIGTRAP to the user. When the user resumes
12127 the inferior, it will most likely immediately crash
12128 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12129 corrupted, because of being resumed e.g., in the
12130 middle of a multi-byte instruction, or skipped a
12131 one-byte instruction. This was actually seen happen
12132 on native x86-linux, and should be less rare on
12133 targets that do not support new thread events, like
12134 remote, due to the heuristic depending on
12137 Mistaking a random SIGTRAP for a breakpoint trap
12138 causes similar symptoms (PC adjustment applied when
12139 it shouldn't), but then again, playing with SIGTRAPs
12140 behind the debugger's back is asking for trouble.
12142 Since hardware watchpoint traps are always
12143 distinguishable from other traps, so we don't need to
12144 apply keep hardware watchpoint moribund locations
12145 around. We simply always ignore hardware watchpoint
12146 traps we can no longer explain. */
12148 process_stratum_target
*proc_target
= nullptr;
12149 for (inferior
*inf
: all_inferiors ())
12150 if (inf
->pspace
== old_loc
->pspace
)
12152 proc_target
= inf
->process_target ();
12155 if (proc_target
!= nullptr)
12156 old_loc
->events_till_retirement
12157 = 3 * (thread_count (proc_target
) + 1);
12159 old_loc
->events_till_retirement
= 1;
12160 old_loc
->owner
= NULL
;
12162 moribund_locations
.push_back (old_loc
);
12166 old_loc
->owner
= NULL
;
12167 decref_bp_location (&old_loc
);
12172 /* Rescan breakpoints at the same address and section, marking the
12173 first one as "first" and any others as "duplicates". This is so
12174 that the bpt instruction is only inserted once. If we have a
12175 permanent breakpoint at the same place as BPT, make that one the
12176 official one, and the rest as duplicates. Permanent breakpoints
12177 are sorted first for the same address.
12179 Do the same for hardware watchpoints, but also considering the
12180 watchpoint's type (regular/access/read) and length. */
12182 bp_loc_first
= NULL
;
12183 wp_loc_first
= NULL
;
12184 awp_loc_first
= NULL
;
12185 rwp_loc_first
= NULL
;
12186 ALL_BP_LOCATIONS (loc
, locp
)
12188 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12190 struct bp_location
**loc_first_p
;
12193 if (!unduplicated_should_be_inserted (loc
)
12194 || !bl_address_is_meaningful (loc
)
12195 /* Don't detect duplicate for tracepoint locations because they are
12196 never duplicated. See the comments in field `duplicate' of
12197 `struct bp_location'. */
12198 || is_tracepoint (b
))
12200 /* Clear the condition modification flag. */
12201 loc
->condition_changed
= condition_unchanged
;
12205 if (b
->type
== bp_hardware_watchpoint
)
12206 loc_first_p
= &wp_loc_first
;
12207 else if (b
->type
== bp_read_watchpoint
)
12208 loc_first_p
= &rwp_loc_first
;
12209 else if (b
->type
== bp_access_watchpoint
)
12210 loc_first_p
= &awp_loc_first
;
12212 loc_first_p
= &bp_loc_first
;
12214 if (*loc_first_p
== NULL
12215 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12216 || !breakpoint_locations_match (loc
, *loc_first_p
))
12218 *loc_first_p
= loc
;
12219 loc
->duplicate
= 0;
12221 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12223 loc
->needs_update
= 1;
12224 /* Clear the condition modification flag. */
12225 loc
->condition_changed
= condition_unchanged
;
12231 /* This and the above ensure the invariant that the first location
12232 is not duplicated, and is the inserted one.
12233 All following are marked as duplicated, and are not inserted. */
12235 swap_insertion (loc
, *loc_first_p
);
12236 loc
->duplicate
= 1;
12238 /* Clear the condition modification flag. */
12239 loc
->condition_changed
= condition_unchanged
;
12242 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12244 if (insert_mode
!= UGLL_DONT_INSERT
)
12245 insert_breakpoint_locations ();
12248 /* Even though the caller told us to not insert new
12249 locations, we may still need to update conditions on the
12250 target's side of breakpoints that were already inserted
12251 if the target is evaluating breakpoint conditions. We
12252 only update conditions for locations that are marked
12254 update_inserted_breakpoint_locations ();
12258 if (insert_mode
!= UGLL_DONT_INSERT
)
12259 download_tracepoint_locations ();
12263 breakpoint_retire_moribund (void)
12265 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
12267 struct bp_location
*loc
= moribund_locations
[ix
];
12268 if (--(loc
->events_till_retirement
) == 0)
12270 decref_bp_location (&loc
);
12271 unordered_remove (moribund_locations
, ix
);
12278 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12283 update_global_location_list (insert_mode
);
12285 catch (const gdb_exception_error
&e
)
12290 /* Clear BKP from a BPS. */
12293 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12297 for (bs
= bps
; bs
; bs
= bs
->next
)
12298 if (bs
->breakpoint_at
== bpt
)
12300 bs
->breakpoint_at
= NULL
;
12301 bs
->old_val
= NULL
;
12302 /* bs->commands will be freed later. */
12306 /* Callback for iterate_over_threads. */
12308 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12310 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12312 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12316 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12320 say_where (struct breakpoint
*b
)
12322 struct value_print_options opts
;
12324 get_user_print_options (&opts
);
12326 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12328 if (b
->loc
== NULL
)
12330 /* For pending locations, the output differs slightly based
12331 on b->extra_string. If this is non-NULL, it contains either
12332 a condition or dprintf arguments. */
12333 if (b
->extra_string
== NULL
)
12335 printf_filtered (_(" (%s) pending."),
12336 event_location_to_string (b
->location
.get ()));
12338 else if (b
->type
== bp_dprintf
)
12340 printf_filtered (_(" (%s,%s) pending."),
12341 event_location_to_string (b
->location
.get ()),
12346 printf_filtered (_(" (%s %s) pending."),
12347 event_location_to_string (b
->location
.get ()),
12353 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12354 printf_filtered (" at %ps",
12355 styled_string (address_style
.style (),
12356 paddress (b
->loc
->gdbarch
,
12357 b
->loc
->address
)));
12358 if (b
->loc
->symtab
!= NULL
)
12360 /* If there is a single location, we can print the location
12362 if (b
->loc
->next
== NULL
)
12364 const char *filename
12365 = symtab_to_filename_for_display (b
->loc
->symtab
);
12366 printf_filtered (": file %ps, line %d.",
12367 styled_string (file_name_style
.style (),
12369 b
->loc
->line_number
);
12372 /* This is not ideal, but each location may have a
12373 different file name, and this at least reflects the
12374 real situation somewhat. */
12375 printf_filtered (": %s.",
12376 event_location_to_string (b
->location
.get ()));
12381 struct bp_location
*loc
= b
->loc
;
12383 for (; loc
; loc
= loc
->next
)
12385 printf_filtered (" (%d locations)", n
);
12390 bp_location::~bp_location ()
12392 xfree (function_name
);
12395 /* Destructor for the breakpoint base class. */
12397 breakpoint::~breakpoint ()
12399 xfree (this->cond_string
);
12400 xfree (this->extra_string
);
12403 static struct bp_location
*
12404 base_breakpoint_allocate_location (struct breakpoint
*self
)
12406 return new bp_location (self
);
12410 base_breakpoint_re_set (struct breakpoint
*b
)
12412 /* Nothing to re-set. */
12415 #define internal_error_pure_virtual_called() \
12416 gdb_assert_not_reached ("pure virtual function called")
12419 base_breakpoint_insert_location (struct bp_location
*bl
)
12421 internal_error_pure_virtual_called ();
12425 base_breakpoint_remove_location (struct bp_location
*bl
,
12426 enum remove_bp_reason reason
)
12428 internal_error_pure_virtual_called ();
12432 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12433 const address_space
*aspace
,
12435 const struct target_waitstatus
*ws
)
12437 internal_error_pure_virtual_called ();
12441 base_breakpoint_check_status (bpstat bs
)
12446 /* A "works_in_software_mode" breakpoint_ops method that just internal
12450 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12452 internal_error_pure_virtual_called ();
12455 /* A "resources_needed" breakpoint_ops method that just internal
12459 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12461 internal_error_pure_virtual_called ();
12464 static enum print_stop_action
12465 base_breakpoint_print_it (bpstat bs
)
12467 internal_error_pure_virtual_called ();
12471 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12472 struct ui_out
*uiout
)
12478 base_breakpoint_print_mention (struct breakpoint
*b
)
12480 internal_error_pure_virtual_called ();
12484 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12486 internal_error_pure_virtual_called ();
12490 base_breakpoint_create_sals_from_location
12491 (struct event_location
*location
,
12492 struct linespec_result
*canonical
,
12493 enum bptype type_wanted
)
12495 internal_error_pure_virtual_called ();
12499 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12500 struct linespec_result
*c
,
12501 gdb::unique_xmalloc_ptr
<char> cond_string
,
12502 gdb::unique_xmalloc_ptr
<char> extra_string
,
12503 enum bptype type_wanted
,
12504 enum bpdisp disposition
,
12506 int task
, int ignore_count
,
12507 const struct breakpoint_ops
*o
,
12508 int from_tty
, int enabled
,
12509 int internal
, unsigned flags
)
12511 internal_error_pure_virtual_called ();
12514 static std::vector
<symtab_and_line
>
12515 base_breakpoint_decode_location (struct breakpoint
*b
,
12516 struct event_location
*location
,
12517 struct program_space
*search_pspace
)
12519 internal_error_pure_virtual_called ();
12522 /* The default 'explains_signal' method. */
12525 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12530 /* The default "after_condition_true" method. */
12533 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12535 /* Nothing to do. */
12538 struct breakpoint_ops base_breakpoint_ops
=
12540 base_breakpoint_allocate_location
,
12541 base_breakpoint_re_set
,
12542 base_breakpoint_insert_location
,
12543 base_breakpoint_remove_location
,
12544 base_breakpoint_breakpoint_hit
,
12545 base_breakpoint_check_status
,
12546 base_breakpoint_resources_needed
,
12547 base_breakpoint_works_in_software_mode
,
12548 base_breakpoint_print_it
,
12550 base_breakpoint_print_one_detail
,
12551 base_breakpoint_print_mention
,
12552 base_breakpoint_print_recreate
,
12553 base_breakpoint_create_sals_from_location
,
12554 base_breakpoint_create_breakpoints_sal
,
12555 base_breakpoint_decode_location
,
12556 base_breakpoint_explains_signal
,
12557 base_breakpoint_after_condition_true
,
12560 /* Default breakpoint_ops methods. */
12563 bkpt_re_set (struct breakpoint
*b
)
12565 /* FIXME: is this still reachable? */
12566 if (breakpoint_event_location_empty_p (b
))
12568 /* Anything without a location can't be re-set. */
12569 delete_breakpoint (b
);
12573 breakpoint_re_set_default (b
);
12577 bkpt_insert_location (struct bp_location
*bl
)
12579 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12581 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12582 bl
->target_info
.placed_address
= addr
;
12584 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12585 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12587 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12591 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12593 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12594 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12596 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12600 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12601 const address_space
*aspace
, CORE_ADDR bp_addr
,
12602 const struct target_waitstatus
*ws
)
12604 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12605 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12608 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12612 if (overlay_debugging
/* unmapped overlay section */
12613 && section_is_overlay (bl
->section
)
12614 && !section_is_mapped (bl
->section
))
12621 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12622 const address_space
*aspace
, CORE_ADDR bp_addr
,
12623 const struct target_waitstatus
*ws
)
12625 if (dprintf_style
== dprintf_style_agent
12626 && target_can_run_breakpoint_commands ())
12628 /* An agent-style dprintf never causes a stop. If we see a trap
12629 for this address it must be for a breakpoint that happens to
12630 be set at the same address. */
12634 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12638 bkpt_resources_needed (const struct bp_location
*bl
)
12640 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12645 static enum print_stop_action
12646 bkpt_print_it (bpstat bs
)
12648 struct breakpoint
*b
;
12649 const struct bp_location
*bl
;
12651 struct ui_out
*uiout
= current_uiout
;
12653 gdb_assert (bs
->bp_location_at
!= NULL
);
12655 bl
= bs
->bp_location_at
.get ();
12656 b
= bs
->breakpoint_at
;
12658 bp_temp
= b
->disposition
== disp_del
;
12659 if (bl
->address
!= bl
->requested_address
)
12660 breakpoint_adjustment_warning (bl
->requested_address
,
12663 annotate_breakpoint (b
->number
);
12664 maybe_print_thread_hit_breakpoint (uiout
);
12666 if (uiout
->is_mi_like_p ())
12668 uiout
->field_string ("reason",
12669 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12670 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12673 uiout
->message ("Temporary breakpoint %pF, ",
12674 signed_field ("bkptno", b
->number
));
12676 uiout
->message ("Breakpoint %pF, ",
12677 signed_field ("bkptno", b
->number
));
12679 return PRINT_SRC_AND_LOC
;
12683 bkpt_print_mention (struct breakpoint
*b
)
12685 if (current_uiout
->is_mi_like_p ())
12690 case bp_breakpoint
:
12691 case bp_gnu_ifunc_resolver
:
12692 if (b
->disposition
== disp_del
)
12693 printf_filtered (_("Temporary breakpoint"));
12695 printf_filtered (_("Breakpoint"));
12696 printf_filtered (_(" %d"), b
->number
);
12697 if (b
->type
== bp_gnu_ifunc_resolver
)
12698 printf_filtered (_(" at gnu-indirect-function resolver"));
12700 case bp_hardware_breakpoint
:
12701 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12704 printf_filtered (_("Dprintf %d"), b
->number
);
12712 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12714 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12715 fprintf_unfiltered (fp
, "tbreak");
12716 else if (tp
->type
== bp_breakpoint
)
12717 fprintf_unfiltered (fp
, "break");
12718 else if (tp
->type
== bp_hardware_breakpoint
12719 && tp
->disposition
== disp_del
)
12720 fprintf_unfiltered (fp
, "thbreak");
12721 else if (tp
->type
== bp_hardware_breakpoint
)
12722 fprintf_unfiltered (fp
, "hbreak");
12724 internal_error (__FILE__
, __LINE__
,
12725 _("unhandled breakpoint type %d"), (int) tp
->type
);
12727 fprintf_unfiltered (fp
, " %s",
12728 event_location_to_string (tp
->location
.get ()));
12730 /* Print out extra_string if this breakpoint is pending. It might
12731 contain, for example, conditions that were set by the user. */
12732 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12733 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12735 print_recreate_thread (tp
, fp
);
12739 bkpt_create_sals_from_location (struct event_location
*location
,
12740 struct linespec_result
*canonical
,
12741 enum bptype type_wanted
)
12743 create_sals_from_location_default (location
, canonical
, type_wanted
);
12747 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12748 struct linespec_result
*canonical
,
12749 gdb::unique_xmalloc_ptr
<char> cond_string
,
12750 gdb::unique_xmalloc_ptr
<char> extra_string
,
12751 enum bptype type_wanted
,
12752 enum bpdisp disposition
,
12754 int task
, int ignore_count
,
12755 const struct breakpoint_ops
*ops
,
12756 int from_tty
, int enabled
,
12757 int internal
, unsigned flags
)
12759 create_breakpoints_sal_default (gdbarch
, canonical
,
12760 std::move (cond_string
),
12761 std::move (extra_string
),
12763 disposition
, thread
, task
,
12764 ignore_count
, ops
, from_tty
,
12765 enabled
, internal
, flags
);
12768 static std::vector
<symtab_and_line
>
12769 bkpt_decode_location (struct breakpoint
*b
,
12770 struct event_location
*location
,
12771 struct program_space
*search_pspace
)
12773 return decode_location_default (b
, location
, search_pspace
);
12776 /* Virtual table for internal breakpoints. */
12779 internal_bkpt_re_set (struct breakpoint
*b
)
12783 /* Delete overlay event and longjmp master breakpoints; they
12784 will be reset later by breakpoint_re_set. */
12785 case bp_overlay_event
:
12786 case bp_longjmp_master
:
12787 case bp_std_terminate_master
:
12788 case bp_exception_master
:
12789 delete_breakpoint (b
);
12792 /* This breakpoint is special, it's set up when the inferior
12793 starts and we really don't want to touch it. */
12794 case bp_shlib_event
:
12796 /* Like bp_shlib_event, this breakpoint type is special. Once
12797 it is set up, we do not want to touch it. */
12798 case bp_thread_event
:
12804 internal_bkpt_check_status (bpstat bs
)
12806 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12808 /* If requested, stop when the dynamic linker notifies GDB of
12809 events. This allows the user to get control and place
12810 breakpoints in initializer routines for dynamically loaded
12811 objects (among other things). */
12812 bs
->stop
= stop_on_solib_events
;
12813 bs
->print
= stop_on_solib_events
;
12819 static enum print_stop_action
12820 internal_bkpt_print_it (bpstat bs
)
12822 struct breakpoint
*b
;
12824 b
= bs
->breakpoint_at
;
12828 case bp_shlib_event
:
12829 /* Did we stop because the user set the stop_on_solib_events
12830 variable? (If so, we report this as a generic, "Stopped due
12831 to shlib event" message.) */
12832 print_solib_event (0);
12835 case bp_thread_event
:
12836 /* Not sure how we will get here.
12837 GDB should not stop for these breakpoints. */
12838 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12841 case bp_overlay_event
:
12842 /* By analogy with the thread event, GDB should not stop for these. */
12843 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12846 case bp_longjmp_master
:
12847 /* These should never be enabled. */
12848 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12851 case bp_std_terminate_master
:
12852 /* These should never be enabled. */
12853 printf_filtered (_("std::terminate Master Breakpoint: "
12854 "gdb should not stop!\n"));
12857 case bp_exception_master
:
12858 /* These should never be enabled. */
12859 printf_filtered (_("Exception Master Breakpoint: "
12860 "gdb should not stop!\n"));
12864 return PRINT_NOTHING
;
12868 internal_bkpt_print_mention (struct breakpoint
*b
)
12870 /* Nothing to mention. These breakpoints are internal. */
12873 /* Virtual table for momentary breakpoints */
12876 momentary_bkpt_re_set (struct breakpoint
*b
)
12878 /* Keep temporary breakpoints, which can be encountered when we step
12879 over a dlopen call and solib_add is resetting the breakpoints.
12880 Otherwise these should have been blown away via the cleanup chain
12881 or by breakpoint_init_inferior when we rerun the executable. */
12885 momentary_bkpt_check_status (bpstat bs
)
12887 /* Nothing. The point of these breakpoints is causing a stop. */
12890 static enum print_stop_action
12891 momentary_bkpt_print_it (bpstat bs
)
12893 return PRINT_UNKNOWN
;
12897 momentary_bkpt_print_mention (struct breakpoint
*b
)
12899 /* Nothing to mention. These breakpoints are internal. */
12902 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12904 It gets cleared already on the removal of the first one of such placed
12905 breakpoints. This is OK as they get all removed altogether. */
12907 longjmp_breakpoint::~longjmp_breakpoint ()
12909 thread_info
*tp
= find_thread_global_id (this->thread
);
12912 tp
->initiating_frame
= null_frame_id
;
12915 /* Specific methods for probe breakpoints. */
12918 bkpt_probe_insert_location (struct bp_location
*bl
)
12920 int v
= bkpt_insert_location (bl
);
12924 /* The insertion was successful, now let's set the probe's semaphore
12926 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12933 bkpt_probe_remove_location (struct bp_location
*bl
,
12934 enum remove_bp_reason reason
)
12936 /* Let's clear the semaphore before removing the location. */
12937 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12939 return bkpt_remove_location (bl
, reason
);
12943 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12944 struct linespec_result
*canonical
,
12945 enum bptype type_wanted
)
12947 struct linespec_sals lsal
;
12949 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12951 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12952 canonical
->lsals
.push_back (std::move (lsal
));
12955 static std::vector
<symtab_and_line
>
12956 bkpt_probe_decode_location (struct breakpoint
*b
,
12957 struct event_location
*location
,
12958 struct program_space
*search_pspace
)
12960 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12962 error (_("probe not found"));
12966 /* The breakpoint_ops structure to be used in tracepoints. */
12969 tracepoint_re_set (struct breakpoint
*b
)
12971 breakpoint_re_set_default (b
);
12975 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12976 const address_space
*aspace
, CORE_ADDR bp_addr
,
12977 const struct target_waitstatus
*ws
)
12979 /* By definition, the inferior does not report stops at
12985 tracepoint_print_one_detail (const struct breakpoint
*self
,
12986 struct ui_out
*uiout
)
12988 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12989 if (!tp
->static_trace_marker_id
.empty ())
12991 gdb_assert (self
->type
== bp_static_tracepoint
);
12993 uiout
->message ("\tmarker id is %pF\n",
12994 string_field ("static-tracepoint-marker-string-id",
12995 tp
->static_trace_marker_id
.c_str ()));
13000 tracepoint_print_mention (struct breakpoint
*b
)
13002 if (current_uiout
->is_mi_like_p ())
13007 case bp_tracepoint
:
13008 printf_filtered (_("Tracepoint"));
13009 printf_filtered (_(" %d"), b
->number
);
13011 case bp_fast_tracepoint
:
13012 printf_filtered (_("Fast tracepoint"));
13013 printf_filtered (_(" %d"), b
->number
);
13015 case bp_static_tracepoint
:
13016 printf_filtered (_("Static tracepoint"));
13017 printf_filtered (_(" %d"), b
->number
);
13020 internal_error (__FILE__
, __LINE__
,
13021 _("unhandled tracepoint type %d"), (int) b
->type
);
13028 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13030 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13032 if (self
->type
== bp_fast_tracepoint
)
13033 fprintf_unfiltered (fp
, "ftrace");
13034 else if (self
->type
== bp_static_tracepoint
)
13035 fprintf_unfiltered (fp
, "strace");
13036 else if (self
->type
== bp_tracepoint
)
13037 fprintf_unfiltered (fp
, "trace");
13039 internal_error (__FILE__
, __LINE__
,
13040 _("unhandled tracepoint type %d"), (int) self
->type
);
13042 fprintf_unfiltered (fp
, " %s",
13043 event_location_to_string (self
->location
.get ()));
13044 print_recreate_thread (self
, fp
);
13046 if (tp
->pass_count
)
13047 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13051 tracepoint_create_sals_from_location (struct event_location
*location
,
13052 struct linespec_result
*canonical
,
13053 enum bptype type_wanted
)
13055 create_sals_from_location_default (location
, canonical
, type_wanted
);
13059 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13060 struct linespec_result
*canonical
,
13061 gdb::unique_xmalloc_ptr
<char> cond_string
,
13062 gdb::unique_xmalloc_ptr
<char> extra_string
,
13063 enum bptype type_wanted
,
13064 enum bpdisp disposition
,
13066 int task
, int ignore_count
,
13067 const struct breakpoint_ops
*ops
,
13068 int from_tty
, int enabled
,
13069 int internal
, unsigned flags
)
13071 create_breakpoints_sal_default (gdbarch
, canonical
,
13072 std::move (cond_string
),
13073 std::move (extra_string
),
13075 disposition
, thread
, task
,
13076 ignore_count
, ops
, from_tty
,
13077 enabled
, internal
, flags
);
13080 static std::vector
<symtab_and_line
>
13081 tracepoint_decode_location (struct breakpoint
*b
,
13082 struct event_location
*location
,
13083 struct program_space
*search_pspace
)
13085 return decode_location_default (b
, location
, search_pspace
);
13088 struct breakpoint_ops tracepoint_breakpoint_ops
;
13090 /* Virtual table for tracepoints on static probes. */
13093 tracepoint_probe_create_sals_from_location
13094 (struct event_location
*location
,
13095 struct linespec_result
*canonical
,
13096 enum bptype type_wanted
)
13098 /* We use the same method for breakpoint on probes. */
13099 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13102 static std::vector
<symtab_and_line
>
13103 tracepoint_probe_decode_location (struct breakpoint
*b
,
13104 struct event_location
*location
,
13105 struct program_space
*search_pspace
)
13107 /* We use the same method for breakpoint on probes. */
13108 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13111 /* Dprintf breakpoint_ops methods. */
13114 dprintf_re_set (struct breakpoint
*b
)
13116 breakpoint_re_set_default (b
);
13118 /* extra_string should never be non-NULL for dprintf. */
13119 gdb_assert (b
->extra_string
!= NULL
);
13121 /* 1 - connect to target 1, that can run breakpoint commands.
13122 2 - create a dprintf, which resolves fine.
13123 3 - disconnect from target 1
13124 4 - connect to target 2, that can NOT run breakpoint commands.
13126 After steps #3/#4, you'll want the dprintf command list to
13127 be updated, because target 1 and 2 may well return different
13128 answers for target_can_run_breakpoint_commands().
13129 Given absence of finer grained resetting, we get to do
13130 it all the time. */
13131 if (b
->extra_string
!= NULL
)
13132 update_dprintf_command_list (b
);
13135 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13138 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13140 fprintf_unfiltered (fp
, "dprintf %s,%s",
13141 event_location_to_string (tp
->location
.get ()),
13143 print_recreate_thread (tp
, fp
);
13146 /* Implement the "after_condition_true" breakpoint_ops method for
13149 dprintf's are implemented with regular commands in their command
13150 list, but we run the commands here instead of before presenting the
13151 stop to the user, as dprintf's don't actually cause a stop. This
13152 also makes it so that the commands of multiple dprintfs at the same
13153 address are all handled. */
13156 dprintf_after_condition_true (struct bpstats
*bs
)
13158 struct bpstats tmp_bs
;
13159 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13161 /* dprintf's never cause a stop. This wasn't set in the
13162 check_status hook instead because that would make the dprintf's
13163 condition not be evaluated. */
13166 /* Run the command list here. Take ownership of it instead of
13167 copying. We never want these commands to run later in
13168 bpstat_do_actions, if a breakpoint that causes a stop happens to
13169 be set at same address as this dprintf, or even if running the
13170 commands here throws. */
13171 tmp_bs
.commands
= bs
->commands
;
13172 bs
->commands
= NULL
;
13174 bpstat_do_actions_1 (&tmp_bs_p
);
13176 /* 'tmp_bs.commands' will usually be NULL by now, but
13177 bpstat_do_actions_1 may return early without processing the whole
13181 /* The breakpoint_ops structure to be used on static tracepoints with
13185 strace_marker_create_sals_from_location (struct event_location
*location
,
13186 struct linespec_result
*canonical
,
13187 enum bptype type_wanted
)
13189 struct linespec_sals lsal
;
13190 const char *arg_start
, *arg
;
13192 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
13193 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13195 std::string
str (arg_start
, arg
- arg_start
);
13196 const char *ptr
= str
.c_str ();
13197 canonical
->location
13198 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
13201 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13202 canonical
->lsals
.push_back (std::move (lsal
));
13206 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13207 struct linespec_result
*canonical
,
13208 gdb::unique_xmalloc_ptr
<char> cond_string
,
13209 gdb::unique_xmalloc_ptr
<char> extra_string
,
13210 enum bptype type_wanted
,
13211 enum bpdisp disposition
,
13213 int task
, int ignore_count
,
13214 const struct breakpoint_ops
*ops
,
13215 int from_tty
, int enabled
,
13216 int internal
, unsigned flags
)
13218 const linespec_sals
&lsal
= canonical
->lsals
[0];
13220 /* If the user is creating a static tracepoint by marker id
13221 (strace -m MARKER_ID), then store the sals index, so that
13222 breakpoint_re_set can try to match up which of the newly
13223 found markers corresponds to this one, and, don't try to
13224 expand multiple locations for each sal, given than SALS
13225 already should contain all sals for MARKER_ID. */
13227 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13229 event_location_up location
13230 = copy_event_location (canonical
->location
.get ());
13232 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13233 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13234 std::move (location
), NULL
,
13235 std::move (cond_string
),
13236 std::move (extra_string
),
13237 type_wanted
, disposition
,
13238 thread
, task
, ignore_count
, ops
,
13239 from_tty
, enabled
, internal
, flags
,
13240 canonical
->special_display
);
13241 /* Given that its possible to have multiple markers with
13242 the same string id, if the user is creating a static
13243 tracepoint by marker id ("strace -m MARKER_ID"), then
13244 store the sals index, so that breakpoint_re_set can
13245 try to match up which of the newly found markers
13246 corresponds to this one */
13247 tp
->static_trace_marker_id_idx
= i
;
13249 install_breakpoint (internal
, std::move (tp
), 0);
13253 static std::vector
<symtab_and_line
>
13254 strace_marker_decode_location (struct breakpoint
*b
,
13255 struct event_location
*location
,
13256 struct program_space
*search_pspace
)
13258 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13259 const char *s
= get_linespec_location (location
)->spec_string
;
13261 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13262 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13264 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13269 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
13272 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13275 strace_marker_p (struct breakpoint
*b
)
13277 return b
->ops
== &strace_marker_breakpoint_ops
;
13280 /* Delete a breakpoint and clean up all traces of it in the data
13284 delete_breakpoint (struct breakpoint
*bpt
)
13286 struct breakpoint
*b
;
13288 gdb_assert (bpt
!= NULL
);
13290 /* Has this bp already been deleted? This can happen because
13291 multiple lists can hold pointers to bp's. bpstat lists are
13294 One example of this happening is a watchpoint's scope bp. When
13295 the scope bp triggers, we notice that the watchpoint is out of
13296 scope, and delete it. We also delete its scope bp. But the
13297 scope bp is marked "auto-deleting", and is already on a bpstat.
13298 That bpstat is then checked for auto-deleting bp's, which are
13301 A real solution to this problem might involve reference counts in
13302 bp's, and/or giving them pointers back to their referencing
13303 bpstat's, and teaching delete_breakpoint to only free a bp's
13304 storage when no more references were extent. A cheaper bandaid
13306 if (bpt
->type
== bp_none
)
13309 /* At least avoid this stale reference until the reference counting
13310 of breakpoints gets resolved. */
13311 if (bpt
->related_breakpoint
!= bpt
)
13313 struct breakpoint
*related
;
13314 struct watchpoint
*w
;
13316 if (bpt
->type
== bp_watchpoint_scope
)
13317 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13318 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13319 w
= (struct watchpoint
*) bpt
;
13323 watchpoint_del_at_next_stop (w
);
13325 /* Unlink bpt from the bpt->related_breakpoint ring. */
13326 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13327 related
= related
->related_breakpoint
);
13328 related
->related_breakpoint
= bpt
->related_breakpoint
;
13329 bpt
->related_breakpoint
= bpt
;
13332 /* watch_command_1 creates a watchpoint but only sets its number if
13333 update_watchpoint succeeds in creating its bp_locations. If there's
13334 a problem in that process, we'll be asked to delete the half-created
13335 watchpoint. In that case, don't announce the deletion. */
13337 gdb::observers::breakpoint_deleted
.notify (bpt
);
13339 if (breakpoint_chain
== bpt
)
13340 breakpoint_chain
= bpt
->next
;
13342 ALL_BREAKPOINTS (b
)
13343 if (b
->next
== bpt
)
13345 b
->next
= bpt
->next
;
13349 /* Be sure no bpstat's are pointing at the breakpoint after it's
13351 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13352 in all threads for now. Note that we cannot just remove bpstats
13353 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13354 commands are associated with the bpstat; if we remove it here,
13355 then the later call to bpstat_do_actions (&stop_bpstat); in
13356 event-top.c won't do anything, and temporary breakpoints with
13357 commands won't work. */
13359 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13361 /* Now that breakpoint is removed from breakpoint list, update the
13362 global location list. This will remove locations that used to
13363 belong to this breakpoint. Do this before freeing the breakpoint
13364 itself, since remove_breakpoint looks at location's owner. It
13365 might be better design to have location completely
13366 self-contained, but it's not the case now. */
13367 update_global_location_list (UGLL_DONT_INSERT
);
13369 /* On the chance that someone will soon try again to delete this
13370 same bp, we mark it as deleted before freeing its storage. */
13371 bpt
->type
= bp_none
;
13375 /* Iterator function to call a user-provided callback function once
13376 for each of B and its related breakpoints. */
13379 iterate_over_related_breakpoints (struct breakpoint
*b
,
13380 gdb::function_view
<void (breakpoint
*)> function
)
13382 struct breakpoint
*related
;
13387 struct breakpoint
*next
;
13389 /* FUNCTION may delete RELATED. */
13390 next
= related
->related_breakpoint
;
13392 if (next
== related
)
13394 /* RELATED is the last ring entry. */
13395 function (related
);
13397 /* FUNCTION may have deleted it, so we'd never reach back to
13398 B. There's nothing left to do anyway, so just break
13403 function (related
);
13407 while (related
!= b
);
13411 delete_command (const char *arg
, int from_tty
)
13413 struct breakpoint
*b
, *b_tmp
;
13419 int breaks_to_delete
= 0;
13421 /* Delete all breakpoints if no argument. Do not delete
13422 internal breakpoints, these have to be deleted with an
13423 explicit breakpoint number argument. */
13424 ALL_BREAKPOINTS (b
)
13425 if (user_breakpoint_p (b
))
13427 breaks_to_delete
= 1;
13431 /* Ask user only if there are some breakpoints to delete. */
13433 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13435 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13436 if (user_breakpoint_p (b
))
13437 delete_breakpoint (b
);
13441 map_breakpoint_numbers
13442 (arg
, [&] (breakpoint
*br
)
13444 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13448 /* Return true if all locations of B bound to PSPACE are pending. If
13449 PSPACE is NULL, all locations of all program spaces are
13453 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13455 struct bp_location
*loc
;
13457 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13458 if ((pspace
== NULL
13459 || loc
->pspace
== pspace
)
13460 && !loc
->shlib_disabled
13461 && !loc
->pspace
->executing_startup
)
13466 /* Subroutine of update_breakpoint_locations to simplify it.
13467 Return non-zero if multiple fns in list LOC have the same name.
13468 Null names are ignored. */
13471 ambiguous_names_p (struct bp_location
*loc
)
13473 struct bp_location
*l
;
13474 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
13477 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13480 const char *name
= l
->function_name
;
13482 /* Allow for some names to be NULL, ignore them. */
13486 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
13488 /* NOTE: We can assume slot != NULL here because xcalloc never
13498 /* When symbols change, it probably means the sources changed as well,
13499 and it might mean the static tracepoint markers are no longer at
13500 the same address or line numbers they used to be at last we
13501 checked. Losing your static tracepoints whenever you rebuild is
13502 undesirable. This function tries to resync/rematch gdb static
13503 tracepoints with the markers on the target, for static tracepoints
13504 that have not been set by marker id. Static tracepoint that have
13505 been set by marker id are reset by marker id in breakpoint_re_set.
13508 1) For a tracepoint set at a specific address, look for a marker at
13509 the old PC. If one is found there, assume to be the same marker.
13510 If the name / string id of the marker found is different from the
13511 previous known name, assume that means the user renamed the marker
13512 in the sources, and output a warning.
13514 2) For a tracepoint set at a given line number, look for a marker
13515 at the new address of the old line number. If one is found there,
13516 assume to be the same marker. If the name / string id of the
13517 marker found is different from the previous known name, assume that
13518 means the user renamed the marker in the sources, and output a
13521 3) If a marker is no longer found at the same address or line, it
13522 may mean the marker no longer exists. But it may also just mean
13523 the code changed a bit. Maybe the user added a few lines of code
13524 that made the marker move up or down (in line number terms). Ask
13525 the target for info about the marker with the string id as we knew
13526 it. If found, update line number and address in the matching
13527 static tracepoint. This will get confused if there's more than one
13528 marker with the same ID (possible in UST, although unadvised
13529 precisely because it confuses tools). */
13531 static struct symtab_and_line
13532 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13534 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13535 struct static_tracepoint_marker marker
;
13540 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13542 if (target_static_tracepoint_marker_at (pc
, &marker
))
13544 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13545 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13546 b
->number
, tp
->static_trace_marker_id
.c_str (),
13547 marker
.str_id
.c_str ());
13549 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13554 /* Old marker wasn't found on target at lineno. Try looking it up
13556 if (!sal
.explicit_pc
13558 && sal
.symtab
!= NULL
13559 && !tp
->static_trace_marker_id
.empty ())
13561 std::vector
<static_tracepoint_marker
> markers
13562 = target_static_tracepoint_markers_by_strid
13563 (tp
->static_trace_marker_id
.c_str ());
13565 if (!markers
.empty ())
13567 struct symbol
*sym
;
13568 struct static_tracepoint_marker
*tpmarker
;
13569 struct ui_out
*uiout
= current_uiout
;
13570 struct explicit_location explicit_loc
;
13572 tpmarker
= &markers
[0];
13574 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13576 warning (_("marker for static tracepoint %d (%s) not "
13577 "found at previous line number"),
13578 b
->number
, tp
->static_trace_marker_id
.c_str ());
13580 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13581 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13582 uiout
->text ("Now in ");
13585 uiout
->field_string ("func", sym
->print_name (),
13586 function_name_style
.style ());
13587 uiout
->text (" at ");
13589 uiout
->field_string ("file",
13590 symtab_to_filename_for_display (sal2
.symtab
),
13591 file_name_style
.style ());
13594 if (uiout
->is_mi_like_p ())
13596 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13598 uiout
->field_string ("fullname", fullname
);
13601 uiout
->field_signed ("line", sal2
.line
);
13602 uiout
->text ("\n");
13604 b
->loc
->line_number
= sal2
.line
;
13605 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13607 b
->location
.reset (NULL
);
13608 initialize_explicit_location (&explicit_loc
);
13609 explicit_loc
.source_filename
13610 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13611 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13612 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13613 b
->location
= new_explicit_location (&explicit_loc
);
13615 /* Might be nice to check if function changed, and warn if
13622 /* Returns 1 iff locations A and B are sufficiently same that
13623 we don't need to report breakpoint as changed. */
13626 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13630 if (a
->address
!= b
->address
)
13633 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13636 if (a
->enabled
!= b
->enabled
)
13639 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
13646 if ((a
== NULL
) != (b
== NULL
))
13652 /* Split all locations of B that are bound to PSPACE out of B's
13653 location list to a separate list and return that list's head. If
13654 PSPACE is NULL, hoist out all locations of B. */
13656 static struct bp_location
*
13657 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13659 struct bp_location head
;
13660 struct bp_location
*i
= b
->loc
;
13661 struct bp_location
**i_link
= &b
->loc
;
13662 struct bp_location
*hoisted
= &head
;
13664 if (pspace
== NULL
)
13675 if (i
->pspace
== pspace
)
13690 /* Create new breakpoint locations for B (a hardware or software
13691 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13692 zero, then B is a ranged breakpoint. Only recreates locations for
13693 FILTER_PSPACE. Locations of other program spaces are left
13697 update_breakpoint_locations (struct breakpoint
*b
,
13698 struct program_space
*filter_pspace
,
13699 gdb::array_view
<const symtab_and_line
> sals
,
13700 gdb::array_view
<const symtab_and_line
> sals_end
)
13702 struct bp_location
*existing_locations
;
13704 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13706 /* Ranged breakpoints have only one start location and one end
13708 b
->enable_state
= bp_disabled
;
13709 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13710 "multiple locations found\n"),
13715 /* If there's no new locations, and all existing locations are
13716 pending, don't do anything. This optimizes the common case where
13717 all locations are in the same shared library, that was unloaded.
13718 We'd like to retain the location, so that when the library is
13719 loaded again, we don't loose the enabled/disabled status of the
13720 individual locations. */
13721 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13724 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13726 for (const auto &sal
: sals
)
13728 struct bp_location
*new_loc
;
13730 switch_to_program_space_and_thread (sal
.pspace
);
13732 new_loc
= add_location_to_breakpoint (b
, &sal
);
13734 /* Reparse conditions, they might contain references to the
13736 if (b
->cond_string
!= NULL
)
13740 s
= b
->cond_string
;
13743 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13744 block_for_pc (sal
.pc
),
13747 catch (const gdb_exception_error
&e
)
13749 new_loc
->disabled_by_cond
= true;
13753 if (!sals_end
.empty ())
13755 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13757 new_loc
->length
= end
- sals
[0].pc
+ 1;
13761 /* If possible, carry over 'disable' status from existing
13764 struct bp_location
*e
= existing_locations
;
13765 /* If there are multiple breakpoints with the same function name,
13766 e.g. for inline functions, comparing function names won't work.
13767 Instead compare pc addresses; this is just a heuristic as things
13768 may have moved, but in practice it gives the correct answer
13769 often enough until a better solution is found. */
13770 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13772 for (; e
; e
= e
->next
)
13774 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
13776 struct bp_location
*l
= b
->loc
;
13777 if (have_ambiguous_names
)
13779 for (; l
; l
= l
->next
)
13781 /* Ignore software vs hardware location type at
13782 this point, because with "set breakpoint
13783 auto-hw", after a re-set, locations that were
13784 hardware can end up as software, or vice versa.
13785 As mentioned above, this is an heuristic and in
13786 practice should give the correct answer often
13788 if (breakpoint_locations_match (e
, l
, true))
13790 l
->enabled
= e
->enabled
;
13791 l
->disabled_by_cond
= e
->disabled_by_cond
;
13798 for (; l
; l
= l
->next
)
13799 if (l
->function_name
13800 && strcmp (e
->function_name
, l
->function_name
) == 0)
13802 l
->enabled
= e
->enabled
;
13803 l
->disabled_by_cond
= e
->disabled_by_cond
;
13811 if (!locations_are_equal (existing_locations
, b
->loc
))
13812 gdb::observers::breakpoint_modified
.notify (b
);
13815 /* Find the SaL locations corresponding to the given LOCATION.
13816 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13818 static std::vector
<symtab_and_line
>
13819 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13820 struct program_space
*search_pspace
, int *found
)
13822 struct gdb_exception exception
;
13824 gdb_assert (b
->ops
!= NULL
);
13826 std::vector
<symtab_and_line
> sals
;
13830 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13832 catch (gdb_exception_error
&e
)
13834 int not_found_and_ok
= 0;
13836 /* For pending breakpoints, it's expected that parsing will
13837 fail until the right shared library is loaded. User has
13838 already told to create pending breakpoints and don't need
13839 extra messages. If breakpoint is in bp_shlib_disabled
13840 state, then user already saw the message about that
13841 breakpoint being disabled, and don't want to see more
13843 if (e
.error
== NOT_FOUND_ERROR
13844 && (b
->condition_not_parsed
13846 && search_pspace
!= NULL
13847 && b
->loc
->pspace
!= search_pspace
)
13848 || (b
->loc
&& b
->loc
->shlib_disabled
)
13849 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13850 || b
->enable_state
== bp_disabled
))
13851 not_found_and_ok
= 1;
13853 if (!not_found_and_ok
)
13855 /* We surely don't want to warn about the same breakpoint
13856 10 times. One solution, implemented here, is disable
13857 the breakpoint on error. Another solution would be to
13858 have separate 'warning emitted' flag. Since this
13859 happens only when a binary has changed, I don't know
13860 which approach is better. */
13861 b
->enable_state
= bp_disabled
;
13865 exception
= std::move (e
);
13868 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13870 for (auto &sal
: sals
)
13871 resolve_sal_pc (&sal
);
13872 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13874 char *cond_string
, *extra_string
;
13877 find_condition_and_thread_for_sals (sals
, b
->extra_string
,
13878 &cond_string
, &thread
,
13879 &task
, &extra_string
);
13880 gdb_assert (b
->cond_string
== NULL
);
13882 b
->cond_string
= cond_string
;
13883 b
->thread
= thread
;
13887 xfree (b
->extra_string
);
13888 b
->extra_string
= extra_string
;
13890 b
->condition_not_parsed
= 0;
13893 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13894 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13904 /* The default re_set method, for typical hardware or software
13905 breakpoints. Reevaluate the breakpoint and recreate its
13909 breakpoint_re_set_default (struct breakpoint
*b
)
13911 struct program_space
*filter_pspace
= current_program_space
;
13912 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13915 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13916 filter_pspace
, &found
);
13918 expanded
= std::move (sals
);
13920 if (b
->location_range_end
!= NULL
)
13922 std::vector
<symtab_and_line
> sals_end
13923 = location_to_sals (b
, b
->location_range_end
.get (),
13924 filter_pspace
, &found
);
13926 expanded_end
= std::move (sals_end
);
13929 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13932 /* Default method for creating SALs from an address string. It basically
13933 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13936 create_sals_from_location_default (struct event_location
*location
,
13937 struct linespec_result
*canonical
,
13938 enum bptype type_wanted
)
13940 parse_breakpoint_sals (location
, canonical
);
13943 /* Call create_breakpoints_sal for the given arguments. This is the default
13944 function for the `create_breakpoints_sal' method of
13948 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13949 struct linespec_result
*canonical
,
13950 gdb::unique_xmalloc_ptr
<char> cond_string
,
13951 gdb::unique_xmalloc_ptr
<char> extra_string
,
13952 enum bptype type_wanted
,
13953 enum bpdisp disposition
,
13955 int task
, int ignore_count
,
13956 const struct breakpoint_ops
*ops
,
13957 int from_tty
, int enabled
,
13958 int internal
, unsigned flags
)
13960 create_breakpoints_sal (gdbarch
, canonical
,
13961 std::move (cond_string
),
13962 std::move (extra_string
),
13963 type_wanted
, disposition
,
13964 thread
, task
, ignore_count
, ops
, from_tty
,
13965 enabled
, internal
, flags
);
13968 /* Decode the line represented by S by calling decode_line_full. This is the
13969 default function for the `decode_location' method of breakpoint_ops. */
13971 static std::vector
<symtab_and_line
>
13972 decode_location_default (struct breakpoint
*b
,
13973 struct event_location
*location
,
13974 struct program_space
*search_pspace
)
13976 struct linespec_result canonical
;
13978 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13979 NULL
, 0, &canonical
, multiple_symbols_all
,
13982 /* We should get 0 or 1 resulting SALs. */
13983 gdb_assert (canonical
.lsals
.size () < 2);
13985 if (!canonical
.lsals
.empty ())
13987 const linespec_sals
&lsal
= canonical
.lsals
[0];
13988 return std::move (lsal
.sals
);
13993 /* Reset a breakpoint. */
13996 breakpoint_re_set_one (breakpoint
*b
)
13998 input_radix
= b
->input_radix
;
13999 set_language (b
->language
);
14001 b
->ops
->re_set (b
);
14004 /* Re-set breakpoint locations for the current program space.
14005 Locations bound to other program spaces are left untouched. */
14008 breakpoint_re_set (void)
14010 struct breakpoint
*b
, *b_tmp
;
14013 scoped_restore_current_language save_language
;
14014 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
14015 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
14017 /* breakpoint_re_set_one sets the current_language to the language
14018 of the breakpoint it is resetting (see prepare_re_set_context)
14019 before re-evaluating the breakpoint's location. This change can
14020 unfortunately get undone by accident if the language_mode is set
14021 to auto, and we either switch frames, or more likely in this context,
14022 we select the current frame.
14024 We prevent this by temporarily turning the language_mode to
14025 language_mode_manual. We restore it once all breakpoints
14026 have been reset. */
14027 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
14028 language_mode
= language_mode_manual
;
14030 /* Note: we must not try to insert locations until after all
14031 breakpoints have been re-set. Otherwise, e.g., when re-setting
14032 breakpoint 1, we'd insert the locations of breakpoint 2, which
14033 hadn't been re-set yet, and thus may have stale locations. */
14035 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14039 breakpoint_re_set_one (b
);
14041 catch (const gdb_exception
&ex
)
14043 exception_fprintf (gdb_stderr
, ex
,
14044 "Error in re-setting breakpoint %d: ",
14049 jit_breakpoint_re_set ();
14052 create_overlay_event_breakpoint ();
14053 create_longjmp_master_breakpoint ();
14054 create_std_terminate_master_breakpoint ();
14055 create_exception_master_breakpoint ();
14057 /* Now we can insert. */
14058 update_global_location_list (UGLL_MAY_INSERT
);
14061 /* Reset the thread number of this breakpoint:
14063 - If the breakpoint is for all threads, leave it as-is.
14064 - Else, reset it to the current thread for inferior_ptid. */
14066 breakpoint_re_set_thread (struct breakpoint
*b
)
14068 if (b
->thread
!= -1)
14070 b
->thread
= inferior_thread ()->global_num
;
14072 /* We're being called after following a fork. The new fork is
14073 selected as current, and unless this was a vfork will have a
14074 different program space from the original thread. Reset that
14076 b
->loc
->pspace
= current_program_space
;
14080 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14081 If from_tty is nonzero, it prints a message to that effect,
14082 which ends with a period (no newline). */
14085 set_ignore_count (int bptnum
, int count
, int from_tty
)
14087 struct breakpoint
*b
;
14092 ALL_BREAKPOINTS (b
)
14093 if (b
->number
== bptnum
)
14095 if (is_tracepoint (b
))
14097 if (from_tty
&& count
!= 0)
14098 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14103 b
->ignore_count
= count
;
14107 printf_filtered (_("Will stop next time "
14108 "breakpoint %d is reached."),
14110 else if (count
== 1)
14111 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14114 printf_filtered (_("Will ignore next %d "
14115 "crossings of breakpoint %d."),
14118 gdb::observers::breakpoint_modified
.notify (b
);
14122 error (_("No breakpoint number %d."), bptnum
);
14125 /* Command to set ignore-count of breakpoint N to COUNT. */
14128 ignore_command (const char *args
, int from_tty
)
14130 const char *p
= args
;
14134 error_no_arg (_("a breakpoint number"));
14136 num
= get_number (&p
);
14138 error (_("bad breakpoint number: '%s'"), args
);
14140 error (_("Second argument (specified ignore-count) is missing."));
14142 set_ignore_count (num
,
14143 longest_to_int (value_as_long (parse_and_eval (p
))),
14146 printf_filtered ("\n");
14150 /* Call FUNCTION on each of the breakpoints with numbers in the range
14151 defined by BP_NUM_RANGE (an inclusive range). */
14154 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
14155 gdb::function_view
<void (breakpoint
*)> function
)
14157 if (bp_num_range
.first
== 0)
14159 warning (_("bad breakpoint number at or near '%d'"),
14160 bp_num_range
.first
);
14164 struct breakpoint
*b
, *tmp
;
14166 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
14168 bool match
= false;
14170 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14171 if (b
->number
== i
)
14178 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
14183 /* Call FUNCTION on each of the breakpoints whose numbers are given in
14187 map_breakpoint_numbers (const char *args
,
14188 gdb::function_view
<void (breakpoint
*)> function
)
14190 if (args
== NULL
|| *args
== '\0')
14191 error_no_arg (_("one or more breakpoint numbers"));
14193 number_or_range_parser
parser (args
);
14195 while (!parser
.finished ())
14197 int num
= parser
.get_number ();
14198 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
14202 /* Return the breakpoint location structure corresponding to the
14203 BP_NUM and LOC_NUM values. */
14205 static struct bp_location
*
14206 find_location_by_number (int bp_num
, int loc_num
)
14208 struct breakpoint
*b
;
14210 ALL_BREAKPOINTS (b
)
14211 if (b
->number
== bp_num
)
14216 if (!b
|| b
->number
!= bp_num
)
14217 error (_("Bad breakpoint number '%d'"), bp_num
);
14220 error (_("Bad breakpoint location number '%d'"), loc_num
);
14223 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
14224 if (++n
== loc_num
)
14227 error (_("Bad breakpoint location number '%d'"), loc_num
);
14230 /* Modes of operation for extract_bp_num. */
14231 enum class extract_bp_kind
14233 /* Extracting a breakpoint number. */
14236 /* Extracting a location number. */
14240 /* Extract a breakpoint or location number (as determined by KIND)
14241 from the string starting at START. TRAILER is a character which
14242 can be found after the number. If you don't want a trailer, use
14243 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14244 string. This always returns a positive integer. */
14247 extract_bp_num (extract_bp_kind kind
, const char *start
,
14248 int trailer
, const char **end_out
= NULL
)
14250 const char *end
= start
;
14251 int num
= get_number_trailer (&end
, trailer
);
14253 error (kind
== extract_bp_kind::bp
14254 ? _("Negative breakpoint number '%.*s'")
14255 : _("Negative breakpoint location number '%.*s'"),
14256 int (end
- start
), start
);
14258 error (kind
== extract_bp_kind::bp
14259 ? _("Bad breakpoint number '%.*s'")
14260 : _("Bad breakpoint location number '%.*s'"),
14261 int (end
- start
), start
);
14263 if (end_out
!= NULL
)
14268 /* Extract a breakpoint or location range (as determined by KIND) in
14269 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14270 representing the (inclusive) range. The returned pair's elements
14271 are always positive integers. */
14273 static std::pair
<int, int>
14274 extract_bp_or_bp_range (extract_bp_kind kind
,
14275 const std::string
&arg
,
14276 std::string::size_type arg_offset
)
14278 std::pair
<int, int> range
;
14279 const char *bp_loc
= &arg
[arg_offset
];
14280 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14281 if (dash
!= std::string::npos
)
14283 /* bp_loc is a range (x-z). */
14284 if (arg
.length () == dash
+ 1)
14285 error (kind
== extract_bp_kind::bp
14286 ? _("Bad breakpoint number at or near: '%s'")
14287 : _("Bad breakpoint location number at or near: '%s'"),
14291 const char *start_first
= bp_loc
;
14292 const char *start_second
= &arg
[dash
+ 1];
14293 range
.first
= extract_bp_num (kind
, start_first
, '-');
14294 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14296 if (range
.first
> range
.second
)
14297 error (kind
== extract_bp_kind::bp
14298 ? _("Inverted breakpoint range at '%.*s'")
14299 : _("Inverted breakpoint location range at '%.*s'"),
14300 int (end
- start_first
), start_first
);
14304 /* bp_loc is a single value. */
14305 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14306 range
.second
= range
.first
;
14311 /* Extract the breakpoint/location range specified by ARG. Returns
14312 the breakpoint range in BP_NUM_RANGE, and the location range in
14315 ARG may be in any of the following forms:
14317 x where 'x' is a breakpoint number.
14318 x-y where 'x' and 'y' specify a breakpoint numbers range.
14319 x.y where 'x' is a breakpoint number and 'y' a location number.
14320 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14321 location number range.
14325 extract_bp_number_and_location (const std::string
&arg
,
14326 std::pair
<int, int> &bp_num_range
,
14327 std::pair
<int, int> &bp_loc_range
)
14329 std::string::size_type dot
= arg
.find ('.');
14331 if (dot
!= std::string::npos
)
14333 /* Handle 'x.y' and 'x.y-z' cases. */
14335 if (arg
.length () == dot
+ 1 || dot
== 0)
14336 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14339 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14340 bp_num_range
.second
= bp_num_range
.first
;
14342 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14347 /* Handle x and x-y cases. */
14349 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14350 bp_loc_range
.first
= 0;
14351 bp_loc_range
.second
= 0;
14355 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14356 specifies whether to enable or disable. */
14359 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14361 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14364 if (loc
->disabled_by_cond
&& enable
)
14365 error (_("Breakpoint %d's condition is invalid at location %d, "
14366 "cannot enable."), bp_num
, loc_num
);
14368 if (loc
->enabled
!= enable
)
14370 loc
->enabled
= enable
;
14371 mark_breakpoint_location_modified (loc
);
14373 if (target_supports_enable_disable_tracepoint ()
14374 && current_trace_status ()->running
&& loc
->owner
14375 && is_tracepoint (loc
->owner
))
14376 target_disable_tracepoint (loc
);
14378 update_global_location_list (UGLL_DONT_INSERT
);
14380 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14383 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14384 number of the breakpoint, and BP_LOC_RANGE specifies the
14385 (inclusive) range of location numbers of that breakpoint to
14386 enable/disable. ENABLE specifies whether to enable or disable the
14390 enable_disable_breakpoint_location_range (int bp_num
,
14391 std::pair
<int, int> &bp_loc_range
,
14394 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14395 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14398 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14399 If from_tty is nonzero, it prints a message to that effect,
14400 which ends with a period (no newline). */
14403 disable_breakpoint (struct breakpoint
*bpt
)
14405 /* Never disable a watchpoint scope breakpoint; we want to
14406 hit them when we leave scope so we can delete both the
14407 watchpoint and its scope breakpoint at that time. */
14408 if (bpt
->type
== bp_watchpoint_scope
)
14411 bpt
->enable_state
= bp_disabled
;
14413 /* Mark breakpoint locations modified. */
14414 mark_breakpoint_modified (bpt
);
14416 if (target_supports_enable_disable_tracepoint ()
14417 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14419 struct bp_location
*location
;
14421 for (location
= bpt
->loc
; location
; location
= location
->next
)
14422 target_disable_tracepoint (location
);
14425 update_global_location_list (UGLL_DONT_INSERT
);
14427 gdb::observers::breakpoint_modified
.notify (bpt
);
14430 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14431 specified in ARGS. ARGS may be in any of the formats handled by
14432 extract_bp_number_and_location. ENABLE specifies whether to enable
14433 or disable the breakpoints/locations. */
14436 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14440 struct breakpoint
*bpt
;
14442 ALL_BREAKPOINTS (bpt
)
14443 if (user_breakpoint_p (bpt
))
14446 enable_breakpoint (bpt
);
14448 disable_breakpoint (bpt
);
14453 std::string num
= extract_arg (&args
);
14455 while (!num
.empty ())
14457 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14459 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14461 if (bp_loc_range
.first
== bp_loc_range
.second
14462 && bp_loc_range
.first
== 0)
14464 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14465 map_breakpoint_number_range (bp_num_range
,
14467 ? enable_breakpoint
14468 : disable_breakpoint
);
14472 /* Handle breakpoint ids with formats 'x.y' or
14474 enable_disable_breakpoint_location_range
14475 (bp_num_range
.first
, bp_loc_range
, enable
);
14477 num
= extract_arg (&args
);
14482 /* The disable command disables the specified breakpoints/locations
14483 (or all defined breakpoints) so they're no longer effective in
14484 stopping the inferior. ARGS may be in any of the forms defined in
14485 extract_bp_number_and_location. */
14488 disable_command (const char *args
, int from_tty
)
14490 enable_disable_command (args
, from_tty
, false);
14494 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14497 int target_resources_ok
;
14499 if (bpt
->type
== bp_hardware_breakpoint
)
14502 i
= hw_breakpoint_used_count ();
14503 target_resources_ok
=
14504 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14506 if (target_resources_ok
== 0)
14507 error (_("No hardware breakpoint support in the target."));
14508 else if (target_resources_ok
< 0)
14509 error (_("Hardware breakpoints used exceeds limit."));
14512 if (is_watchpoint (bpt
))
14514 /* Initialize it just to avoid a GCC false warning. */
14515 enum enable_state orig_enable_state
= bp_disabled
;
14519 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14521 orig_enable_state
= bpt
->enable_state
;
14522 bpt
->enable_state
= bp_enabled
;
14523 update_watchpoint (w
, 1 /* reparse */);
14525 catch (const gdb_exception
&e
)
14527 bpt
->enable_state
= orig_enable_state
;
14528 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14534 bpt
->enable_state
= bp_enabled
;
14536 /* Mark breakpoint locations modified. */
14537 mark_breakpoint_modified (bpt
);
14539 if (target_supports_enable_disable_tracepoint ()
14540 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14542 struct bp_location
*location
;
14544 for (location
= bpt
->loc
; location
; location
= location
->next
)
14545 target_enable_tracepoint (location
);
14548 bpt
->disposition
= disposition
;
14549 bpt
->enable_count
= count
;
14550 update_global_location_list (UGLL_MAY_INSERT
);
14552 gdb::observers::breakpoint_modified
.notify (bpt
);
14557 enable_breakpoint (struct breakpoint
*bpt
)
14559 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14562 /* The enable command enables the specified breakpoints/locations (or
14563 all defined breakpoints) so they once again become (or continue to
14564 be) effective in stopping the inferior. ARGS may be in any of the
14565 forms defined in extract_bp_number_and_location. */
14568 enable_command (const char *args
, int from_tty
)
14570 enable_disable_command (args
, from_tty
, true);
14574 enable_once_command (const char *args
, int from_tty
)
14576 map_breakpoint_numbers
14577 (args
, [&] (breakpoint
*b
)
14579 iterate_over_related_breakpoints
14580 (b
, [&] (breakpoint
*bpt
)
14582 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14588 enable_count_command (const char *args
, int from_tty
)
14593 error_no_arg (_("hit count"));
14595 count
= get_number (&args
);
14597 map_breakpoint_numbers
14598 (args
, [&] (breakpoint
*b
)
14600 iterate_over_related_breakpoints
14601 (b
, [&] (breakpoint
*bpt
)
14603 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14609 enable_delete_command (const char *args
, int from_tty
)
14611 map_breakpoint_numbers
14612 (args
, [&] (breakpoint
*b
)
14614 iterate_over_related_breakpoints
14615 (b
, [&] (breakpoint
*bpt
)
14617 enable_breakpoint_disp (bpt
, disp_del
, 1);
14622 /* Invalidate last known value of any hardware watchpoint if
14623 the memory which that value represents has been written to by
14627 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14628 CORE_ADDR addr
, ssize_t len
,
14629 const bfd_byte
*data
)
14631 struct breakpoint
*bp
;
14633 ALL_BREAKPOINTS (bp
)
14634 if (bp
->enable_state
== bp_enabled
14635 && bp
->type
== bp_hardware_watchpoint
)
14637 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14639 if (wp
->val_valid
&& wp
->val
!= nullptr)
14641 struct bp_location
*loc
;
14643 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14644 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14645 && loc
->address
+ loc
->length
> addr
14646 && addr
+ len
> loc
->address
)
14649 wp
->val_valid
= false;
14655 /* Create and insert a breakpoint for software single step. */
14658 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14659 const address_space
*aspace
,
14662 struct thread_info
*tp
= inferior_thread ();
14663 struct symtab_and_line sal
;
14664 CORE_ADDR pc
= next_pc
;
14666 if (tp
->control
.single_step_breakpoints
== NULL
)
14668 tp
->control
.single_step_breakpoints
14669 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14672 sal
= find_pc_line (pc
, 0);
14674 sal
.section
= find_pc_overlay (pc
);
14675 sal
.explicit_pc
= 1;
14676 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14678 update_global_location_list (UGLL_INSERT
);
14681 /* Insert single step breakpoints according to the current state. */
14684 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14686 struct regcache
*regcache
= get_current_regcache ();
14687 std::vector
<CORE_ADDR
> next_pcs
;
14689 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14691 if (!next_pcs
.empty ())
14693 struct frame_info
*frame
= get_current_frame ();
14694 const address_space
*aspace
= get_frame_address_space (frame
);
14696 for (CORE_ADDR pc
: next_pcs
)
14697 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14705 /* See breakpoint.h. */
14708 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14709 const address_space
*aspace
,
14712 struct bp_location
*loc
;
14714 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14716 && breakpoint_location_address_match (loc
, aspace
, pc
))
14722 /* Check whether a software single-step breakpoint is inserted at
14726 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14729 struct breakpoint
*bpt
;
14731 ALL_BREAKPOINTS (bpt
)
14733 if (bpt
->type
== bp_single_step
14734 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14740 /* Tracepoint-specific operations. */
14742 /* Set tracepoint count to NUM. */
14744 set_tracepoint_count (int num
)
14746 tracepoint_count
= num
;
14747 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14751 trace_command (const char *arg
, int from_tty
)
14753 event_location_up location
= string_to_event_location (&arg
,
14755 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
14756 (location
.get (), true /* is_tracepoint */);
14758 create_breakpoint (get_current_arch (),
14760 NULL
, 0, arg
, false, 1 /* parse arg */,
14762 bp_tracepoint
/* type_wanted */,
14763 0 /* Ignore count */,
14764 pending_break_support
,
14768 0 /* internal */, 0);
14772 ftrace_command (const char *arg
, int from_tty
)
14774 event_location_up location
= string_to_event_location (&arg
,
14776 create_breakpoint (get_current_arch (),
14778 NULL
, 0, arg
, false, 1 /* parse arg */,
14780 bp_fast_tracepoint
/* type_wanted */,
14781 0 /* Ignore count */,
14782 pending_break_support
,
14783 &tracepoint_breakpoint_ops
,
14786 0 /* internal */, 0);
14789 /* strace command implementation. Creates a static tracepoint. */
14792 strace_command (const char *arg
, int from_tty
)
14794 struct breakpoint_ops
*ops
;
14795 event_location_up location
;
14797 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14798 or with a normal static tracepoint. */
14799 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14801 ops
= &strace_marker_breakpoint_ops
;
14802 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14806 ops
= &tracepoint_breakpoint_ops
;
14807 location
= string_to_event_location (&arg
, current_language
);
14810 create_breakpoint (get_current_arch (),
14812 NULL
, 0, arg
, false, 1 /* parse arg */,
14814 bp_static_tracepoint
/* type_wanted */,
14815 0 /* Ignore count */,
14816 pending_break_support
,
14820 0 /* internal */, 0);
14823 /* Set up a fake reader function that gets command lines from a linked
14824 list that was acquired during tracepoint uploading. */
14826 static struct uploaded_tp
*this_utp
;
14827 static int next_cmd
;
14830 read_uploaded_action (void)
14832 char *rslt
= nullptr;
14834 if (next_cmd
< this_utp
->cmd_strings
.size ())
14836 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14843 /* Given information about a tracepoint as recorded on a target (which
14844 can be either a live system or a trace file), attempt to create an
14845 equivalent GDB tracepoint. This is not a reliable process, since
14846 the target does not necessarily have all the information used when
14847 the tracepoint was originally defined. */
14849 struct tracepoint
*
14850 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14852 const char *addr_str
;
14853 char small_buf
[100];
14854 struct tracepoint
*tp
;
14856 if (utp
->at_string
)
14857 addr_str
= utp
->at_string
.get ();
14860 /* In the absence of a source location, fall back to raw
14861 address. Since there is no way to confirm that the address
14862 means the same thing as when the trace was started, warn the
14864 warning (_("Uploaded tracepoint %d has no "
14865 "source location, using raw address"),
14867 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14868 addr_str
= small_buf
;
14871 /* There's not much we can do with a sequence of bytecodes. */
14872 if (utp
->cond
&& !utp
->cond_string
)
14873 warning (_("Uploaded tracepoint %d condition "
14874 "has no source form, ignoring it"),
14877 event_location_up location
= string_to_event_location (&addr_str
,
14879 if (!create_breakpoint (get_current_arch (),
14881 utp
->cond_string
.get (), -1, addr_str
,
14882 false /* force_condition */,
14883 0 /* parse cond/thread */,
14885 utp
->type
/* type_wanted */,
14886 0 /* Ignore count */,
14887 pending_break_support
,
14888 &tracepoint_breakpoint_ops
,
14890 utp
->enabled
/* enabled */,
14892 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14895 /* Get the tracepoint we just created. */
14896 tp
= get_tracepoint (tracepoint_count
);
14897 gdb_assert (tp
!= NULL
);
14901 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14904 trace_pass_command (small_buf
, 0);
14907 /* If we have uploaded versions of the original commands, set up a
14908 special-purpose "reader" function and call the usual command line
14909 reader, then pass the result to the breakpoint command-setting
14911 if (!utp
->cmd_strings
.empty ())
14913 counted_command_line cmd_list
;
14918 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14920 breakpoint_set_commands (tp
, std::move (cmd_list
));
14922 else if (!utp
->actions
.empty ()
14923 || !utp
->step_actions
.empty ())
14924 warning (_("Uploaded tracepoint %d actions "
14925 "have no source form, ignoring them"),
14928 /* Copy any status information that might be available. */
14929 tp
->hit_count
= utp
->hit_count
;
14930 tp
->traceframe_usage
= utp
->traceframe_usage
;
14935 /* Print information on tracepoint number TPNUM_EXP, or all if
14939 info_tracepoints_command (const char *args
, int from_tty
)
14941 struct ui_out
*uiout
= current_uiout
;
14944 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14946 if (num_printed
== 0)
14948 if (args
== NULL
|| *args
== '\0')
14949 uiout
->message ("No tracepoints.\n");
14951 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14954 default_collect_info ();
14957 /* The 'enable trace' command enables tracepoints.
14958 Not supported by all targets. */
14960 enable_trace_command (const char *args
, int from_tty
)
14962 enable_command (args
, from_tty
);
14965 /* The 'disable trace' command disables tracepoints.
14966 Not supported by all targets. */
14968 disable_trace_command (const char *args
, int from_tty
)
14970 disable_command (args
, from_tty
);
14973 /* Remove a tracepoint (or all if no argument). */
14975 delete_trace_command (const char *arg
, int from_tty
)
14977 struct breakpoint
*b
, *b_tmp
;
14983 int breaks_to_delete
= 0;
14985 /* Delete all breakpoints if no argument.
14986 Do not delete internal or call-dummy breakpoints, these
14987 have to be deleted with an explicit breakpoint number
14989 ALL_TRACEPOINTS (b
)
14990 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14992 breaks_to_delete
= 1;
14996 /* Ask user only if there are some breakpoints to delete. */
14998 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15000 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15001 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15002 delete_breakpoint (b
);
15006 map_breakpoint_numbers
15007 (arg
, [&] (breakpoint
*br
)
15009 iterate_over_related_breakpoints (br
, delete_breakpoint
);
15013 /* Helper function for trace_pass_command. */
15016 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15018 tp
->pass_count
= count
;
15019 gdb::observers::breakpoint_modified
.notify (tp
);
15021 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15022 tp
->number
, count
);
15025 /* Set passcount for tracepoint.
15027 First command argument is passcount, second is tracepoint number.
15028 If tracepoint number omitted, apply to most recently defined.
15029 Also accepts special argument "all". */
15032 trace_pass_command (const char *args
, int from_tty
)
15034 struct tracepoint
*t1
;
15037 if (args
== 0 || *args
== 0)
15038 error (_("passcount command requires an "
15039 "argument (count + optional TP num)"));
15041 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
15043 args
= skip_spaces (args
);
15044 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15046 struct breakpoint
*b
;
15048 args
+= 3; /* Skip special argument "all". */
15050 error (_("Junk at end of arguments."));
15052 ALL_TRACEPOINTS (b
)
15054 t1
= (struct tracepoint
*) b
;
15055 trace_pass_set_count (t1
, count
, from_tty
);
15058 else if (*args
== '\0')
15060 t1
= get_tracepoint_by_number (&args
, NULL
);
15062 trace_pass_set_count (t1
, count
, from_tty
);
15066 number_or_range_parser
parser (args
);
15067 while (!parser
.finished ())
15069 t1
= get_tracepoint_by_number (&args
, &parser
);
15071 trace_pass_set_count (t1
, count
, from_tty
);
15076 struct tracepoint
*
15077 get_tracepoint (int num
)
15079 struct breakpoint
*t
;
15081 ALL_TRACEPOINTS (t
)
15082 if (t
->number
== num
)
15083 return (struct tracepoint
*) t
;
15088 /* Find the tracepoint with the given target-side number (which may be
15089 different from the tracepoint number after disconnecting and
15092 struct tracepoint
*
15093 get_tracepoint_by_number_on_target (int num
)
15095 struct breakpoint
*b
;
15097 ALL_TRACEPOINTS (b
)
15099 struct tracepoint
*t
= (struct tracepoint
*) b
;
15101 if (t
->number_on_target
== num
)
15108 /* Utility: parse a tracepoint number and look it up in the list.
15109 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15110 If the argument is missing, the most recent tracepoint
15111 (tracepoint_count) is returned. */
15113 struct tracepoint
*
15114 get_tracepoint_by_number (const char **arg
,
15115 number_or_range_parser
*parser
)
15117 struct breakpoint
*t
;
15119 const char *instring
= arg
== NULL
? NULL
: *arg
;
15121 if (parser
!= NULL
)
15123 gdb_assert (!parser
->finished ());
15124 tpnum
= parser
->get_number ();
15126 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15127 tpnum
= tracepoint_count
;
15129 tpnum
= get_number (arg
);
15133 if (instring
&& *instring
)
15134 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15137 printf_filtered (_("No previous tracepoint\n"));
15141 ALL_TRACEPOINTS (t
)
15142 if (t
->number
== tpnum
)
15144 return (struct tracepoint
*) t
;
15147 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15152 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15154 if (b
->thread
!= -1)
15155 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15158 fprintf_unfiltered (fp
, " task %d", b
->task
);
15160 fprintf_unfiltered (fp
, "\n");
15163 /* Save information on user settable breakpoints (watchpoints, etc) to
15164 a new script file named FILENAME. If FILTER is non-NULL, call it
15165 on each breakpoint and only include the ones for which it returns
15169 save_breakpoints (const char *filename
, int from_tty
,
15170 bool (*filter
) (const struct breakpoint
*))
15172 struct breakpoint
*tp
;
15174 int extra_trace_bits
= 0;
15176 if (filename
== 0 || *filename
== 0)
15177 error (_("Argument required (file name in which to save)"));
15179 /* See if we have anything to save. */
15180 ALL_BREAKPOINTS (tp
)
15182 /* Skip internal and momentary breakpoints. */
15183 if (!user_breakpoint_p (tp
))
15186 /* If we have a filter, only save the breakpoints it accepts. */
15187 if (filter
&& !filter (tp
))
15192 if (is_tracepoint (tp
))
15194 extra_trace_bits
= 1;
15196 /* We can stop searching. */
15203 warning (_("Nothing to save."));
15207 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15211 if (!fp
.open (expanded_filename
.get (), "w"))
15212 error (_("Unable to open file '%s' for saving (%s)"),
15213 expanded_filename
.get (), safe_strerror (errno
));
15215 if (extra_trace_bits
)
15216 save_trace_state_variables (&fp
);
15218 ALL_BREAKPOINTS (tp
)
15220 /* Skip internal and momentary breakpoints. */
15221 if (!user_breakpoint_p (tp
))
15224 /* If we have a filter, only save the breakpoints it accepts. */
15225 if (filter
&& !filter (tp
))
15228 tp
->ops
->print_recreate (tp
, &fp
);
15230 /* Note, we can't rely on tp->number for anything, as we can't
15231 assume the recreated breakpoint numbers will match. Use $bpnum
15234 if (tp
->cond_string
)
15235 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15237 if (tp
->ignore_count
)
15238 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15240 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15242 fp
.puts (" commands\n");
15244 current_uiout
->redirect (&fp
);
15247 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15249 catch (const gdb_exception
&ex
)
15251 current_uiout
->redirect (NULL
);
15255 current_uiout
->redirect (NULL
);
15256 fp
.puts (" end\n");
15259 if (tp
->enable_state
== bp_disabled
)
15260 fp
.puts ("disable $bpnum\n");
15262 /* If this is a multi-location breakpoint, check if the locations
15263 should be individually disabled. Watchpoint locations are
15264 special, and not user visible. */
15265 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15267 struct bp_location
*loc
;
15270 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15272 fp
.printf ("disable $bpnum.%d\n", n
);
15276 if (extra_trace_bits
&& *default_collect
)
15277 fp
.printf ("set default-collect %s\n", default_collect
);
15280 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15283 /* The `save breakpoints' command. */
15286 save_breakpoints_command (const char *args
, int from_tty
)
15288 save_breakpoints (args
, from_tty
, NULL
);
15291 /* The `save tracepoints' command. */
15294 save_tracepoints_command (const char *args
, int from_tty
)
15296 save_breakpoints (args
, from_tty
, is_tracepoint
);
15299 /* Create a vector of all tracepoints. */
15301 std::vector
<breakpoint
*>
15302 all_tracepoints (void)
15304 std::vector
<breakpoint
*> tp_vec
;
15305 struct breakpoint
*tp
;
15307 ALL_TRACEPOINTS (tp
)
15309 tp_vec
.push_back (tp
);
15316 /* This help string is used to consolidate all the help string for specifying
15317 locations used by several commands. */
15319 #define LOCATION_HELP_STRING \
15320 "Linespecs are colon-separated lists of location parameters, such as\n\
15321 source filename, function name, label name, and line number.\n\
15322 Example: To specify the start of a label named \"the_top\" in the\n\
15323 function \"fact\" in the file \"factorial.c\", use\n\
15324 \"factorial.c:fact:the_top\".\n\
15326 Address locations begin with \"*\" and specify an exact address in the\n\
15327 program. Example: To specify the fourth byte past the start function\n\
15328 \"main\", use \"*main + 4\".\n\
15330 Explicit locations are similar to linespecs but use an option/argument\n\
15331 syntax to specify location parameters.\n\
15332 Example: To specify the start of the label named \"the_top\" in the\n\
15333 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15334 -function fact -label the_top\".\n\
15336 By default, a specified function is matched against the program's\n\
15337 functions in all scopes. For C++, this means in all namespaces and\n\
15338 classes. For Ada, this means in all packages. E.g., in C++,\n\
15339 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15340 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15341 specified name as a complete fully-qualified name instead."
15343 /* This help string is used for the break, hbreak, tbreak and thbreak
15344 commands. It is defined as a macro to prevent duplication.
15345 COMMAND should be a string constant containing the name of the
15348 #define BREAK_ARGS_HELP(command) \
15349 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
15350 \t[-force-condition] [if CONDITION]\n\
15351 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15352 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15353 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15354 `-probe-dtrace' (for a DTrace probe).\n\
15355 LOCATION may be a linespec, address, or explicit location as described\n\
15358 With no LOCATION, uses current execution address of the selected\n\
15359 stack frame. This is useful for breaking on return to a stack frame.\n\
15361 THREADNUM is the number from \"info threads\".\n\
15362 CONDITION is a boolean expression.\n\
15364 With the \"-force-condition\" flag, the condition is defined even when\n\
15365 it is invalid for all current locations.\n\
15366 \n" LOCATION_HELP_STRING "\n\n\
15367 Multiple breakpoints at one place are permitted, and useful if their\n\
15368 conditions are different.\n\
15370 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15372 /* List of subcommands for "catch". */
15373 static struct cmd_list_element
*catch_cmdlist
;
15375 /* List of subcommands for "tcatch". */
15376 static struct cmd_list_element
*tcatch_cmdlist
;
15379 add_catch_command (const char *name
, const char *docstring
,
15380 cmd_const_sfunc_ftype
*sfunc
,
15381 completer_ftype
*completer
,
15382 void *user_data_catch
,
15383 void *user_data_tcatch
)
15385 struct cmd_list_element
*command
;
15387 command
= add_cmd (name
, class_breakpoint
, docstring
,
15389 set_cmd_sfunc (command
, sfunc
);
15390 set_cmd_context (command
, user_data_catch
);
15391 set_cmd_completer (command
, completer
);
15393 command
= add_cmd (name
, class_breakpoint
, docstring
,
15395 set_cmd_sfunc (command
, sfunc
);
15396 set_cmd_context (command
, user_data_tcatch
);
15397 set_cmd_completer (command
, completer
);
15400 struct breakpoint
*
15401 iterate_over_breakpoints (gdb::function_view
<bool (breakpoint
*)> callback
)
15403 struct breakpoint
*b
, *b_tmp
;
15405 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15414 /* Zero if any of the breakpoint's locations could be a location where
15415 functions have been inlined, nonzero otherwise. */
15418 is_non_inline_function (struct breakpoint
*b
)
15420 /* The shared library event breakpoint is set on the address of a
15421 non-inline function. */
15422 if (b
->type
== bp_shlib_event
)
15428 /* Nonzero if the specified PC cannot be a location where functions
15429 have been inlined. */
15432 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15433 const struct target_waitstatus
*ws
)
15435 struct breakpoint
*b
;
15436 struct bp_location
*bl
;
15438 ALL_BREAKPOINTS (b
)
15440 if (!is_non_inline_function (b
))
15443 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15445 if (!bl
->shlib_disabled
15446 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15454 /* Remove any references to OBJFILE which is going to be freed. */
15457 breakpoint_free_objfile (struct objfile
*objfile
)
15459 struct bp_location
**locp
, *loc
;
15461 ALL_BP_LOCATIONS (loc
, locp
)
15462 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15463 loc
->symtab
= NULL
;
15467 initialize_breakpoint_ops (void)
15469 static int initialized
= 0;
15471 struct breakpoint_ops
*ops
;
15477 /* The breakpoint_ops structure to be inherit by all kinds of
15478 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15479 internal and momentary breakpoints, etc.). */
15480 ops
= &bkpt_base_breakpoint_ops
;
15481 *ops
= base_breakpoint_ops
;
15482 ops
->re_set
= bkpt_re_set
;
15483 ops
->insert_location
= bkpt_insert_location
;
15484 ops
->remove_location
= bkpt_remove_location
;
15485 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15486 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15487 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15488 ops
->decode_location
= bkpt_decode_location
;
15490 /* The breakpoint_ops structure to be used in regular breakpoints. */
15491 ops
= &bkpt_breakpoint_ops
;
15492 *ops
= bkpt_base_breakpoint_ops
;
15493 ops
->re_set
= bkpt_re_set
;
15494 ops
->resources_needed
= bkpt_resources_needed
;
15495 ops
->print_it
= bkpt_print_it
;
15496 ops
->print_mention
= bkpt_print_mention
;
15497 ops
->print_recreate
= bkpt_print_recreate
;
15499 /* Ranged breakpoints. */
15500 ops
= &ranged_breakpoint_ops
;
15501 *ops
= bkpt_breakpoint_ops
;
15502 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15503 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15504 ops
->print_it
= print_it_ranged_breakpoint
;
15505 ops
->print_one
= print_one_ranged_breakpoint
;
15506 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15507 ops
->print_mention
= print_mention_ranged_breakpoint
;
15508 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15510 /* Internal breakpoints. */
15511 ops
= &internal_breakpoint_ops
;
15512 *ops
= bkpt_base_breakpoint_ops
;
15513 ops
->re_set
= internal_bkpt_re_set
;
15514 ops
->check_status
= internal_bkpt_check_status
;
15515 ops
->print_it
= internal_bkpt_print_it
;
15516 ops
->print_mention
= internal_bkpt_print_mention
;
15518 /* Momentary breakpoints. */
15519 ops
= &momentary_breakpoint_ops
;
15520 *ops
= bkpt_base_breakpoint_ops
;
15521 ops
->re_set
= momentary_bkpt_re_set
;
15522 ops
->check_status
= momentary_bkpt_check_status
;
15523 ops
->print_it
= momentary_bkpt_print_it
;
15524 ops
->print_mention
= momentary_bkpt_print_mention
;
15526 /* Probe breakpoints. */
15527 ops
= &bkpt_probe_breakpoint_ops
;
15528 *ops
= bkpt_breakpoint_ops
;
15529 ops
->insert_location
= bkpt_probe_insert_location
;
15530 ops
->remove_location
= bkpt_probe_remove_location
;
15531 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15532 ops
->decode_location
= bkpt_probe_decode_location
;
15535 ops
= &watchpoint_breakpoint_ops
;
15536 *ops
= base_breakpoint_ops
;
15537 ops
->re_set
= re_set_watchpoint
;
15538 ops
->insert_location
= insert_watchpoint
;
15539 ops
->remove_location
= remove_watchpoint
;
15540 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15541 ops
->check_status
= check_status_watchpoint
;
15542 ops
->resources_needed
= resources_needed_watchpoint
;
15543 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15544 ops
->print_it
= print_it_watchpoint
;
15545 ops
->print_mention
= print_mention_watchpoint
;
15546 ops
->print_recreate
= print_recreate_watchpoint
;
15547 ops
->explains_signal
= explains_signal_watchpoint
;
15549 /* Masked watchpoints. */
15550 ops
= &masked_watchpoint_breakpoint_ops
;
15551 *ops
= watchpoint_breakpoint_ops
;
15552 ops
->insert_location
= insert_masked_watchpoint
;
15553 ops
->remove_location
= remove_masked_watchpoint
;
15554 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15555 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15556 ops
->print_it
= print_it_masked_watchpoint
;
15557 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15558 ops
->print_mention
= print_mention_masked_watchpoint
;
15559 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15562 ops
= &tracepoint_breakpoint_ops
;
15563 *ops
= base_breakpoint_ops
;
15564 ops
->re_set
= tracepoint_re_set
;
15565 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15566 ops
->print_one_detail
= tracepoint_print_one_detail
;
15567 ops
->print_mention
= tracepoint_print_mention
;
15568 ops
->print_recreate
= tracepoint_print_recreate
;
15569 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15570 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15571 ops
->decode_location
= tracepoint_decode_location
;
15573 /* Probe tracepoints. */
15574 ops
= &tracepoint_probe_breakpoint_ops
;
15575 *ops
= tracepoint_breakpoint_ops
;
15576 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15577 ops
->decode_location
= tracepoint_probe_decode_location
;
15579 /* Static tracepoints with marker (`-m'). */
15580 ops
= &strace_marker_breakpoint_ops
;
15581 *ops
= tracepoint_breakpoint_ops
;
15582 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15583 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15584 ops
->decode_location
= strace_marker_decode_location
;
15586 /* Fork catchpoints. */
15587 ops
= &catch_fork_breakpoint_ops
;
15588 *ops
= base_breakpoint_ops
;
15589 ops
->insert_location
= insert_catch_fork
;
15590 ops
->remove_location
= remove_catch_fork
;
15591 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15592 ops
->print_it
= print_it_catch_fork
;
15593 ops
->print_one
= print_one_catch_fork
;
15594 ops
->print_mention
= print_mention_catch_fork
;
15595 ops
->print_recreate
= print_recreate_catch_fork
;
15597 /* Vfork catchpoints. */
15598 ops
= &catch_vfork_breakpoint_ops
;
15599 *ops
= base_breakpoint_ops
;
15600 ops
->insert_location
= insert_catch_vfork
;
15601 ops
->remove_location
= remove_catch_vfork
;
15602 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15603 ops
->print_it
= print_it_catch_vfork
;
15604 ops
->print_one
= print_one_catch_vfork
;
15605 ops
->print_mention
= print_mention_catch_vfork
;
15606 ops
->print_recreate
= print_recreate_catch_vfork
;
15608 /* Exec catchpoints. */
15609 ops
= &catch_exec_breakpoint_ops
;
15610 *ops
= base_breakpoint_ops
;
15611 ops
->insert_location
= insert_catch_exec
;
15612 ops
->remove_location
= remove_catch_exec
;
15613 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15614 ops
->print_it
= print_it_catch_exec
;
15615 ops
->print_one
= print_one_catch_exec
;
15616 ops
->print_mention
= print_mention_catch_exec
;
15617 ops
->print_recreate
= print_recreate_catch_exec
;
15619 /* Solib-related catchpoints. */
15620 ops
= &catch_solib_breakpoint_ops
;
15621 *ops
= base_breakpoint_ops
;
15622 ops
->insert_location
= insert_catch_solib
;
15623 ops
->remove_location
= remove_catch_solib
;
15624 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15625 ops
->check_status
= check_status_catch_solib
;
15626 ops
->print_it
= print_it_catch_solib
;
15627 ops
->print_one
= print_one_catch_solib
;
15628 ops
->print_mention
= print_mention_catch_solib
;
15629 ops
->print_recreate
= print_recreate_catch_solib
;
15631 ops
= &dprintf_breakpoint_ops
;
15632 *ops
= bkpt_base_breakpoint_ops
;
15633 ops
->re_set
= dprintf_re_set
;
15634 ops
->resources_needed
= bkpt_resources_needed
;
15635 ops
->print_it
= bkpt_print_it
;
15636 ops
->print_mention
= bkpt_print_mention
;
15637 ops
->print_recreate
= dprintf_print_recreate
;
15638 ops
->after_condition_true
= dprintf_after_condition_true
;
15639 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15642 /* Chain containing all defined "enable breakpoint" subcommands. */
15644 static struct cmd_list_element
*enablebreaklist
= NULL
;
15646 /* See breakpoint.h. */
15648 cmd_list_element
*commands_cmd_element
= nullptr;
15650 void _initialize_breakpoint ();
15652 _initialize_breakpoint ()
15654 struct cmd_list_element
*c
;
15656 initialize_breakpoint_ops ();
15658 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
15660 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
15662 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
15665 breakpoint_chain
= 0;
15666 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15667 before a breakpoint is set. */
15668 breakpoint_count
= 0;
15670 tracepoint_count
= 0;
15672 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15673 Set ignore-count of breakpoint number N to COUNT.\n\
15674 Usage is `ignore N COUNT'."));
15676 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15677 commands_command
, _("\
15678 Set commands to be executed when the given breakpoints are hit.\n\
15679 Give a space-separated breakpoint list as argument after \"commands\".\n\
15680 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15682 With no argument, the targeted breakpoint is the last one set.\n\
15683 The commands themselves follow starting on the next line.\n\
15684 Type a line containing \"end\" to indicate the end of them.\n\
15685 Give \"silent\" as the first line to make the breakpoint silent;\n\
15686 then no output is printed when it is hit, except what the commands print."));
15688 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
15689 static std::string condition_command_help
15690 = gdb::option::build_help (_("\
15691 Specify breakpoint number N to break only if COND is true.\n\
15692 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
15693 is an expression to be evaluated whenever breakpoint N is reached.\n\
15696 %OPTIONS%"), cc_opts
);
15698 c
= add_com ("condition", class_breakpoint
, condition_command
,
15699 condition_command_help
.c_str ());
15700 set_cmd_completer_handle_brkchars (c
, condition_completer
);
15702 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15703 Set a temporary breakpoint.\n\
15704 Like \"break\" except the breakpoint is only temporary,\n\
15705 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15706 by using \"enable delete\" on the breakpoint number.\n\
15708 BREAK_ARGS_HELP ("tbreak")));
15709 set_cmd_completer (c
, location_completer
);
15711 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15712 Set a hardware assisted breakpoint.\n\
15713 Like \"break\" except the breakpoint requires hardware support,\n\
15714 some target hardware may not have this support.\n\
15716 BREAK_ARGS_HELP ("hbreak")));
15717 set_cmd_completer (c
, location_completer
);
15719 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15720 Set a temporary hardware assisted breakpoint.\n\
15721 Like \"hbreak\" except the breakpoint is only temporary,\n\
15722 so it will be deleted when hit.\n\
15724 BREAK_ARGS_HELP ("thbreak")));
15725 set_cmd_completer (c
, location_completer
);
15727 cmd_list_element
*enable_cmd
15728 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15729 Enable all or some breakpoints.\n\
15730 Usage: enable [BREAKPOINTNUM]...\n\
15731 Give breakpoint numbers (separated by spaces) as arguments.\n\
15732 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15733 This is used to cancel the effect of the \"disable\" command.\n\
15734 With a subcommand you can enable temporarily."),
15735 &enablelist
, 1, &cmdlist
);
15737 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
15739 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15740 Enable all or some breakpoints.\n\
15741 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15742 Give breakpoint numbers (separated by spaces) as arguments.\n\
15743 This is used to cancel the effect of the \"disable\" command.\n\
15744 May be abbreviated to simply \"enable\"."),
15745 &enablebreaklist
, 1, &enablelist
);
15747 add_cmd ("once", no_class
, enable_once_command
, _("\
15748 Enable some breakpoints for one hit.\n\
15749 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15750 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15753 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15754 Enable some breakpoints and delete when hit.\n\
15755 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15756 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15759 add_cmd ("count", no_class
, enable_count_command
, _("\
15760 Enable some breakpoints for COUNT hits.\n\
15761 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15762 If a breakpoint is hit while enabled in this fashion,\n\
15763 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15766 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15767 Enable some breakpoints and delete when hit.\n\
15768 Usage: enable delete BREAKPOINTNUM...\n\
15769 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15772 add_cmd ("once", no_class
, enable_once_command
, _("\
15773 Enable some breakpoints for one hit.\n\
15774 Usage: enable once BREAKPOINTNUM...\n\
15775 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15778 add_cmd ("count", no_class
, enable_count_command
, _("\
15779 Enable some breakpoints for COUNT hits.\n\
15780 Usage: enable count COUNT BREAKPOINTNUM...\n\
15781 If a breakpoint is hit while enabled in this fashion,\n\
15782 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15785 cmd_list_element
*disable_cmd
15786 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15787 Disable all or some breakpoints.\n\
15788 Usage: disable [BREAKPOINTNUM]...\n\
15789 Arguments are breakpoint numbers with spaces in between.\n\
15790 To disable all breakpoints, give no argument.\n\
15791 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15792 &disablelist
, 1, &cmdlist
);
15793 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
15794 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
15796 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
15797 Disable all or some breakpoints.\n\
15798 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15799 Arguments are breakpoint numbers with spaces in between.\n\
15800 To disable all breakpoints, give no argument.\n\
15801 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15802 This command may be abbreviated \"disable\"."),
15805 cmd_list_element
*delete_cmd
15806 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15807 Delete all or some breakpoints.\n\
15808 Usage: delete [BREAKPOINTNUM]...\n\
15809 Arguments are breakpoint numbers with spaces in between.\n\
15810 To delete all breakpoints, give no argument.\n\
15812 Also a prefix command for deletion of other GDB objects."),
15813 &deletelist
, 1, &cmdlist
);
15814 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
15815 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
15817 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
15818 Delete all or some breakpoints or auto-display expressions.\n\
15819 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15820 Arguments are breakpoint numbers with spaces in between.\n\
15821 To delete all breakpoints, give no argument.\n\
15822 This command may be abbreviated \"delete\"."),
15825 cmd_list_element
*clear_cmd
15826 = add_com ("clear", class_breakpoint
, clear_command
, _("\
15827 Clear breakpoint at specified location.\n\
15828 Argument may be a linespec, explicit, or address location as described below.\n\
15830 With no argument, clears all breakpoints in the line that the selected frame\n\
15831 is executing in.\n"
15832 "\n" LOCATION_HELP_STRING
"\n\n\
15833 See also the \"delete\" command which clears breakpoints by number."));
15834 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
15836 cmd_list_element
*break_cmd
15837 = add_com ("break", class_breakpoint
, break_command
, _("\
15838 Set breakpoint at specified location.\n"
15839 BREAK_ARGS_HELP ("break")));
15840 set_cmd_completer (break_cmd
, location_completer
);
15842 add_com_alias ("b", break_cmd
, class_run
, 1);
15843 add_com_alias ("br", break_cmd
, class_run
, 1);
15844 add_com_alias ("bre", break_cmd
, class_run
, 1);
15845 add_com_alias ("brea", break_cmd
, class_run
, 1);
15849 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15850 Break in function/address or break at a line in the current file."),
15851 &stoplist
, 1, &cmdlist
);
15852 add_cmd ("in", class_breakpoint
, stopin_command
,
15853 _("Break in function or address."), &stoplist
);
15854 add_cmd ("at", class_breakpoint
, stopat_command
,
15855 _("Break at a line in the current file."), &stoplist
);
15856 add_com ("status", class_info
, info_breakpoints_command
, _("\
15857 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15858 The \"Type\" column indicates one of:\n\
15859 \tbreakpoint - normal breakpoint\n\
15860 \twatchpoint - watchpoint\n\
15861 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15862 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15863 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15864 address and file/line number respectively.\n\
15866 Convenience variable \"$_\" and default examine address for \"x\"\n\
15867 are set to the address of the last breakpoint listed unless the command\n\
15868 is prefixed with \"server \".\n\n\
15869 Convenience variable \"$bpnum\" contains the number of the last\n\
15870 breakpoint set."));
15873 cmd_list_element
*info_breakpoints_cmd
15874 = add_info ("breakpoints", info_breakpoints_command
, _("\
15875 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15876 The \"Type\" column indicates one of:\n\
15877 \tbreakpoint - normal breakpoint\n\
15878 \twatchpoint - watchpoint\n\
15879 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15880 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15881 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15882 address and file/line number respectively.\n\
15884 Convenience variable \"$_\" and default examine address for \"x\"\n\
15885 are set to the address of the last breakpoint listed unless the command\n\
15886 is prefixed with \"server \".\n\n\
15887 Convenience variable \"$bpnum\" contains the number of the last\n\
15888 breakpoint set."));
15890 add_info_alias ("b", info_breakpoints_cmd
, 1);
15892 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15893 Status of all breakpoints, or breakpoint number NUMBER.\n\
15894 The \"Type\" column indicates one of:\n\
15895 \tbreakpoint - normal breakpoint\n\
15896 \twatchpoint - watchpoint\n\
15897 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15898 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15899 \tuntil - internal breakpoint used by the \"until\" command\n\
15900 \tfinish - internal breakpoint used by the \"finish\" command\n\
15901 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15902 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15903 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15904 address and file/line number respectively.\n\
15906 Convenience variable \"$_\" and default examine address for \"x\"\n\
15907 are set to the address of the last breakpoint listed unless the command\n\
15908 is prefixed with \"server \".\n\n\
15909 Convenience variable \"$bpnum\" contains the number of the last\n\
15911 &maintenanceinfolist
);
15913 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
15914 Set catchpoints to catch events."),
15916 0/*allow-unknown*/, &cmdlist
);
15918 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
15919 Set temporary catchpoints to catch events."),
15921 0/*allow-unknown*/, &cmdlist
);
15923 add_catch_command ("fork", _("Catch calls to fork."),
15924 catch_fork_command_1
,
15926 (void *) (uintptr_t) catch_fork_permanent
,
15927 (void *) (uintptr_t) catch_fork_temporary
);
15928 add_catch_command ("vfork", _("Catch calls to vfork."),
15929 catch_fork_command_1
,
15931 (void *) (uintptr_t) catch_vfork_permanent
,
15932 (void *) (uintptr_t) catch_vfork_temporary
);
15933 add_catch_command ("exec", _("Catch calls to exec."),
15934 catch_exec_command_1
,
15938 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15939 Usage: catch load [REGEX]\n\
15940 If REGEX is given, only stop for libraries matching the regular expression."),
15941 catch_load_command_1
,
15945 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15946 Usage: catch unload [REGEX]\n\
15947 If REGEX is given, only stop for libraries matching the regular expression."),
15948 catch_unload_command_1
,
15953 const auto opts
= make_watch_options_def_group (nullptr);
15955 static const std::string watch_help
= gdb::option::build_help (_("\
15956 Set a watchpoint for EXPRESSION.\n\
15957 Usage: watch [-location] EXPRESSION\n\
15962 A watchpoint stops execution of your program whenever the value of\n\
15963 an expression changes."), opts
);
15964 c
= add_com ("watch", class_breakpoint
, watch_command
,
15965 watch_help
.c_str ());
15966 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15968 static const std::string rwatch_help
= gdb::option::build_help (_("\
15969 Set a read watchpoint for EXPRESSION.\n\
15970 Usage: rwatch [-location] EXPRESSION\n\
15975 A read watchpoint stops execution of your program whenever the value of\n\
15976 an expression is read."), opts
);
15977 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
15978 rwatch_help
.c_str ());
15979 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15981 static const std::string awatch_help
= gdb::option::build_help (_("\
15982 Set an access watchpoint for EXPRESSION.\n\
15983 Usage: awatch [-location] EXPRESSION\n\
15988 An access watchpoint stops execution of your program whenever the value\n\
15989 of an expression is either read or written."), opts
);
15990 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
15991 awatch_help
.c_str ());
15992 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15994 add_info ("watchpoints", info_watchpoints_command
, _("\
15995 Status of specified watchpoints (all watchpoints if no argument)."));
15997 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15998 respond to changes - contrary to the description. */
15999 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
16000 &can_use_hw_watchpoints
, _("\
16001 Set debugger's willingness to use watchpoint hardware."), _("\
16002 Show debugger's willingness to use watchpoint hardware."), _("\
16003 If zero, gdb will not use hardware for new watchpoints, even if\n\
16004 such is available. (However, any hardware watchpoints that were\n\
16005 created before setting this to nonzero, will continue to use watchpoint\n\
16008 show_can_use_hw_watchpoints
,
16009 &setlist
, &showlist
);
16011 can_use_hw_watchpoints
= 1;
16013 /* Tracepoint manipulation commands. */
16015 cmd_list_element
*trace_cmd
16016 = add_com ("trace", class_breakpoint
, trace_command
, _("\
16017 Set a tracepoint at specified location.\n\
16019 BREAK_ARGS_HELP ("trace") "\n\
16020 Do \"help tracepoints\" for info on other tracepoint commands."));
16021 set_cmd_completer (trace_cmd
, location_completer
);
16023 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
16024 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
16025 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
16026 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
16028 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16029 Set a fast tracepoint at specified location.\n\
16031 BREAK_ARGS_HELP ("ftrace") "\n\
16032 Do \"help tracepoints\" for info on other tracepoint commands."));
16033 set_cmd_completer (c
, location_completer
);
16035 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16036 Set a static tracepoint at location or marker.\n\
16038 strace [LOCATION] [if CONDITION]\n\
16039 LOCATION may be a linespec, explicit, or address location (described below) \n\
16040 or -m MARKER_ID.\n\n\
16041 If a marker id is specified, probe the marker with that name. With\n\
16042 no LOCATION, uses current execution address of the selected stack frame.\n\
16043 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16044 This collects arbitrary user data passed in the probe point call to the\n\
16045 tracing library. You can inspect it when analyzing the trace buffer,\n\
16046 by printing the $_sdata variable like any other convenience variable.\n\
16048 CONDITION is a boolean expression.\n\
16049 \n" LOCATION_HELP_STRING
"\n\n\
16050 Multiple tracepoints at one place are permitted, and useful if their\n\
16051 conditions are different.\n\
16053 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16054 Do \"help tracepoints\" for info on other tracepoint commands."));
16055 set_cmd_completer (c
, location_completer
);
16057 cmd_list_element
*info_tracepoints_cmd
16058 = add_info ("tracepoints", info_tracepoints_command
, _("\
16059 Status of specified tracepoints (all tracepoints if no argument).\n\
16060 Convenience variable \"$tpnum\" contains the number of the\n\
16061 last tracepoint set."));
16063 add_info_alias ("tp", info_tracepoints_cmd
, 1);
16065 cmd_list_element
*delete_tracepoints_cmd
16066 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16067 Delete specified tracepoints.\n\
16068 Arguments are tracepoint numbers, separated by spaces.\n\
16069 No argument means delete all tracepoints."),
16071 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
16073 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16074 Disable specified tracepoints.\n\
16075 Arguments are tracepoint numbers, separated by spaces.\n\
16076 No argument means disable all tracepoints."),
16078 deprecate_cmd (c
, "disable");
16080 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16081 Enable specified tracepoints.\n\
16082 Arguments are tracepoint numbers, separated by spaces.\n\
16083 No argument means enable all tracepoints."),
16085 deprecate_cmd (c
, "enable");
16087 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16088 Set the passcount for a tracepoint.\n\
16089 The trace will end when the tracepoint has been passed 'count' times.\n\
16090 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16091 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16093 add_basic_prefix_cmd ("save", class_breakpoint
,
16094 _("Save breakpoint definitions as a script."),
16096 0/*allow-unknown*/, &cmdlist
);
16098 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16099 Save current breakpoint definitions as a script.\n\
16100 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16101 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16102 session to restore them."),
16104 set_cmd_completer (c
, filename_completer
);
16106 cmd_list_element
*save_tracepoints_cmd
16107 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16108 Save current tracepoint definitions as a script.\n\
16109 Use the 'source' command in another debug session to restore them."),
16111 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
16113 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
16114 deprecate_cmd (c
, "save tracepoints");
16116 add_basic_prefix_cmd ("breakpoint", class_maintenance
, _("\
16117 Breakpoint specific settings.\n\
16118 Configure various breakpoint-specific variables such as\n\
16119 pending breakpoint behavior."),
16120 &breakpoint_set_cmdlist
,
16121 0/*allow-unknown*/, &setlist
);
16122 add_show_prefix_cmd ("breakpoint", class_maintenance
, _("\
16123 Breakpoint specific settings.\n\
16124 Configure various breakpoint-specific variables such as\n\
16125 pending breakpoint behavior."),
16126 &breakpoint_show_cmdlist
,
16127 0/*allow-unknown*/, &showlist
);
16129 add_setshow_auto_boolean_cmd ("pending", no_class
,
16130 &pending_break_support
, _("\
16131 Set debugger's behavior regarding pending breakpoints."), _("\
16132 Show debugger's behavior regarding pending breakpoints."), _("\
16133 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16134 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16135 an error. If auto, an unrecognized breakpoint location results in a\n\
16136 user-query to see if a pending breakpoint should be created."),
16138 show_pending_break_support
,
16139 &breakpoint_set_cmdlist
,
16140 &breakpoint_show_cmdlist
);
16142 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16144 add_setshow_boolean_cmd ("auto-hw", no_class
,
16145 &automatic_hardware_breakpoints
, _("\
16146 Set automatic usage of hardware breakpoints."), _("\
16147 Show automatic usage of hardware breakpoints."), _("\
16148 If set, the debugger will automatically use hardware breakpoints for\n\
16149 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16150 a warning will be emitted for such breakpoints."),
16152 show_automatic_hardware_breakpoints
,
16153 &breakpoint_set_cmdlist
,
16154 &breakpoint_show_cmdlist
);
16156 add_setshow_boolean_cmd ("always-inserted", class_support
,
16157 &always_inserted_mode
, _("\
16158 Set mode for inserting breakpoints."), _("\
16159 Show mode for inserting breakpoints."), _("\
16160 When this mode is on, breakpoints are inserted immediately as soon as\n\
16161 they're created, kept inserted even when execution stops, and removed\n\
16162 only when the user deletes them. When this mode is off (the default),\n\
16163 breakpoints are inserted only when execution continues, and removed\n\
16164 when execution stops."),
16166 &show_always_inserted_mode
,
16167 &breakpoint_set_cmdlist
,
16168 &breakpoint_show_cmdlist
);
16170 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16171 condition_evaluation_enums
,
16172 &condition_evaluation_mode_1
, _("\
16173 Set mode of breakpoint condition evaluation."), _("\
16174 Show mode of breakpoint condition evaluation."), _("\
16175 When this is set to \"host\", breakpoint conditions will be\n\
16176 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16177 breakpoint conditions will be downloaded to the target (if the target\n\
16178 supports such feature) and conditions will be evaluated on the target's side.\n\
16179 If this is set to \"auto\" (default), this will be automatically set to\n\
16180 \"target\" if it supports condition evaluation, otherwise it will\n\
16181 be set to \"host\"."),
16182 &set_condition_evaluation_mode
,
16183 &show_condition_evaluation_mode
,
16184 &breakpoint_set_cmdlist
,
16185 &breakpoint_show_cmdlist
);
16187 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16188 Set a breakpoint for an address range.\n\
16189 break-range START-LOCATION, END-LOCATION\n\
16190 where START-LOCATION and END-LOCATION can be one of the following:\n\
16191 LINENUM, for that line in the current file,\n\
16192 FILE:LINENUM, for that line in that file,\n\
16193 +OFFSET, for that number of lines after the current line\n\
16194 or the start of the range\n\
16195 FUNCTION, for the first line in that function,\n\
16196 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16197 *ADDRESS, for the instruction at that address.\n\
16199 The breakpoint will stop execution of the inferior whenever it executes\n\
16200 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16201 range (including START-LOCATION and END-LOCATION)."));
16203 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16204 Set a dynamic printf at specified location.\n\
16205 dprintf location,format string,arg1,arg2,...\n\
16206 location may be a linespec, explicit, or address location.\n"
16207 "\n" LOCATION_HELP_STRING
));
16208 set_cmd_completer (c
, location_completer
);
16210 add_setshow_enum_cmd ("dprintf-style", class_support
,
16211 dprintf_style_enums
, &dprintf_style
, _("\
16212 Set the style of usage for dynamic printf."), _("\
16213 Show the style of usage for dynamic printf."), _("\
16214 This setting chooses how GDB will do a dynamic printf.\n\
16215 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16216 console, as with the \"printf\" command.\n\
16217 If the value is \"call\", the print is done by calling a function in your\n\
16218 program; by default printf(), but you can choose a different function or\n\
16219 output stream by setting dprintf-function and dprintf-channel."),
16220 update_dprintf_commands
, NULL
,
16221 &setlist
, &showlist
);
16223 dprintf_function
= xstrdup ("printf");
16224 add_setshow_string_cmd ("dprintf-function", class_support
,
16225 &dprintf_function
, _("\
16226 Set the function to use for dynamic printf."), _("\
16227 Show the function to use for dynamic printf."), NULL
,
16228 update_dprintf_commands
, NULL
,
16229 &setlist
, &showlist
);
16231 dprintf_channel
= xstrdup ("");
16232 add_setshow_string_cmd ("dprintf-channel", class_support
,
16233 &dprintf_channel
, _("\
16234 Set the channel to use for dynamic printf."), _("\
16235 Show the channel to use for dynamic printf."), NULL
,
16236 update_dprintf_commands
, NULL
,
16237 &setlist
, &showlist
);
16239 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16240 &disconnected_dprintf
, _("\
16241 Set whether dprintf continues after GDB disconnects."), _("\
16242 Show whether dprintf continues after GDB disconnects."), _("\
16243 Use this to let dprintf commands continue to hit and produce output\n\
16244 even if GDB disconnects or detaches from the target."),
16247 &setlist
, &showlist
);
16249 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16250 Target agent only formatted printing, like the C \"printf\" function.\n\
16251 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
16252 This supports most C printf format specifications, like %s, %d, etc.\n\
16253 This is useful for formatted output in user-defined commands."));
16255 automatic_hardware_breakpoints
= true;
16257 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
16259 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,