1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2021 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
48 #include "cli/cli-script.h"
52 #include "observable.h"
58 #include "parser-defs.h"
59 #include "gdb_regex.h"
61 #include "cli/cli-utils.h"
64 #include "dummy-frame.h"
66 #include "gdbsupport/format.h"
67 #include "thread-fsm.h"
68 #include "tid-parse.h"
69 #include "cli/cli-style.h"
71 /* readline include files */
72 #include "readline/tilde.h"
74 /* readline defines this. */
77 #include "mi/mi-common.h"
78 #include "extension.h"
80 #include "progspace-and-thread.h"
81 #include "gdbsupport/array-view.h"
82 #include "gdbsupport/gdb_optional.h"
84 /* Prototypes for local functions. */
86 static void map_breakpoint_numbers (const char *,
87 gdb::function_view
<void (breakpoint
*)>);
89 static void breakpoint_re_set_default (struct breakpoint
*);
92 create_sals_from_location_default (struct event_location
*location
,
93 struct linespec_result
*canonical
,
94 enum bptype type_wanted
);
96 static void create_breakpoints_sal_default (struct gdbarch
*,
97 struct linespec_result
*,
98 gdb::unique_xmalloc_ptr
<char>,
99 gdb::unique_xmalloc_ptr
<char>,
101 enum bpdisp
, int, int,
103 const struct breakpoint_ops
*,
104 int, int, int, unsigned);
106 static std::vector
<symtab_and_line
> decode_location_default
107 (struct breakpoint
*b
, struct event_location
*location
,
108 struct program_space
*search_pspace
);
110 static int can_use_hardware_watchpoint
111 (const std::vector
<value_ref_ptr
> &vals
);
113 static void mention (struct breakpoint
*);
115 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
117 const struct breakpoint_ops
*);
118 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
119 const struct symtab_and_line
*);
121 /* This function is used in gdbtk sources and thus can not be made
123 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
124 struct symtab_and_line
,
126 const struct breakpoint_ops
*);
128 static struct breakpoint
*
129 momentary_breakpoint_from_master (struct breakpoint
*orig
,
131 const struct breakpoint_ops
*ops
,
134 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
136 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
140 static void describe_other_breakpoints (struct gdbarch
*,
141 struct program_space
*, CORE_ADDR
,
142 struct obj_section
*, int);
144 static int watchpoint_locations_match (struct bp_location
*loc1
,
145 struct bp_location
*loc2
);
147 static int breakpoint_locations_match (struct bp_location
*loc1
,
148 struct bp_location
*loc2
,
149 bool sw_hw_bps_match
= false);
151 static int breakpoint_location_address_match (struct bp_location
*bl
,
152 const struct address_space
*aspace
,
155 static int breakpoint_location_address_range_overlap (struct bp_location
*,
156 const address_space
*,
159 static int remove_breakpoint (struct bp_location
*);
160 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
162 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
164 static int hw_breakpoint_used_count (void);
166 static int hw_watchpoint_use_count (struct breakpoint
*);
168 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
170 int *other_type_used
);
172 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
175 static void decref_bp_location (struct bp_location
**loc
);
177 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
179 /* update_global_location_list's modes of operation wrt to whether to
180 insert locations now. */
181 enum ugll_insert_mode
183 /* Don't insert any breakpoint locations into the inferior, only
184 remove already-inserted locations that no longer should be
185 inserted. Functions that delete a breakpoint or breakpoints
186 should specify this mode, so that deleting a breakpoint doesn't
187 have the side effect of inserting the locations of other
188 breakpoints that are marked not-inserted, but should_be_inserted
189 returns true on them.
191 This behavior is useful is situations close to tear-down -- e.g.,
192 after an exec, while the target still has execution, but
193 breakpoint shadows of the previous executable image should *NOT*
194 be restored to the new image; or before detaching, where the
195 target still has execution and wants to delete breakpoints from
196 GDB's lists, and all breakpoints had already been removed from
200 /* May insert breakpoints iff breakpoints_should_be_inserted_now
201 claims breakpoints should be inserted now. */
204 /* Insert locations now, irrespective of
205 breakpoints_should_be_inserted_now. E.g., say all threads are
206 stopped right now, and the user did "continue". We need to
207 insert breakpoints _before_ resuming the target, but
208 UGLL_MAY_INSERT wouldn't insert them, because
209 breakpoints_should_be_inserted_now returns false at that point,
210 as no thread is running yet. */
214 static void update_global_location_list (enum ugll_insert_mode
);
216 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
218 static void insert_breakpoint_locations (void);
220 static void trace_pass_command (const char *, int);
222 static void set_tracepoint_count (int num
);
224 static bool is_masked_watchpoint (const struct breakpoint
*b
);
226 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
228 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
231 static int strace_marker_p (struct breakpoint
*b
);
233 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
234 that are implemented on top of software or hardware breakpoints
235 (user breakpoints, internal and momentary breakpoints, etc.). */
236 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
238 /* Internal breakpoints class type. */
239 static struct breakpoint_ops internal_breakpoint_ops
;
241 /* Momentary breakpoints class type. */
242 static struct breakpoint_ops momentary_breakpoint_ops
;
244 /* The breakpoint_ops structure to be used in regular user created
246 struct breakpoint_ops bkpt_breakpoint_ops
;
248 /* Breakpoints set on probes. */
249 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
251 /* Tracepoints set on probes. */
252 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
254 /* Dynamic printf class type. */
255 struct breakpoint_ops dprintf_breakpoint_ops
;
257 /* The style in which to perform a dynamic printf. This is a user
258 option because different output options have different tradeoffs;
259 if GDB does the printing, there is better error handling if there
260 is a problem with any of the arguments, but using an inferior
261 function lets you have special-purpose printers and sending of
262 output to the same place as compiled-in print functions. */
264 static const char dprintf_style_gdb
[] = "gdb";
265 static const char dprintf_style_call
[] = "call";
266 static const char dprintf_style_agent
[] = "agent";
267 static const char *const dprintf_style_enums
[] = {
273 static const char *dprintf_style
= dprintf_style_gdb
;
275 /* The function to use for dynamic printf if the preferred style is to
276 call into the inferior. The value is simply a string that is
277 copied into the command, so it can be anything that GDB can
278 evaluate to a callable address, not necessarily a function name. */
280 static char *dprintf_function
;
282 /* The channel to use for dynamic printf if the preferred style is to
283 call into the inferior; if a nonempty string, it will be passed to
284 the call as the first argument, with the format string as the
285 second. As with the dprintf function, this can be anything that
286 GDB knows how to evaluate, so in addition to common choices like
287 "stderr", this could be an app-specific expression like
288 "mystreams[curlogger]". */
290 static char *dprintf_channel
;
292 /* True if dprintf commands should continue to operate even if GDB
294 static bool disconnected_dprintf
= true;
296 struct command_line
*
297 breakpoint_commands (struct breakpoint
*b
)
299 return b
->commands
? b
->commands
.get () : NULL
;
302 /* Flag indicating that a command has proceeded the inferior past the
303 current breakpoint. */
305 static bool breakpoint_proceeded
;
308 bpdisp_text (enum bpdisp disp
)
310 /* NOTE: the following values are a part of MI protocol and
311 represent values of 'disp' field returned when inferior stops at
313 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
315 return bpdisps
[(int) disp
];
318 /* Prototypes for exported functions. */
319 /* If FALSE, gdb will not use hardware support for watchpoints, even
320 if such is available. */
321 static int can_use_hw_watchpoints
;
324 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
325 struct cmd_list_element
*c
,
328 fprintf_filtered (file
,
329 _("Debugger's willingness to use "
330 "watchpoint hardware is %s.\n"),
334 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
335 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
336 for unrecognized breakpoint locations.
337 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
338 static enum auto_boolean pending_break_support
;
340 show_pending_break_support (struct ui_file
*file
, int from_tty
,
341 struct cmd_list_element
*c
,
344 fprintf_filtered (file
,
345 _("Debugger's behavior regarding "
346 "pending breakpoints is %s.\n"),
350 /* If true, gdb will automatically use hardware breakpoints for breakpoints
351 set with "break" but falling in read-only memory.
352 If false, gdb will warn about such breakpoints, but won't automatically
353 use hardware breakpoints. */
354 static bool automatic_hardware_breakpoints
;
356 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
357 struct cmd_list_element
*c
,
360 fprintf_filtered (file
,
361 _("Automatic usage of hardware breakpoints is %s.\n"),
365 /* If on, GDB keeps breakpoints inserted even if the inferior is
366 stopped, and immediately inserts any new breakpoints as soon as
367 they're created. If off (default), GDB keeps breakpoints off of
368 the target as long as possible. That is, it delays inserting
369 breakpoints until the next resume, and removes them again when the
370 target fully stops. This is a bit safer in case GDB crashes while
371 processing user input. */
372 static bool always_inserted_mode
= false;
375 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
376 struct cmd_list_element
*c
, const char *value
)
378 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
382 /* See breakpoint.h. */
385 breakpoints_should_be_inserted_now (void)
387 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
389 /* If breakpoints are global, they should be inserted even if no
390 thread under gdb's control is running, or even if there are
391 no threads under GDB's control yet. */
396 if (always_inserted_mode
)
398 /* The user wants breakpoints inserted even if all threads
403 for (inferior
*inf
: all_inferiors ())
404 if (inf
->has_execution ()
405 && threads_are_executing (inf
->process_target ()))
408 /* Don't remove breakpoints yet if, even though all threads are
409 stopped, we still have events to process. */
410 for (thread_info
*tp
: all_non_exited_threads ())
412 && tp
->suspend
.waitstatus_pending_p
)
418 static const char condition_evaluation_both
[] = "host or target";
420 /* Modes for breakpoint condition evaluation. */
421 static const char condition_evaluation_auto
[] = "auto";
422 static const char condition_evaluation_host
[] = "host";
423 static const char condition_evaluation_target
[] = "target";
424 static const char *const condition_evaluation_enums
[] = {
425 condition_evaluation_auto
,
426 condition_evaluation_host
,
427 condition_evaluation_target
,
431 /* Global that holds the current mode for breakpoint condition evaluation. */
432 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
434 /* Global that we use to display information to the user (gets its value from
435 condition_evaluation_mode_1. */
436 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
438 /* Translate a condition evaluation mode MODE into either "host"
439 or "target". This is used mostly to translate from "auto" to the
440 real setting that is being used. It returns the translated
444 translate_condition_evaluation_mode (const char *mode
)
446 if (mode
== condition_evaluation_auto
)
448 if (target_supports_evaluation_of_breakpoint_conditions ())
449 return condition_evaluation_target
;
451 return condition_evaluation_host
;
457 /* Discovers what condition_evaluation_auto translates to. */
460 breakpoint_condition_evaluation_mode (void)
462 return translate_condition_evaluation_mode (condition_evaluation_mode
);
465 /* Return true if GDB should evaluate breakpoint conditions or false
469 gdb_evaluates_breakpoint_condition_p (void)
471 const char *mode
= breakpoint_condition_evaluation_mode ();
473 return (mode
== condition_evaluation_host
);
476 /* Are we executing breakpoint commands? */
477 static int executing_breakpoint_commands
;
479 /* Are overlay event breakpoints enabled? */
480 static int overlay_events_enabled
;
482 /* See description in breakpoint.h. */
483 bool target_exact_watchpoints
= false;
485 /* Walk the following statement or block through all breakpoints.
486 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
487 current breakpoint. */
489 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
490 for (B = breakpoint_chain; \
491 B ? (TMP=B->next, 1): 0; \
494 /* Iterates through locations with address ADDRESS for the currently selected
495 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
496 to where the loop should start from.
497 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
498 appropriate location to start with. */
500 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
501 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
502 BP_LOCP_TMP = BP_LOCP_START; \
504 && (BP_LOCP_TMP < bp_locations.data () + bp_locations.size () \
505 && (*BP_LOCP_TMP)->address == ADDRESS); \
508 /* Chains of all breakpoints defined. */
510 static struct breakpoint
*breakpoint_chain
;
512 /* Breakpoint linked list range. */
514 using breakpoint_range
= next_adapter
<breakpoint
, breakpoint_iterator
>;
516 /* Return a range to iterate over all breakpoints. */
518 static breakpoint_range
521 return breakpoint_range (breakpoint_chain
);
524 /* Breakpoint linked list range, safe against deletion of the current
525 breakpoint while iterating. */
527 using breakpoint_safe_range
= basic_safe_range
<breakpoint_range
>;
529 /* Return a range to iterate over all breakpoints. This range is safe against
530 deletion of the current breakpoint while iterating. */
532 static breakpoint_safe_range
533 all_breakpoints_safe ()
535 return breakpoint_safe_range (all_breakpoints ());
538 /* See breakpoint.h. */
543 return tracepoint_range (breakpoint_chain
);
546 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
548 static std::vector
<bp_location
*> bp_locations
;
550 static const std::vector
<bp_location
*> &
556 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
557 ADDRESS for the current elements of BP_LOCATIONS which get a valid
558 result from bp_location_has_shadow. You can use it for roughly
559 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
560 an address you need to read. */
562 static CORE_ADDR bp_locations_placed_address_before_address_max
;
564 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
565 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
566 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
567 You can use it for roughly limiting the subrange of BP_LOCATIONS to
568 scan for shadow bytes for an address you need to read. */
570 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
572 /* The locations that no longer correspond to any breakpoint, unlinked
573 from the bp_locations array, but for which a hit may still be
574 reported by a target. */
575 static std::vector
<bp_location
*> moribund_locations
;
577 /* Number of last breakpoint made. */
579 static int breakpoint_count
;
581 /* The value of `breakpoint_count' before the last command that
582 created breakpoints. If the last (break-like) command created more
583 than one breakpoint, then the difference between BREAKPOINT_COUNT
584 and PREV_BREAKPOINT_COUNT is more than one. */
585 static int prev_breakpoint_count
;
587 /* Number of last tracepoint made. */
589 static int tracepoint_count
;
591 static struct cmd_list_element
*breakpoint_set_cmdlist
;
592 static struct cmd_list_element
*breakpoint_show_cmdlist
;
593 struct cmd_list_element
*save_cmdlist
;
595 /* See declaration at breakpoint.h. */
598 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
601 for (breakpoint
*b
: all_breakpoints ())
602 if (func (b
, user_data
) != 0)
608 /* Return whether a breakpoint is an active enabled breakpoint. */
610 breakpoint_enabled (struct breakpoint
*b
)
612 return (b
->enable_state
== bp_enabled
);
615 /* Set breakpoint count to NUM. */
618 set_breakpoint_count (int num
)
620 prev_breakpoint_count
= breakpoint_count
;
621 breakpoint_count
= num
;
622 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
625 /* Used by `start_rbreak_breakpoints' below, to record the current
626 breakpoint count before "rbreak" creates any breakpoint. */
627 static int rbreak_start_breakpoint_count
;
629 /* Called at the start an "rbreak" command to record the first
632 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
634 rbreak_start_breakpoint_count
= breakpoint_count
;
637 /* Called at the end of an "rbreak" command to record the last
640 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
642 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
645 /* Used in run_command to zero the hit count when a new run starts. */
648 clear_breakpoint_hit_counts (void)
650 for (breakpoint
*b
: all_breakpoints ())
655 /* Return the breakpoint with the specified number, or NULL
656 if the number does not refer to an existing breakpoint. */
659 get_breakpoint (int num
)
661 for (breakpoint
*b
: all_breakpoints ())
662 if (b
->number
== num
)
670 /* Mark locations as "conditions have changed" in case the target supports
671 evaluating conditions on its side. */
674 mark_breakpoint_modified (struct breakpoint
*b
)
676 /* This is only meaningful if the target is
677 evaluating conditions and if the user has
678 opted for condition evaluation on the target's
680 if (gdb_evaluates_breakpoint_condition_p ()
681 || !target_supports_evaluation_of_breakpoint_conditions ())
684 if (!is_breakpoint (b
))
687 for (bp_location
*loc
: b
->locations ())
688 loc
->condition_changed
= condition_modified
;
691 /* Mark location as "conditions have changed" in case the target supports
692 evaluating conditions on its side. */
695 mark_breakpoint_location_modified (struct bp_location
*loc
)
697 /* This is only meaningful if the target is
698 evaluating conditions and if the user has
699 opted for condition evaluation on the target's
701 if (gdb_evaluates_breakpoint_condition_p ()
702 || !target_supports_evaluation_of_breakpoint_conditions ())
706 if (!is_breakpoint (loc
->owner
))
709 loc
->condition_changed
= condition_modified
;
712 /* Sets the condition-evaluation mode using the static global
713 condition_evaluation_mode. */
716 set_condition_evaluation_mode (const char *args
, int from_tty
,
717 struct cmd_list_element
*c
)
719 const char *old_mode
, *new_mode
;
721 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
722 && !target_supports_evaluation_of_breakpoint_conditions ())
724 condition_evaluation_mode_1
= condition_evaluation_mode
;
725 warning (_("Target does not support breakpoint condition evaluation.\n"
726 "Using host evaluation mode instead."));
730 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
731 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
733 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
734 settings was "auto". */
735 condition_evaluation_mode
= condition_evaluation_mode_1
;
737 /* Only update the mode if the user picked a different one. */
738 if (new_mode
!= old_mode
)
740 /* If the user switched to a different evaluation mode, we
741 need to synch the changes with the target as follows:
743 "host" -> "target": Send all (valid) conditions to the target.
744 "target" -> "host": Remove all the conditions from the target.
747 if (new_mode
== condition_evaluation_target
)
749 /* Mark everything modified and synch conditions with the
751 for (bp_location
*loc
: all_bp_locations ())
752 mark_breakpoint_location_modified (loc
);
756 /* Manually mark non-duplicate locations to synch conditions
757 with the target. We do this to remove all the conditions the
758 target knows about. */
759 for (bp_location
*loc
: all_bp_locations ())
760 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
761 loc
->needs_update
= 1;
765 update_global_location_list (UGLL_MAY_INSERT
);
771 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
772 what "auto" is translating to. */
775 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
776 struct cmd_list_element
*c
, const char *value
)
778 if (condition_evaluation_mode
== condition_evaluation_auto
)
779 fprintf_filtered (file
,
780 _("Breakpoint condition evaluation "
781 "mode is %s (currently %s).\n"),
783 breakpoint_condition_evaluation_mode ());
785 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
789 /* A comparison function for bp_location AP and BP that is used by
790 bsearch. This comparison function only cares about addresses, unlike
791 the more general bp_location_is_less_than function. */
794 bp_locations_compare_addrs (const void *ap
, const void *bp
)
796 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
797 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
799 if (a
->address
== b
->address
)
802 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
805 /* Helper function to skip all bp_locations with addresses
806 less than ADDRESS. It returns the first bp_location that
807 is greater than or equal to ADDRESS. If none is found, just
810 static struct bp_location
**
811 get_first_locp_gte_addr (CORE_ADDR address
)
813 struct bp_location dummy_loc
;
814 struct bp_location
*dummy_locp
= &dummy_loc
;
815 struct bp_location
**locp_found
= NULL
;
817 /* Initialize the dummy location's address field. */
818 dummy_loc
.address
= address
;
820 /* Find a close match to the first location at ADDRESS. */
821 locp_found
= ((struct bp_location
**)
822 bsearch (&dummy_locp
, bp_locations
.data (), bp_locations
.size (),
823 sizeof (struct bp_location
**),
824 bp_locations_compare_addrs
));
826 /* Nothing was found, nothing left to do. */
827 if (locp_found
== NULL
)
830 /* We may have found a location that is at ADDRESS but is not the first in the
831 location's list. Go backwards (if possible) and locate the first one. */
832 while ((locp_found
- 1) >= bp_locations
.data ()
833 && (*(locp_found
- 1))->address
== address
)
839 /* Parse COND_STRING in the context of LOC and set as the condition
840 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
841 the number of LOC within its owner. In case of parsing error, mark
842 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
845 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
846 int bp_num
, int loc_num
)
848 bool has_junk
= false;
851 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
852 block_for_pc (loc
->address
), 0);
853 if (*cond_string
!= 0)
857 loc
->cond
= std::move (new_exp
);
858 if (loc
->disabled_by_cond
&& loc
->enabled
)
859 printf_filtered (_("Breakpoint %d's condition is now valid at "
860 "location %d, enabling.\n"),
863 loc
->disabled_by_cond
= false;
866 catch (const gdb_exception_error
&e
)
870 /* Warn if a user-enabled location is now becoming disabled-by-cond.
871 BP_NUM is 0 if the breakpoint is being defined for the first
872 time using the "break ... if ..." command, and non-zero if
875 warning (_("failed to validate condition at location %d.%d, "
876 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
878 warning (_("failed to validate condition at location %d, "
879 "disabling:\n %s"), loc_num
, e
.what ());
882 loc
->disabled_by_cond
= true;
886 error (_("Garbage '%s' follows condition"), cond_string
);
890 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
891 int from_tty
, bool force
)
895 xfree (b
->cond_string
);
896 b
->cond_string
= nullptr;
898 if (is_watchpoint (b
))
899 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
903 for (bp_location
*loc
: b
->locations ())
906 if (loc
->disabled_by_cond
&& loc
->enabled
)
907 printf_filtered (_("Breakpoint %d's condition is now valid at "
908 "location %d, enabling.\n"),
910 loc
->disabled_by_cond
= false;
913 /* No need to free the condition agent expression
914 bytecode (if we have one). We will handle this
915 when we go through update_global_location_list. */
920 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
924 if (is_watchpoint (b
))
926 innermost_block_tracker tracker
;
927 const char *arg
= exp
;
928 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
930 error (_("Junk at end of expression"));
931 watchpoint
*w
= static_cast<watchpoint
*> (b
);
932 w
->cond_exp
= std::move (new_exp
);
933 w
->cond_exp_valid_block
= tracker
.block ();
937 /* Parse and set condition expressions. We make two passes.
938 In the first, we parse the condition string to see if it
939 is valid in at least one location. If so, the condition
940 would be accepted. So we go ahead and set the locations'
941 conditions. In case no valid case is found, we throw
942 the error and the condition string will be rejected.
943 This two-pass approach is taken to avoid setting the
944 state of locations in case of a reject. */
945 for (bp_location
*loc
: b
->locations ())
949 const char *arg
= exp
;
950 parse_exp_1 (&arg
, loc
->address
,
951 block_for_pc (loc
->address
), 0);
953 error (_("Junk at end of expression"));
956 catch (const gdb_exception_error
&e
)
958 /* Condition string is invalid. If this happens to
959 be the last loc, abandon (if not forced) or continue
961 if (loc
->next
== nullptr && !force
)
966 /* If we reach here, the condition is valid at some locations. */
968 for (bp_location
*loc
: b
->locations ())
970 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
975 /* We know that the new condition parsed successfully. The
976 condition string of the breakpoint can be safely updated. */
977 xfree (b
->cond_string
);
978 b
->cond_string
= xstrdup (exp
);
979 b
->condition_not_parsed
= 0;
981 mark_breakpoint_modified (b
);
983 gdb::observers::breakpoint_modified
.notify (b
);
986 /* See breakpoint.h. */
989 set_breakpoint_condition (int bpnum
, const char *exp
, int from_tty
,
992 for (breakpoint
*b
: all_breakpoints ())
993 if (b
->number
== bpnum
)
995 /* Check if this breakpoint has a "stop" method implemented in an
996 extension language. This method and conditions entered into GDB
997 from the CLI are mutually exclusive. */
998 const struct extension_language_defn
*extlang
999 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1001 if (extlang
!= NULL
)
1003 error (_("Only one stop condition allowed. There is currently"
1004 " a %s stop condition defined for this breakpoint."),
1005 ext_lang_capitalized_name (extlang
));
1007 set_breakpoint_condition (b
, exp
, from_tty
, force
);
1009 if (is_breakpoint (b
))
1010 update_global_location_list (UGLL_MAY_INSERT
);
1015 error (_("No breakpoint number %d."), bpnum
);
1018 /* The options for the "condition" command. */
1020 struct condition_command_opts
1023 bool force_condition
= false;
1026 static const gdb::option::option_def condition_command_option_defs
[] = {
1028 gdb::option::flag_option_def
<condition_command_opts
> {
1030 [] (condition_command_opts
*opts
) { return &opts
->force_condition
; },
1031 N_("Set the condition even if it is invalid for all current locations."),
1036 /* Create an option_def_group for the "condition" options, with
1037 CC_OPTS as context. */
1039 static inline gdb::option::option_def_group
1040 make_condition_command_options_def_group (condition_command_opts
*cc_opts
)
1042 return {{condition_command_option_defs
}, cc_opts
};
1045 /* Completion for the "condition" command. */
1048 condition_completer (struct cmd_list_element
*cmd
,
1049 completion_tracker
&tracker
,
1050 const char *text
, const char * /*word*/)
1052 bool has_no_arguments
= (*text
== '\0');
1053 condition_command_opts cc_opts
;
1054 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1055 if (gdb::option::complete_options
1056 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
))
1059 text
= skip_spaces (text
);
1060 const char *space
= skip_to_space (text
);
1067 tracker
.advance_custom_word_point_by (1);
1068 /* We don't support completion of history indices. */
1069 if (!isdigit (text
[1]))
1070 complete_internalvar (tracker
, &text
[1]);
1074 /* Suggest the "-force" flag if no arguments are given. If
1075 arguments were passed, they either already include the flag,
1076 or we are beyond the point of suggesting it because it's
1077 positionally the first argument. */
1078 if (has_no_arguments
)
1079 gdb::option::complete_on_all_options (tracker
, group
);
1081 /* We're completing the breakpoint number. */
1082 len
= strlen (text
);
1084 for (breakpoint
*b
: all_breakpoints ())
1088 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1090 if (strncmp (number
, text
, len
) == 0)
1091 tracker
.add_completion (make_unique_xstrdup (number
));
1097 /* We're completing the expression part. Skip the breakpoint num. */
1098 const char *exp_start
= skip_spaces (space
);
1099 tracker
.advance_custom_word_point_by (exp_start
- text
);
1101 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
1102 expression_completer (cmd
, tracker
, text
, word
);
1105 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1108 condition_command (const char *arg
, int from_tty
)
1114 error_no_arg (_("breakpoint number"));
1118 /* Check if the "-force" flag was passed. */
1119 condition_command_opts cc_opts
;
1120 const auto group
= make_condition_command_options_def_group (&cc_opts
);
1121 gdb::option::process_options
1122 (&p
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR
, group
);
1124 bnum
= get_number (&p
);
1126 error (_("Bad breakpoint argument: '%s'"), arg
);
1128 set_breakpoint_condition (bnum
, p
, from_tty
, cc_opts
.force_condition
);
1131 /* Check that COMMAND do not contain commands that are suitable
1132 only for tracepoints and not suitable for ordinary breakpoints.
1133 Throw if any such commands is found. */
1136 check_no_tracepoint_commands (struct command_line
*commands
)
1138 struct command_line
*c
;
1140 for (c
= commands
; c
; c
= c
->next
)
1142 if (c
->control_type
== while_stepping_control
)
1143 error (_("The 'while-stepping' command can "
1144 "only be used for tracepoints"));
1146 check_no_tracepoint_commands (c
->body_list_0
.get ());
1147 check_no_tracepoint_commands (c
->body_list_1
.get ());
1149 /* Not that command parsing removes leading whitespace and comment
1150 lines and also empty lines. So, we only need to check for
1151 command directly. */
1152 if (strstr (c
->line
, "collect ") == c
->line
)
1153 error (_("The 'collect' command can only be used for tracepoints"));
1155 if (strstr (c
->line
, "teval ") == c
->line
)
1156 error (_("The 'teval' command can only be used for tracepoints"));
1160 struct longjmp_breakpoint
: public breakpoint
1162 ~longjmp_breakpoint () override
;
1165 /* Encapsulate tests for different types of tracepoints. */
1168 is_tracepoint_type (bptype type
)
1170 return (type
== bp_tracepoint
1171 || type
== bp_fast_tracepoint
1172 || type
== bp_static_tracepoint
);
1176 is_longjmp_type (bptype type
)
1178 return type
== bp_longjmp
|| type
== bp_exception
;
1181 /* See breakpoint.h. */
1184 is_tracepoint (const struct breakpoint
*b
)
1186 return is_tracepoint_type (b
->type
);
1189 /* Factory function to create an appropriate instance of breakpoint given
1192 static std::unique_ptr
<breakpoint
>
1193 new_breakpoint_from_type (bptype type
)
1197 if (is_tracepoint_type (type
))
1198 b
= new tracepoint ();
1199 else if (is_longjmp_type (type
))
1200 b
= new longjmp_breakpoint ();
1202 b
= new breakpoint ();
1204 return std::unique_ptr
<breakpoint
> (b
);
1207 /* A helper function that validates that COMMANDS are valid for a
1208 breakpoint. This function will throw an exception if a problem is
1212 validate_commands_for_breakpoint (struct breakpoint
*b
,
1213 struct command_line
*commands
)
1215 if (is_tracepoint (b
))
1217 struct tracepoint
*t
= (struct tracepoint
*) b
;
1218 struct command_line
*c
;
1219 struct command_line
*while_stepping
= 0;
1221 /* Reset the while-stepping step count. The previous commands
1222 might have included a while-stepping action, while the new
1226 /* We need to verify that each top-level element of commands is
1227 valid for tracepoints, that there's at most one
1228 while-stepping element, and that the while-stepping's body
1229 has valid tracing commands excluding nested while-stepping.
1230 We also need to validate the tracepoint action line in the
1231 context of the tracepoint --- validate_actionline actually
1232 has side effects, like setting the tracepoint's
1233 while-stepping STEP_COUNT, in addition to checking if the
1234 collect/teval actions parse and make sense in the
1235 tracepoint's context. */
1236 for (c
= commands
; c
; c
= c
->next
)
1238 if (c
->control_type
== while_stepping_control
)
1240 if (b
->type
== bp_fast_tracepoint
)
1241 error (_("The 'while-stepping' command "
1242 "cannot be used for fast tracepoint"));
1243 else if (b
->type
== bp_static_tracepoint
)
1244 error (_("The 'while-stepping' command "
1245 "cannot be used for static tracepoint"));
1248 error (_("The 'while-stepping' command "
1249 "can be used only once"));
1254 validate_actionline (c
->line
, b
);
1258 struct command_line
*c2
;
1260 gdb_assert (while_stepping
->body_list_1
== nullptr);
1261 c2
= while_stepping
->body_list_0
.get ();
1262 for (; c2
; c2
= c2
->next
)
1264 if (c2
->control_type
== while_stepping_control
)
1265 error (_("The 'while-stepping' command cannot be nested"));
1271 check_no_tracepoint_commands (commands
);
1275 /* Return a vector of all the static tracepoints set at ADDR. The
1276 caller is responsible for releasing the vector. */
1278 std::vector
<breakpoint
*>
1279 static_tracepoints_here (CORE_ADDR addr
)
1281 std::vector
<breakpoint
*> found
;
1283 for (breakpoint
*b
: all_breakpoints ())
1284 if (b
->type
== bp_static_tracepoint
)
1286 for (bp_location
*loc
: b
->locations ())
1287 if (loc
->address
== addr
)
1288 found
.push_back (b
);
1294 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1295 validate that only allowed commands are included. */
1298 breakpoint_set_commands (struct breakpoint
*b
,
1299 counted_command_line
&&commands
)
1301 validate_commands_for_breakpoint (b
, commands
.get ());
1303 b
->commands
= std::move (commands
);
1304 gdb::observers::breakpoint_modified
.notify (b
);
1307 /* Set the internal `silent' flag on the breakpoint. Note that this
1308 is not the same as the "silent" that may appear in the breakpoint's
1312 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1314 int old_silent
= b
->silent
;
1317 if (old_silent
!= silent
)
1318 gdb::observers::breakpoint_modified
.notify (b
);
1321 /* Set the thread for this breakpoint. If THREAD is -1, make the
1322 breakpoint work for any thread. */
1325 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1327 int old_thread
= b
->thread
;
1330 if (old_thread
!= thread
)
1331 gdb::observers::breakpoint_modified
.notify (b
);
1334 /* Set the task for this breakpoint. If TASK is 0, make the
1335 breakpoint work for any task. */
1338 breakpoint_set_task (struct breakpoint
*b
, int task
)
1340 int old_task
= b
->task
;
1343 if (old_task
!= task
)
1344 gdb::observers::breakpoint_modified
.notify (b
);
1348 commands_command_1 (const char *arg
, int from_tty
,
1349 struct command_line
*control
)
1351 counted_command_line cmd
;
1352 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1353 NULL after the call to read_command_lines if the user provides an empty
1354 list of command by just typing "end". */
1355 bool cmd_read
= false;
1357 std::string new_arg
;
1359 if (arg
== NULL
|| !*arg
)
1361 /* Argument not explicitly given. Synthesize it. */
1362 if (breakpoint_count
- prev_breakpoint_count
> 1)
1363 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1365 else if (breakpoint_count
> 0)
1366 new_arg
= string_printf ("%d", breakpoint_count
);
1370 /* Create a copy of ARG. This is needed because the "commands"
1371 command may be coming from a script. In that case, the read
1372 line buffer is going to be overwritten in the lambda of
1373 'map_breakpoint_numbers' below when reading the next line
1374 before we are are done parsing the breakpoint numbers. */
1377 arg
= new_arg
.c_str ();
1379 map_breakpoint_numbers
1380 (arg
, [&] (breakpoint
*b
)
1384 gdb_assert (cmd
== NULL
);
1385 if (control
!= NULL
)
1386 cmd
= control
->body_list_0
;
1390 = string_printf (_("Type commands for breakpoint(s) "
1391 "%s, one per line."),
1394 auto do_validate
= [=] (const char *line
)
1396 validate_actionline (line
, b
);
1398 gdb::function_view
<void (const char *)> validator
;
1399 if (is_tracepoint (b
))
1400 validator
= do_validate
;
1402 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1407 /* If a breakpoint was on the list more than once, we don't need to
1409 if (b
->commands
!= cmd
)
1411 validate_commands_for_breakpoint (b
, cmd
.get ());
1413 gdb::observers::breakpoint_modified
.notify (b
);
1419 commands_command (const char *arg
, int from_tty
)
1421 commands_command_1 (arg
, from_tty
, NULL
);
1424 /* Like commands_command, but instead of reading the commands from
1425 input stream, takes them from an already parsed command structure.
1427 This is used by cli-script.c to DTRT with breakpoint commands
1428 that are part of if and while bodies. */
1429 enum command_control_type
1430 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1432 commands_command_1 (arg
, 0, cmd
);
1433 return simple_control
;
1436 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1439 bp_location_has_shadow (struct bp_location
*bl
)
1441 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1445 if (bl
->target_info
.shadow_len
== 0)
1446 /* BL isn't valid, or doesn't shadow memory. */
1451 /* Update BUF, which is LEN bytes read from the target address
1452 MEMADDR, by replacing a memory breakpoint with its shadowed
1455 If READBUF is not NULL, this buffer must not overlap with the of
1456 the breakpoint location's shadow_contents buffer. Otherwise, a
1457 failed assertion internal error will be raised. */
1460 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1461 const gdb_byte
*writebuf_org
,
1462 ULONGEST memaddr
, LONGEST len
,
1463 struct bp_target_info
*target_info
,
1464 struct gdbarch
*gdbarch
)
1466 /* Now do full processing of the found relevant range of elements. */
1467 CORE_ADDR bp_addr
= 0;
1471 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1472 current_program_space
->aspace
, 0))
1474 /* The breakpoint is inserted in a different address space. */
1478 /* Addresses and length of the part of the breakpoint that
1480 bp_addr
= target_info
->placed_address
;
1481 bp_size
= target_info
->shadow_len
;
1483 if (bp_addr
+ bp_size
<= memaddr
)
1485 /* The breakpoint is entirely before the chunk of memory we are
1490 if (bp_addr
>= memaddr
+ len
)
1492 /* The breakpoint is entirely after the chunk of memory we are
1497 /* Offset within shadow_contents. */
1498 if (bp_addr
< memaddr
)
1500 /* Only copy the second part of the breakpoint. */
1501 bp_size
-= memaddr
- bp_addr
;
1502 bptoffset
= memaddr
- bp_addr
;
1506 if (bp_addr
+ bp_size
> memaddr
+ len
)
1508 /* Only copy the first part of the breakpoint. */
1509 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1512 if (readbuf
!= NULL
)
1514 /* Verify that the readbuf buffer does not overlap with the
1515 shadow_contents buffer. */
1516 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1517 || readbuf
>= (target_info
->shadow_contents
1518 + target_info
->shadow_len
));
1520 /* Update the read buffer with this inserted breakpoint's
1522 memcpy (readbuf
+ bp_addr
- memaddr
,
1523 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1527 const unsigned char *bp
;
1528 CORE_ADDR addr
= target_info
->reqstd_address
;
1531 /* Update the shadow with what we want to write to memory. */
1532 memcpy (target_info
->shadow_contents
+ bptoffset
,
1533 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1535 /* Determine appropriate breakpoint contents and size for this
1537 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1539 /* Update the final write buffer with this inserted
1540 breakpoint's INSN. */
1541 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1545 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1546 by replacing any memory breakpoints with their shadowed contents.
1548 If READBUF is not NULL, this buffer must not overlap with any of
1549 the breakpoint location's shadow_contents buffers. Otherwise,
1550 a failed assertion internal error will be raised.
1552 The range of shadowed area by each bp_location is:
1553 bl->address - bp_locations_placed_address_before_address_max
1554 up to bl->address + bp_locations_shadow_len_after_address_max
1555 The range we were requested to resolve shadows for is:
1556 memaddr ... memaddr + len
1557 Thus the safe cutoff boundaries for performance optimization are
1558 memaddr + len <= (bl->address
1559 - bp_locations_placed_address_before_address_max)
1561 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1564 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1565 const gdb_byte
*writebuf_org
,
1566 ULONGEST memaddr
, LONGEST len
)
1568 /* Left boundary, right boundary and median element of our binary
1570 unsigned bc_l
, bc_r
, bc
;
1572 /* Find BC_L which is a leftmost element which may affect BUF
1573 content. It is safe to report lower value but a failure to
1574 report higher one. */
1577 bc_r
= bp_locations
.size ();
1578 while (bc_l
+ 1 < bc_r
)
1580 struct bp_location
*bl
;
1582 bc
= (bc_l
+ bc_r
) / 2;
1583 bl
= bp_locations
[bc
];
1585 /* Check first BL->ADDRESS will not overflow due to the added
1586 constant. Then advance the left boundary only if we are sure
1587 the BC element can in no way affect the BUF content (MEMADDR
1588 to MEMADDR + LEN range).
1590 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1591 offset so that we cannot miss a breakpoint with its shadow
1592 range tail still reaching MEMADDR. */
1594 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1596 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1603 /* Due to the binary search above, we need to make sure we pick the
1604 first location that's at BC_L's address. E.g., if there are
1605 multiple locations at the same address, BC_L may end up pointing
1606 at a duplicate location, and miss the "master"/"inserted"
1607 location. Say, given locations L1, L2 and L3 at addresses A and
1610 L1@A, L2@A, L3@B, ...
1612 BC_L could end up pointing at location L2, while the "master"
1613 location could be L1. Since the `loc->inserted' flag is only set
1614 on "master" locations, we'd forget to restore the shadow of L1
1617 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1620 /* Now do full processing of the found relevant range of elements. */
1622 for (bc
= bc_l
; bc
< bp_locations
.size (); bc
++)
1624 struct bp_location
*bl
= bp_locations
[bc
];
1626 /* bp_location array has BL->OWNER always non-NULL. */
1627 if (bl
->owner
->type
== bp_none
)
1628 warning (_("reading through apparently deleted breakpoint #%d?"),
1631 /* Performance optimization: any further element can no longer affect BUF
1634 if (bl
->address
>= bp_locations_placed_address_before_address_max
1635 && memaddr
+ len
<= (bl
->address
1636 - bp_locations_placed_address_before_address_max
))
1639 if (!bp_location_has_shadow (bl
))
1642 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1643 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1647 /* See breakpoint.h. */
1650 is_breakpoint (const struct breakpoint
*bpt
)
1652 return (bpt
->type
== bp_breakpoint
1653 || bpt
->type
== bp_hardware_breakpoint
1654 || bpt
->type
== bp_dprintf
);
1657 /* Return true if BPT is of any hardware watchpoint kind. */
1660 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1662 return (bpt
->type
== bp_hardware_watchpoint
1663 || bpt
->type
== bp_read_watchpoint
1664 || bpt
->type
== bp_access_watchpoint
);
1667 /* See breakpoint.h. */
1670 is_watchpoint (const struct breakpoint
*bpt
)
1672 return (is_hardware_watchpoint (bpt
)
1673 || bpt
->type
== bp_watchpoint
);
1676 /* Returns true if the current thread and its running state are safe
1677 to evaluate or update watchpoint B. Watchpoints on local
1678 expressions need to be evaluated in the context of the thread that
1679 was current when the watchpoint was created, and, that thread needs
1680 to be stopped to be able to select the correct frame context.
1681 Watchpoints on global expressions can be evaluated on any thread,
1682 and in any state. It is presently left to the target allowing
1683 memory accesses when threads are running. */
1686 watchpoint_in_thread_scope (struct watchpoint
*b
)
1688 return (b
->pspace
== current_program_space
1689 && (b
->watchpoint_thread
== null_ptid
1690 || (inferior_ptid
== b
->watchpoint_thread
1691 && !inferior_thread ()->executing
)));
1694 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1695 associated bp_watchpoint_scope breakpoint. */
1698 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1700 if (w
->related_breakpoint
!= w
)
1702 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1703 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1704 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1705 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1706 w
->related_breakpoint
= w
;
1708 w
->disposition
= disp_del_at_next_stop
;
1711 /* Extract a bitfield value from value VAL using the bit parameters contained in
1714 static struct value
*
1715 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1717 struct value
*bit_val
;
1722 bit_val
= allocate_value (value_type (val
));
1724 unpack_value_bitfield (bit_val
,
1727 value_contents_for_printing (val
),
1734 /* Allocate a dummy location and add it to B, which must be a software
1735 watchpoint. This is required because even if a software watchpoint
1736 is not watching any memory, bpstat_stop_status requires a location
1737 to be able to report stops. */
1740 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1741 struct program_space
*pspace
)
1743 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1745 b
->loc
= allocate_bp_location (b
);
1746 b
->loc
->pspace
= pspace
;
1747 b
->loc
->address
= -1;
1748 b
->loc
->length
= -1;
1751 /* Returns true if B is a software watchpoint that is not watching any
1752 memory (e.g., "watch $pc"). */
1755 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1757 return (b
->type
== bp_watchpoint
1759 && b
->loc
->next
== NULL
1760 && b
->loc
->address
== -1
1761 && b
->loc
->length
== -1);
1764 /* Assuming that B is a watchpoint:
1765 - Reparse watchpoint expression, if REPARSE is non-zero
1766 - Evaluate expression and store the result in B->val
1767 - Evaluate the condition if there is one, and store the result
1769 - Update the list of values that must be watched in B->loc.
1771 If the watchpoint disposition is disp_del_at_next_stop, then do
1772 nothing. If this is local watchpoint that is out of scope, delete
1775 Even with `set breakpoint always-inserted on' the watchpoints are
1776 removed + inserted on each stop here. Normal breakpoints must
1777 never be removed because they might be missed by a running thread
1778 when debugging in non-stop mode. On the other hand, hardware
1779 watchpoints (is_hardware_watchpoint; processed here) are specific
1780 to each LWP since they are stored in each LWP's hardware debug
1781 registers. Therefore, such LWP must be stopped first in order to
1782 be able to modify its hardware watchpoints.
1784 Hardware watchpoints must be reset exactly once after being
1785 presented to the user. It cannot be done sooner, because it would
1786 reset the data used to present the watchpoint hit to the user. And
1787 it must not be done later because it could display the same single
1788 watchpoint hit during multiple GDB stops. Note that the latter is
1789 relevant only to the hardware watchpoint types bp_read_watchpoint
1790 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1791 not user-visible - its hit is suppressed if the memory content has
1794 The following constraints influence the location where we can reset
1795 hardware watchpoints:
1797 * target_stopped_by_watchpoint and target_stopped_data_address are
1798 called several times when GDB stops.
1801 * Multiple hardware watchpoints can be hit at the same time,
1802 causing GDB to stop. GDB only presents one hardware watchpoint
1803 hit at a time as the reason for stopping, and all the other hits
1804 are presented later, one after the other, each time the user
1805 requests the execution to be resumed. Execution is not resumed
1806 for the threads still having pending hit event stored in
1807 LWP_INFO->STATUS. While the watchpoint is already removed from
1808 the inferior on the first stop the thread hit event is kept being
1809 reported from its cached value by linux_nat_stopped_data_address
1810 until the real thread resume happens after the watchpoint gets
1811 presented and thus its LWP_INFO->STATUS gets reset.
1813 Therefore the hardware watchpoint hit can get safely reset on the
1814 watchpoint removal from inferior. */
1817 update_watchpoint (struct watchpoint
*b
, int reparse
)
1819 int within_current_scope
;
1820 struct frame_id saved_frame_id
;
1823 /* If this is a local watchpoint, we only want to check if the
1824 watchpoint frame is in scope if the current thread is the thread
1825 that was used to create the watchpoint. */
1826 if (!watchpoint_in_thread_scope (b
))
1829 if (b
->disposition
== disp_del_at_next_stop
)
1834 /* Determine if the watchpoint is within scope. */
1835 if (b
->exp_valid_block
== NULL
)
1836 within_current_scope
= 1;
1839 struct frame_info
*fi
= get_current_frame ();
1840 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1841 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1843 /* If we're at a point where the stack has been destroyed
1844 (e.g. in a function epilogue), unwinding may not work
1845 properly. Do not attempt to recreate locations at this
1846 point. See similar comments in watchpoint_check. */
1847 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1850 /* Save the current frame's ID so we can restore it after
1851 evaluating the watchpoint expression on its own frame. */
1852 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1853 took a frame parameter, so that we didn't have to change the
1856 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1858 fi
= frame_find_by_id (b
->watchpoint_frame
);
1859 within_current_scope
= (fi
!= NULL
);
1860 if (within_current_scope
)
1864 /* We don't free locations. They are stored in the bp_location array
1865 and update_global_location_list will eventually delete them and
1866 remove breakpoints if needed. */
1869 if (within_current_scope
&& reparse
)
1874 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1875 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1876 /* If the meaning of expression itself changed, the old value is
1877 no longer relevant. We don't want to report a watchpoint hit
1878 to the user when the old value and the new value may actually
1879 be completely different objects. */
1881 b
->val_valid
= false;
1883 /* Note that unlike with breakpoints, the watchpoint's condition
1884 expression is stored in the breakpoint object, not in the
1885 locations (re)created below. */
1886 if (b
->cond_string
!= NULL
)
1888 b
->cond_exp
.reset ();
1891 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1895 /* If we failed to parse the expression, for example because
1896 it refers to a global variable in a not-yet-loaded shared library,
1897 don't try to insert watchpoint. We don't automatically delete
1898 such watchpoint, though, since failure to parse expression
1899 is different from out-of-scope watchpoint. */
1900 if (!target_has_execution ())
1902 /* Without execution, memory can't change. No use to try and
1903 set watchpoint locations. The watchpoint will be reset when
1904 the target gains execution, through breakpoint_re_set. */
1905 if (!can_use_hw_watchpoints
)
1907 if (b
->ops
->works_in_software_mode (b
))
1908 b
->type
= bp_watchpoint
;
1910 error (_("Can't set read/access watchpoint when "
1911 "hardware watchpoints are disabled."));
1914 else if (within_current_scope
&& b
->exp
)
1916 std::vector
<value_ref_ptr
> val_chain
;
1917 struct value
*v
, *result
;
1918 struct program_space
*frame_pspace
;
1920 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &v
, &result
,
1923 /* Avoid setting b->val if it's already set. The meaning of
1924 b->val is 'the last value' user saw, and we should update
1925 it only if we reported that last value to user. As it
1926 happens, the code that reports it updates b->val directly.
1927 We don't keep track of the memory value for masked
1929 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1931 if (b
->val_bitsize
!= 0)
1932 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1933 b
->val
= release_value (v
);
1934 b
->val_valid
= true;
1937 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1939 /* Look at each value on the value chain. */
1940 gdb_assert (!val_chain
.empty ());
1941 for (const value_ref_ptr
&iter
: val_chain
)
1945 /* If it's a memory location, and GDB actually needed
1946 its contents to evaluate the expression, then we
1947 must watch it. If the first value returned is
1948 still lazy, that means an error occurred reading it;
1949 watch it anyway in case it becomes readable. */
1950 if (VALUE_LVAL (v
) == lval_memory
1951 && (v
== val_chain
[0] || ! value_lazy (v
)))
1953 struct type
*vtype
= check_typedef (value_type (v
));
1955 /* We only watch structs and arrays if user asked
1956 for it explicitly, never if they just happen to
1957 appear in the middle of some value chain. */
1959 || (vtype
->code () != TYPE_CODE_STRUCT
1960 && vtype
->code () != TYPE_CODE_ARRAY
))
1963 enum target_hw_bp_type type
;
1964 struct bp_location
*loc
, **tmp
;
1965 int bitpos
= 0, bitsize
= 0;
1967 if (value_bitsize (v
) != 0)
1969 /* Extract the bit parameters out from the bitfield
1971 bitpos
= value_bitpos (v
);
1972 bitsize
= value_bitsize (v
);
1974 else if (v
== result
&& b
->val_bitsize
!= 0)
1976 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1977 lvalue whose bit parameters are saved in the fields
1978 VAL_BITPOS and VAL_BITSIZE. */
1979 bitpos
= b
->val_bitpos
;
1980 bitsize
= b
->val_bitsize
;
1983 addr
= value_address (v
);
1986 /* Skip the bytes that don't contain the bitfield. */
1991 if (b
->type
== bp_read_watchpoint
)
1993 else if (b
->type
== bp_access_watchpoint
)
1996 loc
= allocate_bp_location (b
);
1997 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
2000 loc
->gdbarch
= value_type (v
)->arch ();
2002 loc
->pspace
= frame_pspace
;
2003 loc
->address
= address_significant (loc
->gdbarch
, addr
);
2007 /* Just cover the bytes that make up the bitfield. */
2008 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
2011 loc
->length
= TYPE_LENGTH (value_type (v
));
2013 loc
->watchpoint_type
= type
;
2018 /* Change the type of breakpoint between hardware assisted or
2019 an ordinary watchpoint depending on the hardware support
2020 and free hardware slots. REPARSE is set when the inferior
2025 enum bp_loc_type loc_type
;
2027 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
2031 int i
, target_resources_ok
, other_type_used
;
2034 /* Use an exact watchpoint when there's only one memory region to be
2035 watched, and only one debug register is needed to watch it. */
2036 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
2038 /* We need to determine how many resources are already
2039 used for all other hardware watchpoints plus this one
2040 to see if we still have enough resources to also fit
2041 this watchpoint in as well. */
2043 /* If this is a software watchpoint, we try to turn it
2044 to a hardware one -- count resources as if B was of
2045 hardware watchpoint type. */
2047 if (type
== bp_watchpoint
)
2048 type
= bp_hardware_watchpoint
;
2050 /* This watchpoint may or may not have been placed on
2051 the list yet at this point (it won't be in the list
2052 if we're trying to create it for the first time,
2053 through watch_command), so always account for it
2056 /* Count resources used by all watchpoints except B. */
2057 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2059 /* Add in the resources needed for B. */
2060 i
+= hw_watchpoint_use_count (b
);
2063 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2064 if (target_resources_ok
<= 0)
2066 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2068 if (target_resources_ok
== 0 && !sw_mode
)
2069 error (_("Target does not support this type of "
2070 "hardware watchpoint."));
2071 else if (target_resources_ok
< 0 && !sw_mode
)
2072 error (_("There are not enough available hardware "
2073 "resources for this watchpoint."));
2075 /* Downgrade to software watchpoint. */
2076 b
->type
= bp_watchpoint
;
2080 /* If this was a software watchpoint, we've just
2081 found we have enough resources to turn it to a
2082 hardware watchpoint. Otherwise, this is a
2087 else if (!b
->ops
->works_in_software_mode (b
))
2089 if (!can_use_hw_watchpoints
)
2090 error (_("Can't set read/access watchpoint when "
2091 "hardware watchpoints are disabled."));
2093 error (_("Expression cannot be implemented with "
2094 "read/access watchpoint."));
2097 b
->type
= bp_watchpoint
;
2099 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2100 : bp_loc_hardware_watchpoint
);
2101 for (bp_location
*bl
: b
->locations ())
2102 bl
->loc_type
= loc_type
;
2105 /* If a software watchpoint is not watching any memory, then the
2106 above left it without any location set up. But,
2107 bpstat_stop_status requires a location to be able to report
2108 stops, so make sure there's at least a dummy one. */
2109 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2110 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2112 else if (!within_current_scope
)
2114 printf_filtered (_("\
2115 Watchpoint %d deleted because the program has left the block\n\
2116 in which its expression is valid.\n"),
2118 watchpoint_del_at_next_stop (b
);
2121 /* Restore the selected frame. */
2123 select_frame (frame_find_by_id (saved_frame_id
));
2127 /* Returns 1 iff breakpoint location should be
2128 inserted in the inferior. We don't differentiate the type of BL's owner
2129 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2130 breakpoint_ops is not defined, because in insert_bp_location,
2131 tracepoint's insert_location will not be called. */
2133 should_be_inserted (struct bp_location
*bl
)
2135 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2138 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2141 if (!bl
->enabled
|| bl
->disabled_by_cond
2142 || bl
->shlib_disabled
|| bl
->duplicate
)
2145 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2148 /* This is set for example, when we're attached to the parent of a
2149 vfork, and have detached from the child. The child is running
2150 free, and we expect it to do an exec or exit, at which point the
2151 OS makes the parent schedulable again (and the target reports
2152 that the vfork is done). Until the child is done with the shared
2153 memory region, do not insert breakpoints in the parent, otherwise
2154 the child could still trip on the parent's breakpoints. Since
2155 the parent is blocked anyway, it won't miss any breakpoint. */
2156 if (bl
->pspace
->breakpoints_not_allowed
)
2159 /* Don't insert a breakpoint if we're trying to step past its
2160 location, except if the breakpoint is a single-step breakpoint,
2161 and the breakpoint's thread is the thread which is stepping past
2163 if ((bl
->loc_type
== bp_loc_software_breakpoint
2164 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2165 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2167 /* The single-step breakpoint may be inserted at the location
2168 we're trying to step if the instruction branches to itself.
2169 However, the instruction won't be executed at all and it may
2170 break the semantics of the instruction, for example, the
2171 instruction is a conditional branch or updates some flags.
2172 We can't fix it unless GDB is able to emulate the instruction
2173 or switch to displaced stepping. */
2174 && !(bl
->owner
->type
== bp_single_step
2175 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2177 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2178 paddress (bl
->gdbarch
, bl
->address
));
2182 /* Don't insert watchpoints if we're trying to step past the
2183 instruction that triggered one. */
2184 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2185 && stepping_past_nonsteppable_watchpoint ())
2187 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2188 "skipping watchpoint at %s:%d",
2189 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2196 /* Same as should_be_inserted but does the check assuming
2197 that the location is not duplicated. */
2200 unduplicated_should_be_inserted (struct bp_location
*bl
)
2203 const int save_duplicate
= bl
->duplicate
;
2206 result
= should_be_inserted (bl
);
2207 bl
->duplicate
= save_duplicate
;
2211 /* Parses a conditional described by an expression COND into an
2212 agent expression bytecode suitable for evaluation
2213 by the bytecode interpreter. Return NULL if there was
2214 any error during parsing. */
2216 static agent_expr_up
2217 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2222 agent_expr_up aexpr
;
2224 /* We don't want to stop processing, so catch any errors
2225 that may show up. */
2228 aexpr
= gen_eval_for_expr (scope
, cond
);
2231 catch (const gdb_exception_error
&ex
)
2233 /* If we got here, it means the condition could not be parsed to a valid
2234 bytecode expression and thus can't be evaluated on the target's side.
2235 It's no use iterating through the conditions. */
2238 /* We have a valid agent expression. */
2242 /* Based on location BL, create a list of breakpoint conditions to be
2243 passed on to the target. If we have duplicated locations with different
2244 conditions, we will add such conditions to the list. The idea is that the
2245 target will evaluate the list of conditions and will only notify GDB when
2246 one of them is true. */
2249 build_target_condition_list (struct bp_location
*bl
)
2251 struct bp_location
**locp
= NULL
, **loc2p
;
2252 int null_condition_or_parse_error
= 0;
2253 int modified
= bl
->needs_update
;
2254 struct bp_location
*loc
;
2256 /* Release conditions left over from a previous insert. */
2257 bl
->target_info
.conditions
.clear ();
2259 /* This is only meaningful if the target is
2260 evaluating conditions and if the user has
2261 opted for condition evaluation on the target's
2263 if (gdb_evaluates_breakpoint_condition_p ()
2264 || !target_supports_evaluation_of_breakpoint_conditions ())
2267 /* Do a first pass to check for locations with no assigned
2268 conditions or conditions that fail to parse to a valid agent
2269 expression bytecode. If any of these happen, then it's no use to
2270 send conditions to the target since this location will always
2271 trigger and generate a response back to GDB. Note we consider
2272 all locations at the same address irrespective of type, i.e.,
2273 even if the locations aren't considered duplicates (e.g.,
2274 software breakpoint and hardware breakpoint at the same
2276 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2279 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2283 /* Re-parse the conditions since something changed. In that
2284 case we already freed the condition bytecodes (see
2285 force_breakpoint_reinsertion). We just
2286 need to parse the condition to bytecodes again. */
2287 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2291 /* If we have a NULL bytecode expression, it means something
2292 went wrong or we have a null condition expression. */
2293 if (!loc
->cond_bytecode
)
2295 null_condition_or_parse_error
= 1;
2301 /* If any of these happened, it means we will have to evaluate the conditions
2302 for the location's address on gdb's side. It is no use keeping bytecodes
2303 for all the other duplicate locations, thus we free all of them here.
2305 This is so we have a finer control over which locations' conditions are
2306 being evaluated by GDB or the remote stub. */
2307 if (null_condition_or_parse_error
)
2309 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2312 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2314 /* Only go as far as the first NULL bytecode is
2316 if (!loc
->cond_bytecode
)
2319 loc
->cond_bytecode
.reset ();
2324 /* No NULL conditions or failed bytecode generation. Build a
2325 condition list for this location's address. If we have software
2326 and hardware locations at the same address, they aren't
2327 considered duplicates, but we still marge all the conditions
2328 anyway, as it's simpler, and doesn't really make a practical
2330 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2334 && is_breakpoint (loc
->owner
)
2335 && loc
->pspace
->num
== bl
->pspace
->num
2336 && loc
->owner
->enable_state
== bp_enabled
2338 && !loc
->disabled_by_cond
)
2340 /* Add the condition to the vector. This will be used later
2341 to send the conditions to the target. */
2342 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2349 /* Parses a command described by string CMD into an agent expression
2350 bytecode suitable for evaluation by the bytecode interpreter.
2351 Return NULL if there was any error during parsing. */
2353 static agent_expr_up
2354 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2356 const char *cmdrest
;
2357 const char *format_start
, *format_end
;
2358 struct gdbarch
*gdbarch
= get_current_arch ();
2365 if (*cmdrest
== ',')
2367 cmdrest
= skip_spaces (cmdrest
);
2369 if (*cmdrest
++ != '"')
2370 error (_("No format string following the location"));
2372 format_start
= cmdrest
;
2374 format_pieces
fpieces (&cmdrest
);
2376 format_end
= cmdrest
;
2378 if (*cmdrest
++ != '"')
2379 error (_("Bad format string, non-terminated '\"'."));
2381 cmdrest
= skip_spaces (cmdrest
);
2383 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2384 error (_("Invalid argument syntax"));
2386 if (*cmdrest
== ',')
2388 cmdrest
= skip_spaces (cmdrest
);
2390 /* For each argument, make an expression. */
2392 std::vector
<struct expression
*> argvec
;
2393 while (*cmdrest
!= '\0')
2398 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2399 argvec
.push_back (expr
.release ());
2401 if (*cmdrest
== ',')
2405 agent_expr_up aexpr
;
2407 /* We don't want to stop processing, so catch any errors
2408 that may show up. */
2411 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2412 format_start
, format_end
- format_start
,
2413 argvec
.size (), argvec
.data ());
2415 catch (const gdb_exception_error
&ex
)
2417 /* If we got here, it means the command could not be parsed to a valid
2418 bytecode expression and thus can't be evaluated on the target's side.
2419 It's no use iterating through the other commands. */
2422 /* We have a valid agent expression, return it. */
2426 /* Based on location BL, create a list of breakpoint commands to be
2427 passed on to the target. If we have duplicated locations with
2428 different commands, we will add any such to the list. */
2431 build_target_command_list (struct bp_location
*bl
)
2433 struct bp_location
**locp
= NULL
, **loc2p
;
2434 int null_command_or_parse_error
= 0;
2435 int modified
= bl
->needs_update
;
2436 struct bp_location
*loc
;
2438 /* Clear commands left over from a previous insert. */
2439 bl
->target_info
.tcommands
.clear ();
2441 if (!target_can_run_breakpoint_commands ())
2444 /* For now, limit to agent-style dprintf breakpoints. */
2445 if (dprintf_style
!= dprintf_style_agent
)
2448 /* For now, if we have any location at the same address that isn't a
2449 dprintf, don't install the target-side commands, as that would
2450 make the breakpoint not be reported to the core, and we'd lose
2452 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2455 if (is_breakpoint (loc
->owner
)
2456 && loc
->pspace
->num
== bl
->pspace
->num
2457 && loc
->owner
->type
!= bp_dprintf
)
2461 /* Do a first pass to check for locations with no assigned
2462 conditions or conditions that fail to parse to a valid agent expression
2463 bytecode. If any of these happen, then it's no use to send conditions
2464 to the target since this location will always trigger and generate a
2465 response back to GDB. */
2466 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2469 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2473 /* Re-parse the commands since something changed. In that
2474 case we already freed the command bytecodes (see
2475 force_breakpoint_reinsertion). We just
2476 need to parse the command to bytecodes again. */
2478 = parse_cmd_to_aexpr (bl
->address
,
2479 loc
->owner
->extra_string
);
2482 /* If we have a NULL bytecode expression, it means something
2483 went wrong or we have a null command expression. */
2484 if (!loc
->cmd_bytecode
)
2486 null_command_or_parse_error
= 1;
2492 /* If anything failed, then we're not doing target-side commands,
2494 if (null_command_or_parse_error
)
2496 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2499 if (is_breakpoint (loc
->owner
)
2500 && loc
->pspace
->num
== bl
->pspace
->num
)
2502 /* Only go as far as the first NULL bytecode is
2504 if (loc
->cmd_bytecode
== NULL
)
2507 loc
->cmd_bytecode
.reset ();
2512 /* No NULL commands or failed bytecode generation. Build a command
2513 list for all duplicate locations at this location's address.
2514 Note that here we must care for whether the breakpoint location
2515 types are considered duplicates, otherwise, say, if we have a
2516 software and hardware location at the same address, the target
2517 could end up running the commands twice. For the moment, we only
2518 support targets-side commands with dprintf, but it doesn't hurt
2519 to be pedantically correct in case that changes. */
2520 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2523 if (breakpoint_locations_match (bl
, loc
)
2524 && loc
->owner
->extra_string
2525 && is_breakpoint (loc
->owner
)
2526 && loc
->pspace
->num
== bl
->pspace
->num
2527 && loc
->owner
->enable_state
== bp_enabled
2529 && !loc
->disabled_by_cond
)
2531 /* Add the command to the vector. This will be used later
2532 to send the commands to the target. */
2533 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2537 bl
->target_info
.persist
= 0;
2538 /* Maybe flag this location as persistent. */
2539 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2540 bl
->target_info
.persist
= 1;
2543 /* Return the kind of breakpoint on address *ADDR. Get the kind
2544 of breakpoint according to ADDR except single-step breakpoint.
2545 Get the kind of single-step breakpoint according to the current
2549 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2551 if (bl
->owner
->type
== bp_single_step
)
2553 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2554 struct regcache
*regcache
;
2556 regcache
= get_thread_regcache (thr
);
2558 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2562 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2565 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2566 location. Any error messages are printed to TMP_ERROR_STREAM; and
2567 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2568 Returns 0 for success, 1 if the bp_location type is not supported or
2571 NOTE drow/2003-09-09: This routine could be broken down to an
2572 object-style method for each breakpoint or catchpoint type. */
2574 insert_bp_location (struct bp_location
*bl
,
2575 struct ui_file
*tmp_error_stream
,
2576 int *disabled_breaks
,
2577 int *hw_breakpoint_error
,
2578 int *hw_bp_error_explained_already
)
2580 gdb_exception bp_excpt
;
2582 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2585 /* Note we don't initialize bl->target_info, as that wipes out
2586 the breakpoint location's shadow_contents if the breakpoint
2587 is still inserted at that location. This in turn breaks
2588 target_read_memory which depends on these buffers when
2589 a memory read is requested at the breakpoint location:
2590 Once the target_info has been wiped, we fail to see that
2591 we have a breakpoint inserted at that address and thus
2592 read the breakpoint instead of returning the data saved in
2593 the breakpoint location's shadow contents. */
2594 bl
->target_info
.reqstd_address
= bl
->address
;
2595 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2596 bl
->target_info
.length
= bl
->length
;
2598 /* When working with target-side conditions, we must pass all the conditions
2599 for the same breakpoint address down to the target since GDB will not
2600 insert those locations. With a list of breakpoint conditions, the target
2601 can decide when to stop and notify GDB. */
2603 if (is_breakpoint (bl
->owner
))
2605 build_target_condition_list (bl
);
2606 build_target_command_list (bl
);
2607 /* Reset the modification marker. */
2608 bl
->needs_update
= 0;
2611 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2612 set at a read-only address, then a breakpoint location will have
2613 been changed to hardware breakpoint before we get here. If it is
2614 "off" however, error out before actually trying to insert the
2615 breakpoint, with a nicer error message. */
2616 if (bl
->loc_type
== bp_loc_software_breakpoint
2617 && !automatic_hardware_breakpoints
)
2619 mem_region
*mr
= lookup_mem_region (bl
->address
);
2621 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2623 fprintf_unfiltered (tmp_error_stream
,
2624 _("Cannot insert breakpoint %d.\n"
2625 "Cannot set software breakpoint "
2626 "at read-only address %s\n"),
2628 paddress (bl
->gdbarch
, bl
->address
));
2633 if (bl
->loc_type
== bp_loc_software_breakpoint
2634 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2636 /* First check to see if we have to handle an overlay. */
2637 if (overlay_debugging
== ovly_off
2638 || bl
->section
== NULL
2639 || !(section_is_overlay (bl
->section
)))
2641 /* No overlay handling: just set the breakpoint. */
2646 val
= bl
->owner
->ops
->insert_location (bl
);
2648 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2650 catch (gdb_exception
&e
)
2652 bp_excpt
= std::move (e
);
2657 /* This breakpoint is in an overlay section.
2658 Shall we set a breakpoint at the LMA? */
2659 if (!overlay_events_enabled
)
2661 /* Yes -- overlay event support is not active,
2662 so we must try to set a breakpoint at the LMA.
2663 This will not work for a hardware breakpoint. */
2664 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2665 warning (_("hardware breakpoint %d not supported in overlay!"),
2669 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2671 /* Set a software (trap) breakpoint at the LMA. */
2672 bl
->overlay_target_info
= bl
->target_info
;
2673 bl
->overlay_target_info
.reqstd_address
= addr
;
2675 /* No overlay handling: just set the breakpoint. */
2680 bl
->overlay_target_info
.kind
2681 = breakpoint_kind (bl
, &addr
);
2682 bl
->overlay_target_info
.placed_address
= addr
;
2683 val
= target_insert_breakpoint (bl
->gdbarch
,
2684 &bl
->overlay_target_info
);
2687 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2689 catch (gdb_exception
&e
)
2691 bp_excpt
= std::move (e
);
2694 if (bp_excpt
.reason
!= 0)
2695 fprintf_unfiltered (tmp_error_stream
,
2696 "Overlay breakpoint %d "
2697 "failed: in ROM?\n",
2701 /* Shall we set a breakpoint at the VMA? */
2702 if (section_is_mapped (bl
->section
))
2704 /* Yes. This overlay section is mapped into memory. */
2709 val
= bl
->owner
->ops
->insert_location (bl
);
2711 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2713 catch (gdb_exception
&e
)
2715 bp_excpt
= std::move (e
);
2720 /* No. This breakpoint will not be inserted.
2721 No error, but do not mark the bp as 'inserted'. */
2726 if (bp_excpt
.reason
!= 0)
2728 /* Can't set the breakpoint. */
2730 /* In some cases, we might not be able to insert a
2731 breakpoint in a shared library that has already been
2732 removed, but we have not yet processed the shlib unload
2733 event. Unfortunately, some targets that implement
2734 breakpoint insertion themselves can't tell why the
2735 breakpoint insertion failed (e.g., the remote target
2736 doesn't define error codes), so we must treat generic
2737 errors as memory errors. */
2738 if (bp_excpt
.reason
== RETURN_ERROR
2739 && (bp_excpt
.error
== GENERIC_ERROR
2740 || bp_excpt
.error
== MEMORY_ERROR
)
2741 && bl
->loc_type
== bp_loc_software_breakpoint
2742 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2743 || shared_objfile_contains_address_p (bl
->pspace
,
2746 /* See also: disable_breakpoints_in_shlibs. */
2747 bl
->shlib_disabled
= 1;
2748 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2749 if (!*disabled_breaks
)
2751 fprintf_unfiltered (tmp_error_stream
,
2752 "Cannot insert breakpoint %d.\n",
2754 fprintf_unfiltered (tmp_error_stream
,
2755 "Temporarily disabling shared "
2756 "library breakpoints:\n");
2758 *disabled_breaks
= 1;
2759 fprintf_unfiltered (tmp_error_stream
,
2760 "breakpoint #%d\n", bl
->owner
->number
);
2765 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2767 *hw_breakpoint_error
= 1;
2768 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2769 fprintf_unfiltered (tmp_error_stream
,
2770 "Cannot insert hardware breakpoint %d%s",
2772 bp_excpt
.message
? ":" : ".\n");
2773 if (bp_excpt
.message
!= NULL
)
2774 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2779 if (bp_excpt
.message
== NULL
)
2782 = memory_error_message (TARGET_XFER_E_IO
,
2783 bl
->gdbarch
, bl
->address
);
2785 fprintf_unfiltered (tmp_error_stream
,
2786 "Cannot insert breakpoint %d.\n"
2788 bl
->owner
->number
, message
.c_str ());
2792 fprintf_unfiltered (tmp_error_stream
,
2793 "Cannot insert breakpoint %d: %s\n",
2808 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2809 /* NOTE drow/2003-09-08: This state only exists for removing
2810 watchpoints. It's not clear that it's necessary... */
2811 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2815 gdb_assert (bl
->owner
->ops
!= NULL
2816 && bl
->owner
->ops
->insert_location
!= NULL
);
2818 val
= bl
->owner
->ops
->insert_location (bl
);
2820 /* If trying to set a read-watchpoint, and it turns out it's not
2821 supported, try emulating one with an access watchpoint. */
2822 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2824 /* But don't try to insert it, if there's already another
2825 hw_access location that would be considered a duplicate
2827 for (bp_location
*loc
: all_bp_locations ())
2829 && loc
->watchpoint_type
== hw_access
2830 && watchpoint_locations_match (bl
, loc
))
2834 bl
->target_info
= loc
->target_info
;
2835 bl
->watchpoint_type
= hw_access
;
2842 bl
->watchpoint_type
= hw_access
;
2843 val
= bl
->owner
->ops
->insert_location (bl
);
2846 /* Back to the original value. */
2847 bl
->watchpoint_type
= hw_read
;
2851 bl
->inserted
= (val
== 0);
2854 else if (bl
->owner
->type
== bp_catchpoint
)
2858 gdb_assert (bl
->owner
->ops
!= NULL
2859 && bl
->owner
->ops
->insert_location
!= NULL
);
2861 val
= bl
->owner
->ops
->insert_location (bl
);
2864 bl
->owner
->enable_state
= bp_disabled
;
2868 Error inserting catchpoint %d: Your system does not support this type\n\
2869 of catchpoint."), bl
->owner
->number
);
2871 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2874 bl
->inserted
= (val
== 0);
2876 /* We've already printed an error message if there was a problem
2877 inserting this catchpoint, and we've disabled the catchpoint,
2878 so just return success. */
2885 /* This function is called when program space PSPACE is about to be
2886 deleted. It takes care of updating breakpoints to not reference
2890 breakpoint_program_space_exit (struct program_space
*pspace
)
2892 /* Remove any breakpoint that was set through this program space. */
2893 for (breakpoint
*b
: all_breakpoints_safe ())
2894 if (b
->pspace
== pspace
)
2895 delete_breakpoint (b
);
2897 /* Breakpoints set through other program spaces could have locations
2898 bound to PSPACE as well. Remove those. */
2899 for (bp_location
*loc
: all_bp_locations ())
2901 struct bp_location
*tmp
;
2903 if (loc
->pspace
== pspace
)
2905 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2906 if (loc
->owner
->loc
== loc
)
2907 loc
->owner
->loc
= loc
->next
;
2909 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2910 if (tmp
->next
== loc
)
2912 tmp
->next
= loc
->next
;
2918 /* Now update the global location list to permanently delete the
2919 removed locations above. */
2920 update_global_location_list (UGLL_DONT_INSERT
);
2923 /* Make sure all breakpoints are inserted in inferior.
2924 Throws exception on any error.
2925 A breakpoint that is already inserted won't be inserted
2926 again, so calling this function twice is safe. */
2928 insert_breakpoints (void)
2930 for (breakpoint
*bpt
: all_breakpoints ())
2931 if (is_hardware_watchpoint (bpt
))
2933 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2935 update_watchpoint (w
, 0 /* don't reparse. */);
2938 /* Updating watchpoints creates new locations, so update the global
2939 location list. Explicitly tell ugll to insert locations and
2940 ignore breakpoints_always_inserted_mode. Also,
2941 update_global_location_list tries to "upgrade" software
2942 breakpoints to hardware breakpoints to handle "set breakpoint
2943 auto-hw", so we need to call it even if we don't have new
2945 update_global_location_list (UGLL_INSERT
);
2948 /* Invoke CALLBACK for each of bp_location. */
2951 iterate_over_bp_locations (gdb::function_view
<void (bp_location
*)> callback
)
2953 for (bp_location
*loc
: all_bp_locations ())
2957 /* This is used when we need to synch breakpoint conditions between GDB and the
2958 target. It is the case with deleting and disabling of breakpoints when using
2959 always-inserted mode. */
2962 update_inserted_breakpoint_locations (void)
2966 int disabled_breaks
= 0;
2967 int hw_breakpoint_error
= 0;
2968 int hw_bp_details_reported
= 0;
2970 string_file tmp_error_stream
;
2972 /* Explicitly mark the warning -- this will only be printed if
2973 there was an error. */
2974 tmp_error_stream
.puts ("Warning:\n");
2976 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2978 for (bp_location
*bl
: all_bp_locations ())
2980 /* We only want to update software breakpoints and hardware
2982 if (!is_breakpoint (bl
->owner
))
2985 /* We only want to update locations that are already inserted
2986 and need updating. This is to avoid unwanted insertion during
2987 deletion of breakpoints. */
2988 if (!bl
->inserted
|| !bl
->needs_update
)
2991 switch_to_program_space_and_thread (bl
->pspace
);
2993 /* For targets that support global breakpoints, there's no need
2994 to select an inferior to insert breakpoint to. In fact, even
2995 if we aren't attached to any process yet, we should still
2996 insert breakpoints. */
2997 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2998 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3001 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3002 &hw_breakpoint_error
, &hw_bp_details_reported
);
3009 target_terminal::ours_for_output ();
3010 error_stream (tmp_error_stream
);
3014 /* Used when starting or continuing the program. */
3017 insert_breakpoint_locations (void)
3021 int disabled_breaks
= 0;
3022 int hw_breakpoint_error
= 0;
3023 int hw_bp_error_explained_already
= 0;
3025 string_file tmp_error_stream
;
3027 /* Explicitly mark the warning -- this will only be printed if
3028 there was an error. */
3029 tmp_error_stream
.puts ("Warning:\n");
3031 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3033 for (bp_location
*bl
: all_bp_locations ())
3035 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3038 /* There is no point inserting thread-specific breakpoints if
3039 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3040 has BL->OWNER always non-NULL. */
3041 if (bl
->owner
->thread
!= -1
3042 && !valid_global_thread_id (bl
->owner
->thread
))
3045 switch_to_program_space_and_thread (bl
->pspace
);
3047 /* For targets that support global breakpoints, there's no need
3048 to select an inferior to insert breakpoint to. In fact, even
3049 if we aren't attached to any process yet, we should still
3050 insert breakpoints. */
3051 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3052 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3055 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3056 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3061 /* If we failed to insert all locations of a watchpoint, remove
3062 them, as half-inserted watchpoint is of limited use. */
3063 for (breakpoint
*bpt
: all_breakpoints ())
3065 int some_failed
= 0;
3067 if (!is_hardware_watchpoint (bpt
))
3070 if (!breakpoint_enabled (bpt
))
3073 if (bpt
->disposition
== disp_del_at_next_stop
)
3076 for (bp_location
*loc
: bpt
->locations ())
3077 if (!loc
->inserted
&& should_be_inserted (loc
))
3085 for (bp_location
*loc
: bpt
->locations ())
3087 remove_breakpoint (loc
);
3089 hw_breakpoint_error
= 1;
3090 tmp_error_stream
.printf ("Could not insert "
3091 "hardware watchpoint %d.\n",
3099 /* If a hardware breakpoint or watchpoint was inserted, add a
3100 message about possibly exhausted resources. */
3101 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3103 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3104 You may have requested too many hardware breakpoints/watchpoints.\n");
3106 target_terminal::ours_for_output ();
3107 error_stream (tmp_error_stream
);
3111 /* Used when the program stops.
3112 Returns zero if successful, or non-zero if there was a problem
3113 removing a breakpoint location. */
3116 remove_breakpoints (void)
3120 for (bp_location
*bl
: all_bp_locations ())
3122 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3123 val
|= remove_breakpoint (bl
);
3128 /* When a thread exits, remove breakpoints that are related to
3132 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3134 for (breakpoint
*b
: all_breakpoints_safe ())
3136 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3138 b
->disposition
= disp_del_at_next_stop
;
3140 printf_filtered (_("\
3141 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3142 b
->number
, print_thread_id (tp
));
3144 /* Hide it from the user. */
3150 /* See breakpoint.h. */
3153 remove_breakpoints_inf (inferior
*inf
)
3157 for (bp_location
*bl
: all_bp_locations ())
3159 if (bl
->pspace
!= inf
->pspace
)
3162 if (bl
->inserted
&& !bl
->target_info
.persist
)
3164 val
= remove_breakpoint (bl
);
3171 static int internal_breakpoint_number
= -1;
3173 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3174 If INTERNAL is non-zero, the breakpoint number will be populated
3175 from internal_breakpoint_number and that variable decremented.
3176 Otherwise the breakpoint number will be populated from
3177 breakpoint_count and that value incremented. Internal breakpoints
3178 do not set the internal var bpnum. */
3180 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3183 b
->number
= internal_breakpoint_number
--;
3186 set_breakpoint_count (breakpoint_count
+ 1);
3187 b
->number
= breakpoint_count
;
3191 static struct breakpoint
*
3192 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3193 CORE_ADDR address
, enum bptype type
,
3194 const struct breakpoint_ops
*ops
)
3196 symtab_and_line sal
;
3198 sal
.section
= find_pc_overlay (sal
.pc
);
3199 sal
.pspace
= current_program_space
;
3201 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3202 b
->number
= internal_breakpoint_number
--;
3203 b
->disposition
= disp_donttouch
;
3208 static const char *const longjmp_names
[] =
3210 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3212 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3214 /* Per-objfile data private to breakpoint.c. */
3215 struct breakpoint_objfile_data
3217 /* Minimal symbol for "_ovly_debug_event" (if any). */
3218 struct bound_minimal_symbol overlay_msym
{};
3220 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3221 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3223 /* True if we have looked for longjmp probes. */
3224 int longjmp_searched
= 0;
3226 /* SystemTap probe points for longjmp (if any). These are non-owning
3228 std::vector
<probe
*> longjmp_probes
;
3230 /* Minimal symbol for "std::terminate()" (if any). */
3231 struct bound_minimal_symbol terminate_msym
{};
3233 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3234 struct bound_minimal_symbol exception_msym
{};
3236 /* True if we have looked for exception probes. */
3237 int exception_searched
= 0;
3239 /* SystemTap probe points for unwinding (if any). These are non-owning
3241 std::vector
<probe
*> exception_probes
;
3244 static const struct objfile_key
<breakpoint_objfile_data
>
3245 breakpoint_objfile_key
;
3247 /* Minimal symbol not found sentinel. */
3248 static struct minimal_symbol msym_not_found
;
3250 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3253 msym_not_found_p (const struct minimal_symbol
*msym
)
3255 return msym
== &msym_not_found
;
3258 /* Return per-objfile data needed by breakpoint.c.
3259 Allocate the data if necessary. */
3261 static struct breakpoint_objfile_data
*
3262 get_breakpoint_objfile_data (struct objfile
*objfile
)
3264 struct breakpoint_objfile_data
*bp_objfile_data
;
3266 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3267 if (bp_objfile_data
== NULL
)
3268 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3269 return bp_objfile_data
;
3273 create_overlay_event_breakpoint (void)
3275 const char *const func_name
= "_ovly_debug_event";
3277 for (objfile
*objfile
: current_program_space
->objfiles ())
3279 struct breakpoint
*b
;
3280 struct breakpoint_objfile_data
*bp_objfile_data
;
3282 struct explicit_location explicit_loc
;
3284 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3286 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3289 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3291 struct bound_minimal_symbol m
;
3293 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3294 if (m
.minsym
== NULL
)
3296 /* Avoid future lookups in this objfile. */
3297 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3300 bp_objfile_data
->overlay_msym
= m
;
3303 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3304 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3306 &internal_breakpoint_ops
);
3307 initialize_explicit_location (&explicit_loc
);
3308 explicit_loc
.function_name
= ASTRDUP (func_name
);
3309 b
->location
= new_explicit_location (&explicit_loc
);
3311 if (overlay_debugging
== ovly_auto
)
3313 b
->enable_state
= bp_enabled
;
3314 overlay_events_enabled
= 1;
3318 b
->enable_state
= bp_disabled
;
3319 overlay_events_enabled
= 0;
3324 /* Install a master longjmp breakpoint for OBJFILE using a probe. Return
3325 true if a breakpoint was installed. */
3328 create_longjmp_master_breakpoint_probe (objfile
*objfile
)
3330 struct gdbarch
*gdbarch
= objfile
->arch ();
3331 struct breakpoint_objfile_data
*bp_objfile_data
3332 = get_breakpoint_objfile_data (objfile
);
3334 if (!bp_objfile_data
->longjmp_searched
)
3336 std::vector
<probe
*> ret
3337 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3341 /* We are only interested in checking one element. */
3344 if (!p
->can_evaluate_arguments ())
3346 /* We cannot use the probe interface here,
3347 because it does not know how to evaluate
3352 bp_objfile_data
->longjmp_probes
= ret
;
3353 bp_objfile_data
->longjmp_searched
= 1;
3356 if (bp_objfile_data
->longjmp_probes
.empty ())
3359 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3361 struct breakpoint
*b
;
3363 b
= create_internal_breakpoint (gdbarch
,
3364 p
->get_relocated_address (objfile
),
3366 &internal_breakpoint_ops
);
3367 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3368 b
->enable_state
= bp_disabled
;
3374 /* Install master longjmp breakpoints for OBJFILE using longjmp_names.
3375 Return true if at least one breakpoint was installed. */
3378 create_longjmp_master_breakpoint_names (objfile
*objfile
)
3380 struct gdbarch
*gdbarch
= objfile
->arch ();
3381 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3384 struct breakpoint_objfile_data
*bp_objfile_data
3385 = get_breakpoint_objfile_data (objfile
);
3386 unsigned int installed_bp
= 0;
3388 for (int i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3390 struct breakpoint
*b
;
3391 const char *func_name
;
3393 struct explicit_location explicit_loc
;
3395 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3398 func_name
= longjmp_names
[i
];
3399 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3401 struct bound_minimal_symbol m
;
3403 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3404 if (m
.minsym
== NULL
)
3406 /* Prevent future lookups in this objfile. */
3407 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3410 bp_objfile_data
->longjmp_msym
[i
] = m
;
3413 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3414 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3415 &internal_breakpoint_ops
);
3416 initialize_explicit_location (&explicit_loc
);
3417 explicit_loc
.function_name
= ASTRDUP (func_name
);
3418 b
->location
= new_explicit_location (&explicit_loc
);
3419 b
->enable_state
= bp_disabled
;
3423 return installed_bp
> 0;
3426 /* Create a master longjmp breakpoint. */
3429 create_longjmp_master_breakpoint (void)
3431 scoped_restore_current_program_space restore_pspace
;
3433 for (struct program_space
*pspace
: program_spaces
)
3435 set_current_program_space (pspace
);
3437 for (objfile
*obj
: current_program_space
->objfiles ())
3439 /* Skip separate debug object, it's handled in the loop below. */
3440 if (obj
->separate_debug_objfile_backlink
!= nullptr)
3443 /* Try a probe kind breakpoint on main objfile. */
3444 if (create_longjmp_master_breakpoint_probe (obj
))
3447 /* Try longjmp_names kind breakpoints on main and separate_debug
3449 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3450 if (create_longjmp_master_breakpoint_names (debug_objfile
))
3456 /* Create a master std::terminate breakpoint. */
3458 create_std_terminate_master_breakpoint (void)
3460 const char *const func_name
= "std::terminate()";
3462 scoped_restore_current_program_space restore_pspace
;
3464 for (struct program_space
*pspace
: program_spaces
)
3468 set_current_program_space (pspace
);
3470 for (objfile
*objfile
: current_program_space
->objfiles ())
3472 struct breakpoint
*b
;
3473 struct breakpoint_objfile_data
*bp_objfile_data
;
3474 struct explicit_location explicit_loc
;
3476 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3478 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3481 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3483 struct bound_minimal_symbol m
;
3485 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3486 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3487 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3489 /* Prevent future lookups in this objfile. */
3490 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3493 bp_objfile_data
->terminate_msym
= m
;
3496 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3497 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3498 bp_std_terminate_master
,
3499 &internal_breakpoint_ops
);
3500 initialize_explicit_location (&explicit_loc
);
3501 explicit_loc
.function_name
= ASTRDUP (func_name
);
3502 b
->location
= new_explicit_location (&explicit_loc
);
3503 b
->enable_state
= bp_disabled
;
3508 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a
3509 probe. Return true if a breakpoint was installed. */
3512 create_exception_master_breakpoint_probe (objfile
*objfile
)
3514 struct breakpoint
*b
;
3515 struct gdbarch
*gdbarch
;
3516 struct breakpoint_objfile_data
*bp_objfile_data
;
3518 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3520 /* We prefer the SystemTap probe point if it exists. */
3521 if (!bp_objfile_data
->exception_searched
)
3523 std::vector
<probe
*> ret
3524 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3528 /* We are only interested in checking one element. */
3531 if (!p
->can_evaluate_arguments ())
3533 /* We cannot use the probe interface here, because it does
3534 not know how to evaluate arguments. */
3538 bp_objfile_data
->exception_probes
= ret
;
3539 bp_objfile_data
->exception_searched
= 1;
3542 if (bp_objfile_data
->exception_probes
.empty ())
3545 gdbarch
= objfile
->arch ();
3547 for (probe
*p
: bp_objfile_data
->exception_probes
)
3549 b
= create_internal_breakpoint (gdbarch
,
3550 p
->get_relocated_address (objfile
),
3551 bp_exception_master
,
3552 &internal_breakpoint_ops
);
3553 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3554 b
->enable_state
= bp_disabled
;
3560 /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using
3561 _Unwind_DebugHook. Return true if a breakpoint was installed. */
3564 create_exception_master_breakpoint_hook (objfile
*objfile
)
3566 const char *const func_name
= "_Unwind_DebugHook";
3567 struct breakpoint
*b
;
3568 struct gdbarch
*gdbarch
;
3569 struct breakpoint_objfile_data
*bp_objfile_data
;
3571 struct explicit_location explicit_loc
;
3573 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3575 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3578 gdbarch
= objfile
->arch ();
3580 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3582 struct bound_minimal_symbol debug_hook
;
3584 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3585 if (debug_hook
.minsym
== NULL
)
3587 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3591 bp_objfile_data
->exception_msym
= debug_hook
;
3594 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3595 addr
= gdbarch_convert_from_func_ptr_addr
3596 (gdbarch
, addr
, current_inferior ()->top_target ());
3597 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3598 &internal_breakpoint_ops
);
3599 initialize_explicit_location (&explicit_loc
);
3600 explicit_loc
.function_name
= ASTRDUP (func_name
);
3601 b
->location
= new_explicit_location (&explicit_loc
);
3602 b
->enable_state
= bp_disabled
;
3607 /* Install a master breakpoint on the unwinder's debug hook. */
3610 create_exception_master_breakpoint (void)
3612 for (objfile
*obj
: current_program_space
->objfiles ())
3614 /* Skip separate debug object. */
3615 if (obj
->separate_debug_objfile_backlink
)
3618 /* Try a probe kind breakpoint. */
3619 if (create_exception_master_breakpoint_probe (obj
))
3622 /* Iterate over main and separate debug objects and try an
3623 _Unwind_DebugHook kind breakpoint. */
3624 for (objfile
*debug_objfile
: obj
->separate_debug_objfiles ())
3625 if (create_exception_master_breakpoint_hook (debug_objfile
))
3630 /* Does B have a location spec? */
3633 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3635 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3639 update_breakpoints_after_exec (void)
3641 /* We're about to delete breakpoints from GDB's lists. If the
3642 INSERTED flag is true, GDB will try to lift the breakpoints by
3643 writing the breakpoints' "shadow contents" back into memory. The
3644 "shadow contents" are NOT valid after an exec, so GDB should not
3645 do that. Instead, the target is responsible from marking
3646 breakpoints out as soon as it detects an exec. We don't do that
3647 here instead, because there may be other attempts to delete
3648 breakpoints after detecting an exec and before reaching here. */
3649 for (bp_location
*bploc
: all_bp_locations ())
3650 if (bploc
->pspace
== current_program_space
)
3651 gdb_assert (!bploc
->inserted
);
3653 for (breakpoint
*b
: all_breakpoints_safe ())
3655 if (b
->pspace
!= current_program_space
)
3658 /* Solib breakpoints must be explicitly reset after an exec(). */
3659 if (b
->type
== bp_shlib_event
)
3661 delete_breakpoint (b
);
3665 /* JIT breakpoints must be explicitly reset after an exec(). */
3666 if (b
->type
== bp_jit_event
)
3668 delete_breakpoint (b
);
3672 /* Thread event breakpoints must be set anew after an exec(),
3673 as must overlay event and longjmp master breakpoints. */
3674 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3675 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3676 || b
->type
== bp_exception_master
)
3678 delete_breakpoint (b
);
3682 /* Step-resume breakpoints are meaningless after an exec(). */
3683 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3685 delete_breakpoint (b
);
3689 /* Just like single-step breakpoints. */
3690 if (b
->type
== bp_single_step
)
3692 delete_breakpoint (b
);
3696 /* Longjmp and longjmp-resume breakpoints are also meaningless
3698 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3699 || b
->type
== bp_longjmp_call_dummy
3700 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3702 delete_breakpoint (b
);
3706 if (b
->type
== bp_catchpoint
)
3708 /* For now, none of the bp_catchpoint breakpoints need to
3709 do anything at this point. In the future, if some of
3710 the catchpoints need to something, we will need to add
3711 a new method, and call this method from here. */
3715 /* bp_finish is a special case. The only way we ought to be able
3716 to see one of these when an exec() has happened, is if the user
3717 caught a vfork, and then said "finish". Ordinarily a finish just
3718 carries them to the call-site of the current callee, by setting
3719 a temporary bp there and resuming. But in this case, the finish
3720 will carry them entirely through the vfork & exec.
3722 We don't want to allow a bp_finish to remain inserted now. But
3723 we can't safely delete it, 'cause finish_command has a handle to
3724 the bp on a bpstat, and will later want to delete it. There's a
3725 chance (and I've seen it happen) that if we delete the bp_finish
3726 here, that its storage will get reused by the time finish_command
3727 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3728 We really must allow finish_command to delete a bp_finish.
3730 In the absence of a general solution for the "how do we know
3731 it's safe to delete something others may have handles to?"
3732 problem, what we'll do here is just uninsert the bp_finish, and
3733 let finish_command delete it.
3735 (We know the bp_finish is "doomed" in the sense that it's
3736 momentary, and will be deleted as soon as finish_command sees
3737 the inferior stopped. So it doesn't matter that the bp's
3738 address is probably bogus in the new a.out, unlike e.g., the
3739 solib breakpoints.) */
3741 if (b
->type
== bp_finish
)
3746 /* Without a symbolic address, we have little hope of the
3747 pre-exec() address meaning the same thing in the post-exec()
3749 if (breakpoint_event_location_empty_p (b
))
3751 delete_breakpoint (b
);
3758 detach_breakpoints (ptid_t ptid
)
3761 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3762 struct inferior
*inf
= current_inferior ();
3764 if (ptid
.pid () == inferior_ptid
.pid ())
3765 error (_("Cannot detach breakpoints of inferior_ptid"));
3767 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3768 inferior_ptid
= ptid
;
3769 for (bp_location
*bl
: all_bp_locations ())
3771 if (bl
->pspace
!= inf
->pspace
)
3774 /* This function must physically remove breakpoints locations
3775 from the specified ptid, without modifying the breakpoint
3776 package's state. Locations of type bp_loc_other are only
3777 maintained at GDB side. So, there is no need to remove
3778 these bp_loc_other locations. Moreover, removing these
3779 would modify the breakpoint package's state. */
3780 if (bl
->loc_type
== bp_loc_other
)
3784 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3790 /* Remove the breakpoint location BL from the current address space.
3791 Note that this is used to detach breakpoints from a child fork.
3792 When we get here, the child isn't in the inferior list, and neither
3793 do we have objects to represent its address space --- we should
3794 *not* look at bl->pspace->aspace here. */
3797 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3801 /* BL is never in moribund_locations by our callers. */
3802 gdb_assert (bl
->owner
!= NULL
);
3804 /* The type of none suggests that owner is actually deleted.
3805 This should not ever happen. */
3806 gdb_assert (bl
->owner
->type
!= bp_none
);
3808 if (bl
->loc_type
== bp_loc_software_breakpoint
3809 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3811 /* "Normal" instruction breakpoint: either the standard
3812 trap-instruction bp (bp_breakpoint), or a
3813 bp_hardware_breakpoint. */
3815 /* First check to see if we have to handle an overlay. */
3816 if (overlay_debugging
== ovly_off
3817 || bl
->section
== NULL
3818 || !(section_is_overlay (bl
->section
)))
3820 /* No overlay handling: just remove the breakpoint. */
3822 /* If we're trying to uninsert a memory breakpoint that we
3823 know is set in a dynamic object that is marked
3824 shlib_disabled, then either the dynamic object was
3825 removed with "remove-symbol-file" or with
3826 "nosharedlibrary". In the former case, we don't know
3827 whether another dynamic object might have loaded over the
3828 breakpoint's address -- the user might well let us know
3829 about it next with add-symbol-file (the whole point of
3830 add-symbol-file is letting the user manually maintain a
3831 list of dynamically loaded objects). If we have the
3832 breakpoint's shadow memory, that is, this is a software
3833 breakpoint managed by GDB, check whether the breakpoint
3834 is still inserted in memory, to avoid overwriting wrong
3835 code with stale saved shadow contents. Note that HW
3836 breakpoints don't have shadow memory, as they're
3837 implemented using a mechanism that is not dependent on
3838 being able to modify the target's memory, and as such
3839 they should always be removed. */
3840 if (bl
->shlib_disabled
3841 && bl
->target_info
.shadow_len
!= 0
3842 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3845 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3849 /* This breakpoint is in an overlay section.
3850 Did we set a breakpoint at the LMA? */
3851 if (!overlay_events_enabled
)
3853 /* Yes -- overlay event support is not active, so we
3854 should have set a breakpoint at the LMA. Remove it.
3856 /* Ignore any failures: if the LMA is in ROM, we will
3857 have already warned when we failed to insert it. */
3858 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3859 target_remove_hw_breakpoint (bl
->gdbarch
,
3860 &bl
->overlay_target_info
);
3862 target_remove_breakpoint (bl
->gdbarch
,
3863 &bl
->overlay_target_info
,
3866 /* Did we set a breakpoint at the VMA?
3867 If so, we will have marked the breakpoint 'inserted'. */
3870 /* Yes -- remove it. Previously we did not bother to
3871 remove the breakpoint if the section had been
3872 unmapped, but let's not rely on that being safe. We
3873 don't know what the overlay manager might do. */
3875 /* However, we should remove *software* breakpoints only
3876 if the section is still mapped, or else we overwrite
3877 wrong code with the saved shadow contents. */
3878 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3879 || section_is_mapped (bl
->section
))
3880 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3886 /* No -- not inserted, so no need to remove. No error. */
3891 /* In some cases, we might not be able to remove a breakpoint in
3892 a shared library that has already been removed, but we have
3893 not yet processed the shlib unload event. Similarly for an
3894 unloaded add-symbol-file object - the user might not yet have
3895 had the chance to remove-symbol-file it. shlib_disabled will
3896 be set if the library/object has already been removed, but
3897 the breakpoint hasn't been uninserted yet, e.g., after
3898 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3899 always-inserted mode. */
3901 && (bl
->loc_type
== bp_loc_software_breakpoint
3902 && (bl
->shlib_disabled
3903 || solib_name_from_address (bl
->pspace
, bl
->address
)
3904 || shared_objfile_contains_address_p (bl
->pspace
,
3910 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3912 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3914 gdb_assert (bl
->owner
->ops
!= NULL
3915 && bl
->owner
->ops
->remove_location
!= NULL
);
3917 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3918 bl
->owner
->ops
->remove_location (bl
, reason
);
3920 /* Failure to remove any of the hardware watchpoints comes here. */
3921 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3922 warning (_("Could not remove hardware watchpoint %d."),
3925 else if (bl
->owner
->type
== bp_catchpoint
3926 && breakpoint_enabled (bl
->owner
)
3929 gdb_assert (bl
->owner
->ops
!= NULL
3930 && bl
->owner
->ops
->remove_location
!= NULL
);
3932 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3936 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3943 remove_breakpoint (struct bp_location
*bl
)
3945 /* BL is never in moribund_locations by our callers. */
3946 gdb_assert (bl
->owner
!= NULL
);
3948 /* The type of none suggests that owner is actually deleted.
3949 This should not ever happen. */
3950 gdb_assert (bl
->owner
->type
!= bp_none
);
3952 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3954 switch_to_program_space_and_thread (bl
->pspace
);
3956 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3959 /* Clear the "inserted" flag in all breakpoints. */
3962 mark_breakpoints_out (void)
3964 for (bp_location
*bl
: all_bp_locations ())
3965 if (bl
->pspace
== current_program_space
)
3969 /* Clear the "inserted" flag in all breakpoints and delete any
3970 breakpoints which should go away between runs of the program.
3972 Plus other such housekeeping that has to be done for breakpoints
3975 Note: this function gets called at the end of a run (by
3976 generic_mourn_inferior) and when a run begins (by
3977 init_wait_for_inferior). */
3982 breakpoint_init_inferior (enum inf_context context
)
3984 struct program_space
*pspace
= current_program_space
;
3986 /* If breakpoint locations are shared across processes, then there's
3988 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3991 mark_breakpoints_out ();
3993 for (breakpoint
*b
: all_breakpoints_safe ())
3995 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4001 case bp_longjmp_call_dummy
:
4003 /* If the call dummy breakpoint is at the entry point it will
4004 cause problems when the inferior is rerun, so we better get
4007 case bp_watchpoint_scope
:
4009 /* Also get rid of scope breakpoints. */
4011 case bp_shlib_event
:
4013 /* Also remove solib event breakpoints. Their addresses may
4014 have changed since the last time we ran the program.
4015 Actually we may now be debugging against different target;
4016 and so the solib backend that installed this breakpoint may
4017 not be used in by the target. E.g.,
4019 (gdb) file prog-linux
4020 (gdb) run # native linux target
4023 (gdb) file prog-win.exe
4024 (gdb) tar rem :9999 # remote Windows gdbserver.
4027 case bp_step_resume
:
4029 /* Also remove step-resume breakpoints. */
4031 case bp_single_step
:
4033 /* Also remove single-step breakpoints. */
4035 delete_breakpoint (b
);
4039 case bp_hardware_watchpoint
:
4040 case bp_read_watchpoint
:
4041 case bp_access_watchpoint
:
4043 struct watchpoint
*w
= (struct watchpoint
*) b
;
4045 /* Likewise for watchpoints on local expressions. */
4046 if (w
->exp_valid_block
!= NULL
)
4047 delete_breakpoint (b
);
4050 /* Get rid of existing locations, which are no longer
4051 valid. New ones will be created in
4052 update_watchpoint, when the inferior is restarted.
4053 The next update_global_location_list call will
4054 garbage collect them. */
4057 if (context
== inf_starting
)
4059 /* Reset val field to force reread of starting value in
4060 insert_breakpoints. */
4061 w
->val
.reset (nullptr);
4062 w
->val_valid
= false;
4072 /* Get rid of the moribund locations. */
4073 for (bp_location
*bl
: moribund_locations
)
4074 decref_bp_location (&bl
);
4075 moribund_locations
.clear ();
4078 /* These functions concern about actual breakpoints inserted in the
4079 target --- to e.g. check if we need to do decr_pc adjustment or if
4080 we need to hop over the bkpt --- so we check for address space
4081 match, not program space. */
4083 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4084 exists at PC. It returns ordinary_breakpoint_here if it's an
4085 ordinary breakpoint, or permanent_breakpoint_here if it's a
4086 permanent breakpoint.
4087 - When continuing from a location with an ordinary breakpoint, we
4088 actually single step once before calling insert_breakpoints.
4089 - When continuing from a location with a permanent breakpoint, we
4090 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4091 the target, to advance the PC past the breakpoint. */
4093 enum breakpoint_here
4094 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4096 int any_breakpoint_here
= 0;
4098 for (bp_location
*bl
: all_bp_locations ())
4100 if (bl
->loc_type
!= bp_loc_software_breakpoint
4101 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4104 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4105 if ((breakpoint_enabled (bl
->owner
)
4107 && breakpoint_location_address_match (bl
, aspace
, pc
))
4109 if (overlay_debugging
4110 && section_is_overlay (bl
->section
)
4111 && !section_is_mapped (bl
->section
))
4112 continue; /* unmapped overlay -- can't be a match */
4113 else if (bl
->permanent
)
4114 return permanent_breakpoint_here
;
4116 any_breakpoint_here
= 1;
4120 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4123 /* See breakpoint.h. */
4126 breakpoint_in_range_p (const address_space
*aspace
,
4127 CORE_ADDR addr
, ULONGEST len
)
4129 for (bp_location
*bl
: all_bp_locations ())
4131 if (bl
->loc_type
!= bp_loc_software_breakpoint
4132 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4135 if ((breakpoint_enabled (bl
->owner
)
4137 && breakpoint_location_address_range_overlap (bl
, aspace
,
4140 if (overlay_debugging
4141 && section_is_overlay (bl
->section
)
4142 && !section_is_mapped (bl
->section
))
4144 /* Unmapped overlay -- can't be a match. */
4155 /* Return true if there's a moribund breakpoint at PC. */
4158 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4160 for (bp_location
*loc
: moribund_locations
)
4161 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4167 /* Returns non-zero iff BL is inserted at PC, in address space
4171 bp_location_inserted_here_p (struct bp_location
*bl
,
4172 const address_space
*aspace
, CORE_ADDR pc
)
4175 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4178 if (overlay_debugging
4179 && section_is_overlay (bl
->section
)
4180 && !section_is_mapped (bl
->section
))
4181 return 0; /* unmapped overlay -- can't be a match */
4188 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4191 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4193 struct bp_location
**blp
, **blp_tmp
= NULL
;
4195 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4197 struct bp_location
*bl
= *blp
;
4199 if (bl
->loc_type
!= bp_loc_software_breakpoint
4200 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4203 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4209 /* This function returns non-zero iff there is a software breakpoint
4213 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4216 struct bp_location
**blp
, **blp_tmp
= NULL
;
4218 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4220 struct bp_location
*bl
= *blp
;
4222 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4225 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4232 /* See breakpoint.h. */
4235 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4238 struct bp_location
**blp
, **blp_tmp
= NULL
;
4240 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4242 struct bp_location
*bl
= *blp
;
4244 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4247 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4255 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4256 CORE_ADDR addr
, ULONGEST len
)
4258 for (breakpoint
*bpt
: all_breakpoints ())
4260 if (bpt
->type
!= bp_hardware_watchpoint
4261 && bpt
->type
!= bp_access_watchpoint
)
4264 if (!breakpoint_enabled (bpt
))
4267 for (bp_location
*loc
: bpt
->locations ())
4268 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4272 /* Check for intersection. */
4273 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4274 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4282 /* See breakpoint.h. */
4285 is_catchpoint (struct breakpoint
*b
)
4287 return (b
->type
== bp_catchpoint
);
4290 /* Clear a bpstat so that it says we are not at any breakpoint.
4291 Also free any storage that is part of a bpstat. */
4294 bpstat_clear (bpstat
*bsp
)
4311 bpstats::bpstats (const bpstats
&other
)
4313 bp_location_at (other
.bp_location_at
),
4314 breakpoint_at (other
.breakpoint_at
),
4315 commands (other
.commands
),
4316 print (other
.print
),
4318 print_it (other
.print_it
)
4320 if (other
.old_val
!= NULL
)
4321 old_val
= release_value (value_copy (other
.old_val
.get ()));
4324 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4325 is part of the bpstat is copied as well. */
4328 bpstat_copy (bpstat bs
)
4332 bpstat retval
= NULL
;
4337 for (; bs
!= NULL
; bs
= bs
->next
)
4339 tmp
= new bpstats (*bs
);
4342 /* This is the first thing in the chain. */
4352 /* Find the bpstat associated with this breakpoint. */
4355 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4360 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4362 if (bsp
->breakpoint_at
== breakpoint
)
4368 /* See breakpoint.h. */
4371 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4373 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4375 if (bsp
->breakpoint_at
== NULL
)
4377 /* A moribund location can never explain a signal other than
4379 if (sig
== GDB_SIGNAL_TRAP
)
4384 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4393 /* Put in *NUM the breakpoint number of the first breakpoint we are
4394 stopped at. *BSP upon return is a bpstat which points to the
4395 remaining breakpoints stopped at (but which is not guaranteed to be
4396 good for anything but further calls to bpstat_num).
4398 Return 0 if passed a bpstat which does not indicate any breakpoints.
4399 Return -1 if stopped at a breakpoint that has been deleted since
4401 Return 1 otherwise. */
4404 bpstat_num (bpstat
*bsp
, int *num
)
4406 struct breakpoint
*b
;
4409 return 0; /* No more breakpoint values */
4411 /* We assume we'll never have several bpstats that correspond to a
4412 single breakpoint -- otherwise, this function might return the
4413 same number more than once and this will look ugly. */
4414 b
= (*bsp
)->breakpoint_at
;
4415 *bsp
= (*bsp
)->next
;
4417 return -1; /* breakpoint that's been deleted since */
4419 *num
= b
->number
; /* We have its number */
4423 /* See breakpoint.h. */
4426 bpstat_clear_actions (void)
4430 if (inferior_ptid
== null_ptid
)
4433 thread_info
*tp
= inferior_thread ();
4434 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4436 bs
->commands
= NULL
;
4437 bs
->old_val
.reset (nullptr);
4441 /* Called when a command is about to proceed the inferior. */
4444 breakpoint_about_to_proceed (void)
4446 if (inferior_ptid
!= null_ptid
)
4448 struct thread_info
*tp
= inferior_thread ();
4450 /* Allow inferior function calls in breakpoint commands to not
4451 interrupt the command list. When the call finishes
4452 successfully, the inferior will be standing at the same
4453 breakpoint as if nothing happened. */
4454 if (tp
->control
.in_infcall
)
4458 breakpoint_proceeded
= 1;
4461 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4462 or its equivalent. */
4465 command_line_is_silent (struct command_line
*cmd
)
4467 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4470 /* Execute all the commands associated with all the breakpoints at
4471 this location. Any of these commands could cause the process to
4472 proceed beyond this point, etc. We look out for such changes by
4473 checking the global "breakpoint_proceeded" after each command.
4475 Returns true if a breakpoint command resumed the inferior. In that
4476 case, it is the caller's responsibility to recall it again with the
4477 bpstat of the current thread. */
4480 bpstat_do_actions_1 (bpstat
*bsp
)
4485 /* Avoid endless recursion if a `source' command is contained
4487 if (executing_breakpoint_commands
)
4490 scoped_restore save_executing
4491 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4493 scoped_restore preventer
= prevent_dont_repeat ();
4495 /* This pointer will iterate over the list of bpstat's. */
4498 breakpoint_proceeded
= 0;
4499 for (; bs
!= NULL
; bs
= bs
->next
)
4501 struct command_line
*cmd
= NULL
;
4503 /* Take ownership of the BSP's command tree, if it has one.
4505 The command tree could legitimately contain commands like
4506 'step' and 'next', which call clear_proceed_status, which
4507 frees stop_bpstat's command tree. To make sure this doesn't
4508 free the tree we're executing out from under us, we need to
4509 take ownership of the tree ourselves. Since a given bpstat's
4510 commands are only executed once, we don't need to copy it; we
4511 can clear the pointer in the bpstat, and make sure we free
4512 the tree when we're done. */
4513 counted_command_line ccmd
= bs
->commands
;
4514 bs
->commands
= NULL
;
4517 if (command_line_is_silent (cmd
))
4519 /* The action has been already done by bpstat_stop_status. */
4525 execute_control_command (cmd
);
4527 if (breakpoint_proceeded
)
4533 if (breakpoint_proceeded
)
4535 if (current_ui
->async
)
4536 /* If we are in async mode, then the target might be still
4537 running, not stopped at any breakpoint, so nothing for
4538 us to do here -- just return to the event loop. */
4541 /* In sync mode, when execute_control_command returns
4542 we're already standing on the next breakpoint.
4543 Breakpoint commands for that stop were not run, since
4544 execute_command does not run breakpoint commands --
4545 only command_line_handler does, but that one is not
4546 involved in execution of breakpoint commands. So, we
4547 can now execute breakpoint commands. It should be
4548 noted that making execute_command do bpstat actions is
4549 not an option -- in this case we'll have recursive
4550 invocation of bpstat for each breakpoint with a
4551 command, and can easily blow up GDB stack. Instead, we
4552 return true, which will trigger the caller to recall us
4553 with the new stop_bpstat. */
4561 /* Helper for bpstat_do_actions. Get the current thread, if there's
4562 one, is alive and has execution. Return NULL otherwise. */
4564 static thread_info
*
4565 get_bpstat_thread ()
4567 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4570 thread_info
*tp
= inferior_thread ();
4571 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4577 bpstat_do_actions (void)
4579 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4582 /* Do any commands attached to breakpoint we are stopped at. */
4583 while ((tp
= get_bpstat_thread ()) != NULL
)
4585 /* Since in sync mode, bpstat_do_actions may resume the
4586 inferior, and only return when it is stopped at the next
4587 breakpoint, we keep doing breakpoint actions until it returns
4588 false to indicate the inferior was not resumed. */
4589 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4593 cleanup_if_error
.release ();
4596 /* Print out the (old or new) value associated with a watchpoint. */
4599 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4602 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4605 struct value_print_options opts
;
4606 get_user_print_options (&opts
);
4607 value_print (val
, stream
, &opts
);
4611 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4612 debugging multiple threads. */
4615 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4617 if (uiout
->is_mi_like_p ())
4622 if (show_thread_that_caused_stop ())
4625 struct thread_info
*thr
= inferior_thread ();
4627 uiout
->text ("Thread ");
4628 uiout
->field_string ("thread-id", print_thread_id (thr
));
4630 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4633 uiout
->text (" \"");
4634 uiout
->field_string ("name", name
);
4638 uiout
->text (" hit ");
4642 /* Generic routine for printing messages indicating why we
4643 stopped. The behavior of this function depends on the value
4644 'print_it' in the bpstat structure. Under some circumstances we
4645 may decide not to print anything here and delegate the task to
4648 static enum print_stop_action
4649 print_bp_stop_message (bpstat bs
)
4651 switch (bs
->print_it
)
4654 /* Nothing should be printed for this bpstat entry. */
4655 return PRINT_UNKNOWN
;
4659 /* We still want to print the frame, but we already printed the
4660 relevant messages. */
4661 return PRINT_SRC_AND_LOC
;
4664 case print_it_normal
:
4666 struct breakpoint
*b
= bs
->breakpoint_at
;
4668 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4669 which has since been deleted. */
4671 return PRINT_UNKNOWN
;
4673 /* Normal case. Call the breakpoint's print_it method. */
4674 return b
->ops
->print_it (bs
);
4679 internal_error (__FILE__
, __LINE__
,
4680 _("print_bp_stop_message: unrecognized enum value"));
4685 /* A helper function that prints a shared library stopped event. */
4688 print_solib_event (int is_catchpoint
)
4690 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4691 bool any_added
= !current_program_space
->added_solibs
.empty ();
4695 if (any_added
|| any_deleted
)
4696 current_uiout
->text (_("Stopped due to shared library event:\n"));
4698 current_uiout
->text (_("Stopped due to shared library event (no "
4699 "libraries added or removed)\n"));
4702 if (current_uiout
->is_mi_like_p ())
4703 current_uiout
->field_string ("reason",
4704 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4708 current_uiout
->text (_(" Inferior unloaded "));
4709 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4710 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4712 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4715 current_uiout
->text (" ");
4716 current_uiout
->field_string ("library", name
);
4717 current_uiout
->text ("\n");
4723 current_uiout
->text (_(" Inferior loaded "));
4724 ui_out_emit_list
list_emitter (current_uiout
, "added");
4726 for (so_list
*iter
: current_program_space
->added_solibs
)
4729 current_uiout
->text (" ");
4731 current_uiout
->field_string ("library", iter
->so_name
);
4732 current_uiout
->text ("\n");
4737 /* Print a message indicating what happened. This is called from
4738 normal_stop(). The input to this routine is the head of the bpstat
4739 list - a list of the eventpoints that caused this stop. KIND is
4740 the target_waitkind for the stopping event. This
4741 routine calls the generic print routine for printing a message
4742 about reasons for stopping. This will print (for example) the
4743 "Breakpoint n," part of the output. The return value of this
4746 PRINT_UNKNOWN: Means we printed nothing.
4747 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4748 code to print the location. An example is
4749 "Breakpoint 1, " which should be followed by
4751 PRINT_SRC_ONLY: Means we printed something, but there is no need
4752 to also print the location part of the message.
4753 An example is the catch/throw messages, which
4754 don't require a location appended to the end.
4755 PRINT_NOTHING: We have done some printing and we don't need any
4756 further info to be printed. */
4758 enum print_stop_action
4759 bpstat_print (bpstat bs
, int kind
)
4761 enum print_stop_action val
;
4763 /* Maybe another breakpoint in the chain caused us to stop.
4764 (Currently all watchpoints go on the bpstat whether hit or not.
4765 That probably could (should) be changed, provided care is taken
4766 with respect to bpstat_explains_signal). */
4767 for (; bs
; bs
= bs
->next
)
4769 val
= print_bp_stop_message (bs
);
4770 if (val
== PRINT_SRC_ONLY
4771 || val
== PRINT_SRC_AND_LOC
4772 || val
== PRINT_NOTHING
)
4776 /* If we had hit a shared library event breakpoint,
4777 print_bp_stop_message would print out this message. If we hit an
4778 OS-level shared library event, do the same thing. */
4779 if (kind
== TARGET_WAITKIND_LOADED
)
4781 print_solib_event (0);
4782 return PRINT_NOTHING
;
4785 /* We reached the end of the chain, or we got a null BS to start
4786 with and nothing was printed. */
4787 return PRINT_UNKNOWN
;
4790 /* Evaluate the boolean expression EXP and return the result. */
4793 breakpoint_cond_eval (expression
*exp
)
4795 struct value
*mark
= value_mark ();
4796 bool res
= value_true (evaluate_expression (exp
));
4798 value_free_to_mark (mark
);
4802 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4804 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4806 bp_location_at (bp_location_ref_ptr::new_reference (bl
)),
4807 breakpoint_at (bl
->owner
),
4811 print_it (print_it_normal
)
4813 **bs_link_pointer
= this;
4814 *bs_link_pointer
= &next
;
4819 breakpoint_at (NULL
),
4823 print_it (print_it_normal
)
4827 /* The target has stopped with waitstatus WS. Check if any hardware
4828 watchpoints have triggered, according to the target. */
4831 watchpoints_triggered (struct target_waitstatus
*ws
)
4833 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4836 if (!stopped_by_watchpoint
)
4838 /* We were not stopped by a watchpoint. Mark all watchpoints
4839 as not triggered. */
4840 for (breakpoint
*b
: all_breakpoints ())
4841 if (is_hardware_watchpoint (b
))
4843 struct watchpoint
*w
= (struct watchpoint
*) b
;
4845 w
->watchpoint_triggered
= watch_triggered_no
;
4851 if (!target_stopped_data_address (current_inferior ()->top_target (), &addr
))
4853 /* We were stopped by a watchpoint, but we don't know where.
4854 Mark all watchpoints as unknown. */
4855 for (breakpoint
*b
: all_breakpoints ())
4856 if (is_hardware_watchpoint (b
))
4858 struct watchpoint
*w
= (struct watchpoint
*) b
;
4860 w
->watchpoint_triggered
= watch_triggered_unknown
;
4866 /* The target could report the data address. Mark watchpoints
4867 affected by this data address as triggered, and all others as not
4870 for (breakpoint
*b
: all_breakpoints ())
4871 if (is_hardware_watchpoint (b
))
4873 struct watchpoint
*w
= (struct watchpoint
*) b
;
4875 w
->watchpoint_triggered
= watch_triggered_no
;
4876 for (bp_location
*loc
: b
->locations ())
4878 if (is_masked_watchpoint (b
))
4880 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4881 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4883 if (newaddr
== start
)
4885 w
->watchpoint_triggered
= watch_triggered_yes
;
4889 /* Exact match not required. Within range is sufficient. */
4890 else if (target_watchpoint_addr_within_range
4891 (current_inferior ()->top_target (), addr
, loc
->address
,
4894 w
->watchpoint_triggered
= watch_triggered_yes
;
4903 /* Possible return values for watchpoint_check. */
4904 enum wp_check_result
4906 /* The watchpoint has been deleted. */
4909 /* The value has changed. */
4910 WP_VALUE_CHANGED
= 2,
4912 /* The value has not changed. */
4913 WP_VALUE_NOT_CHANGED
= 3,
4915 /* Ignore this watchpoint, no matter if the value changed or not. */
4919 #define BP_TEMPFLAG 1
4920 #define BP_HARDWAREFLAG 2
4922 /* Evaluate watchpoint condition expression and check if its value
4925 static wp_check_result
4926 watchpoint_check (bpstat bs
)
4928 struct watchpoint
*b
;
4929 struct frame_info
*fr
;
4930 int within_current_scope
;
4932 /* BS is built from an existing struct breakpoint. */
4933 gdb_assert (bs
->breakpoint_at
!= NULL
);
4934 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4936 /* If this is a local watchpoint, we only want to check if the
4937 watchpoint frame is in scope if the current thread is the thread
4938 that was used to create the watchpoint. */
4939 if (!watchpoint_in_thread_scope (b
))
4942 if (b
->exp_valid_block
== NULL
)
4943 within_current_scope
= 1;
4946 struct frame_info
*frame
= get_current_frame ();
4947 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4948 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4950 /* stack_frame_destroyed_p() returns a non-zero value if we're
4951 still in the function but the stack frame has already been
4952 invalidated. Since we can't rely on the values of local
4953 variables after the stack has been destroyed, we are treating
4954 the watchpoint in that state as `not changed' without further
4955 checking. Don't mark watchpoints as changed if the current
4956 frame is in an epilogue - even if they are in some other
4957 frame, our view of the stack is likely to be wrong and
4958 frame_find_by_id could error out. */
4959 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4962 fr
= frame_find_by_id (b
->watchpoint_frame
);
4963 within_current_scope
= (fr
!= NULL
);
4965 /* If we've gotten confused in the unwinder, we might have
4966 returned a frame that can't describe this variable. */
4967 if (within_current_scope
)
4969 struct symbol
*function
;
4971 function
= get_frame_function (fr
);
4972 if (function
== NULL
4973 || !contained_in (b
->exp_valid_block
,
4974 SYMBOL_BLOCK_VALUE (function
)))
4975 within_current_scope
= 0;
4978 if (within_current_scope
)
4979 /* If we end up stopping, the current frame will get selected
4980 in normal_stop. So this call to select_frame won't affect
4985 if (within_current_scope
)
4987 /* We use value_{,free_to_}mark because it could be a *long*
4988 time before we return to the command level and call
4989 free_all_values. We can't call free_all_values because we
4990 might be in the middle of evaluating a function call. */
4993 struct value
*new_val
;
4995 if (is_masked_watchpoint (b
))
4996 /* Since we don't know the exact trigger address (from
4997 stopped_data_address), just tell the user we've triggered
4998 a mask watchpoint. */
4999 return WP_VALUE_CHANGED
;
5001 mark
= value_mark ();
5002 fetch_subexp_value (b
->exp
.get (), b
->exp
->op
.get (), &new_val
,
5005 if (b
->val_bitsize
!= 0)
5006 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5008 /* We use value_equal_contents instead of value_equal because
5009 the latter coerces an array to a pointer, thus comparing just
5010 the address of the array instead of its contents. This is
5011 not what we want. */
5012 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5013 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
5016 bs
->old_val
= b
->val
;
5017 b
->val
= release_value (new_val
);
5018 b
->val_valid
= true;
5019 if (new_val
!= NULL
)
5020 value_free_to_mark (mark
);
5021 return WP_VALUE_CHANGED
;
5025 /* Nothing changed. */
5026 value_free_to_mark (mark
);
5027 return WP_VALUE_NOT_CHANGED
;
5032 /* This seems like the only logical thing to do because
5033 if we temporarily ignored the watchpoint, then when
5034 we reenter the block in which it is valid it contains
5035 garbage (in the case of a function, it may have two
5036 garbage values, one before and one after the prologue).
5037 So we can't even detect the first assignment to it and
5038 watch after that (since the garbage may or may not equal
5039 the first value assigned). */
5040 /* We print all the stop information in
5041 breakpoint_ops->print_it, but in this case, by the time we
5042 call breakpoint_ops->print_it this bp will be deleted
5043 already. So we have no choice but print the information
5046 SWITCH_THRU_ALL_UIS ()
5048 struct ui_out
*uiout
= current_uiout
;
5050 if (uiout
->is_mi_like_p ())
5052 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5053 uiout
->message ("\nWatchpoint %pF deleted because the program has "
5054 "left the block in\n"
5055 "which its expression is valid.\n",
5056 signed_field ("wpnum", b
->number
));
5059 /* Make sure the watchpoint's commands aren't executed. */
5061 watchpoint_del_at_next_stop (b
);
5067 /* Return true if it looks like target has stopped due to hitting
5068 breakpoint location BL. This function does not check if we should
5069 stop, only if BL explains the stop. */
5072 bpstat_check_location (const struct bp_location
*bl
,
5073 const address_space
*aspace
, CORE_ADDR bp_addr
,
5074 const struct target_waitstatus
*ws
)
5076 struct breakpoint
*b
= bl
->owner
;
5078 /* BL is from an existing breakpoint. */
5079 gdb_assert (b
!= NULL
);
5081 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5084 /* Determine if the watched values have actually changed, and we
5085 should stop. If not, set BS->stop to 0. */
5088 bpstat_check_watchpoint (bpstat bs
)
5090 const struct bp_location
*bl
;
5091 struct watchpoint
*b
;
5093 /* BS is built for existing struct breakpoint. */
5094 bl
= bs
->bp_location_at
.get ();
5095 gdb_assert (bl
!= NULL
);
5096 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5097 gdb_assert (b
!= NULL
);
5100 int must_check_value
= 0;
5102 if (b
->type
== bp_watchpoint
)
5103 /* For a software watchpoint, we must always check the
5105 must_check_value
= 1;
5106 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5107 /* We have a hardware watchpoint (read, write, or access)
5108 and the target earlier reported an address watched by
5110 must_check_value
= 1;
5111 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5112 && b
->type
== bp_hardware_watchpoint
)
5113 /* We were stopped by a hardware watchpoint, but the target could
5114 not report the data address. We must check the watchpoint's
5115 value. Access and read watchpoints are out of luck; without
5116 a data address, we can't figure it out. */
5117 must_check_value
= 1;
5119 if (must_check_value
)
5125 e
= watchpoint_check (bs
);
5127 catch (const gdb_exception
&ex
)
5129 exception_fprintf (gdb_stderr
, ex
,
5130 "Error evaluating expression "
5131 "for watchpoint %d\n",
5134 SWITCH_THRU_ALL_UIS ()
5136 printf_filtered (_("Watchpoint %d deleted.\n"),
5139 watchpoint_del_at_next_stop (b
);
5146 /* We've already printed what needs to be printed. */
5147 bs
->print_it
= print_it_done
;
5151 bs
->print_it
= print_it_noop
;
5154 case WP_VALUE_CHANGED
:
5155 if (b
->type
== bp_read_watchpoint
)
5157 /* There are two cases to consider here:
5159 1. We're watching the triggered memory for reads.
5160 In that case, trust the target, and always report
5161 the watchpoint hit to the user. Even though
5162 reads don't cause value changes, the value may
5163 have changed since the last time it was read, and
5164 since we're not trapping writes, we will not see
5165 those, and as such we should ignore our notion of
5168 2. We're watching the triggered memory for both
5169 reads and writes. There are two ways this may
5172 2.1. This is a target that can't break on data
5173 reads only, but can break on accesses (reads or
5174 writes), such as e.g., x86. We detect this case
5175 at the time we try to insert read watchpoints.
5177 2.2. Otherwise, the target supports read
5178 watchpoints, but, the user set an access or write
5179 watchpoint watching the same memory as this read
5182 If we're watching memory writes as well as reads,
5183 ignore watchpoint hits when we find that the
5184 value hasn't changed, as reads don't cause
5185 changes. This still gives false positives when
5186 the program writes the same value to memory as
5187 what there was already in memory (we will confuse
5188 it for a read), but it's much better than
5191 int other_write_watchpoint
= 0;
5193 if (bl
->watchpoint_type
== hw_read
)
5195 for (breakpoint
*other_b
: all_breakpoints ())
5196 if (other_b
->type
== bp_hardware_watchpoint
5197 || other_b
->type
== bp_access_watchpoint
)
5199 struct watchpoint
*other_w
=
5200 (struct watchpoint
*) other_b
;
5202 if (other_w
->watchpoint_triggered
5203 == watch_triggered_yes
)
5205 other_write_watchpoint
= 1;
5211 if (other_write_watchpoint
5212 || bl
->watchpoint_type
== hw_access
)
5214 /* We're watching the same memory for writes,
5215 and the value changed since the last time we
5216 updated it, so this trap must be for a write.
5218 bs
->print_it
= print_it_noop
;
5223 case WP_VALUE_NOT_CHANGED
:
5224 if (b
->type
== bp_hardware_watchpoint
5225 || b
->type
== bp_watchpoint
)
5227 /* Don't stop: write watchpoints shouldn't fire if
5228 the value hasn't changed. */
5229 bs
->print_it
= print_it_noop
;
5239 else /* must_check_value == 0 */
5241 /* This is a case where some watchpoint(s) triggered, but
5242 not at the address of this watchpoint, or else no
5243 watchpoint triggered after all. So don't print
5244 anything for this watchpoint. */
5245 bs
->print_it
= print_it_noop
;
5251 /* For breakpoints that are currently marked as telling gdb to stop,
5252 check conditions (condition proper, frame, thread and ignore count)
5253 of breakpoint referred to by BS. If we should not stop for this
5254 breakpoint, set BS->stop to 0. */
5257 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5259 const struct bp_location
*bl
;
5260 struct breakpoint
*b
;
5262 bool condition_result
= true;
5263 struct expression
*cond
;
5265 gdb_assert (bs
->stop
);
5267 /* BS is built for existing struct breakpoint. */
5268 bl
= bs
->bp_location_at
.get ();
5269 gdb_assert (bl
!= NULL
);
5270 b
= bs
->breakpoint_at
;
5271 gdb_assert (b
!= NULL
);
5273 /* Even if the target evaluated the condition on its end and notified GDB, we
5274 need to do so again since GDB does not know if we stopped due to a
5275 breakpoint or a single step breakpoint. */
5277 if (frame_id_p (b
->frame_id
)
5278 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5284 /* If this is a thread/task-specific breakpoint, don't waste cpu
5285 evaluating the condition if this isn't the specified
5287 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5288 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5294 /* Evaluate extension language breakpoints that have a "stop" method
5296 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5298 if (is_watchpoint (b
))
5300 struct watchpoint
*w
= (struct watchpoint
*) b
;
5302 cond
= w
->cond_exp
.get ();
5305 cond
= bl
->cond
.get ();
5307 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5309 int within_current_scope
= 1;
5310 struct watchpoint
* w
;
5312 /* We use value_mark and value_free_to_mark because it could
5313 be a long time before we return to the command level and
5314 call free_all_values. We can't call free_all_values
5315 because we might be in the middle of evaluating a
5317 struct value
*mark
= value_mark ();
5319 if (is_watchpoint (b
))
5320 w
= (struct watchpoint
*) b
;
5324 /* Need to select the frame, with all that implies so that
5325 the conditions will have the right context. Because we
5326 use the frame, we will not see an inlined function's
5327 variables when we arrive at a breakpoint at the start
5328 of the inlined function; the current frame will be the
5330 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5331 select_frame (get_current_frame ());
5334 struct frame_info
*frame
;
5336 /* For local watchpoint expressions, which particular
5337 instance of a local is being watched matters, so we
5338 keep track of the frame to evaluate the expression
5339 in. To evaluate the condition however, it doesn't
5340 really matter which instantiation of the function
5341 where the condition makes sense triggers the
5342 watchpoint. This allows an expression like "watch
5343 global if q > 10" set in `func', catch writes to
5344 global on all threads that call `func', or catch
5345 writes on all recursive calls of `func' by a single
5346 thread. We simply always evaluate the condition in
5347 the innermost frame that's executing where it makes
5348 sense to evaluate the condition. It seems
5350 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5352 select_frame (frame
);
5354 within_current_scope
= 0;
5356 if (within_current_scope
)
5360 condition_result
= breakpoint_cond_eval (cond
);
5362 catch (const gdb_exception
&ex
)
5364 exception_fprintf (gdb_stderr
, ex
,
5365 "Error in testing breakpoint condition:\n");
5370 warning (_("Watchpoint condition cannot be tested "
5371 "in the current scope"));
5372 /* If we failed to set the right context for this
5373 watchpoint, unconditionally report it. */
5375 /* FIXME-someday, should give breakpoint #. */
5376 value_free_to_mark (mark
);
5379 if (cond
&& !condition_result
)
5383 else if (b
->ignore_count
> 0)
5387 /* Increase the hit count even though we don't stop. */
5389 gdb::observers::breakpoint_modified
.notify (b
);
5393 /* Returns true if we need to track moribund locations of LOC's type
5394 on the current target. */
5397 need_moribund_for_location_type (struct bp_location
*loc
)
5399 return ((loc
->loc_type
== bp_loc_software_breakpoint
5400 && !target_supports_stopped_by_sw_breakpoint ())
5401 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5402 && !target_supports_stopped_by_hw_breakpoint ()));
5405 /* See breakpoint.h. */
5408 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5409 const struct target_waitstatus
*ws
)
5411 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5413 for (breakpoint
*b
: all_breakpoints ())
5415 if (!breakpoint_enabled (b
))
5418 for (bp_location
*bl
: b
->locations ())
5420 /* For hardware watchpoints, we look only at the first
5421 location. The watchpoint_check function will work on the
5422 entire expression, not the individual locations. For
5423 read watchpoints, the watchpoints_triggered function has
5424 checked all locations already. */
5425 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5428 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5431 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5434 /* Come here if it's a watchpoint, or if the break address
5437 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5440 /* Assume we stop. Should we find a watchpoint that is not
5441 actually triggered, or if the condition of the breakpoint
5442 evaluates as false, we'll reset 'stop' to 0. */
5446 /* If this is a scope breakpoint, mark the associated
5447 watchpoint as triggered so that we will handle the
5448 out-of-scope event. We'll get to the watchpoint next
5450 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5452 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5454 w
->watchpoint_triggered
= watch_triggered_yes
;
5459 /* Check if a moribund breakpoint explains the stop. */
5460 if (!target_supports_stopped_by_sw_breakpoint ()
5461 || !target_supports_stopped_by_hw_breakpoint ())
5463 for (bp_location
*loc
: moribund_locations
)
5465 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5466 && need_moribund_for_location_type (loc
))
5468 bpstat bs
= new bpstats (loc
, &bs_link
);
5469 /* For hits of moribund locations, we should just proceed. */
5472 bs
->print_it
= print_it_noop
;
5480 /* See breakpoint.h. */
5483 bpstat_stop_status (const address_space
*aspace
,
5484 CORE_ADDR bp_addr
, thread_info
*thread
,
5485 const struct target_waitstatus
*ws
,
5488 struct breakpoint
*b
= NULL
;
5489 /* First item of allocated bpstat's. */
5490 bpstat bs_head
= stop_chain
;
5492 int need_remove_insert
;
5495 /* First, build the bpstat chain with locations that explain a
5496 target stop, while being careful to not set the target running,
5497 as that may invalidate locations (in particular watchpoint
5498 locations are recreated). Resuming will happen here with
5499 breakpoint conditions or watchpoint expressions that include
5500 inferior function calls. */
5501 if (bs_head
== NULL
)
5502 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5504 /* A bit of special processing for shlib breakpoints. We need to
5505 process solib loading here, so that the lists of loaded and
5506 unloaded libraries are correct before we handle "catch load" and
5508 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5510 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5512 handle_solib_event ();
5517 /* Now go through the locations that caused the target to stop, and
5518 check whether we're interested in reporting this stop to higher
5519 layers, or whether we should resume the target transparently. */
5523 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5528 b
= bs
->breakpoint_at
;
5529 b
->ops
->check_status (bs
);
5532 bpstat_check_breakpoint_conditions (bs
, thread
);
5537 gdb::observers::breakpoint_modified
.notify (b
);
5539 /* We will stop here. */
5540 if (b
->disposition
== disp_disable
)
5542 --(b
->enable_count
);
5543 if (b
->enable_count
<= 0)
5544 b
->enable_state
= bp_disabled
;
5549 bs
->commands
= b
->commands
;
5550 if (command_line_is_silent (bs
->commands
5551 ? bs
->commands
.get () : NULL
))
5554 b
->ops
->after_condition_true (bs
);
5559 /* Print nothing for this entry if we don't stop or don't
5561 if (!bs
->stop
|| !bs
->print
)
5562 bs
->print_it
= print_it_noop
;
5565 /* If we aren't stopping, the value of some hardware watchpoint may
5566 not have changed, but the intermediate memory locations we are
5567 watching may have. Don't bother if we're stopping; this will get
5569 need_remove_insert
= 0;
5570 if (! bpstat_causes_stop (bs_head
))
5571 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5573 && bs
->breakpoint_at
5574 && is_hardware_watchpoint (bs
->breakpoint_at
))
5576 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5578 update_watchpoint (w
, 0 /* don't reparse. */);
5579 need_remove_insert
= 1;
5582 if (need_remove_insert
)
5583 update_global_location_list (UGLL_MAY_INSERT
);
5584 else if (removed_any
)
5585 update_global_location_list (UGLL_DONT_INSERT
);
5591 handle_jit_event (CORE_ADDR address
)
5593 struct gdbarch
*gdbarch
;
5595 infrun_debug_printf ("handling bp_jit_event");
5597 /* Switch terminal for any messages produced by
5598 breakpoint_re_set. */
5599 target_terminal::ours_for_output ();
5601 gdbarch
= get_frame_arch (get_current_frame ());
5602 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5603 thus it is expected that its objectfile can be found through
5604 minimal symbol lookup. If it doesn't work (and assert fails), it
5605 most likely means that `jit_breakpoint_re_set` was changes and this
5606 function needs to be updated too. */
5607 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5608 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5609 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5611 target_terminal::inferior ();
5614 /* Prepare WHAT final decision for infrun. */
5616 /* Decide what infrun needs to do with this bpstat. */
5619 bpstat_what (bpstat bs_head
)
5621 struct bpstat_what retval
;
5624 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5625 retval
.call_dummy
= STOP_NONE
;
5626 retval
.is_longjmp
= false;
5628 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5630 /* Extract this BS's action. After processing each BS, we check
5631 if its action overrides all we've seem so far. */
5632 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5635 if (bs
->breakpoint_at
== NULL
)
5637 /* I suspect this can happen if it was a momentary
5638 breakpoint which has since been deleted. */
5642 bptype
= bs
->breakpoint_at
->type
;
5649 case bp_hardware_breakpoint
:
5650 case bp_single_step
:
5653 case bp_shlib_event
:
5657 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5659 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5662 this_action
= BPSTAT_WHAT_SINGLE
;
5665 case bp_hardware_watchpoint
:
5666 case bp_read_watchpoint
:
5667 case bp_access_watchpoint
:
5671 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5673 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5677 /* There was a watchpoint, but we're not stopping.
5678 This requires no further action. */
5682 case bp_longjmp_call_dummy
:
5686 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5687 retval
.is_longjmp
= bptype
!= bp_exception
;
5690 this_action
= BPSTAT_WHAT_SINGLE
;
5692 case bp_longjmp_resume
:
5693 case bp_exception_resume
:
5696 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5697 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5700 this_action
= BPSTAT_WHAT_SINGLE
;
5702 case bp_step_resume
:
5704 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5707 /* It is for the wrong frame. */
5708 this_action
= BPSTAT_WHAT_SINGLE
;
5711 case bp_hp_step_resume
:
5713 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5716 /* It is for the wrong frame. */
5717 this_action
= BPSTAT_WHAT_SINGLE
;
5720 case bp_watchpoint_scope
:
5721 case bp_thread_event
:
5722 case bp_overlay_event
:
5723 case bp_longjmp_master
:
5724 case bp_std_terminate_master
:
5725 case bp_exception_master
:
5726 this_action
= BPSTAT_WHAT_SINGLE
;
5732 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5734 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5738 /* Some catchpoints are implemented with breakpoints.
5739 For those, we need to step over the breakpoint. */
5740 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5741 this_action
= BPSTAT_WHAT_SINGLE
;
5745 this_action
= BPSTAT_WHAT_SINGLE
;
5748 /* Make sure the action is stop (silent or noisy),
5749 so infrun.c pops the dummy frame. */
5750 retval
.call_dummy
= STOP_STACK_DUMMY
;
5751 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5753 case bp_std_terminate
:
5754 /* Make sure the action is stop (silent or noisy),
5755 so infrun.c pops the dummy frame. */
5756 retval
.call_dummy
= STOP_STD_TERMINATE
;
5757 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5760 case bp_fast_tracepoint
:
5761 case bp_static_tracepoint
:
5762 /* Tracepoint hits should not be reported back to GDB, and
5763 if one got through somehow, it should have been filtered
5765 internal_error (__FILE__
, __LINE__
,
5766 _("bpstat_what: tracepoint encountered"));
5768 case bp_gnu_ifunc_resolver
:
5769 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5770 this_action
= BPSTAT_WHAT_SINGLE
;
5772 case bp_gnu_ifunc_resolver_return
:
5773 /* The breakpoint will be removed, execution will restart from the
5774 PC of the former breakpoint. */
5775 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5780 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5782 this_action
= BPSTAT_WHAT_SINGLE
;
5786 internal_error (__FILE__
, __LINE__
,
5787 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5790 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5797 bpstat_run_callbacks (bpstat bs_head
)
5801 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5803 struct breakpoint
*b
= bs
->breakpoint_at
;
5810 handle_jit_event (bs
->bp_location_at
->address
);
5812 case bp_gnu_ifunc_resolver
:
5813 gnu_ifunc_resolver_stop (b
);
5815 case bp_gnu_ifunc_resolver_return
:
5816 gnu_ifunc_resolver_return_stop (b
);
5822 /* See breakpoint.h. */
5825 bpstat_should_step ()
5827 for (breakpoint
*b
: all_breakpoints ())
5828 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5834 /* See breakpoint.h. */
5837 bpstat_causes_stop (bpstat bs
)
5839 for (; bs
!= NULL
; bs
= bs
->next
)
5848 /* Compute a string of spaces suitable to indent the next line
5849 so it starts at the position corresponding to the table column
5850 named COL_NAME in the currently active table of UIOUT. */
5853 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5855 static char wrap_indent
[80];
5856 int i
, total_width
, width
, align
;
5860 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5862 if (strcmp (text
, col_name
) == 0)
5864 gdb_assert (total_width
< sizeof wrap_indent
);
5865 memset (wrap_indent
, ' ', total_width
);
5866 wrap_indent
[total_width
] = 0;
5871 total_width
+= width
+ 1;
5877 /* Determine if the locations of this breakpoint will have their conditions
5878 evaluated by the target, host or a mix of both. Returns the following:
5880 "host": Host evals condition.
5881 "host or target": Host or Target evals condition.
5882 "target": Target evals condition.
5886 bp_condition_evaluator (struct breakpoint
*b
)
5888 char host_evals
= 0;
5889 char target_evals
= 0;
5894 if (!is_breakpoint (b
))
5897 if (gdb_evaluates_breakpoint_condition_p ()
5898 || !target_supports_evaluation_of_breakpoint_conditions ())
5899 return condition_evaluation_host
;
5901 for (bp_location
*bl
: b
->locations ())
5903 if (bl
->cond_bytecode
)
5909 if (host_evals
&& target_evals
)
5910 return condition_evaluation_both
;
5911 else if (target_evals
)
5912 return condition_evaluation_target
;
5914 return condition_evaluation_host
;
5917 /* Determine the breakpoint location's condition evaluator. This is
5918 similar to bp_condition_evaluator, but for locations. */
5921 bp_location_condition_evaluator (struct bp_location
*bl
)
5923 if (bl
&& !is_breakpoint (bl
->owner
))
5926 if (gdb_evaluates_breakpoint_condition_p ()
5927 || !target_supports_evaluation_of_breakpoint_conditions ())
5928 return condition_evaluation_host
;
5930 if (bl
&& bl
->cond_bytecode
)
5931 return condition_evaluation_target
;
5933 return condition_evaluation_host
;
5936 /* Print the LOC location out of the list of B->LOC locations. */
5939 print_breakpoint_location (struct breakpoint
*b
,
5940 struct bp_location
*loc
)
5942 struct ui_out
*uiout
= current_uiout
;
5944 scoped_restore_current_program_space restore_pspace
;
5946 if (loc
!= NULL
&& loc
->shlib_disabled
)
5950 set_current_program_space (loc
->pspace
);
5952 if (b
->display_canonical
)
5953 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5954 else if (loc
&& loc
->symtab
)
5956 const struct symbol
*sym
= loc
->symbol
;
5960 uiout
->text ("in ");
5961 uiout
->field_string ("func", sym
->print_name (),
5962 function_name_style
.style ());
5964 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5965 uiout
->text ("at ");
5967 uiout
->field_string ("file",
5968 symtab_to_filename_for_display (loc
->symtab
),
5969 file_name_style
.style ());
5972 if (uiout
->is_mi_like_p ())
5973 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5975 uiout
->field_signed ("line", loc
->line_number
);
5981 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5983 uiout
->field_stream ("at", stb
);
5987 uiout
->field_string ("pending",
5988 event_location_to_string (b
->location
.get ()));
5989 /* If extra_string is available, it could be holding a condition
5990 or dprintf arguments. In either case, make sure it is printed,
5991 too, but only for non-MI streams. */
5992 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5994 if (b
->type
== bp_dprintf
)
5998 uiout
->text (b
->extra_string
);
6002 if (loc
&& is_breakpoint (b
)
6003 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6004 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6007 uiout
->field_string ("evaluated-by",
6008 bp_location_condition_evaluator (loc
));
6014 bptype_string (enum bptype type
)
6016 struct ep_type_description
6019 const char *description
;
6021 static struct ep_type_description bptypes
[] =
6023 {bp_none
, "?deleted?"},
6024 {bp_breakpoint
, "breakpoint"},
6025 {bp_hardware_breakpoint
, "hw breakpoint"},
6026 {bp_single_step
, "sw single-step"},
6027 {bp_until
, "until"},
6028 {bp_finish
, "finish"},
6029 {bp_watchpoint
, "watchpoint"},
6030 {bp_hardware_watchpoint
, "hw watchpoint"},
6031 {bp_read_watchpoint
, "read watchpoint"},
6032 {bp_access_watchpoint
, "acc watchpoint"},
6033 {bp_longjmp
, "longjmp"},
6034 {bp_longjmp_resume
, "longjmp resume"},
6035 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6036 {bp_exception
, "exception"},
6037 {bp_exception_resume
, "exception resume"},
6038 {bp_step_resume
, "step resume"},
6039 {bp_hp_step_resume
, "high-priority step resume"},
6040 {bp_watchpoint_scope
, "watchpoint scope"},
6041 {bp_call_dummy
, "call dummy"},
6042 {bp_std_terminate
, "std::terminate"},
6043 {bp_shlib_event
, "shlib events"},
6044 {bp_thread_event
, "thread events"},
6045 {bp_overlay_event
, "overlay events"},
6046 {bp_longjmp_master
, "longjmp master"},
6047 {bp_std_terminate_master
, "std::terminate master"},
6048 {bp_exception_master
, "exception master"},
6049 {bp_catchpoint
, "catchpoint"},
6050 {bp_tracepoint
, "tracepoint"},
6051 {bp_fast_tracepoint
, "fast tracepoint"},
6052 {bp_static_tracepoint
, "static tracepoint"},
6053 {bp_dprintf
, "dprintf"},
6054 {bp_jit_event
, "jit events"},
6055 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6056 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6059 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6060 || ((int) type
!= bptypes
[(int) type
].type
))
6061 internal_error (__FILE__
, __LINE__
,
6062 _("bptypes table does not describe type #%d."),
6065 return bptypes
[(int) type
].description
;
6068 /* For MI, output a field named 'thread-groups' with a list as the value.
6069 For CLI, prefix the list with the string 'inf'. */
6072 output_thread_groups (struct ui_out
*uiout
,
6073 const char *field_name
,
6074 const std::vector
<int> &inf_nums
,
6077 int is_mi
= uiout
->is_mi_like_p ();
6079 /* For backward compatibility, don't display inferiors in CLI unless
6080 there are several. Always display them for MI. */
6081 if (!is_mi
&& mi_only
)
6084 ui_out_emit_list
list_emitter (uiout
, field_name
);
6086 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6092 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6093 uiout
->field_string (NULL
, mi_group
);
6098 uiout
->text (" inf ");
6102 uiout
->text (plongest (inf_nums
[i
]));
6107 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6108 instead of going via breakpoint_ops::print_one. This makes "maint
6109 info breakpoints" show the software breakpoint locations of
6110 catchpoints, which are considered internal implementation
6114 print_one_breakpoint_location (struct breakpoint
*b
,
6115 struct bp_location
*loc
,
6117 struct bp_location
**last_loc
,
6118 int allflag
, bool raw_loc
)
6120 struct command_line
*l
;
6121 static char bpenables
[] = "nynny";
6123 struct ui_out
*uiout
= current_uiout
;
6124 int header_of_multiple
= 0;
6125 int part_of_multiple
= (loc
!= NULL
);
6126 struct value_print_options opts
;
6128 get_user_print_options (&opts
);
6130 gdb_assert (!loc
|| loc_number
!= 0);
6131 /* See comment in print_one_breakpoint concerning treatment of
6132 breakpoints with single disabled location. */
6135 && (b
->loc
->next
!= NULL
6136 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6137 header_of_multiple
= 1;
6145 if (part_of_multiple
)
6146 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6148 uiout
->field_signed ("number", b
->number
);
6152 if (part_of_multiple
)
6153 uiout
->field_skip ("type");
6155 uiout
->field_string ("type", bptype_string (b
->type
));
6159 if (part_of_multiple
)
6160 uiout
->field_skip ("disp");
6162 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6166 /* For locations that are disabled because of an invalid condition,
6167 display "N*" on CLI, where "*" refers to a footnote below the
6168 table. For MI, simply display a "N" without a footnote. */
6169 const char *N
= (uiout
->is_mi_like_p ()) ? "N" : "N*";
6170 if (part_of_multiple
)
6171 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? N
6172 : (loc
->enabled
? "y" : "n")));
6174 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6177 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6178 b
->ops
->print_one (b
, last_loc
);
6181 if (is_watchpoint (b
))
6183 struct watchpoint
*w
= (struct watchpoint
*) b
;
6185 /* Field 4, the address, is omitted (which makes the columns
6186 not line up too nicely with the headers, but the effect
6187 is relatively readable). */
6188 if (opts
.addressprint
)
6189 uiout
->field_skip ("addr");
6191 uiout
->field_string ("what", w
->exp_string
);
6193 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6194 || is_ada_exception_catchpoint (b
))
6196 if (opts
.addressprint
)
6199 if (header_of_multiple
)
6200 uiout
->field_string ("addr", "<MULTIPLE>",
6201 metadata_style
.style ());
6202 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6203 uiout
->field_string ("addr", "<PENDING>",
6204 metadata_style
.style ());
6206 uiout
->field_core_addr ("addr",
6207 loc
->gdbarch
, loc
->address
);
6210 if (!header_of_multiple
)
6211 print_breakpoint_location (b
, loc
);
6217 if (loc
!= NULL
&& !header_of_multiple
)
6219 std::vector
<int> inf_nums
;
6222 for (inferior
*inf
: all_inferiors ())
6224 if (inf
->pspace
== loc
->pspace
)
6225 inf_nums
.push_back (inf
->num
);
6228 /* For backward compatibility, don't display inferiors in CLI unless
6229 there are several. Always display for MI. */
6231 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6232 && (program_spaces
.size () > 1
6233 || number_of_inferiors () > 1)
6234 /* LOC is for existing B, it cannot be in
6235 moribund_locations and thus having NULL OWNER. */
6236 && loc
->owner
->type
!= bp_catchpoint
))
6238 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6241 if (!part_of_multiple
)
6243 if (b
->thread
!= -1)
6245 /* FIXME: This seems to be redundant and lost here; see the
6246 "stop only in" line a little further down. */
6247 uiout
->text (" thread ");
6248 uiout
->field_signed ("thread", b
->thread
);
6250 else if (b
->task
!= 0)
6252 uiout
->text (" task ");
6253 uiout
->field_signed ("task", b
->task
);
6259 if (!part_of_multiple
)
6260 b
->ops
->print_one_detail (b
, uiout
);
6262 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6265 uiout
->text ("\tstop only in stack frame at ");
6266 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6268 uiout
->field_core_addr ("frame",
6269 b
->gdbarch
, b
->frame_id
.stack_addr
);
6273 if (!part_of_multiple
&& b
->cond_string
)
6276 if (is_tracepoint (b
))
6277 uiout
->text ("\ttrace only if ");
6279 uiout
->text ("\tstop only if ");
6280 uiout
->field_string ("cond", b
->cond_string
);
6282 /* Print whether the target is doing the breakpoint's condition
6283 evaluation. If GDB is doing the evaluation, don't print anything. */
6284 if (is_breakpoint (b
)
6285 && breakpoint_condition_evaluation_mode ()
6286 == condition_evaluation_target
)
6288 uiout
->message (" (%pF evals)",
6289 string_field ("evaluated-by",
6290 bp_condition_evaluator (b
)));
6295 if (!part_of_multiple
&& b
->thread
!= -1)
6297 /* FIXME should make an annotation for this. */
6298 uiout
->text ("\tstop only in thread ");
6299 if (uiout
->is_mi_like_p ())
6300 uiout
->field_signed ("thread", b
->thread
);
6303 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6305 uiout
->field_string ("thread", print_thread_id (thr
));
6310 if (!part_of_multiple
)
6314 /* FIXME should make an annotation for this. */
6315 if (is_catchpoint (b
))
6316 uiout
->text ("\tcatchpoint");
6317 else if (is_tracepoint (b
))
6318 uiout
->text ("\ttracepoint");
6320 uiout
->text ("\tbreakpoint");
6321 uiout
->text (" already hit ");
6322 uiout
->field_signed ("times", b
->hit_count
);
6323 if (b
->hit_count
== 1)
6324 uiout
->text (" time\n");
6326 uiout
->text (" times\n");
6330 /* Output the count also if it is zero, but only if this is mi. */
6331 if (uiout
->is_mi_like_p ())
6332 uiout
->field_signed ("times", b
->hit_count
);
6336 if (!part_of_multiple
&& b
->ignore_count
)
6339 uiout
->message ("\tignore next %pF hits\n",
6340 signed_field ("ignore", b
->ignore_count
));
6343 /* Note that an enable count of 1 corresponds to "enable once"
6344 behavior, which is reported by the combination of enablement and
6345 disposition, so we don't need to mention it here. */
6346 if (!part_of_multiple
&& b
->enable_count
> 1)
6349 uiout
->text ("\tdisable after ");
6350 /* Tweak the wording to clarify that ignore and enable counts
6351 are distinct, and have additive effect. */
6352 if (b
->ignore_count
)
6353 uiout
->text ("additional ");
6355 uiout
->text ("next ");
6356 uiout
->field_signed ("enable", b
->enable_count
);
6357 uiout
->text (" hits\n");
6360 if (!part_of_multiple
&& is_tracepoint (b
))
6362 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6364 if (tp
->traceframe_usage
)
6366 uiout
->text ("\ttrace buffer usage ");
6367 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6368 uiout
->text (" bytes\n");
6372 l
= b
->commands
? b
->commands
.get () : NULL
;
6373 if (!part_of_multiple
&& l
)
6376 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6377 print_command_lines (uiout
, l
, 4);
6380 if (is_tracepoint (b
))
6382 struct tracepoint
*t
= (struct tracepoint
*) b
;
6384 if (!part_of_multiple
&& t
->pass_count
)
6386 annotate_field (10);
6387 uiout
->text ("\tpass count ");
6388 uiout
->field_signed ("pass", t
->pass_count
);
6389 uiout
->text (" \n");
6392 /* Don't display it when tracepoint or tracepoint location is
6394 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6396 annotate_field (11);
6398 if (uiout
->is_mi_like_p ())
6399 uiout
->field_string ("installed",
6400 loc
->inserted
? "y" : "n");
6406 uiout
->text ("\tnot ");
6407 uiout
->text ("installed on target\n");
6412 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6414 if (is_watchpoint (b
))
6416 struct watchpoint
*w
= (struct watchpoint
*) b
;
6418 uiout
->field_string ("original-location", w
->exp_string
);
6420 else if (b
->location
!= NULL
6421 && event_location_to_string (b
->location
.get ()) != NULL
)
6422 uiout
->field_string ("original-location",
6423 event_location_to_string (b
->location
.get ()));
6427 /* See breakpoint.h. */
6429 bool fix_multi_location_breakpoint_output_globally
= false;
6432 print_one_breakpoint (struct breakpoint
*b
,
6433 struct bp_location
**last_loc
,
6436 struct ui_out
*uiout
= current_uiout
;
6437 bool use_fixed_output
6438 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6439 || fix_multi_location_breakpoint_output_globally
);
6441 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6442 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6444 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6446 if (!use_fixed_output
)
6447 bkpt_tuple_emitter
.reset ();
6449 /* If this breakpoint has custom print function,
6450 it's already printed. Otherwise, print individual
6451 locations, if any. */
6453 || b
->ops
->print_one
== NULL
6456 /* If breakpoint has a single location that is disabled, we
6457 print it as if it had several locations, since otherwise it's
6458 hard to represent "breakpoint enabled, location disabled"
6461 Note that while hardware watchpoints have several locations
6462 internally, that's not a property exposed to users.
6464 Likewise, while catchpoints may be implemented with
6465 breakpoints (e.g., catch throw), that's not a property
6466 exposed to users. We do however display the internal
6467 breakpoint locations with "maint info breakpoints". */
6468 if (!is_hardware_watchpoint (b
)
6469 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6470 || is_ada_exception_catchpoint (b
))
6472 || (b
->loc
&& (b
->loc
->next
6474 || b
->loc
->disabled_by_cond
))))
6476 gdb::optional
<ui_out_emit_list
> locations_list
;
6478 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6479 MI record. For later versions, place breakpoint locations in a
6481 if (uiout
->is_mi_like_p () && use_fixed_output
)
6482 locations_list
.emplace (uiout
, "locations");
6485 for (bp_location
*loc
: b
->locations ())
6487 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6488 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6497 breakpoint_address_bits (struct breakpoint
*b
)
6499 int print_address_bits
= 0;
6501 /* Software watchpoints that aren't watching memory don't have an
6502 address to print. */
6503 if (is_no_memory_software_watchpoint (b
))
6506 for (bp_location
*loc
: b
->locations ())
6510 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6511 if (addr_bit
> print_address_bits
)
6512 print_address_bits
= addr_bit
;
6515 return print_address_bits
;
6518 /* See breakpoint.h. */
6521 print_breakpoint (breakpoint
*b
)
6523 struct bp_location
*dummy_loc
= NULL
;
6524 print_one_breakpoint (b
, &dummy_loc
, 0);
6527 /* Return true if this breakpoint was set by the user, false if it is
6528 internal or momentary. */
6531 user_breakpoint_p (struct breakpoint
*b
)
6533 return b
->number
> 0;
6536 /* See breakpoint.h. */
6539 pending_breakpoint_p (struct breakpoint
*b
)
6541 return b
->loc
== NULL
;
6544 /* Print information on breakpoints (including watchpoints and tracepoints).
6546 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6547 understood by number_or_range_parser. Only breakpoints included in this
6548 list are then printed.
6550 If SHOW_INTERNAL is true, print internal breakpoints.
6552 If FILTER is non-NULL, call it on each breakpoint and only include the
6553 ones for which it returns true.
6555 Return the total number of breakpoints listed. */
6558 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6559 bool (*filter
) (const struct breakpoint
*))
6561 struct bp_location
*last_loc
= NULL
;
6562 int nr_printable_breakpoints
;
6563 struct value_print_options opts
;
6564 int print_address_bits
= 0;
6565 int print_type_col_width
= 14;
6566 struct ui_out
*uiout
= current_uiout
;
6567 bool has_disabled_by_cond_location
= false;
6569 get_user_print_options (&opts
);
6571 /* Compute the number of rows in the table, as well as the size
6572 required for address fields. */
6573 nr_printable_breakpoints
= 0;
6574 for (breakpoint
*b
: all_breakpoints ())
6576 /* If we have a filter, only list the breakpoints it accepts. */
6577 if (filter
&& !filter (b
))
6580 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6581 accept. Skip the others. */
6582 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6584 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6586 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6590 if (show_internal
|| user_breakpoint_p (b
))
6592 int addr_bit
, type_len
;
6594 addr_bit
= breakpoint_address_bits (b
);
6595 if (addr_bit
> print_address_bits
)
6596 print_address_bits
= addr_bit
;
6598 type_len
= strlen (bptype_string (b
->type
));
6599 if (type_len
> print_type_col_width
)
6600 print_type_col_width
= type_len
;
6602 nr_printable_breakpoints
++;
6607 ui_out_emit_table
table_emitter (uiout
,
6608 opts
.addressprint
? 6 : 5,
6609 nr_printable_breakpoints
,
6612 if (nr_printable_breakpoints
> 0)
6613 annotate_breakpoints_headers ();
6614 if (nr_printable_breakpoints
> 0)
6616 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6617 if (nr_printable_breakpoints
> 0)
6619 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6620 if (nr_printable_breakpoints
> 0)
6622 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6623 if (nr_printable_breakpoints
> 0)
6625 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6626 if (opts
.addressprint
)
6628 if (nr_printable_breakpoints
> 0)
6630 if (print_address_bits
<= 32)
6631 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6633 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6635 if (nr_printable_breakpoints
> 0)
6637 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6638 uiout
->table_body ();
6639 if (nr_printable_breakpoints
> 0)
6640 annotate_breakpoints_table ();
6642 for (breakpoint
*b
: all_breakpoints ())
6645 /* If we have a filter, only list the breakpoints it accepts. */
6646 if (filter
&& !filter (b
))
6649 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6650 accept. Skip the others. */
6652 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6654 if (show_internal
) /* maintenance info breakpoint */
6656 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6659 else /* all others */
6661 if (!number_is_in_list (bp_num_list
, b
->number
))
6665 /* We only print out user settable breakpoints unless the
6666 show_internal is set. */
6667 if (show_internal
|| user_breakpoint_p (b
))
6669 print_one_breakpoint (b
, &last_loc
, show_internal
);
6670 for (bp_location
*loc
: b
->locations ())
6671 if (loc
->disabled_by_cond
)
6672 has_disabled_by_cond_location
= true;
6677 if (nr_printable_breakpoints
== 0)
6679 /* If there's a filter, let the caller decide how to report
6683 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6684 uiout
->message ("No breakpoints or watchpoints.\n");
6686 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6692 if (last_loc
&& !server_command
)
6693 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6695 if (has_disabled_by_cond_location
&& !uiout
->is_mi_like_p ())
6696 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6700 /* FIXME? Should this be moved up so that it is only called when
6701 there have been breakpoints? */
6702 annotate_breakpoints_table_end ();
6704 return nr_printable_breakpoints
;
6707 /* Display the value of default-collect in a way that is generally
6708 compatible with the breakpoint list. */
6711 default_collect_info (void)
6713 struct ui_out
*uiout
= current_uiout
;
6715 /* If it has no value (which is frequently the case), say nothing; a
6716 message like "No default-collect." gets in user's face when it's
6718 if (!*default_collect
)
6721 /* The following phrase lines up nicely with per-tracepoint collect
6723 uiout
->text ("default collect ");
6724 uiout
->field_string ("default-collect", default_collect
);
6725 uiout
->text (" \n");
6729 info_breakpoints_command (const char *args
, int from_tty
)
6731 breakpoint_1 (args
, false, NULL
);
6733 default_collect_info ();
6737 info_watchpoints_command (const char *args
, int from_tty
)
6739 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6740 struct ui_out
*uiout
= current_uiout
;
6742 if (num_printed
== 0)
6744 if (args
== NULL
|| *args
== '\0')
6745 uiout
->message ("No watchpoints.\n");
6747 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6752 maintenance_info_breakpoints (const char *args
, int from_tty
)
6754 breakpoint_1 (args
, true, NULL
);
6756 default_collect_info ();
6760 breakpoint_has_pc (struct breakpoint
*b
,
6761 struct program_space
*pspace
,
6762 CORE_ADDR pc
, struct obj_section
*section
)
6764 for (bp_location
*bl
: b
->locations ())
6766 if (bl
->pspace
== pspace
6767 && bl
->address
== pc
6768 && (!overlay_debugging
|| bl
->section
== section
))
6774 /* Print a message describing any user-breakpoints set at PC. This
6775 concerns with logical breakpoints, so we match program spaces, not
6779 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6780 struct program_space
*pspace
, CORE_ADDR pc
,
6781 struct obj_section
*section
, int thread
)
6785 for (breakpoint
*b
: all_breakpoints ())
6786 others
+= (user_breakpoint_p (b
)
6787 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6792 printf_filtered (_("Note: breakpoint "));
6793 else /* if (others == ???) */
6794 printf_filtered (_("Note: breakpoints "));
6795 for (breakpoint
*b
: all_breakpoints ())
6796 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6799 printf_filtered ("%d", b
->number
);
6800 if (b
->thread
== -1 && thread
!= -1)
6801 printf_filtered (" (all threads)");
6802 else if (b
->thread
!= -1)
6803 printf_filtered (" (thread %d)", b
->thread
);
6804 printf_filtered ("%s%s ",
6805 ((b
->enable_state
== bp_disabled
6806 || b
->enable_state
== bp_call_disabled
)
6810 : ((others
== 1) ? " and" : ""));
6812 current_uiout
->message (_("also set at pc %ps.\n"),
6813 styled_string (address_style
.style (),
6814 paddress (gdbarch
, pc
)));
6819 /* Return true iff it is meaningful to use the address member of LOC.
6820 For some breakpoint types, the locations' address members are
6821 irrelevant and it makes no sense to attempt to compare them to
6822 other addresses (or use them for any other purpose either).
6824 More specifically, software watchpoints and catchpoints that are
6825 not backed by breakpoints always have a zero valued location
6826 address and we don't want to mark breakpoints of any of these types
6827 to be a duplicate of an actual breakpoint location at address
6831 bl_address_is_meaningful (bp_location
*loc
)
6833 return loc
->loc_type
!= bp_loc_other
;
6836 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6837 true if LOC1 and LOC2 represent the same watchpoint location. */
6840 watchpoint_locations_match (struct bp_location
*loc1
,
6841 struct bp_location
*loc2
)
6843 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6844 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6846 /* Both of them must exist. */
6847 gdb_assert (w1
!= NULL
);
6848 gdb_assert (w2
!= NULL
);
6850 /* If the target can evaluate the condition expression in hardware,
6851 then we we need to insert both watchpoints even if they are at
6852 the same place. Otherwise the watchpoint will only trigger when
6853 the condition of whichever watchpoint was inserted evaluates to
6854 true, not giving a chance for GDB to check the condition of the
6855 other watchpoint. */
6857 && target_can_accel_watchpoint_condition (loc1
->address
,
6859 loc1
->watchpoint_type
,
6860 w1
->cond_exp
.get ()))
6862 && target_can_accel_watchpoint_condition (loc2
->address
,
6864 loc2
->watchpoint_type
,
6865 w2
->cond_exp
.get ())))
6868 /* Note that this checks the owner's type, not the location's. In
6869 case the target does not support read watchpoints, but does
6870 support access watchpoints, we'll have bp_read_watchpoint
6871 watchpoints with hw_access locations. Those should be considered
6872 duplicates of hw_read locations. The hw_read locations will
6873 become hw_access locations later. */
6874 return (loc1
->owner
->type
== loc2
->owner
->type
6875 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6876 && loc1
->address
== loc2
->address
6877 && loc1
->length
== loc2
->length
);
6880 /* See breakpoint.h. */
6883 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6884 const address_space
*aspace2
, CORE_ADDR addr2
)
6886 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6887 || aspace1
== aspace2
)
6891 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6892 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6893 matches ASPACE2. On targets that have global breakpoints, the address
6894 space doesn't really matter. */
6897 breakpoint_address_match_range (const address_space
*aspace1
,
6899 int len1
, const address_space
*aspace2
,
6902 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6903 || aspace1
== aspace2
)
6904 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6907 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6908 a ranged breakpoint. In most targets, a match happens only if ASPACE
6909 matches the breakpoint's address space. On targets that have global
6910 breakpoints, the address space doesn't really matter. */
6913 breakpoint_location_address_match (struct bp_location
*bl
,
6914 const address_space
*aspace
,
6917 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6920 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6921 bl
->address
, bl
->length
,
6925 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6926 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6927 match happens only if ASPACE matches the breakpoint's address
6928 space. On targets that have global breakpoints, the address space
6929 doesn't really matter. */
6932 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6933 const address_space
*aspace
,
6934 CORE_ADDR addr
, int len
)
6936 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6937 || bl
->pspace
->aspace
== aspace
)
6939 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6941 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6947 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6948 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6949 true, otherwise returns false. */
6952 tracepoint_locations_match (struct bp_location
*loc1
,
6953 struct bp_location
*loc2
)
6955 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6956 /* Since tracepoint locations are never duplicated with others', tracepoint
6957 locations at the same address of different tracepoints are regarded as
6958 different locations. */
6959 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6964 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6965 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6966 the same location. If SW_HW_BPS_MATCH is true, then software
6967 breakpoint locations and hardware breakpoint locations match,
6968 otherwise they don't. */
6971 breakpoint_locations_match (struct bp_location
*loc1
,
6972 struct bp_location
*loc2
,
6973 bool sw_hw_bps_match
)
6975 int hw_point1
, hw_point2
;
6977 /* Both of them must not be in moribund_locations. */
6978 gdb_assert (loc1
->owner
!= NULL
);
6979 gdb_assert (loc2
->owner
!= NULL
);
6981 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6982 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6984 if (hw_point1
!= hw_point2
)
6987 return watchpoint_locations_match (loc1
, loc2
);
6988 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6989 return tracepoint_locations_match (loc1
, loc2
);
6991 /* We compare bp_location.length in order to cover ranged
6992 breakpoints. Keep this in sync with
6993 bp_location_is_less_than. */
6994 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6995 loc2
->pspace
->aspace
, loc2
->address
)
6996 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
6997 && loc1
->length
== loc2
->length
);
7001 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7002 int bnum
, int have_bnum
)
7004 /* The longest string possibly returned by hex_string_custom
7005 is 50 chars. These must be at least that big for safety. */
7009 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7010 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7012 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7013 bnum
, astr1
, astr2
);
7015 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7018 /* Adjust a breakpoint's address to account for architectural
7019 constraints on breakpoint placement. Return the adjusted address.
7020 Note: Very few targets require this kind of adjustment. For most
7021 targets, this function is simply the identity function. */
7024 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7025 CORE_ADDR bpaddr
, enum bptype bptype
)
7027 if (bptype
== bp_watchpoint
7028 || bptype
== bp_hardware_watchpoint
7029 || bptype
== bp_read_watchpoint
7030 || bptype
== bp_access_watchpoint
7031 || bptype
== bp_catchpoint
)
7033 /* Watchpoints and the various bp_catch_* eventpoints should not
7034 have their addresses modified. */
7037 else if (bptype
== bp_single_step
)
7039 /* Single-step breakpoints should not have their addresses
7040 modified. If there's any architectural constrain that
7041 applies to this address, then it should have already been
7042 taken into account when the breakpoint was created in the
7043 first place. If we didn't do this, stepping through e.g.,
7044 Thumb-2 IT blocks would break. */
7049 CORE_ADDR adjusted_bpaddr
= bpaddr
;
7051 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
7053 /* Some targets have architectural constraints on the placement
7054 of breakpoint instructions. Obtain the adjusted address. */
7055 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7058 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
7060 /* An adjusted breakpoint address can significantly alter
7061 a user's expectations. Print a warning if an adjustment
7063 if (adjusted_bpaddr
!= bpaddr
)
7064 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7066 return adjusted_bpaddr
;
7071 bp_location_from_bp_type (bptype type
)
7076 case bp_single_step
:
7080 case bp_longjmp_resume
:
7081 case bp_longjmp_call_dummy
:
7083 case bp_exception_resume
:
7084 case bp_step_resume
:
7085 case bp_hp_step_resume
:
7086 case bp_watchpoint_scope
:
7088 case bp_std_terminate
:
7089 case bp_shlib_event
:
7090 case bp_thread_event
:
7091 case bp_overlay_event
:
7093 case bp_longjmp_master
:
7094 case bp_std_terminate_master
:
7095 case bp_exception_master
:
7096 case bp_gnu_ifunc_resolver
:
7097 case bp_gnu_ifunc_resolver_return
:
7099 return bp_loc_software_breakpoint
;
7100 case bp_hardware_breakpoint
:
7101 return bp_loc_hardware_breakpoint
;
7102 case bp_hardware_watchpoint
:
7103 case bp_read_watchpoint
:
7104 case bp_access_watchpoint
:
7105 return bp_loc_hardware_watchpoint
;
7109 case bp_fast_tracepoint
:
7110 case bp_static_tracepoint
:
7111 return bp_loc_other
;
7113 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7117 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7119 this->owner
= owner
;
7120 this->cond_bytecode
= NULL
;
7121 this->shlib_disabled
= 0;
7123 this->disabled_by_cond
= false;
7125 this->loc_type
= type
;
7127 if (this->loc_type
== bp_loc_software_breakpoint
7128 || this->loc_type
== bp_loc_hardware_breakpoint
)
7129 mark_breakpoint_location_modified (this);
7134 bp_location::bp_location (breakpoint
*owner
)
7135 : bp_location::bp_location (owner
,
7136 bp_location_from_bp_type (owner
->type
))
7140 /* Allocate a struct bp_location. */
7142 static struct bp_location
*
7143 allocate_bp_location (struct breakpoint
*bpt
)
7145 return bpt
->ops
->allocate_location (bpt
);
7148 /* Decrement reference count. If the reference count reaches 0,
7149 destroy the bp_location. Sets *BLP to NULL. */
7152 decref_bp_location (struct bp_location
**blp
)
7154 bp_location_ref_policy::decref (*blp
);
7158 /* Add breakpoint B at the end of the global breakpoint chain. */
7161 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7163 struct breakpoint
*b1
;
7164 struct breakpoint
*result
= b
.get ();
7166 /* Add this breakpoint to the end of the chain so that a list of
7167 breakpoints will come out in order of increasing numbers. */
7169 b1
= breakpoint_chain
;
7171 breakpoint_chain
= b
.release ();
7176 b1
->next
= b
.release ();
7182 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7185 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7186 struct gdbarch
*gdbarch
,
7188 const struct breakpoint_ops
*ops
)
7190 gdb_assert (ops
!= NULL
);
7194 b
->gdbarch
= gdbarch
;
7195 b
->language
= current_language
->la_language
;
7196 b
->input_radix
= input_radix
;
7197 b
->related_breakpoint
= b
;
7200 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7201 that has type BPTYPE and has no locations as yet. */
7203 static struct breakpoint
*
7204 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7206 const struct breakpoint_ops
*ops
)
7208 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7210 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7211 return add_to_breakpoint_chain (std::move (b
));
7214 /* Initialize loc->function_name. */
7217 set_breakpoint_location_function (struct bp_location
*loc
)
7219 gdb_assert (loc
->owner
!= NULL
);
7221 if (loc
->owner
->type
== bp_breakpoint
7222 || loc
->owner
->type
== bp_hardware_breakpoint
7223 || is_tracepoint (loc
->owner
))
7225 const char *function_name
;
7227 if (loc
->msymbol
!= NULL
7228 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7229 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7231 struct breakpoint
*b
= loc
->owner
;
7233 function_name
= loc
->msymbol
->linkage_name ();
7235 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7236 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7238 /* Create only the whole new breakpoint of this type but do not
7239 mess more complicated breakpoints with multiple locations. */
7240 b
->type
= bp_gnu_ifunc_resolver
;
7241 /* Remember the resolver's address for use by the return
7243 loc
->related_address
= loc
->address
;
7247 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7250 loc
->function_name
= xstrdup (function_name
);
7254 /* Attempt to determine architecture of location identified by SAL. */
7256 get_sal_arch (struct symtab_and_line sal
)
7259 return sal
.section
->objfile
->arch ();
7261 return SYMTAB_OBJFILE (sal
.symtab
)->arch ();
7266 /* Low level routine for partially initializing a breakpoint of type
7267 BPTYPE. The newly created breakpoint's address, section, source
7268 file name, and line number are provided by SAL.
7270 It is expected that the caller will complete the initialization of
7271 the newly created breakpoint struct as well as output any status
7272 information regarding the creation of a new breakpoint. */
7275 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7276 struct symtab_and_line sal
, enum bptype bptype
,
7277 const struct breakpoint_ops
*ops
)
7279 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7281 add_location_to_breakpoint (b
, &sal
);
7283 if (bptype
!= bp_catchpoint
)
7284 gdb_assert (sal
.pspace
!= NULL
);
7286 /* Store the program space that was used to set the breakpoint,
7287 except for ordinary breakpoints, which are independent of the
7289 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7290 b
->pspace
= sal
.pspace
;
7293 /* set_raw_breakpoint is a low level routine for allocating and
7294 partially initializing a breakpoint of type BPTYPE. The newly
7295 created breakpoint's address, section, source file name, and line
7296 number are provided by SAL. The newly created and partially
7297 initialized breakpoint is added to the breakpoint chain and
7298 is also returned as the value of this function.
7300 It is expected that the caller will complete the initialization of
7301 the newly created breakpoint struct as well as output any status
7302 information regarding the creation of a new breakpoint. In
7303 particular, set_raw_breakpoint does NOT set the breakpoint
7304 number! Care should be taken to not allow an error to occur
7305 prior to completing the initialization of the breakpoint. If this
7306 should happen, a bogus breakpoint will be left on the chain. */
7309 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7310 struct symtab_and_line sal
, enum bptype bptype
,
7311 const struct breakpoint_ops
*ops
)
7313 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7315 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7316 return add_to_breakpoint_chain (std::move (b
));
7319 /* Call this routine when stepping and nexting to enable a breakpoint
7320 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7321 initiated the operation. */
7324 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7326 int thread
= tp
->global_num
;
7328 /* To avoid having to rescan all objfile symbols at every step,
7329 we maintain a list of continually-inserted but always disabled
7330 longjmp "master" breakpoints. Here, we simply create momentary
7331 clones of those and enable them for the requested thread. */
7332 for (breakpoint
*b
: all_breakpoints_safe ())
7333 if (b
->pspace
== current_program_space
7334 && (b
->type
== bp_longjmp_master
7335 || b
->type
== bp_exception_master
))
7337 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7338 struct breakpoint
*clone
;
7340 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7341 after their removal. */
7342 clone
= momentary_breakpoint_from_master (b
, type
,
7343 &momentary_breakpoint_ops
, 1);
7344 clone
->thread
= thread
;
7347 tp
->initiating_frame
= frame
;
7350 /* Delete all longjmp breakpoints from THREAD. */
7352 delete_longjmp_breakpoint (int thread
)
7354 for (breakpoint
*b
: all_breakpoints_safe ())
7355 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7357 if (b
->thread
== thread
)
7358 delete_breakpoint (b
);
7363 delete_longjmp_breakpoint_at_next_stop (int thread
)
7365 for (breakpoint
*b
: all_breakpoints_safe ())
7366 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7368 if (b
->thread
== thread
)
7369 b
->disposition
= disp_del_at_next_stop
;
7373 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7374 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7375 pointer to any of them. Return NULL if this system cannot place longjmp
7379 set_longjmp_breakpoint_for_call_dummy (void)
7381 breakpoint
*retval
= nullptr;
7383 for (breakpoint
*b
: all_breakpoints ())
7384 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7386 struct breakpoint
*new_b
;
7388 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7389 &momentary_breakpoint_ops
,
7391 new_b
->thread
= inferior_thread ()->global_num
;
7393 /* Link NEW_B into the chain of RETVAL breakpoints. */
7395 gdb_assert (new_b
->related_breakpoint
== new_b
);
7398 new_b
->related_breakpoint
= retval
;
7399 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7400 retval
= retval
->related_breakpoint
;
7401 retval
->related_breakpoint
= new_b
;
7407 /* Verify all existing dummy frames and their associated breakpoints for
7408 TP. Remove those which can no longer be found in the current frame
7411 You should call this function only at places where it is safe to currently
7412 unwind the whole stack. Failed stack unwind would discard live dummy
7416 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7418 struct breakpoint
*b
, *b_tmp
;
7420 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7421 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7423 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7425 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7426 dummy_b
= dummy_b
->related_breakpoint
;
7427 if (dummy_b
->type
!= bp_call_dummy
7428 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7431 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7433 while (b
->related_breakpoint
!= b
)
7435 if (b_tmp
== b
->related_breakpoint
)
7436 b_tmp
= b
->related_breakpoint
->next
;
7437 delete_breakpoint (b
->related_breakpoint
);
7439 delete_breakpoint (b
);
7444 enable_overlay_breakpoints (void)
7446 for (breakpoint
*b
: all_breakpoints ())
7447 if (b
->type
== bp_overlay_event
)
7449 b
->enable_state
= bp_enabled
;
7450 update_global_location_list (UGLL_MAY_INSERT
);
7451 overlay_events_enabled
= 1;
7456 disable_overlay_breakpoints (void)
7458 for (breakpoint
*b
: all_breakpoints ())
7459 if (b
->type
== bp_overlay_event
)
7461 b
->enable_state
= bp_disabled
;
7462 update_global_location_list (UGLL_DONT_INSERT
);
7463 overlay_events_enabled
= 0;
7467 /* Set an active std::terminate breakpoint for each std::terminate
7468 master breakpoint. */
7470 set_std_terminate_breakpoint (void)
7472 for (breakpoint
*b
: all_breakpoints_safe ())
7473 if (b
->pspace
== current_program_space
7474 && b
->type
== bp_std_terminate_master
)
7476 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7477 &momentary_breakpoint_ops
, 1);
7481 /* Delete all the std::terminate breakpoints. */
7483 delete_std_terminate_breakpoint (void)
7485 for (breakpoint
*b
: all_breakpoints_safe ())
7486 if (b
->type
== bp_std_terminate
)
7487 delete_breakpoint (b
);
7491 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7493 struct breakpoint
*b
;
7495 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7496 &internal_breakpoint_ops
);
7498 b
->enable_state
= bp_enabled
;
7499 /* location has to be used or breakpoint_re_set will delete me. */
7500 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7502 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7507 struct lang_and_radix
7513 /* Create a breakpoint for JIT code registration and unregistration. */
7516 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7518 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7519 &internal_breakpoint_ops
);
7522 /* Remove JIT code registration and unregistration breakpoint(s). */
7525 remove_jit_event_breakpoints (void)
7527 for (breakpoint
*b
: all_breakpoints_safe ())
7528 if (b
->type
== bp_jit_event
7529 && b
->loc
->pspace
== current_program_space
)
7530 delete_breakpoint (b
);
7534 remove_solib_event_breakpoints (void)
7536 for (breakpoint
*b
: all_breakpoints_safe ())
7537 if (b
->type
== bp_shlib_event
7538 && b
->loc
->pspace
== current_program_space
)
7539 delete_breakpoint (b
);
7542 /* See breakpoint.h. */
7545 remove_solib_event_breakpoints_at_next_stop (void)
7547 for (breakpoint
*b
: all_breakpoints_safe ())
7548 if (b
->type
== bp_shlib_event
7549 && b
->loc
->pspace
== current_program_space
)
7550 b
->disposition
= disp_del_at_next_stop
;
7553 /* Helper for create_solib_event_breakpoint /
7554 create_and_insert_solib_event_breakpoint. Allows specifying which
7555 INSERT_MODE to pass through to update_global_location_list. */
7557 static struct breakpoint
*
7558 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7559 enum ugll_insert_mode insert_mode
)
7561 struct breakpoint
*b
;
7563 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7564 &internal_breakpoint_ops
);
7565 update_global_location_list_nothrow (insert_mode
);
7570 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7572 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7575 /* See breakpoint.h. */
7578 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7580 struct breakpoint
*b
;
7582 /* Explicitly tell update_global_location_list to insert
7584 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7585 if (!b
->loc
->inserted
)
7587 delete_breakpoint (b
);
7593 /* Disable any breakpoints that are on code in shared libraries. Only
7594 apply to enabled breakpoints, disabled ones can just stay disabled. */
7597 disable_breakpoints_in_shlibs (void)
7599 for (bp_location
*loc
: all_bp_locations ())
7601 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7602 struct breakpoint
*b
= loc
->owner
;
7604 /* We apply the check to all breakpoints, including disabled for
7605 those with loc->duplicate set. This is so that when breakpoint
7606 becomes enabled, or the duplicate is removed, gdb will try to
7607 insert all breakpoints. If we don't set shlib_disabled here,
7608 we'll try to insert those breakpoints and fail. */
7609 if (((b
->type
== bp_breakpoint
)
7610 || (b
->type
== bp_jit_event
)
7611 || (b
->type
== bp_hardware_breakpoint
)
7612 || (is_tracepoint (b
)))
7613 && loc
->pspace
== current_program_space
7614 && !loc
->shlib_disabled
7615 && solib_name_from_address (loc
->pspace
, loc
->address
)
7618 loc
->shlib_disabled
= 1;
7623 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7624 notification of unloaded_shlib. Only apply to enabled breakpoints,
7625 disabled ones can just stay disabled. */
7628 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7630 int disabled_shlib_breaks
= 0;
7632 for (bp_location
*loc
: all_bp_locations ())
7634 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7635 struct breakpoint
*b
= loc
->owner
;
7637 if (solib
->pspace
== loc
->pspace
7638 && !loc
->shlib_disabled
7639 && (((b
->type
== bp_breakpoint
7640 || b
->type
== bp_jit_event
7641 || b
->type
== bp_hardware_breakpoint
)
7642 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7643 || loc
->loc_type
== bp_loc_software_breakpoint
))
7644 || is_tracepoint (b
))
7645 && solib_contains_address_p (solib
, loc
->address
))
7647 loc
->shlib_disabled
= 1;
7648 /* At this point, we cannot rely on remove_breakpoint
7649 succeeding so we must mark the breakpoint as not inserted
7650 to prevent future errors occurring in remove_breakpoints. */
7653 /* This may cause duplicate notifications for the same breakpoint. */
7654 gdb::observers::breakpoint_modified
.notify (b
);
7656 if (!disabled_shlib_breaks
)
7658 target_terminal::ours_for_output ();
7659 warning (_("Temporarily disabling breakpoints "
7660 "for unloaded shared library \"%s\""),
7663 disabled_shlib_breaks
= 1;
7668 /* Disable any breakpoints and tracepoints in OBJFILE upon
7669 notification of free_objfile. Only apply to enabled breakpoints,
7670 disabled ones can just stay disabled. */
7673 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7675 if (objfile
== NULL
)
7678 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7679 managed by the user with add-symbol-file/remove-symbol-file.
7680 Similarly to how breakpoints in shared libraries are handled in
7681 response to "nosharedlibrary", mark breakpoints in such modules
7682 shlib_disabled so they end up uninserted on the next global
7683 location list update. Shared libraries not loaded by the user
7684 aren't handled here -- they're already handled in
7685 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7686 solib_unloaded observer. We skip objfiles that are not
7687 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7689 if ((objfile
->flags
& OBJF_SHARED
) == 0
7690 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7693 for (breakpoint
*b
: all_breakpoints ())
7695 int bp_modified
= 0;
7697 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7700 for (bp_location
*loc
: b
->locations ())
7702 CORE_ADDR loc_addr
= loc
->address
;
7704 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7705 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7708 if (loc
->shlib_disabled
!= 0)
7711 if (objfile
->pspace
!= loc
->pspace
)
7714 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7715 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7718 if (is_addr_in_objfile (loc_addr
, objfile
))
7720 loc
->shlib_disabled
= 1;
7721 /* At this point, we don't know whether the object was
7722 unmapped from the inferior or not, so leave the
7723 inserted flag alone. We'll handle failure to
7724 uninsert quietly, in case the object was indeed
7727 mark_breakpoint_location_modified (loc
);
7734 gdb::observers::breakpoint_modified
.notify (b
);
7738 /* FORK & VFORK catchpoints. */
7740 /* An instance of this type is used to represent a fork or vfork
7741 catchpoint. A breakpoint is really of this type iff its ops pointer points
7742 to CATCH_FORK_BREAKPOINT_OPS. */
7744 struct fork_catchpoint
: public breakpoint
7746 /* Process id of a child process whose forking triggered this
7747 catchpoint. This field is only valid immediately after this
7748 catchpoint has triggered. */
7749 ptid_t forked_inferior_pid
;
7752 /* Implement the "insert" breakpoint_ops method for fork
7756 insert_catch_fork (struct bp_location
*bl
)
7758 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7761 /* Implement the "remove" breakpoint_ops method for fork
7765 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7767 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7770 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7774 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7775 const address_space
*aspace
, CORE_ADDR bp_addr
,
7776 const struct target_waitstatus
*ws
)
7778 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7780 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7783 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7787 /* Implement the "print_it" breakpoint_ops method for fork
7790 static enum print_stop_action
7791 print_it_catch_fork (bpstat bs
)
7793 struct ui_out
*uiout
= current_uiout
;
7794 struct breakpoint
*b
= bs
->breakpoint_at
;
7795 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7797 annotate_catchpoint (b
->number
);
7798 maybe_print_thread_hit_breakpoint (uiout
);
7799 if (b
->disposition
== disp_del
)
7800 uiout
->text ("Temporary catchpoint ");
7802 uiout
->text ("Catchpoint ");
7803 if (uiout
->is_mi_like_p ())
7805 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7806 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7808 uiout
->field_signed ("bkptno", b
->number
);
7809 uiout
->text (" (forked process ");
7810 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7811 uiout
->text ("), ");
7812 return PRINT_SRC_AND_LOC
;
7815 /* Implement the "print_one" breakpoint_ops method for fork
7819 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7821 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7822 struct value_print_options opts
;
7823 struct ui_out
*uiout
= current_uiout
;
7825 get_user_print_options (&opts
);
7827 /* Field 4, the address, is omitted (which makes the columns not
7828 line up too nicely with the headers, but the effect is relatively
7830 if (opts
.addressprint
)
7831 uiout
->field_skip ("addr");
7833 uiout
->text ("fork");
7834 if (c
->forked_inferior_pid
!= null_ptid
)
7836 uiout
->text (", process ");
7837 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7841 if (uiout
->is_mi_like_p ())
7842 uiout
->field_string ("catch-type", "fork");
7845 /* Implement the "print_mention" breakpoint_ops method for fork
7849 print_mention_catch_fork (struct breakpoint
*b
)
7851 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7854 /* Implement the "print_recreate" breakpoint_ops method for fork
7858 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7860 fprintf_unfiltered (fp
, "catch fork");
7861 print_recreate_thread (b
, fp
);
7864 /* The breakpoint_ops structure to be used in fork catchpoints. */
7866 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7868 /* Implement the "insert" breakpoint_ops method for vfork
7872 insert_catch_vfork (struct bp_location
*bl
)
7874 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7877 /* Implement the "remove" breakpoint_ops method for vfork
7881 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7883 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7886 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7890 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7891 const address_space
*aspace
, CORE_ADDR bp_addr
,
7892 const struct target_waitstatus
*ws
)
7894 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7896 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7899 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7903 /* Implement the "print_it" breakpoint_ops method for vfork
7906 static enum print_stop_action
7907 print_it_catch_vfork (bpstat bs
)
7909 struct ui_out
*uiout
= current_uiout
;
7910 struct breakpoint
*b
= bs
->breakpoint_at
;
7911 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7913 annotate_catchpoint (b
->number
);
7914 maybe_print_thread_hit_breakpoint (uiout
);
7915 if (b
->disposition
== disp_del
)
7916 uiout
->text ("Temporary catchpoint ");
7918 uiout
->text ("Catchpoint ");
7919 if (uiout
->is_mi_like_p ())
7921 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7922 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7924 uiout
->field_signed ("bkptno", b
->number
);
7925 uiout
->text (" (vforked process ");
7926 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7927 uiout
->text ("), ");
7928 return PRINT_SRC_AND_LOC
;
7931 /* Implement the "print_one" breakpoint_ops method for vfork
7935 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7937 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7938 struct value_print_options opts
;
7939 struct ui_out
*uiout
= current_uiout
;
7941 get_user_print_options (&opts
);
7942 /* Field 4, the address, is omitted (which makes the columns not
7943 line up too nicely with the headers, but the effect is relatively
7945 if (opts
.addressprint
)
7946 uiout
->field_skip ("addr");
7948 uiout
->text ("vfork");
7949 if (c
->forked_inferior_pid
!= null_ptid
)
7951 uiout
->text (", process ");
7952 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7956 if (uiout
->is_mi_like_p ())
7957 uiout
->field_string ("catch-type", "vfork");
7960 /* Implement the "print_mention" breakpoint_ops method for vfork
7964 print_mention_catch_vfork (struct breakpoint
*b
)
7966 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7969 /* Implement the "print_recreate" breakpoint_ops method for vfork
7973 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7975 fprintf_unfiltered (fp
, "catch vfork");
7976 print_recreate_thread (b
, fp
);
7979 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7981 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7983 /* An instance of this type is used to represent an solib catchpoint.
7984 A breakpoint is really of this type iff its ops pointer points to
7985 CATCH_SOLIB_BREAKPOINT_OPS. */
7987 struct solib_catchpoint
: public breakpoint
7989 ~solib_catchpoint () override
;
7991 /* True for "catch load", false for "catch unload". */
7994 /* Regular expression to match, if any. COMPILED is only valid when
7995 REGEX is non-NULL. */
7997 std::unique_ptr
<compiled_regex
> compiled
;
8000 solib_catchpoint::~solib_catchpoint ()
8002 xfree (this->regex
);
8006 insert_catch_solib (struct bp_location
*ignore
)
8012 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8018 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8019 const address_space
*aspace
,
8021 const struct target_waitstatus
*ws
)
8023 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8025 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8028 for (breakpoint
*other
: all_breakpoints ())
8030 if (other
== bl
->owner
)
8033 if (other
->type
!= bp_shlib_event
)
8036 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8039 for (bp_location
*other_bl
: other
->locations ())
8041 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8050 check_status_catch_solib (struct bpstats
*bs
)
8052 struct solib_catchpoint
*self
8053 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8057 for (so_list
*iter
: current_program_space
->added_solibs
)
8060 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8066 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
8069 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
8075 bs
->print_it
= print_it_noop
;
8078 static enum print_stop_action
8079 print_it_catch_solib (bpstat bs
)
8081 struct breakpoint
*b
= bs
->breakpoint_at
;
8082 struct ui_out
*uiout
= current_uiout
;
8084 annotate_catchpoint (b
->number
);
8085 maybe_print_thread_hit_breakpoint (uiout
);
8086 if (b
->disposition
== disp_del
)
8087 uiout
->text ("Temporary catchpoint ");
8089 uiout
->text ("Catchpoint ");
8090 uiout
->field_signed ("bkptno", b
->number
);
8092 if (uiout
->is_mi_like_p ())
8093 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8094 print_solib_event (1);
8095 return PRINT_SRC_AND_LOC
;
8099 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8101 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8102 struct value_print_options opts
;
8103 struct ui_out
*uiout
= current_uiout
;
8105 get_user_print_options (&opts
);
8106 /* Field 4, the address, is omitted (which makes the columns not
8107 line up too nicely with the headers, but the effect is relatively
8109 if (opts
.addressprint
)
8112 uiout
->field_skip ("addr");
8120 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8122 msg
= _("load of library");
8127 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8129 msg
= _("unload of library");
8131 uiout
->field_string ("what", msg
);
8133 if (uiout
->is_mi_like_p ())
8134 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8138 print_mention_catch_solib (struct breakpoint
*b
)
8140 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8142 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8143 self
->is_load
? "load" : "unload");
8147 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8149 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8151 fprintf_unfiltered (fp
, "%s %s",
8152 b
->disposition
== disp_del
? "tcatch" : "catch",
8153 self
->is_load
? "load" : "unload");
8155 fprintf_unfiltered (fp
, " %s", self
->regex
);
8156 fprintf_unfiltered (fp
, "\n");
8159 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8161 /* See breakpoint.h. */
8164 add_solib_catchpoint (const char *arg
, bool is_load
, bool is_temp
, bool enabled
)
8166 struct gdbarch
*gdbarch
= get_current_arch ();
8170 arg
= skip_spaces (arg
);
8172 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8176 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8177 _("Invalid regexp")));
8178 c
->regex
= xstrdup (arg
);
8181 c
->is_load
= is_load
;
8182 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8183 &catch_solib_breakpoint_ops
);
8185 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8187 install_breakpoint (0, std::move (c
), 1);
8190 /* A helper function that does all the work for "catch load" and
8194 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8195 struct cmd_list_element
*command
)
8197 const int enabled
= 1;
8198 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8200 add_solib_catchpoint (arg
, is_load
, temp
, enabled
);
8204 catch_load_command_1 (const char *arg
, int from_tty
,
8205 struct cmd_list_element
*command
)
8207 catch_load_or_unload (arg
, from_tty
, 1, command
);
8211 catch_unload_command_1 (const char *arg
, int from_tty
,
8212 struct cmd_list_element
*command
)
8214 catch_load_or_unload (arg
, from_tty
, 0, command
);
8217 /* See breakpoint.h. */
8220 init_catchpoint (struct breakpoint
*b
,
8221 struct gdbarch
*gdbarch
, bool temp
,
8222 const char *cond_string
,
8223 const struct breakpoint_ops
*ops
)
8225 symtab_and_line sal
;
8226 sal
.pspace
= current_program_space
;
8228 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8230 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8231 b
->disposition
= temp
? disp_del
: disp_donttouch
;
8235 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8237 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8238 set_breakpoint_number (internal
, b
);
8239 if (is_tracepoint (b
))
8240 set_tracepoint_count (breakpoint_count
);
8243 gdb::observers::breakpoint_created
.notify (b
);
8246 update_global_location_list (UGLL_MAY_INSERT
);
8250 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8251 bool temp
, const char *cond_string
,
8252 const struct breakpoint_ops
*ops
)
8254 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8256 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
, ops
);
8258 c
->forked_inferior_pid
= null_ptid
;
8260 install_breakpoint (0, std::move (c
), 1);
8263 /* Exec catchpoints. */
8265 /* An instance of this type is used to represent an exec catchpoint.
8266 A breakpoint is really of this type iff its ops pointer points to
8267 CATCH_EXEC_BREAKPOINT_OPS. */
8269 struct exec_catchpoint
: public breakpoint
8271 ~exec_catchpoint () override
;
8273 /* Filename of a program whose exec triggered this catchpoint.
8274 This field is only valid immediately after this catchpoint has
8276 char *exec_pathname
;
8279 /* Exec catchpoint destructor. */
8281 exec_catchpoint::~exec_catchpoint ()
8283 xfree (this->exec_pathname
);
8287 insert_catch_exec (struct bp_location
*bl
)
8289 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8293 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8295 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8299 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8300 const address_space
*aspace
, CORE_ADDR bp_addr
,
8301 const struct target_waitstatus
*ws
)
8303 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8305 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8308 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8312 static enum print_stop_action
8313 print_it_catch_exec (bpstat bs
)
8315 struct ui_out
*uiout
= current_uiout
;
8316 struct breakpoint
*b
= bs
->breakpoint_at
;
8317 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8319 annotate_catchpoint (b
->number
);
8320 maybe_print_thread_hit_breakpoint (uiout
);
8321 if (b
->disposition
== disp_del
)
8322 uiout
->text ("Temporary catchpoint ");
8324 uiout
->text ("Catchpoint ");
8325 if (uiout
->is_mi_like_p ())
8327 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8328 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8330 uiout
->field_signed ("bkptno", b
->number
);
8331 uiout
->text (" (exec'd ");
8332 uiout
->field_string ("new-exec", c
->exec_pathname
);
8333 uiout
->text ("), ");
8335 return PRINT_SRC_AND_LOC
;
8339 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8341 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8342 struct value_print_options opts
;
8343 struct ui_out
*uiout
= current_uiout
;
8345 get_user_print_options (&opts
);
8347 /* Field 4, the address, is omitted (which makes the columns
8348 not line up too nicely with the headers, but the effect
8349 is relatively readable). */
8350 if (opts
.addressprint
)
8351 uiout
->field_skip ("addr");
8353 uiout
->text ("exec");
8354 if (c
->exec_pathname
!= NULL
)
8356 uiout
->text (", program \"");
8357 uiout
->field_string ("what", c
->exec_pathname
);
8358 uiout
->text ("\" ");
8361 if (uiout
->is_mi_like_p ())
8362 uiout
->field_string ("catch-type", "exec");
8366 print_mention_catch_exec (struct breakpoint
*b
)
8368 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8371 /* Implement the "print_recreate" breakpoint_ops method for exec
8375 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8377 fprintf_unfiltered (fp
, "catch exec");
8378 print_recreate_thread (b
, fp
);
8381 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8384 hw_breakpoint_used_count (void)
8388 for (breakpoint
*b
: all_breakpoints ())
8389 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8390 for (bp_location
*bl
: b
->locations ())
8392 /* Special types of hardware breakpoints may use more than
8394 i
+= b
->ops
->resources_needed (bl
);
8400 /* Returns the resources B would use if it were a hardware
8404 hw_watchpoint_use_count (struct breakpoint
*b
)
8408 if (!breakpoint_enabled (b
))
8411 for (bp_location
*bl
: b
->locations ())
8413 /* Special types of hardware watchpoints may use more than
8415 i
+= b
->ops
->resources_needed (bl
);
8421 /* Returns the sum the used resources of all hardware watchpoints of
8422 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8423 the sum of the used resources of all hardware watchpoints of other
8424 types _not_ TYPE. */
8427 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8428 enum bptype type
, int *other_type_used
)
8432 *other_type_used
= 0;
8433 for (breakpoint
*b
: all_breakpoints ())
8437 if (!breakpoint_enabled (b
))
8440 if (b
->type
== type
)
8441 i
+= hw_watchpoint_use_count (b
);
8442 else if (is_hardware_watchpoint (b
))
8443 *other_type_used
= 1;
8450 disable_watchpoints_before_interactive_call_start (void)
8452 for (breakpoint
*b
: all_breakpoints ())
8453 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8455 b
->enable_state
= bp_call_disabled
;
8456 update_global_location_list (UGLL_DONT_INSERT
);
8461 enable_watchpoints_after_interactive_call_stop (void)
8463 for (breakpoint
*b
: all_breakpoints ())
8464 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8466 b
->enable_state
= bp_enabled
;
8467 update_global_location_list (UGLL_MAY_INSERT
);
8472 disable_breakpoints_before_startup (void)
8474 current_program_space
->executing_startup
= 1;
8475 update_global_location_list (UGLL_DONT_INSERT
);
8479 enable_breakpoints_after_startup (void)
8481 current_program_space
->executing_startup
= 0;
8482 breakpoint_re_set ();
8485 /* Create a new single-step breakpoint for thread THREAD, with no
8488 static struct breakpoint
*
8489 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8491 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8493 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8494 &momentary_breakpoint_ops
);
8496 b
->disposition
= disp_donttouch
;
8497 b
->frame_id
= null_frame_id
;
8500 gdb_assert (b
->thread
!= 0);
8502 return add_to_breakpoint_chain (std::move (b
));
8505 /* Set a momentary breakpoint of type TYPE at address specified by
8506 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8510 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8511 struct frame_id frame_id
, enum bptype type
)
8513 struct breakpoint
*b
;
8515 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8517 gdb_assert (!frame_id_artificial_p (frame_id
));
8519 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8520 b
->enable_state
= bp_enabled
;
8521 b
->disposition
= disp_donttouch
;
8522 b
->frame_id
= frame_id
;
8524 b
->thread
= inferior_thread ()->global_num
;
8526 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8528 return breakpoint_up (b
);
8531 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8532 The new breakpoint will have type TYPE, use OPS as its
8533 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8535 static struct breakpoint
*
8536 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8538 const struct breakpoint_ops
*ops
,
8541 struct breakpoint
*copy
;
8543 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8544 copy
->loc
= allocate_bp_location (copy
);
8545 set_breakpoint_location_function (copy
->loc
);
8547 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8548 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8549 copy
->loc
->address
= orig
->loc
->address
;
8550 copy
->loc
->section
= orig
->loc
->section
;
8551 copy
->loc
->pspace
= orig
->loc
->pspace
;
8552 copy
->loc
->probe
= orig
->loc
->probe
;
8553 copy
->loc
->line_number
= orig
->loc
->line_number
;
8554 copy
->loc
->symtab
= orig
->loc
->symtab
;
8555 copy
->loc
->enabled
= loc_enabled
;
8556 copy
->frame_id
= orig
->frame_id
;
8557 copy
->thread
= orig
->thread
;
8558 copy
->pspace
= orig
->pspace
;
8560 copy
->enable_state
= bp_enabled
;
8561 copy
->disposition
= disp_donttouch
;
8562 copy
->number
= internal_breakpoint_number
--;
8564 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8568 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8572 clone_momentary_breakpoint (struct breakpoint
*orig
)
8574 /* If there's nothing to clone, then return nothing. */
8578 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8582 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8585 struct symtab_and_line sal
;
8587 sal
= find_pc_line (pc
, 0);
8589 sal
.section
= find_pc_overlay (pc
);
8590 sal
.explicit_pc
= 1;
8592 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8596 /* Tell the user we have just set a breakpoint B. */
8599 mention (struct breakpoint
*b
)
8601 b
->ops
->print_mention (b
);
8602 current_uiout
->text ("\n");
8606 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8608 /* Handle "set breakpoint auto-hw on".
8610 If the explicitly specified breakpoint type is not hardware
8611 breakpoint, check the memory map to see whether the breakpoint
8612 address is in read-only memory.
8614 - location type is not hardware breakpoint, memory is read-only.
8615 We change the type of the location to hardware breakpoint.
8617 - location type is hardware breakpoint, memory is read-write. This
8618 means we've previously made the location hardware one, but then the
8619 memory map changed, so we undo.
8623 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8625 if (automatic_hardware_breakpoints
8626 && bl
->owner
->type
!= bp_hardware_breakpoint
8627 && (bl
->loc_type
== bp_loc_software_breakpoint
8628 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8630 /* When breakpoints are removed, remove_breakpoints will use
8631 location types we've just set here, the only possible problem
8632 is that memory map has changed during running program, but
8633 it's not going to work anyway with current gdb. */
8634 mem_region
*mr
= lookup_mem_region (bl
->address
);
8638 enum bp_loc_type new_type
;
8640 if (mr
->attrib
.mode
!= MEM_RW
)
8641 new_type
= bp_loc_hardware_breakpoint
;
8643 new_type
= bp_loc_software_breakpoint
;
8645 if (new_type
!= bl
->loc_type
)
8647 static bool said
= false;
8649 bl
->loc_type
= new_type
;
8652 fprintf_filtered (gdb_stdout
,
8653 _("Note: automatically using "
8654 "hardware breakpoints for "
8655 "read-only addresses.\n"));
8663 static struct bp_location
*
8664 add_location_to_breakpoint (struct breakpoint
*b
,
8665 const struct symtab_and_line
*sal
)
8667 struct bp_location
*loc
, **tmp
;
8668 CORE_ADDR adjusted_address
;
8669 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8671 if (loc_gdbarch
== NULL
)
8672 loc_gdbarch
= b
->gdbarch
;
8674 /* Adjust the breakpoint's address prior to allocating a location.
8675 Once we call allocate_bp_location(), that mostly uninitialized
8676 location will be placed on the location chain. Adjustment of the
8677 breakpoint may cause target_read_memory() to be called and we do
8678 not want its scan of the location chain to find a breakpoint and
8679 location that's only been partially initialized. */
8680 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8683 /* Sort the locations by their ADDRESS. */
8684 loc
= allocate_bp_location (b
);
8685 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8686 tmp
= &((*tmp
)->next
))
8691 loc
->requested_address
= sal
->pc
;
8692 loc
->address
= adjusted_address
;
8693 loc
->pspace
= sal
->pspace
;
8694 loc
->probe
.prob
= sal
->prob
;
8695 loc
->probe
.objfile
= sal
->objfile
;
8696 gdb_assert (loc
->pspace
!= NULL
);
8697 loc
->section
= sal
->section
;
8698 loc
->gdbarch
= loc_gdbarch
;
8699 loc
->line_number
= sal
->line
;
8700 loc
->symtab
= sal
->symtab
;
8701 loc
->symbol
= sal
->symbol
;
8702 loc
->msymbol
= sal
->msymbol
;
8703 loc
->objfile
= sal
->objfile
;
8705 set_breakpoint_location_function (loc
);
8707 /* While by definition, permanent breakpoints are already present in the
8708 code, we don't mark the location as inserted. Normally one would expect
8709 that GDB could rely on that breakpoint instruction to stop the program,
8710 thus removing the need to insert its own breakpoint, except that executing
8711 the breakpoint instruction can kill the target instead of reporting a
8712 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8713 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8714 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8715 breakpoint be inserted normally results in QEMU knowing about the GDB
8716 breakpoint, and thus trap before the breakpoint instruction is executed.
8717 (If GDB later needs to continue execution past the permanent breakpoint,
8718 it manually increments the PC, thus avoiding executing the breakpoint
8720 if (bp_loc_is_permanent (loc
))
8727 /* Return true if LOC is pointing to a permanent breakpoint,
8728 return false otherwise. */
8731 bp_loc_is_permanent (struct bp_location
*loc
)
8733 gdb_assert (loc
!= NULL
);
8735 /* If we have a non-breakpoint-backed catchpoint or a software
8736 watchpoint, just return 0. We should not attempt to read from
8737 the addresses the locations of these breakpoint types point to.
8738 gdbarch_program_breakpoint_here_p, below, will attempt to read
8740 if (!bl_address_is_meaningful (loc
))
8743 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8744 switch_to_program_space_and_thread (loc
->pspace
);
8745 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8748 /* Build a command list for the dprintf corresponding to the current
8749 settings of the dprintf style options. */
8752 update_dprintf_command_list (struct breakpoint
*b
)
8754 char *dprintf_args
= b
->extra_string
;
8755 char *printf_line
= NULL
;
8760 dprintf_args
= skip_spaces (dprintf_args
);
8762 /* Allow a comma, as it may have terminated a location, but don't
8764 if (*dprintf_args
== ',')
8766 dprintf_args
= skip_spaces (dprintf_args
);
8768 if (*dprintf_args
!= '"')
8769 error (_("Bad format string, missing '\"'."));
8771 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8772 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8773 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8775 if (!dprintf_function
)
8776 error (_("No function supplied for dprintf call"));
8778 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8779 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8784 printf_line
= xstrprintf ("call (void) %s (%s)",
8788 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8790 if (target_can_run_breakpoint_commands ())
8791 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8794 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8795 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8799 internal_error (__FILE__
, __LINE__
,
8800 _("Invalid dprintf style."));
8802 gdb_assert (printf_line
!= NULL
);
8804 /* Manufacture a printf sequence. */
8805 struct command_line
*printf_cmd_line
8806 = new struct command_line (simple_control
, printf_line
);
8807 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8808 command_lines_deleter ()));
8811 /* Update all dprintf commands, making their command lists reflect
8812 current style settings. */
8815 update_dprintf_commands (const char *args
, int from_tty
,
8816 struct cmd_list_element
*c
)
8818 for (breakpoint
*b
: all_breakpoints ())
8819 if (b
->type
== bp_dprintf
)
8820 update_dprintf_command_list (b
);
8823 /* Create a breakpoint with SAL as location. Use LOCATION
8824 as a description of the location, and COND_STRING
8825 as condition expression. If LOCATION is NULL then create an
8826 "address location" from the address in the SAL. */
8829 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8830 gdb::array_view
<const symtab_and_line
> sals
,
8831 event_location_up
&&location
,
8832 gdb::unique_xmalloc_ptr
<char> filter
,
8833 gdb::unique_xmalloc_ptr
<char> cond_string
,
8834 gdb::unique_xmalloc_ptr
<char> extra_string
,
8835 enum bptype type
, enum bpdisp disposition
,
8836 int thread
, int task
, int ignore_count
,
8837 const struct breakpoint_ops
*ops
, int from_tty
,
8838 int enabled
, int internal
, unsigned flags
,
8839 int display_canonical
)
8843 if (type
== bp_hardware_breakpoint
)
8845 int target_resources_ok
;
8847 i
= hw_breakpoint_used_count ();
8848 target_resources_ok
=
8849 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8851 if (target_resources_ok
== 0)
8852 error (_("No hardware breakpoint support in the target."));
8853 else if (target_resources_ok
< 0)
8854 error (_("Hardware breakpoints used exceeds limit."));
8857 gdb_assert (!sals
.empty ());
8859 for (const auto &sal
: sals
)
8861 struct bp_location
*loc
;
8865 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8867 loc_gdbarch
= gdbarch
;
8869 describe_other_breakpoints (loc_gdbarch
,
8870 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8873 if (&sal
== &sals
[0])
8875 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8879 b
->cond_string
= cond_string
.release ();
8880 b
->extra_string
= extra_string
.release ();
8881 b
->ignore_count
= ignore_count
;
8882 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8883 b
->disposition
= disposition
;
8885 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8886 b
->loc
->inserted
= 1;
8888 if (type
== bp_static_tracepoint
)
8890 struct tracepoint
*t
= (struct tracepoint
*) b
;
8891 struct static_tracepoint_marker marker
;
8893 if (strace_marker_p (b
))
8895 /* We already know the marker exists, otherwise, we
8896 wouldn't see a sal for it. */
8898 = &event_location_to_string (b
->location
.get ())[3];
8901 p
= skip_spaces (p
);
8903 endp
= skip_to_space (p
);
8905 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8907 printf_filtered (_("Probed static tracepoint "
8909 t
->static_trace_marker_id
.c_str ());
8911 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8913 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8915 printf_filtered (_("Probed static tracepoint "
8917 t
->static_trace_marker_id
.c_str ());
8920 warning (_("Couldn't determine the static "
8921 "tracepoint marker to probe"));
8928 loc
= add_location_to_breakpoint (b
, &sal
);
8929 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8933 /* Do not set breakpoint locations conditions yet. As locations
8934 are inserted, they get sorted based on their addresses. Let
8935 the list stabilize to have reliable location numbers. */
8937 /* Dynamic printf requires and uses additional arguments on the
8938 command line, otherwise it's an error. */
8939 if (type
== bp_dprintf
)
8941 if (b
->extra_string
)
8942 update_dprintf_command_list (b
);
8944 error (_("Format string required"));
8946 else if (b
->extra_string
)
8947 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8951 /* The order of the locations is now stable. Set the location
8952 condition using the location's number. */
8954 for (bp_location
*loc
: b
->locations ())
8956 if (b
->cond_string
!= nullptr)
8957 set_breakpoint_location_condition (b
->cond_string
, loc
, b
->number
,
8963 b
->display_canonical
= display_canonical
;
8964 if (location
!= NULL
)
8965 b
->location
= std::move (location
);
8967 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8968 b
->filter
= std::move (filter
);
8972 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8973 gdb::array_view
<const symtab_and_line
> sals
,
8974 event_location_up
&&location
,
8975 gdb::unique_xmalloc_ptr
<char> filter
,
8976 gdb::unique_xmalloc_ptr
<char> cond_string
,
8977 gdb::unique_xmalloc_ptr
<char> extra_string
,
8978 enum bptype type
, enum bpdisp disposition
,
8979 int thread
, int task
, int ignore_count
,
8980 const struct breakpoint_ops
*ops
, int from_tty
,
8981 int enabled
, int internal
, unsigned flags
,
8982 int display_canonical
)
8984 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8986 init_breakpoint_sal (b
.get (), gdbarch
,
8987 sals
, std::move (location
),
8989 std::move (cond_string
),
8990 std::move (extra_string
),
8992 thread
, task
, ignore_count
,
8994 enabled
, internal
, flags
,
8997 install_breakpoint (internal
, std::move (b
), 0);
9000 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9001 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9002 value. COND_STRING, if not NULL, specified the condition to be
9003 used for all breakpoints. Essentially the only case where
9004 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9005 function. In that case, it's still not possible to specify
9006 separate conditions for different overloaded functions, so
9007 we take just a single condition string.
9009 NOTE: If the function succeeds, the caller is expected to cleanup
9010 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9011 array contents). If the function fails (error() is called), the
9012 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9013 COND and SALS arrays and each of those arrays contents. */
9016 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9017 struct linespec_result
*canonical
,
9018 gdb::unique_xmalloc_ptr
<char> cond_string
,
9019 gdb::unique_xmalloc_ptr
<char> extra_string
,
9020 enum bptype type
, enum bpdisp disposition
,
9021 int thread
, int task
, int ignore_count
,
9022 const struct breakpoint_ops
*ops
, int from_tty
,
9023 int enabled
, int internal
, unsigned flags
)
9025 if (canonical
->pre_expanded
)
9026 gdb_assert (canonical
->lsals
.size () == 1);
9028 for (const auto &lsal
: canonical
->lsals
)
9030 /* Note that 'location' can be NULL in the case of a plain
9031 'break', without arguments. */
9032 event_location_up location
9033 = (canonical
->location
!= NULL
9034 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9035 gdb::unique_xmalloc_ptr
<char> filter_string
9036 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9038 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9039 std::move (location
),
9040 std::move (filter_string
),
9041 std::move (cond_string
),
9042 std::move (extra_string
),
9044 thread
, task
, ignore_count
, ops
,
9045 from_tty
, enabled
, internal
, flags
,
9046 canonical
->special_display
);
9050 /* Parse LOCATION which is assumed to be a SAL specification possibly
9051 followed by conditionals. On return, SALS contains an array of SAL
9052 addresses found. LOCATION points to the end of the SAL (for
9053 linespec locations).
9055 The array and the line spec strings are allocated on the heap, it is
9056 the caller's responsibility to free them. */
9059 parse_breakpoint_sals (struct event_location
*location
,
9060 struct linespec_result
*canonical
)
9062 struct symtab_and_line cursal
;
9064 if (event_location_type (location
) == LINESPEC_LOCATION
)
9066 const char *spec
= get_linespec_location (location
)->spec_string
;
9070 /* The last displayed codepoint, if it's valid, is our default
9071 breakpoint address. */
9072 if (last_displayed_sal_is_valid ())
9074 /* Set sal's pspace, pc, symtab, and line to the values
9075 corresponding to the last call to print_frame_info.
9076 Be sure to reinitialize LINE with NOTCURRENT == 0
9077 as the breakpoint line number is inappropriate otherwise.
9078 find_pc_line would adjust PC, re-set it back. */
9079 symtab_and_line sal
= get_last_displayed_sal ();
9080 CORE_ADDR pc
= sal
.pc
;
9082 sal
= find_pc_line (pc
, 0);
9084 /* "break" without arguments is equivalent to "break *PC"
9085 where PC is the last displayed codepoint's address. So
9086 make sure to set sal.explicit_pc to prevent GDB from
9087 trying to expand the list of sals to include all other
9088 instances with the same symtab and line. */
9090 sal
.explicit_pc
= 1;
9092 struct linespec_sals lsal
;
9094 lsal
.canonical
= NULL
;
9096 canonical
->lsals
.push_back (std::move (lsal
));
9100 error (_("No default breakpoint address now."));
9104 /* Force almost all breakpoints to be in terms of the
9105 current_source_symtab (which is decode_line_1's default).
9106 This should produce the results we want almost all of the
9107 time while leaving default_breakpoint_* alone.
9109 ObjC: However, don't match an Objective-C method name which
9110 may have a '+' or '-' succeeded by a '['. */
9111 cursal
= get_current_source_symtab_and_line ();
9112 if (last_displayed_sal_is_valid ())
9114 const char *spec
= NULL
;
9116 if (event_location_type (location
) == LINESPEC_LOCATION
)
9117 spec
= get_linespec_location (location
)->spec_string
;
9121 && strchr ("+-", spec
[0]) != NULL
9124 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9125 get_last_displayed_symtab (),
9126 get_last_displayed_line (),
9127 canonical
, NULL
, NULL
);
9132 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9133 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9137 /* Convert each SAL into a real PC. Verify that the PC can be
9138 inserted as a breakpoint. If it can't throw an error. */
9141 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9143 for (auto &sal
: sals
)
9144 resolve_sal_pc (&sal
);
9147 /* Fast tracepoints may have restrictions on valid locations. For
9148 instance, a fast tracepoint using a jump instead of a trap will
9149 likely have to overwrite more bytes than a trap would, and so can
9150 only be placed where the instruction is longer than the jump, or a
9151 multi-instruction sequence does not have a jump into the middle of
9155 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9156 gdb::array_view
<const symtab_and_line
> sals
)
9158 for (const auto &sal
: sals
)
9160 struct gdbarch
*sarch
;
9162 sarch
= get_sal_arch (sal
);
9163 /* We fall back to GDBARCH if there is no architecture
9164 associated with SAL. */
9168 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9169 error (_("May not have a fast tracepoint at %s%s"),
9170 paddress (sarch
, sal
.pc
), msg
.c_str ());
9174 /* Given TOK, a string specification of condition and thread, as
9175 accepted by the 'break' command, extract the condition
9176 string and thread number and set *COND_STRING and *THREAD.
9177 PC identifies the context at which the condition should be parsed.
9178 If no condition is found, *COND_STRING is set to NULL.
9179 If no thread is found, *THREAD is set to -1. */
9182 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9183 char **cond_string
, int *thread
, int *task
,
9186 *cond_string
= NULL
;
9194 const char *end_tok
;
9196 const char *cond_start
= NULL
;
9197 const char *cond_end
= NULL
;
9199 tok
= skip_spaces (tok
);
9201 if ((*tok
== '"' || *tok
== ',') && rest
)
9203 *rest
= savestring (tok
, strlen (tok
));
9207 end_tok
= skip_to_space (tok
);
9209 toklen
= end_tok
- tok
;
9211 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9213 tok
= cond_start
= end_tok
+ 1;
9216 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9218 catch (const gdb_exception_error
&)
9223 tok
= tok
+ strlen (tok
);
9226 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9228 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
9233 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9236 struct thread_info
*thr
;
9239 thr
= parse_thread_id (tok
, &tmptok
);
9241 error (_("Junk after thread keyword."));
9242 *thread
= thr
->global_num
;
9245 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9250 *task
= strtol (tok
, &tmptok
, 0);
9252 error (_("Junk after task keyword."));
9253 if (!valid_task_id (*task
))
9254 error (_("Unknown task %d."), *task
);
9259 *rest
= savestring (tok
, strlen (tok
));
9263 error (_("Junk at end of arguments."));
9267 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
9268 succeeds. The parsed values are written to COND_STRING, THREAD,
9269 TASK, and REST. See the comment of 'find_condition_and_thread'
9270 for the description of these parameters and INPUT. */
9273 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
9274 const char *input
, char **cond_string
,
9275 int *thread
, int *task
, char **rest
)
9277 int num_failures
= 0;
9278 for (auto &sal
: sals
)
9280 char *cond
= nullptr;
9283 char *remaining
= nullptr;
9285 /* Here we want to parse 'arg' to separate condition from thread
9286 number. But because parsing happens in a context and the
9287 contexts of sals might be different, try each until there is
9288 success. Finding one successful parse is sufficient for our
9289 goal. When setting the breakpoint we'll re-parse the
9290 condition in the context of each sal. */
9293 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
9294 &task_id
, &remaining
);
9295 *cond_string
= cond
;
9296 *thread
= thread_id
;
9301 catch (const gdb_exception_error
&e
)
9304 /* If no sal remains, do not continue. */
9305 if (num_failures
== sals
.size ())
9311 /* Decode a static tracepoint marker spec. */
9313 static std::vector
<symtab_and_line
>
9314 decode_static_tracepoint_spec (const char **arg_p
)
9316 const char *p
= &(*arg_p
)[3];
9319 p
= skip_spaces (p
);
9321 endp
= skip_to_space (p
);
9323 std::string
marker_str (p
, endp
- p
);
9325 std::vector
<static_tracepoint_marker
> markers
9326 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9327 if (markers
.empty ())
9328 error (_("No known static tracepoint marker named %s"),
9329 marker_str
.c_str ());
9331 std::vector
<symtab_and_line
> sals
;
9332 sals
.reserve (markers
.size ());
9334 for (const static_tracepoint_marker
&marker
: markers
)
9336 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9337 sal
.pc
= marker
.address
;
9338 sals
.push_back (sal
);
9345 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9346 according to IS_TRACEPOINT. */
9348 static const struct breakpoint_ops
*
9349 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
9354 if (location_type
== PROBE_LOCATION
)
9355 return &tracepoint_probe_breakpoint_ops
;
9357 return &tracepoint_breakpoint_ops
;
9361 if (location_type
== PROBE_LOCATION
)
9362 return &bkpt_probe_breakpoint_ops
;
9364 return &bkpt_breakpoint_ops
;
9368 /* See breakpoint.h. */
9370 const struct breakpoint_ops
*
9371 breakpoint_ops_for_event_location (const struct event_location
*location
,
9374 if (location
!= nullptr)
9375 return breakpoint_ops_for_event_location_type
9376 (event_location_type (location
), is_tracepoint
);
9377 return is_tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
9380 /* See breakpoint.h. */
9383 create_breakpoint (struct gdbarch
*gdbarch
,
9384 struct event_location
*location
,
9385 const char *cond_string
,
9386 int thread
, const char *extra_string
,
9387 bool force_condition
, int parse_extra
,
9388 int tempflag
, enum bptype type_wanted
,
9390 enum auto_boolean pending_break_support
,
9391 const struct breakpoint_ops
*ops
,
9392 int from_tty
, int enabled
, int internal
,
9395 struct linespec_result canonical
;
9398 int prev_bkpt_count
= breakpoint_count
;
9400 gdb_assert (ops
!= NULL
);
9402 /* If extra_string isn't useful, set it to NULL. */
9403 if (extra_string
!= NULL
&& *extra_string
== '\0')
9404 extra_string
= NULL
;
9408 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9410 catch (const gdb_exception_error
&e
)
9412 /* If caller is interested in rc value from parse, set
9414 if (e
.error
== NOT_FOUND_ERROR
)
9416 /* If pending breakpoint support is turned off, throw
9419 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9422 exception_print (gdb_stderr
, e
);
9424 /* If pending breakpoint support is auto query and the user
9425 selects no, then simply return the error code. */
9426 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9427 && !nquery (_("Make %s pending on future shared library load? "),
9428 bptype_string (type_wanted
)))
9431 /* At this point, either the user was queried about setting
9432 a pending breakpoint and selected yes, or pending
9433 breakpoint behavior is on and thus a pending breakpoint
9434 is defaulted on behalf of the user. */
9441 if (!pending
&& canonical
.lsals
.empty ())
9444 /* Resolve all line numbers to PC's and verify that the addresses
9445 are ok for the target. */
9448 for (auto &lsal
: canonical
.lsals
)
9449 breakpoint_sals_to_pc (lsal
.sals
);
9452 /* Fast tracepoints may have additional restrictions on location. */
9453 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9455 for (const auto &lsal
: canonical
.lsals
)
9456 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9459 /* Verify that condition can be parsed, before setting any
9460 breakpoints. Allocate a separate condition expression for each
9464 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9465 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9472 const linespec_sals
&lsal
= canonical
.lsals
[0];
9474 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9475 &cond
, &thread
, &task
, &rest
);
9476 cond_string_copy
.reset (cond
);
9477 extra_string_copy
.reset (rest
);
9481 if (type_wanted
!= bp_dprintf
9482 && extra_string
!= NULL
&& *extra_string
!= '\0')
9483 error (_("Garbage '%s' at end of location"), extra_string
);
9485 /* Check the validity of the condition. We should error out
9486 if the condition is invalid at all of the locations and
9487 if it is not forced. In the PARSE_EXTRA case above, this
9488 check is done when parsing the EXTRA_STRING. */
9489 if (cond_string
!= nullptr && !force_condition
)
9491 int num_failures
= 0;
9492 const linespec_sals
&lsal
= canonical
.lsals
[0];
9493 for (const auto &sal
: lsal
.sals
)
9495 const char *cond
= cond_string
;
9498 parse_exp_1 (&cond
, sal
.pc
, block_for_pc (sal
.pc
), 0);
9499 /* One success is sufficient to keep going. */
9502 catch (const gdb_exception_error
&)
9505 /* If this is the last sal, error out. */
9506 if (num_failures
== lsal
.sals
.size ())
9512 /* Create a private copy of condition string. */
9514 cond_string_copy
.reset (xstrdup (cond_string
));
9515 /* Create a private copy of any extra string. */
9517 extra_string_copy
.reset (xstrdup (extra_string
));
9520 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9521 std::move (cond_string_copy
),
9522 std::move (extra_string_copy
),
9524 tempflag
? disp_del
: disp_donttouch
,
9525 thread
, task
, ignore_count
, ops
,
9526 from_tty
, enabled
, internal
, flags
);
9530 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9532 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9533 b
->location
= copy_event_location (location
);
9536 b
->cond_string
= NULL
;
9539 /* Create a private copy of condition string. */
9540 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9544 /* Create a private copy of any extra string. */
9545 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9546 b
->ignore_count
= ignore_count
;
9547 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9548 b
->condition_not_parsed
= 1;
9549 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9550 if ((type_wanted
!= bp_breakpoint
9551 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9552 b
->pspace
= current_program_space
;
9554 install_breakpoint (internal
, std::move (b
), 0);
9557 if (canonical
.lsals
.size () > 1)
9559 warning (_("Multiple breakpoints were set.\nUse the "
9560 "\"delete\" command to delete unwanted breakpoints."));
9561 prev_breakpoint_count
= prev_bkpt_count
;
9564 update_global_location_list (UGLL_MAY_INSERT
);
9569 /* Set a breakpoint.
9570 ARG is a string describing breakpoint address,
9571 condition, and thread.
9572 FLAG specifies if a breakpoint is hardware on,
9573 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9577 break_command_1 (const char *arg
, int flag
, int from_tty
)
9579 int tempflag
= flag
& BP_TEMPFLAG
;
9580 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9581 ? bp_hardware_breakpoint
9584 event_location_up location
= string_to_event_location (&arg
, current_language
);
9585 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9586 (location
.get (), false /* is_tracepoint */);
9588 create_breakpoint (get_current_arch (),
9590 NULL
, 0, arg
, false, 1 /* parse arg */,
9591 tempflag
, type_wanted
,
9592 0 /* Ignore count */,
9593 pending_break_support
,
9601 /* Helper function for break_command_1 and disassemble_command. */
9604 resolve_sal_pc (struct symtab_and_line
*sal
)
9608 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9610 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9611 error (_("No line %d in file \"%s\"."),
9612 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9615 /* If this SAL corresponds to a breakpoint inserted using a line
9616 number, then skip the function prologue if necessary. */
9617 if (sal
->explicit_line
)
9618 skip_prologue_sal (sal
);
9621 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9623 const struct blockvector
*bv
;
9624 const struct block
*b
;
9627 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9628 SYMTAB_COMPUNIT (sal
->symtab
));
9631 sym
= block_linkage_function (b
);
9634 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9635 sal
->section
= sym
->obj_section (SYMTAB_OBJFILE (sal
->symtab
));
9639 /* It really is worthwhile to have the section, so we'll
9640 just have to look harder. This case can be executed
9641 if we have line numbers but no functions (as can
9642 happen in assembly source). */
9644 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9645 switch_to_program_space_and_thread (sal
->pspace
);
9647 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9649 sal
->section
= msym
.obj_section ();
9656 break_command (const char *arg
, int from_tty
)
9658 break_command_1 (arg
, 0, from_tty
);
9662 tbreak_command (const char *arg
, int from_tty
)
9664 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9668 hbreak_command (const char *arg
, int from_tty
)
9670 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9674 thbreak_command (const char *arg
, int from_tty
)
9676 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9680 stop_command (const char *arg
, int from_tty
)
9682 printf_filtered (_("Specify the type of breakpoint to set.\n\
9683 Usage: stop in <function | address>\n\
9684 stop at <line>\n"));
9688 stopin_command (const char *arg
, int from_tty
)
9694 else if (*arg
!= '*')
9696 const char *argptr
= arg
;
9699 /* Look for a ':'. If this is a line number specification, then
9700 say it is bad, otherwise, it should be an address or
9701 function/method name. */
9702 while (*argptr
&& !hasColon
)
9704 hasColon
= (*argptr
== ':');
9709 badInput
= (*argptr
!= ':'); /* Not a class::method */
9711 badInput
= isdigit (*arg
); /* a simple line number */
9715 printf_filtered (_("Usage: stop in <function | address>\n"));
9717 break_command_1 (arg
, 0, from_tty
);
9721 stopat_command (const char *arg
, int from_tty
)
9725 if (arg
== NULL
|| *arg
== '*') /* no line number */
9729 const char *argptr
= arg
;
9732 /* Look for a ':'. If there is a '::' then get out, otherwise
9733 it is probably a line number. */
9734 while (*argptr
&& !hasColon
)
9736 hasColon
= (*argptr
== ':');
9741 badInput
= (*argptr
== ':'); /* we have class::method */
9743 badInput
= !isdigit (*arg
); /* not a line number */
9747 printf_filtered (_("Usage: stop at LINE\n"));
9749 break_command_1 (arg
, 0, from_tty
);
9752 /* The dynamic printf command is mostly like a regular breakpoint, but
9753 with a prewired command list consisting of a single output command,
9754 built from extra arguments supplied on the dprintf command
9758 dprintf_command (const char *arg
, int from_tty
)
9760 event_location_up location
= string_to_event_location (&arg
, current_language
);
9762 /* If non-NULL, ARG should have been advanced past the location;
9763 the next character must be ','. */
9766 if (arg
[0] != ',' || arg
[1] == '\0')
9767 error (_("Format string required"));
9770 /* Skip the comma. */
9775 create_breakpoint (get_current_arch (),
9777 NULL
, 0, arg
, false, 1 /* parse arg */,
9779 0 /* Ignore count */,
9780 pending_break_support
,
9781 &dprintf_breakpoint_ops
,
9789 agent_printf_command (const char *arg
, int from_tty
)
9791 error (_("May only run agent-printf on the target"));
9794 /* Implement the "breakpoint_hit" breakpoint_ops method for
9795 ranged breakpoints. */
9798 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9799 const address_space
*aspace
,
9801 const struct target_waitstatus
*ws
)
9803 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9804 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9807 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9808 bl
->length
, aspace
, bp_addr
);
9811 /* Implement the "resources_needed" breakpoint_ops method for
9812 ranged breakpoints. */
9815 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9817 return target_ranged_break_num_registers ();
9820 /* Implement the "print_it" breakpoint_ops method for
9821 ranged breakpoints. */
9823 static enum print_stop_action
9824 print_it_ranged_breakpoint (bpstat bs
)
9826 struct breakpoint
*b
= bs
->breakpoint_at
;
9827 struct bp_location
*bl
= b
->loc
;
9828 struct ui_out
*uiout
= current_uiout
;
9830 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9832 /* Ranged breakpoints have only one location. */
9833 gdb_assert (bl
&& bl
->next
== NULL
);
9835 annotate_breakpoint (b
->number
);
9837 maybe_print_thread_hit_breakpoint (uiout
);
9839 if (b
->disposition
== disp_del
)
9840 uiout
->text ("Temporary ranged breakpoint ");
9842 uiout
->text ("Ranged breakpoint ");
9843 if (uiout
->is_mi_like_p ())
9845 uiout
->field_string ("reason",
9846 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9847 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9849 uiout
->field_signed ("bkptno", b
->number
);
9852 return PRINT_SRC_AND_LOC
;
9855 /* Implement the "print_one" breakpoint_ops method for
9856 ranged breakpoints. */
9859 print_one_ranged_breakpoint (struct breakpoint
*b
,
9860 struct bp_location
**last_loc
)
9862 struct bp_location
*bl
= b
->loc
;
9863 struct value_print_options opts
;
9864 struct ui_out
*uiout
= current_uiout
;
9866 /* Ranged breakpoints have only one location. */
9867 gdb_assert (bl
&& bl
->next
== NULL
);
9869 get_user_print_options (&opts
);
9871 if (opts
.addressprint
)
9872 /* We don't print the address range here, it will be printed later
9873 by print_one_detail_ranged_breakpoint. */
9874 uiout
->field_skip ("addr");
9876 print_breakpoint_location (b
, bl
);
9880 /* Implement the "print_one_detail" breakpoint_ops method for
9881 ranged breakpoints. */
9884 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9885 struct ui_out
*uiout
)
9887 CORE_ADDR address_start
, address_end
;
9888 struct bp_location
*bl
= b
->loc
;
9893 address_start
= bl
->address
;
9894 address_end
= address_start
+ bl
->length
- 1;
9896 uiout
->text ("\taddress range: ");
9897 stb
.printf ("[%s, %s]",
9898 print_core_address (bl
->gdbarch
, address_start
),
9899 print_core_address (bl
->gdbarch
, address_end
));
9900 uiout
->field_stream ("addr", stb
);
9904 /* Implement the "print_mention" breakpoint_ops method for
9905 ranged breakpoints. */
9908 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9910 struct bp_location
*bl
= b
->loc
;
9911 struct ui_out
*uiout
= current_uiout
;
9914 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9916 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9917 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9918 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9921 /* Implement the "print_recreate" breakpoint_ops method for
9922 ranged breakpoints. */
9925 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9927 fprintf_unfiltered (fp
, "break-range %s, %s",
9928 event_location_to_string (b
->location
.get ()),
9929 event_location_to_string (b
->location_range_end
.get ()));
9930 print_recreate_thread (b
, fp
);
9933 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9935 static struct breakpoint_ops ranged_breakpoint_ops
;
9937 /* Find the address where the end of the breakpoint range should be
9938 placed, given the SAL of the end of the range. This is so that if
9939 the user provides a line number, the end of the range is set to the
9940 last instruction of the given line. */
9943 find_breakpoint_range_end (struct symtab_and_line sal
)
9947 /* If the user provided a PC value, use it. Otherwise,
9948 find the address of the end of the given location. */
9949 if (sal
.explicit_pc
)
9956 ret
= find_line_pc_range (sal
, &start
, &end
);
9958 error (_("Could not find location of the end of the range."));
9960 /* find_line_pc_range returns the start of the next line. */
9967 /* Implement the "break-range" CLI command. */
9970 break_range_command (const char *arg
, int from_tty
)
9972 const char *arg_start
;
9973 struct linespec_result canonical_start
, canonical_end
;
9974 int bp_count
, can_use_bp
, length
;
9976 struct breakpoint
*b
;
9978 /* We don't support software ranged breakpoints. */
9979 if (target_ranged_break_num_registers () < 0)
9980 error (_("This target does not support hardware ranged breakpoints."));
9982 bp_count
= hw_breakpoint_used_count ();
9983 bp_count
+= target_ranged_break_num_registers ();
9984 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9987 error (_("Hardware breakpoints used exceeds limit."));
9989 arg
= skip_spaces (arg
);
9990 if (arg
== NULL
|| arg
[0] == '\0')
9991 error(_("No address range specified."));
9994 event_location_up start_location
= string_to_event_location (&arg
,
9996 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9999 error (_("Too few arguments."));
10000 else if (canonical_start
.lsals
.empty ())
10001 error (_("Could not find location of the beginning of the range."));
10003 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
10005 if (canonical_start
.lsals
.size () > 1
10006 || lsal_start
.sals
.size () != 1)
10007 error (_("Cannot create a ranged breakpoint with multiple locations."));
10009 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
10010 std::string
addr_string_start (arg_start
, arg
- arg_start
);
10012 arg
++; /* Skip the comma. */
10013 arg
= skip_spaces (arg
);
10015 /* Parse the end location. */
10019 /* We call decode_line_full directly here instead of using
10020 parse_breakpoint_sals because we need to specify the start location's
10021 symtab and line as the default symtab and line for the end of the
10022 range. This makes it possible to have ranges like "foo.c:27, +14",
10023 where +14 means 14 lines from the start location. */
10024 event_location_up end_location
= string_to_event_location (&arg
,
10026 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10027 sal_start
.symtab
, sal_start
.line
,
10028 &canonical_end
, NULL
, NULL
);
10030 if (canonical_end
.lsals
.empty ())
10031 error (_("Could not find location of the end of the range."));
10033 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10034 if (canonical_end
.lsals
.size () > 1
10035 || lsal_end
.sals
.size () != 1)
10036 error (_("Cannot create a ranged breakpoint with multiple locations."));
10038 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10040 end
= find_breakpoint_range_end (sal_end
);
10041 if (sal_start
.pc
> end
)
10042 error (_("Invalid address range, end precedes start."));
10044 length
= end
- sal_start
.pc
+ 1;
10046 /* Length overflowed. */
10047 error (_("Address range too large."));
10048 else if (length
== 1)
10050 /* This range is simple enough to be handled by
10051 the `hbreak' command. */
10052 hbreak_command (&addr_string_start
[0], 1);
10057 /* Now set up the breakpoint. */
10058 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10059 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10060 set_breakpoint_count (breakpoint_count
+ 1);
10061 b
->number
= breakpoint_count
;
10062 b
->disposition
= disp_donttouch
;
10063 b
->location
= std::move (start_location
);
10064 b
->location_range_end
= std::move (end_location
);
10065 b
->loc
->length
= length
;
10068 gdb::observers::breakpoint_created
.notify (b
);
10069 update_global_location_list (UGLL_MAY_INSERT
);
10072 /* Return non-zero if EXP is verified as constant. Returned zero
10073 means EXP is variable. Also the constant detection may fail for
10074 some constant expressions and in such case still falsely return
10078 watchpoint_exp_is_const (const struct expression
*exp
)
10080 return exp
->op
->constant_p ();
10083 /* Watchpoint destructor. */
10085 watchpoint::~watchpoint ()
10087 xfree (this->exp_string
);
10088 xfree (this->exp_string_reparse
);
10091 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10094 re_set_watchpoint (struct breakpoint
*b
)
10096 struct watchpoint
*w
= (struct watchpoint
*) b
;
10098 /* Watchpoint can be either on expression using entirely global
10099 variables, or it can be on local variables.
10101 Watchpoints of the first kind are never auto-deleted, and even
10102 persist across program restarts. Since they can use variables
10103 from shared libraries, we need to reparse expression as libraries
10104 are loaded and unloaded.
10106 Watchpoints on local variables can also change meaning as result
10107 of solib event. For example, if a watchpoint uses both a local
10108 and a global variables in expression, it's a local watchpoint,
10109 but unloading of a shared library will make the expression
10110 invalid. This is not a very common use case, but we still
10111 re-evaluate expression, to avoid surprises to the user.
10113 Note that for local watchpoints, we re-evaluate it only if
10114 watchpoints frame id is still valid. If it's not, it means the
10115 watchpoint is out of scope and will be deleted soon. In fact,
10116 I'm not sure we'll ever be called in this case.
10118 If a local watchpoint's frame id is still valid, then
10119 w->exp_valid_block is likewise valid, and we can safely use it.
10121 Don't do anything about disabled watchpoints, since they will be
10122 reevaluated again when enabled. */
10123 update_watchpoint (w
, 1 /* reparse */);
10126 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10129 insert_watchpoint (struct bp_location
*bl
)
10131 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10132 int length
= w
->exact
? 1 : bl
->length
;
10134 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10135 w
->cond_exp
.get ());
10138 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10141 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10143 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10144 int length
= w
->exact
? 1 : bl
->length
;
10146 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10147 w
->cond_exp
.get ());
10151 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10152 const address_space
*aspace
, CORE_ADDR bp_addr
,
10153 const struct target_waitstatus
*ws
)
10155 struct breakpoint
*b
= bl
->owner
;
10156 struct watchpoint
*w
= (struct watchpoint
*) b
;
10158 /* Continuable hardware watchpoints are treated as non-existent if the
10159 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10160 some data address). Otherwise gdb won't stop on a break instruction
10161 in the code (not from a breakpoint) when a hardware watchpoint has
10162 been defined. Also skip watchpoints which we know did not trigger
10163 (did not match the data address). */
10164 if (is_hardware_watchpoint (b
)
10165 && w
->watchpoint_triggered
== watch_triggered_no
)
10172 check_status_watchpoint (bpstat bs
)
10174 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10176 bpstat_check_watchpoint (bs
);
10179 /* Implement the "resources_needed" breakpoint_ops method for
10180 hardware watchpoints. */
10183 resources_needed_watchpoint (const struct bp_location
*bl
)
10185 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10186 int length
= w
->exact
? 1 : bl
->length
;
10188 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10191 /* Implement the "works_in_software_mode" breakpoint_ops method for
10192 hardware watchpoints. */
10195 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10197 /* Read and access watchpoints only work with hardware support. */
10198 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10201 static enum print_stop_action
10202 print_it_watchpoint (bpstat bs
)
10204 struct breakpoint
*b
;
10205 enum print_stop_action result
;
10206 struct watchpoint
*w
;
10207 struct ui_out
*uiout
= current_uiout
;
10209 gdb_assert (bs
->bp_location_at
!= NULL
);
10211 b
= bs
->breakpoint_at
;
10212 w
= (struct watchpoint
*) b
;
10214 annotate_watchpoint (b
->number
);
10215 maybe_print_thread_hit_breakpoint (uiout
);
10219 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10222 case bp_watchpoint
:
10223 case bp_hardware_watchpoint
:
10224 if (uiout
->is_mi_like_p ())
10225 uiout
->field_string
10226 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10228 tuple_emitter
.emplace (uiout
, "value");
10229 uiout
->text ("\nOld value = ");
10230 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10231 uiout
->field_stream ("old", stb
);
10232 uiout
->text ("\nNew value = ");
10233 watchpoint_value_print (w
->val
.get (), &stb
);
10234 uiout
->field_stream ("new", stb
);
10235 uiout
->text ("\n");
10236 /* More than one watchpoint may have been triggered. */
10237 result
= PRINT_UNKNOWN
;
10240 case bp_read_watchpoint
:
10241 if (uiout
->is_mi_like_p ())
10242 uiout
->field_string
10243 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10245 tuple_emitter
.emplace (uiout
, "value");
10246 uiout
->text ("\nValue = ");
10247 watchpoint_value_print (w
->val
.get (), &stb
);
10248 uiout
->field_stream ("value", stb
);
10249 uiout
->text ("\n");
10250 result
= PRINT_UNKNOWN
;
10253 case bp_access_watchpoint
:
10254 if (bs
->old_val
!= NULL
)
10256 if (uiout
->is_mi_like_p ())
10257 uiout
->field_string
10259 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10261 tuple_emitter
.emplace (uiout
, "value");
10262 uiout
->text ("\nOld value = ");
10263 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10264 uiout
->field_stream ("old", stb
);
10265 uiout
->text ("\nNew value = ");
10270 if (uiout
->is_mi_like_p ())
10271 uiout
->field_string
10273 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10274 tuple_emitter
.emplace (uiout
, "value");
10275 uiout
->text ("\nValue = ");
10277 watchpoint_value_print (w
->val
.get (), &stb
);
10278 uiout
->field_stream ("new", stb
);
10279 uiout
->text ("\n");
10280 result
= PRINT_UNKNOWN
;
10283 result
= PRINT_UNKNOWN
;
10289 /* Implement the "print_mention" breakpoint_ops method for hardware
10293 print_mention_watchpoint (struct breakpoint
*b
)
10295 struct watchpoint
*w
= (struct watchpoint
*) b
;
10296 struct ui_out
*uiout
= current_uiout
;
10297 const char *tuple_name
;
10301 case bp_watchpoint
:
10302 uiout
->text ("Watchpoint ");
10303 tuple_name
= "wpt";
10305 case bp_hardware_watchpoint
:
10306 uiout
->text ("Hardware watchpoint ");
10307 tuple_name
= "wpt";
10309 case bp_read_watchpoint
:
10310 uiout
->text ("Hardware read watchpoint ");
10311 tuple_name
= "hw-rwpt";
10313 case bp_access_watchpoint
:
10314 uiout
->text ("Hardware access (read/write) watchpoint ");
10315 tuple_name
= "hw-awpt";
10318 internal_error (__FILE__
, __LINE__
,
10319 _("Invalid hardware watchpoint type."));
10322 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10323 uiout
->field_signed ("number", b
->number
);
10324 uiout
->text (": ");
10325 uiout
->field_string ("exp", w
->exp_string
);
10328 /* Implement the "print_recreate" breakpoint_ops method for
10332 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10334 struct watchpoint
*w
= (struct watchpoint
*) b
;
10338 case bp_watchpoint
:
10339 case bp_hardware_watchpoint
:
10340 fprintf_unfiltered (fp
, "watch");
10342 case bp_read_watchpoint
:
10343 fprintf_unfiltered (fp
, "rwatch");
10345 case bp_access_watchpoint
:
10346 fprintf_unfiltered (fp
, "awatch");
10349 internal_error (__FILE__
, __LINE__
,
10350 _("Invalid watchpoint type."));
10353 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10354 print_recreate_thread (b
, fp
);
10357 /* Implement the "explains_signal" breakpoint_ops method for
10361 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10363 /* A software watchpoint cannot cause a signal other than
10364 GDB_SIGNAL_TRAP. */
10365 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10371 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10373 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10375 /* Implement the "insert" breakpoint_ops method for
10376 masked hardware watchpoints. */
10379 insert_masked_watchpoint (struct bp_location
*bl
)
10381 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10383 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10384 bl
->watchpoint_type
);
10387 /* Implement the "remove" breakpoint_ops method for
10388 masked hardware watchpoints. */
10391 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10393 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10395 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10396 bl
->watchpoint_type
);
10399 /* Implement the "resources_needed" breakpoint_ops method for
10400 masked hardware watchpoints. */
10403 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10405 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10407 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10410 /* Implement the "works_in_software_mode" breakpoint_ops method for
10411 masked hardware watchpoints. */
10414 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10419 /* Implement the "print_it" breakpoint_ops method for
10420 masked hardware watchpoints. */
10422 static enum print_stop_action
10423 print_it_masked_watchpoint (bpstat bs
)
10425 struct breakpoint
*b
= bs
->breakpoint_at
;
10426 struct ui_out
*uiout
= current_uiout
;
10428 /* Masked watchpoints have only one location. */
10429 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10431 annotate_watchpoint (b
->number
);
10432 maybe_print_thread_hit_breakpoint (uiout
);
10436 case bp_hardware_watchpoint
:
10437 if (uiout
->is_mi_like_p ())
10438 uiout
->field_string
10439 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10442 case bp_read_watchpoint
:
10443 if (uiout
->is_mi_like_p ())
10444 uiout
->field_string
10445 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10448 case bp_access_watchpoint
:
10449 if (uiout
->is_mi_like_p ())
10450 uiout
->field_string
10452 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10455 internal_error (__FILE__
, __LINE__
,
10456 _("Invalid hardware watchpoint type."));
10460 uiout
->text (_("\n\
10461 Check the underlying instruction at PC for the memory\n\
10462 address and value which triggered this watchpoint.\n"));
10463 uiout
->text ("\n");
10465 /* More than one watchpoint may have been triggered. */
10466 return PRINT_UNKNOWN
;
10469 /* Implement the "print_one_detail" breakpoint_ops method for
10470 masked hardware watchpoints. */
10473 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10474 struct ui_out
*uiout
)
10476 struct watchpoint
*w
= (struct watchpoint
*) b
;
10478 /* Masked watchpoints have only one location. */
10479 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10481 uiout
->text ("\tmask ");
10482 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10483 uiout
->text ("\n");
10486 /* Implement the "print_mention" breakpoint_ops method for
10487 masked hardware watchpoints. */
10490 print_mention_masked_watchpoint (struct breakpoint
*b
)
10492 struct watchpoint
*w
= (struct watchpoint
*) b
;
10493 struct ui_out
*uiout
= current_uiout
;
10494 const char *tuple_name
;
10498 case bp_hardware_watchpoint
:
10499 uiout
->text ("Masked hardware watchpoint ");
10500 tuple_name
= "wpt";
10502 case bp_read_watchpoint
:
10503 uiout
->text ("Masked hardware read watchpoint ");
10504 tuple_name
= "hw-rwpt";
10506 case bp_access_watchpoint
:
10507 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10508 tuple_name
= "hw-awpt";
10511 internal_error (__FILE__
, __LINE__
,
10512 _("Invalid hardware watchpoint type."));
10515 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10516 uiout
->field_signed ("number", b
->number
);
10517 uiout
->text (": ");
10518 uiout
->field_string ("exp", w
->exp_string
);
10521 /* Implement the "print_recreate" breakpoint_ops method for
10522 masked hardware watchpoints. */
10525 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10527 struct watchpoint
*w
= (struct watchpoint
*) b
;
10531 case bp_hardware_watchpoint
:
10532 fprintf_unfiltered (fp
, "watch");
10534 case bp_read_watchpoint
:
10535 fprintf_unfiltered (fp
, "rwatch");
10537 case bp_access_watchpoint
:
10538 fprintf_unfiltered (fp
, "awatch");
10541 internal_error (__FILE__
, __LINE__
,
10542 _("Invalid hardware watchpoint type."));
10545 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
,
10546 phex (w
->hw_wp_mask
, sizeof (CORE_ADDR
)));
10547 print_recreate_thread (b
, fp
);
10550 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10552 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10554 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10557 is_masked_watchpoint (const struct breakpoint
*b
)
10559 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10562 /* accessflag: hw_write: watch write,
10563 hw_read: watch read,
10564 hw_access: watch access (read or write) */
10566 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10567 bool just_location
, bool internal
)
10569 struct breakpoint
*scope_breakpoint
= NULL
;
10570 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10571 struct value
*result
;
10572 int saved_bitpos
= 0, saved_bitsize
= 0;
10573 const char *exp_start
= NULL
;
10574 const char *exp_end
= NULL
;
10575 const char *tok
, *end_tok
;
10577 const char *cond_start
= NULL
;
10578 const char *cond_end
= NULL
;
10579 enum bptype bp_type
;
10581 /* Flag to indicate whether we are going to use masks for
10582 the hardware watchpoint. */
10583 bool use_mask
= false;
10584 CORE_ADDR mask
= 0;
10586 /* Make sure that we actually have parameters to parse. */
10587 if (arg
!= NULL
&& arg
[0] != '\0')
10589 const char *value_start
;
10591 exp_end
= arg
+ strlen (arg
);
10593 /* Look for "parameter value" pairs at the end
10594 of the arguments string. */
10595 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10597 /* Skip whitespace at the end of the argument list. */
10598 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10601 /* Find the beginning of the last token.
10602 This is the value of the parameter. */
10603 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10605 value_start
= tok
+ 1;
10607 /* Skip whitespace. */
10608 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10613 /* Find the beginning of the second to last token.
10614 This is the parameter itself. */
10615 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10618 toklen
= end_tok
- tok
+ 1;
10620 if (toklen
== 6 && startswith (tok
, "thread"))
10622 struct thread_info
*thr
;
10623 /* At this point we've found a "thread" token, which means
10624 the user is trying to set a watchpoint that triggers
10625 only in a specific thread. */
10629 error(_("You can specify only one thread."));
10631 /* Extract the thread ID from the next token. */
10632 thr
= parse_thread_id (value_start
, &endp
);
10634 /* Check if the user provided a valid thread ID. */
10635 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10636 invalid_thread_id_error (value_start
);
10638 thread
= thr
->global_num
;
10640 else if (toklen
== 4 && startswith (tok
, "mask"))
10642 /* We've found a "mask" token, which means the user wants to
10643 create a hardware watchpoint that is going to have the mask
10645 struct value
*mask_value
, *mark
;
10648 error(_("You can specify only one mask."));
10650 use_mask
= just_location
= true;
10652 mark
= value_mark ();
10653 mask_value
= parse_to_comma_and_eval (&value_start
);
10654 mask
= value_as_address (mask_value
);
10655 value_free_to_mark (mark
);
10658 /* We didn't recognize what we found. We should stop here. */
10661 /* Truncate the string and get rid of the "parameter value" pair before
10662 the arguments string is parsed by the parse_exp_1 function. */
10669 /* Parse the rest of the arguments. From here on out, everything
10670 is in terms of a newly allocated string instead of the original
10672 std::string
expression (arg
, exp_end
- arg
);
10673 exp_start
= arg
= expression
.c_str ();
10674 innermost_block_tracker tracker
;
10675 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10677 /* Remove trailing whitespace from the expression before saving it.
10678 This makes the eventual display of the expression string a bit
10680 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10683 /* Checking if the expression is not constant. */
10684 if (watchpoint_exp_is_const (exp
.get ()))
10688 len
= exp_end
- exp_start
;
10689 while (len
> 0 && isspace (exp_start
[len
- 1]))
10691 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10694 exp_valid_block
= tracker
.block ();
10695 struct value
*mark
= value_mark ();
10696 struct value
*val_as_value
= nullptr;
10697 fetch_subexp_value (exp
.get (), exp
->op
.get (), &val_as_value
, &result
, NULL
,
10700 if (val_as_value
!= NULL
&& just_location
)
10702 saved_bitpos
= value_bitpos (val_as_value
);
10703 saved_bitsize
= value_bitsize (val_as_value
);
10711 exp_valid_block
= NULL
;
10712 val
= release_value (value_addr (result
));
10713 value_free_to_mark (mark
);
10717 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10720 error (_("This target does not support masked watchpoints."));
10721 else if (ret
== -2)
10722 error (_("Invalid mask or memory region."));
10725 else if (val_as_value
!= NULL
)
10726 val
= release_value (val_as_value
);
10728 tok
= skip_spaces (arg
);
10729 end_tok
= skip_to_space (tok
);
10731 toklen
= end_tok
- tok
;
10732 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10734 tok
= cond_start
= end_tok
+ 1;
10735 innermost_block_tracker if_tracker
;
10736 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10738 /* The watchpoint expression may not be local, but the condition
10739 may still be. E.g.: `watch global if local > 0'. */
10740 cond_exp_valid_block
= if_tracker
.block ();
10745 error (_("Junk at end of command."));
10747 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10749 /* Save this because create_internal_breakpoint below invalidates
10751 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10753 /* If the expression is "local", then set up a "watchpoint scope"
10754 breakpoint at the point where we've left the scope of the watchpoint
10755 expression. Create the scope breakpoint before the watchpoint, so
10756 that we will encounter it first in bpstat_stop_status. */
10757 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10759 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10761 if (frame_id_p (caller_frame_id
))
10763 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10764 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10767 = create_internal_breakpoint (caller_arch
, caller_pc
,
10768 bp_watchpoint_scope
,
10769 &momentary_breakpoint_ops
);
10771 /* create_internal_breakpoint could invalidate WP_FRAME. */
10774 scope_breakpoint
->enable_state
= bp_enabled
;
10776 /* Automatically delete the breakpoint when it hits. */
10777 scope_breakpoint
->disposition
= disp_del
;
10779 /* Only break in the proper frame (help with recursion). */
10780 scope_breakpoint
->frame_id
= caller_frame_id
;
10782 /* Set the address at which we will stop. */
10783 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10784 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10785 scope_breakpoint
->loc
->address
10786 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10787 scope_breakpoint
->loc
->requested_address
,
10788 scope_breakpoint
->type
);
10792 /* Now set up the breakpoint. We create all watchpoints as hardware
10793 watchpoints here even if hardware watchpoints are turned off, a call
10794 to update_watchpoint later in this function will cause the type to
10795 drop back to bp_watchpoint (software watchpoint) if required. */
10797 if (accessflag
== hw_read
)
10798 bp_type
= bp_read_watchpoint
;
10799 else if (accessflag
== hw_access
)
10800 bp_type
= bp_access_watchpoint
;
10802 bp_type
= bp_hardware_watchpoint
;
10804 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10807 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10808 &masked_watchpoint_breakpoint_ops
);
10810 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10811 &watchpoint_breakpoint_ops
);
10812 w
->thread
= thread
;
10813 w
->disposition
= disp_donttouch
;
10814 w
->pspace
= current_program_space
;
10815 w
->exp
= std::move (exp
);
10816 w
->exp_valid_block
= exp_valid_block
;
10817 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10820 struct type
*t
= value_type (val
.get ());
10821 CORE_ADDR addr
= value_as_address (val
.get ());
10823 w
->exp_string_reparse
10824 = current_language
->watch_location_expression (t
, addr
).release ();
10826 w
->exp_string
= xstrprintf ("-location %.*s",
10827 (int) (exp_end
- exp_start
), exp_start
);
10830 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10834 w
->hw_wp_mask
= mask
;
10839 w
->val_bitpos
= saved_bitpos
;
10840 w
->val_bitsize
= saved_bitsize
;
10841 w
->val_valid
= true;
10845 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10847 w
->cond_string
= 0;
10849 if (frame_id_p (watchpoint_frame
))
10851 w
->watchpoint_frame
= watchpoint_frame
;
10852 w
->watchpoint_thread
= inferior_ptid
;
10856 w
->watchpoint_frame
= null_frame_id
;
10857 w
->watchpoint_thread
= null_ptid
;
10860 if (scope_breakpoint
!= NULL
)
10862 /* The scope breakpoint is related to the watchpoint. We will
10863 need to act on them together. */
10864 w
->related_breakpoint
= scope_breakpoint
;
10865 scope_breakpoint
->related_breakpoint
= w
.get ();
10868 if (!just_location
)
10869 value_free_to_mark (mark
);
10871 /* Finally update the new watchpoint. This creates the locations
10872 that should be inserted. */
10873 update_watchpoint (w
.get (), 1);
10875 install_breakpoint (internal
, std::move (w
), 1);
10878 /* Return count of debug registers needed to watch the given expression.
10879 If the watchpoint cannot be handled in hardware return zero. */
10882 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10884 int found_memory_cnt
= 0;
10886 /* Did the user specifically forbid us to use hardware watchpoints? */
10887 if (!can_use_hw_watchpoints
)
10890 gdb_assert (!vals
.empty ());
10891 struct value
*head
= vals
[0].get ();
10893 /* Make sure that the value of the expression depends only upon
10894 memory contents, and values computed from them within GDB. If we
10895 find any register references or function calls, we can't use a
10896 hardware watchpoint.
10898 The idea here is that evaluating an expression generates a series
10899 of values, one holding the value of every subexpression. (The
10900 expression a*b+c has five subexpressions: a, b, a*b, c, and
10901 a*b+c.) GDB's values hold almost enough information to establish
10902 the criteria given above --- they identify memory lvalues,
10903 register lvalues, computed values, etcetera. So we can evaluate
10904 the expression, and then scan the chain of values that leaves
10905 behind to decide whether we can detect any possible change to the
10906 expression's final value using only hardware watchpoints.
10908 However, I don't think that the values returned by inferior
10909 function calls are special in any way. So this function may not
10910 notice that an expression involving an inferior function call
10911 can't be watched with hardware watchpoints. FIXME. */
10912 for (const value_ref_ptr
&iter
: vals
)
10914 struct value
*v
= iter
.get ();
10916 if (VALUE_LVAL (v
) == lval_memory
)
10918 if (v
!= head
&& value_lazy (v
))
10919 /* A lazy memory lvalue in the chain is one that GDB never
10920 needed to fetch; we either just used its address (e.g.,
10921 `a' in `a.b') or we never needed it at all (e.g., `a'
10922 in `a,b'). This doesn't apply to HEAD; if that is
10923 lazy then it was not readable, but watch it anyway. */
10927 /* Ahh, memory we actually used! Check if we can cover
10928 it with hardware watchpoints. */
10929 struct type
*vtype
= check_typedef (value_type (v
));
10931 /* We only watch structs and arrays if user asked for it
10932 explicitly, never if they just happen to appear in a
10933 middle of some value chain. */
10935 || (vtype
->code () != TYPE_CODE_STRUCT
10936 && vtype
->code () != TYPE_CODE_ARRAY
))
10938 CORE_ADDR vaddr
= value_address (v
);
10942 len
= (target_exact_watchpoints
10943 && is_scalar_type_recursive (vtype
))?
10944 1 : TYPE_LENGTH (value_type (v
));
10946 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10950 found_memory_cnt
+= num_regs
;
10954 else if (VALUE_LVAL (v
) != not_lval
10955 && deprecated_value_modifiable (v
) == 0)
10956 return 0; /* These are values from the history (e.g., $1). */
10957 else if (VALUE_LVAL (v
) == lval_register
)
10958 return 0; /* Cannot watch a register with a HW watchpoint. */
10961 /* The expression itself looks suitable for using a hardware
10962 watchpoint, but give the target machine a chance to reject it. */
10963 return found_memory_cnt
;
10967 watch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
10969 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10972 /* Options for the watch, awatch, and rwatch commands. */
10974 struct watch_options
10976 /* For -location. */
10977 bool location
= false;
10980 /* Definitions of options for the "watch", "awatch", and "rwatch" commands.
10982 Historically GDB always accepted both '-location' and '-l' flags for
10983 these commands (both flags being synonyms). When converting to the
10984 newer option scheme only '-location' is added here. That's fine (for
10985 backward compatibility) as any non-ambiguous prefix of a flag will be
10986 accepted, so '-l', '-loc', are now all accepted.
10988 What this means is that, if in the future, we add any new flag here
10989 that starts with '-l' then this will break backward compatibility, so
10990 please, don't do that! */
10992 static const gdb::option::option_def watch_option_defs
[] = {
10993 gdb::option::flag_option_def
<watch_options
> {
10995 [] (watch_options
*opt
) { return &opt
->location
; },
10997 This evaluates EXPRESSION and watches the memory to which is refers.\n\
10998 -l can be used as a short form of -location."),
11002 /* Returns the option group used by 'watch', 'awatch', and 'rwatch'
11005 static gdb::option::option_def_group
11006 make_watch_options_def_group (watch_options
*opts
)
11008 return {{watch_option_defs
}, opts
};
11011 /* A helper function that looks for the "-location" argument and then
11012 calls watch_command_1. */
11015 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
11017 watch_options opts
;
11018 auto grp
= make_watch_options_def_group (&opts
);
11019 gdb::option::process_options
11020 (&arg
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, grp
);
11021 if (arg
!= nullptr && *arg
== '\0')
11024 watch_command_1 (arg
, accessflag
, from_tty
, opts
.location
, false);
11027 /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */
11029 watch_command_completer (struct cmd_list_element
*ignore
,
11030 completion_tracker
&tracker
,
11031 const char *text
, const char * /*word*/)
11033 const auto group
= make_watch_options_def_group (nullptr);
11034 if (gdb::option::complete_options
11035 (tracker
, &text
, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
, group
))
11038 const char *word
= advance_to_expression_complete_word_point (tracker
, text
);
11039 expression_completer (ignore
, tracker
, text
, word
);
11043 watch_command (const char *arg
, int from_tty
)
11045 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11049 rwatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11051 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11055 rwatch_command (const char *arg
, int from_tty
)
11057 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11061 awatch_command_wrapper (const char *arg
, int from_tty
, bool internal
)
11063 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11067 awatch_command (const char *arg
, int from_tty
)
11069 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11073 /* Data for the FSM that manages the until(location)/advance commands
11074 in infcmd.c. Here because it uses the mechanisms of
11077 struct until_break_fsm
: public thread_fsm
11079 /* The thread that was current when the command was executed. */
11082 /* The breakpoint set at the return address in the caller frame,
11083 plus breakpoints at all the destination locations. */
11084 std::vector
<breakpoint_up
> breakpoints
;
11086 until_break_fsm (struct interp
*cmd_interp
, int thread
,
11087 std::vector
<breakpoint_up
> &&breakpoints
)
11088 : thread_fsm (cmd_interp
),
11090 breakpoints (std::move (breakpoints
))
11094 void clean_up (struct thread_info
*thread
) override
;
11095 bool should_stop (struct thread_info
*thread
) override
;
11096 enum async_reply_reason
do_async_reply_reason () override
;
11099 /* Implementation of the 'should_stop' FSM method for the
11100 until(location)/advance commands. */
11103 until_break_fsm::should_stop (struct thread_info
*tp
)
11105 for (const breakpoint_up
&bp
: breakpoints
)
11106 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11107 bp
.get ()) != NULL
)
11116 /* Implementation of the 'clean_up' FSM method for the
11117 until(location)/advance commands. */
11120 until_break_fsm::clean_up (struct thread_info
*)
11122 /* Clean up our temporary breakpoints. */
11123 breakpoints
.clear ();
11124 delete_longjmp_breakpoint (thread
);
11127 /* Implementation of the 'async_reply_reason' FSM method for the
11128 until(location)/advance commands. */
11130 enum async_reply_reason
11131 until_break_fsm::do_async_reply_reason ()
11133 return EXEC_ASYNC_LOCATION_REACHED
;
11137 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11139 struct frame_info
*frame
;
11140 struct gdbarch
*frame_gdbarch
;
11141 struct frame_id stack_frame_id
;
11142 struct frame_id caller_frame_id
;
11144 struct thread_info
*tp
;
11146 clear_proceed_status (0);
11148 /* Set a breakpoint where the user wants it and at return from
11151 event_location_up location
= string_to_event_location (&arg
, current_language
);
11153 std::vector
<symtab_and_line
> sals
11154 = (last_displayed_sal_is_valid ()
11155 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11156 get_last_displayed_symtab (),
11157 get_last_displayed_line ())
11158 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11162 error (_("Couldn't get information on specified line."));
11165 error (_("Junk at end of arguments."));
11167 tp
= inferior_thread ();
11168 thread
= tp
->global_num
;
11170 /* Note linespec handling above invalidates the frame chain.
11171 Installing a breakpoint also invalidates the frame chain (as it
11172 may need to switch threads), so do any frame handling before
11175 frame
= get_selected_frame (NULL
);
11176 frame_gdbarch
= get_frame_arch (frame
);
11177 stack_frame_id
= get_stack_frame_id (frame
);
11178 caller_frame_id
= frame_unwind_caller_id (frame
);
11180 /* Keep within the current frame, or in frames called by the current
11183 std::vector
<breakpoint_up
> breakpoints
;
11185 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11187 if (frame_id_p (caller_frame_id
))
11189 struct symtab_and_line sal2
;
11190 struct gdbarch
*caller_gdbarch
;
11192 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11193 sal2
.pc
= frame_unwind_caller_pc (frame
);
11194 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11196 breakpoint_up caller_breakpoint
11197 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
11198 caller_frame_id
, bp_until
);
11199 breakpoints
.emplace_back (std::move (caller_breakpoint
));
11201 set_longjmp_breakpoint (tp
, caller_frame_id
);
11202 lj_deleter
.emplace (thread
);
11205 /* set_momentary_breakpoint could invalidate FRAME. */
11208 /* If the user told us to continue until a specified location, we
11209 don't specify a frame at which we need to stop. Otherwise,
11210 specify the selected frame, because we want to stop only at the
11211 very same frame. */
11212 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
11214 for (symtab_and_line
&sal
: sals
)
11216 resolve_sal_pc (&sal
);
11218 breakpoint_up location_breakpoint
11219 = set_momentary_breakpoint (frame_gdbarch
, sal
,
11220 stop_frame_id
, bp_until
);
11221 breakpoints
.emplace_back (std::move (location_breakpoint
));
11224 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11225 std::move (breakpoints
));
11228 lj_deleter
->release ();
11230 proceed (-1, GDB_SIGNAL_DEFAULT
);
11233 /* This function attempts to parse an optional "if <cond>" clause
11234 from the arg string. If one is not found, it returns NULL.
11236 Else, it returns a pointer to the condition string. (It does not
11237 attempt to evaluate the string against a particular block.) And,
11238 it updates arg to point to the first character following the parsed
11239 if clause in the arg string. */
11242 ep_parse_optional_if_clause (const char **arg
)
11244 const char *cond_string
;
11246 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11249 /* Skip the "if" keyword. */
11252 /* Skip any extra leading whitespace, and record the start of the
11253 condition string. */
11254 *arg
= skip_spaces (*arg
);
11255 cond_string
= *arg
;
11257 /* Assume that the condition occupies the remainder of the arg
11259 (*arg
) += strlen (cond_string
);
11261 return cond_string
;
11264 /* Commands to deal with catching events, such as signals, exceptions,
11265 process start/exit, etc. */
11269 catch_fork_temporary
, catch_vfork_temporary
,
11270 catch_fork_permanent
, catch_vfork_permanent
11275 catch_fork_command_1 (const char *arg
, int from_tty
,
11276 struct cmd_list_element
*command
)
11278 struct gdbarch
*gdbarch
= get_current_arch ();
11279 const char *cond_string
= NULL
;
11280 catch_fork_kind fork_kind
;
11282 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11283 bool temp
= (fork_kind
== catch_fork_temporary
11284 || fork_kind
== catch_vfork_temporary
);
11288 arg
= skip_spaces (arg
);
11290 /* The allowed syntax is:
11292 catch [v]fork if <cond>
11294 First, check if there's an if clause. */
11295 cond_string
= ep_parse_optional_if_clause (&arg
);
11297 if ((*arg
!= '\0') && !isspace (*arg
))
11298 error (_("Junk at end of arguments."));
11300 /* If this target supports it, create a fork or vfork catchpoint
11301 and enable reporting of such events. */
11304 case catch_fork_temporary
:
11305 case catch_fork_permanent
:
11306 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11307 &catch_fork_breakpoint_ops
);
11309 case catch_vfork_temporary
:
11310 case catch_vfork_permanent
:
11311 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11312 &catch_vfork_breakpoint_ops
);
11315 error (_("unsupported or unknown fork kind; cannot catch it"));
11321 catch_exec_command_1 (const char *arg
, int from_tty
,
11322 struct cmd_list_element
*command
)
11324 struct gdbarch
*gdbarch
= get_current_arch ();
11325 const char *cond_string
= NULL
;
11326 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11330 arg
= skip_spaces (arg
);
11332 /* The allowed syntax is:
11334 catch exec if <cond>
11336 First, check if there's an if clause. */
11337 cond_string
= ep_parse_optional_if_clause (&arg
);
11339 if ((*arg
!= '\0') && !isspace (*arg
))
11340 error (_("Junk at end of arguments."));
11342 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11343 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
,
11344 &catch_exec_breakpoint_ops
);
11345 c
->exec_pathname
= NULL
;
11347 install_breakpoint (0, std::move (c
), 1);
11351 init_ada_exception_breakpoint (struct breakpoint
*b
,
11352 struct gdbarch
*gdbarch
,
11353 struct symtab_and_line sal
,
11354 const char *addr_string
,
11355 const struct breakpoint_ops
*ops
,
11362 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11364 loc_gdbarch
= gdbarch
;
11366 describe_other_breakpoints (loc_gdbarch
,
11367 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11368 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11369 version for exception catchpoints, because two catchpoints
11370 used for different exception names will use the same address.
11371 In this case, a "breakpoint ... also set at..." warning is
11372 unproductive. Besides, the warning phrasing is also a bit
11373 inappropriate, we should use the word catchpoint, and tell
11374 the user what type of catchpoint it is. The above is good
11375 enough for now, though. */
11378 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11380 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11381 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11382 b
->location
= string_to_event_location (&addr_string
,
11383 language_def (language_ada
));
11384 b
->language
= language_ada
;
11389 /* Compare two breakpoints and return a strcmp-like result. */
11392 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11394 uintptr_t ua
= (uintptr_t) a
;
11395 uintptr_t ub
= (uintptr_t) b
;
11397 if (a
->number
< b
->number
)
11399 else if (a
->number
> b
->number
)
11402 /* Now sort by address, in case we see, e..g, two breakpoints with
11406 return ua
> ub
? 1 : 0;
11409 /* Delete breakpoints by address or line. */
11412 clear_command (const char *arg
, int from_tty
)
11416 std::vector
<symtab_and_line
> decoded_sals
;
11417 symtab_and_line last_sal
;
11418 gdb::array_view
<symtab_and_line
> sals
;
11422 = decode_line_with_current_source (arg
,
11423 (DECODE_LINE_FUNFIRSTLINE
11424 | DECODE_LINE_LIST_MODE
));
11426 sals
= decoded_sals
;
11430 /* Set sal's line, symtab, pc, and pspace to the values
11431 corresponding to the last call to print_frame_info. If the
11432 codepoint is not valid, this will set all the fields to 0. */
11433 last_sal
= get_last_displayed_sal ();
11434 if (last_sal
.symtab
== 0)
11435 error (_("No source file specified."));
11441 /* We don't call resolve_sal_pc here. That's not as bad as it
11442 seems, because all existing breakpoints typically have both
11443 file/line and pc set. So, if clear is given file/line, we can
11444 match this to existing breakpoint without obtaining pc at all.
11446 We only support clearing given the address explicitly
11447 present in breakpoint table. Say, we've set breakpoint
11448 at file:line. There were several PC values for that file:line,
11449 due to optimization, all in one block.
11451 We've picked one PC value. If "clear" is issued with another
11452 PC corresponding to the same file:line, the breakpoint won't
11453 be cleared. We probably can still clear the breakpoint, but
11454 since the other PC value is never presented to user, user
11455 can only find it by guessing, and it does not seem important
11456 to support that. */
11458 /* For each line spec given, delete bps which correspond to it. Do
11459 it in two passes, solely to preserve the current behavior that
11460 from_tty is forced true if we delete more than one
11463 std::vector
<struct breakpoint
*> found
;
11464 for (const auto &sal
: sals
)
11466 const char *sal_fullname
;
11468 /* If exact pc given, clear bpts at that pc.
11469 If line given (pc == 0), clear all bpts on specified line.
11470 If defaulting, clear all bpts on default line
11473 defaulting sal.pc != 0 tests to do
11478 1 0 <can't happen> */
11480 sal_fullname
= (sal
.symtab
== NULL
11481 ? NULL
: symtab_to_fullname (sal
.symtab
));
11483 /* Find all matching breakpoints and add them to 'found'. */
11484 for (breakpoint
*b
: all_breakpoints ())
11487 /* Are we going to delete b? */
11488 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11490 for (bp_location
*loc
: b
->locations ())
11492 /* If the user specified file:line, don't allow a PC
11493 match. This matches historical gdb behavior. */
11494 int pc_match
= (!sal
.explicit_line
11496 && (loc
->pspace
== sal
.pspace
)
11497 && (loc
->address
== sal
.pc
)
11498 && (!section_is_overlay (loc
->section
)
11499 || loc
->section
== sal
.section
));
11500 int line_match
= 0;
11502 if ((default_match
|| sal
.explicit_line
)
11503 && loc
->symtab
!= NULL
11504 && sal_fullname
!= NULL
11505 && sal
.pspace
== loc
->pspace
11506 && loc
->line_number
== sal
.line
11507 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11508 sal_fullname
) == 0)
11511 if (pc_match
|| line_match
)
11520 found
.push_back (b
);
11524 /* Now go thru the 'found' chain and delete them. */
11525 if (found
.empty ())
11528 error (_("No breakpoint at %s."), arg
);
11530 error (_("No breakpoint at this line."));
11533 /* Remove duplicates from the vec. */
11534 std::sort (found
.begin (), found
.end (),
11535 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11537 return compare_breakpoints (bp_a
, bp_b
) < 0;
11539 found
.erase (std::unique (found
.begin (), found
.end (),
11540 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11542 return compare_breakpoints (bp_a
, bp_b
) == 0;
11546 if (found
.size () > 1)
11547 from_tty
= 1; /* Always report if deleted more than one. */
11550 if (found
.size () == 1)
11551 printf_unfiltered (_("Deleted breakpoint "));
11553 printf_unfiltered (_("Deleted breakpoints "));
11556 for (breakpoint
*iter
: found
)
11559 printf_unfiltered ("%d ", iter
->number
);
11560 delete_breakpoint (iter
);
11563 putchar_unfiltered ('\n');
11566 /* Delete breakpoint in BS if they are `delete' breakpoints and
11567 all breakpoints that are marked for deletion, whether hit or not.
11568 This is called after any breakpoint is hit, or after errors. */
11571 breakpoint_auto_delete (bpstat bs
)
11573 for (; bs
; bs
= bs
->next
)
11574 if (bs
->breakpoint_at
11575 && bs
->breakpoint_at
->disposition
== disp_del
11577 delete_breakpoint (bs
->breakpoint_at
);
11579 for (breakpoint
*b
: all_breakpoints_safe ())
11580 if (b
->disposition
== disp_del_at_next_stop
)
11581 delete_breakpoint (b
);
11584 /* A comparison function for bp_location AP and BP being interfaced to
11585 std::sort. Sort elements primarily by their ADDRESS (no matter what
11586 bl_address_is_meaningful says), secondarily by ordering first
11587 permanent elements and terciarily just ensuring the array is sorted
11588 stable way despite std::sort being an unstable algorithm. */
11591 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11593 if (a
->address
!= b
->address
)
11594 return a
->address
< b
->address
;
11596 /* Sort locations at the same address by their pspace number, keeping
11597 locations of the same inferior (in a multi-inferior environment)
11600 if (a
->pspace
->num
!= b
->pspace
->num
)
11601 return a
->pspace
->num
< b
->pspace
->num
;
11603 /* Sort permanent breakpoints first. */
11604 if (a
->permanent
!= b
->permanent
)
11605 return a
->permanent
> b
->permanent
;
11607 /* Sort by type in order to make duplicate determination easier.
11608 See update_global_location_list. This is kept in sync with
11609 breakpoint_locations_match. */
11610 if (a
->loc_type
< b
->loc_type
)
11613 /* Likewise, for range-breakpoints, sort by length. */
11614 if (a
->loc_type
== bp_loc_hardware_breakpoint
11615 && b
->loc_type
== bp_loc_hardware_breakpoint
11616 && a
->length
< b
->length
)
11619 /* Make the internal GDB representation stable across GDB runs
11620 where A and B memory inside GDB can differ. Breakpoint locations of
11621 the same type at the same address can be sorted in arbitrary order. */
11623 if (a
->owner
->number
!= b
->owner
->number
)
11624 return a
->owner
->number
< b
->owner
->number
;
11629 /* Set bp_locations_placed_address_before_address_max and
11630 bp_locations_shadow_len_after_address_max according to the current
11631 content of the bp_locations array. */
11634 bp_locations_target_extensions_update (void)
11636 bp_locations_placed_address_before_address_max
= 0;
11637 bp_locations_shadow_len_after_address_max
= 0;
11639 for (bp_location
*bl
: all_bp_locations ())
11641 CORE_ADDR start
, end
, addr
;
11643 if (!bp_location_has_shadow (bl
))
11646 start
= bl
->target_info
.placed_address
;
11647 end
= start
+ bl
->target_info
.shadow_len
;
11649 gdb_assert (bl
->address
>= start
);
11650 addr
= bl
->address
- start
;
11651 if (addr
> bp_locations_placed_address_before_address_max
)
11652 bp_locations_placed_address_before_address_max
= addr
;
11654 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11656 gdb_assert (bl
->address
< end
);
11657 addr
= end
- bl
->address
;
11658 if (addr
> bp_locations_shadow_len_after_address_max
)
11659 bp_locations_shadow_len_after_address_max
= addr
;
11663 /* Download tracepoint locations if they haven't been. */
11666 download_tracepoint_locations (void)
11668 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11670 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11672 for (breakpoint
*b
: all_tracepoints ())
11674 struct tracepoint
*t
;
11675 int bp_location_downloaded
= 0;
11677 if ((b
->type
== bp_fast_tracepoint
11678 ? !may_insert_fast_tracepoints
11679 : !may_insert_tracepoints
))
11682 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11684 if (target_can_download_tracepoint ())
11685 can_download_tracepoint
= TRIBOOL_TRUE
;
11687 can_download_tracepoint
= TRIBOOL_FALSE
;
11690 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11693 for (bp_location
*bl
: b
->locations ())
11695 /* In tracepoint, locations are _never_ duplicated, so
11696 should_be_inserted is equivalent to
11697 unduplicated_should_be_inserted. */
11698 if (!should_be_inserted (bl
) || bl
->inserted
)
11701 switch_to_program_space_and_thread (bl
->pspace
);
11703 target_download_tracepoint (bl
);
11706 bp_location_downloaded
= 1;
11708 t
= (struct tracepoint
*) b
;
11709 t
->number_on_target
= b
->number
;
11710 if (bp_location_downloaded
)
11711 gdb::observers::breakpoint_modified
.notify (b
);
11715 /* Swap the insertion/duplication state between two locations. */
11718 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11720 const int left_inserted
= left
->inserted
;
11721 const int left_duplicate
= left
->duplicate
;
11722 const int left_needs_update
= left
->needs_update
;
11723 const struct bp_target_info left_target_info
= left
->target_info
;
11725 /* Locations of tracepoints can never be duplicated. */
11726 if (is_tracepoint (left
->owner
))
11727 gdb_assert (!left
->duplicate
);
11728 if (is_tracepoint (right
->owner
))
11729 gdb_assert (!right
->duplicate
);
11731 left
->inserted
= right
->inserted
;
11732 left
->duplicate
= right
->duplicate
;
11733 left
->needs_update
= right
->needs_update
;
11734 left
->target_info
= right
->target_info
;
11735 right
->inserted
= left_inserted
;
11736 right
->duplicate
= left_duplicate
;
11737 right
->needs_update
= left_needs_update
;
11738 right
->target_info
= left_target_info
;
11741 /* Force the re-insertion of the locations at ADDRESS. This is called
11742 once a new/deleted/modified duplicate location is found and we are evaluating
11743 conditions on the target's side. Such conditions need to be updated on
11747 force_breakpoint_reinsertion (struct bp_location
*bl
)
11749 struct bp_location
**locp
= NULL
, **loc2p
;
11750 struct bp_location
*loc
;
11751 CORE_ADDR address
= 0;
11754 address
= bl
->address
;
11755 pspace_num
= bl
->pspace
->num
;
11757 /* This is only meaningful if the target is
11758 evaluating conditions and if the user has
11759 opted for condition evaluation on the target's
11761 if (gdb_evaluates_breakpoint_condition_p ()
11762 || !target_supports_evaluation_of_breakpoint_conditions ())
11765 /* Flag all breakpoint locations with this address and
11766 the same program space as the location
11767 as "its condition has changed". We need to
11768 update the conditions on the target's side. */
11769 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11773 if (!is_breakpoint (loc
->owner
)
11774 || pspace_num
!= loc
->pspace
->num
)
11777 /* Flag the location appropriately. We use a different state to
11778 let everyone know that we already updated the set of locations
11779 with addr bl->address and program space bl->pspace. This is so
11780 we don't have to keep calling these functions just to mark locations
11781 that have already been marked. */
11782 loc
->condition_changed
= condition_updated
;
11784 /* Free the agent expression bytecode as well. We will compute
11786 loc
->cond_bytecode
.reset ();
11790 /* Called whether new breakpoints are created, or existing breakpoints
11791 deleted, to update the global location list and recompute which
11792 locations are duplicate of which.
11794 The INSERT_MODE flag determines whether locations may not, may, or
11795 shall be inserted now. See 'enum ugll_insert_mode' for more
11799 update_global_location_list (enum ugll_insert_mode insert_mode
)
11801 /* Last breakpoint location address that was marked for update. */
11802 CORE_ADDR last_addr
= 0;
11803 /* Last breakpoint location program space that was marked for update. */
11804 int last_pspace_num
= -1;
11806 /* Used in the duplicates detection below. When iterating over all
11807 bp_locations, points to the first bp_location of a given address.
11808 Breakpoints and watchpoints of different types are never
11809 duplicates of each other. Keep one pointer for each type of
11810 breakpoint/watchpoint, so we only need to loop over all locations
11812 struct bp_location
*bp_loc_first
; /* breakpoint */
11813 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11814 struct bp_location
*awp_loc_first
; /* access watchpoint */
11815 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11817 /* Saved former bp_locations array which we compare against the newly
11818 built bp_locations from the current state of ALL_BREAKPOINTS. */
11819 std::vector
<bp_location
*> old_locations
= std::move (bp_locations
);
11820 bp_locations
.clear ();
11822 for (breakpoint
*b
: all_breakpoints ())
11823 for (bp_location
*loc
: b
->locations ())
11824 bp_locations
.push_back (loc
);
11826 /* See if we need to "upgrade" a software breakpoint to a hardware
11827 breakpoint. Do this before deciding whether locations are
11828 duplicates. Also do this before sorting because sorting order
11829 depends on location type. */
11830 for (bp_location
*loc
: bp_locations
)
11831 if (!loc
->inserted
&& should_be_inserted (loc
))
11832 handle_automatic_hardware_breakpoints (loc
);
11834 std::sort (bp_locations
.begin (), bp_locations
.end (),
11835 bp_location_is_less_than
);
11837 bp_locations_target_extensions_update ();
11839 /* Identify bp_location instances that are no longer present in the
11840 new list, and therefore should be freed. Note that it's not
11841 necessary that those locations should be removed from inferior --
11842 if there's another location at the same address (previously
11843 marked as duplicate), we don't need to remove/insert the
11846 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11847 and former bp_location array state respectively. */
11850 for (bp_location
*old_loc
: old_locations
)
11852 /* Tells if 'old_loc' is found among the new locations. If
11853 not, we have to free it. */
11854 int found_object
= 0;
11855 /* Tells if the location should remain inserted in the target. */
11856 int keep_in_target
= 0;
11859 /* Skip LOCP entries which will definitely never be needed.
11860 Stop either at or being the one matching OLD_LOC. */
11861 while (loc_i
< bp_locations
.size ()
11862 && bp_locations
[loc_i
]->address
< old_loc
->address
)
11865 for (size_t loc2_i
= loc_i
;
11866 (loc2_i
< bp_locations
.size ()
11867 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11870 /* Check if this is a new/duplicated location or a duplicated
11871 location that had its condition modified. If so, we want to send
11872 its condition to the target if evaluation of conditions is taking
11874 if (bp_locations
[loc2_i
]->condition_changed
== condition_modified
11875 && (last_addr
!= old_loc
->address
11876 || last_pspace_num
!= old_loc
->pspace
->num
))
11878 force_breakpoint_reinsertion (bp_locations
[loc2_i
]);
11879 last_pspace_num
= old_loc
->pspace
->num
;
11882 if (bp_locations
[loc2_i
] == old_loc
)
11886 /* We have already handled this address, update it so that we don't
11887 have to go through updates again. */
11888 last_addr
= old_loc
->address
;
11890 /* Target-side condition evaluation: Handle deleted locations. */
11892 force_breakpoint_reinsertion (old_loc
);
11894 /* If this location is no longer present, and inserted, look if
11895 there's maybe a new location at the same address. If so,
11896 mark that one inserted, and don't remove this one. This is
11897 needed so that we don't have a time window where a breakpoint
11898 at certain location is not inserted. */
11900 if (old_loc
->inserted
)
11902 /* If the location is inserted now, we might have to remove
11905 if (found_object
&& should_be_inserted (old_loc
))
11907 /* The location is still present in the location list,
11908 and still should be inserted. Don't do anything. */
11909 keep_in_target
= 1;
11913 /* This location still exists, but it won't be kept in the
11914 target since it may have been disabled. We proceed to
11915 remove its target-side condition. */
11917 /* The location is either no longer present, or got
11918 disabled. See if there's another location at the
11919 same address, in which case we don't need to remove
11920 this one from the target. */
11922 /* OLD_LOC comes from existing struct breakpoint. */
11923 if (bl_address_is_meaningful (old_loc
))
11925 for (size_t loc2_i
= loc_i
;
11926 (loc2_i
< bp_locations
.size ()
11927 && bp_locations
[loc2_i
]->address
== old_loc
->address
);
11930 bp_location
*loc2
= bp_locations
[loc2_i
];
11932 if (loc2
== old_loc
)
11935 if (breakpoint_locations_match (loc2
, old_loc
))
11937 /* Read watchpoint locations are switched to
11938 access watchpoints, if the former are not
11939 supported, but the latter are. */
11940 if (is_hardware_watchpoint (old_loc
->owner
))
11942 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11943 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11946 /* loc2 is a duplicated location. We need to check
11947 if it should be inserted in case it will be
11949 if (unduplicated_should_be_inserted (loc2
))
11951 swap_insertion (old_loc
, loc2
);
11952 keep_in_target
= 1;
11960 if (!keep_in_target
)
11962 if (remove_breakpoint (old_loc
))
11964 /* This is just about all we can do. We could keep
11965 this location on the global list, and try to
11966 remove it next time, but there's no particular
11967 reason why we will succeed next time.
11969 Note that at this point, old_loc->owner is still
11970 valid, as delete_breakpoint frees the breakpoint
11971 only after calling us. */
11972 printf_filtered (_("warning: Error removing "
11973 "breakpoint %d\n"),
11974 old_loc
->owner
->number
);
11982 if (removed
&& target_is_non_stop_p ()
11983 && need_moribund_for_location_type (old_loc
))
11985 /* This location was removed from the target. In
11986 non-stop mode, a race condition is possible where
11987 we've removed a breakpoint, but stop events for that
11988 breakpoint are already queued and will arrive later.
11989 We apply an heuristic to be able to distinguish such
11990 SIGTRAPs from other random SIGTRAPs: we keep this
11991 breakpoint location for a bit, and will retire it
11992 after we see some number of events. The theory here
11993 is that reporting of events should, "on the average",
11994 be fair, so after a while we'll see events from all
11995 threads that have anything of interest, and no longer
11996 need to keep this breakpoint location around. We
11997 don't hold locations forever so to reduce chances of
11998 mistaking a non-breakpoint SIGTRAP for a breakpoint
12001 The heuristic failing can be disastrous on
12002 decr_pc_after_break targets.
12004 On decr_pc_after_break targets, like e.g., x86-linux,
12005 if we fail to recognize a late breakpoint SIGTRAP,
12006 because events_till_retirement has reached 0 too
12007 soon, we'll fail to do the PC adjustment, and report
12008 a random SIGTRAP to the user. When the user resumes
12009 the inferior, it will most likely immediately crash
12010 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12011 corrupted, because of being resumed e.g., in the
12012 middle of a multi-byte instruction, or skipped a
12013 one-byte instruction. This was actually seen happen
12014 on native x86-linux, and should be less rare on
12015 targets that do not support new thread events, like
12016 remote, due to the heuristic depending on
12019 Mistaking a random SIGTRAP for a breakpoint trap
12020 causes similar symptoms (PC adjustment applied when
12021 it shouldn't), but then again, playing with SIGTRAPs
12022 behind the debugger's back is asking for trouble.
12024 Since hardware watchpoint traps are always
12025 distinguishable from other traps, so we don't need to
12026 apply keep hardware watchpoint moribund locations
12027 around. We simply always ignore hardware watchpoint
12028 traps we can no longer explain. */
12030 process_stratum_target
*proc_target
= nullptr;
12031 for (inferior
*inf
: all_inferiors ())
12032 if (inf
->pspace
== old_loc
->pspace
)
12034 proc_target
= inf
->process_target ();
12037 if (proc_target
!= nullptr)
12038 old_loc
->events_till_retirement
12039 = 3 * (thread_count (proc_target
) + 1);
12041 old_loc
->events_till_retirement
= 1;
12042 old_loc
->owner
= NULL
;
12044 moribund_locations
.push_back (old_loc
);
12048 old_loc
->owner
= NULL
;
12049 decref_bp_location (&old_loc
);
12054 /* Rescan breakpoints at the same address and section, marking the
12055 first one as "first" and any others as "duplicates". This is so
12056 that the bpt instruction is only inserted once. If we have a
12057 permanent breakpoint at the same place as BPT, make that one the
12058 official one, and the rest as duplicates. Permanent breakpoints
12059 are sorted first for the same address.
12061 Do the same for hardware watchpoints, but also considering the
12062 watchpoint's type (regular/access/read) and length. */
12064 bp_loc_first
= NULL
;
12065 wp_loc_first
= NULL
;
12066 awp_loc_first
= NULL
;
12067 rwp_loc_first
= NULL
;
12069 for (bp_location
*loc
: all_bp_locations ())
12071 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12073 struct bp_location
**loc_first_p
;
12074 breakpoint
*b
= loc
->owner
;
12076 if (!unduplicated_should_be_inserted (loc
)
12077 || !bl_address_is_meaningful (loc
)
12078 /* Don't detect duplicate for tracepoint locations because they are
12079 never duplicated. See the comments in field `duplicate' of
12080 `struct bp_location'. */
12081 || is_tracepoint (b
))
12083 /* Clear the condition modification flag. */
12084 loc
->condition_changed
= condition_unchanged
;
12088 if (b
->type
== bp_hardware_watchpoint
)
12089 loc_first_p
= &wp_loc_first
;
12090 else if (b
->type
== bp_read_watchpoint
)
12091 loc_first_p
= &rwp_loc_first
;
12092 else if (b
->type
== bp_access_watchpoint
)
12093 loc_first_p
= &awp_loc_first
;
12095 loc_first_p
= &bp_loc_first
;
12097 if (*loc_first_p
== NULL
12098 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12099 || !breakpoint_locations_match (loc
, *loc_first_p
))
12101 *loc_first_p
= loc
;
12102 loc
->duplicate
= 0;
12104 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12106 loc
->needs_update
= 1;
12107 /* Clear the condition modification flag. */
12108 loc
->condition_changed
= condition_unchanged
;
12114 /* This and the above ensure the invariant that the first location
12115 is not duplicated, and is the inserted one.
12116 All following are marked as duplicated, and are not inserted. */
12118 swap_insertion (loc
, *loc_first_p
);
12119 loc
->duplicate
= 1;
12121 /* Clear the condition modification flag. */
12122 loc
->condition_changed
= condition_unchanged
;
12125 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12127 if (insert_mode
!= UGLL_DONT_INSERT
)
12128 insert_breakpoint_locations ();
12131 /* Even though the caller told us to not insert new
12132 locations, we may still need to update conditions on the
12133 target's side of breakpoints that were already inserted
12134 if the target is evaluating breakpoint conditions. We
12135 only update conditions for locations that are marked
12137 update_inserted_breakpoint_locations ();
12141 if (insert_mode
!= UGLL_DONT_INSERT
)
12142 download_tracepoint_locations ();
12146 breakpoint_retire_moribund (void)
12148 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
12150 struct bp_location
*loc
= moribund_locations
[ix
];
12151 if (--(loc
->events_till_retirement
) == 0)
12153 decref_bp_location (&loc
);
12154 unordered_remove (moribund_locations
, ix
);
12161 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12166 update_global_location_list (insert_mode
);
12168 catch (const gdb_exception_error
&e
)
12173 /* Clear BKP from a BPS. */
12176 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12180 for (bs
= bps
; bs
; bs
= bs
->next
)
12181 if (bs
->breakpoint_at
== bpt
)
12183 bs
->breakpoint_at
= NULL
;
12184 bs
->old_val
= NULL
;
12185 /* bs->commands will be freed later. */
12189 /* Callback for iterate_over_threads. */
12191 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12193 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12195 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12199 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12203 say_where (struct breakpoint
*b
)
12205 struct value_print_options opts
;
12207 get_user_print_options (&opts
);
12209 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12211 if (b
->loc
== NULL
)
12213 /* For pending locations, the output differs slightly based
12214 on b->extra_string. If this is non-NULL, it contains either
12215 a condition or dprintf arguments. */
12216 if (b
->extra_string
== NULL
)
12218 printf_filtered (_(" (%s) pending."),
12219 event_location_to_string (b
->location
.get ()));
12221 else if (b
->type
== bp_dprintf
)
12223 printf_filtered (_(" (%s,%s) pending."),
12224 event_location_to_string (b
->location
.get ()),
12229 printf_filtered (_(" (%s %s) pending."),
12230 event_location_to_string (b
->location
.get ()),
12236 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12237 printf_filtered (" at %ps",
12238 styled_string (address_style
.style (),
12239 paddress (b
->loc
->gdbarch
,
12240 b
->loc
->address
)));
12241 if (b
->loc
->symtab
!= NULL
)
12243 /* If there is a single location, we can print the location
12245 if (b
->loc
->next
== NULL
)
12247 const char *filename
12248 = symtab_to_filename_for_display (b
->loc
->symtab
);
12249 printf_filtered (": file %ps, line %d.",
12250 styled_string (file_name_style
.style (),
12252 b
->loc
->line_number
);
12255 /* This is not ideal, but each location may have a
12256 different file name, and this at least reflects the
12257 real situation somewhat. */
12258 printf_filtered (": %s.",
12259 event_location_to_string (b
->location
.get ()));
12264 struct bp_location
*loc
= b
->loc
;
12266 for (; loc
; loc
= loc
->next
)
12268 printf_filtered (" (%d locations)", n
);
12273 bp_location::~bp_location ()
12275 xfree (function_name
);
12278 /* Destructor for the breakpoint base class. */
12280 breakpoint::~breakpoint ()
12282 xfree (this->cond_string
);
12283 xfree (this->extra_string
);
12286 /* See breakpoint.h. */
12288 bp_locations_range
breakpoint::locations ()
12290 return bp_locations_range (this->loc
);
12293 static struct bp_location
*
12294 base_breakpoint_allocate_location (struct breakpoint
*self
)
12296 return new bp_location (self
);
12300 base_breakpoint_re_set (struct breakpoint
*b
)
12302 /* Nothing to re-set. */
12305 #define internal_error_pure_virtual_called() \
12306 gdb_assert_not_reached ("pure virtual function called")
12309 base_breakpoint_insert_location (struct bp_location
*bl
)
12311 internal_error_pure_virtual_called ();
12315 base_breakpoint_remove_location (struct bp_location
*bl
,
12316 enum remove_bp_reason reason
)
12318 internal_error_pure_virtual_called ();
12322 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12323 const address_space
*aspace
,
12325 const struct target_waitstatus
*ws
)
12327 internal_error_pure_virtual_called ();
12331 base_breakpoint_check_status (bpstat bs
)
12336 /* A "works_in_software_mode" breakpoint_ops method that just internal
12340 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12342 internal_error_pure_virtual_called ();
12345 /* A "resources_needed" breakpoint_ops method that just internal
12349 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12351 internal_error_pure_virtual_called ();
12354 static enum print_stop_action
12355 base_breakpoint_print_it (bpstat bs
)
12357 internal_error_pure_virtual_called ();
12361 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12362 struct ui_out
*uiout
)
12368 base_breakpoint_print_mention (struct breakpoint
*b
)
12370 internal_error_pure_virtual_called ();
12374 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12376 internal_error_pure_virtual_called ();
12380 base_breakpoint_create_sals_from_location
12381 (struct event_location
*location
,
12382 struct linespec_result
*canonical
,
12383 enum bptype type_wanted
)
12385 internal_error_pure_virtual_called ();
12389 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12390 struct linespec_result
*c
,
12391 gdb::unique_xmalloc_ptr
<char> cond_string
,
12392 gdb::unique_xmalloc_ptr
<char> extra_string
,
12393 enum bptype type_wanted
,
12394 enum bpdisp disposition
,
12396 int task
, int ignore_count
,
12397 const struct breakpoint_ops
*o
,
12398 int from_tty
, int enabled
,
12399 int internal
, unsigned flags
)
12401 internal_error_pure_virtual_called ();
12404 static std::vector
<symtab_and_line
>
12405 base_breakpoint_decode_location (struct breakpoint
*b
,
12406 struct event_location
*location
,
12407 struct program_space
*search_pspace
)
12409 internal_error_pure_virtual_called ();
12412 /* The default 'explains_signal' method. */
12415 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12420 /* The default "after_condition_true" method. */
12423 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12425 /* Nothing to do. */
12428 struct breakpoint_ops base_breakpoint_ops
=
12430 base_breakpoint_allocate_location
,
12431 base_breakpoint_re_set
,
12432 base_breakpoint_insert_location
,
12433 base_breakpoint_remove_location
,
12434 base_breakpoint_breakpoint_hit
,
12435 base_breakpoint_check_status
,
12436 base_breakpoint_resources_needed
,
12437 base_breakpoint_works_in_software_mode
,
12438 base_breakpoint_print_it
,
12440 base_breakpoint_print_one_detail
,
12441 base_breakpoint_print_mention
,
12442 base_breakpoint_print_recreate
,
12443 base_breakpoint_create_sals_from_location
,
12444 base_breakpoint_create_breakpoints_sal
,
12445 base_breakpoint_decode_location
,
12446 base_breakpoint_explains_signal
,
12447 base_breakpoint_after_condition_true
,
12450 /* Default breakpoint_ops methods. */
12453 bkpt_re_set (struct breakpoint
*b
)
12455 /* FIXME: is this still reachable? */
12456 if (breakpoint_event_location_empty_p (b
))
12458 /* Anything without a location can't be re-set. */
12459 delete_breakpoint (b
);
12463 breakpoint_re_set_default (b
);
12467 bkpt_insert_location (struct bp_location
*bl
)
12469 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12471 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12472 bl
->target_info
.placed_address
= addr
;
12474 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12475 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12477 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12481 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12483 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12484 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12486 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12490 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12491 const address_space
*aspace
, CORE_ADDR bp_addr
,
12492 const struct target_waitstatus
*ws
)
12494 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12495 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12498 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12502 if (overlay_debugging
/* unmapped overlay section */
12503 && section_is_overlay (bl
->section
)
12504 && !section_is_mapped (bl
->section
))
12511 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12512 const address_space
*aspace
, CORE_ADDR bp_addr
,
12513 const struct target_waitstatus
*ws
)
12515 if (dprintf_style
== dprintf_style_agent
12516 && target_can_run_breakpoint_commands ())
12518 /* An agent-style dprintf never causes a stop. If we see a trap
12519 for this address it must be for a breakpoint that happens to
12520 be set at the same address. */
12524 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12528 bkpt_resources_needed (const struct bp_location
*bl
)
12530 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12535 static enum print_stop_action
12536 bkpt_print_it (bpstat bs
)
12538 struct breakpoint
*b
;
12539 const struct bp_location
*bl
;
12541 struct ui_out
*uiout
= current_uiout
;
12543 gdb_assert (bs
->bp_location_at
!= NULL
);
12545 bl
= bs
->bp_location_at
.get ();
12546 b
= bs
->breakpoint_at
;
12548 bp_temp
= b
->disposition
== disp_del
;
12549 if (bl
->address
!= bl
->requested_address
)
12550 breakpoint_adjustment_warning (bl
->requested_address
,
12553 annotate_breakpoint (b
->number
);
12554 maybe_print_thread_hit_breakpoint (uiout
);
12556 if (uiout
->is_mi_like_p ())
12558 uiout
->field_string ("reason",
12559 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12560 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12563 uiout
->message ("Temporary breakpoint %pF, ",
12564 signed_field ("bkptno", b
->number
));
12566 uiout
->message ("Breakpoint %pF, ",
12567 signed_field ("bkptno", b
->number
));
12569 return PRINT_SRC_AND_LOC
;
12573 bkpt_print_mention (struct breakpoint
*b
)
12575 if (current_uiout
->is_mi_like_p ())
12580 case bp_breakpoint
:
12581 case bp_gnu_ifunc_resolver
:
12582 if (b
->disposition
== disp_del
)
12583 printf_filtered (_("Temporary breakpoint"));
12585 printf_filtered (_("Breakpoint"));
12586 printf_filtered (_(" %d"), b
->number
);
12587 if (b
->type
== bp_gnu_ifunc_resolver
)
12588 printf_filtered (_(" at gnu-indirect-function resolver"));
12590 case bp_hardware_breakpoint
:
12591 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12594 printf_filtered (_("Dprintf %d"), b
->number
);
12602 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12604 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12605 fprintf_unfiltered (fp
, "tbreak");
12606 else if (tp
->type
== bp_breakpoint
)
12607 fprintf_unfiltered (fp
, "break");
12608 else if (tp
->type
== bp_hardware_breakpoint
12609 && tp
->disposition
== disp_del
)
12610 fprintf_unfiltered (fp
, "thbreak");
12611 else if (tp
->type
== bp_hardware_breakpoint
)
12612 fprintf_unfiltered (fp
, "hbreak");
12614 internal_error (__FILE__
, __LINE__
,
12615 _("unhandled breakpoint type %d"), (int) tp
->type
);
12617 fprintf_unfiltered (fp
, " %s",
12618 event_location_to_string (tp
->location
.get ()));
12620 /* Print out extra_string if this breakpoint is pending. It might
12621 contain, for example, conditions that were set by the user. */
12622 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12623 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12625 print_recreate_thread (tp
, fp
);
12629 bkpt_create_sals_from_location (struct event_location
*location
,
12630 struct linespec_result
*canonical
,
12631 enum bptype type_wanted
)
12633 create_sals_from_location_default (location
, canonical
, type_wanted
);
12637 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12638 struct linespec_result
*canonical
,
12639 gdb::unique_xmalloc_ptr
<char> cond_string
,
12640 gdb::unique_xmalloc_ptr
<char> extra_string
,
12641 enum bptype type_wanted
,
12642 enum bpdisp disposition
,
12644 int task
, int ignore_count
,
12645 const struct breakpoint_ops
*ops
,
12646 int from_tty
, int enabled
,
12647 int internal
, unsigned flags
)
12649 create_breakpoints_sal_default (gdbarch
, canonical
,
12650 std::move (cond_string
),
12651 std::move (extra_string
),
12653 disposition
, thread
, task
,
12654 ignore_count
, ops
, from_tty
,
12655 enabled
, internal
, flags
);
12658 static std::vector
<symtab_and_line
>
12659 bkpt_decode_location (struct breakpoint
*b
,
12660 struct event_location
*location
,
12661 struct program_space
*search_pspace
)
12663 return decode_location_default (b
, location
, search_pspace
);
12666 /* Virtual table for internal breakpoints. */
12669 internal_bkpt_re_set (struct breakpoint
*b
)
12673 /* Delete overlay event and longjmp master breakpoints; they
12674 will be reset later by breakpoint_re_set. */
12675 case bp_overlay_event
:
12676 case bp_longjmp_master
:
12677 case bp_std_terminate_master
:
12678 case bp_exception_master
:
12679 delete_breakpoint (b
);
12682 /* This breakpoint is special, it's set up when the inferior
12683 starts and we really don't want to touch it. */
12684 case bp_shlib_event
:
12686 /* Like bp_shlib_event, this breakpoint type is special. Once
12687 it is set up, we do not want to touch it. */
12688 case bp_thread_event
:
12694 internal_bkpt_check_status (bpstat bs
)
12696 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12698 /* If requested, stop when the dynamic linker notifies GDB of
12699 events. This allows the user to get control and place
12700 breakpoints in initializer routines for dynamically loaded
12701 objects (among other things). */
12702 bs
->stop
= stop_on_solib_events
;
12703 bs
->print
= stop_on_solib_events
;
12709 static enum print_stop_action
12710 internal_bkpt_print_it (bpstat bs
)
12712 struct breakpoint
*b
;
12714 b
= bs
->breakpoint_at
;
12718 case bp_shlib_event
:
12719 /* Did we stop because the user set the stop_on_solib_events
12720 variable? (If so, we report this as a generic, "Stopped due
12721 to shlib event" message.) */
12722 print_solib_event (0);
12725 case bp_thread_event
:
12726 /* Not sure how we will get here.
12727 GDB should not stop for these breakpoints. */
12728 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12731 case bp_overlay_event
:
12732 /* By analogy with the thread event, GDB should not stop for these. */
12733 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12736 case bp_longjmp_master
:
12737 /* These should never be enabled. */
12738 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12741 case bp_std_terminate_master
:
12742 /* These should never be enabled. */
12743 printf_filtered (_("std::terminate Master Breakpoint: "
12744 "gdb should not stop!\n"));
12747 case bp_exception_master
:
12748 /* These should never be enabled. */
12749 printf_filtered (_("Exception Master Breakpoint: "
12750 "gdb should not stop!\n"));
12754 return PRINT_NOTHING
;
12758 internal_bkpt_print_mention (struct breakpoint
*b
)
12760 /* Nothing to mention. These breakpoints are internal. */
12763 /* Virtual table for momentary breakpoints */
12766 momentary_bkpt_re_set (struct breakpoint
*b
)
12768 /* Keep temporary breakpoints, which can be encountered when we step
12769 over a dlopen call and solib_add is resetting the breakpoints.
12770 Otherwise these should have been blown away via the cleanup chain
12771 or by breakpoint_init_inferior when we rerun the executable. */
12775 momentary_bkpt_check_status (bpstat bs
)
12777 /* Nothing. The point of these breakpoints is causing a stop. */
12780 static enum print_stop_action
12781 momentary_bkpt_print_it (bpstat bs
)
12783 return PRINT_UNKNOWN
;
12787 momentary_bkpt_print_mention (struct breakpoint
*b
)
12789 /* Nothing to mention. These breakpoints are internal. */
12792 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12794 It gets cleared already on the removal of the first one of such placed
12795 breakpoints. This is OK as they get all removed altogether. */
12797 longjmp_breakpoint::~longjmp_breakpoint ()
12799 thread_info
*tp
= find_thread_global_id (this->thread
);
12802 tp
->initiating_frame
= null_frame_id
;
12805 /* Specific methods for probe breakpoints. */
12808 bkpt_probe_insert_location (struct bp_location
*bl
)
12810 int v
= bkpt_insert_location (bl
);
12814 /* The insertion was successful, now let's set the probe's semaphore
12816 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12823 bkpt_probe_remove_location (struct bp_location
*bl
,
12824 enum remove_bp_reason reason
)
12826 /* Let's clear the semaphore before removing the location. */
12827 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12829 return bkpt_remove_location (bl
, reason
);
12833 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12834 struct linespec_result
*canonical
,
12835 enum bptype type_wanted
)
12837 struct linespec_sals lsal
;
12839 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12841 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12842 canonical
->lsals
.push_back (std::move (lsal
));
12845 static std::vector
<symtab_and_line
>
12846 bkpt_probe_decode_location (struct breakpoint
*b
,
12847 struct event_location
*location
,
12848 struct program_space
*search_pspace
)
12850 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12852 error (_("probe not found"));
12856 /* The breakpoint_ops structure to be used in tracepoints. */
12859 tracepoint_re_set (struct breakpoint
*b
)
12861 breakpoint_re_set_default (b
);
12865 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12866 const address_space
*aspace
, CORE_ADDR bp_addr
,
12867 const struct target_waitstatus
*ws
)
12869 /* By definition, the inferior does not report stops at
12875 tracepoint_print_one_detail (const struct breakpoint
*self
,
12876 struct ui_out
*uiout
)
12878 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12879 if (!tp
->static_trace_marker_id
.empty ())
12881 gdb_assert (self
->type
== bp_static_tracepoint
);
12883 uiout
->message ("\tmarker id is %pF\n",
12884 string_field ("static-tracepoint-marker-string-id",
12885 tp
->static_trace_marker_id
.c_str ()));
12890 tracepoint_print_mention (struct breakpoint
*b
)
12892 if (current_uiout
->is_mi_like_p ())
12897 case bp_tracepoint
:
12898 printf_filtered (_("Tracepoint"));
12899 printf_filtered (_(" %d"), b
->number
);
12901 case bp_fast_tracepoint
:
12902 printf_filtered (_("Fast tracepoint"));
12903 printf_filtered (_(" %d"), b
->number
);
12905 case bp_static_tracepoint
:
12906 printf_filtered (_("Static tracepoint"));
12907 printf_filtered (_(" %d"), b
->number
);
12910 internal_error (__FILE__
, __LINE__
,
12911 _("unhandled tracepoint type %d"), (int) b
->type
);
12918 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12920 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12922 if (self
->type
== bp_fast_tracepoint
)
12923 fprintf_unfiltered (fp
, "ftrace");
12924 else if (self
->type
== bp_static_tracepoint
)
12925 fprintf_unfiltered (fp
, "strace");
12926 else if (self
->type
== bp_tracepoint
)
12927 fprintf_unfiltered (fp
, "trace");
12929 internal_error (__FILE__
, __LINE__
,
12930 _("unhandled tracepoint type %d"), (int) self
->type
);
12932 fprintf_unfiltered (fp
, " %s",
12933 event_location_to_string (self
->location
.get ()));
12934 print_recreate_thread (self
, fp
);
12936 if (tp
->pass_count
)
12937 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12941 tracepoint_create_sals_from_location (struct event_location
*location
,
12942 struct linespec_result
*canonical
,
12943 enum bptype type_wanted
)
12945 create_sals_from_location_default (location
, canonical
, type_wanted
);
12949 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12950 struct linespec_result
*canonical
,
12951 gdb::unique_xmalloc_ptr
<char> cond_string
,
12952 gdb::unique_xmalloc_ptr
<char> extra_string
,
12953 enum bptype type_wanted
,
12954 enum bpdisp disposition
,
12956 int task
, int ignore_count
,
12957 const struct breakpoint_ops
*ops
,
12958 int from_tty
, int enabled
,
12959 int internal
, unsigned flags
)
12961 create_breakpoints_sal_default (gdbarch
, canonical
,
12962 std::move (cond_string
),
12963 std::move (extra_string
),
12965 disposition
, thread
, task
,
12966 ignore_count
, ops
, from_tty
,
12967 enabled
, internal
, flags
);
12970 static std::vector
<symtab_and_line
>
12971 tracepoint_decode_location (struct breakpoint
*b
,
12972 struct event_location
*location
,
12973 struct program_space
*search_pspace
)
12975 return decode_location_default (b
, location
, search_pspace
);
12978 struct breakpoint_ops tracepoint_breakpoint_ops
;
12980 /* Virtual table for tracepoints on static probes. */
12983 tracepoint_probe_create_sals_from_location
12984 (struct event_location
*location
,
12985 struct linespec_result
*canonical
,
12986 enum bptype type_wanted
)
12988 /* We use the same method for breakpoint on probes. */
12989 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
12992 static std::vector
<symtab_and_line
>
12993 tracepoint_probe_decode_location (struct breakpoint
*b
,
12994 struct event_location
*location
,
12995 struct program_space
*search_pspace
)
12997 /* We use the same method for breakpoint on probes. */
12998 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13001 /* Dprintf breakpoint_ops methods. */
13004 dprintf_re_set (struct breakpoint
*b
)
13006 breakpoint_re_set_default (b
);
13008 /* extra_string should never be non-NULL for dprintf. */
13009 gdb_assert (b
->extra_string
!= NULL
);
13011 /* 1 - connect to target 1, that can run breakpoint commands.
13012 2 - create a dprintf, which resolves fine.
13013 3 - disconnect from target 1
13014 4 - connect to target 2, that can NOT run breakpoint commands.
13016 After steps #3/#4, you'll want the dprintf command list to
13017 be updated, because target 1 and 2 may well return different
13018 answers for target_can_run_breakpoint_commands().
13019 Given absence of finer grained resetting, we get to do
13020 it all the time. */
13021 if (b
->extra_string
!= NULL
)
13022 update_dprintf_command_list (b
);
13025 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13028 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13030 fprintf_unfiltered (fp
, "dprintf %s,%s",
13031 event_location_to_string (tp
->location
.get ()),
13033 print_recreate_thread (tp
, fp
);
13036 /* Implement the "after_condition_true" breakpoint_ops method for
13039 dprintf's are implemented with regular commands in their command
13040 list, but we run the commands here instead of before presenting the
13041 stop to the user, as dprintf's don't actually cause a stop. This
13042 also makes it so that the commands of multiple dprintfs at the same
13043 address are all handled. */
13046 dprintf_after_condition_true (struct bpstats
*bs
)
13048 struct bpstats tmp_bs
;
13049 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13051 /* dprintf's never cause a stop. This wasn't set in the
13052 check_status hook instead because that would make the dprintf's
13053 condition not be evaluated. */
13056 /* Run the command list here. Take ownership of it instead of
13057 copying. We never want these commands to run later in
13058 bpstat_do_actions, if a breakpoint that causes a stop happens to
13059 be set at same address as this dprintf, or even if running the
13060 commands here throws. */
13061 tmp_bs
.commands
= bs
->commands
;
13062 bs
->commands
= NULL
;
13064 bpstat_do_actions_1 (&tmp_bs_p
);
13066 /* 'tmp_bs.commands' will usually be NULL by now, but
13067 bpstat_do_actions_1 may return early without processing the whole
13071 /* The breakpoint_ops structure to be used on static tracepoints with
13075 strace_marker_create_sals_from_location (struct event_location
*location
,
13076 struct linespec_result
*canonical
,
13077 enum bptype type_wanted
)
13079 struct linespec_sals lsal
;
13080 const char *arg_start
, *arg
;
13082 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
13083 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13085 std::string
str (arg_start
, arg
- arg_start
);
13086 const char *ptr
= str
.c_str ();
13087 canonical
->location
13088 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
13091 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13092 canonical
->lsals
.push_back (std::move (lsal
));
13096 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13097 struct linespec_result
*canonical
,
13098 gdb::unique_xmalloc_ptr
<char> cond_string
,
13099 gdb::unique_xmalloc_ptr
<char> extra_string
,
13100 enum bptype type_wanted
,
13101 enum bpdisp disposition
,
13103 int task
, int ignore_count
,
13104 const struct breakpoint_ops
*ops
,
13105 int from_tty
, int enabled
,
13106 int internal
, unsigned flags
)
13108 const linespec_sals
&lsal
= canonical
->lsals
[0];
13110 /* If the user is creating a static tracepoint by marker id
13111 (strace -m MARKER_ID), then store the sals index, so that
13112 breakpoint_re_set can try to match up which of the newly
13113 found markers corresponds to this one, and, don't try to
13114 expand multiple locations for each sal, given than SALS
13115 already should contain all sals for MARKER_ID. */
13117 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13119 event_location_up location
13120 = copy_event_location (canonical
->location
.get ());
13122 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13123 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13124 std::move (location
), NULL
,
13125 std::move (cond_string
),
13126 std::move (extra_string
),
13127 type_wanted
, disposition
,
13128 thread
, task
, ignore_count
, ops
,
13129 from_tty
, enabled
, internal
, flags
,
13130 canonical
->special_display
);
13131 /* Given that its possible to have multiple markers with
13132 the same string id, if the user is creating a static
13133 tracepoint by marker id ("strace -m MARKER_ID"), then
13134 store the sals index, so that breakpoint_re_set can
13135 try to match up which of the newly found markers
13136 corresponds to this one */
13137 tp
->static_trace_marker_id_idx
= i
;
13139 install_breakpoint (internal
, std::move (tp
), 0);
13143 static std::vector
<symtab_and_line
>
13144 strace_marker_decode_location (struct breakpoint
*b
,
13145 struct event_location
*location
,
13146 struct program_space
*search_pspace
)
13148 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13149 const char *s
= get_linespec_location (location
)->spec_string
;
13151 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13152 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13154 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13159 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
13162 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13165 strace_marker_p (struct breakpoint
*b
)
13167 return b
->ops
== &strace_marker_breakpoint_ops
;
13170 /* Delete a breakpoint and clean up all traces of it in the data
13174 delete_breakpoint (struct breakpoint
*bpt
)
13176 gdb_assert (bpt
!= NULL
);
13178 /* Has this bp already been deleted? This can happen because
13179 multiple lists can hold pointers to bp's. bpstat lists are
13182 One example of this happening is a watchpoint's scope bp. When
13183 the scope bp triggers, we notice that the watchpoint is out of
13184 scope, and delete it. We also delete its scope bp. But the
13185 scope bp is marked "auto-deleting", and is already on a bpstat.
13186 That bpstat is then checked for auto-deleting bp's, which are
13189 A real solution to this problem might involve reference counts in
13190 bp's, and/or giving them pointers back to their referencing
13191 bpstat's, and teaching delete_breakpoint to only free a bp's
13192 storage when no more references were extent. A cheaper bandaid
13194 if (bpt
->type
== bp_none
)
13197 /* At least avoid this stale reference until the reference counting
13198 of breakpoints gets resolved. */
13199 if (bpt
->related_breakpoint
!= bpt
)
13201 struct breakpoint
*related
;
13202 struct watchpoint
*w
;
13204 if (bpt
->type
== bp_watchpoint_scope
)
13205 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13206 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13207 w
= (struct watchpoint
*) bpt
;
13211 watchpoint_del_at_next_stop (w
);
13213 /* Unlink bpt from the bpt->related_breakpoint ring. */
13214 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13215 related
= related
->related_breakpoint
);
13216 related
->related_breakpoint
= bpt
->related_breakpoint
;
13217 bpt
->related_breakpoint
= bpt
;
13220 /* watch_command_1 creates a watchpoint but only sets its number if
13221 update_watchpoint succeeds in creating its bp_locations. If there's
13222 a problem in that process, we'll be asked to delete the half-created
13223 watchpoint. In that case, don't announce the deletion. */
13225 gdb::observers::breakpoint_deleted
.notify (bpt
);
13227 if (breakpoint_chain
== bpt
)
13228 breakpoint_chain
= bpt
->next
;
13230 for (breakpoint
*b
: all_breakpoints ())
13231 if (b
->next
== bpt
)
13233 b
->next
= bpt
->next
;
13237 /* Be sure no bpstat's are pointing at the breakpoint after it's
13239 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13240 in all threads for now. Note that we cannot just remove bpstats
13241 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13242 commands are associated with the bpstat; if we remove it here,
13243 then the later call to bpstat_do_actions (&stop_bpstat); in
13244 event-top.c won't do anything, and temporary breakpoints with
13245 commands won't work. */
13247 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13249 /* Now that breakpoint is removed from breakpoint list, update the
13250 global location list. This will remove locations that used to
13251 belong to this breakpoint. Do this before freeing the breakpoint
13252 itself, since remove_breakpoint looks at location's owner. It
13253 might be better design to have location completely
13254 self-contained, but it's not the case now. */
13255 update_global_location_list (UGLL_DONT_INSERT
);
13257 /* On the chance that someone will soon try again to delete this
13258 same bp, we mark it as deleted before freeing its storage. */
13259 bpt
->type
= bp_none
;
13263 /* Iterator function to call a user-provided callback function once
13264 for each of B and its related breakpoints. */
13267 iterate_over_related_breakpoints (struct breakpoint
*b
,
13268 gdb::function_view
<void (breakpoint
*)> function
)
13270 struct breakpoint
*related
;
13275 struct breakpoint
*next
;
13277 /* FUNCTION may delete RELATED. */
13278 next
= related
->related_breakpoint
;
13280 if (next
== related
)
13282 /* RELATED is the last ring entry. */
13283 function (related
);
13285 /* FUNCTION may have deleted it, so we'd never reach back to
13286 B. There's nothing left to do anyway, so just break
13291 function (related
);
13295 while (related
!= b
);
13299 delete_command (const char *arg
, int from_tty
)
13305 int breaks_to_delete
= 0;
13307 /* Delete all breakpoints if no argument. Do not delete
13308 internal breakpoints, these have to be deleted with an
13309 explicit breakpoint number argument. */
13310 for (breakpoint
*b
: all_breakpoints ())
13311 if (user_breakpoint_p (b
))
13313 breaks_to_delete
= 1;
13317 /* Ask user only if there are some breakpoints to delete. */
13319 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13320 for (breakpoint
*b
: all_breakpoints_safe ())
13321 if (user_breakpoint_p (b
))
13322 delete_breakpoint (b
);
13325 map_breakpoint_numbers
13326 (arg
, [&] (breakpoint
*br
)
13328 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13332 /* Return true if all locations of B bound to PSPACE are pending. If
13333 PSPACE is NULL, all locations of all program spaces are
13337 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13339 for (bp_location
*loc
: b
->locations ())
13340 if ((pspace
== NULL
13341 || loc
->pspace
== pspace
)
13342 && !loc
->shlib_disabled
13343 && !loc
->pspace
->executing_startup
)
13348 /* Subroutine of update_breakpoint_locations to simplify it.
13349 Return non-zero if multiple fns in list LOC have the same name.
13350 Null names are ignored. */
13353 ambiguous_names_p (struct bp_location
*loc
)
13355 struct bp_location
*l
;
13356 htab_up
htab (htab_create_alloc (13, htab_hash_string
, htab_eq_string
, NULL
,
13359 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13362 const char *name
= l
->function_name
;
13364 /* Allow for some names to be NULL, ignore them. */
13368 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
13370 /* NOTE: We can assume slot != NULL here because xcalloc never
13380 /* When symbols change, it probably means the sources changed as well,
13381 and it might mean the static tracepoint markers are no longer at
13382 the same address or line numbers they used to be at last we
13383 checked. Losing your static tracepoints whenever you rebuild is
13384 undesirable. This function tries to resync/rematch gdb static
13385 tracepoints with the markers on the target, for static tracepoints
13386 that have not been set by marker id. Static tracepoint that have
13387 been set by marker id are reset by marker id in breakpoint_re_set.
13390 1) For a tracepoint set at a specific address, look for a marker at
13391 the old PC. If one is found there, assume to be the same marker.
13392 If the name / string id of the marker found is different from the
13393 previous known name, assume that means the user renamed the marker
13394 in the sources, and output a warning.
13396 2) For a tracepoint set at a given line number, look for a marker
13397 at the new address of the old line number. If one is found there,
13398 assume to be the same marker. If the name / string id of the
13399 marker found is different from the previous known name, assume that
13400 means the user renamed the marker in the sources, and output a
13403 3) If a marker is no longer found at the same address or line, it
13404 may mean the marker no longer exists. But it may also just mean
13405 the code changed a bit. Maybe the user added a few lines of code
13406 that made the marker move up or down (in line number terms). Ask
13407 the target for info about the marker with the string id as we knew
13408 it. If found, update line number and address in the matching
13409 static tracepoint. This will get confused if there's more than one
13410 marker with the same ID (possible in UST, although unadvised
13411 precisely because it confuses tools). */
13413 static struct symtab_and_line
13414 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13416 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13417 struct static_tracepoint_marker marker
;
13422 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13424 if (target_static_tracepoint_marker_at (pc
, &marker
))
13426 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13427 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13428 b
->number
, tp
->static_trace_marker_id
.c_str (),
13429 marker
.str_id
.c_str ());
13431 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13436 /* Old marker wasn't found on target at lineno. Try looking it up
13438 if (!sal
.explicit_pc
13440 && sal
.symtab
!= NULL
13441 && !tp
->static_trace_marker_id
.empty ())
13443 std::vector
<static_tracepoint_marker
> markers
13444 = target_static_tracepoint_markers_by_strid
13445 (tp
->static_trace_marker_id
.c_str ());
13447 if (!markers
.empty ())
13449 struct symbol
*sym
;
13450 struct static_tracepoint_marker
*tpmarker
;
13451 struct ui_out
*uiout
= current_uiout
;
13452 struct explicit_location explicit_loc
;
13454 tpmarker
= &markers
[0];
13456 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13458 warning (_("marker for static tracepoint %d (%s) not "
13459 "found at previous line number"),
13460 b
->number
, tp
->static_trace_marker_id
.c_str ());
13462 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13463 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13464 uiout
->text ("Now in ");
13467 uiout
->field_string ("func", sym
->print_name (),
13468 function_name_style
.style ());
13469 uiout
->text (" at ");
13471 uiout
->field_string ("file",
13472 symtab_to_filename_for_display (sal2
.symtab
),
13473 file_name_style
.style ());
13476 if (uiout
->is_mi_like_p ())
13478 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13480 uiout
->field_string ("fullname", fullname
);
13483 uiout
->field_signed ("line", sal2
.line
);
13484 uiout
->text ("\n");
13486 b
->loc
->line_number
= sal2
.line
;
13487 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13489 b
->location
.reset (NULL
);
13490 initialize_explicit_location (&explicit_loc
);
13491 explicit_loc
.source_filename
13492 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13493 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13494 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13495 b
->location
= new_explicit_location (&explicit_loc
);
13497 /* Might be nice to check if function changed, and warn if
13504 /* Returns 1 iff locations A and B are sufficiently same that
13505 we don't need to report breakpoint as changed. */
13508 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13512 if (a
->address
!= b
->address
)
13515 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13518 if (a
->enabled
!= b
->enabled
)
13521 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
13528 if ((a
== NULL
) != (b
== NULL
))
13534 /* Split all locations of B that are bound to PSPACE out of B's
13535 location list to a separate list and return that list's head. If
13536 PSPACE is NULL, hoist out all locations of B. */
13538 static struct bp_location
*
13539 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13541 struct bp_location head
;
13542 struct bp_location
*i
= b
->loc
;
13543 struct bp_location
**i_link
= &b
->loc
;
13544 struct bp_location
*hoisted
= &head
;
13546 if (pspace
== NULL
)
13557 if (i
->pspace
== pspace
)
13572 /* Create new breakpoint locations for B (a hardware or software
13573 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13574 zero, then B is a ranged breakpoint. Only recreates locations for
13575 FILTER_PSPACE. Locations of other program spaces are left
13579 update_breakpoint_locations (struct breakpoint
*b
,
13580 struct program_space
*filter_pspace
,
13581 gdb::array_view
<const symtab_and_line
> sals
,
13582 gdb::array_view
<const symtab_and_line
> sals_end
)
13584 struct bp_location
*existing_locations
;
13586 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13588 /* Ranged breakpoints have only one start location and one end
13590 b
->enable_state
= bp_disabled
;
13591 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13592 "multiple locations found\n"),
13597 /* If there's no new locations, and all existing locations are
13598 pending, don't do anything. This optimizes the common case where
13599 all locations are in the same shared library, that was unloaded.
13600 We'd like to retain the location, so that when the library is
13601 loaded again, we don't loose the enabled/disabled status of the
13602 individual locations. */
13603 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13606 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13608 for (const auto &sal
: sals
)
13610 struct bp_location
*new_loc
;
13612 switch_to_program_space_and_thread (sal
.pspace
);
13614 new_loc
= add_location_to_breakpoint (b
, &sal
);
13616 /* Reparse conditions, they might contain references to the
13618 if (b
->cond_string
!= NULL
)
13622 s
= b
->cond_string
;
13625 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13626 block_for_pc (sal
.pc
),
13629 catch (const gdb_exception_error
&e
)
13631 new_loc
->disabled_by_cond
= true;
13635 if (!sals_end
.empty ())
13637 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13639 new_loc
->length
= end
- sals
[0].pc
+ 1;
13643 /* If possible, carry over 'disable' status from existing
13646 struct bp_location
*e
= existing_locations
;
13647 /* If there are multiple breakpoints with the same function name,
13648 e.g. for inline functions, comparing function names won't work.
13649 Instead compare pc addresses; this is just a heuristic as things
13650 may have moved, but in practice it gives the correct answer
13651 often enough until a better solution is found. */
13652 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13654 for (; e
; e
= e
->next
)
13656 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
13658 if (have_ambiguous_names
)
13660 for (bp_location
*l
: b
->locations ())
13662 /* Ignore software vs hardware location type at
13663 this point, because with "set breakpoint
13664 auto-hw", after a re-set, locations that were
13665 hardware can end up as software, or vice versa.
13666 As mentioned above, this is an heuristic and in
13667 practice should give the correct answer often
13669 if (breakpoint_locations_match (e
, l
, true))
13671 l
->enabled
= e
->enabled
;
13672 l
->disabled_by_cond
= e
->disabled_by_cond
;
13679 for (bp_location
*l
: b
->locations ())
13680 if (l
->function_name
13681 && strcmp (e
->function_name
, l
->function_name
) == 0)
13683 l
->enabled
= e
->enabled
;
13684 l
->disabled_by_cond
= e
->disabled_by_cond
;
13692 if (!locations_are_equal (existing_locations
, b
->loc
))
13693 gdb::observers::breakpoint_modified
.notify (b
);
13696 /* Find the SaL locations corresponding to the given LOCATION.
13697 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13699 static std::vector
<symtab_and_line
>
13700 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13701 struct program_space
*search_pspace
, int *found
)
13703 struct gdb_exception exception
;
13705 gdb_assert (b
->ops
!= NULL
);
13707 std::vector
<symtab_and_line
> sals
;
13711 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13713 catch (gdb_exception_error
&e
)
13715 int not_found_and_ok
= 0;
13717 /* For pending breakpoints, it's expected that parsing will
13718 fail until the right shared library is loaded. User has
13719 already told to create pending breakpoints and don't need
13720 extra messages. If breakpoint is in bp_shlib_disabled
13721 state, then user already saw the message about that
13722 breakpoint being disabled, and don't want to see more
13724 if (e
.error
== NOT_FOUND_ERROR
13725 && (b
->condition_not_parsed
13727 && search_pspace
!= NULL
13728 && b
->loc
->pspace
!= search_pspace
)
13729 || (b
->loc
&& b
->loc
->shlib_disabled
)
13730 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13731 || b
->enable_state
== bp_disabled
))
13732 not_found_and_ok
= 1;
13734 if (!not_found_and_ok
)
13736 /* We surely don't want to warn about the same breakpoint
13737 10 times. One solution, implemented here, is disable
13738 the breakpoint on error. Another solution would be to
13739 have separate 'warning emitted' flag. Since this
13740 happens only when a binary has changed, I don't know
13741 which approach is better. */
13742 b
->enable_state
= bp_disabled
;
13746 exception
= std::move (e
);
13749 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13751 for (auto &sal
: sals
)
13752 resolve_sal_pc (&sal
);
13753 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13755 char *cond_string
, *extra_string
;
13758 find_condition_and_thread_for_sals (sals
, b
->extra_string
,
13759 &cond_string
, &thread
,
13760 &task
, &extra_string
);
13761 gdb_assert (b
->cond_string
== NULL
);
13763 b
->cond_string
= cond_string
;
13764 b
->thread
= thread
;
13768 xfree (b
->extra_string
);
13769 b
->extra_string
= extra_string
;
13771 b
->condition_not_parsed
= 0;
13774 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13775 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13785 /* The default re_set method, for typical hardware or software
13786 breakpoints. Reevaluate the breakpoint and recreate its
13790 breakpoint_re_set_default (struct breakpoint
*b
)
13792 struct program_space
*filter_pspace
= current_program_space
;
13793 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13796 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13797 filter_pspace
, &found
);
13799 expanded
= std::move (sals
);
13801 if (b
->location_range_end
!= NULL
)
13803 std::vector
<symtab_and_line
> sals_end
13804 = location_to_sals (b
, b
->location_range_end
.get (),
13805 filter_pspace
, &found
);
13807 expanded_end
= std::move (sals_end
);
13810 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13813 /* Default method for creating SALs from an address string. It basically
13814 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13817 create_sals_from_location_default (struct event_location
*location
,
13818 struct linespec_result
*canonical
,
13819 enum bptype type_wanted
)
13821 parse_breakpoint_sals (location
, canonical
);
13824 /* Call create_breakpoints_sal for the given arguments. This is the default
13825 function for the `create_breakpoints_sal' method of
13829 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13830 struct linespec_result
*canonical
,
13831 gdb::unique_xmalloc_ptr
<char> cond_string
,
13832 gdb::unique_xmalloc_ptr
<char> extra_string
,
13833 enum bptype type_wanted
,
13834 enum bpdisp disposition
,
13836 int task
, int ignore_count
,
13837 const struct breakpoint_ops
*ops
,
13838 int from_tty
, int enabled
,
13839 int internal
, unsigned flags
)
13841 create_breakpoints_sal (gdbarch
, canonical
,
13842 std::move (cond_string
),
13843 std::move (extra_string
),
13844 type_wanted
, disposition
,
13845 thread
, task
, ignore_count
, ops
, from_tty
,
13846 enabled
, internal
, flags
);
13849 /* Decode the line represented by S by calling decode_line_full. This is the
13850 default function for the `decode_location' method of breakpoint_ops. */
13852 static std::vector
<symtab_and_line
>
13853 decode_location_default (struct breakpoint
*b
,
13854 struct event_location
*location
,
13855 struct program_space
*search_pspace
)
13857 struct linespec_result canonical
;
13859 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13860 NULL
, 0, &canonical
, multiple_symbols_all
,
13863 /* We should get 0 or 1 resulting SALs. */
13864 gdb_assert (canonical
.lsals
.size () < 2);
13866 if (!canonical
.lsals
.empty ())
13868 const linespec_sals
&lsal
= canonical
.lsals
[0];
13869 return std::move (lsal
.sals
);
13874 /* Reset a breakpoint. */
13877 breakpoint_re_set_one (breakpoint
*b
)
13879 input_radix
= b
->input_radix
;
13880 set_language (b
->language
);
13882 b
->ops
->re_set (b
);
13885 /* Re-set breakpoint locations for the current program space.
13886 Locations bound to other program spaces are left untouched. */
13889 breakpoint_re_set (void)
13892 scoped_restore_current_language save_language
;
13893 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13894 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13896 /* breakpoint_re_set_one sets the current_language to the language
13897 of the breakpoint it is resetting (see prepare_re_set_context)
13898 before re-evaluating the breakpoint's location. This change can
13899 unfortunately get undone by accident if the language_mode is set
13900 to auto, and we either switch frames, or more likely in this context,
13901 we select the current frame.
13903 We prevent this by temporarily turning the language_mode to
13904 language_mode_manual. We restore it once all breakpoints
13905 have been reset. */
13906 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13907 language_mode
= language_mode_manual
;
13909 /* Note: we must not try to insert locations until after all
13910 breakpoints have been re-set. Otherwise, e.g., when re-setting
13911 breakpoint 1, we'd insert the locations of breakpoint 2, which
13912 hadn't been re-set yet, and thus may have stale locations. */
13914 for (breakpoint
*b
: all_breakpoints_safe ())
13918 breakpoint_re_set_one (b
);
13920 catch (const gdb_exception
&ex
)
13922 exception_fprintf (gdb_stderr
, ex
,
13923 "Error in re-setting breakpoint %d: ",
13928 jit_breakpoint_re_set ();
13931 create_overlay_event_breakpoint ();
13932 create_longjmp_master_breakpoint ();
13933 create_std_terminate_master_breakpoint ();
13934 create_exception_master_breakpoint ();
13936 /* Now we can insert. */
13937 update_global_location_list (UGLL_MAY_INSERT
);
13940 /* Reset the thread number of this breakpoint:
13942 - If the breakpoint is for all threads, leave it as-is.
13943 - Else, reset it to the current thread for inferior_ptid. */
13945 breakpoint_re_set_thread (struct breakpoint
*b
)
13947 if (b
->thread
!= -1)
13949 b
->thread
= inferior_thread ()->global_num
;
13951 /* We're being called after following a fork. The new fork is
13952 selected as current, and unless this was a vfork will have a
13953 different program space from the original thread. Reset that
13955 b
->loc
->pspace
= current_program_space
;
13959 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13960 If from_tty is nonzero, it prints a message to that effect,
13961 which ends with a period (no newline). */
13964 set_ignore_count (int bptnum
, int count
, int from_tty
)
13969 for (breakpoint
*b
: all_breakpoints ())
13970 if (b
->number
== bptnum
)
13972 if (is_tracepoint (b
))
13974 if (from_tty
&& count
!= 0)
13975 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13980 b
->ignore_count
= count
;
13984 printf_filtered (_("Will stop next time "
13985 "breakpoint %d is reached."),
13987 else if (count
== 1)
13988 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13991 printf_filtered (_("Will ignore next %d "
13992 "crossings of breakpoint %d."),
13995 gdb::observers::breakpoint_modified
.notify (b
);
13999 error (_("No breakpoint number %d."), bptnum
);
14002 /* Command to set ignore-count of breakpoint N to COUNT. */
14005 ignore_command (const char *args
, int from_tty
)
14007 const char *p
= args
;
14011 error_no_arg (_("a breakpoint number"));
14013 num
= get_number (&p
);
14015 error (_("bad breakpoint number: '%s'"), args
);
14017 error (_("Second argument (specified ignore-count) is missing."));
14019 set_ignore_count (num
,
14020 longest_to_int (value_as_long (parse_and_eval (p
))),
14023 printf_filtered ("\n");
14027 /* Call FUNCTION on each of the breakpoints with numbers in the range
14028 defined by BP_NUM_RANGE (an inclusive range). */
14031 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
14032 gdb::function_view
<void (breakpoint
*)> function
)
14034 if (bp_num_range
.first
== 0)
14036 warning (_("bad breakpoint number at or near '%d'"),
14037 bp_num_range
.first
);
14041 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
14043 bool match
= false;
14045 for (breakpoint
*b
: all_breakpoints_safe ())
14046 if (b
->number
== i
)
14053 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
14058 /* Call FUNCTION on each of the breakpoints whose numbers are given in
14062 map_breakpoint_numbers (const char *args
,
14063 gdb::function_view
<void (breakpoint
*)> function
)
14065 if (args
== NULL
|| *args
== '\0')
14066 error_no_arg (_("one or more breakpoint numbers"));
14068 number_or_range_parser
parser (args
);
14070 while (!parser
.finished ())
14072 int num
= parser
.get_number ();
14073 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
14077 /* Return the breakpoint location structure corresponding to the
14078 BP_NUM and LOC_NUM values. */
14080 static struct bp_location
*
14081 find_location_by_number (int bp_num
, int loc_num
)
14083 breakpoint
*b
= get_breakpoint (bp_num
);
14085 if (!b
|| b
->number
!= bp_num
)
14086 error (_("Bad breakpoint number '%d'"), bp_num
);
14089 error (_("Bad breakpoint location number '%d'"), loc_num
);
14092 for (bp_location
*loc
: b
->locations ())
14093 if (++n
== loc_num
)
14096 error (_("Bad breakpoint location number '%d'"), loc_num
);
14099 /* Modes of operation for extract_bp_num. */
14100 enum class extract_bp_kind
14102 /* Extracting a breakpoint number. */
14105 /* Extracting a location number. */
14109 /* Extract a breakpoint or location number (as determined by KIND)
14110 from the string starting at START. TRAILER is a character which
14111 can be found after the number. If you don't want a trailer, use
14112 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14113 string. This always returns a positive integer. */
14116 extract_bp_num (extract_bp_kind kind
, const char *start
,
14117 int trailer
, const char **end_out
= NULL
)
14119 const char *end
= start
;
14120 int num
= get_number_trailer (&end
, trailer
);
14122 error (kind
== extract_bp_kind::bp
14123 ? _("Negative breakpoint number '%.*s'")
14124 : _("Negative breakpoint location number '%.*s'"),
14125 int (end
- start
), start
);
14127 error (kind
== extract_bp_kind::bp
14128 ? _("Bad breakpoint number '%.*s'")
14129 : _("Bad breakpoint location number '%.*s'"),
14130 int (end
- start
), start
);
14132 if (end_out
!= NULL
)
14137 /* Extract a breakpoint or location range (as determined by KIND) in
14138 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14139 representing the (inclusive) range. The returned pair's elements
14140 are always positive integers. */
14142 static std::pair
<int, int>
14143 extract_bp_or_bp_range (extract_bp_kind kind
,
14144 const std::string
&arg
,
14145 std::string::size_type arg_offset
)
14147 std::pair
<int, int> range
;
14148 const char *bp_loc
= &arg
[arg_offset
];
14149 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14150 if (dash
!= std::string::npos
)
14152 /* bp_loc is a range (x-z). */
14153 if (arg
.length () == dash
+ 1)
14154 error (kind
== extract_bp_kind::bp
14155 ? _("Bad breakpoint number at or near: '%s'")
14156 : _("Bad breakpoint location number at or near: '%s'"),
14160 const char *start_first
= bp_loc
;
14161 const char *start_second
= &arg
[dash
+ 1];
14162 range
.first
= extract_bp_num (kind
, start_first
, '-');
14163 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14165 if (range
.first
> range
.second
)
14166 error (kind
== extract_bp_kind::bp
14167 ? _("Inverted breakpoint range at '%.*s'")
14168 : _("Inverted breakpoint location range at '%.*s'"),
14169 int (end
- start_first
), start_first
);
14173 /* bp_loc is a single value. */
14174 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14175 range
.second
= range
.first
;
14180 /* Extract the breakpoint/location range specified by ARG. Returns
14181 the breakpoint range in BP_NUM_RANGE, and the location range in
14184 ARG may be in any of the following forms:
14186 x where 'x' is a breakpoint number.
14187 x-y where 'x' and 'y' specify a breakpoint numbers range.
14188 x.y where 'x' is a breakpoint number and 'y' a location number.
14189 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14190 location number range.
14194 extract_bp_number_and_location (const std::string
&arg
,
14195 std::pair
<int, int> &bp_num_range
,
14196 std::pair
<int, int> &bp_loc_range
)
14198 std::string::size_type dot
= arg
.find ('.');
14200 if (dot
!= std::string::npos
)
14202 /* Handle 'x.y' and 'x.y-z' cases. */
14204 if (arg
.length () == dot
+ 1 || dot
== 0)
14205 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14208 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14209 bp_num_range
.second
= bp_num_range
.first
;
14211 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14216 /* Handle x and x-y cases. */
14218 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14219 bp_loc_range
.first
= 0;
14220 bp_loc_range
.second
= 0;
14224 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14225 specifies whether to enable or disable. */
14228 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14230 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14233 if (loc
->disabled_by_cond
&& enable
)
14234 error (_("Breakpoint %d's condition is invalid at location %d, "
14235 "cannot enable."), bp_num
, loc_num
);
14237 if (loc
->enabled
!= enable
)
14239 loc
->enabled
= enable
;
14240 mark_breakpoint_location_modified (loc
);
14242 if (target_supports_enable_disable_tracepoint ()
14243 && current_trace_status ()->running
&& loc
->owner
14244 && is_tracepoint (loc
->owner
))
14245 target_disable_tracepoint (loc
);
14247 update_global_location_list (UGLL_DONT_INSERT
);
14249 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14252 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14253 number of the breakpoint, and BP_LOC_RANGE specifies the
14254 (inclusive) range of location numbers of that breakpoint to
14255 enable/disable. ENABLE specifies whether to enable or disable the
14259 enable_disable_breakpoint_location_range (int bp_num
,
14260 std::pair
<int, int> &bp_loc_range
,
14263 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14264 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14267 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14268 If from_tty is nonzero, it prints a message to that effect,
14269 which ends with a period (no newline). */
14272 disable_breakpoint (struct breakpoint
*bpt
)
14274 /* Never disable a watchpoint scope breakpoint; we want to
14275 hit them when we leave scope so we can delete both the
14276 watchpoint and its scope breakpoint at that time. */
14277 if (bpt
->type
== bp_watchpoint_scope
)
14280 bpt
->enable_state
= bp_disabled
;
14282 /* Mark breakpoint locations modified. */
14283 mark_breakpoint_modified (bpt
);
14285 if (target_supports_enable_disable_tracepoint ()
14286 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14288 for (bp_location
*location
: bpt
->locations ())
14289 target_disable_tracepoint (location
);
14292 update_global_location_list (UGLL_DONT_INSERT
);
14294 gdb::observers::breakpoint_modified
.notify (bpt
);
14297 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14298 specified in ARGS. ARGS may be in any of the formats handled by
14299 extract_bp_number_and_location. ENABLE specifies whether to enable
14300 or disable the breakpoints/locations. */
14303 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14307 for (breakpoint
*bpt
: all_breakpoints ())
14308 if (user_breakpoint_p (bpt
))
14311 enable_breakpoint (bpt
);
14313 disable_breakpoint (bpt
);
14318 std::string num
= extract_arg (&args
);
14320 while (!num
.empty ())
14322 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14324 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14326 if (bp_loc_range
.first
== bp_loc_range
.second
14327 && bp_loc_range
.first
== 0)
14329 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14330 map_breakpoint_number_range (bp_num_range
,
14332 ? enable_breakpoint
14333 : disable_breakpoint
);
14337 /* Handle breakpoint ids with formats 'x.y' or
14339 enable_disable_breakpoint_location_range
14340 (bp_num_range
.first
, bp_loc_range
, enable
);
14342 num
= extract_arg (&args
);
14347 /* The disable command disables the specified breakpoints/locations
14348 (or all defined breakpoints) so they're no longer effective in
14349 stopping the inferior. ARGS may be in any of the forms defined in
14350 extract_bp_number_and_location. */
14353 disable_command (const char *args
, int from_tty
)
14355 enable_disable_command (args
, from_tty
, false);
14359 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14362 int target_resources_ok
;
14364 if (bpt
->type
== bp_hardware_breakpoint
)
14367 i
= hw_breakpoint_used_count ();
14368 target_resources_ok
=
14369 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14371 if (target_resources_ok
== 0)
14372 error (_("No hardware breakpoint support in the target."));
14373 else if (target_resources_ok
< 0)
14374 error (_("Hardware breakpoints used exceeds limit."));
14377 if (is_watchpoint (bpt
))
14379 /* Initialize it just to avoid a GCC false warning. */
14380 enum enable_state orig_enable_state
= bp_disabled
;
14384 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14386 orig_enable_state
= bpt
->enable_state
;
14387 bpt
->enable_state
= bp_enabled
;
14388 update_watchpoint (w
, 1 /* reparse */);
14390 catch (const gdb_exception
&e
)
14392 bpt
->enable_state
= orig_enable_state
;
14393 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14399 bpt
->enable_state
= bp_enabled
;
14401 /* Mark breakpoint locations modified. */
14402 mark_breakpoint_modified (bpt
);
14404 if (target_supports_enable_disable_tracepoint ()
14405 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14407 for (bp_location
*location
: bpt
->locations ())
14408 target_enable_tracepoint (location
);
14411 bpt
->disposition
= disposition
;
14412 bpt
->enable_count
= count
;
14413 update_global_location_list (UGLL_MAY_INSERT
);
14415 gdb::observers::breakpoint_modified
.notify (bpt
);
14420 enable_breakpoint (struct breakpoint
*bpt
)
14422 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14425 /* The enable command enables the specified breakpoints/locations (or
14426 all defined breakpoints) so they once again become (or continue to
14427 be) effective in stopping the inferior. ARGS may be in any of the
14428 forms defined in extract_bp_number_and_location. */
14431 enable_command (const char *args
, int from_tty
)
14433 enable_disable_command (args
, from_tty
, true);
14437 enable_once_command (const char *args
, int from_tty
)
14439 map_breakpoint_numbers
14440 (args
, [&] (breakpoint
*b
)
14442 iterate_over_related_breakpoints
14443 (b
, [&] (breakpoint
*bpt
)
14445 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14451 enable_count_command (const char *args
, int from_tty
)
14456 error_no_arg (_("hit count"));
14458 count
= get_number (&args
);
14460 map_breakpoint_numbers
14461 (args
, [&] (breakpoint
*b
)
14463 iterate_over_related_breakpoints
14464 (b
, [&] (breakpoint
*bpt
)
14466 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14472 enable_delete_command (const char *args
, int from_tty
)
14474 map_breakpoint_numbers
14475 (args
, [&] (breakpoint
*b
)
14477 iterate_over_related_breakpoints
14478 (b
, [&] (breakpoint
*bpt
)
14480 enable_breakpoint_disp (bpt
, disp_del
, 1);
14485 /* Invalidate last known value of any hardware watchpoint if
14486 the memory which that value represents has been written to by
14490 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14491 CORE_ADDR addr
, ssize_t len
,
14492 const bfd_byte
*data
)
14494 for (breakpoint
*bp
: all_breakpoints ())
14495 if (bp
->enable_state
== bp_enabled
14496 && bp
->type
== bp_hardware_watchpoint
)
14498 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14500 if (wp
->val_valid
&& wp
->val
!= nullptr)
14502 for (bp_location
*loc
: bp
->locations ())
14503 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14504 && loc
->address
+ loc
->length
> addr
14505 && addr
+ len
> loc
->address
)
14508 wp
->val_valid
= false;
14514 /* Create and insert a breakpoint for software single step. */
14517 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14518 const address_space
*aspace
,
14521 struct thread_info
*tp
= inferior_thread ();
14522 struct symtab_and_line sal
;
14523 CORE_ADDR pc
= next_pc
;
14525 if (tp
->control
.single_step_breakpoints
== NULL
)
14527 tp
->control
.single_step_breakpoints
14528 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14531 sal
= find_pc_line (pc
, 0);
14533 sal
.section
= find_pc_overlay (pc
);
14534 sal
.explicit_pc
= 1;
14535 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14537 update_global_location_list (UGLL_INSERT
);
14540 /* Insert single step breakpoints according to the current state. */
14543 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14545 struct regcache
*regcache
= get_current_regcache ();
14546 std::vector
<CORE_ADDR
> next_pcs
;
14548 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14550 if (!next_pcs
.empty ())
14552 struct frame_info
*frame
= get_current_frame ();
14553 const address_space
*aspace
= get_frame_address_space (frame
);
14555 for (CORE_ADDR pc
: next_pcs
)
14556 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14564 /* See breakpoint.h. */
14567 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14568 const address_space
*aspace
,
14571 for (bp_location
*loc
: bp
->locations ())
14573 && breakpoint_location_address_match (loc
, aspace
, pc
))
14579 /* Check whether a software single-step breakpoint is inserted at
14583 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14586 for (breakpoint
*bpt
: all_breakpoints ())
14588 if (bpt
->type
== bp_single_step
14589 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14595 /* Tracepoint-specific operations. */
14597 /* Set tracepoint count to NUM. */
14599 set_tracepoint_count (int num
)
14601 tracepoint_count
= num
;
14602 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14606 trace_command (const char *arg
, int from_tty
)
14608 event_location_up location
= string_to_event_location (&arg
,
14610 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
14611 (location
.get (), true /* is_tracepoint */);
14613 create_breakpoint (get_current_arch (),
14615 NULL
, 0, arg
, false, 1 /* parse arg */,
14617 bp_tracepoint
/* type_wanted */,
14618 0 /* Ignore count */,
14619 pending_break_support
,
14623 0 /* internal */, 0);
14627 ftrace_command (const char *arg
, int from_tty
)
14629 event_location_up location
= string_to_event_location (&arg
,
14631 create_breakpoint (get_current_arch (),
14633 NULL
, 0, arg
, false, 1 /* parse arg */,
14635 bp_fast_tracepoint
/* type_wanted */,
14636 0 /* Ignore count */,
14637 pending_break_support
,
14638 &tracepoint_breakpoint_ops
,
14641 0 /* internal */, 0);
14644 /* strace command implementation. Creates a static tracepoint. */
14647 strace_command (const char *arg
, int from_tty
)
14649 struct breakpoint_ops
*ops
;
14650 event_location_up location
;
14652 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14653 or with a normal static tracepoint. */
14654 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14656 ops
= &strace_marker_breakpoint_ops
;
14657 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14661 ops
= &tracepoint_breakpoint_ops
;
14662 location
= string_to_event_location (&arg
, current_language
);
14665 create_breakpoint (get_current_arch (),
14667 NULL
, 0, arg
, false, 1 /* parse arg */,
14669 bp_static_tracepoint
/* type_wanted */,
14670 0 /* Ignore count */,
14671 pending_break_support
,
14675 0 /* internal */, 0);
14678 /* Set up a fake reader function that gets command lines from a linked
14679 list that was acquired during tracepoint uploading. */
14681 static struct uploaded_tp
*this_utp
;
14682 static int next_cmd
;
14685 read_uploaded_action (void)
14687 char *rslt
= nullptr;
14689 if (next_cmd
< this_utp
->cmd_strings
.size ())
14691 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14698 /* Given information about a tracepoint as recorded on a target (which
14699 can be either a live system or a trace file), attempt to create an
14700 equivalent GDB tracepoint. This is not a reliable process, since
14701 the target does not necessarily have all the information used when
14702 the tracepoint was originally defined. */
14704 struct tracepoint
*
14705 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14707 const char *addr_str
;
14708 char small_buf
[100];
14709 struct tracepoint
*tp
;
14711 if (utp
->at_string
)
14712 addr_str
= utp
->at_string
.get ();
14715 /* In the absence of a source location, fall back to raw
14716 address. Since there is no way to confirm that the address
14717 means the same thing as when the trace was started, warn the
14719 warning (_("Uploaded tracepoint %d has no "
14720 "source location, using raw address"),
14722 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14723 addr_str
= small_buf
;
14726 /* There's not much we can do with a sequence of bytecodes. */
14727 if (utp
->cond
&& !utp
->cond_string
)
14728 warning (_("Uploaded tracepoint %d condition "
14729 "has no source form, ignoring it"),
14732 event_location_up location
= string_to_event_location (&addr_str
,
14734 if (!create_breakpoint (get_current_arch (),
14736 utp
->cond_string
.get (), -1, addr_str
,
14737 false /* force_condition */,
14738 0 /* parse cond/thread */,
14740 utp
->type
/* type_wanted */,
14741 0 /* Ignore count */,
14742 pending_break_support
,
14743 &tracepoint_breakpoint_ops
,
14745 utp
->enabled
/* enabled */,
14747 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14750 /* Get the tracepoint we just created. */
14751 tp
= get_tracepoint (tracepoint_count
);
14752 gdb_assert (tp
!= NULL
);
14756 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14759 trace_pass_command (small_buf
, 0);
14762 /* If we have uploaded versions of the original commands, set up a
14763 special-purpose "reader" function and call the usual command line
14764 reader, then pass the result to the breakpoint command-setting
14766 if (!utp
->cmd_strings
.empty ())
14768 counted_command_line cmd_list
;
14773 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14775 breakpoint_set_commands (tp
, std::move (cmd_list
));
14777 else if (!utp
->actions
.empty ()
14778 || !utp
->step_actions
.empty ())
14779 warning (_("Uploaded tracepoint %d actions "
14780 "have no source form, ignoring them"),
14783 /* Copy any status information that might be available. */
14784 tp
->hit_count
= utp
->hit_count
;
14785 tp
->traceframe_usage
= utp
->traceframe_usage
;
14790 /* Print information on tracepoint number TPNUM_EXP, or all if
14794 info_tracepoints_command (const char *args
, int from_tty
)
14796 struct ui_out
*uiout
= current_uiout
;
14799 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14801 if (num_printed
== 0)
14803 if (args
== NULL
|| *args
== '\0')
14804 uiout
->message ("No tracepoints.\n");
14806 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14809 default_collect_info ();
14812 /* The 'enable trace' command enables tracepoints.
14813 Not supported by all targets. */
14815 enable_trace_command (const char *args
, int from_tty
)
14817 enable_command (args
, from_tty
);
14820 /* The 'disable trace' command disables tracepoints.
14821 Not supported by all targets. */
14823 disable_trace_command (const char *args
, int from_tty
)
14825 disable_command (args
, from_tty
);
14828 /* Remove a tracepoint (or all if no argument). */
14830 delete_trace_command (const char *arg
, int from_tty
)
14836 int breaks_to_delete
= 0;
14838 /* Delete all breakpoints if no argument.
14839 Do not delete internal or call-dummy breakpoints, these
14840 have to be deleted with an explicit breakpoint number
14842 for (breakpoint
*tp
: all_tracepoints ())
14843 if (is_tracepoint (tp
) && user_breakpoint_p (tp
))
14845 breaks_to_delete
= 1;
14849 /* Ask user only if there are some breakpoints to delete. */
14851 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14853 for (breakpoint
*b
: all_breakpoints_safe ())
14854 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14855 delete_breakpoint (b
);
14859 map_breakpoint_numbers
14860 (arg
, [&] (breakpoint
*br
)
14862 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14866 /* Helper function for trace_pass_command. */
14869 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14871 tp
->pass_count
= count
;
14872 gdb::observers::breakpoint_modified
.notify (tp
);
14874 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14875 tp
->number
, count
);
14878 /* Set passcount for tracepoint.
14880 First command argument is passcount, second is tracepoint number.
14881 If tracepoint number omitted, apply to most recently defined.
14882 Also accepts special argument "all". */
14885 trace_pass_command (const char *args
, int from_tty
)
14887 struct tracepoint
*t1
;
14890 if (args
== 0 || *args
== 0)
14891 error (_("passcount command requires an "
14892 "argument (count + optional TP num)"));
14894 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14896 args
= skip_spaces (args
);
14897 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14899 args
+= 3; /* Skip special argument "all". */
14901 error (_("Junk at end of arguments."));
14903 for (breakpoint
*b
: all_tracepoints ())
14905 t1
= (struct tracepoint
*) b
;
14906 trace_pass_set_count (t1
, count
, from_tty
);
14909 else if (*args
== '\0')
14911 t1
= get_tracepoint_by_number (&args
, NULL
);
14913 trace_pass_set_count (t1
, count
, from_tty
);
14917 number_or_range_parser
parser (args
);
14918 while (!parser
.finished ())
14920 t1
= get_tracepoint_by_number (&args
, &parser
);
14922 trace_pass_set_count (t1
, count
, from_tty
);
14927 struct tracepoint
*
14928 get_tracepoint (int num
)
14930 for (breakpoint
*t
: all_tracepoints ())
14931 if (t
->number
== num
)
14932 return (struct tracepoint
*) t
;
14937 /* Find the tracepoint with the given target-side number (which may be
14938 different from the tracepoint number after disconnecting and
14941 struct tracepoint
*
14942 get_tracepoint_by_number_on_target (int num
)
14944 for (breakpoint
*b
: all_tracepoints ())
14946 struct tracepoint
*t
= (struct tracepoint
*) b
;
14948 if (t
->number_on_target
== num
)
14955 /* Utility: parse a tracepoint number and look it up in the list.
14956 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14957 If the argument is missing, the most recent tracepoint
14958 (tracepoint_count) is returned. */
14960 struct tracepoint
*
14961 get_tracepoint_by_number (const char **arg
,
14962 number_or_range_parser
*parser
)
14965 const char *instring
= arg
== NULL
? NULL
: *arg
;
14967 if (parser
!= NULL
)
14969 gdb_assert (!parser
->finished ());
14970 tpnum
= parser
->get_number ();
14972 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14973 tpnum
= tracepoint_count
;
14975 tpnum
= get_number (arg
);
14979 if (instring
&& *instring
)
14980 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14983 printf_filtered (_("No previous tracepoint\n"));
14987 for (breakpoint
*t
: all_tracepoints ())
14988 if (t
->number
== tpnum
)
14990 return (struct tracepoint
*) t
;
14993 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
14998 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15000 if (b
->thread
!= -1)
15001 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15004 fprintf_unfiltered (fp
, " task %d", b
->task
);
15006 fprintf_unfiltered (fp
, "\n");
15009 /* Save information on user settable breakpoints (watchpoints, etc) to
15010 a new script file named FILENAME. If FILTER is non-NULL, call it
15011 on each breakpoint and only include the ones for which it returns
15015 save_breakpoints (const char *filename
, int from_tty
,
15016 bool (*filter
) (const struct breakpoint
*))
15019 int extra_trace_bits
= 0;
15021 if (filename
== 0 || *filename
== 0)
15022 error (_("Argument required (file name in which to save)"));
15024 /* See if we have anything to save. */
15025 for (breakpoint
*tp
: all_breakpoints ())
15027 /* Skip internal and momentary breakpoints. */
15028 if (!user_breakpoint_p (tp
))
15031 /* If we have a filter, only save the breakpoints it accepts. */
15032 if (filter
&& !filter (tp
))
15037 if (is_tracepoint (tp
))
15039 extra_trace_bits
= 1;
15041 /* We can stop searching. */
15048 warning (_("Nothing to save."));
15052 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15056 if (!fp
.open (expanded_filename
.get (), "w"))
15057 error (_("Unable to open file '%s' for saving (%s)"),
15058 expanded_filename
.get (), safe_strerror (errno
));
15060 if (extra_trace_bits
)
15061 save_trace_state_variables (&fp
);
15063 for (breakpoint
*tp
: all_breakpoints ())
15065 /* Skip internal and momentary breakpoints. */
15066 if (!user_breakpoint_p (tp
))
15069 /* If we have a filter, only save the breakpoints it accepts. */
15070 if (filter
&& !filter (tp
))
15073 tp
->ops
->print_recreate (tp
, &fp
);
15075 /* Note, we can't rely on tp->number for anything, as we can't
15076 assume the recreated breakpoint numbers will match. Use $bpnum
15079 if (tp
->cond_string
)
15080 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15082 if (tp
->ignore_count
)
15083 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15085 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15087 fp
.puts (" commands\n");
15089 current_uiout
->redirect (&fp
);
15092 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15094 catch (const gdb_exception
&ex
)
15096 current_uiout
->redirect (NULL
);
15100 current_uiout
->redirect (NULL
);
15101 fp
.puts (" end\n");
15104 if (tp
->enable_state
== bp_disabled
)
15105 fp
.puts ("disable $bpnum\n");
15107 /* If this is a multi-location breakpoint, check if the locations
15108 should be individually disabled. Watchpoint locations are
15109 special, and not user visible. */
15110 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15114 for (bp_location
*loc
: tp
->locations ())
15117 fp
.printf ("disable $bpnum.%d\n", n
);
15124 if (extra_trace_bits
&& *default_collect
)
15125 fp
.printf ("set default-collect %s\n", default_collect
);
15128 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15131 /* The `save breakpoints' command. */
15134 save_breakpoints_command (const char *args
, int from_tty
)
15136 save_breakpoints (args
, from_tty
, NULL
);
15139 /* The `save tracepoints' command. */
15142 save_tracepoints_command (const char *args
, int from_tty
)
15144 save_breakpoints (args
, from_tty
, is_tracepoint
);
15148 /* This help string is used to consolidate all the help string for specifying
15149 locations used by several commands. */
15151 #define LOCATION_HELP_STRING \
15152 "Linespecs are colon-separated lists of location parameters, such as\n\
15153 source filename, function name, label name, and line number.\n\
15154 Example: To specify the start of a label named \"the_top\" in the\n\
15155 function \"fact\" in the file \"factorial.c\", use\n\
15156 \"factorial.c:fact:the_top\".\n\
15158 Address locations begin with \"*\" and specify an exact address in the\n\
15159 program. Example: To specify the fourth byte past the start function\n\
15160 \"main\", use \"*main + 4\".\n\
15162 Explicit locations are similar to linespecs but use an option/argument\n\
15163 syntax to specify location parameters.\n\
15164 Example: To specify the start of the label named \"the_top\" in the\n\
15165 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15166 -function fact -label the_top\".\n\
15168 By default, a specified function is matched against the program's\n\
15169 functions in all scopes. For C++, this means in all namespaces and\n\
15170 classes. For Ada, this means in all packages. E.g., in C++,\n\
15171 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15172 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15173 specified name as a complete fully-qualified name instead."
15175 /* This help string is used for the break, hbreak, tbreak and thbreak
15176 commands. It is defined as a macro to prevent duplication.
15177 COMMAND should be a string constant containing the name of the
15180 #define BREAK_ARGS_HELP(command) \
15181 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
15182 \t[-force-condition] [if CONDITION]\n\
15183 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15184 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15185 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15186 `-probe-dtrace' (for a DTrace probe).\n\
15187 LOCATION may be a linespec, address, or explicit location as described\n\
15190 With no LOCATION, uses current execution address of the selected\n\
15191 stack frame. This is useful for breaking on return to a stack frame.\n\
15193 THREADNUM is the number from \"info threads\".\n\
15194 CONDITION is a boolean expression.\n\
15196 With the \"-force-condition\" flag, the condition is defined even when\n\
15197 it is invalid for all current locations.\n\
15198 \n" LOCATION_HELP_STRING "\n\n\
15199 Multiple breakpoints at one place are permitted, and useful if their\n\
15200 conditions are different.\n\
15202 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15204 /* List of subcommands for "catch". */
15205 static struct cmd_list_element
*catch_cmdlist
;
15207 /* List of subcommands for "tcatch". */
15208 static struct cmd_list_element
*tcatch_cmdlist
;
15211 add_catch_command (const char *name
, const char *docstring
,
15212 cmd_const_sfunc_ftype
*sfunc
,
15213 completer_ftype
*completer
,
15214 void *user_data_catch
,
15215 void *user_data_tcatch
)
15217 struct cmd_list_element
*command
;
15219 command
= add_cmd (name
, class_breakpoint
, docstring
,
15221 set_cmd_sfunc (command
, sfunc
);
15222 set_cmd_context (command
, user_data_catch
);
15223 set_cmd_completer (command
, completer
);
15225 command
= add_cmd (name
, class_breakpoint
, docstring
,
15227 set_cmd_sfunc (command
, sfunc
);
15228 set_cmd_context (command
, user_data_tcatch
);
15229 set_cmd_completer (command
, completer
);
15232 struct breakpoint
*
15233 iterate_over_breakpoints (gdb::function_view
<bool (breakpoint
*)> callback
)
15235 for (breakpoint
*b
: all_breakpoints_safe ())
15242 /* Zero if any of the breakpoint's locations could be a location where
15243 functions have been inlined, nonzero otherwise. */
15246 is_non_inline_function (struct breakpoint
*b
)
15248 /* The shared library event breakpoint is set on the address of a
15249 non-inline function. */
15250 if (b
->type
== bp_shlib_event
)
15256 /* Nonzero if the specified PC cannot be a location where functions
15257 have been inlined. */
15260 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15261 const struct target_waitstatus
*ws
)
15263 for (breakpoint
*b
: all_breakpoints ())
15265 if (!is_non_inline_function (b
))
15268 for (bp_location
*bl
: b
->locations ())
15270 if (!bl
->shlib_disabled
15271 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15279 /* Remove any references to OBJFILE which is going to be freed. */
15282 breakpoint_free_objfile (struct objfile
*objfile
)
15284 for (bp_location
*loc
: all_bp_locations ())
15285 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15286 loc
->symtab
= NULL
;
15290 initialize_breakpoint_ops (void)
15292 static int initialized
= 0;
15294 struct breakpoint_ops
*ops
;
15300 /* The breakpoint_ops structure to be inherit by all kinds of
15301 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15302 internal and momentary breakpoints, etc.). */
15303 ops
= &bkpt_base_breakpoint_ops
;
15304 *ops
= base_breakpoint_ops
;
15305 ops
->re_set
= bkpt_re_set
;
15306 ops
->insert_location
= bkpt_insert_location
;
15307 ops
->remove_location
= bkpt_remove_location
;
15308 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15309 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15310 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15311 ops
->decode_location
= bkpt_decode_location
;
15313 /* The breakpoint_ops structure to be used in regular breakpoints. */
15314 ops
= &bkpt_breakpoint_ops
;
15315 *ops
= bkpt_base_breakpoint_ops
;
15316 ops
->re_set
= bkpt_re_set
;
15317 ops
->resources_needed
= bkpt_resources_needed
;
15318 ops
->print_it
= bkpt_print_it
;
15319 ops
->print_mention
= bkpt_print_mention
;
15320 ops
->print_recreate
= bkpt_print_recreate
;
15322 /* Ranged breakpoints. */
15323 ops
= &ranged_breakpoint_ops
;
15324 *ops
= bkpt_breakpoint_ops
;
15325 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15326 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15327 ops
->print_it
= print_it_ranged_breakpoint
;
15328 ops
->print_one
= print_one_ranged_breakpoint
;
15329 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15330 ops
->print_mention
= print_mention_ranged_breakpoint
;
15331 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15333 /* Internal breakpoints. */
15334 ops
= &internal_breakpoint_ops
;
15335 *ops
= bkpt_base_breakpoint_ops
;
15336 ops
->re_set
= internal_bkpt_re_set
;
15337 ops
->check_status
= internal_bkpt_check_status
;
15338 ops
->print_it
= internal_bkpt_print_it
;
15339 ops
->print_mention
= internal_bkpt_print_mention
;
15341 /* Momentary breakpoints. */
15342 ops
= &momentary_breakpoint_ops
;
15343 *ops
= bkpt_base_breakpoint_ops
;
15344 ops
->re_set
= momentary_bkpt_re_set
;
15345 ops
->check_status
= momentary_bkpt_check_status
;
15346 ops
->print_it
= momentary_bkpt_print_it
;
15347 ops
->print_mention
= momentary_bkpt_print_mention
;
15349 /* Probe breakpoints. */
15350 ops
= &bkpt_probe_breakpoint_ops
;
15351 *ops
= bkpt_breakpoint_ops
;
15352 ops
->insert_location
= bkpt_probe_insert_location
;
15353 ops
->remove_location
= bkpt_probe_remove_location
;
15354 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15355 ops
->decode_location
= bkpt_probe_decode_location
;
15358 ops
= &watchpoint_breakpoint_ops
;
15359 *ops
= base_breakpoint_ops
;
15360 ops
->re_set
= re_set_watchpoint
;
15361 ops
->insert_location
= insert_watchpoint
;
15362 ops
->remove_location
= remove_watchpoint
;
15363 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15364 ops
->check_status
= check_status_watchpoint
;
15365 ops
->resources_needed
= resources_needed_watchpoint
;
15366 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15367 ops
->print_it
= print_it_watchpoint
;
15368 ops
->print_mention
= print_mention_watchpoint
;
15369 ops
->print_recreate
= print_recreate_watchpoint
;
15370 ops
->explains_signal
= explains_signal_watchpoint
;
15372 /* Masked watchpoints. */
15373 ops
= &masked_watchpoint_breakpoint_ops
;
15374 *ops
= watchpoint_breakpoint_ops
;
15375 ops
->insert_location
= insert_masked_watchpoint
;
15376 ops
->remove_location
= remove_masked_watchpoint
;
15377 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15378 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15379 ops
->print_it
= print_it_masked_watchpoint
;
15380 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15381 ops
->print_mention
= print_mention_masked_watchpoint
;
15382 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15385 ops
= &tracepoint_breakpoint_ops
;
15386 *ops
= base_breakpoint_ops
;
15387 ops
->re_set
= tracepoint_re_set
;
15388 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15389 ops
->print_one_detail
= tracepoint_print_one_detail
;
15390 ops
->print_mention
= tracepoint_print_mention
;
15391 ops
->print_recreate
= tracepoint_print_recreate
;
15392 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15393 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15394 ops
->decode_location
= tracepoint_decode_location
;
15396 /* Probe tracepoints. */
15397 ops
= &tracepoint_probe_breakpoint_ops
;
15398 *ops
= tracepoint_breakpoint_ops
;
15399 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15400 ops
->decode_location
= tracepoint_probe_decode_location
;
15402 /* Static tracepoints with marker (`-m'). */
15403 ops
= &strace_marker_breakpoint_ops
;
15404 *ops
= tracepoint_breakpoint_ops
;
15405 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15406 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15407 ops
->decode_location
= strace_marker_decode_location
;
15409 /* Fork catchpoints. */
15410 ops
= &catch_fork_breakpoint_ops
;
15411 *ops
= base_breakpoint_ops
;
15412 ops
->insert_location
= insert_catch_fork
;
15413 ops
->remove_location
= remove_catch_fork
;
15414 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15415 ops
->print_it
= print_it_catch_fork
;
15416 ops
->print_one
= print_one_catch_fork
;
15417 ops
->print_mention
= print_mention_catch_fork
;
15418 ops
->print_recreate
= print_recreate_catch_fork
;
15420 /* Vfork catchpoints. */
15421 ops
= &catch_vfork_breakpoint_ops
;
15422 *ops
= base_breakpoint_ops
;
15423 ops
->insert_location
= insert_catch_vfork
;
15424 ops
->remove_location
= remove_catch_vfork
;
15425 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15426 ops
->print_it
= print_it_catch_vfork
;
15427 ops
->print_one
= print_one_catch_vfork
;
15428 ops
->print_mention
= print_mention_catch_vfork
;
15429 ops
->print_recreate
= print_recreate_catch_vfork
;
15431 /* Exec catchpoints. */
15432 ops
= &catch_exec_breakpoint_ops
;
15433 *ops
= base_breakpoint_ops
;
15434 ops
->insert_location
= insert_catch_exec
;
15435 ops
->remove_location
= remove_catch_exec
;
15436 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15437 ops
->print_it
= print_it_catch_exec
;
15438 ops
->print_one
= print_one_catch_exec
;
15439 ops
->print_mention
= print_mention_catch_exec
;
15440 ops
->print_recreate
= print_recreate_catch_exec
;
15442 /* Solib-related catchpoints. */
15443 ops
= &catch_solib_breakpoint_ops
;
15444 *ops
= base_breakpoint_ops
;
15445 ops
->insert_location
= insert_catch_solib
;
15446 ops
->remove_location
= remove_catch_solib
;
15447 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15448 ops
->check_status
= check_status_catch_solib
;
15449 ops
->print_it
= print_it_catch_solib
;
15450 ops
->print_one
= print_one_catch_solib
;
15451 ops
->print_mention
= print_mention_catch_solib
;
15452 ops
->print_recreate
= print_recreate_catch_solib
;
15454 ops
= &dprintf_breakpoint_ops
;
15455 *ops
= bkpt_base_breakpoint_ops
;
15456 ops
->re_set
= dprintf_re_set
;
15457 ops
->resources_needed
= bkpt_resources_needed
;
15458 ops
->print_it
= bkpt_print_it
;
15459 ops
->print_mention
= bkpt_print_mention
;
15460 ops
->print_recreate
= dprintf_print_recreate
;
15461 ops
->after_condition_true
= dprintf_after_condition_true
;
15462 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15465 /* Chain containing all defined "enable breakpoint" subcommands. */
15467 static struct cmd_list_element
*enablebreaklist
= NULL
;
15469 /* See breakpoint.h. */
15471 cmd_list_element
*commands_cmd_element
= nullptr;
15473 void _initialize_breakpoint ();
15475 _initialize_breakpoint ()
15477 struct cmd_list_element
*c
;
15479 initialize_breakpoint_ops ();
15481 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
,
15483 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
,
15485 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
,
15488 breakpoint_chain
= 0;
15489 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15490 before a breakpoint is set. */
15491 breakpoint_count
= 0;
15493 tracepoint_count
= 0;
15495 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15496 Set ignore-count of breakpoint number N to COUNT.\n\
15497 Usage is `ignore N COUNT'."));
15499 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15500 commands_command
, _("\
15501 Set commands to be executed when the given breakpoints are hit.\n\
15502 Give a space-separated breakpoint list as argument after \"commands\".\n\
15503 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15505 With no argument, the targeted breakpoint is the last one set.\n\
15506 The commands themselves follow starting on the next line.\n\
15507 Type a line containing \"end\" to indicate the end of them.\n\
15508 Give \"silent\" as the first line to make the breakpoint silent;\n\
15509 then no output is printed when it is hit, except what the commands print."));
15511 const auto cc_opts
= make_condition_command_options_def_group (nullptr);
15512 static std::string condition_command_help
15513 = gdb::option::build_help (_("\
15514 Specify breakpoint number N to break only if COND is true.\n\
15515 Usage is `condition [OPTION] N COND', where N is an integer and COND\n\
15516 is an expression to be evaluated whenever breakpoint N is reached.\n\
15519 %OPTIONS%"), cc_opts
);
15521 c
= add_com ("condition", class_breakpoint
, condition_command
,
15522 condition_command_help
.c_str ());
15523 set_cmd_completer_handle_brkchars (c
, condition_completer
);
15525 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15526 Set a temporary breakpoint.\n\
15527 Like \"break\" except the breakpoint is only temporary,\n\
15528 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15529 by using \"enable delete\" on the breakpoint number.\n\
15531 BREAK_ARGS_HELP ("tbreak")));
15532 set_cmd_completer (c
, location_completer
);
15534 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15535 Set a hardware assisted breakpoint.\n\
15536 Like \"break\" except the breakpoint requires hardware support,\n\
15537 some target hardware may not have this support.\n\
15539 BREAK_ARGS_HELP ("hbreak")));
15540 set_cmd_completer (c
, location_completer
);
15542 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15543 Set a temporary hardware assisted breakpoint.\n\
15544 Like \"hbreak\" except the breakpoint is only temporary,\n\
15545 so it will be deleted when hit.\n\
15547 BREAK_ARGS_HELP ("thbreak")));
15548 set_cmd_completer (c
, location_completer
);
15550 cmd_list_element
*enable_cmd
15551 = add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15552 Enable all or some breakpoints.\n\
15553 Usage: enable [BREAKPOINTNUM]...\n\
15554 Give breakpoint numbers (separated by spaces) as arguments.\n\
15555 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15556 This is used to cancel the effect of the \"disable\" command.\n\
15557 With a subcommand you can enable temporarily."),
15558 &enablelist
, 1, &cmdlist
);
15560 add_com_alias ("en", enable_cmd
, class_breakpoint
, 1);
15562 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15563 Enable all or some breakpoints.\n\
15564 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15565 Give breakpoint numbers (separated by spaces) as arguments.\n\
15566 This is used to cancel the effect of the \"disable\" command.\n\
15567 May be abbreviated to simply \"enable\"."),
15568 &enablebreaklist
, 1, &enablelist
);
15570 add_cmd ("once", no_class
, enable_once_command
, _("\
15571 Enable some breakpoints for one hit.\n\
15572 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15573 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15576 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15577 Enable some breakpoints and delete when hit.\n\
15578 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15579 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15582 add_cmd ("count", no_class
, enable_count_command
, _("\
15583 Enable some breakpoints for COUNT hits.\n\
15584 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15585 If a breakpoint is hit while enabled in this fashion,\n\
15586 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15589 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15590 Enable some breakpoints and delete when hit.\n\
15591 Usage: enable delete BREAKPOINTNUM...\n\
15592 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15595 add_cmd ("once", no_class
, enable_once_command
, _("\
15596 Enable some breakpoints for one hit.\n\
15597 Usage: enable once BREAKPOINTNUM...\n\
15598 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15601 add_cmd ("count", no_class
, enable_count_command
, _("\
15602 Enable some breakpoints for COUNT hits.\n\
15603 Usage: enable count COUNT BREAKPOINTNUM...\n\
15604 If a breakpoint is hit while enabled in this fashion,\n\
15605 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15608 cmd_list_element
*disable_cmd
15609 = add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15610 Disable all or some breakpoints.\n\
15611 Usage: disable [BREAKPOINTNUM]...\n\
15612 Arguments are breakpoint numbers with spaces in between.\n\
15613 To disable all breakpoints, give no argument.\n\
15614 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15615 &disablelist
, 1, &cmdlist
);
15616 add_com_alias ("dis", disable_cmd
, class_breakpoint
, 1);
15617 add_com_alias ("disa", disable_cmd
, class_breakpoint
, 1);
15619 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
15620 Disable all or some breakpoints.\n\
15621 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15622 Arguments are breakpoint numbers with spaces in between.\n\
15623 To disable all breakpoints, give no argument.\n\
15624 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15625 This command may be abbreviated \"disable\"."),
15628 cmd_list_element
*delete_cmd
15629 = add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15630 Delete all or some breakpoints.\n\
15631 Usage: delete [BREAKPOINTNUM]...\n\
15632 Arguments are breakpoint numbers with spaces in between.\n\
15633 To delete all breakpoints, give no argument.\n\
15635 Also a prefix command for deletion of other GDB objects."),
15636 &deletelist
, 1, &cmdlist
);
15637 add_com_alias ("d", delete_cmd
, class_breakpoint
, 1);
15638 add_com_alias ("del", delete_cmd
, class_breakpoint
, 1);
15640 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
15641 Delete all or some breakpoints or auto-display expressions.\n\
15642 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15643 Arguments are breakpoint numbers with spaces in between.\n\
15644 To delete all breakpoints, give no argument.\n\
15645 This command may be abbreviated \"delete\"."),
15648 cmd_list_element
*clear_cmd
15649 = add_com ("clear", class_breakpoint
, clear_command
, _("\
15650 Clear breakpoint at specified location.\n\
15651 Argument may be a linespec, explicit, or address location as described below.\n\
15653 With no argument, clears all breakpoints in the line that the selected frame\n\
15654 is executing in.\n"
15655 "\n" LOCATION_HELP_STRING
"\n\n\
15656 See also the \"delete\" command which clears breakpoints by number."));
15657 add_com_alias ("cl", clear_cmd
, class_breakpoint
, 1);
15659 cmd_list_element
*break_cmd
15660 = add_com ("break", class_breakpoint
, break_command
, _("\
15661 Set breakpoint at specified location.\n"
15662 BREAK_ARGS_HELP ("break")));
15663 set_cmd_completer (break_cmd
, location_completer
);
15665 add_com_alias ("b", break_cmd
, class_run
, 1);
15666 add_com_alias ("br", break_cmd
, class_run
, 1);
15667 add_com_alias ("bre", break_cmd
, class_run
, 1);
15668 add_com_alias ("brea", break_cmd
, class_run
, 1);
15672 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15673 Break in function/address or break at a line in the current file."),
15674 &stoplist
, 1, &cmdlist
);
15675 add_cmd ("in", class_breakpoint
, stopin_command
,
15676 _("Break in function or address."), &stoplist
);
15677 add_cmd ("at", class_breakpoint
, stopat_command
,
15678 _("Break at a line in the current file."), &stoplist
);
15679 add_com ("status", class_info
, info_breakpoints_command
, _("\
15680 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15681 The \"Type\" column indicates one of:\n\
15682 \tbreakpoint - normal breakpoint\n\
15683 \twatchpoint - watchpoint\n\
15684 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15685 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15686 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15687 address and file/line number respectively.\n\
15689 Convenience variable \"$_\" and default examine address for \"x\"\n\
15690 are set to the address of the last breakpoint listed unless the command\n\
15691 is prefixed with \"server \".\n\n\
15692 Convenience variable \"$bpnum\" contains the number of the last\n\
15693 breakpoint set."));
15696 cmd_list_element
*info_breakpoints_cmd
15697 = add_info ("breakpoints", info_breakpoints_command
, _("\
15698 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15699 The \"Type\" column indicates one of:\n\
15700 \tbreakpoint - normal breakpoint\n\
15701 \twatchpoint - watchpoint\n\
15702 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15703 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15704 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15705 address and file/line number respectively.\n\
15707 Convenience variable \"$_\" and default examine address for \"x\"\n\
15708 are set to the address of the last breakpoint listed unless the command\n\
15709 is prefixed with \"server \".\n\n\
15710 Convenience variable \"$bpnum\" contains the number of the last\n\
15711 breakpoint set."));
15713 add_info_alias ("b", info_breakpoints_cmd
, 1);
15715 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15716 Status of all breakpoints, or breakpoint number NUMBER.\n\
15717 The \"Type\" column indicates one of:\n\
15718 \tbreakpoint - normal breakpoint\n\
15719 \twatchpoint - watchpoint\n\
15720 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15721 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15722 \tuntil - internal breakpoint used by the \"until\" command\n\
15723 \tfinish - internal breakpoint used by the \"finish\" command\n\
15724 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15725 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15726 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15727 address and file/line number respectively.\n\
15729 Convenience variable \"$_\" and default examine address for \"x\"\n\
15730 are set to the address of the last breakpoint listed unless the command\n\
15731 is prefixed with \"server \".\n\n\
15732 Convenience variable \"$bpnum\" contains the number of the last\n\
15734 &maintenanceinfolist
);
15736 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
15737 Set catchpoints to catch events."),
15739 0/*allow-unknown*/, &cmdlist
);
15741 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
15742 Set temporary catchpoints to catch events."),
15744 0/*allow-unknown*/, &cmdlist
);
15746 add_catch_command ("fork", _("Catch calls to fork."),
15747 catch_fork_command_1
,
15749 (void *) (uintptr_t) catch_fork_permanent
,
15750 (void *) (uintptr_t) catch_fork_temporary
);
15751 add_catch_command ("vfork", _("Catch calls to vfork."),
15752 catch_fork_command_1
,
15754 (void *) (uintptr_t) catch_vfork_permanent
,
15755 (void *) (uintptr_t) catch_vfork_temporary
);
15756 add_catch_command ("exec", _("Catch calls to exec."),
15757 catch_exec_command_1
,
15761 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15762 Usage: catch load [REGEX]\n\
15763 If REGEX is given, only stop for libraries matching the regular expression."),
15764 catch_load_command_1
,
15768 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15769 Usage: catch unload [REGEX]\n\
15770 If REGEX is given, only stop for libraries matching the regular expression."),
15771 catch_unload_command_1
,
15776 const auto opts
= make_watch_options_def_group (nullptr);
15778 static const std::string watch_help
= gdb::option::build_help (_("\
15779 Set a watchpoint for EXPRESSION.\n\
15780 Usage: watch [-location] EXPRESSION\n\
15785 A watchpoint stops execution of your program whenever the value of\n\
15786 an expression changes."), opts
);
15787 c
= add_com ("watch", class_breakpoint
, watch_command
,
15788 watch_help
.c_str ());
15789 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15791 static const std::string rwatch_help
= gdb::option::build_help (_("\
15792 Set a read watchpoint for EXPRESSION.\n\
15793 Usage: rwatch [-location] EXPRESSION\n\
15798 A read watchpoint stops execution of your program whenever the value of\n\
15799 an expression is read."), opts
);
15800 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
15801 rwatch_help
.c_str ());
15802 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15804 static const std::string awatch_help
= gdb::option::build_help (_("\
15805 Set an access watchpoint for EXPRESSION.\n\
15806 Usage: awatch [-location] EXPRESSION\n\
15811 An access watchpoint stops execution of your program whenever the value\n\
15812 of an expression is either read or written."), opts
);
15813 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
15814 awatch_help
.c_str ());
15815 set_cmd_completer_handle_brkchars (c
, watch_command_completer
);
15817 add_info ("watchpoints", info_watchpoints_command
, _("\
15818 Status of specified watchpoints (all watchpoints if no argument)."));
15820 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15821 respond to changes - contrary to the description. */
15822 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15823 &can_use_hw_watchpoints
, _("\
15824 Set debugger's willingness to use watchpoint hardware."), _("\
15825 Show debugger's willingness to use watchpoint hardware."), _("\
15826 If zero, gdb will not use hardware for new watchpoints, even if\n\
15827 such is available. (However, any hardware watchpoints that were\n\
15828 created before setting this to nonzero, will continue to use watchpoint\n\
15831 show_can_use_hw_watchpoints
,
15832 &setlist
, &showlist
);
15834 can_use_hw_watchpoints
= 1;
15836 /* Tracepoint manipulation commands. */
15838 cmd_list_element
*trace_cmd
15839 = add_com ("trace", class_breakpoint
, trace_command
, _("\
15840 Set a tracepoint at specified location.\n\
15842 BREAK_ARGS_HELP ("trace") "\n\
15843 Do \"help tracepoints\" for info on other tracepoint commands."));
15844 set_cmd_completer (trace_cmd
, location_completer
);
15846 add_com_alias ("tp", trace_cmd
, class_breakpoint
, 0);
15847 add_com_alias ("tr", trace_cmd
, class_breakpoint
, 1);
15848 add_com_alias ("tra", trace_cmd
, class_breakpoint
, 1);
15849 add_com_alias ("trac", trace_cmd
, class_breakpoint
, 1);
15851 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15852 Set a fast tracepoint at specified location.\n\
15854 BREAK_ARGS_HELP ("ftrace") "\n\
15855 Do \"help tracepoints\" for info on other tracepoint commands."));
15856 set_cmd_completer (c
, location_completer
);
15858 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15859 Set a static tracepoint at location or marker.\n\
15861 strace [LOCATION] [if CONDITION]\n\
15862 LOCATION may be a linespec, explicit, or address location (described below) \n\
15863 or -m MARKER_ID.\n\n\
15864 If a marker id is specified, probe the marker with that name. With\n\
15865 no LOCATION, uses current execution address of the selected stack frame.\n\
15866 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15867 This collects arbitrary user data passed in the probe point call to the\n\
15868 tracing library. You can inspect it when analyzing the trace buffer,\n\
15869 by printing the $_sdata variable like any other convenience variable.\n\
15871 CONDITION is a boolean expression.\n\
15872 \n" LOCATION_HELP_STRING
"\n\n\
15873 Multiple tracepoints at one place are permitted, and useful if their\n\
15874 conditions are different.\n\
15876 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15877 Do \"help tracepoints\" for info on other tracepoint commands."));
15878 set_cmd_completer (c
, location_completer
);
15880 cmd_list_element
*info_tracepoints_cmd
15881 = add_info ("tracepoints", info_tracepoints_command
, _("\
15882 Status of specified tracepoints (all tracepoints if no argument).\n\
15883 Convenience variable \"$tpnum\" contains the number of the\n\
15884 last tracepoint set."));
15886 add_info_alias ("tp", info_tracepoints_cmd
, 1);
15888 cmd_list_element
*delete_tracepoints_cmd
15889 = add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15890 Delete specified tracepoints.\n\
15891 Arguments are tracepoint numbers, separated by spaces.\n\
15892 No argument means delete all tracepoints."),
15894 add_alias_cmd ("tr", delete_tracepoints_cmd
, class_trace
, 1, &deletelist
);
15896 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15897 Disable specified tracepoints.\n\
15898 Arguments are tracepoint numbers, separated by spaces.\n\
15899 No argument means disable all tracepoints."),
15901 deprecate_cmd (c
, "disable");
15903 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15904 Enable specified tracepoints.\n\
15905 Arguments are tracepoint numbers, separated by spaces.\n\
15906 No argument means enable all tracepoints."),
15908 deprecate_cmd (c
, "enable");
15910 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15911 Set the passcount for a tracepoint.\n\
15912 The trace will end when the tracepoint has been passed 'count' times.\n\
15913 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15914 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15916 add_basic_prefix_cmd ("save", class_breakpoint
,
15917 _("Save breakpoint definitions as a script."),
15919 0/*allow-unknown*/, &cmdlist
);
15921 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15922 Save current breakpoint definitions as a script.\n\
15923 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15924 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15925 session to restore them."),
15927 set_cmd_completer (c
, filename_completer
);
15929 cmd_list_element
*save_tracepoints_cmd
15930 = add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15931 Save current tracepoint definitions as a script.\n\
15932 Use the 'source' command in another debug session to restore them."),
15934 set_cmd_completer (save_tracepoints_cmd
, filename_completer
);
15936 c
= add_com_alias ("save-tracepoints", save_tracepoints_cmd
, class_trace
, 0);
15937 deprecate_cmd (c
, "save tracepoints");
15939 add_basic_prefix_cmd ("breakpoint", class_maintenance
, _("\
15940 Breakpoint specific settings.\n\
15941 Configure various breakpoint-specific variables such as\n\
15942 pending breakpoint behavior."),
15943 &breakpoint_set_cmdlist
,
15944 0/*allow-unknown*/, &setlist
);
15945 add_show_prefix_cmd ("breakpoint", class_maintenance
, _("\
15946 Breakpoint specific settings.\n\
15947 Configure various breakpoint-specific variables such as\n\
15948 pending breakpoint behavior."),
15949 &breakpoint_show_cmdlist
,
15950 0/*allow-unknown*/, &showlist
);
15952 add_setshow_auto_boolean_cmd ("pending", no_class
,
15953 &pending_break_support
, _("\
15954 Set debugger's behavior regarding pending breakpoints."), _("\
15955 Show debugger's behavior regarding pending breakpoints."), _("\
15956 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15957 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15958 an error. If auto, an unrecognized breakpoint location results in a\n\
15959 user-query to see if a pending breakpoint should be created."),
15961 show_pending_break_support
,
15962 &breakpoint_set_cmdlist
,
15963 &breakpoint_show_cmdlist
);
15965 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15967 add_setshow_boolean_cmd ("auto-hw", no_class
,
15968 &automatic_hardware_breakpoints
, _("\
15969 Set automatic usage of hardware breakpoints."), _("\
15970 Show automatic usage of hardware breakpoints."), _("\
15971 If set, the debugger will automatically use hardware breakpoints for\n\
15972 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15973 a warning will be emitted for such breakpoints."),
15975 show_automatic_hardware_breakpoints
,
15976 &breakpoint_set_cmdlist
,
15977 &breakpoint_show_cmdlist
);
15979 add_setshow_boolean_cmd ("always-inserted", class_support
,
15980 &always_inserted_mode
, _("\
15981 Set mode for inserting breakpoints."), _("\
15982 Show mode for inserting breakpoints."), _("\
15983 When this mode is on, breakpoints are inserted immediately as soon as\n\
15984 they're created, kept inserted even when execution stops, and removed\n\
15985 only when the user deletes them. When this mode is off (the default),\n\
15986 breakpoints are inserted only when execution continues, and removed\n\
15987 when execution stops."),
15989 &show_always_inserted_mode
,
15990 &breakpoint_set_cmdlist
,
15991 &breakpoint_show_cmdlist
);
15993 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15994 condition_evaluation_enums
,
15995 &condition_evaluation_mode_1
, _("\
15996 Set mode of breakpoint condition evaluation."), _("\
15997 Show mode of breakpoint condition evaluation."), _("\
15998 When this is set to \"host\", breakpoint conditions will be\n\
15999 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16000 breakpoint conditions will be downloaded to the target (if the target\n\
16001 supports such feature) and conditions will be evaluated on the target's side.\n\
16002 If this is set to \"auto\" (default), this will be automatically set to\n\
16003 \"target\" if it supports condition evaluation, otherwise it will\n\
16004 be set to \"host\"."),
16005 &set_condition_evaluation_mode
,
16006 &show_condition_evaluation_mode
,
16007 &breakpoint_set_cmdlist
,
16008 &breakpoint_show_cmdlist
);
16010 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16011 Set a breakpoint for an address range.\n\
16012 break-range START-LOCATION, END-LOCATION\n\
16013 where START-LOCATION and END-LOCATION can be one of the following:\n\
16014 LINENUM, for that line in the current file,\n\
16015 FILE:LINENUM, for that line in that file,\n\
16016 +OFFSET, for that number of lines after the current line\n\
16017 or the start of the range\n\
16018 FUNCTION, for the first line in that function,\n\
16019 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16020 *ADDRESS, for the instruction at that address.\n\
16022 The breakpoint will stop execution of the inferior whenever it executes\n\
16023 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16024 range (including START-LOCATION and END-LOCATION)."));
16026 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16027 Set a dynamic printf at specified location.\n\
16028 dprintf location,format string,arg1,arg2,...\n\
16029 location may be a linespec, explicit, or address location.\n"
16030 "\n" LOCATION_HELP_STRING
));
16031 set_cmd_completer (c
, location_completer
);
16033 add_setshow_enum_cmd ("dprintf-style", class_support
,
16034 dprintf_style_enums
, &dprintf_style
, _("\
16035 Set the style of usage for dynamic printf."), _("\
16036 Show the style of usage for dynamic printf."), _("\
16037 This setting chooses how GDB will do a dynamic printf.\n\
16038 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16039 console, as with the \"printf\" command.\n\
16040 If the value is \"call\", the print is done by calling a function in your\n\
16041 program; by default printf(), but you can choose a different function or\n\
16042 output stream by setting dprintf-function and dprintf-channel."),
16043 update_dprintf_commands
, NULL
,
16044 &setlist
, &showlist
);
16046 dprintf_function
= xstrdup ("printf");
16047 add_setshow_string_cmd ("dprintf-function", class_support
,
16048 &dprintf_function
, _("\
16049 Set the function to use for dynamic printf."), _("\
16050 Show the function to use for dynamic printf."), NULL
,
16051 update_dprintf_commands
, NULL
,
16052 &setlist
, &showlist
);
16054 dprintf_channel
= xstrdup ("");
16055 add_setshow_string_cmd ("dprintf-channel", class_support
,
16056 &dprintf_channel
, _("\
16057 Set the channel to use for dynamic printf."), _("\
16058 Show the channel to use for dynamic printf."), NULL
,
16059 update_dprintf_commands
, NULL
,
16060 &setlist
, &showlist
);
16062 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16063 &disconnected_dprintf
, _("\
16064 Set whether dprintf continues after GDB disconnects."), _("\
16065 Show whether dprintf continues after GDB disconnects."), _("\
16066 Use this to let dprintf commands continue to hit and produce output\n\
16067 even if GDB disconnects or detaches from the target."),
16070 &setlist
, &showlist
);
16072 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16073 Target agent only formatted printing, like the C \"printf\" function.\n\
16074 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
16075 This supports most C printf format specifications, like %s, %d, etc.\n\
16076 This is useful for formatted output in user-defined commands."));
16078 automatic_hardware_breakpoints
= true;
16080 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
,
16082 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
,