1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2020 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 free_bp_location (struct bp_location
*loc
);
176 static void incref_bp_location (struct bp_location
*loc
);
177 static void decref_bp_location (struct bp_location
**loc
);
179 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
181 /* update_global_location_list's modes of operation wrt to whether to
182 insert locations now. */
183 enum ugll_insert_mode
185 /* Don't insert any breakpoint locations into the inferior, only
186 remove already-inserted locations that no longer should be
187 inserted. Functions that delete a breakpoint or breakpoints
188 should specify this mode, so that deleting a breakpoint doesn't
189 have the side effect of inserting the locations of other
190 breakpoints that are marked not-inserted, but should_be_inserted
191 returns true on them.
193 This behavior is useful is situations close to tear-down -- e.g.,
194 after an exec, while the target still has execution, but
195 breakpoint shadows of the previous executable image should *NOT*
196 be restored to the new image; or before detaching, where the
197 target still has execution and wants to delete breakpoints from
198 GDB's lists, and all breakpoints had already been removed from
202 /* May insert breakpoints iff breakpoints_should_be_inserted_now
203 claims breakpoints should be inserted now. */
206 /* Insert locations now, irrespective of
207 breakpoints_should_be_inserted_now. E.g., say all threads are
208 stopped right now, and the user did "continue". We need to
209 insert breakpoints _before_ resuming the target, but
210 UGLL_MAY_INSERT wouldn't insert them, because
211 breakpoints_should_be_inserted_now returns false at that point,
212 as no thread is running yet. */
216 static void update_global_location_list (enum ugll_insert_mode
);
218 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
220 static void insert_breakpoint_locations (void);
222 static void trace_pass_command (const char *, int);
224 static void set_tracepoint_count (int num
);
226 static bool is_masked_watchpoint (const struct breakpoint
*b
);
228 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
230 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
233 static int strace_marker_p (struct breakpoint
*b
);
235 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
236 that are implemented on top of software or hardware breakpoints
237 (user breakpoints, internal and momentary breakpoints, etc.). */
238 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
240 /* Internal breakpoints class type. */
241 static struct breakpoint_ops internal_breakpoint_ops
;
243 /* Momentary breakpoints class type. */
244 static struct breakpoint_ops momentary_breakpoint_ops
;
246 /* The breakpoint_ops structure to be used in regular user created
248 struct breakpoint_ops bkpt_breakpoint_ops
;
250 /* Breakpoints set on probes. */
251 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
253 /* Tracepoints set on probes. */
254 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
256 /* Dynamic printf class type. */
257 struct breakpoint_ops dprintf_breakpoint_ops
;
259 /* The style in which to perform a dynamic printf. This is a user
260 option because different output options have different tradeoffs;
261 if GDB does the printing, there is better error handling if there
262 is a problem with any of the arguments, but using an inferior
263 function lets you have special-purpose printers and sending of
264 output to the same place as compiled-in print functions. */
266 static const char dprintf_style_gdb
[] = "gdb";
267 static const char dprintf_style_call
[] = "call";
268 static const char dprintf_style_agent
[] = "agent";
269 static const char *const dprintf_style_enums
[] = {
275 static const char *dprintf_style
= dprintf_style_gdb
;
277 /* The function to use for dynamic printf if the preferred style is to
278 call into the inferior. The value is simply a string that is
279 copied into the command, so it can be anything that GDB can
280 evaluate to a callable address, not necessarily a function name. */
282 static char *dprintf_function
;
284 /* The channel to use for dynamic printf if the preferred style is to
285 call into the inferior; if a nonempty string, it will be passed to
286 the call as the first argument, with the format string as the
287 second. As with the dprintf function, this can be anything that
288 GDB knows how to evaluate, so in addition to common choices like
289 "stderr", this could be an app-specific expression like
290 "mystreams[curlogger]". */
292 static char *dprintf_channel
;
294 /* True if dprintf commands should continue to operate even if GDB
296 static bool disconnected_dprintf
= true;
298 struct command_line
*
299 breakpoint_commands (struct breakpoint
*b
)
301 return b
->commands
? b
->commands
.get () : NULL
;
304 /* Flag indicating that a command has proceeded the inferior past the
305 current breakpoint. */
307 static bool breakpoint_proceeded
;
310 bpdisp_text (enum bpdisp disp
)
312 /* NOTE: the following values are a part of MI protocol and
313 represent values of 'disp' field returned when inferior stops at
315 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
317 return bpdisps
[(int) disp
];
320 /* Prototypes for exported functions. */
321 /* If FALSE, gdb will not use hardware support for watchpoints, even
322 if such is available. */
323 static int can_use_hw_watchpoints
;
326 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
327 struct cmd_list_element
*c
,
330 fprintf_filtered (file
,
331 _("Debugger's willingness to use "
332 "watchpoint hardware is %s.\n"),
336 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
337 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
338 for unrecognized breakpoint locations.
339 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
340 static enum auto_boolean pending_break_support
;
342 show_pending_break_support (struct ui_file
*file
, int from_tty
,
343 struct cmd_list_element
*c
,
346 fprintf_filtered (file
,
347 _("Debugger's behavior regarding "
348 "pending breakpoints is %s.\n"),
352 /* If true, gdb will automatically use hardware breakpoints for breakpoints
353 set with "break" but falling in read-only memory.
354 If false, gdb will warn about such breakpoints, but won't automatically
355 use hardware breakpoints. */
356 static bool automatic_hardware_breakpoints
;
358 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
359 struct cmd_list_element
*c
,
362 fprintf_filtered (file
,
363 _("Automatic usage of hardware breakpoints is %s.\n"),
367 /* If on, GDB keeps breakpoints inserted even if the inferior is
368 stopped, and immediately inserts any new breakpoints as soon as
369 they're created. If off (default), GDB keeps breakpoints off of
370 the target as long as possible. That is, it delays inserting
371 breakpoints until the next resume, and removes them again when the
372 target fully stops. This is a bit safer in case GDB crashes while
373 processing user input. */
374 static bool always_inserted_mode
= false;
377 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
378 struct cmd_list_element
*c
, const char *value
)
380 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
384 /* See breakpoint.h. */
387 breakpoints_should_be_inserted_now (void)
389 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
391 /* If breakpoints are global, they should be inserted even if no
392 thread under gdb's control is running, or even if there are
393 no threads under GDB's control yet. */
398 if (always_inserted_mode
)
400 /* The user wants breakpoints inserted even if all threads
405 for (inferior
*inf
: all_inferiors ())
406 if (inf
->has_execution ()
407 && threads_are_executing (inf
->process_target ()))
410 /* Don't remove breakpoints yet if, even though all threads are
411 stopped, we still have events to process. */
412 for (thread_info
*tp
: all_non_exited_threads ())
414 && tp
->suspend
.waitstatus_pending_p
)
420 static const char condition_evaluation_both
[] = "host or target";
422 /* Modes for breakpoint condition evaluation. */
423 static const char condition_evaluation_auto
[] = "auto";
424 static const char condition_evaluation_host
[] = "host";
425 static const char condition_evaluation_target
[] = "target";
426 static const char *const condition_evaluation_enums
[] = {
427 condition_evaluation_auto
,
428 condition_evaluation_host
,
429 condition_evaluation_target
,
433 /* Global that holds the current mode for breakpoint condition evaluation. */
434 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
436 /* Global that we use to display information to the user (gets its value from
437 condition_evaluation_mode_1. */
438 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
440 /* Translate a condition evaluation mode MODE into either "host"
441 or "target". This is used mostly to translate from "auto" to the
442 real setting that is being used. It returns the translated
446 translate_condition_evaluation_mode (const char *mode
)
448 if (mode
== condition_evaluation_auto
)
450 if (target_supports_evaluation_of_breakpoint_conditions ())
451 return condition_evaluation_target
;
453 return condition_evaluation_host
;
459 /* Discovers what condition_evaluation_auto translates to. */
462 breakpoint_condition_evaluation_mode (void)
464 return translate_condition_evaluation_mode (condition_evaluation_mode
);
467 /* Return true if GDB should evaluate breakpoint conditions or false
471 gdb_evaluates_breakpoint_condition_p (void)
473 const char *mode
= breakpoint_condition_evaluation_mode ();
475 return (mode
== condition_evaluation_host
);
478 /* Are we executing breakpoint commands? */
479 static int executing_breakpoint_commands
;
481 /* Are overlay event breakpoints enabled? */
482 static int overlay_events_enabled
;
484 /* See description in breakpoint.h. */
485 bool target_exact_watchpoints
= false;
487 /* Walk the following statement or block through all breakpoints.
488 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
489 current breakpoint. */
491 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
493 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
494 for (B = breakpoint_chain; \
495 B ? (TMP=B->next, 1): 0; \
498 /* Similar iterator for the low-level breakpoints. SAFE variant is
499 not provided so update_global_location_list must not be called
500 while executing the block of ALL_BP_LOCATIONS. */
502 #define ALL_BP_LOCATIONS(B,BP_TMP) \
503 for (BP_TMP = bp_locations; \
504 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
507 /* Iterates through locations with address ADDRESS for the currently selected
508 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
509 to where the loop should start from.
510 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
511 appropriate location to start with. */
513 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
514 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
515 BP_LOCP_TMP = BP_LOCP_START; \
517 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
518 && (*BP_LOCP_TMP)->address == ADDRESS); \
521 /* Iterator for tracepoints only. */
523 #define ALL_TRACEPOINTS(B) \
524 for (B = breakpoint_chain; B; B = B->next) \
525 if (is_tracepoint (B))
527 /* Chains of all breakpoints defined. */
529 static struct breakpoint
*breakpoint_chain
;
531 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
533 static struct bp_location
**bp_locations
;
535 /* Number of elements of BP_LOCATIONS. */
537 static unsigned bp_locations_count
;
539 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
540 ADDRESS for the current elements of BP_LOCATIONS which get a valid
541 result from bp_location_has_shadow. You can use it for roughly
542 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
543 an address you need to read. */
545 static CORE_ADDR bp_locations_placed_address_before_address_max
;
547 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
548 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
549 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
550 You can use it for roughly limiting the subrange of BP_LOCATIONS to
551 scan for shadow bytes for an address you need to read. */
553 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
555 /* The locations that no longer correspond to any breakpoint, unlinked
556 from the bp_locations array, but for which a hit may still be
557 reported by a target. */
558 static std::vector
<bp_location
*> moribund_locations
;
560 /* Number of last breakpoint made. */
562 static int breakpoint_count
;
564 /* The value of `breakpoint_count' before the last command that
565 created breakpoints. If the last (break-like) command created more
566 than one breakpoint, then the difference between BREAKPOINT_COUNT
567 and PREV_BREAKPOINT_COUNT is more than one. */
568 static int prev_breakpoint_count
;
570 /* Number of last tracepoint made. */
572 static int tracepoint_count
;
574 static struct cmd_list_element
*breakpoint_set_cmdlist
;
575 static struct cmd_list_element
*breakpoint_show_cmdlist
;
576 struct cmd_list_element
*save_cmdlist
;
578 /* See declaration at breakpoint.h. */
581 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
584 struct breakpoint
*b
= NULL
;
588 if (func (b
, user_data
) != 0)
595 /* Return whether a breakpoint is an active enabled breakpoint. */
597 breakpoint_enabled (struct breakpoint
*b
)
599 return (b
->enable_state
== bp_enabled
);
602 /* Set breakpoint count to NUM. */
605 set_breakpoint_count (int num
)
607 prev_breakpoint_count
= breakpoint_count
;
608 breakpoint_count
= num
;
609 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
612 /* Used by `start_rbreak_breakpoints' below, to record the current
613 breakpoint count before "rbreak" creates any breakpoint. */
614 static int rbreak_start_breakpoint_count
;
616 /* Called at the start an "rbreak" command to record the first
619 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
621 rbreak_start_breakpoint_count
= breakpoint_count
;
624 /* Called at the end of an "rbreak" command to record the last
627 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
629 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
632 /* Used in run_command to zero the hit count when a new run starts. */
635 clear_breakpoint_hit_counts (void)
637 struct breakpoint
*b
;
644 /* Return the breakpoint with the specified number, or NULL
645 if the number does not refer to an existing breakpoint. */
648 get_breakpoint (int num
)
650 struct breakpoint
*b
;
653 if (b
->number
== num
)
661 /* Mark locations as "conditions have changed" in case the target supports
662 evaluating conditions on its side. */
665 mark_breakpoint_modified (struct breakpoint
*b
)
667 struct bp_location
*loc
;
669 /* This is only meaningful if the target is
670 evaluating conditions and if the user has
671 opted for condition evaluation on the target's
673 if (gdb_evaluates_breakpoint_condition_p ()
674 || !target_supports_evaluation_of_breakpoint_conditions ())
677 if (!is_breakpoint (b
))
680 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
681 loc
->condition_changed
= condition_modified
;
684 /* Mark location as "conditions have changed" in case the target supports
685 evaluating conditions on its side. */
688 mark_breakpoint_location_modified (struct bp_location
*loc
)
690 /* This is only meaningful if the target is
691 evaluating conditions and if the user has
692 opted for condition evaluation on the target's
694 if (gdb_evaluates_breakpoint_condition_p ()
695 || !target_supports_evaluation_of_breakpoint_conditions ())
699 if (!is_breakpoint (loc
->owner
))
702 loc
->condition_changed
= condition_modified
;
705 /* Sets the condition-evaluation mode using the static global
706 condition_evaluation_mode. */
709 set_condition_evaluation_mode (const char *args
, int from_tty
,
710 struct cmd_list_element
*c
)
712 const char *old_mode
, *new_mode
;
714 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
715 && !target_supports_evaluation_of_breakpoint_conditions ())
717 condition_evaluation_mode_1
= condition_evaluation_mode
;
718 warning (_("Target does not support breakpoint condition evaluation.\n"
719 "Using host evaluation mode instead."));
723 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
724 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
726 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
727 settings was "auto". */
728 condition_evaluation_mode
= condition_evaluation_mode_1
;
730 /* Only update the mode if the user picked a different one. */
731 if (new_mode
!= old_mode
)
733 struct bp_location
*loc
, **loc_tmp
;
734 /* If the user switched to a different evaluation mode, we
735 need to synch the changes with the target as follows:
737 "host" -> "target": Send all (valid) conditions to the target.
738 "target" -> "host": Remove all the conditions from the target.
741 if (new_mode
== condition_evaluation_target
)
743 /* Mark everything modified and synch conditions with the
745 ALL_BP_LOCATIONS (loc
, loc_tmp
)
746 mark_breakpoint_location_modified (loc
);
750 /* Manually mark non-duplicate locations to synch conditions
751 with the target. We do this to remove all the conditions the
752 target knows about. */
753 ALL_BP_LOCATIONS (loc
, loc_tmp
)
754 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
755 loc
->needs_update
= 1;
759 update_global_location_list (UGLL_MAY_INSERT
);
765 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
766 what "auto" is translating to. */
769 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
770 struct cmd_list_element
*c
, const char *value
)
772 if (condition_evaluation_mode
== condition_evaluation_auto
)
773 fprintf_filtered (file
,
774 _("Breakpoint condition evaluation "
775 "mode is %s (currently %s).\n"),
777 breakpoint_condition_evaluation_mode ());
779 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
783 /* A comparison function for bp_location AP and BP that is used by
784 bsearch. This comparison function only cares about addresses, unlike
785 the more general bp_location_is_less_than function. */
788 bp_locations_compare_addrs (const void *ap
, const void *bp
)
790 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
791 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
793 if (a
->address
== b
->address
)
796 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
799 /* Helper function to skip all bp_locations with addresses
800 less than ADDRESS. It returns the first bp_location that
801 is greater than or equal to ADDRESS. If none is found, just
804 static struct bp_location
**
805 get_first_locp_gte_addr (CORE_ADDR address
)
807 struct bp_location dummy_loc
;
808 struct bp_location
*dummy_locp
= &dummy_loc
;
809 struct bp_location
**locp_found
= NULL
;
811 /* Initialize the dummy location's address field. */
812 dummy_loc
.address
= address
;
814 /* Find a close match to the first location at ADDRESS. */
815 locp_found
= ((struct bp_location
**)
816 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
817 sizeof (struct bp_location
**),
818 bp_locations_compare_addrs
));
820 /* Nothing was found, nothing left to do. */
821 if (locp_found
== NULL
)
824 /* We may have found a location that is at ADDRESS but is not the first in the
825 location's list. Go backwards (if possible) and locate the first one. */
826 while ((locp_found
- 1) >= bp_locations
827 && (*(locp_found
- 1))->address
== address
)
834 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
839 xfree (b
->cond_string
);
840 b
->cond_string
= nullptr;
842 if (is_watchpoint (b
))
843 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
846 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
850 /* No need to free the condition agent expression
851 bytecode (if we have one). We will handle this
852 when we go through update_global_location_list. */
857 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
861 if (is_watchpoint (b
))
863 innermost_block_tracker tracker
;
864 const char *arg
= exp
;
865 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
867 error (_("Junk at end of expression"));
868 watchpoint
*w
= static_cast<watchpoint
*> (b
);
869 w
->cond_exp
= std::move (new_exp
);
870 w
->cond_exp_valid_block
= tracker
.block ();
874 /* Parse and set condition expressions. We make two passes.
875 In the first, we parse the condition string to see if it
876 is valid in all locations. If so, the condition would be
877 accepted. So we go ahead and set the locations'
878 conditions. In case a failing case is found, we throw
879 the error and the condition string will be rejected.
880 This two-pass approach is taken to avoid setting the
881 state of locations in case of a reject. */
882 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
884 const char *arg
= exp
;
885 parse_exp_1 (&arg
, loc
->address
,
886 block_for_pc (loc
->address
), 0);
888 error (_("Junk at end of expression"));
891 /* If we reach here, the condition is valid at all locations. */
892 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
894 const char *arg
= exp
;
896 parse_exp_1 (&arg
, loc
->address
,
897 block_for_pc (loc
->address
), 0);
901 /* We know that the new condition parsed successfully. The
902 condition string of the breakpoint can be safely updated. */
903 xfree (b
->cond_string
);
904 b
->cond_string
= xstrdup (exp
);
905 b
->condition_not_parsed
= 0;
907 mark_breakpoint_modified (b
);
909 gdb::observers::breakpoint_modified
.notify (b
);
912 /* Completion for the "condition" command. */
915 condition_completer (struct cmd_list_element
*cmd
,
916 completion_tracker
&tracker
,
917 const char *text
, const char *word
)
921 text
= skip_spaces (text
);
922 space
= skip_to_space (text
);
926 struct breakpoint
*b
;
930 /* We don't support completion of history indices. */
931 if (!isdigit (text
[1]))
932 complete_internalvar (tracker
, &text
[1]);
936 /* We're completing the breakpoint number. */
943 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
945 if (strncmp (number
, text
, len
) == 0)
946 tracker
.add_completion (make_unique_xstrdup (number
));
952 /* We're completing the expression part. */
953 text
= skip_spaces (space
);
954 expression_completer (cmd
, tracker
, text
, word
);
957 /* condition N EXP -- set break condition of breakpoint N to EXP. */
960 condition_command (const char *arg
, int from_tty
)
962 struct breakpoint
*b
;
967 error_no_arg (_("breakpoint number"));
970 bnum
= get_number (&p
);
972 error (_("Bad breakpoint argument: '%s'"), arg
);
975 if (b
->number
== bnum
)
977 /* Check if this breakpoint has a "stop" method implemented in an
978 extension language. This method and conditions entered into GDB
979 from the CLI are mutually exclusive. */
980 const struct extension_language_defn
*extlang
981 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
985 error (_("Only one stop condition allowed. There is currently"
986 " a %s stop condition defined for this breakpoint."),
987 ext_lang_capitalized_name (extlang
));
989 set_breakpoint_condition (b
, p
, from_tty
);
991 if (is_breakpoint (b
))
992 update_global_location_list (UGLL_MAY_INSERT
);
997 error (_("No breakpoint number %d."), bnum
);
1000 /* Check that COMMAND do not contain commands that are suitable
1001 only for tracepoints and not suitable for ordinary breakpoints.
1002 Throw if any such commands is found. */
1005 check_no_tracepoint_commands (struct command_line
*commands
)
1007 struct command_line
*c
;
1009 for (c
= commands
; c
; c
= c
->next
)
1011 if (c
->control_type
== while_stepping_control
)
1012 error (_("The 'while-stepping' command can "
1013 "only be used for tracepoints"));
1015 check_no_tracepoint_commands (c
->body_list_0
.get ());
1016 check_no_tracepoint_commands (c
->body_list_1
.get ());
1018 /* Not that command parsing removes leading whitespace and comment
1019 lines and also empty lines. So, we only need to check for
1020 command directly. */
1021 if (strstr (c
->line
, "collect ") == c
->line
)
1022 error (_("The 'collect' command can only be used for tracepoints"));
1024 if (strstr (c
->line
, "teval ") == c
->line
)
1025 error (_("The 'teval' command can only be used for tracepoints"));
1029 struct longjmp_breakpoint
: public breakpoint
1031 ~longjmp_breakpoint () override
;
1034 /* Encapsulate tests for different types of tracepoints. */
1037 is_tracepoint_type (bptype type
)
1039 return (type
== bp_tracepoint
1040 || type
== bp_fast_tracepoint
1041 || type
== bp_static_tracepoint
);
1045 is_longjmp_type (bptype type
)
1047 return type
== bp_longjmp
|| type
== bp_exception
;
1050 /* See breakpoint.h. */
1053 is_tracepoint (const struct breakpoint
*b
)
1055 return is_tracepoint_type (b
->type
);
1058 /* Factory function to create an appropriate instance of breakpoint given
1061 static std::unique_ptr
<breakpoint
>
1062 new_breakpoint_from_type (bptype type
)
1066 if (is_tracepoint_type (type
))
1067 b
= new tracepoint ();
1068 else if (is_longjmp_type (type
))
1069 b
= new longjmp_breakpoint ();
1071 b
= new breakpoint ();
1073 return std::unique_ptr
<breakpoint
> (b
);
1076 /* A helper function that validates that COMMANDS are valid for a
1077 breakpoint. This function will throw an exception if a problem is
1081 validate_commands_for_breakpoint (struct breakpoint
*b
,
1082 struct command_line
*commands
)
1084 if (is_tracepoint (b
))
1086 struct tracepoint
*t
= (struct tracepoint
*) b
;
1087 struct command_line
*c
;
1088 struct command_line
*while_stepping
= 0;
1090 /* Reset the while-stepping step count. The previous commands
1091 might have included a while-stepping action, while the new
1095 /* We need to verify that each top-level element of commands is
1096 valid for tracepoints, that there's at most one
1097 while-stepping element, and that the while-stepping's body
1098 has valid tracing commands excluding nested while-stepping.
1099 We also need to validate the tracepoint action line in the
1100 context of the tracepoint --- validate_actionline actually
1101 has side effects, like setting the tracepoint's
1102 while-stepping STEP_COUNT, in addition to checking if the
1103 collect/teval actions parse and make sense in the
1104 tracepoint's context. */
1105 for (c
= commands
; c
; c
= c
->next
)
1107 if (c
->control_type
== while_stepping_control
)
1109 if (b
->type
== bp_fast_tracepoint
)
1110 error (_("The 'while-stepping' command "
1111 "cannot be used for fast tracepoint"));
1112 else if (b
->type
== bp_static_tracepoint
)
1113 error (_("The 'while-stepping' command "
1114 "cannot be used for static tracepoint"));
1117 error (_("The 'while-stepping' command "
1118 "can be used only once"));
1123 validate_actionline (c
->line
, b
);
1127 struct command_line
*c2
;
1129 gdb_assert (while_stepping
->body_list_1
== nullptr);
1130 c2
= while_stepping
->body_list_0
.get ();
1131 for (; c2
; c2
= c2
->next
)
1133 if (c2
->control_type
== while_stepping_control
)
1134 error (_("The 'while-stepping' command cannot be nested"));
1140 check_no_tracepoint_commands (commands
);
1144 /* Return a vector of all the static tracepoints set at ADDR. The
1145 caller is responsible for releasing the vector. */
1147 std::vector
<breakpoint
*>
1148 static_tracepoints_here (CORE_ADDR addr
)
1150 struct breakpoint
*b
;
1151 std::vector
<breakpoint
*> found
;
1152 struct bp_location
*loc
;
1155 if (b
->type
== bp_static_tracepoint
)
1157 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1158 if (loc
->address
== addr
)
1159 found
.push_back (b
);
1165 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1166 validate that only allowed commands are included. */
1169 breakpoint_set_commands (struct breakpoint
*b
,
1170 counted_command_line
&&commands
)
1172 validate_commands_for_breakpoint (b
, commands
.get ());
1174 b
->commands
= std::move (commands
);
1175 gdb::observers::breakpoint_modified
.notify (b
);
1178 /* Set the internal `silent' flag on the breakpoint. Note that this
1179 is not the same as the "silent" that may appear in the breakpoint's
1183 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1185 int old_silent
= b
->silent
;
1188 if (old_silent
!= silent
)
1189 gdb::observers::breakpoint_modified
.notify (b
);
1192 /* Set the thread for this breakpoint. If THREAD is -1, make the
1193 breakpoint work for any thread. */
1196 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1198 int old_thread
= b
->thread
;
1201 if (old_thread
!= thread
)
1202 gdb::observers::breakpoint_modified
.notify (b
);
1205 /* Set the task for this breakpoint. If TASK is 0, make the
1206 breakpoint work for any task. */
1209 breakpoint_set_task (struct breakpoint
*b
, int task
)
1211 int old_task
= b
->task
;
1214 if (old_task
!= task
)
1215 gdb::observers::breakpoint_modified
.notify (b
);
1219 commands_command_1 (const char *arg
, int from_tty
,
1220 struct command_line
*control
)
1222 counted_command_line cmd
;
1223 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1224 NULL after the call to read_command_lines if the user provides an empty
1225 list of command by just typing "end". */
1226 bool cmd_read
= false;
1228 std::string new_arg
;
1230 if (arg
== NULL
|| !*arg
)
1232 /* Argument not explicitly given. Synthesize it. */
1233 if (breakpoint_count
- prev_breakpoint_count
> 1)
1234 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1236 else if (breakpoint_count
> 0)
1237 new_arg
= string_printf ("%d", breakpoint_count
);
1241 /* Create a copy of ARG. This is needed because the "commands"
1242 command may be coming from a script. In that case, the read
1243 line buffer is going to be overwritten in the lambda of
1244 'map_breakpoint_numbers' below when reading the next line
1245 before we are are done parsing the breakpoint numbers. */
1248 arg
= new_arg
.c_str ();
1250 map_breakpoint_numbers
1251 (arg
, [&] (breakpoint
*b
)
1255 gdb_assert (cmd
== NULL
);
1256 if (control
!= NULL
)
1257 cmd
= control
->body_list_0
;
1261 = string_printf (_("Type commands for breakpoint(s) "
1262 "%s, one per line."),
1265 auto do_validate
= [=] (const char *line
)
1267 validate_actionline (line
, b
);
1269 gdb::function_view
<void (const char *)> validator
;
1270 if (is_tracepoint (b
))
1271 validator
= do_validate
;
1273 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1278 /* If a breakpoint was on the list more than once, we don't need to
1280 if (b
->commands
!= cmd
)
1282 validate_commands_for_breakpoint (b
, cmd
.get ());
1284 gdb::observers::breakpoint_modified
.notify (b
);
1290 commands_command (const char *arg
, int from_tty
)
1292 commands_command_1 (arg
, from_tty
, NULL
);
1295 /* Like commands_command, but instead of reading the commands from
1296 input stream, takes them from an already parsed command structure.
1298 This is used by cli-script.c to DTRT with breakpoint commands
1299 that are part of if and while bodies. */
1300 enum command_control_type
1301 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1303 commands_command_1 (arg
, 0, cmd
);
1304 return simple_control
;
1307 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1310 bp_location_has_shadow (struct bp_location
*bl
)
1312 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1316 if (bl
->target_info
.shadow_len
== 0)
1317 /* BL isn't valid, or doesn't shadow memory. */
1322 /* Update BUF, which is LEN bytes read from the target address
1323 MEMADDR, by replacing a memory breakpoint with its shadowed
1326 If READBUF is not NULL, this buffer must not overlap with the of
1327 the breakpoint location's shadow_contents buffer. Otherwise, a
1328 failed assertion internal error will be raised. */
1331 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1332 const gdb_byte
*writebuf_org
,
1333 ULONGEST memaddr
, LONGEST len
,
1334 struct bp_target_info
*target_info
,
1335 struct gdbarch
*gdbarch
)
1337 /* Now do full processing of the found relevant range of elements. */
1338 CORE_ADDR bp_addr
= 0;
1342 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1343 current_program_space
->aspace
, 0))
1345 /* The breakpoint is inserted in a different address space. */
1349 /* Addresses and length of the part of the breakpoint that
1351 bp_addr
= target_info
->placed_address
;
1352 bp_size
= target_info
->shadow_len
;
1354 if (bp_addr
+ bp_size
<= memaddr
)
1356 /* The breakpoint is entirely before the chunk of memory we are
1361 if (bp_addr
>= memaddr
+ len
)
1363 /* The breakpoint is entirely after the chunk of memory we are
1368 /* Offset within shadow_contents. */
1369 if (bp_addr
< memaddr
)
1371 /* Only copy the second part of the breakpoint. */
1372 bp_size
-= memaddr
- bp_addr
;
1373 bptoffset
= memaddr
- bp_addr
;
1377 if (bp_addr
+ bp_size
> memaddr
+ len
)
1379 /* Only copy the first part of the breakpoint. */
1380 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1383 if (readbuf
!= NULL
)
1385 /* Verify that the readbuf buffer does not overlap with the
1386 shadow_contents buffer. */
1387 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1388 || readbuf
>= (target_info
->shadow_contents
1389 + target_info
->shadow_len
));
1391 /* Update the read buffer with this inserted breakpoint's
1393 memcpy (readbuf
+ bp_addr
- memaddr
,
1394 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1398 const unsigned char *bp
;
1399 CORE_ADDR addr
= target_info
->reqstd_address
;
1402 /* Update the shadow with what we want to write to memory. */
1403 memcpy (target_info
->shadow_contents
+ bptoffset
,
1404 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1406 /* Determine appropriate breakpoint contents and size for this
1408 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1410 /* Update the final write buffer with this inserted
1411 breakpoint's INSN. */
1412 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1416 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1417 by replacing any memory breakpoints with their shadowed contents.
1419 If READBUF is not NULL, this buffer must not overlap with any of
1420 the breakpoint location's shadow_contents buffers. Otherwise,
1421 a failed assertion internal error will be raised.
1423 The range of shadowed area by each bp_location is:
1424 bl->address - bp_locations_placed_address_before_address_max
1425 up to bl->address + bp_locations_shadow_len_after_address_max
1426 The range we were requested to resolve shadows for is:
1427 memaddr ... memaddr + len
1428 Thus the safe cutoff boundaries for performance optimization are
1429 memaddr + len <= (bl->address
1430 - bp_locations_placed_address_before_address_max)
1432 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1435 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1436 const gdb_byte
*writebuf_org
,
1437 ULONGEST memaddr
, LONGEST len
)
1439 /* Left boundary, right boundary and median element of our binary
1441 unsigned bc_l
, bc_r
, bc
;
1443 /* Find BC_L which is a leftmost element which may affect BUF
1444 content. It is safe to report lower value but a failure to
1445 report higher one. */
1448 bc_r
= bp_locations_count
;
1449 while (bc_l
+ 1 < bc_r
)
1451 struct bp_location
*bl
;
1453 bc
= (bc_l
+ bc_r
) / 2;
1454 bl
= bp_locations
[bc
];
1456 /* Check first BL->ADDRESS will not overflow due to the added
1457 constant. Then advance the left boundary only if we are sure
1458 the BC element can in no way affect the BUF content (MEMADDR
1459 to MEMADDR + LEN range).
1461 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1462 offset so that we cannot miss a breakpoint with its shadow
1463 range tail still reaching MEMADDR. */
1465 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1467 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1474 /* Due to the binary search above, we need to make sure we pick the
1475 first location that's at BC_L's address. E.g., if there are
1476 multiple locations at the same address, BC_L may end up pointing
1477 at a duplicate location, and miss the "master"/"inserted"
1478 location. Say, given locations L1, L2 and L3 at addresses A and
1481 L1@A, L2@A, L3@B, ...
1483 BC_L could end up pointing at location L2, while the "master"
1484 location could be L1. Since the `loc->inserted' flag is only set
1485 on "master" locations, we'd forget to restore the shadow of L1
1488 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1491 /* Now do full processing of the found relevant range of elements. */
1493 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1495 struct bp_location
*bl
= bp_locations
[bc
];
1497 /* bp_location array has BL->OWNER always non-NULL. */
1498 if (bl
->owner
->type
== bp_none
)
1499 warning (_("reading through apparently deleted breakpoint #%d?"),
1502 /* Performance optimization: any further element can no longer affect BUF
1505 if (bl
->address
>= bp_locations_placed_address_before_address_max
1506 && memaddr
+ len
<= (bl
->address
1507 - bp_locations_placed_address_before_address_max
))
1510 if (!bp_location_has_shadow (bl
))
1513 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1514 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1518 /* See breakpoint.h. */
1521 is_breakpoint (const struct breakpoint
*bpt
)
1523 return (bpt
->type
== bp_breakpoint
1524 || bpt
->type
== bp_hardware_breakpoint
1525 || bpt
->type
== bp_dprintf
);
1528 /* Return true if BPT is of any hardware watchpoint kind. */
1531 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1533 return (bpt
->type
== bp_hardware_watchpoint
1534 || bpt
->type
== bp_read_watchpoint
1535 || bpt
->type
== bp_access_watchpoint
);
1538 /* See breakpoint.h. */
1541 is_watchpoint (const struct breakpoint
*bpt
)
1543 return (is_hardware_watchpoint (bpt
)
1544 || bpt
->type
== bp_watchpoint
);
1547 /* Returns true if the current thread and its running state are safe
1548 to evaluate or update watchpoint B. Watchpoints on local
1549 expressions need to be evaluated in the context of the thread that
1550 was current when the watchpoint was created, and, that thread needs
1551 to be stopped to be able to select the correct frame context.
1552 Watchpoints on global expressions can be evaluated on any thread,
1553 and in any state. It is presently left to the target allowing
1554 memory accesses when threads are running. */
1557 watchpoint_in_thread_scope (struct watchpoint
*b
)
1559 return (b
->pspace
== current_program_space
1560 && (b
->watchpoint_thread
== null_ptid
1561 || (inferior_ptid
== b
->watchpoint_thread
1562 && !inferior_thread ()->executing
)));
1565 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1566 associated bp_watchpoint_scope breakpoint. */
1569 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1571 if (w
->related_breakpoint
!= w
)
1573 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1574 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1575 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1576 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1577 w
->related_breakpoint
= w
;
1579 w
->disposition
= disp_del_at_next_stop
;
1582 /* Extract a bitfield value from value VAL using the bit parameters contained in
1585 static struct value
*
1586 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1588 struct value
*bit_val
;
1593 bit_val
= allocate_value (value_type (val
));
1595 unpack_value_bitfield (bit_val
,
1598 value_contents_for_printing (val
),
1605 /* Allocate a dummy location and add it to B, which must be a software
1606 watchpoint. This is required because even if a software watchpoint
1607 is not watching any memory, bpstat_stop_status requires a location
1608 to be able to report stops. */
1611 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1612 struct program_space
*pspace
)
1614 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1616 b
->loc
= allocate_bp_location (b
);
1617 b
->loc
->pspace
= pspace
;
1618 b
->loc
->address
= -1;
1619 b
->loc
->length
= -1;
1622 /* Returns true if B is a software watchpoint that is not watching any
1623 memory (e.g., "watch $pc"). */
1626 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1628 return (b
->type
== bp_watchpoint
1630 && b
->loc
->next
== NULL
1631 && b
->loc
->address
== -1
1632 && b
->loc
->length
== -1);
1635 /* Assuming that B is a watchpoint:
1636 - Reparse watchpoint expression, if REPARSE is non-zero
1637 - Evaluate expression and store the result in B->val
1638 - Evaluate the condition if there is one, and store the result
1640 - Update the list of values that must be watched in B->loc.
1642 If the watchpoint disposition is disp_del_at_next_stop, then do
1643 nothing. If this is local watchpoint that is out of scope, delete
1646 Even with `set breakpoint always-inserted on' the watchpoints are
1647 removed + inserted on each stop here. Normal breakpoints must
1648 never be removed because they might be missed by a running thread
1649 when debugging in non-stop mode. On the other hand, hardware
1650 watchpoints (is_hardware_watchpoint; processed here) are specific
1651 to each LWP since they are stored in each LWP's hardware debug
1652 registers. Therefore, such LWP must be stopped first in order to
1653 be able to modify its hardware watchpoints.
1655 Hardware watchpoints must be reset exactly once after being
1656 presented to the user. It cannot be done sooner, because it would
1657 reset the data used to present the watchpoint hit to the user. And
1658 it must not be done later because it could display the same single
1659 watchpoint hit during multiple GDB stops. Note that the latter is
1660 relevant only to the hardware watchpoint types bp_read_watchpoint
1661 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1662 not user-visible - its hit is suppressed if the memory content has
1665 The following constraints influence the location where we can reset
1666 hardware watchpoints:
1668 * target_stopped_by_watchpoint and target_stopped_data_address are
1669 called several times when GDB stops.
1672 * Multiple hardware watchpoints can be hit at the same time,
1673 causing GDB to stop. GDB only presents one hardware watchpoint
1674 hit at a time as the reason for stopping, and all the other hits
1675 are presented later, one after the other, each time the user
1676 requests the execution to be resumed. Execution is not resumed
1677 for the threads still having pending hit event stored in
1678 LWP_INFO->STATUS. While the watchpoint is already removed from
1679 the inferior on the first stop the thread hit event is kept being
1680 reported from its cached value by linux_nat_stopped_data_address
1681 until the real thread resume happens after the watchpoint gets
1682 presented and thus its LWP_INFO->STATUS gets reset.
1684 Therefore the hardware watchpoint hit can get safely reset on the
1685 watchpoint removal from inferior. */
1688 update_watchpoint (struct watchpoint
*b
, int reparse
)
1690 int within_current_scope
;
1691 struct frame_id saved_frame_id
;
1694 /* If this is a local watchpoint, we only want to check if the
1695 watchpoint frame is in scope if the current thread is the thread
1696 that was used to create the watchpoint. */
1697 if (!watchpoint_in_thread_scope (b
))
1700 if (b
->disposition
== disp_del_at_next_stop
)
1705 /* Determine if the watchpoint is within scope. */
1706 if (b
->exp_valid_block
== NULL
)
1707 within_current_scope
= 1;
1710 struct frame_info
*fi
= get_current_frame ();
1711 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1712 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1714 /* If we're at a point where the stack has been destroyed
1715 (e.g. in a function epilogue), unwinding may not work
1716 properly. Do not attempt to recreate locations at this
1717 point. See similar comments in watchpoint_check. */
1718 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1721 /* Save the current frame's ID so we can restore it after
1722 evaluating the watchpoint expression on its own frame. */
1723 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1724 took a frame parameter, so that we didn't have to change the
1727 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1729 fi
= frame_find_by_id (b
->watchpoint_frame
);
1730 within_current_scope
= (fi
!= NULL
);
1731 if (within_current_scope
)
1735 /* We don't free locations. They are stored in the bp_location array
1736 and update_global_location_list will eventually delete them and
1737 remove breakpoints if needed. */
1740 if (within_current_scope
&& reparse
)
1745 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1746 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1747 /* If the meaning of expression itself changed, the old value is
1748 no longer relevant. We don't want to report a watchpoint hit
1749 to the user when the old value and the new value may actually
1750 be completely different objects. */
1752 b
->val_valid
= false;
1754 /* Note that unlike with breakpoints, the watchpoint's condition
1755 expression is stored in the breakpoint object, not in the
1756 locations (re)created below. */
1757 if (b
->cond_string
!= NULL
)
1759 b
->cond_exp
.reset ();
1762 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1766 /* If we failed to parse the expression, for example because
1767 it refers to a global variable in a not-yet-loaded shared library,
1768 don't try to insert watchpoint. We don't automatically delete
1769 such watchpoint, though, since failure to parse expression
1770 is different from out-of-scope watchpoint. */
1771 if (!target_has_execution ())
1773 /* Without execution, memory can't change. No use to try and
1774 set watchpoint locations. The watchpoint will be reset when
1775 the target gains execution, through breakpoint_re_set. */
1776 if (!can_use_hw_watchpoints
)
1778 if (b
->ops
->works_in_software_mode (b
))
1779 b
->type
= bp_watchpoint
;
1781 error (_("Can't set read/access watchpoint when "
1782 "hardware watchpoints are disabled."));
1785 else if (within_current_scope
&& b
->exp
)
1788 std::vector
<value_ref_ptr
> val_chain
;
1789 struct value
*v
, *result
;
1790 struct program_space
*frame_pspace
;
1792 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1794 /* Avoid setting b->val if it's already set. The meaning of
1795 b->val is 'the last value' user saw, and we should update
1796 it only if we reported that last value to user. As it
1797 happens, the code that reports it updates b->val directly.
1798 We don't keep track of the memory value for masked
1800 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1802 if (b
->val_bitsize
!= 0)
1803 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1804 b
->val
= release_value (v
);
1805 b
->val_valid
= true;
1808 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1810 /* Look at each value on the value chain. */
1811 gdb_assert (!val_chain
.empty ());
1812 for (const value_ref_ptr
&iter
: val_chain
)
1816 /* If it's a memory location, and GDB actually needed
1817 its contents to evaluate the expression, then we
1818 must watch it. If the first value returned is
1819 still lazy, that means an error occurred reading it;
1820 watch it anyway in case it becomes readable. */
1821 if (VALUE_LVAL (v
) == lval_memory
1822 && (v
== val_chain
[0] || ! value_lazy (v
)))
1824 struct type
*vtype
= check_typedef (value_type (v
));
1826 /* We only watch structs and arrays if user asked
1827 for it explicitly, never if they just happen to
1828 appear in the middle of some value chain. */
1830 || (vtype
->code () != TYPE_CODE_STRUCT
1831 && vtype
->code () != TYPE_CODE_ARRAY
))
1834 enum target_hw_bp_type type
;
1835 struct bp_location
*loc
, **tmp
;
1836 int bitpos
= 0, bitsize
= 0;
1838 if (value_bitsize (v
) != 0)
1840 /* Extract the bit parameters out from the bitfield
1842 bitpos
= value_bitpos (v
);
1843 bitsize
= value_bitsize (v
);
1845 else if (v
== result
&& b
->val_bitsize
!= 0)
1847 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1848 lvalue whose bit parameters are saved in the fields
1849 VAL_BITPOS and VAL_BITSIZE. */
1850 bitpos
= b
->val_bitpos
;
1851 bitsize
= b
->val_bitsize
;
1854 addr
= value_address (v
);
1857 /* Skip the bytes that don't contain the bitfield. */
1862 if (b
->type
== bp_read_watchpoint
)
1864 else if (b
->type
== bp_access_watchpoint
)
1867 loc
= allocate_bp_location (b
);
1868 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1871 loc
->gdbarch
= get_type_arch (value_type (v
));
1873 loc
->pspace
= frame_pspace
;
1874 loc
->address
= address_significant (loc
->gdbarch
, addr
);
1878 /* Just cover the bytes that make up the bitfield. */
1879 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1882 loc
->length
= TYPE_LENGTH (value_type (v
));
1884 loc
->watchpoint_type
= type
;
1889 /* Change the type of breakpoint between hardware assisted or
1890 an ordinary watchpoint depending on the hardware support
1891 and free hardware slots. REPARSE is set when the inferior
1896 enum bp_loc_type loc_type
;
1897 struct bp_location
*bl
;
1899 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1903 int i
, target_resources_ok
, other_type_used
;
1906 /* Use an exact watchpoint when there's only one memory region to be
1907 watched, and only one debug register is needed to watch it. */
1908 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1910 /* We need to determine how many resources are already
1911 used for all other hardware watchpoints plus this one
1912 to see if we still have enough resources to also fit
1913 this watchpoint in as well. */
1915 /* If this is a software watchpoint, we try to turn it
1916 to a hardware one -- count resources as if B was of
1917 hardware watchpoint type. */
1919 if (type
== bp_watchpoint
)
1920 type
= bp_hardware_watchpoint
;
1922 /* This watchpoint may or may not have been placed on
1923 the list yet at this point (it won't be in the list
1924 if we're trying to create it for the first time,
1925 through watch_command), so always account for it
1928 /* Count resources used by all watchpoints except B. */
1929 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1931 /* Add in the resources needed for B. */
1932 i
+= hw_watchpoint_use_count (b
);
1935 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1936 if (target_resources_ok
<= 0)
1938 int sw_mode
= b
->ops
->works_in_software_mode (b
);
1940 if (target_resources_ok
== 0 && !sw_mode
)
1941 error (_("Target does not support this type of "
1942 "hardware watchpoint."));
1943 else if (target_resources_ok
< 0 && !sw_mode
)
1944 error (_("There are not enough available hardware "
1945 "resources for this watchpoint."));
1947 /* Downgrade to software watchpoint. */
1948 b
->type
= bp_watchpoint
;
1952 /* If this was a software watchpoint, we've just
1953 found we have enough resources to turn it to a
1954 hardware watchpoint. Otherwise, this is a
1959 else if (!b
->ops
->works_in_software_mode (b
))
1961 if (!can_use_hw_watchpoints
)
1962 error (_("Can't set read/access watchpoint when "
1963 "hardware watchpoints are disabled."));
1965 error (_("Expression cannot be implemented with "
1966 "read/access watchpoint."));
1969 b
->type
= bp_watchpoint
;
1971 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1972 : bp_loc_hardware_watchpoint
);
1973 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1974 bl
->loc_type
= loc_type
;
1977 /* If a software watchpoint is not watching any memory, then the
1978 above left it without any location set up. But,
1979 bpstat_stop_status requires a location to be able to report
1980 stops, so make sure there's at least a dummy one. */
1981 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1982 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
1984 else if (!within_current_scope
)
1986 printf_filtered (_("\
1987 Watchpoint %d deleted because the program has left the block\n\
1988 in which its expression is valid.\n"),
1990 watchpoint_del_at_next_stop (b
);
1993 /* Restore the selected frame. */
1995 select_frame (frame_find_by_id (saved_frame_id
));
1999 /* Returns 1 iff breakpoint location should be
2000 inserted in the inferior. We don't differentiate the type of BL's owner
2001 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2002 breakpoint_ops is not defined, because in insert_bp_location,
2003 tracepoint's insert_location will not be called. */
2005 should_be_inserted (struct bp_location
*bl
)
2007 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2010 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2013 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2016 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2019 /* This is set for example, when we're attached to the parent of a
2020 vfork, and have detached from the child. The child is running
2021 free, and we expect it to do an exec or exit, at which point the
2022 OS makes the parent schedulable again (and the target reports
2023 that the vfork is done). Until the child is done with the shared
2024 memory region, do not insert breakpoints in the parent, otherwise
2025 the child could still trip on the parent's breakpoints. Since
2026 the parent is blocked anyway, it won't miss any breakpoint. */
2027 if (bl
->pspace
->breakpoints_not_allowed
)
2030 /* Don't insert a breakpoint if we're trying to step past its
2031 location, except if the breakpoint is a single-step breakpoint,
2032 and the breakpoint's thread is the thread which is stepping past
2034 if ((bl
->loc_type
== bp_loc_software_breakpoint
2035 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2036 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2038 /* The single-step breakpoint may be inserted at the location
2039 we're trying to step if the instruction branches to itself.
2040 However, the instruction won't be executed at all and it may
2041 break the semantics of the instruction, for example, the
2042 instruction is a conditional branch or updates some flags.
2043 We can't fix it unless GDB is able to emulate the instruction
2044 or switch to displaced stepping. */
2045 && !(bl
->owner
->type
== bp_single_step
2046 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2048 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2049 paddress (bl
->gdbarch
, bl
->address
));
2053 /* Don't insert watchpoints if we're trying to step past the
2054 instruction that triggered one. */
2055 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2056 && stepping_past_nonsteppable_watchpoint ())
2058 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2059 "skipping watchpoint at %s:%d\n",
2060 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2067 /* Same as should_be_inserted but does the check assuming
2068 that the location is not duplicated. */
2071 unduplicated_should_be_inserted (struct bp_location
*bl
)
2074 const int save_duplicate
= bl
->duplicate
;
2077 result
= should_be_inserted (bl
);
2078 bl
->duplicate
= save_duplicate
;
2082 /* Parses a conditional described by an expression COND into an
2083 agent expression bytecode suitable for evaluation
2084 by the bytecode interpreter. Return NULL if there was
2085 any error during parsing. */
2087 static agent_expr_up
2088 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2093 agent_expr_up aexpr
;
2095 /* We don't want to stop processing, so catch any errors
2096 that may show up. */
2099 aexpr
= gen_eval_for_expr (scope
, cond
);
2102 catch (const gdb_exception_error
&ex
)
2104 /* If we got here, it means the condition could not be parsed to a valid
2105 bytecode expression and thus can't be evaluated on the target's side.
2106 It's no use iterating through the conditions. */
2109 /* We have a valid agent expression. */
2113 /* Based on location BL, create a list of breakpoint conditions to be
2114 passed on to the target. If we have duplicated locations with different
2115 conditions, we will add such conditions to the list. The idea is that the
2116 target will evaluate the list of conditions and will only notify GDB when
2117 one of them is true. */
2120 build_target_condition_list (struct bp_location
*bl
)
2122 struct bp_location
**locp
= NULL
, **loc2p
;
2123 int null_condition_or_parse_error
= 0;
2124 int modified
= bl
->needs_update
;
2125 struct bp_location
*loc
;
2127 /* Release conditions left over from a previous insert. */
2128 bl
->target_info
.conditions
.clear ();
2130 /* This is only meaningful if the target is
2131 evaluating conditions and if the user has
2132 opted for condition evaluation on the target's
2134 if (gdb_evaluates_breakpoint_condition_p ()
2135 || !target_supports_evaluation_of_breakpoint_conditions ())
2138 /* Do a first pass to check for locations with no assigned
2139 conditions or conditions that fail to parse to a valid agent
2140 expression bytecode. If any of these happen, then it's no use to
2141 send conditions to the target since this location will always
2142 trigger and generate a response back to GDB. Note we consider
2143 all locations at the same address irrespective of type, i.e.,
2144 even if the locations aren't considered duplicates (e.g.,
2145 software breakpoint and hardware breakpoint at the same
2147 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2150 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2154 /* Re-parse the conditions since something changed. In that
2155 case we already freed the condition bytecodes (see
2156 force_breakpoint_reinsertion). We just
2157 need to parse the condition to bytecodes again. */
2158 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2162 /* If we have a NULL bytecode expression, it means something
2163 went wrong or we have a null condition expression. */
2164 if (!loc
->cond_bytecode
)
2166 null_condition_or_parse_error
= 1;
2172 /* If any of these happened, it means we will have to evaluate the conditions
2173 for the location's address on gdb's side. It is no use keeping bytecodes
2174 for all the other duplicate locations, thus we free all of them here.
2176 This is so we have a finer control over which locations' conditions are
2177 being evaluated by GDB or the remote stub. */
2178 if (null_condition_or_parse_error
)
2180 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2183 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2185 /* Only go as far as the first NULL bytecode is
2187 if (!loc
->cond_bytecode
)
2190 loc
->cond_bytecode
.reset ();
2195 /* No NULL conditions or failed bytecode generation. Build a
2196 condition list for this location's address. If we have software
2197 and hardware locations at the same address, they aren't
2198 considered duplicates, but we still marge all the conditions
2199 anyway, as it's simpler, and doesn't really make a practical
2201 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2205 && is_breakpoint (loc
->owner
)
2206 && loc
->pspace
->num
== bl
->pspace
->num
2207 && loc
->owner
->enable_state
== bp_enabled
2210 /* Add the condition to the vector. This will be used later
2211 to send the conditions to the target. */
2212 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2219 /* Parses a command described by string CMD into an agent expression
2220 bytecode suitable for evaluation by the bytecode interpreter.
2221 Return NULL if there was any error during parsing. */
2223 static agent_expr_up
2224 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2226 const char *cmdrest
;
2227 const char *format_start
, *format_end
;
2228 struct gdbarch
*gdbarch
= get_current_arch ();
2235 if (*cmdrest
== ',')
2237 cmdrest
= skip_spaces (cmdrest
);
2239 if (*cmdrest
++ != '"')
2240 error (_("No format string following the location"));
2242 format_start
= cmdrest
;
2244 format_pieces
fpieces (&cmdrest
);
2246 format_end
= cmdrest
;
2248 if (*cmdrest
++ != '"')
2249 error (_("Bad format string, non-terminated '\"'."));
2251 cmdrest
= skip_spaces (cmdrest
);
2253 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2254 error (_("Invalid argument syntax"));
2256 if (*cmdrest
== ',')
2258 cmdrest
= skip_spaces (cmdrest
);
2260 /* For each argument, make an expression. */
2262 std::vector
<struct expression
*> argvec
;
2263 while (*cmdrest
!= '\0')
2268 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2269 argvec
.push_back (expr
.release ());
2271 if (*cmdrest
== ',')
2275 agent_expr_up aexpr
;
2277 /* We don't want to stop processing, so catch any errors
2278 that may show up. */
2281 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2282 format_start
, format_end
- format_start
,
2283 argvec
.size (), argvec
.data ());
2285 catch (const gdb_exception_error
&ex
)
2287 /* If we got here, it means the command could not be parsed to a valid
2288 bytecode expression and thus can't be evaluated on the target's side.
2289 It's no use iterating through the other commands. */
2292 /* We have a valid agent expression, return it. */
2296 /* Based on location BL, create a list of breakpoint commands to be
2297 passed on to the target. If we have duplicated locations with
2298 different commands, we will add any such to the list. */
2301 build_target_command_list (struct bp_location
*bl
)
2303 struct bp_location
**locp
= NULL
, **loc2p
;
2304 int null_command_or_parse_error
= 0;
2305 int modified
= bl
->needs_update
;
2306 struct bp_location
*loc
;
2308 /* Clear commands left over from a previous insert. */
2309 bl
->target_info
.tcommands
.clear ();
2311 if (!target_can_run_breakpoint_commands ())
2314 /* For now, limit to agent-style dprintf breakpoints. */
2315 if (dprintf_style
!= dprintf_style_agent
)
2318 /* For now, if we have any location at the same address that isn't a
2319 dprintf, don't install the target-side commands, as that would
2320 make the breakpoint not be reported to the core, and we'd lose
2322 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2325 if (is_breakpoint (loc
->owner
)
2326 && loc
->pspace
->num
== bl
->pspace
->num
2327 && loc
->owner
->type
!= bp_dprintf
)
2331 /* Do a first pass to check for locations with no assigned
2332 conditions or conditions that fail to parse to a valid agent expression
2333 bytecode. If any of these happen, then it's no use to send conditions
2334 to the target since this location will always trigger and generate a
2335 response back to GDB. */
2336 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2339 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2343 /* Re-parse the commands since something changed. In that
2344 case we already freed the command bytecodes (see
2345 force_breakpoint_reinsertion). We just
2346 need to parse the command to bytecodes again. */
2348 = parse_cmd_to_aexpr (bl
->address
,
2349 loc
->owner
->extra_string
);
2352 /* If we have a NULL bytecode expression, it means something
2353 went wrong or we have a null command expression. */
2354 if (!loc
->cmd_bytecode
)
2356 null_command_or_parse_error
= 1;
2362 /* If anything failed, then we're not doing target-side commands,
2364 if (null_command_or_parse_error
)
2366 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2369 if (is_breakpoint (loc
->owner
)
2370 && loc
->pspace
->num
== bl
->pspace
->num
)
2372 /* Only go as far as the first NULL bytecode is
2374 if (loc
->cmd_bytecode
== NULL
)
2377 loc
->cmd_bytecode
.reset ();
2382 /* No NULL commands or failed bytecode generation. Build a command
2383 list for all duplicate locations at this location's address.
2384 Note that here we must care for whether the breakpoint location
2385 types are considered duplicates, otherwise, say, if we have a
2386 software and hardware location at the same address, the target
2387 could end up running the commands twice. For the moment, we only
2388 support targets-side commands with dprintf, but it doesn't hurt
2389 to be pedantically correct in case that changes. */
2390 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2393 if (breakpoint_locations_match (bl
, loc
)
2394 && loc
->owner
->extra_string
2395 && is_breakpoint (loc
->owner
)
2396 && loc
->pspace
->num
== bl
->pspace
->num
2397 && loc
->owner
->enable_state
== bp_enabled
2400 /* Add the command to the vector. This will be used later
2401 to send the commands to the target. */
2402 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2406 bl
->target_info
.persist
= 0;
2407 /* Maybe flag this location as persistent. */
2408 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2409 bl
->target_info
.persist
= 1;
2412 /* Return the kind of breakpoint on address *ADDR. Get the kind
2413 of breakpoint according to ADDR except single-step breakpoint.
2414 Get the kind of single-step breakpoint according to the current
2418 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2420 if (bl
->owner
->type
== bp_single_step
)
2422 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2423 struct regcache
*regcache
;
2425 regcache
= get_thread_regcache (thr
);
2427 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2431 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2434 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2435 location. Any error messages are printed to TMP_ERROR_STREAM; and
2436 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2437 Returns 0 for success, 1 if the bp_location type is not supported or
2440 NOTE drow/2003-09-09: This routine could be broken down to an
2441 object-style method for each breakpoint or catchpoint type. */
2443 insert_bp_location (struct bp_location
*bl
,
2444 struct ui_file
*tmp_error_stream
,
2445 int *disabled_breaks
,
2446 int *hw_breakpoint_error
,
2447 int *hw_bp_error_explained_already
)
2449 gdb_exception bp_excpt
;
2451 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2454 /* Note we don't initialize bl->target_info, as that wipes out
2455 the breakpoint location's shadow_contents if the breakpoint
2456 is still inserted at that location. This in turn breaks
2457 target_read_memory which depends on these buffers when
2458 a memory read is requested at the breakpoint location:
2459 Once the target_info has been wiped, we fail to see that
2460 we have a breakpoint inserted at that address and thus
2461 read the breakpoint instead of returning the data saved in
2462 the breakpoint location's shadow contents. */
2463 bl
->target_info
.reqstd_address
= bl
->address
;
2464 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2465 bl
->target_info
.length
= bl
->length
;
2467 /* When working with target-side conditions, we must pass all the conditions
2468 for the same breakpoint address down to the target since GDB will not
2469 insert those locations. With a list of breakpoint conditions, the target
2470 can decide when to stop and notify GDB. */
2472 if (is_breakpoint (bl
->owner
))
2474 build_target_condition_list (bl
);
2475 build_target_command_list (bl
);
2476 /* Reset the modification marker. */
2477 bl
->needs_update
= 0;
2480 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2481 set at a read-only address, then a breakpoint location will have
2482 been changed to hardware breakpoint before we get here. If it is
2483 "off" however, error out before actually trying to insert the
2484 breakpoint, with a nicer error message. */
2485 if (bl
->loc_type
== bp_loc_software_breakpoint
2486 && !automatic_hardware_breakpoints
)
2488 mem_region
*mr
= lookup_mem_region (bl
->address
);
2490 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2492 fprintf_unfiltered (tmp_error_stream
,
2493 _("Cannot insert breakpoint %d.\n"
2494 "Cannot set software breakpoint "
2495 "at read-only address %s\n"),
2497 paddress (bl
->gdbarch
, bl
->address
));
2502 if (bl
->loc_type
== bp_loc_software_breakpoint
2503 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2505 /* First check to see if we have to handle an overlay. */
2506 if (overlay_debugging
== ovly_off
2507 || bl
->section
== NULL
2508 || !(section_is_overlay (bl
->section
)))
2510 /* No overlay handling: just set the breakpoint. */
2515 val
= bl
->owner
->ops
->insert_location (bl
);
2517 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2519 catch (gdb_exception
&e
)
2521 bp_excpt
= std::move (e
);
2526 /* This breakpoint is in an overlay section.
2527 Shall we set a breakpoint at the LMA? */
2528 if (!overlay_events_enabled
)
2530 /* Yes -- overlay event support is not active,
2531 so we must try to set a breakpoint at the LMA.
2532 This will not work for a hardware breakpoint. */
2533 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2534 warning (_("hardware breakpoint %d not supported in overlay!"),
2538 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2540 /* Set a software (trap) breakpoint at the LMA. */
2541 bl
->overlay_target_info
= bl
->target_info
;
2542 bl
->overlay_target_info
.reqstd_address
= addr
;
2544 /* No overlay handling: just set the breakpoint. */
2549 bl
->overlay_target_info
.kind
2550 = breakpoint_kind (bl
, &addr
);
2551 bl
->overlay_target_info
.placed_address
= addr
;
2552 val
= target_insert_breakpoint (bl
->gdbarch
,
2553 &bl
->overlay_target_info
);
2556 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2558 catch (gdb_exception
&e
)
2560 bp_excpt
= std::move (e
);
2563 if (bp_excpt
.reason
!= 0)
2564 fprintf_unfiltered (tmp_error_stream
,
2565 "Overlay breakpoint %d "
2566 "failed: in ROM?\n",
2570 /* Shall we set a breakpoint at the VMA? */
2571 if (section_is_mapped (bl
->section
))
2573 /* Yes. This overlay section is mapped into memory. */
2578 val
= bl
->owner
->ops
->insert_location (bl
);
2580 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2582 catch (gdb_exception
&e
)
2584 bp_excpt
= std::move (e
);
2589 /* No. This breakpoint will not be inserted.
2590 No error, but do not mark the bp as 'inserted'. */
2595 if (bp_excpt
.reason
!= 0)
2597 /* Can't set the breakpoint. */
2599 /* In some cases, we might not be able to insert a
2600 breakpoint in a shared library that has already been
2601 removed, but we have not yet processed the shlib unload
2602 event. Unfortunately, some targets that implement
2603 breakpoint insertion themselves can't tell why the
2604 breakpoint insertion failed (e.g., the remote target
2605 doesn't define error codes), so we must treat generic
2606 errors as memory errors. */
2607 if (bp_excpt
.reason
== RETURN_ERROR
2608 && (bp_excpt
.error
== GENERIC_ERROR
2609 || bp_excpt
.error
== MEMORY_ERROR
)
2610 && bl
->loc_type
== bp_loc_software_breakpoint
2611 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2612 || shared_objfile_contains_address_p (bl
->pspace
,
2615 /* See also: disable_breakpoints_in_shlibs. */
2616 bl
->shlib_disabled
= 1;
2617 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2618 if (!*disabled_breaks
)
2620 fprintf_unfiltered (tmp_error_stream
,
2621 "Cannot insert breakpoint %d.\n",
2623 fprintf_unfiltered (tmp_error_stream
,
2624 "Temporarily disabling shared "
2625 "library breakpoints:\n");
2627 *disabled_breaks
= 1;
2628 fprintf_unfiltered (tmp_error_stream
,
2629 "breakpoint #%d\n", bl
->owner
->number
);
2634 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2636 *hw_breakpoint_error
= 1;
2637 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2638 fprintf_unfiltered (tmp_error_stream
,
2639 "Cannot insert hardware breakpoint %d%s",
2641 bp_excpt
.message
? ":" : ".\n");
2642 if (bp_excpt
.message
!= NULL
)
2643 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2648 if (bp_excpt
.message
== NULL
)
2651 = memory_error_message (TARGET_XFER_E_IO
,
2652 bl
->gdbarch
, bl
->address
);
2654 fprintf_unfiltered (tmp_error_stream
,
2655 "Cannot insert breakpoint %d.\n"
2657 bl
->owner
->number
, message
.c_str ());
2661 fprintf_unfiltered (tmp_error_stream
,
2662 "Cannot insert breakpoint %d: %s\n",
2677 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2678 /* NOTE drow/2003-09-08: This state only exists for removing
2679 watchpoints. It's not clear that it's necessary... */
2680 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2684 gdb_assert (bl
->owner
->ops
!= NULL
2685 && bl
->owner
->ops
->insert_location
!= NULL
);
2687 val
= bl
->owner
->ops
->insert_location (bl
);
2689 /* If trying to set a read-watchpoint, and it turns out it's not
2690 supported, try emulating one with an access watchpoint. */
2691 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2693 struct bp_location
*loc
, **loc_temp
;
2695 /* But don't try to insert it, if there's already another
2696 hw_access location that would be considered a duplicate
2698 ALL_BP_LOCATIONS (loc
, loc_temp
)
2700 && loc
->watchpoint_type
== hw_access
2701 && watchpoint_locations_match (bl
, loc
))
2705 bl
->target_info
= loc
->target_info
;
2706 bl
->watchpoint_type
= hw_access
;
2713 bl
->watchpoint_type
= hw_access
;
2714 val
= bl
->owner
->ops
->insert_location (bl
);
2717 /* Back to the original value. */
2718 bl
->watchpoint_type
= hw_read
;
2722 bl
->inserted
= (val
== 0);
2725 else if (bl
->owner
->type
== bp_catchpoint
)
2729 gdb_assert (bl
->owner
->ops
!= NULL
2730 && bl
->owner
->ops
->insert_location
!= NULL
);
2732 val
= bl
->owner
->ops
->insert_location (bl
);
2735 bl
->owner
->enable_state
= bp_disabled
;
2739 Error inserting catchpoint %d: Your system does not support this type\n\
2740 of catchpoint."), bl
->owner
->number
);
2742 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2745 bl
->inserted
= (val
== 0);
2747 /* We've already printed an error message if there was a problem
2748 inserting this catchpoint, and we've disabled the catchpoint,
2749 so just return success. */
2756 /* This function is called when program space PSPACE is about to be
2757 deleted. It takes care of updating breakpoints to not reference
2761 breakpoint_program_space_exit (struct program_space
*pspace
)
2763 struct breakpoint
*b
, *b_temp
;
2764 struct bp_location
*loc
, **loc_temp
;
2766 /* Remove any breakpoint that was set through this program space. */
2767 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2769 if (b
->pspace
== pspace
)
2770 delete_breakpoint (b
);
2773 /* Breakpoints set through other program spaces could have locations
2774 bound to PSPACE as well. Remove those. */
2775 ALL_BP_LOCATIONS (loc
, loc_temp
)
2777 struct bp_location
*tmp
;
2779 if (loc
->pspace
== pspace
)
2781 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2782 if (loc
->owner
->loc
== loc
)
2783 loc
->owner
->loc
= loc
->next
;
2785 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2786 if (tmp
->next
== loc
)
2788 tmp
->next
= loc
->next
;
2794 /* Now update the global location list to permanently delete the
2795 removed locations above. */
2796 update_global_location_list (UGLL_DONT_INSERT
);
2799 /* Make sure all breakpoints are inserted in inferior.
2800 Throws exception on any error.
2801 A breakpoint that is already inserted won't be inserted
2802 again, so calling this function twice is safe. */
2804 insert_breakpoints (void)
2806 struct breakpoint
*bpt
;
2808 ALL_BREAKPOINTS (bpt
)
2809 if (is_hardware_watchpoint (bpt
))
2811 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2813 update_watchpoint (w
, 0 /* don't reparse. */);
2816 /* Updating watchpoints creates new locations, so update the global
2817 location list. Explicitly tell ugll to insert locations and
2818 ignore breakpoints_always_inserted_mode. Also,
2819 update_global_location_list tries to "upgrade" software
2820 breakpoints to hardware breakpoints to handle "set breakpoint
2821 auto-hw", so we need to call it even if we don't have new
2823 update_global_location_list (UGLL_INSERT
);
2826 /* Invoke CALLBACK for each of bp_location. */
2829 iterate_over_bp_locations (walk_bp_location_callback callback
)
2831 struct bp_location
*loc
, **loc_tmp
;
2833 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2835 callback (loc
, NULL
);
2839 /* This is used when we need to synch breakpoint conditions between GDB and the
2840 target. It is the case with deleting and disabling of breakpoints when using
2841 always-inserted mode. */
2844 update_inserted_breakpoint_locations (void)
2846 struct bp_location
*bl
, **blp_tmp
;
2849 int disabled_breaks
= 0;
2850 int hw_breakpoint_error
= 0;
2851 int hw_bp_details_reported
= 0;
2853 string_file tmp_error_stream
;
2855 /* Explicitly mark the warning -- this will only be printed if
2856 there was an error. */
2857 tmp_error_stream
.puts ("Warning:\n");
2859 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2861 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2863 /* We only want to update software breakpoints and hardware
2865 if (!is_breakpoint (bl
->owner
))
2868 /* We only want to update locations that are already inserted
2869 and need updating. This is to avoid unwanted insertion during
2870 deletion of breakpoints. */
2871 if (!bl
->inserted
|| !bl
->needs_update
)
2874 switch_to_program_space_and_thread (bl
->pspace
);
2876 /* For targets that support global breakpoints, there's no need
2877 to select an inferior to insert breakpoint to. In fact, even
2878 if we aren't attached to any process yet, we should still
2879 insert breakpoints. */
2880 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2881 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
2884 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2885 &hw_breakpoint_error
, &hw_bp_details_reported
);
2892 target_terminal::ours_for_output ();
2893 error_stream (tmp_error_stream
);
2897 /* Used when starting or continuing the program. */
2900 insert_breakpoint_locations (void)
2902 struct breakpoint
*bpt
;
2903 struct bp_location
*bl
, **blp_tmp
;
2906 int disabled_breaks
= 0;
2907 int hw_breakpoint_error
= 0;
2908 int hw_bp_error_explained_already
= 0;
2910 string_file tmp_error_stream
;
2912 /* Explicitly mark the warning -- this will only be printed if
2913 there was an error. */
2914 tmp_error_stream
.puts ("Warning:\n");
2916 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2918 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2920 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2923 /* There is no point inserting thread-specific breakpoints if
2924 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2925 has BL->OWNER always non-NULL. */
2926 if (bl
->owner
->thread
!= -1
2927 && !valid_global_thread_id (bl
->owner
->thread
))
2930 switch_to_program_space_and_thread (bl
->pspace
);
2932 /* For targets that support global breakpoints, there's no need
2933 to select an inferior to insert breakpoint to. In fact, even
2934 if we aren't attached to any process yet, we should still
2935 insert breakpoints. */
2936 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2937 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
2940 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2941 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
2946 /* If we failed to insert all locations of a watchpoint, remove
2947 them, as half-inserted watchpoint is of limited use. */
2948 ALL_BREAKPOINTS (bpt
)
2950 int some_failed
= 0;
2951 struct bp_location
*loc
;
2953 if (!is_hardware_watchpoint (bpt
))
2956 if (!breakpoint_enabled (bpt
))
2959 if (bpt
->disposition
== disp_del_at_next_stop
)
2962 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2963 if (!loc
->inserted
&& should_be_inserted (loc
))
2970 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2972 remove_breakpoint (loc
);
2974 hw_breakpoint_error
= 1;
2975 tmp_error_stream
.printf ("Could not insert "
2976 "hardware watchpoint %d.\n",
2984 /* If a hardware breakpoint or watchpoint was inserted, add a
2985 message about possibly exhausted resources. */
2986 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
2988 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
2989 You may have requested too many hardware breakpoints/watchpoints.\n");
2991 target_terminal::ours_for_output ();
2992 error_stream (tmp_error_stream
);
2996 /* Used when the program stops.
2997 Returns zero if successful, or non-zero if there was a problem
2998 removing a breakpoint location. */
3001 remove_breakpoints (void)
3003 struct bp_location
*bl
, **blp_tmp
;
3006 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3008 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3009 val
|= remove_breakpoint (bl
);
3014 /* When a thread exits, remove breakpoints that are related to
3018 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3020 struct breakpoint
*b
, *b_tmp
;
3022 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3024 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3026 b
->disposition
= disp_del_at_next_stop
;
3028 printf_filtered (_("\
3029 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3030 b
->number
, print_thread_id (tp
));
3032 /* Hide it from the user. */
3038 /* See breakpoint.h. */
3041 remove_breakpoints_inf (inferior
*inf
)
3043 struct bp_location
*bl
, **blp_tmp
;
3046 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3048 if (bl
->pspace
!= inf
->pspace
)
3051 if (bl
->inserted
&& !bl
->target_info
.persist
)
3053 val
= remove_breakpoint (bl
);
3060 static int internal_breakpoint_number
= -1;
3062 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3063 If INTERNAL is non-zero, the breakpoint number will be populated
3064 from internal_breakpoint_number and that variable decremented.
3065 Otherwise the breakpoint number will be populated from
3066 breakpoint_count and that value incremented. Internal breakpoints
3067 do not set the internal var bpnum. */
3069 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3072 b
->number
= internal_breakpoint_number
--;
3075 set_breakpoint_count (breakpoint_count
+ 1);
3076 b
->number
= breakpoint_count
;
3080 static struct breakpoint
*
3081 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3082 CORE_ADDR address
, enum bptype type
,
3083 const struct breakpoint_ops
*ops
)
3085 symtab_and_line sal
;
3087 sal
.section
= find_pc_overlay (sal
.pc
);
3088 sal
.pspace
= current_program_space
;
3090 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3091 b
->number
= internal_breakpoint_number
--;
3092 b
->disposition
= disp_donttouch
;
3097 static const char *const longjmp_names
[] =
3099 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3101 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3103 /* Per-objfile data private to breakpoint.c. */
3104 struct breakpoint_objfile_data
3106 /* Minimal symbol for "_ovly_debug_event" (if any). */
3107 struct bound_minimal_symbol overlay_msym
{};
3109 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3110 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3112 /* True if we have looked for longjmp probes. */
3113 int longjmp_searched
= 0;
3115 /* SystemTap probe points for longjmp (if any). These are non-owning
3117 std::vector
<probe
*> longjmp_probes
;
3119 /* Minimal symbol for "std::terminate()" (if any). */
3120 struct bound_minimal_symbol terminate_msym
{};
3122 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3123 struct bound_minimal_symbol exception_msym
{};
3125 /* True if we have looked for exception probes. */
3126 int exception_searched
= 0;
3128 /* SystemTap probe points for unwinding (if any). These are non-owning
3130 std::vector
<probe
*> exception_probes
;
3133 static const struct objfile_key
<breakpoint_objfile_data
>
3134 breakpoint_objfile_key
;
3136 /* Minimal symbol not found sentinel. */
3137 static struct minimal_symbol msym_not_found
;
3139 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3142 msym_not_found_p (const struct minimal_symbol
*msym
)
3144 return msym
== &msym_not_found
;
3147 /* Return per-objfile data needed by breakpoint.c.
3148 Allocate the data if necessary. */
3150 static struct breakpoint_objfile_data
*
3151 get_breakpoint_objfile_data (struct objfile
*objfile
)
3153 struct breakpoint_objfile_data
*bp_objfile_data
;
3155 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3156 if (bp_objfile_data
== NULL
)
3157 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3158 return bp_objfile_data
;
3162 create_overlay_event_breakpoint (void)
3164 const char *const func_name
= "_ovly_debug_event";
3166 for (objfile
*objfile
: current_program_space
->objfiles ())
3168 struct breakpoint
*b
;
3169 struct breakpoint_objfile_data
*bp_objfile_data
;
3171 struct explicit_location explicit_loc
;
3173 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3175 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3178 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3180 struct bound_minimal_symbol m
;
3182 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3183 if (m
.minsym
== NULL
)
3185 /* Avoid future lookups in this objfile. */
3186 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3189 bp_objfile_data
->overlay_msym
= m
;
3192 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3193 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3195 &internal_breakpoint_ops
);
3196 initialize_explicit_location (&explicit_loc
);
3197 explicit_loc
.function_name
= ASTRDUP (func_name
);
3198 b
->location
= new_explicit_location (&explicit_loc
);
3200 if (overlay_debugging
== ovly_auto
)
3202 b
->enable_state
= bp_enabled
;
3203 overlay_events_enabled
= 1;
3207 b
->enable_state
= bp_disabled
;
3208 overlay_events_enabled
= 0;
3214 create_longjmp_master_breakpoint (void)
3216 scoped_restore_current_program_space restore_pspace
;
3218 for (struct program_space
*pspace
: program_spaces
)
3220 set_current_program_space (pspace
);
3222 for (objfile
*objfile
: current_program_space
->objfiles ())
3225 struct gdbarch
*gdbarch
;
3226 struct breakpoint_objfile_data
*bp_objfile_data
;
3228 gdbarch
= objfile
->arch ();
3230 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3232 if (!bp_objfile_data
->longjmp_searched
)
3234 std::vector
<probe
*> ret
3235 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3239 /* We are only interested in checking one element. */
3242 if (!p
->can_evaluate_arguments ())
3244 /* We cannot use the probe interface here,
3245 because it does not know how to evaluate
3250 bp_objfile_data
->longjmp_probes
= ret
;
3251 bp_objfile_data
->longjmp_searched
= 1;
3254 if (!bp_objfile_data
->longjmp_probes
.empty ())
3256 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3258 struct breakpoint
*b
;
3260 b
= create_internal_breakpoint (gdbarch
,
3261 p
->get_relocated_address (objfile
),
3263 &internal_breakpoint_ops
);
3264 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3265 b
->enable_state
= bp_disabled
;
3271 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3274 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3276 struct breakpoint
*b
;
3277 const char *func_name
;
3279 struct explicit_location explicit_loc
;
3281 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3284 func_name
= longjmp_names
[i
];
3285 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3287 struct bound_minimal_symbol m
;
3289 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3290 if (m
.minsym
== NULL
)
3292 /* Prevent future lookups in this objfile. */
3293 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3296 bp_objfile_data
->longjmp_msym
[i
] = m
;
3299 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3300 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3301 &internal_breakpoint_ops
);
3302 initialize_explicit_location (&explicit_loc
);
3303 explicit_loc
.function_name
= ASTRDUP (func_name
);
3304 b
->location
= new_explicit_location (&explicit_loc
);
3305 b
->enable_state
= bp_disabled
;
3311 /* Create a master std::terminate breakpoint. */
3313 create_std_terminate_master_breakpoint (void)
3315 const char *const func_name
= "std::terminate()";
3317 scoped_restore_current_program_space restore_pspace
;
3319 for (struct program_space
*pspace
: program_spaces
)
3323 set_current_program_space (pspace
);
3325 for (objfile
*objfile
: current_program_space
->objfiles ())
3327 struct breakpoint
*b
;
3328 struct breakpoint_objfile_data
*bp_objfile_data
;
3329 struct explicit_location explicit_loc
;
3331 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3333 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3336 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3338 struct bound_minimal_symbol m
;
3340 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3341 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3342 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3344 /* Prevent future lookups in this objfile. */
3345 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3348 bp_objfile_data
->terminate_msym
= m
;
3351 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3352 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3353 bp_std_terminate_master
,
3354 &internal_breakpoint_ops
);
3355 initialize_explicit_location (&explicit_loc
);
3356 explicit_loc
.function_name
= ASTRDUP (func_name
);
3357 b
->location
= new_explicit_location (&explicit_loc
);
3358 b
->enable_state
= bp_disabled
;
3363 /* Install a master breakpoint on the unwinder's debug hook. */
3366 create_exception_master_breakpoint (void)
3368 const char *const func_name
= "_Unwind_DebugHook";
3370 for (objfile
*objfile
: current_program_space
->objfiles ())
3372 struct breakpoint
*b
;
3373 struct gdbarch
*gdbarch
;
3374 struct breakpoint_objfile_data
*bp_objfile_data
;
3376 struct explicit_location explicit_loc
;
3378 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3380 /* We prefer the SystemTap probe point if it exists. */
3381 if (!bp_objfile_data
->exception_searched
)
3383 std::vector
<probe
*> ret
3384 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3388 /* We are only interested in checking one element. */
3391 if (!p
->can_evaluate_arguments ())
3393 /* We cannot use the probe interface here, because it does
3394 not know how to evaluate arguments. */
3398 bp_objfile_data
->exception_probes
= ret
;
3399 bp_objfile_data
->exception_searched
= 1;
3402 if (!bp_objfile_data
->exception_probes
.empty ())
3404 gdbarch
= objfile
->arch ();
3406 for (probe
*p
: bp_objfile_data
->exception_probes
)
3408 b
= create_internal_breakpoint (gdbarch
,
3409 p
->get_relocated_address (objfile
),
3410 bp_exception_master
,
3411 &internal_breakpoint_ops
);
3412 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3413 b
->enable_state
= bp_disabled
;
3419 /* Otherwise, try the hook function. */
3421 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3424 gdbarch
= objfile
->arch ();
3426 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3428 struct bound_minimal_symbol debug_hook
;
3430 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3431 if (debug_hook
.minsym
== NULL
)
3433 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3437 bp_objfile_data
->exception_msym
= debug_hook
;
3440 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3441 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3442 current_top_target ());
3443 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3444 &internal_breakpoint_ops
);
3445 initialize_explicit_location (&explicit_loc
);
3446 explicit_loc
.function_name
= ASTRDUP (func_name
);
3447 b
->location
= new_explicit_location (&explicit_loc
);
3448 b
->enable_state
= bp_disabled
;
3452 /* Does B have a location spec? */
3455 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3457 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3461 update_breakpoints_after_exec (void)
3463 struct breakpoint
*b
, *b_tmp
;
3464 struct bp_location
*bploc
, **bplocp_tmp
;
3466 /* We're about to delete breakpoints from GDB's lists. If the
3467 INSERTED flag is true, GDB will try to lift the breakpoints by
3468 writing the breakpoints' "shadow contents" back into memory. The
3469 "shadow contents" are NOT valid after an exec, so GDB should not
3470 do that. Instead, the target is responsible from marking
3471 breakpoints out as soon as it detects an exec. We don't do that
3472 here instead, because there may be other attempts to delete
3473 breakpoints after detecting an exec and before reaching here. */
3474 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3475 if (bploc
->pspace
== current_program_space
)
3476 gdb_assert (!bploc
->inserted
);
3478 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3480 if (b
->pspace
!= current_program_space
)
3483 /* Solib breakpoints must be explicitly reset after an exec(). */
3484 if (b
->type
== bp_shlib_event
)
3486 delete_breakpoint (b
);
3490 /* JIT breakpoints must be explicitly reset after an exec(). */
3491 if (b
->type
== bp_jit_event
)
3493 delete_breakpoint (b
);
3497 /* Thread event breakpoints must be set anew after an exec(),
3498 as must overlay event and longjmp master breakpoints. */
3499 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3500 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3501 || b
->type
== bp_exception_master
)
3503 delete_breakpoint (b
);
3507 /* Step-resume breakpoints are meaningless after an exec(). */
3508 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3510 delete_breakpoint (b
);
3514 /* Just like single-step breakpoints. */
3515 if (b
->type
== bp_single_step
)
3517 delete_breakpoint (b
);
3521 /* Longjmp and longjmp-resume breakpoints are also meaningless
3523 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3524 || b
->type
== bp_longjmp_call_dummy
3525 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3527 delete_breakpoint (b
);
3531 if (b
->type
== bp_catchpoint
)
3533 /* For now, none of the bp_catchpoint breakpoints need to
3534 do anything at this point. In the future, if some of
3535 the catchpoints need to something, we will need to add
3536 a new method, and call this method from here. */
3540 /* bp_finish is a special case. The only way we ought to be able
3541 to see one of these when an exec() has happened, is if the user
3542 caught a vfork, and then said "finish". Ordinarily a finish just
3543 carries them to the call-site of the current callee, by setting
3544 a temporary bp there and resuming. But in this case, the finish
3545 will carry them entirely through the vfork & exec.
3547 We don't want to allow a bp_finish to remain inserted now. But
3548 we can't safely delete it, 'cause finish_command has a handle to
3549 the bp on a bpstat, and will later want to delete it. There's a
3550 chance (and I've seen it happen) that if we delete the bp_finish
3551 here, that its storage will get reused by the time finish_command
3552 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3553 We really must allow finish_command to delete a bp_finish.
3555 In the absence of a general solution for the "how do we know
3556 it's safe to delete something others may have handles to?"
3557 problem, what we'll do here is just uninsert the bp_finish, and
3558 let finish_command delete it.
3560 (We know the bp_finish is "doomed" in the sense that it's
3561 momentary, and will be deleted as soon as finish_command sees
3562 the inferior stopped. So it doesn't matter that the bp's
3563 address is probably bogus in the new a.out, unlike e.g., the
3564 solib breakpoints.) */
3566 if (b
->type
== bp_finish
)
3571 /* Without a symbolic address, we have little hope of the
3572 pre-exec() address meaning the same thing in the post-exec()
3574 if (breakpoint_event_location_empty_p (b
))
3576 delete_breakpoint (b
);
3583 detach_breakpoints (ptid_t ptid
)
3585 struct bp_location
*bl
, **blp_tmp
;
3587 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3588 struct inferior
*inf
= current_inferior ();
3590 if (ptid
.pid () == inferior_ptid
.pid ())
3591 error (_("Cannot detach breakpoints of inferior_ptid"));
3593 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3594 inferior_ptid
= ptid
;
3595 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3597 if (bl
->pspace
!= inf
->pspace
)
3600 /* This function must physically remove breakpoints locations
3601 from the specified ptid, without modifying the breakpoint
3602 package's state. Locations of type bp_loc_other are only
3603 maintained at GDB side. So, there is no need to remove
3604 these bp_loc_other locations. Moreover, removing these
3605 would modify the breakpoint package's state. */
3606 if (bl
->loc_type
== bp_loc_other
)
3610 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3616 /* Remove the breakpoint location BL from the current address space.
3617 Note that this is used to detach breakpoints from a child fork.
3618 When we get here, the child isn't in the inferior list, and neither
3619 do we have objects to represent its address space --- we should
3620 *not* look at bl->pspace->aspace here. */
3623 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3627 /* BL is never in moribund_locations by our callers. */
3628 gdb_assert (bl
->owner
!= NULL
);
3630 /* The type of none suggests that owner is actually deleted.
3631 This should not ever happen. */
3632 gdb_assert (bl
->owner
->type
!= bp_none
);
3634 if (bl
->loc_type
== bp_loc_software_breakpoint
3635 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3637 /* "Normal" instruction breakpoint: either the standard
3638 trap-instruction bp (bp_breakpoint), or a
3639 bp_hardware_breakpoint. */
3641 /* First check to see if we have to handle an overlay. */
3642 if (overlay_debugging
== ovly_off
3643 || bl
->section
== NULL
3644 || !(section_is_overlay (bl
->section
)))
3646 /* No overlay handling: just remove the breakpoint. */
3648 /* If we're trying to uninsert a memory breakpoint that we
3649 know is set in a dynamic object that is marked
3650 shlib_disabled, then either the dynamic object was
3651 removed with "remove-symbol-file" or with
3652 "nosharedlibrary". In the former case, we don't know
3653 whether another dynamic object might have loaded over the
3654 breakpoint's address -- the user might well let us know
3655 about it next with add-symbol-file (the whole point of
3656 add-symbol-file is letting the user manually maintain a
3657 list of dynamically loaded objects). If we have the
3658 breakpoint's shadow memory, that is, this is a software
3659 breakpoint managed by GDB, check whether the breakpoint
3660 is still inserted in memory, to avoid overwriting wrong
3661 code with stale saved shadow contents. Note that HW
3662 breakpoints don't have shadow memory, as they're
3663 implemented using a mechanism that is not dependent on
3664 being able to modify the target's memory, and as such
3665 they should always be removed. */
3666 if (bl
->shlib_disabled
3667 && bl
->target_info
.shadow_len
!= 0
3668 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3671 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3675 /* This breakpoint is in an overlay section.
3676 Did we set a breakpoint at the LMA? */
3677 if (!overlay_events_enabled
)
3679 /* Yes -- overlay event support is not active, so we
3680 should have set a breakpoint at the LMA. Remove it.
3682 /* Ignore any failures: if the LMA is in ROM, we will
3683 have already warned when we failed to insert it. */
3684 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3685 target_remove_hw_breakpoint (bl
->gdbarch
,
3686 &bl
->overlay_target_info
);
3688 target_remove_breakpoint (bl
->gdbarch
,
3689 &bl
->overlay_target_info
,
3692 /* Did we set a breakpoint at the VMA?
3693 If so, we will have marked the breakpoint 'inserted'. */
3696 /* Yes -- remove it. Previously we did not bother to
3697 remove the breakpoint if the section had been
3698 unmapped, but let's not rely on that being safe. We
3699 don't know what the overlay manager might do. */
3701 /* However, we should remove *software* breakpoints only
3702 if the section is still mapped, or else we overwrite
3703 wrong code with the saved shadow contents. */
3704 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3705 || section_is_mapped (bl
->section
))
3706 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3712 /* No -- not inserted, so no need to remove. No error. */
3717 /* In some cases, we might not be able to remove a breakpoint in
3718 a shared library that has already been removed, but we have
3719 not yet processed the shlib unload event. Similarly for an
3720 unloaded add-symbol-file object - the user might not yet have
3721 had the chance to remove-symbol-file it. shlib_disabled will
3722 be set if the library/object has already been removed, but
3723 the breakpoint hasn't been uninserted yet, e.g., after
3724 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3725 always-inserted mode. */
3727 && (bl
->loc_type
== bp_loc_software_breakpoint
3728 && (bl
->shlib_disabled
3729 || solib_name_from_address (bl
->pspace
, bl
->address
)
3730 || shared_objfile_contains_address_p (bl
->pspace
,
3736 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3738 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3740 gdb_assert (bl
->owner
->ops
!= NULL
3741 && bl
->owner
->ops
->remove_location
!= NULL
);
3743 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3744 bl
->owner
->ops
->remove_location (bl
, reason
);
3746 /* Failure to remove any of the hardware watchpoints comes here. */
3747 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3748 warning (_("Could not remove hardware watchpoint %d."),
3751 else if (bl
->owner
->type
== bp_catchpoint
3752 && breakpoint_enabled (bl
->owner
)
3755 gdb_assert (bl
->owner
->ops
!= NULL
3756 && bl
->owner
->ops
->remove_location
!= NULL
);
3758 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3762 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3769 remove_breakpoint (struct bp_location
*bl
)
3771 /* BL is never in moribund_locations by our callers. */
3772 gdb_assert (bl
->owner
!= NULL
);
3774 /* The type of none suggests that owner is actually deleted.
3775 This should not ever happen. */
3776 gdb_assert (bl
->owner
->type
!= bp_none
);
3778 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3780 switch_to_program_space_and_thread (bl
->pspace
);
3782 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3785 /* Clear the "inserted" flag in all breakpoints. */
3788 mark_breakpoints_out (void)
3790 struct bp_location
*bl
, **blp_tmp
;
3792 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3793 if (bl
->pspace
== current_program_space
)
3797 /* Clear the "inserted" flag in all breakpoints and delete any
3798 breakpoints which should go away between runs of the program.
3800 Plus other such housekeeping that has to be done for breakpoints
3803 Note: this function gets called at the end of a run (by
3804 generic_mourn_inferior) and when a run begins (by
3805 init_wait_for_inferior). */
3810 breakpoint_init_inferior (enum inf_context context
)
3812 struct breakpoint
*b
, *b_tmp
;
3813 struct program_space
*pspace
= current_program_space
;
3815 /* If breakpoint locations are shared across processes, then there's
3817 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3820 mark_breakpoints_out ();
3822 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3824 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3830 case bp_longjmp_call_dummy
:
3832 /* If the call dummy breakpoint is at the entry point it will
3833 cause problems when the inferior is rerun, so we better get
3836 case bp_watchpoint_scope
:
3838 /* Also get rid of scope breakpoints. */
3840 case bp_shlib_event
:
3842 /* Also remove solib event breakpoints. Their addresses may
3843 have changed since the last time we ran the program.
3844 Actually we may now be debugging against different target;
3845 and so the solib backend that installed this breakpoint may
3846 not be used in by the target. E.g.,
3848 (gdb) file prog-linux
3849 (gdb) run # native linux target
3852 (gdb) file prog-win.exe
3853 (gdb) tar rem :9999 # remote Windows gdbserver.
3856 case bp_step_resume
:
3858 /* Also remove step-resume breakpoints. */
3860 case bp_single_step
:
3862 /* Also remove single-step breakpoints. */
3864 delete_breakpoint (b
);
3868 case bp_hardware_watchpoint
:
3869 case bp_read_watchpoint
:
3870 case bp_access_watchpoint
:
3872 struct watchpoint
*w
= (struct watchpoint
*) b
;
3874 /* Likewise for watchpoints on local expressions. */
3875 if (w
->exp_valid_block
!= NULL
)
3876 delete_breakpoint (b
);
3879 /* Get rid of existing locations, which are no longer
3880 valid. New ones will be created in
3881 update_watchpoint, when the inferior is restarted.
3882 The next update_global_location_list call will
3883 garbage collect them. */
3886 if (context
== inf_starting
)
3888 /* Reset val field to force reread of starting value in
3889 insert_breakpoints. */
3890 w
->val
.reset (nullptr);
3891 w
->val_valid
= false;
3901 /* Get rid of the moribund locations. */
3902 for (bp_location
*bl
: moribund_locations
)
3903 decref_bp_location (&bl
);
3904 moribund_locations
.clear ();
3907 /* These functions concern about actual breakpoints inserted in the
3908 target --- to e.g. check if we need to do decr_pc adjustment or if
3909 we need to hop over the bkpt --- so we check for address space
3910 match, not program space. */
3912 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3913 exists at PC. It returns ordinary_breakpoint_here if it's an
3914 ordinary breakpoint, or permanent_breakpoint_here if it's a
3915 permanent breakpoint.
3916 - When continuing from a location with an ordinary breakpoint, we
3917 actually single step once before calling insert_breakpoints.
3918 - When continuing from a location with a permanent breakpoint, we
3919 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3920 the target, to advance the PC past the breakpoint. */
3922 enum breakpoint_here
3923 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
3925 struct bp_location
*bl
, **blp_tmp
;
3926 int any_breakpoint_here
= 0;
3928 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3930 if (bl
->loc_type
!= bp_loc_software_breakpoint
3931 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3934 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3935 if ((breakpoint_enabled (bl
->owner
)
3937 && breakpoint_location_address_match (bl
, aspace
, pc
))
3939 if (overlay_debugging
3940 && section_is_overlay (bl
->section
)
3941 && !section_is_mapped (bl
->section
))
3942 continue; /* unmapped overlay -- can't be a match */
3943 else if (bl
->permanent
)
3944 return permanent_breakpoint_here
;
3946 any_breakpoint_here
= 1;
3950 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
3953 /* See breakpoint.h. */
3956 breakpoint_in_range_p (const address_space
*aspace
,
3957 CORE_ADDR addr
, ULONGEST len
)
3959 struct bp_location
*bl
, **blp_tmp
;
3961 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3963 if (bl
->loc_type
!= bp_loc_software_breakpoint
3964 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3967 if ((breakpoint_enabled (bl
->owner
)
3969 && breakpoint_location_address_range_overlap (bl
, aspace
,
3972 if (overlay_debugging
3973 && section_is_overlay (bl
->section
)
3974 && !section_is_mapped (bl
->section
))
3976 /* Unmapped overlay -- can't be a match. */
3987 /* Return true if there's a moribund breakpoint at PC. */
3990 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
3992 for (bp_location
*loc
: moribund_locations
)
3993 if (breakpoint_location_address_match (loc
, aspace
, pc
))
3999 /* Returns non-zero iff BL is inserted at PC, in address space
4003 bp_location_inserted_here_p (struct bp_location
*bl
,
4004 const address_space
*aspace
, CORE_ADDR pc
)
4007 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4010 if (overlay_debugging
4011 && section_is_overlay (bl
->section
)
4012 && !section_is_mapped (bl
->section
))
4013 return 0; /* unmapped overlay -- can't be a match */
4020 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4023 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4025 struct bp_location
**blp
, **blp_tmp
= NULL
;
4027 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4029 struct bp_location
*bl
= *blp
;
4031 if (bl
->loc_type
!= bp_loc_software_breakpoint
4032 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4035 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4041 /* This function returns non-zero iff there is a software breakpoint
4045 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4048 struct bp_location
**blp
, **blp_tmp
= NULL
;
4050 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4052 struct bp_location
*bl
= *blp
;
4054 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4057 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4064 /* See breakpoint.h. */
4067 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4070 struct bp_location
**blp
, **blp_tmp
= NULL
;
4072 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4074 struct bp_location
*bl
= *blp
;
4076 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4079 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4087 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4088 CORE_ADDR addr
, ULONGEST len
)
4090 struct breakpoint
*bpt
;
4092 ALL_BREAKPOINTS (bpt
)
4094 struct bp_location
*loc
;
4096 if (bpt
->type
!= bp_hardware_watchpoint
4097 && bpt
->type
!= bp_access_watchpoint
)
4100 if (!breakpoint_enabled (bpt
))
4103 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4104 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4108 /* Check for intersection. */
4109 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4110 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4118 /* See breakpoint.h. */
4121 is_catchpoint (struct breakpoint
*b
)
4123 return (b
->type
== bp_catchpoint
);
4126 /* Frees any storage that is part of a bpstat. Does not walk the
4129 bpstats::~bpstats ()
4131 if (bp_location_at
!= NULL
)
4132 decref_bp_location (&bp_location_at
);
4135 /* Clear a bpstat so that it says we are not at any breakpoint.
4136 Also free any storage that is part of a bpstat. */
4139 bpstat_clear (bpstat
*bsp
)
4156 bpstats::bpstats (const bpstats
&other
)
4158 bp_location_at (other
.bp_location_at
),
4159 breakpoint_at (other
.breakpoint_at
),
4160 commands (other
.commands
),
4161 print (other
.print
),
4163 print_it (other
.print_it
)
4165 if (other
.old_val
!= NULL
)
4166 old_val
= release_value (value_copy (other
.old_val
.get ()));
4167 incref_bp_location (bp_location_at
);
4170 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4171 is part of the bpstat is copied as well. */
4174 bpstat_copy (bpstat bs
)
4178 bpstat retval
= NULL
;
4183 for (; bs
!= NULL
; bs
= bs
->next
)
4185 tmp
= new bpstats (*bs
);
4188 /* This is the first thing in the chain. */
4198 /* Find the bpstat associated with this breakpoint. */
4201 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4206 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4208 if (bsp
->breakpoint_at
== breakpoint
)
4214 /* See breakpoint.h. */
4217 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4219 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4221 if (bsp
->breakpoint_at
== NULL
)
4223 /* A moribund location can never explain a signal other than
4225 if (sig
== GDB_SIGNAL_TRAP
)
4230 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4239 /* Put in *NUM the breakpoint number of the first breakpoint we are
4240 stopped at. *BSP upon return is a bpstat which points to the
4241 remaining breakpoints stopped at (but which is not guaranteed to be
4242 good for anything but further calls to bpstat_num).
4244 Return 0 if passed a bpstat which does not indicate any breakpoints.
4245 Return -1 if stopped at a breakpoint that has been deleted since
4247 Return 1 otherwise. */
4250 bpstat_num (bpstat
*bsp
, int *num
)
4252 struct breakpoint
*b
;
4255 return 0; /* No more breakpoint values */
4257 /* We assume we'll never have several bpstats that correspond to a
4258 single breakpoint -- otherwise, this function might return the
4259 same number more than once and this will look ugly. */
4260 b
= (*bsp
)->breakpoint_at
;
4261 *bsp
= (*bsp
)->next
;
4263 return -1; /* breakpoint that's been deleted since */
4265 *num
= b
->number
; /* We have its number */
4269 /* See breakpoint.h. */
4272 bpstat_clear_actions (void)
4276 if (inferior_ptid
== null_ptid
)
4279 thread_info
*tp
= inferior_thread ();
4280 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4282 bs
->commands
= NULL
;
4283 bs
->old_val
.reset (nullptr);
4287 /* Called when a command is about to proceed the inferior. */
4290 breakpoint_about_to_proceed (void)
4292 if (inferior_ptid
!= null_ptid
)
4294 struct thread_info
*tp
= inferior_thread ();
4296 /* Allow inferior function calls in breakpoint commands to not
4297 interrupt the command list. When the call finishes
4298 successfully, the inferior will be standing at the same
4299 breakpoint as if nothing happened. */
4300 if (tp
->control
.in_infcall
)
4304 breakpoint_proceeded
= 1;
4307 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4308 or its equivalent. */
4311 command_line_is_silent (struct command_line
*cmd
)
4313 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4316 /* Execute all the commands associated with all the breakpoints at
4317 this location. Any of these commands could cause the process to
4318 proceed beyond this point, etc. We look out for such changes by
4319 checking the global "breakpoint_proceeded" after each command.
4321 Returns true if a breakpoint command resumed the inferior. In that
4322 case, it is the caller's responsibility to recall it again with the
4323 bpstat of the current thread. */
4326 bpstat_do_actions_1 (bpstat
*bsp
)
4331 /* Avoid endless recursion if a `source' command is contained
4333 if (executing_breakpoint_commands
)
4336 scoped_restore save_executing
4337 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4339 scoped_restore preventer
= prevent_dont_repeat ();
4341 /* This pointer will iterate over the list of bpstat's. */
4344 breakpoint_proceeded
= 0;
4345 for (; bs
!= NULL
; bs
= bs
->next
)
4347 struct command_line
*cmd
= NULL
;
4349 /* Take ownership of the BSP's command tree, if it has one.
4351 The command tree could legitimately contain commands like
4352 'step' and 'next', which call clear_proceed_status, which
4353 frees stop_bpstat's command tree. To make sure this doesn't
4354 free the tree we're executing out from under us, we need to
4355 take ownership of the tree ourselves. Since a given bpstat's
4356 commands are only executed once, we don't need to copy it; we
4357 can clear the pointer in the bpstat, and make sure we free
4358 the tree when we're done. */
4359 counted_command_line ccmd
= bs
->commands
;
4360 bs
->commands
= NULL
;
4363 if (command_line_is_silent (cmd
))
4365 /* The action has been already done by bpstat_stop_status. */
4371 execute_control_command (cmd
);
4373 if (breakpoint_proceeded
)
4379 if (breakpoint_proceeded
)
4381 if (current_ui
->async
)
4382 /* If we are in async mode, then the target might be still
4383 running, not stopped at any breakpoint, so nothing for
4384 us to do here -- just return to the event loop. */
4387 /* In sync mode, when execute_control_command returns
4388 we're already standing on the next breakpoint.
4389 Breakpoint commands for that stop were not run, since
4390 execute_command does not run breakpoint commands --
4391 only command_line_handler does, but that one is not
4392 involved in execution of breakpoint commands. So, we
4393 can now execute breakpoint commands. It should be
4394 noted that making execute_command do bpstat actions is
4395 not an option -- in this case we'll have recursive
4396 invocation of bpstat for each breakpoint with a
4397 command, and can easily blow up GDB stack. Instead, we
4398 return true, which will trigger the caller to recall us
4399 with the new stop_bpstat. */
4407 /* Helper for bpstat_do_actions. Get the current thread, if there's
4408 one, is alive and has execution. Return NULL otherwise. */
4410 static thread_info
*
4411 get_bpstat_thread ()
4413 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4416 thread_info
*tp
= inferior_thread ();
4417 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4423 bpstat_do_actions (void)
4425 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4428 /* Do any commands attached to breakpoint we are stopped at. */
4429 while ((tp
= get_bpstat_thread ()) != NULL
)
4431 /* Since in sync mode, bpstat_do_actions may resume the
4432 inferior, and only return when it is stopped at the next
4433 breakpoint, we keep doing breakpoint actions until it returns
4434 false to indicate the inferior was not resumed. */
4435 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4439 cleanup_if_error
.release ();
4442 /* Print out the (old or new) value associated with a watchpoint. */
4445 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4448 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4451 struct value_print_options opts
;
4452 get_user_print_options (&opts
);
4453 value_print (val
, stream
, &opts
);
4457 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4458 debugging multiple threads. */
4461 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4463 if (uiout
->is_mi_like_p ())
4468 if (show_thread_that_caused_stop ())
4471 struct thread_info
*thr
= inferior_thread ();
4473 uiout
->text ("Thread ");
4474 uiout
->field_string ("thread-id", print_thread_id (thr
));
4476 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4479 uiout
->text (" \"");
4480 uiout
->field_string ("name", name
);
4484 uiout
->text (" hit ");
4488 /* Generic routine for printing messages indicating why we
4489 stopped. The behavior of this function depends on the value
4490 'print_it' in the bpstat structure. Under some circumstances we
4491 may decide not to print anything here and delegate the task to
4494 static enum print_stop_action
4495 print_bp_stop_message (bpstat bs
)
4497 switch (bs
->print_it
)
4500 /* Nothing should be printed for this bpstat entry. */
4501 return PRINT_UNKNOWN
;
4505 /* We still want to print the frame, but we already printed the
4506 relevant messages. */
4507 return PRINT_SRC_AND_LOC
;
4510 case print_it_normal
:
4512 struct breakpoint
*b
= bs
->breakpoint_at
;
4514 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4515 which has since been deleted. */
4517 return PRINT_UNKNOWN
;
4519 /* Normal case. Call the breakpoint's print_it method. */
4520 return b
->ops
->print_it (bs
);
4525 internal_error (__FILE__
, __LINE__
,
4526 _("print_bp_stop_message: unrecognized enum value"));
4531 /* A helper function that prints a shared library stopped event. */
4534 print_solib_event (int is_catchpoint
)
4536 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4537 bool any_added
= !current_program_space
->added_solibs
.empty ();
4541 if (any_added
|| any_deleted
)
4542 current_uiout
->text (_("Stopped due to shared library event:\n"));
4544 current_uiout
->text (_("Stopped due to shared library event (no "
4545 "libraries added or removed)\n"));
4548 if (current_uiout
->is_mi_like_p ())
4549 current_uiout
->field_string ("reason",
4550 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4554 current_uiout
->text (_(" Inferior unloaded "));
4555 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4556 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4558 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4561 current_uiout
->text (" ");
4562 current_uiout
->field_string ("library", name
);
4563 current_uiout
->text ("\n");
4569 current_uiout
->text (_(" Inferior loaded "));
4570 ui_out_emit_list
list_emitter (current_uiout
, "added");
4572 for (so_list
*iter
: current_program_space
->added_solibs
)
4575 current_uiout
->text (" ");
4577 current_uiout
->field_string ("library", iter
->so_name
);
4578 current_uiout
->text ("\n");
4583 /* Print a message indicating what happened. This is called from
4584 normal_stop(). The input to this routine is the head of the bpstat
4585 list - a list of the eventpoints that caused this stop. KIND is
4586 the target_waitkind for the stopping event. This
4587 routine calls the generic print routine for printing a message
4588 about reasons for stopping. This will print (for example) the
4589 "Breakpoint n," part of the output. The return value of this
4592 PRINT_UNKNOWN: Means we printed nothing.
4593 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4594 code to print the location. An example is
4595 "Breakpoint 1, " which should be followed by
4597 PRINT_SRC_ONLY: Means we printed something, but there is no need
4598 to also print the location part of the message.
4599 An example is the catch/throw messages, which
4600 don't require a location appended to the end.
4601 PRINT_NOTHING: We have done some printing and we don't need any
4602 further info to be printed. */
4604 enum print_stop_action
4605 bpstat_print (bpstat bs
, int kind
)
4607 enum print_stop_action val
;
4609 /* Maybe another breakpoint in the chain caused us to stop.
4610 (Currently all watchpoints go on the bpstat whether hit or not.
4611 That probably could (should) be changed, provided care is taken
4612 with respect to bpstat_explains_signal). */
4613 for (; bs
; bs
= bs
->next
)
4615 val
= print_bp_stop_message (bs
);
4616 if (val
== PRINT_SRC_ONLY
4617 || val
== PRINT_SRC_AND_LOC
4618 || val
== PRINT_NOTHING
)
4622 /* If we had hit a shared library event breakpoint,
4623 print_bp_stop_message would print out this message. If we hit an
4624 OS-level shared library event, do the same thing. */
4625 if (kind
== TARGET_WAITKIND_LOADED
)
4627 print_solib_event (0);
4628 return PRINT_NOTHING
;
4631 /* We reached the end of the chain, or we got a null BS to start
4632 with and nothing was printed. */
4633 return PRINT_UNKNOWN
;
4636 /* Evaluate the boolean expression EXP and return the result. */
4639 breakpoint_cond_eval (expression
*exp
)
4641 struct value
*mark
= value_mark ();
4642 bool res
= value_true (evaluate_expression (exp
));
4644 value_free_to_mark (mark
);
4648 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4650 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4652 bp_location_at (bl
),
4653 breakpoint_at (bl
->owner
),
4657 print_it (print_it_normal
)
4659 incref_bp_location (bl
);
4660 **bs_link_pointer
= this;
4661 *bs_link_pointer
= &next
;
4666 bp_location_at (NULL
),
4667 breakpoint_at (NULL
),
4671 print_it (print_it_normal
)
4675 /* The target has stopped with waitstatus WS. Check if any hardware
4676 watchpoints have triggered, according to the target. */
4679 watchpoints_triggered (struct target_waitstatus
*ws
)
4681 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4683 struct breakpoint
*b
;
4685 if (!stopped_by_watchpoint
)
4687 /* We were not stopped by a watchpoint. Mark all watchpoints
4688 as not triggered. */
4690 if (is_hardware_watchpoint (b
))
4692 struct watchpoint
*w
= (struct watchpoint
*) b
;
4694 w
->watchpoint_triggered
= watch_triggered_no
;
4700 if (!target_stopped_data_address (current_top_target (), &addr
))
4702 /* We were stopped by a watchpoint, but we don't know where.
4703 Mark all watchpoints as unknown. */
4705 if (is_hardware_watchpoint (b
))
4707 struct watchpoint
*w
= (struct watchpoint
*) b
;
4709 w
->watchpoint_triggered
= watch_triggered_unknown
;
4715 /* The target could report the data address. Mark watchpoints
4716 affected by this data address as triggered, and all others as not
4720 if (is_hardware_watchpoint (b
))
4722 struct watchpoint
*w
= (struct watchpoint
*) b
;
4723 struct bp_location
*loc
;
4725 w
->watchpoint_triggered
= watch_triggered_no
;
4726 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4728 if (is_masked_watchpoint (b
))
4730 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4731 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4733 if (newaddr
== start
)
4735 w
->watchpoint_triggered
= watch_triggered_yes
;
4739 /* Exact match not required. Within range is sufficient. */
4740 else if (target_watchpoint_addr_within_range (current_top_target (),
4744 w
->watchpoint_triggered
= watch_triggered_yes
;
4753 /* Possible return values for watchpoint_check. */
4754 enum wp_check_result
4756 /* The watchpoint has been deleted. */
4759 /* The value has changed. */
4760 WP_VALUE_CHANGED
= 2,
4762 /* The value has not changed. */
4763 WP_VALUE_NOT_CHANGED
= 3,
4765 /* Ignore this watchpoint, no matter if the value changed or not. */
4769 #define BP_TEMPFLAG 1
4770 #define BP_HARDWAREFLAG 2
4772 /* Evaluate watchpoint condition expression and check if its value
4775 static wp_check_result
4776 watchpoint_check (bpstat bs
)
4778 struct watchpoint
*b
;
4779 struct frame_info
*fr
;
4780 int within_current_scope
;
4782 /* BS is built from an existing struct breakpoint. */
4783 gdb_assert (bs
->breakpoint_at
!= NULL
);
4784 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4786 /* If this is a local watchpoint, we only want to check if the
4787 watchpoint frame is in scope if the current thread is the thread
4788 that was used to create the watchpoint. */
4789 if (!watchpoint_in_thread_scope (b
))
4792 if (b
->exp_valid_block
== NULL
)
4793 within_current_scope
= 1;
4796 struct frame_info
*frame
= get_current_frame ();
4797 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4798 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4800 /* stack_frame_destroyed_p() returns a non-zero value if we're
4801 still in the function but the stack frame has already been
4802 invalidated. Since we can't rely on the values of local
4803 variables after the stack has been destroyed, we are treating
4804 the watchpoint in that state as `not changed' without further
4805 checking. Don't mark watchpoints as changed if the current
4806 frame is in an epilogue - even if they are in some other
4807 frame, our view of the stack is likely to be wrong and
4808 frame_find_by_id could error out. */
4809 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4812 fr
= frame_find_by_id (b
->watchpoint_frame
);
4813 within_current_scope
= (fr
!= NULL
);
4815 /* If we've gotten confused in the unwinder, we might have
4816 returned a frame that can't describe this variable. */
4817 if (within_current_scope
)
4819 struct symbol
*function
;
4821 function
= get_frame_function (fr
);
4822 if (function
== NULL
4823 || !contained_in (b
->exp_valid_block
,
4824 SYMBOL_BLOCK_VALUE (function
)))
4825 within_current_scope
= 0;
4828 if (within_current_scope
)
4829 /* If we end up stopping, the current frame will get selected
4830 in normal_stop. So this call to select_frame won't affect
4835 if (within_current_scope
)
4837 /* We use value_{,free_to_}mark because it could be a *long*
4838 time before we return to the command level and call
4839 free_all_values. We can't call free_all_values because we
4840 might be in the middle of evaluating a function call. */
4844 struct value
*new_val
;
4846 if (is_masked_watchpoint (b
))
4847 /* Since we don't know the exact trigger address (from
4848 stopped_data_address), just tell the user we've triggered
4849 a mask watchpoint. */
4850 return WP_VALUE_CHANGED
;
4852 mark
= value_mark ();
4853 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
4855 if (b
->val_bitsize
!= 0)
4856 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4858 /* We use value_equal_contents instead of value_equal because
4859 the latter coerces an array to a pointer, thus comparing just
4860 the address of the array instead of its contents. This is
4861 not what we want. */
4862 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4863 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
4866 bs
->old_val
= b
->val
;
4867 b
->val
= release_value (new_val
);
4868 b
->val_valid
= true;
4869 if (new_val
!= NULL
)
4870 value_free_to_mark (mark
);
4871 return WP_VALUE_CHANGED
;
4875 /* Nothing changed. */
4876 value_free_to_mark (mark
);
4877 return WP_VALUE_NOT_CHANGED
;
4882 /* This seems like the only logical thing to do because
4883 if we temporarily ignored the watchpoint, then when
4884 we reenter the block in which it is valid it contains
4885 garbage (in the case of a function, it may have two
4886 garbage values, one before and one after the prologue).
4887 So we can't even detect the first assignment to it and
4888 watch after that (since the garbage may or may not equal
4889 the first value assigned). */
4890 /* We print all the stop information in
4891 breakpoint_ops->print_it, but in this case, by the time we
4892 call breakpoint_ops->print_it this bp will be deleted
4893 already. So we have no choice but print the information
4896 SWITCH_THRU_ALL_UIS ()
4898 struct ui_out
*uiout
= current_uiout
;
4900 if (uiout
->is_mi_like_p ())
4902 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4903 uiout
->message ("\nWatchpoint %pF deleted because the program has "
4904 "left the block in\n"
4905 "which its expression is valid.\n",
4906 signed_field ("wpnum", b
->number
));
4909 /* Make sure the watchpoint's commands aren't executed. */
4911 watchpoint_del_at_next_stop (b
);
4917 /* Return true if it looks like target has stopped due to hitting
4918 breakpoint location BL. This function does not check if we should
4919 stop, only if BL explains the stop. */
4922 bpstat_check_location (const struct bp_location
*bl
,
4923 const address_space
*aspace
, CORE_ADDR bp_addr
,
4924 const struct target_waitstatus
*ws
)
4926 struct breakpoint
*b
= bl
->owner
;
4928 /* BL is from an existing breakpoint. */
4929 gdb_assert (b
!= NULL
);
4931 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4934 /* Determine if the watched values have actually changed, and we
4935 should stop. If not, set BS->stop to 0. */
4938 bpstat_check_watchpoint (bpstat bs
)
4940 const struct bp_location
*bl
;
4941 struct watchpoint
*b
;
4943 /* BS is built for existing struct breakpoint. */
4944 bl
= bs
->bp_location_at
;
4945 gdb_assert (bl
!= NULL
);
4946 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4947 gdb_assert (b
!= NULL
);
4950 int must_check_value
= 0;
4952 if (b
->type
== bp_watchpoint
)
4953 /* For a software watchpoint, we must always check the
4955 must_check_value
= 1;
4956 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4957 /* We have a hardware watchpoint (read, write, or access)
4958 and the target earlier reported an address watched by
4960 must_check_value
= 1;
4961 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4962 && b
->type
== bp_hardware_watchpoint
)
4963 /* We were stopped by a hardware watchpoint, but the target could
4964 not report the data address. We must check the watchpoint's
4965 value. Access and read watchpoints are out of luck; without
4966 a data address, we can't figure it out. */
4967 must_check_value
= 1;
4969 if (must_check_value
)
4975 e
= watchpoint_check (bs
);
4977 catch (const gdb_exception
&ex
)
4979 exception_fprintf (gdb_stderr
, ex
,
4980 "Error evaluating expression "
4981 "for watchpoint %d\n",
4984 SWITCH_THRU_ALL_UIS ()
4986 printf_filtered (_("Watchpoint %d deleted.\n"),
4989 watchpoint_del_at_next_stop (b
);
4996 /* We've already printed what needs to be printed. */
4997 bs
->print_it
= print_it_done
;
5001 bs
->print_it
= print_it_noop
;
5004 case WP_VALUE_CHANGED
:
5005 if (b
->type
== bp_read_watchpoint
)
5007 /* There are two cases to consider here:
5009 1. We're watching the triggered memory for reads.
5010 In that case, trust the target, and always report
5011 the watchpoint hit to the user. Even though
5012 reads don't cause value changes, the value may
5013 have changed since the last time it was read, and
5014 since we're not trapping writes, we will not see
5015 those, and as such we should ignore our notion of
5018 2. We're watching the triggered memory for both
5019 reads and writes. There are two ways this may
5022 2.1. This is a target that can't break on data
5023 reads only, but can break on accesses (reads or
5024 writes), such as e.g., x86. We detect this case
5025 at the time we try to insert read watchpoints.
5027 2.2. Otherwise, the target supports read
5028 watchpoints, but, the user set an access or write
5029 watchpoint watching the same memory as this read
5032 If we're watching memory writes as well as reads,
5033 ignore watchpoint hits when we find that the
5034 value hasn't changed, as reads don't cause
5035 changes. This still gives false positives when
5036 the program writes the same value to memory as
5037 what there was already in memory (we will confuse
5038 it for a read), but it's much better than
5041 int other_write_watchpoint
= 0;
5043 if (bl
->watchpoint_type
== hw_read
)
5045 struct breakpoint
*other_b
;
5047 ALL_BREAKPOINTS (other_b
)
5048 if (other_b
->type
== bp_hardware_watchpoint
5049 || other_b
->type
== bp_access_watchpoint
)
5051 struct watchpoint
*other_w
=
5052 (struct watchpoint
*) other_b
;
5054 if (other_w
->watchpoint_triggered
5055 == watch_triggered_yes
)
5057 other_write_watchpoint
= 1;
5063 if (other_write_watchpoint
5064 || bl
->watchpoint_type
== hw_access
)
5066 /* We're watching the same memory for writes,
5067 and the value changed since the last time we
5068 updated it, so this trap must be for a write.
5070 bs
->print_it
= print_it_noop
;
5075 case WP_VALUE_NOT_CHANGED
:
5076 if (b
->type
== bp_hardware_watchpoint
5077 || b
->type
== bp_watchpoint
)
5079 /* Don't stop: write watchpoints shouldn't fire if
5080 the value hasn't changed. */
5081 bs
->print_it
= print_it_noop
;
5091 else /* must_check_value == 0 */
5093 /* This is a case where some watchpoint(s) triggered, but
5094 not at the address of this watchpoint, or else no
5095 watchpoint triggered after all. So don't print
5096 anything for this watchpoint. */
5097 bs
->print_it
= print_it_noop
;
5103 /* For breakpoints that are currently marked as telling gdb to stop,
5104 check conditions (condition proper, frame, thread and ignore count)
5105 of breakpoint referred to by BS. If we should not stop for this
5106 breakpoint, set BS->stop to 0. */
5109 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5111 const struct bp_location
*bl
;
5112 struct breakpoint
*b
;
5114 bool condition_result
= true;
5115 struct expression
*cond
;
5117 gdb_assert (bs
->stop
);
5119 /* BS is built for existing struct breakpoint. */
5120 bl
= bs
->bp_location_at
;
5121 gdb_assert (bl
!= NULL
);
5122 b
= bs
->breakpoint_at
;
5123 gdb_assert (b
!= NULL
);
5125 /* Even if the target evaluated the condition on its end and notified GDB, we
5126 need to do so again since GDB does not know if we stopped due to a
5127 breakpoint or a single step breakpoint. */
5129 if (frame_id_p (b
->frame_id
)
5130 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5136 /* If this is a thread/task-specific breakpoint, don't waste cpu
5137 evaluating the condition if this isn't the specified
5139 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5140 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5146 /* Evaluate extension language breakpoints that have a "stop" method
5148 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5150 if (is_watchpoint (b
))
5152 struct watchpoint
*w
= (struct watchpoint
*) b
;
5154 cond
= w
->cond_exp
.get ();
5157 cond
= bl
->cond
.get ();
5159 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5161 int within_current_scope
= 1;
5162 struct watchpoint
* w
;
5164 /* We use value_mark and value_free_to_mark because it could
5165 be a long time before we return to the command level and
5166 call free_all_values. We can't call free_all_values
5167 because we might be in the middle of evaluating a
5169 struct value
*mark
= value_mark ();
5171 if (is_watchpoint (b
))
5172 w
= (struct watchpoint
*) b
;
5176 /* Need to select the frame, with all that implies so that
5177 the conditions will have the right context. Because we
5178 use the frame, we will not see an inlined function's
5179 variables when we arrive at a breakpoint at the start
5180 of the inlined function; the current frame will be the
5182 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5183 select_frame (get_current_frame ());
5186 struct frame_info
*frame
;
5188 /* For local watchpoint expressions, which particular
5189 instance of a local is being watched matters, so we
5190 keep track of the frame to evaluate the expression
5191 in. To evaluate the condition however, it doesn't
5192 really matter which instantiation of the function
5193 where the condition makes sense triggers the
5194 watchpoint. This allows an expression like "watch
5195 global if q > 10" set in `func', catch writes to
5196 global on all threads that call `func', or catch
5197 writes on all recursive calls of `func' by a single
5198 thread. We simply always evaluate the condition in
5199 the innermost frame that's executing where it makes
5200 sense to evaluate the condition. It seems
5202 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5204 select_frame (frame
);
5206 within_current_scope
= 0;
5208 if (within_current_scope
)
5212 condition_result
= breakpoint_cond_eval (cond
);
5214 catch (const gdb_exception
&ex
)
5216 exception_fprintf (gdb_stderr
, ex
,
5217 "Error in testing breakpoint condition:\n");
5222 warning (_("Watchpoint condition cannot be tested "
5223 "in the current scope"));
5224 /* If we failed to set the right context for this
5225 watchpoint, unconditionally report it. */
5227 /* FIXME-someday, should give breakpoint #. */
5228 value_free_to_mark (mark
);
5231 if (cond
&& !condition_result
)
5235 else if (b
->ignore_count
> 0)
5239 /* Increase the hit count even though we don't stop. */
5241 gdb::observers::breakpoint_modified
.notify (b
);
5245 /* Returns true if we need to track moribund locations of LOC's type
5246 on the current target. */
5249 need_moribund_for_location_type (struct bp_location
*loc
)
5251 return ((loc
->loc_type
== bp_loc_software_breakpoint
5252 && !target_supports_stopped_by_sw_breakpoint ())
5253 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5254 && !target_supports_stopped_by_hw_breakpoint ()));
5257 /* See breakpoint.h. */
5260 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5261 const struct target_waitstatus
*ws
)
5263 struct breakpoint
*b
;
5264 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5268 if (!breakpoint_enabled (b
))
5271 for (bp_location
*bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5273 /* For hardware watchpoints, we look only at the first
5274 location. The watchpoint_check function will work on the
5275 entire expression, not the individual locations. For
5276 read watchpoints, the watchpoints_triggered function has
5277 checked all locations already. */
5278 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5281 if (!bl
->enabled
|| bl
->shlib_disabled
)
5284 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5287 /* Come here if it's a watchpoint, or if the break address
5290 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5293 /* Assume we stop. Should we find a watchpoint that is not
5294 actually triggered, or if the condition of the breakpoint
5295 evaluates as false, we'll reset 'stop' to 0. */
5299 /* If this is a scope breakpoint, mark the associated
5300 watchpoint as triggered so that we will handle the
5301 out-of-scope event. We'll get to the watchpoint next
5303 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5305 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5307 w
->watchpoint_triggered
= watch_triggered_yes
;
5312 /* Check if a moribund breakpoint explains the stop. */
5313 if (!target_supports_stopped_by_sw_breakpoint ()
5314 || !target_supports_stopped_by_hw_breakpoint ())
5316 for (bp_location
*loc
: moribund_locations
)
5318 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5319 && need_moribund_for_location_type (loc
))
5321 bpstat bs
= new bpstats (loc
, &bs_link
);
5322 /* For hits of moribund locations, we should just proceed. */
5325 bs
->print_it
= print_it_noop
;
5333 /* See breakpoint.h. */
5336 bpstat_stop_status (const address_space
*aspace
,
5337 CORE_ADDR bp_addr
, thread_info
*thread
,
5338 const struct target_waitstatus
*ws
,
5341 struct breakpoint
*b
= NULL
;
5342 /* First item of allocated bpstat's. */
5343 bpstat bs_head
= stop_chain
;
5345 int need_remove_insert
;
5348 /* First, build the bpstat chain with locations that explain a
5349 target stop, while being careful to not set the target running,
5350 as that may invalidate locations (in particular watchpoint
5351 locations are recreated). Resuming will happen here with
5352 breakpoint conditions or watchpoint expressions that include
5353 inferior function calls. */
5354 if (bs_head
== NULL
)
5355 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5357 /* A bit of special processing for shlib breakpoints. We need to
5358 process solib loading here, so that the lists of loaded and
5359 unloaded libraries are correct before we handle "catch load" and
5361 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5363 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5365 handle_solib_event ();
5370 /* Now go through the locations that caused the target to stop, and
5371 check whether we're interested in reporting this stop to higher
5372 layers, or whether we should resume the target transparently. */
5376 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5381 b
= bs
->breakpoint_at
;
5382 b
->ops
->check_status (bs
);
5385 bpstat_check_breakpoint_conditions (bs
, thread
);
5390 gdb::observers::breakpoint_modified
.notify (b
);
5392 /* We will stop here. */
5393 if (b
->disposition
== disp_disable
)
5395 --(b
->enable_count
);
5396 if (b
->enable_count
<= 0)
5397 b
->enable_state
= bp_disabled
;
5402 bs
->commands
= b
->commands
;
5403 if (command_line_is_silent (bs
->commands
5404 ? bs
->commands
.get () : NULL
))
5407 b
->ops
->after_condition_true (bs
);
5412 /* Print nothing for this entry if we don't stop or don't
5414 if (!bs
->stop
|| !bs
->print
)
5415 bs
->print_it
= print_it_noop
;
5418 /* If we aren't stopping, the value of some hardware watchpoint may
5419 not have changed, but the intermediate memory locations we are
5420 watching may have. Don't bother if we're stopping; this will get
5422 need_remove_insert
= 0;
5423 if (! bpstat_causes_stop (bs_head
))
5424 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5426 && bs
->breakpoint_at
5427 && is_hardware_watchpoint (bs
->breakpoint_at
))
5429 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5431 update_watchpoint (w
, 0 /* don't reparse. */);
5432 need_remove_insert
= 1;
5435 if (need_remove_insert
)
5436 update_global_location_list (UGLL_MAY_INSERT
);
5437 else if (removed_any
)
5438 update_global_location_list (UGLL_DONT_INSERT
);
5444 handle_jit_event (void)
5446 struct frame_info
*frame
;
5447 struct gdbarch
*gdbarch
;
5449 infrun_debug_printf ("handling bp_jit_event");
5451 /* Switch terminal for any messages produced by
5452 breakpoint_re_set. */
5453 target_terminal::ours_for_output ();
5455 frame
= get_current_frame ();
5456 gdbarch
= get_frame_arch (frame
);
5457 objfile
*jiter
= symbol_objfile (get_frame_function (frame
));
5459 jit_event_handler (gdbarch
, jiter
);
5461 target_terminal::inferior ();
5464 /* Prepare WHAT final decision for infrun. */
5466 /* Decide what infrun needs to do with this bpstat. */
5469 bpstat_what (bpstat bs_head
)
5471 struct bpstat_what retval
;
5474 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5475 retval
.call_dummy
= STOP_NONE
;
5476 retval
.is_longjmp
= false;
5478 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5480 /* Extract this BS's action. After processing each BS, we check
5481 if its action overrides all we've seem so far. */
5482 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5485 if (bs
->breakpoint_at
== NULL
)
5487 /* I suspect this can happen if it was a momentary
5488 breakpoint which has since been deleted. */
5492 bptype
= bs
->breakpoint_at
->type
;
5499 case bp_hardware_breakpoint
:
5500 case bp_single_step
:
5503 case bp_shlib_event
:
5507 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5509 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5512 this_action
= BPSTAT_WHAT_SINGLE
;
5515 case bp_hardware_watchpoint
:
5516 case bp_read_watchpoint
:
5517 case bp_access_watchpoint
:
5521 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5523 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5527 /* There was a watchpoint, but we're not stopping.
5528 This requires no further action. */
5532 case bp_longjmp_call_dummy
:
5536 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5537 retval
.is_longjmp
= bptype
!= bp_exception
;
5540 this_action
= BPSTAT_WHAT_SINGLE
;
5542 case bp_longjmp_resume
:
5543 case bp_exception_resume
:
5546 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5547 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5550 this_action
= BPSTAT_WHAT_SINGLE
;
5552 case bp_step_resume
:
5554 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5557 /* It is for the wrong frame. */
5558 this_action
= BPSTAT_WHAT_SINGLE
;
5561 case bp_hp_step_resume
:
5563 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5566 /* It is for the wrong frame. */
5567 this_action
= BPSTAT_WHAT_SINGLE
;
5570 case bp_watchpoint_scope
:
5571 case bp_thread_event
:
5572 case bp_overlay_event
:
5573 case bp_longjmp_master
:
5574 case bp_std_terminate_master
:
5575 case bp_exception_master
:
5576 this_action
= BPSTAT_WHAT_SINGLE
;
5582 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5584 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5588 /* Some catchpoints are implemented with breakpoints.
5589 For those, we need to step over the breakpoint. */
5590 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5591 this_action
= BPSTAT_WHAT_SINGLE
;
5595 this_action
= BPSTAT_WHAT_SINGLE
;
5598 /* Make sure the action is stop (silent or noisy),
5599 so infrun.c pops the dummy frame. */
5600 retval
.call_dummy
= STOP_STACK_DUMMY
;
5601 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5603 case bp_std_terminate
:
5604 /* Make sure the action is stop (silent or noisy),
5605 so infrun.c pops the dummy frame. */
5606 retval
.call_dummy
= STOP_STD_TERMINATE
;
5607 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5610 case bp_fast_tracepoint
:
5611 case bp_static_tracepoint
:
5612 /* Tracepoint hits should not be reported back to GDB, and
5613 if one got through somehow, it should have been filtered
5615 internal_error (__FILE__
, __LINE__
,
5616 _("bpstat_what: tracepoint encountered"));
5618 case bp_gnu_ifunc_resolver
:
5619 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5620 this_action
= BPSTAT_WHAT_SINGLE
;
5622 case bp_gnu_ifunc_resolver_return
:
5623 /* The breakpoint will be removed, execution will restart from the
5624 PC of the former breakpoint. */
5625 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5630 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5632 this_action
= BPSTAT_WHAT_SINGLE
;
5636 internal_error (__FILE__
, __LINE__
,
5637 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5640 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5647 bpstat_run_callbacks (bpstat bs_head
)
5651 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5653 struct breakpoint
*b
= bs
->breakpoint_at
;
5660 handle_jit_event ();
5662 case bp_gnu_ifunc_resolver
:
5663 gnu_ifunc_resolver_stop (b
);
5665 case bp_gnu_ifunc_resolver_return
:
5666 gnu_ifunc_resolver_return_stop (b
);
5672 /* See breakpoint.h. */
5675 bpstat_should_step ()
5677 struct breakpoint
*b
;
5680 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5685 /* See breakpoint.h. */
5688 bpstat_causes_stop (bpstat bs
)
5690 for (; bs
!= NULL
; bs
= bs
->next
)
5699 /* Compute a string of spaces suitable to indent the next line
5700 so it starts at the position corresponding to the table column
5701 named COL_NAME in the currently active table of UIOUT. */
5704 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5706 static char wrap_indent
[80];
5707 int i
, total_width
, width
, align
;
5711 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5713 if (strcmp (text
, col_name
) == 0)
5715 gdb_assert (total_width
< sizeof wrap_indent
);
5716 memset (wrap_indent
, ' ', total_width
);
5717 wrap_indent
[total_width
] = 0;
5722 total_width
+= width
+ 1;
5728 /* Determine if the locations of this breakpoint will have their conditions
5729 evaluated by the target, host or a mix of both. Returns the following:
5731 "host": Host evals condition.
5732 "host or target": Host or Target evals condition.
5733 "target": Target evals condition.
5737 bp_condition_evaluator (struct breakpoint
*b
)
5739 struct bp_location
*bl
;
5740 char host_evals
= 0;
5741 char target_evals
= 0;
5746 if (!is_breakpoint (b
))
5749 if (gdb_evaluates_breakpoint_condition_p ()
5750 || !target_supports_evaluation_of_breakpoint_conditions ())
5751 return condition_evaluation_host
;
5753 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5755 if (bl
->cond_bytecode
)
5761 if (host_evals
&& target_evals
)
5762 return condition_evaluation_both
;
5763 else if (target_evals
)
5764 return condition_evaluation_target
;
5766 return condition_evaluation_host
;
5769 /* Determine the breakpoint location's condition evaluator. This is
5770 similar to bp_condition_evaluator, but for locations. */
5773 bp_location_condition_evaluator (struct bp_location
*bl
)
5775 if (bl
&& !is_breakpoint (bl
->owner
))
5778 if (gdb_evaluates_breakpoint_condition_p ()
5779 || !target_supports_evaluation_of_breakpoint_conditions ())
5780 return condition_evaluation_host
;
5782 if (bl
&& bl
->cond_bytecode
)
5783 return condition_evaluation_target
;
5785 return condition_evaluation_host
;
5788 /* Print the LOC location out of the list of B->LOC locations. */
5791 print_breakpoint_location (struct breakpoint
*b
,
5792 struct bp_location
*loc
)
5794 struct ui_out
*uiout
= current_uiout
;
5796 scoped_restore_current_program_space restore_pspace
;
5798 if (loc
!= NULL
&& loc
->shlib_disabled
)
5802 set_current_program_space (loc
->pspace
);
5804 if (b
->display_canonical
)
5805 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5806 else if (loc
&& loc
->symtab
)
5808 const struct symbol
*sym
= loc
->symbol
;
5812 uiout
->text ("in ");
5813 uiout
->field_string ("func", sym
->print_name (),
5814 function_name_style
.style ());
5816 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5817 uiout
->text ("at ");
5819 uiout
->field_string ("file",
5820 symtab_to_filename_for_display (loc
->symtab
),
5821 file_name_style
.style ());
5824 if (uiout
->is_mi_like_p ())
5825 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5827 uiout
->field_signed ("line", loc
->line_number
);
5833 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5835 uiout
->field_stream ("at", stb
);
5839 uiout
->field_string ("pending",
5840 event_location_to_string (b
->location
.get ()));
5841 /* If extra_string is available, it could be holding a condition
5842 or dprintf arguments. In either case, make sure it is printed,
5843 too, but only for non-MI streams. */
5844 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5846 if (b
->type
== bp_dprintf
)
5850 uiout
->text (b
->extra_string
);
5854 if (loc
&& is_breakpoint (b
)
5855 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5856 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5859 uiout
->field_string ("evaluated-by",
5860 bp_location_condition_evaluator (loc
));
5866 bptype_string (enum bptype type
)
5868 struct ep_type_description
5871 const char *description
;
5873 static struct ep_type_description bptypes
[] =
5875 {bp_none
, "?deleted?"},
5876 {bp_breakpoint
, "breakpoint"},
5877 {bp_hardware_breakpoint
, "hw breakpoint"},
5878 {bp_single_step
, "sw single-step"},
5879 {bp_until
, "until"},
5880 {bp_finish
, "finish"},
5881 {bp_watchpoint
, "watchpoint"},
5882 {bp_hardware_watchpoint
, "hw watchpoint"},
5883 {bp_read_watchpoint
, "read watchpoint"},
5884 {bp_access_watchpoint
, "acc watchpoint"},
5885 {bp_longjmp
, "longjmp"},
5886 {bp_longjmp_resume
, "longjmp resume"},
5887 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5888 {bp_exception
, "exception"},
5889 {bp_exception_resume
, "exception resume"},
5890 {bp_step_resume
, "step resume"},
5891 {bp_hp_step_resume
, "high-priority step resume"},
5892 {bp_watchpoint_scope
, "watchpoint scope"},
5893 {bp_call_dummy
, "call dummy"},
5894 {bp_std_terminate
, "std::terminate"},
5895 {bp_shlib_event
, "shlib events"},
5896 {bp_thread_event
, "thread events"},
5897 {bp_overlay_event
, "overlay events"},
5898 {bp_longjmp_master
, "longjmp master"},
5899 {bp_std_terminate_master
, "std::terminate master"},
5900 {bp_exception_master
, "exception master"},
5901 {bp_catchpoint
, "catchpoint"},
5902 {bp_tracepoint
, "tracepoint"},
5903 {bp_fast_tracepoint
, "fast tracepoint"},
5904 {bp_static_tracepoint
, "static tracepoint"},
5905 {bp_dprintf
, "dprintf"},
5906 {bp_jit_event
, "jit events"},
5907 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5908 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5911 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5912 || ((int) type
!= bptypes
[(int) type
].type
))
5913 internal_error (__FILE__
, __LINE__
,
5914 _("bptypes table does not describe type #%d."),
5917 return bptypes
[(int) type
].description
;
5920 /* For MI, output a field named 'thread-groups' with a list as the value.
5921 For CLI, prefix the list with the string 'inf'. */
5924 output_thread_groups (struct ui_out
*uiout
,
5925 const char *field_name
,
5926 const std::vector
<int> &inf_nums
,
5929 int is_mi
= uiout
->is_mi_like_p ();
5931 /* For backward compatibility, don't display inferiors in CLI unless
5932 there are several. Always display them for MI. */
5933 if (!is_mi
&& mi_only
)
5936 ui_out_emit_list
list_emitter (uiout
, field_name
);
5938 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
5944 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
5945 uiout
->field_string (NULL
, mi_group
);
5950 uiout
->text (" inf ");
5954 uiout
->text (plongest (inf_nums
[i
]));
5959 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
5960 instead of going via breakpoint_ops::print_one. This makes "maint
5961 info breakpoints" show the software breakpoint locations of
5962 catchpoints, which are considered internal implementation
5966 print_one_breakpoint_location (struct breakpoint
*b
,
5967 struct bp_location
*loc
,
5969 struct bp_location
**last_loc
,
5970 int allflag
, bool raw_loc
)
5972 struct command_line
*l
;
5973 static char bpenables
[] = "nynny";
5975 struct ui_out
*uiout
= current_uiout
;
5976 int header_of_multiple
= 0;
5977 int part_of_multiple
= (loc
!= NULL
);
5978 struct value_print_options opts
;
5980 get_user_print_options (&opts
);
5982 gdb_assert (!loc
|| loc_number
!= 0);
5983 /* See comment in print_one_breakpoint concerning treatment of
5984 breakpoints with single disabled location. */
5987 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
5988 header_of_multiple
= 1;
5996 if (part_of_multiple
)
5997 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
5999 uiout
->field_signed ("number", b
->number
);
6003 if (part_of_multiple
)
6004 uiout
->field_skip ("type");
6006 uiout
->field_string ("type", bptype_string (b
->type
));
6010 if (part_of_multiple
)
6011 uiout
->field_skip ("disp");
6013 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6017 if (part_of_multiple
)
6018 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6020 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6023 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6024 b
->ops
->print_one (b
, last_loc
);
6027 if (is_watchpoint (b
))
6029 struct watchpoint
*w
= (struct watchpoint
*) b
;
6031 /* Field 4, the address, is omitted (which makes the columns
6032 not line up too nicely with the headers, but the effect
6033 is relatively readable). */
6034 if (opts
.addressprint
)
6035 uiout
->field_skip ("addr");
6037 uiout
->field_string ("what", w
->exp_string
);
6039 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6040 || is_ada_exception_catchpoint (b
))
6042 if (opts
.addressprint
)
6045 if (header_of_multiple
)
6046 uiout
->field_string ("addr", "<MULTIPLE>",
6047 metadata_style
.style ());
6048 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6049 uiout
->field_string ("addr", "<PENDING>",
6050 metadata_style
.style ());
6052 uiout
->field_core_addr ("addr",
6053 loc
->gdbarch
, loc
->address
);
6056 if (!header_of_multiple
)
6057 print_breakpoint_location (b
, loc
);
6063 if (loc
!= NULL
&& !header_of_multiple
)
6065 std::vector
<int> inf_nums
;
6068 for (inferior
*inf
: all_inferiors ())
6070 if (inf
->pspace
== loc
->pspace
)
6071 inf_nums
.push_back (inf
->num
);
6074 /* For backward compatibility, don't display inferiors in CLI unless
6075 there are several. Always display for MI. */
6077 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6078 && (program_spaces
.size () > 1
6079 || number_of_inferiors () > 1)
6080 /* LOC is for existing B, it cannot be in
6081 moribund_locations and thus having NULL OWNER. */
6082 && loc
->owner
->type
!= bp_catchpoint
))
6084 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6087 if (!part_of_multiple
)
6089 if (b
->thread
!= -1)
6091 /* FIXME: This seems to be redundant and lost here; see the
6092 "stop only in" line a little further down. */
6093 uiout
->text (" thread ");
6094 uiout
->field_signed ("thread", b
->thread
);
6096 else if (b
->task
!= 0)
6098 uiout
->text (" task ");
6099 uiout
->field_signed ("task", b
->task
);
6105 if (!part_of_multiple
)
6106 b
->ops
->print_one_detail (b
, uiout
);
6108 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6111 uiout
->text ("\tstop only in stack frame at ");
6112 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6114 uiout
->field_core_addr ("frame",
6115 b
->gdbarch
, b
->frame_id
.stack_addr
);
6119 if (!part_of_multiple
&& b
->cond_string
)
6122 if (is_tracepoint (b
))
6123 uiout
->text ("\ttrace only if ");
6125 uiout
->text ("\tstop only if ");
6126 uiout
->field_string ("cond", b
->cond_string
);
6128 /* Print whether the target is doing the breakpoint's condition
6129 evaluation. If GDB is doing the evaluation, don't print anything. */
6130 if (is_breakpoint (b
)
6131 && breakpoint_condition_evaluation_mode ()
6132 == condition_evaluation_target
)
6134 uiout
->message (" (%pF evals)",
6135 string_field ("evaluated-by",
6136 bp_condition_evaluator (b
)));
6141 if (!part_of_multiple
&& b
->thread
!= -1)
6143 /* FIXME should make an annotation for this. */
6144 uiout
->text ("\tstop only in thread ");
6145 if (uiout
->is_mi_like_p ())
6146 uiout
->field_signed ("thread", b
->thread
);
6149 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6151 uiout
->field_string ("thread", print_thread_id (thr
));
6156 if (!part_of_multiple
)
6160 /* FIXME should make an annotation for this. */
6161 if (is_catchpoint (b
))
6162 uiout
->text ("\tcatchpoint");
6163 else if (is_tracepoint (b
))
6164 uiout
->text ("\ttracepoint");
6166 uiout
->text ("\tbreakpoint");
6167 uiout
->text (" already hit ");
6168 uiout
->field_signed ("times", b
->hit_count
);
6169 if (b
->hit_count
== 1)
6170 uiout
->text (" time\n");
6172 uiout
->text (" times\n");
6176 /* Output the count also if it is zero, but only if this is mi. */
6177 if (uiout
->is_mi_like_p ())
6178 uiout
->field_signed ("times", b
->hit_count
);
6182 if (!part_of_multiple
&& b
->ignore_count
)
6185 uiout
->message ("\tignore next %pF hits\n",
6186 signed_field ("ignore", b
->ignore_count
));
6189 /* Note that an enable count of 1 corresponds to "enable once"
6190 behavior, which is reported by the combination of enablement and
6191 disposition, so we don't need to mention it here. */
6192 if (!part_of_multiple
&& b
->enable_count
> 1)
6195 uiout
->text ("\tdisable after ");
6196 /* Tweak the wording to clarify that ignore and enable counts
6197 are distinct, and have additive effect. */
6198 if (b
->ignore_count
)
6199 uiout
->text ("additional ");
6201 uiout
->text ("next ");
6202 uiout
->field_signed ("enable", b
->enable_count
);
6203 uiout
->text (" hits\n");
6206 if (!part_of_multiple
&& is_tracepoint (b
))
6208 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6210 if (tp
->traceframe_usage
)
6212 uiout
->text ("\ttrace buffer usage ");
6213 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6214 uiout
->text (" bytes\n");
6218 l
= b
->commands
? b
->commands
.get () : NULL
;
6219 if (!part_of_multiple
&& l
)
6222 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6223 print_command_lines (uiout
, l
, 4);
6226 if (is_tracepoint (b
))
6228 struct tracepoint
*t
= (struct tracepoint
*) b
;
6230 if (!part_of_multiple
&& t
->pass_count
)
6232 annotate_field (10);
6233 uiout
->text ("\tpass count ");
6234 uiout
->field_signed ("pass", t
->pass_count
);
6235 uiout
->text (" \n");
6238 /* Don't display it when tracepoint or tracepoint location is
6240 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6242 annotate_field (11);
6244 if (uiout
->is_mi_like_p ())
6245 uiout
->field_string ("installed",
6246 loc
->inserted
? "y" : "n");
6252 uiout
->text ("\tnot ");
6253 uiout
->text ("installed on target\n");
6258 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6260 if (is_watchpoint (b
))
6262 struct watchpoint
*w
= (struct watchpoint
*) b
;
6264 uiout
->field_string ("original-location", w
->exp_string
);
6266 else if (b
->location
!= NULL
6267 && event_location_to_string (b
->location
.get ()) != NULL
)
6268 uiout
->field_string ("original-location",
6269 event_location_to_string (b
->location
.get ()));
6273 /* See breakpoint.h. */
6275 bool fix_multi_location_breakpoint_output_globally
= false;
6278 print_one_breakpoint (struct breakpoint
*b
,
6279 struct bp_location
**last_loc
,
6282 struct ui_out
*uiout
= current_uiout
;
6283 bool use_fixed_output
6284 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6285 || fix_multi_location_breakpoint_output_globally
);
6287 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6288 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6290 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6292 if (!use_fixed_output
)
6293 bkpt_tuple_emitter
.reset ();
6295 /* If this breakpoint has custom print function,
6296 it's already printed. Otherwise, print individual
6297 locations, if any. */
6299 || b
->ops
->print_one
== NULL
6302 /* If breakpoint has a single location that is disabled, we
6303 print it as if it had several locations, since otherwise it's
6304 hard to represent "breakpoint enabled, location disabled"
6307 Note that while hardware watchpoints have several locations
6308 internally, that's not a property exposed to users.
6310 Likewise, while catchpoints may be implemented with
6311 breakpoints (e.g., catch throw), that's not a property
6312 exposed to users. We do however display the internal
6313 breakpoint locations with "maint info breakpoints". */
6314 if (!is_hardware_watchpoint (b
)
6315 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6316 || is_ada_exception_catchpoint (b
))
6318 || (b
->loc
&& (b
->loc
->next
|| !b
->loc
->enabled
))))
6320 gdb::optional
<ui_out_emit_list
> locations_list
;
6322 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6323 MI record. For later versions, place breakpoint locations in a
6325 if (uiout
->is_mi_like_p () && use_fixed_output
)
6326 locations_list
.emplace (uiout
, "locations");
6329 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
, ++n
)
6331 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6332 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6340 breakpoint_address_bits (struct breakpoint
*b
)
6342 int print_address_bits
= 0;
6343 struct bp_location
*loc
;
6345 /* Software watchpoints that aren't watching memory don't have an
6346 address to print. */
6347 if (is_no_memory_software_watchpoint (b
))
6350 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6354 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6355 if (addr_bit
> print_address_bits
)
6356 print_address_bits
= addr_bit
;
6359 return print_address_bits
;
6362 /* See breakpoint.h. */
6365 print_breakpoint (breakpoint
*b
)
6367 struct bp_location
*dummy_loc
= NULL
;
6368 print_one_breakpoint (b
, &dummy_loc
, 0);
6371 /* Return true if this breakpoint was set by the user, false if it is
6372 internal or momentary. */
6375 user_breakpoint_p (struct breakpoint
*b
)
6377 return b
->number
> 0;
6380 /* See breakpoint.h. */
6383 pending_breakpoint_p (struct breakpoint
*b
)
6385 return b
->loc
== NULL
;
6388 /* Print information on breakpoints (including watchpoints and tracepoints).
6390 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6391 understood by number_or_range_parser. Only breakpoints included in this
6392 list are then printed.
6394 If SHOW_INTERNAL is true, print internal breakpoints.
6396 If FILTER is non-NULL, call it on each breakpoint and only include the
6397 ones for which it returns true.
6399 Return the total number of breakpoints listed. */
6402 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6403 bool (*filter
) (const struct breakpoint
*))
6405 struct breakpoint
*b
;
6406 struct bp_location
*last_loc
= NULL
;
6407 int nr_printable_breakpoints
;
6408 struct value_print_options opts
;
6409 int print_address_bits
= 0;
6410 int print_type_col_width
= 14;
6411 struct ui_out
*uiout
= current_uiout
;
6413 get_user_print_options (&opts
);
6415 /* Compute the number of rows in the table, as well as the size
6416 required for address fields. */
6417 nr_printable_breakpoints
= 0;
6420 /* If we have a filter, only list the breakpoints it accepts. */
6421 if (filter
&& !filter (b
))
6424 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6425 accept. Skip the others. */
6426 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6428 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6430 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6434 if (show_internal
|| user_breakpoint_p (b
))
6436 int addr_bit
, type_len
;
6438 addr_bit
= breakpoint_address_bits (b
);
6439 if (addr_bit
> print_address_bits
)
6440 print_address_bits
= addr_bit
;
6442 type_len
= strlen (bptype_string (b
->type
));
6443 if (type_len
> print_type_col_width
)
6444 print_type_col_width
= type_len
;
6446 nr_printable_breakpoints
++;
6451 ui_out_emit_table
table_emitter (uiout
,
6452 opts
.addressprint
? 6 : 5,
6453 nr_printable_breakpoints
,
6456 if (nr_printable_breakpoints
> 0)
6457 annotate_breakpoints_headers ();
6458 if (nr_printable_breakpoints
> 0)
6460 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6461 if (nr_printable_breakpoints
> 0)
6463 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6464 if (nr_printable_breakpoints
> 0)
6466 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6467 if (nr_printable_breakpoints
> 0)
6469 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6470 if (opts
.addressprint
)
6472 if (nr_printable_breakpoints
> 0)
6474 if (print_address_bits
<= 32)
6475 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6477 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6479 if (nr_printable_breakpoints
> 0)
6481 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6482 uiout
->table_body ();
6483 if (nr_printable_breakpoints
> 0)
6484 annotate_breakpoints_table ();
6489 /* If we have a filter, only list the breakpoints it accepts. */
6490 if (filter
&& !filter (b
))
6493 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6494 accept. Skip the others. */
6496 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6498 if (show_internal
) /* maintenance info breakpoint */
6500 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6503 else /* all others */
6505 if (!number_is_in_list (bp_num_list
, b
->number
))
6509 /* We only print out user settable breakpoints unless the
6510 show_internal is set. */
6511 if (show_internal
|| user_breakpoint_p (b
))
6512 print_one_breakpoint (b
, &last_loc
, show_internal
);
6516 if (nr_printable_breakpoints
== 0)
6518 /* If there's a filter, let the caller decide how to report
6522 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6523 uiout
->message ("No breakpoints or watchpoints.\n");
6525 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6531 if (last_loc
&& !server_command
)
6532 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6535 /* FIXME? Should this be moved up so that it is only called when
6536 there have been breakpoints? */
6537 annotate_breakpoints_table_end ();
6539 return nr_printable_breakpoints
;
6542 /* Display the value of default-collect in a way that is generally
6543 compatible with the breakpoint list. */
6546 default_collect_info (void)
6548 struct ui_out
*uiout
= current_uiout
;
6550 /* If it has no value (which is frequently the case), say nothing; a
6551 message like "No default-collect." gets in user's face when it's
6553 if (!*default_collect
)
6556 /* The following phrase lines up nicely with per-tracepoint collect
6558 uiout
->text ("default collect ");
6559 uiout
->field_string ("default-collect", default_collect
);
6560 uiout
->text (" \n");
6564 info_breakpoints_command (const char *args
, int from_tty
)
6566 breakpoint_1 (args
, false, NULL
);
6568 default_collect_info ();
6572 info_watchpoints_command (const char *args
, int from_tty
)
6574 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6575 struct ui_out
*uiout
= current_uiout
;
6577 if (num_printed
== 0)
6579 if (args
== NULL
|| *args
== '\0')
6580 uiout
->message ("No watchpoints.\n");
6582 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6587 maintenance_info_breakpoints (const char *args
, int from_tty
)
6589 breakpoint_1 (args
, true, NULL
);
6591 default_collect_info ();
6595 breakpoint_has_pc (struct breakpoint
*b
,
6596 struct program_space
*pspace
,
6597 CORE_ADDR pc
, struct obj_section
*section
)
6599 struct bp_location
*bl
= b
->loc
;
6601 for (; bl
; bl
= bl
->next
)
6603 if (bl
->pspace
== pspace
6604 && bl
->address
== pc
6605 && (!overlay_debugging
|| bl
->section
== section
))
6611 /* Print a message describing any user-breakpoints set at PC. This
6612 concerns with logical breakpoints, so we match program spaces, not
6616 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6617 struct program_space
*pspace
, CORE_ADDR pc
,
6618 struct obj_section
*section
, int thread
)
6621 struct breakpoint
*b
;
6624 others
+= (user_breakpoint_p (b
)
6625 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6629 printf_filtered (_("Note: breakpoint "));
6630 else /* if (others == ???) */
6631 printf_filtered (_("Note: breakpoints "));
6633 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6636 printf_filtered ("%d", b
->number
);
6637 if (b
->thread
== -1 && thread
!= -1)
6638 printf_filtered (" (all threads)");
6639 else if (b
->thread
!= -1)
6640 printf_filtered (" (thread %d)", b
->thread
);
6641 printf_filtered ("%s%s ",
6642 ((b
->enable_state
== bp_disabled
6643 || b
->enable_state
== bp_call_disabled
)
6647 : ((others
== 1) ? " and" : ""));
6649 current_uiout
->message (_("also set at pc %ps.\n"),
6650 styled_string (address_style
.style (),
6651 paddress (gdbarch
, pc
)));
6656 /* Return true iff it is meaningful to use the address member of LOC.
6657 For some breakpoint types, the locations' address members are
6658 irrelevant and it makes no sense to attempt to compare them to
6659 other addresses (or use them for any other purpose either).
6661 More specifically, software watchpoints and catchpoints that are
6662 not backed by breakpoints always have a zero valued location
6663 address and we don't want to mark breakpoints of any of these types
6664 to be a duplicate of an actual breakpoint location at address
6668 bl_address_is_meaningful (bp_location
*loc
)
6670 return loc
->loc_type
!= bp_loc_other
;
6673 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6674 true if LOC1 and LOC2 represent the same watchpoint location. */
6677 watchpoint_locations_match (struct bp_location
*loc1
,
6678 struct bp_location
*loc2
)
6680 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6681 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6683 /* Both of them must exist. */
6684 gdb_assert (w1
!= NULL
);
6685 gdb_assert (w2
!= NULL
);
6687 /* If the target can evaluate the condition expression in hardware,
6688 then we we need to insert both watchpoints even if they are at
6689 the same place. Otherwise the watchpoint will only trigger when
6690 the condition of whichever watchpoint was inserted evaluates to
6691 true, not giving a chance for GDB to check the condition of the
6692 other watchpoint. */
6694 && target_can_accel_watchpoint_condition (loc1
->address
,
6696 loc1
->watchpoint_type
,
6697 w1
->cond_exp
.get ()))
6699 && target_can_accel_watchpoint_condition (loc2
->address
,
6701 loc2
->watchpoint_type
,
6702 w2
->cond_exp
.get ())))
6705 /* Note that this checks the owner's type, not the location's. In
6706 case the target does not support read watchpoints, but does
6707 support access watchpoints, we'll have bp_read_watchpoint
6708 watchpoints with hw_access locations. Those should be considered
6709 duplicates of hw_read locations. The hw_read locations will
6710 become hw_access locations later. */
6711 return (loc1
->owner
->type
== loc2
->owner
->type
6712 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6713 && loc1
->address
== loc2
->address
6714 && loc1
->length
== loc2
->length
);
6717 /* See breakpoint.h. */
6720 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6721 const address_space
*aspace2
, CORE_ADDR addr2
)
6723 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6724 || aspace1
== aspace2
)
6728 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6729 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6730 matches ASPACE2. On targets that have global breakpoints, the address
6731 space doesn't really matter. */
6734 breakpoint_address_match_range (const address_space
*aspace1
,
6736 int len1
, const address_space
*aspace2
,
6739 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6740 || aspace1
== aspace2
)
6741 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6744 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6745 a ranged breakpoint. In most targets, a match happens only if ASPACE
6746 matches the breakpoint's address space. On targets that have global
6747 breakpoints, the address space doesn't really matter. */
6750 breakpoint_location_address_match (struct bp_location
*bl
,
6751 const address_space
*aspace
,
6754 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6757 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6758 bl
->address
, bl
->length
,
6762 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6763 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6764 match happens only if ASPACE matches the breakpoint's address
6765 space. On targets that have global breakpoints, the address space
6766 doesn't really matter. */
6769 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6770 const address_space
*aspace
,
6771 CORE_ADDR addr
, int len
)
6773 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6774 || bl
->pspace
->aspace
== aspace
)
6776 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6778 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6784 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6785 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6786 true, otherwise returns false. */
6789 tracepoint_locations_match (struct bp_location
*loc1
,
6790 struct bp_location
*loc2
)
6792 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6793 /* Since tracepoint locations are never duplicated with others', tracepoint
6794 locations at the same address of different tracepoints are regarded as
6795 different locations. */
6796 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6801 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6802 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6803 the same location. If SW_HW_BPS_MATCH is true, then software
6804 breakpoint locations and hardware breakpoint locations match,
6805 otherwise they don't. */
6808 breakpoint_locations_match (struct bp_location
*loc1
,
6809 struct bp_location
*loc2
,
6810 bool sw_hw_bps_match
)
6812 int hw_point1
, hw_point2
;
6814 /* Both of them must not be in moribund_locations. */
6815 gdb_assert (loc1
->owner
!= NULL
);
6816 gdb_assert (loc2
->owner
!= NULL
);
6818 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6819 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6821 if (hw_point1
!= hw_point2
)
6824 return watchpoint_locations_match (loc1
, loc2
);
6825 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6826 return tracepoint_locations_match (loc1
, loc2
);
6828 /* We compare bp_location.length in order to cover ranged
6829 breakpoints. Keep this in sync with
6830 bp_location_is_less_than. */
6831 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6832 loc2
->pspace
->aspace
, loc2
->address
)
6833 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
6834 && loc1
->length
== loc2
->length
);
6838 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6839 int bnum
, int have_bnum
)
6841 /* The longest string possibly returned by hex_string_custom
6842 is 50 chars. These must be at least that big for safety. */
6846 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6847 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6849 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6850 bnum
, astr1
, astr2
);
6852 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6855 /* Adjust a breakpoint's address to account for architectural
6856 constraints on breakpoint placement. Return the adjusted address.
6857 Note: Very few targets require this kind of adjustment. For most
6858 targets, this function is simply the identity function. */
6861 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6862 CORE_ADDR bpaddr
, enum bptype bptype
)
6864 if (bptype
== bp_watchpoint
6865 || bptype
== bp_hardware_watchpoint
6866 || bptype
== bp_read_watchpoint
6867 || bptype
== bp_access_watchpoint
6868 || bptype
== bp_catchpoint
)
6870 /* Watchpoints and the various bp_catch_* eventpoints should not
6871 have their addresses modified. */
6874 else if (bptype
== bp_single_step
)
6876 /* Single-step breakpoints should not have their addresses
6877 modified. If there's any architectural constrain that
6878 applies to this address, then it should have already been
6879 taken into account when the breakpoint was created in the
6880 first place. If we didn't do this, stepping through e.g.,
6881 Thumb-2 IT blocks would break. */
6886 CORE_ADDR adjusted_bpaddr
= bpaddr
;
6888 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
6890 /* Some targets have architectural constraints on the placement
6891 of breakpoint instructions. Obtain the adjusted address. */
6892 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6895 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
6897 /* An adjusted breakpoint address can significantly alter
6898 a user's expectations. Print a warning if an adjustment
6900 if (adjusted_bpaddr
!= bpaddr
)
6901 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6903 return adjusted_bpaddr
;
6908 bp_location_from_bp_type (bptype type
)
6913 case bp_single_step
:
6917 case bp_longjmp_resume
:
6918 case bp_longjmp_call_dummy
:
6920 case bp_exception_resume
:
6921 case bp_step_resume
:
6922 case bp_hp_step_resume
:
6923 case bp_watchpoint_scope
:
6925 case bp_std_terminate
:
6926 case bp_shlib_event
:
6927 case bp_thread_event
:
6928 case bp_overlay_event
:
6930 case bp_longjmp_master
:
6931 case bp_std_terminate_master
:
6932 case bp_exception_master
:
6933 case bp_gnu_ifunc_resolver
:
6934 case bp_gnu_ifunc_resolver_return
:
6936 return bp_loc_software_breakpoint
;
6937 case bp_hardware_breakpoint
:
6938 return bp_loc_hardware_breakpoint
;
6939 case bp_hardware_watchpoint
:
6940 case bp_read_watchpoint
:
6941 case bp_access_watchpoint
:
6942 return bp_loc_hardware_watchpoint
;
6946 case bp_fast_tracepoint
:
6947 case bp_static_tracepoint
:
6948 return bp_loc_other
;
6950 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
6954 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
6956 this->owner
= owner
;
6957 this->cond_bytecode
= NULL
;
6958 this->shlib_disabled
= 0;
6961 this->loc_type
= type
;
6963 if (this->loc_type
== bp_loc_software_breakpoint
6964 || this->loc_type
== bp_loc_hardware_breakpoint
)
6965 mark_breakpoint_location_modified (this);
6970 bp_location::bp_location (breakpoint
*owner
)
6971 : bp_location::bp_location (owner
,
6972 bp_location_from_bp_type (owner
->type
))
6976 /* Allocate a struct bp_location. */
6978 static struct bp_location
*
6979 allocate_bp_location (struct breakpoint
*bpt
)
6981 return bpt
->ops
->allocate_location (bpt
);
6985 free_bp_location (struct bp_location
*loc
)
6990 /* Increment reference count. */
6993 incref_bp_location (struct bp_location
*bl
)
6998 /* Decrement reference count. If the reference count reaches 0,
6999 destroy the bp_location. Sets *BLP to NULL. */
7002 decref_bp_location (struct bp_location
**blp
)
7004 gdb_assert ((*blp
)->refc
> 0);
7006 if (--(*blp
)->refc
== 0)
7007 free_bp_location (*blp
);
7011 /* Add breakpoint B at the end of the global breakpoint chain. */
7014 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7016 struct breakpoint
*b1
;
7017 struct breakpoint
*result
= b
.get ();
7019 /* Add this breakpoint to the end of the chain so that a list of
7020 breakpoints will come out in order of increasing numbers. */
7022 b1
= breakpoint_chain
;
7024 breakpoint_chain
= b
.release ();
7029 b1
->next
= b
.release ();
7035 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7038 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7039 struct gdbarch
*gdbarch
,
7041 const struct breakpoint_ops
*ops
)
7043 gdb_assert (ops
!= NULL
);
7047 b
->gdbarch
= gdbarch
;
7048 b
->language
= current_language
->la_language
;
7049 b
->input_radix
= input_radix
;
7050 b
->related_breakpoint
= b
;
7053 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7054 that has type BPTYPE and has no locations as yet. */
7056 static struct breakpoint
*
7057 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7059 const struct breakpoint_ops
*ops
)
7061 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7063 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7064 return add_to_breakpoint_chain (std::move (b
));
7067 /* Initialize loc->function_name. */
7070 set_breakpoint_location_function (struct bp_location
*loc
)
7072 gdb_assert (loc
->owner
!= NULL
);
7074 if (loc
->owner
->type
== bp_breakpoint
7075 || loc
->owner
->type
== bp_hardware_breakpoint
7076 || is_tracepoint (loc
->owner
))
7078 const char *function_name
;
7080 if (loc
->msymbol
!= NULL
7081 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7082 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7084 struct breakpoint
*b
= loc
->owner
;
7086 function_name
= loc
->msymbol
->linkage_name ();
7088 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7089 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7091 /* Create only the whole new breakpoint of this type but do not
7092 mess more complicated breakpoints with multiple locations. */
7093 b
->type
= bp_gnu_ifunc_resolver
;
7094 /* Remember the resolver's address for use by the return
7096 loc
->related_address
= loc
->address
;
7100 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7103 loc
->function_name
= xstrdup (function_name
);
7107 /* Attempt to determine architecture of location identified by SAL. */
7109 get_sal_arch (struct symtab_and_line sal
)
7112 return sal
.section
->objfile
->arch ();
7114 return SYMTAB_OBJFILE (sal
.symtab
)->arch ();
7119 /* Low level routine for partially initializing a breakpoint of type
7120 BPTYPE. The newly created breakpoint's address, section, source
7121 file name, and line number are provided by SAL.
7123 It is expected that the caller will complete the initialization of
7124 the newly created breakpoint struct as well as output any status
7125 information regarding the creation of a new breakpoint. */
7128 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7129 struct symtab_and_line sal
, enum bptype bptype
,
7130 const struct breakpoint_ops
*ops
)
7132 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7134 add_location_to_breakpoint (b
, &sal
);
7136 if (bptype
!= bp_catchpoint
)
7137 gdb_assert (sal
.pspace
!= NULL
);
7139 /* Store the program space that was used to set the breakpoint,
7140 except for ordinary breakpoints, which are independent of the
7142 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7143 b
->pspace
= sal
.pspace
;
7146 /* set_raw_breakpoint is a low level routine for allocating and
7147 partially initializing a breakpoint of type BPTYPE. The newly
7148 created breakpoint's address, section, source file name, and line
7149 number are provided by SAL. The newly created and partially
7150 initialized breakpoint is added to the breakpoint chain and
7151 is also returned as the value of this function.
7153 It is expected that the caller will complete the initialization of
7154 the newly created breakpoint struct as well as output any status
7155 information regarding the creation of a new breakpoint. In
7156 particular, set_raw_breakpoint does NOT set the breakpoint
7157 number! Care should be taken to not allow an error to occur
7158 prior to completing the initialization of the breakpoint. If this
7159 should happen, a bogus breakpoint will be left on the chain. */
7162 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7163 struct symtab_and_line sal
, enum bptype bptype
,
7164 const struct breakpoint_ops
*ops
)
7166 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7168 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7169 return add_to_breakpoint_chain (std::move (b
));
7172 /* Call this routine when stepping and nexting to enable a breakpoint
7173 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7174 initiated the operation. */
7177 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7179 struct breakpoint
*b
, *b_tmp
;
7180 int thread
= tp
->global_num
;
7182 /* To avoid having to rescan all objfile symbols at every step,
7183 we maintain a list of continually-inserted but always disabled
7184 longjmp "master" breakpoints. Here, we simply create momentary
7185 clones of those and enable them for the requested thread. */
7186 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7187 if (b
->pspace
== current_program_space
7188 && (b
->type
== bp_longjmp_master
7189 || b
->type
== bp_exception_master
))
7191 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7192 struct breakpoint
*clone
;
7194 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7195 after their removal. */
7196 clone
= momentary_breakpoint_from_master (b
, type
,
7197 &momentary_breakpoint_ops
, 1);
7198 clone
->thread
= thread
;
7201 tp
->initiating_frame
= frame
;
7204 /* Delete all longjmp breakpoints from THREAD. */
7206 delete_longjmp_breakpoint (int thread
)
7208 struct breakpoint
*b
, *b_tmp
;
7210 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7211 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7213 if (b
->thread
== thread
)
7214 delete_breakpoint (b
);
7219 delete_longjmp_breakpoint_at_next_stop (int thread
)
7221 struct breakpoint
*b
, *b_tmp
;
7223 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7224 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7226 if (b
->thread
== thread
)
7227 b
->disposition
= disp_del_at_next_stop
;
7231 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7232 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7233 pointer to any of them. Return NULL if this system cannot place longjmp
7237 set_longjmp_breakpoint_for_call_dummy (void)
7239 struct breakpoint
*b
, *retval
= NULL
;
7242 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7244 struct breakpoint
*new_b
;
7246 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7247 &momentary_breakpoint_ops
,
7249 new_b
->thread
= inferior_thread ()->global_num
;
7251 /* Link NEW_B into the chain of RETVAL breakpoints. */
7253 gdb_assert (new_b
->related_breakpoint
== new_b
);
7256 new_b
->related_breakpoint
= retval
;
7257 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7258 retval
= retval
->related_breakpoint
;
7259 retval
->related_breakpoint
= new_b
;
7265 /* Verify all existing dummy frames and their associated breakpoints for
7266 TP. Remove those which can no longer be found in the current frame
7269 You should call this function only at places where it is safe to currently
7270 unwind the whole stack. Failed stack unwind would discard live dummy
7274 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7276 struct breakpoint
*b
, *b_tmp
;
7278 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7279 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7281 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7283 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7284 dummy_b
= dummy_b
->related_breakpoint
;
7285 if (dummy_b
->type
!= bp_call_dummy
7286 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7289 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7291 while (b
->related_breakpoint
!= b
)
7293 if (b_tmp
== b
->related_breakpoint
)
7294 b_tmp
= b
->related_breakpoint
->next
;
7295 delete_breakpoint (b
->related_breakpoint
);
7297 delete_breakpoint (b
);
7302 enable_overlay_breakpoints (void)
7304 struct breakpoint
*b
;
7307 if (b
->type
== bp_overlay_event
)
7309 b
->enable_state
= bp_enabled
;
7310 update_global_location_list (UGLL_MAY_INSERT
);
7311 overlay_events_enabled
= 1;
7316 disable_overlay_breakpoints (void)
7318 struct breakpoint
*b
;
7321 if (b
->type
== bp_overlay_event
)
7323 b
->enable_state
= bp_disabled
;
7324 update_global_location_list (UGLL_DONT_INSERT
);
7325 overlay_events_enabled
= 0;
7329 /* Set an active std::terminate breakpoint for each std::terminate
7330 master breakpoint. */
7332 set_std_terminate_breakpoint (void)
7334 struct breakpoint
*b
, *b_tmp
;
7336 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7337 if (b
->pspace
== current_program_space
7338 && b
->type
== bp_std_terminate_master
)
7340 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7341 &momentary_breakpoint_ops
, 1);
7345 /* Delete all the std::terminate breakpoints. */
7347 delete_std_terminate_breakpoint (void)
7349 struct breakpoint
*b
, *b_tmp
;
7351 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7352 if (b
->type
== bp_std_terminate
)
7353 delete_breakpoint (b
);
7357 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7359 struct breakpoint
*b
;
7361 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7362 &internal_breakpoint_ops
);
7364 b
->enable_state
= bp_enabled
;
7365 /* location has to be used or breakpoint_re_set will delete me. */
7366 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7368 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7373 struct lang_and_radix
7379 /* Create a breakpoint for JIT code registration and unregistration. */
7382 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7384 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7385 &internal_breakpoint_ops
);
7388 /* Remove JIT code registration and unregistration breakpoint(s). */
7391 remove_jit_event_breakpoints (void)
7393 struct breakpoint
*b
, *b_tmp
;
7395 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7396 if (b
->type
== bp_jit_event
7397 && b
->loc
->pspace
== current_program_space
)
7398 delete_breakpoint (b
);
7402 remove_solib_event_breakpoints (void)
7404 struct breakpoint
*b
, *b_tmp
;
7406 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7407 if (b
->type
== bp_shlib_event
7408 && b
->loc
->pspace
== current_program_space
)
7409 delete_breakpoint (b
);
7412 /* See breakpoint.h. */
7415 remove_solib_event_breakpoints_at_next_stop (void)
7417 struct breakpoint
*b
, *b_tmp
;
7419 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7420 if (b
->type
== bp_shlib_event
7421 && b
->loc
->pspace
== current_program_space
)
7422 b
->disposition
= disp_del_at_next_stop
;
7425 /* Helper for create_solib_event_breakpoint /
7426 create_and_insert_solib_event_breakpoint. Allows specifying which
7427 INSERT_MODE to pass through to update_global_location_list. */
7429 static struct breakpoint
*
7430 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7431 enum ugll_insert_mode insert_mode
)
7433 struct breakpoint
*b
;
7435 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7436 &internal_breakpoint_ops
);
7437 update_global_location_list_nothrow (insert_mode
);
7442 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7444 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7447 /* See breakpoint.h. */
7450 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7452 struct breakpoint
*b
;
7454 /* Explicitly tell update_global_location_list to insert
7456 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7457 if (!b
->loc
->inserted
)
7459 delete_breakpoint (b
);
7465 /* Disable any breakpoints that are on code in shared libraries. Only
7466 apply to enabled breakpoints, disabled ones can just stay disabled. */
7469 disable_breakpoints_in_shlibs (void)
7471 struct bp_location
*loc
, **locp_tmp
;
7473 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7475 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7476 struct breakpoint
*b
= loc
->owner
;
7478 /* We apply the check to all breakpoints, including disabled for
7479 those with loc->duplicate set. This is so that when breakpoint
7480 becomes enabled, or the duplicate is removed, gdb will try to
7481 insert all breakpoints. If we don't set shlib_disabled here,
7482 we'll try to insert those breakpoints and fail. */
7483 if (((b
->type
== bp_breakpoint
)
7484 || (b
->type
== bp_jit_event
)
7485 || (b
->type
== bp_hardware_breakpoint
)
7486 || (is_tracepoint (b
)))
7487 && loc
->pspace
== current_program_space
7488 && !loc
->shlib_disabled
7489 && solib_name_from_address (loc
->pspace
, loc
->address
)
7492 loc
->shlib_disabled
= 1;
7497 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7498 notification of unloaded_shlib. Only apply to enabled breakpoints,
7499 disabled ones can just stay disabled. */
7502 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7504 struct bp_location
*loc
, **locp_tmp
;
7505 int disabled_shlib_breaks
= 0;
7507 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7509 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7510 struct breakpoint
*b
= loc
->owner
;
7512 if (solib
->pspace
== loc
->pspace
7513 && !loc
->shlib_disabled
7514 && (((b
->type
== bp_breakpoint
7515 || b
->type
== bp_jit_event
7516 || b
->type
== bp_hardware_breakpoint
)
7517 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7518 || loc
->loc_type
== bp_loc_software_breakpoint
))
7519 || is_tracepoint (b
))
7520 && solib_contains_address_p (solib
, loc
->address
))
7522 loc
->shlib_disabled
= 1;
7523 /* At this point, we cannot rely on remove_breakpoint
7524 succeeding so we must mark the breakpoint as not inserted
7525 to prevent future errors occurring in remove_breakpoints. */
7528 /* This may cause duplicate notifications for the same breakpoint. */
7529 gdb::observers::breakpoint_modified
.notify (b
);
7531 if (!disabled_shlib_breaks
)
7533 target_terminal::ours_for_output ();
7534 warning (_("Temporarily disabling breakpoints "
7535 "for unloaded shared library \"%s\""),
7538 disabled_shlib_breaks
= 1;
7543 /* Disable any breakpoints and tracepoints in OBJFILE upon
7544 notification of free_objfile. Only apply to enabled breakpoints,
7545 disabled ones can just stay disabled. */
7548 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7550 struct breakpoint
*b
;
7552 if (objfile
== NULL
)
7555 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7556 managed by the user with add-symbol-file/remove-symbol-file.
7557 Similarly to how breakpoints in shared libraries are handled in
7558 response to "nosharedlibrary", mark breakpoints in such modules
7559 shlib_disabled so they end up uninserted on the next global
7560 location list update. Shared libraries not loaded by the user
7561 aren't handled here -- they're already handled in
7562 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7563 solib_unloaded observer. We skip objfiles that are not
7564 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7566 if ((objfile
->flags
& OBJF_SHARED
) == 0
7567 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7572 struct bp_location
*loc
;
7573 int bp_modified
= 0;
7575 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7578 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7580 CORE_ADDR loc_addr
= loc
->address
;
7582 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7583 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7586 if (loc
->shlib_disabled
!= 0)
7589 if (objfile
->pspace
!= loc
->pspace
)
7592 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7593 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7596 if (is_addr_in_objfile (loc_addr
, objfile
))
7598 loc
->shlib_disabled
= 1;
7599 /* At this point, we don't know whether the object was
7600 unmapped from the inferior or not, so leave the
7601 inserted flag alone. We'll handle failure to
7602 uninsert quietly, in case the object was indeed
7605 mark_breakpoint_location_modified (loc
);
7612 gdb::observers::breakpoint_modified
.notify (b
);
7616 /* FORK & VFORK catchpoints. */
7618 /* An instance of this type is used to represent a fork or vfork
7619 catchpoint. A breakpoint is really of this type iff its ops pointer points
7620 to CATCH_FORK_BREAKPOINT_OPS. */
7622 struct fork_catchpoint
: public breakpoint
7624 /* Process id of a child process whose forking triggered this
7625 catchpoint. This field is only valid immediately after this
7626 catchpoint has triggered. */
7627 ptid_t forked_inferior_pid
;
7630 /* Implement the "insert" breakpoint_ops method for fork
7634 insert_catch_fork (struct bp_location
*bl
)
7636 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7639 /* Implement the "remove" breakpoint_ops method for fork
7643 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7645 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7648 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7652 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7653 const address_space
*aspace
, CORE_ADDR bp_addr
,
7654 const struct target_waitstatus
*ws
)
7656 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7658 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7661 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7665 /* Implement the "print_it" breakpoint_ops method for fork
7668 static enum print_stop_action
7669 print_it_catch_fork (bpstat bs
)
7671 struct ui_out
*uiout
= current_uiout
;
7672 struct breakpoint
*b
= bs
->breakpoint_at
;
7673 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7675 annotate_catchpoint (b
->number
);
7676 maybe_print_thread_hit_breakpoint (uiout
);
7677 if (b
->disposition
== disp_del
)
7678 uiout
->text ("Temporary catchpoint ");
7680 uiout
->text ("Catchpoint ");
7681 if (uiout
->is_mi_like_p ())
7683 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7684 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7686 uiout
->field_signed ("bkptno", b
->number
);
7687 uiout
->text (" (forked process ");
7688 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7689 uiout
->text ("), ");
7690 return PRINT_SRC_AND_LOC
;
7693 /* Implement the "print_one" breakpoint_ops method for fork
7697 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7699 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7700 struct value_print_options opts
;
7701 struct ui_out
*uiout
= current_uiout
;
7703 get_user_print_options (&opts
);
7705 /* Field 4, the address, is omitted (which makes the columns not
7706 line up too nicely with the headers, but the effect is relatively
7708 if (opts
.addressprint
)
7709 uiout
->field_skip ("addr");
7711 uiout
->text ("fork");
7712 if (c
->forked_inferior_pid
!= null_ptid
)
7714 uiout
->text (", process ");
7715 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7719 if (uiout
->is_mi_like_p ())
7720 uiout
->field_string ("catch-type", "fork");
7723 /* Implement the "print_mention" breakpoint_ops method for fork
7727 print_mention_catch_fork (struct breakpoint
*b
)
7729 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7732 /* Implement the "print_recreate" breakpoint_ops method for fork
7736 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7738 fprintf_unfiltered (fp
, "catch fork");
7739 print_recreate_thread (b
, fp
);
7742 /* The breakpoint_ops structure to be used in fork catchpoints. */
7744 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7746 /* Implement the "insert" breakpoint_ops method for vfork
7750 insert_catch_vfork (struct bp_location
*bl
)
7752 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7755 /* Implement the "remove" breakpoint_ops method for vfork
7759 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7761 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7764 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7768 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7769 const address_space
*aspace
, CORE_ADDR bp_addr
,
7770 const struct target_waitstatus
*ws
)
7772 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7774 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7777 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7781 /* Implement the "print_it" breakpoint_ops method for vfork
7784 static enum print_stop_action
7785 print_it_catch_vfork (bpstat bs
)
7787 struct ui_out
*uiout
= current_uiout
;
7788 struct breakpoint
*b
= bs
->breakpoint_at
;
7789 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7791 annotate_catchpoint (b
->number
);
7792 maybe_print_thread_hit_breakpoint (uiout
);
7793 if (b
->disposition
== disp_del
)
7794 uiout
->text ("Temporary catchpoint ");
7796 uiout
->text ("Catchpoint ");
7797 if (uiout
->is_mi_like_p ())
7799 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7800 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7802 uiout
->field_signed ("bkptno", b
->number
);
7803 uiout
->text (" (vforked process ");
7804 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7805 uiout
->text ("), ");
7806 return PRINT_SRC_AND_LOC
;
7809 /* Implement the "print_one" breakpoint_ops method for vfork
7813 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7815 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7816 struct value_print_options opts
;
7817 struct ui_out
*uiout
= current_uiout
;
7819 get_user_print_options (&opts
);
7820 /* Field 4, the address, is omitted (which makes the columns not
7821 line up too nicely with the headers, but the effect is relatively
7823 if (opts
.addressprint
)
7824 uiout
->field_skip ("addr");
7826 uiout
->text ("vfork");
7827 if (c
->forked_inferior_pid
!= null_ptid
)
7829 uiout
->text (", process ");
7830 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7834 if (uiout
->is_mi_like_p ())
7835 uiout
->field_string ("catch-type", "vfork");
7838 /* Implement the "print_mention" breakpoint_ops method for vfork
7842 print_mention_catch_vfork (struct breakpoint
*b
)
7844 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7847 /* Implement the "print_recreate" breakpoint_ops method for vfork
7851 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7853 fprintf_unfiltered (fp
, "catch vfork");
7854 print_recreate_thread (b
, fp
);
7857 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7859 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7861 /* An instance of this type is used to represent an solib catchpoint.
7862 A breakpoint is really of this type iff its ops pointer points to
7863 CATCH_SOLIB_BREAKPOINT_OPS. */
7865 struct solib_catchpoint
: public breakpoint
7867 ~solib_catchpoint () override
;
7869 /* True for "catch load", false for "catch unload". */
7872 /* Regular expression to match, if any. COMPILED is only valid when
7873 REGEX is non-NULL. */
7875 std::unique_ptr
<compiled_regex
> compiled
;
7878 solib_catchpoint::~solib_catchpoint ()
7880 xfree (this->regex
);
7884 insert_catch_solib (struct bp_location
*ignore
)
7890 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
7896 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7897 const address_space
*aspace
,
7899 const struct target_waitstatus
*ws
)
7901 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7902 struct breakpoint
*other
;
7904 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7907 ALL_BREAKPOINTS (other
)
7909 struct bp_location
*other_bl
;
7911 if (other
== bl
->owner
)
7914 if (other
->type
!= bp_shlib_event
)
7917 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
7920 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7922 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7931 check_status_catch_solib (struct bpstats
*bs
)
7933 struct solib_catchpoint
*self
7934 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7938 for (so_list
*iter
: current_program_space
->added_solibs
)
7941 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
7947 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
7950 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
7956 bs
->print_it
= print_it_noop
;
7959 static enum print_stop_action
7960 print_it_catch_solib (bpstat bs
)
7962 struct breakpoint
*b
= bs
->breakpoint_at
;
7963 struct ui_out
*uiout
= current_uiout
;
7965 annotate_catchpoint (b
->number
);
7966 maybe_print_thread_hit_breakpoint (uiout
);
7967 if (b
->disposition
== disp_del
)
7968 uiout
->text ("Temporary catchpoint ");
7970 uiout
->text ("Catchpoint ");
7971 uiout
->field_signed ("bkptno", b
->number
);
7973 if (uiout
->is_mi_like_p ())
7974 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7975 print_solib_event (1);
7976 return PRINT_SRC_AND_LOC
;
7980 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7982 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7983 struct value_print_options opts
;
7984 struct ui_out
*uiout
= current_uiout
;
7986 get_user_print_options (&opts
);
7987 /* Field 4, the address, is omitted (which makes the columns not
7988 line up too nicely with the headers, but the effect is relatively
7990 if (opts
.addressprint
)
7993 uiout
->field_skip ("addr");
8001 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8003 msg
= _("load of library");
8008 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8010 msg
= _("unload of library");
8012 uiout
->field_string ("what", msg
);
8014 if (uiout
->is_mi_like_p ())
8015 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8019 print_mention_catch_solib (struct breakpoint
*b
)
8021 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8023 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8024 self
->is_load
? "load" : "unload");
8028 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8030 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8032 fprintf_unfiltered (fp
, "%s %s",
8033 b
->disposition
== disp_del
? "tcatch" : "catch",
8034 self
->is_load
? "load" : "unload");
8036 fprintf_unfiltered (fp
, " %s", self
->regex
);
8037 fprintf_unfiltered (fp
, "\n");
8040 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8042 /* See breakpoint.h. */
8045 add_solib_catchpoint (const char *arg
, bool is_load
, bool is_temp
, bool enabled
)
8047 struct gdbarch
*gdbarch
= get_current_arch ();
8051 arg
= skip_spaces (arg
);
8053 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8057 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8058 _("Invalid regexp")));
8059 c
->regex
= xstrdup (arg
);
8062 c
->is_load
= is_load
;
8063 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8064 &catch_solib_breakpoint_ops
);
8066 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8068 install_breakpoint (0, std::move (c
), 1);
8071 /* A helper function that does all the work for "catch load" and
8075 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8076 struct cmd_list_element
*command
)
8078 const int enabled
= 1;
8079 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8081 add_solib_catchpoint (arg
, is_load
, temp
, enabled
);
8085 catch_load_command_1 (const char *arg
, int from_tty
,
8086 struct cmd_list_element
*command
)
8088 catch_load_or_unload (arg
, from_tty
, 1, command
);
8092 catch_unload_command_1 (const char *arg
, int from_tty
,
8093 struct cmd_list_element
*command
)
8095 catch_load_or_unload (arg
, from_tty
, 0, command
);
8098 /* See breakpoint.h. */
8101 init_catchpoint (struct breakpoint
*b
,
8102 struct gdbarch
*gdbarch
, bool temp
,
8103 const char *cond_string
,
8104 const struct breakpoint_ops
*ops
)
8106 symtab_and_line sal
;
8107 sal
.pspace
= current_program_space
;
8109 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8111 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8112 b
->disposition
= temp
? disp_del
: disp_donttouch
;
8116 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8118 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8119 set_breakpoint_number (internal
, b
);
8120 if (is_tracepoint (b
))
8121 set_tracepoint_count (breakpoint_count
);
8124 gdb::observers::breakpoint_created
.notify (b
);
8127 update_global_location_list (UGLL_MAY_INSERT
);
8131 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8132 bool temp
, const char *cond_string
,
8133 const struct breakpoint_ops
*ops
)
8135 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8137 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
, ops
);
8139 c
->forked_inferior_pid
= null_ptid
;
8141 install_breakpoint (0, std::move (c
), 1);
8144 /* Exec catchpoints. */
8146 /* An instance of this type is used to represent an exec catchpoint.
8147 A breakpoint is really of this type iff its ops pointer points to
8148 CATCH_EXEC_BREAKPOINT_OPS. */
8150 struct exec_catchpoint
: public breakpoint
8152 ~exec_catchpoint () override
;
8154 /* Filename of a program whose exec triggered this catchpoint.
8155 This field is only valid immediately after this catchpoint has
8157 char *exec_pathname
;
8160 /* Exec catchpoint destructor. */
8162 exec_catchpoint::~exec_catchpoint ()
8164 xfree (this->exec_pathname
);
8168 insert_catch_exec (struct bp_location
*bl
)
8170 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8174 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8176 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8180 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8181 const address_space
*aspace
, CORE_ADDR bp_addr
,
8182 const struct target_waitstatus
*ws
)
8184 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8186 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8189 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8193 static enum print_stop_action
8194 print_it_catch_exec (bpstat bs
)
8196 struct ui_out
*uiout
= current_uiout
;
8197 struct breakpoint
*b
= bs
->breakpoint_at
;
8198 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8200 annotate_catchpoint (b
->number
);
8201 maybe_print_thread_hit_breakpoint (uiout
);
8202 if (b
->disposition
== disp_del
)
8203 uiout
->text ("Temporary catchpoint ");
8205 uiout
->text ("Catchpoint ");
8206 if (uiout
->is_mi_like_p ())
8208 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8209 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8211 uiout
->field_signed ("bkptno", b
->number
);
8212 uiout
->text (" (exec'd ");
8213 uiout
->field_string ("new-exec", c
->exec_pathname
);
8214 uiout
->text ("), ");
8216 return PRINT_SRC_AND_LOC
;
8220 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8222 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8223 struct value_print_options opts
;
8224 struct ui_out
*uiout
= current_uiout
;
8226 get_user_print_options (&opts
);
8228 /* Field 4, the address, is omitted (which makes the columns
8229 not line up too nicely with the headers, but the effect
8230 is relatively readable). */
8231 if (opts
.addressprint
)
8232 uiout
->field_skip ("addr");
8234 uiout
->text ("exec");
8235 if (c
->exec_pathname
!= NULL
)
8237 uiout
->text (", program \"");
8238 uiout
->field_string ("what", c
->exec_pathname
);
8239 uiout
->text ("\" ");
8242 if (uiout
->is_mi_like_p ())
8243 uiout
->field_string ("catch-type", "exec");
8247 print_mention_catch_exec (struct breakpoint
*b
)
8249 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8252 /* Implement the "print_recreate" breakpoint_ops method for exec
8256 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8258 fprintf_unfiltered (fp
, "catch exec");
8259 print_recreate_thread (b
, fp
);
8262 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8265 hw_breakpoint_used_count (void)
8268 struct breakpoint
*b
;
8269 struct bp_location
*bl
;
8273 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8274 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8276 /* Special types of hardware breakpoints may use more than
8278 i
+= b
->ops
->resources_needed (bl
);
8285 /* Returns the resources B would use if it were a hardware
8289 hw_watchpoint_use_count (struct breakpoint
*b
)
8292 struct bp_location
*bl
;
8294 if (!breakpoint_enabled (b
))
8297 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8299 /* Special types of hardware watchpoints may use more than
8301 i
+= b
->ops
->resources_needed (bl
);
8307 /* Returns the sum the used resources of all hardware watchpoints of
8308 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8309 the sum of the used resources of all hardware watchpoints of other
8310 types _not_ TYPE. */
8313 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8314 enum bptype type
, int *other_type_used
)
8317 struct breakpoint
*b
;
8319 *other_type_used
= 0;
8324 if (!breakpoint_enabled (b
))
8327 if (b
->type
== type
)
8328 i
+= hw_watchpoint_use_count (b
);
8329 else if (is_hardware_watchpoint (b
))
8330 *other_type_used
= 1;
8337 disable_watchpoints_before_interactive_call_start (void)
8339 struct breakpoint
*b
;
8343 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8345 b
->enable_state
= bp_call_disabled
;
8346 update_global_location_list (UGLL_DONT_INSERT
);
8352 enable_watchpoints_after_interactive_call_stop (void)
8354 struct breakpoint
*b
;
8358 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8360 b
->enable_state
= bp_enabled
;
8361 update_global_location_list (UGLL_MAY_INSERT
);
8367 disable_breakpoints_before_startup (void)
8369 current_program_space
->executing_startup
= 1;
8370 update_global_location_list (UGLL_DONT_INSERT
);
8374 enable_breakpoints_after_startup (void)
8376 current_program_space
->executing_startup
= 0;
8377 breakpoint_re_set ();
8380 /* Create a new single-step breakpoint for thread THREAD, with no
8383 static struct breakpoint
*
8384 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8386 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8388 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8389 &momentary_breakpoint_ops
);
8391 b
->disposition
= disp_donttouch
;
8392 b
->frame_id
= null_frame_id
;
8395 gdb_assert (b
->thread
!= 0);
8397 return add_to_breakpoint_chain (std::move (b
));
8400 /* Set a momentary breakpoint of type TYPE at address specified by
8401 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8405 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8406 struct frame_id frame_id
, enum bptype type
)
8408 struct breakpoint
*b
;
8410 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8412 gdb_assert (!frame_id_artificial_p (frame_id
));
8414 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8415 b
->enable_state
= bp_enabled
;
8416 b
->disposition
= disp_donttouch
;
8417 b
->frame_id
= frame_id
;
8419 b
->thread
= inferior_thread ()->global_num
;
8421 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8423 return breakpoint_up (b
);
8426 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8427 The new breakpoint will have type TYPE, use OPS as its
8428 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8430 static struct breakpoint
*
8431 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8433 const struct breakpoint_ops
*ops
,
8436 struct breakpoint
*copy
;
8438 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8439 copy
->loc
= allocate_bp_location (copy
);
8440 set_breakpoint_location_function (copy
->loc
);
8442 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8443 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8444 copy
->loc
->address
= orig
->loc
->address
;
8445 copy
->loc
->section
= orig
->loc
->section
;
8446 copy
->loc
->pspace
= orig
->loc
->pspace
;
8447 copy
->loc
->probe
= orig
->loc
->probe
;
8448 copy
->loc
->line_number
= orig
->loc
->line_number
;
8449 copy
->loc
->symtab
= orig
->loc
->symtab
;
8450 copy
->loc
->enabled
= loc_enabled
;
8451 copy
->frame_id
= orig
->frame_id
;
8452 copy
->thread
= orig
->thread
;
8453 copy
->pspace
= orig
->pspace
;
8455 copy
->enable_state
= bp_enabled
;
8456 copy
->disposition
= disp_donttouch
;
8457 copy
->number
= internal_breakpoint_number
--;
8459 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8463 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8467 clone_momentary_breakpoint (struct breakpoint
*orig
)
8469 /* If there's nothing to clone, then return nothing. */
8473 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8477 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8480 struct symtab_and_line sal
;
8482 sal
= find_pc_line (pc
, 0);
8484 sal
.section
= find_pc_overlay (pc
);
8485 sal
.explicit_pc
= 1;
8487 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8491 /* Tell the user we have just set a breakpoint B. */
8494 mention (struct breakpoint
*b
)
8496 b
->ops
->print_mention (b
);
8497 current_uiout
->text ("\n");
8501 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8503 /* Handle "set breakpoint auto-hw on".
8505 If the explicitly specified breakpoint type is not hardware
8506 breakpoint, check the memory map to see whether the breakpoint
8507 address is in read-only memory.
8509 - location type is not hardware breakpoint, memory is read-only.
8510 We change the type of the location to hardware breakpoint.
8512 - location type is hardware breakpoint, memory is read-write. This
8513 means we've previously made the location hardware one, but then the
8514 memory map changed, so we undo.
8518 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8520 if (automatic_hardware_breakpoints
8521 && bl
->owner
->type
!= bp_hardware_breakpoint
8522 && (bl
->loc_type
== bp_loc_software_breakpoint
8523 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8525 /* When breakpoints are removed, remove_breakpoints will use
8526 location types we've just set here, the only possible problem
8527 is that memory map has changed during running program, but
8528 it's not going to work anyway with current gdb. */
8529 mem_region
*mr
= lookup_mem_region (bl
->address
);
8533 enum bp_loc_type new_type
;
8535 if (mr
->attrib
.mode
!= MEM_RW
)
8536 new_type
= bp_loc_hardware_breakpoint
;
8538 new_type
= bp_loc_software_breakpoint
;
8540 if (new_type
!= bl
->loc_type
)
8542 static bool said
= false;
8544 bl
->loc_type
= new_type
;
8547 fprintf_filtered (gdb_stdout
,
8548 _("Note: automatically using "
8549 "hardware breakpoints for "
8550 "read-only addresses.\n"));
8558 static struct bp_location
*
8559 add_location_to_breakpoint (struct breakpoint
*b
,
8560 const struct symtab_and_line
*sal
)
8562 struct bp_location
*loc
, **tmp
;
8563 CORE_ADDR adjusted_address
;
8564 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8566 if (loc_gdbarch
== NULL
)
8567 loc_gdbarch
= b
->gdbarch
;
8569 /* Adjust the breakpoint's address prior to allocating a location.
8570 Once we call allocate_bp_location(), that mostly uninitialized
8571 location will be placed on the location chain. Adjustment of the
8572 breakpoint may cause target_read_memory() to be called and we do
8573 not want its scan of the location chain to find a breakpoint and
8574 location that's only been partially initialized. */
8575 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8578 /* Sort the locations by their ADDRESS. */
8579 loc
= allocate_bp_location (b
);
8580 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8581 tmp
= &((*tmp
)->next
))
8586 loc
->requested_address
= sal
->pc
;
8587 loc
->address
= adjusted_address
;
8588 loc
->pspace
= sal
->pspace
;
8589 loc
->probe
.prob
= sal
->prob
;
8590 loc
->probe
.objfile
= sal
->objfile
;
8591 gdb_assert (loc
->pspace
!= NULL
);
8592 loc
->section
= sal
->section
;
8593 loc
->gdbarch
= loc_gdbarch
;
8594 loc
->line_number
= sal
->line
;
8595 loc
->symtab
= sal
->symtab
;
8596 loc
->symbol
= sal
->symbol
;
8597 loc
->msymbol
= sal
->msymbol
;
8598 loc
->objfile
= sal
->objfile
;
8600 set_breakpoint_location_function (loc
);
8602 /* While by definition, permanent breakpoints are already present in the
8603 code, we don't mark the location as inserted. Normally one would expect
8604 that GDB could rely on that breakpoint instruction to stop the program,
8605 thus removing the need to insert its own breakpoint, except that executing
8606 the breakpoint instruction can kill the target instead of reporting a
8607 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8608 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8609 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8610 breakpoint be inserted normally results in QEMU knowing about the GDB
8611 breakpoint, and thus trap before the breakpoint instruction is executed.
8612 (If GDB later needs to continue execution past the permanent breakpoint,
8613 it manually increments the PC, thus avoiding executing the breakpoint
8615 if (bp_loc_is_permanent (loc
))
8622 /* Return true if LOC is pointing to a permanent breakpoint,
8623 return false otherwise. */
8626 bp_loc_is_permanent (struct bp_location
*loc
)
8628 gdb_assert (loc
!= NULL
);
8630 /* If we have a non-breakpoint-backed catchpoint or a software
8631 watchpoint, just return 0. We should not attempt to read from
8632 the addresses the locations of these breakpoint types point to.
8633 gdbarch_program_breakpoint_here_p, below, will attempt to read
8635 if (!bl_address_is_meaningful (loc
))
8638 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8639 switch_to_program_space_and_thread (loc
->pspace
);
8640 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8643 /* Build a command list for the dprintf corresponding to the current
8644 settings of the dprintf style options. */
8647 update_dprintf_command_list (struct breakpoint
*b
)
8649 char *dprintf_args
= b
->extra_string
;
8650 char *printf_line
= NULL
;
8655 dprintf_args
= skip_spaces (dprintf_args
);
8657 /* Allow a comma, as it may have terminated a location, but don't
8659 if (*dprintf_args
== ',')
8661 dprintf_args
= skip_spaces (dprintf_args
);
8663 if (*dprintf_args
!= '"')
8664 error (_("Bad format string, missing '\"'."));
8666 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8667 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8668 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8670 if (!dprintf_function
)
8671 error (_("No function supplied for dprintf call"));
8673 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8674 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8679 printf_line
= xstrprintf ("call (void) %s (%s)",
8683 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8685 if (target_can_run_breakpoint_commands ())
8686 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8689 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8690 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8694 internal_error (__FILE__
, __LINE__
,
8695 _("Invalid dprintf style."));
8697 gdb_assert (printf_line
!= NULL
);
8699 /* Manufacture a printf sequence. */
8700 struct command_line
*printf_cmd_line
8701 = new struct command_line (simple_control
, printf_line
);
8702 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8703 command_lines_deleter ()));
8706 /* Update all dprintf commands, making their command lists reflect
8707 current style settings. */
8710 update_dprintf_commands (const char *args
, int from_tty
,
8711 struct cmd_list_element
*c
)
8713 struct breakpoint
*b
;
8717 if (b
->type
== bp_dprintf
)
8718 update_dprintf_command_list (b
);
8722 /* Create a breakpoint with SAL as location. Use LOCATION
8723 as a description of the location, and COND_STRING
8724 as condition expression. If LOCATION is NULL then create an
8725 "address location" from the address in the SAL. */
8728 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8729 gdb::array_view
<const symtab_and_line
> sals
,
8730 event_location_up
&&location
,
8731 gdb::unique_xmalloc_ptr
<char> filter
,
8732 gdb::unique_xmalloc_ptr
<char> cond_string
,
8733 gdb::unique_xmalloc_ptr
<char> extra_string
,
8734 enum bptype type
, enum bpdisp disposition
,
8735 int thread
, int task
, int ignore_count
,
8736 const struct breakpoint_ops
*ops
, int from_tty
,
8737 int enabled
, int internal
, unsigned flags
,
8738 int display_canonical
)
8742 if (type
== bp_hardware_breakpoint
)
8744 int target_resources_ok
;
8746 i
= hw_breakpoint_used_count ();
8747 target_resources_ok
=
8748 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8750 if (target_resources_ok
== 0)
8751 error (_("No hardware breakpoint support in the target."));
8752 else if (target_resources_ok
< 0)
8753 error (_("Hardware breakpoints used exceeds limit."));
8756 gdb_assert (!sals
.empty ());
8758 for (const auto &sal
: sals
)
8760 struct bp_location
*loc
;
8764 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8766 loc_gdbarch
= gdbarch
;
8768 describe_other_breakpoints (loc_gdbarch
,
8769 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8772 if (&sal
== &sals
[0])
8774 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8778 b
->cond_string
= cond_string
.release ();
8779 b
->extra_string
= extra_string
.release ();
8780 b
->ignore_count
= ignore_count
;
8781 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8782 b
->disposition
= disposition
;
8784 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8785 b
->loc
->inserted
= 1;
8787 if (type
== bp_static_tracepoint
)
8789 struct tracepoint
*t
= (struct tracepoint
*) b
;
8790 struct static_tracepoint_marker marker
;
8792 if (strace_marker_p (b
))
8794 /* We already know the marker exists, otherwise, we
8795 wouldn't see a sal for it. */
8797 = &event_location_to_string (b
->location
.get ())[3];
8800 p
= skip_spaces (p
);
8802 endp
= skip_to_space (p
);
8804 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8806 printf_filtered (_("Probed static tracepoint "
8808 t
->static_trace_marker_id
.c_str ());
8810 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8812 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8814 printf_filtered (_("Probed static tracepoint "
8816 t
->static_trace_marker_id
.c_str ());
8819 warning (_("Couldn't determine the static "
8820 "tracepoint marker to probe"));
8827 loc
= add_location_to_breakpoint (b
, &sal
);
8828 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8834 const char *arg
= b
->cond_string
;
8836 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
8837 block_for_pc (loc
->address
), 0);
8839 error (_("Garbage '%s' follows condition"), arg
);
8842 /* Dynamic printf requires and uses additional arguments on the
8843 command line, otherwise it's an error. */
8844 if (type
== bp_dprintf
)
8846 if (b
->extra_string
)
8847 update_dprintf_command_list (b
);
8849 error (_("Format string required"));
8851 else if (b
->extra_string
)
8852 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8855 b
->display_canonical
= display_canonical
;
8856 if (location
!= NULL
)
8857 b
->location
= std::move (location
);
8859 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8860 b
->filter
= std::move (filter
);
8864 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8865 gdb::array_view
<const symtab_and_line
> sals
,
8866 event_location_up
&&location
,
8867 gdb::unique_xmalloc_ptr
<char> filter
,
8868 gdb::unique_xmalloc_ptr
<char> cond_string
,
8869 gdb::unique_xmalloc_ptr
<char> extra_string
,
8870 enum bptype type
, enum bpdisp disposition
,
8871 int thread
, int task
, int ignore_count
,
8872 const struct breakpoint_ops
*ops
, int from_tty
,
8873 int enabled
, int internal
, unsigned flags
,
8874 int display_canonical
)
8876 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8878 init_breakpoint_sal (b
.get (), gdbarch
,
8879 sals
, std::move (location
),
8881 std::move (cond_string
),
8882 std::move (extra_string
),
8884 thread
, task
, ignore_count
,
8886 enabled
, internal
, flags
,
8889 install_breakpoint (internal
, std::move (b
), 0);
8892 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8893 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8894 value. COND_STRING, if not NULL, specified the condition to be
8895 used for all breakpoints. Essentially the only case where
8896 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8897 function. In that case, it's still not possible to specify
8898 separate conditions for different overloaded functions, so
8899 we take just a single condition string.
8901 NOTE: If the function succeeds, the caller is expected to cleanup
8902 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8903 array contents). If the function fails (error() is called), the
8904 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8905 COND and SALS arrays and each of those arrays contents. */
8908 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8909 struct linespec_result
*canonical
,
8910 gdb::unique_xmalloc_ptr
<char> cond_string
,
8911 gdb::unique_xmalloc_ptr
<char> extra_string
,
8912 enum bptype type
, enum bpdisp disposition
,
8913 int thread
, int task
, int ignore_count
,
8914 const struct breakpoint_ops
*ops
, int from_tty
,
8915 int enabled
, int internal
, unsigned flags
)
8917 if (canonical
->pre_expanded
)
8918 gdb_assert (canonical
->lsals
.size () == 1);
8920 for (const auto &lsal
: canonical
->lsals
)
8922 /* Note that 'location' can be NULL in the case of a plain
8923 'break', without arguments. */
8924 event_location_up location
8925 = (canonical
->location
!= NULL
8926 ? copy_event_location (canonical
->location
.get ()) : NULL
);
8927 gdb::unique_xmalloc_ptr
<char> filter_string
8928 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8930 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8931 std::move (location
),
8932 std::move (filter_string
),
8933 std::move (cond_string
),
8934 std::move (extra_string
),
8936 thread
, task
, ignore_count
, ops
,
8937 from_tty
, enabled
, internal
, flags
,
8938 canonical
->special_display
);
8942 /* Parse LOCATION which is assumed to be a SAL specification possibly
8943 followed by conditionals. On return, SALS contains an array of SAL
8944 addresses found. LOCATION points to the end of the SAL (for
8945 linespec locations).
8947 The array and the line spec strings are allocated on the heap, it is
8948 the caller's responsibility to free them. */
8951 parse_breakpoint_sals (struct event_location
*location
,
8952 struct linespec_result
*canonical
)
8954 struct symtab_and_line cursal
;
8956 if (event_location_type (location
) == LINESPEC_LOCATION
)
8958 const char *spec
= get_linespec_location (location
)->spec_string
;
8962 /* The last displayed codepoint, if it's valid, is our default
8963 breakpoint address. */
8964 if (last_displayed_sal_is_valid ())
8966 /* Set sal's pspace, pc, symtab, and line to the values
8967 corresponding to the last call to print_frame_info.
8968 Be sure to reinitialize LINE with NOTCURRENT == 0
8969 as the breakpoint line number is inappropriate otherwise.
8970 find_pc_line would adjust PC, re-set it back. */
8971 symtab_and_line sal
= get_last_displayed_sal ();
8972 CORE_ADDR pc
= sal
.pc
;
8974 sal
= find_pc_line (pc
, 0);
8976 /* "break" without arguments is equivalent to "break *PC"
8977 where PC is the last displayed codepoint's address. So
8978 make sure to set sal.explicit_pc to prevent GDB from
8979 trying to expand the list of sals to include all other
8980 instances with the same symtab and line. */
8982 sal
.explicit_pc
= 1;
8984 struct linespec_sals lsal
;
8986 lsal
.canonical
= NULL
;
8988 canonical
->lsals
.push_back (std::move (lsal
));
8992 error (_("No default breakpoint address now."));
8996 /* Force almost all breakpoints to be in terms of the
8997 current_source_symtab (which is decode_line_1's default).
8998 This should produce the results we want almost all of the
8999 time while leaving default_breakpoint_* alone.
9001 ObjC: However, don't match an Objective-C method name which
9002 may have a '+' or '-' succeeded by a '['. */
9003 cursal
= get_current_source_symtab_and_line ();
9004 if (last_displayed_sal_is_valid ())
9006 const char *spec
= NULL
;
9008 if (event_location_type (location
) == LINESPEC_LOCATION
)
9009 spec
= get_linespec_location (location
)->spec_string
;
9013 && strchr ("+-", spec
[0]) != NULL
9016 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9017 get_last_displayed_symtab (),
9018 get_last_displayed_line (),
9019 canonical
, NULL
, NULL
);
9024 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9025 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9029 /* Convert each SAL into a real PC. Verify that the PC can be
9030 inserted as a breakpoint. If it can't throw an error. */
9033 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9035 for (auto &sal
: sals
)
9036 resolve_sal_pc (&sal
);
9039 /* Fast tracepoints may have restrictions on valid locations. For
9040 instance, a fast tracepoint using a jump instead of a trap will
9041 likely have to overwrite more bytes than a trap would, and so can
9042 only be placed where the instruction is longer than the jump, or a
9043 multi-instruction sequence does not have a jump into the middle of
9047 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9048 gdb::array_view
<const symtab_and_line
> sals
)
9050 for (const auto &sal
: sals
)
9052 struct gdbarch
*sarch
;
9054 sarch
= get_sal_arch (sal
);
9055 /* We fall back to GDBARCH if there is no architecture
9056 associated with SAL. */
9060 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9061 error (_("May not have a fast tracepoint at %s%s"),
9062 paddress (sarch
, sal
.pc
), msg
.c_str ());
9066 /* Given TOK, a string specification of condition and thread, as
9067 accepted by the 'break' command, extract the condition
9068 string and thread number and set *COND_STRING and *THREAD.
9069 PC identifies the context at which the condition should be parsed.
9070 If no condition is found, *COND_STRING is set to NULL.
9071 If no thread is found, *THREAD is set to -1. */
9074 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9075 char **cond_string
, int *thread
, int *task
,
9078 *cond_string
= NULL
;
9085 const char *end_tok
;
9087 const char *cond_start
= NULL
;
9088 const char *cond_end
= NULL
;
9090 tok
= skip_spaces (tok
);
9092 if ((*tok
== '"' || *tok
== ',') && rest
)
9094 *rest
= savestring (tok
, strlen (tok
));
9098 end_tok
= skip_to_space (tok
);
9100 toklen
= end_tok
- tok
;
9102 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9104 tok
= cond_start
= end_tok
+ 1;
9105 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9107 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9109 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9112 struct thread_info
*thr
;
9115 thr
= parse_thread_id (tok
, &tmptok
);
9117 error (_("Junk after thread keyword."));
9118 *thread
= thr
->global_num
;
9121 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9126 *task
= strtol (tok
, &tmptok
, 0);
9128 error (_("Junk after task keyword."));
9129 if (!valid_task_id (*task
))
9130 error (_("Unknown task %d."), *task
);
9135 *rest
= savestring (tok
, strlen (tok
));
9139 error (_("Junk at end of arguments."));
9143 /* Decode a static tracepoint marker spec. */
9145 static std::vector
<symtab_and_line
>
9146 decode_static_tracepoint_spec (const char **arg_p
)
9148 const char *p
= &(*arg_p
)[3];
9151 p
= skip_spaces (p
);
9153 endp
= skip_to_space (p
);
9155 std::string
marker_str (p
, endp
- p
);
9157 std::vector
<static_tracepoint_marker
> markers
9158 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9159 if (markers
.empty ())
9160 error (_("No known static tracepoint marker named %s"),
9161 marker_str
.c_str ());
9163 std::vector
<symtab_and_line
> sals
;
9164 sals
.reserve (markers
.size ());
9166 for (const static_tracepoint_marker
&marker
: markers
)
9168 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9169 sal
.pc
= marker
.address
;
9170 sals
.push_back (sal
);
9177 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9178 according to IS_TRACEPOINT. */
9180 static const struct breakpoint_ops
*
9181 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
9186 if (location_type
== PROBE_LOCATION
)
9187 return &tracepoint_probe_breakpoint_ops
;
9189 return &tracepoint_breakpoint_ops
;
9193 if (location_type
== PROBE_LOCATION
)
9194 return &bkpt_probe_breakpoint_ops
;
9196 return &bkpt_breakpoint_ops
;
9200 /* See breakpoint.h. */
9202 const struct breakpoint_ops
*
9203 breakpoint_ops_for_event_location (const struct event_location
*location
,
9206 if (location
!= nullptr)
9207 return breakpoint_ops_for_event_location_type
9208 (event_location_type (location
), is_tracepoint
);
9209 return is_tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
9212 /* See breakpoint.h. */
9215 create_breakpoint (struct gdbarch
*gdbarch
,
9216 struct event_location
*location
,
9217 const char *cond_string
,
9218 int thread
, const char *extra_string
,
9220 int tempflag
, enum bptype type_wanted
,
9222 enum auto_boolean pending_break_support
,
9223 const struct breakpoint_ops
*ops
,
9224 int from_tty
, int enabled
, int internal
,
9227 struct linespec_result canonical
;
9230 int prev_bkpt_count
= breakpoint_count
;
9232 gdb_assert (ops
!= NULL
);
9234 /* If extra_string isn't useful, set it to NULL. */
9235 if (extra_string
!= NULL
&& *extra_string
== '\0')
9236 extra_string
= NULL
;
9240 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9242 catch (const gdb_exception_error
&e
)
9244 /* If caller is interested in rc value from parse, set
9246 if (e
.error
== NOT_FOUND_ERROR
)
9248 /* If pending breakpoint support is turned off, throw
9251 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9254 exception_print (gdb_stderr
, e
);
9256 /* If pending breakpoint support is auto query and the user
9257 selects no, then simply return the error code. */
9258 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9259 && !nquery (_("Make %s pending on future shared library load? "),
9260 bptype_string (type_wanted
)))
9263 /* At this point, either the user was queried about setting
9264 a pending breakpoint and selected yes, or pending
9265 breakpoint behavior is on and thus a pending breakpoint
9266 is defaulted on behalf of the user. */
9273 if (!pending
&& canonical
.lsals
.empty ())
9276 /* Resolve all line numbers to PC's and verify that the addresses
9277 are ok for the target. */
9280 for (auto &lsal
: canonical
.lsals
)
9281 breakpoint_sals_to_pc (lsal
.sals
);
9284 /* Fast tracepoints may have additional restrictions on location. */
9285 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9287 for (const auto &lsal
: canonical
.lsals
)
9288 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9291 /* Verify that condition can be parsed, before setting any
9292 breakpoints. Allocate a separate condition expression for each
9296 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9297 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9304 const linespec_sals
&lsal
= canonical
.lsals
[0];
9306 /* Here we only parse 'arg' to separate condition
9307 from thread number, so parsing in context of first
9308 sal is OK. When setting the breakpoint we'll
9309 re-parse it in context of each sal. */
9311 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9312 &cond
, &thread
, &task
, &rest
);
9313 cond_string_copy
.reset (cond
);
9314 extra_string_copy
.reset (rest
);
9318 if (type_wanted
!= bp_dprintf
9319 && extra_string
!= NULL
&& *extra_string
!= '\0')
9320 error (_("Garbage '%s' at end of location"), extra_string
);
9322 /* Create a private copy of condition string. */
9324 cond_string_copy
.reset (xstrdup (cond_string
));
9325 /* Create a private copy of any extra string. */
9327 extra_string_copy
.reset (xstrdup (extra_string
));
9330 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9331 std::move (cond_string_copy
),
9332 std::move (extra_string_copy
),
9334 tempflag
? disp_del
: disp_donttouch
,
9335 thread
, task
, ignore_count
, ops
,
9336 from_tty
, enabled
, internal
, flags
);
9340 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9342 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9343 b
->location
= copy_event_location (location
);
9346 b
->cond_string
= NULL
;
9349 /* Create a private copy of condition string. */
9350 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9354 /* Create a private copy of any extra string. */
9355 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9356 b
->ignore_count
= ignore_count
;
9357 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9358 b
->condition_not_parsed
= 1;
9359 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9360 if ((type_wanted
!= bp_breakpoint
9361 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9362 b
->pspace
= current_program_space
;
9364 install_breakpoint (internal
, std::move (b
), 0);
9367 if (canonical
.lsals
.size () > 1)
9369 warning (_("Multiple breakpoints were set.\nUse the "
9370 "\"delete\" command to delete unwanted breakpoints."));
9371 prev_breakpoint_count
= prev_bkpt_count
;
9374 update_global_location_list (UGLL_MAY_INSERT
);
9379 /* Set a breakpoint.
9380 ARG is a string describing breakpoint address,
9381 condition, and thread.
9382 FLAG specifies if a breakpoint is hardware on,
9383 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9387 break_command_1 (const char *arg
, int flag
, int from_tty
)
9389 int tempflag
= flag
& BP_TEMPFLAG
;
9390 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9391 ? bp_hardware_breakpoint
9394 event_location_up location
= string_to_event_location (&arg
, current_language
);
9395 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9396 (location
.get (), false /* is_tracepoint */);
9398 create_breakpoint (get_current_arch (),
9400 NULL
, 0, arg
, 1 /* parse arg */,
9401 tempflag
, type_wanted
,
9402 0 /* Ignore count */,
9403 pending_break_support
,
9411 /* Helper function for break_command_1 and disassemble_command. */
9414 resolve_sal_pc (struct symtab_and_line
*sal
)
9418 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9420 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9421 error (_("No line %d in file \"%s\"."),
9422 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9425 /* If this SAL corresponds to a breakpoint inserted using a line
9426 number, then skip the function prologue if necessary. */
9427 if (sal
->explicit_line
)
9428 skip_prologue_sal (sal
);
9431 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9433 const struct blockvector
*bv
;
9434 const struct block
*b
;
9437 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9438 SYMTAB_COMPUNIT (sal
->symtab
));
9441 sym
= block_linkage_function (b
);
9444 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9445 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9450 /* It really is worthwhile to have the section, so we'll
9451 just have to look harder. This case can be executed
9452 if we have line numbers but no functions (as can
9453 happen in assembly source). */
9455 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9456 switch_to_program_space_and_thread (sal
->pspace
);
9458 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9460 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9467 break_command (const char *arg
, int from_tty
)
9469 break_command_1 (arg
, 0, from_tty
);
9473 tbreak_command (const char *arg
, int from_tty
)
9475 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9479 hbreak_command (const char *arg
, int from_tty
)
9481 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9485 thbreak_command (const char *arg
, int from_tty
)
9487 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9491 stop_command (const char *arg
, int from_tty
)
9493 printf_filtered (_("Specify the type of breakpoint to set.\n\
9494 Usage: stop in <function | address>\n\
9495 stop at <line>\n"));
9499 stopin_command (const char *arg
, int from_tty
)
9505 else if (*arg
!= '*')
9507 const char *argptr
= arg
;
9510 /* Look for a ':'. If this is a line number specification, then
9511 say it is bad, otherwise, it should be an address or
9512 function/method name. */
9513 while (*argptr
&& !hasColon
)
9515 hasColon
= (*argptr
== ':');
9520 badInput
= (*argptr
!= ':'); /* Not a class::method */
9522 badInput
= isdigit (*arg
); /* a simple line number */
9526 printf_filtered (_("Usage: stop in <function | address>\n"));
9528 break_command_1 (arg
, 0, from_tty
);
9532 stopat_command (const char *arg
, int from_tty
)
9536 if (arg
== NULL
|| *arg
== '*') /* no line number */
9540 const char *argptr
= arg
;
9543 /* Look for a ':'. If there is a '::' then get out, otherwise
9544 it is probably a line number. */
9545 while (*argptr
&& !hasColon
)
9547 hasColon
= (*argptr
== ':');
9552 badInput
= (*argptr
== ':'); /* we have class::method */
9554 badInput
= !isdigit (*arg
); /* not a line number */
9558 printf_filtered (_("Usage: stop at LINE\n"));
9560 break_command_1 (arg
, 0, from_tty
);
9563 /* The dynamic printf command is mostly like a regular breakpoint, but
9564 with a prewired command list consisting of a single output command,
9565 built from extra arguments supplied on the dprintf command
9569 dprintf_command (const char *arg
, int from_tty
)
9571 event_location_up location
= string_to_event_location (&arg
, current_language
);
9573 /* If non-NULL, ARG should have been advanced past the location;
9574 the next character must be ','. */
9577 if (arg
[0] != ',' || arg
[1] == '\0')
9578 error (_("Format string required"));
9581 /* Skip the comma. */
9586 create_breakpoint (get_current_arch (),
9588 NULL
, 0, arg
, 1 /* parse arg */,
9590 0 /* Ignore count */,
9591 pending_break_support
,
9592 &dprintf_breakpoint_ops
,
9600 agent_printf_command (const char *arg
, int from_tty
)
9602 error (_("May only run agent-printf on the target"));
9605 /* Implement the "breakpoint_hit" breakpoint_ops method for
9606 ranged breakpoints. */
9609 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9610 const address_space
*aspace
,
9612 const struct target_waitstatus
*ws
)
9614 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9615 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9618 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9619 bl
->length
, aspace
, bp_addr
);
9622 /* Implement the "resources_needed" breakpoint_ops method for
9623 ranged breakpoints. */
9626 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9628 return target_ranged_break_num_registers ();
9631 /* Implement the "print_it" breakpoint_ops method for
9632 ranged breakpoints. */
9634 static enum print_stop_action
9635 print_it_ranged_breakpoint (bpstat bs
)
9637 struct breakpoint
*b
= bs
->breakpoint_at
;
9638 struct bp_location
*bl
= b
->loc
;
9639 struct ui_out
*uiout
= current_uiout
;
9641 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9643 /* Ranged breakpoints have only one location. */
9644 gdb_assert (bl
&& bl
->next
== NULL
);
9646 annotate_breakpoint (b
->number
);
9648 maybe_print_thread_hit_breakpoint (uiout
);
9650 if (b
->disposition
== disp_del
)
9651 uiout
->text ("Temporary ranged breakpoint ");
9653 uiout
->text ("Ranged breakpoint ");
9654 if (uiout
->is_mi_like_p ())
9656 uiout
->field_string ("reason",
9657 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9658 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9660 uiout
->field_signed ("bkptno", b
->number
);
9663 return PRINT_SRC_AND_LOC
;
9666 /* Implement the "print_one" breakpoint_ops method for
9667 ranged breakpoints. */
9670 print_one_ranged_breakpoint (struct breakpoint
*b
,
9671 struct bp_location
**last_loc
)
9673 struct bp_location
*bl
= b
->loc
;
9674 struct value_print_options opts
;
9675 struct ui_out
*uiout
= current_uiout
;
9677 /* Ranged breakpoints have only one location. */
9678 gdb_assert (bl
&& bl
->next
== NULL
);
9680 get_user_print_options (&opts
);
9682 if (opts
.addressprint
)
9683 /* We don't print the address range here, it will be printed later
9684 by print_one_detail_ranged_breakpoint. */
9685 uiout
->field_skip ("addr");
9687 print_breakpoint_location (b
, bl
);
9691 /* Implement the "print_one_detail" breakpoint_ops method for
9692 ranged breakpoints. */
9695 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9696 struct ui_out
*uiout
)
9698 CORE_ADDR address_start
, address_end
;
9699 struct bp_location
*bl
= b
->loc
;
9704 address_start
= bl
->address
;
9705 address_end
= address_start
+ bl
->length
- 1;
9707 uiout
->text ("\taddress range: ");
9708 stb
.printf ("[%s, %s]",
9709 print_core_address (bl
->gdbarch
, address_start
),
9710 print_core_address (bl
->gdbarch
, address_end
));
9711 uiout
->field_stream ("addr", stb
);
9715 /* Implement the "print_mention" breakpoint_ops method for
9716 ranged breakpoints. */
9719 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9721 struct bp_location
*bl
= b
->loc
;
9722 struct ui_out
*uiout
= current_uiout
;
9725 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9727 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9728 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9729 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9732 /* Implement the "print_recreate" breakpoint_ops method for
9733 ranged breakpoints. */
9736 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9738 fprintf_unfiltered (fp
, "break-range %s, %s",
9739 event_location_to_string (b
->location
.get ()),
9740 event_location_to_string (b
->location_range_end
.get ()));
9741 print_recreate_thread (b
, fp
);
9744 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9746 static struct breakpoint_ops ranged_breakpoint_ops
;
9748 /* Find the address where the end of the breakpoint range should be
9749 placed, given the SAL of the end of the range. This is so that if
9750 the user provides a line number, the end of the range is set to the
9751 last instruction of the given line. */
9754 find_breakpoint_range_end (struct symtab_and_line sal
)
9758 /* If the user provided a PC value, use it. Otherwise,
9759 find the address of the end of the given location. */
9760 if (sal
.explicit_pc
)
9767 ret
= find_line_pc_range (sal
, &start
, &end
);
9769 error (_("Could not find location of the end of the range."));
9771 /* find_line_pc_range returns the start of the next line. */
9778 /* Implement the "break-range" CLI command. */
9781 break_range_command (const char *arg
, int from_tty
)
9783 const char *arg_start
;
9784 struct linespec_result canonical_start
, canonical_end
;
9785 int bp_count
, can_use_bp
, length
;
9787 struct breakpoint
*b
;
9789 /* We don't support software ranged breakpoints. */
9790 if (target_ranged_break_num_registers () < 0)
9791 error (_("This target does not support hardware ranged breakpoints."));
9793 bp_count
= hw_breakpoint_used_count ();
9794 bp_count
+= target_ranged_break_num_registers ();
9795 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9798 error (_("Hardware breakpoints used exceeds limit."));
9800 arg
= skip_spaces (arg
);
9801 if (arg
== NULL
|| arg
[0] == '\0')
9802 error(_("No address range specified."));
9805 event_location_up start_location
= string_to_event_location (&arg
,
9807 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9810 error (_("Too few arguments."));
9811 else if (canonical_start
.lsals
.empty ())
9812 error (_("Could not find location of the beginning of the range."));
9814 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9816 if (canonical_start
.lsals
.size () > 1
9817 || lsal_start
.sals
.size () != 1)
9818 error (_("Cannot create a ranged breakpoint with multiple locations."));
9820 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9821 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9823 arg
++; /* Skip the comma. */
9824 arg
= skip_spaces (arg
);
9826 /* Parse the end location. */
9830 /* We call decode_line_full directly here instead of using
9831 parse_breakpoint_sals because we need to specify the start location's
9832 symtab and line as the default symtab and line for the end of the
9833 range. This makes it possible to have ranges like "foo.c:27, +14",
9834 where +14 means 14 lines from the start location. */
9835 event_location_up end_location
= string_to_event_location (&arg
,
9837 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9838 sal_start
.symtab
, sal_start
.line
,
9839 &canonical_end
, NULL
, NULL
);
9841 if (canonical_end
.lsals
.empty ())
9842 error (_("Could not find location of the end of the range."));
9844 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9845 if (canonical_end
.lsals
.size () > 1
9846 || lsal_end
.sals
.size () != 1)
9847 error (_("Cannot create a ranged breakpoint with multiple locations."));
9849 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9851 end
= find_breakpoint_range_end (sal_end
);
9852 if (sal_start
.pc
> end
)
9853 error (_("Invalid address range, end precedes start."));
9855 length
= end
- sal_start
.pc
+ 1;
9857 /* Length overflowed. */
9858 error (_("Address range too large."));
9859 else if (length
== 1)
9861 /* This range is simple enough to be handled by
9862 the `hbreak' command. */
9863 hbreak_command (&addr_string_start
[0], 1);
9868 /* Now set up the breakpoint. */
9869 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9870 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9871 set_breakpoint_count (breakpoint_count
+ 1);
9872 b
->number
= breakpoint_count
;
9873 b
->disposition
= disp_donttouch
;
9874 b
->location
= std::move (start_location
);
9875 b
->location_range_end
= std::move (end_location
);
9876 b
->loc
->length
= length
;
9879 gdb::observers::breakpoint_created
.notify (b
);
9880 update_global_location_list (UGLL_MAY_INSERT
);
9883 /* Return non-zero if EXP is verified as constant. Returned zero
9884 means EXP is variable. Also the constant detection may fail for
9885 some constant expressions and in such case still falsely return
9889 watchpoint_exp_is_const (const struct expression
*exp
)
9897 /* We are only interested in the descriptor of each element. */
9898 operator_length (exp
, i
, &oplenp
, &argsp
);
9901 switch (exp
->elts
[i
].opcode
)
9911 case BINOP_LOGICAL_AND
:
9912 case BINOP_LOGICAL_OR
:
9913 case BINOP_BITWISE_AND
:
9914 case BINOP_BITWISE_IOR
:
9915 case BINOP_BITWISE_XOR
:
9917 case BINOP_NOTEQUAL
:
9943 case OP_OBJC_NSSTRING
:
9946 case UNOP_LOGICAL_NOT
:
9947 case UNOP_COMPLEMENT
:
9952 case UNOP_CAST_TYPE
:
9953 case UNOP_REINTERPRET_CAST
:
9954 case UNOP_DYNAMIC_CAST
:
9955 /* Unary, binary and ternary operators: We have to check
9956 their operands. If they are constant, then so is the
9957 result of that operation. For instance, if A and B are
9958 determined to be constants, then so is "A + B".
9960 UNOP_IND is one exception to the rule above, because the
9961 value of *ADDR is not necessarily a constant, even when
9966 /* Check whether the associated symbol is a constant.
9968 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9969 possible that a buggy compiler could mark a variable as
9970 constant even when it is not, and TYPE_CONST would return
9971 true in this case, while SYMBOL_CLASS wouldn't.
9973 We also have to check for function symbols because they
9974 are always constant. */
9976 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
9978 if (SYMBOL_CLASS (s
) != LOC_BLOCK
9979 && SYMBOL_CLASS (s
) != LOC_CONST
9980 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
9985 /* The default action is to return 0 because we are using
9986 the optimistic approach here: If we don't know something,
9987 then it is not a constant. */
9996 /* Watchpoint destructor. */
9998 watchpoint::~watchpoint ()
10000 xfree (this->exp_string
);
10001 xfree (this->exp_string_reparse
);
10004 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10007 re_set_watchpoint (struct breakpoint
*b
)
10009 struct watchpoint
*w
= (struct watchpoint
*) b
;
10011 /* Watchpoint can be either on expression using entirely global
10012 variables, or it can be on local variables.
10014 Watchpoints of the first kind are never auto-deleted, and even
10015 persist across program restarts. Since they can use variables
10016 from shared libraries, we need to reparse expression as libraries
10017 are loaded and unloaded.
10019 Watchpoints on local variables can also change meaning as result
10020 of solib event. For example, if a watchpoint uses both a local
10021 and a global variables in expression, it's a local watchpoint,
10022 but unloading of a shared library will make the expression
10023 invalid. This is not a very common use case, but we still
10024 re-evaluate expression, to avoid surprises to the user.
10026 Note that for local watchpoints, we re-evaluate it only if
10027 watchpoints frame id is still valid. If it's not, it means the
10028 watchpoint is out of scope and will be deleted soon. In fact,
10029 I'm not sure we'll ever be called in this case.
10031 If a local watchpoint's frame id is still valid, then
10032 w->exp_valid_block is likewise valid, and we can safely use it.
10034 Don't do anything about disabled watchpoints, since they will be
10035 reevaluated again when enabled. */
10036 update_watchpoint (w
, 1 /* reparse */);
10039 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10042 insert_watchpoint (struct bp_location
*bl
)
10044 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10045 int length
= w
->exact
? 1 : bl
->length
;
10047 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10048 w
->cond_exp
.get ());
10051 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10054 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10056 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10057 int length
= w
->exact
? 1 : bl
->length
;
10059 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10060 w
->cond_exp
.get ());
10064 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10065 const address_space
*aspace
, CORE_ADDR bp_addr
,
10066 const struct target_waitstatus
*ws
)
10068 struct breakpoint
*b
= bl
->owner
;
10069 struct watchpoint
*w
= (struct watchpoint
*) b
;
10071 /* Continuable hardware watchpoints are treated as non-existent if the
10072 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10073 some data address). Otherwise gdb won't stop on a break instruction
10074 in the code (not from a breakpoint) when a hardware watchpoint has
10075 been defined. Also skip watchpoints which we know did not trigger
10076 (did not match the data address). */
10077 if (is_hardware_watchpoint (b
)
10078 && w
->watchpoint_triggered
== watch_triggered_no
)
10085 check_status_watchpoint (bpstat bs
)
10087 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10089 bpstat_check_watchpoint (bs
);
10092 /* Implement the "resources_needed" breakpoint_ops method for
10093 hardware watchpoints. */
10096 resources_needed_watchpoint (const struct bp_location
*bl
)
10098 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10099 int length
= w
->exact
? 1 : bl
->length
;
10101 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10104 /* Implement the "works_in_software_mode" breakpoint_ops method for
10105 hardware watchpoints. */
10108 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10110 /* Read and access watchpoints only work with hardware support. */
10111 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10114 static enum print_stop_action
10115 print_it_watchpoint (bpstat bs
)
10117 struct breakpoint
*b
;
10118 enum print_stop_action result
;
10119 struct watchpoint
*w
;
10120 struct ui_out
*uiout
= current_uiout
;
10122 gdb_assert (bs
->bp_location_at
!= NULL
);
10124 b
= bs
->breakpoint_at
;
10125 w
= (struct watchpoint
*) b
;
10127 annotate_watchpoint (b
->number
);
10128 maybe_print_thread_hit_breakpoint (uiout
);
10132 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10135 case bp_watchpoint
:
10136 case bp_hardware_watchpoint
:
10137 if (uiout
->is_mi_like_p ())
10138 uiout
->field_string
10139 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10141 tuple_emitter
.emplace (uiout
, "value");
10142 uiout
->text ("\nOld value = ");
10143 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10144 uiout
->field_stream ("old", stb
);
10145 uiout
->text ("\nNew value = ");
10146 watchpoint_value_print (w
->val
.get (), &stb
);
10147 uiout
->field_stream ("new", stb
);
10148 uiout
->text ("\n");
10149 /* More than one watchpoint may have been triggered. */
10150 result
= PRINT_UNKNOWN
;
10153 case bp_read_watchpoint
:
10154 if (uiout
->is_mi_like_p ())
10155 uiout
->field_string
10156 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10158 tuple_emitter
.emplace (uiout
, "value");
10159 uiout
->text ("\nValue = ");
10160 watchpoint_value_print (w
->val
.get (), &stb
);
10161 uiout
->field_stream ("value", stb
);
10162 uiout
->text ("\n");
10163 result
= PRINT_UNKNOWN
;
10166 case bp_access_watchpoint
:
10167 if (bs
->old_val
!= NULL
)
10169 if (uiout
->is_mi_like_p ())
10170 uiout
->field_string
10172 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10174 tuple_emitter
.emplace (uiout
, "value");
10175 uiout
->text ("\nOld value = ");
10176 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10177 uiout
->field_stream ("old", stb
);
10178 uiout
->text ("\nNew value = ");
10183 if (uiout
->is_mi_like_p ())
10184 uiout
->field_string
10186 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10187 tuple_emitter
.emplace (uiout
, "value");
10188 uiout
->text ("\nValue = ");
10190 watchpoint_value_print (w
->val
.get (), &stb
);
10191 uiout
->field_stream ("new", stb
);
10192 uiout
->text ("\n");
10193 result
= PRINT_UNKNOWN
;
10196 result
= PRINT_UNKNOWN
;
10202 /* Implement the "print_mention" breakpoint_ops method for hardware
10206 print_mention_watchpoint (struct breakpoint
*b
)
10208 struct watchpoint
*w
= (struct watchpoint
*) b
;
10209 struct ui_out
*uiout
= current_uiout
;
10210 const char *tuple_name
;
10214 case bp_watchpoint
:
10215 uiout
->text ("Watchpoint ");
10216 tuple_name
= "wpt";
10218 case bp_hardware_watchpoint
:
10219 uiout
->text ("Hardware watchpoint ");
10220 tuple_name
= "wpt";
10222 case bp_read_watchpoint
:
10223 uiout
->text ("Hardware read watchpoint ");
10224 tuple_name
= "hw-rwpt";
10226 case bp_access_watchpoint
:
10227 uiout
->text ("Hardware access (read/write) watchpoint ");
10228 tuple_name
= "hw-awpt";
10231 internal_error (__FILE__
, __LINE__
,
10232 _("Invalid hardware watchpoint type."));
10235 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10236 uiout
->field_signed ("number", b
->number
);
10237 uiout
->text (": ");
10238 uiout
->field_string ("exp", w
->exp_string
);
10241 /* Implement the "print_recreate" breakpoint_ops method for
10245 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10247 struct watchpoint
*w
= (struct watchpoint
*) b
;
10251 case bp_watchpoint
:
10252 case bp_hardware_watchpoint
:
10253 fprintf_unfiltered (fp
, "watch");
10255 case bp_read_watchpoint
:
10256 fprintf_unfiltered (fp
, "rwatch");
10258 case bp_access_watchpoint
:
10259 fprintf_unfiltered (fp
, "awatch");
10262 internal_error (__FILE__
, __LINE__
,
10263 _("Invalid watchpoint type."));
10266 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10267 print_recreate_thread (b
, fp
);
10270 /* Implement the "explains_signal" breakpoint_ops method for
10274 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10276 /* A software watchpoint cannot cause a signal other than
10277 GDB_SIGNAL_TRAP. */
10278 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10284 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10286 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10288 /* Implement the "insert" breakpoint_ops method for
10289 masked hardware watchpoints. */
10292 insert_masked_watchpoint (struct bp_location
*bl
)
10294 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10296 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10297 bl
->watchpoint_type
);
10300 /* Implement the "remove" breakpoint_ops method for
10301 masked hardware watchpoints. */
10304 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10306 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10308 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10309 bl
->watchpoint_type
);
10312 /* Implement the "resources_needed" breakpoint_ops method for
10313 masked hardware watchpoints. */
10316 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10318 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10320 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10323 /* Implement the "works_in_software_mode" breakpoint_ops method for
10324 masked hardware watchpoints. */
10327 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10332 /* Implement the "print_it" breakpoint_ops method for
10333 masked hardware watchpoints. */
10335 static enum print_stop_action
10336 print_it_masked_watchpoint (bpstat bs
)
10338 struct breakpoint
*b
= bs
->breakpoint_at
;
10339 struct ui_out
*uiout
= current_uiout
;
10341 /* Masked watchpoints have only one location. */
10342 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10344 annotate_watchpoint (b
->number
);
10345 maybe_print_thread_hit_breakpoint (uiout
);
10349 case bp_hardware_watchpoint
:
10350 if (uiout
->is_mi_like_p ())
10351 uiout
->field_string
10352 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10355 case bp_read_watchpoint
:
10356 if (uiout
->is_mi_like_p ())
10357 uiout
->field_string
10358 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10361 case bp_access_watchpoint
:
10362 if (uiout
->is_mi_like_p ())
10363 uiout
->field_string
10365 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10368 internal_error (__FILE__
, __LINE__
,
10369 _("Invalid hardware watchpoint type."));
10373 uiout
->text (_("\n\
10374 Check the underlying instruction at PC for the memory\n\
10375 address and value which triggered this watchpoint.\n"));
10376 uiout
->text ("\n");
10378 /* More than one watchpoint may have been triggered. */
10379 return PRINT_UNKNOWN
;
10382 /* Implement the "print_one_detail" breakpoint_ops method for
10383 masked hardware watchpoints. */
10386 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10387 struct ui_out
*uiout
)
10389 struct watchpoint
*w
= (struct watchpoint
*) b
;
10391 /* Masked watchpoints have only one location. */
10392 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10394 uiout
->text ("\tmask ");
10395 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10396 uiout
->text ("\n");
10399 /* Implement the "print_mention" breakpoint_ops method for
10400 masked hardware watchpoints. */
10403 print_mention_masked_watchpoint (struct breakpoint
*b
)
10405 struct watchpoint
*w
= (struct watchpoint
*) b
;
10406 struct ui_out
*uiout
= current_uiout
;
10407 const char *tuple_name
;
10411 case bp_hardware_watchpoint
:
10412 uiout
->text ("Masked hardware watchpoint ");
10413 tuple_name
= "wpt";
10415 case bp_read_watchpoint
:
10416 uiout
->text ("Masked hardware read watchpoint ");
10417 tuple_name
= "hw-rwpt";
10419 case bp_access_watchpoint
:
10420 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10421 tuple_name
= "hw-awpt";
10424 internal_error (__FILE__
, __LINE__
,
10425 _("Invalid hardware watchpoint type."));
10428 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10429 uiout
->field_signed ("number", b
->number
);
10430 uiout
->text (": ");
10431 uiout
->field_string ("exp", w
->exp_string
);
10434 /* Implement the "print_recreate" breakpoint_ops method for
10435 masked hardware watchpoints. */
10438 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10440 struct watchpoint
*w
= (struct watchpoint
*) b
;
10444 case bp_hardware_watchpoint
:
10445 fprintf_unfiltered (fp
, "watch");
10447 case bp_read_watchpoint
:
10448 fprintf_unfiltered (fp
, "rwatch");
10450 case bp_access_watchpoint
:
10451 fprintf_unfiltered (fp
, "awatch");
10454 internal_error (__FILE__
, __LINE__
,
10455 _("Invalid hardware watchpoint type."));
10458 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
,
10459 phex (w
->hw_wp_mask
, sizeof (CORE_ADDR
)));
10460 print_recreate_thread (b
, fp
);
10463 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10465 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10467 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10470 is_masked_watchpoint (const struct breakpoint
*b
)
10472 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10475 /* accessflag: hw_write: watch write,
10476 hw_read: watch read,
10477 hw_access: watch access (read or write) */
10479 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10480 int just_location
, int internal
)
10482 struct breakpoint
*scope_breakpoint
= NULL
;
10483 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10484 struct value
*result
;
10485 int saved_bitpos
= 0, saved_bitsize
= 0;
10486 const char *exp_start
= NULL
;
10487 const char *exp_end
= NULL
;
10488 const char *tok
, *end_tok
;
10490 const char *cond_start
= NULL
;
10491 const char *cond_end
= NULL
;
10492 enum bptype bp_type
;
10495 /* Flag to indicate whether we are going to use masks for
10496 the hardware watchpoint. */
10498 CORE_ADDR mask
= 0;
10500 /* Make sure that we actually have parameters to parse. */
10501 if (arg
!= NULL
&& arg
[0] != '\0')
10503 const char *value_start
;
10505 exp_end
= arg
+ strlen (arg
);
10507 /* Look for "parameter value" pairs at the end
10508 of the arguments string. */
10509 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10511 /* Skip whitespace at the end of the argument list. */
10512 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10515 /* Find the beginning of the last token.
10516 This is the value of the parameter. */
10517 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10519 value_start
= tok
+ 1;
10521 /* Skip whitespace. */
10522 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10527 /* Find the beginning of the second to last token.
10528 This is the parameter itself. */
10529 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10532 toklen
= end_tok
- tok
+ 1;
10534 if (toklen
== 6 && startswith (tok
, "thread"))
10536 struct thread_info
*thr
;
10537 /* At this point we've found a "thread" token, which means
10538 the user is trying to set a watchpoint that triggers
10539 only in a specific thread. */
10543 error(_("You can specify only one thread."));
10545 /* Extract the thread ID from the next token. */
10546 thr
= parse_thread_id (value_start
, &endp
);
10548 /* Check if the user provided a valid thread ID. */
10549 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10550 invalid_thread_id_error (value_start
);
10552 thread
= thr
->global_num
;
10554 else if (toklen
== 4 && startswith (tok
, "mask"))
10556 /* We've found a "mask" token, which means the user wants to
10557 create a hardware watchpoint that is going to have the mask
10559 struct value
*mask_value
, *mark
;
10562 error(_("You can specify only one mask."));
10564 use_mask
= just_location
= 1;
10566 mark
= value_mark ();
10567 mask_value
= parse_to_comma_and_eval (&value_start
);
10568 mask
= value_as_address (mask_value
);
10569 value_free_to_mark (mark
);
10572 /* We didn't recognize what we found. We should stop here. */
10575 /* Truncate the string and get rid of the "parameter value" pair before
10576 the arguments string is parsed by the parse_exp_1 function. */
10583 /* Parse the rest of the arguments. From here on out, everything
10584 is in terms of a newly allocated string instead of the original
10586 std::string
expression (arg
, exp_end
- arg
);
10587 exp_start
= arg
= expression
.c_str ();
10588 innermost_block_tracker tracker
;
10589 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10591 /* Remove trailing whitespace from the expression before saving it.
10592 This makes the eventual display of the expression string a bit
10594 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10597 /* Checking if the expression is not constant. */
10598 if (watchpoint_exp_is_const (exp
.get ()))
10602 len
= exp_end
- exp_start
;
10603 while (len
> 0 && isspace (exp_start
[len
- 1]))
10605 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10608 exp_valid_block
= tracker
.block ();
10609 struct value
*mark
= value_mark ();
10610 struct value
*val_as_value
= nullptr;
10611 fetch_subexp_value (exp
.get (), &pc
, &val_as_value
, &result
, NULL
,
10614 if (val_as_value
!= NULL
&& just_location
)
10616 saved_bitpos
= value_bitpos (val_as_value
);
10617 saved_bitsize
= value_bitsize (val_as_value
);
10625 exp_valid_block
= NULL
;
10626 val
= release_value (value_addr (result
));
10627 value_free_to_mark (mark
);
10631 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10634 error (_("This target does not support masked watchpoints."));
10635 else if (ret
== -2)
10636 error (_("Invalid mask or memory region."));
10639 else if (val_as_value
!= NULL
)
10640 val
= release_value (val_as_value
);
10642 tok
= skip_spaces (arg
);
10643 end_tok
= skip_to_space (tok
);
10645 toklen
= end_tok
- tok
;
10646 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10648 tok
= cond_start
= end_tok
+ 1;
10649 innermost_block_tracker if_tracker
;
10650 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10652 /* The watchpoint expression may not be local, but the condition
10653 may still be. E.g.: `watch global if local > 0'. */
10654 cond_exp_valid_block
= if_tracker
.block ();
10659 error (_("Junk at end of command."));
10661 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10663 /* Save this because create_internal_breakpoint below invalidates
10665 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10667 /* If the expression is "local", then set up a "watchpoint scope"
10668 breakpoint at the point where we've left the scope of the watchpoint
10669 expression. Create the scope breakpoint before the watchpoint, so
10670 that we will encounter it first in bpstat_stop_status. */
10671 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10673 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10675 if (frame_id_p (caller_frame_id
))
10677 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10678 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10681 = create_internal_breakpoint (caller_arch
, caller_pc
,
10682 bp_watchpoint_scope
,
10683 &momentary_breakpoint_ops
);
10685 /* create_internal_breakpoint could invalidate WP_FRAME. */
10688 scope_breakpoint
->enable_state
= bp_enabled
;
10690 /* Automatically delete the breakpoint when it hits. */
10691 scope_breakpoint
->disposition
= disp_del
;
10693 /* Only break in the proper frame (help with recursion). */
10694 scope_breakpoint
->frame_id
= caller_frame_id
;
10696 /* Set the address at which we will stop. */
10697 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10698 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10699 scope_breakpoint
->loc
->address
10700 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10701 scope_breakpoint
->loc
->requested_address
,
10702 scope_breakpoint
->type
);
10706 /* Now set up the breakpoint. We create all watchpoints as hardware
10707 watchpoints here even if hardware watchpoints are turned off, a call
10708 to update_watchpoint later in this function will cause the type to
10709 drop back to bp_watchpoint (software watchpoint) if required. */
10711 if (accessflag
== hw_read
)
10712 bp_type
= bp_read_watchpoint
;
10713 else if (accessflag
== hw_access
)
10714 bp_type
= bp_access_watchpoint
;
10716 bp_type
= bp_hardware_watchpoint
;
10718 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10721 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10722 &masked_watchpoint_breakpoint_ops
);
10724 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10725 &watchpoint_breakpoint_ops
);
10726 w
->thread
= thread
;
10727 w
->disposition
= disp_donttouch
;
10728 w
->pspace
= current_program_space
;
10729 w
->exp
= std::move (exp
);
10730 w
->exp_valid_block
= exp_valid_block
;
10731 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10734 struct type
*t
= value_type (val
.get ());
10735 CORE_ADDR addr
= value_as_address (val
.get ());
10737 w
->exp_string_reparse
10738 = current_language
->watch_location_expression (t
, addr
).release ();
10740 w
->exp_string
= xstrprintf ("-location %.*s",
10741 (int) (exp_end
- exp_start
), exp_start
);
10744 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10748 w
->hw_wp_mask
= mask
;
10753 w
->val_bitpos
= saved_bitpos
;
10754 w
->val_bitsize
= saved_bitsize
;
10755 w
->val_valid
= true;
10759 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10761 w
->cond_string
= 0;
10763 if (frame_id_p (watchpoint_frame
))
10765 w
->watchpoint_frame
= watchpoint_frame
;
10766 w
->watchpoint_thread
= inferior_ptid
;
10770 w
->watchpoint_frame
= null_frame_id
;
10771 w
->watchpoint_thread
= null_ptid
;
10774 if (scope_breakpoint
!= NULL
)
10776 /* The scope breakpoint is related to the watchpoint. We will
10777 need to act on them together. */
10778 w
->related_breakpoint
= scope_breakpoint
;
10779 scope_breakpoint
->related_breakpoint
= w
.get ();
10782 if (!just_location
)
10783 value_free_to_mark (mark
);
10785 /* Finally update the new watchpoint. This creates the locations
10786 that should be inserted. */
10787 update_watchpoint (w
.get (), 1);
10789 install_breakpoint (internal
, std::move (w
), 1);
10792 /* Return count of debug registers needed to watch the given expression.
10793 If the watchpoint cannot be handled in hardware return zero. */
10796 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10798 int found_memory_cnt
= 0;
10800 /* Did the user specifically forbid us to use hardware watchpoints? */
10801 if (!can_use_hw_watchpoints
)
10804 gdb_assert (!vals
.empty ());
10805 struct value
*head
= vals
[0].get ();
10807 /* Make sure that the value of the expression depends only upon
10808 memory contents, and values computed from them within GDB. If we
10809 find any register references or function calls, we can't use a
10810 hardware watchpoint.
10812 The idea here is that evaluating an expression generates a series
10813 of values, one holding the value of every subexpression. (The
10814 expression a*b+c has five subexpressions: a, b, a*b, c, and
10815 a*b+c.) GDB's values hold almost enough information to establish
10816 the criteria given above --- they identify memory lvalues,
10817 register lvalues, computed values, etcetera. So we can evaluate
10818 the expression, and then scan the chain of values that leaves
10819 behind to decide whether we can detect any possible change to the
10820 expression's final value using only hardware watchpoints.
10822 However, I don't think that the values returned by inferior
10823 function calls are special in any way. So this function may not
10824 notice that an expression involving an inferior function call
10825 can't be watched with hardware watchpoints. FIXME. */
10826 for (const value_ref_ptr
&iter
: vals
)
10828 struct value
*v
= iter
.get ();
10830 if (VALUE_LVAL (v
) == lval_memory
)
10832 if (v
!= head
&& value_lazy (v
))
10833 /* A lazy memory lvalue in the chain is one that GDB never
10834 needed to fetch; we either just used its address (e.g.,
10835 `a' in `a.b') or we never needed it at all (e.g., `a'
10836 in `a,b'). This doesn't apply to HEAD; if that is
10837 lazy then it was not readable, but watch it anyway. */
10841 /* Ahh, memory we actually used! Check if we can cover
10842 it with hardware watchpoints. */
10843 struct type
*vtype
= check_typedef (value_type (v
));
10845 /* We only watch structs and arrays if user asked for it
10846 explicitly, never if they just happen to appear in a
10847 middle of some value chain. */
10849 || (vtype
->code () != TYPE_CODE_STRUCT
10850 && vtype
->code () != TYPE_CODE_ARRAY
))
10852 CORE_ADDR vaddr
= value_address (v
);
10856 len
= (target_exact_watchpoints
10857 && is_scalar_type_recursive (vtype
))?
10858 1 : TYPE_LENGTH (value_type (v
));
10860 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10864 found_memory_cnt
+= num_regs
;
10868 else if (VALUE_LVAL (v
) != not_lval
10869 && deprecated_value_modifiable (v
) == 0)
10870 return 0; /* These are values from the history (e.g., $1). */
10871 else if (VALUE_LVAL (v
) == lval_register
)
10872 return 0; /* Cannot watch a register with a HW watchpoint. */
10875 /* The expression itself looks suitable for using a hardware
10876 watchpoint, but give the target machine a chance to reject it. */
10877 return found_memory_cnt
;
10881 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10883 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10886 /* A helper function that looks for the "-location" argument and then
10887 calls watch_command_1. */
10890 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10892 int just_location
= 0;
10895 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
10896 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
10899 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
10903 watch_command (const char *arg
, int from_tty
)
10905 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10909 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10911 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10915 rwatch_command (const char *arg
, int from_tty
)
10917 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10921 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10923 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10927 awatch_command (const char *arg
, int from_tty
)
10929 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10933 /* Data for the FSM that manages the until(location)/advance commands
10934 in infcmd.c. Here because it uses the mechanisms of
10937 struct until_break_fsm
: public thread_fsm
10939 /* The thread that was current when the command was executed. */
10942 /* The breakpoint set at the return address in the caller frame,
10943 plus breakpoints at all the destination locations. */
10944 std::vector
<breakpoint_up
> breakpoints
;
10946 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10947 std::vector
<breakpoint_up
> &&breakpoints
)
10948 : thread_fsm (cmd_interp
),
10950 breakpoints (std::move (breakpoints
))
10954 void clean_up (struct thread_info
*thread
) override
;
10955 bool should_stop (struct thread_info
*thread
) override
;
10956 enum async_reply_reason
do_async_reply_reason () override
;
10959 /* Implementation of the 'should_stop' FSM method for the
10960 until(location)/advance commands. */
10963 until_break_fsm::should_stop (struct thread_info
*tp
)
10965 for (const breakpoint_up
&bp
: breakpoints
)
10966 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10967 bp
.get ()) != NULL
)
10976 /* Implementation of the 'clean_up' FSM method for the
10977 until(location)/advance commands. */
10980 until_break_fsm::clean_up (struct thread_info
*)
10982 /* Clean up our temporary breakpoints. */
10983 breakpoints
.clear ();
10984 delete_longjmp_breakpoint (thread
);
10987 /* Implementation of the 'async_reply_reason' FSM method for the
10988 until(location)/advance commands. */
10990 enum async_reply_reason
10991 until_break_fsm::do_async_reply_reason ()
10993 return EXEC_ASYNC_LOCATION_REACHED
;
10997 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10999 struct frame_info
*frame
;
11000 struct gdbarch
*frame_gdbarch
;
11001 struct frame_id stack_frame_id
;
11002 struct frame_id caller_frame_id
;
11004 struct thread_info
*tp
;
11006 clear_proceed_status (0);
11008 /* Set a breakpoint where the user wants it and at return from
11011 event_location_up location
= string_to_event_location (&arg
, current_language
);
11013 std::vector
<symtab_and_line
> sals
11014 = (last_displayed_sal_is_valid ()
11015 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11016 get_last_displayed_symtab (),
11017 get_last_displayed_line ())
11018 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11022 error (_("Couldn't get information on specified line."));
11025 error (_("Junk at end of arguments."));
11027 tp
= inferior_thread ();
11028 thread
= tp
->global_num
;
11030 /* Note linespec handling above invalidates the frame chain.
11031 Installing a breakpoint also invalidates the frame chain (as it
11032 may need to switch threads), so do any frame handling before
11035 frame
= get_selected_frame (NULL
);
11036 frame_gdbarch
= get_frame_arch (frame
);
11037 stack_frame_id
= get_stack_frame_id (frame
);
11038 caller_frame_id
= frame_unwind_caller_id (frame
);
11040 /* Keep within the current frame, or in frames called by the current
11043 std::vector
<breakpoint_up
> breakpoints
;
11045 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11047 if (frame_id_p (caller_frame_id
))
11049 struct symtab_and_line sal2
;
11050 struct gdbarch
*caller_gdbarch
;
11052 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11053 sal2
.pc
= frame_unwind_caller_pc (frame
);
11054 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11056 breakpoint_up caller_breakpoint
11057 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
11058 caller_frame_id
, bp_until
);
11059 breakpoints
.emplace_back (std::move (caller_breakpoint
));
11061 set_longjmp_breakpoint (tp
, caller_frame_id
);
11062 lj_deleter
.emplace (thread
);
11065 /* set_momentary_breakpoint could invalidate FRAME. */
11068 /* If the user told us to continue until a specified location, we
11069 don't specify a frame at which we need to stop. Otherwise,
11070 specify the selected frame, because we want to stop only at the
11071 very same frame. */
11072 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
11074 for (symtab_and_line
&sal
: sals
)
11076 resolve_sal_pc (&sal
);
11078 breakpoint_up location_breakpoint
11079 = set_momentary_breakpoint (frame_gdbarch
, sal
,
11080 stop_frame_id
, bp_until
);
11081 breakpoints
.emplace_back (std::move (location_breakpoint
));
11084 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11085 std::move (breakpoints
));
11088 lj_deleter
->release ();
11090 proceed (-1, GDB_SIGNAL_DEFAULT
);
11093 /* This function attempts to parse an optional "if <cond>" clause
11094 from the arg string. If one is not found, it returns NULL.
11096 Else, it returns a pointer to the condition string. (It does not
11097 attempt to evaluate the string against a particular block.) And,
11098 it updates arg to point to the first character following the parsed
11099 if clause in the arg string. */
11102 ep_parse_optional_if_clause (const char **arg
)
11104 const char *cond_string
;
11106 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11109 /* Skip the "if" keyword. */
11112 /* Skip any extra leading whitespace, and record the start of the
11113 condition string. */
11114 *arg
= skip_spaces (*arg
);
11115 cond_string
= *arg
;
11117 /* Assume that the condition occupies the remainder of the arg
11119 (*arg
) += strlen (cond_string
);
11121 return cond_string
;
11124 /* Commands to deal with catching events, such as signals, exceptions,
11125 process start/exit, etc. */
11129 catch_fork_temporary
, catch_vfork_temporary
,
11130 catch_fork_permanent
, catch_vfork_permanent
11135 catch_fork_command_1 (const char *arg
, int from_tty
,
11136 struct cmd_list_element
*command
)
11138 struct gdbarch
*gdbarch
= get_current_arch ();
11139 const char *cond_string
= NULL
;
11140 catch_fork_kind fork_kind
;
11142 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11143 bool temp
= (fork_kind
== catch_fork_temporary
11144 || fork_kind
== catch_vfork_temporary
);
11148 arg
= skip_spaces (arg
);
11150 /* The allowed syntax is:
11152 catch [v]fork if <cond>
11154 First, check if there's an if clause. */
11155 cond_string
= ep_parse_optional_if_clause (&arg
);
11157 if ((*arg
!= '\0') && !isspace (*arg
))
11158 error (_("Junk at end of arguments."));
11160 /* If this target supports it, create a fork or vfork catchpoint
11161 and enable reporting of such events. */
11164 case catch_fork_temporary
:
11165 case catch_fork_permanent
:
11166 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11167 &catch_fork_breakpoint_ops
);
11169 case catch_vfork_temporary
:
11170 case catch_vfork_permanent
:
11171 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11172 &catch_vfork_breakpoint_ops
);
11175 error (_("unsupported or unknown fork kind; cannot catch it"));
11181 catch_exec_command_1 (const char *arg
, int from_tty
,
11182 struct cmd_list_element
*command
)
11184 struct gdbarch
*gdbarch
= get_current_arch ();
11185 const char *cond_string
= NULL
;
11186 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11190 arg
= skip_spaces (arg
);
11192 /* The allowed syntax is:
11194 catch exec if <cond>
11196 First, check if there's an if clause. */
11197 cond_string
= ep_parse_optional_if_clause (&arg
);
11199 if ((*arg
!= '\0') && !isspace (*arg
))
11200 error (_("Junk at end of arguments."));
11202 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11203 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
,
11204 &catch_exec_breakpoint_ops
);
11205 c
->exec_pathname
= NULL
;
11207 install_breakpoint (0, std::move (c
), 1);
11211 init_ada_exception_breakpoint (struct breakpoint
*b
,
11212 struct gdbarch
*gdbarch
,
11213 struct symtab_and_line sal
,
11214 const char *addr_string
,
11215 const struct breakpoint_ops
*ops
,
11222 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11224 loc_gdbarch
= gdbarch
;
11226 describe_other_breakpoints (loc_gdbarch
,
11227 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11228 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11229 version for exception catchpoints, because two catchpoints
11230 used for different exception names will use the same address.
11231 In this case, a "breakpoint ... also set at..." warning is
11232 unproductive. Besides, the warning phrasing is also a bit
11233 inappropriate, we should use the word catchpoint, and tell
11234 the user what type of catchpoint it is. The above is good
11235 enough for now, though. */
11238 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11240 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11241 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11242 b
->location
= string_to_event_location (&addr_string
,
11243 language_def (language_ada
));
11244 b
->language
= language_ada
;
11249 /* Compare two breakpoints and return a strcmp-like result. */
11252 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11254 uintptr_t ua
= (uintptr_t) a
;
11255 uintptr_t ub
= (uintptr_t) b
;
11257 if (a
->number
< b
->number
)
11259 else if (a
->number
> b
->number
)
11262 /* Now sort by address, in case we see, e..g, two breakpoints with
11266 return ua
> ub
? 1 : 0;
11269 /* Delete breakpoints by address or line. */
11272 clear_command (const char *arg
, int from_tty
)
11274 struct breakpoint
*b
;
11277 std::vector
<symtab_and_line
> decoded_sals
;
11278 symtab_and_line last_sal
;
11279 gdb::array_view
<symtab_and_line
> sals
;
11283 = decode_line_with_current_source (arg
,
11284 (DECODE_LINE_FUNFIRSTLINE
11285 | DECODE_LINE_LIST_MODE
));
11287 sals
= decoded_sals
;
11291 /* Set sal's line, symtab, pc, and pspace to the values
11292 corresponding to the last call to print_frame_info. If the
11293 codepoint is not valid, this will set all the fields to 0. */
11294 last_sal
= get_last_displayed_sal ();
11295 if (last_sal
.symtab
== 0)
11296 error (_("No source file specified."));
11302 /* We don't call resolve_sal_pc here. That's not as bad as it
11303 seems, because all existing breakpoints typically have both
11304 file/line and pc set. So, if clear is given file/line, we can
11305 match this to existing breakpoint without obtaining pc at all.
11307 We only support clearing given the address explicitly
11308 present in breakpoint table. Say, we've set breakpoint
11309 at file:line. There were several PC values for that file:line,
11310 due to optimization, all in one block.
11312 We've picked one PC value. If "clear" is issued with another
11313 PC corresponding to the same file:line, the breakpoint won't
11314 be cleared. We probably can still clear the breakpoint, but
11315 since the other PC value is never presented to user, user
11316 can only find it by guessing, and it does not seem important
11317 to support that. */
11319 /* For each line spec given, delete bps which correspond to it. Do
11320 it in two passes, solely to preserve the current behavior that
11321 from_tty is forced true if we delete more than one
11324 std::vector
<struct breakpoint
*> found
;
11325 for (const auto &sal
: sals
)
11327 const char *sal_fullname
;
11329 /* If exact pc given, clear bpts at that pc.
11330 If line given (pc == 0), clear all bpts on specified line.
11331 If defaulting, clear all bpts on default line
11334 defaulting sal.pc != 0 tests to do
11339 1 0 <can't happen> */
11341 sal_fullname
= (sal
.symtab
== NULL
11342 ? NULL
: symtab_to_fullname (sal
.symtab
));
11344 /* Find all matching breakpoints and add them to 'found'. */
11345 ALL_BREAKPOINTS (b
)
11348 /* Are we going to delete b? */
11349 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11351 struct bp_location
*loc
= b
->loc
;
11352 for (; loc
; loc
= loc
->next
)
11354 /* If the user specified file:line, don't allow a PC
11355 match. This matches historical gdb behavior. */
11356 int pc_match
= (!sal
.explicit_line
11358 && (loc
->pspace
== sal
.pspace
)
11359 && (loc
->address
== sal
.pc
)
11360 && (!section_is_overlay (loc
->section
)
11361 || loc
->section
== sal
.section
));
11362 int line_match
= 0;
11364 if ((default_match
|| sal
.explicit_line
)
11365 && loc
->symtab
!= NULL
11366 && sal_fullname
!= NULL
11367 && sal
.pspace
== loc
->pspace
11368 && loc
->line_number
== sal
.line
11369 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11370 sal_fullname
) == 0)
11373 if (pc_match
|| line_match
)
11382 found
.push_back (b
);
11386 /* Now go thru the 'found' chain and delete them. */
11387 if (found
.empty ())
11390 error (_("No breakpoint at %s."), arg
);
11392 error (_("No breakpoint at this line."));
11395 /* Remove duplicates from the vec. */
11396 std::sort (found
.begin (), found
.end (),
11397 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11399 return compare_breakpoints (bp_a
, bp_b
) < 0;
11401 found
.erase (std::unique (found
.begin (), found
.end (),
11402 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11404 return compare_breakpoints (bp_a
, bp_b
) == 0;
11408 if (found
.size () > 1)
11409 from_tty
= 1; /* Always report if deleted more than one. */
11412 if (found
.size () == 1)
11413 printf_unfiltered (_("Deleted breakpoint "));
11415 printf_unfiltered (_("Deleted breakpoints "));
11418 for (breakpoint
*iter
: found
)
11421 printf_unfiltered ("%d ", iter
->number
);
11422 delete_breakpoint (iter
);
11425 putchar_unfiltered ('\n');
11428 /* Delete breakpoint in BS if they are `delete' breakpoints and
11429 all breakpoints that are marked for deletion, whether hit or not.
11430 This is called after any breakpoint is hit, or after errors. */
11433 breakpoint_auto_delete (bpstat bs
)
11435 struct breakpoint
*b
, *b_tmp
;
11437 for (; bs
; bs
= bs
->next
)
11438 if (bs
->breakpoint_at
11439 && bs
->breakpoint_at
->disposition
== disp_del
11441 delete_breakpoint (bs
->breakpoint_at
);
11443 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11445 if (b
->disposition
== disp_del_at_next_stop
)
11446 delete_breakpoint (b
);
11450 /* A comparison function for bp_location AP and BP being interfaced to
11451 std::sort. Sort elements primarily by their ADDRESS (no matter what
11452 bl_address_is_meaningful says), secondarily by ordering first
11453 permanent elements and terciarily just ensuring the array is sorted
11454 stable way despite std::sort being an unstable algorithm. */
11457 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11459 if (a
->address
!= b
->address
)
11460 return a
->address
< b
->address
;
11462 /* Sort locations at the same address by their pspace number, keeping
11463 locations of the same inferior (in a multi-inferior environment)
11466 if (a
->pspace
->num
!= b
->pspace
->num
)
11467 return a
->pspace
->num
< b
->pspace
->num
;
11469 /* Sort permanent breakpoints first. */
11470 if (a
->permanent
!= b
->permanent
)
11471 return a
->permanent
> b
->permanent
;
11473 /* Sort by type in order to make duplicate determination easier.
11474 See update_global_location_list. This is kept in sync with
11475 breakpoint_locations_match. */
11476 if (a
->loc_type
< b
->loc_type
)
11479 /* Likewise, for range-breakpoints, sort by length. */
11480 if (a
->loc_type
== bp_loc_hardware_breakpoint
11481 && b
->loc_type
== bp_loc_hardware_breakpoint
11482 && a
->length
< b
->length
)
11485 /* Make the internal GDB representation stable across GDB runs
11486 where A and B memory inside GDB can differ. Breakpoint locations of
11487 the same type at the same address can be sorted in arbitrary order. */
11489 if (a
->owner
->number
!= b
->owner
->number
)
11490 return a
->owner
->number
< b
->owner
->number
;
11495 /* Set bp_locations_placed_address_before_address_max and
11496 bp_locations_shadow_len_after_address_max according to the current
11497 content of the bp_locations array. */
11500 bp_locations_target_extensions_update (void)
11502 struct bp_location
*bl
, **blp_tmp
;
11504 bp_locations_placed_address_before_address_max
= 0;
11505 bp_locations_shadow_len_after_address_max
= 0;
11507 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11509 CORE_ADDR start
, end
, addr
;
11511 if (!bp_location_has_shadow (bl
))
11514 start
= bl
->target_info
.placed_address
;
11515 end
= start
+ bl
->target_info
.shadow_len
;
11517 gdb_assert (bl
->address
>= start
);
11518 addr
= bl
->address
- start
;
11519 if (addr
> bp_locations_placed_address_before_address_max
)
11520 bp_locations_placed_address_before_address_max
= addr
;
11522 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11524 gdb_assert (bl
->address
< end
);
11525 addr
= end
- bl
->address
;
11526 if (addr
> bp_locations_shadow_len_after_address_max
)
11527 bp_locations_shadow_len_after_address_max
= addr
;
11531 /* Download tracepoint locations if they haven't been. */
11534 download_tracepoint_locations (void)
11536 struct breakpoint
*b
;
11537 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11539 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11541 ALL_TRACEPOINTS (b
)
11543 struct bp_location
*bl
;
11544 struct tracepoint
*t
;
11545 int bp_location_downloaded
= 0;
11547 if ((b
->type
== bp_fast_tracepoint
11548 ? !may_insert_fast_tracepoints
11549 : !may_insert_tracepoints
))
11552 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11554 if (target_can_download_tracepoint ())
11555 can_download_tracepoint
= TRIBOOL_TRUE
;
11557 can_download_tracepoint
= TRIBOOL_FALSE
;
11560 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11563 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11565 /* In tracepoint, locations are _never_ duplicated, so
11566 should_be_inserted is equivalent to
11567 unduplicated_should_be_inserted. */
11568 if (!should_be_inserted (bl
) || bl
->inserted
)
11571 switch_to_program_space_and_thread (bl
->pspace
);
11573 target_download_tracepoint (bl
);
11576 bp_location_downloaded
= 1;
11578 t
= (struct tracepoint
*) b
;
11579 t
->number_on_target
= b
->number
;
11580 if (bp_location_downloaded
)
11581 gdb::observers::breakpoint_modified
.notify (b
);
11585 /* Swap the insertion/duplication state between two locations. */
11588 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11590 const int left_inserted
= left
->inserted
;
11591 const int left_duplicate
= left
->duplicate
;
11592 const int left_needs_update
= left
->needs_update
;
11593 const struct bp_target_info left_target_info
= left
->target_info
;
11595 /* Locations of tracepoints can never be duplicated. */
11596 if (is_tracepoint (left
->owner
))
11597 gdb_assert (!left
->duplicate
);
11598 if (is_tracepoint (right
->owner
))
11599 gdb_assert (!right
->duplicate
);
11601 left
->inserted
= right
->inserted
;
11602 left
->duplicate
= right
->duplicate
;
11603 left
->needs_update
= right
->needs_update
;
11604 left
->target_info
= right
->target_info
;
11605 right
->inserted
= left_inserted
;
11606 right
->duplicate
= left_duplicate
;
11607 right
->needs_update
= left_needs_update
;
11608 right
->target_info
= left_target_info
;
11611 /* Force the re-insertion of the locations at ADDRESS. This is called
11612 once a new/deleted/modified duplicate location is found and we are evaluating
11613 conditions on the target's side. Such conditions need to be updated on
11617 force_breakpoint_reinsertion (struct bp_location
*bl
)
11619 struct bp_location
**locp
= NULL
, **loc2p
;
11620 struct bp_location
*loc
;
11621 CORE_ADDR address
= 0;
11624 address
= bl
->address
;
11625 pspace_num
= bl
->pspace
->num
;
11627 /* This is only meaningful if the target is
11628 evaluating conditions and if the user has
11629 opted for condition evaluation on the target's
11631 if (gdb_evaluates_breakpoint_condition_p ()
11632 || !target_supports_evaluation_of_breakpoint_conditions ())
11635 /* Flag all breakpoint locations with this address and
11636 the same program space as the location
11637 as "its condition has changed". We need to
11638 update the conditions on the target's side. */
11639 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11643 if (!is_breakpoint (loc
->owner
)
11644 || pspace_num
!= loc
->pspace
->num
)
11647 /* Flag the location appropriately. We use a different state to
11648 let everyone know that we already updated the set of locations
11649 with addr bl->address and program space bl->pspace. This is so
11650 we don't have to keep calling these functions just to mark locations
11651 that have already been marked. */
11652 loc
->condition_changed
= condition_updated
;
11654 /* Free the agent expression bytecode as well. We will compute
11656 loc
->cond_bytecode
.reset ();
11660 /* Called whether new breakpoints are created, or existing breakpoints
11661 deleted, to update the global location list and recompute which
11662 locations are duplicate of which.
11664 The INSERT_MODE flag determines whether locations may not, may, or
11665 shall be inserted now. See 'enum ugll_insert_mode' for more
11669 update_global_location_list (enum ugll_insert_mode insert_mode
)
11671 struct breakpoint
*b
;
11672 struct bp_location
**locp
, *loc
;
11673 /* Last breakpoint location address that was marked for update. */
11674 CORE_ADDR last_addr
= 0;
11675 /* Last breakpoint location program space that was marked for update. */
11676 int last_pspace_num
= -1;
11678 /* Used in the duplicates detection below. When iterating over all
11679 bp_locations, points to the first bp_location of a given address.
11680 Breakpoints and watchpoints of different types are never
11681 duplicates of each other. Keep one pointer for each type of
11682 breakpoint/watchpoint, so we only need to loop over all locations
11684 struct bp_location
*bp_loc_first
; /* breakpoint */
11685 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11686 struct bp_location
*awp_loc_first
; /* access watchpoint */
11687 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11689 /* Saved former bp_locations array which we compare against the newly
11690 built bp_locations from the current state of ALL_BREAKPOINTS. */
11691 struct bp_location
**old_locp
;
11692 unsigned old_locations_count
;
11693 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11695 old_locations_count
= bp_locations_count
;
11696 bp_locations
= NULL
;
11697 bp_locations_count
= 0;
11699 ALL_BREAKPOINTS (b
)
11700 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11701 bp_locations_count
++;
11703 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11704 locp
= bp_locations
;
11705 ALL_BREAKPOINTS (b
)
11706 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11709 /* See if we need to "upgrade" a software breakpoint to a hardware
11710 breakpoint. Do this before deciding whether locations are
11711 duplicates. Also do this before sorting because sorting order
11712 depends on location type. */
11713 for (locp
= bp_locations
;
11714 locp
< bp_locations
+ bp_locations_count
;
11718 if (!loc
->inserted
&& should_be_inserted (loc
))
11719 handle_automatic_hardware_breakpoints (loc
);
11722 std::sort (bp_locations
, bp_locations
+ bp_locations_count
,
11723 bp_location_is_less_than
);
11725 bp_locations_target_extensions_update ();
11727 /* Identify bp_location instances that are no longer present in the
11728 new list, and therefore should be freed. Note that it's not
11729 necessary that those locations should be removed from inferior --
11730 if there's another location at the same address (previously
11731 marked as duplicate), we don't need to remove/insert the
11734 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11735 and former bp_location array state respectively. */
11737 locp
= bp_locations
;
11738 for (old_locp
= old_locations
.get ();
11739 old_locp
< old_locations
.get () + old_locations_count
;
11742 struct bp_location
*old_loc
= *old_locp
;
11743 struct bp_location
**loc2p
;
11745 /* Tells if 'old_loc' is found among the new locations. If
11746 not, we have to free it. */
11747 int found_object
= 0;
11748 /* Tells if the location should remain inserted in the target. */
11749 int keep_in_target
= 0;
11752 /* Skip LOCP entries which will definitely never be needed.
11753 Stop either at or being the one matching OLD_LOC. */
11754 while (locp
< bp_locations
+ bp_locations_count
11755 && (*locp
)->address
< old_loc
->address
)
11759 (loc2p
< bp_locations
+ bp_locations_count
11760 && (*loc2p
)->address
== old_loc
->address
);
11763 /* Check if this is a new/duplicated location or a duplicated
11764 location that had its condition modified. If so, we want to send
11765 its condition to the target if evaluation of conditions is taking
11767 if ((*loc2p
)->condition_changed
== condition_modified
11768 && (last_addr
!= old_loc
->address
11769 || last_pspace_num
!= old_loc
->pspace
->num
))
11771 force_breakpoint_reinsertion (*loc2p
);
11772 last_pspace_num
= old_loc
->pspace
->num
;
11775 if (*loc2p
== old_loc
)
11779 /* We have already handled this address, update it so that we don't
11780 have to go through updates again. */
11781 last_addr
= old_loc
->address
;
11783 /* Target-side condition evaluation: Handle deleted locations. */
11785 force_breakpoint_reinsertion (old_loc
);
11787 /* If this location is no longer present, and inserted, look if
11788 there's maybe a new location at the same address. If so,
11789 mark that one inserted, and don't remove this one. This is
11790 needed so that we don't have a time window where a breakpoint
11791 at certain location is not inserted. */
11793 if (old_loc
->inserted
)
11795 /* If the location is inserted now, we might have to remove
11798 if (found_object
&& should_be_inserted (old_loc
))
11800 /* The location is still present in the location list,
11801 and still should be inserted. Don't do anything. */
11802 keep_in_target
= 1;
11806 /* This location still exists, but it won't be kept in the
11807 target since it may have been disabled. We proceed to
11808 remove its target-side condition. */
11810 /* The location is either no longer present, or got
11811 disabled. See if there's another location at the
11812 same address, in which case we don't need to remove
11813 this one from the target. */
11815 /* OLD_LOC comes from existing struct breakpoint. */
11816 if (bl_address_is_meaningful (old_loc
))
11819 (loc2p
< bp_locations
+ bp_locations_count
11820 && (*loc2p
)->address
== old_loc
->address
);
11823 struct bp_location
*loc2
= *loc2p
;
11825 if (loc2
== old_loc
)
11828 if (breakpoint_locations_match (loc2
, old_loc
))
11830 /* Read watchpoint locations are switched to
11831 access watchpoints, if the former are not
11832 supported, but the latter are. */
11833 if (is_hardware_watchpoint (old_loc
->owner
))
11835 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11836 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11839 /* loc2 is a duplicated location. We need to check
11840 if it should be inserted in case it will be
11842 if (unduplicated_should_be_inserted (loc2
))
11844 swap_insertion (old_loc
, loc2
);
11845 keep_in_target
= 1;
11853 if (!keep_in_target
)
11855 if (remove_breakpoint (old_loc
))
11857 /* This is just about all we can do. We could keep
11858 this location on the global list, and try to
11859 remove it next time, but there's no particular
11860 reason why we will succeed next time.
11862 Note that at this point, old_loc->owner is still
11863 valid, as delete_breakpoint frees the breakpoint
11864 only after calling us. */
11865 printf_filtered (_("warning: Error removing "
11866 "breakpoint %d\n"),
11867 old_loc
->owner
->number
);
11875 if (removed
&& target_is_non_stop_p ()
11876 && need_moribund_for_location_type (old_loc
))
11878 /* This location was removed from the target. In
11879 non-stop mode, a race condition is possible where
11880 we've removed a breakpoint, but stop events for that
11881 breakpoint are already queued and will arrive later.
11882 We apply an heuristic to be able to distinguish such
11883 SIGTRAPs from other random SIGTRAPs: we keep this
11884 breakpoint location for a bit, and will retire it
11885 after we see some number of events. The theory here
11886 is that reporting of events should, "on the average",
11887 be fair, so after a while we'll see events from all
11888 threads that have anything of interest, and no longer
11889 need to keep this breakpoint location around. We
11890 don't hold locations forever so to reduce chances of
11891 mistaking a non-breakpoint SIGTRAP for a breakpoint
11894 The heuristic failing can be disastrous on
11895 decr_pc_after_break targets.
11897 On decr_pc_after_break targets, like e.g., x86-linux,
11898 if we fail to recognize a late breakpoint SIGTRAP,
11899 because events_till_retirement has reached 0 too
11900 soon, we'll fail to do the PC adjustment, and report
11901 a random SIGTRAP to the user. When the user resumes
11902 the inferior, it will most likely immediately crash
11903 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11904 corrupted, because of being resumed e.g., in the
11905 middle of a multi-byte instruction, or skipped a
11906 one-byte instruction. This was actually seen happen
11907 on native x86-linux, and should be less rare on
11908 targets that do not support new thread events, like
11909 remote, due to the heuristic depending on
11912 Mistaking a random SIGTRAP for a breakpoint trap
11913 causes similar symptoms (PC adjustment applied when
11914 it shouldn't), but then again, playing with SIGTRAPs
11915 behind the debugger's back is asking for trouble.
11917 Since hardware watchpoint traps are always
11918 distinguishable from other traps, so we don't need to
11919 apply keep hardware watchpoint moribund locations
11920 around. We simply always ignore hardware watchpoint
11921 traps we can no longer explain. */
11923 process_stratum_target
*proc_target
= nullptr;
11924 for (inferior
*inf
: all_inferiors ())
11925 if (inf
->pspace
== old_loc
->pspace
)
11927 proc_target
= inf
->process_target ();
11930 if (proc_target
!= nullptr)
11931 old_loc
->events_till_retirement
11932 = 3 * (thread_count (proc_target
) + 1);
11934 old_loc
->events_till_retirement
= 1;
11935 old_loc
->owner
= NULL
;
11937 moribund_locations
.push_back (old_loc
);
11941 old_loc
->owner
= NULL
;
11942 decref_bp_location (&old_loc
);
11947 /* Rescan breakpoints at the same address and section, marking the
11948 first one as "first" and any others as "duplicates". This is so
11949 that the bpt instruction is only inserted once. If we have a
11950 permanent breakpoint at the same place as BPT, make that one the
11951 official one, and the rest as duplicates. Permanent breakpoints
11952 are sorted first for the same address.
11954 Do the same for hardware watchpoints, but also considering the
11955 watchpoint's type (regular/access/read) and length. */
11957 bp_loc_first
= NULL
;
11958 wp_loc_first
= NULL
;
11959 awp_loc_first
= NULL
;
11960 rwp_loc_first
= NULL
;
11961 ALL_BP_LOCATIONS (loc
, locp
)
11963 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11965 struct bp_location
**loc_first_p
;
11968 if (!unduplicated_should_be_inserted (loc
)
11969 || !bl_address_is_meaningful (loc
)
11970 /* Don't detect duplicate for tracepoint locations because they are
11971 never duplicated. See the comments in field `duplicate' of
11972 `struct bp_location'. */
11973 || is_tracepoint (b
))
11975 /* Clear the condition modification flag. */
11976 loc
->condition_changed
= condition_unchanged
;
11980 if (b
->type
== bp_hardware_watchpoint
)
11981 loc_first_p
= &wp_loc_first
;
11982 else if (b
->type
== bp_read_watchpoint
)
11983 loc_first_p
= &rwp_loc_first
;
11984 else if (b
->type
== bp_access_watchpoint
)
11985 loc_first_p
= &awp_loc_first
;
11987 loc_first_p
= &bp_loc_first
;
11989 if (*loc_first_p
== NULL
11990 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11991 || !breakpoint_locations_match (loc
, *loc_first_p
))
11993 *loc_first_p
= loc
;
11994 loc
->duplicate
= 0;
11996 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11998 loc
->needs_update
= 1;
11999 /* Clear the condition modification flag. */
12000 loc
->condition_changed
= condition_unchanged
;
12006 /* This and the above ensure the invariant that the first location
12007 is not duplicated, and is the inserted one.
12008 All following are marked as duplicated, and are not inserted. */
12010 swap_insertion (loc
, *loc_first_p
);
12011 loc
->duplicate
= 1;
12013 /* Clear the condition modification flag. */
12014 loc
->condition_changed
= condition_unchanged
;
12017 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12019 if (insert_mode
!= UGLL_DONT_INSERT
)
12020 insert_breakpoint_locations ();
12023 /* Even though the caller told us to not insert new
12024 locations, we may still need to update conditions on the
12025 target's side of breakpoints that were already inserted
12026 if the target is evaluating breakpoint conditions. We
12027 only update conditions for locations that are marked
12029 update_inserted_breakpoint_locations ();
12033 if (insert_mode
!= UGLL_DONT_INSERT
)
12034 download_tracepoint_locations ();
12038 breakpoint_retire_moribund (void)
12040 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
12042 struct bp_location
*loc
= moribund_locations
[ix
];
12043 if (--(loc
->events_till_retirement
) == 0)
12045 decref_bp_location (&loc
);
12046 unordered_remove (moribund_locations
, ix
);
12053 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12058 update_global_location_list (insert_mode
);
12060 catch (const gdb_exception_error
&e
)
12065 /* Clear BKP from a BPS. */
12068 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12072 for (bs
= bps
; bs
; bs
= bs
->next
)
12073 if (bs
->breakpoint_at
== bpt
)
12075 bs
->breakpoint_at
= NULL
;
12076 bs
->old_val
= NULL
;
12077 /* bs->commands will be freed later. */
12081 /* Callback for iterate_over_threads. */
12083 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12085 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12087 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12091 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12095 say_where (struct breakpoint
*b
)
12097 struct value_print_options opts
;
12099 get_user_print_options (&opts
);
12101 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12103 if (b
->loc
== NULL
)
12105 /* For pending locations, the output differs slightly based
12106 on b->extra_string. If this is non-NULL, it contains either
12107 a condition or dprintf arguments. */
12108 if (b
->extra_string
== NULL
)
12110 printf_filtered (_(" (%s) pending."),
12111 event_location_to_string (b
->location
.get ()));
12113 else if (b
->type
== bp_dprintf
)
12115 printf_filtered (_(" (%s,%s) pending."),
12116 event_location_to_string (b
->location
.get ()),
12121 printf_filtered (_(" (%s %s) pending."),
12122 event_location_to_string (b
->location
.get ()),
12128 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12129 printf_filtered (" at %ps",
12130 styled_string (address_style
.style (),
12131 paddress (b
->loc
->gdbarch
,
12132 b
->loc
->address
)));
12133 if (b
->loc
->symtab
!= NULL
)
12135 /* If there is a single location, we can print the location
12137 if (b
->loc
->next
== NULL
)
12139 const char *filename
12140 = symtab_to_filename_for_display (b
->loc
->symtab
);
12141 printf_filtered (": file %ps, line %d.",
12142 styled_string (file_name_style
.style (),
12144 b
->loc
->line_number
);
12147 /* This is not ideal, but each location may have a
12148 different file name, and this at least reflects the
12149 real situation somewhat. */
12150 printf_filtered (": %s.",
12151 event_location_to_string (b
->location
.get ()));
12156 struct bp_location
*loc
= b
->loc
;
12158 for (; loc
; loc
= loc
->next
)
12160 printf_filtered (" (%d locations)", n
);
12165 bp_location::~bp_location ()
12167 xfree (function_name
);
12170 /* Destructor for the breakpoint base class. */
12172 breakpoint::~breakpoint ()
12174 xfree (this->cond_string
);
12175 xfree (this->extra_string
);
12178 static struct bp_location
*
12179 base_breakpoint_allocate_location (struct breakpoint
*self
)
12181 return new bp_location (self
);
12185 base_breakpoint_re_set (struct breakpoint
*b
)
12187 /* Nothing to re-set. */
12190 #define internal_error_pure_virtual_called() \
12191 gdb_assert_not_reached ("pure virtual function called")
12194 base_breakpoint_insert_location (struct bp_location
*bl
)
12196 internal_error_pure_virtual_called ();
12200 base_breakpoint_remove_location (struct bp_location
*bl
,
12201 enum remove_bp_reason reason
)
12203 internal_error_pure_virtual_called ();
12207 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12208 const address_space
*aspace
,
12210 const struct target_waitstatus
*ws
)
12212 internal_error_pure_virtual_called ();
12216 base_breakpoint_check_status (bpstat bs
)
12221 /* A "works_in_software_mode" breakpoint_ops method that just internal
12225 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12227 internal_error_pure_virtual_called ();
12230 /* A "resources_needed" breakpoint_ops method that just internal
12234 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12236 internal_error_pure_virtual_called ();
12239 static enum print_stop_action
12240 base_breakpoint_print_it (bpstat bs
)
12242 internal_error_pure_virtual_called ();
12246 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12247 struct ui_out
*uiout
)
12253 base_breakpoint_print_mention (struct breakpoint
*b
)
12255 internal_error_pure_virtual_called ();
12259 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12261 internal_error_pure_virtual_called ();
12265 base_breakpoint_create_sals_from_location
12266 (struct event_location
*location
,
12267 struct linespec_result
*canonical
,
12268 enum bptype type_wanted
)
12270 internal_error_pure_virtual_called ();
12274 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12275 struct linespec_result
*c
,
12276 gdb::unique_xmalloc_ptr
<char> cond_string
,
12277 gdb::unique_xmalloc_ptr
<char> extra_string
,
12278 enum bptype type_wanted
,
12279 enum bpdisp disposition
,
12281 int task
, int ignore_count
,
12282 const struct breakpoint_ops
*o
,
12283 int from_tty
, int enabled
,
12284 int internal
, unsigned flags
)
12286 internal_error_pure_virtual_called ();
12289 static std::vector
<symtab_and_line
>
12290 base_breakpoint_decode_location (struct breakpoint
*b
,
12291 struct event_location
*location
,
12292 struct program_space
*search_pspace
)
12294 internal_error_pure_virtual_called ();
12297 /* The default 'explains_signal' method. */
12300 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12305 /* The default "after_condition_true" method. */
12308 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12310 /* Nothing to do. */
12313 struct breakpoint_ops base_breakpoint_ops
=
12315 base_breakpoint_allocate_location
,
12316 base_breakpoint_re_set
,
12317 base_breakpoint_insert_location
,
12318 base_breakpoint_remove_location
,
12319 base_breakpoint_breakpoint_hit
,
12320 base_breakpoint_check_status
,
12321 base_breakpoint_resources_needed
,
12322 base_breakpoint_works_in_software_mode
,
12323 base_breakpoint_print_it
,
12325 base_breakpoint_print_one_detail
,
12326 base_breakpoint_print_mention
,
12327 base_breakpoint_print_recreate
,
12328 base_breakpoint_create_sals_from_location
,
12329 base_breakpoint_create_breakpoints_sal
,
12330 base_breakpoint_decode_location
,
12331 base_breakpoint_explains_signal
,
12332 base_breakpoint_after_condition_true
,
12335 /* Default breakpoint_ops methods. */
12338 bkpt_re_set (struct breakpoint
*b
)
12340 /* FIXME: is this still reachable? */
12341 if (breakpoint_event_location_empty_p (b
))
12343 /* Anything without a location can't be re-set. */
12344 delete_breakpoint (b
);
12348 breakpoint_re_set_default (b
);
12352 bkpt_insert_location (struct bp_location
*bl
)
12354 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12356 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12357 bl
->target_info
.placed_address
= addr
;
12359 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12360 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12362 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12366 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12368 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12369 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12371 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12375 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12376 const address_space
*aspace
, CORE_ADDR bp_addr
,
12377 const struct target_waitstatus
*ws
)
12379 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12380 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12383 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12387 if (overlay_debugging
/* unmapped overlay section */
12388 && section_is_overlay (bl
->section
)
12389 && !section_is_mapped (bl
->section
))
12396 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12397 const address_space
*aspace
, CORE_ADDR bp_addr
,
12398 const struct target_waitstatus
*ws
)
12400 if (dprintf_style
== dprintf_style_agent
12401 && target_can_run_breakpoint_commands ())
12403 /* An agent-style dprintf never causes a stop. If we see a trap
12404 for this address it must be for a breakpoint that happens to
12405 be set at the same address. */
12409 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12413 bkpt_resources_needed (const struct bp_location
*bl
)
12415 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12420 static enum print_stop_action
12421 bkpt_print_it (bpstat bs
)
12423 struct breakpoint
*b
;
12424 const struct bp_location
*bl
;
12426 struct ui_out
*uiout
= current_uiout
;
12428 gdb_assert (bs
->bp_location_at
!= NULL
);
12430 bl
= bs
->bp_location_at
;
12431 b
= bs
->breakpoint_at
;
12433 bp_temp
= b
->disposition
== disp_del
;
12434 if (bl
->address
!= bl
->requested_address
)
12435 breakpoint_adjustment_warning (bl
->requested_address
,
12438 annotate_breakpoint (b
->number
);
12439 maybe_print_thread_hit_breakpoint (uiout
);
12441 if (uiout
->is_mi_like_p ())
12443 uiout
->field_string ("reason",
12444 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12445 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12448 uiout
->message ("Temporary breakpoint %pF, ",
12449 signed_field ("bkptno", b
->number
));
12451 uiout
->message ("Breakpoint %pF, ",
12452 signed_field ("bkptno", b
->number
));
12454 return PRINT_SRC_AND_LOC
;
12458 bkpt_print_mention (struct breakpoint
*b
)
12460 if (current_uiout
->is_mi_like_p ())
12465 case bp_breakpoint
:
12466 case bp_gnu_ifunc_resolver
:
12467 if (b
->disposition
== disp_del
)
12468 printf_filtered (_("Temporary breakpoint"));
12470 printf_filtered (_("Breakpoint"));
12471 printf_filtered (_(" %d"), b
->number
);
12472 if (b
->type
== bp_gnu_ifunc_resolver
)
12473 printf_filtered (_(" at gnu-indirect-function resolver"));
12475 case bp_hardware_breakpoint
:
12476 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12479 printf_filtered (_("Dprintf %d"), b
->number
);
12487 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12489 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12490 fprintf_unfiltered (fp
, "tbreak");
12491 else if (tp
->type
== bp_breakpoint
)
12492 fprintf_unfiltered (fp
, "break");
12493 else if (tp
->type
== bp_hardware_breakpoint
12494 && tp
->disposition
== disp_del
)
12495 fprintf_unfiltered (fp
, "thbreak");
12496 else if (tp
->type
== bp_hardware_breakpoint
)
12497 fprintf_unfiltered (fp
, "hbreak");
12499 internal_error (__FILE__
, __LINE__
,
12500 _("unhandled breakpoint type %d"), (int) tp
->type
);
12502 fprintf_unfiltered (fp
, " %s",
12503 event_location_to_string (tp
->location
.get ()));
12505 /* Print out extra_string if this breakpoint is pending. It might
12506 contain, for example, conditions that were set by the user. */
12507 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12508 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12510 print_recreate_thread (tp
, fp
);
12514 bkpt_create_sals_from_location (struct event_location
*location
,
12515 struct linespec_result
*canonical
,
12516 enum bptype type_wanted
)
12518 create_sals_from_location_default (location
, canonical
, type_wanted
);
12522 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12523 struct linespec_result
*canonical
,
12524 gdb::unique_xmalloc_ptr
<char> cond_string
,
12525 gdb::unique_xmalloc_ptr
<char> extra_string
,
12526 enum bptype type_wanted
,
12527 enum bpdisp disposition
,
12529 int task
, int ignore_count
,
12530 const struct breakpoint_ops
*ops
,
12531 int from_tty
, int enabled
,
12532 int internal
, unsigned flags
)
12534 create_breakpoints_sal_default (gdbarch
, canonical
,
12535 std::move (cond_string
),
12536 std::move (extra_string
),
12538 disposition
, thread
, task
,
12539 ignore_count
, ops
, from_tty
,
12540 enabled
, internal
, flags
);
12543 static std::vector
<symtab_and_line
>
12544 bkpt_decode_location (struct breakpoint
*b
,
12545 struct event_location
*location
,
12546 struct program_space
*search_pspace
)
12548 return decode_location_default (b
, location
, search_pspace
);
12551 /* Virtual table for internal breakpoints. */
12554 internal_bkpt_re_set (struct breakpoint
*b
)
12558 /* Delete overlay event and longjmp master breakpoints; they
12559 will be reset later by breakpoint_re_set. */
12560 case bp_overlay_event
:
12561 case bp_longjmp_master
:
12562 case bp_std_terminate_master
:
12563 case bp_exception_master
:
12564 delete_breakpoint (b
);
12567 /* This breakpoint is special, it's set up when the inferior
12568 starts and we really don't want to touch it. */
12569 case bp_shlib_event
:
12571 /* Like bp_shlib_event, this breakpoint type is special. Once
12572 it is set up, we do not want to touch it. */
12573 case bp_thread_event
:
12579 internal_bkpt_check_status (bpstat bs
)
12581 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12583 /* If requested, stop when the dynamic linker notifies GDB of
12584 events. This allows the user to get control and place
12585 breakpoints in initializer routines for dynamically loaded
12586 objects (among other things). */
12587 bs
->stop
= stop_on_solib_events
;
12588 bs
->print
= stop_on_solib_events
;
12594 static enum print_stop_action
12595 internal_bkpt_print_it (bpstat bs
)
12597 struct breakpoint
*b
;
12599 b
= bs
->breakpoint_at
;
12603 case bp_shlib_event
:
12604 /* Did we stop because the user set the stop_on_solib_events
12605 variable? (If so, we report this as a generic, "Stopped due
12606 to shlib event" message.) */
12607 print_solib_event (0);
12610 case bp_thread_event
:
12611 /* Not sure how we will get here.
12612 GDB should not stop for these breakpoints. */
12613 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12616 case bp_overlay_event
:
12617 /* By analogy with the thread event, GDB should not stop for these. */
12618 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12621 case bp_longjmp_master
:
12622 /* These should never be enabled. */
12623 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12626 case bp_std_terminate_master
:
12627 /* These should never be enabled. */
12628 printf_filtered (_("std::terminate Master Breakpoint: "
12629 "gdb should not stop!\n"));
12632 case bp_exception_master
:
12633 /* These should never be enabled. */
12634 printf_filtered (_("Exception Master Breakpoint: "
12635 "gdb should not stop!\n"));
12639 return PRINT_NOTHING
;
12643 internal_bkpt_print_mention (struct breakpoint
*b
)
12645 /* Nothing to mention. These breakpoints are internal. */
12648 /* Virtual table for momentary breakpoints */
12651 momentary_bkpt_re_set (struct breakpoint
*b
)
12653 /* Keep temporary breakpoints, which can be encountered when we step
12654 over a dlopen call and solib_add is resetting the breakpoints.
12655 Otherwise these should have been blown away via the cleanup chain
12656 or by breakpoint_init_inferior when we rerun the executable. */
12660 momentary_bkpt_check_status (bpstat bs
)
12662 /* Nothing. The point of these breakpoints is causing a stop. */
12665 static enum print_stop_action
12666 momentary_bkpt_print_it (bpstat bs
)
12668 return PRINT_UNKNOWN
;
12672 momentary_bkpt_print_mention (struct breakpoint
*b
)
12674 /* Nothing to mention. These breakpoints are internal. */
12677 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12679 It gets cleared already on the removal of the first one of such placed
12680 breakpoints. This is OK as they get all removed altogether. */
12682 longjmp_breakpoint::~longjmp_breakpoint ()
12684 thread_info
*tp
= find_thread_global_id (this->thread
);
12687 tp
->initiating_frame
= null_frame_id
;
12690 /* Specific methods for probe breakpoints. */
12693 bkpt_probe_insert_location (struct bp_location
*bl
)
12695 int v
= bkpt_insert_location (bl
);
12699 /* The insertion was successful, now let's set the probe's semaphore
12701 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12708 bkpt_probe_remove_location (struct bp_location
*bl
,
12709 enum remove_bp_reason reason
)
12711 /* Let's clear the semaphore before removing the location. */
12712 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12714 return bkpt_remove_location (bl
, reason
);
12718 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12719 struct linespec_result
*canonical
,
12720 enum bptype type_wanted
)
12722 struct linespec_sals lsal
;
12724 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12726 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12727 canonical
->lsals
.push_back (std::move (lsal
));
12730 static std::vector
<symtab_and_line
>
12731 bkpt_probe_decode_location (struct breakpoint
*b
,
12732 struct event_location
*location
,
12733 struct program_space
*search_pspace
)
12735 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12737 error (_("probe not found"));
12741 /* The breakpoint_ops structure to be used in tracepoints. */
12744 tracepoint_re_set (struct breakpoint
*b
)
12746 breakpoint_re_set_default (b
);
12750 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12751 const address_space
*aspace
, CORE_ADDR bp_addr
,
12752 const struct target_waitstatus
*ws
)
12754 /* By definition, the inferior does not report stops at
12760 tracepoint_print_one_detail (const struct breakpoint
*self
,
12761 struct ui_out
*uiout
)
12763 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12764 if (!tp
->static_trace_marker_id
.empty ())
12766 gdb_assert (self
->type
== bp_static_tracepoint
);
12768 uiout
->message ("\tmarker id is %pF\n",
12769 string_field ("static-tracepoint-marker-string-id",
12770 tp
->static_trace_marker_id
.c_str ()));
12775 tracepoint_print_mention (struct breakpoint
*b
)
12777 if (current_uiout
->is_mi_like_p ())
12782 case bp_tracepoint
:
12783 printf_filtered (_("Tracepoint"));
12784 printf_filtered (_(" %d"), b
->number
);
12786 case bp_fast_tracepoint
:
12787 printf_filtered (_("Fast tracepoint"));
12788 printf_filtered (_(" %d"), b
->number
);
12790 case bp_static_tracepoint
:
12791 printf_filtered (_("Static tracepoint"));
12792 printf_filtered (_(" %d"), b
->number
);
12795 internal_error (__FILE__
, __LINE__
,
12796 _("unhandled tracepoint type %d"), (int) b
->type
);
12803 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12805 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12807 if (self
->type
== bp_fast_tracepoint
)
12808 fprintf_unfiltered (fp
, "ftrace");
12809 else if (self
->type
== bp_static_tracepoint
)
12810 fprintf_unfiltered (fp
, "strace");
12811 else if (self
->type
== bp_tracepoint
)
12812 fprintf_unfiltered (fp
, "trace");
12814 internal_error (__FILE__
, __LINE__
,
12815 _("unhandled tracepoint type %d"), (int) self
->type
);
12817 fprintf_unfiltered (fp
, " %s",
12818 event_location_to_string (self
->location
.get ()));
12819 print_recreate_thread (self
, fp
);
12821 if (tp
->pass_count
)
12822 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12826 tracepoint_create_sals_from_location (struct event_location
*location
,
12827 struct linespec_result
*canonical
,
12828 enum bptype type_wanted
)
12830 create_sals_from_location_default (location
, canonical
, type_wanted
);
12834 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12835 struct linespec_result
*canonical
,
12836 gdb::unique_xmalloc_ptr
<char> cond_string
,
12837 gdb::unique_xmalloc_ptr
<char> extra_string
,
12838 enum bptype type_wanted
,
12839 enum bpdisp disposition
,
12841 int task
, int ignore_count
,
12842 const struct breakpoint_ops
*ops
,
12843 int from_tty
, int enabled
,
12844 int internal
, unsigned flags
)
12846 create_breakpoints_sal_default (gdbarch
, canonical
,
12847 std::move (cond_string
),
12848 std::move (extra_string
),
12850 disposition
, thread
, task
,
12851 ignore_count
, ops
, from_tty
,
12852 enabled
, internal
, flags
);
12855 static std::vector
<symtab_and_line
>
12856 tracepoint_decode_location (struct breakpoint
*b
,
12857 struct event_location
*location
,
12858 struct program_space
*search_pspace
)
12860 return decode_location_default (b
, location
, search_pspace
);
12863 struct breakpoint_ops tracepoint_breakpoint_ops
;
12865 /* Virtual table for tracepoints on static probes. */
12868 tracepoint_probe_create_sals_from_location
12869 (struct event_location
*location
,
12870 struct linespec_result
*canonical
,
12871 enum bptype type_wanted
)
12873 /* We use the same method for breakpoint on probes. */
12874 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
12877 static std::vector
<symtab_and_line
>
12878 tracepoint_probe_decode_location (struct breakpoint
*b
,
12879 struct event_location
*location
,
12880 struct program_space
*search_pspace
)
12882 /* We use the same method for breakpoint on probes. */
12883 return bkpt_probe_decode_location (b
, location
, search_pspace
);
12886 /* Dprintf breakpoint_ops methods. */
12889 dprintf_re_set (struct breakpoint
*b
)
12891 breakpoint_re_set_default (b
);
12893 /* extra_string should never be non-NULL for dprintf. */
12894 gdb_assert (b
->extra_string
!= NULL
);
12896 /* 1 - connect to target 1, that can run breakpoint commands.
12897 2 - create a dprintf, which resolves fine.
12898 3 - disconnect from target 1
12899 4 - connect to target 2, that can NOT run breakpoint commands.
12901 After steps #3/#4, you'll want the dprintf command list to
12902 be updated, because target 1 and 2 may well return different
12903 answers for target_can_run_breakpoint_commands().
12904 Given absence of finer grained resetting, we get to do
12905 it all the time. */
12906 if (b
->extra_string
!= NULL
)
12907 update_dprintf_command_list (b
);
12910 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
12913 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12915 fprintf_unfiltered (fp
, "dprintf %s,%s",
12916 event_location_to_string (tp
->location
.get ()),
12918 print_recreate_thread (tp
, fp
);
12921 /* Implement the "after_condition_true" breakpoint_ops method for
12924 dprintf's are implemented with regular commands in their command
12925 list, but we run the commands here instead of before presenting the
12926 stop to the user, as dprintf's don't actually cause a stop. This
12927 also makes it so that the commands of multiple dprintfs at the same
12928 address are all handled. */
12931 dprintf_after_condition_true (struct bpstats
*bs
)
12933 struct bpstats tmp_bs
;
12934 struct bpstats
*tmp_bs_p
= &tmp_bs
;
12936 /* dprintf's never cause a stop. This wasn't set in the
12937 check_status hook instead because that would make the dprintf's
12938 condition not be evaluated. */
12941 /* Run the command list here. Take ownership of it instead of
12942 copying. We never want these commands to run later in
12943 bpstat_do_actions, if a breakpoint that causes a stop happens to
12944 be set at same address as this dprintf, or even if running the
12945 commands here throws. */
12946 tmp_bs
.commands
= bs
->commands
;
12947 bs
->commands
= NULL
;
12949 bpstat_do_actions_1 (&tmp_bs_p
);
12951 /* 'tmp_bs.commands' will usually be NULL by now, but
12952 bpstat_do_actions_1 may return early without processing the whole
12956 /* The breakpoint_ops structure to be used on static tracepoints with
12960 strace_marker_create_sals_from_location (struct event_location
*location
,
12961 struct linespec_result
*canonical
,
12962 enum bptype type_wanted
)
12964 struct linespec_sals lsal
;
12965 const char *arg_start
, *arg
;
12967 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
12968 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12970 std::string
str (arg_start
, arg
- arg_start
);
12971 const char *ptr
= str
.c_str ();
12972 canonical
->location
12973 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
12976 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12977 canonical
->lsals
.push_back (std::move (lsal
));
12981 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12982 struct linespec_result
*canonical
,
12983 gdb::unique_xmalloc_ptr
<char> cond_string
,
12984 gdb::unique_xmalloc_ptr
<char> extra_string
,
12985 enum bptype type_wanted
,
12986 enum bpdisp disposition
,
12988 int task
, int ignore_count
,
12989 const struct breakpoint_ops
*ops
,
12990 int from_tty
, int enabled
,
12991 int internal
, unsigned flags
)
12993 const linespec_sals
&lsal
= canonical
->lsals
[0];
12995 /* If the user is creating a static tracepoint by marker id
12996 (strace -m MARKER_ID), then store the sals index, so that
12997 breakpoint_re_set can try to match up which of the newly
12998 found markers corresponds to this one, and, don't try to
12999 expand multiple locations for each sal, given than SALS
13000 already should contain all sals for MARKER_ID. */
13002 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13004 event_location_up location
13005 = copy_event_location (canonical
->location
.get ());
13007 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13008 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13009 std::move (location
), NULL
,
13010 std::move (cond_string
),
13011 std::move (extra_string
),
13012 type_wanted
, disposition
,
13013 thread
, task
, ignore_count
, ops
,
13014 from_tty
, enabled
, internal
, flags
,
13015 canonical
->special_display
);
13016 /* Given that its possible to have multiple markers with
13017 the same string id, if the user is creating a static
13018 tracepoint by marker id ("strace -m MARKER_ID"), then
13019 store the sals index, so that breakpoint_re_set can
13020 try to match up which of the newly found markers
13021 corresponds to this one */
13022 tp
->static_trace_marker_id_idx
= i
;
13024 install_breakpoint (internal
, std::move (tp
), 0);
13028 static std::vector
<symtab_and_line
>
13029 strace_marker_decode_location (struct breakpoint
*b
,
13030 struct event_location
*location
,
13031 struct program_space
*search_pspace
)
13033 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13034 const char *s
= get_linespec_location (location
)->spec_string
;
13036 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13037 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13039 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13044 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
13047 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13050 strace_marker_p (struct breakpoint
*b
)
13052 return b
->ops
== &strace_marker_breakpoint_ops
;
13055 /* Delete a breakpoint and clean up all traces of it in the data
13059 delete_breakpoint (struct breakpoint
*bpt
)
13061 struct breakpoint
*b
;
13063 gdb_assert (bpt
!= NULL
);
13065 /* Has this bp already been deleted? This can happen because
13066 multiple lists can hold pointers to bp's. bpstat lists are
13069 One example of this happening is a watchpoint's scope bp. When
13070 the scope bp triggers, we notice that the watchpoint is out of
13071 scope, and delete it. We also delete its scope bp. But the
13072 scope bp is marked "auto-deleting", and is already on a bpstat.
13073 That bpstat is then checked for auto-deleting bp's, which are
13076 A real solution to this problem might involve reference counts in
13077 bp's, and/or giving them pointers back to their referencing
13078 bpstat's, and teaching delete_breakpoint to only free a bp's
13079 storage when no more references were extent. A cheaper bandaid
13081 if (bpt
->type
== bp_none
)
13084 /* At least avoid this stale reference until the reference counting
13085 of breakpoints gets resolved. */
13086 if (bpt
->related_breakpoint
!= bpt
)
13088 struct breakpoint
*related
;
13089 struct watchpoint
*w
;
13091 if (bpt
->type
== bp_watchpoint_scope
)
13092 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13093 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13094 w
= (struct watchpoint
*) bpt
;
13098 watchpoint_del_at_next_stop (w
);
13100 /* Unlink bpt from the bpt->related_breakpoint ring. */
13101 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13102 related
= related
->related_breakpoint
);
13103 related
->related_breakpoint
= bpt
->related_breakpoint
;
13104 bpt
->related_breakpoint
= bpt
;
13107 /* watch_command_1 creates a watchpoint but only sets its number if
13108 update_watchpoint succeeds in creating its bp_locations. If there's
13109 a problem in that process, we'll be asked to delete the half-created
13110 watchpoint. In that case, don't announce the deletion. */
13112 gdb::observers::breakpoint_deleted
.notify (bpt
);
13114 if (breakpoint_chain
== bpt
)
13115 breakpoint_chain
= bpt
->next
;
13117 ALL_BREAKPOINTS (b
)
13118 if (b
->next
== bpt
)
13120 b
->next
= bpt
->next
;
13124 /* Be sure no bpstat's are pointing at the breakpoint after it's
13126 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13127 in all threads for now. Note that we cannot just remove bpstats
13128 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13129 commands are associated with the bpstat; if we remove it here,
13130 then the later call to bpstat_do_actions (&stop_bpstat); in
13131 event-top.c won't do anything, and temporary breakpoints with
13132 commands won't work. */
13134 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13136 /* Now that breakpoint is removed from breakpoint list, update the
13137 global location list. This will remove locations that used to
13138 belong to this breakpoint. Do this before freeing the breakpoint
13139 itself, since remove_breakpoint looks at location's owner. It
13140 might be better design to have location completely
13141 self-contained, but it's not the case now. */
13142 update_global_location_list (UGLL_DONT_INSERT
);
13144 /* On the chance that someone will soon try again to delete this
13145 same bp, we mark it as deleted before freeing its storage. */
13146 bpt
->type
= bp_none
;
13150 /* Iterator function to call a user-provided callback function once
13151 for each of B and its related breakpoints. */
13154 iterate_over_related_breakpoints (struct breakpoint
*b
,
13155 gdb::function_view
<void (breakpoint
*)> function
)
13157 struct breakpoint
*related
;
13162 struct breakpoint
*next
;
13164 /* FUNCTION may delete RELATED. */
13165 next
= related
->related_breakpoint
;
13167 if (next
== related
)
13169 /* RELATED is the last ring entry. */
13170 function (related
);
13172 /* FUNCTION may have deleted it, so we'd never reach back to
13173 B. There's nothing left to do anyway, so just break
13178 function (related
);
13182 while (related
!= b
);
13186 delete_command (const char *arg
, int from_tty
)
13188 struct breakpoint
*b
, *b_tmp
;
13194 int breaks_to_delete
= 0;
13196 /* Delete all breakpoints if no argument. Do not delete
13197 internal breakpoints, these have to be deleted with an
13198 explicit breakpoint number argument. */
13199 ALL_BREAKPOINTS (b
)
13200 if (user_breakpoint_p (b
))
13202 breaks_to_delete
= 1;
13206 /* Ask user only if there are some breakpoints to delete. */
13208 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13210 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13211 if (user_breakpoint_p (b
))
13212 delete_breakpoint (b
);
13216 map_breakpoint_numbers
13217 (arg
, [&] (breakpoint
*br
)
13219 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13223 /* Return true if all locations of B bound to PSPACE are pending. If
13224 PSPACE is NULL, all locations of all program spaces are
13228 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13230 struct bp_location
*loc
;
13232 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13233 if ((pspace
== NULL
13234 || loc
->pspace
== pspace
)
13235 && !loc
->shlib_disabled
13236 && !loc
->pspace
->executing_startup
)
13241 /* Subroutine of update_breakpoint_locations to simplify it.
13242 Return non-zero if multiple fns in list LOC have the same name.
13243 Null names are ignored. */
13246 ambiguous_names_p (struct bp_location
*loc
)
13248 struct bp_location
*l
;
13249 htab_up
htab (htab_create_alloc (13, htab_hash_string
, streq_hash
, NULL
,
13252 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13255 const char *name
= l
->function_name
;
13257 /* Allow for some names to be NULL, ignore them. */
13261 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
13263 /* NOTE: We can assume slot != NULL here because xcalloc never
13273 /* When symbols change, it probably means the sources changed as well,
13274 and it might mean the static tracepoint markers are no longer at
13275 the same address or line numbers they used to be at last we
13276 checked. Losing your static tracepoints whenever you rebuild is
13277 undesirable. This function tries to resync/rematch gdb static
13278 tracepoints with the markers on the target, for static tracepoints
13279 that have not been set by marker id. Static tracepoint that have
13280 been set by marker id are reset by marker id in breakpoint_re_set.
13283 1) For a tracepoint set at a specific address, look for a marker at
13284 the old PC. If one is found there, assume to be the same marker.
13285 If the name / string id of the marker found is different from the
13286 previous known name, assume that means the user renamed the marker
13287 in the sources, and output a warning.
13289 2) For a tracepoint set at a given line number, look for a marker
13290 at the new address of the old line number. If one is found there,
13291 assume to be the same marker. If the name / string id of the
13292 marker found is different from the previous known name, assume that
13293 means the user renamed the marker in the sources, and output a
13296 3) If a marker is no longer found at the same address or line, it
13297 may mean the marker no longer exists. But it may also just mean
13298 the code changed a bit. Maybe the user added a few lines of code
13299 that made the marker move up or down (in line number terms). Ask
13300 the target for info about the marker with the string id as we knew
13301 it. If found, update line number and address in the matching
13302 static tracepoint. This will get confused if there's more than one
13303 marker with the same ID (possible in UST, although unadvised
13304 precisely because it confuses tools). */
13306 static struct symtab_and_line
13307 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13309 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13310 struct static_tracepoint_marker marker
;
13315 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13317 if (target_static_tracepoint_marker_at (pc
, &marker
))
13319 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13320 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13321 b
->number
, tp
->static_trace_marker_id
.c_str (),
13322 marker
.str_id
.c_str ());
13324 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13329 /* Old marker wasn't found on target at lineno. Try looking it up
13331 if (!sal
.explicit_pc
13333 && sal
.symtab
!= NULL
13334 && !tp
->static_trace_marker_id
.empty ())
13336 std::vector
<static_tracepoint_marker
> markers
13337 = target_static_tracepoint_markers_by_strid
13338 (tp
->static_trace_marker_id
.c_str ());
13340 if (!markers
.empty ())
13342 struct symbol
*sym
;
13343 struct static_tracepoint_marker
*tpmarker
;
13344 struct ui_out
*uiout
= current_uiout
;
13345 struct explicit_location explicit_loc
;
13347 tpmarker
= &markers
[0];
13349 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13351 warning (_("marker for static tracepoint %d (%s) not "
13352 "found at previous line number"),
13353 b
->number
, tp
->static_trace_marker_id
.c_str ());
13355 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13356 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13357 uiout
->text ("Now in ");
13360 uiout
->field_string ("func", sym
->print_name (),
13361 function_name_style
.style ());
13362 uiout
->text (" at ");
13364 uiout
->field_string ("file",
13365 symtab_to_filename_for_display (sal2
.symtab
),
13366 file_name_style
.style ());
13369 if (uiout
->is_mi_like_p ())
13371 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13373 uiout
->field_string ("fullname", fullname
);
13376 uiout
->field_signed ("line", sal2
.line
);
13377 uiout
->text ("\n");
13379 b
->loc
->line_number
= sal2
.line
;
13380 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13382 b
->location
.reset (NULL
);
13383 initialize_explicit_location (&explicit_loc
);
13384 explicit_loc
.source_filename
13385 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13386 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13387 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13388 b
->location
= new_explicit_location (&explicit_loc
);
13390 /* Might be nice to check if function changed, and warn if
13397 /* Returns 1 iff locations A and B are sufficiently same that
13398 we don't need to report breakpoint as changed. */
13401 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13405 if (a
->address
!= b
->address
)
13408 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13411 if (a
->enabled
!= b
->enabled
)
13418 if ((a
== NULL
) != (b
== NULL
))
13424 /* Split all locations of B that are bound to PSPACE out of B's
13425 location list to a separate list and return that list's head. If
13426 PSPACE is NULL, hoist out all locations of B. */
13428 static struct bp_location
*
13429 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13431 struct bp_location head
;
13432 struct bp_location
*i
= b
->loc
;
13433 struct bp_location
**i_link
= &b
->loc
;
13434 struct bp_location
*hoisted
= &head
;
13436 if (pspace
== NULL
)
13447 if (i
->pspace
== pspace
)
13462 /* Create new breakpoint locations for B (a hardware or software
13463 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13464 zero, then B is a ranged breakpoint. Only recreates locations for
13465 FILTER_PSPACE. Locations of other program spaces are left
13469 update_breakpoint_locations (struct breakpoint
*b
,
13470 struct program_space
*filter_pspace
,
13471 gdb::array_view
<const symtab_and_line
> sals
,
13472 gdb::array_view
<const symtab_and_line
> sals_end
)
13474 struct bp_location
*existing_locations
;
13476 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13478 /* Ranged breakpoints have only one start location and one end
13480 b
->enable_state
= bp_disabled
;
13481 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13482 "multiple locations found\n"),
13487 /* If there's no new locations, and all existing locations are
13488 pending, don't do anything. This optimizes the common case where
13489 all locations are in the same shared library, that was unloaded.
13490 We'd like to retain the location, so that when the library is
13491 loaded again, we don't loose the enabled/disabled status of the
13492 individual locations. */
13493 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13496 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13498 for (const auto &sal
: sals
)
13500 struct bp_location
*new_loc
;
13502 switch_to_program_space_and_thread (sal
.pspace
);
13504 new_loc
= add_location_to_breakpoint (b
, &sal
);
13506 /* Reparse conditions, they might contain references to the
13508 if (b
->cond_string
!= NULL
)
13512 s
= b
->cond_string
;
13515 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13516 block_for_pc (sal
.pc
),
13519 catch (const gdb_exception_error
&e
)
13521 warning (_("failed to reevaluate condition "
13522 "for breakpoint %d: %s"),
13523 b
->number
, e
.what ());
13524 new_loc
->enabled
= 0;
13528 if (!sals_end
.empty ())
13530 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13532 new_loc
->length
= end
- sals
[0].pc
+ 1;
13536 /* If possible, carry over 'disable' status from existing
13539 struct bp_location
*e
= existing_locations
;
13540 /* If there are multiple breakpoints with the same function name,
13541 e.g. for inline functions, comparing function names won't work.
13542 Instead compare pc addresses; this is just a heuristic as things
13543 may have moved, but in practice it gives the correct answer
13544 often enough until a better solution is found. */
13545 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13547 for (; e
; e
= e
->next
)
13549 if (!e
->enabled
&& e
->function_name
)
13551 struct bp_location
*l
= b
->loc
;
13552 if (have_ambiguous_names
)
13554 for (; l
; l
= l
->next
)
13556 /* Ignore software vs hardware location type at
13557 this point, because with "set breakpoint
13558 auto-hw", after a re-set, locations that were
13559 hardware can end up as software, or vice versa.
13560 As mentioned above, this is an heuristic and in
13561 practice should give the correct answer often
13563 if (breakpoint_locations_match (e
, l
, true))
13572 for (; l
; l
= l
->next
)
13573 if (l
->function_name
13574 && strcmp (e
->function_name
, l
->function_name
) == 0)
13584 if (!locations_are_equal (existing_locations
, b
->loc
))
13585 gdb::observers::breakpoint_modified
.notify (b
);
13588 /* Find the SaL locations corresponding to the given LOCATION.
13589 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13591 static std::vector
<symtab_and_line
>
13592 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13593 struct program_space
*search_pspace
, int *found
)
13595 struct gdb_exception exception
;
13597 gdb_assert (b
->ops
!= NULL
);
13599 std::vector
<symtab_and_line
> sals
;
13603 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13605 catch (gdb_exception_error
&e
)
13607 int not_found_and_ok
= 0;
13609 /* For pending breakpoints, it's expected that parsing will
13610 fail until the right shared library is loaded. User has
13611 already told to create pending breakpoints and don't need
13612 extra messages. If breakpoint is in bp_shlib_disabled
13613 state, then user already saw the message about that
13614 breakpoint being disabled, and don't want to see more
13616 if (e
.error
== NOT_FOUND_ERROR
13617 && (b
->condition_not_parsed
13619 && search_pspace
!= NULL
13620 && b
->loc
->pspace
!= search_pspace
)
13621 || (b
->loc
&& b
->loc
->shlib_disabled
)
13622 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13623 || b
->enable_state
== bp_disabled
))
13624 not_found_and_ok
= 1;
13626 if (!not_found_and_ok
)
13628 /* We surely don't want to warn about the same breakpoint
13629 10 times. One solution, implemented here, is disable
13630 the breakpoint on error. Another solution would be to
13631 have separate 'warning emitted' flag. Since this
13632 happens only when a binary has changed, I don't know
13633 which approach is better. */
13634 b
->enable_state
= bp_disabled
;
13638 exception
= std::move (e
);
13641 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13643 for (auto &sal
: sals
)
13644 resolve_sal_pc (&sal
);
13645 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13647 char *cond_string
, *extra_string
;
13650 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
13651 &cond_string
, &thread
, &task
,
13653 gdb_assert (b
->cond_string
== NULL
);
13655 b
->cond_string
= cond_string
;
13656 b
->thread
= thread
;
13660 xfree (b
->extra_string
);
13661 b
->extra_string
= extra_string
;
13663 b
->condition_not_parsed
= 0;
13666 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13667 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13677 /* The default re_set method, for typical hardware or software
13678 breakpoints. Reevaluate the breakpoint and recreate its
13682 breakpoint_re_set_default (struct breakpoint
*b
)
13684 struct program_space
*filter_pspace
= current_program_space
;
13685 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13688 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13689 filter_pspace
, &found
);
13691 expanded
= std::move (sals
);
13693 if (b
->location_range_end
!= NULL
)
13695 std::vector
<symtab_and_line
> sals_end
13696 = location_to_sals (b
, b
->location_range_end
.get (),
13697 filter_pspace
, &found
);
13699 expanded_end
= std::move (sals_end
);
13702 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13705 /* Default method for creating SALs from an address string. It basically
13706 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13709 create_sals_from_location_default (struct event_location
*location
,
13710 struct linespec_result
*canonical
,
13711 enum bptype type_wanted
)
13713 parse_breakpoint_sals (location
, canonical
);
13716 /* Call create_breakpoints_sal for the given arguments. This is the default
13717 function for the `create_breakpoints_sal' method of
13721 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13722 struct linespec_result
*canonical
,
13723 gdb::unique_xmalloc_ptr
<char> cond_string
,
13724 gdb::unique_xmalloc_ptr
<char> extra_string
,
13725 enum bptype type_wanted
,
13726 enum bpdisp disposition
,
13728 int task
, int ignore_count
,
13729 const struct breakpoint_ops
*ops
,
13730 int from_tty
, int enabled
,
13731 int internal
, unsigned flags
)
13733 create_breakpoints_sal (gdbarch
, canonical
,
13734 std::move (cond_string
),
13735 std::move (extra_string
),
13736 type_wanted
, disposition
,
13737 thread
, task
, ignore_count
, ops
, from_tty
,
13738 enabled
, internal
, flags
);
13741 /* Decode the line represented by S by calling decode_line_full. This is the
13742 default function for the `decode_location' method of breakpoint_ops. */
13744 static std::vector
<symtab_and_line
>
13745 decode_location_default (struct breakpoint
*b
,
13746 struct event_location
*location
,
13747 struct program_space
*search_pspace
)
13749 struct linespec_result canonical
;
13751 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13752 NULL
, 0, &canonical
, multiple_symbols_all
,
13755 /* We should get 0 or 1 resulting SALs. */
13756 gdb_assert (canonical
.lsals
.size () < 2);
13758 if (!canonical
.lsals
.empty ())
13760 const linespec_sals
&lsal
= canonical
.lsals
[0];
13761 return std::move (lsal
.sals
);
13766 /* Reset a breakpoint. */
13769 breakpoint_re_set_one (breakpoint
*b
)
13771 input_radix
= b
->input_radix
;
13772 set_language (b
->language
);
13774 b
->ops
->re_set (b
);
13777 /* Re-set breakpoint locations for the current program space.
13778 Locations bound to other program spaces are left untouched. */
13781 breakpoint_re_set (void)
13783 struct breakpoint
*b
, *b_tmp
;
13786 scoped_restore_current_language save_language
;
13787 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13788 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13790 /* breakpoint_re_set_one sets the current_language to the language
13791 of the breakpoint it is resetting (see prepare_re_set_context)
13792 before re-evaluating the breakpoint's location. This change can
13793 unfortunately get undone by accident if the language_mode is set
13794 to auto, and we either switch frames, or more likely in this context,
13795 we select the current frame.
13797 We prevent this by temporarily turning the language_mode to
13798 language_mode_manual. We restore it once all breakpoints
13799 have been reset. */
13800 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13801 language_mode
= language_mode_manual
;
13803 /* Note: we must not try to insert locations until after all
13804 breakpoints have been re-set. Otherwise, e.g., when re-setting
13805 breakpoint 1, we'd insert the locations of breakpoint 2, which
13806 hadn't been re-set yet, and thus may have stale locations. */
13808 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13812 breakpoint_re_set_one (b
);
13814 catch (const gdb_exception
&ex
)
13816 exception_fprintf (gdb_stderr
, ex
,
13817 "Error in re-setting breakpoint %d: ",
13822 jit_breakpoint_re_set ();
13825 create_overlay_event_breakpoint ();
13826 create_longjmp_master_breakpoint ();
13827 create_std_terminate_master_breakpoint ();
13828 create_exception_master_breakpoint ();
13830 /* Now we can insert. */
13831 update_global_location_list (UGLL_MAY_INSERT
);
13834 /* Reset the thread number of this breakpoint:
13836 - If the breakpoint is for all threads, leave it as-is.
13837 - Else, reset it to the current thread for inferior_ptid. */
13839 breakpoint_re_set_thread (struct breakpoint
*b
)
13841 if (b
->thread
!= -1)
13843 b
->thread
= inferior_thread ()->global_num
;
13845 /* We're being called after following a fork. The new fork is
13846 selected as current, and unless this was a vfork will have a
13847 different program space from the original thread. Reset that
13849 b
->loc
->pspace
= current_program_space
;
13853 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13854 If from_tty is nonzero, it prints a message to that effect,
13855 which ends with a period (no newline). */
13858 set_ignore_count (int bptnum
, int count
, int from_tty
)
13860 struct breakpoint
*b
;
13865 ALL_BREAKPOINTS (b
)
13866 if (b
->number
== bptnum
)
13868 if (is_tracepoint (b
))
13870 if (from_tty
&& count
!= 0)
13871 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13876 b
->ignore_count
= count
;
13880 printf_filtered (_("Will stop next time "
13881 "breakpoint %d is reached."),
13883 else if (count
== 1)
13884 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13887 printf_filtered (_("Will ignore next %d "
13888 "crossings of breakpoint %d."),
13891 gdb::observers::breakpoint_modified
.notify (b
);
13895 error (_("No breakpoint number %d."), bptnum
);
13898 /* Command to set ignore-count of breakpoint N to COUNT. */
13901 ignore_command (const char *args
, int from_tty
)
13903 const char *p
= args
;
13907 error_no_arg (_("a breakpoint number"));
13909 num
= get_number (&p
);
13911 error (_("bad breakpoint number: '%s'"), args
);
13913 error (_("Second argument (specified ignore-count) is missing."));
13915 set_ignore_count (num
,
13916 longest_to_int (value_as_long (parse_and_eval (p
))),
13919 printf_filtered ("\n");
13923 /* Call FUNCTION on each of the breakpoints with numbers in the range
13924 defined by BP_NUM_RANGE (an inclusive range). */
13927 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13928 gdb::function_view
<void (breakpoint
*)> function
)
13930 if (bp_num_range
.first
== 0)
13932 warning (_("bad breakpoint number at or near '%d'"),
13933 bp_num_range
.first
);
13937 struct breakpoint
*b
, *tmp
;
13939 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13941 bool match
= false;
13943 ALL_BREAKPOINTS_SAFE (b
, tmp
)
13944 if (b
->number
== i
)
13951 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
13956 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13960 map_breakpoint_numbers (const char *args
,
13961 gdb::function_view
<void (breakpoint
*)> function
)
13963 if (args
== NULL
|| *args
== '\0')
13964 error_no_arg (_("one or more breakpoint numbers"));
13966 number_or_range_parser
parser (args
);
13968 while (!parser
.finished ())
13970 int num
= parser
.get_number ();
13971 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13975 /* Return the breakpoint location structure corresponding to the
13976 BP_NUM and LOC_NUM values. */
13978 static struct bp_location
*
13979 find_location_by_number (int bp_num
, int loc_num
)
13981 struct breakpoint
*b
;
13983 ALL_BREAKPOINTS (b
)
13984 if (b
->number
== bp_num
)
13989 if (!b
|| b
->number
!= bp_num
)
13990 error (_("Bad breakpoint number '%d'"), bp_num
);
13993 error (_("Bad breakpoint location number '%d'"), loc_num
);
13996 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13997 if (++n
== loc_num
)
14000 error (_("Bad breakpoint location number '%d'"), loc_num
);
14003 /* Modes of operation for extract_bp_num. */
14004 enum class extract_bp_kind
14006 /* Extracting a breakpoint number. */
14009 /* Extracting a location number. */
14013 /* Extract a breakpoint or location number (as determined by KIND)
14014 from the string starting at START. TRAILER is a character which
14015 can be found after the number. If you don't want a trailer, use
14016 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14017 string. This always returns a positive integer. */
14020 extract_bp_num (extract_bp_kind kind
, const char *start
,
14021 int trailer
, const char **end_out
= NULL
)
14023 const char *end
= start
;
14024 int num
= get_number_trailer (&end
, trailer
);
14026 error (kind
== extract_bp_kind::bp
14027 ? _("Negative breakpoint number '%.*s'")
14028 : _("Negative breakpoint location number '%.*s'"),
14029 int (end
- start
), start
);
14031 error (kind
== extract_bp_kind::bp
14032 ? _("Bad breakpoint number '%.*s'")
14033 : _("Bad breakpoint location number '%.*s'"),
14034 int (end
- start
), start
);
14036 if (end_out
!= NULL
)
14041 /* Extract a breakpoint or location range (as determined by KIND) in
14042 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14043 representing the (inclusive) range. The returned pair's elements
14044 are always positive integers. */
14046 static std::pair
<int, int>
14047 extract_bp_or_bp_range (extract_bp_kind kind
,
14048 const std::string
&arg
,
14049 std::string::size_type arg_offset
)
14051 std::pair
<int, int> range
;
14052 const char *bp_loc
= &arg
[arg_offset
];
14053 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14054 if (dash
!= std::string::npos
)
14056 /* bp_loc is a range (x-z). */
14057 if (arg
.length () == dash
+ 1)
14058 error (kind
== extract_bp_kind::bp
14059 ? _("Bad breakpoint number at or near: '%s'")
14060 : _("Bad breakpoint location number at or near: '%s'"),
14064 const char *start_first
= bp_loc
;
14065 const char *start_second
= &arg
[dash
+ 1];
14066 range
.first
= extract_bp_num (kind
, start_first
, '-');
14067 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14069 if (range
.first
> range
.second
)
14070 error (kind
== extract_bp_kind::bp
14071 ? _("Inverted breakpoint range at '%.*s'")
14072 : _("Inverted breakpoint location range at '%.*s'"),
14073 int (end
- start_first
), start_first
);
14077 /* bp_loc is a single value. */
14078 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14079 range
.second
= range
.first
;
14084 /* Extract the breakpoint/location range specified by ARG. Returns
14085 the breakpoint range in BP_NUM_RANGE, and the location range in
14088 ARG may be in any of the following forms:
14090 x where 'x' is a breakpoint number.
14091 x-y where 'x' and 'y' specify a breakpoint numbers range.
14092 x.y where 'x' is a breakpoint number and 'y' a location number.
14093 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14094 location number range.
14098 extract_bp_number_and_location (const std::string
&arg
,
14099 std::pair
<int, int> &bp_num_range
,
14100 std::pair
<int, int> &bp_loc_range
)
14102 std::string::size_type dot
= arg
.find ('.');
14104 if (dot
!= std::string::npos
)
14106 /* Handle 'x.y' and 'x.y-z' cases. */
14108 if (arg
.length () == dot
+ 1 || dot
== 0)
14109 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14112 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14113 bp_num_range
.second
= bp_num_range
.first
;
14115 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14120 /* Handle x and x-y cases. */
14122 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14123 bp_loc_range
.first
= 0;
14124 bp_loc_range
.second
= 0;
14128 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14129 specifies whether to enable or disable. */
14132 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14134 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14137 if (loc
->enabled
!= enable
)
14139 loc
->enabled
= enable
;
14140 mark_breakpoint_location_modified (loc
);
14142 if (target_supports_enable_disable_tracepoint ()
14143 && current_trace_status ()->running
&& loc
->owner
14144 && is_tracepoint (loc
->owner
))
14145 target_disable_tracepoint (loc
);
14147 update_global_location_list (UGLL_DONT_INSERT
);
14149 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14152 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14153 number of the breakpoint, and BP_LOC_RANGE specifies the
14154 (inclusive) range of location numbers of that breakpoint to
14155 enable/disable. ENABLE specifies whether to enable or disable the
14159 enable_disable_breakpoint_location_range (int bp_num
,
14160 std::pair
<int, int> &bp_loc_range
,
14163 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14164 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14167 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14168 If from_tty is nonzero, it prints a message to that effect,
14169 which ends with a period (no newline). */
14172 disable_breakpoint (struct breakpoint
*bpt
)
14174 /* Never disable a watchpoint scope breakpoint; we want to
14175 hit them when we leave scope so we can delete both the
14176 watchpoint and its scope breakpoint at that time. */
14177 if (bpt
->type
== bp_watchpoint_scope
)
14180 bpt
->enable_state
= bp_disabled
;
14182 /* Mark breakpoint locations modified. */
14183 mark_breakpoint_modified (bpt
);
14185 if (target_supports_enable_disable_tracepoint ()
14186 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14188 struct bp_location
*location
;
14190 for (location
= bpt
->loc
; location
; location
= location
->next
)
14191 target_disable_tracepoint (location
);
14194 update_global_location_list (UGLL_DONT_INSERT
);
14196 gdb::observers::breakpoint_modified
.notify (bpt
);
14199 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14200 specified in ARGS. ARGS may be in any of the formats handled by
14201 extract_bp_number_and_location. ENABLE specifies whether to enable
14202 or disable the breakpoints/locations. */
14205 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14209 struct breakpoint
*bpt
;
14211 ALL_BREAKPOINTS (bpt
)
14212 if (user_breakpoint_p (bpt
))
14215 enable_breakpoint (bpt
);
14217 disable_breakpoint (bpt
);
14222 std::string num
= extract_arg (&args
);
14224 while (!num
.empty ())
14226 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14228 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14230 if (bp_loc_range
.first
== bp_loc_range
.second
14231 && bp_loc_range
.first
== 0)
14233 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14234 map_breakpoint_number_range (bp_num_range
,
14236 ? enable_breakpoint
14237 : disable_breakpoint
);
14241 /* Handle breakpoint ids with formats 'x.y' or
14243 enable_disable_breakpoint_location_range
14244 (bp_num_range
.first
, bp_loc_range
, enable
);
14246 num
= extract_arg (&args
);
14251 /* The disable command disables the specified breakpoints/locations
14252 (or all defined breakpoints) so they're no longer effective in
14253 stopping the inferior. ARGS may be in any of the forms defined in
14254 extract_bp_number_and_location. */
14257 disable_command (const char *args
, int from_tty
)
14259 enable_disable_command (args
, from_tty
, false);
14263 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14266 int target_resources_ok
;
14268 if (bpt
->type
== bp_hardware_breakpoint
)
14271 i
= hw_breakpoint_used_count ();
14272 target_resources_ok
=
14273 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14275 if (target_resources_ok
== 0)
14276 error (_("No hardware breakpoint support in the target."));
14277 else if (target_resources_ok
< 0)
14278 error (_("Hardware breakpoints used exceeds limit."));
14281 if (is_watchpoint (bpt
))
14283 /* Initialize it just to avoid a GCC false warning. */
14284 enum enable_state orig_enable_state
= bp_disabled
;
14288 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14290 orig_enable_state
= bpt
->enable_state
;
14291 bpt
->enable_state
= bp_enabled
;
14292 update_watchpoint (w
, 1 /* reparse */);
14294 catch (const gdb_exception
&e
)
14296 bpt
->enable_state
= orig_enable_state
;
14297 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14303 bpt
->enable_state
= bp_enabled
;
14305 /* Mark breakpoint locations modified. */
14306 mark_breakpoint_modified (bpt
);
14308 if (target_supports_enable_disable_tracepoint ()
14309 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14311 struct bp_location
*location
;
14313 for (location
= bpt
->loc
; location
; location
= location
->next
)
14314 target_enable_tracepoint (location
);
14317 bpt
->disposition
= disposition
;
14318 bpt
->enable_count
= count
;
14319 update_global_location_list (UGLL_MAY_INSERT
);
14321 gdb::observers::breakpoint_modified
.notify (bpt
);
14326 enable_breakpoint (struct breakpoint
*bpt
)
14328 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14331 /* The enable command enables the specified breakpoints/locations (or
14332 all defined breakpoints) so they once again become (or continue to
14333 be) effective in stopping the inferior. ARGS may be in any of the
14334 forms defined in extract_bp_number_and_location. */
14337 enable_command (const char *args
, int from_tty
)
14339 enable_disable_command (args
, from_tty
, true);
14343 enable_once_command (const char *args
, int from_tty
)
14345 map_breakpoint_numbers
14346 (args
, [&] (breakpoint
*b
)
14348 iterate_over_related_breakpoints
14349 (b
, [&] (breakpoint
*bpt
)
14351 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14357 enable_count_command (const char *args
, int from_tty
)
14362 error_no_arg (_("hit count"));
14364 count
= get_number (&args
);
14366 map_breakpoint_numbers
14367 (args
, [&] (breakpoint
*b
)
14369 iterate_over_related_breakpoints
14370 (b
, [&] (breakpoint
*bpt
)
14372 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14378 enable_delete_command (const char *args
, int from_tty
)
14380 map_breakpoint_numbers
14381 (args
, [&] (breakpoint
*b
)
14383 iterate_over_related_breakpoints
14384 (b
, [&] (breakpoint
*bpt
)
14386 enable_breakpoint_disp (bpt
, disp_del
, 1);
14391 /* Invalidate last known value of any hardware watchpoint if
14392 the memory which that value represents has been written to by
14396 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14397 CORE_ADDR addr
, ssize_t len
,
14398 const bfd_byte
*data
)
14400 struct breakpoint
*bp
;
14402 ALL_BREAKPOINTS (bp
)
14403 if (bp
->enable_state
== bp_enabled
14404 && bp
->type
== bp_hardware_watchpoint
)
14406 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14408 if (wp
->val_valid
&& wp
->val
!= nullptr)
14410 struct bp_location
*loc
;
14412 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14413 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14414 && loc
->address
+ loc
->length
> addr
14415 && addr
+ len
> loc
->address
)
14418 wp
->val_valid
= false;
14424 /* Create and insert a breakpoint for software single step. */
14427 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14428 const address_space
*aspace
,
14431 struct thread_info
*tp
= inferior_thread ();
14432 struct symtab_and_line sal
;
14433 CORE_ADDR pc
= next_pc
;
14435 if (tp
->control
.single_step_breakpoints
== NULL
)
14437 tp
->control
.single_step_breakpoints
14438 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14441 sal
= find_pc_line (pc
, 0);
14443 sal
.section
= find_pc_overlay (pc
);
14444 sal
.explicit_pc
= 1;
14445 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14447 update_global_location_list (UGLL_INSERT
);
14450 /* Insert single step breakpoints according to the current state. */
14453 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14455 struct regcache
*regcache
= get_current_regcache ();
14456 std::vector
<CORE_ADDR
> next_pcs
;
14458 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14460 if (!next_pcs
.empty ())
14462 struct frame_info
*frame
= get_current_frame ();
14463 const address_space
*aspace
= get_frame_address_space (frame
);
14465 for (CORE_ADDR pc
: next_pcs
)
14466 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14474 /* See breakpoint.h. */
14477 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14478 const address_space
*aspace
,
14481 struct bp_location
*loc
;
14483 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14485 && breakpoint_location_address_match (loc
, aspace
, pc
))
14491 /* Check whether a software single-step breakpoint is inserted at
14495 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14498 struct breakpoint
*bpt
;
14500 ALL_BREAKPOINTS (bpt
)
14502 if (bpt
->type
== bp_single_step
14503 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14509 /* Tracepoint-specific operations. */
14511 /* Set tracepoint count to NUM. */
14513 set_tracepoint_count (int num
)
14515 tracepoint_count
= num
;
14516 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14520 trace_command (const char *arg
, int from_tty
)
14522 event_location_up location
= string_to_event_location (&arg
,
14524 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
14525 (location
.get (), true /* is_tracepoint */);
14527 create_breakpoint (get_current_arch (),
14529 NULL
, 0, arg
, 1 /* parse arg */,
14531 bp_tracepoint
/* type_wanted */,
14532 0 /* Ignore count */,
14533 pending_break_support
,
14537 0 /* internal */, 0);
14541 ftrace_command (const char *arg
, int from_tty
)
14543 event_location_up location
= string_to_event_location (&arg
,
14545 create_breakpoint (get_current_arch (),
14547 NULL
, 0, arg
, 1 /* parse arg */,
14549 bp_fast_tracepoint
/* type_wanted */,
14550 0 /* Ignore count */,
14551 pending_break_support
,
14552 &tracepoint_breakpoint_ops
,
14555 0 /* internal */, 0);
14558 /* strace command implementation. Creates a static tracepoint. */
14561 strace_command (const char *arg
, int from_tty
)
14563 struct breakpoint_ops
*ops
;
14564 event_location_up location
;
14566 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14567 or with a normal static tracepoint. */
14568 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14570 ops
= &strace_marker_breakpoint_ops
;
14571 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14575 ops
= &tracepoint_breakpoint_ops
;
14576 location
= string_to_event_location (&arg
, current_language
);
14579 create_breakpoint (get_current_arch (),
14581 NULL
, 0, arg
, 1 /* parse arg */,
14583 bp_static_tracepoint
/* type_wanted */,
14584 0 /* Ignore count */,
14585 pending_break_support
,
14589 0 /* internal */, 0);
14592 /* Set up a fake reader function that gets command lines from a linked
14593 list that was acquired during tracepoint uploading. */
14595 static struct uploaded_tp
*this_utp
;
14596 static int next_cmd
;
14599 read_uploaded_action (void)
14601 char *rslt
= nullptr;
14603 if (next_cmd
< this_utp
->cmd_strings
.size ())
14605 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14612 /* Given information about a tracepoint as recorded on a target (which
14613 can be either a live system or a trace file), attempt to create an
14614 equivalent GDB tracepoint. This is not a reliable process, since
14615 the target does not necessarily have all the information used when
14616 the tracepoint was originally defined. */
14618 struct tracepoint
*
14619 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14621 const char *addr_str
;
14622 char small_buf
[100];
14623 struct tracepoint
*tp
;
14625 if (utp
->at_string
)
14626 addr_str
= utp
->at_string
.get ();
14629 /* In the absence of a source location, fall back to raw
14630 address. Since there is no way to confirm that the address
14631 means the same thing as when the trace was started, warn the
14633 warning (_("Uploaded tracepoint %d has no "
14634 "source location, using raw address"),
14636 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14637 addr_str
= small_buf
;
14640 /* There's not much we can do with a sequence of bytecodes. */
14641 if (utp
->cond
&& !utp
->cond_string
)
14642 warning (_("Uploaded tracepoint %d condition "
14643 "has no source form, ignoring it"),
14646 event_location_up location
= string_to_event_location (&addr_str
,
14648 if (!create_breakpoint (get_current_arch (),
14650 utp
->cond_string
.get (), -1, addr_str
,
14651 0 /* parse cond/thread */,
14653 utp
->type
/* type_wanted */,
14654 0 /* Ignore count */,
14655 pending_break_support
,
14656 &tracepoint_breakpoint_ops
,
14658 utp
->enabled
/* enabled */,
14660 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14663 /* Get the tracepoint we just created. */
14664 tp
= get_tracepoint (tracepoint_count
);
14665 gdb_assert (tp
!= NULL
);
14669 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14672 trace_pass_command (small_buf
, 0);
14675 /* If we have uploaded versions of the original commands, set up a
14676 special-purpose "reader" function and call the usual command line
14677 reader, then pass the result to the breakpoint command-setting
14679 if (!utp
->cmd_strings
.empty ())
14681 counted_command_line cmd_list
;
14686 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14688 breakpoint_set_commands (tp
, std::move (cmd_list
));
14690 else if (!utp
->actions
.empty ()
14691 || !utp
->step_actions
.empty ())
14692 warning (_("Uploaded tracepoint %d actions "
14693 "have no source form, ignoring them"),
14696 /* Copy any status information that might be available. */
14697 tp
->hit_count
= utp
->hit_count
;
14698 tp
->traceframe_usage
= utp
->traceframe_usage
;
14703 /* Print information on tracepoint number TPNUM_EXP, or all if
14707 info_tracepoints_command (const char *args
, int from_tty
)
14709 struct ui_out
*uiout
= current_uiout
;
14712 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14714 if (num_printed
== 0)
14716 if (args
== NULL
|| *args
== '\0')
14717 uiout
->message ("No tracepoints.\n");
14719 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14722 default_collect_info ();
14725 /* The 'enable trace' command enables tracepoints.
14726 Not supported by all targets. */
14728 enable_trace_command (const char *args
, int from_tty
)
14730 enable_command (args
, from_tty
);
14733 /* The 'disable trace' command disables tracepoints.
14734 Not supported by all targets. */
14736 disable_trace_command (const char *args
, int from_tty
)
14738 disable_command (args
, from_tty
);
14741 /* Remove a tracepoint (or all if no argument). */
14743 delete_trace_command (const char *arg
, int from_tty
)
14745 struct breakpoint
*b
, *b_tmp
;
14751 int breaks_to_delete
= 0;
14753 /* Delete all breakpoints if no argument.
14754 Do not delete internal or call-dummy breakpoints, these
14755 have to be deleted with an explicit breakpoint number
14757 ALL_TRACEPOINTS (b
)
14758 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14760 breaks_to_delete
= 1;
14764 /* Ask user only if there are some breakpoints to delete. */
14766 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14768 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14769 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14770 delete_breakpoint (b
);
14774 map_breakpoint_numbers
14775 (arg
, [&] (breakpoint
*br
)
14777 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14781 /* Helper function for trace_pass_command. */
14784 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14786 tp
->pass_count
= count
;
14787 gdb::observers::breakpoint_modified
.notify (tp
);
14789 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14790 tp
->number
, count
);
14793 /* Set passcount for tracepoint.
14795 First command argument is passcount, second is tracepoint number.
14796 If tracepoint number omitted, apply to most recently defined.
14797 Also accepts special argument "all". */
14800 trace_pass_command (const char *args
, int from_tty
)
14802 struct tracepoint
*t1
;
14805 if (args
== 0 || *args
== 0)
14806 error (_("passcount command requires an "
14807 "argument (count + optional TP num)"));
14809 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14811 args
= skip_spaces (args
);
14812 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14814 struct breakpoint
*b
;
14816 args
+= 3; /* Skip special argument "all". */
14818 error (_("Junk at end of arguments."));
14820 ALL_TRACEPOINTS (b
)
14822 t1
= (struct tracepoint
*) b
;
14823 trace_pass_set_count (t1
, count
, from_tty
);
14826 else if (*args
== '\0')
14828 t1
= get_tracepoint_by_number (&args
, NULL
);
14830 trace_pass_set_count (t1
, count
, from_tty
);
14834 number_or_range_parser
parser (args
);
14835 while (!parser
.finished ())
14837 t1
= get_tracepoint_by_number (&args
, &parser
);
14839 trace_pass_set_count (t1
, count
, from_tty
);
14844 struct tracepoint
*
14845 get_tracepoint (int num
)
14847 struct breakpoint
*t
;
14849 ALL_TRACEPOINTS (t
)
14850 if (t
->number
== num
)
14851 return (struct tracepoint
*) t
;
14856 /* Find the tracepoint with the given target-side number (which may be
14857 different from the tracepoint number after disconnecting and
14860 struct tracepoint
*
14861 get_tracepoint_by_number_on_target (int num
)
14863 struct breakpoint
*b
;
14865 ALL_TRACEPOINTS (b
)
14867 struct tracepoint
*t
= (struct tracepoint
*) b
;
14869 if (t
->number_on_target
== num
)
14876 /* Utility: parse a tracepoint number and look it up in the list.
14877 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14878 If the argument is missing, the most recent tracepoint
14879 (tracepoint_count) is returned. */
14881 struct tracepoint
*
14882 get_tracepoint_by_number (const char **arg
,
14883 number_or_range_parser
*parser
)
14885 struct breakpoint
*t
;
14887 const char *instring
= arg
== NULL
? NULL
: *arg
;
14889 if (parser
!= NULL
)
14891 gdb_assert (!parser
->finished ());
14892 tpnum
= parser
->get_number ();
14894 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14895 tpnum
= tracepoint_count
;
14897 tpnum
= get_number (arg
);
14901 if (instring
&& *instring
)
14902 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14905 printf_filtered (_("No previous tracepoint\n"));
14909 ALL_TRACEPOINTS (t
)
14910 if (t
->number
== tpnum
)
14912 return (struct tracepoint
*) t
;
14915 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
14920 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14922 if (b
->thread
!= -1)
14923 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
14926 fprintf_unfiltered (fp
, " task %d", b
->task
);
14928 fprintf_unfiltered (fp
, "\n");
14931 /* Save information on user settable breakpoints (watchpoints, etc) to
14932 a new script file named FILENAME. If FILTER is non-NULL, call it
14933 on each breakpoint and only include the ones for which it returns
14937 save_breakpoints (const char *filename
, int from_tty
,
14938 bool (*filter
) (const struct breakpoint
*))
14940 struct breakpoint
*tp
;
14942 int extra_trace_bits
= 0;
14944 if (filename
== 0 || *filename
== 0)
14945 error (_("Argument required (file name in which to save)"));
14947 /* See if we have anything to save. */
14948 ALL_BREAKPOINTS (tp
)
14950 /* Skip internal and momentary breakpoints. */
14951 if (!user_breakpoint_p (tp
))
14954 /* If we have a filter, only save the breakpoints it accepts. */
14955 if (filter
&& !filter (tp
))
14960 if (is_tracepoint (tp
))
14962 extra_trace_bits
= 1;
14964 /* We can stop searching. */
14971 warning (_("Nothing to save."));
14975 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14979 if (!fp
.open (expanded_filename
.get (), "w"))
14980 error (_("Unable to open file '%s' for saving (%s)"),
14981 expanded_filename
.get (), safe_strerror (errno
));
14983 if (extra_trace_bits
)
14984 save_trace_state_variables (&fp
);
14986 ALL_BREAKPOINTS (tp
)
14988 /* Skip internal and momentary breakpoints. */
14989 if (!user_breakpoint_p (tp
))
14992 /* If we have a filter, only save the breakpoints it accepts. */
14993 if (filter
&& !filter (tp
))
14996 tp
->ops
->print_recreate (tp
, &fp
);
14998 /* Note, we can't rely on tp->number for anything, as we can't
14999 assume the recreated breakpoint numbers will match. Use $bpnum
15002 if (tp
->cond_string
)
15003 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15005 if (tp
->ignore_count
)
15006 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15008 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15010 fp
.puts (" commands\n");
15012 current_uiout
->redirect (&fp
);
15015 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15017 catch (const gdb_exception
&ex
)
15019 current_uiout
->redirect (NULL
);
15023 current_uiout
->redirect (NULL
);
15024 fp
.puts (" end\n");
15027 if (tp
->enable_state
== bp_disabled
)
15028 fp
.puts ("disable $bpnum\n");
15030 /* If this is a multi-location breakpoint, check if the locations
15031 should be individually disabled. Watchpoint locations are
15032 special, and not user visible. */
15033 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15035 struct bp_location
*loc
;
15038 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15040 fp
.printf ("disable $bpnum.%d\n", n
);
15044 if (extra_trace_bits
&& *default_collect
)
15045 fp
.printf ("set default-collect %s\n", default_collect
);
15048 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15051 /* The `save breakpoints' command. */
15054 save_breakpoints_command (const char *args
, int from_tty
)
15056 save_breakpoints (args
, from_tty
, NULL
);
15059 /* The `save tracepoints' command. */
15062 save_tracepoints_command (const char *args
, int from_tty
)
15064 save_breakpoints (args
, from_tty
, is_tracepoint
);
15067 /* Create a vector of all tracepoints. */
15069 std::vector
<breakpoint
*>
15070 all_tracepoints (void)
15072 std::vector
<breakpoint
*> tp_vec
;
15073 struct breakpoint
*tp
;
15075 ALL_TRACEPOINTS (tp
)
15077 tp_vec
.push_back (tp
);
15084 /* This help string is used to consolidate all the help string for specifying
15085 locations used by several commands. */
15087 #define LOCATION_HELP_STRING \
15088 "Linespecs are colon-separated lists of location parameters, such as\n\
15089 source filename, function name, label name, and line number.\n\
15090 Example: To specify the start of a label named \"the_top\" in the\n\
15091 function \"fact\" in the file \"factorial.c\", use\n\
15092 \"factorial.c:fact:the_top\".\n\
15094 Address locations begin with \"*\" and specify an exact address in the\n\
15095 program. Example: To specify the fourth byte past the start function\n\
15096 \"main\", use \"*main + 4\".\n\
15098 Explicit locations are similar to linespecs but use an option/argument\n\
15099 syntax to specify location parameters.\n\
15100 Example: To specify the start of the label named \"the_top\" in the\n\
15101 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15102 -function fact -label the_top\".\n\
15104 By default, a specified function is matched against the program's\n\
15105 functions in all scopes. For C++, this means in all namespaces and\n\
15106 classes. For Ada, this means in all packages. E.g., in C++,\n\
15107 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15108 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15109 specified name as a complete fully-qualified name instead."
15111 /* This help string is used for the break, hbreak, tbreak and thbreak
15112 commands. It is defined as a macro to prevent duplication.
15113 COMMAND should be a string constant containing the name of the
15116 #define BREAK_ARGS_HELP(command) \
15117 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15118 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15119 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15120 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15121 `-probe-dtrace' (for a DTrace probe).\n\
15122 LOCATION may be a linespec, address, or explicit location as described\n\
15125 With no LOCATION, uses current execution address of the selected\n\
15126 stack frame. This is useful for breaking on return to a stack frame.\n\
15128 THREADNUM is the number from \"info threads\".\n\
15129 CONDITION is a boolean expression.\n\
15130 \n" LOCATION_HELP_STRING "\n\n\
15131 Multiple breakpoints at one place are permitted, and useful if their\n\
15132 conditions are different.\n\
15134 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15136 /* List of subcommands for "catch". */
15137 static struct cmd_list_element
*catch_cmdlist
;
15139 /* List of subcommands for "tcatch". */
15140 static struct cmd_list_element
*tcatch_cmdlist
;
15143 add_catch_command (const char *name
, const char *docstring
,
15144 cmd_const_sfunc_ftype
*sfunc
,
15145 completer_ftype
*completer
,
15146 void *user_data_catch
,
15147 void *user_data_tcatch
)
15149 struct cmd_list_element
*command
;
15151 command
= add_cmd (name
, class_breakpoint
, docstring
,
15153 set_cmd_sfunc (command
, sfunc
);
15154 set_cmd_context (command
, user_data_catch
);
15155 set_cmd_completer (command
, completer
);
15157 command
= add_cmd (name
, class_breakpoint
, docstring
,
15159 set_cmd_sfunc (command
, sfunc
);
15160 set_cmd_context (command
, user_data_tcatch
);
15161 set_cmd_completer (command
, completer
);
15164 struct breakpoint
*
15165 iterate_over_breakpoints (gdb::function_view
<bool (breakpoint
*)> callback
)
15167 struct breakpoint
*b
, *b_tmp
;
15169 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15178 /* Zero if any of the breakpoint's locations could be a location where
15179 functions have been inlined, nonzero otherwise. */
15182 is_non_inline_function (struct breakpoint
*b
)
15184 /* The shared library event breakpoint is set on the address of a
15185 non-inline function. */
15186 if (b
->type
== bp_shlib_event
)
15192 /* Nonzero if the specified PC cannot be a location where functions
15193 have been inlined. */
15196 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15197 const struct target_waitstatus
*ws
)
15199 struct breakpoint
*b
;
15200 struct bp_location
*bl
;
15202 ALL_BREAKPOINTS (b
)
15204 if (!is_non_inline_function (b
))
15207 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15209 if (!bl
->shlib_disabled
15210 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15218 /* Remove any references to OBJFILE which is going to be freed. */
15221 breakpoint_free_objfile (struct objfile
*objfile
)
15223 struct bp_location
**locp
, *loc
;
15225 ALL_BP_LOCATIONS (loc
, locp
)
15226 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15227 loc
->symtab
= NULL
;
15231 initialize_breakpoint_ops (void)
15233 static int initialized
= 0;
15235 struct breakpoint_ops
*ops
;
15241 /* The breakpoint_ops structure to be inherit by all kinds of
15242 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15243 internal and momentary breakpoints, etc.). */
15244 ops
= &bkpt_base_breakpoint_ops
;
15245 *ops
= base_breakpoint_ops
;
15246 ops
->re_set
= bkpt_re_set
;
15247 ops
->insert_location
= bkpt_insert_location
;
15248 ops
->remove_location
= bkpt_remove_location
;
15249 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15250 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15251 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15252 ops
->decode_location
= bkpt_decode_location
;
15254 /* The breakpoint_ops structure to be used in regular breakpoints. */
15255 ops
= &bkpt_breakpoint_ops
;
15256 *ops
= bkpt_base_breakpoint_ops
;
15257 ops
->re_set
= bkpt_re_set
;
15258 ops
->resources_needed
= bkpt_resources_needed
;
15259 ops
->print_it
= bkpt_print_it
;
15260 ops
->print_mention
= bkpt_print_mention
;
15261 ops
->print_recreate
= bkpt_print_recreate
;
15263 /* Ranged breakpoints. */
15264 ops
= &ranged_breakpoint_ops
;
15265 *ops
= bkpt_breakpoint_ops
;
15266 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15267 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15268 ops
->print_it
= print_it_ranged_breakpoint
;
15269 ops
->print_one
= print_one_ranged_breakpoint
;
15270 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15271 ops
->print_mention
= print_mention_ranged_breakpoint
;
15272 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15274 /* Internal breakpoints. */
15275 ops
= &internal_breakpoint_ops
;
15276 *ops
= bkpt_base_breakpoint_ops
;
15277 ops
->re_set
= internal_bkpt_re_set
;
15278 ops
->check_status
= internal_bkpt_check_status
;
15279 ops
->print_it
= internal_bkpt_print_it
;
15280 ops
->print_mention
= internal_bkpt_print_mention
;
15282 /* Momentary breakpoints. */
15283 ops
= &momentary_breakpoint_ops
;
15284 *ops
= bkpt_base_breakpoint_ops
;
15285 ops
->re_set
= momentary_bkpt_re_set
;
15286 ops
->check_status
= momentary_bkpt_check_status
;
15287 ops
->print_it
= momentary_bkpt_print_it
;
15288 ops
->print_mention
= momentary_bkpt_print_mention
;
15290 /* Probe breakpoints. */
15291 ops
= &bkpt_probe_breakpoint_ops
;
15292 *ops
= bkpt_breakpoint_ops
;
15293 ops
->insert_location
= bkpt_probe_insert_location
;
15294 ops
->remove_location
= bkpt_probe_remove_location
;
15295 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15296 ops
->decode_location
= bkpt_probe_decode_location
;
15299 ops
= &watchpoint_breakpoint_ops
;
15300 *ops
= base_breakpoint_ops
;
15301 ops
->re_set
= re_set_watchpoint
;
15302 ops
->insert_location
= insert_watchpoint
;
15303 ops
->remove_location
= remove_watchpoint
;
15304 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15305 ops
->check_status
= check_status_watchpoint
;
15306 ops
->resources_needed
= resources_needed_watchpoint
;
15307 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15308 ops
->print_it
= print_it_watchpoint
;
15309 ops
->print_mention
= print_mention_watchpoint
;
15310 ops
->print_recreate
= print_recreate_watchpoint
;
15311 ops
->explains_signal
= explains_signal_watchpoint
;
15313 /* Masked watchpoints. */
15314 ops
= &masked_watchpoint_breakpoint_ops
;
15315 *ops
= watchpoint_breakpoint_ops
;
15316 ops
->insert_location
= insert_masked_watchpoint
;
15317 ops
->remove_location
= remove_masked_watchpoint
;
15318 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15319 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15320 ops
->print_it
= print_it_masked_watchpoint
;
15321 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15322 ops
->print_mention
= print_mention_masked_watchpoint
;
15323 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15326 ops
= &tracepoint_breakpoint_ops
;
15327 *ops
= base_breakpoint_ops
;
15328 ops
->re_set
= tracepoint_re_set
;
15329 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15330 ops
->print_one_detail
= tracepoint_print_one_detail
;
15331 ops
->print_mention
= tracepoint_print_mention
;
15332 ops
->print_recreate
= tracepoint_print_recreate
;
15333 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15334 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15335 ops
->decode_location
= tracepoint_decode_location
;
15337 /* Probe tracepoints. */
15338 ops
= &tracepoint_probe_breakpoint_ops
;
15339 *ops
= tracepoint_breakpoint_ops
;
15340 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15341 ops
->decode_location
= tracepoint_probe_decode_location
;
15343 /* Static tracepoints with marker (`-m'). */
15344 ops
= &strace_marker_breakpoint_ops
;
15345 *ops
= tracepoint_breakpoint_ops
;
15346 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15347 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15348 ops
->decode_location
= strace_marker_decode_location
;
15350 /* Fork catchpoints. */
15351 ops
= &catch_fork_breakpoint_ops
;
15352 *ops
= base_breakpoint_ops
;
15353 ops
->insert_location
= insert_catch_fork
;
15354 ops
->remove_location
= remove_catch_fork
;
15355 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15356 ops
->print_it
= print_it_catch_fork
;
15357 ops
->print_one
= print_one_catch_fork
;
15358 ops
->print_mention
= print_mention_catch_fork
;
15359 ops
->print_recreate
= print_recreate_catch_fork
;
15361 /* Vfork catchpoints. */
15362 ops
= &catch_vfork_breakpoint_ops
;
15363 *ops
= base_breakpoint_ops
;
15364 ops
->insert_location
= insert_catch_vfork
;
15365 ops
->remove_location
= remove_catch_vfork
;
15366 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15367 ops
->print_it
= print_it_catch_vfork
;
15368 ops
->print_one
= print_one_catch_vfork
;
15369 ops
->print_mention
= print_mention_catch_vfork
;
15370 ops
->print_recreate
= print_recreate_catch_vfork
;
15372 /* Exec catchpoints. */
15373 ops
= &catch_exec_breakpoint_ops
;
15374 *ops
= base_breakpoint_ops
;
15375 ops
->insert_location
= insert_catch_exec
;
15376 ops
->remove_location
= remove_catch_exec
;
15377 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15378 ops
->print_it
= print_it_catch_exec
;
15379 ops
->print_one
= print_one_catch_exec
;
15380 ops
->print_mention
= print_mention_catch_exec
;
15381 ops
->print_recreate
= print_recreate_catch_exec
;
15383 /* Solib-related catchpoints. */
15384 ops
= &catch_solib_breakpoint_ops
;
15385 *ops
= base_breakpoint_ops
;
15386 ops
->insert_location
= insert_catch_solib
;
15387 ops
->remove_location
= remove_catch_solib
;
15388 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15389 ops
->check_status
= check_status_catch_solib
;
15390 ops
->print_it
= print_it_catch_solib
;
15391 ops
->print_one
= print_one_catch_solib
;
15392 ops
->print_mention
= print_mention_catch_solib
;
15393 ops
->print_recreate
= print_recreate_catch_solib
;
15395 ops
= &dprintf_breakpoint_ops
;
15396 *ops
= bkpt_base_breakpoint_ops
;
15397 ops
->re_set
= dprintf_re_set
;
15398 ops
->resources_needed
= bkpt_resources_needed
;
15399 ops
->print_it
= bkpt_print_it
;
15400 ops
->print_mention
= bkpt_print_mention
;
15401 ops
->print_recreate
= dprintf_print_recreate
;
15402 ops
->after_condition_true
= dprintf_after_condition_true
;
15403 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15406 /* Chain containing all defined "enable breakpoint" subcommands. */
15408 static struct cmd_list_element
*enablebreaklist
= NULL
;
15410 /* See breakpoint.h. */
15412 cmd_list_element
*commands_cmd_element
= nullptr;
15414 void _initialize_breakpoint ();
15416 _initialize_breakpoint ()
15418 struct cmd_list_element
*c
;
15420 initialize_breakpoint_ops ();
15422 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
);
15423 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
);
15424 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
);
15426 breakpoint_chain
= 0;
15427 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15428 before a breakpoint is set. */
15429 breakpoint_count
= 0;
15431 tracepoint_count
= 0;
15433 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15434 Set ignore-count of breakpoint number N to COUNT.\n\
15435 Usage is `ignore N COUNT'."));
15437 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15438 commands_command
, _("\
15439 Set commands to be executed when the given breakpoints are hit.\n\
15440 Give a space-separated breakpoint list as argument after \"commands\".\n\
15441 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15443 With no argument, the targeted breakpoint is the last one set.\n\
15444 The commands themselves follow starting on the next line.\n\
15445 Type a line containing \"end\" to indicate the end of them.\n\
15446 Give \"silent\" as the first line to make the breakpoint silent;\n\
15447 then no output is printed when it is hit, except what the commands print."));
15449 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15450 Specify breakpoint number N to break only if COND is true.\n\
15451 Usage is `condition N COND', where N is an integer and COND is an\n\
15452 expression to be evaluated whenever breakpoint N is reached."));
15453 set_cmd_completer (c
, condition_completer
);
15455 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15456 Set a temporary breakpoint.\n\
15457 Like \"break\" except the breakpoint is only temporary,\n\
15458 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15459 by using \"enable delete\" on the breakpoint number.\n\
15461 BREAK_ARGS_HELP ("tbreak")));
15462 set_cmd_completer (c
, location_completer
);
15464 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15465 Set a hardware assisted breakpoint.\n\
15466 Like \"break\" except the breakpoint requires hardware support,\n\
15467 some target hardware may not have this support.\n\
15469 BREAK_ARGS_HELP ("hbreak")));
15470 set_cmd_completer (c
, location_completer
);
15472 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15473 Set a temporary hardware assisted breakpoint.\n\
15474 Like \"hbreak\" except the breakpoint is only temporary,\n\
15475 so it will be deleted when hit.\n\
15477 BREAK_ARGS_HELP ("thbreak")));
15478 set_cmd_completer (c
, location_completer
);
15480 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15481 Enable all or some breakpoints.\n\
15482 Usage: enable [BREAKPOINTNUM]...\n\
15483 Give breakpoint numbers (separated by spaces) as arguments.\n\
15484 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15485 This is used to cancel the effect of the \"disable\" command.\n\
15486 With a subcommand you can enable temporarily."),
15487 &enablelist
, "enable ", 1, &cmdlist
);
15489 add_com_alias ("en", "enable", class_breakpoint
, 1);
15491 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15492 Enable all or some breakpoints.\n\
15493 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15494 Give breakpoint numbers (separated by spaces) as arguments.\n\
15495 This is used to cancel the effect of the \"disable\" command.\n\
15496 May be abbreviated to simply \"enable\"."),
15497 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15499 add_cmd ("once", no_class
, enable_once_command
, _("\
15500 Enable some breakpoints for one hit.\n\
15501 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15502 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15505 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15506 Enable some breakpoints and delete when hit.\n\
15507 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15508 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15511 add_cmd ("count", no_class
, enable_count_command
, _("\
15512 Enable some breakpoints for COUNT hits.\n\
15513 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15514 If a breakpoint is hit while enabled in this fashion,\n\
15515 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15518 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15519 Enable some breakpoints and delete when hit.\n\
15520 Usage: enable delete BREAKPOINTNUM...\n\
15521 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15524 add_cmd ("once", no_class
, enable_once_command
, _("\
15525 Enable some breakpoints for one hit.\n\
15526 Usage: enable once BREAKPOINTNUM...\n\
15527 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15530 add_cmd ("count", no_class
, enable_count_command
, _("\
15531 Enable some breakpoints for COUNT hits.\n\
15532 Usage: enable count COUNT BREAKPOINTNUM...\n\
15533 If a breakpoint is hit while enabled in this fashion,\n\
15534 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15537 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15538 Disable all or some breakpoints.\n\
15539 Usage: disable [BREAKPOINTNUM]...\n\
15540 Arguments are breakpoint numbers with spaces in between.\n\
15541 To disable all breakpoints, give no argument.\n\
15542 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15543 &disablelist
, "disable ", 1, &cmdlist
);
15544 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15545 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15547 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
15548 Disable all or some breakpoints.\n\
15549 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15550 Arguments are breakpoint numbers with spaces in between.\n\
15551 To disable all breakpoints, give no argument.\n\
15552 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15553 This command may be abbreviated \"disable\"."),
15556 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15557 Delete all or some breakpoints.\n\
15558 Usage: delete [BREAKPOINTNUM]...\n\
15559 Arguments are breakpoint numbers with spaces in between.\n\
15560 To delete all breakpoints, give no argument.\n\
15562 Also a prefix command for deletion of other GDB objects."),
15563 &deletelist
, "delete ", 1, &cmdlist
);
15564 add_com_alias ("d", "delete", class_breakpoint
, 1);
15565 add_com_alias ("del", "delete", class_breakpoint
, 1);
15567 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
15568 Delete all or some breakpoints or auto-display expressions.\n\
15569 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15570 Arguments are breakpoint numbers with spaces in between.\n\
15571 To delete all breakpoints, give no argument.\n\
15572 This command may be abbreviated \"delete\"."),
15575 add_com ("clear", class_breakpoint
, clear_command
, _("\
15576 Clear breakpoint at specified location.\n\
15577 Argument may be a linespec, explicit, or address location as described below.\n\
15579 With no argument, clears all breakpoints in the line that the selected frame\n\
15580 is executing in.\n"
15581 "\n" LOCATION_HELP_STRING
"\n\n\
15582 See also the \"delete\" command which clears breakpoints by number."));
15583 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15585 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15586 Set breakpoint at specified location.\n"
15587 BREAK_ARGS_HELP ("break")));
15588 set_cmd_completer (c
, location_completer
);
15590 add_com_alias ("b", "break", class_run
, 1);
15591 add_com_alias ("br", "break", class_run
, 1);
15592 add_com_alias ("bre", "break", class_run
, 1);
15593 add_com_alias ("brea", "break", class_run
, 1);
15597 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15598 Break in function/address or break at a line in the current file."),
15599 &stoplist
, "stop ", 1, &cmdlist
);
15600 add_cmd ("in", class_breakpoint
, stopin_command
,
15601 _("Break in function or address."), &stoplist
);
15602 add_cmd ("at", class_breakpoint
, stopat_command
,
15603 _("Break at a line in the current file."), &stoplist
);
15604 add_com ("status", class_info
, info_breakpoints_command
, _("\
15605 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15606 The \"Type\" column indicates one of:\n\
15607 \tbreakpoint - normal breakpoint\n\
15608 \twatchpoint - watchpoint\n\
15609 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15610 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15611 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15612 address and file/line number respectively.\n\
15614 Convenience variable \"$_\" and default examine address for \"x\"\n\
15615 are set to the address of the last breakpoint listed unless the command\n\
15616 is prefixed with \"server \".\n\n\
15617 Convenience variable \"$bpnum\" contains the number of the last\n\
15618 breakpoint set."));
15621 add_info ("breakpoints", info_breakpoints_command
, _("\
15622 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15623 The \"Type\" column indicates one of:\n\
15624 \tbreakpoint - normal breakpoint\n\
15625 \twatchpoint - watchpoint\n\
15626 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15627 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15628 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15629 address and file/line number respectively.\n\
15631 Convenience variable \"$_\" and default examine address for \"x\"\n\
15632 are set to the address of the last breakpoint listed unless the command\n\
15633 is prefixed with \"server \".\n\n\
15634 Convenience variable \"$bpnum\" contains the number of the last\n\
15635 breakpoint set."));
15637 add_info_alias ("b", "breakpoints", 1);
15639 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15640 Status of all breakpoints, or breakpoint number NUMBER.\n\
15641 The \"Type\" column indicates one of:\n\
15642 \tbreakpoint - normal breakpoint\n\
15643 \twatchpoint - watchpoint\n\
15644 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15645 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15646 \tuntil - internal breakpoint used by the \"until\" command\n\
15647 \tfinish - internal breakpoint used by the \"finish\" command\n\
15648 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15649 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15650 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15651 address and file/line number respectively.\n\
15653 Convenience variable \"$_\" and default examine address for \"x\"\n\
15654 are set to the address of the last breakpoint listed unless the command\n\
15655 is prefixed with \"server \".\n\n\
15656 Convenience variable \"$bpnum\" contains the number of the last\n\
15658 &maintenanceinfolist
);
15660 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
15661 Set catchpoints to catch events."),
15662 &catch_cmdlist
, "catch ",
15663 0/*allow-unknown*/, &cmdlist
);
15665 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
15666 Set temporary catchpoints to catch events."),
15667 &tcatch_cmdlist
, "tcatch ",
15668 0/*allow-unknown*/, &cmdlist
);
15670 add_catch_command ("fork", _("Catch calls to fork."),
15671 catch_fork_command_1
,
15673 (void *) (uintptr_t) catch_fork_permanent
,
15674 (void *) (uintptr_t) catch_fork_temporary
);
15675 add_catch_command ("vfork", _("Catch calls to vfork."),
15676 catch_fork_command_1
,
15678 (void *) (uintptr_t) catch_vfork_permanent
,
15679 (void *) (uintptr_t) catch_vfork_temporary
);
15680 add_catch_command ("exec", _("Catch calls to exec."),
15681 catch_exec_command_1
,
15685 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15686 Usage: catch load [REGEX]\n\
15687 If REGEX is given, only stop for libraries matching the regular expression."),
15688 catch_load_command_1
,
15692 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15693 Usage: catch unload [REGEX]\n\
15694 If REGEX is given, only stop for libraries matching the regular expression."),
15695 catch_unload_command_1
,
15700 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15701 Set a watchpoint for an expression.\n\
15702 Usage: watch [-l|-location] EXPRESSION\n\
15703 A watchpoint stops execution of your program whenever the value of\n\
15704 an expression changes.\n\
15705 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15706 the memory to which it refers."));
15707 set_cmd_completer (c
, expression_completer
);
15709 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15710 Set a read watchpoint for an expression.\n\
15711 Usage: rwatch [-l|-location] EXPRESSION\n\
15712 A watchpoint stops execution of your program whenever the value of\n\
15713 an expression is read.\n\
15714 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15715 the memory to which it refers."));
15716 set_cmd_completer (c
, expression_completer
);
15718 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15719 Set a watchpoint for an expression.\n\
15720 Usage: awatch [-l|-location] EXPRESSION\n\
15721 A watchpoint stops execution of your program whenever the value of\n\
15722 an expression is either read or written.\n\
15723 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15724 the memory to which it refers."));
15725 set_cmd_completer (c
, expression_completer
);
15727 add_info ("watchpoints", info_watchpoints_command
, _("\
15728 Status of specified watchpoints (all watchpoints if no argument)."));
15730 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15731 respond to changes - contrary to the description. */
15732 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15733 &can_use_hw_watchpoints
, _("\
15734 Set debugger's willingness to use watchpoint hardware."), _("\
15735 Show debugger's willingness to use watchpoint hardware."), _("\
15736 If zero, gdb will not use hardware for new watchpoints, even if\n\
15737 such is available. (However, any hardware watchpoints that were\n\
15738 created before setting this to nonzero, will continue to use watchpoint\n\
15741 show_can_use_hw_watchpoints
,
15742 &setlist
, &showlist
);
15744 can_use_hw_watchpoints
= 1;
15746 /* Tracepoint manipulation commands. */
15748 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15749 Set a tracepoint at specified location.\n\
15751 BREAK_ARGS_HELP ("trace") "\n\
15752 Do \"help tracepoints\" for info on other tracepoint commands."));
15753 set_cmd_completer (c
, location_completer
);
15755 add_com_alias ("tp", "trace", class_breakpoint
, 0);
15756 add_com_alias ("tr", "trace", class_breakpoint
, 1);
15757 add_com_alias ("tra", "trace", class_breakpoint
, 1);
15758 add_com_alias ("trac", "trace", class_breakpoint
, 1);
15760 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15761 Set a fast tracepoint at specified location.\n\
15763 BREAK_ARGS_HELP ("ftrace") "\n\
15764 Do \"help tracepoints\" for info on other tracepoint commands."));
15765 set_cmd_completer (c
, location_completer
);
15767 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15768 Set a static tracepoint at location or marker.\n\
15770 strace [LOCATION] [if CONDITION]\n\
15771 LOCATION may be a linespec, explicit, or address location (described below) \n\
15772 or -m MARKER_ID.\n\n\
15773 If a marker id is specified, probe the marker with that name. With\n\
15774 no LOCATION, uses current execution address of the selected stack frame.\n\
15775 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15776 This collects arbitrary user data passed in the probe point call to the\n\
15777 tracing library. You can inspect it when analyzing the trace buffer,\n\
15778 by printing the $_sdata variable like any other convenience variable.\n\
15780 CONDITION is a boolean expression.\n\
15781 \n" LOCATION_HELP_STRING
"\n\n\
15782 Multiple tracepoints at one place are permitted, and useful if their\n\
15783 conditions are different.\n\
15785 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15786 Do \"help tracepoints\" for info on other tracepoint commands."));
15787 set_cmd_completer (c
, location_completer
);
15789 add_info ("tracepoints", info_tracepoints_command
, _("\
15790 Status of specified tracepoints (all tracepoints if no argument).\n\
15791 Convenience variable \"$tpnum\" contains the number of the\n\
15792 last tracepoint set."));
15794 add_info_alias ("tp", "tracepoints", 1);
15796 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15797 Delete specified tracepoints.\n\
15798 Arguments are tracepoint numbers, separated by spaces.\n\
15799 No argument means delete all tracepoints."),
15801 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
15803 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15804 Disable specified tracepoints.\n\
15805 Arguments are tracepoint numbers, separated by spaces.\n\
15806 No argument means disable all tracepoints."),
15808 deprecate_cmd (c
, "disable");
15810 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15811 Enable specified tracepoints.\n\
15812 Arguments are tracepoint numbers, separated by spaces.\n\
15813 No argument means enable all tracepoints."),
15815 deprecate_cmd (c
, "enable");
15817 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15818 Set the passcount for a tracepoint.\n\
15819 The trace will end when the tracepoint has been passed 'count' times.\n\
15820 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15821 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15823 add_basic_prefix_cmd ("save", class_breakpoint
,
15824 _("Save breakpoint definitions as a script."),
15825 &save_cmdlist
, "save ",
15826 0/*allow-unknown*/, &cmdlist
);
15828 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15829 Save current breakpoint definitions as a script.\n\
15830 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15831 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15832 session to restore them."),
15834 set_cmd_completer (c
, filename_completer
);
15836 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15837 Save current tracepoint definitions as a script.\n\
15838 Use the 'source' command in another debug session to restore them."),
15840 set_cmd_completer (c
, filename_completer
);
15842 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
15843 deprecate_cmd (c
, "save tracepoints");
15845 add_basic_prefix_cmd ("breakpoint", class_maintenance
, _("\
15846 Breakpoint specific settings.\n\
15847 Configure various breakpoint-specific variables such as\n\
15848 pending breakpoint behavior."),
15849 &breakpoint_set_cmdlist
, "set breakpoint ",
15850 0/*allow-unknown*/, &setlist
);
15851 add_show_prefix_cmd ("breakpoint", class_maintenance
, _("\
15852 Breakpoint specific settings.\n\
15853 Configure various breakpoint-specific variables such as\n\
15854 pending breakpoint behavior."),
15855 &breakpoint_show_cmdlist
, "show breakpoint ",
15856 0/*allow-unknown*/, &showlist
);
15858 add_setshow_auto_boolean_cmd ("pending", no_class
,
15859 &pending_break_support
, _("\
15860 Set debugger's behavior regarding pending breakpoints."), _("\
15861 Show debugger's behavior regarding pending breakpoints."), _("\
15862 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15863 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15864 an error. If auto, an unrecognized breakpoint location results in a\n\
15865 user-query to see if a pending breakpoint should be created."),
15867 show_pending_break_support
,
15868 &breakpoint_set_cmdlist
,
15869 &breakpoint_show_cmdlist
);
15871 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15873 add_setshow_boolean_cmd ("auto-hw", no_class
,
15874 &automatic_hardware_breakpoints
, _("\
15875 Set automatic usage of hardware breakpoints."), _("\
15876 Show automatic usage of hardware breakpoints."), _("\
15877 If set, the debugger will automatically use hardware breakpoints for\n\
15878 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15879 a warning will be emitted for such breakpoints."),
15881 show_automatic_hardware_breakpoints
,
15882 &breakpoint_set_cmdlist
,
15883 &breakpoint_show_cmdlist
);
15885 add_setshow_boolean_cmd ("always-inserted", class_support
,
15886 &always_inserted_mode
, _("\
15887 Set mode for inserting breakpoints."), _("\
15888 Show mode for inserting breakpoints."), _("\
15889 When this mode is on, breakpoints are inserted immediately as soon as\n\
15890 they're created, kept inserted even when execution stops, and removed\n\
15891 only when the user deletes them. When this mode is off (the default),\n\
15892 breakpoints are inserted only when execution continues, and removed\n\
15893 when execution stops."),
15895 &show_always_inserted_mode
,
15896 &breakpoint_set_cmdlist
,
15897 &breakpoint_show_cmdlist
);
15899 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15900 condition_evaluation_enums
,
15901 &condition_evaluation_mode_1
, _("\
15902 Set mode of breakpoint condition evaluation."), _("\
15903 Show mode of breakpoint condition evaluation."), _("\
15904 When this is set to \"host\", breakpoint conditions will be\n\
15905 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15906 breakpoint conditions will be downloaded to the target (if the target\n\
15907 supports such feature) and conditions will be evaluated on the target's side.\n\
15908 If this is set to \"auto\" (default), this will be automatically set to\n\
15909 \"target\" if it supports condition evaluation, otherwise it will\n\
15910 be set to \"host\"."),
15911 &set_condition_evaluation_mode
,
15912 &show_condition_evaluation_mode
,
15913 &breakpoint_set_cmdlist
,
15914 &breakpoint_show_cmdlist
);
15916 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15917 Set a breakpoint for an address range.\n\
15918 break-range START-LOCATION, END-LOCATION\n\
15919 where START-LOCATION and END-LOCATION can be one of the following:\n\
15920 LINENUM, for that line in the current file,\n\
15921 FILE:LINENUM, for that line in that file,\n\
15922 +OFFSET, for that number of lines after the current line\n\
15923 or the start of the range\n\
15924 FUNCTION, for the first line in that function,\n\
15925 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15926 *ADDRESS, for the instruction at that address.\n\
15928 The breakpoint will stop execution of the inferior whenever it executes\n\
15929 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15930 range (including START-LOCATION and END-LOCATION)."));
15932 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
15933 Set a dynamic printf at specified location.\n\
15934 dprintf location,format string,arg1,arg2,...\n\
15935 location may be a linespec, explicit, or address location.\n"
15936 "\n" LOCATION_HELP_STRING
));
15937 set_cmd_completer (c
, location_completer
);
15939 add_setshow_enum_cmd ("dprintf-style", class_support
,
15940 dprintf_style_enums
, &dprintf_style
, _("\
15941 Set the style of usage for dynamic printf."), _("\
15942 Show the style of usage for dynamic printf."), _("\
15943 This setting chooses how GDB will do a dynamic printf.\n\
15944 If the value is \"gdb\", then the printing is done by GDB to its own\n\
15945 console, as with the \"printf\" command.\n\
15946 If the value is \"call\", the print is done by calling a function in your\n\
15947 program; by default printf(), but you can choose a different function or\n\
15948 output stream by setting dprintf-function and dprintf-channel."),
15949 update_dprintf_commands
, NULL
,
15950 &setlist
, &showlist
);
15952 dprintf_function
= xstrdup ("printf");
15953 add_setshow_string_cmd ("dprintf-function", class_support
,
15954 &dprintf_function
, _("\
15955 Set the function to use for dynamic printf."), _("\
15956 Show the function to use for dynamic printf."), NULL
,
15957 update_dprintf_commands
, NULL
,
15958 &setlist
, &showlist
);
15960 dprintf_channel
= xstrdup ("");
15961 add_setshow_string_cmd ("dprintf-channel", class_support
,
15962 &dprintf_channel
, _("\
15963 Set the channel to use for dynamic printf."), _("\
15964 Show the channel to use for dynamic printf."), NULL
,
15965 update_dprintf_commands
, NULL
,
15966 &setlist
, &showlist
);
15968 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
15969 &disconnected_dprintf
, _("\
15970 Set whether dprintf continues after GDB disconnects."), _("\
15971 Show whether dprintf continues after GDB disconnects."), _("\
15972 Use this to let dprintf commands continue to hit and produce output\n\
15973 even if GDB disconnects or detaches from the target."),
15976 &setlist
, &showlist
);
15978 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
15979 Target agent only formatted printing, like the C \"printf\" function.\n\
15980 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
15981 This supports most C printf format specifications, like %s, %d, etc.\n\
15982 This is useful for formatted output in user-defined commands."));
15984 automatic_hardware_breakpoints
= true;
15986 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
);
15987 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
);