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
)
833 /* Parse COND_STRING in the context of LOC and set as the condition
834 expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is
835 the number of LOC within its owner. In case of parsing error, mark
836 LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */
839 set_breakpoint_location_condition (const char *cond_string
, bp_location
*loc
,
840 int bp_num
, int loc_num
)
842 bool has_junk
= false;
845 expression_up new_exp
= parse_exp_1 (&cond_string
, loc
->address
,
846 block_for_pc (loc
->address
), 0);
847 if (*cond_string
!= 0)
851 loc
->cond
= std::move (new_exp
);
852 if (loc
->disabled_by_cond
&& loc
->enabled
)
853 printf_filtered (_("Breakpoint %d's condition is now valid at "
854 "location %d, enabling.\n"),
857 loc
->disabled_by_cond
= false;
860 catch (const gdb_exception_error
&e
)
864 /* Warn if a user-enabled location is now becoming disabled-by-cond.
865 BP_NUM is 0 if the breakpoint is being defined for the first
866 time using the "break ... if ..." command, and non-zero if
869 warning (_("failed to validate condition at location %d.%d, "
870 "disabling:\n %s"), bp_num
, loc_num
, e
.what ());
872 warning (_("failed to validate condition at location %d, "
873 "disabling:\n %s"), loc_num
, e
.what ());
876 loc
->disabled_by_cond
= true;
880 error (_("Garbage '%s' follows condition"), cond_string
);
884 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
885 int from_tty
, bool force
)
889 xfree (b
->cond_string
);
890 b
->cond_string
= nullptr;
892 if (is_watchpoint (b
))
893 static_cast<watchpoint
*> (b
)->cond_exp
.reset ();
897 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
900 if (loc
->disabled_by_cond
&& loc
->enabled
)
901 printf_filtered (_("Breakpoint %d's condition is now valid at "
902 "location %d, enabling.\n"),
904 loc
->disabled_by_cond
= false;
907 /* No need to free the condition agent expression
908 bytecode (if we have one). We will handle this
909 when we go through update_global_location_list. */
914 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
918 if (is_watchpoint (b
))
920 innermost_block_tracker tracker
;
921 const char *arg
= exp
;
922 expression_up new_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
924 error (_("Junk at end of expression"));
925 watchpoint
*w
= static_cast<watchpoint
*> (b
);
926 w
->cond_exp
= std::move (new_exp
);
927 w
->cond_exp_valid_block
= tracker
.block ();
931 /* Parse and set condition expressions. We make two passes.
932 In the first, we parse the condition string to see if it
933 is valid in at least one location. If so, the condition
934 would be accepted. So we go ahead and set the locations'
935 conditions. In case no valid case is found, we throw
936 the error and the condition string will be rejected.
937 This two-pass approach is taken to avoid setting the
938 state of locations in case of a reject. */
939 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
943 const char *arg
= exp
;
944 parse_exp_1 (&arg
, loc
->address
,
945 block_for_pc (loc
->address
), 0);
947 error (_("Junk at end of expression"));
950 catch (const gdb_exception_error
&e
)
952 /* Condition string is invalid. If this happens to
953 be the last loc, abandon (if not forced) or continue
955 if (loc
->next
== nullptr && !force
)
960 /* If we reach here, the condition is valid at some locations. */
962 for (bp_location
*loc
= b
->loc
; loc
!= nullptr;
963 loc
= loc
->next
, loc_num
++)
964 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
967 /* We know that the new condition parsed successfully. The
968 condition string of the breakpoint can be safely updated. */
969 xfree (b
->cond_string
);
970 b
->cond_string
= xstrdup (exp
);
971 b
->condition_not_parsed
= 0;
973 mark_breakpoint_modified (b
);
975 gdb::observers::breakpoint_modified
.notify (b
);
978 /* Completion for the "condition" command. */
981 condition_completer (struct cmd_list_element
*cmd
,
982 completion_tracker
&tracker
,
983 const char *text
, const char *word
)
987 text
= skip_spaces (text
);
988 space
= skip_to_space (text
);
992 struct breakpoint
*b
;
996 /* We don't support completion of history indices. */
997 if (!isdigit (text
[1]))
998 complete_internalvar (tracker
, &text
[1]);
1002 /* We're completing the breakpoint number. */
1003 len
= strlen (text
);
1009 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1011 if (strncmp (number
, text
, len
) == 0)
1012 tracker
.add_completion (make_unique_xstrdup (number
));
1018 /* We're completing the expression part. */
1019 text
= skip_spaces (space
);
1020 expression_completer (cmd
, tracker
, text
, word
);
1023 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1026 condition_command (const char *arg
, int from_tty
)
1028 struct breakpoint
*b
;
1033 error_no_arg (_("breakpoint number"));
1037 /* Check if the "-force" flag was passed. */
1039 const char *tok
= skip_spaces (p
);
1040 const char *end_tok
= skip_to_space (tok
);
1041 int toklen
= end_tok
- tok
;
1042 if (toklen
>= 1 && strncmp (tok
, "-force", toklen
) == 0)
1048 bnum
= get_number (&p
);
1050 error (_("Bad breakpoint argument: '%s'"), arg
);
1053 if (b
->number
== bnum
)
1055 /* Check if this breakpoint has a "stop" method implemented in an
1056 extension language. This method and conditions entered into GDB
1057 from the CLI are mutually exclusive. */
1058 const struct extension_language_defn
*extlang
1059 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1061 if (extlang
!= NULL
)
1063 error (_("Only one stop condition allowed. There is currently"
1064 " a %s stop condition defined for this breakpoint."),
1065 ext_lang_capitalized_name (extlang
));
1067 set_breakpoint_condition (b
, p
, from_tty
, force
);
1069 if (is_breakpoint (b
))
1070 update_global_location_list (UGLL_MAY_INSERT
);
1075 error (_("No breakpoint number %d."), bnum
);
1078 /* Check that COMMAND do not contain commands that are suitable
1079 only for tracepoints and not suitable for ordinary breakpoints.
1080 Throw if any such commands is found. */
1083 check_no_tracepoint_commands (struct command_line
*commands
)
1085 struct command_line
*c
;
1087 for (c
= commands
; c
; c
= c
->next
)
1089 if (c
->control_type
== while_stepping_control
)
1090 error (_("The 'while-stepping' command can "
1091 "only be used for tracepoints"));
1093 check_no_tracepoint_commands (c
->body_list_0
.get ());
1094 check_no_tracepoint_commands (c
->body_list_1
.get ());
1096 /* Not that command parsing removes leading whitespace and comment
1097 lines and also empty lines. So, we only need to check for
1098 command directly. */
1099 if (strstr (c
->line
, "collect ") == c
->line
)
1100 error (_("The 'collect' command can only be used for tracepoints"));
1102 if (strstr (c
->line
, "teval ") == c
->line
)
1103 error (_("The 'teval' command can only be used for tracepoints"));
1107 struct longjmp_breakpoint
: public breakpoint
1109 ~longjmp_breakpoint () override
;
1112 /* Encapsulate tests for different types of tracepoints. */
1115 is_tracepoint_type (bptype type
)
1117 return (type
== bp_tracepoint
1118 || type
== bp_fast_tracepoint
1119 || type
== bp_static_tracepoint
);
1123 is_longjmp_type (bptype type
)
1125 return type
== bp_longjmp
|| type
== bp_exception
;
1128 /* See breakpoint.h. */
1131 is_tracepoint (const struct breakpoint
*b
)
1133 return is_tracepoint_type (b
->type
);
1136 /* Factory function to create an appropriate instance of breakpoint given
1139 static std::unique_ptr
<breakpoint
>
1140 new_breakpoint_from_type (bptype type
)
1144 if (is_tracepoint_type (type
))
1145 b
= new tracepoint ();
1146 else if (is_longjmp_type (type
))
1147 b
= new longjmp_breakpoint ();
1149 b
= new breakpoint ();
1151 return std::unique_ptr
<breakpoint
> (b
);
1154 /* A helper function that validates that COMMANDS are valid for a
1155 breakpoint. This function will throw an exception if a problem is
1159 validate_commands_for_breakpoint (struct breakpoint
*b
,
1160 struct command_line
*commands
)
1162 if (is_tracepoint (b
))
1164 struct tracepoint
*t
= (struct tracepoint
*) b
;
1165 struct command_line
*c
;
1166 struct command_line
*while_stepping
= 0;
1168 /* Reset the while-stepping step count. The previous commands
1169 might have included a while-stepping action, while the new
1173 /* We need to verify that each top-level element of commands is
1174 valid for tracepoints, that there's at most one
1175 while-stepping element, and that the while-stepping's body
1176 has valid tracing commands excluding nested while-stepping.
1177 We also need to validate the tracepoint action line in the
1178 context of the tracepoint --- validate_actionline actually
1179 has side effects, like setting the tracepoint's
1180 while-stepping STEP_COUNT, in addition to checking if the
1181 collect/teval actions parse and make sense in the
1182 tracepoint's context. */
1183 for (c
= commands
; c
; c
= c
->next
)
1185 if (c
->control_type
== while_stepping_control
)
1187 if (b
->type
== bp_fast_tracepoint
)
1188 error (_("The 'while-stepping' command "
1189 "cannot be used for fast tracepoint"));
1190 else if (b
->type
== bp_static_tracepoint
)
1191 error (_("The 'while-stepping' command "
1192 "cannot be used for static tracepoint"));
1195 error (_("The 'while-stepping' command "
1196 "can be used only once"));
1201 validate_actionline (c
->line
, b
);
1205 struct command_line
*c2
;
1207 gdb_assert (while_stepping
->body_list_1
== nullptr);
1208 c2
= while_stepping
->body_list_0
.get ();
1209 for (; c2
; c2
= c2
->next
)
1211 if (c2
->control_type
== while_stepping_control
)
1212 error (_("The 'while-stepping' command cannot be nested"));
1218 check_no_tracepoint_commands (commands
);
1222 /* Return a vector of all the static tracepoints set at ADDR. The
1223 caller is responsible for releasing the vector. */
1225 std::vector
<breakpoint
*>
1226 static_tracepoints_here (CORE_ADDR addr
)
1228 struct breakpoint
*b
;
1229 std::vector
<breakpoint
*> found
;
1230 struct bp_location
*loc
;
1233 if (b
->type
== bp_static_tracepoint
)
1235 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1236 if (loc
->address
== addr
)
1237 found
.push_back (b
);
1243 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1244 validate that only allowed commands are included. */
1247 breakpoint_set_commands (struct breakpoint
*b
,
1248 counted_command_line
&&commands
)
1250 validate_commands_for_breakpoint (b
, commands
.get ());
1252 b
->commands
= std::move (commands
);
1253 gdb::observers::breakpoint_modified
.notify (b
);
1256 /* Set the internal `silent' flag on the breakpoint. Note that this
1257 is not the same as the "silent" that may appear in the breakpoint's
1261 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1263 int old_silent
= b
->silent
;
1266 if (old_silent
!= silent
)
1267 gdb::observers::breakpoint_modified
.notify (b
);
1270 /* Set the thread for this breakpoint. If THREAD is -1, make the
1271 breakpoint work for any thread. */
1274 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1276 int old_thread
= b
->thread
;
1279 if (old_thread
!= thread
)
1280 gdb::observers::breakpoint_modified
.notify (b
);
1283 /* Set the task for this breakpoint. If TASK is 0, make the
1284 breakpoint work for any task. */
1287 breakpoint_set_task (struct breakpoint
*b
, int task
)
1289 int old_task
= b
->task
;
1292 if (old_task
!= task
)
1293 gdb::observers::breakpoint_modified
.notify (b
);
1297 commands_command_1 (const char *arg
, int from_tty
,
1298 struct command_line
*control
)
1300 counted_command_line cmd
;
1301 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1302 NULL after the call to read_command_lines if the user provides an empty
1303 list of command by just typing "end". */
1304 bool cmd_read
= false;
1306 std::string new_arg
;
1308 if (arg
== NULL
|| !*arg
)
1310 /* Argument not explicitly given. Synthesize it. */
1311 if (breakpoint_count
- prev_breakpoint_count
> 1)
1312 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1314 else if (breakpoint_count
> 0)
1315 new_arg
= string_printf ("%d", breakpoint_count
);
1319 /* Create a copy of ARG. This is needed because the "commands"
1320 command may be coming from a script. In that case, the read
1321 line buffer is going to be overwritten in the lambda of
1322 'map_breakpoint_numbers' below when reading the next line
1323 before we are are done parsing the breakpoint numbers. */
1326 arg
= new_arg
.c_str ();
1328 map_breakpoint_numbers
1329 (arg
, [&] (breakpoint
*b
)
1333 gdb_assert (cmd
== NULL
);
1334 if (control
!= NULL
)
1335 cmd
= control
->body_list_0
;
1339 = string_printf (_("Type commands for breakpoint(s) "
1340 "%s, one per line."),
1343 auto do_validate
= [=] (const char *line
)
1345 validate_actionline (line
, b
);
1347 gdb::function_view
<void (const char *)> validator
;
1348 if (is_tracepoint (b
))
1349 validator
= do_validate
;
1351 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1356 /* If a breakpoint was on the list more than once, we don't need to
1358 if (b
->commands
!= cmd
)
1360 validate_commands_for_breakpoint (b
, cmd
.get ());
1362 gdb::observers::breakpoint_modified
.notify (b
);
1368 commands_command (const char *arg
, int from_tty
)
1370 commands_command_1 (arg
, from_tty
, NULL
);
1373 /* Like commands_command, but instead of reading the commands from
1374 input stream, takes them from an already parsed command structure.
1376 This is used by cli-script.c to DTRT with breakpoint commands
1377 that are part of if and while bodies. */
1378 enum command_control_type
1379 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1381 commands_command_1 (arg
, 0, cmd
);
1382 return simple_control
;
1385 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1388 bp_location_has_shadow (struct bp_location
*bl
)
1390 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1394 if (bl
->target_info
.shadow_len
== 0)
1395 /* BL isn't valid, or doesn't shadow memory. */
1400 /* Update BUF, which is LEN bytes read from the target address
1401 MEMADDR, by replacing a memory breakpoint with its shadowed
1404 If READBUF is not NULL, this buffer must not overlap with the of
1405 the breakpoint location's shadow_contents buffer. Otherwise, a
1406 failed assertion internal error will be raised. */
1409 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1410 const gdb_byte
*writebuf_org
,
1411 ULONGEST memaddr
, LONGEST len
,
1412 struct bp_target_info
*target_info
,
1413 struct gdbarch
*gdbarch
)
1415 /* Now do full processing of the found relevant range of elements. */
1416 CORE_ADDR bp_addr
= 0;
1420 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1421 current_program_space
->aspace
, 0))
1423 /* The breakpoint is inserted in a different address space. */
1427 /* Addresses and length of the part of the breakpoint that
1429 bp_addr
= target_info
->placed_address
;
1430 bp_size
= target_info
->shadow_len
;
1432 if (bp_addr
+ bp_size
<= memaddr
)
1434 /* The breakpoint is entirely before the chunk of memory we are
1439 if (bp_addr
>= memaddr
+ len
)
1441 /* The breakpoint is entirely after the chunk of memory we are
1446 /* Offset within shadow_contents. */
1447 if (bp_addr
< memaddr
)
1449 /* Only copy the second part of the breakpoint. */
1450 bp_size
-= memaddr
- bp_addr
;
1451 bptoffset
= memaddr
- bp_addr
;
1455 if (bp_addr
+ bp_size
> memaddr
+ len
)
1457 /* Only copy the first part of the breakpoint. */
1458 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1461 if (readbuf
!= NULL
)
1463 /* Verify that the readbuf buffer does not overlap with the
1464 shadow_contents buffer. */
1465 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1466 || readbuf
>= (target_info
->shadow_contents
1467 + target_info
->shadow_len
));
1469 /* Update the read buffer with this inserted breakpoint's
1471 memcpy (readbuf
+ bp_addr
- memaddr
,
1472 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1476 const unsigned char *bp
;
1477 CORE_ADDR addr
= target_info
->reqstd_address
;
1480 /* Update the shadow with what we want to write to memory. */
1481 memcpy (target_info
->shadow_contents
+ bptoffset
,
1482 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1484 /* Determine appropriate breakpoint contents and size for this
1486 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1488 /* Update the final write buffer with this inserted
1489 breakpoint's INSN. */
1490 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1494 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1495 by replacing any memory breakpoints with their shadowed contents.
1497 If READBUF is not NULL, this buffer must not overlap with any of
1498 the breakpoint location's shadow_contents buffers. Otherwise,
1499 a failed assertion internal error will be raised.
1501 The range of shadowed area by each bp_location is:
1502 bl->address - bp_locations_placed_address_before_address_max
1503 up to bl->address + bp_locations_shadow_len_after_address_max
1504 The range we were requested to resolve shadows for is:
1505 memaddr ... memaddr + len
1506 Thus the safe cutoff boundaries for performance optimization are
1507 memaddr + len <= (bl->address
1508 - bp_locations_placed_address_before_address_max)
1510 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1513 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1514 const gdb_byte
*writebuf_org
,
1515 ULONGEST memaddr
, LONGEST len
)
1517 /* Left boundary, right boundary and median element of our binary
1519 unsigned bc_l
, bc_r
, bc
;
1521 /* Find BC_L which is a leftmost element which may affect BUF
1522 content. It is safe to report lower value but a failure to
1523 report higher one. */
1526 bc_r
= bp_locations_count
;
1527 while (bc_l
+ 1 < bc_r
)
1529 struct bp_location
*bl
;
1531 bc
= (bc_l
+ bc_r
) / 2;
1532 bl
= bp_locations
[bc
];
1534 /* Check first BL->ADDRESS will not overflow due to the added
1535 constant. Then advance the left boundary only if we are sure
1536 the BC element can in no way affect the BUF content (MEMADDR
1537 to MEMADDR + LEN range).
1539 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1540 offset so that we cannot miss a breakpoint with its shadow
1541 range tail still reaching MEMADDR. */
1543 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1545 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1552 /* Due to the binary search above, we need to make sure we pick the
1553 first location that's at BC_L's address. E.g., if there are
1554 multiple locations at the same address, BC_L may end up pointing
1555 at a duplicate location, and miss the "master"/"inserted"
1556 location. Say, given locations L1, L2 and L3 at addresses A and
1559 L1@A, L2@A, L3@B, ...
1561 BC_L could end up pointing at location L2, while the "master"
1562 location could be L1. Since the `loc->inserted' flag is only set
1563 on "master" locations, we'd forget to restore the shadow of L1
1566 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1569 /* Now do full processing of the found relevant range of elements. */
1571 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1573 struct bp_location
*bl
= bp_locations
[bc
];
1575 /* bp_location array has BL->OWNER always non-NULL. */
1576 if (bl
->owner
->type
== bp_none
)
1577 warning (_("reading through apparently deleted breakpoint #%d?"),
1580 /* Performance optimization: any further element can no longer affect BUF
1583 if (bl
->address
>= bp_locations_placed_address_before_address_max
1584 && memaddr
+ len
<= (bl
->address
1585 - bp_locations_placed_address_before_address_max
))
1588 if (!bp_location_has_shadow (bl
))
1591 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1592 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1596 /* See breakpoint.h. */
1599 is_breakpoint (const struct breakpoint
*bpt
)
1601 return (bpt
->type
== bp_breakpoint
1602 || bpt
->type
== bp_hardware_breakpoint
1603 || bpt
->type
== bp_dprintf
);
1606 /* Return true if BPT is of any hardware watchpoint kind. */
1609 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1611 return (bpt
->type
== bp_hardware_watchpoint
1612 || bpt
->type
== bp_read_watchpoint
1613 || bpt
->type
== bp_access_watchpoint
);
1616 /* See breakpoint.h. */
1619 is_watchpoint (const struct breakpoint
*bpt
)
1621 return (is_hardware_watchpoint (bpt
)
1622 || bpt
->type
== bp_watchpoint
);
1625 /* Returns true if the current thread and its running state are safe
1626 to evaluate or update watchpoint B. Watchpoints on local
1627 expressions need to be evaluated in the context of the thread that
1628 was current when the watchpoint was created, and, that thread needs
1629 to be stopped to be able to select the correct frame context.
1630 Watchpoints on global expressions can be evaluated on any thread,
1631 and in any state. It is presently left to the target allowing
1632 memory accesses when threads are running. */
1635 watchpoint_in_thread_scope (struct watchpoint
*b
)
1637 return (b
->pspace
== current_program_space
1638 && (b
->watchpoint_thread
== null_ptid
1639 || (inferior_ptid
== b
->watchpoint_thread
1640 && !inferior_thread ()->executing
)));
1643 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1644 associated bp_watchpoint_scope breakpoint. */
1647 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1649 if (w
->related_breakpoint
!= w
)
1651 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1652 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1653 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1654 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1655 w
->related_breakpoint
= w
;
1657 w
->disposition
= disp_del_at_next_stop
;
1660 /* Extract a bitfield value from value VAL using the bit parameters contained in
1663 static struct value
*
1664 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1666 struct value
*bit_val
;
1671 bit_val
= allocate_value (value_type (val
));
1673 unpack_value_bitfield (bit_val
,
1676 value_contents_for_printing (val
),
1683 /* Allocate a dummy location and add it to B, which must be a software
1684 watchpoint. This is required because even if a software watchpoint
1685 is not watching any memory, bpstat_stop_status requires a location
1686 to be able to report stops. */
1689 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1690 struct program_space
*pspace
)
1692 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1694 b
->loc
= allocate_bp_location (b
);
1695 b
->loc
->pspace
= pspace
;
1696 b
->loc
->address
= -1;
1697 b
->loc
->length
= -1;
1700 /* Returns true if B is a software watchpoint that is not watching any
1701 memory (e.g., "watch $pc"). */
1704 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1706 return (b
->type
== bp_watchpoint
1708 && b
->loc
->next
== NULL
1709 && b
->loc
->address
== -1
1710 && b
->loc
->length
== -1);
1713 /* Assuming that B is a watchpoint:
1714 - Reparse watchpoint expression, if REPARSE is non-zero
1715 - Evaluate expression and store the result in B->val
1716 - Evaluate the condition if there is one, and store the result
1718 - Update the list of values that must be watched in B->loc.
1720 If the watchpoint disposition is disp_del_at_next_stop, then do
1721 nothing. If this is local watchpoint that is out of scope, delete
1724 Even with `set breakpoint always-inserted on' the watchpoints are
1725 removed + inserted on each stop here. Normal breakpoints must
1726 never be removed because they might be missed by a running thread
1727 when debugging in non-stop mode. On the other hand, hardware
1728 watchpoints (is_hardware_watchpoint; processed here) are specific
1729 to each LWP since they are stored in each LWP's hardware debug
1730 registers. Therefore, such LWP must be stopped first in order to
1731 be able to modify its hardware watchpoints.
1733 Hardware watchpoints must be reset exactly once after being
1734 presented to the user. It cannot be done sooner, because it would
1735 reset the data used to present the watchpoint hit to the user. And
1736 it must not be done later because it could display the same single
1737 watchpoint hit during multiple GDB stops. Note that the latter is
1738 relevant only to the hardware watchpoint types bp_read_watchpoint
1739 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1740 not user-visible - its hit is suppressed if the memory content has
1743 The following constraints influence the location where we can reset
1744 hardware watchpoints:
1746 * target_stopped_by_watchpoint and target_stopped_data_address are
1747 called several times when GDB stops.
1750 * Multiple hardware watchpoints can be hit at the same time,
1751 causing GDB to stop. GDB only presents one hardware watchpoint
1752 hit at a time as the reason for stopping, and all the other hits
1753 are presented later, one after the other, each time the user
1754 requests the execution to be resumed. Execution is not resumed
1755 for the threads still having pending hit event stored in
1756 LWP_INFO->STATUS. While the watchpoint is already removed from
1757 the inferior on the first stop the thread hit event is kept being
1758 reported from its cached value by linux_nat_stopped_data_address
1759 until the real thread resume happens after the watchpoint gets
1760 presented and thus its LWP_INFO->STATUS gets reset.
1762 Therefore the hardware watchpoint hit can get safely reset on the
1763 watchpoint removal from inferior. */
1766 update_watchpoint (struct watchpoint
*b
, int reparse
)
1768 int within_current_scope
;
1769 struct frame_id saved_frame_id
;
1772 /* If this is a local watchpoint, we only want to check if the
1773 watchpoint frame is in scope if the current thread is the thread
1774 that was used to create the watchpoint. */
1775 if (!watchpoint_in_thread_scope (b
))
1778 if (b
->disposition
== disp_del_at_next_stop
)
1783 /* Determine if the watchpoint is within scope. */
1784 if (b
->exp_valid_block
== NULL
)
1785 within_current_scope
= 1;
1788 struct frame_info
*fi
= get_current_frame ();
1789 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1790 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1792 /* If we're at a point where the stack has been destroyed
1793 (e.g. in a function epilogue), unwinding may not work
1794 properly. Do not attempt to recreate locations at this
1795 point. See similar comments in watchpoint_check. */
1796 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1799 /* Save the current frame's ID so we can restore it after
1800 evaluating the watchpoint expression on its own frame. */
1801 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1802 took a frame parameter, so that we didn't have to change the
1805 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1807 fi
= frame_find_by_id (b
->watchpoint_frame
);
1808 within_current_scope
= (fi
!= NULL
);
1809 if (within_current_scope
)
1813 /* We don't free locations. They are stored in the bp_location array
1814 and update_global_location_list will eventually delete them and
1815 remove breakpoints if needed. */
1818 if (within_current_scope
&& reparse
)
1823 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1824 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1825 /* If the meaning of expression itself changed, the old value is
1826 no longer relevant. We don't want to report a watchpoint hit
1827 to the user when the old value and the new value may actually
1828 be completely different objects. */
1830 b
->val_valid
= false;
1832 /* Note that unlike with breakpoints, the watchpoint's condition
1833 expression is stored in the breakpoint object, not in the
1834 locations (re)created below. */
1835 if (b
->cond_string
!= NULL
)
1837 b
->cond_exp
.reset ();
1840 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1844 /* If we failed to parse the expression, for example because
1845 it refers to a global variable in a not-yet-loaded shared library,
1846 don't try to insert watchpoint. We don't automatically delete
1847 such watchpoint, though, since failure to parse expression
1848 is different from out-of-scope watchpoint. */
1849 if (!target_has_execution ())
1851 /* Without execution, memory can't change. No use to try and
1852 set watchpoint locations. The watchpoint will be reset when
1853 the target gains execution, through breakpoint_re_set. */
1854 if (!can_use_hw_watchpoints
)
1856 if (b
->ops
->works_in_software_mode (b
))
1857 b
->type
= bp_watchpoint
;
1859 error (_("Can't set read/access watchpoint when "
1860 "hardware watchpoints are disabled."));
1863 else if (within_current_scope
&& b
->exp
)
1866 std::vector
<value_ref_ptr
> val_chain
;
1867 struct value
*v
, *result
;
1868 struct program_space
*frame_pspace
;
1870 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1872 /* Avoid setting b->val if it's already set. The meaning of
1873 b->val is 'the last value' user saw, and we should update
1874 it only if we reported that last value to user. As it
1875 happens, the code that reports it updates b->val directly.
1876 We don't keep track of the memory value for masked
1878 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1880 if (b
->val_bitsize
!= 0)
1881 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1882 b
->val
= release_value (v
);
1883 b
->val_valid
= true;
1886 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1888 /* Look at each value on the value chain. */
1889 gdb_assert (!val_chain
.empty ());
1890 for (const value_ref_ptr
&iter
: val_chain
)
1894 /* If it's a memory location, and GDB actually needed
1895 its contents to evaluate the expression, then we
1896 must watch it. If the first value returned is
1897 still lazy, that means an error occurred reading it;
1898 watch it anyway in case it becomes readable. */
1899 if (VALUE_LVAL (v
) == lval_memory
1900 && (v
== val_chain
[0] || ! value_lazy (v
)))
1902 struct type
*vtype
= check_typedef (value_type (v
));
1904 /* We only watch structs and arrays if user asked
1905 for it explicitly, never if they just happen to
1906 appear in the middle of some value chain. */
1908 || (vtype
->code () != TYPE_CODE_STRUCT
1909 && vtype
->code () != TYPE_CODE_ARRAY
))
1912 enum target_hw_bp_type type
;
1913 struct bp_location
*loc
, **tmp
;
1914 int bitpos
= 0, bitsize
= 0;
1916 if (value_bitsize (v
) != 0)
1918 /* Extract the bit parameters out from the bitfield
1920 bitpos
= value_bitpos (v
);
1921 bitsize
= value_bitsize (v
);
1923 else if (v
== result
&& b
->val_bitsize
!= 0)
1925 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1926 lvalue whose bit parameters are saved in the fields
1927 VAL_BITPOS and VAL_BITSIZE. */
1928 bitpos
= b
->val_bitpos
;
1929 bitsize
= b
->val_bitsize
;
1932 addr
= value_address (v
);
1935 /* Skip the bytes that don't contain the bitfield. */
1940 if (b
->type
== bp_read_watchpoint
)
1942 else if (b
->type
== bp_access_watchpoint
)
1945 loc
= allocate_bp_location (b
);
1946 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1949 loc
->gdbarch
= get_type_arch (value_type (v
));
1951 loc
->pspace
= frame_pspace
;
1952 loc
->address
= address_significant (loc
->gdbarch
, addr
);
1956 /* Just cover the bytes that make up the bitfield. */
1957 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1960 loc
->length
= TYPE_LENGTH (value_type (v
));
1962 loc
->watchpoint_type
= type
;
1967 /* Change the type of breakpoint between hardware assisted or
1968 an ordinary watchpoint depending on the hardware support
1969 and free hardware slots. REPARSE is set when the inferior
1974 enum bp_loc_type loc_type
;
1975 struct bp_location
*bl
;
1977 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1981 int i
, target_resources_ok
, other_type_used
;
1984 /* Use an exact watchpoint when there's only one memory region to be
1985 watched, and only one debug register is needed to watch it. */
1986 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1988 /* We need to determine how many resources are already
1989 used for all other hardware watchpoints plus this one
1990 to see if we still have enough resources to also fit
1991 this watchpoint in as well. */
1993 /* If this is a software watchpoint, we try to turn it
1994 to a hardware one -- count resources as if B was of
1995 hardware watchpoint type. */
1997 if (type
== bp_watchpoint
)
1998 type
= bp_hardware_watchpoint
;
2000 /* This watchpoint may or may not have been placed on
2001 the list yet at this point (it won't be in the list
2002 if we're trying to create it for the first time,
2003 through watch_command), so always account for it
2006 /* Count resources used by all watchpoints except B. */
2007 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
2009 /* Add in the resources needed for B. */
2010 i
+= hw_watchpoint_use_count (b
);
2013 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2014 if (target_resources_ok
<= 0)
2016 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2018 if (target_resources_ok
== 0 && !sw_mode
)
2019 error (_("Target does not support this type of "
2020 "hardware watchpoint."));
2021 else if (target_resources_ok
< 0 && !sw_mode
)
2022 error (_("There are not enough available hardware "
2023 "resources for this watchpoint."));
2025 /* Downgrade to software watchpoint. */
2026 b
->type
= bp_watchpoint
;
2030 /* If this was a software watchpoint, we've just
2031 found we have enough resources to turn it to a
2032 hardware watchpoint. Otherwise, this is a
2037 else if (!b
->ops
->works_in_software_mode (b
))
2039 if (!can_use_hw_watchpoints
)
2040 error (_("Can't set read/access watchpoint when "
2041 "hardware watchpoints are disabled."));
2043 error (_("Expression cannot be implemented with "
2044 "read/access watchpoint."));
2047 b
->type
= bp_watchpoint
;
2049 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2050 : bp_loc_hardware_watchpoint
);
2051 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
2052 bl
->loc_type
= loc_type
;
2055 /* If a software watchpoint is not watching any memory, then the
2056 above left it without any location set up. But,
2057 bpstat_stop_status requires a location to be able to report
2058 stops, so make sure there's at least a dummy one. */
2059 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2060 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2062 else if (!within_current_scope
)
2064 printf_filtered (_("\
2065 Watchpoint %d deleted because the program has left the block\n\
2066 in which its expression is valid.\n"),
2068 watchpoint_del_at_next_stop (b
);
2071 /* Restore the selected frame. */
2073 select_frame (frame_find_by_id (saved_frame_id
));
2077 /* Returns 1 iff breakpoint location should be
2078 inserted in the inferior. We don't differentiate the type of BL's owner
2079 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2080 breakpoint_ops is not defined, because in insert_bp_location,
2081 tracepoint's insert_location will not be called. */
2083 should_be_inserted (struct bp_location
*bl
)
2085 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2088 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2091 if (!bl
->enabled
|| bl
->disabled_by_cond
2092 || bl
->shlib_disabled
|| bl
->duplicate
)
2095 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2098 /* This is set for example, when we're attached to the parent of a
2099 vfork, and have detached from the child. The child is running
2100 free, and we expect it to do an exec or exit, at which point the
2101 OS makes the parent schedulable again (and the target reports
2102 that the vfork is done). Until the child is done with the shared
2103 memory region, do not insert breakpoints in the parent, otherwise
2104 the child could still trip on the parent's breakpoints. Since
2105 the parent is blocked anyway, it won't miss any breakpoint. */
2106 if (bl
->pspace
->breakpoints_not_allowed
)
2109 /* Don't insert a breakpoint if we're trying to step past its
2110 location, except if the breakpoint is a single-step breakpoint,
2111 and the breakpoint's thread is the thread which is stepping past
2113 if ((bl
->loc_type
== bp_loc_software_breakpoint
2114 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2115 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2117 /* The single-step breakpoint may be inserted at the location
2118 we're trying to step if the instruction branches to itself.
2119 However, the instruction won't be executed at all and it may
2120 break the semantics of the instruction, for example, the
2121 instruction is a conditional branch or updates some flags.
2122 We can't fix it unless GDB is able to emulate the instruction
2123 or switch to displaced stepping. */
2124 && !(bl
->owner
->type
== bp_single_step
2125 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2127 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2128 paddress (bl
->gdbarch
, bl
->address
));
2132 /* Don't insert watchpoints if we're trying to step past the
2133 instruction that triggered one. */
2134 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2135 && stepping_past_nonsteppable_watchpoint ())
2137 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2138 "skipping watchpoint at %s:%d\n",
2139 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2146 /* Same as should_be_inserted but does the check assuming
2147 that the location is not duplicated. */
2150 unduplicated_should_be_inserted (struct bp_location
*bl
)
2153 const int save_duplicate
= bl
->duplicate
;
2156 result
= should_be_inserted (bl
);
2157 bl
->duplicate
= save_duplicate
;
2161 /* Parses a conditional described by an expression COND into an
2162 agent expression bytecode suitable for evaluation
2163 by the bytecode interpreter. Return NULL if there was
2164 any error during parsing. */
2166 static agent_expr_up
2167 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2172 agent_expr_up aexpr
;
2174 /* We don't want to stop processing, so catch any errors
2175 that may show up. */
2178 aexpr
= gen_eval_for_expr (scope
, cond
);
2181 catch (const gdb_exception_error
&ex
)
2183 /* If we got here, it means the condition could not be parsed to a valid
2184 bytecode expression and thus can't be evaluated on the target's side.
2185 It's no use iterating through the conditions. */
2188 /* We have a valid agent expression. */
2192 /* Based on location BL, create a list of breakpoint conditions to be
2193 passed on to the target. If we have duplicated locations with different
2194 conditions, we will add such conditions to the list. The idea is that the
2195 target will evaluate the list of conditions and will only notify GDB when
2196 one of them is true. */
2199 build_target_condition_list (struct bp_location
*bl
)
2201 struct bp_location
**locp
= NULL
, **loc2p
;
2202 int null_condition_or_parse_error
= 0;
2203 int modified
= bl
->needs_update
;
2204 struct bp_location
*loc
;
2206 /* Release conditions left over from a previous insert. */
2207 bl
->target_info
.conditions
.clear ();
2209 /* This is only meaningful if the target is
2210 evaluating conditions and if the user has
2211 opted for condition evaluation on the target's
2213 if (gdb_evaluates_breakpoint_condition_p ()
2214 || !target_supports_evaluation_of_breakpoint_conditions ())
2217 /* Do a first pass to check for locations with no assigned
2218 conditions or conditions that fail to parse to a valid agent
2219 expression bytecode. If any of these happen, then it's no use to
2220 send conditions to the target since this location will always
2221 trigger and generate a response back to GDB. Note we consider
2222 all locations at the same address irrespective of type, i.e.,
2223 even if the locations aren't considered duplicates (e.g.,
2224 software breakpoint and hardware breakpoint at the same
2226 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2229 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2233 /* Re-parse the conditions since something changed. In that
2234 case we already freed the condition bytecodes (see
2235 force_breakpoint_reinsertion). We just
2236 need to parse the condition to bytecodes again. */
2237 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2241 /* If we have a NULL bytecode expression, it means something
2242 went wrong or we have a null condition expression. */
2243 if (!loc
->cond_bytecode
)
2245 null_condition_or_parse_error
= 1;
2251 /* If any of these happened, it means we will have to evaluate the conditions
2252 for the location's address on gdb's side. It is no use keeping bytecodes
2253 for all the other duplicate locations, thus we free all of them here.
2255 This is so we have a finer control over which locations' conditions are
2256 being evaluated by GDB or the remote stub. */
2257 if (null_condition_or_parse_error
)
2259 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2262 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2264 /* Only go as far as the first NULL bytecode is
2266 if (!loc
->cond_bytecode
)
2269 loc
->cond_bytecode
.reset ();
2274 /* No NULL conditions or failed bytecode generation. Build a
2275 condition list for this location's address. If we have software
2276 and hardware locations at the same address, they aren't
2277 considered duplicates, but we still marge all the conditions
2278 anyway, as it's simpler, and doesn't really make a practical
2280 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2284 && is_breakpoint (loc
->owner
)
2285 && loc
->pspace
->num
== bl
->pspace
->num
2286 && loc
->owner
->enable_state
== bp_enabled
2288 && !loc
->disabled_by_cond
)
2290 /* Add the condition to the vector. This will be used later
2291 to send the conditions to the target. */
2292 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2299 /* Parses a command described by string CMD into an agent expression
2300 bytecode suitable for evaluation by the bytecode interpreter.
2301 Return NULL if there was any error during parsing. */
2303 static agent_expr_up
2304 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2306 const char *cmdrest
;
2307 const char *format_start
, *format_end
;
2308 struct gdbarch
*gdbarch
= get_current_arch ();
2315 if (*cmdrest
== ',')
2317 cmdrest
= skip_spaces (cmdrest
);
2319 if (*cmdrest
++ != '"')
2320 error (_("No format string following the location"));
2322 format_start
= cmdrest
;
2324 format_pieces
fpieces (&cmdrest
);
2326 format_end
= cmdrest
;
2328 if (*cmdrest
++ != '"')
2329 error (_("Bad format string, non-terminated '\"'."));
2331 cmdrest
= skip_spaces (cmdrest
);
2333 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2334 error (_("Invalid argument syntax"));
2336 if (*cmdrest
== ',')
2338 cmdrest
= skip_spaces (cmdrest
);
2340 /* For each argument, make an expression. */
2342 std::vector
<struct expression
*> argvec
;
2343 while (*cmdrest
!= '\0')
2348 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2349 argvec
.push_back (expr
.release ());
2351 if (*cmdrest
== ',')
2355 agent_expr_up aexpr
;
2357 /* We don't want to stop processing, so catch any errors
2358 that may show up. */
2361 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2362 format_start
, format_end
- format_start
,
2363 argvec
.size (), argvec
.data ());
2365 catch (const gdb_exception_error
&ex
)
2367 /* If we got here, it means the command could not be parsed to a valid
2368 bytecode expression and thus can't be evaluated on the target's side.
2369 It's no use iterating through the other commands. */
2372 /* We have a valid agent expression, return it. */
2376 /* Based on location BL, create a list of breakpoint commands to be
2377 passed on to the target. If we have duplicated locations with
2378 different commands, we will add any such to the list. */
2381 build_target_command_list (struct bp_location
*bl
)
2383 struct bp_location
**locp
= NULL
, **loc2p
;
2384 int null_command_or_parse_error
= 0;
2385 int modified
= bl
->needs_update
;
2386 struct bp_location
*loc
;
2388 /* Clear commands left over from a previous insert. */
2389 bl
->target_info
.tcommands
.clear ();
2391 if (!target_can_run_breakpoint_commands ())
2394 /* For now, limit to agent-style dprintf breakpoints. */
2395 if (dprintf_style
!= dprintf_style_agent
)
2398 /* For now, if we have any location at the same address that isn't a
2399 dprintf, don't install the target-side commands, as that would
2400 make the breakpoint not be reported to the core, and we'd lose
2402 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2405 if (is_breakpoint (loc
->owner
)
2406 && loc
->pspace
->num
== bl
->pspace
->num
2407 && loc
->owner
->type
!= bp_dprintf
)
2411 /* Do a first pass to check for locations with no assigned
2412 conditions or conditions that fail to parse to a valid agent expression
2413 bytecode. If any of these happen, then it's no use to send conditions
2414 to the target since this location will always trigger and generate a
2415 response back to GDB. */
2416 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2419 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2423 /* Re-parse the commands since something changed. In that
2424 case we already freed the command bytecodes (see
2425 force_breakpoint_reinsertion). We just
2426 need to parse the command to bytecodes again. */
2428 = parse_cmd_to_aexpr (bl
->address
,
2429 loc
->owner
->extra_string
);
2432 /* If we have a NULL bytecode expression, it means something
2433 went wrong or we have a null command expression. */
2434 if (!loc
->cmd_bytecode
)
2436 null_command_or_parse_error
= 1;
2442 /* If anything failed, then we're not doing target-side commands,
2444 if (null_command_or_parse_error
)
2446 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2449 if (is_breakpoint (loc
->owner
)
2450 && loc
->pspace
->num
== bl
->pspace
->num
)
2452 /* Only go as far as the first NULL bytecode is
2454 if (loc
->cmd_bytecode
== NULL
)
2457 loc
->cmd_bytecode
.reset ();
2462 /* No NULL commands or failed bytecode generation. Build a command
2463 list for all duplicate locations at this location's address.
2464 Note that here we must care for whether the breakpoint location
2465 types are considered duplicates, otherwise, say, if we have a
2466 software and hardware location at the same address, the target
2467 could end up running the commands twice. For the moment, we only
2468 support targets-side commands with dprintf, but it doesn't hurt
2469 to be pedantically correct in case that changes. */
2470 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2473 if (breakpoint_locations_match (bl
, loc
)
2474 && loc
->owner
->extra_string
2475 && is_breakpoint (loc
->owner
)
2476 && loc
->pspace
->num
== bl
->pspace
->num
2477 && loc
->owner
->enable_state
== bp_enabled
2479 && !loc
->disabled_by_cond
)
2481 /* Add the command to the vector. This will be used later
2482 to send the commands to the target. */
2483 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2487 bl
->target_info
.persist
= 0;
2488 /* Maybe flag this location as persistent. */
2489 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2490 bl
->target_info
.persist
= 1;
2493 /* Return the kind of breakpoint on address *ADDR. Get the kind
2494 of breakpoint according to ADDR except single-step breakpoint.
2495 Get the kind of single-step breakpoint according to the current
2499 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2501 if (bl
->owner
->type
== bp_single_step
)
2503 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2504 struct regcache
*regcache
;
2506 regcache
= get_thread_regcache (thr
);
2508 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2512 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2515 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2516 location. Any error messages are printed to TMP_ERROR_STREAM; and
2517 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2518 Returns 0 for success, 1 if the bp_location type is not supported or
2521 NOTE drow/2003-09-09: This routine could be broken down to an
2522 object-style method for each breakpoint or catchpoint type. */
2524 insert_bp_location (struct bp_location
*bl
,
2525 struct ui_file
*tmp_error_stream
,
2526 int *disabled_breaks
,
2527 int *hw_breakpoint_error
,
2528 int *hw_bp_error_explained_already
)
2530 gdb_exception bp_excpt
;
2532 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2535 /* Note we don't initialize bl->target_info, as that wipes out
2536 the breakpoint location's shadow_contents if the breakpoint
2537 is still inserted at that location. This in turn breaks
2538 target_read_memory which depends on these buffers when
2539 a memory read is requested at the breakpoint location:
2540 Once the target_info has been wiped, we fail to see that
2541 we have a breakpoint inserted at that address and thus
2542 read the breakpoint instead of returning the data saved in
2543 the breakpoint location's shadow contents. */
2544 bl
->target_info
.reqstd_address
= bl
->address
;
2545 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2546 bl
->target_info
.length
= bl
->length
;
2548 /* When working with target-side conditions, we must pass all the conditions
2549 for the same breakpoint address down to the target since GDB will not
2550 insert those locations. With a list of breakpoint conditions, the target
2551 can decide when to stop and notify GDB. */
2553 if (is_breakpoint (bl
->owner
))
2555 build_target_condition_list (bl
);
2556 build_target_command_list (bl
);
2557 /* Reset the modification marker. */
2558 bl
->needs_update
= 0;
2561 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2562 set at a read-only address, then a breakpoint location will have
2563 been changed to hardware breakpoint before we get here. If it is
2564 "off" however, error out before actually trying to insert the
2565 breakpoint, with a nicer error message. */
2566 if (bl
->loc_type
== bp_loc_software_breakpoint
2567 && !automatic_hardware_breakpoints
)
2569 mem_region
*mr
= lookup_mem_region (bl
->address
);
2571 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2573 fprintf_unfiltered (tmp_error_stream
,
2574 _("Cannot insert breakpoint %d.\n"
2575 "Cannot set software breakpoint "
2576 "at read-only address %s\n"),
2578 paddress (bl
->gdbarch
, bl
->address
));
2583 if (bl
->loc_type
== bp_loc_software_breakpoint
2584 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2586 /* First check to see if we have to handle an overlay. */
2587 if (overlay_debugging
== ovly_off
2588 || bl
->section
== NULL
2589 || !(section_is_overlay (bl
->section
)))
2591 /* No overlay handling: just set the breakpoint. */
2596 val
= bl
->owner
->ops
->insert_location (bl
);
2598 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2600 catch (gdb_exception
&e
)
2602 bp_excpt
= std::move (e
);
2607 /* This breakpoint is in an overlay section.
2608 Shall we set a breakpoint at the LMA? */
2609 if (!overlay_events_enabled
)
2611 /* Yes -- overlay event support is not active,
2612 so we must try to set a breakpoint at the LMA.
2613 This will not work for a hardware breakpoint. */
2614 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2615 warning (_("hardware breakpoint %d not supported in overlay!"),
2619 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2621 /* Set a software (trap) breakpoint at the LMA. */
2622 bl
->overlay_target_info
= bl
->target_info
;
2623 bl
->overlay_target_info
.reqstd_address
= addr
;
2625 /* No overlay handling: just set the breakpoint. */
2630 bl
->overlay_target_info
.kind
2631 = breakpoint_kind (bl
, &addr
);
2632 bl
->overlay_target_info
.placed_address
= addr
;
2633 val
= target_insert_breakpoint (bl
->gdbarch
,
2634 &bl
->overlay_target_info
);
2637 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2639 catch (gdb_exception
&e
)
2641 bp_excpt
= std::move (e
);
2644 if (bp_excpt
.reason
!= 0)
2645 fprintf_unfiltered (tmp_error_stream
,
2646 "Overlay breakpoint %d "
2647 "failed: in ROM?\n",
2651 /* Shall we set a breakpoint at the VMA? */
2652 if (section_is_mapped (bl
->section
))
2654 /* Yes. This overlay section is mapped into memory. */
2659 val
= bl
->owner
->ops
->insert_location (bl
);
2661 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2663 catch (gdb_exception
&e
)
2665 bp_excpt
= std::move (e
);
2670 /* No. This breakpoint will not be inserted.
2671 No error, but do not mark the bp as 'inserted'. */
2676 if (bp_excpt
.reason
!= 0)
2678 /* Can't set the breakpoint. */
2680 /* In some cases, we might not be able to insert a
2681 breakpoint in a shared library that has already been
2682 removed, but we have not yet processed the shlib unload
2683 event. Unfortunately, some targets that implement
2684 breakpoint insertion themselves can't tell why the
2685 breakpoint insertion failed (e.g., the remote target
2686 doesn't define error codes), so we must treat generic
2687 errors as memory errors. */
2688 if (bp_excpt
.reason
== RETURN_ERROR
2689 && (bp_excpt
.error
== GENERIC_ERROR
2690 || bp_excpt
.error
== MEMORY_ERROR
)
2691 && bl
->loc_type
== bp_loc_software_breakpoint
2692 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2693 || shared_objfile_contains_address_p (bl
->pspace
,
2696 /* See also: disable_breakpoints_in_shlibs. */
2697 bl
->shlib_disabled
= 1;
2698 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2699 if (!*disabled_breaks
)
2701 fprintf_unfiltered (tmp_error_stream
,
2702 "Cannot insert breakpoint %d.\n",
2704 fprintf_unfiltered (tmp_error_stream
,
2705 "Temporarily disabling shared "
2706 "library breakpoints:\n");
2708 *disabled_breaks
= 1;
2709 fprintf_unfiltered (tmp_error_stream
,
2710 "breakpoint #%d\n", bl
->owner
->number
);
2715 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2717 *hw_breakpoint_error
= 1;
2718 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2719 fprintf_unfiltered (tmp_error_stream
,
2720 "Cannot insert hardware breakpoint %d%s",
2722 bp_excpt
.message
? ":" : ".\n");
2723 if (bp_excpt
.message
!= NULL
)
2724 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2729 if (bp_excpt
.message
== NULL
)
2732 = memory_error_message (TARGET_XFER_E_IO
,
2733 bl
->gdbarch
, bl
->address
);
2735 fprintf_unfiltered (tmp_error_stream
,
2736 "Cannot insert breakpoint %d.\n"
2738 bl
->owner
->number
, message
.c_str ());
2742 fprintf_unfiltered (tmp_error_stream
,
2743 "Cannot insert breakpoint %d: %s\n",
2758 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2759 /* NOTE drow/2003-09-08: This state only exists for removing
2760 watchpoints. It's not clear that it's necessary... */
2761 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2765 gdb_assert (bl
->owner
->ops
!= NULL
2766 && bl
->owner
->ops
->insert_location
!= NULL
);
2768 val
= bl
->owner
->ops
->insert_location (bl
);
2770 /* If trying to set a read-watchpoint, and it turns out it's not
2771 supported, try emulating one with an access watchpoint. */
2772 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2774 struct bp_location
*loc
, **loc_temp
;
2776 /* But don't try to insert it, if there's already another
2777 hw_access location that would be considered a duplicate
2779 ALL_BP_LOCATIONS (loc
, loc_temp
)
2781 && loc
->watchpoint_type
== hw_access
2782 && watchpoint_locations_match (bl
, loc
))
2786 bl
->target_info
= loc
->target_info
;
2787 bl
->watchpoint_type
= hw_access
;
2794 bl
->watchpoint_type
= hw_access
;
2795 val
= bl
->owner
->ops
->insert_location (bl
);
2798 /* Back to the original value. */
2799 bl
->watchpoint_type
= hw_read
;
2803 bl
->inserted
= (val
== 0);
2806 else if (bl
->owner
->type
== bp_catchpoint
)
2810 gdb_assert (bl
->owner
->ops
!= NULL
2811 && bl
->owner
->ops
->insert_location
!= NULL
);
2813 val
= bl
->owner
->ops
->insert_location (bl
);
2816 bl
->owner
->enable_state
= bp_disabled
;
2820 Error inserting catchpoint %d: Your system does not support this type\n\
2821 of catchpoint."), bl
->owner
->number
);
2823 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2826 bl
->inserted
= (val
== 0);
2828 /* We've already printed an error message if there was a problem
2829 inserting this catchpoint, and we've disabled the catchpoint,
2830 so just return success. */
2837 /* This function is called when program space PSPACE is about to be
2838 deleted. It takes care of updating breakpoints to not reference
2842 breakpoint_program_space_exit (struct program_space
*pspace
)
2844 struct breakpoint
*b
, *b_temp
;
2845 struct bp_location
*loc
, **loc_temp
;
2847 /* Remove any breakpoint that was set through this program space. */
2848 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2850 if (b
->pspace
== pspace
)
2851 delete_breakpoint (b
);
2854 /* Breakpoints set through other program spaces could have locations
2855 bound to PSPACE as well. Remove those. */
2856 ALL_BP_LOCATIONS (loc
, loc_temp
)
2858 struct bp_location
*tmp
;
2860 if (loc
->pspace
== pspace
)
2862 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2863 if (loc
->owner
->loc
== loc
)
2864 loc
->owner
->loc
= loc
->next
;
2866 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2867 if (tmp
->next
== loc
)
2869 tmp
->next
= loc
->next
;
2875 /* Now update the global location list to permanently delete the
2876 removed locations above. */
2877 update_global_location_list (UGLL_DONT_INSERT
);
2880 /* Make sure all breakpoints are inserted in inferior.
2881 Throws exception on any error.
2882 A breakpoint that is already inserted won't be inserted
2883 again, so calling this function twice is safe. */
2885 insert_breakpoints (void)
2887 struct breakpoint
*bpt
;
2889 ALL_BREAKPOINTS (bpt
)
2890 if (is_hardware_watchpoint (bpt
))
2892 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2894 update_watchpoint (w
, 0 /* don't reparse. */);
2897 /* Updating watchpoints creates new locations, so update the global
2898 location list. Explicitly tell ugll to insert locations and
2899 ignore breakpoints_always_inserted_mode. Also,
2900 update_global_location_list tries to "upgrade" software
2901 breakpoints to hardware breakpoints to handle "set breakpoint
2902 auto-hw", so we need to call it even if we don't have new
2904 update_global_location_list (UGLL_INSERT
);
2907 /* Invoke CALLBACK for each of bp_location. */
2910 iterate_over_bp_locations (walk_bp_location_callback callback
)
2912 struct bp_location
*loc
, **loc_tmp
;
2914 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2916 callback (loc
, NULL
);
2920 /* This is used when we need to synch breakpoint conditions between GDB and the
2921 target. It is the case with deleting and disabling of breakpoints when using
2922 always-inserted mode. */
2925 update_inserted_breakpoint_locations (void)
2927 struct bp_location
*bl
, **blp_tmp
;
2930 int disabled_breaks
= 0;
2931 int hw_breakpoint_error
= 0;
2932 int hw_bp_details_reported
= 0;
2934 string_file tmp_error_stream
;
2936 /* Explicitly mark the warning -- this will only be printed if
2937 there was an error. */
2938 tmp_error_stream
.puts ("Warning:\n");
2940 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2942 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2944 /* We only want to update software breakpoints and hardware
2946 if (!is_breakpoint (bl
->owner
))
2949 /* We only want to update locations that are already inserted
2950 and need updating. This is to avoid unwanted insertion during
2951 deletion of breakpoints. */
2952 if (!bl
->inserted
|| !bl
->needs_update
)
2955 switch_to_program_space_and_thread (bl
->pspace
);
2957 /* For targets that support global breakpoints, there's no need
2958 to select an inferior to insert breakpoint to. In fact, even
2959 if we aren't attached to any process yet, we should still
2960 insert breakpoints. */
2961 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2962 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
2965 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2966 &hw_breakpoint_error
, &hw_bp_details_reported
);
2973 target_terminal::ours_for_output ();
2974 error_stream (tmp_error_stream
);
2978 /* Used when starting or continuing the program. */
2981 insert_breakpoint_locations (void)
2983 struct breakpoint
*bpt
;
2984 struct bp_location
*bl
, **blp_tmp
;
2987 int disabled_breaks
= 0;
2988 int hw_breakpoint_error
= 0;
2989 int hw_bp_error_explained_already
= 0;
2991 string_file tmp_error_stream
;
2993 /* Explicitly mark the warning -- this will only be printed if
2994 there was an error. */
2995 tmp_error_stream
.puts ("Warning:\n");
2997 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2999 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3001 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3004 /* There is no point inserting thread-specific breakpoints if
3005 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3006 has BL->OWNER always non-NULL. */
3007 if (bl
->owner
->thread
!= -1
3008 && !valid_global_thread_id (bl
->owner
->thread
))
3011 switch_to_program_space_and_thread (bl
->pspace
);
3013 /* For targets that support global breakpoints, there's no need
3014 to select an inferior to insert breakpoint to. In fact, even
3015 if we aren't attached to any process yet, we should still
3016 insert breakpoints. */
3017 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3018 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3021 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3022 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3027 /* If we failed to insert all locations of a watchpoint, remove
3028 them, as half-inserted watchpoint is of limited use. */
3029 ALL_BREAKPOINTS (bpt
)
3031 int some_failed
= 0;
3032 struct bp_location
*loc
;
3034 if (!is_hardware_watchpoint (bpt
))
3037 if (!breakpoint_enabled (bpt
))
3040 if (bpt
->disposition
== disp_del_at_next_stop
)
3043 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3044 if (!loc
->inserted
&& should_be_inserted (loc
))
3051 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3053 remove_breakpoint (loc
);
3055 hw_breakpoint_error
= 1;
3056 tmp_error_stream
.printf ("Could not insert "
3057 "hardware watchpoint %d.\n",
3065 /* If a hardware breakpoint or watchpoint was inserted, add a
3066 message about possibly exhausted resources. */
3067 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3069 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3070 You may have requested too many hardware breakpoints/watchpoints.\n");
3072 target_terminal::ours_for_output ();
3073 error_stream (tmp_error_stream
);
3077 /* Used when the program stops.
3078 Returns zero if successful, or non-zero if there was a problem
3079 removing a breakpoint location. */
3082 remove_breakpoints (void)
3084 struct bp_location
*bl
, **blp_tmp
;
3087 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3089 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3090 val
|= remove_breakpoint (bl
);
3095 /* When a thread exits, remove breakpoints that are related to
3099 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3101 struct breakpoint
*b
, *b_tmp
;
3103 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3105 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3107 b
->disposition
= disp_del_at_next_stop
;
3109 printf_filtered (_("\
3110 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3111 b
->number
, print_thread_id (tp
));
3113 /* Hide it from the user. */
3119 /* See breakpoint.h. */
3122 remove_breakpoints_inf (inferior
*inf
)
3124 struct bp_location
*bl
, **blp_tmp
;
3127 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3129 if (bl
->pspace
!= inf
->pspace
)
3132 if (bl
->inserted
&& !bl
->target_info
.persist
)
3134 val
= remove_breakpoint (bl
);
3141 static int internal_breakpoint_number
= -1;
3143 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3144 If INTERNAL is non-zero, the breakpoint number will be populated
3145 from internal_breakpoint_number and that variable decremented.
3146 Otherwise the breakpoint number will be populated from
3147 breakpoint_count and that value incremented. Internal breakpoints
3148 do not set the internal var bpnum. */
3150 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3153 b
->number
= internal_breakpoint_number
--;
3156 set_breakpoint_count (breakpoint_count
+ 1);
3157 b
->number
= breakpoint_count
;
3161 static struct breakpoint
*
3162 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3163 CORE_ADDR address
, enum bptype type
,
3164 const struct breakpoint_ops
*ops
)
3166 symtab_and_line sal
;
3168 sal
.section
= find_pc_overlay (sal
.pc
);
3169 sal
.pspace
= current_program_space
;
3171 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3172 b
->number
= internal_breakpoint_number
--;
3173 b
->disposition
= disp_donttouch
;
3178 static const char *const longjmp_names
[] =
3180 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3182 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3184 /* Per-objfile data private to breakpoint.c. */
3185 struct breakpoint_objfile_data
3187 /* Minimal symbol for "_ovly_debug_event" (if any). */
3188 struct bound_minimal_symbol overlay_msym
{};
3190 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3191 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3193 /* True if we have looked for longjmp probes. */
3194 int longjmp_searched
= 0;
3196 /* SystemTap probe points for longjmp (if any). These are non-owning
3198 std::vector
<probe
*> longjmp_probes
;
3200 /* Minimal symbol for "std::terminate()" (if any). */
3201 struct bound_minimal_symbol terminate_msym
{};
3203 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3204 struct bound_minimal_symbol exception_msym
{};
3206 /* True if we have looked for exception probes. */
3207 int exception_searched
= 0;
3209 /* SystemTap probe points for unwinding (if any). These are non-owning
3211 std::vector
<probe
*> exception_probes
;
3214 static const struct objfile_key
<breakpoint_objfile_data
>
3215 breakpoint_objfile_key
;
3217 /* Minimal symbol not found sentinel. */
3218 static struct minimal_symbol msym_not_found
;
3220 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3223 msym_not_found_p (const struct minimal_symbol
*msym
)
3225 return msym
== &msym_not_found
;
3228 /* Return per-objfile data needed by breakpoint.c.
3229 Allocate the data if necessary. */
3231 static struct breakpoint_objfile_data
*
3232 get_breakpoint_objfile_data (struct objfile
*objfile
)
3234 struct breakpoint_objfile_data
*bp_objfile_data
;
3236 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3237 if (bp_objfile_data
== NULL
)
3238 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3239 return bp_objfile_data
;
3243 create_overlay_event_breakpoint (void)
3245 const char *const func_name
= "_ovly_debug_event";
3247 for (objfile
*objfile
: current_program_space
->objfiles ())
3249 struct breakpoint
*b
;
3250 struct breakpoint_objfile_data
*bp_objfile_data
;
3252 struct explicit_location explicit_loc
;
3254 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3256 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3259 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3261 struct bound_minimal_symbol m
;
3263 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3264 if (m
.minsym
== NULL
)
3266 /* Avoid future lookups in this objfile. */
3267 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3270 bp_objfile_data
->overlay_msym
= m
;
3273 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3274 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3276 &internal_breakpoint_ops
);
3277 initialize_explicit_location (&explicit_loc
);
3278 explicit_loc
.function_name
= ASTRDUP (func_name
);
3279 b
->location
= new_explicit_location (&explicit_loc
);
3281 if (overlay_debugging
== ovly_auto
)
3283 b
->enable_state
= bp_enabled
;
3284 overlay_events_enabled
= 1;
3288 b
->enable_state
= bp_disabled
;
3289 overlay_events_enabled
= 0;
3295 create_longjmp_master_breakpoint (void)
3297 scoped_restore_current_program_space restore_pspace
;
3299 for (struct program_space
*pspace
: program_spaces
)
3301 set_current_program_space (pspace
);
3303 for (objfile
*objfile
: current_program_space
->objfiles ())
3306 struct gdbarch
*gdbarch
;
3307 struct breakpoint_objfile_data
*bp_objfile_data
;
3309 gdbarch
= objfile
->arch ();
3311 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3313 if (!bp_objfile_data
->longjmp_searched
)
3315 std::vector
<probe
*> ret
3316 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3320 /* We are only interested in checking one element. */
3323 if (!p
->can_evaluate_arguments ())
3325 /* We cannot use the probe interface here,
3326 because it does not know how to evaluate
3331 bp_objfile_data
->longjmp_probes
= ret
;
3332 bp_objfile_data
->longjmp_searched
= 1;
3335 if (!bp_objfile_data
->longjmp_probes
.empty ())
3337 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3339 struct breakpoint
*b
;
3341 b
= create_internal_breakpoint (gdbarch
,
3342 p
->get_relocated_address (objfile
),
3344 &internal_breakpoint_ops
);
3345 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3346 b
->enable_state
= bp_disabled
;
3352 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3355 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3357 struct breakpoint
*b
;
3358 const char *func_name
;
3360 struct explicit_location explicit_loc
;
3362 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3365 func_name
= longjmp_names
[i
];
3366 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3368 struct bound_minimal_symbol m
;
3370 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3371 if (m
.minsym
== NULL
)
3373 /* Prevent future lookups in this objfile. */
3374 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3377 bp_objfile_data
->longjmp_msym
[i
] = m
;
3380 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3381 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3382 &internal_breakpoint_ops
);
3383 initialize_explicit_location (&explicit_loc
);
3384 explicit_loc
.function_name
= ASTRDUP (func_name
);
3385 b
->location
= new_explicit_location (&explicit_loc
);
3386 b
->enable_state
= bp_disabled
;
3392 /* Create a master std::terminate breakpoint. */
3394 create_std_terminate_master_breakpoint (void)
3396 const char *const func_name
= "std::terminate()";
3398 scoped_restore_current_program_space restore_pspace
;
3400 for (struct program_space
*pspace
: program_spaces
)
3404 set_current_program_space (pspace
);
3406 for (objfile
*objfile
: current_program_space
->objfiles ())
3408 struct breakpoint
*b
;
3409 struct breakpoint_objfile_data
*bp_objfile_data
;
3410 struct explicit_location explicit_loc
;
3412 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3414 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3417 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3419 struct bound_minimal_symbol m
;
3421 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3422 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3423 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3425 /* Prevent future lookups in this objfile. */
3426 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3429 bp_objfile_data
->terminate_msym
= m
;
3432 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3433 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3434 bp_std_terminate_master
,
3435 &internal_breakpoint_ops
);
3436 initialize_explicit_location (&explicit_loc
);
3437 explicit_loc
.function_name
= ASTRDUP (func_name
);
3438 b
->location
= new_explicit_location (&explicit_loc
);
3439 b
->enable_state
= bp_disabled
;
3444 /* Install a master breakpoint on the unwinder's debug hook. */
3447 create_exception_master_breakpoint (void)
3449 const char *const func_name
= "_Unwind_DebugHook";
3451 for (objfile
*objfile
: current_program_space
->objfiles ())
3453 struct breakpoint
*b
;
3454 struct gdbarch
*gdbarch
;
3455 struct breakpoint_objfile_data
*bp_objfile_data
;
3457 struct explicit_location explicit_loc
;
3459 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3461 /* We prefer the SystemTap probe point if it exists. */
3462 if (!bp_objfile_data
->exception_searched
)
3464 std::vector
<probe
*> ret
3465 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3469 /* We are only interested in checking one element. */
3472 if (!p
->can_evaluate_arguments ())
3474 /* We cannot use the probe interface here, because it does
3475 not know how to evaluate arguments. */
3479 bp_objfile_data
->exception_probes
= ret
;
3480 bp_objfile_data
->exception_searched
= 1;
3483 if (!bp_objfile_data
->exception_probes
.empty ())
3485 gdbarch
= objfile
->arch ();
3487 for (probe
*p
: bp_objfile_data
->exception_probes
)
3489 b
= create_internal_breakpoint (gdbarch
,
3490 p
->get_relocated_address (objfile
),
3491 bp_exception_master
,
3492 &internal_breakpoint_ops
);
3493 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3494 b
->enable_state
= bp_disabled
;
3500 /* Otherwise, try the hook function. */
3502 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3505 gdbarch
= objfile
->arch ();
3507 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3509 struct bound_minimal_symbol debug_hook
;
3511 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3512 if (debug_hook
.minsym
== NULL
)
3514 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3518 bp_objfile_data
->exception_msym
= debug_hook
;
3521 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3522 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3523 current_top_target ());
3524 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3525 &internal_breakpoint_ops
);
3526 initialize_explicit_location (&explicit_loc
);
3527 explicit_loc
.function_name
= ASTRDUP (func_name
);
3528 b
->location
= new_explicit_location (&explicit_loc
);
3529 b
->enable_state
= bp_disabled
;
3533 /* Does B have a location spec? */
3536 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3538 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3542 update_breakpoints_after_exec (void)
3544 struct breakpoint
*b
, *b_tmp
;
3545 struct bp_location
*bploc
, **bplocp_tmp
;
3547 /* We're about to delete breakpoints from GDB's lists. If the
3548 INSERTED flag is true, GDB will try to lift the breakpoints by
3549 writing the breakpoints' "shadow contents" back into memory. The
3550 "shadow contents" are NOT valid after an exec, so GDB should not
3551 do that. Instead, the target is responsible from marking
3552 breakpoints out as soon as it detects an exec. We don't do that
3553 here instead, because there may be other attempts to delete
3554 breakpoints after detecting an exec and before reaching here. */
3555 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3556 if (bploc
->pspace
== current_program_space
)
3557 gdb_assert (!bploc
->inserted
);
3559 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3561 if (b
->pspace
!= current_program_space
)
3564 /* Solib breakpoints must be explicitly reset after an exec(). */
3565 if (b
->type
== bp_shlib_event
)
3567 delete_breakpoint (b
);
3571 /* JIT breakpoints must be explicitly reset after an exec(). */
3572 if (b
->type
== bp_jit_event
)
3574 delete_breakpoint (b
);
3578 /* Thread event breakpoints must be set anew after an exec(),
3579 as must overlay event and longjmp master breakpoints. */
3580 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3581 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3582 || b
->type
== bp_exception_master
)
3584 delete_breakpoint (b
);
3588 /* Step-resume breakpoints are meaningless after an exec(). */
3589 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3591 delete_breakpoint (b
);
3595 /* Just like single-step breakpoints. */
3596 if (b
->type
== bp_single_step
)
3598 delete_breakpoint (b
);
3602 /* Longjmp and longjmp-resume breakpoints are also meaningless
3604 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3605 || b
->type
== bp_longjmp_call_dummy
3606 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3608 delete_breakpoint (b
);
3612 if (b
->type
== bp_catchpoint
)
3614 /* For now, none of the bp_catchpoint breakpoints need to
3615 do anything at this point. In the future, if some of
3616 the catchpoints need to something, we will need to add
3617 a new method, and call this method from here. */
3621 /* bp_finish is a special case. The only way we ought to be able
3622 to see one of these when an exec() has happened, is if the user
3623 caught a vfork, and then said "finish". Ordinarily a finish just
3624 carries them to the call-site of the current callee, by setting
3625 a temporary bp there and resuming. But in this case, the finish
3626 will carry them entirely through the vfork & exec.
3628 We don't want to allow a bp_finish to remain inserted now. But
3629 we can't safely delete it, 'cause finish_command has a handle to
3630 the bp on a bpstat, and will later want to delete it. There's a
3631 chance (and I've seen it happen) that if we delete the bp_finish
3632 here, that its storage will get reused by the time finish_command
3633 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3634 We really must allow finish_command to delete a bp_finish.
3636 In the absence of a general solution for the "how do we know
3637 it's safe to delete something others may have handles to?"
3638 problem, what we'll do here is just uninsert the bp_finish, and
3639 let finish_command delete it.
3641 (We know the bp_finish is "doomed" in the sense that it's
3642 momentary, and will be deleted as soon as finish_command sees
3643 the inferior stopped. So it doesn't matter that the bp's
3644 address is probably bogus in the new a.out, unlike e.g., the
3645 solib breakpoints.) */
3647 if (b
->type
== bp_finish
)
3652 /* Without a symbolic address, we have little hope of the
3653 pre-exec() address meaning the same thing in the post-exec()
3655 if (breakpoint_event_location_empty_p (b
))
3657 delete_breakpoint (b
);
3664 detach_breakpoints (ptid_t ptid
)
3666 struct bp_location
*bl
, **blp_tmp
;
3668 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3669 struct inferior
*inf
= current_inferior ();
3671 if (ptid
.pid () == inferior_ptid
.pid ())
3672 error (_("Cannot detach breakpoints of inferior_ptid"));
3674 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3675 inferior_ptid
= ptid
;
3676 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3678 if (bl
->pspace
!= inf
->pspace
)
3681 /* This function must physically remove breakpoints locations
3682 from the specified ptid, without modifying the breakpoint
3683 package's state. Locations of type bp_loc_other are only
3684 maintained at GDB side. So, there is no need to remove
3685 these bp_loc_other locations. Moreover, removing these
3686 would modify the breakpoint package's state. */
3687 if (bl
->loc_type
== bp_loc_other
)
3691 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3697 /* Remove the breakpoint location BL from the current address space.
3698 Note that this is used to detach breakpoints from a child fork.
3699 When we get here, the child isn't in the inferior list, and neither
3700 do we have objects to represent its address space --- we should
3701 *not* look at bl->pspace->aspace here. */
3704 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3708 /* BL is never in moribund_locations by our callers. */
3709 gdb_assert (bl
->owner
!= NULL
);
3711 /* The type of none suggests that owner is actually deleted.
3712 This should not ever happen. */
3713 gdb_assert (bl
->owner
->type
!= bp_none
);
3715 if (bl
->loc_type
== bp_loc_software_breakpoint
3716 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3718 /* "Normal" instruction breakpoint: either the standard
3719 trap-instruction bp (bp_breakpoint), or a
3720 bp_hardware_breakpoint. */
3722 /* First check to see if we have to handle an overlay. */
3723 if (overlay_debugging
== ovly_off
3724 || bl
->section
== NULL
3725 || !(section_is_overlay (bl
->section
)))
3727 /* No overlay handling: just remove the breakpoint. */
3729 /* If we're trying to uninsert a memory breakpoint that we
3730 know is set in a dynamic object that is marked
3731 shlib_disabled, then either the dynamic object was
3732 removed with "remove-symbol-file" or with
3733 "nosharedlibrary". In the former case, we don't know
3734 whether another dynamic object might have loaded over the
3735 breakpoint's address -- the user might well let us know
3736 about it next with add-symbol-file (the whole point of
3737 add-symbol-file is letting the user manually maintain a
3738 list of dynamically loaded objects). If we have the
3739 breakpoint's shadow memory, that is, this is a software
3740 breakpoint managed by GDB, check whether the breakpoint
3741 is still inserted in memory, to avoid overwriting wrong
3742 code with stale saved shadow contents. Note that HW
3743 breakpoints don't have shadow memory, as they're
3744 implemented using a mechanism that is not dependent on
3745 being able to modify the target's memory, and as such
3746 they should always be removed. */
3747 if (bl
->shlib_disabled
3748 && bl
->target_info
.shadow_len
!= 0
3749 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3752 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3756 /* This breakpoint is in an overlay section.
3757 Did we set a breakpoint at the LMA? */
3758 if (!overlay_events_enabled
)
3760 /* Yes -- overlay event support is not active, so we
3761 should have set a breakpoint at the LMA. Remove it.
3763 /* Ignore any failures: if the LMA is in ROM, we will
3764 have already warned when we failed to insert it. */
3765 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3766 target_remove_hw_breakpoint (bl
->gdbarch
,
3767 &bl
->overlay_target_info
);
3769 target_remove_breakpoint (bl
->gdbarch
,
3770 &bl
->overlay_target_info
,
3773 /* Did we set a breakpoint at the VMA?
3774 If so, we will have marked the breakpoint 'inserted'. */
3777 /* Yes -- remove it. Previously we did not bother to
3778 remove the breakpoint if the section had been
3779 unmapped, but let's not rely on that being safe. We
3780 don't know what the overlay manager might do. */
3782 /* However, we should remove *software* breakpoints only
3783 if the section is still mapped, or else we overwrite
3784 wrong code with the saved shadow contents. */
3785 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3786 || section_is_mapped (bl
->section
))
3787 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3793 /* No -- not inserted, so no need to remove. No error. */
3798 /* In some cases, we might not be able to remove a breakpoint in
3799 a shared library that has already been removed, but we have
3800 not yet processed the shlib unload event. Similarly for an
3801 unloaded add-symbol-file object - the user might not yet have
3802 had the chance to remove-symbol-file it. shlib_disabled will
3803 be set if the library/object has already been removed, but
3804 the breakpoint hasn't been uninserted yet, e.g., after
3805 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3806 always-inserted mode. */
3808 && (bl
->loc_type
== bp_loc_software_breakpoint
3809 && (bl
->shlib_disabled
3810 || solib_name_from_address (bl
->pspace
, bl
->address
)
3811 || shared_objfile_contains_address_p (bl
->pspace
,
3817 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3819 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3821 gdb_assert (bl
->owner
->ops
!= NULL
3822 && bl
->owner
->ops
->remove_location
!= NULL
);
3824 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3825 bl
->owner
->ops
->remove_location (bl
, reason
);
3827 /* Failure to remove any of the hardware watchpoints comes here. */
3828 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3829 warning (_("Could not remove hardware watchpoint %d."),
3832 else if (bl
->owner
->type
== bp_catchpoint
3833 && breakpoint_enabled (bl
->owner
)
3836 gdb_assert (bl
->owner
->ops
!= NULL
3837 && bl
->owner
->ops
->remove_location
!= NULL
);
3839 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3843 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3850 remove_breakpoint (struct bp_location
*bl
)
3852 /* BL is never in moribund_locations by our callers. */
3853 gdb_assert (bl
->owner
!= NULL
);
3855 /* The type of none suggests that owner is actually deleted.
3856 This should not ever happen. */
3857 gdb_assert (bl
->owner
->type
!= bp_none
);
3859 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3861 switch_to_program_space_and_thread (bl
->pspace
);
3863 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3866 /* Clear the "inserted" flag in all breakpoints. */
3869 mark_breakpoints_out (void)
3871 struct bp_location
*bl
, **blp_tmp
;
3873 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3874 if (bl
->pspace
== current_program_space
)
3878 /* Clear the "inserted" flag in all breakpoints and delete any
3879 breakpoints which should go away between runs of the program.
3881 Plus other such housekeeping that has to be done for breakpoints
3884 Note: this function gets called at the end of a run (by
3885 generic_mourn_inferior) and when a run begins (by
3886 init_wait_for_inferior). */
3891 breakpoint_init_inferior (enum inf_context context
)
3893 struct breakpoint
*b
, *b_tmp
;
3894 struct program_space
*pspace
= current_program_space
;
3896 /* If breakpoint locations are shared across processes, then there's
3898 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3901 mark_breakpoints_out ();
3903 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3905 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3911 case bp_longjmp_call_dummy
:
3913 /* If the call dummy breakpoint is at the entry point it will
3914 cause problems when the inferior is rerun, so we better get
3917 case bp_watchpoint_scope
:
3919 /* Also get rid of scope breakpoints. */
3921 case bp_shlib_event
:
3923 /* Also remove solib event breakpoints. Their addresses may
3924 have changed since the last time we ran the program.
3925 Actually we may now be debugging against different target;
3926 and so the solib backend that installed this breakpoint may
3927 not be used in by the target. E.g.,
3929 (gdb) file prog-linux
3930 (gdb) run # native linux target
3933 (gdb) file prog-win.exe
3934 (gdb) tar rem :9999 # remote Windows gdbserver.
3937 case bp_step_resume
:
3939 /* Also remove step-resume breakpoints. */
3941 case bp_single_step
:
3943 /* Also remove single-step breakpoints. */
3945 delete_breakpoint (b
);
3949 case bp_hardware_watchpoint
:
3950 case bp_read_watchpoint
:
3951 case bp_access_watchpoint
:
3953 struct watchpoint
*w
= (struct watchpoint
*) b
;
3955 /* Likewise for watchpoints on local expressions. */
3956 if (w
->exp_valid_block
!= NULL
)
3957 delete_breakpoint (b
);
3960 /* Get rid of existing locations, which are no longer
3961 valid. New ones will be created in
3962 update_watchpoint, when the inferior is restarted.
3963 The next update_global_location_list call will
3964 garbage collect them. */
3967 if (context
== inf_starting
)
3969 /* Reset val field to force reread of starting value in
3970 insert_breakpoints. */
3971 w
->val
.reset (nullptr);
3972 w
->val_valid
= false;
3982 /* Get rid of the moribund locations. */
3983 for (bp_location
*bl
: moribund_locations
)
3984 decref_bp_location (&bl
);
3985 moribund_locations
.clear ();
3988 /* These functions concern about actual breakpoints inserted in the
3989 target --- to e.g. check if we need to do decr_pc adjustment or if
3990 we need to hop over the bkpt --- so we check for address space
3991 match, not program space. */
3993 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3994 exists at PC. It returns ordinary_breakpoint_here if it's an
3995 ordinary breakpoint, or permanent_breakpoint_here if it's a
3996 permanent breakpoint.
3997 - When continuing from a location with an ordinary breakpoint, we
3998 actually single step once before calling insert_breakpoints.
3999 - When continuing from a location with a permanent breakpoint, we
4000 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4001 the target, to advance the PC past the breakpoint. */
4003 enum breakpoint_here
4004 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4006 struct bp_location
*bl
, **blp_tmp
;
4007 int any_breakpoint_here
= 0;
4009 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4011 if (bl
->loc_type
!= bp_loc_software_breakpoint
4012 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4015 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4016 if ((breakpoint_enabled (bl
->owner
)
4018 && breakpoint_location_address_match (bl
, aspace
, pc
))
4020 if (overlay_debugging
4021 && section_is_overlay (bl
->section
)
4022 && !section_is_mapped (bl
->section
))
4023 continue; /* unmapped overlay -- can't be a match */
4024 else if (bl
->permanent
)
4025 return permanent_breakpoint_here
;
4027 any_breakpoint_here
= 1;
4031 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4034 /* See breakpoint.h. */
4037 breakpoint_in_range_p (const address_space
*aspace
,
4038 CORE_ADDR addr
, ULONGEST len
)
4040 struct bp_location
*bl
, **blp_tmp
;
4042 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4044 if (bl
->loc_type
!= bp_loc_software_breakpoint
4045 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4048 if ((breakpoint_enabled (bl
->owner
)
4050 && breakpoint_location_address_range_overlap (bl
, aspace
,
4053 if (overlay_debugging
4054 && section_is_overlay (bl
->section
)
4055 && !section_is_mapped (bl
->section
))
4057 /* Unmapped overlay -- can't be a match. */
4068 /* Return true if there's a moribund breakpoint at PC. */
4071 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4073 for (bp_location
*loc
: moribund_locations
)
4074 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4080 /* Returns non-zero iff BL is inserted at PC, in address space
4084 bp_location_inserted_here_p (struct bp_location
*bl
,
4085 const address_space
*aspace
, CORE_ADDR pc
)
4088 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4091 if (overlay_debugging
4092 && section_is_overlay (bl
->section
)
4093 && !section_is_mapped (bl
->section
))
4094 return 0; /* unmapped overlay -- can't be a match */
4101 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4104 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4106 struct bp_location
**blp
, **blp_tmp
= NULL
;
4108 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4110 struct bp_location
*bl
= *blp
;
4112 if (bl
->loc_type
!= bp_loc_software_breakpoint
4113 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4116 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4122 /* This function returns non-zero iff there is a software breakpoint
4126 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4129 struct bp_location
**blp
, **blp_tmp
= NULL
;
4131 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4133 struct bp_location
*bl
= *blp
;
4135 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4138 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4145 /* See breakpoint.h. */
4148 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4151 struct bp_location
**blp
, **blp_tmp
= NULL
;
4153 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4155 struct bp_location
*bl
= *blp
;
4157 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4160 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4168 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4169 CORE_ADDR addr
, ULONGEST len
)
4171 struct breakpoint
*bpt
;
4173 ALL_BREAKPOINTS (bpt
)
4175 struct bp_location
*loc
;
4177 if (bpt
->type
!= bp_hardware_watchpoint
4178 && bpt
->type
!= bp_access_watchpoint
)
4181 if (!breakpoint_enabled (bpt
))
4184 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4185 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4189 /* Check for intersection. */
4190 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4191 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4199 /* See breakpoint.h. */
4202 is_catchpoint (struct breakpoint
*b
)
4204 return (b
->type
== bp_catchpoint
);
4207 /* Frees any storage that is part of a bpstat. Does not walk the
4210 bpstats::~bpstats ()
4212 if (bp_location_at
!= NULL
)
4213 decref_bp_location (&bp_location_at
);
4216 /* Clear a bpstat so that it says we are not at any breakpoint.
4217 Also free any storage that is part of a bpstat. */
4220 bpstat_clear (bpstat
*bsp
)
4237 bpstats::bpstats (const bpstats
&other
)
4239 bp_location_at (other
.bp_location_at
),
4240 breakpoint_at (other
.breakpoint_at
),
4241 commands (other
.commands
),
4242 print (other
.print
),
4244 print_it (other
.print_it
)
4246 if (other
.old_val
!= NULL
)
4247 old_val
= release_value (value_copy (other
.old_val
.get ()));
4248 incref_bp_location (bp_location_at
);
4251 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4252 is part of the bpstat is copied as well. */
4255 bpstat_copy (bpstat bs
)
4259 bpstat retval
= NULL
;
4264 for (; bs
!= NULL
; bs
= bs
->next
)
4266 tmp
= new bpstats (*bs
);
4269 /* This is the first thing in the chain. */
4279 /* Find the bpstat associated with this breakpoint. */
4282 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4287 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4289 if (bsp
->breakpoint_at
== breakpoint
)
4295 /* See breakpoint.h. */
4298 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4300 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4302 if (bsp
->breakpoint_at
== NULL
)
4304 /* A moribund location can never explain a signal other than
4306 if (sig
== GDB_SIGNAL_TRAP
)
4311 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4320 /* Put in *NUM the breakpoint number of the first breakpoint we are
4321 stopped at. *BSP upon return is a bpstat which points to the
4322 remaining breakpoints stopped at (but which is not guaranteed to be
4323 good for anything but further calls to bpstat_num).
4325 Return 0 if passed a bpstat which does not indicate any breakpoints.
4326 Return -1 if stopped at a breakpoint that has been deleted since
4328 Return 1 otherwise. */
4331 bpstat_num (bpstat
*bsp
, int *num
)
4333 struct breakpoint
*b
;
4336 return 0; /* No more breakpoint values */
4338 /* We assume we'll never have several bpstats that correspond to a
4339 single breakpoint -- otherwise, this function might return the
4340 same number more than once and this will look ugly. */
4341 b
= (*bsp
)->breakpoint_at
;
4342 *bsp
= (*bsp
)->next
;
4344 return -1; /* breakpoint that's been deleted since */
4346 *num
= b
->number
; /* We have its number */
4350 /* See breakpoint.h. */
4353 bpstat_clear_actions (void)
4357 if (inferior_ptid
== null_ptid
)
4360 thread_info
*tp
= inferior_thread ();
4361 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4363 bs
->commands
= NULL
;
4364 bs
->old_val
.reset (nullptr);
4368 /* Called when a command is about to proceed the inferior. */
4371 breakpoint_about_to_proceed (void)
4373 if (inferior_ptid
!= null_ptid
)
4375 struct thread_info
*tp
= inferior_thread ();
4377 /* Allow inferior function calls in breakpoint commands to not
4378 interrupt the command list. When the call finishes
4379 successfully, the inferior will be standing at the same
4380 breakpoint as if nothing happened. */
4381 if (tp
->control
.in_infcall
)
4385 breakpoint_proceeded
= 1;
4388 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4389 or its equivalent. */
4392 command_line_is_silent (struct command_line
*cmd
)
4394 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4397 /* Execute all the commands associated with all the breakpoints at
4398 this location. Any of these commands could cause the process to
4399 proceed beyond this point, etc. We look out for such changes by
4400 checking the global "breakpoint_proceeded" after each command.
4402 Returns true if a breakpoint command resumed the inferior. In that
4403 case, it is the caller's responsibility to recall it again with the
4404 bpstat of the current thread. */
4407 bpstat_do_actions_1 (bpstat
*bsp
)
4412 /* Avoid endless recursion if a `source' command is contained
4414 if (executing_breakpoint_commands
)
4417 scoped_restore save_executing
4418 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4420 scoped_restore preventer
= prevent_dont_repeat ();
4422 /* This pointer will iterate over the list of bpstat's. */
4425 breakpoint_proceeded
= 0;
4426 for (; bs
!= NULL
; bs
= bs
->next
)
4428 struct command_line
*cmd
= NULL
;
4430 /* Take ownership of the BSP's command tree, if it has one.
4432 The command tree could legitimately contain commands like
4433 'step' and 'next', which call clear_proceed_status, which
4434 frees stop_bpstat's command tree. To make sure this doesn't
4435 free the tree we're executing out from under us, we need to
4436 take ownership of the tree ourselves. Since a given bpstat's
4437 commands are only executed once, we don't need to copy it; we
4438 can clear the pointer in the bpstat, and make sure we free
4439 the tree when we're done. */
4440 counted_command_line ccmd
= bs
->commands
;
4441 bs
->commands
= NULL
;
4444 if (command_line_is_silent (cmd
))
4446 /* The action has been already done by bpstat_stop_status. */
4452 execute_control_command (cmd
);
4454 if (breakpoint_proceeded
)
4460 if (breakpoint_proceeded
)
4462 if (current_ui
->async
)
4463 /* If we are in async mode, then the target might be still
4464 running, not stopped at any breakpoint, so nothing for
4465 us to do here -- just return to the event loop. */
4468 /* In sync mode, when execute_control_command returns
4469 we're already standing on the next breakpoint.
4470 Breakpoint commands for that stop were not run, since
4471 execute_command does not run breakpoint commands --
4472 only command_line_handler does, but that one is not
4473 involved in execution of breakpoint commands. So, we
4474 can now execute breakpoint commands. It should be
4475 noted that making execute_command do bpstat actions is
4476 not an option -- in this case we'll have recursive
4477 invocation of bpstat for each breakpoint with a
4478 command, and can easily blow up GDB stack. Instead, we
4479 return true, which will trigger the caller to recall us
4480 with the new stop_bpstat. */
4488 /* Helper for bpstat_do_actions. Get the current thread, if there's
4489 one, is alive and has execution. Return NULL otherwise. */
4491 static thread_info
*
4492 get_bpstat_thread ()
4494 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4497 thread_info
*tp
= inferior_thread ();
4498 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4504 bpstat_do_actions (void)
4506 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4509 /* Do any commands attached to breakpoint we are stopped at. */
4510 while ((tp
= get_bpstat_thread ()) != NULL
)
4512 /* Since in sync mode, bpstat_do_actions may resume the
4513 inferior, and only return when it is stopped at the next
4514 breakpoint, we keep doing breakpoint actions until it returns
4515 false to indicate the inferior was not resumed. */
4516 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4520 cleanup_if_error
.release ();
4523 /* Print out the (old or new) value associated with a watchpoint. */
4526 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4529 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4532 struct value_print_options opts
;
4533 get_user_print_options (&opts
);
4534 value_print (val
, stream
, &opts
);
4538 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4539 debugging multiple threads. */
4542 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4544 if (uiout
->is_mi_like_p ())
4549 if (show_thread_that_caused_stop ())
4552 struct thread_info
*thr
= inferior_thread ();
4554 uiout
->text ("Thread ");
4555 uiout
->field_string ("thread-id", print_thread_id (thr
));
4557 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4560 uiout
->text (" \"");
4561 uiout
->field_string ("name", name
);
4565 uiout
->text (" hit ");
4569 /* Generic routine for printing messages indicating why we
4570 stopped. The behavior of this function depends on the value
4571 'print_it' in the bpstat structure. Under some circumstances we
4572 may decide not to print anything here and delegate the task to
4575 static enum print_stop_action
4576 print_bp_stop_message (bpstat bs
)
4578 switch (bs
->print_it
)
4581 /* Nothing should be printed for this bpstat entry. */
4582 return PRINT_UNKNOWN
;
4586 /* We still want to print the frame, but we already printed the
4587 relevant messages. */
4588 return PRINT_SRC_AND_LOC
;
4591 case print_it_normal
:
4593 struct breakpoint
*b
= bs
->breakpoint_at
;
4595 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4596 which has since been deleted. */
4598 return PRINT_UNKNOWN
;
4600 /* Normal case. Call the breakpoint's print_it method. */
4601 return b
->ops
->print_it (bs
);
4606 internal_error (__FILE__
, __LINE__
,
4607 _("print_bp_stop_message: unrecognized enum value"));
4612 /* A helper function that prints a shared library stopped event. */
4615 print_solib_event (int is_catchpoint
)
4617 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4618 bool any_added
= !current_program_space
->added_solibs
.empty ();
4622 if (any_added
|| any_deleted
)
4623 current_uiout
->text (_("Stopped due to shared library event:\n"));
4625 current_uiout
->text (_("Stopped due to shared library event (no "
4626 "libraries added or removed)\n"));
4629 if (current_uiout
->is_mi_like_p ())
4630 current_uiout
->field_string ("reason",
4631 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4635 current_uiout
->text (_(" Inferior unloaded "));
4636 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4637 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4639 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4642 current_uiout
->text (" ");
4643 current_uiout
->field_string ("library", name
);
4644 current_uiout
->text ("\n");
4650 current_uiout
->text (_(" Inferior loaded "));
4651 ui_out_emit_list
list_emitter (current_uiout
, "added");
4653 for (so_list
*iter
: current_program_space
->added_solibs
)
4656 current_uiout
->text (" ");
4658 current_uiout
->field_string ("library", iter
->so_name
);
4659 current_uiout
->text ("\n");
4664 /* Print a message indicating what happened. This is called from
4665 normal_stop(). The input to this routine is the head of the bpstat
4666 list - a list of the eventpoints that caused this stop. KIND is
4667 the target_waitkind for the stopping event. This
4668 routine calls the generic print routine for printing a message
4669 about reasons for stopping. This will print (for example) the
4670 "Breakpoint n," part of the output. The return value of this
4673 PRINT_UNKNOWN: Means we printed nothing.
4674 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4675 code to print the location. An example is
4676 "Breakpoint 1, " which should be followed by
4678 PRINT_SRC_ONLY: Means we printed something, but there is no need
4679 to also print the location part of the message.
4680 An example is the catch/throw messages, which
4681 don't require a location appended to the end.
4682 PRINT_NOTHING: We have done some printing and we don't need any
4683 further info to be printed. */
4685 enum print_stop_action
4686 bpstat_print (bpstat bs
, int kind
)
4688 enum print_stop_action val
;
4690 /* Maybe another breakpoint in the chain caused us to stop.
4691 (Currently all watchpoints go on the bpstat whether hit or not.
4692 That probably could (should) be changed, provided care is taken
4693 with respect to bpstat_explains_signal). */
4694 for (; bs
; bs
= bs
->next
)
4696 val
= print_bp_stop_message (bs
);
4697 if (val
== PRINT_SRC_ONLY
4698 || val
== PRINT_SRC_AND_LOC
4699 || val
== PRINT_NOTHING
)
4703 /* If we had hit a shared library event breakpoint,
4704 print_bp_stop_message would print out this message. If we hit an
4705 OS-level shared library event, do the same thing. */
4706 if (kind
== TARGET_WAITKIND_LOADED
)
4708 print_solib_event (0);
4709 return PRINT_NOTHING
;
4712 /* We reached the end of the chain, or we got a null BS to start
4713 with and nothing was printed. */
4714 return PRINT_UNKNOWN
;
4717 /* Evaluate the boolean expression EXP and return the result. */
4720 breakpoint_cond_eval (expression
*exp
)
4722 struct value
*mark
= value_mark ();
4723 bool res
= value_true (evaluate_expression (exp
));
4725 value_free_to_mark (mark
);
4729 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4731 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4733 bp_location_at (bl
),
4734 breakpoint_at (bl
->owner
),
4738 print_it (print_it_normal
)
4740 incref_bp_location (bl
);
4741 **bs_link_pointer
= this;
4742 *bs_link_pointer
= &next
;
4747 bp_location_at (NULL
),
4748 breakpoint_at (NULL
),
4752 print_it (print_it_normal
)
4756 /* The target has stopped with waitstatus WS. Check if any hardware
4757 watchpoints have triggered, according to the target. */
4760 watchpoints_triggered (struct target_waitstatus
*ws
)
4762 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4764 struct breakpoint
*b
;
4766 if (!stopped_by_watchpoint
)
4768 /* We were not stopped by a watchpoint. Mark all watchpoints
4769 as not triggered. */
4771 if (is_hardware_watchpoint (b
))
4773 struct watchpoint
*w
= (struct watchpoint
*) b
;
4775 w
->watchpoint_triggered
= watch_triggered_no
;
4781 if (!target_stopped_data_address (current_top_target (), &addr
))
4783 /* We were stopped by a watchpoint, but we don't know where.
4784 Mark all watchpoints as unknown. */
4786 if (is_hardware_watchpoint (b
))
4788 struct watchpoint
*w
= (struct watchpoint
*) b
;
4790 w
->watchpoint_triggered
= watch_triggered_unknown
;
4796 /* The target could report the data address. Mark watchpoints
4797 affected by this data address as triggered, and all others as not
4801 if (is_hardware_watchpoint (b
))
4803 struct watchpoint
*w
= (struct watchpoint
*) b
;
4804 struct bp_location
*loc
;
4806 w
->watchpoint_triggered
= watch_triggered_no
;
4807 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4809 if (is_masked_watchpoint (b
))
4811 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4812 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4814 if (newaddr
== start
)
4816 w
->watchpoint_triggered
= watch_triggered_yes
;
4820 /* Exact match not required. Within range is sufficient. */
4821 else if (target_watchpoint_addr_within_range (current_top_target (),
4825 w
->watchpoint_triggered
= watch_triggered_yes
;
4834 /* Possible return values for watchpoint_check. */
4835 enum wp_check_result
4837 /* The watchpoint has been deleted. */
4840 /* The value has changed. */
4841 WP_VALUE_CHANGED
= 2,
4843 /* The value has not changed. */
4844 WP_VALUE_NOT_CHANGED
= 3,
4846 /* Ignore this watchpoint, no matter if the value changed or not. */
4850 #define BP_TEMPFLAG 1
4851 #define BP_HARDWAREFLAG 2
4853 /* Evaluate watchpoint condition expression and check if its value
4856 static wp_check_result
4857 watchpoint_check (bpstat bs
)
4859 struct watchpoint
*b
;
4860 struct frame_info
*fr
;
4861 int within_current_scope
;
4863 /* BS is built from an existing struct breakpoint. */
4864 gdb_assert (bs
->breakpoint_at
!= NULL
);
4865 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4867 /* If this is a local watchpoint, we only want to check if the
4868 watchpoint frame is in scope if the current thread is the thread
4869 that was used to create the watchpoint. */
4870 if (!watchpoint_in_thread_scope (b
))
4873 if (b
->exp_valid_block
== NULL
)
4874 within_current_scope
= 1;
4877 struct frame_info
*frame
= get_current_frame ();
4878 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4879 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4881 /* stack_frame_destroyed_p() returns a non-zero value if we're
4882 still in the function but the stack frame has already been
4883 invalidated. Since we can't rely on the values of local
4884 variables after the stack has been destroyed, we are treating
4885 the watchpoint in that state as `not changed' without further
4886 checking. Don't mark watchpoints as changed if the current
4887 frame is in an epilogue - even if they are in some other
4888 frame, our view of the stack is likely to be wrong and
4889 frame_find_by_id could error out. */
4890 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4893 fr
= frame_find_by_id (b
->watchpoint_frame
);
4894 within_current_scope
= (fr
!= NULL
);
4896 /* If we've gotten confused in the unwinder, we might have
4897 returned a frame that can't describe this variable. */
4898 if (within_current_scope
)
4900 struct symbol
*function
;
4902 function
= get_frame_function (fr
);
4903 if (function
== NULL
4904 || !contained_in (b
->exp_valid_block
,
4905 SYMBOL_BLOCK_VALUE (function
)))
4906 within_current_scope
= 0;
4909 if (within_current_scope
)
4910 /* If we end up stopping, the current frame will get selected
4911 in normal_stop. So this call to select_frame won't affect
4916 if (within_current_scope
)
4918 /* We use value_{,free_to_}mark because it could be a *long*
4919 time before we return to the command level and call
4920 free_all_values. We can't call free_all_values because we
4921 might be in the middle of evaluating a function call. */
4925 struct value
*new_val
;
4927 if (is_masked_watchpoint (b
))
4928 /* Since we don't know the exact trigger address (from
4929 stopped_data_address), just tell the user we've triggered
4930 a mask watchpoint. */
4931 return WP_VALUE_CHANGED
;
4933 mark
= value_mark ();
4934 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
4936 if (b
->val_bitsize
!= 0)
4937 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4939 /* We use value_equal_contents instead of value_equal because
4940 the latter coerces an array to a pointer, thus comparing just
4941 the address of the array instead of its contents. This is
4942 not what we want. */
4943 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4944 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
4947 bs
->old_val
= b
->val
;
4948 b
->val
= release_value (new_val
);
4949 b
->val_valid
= true;
4950 if (new_val
!= NULL
)
4951 value_free_to_mark (mark
);
4952 return WP_VALUE_CHANGED
;
4956 /* Nothing changed. */
4957 value_free_to_mark (mark
);
4958 return WP_VALUE_NOT_CHANGED
;
4963 /* This seems like the only logical thing to do because
4964 if we temporarily ignored the watchpoint, then when
4965 we reenter the block in which it is valid it contains
4966 garbage (in the case of a function, it may have two
4967 garbage values, one before and one after the prologue).
4968 So we can't even detect the first assignment to it and
4969 watch after that (since the garbage may or may not equal
4970 the first value assigned). */
4971 /* We print all the stop information in
4972 breakpoint_ops->print_it, but in this case, by the time we
4973 call breakpoint_ops->print_it this bp will be deleted
4974 already. So we have no choice but print the information
4977 SWITCH_THRU_ALL_UIS ()
4979 struct ui_out
*uiout
= current_uiout
;
4981 if (uiout
->is_mi_like_p ())
4983 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4984 uiout
->message ("\nWatchpoint %pF deleted because the program has "
4985 "left the block in\n"
4986 "which its expression is valid.\n",
4987 signed_field ("wpnum", b
->number
));
4990 /* Make sure the watchpoint's commands aren't executed. */
4992 watchpoint_del_at_next_stop (b
);
4998 /* Return true if it looks like target has stopped due to hitting
4999 breakpoint location BL. This function does not check if we should
5000 stop, only if BL explains the stop. */
5003 bpstat_check_location (const struct bp_location
*bl
,
5004 const address_space
*aspace
, CORE_ADDR bp_addr
,
5005 const struct target_waitstatus
*ws
)
5007 struct breakpoint
*b
= bl
->owner
;
5009 /* BL is from an existing breakpoint. */
5010 gdb_assert (b
!= NULL
);
5012 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5015 /* Determine if the watched values have actually changed, and we
5016 should stop. If not, set BS->stop to 0. */
5019 bpstat_check_watchpoint (bpstat bs
)
5021 const struct bp_location
*bl
;
5022 struct watchpoint
*b
;
5024 /* BS is built for existing struct breakpoint. */
5025 bl
= bs
->bp_location_at
;
5026 gdb_assert (bl
!= NULL
);
5027 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5028 gdb_assert (b
!= NULL
);
5031 int must_check_value
= 0;
5033 if (b
->type
== bp_watchpoint
)
5034 /* For a software watchpoint, we must always check the
5036 must_check_value
= 1;
5037 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5038 /* We have a hardware watchpoint (read, write, or access)
5039 and the target earlier reported an address watched by
5041 must_check_value
= 1;
5042 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5043 && b
->type
== bp_hardware_watchpoint
)
5044 /* We were stopped by a hardware watchpoint, but the target could
5045 not report the data address. We must check the watchpoint's
5046 value. Access and read watchpoints are out of luck; without
5047 a data address, we can't figure it out. */
5048 must_check_value
= 1;
5050 if (must_check_value
)
5056 e
= watchpoint_check (bs
);
5058 catch (const gdb_exception
&ex
)
5060 exception_fprintf (gdb_stderr
, ex
,
5061 "Error evaluating expression "
5062 "for watchpoint %d\n",
5065 SWITCH_THRU_ALL_UIS ()
5067 printf_filtered (_("Watchpoint %d deleted.\n"),
5070 watchpoint_del_at_next_stop (b
);
5077 /* We've already printed what needs to be printed. */
5078 bs
->print_it
= print_it_done
;
5082 bs
->print_it
= print_it_noop
;
5085 case WP_VALUE_CHANGED
:
5086 if (b
->type
== bp_read_watchpoint
)
5088 /* There are two cases to consider here:
5090 1. We're watching the triggered memory for reads.
5091 In that case, trust the target, and always report
5092 the watchpoint hit to the user. Even though
5093 reads don't cause value changes, the value may
5094 have changed since the last time it was read, and
5095 since we're not trapping writes, we will not see
5096 those, and as such we should ignore our notion of
5099 2. We're watching the triggered memory for both
5100 reads and writes. There are two ways this may
5103 2.1. This is a target that can't break on data
5104 reads only, but can break on accesses (reads or
5105 writes), such as e.g., x86. We detect this case
5106 at the time we try to insert read watchpoints.
5108 2.2. Otherwise, the target supports read
5109 watchpoints, but, the user set an access or write
5110 watchpoint watching the same memory as this read
5113 If we're watching memory writes as well as reads,
5114 ignore watchpoint hits when we find that the
5115 value hasn't changed, as reads don't cause
5116 changes. This still gives false positives when
5117 the program writes the same value to memory as
5118 what there was already in memory (we will confuse
5119 it for a read), but it's much better than
5122 int other_write_watchpoint
= 0;
5124 if (bl
->watchpoint_type
== hw_read
)
5126 struct breakpoint
*other_b
;
5128 ALL_BREAKPOINTS (other_b
)
5129 if (other_b
->type
== bp_hardware_watchpoint
5130 || other_b
->type
== bp_access_watchpoint
)
5132 struct watchpoint
*other_w
=
5133 (struct watchpoint
*) other_b
;
5135 if (other_w
->watchpoint_triggered
5136 == watch_triggered_yes
)
5138 other_write_watchpoint
= 1;
5144 if (other_write_watchpoint
5145 || bl
->watchpoint_type
== hw_access
)
5147 /* We're watching the same memory for writes,
5148 and the value changed since the last time we
5149 updated it, so this trap must be for a write.
5151 bs
->print_it
= print_it_noop
;
5156 case WP_VALUE_NOT_CHANGED
:
5157 if (b
->type
== bp_hardware_watchpoint
5158 || b
->type
== bp_watchpoint
)
5160 /* Don't stop: write watchpoints shouldn't fire if
5161 the value hasn't changed. */
5162 bs
->print_it
= print_it_noop
;
5172 else /* must_check_value == 0 */
5174 /* This is a case where some watchpoint(s) triggered, but
5175 not at the address of this watchpoint, or else no
5176 watchpoint triggered after all. So don't print
5177 anything for this watchpoint. */
5178 bs
->print_it
= print_it_noop
;
5184 /* For breakpoints that are currently marked as telling gdb to stop,
5185 check conditions (condition proper, frame, thread and ignore count)
5186 of breakpoint referred to by BS. If we should not stop for this
5187 breakpoint, set BS->stop to 0. */
5190 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5192 const struct bp_location
*bl
;
5193 struct breakpoint
*b
;
5195 bool condition_result
= true;
5196 struct expression
*cond
;
5198 gdb_assert (bs
->stop
);
5200 /* BS is built for existing struct breakpoint. */
5201 bl
= bs
->bp_location_at
;
5202 gdb_assert (bl
!= NULL
);
5203 b
= bs
->breakpoint_at
;
5204 gdb_assert (b
!= NULL
);
5206 /* Even if the target evaluated the condition on its end and notified GDB, we
5207 need to do so again since GDB does not know if we stopped due to a
5208 breakpoint or a single step breakpoint. */
5210 if (frame_id_p (b
->frame_id
)
5211 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5217 /* If this is a thread/task-specific breakpoint, don't waste cpu
5218 evaluating the condition if this isn't the specified
5220 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5221 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5227 /* Evaluate extension language breakpoints that have a "stop" method
5229 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5231 if (is_watchpoint (b
))
5233 struct watchpoint
*w
= (struct watchpoint
*) b
;
5235 cond
= w
->cond_exp
.get ();
5238 cond
= bl
->cond
.get ();
5240 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5242 int within_current_scope
= 1;
5243 struct watchpoint
* w
;
5245 /* We use value_mark and value_free_to_mark because it could
5246 be a long time before we return to the command level and
5247 call free_all_values. We can't call free_all_values
5248 because we might be in the middle of evaluating a
5250 struct value
*mark
= value_mark ();
5252 if (is_watchpoint (b
))
5253 w
= (struct watchpoint
*) b
;
5257 /* Need to select the frame, with all that implies so that
5258 the conditions will have the right context. Because we
5259 use the frame, we will not see an inlined function's
5260 variables when we arrive at a breakpoint at the start
5261 of the inlined function; the current frame will be the
5263 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5264 select_frame (get_current_frame ());
5267 struct frame_info
*frame
;
5269 /* For local watchpoint expressions, which particular
5270 instance of a local is being watched matters, so we
5271 keep track of the frame to evaluate the expression
5272 in. To evaluate the condition however, it doesn't
5273 really matter which instantiation of the function
5274 where the condition makes sense triggers the
5275 watchpoint. This allows an expression like "watch
5276 global if q > 10" set in `func', catch writes to
5277 global on all threads that call `func', or catch
5278 writes on all recursive calls of `func' by a single
5279 thread. We simply always evaluate the condition in
5280 the innermost frame that's executing where it makes
5281 sense to evaluate the condition. It seems
5283 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5285 select_frame (frame
);
5287 within_current_scope
= 0;
5289 if (within_current_scope
)
5293 condition_result
= breakpoint_cond_eval (cond
);
5295 catch (const gdb_exception
&ex
)
5297 exception_fprintf (gdb_stderr
, ex
,
5298 "Error in testing breakpoint condition:\n");
5303 warning (_("Watchpoint condition cannot be tested "
5304 "in the current scope"));
5305 /* If we failed to set the right context for this
5306 watchpoint, unconditionally report it. */
5308 /* FIXME-someday, should give breakpoint #. */
5309 value_free_to_mark (mark
);
5312 if (cond
&& !condition_result
)
5316 else if (b
->ignore_count
> 0)
5320 /* Increase the hit count even though we don't stop. */
5322 gdb::observers::breakpoint_modified
.notify (b
);
5326 /* Returns true if we need to track moribund locations of LOC's type
5327 on the current target. */
5330 need_moribund_for_location_type (struct bp_location
*loc
)
5332 return ((loc
->loc_type
== bp_loc_software_breakpoint
5333 && !target_supports_stopped_by_sw_breakpoint ())
5334 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5335 && !target_supports_stopped_by_hw_breakpoint ()));
5338 /* See breakpoint.h. */
5341 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5342 const struct target_waitstatus
*ws
)
5344 struct breakpoint
*b
;
5345 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5349 if (!breakpoint_enabled (b
))
5352 for (bp_location
*bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5354 /* For hardware watchpoints, we look only at the first
5355 location. The watchpoint_check function will work on the
5356 entire expression, not the individual locations. For
5357 read watchpoints, the watchpoints_triggered function has
5358 checked all locations already. */
5359 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5362 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5365 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5368 /* Come here if it's a watchpoint, or if the break address
5371 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5374 /* Assume we stop. Should we find a watchpoint that is not
5375 actually triggered, or if the condition of the breakpoint
5376 evaluates as false, we'll reset 'stop' to 0. */
5380 /* If this is a scope breakpoint, mark the associated
5381 watchpoint as triggered so that we will handle the
5382 out-of-scope event. We'll get to the watchpoint next
5384 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5386 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5388 w
->watchpoint_triggered
= watch_triggered_yes
;
5393 /* Check if a moribund breakpoint explains the stop. */
5394 if (!target_supports_stopped_by_sw_breakpoint ()
5395 || !target_supports_stopped_by_hw_breakpoint ())
5397 for (bp_location
*loc
: moribund_locations
)
5399 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5400 && need_moribund_for_location_type (loc
))
5402 bpstat bs
= new bpstats (loc
, &bs_link
);
5403 /* For hits of moribund locations, we should just proceed. */
5406 bs
->print_it
= print_it_noop
;
5414 /* See breakpoint.h. */
5417 bpstat_stop_status (const address_space
*aspace
,
5418 CORE_ADDR bp_addr
, thread_info
*thread
,
5419 const struct target_waitstatus
*ws
,
5422 struct breakpoint
*b
= NULL
;
5423 /* First item of allocated bpstat's. */
5424 bpstat bs_head
= stop_chain
;
5426 int need_remove_insert
;
5429 /* First, build the bpstat chain with locations that explain a
5430 target stop, while being careful to not set the target running,
5431 as that may invalidate locations (in particular watchpoint
5432 locations are recreated). Resuming will happen here with
5433 breakpoint conditions or watchpoint expressions that include
5434 inferior function calls. */
5435 if (bs_head
== NULL
)
5436 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5438 /* A bit of special processing for shlib breakpoints. We need to
5439 process solib loading here, so that the lists of loaded and
5440 unloaded libraries are correct before we handle "catch load" and
5442 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5444 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5446 handle_solib_event ();
5451 /* Now go through the locations that caused the target to stop, and
5452 check whether we're interested in reporting this stop to higher
5453 layers, or whether we should resume the target transparently. */
5457 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5462 b
= bs
->breakpoint_at
;
5463 b
->ops
->check_status (bs
);
5466 bpstat_check_breakpoint_conditions (bs
, thread
);
5471 gdb::observers::breakpoint_modified
.notify (b
);
5473 /* We will stop here. */
5474 if (b
->disposition
== disp_disable
)
5476 --(b
->enable_count
);
5477 if (b
->enable_count
<= 0)
5478 b
->enable_state
= bp_disabled
;
5483 bs
->commands
= b
->commands
;
5484 if (command_line_is_silent (bs
->commands
5485 ? bs
->commands
.get () : NULL
))
5488 b
->ops
->after_condition_true (bs
);
5493 /* Print nothing for this entry if we don't stop or don't
5495 if (!bs
->stop
|| !bs
->print
)
5496 bs
->print_it
= print_it_noop
;
5499 /* If we aren't stopping, the value of some hardware watchpoint may
5500 not have changed, but the intermediate memory locations we are
5501 watching may have. Don't bother if we're stopping; this will get
5503 need_remove_insert
= 0;
5504 if (! bpstat_causes_stop (bs_head
))
5505 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5507 && bs
->breakpoint_at
5508 && is_hardware_watchpoint (bs
->breakpoint_at
))
5510 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5512 update_watchpoint (w
, 0 /* don't reparse. */);
5513 need_remove_insert
= 1;
5516 if (need_remove_insert
)
5517 update_global_location_list (UGLL_MAY_INSERT
);
5518 else if (removed_any
)
5519 update_global_location_list (UGLL_DONT_INSERT
);
5525 handle_jit_event (CORE_ADDR address
)
5527 struct gdbarch
*gdbarch
;
5529 infrun_debug_printf ("handling bp_jit_event");
5531 /* Switch terminal for any messages produced by
5532 breakpoint_re_set. */
5533 target_terminal::ours_for_output ();
5535 gdbarch
= get_frame_arch (get_current_frame ());
5536 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5537 thus it is expected that its objectfile can be found through
5538 minimal symbol lookup. If it doesn't work (and assert fails), it
5539 most likely means that `jit_breakpoint_re_set` was changes and this
5540 function needs to be updated too. */
5541 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5542 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5543 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5545 target_terminal::inferior ();
5548 /* Prepare WHAT final decision for infrun. */
5550 /* Decide what infrun needs to do with this bpstat. */
5553 bpstat_what (bpstat bs_head
)
5555 struct bpstat_what retval
;
5558 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5559 retval
.call_dummy
= STOP_NONE
;
5560 retval
.is_longjmp
= false;
5562 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5564 /* Extract this BS's action. After processing each BS, we check
5565 if its action overrides all we've seem so far. */
5566 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5569 if (bs
->breakpoint_at
== NULL
)
5571 /* I suspect this can happen if it was a momentary
5572 breakpoint which has since been deleted. */
5576 bptype
= bs
->breakpoint_at
->type
;
5583 case bp_hardware_breakpoint
:
5584 case bp_single_step
:
5587 case bp_shlib_event
:
5591 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5593 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5596 this_action
= BPSTAT_WHAT_SINGLE
;
5599 case bp_hardware_watchpoint
:
5600 case bp_read_watchpoint
:
5601 case bp_access_watchpoint
:
5605 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5607 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5611 /* There was a watchpoint, but we're not stopping.
5612 This requires no further action. */
5616 case bp_longjmp_call_dummy
:
5620 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5621 retval
.is_longjmp
= bptype
!= bp_exception
;
5624 this_action
= BPSTAT_WHAT_SINGLE
;
5626 case bp_longjmp_resume
:
5627 case bp_exception_resume
:
5630 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5631 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5634 this_action
= BPSTAT_WHAT_SINGLE
;
5636 case bp_step_resume
:
5638 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5641 /* It is for the wrong frame. */
5642 this_action
= BPSTAT_WHAT_SINGLE
;
5645 case bp_hp_step_resume
:
5647 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5650 /* It is for the wrong frame. */
5651 this_action
= BPSTAT_WHAT_SINGLE
;
5654 case bp_watchpoint_scope
:
5655 case bp_thread_event
:
5656 case bp_overlay_event
:
5657 case bp_longjmp_master
:
5658 case bp_std_terminate_master
:
5659 case bp_exception_master
:
5660 this_action
= BPSTAT_WHAT_SINGLE
;
5666 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5668 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5672 /* Some catchpoints are implemented with breakpoints.
5673 For those, we need to step over the breakpoint. */
5674 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5675 this_action
= BPSTAT_WHAT_SINGLE
;
5679 this_action
= BPSTAT_WHAT_SINGLE
;
5682 /* Make sure the action is stop (silent or noisy),
5683 so infrun.c pops the dummy frame. */
5684 retval
.call_dummy
= STOP_STACK_DUMMY
;
5685 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5687 case bp_std_terminate
:
5688 /* Make sure the action is stop (silent or noisy),
5689 so infrun.c pops the dummy frame. */
5690 retval
.call_dummy
= STOP_STD_TERMINATE
;
5691 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5694 case bp_fast_tracepoint
:
5695 case bp_static_tracepoint
:
5696 /* Tracepoint hits should not be reported back to GDB, and
5697 if one got through somehow, it should have been filtered
5699 internal_error (__FILE__
, __LINE__
,
5700 _("bpstat_what: tracepoint encountered"));
5702 case bp_gnu_ifunc_resolver
:
5703 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5704 this_action
= BPSTAT_WHAT_SINGLE
;
5706 case bp_gnu_ifunc_resolver_return
:
5707 /* The breakpoint will be removed, execution will restart from the
5708 PC of the former breakpoint. */
5709 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5714 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5716 this_action
= BPSTAT_WHAT_SINGLE
;
5720 internal_error (__FILE__
, __LINE__
,
5721 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5724 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5731 bpstat_run_callbacks (bpstat bs_head
)
5735 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5737 struct breakpoint
*b
= bs
->breakpoint_at
;
5744 handle_jit_event (bs
->bp_location_at
->address
);
5746 case bp_gnu_ifunc_resolver
:
5747 gnu_ifunc_resolver_stop (b
);
5749 case bp_gnu_ifunc_resolver_return
:
5750 gnu_ifunc_resolver_return_stop (b
);
5756 /* See breakpoint.h. */
5759 bpstat_should_step ()
5761 struct breakpoint
*b
;
5764 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5769 /* See breakpoint.h. */
5772 bpstat_causes_stop (bpstat bs
)
5774 for (; bs
!= NULL
; bs
= bs
->next
)
5783 /* Compute a string of spaces suitable to indent the next line
5784 so it starts at the position corresponding to the table column
5785 named COL_NAME in the currently active table of UIOUT. */
5788 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5790 static char wrap_indent
[80];
5791 int i
, total_width
, width
, align
;
5795 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5797 if (strcmp (text
, col_name
) == 0)
5799 gdb_assert (total_width
< sizeof wrap_indent
);
5800 memset (wrap_indent
, ' ', total_width
);
5801 wrap_indent
[total_width
] = 0;
5806 total_width
+= width
+ 1;
5812 /* Determine if the locations of this breakpoint will have their conditions
5813 evaluated by the target, host or a mix of both. Returns the following:
5815 "host": Host evals condition.
5816 "host or target": Host or Target evals condition.
5817 "target": Target evals condition.
5821 bp_condition_evaluator (struct breakpoint
*b
)
5823 struct bp_location
*bl
;
5824 char host_evals
= 0;
5825 char target_evals
= 0;
5830 if (!is_breakpoint (b
))
5833 if (gdb_evaluates_breakpoint_condition_p ()
5834 || !target_supports_evaluation_of_breakpoint_conditions ())
5835 return condition_evaluation_host
;
5837 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5839 if (bl
->cond_bytecode
)
5845 if (host_evals
&& target_evals
)
5846 return condition_evaluation_both
;
5847 else if (target_evals
)
5848 return condition_evaluation_target
;
5850 return condition_evaluation_host
;
5853 /* Determine the breakpoint location's condition evaluator. This is
5854 similar to bp_condition_evaluator, but for locations. */
5857 bp_location_condition_evaluator (struct bp_location
*bl
)
5859 if (bl
&& !is_breakpoint (bl
->owner
))
5862 if (gdb_evaluates_breakpoint_condition_p ()
5863 || !target_supports_evaluation_of_breakpoint_conditions ())
5864 return condition_evaluation_host
;
5866 if (bl
&& bl
->cond_bytecode
)
5867 return condition_evaluation_target
;
5869 return condition_evaluation_host
;
5872 /* Print the LOC location out of the list of B->LOC locations. */
5875 print_breakpoint_location (struct breakpoint
*b
,
5876 struct bp_location
*loc
)
5878 struct ui_out
*uiout
= current_uiout
;
5880 scoped_restore_current_program_space restore_pspace
;
5882 if (loc
!= NULL
&& loc
->shlib_disabled
)
5886 set_current_program_space (loc
->pspace
);
5888 if (b
->display_canonical
)
5889 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5890 else if (loc
&& loc
->symtab
)
5892 const struct symbol
*sym
= loc
->symbol
;
5896 uiout
->text ("in ");
5897 uiout
->field_string ("func", sym
->print_name (),
5898 function_name_style
.style ());
5900 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5901 uiout
->text ("at ");
5903 uiout
->field_string ("file",
5904 symtab_to_filename_for_display (loc
->symtab
),
5905 file_name_style
.style ());
5908 if (uiout
->is_mi_like_p ())
5909 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5911 uiout
->field_signed ("line", loc
->line_number
);
5917 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5919 uiout
->field_stream ("at", stb
);
5923 uiout
->field_string ("pending",
5924 event_location_to_string (b
->location
.get ()));
5925 /* If extra_string is available, it could be holding a condition
5926 or dprintf arguments. In either case, make sure it is printed,
5927 too, but only for non-MI streams. */
5928 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5930 if (b
->type
== bp_dprintf
)
5934 uiout
->text (b
->extra_string
);
5938 if (loc
&& is_breakpoint (b
)
5939 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5940 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5943 uiout
->field_string ("evaluated-by",
5944 bp_location_condition_evaluator (loc
));
5950 bptype_string (enum bptype type
)
5952 struct ep_type_description
5955 const char *description
;
5957 static struct ep_type_description bptypes
[] =
5959 {bp_none
, "?deleted?"},
5960 {bp_breakpoint
, "breakpoint"},
5961 {bp_hardware_breakpoint
, "hw breakpoint"},
5962 {bp_single_step
, "sw single-step"},
5963 {bp_until
, "until"},
5964 {bp_finish
, "finish"},
5965 {bp_watchpoint
, "watchpoint"},
5966 {bp_hardware_watchpoint
, "hw watchpoint"},
5967 {bp_read_watchpoint
, "read watchpoint"},
5968 {bp_access_watchpoint
, "acc watchpoint"},
5969 {bp_longjmp
, "longjmp"},
5970 {bp_longjmp_resume
, "longjmp resume"},
5971 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5972 {bp_exception
, "exception"},
5973 {bp_exception_resume
, "exception resume"},
5974 {bp_step_resume
, "step resume"},
5975 {bp_hp_step_resume
, "high-priority step resume"},
5976 {bp_watchpoint_scope
, "watchpoint scope"},
5977 {bp_call_dummy
, "call dummy"},
5978 {bp_std_terminate
, "std::terminate"},
5979 {bp_shlib_event
, "shlib events"},
5980 {bp_thread_event
, "thread events"},
5981 {bp_overlay_event
, "overlay events"},
5982 {bp_longjmp_master
, "longjmp master"},
5983 {bp_std_terminate_master
, "std::terminate master"},
5984 {bp_exception_master
, "exception master"},
5985 {bp_catchpoint
, "catchpoint"},
5986 {bp_tracepoint
, "tracepoint"},
5987 {bp_fast_tracepoint
, "fast tracepoint"},
5988 {bp_static_tracepoint
, "static tracepoint"},
5989 {bp_dprintf
, "dprintf"},
5990 {bp_jit_event
, "jit events"},
5991 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5992 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5995 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5996 || ((int) type
!= bptypes
[(int) type
].type
))
5997 internal_error (__FILE__
, __LINE__
,
5998 _("bptypes table does not describe type #%d."),
6001 return bptypes
[(int) type
].description
;
6004 /* For MI, output a field named 'thread-groups' with a list as the value.
6005 For CLI, prefix the list with the string 'inf'. */
6008 output_thread_groups (struct ui_out
*uiout
,
6009 const char *field_name
,
6010 const std::vector
<int> &inf_nums
,
6013 int is_mi
= uiout
->is_mi_like_p ();
6015 /* For backward compatibility, don't display inferiors in CLI unless
6016 there are several. Always display them for MI. */
6017 if (!is_mi
&& mi_only
)
6020 ui_out_emit_list
list_emitter (uiout
, field_name
);
6022 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6028 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6029 uiout
->field_string (NULL
, mi_group
);
6034 uiout
->text (" inf ");
6038 uiout
->text (plongest (inf_nums
[i
]));
6043 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6044 instead of going via breakpoint_ops::print_one. This makes "maint
6045 info breakpoints" show the software breakpoint locations of
6046 catchpoints, which are considered internal implementation
6050 print_one_breakpoint_location (struct breakpoint
*b
,
6051 struct bp_location
*loc
,
6053 struct bp_location
**last_loc
,
6054 int allflag
, bool raw_loc
)
6056 struct command_line
*l
;
6057 static char bpenables
[] = "nynny";
6059 struct ui_out
*uiout
= current_uiout
;
6060 int header_of_multiple
= 0;
6061 int part_of_multiple
= (loc
!= NULL
);
6062 struct value_print_options opts
;
6064 get_user_print_options (&opts
);
6066 gdb_assert (!loc
|| loc_number
!= 0);
6067 /* See comment in print_one_breakpoint concerning treatment of
6068 breakpoints with single disabled location. */
6071 && (b
->loc
->next
!= NULL
6072 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6073 header_of_multiple
= 1;
6081 if (part_of_multiple
)
6082 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6084 uiout
->field_signed ("number", b
->number
);
6088 if (part_of_multiple
)
6089 uiout
->field_skip ("type");
6091 uiout
->field_string ("type", bptype_string (b
->type
));
6095 if (part_of_multiple
)
6096 uiout
->field_skip ("disp");
6098 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6102 if (part_of_multiple
)
6103 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? "N*"
6104 : (loc
->enabled
? "y" : "n")));
6106 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6109 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6110 b
->ops
->print_one (b
, last_loc
);
6113 if (is_watchpoint (b
))
6115 struct watchpoint
*w
= (struct watchpoint
*) b
;
6117 /* Field 4, the address, is omitted (which makes the columns
6118 not line up too nicely with the headers, but the effect
6119 is relatively readable). */
6120 if (opts
.addressprint
)
6121 uiout
->field_skip ("addr");
6123 uiout
->field_string ("what", w
->exp_string
);
6125 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6126 || is_ada_exception_catchpoint (b
))
6128 if (opts
.addressprint
)
6131 if (header_of_multiple
)
6132 uiout
->field_string ("addr", "<MULTIPLE>",
6133 metadata_style
.style ());
6134 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6135 uiout
->field_string ("addr", "<PENDING>",
6136 metadata_style
.style ());
6138 uiout
->field_core_addr ("addr",
6139 loc
->gdbarch
, loc
->address
);
6142 if (!header_of_multiple
)
6143 print_breakpoint_location (b
, loc
);
6149 if (loc
!= NULL
&& !header_of_multiple
)
6151 std::vector
<int> inf_nums
;
6154 for (inferior
*inf
: all_inferiors ())
6156 if (inf
->pspace
== loc
->pspace
)
6157 inf_nums
.push_back (inf
->num
);
6160 /* For backward compatibility, don't display inferiors in CLI unless
6161 there are several. Always display for MI. */
6163 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6164 && (program_spaces
.size () > 1
6165 || number_of_inferiors () > 1)
6166 /* LOC is for existing B, it cannot be in
6167 moribund_locations and thus having NULL OWNER. */
6168 && loc
->owner
->type
!= bp_catchpoint
))
6170 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6173 if (!part_of_multiple
)
6175 if (b
->thread
!= -1)
6177 /* FIXME: This seems to be redundant and lost here; see the
6178 "stop only in" line a little further down. */
6179 uiout
->text (" thread ");
6180 uiout
->field_signed ("thread", b
->thread
);
6182 else if (b
->task
!= 0)
6184 uiout
->text (" task ");
6185 uiout
->field_signed ("task", b
->task
);
6191 if (!part_of_multiple
)
6192 b
->ops
->print_one_detail (b
, uiout
);
6194 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6197 uiout
->text ("\tstop only in stack frame at ");
6198 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6200 uiout
->field_core_addr ("frame",
6201 b
->gdbarch
, b
->frame_id
.stack_addr
);
6205 if (!part_of_multiple
&& b
->cond_string
)
6208 if (is_tracepoint (b
))
6209 uiout
->text ("\ttrace only if ");
6211 uiout
->text ("\tstop only if ");
6212 uiout
->field_string ("cond", b
->cond_string
);
6214 /* Print whether the target is doing the breakpoint's condition
6215 evaluation. If GDB is doing the evaluation, don't print anything. */
6216 if (is_breakpoint (b
)
6217 && breakpoint_condition_evaluation_mode ()
6218 == condition_evaluation_target
)
6220 uiout
->message (" (%pF evals)",
6221 string_field ("evaluated-by",
6222 bp_condition_evaluator (b
)));
6227 if (!part_of_multiple
&& b
->thread
!= -1)
6229 /* FIXME should make an annotation for this. */
6230 uiout
->text ("\tstop only in thread ");
6231 if (uiout
->is_mi_like_p ())
6232 uiout
->field_signed ("thread", b
->thread
);
6235 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6237 uiout
->field_string ("thread", print_thread_id (thr
));
6242 if (!part_of_multiple
)
6246 /* FIXME should make an annotation for this. */
6247 if (is_catchpoint (b
))
6248 uiout
->text ("\tcatchpoint");
6249 else if (is_tracepoint (b
))
6250 uiout
->text ("\ttracepoint");
6252 uiout
->text ("\tbreakpoint");
6253 uiout
->text (" already hit ");
6254 uiout
->field_signed ("times", b
->hit_count
);
6255 if (b
->hit_count
== 1)
6256 uiout
->text (" time\n");
6258 uiout
->text (" times\n");
6262 /* Output the count also if it is zero, but only if this is mi. */
6263 if (uiout
->is_mi_like_p ())
6264 uiout
->field_signed ("times", b
->hit_count
);
6268 if (!part_of_multiple
&& b
->ignore_count
)
6271 uiout
->message ("\tignore next %pF hits\n",
6272 signed_field ("ignore", b
->ignore_count
));
6275 /* Note that an enable count of 1 corresponds to "enable once"
6276 behavior, which is reported by the combination of enablement and
6277 disposition, so we don't need to mention it here. */
6278 if (!part_of_multiple
&& b
->enable_count
> 1)
6281 uiout
->text ("\tdisable after ");
6282 /* Tweak the wording to clarify that ignore and enable counts
6283 are distinct, and have additive effect. */
6284 if (b
->ignore_count
)
6285 uiout
->text ("additional ");
6287 uiout
->text ("next ");
6288 uiout
->field_signed ("enable", b
->enable_count
);
6289 uiout
->text (" hits\n");
6292 if (!part_of_multiple
&& is_tracepoint (b
))
6294 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6296 if (tp
->traceframe_usage
)
6298 uiout
->text ("\ttrace buffer usage ");
6299 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6300 uiout
->text (" bytes\n");
6304 l
= b
->commands
? b
->commands
.get () : NULL
;
6305 if (!part_of_multiple
&& l
)
6308 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6309 print_command_lines (uiout
, l
, 4);
6312 if (is_tracepoint (b
))
6314 struct tracepoint
*t
= (struct tracepoint
*) b
;
6316 if (!part_of_multiple
&& t
->pass_count
)
6318 annotate_field (10);
6319 uiout
->text ("\tpass count ");
6320 uiout
->field_signed ("pass", t
->pass_count
);
6321 uiout
->text (" \n");
6324 /* Don't display it when tracepoint or tracepoint location is
6326 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6328 annotate_field (11);
6330 if (uiout
->is_mi_like_p ())
6331 uiout
->field_string ("installed",
6332 loc
->inserted
? "y" : "n");
6338 uiout
->text ("\tnot ");
6339 uiout
->text ("installed on target\n");
6344 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6346 if (is_watchpoint (b
))
6348 struct watchpoint
*w
= (struct watchpoint
*) b
;
6350 uiout
->field_string ("original-location", w
->exp_string
);
6352 else if (b
->location
!= NULL
6353 && event_location_to_string (b
->location
.get ()) != NULL
)
6354 uiout
->field_string ("original-location",
6355 event_location_to_string (b
->location
.get ()));
6359 /* See breakpoint.h. */
6361 bool fix_multi_location_breakpoint_output_globally
= false;
6364 print_one_breakpoint (struct breakpoint
*b
,
6365 struct bp_location
**last_loc
,
6368 struct ui_out
*uiout
= current_uiout
;
6369 bool use_fixed_output
6370 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6371 || fix_multi_location_breakpoint_output_globally
);
6373 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6374 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6376 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6378 if (!use_fixed_output
)
6379 bkpt_tuple_emitter
.reset ();
6381 /* If this breakpoint has custom print function,
6382 it's already printed. Otherwise, print individual
6383 locations, if any. */
6385 || b
->ops
->print_one
== NULL
6388 /* If breakpoint has a single location that is disabled, we
6389 print it as if it had several locations, since otherwise it's
6390 hard to represent "breakpoint enabled, location disabled"
6393 Note that while hardware watchpoints have several locations
6394 internally, that's not a property exposed to users.
6396 Likewise, while catchpoints may be implemented with
6397 breakpoints (e.g., catch throw), that's not a property
6398 exposed to users. We do however display the internal
6399 breakpoint locations with "maint info breakpoints". */
6400 if (!is_hardware_watchpoint (b
)
6401 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6402 || is_ada_exception_catchpoint (b
))
6404 || (b
->loc
&& (b
->loc
->next
6406 || b
->loc
->disabled_by_cond
))))
6408 gdb::optional
<ui_out_emit_list
> locations_list
;
6410 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6411 MI record. For later versions, place breakpoint locations in a
6413 if (uiout
->is_mi_like_p () && use_fixed_output
)
6414 locations_list
.emplace (uiout
, "locations");
6417 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
, ++n
)
6419 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6420 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6428 breakpoint_address_bits (struct breakpoint
*b
)
6430 int print_address_bits
= 0;
6431 struct bp_location
*loc
;
6433 /* Software watchpoints that aren't watching memory don't have an
6434 address to print. */
6435 if (is_no_memory_software_watchpoint (b
))
6438 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6442 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6443 if (addr_bit
> print_address_bits
)
6444 print_address_bits
= addr_bit
;
6447 return print_address_bits
;
6450 /* See breakpoint.h. */
6453 print_breakpoint (breakpoint
*b
)
6455 struct bp_location
*dummy_loc
= NULL
;
6456 print_one_breakpoint (b
, &dummy_loc
, 0);
6459 /* Return true if this breakpoint was set by the user, false if it is
6460 internal or momentary. */
6463 user_breakpoint_p (struct breakpoint
*b
)
6465 return b
->number
> 0;
6468 /* See breakpoint.h. */
6471 pending_breakpoint_p (struct breakpoint
*b
)
6473 return b
->loc
== NULL
;
6476 /* Print information on breakpoints (including watchpoints and tracepoints).
6478 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6479 understood by number_or_range_parser. Only breakpoints included in this
6480 list are then printed.
6482 If SHOW_INTERNAL is true, print internal breakpoints.
6484 If FILTER is non-NULL, call it on each breakpoint and only include the
6485 ones for which it returns true.
6487 Return the total number of breakpoints listed. */
6490 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6491 bool (*filter
) (const struct breakpoint
*))
6493 struct breakpoint
*b
;
6494 struct bp_location
*last_loc
= NULL
;
6495 int nr_printable_breakpoints
;
6496 struct value_print_options opts
;
6497 int print_address_bits
= 0;
6498 int print_type_col_width
= 14;
6499 struct ui_out
*uiout
= current_uiout
;
6500 bool has_disabled_by_cond_location
= false;
6502 get_user_print_options (&opts
);
6504 /* Compute the number of rows in the table, as well as the size
6505 required for address fields. */
6506 nr_printable_breakpoints
= 0;
6509 /* If we have a filter, only list the breakpoints it accepts. */
6510 if (filter
&& !filter (b
))
6513 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6514 accept. Skip the others. */
6515 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6517 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6519 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6523 if (show_internal
|| user_breakpoint_p (b
))
6525 int addr_bit
, type_len
;
6527 addr_bit
= breakpoint_address_bits (b
);
6528 if (addr_bit
> print_address_bits
)
6529 print_address_bits
= addr_bit
;
6531 type_len
= strlen (bptype_string (b
->type
));
6532 if (type_len
> print_type_col_width
)
6533 print_type_col_width
= type_len
;
6535 nr_printable_breakpoints
++;
6540 ui_out_emit_table
table_emitter (uiout
,
6541 opts
.addressprint
? 6 : 5,
6542 nr_printable_breakpoints
,
6545 if (nr_printable_breakpoints
> 0)
6546 annotate_breakpoints_headers ();
6547 if (nr_printable_breakpoints
> 0)
6549 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6550 if (nr_printable_breakpoints
> 0)
6552 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6553 if (nr_printable_breakpoints
> 0)
6555 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6556 if (nr_printable_breakpoints
> 0)
6558 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6559 if (opts
.addressprint
)
6561 if (nr_printable_breakpoints
> 0)
6563 if (print_address_bits
<= 32)
6564 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6566 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6568 if (nr_printable_breakpoints
> 0)
6570 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6571 uiout
->table_body ();
6572 if (nr_printable_breakpoints
> 0)
6573 annotate_breakpoints_table ();
6578 /* If we have a filter, only list the breakpoints it accepts. */
6579 if (filter
&& !filter (b
))
6582 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6583 accept. Skip the others. */
6585 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6587 if (show_internal
) /* maintenance info breakpoint */
6589 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6592 else /* all others */
6594 if (!number_is_in_list (bp_num_list
, b
->number
))
6598 /* We only print out user settable breakpoints unless the
6599 show_internal is set. */
6600 if (show_internal
|| user_breakpoint_p (b
))
6602 print_one_breakpoint (b
, &last_loc
, show_internal
);
6603 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
6604 if (loc
->disabled_by_cond
)
6605 has_disabled_by_cond_location
= true;
6610 if (nr_printable_breakpoints
== 0)
6612 /* If there's a filter, let the caller decide how to report
6616 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6617 uiout
->message ("No breakpoints or watchpoints.\n");
6619 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6625 if (last_loc
&& !server_command
)
6626 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6628 if (has_disabled_by_cond_location
)
6629 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6633 /* FIXME? Should this be moved up so that it is only called when
6634 there have been breakpoints? */
6635 annotate_breakpoints_table_end ();
6637 return nr_printable_breakpoints
;
6640 /* Display the value of default-collect in a way that is generally
6641 compatible with the breakpoint list. */
6644 default_collect_info (void)
6646 struct ui_out
*uiout
= current_uiout
;
6648 /* If it has no value (which is frequently the case), say nothing; a
6649 message like "No default-collect." gets in user's face when it's
6651 if (!*default_collect
)
6654 /* The following phrase lines up nicely with per-tracepoint collect
6656 uiout
->text ("default collect ");
6657 uiout
->field_string ("default-collect", default_collect
);
6658 uiout
->text (" \n");
6662 info_breakpoints_command (const char *args
, int from_tty
)
6664 breakpoint_1 (args
, false, NULL
);
6666 default_collect_info ();
6670 info_watchpoints_command (const char *args
, int from_tty
)
6672 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6673 struct ui_out
*uiout
= current_uiout
;
6675 if (num_printed
== 0)
6677 if (args
== NULL
|| *args
== '\0')
6678 uiout
->message ("No watchpoints.\n");
6680 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6685 maintenance_info_breakpoints (const char *args
, int from_tty
)
6687 breakpoint_1 (args
, true, NULL
);
6689 default_collect_info ();
6693 breakpoint_has_pc (struct breakpoint
*b
,
6694 struct program_space
*pspace
,
6695 CORE_ADDR pc
, struct obj_section
*section
)
6697 struct bp_location
*bl
= b
->loc
;
6699 for (; bl
; bl
= bl
->next
)
6701 if (bl
->pspace
== pspace
6702 && bl
->address
== pc
6703 && (!overlay_debugging
|| bl
->section
== section
))
6709 /* Print a message describing any user-breakpoints set at PC. This
6710 concerns with logical breakpoints, so we match program spaces, not
6714 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6715 struct program_space
*pspace
, CORE_ADDR pc
,
6716 struct obj_section
*section
, int thread
)
6719 struct breakpoint
*b
;
6722 others
+= (user_breakpoint_p (b
)
6723 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6727 printf_filtered (_("Note: breakpoint "));
6728 else /* if (others == ???) */
6729 printf_filtered (_("Note: breakpoints "));
6731 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6734 printf_filtered ("%d", b
->number
);
6735 if (b
->thread
== -1 && thread
!= -1)
6736 printf_filtered (" (all threads)");
6737 else if (b
->thread
!= -1)
6738 printf_filtered (" (thread %d)", b
->thread
);
6739 printf_filtered ("%s%s ",
6740 ((b
->enable_state
== bp_disabled
6741 || b
->enable_state
== bp_call_disabled
)
6745 : ((others
== 1) ? " and" : ""));
6747 current_uiout
->message (_("also set at pc %ps.\n"),
6748 styled_string (address_style
.style (),
6749 paddress (gdbarch
, pc
)));
6754 /* Return true iff it is meaningful to use the address member of LOC.
6755 For some breakpoint types, the locations' address members are
6756 irrelevant and it makes no sense to attempt to compare them to
6757 other addresses (or use them for any other purpose either).
6759 More specifically, software watchpoints and catchpoints that are
6760 not backed by breakpoints always have a zero valued location
6761 address and we don't want to mark breakpoints of any of these types
6762 to be a duplicate of an actual breakpoint location at address
6766 bl_address_is_meaningful (bp_location
*loc
)
6768 return loc
->loc_type
!= bp_loc_other
;
6771 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6772 true if LOC1 and LOC2 represent the same watchpoint location. */
6775 watchpoint_locations_match (struct bp_location
*loc1
,
6776 struct bp_location
*loc2
)
6778 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6779 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6781 /* Both of them must exist. */
6782 gdb_assert (w1
!= NULL
);
6783 gdb_assert (w2
!= NULL
);
6785 /* If the target can evaluate the condition expression in hardware,
6786 then we we need to insert both watchpoints even if they are at
6787 the same place. Otherwise the watchpoint will only trigger when
6788 the condition of whichever watchpoint was inserted evaluates to
6789 true, not giving a chance for GDB to check the condition of the
6790 other watchpoint. */
6792 && target_can_accel_watchpoint_condition (loc1
->address
,
6794 loc1
->watchpoint_type
,
6795 w1
->cond_exp
.get ()))
6797 && target_can_accel_watchpoint_condition (loc2
->address
,
6799 loc2
->watchpoint_type
,
6800 w2
->cond_exp
.get ())))
6803 /* Note that this checks the owner's type, not the location's. In
6804 case the target does not support read watchpoints, but does
6805 support access watchpoints, we'll have bp_read_watchpoint
6806 watchpoints with hw_access locations. Those should be considered
6807 duplicates of hw_read locations. The hw_read locations will
6808 become hw_access locations later. */
6809 return (loc1
->owner
->type
== loc2
->owner
->type
6810 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6811 && loc1
->address
== loc2
->address
6812 && loc1
->length
== loc2
->length
);
6815 /* See breakpoint.h. */
6818 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6819 const address_space
*aspace2
, CORE_ADDR addr2
)
6821 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6822 || aspace1
== aspace2
)
6826 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6827 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6828 matches ASPACE2. On targets that have global breakpoints, the address
6829 space doesn't really matter. */
6832 breakpoint_address_match_range (const address_space
*aspace1
,
6834 int len1
, const address_space
*aspace2
,
6837 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6838 || aspace1
== aspace2
)
6839 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6842 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6843 a ranged breakpoint. In most targets, a match happens only if ASPACE
6844 matches the breakpoint's address space. On targets that have global
6845 breakpoints, the address space doesn't really matter. */
6848 breakpoint_location_address_match (struct bp_location
*bl
,
6849 const address_space
*aspace
,
6852 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6855 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6856 bl
->address
, bl
->length
,
6860 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6861 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6862 match happens only if ASPACE matches the breakpoint's address
6863 space. On targets that have global breakpoints, the address space
6864 doesn't really matter. */
6867 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6868 const address_space
*aspace
,
6869 CORE_ADDR addr
, int len
)
6871 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6872 || bl
->pspace
->aspace
== aspace
)
6874 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6876 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6882 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6883 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6884 true, otherwise returns false. */
6887 tracepoint_locations_match (struct bp_location
*loc1
,
6888 struct bp_location
*loc2
)
6890 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6891 /* Since tracepoint locations are never duplicated with others', tracepoint
6892 locations at the same address of different tracepoints are regarded as
6893 different locations. */
6894 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6899 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6900 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6901 the same location. If SW_HW_BPS_MATCH is true, then software
6902 breakpoint locations and hardware breakpoint locations match,
6903 otherwise they don't. */
6906 breakpoint_locations_match (struct bp_location
*loc1
,
6907 struct bp_location
*loc2
,
6908 bool sw_hw_bps_match
)
6910 int hw_point1
, hw_point2
;
6912 /* Both of them must not be in moribund_locations. */
6913 gdb_assert (loc1
->owner
!= NULL
);
6914 gdb_assert (loc2
->owner
!= NULL
);
6916 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6917 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6919 if (hw_point1
!= hw_point2
)
6922 return watchpoint_locations_match (loc1
, loc2
);
6923 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6924 return tracepoint_locations_match (loc1
, loc2
);
6926 /* We compare bp_location.length in order to cover ranged
6927 breakpoints. Keep this in sync with
6928 bp_location_is_less_than. */
6929 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6930 loc2
->pspace
->aspace
, loc2
->address
)
6931 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
6932 && loc1
->length
== loc2
->length
);
6936 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6937 int bnum
, int have_bnum
)
6939 /* The longest string possibly returned by hex_string_custom
6940 is 50 chars. These must be at least that big for safety. */
6944 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6945 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6947 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6948 bnum
, astr1
, astr2
);
6950 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6953 /* Adjust a breakpoint's address to account for architectural
6954 constraints on breakpoint placement. Return the adjusted address.
6955 Note: Very few targets require this kind of adjustment. For most
6956 targets, this function is simply the identity function. */
6959 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6960 CORE_ADDR bpaddr
, enum bptype bptype
)
6962 if (bptype
== bp_watchpoint
6963 || bptype
== bp_hardware_watchpoint
6964 || bptype
== bp_read_watchpoint
6965 || bptype
== bp_access_watchpoint
6966 || bptype
== bp_catchpoint
)
6968 /* Watchpoints and the various bp_catch_* eventpoints should not
6969 have their addresses modified. */
6972 else if (bptype
== bp_single_step
)
6974 /* Single-step breakpoints should not have their addresses
6975 modified. If there's any architectural constrain that
6976 applies to this address, then it should have already been
6977 taken into account when the breakpoint was created in the
6978 first place. If we didn't do this, stepping through e.g.,
6979 Thumb-2 IT blocks would break. */
6984 CORE_ADDR adjusted_bpaddr
= bpaddr
;
6986 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
6988 /* Some targets have architectural constraints on the placement
6989 of breakpoint instructions. Obtain the adjusted address. */
6990 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6993 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
6995 /* An adjusted breakpoint address can significantly alter
6996 a user's expectations. Print a warning if an adjustment
6998 if (adjusted_bpaddr
!= bpaddr
)
6999 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7001 return adjusted_bpaddr
;
7006 bp_location_from_bp_type (bptype type
)
7011 case bp_single_step
:
7015 case bp_longjmp_resume
:
7016 case bp_longjmp_call_dummy
:
7018 case bp_exception_resume
:
7019 case bp_step_resume
:
7020 case bp_hp_step_resume
:
7021 case bp_watchpoint_scope
:
7023 case bp_std_terminate
:
7024 case bp_shlib_event
:
7025 case bp_thread_event
:
7026 case bp_overlay_event
:
7028 case bp_longjmp_master
:
7029 case bp_std_terminate_master
:
7030 case bp_exception_master
:
7031 case bp_gnu_ifunc_resolver
:
7032 case bp_gnu_ifunc_resolver_return
:
7034 return bp_loc_software_breakpoint
;
7035 case bp_hardware_breakpoint
:
7036 return bp_loc_hardware_breakpoint
;
7037 case bp_hardware_watchpoint
:
7038 case bp_read_watchpoint
:
7039 case bp_access_watchpoint
:
7040 return bp_loc_hardware_watchpoint
;
7044 case bp_fast_tracepoint
:
7045 case bp_static_tracepoint
:
7046 return bp_loc_other
;
7048 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7052 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7054 this->owner
= owner
;
7055 this->cond_bytecode
= NULL
;
7056 this->shlib_disabled
= 0;
7058 this->disabled_by_cond
= false;
7060 this->loc_type
= type
;
7062 if (this->loc_type
== bp_loc_software_breakpoint
7063 || this->loc_type
== bp_loc_hardware_breakpoint
)
7064 mark_breakpoint_location_modified (this);
7069 bp_location::bp_location (breakpoint
*owner
)
7070 : bp_location::bp_location (owner
,
7071 bp_location_from_bp_type (owner
->type
))
7075 /* Allocate a struct bp_location. */
7077 static struct bp_location
*
7078 allocate_bp_location (struct breakpoint
*bpt
)
7080 return bpt
->ops
->allocate_location (bpt
);
7084 free_bp_location (struct bp_location
*loc
)
7089 /* Increment reference count. */
7092 incref_bp_location (struct bp_location
*bl
)
7097 /* Decrement reference count. If the reference count reaches 0,
7098 destroy the bp_location. Sets *BLP to NULL. */
7101 decref_bp_location (struct bp_location
**blp
)
7103 gdb_assert ((*blp
)->refc
> 0);
7105 if (--(*blp
)->refc
== 0)
7106 free_bp_location (*blp
);
7110 /* Add breakpoint B at the end of the global breakpoint chain. */
7113 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7115 struct breakpoint
*b1
;
7116 struct breakpoint
*result
= b
.get ();
7118 /* Add this breakpoint to the end of the chain so that a list of
7119 breakpoints will come out in order of increasing numbers. */
7121 b1
= breakpoint_chain
;
7123 breakpoint_chain
= b
.release ();
7128 b1
->next
= b
.release ();
7134 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7137 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7138 struct gdbarch
*gdbarch
,
7140 const struct breakpoint_ops
*ops
)
7142 gdb_assert (ops
!= NULL
);
7146 b
->gdbarch
= gdbarch
;
7147 b
->language
= current_language
->la_language
;
7148 b
->input_radix
= input_radix
;
7149 b
->related_breakpoint
= b
;
7152 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7153 that has type BPTYPE and has no locations as yet. */
7155 static struct breakpoint
*
7156 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7158 const struct breakpoint_ops
*ops
)
7160 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7162 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7163 return add_to_breakpoint_chain (std::move (b
));
7166 /* Initialize loc->function_name. */
7169 set_breakpoint_location_function (struct bp_location
*loc
)
7171 gdb_assert (loc
->owner
!= NULL
);
7173 if (loc
->owner
->type
== bp_breakpoint
7174 || loc
->owner
->type
== bp_hardware_breakpoint
7175 || is_tracepoint (loc
->owner
))
7177 const char *function_name
;
7179 if (loc
->msymbol
!= NULL
7180 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7181 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7183 struct breakpoint
*b
= loc
->owner
;
7185 function_name
= loc
->msymbol
->linkage_name ();
7187 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7188 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7190 /* Create only the whole new breakpoint of this type but do not
7191 mess more complicated breakpoints with multiple locations. */
7192 b
->type
= bp_gnu_ifunc_resolver
;
7193 /* Remember the resolver's address for use by the return
7195 loc
->related_address
= loc
->address
;
7199 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7202 loc
->function_name
= xstrdup (function_name
);
7206 /* Attempt to determine architecture of location identified by SAL. */
7208 get_sal_arch (struct symtab_and_line sal
)
7211 return sal
.section
->objfile
->arch ();
7213 return SYMTAB_OBJFILE (sal
.symtab
)->arch ();
7218 /* Low level routine for partially initializing a breakpoint of type
7219 BPTYPE. The newly created breakpoint's address, section, source
7220 file name, and line number are provided by SAL.
7222 It is expected that the caller will complete the initialization of
7223 the newly created breakpoint struct as well as output any status
7224 information regarding the creation of a new breakpoint. */
7227 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7228 struct symtab_and_line sal
, enum bptype bptype
,
7229 const struct breakpoint_ops
*ops
)
7231 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7233 add_location_to_breakpoint (b
, &sal
);
7235 if (bptype
!= bp_catchpoint
)
7236 gdb_assert (sal
.pspace
!= NULL
);
7238 /* Store the program space that was used to set the breakpoint,
7239 except for ordinary breakpoints, which are independent of the
7241 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7242 b
->pspace
= sal
.pspace
;
7245 /* set_raw_breakpoint is a low level routine for allocating and
7246 partially initializing a breakpoint of type BPTYPE. The newly
7247 created breakpoint's address, section, source file name, and line
7248 number are provided by SAL. The newly created and partially
7249 initialized breakpoint is added to the breakpoint chain and
7250 is also returned as the value of this function.
7252 It is expected that the caller will complete the initialization of
7253 the newly created breakpoint struct as well as output any status
7254 information regarding the creation of a new breakpoint. In
7255 particular, set_raw_breakpoint does NOT set the breakpoint
7256 number! Care should be taken to not allow an error to occur
7257 prior to completing the initialization of the breakpoint. If this
7258 should happen, a bogus breakpoint will be left on the chain. */
7261 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7262 struct symtab_and_line sal
, enum bptype bptype
,
7263 const struct breakpoint_ops
*ops
)
7265 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7267 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7268 return add_to_breakpoint_chain (std::move (b
));
7271 /* Call this routine when stepping and nexting to enable a breakpoint
7272 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7273 initiated the operation. */
7276 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7278 struct breakpoint
*b
, *b_tmp
;
7279 int thread
= tp
->global_num
;
7281 /* To avoid having to rescan all objfile symbols at every step,
7282 we maintain a list of continually-inserted but always disabled
7283 longjmp "master" breakpoints. Here, we simply create momentary
7284 clones of those and enable them for the requested thread. */
7285 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7286 if (b
->pspace
== current_program_space
7287 && (b
->type
== bp_longjmp_master
7288 || b
->type
== bp_exception_master
))
7290 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7291 struct breakpoint
*clone
;
7293 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7294 after their removal. */
7295 clone
= momentary_breakpoint_from_master (b
, type
,
7296 &momentary_breakpoint_ops
, 1);
7297 clone
->thread
= thread
;
7300 tp
->initiating_frame
= frame
;
7303 /* Delete all longjmp breakpoints from THREAD. */
7305 delete_longjmp_breakpoint (int thread
)
7307 struct breakpoint
*b
, *b_tmp
;
7309 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7310 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7312 if (b
->thread
== thread
)
7313 delete_breakpoint (b
);
7318 delete_longjmp_breakpoint_at_next_stop (int thread
)
7320 struct breakpoint
*b
, *b_tmp
;
7322 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7323 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7325 if (b
->thread
== thread
)
7326 b
->disposition
= disp_del_at_next_stop
;
7330 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7331 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7332 pointer to any of them. Return NULL if this system cannot place longjmp
7336 set_longjmp_breakpoint_for_call_dummy (void)
7338 struct breakpoint
*b
, *retval
= NULL
;
7341 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7343 struct breakpoint
*new_b
;
7345 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7346 &momentary_breakpoint_ops
,
7348 new_b
->thread
= inferior_thread ()->global_num
;
7350 /* Link NEW_B into the chain of RETVAL breakpoints. */
7352 gdb_assert (new_b
->related_breakpoint
== new_b
);
7355 new_b
->related_breakpoint
= retval
;
7356 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7357 retval
= retval
->related_breakpoint
;
7358 retval
->related_breakpoint
= new_b
;
7364 /* Verify all existing dummy frames and their associated breakpoints for
7365 TP. Remove those which can no longer be found in the current frame
7368 You should call this function only at places where it is safe to currently
7369 unwind the whole stack. Failed stack unwind would discard live dummy
7373 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7375 struct breakpoint
*b
, *b_tmp
;
7377 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7378 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7380 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7382 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7383 dummy_b
= dummy_b
->related_breakpoint
;
7384 if (dummy_b
->type
!= bp_call_dummy
7385 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7388 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7390 while (b
->related_breakpoint
!= b
)
7392 if (b_tmp
== b
->related_breakpoint
)
7393 b_tmp
= b
->related_breakpoint
->next
;
7394 delete_breakpoint (b
->related_breakpoint
);
7396 delete_breakpoint (b
);
7401 enable_overlay_breakpoints (void)
7403 struct breakpoint
*b
;
7406 if (b
->type
== bp_overlay_event
)
7408 b
->enable_state
= bp_enabled
;
7409 update_global_location_list (UGLL_MAY_INSERT
);
7410 overlay_events_enabled
= 1;
7415 disable_overlay_breakpoints (void)
7417 struct breakpoint
*b
;
7420 if (b
->type
== bp_overlay_event
)
7422 b
->enable_state
= bp_disabled
;
7423 update_global_location_list (UGLL_DONT_INSERT
);
7424 overlay_events_enabled
= 0;
7428 /* Set an active std::terminate breakpoint for each std::terminate
7429 master breakpoint. */
7431 set_std_terminate_breakpoint (void)
7433 struct breakpoint
*b
, *b_tmp
;
7435 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7436 if (b
->pspace
== current_program_space
7437 && b
->type
== bp_std_terminate_master
)
7439 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7440 &momentary_breakpoint_ops
, 1);
7444 /* Delete all the std::terminate breakpoints. */
7446 delete_std_terminate_breakpoint (void)
7448 struct breakpoint
*b
, *b_tmp
;
7450 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7451 if (b
->type
== bp_std_terminate
)
7452 delete_breakpoint (b
);
7456 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7458 struct breakpoint
*b
;
7460 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7461 &internal_breakpoint_ops
);
7463 b
->enable_state
= bp_enabled
;
7464 /* location has to be used or breakpoint_re_set will delete me. */
7465 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7467 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7472 struct lang_and_radix
7478 /* Create a breakpoint for JIT code registration and unregistration. */
7481 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7483 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7484 &internal_breakpoint_ops
);
7487 /* Remove JIT code registration and unregistration breakpoint(s). */
7490 remove_jit_event_breakpoints (void)
7492 struct breakpoint
*b
, *b_tmp
;
7494 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7495 if (b
->type
== bp_jit_event
7496 && b
->loc
->pspace
== current_program_space
)
7497 delete_breakpoint (b
);
7501 remove_solib_event_breakpoints (void)
7503 struct breakpoint
*b
, *b_tmp
;
7505 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7506 if (b
->type
== bp_shlib_event
7507 && b
->loc
->pspace
== current_program_space
)
7508 delete_breakpoint (b
);
7511 /* See breakpoint.h. */
7514 remove_solib_event_breakpoints_at_next_stop (void)
7516 struct breakpoint
*b
, *b_tmp
;
7518 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7519 if (b
->type
== bp_shlib_event
7520 && b
->loc
->pspace
== current_program_space
)
7521 b
->disposition
= disp_del_at_next_stop
;
7524 /* Helper for create_solib_event_breakpoint /
7525 create_and_insert_solib_event_breakpoint. Allows specifying which
7526 INSERT_MODE to pass through to update_global_location_list. */
7528 static struct breakpoint
*
7529 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7530 enum ugll_insert_mode insert_mode
)
7532 struct breakpoint
*b
;
7534 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7535 &internal_breakpoint_ops
);
7536 update_global_location_list_nothrow (insert_mode
);
7541 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7543 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7546 /* See breakpoint.h. */
7549 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7551 struct breakpoint
*b
;
7553 /* Explicitly tell update_global_location_list to insert
7555 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7556 if (!b
->loc
->inserted
)
7558 delete_breakpoint (b
);
7564 /* Disable any breakpoints that are on code in shared libraries. Only
7565 apply to enabled breakpoints, disabled ones can just stay disabled. */
7568 disable_breakpoints_in_shlibs (void)
7570 struct bp_location
*loc
, **locp_tmp
;
7572 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7574 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7575 struct breakpoint
*b
= loc
->owner
;
7577 /* We apply the check to all breakpoints, including disabled for
7578 those with loc->duplicate set. This is so that when breakpoint
7579 becomes enabled, or the duplicate is removed, gdb will try to
7580 insert all breakpoints. If we don't set shlib_disabled here,
7581 we'll try to insert those breakpoints and fail. */
7582 if (((b
->type
== bp_breakpoint
)
7583 || (b
->type
== bp_jit_event
)
7584 || (b
->type
== bp_hardware_breakpoint
)
7585 || (is_tracepoint (b
)))
7586 && loc
->pspace
== current_program_space
7587 && !loc
->shlib_disabled
7588 && solib_name_from_address (loc
->pspace
, loc
->address
)
7591 loc
->shlib_disabled
= 1;
7596 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7597 notification of unloaded_shlib. Only apply to enabled breakpoints,
7598 disabled ones can just stay disabled. */
7601 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7603 struct bp_location
*loc
, **locp_tmp
;
7604 int disabled_shlib_breaks
= 0;
7606 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7608 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7609 struct breakpoint
*b
= loc
->owner
;
7611 if (solib
->pspace
== loc
->pspace
7612 && !loc
->shlib_disabled
7613 && (((b
->type
== bp_breakpoint
7614 || b
->type
== bp_jit_event
7615 || b
->type
== bp_hardware_breakpoint
)
7616 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7617 || loc
->loc_type
== bp_loc_software_breakpoint
))
7618 || is_tracepoint (b
))
7619 && solib_contains_address_p (solib
, loc
->address
))
7621 loc
->shlib_disabled
= 1;
7622 /* At this point, we cannot rely on remove_breakpoint
7623 succeeding so we must mark the breakpoint as not inserted
7624 to prevent future errors occurring in remove_breakpoints. */
7627 /* This may cause duplicate notifications for the same breakpoint. */
7628 gdb::observers::breakpoint_modified
.notify (b
);
7630 if (!disabled_shlib_breaks
)
7632 target_terminal::ours_for_output ();
7633 warning (_("Temporarily disabling breakpoints "
7634 "for unloaded shared library \"%s\""),
7637 disabled_shlib_breaks
= 1;
7642 /* Disable any breakpoints and tracepoints in OBJFILE upon
7643 notification of free_objfile. Only apply to enabled breakpoints,
7644 disabled ones can just stay disabled. */
7647 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7649 struct breakpoint
*b
;
7651 if (objfile
== NULL
)
7654 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7655 managed by the user with add-symbol-file/remove-symbol-file.
7656 Similarly to how breakpoints in shared libraries are handled in
7657 response to "nosharedlibrary", mark breakpoints in such modules
7658 shlib_disabled so they end up uninserted on the next global
7659 location list update. Shared libraries not loaded by the user
7660 aren't handled here -- they're already handled in
7661 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7662 solib_unloaded observer. We skip objfiles that are not
7663 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7665 if ((objfile
->flags
& OBJF_SHARED
) == 0
7666 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7671 struct bp_location
*loc
;
7672 int bp_modified
= 0;
7674 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7677 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7679 CORE_ADDR loc_addr
= loc
->address
;
7681 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7682 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7685 if (loc
->shlib_disabled
!= 0)
7688 if (objfile
->pspace
!= loc
->pspace
)
7691 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7692 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7695 if (is_addr_in_objfile (loc_addr
, objfile
))
7697 loc
->shlib_disabled
= 1;
7698 /* At this point, we don't know whether the object was
7699 unmapped from the inferior or not, so leave the
7700 inserted flag alone. We'll handle failure to
7701 uninsert quietly, in case the object was indeed
7704 mark_breakpoint_location_modified (loc
);
7711 gdb::observers::breakpoint_modified
.notify (b
);
7715 /* FORK & VFORK catchpoints. */
7717 /* An instance of this type is used to represent a fork or vfork
7718 catchpoint. A breakpoint is really of this type iff its ops pointer points
7719 to CATCH_FORK_BREAKPOINT_OPS. */
7721 struct fork_catchpoint
: public breakpoint
7723 /* Process id of a child process whose forking triggered this
7724 catchpoint. This field is only valid immediately after this
7725 catchpoint has triggered. */
7726 ptid_t forked_inferior_pid
;
7729 /* Implement the "insert" breakpoint_ops method for fork
7733 insert_catch_fork (struct bp_location
*bl
)
7735 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7738 /* Implement the "remove" breakpoint_ops method for fork
7742 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7744 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7747 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7751 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7752 const address_space
*aspace
, CORE_ADDR bp_addr
,
7753 const struct target_waitstatus
*ws
)
7755 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7757 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7760 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7764 /* Implement the "print_it" breakpoint_ops method for fork
7767 static enum print_stop_action
7768 print_it_catch_fork (bpstat bs
)
7770 struct ui_out
*uiout
= current_uiout
;
7771 struct breakpoint
*b
= bs
->breakpoint_at
;
7772 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7774 annotate_catchpoint (b
->number
);
7775 maybe_print_thread_hit_breakpoint (uiout
);
7776 if (b
->disposition
== disp_del
)
7777 uiout
->text ("Temporary catchpoint ");
7779 uiout
->text ("Catchpoint ");
7780 if (uiout
->is_mi_like_p ())
7782 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7783 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7785 uiout
->field_signed ("bkptno", b
->number
);
7786 uiout
->text (" (forked process ");
7787 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7788 uiout
->text ("), ");
7789 return PRINT_SRC_AND_LOC
;
7792 /* Implement the "print_one" breakpoint_ops method for fork
7796 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7798 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7799 struct value_print_options opts
;
7800 struct ui_out
*uiout
= current_uiout
;
7802 get_user_print_options (&opts
);
7804 /* Field 4, the address, is omitted (which makes the columns not
7805 line up too nicely with the headers, but the effect is relatively
7807 if (opts
.addressprint
)
7808 uiout
->field_skip ("addr");
7810 uiout
->text ("fork");
7811 if (c
->forked_inferior_pid
!= null_ptid
)
7813 uiout
->text (", process ");
7814 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7818 if (uiout
->is_mi_like_p ())
7819 uiout
->field_string ("catch-type", "fork");
7822 /* Implement the "print_mention" breakpoint_ops method for fork
7826 print_mention_catch_fork (struct breakpoint
*b
)
7828 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7831 /* Implement the "print_recreate" breakpoint_ops method for fork
7835 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7837 fprintf_unfiltered (fp
, "catch fork");
7838 print_recreate_thread (b
, fp
);
7841 /* The breakpoint_ops structure to be used in fork catchpoints. */
7843 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7845 /* Implement the "insert" breakpoint_ops method for vfork
7849 insert_catch_vfork (struct bp_location
*bl
)
7851 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7854 /* Implement the "remove" breakpoint_ops method for vfork
7858 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7860 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7863 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7867 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7868 const address_space
*aspace
, CORE_ADDR bp_addr
,
7869 const struct target_waitstatus
*ws
)
7871 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7873 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7876 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7880 /* Implement the "print_it" breakpoint_ops method for vfork
7883 static enum print_stop_action
7884 print_it_catch_vfork (bpstat bs
)
7886 struct ui_out
*uiout
= current_uiout
;
7887 struct breakpoint
*b
= bs
->breakpoint_at
;
7888 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7890 annotate_catchpoint (b
->number
);
7891 maybe_print_thread_hit_breakpoint (uiout
);
7892 if (b
->disposition
== disp_del
)
7893 uiout
->text ("Temporary catchpoint ");
7895 uiout
->text ("Catchpoint ");
7896 if (uiout
->is_mi_like_p ())
7898 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7899 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7901 uiout
->field_signed ("bkptno", b
->number
);
7902 uiout
->text (" (vforked process ");
7903 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7904 uiout
->text ("), ");
7905 return PRINT_SRC_AND_LOC
;
7908 /* Implement the "print_one" breakpoint_ops method for vfork
7912 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7914 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7915 struct value_print_options opts
;
7916 struct ui_out
*uiout
= current_uiout
;
7918 get_user_print_options (&opts
);
7919 /* Field 4, the address, is omitted (which makes the columns not
7920 line up too nicely with the headers, but the effect is relatively
7922 if (opts
.addressprint
)
7923 uiout
->field_skip ("addr");
7925 uiout
->text ("vfork");
7926 if (c
->forked_inferior_pid
!= null_ptid
)
7928 uiout
->text (", process ");
7929 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7933 if (uiout
->is_mi_like_p ())
7934 uiout
->field_string ("catch-type", "vfork");
7937 /* Implement the "print_mention" breakpoint_ops method for vfork
7941 print_mention_catch_vfork (struct breakpoint
*b
)
7943 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7946 /* Implement the "print_recreate" breakpoint_ops method for vfork
7950 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7952 fprintf_unfiltered (fp
, "catch vfork");
7953 print_recreate_thread (b
, fp
);
7956 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7958 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7960 /* An instance of this type is used to represent an solib catchpoint.
7961 A breakpoint is really of this type iff its ops pointer points to
7962 CATCH_SOLIB_BREAKPOINT_OPS. */
7964 struct solib_catchpoint
: public breakpoint
7966 ~solib_catchpoint () override
;
7968 /* True for "catch load", false for "catch unload". */
7971 /* Regular expression to match, if any. COMPILED is only valid when
7972 REGEX is non-NULL. */
7974 std::unique_ptr
<compiled_regex
> compiled
;
7977 solib_catchpoint::~solib_catchpoint ()
7979 xfree (this->regex
);
7983 insert_catch_solib (struct bp_location
*ignore
)
7989 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
7995 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7996 const address_space
*aspace
,
7998 const struct target_waitstatus
*ws
)
8000 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8001 struct breakpoint
*other
;
8003 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8006 ALL_BREAKPOINTS (other
)
8008 struct bp_location
*other_bl
;
8010 if (other
== bl
->owner
)
8013 if (other
->type
!= bp_shlib_event
)
8016 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8019 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8021 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8030 check_status_catch_solib (struct bpstats
*bs
)
8032 struct solib_catchpoint
*self
8033 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8037 for (so_list
*iter
: current_program_space
->added_solibs
)
8040 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8046 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
8049 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
8055 bs
->print_it
= print_it_noop
;
8058 static enum print_stop_action
8059 print_it_catch_solib (bpstat bs
)
8061 struct breakpoint
*b
= bs
->breakpoint_at
;
8062 struct ui_out
*uiout
= current_uiout
;
8064 annotate_catchpoint (b
->number
);
8065 maybe_print_thread_hit_breakpoint (uiout
);
8066 if (b
->disposition
== disp_del
)
8067 uiout
->text ("Temporary catchpoint ");
8069 uiout
->text ("Catchpoint ");
8070 uiout
->field_signed ("bkptno", b
->number
);
8072 if (uiout
->is_mi_like_p ())
8073 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8074 print_solib_event (1);
8075 return PRINT_SRC_AND_LOC
;
8079 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8081 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8082 struct value_print_options opts
;
8083 struct ui_out
*uiout
= current_uiout
;
8085 get_user_print_options (&opts
);
8086 /* Field 4, the address, is omitted (which makes the columns not
8087 line up too nicely with the headers, but the effect is relatively
8089 if (opts
.addressprint
)
8092 uiout
->field_skip ("addr");
8100 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8102 msg
= _("load of library");
8107 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8109 msg
= _("unload of library");
8111 uiout
->field_string ("what", msg
);
8113 if (uiout
->is_mi_like_p ())
8114 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8118 print_mention_catch_solib (struct breakpoint
*b
)
8120 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8122 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8123 self
->is_load
? "load" : "unload");
8127 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8129 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8131 fprintf_unfiltered (fp
, "%s %s",
8132 b
->disposition
== disp_del
? "tcatch" : "catch",
8133 self
->is_load
? "load" : "unload");
8135 fprintf_unfiltered (fp
, " %s", self
->regex
);
8136 fprintf_unfiltered (fp
, "\n");
8139 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8141 /* See breakpoint.h. */
8144 add_solib_catchpoint (const char *arg
, bool is_load
, bool is_temp
, bool enabled
)
8146 struct gdbarch
*gdbarch
= get_current_arch ();
8150 arg
= skip_spaces (arg
);
8152 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8156 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8157 _("Invalid regexp")));
8158 c
->regex
= xstrdup (arg
);
8161 c
->is_load
= is_load
;
8162 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8163 &catch_solib_breakpoint_ops
);
8165 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8167 install_breakpoint (0, std::move (c
), 1);
8170 /* A helper function that does all the work for "catch load" and
8174 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8175 struct cmd_list_element
*command
)
8177 const int enabled
= 1;
8178 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8180 add_solib_catchpoint (arg
, is_load
, temp
, enabled
);
8184 catch_load_command_1 (const char *arg
, int from_tty
,
8185 struct cmd_list_element
*command
)
8187 catch_load_or_unload (arg
, from_tty
, 1, command
);
8191 catch_unload_command_1 (const char *arg
, int from_tty
,
8192 struct cmd_list_element
*command
)
8194 catch_load_or_unload (arg
, from_tty
, 0, command
);
8197 /* See breakpoint.h. */
8200 init_catchpoint (struct breakpoint
*b
,
8201 struct gdbarch
*gdbarch
, bool temp
,
8202 const char *cond_string
,
8203 const struct breakpoint_ops
*ops
)
8205 symtab_and_line sal
;
8206 sal
.pspace
= current_program_space
;
8208 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8210 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8211 b
->disposition
= temp
? disp_del
: disp_donttouch
;
8215 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8217 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8218 set_breakpoint_number (internal
, b
);
8219 if (is_tracepoint (b
))
8220 set_tracepoint_count (breakpoint_count
);
8223 gdb::observers::breakpoint_created
.notify (b
);
8226 update_global_location_list (UGLL_MAY_INSERT
);
8230 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8231 bool temp
, const char *cond_string
,
8232 const struct breakpoint_ops
*ops
)
8234 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8236 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
, ops
);
8238 c
->forked_inferior_pid
= null_ptid
;
8240 install_breakpoint (0, std::move (c
), 1);
8243 /* Exec catchpoints. */
8245 /* An instance of this type is used to represent an exec catchpoint.
8246 A breakpoint is really of this type iff its ops pointer points to
8247 CATCH_EXEC_BREAKPOINT_OPS. */
8249 struct exec_catchpoint
: public breakpoint
8251 ~exec_catchpoint () override
;
8253 /* Filename of a program whose exec triggered this catchpoint.
8254 This field is only valid immediately after this catchpoint has
8256 char *exec_pathname
;
8259 /* Exec catchpoint destructor. */
8261 exec_catchpoint::~exec_catchpoint ()
8263 xfree (this->exec_pathname
);
8267 insert_catch_exec (struct bp_location
*bl
)
8269 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8273 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8275 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8279 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8280 const address_space
*aspace
, CORE_ADDR bp_addr
,
8281 const struct target_waitstatus
*ws
)
8283 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8285 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8288 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8292 static enum print_stop_action
8293 print_it_catch_exec (bpstat bs
)
8295 struct ui_out
*uiout
= current_uiout
;
8296 struct breakpoint
*b
= bs
->breakpoint_at
;
8297 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8299 annotate_catchpoint (b
->number
);
8300 maybe_print_thread_hit_breakpoint (uiout
);
8301 if (b
->disposition
== disp_del
)
8302 uiout
->text ("Temporary catchpoint ");
8304 uiout
->text ("Catchpoint ");
8305 if (uiout
->is_mi_like_p ())
8307 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8308 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8310 uiout
->field_signed ("bkptno", b
->number
);
8311 uiout
->text (" (exec'd ");
8312 uiout
->field_string ("new-exec", c
->exec_pathname
);
8313 uiout
->text ("), ");
8315 return PRINT_SRC_AND_LOC
;
8319 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8321 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8322 struct value_print_options opts
;
8323 struct ui_out
*uiout
= current_uiout
;
8325 get_user_print_options (&opts
);
8327 /* Field 4, the address, is omitted (which makes the columns
8328 not line up too nicely with the headers, but the effect
8329 is relatively readable). */
8330 if (opts
.addressprint
)
8331 uiout
->field_skip ("addr");
8333 uiout
->text ("exec");
8334 if (c
->exec_pathname
!= NULL
)
8336 uiout
->text (", program \"");
8337 uiout
->field_string ("what", c
->exec_pathname
);
8338 uiout
->text ("\" ");
8341 if (uiout
->is_mi_like_p ())
8342 uiout
->field_string ("catch-type", "exec");
8346 print_mention_catch_exec (struct breakpoint
*b
)
8348 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8351 /* Implement the "print_recreate" breakpoint_ops method for exec
8355 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8357 fprintf_unfiltered (fp
, "catch exec");
8358 print_recreate_thread (b
, fp
);
8361 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8364 hw_breakpoint_used_count (void)
8367 struct breakpoint
*b
;
8368 struct bp_location
*bl
;
8372 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8373 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8375 /* Special types of hardware breakpoints may use more than
8377 i
+= b
->ops
->resources_needed (bl
);
8384 /* Returns the resources B would use if it were a hardware
8388 hw_watchpoint_use_count (struct breakpoint
*b
)
8391 struct bp_location
*bl
;
8393 if (!breakpoint_enabled (b
))
8396 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8398 /* Special types of hardware watchpoints may use more than
8400 i
+= b
->ops
->resources_needed (bl
);
8406 /* Returns the sum the used resources of all hardware watchpoints of
8407 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8408 the sum of the used resources of all hardware watchpoints of other
8409 types _not_ TYPE. */
8412 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8413 enum bptype type
, int *other_type_used
)
8416 struct breakpoint
*b
;
8418 *other_type_used
= 0;
8423 if (!breakpoint_enabled (b
))
8426 if (b
->type
== type
)
8427 i
+= hw_watchpoint_use_count (b
);
8428 else if (is_hardware_watchpoint (b
))
8429 *other_type_used
= 1;
8436 disable_watchpoints_before_interactive_call_start (void)
8438 struct breakpoint
*b
;
8442 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8444 b
->enable_state
= bp_call_disabled
;
8445 update_global_location_list (UGLL_DONT_INSERT
);
8451 enable_watchpoints_after_interactive_call_stop (void)
8453 struct breakpoint
*b
;
8457 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8459 b
->enable_state
= bp_enabled
;
8460 update_global_location_list (UGLL_MAY_INSERT
);
8466 disable_breakpoints_before_startup (void)
8468 current_program_space
->executing_startup
= 1;
8469 update_global_location_list (UGLL_DONT_INSERT
);
8473 enable_breakpoints_after_startup (void)
8475 current_program_space
->executing_startup
= 0;
8476 breakpoint_re_set ();
8479 /* Create a new single-step breakpoint for thread THREAD, with no
8482 static struct breakpoint
*
8483 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8485 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8487 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8488 &momentary_breakpoint_ops
);
8490 b
->disposition
= disp_donttouch
;
8491 b
->frame_id
= null_frame_id
;
8494 gdb_assert (b
->thread
!= 0);
8496 return add_to_breakpoint_chain (std::move (b
));
8499 /* Set a momentary breakpoint of type TYPE at address specified by
8500 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8504 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8505 struct frame_id frame_id
, enum bptype type
)
8507 struct breakpoint
*b
;
8509 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8511 gdb_assert (!frame_id_artificial_p (frame_id
));
8513 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8514 b
->enable_state
= bp_enabled
;
8515 b
->disposition
= disp_donttouch
;
8516 b
->frame_id
= frame_id
;
8518 b
->thread
= inferior_thread ()->global_num
;
8520 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8522 return breakpoint_up (b
);
8525 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8526 The new breakpoint will have type TYPE, use OPS as its
8527 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8529 static struct breakpoint
*
8530 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8532 const struct breakpoint_ops
*ops
,
8535 struct breakpoint
*copy
;
8537 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8538 copy
->loc
= allocate_bp_location (copy
);
8539 set_breakpoint_location_function (copy
->loc
);
8541 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8542 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8543 copy
->loc
->address
= orig
->loc
->address
;
8544 copy
->loc
->section
= orig
->loc
->section
;
8545 copy
->loc
->pspace
= orig
->loc
->pspace
;
8546 copy
->loc
->probe
= orig
->loc
->probe
;
8547 copy
->loc
->line_number
= orig
->loc
->line_number
;
8548 copy
->loc
->symtab
= orig
->loc
->symtab
;
8549 copy
->loc
->enabled
= loc_enabled
;
8550 copy
->frame_id
= orig
->frame_id
;
8551 copy
->thread
= orig
->thread
;
8552 copy
->pspace
= orig
->pspace
;
8554 copy
->enable_state
= bp_enabled
;
8555 copy
->disposition
= disp_donttouch
;
8556 copy
->number
= internal_breakpoint_number
--;
8558 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8562 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8566 clone_momentary_breakpoint (struct breakpoint
*orig
)
8568 /* If there's nothing to clone, then return nothing. */
8572 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8576 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8579 struct symtab_and_line sal
;
8581 sal
= find_pc_line (pc
, 0);
8583 sal
.section
= find_pc_overlay (pc
);
8584 sal
.explicit_pc
= 1;
8586 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8590 /* Tell the user we have just set a breakpoint B. */
8593 mention (struct breakpoint
*b
)
8595 b
->ops
->print_mention (b
);
8596 current_uiout
->text ("\n");
8600 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8602 /* Handle "set breakpoint auto-hw on".
8604 If the explicitly specified breakpoint type is not hardware
8605 breakpoint, check the memory map to see whether the breakpoint
8606 address is in read-only memory.
8608 - location type is not hardware breakpoint, memory is read-only.
8609 We change the type of the location to hardware breakpoint.
8611 - location type is hardware breakpoint, memory is read-write. This
8612 means we've previously made the location hardware one, but then the
8613 memory map changed, so we undo.
8617 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8619 if (automatic_hardware_breakpoints
8620 && bl
->owner
->type
!= bp_hardware_breakpoint
8621 && (bl
->loc_type
== bp_loc_software_breakpoint
8622 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8624 /* When breakpoints are removed, remove_breakpoints will use
8625 location types we've just set here, the only possible problem
8626 is that memory map has changed during running program, but
8627 it's not going to work anyway with current gdb. */
8628 mem_region
*mr
= lookup_mem_region (bl
->address
);
8632 enum bp_loc_type new_type
;
8634 if (mr
->attrib
.mode
!= MEM_RW
)
8635 new_type
= bp_loc_hardware_breakpoint
;
8637 new_type
= bp_loc_software_breakpoint
;
8639 if (new_type
!= bl
->loc_type
)
8641 static bool said
= false;
8643 bl
->loc_type
= new_type
;
8646 fprintf_filtered (gdb_stdout
,
8647 _("Note: automatically using "
8648 "hardware breakpoints for "
8649 "read-only addresses.\n"));
8657 static struct bp_location
*
8658 add_location_to_breakpoint (struct breakpoint
*b
,
8659 const struct symtab_and_line
*sal
)
8661 struct bp_location
*loc
, **tmp
;
8662 CORE_ADDR adjusted_address
;
8663 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8665 if (loc_gdbarch
== NULL
)
8666 loc_gdbarch
= b
->gdbarch
;
8668 /* Adjust the breakpoint's address prior to allocating a location.
8669 Once we call allocate_bp_location(), that mostly uninitialized
8670 location will be placed on the location chain. Adjustment of the
8671 breakpoint may cause target_read_memory() to be called and we do
8672 not want its scan of the location chain to find a breakpoint and
8673 location that's only been partially initialized. */
8674 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8677 /* Sort the locations by their ADDRESS. */
8678 loc
= allocate_bp_location (b
);
8679 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8680 tmp
= &((*tmp
)->next
))
8685 loc
->requested_address
= sal
->pc
;
8686 loc
->address
= adjusted_address
;
8687 loc
->pspace
= sal
->pspace
;
8688 loc
->probe
.prob
= sal
->prob
;
8689 loc
->probe
.objfile
= sal
->objfile
;
8690 gdb_assert (loc
->pspace
!= NULL
);
8691 loc
->section
= sal
->section
;
8692 loc
->gdbarch
= loc_gdbarch
;
8693 loc
->line_number
= sal
->line
;
8694 loc
->symtab
= sal
->symtab
;
8695 loc
->symbol
= sal
->symbol
;
8696 loc
->msymbol
= sal
->msymbol
;
8697 loc
->objfile
= sal
->objfile
;
8699 set_breakpoint_location_function (loc
);
8701 /* While by definition, permanent breakpoints are already present in the
8702 code, we don't mark the location as inserted. Normally one would expect
8703 that GDB could rely on that breakpoint instruction to stop the program,
8704 thus removing the need to insert its own breakpoint, except that executing
8705 the breakpoint instruction can kill the target instead of reporting a
8706 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8707 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8708 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8709 breakpoint be inserted normally results in QEMU knowing about the GDB
8710 breakpoint, and thus trap before the breakpoint instruction is executed.
8711 (If GDB later needs to continue execution past the permanent breakpoint,
8712 it manually increments the PC, thus avoiding executing the breakpoint
8714 if (bp_loc_is_permanent (loc
))
8721 /* Return true if LOC is pointing to a permanent breakpoint,
8722 return false otherwise. */
8725 bp_loc_is_permanent (struct bp_location
*loc
)
8727 gdb_assert (loc
!= NULL
);
8729 /* If we have a non-breakpoint-backed catchpoint or a software
8730 watchpoint, just return 0. We should not attempt to read from
8731 the addresses the locations of these breakpoint types point to.
8732 gdbarch_program_breakpoint_here_p, below, will attempt to read
8734 if (!bl_address_is_meaningful (loc
))
8737 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8738 switch_to_program_space_and_thread (loc
->pspace
);
8739 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8742 /* Build a command list for the dprintf corresponding to the current
8743 settings of the dprintf style options. */
8746 update_dprintf_command_list (struct breakpoint
*b
)
8748 char *dprintf_args
= b
->extra_string
;
8749 char *printf_line
= NULL
;
8754 dprintf_args
= skip_spaces (dprintf_args
);
8756 /* Allow a comma, as it may have terminated a location, but don't
8758 if (*dprintf_args
== ',')
8760 dprintf_args
= skip_spaces (dprintf_args
);
8762 if (*dprintf_args
!= '"')
8763 error (_("Bad format string, missing '\"'."));
8765 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8766 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8767 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8769 if (!dprintf_function
)
8770 error (_("No function supplied for dprintf call"));
8772 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8773 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8778 printf_line
= xstrprintf ("call (void) %s (%s)",
8782 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8784 if (target_can_run_breakpoint_commands ())
8785 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8788 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8789 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8793 internal_error (__FILE__
, __LINE__
,
8794 _("Invalid dprintf style."));
8796 gdb_assert (printf_line
!= NULL
);
8798 /* Manufacture a printf sequence. */
8799 struct command_line
*printf_cmd_line
8800 = new struct command_line (simple_control
, printf_line
);
8801 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8802 command_lines_deleter ()));
8805 /* Update all dprintf commands, making their command lists reflect
8806 current style settings. */
8809 update_dprintf_commands (const char *args
, int from_tty
,
8810 struct cmd_list_element
*c
)
8812 struct breakpoint
*b
;
8816 if (b
->type
== bp_dprintf
)
8817 update_dprintf_command_list (b
);
8821 /* Create a breakpoint with SAL as location. Use LOCATION
8822 as a description of the location, and COND_STRING
8823 as condition expression. If LOCATION is NULL then create an
8824 "address location" from the address in the SAL. */
8827 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8828 gdb::array_view
<const symtab_and_line
> sals
,
8829 event_location_up
&&location
,
8830 gdb::unique_xmalloc_ptr
<char> filter
,
8831 gdb::unique_xmalloc_ptr
<char> cond_string
,
8832 gdb::unique_xmalloc_ptr
<char> extra_string
,
8833 enum bptype type
, enum bpdisp disposition
,
8834 int thread
, int task
, int ignore_count
,
8835 const struct breakpoint_ops
*ops
, int from_tty
,
8836 int enabled
, int internal
, unsigned flags
,
8837 int display_canonical
)
8841 if (type
== bp_hardware_breakpoint
)
8843 int target_resources_ok
;
8845 i
= hw_breakpoint_used_count ();
8846 target_resources_ok
=
8847 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8849 if (target_resources_ok
== 0)
8850 error (_("No hardware breakpoint support in the target."));
8851 else if (target_resources_ok
< 0)
8852 error (_("Hardware breakpoints used exceeds limit."));
8855 gdb_assert (!sals
.empty ());
8857 for (const auto &sal
: sals
)
8859 struct bp_location
*loc
;
8863 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8865 loc_gdbarch
= gdbarch
;
8867 describe_other_breakpoints (loc_gdbarch
,
8868 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8871 if (&sal
== &sals
[0])
8873 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8877 b
->cond_string
= cond_string
.release ();
8878 b
->extra_string
= extra_string
.release ();
8879 b
->ignore_count
= ignore_count
;
8880 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8881 b
->disposition
= disposition
;
8883 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8884 b
->loc
->inserted
= 1;
8886 if (type
== bp_static_tracepoint
)
8888 struct tracepoint
*t
= (struct tracepoint
*) b
;
8889 struct static_tracepoint_marker marker
;
8891 if (strace_marker_p (b
))
8893 /* We already know the marker exists, otherwise, we
8894 wouldn't see a sal for it. */
8896 = &event_location_to_string (b
->location
.get ())[3];
8899 p
= skip_spaces (p
);
8901 endp
= skip_to_space (p
);
8903 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8905 printf_filtered (_("Probed static tracepoint "
8907 t
->static_trace_marker_id
.c_str ());
8909 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8911 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8913 printf_filtered (_("Probed static tracepoint "
8915 t
->static_trace_marker_id
.c_str ());
8918 warning (_("Couldn't determine the static "
8919 "tracepoint marker to probe"));
8926 loc
= add_location_to_breakpoint (b
, &sal
);
8927 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8931 /* Do not set breakpoint locations conditions yet. As locations
8932 are inserted, they get sorted based on their addresses. Let
8933 the list stabilize to have reliable location numbers. */
8935 /* Dynamic printf requires and uses additional arguments on the
8936 command line, otherwise it's an error. */
8937 if (type
== bp_dprintf
)
8939 if (b
->extra_string
)
8940 update_dprintf_command_list (b
);
8942 error (_("Format string required"));
8944 else if (b
->extra_string
)
8945 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8949 /* The order of the locations is now stable. Set the location
8950 condition using the location's number. */
8952 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
8954 if (b
->cond_string
!= nullptr)
8955 set_breakpoint_location_condition (b
->cond_string
, loc
, b
->number
,
8961 b
->display_canonical
= display_canonical
;
8962 if (location
!= NULL
)
8963 b
->location
= std::move (location
);
8965 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8966 b
->filter
= std::move (filter
);
8970 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8971 gdb::array_view
<const symtab_and_line
> sals
,
8972 event_location_up
&&location
,
8973 gdb::unique_xmalloc_ptr
<char> filter
,
8974 gdb::unique_xmalloc_ptr
<char> cond_string
,
8975 gdb::unique_xmalloc_ptr
<char> extra_string
,
8976 enum bptype type
, enum bpdisp disposition
,
8977 int thread
, int task
, int ignore_count
,
8978 const struct breakpoint_ops
*ops
, int from_tty
,
8979 int enabled
, int internal
, unsigned flags
,
8980 int display_canonical
)
8982 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8984 init_breakpoint_sal (b
.get (), gdbarch
,
8985 sals
, std::move (location
),
8987 std::move (cond_string
),
8988 std::move (extra_string
),
8990 thread
, task
, ignore_count
,
8992 enabled
, internal
, flags
,
8995 install_breakpoint (internal
, std::move (b
), 0);
8998 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8999 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9000 value. COND_STRING, if not NULL, specified the condition to be
9001 used for all breakpoints. Essentially the only case where
9002 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9003 function. In that case, it's still not possible to specify
9004 separate conditions for different overloaded functions, so
9005 we take just a single condition string.
9007 NOTE: If the function succeeds, the caller is expected to cleanup
9008 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9009 array contents). If the function fails (error() is called), the
9010 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9011 COND and SALS arrays and each of those arrays contents. */
9014 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9015 struct linespec_result
*canonical
,
9016 gdb::unique_xmalloc_ptr
<char> cond_string
,
9017 gdb::unique_xmalloc_ptr
<char> extra_string
,
9018 enum bptype type
, enum bpdisp disposition
,
9019 int thread
, int task
, int ignore_count
,
9020 const struct breakpoint_ops
*ops
, int from_tty
,
9021 int enabled
, int internal
, unsigned flags
)
9023 if (canonical
->pre_expanded
)
9024 gdb_assert (canonical
->lsals
.size () == 1);
9026 for (const auto &lsal
: canonical
->lsals
)
9028 /* Note that 'location' can be NULL in the case of a plain
9029 'break', without arguments. */
9030 event_location_up location
9031 = (canonical
->location
!= NULL
9032 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9033 gdb::unique_xmalloc_ptr
<char> filter_string
9034 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9036 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9037 std::move (location
),
9038 std::move (filter_string
),
9039 std::move (cond_string
),
9040 std::move (extra_string
),
9042 thread
, task
, ignore_count
, ops
,
9043 from_tty
, enabled
, internal
, flags
,
9044 canonical
->special_display
);
9048 /* Parse LOCATION which is assumed to be a SAL specification possibly
9049 followed by conditionals. On return, SALS contains an array of SAL
9050 addresses found. LOCATION points to the end of the SAL (for
9051 linespec locations).
9053 The array and the line spec strings are allocated on the heap, it is
9054 the caller's responsibility to free them. */
9057 parse_breakpoint_sals (struct event_location
*location
,
9058 struct linespec_result
*canonical
)
9060 struct symtab_and_line cursal
;
9062 if (event_location_type (location
) == LINESPEC_LOCATION
)
9064 const char *spec
= get_linespec_location (location
)->spec_string
;
9068 /* The last displayed codepoint, if it's valid, is our default
9069 breakpoint address. */
9070 if (last_displayed_sal_is_valid ())
9072 /* Set sal's pspace, pc, symtab, and line to the values
9073 corresponding to the last call to print_frame_info.
9074 Be sure to reinitialize LINE with NOTCURRENT == 0
9075 as the breakpoint line number is inappropriate otherwise.
9076 find_pc_line would adjust PC, re-set it back. */
9077 symtab_and_line sal
= get_last_displayed_sal ();
9078 CORE_ADDR pc
= sal
.pc
;
9080 sal
= find_pc_line (pc
, 0);
9082 /* "break" without arguments is equivalent to "break *PC"
9083 where PC is the last displayed codepoint's address. So
9084 make sure to set sal.explicit_pc to prevent GDB from
9085 trying to expand the list of sals to include all other
9086 instances with the same symtab and line. */
9088 sal
.explicit_pc
= 1;
9090 struct linespec_sals lsal
;
9092 lsal
.canonical
= NULL
;
9094 canonical
->lsals
.push_back (std::move (lsal
));
9098 error (_("No default breakpoint address now."));
9102 /* Force almost all breakpoints to be in terms of the
9103 current_source_symtab (which is decode_line_1's default).
9104 This should produce the results we want almost all of the
9105 time while leaving default_breakpoint_* alone.
9107 ObjC: However, don't match an Objective-C method name which
9108 may have a '+' or '-' succeeded by a '['. */
9109 cursal
= get_current_source_symtab_and_line ();
9110 if (last_displayed_sal_is_valid ())
9112 const char *spec
= NULL
;
9114 if (event_location_type (location
) == LINESPEC_LOCATION
)
9115 spec
= get_linespec_location (location
)->spec_string
;
9119 && strchr ("+-", spec
[0]) != NULL
9122 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9123 get_last_displayed_symtab (),
9124 get_last_displayed_line (),
9125 canonical
, NULL
, NULL
);
9130 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9131 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9135 /* Convert each SAL into a real PC. Verify that the PC can be
9136 inserted as a breakpoint. If it can't throw an error. */
9139 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9141 for (auto &sal
: sals
)
9142 resolve_sal_pc (&sal
);
9145 /* Fast tracepoints may have restrictions on valid locations. For
9146 instance, a fast tracepoint using a jump instead of a trap will
9147 likely have to overwrite more bytes than a trap would, and so can
9148 only be placed where the instruction is longer than the jump, or a
9149 multi-instruction sequence does not have a jump into the middle of
9153 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9154 gdb::array_view
<const symtab_and_line
> sals
)
9156 for (const auto &sal
: sals
)
9158 struct gdbarch
*sarch
;
9160 sarch
= get_sal_arch (sal
);
9161 /* We fall back to GDBARCH if there is no architecture
9162 associated with SAL. */
9166 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9167 error (_("May not have a fast tracepoint at %s%s"),
9168 paddress (sarch
, sal
.pc
), msg
.c_str ());
9172 /* Given TOK, a string specification of condition and thread, as
9173 accepted by the 'break' command, extract the condition
9174 string and thread number and set *COND_STRING and *THREAD.
9175 PC identifies the context at which the condition should be parsed.
9176 If no condition is found, *COND_STRING is set to NULL.
9177 If no thread is found, *THREAD is set to -1. */
9180 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9181 char **cond_string
, int *thread
, int *task
,
9184 *cond_string
= NULL
;
9192 const char *end_tok
;
9194 const char *cond_start
= NULL
;
9195 const char *cond_end
= NULL
;
9197 tok
= skip_spaces (tok
);
9199 if ((*tok
== '"' || *tok
== ',') && rest
)
9201 *rest
= savestring (tok
, strlen (tok
));
9205 end_tok
= skip_to_space (tok
);
9207 toklen
= end_tok
- tok
;
9209 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9211 tok
= cond_start
= end_tok
+ 1;
9214 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9216 catch (const gdb_exception_error
&)
9221 tok
= tok
+ strlen (tok
);
9224 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9226 else if (toklen
>= 1 && strncmp (tok
, "-force-condition", toklen
) == 0)
9228 tok
= cond_start
= end_tok
+ 1;
9231 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9234 struct thread_info
*thr
;
9237 thr
= parse_thread_id (tok
, &tmptok
);
9239 error (_("Junk after thread keyword."));
9240 *thread
= thr
->global_num
;
9243 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9248 *task
= strtol (tok
, &tmptok
, 0);
9250 error (_("Junk after task keyword."));
9251 if (!valid_task_id (*task
))
9252 error (_("Unknown task %d."), *task
);
9257 *rest
= savestring (tok
, strlen (tok
));
9261 error (_("Junk at end of arguments."));
9265 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
9266 succeeds. The parsed values are written to COND_STRING, THREAD,
9267 TASK, and REST. See the comment of 'find_condition_and_thread'
9268 for the description of these parameters and INPUT. */
9271 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
9272 const char *input
, char **cond_string
,
9273 int *thread
, int *task
, char **rest
)
9275 int num_failures
= 0;
9276 for (auto &sal
: sals
)
9278 char *cond
= nullptr;
9281 char *remaining
= nullptr;
9283 /* Here we want to parse 'arg' to separate condition from thread
9284 number. But because parsing happens in a context and the
9285 contexts of sals might be different, try each until there is
9286 success. Finding one successful parse is sufficient for our
9287 goal. When setting the breakpoint we'll re-parse the
9288 condition in the context of each sal. */
9291 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
9292 &task_id
, &remaining
);
9293 *cond_string
= cond
;
9294 *thread
= thread_id
;
9299 catch (const gdb_exception_error
&e
)
9302 /* If no sal remains, do not continue. */
9303 if (num_failures
== sals
.size ())
9309 /* Decode a static tracepoint marker spec. */
9311 static std::vector
<symtab_and_line
>
9312 decode_static_tracepoint_spec (const char **arg_p
)
9314 const char *p
= &(*arg_p
)[3];
9317 p
= skip_spaces (p
);
9319 endp
= skip_to_space (p
);
9321 std::string
marker_str (p
, endp
- p
);
9323 std::vector
<static_tracepoint_marker
> markers
9324 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9325 if (markers
.empty ())
9326 error (_("No known static tracepoint marker named %s"),
9327 marker_str
.c_str ());
9329 std::vector
<symtab_and_line
> sals
;
9330 sals
.reserve (markers
.size ());
9332 for (const static_tracepoint_marker
&marker
: markers
)
9334 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9335 sal
.pc
= marker
.address
;
9336 sals
.push_back (sal
);
9343 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9344 according to IS_TRACEPOINT. */
9346 static const struct breakpoint_ops
*
9347 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
9352 if (location_type
== PROBE_LOCATION
)
9353 return &tracepoint_probe_breakpoint_ops
;
9355 return &tracepoint_breakpoint_ops
;
9359 if (location_type
== PROBE_LOCATION
)
9360 return &bkpt_probe_breakpoint_ops
;
9362 return &bkpt_breakpoint_ops
;
9366 /* See breakpoint.h. */
9368 const struct breakpoint_ops
*
9369 breakpoint_ops_for_event_location (const struct event_location
*location
,
9372 if (location
!= nullptr)
9373 return breakpoint_ops_for_event_location_type
9374 (event_location_type (location
), is_tracepoint
);
9375 return is_tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
9378 /* See breakpoint.h. */
9381 create_breakpoint (struct gdbarch
*gdbarch
,
9382 struct event_location
*location
,
9383 const char *cond_string
,
9384 int thread
, const char *extra_string
,
9386 int tempflag
, enum bptype type_wanted
,
9388 enum auto_boolean pending_break_support
,
9389 const struct breakpoint_ops
*ops
,
9390 int from_tty
, int enabled
, int internal
,
9393 struct linespec_result canonical
;
9396 int prev_bkpt_count
= breakpoint_count
;
9398 gdb_assert (ops
!= NULL
);
9400 /* If extra_string isn't useful, set it to NULL. */
9401 if (extra_string
!= NULL
&& *extra_string
== '\0')
9402 extra_string
= NULL
;
9406 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9408 catch (const gdb_exception_error
&e
)
9410 /* If caller is interested in rc value from parse, set
9412 if (e
.error
== NOT_FOUND_ERROR
)
9414 /* If pending breakpoint support is turned off, throw
9417 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9420 exception_print (gdb_stderr
, e
);
9422 /* If pending breakpoint support is auto query and the user
9423 selects no, then simply return the error code. */
9424 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9425 && !nquery (_("Make %s pending on future shared library load? "),
9426 bptype_string (type_wanted
)))
9429 /* At this point, either the user was queried about setting
9430 a pending breakpoint and selected yes, or pending
9431 breakpoint behavior is on and thus a pending breakpoint
9432 is defaulted on behalf of the user. */
9439 if (!pending
&& canonical
.lsals
.empty ())
9442 /* Resolve all line numbers to PC's and verify that the addresses
9443 are ok for the target. */
9446 for (auto &lsal
: canonical
.lsals
)
9447 breakpoint_sals_to_pc (lsal
.sals
);
9450 /* Fast tracepoints may have additional restrictions on location. */
9451 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9453 for (const auto &lsal
: canonical
.lsals
)
9454 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9457 /* Verify that condition can be parsed, before setting any
9458 breakpoints. Allocate a separate condition expression for each
9462 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9463 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9470 const linespec_sals
&lsal
= canonical
.lsals
[0];
9472 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9473 &cond
, &thread
, &task
, &rest
);
9474 cond_string_copy
.reset (cond
);
9475 extra_string_copy
.reset (rest
);
9479 if (type_wanted
!= bp_dprintf
9480 && extra_string
!= NULL
&& *extra_string
!= '\0')
9481 error (_("Garbage '%s' at end of location"), extra_string
);
9483 /* Create a private copy of condition string. */
9485 cond_string_copy
.reset (xstrdup (cond_string
));
9486 /* Create a private copy of any extra string. */
9488 extra_string_copy
.reset (xstrdup (extra_string
));
9491 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9492 std::move (cond_string_copy
),
9493 std::move (extra_string_copy
),
9495 tempflag
? disp_del
: disp_donttouch
,
9496 thread
, task
, ignore_count
, ops
,
9497 from_tty
, enabled
, internal
, flags
);
9501 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9503 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9504 b
->location
= copy_event_location (location
);
9507 b
->cond_string
= NULL
;
9510 /* Create a private copy of condition string. */
9511 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9515 /* Create a private copy of any extra string. */
9516 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9517 b
->ignore_count
= ignore_count
;
9518 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9519 b
->condition_not_parsed
= 1;
9520 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9521 if ((type_wanted
!= bp_breakpoint
9522 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9523 b
->pspace
= current_program_space
;
9525 install_breakpoint (internal
, std::move (b
), 0);
9528 if (canonical
.lsals
.size () > 1)
9530 warning (_("Multiple breakpoints were set.\nUse the "
9531 "\"delete\" command to delete unwanted breakpoints."));
9532 prev_breakpoint_count
= prev_bkpt_count
;
9535 update_global_location_list (UGLL_MAY_INSERT
);
9540 /* Set a breakpoint.
9541 ARG is a string describing breakpoint address,
9542 condition, and thread.
9543 FLAG specifies if a breakpoint is hardware on,
9544 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9548 break_command_1 (const char *arg
, int flag
, int from_tty
)
9550 int tempflag
= flag
& BP_TEMPFLAG
;
9551 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9552 ? bp_hardware_breakpoint
9555 event_location_up location
= string_to_event_location (&arg
, current_language
);
9556 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9557 (location
.get (), false /* is_tracepoint */);
9559 create_breakpoint (get_current_arch (),
9561 NULL
, 0, arg
, 1 /* parse arg */,
9562 tempflag
, type_wanted
,
9563 0 /* Ignore count */,
9564 pending_break_support
,
9572 /* Helper function for break_command_1 and disassemble_command. */
9575 resolve_sal_pc (struct symtab_and_line
*sal
)
9579 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9581 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9582 error (_("No line %d in file \"%s\"."),
9583 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9586 /* If this SAL corresponds to a breakpoint inserted using a line
9587 number, then skip the function prologue if necessary. */
9588 if (sal
->explicit_line
)
9589 skip_prologue_sal (sal
);
9592 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9594 const struct blockvector
*bv
;
9595 const struct block
*b
;
9598 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9599 SYMTAB_COMPUNIT (sal
->symtab
));
9602 sym
= block_linkage_function (b
);
9605 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9606 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9611 /* It really is worthwhile to have the section, so we'll
9612 just have to look harder. This case can be executed
9613 if we have line numbers but no functions (as can
9614 happen in assembly source). */
9616 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9617 switch_to_program_space_and_thread (sal
->pspace
);
9619 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9621 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9628 break_command (const char *arg
, int from_tty
)
9630 break_command_1 (arg
, 0, from_tty
);
9634 tbreak_command (const char *arg
, int from_tty
)
9636 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9640 hbreak_command (const char *arg
, int from_tty
)
9642 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9646 thbreak_command (const char *arg
, int from_tty
)
9648 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9652 stop_command (const char *arg
, int from_tty
)
9654 printf_filtered (_("Specify the type of breakpoint to set.\n\
9655 Usage: stop in <function | address>\n\
9656 stop at <line>\n"));
9660 stopin_command (const char *arg
, int from_tty
)
9666 else if (*arg
!= '*')
9668 const char *argptr
= arg
;
9671 /* Look for a ':'. If this is a line number specification, then
9672 say it is bad, otherwise, it should be an address or
9673 function/method name. */
9674 while (*argptr
&& !hasColon
)
9676 hasColon
= (*argptr
== ':');
9681 badInput
= (*argptr
!= ':'); /* Not a class::method */
9683 badInput
= isdigit (*arg
); /* a simple line number */
9687 printf_filtered (_("Usage: stop in <function | address>\n"));
9689 break_command_1 (arg
, 0, from_tty
);
9693 stopat_command (const char *arg
, int from_tty
)
9697 if (arg
== NULL
|| *arg
== '*') /* no line number */
9701 const char *argptr
= arg
;
9704 /* Look for a ':'. If there is a '::' then get out, otherwise
9705 it is probably a line number. */
9706 while (*argptr
&& !hasColon
)
9708 hasColon
= (*argptr
== ':');
9713 badInput
= (*argptr
== ':'); /* we have class::method */
9715 badInput
= !isdigit (*arg
); /* not a line number */
9719 printf_filtered (_("Usage: stop at LINE\n"));
9721 break_command_1 (arg
, 0, from_tty
);
9724 /* The dynamic printf command is mostly like a regular breakpoint, but
9725 with a prewired command list consisting of a single output command,
9726 built from extra arguments supplied on the dprintf command
9730 dprintf_command (const char *arg
, int from_tty
)
9732 event_location_up location
= string_to_event_location (&arg
, current_language
);
9734 /* If non-NULL, ARG should have been advanced past the location;
9735 the next character must be ','. */
9738 if (arg
[0] != ',' || arg
[1] == '\0')
9739 error (_("Format string required"));
9742 /* Skip the comma. */
9747 create_breakpoint (get_current_arch (),
9749 NULL
, 0, arg
, 1 /* parse arg */,
9751 0 /* Ignore count */,
9752 pending_break_support
,
9753 &dprintf_breakpoint_ops
,
9761 agent_printf_command (const char *arg
, int from_tty
)
9763 error (_("May only run agent-printf on the target"));
9766 /* Implement the "breakpoint_hit" breakpoint_ops method for
9767 ranged breakpoints. */
9770 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9771 const address_space
*aspace
,
9773 const struct target_waitstatus
*ws
)
9775 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9776 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9779 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9780 bl
->length
, aspace
, bp_addr
);
9783 /* Implement the "resources_needed" breakpoint_ops method for
9784 ranged breakpoints. */
9787 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9789 return target_ranged_break_num_registers ();
9792 /* Implement the "print_it" breakpoint_ops method for
9793 ranged breakpoints. */
9795 static enum print_stop_action
9796 print_it_ranged_breakpoint (bpstat bs
)
9798 struct breakpoint
*b
= bs
->breakpoint_at
;
9799 struct bp_location
*bl
= b
->loc
;
9800 struct ui_out
*uiout
= current_uiout
;
9802 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9804 /* Ranged breakpoints have only one location. */
9805 gdb_assert (bl
&& bl
->next
== NULL
);
9807 annotate_breakpoint (b
->number
);
9809 maybe_print_thread_hit_breakpoint (uiout
);
9811 if (b
->disposition
== disp_del
)
9812 uiout
->text ("Temporary ranged breakpoint ");
9814 uiout
->text ("Ranged breakpoint ");
9815 if (uiout
->is_mi_like_p ())
9817 uiout
->field_string ("reason",
9818 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9819 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9821 uiout
->field_signed ("bkptno", b
->number
);
9824 return PRINT_SRC_AND_LOC
;
9827 /* Implement the "print_one" breakpoint_ops method for
9828 ranged breakpoints. */
9831 print_one_ranged_breakpoint (struct breakpoint
*b
,
9832 struct bp_location
**last_loc
)
9834 struct bp_location
*bl
= b
->loc
;
9835 struct value_print_options opts
;
9836 struct ui_out
*uiout
= current_uiout
;
9838 /* Ranged breakpoints have only one location. */
9839 gdb_assert (bl
&& bl
->next
== NULL
);
9841 get_user_print_options (&opts
);
9843 if (opts
.addressprint
)
9844 /* We don't print the address range here, it will be printed later
9845 by print_one_detail_ranged_breakpoint. */
9846 uiout
->field_skip ("addr");
9848 print_breakpoint_location (b
, bl
);
9852 /* Implement the "print_one_detail" breakpoint_ops method for
9853 ranged breakpoints. */
9856 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9857 struct ui_out
*uiout
)
9859 CORE_ADDR address_start
, address_end
;
9860 struct bp_location
*bl
= b
->loc
;
9865 address_start
= bl
->address
;
9866 address_end
= address_start
+ bl
->length
- 1;
9868 uiout
->text ("\taddress range: ");
9869 stb
.printf ("[%s, %s]",
9870 print_core_address (bl
->gdbarch
, address_start
),
9871 print_core_address (bl
->gdbarch
, address_end
));
9872 uiout
->field_stream ("addr", stb
);
9876 /* Implement the "print_mention" breakpoint_ops method for
9877 ranged breakpoints. */
9880 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9882 struct bp_location
*bl
= b
->loc
;
9883 struct ui_out
*uiout
= current_uiout
;
9886 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9888 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9889 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9890 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9893 /* Implement the "print_recreate" breakpoint_ops method for
9894 ranged breakpoints. */
9897 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9899 fprintf_unfiltered (fp
, "break-range %s, %s",
9900 event_location_to_string (b
->location
.get ()),
9901 event_location_to_string (b
->location_range_end
.get ()));
9902 print_recreate_thread (b
, fp
);
9905 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9907 static struct breakpoint_ops ranged_breakpoint_ops
;
9909 /* Find the address where the end of the breakpoint range should be
9910 placed, given the SAL of the end of the range. This is so that if
9911 the user provides a line number, the end of the range is set to the
9912 last instruction of the given line. */
9915 find_breakpoint_range_end (struct symtab_and_line sal
)
9919 /* If the user provided a PC value, use it. Otherwise,
9920 find the address of the end of the given location. */
9921 if (sal
.explicit_pc
)
9928 ret
= find_line_pc_range (sal
, &start
, &end
);
9930 error (_("Could not find location of the end of the range."));
9932 /* find_line_pc_range returns the start of the next line. */
9939 /* Implement the "break-range" CLI command. */
9942 break_range_command (const char *arg
, int from_tty
)
9944 const char *arg_start
;
9945 struct linespec_result canonical_start
, canonical_end
;
9946 int bp_count
, can_use_bp
, length
;
9948 struct breakpoint
*b
;
9950 /* We don't support software ranged breakpoints. */
9951 if (target_ranged_break_num_registers () < 0)
9952 error (_("This target does not support hardware ranged breakpoints."));
9954 bp_count
= hw_breakpoint_used_count ();
9955 bp_count
+= target_ranged_break_num_registers ();
9956 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9959 error (_("Hardware breakpoints used exceeds limit."));
9961 arg
= skip_spaces (arg
);
9962 if (arg
== NULL
|| arg
[0] == '\0')
9963 error(_("No address range specified."));
9966 event_location_up start_location
= string_to_event_location (&arg
,
9968 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9971 error (_("Too few arguments."));
9972 else if (canonical_start
.lsals
.empty ())
9973 error (_("Could not find location of the beginning of the range."));
9975 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9977 if (canonical_start
.lsals
.size () > 1
9978 || lsal_start
.sals
.size () != 1)
9979 error (_("Cannot create a ranged breakpoint with multiple locations."));
9981 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9982 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9984 arg
++; /* Skip the comma. */
9985 arg
= skip_spaces (arg
);
9987 /* Parse the end location. */
9991 /* We call decode_line_full directly here instead of using
9992 parse_breakpoint_sals because we need to specify the start location's
9993 symtab and line as the default symtab and line for the end of the
9994 range. This makes it possible to have ranges like "foo.c:27, +14",
9995 where +14 means 14 lines from the start location. */
9996 event_location_up end_location
= string_to_event_location (&arg
,
9998 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9999 sal_start
.symtab
, sal_start
.line
,
10000 &canonical_end
, NULL
, NULL
);
10002 if (canonical_end
.lsals
.empty ())
10003 error (_("Could not find location of the end of the range."));
10005 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10006 if (canonical_end
.lsals
.size () > 1
10007 || lsal_end
.sals
.size () != 1)
10008 error (_("Cannot create a ranged breakpoint with multiple locations."));
10010 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10012 end
= find_breakpoint_range_end (sal_end
);
10013 if (sal_start
.pc
> end
)
10014 error (_("Invalid address range, end precedes start."));
10016 length
= end
- sal_start
.pc
+ 1;
10018 /* Length overflowed. */
10019 error (_("Address range too large."));
10020 else if (length
== 1)
10022 /* This range is simple enough to be handled by
10023 the `hbreak' command. */
10024 hbreak_command (&addr_string_start
[0], 1);
10029 /* Now set up the breakpoint. */
10030 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10031 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10032 set_breakpoint_count (breakpoint_count
+ 1);
10033 b
->number
= breakpoint_count
;
10034 b
->disposition
= disp_donttouch
;
10035 b
->location
= std::move (start_location
);
10036 b
->location_range_end
= std::move (end_location
);
10037 b
->loc
->length
= length
;
10040 gdb::observers::breakpoint_created
.notify (b
);
10041 update_global_location_list (UGLL_MAY_INSERT
);
10044 /* Return non-zero if EXP is verified as constant. Returned zero
10045 means EXP is variable. Also the constant detection may fail for
10046 some constant expressions and in such case still falsely return
10050 watchpoint_exp_is_const (const struct expression
*exp
)
10052 int i
= exp
->nelts
;
10058 /* We are only interested in the descriptor of each element. */
10059 operator_length (exp
, i
, &oplenp
, &argsp
);
10062 switch (exp
->elts
[i
].opcode
)
10072 case BINOP_LOGICAL_AND
:
10073 case BINOP_LOGICAL_OR
:
10074 case BINOP_BITWISE_AND
:
10075 case BINOP_BITWISE_IOR
:
10076 case BINOP_BITWISE_XOR
:
10078 case BINOP_NOTEQUAL
:
10104 case OP_OBJC_NSSTRING
:
10107 case UNOP_LOGICAL_NOT
:
10108 case UNOP_COMPLEMENT
:
10113 case UNOP_CAST_TYPE
:
10114 case UNOP_REINTERPRET_CAST
:
10115 case UNOP_DYNAMIC_CAST
:
10116 /* Unary, binary and ternary operators: We have to check
10117 their operands. If they are constant, then so is the
10118 result of that operation. For instance, if A and B are
10119 determined to be constants, then so is "A + B".
10121 UNOP_IND is one exception to the rule above, because the
10122 value of *ADDR is not necessarily a constant, even when
10127 /* Check whether the associated symbol is a constant.
10129 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10130 possible that a buggy compiler could mark a variable as
10131 constant even when it is not, and TYPE_CONST would return
10132 true in this case, while SYMBOL_CLASS wouldn't.
10134 We also have to check for function symbols because they
10135 are always constant. */
10137 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10139 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10140 && SYMBOL_CLASS (s
) != LOC_CONST
10141 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10146 /* The default action is to return 0 because we are using
10147 the optimistic approach here: If we don't know something,
10148 then it is not a constant. */
10157 /* Watchpoint destructor. */
10159 watchpoint::~watchpoint ()
10161 xfree (this->exp_string
);
10162 xfree (this->exp_string_reparse
);
10165 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10168 re_set_watchpoint (struct breakpoint
*b
)
10170 struct watchpoint
*w
= (struct watchpoint
*) b
;
10172 /* Watchpoint can be either on expression using entirely global
10173 variables, or it can be on local variables.
10175 Watchpoints of the first kind are never auto-deleted, and even
10176 persist across program restarts. Since they can use variables
10177 from shared libraries, we need to reparse expression as libraries
10178 are loaded and unloaded.
10180 Watchpoints on local variables can also change meaning as result
10181 of solib event. For example, if a watchpoint uses both a local
10182 and a global variables in expression, it's a local watchpoint,
10183 but unloading of a shared library will make the expression
10184 invalid. This is not a very common use case, but we still
10185 re-evaluate expression, to avoid surprises to the user.
10187 Note that for local watchpoints, we re-evaluate it only if
10188 watchpoints frame id is still valid. If it's not, it means the
10189 watchpoint is out of scope and will be deleted soon. In fact,
10190 I'm not sure we'll ever be called in this case.
10192 If a local watchpoint's frame id is still valid, then
10193 w->exp_valid_block is likewise valid, and we can safely use it.
10195 Don't do anything about disabled watchpoints, since they will be
10196 reevaluated again when enabled. */
10197 update_watchpoint (w
, 1 /* reparse */);
10200 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10203 insert_watchpoint (struct bp_location
*bl
)
10205 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10206 int length
= w
->exact
? 1 : bl
->length
;
10208 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10209 w
->cond_exp
.get ());
10212 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10215 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10217 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10218 int length
= w
->exact
? 1 : bl
->length
;
10220 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10221 w
->cond_exp
.get ());
10225 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10226 const address_space
*aspace
, CORE_ADDR bp_addr
,
10227 const struct target_waitstatus
*ws
)
10229 struct breakpoint
*b
= bl
->owner
;
10230 struct watchpoint
*w
= (struct watchpoint
*) b
;
10232 /* Continuable hardware watchpoints are treated as non-existent if the
10233 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10234 some data address). Otherwise gdb won't stop on a break instruction
10235 in the code (not from a breakpoint) when a hardware watchpoint has
10236 been defined. Also skip watchpoints which we know did not trigger
10237 (did not match the data address). */
10238 if (is_hardware_watchpoint (b
)
10239 && w
->watchpoint_triggered
== watch_triggered_no
)
10246 check_status_watchpoint (bpstat bs
)
10248 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10250 bpstat_check_watchpoint (bs
);
10253 /* Implement the "resources_needed" breakpoint_ops method for
10254 hardware watchpoints. */
10257 resources_needed_watchpoint (const struct bp_location
*bl
)
10259 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10260 int length
= w
->exact
? 1 : bl
->length
;
10262 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10265 /* Implement the "works_in_software_mode" breakpoint_ops method for
10266 hardware watchpoints. */
10269 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10271 /* Read and access watchpoints only work with hardware support. */
10272 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10275 static enum print_stop_action
10276 print_it_watchpoint (bpstat bs
)
10278 struct breakpoint
*b
;
10279 enum print_stop_action result
;
10280 struct watchpoint
*w
;
10281 struct ui_out
*uiout
= current_uiout
;
10283 gdb_assert (bs
->bp_location_at
!= NULL
);
10285 b
= bs
->breakpoint_at
;
10286 w
= (struct watchpoint
*) b
;
10288 annotate_watchpoint (b
->number
);
10289 maybe_print_thread_hit_breakpoint (uiout
);
10293 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10296 case bp_watchpoint
:
10297 case bp_hardware_watchpoint
:
10298 if (uiout
->is_mi_like_p ())
10299 uiout
->field_string
10300 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10302 tuple_emitter
.emplace (uiout
, "value");
10303 uiout
->text ("\nOld value = ");
10304 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10305 uiout
->field_stream ("old", stb
);
10306 uiout
->text ("\nNew value = ");
10307 watchpoint_value_print (w
->val
.get (), &stb
);
10308 uiout
->field_stream ("new", stb
);
10309 uiout
->text ("\n");
10310 /* More than one watchpoint may have been triggered. */
10311 result
= PRINT_UNKNOWN
;
10314 case bp_read_watchpoint
:
10315 if (uiout
->is_mi_like_p ())
10316 uiout
->field_string
10317 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10319 tuple_emitter
.emplace (uiout
, "value");
10320 uiout
->text ("\nValue = ");
10321 watchpoint_value_print (w
->val
.get (), &stb
);
10322 uiout
->field_stream ("value", stb
);
10323 uiout
->text ("\n");
10324 result
= PRINT_UNKNOWN
;
10327 case bp_access_watchpoint
:
10328 if (bs
->old_val
!= NULL
)
10330 if (uiout
->is_mi_like_p ())
10331 uiout
->field_string
10333 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10335 tuple_emitter
.emplace (uiout
, "value");
10336 uiout
->text ("\nOld value = ");
10337 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10338 uiout
->field_stream ("old", stb
);
10339 uiout
->text ("\nNew value = ");
10344 if (uiout
->is_mi_like_p ())
10345 uiout
->field_string
10347 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10348 tuple_emitter
.emplace (uiout
, "value");
10349 uiout
->text ("\nValue = ");
10351 watchpoint_value_print (w
->val
.get (), &stb
);
10352 uiout
->field_stream ("new", stb
);
10353 uiout
->text ("\n");
10354 result
= PRINT_UNKNOWN
;
10357 result
= PRINT_UNKNOWN
;
10363 /* Implement the "print_mention" breakpoint_ops method for hardware
10367 print_mention_watchpoint (struct breakpoint
*b
)
10369 struct watchpoint
*w
= (struct watchpoint
*) b
;
10370 struct ui_out
*uiout
= current_uiout
;
10371 const char *tuple_name
;
10375 case bp_watchpoint
:
10376 uiout
->text ("Watchpoint ");
10377 tuple_name
= "wpt";
10379 case bp_hardware_watchpoint
:
10380 uiout
->text ("Hardware watchpoint ");
10381 tuple_name
= "wpt";
10383 case bp_read_watchpoint
:
10384 uiout
->text ("Hardware read watchpoint ");
10385 tuple_name
= "hw-rwpt";
10387 case bp_access_watchpoint
:
10388 uiout
->text ("Hardware access (read/write) watchpoint ");
10389 tuple_name
= "hw-awpt";
10392 internal_error (__FILE__
, __LINE__
,
10393 _("Invalid hardware watchpoint type."));
10396 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10397 uiout
->field_signed ("number", b
->number
);
10398 uiout
->text (": ");
10399 uiout
->field_string ("exp", w
->exp_string
);
10402 /* Implement the "print_recreate" breakpoint_ops method for
10406 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10408 struct watchpoint
*w
= (struct watchpoint
*) b
;
10412 case bp_watchpoint
:
10413 case bp_hardware_watchpoint
:
10414 fprintf_unfiltered (fp
, "watch");
10416 case bp_read_watchpoint
:
10417 fprintf_unfiltered (fp
, "rwatch");
10419 case bp_access_watchpoint
:
10420 fprintf_unfiltered (fp
, "awatch");
10423 internal_error (__FILE__
, __LINE__
,
10424 _("Invalid watchpoint type."));
10427 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10428 print_recreate_thread (b
, fp
);
10431 /* Implement the "explains_signal" breakpoint_ops method for
10435 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10437 /* A software watchpoint cannot cause a signal other than
10438 GDB_SIGNAL_TRAP. */
10439 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10445 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10447 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10449 /* Implement the "insert" breakpoint_ops method for
10450 masked hardware watchpoints. */
10453 insert_masked_watchpoint (struct bp_location
*bl
)
10455 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10457 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10458 bl
->watchpoint_type
);
10461 /* Implement the "remove" breakpoint_ops method for
10462 masked hardware watchpoints. */
10465 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10467 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10469 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10470 bl
->watchpoint_type
);
10473 /* Implement the "resources_needed" breakpoint_ops method for
10474 masked hardware watchpoints. */
10477 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10479 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10481 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10484 /* Implement the "works_in_software_mode" breakpoint_ops method for
10485 masked hardware watchpoints. */
10488 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10493 /* Implement the "print_it" breakpoint_ops method for
10494 masked hardware watchpoints. */
10496 static enum print_stop_action
10497 print_it_masked_watchpoint (bpstat bs
)
10499 struct breakpoint
*b
= bs
->breakpoint_at
;
10500 struct ui_out
*uiout
= current_uiout
;
10502 /* Masked watchpoints have only one location. */
10503 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10505 annotate_watchpoint (b
->number
);
10506 maybe_print_thread_hit_breakpoint (uiout
);
10510 case bp_hardware_watchpoint
:
10511 if (uiout
->is_mi_like_p ())
10512 uiout
->field_string
10513 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10516 case bp_read_watchpoint
:
10517 if (uiout
->is_mi_like_p ())
10518 uiout
->field_string
10519 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10522 case bp_access_watchpoint
:
10523 if (uiout
->is_mi_like_p ())
10524 uiout
->field_string
10526 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10529 internal_error (__FILE__
, __LINE__
,
10530 _("Invalid hardware watchpoint type."));
10534 uiout
->text (_("\n\
10535 Check the underlying instruction at PC for the memory\n\
10536 address and value which triggered this watchpoint.\n"));
10537 uiout
->text ("\n");
10539 /* More than one watchpoint may have been triggered. */
10540 return PRINT_UNKNOWN
;
10543 /* Implement the "print_one_detail" breakpoint_ops method for
10544 masked hardware watchpoints. */
10547 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10548 struct ui_out
*uiout
)
10550 struct watchpoint
*w
= (struct watchpoint
*) b
;
10552 /* Masked watchpoints have only one location. */
10553 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10555 uiout
->text ("\tmask ");
10556 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10557 uiout
->text ("\n");
10560 /* Implement the "print_mention" breakpoint_ops method for
10561 masked hardware watchpoints. */
10564 print_mention_masked_watchpoint (struct breakpoint
*b
)
10566 struct watchpoint
*w
= (struct watchpoint
*) b
;
10567 struct ui_out
*uiout
= current_uiout
;
10568 const char *tuple_name
;
10572 case bp_hardware_watchpoint
:
10573 uiout
->text ("Masked hardware watchpoint ");
10574 tuple_name
= "wpt";
10576 case bp_read_watchpoint
:
10577 uiout
->text ("Masked hardware read watchpoint ");
10578 tuple_name
= "hw-rwpt";
10580 case bp_access_watchpoint
:
10581 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10582 tuple_name
= "hw-awpt";
10585 internal_error (__FILE__
, __LINE__
,
10586 _("Invalid hardware watchpoint type."));
10589 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10590 uiout
->field_signed ("number", b
->number
);
10591 uiout
->text (": ");
10592 uiout
->field_string ("exp", w
->exp_string
);
10595 /* Implement the "print_recreate" breakpoint_ops method for
10596 masked hardware watchpoints. */
10599 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10601 struct watchpoint
*w
= (struct watchpoint
*) b
;
10605 case bp_hardware_watchpoint
:
10606 fprintf_unfiltered (fp
, "watch");
10608 case bp_read_watchpoint
:
10609 fprintf_unfiltered (fp
, "rwatch");
10611 case bp_access_watchpoint
:
10612 fprintf_unfiltered (fp
, "awatch");
10615 internal_error (__FILE__
, __LINE__
,
10616 _("Invalid hardware watchpoint type."));
10619 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
,
10620 phex (w
->hw_wp_mask
, sizeof (CORE_ADDR
)));
10621 print_recreate_thread (b
, fp
);
10624 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10626 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10628 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10631 is_masked_watchpoint (const struct breakpoint
*b
)
10633 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10636 /* accessflag: hw_write: watch write,
10637 hw_read: watch read,
10638 hw_access: watch access (read or write) */
10640 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10641 int just_location
, int internal
)
10643 struct breakpoint
*scope_breakpoint
= NULL
;
10644 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10645 struct value
*result
;
10646 int saved_bitpos
= 0, saved_bitsize
= 0;
10647 const char *exp_start
= NULL
;
10648 const char *exp_end
= NULL
;
10649 const char *tok
, *end_tok
;
10651 const char *cond_start
= NULL
;
10652 const char *cond_end
= NULL
;
10653 enum bptype bp_type
;
10656 /* Flag to indicate whether we are going to use masks for
10657 the hardware watchpoint. */
10659 CORE_ADDR mask
= 0;
10661 /* Make sure that we actually have parameters to parse. */
10662 if (arg
!= NULL
&& arg
[0] != '\0')
10664 const char *value_start
;
10666 exp_end
= arg
+ strlen (arg
);
10668 /* Look for "parameter value" pairs at the end
10669 of the arguments string. */
10670 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10672 /* Skip whitespace at the end of the argument list. */
10673 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10676 /* Find the beginning of the last token.
10677 This is the value of the parameter. */
10678 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10680 value_start
= tok
+ 1;
10682 /* Skip whitespace. */
10683 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10688 /* Find the beginning of the second to last token.
10689 This is the parameter itself. */
10690 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10693 toklen
= end_tok
- tok
+ 1;
10695 if (toklen
== 6 && startswith (tok
, "thread"))
10697 struct thread_info
*thr
;
10698 /* At this point we've found a "thread" token, which means
10699 the user is trying to set a watchpoint that triggers
10700 only in a specific thread. */
10704 error(_("You can specify only one thread."));
10706 /* Extract the thread ID from the next token. */
10707 thr
= parse_thread_id (value_start
, &endp
);
10709 /* Check if the user provided a valid thread ID. */
10710 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10711 invalid_thread_id_error (value_start
);
10713 thread
= thr
->global_num
;
10715 else if (toklen
== 4 && startswith (tok
, "mask"))
10717 /* We've found a "mask" token, which means the user wants to
10718 create a hardware watchpoint that is going to have the mask
10720 struct value
*mask_value
, *mark
;
10723 error(_("You can specify only one mask."));
10725 use_mask
= just_location
= 1;
10727 mark
= value_mark ();
10728 mask_value
= parse_to_comma_and_eval (&value_start
);
10729 mask
= value_as_address (mask_value
);
10730 value_free_to_mark (mark
);
10733 /* We didn't recognize what we found. We should stop here. */
10736 /* Truncate the string and get rid of the "parameter value" pair before
10737 the arguments string is parsed by the parse_exp_1 function. */
10744 /* Parse the rest of the arguments. From here on out, everything
10745 is in terms of a newly allocated string instead of the original
10747 std::string
expression (arg
, exp_end
- arg
);
10748 exp_start
= arg
= expression
.c_str ();
10749 innermost_block_tracker tracker
;
10750 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10752 /* Remove trailing whitespace from the expression before saving it.
10753 This makes the eventual display of the expression string a bit
10755 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10758 /* Checking if the expression is not constant. */
10759 if (watchpoint_exp_is_const (exp
.get ()))
10763 len
= exp_end
- exp_start
;
10764 while (len
> 0 && isspace (exp_start
[len
- 1]))
10766 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10769 exp_valid_block
= tracker
.block ();
10770 struct value
*mark
= value_mark ();
10771 struct value
*val_as_value
= nullptr;
10772 fetch_subexp_value (exp
.get (), &pc
, &val_as_value
, &result
, NULL
,
10775 if (val_as_value
!= NULL
&& just_location
)
10777 saved_bitpos
= value_bitpos (val_as_value
);
10778 saved_bitsize
= value_bitsize (val_as_value
);
10786 exp_valid_block
= NULL
;
10787 val
= release_value (value_addr (result
));
10788 value_free_to_mark (mark
);
10792 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10795 error (_("This target does not support masked watchpoints."));
10796 else if (ret
== -2)
10797 error (_("Invalid mask or memory region."));
10800 else if (val_as_value
!= NULL
)
10801 val
= release_value (val_as_value
);
10803 tok
= skip_spaces (arg
);
10804 end_tok
= skip_to_space (tok
);
10806 toklen
= end_tok
- tok
;
10807 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10809 tok
= cond_start
= end_tok
+ 1;
10810 innermost_block_tracker if_tracker
;
10811 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10813 /* The watchpoint expression may not be local, but the condition
10814 may still be. E.g.: `watch global if local > 0'. */
10815 cond_exp_valid_block
= if_tracker
.block ();
10820 error (_("Junk at end of command."));
10822 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10824 /* Save this because create_internal_breakpoint below invalidates
10826 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10828 /* If the expression is "local", then set up a "watchpoint scope"
10829 breakpoint at the point where we've left the scope of the watchpoint
10830 expression. Create the scope breakpoint before the watchpoint, so
10831 that we will encounter it first in bpstat_stop_status. */
10832 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10834 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10836 if (frame_id_p (caller_frame_id
))
10838 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10839 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10842 = create_internal_breakpoint (caller_arch
, caller_pc
,
10843 bp_watchpoint_scope
,
10844 &momentary_breakpoint_ops
);
10846 /* create_internal_breakpoint could invalidate WP_FRAME. */
10849 scope_breakpoint
->enable_state
= bp_enabled
;
10851 /* Automatically delete the breakpoint when it hits. */
10852 scope_breakpoint
->disposition
= disp_del
;
10854 /* Only break in the proper frame (help with recursion). */
10855 scope_breakpoint
->frame_id
= caller_frame_id
;
10857 /* Set the address at which we will stop. */
10858 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10859 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10860 scope_breakpoint
->loc
->address
10861 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10862 scope_breakpoint
->loc
->requested_address
,
10863 scope_breakpoint
->type
);
10867 /* Now set up the breakpoint. We create all watchpoints as hardware
10868 watchpoints here even if hardware watchpoints are turned off, a call
10869 to update_watchpoint later in this function will cause the type to
10870 drop back to bp_watchpoint (software watchpoint) if required. */
10872 if (accessflag
== hw_read
)
10873 bp_type
= bp_read_watchpoint
;
10874 else if (accessflag
== hw_access
)
10875 bp_type
= bp_access_watchpoint
;
10877 bp_type
= bp_hardware_watchpoint
;
10879 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10882 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10883 &masked_watchpoint_breakpoint_ops
);
10885 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10886 &watchpoint_breakpoint_ops
);
10887 w
->thread
= thread
;
10888 w
->disposition
= disp_donttouch
;
10889 w
->pspace
= current_program_space
;
10890 w
->exp
= std::move (exp
);
10891 w
->exp_valid_block
= exp_valid_block
;
10892 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10895 struct type
*t
= value_type (val
.get ());
10896 CORE_ADDR addr
= value_as_address (val
.get ());
10898 w
->exp_string_reparse
10899 = current_language
->watch_location_expression (t
, addr
).release ();
10901 w
->exp_string
= xstrprintf ("-location %.*s",
10902 (int) (exp_end
- exp_start
), exp_start
);
10905 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10909 w
->hw_wp_mask
= mask
;
10914 w
->val_bitpos
= saved_bitpos
;
10915 w
->val_bitsize
= saved_bitsize
;
10916 w
->val_valid
= true;
10920 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10922 w
->cond_string
= 0;
10924 if (frame_id_p (watchpoint_frame
))
10926 w
->watchpoint_frame
= watchpoint_frame
;
10927 w
->watchpoint_thread
= inferior_ptid
;
10931 w
->watchpoint_frame
= null_frame_id
;
10932 w
->watchpoint_thread
= null_ptid
;
10935 if (scope_breakpoint
!= NULL
)
10937 /* The scope breakpoint is related to the watchpoint. We will
10938 need to act on them together. */
10939 w
->related_breakpoint
= scope_breakpoint
;
10940 scope_breakpoint
->related_breakpoint
= w
.get ();
10943 if (!just_location
)
10944 value_free_to_mark (mark
);
10946 /* Finally update the new watchpoint. This creates the locations
10947 that should be inserted. */
10948 update_watchpoint (w
.get (), 1);
10950 install_breakpoint (internal
, std::move (w
), 1);
10953 /* Return count of debug registers needed to watch the given expression.
10954 If the watchpoint cannot be handled in hardware return zero. */
10957 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10959 int found_memory_cnt
= 0;
10961 /* Did the user specifically forbid us to use hardware watchpoints? */
10962 if (!can_use_hw_watchpoints
)
10965 gdb_assert (!vals
.empty ());
10966 struct value
*head
= vals
[0].get ();
10968 /* Make sure that the value of the expression depends only upon
10969 memory contents, and values computed from them within GDB. If we
10970 find any register references or function calls, we can't use a
10971 hardware watchpoint.
10973 The idea here is that evaluating an expression generates a series
10974 of values, one holding the value of every subexpression. (The
10975 expression a*b+c has five subexpressions: a, b, a*b, c, and
10976 a*b+c.) GDB's values hold almost enough information to establish
10977 the criteria given above --- they identify memory lvalues,
10978 register lvalues, computed values, etcetera. So we can evaluate
10979 the expression, and then scan the chain of values that leaves
10980 behind to decide whether we can detect any possible change to the
10981 expression's final value using only hardware watchpoints.
10983 However, I don't think that the values returned by inferior
10984 function calls are special in any way. So this function may not
10985 notice that an expression involving an inferior function call
10986 can't be watched with hardware watchpoints. FIXME. */
10987 for (const value_ref_ptr
&iter
: vals
)
10989 struct value
*v
= iter
.get ();
10991 if (VALUE_LVAL (v
) == lval_memory
)
10993 if (v
!= head
&& value_lazy (v
))
10994 /* A lazy memory lvalue in the chain is one that GDB never
10995 needed to fetch; we either just used its address (e.g.,
10996 `a' in `a.b') or we never needed it at all (e.g., `a'
10997 in `a,b'). This doesn't apply to HEAD; if that is
10998 lazy then it was not readable, but watch it anyway. */
11002 /* Ahh, memory we actually used! Check if we can cover
11003 it with hardware watchpoints. */
11004 struct type
*vtype
= check_typedef (value_type (v
));
11006 /* We only watch structs and arrays if user asked for it
11007 explicitly, never if they just happen to appear in a
11008 middle of some value chain. */
11010 || (vtype
->code () != TYPE_CODE_STRUCT
11011 && vtype
->code () != TYPE_CODE_ARRAY
))
11013 CORE_ADDR vaddr
= value_address (v
);
11017 len
= (target_exact_watchpoints
11018 && is_scalar_type_recursive (vtype
))?
11019 1 : TYPE_LENGTH (value_type (v
));
11021 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11025 found_memory_cnt
+= num_regs
;
11029 else if (VALUE_LVAL (v
) != not_lval
11030 && deprecated_value_modifiable (v
) == 0)
11031 return 0; /* These are values from the history (e.g., $1). */
11032 else if (VALUE_LVAL (v
) == lval_register
)
11033 return 0; /* Cannot watch a register with a HW watchpoint. */
11036 /* The expression itself looks suitable for using a hardware
11037 watchpoint, but give the target machine a chance to reject it. */
11038 return found_memory_cnt
;
11042 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11044 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11047 /* A helper function that looks for the "-location" argument and then
11048 calls watch_command_1. */
11051 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
11053 int just_location
= 0;
11056 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11057 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11060 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11064 watch_command (const char *arg
, int from_tty
)
11066 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11070 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11072 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11076 rwatch_command (const char *arg
, int from_tty
)
11078 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11082 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11084 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11088 awatch_command (const char *arg
, int from_tty
)
11090 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11094 /* Data for the FSM that manages the until(location)/advance commands
11095 in infcmd.c. Here because it uses the mechanisms of
11098 struct until_break_fsm
: public thread_fsm
11100 /* The thread that was current when the command was executed. */
11103 /* The breakpoint set at the return address in the caller frame,
11104 plus breakpoints at all the destination locations. */
11105 std::vector
<breakpoint_up
> breakpoints
;
11107 until_break_fsm (struct interp
*cmd_interp
, int thread
,
11108 std::vector
<breakpoint_up
> &&breakpoints
)
11109 : thread_fsm (cmd_interp
),
11111 breakpoints (std::move (breakpoints
))
11115 void clean_up (struct thread_info
*thread
) override
;
11116 bool should_stop (struct thread_info
*thread
) override
;
11117 enum async_reply_reason
do_async_reply_reason () override
;
11120 /* Implementation of the 'should_stop' FSM method for the
11121 until(location)/advance commands. */
11124 until_break_fsm::should_stop (struct thread_info
*tp
)
11126 for (const breakpoint_up
&bp
: breakpoints
)
11127 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11128 bp
.get ()) != NULL
)
11137 /* Implementation of the 'clean_up' FSM method for the
11138 until(location)/advance commands. */
11141 until_break_fsm::clean_up (struct thread_info
*)
11143 /* Clean up our temporary breakpoints. */
11144 breakpoints
.clear ();
11145 delete_longjmp_breakpoint (thread
);
11148 /* Implementation of the 'async_reply_reason' FSM method for the
11149 until(location)/advance commands. */
11151 enum async_reply_reason
11152 until_break_fsm::do_async_reply_reason ()
11154 return EXEC_ASYNC_LOCATION_REACHED
;
11158 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11160 struct frame_info
*frame
;
11161 struct gdbarch
*frame_gdbarch
;
11162 struct frame_id stack_frame_id
;
11163 struct frame_id caller_frame_id
;
11165 struct thread_info
*tp
;
11167 clear_proceed_status (0);
11169 /* Set a breakpoint where the user wants it and at return from
11172 event_location_up location
= string_to_event_location (&arg
, current_language
);
11174 std::vector
<symtab_and_line
> sals
11175 = (last_displayed_sal_is_valid ()
11176 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11177 get_last_displayed_symtab (),
11178 get_last_displayed_line ())
11179 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11183 error (_("Couldn't get information on specified line."));
11186 error (_("Junk at end of arguments."));
11188 tp
= inferior_thread ();
11189 thread
= tp
->global_num
;
11191 /* Note linespec handling above invalidates the frame chain.
11192 Installing a breakpoint also invalidates the frame chain (as it
11193 may need to switch threads), so do any frame handling before
11196 frame
= get_selected_frame (NULL
);
11197 frame_gdbarch
= get_frame_arch (frame
);
11198 stack_frame_id
= get_stack_frame_id (frame
);
11199 caller_frame_id
= frame_unwind_caller_id (frame
);
11201 /* Keep within the current frame, or in frames called by the current
11204 std::vector
<breakpoint_up
> breakpoints
;
11206 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11208 if (frame_id_p (caller_frame_id
))
11210 struct symtab_and_line sal2
;
11211 struct gdbarch
*caller_gdbarch
;
11213 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11214 sal2
.pc
= frame_unwind_caller_pc (frame
);
11215 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11217 breakpoint_up caller_breakpoint
11218 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
11219 caller_frame_id
, bp_until
);
11220 breakpoints
.emplace_back (std::move (caller_breakpoint
));
11222 set_longjmp_breakpoint (tp
, caller_frame_id
);
11223 lj_deleter
.emplace (thread
);
11226 /* set_momentary_breakpoint could invalidate FRAME. */
11229 /* If the user told us to continue until a specified location, we
11230 don't specify a frame at which we need to stop. Otherwise,
11231 specify the selected frame, because we want to stop only at the
11232 very same frame. */
11233 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
11235 for (symtab_and_line
&sal
: sals
)
11237 resolve_sal_pc (&sal
);
11239 breakpoint_up location_breakpoint
11240 = set_momentary_breakpoint (frame_gdbarch
, sal
,
11241 stop_frame_id
, bp_until
);
11242 breakpoints
.emplace_back (std::move (location_breakpoint
));
11245 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11246 std::move (breakpoints
));
11249 lj_deleter
->release ();
11251 proceed (-1, GDB_SIGNAL_DEFAULT
);
11254 /* This function attempts to parse an optional "if <cond>" clause
11255 from the arg string. If one is not found, it returns NULL.
11257 Else, it returns a pointer to the condition string. (It does not
11258 attempt to evaluate the string against a particular block.) And,
11259 it updates arg to point to the first character following the parsed
11260 if clause in the arg string. */
11263 ep_parse_optional_if_clause (const char **arg
)
11265 const char *cond_string
;
11267 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11270 /* Skip the "if" keyword. */
11273 /* Skip any extra leading whitespace, and record the start of the
11274 condition string. */
11275 *arg
= skip_spaces (*arg
);
11276 cond_string
= *arg
;
11278 /* Assume that the condition occupies the remainder of the arg
11280 (*arg
) += strlen (cond_string
);
11282 return cond_string
;
11285 /* Commands to deal with catching events, such as signals, exceptions,
11286 process start/exit, etc. */
11290 catch_fork_temporary
, catch_vfork_temporary
,
11291 catch_fork_permanent
, catch_vfork_permanent
11296 catch_fork_command_1 (const char *arg
, int from_tty
,
11297 struct cmd_list_element
*command
)
11299 struct gdbarch
*gdbarch
= get_current_arch ();
11300 const char *cond_string
= NULL
;
11301 catch_fork_kind fork_kind
;
11303 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11304 bool temp
= (fork_kind
== catch_fork_temporary
11305 || fork_kind
== catch_vfork_temporary
);
11309 arg
= skip_spaces (arg
);
11311 /* The allowed syntax is:
11313 catch [v]fork if <cond>
11315 First, check if there's an if clause. */
11316 cond_string
= ep_parse_optional_if_clause (&arg
);
11318 if ((*arg
!= '\0') && !isspace (*arg
))
11319 error (_("Junk at end of arguments."));
11321 /* If this target supports it, create a fork or vfork catchpoint
11322 and enable reporting of such events. */
11325 case catch_fork_temporary
:
11326 case catch_fork_permanent
:
11327 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11328 &catch_fork_breakpoint_ops
);
11330 case catch_vfork_temporary
:
11331 case catch_vfork_permanent
:
11332 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11333 &catch_vfork_breakpoint_ops
);
11336 error (_("unsupported or unknown fork kind; cannot catch it"));
11342 catch_exec_command_1 (const char *arg
, int from_tty
,
11343 struct cmd_list_element
*command
)
11345 struct gdbarch
*gdbarch
= get_current_arch ();
11346 const char *cond_string
= NULL
;
11347 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11351 arg
= skip_spaces (arg
);
11353 /* The allowed syntax is:
11355 catch exec if <cond>
11357 First, check if there's an if clause. */
11358 cond_string
= ep_parse_optional_if_clause (&arg
);
11360 if ((*arg
!= '\0') && !isspace (*arg
))
11361 error (_("Junk at end of arguments."));
11363 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11364 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
,
11365 &catch_exec_breakpoint_ops
);
11366 c
->exec_pathname
= NULL
;
11368 install_breakpoint (0, std::move (c
), 1);
11372 init_ada_exception_breakpoint (struct breakpoint
*b
,
11373 struct gdbarch
*gdbarch
,
11374 struct symtab_and_line sal
,
11375 const char *addr_string
,
11376 const struct breakpoint_ops
*ops
,
11383 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11385 loc_gdbarch
= gdbarch
;
11387 describe_other_breakpoints (loc_gdbarch
,
11388 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11389 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11390 version for exception catchpoints, because two catchpoints
11391 used for different exception names will use the same address.
11392 In this case, a "breakpoint ... also set at..." warning is
11393 unproductive. Besides, the warning phrasing is also a bit
11394 inappropriate, we should use the word catchpoint, and tell
11395 the user what type of catchpoint it is. The above is good
11396 enough for now, though. */
11399 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11401 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11402 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11403 b
->location
= string_to_event_location (&addr_string
,
11404 language_def (language_ada
));
11405 b
->language
= language_ada
;
11410 /* Compare two breakpoints and return a strcmp-like result. */
11413 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11415 uintptr_t ua
= (uintptr_t) a
;
11416 uintptr_t ub
= (uintptr_t) b
;
11418 if (a
->number
< b
->number
)
11420 else if (a
->number
> b
->number
)
11423 /* Now sort by address, in case we see, e..g, two breakpoints with
11427 return ua
> ub
? 1 : 0;
11430 /* Delete breakpoints by address or line. */
11433 clear_command (const char *arg
, int from_tty
)
11435 struct breakpoint
*b
;
11438 std::vector
<symtab_and_line
> decoded_sals
;
11439 symtab_and_line last_sal
;
11440 gdb::array_view
<symtab_and_line
> sals
;
11444 = decode_line_with_current_source (arg
,
11445 (DECODE_LINE_FUNFIRSTLINE
11446 | DECODE_LINE_LIST_MODE
));
11448 sals
= decoded_sals
;
11452 /* Set sal's line, symtab, pc, and pspace to the values
11453 corresponding to the last call to print_frame_info. If the
11454 codepoint is not valid, this will set all the fields to 0. */
11455 last_sal
= get_last_displayed_sal ();
11456 if (last_sal
.symtab
== 0)
11457 error (_("No source file specified."));
11463 /* We don't call resolve_sal_pc here. That's not as bad as it
11464 seems, because all existing breakpoints typically have both
11465 file/line and pc set. So, if clear is given file/line, we can
11466 match this to existing breakpoint without obtaining pc at all.
11468 We only support clearing given the address explicitly
11469 present in breakpoint table. Say, we've set breakpoint
11470 at file:line. There were several PC values for that file:line,
11471 due to optimization, all in one block.
11473 We've picked one PC value. If "clear" is issued with another
11474 PC corresponding to the same file:line, the breakpoint won't
11475 be cleared. We probably can still clear the breakpoint, but
11476 since the other PC value is never presented to user, user
11477 can only find it by guessing, and it does not seem important
11478 to support that. */
11480 /* For each line spec given, delete bps which correspond to it. Do
11481 it in two passes, solely to preserve the current behavior that
11482 from_tty is forced true if we delete more than one
11485 std::vector
<struct breakpoint
*> found
;
11486 for (const auto &sal
: sals
)
11488 const char *sal_fullname
;
11490 /* If exact pc given, clear bpts at that pc.
11491 If line given (pc == 0), clear all bpts on specified line.
11492 If defaulting, clear all bpts on default line
11495 defaulting sal.pc != 0 tests to do
11500 1 0 <can't happen> */
11502 sal_fullname
= (sal
.symtab
== NULL
11503 ? NULL
: symtab_to_fullname (sal
.symtab
));
11505 /* Find all matching breakpoints and add them to 'found'. */
11506 ALL_BREAKPOINTS (b
)
11509 /* Are we going to delete b? */
11510 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11512 struct bp_location
*loc
= b
->loc
;
11513 for (; loc
; loc
= loc
->next
)
11515 /* If the user specified file:line, don't allow a PC
11516 match. This matches historical gdb behavior. */
11517 int pc_match
= (!sal
.explicit_line
11519 && (loc
->pspace
== sal
.pspace
)
11520 && (loc
->address
== sal
.pc
)
11521 && (!section_is_overlay (loc
->section
)
11522 || loc
->section
== sal
.section
));
11523 int line_match
= 0;
11525 if ((default_match
|| sal
.explicit_line
)
11526 && loc
->symtab
!= NULL
11527 && sal_fullname
!= NULL
11528 && sal
.pspace
== loc
->pspace
11529 && loc
->line_number
== sal
.line
11530 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11531 sal_fullname
) == 0)
11534 if (pc_match
|| line_match
)
11543 found
.push_back (b
);
11547 /* Now go thru the 'found' chain and delete them. */
11548 if (found
.empty ())
11551 error (_("No breakpoint at %s."), arg
);
11553 error (_("No breakpoint at this line."));
11556 /* Remove duplicates from the vec. */
11557 std::sort (found
.begin (), found
.end (),
11558 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11560 return compare_breakpoints (bp_a
, bp_b
) < 0;
11562 found
.erase (std::unique (found
.begin (), found
.end (),
11563 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11565 return compare_breakpoints (bp_a
, bp_b
) == 0;
11569 if (found
.size () > 1)
11570 from_tty
= 1; /* Always report if deleted more than one. */
11573 if (found
.size () == 1)
11574 printf_unfiltered (_("Deleted breakpoint "));
11576 printf_unfiltered (_("Deleted breakpoints "));
11579 for (breakpoint
*iter
: found
)
11582 printf_unfiltered ("%d ", iter
->number
);
11583 delete_breakpoint (iter
);
11586 putchar_unfiltered ('\n');
11589 /* Delete breakpoint in BS if they are `delete' breakpoints and
11590 all breakpoints that are marked for deletion, whether hit or not.
11591 This is called after any breakpoint is hit, or after errors. */
11594 breakpoint_auto_delete (bpstat bs
)
11596 struct breakpoint
*b
, *b_tmp
;
11598 for (; bs
; bs
= bs
->next
)
11599 if (bs
->breakpoint_at
11600 && bs
->breakpoint_at
->disposition
== disp_del
11602 delete_breakpoint (bs
->breakpoint_at
);
11604 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11606 if (b
->disposition
== disp_del_at_next_stop
)
11607 delete_breakpoint (b
);
11611 /* A comparison function for bp_location AP and BP being interfaced to
11612 std::sort. Sort elements primarily by their ADDRESS (no matter what
11613 bl_address_is_meaningful says), secondarily by ordering first
11614 permanent elements and terciarily just ensuring the array is sorted
11615 stable way despite std::sort being an unstable algorithm. */
11618 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11620 if (a
->address
!= b
->address
)
11621 return a
->address
< b
->address
;
11623 /* Sort locations at the same address by their pspace number, keeping
11624 locations of the same inferior (in a multi-inferior environment)
11627 if (a
->pspace
->num
!= b
->pspace
->num
)
11628 return a
->pspace
->num
< b
->pspace
->num
;
11630 /* Sort permanent breakpoints first. */
11631 if (a
->permanent
!= b
->permanent
)
11632 return a
->permanent
> b
->permanent
;
11634 /* Sort by type in order to make duplicate determination easier.
11635 See update_global_location_list. This is kept in sync with
11636 breakpoint_locations_match. */
11637 if (a
->loc_type
< b
->loc_type
)
11640 /* Likewise, for range-breakpoints, sort by length. */
11641 if (a
->loc_type
== bp_loc_hardware_breakpoint
11642 && b
->loc_type
== bp_loc_hardware_breakpoint
11643 && a
->length
< b
->length
)
11646 /* Make the internal GDB representation stable across GDB runs
11647 where A and B memory inside GDB can differ. Breakpoint locations of
11648 the same type at the same address can be sorted in arbitrary order. */
11650 if (a
->owner
->number
!= b
->owner
->number
)
11651 return a
->owner
->number
< b
->owner
->number
;
11656 /* Set bp_locations_placed_address_before_address_max and
11657 bp_locations_shadow_len_after_address_max according to the current
11658 content of the bp_locations array. */
11661 bp_locations_target_extensions_update (void)
11663 struct bp_location
*bl
, **blp_tmp
;
11665 bp_locations_placed_address_before_address_max
= 0;
11666 bp_locations_shadow_len_after_address_max
= 0;
11668 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11670 CORE_ADDR start
, end
, addr
;
11672 if (!bp_location_has_shadow (bl
))
11675 start
= bl
->target_info
.placed_address
;
11676 end
= start
+ bl
->target_info
.shadow_len
;
11678 gdb_assert (bl
->address
>= start
);
11679 addr
= bl
->address
- start
;
11680 if (addr
> bp_locations_placed_address_before_address_max
)
11681 bp_locations_placed_address_before_address_max
= addr
;
11683 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11685 gdb_assert (bl
->address
< end
);
11686 addr
= end
- bl
->address
;
11687 if (addr
> bp_locations_shadow_len_after_address_max
)
11688 bp_locations_shadow_len_after_address_max
= addr
;
11692 /* Download tracepoint locations if they haven't been. */
11695 download_tracepoint_locations (void)
11697 struct breakpoint
*b
;
11698 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11700 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11702 ALL_TRACEPOINTS (b
)
11704 struct bp_location
*bl
;
11705 struct tracepoint
*t
;
11706 int bp_location_downloaded
= 0;
11708 if ((b
->type
== bp_fast_tracepoint
11709 ? !may_insert_fast_tracepoints
11710 : !may_insert_tracepoints
))
11713 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11715 if (target_can_download_tracepoint ())
11716 can_download_tracepoint
= TRIBOOL_TRUE
;
11718 can_download_tracepoint
= TRIBOOL_FALSE
;
11721 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11724 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11726 /* In tracepoint, locations are _never_ duplicated, so
11727 should_be_inserted is equivalent to
11728 unduplicated_should_be_inserted. */
11729 if (!should_be_inserted (bl
) || bl
->inserted
)
11732 switch_to_program_space_and_thread (bl
->pspace
);
11734 target_download_tracepoint (bl
);
11737 bp_location_downloaded
= 1;
11739 t
= (struct tracepoint
*) b
;
11740 t
->number_on_target
= b
->number
;
11741 if (bp_location_downloaded
)
11742 gdb::observers::breakpoint_modified
.notify (b
);
11746 /* Swap the insertion/duplication state between two locations. */
11749 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11751 const int left_inserted
= left
->inserted
;
11752 const int left_duplicate
= left
->duplicate
;
11753 const int left_needs_update
= left
->needs_update
;
11754 const struct bp_target_info left_target_info
= left
->target_info
;
11756 /* Locations of tracepoints can never be duplicated. */
11757 if (is_tracepoint (left
->owner
))
11758 gdb_assert (!left
->duplicate
);
11759 if (is_tracepoint (right
->owner
))
11760 gdb_assert (!right
->duplicate
);
11762 left
->inserted
= right
->inserted
;
11763 left
->duplicate
= right
->duplicate
;
11764 left
->needs_update
= right
->needs_update
;
11765 left
->target_info
= right
->target_info
;
11766 right
->inserted
= left_inserted
;
11767 right
->duplicate
= left_duplicate
;
11768 right
->needs_update
= left_needs_update
;
11769 right
->target_info
= left_target_info
;
11772 /* Force the re-insertion of the locations at ADDRESS. This is called
11773 once a new/deleted/modified duplicate location is found and we are evaluating
11774 conditions on the target's side. Such conditions need to be updated on
11778 force_breakpoint_reinsertion (struct bp_location
*bl
)
11780 struct bp_location
**locp
= NULL
, **loc2p
;
11781 struct bp_location
*loc
;
11782 CORE_ADDR address
= 0;
11785 address
= bl
->address
;
11786 pspace_num
= bl
->pspace
->num
;
11788 /* This is only meaningful if the target is
11789 evaluating conditions and if the user has
11790 opted for condition evaluation on the target's
11792 if (gdb_evaluates_breakpoint_condition_p ()
11793 || !target_supports_evaluation_of_breakpoint_conditions ())
11796 /* Flag all breakpoint locations with this address and
11797 the same program space as the location
11798 as "its condition has changed". We need to
11799 update the conditions on the target's side. */
11800 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11804 if (!is_breakpoint (loc
->owner
)
11805 || pspace_num
!= loc
->pspace
->num
)
11808 /* Flag the location appropriately. We use a different state to
11809 let everyone know that we already updated the set of locations
11810 with addr bl->address and program space bl->pspace. This is so
11811 we don't have to keep calling these functions just to mark locations
11812 that have already been marked. */
11813 loc
->condition_changed
= condition_updated
;
11815 /* Free the agent expression bytecode as well. We will compute
11817 loc
->cond_bytecode
.reset ();
11821 /* Called whether new breakpoints are created, or existing breakpoints
11822 deleted, to update the global location list and recompute which
11823 locations are duplicate of which.
11825 The INSERT_MODE flag determines whether locations may not, may, or
11826 shall be inserted now. See 'enum ugll_insert_mode' for more
11830 update_global_location_list (enum ugll_insert_mode insert_mode
)
11832 struct breakpoint
*b
;
11833 struct bp_location
**locp
, *loc
;
11834 /* Last breakpoint location address that was marked for update. */
11835 CORE_ADDR last_addr
= 0;
11836 /* Last breakpoint location program space that was marked for update. */
11837 int last_pspace_num
= -1;
11839 /* Used in the duplicates detection below. When iterating over all
11840 bp_locations, points to the first bp_location of a given address.
11841 Breakpoints and watchpoints of different types are never
11842 duplicates of each other. Keep one pointer for each type of
11843 breakpoint/watchpoint, so we only need to loop over all locations
11845 struct bp_location
*bp_loc_first
; /* breakpoint */
11846 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11847 struct bp_location
*awp_loc_first
; /* access watchpoint */
11848 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11850 /* Saved former bp_locations array which we compare against the newly
11851 built bp_locations from the current state of ALL_BREAKPOINTS. */
11852 struct bp_location
**old_locp
;
11853 unsigned old_locations_count
;
11854 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11856 old_locations_count
= bp_locations_count
;
11857 bp_locations
= NULL
;
11858 bp_locations_count
= 0;
11860 ALL_BREAKPOINTS (b
)
11861 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11862 bp_locations_count
++;
11864 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11865 locp
= bp_locations
;
11866 ALL_BREAKPOINTS (b
)
11867 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11870 /* See if we need to "upgrade" a software breakpoint to a hardware
11871 breakpoint. Do this before deciding whether locations are
11872 duplicates. Also do this before sorting because sorting order
11873 depends on location type. */
11874 for (locp
= bp_locations
;
11875 locp
< bp_locations
+ bp_locations_count
;
11879 if (!loc
->inserted
&& should_be_inserted (loc
))
11880 handle_automatic_hardware_breakpoints (loc
);
11883 std::sort (bp_locations
, bp_locations
+ bp_locations_count
,
11884 bp_location_is_less_than
);
11886 bp_locations_target_extensions_update ();
11888 /* Identify bp_location instances that are no longer present in the
11889 new list, and therefore should be freed. Note that it's not
11890 necessary that those locations should be removed from inferior --
11891 if there's another location at the same address (previously
11892 marked as duplicate), we don't need to remove/insert the
11895 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11896 and former bp_location array state respectively. */
11898 locp
= bp_locations
;
11899 for (old_locp
= old_locations
.get ();
11900 old_locp
< old_locations
.get () + old_locations_count
;
11903 struct bp_location
*old_loc
= *old_locp
;
11904 struct bp_location
**loc2p
;
11906 /* Tells if 'old_loc' is found among the new locations. If
11907 not, we have to free it. */
11908 int found_object
= 0;
11909 /* Tells if the location should remain inserted in the target. */
11910 int keep_in_target
= 0;
11913 /* Skip LOCP entries which will definitely never be needed.
11914 Stop either at or being the one matching OLD_LOC. */
11915 while (locp
< bp_locations
+ bp_locations_count
11916 && (*locp
)->address
< old_loc
->address
)
11920 (loc2p
< bp_locations
+ bp_locations_count
11921 && (*loc2p
)->address
== old_loc
->address
);
11924 /* Check if this is a new/duplicated location or a duplicated
11925 location that had its condition modified. If so, we want to send
11926 its condition to the target if evaluation of conditions is taking
11928 if ((*loc2p
)->condition_changed
== condition_modified
11929 && (last_addr
!= old_loc
->address
11930 || last_pspace_num
!= old_loc
->pspace
->num
))
11932 force_breakpoint_reinsertion (*loc2p
);
11933 last_pspace_num
= old_loc
->pspace
->num
;
11936 if (*loc2p
== old_loc
)
11940 /* We have already handled this address, update it so that we don't
11941 have to go through updates again. */
11942 last_addr
= old_loc
->address
;
11944 /* Target-side condition evaluation: Handle deleted locations. */
11946 force_breakpoint_reinsertion (old_loc
);
11948 /* If this location is no longer present, and inserted, look if
11949 there's maybe a new location at the same address. If so,
11950 mark that one inserted, and don't remove this one. This is
11951 needed so that we don't have a time window where a breakpoint
11952 at certain location is not inserted. */
11954 if (old_loc
->inserted
)
11956 /* If the location is inserted now, we might have to remove
11959 if (found_object
&& should_be_inserted (old_loc
))
11961 /* The location is still present in the location list,
11962 and still should be inserted. Don't do anything. */
11963 keep_in_target
= 1;
11967 /* This location still exists, but it won't be kept in the
11968 target since it may have been disabled. We proceed to
11969 remove its target-side condition. */
11971 /* The location is either no longer present, or got
11972 disabled. See if there's another location at the
11973 same address, in which case we don't need to remove
11974 this one from the target. */
11976 /* OLD_LOC comes from existing struct breakpoint. */
11977 if (bl_address_is_meaningful (old_loc
))
11980 (loc2p
< bp_locations
+ bp_locations_count
11981 && (*loc2p
)->address
== old_loc
->address
);
11984 struct bp_location
*loc2
= *loc2p
;
11986 if (loc2
== old_loc
)
11989 if (breakpoint_locations_match (loc2
, old_loc
))
11991 /* Read watchpoint locations are switched to
11992 access watchpoints, if the former are not
11993 supported, but the latter are. */
11994 if (is_hardware_watchpoint (old_loc
->owner
))
11996 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11997 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12000 /* loc2 is a duplicated location. We need to check
12001 if it should be inserted in case it will be
12003 if (unduplicated_should_be_inserted (loc2
))
12005 swap_insertion (old_loc
, loc2
);
12006 keep_in_target
= 1;
12014 if (!keep_in_target
)
12016 if (remove_breakpoint (old_loc
))
12018 /* This is just about all we can do. We could keep
12019 this location on the global list, and try to
12020 remove it next time, but there's no particular
12021 reason why we will succeed next time.
12023 Note that at this point, old_loc->owner is still
12024 valid, as delete_breakpoint frees the breakpoint
12025 only after calling us. */
12026 printf_filtered (_("warning: Error removing "
12027 "breakpoint %d\n"),
12028 old_loc
->owner
->number
);
12036 if (removed
&& target_is_non_stop_p ()
12037 && need_moribund_for_location_type (old_loc
))
12039 /* This location was removed from the target. In
12040 non-stop mode, a race condition is possible where
12041 we've removed a breakpoint, but stop events for that
12042 breakpoint are already queued and will arrive later.
12043 We apply an heuristic to be able to distinguish such
12044 SIGTRAPs from other random SIGTRAPs: we keep this
12045 breakpoint location for a bit, and will retire it
12046 after we see some number of events. The theory here
12047 is that reporting of events should, "on the average",
12048 be fair, so after a while we'll see events from all
12049 threads that have anything of interest, and no longer
12050 need to keep this breakpoint location around. We
12051 don't hold locations forever so to reduce chances of
12052 mistaking a non-breakpoint SIGTRAP for a breakpoint
12055 The heuristic failing can be disastrous on
12056 decr_pc_after_break targets.
12058 On decr_pc_after_break targets, like e.g., x86-linux,
12059 if we fail to recognize a late breakpoint SIGTRAP,
12060 because events_till_retirement has reached 0 too
12061 soon, we'll fail to do the PC adjustment, and report
12062 a random SIGTRAP to the user. When the user resumes
12063 the inferior, it will most likely immediately crash
12064 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12065 corrupted, because of being resumed e.g., in the
12066 middle of a multi-byte instruction, or skipped a
12067 one-byte instruction. This was actually seen happen
12068 on native x86-linux, and should be less rare on
12069 targets that do not support new thread events, like
12070 remote, due to the heuristic depending on
12073 Mistaking a random SIGTRAP for a breakpoint trap
12074 causes similar symptoms (PC adjustment applied when
12075 it shouldn't), but then again, playing with SIGTRAPs
12076 behind the debugger's back is asking for trouble.
12078 Since hardware watchpoint traps are always
12079 distinguishable from other traps, so we don't need to
12080 apply keep hardware watchpoint moribund locations
12081 around. We simply always ignore hardware watchpoint
12082 traps we can no longer explain. */
12084 process_stratum_target
*proc_target
= nullptr;
12085 for (inferior
*inf
: all_inferiors ())
12086 if (inf
->pspace
== old_loc
->pspace
)
12088 proc_target
= inf
->process_target ();
12091 if (proc_target
!= nullptr)
12092 old_loc
->events_till_retirement
12093 = 3 * (thread_count (proc_target
) + 1);
12095 old_loc
->events_till_retirement
= 1;
12096 old_loc
->owner
= NULL
;
12098 moribund_locations
.push_back (old_loc
);
12102 old_loc
->owner
= NULL
;
12103 decref_bp_location (&old_loc
);
12108 /* Rescan breakpoints at the same address and section, marking the
12109 first one as "first" and any others as "duplicates". This is so
12110 that the bpt instruction is only inserted once. If we have a
12111 permanent breakpoint at the same place as BPT, make that one the
12112 official one, and the rest as duplicates. Permanent breakpoints
12113 are sorted first for the same address.
12115 Do the same for hardware watchpoints, but also considering the
12116 watchpoint's type (regular/access/read) and length. */
12118 bp_loc_first
= NULL
;
12119 wp_loc_first
= NULL
;
12120 awp_loc_first
= NULL
;
12121 rwp_loc_first
= NULL
;
12122 ALL_BP_LOCATIONS (loc
, locp
)
12124 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12126 struct bp_location
**loc_first_p
;
12129 if (!unduplicated_should_be_inserted (loc
)
12130 || !bl_address_is_meaningful (loc
)
12131 /* Don't detect duplicate for tracepoint locations because they are
12132 never duplicated. See the comments in field `duplicate' of
12133 `struct bp_location'. */
12134 || is_tracepoint (b
))
12136 /* Clear the condition modification flag. */
12137 loc
->condition_changed
= condition_unchanged
;
12141 if (b
->type
== bp_hardware_watchpoint
)
12142 loc_first_p
= &wp_loc_first
;
12143 else if (b
->type
== bp_read_watchpoint
)
12144 loc_first_p
= &rwp_loc_first
;
12145 else if (b
->type
== bp_access_watchpoint
)
12146 loc_first_p
= &awp_loc_first
;
12148 loc_first_p
= &bp_loc_first
;
12150 if (*loc_first_p
== NULL
12151 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12152 || !breakpoint_locations_match (loc
, *loc_first_p
))
12154 *loc_first_p
= loc
;
12155 loc
->duplicate
= 0;
12157 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12159 loc
->needs_update
= 1;
12160 /* Clear the condition modification flag. */
12161 loc
->condition_changed
= condition_unchanged
;
12167 /* This and the above ensure the invariant that the first location
12168 is not duplicated, and is the inserted one.
12169 All following are marked as duplicated, and are not inserted. */
12171 swap_insertion (loc
, *loc_first_p
);
12172 loc
->duplicate
= 1;
12174 /* Clear the condition modification flag. */
12175 loc
->condition_changed
= condition_unchanged
;
12178 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12180 if (insert_mode
!= UGLL_DONT_INSERT
)
12181 insert_breakpoint_locations ();
12184 /* Even though the caller told us to not insert new
12185 locations, we may still need to update conditions on the
12186 target's side of breakpoints that were already inserted
12187 if the target is evaluating breakpoint conditions. We
12188 only update conditions for locations that are marked
12190 update_inserted_breakpoint_locations ();
12194 if (insert_mode
!= UGLL_DONT_INSERT
)
12195 download_tracepoint_locations ();
12199 breakpoint_retire_moribund (void)
12201 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
12203 struct bp_location
*loc
= moribund_locations
[ix
];
12204 if (--(loc
->events_till_retirement
) == 0)
12206 decref_bp_location (&loc
);
12207 unordered_remove (moribund_locations
, ix
);
12214 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12219 update_global_location_list (insert_mode
);
12221 catch (const gdb_exception_error
&e
)
12226 /* Clear BKP from a BPS. */
12229 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12233 for (bs
= bps
; bs
; bs
= bs
->next
)
12234 if (bs
->breakpoint_at
== bpt
)
12236 bs
->breakpoint_at
= NULL
;
12237 bs
->old_val
= NULL
;
12238 /* bs->commands will be freed later. */
12242 /* Callback for iterate_over_threads. */
12244 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12246 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12248 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12252 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12256 say_where (struct breakpoint
*b
)
12258 struct value_print_options opts
;
12260 get_user_print_options (&opts
);
12262 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12264 if (b
->loc
== NULL
)
12266 /* For pending locations, the output differs slightly based
12267 on b->extra_string. If this is non-NULL, it contains either
12268 a condition or dprintf arguments. */
12269 if (b
->extra_string
== NULL
)
12271 printf_filtered (_(" (%s) pending."),
12272 event_location_to_string (b
->location
.get ()));
12274 else if (b
->type
== bp_dprintf
)
12276 printf_filtered (_(" (%s,%s) pending."),
12277 event_location_to_string (b
->location
.get ()),
12282 printf_filtered (_(" (%s %s) pending."),
12283 event_location_to_string (b
->location
.get ()),
12289 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12290 printf_filtered (" at %ps",
12291 styled_string (address_style
.style (),
12292 paddress (b
->loc
->gdbarch
,
12293 b
->loc
->address
)));
12294 if (b
->loc
->symtab
!= NULL
)
12296 /* If there is a single location, we can print the location
12298 if (b
->loc
->next
== NULL
)
12300 const char *filename
12301 = symtab_to_filename_for_display (b
->loc
->symtab
);
12302 printf_filtered (": file %ps, line %d.",
12303 styled_string (file_name_style
.style (),
12305 b
->loc
->line_number
);
12308 /* This is not ideal, but each location may have a
12309 different file name, and this at least reflects the
12310 real situation somewhat. */
12311 printf_filtered (": %s.",
12312 event_location_to_string (b
->location
.get ()));
12317 struct bp_location
*loc
= b
->loc
;
12319 for (; loc
; loc
= loc
->next
)
12321 printf_filtered (" (%d locations)", n
);
12326 bp_location::~bp_location ()
12328 xfree (function_name
);
12331 /* Destructor for the breakpoint base class. */
12333 breakpoint::~breakpoint ()
12335 xfree (this->cond_string
);
12336 xfree (this->extra_string
);
12339 static struct bp_location
*
12340 base_breakpoint_allocate_location (struct breakpoint
*self
)
12342 return new bp_location (self
);
12346 base_breakpoint_re_set (struct breakpoint
*b
)
12348 /* Nothing to re-set. */
12351 #define internal_error_pure_virtual_called() \
12352 gdb_assert_not_reached ("pure virtual function called")
12355 base_breakpoint_insert_location (struct bp_location
*bl
)
12357 internal_error_pure_virtual_called ();
12361 base_breakpoint_remove_location (struct bp_location
*bl
,
12362 enum remove_bp_reason reason
)
12364 internal_error_pure_virtual_called ();
12368 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12369 const address_space
*aspace
,
12371 const struct target_waitstatus
*ws
)
12373 internal_error_pure_virtual_called ();
12377 base_breakpoint_check_status (bpstat bs
)
12382 /* A "works_in_software_mode" breakpoint_ops method that just internal
12386 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12388 internal_error_pure_virtual_called ();
12391 /* A "resources_needed" breakpoint_ops method that just internal
12395 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12397 internal_error_pure_virtual_called ();
12400 static enum print_stop_action
12401 base_breakpoint_print_it (bpstat bs
)
12403 internal_error_pure_virtual_called ();
12407 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12408 struct ui_out
*uiout
)
12414 base_breakpoint_print_mention (struct breakpoint
*b
)
12416 internal_error_pure_virtual_called ();
12420 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12422 internal_error_pure_virtual_called ();
12426 base_breakpoint_create_sals_from_location
12427 (struct event_location
*location
,
12428 struct linespec_result
*canonical
,
12429 enum bptype type_wanted
)
12431 internal_error_pure_virtual_called ();
12435 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12436 struct linespec_result
*c
,
12437 gdb::unique_xmalloc_ptr
<char> cond_string
,
12438 gdb::unique_xmalloc_ptr
<char> extra_string
,
12439 enum bptype type_wanted
,
12440 enum bpdisp disposition
,
12442 int task
, int ignore_count
,
12443 const struct breakpoint_ops
*o
,
12444 int from_tty
, int enabled
,
12445 int internal
, unsigned flags
)
12447 internal_error_pure_virtual_called ();
12450 static std::vector
<symtab_and_line
>
12451 base_breakpoint_decode_location (struct breakpoint
*b
,
12452 struct event_location
*location
,
12453 struct program_space
*search_pspace
)
12455 internal_error_pure_virtual_called ();
12458 /* The default 'explains_signal' method. */
12461 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12466 /* The default "after_condition_true" method. */
12469 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12471 /* Nothing to do. */
12474 struct breakpoint_ops base_breakpoint_ops
=
12476 base_breakpoint_allocate_location
,
12477 base_breakpoint_re_set
,
12478 base_breakpoint_insert_location
,
12479 base_breakpoint_remove_location
,
12480 base_breakpoint_breakpoint_hit
,
12481 base_breakpoint_check_status
,
12482 base_breakpoint_resources_needed
,
12483 base_breakpoint_works_in_software_mode
,
12484 base_breakpoint_print_it
,
12486 base_breakpoint_print_one_detail
,
12487 base_breakpoint_print_mention
,
12488 base_breakpoint_print_recreate
,
12489 base_breakpoint_create_sals_from_location
,
12490 base_breakpoint_create_breakpoints_sal
,
12491 base_breakpoint_decode_location
,
12492 base_breakpoint_explains_signal
,
12493 base_breakpoint_after_condition_true
,
12496 /* Default breakpoint_ops methods. */
12499 bkpt_re_set (struct breakpoint
*b
)
12501 /* FIXME: is this still reachable? */
12502 if (breakpoint_event_location_empty_p (b
))
12504 /* Anything without a location can't be re-set. */
12505 delete_breakpoint (b
);
12509 breakpoint_re_set_default (b
);
12513 bkpt_insert_location (struct bp_location
*bl
)
12515 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12517 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12518 bl
->target_info
.placed_address
= addr
;
12520 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12521 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12523 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12527 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12529 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12530 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12532 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12536 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12537 const address_space
*aspace
, CORE_ADDR bp_addr
,
12538 const struct target_waitstatus
*ws
)
12540 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12541 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12544 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12548 if (overlay_debugging
/* unmapped overlay section */
12549 && section_is_overlay (bl
->section
)
12550 && !section_is_mapped (bl
->section
))
12557 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12558 const address_space
*aspace
, CORE_ADDR bp_addr
,
12559 const struct target_waitstatus
*ws
)
12561 if (dprintf_style
== dprintf_style_agent
12562 && target_can_run_breakpoint_commands ())
12564 /* An agent-style dprintf never causes a stop. If we see a trap
12565 for this address it must be for a breakpoint that happens to
12566 be set at the same address. */
12570 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12574 bkpt_resources_needed (const struct bp_location
*bl
)
12576 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12581 static enum print_stop_action
12582 bkpt_print_it (bpstat bs
)
12584 struct breakpoint
*b
;
12585 const struct bp_location
*bl
;
12587 struct ui_out
*uiout
= current_uiout
;
12589 gdb_assert (bs
->bp_location_at
!= NULL
);
12591 bl
= bs
->bp_location_at
;
12592 b
= bs
->breakpoint_at
;
12594 bp_temp
= b
->disposition
== disp_del
;
12595 if (bl
->address
!= bl
->requested_address
)
12596 breakpoint_adjustment_warning (bl
->requested_address
,
12599 annotate_breakpoint (b
->number
);
12600 maybe_print_thread_hit_breakpoint (uiout
);
12602 if (uiout
->is_mi_like_p ())
12604 uiout
->field_string ("reason",
12605 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12606 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12609 uiout
->message ("Temporary breakpoint %pF, ",
12610 signed_field ("bkptno", b
->number
));
12612 uiout
->message ("Breakpoint %pF, ",
12613 signed_field ("bkptno", b
->number
));
12615 return PRINT_SRC_AND_LOC
;
12619 bkpt_print_mention (struct breakpoint
*b
)
12621 if (current_uiout
->is_mi_like_p ())
12626 case bp_breakpoint
:
12627 case bp_gnu_ifunc_resolver
:
12628 if (b
->disposition
== disp_del
)
12629 printf_filtered (_("Temporary breakpoint"));
12631 printf_filtered (_("Breakpoint"));
12632 printf_filtered (_(" %d"), b
->number
);
12633 if (b
->type
== bp_gnu_ifunc_resolver
)
12634 printf_filtered (_(" at gnu-indirect-function resolver"));
12636 case bp_hardware_breakpoint
:
12637 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12640 printf_filtered (_("Dprintf %d"), b
->number
);
12648 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12650 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12651 fprintf_unfiltered (fp
, "tbreak");
12652 else if (tp
->type
== bp_breakpoint
)
12653 fprintf_unfiltered (fp
, "break");
12654 else if (tp
->type
== bp_hardware_breakpoint
12655 && tp
->disposition
== disp_del
)
12656 fprintf_unfiltered (fp
, "thbreak");
12657 else if (tp
->type
== bp_hardware_breakpoint
)
12658 fprintf_unfiltered (fp
, "hbreak");
12660 internal_error (__FILE__
, __LINE__
,
12661 _("unhandled breakpoint type %d"), (int) tp
->type
);
12663 fprintf_unfiltered (fp
, " %s",
12664 event_location_to_string (tp
->location
.get ()));
12666 /* Print out extra_string if this breakpoint is pending. It might
12667 contain, for example, conditions that were set by the user. */
12668 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12669 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12671 print_recreate_thread (tp
, fp
);
12675 bkpt_create_sals_from_location (struct event_location
*location
,
12676 struct linespec_result
*canonical
,
12677 enum bptype type_wanted
)
12679 create_sals_from_location_default (location
, canonical
, type_wanted
);
12683 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12684 struct linespec_result
*canonical
,
12685 gdb::unique_xmalloc_ptr
<char> cond_string
,
12686 gdb::unique_xmalloc_ptr
<char> extra_string
,
12687 enum bptype type_wanted
,
12688 enum bpdisp disposition
,
12690 int task
, int ignore_count
,
12691 const struct breakpoint_ops
*ops
,
12692 int from_tty
, int enabled
,
12693 int internal
, unsigned flags
)
12695 create_breakpoints_sal_default (gdbarch
, canonical
,
12696 std::move (cond_string
),
12697 std::move (extra_string
),
12699 disposition
, thread
, task
,
12700 ignore_count
, ops
, from_tty
,
12701 enabled
, internal
, flags
);
12704 static std::vector
<symtab_and_line
>
12705 bkpt_decode_location (struct breakpoint
*b
,
12706 struct event_location
*location
,
12707 struct program_space
*search_pspace
)
12709 return decode_location_default (b
, location
, search_pspace
);
12712 /* Virtual table for internal breakpoints. */
12715 internal_bkpt_re_set (struct breakpoint
*b
)
12719 /* Delete overlay event and longjmp master breakpoints; they
12720 will be reset later by breakpoint_re_set. */
12721 case bp_overlay_event
:
12722 case bp_longjmp_master
:
12723 case bp_std_terminate_master
:
12724 case bp_exception_master
:
12725 delete_breakpoint (b
);
12728 /* This breakpoint is special, it's set up when the inferior
12729 starts and we really don't want to touch it. */
12730 case bp_shlib_event
:
12732 /* Like bp_shlib_event, this breakpoint type is special. Once
12733 it is set up, we do not want to touch it. */
12734 case bp_thread_event
:
12740 internal_bkpt_check_status (bpstat bs
)
12742 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12744 /* If requested, stop when the dynamic linker notifies GDB of
12745 events. This allows the user to get control and place
12746 breakpoints in initializer routines for dynamically loaded
12747 objects (among other things). */
12748 bs
->stop
= stop_on_solib_events
;
12749 bs
->print
= stop_on_solib_events
;
12755 static enum print_stop_action
12756 internal_bkpt_print_it (bpstat bs
)
12758 struct breakpoint
*b
;
12760 b
= bs
->breakpoint_at
;
12764 case bp_shlib_event
:
12765 /* Did we stop because the user set the stop_on_solib_events
12766 variable? (If so, we report this as a generic, "Stopped due
12767 to shlib event" message.) */
12768 print_solib_event (0);
12771 case bp_thread_event
:
12772 /* Not sure how we will get here.
12773 GDB should not stop for these breakpoints. */
12774 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12777 case bp_overlay_event
:
12778 /* By analogy with the thread event, GDB should not stop for these. */
12779 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12782 case bp_longjmp_master
:
12783 /* These should never be enabled. */
12784 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12787 case bp_std_terminate_master
:
12788 /* These should never be enabled. */
12789 printf_filtered (_("std::terminate Master Breakpoint: "
12790 "gdb should not stop!\n"));
12793 case bp_exception_master
:
12794 /* These should never be enabled. */
12795 printf_filtered (_("Exception Master Breakpoint: "
12796 "gdb should not stop!\n"));
12800 return PRINT_NOTHING
;
12804 internal_bkpt_print_mention (struct breakpoint
*b
)
12806 /* Nothing to mention. These breakpoints are internal. */
12809 /* Virtual table for momentary breakpoints */
12812 momentary_bkpt_re_set (struct breakpoint
*b
)
12814 /* Keep temporary breakpoints, which can be encountered when we step
12815 over a dlopen call and solib_add is resetting the breakpoints.
12816 Otherwise these should have been blown away via the cleanup chain
12817 or by breakpoint_init_inferior when we rerun the executable. */
12821 momentary_bkpt_check_status (bpstat bs
)
12823 /* Nothing. The point of these breakpoints is causing a stop. */
12826 static enum print_stop_action
12827 momentary_bkpt_print_it (bpstat bs
)
12829 return PRINT_UNKNOWN
;
12833 momentary_bkpt_print_mention (struct breakpoint
*b
)
12835 /* Nothing to mention. These breakpoints are internal. */
12838 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12840 It gets cleared already on the removal of the first one of such placed
12841 breakpoints. This is OK as they get all removed altogether. */
12843 longjmp_breakpoint::~longjmp_breakpoint ()
12845 thread_info
*tp
= find_thread_global_id (this->thread
);
12848 tp
->initiating_frame
= null_frame_id
;
12851 /* Specific methods for probe breakpoints. */
12854 bkpt_probe_insert_location (struct bp_location
*bl
)
12856 int v
= bkpt_insert_location (bl
);
12860 /* The insertion was successful, now let's set the probe's semaphore
12862 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12869 bkpt_probe_remove_location (struct bp_location
*bl
,
12870 enum remove_bp_reason reason
)
12872 /* Let's clear the semaphore before removing the location. */
12873 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12875 return bkpt_remove_location (bl
, reason
);
12879 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12880 struct linespec_result
*canonical
,
12881 enum bptype type_wanted
)
12883 struct linespec_sals lsal
;
12885 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12887 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12888 canonical
->lsals
.push_back (std::move (lsal
));
12891 static std::vector
<symtab_and_line
>
12892 bkpt_probe_decode_location (struct breakpoint
*b
,
12893 struct event_location
*location
,
12894 struct program_space
*search_pspace
)
12896 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12898 error (_("probe not found"));
12902 /* The breakpoint_ops structure to be used in tracepoints. */
12905 tracepoint_re_set (struct breakpoint
*b
)
12907 breakpoint_re_set_default (b
);
12911 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12912 const address_space
*aspace
, CORE_ADDR bp_addr
,
12913 const struct target_waitstatus
*ws
)
12915 /* By definition, the inferior does not report stops at
12921 tracepoint_print_one_detail (const struct breakpoint
*self
,
12922 struct ui_out
*uiout
)
12924 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12925 if (!tp
->static_trace_marker_id
.empty ())
12927 gdb_assert (self
->type
== bp_static_tracepoint
);
12929 uiout
->message ("\tmarker id is %pF\n",
12930 string_field ("static-tracepoint-marker-string-id",
12931 tp
->static_trace_marker_id
.c_str ()));
12936 tracepoint_print_mention (struct breakpoint
*b
)
12938 if (current_uiout
->is_mi_like_p ())
12943 case bp_tracepoint
:
12944 printf_filtered (_("Tracepoint"));
12945 printf_filtered (_(" %d"), b
->number
);
12947 case bp_fast_tracepoint
:
12948 printf_filtered (_("Fast tracepoint"));
12949 printf_filtered (_(" %d"), b
->number
);
12951 case bp_static_tracepoint
:
12952 printf_filtered (_("Static tracepoint"));
12953 printf_filtered (_(" %d"), b
->number
);
12956 internal_error (__FILE__
, __LINE__
,
12957 _("unhandled tracepoint type %d"), (int) b
->type
);
12964 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12966 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12968 if (self
->type
== bp_fast_tracepoint
)
12969 fprintf_unfiltered (fp
, "ftrace");
12970 else if (self
->type
== bp_static_tracepoint
)
12971 fprintf_unfiltered (fp
, "strace");
12972 else if (self
->type
== bp_tracepoint
)
12973 fprintf_unfiltered (fp
, "trace");
12975 internal_error (__FILE__
, __LINE__
,
12976 _("unhandled tracepoint type %d"), (int) self
->type
);
12978 fprintf_unfiltered (fp
, " %s",
12979 event_location_to_string (self
->location
.get ()));
12980 print_recreate_thread (self
, fp
);
12982 if (tp
->pass_count
)
12983 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12987 tracepoint_create_sals_from_location (struct event_location
*location
,
12988 struct linespec_result
*canonical
,
12989 enum bptype type_wanted
)
12991 create_sals_from_location_default (location
, canonical
, type_wanted
);
12995 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12996 struct linespec_result
*canonical
,
12997 gdb::unique_xmalloc_ptr
<char> cond_string
,
12998 gdb::unique_xmalloc_ptr
<char> extra_string
,
12999 enum bptype type_wanted
,
13000 enum bpdisp disposition
,
13002 int task
, int ignore_count
,
13003 const struct breakpoint_ops
*ops
,
13004 int from_tty
, int enabled
,
13005 int internal
, unsigned flags
)
13007 create_breakpoints_sal_default (gdbarch
, canonical
,
13008 std::move (cond_string
),
13009 std::move (extra_string
),
13011 disposition
, thread
, task
,
13012 ignore_count
, ops
, from_tty
,
13013 enabled
, internal
, flags
);
13016 static std::vector
<symtab_and_line
>
13017 tracepoint_decode_location (struct breakpoint
*b
,
13018 struct event_location
*location
,
13019 struct program_space
*search_pspace
)
13021 return decode_location_default (b
, location
, search_pspace
);
13024 struct breakpoint_ops tracepoint_breakpoint_ops
;
13026 /* Virtual table for tracepoints on static probes. */
13029 tracepoint_probe_create_sals_from_location
13030 (struct event_location
*location
,
13031 struct linespec_result
*canonical
,
13032 enum bptype type_wanted
)
13034 /* We use the same method for breakpoint on probes. */
13035 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13038 static std::vector
<symtab_and_line
>
13039 tracepoint_probe_decode_location (struct breakpoint
*b
,
13040 struct event_location
*location
,
13041 struct program_space
*search_pspace
)
13043 /* We use the same method for breakpoint on probes. */
13044 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13047 /* Dprintf breakpoint_ops methods. */
13050 dprintf_re_set (struct breakpoint
*b
)
13052 breakpoint_re_set_default (b
);
13054 /* extra_string should never be non-NULL for dprintf. */
13055 gdb_assert (b
->extra_string
!= NULL
);
13057 /* 1 - connect to target 1, that can run breakpoint commands.
13058 2 - create a dprintf, which resolves fine.
13059 3 - disconnect from target 1
13060 4 - connect to target 2, that can NOT run breakpoint commands.
13062 After steps #3/#4, you'll want the dprintf command list to
13063 be updated, because target 1 and 2 may well return different
13064 answers for target_can_run_breakpoint_commands().
13065 Given absence of finer grained resetting, we get to do
13066 it all the time. */
13067 if (b
->extra_string
!= NULL
)
13068 update_dprintf_command_list (b
);
13071 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13074 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13076 fprintf_unfiltered (fp
, "dprintf %s,%s",
13077 event_location_to_string (tp
->location
.get ()),
13079 print_recreate_thread (tp
, fp
);
13082 /* Implement the "after_condition_true" breakpoint_ops method for
13085 dprintf's are implemented with regular commands in their command
13086 list, but we run the commands here instead of before presenting the
13087 stop to the user, as dprintf's don't actually cause a stop. This
13088 also makes it so that the commands of multiple dprintfs at the same
13089 address are all handled. */
13092 dprintf_after_condition_true (struct bpstats
*bs
)
13094 struct bpstats tmp_bs
;
13095 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13097 /* dprintf's never cause a stop. This wasn't set in the
13098 check_status hook instead because that would make the dprintf's
13099 condition not be evaluated. */
13102 /* Run the command list here. Take ownership of it instead of
13103 copying. We never want these commands to run later in
13104 bpstat_do_actions, if a breakpoint that causes a stop happens to
13105 be set at same address as this dprintf, or even if running the
13106 commands here throws. */
13107 tmp_bs
.commands
= bs
->commands
;
13108 bs
->commands
= NULL
;
13110 bpstat_do_actions_1 (&tmp_bs_p
);
13112 /* 'tmp_bs.commands' will usually be NULL by now, but
13113 bpstat_do_actions_1 may return early without processing the whole
13117 /* The breakpoint_ops structure to be used on static tracepoints with
13121 strace_marker_create_sals_from_location (struct event_location
*location
,
13122 struct linespec_result
*canonical
,
13123 enum bptype type_wanted
)
13125 struct linespec_sals lsal
;
13126 const char *arg_start
, *arg
;
13128 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
13129 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13131 std::string
str (arg_start
, arg
- arg_start
);
13132 const char *ptr
= str
.c_str ();
13133 canonical
->location
13134 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
13137 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13138 canonical
->lsals
.push_back (std::move (lsal
));
13142 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13143 struct linespec_result
*canonical
,
13144 gdb::unique_xmalloc_ptr
<char> cond_string
,
13145 gdb::unique_xmalloc_ptr
<char> extra_string
,
13146 enum bptype type_wanted
,
13147 enum bpdisp disposition
,
13149 int task
, int ignore_count
,
13150 const struct breakpoint_ops
*ops
,
13151 int from_tty
, int enabled
,
13152 int internal
, unsigned flags
)
13154 const linespec_sals
&lsal
= canonical
->lsals
[0];
13156 /* If the user is creating a static tracepoint by marker id
13157 (strace -m MARKER_ID), then store the sals index, so that
13158 breakpoint_re_set can try to match up which of the newly
13159 found markers corresponds to this one, and, don't try to
13160 expand multiple locations for each sal, given than SALS
13161 already should contain all sals for MARKER_ID. */
13163 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13165 event_location_up location
13166 = copy_event_location (canonical
->location
.get ());
13168 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13169 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13170 std::move (location
), NULL
,
13171 std::move (cond_string
),
13172 std::move (extra_string
),
13173 type_wanted
, disposition
,
13174 thread
, task
, ignore_count
, ops
,
13175 from_tty
, enabled
, internal
, flags
,
13176 canonical
->special_display
);
13177 /* Given that its possible to have multiple markers with
13178 the same string id, if the user is creating a static
13179 tracepoint by marker id ("strace -m MARKER_ID"), then
13180 store the sals index, so that breakpoint_re_set can
13181 try to match up which of the newly found markers
13182 corresponds to this one */
13183 tp
->static_trace_marker_id_idx
= i
;
13185 install_breakpoint (internal
, std::move (tp
), 0);
13189 static std::vector
<symtab_and_line
>
13190 strace_marker_decode_location (struct breakpoint
*b
,
13191 struct event_location
*location
,
13192 struct program_space
*search_pspace
)
13194 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13195 const char *s
= get_linespec_location (location
)->spec_string
;
13197 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13198 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13200 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13205 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
13208 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13211 strace_marker_p (struct breakpoint
*b
)
13213 return b
->ops
== &strace_marker_breakpoint_ops
;
13216 /* Delete a breakpoint and clean up all traces of it in the data
13220 delete_breakpoint (struct breakpoint
*bpt
)
13222 struct breakpoint
*b
;
13224 gdb_assert (bpt
!= NULL
);
13226 /* Has this bp already been deleted? This can happen because
13227 multiple lists can hold pointers to bp's. bpstat lists are
13230 One example of this happening is a watchpoint's scope bp. When
13231 the scope bp triggers, we notice that the watchpoint is out of
13232 scope, and delete it. We also delete its scope bp. But the
13233 scope bp is marked "auto-deleting", and is already on a bpstat.
13234 That bpstat is then checked for auto-deleting bp's, which are
13237 A real solution to this problem might involve reference counts in
13238 bp's, and/or giving them pointers back to their referencing
13239 bpstat's, and teaching delete_breakpoint to only free a bp's
13240 storage when no more references were extent. A cheaper bandaid
13242 if (bpt
->type
== bp_none
)
13245 /* At least avoid this stale reference until the reference counting
13246 of breakpoints gets resolved. */
13247 if (bpt
->related_breakpoint
!= bpt
)
13249 struct breakpoint
*related
;
13250 struct watchpoint
*w
;
13252 if (bpt
->type
== bp_watchpoint_scope
)
13253 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13254 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13255 w
= (struct watchpoint
*) bpt
;
13259 watchpoint_del_at_next_stop (w
);
13261 /* Unlink bpt from the bpt->related_breakpoint ring. */
13262 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13263 related
= related
->related_breakpoint
);
13264 related
->related_breakpoint
= bpt
->related_breakpoint
;
13265 bpt
->related_breakpoint
= bpt
;
13268 /* watch_command_1 creates a watchpoint but only sets its number if
13269 update_watchpoint succeeds in creating its bp_locations. If there's
13270 a problem in that process, we'll be asked to delete the half-created
13271 watchpoint. In that case, don't announce the deletion. */
13273 gdb::observers::breakpoint_deleted
.notify (bpt
);
13275 if (breakpoint_chain
== bpt
)
13276 breakpoint_chain
= bpt
->next
;
13278 ALL_BREAKPOINTS (b
)
13279 if (b
->next
== bpt
)
13281 b
->next
= bpt
->next
;
13285 /* Be sure no bpstat's are pointing at the breakpoint after it's
13287 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13288 in all threads for now. Note that we cannot just remove bpstats
13289 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13290 commands are associated with the bpstat; if we remove it here,
13291 then the later call to bpstat_do_actions (&stop_bpstat); in
13292 event-top.c won't do anything, and temporary breakpoints with
13293 commands won't work. */
13295 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13297 /* Now that breakpoint is removed from breakpoint list, update the
13298 global location list. This will remove locations that used to
13299 belong to this breakpoint. Do this before freeing the breakpoint
13300 itself, since remove_breakpoint looks at location's owner. It
13301 might be better design to have location completely
13302 self-contained, but it's not the case now. */
13303 update_global_location_list (UGLL_DONT_INSERT
);
13305 /* On the chance that someone will soon try again to delete this
13306 same bp, we mark it as deleted before freeing its storage. */
13307 bpt
->type
= bp_none
;
13311 /* Iterator function to call a user-provided callback function once
13312 for each of B and its related breakpoints. */
13315 iterate_over_related_breakpoints (struct breakpoint
*b
,
13316 gdb::function_view
<void (breakpoint
*)> function
)
13318 struct breakpoint
*related
;
13323 struct breakpoint
*next
;
13325 /* FUNCTION may delete RELATED. */
13326 next
= related
->related_breakpoint
;
13328 if (next
== related
)
13330 /* RELATED is the last ring entry. */
13331 function (related
);
13333 /* FUNCTION may have deleted it, so we'd never reach back to
13334 B. There's nothing left to do anyway, so just break
13339 function (related
);
13343 while (related
!= b
);
13347 delete_command (const char *arg
, int from_tty
)
13349 struct breakpoint
*b
, *b_tmp
;
13355 int breaks_to_delete
= 0;
13357 /* Delete all breakpoints if no argument. Do not delete
13358 internal breakpoints, these have to be deleted with an
13359 explicit breakpoint number argument. */
13360 ALL_BREAKPOINTS (b
)
13361 if (user_breakpoint_p (b
))
13363 breaks_to_delete
= 1;
13367 /* Ask user only if there are some breakpoints to delete. */
13369 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13371 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13372 if (user_breakpoint_p (b
))
13373 delete_breakpoint (b
);
13377 map_breakpoint_numbers
13378 (arg
, [&] (breakpoint
*br
)
13380 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13384 /* Return true if all locations of B bound to PSPACE are pending. If
13385 PSPACE is NULL, all locations of all program spaces are
13389 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13391 struct bp_location
*loc
;
13393 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13394 if ((pspace
== NULL
13395 || loc
->pspace
== pspace
)
13396 && !loc
->shlib_disabled
13397 && !loc
->pspace
->executing_startup
)
13402 /* Subroutine of update_breakpoint_locations to simplify it.
13403 Return non-zero if multiple fns in list LOC have the same name.
13404 Null names are ignored. */
13407 ambiguous_names_p (struct bp_location
*loc
)
13409 struct bp_location
*l
;
13410 htab_up
htab (htab_create_alloc (13, htab_hash_string
, streq_hash
, NULL
,
13413 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13416 const char *name
= l
->function_name
;
13418 /* Allow for some names to be NULL, ignore them. */
13422 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
13424 /* NOTE: We can assume slot != NULL here because xcalloc never
13434 /* When symbols change, it probably means the sources changed as well,
13435 and it might mean the static tracepoint markers are no longer at
13436 the same address or line numbers they used to be at last we
13437 checked. Losing your static tracepoints whenever you rebuild is
13438 undesirable. This function tries to resync/rematch gdb static
13439 tracepoints with the markers on the target, for static tracepoints
13440 that have not been set by marker id. Static tracepoint that have
13441 been set by marker id are reset by marker id in breakpoint_re_set.
13444 1) For a tracepoint set at a specific address, look for a marker at
13445 the old PC. If one is found there, assume to be the same marker.
13446 If the name / string id of the marker found is different from the
13447 previous known name, assume that means the user renamed the marker
13448 in the sources, and output a warning.
13450 2) For a tracepoint set at a given line number, look for a marker
13451 at the new address of the old line number. If one is found there,
13452 assume to be the same marker. If the name / string id of the
13453 marker found is different from the previous known name, assume that
13454 means the user renamed the marker in the sources, and output a
13457 3) If a marker is no longer found at the same address or line, it
13458 may mean the marker no longer exists. But it may also just mean
13459 the code changed a bit. Maybe the user added a few lines of code
13460 that made the marker move up or down (in line number terms). Ask
13461 the target for info about the marker with the string id as we knew
13462 it. If found, update line number and address in the matching
13463 static tracepoint. This will get confused if there's more than one
13464 marker with the same ID (possible in UST, although unadvised
13465 precisely because it confuses tools). */
13467 static struct symtab_and_line
13468 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13470 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13471 struct static_tracepoint_marker marker
;
13476 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13478 if (target_static_tracepoint_marker_at (pc
, &marker
))
13480 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13481 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13482 b
->number
, tp
->static_trace_marker_id
.c_str (),
13483 marker
.str_id
.c_str ());
13485 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13490 /* Old marker wasn't found on target at lineno. Try looking it up
13492 if (!sal
.explicit_pc
13494 && sal
.symtab
!= NULL
13495 && !tp
->static_trace_marker_id
.empty ())
13497 std::vector
<static_tracepoint_marker
> markers
13498 = target_static_tracepoint_markers_by_strid
13499 (tp
->static_trace_marker_id
.c_str ());
13501 if (!markers
.empty ())
13503 struct symbol
*sym
;
13504 struct static_tracepoint_marker
*tpmarker
;
13505 struct ui_out
*uiout
= current_uiout
;
13506 struct explicit_location explicit_loc
;
13508 tpmarker
= &markers
[0];
13510 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13512 warning (_("marker for static tracepoint %d (%s) not "
13513 "found at previous line number"),
13514 b
->number
, tp
->static_trace_marker_id
.c_str ());
13516 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13517 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13518 uiout
->text ("Now in ");
13521 uiout
->field_string ("func", sym
->print_name (),
13522 function_name_style
.style ());
13523 uiout
->text (" at ");
13525 uiout
->field_string ("file",
13526 symtab_to_filename_for_display (sal2
.symtab
),
13527 file_name_style
.style ());
13530 if (uiout
->is_mi_like_p ())
13532 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13534 uiout
->field_string ("fullname", fullname
);
13537 uiout
->field_signed ("line", sal2
.line
);
13538 uiout
->text ("\n");
13540 b
->loc
->line_number
= sal2
.line
;
13541 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13543 b
->location
.reset (NULL
);
13544 initialize_explicit_location (&explicit_loc
);
13545 explicit_loc
.source_filename
13546 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13547 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13548 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13549 b
->location
= new_explicit_location (&explicit_loc
);
13551 /* Might be nice to check if function changed, and warn if
13558 /* Returns 1 iff locations A and B are sufficiently same that
13559 we don't need to report breakpoint as changed. */
13562 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13566 if (a
->address
!= b
->address
)
13569 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13572 if (a
->enabled
!= b
->enabled
)
13575 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
13582 if ((a
== NULL
) != (b
== NULL
))
13588 /* Split all locations of B that are bound to PSPACE out of B's
13589 location list to a separate list and return that list's head. If
13590 PSPACE is NULL, hoist out all locations of B. */
13592 static struct bp_location
*
13593 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13595 struct bp_location head
;
13596 struct bp_location
*i
= b
->loc
;
13597 struct bp_location
**i_link
= &b
->loc
;
13598 struct bp_location
*hoisted
= &head
;
13600 if (pspace
== NULL
)
13611 if (i
->pspace
== pspace
)
13626 /* Create new breakpoint locations for B (a hardware or software
13627 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13628 zero, then B is a ranged breakpoint. Only recreates locations for
13629 FILTER_PSPACE. Locations of other program spaces are left
13633 update_breakpoint_locations (struct breakpoint
*b
,
13634 struct program_space
*filter_pspace
,
13635 gdb::array_view
<const symtab_and_line
> sals
,
13636 gdb::array_view
<const symtab_and_line
> sals_end
)
13638 struct bp_location
*existing_locations
;
13640 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13642 /* Ranged breakpoints have only one start location and one end
13644 b
->enable_state
= bp_disabled
;
13645 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13646 "multiple locations found\n"),
13651 /* If there's no new locations, and all existing locations are
13652 pending, don't do anything. This optimizes the common case where
13653 all locations are in the same shared library, that was unloaded.
13654 We'd like to retain the location, so that when the library is
13655 loaded again, we don't loose the enabled/disabled status of the
13656 individual locations. */
13657 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13660 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13662 for (const auto &sal
: sals
)
13664 struct bp_location
*new_loc
;
13666 switch_to_program_space_and_thread (sal
.pspace
);
13668 new_loc
= add_location_to_breakpoint (b
, &sal
);
13670 /* Reparse conditions, they might contain references to the
13672 if (b
->cond_string
!= NULL
)
13676 s
= b
->cond_string
;
13679 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13680 block_for_pc (sal
.pc
),
13683 catch (const gdb_exception_error
&e
)
13685 new_loc
->disabled_by_cond
= true;
13689 if (!sals_end
.empty ())
13691 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13693 new_loc
->length
= end
- sals
[0].pc
+ 1;
13697 /* If possible, carry over 'disable' status from existing
13700 struct bp_location
*e
= existing_locations
;
13701 /* If there are multiple breakpoints with the same function name,
13702 e.g. for inline functions, comparing function names won't work.
13703 Instead compare pc addresses; this is just a heuristic as things
13704 may have moved, but in practice it gives the correct answer
13705 often enough until a better solution is found. */
13706 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13708 for (; e
; e
= e
->next
)
13710 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
13712 struct bp_location
*l
= b
->loc
;
13713 if (have_ambiguous_names
)
13715 for (; l
; l
= l
->next
)
13717 /* Ignore software vs hardware location type at
13718 this point, because with "set breakpoint
13719 auto-hw", after a re-set, locations that were
13720 hardware can end up as software, or vice versa.
13721 As mentioned above, this is an heuristic and in
13722 practice should give the correct answer often
13724 if (breakpoint_locations_match (e
, l
, true))
13726 l
->enabled
= e
->enabled
;
13727 l
->disabled_by_cond
= e
->disabled_by_cond
;
13734 for (; l
; l
= l
->next
)
13735 if (l
->function_name
13736 && strcmp (e
->function_name
, l
->function_name
) == 0)
13738 l
->enabled
= e
->enabled
;
13739 l
->disabled_by_cond
= e
->disabled_by_cond
;
13747 if (!locations_are_equal (existing_locations
, b
->loc
))
13748 gdb::observers::breakpoint_modified
.notify (b
);
13751 /* Find the SaL locations corresponding to the given LOCATION.
13752 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13754 static std::vector
<symtab_and_line
>
13755 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13756 struct program_space
*search_pspace
, int *found
)
13758 struct gdb_exception exception
;
13760 gdb_assert (b
->ops
!= NULL
);
13762 std::vector
<symtab_and_line
> sals
;
13766 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13768 catch (gdb_exception_error
&e
)
13770 int not_found_and_ok
= 0;
13772 /* For pending breakpoints, it's expected that parsing will
13773 fail until the right shared library is loaded. User has
13774 already told to create pending breakpoints and don't need
13775 extra messages. If breakpoint is in bp_shlib_disabled
13776 state, then user already saw the message about that
13777 breakpoint being disabled, and don't want to see more
13779 if (e
.error
== NOT_FOUND_ERROR
13780 && (b
->condition_not_parsed
13782 && search_pspace
!= NULL
13783 && b
->loc
->pspace
!= search_pspace
)
13784 || (b
->loc
&& b
->loc
->shlib_disabled
)
13785 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13786 || b
->enable_state
== bp_disabled
))
13787 not_found_and_ok
= 1;
13789 if (!not_found_and_ok
)
13791 /* We surely don't want to warn about the same breakpoint
13792 10 times. One solution, implemented here, is disable
13793 the breakpoint on error. Another solution would be to
13794 have separate 'warning emitted' flag. Since this
13795 happens only when a binary has changed, I don't know
13796 which approach is better. */
13797 b
->enable_state
= bp_disabled
;
13801 exception
= std::move (e
);
13804 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13806 for (auto &sal
: sals
)
13807 resolve_sal_pc (&sal
);
13808 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13810 char *cond_string
, *extra_string
;
13813 find_condition_and_thread_for_sals (sals
, b
->extra_string
,
13814 &cond_string
, &thread
,
13815 &task
, &extra_string
);
13816 gdb_assert (b
->cond_string
== NULL
);
13818 b
->cond_string
= cond_string
;
13819 b
->thread
= thread
;
13823 xfree (b
->extra_string
);
13824 b
->extra_string
= extra_string
;
13826 b
->condition_not_parsed
= 0;
13829 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13830 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13840 /* The default re_set method, for typical hardware or software
13841 breakpoints. Reevaluate the breakpoint and recreate its
13845 breakpoint_re_set_default (struct breakpoint
*b
)
13847 struct program_space
*filter_pspace
= current_program_space
;
13848 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13851 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13852 filter_pspace
, &found
);
13854 expanded
= std::move (sals
);
13856 if (b
->location_range_end
!= NULL
)
13858 std::vector
<symtab_and_line
> sals_end
13859 = location_to_sals (b
, b
->location_range_end
.get (),
13860 filter_pspace
, &found
);
13862 expanded_end
= std::move (sals_end
);
13865 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13868 /* Default method for creating SALs from an address string. It basically
13869 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13872 create_sals_from_location_default (struct event_location
*location
,
13873 struct linespec_result
*canonical
,
13874 enum bptype type_wanted
)
13876 parse_breakpoint_sals (location
, canonical
);
13879 /* Call create_breakpoints_sal for the given arguments. This is the default
13880 function for the `create_breakpoints_sal' method of
13884 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13885 struct linespec_result
*canonical
,
13886 gdb::unique_xmalloc_ptr
<char> cond_string
,
13887 gdb::unique_xmalloc_ptr
<char> extra_string
,
13888 enum bptype type_wanted
,
13889 enum bpdisp disposition
,
13891 int task
, int ignore_count
,
13892 const struct breakpoint_ops
*ops
,
13893 int from_tty
, int enabled
,
13894 int internal
, unsigned flags
)
13896 create_breakpoints_sal (gdbarch
, canonical
,
13897 std::move (cond_string
),
13898 std::move (extra_string
),
13899 type_wanted
, disposition
,
13900 thread
, task
, ignore_count
, ops
, from_tty
,
13901 enabled
, internal
, flags
);
13904 /* Decode the line represented by S by calling decode_line_full. This is the
13905 default function for the `decode_location' method of breakpoint_ops. */
13907 static std::vector
<symtab_and_line
>
13908 decode_location_default (struct breakpoint
*b
,
13909 struct event_location
*location
,
13910 struct program_space
*search_pspace
)
13912 struct linespec_result canonical
;
13914 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13915 NULL
, 0, &canonical
, multiple_symbols_all
,
13918 /* We should get 0 or 1 resulting SALs. */
13919 gdb_assert (canonical
.lsals
.size () < 2);
13921 if (!canonical
.lsals
.empty ())
13923 const linespec_sals
&lsal
= canonical
.lsals
[0];
13924 return std::move (lsal
.sals
);
13929 /* Reset a breakpoint. */
13932 breakpoint_re_set_one (breakpoint
*b
)
13934 input_radix
= b
->input_radix
;
13935 set_language (b
->language
);
13937 b
->ops
->re_set (b
);
13940 /* Re-set breakpoint locations for the current program space.
13941 Locations bound to other program spaces are left untouched. */
13944 breakpoint_re_set (void)
13946 struct breakpoint
*b
, *b_tmp
;
13949 scoped_restore_current_language save_language
;
13950 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13951 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13953 /* breakpoint_re_set_one sets the current_language to the language
13954 of the breakpoint it is resetting (see prepare_re_set_context)
13955 before re-evaluating the breakpoint's location. This change can
13956 unfortunately get undone by accident if the language_mode is set
13957 to auto, and we either switch frames, or more likely in this context,
13958 we select the current frame.
13960 We prevent this by temporarily turning the language_mode to
13961 language_mode_manual. We restore it once all breakpoints
13962 have been reset. */
13963 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13964 language_mode
= language_mode_manual
;
13966 /* Note: we must not try to insert locations until after all
13967 breakpoints have been re-set. Otherwise, e.g., when re-setting
13968 breakpoint 1, we'd insert the locations of breakpoint 2, which
13969 hadn't been re-set yet, and thus may have stale locations. */
13971 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13975 breakpoint_re_set_one (b
);
13977 catch (const gdb_exception
&ex
)
13979 exception_fprintf (gdb_stderr
, ex
,
13980 "Error in re-setting breakpoint %d: ",
13985 jit_breakpoint_re_set ();
13988 create_overlay_event_breakpoint ();
13989 create_longjmp_master_breakpoint ();
13990 create_std_terminate_master_breakpoint ();
13991 create_exception_master_breakpoint ();
13993 /* Now we can insert. */
13994 update_global_location_list (UGLL_MAY_INSERT
);
13997 /* Reset the thread number of this breakpoint:
13999 - If the breakpoint is for all threads, leave it as-is.
14000 - Else, reset it to the current thread for inferior_ptid. */
14002 breakpoint_re_set_thread (struct breakpoint
*b
)
14004 if (b
->thread
!= -1)
14006 b
->thread
= inferior_thread ()->global_num
;
14008 /* We're being called after following a fork. The new fork is
14009 selected as current, and unless this was a vfork will have a
14010 different program space from the original thread. Reset that
14012 b
->loc
->pspace
= current_program_space
;
14016 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14017 If from_tty is nonzero, it prints a message to that effect,
14018 which ends with a period (no newline). */
14021 set_ignore_count (int bptnum
, int count
, int from_tty
)
14023 struct breakpoint
*b
;
14028 ALL_BREAKPOINTS (b
)
14029 if (b
->number
== bptnum
)
14031 if (is_tracepoint (b
))
14033 if (from_tty
&& count
!= 0)
14034 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14039 b
->ignore_count
= count
;
14043 printf_filtered (_("Will stop next time "
14044 "breakpoint %d is reached."),
14046 else if (count
== 1)
14047 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14050 printf_filtered (_("Will ignore next %d "
14051 "crossings of breakpoint %d."),
14054 gdb::observers::breakpoint_modified
.notify (b
);
14058 error (_("No breakpoint number %d."), bptnum
);
14061 /* Command to set ignore-count of breakpoint N to COUNT. */
14064 ignore_command (const char *args
, int from_tty
)
14066 const char *p
= args
;
14070 error_no_arg (_("a breakpoint number"));
14072 num
= get_number (&p
);
14074 error (_("bad breakpoint number: '%s'"), args
);
14076 error (_("Second argument (specified ignore-count) is missing."));
14078 set_ignore_count (num
,
14079 longest_to_int (value_as_long (parse_and_eval (p
))),
14082 printf_filtered ("\n");
14086 /* Call FUNCTION on each of the breakpoints with numbers in the range
14087 defined by BP_NUM_RANGE (an inclusive range). */
14090 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
14091 gdb::function_view
<void (breakpoint
*)> function
)
14093 if (bp_num_range
.first
== 0)
14095 warning (_("bad breakpoint number at or near '%d'"),
14096 bp_num_range
.first
);
14100 struct breakpoint
*b
, *tmp
;
14102 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
14104 bool match
= false;
14106 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14107 if (b
->number
== i
)
14114 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
14119 /* Call FUNCTION on each of the breakpoints whose numbers are given in
14123 map_breakpoint_numbers (const char *args
,
14124 gdb::function_view
<void (breakpoint
*)> function
)
14126 if (args
== NULL
|| *args
== '\0')
14127 error_no_arg (_("one or more breakpoint numbers"));
14129 number_or_range_parser
parser (args
);
14131 while (!parser
.finished ())
14133 int num
= parser
.get_number ();
14134 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
14138 /* Return the breakpoint location structure corresponding to the
14139 BP_NUM and LOC_NUM values. */
14141 static struct bp_location
*
14142 find_location_by_number (int bp_num
, int loc_num
)
14144 struct breakpoint
*b
;
14146 ALL_BREAKPOINTS (b
)
14147 if (b
->number
== bp_num
)
14152 if (!b
|| b
->number
!= bp_num
)
14153 error (_("Bad breakpoint number '%d'"), bp_num
);
14156 error (_("Bad breakpoint location number '%d'"), loc_num
);
14159 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
14160 if (++n
== loc_num
)
14163 error (_("Bad breakpoint location number '%d'"), loc_num
);
14166 /* Modes of operation for extract_bp_num. */
14167 enum class extract_bp_kind
14169 /* Extracting a breakpoint number. */
14172 /* Extracting a location number. */
14176 /* Extract a breakpoint or location number (as determined by KIND)
14177 from the string starting at START. TRAILER is a character which
14178 can be found after the number. If you don't want a trailer, use
14179 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14180 string. This always returns a positive integer. */
14183 extract_bp_num (extract_bp_kind kind
, const char *start
,
14184 int trailer
, const char **end_out
= NULL
)
14186 const char *end
= start
;
14187 int num
= get_number_trailer (&end
, trailer
);
14189 error (kind
== extract_bp_kind::bp
14190 ? _("Negative breakpoint number '%.*s'")
14191 : _("Negative breakpoint location number '%.*s'"),
14192 int (end
- start
), start
);
14194 error (kind
== extract_bp_kind::bp
14195 ? _("Bad breakpoint number '%.*s'")
14196 : _("Bad breakpoint location number '%.*s'"),
14197 int (end
- start
), start
);
14199 if (end_out
!= NULL
)
14204 /* Extract a breakpoint or location range (as determined by KIND) in
14205 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14206 representing the (inclusive) range. The returned pair's elements
14207 are always positive integers. */
14209 static std::pair
<int, int>
14210 extract_bp_or_bp_range (extract_bp_kind kind
,
14211 const std::string
&arg
,
14212 std::string::size_type arg_offset
)
14214 std::pair
<int, int> range
;
14215 const char *bp_loc
= &arg
[arg_offset
];
14216 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14217 if (dash
!= std::string::npos
)
14219 /* bp_loc is a range (x-z). */
14220 if (arg
.length () == dash
+ 1)
14221 error (kind
== extract_bp_kind::bp
14222 ? _("Bad breakpoint number at or near: '%s'")
14223 : _("Bad breakpoint location number at or near: '%s'"),
14227 const char *start_first
= bp_loc
;
14228 const char *start_second
= &arg
[dash
+ 1];
14229 range
.first
= extract_bp_num (kind
, start_first
, '-');
14230 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14232 if (range
.first
> range
.second
)
14233 error (kind
== extract_bp_kind::bp
14234 ? _("Inverted breakpoint range at '%.*s'")
14235 : _("Inverted breakpoint location range at '%.*s'"),
14236 int (end
- start_first
), start_first
);
14240 /* bp_loc is a single value. */
14241 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14242 range
.second
= range
.first
;
14247 /* Extract the breakpoint/location range specified by ARG. Returns
14248 the breakpoint range in BP_NUM_RANGE, and the location range in
14251 ARG may be in any of the following forms:
14253 x where 'x' is a breakpoint number.
14254 x-y where 'x' and 'y' specify a breakpoint numbers range.
14255 x.y where 'x' is a breakpoint number and 'y' a location number.
14256 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14257 location number range.
14261 extract_bp_number_and_location (const std::string
&arg
,
14262 std::pair
<int, int> &bp_num_range
,
14263 std::pair
<int, int> &bp_loc_range
)
14265 std::string::size_type dot
= arg
.find ('.');
14267 if (dot
!= std::string::npos
)
14269 /* Handle 'x.y' and 'x.y-z' cases. */
14271 if (arg
.length () == dot
+ 1 || dot
== 0)
14272 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14275 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14276 bp_num_range
.second
= bp_num_range
.first
;
14278 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14283 /* Handle x and x-y cases. */
14285 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14286 bp_loc_range
.first
= 0;
14287 bp_loc_range
.second
= 0;
14291 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14292 specifies whether to enable or disable. */
14295 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14297 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14300 if (loc
->disabled_by_cond
&& enable
)
14301 error (_("Breakpoint %d's condition is invalid at location %d, "
14302 "cannot enable."), bp_num
, loc_num
);
14304 if (loc
->enabled
!= enable
)
14306 loc
->enabled
= enable
;
14307 mark_breakpoint_location_modified (loc
);
14309 if (target_supports_enable_disable_tracepoint ()
14310 && current_trace_status ()->running
&& loc
->owner
14311 && is_tracepoint (loc
->owner
))
14312 target_disable_tracepoint (loc
);
14314 update_global_location_list (UGLL_DONT_INSERT
);
14316 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14319 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14320 number of the breakpoint, and BP_LOC_RANGE specifies the
14321 (inclusive) range of location numbers of that breakpoint to
14322 enable/disable. ENABLE specifies whether to enable or disable the
14326 enable_disable_breakpoint_location_range (int bp_num
,
14327 std::pair
<int, int> &bp_loc_range
,
14330 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14331 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14334 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14335 If from_tty is nonzero, it prints a message to that effect,
14336 which ends with a period (no newline). */
14339 disable_breakpoint (struct breakpoint
*bpt
)
14341 /* Never disable a watchpoint scope breakpoint; we want to
14342 hit them when we leave scope so we can delete both the
14343 watchpoint and its scope breakpoint at that time. */
14344 if (bpt
->type
== bp_watchpoint_scope
)
14347 bpt
->enable_state
= bp_disabled
;
14349 /* Mark breakpoint locations modified. */
14350 mark_breakpoint_modified (bpt
);
14352 if (target_supports_enable_disable_tracepoint ()
14353 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14355 struct bp_location
*location
;
14357 for (location
= bpt
->loc
; location
; location
= location
->next
)
14358 target_disable_tracepoint (location
);
14361 update_global_location_list (UGLL_DONT_INSERT
);
14363 gdb::observers::breakpoint_modified
.notify (bpt
);
14366 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14367 specified in ARGS. ARGS may be in any of the formats handled by
14368 extract_bp_number_and_location. ENABLE specifies whether to enable
14369 or disable the breakpoints/locations. */
14372 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14376 struct breakpoint
*bpt
;
14378 ALL_BREAKPOINTS (bpt
)
14379 if (user_breakpoint_p (bpt
))
14382 enable_breakpoint (bpt
);
14384 disable_breakpoint (bpt
);
14389 std::string num
= extract_arg (&args
);
14391 while (!num
.empty ())
14393 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14395 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14397 if (bp_loc_range
.first
== bp_loc_range
.second
14398 && bp_loc_range
.first
== 0)
14400 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14401 map_breakpoint_number_range (bp_num_range
,
14403 ? enable_breakpoint
14404 : disable_breakpoint
);
14408 /* Handle breakpoint ids with formats 'x.y' or
14410 enable_disable_breakpoint_location_range
14411 (bp_num_range
.first
, bp_loc_range
, enable
);
14413 num
= extract_arg (&args
);
14418 /* The disable command disables the specified breakpoints/locations
14419 (or all defined breakpoints) so they're no longer effective in
14420 stopping the inferior. ARGS may be in any of the forms defined in
14421 extract_bp_number_and_location. */
14424 disable_command (const char *args
, int from_tty
)
14426 enable_disable_command (args
, from_tty
, false);
14430 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14433 int target_resources_ok
;
14435 if (bpt
->type
== bp_hardware_breakpoint
)
14438 i
= hw_breakpoint_used_count ();
14439 target_resources_ok
=
14440 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14442 if (target_resources_ok
== 0)
14443 error (_("No hardware breakpoint support in the target."));
14444 else if (target_resources_ok
< 0)
14445 error (_("Hardware breakpoints used exceeds limit."));
14448 if (is_watchpoint (bpt
))
14450 /* Initialize it just to avoid a GCC false warning. */
14451 enum enable_state orig_enable_state
= bp_disabled
;
14455 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14457 orig_enable_state
= bpt
->enable_state
;
14458 bpt
->enable_state
= bp_enabled
;
14459 update_watchpoint (w
, 1 /* reparse */);
14461 catch (const gdb_exception
&e
)
14463 bpt
->enable_state
= orig_enable_state
;
14464 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14470 bpt
->enable_state
= bp_enabled
;
14472 /* Mark breakpoint locations modified. */
14473 mark_breakpoint_modified (bpt
);
14475 if (target_supports_enable_disable_tracepoint ()
14476 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14478 struct bp_location
*location
;
14480 for (location
= bpt
->loc
; location
; location
= location
->next
)
14481 target_enable_tracepoint (location
);
14484 bpt
->disposition
= disposition
;
14485 bpt
->enable_count
= count
;
14486 update_global_location_list (UGLL_MAY_INSERT
);
14488 gdb::observers::breakpoint_modified
.notify (bpt
);
14493 enable_breakpoint (struct breakpoint
*bpt
)
14495 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14498 /* The enable command enables the specified breakpoints/locations (or
14499 all defined breakpoints) so they once again become (or continue to
14500 be) effective in stopping the inferior. ARGS may be in any of the
14501 forms defined in extract_bp_number_and_location. */
14504 enable_command (const char *args
, int from_tty
)
14506 enable_disable_command (args
, from_tty
, true);
14510 enable_once_command (const char *args
, int from_tty
)
14512 map_breakpoint_numbers
14513 (args
, [&] (breakpoint
*b
)
14515 iterate_over_related_breakpoints
14516 (b
, [&] (breakpoint
*bpt
)
14518 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14524 enable_count_command (const char *args
, int from_tty
)
14529 error_no_arg (_("hit count"));
14531 count
= get_number (&args
);
14533 map_breakpoint_numbers
14534 (args
, [&] (breakpoint
*b
)
14536 iterate_over_related_breakpoints
14537 (b
, [&] (breakpoint
*bpt
)
14539 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14545 enable_delete_command (const char *args
, int from_tty
)
14547 map_breakpoint_numbers
14548 (args
, [&] (breakpoint
*b
)
14550 iterate_over_related_breakpoints
14551 (b
, [&] (breakpoint
*bpt
)
14553 enable_breakpoint_disp (bpt
, disp_del
, 1);
14558 /* Invalidate last known value of any hardware watchpoint if
14559 the memory which that value represents has been written to by
14563 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14564 CORE_ADDR addr
, ssize_t len
,
14565 const bfd_byte
*data
)
14567 struct breakpoint
*bp
;
14569 ALL_BREAKPOINTS (bp
)
14570 if (bp
->enable_state
== bp_enabled
14571 && bp
->type
== bp_hardware_watchpoint
)
14573 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14575 if (wp
->val_valid
&& wp
->val
!= nullptr)
14577 struct bp_location
*loc
;
14579 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14580 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14581 && loc
->address
+ loc
->length
> addr
14582 && addr
+ len
> loc
->address
)
14585 wp
->val_valid
= false;
14591 /* Create and insert a breakpoint for software single step. */
14594 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14595 const address_space
*aspace
,
14598 struct thread_info
*tp
= inferior_thread ();
14599 struct symtab_and_line sal
;
14600 CORE_ADDR pc
= next_pc
;
14602 if (tp
->control
.single_step_breakpoints
== NULL
)
14604 tp
->control
.single_step_breakpoints
14605 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14608 sal
= find_pc_line (pc
, 0);
14610 sal
.section
= find_pc_overlay (pc
);
14611 sal
.explicit_pc
= 1;
14612 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14614 update_global_location_list (UGLL_INSERT
);
14617 /* Insert single step breakpoints according to the current state. */
14620 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14622 struct regcache
*regcache
= get_current_regcache ();
14623 std::vector
<CORE_ADDR
> next_pcs
;
14625 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14627 if (!next_pcs
.empty ())
14629 struct frame_info
*frame
= get_current_frame ();
14630 const address_space
*aspace
= get_frame_address_space (frame
);
14632 for (CORE_ADDR pc
: next_pcs
)
14633 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14641 /* See breakpoint.h. */
14644 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14645 const address_space
*aspace
,
14648 struct bp_location
*loc
;
14650 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14652 && breakpoint_location_address_match (loc
, aspace
, pc
))
14658 /* Check whether a software single-step breakpoint is inserted at
14662 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14665 struct breakpoint
*bpt
;
14667 ALL_BREAKPOINTS (bpt
)
14669 if (bpt
->type
== bp_single_step
14670 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14676 /* Tracepoint-specific operations. */
14678 /* Set tracepoint count to NUM. */
14680 set_tracepoint_count (int num
)
14682 tracepoint_count
= num
;
14683 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14687 trace_command (const char *arg
, int from_tty
)
14689 event_location_up location
= string_to_event_location (&arg
,
14691 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
14692 (location
.get (), true /* is_tracepoint */);
14694 create_breakpoint (get_current_arch (),
14696 NULL
, 0, arg
, 1 /* parse arg */,
14698 bp_tracepoint
/* type_wanted */,
14699 0 /* Ignore count */,
14700 pending_break_support
,
14704 0 /* internal */, 0);
14708 ftrace_command (const char *arg
, int from_tty
)
14710 event_location_up location
= string_to_event_location (&arg
,
14712 create_breakpoint (get_current_arch (),
14714 NULL
, 0, arg
, 1 /* parse arg */,
14716 bp_fast_tracepoint
/* type_wanted */,
14717 0 /* Ignore count */,
14718 pending_break_support
,
14719 &tracepoint_breakpoint_ops
,
14722 0 /* internal */, 0);
14725 /* strace command implementation. Creates a static tracepoint. */
14728 strace_command (const char *arg
, int from_tty
)
14730 struct breakpoint_ops
*ops
;
14731 event_location_up location
;
14733 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14734 or with a normal static tracepoint. */
14735 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14737 ops
= &strace_marker_breakpoint_ops
;
14738 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14742 ops
= &tracepoint_breakpoint_ops
;
14743 location
= string_to_event_location (&arg
, current_language
);
14746 create_breakpoint (get_current_arch (),
14748 NULL
, 0, arg
, 1 /* parse arg */,
14750 bp_static_tracepoint
/* type_wanted */,
14751 0 /* Ignore count */,
14752 pending_break_support
,
14756 0 /* internal */, 0);
14759 /* Set up a fake reader function that gets command lines from a linked
14760 list that was acquired during tracepoint uploading. */
14762 static struct uploaded_tp
*this_utp
;
14763 static int next_cmd
;
14766 read_uploaded_action (void)
14768 char *rslt
= nullptr;
14770 if (next_cmd
< this_utp
->cmd_strings
.size ())
14772 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14779 /* Given information about a tracepoint as recorded on a target (which
14780 can be either a live system or a trace file), attempt to create an
14781 equivalent GDB tracepoint. This is not a reliable process, since
14782 the target does not necessarily have all the information used when
14783 the tracepoint was originally defined. */
14785 struct tracepoint
*
14786 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14788 const char *addr_str
;
14789 char small_buf
[100];
14790 struct tracepoint
*tp
;
14792 if (utp
->at_string
)
14793 addr_str
= utp
->at_string
.get ();
14796 /* In the absence of a source location, fall back to raw
14797 address. Since there is no way to confirm that the address
14798 means the same thing as when the trace was started, warn the
14800 warning (_("Uploaded tracepoint %d has no "
14801 "source location, using raw address"),
14803 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14804 addr_str
= small_buf
;
14807 /* There's not much we can do with a sequence of bytecodes. */
14808 if (utp
->cond
&& !utp
->cond_string
)
14809 warning (_("Uploaded tracepoint %d condition "
14810 "has no source form, ignoring it"),
14813 event_location_up location
= string_to_event_location (&addr_str
,
14815 if (!create_breakpoint (get_current_arch (),
14817 utp
->cond_string
.get (), -1, addr_str
,
14818 0 /* parse cond/thread */,
14820 utp
->type
/* type_wanted */,
14821 0 /* Ignore count */,
14822 pending_break_support
,
14823 &tracepoint_breakpoint_ops
,
14825 utp
->enabled
/* enabled */,
14827 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14830 /* Get the tracepoint we just created. */
14831 tp
= get_tracepoint (tracepoint_count
);
14832 gdb_assert (tp
!= NULL
);
14836 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14839 trace_pass_command (small_buf
, 0);
14842 /* If we have uploaded versions of the original commands, set up a
14843 special-purpose "reader" function and call the usual command line
14844 reader, then pass the result to the breakpoint command-setting
14846 if (!utp
->cmd_strings
.empty ())
14848 counted_command_line cmd_list
;
14853 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14855 breakpoint_set_commands (tp
, std::move (cmd_list
));
14857 else if (!utp
->actions
.empty ()
14858 || !utp
->step_actions
.empty ())
14859 warning (_("Uploaded tracepoint %d actions "
14860 "have no source form, ignoring them"),
14863 /* Copy any status information that might be available. */
14864 tp
->hit_count
= utp
->hit_count
;
14865 tp
->traceframe_usage
= utp
->traceframe_usage
;
14870 /* Print information on tracepoint number TPNUM_EXP, or all if
14874 info_tracepoints_command (const char *args
, int from_tty
)
14876 struct ui_out
*uiout
= current_uiout
;
14879 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14881 if (num_printed
== 0)
14883 if (args
== NULL
|| *args
== '\0')
14884 uiout
->message ("No tracepoints.\n");
14886 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14889 default_collect_info ();
14892 /* The 'enable trace' command enables tracepoints.
14893 Not supported by all targets. */
14895 enable_trace_command (const char *args
, int from_tty
)
14897 enable_command (args
, from_tty
);
14900 /* The 'disable trace' command disables tracepoints.
14901 Not supported by all targets. */
14903 disable_trace_command (const char *args
, int from_tty
)
14905 disable_command (args
, from_tty
);
14908 /* Remove a tracepoint (or all if no argument). */
14910 delete_trace_command (const char *arg
, int from_tty
)
14912 struct breakpoint
*b
, *b_tmp
;
14918 int breaks_to_delete
= 0;
14920 /* Delete all breakpoints if no argument.
14921 Do not delete internal or call-dummy breakpoints, these
14922 have to be deleted with an explicit breakpoint number
14924 ALL_TRACEPOINTS (b
)
14925 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14927 breaks_to_delete
= 1;
14931 /* Ask user only if there are some breakpoints to delete. */
14933 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14935 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14936 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14937 delete_breakpoint (b
);
14941 map_breakpoint_numbers
14942 (arg
, [&] (breakpoint
*br
)
14944 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14948 /* Helper function for trace_pass_command. */
14951 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14953 tp
->pass_count
= count
;
14954 gdb::observers::breakpoint_modified
.notify (tp
);
14956 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14957 tp
->number
, count
);
14960 /* Set passcount for tracepoint.
14962 First command argument is passcount, second is tracepoint number.
14963 If tracepoint number omitted, apply to most recently defined.
14964 Also accepts special argument "all". */
14967 trace_pass_command (const char *args
, int from_tty
)
14969 struct tracepoint
*t1
;
14972 if (args
== 0 || *args
== 0)
14973 error (_("passcount command requires an "
14974 "argument (count + optional TP num)"));
14976 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14978 args
= skip_spaces (args
);
14979 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14981 struct breakpoint
*b
;
14983 args
+= 3; /* Skip special argument "all". */
14985 error (_("Junk at end of arguments."));
14987 ALL_TRACEPOINTS (b
)
14989 t1
= (struct tracepoint
*) b
;
14990 trace_pass_set_count (t1
, count
, from_tty
);
14993 else if (*args
== '\0')
14995 t1
= get_tracepoint_by_number (&args
, NULL
);
14997 trace_pass_set_count (t1
, count
, from_tty
);
15001 number_or_range_parser
parser (args
);
15002 while (!parser
.finished ())
15004 t1
= get_tracepoint_by_number (&args
, &parser
);
15006 trace_pass_set_count (t1
, count
, from_tty
);
15011 struct tracepoint
*
15012 get_tracepoint (int num
)
15014 struct breakpoint
*t
;
15016 ALL_TRACEPOINTS (t
)
15017 if (t
->number
== num
)
15018 return (struct tracepoint
*) t
;
15023 /* Find the tracepoint with the given target-side number (which may be
15024 different from the tracepoint number after disconnecting and
15027 struct tracepoint
*
15028 get_tracepoint_by_number_on_target (int num
)
15030 struct breakpoint
*b
;
15032 ALL_TRACEPOINTS (b
)
15034 struct tracepoint
*t
= (struct tracepoint
*) b
;
15036 if (t
->number_on_target
== num
)
15043 /* Utility: parse a tracepoint number and look it up in the list.
15044 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15045 If the argument is missing, the most recent tracepoint
15046 (tracepoint_count) is returned. */
15048 struct tracepoint
*
15049 get_tracepoint_by_number (const char **arg
,
15050 number_or_range_parser
*parser
)
15052 struct breakpoint
*t
;
15054 const char *instring
= arg
== NULL
? NULL
: *arg
;
15056 if (parser
!= NULL
)
15058 gdb_assert (!parser
->finished ());
15059 tpnum
= parser
->get_number ();
15061 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15062 tpnum
= tracepoint_count
;
15064 tpnum
= get_number (arg
);
15068 if (instring
&& *instring
)
15069 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15072 printf_filtered (_("No previous tracepoint\n"));
15076 ALL_TRACEPOINTS (t
)
15077 if (t
->number
== tpnum
)
15079 return (struct tracepoint
*) t
;
15082 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15087 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15089 if (b
->thread
!= -1)
15090 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15093 fprintf_unfiltered (fp
, " task %d", b
->task
);
15095 fprintf_unfiltered (fp
, "\n");
15098 /* Save information on user settable breakpoints (watchpoints, etc) to
15099 a new script file named FILENAME. If FILTER is non-NULL, call it
15100 on each breakpoint and only include the ones for which it returns
15104 save_breakpoints (const char *filename
, int from_tty
,
15105 bool (*filter
) (const struct breakpoint
*))
15107 struct breakpoint
*tp
;
15109 int extra_trace_bits
= 0;
15111 if (filename
== 0 || *filename
== 0)
15112 error (_("Argument required (file name in which to save)"));
15114 /* See if we have anything to save. */
15115 ALL_BREAKPOINTS (tp
)
15117 /* Skip internal and momentary breakpoints. */
15118 if (!user_breakpoint_p (tp
))
15121 /* If we have a filter, only save the breakpoints it accepts. */
15122 if (filter
&& !filter (tp
))
15127 if (is_tracepoint (tp
))
15129 extra_trace_bits
= 1;
15131 /* We can stop searching. */
15138 warning (_("Nothing to save."));
15142 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15146 if (!fp
.open (expanded_filename
.get (), "w"))
15147 error (_("Unable to open file '%s' for saving (%s)"),
15148 expanded_filename
.get (), safe_strerror (errno
));
15150 if (extra_trace_bits
)
15151 save_trace_state_variables (&fp
);
15153 ALL_BREAKPOINTS (tp
)
15155 /* Skip internal and momentary breakpoints. */
15156 if (!user_breakpoint_p (tp
))
15159 /* If we have a filter, only save the breakpoints it accepts. */
15160 if (filter
&& !filter (tp
))
15163 tp
->ops
->print_recreate (tp
, &fp
);
15165 /* Note, we can't rely on tp->number for anything, as we can't
15166 assume the recreated breakpoint numbers will match. Use $bpnum
15169 if (tp
->cond_string
)
15170 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15172 if (tp
->ignore_count
)
15173 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15175 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15177 fp
.puts (" commands\n");
15179 current_uiout
->redirect (&fp
);
15182 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15184 catch (const gdb_exception
&ex
)
15186 current_uiout
->redirect (NULL
);
15190 current_uiout
->redirect (NULL
);
15191 fp
.puts (" end\n");
15194 if (tp
->enable_state
== bp_disabled
)
15195 fp
.puts ("disable $bpnum\n");
15197 /* If this is a multi-location breakpoint, check if the locations
15198 should be individually disabled. Watchpoint locations are
15199 special, and not user visible. */
15200 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15202 struct bp_location
*loc
;
15205 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15207 fp
.printf ("disable $bpnum.%d\n", n
);
15211 if (extra_trace_bits
&& *default_collect
)
15212 fp
.printf ("set default-collect %s\n", default_collect
);
15215 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15218 /* The `save breakpoints' command. */
15221 save_breakpoints_command (const char *args
, int from_tty
)
15223 save_breakpoints (args
, from_tty
, NULL
);
15226 /* The `save tracepoints' command. */
15229 save_tracepoints_command (const char *args
, int from_tty
)
15231 save_breakpoints (args
, from_tty
, is_tracepoint
);
15234 /* Create a vector of all tracepoints. */
15236 std::vector
<breakpoint
*>
15237 all_tracepoints (void)
15239 std::vector
<breakpoint
*> tp_vec
;
15240 struct breakpoint
*tp
;
15242 ALL_TRACEPOINTS (tp
)
15244 tp_vec
.push_back (tp
);
15251 /* This help string is used to consolidate all the help string for specifying
15252 locations used by several commands. */
15254 #define LOCATION_HELP_STRING \
15255 "Linespecs are colon-separated lists of location parameters, such as\n\
15256 source filename, function name, label name, and line number.\n\
15257 Example: To specify the start of a label named \"the_top\" in the\n\
15258 function \"fact\" in the file \"factorial.c\", use\n\
15259 \"factorial.c:fact:the_top\".\n\
15261 Address locations begin with \"*\" and specify an exact address in the\n\
15262 program. Example: To specify the fourth byte past the start function\n\
15263 \"main\", use \"*main + 4\".\n\
15265 Explicit locations are similar to linespecs but use an option/argument\n\
15266 syntax to specify location parameters.\n\
15267 Example: To specify the start of the label named \"the_top\" in the\n\
15268 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15269 -function fact -label the_top\".\n\
15271 By default, a specified function is matched against the program's\n\
15272 functions in all scopes. For C++, this means in all namespaces and\n\
15273 classes. For Ada, this means in all packages. E.g., in C++,\n\
15274 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15275 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15276 specified name as a complete fully-qualified name instead."
15278 /* This help string is used for the break, hbreak, tbreak and thbreak
15279 commands. It is defined as a macro to prevent duplication.
15280 COMMAND should be a string constant containing the name of the
15283 #define BREAK_ARGS_HELP(command) \
15284 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
15285 \t[-force-condition] [if CONDITION]\n\
15286 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15287 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15288 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15289 `-probe-dtrace' (for a DTrace probe).\n\
15290 LOCATION may be a linespec, address, or explicit location as described\n\
15293 With no LOCATION, uses current execution address of the selected\n\
15294 stack frame. This is useful for breaking on return to a stack frame.\n\
15296 THREADNUM is the number from \"info threads\".\n\
15297 CONDITION is a boolean expression.\n\
15299 With the \"-force-condition\" flag, the condition is defined even when\n\
15300 it is invalid for all current locations.\n\
15301 \n" LOCATION_HELP_STRING "\n\n\
15302 Multiple breakpoints at one place are permitted, and useful if their\n\
15303 conditions are different.\n\
15305 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15307 /* List of subcommands for "catch". */
15308 static struct cmd_list_element
*catch_cmdlist
;
15310 /* List of subcommands for "tcatch". */
15311 static struct cmd_list_element
*tcatch_cmdlist
;
15314 add_catch_command (const char *name
, const char *docstring
,
15315 cmd_const_sfunc_ftype
*sfunc
,
15316 completer_ftype
*completer
,
15317 void *user_data_catch
,
15318 void *user_data_tcatch
)
15320 struct cmd_list_element
*command
;
15322 command
= add_cmd (name
, class_breakpoint
, docstring
,
15324 set_cmd_sfunc (command
, sfunc
);
15325 set_cmd_context (command
, user_data_catch
);
15326 set_cmd_completer (command
, completer
);
15328 command
= add_cmd (name
, class_breakpoint
, docstring
,
15330 set_cmd_sfunc (command
, sfunc
);
15331 set_cmd_context (command
, user_data_tcatch
);
15332 set_cmd_completer (command
, completer
);
15335 struct breakpoint
*
15336 iterate_over_breakpoints (gdb::function_view
<bool (breakpoint
*)> callback
)
15338 struct breakpoint
*b
, *b_tmp
;
15340 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15349 /* Zero if any of the breakpoint's locations could be a location where
15350 functions have been inlined, nonzero otherwise. */
15353 is_non_inline_function (struct breakpoint
*b
)
15355 /* The shared library event breakpoint is set on the address of a
15356 non-inline function. */
15357 if (b
->type
== bp_shlib_event
)
15363 /* Nonzero if the specified PC cannot be a location where functions
15364 have been inlined. */
15367 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15368 const struct target_waitstatus
*ws
)
15370 struct breakpoint
*b
;
15371 struct bp_location
*bl
;
15373 ALL_BREAKPOINTS (b
)
15375 if (!is_non_inline_function (b
))
15378 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15380 if (!bl
->shlib_disabled
15381 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15389 /* Remove any references to OBJFILE which is going to be freed. */
15392 breakpoint_free_objfile (struct objfile
*objfile
)
15394 struct bp_location
**locp
, *loc
;
15396 ALL_BP_LOCATIONS (loc
, locp
)
15397 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15398 loc
->symtab
= NULL
;
15402 initialize_breakpoint_ops (void)
15404 static int initialized
= 0;
15406 struct breakpoint_ops
*ops
;
15412 /* The breakpoint_ops structure to be inherit by all kinds of
15413 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15414 internal and momentary breakpoints, etc.). */
15415 ops
= &bkpt_base_breakpoint_ops
;
15416 *ops
= base_breakpoint_ops
;
15417 ops
->re_set
= bkpt_re_set
;
15418 ops
->insert_location
= bkpt_insert_location
;
15419 ops
->remove_location
= bkpt_remove_location
;
15420 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15421 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15422 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15423 ops
->decode_location
= bkpt_decode_location
;
15425 /* The breakpoint_ops structure to be used in regular breakpoints. */
15426 ops
= &bkpt_breakpoint_ops
;
15427 *ops
= bkpt_base_breakpoint_ops
;
15428 ops
->re_set
= bkpt_re_set
;
15429 ops
->resources_needed
= bkpt_resources_needed
;
15430 ops
->print_it
= bkpt_print_it
;
15431 ops
->print_mention
= bkpt_print_mention
;
15432 ops
->print_recreate
= bkpt_print_recreate
;
15434 /* Ranged breakpoints. */
15435 ops
= &ranged_breakpoint_ops
;
15436 *ops
= bkpt_breakpoint_ops
;
15437 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15438 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15439 ops
->print_it
= print_it_ranged_breakpoint
;
15440 ops
->print_one
= print_one_ranged_breakpoint
;
15441 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15442 ops
->print_mention
= print_mention_ranged_breakpoint
;
15443 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15445 /* Internal breakpoints. */
15446 ops
= &internal_breakpoint_ops
;
15447 *ops
= bkpt_base_breakpoint_ops
;
15448 ops
->re_set
= internal_bkpt_re_set
;
15449 ops
->check_status
= internal_bkpt_check_status
;
15450 ops
->print_it
= internal_bkpt_print_it
;
15451 ops
->print_mention
= internal_bkpt_print_mention
;
15453 /* Momentary breakpoints. */
15454 ops
= &momentary_breakpoint_ops
;
15455 *ops
= bkpt_base_breakpoint_ops
;
15456 ops
->re_set
= momentary_bkpt_re_set
;
15457 ops
->check_status
= momentary_bkpt_check_status
;
15458 ops
->print_it
= momentary_bkpt_print_it
;
15459 ops
->print_mention
= momentary_bkpt_print_mention
;
15461 /* Probe breakpoints. */
15462 ops
= &bkpt_probe_breakpoint_ops
;
15463 *ops
= bkpt_breakpoint_ops
;
15464 ops
->insert_location
= bkpt_probe_insert_location
;
15465 ops
->remove_location
= bkpt_probe_remove_location
;
15466 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15467 ops
->decode_location
= bkpt_probe_decode_location
;
15470 ops
= &watchpoint_breakpoint_ops
;
15471 *ops
= base_breakpoint_ops
;
15472 ops
->re_set
= re_set_watchpoint
;
15473 ops
->insert_location
= insert_watchpoint
;
15474 ops
->remove_location
= remove_watchpoint
;
15475 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15476 ops
->check_status
= check_status_watchpoint
;
15477 ops
->resources_needed
= resources_needed_watchpoint
;
15478 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15479 ops
->print_it
= print_it_watchpoint
;
15480 ops
->print_mention
= print_mention_watchpoint
;
15481 ops
->print_recreate
= print_recreate_watchpoint
;
15482 ops
->explains_signal
= explains_signal_watchpoint
;
15484 /* Masked watchpoints. */
15485 ops
= &masked_watchpoint_breakpoint_ops
;
15486 *ops
= watchpoint_breakpoint_ops
;
15487 ops
->insert_location
= insert_masked_watchpoint
;
15488 ops
->remove_location
= remove_masked_watchpoint
;
15489 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15490 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15491 ops
->print_it
= print_it_masked_watchpoint
;
15492 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15493 ops
->print_mention
= print_mention_masked_watchpoint
;
15494 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15497 ops
= &tracepoint_breakpoint_ops
;
15498 *ops
= base_breakpoint_ops
;
15499 ops
->re_set
= tracepoint_re_set
;
15500 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15501 ops
->print_one_detail
= tracepoint_print_one_detail
;
15502 ops
->print_mention
= tracepoint_print_mention
;
15503 ops
->print_recreate
= tracepoint_print_recreate
;
15504 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15505 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15506 ops
->decode_location
= tracepoint_decode_location
;
15508 /* Probe tracepoints. */
15509 ops
= &tracepoint_probe_breakpoint_ops
;
15510 *ops
= tracepoint_breakpoint_ops
;
15511 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15512 ops
->decode_location
= tracepoint_probe_decode_location
;
15514 /* Static tracepoints with marker (`-m'). */
15515 ops
= &strace_marker_breakpoint_ops
;
15516 *ops
= tracepoint_breakpoint_ops
;
15517 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15518 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15519 ops
->decode_location
= strace_marker_decode_location
;
15521 /* Fork catchpoints. */
15522 ops
= &catch_fork_breakpoint_ops
;
15523 *ops
= base_breakpoint_ops
;
15524 ops
->insert_location
= insert_catch_fork
;
15525 ops
->remove_location
= remove_catch_fork
;
15526 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15527 ops
->print_it
= print_it_catch_fork
;
15528 ops
->print_one
= print_one_catch_fork
;
15529 ops
->print_mention
= print_mention_catch_fork
;
15530 ops
->print_recreate
= print_recreate_catch_fork
;
15532 /* Vfork catchpoints. */
15533 ops
= &catch_vfork_breakpoint_ops
;
15534 *ops
= base_breakpoint_ops
;
15535 ops
->insert_location
= insert_catch_vfork
;
15536 ops
->remove_location
= remove_catch_vfork
;
15537 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15538 ops
->print_it
= print_it_catch_vfork
;
15539 ops
->print_one
= print_one_catch_vfork
;
15540 ops
->print_mention
= print_mention_catch_vfork
;
15541 ops
->print_recreate
= print_recreate_catch_vfork
;
15543 /* Exec catchpoints. */
15544 ops
= &catch_exec_breakpoint_ops
;
15545 *ops
= base_breakpoint_ops
;
15546 ops
->insert_location
= insert_catch_exec
;
15547 ops
->remove_location
= remove_catch_exec
;
15548 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15549 ops
->print_it
= print_it_catch_exec
;
15550 ops
->print_one
= print_one_catch_exec
;
15551 ops
->print_mention
= print_mention_catch_exec
;
15552 ops
->print_recreate
= print_recreate_catch_exec
;
15554 /* Solib-related catchpoints. */
15555 ops
= &catch_solib_breakpoint_ops
;
15556 *ops
= base_breakpoint_ops
;
15557 ops
->insert_location
= insert_catch_solib
;
15558 ops
->remove_location
= remove_catch_solib
;
15559 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15560 ops
->check_status
= check_status_catch_solib
;
15561 ops
->print_it
= print_it_catch_solib
;
15562 ops
->print_one
= print_one_catch_solib
;
15563 ops
->print_mention
= print_mention_catch_solib
;
15564 ops
->print_recreate
= print_recreate_catch_solib
;
15566 ops
= &dprintf_breakpoint_ops
;
15567 *ops
= bkpt_base_breakpoint_ops
;
15568 ops
->re_set
= dprintf_re_set
;
15569 ops
->resources_needed
= bkpt_resources_needed
;
15570 ops
->print_it
= bkpt_print_it
;
15571 ops
->print_mention
= bkpt_print_mention
;
15572 ops
->print_recreate
= dprintf_print_recreate
;
15573 ops
->after_condition_true
= dprintf_after_condition_true
;
15574 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15577 /* Chain containing all defined "enable breakpoint" subcommands. */
15579 static struct cmd_list_element
*enablebreaklist
= NULL
;
15581 /* See breakpoint.h. */
15583 cmd_list_element
*commands_cmd_element
= nullptr;
15585 void _initialize_breakpoint ();
15587 _initialize_breakpoint ()
15589 struct cmd_list_element
*c
;
15591 initialize_breakpoint_ops ();
15593 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
);
15594 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
);
15595 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
);
15597 breakpoint_chain
= 0;
15598 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15599 before a breakpoint is set. */
15600 breakpoint_count
= 0;
15602 tracepoint_count
= 0;
15604 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15605 Set ignore-count of breakpoint number N to COUNT.\n\
15606 Usage is `ignore N COUNT'."));
15608 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15609 commands_command
, _("\
15610 Set commands to be executed when the given breakpoints are hit.\n\
15611 Give a space-separated breakpoint list as argument after \"commands\".\n\
15612 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15614 With no argument, the targeted breakpoint is the last one set.\n\
15615 The commands themselves follow starting on the next line.\n\
15616 Type a line containing \"end\" to indicate the end of them.\n\
15617 Give \"silent\" as the first line to make the breakpoint silent;\n\
15618 then no output is printed when it is hit, except what the commands print."));
15620 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15621 Specify breakpoint number N to break only if COND is true.\n\
15622 Usage is `condition [-force] N COND', where N is an integer and COND\n\
15623 is an expression to be evaluated whenever breakpoint N is reached.\n\
15624 With the \"-force\" flag, the condition is defined even when it is\n\
15625 invalid for all current locations."));
15626 set_cmd_completer (c
, condition_completer
);
15628 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15629 Set a temporary breakpoint.\n\
15630 Like \"break\" except the breakpoint is only temporary,\n\
15631 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15632 by using \"enable delete\" on the breakpoint number.\n\
15634 BREAK_ARGS_HELP ("tbreak")));
15635 set_cmd_completer (c
, location_completer
);
15637 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15638 Set a hardware assisted breakpoint.\n\
15639 Like \"break\" except the breakpoint requires hardware support,\n\
15640 some target hardware may not have this support.\n\
15642 BREAK_ARGS_HELP ("hbreak")));
15643 set_cmd_completer (c
, location_completer
);
15645 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15646 Set a temporary hardware assisted breakpoint.\n\
15647 Like \"hbreak\" except the breakpoint is only temporary,\n\
15648 so it will be deleted when hit.\n\
15650 BREAK_ARGS_HELP ("thbreak")));
15651 set_cmd_completer (c
, location_completer
);
15653 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15654 Enable all or some breakpoints.\n\
15655 Usage: enable [BREAKPOINTNUM]...\n\
15656 Give breakpoint numbers (separated by spaces) as arguments.\n\
15657 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15658 This is used to cancel the effect of the \"disable\" command.\n\
15659 With a subcommand you can enable temporarily."),
15660 &enablelist
, "enable ", 1, &cmdlist
);
15662 add_com_alias ("en", "enable", class_breakpoint
, 1);
15664 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15665 Enable all or some breakpoints.\n\
15666 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15667 Give breakpoint numbers (separated by spaces) as arguments.\n\
15668 This is used to cancel the effect of the \"disable\" command.\n\
15669 May be abbreviated to simply \"enable\"."),
15670 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15672 add_cmd ("once", no_class
, enable_once_command
, _("\
15673 Enable some breakpoints for one hit.\n\
15674 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15675 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15678 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15679 Enable some breakpoints and delete when hit.\n\
15680 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15681 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15684 add_cmd ("count", no_class
, enable_count_command
, _("\
15685 Enable some breakpoints for COUNT hits.\n\
15686 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15687 If a breakpoint is hit while enabled in this fashion,\n\
15688 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15691 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15692 Enable some breakpoints and delete when hit.\n\
15693 Usage: enable delete BREAKPOINTNUM...\n\
15694 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15697 add_cmd ("once", no_class
, enable_once_command
, _("\
15698 Enable some breakpoints for one hit.\n\
15699 Usage: enable once BREAKPOINTNUM...\n\
15700 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15703 add_cmd ("count", no_class
, enable_count_command
, _("\
15704 Enable some breakpoints for COUNT hits.\n\
15705 Usage: enable count COUNT BREAKPOINTNUM...\n\
15706 If a breakpoint is hit while enabled in this fashion,\n\
15707 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15710 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15711 Disable all or some breakpoints.\n\
15712 Usage: disable [BREAKPOINTNUM]...\n\
15713 Arguments are breakpoint numbers with spaces in between.\n\
15714 To disable all breakpoints, give no argument.\n\
15715 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15716 &disablelist
, "disable ", 1, &cmdlist
);
15717 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15718 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15720 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
15721 Disable all or some breakpoints.\n\
15722 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15723 Arguments are breakpoint numbers with spaces in between.\n\
15724 To disable all breakpoints, give no argument.\n\
15725 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15726 This command may be abbreviated \"disable\"."),
15729 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15730 Delete all or some breakpoints.\n\
15731 Usage: delete [BREAKPOINTNUM]...\n\
15732 Arguments are breakpoint numbers with spaces in between.\n\
15733 To delete all breakpoints, give no argument.\n\
15735 Also a prefix command for deletion of other GDB objects."),
15736 &deletelist
, "delete ", 1, &cmdlist
);
15737 add_com_alias ("d", "delete", class_breakpoint
, 1);
15738 add_com_alias ("del", "delete", class_breakpoint
, 1);
15740 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
15741 Delete all or some breakpoints or auto-display expressions.\n\
15742 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15743 Arguments are breakpoint numbers with spaces in between.\n\
15744 To delete all breakpoints, give no argument.\n\
15745 This command may be abbreviated \"delete\"."),
15748 add_com ("clear", class_breakpoint
, clear_command
, _("\
15749 Clear breakpoint at specified location.\n\
15750 Argument may be a linespec, explicit, or address location as described below.\n\
15752 With no argument, clears all breakpoints in the line that the selected frame\n\
15753 is executing in.\n"
15754 "\n" LOCATION_HELP_STRING
"\n\n\
15755 See also the \"delete\" command which clears breakpoints by number."));
15756 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15758 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15759 Set breakpoint at specified location.\n"
15760 BREAK_ARGS_HELP ("break")));
15761 set_cmd_completer (c
, location_completer
);
15763 add_com_alias ("b", "break", class_run
, 1);
15764 add_com_alias ("br", "break", class_run
, 1);
15765 add_com_alias ("bre", "break", class_run
, 1);
15766 add_com_alias ("brea", "break", class_run
, 1);
15770 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15771 Break in function/address or break at a line in the current file."),
15772 &stoplist
, "stop ", 1, &cmdlist
);
15773 add_cmd ("in", class_breakpoint
, stopin_command
,
15774 _("Break in function or address."), &stoplist
);
15775 add_cmd ("at", class_breakpoint
, stopat_command
,
15776 _("Break at a line in the current file."), &stoplist
);
15777 add_com ("status", class_info
, info_breakpoints_command
, _("\
15778 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15779 The \"Type\" column indicates one of:\n\
15780 \tbreakpoint - normal breakpoint\n\
15781 \twatchpoint - watchpoint\n\
15782 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15783 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15784 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15785 address and file/line number respectively.\n\
15787 Convenience variable \"$_\" and default examine address for \"x\"\n\
15788 are set to the address of the last breakpoint listed unless the command\n\
15789 is prefixed with \"server \".\n\n\
15790 Convenience variable \"$bpnum\" contains the number of the last\n\
15791 breakpoint set."));
15794 add_info ("breakpoints", info_breakpoints_command
, _("\
15795 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15796 The \"Type\" column indicates one of:\n\
15797 \tbreakpoint - normal breakpoint\n\
15798 \twatchpoint - watchpoint\n\
15799 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15800 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15801 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15802 address and file/line number respectively.\n\
15804 Convenience variable \"$_\" and default examine address for \"x\"\n\
15805 are set to the address of the last breakpoint listed unless the command\n\
15806 is prefixed with \"server \".\n\n\
15807 Convenience variable \"$bpnum\" contains the number of the last\n\
15808 breakpoint set."));
15810 add_info_alias ("b", "breakpoints", 1);
15812 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15813 Status of all breakpoints, or breakpoint number NUMBER.\n\
15814 The \"Type\" column indicates one of:\n\
15815 \tbreakpoint - normal breakpoint\n\
15816 \twatchpoint - watchpoint\n\
15817 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15818 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15819 \tuntil - internal breakpoint used by the \"until\" command\n\
15820 \tfinish - internal breakpoint used by the \"finish\" command\n\
15821 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15822 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15823 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15824 address and file/line number respectively.\n\
15826 Convenience variable \"$_\" and default examine address for \"x\"\n\
15827 are set to the address of the last breakpoint listed unless the command\n\
15828 is prefixed with \"server \".\n\n\
15829 Convenience variable \"$bpnum\" contains the number of the last\n\
15831 &maintenanceinfolist
);
15833 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
15834 Set catchpoints to catch events."),
15835 &catch_cmdlist
, "catch ",
15836 0/*allow-unknown*/, &cmdlist
);
15838 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
15839 Set temporary catchpoints to catch events."),
15840 &tcatch_cmdlist
, "tcatch ",
15841 0/*allow-unknown*/, &cmdlist
);
15843 add_catch_command ("fork", _("Catch calls to fork."),
15844 catch_fork_command_1
,
15846 (void *) (uintptr_t) catch_fork_permanent
,
15847 (void *) (uintptr_t) catch_fork_temporary
);
15848 add_catch_command ("vfork", _("Catch calls to vfork."),
15849 catch_fork_command_1
,
15851 (void *) (uintptr_t) catch_vfork_permanent
,
15852 (void *) (uintptr_t) catch_vfork_temporary
);
15853 add_catch_command ("exec", _("Catch calls to exec."),
15854 catch_exec_command_1
,
15858 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15859 Usage: catch load [REGEX]\n\
15860 If REGEX is given, only stop for libraries matching the regular expression."),
15861 catch_load_command_1
,
15865 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15866 Usage: catch unload [REGEX]\n\
15867 If REGEX is given, only stop for libraries matching the regular expression."),
15868 catch_unload_command_1
,
15873 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15874 Set a watchpoint for an expression.\n\
15875 Usage: watch [-l|-location] EXPRESSION\n\
15876 A watchpoint stops execution of your program whenever the value of\n\
15877 an expression changes.\n\
15878 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15879 the memory to which it refers."));
15880 set_cmd_completer (c
, expression_completer
);
15882 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15883 Set a read watchpoint for an expression.\n\
15884 Usage: rwatch [-l|-location] EXPRESSION\n\
15885 A watchpoint stops execution of your program whenever the value of\n\
15886 an expression is read.\n\
15887 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15888 the memory to which it refers."));
15889 set_cmd_completer (c
, expression_completer
);
15891 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15892 Set a watchpoint for an expression.\n\
15893 Usage: awatch [-l|-location] EXPRESSION\n\
15894 A watchpoint stops execution of your program whenever the value of\n\
15895 an expression is either read or written.\n\
15896 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15897 the memory to which it refers."));
15898 set_cmd_completer (c
, expression_completer
);
15900 add_info ("watchpoints", info_watchpoints_command
, _("\
15901 Status of specified watchpoints (all watchpoints if no argument)."));
15903 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15904 respond to changes - contrary to the description. */
15905 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15906 &can_use_hw_watchpoints
, _("\
15907 Set debugger's willingness to use watchpoint hardware."), _("\
15908 Show debugger's willingness to use watchpoint hardware."), _("\
15909 If zero, gdb will not use hardware for new watchpoints, even if\n\
15910 such is available. (However, any hardware watchpoints that were\n\
15911 created before setting this to nonzero, will continue to use watchpoint\n\
15914 show_can_use_hw_watchpoints
,
15915 &setlist
, &showlist
);
15917 can_use_hw_watchpoints
= 1;
15919 /* Tracepoint manipulation commands. */
15921 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15922 Set a tracepoint at specified location.\n\
15924 BREAK_ARGS_HELP ("trace") "\n\
15925 Do \"help tracepoints\" for info on other tracepoint commands."));
15926 set_cmd_completer (c
, location_completer
);
15928 add_com_alias ("tp", "trace", class_breakpoint
, 0);
15929 add_com_alias ("tr", "trace", class_breakpoint
, 1);
15930 add_com_alias ("tra", "trace", class_breakpoint
, 1);
15931 add_com_alias ("trac", "trace", class_breakpoint
, 1);
15933 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15934 Set a fast tracepoint at specified location.\n\
15936 BREAK_ARGS_HELP ("ftrace") "\n\
15937 Do \"help tracepoints\" for info on other tracepoint commands."));
15938 set_cmd_completer (c
, location_completer
);
15940 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15941 Set a static tracepoint at location or marker.\n\
15943 strace [LOCATION] [if CONDITION]\n\
15944 LOCATION may be a linespec, explicit, or address location (described below) \n\
15945 or -m MARKER_ID.\n\n\
15946 If a marker id is specified, probe the marker with that name. With\n\
15947 no LOCATION, uses current execution address of the selected stack frame.\n\
15948 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15949 This collects arbitrary user data passed in the probe point call to the\n\
15950 tracing library. You can inspect it when analyzing the trace buffer,\n\
15951 by printing the $_sdata variable like any other convenience variable.\n\
15953 CONDITION is a boolean expression.\n\
15954 \n" LOCATION_HELP_STRING
"\n\n\
15955 Multiple tracepoints at one place are permitted, and useful if their\n\
15956 conditions are different.\n\
15958 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15959 Do \"help tracepoints\" for info on other tracepoint commands."));
15960 set_cmd_completer (c
, location_completer
);
15962 add_info ("tracepoints", info_tracepoints_command
, _("\
15963 Status of specified tracepoints (all tracepoints if no argument).\n\
15964 Convenience variable \"$tpnum\" contains the number of the\n\
15965 last tracepoint set."));
15967 add_info_alias ("tp", "tracepoints", 1);
15969 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15970 Delete specified tracepoints.\n\
15971 Arguments are tracepoint numbers, separated by spaces.\n\
15972 No argument means delete all tracepoints."),
15974 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
15976 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15977 Disable specified tracepoints.\n\
15978 Arguments are tracepoint numbers, separated by spaces.\n\
15979 No argument means disable all tracepoints."),
15981 deprecate_cmd (c
, "disable");
15983 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15984 Enable specified tracepoints.\n\
15985 Arguments are tracepoint numbers, separated by spaces.\n\
15986 No argument means enable all tracepoints."),
15988 deprecate_cmd (c
, "enable");
15990 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15991 Set the passcount for a tracepoint.\n\
15992 The trace will end when the tracepoint has been passed 'count' times.\n\
15993 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15994 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15996 add_basic_prefix_cmd ("save", class_breakpoint
,
15997 _("Save breakpoint definitions as a script."),
15998 &save_cmdlist
, "save ",
15999 0/*allow-unknown*/, &cmdlist
);
16001 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16002 Save current breakpoint definitions as a script.\n\
16003 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16004 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16005 session to restore them."),
16007 set_cmd_completer (c
, filename_completer
);
16009 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16010 Save current tracepoint definitions as a script.\n\
16011 Use the 'source' command in another debug session to restore them."),
16013 set_cmd_completer (c
, filename_completer
);
16015 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16016 deprecate_cmd (c
, "save tracepoints");
16018 add_basic_prefix_cmd ("breakpoint", class_maintenance
, _("\
16019 Breakpoint specific settings.\n\
16020 Configure various breakpoint-specific variables such as\n\
16021 pending breakpoint behavior."),
16022 &breakpoint_set_cmdlist
, "set breakpoint ",
16023 0/*allow-unknown*/, &setlist
);
16024 add_show_prefix_cmd ("breakpoint", class_maintenance
, _("\
16025 Breakpoint specific settings.\n\
16026 Configure various breakpoint-specific variables such as\n\
16027 pending breakpoint behavior."),
16028 &breakpoint_show_cmdlist
, "show breakpoint ",
16029 0/*allow-unknown*/, &showlist
);
16031 add_setshow_auto_boolean_cmd ("pending", no_class
,
16032 &pending_break_support
, _("\
16033 Set debugger's behavior regarding pending breakpoints."), _("\
16034 Show debugger's behavior regarding pending breakpoints."), _("\
16035 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16036 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16037 an error. If auto, an unrecognized breakpoint location results in a\n\
16038 user-query to see if a pending breakpoint should be created."),
16040 show_pending_break_support
,
16041 &breakpoint_set_cmdlist
,
16042 &breakpoint_show_cmdlist
);
16044 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16046 add_setshow_boolean_cmd ("auto-hw", no_class
,
16047 &automatic_hardware_breakpoints
, _("\
16048 Set automatic usage of hardware breakpoints."), _("\
16049 Show automatic usage of hardware breakpoints."), _("\
16050 If set, the debugger will automatically use hardware breakpoints for\n\
16051 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16052 a warning will be emitted for such breakpoints."),
16054 show_automatic_hardware_breakpoints
,
16055 &breakpoint_set_cmdlist
,
16056 &breakpoint_show_cmdlist
);
16058 add_setshow_boolean_cmd ("always-inserted", class_support
,
16059 &always_inserted_mode
, _("\
16060 Set mode for inserting breakpoints."), _("\
16061 Show mode for inserting breakpoints."), _("\
16062 When this mode is on, breakpoints are inserted immediately as soon as\n\
16063 they're created, kept inserted even when execution stops, and removed\n\
16064 only when the user deletes them. When this mode is off (the default),\n\
16065 breakpoints are inserted only when execution continues, and removed\n\
16066 when execution stops."),
16068 &show_always_inserted_mode
,
16069 &breakpoint_set_cmdlist
,
16070 &breakpoint_show_cmdlist
);
16072 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16073 condition_evaluation_enums
,
16074 &condition_evaluation_mode_1
, _("\
16075 Set mode of breakpoint condition evaluation."), _("\
16076 Show mode of breakpoint condition evaluation."), _("\
16077 When this is set to \"host\", breakpoint conditions will be\n\
16078 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16079 breakpoint conditions will be downloaded to the target (if the target\n\
16080 supports such feature) and conditions will be evaluated on the target's side.\n\
16081 If this is set to \"auto\" (default), this will be automatically set to\n\
16082 \"target\" if it supports condition evaluation, otherwise it will\n\
16083 be set to \"host\"."),
16084 &set_condition_evaluation_mode
,
16085 &show_condition_evaluation_mode
,
16086 &breakpoint_set_cmdlist
,
16087 &breakpoint_show_cmdlist
);
16089 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16090 Set a breakpoint for an address range.\n\
16091 break-range START-LOCATION, END-LOCATION\n\
16092 where START-LOCATION and END-LOCATION can be one of the following:\n\
16093 LINENUM, for that line in the current file,\n\
16094 FILE:LINENUM, for that line in that file,\n\
16095 +OFFSET, for that number of lines after the current line\n\
16096 or the start of the range\n\
16097 FUNCTION, for the first line in that function,\n\
16098 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16099 *ADDRESS, for the instruction at that address.\n\
16101 The breakpoint will stop execution of the inferior whenever it executes\n\
16102 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16103 range (including START-LOCATION and END-LOCATION)."));
16105 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16106 Set a dynamic printf at specified location.\n\
16107 dprintf location,format string,arg1,arg2,...\n\
16108 location may be a linespec, explicit, or address location.\n"
16109 "\n" LOCATION_HELP_STRING
));
16110 set_cmd_completer (c
, location_completer
);
16112 add_setshow_enum_cmd ("dprintf-style", class_support
,
16113 dprintf_style_enums
, &dprintf_style
, _("\
16114 Set the style of usage for dynamic printf."), _("\
16115 Show the style of usage for dynamic printf."), _("\
16116 This setting chooses how GDB will do a dynamic printf.\n\
16117 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16118 console, as with the \"printf\" command.\n\
16119 If the value is \"call\", the print is done by calling a function in your\n\
16120 program; by default printf(), but you can choose a different function or\n\
16121 output stream by setting dprintf-function and dprintf-channel."),
16122 update_dprintf_commands
, NULL
,
16123 &setlist
, &showlist
);
16125 dprintf_function
= xstrdup ("printf");
16126 add_setshow_string_cmd ("dprintf-function", class_support
,
16127 &dprintf_function
, _("\
16128 Set the function to use for dynamic printf."), _("\
16129 Show the function to use for dynamic printf."), NULL
,
16130 update_dprintf_commands
, NULL
,
16131 &setlist
, &showlist
);
16133 dprintf_channel
= xstrdup ("");
16134 add_setshow_string_cmd ("dprintf-channel", class_support
,
16135 &dprintf_channel
, _("\
16136 Set the channel to use for dynamic printf."), _("\
16137 Show the channel to use for dynamic printf."), NULL
,
16138 update_dprintf_commands
, NULL
,
16139 &setlist
, &showlist
);
16141 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16142 &disconnected_dprintf
, _("\
16143 Set whether dprintf continues after GDB disconnects."), _("\
16144 Show whether dprintf continues after GDB disconnects."), _("\
16145 Use this to let dprintf commands continue to hit and produce output\n\
16146 even if GDB disconnects or detaches from the target."),
16149 &setlist
, &showlist
);
16151 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16152 Target agent only formatted printing, like the C \"printf\" function.\n\
16153 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
16154 This supports most C printf format specifications, like %s, %d, etc.\n\
16155 This is useful for formatted output in user-defined commands."));
16157 automatic_hardware_breakpoints
= true;
16159 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
);
16160 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
);