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
,
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. */
954 if (loc
->next
== nullptr)
959 /* If we reach here, the condition is valid at some locations. */
961 for (bp_location
*loc
= b
->loc
; loc
!= nullptr;
962 loc
= loc
->next
, loc_num
++)
963 set_breakpoint_location_condition (exp
, loc
, b
->number
, loc_num
);
966 /* We know that the new condition parsed successfully. The
967 condition string of the breakpoint can be safely updated. */
968 xfree (b
->cond_string
);
969 b
->cond_string
= xstrdup (exp
);
970 b
->condition_not_parsed
= 0;
972 mark_breakpoint_modified (b
);
974 gdb::observers::breakpoint_modified
.notify (b
);
977 /* Completion for the "condition" command. */
980 condition_completer (struct cmd_list_element
*cmd
,
981 completion_tracker
&tracker
,
982 const char *text
, const char *word
)
986 text
= skip_spaces (text
);
987 space
= skip_to_space (text
);
991 struct breakpoint
*b
;
995 /* We don't support completion of history indices. */
996 if (!isdigit (text
[1]))
997 complete_internalvar (tracker
, &text
[1]);
1001 /* We're completing the breakpoint number. */
1002 len
= strlen (text
);
1008 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1010 if (strncmp (number
, text
, len
) == 0)
1011 tracker
.add_completion (make_unique_xstrdup (number
));
1017 /* We're completing the expression part. */
1018 text
= skip_spaces (space
);
1019 expression_completer (cmd
, tracker
, text
, word
);
1022 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1025 condition_command (const char *arg
, int from_tty
)
1027 struct breakpoint
*b
;
1032 error_no_arg (_("breakpoint number"));
1035 bnum
= get_number (&p
);
1037 error (_("Bad breakpoint argument: '%s'"), arg
);
1040 if (b
->number
== bnum
)
1042 /* Check if this breakpoint has a "stop" method implemented in an
1043 extension language. This method and conditions entered into GDB
1044 from the CLI are mutually exclusive. */
1045 const struct extension_language_defn
*extlang
1046 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1048 if (extlang
!= NULL
)
1050 error (_("Only one stop condition allowed. There is currently"
1051 " a %s stop condition defined for this breakpoint."),
1052 ext_lang_capitalized_name (extlang
));
1054 set_breakpoint_condition (b
, p
, from_tty
);
1056 if (is_breakpoint (b
))
1057 update_global_location_list (UGLL_MAY_INSERT
);
1062 error (_("No breakpoint number %d."), bnum
);
1065 /* Check that COMMAND do not contain commands that are suitable
1066 only for tracepoints and not suitable for ordinary breakpoints.
1067 Throw if any such commands is found. */
1070 check_no_tracepoint_commands (struct command_line
*commands
)
1072 struct command_line
*c
;
1074 for (c
= commands
; c
; c
= c
->next
)
1076 if (c
->control_type
== while_stepping_control
)
1077 error (_("The 'while-stepping' command can "
1078 "only be used for tracepoints"));
1080 check_no_tracepoint_commands (c
->body_list_0
.get ());
1081 check_no_tracepoint_commands (c
->body_list_1
.get ());
1083 /* Not that command parsing removes leading whitespace and comment
1084 lines and also empty lines. So, we only need to check for
1085 command directly. */
1086 if (strstr (c
->line
, "collect ") == c
->line
)
1087 error (_("The 'collect' command can only be used for tracepoints"));
1089 if (strstr (c
->line
, "teval ") == c
->line
)
1090 error (_("The 'teval' command can only be used for tracepoints"));
1094 struct longjmp_breakpoint
: public breakpoint
1096 ~longjmp_breakpoint () override
;
1099 /* Encapsulate tests for different types of tracepoints. */
1102 is_tracepoint_type (bptype type
)
1104 return (type
== bp_tracepoint
1105 || type
== bp_fast_tracepoint
1106 || type
== bp_static_tracepoint
);
1110 is_longjmp_type (bptype type
)
1112 return type
== bp_longjmp
|| type
== bp_exception
;
1115 /* See breakpoint.h. */
1118 is_tracepoint (const struct breakpoint
*b
)
1120 return is_tracepoint_type (b
->type
);
1123 /* Factory function to create an appropriate instance of breakpoint given
1126 static std::unique_ptr
<breakpoint
>
1127 new_breakpoint_from_type (bptype type
)
1131 if (is_tracepoint_type (type
))
1132 b
= new tracepoint ();
1133 else if (is_longjmp_type (type
))
1134 b
= new longjmp_breakpoint ();
1136 b
= new breakpoint ();
1138 return std::unique_ptr
<breakpoint
> (b
);
1141 /* A helper function that validates that COMMANDS are valid for a
1142 breakpoint. This function will throw an exception if a problem is
1146 validate_commands_for_breakpoint (struct breakpoint
*b
,
1147 struct command_line
*commands
)
1149 if (is_tracepoint (b
))
1151 struct tracepoint
*t
= (struct tracepoint
*) b
;
1152 struct command_line
*c
;
1153 struct command_line
*while_stepping
= 0;
1155 /* Reset the while-stepping step count. The previous commands
1156 might have included a while-stepping action, while the new
1160 /* We need to verify that each top-level element of commands is
1161 valid for tracepoints, that there's at most one
1162 while-stepping element, and that the while-stepping's body
1163 has valid tracing commands excluding nested while-stepping.
1164 We also need to validate the tracepoint action line in the
1165 context of the tracepoint --- validate_actionline actually
1166 has side effects, like setting the tracepoint's
1167 while-stepping STEP_COUNT, in addition to checking if the
1168 collect/teval actions parse and make sense in the
1169 tracepoint's context. */
1170 for (c
= commands
; c
; c
= c
->next
)
1172 if (c
->control_type
== while_stepping_control
)
1174 if (b
->type
== bp_fast_tracepoint
)
1175 error (_("The 'while-stepping' command "
1176 "cannot be used for fast tracepoint"));
1177 else if (b
->type
== bp_static_tracepoint
)
1178 error (_("The 'while-stepping' command "
1179 "cannot be used for static tracepoint"));
1182 error (_("The 'while-stepping' command "
1183 "can be used only once"));
1188 validate_actionline (c
->line
, b
);
1192 struct command_line
*c2
;
1194 gdb_assert (while_stepping
->body_list_1
== nullptr);
1195 c2
= while_stepping
->body_list_0
.get ();
1196 for (; c2
; c2
= c2
->next
)
1198 if (c2
->control_type
== while_stepping_control
)
1199 error (_("The 'while-stepping' command cannot be nested"));
1205 check_no_tracepoint_commands (commands
);
1209 /* Return a vector of all the static tracepoints set at ADDR. The
1210 caller is responsible for releasing the vector. */
1212 std::vector
<breakpoint
*>
1213 static_tracepoints_here (CORE_ADDR addr
)
1215 struct breakpoint
*b
;
1216 std::vector
<breakpoint
*> found
;
1217 struct bp_location
*loc
;
1220 if (b
->type
== bp_static_tracepoint
)
1222 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1223 if (loc
->address
== addr
)
1224 found
.push_back (b
);
1230 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1231 validate that only allowed commands are included. */
1234 breakpoint_set_commands (struct breakpoint
*b
,
1235 counted_command_line
&&commands
)
1237 validate_commands_for_breakpoint (b
, commands
.get ());
1239 b
->commands
= std::move (commands
);
1240 gdb::observers::breakpoint_modified
.notify (b
);
1243 /* Set the internal `silent' flag on the breakpoint. Note that this
1244 is not the same as the "silent" that may appear in the breakpoint's
1248 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1250 int old_silent
= b
->silent
;
1253 if (old_silent
!= silent
)
1254 gdb::observers::breakpoint_modified
.notify (b
);
1257 /* Set the thread for this breakpoint. If THREAD is -1, make the
1258 breakpoint work for any thread. */
1261 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1263 int old_thread
= b
->thread
;
1266 if (old_thread
!= thread
)
1267 gdb::observers::breakpoint_modified
.notify (b
);
1270 /* Set the task for this breakpoint. If TASK is 0, make the
1271 breakpoint work for any task. */
1274 breakpoint_set_task (struct breakpoint
*b
, int task
)
1276 int old_task
= b
->task
;
1279 if (old_task
!= task
)
1280 gdb::observers::breakpoint_modified
.notify (b
);
1284 commands_command_1 (const char *arg
, int from_tty
,
1285 struct command_line
*control
)
1287 counted_command_line cmd
;
1288 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1289 NULL after the call to read_command_lines if the user provides an empty
1290 list of command by just typing "end". */
1291 bool cmd_read
= false;
1293 std::string new_arg
;
1295 if (arg
== NULL
|| !*arg
)
1297 /* Argument not explicitly given. Synthesize it. */
1298 if (breakpoint_count
- prev_breakpoint_count
> 1)
1299 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1301 else if (breakpoint_count
> 0)
1302 new_arg
= string_printf ("%d", breakpoint_count
);
1306 /* Create a copy of ARG. This is needed because the "commands"
1307 command may be coming from a script. In that case, the read
1308 line buffer is going to be overwritten in the lambda of
1309 'map_breakpoint_numbers' below when reading the next line
1310 before we are are done parsing the breakpoint numbers. */
1313 arg
= new_arg
.c_str ();
1315 map_breakpoint_numbers
1316 (arg
, [&] (breakpoint
*b
)
1320 gdb_assert (cmd
== NULL
);
1321 if (control
!= NULL
)
1322 cmd
= control
->body_list_0
;
1326 = string_printf (_("Type commands for breakpoint(s) "
1327 "%s, one per line."),
1330 auto do_validate
= [=] (const char *line
)
1332 validate_actionline (line
, b
);
1334 gdb::function_view
<void (const char *)> validator
;
1335 if (is_tracepoint (b
))
1336 validator
= do_validate
;
1338 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1343 /* If a breakpoint was on the list more than once, we don't need to
1345 if (b
->commands
!= cmd
)
1347 validate_commands_for_breakpoint (b
, cmd
.get ());
1349 gdb::observers::breakpoint_modified
.notify (b
);
1355 commands_command (const char *arg
, int from_tty
)
1357 commands_command_1 (arg
, from_tty
, NULL
);
1360 /* Like commands_command, but instead of reading the commands from
1361 input stream, takes them from an already parsed command structure.
1363 This is used by cli-script.c to DTRT with breakpoint commands
1364 that are part of if and while bodies. */
1365 enum command_control_type
1366 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1368 commands_command_1 (arg
, 0, cmd
);
1369 return simple_control
;
1372 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1375 bp_location_has_shadow (struct bp_location
*bl
)
1377 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1381 if (bl
->target_info
.shadow_len
== 0)
1382 /* BL isn't valid, or doesn't shadow memory. */
1387 /* Update BUF, which is LEN bytes read from the target address
1388 MEMADDR, by replacing a memory breakpoint with its shadowed
1391 If READBUF is not NULL, this buffer must not overlap with the of
1392 the breakpoint location's shadow_contents buffer. Otherwise, a
1393 failed assertion internal error will be raised. */
1396 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1397 const gdb_byte
*writebuf_org
,
1398 ULONGEST memaddr
, LONGEST len
,
1399 struct bp_target_info
*target_info
,
1400 struct gdbarch
*gdbarch
)
1402 /* Now do full processing of the found relevant range of elements. */
1403 CORE_ADDR bp_addr
= 0;
1407 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1408 current_program_space
->aspace
, 0))
1410 /* The breakpoint is inserted in a different address space. */
1414 /* Addresses and length of the part of the breakpoint that
1416 bp_addr
= target_info
->placed_address
;
1417 bp_size
= target_info
->shadow_len
;
1419 if (bp_addr
+ bp_size
<= memaddr
)
1421 /* The breakpoint is entirely before the chunk of memory we are
1426 if (bp_addr
>= memaddr
+ len
)
1428 /* The breakpoint is entirely after the chunk of memory we are
1433 /* Offset within shadow_contents. */
1434 if (bp_addr
< memaddr
)
1436 /* Only copy the second part of the breakpoint. */
1437 bp_size
-= memaddr
- bp_addr
;
1438 bptoffset
= memaddr
- bp_addr
;
1442 if (bp_addr
+ bp_size
> memaddr
+ len
)
1444 /* Only copy the first part of the breakpoint. */
1445 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1448 if (readbuf
!= NULL
)
1450 /* Verify that the readbuf buffer does not overlap with the
1451 shadow_contents buffer. */
1452 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1453 || readbuf
>= (target_info
->shadow_contents
1454 + target_info
->shadow_len
));
1456 /* Update the read buffer with this inserted breakpoint's
1458 memcpy (readbuf
+ bp_addr
- memaddr
,
1459 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1463 const unsigned char *bp
;
1464 CORE_ADDR addr
= target_info
->reqstd_address
;
1467 /* Update the shadow with what we want to write to memory. */
1468 memcpy (target_info
->shadow_contents
+ bptoffset
,
1469 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1471 /* Determine appropriate breakpoint contents and size for this
1473 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1475 /* Update the final write buffer with this inserted
1476 breakpoint's INSN. */
1477 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1481 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1482 by replacing any memory breakpoints with their shadowed contents.
1484 If READBUF is not NULL, this buffer must not overlap with any of
1485 the breakpoint location's shadow_contents buffers. Otherwise,
1486 a failed assertion internal error will be raised.
1488 The range of shadowed area by each bp_location is:
1489 bl->address - bp_locations_placed_address_before_address_max
1490 up to bl->address + bp_locations_shadow_len_after_address_max
1491 The range we were requested to resolve shadows for is:
1492 memaddr ... memaddr + len
1493 Thus the safe cutoff boundaries for performance optimization are
1494 memaddr + len <= (bl->address
1495 - bp_locations_placed_address_before_address_max)
1497 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1500 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1501 const gdb_byte
*writebuf_org
,
1502 ULONGEST memaddr
, LONGEST len
)
1504 /* Left boundary, right boundary and median element of our binary
1506 unsigned bc_l
, bc_r
, bc
;
1508 /* Find BC_L which is a leftmost element which may affect BUF
1509 content. It is safe to report lower value but a failure to
1510 report higher one. */
1513 bc_r
= bp_locations_count
;
1514 while (bc_l
+ 1 < bc_r
)
1516 struct bp_location
*bl
;
1518 bc
= (bc_l
+ bc_r
) / 2;
1519 bl
= bp_locations
[bc
];
1521 /* Check first BL->ADDRESS will not overflow due to the added
1522 constant. Then advance the left boundary only if we are sure
1523 the BC element can in no way affect the BUF content (MEMADDR
1524 to MEMADDR + LEN range).
1526 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1527 offset so that we cannot miss a breakpoint with its shadow
1528 range tail still reaching MEMADDR. */
1530 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1532 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1539 /* Due to the binary search above, we need to make sure we pick the
1540 first location that's at BC_L's address. E.g., if there are
1541 multiple locations at the same address, BC_L may end up pointing
1542 at a duplicate location, and miss the "master"/"inserted"
1543 location. Say, given locations L1, L2 and L3 at addresses A and
1546 L1@A, L2@A, L3@B, ...
1548 BC_L could end up pointing at location L2, while the "master"
1549 location could be L1. Since the `loc->inserted' flag is only set
1550 on "master" locations, we'd forget to restore the shadow of L1
1553 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1556 /* Now do full processing of the found relevant range of elements. */
1558 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1560 struct bp_location
*bl
= bp_locations
[bc
];
1562 /* bp_location array has BL->OWNER always non-NULL. */
1563 if (bl
->owner
->type
== bp_none
)
1564 warning (_("reading through apparently deleted breakpoint #%d?"),
1567 /* Performance optimization: any further element can no longer affect BUF
1570 if (bl
->address
>= bp_locations_placed_address_before_address_max
1571 && memaddr
+ len
<= (bl
->address
1572 - bp_locations_placed_address_before_address_max
))
1575 if (!bp_location_has_shadow (bl
))
1578 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1579 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1583 /* See breakpoint.h. */
1586 is_breakpoint (const struct breakpoint
*bpt
)
1588 return (bpt
->type
== bp_breakpoint
1589 || bpt
->type
== bp_hardware_breakpoint
1590 || bpt
->type
== bp_dprintf
);
1593 /* Return true if BPT is of any hardware watchpoint kind. */
1596 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1598 return (bpt
->type
== bp_hardware_watchpoint
1599 || bpt
->type
== bp_read_watchpoint
1600 || bpt
->type
== bp_access_watchpoint
);
1603 /* See breakpoint.h. */
1606 is_watchpoint (const struct breakpoint
*bpt
)
1608 return (is_hardware_watchpoint (bpt
)
1609 || bpt
->type
== bp_watchpoint
);
1612 /* Returns true if the current thread and its running state are safe
1613 to evaluate or update watchpoint B. Watchpoints on local
1614 expressions need to be evaluated in the context of the thread that
1615 was current when the watchpoint was created, and, that thread needs
1616 to be stopped to be able to select the correct frame context.
1617 Watchpoints on global expressions can be evaluated on any thread,
1618 and in any state. It is presently left to the target allowing
1619 memory accesses when threads are running. */
1622 watchpoint_in_thread_scope (struct watchpoint
*b
)
1624 return (b
->pspace
== current_program_space
1625 && (b
->watchpoint_thread
== null_ptid
1626 || (inferior_ptid
== b
->watchpoint_thread
1627 && !inferior_thread ()->executing
)));
1630 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1631 associated bp_watchpoint_scope breakpoint. */
1634 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1636 if (w
->related_breakpoint
!= w
)
1638 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1639 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1640 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1641 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1642 w
->related_breakpoint
= w
;
1644 w
->disposition
= disp_del_at_next_stop
;
1647 /* Extract a bitfield value from value VAL using the bit parameters contained in
1650 static struct value
*
1651 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1653 struct value
*bit_val
;
1658 bit_val
= allocate_value (value_type (val
));
1660 unpack_value_bitfield (bit_val
,
1663 value_contents_for_printing (val
),
1670 /* Allocate a dummy location and add it to B, which must be a software
1671 watchpoint. This is required because even if a software watchpoint
1672 is not watching any memory, bpstat_stop_status requires a location
1673 to be able to report stops. */
1676 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1677 struct program_space
*pspace
)
1679 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1681 b
->loc
= allocate_bp_location (b
);
1682 b
->loc
->pspace
= pspace
;
1683 b
->loc
->address
= -1;
1684 b
->loc
->length
= -1;
1687 /* Returns true if B is a software watchpoint that is not watching any
1688 memory (e.g., "watch $pc"). */
1691 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1693 return (b
->type
== bp_watchpoint
1695 && b
->loc
->next
== NULL
1696 && b
->loc
->address
== -1
1697 && b
->loc
->length
== -1);
1700 /* Assuming that B is a watchpoint:
1701 - Reparse watchpoint expression, if REPARSE is non-zero
1702 - Evaluate expression and store the result in B->val
1703 - Evaluate the condition if there is one, and store the result
1705 - Update the list of values that must be watched in B->loc.
1707 If the watchpoint disposition is disp_del_at_next_stop, then do
1708 nothing. If this is local watchpoint that is out of scope, delete
1711 Even with `set breakpoint always-inserted on' the watchpoints are
1712 removed + inserted on each stop here. Normal breakpoints must
1713 never be removed because they might be missed by a running thread
1714 when debugging in non-stop mode. On the other hand, hardware
1715 watchpoints (is_hardware_watchpoint; processed here) are specific
1716 to each LWP since they are stored in each LWP's hardware debug
1717 registers. Therefore, such LWP must be stopped first in order to
1718 be able to modify its hardware watchpoints.
1720 Hardware watchpoints must be reset exactly once after being
1721 presented to the user. It cannot be done sooner, because it would
1722 reset the data used to present the watchpoint hit to the user. And
1723 it must not be done later because it could display the same single
1724 watchpoint hit during multiple GDB stops. Note that the latter is
1725 relevant only to the hardware watchpoint types bp_read_watchpoint
1726 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1727 not user-visible - its hit is suppressed if the memory content has
1730 The following constraints influence the location where we can reset
1731 hardware watchpoints:
1733 * target_stopped_by_watchpoint and target_stopped_data_address are
1734 called several times when GDB stops.
1737 * Multiple hardware watchpoints can be hit at the same time,
1738 causing GDB to stop. GDB only presents one hardware watchpoint
1739 hit at a time as the reason for stopping, and all the other hits
1740 are presented later, one after the other, each time the user
1741 requests the execution to be resumed. Execution is not resumed
1742 for the threads still having pending hit event stored in
1743 LWP_INFO->STATUS. While the watchpoint is already removed from
1744 the inferior on the first stop the thread hit event is kept being
1745 reported from its cached value by linux_nat_stopped_data_address
1746 until the real thread resume happens after the watchpoint gets
1747 presented and thus its LWP_INFO->STATUS gets reset.
1749 Therefore the hardware watchpoint hit can get safely reset on the
1750 watchpoint removal from inferior. */
1753 update_watchpoint (struct watchpoint
*b
, int reparse
)
1755 int within_current_scope
;
1756 struct frame_id saved_frame_id
;
1759 /* If this is a local watchpoint, we only want to check if the
1760 watchpoint frame is in scope if the current thread is the thread
1761 that was used to create the watchpoint. */
1762 if (!watchpoint_in_thread_scope (b
))
1765 if (b
->disposition
== disp_del_at_next_stop
)
1770 /* Determine if the watchpoint is within scope. */
1771 if (b
->exp_valid_block
== NULL
)
1772 within_current_scope
= 1;
1775 struct frame_info
*fi
= get_current_frame ();
1776 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1777 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1779 /* If we're at a point where the stack has been destroyed
1780 (e.g. in a function epilogue), unwinding may not work
1781 properly. Do not attempt to recreate locations at this
1782 point. See similar comments in watchpoint_check. */
1783 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1786 /* Save the current frame's ID so we can restore it after
1787 evaluating the watchpoint expression on its own frame. */
1788 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1789 took a frame parameter, so that we didn't have to change the
1792 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1794 fi
= frame_find_by_id (b
->watchpoint_frame
);
1795 within_current_scope
= (fi
!= NULL
);
1796 if (within_current_scope
)
1800 /* We don't free locations. They are stored in the bp_location array
1801 and update_global_location_list will eventually delete them and
1802 remove breakpoints if needed. */
1805 if (within_current_scope
&& reparse
)
1810 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1811 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1812 /* If the meaning of expression itself changed, the old value is
1813 no longer relevant. We don't want to report a watchpoint hit
1814 to the user when the old value and the new value may actually
1815 be completely different objects. */
1817 b
->val_valid
= false;
1819 /* Note that unlike with breakpoints, the watchpoint's condition
1820 expression is stored in the breakpoint object, not in the
1821 locations (re)created below. */
1822 if (b
->cond_string
!= NULL
)
1824 b
->cond_exp
.reset ();
1827 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1831 /* If we failed to parse the expression, for example because
1832 it refers to a global variable in a not-yet-loaded shared library,
1833 don't try to insert watchpoint. We don't automatically delete
1834 such watchpoint, though, since failure to parse expression
1835 is different from out-of-scope watchpoint. */
1836 if (!target_has_execution ())
1838 /* Without execution, memory can't change. No use to try and
1839 set watchpoint locations. The watchpoint will be reset when
1840 the target gains execution, through breakpoint_re_set. */
1841 if (!can_use_hw_watchpoints
)
1843 if (b
->ops
->works_in_software_mode (b
))
1844 b
->type
= bp_watchpoint
;
1846 error (_("Can't set read/access watchpoint when "
1847 "hardware watchpoints are disabled."));
1850 else if (within_current_scope
&& b
->exp
)
1853 std::vector
<value_ref_ptr
> val_chain
;
1854 struct value
*v
, *result
;
1855 struct program_space
*frame_pspace
;
1857 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1859 /* Avoid setting b->val if it's already set. The meaning of
1860 b->val is 'the last value' user saw, and we should update
1861 it only if we reported that last value to user. As it
1862 happens, the code that reports it updates b->val directly.
1863 We don't keep track of the memory value for masked
1865 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1867 if (b
->val_bitsize
!= 0)
1868 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1869 b
->val
= release_value (v
);
1870 b
->val_valid
= true;
1873 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1875 /* Look at each value on the value chain. */
1876 gdb_assert (!val_chain
.empty ());
1877 for (const value_ref_ptr
&iter
: val_chain
)
1881 /* If it's a memory location, and GDB actually needed
1882 its contents to evaluate the expression, then we
1883 must watch it. If the first value returned is
1884 still lazy, that means an error occurred reading it;
1885 watch it anyway in case it becomes readable. */
1886 if (VALUE_LVAL (v
) == lval_memory
1887 && (v
== val_chain
[0] || ! value_lazy (v
)))
1889 struct type
*vtype
= check_typedef (value_type (v
));
1891 /* We only watch structs and arrays if user asked
1892 for it explicitly, never if they just happen to
1893 appear in the middle of some value chain. */
1895 || (vtype
->code () != TYPE_CODE_STRUCT
1896 && vtype
->code () != TYPE_CODE_ARRAY
))
1899 enum target_hw_bp_type type
;
1900 struct bp_location
*loc
, **tmp
;
1901 int bitpos
= 0, bitsize
= 0;
1903 if (value_bitsize (v
) != 0)
1905 /* Extract the bit parameters out from the bitfield
1907 bitpos
= value_bitpos (v
);
1908 bitsize
= value_bitsize (v
);
1910 else if (v
== result
&& b
->val_bitsize
!= 0)
1912 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1913 lvalue whose bit parameters are saved in the fields
1914 VAL_BITPOS and VAL_BITSIZE. */
1915 bitpos
= b
->val_bitpos
;
1916 bitsize
= b
->val_bitsize
;
1919 addr
= value_address (v
);
1922 /* Skip the bytes that don't contain the bitfield. */
1927 if (b
->type
== bp_read_watchpoint
)
1929 else if (b
->type
== bp_access_watchpoint
)
1932 loc
= allocate_bp_location (b
);
1933 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1936 loc
->gdbarch
= get_type_arch (value_type (v
));
1938 loc
->pspace
= frame_pspace
;
1939 loc
->address
= address_significant (loc
->gdbarch
, addr
);
1943 /* Just cover the bytes that make up the bitfield. */
1944 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1947 loc
->length
= TYPE_LENGTH (value_type (v
));
1949 loc
->watchpoint_type
= type
;
1954 /* Change the type of breakpoint between hardware assisted or
1955 an ordinary watchpoint depending on the hardware support
1956 and free hardware slots. REPARSE is set when the inferior
1961 enum bp_loc_type loc_type
;
1962 struct bp_location
*bl
;
1964 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1968 int i
, target_resources_ok
, other_type_used
;
1971 /* Use an exact watchpoint when there's only one memory region to be
1972 watched, and only one debug register is needed to watch it. */
1973 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1975 /* We need to determine how many resources are already
1976 used for all other hardware watchpoints plus this one
1977 to see if we still have enough resources to also fit
1978 this watchpoint in as well. */
1980 /* If this is a software watchpoint, we try to turn it
1981 to a hardware one -- count resources as if B was of
1982 hardware watchpoint type. */
1984 if (type
== bp_watchpoint
)
1985 type
= bp_hardware_watchpoint
;
1987 /* This watchpoint may or may not have been placed on
1988 the list yet at this point (it won't be in the list
1989 if we're trying to create it for the first time,
1990 through watch_command), so always account for it
1993 /* Count resources used by all watchpoints except B. */
1994 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1996 /* Add in the resources needed for B. */
1997 i
+= hw_watchpoint_use_count (b
);
2000 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2001 if (target_resources_ok
<= 0)
2003 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2005 if (target_resources_ok
== 0 && !sw_mode
)
2006 error (_("Target does not support this type of "
2007 "hardware watchpoint."));
2008 else if (target_resources_ok
< 0 && !sw_mode
)
2009 error (_("There are not enough available hardware "
2010 "resources for this watchpoint."));
2012 /* Downgrade to software watchpoint. */
2013 b
->type
= bp_watchpoint
;
2017 /* If this was a software watchpoint, we've just
2018 found we have enough resources to turn it to a
2019 hardware watchpoint. Otherwise, this is a
2024 else if (!b
->ops
->works_in_software_mode (b
))
2026 if (!can_use_hw_watchpoints
)
2027 error (_("Can't set read/access watchpoint when "
2028 "hardware watchpoints are disabled."));
2030 error (_("Expression cannot be implemented with "
2031 "read/access watchpoint."));
2034 b
->type
= bp_watchpoint
;
2036 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2037 : bp_loc_hardware_watchpoint
);
2038 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
2039 bl
->loc_type
= loc_type
;
2042 /* If a software watchpoint is not watching any memory, then the
2043 above left it without any location set up. But,
2044 bpstat_stop_status requires a location to be able to report
2045 stops, so make sure there's at least a dummy one. */
2046 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2047 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2049 else if (!within_current_scope
)
2051 printf_filtered (_("\
2052 Watchpoint %d deleted because the program has left the block\n\
2053 in which its expression is valid.\n"),
2055 watchpoint_del_at_next_stop (b
);
2058 /* Restore the selected frame. */
2060 select_frame (frame_find_by_id (saved_frame_id
));
2064 /* Returns 1 iff breakpoint location should be
2065 inserted in the inferior. We don't differentiate the type of BL's owner
2066 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2067 breakpoint_ops is not defined, because in insert_bp_location,
2068 tracepoint's insert_location will not be called. */
2070 should_be_inserted (struct bp_location
*bl
)
2072 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2075 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2078 if (!bl
->enabled
|| bl
->disabled_by_cond
2079 || bl
->shlib_disabled
|| bl
->duplicate
)
2082 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2085 /* This is set for example, when we're attached to the parent of a
2086 vfork, and have detached from the child. The child is running
2087 free, and we expect it to do an exec or exit, at which point the
2088 OS makes the parent schedulable again (and the target reports
2089 that the vfork is done). Until the child is done with the shared
2090 memory region, do not insert breakpoints in the parent, otherwise
2091 the child could still trip on the parent's breakpoints. Since
2092 the parent is blocked anyway, it won't miss any breakpoint. */
2093 if (bl
->pspace
->breakpoints_not_allowed
)
2096 /* Don't insert a breakpoint if we're trying to step past its
2097 location, except if the breakpoint is a single-step breakpoint,
2098 and the breakpoint's thread is the thread which is stepping past
2100 if ((bl
->loc_type
== bp_loc_software_breakpoint
2101 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2102 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2104 /* The single-step breakpoint may be inserted at the location
2105 we're trying to step if the instruction branches to itself.
2106 However, the instruction won't be executed at all and it may
2107 break the semantics of the instruction, for example, the
2108 instruction is a conditional branch or updates some flags.
2109 We can't fix it unless GDB is able to emulate the instruction
2110 or switch to displaced stepping. */
2111 && !(bl
->owner
->type
== bp_single_step
2112 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2114 infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s",
2115 paddress (bl
->gdbarch
, bl
->address
));
2119 /* Don't insert watchpoints if we're trying to step past the
2120 instruction that triggered one. */
2121 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2122 && stepping_past_nonsteppable_watchpoint ())
2124 infrun_debug_printf ("stepping past non-steppable watchpoint. "
2125 "skipping watchpoint at %s:%d\n",
2126 paddress (bl
->gdbarch
, bl
->address
), bl
->length
);
2133 /* Same as should_be_inserted but does the check assuming
2134 that the location is not duplicated. */
2137 unduplicated_should_be_inserted (struct bp_location
*bl
)
2140 const int save_duplicate
= bl
->duplicate
;
2143 result
= should_be_inserted (bl
);
2144 bl
->duplicate
= save_duplicate
;
2148 /* Parses a conditional described by an expression COND into an
2149 agent expression bytecode suitable for evaluation
2150 by the bytecode interpreter. Return NULL if there was
2151 any error during parsing. */
2153 static agent_expr_up
2154 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2159 agent_expr_up aexpr
;
2161 /* We don't want to stop processing, so catch any errors
2162 that may show up. */
2165 aexpr
= gen_eval_for_expr (scope
, cond
);
2168 catch (const gdb_exception_error
&ex
)
2170 /* If we got here, it means the condition could not be parsed to a valid
2171 bytecode expression and thus can't be evaluated on the target's side.
2172 It's no use iterating through the conditions. */
2175 /* We have a valid agent expression. */
2179 /* Based on location BL, create a list of breakpoint conditions to be
2180 passed on to the target. If we have duplicated locations with different
2181 conditions, we will add such conditions to the list. The idea is that the
2182 target will evaluate the list of conditions and will only notify GDB when
2183 one of them is true. */
2186 build_target_condition_list (struct bp_location
*bl
)
2188 struct bp_location
**locp
= NULL
, **loc2p
;
2189 int null_condition_or_parse_error
= 0;
2190 int modified
= bl
->needs_update
;
2191 struct bp_location
*loc
;
2193 /* Release conditions left over from a previous insert. */
2194 bl
->target_info
.conditions
.clear ();
2196 /* This is only meaningful if the target is
2197 evaluating conditions and if the user has
2198 opted for condition evaluation on the target's
2200 if (gdb_evaluates_breakpoint_condition_p ()
2201 || !target_supports_evaluation_of_breakpoint_conditions ())
2204 /* Do a first pass to check for locations with no assigned
2205 conditions or conditions that fail to parse to a valid agent
2206 expression bytecode. If any of these happen, then it's no use to
2207 send conditions to the target since this location will always
2208 trigger and generate a response back to GDB. Note we consider
2209 all locations at the same address irrespective of type, i.e.,
2210 even if the locations aren't considered duplicates (e.g.,
2211 software breakpoint and hardware breakpoint at the same
2213 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2216 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2220 /* Re-parse the conditions since something changed. In that
2221 case we already freed the condition bytecodes (see
2222 force_breakpoint_reinsertion). We just
2223 need to parse the condition to bytecodes again. */
2224 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2228 /* If we have a NULL bytecode expression, it means something
2229 went wrong or we have a null condition expression. */
2230 if (!loc
->cond_bytecode
)
2232 null_condition_or_parse_error
= 1;
2238 /* If any of these happened, it means we will have to evaluate the conditions
2239 for the location's address on gdb's side. It is no use keeping bytecodes
2240 for all the other duplicate locations, thus we free all of them here.
2242 This is so we have a finer control over which locations' conditions are
2243 being evaluated by GDB or the remote stub. */
2244 if (null_condition_or_parse_error
)
2246 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2249 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2251 /* Only go as far as the first NULL bytecode is
2253 if (!loc
->cond_bytecode
)
2256 loc
->cond_bytecode
.reset ();
2261 /* No NULL conditions or failed bytecode generation. Build a
2262 condition list for this location's address. If we have software
2263 and hardware locations at the same address, they aren't
2264 considered duplicates, but we still marge all the conditions
2265 anyway, as it's simpler, and doesn't really make a practical
2267 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2271 && is_breakpoint (loc
->owner
)
2272 && loc
->pspace
->num
== bl
->pspace
->num
2273 && loc
->owner
->enable_state
== bp_enabled
2275 && !loc
->disabled_by_cond
)
2277 /* Add the condition to the vector. This will be used later
2278 to send the conditions to the target. */
2279 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2286 /* Parses a command described by string CMD into an agent expression
2287 bytecode suitable for evaluation by the bytecode interpreter.
2288 Return NULL if there was any error during parsing. */
2290 static agent_expr_up
2291 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2293 const char *cmdrest
;
2294 const char *format_start
, *format_end
;
2295 struct gdbarch
*gdbarch
= get_current_arch ();
2302 if (*cmdrest
== ',')
2304 cmdrest
= skip_spaces (cmdrest
);
2306 if (*cmdrest
++ != '"')
2307 error (_("No format string following the location"));
2309 format_start
= cmdrest
;
2311 format_pieces
fpieces (&cmdrest
);
2313 format_end
= cmdrest
;
2315 if (*cmdrest
++ != '"')
2316 error (_("Bad format string, non-terminated '\"'."));
2318 cmdrest
= skip_spaces (cmdrest
);
2320 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2321 error (_("Invalid argument syntax"));
2323 if (*cmdrest
== ',')
2325 cmdrest
= skip_spaces (cmdrest
);
2327 /* For each argument, make an expression. */
2329 std::vector
<struct expression
*> argvec
;
2330 while (*cmdrest
!= '\0')
2335 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2336 argvec
.push_back (expr
.release ());
2338 if (*cmdrest
== ',')
2342 agent_expr_up aexpr
;
2344 /* We don't want to stop processing, so catch any errors
2345 that may show up. */
2348 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2349 format_start
, format_end
- format_start
,
2350 argvec
.size (), argvec
.data ());
2352 catch (const gdb_exception_error
&ex
)
2354 /* If we got here, it means the command could not be parsed to a valid
2355 bytecode expression and thus can't be evaluated on the target's side.
2356 It's no use iterating through the other commands. */
2359 /* We have a valid agent expression, return it. */
2363 /* Based on location BL, create a list of breakpoint commands to be
2364 passed on to the target. If we have duplicated locations with
2365 different commands, we will add any such to the list. */
2368 build_target_command_list (struct bp_location
*bl
)
2370 struct bp_location
**locp
= NULL
, **loc2p
;
2371 int null_command_or_parse_error
= 0;
2372 int modified
= bl
->needs_update
;
2373 struct bp_location
*loc
;
2375 /* Clear commands left over from a previous insert. */
2376 bl
->target_info
.tcommands
.clear ();
2378 if (!target_can_run_breakpoint_commands ())
2381 /* For now, limit to agent-style dprintf breakpoints. */
2382 if (dprintf_style
!= dprintf_style_agent
)
2385 /* For now, if we have any location at the same address that isn't a
2386 dprintf, don't install the target-side commands, as that would
2387 make the breakpoint not be reported to the core, and we'd lose
2389 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2392 if (is_breakpoint (loc
->owner
)
2393 && loc
->pspace
->num
== bl
->pspace
->num
2394 && loc
->owner
->type
!= bp_dprintf
)
2398 /* Do a first pass to check for locations with no assigned
2399 conditions or conditions that fail to parse to a valid agent expression
2400 bytecode. If any of these happen, then it's no use to send conditions
2401 to the target since this location will always trigger and generate a
2402 response back to GDB. */
2403 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2406 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2410 /* Re-parse the commands since something changed. In that
2411 case we already freed the command bytecodes (see
2412 force_breakpoint_reinsertion). We just
2413 need to parse the command to bytecodes again. */
2415 = parse_cmd_to_aexpr (bl
->address
,
2416 loc
->owner
->extra_string
);
2419 /* If we have a NULL bytecode expression, it means something
2420 went wrong or we have a null command expression. */
2421 if (!loc
->cmd_bytecode
)
2423 null_command_or_parse_error
= 1;
2429 /* If anything failed, then we're not doing target-side commands,
2431 if (null_command_or_parse_error
)
2433 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2436 if (is_breakpoint (loc
->owner
)
2437 && loc
->pspace
->num
== bl
->pspace
->num
)
2439 /* Only go as far as the first NULL bytecode is
2441 if (loc
->cmd_bytecode
== NULL
)
2444 loc
->cmd_bytecode
.reset ();
2449 /* No NULL commands or failed bytecode generation. Build a command
2450 list for all duplicate locations at this location's address.
2451 Note that here we must care for whether the breakpoint location
2452 types are considered duplicates, otherwise, say, if we have a
2453 software and hardware location at the same address, the target
2454 could end up running the commands twice. For the moment, we only
2455 support targets-side commands with dprintf, but it doesn't hurt
2456 to be pedantically correct in case that changes. */
2457 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2460 if (breakpoint_locations_match (bl
, loc
)
2461 && loc
->owner
->extra_string
2462 && is_breakpoint (loc
->owner
)
2463 && loc
->pspace
->num
== bl
->pspace
->num
2464 && loc
->owner
->enable_state
== bp_enabled
2466 && !loc
->disabled_by_cond
)
2468 /* Add the command to the vector. This will be used later
2469 to send the commands to the target. */
2470 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2474 bl
->target_info
.persist
= 0;
2475 /* Maybe flag this location as persistent. */
2476 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2477 bl
->target_info
.persist
= 1;
2480 /* Return the kind of breakpoint on address *ADDR. Get the kind
2481 of breakpoint according to ADDR except single-step breakpoint.
2482 Get the kind of single-step breakpoint according to the current
2486 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2488 if (bl
->owner
->type
== bp_single_step
)
2490 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2491 struct regcache
*regcache
;
2493 regcache
= get_thread_regcache (thr
);
2495 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2499 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2502 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2503 location. Any error messages are printed to TMP_ERROR_STREAM; and
2504 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2505 Returns 0 for success, 1 if the bp_location type is not supported or
2508 NOTE drow/2003-09-09: This routine could be broken down to an
2509 object-style method for each breakpoint or catchpoint type. */
2511 insert_bp_location (struct bp_location
*bl
,
2512 struct ui_file
*tmp_error_stream
,
2513 int *disabled_breaks
,
2514 int *hw_breakpoint_error
,
2515 int *hw_bp_error_explained_already
)
2517 gdb_exception bp_excpt
;
2519 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2522 /* Note we don't initialize bl->target_info, as that wipes out
2523 the breakpoint location's shadow_contents if the breakpoint
2524 is still inserted at that location. This in turn breaks
2525 target_read_memory which depends on these buffers when
2526 a memory read is requested at the breakpoint location:
2527 Once the target_info has been wiped, we fail to see that
2528 we have a breakpoint inserted at that address and thus
2529 read the breakpoint instead of returning the data saved in
2530 the breakpoint location's shadow contents. */
2531 bl
->target_info
.reqstd_address
= bl
->address
;
2532 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2533 bl
->target_info
.length
= bl
->length
;
2535 /* When working with target-side conditions, we must pass all the conditions
2536 for the same breakpoint address down to the target since GDB will not
2537 insert those locations. With a list of breakpoint conditions, the target
2538 can decide when to stop and notify GDB. */
2540 if (is_breakpoint (bl
->owner
))
2542 build_target_condition_list (bl
);
2543 build_target_command_list (bl
);
2544 /* Reset the modification marker. */
2545 bl
->needs_update
= 0;
2548 /* If "set breakpoint auto-hw" is "on" and a software breakpoint was
2549 set at a read-only address, then a breakpoint location will have
2550 been changed to hardware breakpoint before we get here. If it is
2551 "off" however, error out before actually trying to insert the
2552 breakpoint, with a nicer error message. */
2553 if (bl
->loc_type
== bp_loc_software_breakpoint
2554 && !automatic_hardware_breakpoints
)
2556 mem_region
*mr
= lookup_mem_region (bl
->address
);
2558 if (mr
!= nullptr && mr
->attrib
.mode
!= MEM_RW
)
2560 fprintf_unfiltered (tmp_error_stream
,
2561 _("Cannot insert breakpoint %d.\n"
2562 "Cannot set software breakpoint "
2563 "at read-only address %s\n"),
2565 paddress (bl
->gdbarch
, bl
->address
));
2570 if (bl
->loc_type
== bp_loc_software_breakpoint
2571 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2573 /* First check to see if we have to handle an overlay. */
2574 if (overlay_debugging
== ovly_off
2575 || bl
->section
== NULL
2576 || !(section_is_overlay (bl
->section
)))
2578 /* No overlay handling: just set the breakpoint. */
2583 val
= bl
->owner
->ops
->insert_location (bl
);
2585 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2587 catch (gdb_exception
&e
)
2589 bp_excpt
= std::move (e
);
2594 /* This breakpoint is in an overlay section.
2595 Shall we set a breakpoint at the LMA? */
2596 if (!overlay_events_enabled
)
2598 /* Yes -- overlay event support is not active,
2599 so we must try to set a breakpoint at the LMA.
2600 This will not work for a hardware breakpoint. */
2601 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2602 warning (_("hardware breakpoint %d not supported in overlay!"),
2606 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2608 /* Set a software (trap) breakpoint at the LMA. */
2609 bl
->overlay_target_info
= bl
->target_info
;
2610 bl
->overlay_target_info
.reqstd_address
= addr
;
2612 /* No overlay handling: just set the breakpoint. */
2617 bl
->overlay_target_info
.kind
2618 = breakpoint_kind (bl
, &addr
);
2619 bl
->overlay_target_info
.placed_address
= addr
;
2620 val
= target_insert_breakpoint (bl
->gdbarch
,
2621 &bl
->overlay_target_info
);
2624 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2626 catch (gdb_exception
&e
)
2628 bp_excpt
= std::move (e
);
2631 if (bp_excpt
.reason
!= 0)
2632 fprintf_unfiltered (tmp_error_stream
,
2633 "Overlay breakpoint %d "
2634 "failed: in ROM?\n",
2638 /* Shall we set a breakpoint at the VMA? */
2639 if (section_is_mapped (bl
->section
))
2641 /* Yes. This overlay section is mapped into memory. */
2646 val
= bl
->owner
->ops
->insert_location (bl
);
2648 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2650 catch (gdb_exception
&e
)
2652 bp_excpt
= std::move (e
);
2657 /* No. This breakpoint will not be inserted.
2658 No error, but do not mark the bp as 'inserted'. */
2663 if (bp_excpt
.reason
!= 0)
2665 /* Can't set the breakpoint. */
2667 /* In some cases, we might not be able to insert a
2668 breakpoint in a shared library that has already been
2669 removed, but we have not yet processed the shlib unload
2670 event. Unfortunately, some targets that implement
2671 breakpoint insertion themselves can't tell why the
2672 breakpoint insertion failed (e.g., the remote target
2673 doesn't define error codes), so we must treat generic
2674 errors as memory errors. */
2675 if (bp_excpt
.reason
== RETURN_ERROR
2676 && (bp_excpt
.error
== GENERIC_ERROR
2677 || bp_excpt
.error
== MEMORY_ERROR
)
2678 && bl
->loc_type
== bp_loc_software_breakpoint
2679 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2680 || shared_objfile_contains_address_p (bl
->pspace
,
2683 /* See also: disable_breakpoints_in_shlibs. */
2684 bl
->shlib_disabled
= 1;
2685 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2686 if (!*disabled_breaks
)
2688 fprintf_unfiltered (tmp_error_stream
,
2689 "Cannot insert breakpoint %d.\n",
2691 fprintf_unfiltered (tmp_error_stream
,
2692 "Temporarily disabling shared "
2693 "library breakpoints:\n");
2695 *disabled_breaks
= 1;
2696 fprintf_unfiltered (tmp_error_stream
,
2697 "breakpoint #%d\n", bl
->owner
->number
);
2702 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2704 *hw_breakpoint_error
= 1;
2705 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2706 fprintf_unfiltered (tmp_error_stream
,
2707 "Cannot insert hardware breakpoint %d%s",
2709 bp_excpt
.message
? ":" : ".\n");
2710 if (bp_excpt
.message
!= NULL
)
2711 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2716 if (bp_excpt
.message
== NULL
)
2719 = memory_error_message (TARGET_XFER_E_IO
,
2720 bl
->gdbarch
, bl
->address
);
2722 fprintf_unfiltered (tmp_error_stream
,
2723 "Cannot insert breakpoint %d.\n"
2725 bl
->owner
->number
, message
.c_str ());
2729 fprintf_unfiltered (tmp_error_stream
,
2730 "Cannot insert breakpoint %d: %s\n",
2745 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2746 /* NOTE drow/2003-09-08: This state only exists for removing
2747 watchpoints. It's not clear that it's necessary... */
2748 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2752 gdb_assert (bl
->owner
->ops
!= NULL
2753 && bl
->owner
->ops
->insert_location
!= NULL
);
2755 val
= bl
->owner
->ops
->insert_location (bl
);
2757 /* If trying to set a read-watchpoint, and it turns out it's not
2758 supported, try emulating one with an access watchpoint. */
2759 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2761 struct bp_location
*loc
, **loc_temp
;
2763 /* But don't try to insert it, if there's already another
2764 hw_access location that would be considered a duplicate
2766 ALL_BP_LOCATIONS (loc
, loc_temp
)
2768 && loc
->watchpoint_type
== hw_access
2769 && watchpoint_locations_match (bl
, loc
))
2773 bl
->target_info
= loc
->target_info
;
2774 bl
->watchpoint_type
= hw_access
;
2781 bl
->watchpoint_type
= hw_access
;
2782 val
= bl
->owner
->ops
->insert_location (bl
);
2785 /* Back to the original value. */
2786 bl
->watchpoint_type
= hw_read
;
2790 bl
->inserted
= (val
== 0);
2793 else if (bl
->owner
->type
== bp_catchpoint
)
2797 gdb_assert (bl
->owner
->ops
!= NULL
2798 && bl
->owner
->ops
->insert_location
!= NULL
);
2800 val
= bl
->owner
->ops
->insert_location (bl
);
2803 bl
->owner
->enable_state
= bp_disabled
;
2807 Error inserting catchpoint %d: Your system does not support this type\n\
2808 of catchpoint."), bl
->owner
->number
);
2810 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2813 bl
->inserted
= (val
== 0);
2815 /* We've already printed an error message if there was a problem
2816 inserting this catchpoint, and we've disabled the catchpoint,
2817 so just return success. */
2824 /* This function is called when program space PSPACE is about to be
2825 deleted. It takes care of updating breakpoints to not reference
2829 breakpoint_program_space_exit (struct program_space
*pspace
)
2831 struct breakpoint
*b
, *b_temp
;
2832 struct bp_location
*loc
, **loc_temp
;
2834 /* Remove any breakpoint that was set through this program space. */
2835 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2837 if (b
->pspace
== pspace
)
2838 delete_breakpoint (b
);
2841 /* Breakpoints set through other program spaces could have locations
2842 bound to PSPACE as well. Remove those. */
2843 ALL_BP_LOCATIONS (loc
, loc_temp
)
2845 struct bp_location
*tmp
;
2847 if (loc
->pspace
== pspace
)
2849 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2850 if (loc
->owner
->loc
== loc
)
2851 loc
->owner
->loc
= loc
->next
;
2853 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2854 if (tmp
->next
== loc
)
2856 tmp
->next
= loc
->next
;
2862 /* Now update the global location list to permanently delete the
2863 removed locations above. */
2864 update_global_location_list (UGLL_DONT_INSERT
);
2867 /* Make sure all breakpoints are inserted in inferior.
2868 Throws exception on any error.
2869 A breakpoint that is already inserted won't be inserted
2870 again, so calling this function twice is safe. */
2872 insert_breakpoints (void)
2874 struct breakpoint
*bpt
;
2876 ALL_BREAKPOINTS (bpt
)
2877 if (is_hardware_watchpoint (bpt
))
2879 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2881 update_watchpoint (w
, 0 /* don't reparse. */);
2884 /* Updating watchpoints creates new locations, so update the global
2885 location list. Explicitly tell ugll to insert locations and
2886 ignore breakpoints_always_inserted_mode. Also,
2887 update_global_location_list tries to "upgrade" software
2888 breakpoints to hardware breakpoints to handle "set breakpoint
2889 auto-hw", so we need to call it even if we don't have new
2891 update_global_location_list (UGLL_INSERT
);
2894 /* Invoke CALLBACK for each of bp_location. */
2897 iterate_over_bp_locations (walk_bp_location_callback callback
)
2899 struct bp_location
*loc
, **loc_tmp
;
2901 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2903 callback (loc
, NULL
);
2907 /* This is used when we need to synch breakpoint conditions between GDB and the
2908 target. It is the case with deleting and disabling of breakpoints when using
2909 always-inserted mode. */
2912 update_inserted_breakpoint_locations (void)
2914 struct bp_location
*bl
, **blp_tmp
;
2917 int disabled_breaks
= 0;
2918 int hw_breakpoint_error
= 0;
2919 int hw_bp_details_reported
= 0;
2921 string_file tmp_error_stream
;
2923 /* Explicitly mark the warning -- this will only be printed if
2924 there was an error. */
2925 tmp_error_stream
.puts ("Warning:\n");
2927 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2929 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2931 /* We only want to update software breakpoints and hardware
2933 if (!is_breakpoint (bl
->owner
))
2936 /* We only want to update locations that are already inserted
2937 and need updating. This is to avoid unwanted insertion during
2938 deletion of breakpoints. */
2939 if (!bl
->inserted
|| !bl
->needs_update
)
2942 switch_to_program_space_and_thread (bl
->pspace
);
2944 /* For targets that support global breakpoints, there's no need
2945 to select an inferior to insert breakpoint to. In fact, even
2946 if we aren't attached to any process yet, we should still
2947 insert breakpoints. */
2948 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2949 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
2952 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2953 &hw_breakpoint_error
, &hw_bp_details_reported
);
2960 target_terminal::ours_for_output ();
2961 error_stream (tmp_error_stream
);
2965 /* Used when starting or continuing the program. */
2968 insert_breakpoint_locations (void)
2970 struct breakpoint
*bpt
;
2971 struct bp_location
*bl
, **blp_tmp
;
2974 int disabled_breaks
= 0;
2975 int hw_breakpoint_error
= 0;
2976 int hw_bp_error_explained_already
= 0;
2978 string_file tmp_error_stream
;
2980 /* Explicitly mark the warning -- this will only be printed if
2981 there was an error. */
2982 tmp_error_stream
.puts ("Warning:\n");
2984 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2986 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2988 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2991 /* There is no point inserting thread-specific breakpoints if
2992 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2993 has BL->OWNER always non-NULL. */
2994 if (bl
->owner
->thread
!= -1
2995 && !valid_global_thread_id (bl
->owner
->thread
))
2998 switch_to_program_space_and_thread (bl
->pspace
);
3000 /* For targets that support global breakpoints, there's no need
3001 to select an inferior to insert breakpoint to. In fact, even
3002 if we aren't attached to any process yet, we should still
3003 insert breakpoints. */
3004 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3005 && (inferior_ptid
== null_ptid
|| !target_has_execution ()))
3008 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3009 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3014 /* If we failed to insert all locations of a watchpoint, remove
3015 them, as half-inserted watchpoint is of limited use. */
3016 ALL_BREAKPOINTS (bpt
)
3018 int some_failed
= 0;
3019 struct bp_location
*loc
;
3021 if (!is_hardware_watchpoint (bpt
))
3024 if (!breakpoint_enabled (bpt
))
3027 if (bpt
->disposition
== disp_del_at_next_stop
)
3030 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3031 if (!loc
->inserted
&& should_be_inserted (loc
))
3038 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3040 remove_breakpoint (loc
);
3042 hw_breakpoint_error
= 1;
3043 tmp_error_stream
.printf ("Could not insert "
3044 "hardware watchpoint %d.\n",
3052 /* If a hardware breakpoint or watchpoint was inserted, add a
3053 message about possibly exhausted resources. */
3054 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3056 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3057 You may have requested too many hardware breakpoints/watchpoints.\n");
3059 target_terminal::ours_for_output ();
3060 error_stream (tmp_error_stream
);
3064 /* Used when the program stops.
3065 Returns zero if successful, or non-zero if there was a problem
3066 removing a breakpoint location. */
3069 remove_breakpoints (void)
3071 struct bp_location
*bl
, **blp_tmp
;
3074 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3076 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3077 val
|= remove_breakpoint (bl
);
3082 /* When a thread exits, remove breakpoints that are related to
3086 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3088 struct breakpoint
*b
, *b_tmp
;
3090 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3092 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3094 b
->disposition
= disp_del_at_next_stop
;
3096 printf_filtered (_("\
3097 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3098 b
->number
, print_thread_id (tp
));
3100 /* Hide it from the user. */
3106 /* See breakpoint.h. */
3109 remove_breakpoints_inf (inferior
*inf
)
3111 struct bp_location
*bl
, **blp_tmp
;
3114 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3116 if (bl
->pspace
!= inf
->pspace
)
3119 if (bl
->inserted
&& !bl
->target_info
.persist
)
3121 val
= remove_breakpoint (bl
);
3128 static int internal_breakpoint_number
= -1;
3130 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3131 If INTERNAL is non-zero, the breakpoint number will be populated
3132 from internal_breakpoint_number and that variable decremented.
3133 Otherwise the breakpoint number will be populated from
3134 breakpoint_count and that value incremented. Internal breakpoints
3135 do not set the internal var bpnum. */
3137 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3140 b
->number
= internal_breakpoint_number
--;
3143 set_breakpoint_count (breakpoint_count
+ 1);
3144 b
->number
= breakpoint_count
;
3148 static struct breakpoint
*
3149 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3150 CORE_ADDR address
, enum bptype type
,
3151 const struct breakpoint_ops
*ops
)
3153 symtab_and_line sal
;
3155 sal
.section
= find_pc_overlay (sal
.pc
);
3156 sal
.pspace
= current_program_space
;
3158 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3159 b
->number
= internal_breakpoint_number
--;
3160 b
->disposition
= disp_donttouch
;
3165 static const char *const longjmp_names
[] =
3167 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3169 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3171 /* Per-objfile data private to breakpoint.c. */
3172 struct breakpoint_objfile_data
3174 /* Minimal symbol for "_ovly_debug_event" (if any). */
3175 struct bound_minimal_symbol overlay_msym
{};
3177 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3178 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3180 /* True if we have looked for longjmp probes. */
3181 int longjmp_searched
= 0;
3183 /* SystemTap probe points for longjmp (if any). These are non-owning
3185 std::vector
<probe
*> longjmp_probes
;
3187 /* Minimal symbol for "std::terminate()" (if any). */
3188 struct bound_minimal_symbol terminate_msym
{};
3190 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3191 struct bound_minimal_symbol exception_msym
{};
3193 /* True if we have looked for exception probes. */
3194 int exception_searched
= 0;
3196 /* SystemTap probe points for unwinding (if any). These are non-owning
3198 std::vector
<probe
*> exception_probes
;
3201 static const struct objfile_key
<breakpoint_objfile_data
>
3202 breakpoint_objfile_key
;
3204 /* Minimal symbol not found sentinel. */
3205 static struct minimal_symbol msym_not_found
;
3207 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3210 msym_not_found_p (const struct minimal_symbol
*msym
)
3212 return msym
== &msym_not_found
;
3215 /* Return per-objfile data needed by breakpoint.c.
3216 Allocate the data if necessary. */
3218 static struct breakpoint_objfile_data
*
3219 get_breakpoint_objfile_data (struct objfile
*objfile
)
3221 struct breakpoint_objfile_data
*bp_objfile_data
;
3223 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3224 if (bp_objfile_data
== NULL
)
3225 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3226 return bp_objfile_data
;
3230 create_overlay_event_breakpoint (void)
3232 const char *const func_name
= "_ovly_debug_event";
3234 for (objfile
*objfile
: current_program_space
->objfiles ())
3236 struct breakpoint
*b
;
3237 struct breakpoint_objfile_data
*bp_objfile_data
;
3239 struct explicit_location explicit_loc
;
3241 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3243 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3246 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3248 struct bound_minimal_symbol m
;
3250 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3251 if (m
.minsym
== NULL
)
3253 /* Avoid future lookups in this objfile. */
3254 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3257 bp_objfile_data
->overlay_msym
= m
;
3260 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3261 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3263 &internal_breakpoint_ops
);
3264 initialize_explicit_location (&explicit_loc
);
3265 explicit_loc
.function_name
= ASTRDUP (func_name
);
3266 b
->location
= new_explicit_location (&explicit_loc
);
3268 if (overlay_debugging
== ovly_auto
)
3270 b
->enable_state
= bp_enabled
;
3271 overlay_events_enabled
= 1;
3275 b
->enable_state
= bp_disabled
;
3276 overlay_events_enabled
= 0;
3282 create_longjmp_master_breakpoint (void)
3284 scoped_restore_current_program_space restore_pspace
;
3286 for (struct program_space
*pspace
: program_spaces
)
3288 set_current_program_space (pspace
);
3290 for (objfile
*objfile
: current_program_space
->objfiles ())
3293 struct gdbarch
*gdbarch
;
3294 struct breakpoint_objfile_data
*bp_objfile_data
;
3296 gdbarch
= objfile
->arch ();
3298 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3300 if (!bp_objfile_data
->longjmp_searched
)
3302 std::vector
<probe
*> ret
3303 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3307 /* We are only interested in checking one element. */
3310 if (!p
->can_evaluate_arguments ())
3312 /* We cannot use the probe interface here,
3313 because it does not know how to evaluate
3318 bp_objfile_data
->longjmp_probes
= ret
;
3319 bp_objfile_data
->longjmp_searched
= 1;
3322 if (!bp_objfile_data
->longjmp_probes
.empty ())
3324 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3326 struct breakpoint
*b
;
3328 b
= create_internal_breakpoint (gdbarch
,
3329 p
->get_relocated_address (objfile
),
3331 &internal_breakpoint_ops
);
3332 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3333 b
->enable_state
= bp_disabled
;
3339 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3342 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3344 struct breakpoint
*b
;
3345 const char *func_name
;
3347 struct explicit_location explicit_loc
;
3349 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3352 func_name
= longjmp_names
[i
];
3353 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3355 struct bound_minimal_symbol m
;
3357 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3358 if (m
.minsym
== NULL
)
3360 /* Prevent future lookups in this objfile. */
3361 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3364 bp_objfile_data
->longjmp_msym
[i
] = m
;
3367 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3368 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3369 &internal_breakpoint_ops
);
3370 initialize_explicit_location (&explicit_loc
);
3371 explicit_loc
.function_name
= ASTRDUP (func_name
);
3372 b
->location
= new_explicit_location (&explicit_loc
);
3373 b
->enable_state
= bp_disabled
;
3379 /* Create a master std::terminate breakpoint. */
3381 create_std_terminate_master_breakpoint (void)
3383 const char *const func_name
= "std::terminate()";
3385 scoped_restore_current_program_space restore_pspace
;
3387 for (struct program_space
*pspace
: program_spaces
)
3391 set_current_program_space (pspace
);
3393 for (objfile
*objfile
: current_program_space
->objfiles ())
3395 struct breakpoint
*b
;
3396 struct breakpoint_objfile_data
*bp_objfile_data
;
3397 struct explicit_location explicit_loc
;
3399 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3401 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3404 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3406 struct bound_minimal_symbol m
;
3408 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3409 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3410 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3412 /* Prevent future lookups in this objfile. */
3413 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3416 bp_objfile_data
->terminate_msym
= m
;
3419 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3420 b
= create_internal_breakpoint (objfile
->arch (), addr
,
3421 bp_std_terminate_master
,
3422 &internal_breakpoint_ops
);
3423 initialize_explicit_location (&explicit_loc
);
3424 explicit_loc
.function_name
= ASTRDUP (func_name
);
3425 b
->location
= new_explicit_location (&explicit_loc
);
3426 b
->enable_state
= bp_disabled
;
3431 /* Install a master breakpoint on the unwinder's debug hook. */
3434 create_exception_master_breakpoint (void)
3436 const char *const func_name
= "_Unwind_DebugHook";
3438 for (objfile
*objfile
: current_program_space
->objfiles ())
3440 struct breakpoint
*b
;
3441 struct gdbarch
*gdbarch
;
3442 struct breakpoint_objfile_data
*bp_objfile_data
;
3444 struct explicit_location explicit_loc
;
3446 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3448 /* We prefer the SystemTap probe point if it exists. */
3449 if (!bp_objfile_data
->exception_searched
)
3451 std::vector
<probe
*> ret
3452 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3456 /* We are only interested in checking one element. */
3459 if (!p
->can_evaluate_arguments ())
3461 /* We cannot use the probe interface here, because it does
3462 not know how to evaluate arguments. */
3466 bp_objfile_data
->exception_probes
= ret
;
3467 bp_objfile_data
->exception_searched
= 1;
3470 if (!bp_objfile_data
->exception_probes
.empty ())
3472 gdbarch
= objfile
->arch ();
3474 for (probe
*p
: bp_objfile_data
->exception_probes
)
3476 b
= create_internal_breakpoint (gdbarch
,
3477 p
->get_relocated_address (objfile
),
3478 bp_exception_master
,
3479 &internal_breakpoint_ops
);
3480 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3481 b
->enable_state
= bp_disabled
;
3487 /* Otherwise, try the hook function. */
3489 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3492 gdbarch
= objfile
->arch ();
3494 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3496 struct bound_minimal_symbol debug_hook
;
3498 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3499 if (debug_hook
.minsym
== NULL
)
3501 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3505 bp_objfile_data
->exception_msym
= debug_hook
;
3508 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3509 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3510 current_top_target ());
3511 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3512 &internal_breakpoint_ops
);
3513 initialize_explicit_location (&explicit_loc
);
3514 explicit_loc
.function_name
= ASTRDUP (func_name
);
3515 b
->location
= new_explicit_location (&explicit_loc
);
3516 b
->enable_state
= bp_disabled
;
3520 /* Does B have a location spec? */
3523 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3525 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3529 update_breakpoints_after_exec (void)
3531 struct breakpoint
*b
, *b_tmp
;
3532 struct bp_location
*bploc
, **bplocp_tmp
;
3534 /* We're about to delete breakpoints from GDB's lists. If the
3535 INSERTED flag is true, GDB will try to lift the breakpoints by
3536 writing the breakpoints' "shadow contents" back into memory. The
3537 "shadow contents" are NOT valid after an exec, so GDB should not
3538 do that. Instead, the target is responsible from marking
3539 breakpoints out as soon as it detects an exec. We don't do that
3540 here instead, because there may be other attempts to delete
3541 breakpoints after detecting an exec and before reaching here. */
3542 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3543 if (bploc
->pspace
== current_program_space
)
3544 gdb_assert (!bploc
->inserted
);
3546 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3548 if (b
->pspace
!= current_program_space
)
3551 /* Solib breakpoints must be explicitly reset after an exec(). */
3552 if (b
->type
== bp_shlib_event
)
3554 delete_breakpoint (b
);
3558 /* JIT breakpoints must be explicitly reset after an exec(). */
3559 if (b
->type
== bp_jit_event
)
3561 delete_breakpoint (b
);
3565 /* Thread event breakpoints must be set anew after an exec(),
3566 as must overlay event and longjmp master breakpoints. */
3567 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3568 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3569 || b
->type
== bp_exception_master
)
3571 delete_breakpoint (b
);
3575 /* Step-resume breakpoints are meaningless after an exec(). */
3576 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3578 delete_breakpoint (b
);
3582 /* Just like single-step breakpoints. */
3583 if (b
->type
== bp_single_step
)
3585 delete_breakpoint (b
);
3589 /* Longjmp and longjmp-resume breakpoints are also meaningless
3591 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3592 || b
->type
== bp_longjmp_call_dummy
3593 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3595 delete_breakpoint (b
);
3599 if (b
->type
== bp_catchpoint
)
3601 /* For now, none of the bp_catchpoint breakpoints need to
3602 do anything at this point. In the future, if some of
3603 the catchpoints need to something, we will need to add
3604 a new method, and call this method from here. */
3608 /* bp_finish is a special case. The only way we ought to be able
3609 to see one of these when an exec() has happened, is if the user
3610 caught a vfork, and then said "finish". Ordinarily a finish just
3611 carries them to the call-site of the current callee, by setting
3612 a temporary bp there and resuming. But in this case, the finish
3613 will carry them entirely through the vfork & exec.
3615 We don't want to allow a bp_finish to remain inserted now. But
3616 we can't safely delete it, 'cause finish_command has a handle to
3617 the bp on a bpstat, and will later want to delete it. There's a
3618 chance (and I've seen it happen) that if we delete the bp_finish
3619 here, that its storage will get reused by the time finish_command
3620 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3621 We really must allow finish_command to delete a bp_finish.
3623 In the absence of a general solution for the "how do we know
3624 it's safe to delete something others may have handles to?"
3625 problem, what we'll do here is just uninsert the bp_finish, and
3626 let finish_command delete it.
3628 (We know the bp_finish is "doomed" in the sense that it's
3629 momentary, and will be deleted as soon as finish_command sees
3630 the inferior stopped. So it doesn't matter that the bp's
3631 address is probably bogus in the new a.out, unlike e.g., the
3632 solib breakpoints.) */
3634 if (b
->type
== bp_finish
)
3639 /* Without a symbolic address, we have little hope of the
3640 pre-exec() address meaning the same thing in the post-exec()
3642 if (breakpoint_event_location_empty_p (b
))
3644 delete_breakpoint (b
);
3651 detach_breakpoints (ptid_t ptid
)
3653 struct bp_location
*bl
, **blp_tmp
;
3655 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3656 struct inferior
*inf
= current_inferior ();
3658 if (ptid
.pid () == inferior_ptid
.pid ())
3659 error (_("Cannot detach breakpoints of inferior_ptid"));
3661 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3662 inferior_ptid
= ptid
;
3663 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3665 if (bl
->pspace
!= inf
->pspace
)
3668 /* This function must physically remove breakpoints locations
3669 from the specified ptid, without modifying the breakpoint
3670 package's state. Locations of type bp_loc_other are only
3671 maintained at GDB side. So, there is no need to remove
3672 these bp_loc_other locations. Moreover, removing these
3673 would modify the breakpoint package's state. */
3674 if (bl
->loc_type
== bp_loc_other
)
3678 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3684 /* Remove the breakpoint location BL from the current address space.
3685 Note that this is used to detach breakpoints from a child fork.
3686 When we get here, the child isn't in the inferior list, and neither
3687 do we have objects to represent its address space --- we should
3688 *not* look at bl->pspace->aspace here. */
3691 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3695 /* BL is never in moribund_locations by our callers. */
3696 gdb_assert (bl
->owner
!= NULL
);
3698 /* The type of none suggests that owner is actually deleted.
3699 This should not ever happen. */
3700 gdb_assert (bl
->owner
->type
!= bp_none
);
3702 if (bl
->loc_type
== bp_loc_software_breakpoint
3703 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3705 /* "Normal" instruction breakpoint: either the standard
3706 trap-instruction bp (bp_breakpoint), or a
3707 bp_hardware_breakpoint. */
3709 /* First check to see if we have to handle an overlay. */
3710 if (overlay_debugging
== ovly_off
3711 || bl
->section
== NULL
3712 || !(section_is_overlay (bl
->section
)))
3714 /* No overlay handling: just remove the breakpoint. */
3716 /* If we're trying to uninsert a memory breakpoint that we
3717 know is set in a dynamic object that is marked
3718 shlib_disabled, then either the dynamic object was
3719 removed with "remove-symbol-file" or with
3720 "nosharedlibrary". In the former case, we don't know
3721 whether another dynamic object might have loaded over the
3722 breakpoint's address -- the user might well let us know
3723 about it next with add-symbol-file (the whole point of
3724 add-symbol-file is letting the user manually maintain a
3725 list of dynamically loaded objects). If we have the
3726 breakpoint's shadow memory, that is, this is a software
3727 breakpoint managed by GDB, check whether the breakpoint
3728 is still inserted in memory, to avoid overwriting wrong
3729 code with stale saved shadow contents. Note that HW
3730 breakpoints don't have shadow memory, as they're
3731 implemented using a mechanism that is not dependent on
3732 being able to modify the target's memory, and as such
3733 they should always be removed. */
3734 if (bl
->shlib_disabled
3735 && bl
->target_info
.shadow_len
!= 0
3736 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3739 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3743 /* This breakpoint is in an overlay section.
3744 Did we set a breakpoint at the LMA? */
3745 if (!overlay_events_enabled
)
3747 /* Yes -- overlay event support is not active, so we
3748 should have set a breakpoint at the LMA. Remove it.
3750 /* Ignore any failures: if the LMA is in ROM, we will
3751 have already warned when we failed to insert it. */
3752 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3753 target_remove_hw_breakpoint (bl
->gdbarch
,
3754 &bl
->overlay_target_info
);
3756 target_remove_breakpoint (bl
->gdbarch
,
3757 &bl
->overlay_target_info
,
3760 /* Did we set a breakpoint at the VMA?
3761 If so, we will have marked the breakpoint 'inserted'. */
3764 /* Yes -- remove it. Previously we did not bother to
3765 remove the breakpoint if the section had been
3766 unmapped, but let's not rely on that being safe. We
3767 don't know what the overlay manager might do. */
3769 /* However, we should remove *software* breakpoints only
3770 if the section is still mapped, or else we overwrite
3771 wrong code with the saved shadow contents. */
3772 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3773 || section_is_mapped (bl
->section
))
3774 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3780 /* No -- not inserted, so no need to remove. No error. */
3785 /* In some cases, we might not be able to remove a breakpoint in
3786 a shared library that has already been removed, but we have
3787 not yet processed the shlib unload event. Similarly for an
3788 unloaded add-symbol-file object - the user might not yet have
3789 had the chance to remove-symbol-file it. shlib_disabled will
3790 be set if the library/object has already been removed, but
3791 the breakpoint hasn't been uninserted yet, e.g., after
3792 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3793 always-inserted mode. */
3795 && (bl
->loc_type
== bp_loc_software_breakpoint
3796 && (bl
->shlib_disabled
3797 || solib_name_from_address (bl
->pspace
, bl
->address
)
3798 || shared_objfile_contains_address_p (bl
->pspace
,
3804 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3806 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3808 gdb_assert (bl
->owner
->ops
!= NULL
3809 && bl
->owner
->ops
->remove_location
!= NULL
);
3811 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3812 bl
->owner
->ops
->remove_location (bl
, reason
);
3814 /* Failure to remove any of the hardware watchpoints comes here. */
3815 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3816 warning (_("Could not remove hardware watchpoint %d."),
3819 else if (bl
->owner
->type
== bp_catchpoint
3820 && breakpoint_enabled (bl
->owner
)
3823 gdb_assert (bl
->owner
->ops
!= NULL
3824 && bl
->owner
->ops
->remove_location
!= NULL
);
3826 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3830 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3837 remove_breakpoint (struct bp_location
*bl
)
3839 /* BL is never in moribund_locations by our callers. */
3840 gdb_assert (bl
->owner
!= NULL
);
3842 /* The type of none suggests that owner is actually deleted.
3843 This should not ever happen. */
3844 gdb_assert (bl
->owner
->type
!= bp_none
);
3846 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3848 switch_to_program_space_and_thread (bl
->pspace
);
3850 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3853 /* Clear the "inserted" flag in all breakpoints. */
3856 mark_breakpoints_out (void)
3858 struct bp_location
*bl
, **blp_tmp
;
3860 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3861 if (bl
->pspace
== current_program_space
)
3865 /* Clear the "inserted" flag in all breakpoints and delete any
3866 breakpoints which should go away between runs of the program.
3868 Plus other such housekeeping that has to be done for breakpoints
3871 Note: this function gets called at the end of a run (by
3872 generic_mourn_inferior) and when a run begins (by
3873 init_wait_for_inferior). */
3878 breakpoint_init_inferior (enum inf_context context
)
3880 struct breakpoint
*b
, *b_tmp
;
3881 struct program_space
*pspace
= current_program_space
;
3883 /* If breakpoint locations are shared across processes, then there's
3885 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3888 mark_breakpoints_out ();
3890 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3892 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3898 case bp_longjmp_call_dummy
:
3900 /* If the call dummy breakpoint is at the entry point it will
3901 cause problems when the inferior is rerun, so we better get
3904 case bp_watchpoint_scope
:
3906 /* Also get rid of scope breakpoints. */
3908 case bp_shlib_event
:
3910 /* Also remove solib event breakpoints. Their addresses may
3911 have changed since the last time we ran the program.
3912 Actually we may now be debugging against different target;
3913 and so the solib backend that installed this breakpoint may
3914 not be used in by the target. E.g.,
3916 (gdb) file prog-linux
3917 (gdb) run # native linux target
3920 (gdb) file prog-win.exe
3921 (gdb) tar rem :9999 # remote Windows gdbserver.
3924 case bp_step_resume
:
3926 /* Also remove step-resume breakpoints. */
3928 case bp_single_step
:
3930 /* Also remove single-step breakpoints. */
3932 delete_breakpoint (b
);
3936 case bp_hardware_watchpoint
:
3937 case bp_read_watchpoint
:
3938 case bp_access_watchpoint
:
3940 struct watchpoint
*w
= (struct watchpoint
*) b
;
3942 /* Likewise for watchpoints on local expressions. */
3943 if (w
->exp_valid_block
!= NULL
)
3944 delete_breakpoint (b
);
3947 /* Get rid of existing locations, which are no longer
3948 valid. New ones will be created in
3949 update_watchpoint, when the inferior is restarted.
3950 The next update_global_location_list call will
3951 garbage collect them. */
3954 if (context
== inf_starting
)
3956 /* Reset val field to force reread of starting value in
3957 insert_breakpoints. */
3958 w
->val
.reset (nullptr);
3959 w
->val_valid
= false;
3969 /* Get rid of the moribund locations. */
3970 for (bp_location
*bl
: moribund_locations
)
3971 decref_bp_location (&bl
);
3972 moribund_locations
.clear ();
3975 /* These functions concern about actual breakpoints inserted in the
3976 target --- to e.g. check if we need to do decr_pc adjustment or if
3977 we need to hop over the bkpt --- so we check for address space
3978 match, not program space. */
3980 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3981 exists at PC. It returns ordinary_breakpoint_here if it's an
3982 ordinary breakpoint, or permanent_breakpoint_here if it's a
3983 permanent breakpoint.
3984 - When continuing from a location with an ordinary breakpoint, we
3985 actually single step once before calling insert_breakpoints.
3986 - When continuing from a location with a permanent breakpoint, we
3987 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3988 the target, to advance the PC past the breakpoint. */
3990 enum breakpoint_here
3991 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
3993 struct bp_location
*bl
, **blp_tmp
;
3994 int any_breakpoint_here
= 0;
3996 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3998 if (bl
->loc_type
!= bp_loc_software_breakpoint
3999 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4002 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4003 if ((breakpoint_enabled (bl
->owner
)
4005 && breakpoint_location_address_match (bl
, aspace
, pc
))
4007 if (overlay_debugging
4008 && section_is_overlay (bl
->section
)
4009 && !section_is_mapped (bl
->section
))
4010 continue; /* unmapped overlay -- can't be a match */
4011 else if (bl
->permanent
)
4012 return permanent_breakpoint_here
;
4014 any_breakpoint_here
= 1;
4018 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4021 /* See breakpoint.h. */
4024 breakpoint_in_range_p (const address_space
*aspace
,
4025 CORE_ADDR addr
, ULONGEST len
)
4027 struct bp_location
*bl
, **blp_tmp
;
4029 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4031 if (bl
->loc_type
!= bp_loc_software_breakpoint
4032 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4035 if ((breakpoint_enabled (bl
->owner
)
4037 && breakpoint_location_address_range_overlap (bl
, aspace
,
4040 if (overlay_debugging
4041 && section_is_overlay (bl
->section
)
4042 && !section_is_mapped (bl
->section
))
4044 /* Unmapped overlay -- can't be a match. */
4055 /* Return true if there's a moribund breakpoint at PC. */
4058 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4060 for (bp_location
*loc
: moribund_locations
)
4061 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4067 /* Returns non-zero iff BL is inserted at PC, in address space
4071 bp_location_inserted_here_p (struct bp_location
*bl
,
4072 const address_space
*aspace
, CORE_ADDR pc
)
4075 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4078 if (overlay_debugging
4079 && section_is_overlay (bl
->section
)
4080 && !section_is_mapped (bl
->section
))
4081 return 0; /* unmapped overlay -- can't be a match */
4088 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4091 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4093 struct bp_location
**blp
, **blp_tmp
= NULL
;
4095 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4097 struct bp_location
*bl
= *blp
;
4099 if (bl
->loc_type
!= bp_loc_software_breakpoint
4100 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4103 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4109 /* This function returns non-zero iff there is a software breakpoint
4113 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4116 struct bp_location
**blp
, **blp_tmp
= NULL
;
4118 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4120 struct bp_location
*bl
= *blp
;
4122 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4125 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4132 /* See breakpoint.h. */
4135 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4138 struct bp_location
**blp
, **blp_tmp
= NULL
;
4140 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4142 struct bp_location
*bl
= *blp
;
4144 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4147 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4155 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4156 CORE_ADDR addr
, ULONGEST len
)
4158 struct breakpoint
*bpt
;
4160 ALL_BREAKPOINTS (bpt
)
4162 struct bp_location
*loc
;
4164 if (bpt
->type
!= bp_hardware_watchpoint
4165 && bpt
->type
!= bp_access_watchpoint
)
4168 if (!breakpoint_enabled (bpt
))
4171 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4172 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4176 /* Check for intersection. */
4177 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4178 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4186 /* See breakpoint.h. */
4189 is_catchpoint (struct breakpoint
*b
)
4191 return (b
->type
== bp_catchpoint
);
4194 /* Frees any storage that is part of a bpstat. Does not walk the
4197 bpstats::~bpstats ()
4199 if (bp_location_at
!= NULL
)
4200 decref_bp_location (&bp_location_at
);
4203 /* Clear a bpstat so that it says we are not at any breakpoint.
4204 Also free any storage that is part of a bpstat. */
4207 bpstat_clear (bpstat
*bsp
)
4224 bpstats::bpstats (const bpstats
&other
)
4226 bp_location_at (other
.bp_location_at
),
4227 breakpoint_at (other
.breakpoint_at
),
4228 commands (other
.commands
),
4229 print (other
.print
),
4231 print_it (other
.print_it
)
4233 if (other
.old_val
!= NULL
)
4234 old_val
= release_value (value_copy (other
.old_val
.get ()));
4235 incref_bp_location (bp_location_at
);
4238 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4239 is part of the bpstat is copied as well. */
4242 bpstat_copy (bpstat bs
)
4246 bpstat retval
= NULL
;
4251 for (; bs
!= NULL
; bs
= bs
->next
)
4253 tmp
= new bpstats (*bs
);
4256 /* This is the first thing in the chain. */
4266 /* Find the bpstat associated with this breakpoint. */
4269 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4274 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4276 if (bsp
->breakpoint_at
== breakpoint
)
4282 /* See breakpoint.h. */
4285 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4287 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4289 if (bsp
->breakpoint_at
== NULL
)
4291 /* A moribund location can never explain a signal other than
4293 if (sig
== GDB_SIGNAL_TRAP
)
4298 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4307 /* Put in *NUM the breakpoint number of the first breakpoint we are
4308 stopped at. *BSP upon return is a bpstat which points to the
4309 remaining breakpoints stopped at (but which is not guaranteed to be
4310 good for anything but further calls to bpstat_num).
4312 Return 0 if passed a bpstat which does not indicate any breakpoints.
4313 Return -1 if stopped at a breakpoint that has been deleted since
4315 Return 1 otherwise. */
4318 bpstat_num (bpstat
*bsp
, int *num
)
4320 struct breakpoint
*b
;
4323 return 0; /* No more breakpoint values */
4325 /* We assume we'll never have several bpstats that correspond to a
4326 single breakpoint -- otherwise, this function might return the
4327 same number more than once and this will look ugly. */
4328 b
= (*bsp
)->breakpoint_at
;
4329 *bsp
= (*bsp
)->next
;
4331 return -1; /* breakpoint that's been deleted since */
4333 *num
= b
->number
; /* We have its number */
4337 /* See breakpoint.h. */
4340 bpstat_clear_actions (void)
4344 if (inferior_ptid
== null_ptid
)
4347 thread_info
*tp
= inferior_thread ();
4348 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4350 bs
->commands
= NULL
;
4351 bs
->old_val
.reset (nullptr);
4355 /* Called when a command is about to proceed the inferior. */
4358 breakpoint_about_to_proceed (void)
4360 if (inferior_ptid
!= null_ptid
)
4362 struct thread_info
*tp
= inferior_thread ();
4364 /* Allow inferior function calls in breakpoint commands to not
4365 interrupt the command list. When the call finishes
4366 successfully, the inferior will be standing at the same
4367 breakpoint as if nothing happened. */
4368 if (tp
->control
.in_infcall
)
4372 breakpoint_proceeded
= 1;
4375 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4376 or its equivalent. */
4379 command_line_is_silent (struct command_line
*cmd
)
4381 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4384 /* Execute all the commands associated with all the breakpoints at
4385 this location. Any of these commands could cause the process to
4386 proceed beyond this point, etc. We look out for such changes by
4387 checking the global "breakpoint_proceeded" after each command.
4389 Returns true if a breakpoint command resumed the inferior. In that
4390 case, it is the caller's responsibility to recall it again with the
4391 bpstat of the current thread. */
4394 bpstat_do_actions_1 (bpstat
*bsp
)
4399 /* Avoid endless recursion if a `source' command is contained
4401 if (executing_breakpoint_commands
)
4404 scoped_restore save_executing
4405 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4407 scoped_restore preventer
= prevent_dont_repeat ();
4409 /* This pointer will iterate over the list of bpstat's. */
4412 breakpoint_proceeded
= 0;
4413 for (; bs
!= NULL
; bs
= bs
->next
)
4415 struct command_line
*cmd
= NULL
;
4417 /* Take ownership of the BSP's command tree, if it has one.
4419 The command tree could legitimately contain commands like
4420 'step' and 'next', which call clear_proceed_status, which
4421 frees stop_bpstat's command tree. To make sure this doesn't
4422 free the tree we're executing out from under us, we need to
4423 take ownership of the tree ourselves. Since a given bpstat's
4424 commands are only executed once, we don't need to copy it; we
4425 can clear the pointer in the bpstat, and make sure we free
4426 the tree when we're done. */
4427 counted_command_line ccmd
= bs
->commands
;
4428 bs
->commands
= NULL
;
4431 if (command_line_is_silent (cmd
))
4433 /* The action has been already done by bpstat_stop_status. */
4439 execute_control_command (cmd
);
4441 if (breakpoint_proceeded
)
4447 if (breakpoint_proceeded
)
4449 if (current_ui
->async
)
4450 /* If we are in async mode, then the target might be still
4451 running, not stopped at any breakpoint, so nothing for
4452 us to do here -- just return to the event loop. */
4455 /* In sync mode, when execute_control_command returns
4456 we're already standing on the next breakpoint.
4457 Breakpoint commands for that stop were not run, since
4458 execute_command does not run breakpoint commands --
4459 only command_line_handler does, but that one is not
4460 involved in execution of breakpoint commands. So, we
4461 can now execute breakpoint commands. It should be
4462 noted that making execute_command do bpstat actions is
4463 not an option -- in this case we'll have recursive
4464 invocation of bpstat for each breakpoint with a
4465 command, and can easily blow up GDB stack. Instead, we
4466 return true, which will trigger the caller to recall us
4467 with the new stop_bpstat. */
4475 /* Helper for bpstat_do_actions. Get the current thread, if there's
4476 one, is alive and has execution. Return NULL otherwise. */
4478 static thread_info
*
4479 get_bpstat_thread ()
4481 if (inferior_ptid
== null_ptid
|| !target_has_execution ())
4484 thread_info
*tp
= inferior_thread ();
4485 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4491 bpstat_do_actions (void)
4493 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4496 /* Do any commands attached to breakpoint we are stopped at. */
4497 while ((tp
= get_bpstat_thread ()) != NULL
)
4499 /* Since in sync mode, bpstat_do_actions may resume the
4500 inferior, and only return when it is stopped at the next
4501 breakpoint, we keep doing breakpoint actions until it returns
4502 false to indicate the inferior was not resumed. */
4503 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4507 cleanup_if_error
.release ();
4510 /* Print out the (old or new) value associated with a watchpoint. */
4513 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4516 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4519 struct value_print_options opts
;
4520 get_user_print_options (&opts
);
4521 value_print (val
, stream
, &opts
);
4525 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4526 debugging multiple threads. */
4529 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4531 if (uiout
->is_mi_like_p ())
4536 if (show_thread_that_caused_stop ())
4539 struct thread_info
*thr
= inferior_thread ();
4541 uiout
->text ("Thread ");
4542 uiout
->field_string ("thread-id", print_thread_id (thr
));
4544 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4547 uiout
->text (" \"");
4548 uiout
->field_string ("name", name
);
4552 uiout
->text (" hit ");
4556 /* Generic routine for printing messages indicating why we
4557 stopped. The behavior of this function depends on the value
4558 'print_it' in the bpstat structure. Under some circumstances we
4559 may decide not to print anything here and delegate the task to
4562 static enum print_stop_action
4563 print_bp_stop_message (bpstat bs
)
4565 switch (bs
->print_it
)
4568 /* Nothing should be printed for this bpstat entry. */
4569 return PRINT_UNKNOWN
;
4573 /* We still want to print the frame, but we already printed the
4574 relevant messages. */
4575 return PRINT_SRC_AND_LOC
;
4578 case print_it_normal
:
4580 struct breakpoint
*b
= bs
->breakpoint_at
;
4582 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4583 which has since been deleted. */
4585 return PRINT_UNKNOWN
;
4587 /* Normal case. Call the breakpoint's print_it method. */
4588 return b
->ops
->print_it (bs
);
4593 internal_error (__FILE__
, __LINE__
,
4594 _("print_bp_stop_message: unrecognized enum value"));
4599 /* A helper function that prints a shared library stopped event. */
4602 print_solib_event (int is_catchpoint
)
4604 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4605 bool any_added
= !current_program_space
->added_solibs
.empty ();
4609 if (any_added
|| any_deleted
)
4610 current_uiout
->text (_("Stopped due to shared library event:\n"));
4612 current_uiout
->text (_("Stopped due to shared library event (no "
4613 "libraries added or removed)\n"));
4616 if (current_uiout
->is_mi_like_p ())
4617 current_uiout
->field_string ("reason",
4618 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4622 current_uiout
->text (_(" Inferior unloaded "));
4623 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4624 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4626 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4629 current_uiout
->text (" ");
4630 current_uiout
->field_string ("library", name
);
4631 current_uiout
->text ("\n");
4637 current_uiout
->text (_(" Inferior loaded "));
4638 ui_out_emit_list
list_emitter (current_uiout
, "added");
4640 for (so_list
*iter
: current_program_space
->added_solibs
)
4643 current_uiout
->text (" ");
4645 current_uiout
->field_string ("library", iter
->so_name
);
4646 current_uiout
->text ("\n");
4651 /* Print a message indicating what happened. This is called from
4652 normal_stop(). The input to this routine is the head of the bpstat
4653 list - a list of the eventpoints that caused this stop. KIND is
4654 the target_waitkind for the stopping event. This
4655 routine calls the generic print routine for printing a message
4656 about reasons for stopping. This will print (for example) the
4657 "Breakpoint n," part of the output. The return value of this
4660 PRINT_UNKNOWN: Means we printed nothing.
4661 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4662 code to print the location. An example is
4663 "Breakpoint 1, " which should be followed by
4665 PRINT_SRC_ONLY: Means we printed something, but there is no need
4666 to also print the location part of the message.
4667 An example is the catch/throw messages, which
4668 don't require a location appended to the end.
4669 PRINT_NOTHING: We have done some printing and we don't need any
4670 further info to be printed. */
4672 enum print_stop_action
4673 bpstat_print (bpstat bs
, int kind
)
4675 enum print_stop_action val
;
4677 /* Maybe another breakpoint in the chain caused us to stop.
4678 (Currently all watchpoints go on the bpstat whether hit or not.
4679 That probably could (should) be changed, provided care is taken
4680 with respect to bpstat_explains_signal). */
4681 for (; bs
; bs
= bs
->next
)
4683 val
= print_bp_stop_message (bs
);
4684 if (val
== PRINT_SRC_ONLY
4685 || val
== PRINT_SRC_AND_LOC
4686 || val
== PRINT_NOTHING
)
4690 /* If we had hit a shared library event breakpoint,
4691 print_bp_stop_message would print out this message. If we hit an
4692 OS-level shared library event, do the same thing. */
4693 if (kind
== TARGET_WAITKIND_LOADED
)
4695 print_solib_event (0);
4696 return PRINT_NOTHING
;
4699 /* We reached the end of the chain, or we got a null BS to start
4700 with and nothing was printed. */
4701 return PRINT_UNKNOWN
;
4704 /* Evaluate the boolean expression EXP and return the result. */
4707 breakpoint_cond_eval (expression
*exp
)
4709 struct value
*mark
= value_mark ();
4710 bool res
= value_true (evaluate_expression (exp
));
4712 value_free_to_mark (mark
);
4716 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4718 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4720 bp_location_at (bl
),
4721 breakpoint_at (bl
->owner
),
4725 print_it (print_it_normal
)
4727 incref_bp_location (bl
);
4728 **bs_link_pointer
= this;
4729 *bs_link_pointer
= &next
;
4734 bp_location_at (NULL
),
4735 breakpoint_at (NULL
),
4739 print_it (print_it_normal
)
4743 /* The target has stopped with waitstatus WS. Check if any hardware
4744 watchpoints have triggered, according to the target. */
4747 watchpoints_triggered (struct target_waitstatus
*ws
)
4749 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4751 struct breakpoint
*b
;
4753 if (!stopped_by_watchpoint
)
4755 /* We were not stopped by a watchpoint. Mark all watchpoints
4756 as not triggered. */
4758 if (is_hardware_watchpoint (b
))
4760 struct watchpoint
*w
= (struct watchpoint
*) b
;
4762 w
->watchpoint_triggered
= watch_triggered_no
;
4768 if (!target_stopped_data_address (current_top_target (), &addr
))
4770 /* We were stopped by a watchpoint, but we don't know where.
4771 Mark all watchpoints as unknown. */
4773 if (is_hardware_watchpoint (b
))
4775 struct watchpoint
*w
= (struct watchpoint
*) b
;
4777 w
->watchpoint_triggered
= watch_triggered_unknown
;
4783 /* The target could report the data address. Mark watchpoints
4784 affected by this data address as triggered, and all others as not
4788 if (is_hardware_watchpoint (b
))
4790 struct watchpoint
*w
= (struct watchpoint
*) b
;
4791 struct bp_location
*loc
;
4793 w
->watchpoint_triggered
= watch_triggered_no
;
4794 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4796 if (is_masked_watchpoint (b
))
4798 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4799 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4801 if (newaddr
== start
)
4803 w
->watchpoint_triggered
= watch_triggered_yes
;
4807 /* Exact match not required. Within range is sufficient. */
4808 else if (target_watchpoint_addr_within_range (current_top_target (),
4812 w
->watchpoint_triggered
= watch_triggered_yes
;
4821 /* Possible return values for watchpoint_check. */
4822 enum wp_check_result
4824 /* The watchpoint has been deleted. */
4827 /* The value has changed. */
4828 WP_VALUE_CHANGED
= 2,
4830 /* The value has not changed. */
4831 WP_VALUE_NOT_CHANGED
= 3,
4833 /* Ignore this watchpoint, no matter if the value changed or not. */
4837 #define BP_TEMPFLAG 1
4838 #define BP_HARDWAREFLAG 2
4840 /* Evaluate watchpoint condition expression and check if its value
4843 static wp_check_result
4844 watchpoint_check (bpstat bs
)
4846 struct watchpoint
*b
;
4847 struct frame_info
*fr
;
4848 int within_current_scope
;
4850 /* BS is built from an existing struct breakpoint. */
4851 gdb_assert (bs
->breakpoint_at
!= NULL
);
4852 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4854 /* If this is a local watchpoint, we only want to check if the
4855 watchpoint frame is in scope if the current thread is the thread
4856 that was used to create the watchpoint. */
4857 if (!watchpoint_in_thread_scope (b
))
4860 if (b
->exp_valid_block
== NULL
)
4861 within_current_scope
= 1;
4864 struct frame_info
*frame
= get_current_frame ();
4865 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4866 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4868 /* stack_frame_destroyed_p() returns a non-zero value if we're
4869 still in the function but the stack frame has already been
4870 invalidated. Since we can't rely on the values of local
4871 variables after the stack has been destroyed, we are treating
4872 the watchpoint in that state as `not changed' without further
4873 checking. Don't mark watchpoints as changed if the current
4874 frame is in an epilogue - even if they are in some other
4875 frame, our view of the stack is likely to be wrong and
4876 frame_find_by_id could error out. */
4877 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4880 fr
= frame_find_by_id (b
->watchpoint_frame
);
4881 within_current_scope
= (fr
!= NULL
);
4883 /* If we've gotten confused in the unwinder, we might have
4884 returned a frame that can't describe this variable. */
4885 if (within_current_scope
)
4887 struct symbol
*function
;
4889 function
= get_frame_function (fr
);
4890 if (function
== NULL
4891 || !contained_in (b
->exp_valid_block
,
4892 SYMBOL_BLOCK_VALUE (function
)))
4893 within_current_scope
= 0;
4896 if (within_current_scope
)
4897 /* If we end up stopping, the current frame will get selected
4898 in normal_stop. So this call to select_frame won't affect
4903 if (within_current_scope
)
4905 /* We use value_{,free_to_}mark because it could be a *long*
4906 time before we return to the command level and call
4907 free_all_values. We can't call free_all_values because we
4908 might be in the middle of evaluating a function call. */
4912 struct value
*new_val
;
4914 if (is_masked_watchpoint (b
))
4915 /* Since we don't know the exact trigger address (from
4916 stopped_data_address), just tell the user we've triggered
4917 a mask watchpoint. */
4918 return WP_VALUE_CHANGED
;
4920 mark
= value_mark ();
4921 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
4923 if (b
->val_bitsize
!= 0)
4924 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4926 /* We use value_equal_contents instead of value_equal because
4927 the latter coerces an array to a pointer, thus comparing just
4928 the address of the array instead of its contents. This is
4929 not what we want. */
4930 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4931 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
4934 bs
->old_val
= b
->val
;
4935 b
->val
= release_value (new_val
);
4936 b
->val_valid
= true;
4937 if (new_val
!= NULL
)
4938 value_free_to_mark (mark
);
4939 return WP_VALUE_CHANGED
;
4943 /* Nothing changed. */
4944 value_free_to_mark (mark
);
4945 return WP_VALUE_NOT_CHANGED
;
4950 /* This seems like the only logical thing to do because
4951 if we temporarily ignored the watchpoint, then when
4952 we reenter the block in which it is valid it contains
4953 garbage (in the case of a function, it may have two
4954 garbage values, one before and one after the prologue).
4955 So we can't even detect the first assignment to it and
4956 watch after that (since the garbage may or may not equal
4957 the first value assigned). */
4958 /* We print all the stop information in
4959 breakpoint_ops->print_it, but in this case, by the time we
4960 call breakpoint_ops->print_it this bp will be deleted
4961 already. So we have no choice but print the information
4964 SWITCH_THRU_ALL_UIS ()
4966 struct ui_out
*uiout
= current_uiout
;
4968 if (uiout
->is_mi_like_p ())
4970 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4971 uiout
->message ("\nWatchpoint %pF deleted because the program has "
4972 "left the block in\n"
4973 "which its expression is valid.\n",
4974 signed_field ("wpnum", b
->number
));
4977 /* Make sure the watchpoint's commands aren't executed. */
4979 watchpoint_del_at_next_stop (b
);
4985 /* Return true if it looks like target has stopped due to hitting
4986 breakpoint location BL. This function does not check if we should
4987 stop, only if BL explains the stop. */
4990 bpstat_check_location (const struct bp_location
*bl
,
4991 const address_space
*aspace
, CORE_ADDR bp_addr
,
4992 const struct target_waitstatus
*ws
)
4994 struct breakpoint
*b
= bl
->owner
;
4996 /* BL is from an existing breakpoint. */
4997 gdb_assert (b
!= NULL
);
4999 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5002 /* Determine if the watched values have actually changed, and we
5003 should stop. If not, set BS->stop to 0. */
5006 bpstat_check_watchpoint (bpstat bs
)
5008 const struct bp_location
*bl
;
5009 struct watchpoint
*b
;
5011 /* BS is built for existing struct breakpoint. */
5012 bl
= bs
->bp_location_at
;
5013 gdb_assert (bl
!= NULL
);
5014 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5015 gdb_assert (b
!= NULL
);
5018 int must_check_value
= 0;
5020 if (b
->type
== bp_watchpoint
)
5021 /* For a software watchpoint, we must always check the
5023 must_check_value
= 1;
5024 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5025 /* We have a hardware watchpoint (read, write, or access)
5026 and the target earlier reported an address watched by
5028 must_check_value
= 1;
5029 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5030 && b
->type
== bp_hardware_watchpoint
)
5031 /* We were stopped by a hardware watchpoint, but the target could
5032 not report the data address. We must check the watchpoint's
5033 value. Access and read watchpoints are out of luck; without
5034 a data address, we can't figure it out. */
5035 must_check_value
= 1;
5037 if (must_check_value
)
5043 e
= watchpoint_check (bs
);
5045 catch (const gdb_exception
&ex
)
5047 exception_fprintf (gdb_stderr
, ex
,
5048 "Error evaluating expression "
5049 "for watchpoint %d\n",
5052 SWITCH_THRU_ALL_UIS ()
5054 printf_filtered (_("Watchpoint %d deleted.\n"),
5057 watchpoint_del_at_next_stop (b
);
5064 /* We've already printed what needs to be printed. */
5065 bs
->print_it
= print_it_done
;
5069 bs
->print_it
= print_it_noop
;
5072 case WP_VALUE_CHANGED
:
5073 if (b
->type
== bp_read_watchpoint
)
5075 /* There are two cases to consider here:
5077 1. We're watching the triggered memory for reads.
5078 In that case, trust the target, and always report
5079 the watchpoint hit to the user. Even though
5080 reads don't cause value changes, the value may
5081 have changed since the last time it was read, and
5082 since we're not trapping writes, we will not see
5083 those, and as such we should ignore our notion of
5086 2. We're watching the triggered memory for both
5087 reads and writes. There are two ways this may
5090 2.1. This is a target that can't break on data
5091 reads only, but can break on accesses (reads or
5092 writes), such as e.g., x86. We detect this case
5093 at the time we try to insert read watchpoints.
5095 2.2. Otherwise, the target supports read
5096 watchpoints, but, the user set an access or write
5097 watchpoint watching the same memory as this read
5100 If we're watching memory writes as well as reads,
5101 ignore watchpoint hits when we find that the
5102 value hasn't changed, as reads don't cause
5103 changes. This still gives false positives when
5104 the program writes the same value to memory as
5105 what there was already in memory (we will confuse
5106 it for a read), but it's much better than
5109 int other_write_watchpoint
= 0;
5111 if (bl
->watchpoint_type
== hw_read
)
5113 struct breakpoint
*other_b
;
5115 ALL_BREAKPOINTS (other_b
)
5116 if (other_b
->type
== bp_hardware_watchpoint
5117 || other_b
->type
== bp_access_watchpoint
)
5119 struct watchpoint
*other_w
=
5120 (struct watchpoint
*) other_b
;
5122 if (other_w
->watchpoint_triggered
5123 == watch_triggered_yes
)
5125 other_write_watchpoint
= 1;
5131 if (other_write_watchpoint
5132 || bl
->watchpoint_type
== hw_access
)
5134 /* We're watching the same memory for writes,
5135 and the value changed since the last time we
5136 updated it, so this trap must be for a write.
5138 bs
->print_it
= print_it_noop
;
5143 case WP_VALUE_NOT_CHANGED
:
5144 if (b
->type
== bp_hardware_watchpoint
5145 || b
->type
== bp_watchpoint
)
5147 /* Don't stop: write watchpoints shouldn't fire if
5148 the value hasn't changed. */
5149 bs
->print_it
= print_it_noop
;
5159 else /* must_check_value == 0 */
5161 /* This is a case where some watchpoint(s) triggered, but
5162 not at the address of this watchpoint, or else no
5163 watchpoint triggered after all. So don't print
5164 anything for this watchpoint. */
5165 bs
->print_it
= print_it_noop
;
5171 /* For breakpoints that are currently marked as telling gdb to stop,
5172 check conditions (condition proper, frame, thread and ignore count)
5173 of breakpoint referred to by BS. If we should not stop for this
5174 breakpoint, set BS->stop to 0. */
5177 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5179 const struct bp_location
*bl
;
5180 struct breakpoint
*b
;
5182 bool condition_result
= true;
5183 struct expression
*cond
;
5185 gdb_assert (bs
->stop
);
5187 /* BS is built for existing struct breakpoint. */
5188 bl
= bs
->bp_location_at
;
5189 gdb_assert (bl
!= NULL
);
5190 b
= bs
->breakpoint_at
;
5191 gdb_assert (b
!= NULL
);
5193 /* Even if the target evaluated the condition on its end and notified GDB, we
5194 need to do so again since GDB does not know if we stopped due to a
5195 breakpoint or a single step breakpoint. */
5197 if (frame_id_p (b
->frame_id
)
5198 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5204 /* If this is a thread/task-specific breakpoint, don't waste cpu
5205 evaluating the condition if this isn't the specified
5207 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5208 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5214 /* Evaluate extension language breakpoints that have a "stop" method
5216 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5218 if (is_watchpoint (b
))
5220 struct watchpoint
*w
= (struct watchpoint
*) b
;
5222 cond
= w
->cond_exp
.get ();
5225 cond
= bl
->cond
.get ();
5227 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5229 int within_current_scope
= 1;
5230 struct watchpoint
* w
;
5232 /* We use value_mark and value_free_to_mark because it could
5233 be a long time before we return to the command level and
5234 call free_all_values. We can't call free_all_values
5235 because we might be in the middle of evaluating a
5237 struct value
*mark
= value_mark ();
5239 if (is_watchpoint (b
))
5240 w
= (struct watchpoint
*) b
;
5244 /* Need to select the frame, with all that implies so that
5245 the conditions will have the right context. Because we
5246 use the frame, we will not see an inlined function's
5247 variables when we arrive at a breakpoint at the start
5248 of the inlined function; the current frame will be the
5250 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5251 select_frame (get_current_frame ());
5254 struct frame_info
*frame
;
5256 /* For local watchpoint expressions, which particular
5257 instance of a local is being watched matters, so we
5258 keep track of the frame to evaluate the expression
5259 in. To evaluate the condition however, it doesn't
5260 really matter which instantiation of the function
5261 where the condition makes sense triggers the
5262 watchpoint. This allows an expression like "watch
5263 global if q > 10" set in `func', catch writes to
5264 global on all threads that call `func', or catch
5265 writes on all recursive calls of `func' by a single
5266 thread. We simply always evaluate the condition in
5267 the innermost frame that's executing where it makes
5268 sense to evaluate the condition. It seems
5270 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5272 select_frame (frame
);
5274 within_current_scope
= 0;
5276 if (within_current_scope
)
5280 condition_result
= breakpoint_cond_eval (cond
);
5282 catch (const gdb_exception
&ex
)
5284 exception_fprintf (gdb_stderr
, ex
,
5285 "Error in testing breakpoint condition:\n");
5290 warning (_("Watchpoint condition cannot be tested "
5291 "in the current scope"));
5292 /* If we failed to set the right context for this
5293 watchpoint, unconditionally report it. */
5295 /* FIXME-someday, should give breakpoint #. */
5296 value_free_to_mark (mark
);
5299 if (cond
&& !condition_result
)
5303 else if (b
->ignore_count
> 0)
5307 /* Increase the hit count even though we don't stop. */
5309 gdb::observers::breakpoint_modified
.notify (b
);
5313 /* Returns true if we need to track moribund locations of LOC's type
5314 on the current target. */
5317 need_moribund_for_location_type (struct bp_location
*loc
)
5319 return ((loc
->loc_type
== bp_loc_software_breakpoint
5320 && !target_supports_stopped_by_sw_breakpoint ())
5321 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5322 && !target_supports_stopped_by_hw_breakpoint ()));
5325 /* See breakpoint.h. */
5328 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5329 const struct target_waitstatus
*ws
)
5331 struct breakpoint
*b
;
5332 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5336 if (!breakpoint_enabled (b
))
5339 for (bp_location
*bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5341 /* For hardware watchpoints, we look only at the first
5342 location. The watchpoint_check function will work on the
5343 entire expression, not the individual locations. For
5344 read watchpoints, the watchpoints_triggered function has
5345 checked all locations already. */
5346 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5349 if (!bl
->enabled
|| bl
->disabled_by_cond
|| bl
->shlib_disabled
)
5352 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5355 /* Come here if it's a watchpoint, or if the break address
5358 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5361 /* Assume we stop. Should we find a watchpoint that is not
5362 actually triggered, or if the condition of the breakpoint
5363 evaluates as false, we'll reset 'stop' to 0. */
5367 /* If this is a scope breakpoint, mark the associated
5368 watchpoint as triggered so that we will handle the
5369 out-of-scope event. We'll get to the watchpoint next
5371 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5373 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5375 w
->watchpoint_triggered
= watch_triggered_yes
;
5380 /* Check if a moribund breakpoint explains the stop. */
5381 if (!target_supports_stopped_by_sw_breakpoint ()
5382 || !target_supports_stopped_by_hw_breakpoint ())
5384 for (bp_location
*loc
: moribund_locations
)
5386 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5387 && need_moribund_for_location_type (loc
))
5389 bpstat bs
= new bpstats (loc
, &bs_link
);
5390 /* For hits of moribund locations, we should just proceed. */
5393 bs
->print_it
= print_it_noop
;
5401 /* See breakpoint.h. */
5404 bpstat_stop_status (const address_space
*aspace
,
5405 CORE_ADDR bp_addr
, thread_info
*thread
,
5406 const struct target_waitstatus
*ws
,
5409 struct breakpoint
*b
= NULL
;
5410 /* First item of allocated bpstat's. */
5411 bpstat bs_head
= stop_chain
;
5413 int need_remove_insert
;
5416 /* First, build the bpstat chain with locations that explain a
5417 target stop, while being careful to not set the target running,
5418 as that may invalidate locations (in particular watchpoint
5419 locations are recreated). Resuming will happen here with
5420 breakpoint conditions or watchpoint expressions that include
5421 inferior function calls. */
5422 if (bs_head
== NULL
)
5423 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5425 /* A bit of special processing for shlib breakpoints. We need to
5426 process solib loading here, so that the lists of loaded and
5427 unloaded libraries are correct before we handle "catch load" and
5429 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5431 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5433 handle_solib_event ();
5438 /* Now go through the locations that caused the target to stop, and
5439 check whether we're interested in reporting this stop to higher
5440 layers, or whether we should resume the target transparently. */
5444 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5449 b
= bs
->breakpoint_at
;
5450 b
->ops
->check_status (bs
);
5453 bpstat_check_breakpoint_conditions (bs
, thread
);
5458 gdb::observers::breakpoint_modified
.notify (b
);
5460 /* We will stop here. */
5461 if (b
->disposition
== disp_disable
)
5463 --(b
->enable_count
);
5464 if (b
->enable_count
<= 0)
5465 b
->enable_state
= bp_disabled
;
5470 bs
->commands
= b
->commands
;
5471 if (command_line_is_silent (bs
->commands
5472 ? bs
->commands
.get () : NULL
))
5475 b
->ops
->after_condition_true (bs
);
5480 /* Print nothing for this entry if we don't stop or don't
5482 if (!bs
->stop
|| !bs
->print
)
5483 bs
->print_it
= print_it_noop
;
5486 /* If we aren't stopping, the value of some hardware watchpoint may
5487 not have changed, but the intermediate memory locations we are
5488 watching may have. Don't bother if we're stopping; this will get
5490 need_remove_insert
= 0;
5491 if (! bpstat_causes_stop (bs_head
))
5492 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5494 && bs
->breakpoint_at
5495 && is_hardware_watchpoint (bs
->breakpoint_at
))
5497 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5499 update_watchpoint (w
, 0 /* don't reparse. */);
5500 need_remove_insert
= 1;
5503 if (need_remove_insert
)
5504 update_global_location_list (UGLL_MAY_INSERT
);
5505 else if (removed_any
)
5506 update_global_location_list (UGLL_DONT_INSERT
);
5512 handle_jit_event (CORE_ADDR address
)
5514 struct gdbarch
*gdbarch
;
5516 infrun_debug_printf ("handling bp_jit_event");
5518 /* Switch terminal for any messages produced by
5519 breakpoint_re_set. */
5520 target_terminal::ours_for_output ();
5522 gdbarch
= get_frame_arch (get_current_frame ());
5523 /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`,
5524 thus it is expected that its objectfile can be found through
5525 minimal symbol lookup. If it doesn't work (and assert fails), it
5526 most likely means that `jit_breakpoint_re_set` was changes and this
5527 function needs to be updated too. */
5528 bound_minimal_symbol jit_bp_sym
= lookup_minimal_symbol_by_pc (address
);
5529 gdb_assert (jit_bp_sym
.objfile
!= nullptr);
5530 jit_event_handler (gdbarch
, jit_bp_sym
.objfile
);
5532 target_terminal::inferior ();
5535 /* Prepare WHAT final decision for infrun. */
5537 /* Decide what infrun needs to do with this bpstat. */
5540 bpstat_what (bpstat bs_head
)
5542 struct bpstat_what retval
;
5545 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5546 retval
.call_dummy
= STOP_NONE
;
5547 retval
.is_longjmp
= false;
5549 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5551 /* Extract this BS's action. After processing each BS, we check
5552 if its action overrides all we've seem so far. */
5553 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5556 if (bs
->breakpoint_at
== NULL
)
5558 /* I suspect this can happen if it was a momentary
5559 breakpoint which has since been deleted. */
5563 bptype
= bs
->breakpoint_at
->type
;
5570 case bp_hardware_breakpoint
:
5571 case bp_single_step
:
5574 case bp_shlib_event
:
5578 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5580 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5583 this_action
= BPSTAT_WHAT_SINGLE
;
5586 case bp_hardware_watchpoint
:
5587 case bp_read_watchpoint
:
5588 case bp_access_watchpoint
:
5592 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5594 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5598 /* There was a watchpoint, but we're not stopping.
5599 This requires no further action. */
5603 case bp_longjmp_call_dummy
:
5607 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5608 retval
.is_longjmp
= bptype
!= bp_exception
;
5611 this_action
= BPSTAT_WHAT_SINGLE
;
5613 case bp_longjmp_resume
:
5614 case bp_exception_resume
:
5617 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5618 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5621 this_action
= BPSTAT_WHAT_SINGLE
;
5623 case bp_step_resume
:
5625 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5628 /* It is for the wrong frame. */
5629 this_action
= BPSTAT_WHAT_SINGLE
;
5632 case bp_hp_step_resume
:
5634 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5637 /* It is for the wrong frame. */
5638 this_action
= BPSTAT_WHAT_SINGLE
;
5641 case bp_watchpoint_scope
:
5642 case bp_thread_event
:
5643 case bp_overlay_event
:
5644 case bp_longjmp_master
:
5645 case bp_std_terminate_master
:
5646 case bp_exception_master
:
5647 this_action
= BPSTAT_WHAT_SINGLE
;
5653 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5655 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5659 /* Some catchpoints are implemented with breakpoints.
5660 For those, we need to step over the breakpoint. */
5661 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5662 this_action
= BPSTAT_WHAT_SINGLE
;
5666 this_action
= BPSTAT_WHAT_SINGLE
;
5669 /* Make sure the action is stop (silent or noisy),
5670 so infrun.c pops the dummy frame. */
5671 retval
.call_dummy
= STOP_STACK_DUMMY
;
5672 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5674 case bp_std_terminate
:
5675 /* Make sure the action is stop (silent or noisy),
5676 so infrun.c pops the dummy frame. */
5677 retval
.call_dummy
= STOP_STD_TERMINATE
;
5678 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5681 case bp_fast_tracepoint
:
5682 case bp_static_tracepoint
:
5683 /* Tracepoint hits should not be reported back to GDB, and
5684 if one got through somehow, it should have been filtered
5686 internal_error (__FILE__
, __LINE__
,
5687 _("bpstat_what: tracepoint encountered"));
5689 case bp_gnu_ifunc_resolver
:
5690 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5691 this_action
= BPSTAT_WHAT_SINGLE
;
5693 case bp_gnu_ifunc_resolver_return
:
5694 /* The breakpoint will be removed, execution will restart from the
5695 PC of the former breakpoint. */
5696 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5701 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5703 this_action
= BPSTAT_WHAT_SINGLE
;
5707 internal_error (__FILE__
, __LINE__
,
5708 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5711 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5718 bpstat_run_callbacks (bpstat bs_head
)
5722 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5724 struct breakpoint
*b
= bs
->breakpoint_at
;
5731 handle_jit_event (bs
->bp_location_at
->address
);
5733 case bp_gnu_ifunc_resolver
:
5734 gnu_ifunc_resolver_stop (b
);
5736 case bp_gnu_ifunc_resolver_return
:
5737 gnu_ifunc_resolver_return_stop (b
);
5743 /* See breakpoint.h. */
5746 bpstat_should_step ()
5748 struct breakpoint
*b
;
5751 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5756 /* See breakpoint.h. */
5759 bpstat_causes_stop (bpstat bs
)
5761 for (; bs
!= NULL
; bs
= bs
->next
)
5770 /* Compute a string of spaces suitable to indent the next line
5771 so it starts at the position corresponding to the table column
5772 named COL_NAME in the currently active table of UIOUT. */
5775 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5777 static char wrap_indent
[80];
5778 int i
, total_width
, width
, align
;
5782 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5784 if (strcmp (text
, col_name
) == 0)
5786 gdb_assert (total_width
< sizeof wrap_indent
);
5787 memset (wrap_indent
, ' ', total_width
);
5788 wrap_indent
[total_width
] = 0;
5793 total_width
+= width
+ 1;
5799 /* Determine if the locations of this breakpoint will have their conditions
5800 evaluated by the target, host or a mix of both. Returns the following:
5802 "host": Host evals condition.
5803 "host or target": Host or Target evals condition.
5804 "target": Target evals condition.
5808 bp_condition_evaluator (struct breakpoint
*b
)
5810 struct bp_location
*bl
;
5811 char host_evals
= 0;
5812 char target_evals
= 0;
5817 if (!is_breakpoint (b
))
5820 if (gdb_evaluates_breakpoint_condition_p ()
5821 || !target_supports_evaluation_of_breakpoint_conditions ())
5822 return condition_evaluation_host
;
5824 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5826 if (bl
->cond_bytecode
)
5832 if (host_evals
&& target_evals
)
5833 return condition_evaluation_both
;
5834 else if (target_evals
)
5835 return condition_evaluation_target
;
5837 return condition_evaluation_host
;
5840 /* Determine the breakpoint location's condition evaluator. This is
5841 similar to bp_condition_evaluator, but for locations. */
5844 bp_location_condition_evaluator (struct bp_location
*bl
)
5846 if (bl
&& !is_breakpoint (bl
->owner
))
5849 if (gdb_evaluates_breakpoint_condition_p ()
5850 || !target_supports_evaluation_of_breakpoint_conditions ())
5851 return condition_evaluation_host
;
5853 if (bl
&& bl
->cond_bytecode
)
5854 return condition_evaluation_target
;
5856 return condition_evaluation_host
;
5859 /* Print the LOC location out of the list of B->LOC locations. */
5862 print_breakpoint_location (struct breakpoint
*b
,
5863 struct bp_location
*loc
)
5865 struct ui_out
*uiout
= current_uiout
;
5867 scoped_restore_current_program_space restore_pspace
;
5869 if (loc
!= NULL
&& loc
->shlib_disabled
)
5873 set_current_program_space (loc
->pspace
);
5875 if (b
->display_canonical
)
5876 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5877 else if (loc
&& loc
->symtab
)
5879 const struct symbol
*sym
= loc
->symbol
;
5883 uiout
->text ("in ");
5884 uiout
->field_string ("func", sym
->print_name (),
5885 function_name_style
.style ());
5887 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5888 uiout
->text ("at ");
5890 uiout
->field_string ("file",
5891 symtab_to_filename_for_display (loc
->symtab
),
5892 file_name_style
.style ());
5895 if (uiout
->is_mi_like_p ())
5896 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5898 uiout
->field_signed ("line", loc
->line_number
);
5904 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5906 uiout
->field_stream ("at", stb
);
5910 uiout
->field_string ("pending",
5911 event_location_to_string (b
->location
.get ()));
5912 /* If extra_string is available, it could be holding a condition
5913 or dprintf arguments. In either case, make sure it is printed,
5914 too, but only for non-MI streams. */
5915 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5917 if (b
->type
== bp_dprintf
)
5921 uiout
->text (b
->extra_string
);
5925 if (loc
&& is_breakpoint (b
)
5926 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5927 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5930 uiout
->field_string ("evaluated-by",
5931 bp_location_condition_evaluator (loc
));
5937 bptype_string (enum bptype type
)
5939 struct ep_type_description
5942 const char *description
;
5944 static struct ep_type_description bptypes
[] =
5946 {bp_none
, "?deleted?"},
5947 {bp_breakpoint
, "breakpoint"},
5948 {bp_hardware_breakpoint
, "hw breakpoint"},
5949 {bp_single_step
, "sw single-step"},
5950 {bp_until
, "until"},
5951 {bp_finish
, "finish"},
5952 {bp_watchpoint
, "watchpoint"},
5953 {bp_hardware_watchpoint
, "hw watchpoint"},
5954 {bp_read_watchpoint
, "read watchpoint"},
5955 {bp_access_watchpoint
, "acc watchpoint"},
5956 {bp_longjmp
, "longjmp"},
5957 {bp_longjmp_resume
, "longjmp resume"},
5958 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5959 {bp_exception
, "exception"},
5960 {bp_exception_resume
, "exception resume"},
5961 {bp_step_resume
, "step resume"},
5962 {bp_hp_step_resume
, "high-priority step resume"},
5963 {bp_watchpoint_scope
, "watchpoint scope"},
5964 {bp_call_dummy
, "call dummy"},
5965 {bp_std_terminate
, "std::terminate"},
5966 {bp_shlib_event
, "shlib events"},
5967 {bp_thread_event
, "thread events"},
5968 {bp_overlay_event
, "overlay events"},
5969 {bp_longjmp_master
, "longjmp master"},
5970 {bp_std_terminate_master
, "std::terminate master"},
5971 {bp_exception_master
, "exception master"},
5972 {bp_catchpoint
, "catchpoint"},
5973 {bp_tracepoint
, "tracepoint"},
5974 {bp_fast_tracepoint
, "fast tracepoint"},
5975 {bp_static_tracepoint
, "static tracepoint"},
5976 {bp_dprintf
, "dprintf"},
5977 {bp_jit_event
, "jit events"},
5978 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5979 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5982 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5983 || ((int) type
!= bptypes
[(int) type
].type
))
5984 internal_error (__FILE__
, __LINE__
,
5985 _("bptypes table does not describe type #%d."),
5988 return bptypes
[(int) type
].description
;
5991 /* For MI, output a field named 'thread-groups' with a list as the value.
5992 For CLI, prefix the list with the string 'inf'. */
5995 output_thread_groups (struct ui_out
*uiout
,
5996 const char *field_name
,
5997 const std::vector
<int> &inf_nums
,
6000 int is_mi
= uiout
->is_mi_like_p ();
6002 /* For backward compatibility, don't display inferiors in CLI unless
6003 there are several. Always display them for MI. */
6004 if (!is_mi
&& mi_only
)
6007 ui_out_emit_list
list_emitter (uiout
, field_name
);
6009 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
6015 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
6016 uiout
->field_string (NULL
, mi_group
);
6021 uiout
->text (" inf ");
6025 uiout
->text (plongest (inf_nums
[i
]));
6030 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
6031 instead of going via breakpoint_ops::print_one. This makes "maint
6032 info breakpoints" show the software breakpoint locations of
6033 catchpoints, which are considered internal implementation
6037 print_one_breakpoint_location (struct breakpoint
*b
,
6038 struct bp_location
*loc
,
6040 struct bp_location
**last_loc
,
6041 int allflag
, bool raw_loc
)
6043 struct command_line
*l
;
6044 static char bpenables
[] = "nynny";
6046 struct ui_out
*uiout
= current_uiout
;
6047 int header_of_multiple
= 0;
6048 int part_of_multiple
= (loc
!= NULL
);
6049 struct value_print_options opts
;
6051 get_user_print_options (&opts
);
6053 gdb_assert (!loc
|| loc_number
!= 0);
6054 /* See comment in print_one_breakpoint concerning treatment of
6055 breakpoints with single disabled location. */
6058 && (b
->loc
->next
!= NULL
6059 || !b
->loc
->enabled
|| b
->loc
->disabled_by_cond
)))
6060 header_of_multiple
= 1;
6068 if (part_of_multiple
)
6069 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6071 uiout
->field_signed ("number", b
->number
);
6075 if (part_of_multiple
)
6076 uiout
->field_skip ("type");
6078 uiout
->field_string ("type", bptype_string (b
->type
));
6082 if (part_of_multiple
)
6083 uiout
->field_skip ("disp");
6085 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6089 if (part_of_multiple
)
6090 uiout
->field_string ("enabled", (loc
->disabled_by_cond
? "N*"
6091 : (loc
->enabled
? "y" : "n")));
6093 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6096 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6097 b
->ops
->print_one (b
, last_loc
);
6100 if (is_watchpoint (b
))
6102 struct watchpoint
*w
= (struct watchpoint
*) b
;
6104 /* Field 4, the address, is omitted (which makes the columns
6105 not line up too nicely with the headers, but the effect
6106 is relatively readable). */
6107 if (opts
.addressprint
)
6108 uiout
->field_skip ("addr");
6110 uiout
->field_string ("what", w
->exp_string
);
6112 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6113 || is_ada_exception_catchpoint (b
))
6115 if (opts
.addressprint
)
6118 if (header_of_multiple
)
6119 uiout
->field_string ("addr", "<MULTIPLE>",
6120 metadata_style
.style ());
6121 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6122 uiout
->field_string ("addr", "<PENDING>",
6123 metadata_style
.style ());
6125 uiout
->field_core_addr ("addr",
6126 loc
->gdbarch
, loc
->address
);
6129 if (!header_of_multiple
)
6130 print_breakpoint_location (b
, loc
);
6136 if (loc
!= NULL
&& !header_of_multiple
)
6138 std::vector
<int> inf_nums
;
6141 for (inferior
*inf
: all_inferiors ())
6143 if (inf
->pspace
== loc
->pspace
)
6144 inf_nums
.push_back (inf
->num
);
6147 /* For backward compatibility, don't display inferiors in CLI unless
6148 there are several. Always display for MI. */
6150 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6151 && (program_spaces
.size () > 1
6152 || number_of_inferiors () > 1)
6153 /* LOC is for existing B, it cannot be in
6154 moribund_locations and thus having NULL OWNER. */
6155 && loc
->owner
->type
!= bp_catchpoint
))
6157 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6160 if (!part_of_multiple
)
6162 if (b
->thread
!= -1)
6164 /* FIXME: This seems to be redundant and lost here; see the
6165 "stop only in" line a little further down. */
6166 uiout
->text (" thread ");
6167 uiout
->field_signed ("thread", b
->thread
);
6169 else if (b
->task
!= 0)
6171 uiout
->text (" task ");
6172 uiout
->field_signed ("task", b
->task
);
6178 if (!part_of_multiple
)
6179 b
->ops
->print_one_detail (b
, uiout
);
6181 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6184 uiout
->text ("\tstop only in stack frame at ");
6185 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6187 uiout
->field_core_addr ("frame",
6188 b
->gdbarch
, b
->frame_id
.stack_addr
);
6192 if (!part_of_multiple
&& b
->cond_string
)
6195 if (is_tracepoint (b
))
6196 uiout
->text ("\ttrace only if ");
6198 uiout
->text ("\tstop only if ");
6199 uiout
->field_string ("cond", b
->cond_string
);
6201 /* Print whether the target is doing the breakpoint's condition
6202 evaluation. If GDB is doing the evaluation, don't print anything. */
6203 if (is_breakpoint (b
)
6204 && breakpoint_condition_evaluation_mode ()
6205 == condition_evaluation_target
)
6207 uiout
->message (" (%pF evals)",
6208 string_field ("evaluated-by",
6209 bp_condition_evaluator (b
)));
6214 if (!part_of_multiple
&& b
->thread
!= -1)
6216 /* FIXME should make an annotation for this. */
6217 uiout
->text ("\tstop only in thread ");
6218 if (uiout
->is_mi_like_p ())
6219 uiout
->field_signed ("thread", b
->thread
);
6222 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6224 uiout
->field_string ("thread", print_thread_id (thr
));
6229 if (!part_of_multiple
)
6233 /* FIXME should make an annotation for this. */
6234 if (is_catchpoint (b
))
6235 uiout
->text ("\tcatchpoint");
6236 else if (is_tracepoint (b
))
6237 uiout
->text ("\ttracepoint");
6239 uiout
->text ("\tbreakpoint");
6240 uiout
->text (" already hit ");
6241 uiout
->field_signed ("times", b
->hit_count
);
6242 if (b
->hit_count
== 1)
6243 uiout
->text (" time\n");
6245 uiout
->text (" times\n");
6249 /* Output the count also if it is zero, but only if this is mi. */
6250 if (uiout
->is_mi_like_p ())
6251 uiout
->field_signed ("times", b
->hit_count
);
6255 if (!part_of_multiple
&& b
->ignore_count
)
6258 uiout
->message ("\tignore next %pF hits\n",
6259 signed_field ("ignore", b
->ignore_count
));
6262 /* Note that an enable count of 1 corresponds to "enable once"
6263 behavior, which is reported by the combination of enablement and
6264 disposition, so we don't need to mention it here. */
6265 if (!part_of_multiple
&& b
->enable_count
> 1)
6268 uiout
->text ("\tdisable after ");
6269 /* Tweak the wording to clarify that ignore and enable counts
6270 are distinct, and have additive effect. */
6271 if (b
->ignore_count
)
6272 uiout
->text ("additional ");
6274 uiout
->text ("next ");
6275 uiout
->field_signed ("enable", b
->enable_count
);
6276 uiout
->text (" hits\n");
6279 if (!part_of_multiple
&& is_tracepoint (b
))
6281 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6283 if (tp
->traceframe_usage
)
6285 uiout
->text ("\ttrace buffer usage ");
6286 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6287 uiout
->text (" bytes\n");
6291 l
= b
->commands
? b
->commands
.get () : NULL
;
6292 if (!part_of_multiple
&& l
)
6295 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6296 print_command_lines (uiout
, l
, 4);
6299 if (is_tracepoint (b
))
6301 struct tracepoint
*t
= (struct tracepoint
*) b
;
6303 if (!part_of_multiple
&& t
->pass_count
)
6305 annotate_field (10);
6306 uiout
->text ("\tpass count ");
6307 uiout
->field_signed ("pass", t
->pass_count
);
6308 uiout
->text (" \n");
6311 /* Don't display it when tracepoint or tracepoint location is
6313 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6315 annotate_field (11);
6317 if (uiout
->is_mi_like_p ())
6318 uiout
->field_string ("installed",
6319 loc
->inserted
? "y" : "n");
6325 uiout
->text ("\tnot ");
6326 uiout
->text ("installed on target\n");
6331 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6333 if (is_watchpoint (b
))
6335 struct watchpoint
*w
= (struct watchpoint
*) b
;
6337 uiout
->field_string ("original-location", w
->exp_string
);
6339 else if (b
->location
!= NULL
6340 && event_location_to_string (b
->location
.get ()) != NULL
)
6341 uiout
->field_string ("original-location",
6342 event_location_to_string (b
->location
.get ()));
6346 /* See breakpoint.h. */
6348 bool fix_multi_location_breakpoint_output_globally
= false;
6351 print_one_breakpoint (struct breakpoint
*b
,
6352 struct bp_location
**last_loc
,
6355 struct ui_out
*uiout
= current_uiout
;
6356 bool use_fixed_output
6357 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6358 || fix_multi_location_breakpoint_output_globally
);
6360 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6361 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6363 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6365 if (!use_fixed_output
)
6366 bkpt_tuple_emitter
.reset ();
6368 /* If this breakpoint has custom print function,
6369 it's already printed. Otherwise, print individual
6370 locations, if any. */
6372 || b
->ops
->print_one
== NULL
6375 /* If breakpoint has a single location that is disabled, we
6376 print it as if it had several locations, since otherwise it's
6377 hard to represent "breakpoint enabled, location disabled"
6380 Note that while hardware watchpoints have several locations
6381 internally, that's not a property exposed to users.
6383 Likewise, while catchpoints may be implemented with
6384 breakpoints (e.g., catch throw), that's not a property
6385 exposed to users. We do however display the internal
6386 breakpoint locations with "maint info breakpoints". */
6387 if (!is_hardware_watchpoint (b
)
6388 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6389 || is_ada_exception_catchpoint (b
))
6391 || (b
->loc
&& (b
->loc
->next
6393 || b
->loc
->disabled_by_cond
))))
6395 gdb::optional
<ui_out_emit_list
> locations_list
;
6397 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6398 MI record. For later versions, place breakpoint locations in a
6400 if (uiout
->is_mi_like_p () && use_fixed_output
)
6401 locations_list
.emplace (uiout
, "locations");
6404 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
, ++n
)
6406 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6407 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6415 breakpoint_address_bits (struct breakpoint
*b
)
6417 int print_address_bits
= 0;
6418 struct bp_location
*loc
;
6420 /* Software watchpoints that aren't watching memory don't have an
6421 address to print. */
6422 if (is_no_memory_software_watchpoint (b
))
6425 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6429 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6430 if (addr_bit
> print_address_bits
)
6431 print_address_bits
= addr_bit
;
6434 return print_address_bits
;
6437 /* See breakpoint.h. */
6440 print_breakpoint (breakpoint
*b
)
6442 struct bp_location
*dummy_loc
= NULL
;
6443 print_one_breakpoint (b
, &dummy_loc
, 0);
6446 /* Return true if this breakpoint was set by the user, false if it is
6447 internal or momentary. */
6450 user_breakpoint_p (struct breakpoint
*b
)
6452 return b
->number
> 0;
6455 /* See breakpoint.h. */
6458 pending_breakpoint_p (struct breakpoint
*b
)
6460 return b
->loc
== NULL
;
6463 /* Print information on breakpoints (including watchpoints and tracepoints).
6465 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6466 understood by number_or_range_parser. Only breakpoints included in this
6467 list are then printed.
6469 If SHOW_INTERNAL is true, print internal breakpoints.
6471 If FILTER is non-NULL, call it on each breakpoint and only include the
6472 ones for which it returns true.
6474 Return the total number of breakpoints listed. */
6477 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6478 bool (*filter
) (const struct breakpoint
*))
6480 struct breakpoint
*b
;
6481 struct bp_location
*last_loc
= NULL
;
6482 int nr_printable_breakpoints
;
6483 struct value_print_options opts
;
6484 int print_address_bits
= 0;
6485 int print_type_col_width
= 14;
6486 struct ui_out
*uiout
= current_uiout
;
6487 bool has_disabled_by_cond_location
= false;
6489 get_user_print_options (&opts
);
6491 /* Compute the number of rows in the table, as well as the size
6492 required for address fields. */
6493 nr_printable_breakpoints
= 0;
6496 /* If we have a filter, only list the breakpoints it accepts. */
6497 if (filter
&& !filter (b
))
6500 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6501 accept. Skip the others. */
6502 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6504 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6506 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6510 if (show_internal
|| user_breakpoint_p (b
))
6512 int addr_bit
, type_len
;
6514 addr_bit
= breakpoint_address_bits (b
);
6515 if (addr_bit
> print_address_bits
)
6516 print_address_bits
= addr_bit
;
6518 type_len
= strlen (bptype_string (b
->type
));
6519 if (type_len
> print_type_col_width
)
6520 print_type_col_width
= type_len
;
6522 nr_printable_breakpoints
++;
6527 ui_out_emit_table
table_emitter (uiout
,
6528 opts
.addressprint
? 6 : 5,
6529 nr_printable_breakpoints
,
6532 if (nr_printable_breakpoints
> 0)
6533 annotate_breakpoints_headers ();
6534 if (nr_printable_breakpoints
> 0)
6536 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6537 if (nr_printable_breakpoints
> 0)
6539 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6540 if (nr_printable_breakpoints
> 0)
6542 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6543 if (nr_printable_breakpoints
> 0)
6545 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6546 if (opts
.addressprint
)
6548 if (nr_printable_breakpoints
> 0)
6550 if (print_address_bits
<= 32)
6551 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6553 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6555 if (nr_printable_breakpoints
> 0)
6557 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6558 uiout
->table_body ();
6559 if (nr_printable_breakpoints
> 0)
6560 annotate_breakpoints_table ();
6565 /* If we have a filter, only list the breakpoints it accepts. */
6566 if (filter
&& !filter (b
))
6569 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6570 accept. Skip the others. */
6572 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6574 if (show_internal
) /* maintenance info breakpoint */
6576 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6579 else /* all others */
6581 if (!number_is_in_list (bp_num_list
, b
->number
))
6585 /* We only print out user settable breakpoints unless the
6586 show_internal is set. */
6587 if (show_internal
|| user_breakpoint_p (b
))
6589 print_one_breakpoint (b
, &last_loc
, show_internal
);
6590 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
6591 if (loc
->disabled_by_cond
)
6592 has_disabled_by_cond_location
= true;
6597 if (nr_printable_breakpoints
== 0)
6599 /* If there's a filter, let the caller decide how to report
6603 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6604 uiout
->message ("No breakpoints or watchpoints.\n");
6606 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6612 if (last_loc
&& !server_command
)
6613 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6615 if (has_disabled_by_cond_location
)
6616 uiout
->message (_("(*): Breakpoint condition is invalid at this "
6620 /* FIXME? Should this be moved up so that it is only called when
6621 there have been breakpoints? */
6622 annotate_breakpoints_table_end ();
6624 return nr_printable_breakpoints
;
6627 /* Display the value of default-collect in a way that is generally
6628 compatible with the breakpoint list. */
6631 default_collect_info (void)
6633 struct ui_out
*uiout
= current_uiout
;
6635 /* If it has no value (which is frequently the case), say nothing; a
6636 message like "No default-collect." gets in user's face when it's
6638 if (!*default_collect
)
6641 /* The following phrase lines up nicely with per-tracepoint collect
6643 uiout
->text ("default collect ");
6644 uiout
->field_string ("default-collect", default_collect
);
6645 uiout
->text (" \n");
6649 info_breakpoints_command (const char *args
, int from_tty
)
6651 breakpoint_1 (args
, false, NULL
);
6653 default_collect_info ();
6657 info_watchpoints_command (const char *args
, int from_tty
)
6659 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6660 struct ui_out
*uiout
= current_uiout
;
6662 if (num_printed
== 0)
6664 if (args
== NULL
|| *args
== '\0')
6665 uiout
->message ("No watchpoints.\n");
6667 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6672 maintenance_info_breakpoints (const char *args
, int from_tty
)
6674 breakpoint_1 (args
, true, NULL
);
6676 default_collect_info ();
6680 breakpoint_has_pc (struct breakpoint
*b
,
6681 struct program_space
*pspace
,
6682 CORE_ADDR pc
, struct obj_section
*section
)
6684 struct bp_location
*bl
= b
->loc
;
6686 for (; bl
; bl
= bl
->next
)
6688 if (bl
->pspace
== pspace
6689 && bl
->address
== pc
6690 && (!overlay_debugging
|| bl
->section
== section
))
6696 /* Print a message describing any user-breakpoints set at PC. This
6697 concerns with logical breakpoints, so we match program spaces, not
6701 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6702 struct program_space
*pspace
, CORE_ADDR pc
,
6703 struct obj_section
*section
, int thread
)
6706 struct breakpoint
*b
;
6709 others
+= (user_breakpoint_p (b
)
6710 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6714 printf_filtered (_("Note: breakpoint "));
6715 else /* if (others == ???) */
6716 printf_filtered (_("Note: breakpoints "));
6718 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6721 printf_filtered ("%d", b
->number
);
6722 if (b
->thread
== -1 && thread
!= -1)
6723 printf_filtered (" (all threads)");
6724 else if (b
->thread
!= -1)
6725 printf_filtered (" (thread %d)", b
->thread
);
6726 printf_filtered ("%s%s ",
6727 ((b
->enable_state
== bp_disabled
6728 || b
->enable_state
== bp_call_disabled
)
6732 : ((others
== 1) ? " and" : ""));
6734 current_uiout
->message (_("also set at pc %ps.\n"),
6735 styled_string (address_style
.style (),
6736 paddress (gdbarch
, pc
)));
6741 /* Return true iff it is meaningful to use the address member of LOC.
6742 For some breakpoint types, the locations' address members are
6743 irrelevant and it makes no sense to attempt to compare them to
6744 other addresses (or use them for any other purpose either).
6746 More specifically, software watchpoints and catchpoints that are
6747 not backed by breakpoints always have a zero valued location
6748 address and we don't want to mark breakpoints of any of these types
6749 to be a duplicate of an actual breakpoint location at address
6753 bl_address_is_meaningful (bp_location
*loc
)
6755 return loc
->loc_type
!= bp_loc_other
;
6758 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6759 true if LOC1 and LOC2 represent the same watchpoint location. */
6762 watchpoint_locations_match (struct bp_location
*loc1
,
6763 struct bp_location
*loc2
)
6765 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6766 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6768 /* Both of them must exist. */
6769 gdb_assert (w1
!= NULL
);
6770 gdb_assert (w2
!= NULL
);
6772 /* If the target can evaluate the condition expression in hardware,
6773 then we we need to insert both watchpoints even if they are at
6774 the same place. Otherwise the watchpoint will only trigger when
6775 the condition of whichever watchpoint was inserted evaluates to
6776 true, not giving a chance for GDB to check the condition of the
6777 other watchpoint. */
6779 && target_can_accel_watchpoint_condition (loc1
->address
,
6781 loc1
->watchpoint_type
,
6782 w1
->cond_exp
.get ()))
6784 && target_can_accel_watchpoint_condition (loc2
->address
,
6786 loc2
->watchpoint_type
,
6787 w2
->cond_exp
.get ())))
6790 /* Note that this checks the owner's type, not the location's. In
6791 case the target does not support read watchpoints, but does
6792 support access watchpoints, we'll have bp_read_watchpoint
6793 watchpoints with hw_access locations. Those should be considered
6794 duplicates of hw_read locations. The hw_read locations will
6795 become hw_access locations later. */
6796 return (loc1
->owner
->type
== loc2
->owner
->type
6797 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6798 && loc1
->address
== loc2
->address
6799 && loc1
->length
== loc2
->length
);
6802 /* See breakpoint.h. */
6805 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6806 const address_space
*aspace2
, CORE_ADDR addr2
)
6808 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6809 || aspace1
== aspace2
)
6813 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6814 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6815 matches ASPACE2. On targets that have global breakpoints, the address
6816 space doesn't really matter. */
6819 breakpoint_address_match_range (const address_space
*aspace1
,
6821 int len1
, const address_space
*aspace2
,
6824 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6825 || aspace1
== aspace2
)
6826 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6829 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6830 a ranged breakpoint. In most targets, a match happens only if ASPACE
6831 matches the breakpoint's address space. On targets that have global
6832 breakpoints, the address space doesn't really matter. */
6835 breakpoint_location_address_match (struct bp_location
*bl
,
6836 const address_space
*aspace
,
6839 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6842 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6843 bl
->address
, bl
->length
,
6847 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6848 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6849 match happens only if ASPACE matches the breakpoint's address
6850 space. On targets that have global breakpoints, the address space
6851 doesn't really matter. */
6854 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6855 const address_space
*aspace
,
6856 CORE_ADDR addr
, int len
)
6858 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6859 || bl
->pspace
->aspace
== aspace
)
6861 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6863 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6869 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6870 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6871 true, otherwise returns false. */
6874 tracepoint_locations_match (struct bp_location
*loc1
,
6875 struct bp_location
*loc2
)
6877 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6878 /* Since tracepoint locations are never duplicated with others', tracepoint
6879 locations at the same address of different tracepoints are regarded as
6880 different locations. */
6881 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6886 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6887 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6888 the same location. If SW_HW_BPS_MATCH is true, then software
6889 breakpoint locations and hardware breakpoint locations match,
6890 otherwise they don't. */
6893 breakpoint_locations_match (struct bp_location
*loc1
,
6894 struct bp_location
*loc2
,
6895 bool sw_hw_bps_match
)
6897 int hw_point1
, hw_point2
;
6899 /* Both of them must not be in moribund_locations. */
6900 gdb_assert (loc1
->owner
!= NULL
);
6901 gdb_assert (loc2
->owner
!= NULL
);
6903 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6904 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6906 if (hw_point1
!= hw_point2
)
6909 return watchpoint_locations_match (loc1
, loc2
);
6910 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6911 return tracepoint_locations_match (loc1
, loc2
);
6913 /* We compare bp_location.length in order to cover ranged
6914 breakpoints. Keep this in sync with
6915 bp_location_is_less_than. */
6916 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6917 loc2
->pspace
->aspace
, loc2
->address
)
6918 && (loc1
->loc_type
== loc2
->loc_type
|| sw_hw_bps_match
)
6919 && loc1
->length
== loc2
->length
);
6923 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6924 int bnum
, int have_bnum
)
6926 /* The longest string possibly returned by hex_string_custom
6927 is 50 chars. These must be at least that big for safety. */
6931 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6932 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6934 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6935 bnum
, astr1
, astr2
);
6937 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6940 /* Adjust a breakpoint's address to account for architectural
6941 constraints on breakpoint placement. Return the adjusted address.
6942 Note: Very few targets require this kind of adjustment. For most
6943 targets, this function is simply the identity function. */
6946 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6947 CORE_ADDR bpaddr
, enum bptype bptype
)
6949 if (bptype
== bp_watchpoint
6950 || bptype
== bp_hardware_watchpoint
6951 || bptype
== bp_read_watchpoint
6952 || bptype
== bp_access_watchpoint
6953 || bptype
== bp_catchpoint
)
6955 /* Watchpoints and the various bp_catch_* eventpoints should not
6956 have their addresses modified. */
6959 else if (bptype
== bp_single_step
)
6961 /* Single-step breakpoints should not have their addresses
6962 modified. If there's any architectural constrain that
6963 applies to this address, then it should have already been
6964 taken into account when the breakpoint was created in the
6965 first place. If we didn't do this, stepping through e.g.,
6966 Thumb-2 IT blocks would break. */
6971 CORE_ADDR adjusted_bpaddr
= bpaddr
;
6973 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
6975 /* Some targets have architectural constraints on the placement
6976 of breakpoint instructions. Obtain the adjusted address. */
6977 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6980 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
6982 /* An adjusted breakpoint address can significantly alter
6983 a user's expectations. Print a warning if an adjustment
6985 if (adjusted_bpaddr
!= bpaddr
)
6986 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6988 return adjusted_bpaddr
;
6993 bp_location_from_bp_type (bptype type
)
6998 case bp_single_step
:
7002 case bp_longjmp_resume
:
7003 case bp_longjmp_call_dummy
:
7005 case bp_exception_resume
:
7006 case bp_step_resume
:
7007 case bp_hp_step_resume
:
7008 case bp_watchpoint_scope
:
7010 case bp_std_terminate
:
7011 case bp_shlib_event
:
7012 case bp_thread_event
:
7013 case bp_overlay_event
:
7015 case bp_longjmp_master
:
7016 case bp_std_terminate_master
:
7017 case bp_exception_master
:
7018 case bp_gnu_ifunc_resolver
:
7019 case bp_gnu_ifunc_resolver_return
:
7021 return bp_loc_software_breakpoint
;
7022 case bp_hardware_breakpoint
:
7023 return bp_loc_hardware_breakpoint
;
7024 case bp_hardware_watchpoint
:
7025 case bp_read_watchpoint
:
7026 case bp_access_watchpoint
:
7027 return bp_loc_hardware_watchpoint
;
7031 case bp_fast_tracepoint
:
7032 case bp_static_tracepoint
:
7033 return bp_loc_other
;
7035 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7039 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
7041 this->owner
= owner
;
7042 this->cond_bytecode
= NULL
;
7043 this->shlib_disabled
= 0;
7045 this->disabled_by_cond
= false;
7047 this->loc_type
= type
;
7049 if (this->loc_type
== bp_loc_software_breakpoint
7050 || this->loc_type
== bp_loc_hardware_breakpoint
)
7051 mark_breakpoint_location_modified (this);
7056 bp_location::bp_location (breakpoint
*owner
)
7057 : bp_location::bp_location (owner
,
7058 bp_location_from_bp_type (owner
->type
))
7062 /* Allocate a struct bp_location. */
7064 static struct bp_location
*
7065 allocate_bp_location (struct breakpoint
*bpt
)
7067 return bpt
->ops
->allocate_location (bpt
);
7071 free_bp_location (struct bp_location
*loc
)
7076 /* Increment reference count. */
7079 incref_bp_location (struct bp_location
*bl
)
7084 /* Decrement reference count. If the reference count reaches 0,
7085 destroy the bp_location. Sets *BLP to NULL. */
7088 decref_bp_location (struct bp_location
**blp
)
7090 gdb_assert ((*blp
)->refc
> 0);
7092 if (--(*blp
)->refc
== 0)
7093 free_bp_location (*blp
);
7097 /* Add breakpoint B at the end of the global breakpoint chain. */
7100 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7102 struct breakpoint
*b1
;
7103 struct breakpoint
*result
= b
.get ();
7105 /* Add this breakpoint to the end of the chain so that a list of
7106 breakpoints will come out in order of increasing numbers. */
7108 b1
= breakpoint_chain
;
7110 breakpoint_chain
= b
.release ();
7115 b1
->next
= b
.release ();
7121 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7124 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7125 struct gdbarch
*gdbarch
,
7127 const struct breakpoint_ops
*ops
)
7129 gdb_assert (ops
!= NULL
);
7133 b
->gdbarch
= gdbarch
;
7134 b
->language
= current_language
->la_language
;
7135 b
->input_radix
= input_radix
;
7136 b
->related_breakpoint
= b
;
7139 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7140 that has type BPTYPE and has no locations as yet. */
7142 static struct breakpoint
*
7143 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7145 const struct breakpoint_ops
*ops
)
7147 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7149 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7150 return add_to_breakpoint_chain (std::move (b
));
7153 /* Initialize loc->function_name. */
7156 set_breakpoint_location_function (struct bp_location
*loc
)
7158 gdb_assert (loc
->owner
!= NULL
);
7160 if (loc
->owner
->type
== bp_breakpoint
7161 || loc
->owner
->type
== bp_hardware_breakpoint
7162 || is_tracepoint (loc
->owner
))
7164 const char *function_name
;
7166 if (loc
->msymbol
!= NULL
7167 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7168 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7170 struct breakpoint
*b
= loc
->owner
;
7172 function_name
= loc
->msymbol
->linkage_name ();
7174 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7175 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7177 /* Create only the whole new breakpoint of this type but do not
7178 mess more complicated breakpoints with multiple locations. */
7179 b
->type
= bp_gnu_ifunc_resolver
;
7180 /* Remember the resolver's address for use by the return
7182 loc
->related_address
= loc
->address
;
7186 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7189 loc
->function_name
= xstrdup (function_name
);
7193 /* Attempt to determine architecture of location identified by SAL. */
7195 get_sal_arch (struct symtab_and_line sal
)
7198 return sal
.section
->objfile
->arch ();
7200 return SYMTAB_OBJFILE (sal
.symtab
)->arch ();
7205 /* Low level routine for partially initializing a breakpoint of type
7206 BPTYPE. The newly created breakpoint's address, section, source
7207 file name, and line number are provided by SAL.
7209 It is expected that the caller will complete the initialization of
7210 the newly created breakpoint struct as well as output any status
7211 information regarding the creation of a new breakpoint. */
7214 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7215 struct symtab_and_line sal
, enum bptype bptype
,
7216 const struct breakpoint_ops
*ops
)
7218 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7220 add_location_to_breakpoint (b
, &sal
);
7222 if (bptype
!= bp_catchpoint
)
7223 gdb_assert (sal
.pspace
!= NULL
);
7225 /* Store the program space that was used to set the breakpoint,
7226 except for ordinary breakpoints, which are independent of the
7228 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7229 b
->pspace
= sal
.pspace
;
7232 /* set_raw_breakpoint is a low level routine for allocating and
7233 partially initializing a breakpoint of type BPTYPE. The newly
7234 created breakpoint's address, section, source file name, and line
7235 number are provided by SAL. The newly created and partially
7236 initialized breakpoint is added to the breakpoint chain and
7237 is also returned as the value of this function.
7239 It is expected that the caller will complete the initialization of
7240 the newly created breakpoint struct as well as output any status
7241 information regarding the creation of a new breakpoint. In
7242 particular, set_raw_breakpoint does NOT set the breakpoint
7243 number! Care should be taken to not allow an error to occur
7244 prior to completing the initialization of the breakpoint. If this
7245 should happen, a bogus breakpoint will be left on the chain. */
7248 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7249 struct symtab_and_line sal
, enum bptype bptype
,
7250 const struct breakpoint_ops
*ops
)
7252 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7254 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7255 return add_to_breakpoint_chain (std::move (b
));
7258 /* Call this routine when stepping and nexting to enable a breakpoint
7259 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7260 initiated the operation. */
7263 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7265 struct breakpoint
*b
, *b_tmp
;
7266 int thread
= tp
->global_num
;
7268 /* To avoid having to rescan all objfile symbols at every step,
7269 we maintain a list of continually-inserted but always disabled
7270 longjmp "master" breakpoints. Here, we simply create momentary
7271 clones of those and enable them for the requested thread. */
7272 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7273 if (b
->pspace
== current_program_space
7274 && (b
->type
== bp_longjmp_master
7275 || b
->type
== bp_exception_master
))
7277 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7278 struct breakpoint
*clone
;
7280 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7281 after their removal. */
7282 clone
= momentary_breakpoint_from_master (b
, type
,
7283 &momentary_breakpoint_ops
, 1);
7284 clone
->thread
= thread
;
7287 tp
->initiating_frame
= frame
;
7290 /* Delete all longjmp breakpoints from THREAD. */
7292 delete_longjmp_breakpoint (int thread
)
7294 struct breakpoint
*b
, *b_tmp
;
7296 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7297 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7299 if (b
->thread
== thread
)
7300 delete_breakpoint (b
);
7305 delete_longjmp_breakpoint_at_next_stop (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 b
->disposition
= disp_del_at_next_stop
;
7317 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7318 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7319 pointer to any of them. Return NULL if this system cannot place longjmp
7323 set_longjmp_breakpoint_for_call_dummy (void)
7325 struct breakpoint
*b
, *retval
= NULL
;
7328 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7330 struct breakpoint
*new_b
;
7332 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7333 &momentary_breakpoint_ops
,
7335 new_b
->thread
= inferior_thread ()->global_num
;
7337 /* Link NEW_B into the chain of RETVAL breakpoints. */
7339 gdb_assert (new_b
->related_breakpoint
== new_b
);
7342 new_b
->related_breakpoint
= retval
;
7343 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7344 retval
= retval
->related_breakpoint
;
7345 retval
->related_breakpoint
= new_b
;
7351 /* Verify all existing dummy frames and their associated breakpoints for
7352 TP. Remove those which can no longer be found in the current frame
7355 You should call this function only at places where it is safe to currently
7356 unwind the whole stack. Failed stack unwind would discard live dummy
7360 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7362 struct breakpoint
*b
, *b_tmp
;
7364 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7365 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7367 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7369 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7370 dummy_b
= dummy_b
->related_breakpoint
;
7371 if (dummy_b
->type
!= bp_call_dummy
7372 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7375 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7377 while (b
->related_breakpoint
!= b
)
7379 if (b_tmp
== b
->related_breakpoint
)
7380 b_tmp
= b
->related_breakpoint
->next
;
7381 delete_breakpoint (b
->related_breakpoint
);
7383 delete_breakpoint (b
);
7388 enable_overlay_breakpoints (void)
7390 struct breakpoint
*b
;
7393 if (b
->type
== bp_overlay_event
)
7395 b
->enable_state
= bp_enabled
;
7396 update_global_location_list (UGLL_MAY_INSERT
);
7397 overlay_events_enabled
= 1;
7402 disable_overlay_breakpoints (void)
7404 struct breakpoint
*b
;
7407 if (b
->type
== bp_overlay_event
)
7409 b
->enable_state
= bp_disabled
;
7410 update_global_location_list (UGLL_DONT_INSERT
);
7411 overlay_events_enabled
= 0;
7415 /* Set an active std::terminate breakpoint for each std::terminate
7416 master breakpoint. */
7418 set_std_terminate_breakpoint (void)
7420 struct breakpoint
*b
, *b_tmp
;
7422 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7423 if (b
->pspace
== current_program_space
7424 && b
->type
== bp_std_terminate_master
)
7426 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7427 &momentary_breakpoint_ops
, 1);
7431 /* Delete all the std::terminate breakpoints. */
7433 delete_std_terminate_breakpoint (void)
7435 struct breakpoint
*b
, *b_tmp
;
7437 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7438 if (b
->type
== bp_std_terminate
)
7439 delete_breakpoint (b
);
7443 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7445 struct breakpoint
*b
;
7447 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7448 &internal_breakpoint_ops
);
7450 b
->enable_state
= bp_enabled
;
7451 /* location has to be used or breakpoint_re_set will delete me. */
7452 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7454 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7459 struct lang_and_radix
7465 /* Create a breakpoint for JIT code registration and unregistration. */
7468 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7470 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7471 &internal_breakpoint_ops
);
7474 /* Remove JIT code registration and unregistration breakpoint(s). */
7477 remove_jit_event_breakpoints (void)
7479 struct breakpoint
*b
, *b_tmp
;
7481 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7482 if (b
->type
== bp_jit_event
7483 && b
->loc
->pspace
== current_program_space
)
7484 delete_breakpoint (b
);
7488 remove_solib_event_breakpoints (void)
7490 struct breakpoint
*b
, *b_tmp
;
7492 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7493 if (b
->type
== bp_shlib_event
7494 && b
->loc
->pspace
== current_program_space
)
7495 delete_breakpoint (b
);
7498 /* See breakpoint.h. */
7501 remove_solib_event_breakpoints_at_next_stop (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 b
->disposition
= disp_del_at_next_stop
;
7511 /* Helper for create_solib_event_breakpoint /
7512 create_and_insert_solib_event_breakpoint. Allows specifying which
7513 INSERT_MODE to pass through to update_global_location_list. */
7515 static struct breakpoint
*
7516 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7517 enum ugll_insert_mode insert_mode
)
7519 struct breakpoint
*b
;
7521 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7522 &internal_breakpoint_ops
);
7523 update_global_location_list_nothrow (insert_mode
);
7528 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7530 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7533 /* See breakpoint.h. */
7536 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7538 struct breakpoint
*b
;
7540 /* Explicitly tell update_global_location_list to insert
7542 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7543 if (!b
->loc
->inserted
)
7545 delete_breakpoint (b
);
7551 /* Disable any breakpoints that are on code in shared libraries. Only
7552 apply to enabled breakpoints, disabled ones can just stay disabled. */
7555 disable_breakpoints_in_shlibs (void)
7557 struct bp_location
*loc
, **locp_tmp
;
7559 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7561 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7562 struct breakpoint
*b
= loc
->owner
;
7564 /* We apply the check to all breakpoints, including disabled for
7565 those with loc->duplicate set. This is so that when breakpoint
7566 becomes enabled, or the duplicate is removed, gdb will try to
7567 insert all breakpoints. If we don't set shlib_disabled here,
7568 we'll try to insert those breakpoints and fail. */
7569 if (((b
->type
== bp_breakpoint
)
7570 || (b
->type
== bp_jit_event
)
7571 || (b
->type
== bp_hardware_breakpoint
)
7572 || (is_tracepoint (b
)))
7573 && loc
->pspace
== current_program_space
7574 && !loc
->shlib_disabled
7575 && solib_name_from_address (loc
->pspace
, loc
->address
)
7578 loc
->shlib_disabled
= 1;
7583 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7584 notification of unloaded_shlib. Only apply to enabled breakpoints,
7585 disabled ones can just stay disabled. */
7588 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7590 struct bp_location
*loc
, **locp_tmp
;
7591 int disabled_shlib_breaks
= 0;
7593 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7595 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7596 struct breakpoint
*b
= loc
->owner
;
7598 if (solib
->pspace
== loc
->pspace
7599 && !loc
->shlib_disabled
7600 && (((b
->type
== bp_breakpoint
7601 || b
->type
== bp_jit_event
7602 || b
->type
== bp_hardware_breakpoint
)
7603 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7604 || loc
->loc_type
== bp_loc_software_breakpoint
))
7605 || is_tracepoint (b
))
7606 && solib_contains_address_p (solib
, loc
->address
))
7608 loc
->shlib_disabled
= 1;
7609 /* At this point, we cannot rely on remove_breakpoint
7610 succeeding so we must mark the breakpoint as not inserted
7611 to prevent future errors occurring in remove_breakpoints. */
7614 /* This may cause duplicate notifications for the same breakpoint. */
7615 gdb::observers::breakpoint_modified
.notify (b
);
7617 if (!disabled_shlib_breaks
)
7619 target_terminal::ours_for_output ();
7620 warning (_("Temporarily disabling breakpoints "
7621 "for unloaded shared library \"%s\""),
7624 disabled_shlib_breaks
= 1;
7629 /* Disable any breakpoints and tracepoints in OBJFILE upon
7630 notification of free_objfile. Only apply to enabled breakpoints,
7631 disabled ones can just stay disabled. */
7634 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7636 struct breakpoint
*b
;
7638 if (objfile
== NULL
)
7641 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7642 managed by the user with add-symbol-file/remove-symbol-file.
7643 Similarly to how breakpoints in shared libraries are handled in
7644 response to "nosharedlibrary", mark breakpoints in such modules
7645 shlib_disabled so they end up uninserted on the next global
7646 location list update. Shared libraries not loaded by the user
7647 aren't handled here -- they're already handled in
7648 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7649 solib_unloaded observer. We skip objfiles that are not
7650 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7652 if ((objfile
->flags
& OBJF_SHARED
) == 0
7653 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7658 struct bp_location
*loc
;
7659 int bp_modified
= 0;
7661 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7664 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7666 CORE_ADDR loc_addr
= loc
->address
;
7668 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7669 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7672 if (loc
->shlib_disabled
!= 0)
7675 if (objfile
->pspace
!= loc
->pspace
)
7678 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7679 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7682 if (is_addr_in_objfile (loc_addr
, objfile
))
7684 loc
->shlib_disabled
= 1;
7685 /* At this point, we don't know whether the object was
7686 unmapped from the inferior or not, so leave the
7687 inserted flag alone. We'll handle failure to
7688 uninsert quietly, in case the object was indeed
7691 mark_breakpoint_location_modified (loc
);
7698 gdb::observers::breakpoint_modified
.notify (b
);
7702 /* FORK & VFORK catchpoints. */
7704 /* An instance of this type is used to represent a fork or vfork
7705 catchpoint. A breakpoint is really of this type iff its ops pointer points
7706 to CATCH_FORK_BREAKPOINT_OPS. */
7708 struct fork_catchpoint
: public breakpoint
7710 /* Process id of a child process whose forking triggered this
7711 catchpoint. This field is only valid immediately after this
7712 catchpoint has triggered. */
7713 ptid_t forked_inferior_pid
;
7716 /* Implement the "insert" breakpoint_ops method for fork
7720 insert_catch_fork (struct bp_location
*bl
)
7722 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7725 /* Implement the "remove" breakpoint_ops method for fork
7729 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7731 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7734 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7738 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7739 const address_space
*aspace
, CORE_ADDR bp_addr
,
7740 const struct target_waitstatus
*ws
)
7742 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7744 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7747 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7751 /* Implement the "print_it" breakpoint_ops method for fork
7754 static enum print_stop_action
7755 print_it_catch_fork (bpstat bs
)
7757 struct ui_out
*uiout
= current_uiout
;
7758 struct breakpoint
*b
= bs
->breakpoint_at
;
7759 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7761 annotate_catchpoint (b
->number
);
7762 maybe_print_thread_hit_breakpoint (uiout
);
7763 if (b
->disposition
== disp_del
)
7764 uiout
->text ("Temporary catchpoint ");
7766 uiout
->text ("Catchpoint ");
7767 if (uiout
->is_mi_like_p ())
7769 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7770 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7772 uiout
->field_signed ("bkptno", b
->number
);
7773 uiout
->text (" (forked process ");
7774 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7775 uiout
->text ("), ");
7776 return PRINT_SRC_AND_LOC
;
7779 /* Implement the "print_one" breakpoint_ops method for fork
7783 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7785 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7786 struct value_print_options opts
;
7787 struct ui_out
*uiout
= current_uiout
;
7789 get_user_print_options (&opts
);
7791 /* Field 4, the address, is omitted (which makes the columns not
7792 line up too nicely with the headers, but the effect is relatively
7794 if (opts
.addressprint
)
7795 uiout
->field_skip ("addr");
7797 uiout
->text ("fork");
7798 if (c
->forked_inferior_pid
!= null_ptid
)
7800 uiout
->text (", process ");
7801 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7805 if (uiout
->is_mi_like_p ())
7806 uiout
->field_string ("catch-type", "fork");
7809 /* Implement the "print_mention" breakpoint_ops method for fork
7813 print_mention_catch_fork (struct breakpoint
*b
)
7815 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7818 /* Implement the "print_recreate" breakpoint_ops method for fork
7822 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7824 fprintf_unfiltered (fp
, "catch fork");
7825 print_recreate_thread (b
, fp
);
7828 /* The breakpoint_ops structure to be used in fork catchpoints. */
7830 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7832 /* Implement the "insert" breakpoint_ops method for vfork
7836 insert_catch_vfork (struct bp_location
*bl
)
7838 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7841 /* Implement the "remove" breakpoint_ops method for vfork
7845 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7847 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7850 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7854 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7855 const address_space
*aspace
, CORE_ADDR bp_addr
,
7856 const struct target_waitstatus
*ws
)
7858 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7860 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7863 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7867 /* Implement the "print_it" breakpoint_ops method for vfork
7870 static enum print_stop_action
7871 print_it_catch_vfork (bpstat bs
)
7873 struct ui_out
*uiout
= current_uiout
;
7874 struct breakpoint
*b
= bs
->breakpoint_at
;
7875 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7877 annotate_catchpoint (b
->number
);
7878 maybe_print_thread_hit_breakpoint (uiout
);
7879 if (b
->disposition
== disp_del
)
7880 uiout
->text ("Temporary catchpoint ");
7882 uiout
->text ("Catchpoint ");
7883 if (uiout
->is_mi_like_p ())
7885 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7886 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7888 uiout
->field_signed ("bkptno", b
->number
);
7889 uiout
->text (" (vforked process ");
7890 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7891 uiout
->text ("), ");
7892 return PRINT_SRC_AND_LOC
;
7895 /* Implement the "print_one" breakpoint_ops method for vfork
7899 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7901 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7902 struct value_print_options opts
;
7903 struct ui_out
*uiout
= current_uiout
;
7905 get_user_print_options (&opts
);
7906 /* Field 4, the address, is omitted (which makes the columns not
7907 line up too nicely with the headers, but the effect is relatively
7909 if (opts
.addressprint
)
7910 uiout
->field_skip ("addr");
7912 uiout
->text ("vfork");
7913 if (c
->forked_inferior_pid
!= null_ptid
)
7915 uiout
->text (", process ");
7916 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7920 if (uiout
->is_mi_like_p ())
7921 uiout
->field_string ("catch-type", "vfork");
7924 /* Implement the "print_mention" breakpoint_ops method for vfork
7928 print_mention_catch_vfork (struct breakpoint
*b
)
7930 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7933 /* Implement the "print_recreate" breakpoint_ops method for vfork
7937 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7939 fprintf_unfiltered (fp
, "catch vfork");
7940 print_recreate_thread (b
, fp
);
7943 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7945 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7947 /* An instance of this type is used to represent an solib catchpoint.
7948 A breakpoint is really of this type iff its ops pointer points to
7949 CATCH_SOLIB_BREAKPOINT_OPS. */
7951 struct solib_catchpoint
: public breakpoint
7953 ~solib_catchpoint () override
;
7955 /* True for "catch load", false for "catch unload". */
7958 /* Regular expression to match, if any. COMPILED is only valid when
7959 REGEX is non-NULL. */
7961 std::unique_ptr
<compiled_regex
> compiled
;
7964 solib_catchpoint::~solib_catchpoint ()
7966 xfree (this->regex
);
7970 insert_catch_solib (struct bp_location
*ignore
)
7976 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
7982 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7983 const address_space
*aspace
,
7985 const struct target_waitstatus
*ws
)
7987 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7988 struct breakpoint
*other
;
7990 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7993 ALL_BREAKPOINTS (other
)
7995 struct bp_location
*other_bl
;
7997 if (other
== bl
->owner
)
8000 if (other
->type
!= bp_shlib_event
)
8003 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8006 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8008 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8017 check_status_catch_solib (struct bpstats
*bs
)
8019 struct solib_catchpoint
*self
8020 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8024 for (so_list
*iter
: current_program_space
->added_solibs
)
8027 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8033 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
8036 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
8042 bs
->print_it
= print_it_noop
;
8045 static enum print_stop_action
8046 print_it_catch_solib (bpstat bs
)
8048 struct breakpoint
*b
= bs
->breakpoint_at
;
8049 struct ui_out
*uiout
= current_uiout
;
8051 annotate_catchpoint (b
->number
);
8052 maybe_print_thread_hit_breakpoint (uiout
);
8053 if (b
->disposition
== disp_del
)
8054 uiout
->text ("Temporary catchpoint ");
8056 uiout
->text ("Catchpoint ");
8057 uiout
->field_signed ("bkptno", b
->number
);
8059 if (uiout
->is_mi_like_p ())
8060 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8061 print_solib_event (1);
8062 return PRINT_SRC_AND_LOC
;
8066 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8068 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8069 struct value_print_options opts
;
8070 struct ui_out
*uiout
= current_uiout
;
8072 get_user_print_options (&opts
);
8073 /* Field 4, the address, is omitted (which makes the columns not
8074 line up too nicely with the headers, but the effect is relatively
8076 if (opts
.addressprint
)
8079 uiout
->field_skip ("addr");
8087 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8089 msg
= _("load of library");
8094 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8096 msg
= _("unload of library");
8098 uiout
->field_string ("what", msg
);
8100 if (uiout
->is_mi_like_p ())
8101 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8105 print_mention_catch_solib (struct breakpoint
*b
)
8107 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8109 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8110 self
->is_load
? "load" : "unload");
8114 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8116 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8118 fprintf_unfiltered (fp
, "%s %s",
8119 b
->disposition
== disp_del
? "tcatch" : "catch",
8120 self
->is_load
? "load" : "unload");
8122 fprintf_unfiltered (fp
, " %s", self
->regex
);
8123 fprintf_unfiltered (fp
, "\n");
8126 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8128 /* See breakpoint.h. */
8131 add_solib_catchpoint (const char *arg
, bool is_load
, bool is_temp
, bool enabled
)
8133 struct gdbarch
*gdbarch
= get_current_arch ();
8137 arg
= skip_spaces (arg
);
8139 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8143 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8144 _("Invalid regexp")));
8145 c
->regex
= xstrdup (arg
);
8148 c
->is_load
= is_load
;
8149 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8150 &catch_solib_breakpoint_ops
);
8152 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8154 install_breakpoint (0, std::move (c
), 1);
8157 /* A helper function that does all the work for "catch load" and
8161 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8162 struct cmd_list_element
*command
)
8164 const int enabled
= 1;
8165 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8167 add_solib_catchpoint (arg
, is_load
, temp
, enabled
);
8171 catch_load_command_1 (const char *arg
, int from_tty
,
8172 struct cmd_list_element
*command
)
8174 catch_load_or_unload (arg
, from_tty
, 1, command
);
8178 catch_unload_command_1 (const char *arg
, int from_tty
,
8179 struct cmd_list_element
*command
)
8181 catch_load_or_unload (arg
, from_tty
, 0, command
);
8184 /* See breakpoint.h. */
8187 init_catchpoint (struct breakpoint
*b
,
8188 struct gdbarch
*gdbarch
, bool temp
,
8189 const char *cond_string
,
8190 const struct breakpoint_ops
*ops
)
8192 symtab_and_line sal
;
8193 sal
.pspace
= current_program_space
;
8195 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8197 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8198 b
->disposition
= temp
? disp_del
: disp_donttouch
;
8202 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8204 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8205 set_breakpoint_number (internal
, b
);
8206 if (is_tracepoint (b
))
8207 set_tracepoint_count (breakpoint_count
);
8210 gdb::observers::breakpoint_created
.notify (b
);
8213 update_global_location_list (UGLL_MAY_INSERT
);
8217 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8218 bool temp
, const char *cond_string
,
8219 const struct breakpoint_ops
*ops
)
8221 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8223 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
, ops
);
8225 c
->forked_inferior_pid
= null_ptid
;
8227 install_breakpoint (0, std::move (c
), 1);
8230 /* Exec catchpoints. */
8232 /* An instance of this type is used to represent an exec catchpoint.
8233 A breakpoint is really of this type iff its ops pointer points to
8234 CATCH_EXEC_BREAKPOINT_OPS. */
8236 struct exec_catchpoint
: public breakpoint
8238 ~exec_catchpoint () override
;
8240 /* Filename of a program whose exec triggered this catchpoint.
8241 This field is only valid immediately after this catchpoint has
8243 char *exec_pathname
;
8246 /* Exec catchpoint destructor. */
8248 exec_catchpoint::~exec_catchpoint ()
8250 xfree (this->exec_pathname
);
8254 insert_catch_exec (struct bp_location
*bl
)
8256 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8260 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8262 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8266 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8267 const address_space
*aspace
, CORE_ADDR bp_addr
,
8268 const struct target_waitstatus
*ws
)
8270 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8272 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8275 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8279 static enum print_stop_action
8280 print_it_catch_exec (bpstat bs
)
8282 struct ui_out
*uiout
= current_uiout
;
8283 struct breakpoint
*b
= bs
->breakpoint_at
;
8284 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8286 annotate_catchpoint (b
->number
);
8287 maybe_print_thread_hit_breakpoint (uiout
);
8288 if (b
->disposition
== disp_del
)
8289 uiout
->text ("Temporary catchpoint ");
8291 uiout
->text ("Catchpoint ");
8292 if (uiout
->is_mi_like_p ())
8294 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8295 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8297 uiout
->field_signed ("bkptno", b
->number
);
8298 uiout
->text (" (exec'd ");
8299 uiout
->field_string ("new-exec", c
->exec_pathname
);
8300 uiout
->text ("), ");
8302 return PRINT_SRC_AND_LOC
;
8306 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8308 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8309 struct value_print_options opts
;
8310 struct ui_out
*uiout
= current_uiout
;
8312 get_user_print_options (&opts
);
8314 /* Field 4, the address, is omitted (which makes the columns
8315 not line up too nicely with the headers, but the effect
8316 is relatively readable). */
8317 if (opts
.addressprint
)
8318 uiout
->field_skip ("addr");
8320 uiout
->text ("exec");
8321 if (c
->exec_pathname
!= NULL
)
8323 uiout
->text (", program \"");
8324 uiout
->field_string ("what", c
->exec_pathname
);
8325 uiout
->text ("\" ");
8328 if (uiout
->is_mi_like_p ())
8329 uiout
->field_string ("catch-type", "exec");
8333 print_mention_catch_exec (struct breakpoint
*b
)
8335 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8338 /* Implement the "print_recreate" breakpoint_ops method for exec
8342 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8344 fprintf_unfiltered (fp
, "catch exec");
8345 print_recreate_thread (b
, fp
);
8348 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8351 hw_breakpoint_used_count (void)
8354 struct breakpoint
*b
;
8355 struct bp_location
*bl
;
8359 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8360 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8362 /* Special types of hardware breakpoints may use more than
8364 i
+= b
->ops
->resources_needed (bl
);
8371 /* Returns the resources B would use if it were a hardware
8375 hw_watchpoint_use_count (struct breakpoint
*b
)
8378 struct bp_location
*bl
;
8380 if (!breakpoint_enabled (b
))
8383 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8385 /* Special types of hardware watchpoints may use more than
8387 i
+= b
->ops
->resources_needed (bl
);
8393 /* Returns the sum the used resources of all hardware watchpoints of
8394 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8395 the sum of the used resources of all hardware watchpoints of other
8396 types _not_ TYPE. */
8399 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8400 enum bptype type
, int *other_type_used
)
8403 struct breakpoint
*b
;
8405 *other_type_used
= 0;
8410 if (!breakpoint_enabled (b
))
8413 if (b
->type
== type
)
8414 i
+= hw_watchpoint_use_count (b
);
8415 else if (is_hardware_watchpoint (b
))
8416 *other_type_used
= 1;
8423 disable_watchpoints_before_interactive_call_start (void)
8425 struct breakpoint
*b
;
8429 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8431 b
->enable_state
= bp_call_disabled
;
8432 update_global_location_list (UGLL_DONT_INSERT
);
8438 enable_watchpoints_after_interactive_call_stop (void)
8440 struct breakpoint
*b
;
8444 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8446 b
->enable_state
= bp_enabled
;
8447 update_global_location_list (UGLL_MAY_INSERT
);
8453 disable_breakpoints_before_startup (void)
8455 current_program_space
->executing_startup
= 1;
8456 update_global_location_list (UGLL_DONT_INSERT
);
8460 enable_breakpoints_after_startup (void)
8462 current_program_space
->executing_startup
= 0;
8463 breakpoint_re_set ();
8466 /* Create a new single-step breakpoint for thread THREAD, with no
8469 static struct breakpoint
*
8470 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8472 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8474 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8475 &momentary_breakpoint_ops
);
8477 b
->disposition
= disp_donttouch
;
8478 b
->frame_id
= null_frame_id
;
8481 gdb_assert (b
->thread
!= 0);
8483 return add_to_breakpoint_chain (std::move (b
));
8486 /* Set a momentary breakpoint of type TYPE at address specified by
8487 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8491 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8492 struct frame_id frame_id
, enum bptype type
)
8494 struct breakpoint
*b
;
8496 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8498 gdb_assert (!frame_id_artificial_p (frame_id
));
8500 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8501 b
->enable_state
= bp_enabled
;
8502 b
->disposition
= disp_donttouch
;
8503 b
->frame_id
= frame_id
;
8505 b
->thread
= inferior_thread ()->global_num
;
8507 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8509 return breakpoint_up (b
);
8512 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8513 The new breakpoint will have type TYPE, use OPS as its
8514 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8516 static struct breakpoint
*
8517 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8519 const struct breakpoint_ops
*ops
,
8522 struct breakpoint
*copy
;
8524 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8525 copy
->loc
= allocate_bp_location (copy
);
8526 set_breakpoint_location_function (copy
->loc
);
8528 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8529 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8530 copy
->loc
->address
= orig
->loc
->address
;
8531 copy
->loc
->section
= orig
->loc
->section
;
8532 copy
->loc
->pspace
= orig
->loc
->pspace
;
8533 copy
->loc
->probe
= orig
->loc
->probe
;
8534 copy
->loc
->line_number
= orig
->loc
->line_number
;
8535 copy
->loc
->symtab
= orig
->loc
->symtab
;
8536 copy
->loc
->enabled
= loc_enabled
;
8537 copy
->frame_id
= orig
->frame_id
;
8538 copy
->thread
= orig
->thread
;
8539 copy
->pspace
= orig
->pspace
;
8541 copy
->enable_state
= bp_enabled
;
8542 copy
->disposition
= disp_donttouch
;
8543 copy
->number
= internal_breakpoint_number
--;
8545 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8549 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8553 clone_momentary_breakpoint (struct breakpoint
*orig
)
8555 /* If there's nothing to clone, then return nothing. */
8559 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8563 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8566 struct symtab_and_line sal
;
8568 sal
= find_pc_line (pc
, 0);
8570 sal
.section
= find_pc_overlay (pc
);
8571 sal
.explicit_pc
= 1;
8573 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8577 /* Tell the user we have just set a breakpoint B. */
8580 mention (struct breakpoint
*b
)
8582 b
->ops
->print_mention (b
);
8583 current_uiout
->text ("\n");
8587 static bool bp_loc_is_permanent (struct bp_location
*loc
);
8589 /* Handle "set breakpoint auto-hw on".
8591 If the explicitly specified breakpoint type is not hardware
8592 breakpoint, check the memory map to see whether the breakpoint
8593 address is in read-only memory.
8595 - location type is not hardware breakpoint, memory is read-only.
8596 We change the type of the location to hardware breakpoint.
8598 - location type is hardware breakpoint, memory is read-write. This
8599 means we've previously made the location hardware one, but then the
8600 memory map changed, so we undo.
8604 handle_automatic_hardware_breakpoints (bp_location
*bl
)
8606 if (automatic_hardware_breakpoints
8607 && bl
->owner
->type
!= bp_hardware_breakpoint
8608 && (bl
->loc_type
== bp_loc_software_breakpoint
8609 || bl
->loc_type
== bp_loc_hardware_breakpoint
))
8611 /* When breakpoints are removed, remove_breakpoints will use
8612 location types we've just set here, the only possible problem
8613 is that memory map has changed during running program, but
8614 it's not going to work anyway with current gdb. */
8615 mem_region
*mr
= lookup_mem_region (bl
->address
);
8619 enum bp_loc_type new_type
;
8621 if (mr
->attrib
.mode
!= MEM_RW
)
8622 new_type
= bp_loc_hardware_breakpoint
;
8624 new_type
= bp_loc_software_breakpoint
;
8626 if (new_type
!= bl
->loc_type
)
8628 static bool said
= false;
8630 bl
->loc_type
= new_type
;
8633 fprintf_filtered (gdb_stdout
,
8634 _("Note: automatically using "
8635 "hardware breakpoints for "
8636 "read-only addresses.\n"));
8644 static struct bp_location
*
8645 add_location_to_breakpoint (struct breakpoint
*b
,
8646 const struct symtab_and_line
*sal
)
8648 struct bp_location
*loc
, **tmp
;
8649 CORE_ADDR adjusted_address
;
8650 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8652 if (loc_gdbarch
== NULL
)
8653 loc_gdbarch
= b
->gdbarch
;
8655 /* Adjust the breakpoint's address prior to allocating a location.
8656 Once we call allocate_bp_location(), that mostly uninitialized
8657 location will be placed on the location chain. Adjustment of the
8658 breakpoint may cause target_read_memory() to be called and we do
8659 not want its scan of the location chain to find a breakpoint and
8660 location that's only been partially initialized. */
8661 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8664 /* Sort the locations by their ADDRESS. */
8665 loc
= allocate_bp_location (b
);
8666 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8667 tmp
= &((*tmp
)->next
))
8672 loc
->requested_address
= sal
->pc
;
8673 loc
->address
= adjusted_address
;
8674 loc
->pspace
= sal
->pspace
;
8675 loc
->probe
.prob
= sal
->prob
;
8676 loc
->probe
.objfile
= sal
->objfile
;
8677 gdb_assert (loc
->pspace
!= NULL
);
8678 loc
->section
= sal
->section
;
8679 loc
->gdbarch
= loc_gdbarch
;
8680 loc
->line_number
= sal
->line
;
8681 loc
->symtab
= sal
->symtab
;
8682 loc
->symbol
= sal
->symbol
;
8683 loc
->msymbol
= sal
->msymbol
;
8684 loc
->objfile
= sal
->objfile
;
8686 set_breakpoint_location_function (loc
);
8688 /* While by definition, permanent breakpoints are already present in the
8689 code, we don't mark the location as inserted. Normally one would expect
8690 that GDB could rely on that breakpoint instruction to stop the program,
8691 thus removing the need to insert its own breakpoint, except that executing
8692 the breakpoint instruction can kill the target instead of reporting a
8693 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8694 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8695 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8696 breakpoint be inserted normally results in QEMU knowing about the GDB
8697 breakpoint, and thus trap before the breakpoint instruction is executed.
8698 (If GDB later needs to continue execution past the permanent breakpoint,
8699 it manually increments the PC, thus avoiding executing the breakpoint
8701 if (bp_loc_is_permanent (loc
))
8708 /* Return true if LOC is pointing to a permanent breakpoint,
8709 return false otherwise. */
8712 bp_loc_is_permanent (struct bp_location
*loc
)
8714 gdb_assert (loc
!= NULL
);
8716 /* If we have a non-breakpoint-backed catchpoint or a software
8717 watchpoint, just return 0. We should not attempt to read from
8718 the addresses the locations of these breakpoint types point to.
8719 gdbarch_program_breakpoint_here_p, below, will attempt to read
8721 if (!bl_address_is_meaningful (loc
))
8724 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8725 switch_to_program_space_and_thread (loc
->pspace
);
8726 return gdbarch_program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8729 /* Build a command list for the dprintf corresponding to the current
8730 settings of the dprintf style options. */
8733 update_dprintf_command_list (struct breakpoint
*b
)
8735 char *dprintf_args
= b
->extra_string
;
8736 char *printf_line
= NULL
;
8741 dprintf_args
= skip_spaces (dprintf_args
);
8743 /* Allow a comma, as it may have terminated a location, but don't
8745 if (*dprintf_args
== ',')
8747 dprintf_args
= skip_spaces (dprintf_args
);
8749 if (*dprintf_args
!= '"')
8750 error (_("Bad format string, missing '\"'."));
8752 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8753 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8754 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8756 if (!dprintf_function
)
8757 error (_("No function supplied for dprintf call"));
8759 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8760 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8765 printf_line
= xstrprintf ("call (void) %s (%s)",
8769 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8771 if (target_can_run_breakpoint_commands ())
8772 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8775 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8776 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8780 internal_error (__FILE__
, __LINE__
,
8781 _("Invalid dprintf style."));
8783 gdb_assert (printf_line
!= NULL
);
8785 /* Manufacture a printf sequence. */
8786 struct command_line
*printf_cmd_line
8787 = new struct command_line (simple_control
, printf_line
);
8788 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8789 command_lines_deleter ()));
8792 /* Update all dprintf commands, making their command lists reflect
8793 current style settings. */
8796 update_dprintf_commands (const char *args
, int from_tty
,
8797 struct cmd_list_element
*c
)
8799 struct breakpoint
*b
;
8803 if (b
->type
== bp_dprintf
)
8804 update_dprintf_command_list (b
);
8808 /* Create a breakpoint with SAL as location. Use LOCATION
8809 as a description of the location, and COND_STRING
8810 as condition expression. If LOCATION is NULL then create an
8811 "address location" from the address in the SAL. */
8814 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8815 gdb::array_view
<const symtab_and_line
> sals
,
8816 event_location_up
&&location
,
8817 gdb::unique_xmalloc_ptr
<char> filter
,
8818 gdb::unique_xmalloc_ptr
<char> cond_string
,
8819 gdb::unique_xmalloc_ptr
<char> extra_string
,
8820 enum bptype type
, enum bpdisp disposition
,
8821 int thread
, int task
, int ignore_count
,
8822 const struct breakpoint_ops
*ops
, int from_tty
,
8823 int enabled
, int internal
, unsigned flags
,
8824 int display_canonical
)
8828 if (type
== bp_hardware_breakpoint
)
8830 int target_resources_ok
;
8832 i
= hw_breakpoint_used_count ();
8833 target_resources_ok
=
8834 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8836 if (target_resources_ok
== 0)
8837 error (_("No hardware breakpoint support in the target."));
8838 else if (target_resources_ok
< 0)
8839 error (_("Hardware breakpoints used exceeds limit."));
8842 gdb_assert (!sals
.empty ());
8844 for (const auto &sal
: sals
)
8846 struct bp_location
*loc
;
8850 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8852 loc_gdbarch
= gdbarch
;
8854 describe_other_breakpoints (loc_gdbarch
,
8855 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8858 if (&sal
== &sals
[0])
8860 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8864 b
->cond_string
= cond_string
.release ();
8865 b
->extra_string
= extra_string
.release ();
8866 b
->ignore_count
= ignore_count
;
8867 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8868 b
->disposition
= disposition
;
8870 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8871 b
->loc
->inserted
= 1;
8873 if (type
== bp_static_tracepoint
)
8875 struct tracepoint
*t
= (struct tracepoint
*) b
;
8876 struct static_tracepoint_marker marker
;
8878 if (strace_marker_p (b
))
8880 /* We already know the marker exists, otherwise, we
8881 wouldn't see a sal for it. */
8883 = &event_location_to_string (b
->location
.get ())[3];
8886 p
= skip_spaces (p
);
8888 endp
= skip_to_space (p
);
8890 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8892 printf_filtered (_("Probed static tracepoint "
8894 t
->static_trace_marker_id
.c_str ());
8896 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8898 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8900 printf_filtered (_("Probed static tracepoint "
8902 t
->static_trace_marker_id
.c_str ());
8905 warning (_("Couldn't determine the static "
8906 "tracepoint marker to probe"));
8913 loc
= add_location_to_breakpoint (b
, &sal
);
8914 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8918 /* Do not set breakpoint locations conditions yet. As locations
8919 are inserted, they get sorted based on their addresses. Let
8920 the list stabilize to have reliable location numbers. */
8922 /* Dynamic printf requires and uses additional arguments on the
8923 command line, otherwise it's an error. */
8924 if (type
== bp_dprintf
)
8926 if (b
->extra_string
)
8927 update_dprintf_command_list (b
);
8929 error (_("Format string required"));
8931 else if (b
->extra_string
)
8932 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8936 /* The order of the locations is now stable. Set the location
8937 condition using the location's number. */
8939 for (bp_location
*loc
= b
->loc
; loc
!= nullptr; loc
= loc
->next
)
8941 if (b
->cond_string
!= nullptr)
8942 set_breakpoint_location_condition (b
->cond_string
, loc
, b
->number
,
8948 b
->display_canonical
= display_canonical
;
8949 if (location
!= NULL
)
8950 b
->location
= std::move (location
);
8952 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8953 b
->filter
= std::move (filter
);
8957 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8958 gdb::array_view
<const symtab_and_line
> sals
,
8959 event_location_up
&&location
,
8960 gdb::unique_xmalloc_ptr
<char> filter
,
8961 gdb::unique_xmalloc_ptr
<char> cond_string
,
8962 gdb::unique_xmalloc_ptr
<char> extra_string
,
8963 enum bptype type
, enum bpdisp disposition
,
8964 int thread
, int task
, int ignore_count
,
8965 const struct breakpoint_ops
*ops
, int from_tty
,
8966 int enabled
, int internal
, unsigned flags
,
8967 int display_canonical
)
8969 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8971 init_breakpoint_sal (b
.get (), gdbarch
,
8972 sals
, std::move (location
),
8974 std::move (cond_string
),
8975 std::move (extra_string
),
8977 thread
, task
, ignore_count
,
8979 enabled
, internal
, flags
,
8982 install_breakpoint (internal
, std::move (b
), 0);
8985 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8986 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8987 value. COND_STRING, if not NULL, specified the condition to be
8988 used for all breakpoints. Essentially the only case where
8989 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8990 function. In that case, it's still not possible to specify
8991 separate conditions for different overloaded functions, so
8992 we take just a single condition string.
8994 NOTE: If the function succeeds, the caller is expected to cleanup
8995 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8996 array contents). If the function fails (error() is called), the
8997 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8998 COND and SALS arrays and each of those arrays contents. */
9001 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9002 struct linespec_result
*canonical
,
9003 gdb::unique_xmalloc_ptr
<char> cond_string
,
9004 gdb::unique_xmalloc_ptr
<char> extra_string
,
9005 enum bptype type
, enum bpdisp disposition
,
9006 int thread
, int task
, int ignore_count
,
9007 const struct breakpoint_ops
*ops
, int from_tty
,
9008 int enabled
, int internal
, unsigned flags
)
9010 if (canonical
->pre_expanded
)
9011 gdb_assert (canonical
->lsals
.size () == 1);
9013 for (const auto &lsal
: canonical
->lsals
)
9015 /* Note that 'location' can be NULL in the case of a plain
9016 'break', without arguments. */
9017 event_location_up location
9018 = (canonical
->location
!= NULL
9019 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9020 gdb::unique_xmalloc_ptr
<char> filter_string
9021 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9023 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9024 std::move (location
),
9025 std::move (filter_string
),
9026 std::move (cond_string
),
9027 std::move (extra_string
),
9029 thread
, task
, ignore_count
, ops
,
9030 from_tty
, enabled
, internal
, flags
,
9031 canonical
->special_display
);
9035 /* Parse LOCATION which is assumed to be a SAL specification possibly
9036 followed by conditionals. On return, SALS contains an array of SAL
9037 addresses found. LOCATION points to the end of the SAL (for
9038 linespec locations).
9040 The array and the line spec strings are allocated on the heap, it is
9041 the caller's responsibility to free them. */
9044 parse_breakpoint_sals (struct event_location
*location
,
9045 struct linespec_result
*canonical
)
9047 struct symtab_and_line cursal
;
9049 if (event_location_type (location
) == LINESPEC_LOCATION
)
9051 const char *spec
= get_linespec_location (location
)->spec_string
;
9055 /* The last displayed codepoint, if it's valid, is our default
9056 breakpoint address. */
9057 if (last_displayed_sal_is_valid ())
9059 /* Set sal's pspace, pc, symtab, and line to the values
9060 corresponding to the last call to print_frame_info.
9061 Be sure to reinitialize LINE with NOTCURRENT == 0
9062 as the breakpoint line number is inappropriate otherwise.
9063 find_pc_line would adjust PC, re-set it back. */
9064 symtab_and_line sal
= get_last_displayed_sal ();
9065 CORE_ADDR pc
= sal
.pc
;
9067 sal
= find_pc_line (pc
, 0);
9069 /* "break" without arguments is equivalent to "break *PC"
9070 where PC is the last displayed codepoint's address. So
9071 make sure to set sal.explicit_pc to prevent GDB from
9072 trying to expand the list of sals to include all other
9073 instances with the same symtab and line. */
9075 sal
.explicit_pc
= 1;
9077 struct linespec_sals lsal
;
9079 lsal
.canonical
= NULL
;
9081 canonical
->lsals
.push_back (std::move (lsal
));
9085 error (_("No default breakpoint address now."));
9089 /* Force almost all breakpoints to be in terms of the
9090 current_source_symtab (which is decode_line_1's default).
9091 This should produce the results we want almost all of the
9092 time while leaving default_breakpoint_* alone.
9094 ObjC: However, don't match an Objective-C method name which
9095 may have a '+' or '-' succeeded by a '['. */
9096 cursal
= get_current_source_symtab_and_line ();
9097 if (last_displayed_sal_is_valid ())
9099 const char *spec
= NULL
;
9101 if (event_location_type (location
) == LINESPEC_LOCATION
)
9102 spec
= get_linespec_location (location
)->spec_string
;
9106 && strchr ("+-", spec
[0]) != NULL
9109 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9110 get_last_displayed_symtab (),
9111 get_last_displayed_line (),
9112 canonical
, NULL
, NULL
);
9117 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9118 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9122 /* Convert each SAL into a real PC. Verify that the PC can be
9123 inserted as a breakpoint. If it can't throw an error. */
9126 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9128 for (auto &sal
: sals
)
9129 resolve_sal_pc (&sal
);
9132 /* Fast tracepoints may have restrictions on valid locations. For
9133 instance, a fast tracepoint using a jump instead of a trap will
9134 likely have to overwrite more bytes than a trap would, and so can
9135 only be placed where the instruction is longer than the jump, or a
9136 multi-instruction sequence does not have a jump into the middle of
9140 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9141 gdb::array_view
<const symtab_and_line
> sals
)
9143 for (const auto &sal
: sals
)
9145 struct gdbarch
*sarch
;
9147 sarch
= get_sal_arch (sal
);
9148 /* We fall back to GDBARCH if there is no architecture
9149 associated with SAL. */
9153 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9154 error (_("May not have a fast tracepoint at %s%s"),
9155 paddress (sarch
, sal
.pc
), msg
.c_str ());
9159 /* Given TOK, a string specification of condition and thread, as
9160 accepted by the 'break' command, extract the condition
9161 string and thread number and set *COND_STRING and *THREAD.
9162 PC identifies the context at which the condition should be parsed.
9163 If no condition is found, *COND_STRING is set to NULL.
9164 If no thread is found, *THREAD is set to -1. */
9167 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9168 char **cond_string
, int *thread
, int *task
,
9171 *cond_string
= NULL
;
9178 const char *end_tok
;
9180 const char *cond_start
= NULL
;
9181 const char *cond_end
= NULL
;
9183 tok
= skip_spaces (tok
);
9185 if ((*tok
== '"' || *tok
== ',') && rest
)
9187 *rest
= savestring (tok
, strlen (tok
));
9191 end_tok
= skip_to_space (tok
);
9193 toklen
= end_tok
- tok
;
9195 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9197 tok
= cond_start
= end_tok
+ 1;
9198 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9200 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9202 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9205 struct thread_info
*thr
;
9208 thr
= parse_thread_id (tok
, &tmptok
);
9210 error (_("Junk after thread keyword."));
9211 *thread
= thr
->global_num
;
9214 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9219 *task
= strtol (tok
, &tmptok
, 0);
9221 error (_("Junk after task keyword."));
9222 if (!valid_task_id (*task
))
9223 error (_("Unknown task %d."), *task
);
9228 *rest
= savestring (tok
, strlen (tok
));
9232 error (_("Junk at end of arguments."));
9236 /* Call 'find_condition_and_thread' for each sal in SALS until a parse
9237 succeeds. The parsed values are written to COND_STRING, THREAD,
9238 TASK, and REST. See the comment of 'find_condition_and_thread'
9239 for the description of these parameters and INPUT. */
9242 find_condition_and_thread_for_sals (const std::vector
<symtab_and_line
> &sals
,
9243 const char *input
, char **cond_string
,
9244 int *thread
, int *task
, char **rest
)
9246 int num_failures
= 0;
9247 for (auto &sal
: sals
)
9249 char *cond
= nullptr;
9252 char *remaining
= nullptr;
9254 /* Here we want to parse 'arg' to separate condition from thread
9255 number. But because parsing happens in a context and the
9256 contexts of sals might be different, try each until there is
9257 success. Finding one successful parse is sufficient for our
9258 goal. When setting the breakpoint we'll re-parse the
9259 condition in the context of each sal. */
9262 find_condition_and_thread (input
, sal
.pc
, &cond
, &thread_id
,
9263 &task_id
, &remaining
);
9264 *cond_string
= cond
;
9265 *thread
= thread_id
;
9270 catch (const gdb_exception_error
&e
)
9273 /* If no sal remains, do not continue. */
9274 if (num_failures
== sals
.size ())
9280 /* Decode a static tracepoint marker spec. */
9282 static std::vector
<symtab_and_line
>
9283 decode_static_tracepoint_spec (const char **arg_p
)
9285 const char *p
= &(*arg_p
)[3];
9288 p
= skip_spaces (p
);
9290 endp
= skip_to_space (p
);
9292 std::string
marker_str (p
, endp
- p
);
9294 std::vector
<static_tracepoint_marker
> markers
9295 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9296 if (markers
.empty ())
9297 error (_("No known static tracepoint marker named %s"),
9298 marker_str
.c_str ());
9300 std::vector
<symtab_and_line
> sals
;
9301 sals
.reserve (markers
.size ());
9303 for (const static_tracepoint_marker
&marker
: markers
)
9305 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9306 sal
.pc
= marker
.address
;
9307 sals
.push_back (sal
);
9314 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9315 according to IS_TRACEPOINT. */
9317 static const struct breakpoint_ops
*
9318 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
9323 if (location_type
== PROBE_LOCATION
)
9324 return &tracepoint_probe_breakpoint_ops
;
9326 return &tracepoint_breakpoint_ops
;
9330 if (location_type
== PROBE_LOCATION
)
9331 return &bkpt_probe_breakpoint_ops
;
9333 return &bkpt_breakpoint_ops
;
9337 /* See breakpoint.h. */
9339 const struct breakpoint_ops
*
9340 breakpoint_ops_for_event_location (const struct event_location
*location
,
9343 if (location
!= nullptr)
9344 return breakpoint_ops_for_event_location_type
9345 (event_location_type (location
), is_tracepoint
);
9346 return is_tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
9349 /* See breakpoint.h. */
9352 create_breakpoint (struct gdbarch
*gdbarch
,
9353 struct event_location
*location
,
9354 const char *cond_string
,
9355 int thread
, const char *extra_string
,
9357 int tempflag
, enum bptype type_wanted
,
9359 enum auto_boolean pending_break_support
,
9360 const struct breakpoint_ops
*ops
,
9361 int from_tty
, int enabled
, int internal
,
9364 struct linespec_result canonical
;
9367 int prev_bkpt_count
= breakpoint_count
;
9369 gdb_assert (ops
!= NULL
);
9371 /* If extra_string isn't useful, set it to NULL. */
9372 if (extra_string
!= NULL
&& *extra_string
== '\0')
9373 extra_string
= NULL
;
9377 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9379 catch (const gdb_exception_error
&e
)
9381 /* If caller is interested in rc value from parse, set
9383 if (e
.error
== NOT_FOUND_ERROR
)
9385 /* If pending breakpoint support is turned off, throw
9388 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9391 exception_print (gdb_stderr
, e
);
9393 /* If pending breakpoint support is auto query and the user
9394 selects no, then simply return the error code. */
9395 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9396 && !nquery (_("Make %s pending on future shared library load? "),
9397 bptype_string (type_wanted
)))
9400 /* At this point, either the user was queried about setting
9401 a pending breakpoint and selected yes, or pending
9402 breakpoint behavior is on and thus a pending breakpoint
9403 is defaulted on behalf of the user. */
9410 if (!pending
&& canonical
.lsals
.empty ())
9413 /* Resolve all line numbers to PC's and verify that the addresses
9414 are ok for the target. */
9417 for (auto &lsal
: canonical
.lsals
)
9418 breakpoint_sals_to_pc (lsal
.sals
);
9421 /* Fast tracepoints may have additional restrictions on location. */
9422 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9424 for (const auto &lsal
: canonical
.lsals
)
9425 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9428 /* Verify that condition can be parsed, before setting any
9429 breakpoints. Allocate a separate condition expression for each
9433 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9434 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9441 const linespec_sals
&lsal
= canonical
.lsals
[0];
9443 find_condition_and_thread_for_sals (lsal
.sals
, extra_string
,
9444 &cond
, &thread
, &task
, &rest
);
9445 cond_string_copy
.reset (cond
);
9446 extra_string_copy
.reset (rest
);
9450 if (type_wanted
!= bp_dprintf
9451 && extra_string
!= NULL
&& *extra_string
!= '\0')
9452 error (_("Garbage '%s' at end of location"), extra_string
);
9454 /* Create a private copy of condition string. */
9456 cond_string_copy
.reset (xstrdup (cond_string
));
9457 /* Create a private copy of any extra string. */
9459 extra_string_copy
.reset (xstrdup (extra_string
));
9462 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9463 std::move (cond_string_copy
),
9464 std::move (extra_string_copy
),
9466 tempflag
? disp_del
: disp_donttouch
,
9467 thread
, task
, ignore_count
, ops
,
9468 from_tty
, enabled
, internal
, flags
);
9472 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9474 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9475 b
->location
= copy_event_location (location
);
9478 b
->cond_string
= NULL
;
9481 /* Create a private copy of condition string. */
9482 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9486 /* Create a private copy of any extra string. */
9487 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9488 b
->ignore_count
= ignore_count
;
9489 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9490 b
->condition_not_parsed
= 1;
9491 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9492 if ((type_wanted
!= bp_breakpoint
9493 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9494 b
->pspace
= current_program_space
;
9496 install_breakpoint (internal
, std::move (b
), 0);
9499 if (canonical
.lsals
.size () > 1)
9501 warning (_("Multiple breakpoints were set.\nUse the "
9502 "\"delete\" command to delete unwanted breakpoints."));
9503 prev_breakpoint_count
= prev_bkpt_count
;
9506 update_global_location_list (UGLL_MAY_INSERT
);
9511 /* Set a breakpoint.
9512 ARG is a string describing breakpoint address,
9513 condition, and thread.
9514 FLAG specifies if a breakpoint is hardware on,
9515 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9519 break_command_1 (const char *arg
, int flag
, int from_tty
)
9521 int tempflag
= flag
& BP_TEMPFLAG
;
9522 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9523 ? bp_hardware_breakpoint
9526 event_location_up location
= string_to_event_location (&arg
, current_language
);
9527 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9528 (location
.get (), false /* is_tracepoint */);
9530 create_breakpoint (get_current_arch (),
9532 NULL
, 0, arg
, 1 /* parse arg */,
9533 tempflag
, type_wanted
,
9534 0 /* Ignore count */,
9535 pending_break_support
,
9543 /* Helper function for break_command_1 and disassemble_command. */
9546 resolve_sal_pc (struct symtab_and_line
*sal
)
9550 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9552 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9553 error (_("No line %d in file \"%s\"."),
9554 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9557 /* If this SAL corresponds to a breakpoint inserted using a line
9558 number, then skip the function prologue if necessary. */
9559 if (sal
->explicit_line
)
9560 skip_prologue_sal (sal
);
9563 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9565 const struct blockvector
*bv
;
9566 const struct block
*b
;
9569 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9570 SYMTAB_COMPUNIT (sal
->symtab
));
9573 sym
= block_linkage_function (b
);
9576 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9577 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9582 /* It really is worthwhile to have the section, so we'll
9583 just have to look harder. This case can be executed
9584 if we have line numbers but no functions (as can
9585 happen in assembly source). */
9587 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9588 switch_to_program_space_and_thread (sal
->pspace
);
9590 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9592 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9599 break_command (const char *arg
, int from_tty
)
9601 break_command_1 (arg
, 0, from_tty
);
9605 tbreak_command (const char *arg
, int from_tty
)
9607 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9611 hbreak_command (const char *arg
, int from_tty
)
9613 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9617 thbreak_command (const char *arg
, int from_tty
)
9619 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9623 stop_command (const char *arg
, int from_tty
)
9625 printf_filtered (_("Specify the type of breakpoint to set.\n\
9626 Usage: stop in <function | address>\n\
9627 stop at <line>\n"));
9631 stopin_command (const char *arg
, int from_tty
)
9637 else if (*arg
!= '*')
9639 const char *argptr
= arg
;
9642 /* Look for a ':'. If this is a line number specification, then
9643 say it is bad, otherwise, it should be an address or
9644 function/method name. */
9645 while (*argptr
&& !hasColon
)
9647 hasColon
= (*argptr
== ':');
9652 badInput
= (*argptr
!= ':'); /* Not a class::method */
9654 badInput
= isdigit (*arg
); /* a simple line number */
9658 printf_filtered (_("Usage: stop in <function | address>\n"));
9660 break_command_1 (arg
, 0, from_tty
);
9664 stopat_command (const char *arg
, int from_tty
)
9668 if (arg
== NULL
|| *arg
== '*') /* no line number */
9672 const char *argptr
= arg
;
9675 /* Look for a ':'. If there is a '::' then get out, otherwise
9676 it is probably a line number. */
9677 while (*argptr
&& !hasColon
)
9679 hasColon
= (*argptr
== ':');
9684 badInput
= (*argptr
== ':'); /* we have class::method */
9686 badInput
= !isdigit (*arg
); /* not a line number */
9690 printf_filtered (_("Usage: stop at LINE\n"));
9692 break_command_1 (arg
, 0, from_tty
);
9695 /* The dynamic printf command is mostly like a regular breakpoint, but
9696 with a prewired command list consisting of a single output command,
9697 built from extra arguments supplied on the dprintf command
9701 dprintf_command (const char *arg
, int from_tty
)
9703 event_location_up location
= string_to_event_location (&arg
, current_language
);
9705 /* If non-NULL, ARG should have been advanced past the location;
9706 the next character must be ','. */
9709 if (arg
[0] != ',' || arg
[1] == '\0')
9710 error (_("Format string required"));
9713 /* Skip the comma. */
9718 create_breakpoint (get_current_arch (),
9720 NULL
, 0, arg
, 1 /* parse arg */,
9722 0 /* Ignore count */,
9723 pending_break_support
,
9724 &dprintf_breakpoint_ops
,
9732 agent_printf_command (const char *arg
, int from_tty
)
9734 error (_("May only run agent-printf on the target"));
9737 /* Implement the "breakpoint_hit" breakpoint_ops method for
9738 ranged breakpoints. */
9741 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9742 const address_space
*aspace
,
9744 const struct target_waitstatus
*ws
)
9746 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9747 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9750 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9751 bl
->length
, aspace
, bp_addr
);
9754 /* Implement the "resources_needed" breakpoint_ops method for
9755 ranged breakpoints. */
9758 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9760 return target_ranged_break_num_registers ();
9763 /* Implement the "print_it" breakpoint_ops method for
9764 ranged breakpoints. */
9766 static enum print_stop_action
9767 print_it_ranged_breakpoint (bpstat bs
)
9769 struct breakpoint
*b
= bs
->breakpoint_at
;
9770 struct bp_location
*bl
= b
->loc
;
9771 struct ui_out
*uiout
= current_uiout
;
9773 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9775 /* Ranged breakpoints have only one location. */
9776 gdb_assert (bl
&& bl
->next
== NULL
);
9778 annotate_breakpoint (b
->number
);
9780 maybe_print_thread_hit_breakpoint (uiout
);
9782 if (b
->disposition
== disp_del
)
9783 uiout
->text ("Temporary ranged breakpoint ");
9785 uiout
->text ("Ranged breakpoint ");
9786 if (uiout
->is_mi_like_p ())
9788 uiout
->field_string ("reason",
9789 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9790 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9792 uiout
->field_signed ("bkptno", b
->number
);
9795 return PRINT_SRC_AND_LOC
;
9798 /* Implement the "print_one" breakpoint_ops method for
9799 ranged breakpoints. */
9802 print_one_ranged_breakpoint (struct breakpoint
*b
,
9803 struct bp_location
**last_loc
)
9805 struct bp_location
*bl
= b
->loc
;
9806 struct value_print_options opts
;
9807 struct ui_out
*uiout
= current_uiout
;
9809 /* Ranged breakpoints have only one location. */
9810 gdb_assert (bl
&& bl
->next
== NULL
);
9812 get_user_print_options (&opts
);
9814 if (opts
.addressprint
)
9815 /* We don't print the address range here, it will be printed later
9816 by print_one_detail_ranged_breakpoint. */
9817 uiout
->field_skip ("addr");
9819 print_breakpoint_location (b
, bl
);
9823 /* Implement the "print_one_detail" breakpoint_ops method for
9824 ranged breakpoints. */
9827 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9828 struct ui_out
*uiout
)
9830 CORE_ADDR address_start
, address_end
;
9831 struct bp_location
*bl
= b
->loc
;
9836 address_start
= bl
->address
;
9837 address_end
= address_start
+ bl
->length
- 1;
9839 uiout
->text ("\taddress range: ");
9840 stb
.printf ("[%s, %s]",
9841 print_core_address (bl
->gdbarch
, address_start
),
9842 print_core_address (bl
->gdbarch
, address_end
));
9843 uiout
->field_stream ("addr", stb
);
9847 /* Implement the "print_mention" breakpoint_ops method for
9848 ranged breakpoints. */
9851 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9853 struct bp_location
*bl
= b
->loc
;
9854 struct ui_out
*uiout
= current_uiout
;
9857 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9859 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9860 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9861 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9864 /* Implement the "print_recreate" breakpoint_ops method for
9865 ranged breakpoints. */
9868 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9870 fprintf_unfiltered (fp
, "break-range %s, %s",
9871 event_location_to_string (b
->location
.get ()),
9872 event_location_to_string (b
->location_range_end
.get ()));
9873 print_recreate_thread (b
, fp
);
9876 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9878 static struct breakpoint_ops ranged_breakpoint_ops
;
9880 /* Find the address where the end of the breakpoint range should be
9881 placed, given the SAL of the end of the range. This is so that if
9882 the user provides a line number, the end of the range is set to the
9883 last instruction of the given line. */
9886 find_breakpoint_range_end (struct symtab_and_line sal
)
9890 /* If the user provided a PC value, use it. Otherwise,
9891 find the address of the end of the given location. */
9892 if (sal
.explicit_pc
)
9899 ret
= find_line_pc_range (sal
, &start
, &end
);
9901 error (_("Could not find location of the end of the range."));
9903 /* find_line_pc_range returns the start of the next line. */
9910 /* Implement the "break-range" CLI command. */
9913 break_range_command (const char *arg
, int from_tty
)
9915 const char *arg_start
;
9916 struct linespec_result canonical_start
, canonical_end
;
9917 int bp_count
, can_use_bp
, length
;
9919 struct breakpoint
*b
;
9921 /* We don't support software ranged breakpoints. */
9922 if (target_ranged_break_num_registers () < 0)
9923 error (_("This target does not support hardware ranged breakpoints."));
9925 bp_count
= hw_breakpoint_used_count ();
9926 bp_count
+= target_ranged_break_num_registers ();
9927 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9930 error (_("Hardware breakpoints used exceeds limit."));
9932 arg
= skip_spaces (arg
);
9933 if (arg
== NULL
|| arg
[0] == '\0')
9934 error(_("No address range specified."));
9937 event_location_up start_location
= string_to_event_location (&arg
,
9939 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9942 error (_("Too few arguments."));
9943 else if (canonical_start
.lsals
.empty ())
9944 error (_("Could not find location of the beginning of the range."));
9946 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9948 if (canonical_start
.lsals
.size () > 1
9949 || lsal_start
.sals
.size () != 1)
9950 error (_("Cannot create a ranged breakpoint with multiple locations."));
9952 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9953 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9955 arg
++; /* Skip the comma. */
9956 arg
= skip_spaces (arg
);
9958 /* Parse the end location. */
9962 /* We call decode_line_full directly here instead of using
9963 parse_breakpoint_sals because we need to specify the start location's
9964 symtab and line as the default symtab and line for the end of the
9965 range. This makes it possible to have ranges like "foo.c:27, +14",
9966 where +14 means 14 lines from the start location. */
9967 event_location_up end_location
= string_to_event_location (&arg
,
9969 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9970 sal_start
.symtab
, sal_start
.line
,
9971 &canonical_end
, NULL
, NULL
);
9973 if (canonical_end
.lsals
.empty ())
9974 error (_("Could not find location of the end of the range."));
9976 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9977 if (canonical_end
.lsals
.size () > 1
9978 || lsal_end
.sals
.size () != 1)
9979 error (_("Cannot create a ranged breakpoint with multiple locations."));
9981 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9983 end
= find_breakpoint_range_end (sal_end
);
9984 if (sal_start
.pc
> end
)
9985 error (_("Invalid address range, end precedes start."));
9987 length
= end
- sal_start
.pc
+ 1;
9989 /* Length overflowed. */
9990 error (_("Address range too large."));
9991 else if (length
== 1)
9993 /* This range is simple enough to be handled by
9994 the `hbreak' command. */
9995 hbreak_command (&addr_string_start
[0], 1);
10000 /* Now set up the breakpoint. */
10001 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10002 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10003 set_breakpoint_count (breakpoint_count
+ 1);
10004 b
->number
= breakpoint_count
;
10005 b
->disposition
= disp_donttouch
;
10006 b
->location
= std::move (start_location
);
10007 b
->location_range_end
= std::move (end_location
);
10008 b
->loc
->length
= length
;
10011 gdb::observers::breakpoint_created
.notify (b
);
10012 update_global_location_list (UGLL_MAY_INSERT
);
10015 /* Return non-zero if EXP is verified as constant. Returned zero
10016 means EXP is variable. Also the constant detection may fail for
10017 some constant expressions and in such case still falsely return
10021 watchpoint_exp_is_const (const struct expression
*exp
)
10023 int i
= exp
->nelts
;
10029 /* We are only interested in the descriptor of each element. */
10030 operator_length (exp
, i
, &oplenp
, &argsp
);
10033 switch (exp
->elts
[i
].opcode
)
10043 case BINOP_LOGICAL_AND
:
10044 case BINOP_LOGICAL_OR
:
10045 case BINOP_BITWISE_AND
:
10046 case BINOP_BITWISE_IOR
:
10047 case BINOP_BITWISE_XOR
:
10049 case BINOP_NOTEQUAL
:
10075 case OP_OBJC_NSSTRING
:
10078 case UNOP_LOGICAL_NOT
:
10079 case UNOP_COMPLEMENT
:
10084 case UNOP_CAST_TYPE
:
10085 case UNOP_REINTERPRET_CAST
:
10086 case UNOP_DYNAMIC_CAST
:
10087 /* Unary, binary and ternary operators: We have to check
10088 their operands. If they are constant, then so is the
10089 result of that operation. For instance, if A and B are
10090 determined to be constants, then so is "A + B".
10092 UNOP_IND is one exception to the rule above, because the
10093 value of *ADDR is not necessarily a constant, even when
10098 /* Check whether the associated symbol is a constant.
10100 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10101 possible that a buggy compiler could mark a variable as
10102 constant even when it is not, and TYPE_CONST would return
10103 true in this case, while SYMBOL_CLASS wouldn't.
10105 We also have to check for function symbols because they
10106 are always constant. */
10108 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10110 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10111 && SYMBOL_CLASS (s
) != LOC_CONST
10112 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10117 /* The default action is to return 0 because we are using
10118 the optimistic approach here: If we don't know something,
10119 then it is not a constant. */
10128 /* Watchpoint destructor. */
10130 watchpoint::~watchpoint ()
10132 xfree (this->exp_string
);
10133 xfree (this->exp_string_reparse
);
10136 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10139 re_set_watchpoint (struct breakpoint
*b
)
10141 struct watchpoint
*w
= (struct watchpoint
*) b
;
10143 /* Watchpoint can be either on expression using entirely global
10144 variables, or it can be on local variables.
10146 Watchpoints of the first kind are never auto-deleted, and even
10147 persist across program restarts. Since they can use variables
10148 from shared libraries, we need to reparse expression as libraries
10149 are loaded and unloaded.
10151 Watchpoints on local variables can also change meaning as result
10152 of solib event. For example, if a watchpoint uses both a local
10153 and a global variables in expression, it's a local watchpoint,
10154 but unloading of a shared library will make the expression
10155 invalid. This is not a very common use case, but we still
10156 re-evaluate expression, to avoid surprises to the user.
10158 Note that for local watchpoints, we re-evaluate it only if
10159 watchpoints frame id is still valid. If it's not, it means the
10160 watchpoint is out of scope and will be deleted soon. In fact,
10161 I'm not sure we'll ever be called in this case.
10163 If a local watchpoint's frame id is still valid, then
10164 w->exp_valid_block is likewise valid, and we can safely use it.
10166 Don't do anything about disabled watchpoints, since they will be
10167 reevaluated again when enabled. */
10168 update_watchpoint (w
, 1 /* reparse */);
10171 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10174 insert_watchpoint (struct bp_location
*bl
)
10176 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10177 int length
= w
->exact
? 1 : bl
->length
;
10179 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10180 w
->cond_exp
.get ());
10183 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10186 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10188 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10189 int length
= w
->exact
? 1 : bl
->length
;
10191 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10192 w
->cond_exp
.get ());
10196 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10197 const address_space
*aspace
, CORE_ADDR bp_addr
,
10198 const struct target_waitstatus
*ws
)
10200 struct breakpoint
*b
= bl
->owner
;
10201 struct watchpoint
*w
= (struct watchpoint
*) b
;
10203 /* Continuable hardware watchpoints are treated as non-existent if the
10204 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10205 some data address). Otherwise gdb won't stop on a break instruction
10206 in the code (not from a breakpoint) when a hardware watchpoint has
10207 been defined. Also skip watchpoints which we know did not trigger
10208 (did not match the data address). */
10209 if (is_hardware_watchpoint (b
)
10210 && w
->watchpoint_triggered
== watch_triggered_no
)
10217 check_status_watchpoint (bpstat bs
)
10219 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10221 bpstat_check_watchpoint (bs
);
10224 /* Implement the "resources_needed" breakpoint_ops method for
10225 hardware watchpoints. */
10228 resources_needed_watchpoint (const struct bp_location
*bl
)
10230 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10231 int length
= w
->exact
? 1 : bl
->length
;
10233 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10236 /* Implement the "works_in_software_mode" breakpoint_ops method for
10237 hardware watchpoints. */
10240 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10242 /* Read and access watchpoints only work with hardware support. */
10243 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10246 static enum print_stop_action
10247 print_it_watchpoint (bpstat bs
)
10249 struct breakpoint
*b
;
10250 enum print_stop_action result
;
10251 struct watchpoint
*w
;
10252 struct ui_out
*uiout
= current_uiout
;
10254 gdb_assert (bs
->bp_location_at
!= NULL
);
10256 b
= bs
->breakpoint_at
;
10257 w
= (struct watchpoint
*) b
;
10259 annotate_watchpoint (b
->number
);
10260 maybe_print_thread_hit_breakpoint (uiout
);
10264 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10267 case bp_watchpoint
:
10268 case bp_hardware_watchpoint
:
10269 if (uiout
->is_mi_like_p ())
10270 uiout
->field_string
10271 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10273 tuple_emitter
.emplace (uiout
, "value");
10274 uiout
->text ("\nOld value = ");
10275 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10276 uiout
->field_stream ("old", stb
);
10277 uiout
->text ("\nNew value = ");
10278 watchpoint_value_print (w
->val
.get (), &stb
);
10279 uiout
->field_stream ("new", stb
);
10280 uiout
->text ("\n");
10281 /* More than one watchpoint may have been triggered. */
10282 result
= PRINT_UNKNOWN
;
10285 case bp_read_watchpoint
:
10286 if (uiout
->is_mi_like_p ())
10287 uiout
->field_string
10288 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10290 tuple_emitter
.emplace (uiout
, "value");
10291 uiout
->text ("\nValue = ");
10292 watchpoint_value_print (w
->val
.get (), &stb
);
10293 uiout
->field_stream ("value", stb
);
10294 uiout
->text ("\n");
10295 result
= PRINT_UNKNOWN
;
10298 case bp_access_watchpoint
:
10299 if (bs
->old_val
!= NULL
)
10301 if (uiout
->is_mi_like_p ())
10302 uiout
->field_string
10304 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10306 tuple_emitter
.emplace (uiout
, "value");
10307 uiout
->text ("\nOld value = ");
10308 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10309 uiout
->field_stream ("old", stb
);
10310 uiout
->text ("\nNew value = ");
10315 if (uiout
->is_mi_like_p ())
10316 uiout
->field_string
10318 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10319 tuple_emitter
.emplace (uiout
, "value");
10320 uiout
->text ("\nValue = ");
10322 watchpoint_value_print (w
->val
.get (), &stb
);
10323 uiout
->field_stream ("new", stb
);
10324 uiout
->text ("\n");
10325 result
= PRINT_UNKNOWN
;
10328 result
= PRINT_UNKNOWN
;
10334 /* Implement the "print_mention" breakpoint_ops method for hardware
10338 print_mention_watchpoint (struct breakpoint
*b
)
10340 struct watchpoint
*w
= (struct watchpoint
*) b
;
10341 struct ui_out
*uiout
= current_uiout
;
10342 const char *tuple_name
;
10346 case bp_watchpoint
:
10347 uiout
->text ("Watchpoint ");
10348 tuple_name
= "wpt";
10350 case bp_hardware_watchpoint
:
10351 uiout
->text ("Hardware watchpoint ");
10352 tuple_name
= "wpt";
10354 case bp_read_watchpoint
:
10355 uiout
->text ("Hardware read watchpoint ");
10356 tuple_name
= "hw-rwpt";
10358 case bp_access_watchpoint
:
10359 uiout
->text ("Hardware access (read/write) watchpoint ");
10360 tuple_name
= "hw-awpt";
10363 internal_error (__FILE__
, __LINE__
,
10364 _("Invalid hardware watchpoint type."));
10367 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10368 uiout
->field_signed ("number", b
->number
);
10369 uiout
->text (": ");
10370 uiout
->field_string ("exp", w
->exp_string
);
10373 /* Implement the "print_recreate" breakpoint_ops method for
10377 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10379 struct watchpoint
*w
= (struct watchpoint
*) b
;
10383 case bp_watchpoint
:
10384 case bp_hardware_watchpoint
:
10385 fprintf_unfiltered (fp
, "watch");
10387 case bp_read_watchpoint
:
10388 fprintf_unfiltered (fp
, "rwatch");
10390 case bp_access_watchpoint
:
10391 fprintf_unfiltered (fp
, "awatch");
10394 internal_error (__FILE__
, __LINE__
,
10395 _("Invalid watchpoint type."));
10398 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10399 print_recreate_thread (b
, fp
);
10402 /* Implement the "explains_signal" breakpoint_ops method for
10406 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10408 /* A software watchpoint cannot cause a signal other than
10409 GDB_SIGNAL_TRAP. */
10410 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10416 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10418 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10420 /* Implement the "insert" breakpoint_ops method for
10421 masked hardware watchpoints. */
10424 insert_masked_watchpoint (struct bp_location
*bl
)
10426 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10428 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10429 bl
->watchpoint_type
);
10432 /* Implement the "remove" breakpoint_ops method for
10433 masked hardware watchpoints. */
10436 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10438 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10440 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10441 bl
->watchpoint_type
);
10444 /* Implement the "resources_needed" breakpoint_ops method for
10445 masked hardware watchpoints. */
10448 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10450 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10452 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10455 /* Implement the "works_in_software_mode" breakpoint_ops method for
10456 masked hardware watchpoints. */
10459 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10464 /* Implement the "print_it" breakpoint_ops method for
10465 masked hardware watchpoints. */
10467 static enum print_stop_action
10468 print_it_masked_watchpoint (bpstat bs
)
10470 struct breakpoint
*b
= bs
->breakpoint_at
;
10471 struct ui_out
*uiout
= current_uiout
;
10473 /* Masked watchpoints have only one location. */
10474 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10476 annotate_watchpoint (b
->number
);
10477 maybe_print_thread_hit_breakpoint (uiout
);
10481 case bp_hardware_watchpoint
:
10482 if (uiout
->is_mi_like_p ())
10483 uiout
->field_string
10484 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10487 case bp_read_watchpoint
:
10488 if (uiout
->is_mi_like_p ())
10489 uiout
->field_string
10490 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10493 case bp_access_watchpoint
:
10494 if (uiout
->is_mi_like_p ())
10495 uiout
->field_string
10497 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10500 internal_error (__FILE__
, __LINE__
,
10501 _("Invalid hardware watchpoint type."));
10505 uiout
->text (_("\n\
10506 Check the underlying instruction at PC for the memory\n\
10507 address and value which triggered this watchpoint.\n"));
10508 uiout
->text ("\n");
10510 /* More than one watchpoint may have been triggered. */
10511 return PRINT_UNKNOWN
;
10514 /* Implement the "print_one_detail" breakpoint_ops method for
10515 masked hardware watchpoints. */
10518 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10519 struct ui_out
*uiout
)
10521 struct watchpoint
*w
= (struct watchpoint
*) b
;
10523 /* Masked watchpoints have only one location. */
10524 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10526 uiout
->text ("\tmask ");
10527 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10528 uiout
->text ("\n");
10531 /* Implement the "print_mention" breakpoint_ops method for
10532 masked hardware watchpoints. */
10535 print_mention_masked_watchpoint (struct breakpoint
*b
)
10537 struct watchpoint
*w
= (struct watchpoint
*) b
;
10538 struct ui_out
*uiout
= current_uiout
;
10539 const char *tuple_name
;
10543 case bp_hardware_watchpoint
:
10544 uiout
->text ("Masked hardware watchpoint ");
10545 tuple_name
= "wpt";
10547 case bp_read_watchpoint
:
10548 uiout
->text ("Masked hardware read watchpoint ");
10549 tuple_name
= "hw-rwpt";
10551 case bp_access_watchpoint
:
10552 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10553 tuple_name
= "hw-awpt";
10556 internal_error (__FILE__
, __LINE__
,
10557 _("Invalid hardware watchpoint type."));
10560 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10561 uiout
->field_signed ("number", b
->number
);
10562 uiout
->text (": ");
10563 uiout
->field_string ("exp", w
->exp_string
);
10566 /* Implement the "print_recreate" breakpoint_ops method for
10567 masked hardware watchpoints. */
10570 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10572 struct watchpoint
*w
= (struct watchpoint
*) b
;
10576 case bp_hardware_watchpoint
:
10577 fprintf_unfiltered (fp
, "watch");
10579 case bp_read_watchpoint
:
10580 fprintf_unfiltered (fp
, "rwatch");
10582 case bp_access_watchpoint
:
10583 fprintf_unfiltered (fp
, "awatch");
10586 internal_error (__FILE__
, __LINE__
,
10587 _("Invalid hardware watchpoint type."));
10590 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
,
10591 phex (w
->hw_wp_mask
, sizeof (CORE_ADDR
)));
10592 print_recreate_thread (b
, fp
);
10595 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10597 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10599 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10602 is_masked_watchpoint (const struct breakpoint
*b
)
10604 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10607 /* accessflag: hw_write: watch write,
10608 hw_read: watch read,
10609 hw_access: watch access (read or write) */
10611 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10612 int just_location
, int internal
)
10614 struct breakpoint
*scope_breakpoint
= NULL
;
10615 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10616 struct value
*result
;
10617 int saved_bitpos
= 0, saved_bitsize
= 0;
10618 const char *exp_start
= NULL
;
10619 const char *exp_end
= NULL
;
10620 const char *tok
, *end_tok
;
10622 const char *cond_start
= NULL
;
10623 const char *cond_end
= NULL
;
10624 enum bptype bp_type
;
10627 /* Flag to indicate whether we are going to use masks for
10628 the hardware watchpoint. */
10630 CORE_ADDR mask
= 0;
10632 /* Make sure that we actually have parameters to parse. */
10633 if (arg
!= NULL
&& arg
[0] != '\0')
10635 const char *value_start
;
10637 exp_end
= arg
+ strlen (arg
);
10639 /* Look for "parameter value" pairs at the end
10640 of the arguments string. */
10641 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10643 /* Skip whitespace at the end of the argument list. */
10644 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10647 /* Find the beginning of the last token.
10648 This is the value of the parameter. */
10649 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10651 value_start
= tok
+ 1;
10653 /* Skip whitespace. */
10654 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10659 /* Find the beginning of the second to last token.
10660 This is the parameter itself. */
10661 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10664 toklen
= end_tok
- tok
+ 1;
10666 if (toklen
== 6 && startswith (tok
, "thread"))
10668 struct thread_info
*thr
;
10669 /* At this point we've found a "thread" token, which means
10670 the user is trying to set a watchpoint that triggers
10671 only in a specific thread. */
10675 error(_("You can specify only one thread."));
10677 /* Extract the thread ID from the next token. */
10678 thr
= parse_thread_id (value_start
, &endp
);
10680 /* Check if the user provided a valid thread ID. */
10681 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10682 invalid_thread_id_error (value_start
);
10684 thread
= thr
->global_num
;
10686 else if (toklen
== 4 && startswith (tok
, "mask"))
10688 /* We've found a "mask" token, which means the user wants to
10689 create a hardware watchpoint that is going to have the mask
10691 struct value
*mask_value
, *mark
;
10694 error(_("You can specify only one mask."));
10696 use_mask
= just_location
= 1;
10698 mark
= value_mark ();
10699 mask_value
= parse_to_comma_and_eval (&value_start
);
10700 mask
= value_as_address (mask_value
);
10701 value_free_to_mark (mark
);
10704 /* We didn't recognize what we found. We should stop here. */
10707 /* Truncate the string and get rid of the "parameter value" pair before
10708 the arguments string is parsed by the parse_exp_1 function. */
10715 /* Parse the rest of the arguments. From here on out, everything
10716 is in terms of a newly allocated string instead of the original
10718 std::string
expression (arg
, exp_end
- arg
);
10719 exp_start
= arg
= expression
.c_str ();
10720 innermost_block_tracker tracker
;
10721 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10723 /* Remove trailing whitespace from the expression before saving it.
10724 This makes the eventual display of the expression string a bit
10726 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10729 /* Checking if the expression is not constant. */
10730 if (watchpoint_exp_is_const (exp
.get ()))
10734 len
= exp_end
- exp_start
;
10735 while (len
> 0 && isspace (exp_start
[len
- 1]))
10737 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10740 exp_valid_block
= tracker
.block ();
10741 struct value
*mark
= value_mark ();
10742 struct value
*val_as_value
= nullptr;
10743 fetch_subexp_value (exp
.get (), &pc
, &val_as_value
, &result
, NULL
,
10746 if (val_as_value
!= NULL
&& just_location
)
10748 saved_bitpos
= value_bitpos (val_as_value
);
10749 saved_bitsize
= value_bitsize (val_as_value
);
10757 exp_valid_block
= NULL
;
10758 val
= release_value (value_addr (result
));
10759 value_free_to_mark (mark
);
10763 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10766 error (_("This target does not support masked watchpoints."));
10767 else if (ret
== -2)
10768 error (_("Invalid mask or memory region."));
10771 else if (val_as_value
!= NULL
)
10772 val
= release_value (val_as_value
);
10774 tok
= skip_spaces (arg
);
10775 end_tok
= skip_to_space (tok
);
10777 toklen
= end_tok
- tok
;
10778 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10780 tok
= cond_start
= end_tok
+ 1;
10781 innermost_block_tracker if_tracker
;
10782 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10784 /* The watchpoint expression may not be local, but the condition
10785 may still be. E.g.: `watch global if local > 0'. */
10786 cond_exp_valid_block
= if_tracker
.block ();
10791 error (_("Junk at end of command."));
10793 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10795 /* Save this because create_internal_breakpoint below invalidates
10797 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10799 /* If the expression is "local", then set up a "watchpoint scope"
10800 breakpoint at the point where we've left the scope of the watchpoint
10801 expression. Create the scope breakpoint before the watchpoint, so
10802 that we will encounter it first in bpstat_stop_status. */
10803 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10805 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10807 if (frame_id_p (caller_frame_id
))
10809 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10810 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10813 = create_internal_breakpoint (caller_arch
, caller_pc
,
10814 bp_watchpoint_scope
,
10815 &momentary_breakpoint_ops
);
10817 /* create_internal_breakpoint could invalidate WP_FRAME. */
10820 scope_breakpoint
->enable_state
= bp_enabled
;
10822 /* Automatically delete the breakpoint when it hits. */
10823 scope_breakpoint
->disposition
= disp_del
;
10825 /* Only break in the proper frame (help with recursion). */
10826 scope_breakpoint
->frame_id
= caller_frame_id
;
10828 /* Set the address at which we will stop. */
10829 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10830 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10831 scope_breakpoint
->loc
->address
10832 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10833 scope_breakpoint
->loc
->requested_address
,
10834 scope_breakpoint
->type
);
10838 /* Now set up the breakpoint. We create all watchpoints as hardware
10839 watchpoints here even if hardware watchpoints are turned off, a call
10840 to update_watchpoint later in this function will cause the type to
10841 drop back to bp_watchpoint (software watchpoint) if required. */
10843 if (accessflag
== hw_read
)
10844 bp_type
= bp_read_watchpoint
;
10845 else if (accessflag
== hw_access
)
10846 bp_type
= bp_access_watchpoint
;
10848 bp_type
= bp_hardware_watchpoint
;
10850 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10853 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10854 &masked_watchpoint_breakpoint_ops
);
10856 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10857 &watchpoint_breakpoint_ops
);
10858 w
->thread
= thread
;
10859 w
->disposition
= disp_donttouch
;
10860 w
->pspace
= current_program_space
;
10861 w
->exp
= std::move (exp
);
10862 w
->exp_valid_block
= exp_valid_block
;
10863 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10866 struct type
*t
= value_type (val
.get ());
10867 CORE_ADDR addr
= value_as_address (val
.get ());
10869 w
->exp_string_reparse
10870 = current_language
->watch_location_expression (t
, addr
).release ();
10872 w
->exp_string
= xstrprintf ("-location %.*s",
10873 (int) (exp_end
- exp_start
), exp_start
);
10876 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10880 w
->hw_wp_mask
= mask
;
10885 w
->val_bitpos
= saved_bitpos
;
10886 w
->val_bitsize
= saved_bitsize
;
10887 w
->val_valid
= true;
10891 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10893 w
->cond_string
= 0;
10895 if (frame_id_p (watchpoint_frame
))
10897 w
->watchpoint_frame
= watchpoint_frame
;
10898 w
->watchpoint_thread
= inferior_ptid
;
10902 w
->watchpoint_frame
= null_frame_id
;
10903 w
->watchpoint_thread
= null_ptid
;
10906 if (scope_breakpoint
!= NULL
)
10908 /* The scope breakpoint is related to the watchpoint. We will
10909 need to act on them together. */
10910 w
->related_breakpoint
= scope_breakpoint
;
10911 scope_breakpoint
->related_breakpoint
= w
.get ();
10914 if (!just_location
)
10915 value_free_to_mark (mark
);
10917 /* Finally update the new watchpoint. This creates the locations
10918 that should be inserted. */
10919 update_watchpoint (w
.get (), 1);
10921 install_breakpoint (internal
, std::move (w
), 1);
10924 /* Return count of debug registers needed to watch the given expression.
10925 If the watchpoint cannot be handled in hardware return zero. */
10928 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10930 int found_memory_cnt
= 0;
10932 /* Did the user specifically forbid us to use hardware watchpoints? */
10933 if (!can_use_hw_watchpoints
)
10936 gdb_assert (!vals
.empty ());
10937 struct value
*head
= vals
[0].get ();
10939 /* Make sure that the value of the expression depends only upon
10940 memory contents, and values computed from them within GDB. If we
10941 find any register references or function calls, we can't use a
10942 hardware watchpoint.
10944 The idea here is that evaluating an expression generates a series
10945 of values, one holding the value of every subexpression. (The
10946 expression a*b+c has five subexpressions: a, b, a*b, c, and
10947 a*b+c.) GDB's values hold almost enough information to establish
10948 the criteria given above --- they identify memory lvalues,
10949 register lvalues, computed values, etcetera. So we can evaluate
10950 the expression, and then scan the chain of values that leaves
10951 behind to decide whether we can detect any possible change to the
10952 expression's final value using only hardware watchpoints.
10954 However, I don't think that the values returned by inferior
10955 function calls are special in any way. So this function may not
10956 notice that an expression involving an inferior function call
10957 can't be watched with hardware watchpoints. FIXME. */
10958 for (const value_ref_ptr
&iter
: vals
)
10960 struct value
*v
= iter
.get ();
10962 if (VALUE_LVAL (v
) == lval_memory
)
10964 if (v
!= head
&& value_lazy (v
))
10965 /* A lazy memory lvalue in the chain is one that GDB never
10966 needed to fetch; we either just used its address (e.g.,
10967 `a' in `a.b') or we never needed it at all (e.g., `a'
10968 in `a,b'). This doesn't apply to HEAD; if that is
10969 lazy then it was not readable, but watch it anyway. */
10973 /* Ahh, memory we actually used! Check if we can cover
10974 it with hardware watchpoints. */
10975 struct type
*vtype
= check_typedef (value_type (v
));
10977 /* We only watch structs and arrays if user asked for it
10978 explicitly, never if they just happen to appear in a
10979 middle of some value chain. */
10981 || (vtype
->code () != TYPE_CODE_STRUCT
10982 && vtype
->code () != TYPE_CODE_ARRAY
))
10984 CORE_ADDR vaddr
= value_address (v
);
10988 len
= (target_exact_watchpoints
10989 && is_scalar_type_recursive (vtype
))?
10990 1 : TYPE_LENGTH (value_type (v
));
10992 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10996 found_memory_cnt
+= num_regs
;
11000 else if (VALUE_LVAL (v
) != not_lval
11001 && deprecated_value_modifiable (v
) == 0)
11002 return 0; /* These are values from the history (e.g., $1). */
11003 else if (VALUE_LVAL (v
) == lval_register
)
11004 return 0; /* Cannot watch a register with a HW watchpoint. */
11007 /* The expression itself looks suitable for using a hardware
11008 watchpoint, but give the target machine a chance to reject it. */
11009 return found_memory_cnt
;
11013 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11015 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11018 /* A helper function that looks for the "-location" argument and then
11019 calls watch_command_1. */
11022 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
11024 int just_location
= 0;
11027 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11028 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11031 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11035 watch_command (const char *arg
, int from_tty
)
11037 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11041 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11043 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11047 rwatch_command (const char *arg
, int from_tty
)
11049 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11053 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11055 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11059 awatch_command (const char *arg
, int from_tty
)
11061 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11065 /* Data for the FSM that manages the until(location)/advance commands
11066 in infcmd.c. Here because it uses the mechanisms of
11069 struct until_break_fsm
: public thread_fsm
11071 /* The thread that was current when the command was executed. */
11074 /* The breakpoint set at the return address in the caller frame,
11075 plus breakpoints at all the destination locations. */
11076 std::vector
<breakpoint_up
> breakpoints
;
11078 until_break_fsm (struct interp
*cmd_interp
, int thread
,
11079 std::vector
<breakpoint_up
> &&breakpoints
)
11080 : thread_fsm (cmd_interp
),
11082 breakpoints (std::move (breakpoints
))
11086 void clean_up (struct thread_info
*thread
) override
;
11087 bool should_stop (struct thread_info
*thread
) override
;
11088 enum async_reply_reason
do_async_reply_reason () override
;
11091 /* Implementation of the 'should_stop' FSM method for the
11092 until(location)/advance commands. */
11095 until_break_fsm::should_stop (struct thread_info
*tp
)
11097 for (const breakpoint_up
&bp
: breakpoints
)
11098 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11099 bp
.get ()) != NULL
)
11108 /* Implementation of the 'clean_up' FSM method for the
11109 until(location)/advance commands. */
11112 until_break_fsm::clean_up (struct thread_info
*)
11114 /* Clean up our temporary breakpoints. */
11115 breakpoints
.clear ();
11116 delete_longjmp_breakpoint (thread
);
11119 /* Implementation of the 'async_reply_reason' FSM method for the
11120 until(location)/advance commands. */
11122 enum async_reply_reason
11123 until_break_fsm::do_async_reply_reason ()
11125 return EXEC_ASYNC_LOCATION_REACHED
;
11129 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11131 struct frame_info
*frame
;
11132 struct gdbarch
*frame_gdbarch
;
11133 struct frame_id stack_frame_id
;
11134 struct frame_id caller_frame_id
;
11136 struct thread_info
*tp
;
11138 clear_proceed_status (0);
11140 /* Set a breakpoint where the user wants it and at return from
11143 event_location_up location
= string_to_event_location (&arg
, current_language
);
11145 std::vector
<symtab_and_line
> sals
11146 = (last_displayed_sal_is_valid ()
11147 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11148 get_last_displayed_symtab (),
11149 get_last_displayed_line ())
11150 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11154 error (_("Couldn't get information on specified line."));
11157 error (_("Junk at end of arguments."));
11159 tp
= inferior_thread ();
11160 thread
= tp
->global_num
;
11162 /* Note linespec handling above invalidates the frame chain.
11163 Installing a breakpoint also invalidates the frame chain (as it
11164 may need to switch threads), so do any frame handling before
11167 frame
= get_selected_frame (NULL
);
11168 frame_gdbarch
= get_frame_arch (frame
);
11169 stack_frame_id
= get_stack_frame_id (frame
);
11170 caller_frame_id
= frame_unwind_caller_id (frame
);
11172 /* Keep within the current frame, or in frames called by the current
11175 std::vector
<breakpoint_up
> breakpoints
;
11177 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11179 if (frame_id_p (caller_frame_id
))
11181 struct symtab_and_line sal2
;
11182 struct gdbarch
*caller_gdbarch
;
11184 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11185 sal2
.pc
= frame_unwind_caller_pc (frame
);
11186 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11188 breakpoint_up caller_breakpoint
11189 = set_momentary_breakpoint (caller_gdbarch
, sal2
,
11190 caller_frame_id
, bp_until
);
11191 breakpoints
.emplace_back (std::move (caller_breakpoint
));
11193 set_longjmp_breakpoint (tp
, caller_frame_id
);
11194 lj_deleter
.emplace (thread
);
11197 /* set_momentary_breakpoint could invalidate FRAME. */
11200 /* If the user told us to continue until a specified location, we
11201 don't specify a frame at which we need to stop. Otherwise,
11202 specify the selected frame, because we want to stop only at the
11203 very same frame. */
11204 frame_id stop_frame_id
= anywhere
? null_frame_id
: stack_frame_id
;
11206 for (symtab_and_line
&sal
: sals
)
11208 resolve_sal_pc (&sal
);
11210 breakpoint_up location_breakpoint
11211 = set_momentary_breakpoint (frame_gdbarch
, sal
,
11212 stop_frame_id
, bp_until
);
11213 breakpoints
.emplace_back (std::move (location_breakpoint
));
11216 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11217 std::move (breakpoints
));
11220 lj_deleter
->release ();
11222 proceed (-1, GDB_SIGNAL_DEFAULT
);
11225 /* This function attempts to parse an optional "if <cond>" clause
11226 from the arg string. If one is not found, it returns NULL.
11228 Else, it returns a pointer to the condition string. (It does not
11229 attempt to evaluate the string against a particular block.) And,
11230 it updates arg to point to the first character following the parsed
11231 if clause in the arg string. */
11234 ep_parse_optional_if_clause (const char **arg
)
11236 const char *cond_string
;
11238 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11241 /* Skip the "if" keyword. */
11244 /* Skip any extra leading whitespace, and record the start of the
11245 condition string. */
11246 *arg
= skip_spaces (*arg
);
11247 cond_string
= *arg
;
11249 /* Assume that the condition occupies the remainder of the arg
11251 (*arg
) += strlen (cond_string
);
11253 return cond_string
;
11256 /* Commands to deal with catching events, such as signals, exceptions,
11257 process start/exit, etc. */
11261 catch_fork_temporary
, catch_vfork_temporary
,
11262 catch_fork_permanent
, catch_vfork_permanent
11267 catch_fork_command_1 (const char *arg
, int from_tty
,
11268 struct cmd_list_element
*command
)
11270 struct gdbarch
*gdbarch
= get_current_arch ();
11271 const char *cond_string
= NULL
;
11272 catch_fork_kind fork_kind
;
11274 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11275 bool temp
= (fork_kind
== catch_fork_temporary
11276 || fork_kind
== catch_vfork_temporary
);
11280 arg
= skip_spaces (arg
);
11282 /* The allowed syntax is:
11284 catch [v]fork if <cond>
11286 First, check if there's an if clause. */
11287 cond_string
= ep_parse_optional_if_clause (&arg
);
11289 if ((*arg
!= '\0') && !isspace (*arg
))
11290 error (_("Junk at end of arguments."));
11292 /* If this target supports it, create a fork or vfork catchpoint
11293 and enable reporting of such events. */
11296 case catch_fork_temporary
:
11297 case catch_fork_permanent
:
11298 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11299 &catch_fork_breakpoint_ops
);
11301 case catch_vfork_temporary
:
11302 case catch_vfork_permanent
:
11303 create_fork_vfork_event_catchpoint (gdbarch
, temp
, cond_string
,
11304 &catch_vfork_breakpoint_ops
);
11307 error (_("unsupported or unknown fork kind; cannot catch it"));
11313 catch_exec_command_1 (const char *arg
, int from_tty
,
11314 struct cmd_list_element
*command
)
11316 struct gdbarch
*gdbarch
= get_current_arch ();
11317 const char *cond_string
= NULL
;
11318 bool temp
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11322 arg
= skip_spaces (arg
);
11324 /* The allowed syntax is:
11326 catch exec if <cond>
11328 First, check if there's an if clause. */
11329 cond_string
= ep_parse_optional_if_clause (&arg
);
11331 if ((*arg
!= '\0') && !isspace (*arg
))
11332 error (_("Junk at end of arguments."));
11334 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11335 init_catchpoint (c
.get (), gdbarch
, temp
, cond_string
,
11336 &catch_exec_breakpoint_ops
);
11337 c
->exec_pathname
= NULL
;
11339 install_breakpoint (0, std::move (c
), 1);
11343 init_ada_exception_breakpoint (struct breakpoint
*b
,
11344 struct gdbarch
*gdbarch
,
11345 struct symtab_and_line sal
,
11346 const char *addr_string
,
11347 const struct breakpoint_ops
*ops
,
11354 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11356 loc_gdbarch
= gdbarch
;
11358 describe_other_breakpoints (loc_gdbarch
,
11359 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11360 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11361 version for exception catchpoints, because two catchpoints
11362 used for different exception names will use the same address.
11363 In this case, a "breakpoint ... also set at..." warning is
11364 unproductive. Besides, the warning phrasing is also a bit
11365 inappropriate, we should use the word catchpoint, and tell
11366 the user what type of catchpoint it is. The above is good
11367 enough for now, though. */
11370 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11372 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11373 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11374 b
->location
= string_to_event_location (&addr_string
,
11375 language_def (language_ada
));
11376 b
->language
= language_ada
;
11381 /* Compare two breakpoints and return a strcmp-like result. */
11384 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11386 uintptr_t ua
= (uintptr_t) a
;
11387 uintptr_t ub
= (uintptr_t) b
;
11389 if (a
->number
< b
->number
)
11391 else if (a
->number
> b
->number
)
11394 /* Now sort by address, in case we see, e..g, two breakpoints with
11398 return ua
> ub
? 1 : 0;
11401 /* Delete breakpoints by address or line. */
11404 clear_command (const char *arg
, int from_tty
)
11406 struct breakpoint
*b
;
11409 std::vector
<symtab_and_line
> decoded_sals
;
11410 symtab_and_line last_sal
;
11411 gdb::array_view
<symtab_and_line
> sals
;
11415 = decode_line_with_current_source (arg
,
11416 (DECODE_LINE_FUNFIRSTLINE
11417 | DECODE_LINE_LIST_MODE
));
11419 sals
= decoded_sals
;
11423 /* Set sal's line, symtab, pc, and pspace to the values
11424 corresponding to the last call to print_frame_info. If the
11425 codepoint is not valid, this will set all the fields to 0. */
11426 last_sal
= get_last_displayed_sal ();
11427 if (last_sal
.symtab
== 0)
11428 error (_("No source file specified."));
11434 /* We don't call resolve_sal_pc here. That's not as bad as it
11435 seems, because all existing breakpoints typically have both
11436 file/line and pc set. So, if clear is given file/line, we can
11437 match this to existing breakpoint without obtaining pc at all.
11439 We only support clearing given the address explicitly
11440 present in breakpoint table. Say, we've set breakpoint
11441 at file:line. There were several PC values for that file:line,
11442 due to optimization, all in one block.
11444 We've picked one PC value. If "clear" is issued with another
11445 PC corresponding to the same file:line, the breakpoint won't
11446 be cleared. We probably can still clear the breakpoint, but
11447 since the other PC value is never presented to user, user
11448 can only find it by guessing, and it does not seem important
11449 to support that. */
11451 /* For each line spec given, delete bps which correspond to it. Do
11452 it in two passes, solely to preserve the current behavior that
11453 from_tty is forced true if we delete more than one
11456 std::vector
<struct breakpoint
*> found
;
11457 for (const auto &sal
: sals
)
11459 const char *sal_fullname
;
11461 /* If exact pc given, clear bpts at that pc.
11462 If line given (pc == 0), clear all bpts on specified line.
11463 If defaulting, clear all bpts on default line
11466 defaulting sal.pc != 0 tests to do
11471 1 0 <can't happen> */
11473 sal_fullname
= (sal
.symtab
== NULL
11474 ? NULL
: symtab_to_fullname (sal
.symtab
));
11476 /* Find all matching breakpoints and add them to 'found'. */
11477 ALL_BREAKPOINTS (b
)
11480 /* Are we going to delete b? */
11481 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11483 struct bp_location
*loc
= b
->loc
;
11484 for (; loc
; loc
= loc
->next
)
11486 /* If the user specified file:line, don't allow a PC
11487 match. This matches historical gdb behavior. */
11488 int pc_match
= (!sal
.explicit_line
11490 && (loc
->pspace
== sal
.pspace
)
11491 && (loc
->address
== sal
.pc
)
11492 && (!section_is_overlay (loc
->section
)
11493 || loc
->section
== sal
.section
));
11494 int line_match
= 0;
11496 if ((default_match
|| sal
.explicit_line
)
11497 && loc
->symtab
!= NULL
11498 && sal_fullname
!= NULL
11499 && sal
.pspace
== loc
->pspace
11500 && loc
->line_number
== sal
.line
11501 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11502 sal_fullname
) == 0)
11505 if (pc_match
|| line_match
)
11514 found
.push_back (b
);
11518 /* Now go thru the 'found' chain and delete them. */
11519 if (found
.empty ())
11522 error (_("No breakpoint at %s."), arg
);
11524 error (_("No breakpoint at this line."));
11527 /* Remove duplicates from the vec. */
11528 std::sort (found
.begin (), found
.end (),
11529 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11531 return compare_breakpoints (bp_a
, bp_b
) < 0;
11533 found
.erase (std::unique (found
.begin (), found
.end (),
11534 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11536 return compare_breakpoints (bp_a
, bp_b
) == 0;
11540 if (found
.size () > 1)
11541 from_tty
= 1; /* Always report if deleted more than one. */
11544 if (found
.size () == 1)
11545 printf_unfiltered (_("Deleted breakpoint "));
11547 printf_unfiltered (_("Deleted breakpoints "));
11550 for (breakpoint
*iter
: found
)
11553 printf_unfiltered ("%d ", iter
->number
);
11554 delete_breakpoint (iter
);
11557 putchar_unfiltered ('\n');
11560 /* Delete breakpoint in BS if they are `delete' breakpoints and
11561 all breakpoints that are marked for deletion, whether hit or not.
11562 This is called after any breakpoint is hit, or after errors. */
11565 breakpoint_auto_delete (bpstat bs
)
11567 struct breakpoint
*b
, *b_tmp
;
11569 for (; bs
; bs
= bs
->next
)
11570 if (bs
->breakpoint_at
11571 && bs
->breakpoint_at
->disposition
== disp_del
11573 delete_breakpoint (bs
->breakpoint_at
);
11575 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11577 if (b
->disposition
== disp_del_at_next_stop
)
11578 delete_breakpoint (b
);
11582 /* A comparison function for bp_location AP and BP being interfaced to
11583 std::sort. Sort elements primarily by their ADDRESS (no matter what
11584 bl_address_is_meaningful says), secondarily by ordering first
11585 permanent elements and terciarily just ensuring the array is sorted
11586 stable way despite std::sort being an unstable algorithm. */
11589 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11591 if (a
->address
!= b
->address
)
11592 return a
->address
< b
->address
;
11594 /* Sort locations at the same address by their pspace number, keeping
11595 locations of the same inferior (in a multi-inferior environment)
11598 if (a
->pspace
->num
!= b
->pspace
->num
)
11599 return a
->pspace
->num
< b
->pspace
->num
;
11601 /* Sort permanent breakpoints first. */
11602 if (a
->permanent
!= b
->permanent
)
11603 return a
->permanent
> b
->permanent
;
11605 /* Sort by type in order to make duplicate determination easier.
11606 See update_global_location_list. This is kept in sync with
11607 breakpoint_locations_match. */
11608 if (a
->loc_type
< b
->loc_type
)
11611 /* Likewise, for range-breakpoints, sort by length. */
11612 if (a
->loc_type
== bp_loc_hardware_breakpoint
11613 && b
->loc_type
== bp_loc_hardware_breakpoint
11614 && a
->length
< b
->length
)
11617 /* Make the internal GDB representation stable across GDB runs
11618 where A and B memory inside GDB can differ. Breakpoint locations of
11619 the same type at the same address can be sorted in arbitrary order. */
11621 if (a
->owner
->number
!= b
->owner
->number
)
11622 return a
->owner
->number
< b
->owner
->number
;
11627 /* Set bp_locations_placed_address_before_address_max and
11628 bp_locations_shadow_len_after_address_max according to the current
11629 content of the bp_locations array. */
11632 bp_locations_target_extensions_update (void)
11634 struct bp_location
*bl
, **blp_tmp
;
11636 bp_locations_placed_address_before_address_max
= 0;
11637 bp_locations_shadow_len_after_address_max
= 0;
11639 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11641 CORE_ADDR start
, end
, addr
;
11643 if (!bp_location_has_shadow (bl
))
11646 start
= bl
->target_info
.placed_address
;
11647 end
= start
+ bl
->target_info
.shadow_len
;
11649 gdb_assert (bl
->address
>= start
);
11650 addr
= bl
->address
- start
;
11651 if (addr
> bp_locations_placed_address_before_address_max
)
11652 bp_locations_placed_address_before_address_max
= addr
;
11654 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11656 gdb_assert (bl
->address
< end
);
11657 addr
= end
- bl
->address
;
11658 if (addr
> bp_locations_shadow_len_after_address_max
)
11659 bp_locations_shadow_len_after_address_max
= addr
;
11663 /* Download tracepoint locations if they haven't been. */
11666 download_tracepoint_locations (void)
11668 struct breakpoint
*b
;
11669 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11671 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11673 ALL_TRACEPOINTS (b
)
11675 struct bp_location
*bl
;
11676 struct tracepoint
*t
;
11677 int bp_location_downloaded
= 0;
11679 if ((b
->type
== bp_fast_tracepoint
11680 ? !may_insert_fast_tracepoints
11681 : !may_insert_tracepoints
))
11684 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11686 if (target_can_download_tracepoint ())
11687 can_download_tracepoint
= TRIBOOL_TRUE
;
11689 can_download_tracepoint
= TRIBOOL_FALSE
;
11692 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11695 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11697 /* In tracepoint, locations are _never_ duplicated, so
11698 should_be_inserted is equivalent to
11699 unduplicated_should_be_inserted. */
11700 if (!should_be_inserted (bl
) || bl
->inserted
)
11703 switch_to_program_space_and_thread (bl
->pspace
);
11705 target_download_tracepoint (bl
);
11708 bp_location_downloaded
= 1;
11710 t
= (struct tracepoint
*) b
;
11711 t
->number_on_target
= b
->number
;
11712 if (bp_location_downloaded
)
11713 gdb::observers::breakpoint_modified
.notify (b
);
11717 /* Swap the insertion/duplication state between two locations. */
11720 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11722 const int left_inserted
= left
->inserted
;
11723 const int left_duplicate
= left
->duplicate
;
11724 const int left_needs_update
= left
->needs_update
;
11725 const struct bp_target_info left_target_info
= left
->target_info
;
11727 /* Locations of tracepoints can never be duplicated. */
11728 if (is_tracepoint (left
->owner
))
11729 gdb_assert (!left
->duplicate
);
11730 if (is_tracepoint (right
->owner
))
11731 gdb_assert (!right
->duplicate
);
11733 left
->inserted
= right
->inserted
;
11734 left
->duplicate
= right
->duplicate
;
11735 left
->needs_update
= right
->needs_update
;
11736 left
->target_info
= right
->target_info
;
11737 right
->inserted
= left_inserted
;
11738 right
->duplicate
= left_duplicate
;
11739 right
->needs_update
= left_needs_update
;
11740 right
->target_info
= left_target_info
;
11743 /* Force the re-insertion of the locations at ADDRESS. This is called
11744 once a new/deleted/modified duplicate location is found and we are evaluating
11745 conditions on the target's side. Such conditions need to be updated on
11749 force_breakpoint_reinsertion (struct bp_location
*bl
)
11751 struct bp_location
**locp
= NULL
, **loc2p
;
11752 struct bp_location
*loc
;
11753 CORE_ADDR address
= 0;
11756 address
= bl
->address
;
11757 pspace_num
= bl
->pspace
->num
;
11759 /* This is only meaningful if the target is
11760 evaluating conditions and if the user has
11761 opted for condition evaluation on the target's
11763 if (gdb_evaluates_breakpoint_condition_p ()
11764 || !target_supports_evaluation_of_breakpoint_conditions ())
11767 /* Flag all breakpoint locations with this address and
11768 the same program space as the location
11769 as "its condition has changed". We need to
11770 update the conditions on the target's side. */
11771 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11775 if (!is_breakpoint (loc
->owner
)
11776 || pspace_num
!= loc
->pspace
->num
)
11779 /* Flag the location appropriately. We use a different state to
11780 let everyone know that we already updated the set of locations
11781 with addr bl->address and program space bl->pspace. This is so
11782 we don't have to keep calling these functions just to mark locations
11783 that have already been marked. */
11784 loc
->condition_changed
= condition_updated
;
11786 /* Free the agent expression bytecode as well. We will compute
11788 loc
->cond_bytecode
.reset ();
11792 /* Called whether new breakpoints are created, or existing breakpoints
11793 deleted, to update the global location list and recompute which
11794 locations are duplicate of which.
11796 The INSERT_MODE flag determines whether locations may not, may, or
11797 shall be inserted now. See 'enum ugll_insert_mode' for more
11801 update_global_location_list (enum ugll_insert_mode insert_mode
)
11803 struct breakpoint
*b
;
11804 struct bp_location
**locp
, *loc
;
11805 /* Last breakpoint location address that was marked for update. */
11806 CORE_ADDR last_addr
= 0;
11807 /* Last breakpoint location program space that was marked for update. */
11808 int last_pspace_num
= -1;
11810 /* Used in the duplicates detection below. When iterating over all
11811 bp_locations, points to the first bp_location of a given address.
11812 Breakpoints and watchpoints of different types are never
11813 duplicates of each other. Keep one pointer for each type of
11814 breakpoint/watchpoint, so we only need to loop over all locations
11816 struct bp_location
*bp_loc_first
; /* breakpoint */
11817 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11818 struct bp_location
*awp_loc_first
; /* access watchpoint */
11819 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11821 /* Saved former bp_locations array which we compare against the newly
11822 built bp_locations from the current state of ALL_BREAKPOINTS. */
11823 struct bp_location
**old_locp
;
11824 unsigned old_locations_count
;
11825 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11827 old_locations_count
= bp_locations_count
;
11828 bp_locations
= NULL
;
11829 bp_locations_count
= 0;
11831 ALL_BREAKPOINTS (b
)
11832 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11833 bp_locations_count
++;
11835 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11836 locp
= bp_locations
;
11837 ALL_BREAKPOINTS (b
)
11838 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11841 /* See if we need to "upgrade" a software breakpoint to a hardware
11842 breakpoint. Do this before deciding whether locations are
11843 duplicates. Also do this before sorting because sorting order
11844 depends on location type. */
11845 for (locp
= bp_locations
;
11846 locp
< bp_locations
+ bp_locations_count
;
11850 if (!loc
->inserted
&& should_be_inserted (loc
))
11851 handle_automatic_hardware_breakpoints (loc
);
11854 std::sort (bp_locations
, bp_locations
+ bp_locations_count
,
11855 bp_location_is_less_than
);
11857 bp_locations_target_extensions_update ();
11859 /* Identify bp_location instances that are no longer present in the
11860 new list, and therefore should be freed. Note that it's not
11861 necessary that those locations should be removed from inferior --
11862 if there's another location at the same address (previously
11863 marked as duplicate), we don't need to remove/insert the
11866 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11867 and former bp_location array state respectively. */
11869 locp
= bp_locations
;
11870 for (old_locp
= old_locations
.get ();
11871 old_locp
< old_locations
.get () + old_locations_count
;
11874 struct bp_location
*old_loc
= *old_locp
;
11875 struct bp_location
**loc2p
;
11877 /* Tells if 'old_loc' is found among the new locations. If
11878 not, we have to free it. */
11879 int found_object
= 0;
11880 /* Tells if the location should remain inserted in the target. */
11881 int keep_in_target
= 0;
11884 /* Skip LOCP entries which will definitely never be needed.
11885 Stop either at or being the one matching OLD_LOC. */
11886 while (locp
< bp_locations
+ bp_locations_count
11887 && (*locp
)->address
< old_loc
->address
)
11891 (loc2p
< bp_locations
+ bp_locations_count
11892 && (*loc2p
)->address
== old_loc
->address
);
11895 /* Check if this is a new/duplicated location or a duplicated
11896 location that had its condition modified. If so, we want to send
11897 its condition to the target if evaluation of conditions is taking
11899 if ((*loc2p
)->condition_changed
== condition_modified
11900 && (last_addr
!= old_loc
->address
11901 || last_pspace_num
!= old_loc
->pspace
->num
))
11903 force_breakpoint_reinsertion (*loc2p
);
11904 last_pspace_num
= old_loc
->pspace
->num
;
11907 if (*loc2p
== old_loc
)
11911 /* We have already handled this address, update it so that we don't
11912 have to go through updates again. */
11913 last_addr
= old_loc
->address
;
11915 /* Target-side condition evaluation: Handle deleted locations. */
11917 force_breakpoint_reinsertion (old_loc
);
11919 /* If this location is no longer present, and inserted, look if
11920 there's maybe a new location at the same address. If so,
11921 mark that one inserted, and don't remove this one. This is
11922 needed so that we don't have a time window where a breakpoint
11923 at certain location is not inserted. */
11925 if (old_loc
->inserted
)
11927 /* If the location is inserted now, we might have to remove
11930 if (found_object
&& should_be_inserted (old_loc
))
11932 /* The location is still present in the location list,
11933 and still should be inserted. Don't do anything. */
11934 keep_in_target
= 1;
11938 /* This location still exists, but it won't be kept in the
11939 target since it may have been disabled. We proceed to
11940 remove its target-side condition. */
11942 /* The location is either no longer present, or got
11943 disabled. See if there's another location at the
11944 same address, in which case we don't need to remove
11945 this one from the target. */
11947 /* OLD_LOC comes from existing struct breakpoint. */
11948 if (bl_address_is_meaningful (old_loc
))
11951 (loc2p
< bp_locations
+ bp_locations_count
11952 && (*loc2p
)->address
== old_loc
->address
);
11955 struct bp_location
*loc2
= *loc2p
;
11957 if (loc2
== old_loc
)
11960 if (breakpoint_locations_match (loc2
, old_loc
))
11962 /* Read watchpoint locations are switched to
11963 access watchpoints, if the former are not
11964 supported, but the latter are. */
11965 if (is_hardware_watchpoint (old_loc
->owner
))
11967 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11968 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11971 /* loc2 is a duplicated location. We need to check
11972 if it should be inserted in case it will be
11974 if (unduplicated_should_be_inserted (loc2
))
11976 swap_insertion (old_loc
, loc2
);
11977 keep_in_target
= 1;
11985 if (!keep_in_target
)
11987 if (remove_breakpoint (old_loc
))
11989 /* This is just about all we can do. We could keep
11990 this location on the global list, and try to
11991 remove it next time, but there's no particular
11992 reason why we will succeed next time.
11994 Note that at this point, old_loc->owner is still
11995 valid, as delete_breakpoint frees the breakpoint
11996 only after calling us. */
11997 printf_filtered (_("warning: Error removing "
11998 "breakpoint %d\n"),
11999 old_loc
->owner
->number
);
12007 if (removed
&& target_is_non_stop_p ()
12008 && need_moribund_for_location_type (old_loc
))
12010 /* This location was removed from the target. In
12011 non-stop mode, a race condition is possible where
12012 we've removed a breakpoint, but stop events for that
12013 breakpoint are already queued and will arrive later.
12014 We apply an heuristic to be able to distinguish such
12015 SIGTRAPs from other random SIGTRAPs: we keep this
12016 breakpoint location for a bit, and will retire it
12017 after we see some number of events. The theory here
12018 is that reporting of events should, "on the average",
12019 be fair, so after a while we'll see events from all
12020 threads that have anything of interest, and no longer
12021 need to keep this breakpoint location around. We
12022 don't hold locations forever so to reduce chances of
12023 mistaking a non-breakpoint SIGTRAP for a breakpoint
12026 The heuristic failing can be disastrous on
12027 decr_pc_after_break targets.
12029 On decr_pc_after_break targets, like e.g., x86-linux,
12030 if we fail to recognize a late breakpoint SIGTRAP,
12031 because events_till_retirement has reached 0 too
12032 soon, we'll fail to do the PC adjustment, and report
12033 a random SIGTRAP to the user. When the user resumes
12034 the inferior, it will most likely immediately crash
12035 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12036 corrupted, because of being resumed e.g., in the
12037 middle of a multi-byte instruction, or skipped a
12038 one-byte instruction. This was actually seen happen
12039 on native x86-linux, and should be less rare on
12040 targets that do not support new thread events, like
12041 remote, due to the heuristic depending on
12044 Mistaking a random SIGTRAP for a breakpoint trap
12045 causes similar symptoms (PC adjustment applied when
12046 it shouldn't), but then again, playing with SIGTRAPs
12047 behind the debugger's back is asking for trouble.
12049 Since hardware watchpoint traps are always
12050 distinguishable from other traps, so we don't need to
12051 apply keep hardware watchpoint moribund locations
12052 around. We simply always ignore hardware watchpoint
12053 traps we can no longer explain. */
12055 process_stratum_target
*proc_target
= nullptr;
12056 for (inferior
*inf
: all_inferiors ())
12057 if (inf
->pspace
== old_loc
->pspace
)
12059 proc_target
= inf
->process_target ();
12062 if (proc_target
!= nullptr)
12063 old_loc
->events_till_retirement
12064 = 3 * (thread_count (proc_target
) + 1);
12066 old_loc
->events_till_retirement
= 1;
12067 old_loc
->owner
= NULL
;
12069 moribund_locations
.push_back (old_loc
);
12073 old_loc
->owner
= NULL
;
12074 decref_bp_location (&old_loc
);
12079 /* Rescan breakpoints at the same address and section, marking the
12080 first one as "first" and any others as "duplicates". This is so
12081 that the bpt instruction is only inserted once. If we have a
12082 permanent breakpoint at the same place as BPT, make that one the
12083 official one, and the rest as duplicates. Permanent breakpoints
12084 are sorted first for the same address.
12086 Do the same for hardware watchpoints, but also considering the
12087 watchpoint's type (regular/access/read) and length. */
12089 bp_loc_first
= NULL
;
12090 wp_loc_first
= NULL
;
12091 awp_loc_first
= NULL
;
12092 rwp_loc_first
= NULL
;
12093 ALL_BP_LOCATIONS (loc
, locp
)
12095 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12097 struct bp_location
**loc_first_p
;
12100 if (!unduplicated_should_be_inserted (loc
)
12101 || !bl_address_is_meaningful (loc
)
12102 /* Don't detect duplicate for tracepoint locations because they are
12103 never duplicated. See the comments in field `duplicate' of
12104 `struct bp_location'. */
12105 || is_tracepoint (b
))
12107 /* Clear the condition modification flag. */
12108 loc
->condition_changed
= condition_unchanged
;
12112 if (b
->type
== bp_hardware_watchpoint
)
12113 loc_first_p
= &wp_loc_first
;
12114 else if (b
->type
== bp_read_watchpoint
)
12115 loc_first_p
= &rwp_loc_first
;
12116 else if (b
->type
== bp_access_watchpoint
)
12117 loc_first_p
= &awp_loc_first
;
12119 loc_first_p
= &bp_loc_first
;
12121 if (*loc_first_p
== NULL
12122 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12123 || !breakpoint_locations_match (loc
, *loc_first_p
))
12125 *loc_first_p
= loc
;
12126 loc
->duplicate
= 0;
12128 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12130 loc
->needs_update
= 1;
12131 /* Clear the condition modification flag. */
12132 loc
->condition_changed
= condition_unchanged
;
12138 /* This and the above ensure the invariant that the first location
12139 is not duplicated, and is the inserted one.
12140 All following are marked as duplicated, and are not inserted. */
12142 swap_insertion (loc
, *loc_first_p
);
12143 loc
->duplicate
= 1;
12145 /* Clear the condition modification flag. */
12146 loc
->condition_changed
= condition_unchanged
;
12149 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12151 if (insert_mode
!= UGLL_DONT_INSERT
)
12152 insert_breakpoint_locations ();
12155 /* Even though the caller told us to not insert new
12156 locations, we may still need to update conditions on the
12157 target's side of breakpoints that were already inserted
12158 if the target is evaluating breakpoint conditions. We
12159 only update conditions for locations that are marked
12161 update_inserted_breakpoint_locations ();
12165 if (insert_mode
!= UGLL_DONT_INSERT
)
12166 download_tracepoint_locations ();
12170 breakpoint_retire_moribund (void)
12172 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
12174 struct bp_location
*loc
= moribund_locations
[ix
];
12175 if (--(loc
->events_till_retirement
) == 0)
12177 decref_bp_location (&loc
);
12178 unordered_remove (moribund_locations
, ix
);
12185 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12190 update_global_location_list (insert_mode
);
12192 catch (const gdb_exception_error
&e
)
12197 /* Clear BKP from a BPS. */
12200 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12204 for (bs
= bps
; bs
; bs
= bs
->next
)
12205 if (bs
->breakpoint_at
== bpt
)
12207 bs
->breakpoint_at
= NULL
;
12208 bs
->old_val
= NULL
;
12209 /* bs->commands will be freed later. */
12213 /* Callback for iterate_over_threads. */
12215 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12217 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12219 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12223 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12227 say_where (struct breakpoint
*b
)
12229 struct value_print_options opts
;
12231 get_user_print_options (&opts
);
12233 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12235 if (b
->loc
== NULL
)
12237 /* For pending locations, the output differs slightly based
12238 on b->extra_string. If this is non-NULL, it contains either
12239 a condition or dprintf arguments. */
12240 if (b
->extra_string
== NULL
)
12242 printf_filtered (_(" (%s) pending."),
12243 event_location_to_string (b
->location
.get ()));
12245 else if (b
->type
== bp_dprintf
)
12247 printf_filtered (_(" (%s,%s) pending."),
12248 event_location_to_string (b
->location
.get ()),
12253 printf_filtered (_(" (%s %s) pending."),
12254 event_location_to_string (b
->location
.get ()),
12260 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12261 printf_filtered (" at %ps",
12262 styled_string (address_style
.style (),
12263 paddress (b
->loc
->gdbarch
,
12264 b
->loc
->address
)));
12265 if (b
->loc
->symtab
!= NULL
)
12267 /* If there is a single location, we can print the location
12269 if (b
->loc
->next
== NULL
)
12271 const char *filename
12272 = symtab_to_filename_for_display (b
->loc
->symtab
);
12273 printf_filtered (": file %ps, line %d.",
12274 styled_string (file_name_style
.style (),
12276 b
->loc
->line_number
);
12279 /* This is not ideal, but each location may have a
12280 different file name, and this at least reflects the
12281 real situation somewhat. */
12282 printf_filtered (": %s.",
12283 event_location_to_string (b
->location
.get ()));
12288 struct bp_location
*loc
= b
->loc
;
12290 for (; loc
; loc
= loc
->next
)
12292 printf_filtered (" (%d locations)", n
);
12297 bp_location::~bp_location ()
12299 xfree (function_name
);
12302 /* Destructor for the breakpoint base class. */
12304 breakpoint::~breakpoint ()
12306 xfree (this->cond_string
);
12307 xfree (this->extra_string
);
12310 static struct bp_location
*
12311 base_breakpoint_allocate_location (struct breakpoint
*self
)
12313 return new bp_location (self
);
12317 base_breakpoint_re_set (struct breakpoint
*b
)
12319 /* Nothing to re-set. */
12322 #define internal_error_pure_virtual_called() \
12323 gdb_assert_not_reached ("pure virtual function called")
12326 base_breakpoint_insert_location (struct bp_location
*bl
)
12328 internal_error_pure_virtual_called ();
12332 base_breakpoint_remove_location (struct bp_location
*bl
,
12333 enum remove_bp_reason reason
)
12335 internal_error_pure_virtual_called ();
12339 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12340 const address_space
*aspace
,
12342 const struct target_waitstatus
*ws
)
12344 internal_error_pure_virtual_called ();
12348 base_breakpoint_check_status (bpstat bs
)
12353 /* A "works_in_software_mode" breakpoint_ops method that just internal
12357 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12359 internal_error_pure_virtual_called ();
12362 /* A "resources_needed" breakpoint_ops method that just internal
12366 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12368 internal_error_pure_virtual_called ();
12371 static enum print_stop_action
12372 base_breakpoint_print_it (bpstat bs
)
12374 internal_error_pure_virtual_called ();
12378 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12379 struct ui_out
*uiout
)
12385 base_breakpoint_print_mention (struct breakpoint
*b
)
12387 internal_error_pure_virtual_called ();
12391 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12393 internal_error_pure_virtual_called ();
12397 base_breakpoint_create_sals_from_location
12398 (struct event_location
*location
,
12399 struct linespec_result
*canonical
,
12400 enum bptype type_wanted
)
12402 internal_error_pure_virtual_called ();
12406 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12407 struct linespec_result
*c
,
12408 gdb::unique_xmalloc_ptr
<char> cond_string
,
12409 gdb::unique_xmalloc_ptr
<char> extra_string
,
12410 enum bptype type_wanted
,
12411 enum bpdisp disposition
,
12413 int task
, int ignore_count
,
12414 const struct breakpoint_ops
*o
,
12415 int from_tty
, int enabled
,
12416 int internal
, unsigned flags
)
12418 internal_error_pure_virtual_called ();
12421 static std::vector
<symtab_and_line
>
12422 base_breakpoint_decode_location (struct breakpoint
*b
,
12423 struct event_location
*location
,
12424 struct program_space
*search_pspace
)
12426 internal_error_pure_virtual_called ();
12429 /* The default 'explains_signal' method. */
12432 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12437 /* The default "after_condition_true" method. */
12440 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12442 /* Nothing to do. */
12445 struct breakpoint_ops base_breakpoint_ops
=
12447 base_breakpoint_allocate_location
,
12448 base_breakpoint_re_set
,
12449 base_breakpoint_insert_location
,
12450 base_breakpoint_remove_location
,
12451 base_breakpoint_breakpoint_hit
,
12452 base_breakpoint_check_status
,
12453 base_breakpoint_resources_needed
,
12454 base_breakpoint_works_in_software_mode
,
12455 base_breakpoint_print_it
,
12457 base_breakpoint_print_one_detail
,
12458 base_breakpoint_print_mention
,
12459 base_breakpoint_print_recreate
,
12460 base_breakpoint_create_sals_from_location
,
12461 base_breakpoint_create_breakpoints_sal
,
12462 base_breakpoint_decode_location
,
12463 base_breakpoint_explains_signal
,
12464 base_breakpoint_after_condition_true
,
12467 /* Default breakpoint_ops methods. */
12470 bkpt_re_set (struct breakpoint
*b
)
12472 /* FIXME: is this still reachable? */
12473 if (breakpoint_event_location_empty_p (b
))
12475 /* Anything without a location can't be re-set. */
12476 delete_breakpoint (b
);
12480 breakpoint_re_set_default (b
);
12484 bkpt_insert_location (struct bp_location
*bl
)
12486 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12488 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12489 bl
->target_info
.placed_address
= addr
;
12491 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12492 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12494 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12498 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12500 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12501 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12503 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12507 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12508 const address_space
*aspace
, CORE_ADDR bp_addr
,
12509 const struct target_waitstatus
*ws
)
12511 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12512 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12515 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12519 if (overlay_debugging
/* unmapped overlay section */
12520 && section_is_overlay (bl
->section
)
12521 && !section_is_mapped (bl
->section
))
12528 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12529 const address_space
*aspace
, CORE_ADDR bp_addr
,
12530 const struct target_waitstatus
*ws
)
12532 if (dprintf_style
== dprintf_style_agent
12533 && target_can_run_breakpoint_commands ())
12535 /* An agent-style dprintf never causes a stop. If we see a trap
12536 for this address it must be for a breakpoint that happens to
12537 be set at the same address. */
12541 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12545 bkpt_resources_needed (const struct bp_location
*bl
)
12547 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12552 static enum print_stop_action
12553 bkpt_print_it (bpstat bs
)
12555 struct breakpoint
*b
;
12556 const struct bp_location
*bl
;
12558 struct ui_out
*uiout
= current_uiout
;
12560 gdb_assert (bs
->bp_location_at
!= NULL
);
12562 bl
= bs
->bp_location_at
;
12563 b
= bs
->breakpoint_at
;
12565 bp_temp
= b
->disposition
== disp_del
;
12566 if (bl
->address
!= bl
->requested_address
)
12567 breakpoint_adjustment_warning (bl
->requested_address
,
12570 annotate_breakpoint (b
->number
);
12571 maybe_print_thread_hit_breakpoint (uiout
);
12573 if (uiout
->is_mi_like_p ())
12575 uiout
->field_string ("reason",
12576 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12577 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12580 uiout
->message ("Temporary breakpoint %pF, ",
12581 signed_field ("bkptno", b
->number
));
12583 uiout
->message ("Breakpoint %pF, ",
12584 signed_field ("bkptno", b
->number
));
12586 return PRINT_SRC_AND_LOC
;
12590 bkpt_print_mention (struct breakpoint
*b
)
12592 if (current_uiout
->is_mi_like_p ())
12597 case bp_breakpoint
:
12598 case bp_gnu_ifunc_resolver
:
12599 if (b
->disposition
== disp_del
)
12600 printf_filtered (_("Temporary breakpoint"));
12602 printf_filtered (_("Breakpoint"));
12603 printf_filtered (_(" %d"), b
->number
);
12604 if (b
->type
== bp_gnu_ifunc_resolver
)
12605 printf_filtered (_(" at gnu-indirect-function resolver"));
12607 case bp_hardware_breakpoint
:
12608 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12611 printf_filtered (_("Dprintf %d"), b
->number
);
12619 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12621 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12622 fprintf_unfiltered (fp
, "tbreak");
12623 else if (tp
->type
== bp_breakpoint
)
12624 fprintf_unfiltered (fp
, "break");
12625 else if (tp
->type
== bp_hardware_breakpoint
12626 && tp
->disposition
== disp_del
)
12627 fprintf_unfiltered (fp
, "thbreak");
12628 else if (tp
->type
== bp_hardware_breakpoint
)
12629 fprintf_unfiltered (fp
, "hbreak");
12631 internal_error (__FILE__
, __LINE__
,
12632 _("unhandled breakpoint type %d"), (int) tp
->type
);
12634 fprintf_unfiltered (fp
, " %s",
12635 event_location_to_string (tp
->location
.get ()));
12637 /* Print out extra_string if this breakpoint is pending. It might
12638 contain, for example, conditions that were set by the user. */
12639 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12640 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12642 print_recreate_thread (tp
, fp
);
12646 bkpt_create_sals_from_location (struct event_location
*location
,
12647 struct linespec_result
*canonical
,
12648 enum bptype type_wanted
)
12650 create_sals_from_location_default (location
, canonical
, type_wanted
);
12654 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12655 struct linespec_result
*canonical
,
12656 gdb::unique_xmalloc_ptr
<char> cond_string
,
12657 gdb::unique_xmalloc_ptr
<char> extra_string
,
12658 enum bptype type_wanted
,
12659 enum bpdisp disposition
,
12661 int task
, int ignore_count
,
12662 const struct breakpoint_ops
*ops
,
12663 int from_tty
, int enabled
,
12664 int internal
, unsigned flags
)
12666 create_breakpoints_sal_default (gdbarch
, canonical
,
12667 std::move (cond_string
),
12668 std::move (extra_string
),
12670 disposition
, thread
, task
,
12671 ignore_count
, ops
, from_tty
,
12672 enabled
, internal
, flags
);
12675 static std::vector
<symtab_and_line
>
12676 bkpt_decode_location (struct breakpoint
*b
,
12677 struct event_location
*location
,
12678 struct program_space
*search_pspace
)
12680 return decode_location_default (b
, location
, search_pspace
);
12683 /* Virtual table for internal breakpoints. */
12686 internal_bkpt_re_set (struct breakpoint
*b
)
12690 /* Delete overlay event and longjmp master breakpoints; they
12691 will be reset later by breakpoint_re_set. */
12692 case bp_overlay_event
:
12693 case bp_longjmp_master
:
12694 case bp_std_terminate_master
:
12695 case bp_exception_master
:
12696 delete_breakpoint (b
);
12699 /* This breakpoint is special, it's set up when the inferior
12700 starts and we really don't want to touch it. */
12701 case bp_shlib_event
:
12703 /* Like bp_shlib_event, this breakpoint type is special. Once
12704 it is set up, we do not want to touch it. */
12705 case bp_thread_event
:
12711 internal_bkpt_check_status (bpstat bs
)
12713 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12715 /* If requested, stop when the dynamic linker notifies GDB of
12716 events. This allows the user to get control and place
12717 breakpoints in initializer routines for dynamically loaded
12718 objects (among other things). */
12719 bs
->stop
= stop_on_solib_events
;
12720 bs
->print
= stop_on_solib_events
;
12726 static enum print_stop_action
12727 internal_bkpt_print_it (bpstat bs
)
12729 struct breakpoint
*b
;
12731 b
= bs
->breakpoint_at
;
12735 case bp_shlib_event
:
12736 /* Did we stop because the user set the stop_on_solib_events
12737 variable? (If so, we report this as a generic, "Stopped due
12738 to shlib event" message.) */
12739 print_solib_event (0);
12742 case bp_thread_event
:
12743 /* Not sure how we will get here.
12744 GDB should not stop for these breakpoints. */
12745 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12748 case bp_overlay_event
:
12749 /* By analogy with the thread event, GDB should not stop for these. */
12750 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12753 case bp_longjmp_master
:
12754 /* These should never be enabled. */
12755 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12758 case bp_std_terminate_master
:
12759 /* These should never be enabled. */
12760 printf_filtered (_("std::terminate Master Breakpoint: "
12761 "gdb should not stop!\n"));
12764 case bp_exception_master
:
12765 /* These should never be enabled. */
12766 printf_filtered (_("Exception Master Breakpoint: "
12767 "gdb should not stop!\n"));
12771 return PRINT_NOTHING
;
12775 internal_bkpt_print_mention (struct breakpoint
*b
)
12777 /* Nothing to mention. These breakpoints are internal. */
12780 /* Virtual table for momentary breakpoints */
12783 momentary_bkpt_re_set (struct breakpoint
*b
)
12785 /* Keep temporary breakpoints, which can be encountered when we step
12786 over a dlopen call and solib_add is resetting the breakpoints.
12787 Otherwise these should have been blown away via the cleanup chain
12788 or by breakpoint_init_inferior when we rerun the executable. */
12792 momentary_bkpt_check_status (bpstat bs
)
12794 /* Nothing. The point of these breakpoints is causing a stop. */
12797 static enum print_stop_action
12798 momentary_bkpt_print_it (bpstat bs
)
12800 return PRINT_UNKNOWN
;
12804 momentary_bkpt_print_mention (struct breakpoint
*b
)
12806 /* Nothing to mention. These breakpoints are internal. */
12809 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12811 It gets cleared already on the removal of the first one of such placed
12812 breakpoints. This is OK as they get all removed altogether. */
12814 longjmp_breakpoint::~longjmp_breakpoint ()
12816 thread_info
*tp
= find_thread_global_id (this->thread
);
12819 tp
->initiating_frame
= null_frame_id
;
12822 /* Specific methods for probe breakpoints. */
12825 bkpt_probe_insert_location (struct bp_location
*bl
)
12827 int v
= bkpt_insert_location (bl
);
12831 /* The insertion was successful, now let's set the probe's semaphore
12833 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12840 bkpt_probe_remove_location (struct bp_location
*bl
,
12841 enum remove_bp_reason reason
)
12843 /* Let's clear the semaphore before removing the location. */
12844 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12846 return bkpt_remove_location (bl
, reason
);
12850 bkpt_probe_create_sals_from_location (struct event_location
*location
,
12851 struct linespec_result
*canonical
,
12852 enum bptype type_wanted
)
12854 struct linespec_sals lsal
;
12856 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12858 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12859 canonical
->lsals
.push_back (std::move (lsal
));
12862 static std::vector
<symtab_and_line
>
12863 bkpt_probe_decode_location (struct breakpoint
*b
,
12864 struct event_location
*location
,
12865 struct program_space
*search_pspace
)
12867 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12869 error (_("probe not found"));
12873 /* The breakpoint_ops structure to be used in tracepoints. */
12876 tracepoint_re_set (struct breakpoint
*b
)
12878 breakpoint_re_set_default (b
);
12882 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12883 const address_space
*aspace
, CORE_ADDR bp_addr
,
12884 const struct target_waitstatus
*ws
)
12886 /* By definition, the inferior does not report stops at
12892 tracepoint_print_one_detail (const struct breakpoint
*self
,
12893 struct ui_out
*uiout
)
12895 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12896 if (!tp
->static_trace_marker_id
.empty ())
12898 gdb_assert (self
->type
== bp_static_tracepoint
);
12900 uiout
->message ("\tmarker id is %pF\n",
12901 string_field ("static-tracepoint-marker-string-id",
12902 tp
->static_trace_marker_id
.c_str ()));
12907 tracepoint_print_mention (struct breakpoint
*b
)
12909 if (current_uiout
->is_mi_like_p ())
12914 case bp_tracepoint
:
12915 printf_filtered (_("Tracepoint"));
12916 printf_filtered (_(" %d"), b
->number
);
12918 case bp_fast_tracepoint
:
12919 printf_filtered (_("Fast tracepoint"));
12920 printf_filtered (_(" %d"), b
->number
);
12922 case bp_static_tracepoint
:
12923 printf_filtered (_("Static tracepoint"));
12924 printf_filtered (_(" %d"), b
->number
);
12927 internal_error (__FILE__
, __LINE__
,
12928 _("unhandled tracepoint type %d"), (int) b
->type
);
12935 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12937 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12939 if (self
->type
== bp_fast_tracepoint
)
12940 fprintf_unfiltered (fp
, "ftrace");
12941 else if (self
->type
== bp_static_tracepoint
)
12942 fprintf_unfiltered (fp
, "strace");
12943 else if (self
->type
== bp_tracepoint
)
12944 fprintf_unfiltered (fp
, "trace");
12946 internal_error (__FILE__
, __LINE__
,
12947 _("unhandled tracepoint type %d"), (int) self
->type
);
12949 fprintf_unfiltered (fp
, " %s",
12950 event_location_to_string (self
->location
.get ()));
12951 print_recreate_thread (self
, fp
);
12953 if (tp
->pass_count
)
12954 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12958 tracepoint_create_sals_from_location (struct event_location
*location
,
12959 struct linespec_result
*canonical
,
12960 enum bptype type_wanted
)
12962 create_sals_from_location_default (location
, canonical
, type_wanted
);
12966 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12967 struct linespec_result
*canonical
,
12968 gdb::unique_xmalloc_ptr
<char> cond_string
,
12969 gdb::unique_xmalloc_ptr
<char> extra_string
,
12970 enum bptype type_wanted
,
12971 enum bpdisp disposition
,
12973 int task
, int ignore_count
,
12974 const struct breakpoint_ops
*ops
,
12975 int from_tty
, int enabled
,
12976 int internal
, unsigned flags
)
12978 create_breakpoints_sal_default (gdbarch
, canonical
,
12979 std::move (cond_string
),
12980 std::move (extra_string
),
12982 disposition
, thread
, task
,
12983 ignore_count
, ops
, from_tty
,
12984 enabled
, internal
, flags
);
12987 static std::vector
<symtab_and_line
>
12988 tracepoint_decode_location (struct breakpoint
*b
,
12989 struct event_location
*location
,
12990 struct program_space
*search_pspace
)
12992 return decode_location_default (b
, location
, search_pspace
);
12995 struct breakpoint_ops tracepoint_breakpoint_ops
;
12997 /* Virtual table for tracepoints on static probes. */
13000 tracepoint_probe_create_sals_from_location
13001 (struct event_location
*location
,
13002 struct linespec_result
*canonical
,
13003 enum bptype type_wanted
)
13005 /* We use the same method for breakpoint on probes. */
13006 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13009 static std::vector
<symtab_and_line
>
13010 tracepoint_probe_decode_location (struct breakpoint
*b
,
13011 struct event_location
*location
,
13012 struct program_space
*search_pspace
)
13014 /* We use the same method for breakpoint on probes. */
13015 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13018 /* Dprintf breakpoint_ops methods. */
13021 dprintf_re_set (struct breakpoint
*b
)
13023 breakpoint_re_set_default (b
);
13025 /* extra_string should never be non-NULL for dprintf. */
13026 gdb_assert (b
->extra_string
!= NULL
);
13028 /* 1 - connect to target 1, that can run breakpoint commands.
13029 2 - create a dprintf, which resolves fine.
13030 3 - disconnect from target 1
13031 4 - connect to target 2, that can NOT run breakpoint commands.
13033 After steps #3/#4, you'll want the dprintf command list to
13034 be updated, because target 1 and 2 may well return different
13035 answers for target_can_run_breakpoint_commands().
13036 Given absence of finer grained resetting, we get to do
13037 it all the time. */
13038 if (b
->extra_string
!= NULL
)
13039 update_dprintf_command_list (b
);
13042 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13045 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13047 fprintf_unfiltered (fp
, "dprintf %s,%s",
13048 event_location_to_string (tp
->location
.get ()),
13050 print_recreate_thread (tp
, fp
);
13053 /* Implement the "after_condition_true" breakpoint_ops method for
13056 dprintf's are implemented with regular commands in their command
13057 list, but we run the commands here instead of before presenting the
13058 stop to the user, as dprintf's don't actually cause a stop. This
13059 also makes it so that the commands of multiple dprintfs at the same
13060 address are all handled. */
13063 dprintf_after_condition_true (struct bpstats
*bs
)
13065 struct bpstats tmp_bs
;
13066 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13068 /* dprintf's never cause a stop. This wasn't set in the
13069 check_status hook instead because that would make the dprintf's
13070 condition not be evaluated. */
13073 /* Run the command list here. Take ownership of it instead of
13074 copying. We never want these commands to run later in
13075 bpstat_do_actions, if a breakpoint that causes a stop happens to
13076 be set at same address as this dprintf, or even if running the
13077 commands here throws. */
13078 tmp_bs
.commands
= bs
->commands
;
13079 bs
->commands
= NULL
;
13081 bpstat_do_actions_1 (&tmp_bs_p
);
13083 /* 'tmp_bs.commands' will usually be NULL by now, but
13084 bpstat_do_actions_1 may return early without processing the whole
13088 /* The breakpoint_ops structure to be used on static tracepoints with
13092 strace_marker_create_sals_from_location (struct event_location
*location
,
13093 struct linespec_result
*canonical
,
13094 enum bptype type_wanted
)
13096 struct linespec_sals lsal
;
13097 const char *arg_start
, *arg
;
13099 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
13100 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13102 std::string
str (arg_start
, arg
- arg_start
);
13103 const char *ptr
= str
.c_str ();
13104 canonical
->location
13105 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
13108 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13109 canonical
->lsals
.push_back (std::move (lsal
));
13113 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13114 struct linespec_result
*canonical
,
13115 gdb::unique_xmalloc_ptr
<char> cond_string
,
13116 gdb::unique_xmalloc_ptr
<char> extra_string
,
13117 enum bptype type_wanted
,
13118 enum bpdisp disposition
,
13120 int task
, int ignore_count
,
13121 const struct breakpoint_ops
*ops
,
13122 int from_tty
, int enabled
,
13123 int internal
, unsigned flags
)
13125 const linespec_sals
&lsal
= canonical
->lsals
[0];
13127 /* If the user is creating a static tracepoint by marker id
13128 (strace -m MARKER_ID), then store the sals index, so that
13129 breakpoint_re_set can try to match up which of the newly
13130 found markers corresponds to this one, and, don't try to
13131 expand multiple locations for each sal, given than SALS
13132 already should contain all sals for MARKER_ID. */
13134 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13136 event_location_up location
13137 = copy_event_location (canonical
->location
.get ());
13139 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13140 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13141 std::move (location
), NULL
,
13142 std::move (cond_string
),
13143 std::move (extra_string
),
13144 type_wanted
, disposition
,
13145 thread
, task
, ignore_count
, ops
,
13146 from_tty
, enabled
, internal
, flags
,
13147 canonical
->special_display
);
13148 /* Given that its possible to have multiple markers with
13149 the same string id, if the user is creating a static
13150 tracepoint by marker id ("strace -m MARKER_ID"), then
13151 store the sals index, so that breakpoint_re_set can
13152 try to match up which of the newly found markers
13153 corresponds to this one */
13154 tp
->static_trace_marker_id_idx
= i
;
13156 install_breakpoint (internal
, std::move (tp
), 0);
13160 static std::vector
<symtab_and_line
>
13161 strace_marker_decode_location (struct breakpoint
*b
,
13162 struct event_location
*location
,
13163 struct program_space
*search_pspace
)
13165 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13166 const char *s
= get_linespec_location (location
)->spec_string
;
13168 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13169 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13171 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13176 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
13179 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13182 strace_marker_p (struct breakpoint
*b
)
13184 return b
->ops
== &strace_marker_breakpoint_ops
;
13187 /* Delete a breakpoint and clean up all traces of it in the data
13191 delete_breakpoint (struct breakpoint
*bpt
)
13193 struct breakpoint
*b
;
13195 gdb_assert (bpt
!= NULL
);
13197 /* Has this bp already been deleted? This can happen because
13198 multiple lists can hold pointers to bp's. bpstat lists are
13201 One example of this happening is a watchpoint's scope bp. When
13202 the scope bp triggers, we notice that the watchpoint is out of
13203 scope, and delete it. We also delete its scope bp. But the
13204 scope bp is marked "auto-deleting", and is already on a bpstat.
13205 That bpstat is then checked for auto-deleting bp's, which are
13208 A real solution to this problem might involve reference counts in
13209 bp's, and/or giving them pointers back to their referencing
13210 bpstat's, and teaching delete_breakpoint to only free a bp's
13211 storage when no more references were extent. A cheaper bandaid
13213 if (bpt
->type
== bp_none
)
13216 /* At least avoid this stale reference until the reference counting
13217 of breakpoints gets resolved. */
13218 if (bpt
->related_breakpoint
!= bpt
)
13220 struct breakpoint
*related
;
13221 struct watchpoint
*w
;
13223 if (bpt
->type
== bp_watchpoint_scope
)
13224 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13225 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13226 w
= (struct watchpoint
*) bpt
;
13230 watchpoint_del_at_next_stop (w
);
13232 /* Unlink bpt from the bpt->related_breakpoint ring. */
13233 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13234 related
= related
->related_breakpoint
);
13235 related
->related_breakpoint
= bpt
->related_breakpoint
;
13236 bpt
->related_breakpoint
= bpt
;
13239 /* watch_command_1 creates a watchpoint but only sets its number if
13240 update_watchpoint succeeds in creating its bp_locations. If there's
13241 a problem in that process, we'll be asked to delete the half-created
13242 watchpoint. In that case, don't announce the deletion. */
13244 gdb::observers::breakpoint_deleted
.notify (bpt
);
13246 if (breakpoint_chain
== bpt
)
13247 breakpoint_chain
= bpt
->next
;
13249 ALL_BREAKPOINTS (b
)
13250 if (b
->next
== bpt
)
13252 b
->next
= bpt
->next
;
13256 /* Be sure no bpstat's are pointing at the breakpoint after it's
13258 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13259 in all threads for now. Note that we cannot just remove bpstats
13260 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13261 commands are associated with the bpstat; if we remove it here,
13262 then the later call to bpstat_do_actions (&stop_bpstat); in
13263 event-top.c won't do anything, and temporary breakpoints with
13264 commands won't work. */
13266 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13268 /* Now that breakpoint is removed from breakpoint list, update the
13269 global location list. This will remove locations that used to
13270 belong to this breakpoint. Do this before freeing the breakpoint
13271 itself, since remove_breakpoint looks at location's owner. It
13272 might be better design to have location completely
13273 self-contained, but it's not the case now. */
13274 update_global_location_list (UGLL_DONT_INSERT
);
13276 /* On the chance that someone will soon try again to delete this
13277 same bp, we mark it as deleted before freeing its storage. */
13278 bpt
->type
= bp_none
;
13282 /* Iterator function to call a user-provided callback function once
13283 for each of B and its related breakpoints. */
13286 iterate_over_related_breakpoints (struct breakpoint
*b
,
13287 gdb::function_view
<void (breakpoint
*)> function
)
13289 struct breakpoint
*related
;
13294 struct breakpoint
*next
;
13296 /* FUNCTION may delete RELATED. */
13297 next
= related
->related_breakpoint
;
13299 if (next
== related
)
13301 /* RELATED is the last ring entry. */
13302 function (related
);
13304 /* FUNCTION may have deleted it, so we'd never reach back to
13305 B. There's nothing left to do anyway, so just break
13310 function (related
);
13314 while (related
!= b
);
13318 delete_command (const char *arg
, int from_tty
)
13320 struct breakpoint
*b
, *b_tmp
;
13326 int breaks_to_delete
= 0;
13328 /* Delete all breakpoints if no argument. Do not delete
13329 internal breakpoints, these have to be deleted with an
13330 explicit breakpoint number argument. */
13331 ALL_BREAKPOINTS (b
)
13332 if (user_breakpoint_p (b
))
13334 breaks_to_delete
= 1;
13338 /* Ask user only if there are some breakpoints to delete. */
13340 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13342 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13343 if (user_breakpoint_p (b
))
13344 delete_breakpoint (b
);
13348 map_breakpoint_numbers
13349 (arg
, [&] (breakpoint
*br
)
13351 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13355 /* Return true if all locations of B bound to PSPACE are pending. If
13356 PSPACE is NULL, all locations of all program spaces are
13360 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13362 struct bp_location
*loc
;
13364 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13365 if ((pspace
== NULL
13366 || loc
->pspace
== pspace
)
13367 && !loc
->shlib_disabled
13368 && !loc
->pspace
->executing_startup
)
13373 /* Subroutine of update_breakpoint_locations to simplify it.
13374 Return non-zero if multiple fns in list LOC have the same name.
13375 Null names are ignored. */
13378 ambiguous_names_p (struct bp_location
*loc
)
13380 struct bp_location
*l
;
13381 htab_up
htab (htab_create_alloc (13, htab_hash_string
, streq_hash
, NULL
,
13384 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13387 const char *name
= l
->function_name
;
13389 /* Allow for some names to be NULL, ignore them. */
13393 slot
= (const char **) htab_find_slot (htab
.get (), (const void *) name
,
13395 /* NOTE: We can assume slot != NULL here because xcalloc never
13405 /* When symbols change, it probably means the sources changed as well,
13406 and it might mean the static tracepoint markers are no longer at
13407 the same address or line numbers they used to be at last we
13408 checked. Losing your static tracepoints whenever you rebuild is
13409 undesirable. This function tries to resync/rematch gdb static
13410 tracepoints with the markers on the target, for static tracepoints
13411 that have not been set by marker id. Static tracepoint that have
13412 been set by marker id are reset by marker id in breakpoint_re_set.
13415 1) For a tracepoint set at a specific address, look for a marker at
13416 the old PC. If one is found there, assume to be the same marker.
13417 If the name / string id of the marker found is different from the
13418 previous known name, assume that means the user renamed the marker
13419 in the sources, and output a warning.
13421 2) For a tracepoint set at a given line number, look for a marker
13422 at the new address of the old line number. If one is found there,
13423 assume to be the same marker. If the name / string id of the
13424 marker found is different from the previous known name, assume that
13425 means the user renamed the marker in the sources, and output a
13428 3) If a marker is no longer found at the same address or line, it
13429 may mean the marker no longer exists. But it may also just mean
13430 the code changed a bit. Maybe the user added a few lines of code
13431 that made the marker move up or down (in line number terms). Ask
13432 the target for info about the marker with the string id as we knew
13433 it. If found, update line number and address in the matching
13434 static tracepoint. This will get confused if there's more than one
13435 marker with the same ID (possible in UST, although unadvised
13436 precisely because it confuses tools). */
13438 static struct symtab_and_line
13439 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13441 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13442 struct static_tracepoint_marker marker
;
13447 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13449 if (target_static_tracepoint_marker_at (pc
, &marker
))
13451 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13452 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13453 b
->number
, tp
->static_trace_marker_id
.c_str (),
13454 marker
.str_id
.c_str ());
13456 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13461 /* Old marker wasn't found on target at lineno. Try looking it up
13463 if (!sal
.explicit_pc
13465 && sal
.symtab
!= NULL
13466 && !tp
->static_trace_marker_id
.empty ())
13468 std::vector
<static_tracepoint_marker
> markers
13469 = target_static_tracepoint_markers_by_strid
13470 (tp
->static_trace_marker_id
.c_str ());
13472 if (!markers
.empty ())
13474 struct symbol
*sym
;
13475 struct static_tracepoint_marker
*tpmarker
;
13476 struct ui_out
*uiout
= current_uiout
;
13477 struct explicit_location explicit_loc
;
13479 tpmarker
= &markers
[0];
13481 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13483 warning (_("marker for static tracepoint %d (%s) not "
13484 "found at previous line number"),
13485 b
->number
, tp
->static_trace_marker_id
.c_str ());
13487 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13488 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13489 uiout
->text ("Now in ");
13492 uiout
->field_string ("func", sym
->print_name (),
13493 function_name_style
.style ());
13494 uiout
->text (" at ");
13496 uiout
->field_string ("file",
13497 symtab_to_filename_for_display (sal2
.symtab
),
13498 file_name_style
.style ());
13501 if (uiout
->is_mi_like_p ())
13503 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13505 uiout
->field_string ("fullname", fullname
);
13508 uiout
->field_signed ("line", sal2
.line
);
13509 uiout
->text ("\n");
13511 b
->loc
->line_number
= sal2
.line
;
13512 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13514 b
->location
.reset (NULL
);
13515 initialize_explicit_location (&explicit_loc
);
13516 explicit_loc
.source_filename
13517 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13518 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13519 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13520 b
->location
= new_explicit_location (&explicit_loc
);
13522 /* Might be nice to check if function changed, and warn if
13529 /* Returns 1 iff locations A and B are sufficiently same that
13530 we don't need to report breakpoint as changed. */
13533 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13537 if (a
->address
!= b
->address
)
13540 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13543 if (a
->enabled
!= b
->enabled
)
13546 if (a
->disabled_by_cond
!= b
->disabled_by_cond
)
13553 if ((a
== NULL
) != (b
== NULL
))
13559 /* Split all locations of B that are bound to PSPACE out of B's
13560 location list to a separate list and return that list's head. If
13561 PSPACE is NULL, hoist out all locations of B. */
13563 static struct bp_location
*
13564 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13566 struct bp_location head
;
13567 struct bp_location
*i
= b
->loc
;
13568 struct bp_location
**i_link
= &b
->loc
;
13569 struct bp_location
*hoisted
= &head
;
13571 if (pspace
== NULL
)
13582 if (i
->pspace
== pspace
)
13597 /* Create new breakpoint locations for B (a hardware or software
13598 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13599 zero, then B is a ranged breakpoint. Only recreates locations for
13600 FILTER_PSPACE. Locations of other program spaces are left
13604 update_breakpoint_locations (struct breakpoint
*b
,
13605 struct program_space
*filter_pspace
,
13606 gdb::array_view
<const symtab_and_line
> sals
,
13607 gdb::array_view
<const symtab_and_line
> sals_end
)
13609 struct bp_location
*existing_locations
;
13611 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13613 /* Ranged breakpoints have only one start location and one end
13615 b
->enable_state
= bp_disabled
;
13616 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13617 "multiple locations found\n"),
13622 /* If there's no new locations, and all existing locations are
13623 pending, don't do anything. This optimizes the common case where
13624 all locations are in the same shared library, that was unloaded.
13625 We'd like to retain the location, so that when the library is
13626 loaded again, we don't loose the enabled/disabled status of the
13627 individual locations. */
13628 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13631 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13633 for (const auto &sal
: sals
)
13635 struct bp_location
*new_loc
;
13637 switch_to_program_space_and_thread (sal
.pspace
);
13639 new_loc
= add_location_to_breakpoint (b
, &sal
);
13641 /* Reparse conditions, they might contain references to the
13643 if (b
->cond_string
!= NULL
)
13647 s
= b
->cond_string
;
13650 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13651 block_for_pc (sal
.pc
),
13654 catch (const gdb_exception_error
&e
)
13656 new_loc
->disabled_by_cond
= true;
13660 if (!sals_end
.empty ())
13662 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13664 new_loc
->length
= end
- sals
[0].pc
+ 1;
13668 /* If possible, carry over 'disable' status from existing
13671 struct bp_location
*e
= existing_locations
;
13672 /* If there are multiple breakpoints with the same function name,
13673 e.g. for inline functions, comparing function names won't work.
13674 Instead compare pc addresses; this is just a heuristic as things
13675 may have moved, but in practice it gives the correct answer
13676 often enough until a better solution is found. */
13677 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13679 for (; e
; e
= e
->next
)
13681 if ((!e
->enabled
|| e
->disabled_by_cond
) && e
->function_name
)
13683 struct bp_location
*l
= b
->loc
;
13684 if (have_ambiguous_names
)
13686 for (; l
; l
= l
->next
)
13688 /* Ignore software vs hardware location type at
13689 this point, because with "set breakpoint
13690 auto-hw", after a re-set, locations that were
13691 hardware can end up as software, or vice versa.
13692 As mentioned above, this is an heuristic and in
13693 practice should give the correct answer often
13695 if (breakpoint_locations_match (e
, l
, true))
13697 l
->enabled
= e
->enabled
;
13698 l
->disabled_by_cond
= e
->disabled_by_cond
;
13705 for (; l
; l
= l
->next
)
13706 if (l
->function_name
13707 && strcmp (e
->function_name
, l
->function_name
) == 0)
13709 l
->enabled
= e
->enabled
;
13710 l
->disabled_by_cond
= e
->disabled_by_cond
;
13718 if (!locations_are_equal (existing_locations
, b
->loc
))
13719 gdb::observers::breakpoint_modified
.notify (b
);
13722 /* Find the SaL locations corresponding to the given LOCATION.
13723 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13725 static std::vector
<symtab_and_line
>
13726 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13727 struct program_space
*search_pspace
, int *found
)
13729 struct gdb_exception exception
;
13731 gdb_assert (b
->ops
!= NULL
);
13733 std::vector
<symtab_and_line
> sals
;
13737 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13739 catch (gdb_exception_error
&e
)
13741 int not_found_and_ok
= 0;
13743 /* For pending breakpoints, it's expected that parsing will
13744 fail until the right shared library is loaded. User has
13745 already told to create pending breakpoints and don't need
13746 extra messages. If breakpoint is in bp_shlib_disabled
13747 state, then user already saw the message about that
13748 breakpoint being disabled, and don't want to see more
13750 if (e
.error
== NOT_FOUND_ERROR
13751 && (b
->condition_not_parsed
13753 && search_pspace
!= NULL
13754 && b
->loc
->pspace
!= search_pspace
)
13755 || (b
->loc
&& b
->loc
->shlib_disabled
)
13756 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13757 || b
->enable_state
== bp_disabled
))
13758 not_found_and_ok
= 1;
13760 if (!not_found_and_ok
)
13762 /* We surely don't want to warn about the same breakpoint
13763 10 times. One solution, implemented here, is disable
13764 the breakpoint on error. Another solution would be to
13765 have separate 'warning emitted' flag. Since this
13766 happens only when a binary has changed, I don't know
13767 which approach is better. */
13768 b
->enable_state
= bp_disabled
;
13772 exception
= std::move (e
);
13775 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13777 for (auto &sal
: sals
)
13778 resolve_sal_pc (&sal
);
13779 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13781 char *cond_string
, *extra_string
;
13784 find_condition_and_thread_for_sals (sals
, b
->extra_string
,
13785 &cond_string
, &thread
,
13786 &task
, &extra_string
);
13787 gdb_assert (b
->cond_string
== NULL
);
13789 b
->cond_string
= cond_string
;
13790 b
->thread
= thread
;
13794 xfree (b
->extra_string
);
13795 b
->extra_string
= extra_string
;
13797 b
->condition_not_parsed
= 0;
13800 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13801 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13811 /* The default re_set method, for typical hardware or software
13812 breakpoints. Reevaluate the breakpoint and recreate its
13816 breakpoint_re_set_default (struct breakpoint
*b
)
13818 struct program_space
*filter_pspace
= current_program_space
;
13819 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13822 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13823 filter_pspace
, &found
);
13825 expanded
= std::move (sals
);
13827 if (b
->location_range_end
!= NULL
)
13829 std::vector
<symtab_and_line
> sals_end
13830 = location_to_sals (b
, b
->location_range_end
.get (),
13831 filter_pspace
, &found
);
13833 expanded_end
= std::move (sals_end
);
13836 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13839 /* Default method for creating SALs from an address string. It basically
13840 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13843 create_sals_from_location_default (struct event_location
*location
,
13844 struct linespec_result
*canonical
,
13845 enum bptype type_wanted
)
13847 parse_breakpoint_sals (location
, canonical
);
13850 /* Call create_breakpoints_sal for the given arguments. This is the default
13851 function for the `create_breakpoints_sal' method of
13855 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13856 struct linespec_result
*canonical
,
13857 gdb::unique_xmalloc_ptr
<char> cond_string
,
13858 gdb::unique_xmalloc_ptr
<char> extra_string
,
13859 enum bptype type_wanted
,
13860 enum bpdisp disposition
,
13862 int task
, int ignore_count
,
13863 const struct breakpoint_ops
*ops
,
13864 int from_tty
, int enabled
,
13865 int internal
, unsigned flags
)
13867 create_breakpoints_sal (gdbarch
, canonical
,
13868 std::move (cond_string
),
13869 std::move (extra_string
),
13870 type_wanted
, disposition
,
13871 thread
, task
, ignore_count
, ops
, from_tty
,
13872 enabled
, internal
, flags
);
13875 /* Decode the line represented by S by calling decode_line_full. This is the
13876 default function for the `decode_location' method of breakpoint_ops. */
13878 static std::vector
<symtab_and_line
>
13879 decode_location_default (struct breakpoint
*b
,
13880 struct event_location
*location
,
13881 struct program_space
*search_pspace
)
13883 struct linespec_result canonical
;
13885 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13886 NULL
, 0, &canonical
, multiple_symbols_all
,
13889 /* We should get 0 or 1 resulting SALs. */
13890 gdb_assert (canonical
.lsals
.size () < 2);
13892 if (!canonical
.lsals
.empty ())
13894 const linespec_sals
&lsal
= canonical
.lsals
[0];
13895 return std::move (lsal
.sals
);
13900 /* Reset a breakpoint. */
13903 breakpoint_re_set_one (breakpoint
*b
)
13905 input_radix
= b
->input_radix
;
13906 set_language (b
->language
);
13908 b
->ops
->re_set (b
);
13911 /* Re-set breakpoint locations for the current program space.
13912 Locations bound to other program spaces are left untouched. */
13915 breakpoint_re_set (void)
13917 struct breakpoint
*b
, *b_tmp
;
13920 scoped_restore_current_language save_language
;
13921 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13922 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13924 /* breakpoint_re_set_one sets the current_language to the language
13925 of the breakpoint it is resetting (see prepare_re_set_context)
13926 before re-evaluating the breakpoint's location. This change can
13927 unfortunately get undone by accident if the language_mode is set
13928 to auto, and we either switch frames, or more likely in this context,
13929 we select the current frame.
13931 We prevent this by temporarily turning the language_mode to
13932 language_mode_manual. We restore it once all breakpoints
13933 have been reset. */
13934 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13935 language_mode
= language_mode_manual
;
13937 /* Note: we must not try to insert locations until after all
13938 breakpoints have been re-set. Otherwise, e.g., when re-setting
13939 breakpoint 1, we'd insert the locations of breakpoint 2, which
13940 hadn't been re-set yet, and thus may have stale locations. */
13942 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13946 breakpoint_re_set_one (b
);
13948 catch (const gdb_exception
&ex
)
13950 exception_fprintf (gdb_stderr
, ex
,
13951 "Error in re-setting breakpoint %d: ",
13956 jit_breakpoint_re_set ();
13959 create_overlay_event_breakpoint ();
13960 create_longjmp_master_breakpoint ();
13961 create_std_terminate_master_breakpoint ();
13962 create_exception_master_breakpoint ();
13964 /* Now we can insert. */
13965 update_global_location_list (UGLL_MAY_INSERT
);
13968 /* Reset the thread number of this breakpoint:
13970 - If the breakpoint is for all threads, leave it as-is.
13971 - Else, reset it to the current thread for inferior_ptid. */
13973 breakpoint_re_set_thread (struct breakpoint
*b
)
13975 if (b
->thread
!= -1)
13977 b
->thread
= inferior_thread ()->global_num
;
13979 /* We're being called after following a fork. The new fork is
13980 selected as current, and unless this was a vfork will have a
13981 different program space from the original thread. Reset that
13983 b
->loc
->pspace
= current_program_space
;
13987 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13988 If from_tty is nonzero, it prints a message to that effect,
13989 which ends with a period (no newline). */
13992 set_ignore_count (int bptnum
, int count
, int from_tty
)
13994 struct breakpoint
*b
;
13999 ALL_BREAKPOINTS (b
)
14000 if (b
->number
== bptnum
)
14002 if (is_tracepoint (b
))
14004 if (from_tty
&& count
!= 0)
14005 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14010 b
->ignore_count
= count
;
14014 printf_filtered (_("Will stop next time "
14015 "breakpoint %d is reached."),
14017 else if (count
== 1)
14018 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14021 printf_filtered (_("Will ignore next %d "
14022 "crossings of breakpoint %d."),
14025 gdb::observers::breakpoint_modified
.notify (b
);
14029 error (_("No breakpoint number %d."), bptnum
);
14032 /* Command to set ignore-count of breakpoint N to COUNT. */
14035 ignore_command (const char *args
, int from_tty
)
14037 const char *p
= args
;
14041 error_no_arg (_("a breakpoint number"));
14043 num
= get_number (&p
);
14045 error (_("bad breakpoint number: '%s'"), args
);
14047 error (_("Second argument (specified ignore-count) is missing."));
14049 set_ignore_count (num
,
14050 longest_to_int (value_as_long (parse_and_eval (p
))),
14053 printf_filtered ("\n");
14057 /* Call FUNCTION on each of the breakpoints with numbers in the range
14058 defined by BP_NUM_RANGE (an inclusive range). */
14061 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
14062 gdb::function_view
<void (breakpoint
*)> function
)
14064 if (bp_num_range
.first
== 0)
14066 warning (_("bad breakpoint number at or near '%d'"),
14067 bp_num_range
.first
);
14071 struct breakpoint
*b
, *tmp
;
14073 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
14075 bool match
= false;
14077 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14078 if (b
->number
== i
)
14085 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
14090 /* Call FUNCTION on each of the breakpoints whose numbers are given in
14094 map_breakpoint_numbers (const char *args
,
14095 gdb::function_view
<void (breakpoint
*)> function
)
14097 if (args
== NULL
|| *args
== '\0')
14098 error_no_arg (_("one or more breakpoint numbers"));
14100 number_or_range_parser
parser (args
);
14102 while (!parser
.finished ())
14104 int num
= parser
.get_number ();
14105 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
14109 /* Return the breakpoint location structure corresponding to the
14110 BP_NUM and LOC_NUM values. */
14112 static struct bp_location
*
14113 find_location_by_number (int bp_num
, int loc_num
)
14115 struct breakpoint
*b
;
14117 ALL_BREAKPOINTS (b
)
14118 if (b
->number
== bp_num
)
14123 if (!b
|| b
->number
!= bp_num
)
14124 error (_("Bad breakpoint number '%d'"), bp_num
);
14127 error (_("Bad breakpoint location number '%d'"), loc_num
);
14130 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
14131 if (++n
== loc_num
)
14134 error (_("Bad breakpoint location number '%d'"), loc_num
);
14137 /* Modes of operation for extract_bp_num. */
14138 enum class extract_bp_kind
14140 /* Extracting a breakpoint number. */
14143 /* Extracting a location number. */
14147 /* Extract a breakpoint or location number (as determined by KIND)
14148 from the string starting at START. TRAILER is a character which
14149 can be found after the number. If you don't want a trailer, use
14150 '\0'. If END_OUT is not NULL, it is set to point after the parsed
14151 string. This always returns a positive integer. */
14154 extract_bp_num (extract_bp_kind kind
, const char *start
,
14155 int trailer
, const char **end_out
= NULL
)
14157 const char *end
= start
;
14158 int num
= get_number_trailer (&end
, trailer
);
14160 error (kind
== extract_bp_kind::bp
14161 ? _("Negative breakpoint number '%.*s'")
14162 : _("Negative breakpoint location number '%.*s'"),
14163 int (end
- start
), start
);
14165 error (kind
== extract_bp_kind::bp
14166 ? _("Bad breakpoint number '%.*s'")
14167 : _("Bad breakpoint location number '%.*s'"),
14168 int (end
- start
), start
);
14170 if (end_out
!= NULL
)
14175 /* Extract a breakpoint or location range (as determined by KIND) in
14176 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14177 representing the (inclusive) range. The returned pair's elements
14178 are always positive integers. */
14180 static std::pair
<int, int>
14181 extract_bp_or_bp_range (extract_bp_kind kind
,
14182 const std::string
&arg
,
14183 std::string::size_type arg_offset
)
14185 std::pair
<int, int> range
;
14186 const char *bp_loc
= &arg
[arg_offset
];
14187 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14188 if (dash
!= std::string::npos
)
14190 /* bp_loc is a range (x-z). */
14191 if (arg
.length () == dash
+ 1)
14192 error (kind
== extract_bp_kind::bp
14193 ? _("Bad breakpoint number at or near: '%s'")
14194 : _("Bad breakpoint location number at or near: '%s'"),
14198 const char *start_first
= bp_loc
;
14199 const char *start_second
= &arg
[dash
+ 1];
14200 range
.first
= extract_bp_num (kind
, start_first
, '-');
14201 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14203 if (range
.first
> range
.second
)
14204 error (kind
== extract_bp_kind::bp
14205 ? _("Inverted breakpoint range at '%.*s'")
14206 : _("Inverted breakpoint location range at '%.*s'"),
14207 int (end
- start_first
), start_first
);
14211 /* bp_loc is a single value. */
14212 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14213 range
.second
= range
.first
;
14218 /* Extract the breakpoint/location range specified by ARG. Returns
14219 the breakpoint range in BP_NUM_RANGE, and the location range in
14222 ARG may be in any of the following forms:
14224 x where 'x' is a breakpoint number.
14225 x-y where 'x' and 'y' specify a breakpoint numbers range.
14226 x.y where 'x' is a breakpoint number and 'y' a location number.
14227 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14228 location number range.
14232 extract_bp_number_and_location (const std::string
&arg
,
14233 std::pair
<int, int> &bp_num_range
,
14234 std::pair
<int, int> &bp_loc_range
)
14236 std::string::size_type dot
= arg
.find ('.');
14238 if (dot
!= std::string::npos
)
14240 /* Handle 'x.y' and 'x.y-z' cases. */
14242 if (arg
.length () == dot
+ 1 || dot
== 0)
14243 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14246 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14247 bp_num_range
.second
= bp_num_range
.first
;
14249 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14254 /* Handle x and x-y cases. */
14256 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14257 bp_loc_range
.first
= 0;
14258 bp_loc_range
.second
= 0;
14262 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14263 specifies whether to enable or disable. */
14266 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14268 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14271 if (loc
->disabled_by_cond
&& enable
)
14272 error (_("Breakpoint %d's condition is invalid at location %d, "
14273 "cannot enable."), bp_num
, loc_num
);
14275 if (loc
->enabled
!= enable
)
14277 loc
->enabled
= enable
;
14278 mark_breakpoint_location_modified (loc
);
14280 if (target_supports_enable_disable_tracepoint ()
14281 && current_trace_status ()->running
&& loc
->owner
14282 && is_tracepoint (loc
->owner
))
14283 target_disable_tracepoint (loc
);
14285 update_global_location_list (UGLL_DONT_INSERT
);
14287 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14290 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14291 number of the breakpoint, and BP_LOC_RANGE specifies the
14292 (inclusive) range of location numbers of that breakpoint to
14293 enable/disable. ENABLE specifies whether to enable or disable the
14297 enable_disable_breakpoint_location_range (int bp_num
,
14298 std::pair
<int, int> &bp_loc_range
,
14301 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14302 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14305 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14306 If from_tty is nonzero, it prints a message to that effect,
14307 which ends with a period (no newline). */
14310 disable_breakpoint (struct breakpoint
*bpt
)
14312 /* Never disable a watchpoint scope breakpoint; we want to
14313 hit them when we leave scope so we can delete both the
14314 watchpoint and its scope breakpoint at that time. */
14315 if (bpt
->type
== bp_watchpoint_scope
)
14318 bpt
->enable_state
= bp_disabled
;
14320 /* Mark breakpoint locations modified. */
14321 mark_breakpoint_modified (bpt
);
14323 if (target_supports_enable_disable_tracepoint ()
14324 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14326 struct bp_location
*location
;
14328 for (location
= bpt
->loc
; location
; location
= location
->next
)
14329 target_disable_tracepoint (location
);
14332 update_global_location_list (UGLL_DONT_INSERT
);
14334 gdb::observers::breakpoint_modified
.notify (bpt
);
14337 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14338 specified in ARGS. ARGS may be in any of the formats handled by
14339 extract_bp_number_and_location. ENABLE specifies whether to enable
14340 or disable the breakpoints/locations. */
14343 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14347 struct breakpoint
*bpt
;
14349 ALL_BREAKPOINTS (bpt
)
14350 if (user_breakpoint_p (bpt
))
14353 enable_breakpoint (bpt
);
14355 disable_breakpoint (bpt
);
14360 std::string num
= extract_arg (&args
);
14362 while (!num
.empty ())
14364 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14366 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14368 if (bp_loc_range
.first
== bp_loc_range
.second
14369 && bp_loc_range
.first
== 0)
14371 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14372 map_breakpoint_number_range (bp_num_range
,
14374 ? enable_breakpoint
14375 : disable_breakpoint
);
14379 /* Handle breakpoint ids with formats 'x.y' or
14381 enable_disable_breakpoint_location_range
14382 (bp_num_range
.first
, bp_loc_range
, enable
);
14384 num
= extract_arg (&args
);
14389 /* The disable command disables the specified breakpoints/locations
14390 (or all defined breakpoints) so they're no longer effective in
14391 stopping the inferior. ARGS may be in any of the forms defined in
14392 extract_bp_number_and_location. */
14395 disable_command (const char *args
, int from_tty
)
14397 enable_disable_command (args
, from_tty
, false);
14401 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14404 int target_resources_ok
;
14406 if (bpt
->type
== bp_hardware_breakpoint
)
14409 i
= hw_breakpoint_used_count ();
14410 target_resources_ok
=
14411 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14413 if (target_resources_ok
== 0)
14414 error (_("No hardware breakpoint support in the target."));
14415 else if (target_resources_ok
< 0)
14416 error (_("Hardware breakpoints used exceeds limit."));
14419 if (is_watchpoint (bpt
))
14421 /* Initialize it just to avoid a GCC false warning. */
14422 enum enable_state orig_enable_state
= bp_disabled
;
14426 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14428 orig_enable_state
= bpt
->enable_state
;
14429 bpt
->enable_state
= bp_enabled
;
14430 update_watchpoint (w
, 1 /* reparse */);
14432 catch (const gdb_exception
&e
)
14434 bpt
->enable_state
= orig_enable_state
;
14435 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14441 bpt
->enable_state
= bp_enabled
;
14443 /* Mark breakpoint locations modified. */
14444 mark_breakpoint_modified (bpt
);
14446 if (target_supports_enable_disable_tracepoint ()
14447 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14449 struct bp_location
*location
;
14451 for (location
= bpt
->loc
; location
; location
= location
->next
)
14452 target_enable_tracepoint (location
);
14455 bpt
->disposition
= disposition
;
14456 bpt
->enable_count
= count
;
14457 update_global_location_list (UGLL_MAY_INSERT
);
14459 gdb::observers::breakpoint_modified
.notify (bpt
);
14464 enable_breakpoint (struct breakpoint
*bpt
)
14466 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14469 /* The enable command enables the specified breakpoints/locations (or
14470 all defined breakpoints) so they once again become (or continue to
14471 be) effective in stopping the inferior. ARGS may be in any of the
14472 forms defined in extract_bp_number_and_location. */
14475 enable_command (const char *args
, int from_tty
)
14477 enable_disable_command (args
, from_tty
, true);
14481 enable_once_command (const char *args
, int from_tty
)
14483 map_breakpoint_numbers
14484 (args
, [&] (breakpoint
*b
)
14486 iterate_over_related_breakpoints
14487 (b
, [&] (breakpoint
*bpt
)
14489 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14495 enable_count_command (const char *args
, int from_tty
)
14500 error_no_arg (_("hit count"));
14502 count
= get_number (&args
);
14504 map_breakpoint_numbers
14505 (args
, [&] (breakpoint
*b
)
14507 iterate_over_related_breakpoints
14508 (b
, [&] (breakpoint
*bpt
)
14510 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14516 enable_delete_command (const char *args
, int from_tty
)
14518 map_breakpoint_numbers
14519 (args
, [&] (breakpoint
*b
)
14521 iterate_over_related_breakpoints
14522 (b
, [&] (breakpoint
*bpt
)
14524 enable_breakpoint_disp (bpt
, disp_del
, 1);
14529 /* Invalidate last known value of any hardware watchpoint if
14530 the memory which that value represents has been written to by
14534 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14535 CORE_ADDR addr
, ssize_t len
,
14536 const bfd_byte
*data
)
14538 struct breakpoint
*bp
;
14540 ALL_BREAKPOINTS (bp
)
14541 if (bp
->enable_state
== bp_enabled
14542 && bp
->type
== bp_hardware_watchpoint
)
14544 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14546 if (wp
->val_valid
&& wp
->val
!= nullptr)
14548 struct bp_location
*loc
;
14550 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14551 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14552 && loc
->address
+ loc
->length
> addr
14553 && addr
+ len
> loc
->address
)
14556 wp
->val_valid
= false;
14562 /* Create and insert a breakpoint for software single step. */
14565 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14566 const address_space
*aspace
,
14569 struct thread_info
*tp
= inferior_thread ();
14570 struct symtab_and_line sal
;
14571 CORE_ADDR pc
= next_pc
;
14573 if (tp
->control
.single_step_breakpoints
== NULL
)
14575 tp
->control
.single_step_breakpoints
14576 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14579 sal
= find_pc_line (pc
, 0);
14581 sal
.section
= find_pc_overlay (pc
);
14582 sal
.explicit_pc
= 1;
14583 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14585 update_global_location_list (UGLL_INSERT
);
14588 /* Insert single step breakpoints according to the current state. */
14591 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14593 struct regcache
*regcache
= get_current_regcache ();
14594 std::vector
<CORE_ADDR
> next_pcs
;
14596 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14598 if (!next_pcs
.empty ())
14600 struct frame_info
*frame
= get_current_frame ();
14601 const address_space
*aspace
= get_frame_address_space (frame
);
14603 for (CORE_ADDR pc
: next_pcs
)
14604 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14612 /* See breakpoint.h. */
14615 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14616 const address_space
*aspace
,
14619 struct bp_location
*loc
;
14621 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14623 && breakpoint_location_address_match (loc
, aspace
, pc
))
14629 /* Check whether a software single-step breakpoint is inserted at
14633 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14636 struct breakpoint
*bpt
;
14638 ALL_BREAKPOINTS (bpt
)
14640 if (bpt
->type
== bp_single_step
14641 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14647 /* Tracepoint-specific operations. */
14649 /* Set tracepoint count to NUM. */
14651 set_tracepoint_count (int num
)
14653 tracepoint_count
= num
;
14654 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14658 trace_command (const char *arg
, int from_tty
)
14660 event_location_up location
= string_to_event_location (&arg
,
14662 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
14663 (location
.get (), true /* is_tracepoint */);
14665 create_breakpoint (get_current_arch (),
14667 NULL
, 0, arg
, 1 /* parse arg */,
14669 bp_tracepoint
/* type_wanted */,
14670 0 /* Ignore count */,
14671 pending_break_support
,
14675 0 /* internal */, 0);
14679 ftrace_command (const char *arg
, int from_tty
)
14681 event_location_up location
= string_to_event_location (&arg
,
14683 create_breakpoint (get_current_arch (),
14685 NULL
, 0, arg
, 1 /* parse arg */,
14687 bp_fast_tracepoint
/* type_wanted */,
14688 0 /* Ignore count */,
14689 pending_break_support
,
14690 &tracepoint_breakpoint_ops
,
14693 0 /* internal */, 0);
14696 /* strace command implementation. Creates a static tracepoint. */
14699 strace_command (const char *arg
, int from_tty
)
14701 struct breakpoint_ops
*ops
;
14702 event_location_up location
;
14704 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14705 or with a normal static tracepoint. */
14706 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14708 ops
= &strace_marker_breakpoint_ops
;
14709 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14713 ops
= &tracepoint_breakpoint_ops
;
14714 location
= string_to_event_location (&arg
, current_language
);
14717 create_breakpoint (get_current_arch (),
14719 NULL
, 0, arg
, 1 /* parse arg */,
14721 bp_static_tracepoint
/* type_wanted */,
14722 0 /* Ignore count */,
14723 pending_break_support
,
14727 0 /* internal */, 0);
14730 /* Set up a fake reader function that gets command lines from a linked
14731 list that was acquired during tracepoint uploading. */
14733 static struct uploaded_tp
*this_utp
;
14734 static int next_cmd
;
14737 read_uploaded_action (void)
14739 char *rslt
= nullptr;
14741 if (next_cmd
< this_utp
->cmd_strings
.size ())
14743 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14750 /* Given information about a tracepoint as recorded on a target (which
14751 can be either a live system or a trace file), attempt to create an
14752 equivalent GDB tracepoint. This is not a reliable process, since
14753 the target does not necessarily have all the information used when
14754 the tracepoint was originally defined. */
14756 struct tracepoint
*
14757 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14759 const char *addr_str
;
14760 char small_buf
[100];
14761 struct tracepoint
*tp
;
14763 if (utp
->at_string
)
14764 addr_str
= utp
->at_string
.get ();
14767 /* In the absence of a source location, fall back to raw
14768 address. Since there is no way to confirm that the address
14769 means the same thing as when the trace was started, warn the
14771 warning (_("Uploaded tracepoint %d has no "
14772 "source location, using raw address"),
14774 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14775 addr_str
= small_buf
;
14778 /* There's not much we can do with a sequence of bytecodes. */
14779 if (utp
->cond
&& !utp
->cond_string
)
14780 warning (_("Uploaded tracepoint %d condition "
14781 "has no source form, ignoring it"),
14784 event_location_up location
= string_to_event_location (&addr_str
,
14786 if (!create_breakpoint (get_current_arch (),
14788 utp
->cond_string
.get (), -1, addr_str
,
14789 0 /* parse cond/thread */,
14791 utp
->type
/* type_wanted */,
14792 0 /* Ignore count */,
14793 pending_break_support
,
14794 &tracepoint_breakpoint_ops
,
14796 utp
->enabled
/* enabled */,
14798 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14801 /* Get the tracepoint we just created. */
14802 tp
= get_tracepoint (tracepoint_count
);
14803 gdb_assert (tp
!= NULL
);
14807 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14810 trace_pass_command (small_buf
, 0);
14813 /* If we have uploaded versions of the original commands, set up a
14814 special-purpose "reader" function and call the usual command line
14815 reader, then pass the result to the breakpoint command-setting
14817 if (!utp
->cmd_strings
.empty ())
14819 counted_command_line cmd_list
;
14824 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14826 breakpoint_set_commands (tp
, std::move (cmd_list
));
14828 else if (!utp
->actions
.empty ()
14829 || !utp
->step_actions
.empty ())
14830 warning (_("Uploaded tracepoint %d actions "
14831 "have no source form, ignoring them"),
14834 /* Copy any status information that might be available. */
14835 tp
->hit_count
= utp
->hit_count
;
14836 tp
->traceframe_usage
= utp
->traceframe_usage
;
14841 /* Print information on tracepoint number TPNUM_EXP, or all if
14845 info_tracepoints_command (const char *args
, int from_tty
)
14847 struct ui_out
*uiout
= current_uiout
;
14850 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14852 if (num_printed
== 0)
14854 if (args
== NULL
|| *args
== '\0')
14855 uiout
->message ("No tracepoints.\n");
14857 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14860 default_collect_info ();
14863 /* The 'enable trace' command enables tracepoints.
14864 Not supported by all targets. */
14866 enable_trace_command (const char *args
, int from_tty
)
14868 enable_command (args
, from_tty
);
14871 /* The 'disable trace' command disables tracepoints.
14872 Not supported by all targets. */
14874 disable_trace_command (const char *args
, int from_tty
)
14876 disable_command (args
, from_tty
);
14879 /* Remove a tracepoint (or all if no argument). */
14881 delete_trace_command (const char *arg
, int from_tty
)
14883 struct breakpoint
*b
, *b_tmp
;
14889 int breaks_to_delete
= 0;
14891 /* Delete all breakpoints if no argument.
14892 Do not delete internal or call-dummy breakpoints, these
14893 have to be deleted with an explicit breakpoint number
14895 ALL_TRACEPOINTS (b
)
14896 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14898 breaks_to_delete
= 1;
14902 /* Ask user only if there are some breakpoints to delete. */
14904 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14906 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14907 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14908 delete_breakpoint (b
);
14912 map_breakpoint_numbers
14913 (arg
, [&] (breakpoint
*br
)
14915 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14919 /* Helper function for trace_pass_command. */
14922 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14924 tp
->pass_count
= count
;
14925 gdb::observers::breakpoint_modified
.notify (tp
);
14927 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14928 tp
->number
, count
);
14931 /* Set passcount for tracepoint.
14933 First command argument is passcount, second is tracepoint number.
14934 If tracepoint number omitted, apply to most recently defined.
14935 Also accepts special argument "all". */
14938 trace_pass_command (const char *args
, int from_tty
)
14940 struct tracepoint
*t1
;
14943 if (args
== 0 || *args
== 0)
14944 error (_("passcount command requires an "
14945 "argument (count + optional TP num)"));
14947 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14949 args
= skip_spaces (args
);
14950 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14952 struct breakpoint
*b
;
14954 args
+= 3; /* Skip special argument "all". */
14956 error (_("Junk at end of arguments."));
14958 ALL_TRACEPOINTS (b
)
14960 t1
= (struct tracepoint
*) b
;
14961 trace_pass_set_count (t1
, count
, from_tty
);
14964 else if (*args
== '\0')
14966 t1
= get_tracepoint_by_number (&args
, NULL
);
14968 trace_pass_set_count (t1
, count
, from_tty
);
14972 number_or_range_parser
parser (args
);
14973 while (!parser
.finished ())
14975 t1
= get_tracepoint_by_number (&args
, &parser
);
14977 trace_pass_set_count (t1
, count
, from_tty
);
14982 struct tracepoint
*
14983 get_tracepoint (int num
)
14985 struct breakpoint
*t
;
14987 ALL_TRACEPOINTS (t
)
14988 if (t
->number
== num
)
14989 return (struct tracepoint
*) t
;
14994 /* Find the tracepoint with the given target-side number (which may be
14995 different from the tracepoint number after disconnecting and
14998 struct tracepoint
*
14999 get_tracepoint_by_number_on_target (int num
)
15001 struct breakpoint
*b
;
15003 ALL_TRACEPOINTS (b
)
15005 struct tracepoint
*t
= (struct tracepoint
*) b
;
15007 if (t
->number_on_target
== num
)
15014 /* Utility: parse a tracepoint number and look it up in the list.
15015 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15016 If the argument is missing, the most recent tracepoint
15017 (tracepoint_count) is returned. */
15019 struct tracepoint
*
15020 get_tracepoint_by_number (const char **arg
,
15021 number_or_range_parser
*parser
)
15023 struct breakpoint
*t
;
15025 const char *instring
= arg
== NULL
? NULL
: *arg
;
15027 if (parser
!= NULL
)
15029 gdb_assert (!parser
->finished ());
15030 tpnum
= parser
->get_number ();
15032 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15033 tpnum
= tracepoint_count
;
15035 tpnum
= get_number (arg
);
15039 if (instring
&& *instring
)
15040 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15043 printf_filtered (_("No previous tracepoint\n"));
15047 ALL_TRACEPOINTS (t
)
15048 if (t
->number
== tpnum
)
15050 return (struct tracepoint
*) t
;
15053 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15058 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15060 if (b
->thread
!= -1)
15061 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15064 fprintf_unfiltered (fp
, " task %d", b
->task
);
15066 fprintf_unfiltered (fp
, "\n");
15069 /* Save information on user settable breakpoints (watchpoints, etc) to
15070 a new script file named FILENAME. If FILTER is non-NULL, call it
15071 on each breakpoint and only include the ones for which it returns
15075 save_breakpoints (const char *filename
, int from_tty
,
15076 bool (*filter
) (const struct breakpoint
*))
15078 struct breakpoint
*tp
;
15080 int extra_trace_bits
= 0;
15082 if (filename
== 0 || *filename
== 0)
15083 error (_("Argument required (file name in which to save)"));
15085 /* See if we have anything to save. */
15086 ALL_BREAKPOINTS (tp
)
15088 /* Skip internal and momentary breakpoints. */
15089 if (!user_breakpoint_p (tp
))
15092 /* If we have a filter, only save the breakpoints it accepts. */
15093 if (filter
&& !filter (tp
))
15098 if (is_tracepoint (tp
))
15100 extra_trace_bits
= 1;
15102 /* We can stop searching. */
15109 warning (_("Nothing to save."));
15113 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15117 if (!fp
.open (expanded_filename
.get (), "w"))
15118 error (_("Unable to open file '%s' for saving (%s)"),
15119 expanded_filename
.get (), safe_strerror (errno
));
15121 if (extra_trace_bits
)
15122 save_trace_state_variables (&fp
);
15124 ALL_BREAKPOINTS (tp
)
15126 /* Skip internal and momentary breakpoints. */
15127 if (!user_breakpoint_p (tp
))
15130 /* If we have a filter, only save the breakpoints it accepts. */
15131 if (filter
&& !filter (tp
))
15134 tp
->ops
->print_recreate (tp
, &fp
);
15136 /* Note, we can't rely on tp->number for anything, as we can't
15137 assume the recreated breakpoint numbers will match. Use $bpnum
15140 if (tp
->cond_string
)
15141 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15143 if (tp
->ignore_count
)
15144 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15146 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15148 fp
.puts (" commands\n");
15150 current_uiout
->redirect (&fp
);
15153 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15155 catch (const gdb_exception
&ex
)
15157 current_uiout
->redirect (NULL
);
15161 current_uiout
->redirect (NULL
);
15162 fp
.puts (" end\n");
15165 if (tp
->enable_state
== bp_disabled
)
15166 fp
.puts ("disable $bpnum\n");
15168 /* If this is a multi-location breakpoint, check if the locations
15169 should be individually disabled. Watchpoint locations are
15170 special, and not user visible. */
15171 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15173 struct bp_location
*loc
;
15176 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15178 fp
.printf ("disable $bpnum.%d\n", n
);
15182 if (extra_trace_bits
&& *default_collect
)
15183 fp
.printf ("set default-collect %s\n", default_collect
);
15186 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15189 /* The `save breakpoints' command. */
15192 save_breakpoints_command (const char *args
, int from_tty
)
15194 save_breakpoints (args
, from_tty
, NULL
);
15197 /* The `save tracepoints' command. */
15200 save_tracepoints_command (const char *args
, int from_tty
)
15202 save_breakpoints (args
, from_tty
, is_tracepoint
);
15205 /* Create a vector of all tracepoints. */
15207 std::vector
<breakpoint
*>
15208 all_tracepoints (void)
15210 std::vector
<breakpoint
*> tp_vec
;
15211 struct breakpoint
*tp
;
15213 ALL_TRACEPOINTS (tp
)
15215 tp_vec
.push_back (tp
);
15222 /* This help string is used to consolidate all the help string for specifying
15223 locations used by several commands. */
15225 #define LOCATION_HELP_STRING \
15226 "Linespecs are colon-separated lists of location parameters, such as\n\
15227 source filename, function name, label name, and line number.\n\
15228 Example: To specify the start of a label named \"the_top\" in the\n\
15229 function \"fact\" in the file \"factorial.c\", use\n\
15230 \"factorial.c:fact:the_top\".\n\
15232 Address locations begin with \"*\" and specify an exact address in the\n\
15233 program. Example: To specify the fourth byte past the start function\n\
15234 \"main\", use \"*main + 4\".\n\
15236 Explicit locations are similar to linespecs but use an option/argument\n\
15237 syntax to specify location parameters.\n\
15238 Example: To specify the start of the label named \"the_top\" in the\n\
15239 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15240 -function fact -label the_top\".\n\
15242 By default, a specified function is matched against the program's\n\
15243 functions in all scopes. For C++, this means in all namespaces and\n\
15244 classes. For Ada, this means in all packages. E.g., in C++,\n\
15245 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15246 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15247 specified name as a complete fully-qualified name instead."
15249 /* This help string is used for the break, hbreak, tbreak and thbreak
15250 commands. It is defined as a macro to prevent duplication.
15251 COMMAND should be a string constant containing the name of the
15254 #define BREAK_ARGS_HELP(command) \
15255 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15256 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15257 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15258 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15259 `-probe-dtrace' (for a DTrace probe).\n\
15260 LOCATION may be a linespec, address, or explicit location as described\n\
15263 With no LOCATION, uses current execution address of the selected\n\
15264 stack frame. This is useful for breaking on return to a stack frame.\n\
15266 THREADNUM is the number from \"info threads\".\n\
15267 CONDITION is a boolean expression.\n\
15268 \n" LOCATION_HELP_STRING "\n\n\
15269 Multiple breakpoints at one place are permitted, and useful if their\n\
15270 conditions are different.\n\
15272 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15274 /* List of subcommands for "catch". */
15275 static struct cmd_list_element
*catch_cmdlist
;
15277 /* List of subcommands for "tcatch". */
15278 static struct cmd_list_element
*tcatch_cmdlist
;
15281 add_catch_command (const char *name
, const char *docstring
,
15282 cmd_const_sfunc_ftype
*sfunc
,
15283 completer_ftype
*completer
,
15284 void *user_data_catch
,
15285 void *user_data_tcatch
)
15287 struct cmd_list_element
*command
;
15289 command
= add_cmd (name
, class_breakpoint
, docstring
,
15291 set_cmd_sfunc (command
, sfunc
);
15292 set_cmd_context (command
, user_data_catch
);
15293 set_cmd_completer (command
, completer
);
15295 command
= add_cmd (name
, class_breakpoint
, docstring
,
15297 set_cmd_sfunc (command
, sfunc
);
15298 set_cmd_context (command
, user_data_tcatch
);
15299 set_cmd_completer (command
, completer
);
15302 struct breakpoint
*
15303 iterate_over_breakpoints (gdb::function_view
<bool (breakpoint
*)> callback
)
15305 struct breakpoint
*b
, *b_tmp
;
15307 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15316 /* Zero if any of the breakpoint's locations could be a location where
15317 functions have been inlined, nonzero otherwise. */
15320 is_non_inline_function (struct breakpoint
*b
)
15322 /* The shared library event breakpoint is set on the address of a
15323 non-inline function. */
15324 if (b
->type
== bp_shlib_event
)
15330 /* Nonzero if the specified PC cannot be a location where functions
15331 have been inlined. */
15334 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15335 const struct target_waitstatus
*ws
)
15337 struct breakpoint
*b
;
15338 struct bp_location
*bl
;
15340 ALL_BREAKPOINTS (b
)
15342 if (!is_non_inline_function (b
))
15345 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15347 if (!bl
->shlib_disabled
15348 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15356 /* Remove any references to OBJFILE which is going to be freed. */
15359 breakpoint_free_objfile (struct objfile
*objfile
)
15361 struct bp_location
**locp
, *loc
;
15363 ALL_BP_LOCATIONS (loc
, locp
)
15364 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15365 loc
->symtab
= NULL
;
15369 initialize_breakpoint_ops (void)
15371 static int initialized
= 0;
15373 struct breakpoint_ops
*ops
;
15379 /* The breakpoint_ops structure to be inherit by all kinds of
15380 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15381 internal and momentary breakpoints, etc.). */
15382 ops
= &bkpt_base_breakpoint_ops
;
15383 *ops
= base_breakpoint_ops
;
15384 ops
->re_set
= bkpt_re_set
;
15385 ops
->insert_location
= bkpt_insert_location
;
15386 ops
->remove_location
= bkpt_remove_location
;
15387 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15388 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15389 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15390 ops
->decode_location
= bkpt_decode_location
;
15392 /* The breakpoint_ops structure to be used in regular breakpoints. */
15393 ops
= &bkpt_breakpoint_ops
;
15394 *ops
= bkpt_base_breakpoint_ops
;
15395 ops
->re_set
= bkpt_re_set
;
15396 ops
->resources_needed
= bkpt_resources_needed
;
15397 ops
->print_it
= bkpt_print_it
;
15398 ops
->print_mention
= bkpt_print_mention
;
15399 ops
->print_recreate
= bkpt_print_recreate
;
15401 /* Ranged breakpoints. */
15402 ops
= &ranged_breakpoint_ops
;
15403 *ops
= bkpt_breakpoint_ops
;
15404 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15405 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15406 ops
->print_it
= print_it_ranged_breakpoint
;
15407 ops
->print_one
= print_one_ranged_breakpoint
;
15408 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15409 ops
->print_mention
= print_mention_ranged_breakpoint
;
15410 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15412 /* Internal breakpoints. */
15413 ops
= &internal_breakpoint_ops
;
15414 *ops
= bkpt_base_breakpoint_ops
;
15415 ops
->re_set
= internal_bkpt_re_set
;
15416 ops
->check_status
= internal_bkpt_check_status
;
15417 ops
->print_it
= internal_bkpt_print_it
;
15418 ops
->print_mention
= internal_bkpt_print_mention
;
15420 /* Momentary breakpoints. */
15421 ops
= &momentary_breakpoint_ops
;
15422 *ops
= bkpt_base_breakpoint_ops
;
15423 ops
->re_set
= momentary_bkpt_re_set
;
15424 ops
->check_status
= momentary_bkpt_check_status
;
15425 ops
->print_it
= momentary_bkpt_print_it
;
15426 ops
->print_mention
= momentary_bkpt_print_mention
;
15428 /* Probe breakpoints. */
15429 ops
= &bkpt_probe_breakpoint_ops
;
15430 *ops
= bkpt_breakpoint_ops
;
15431 ops
->insert_location
= bkpt_probe_insert_location
;
15432 ops
->remove_location
= bkpt_probe_remove_location
;
15433 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15434 ops
->decode_location
= bkpt_probe_decode_location
;
15437 ops
= &watchpoint_breakpoint_ops
;
15438 *ops
= base_breakpoint_ops
;
15439 ops
->re_set
= re_set_watchpoint
;
15440 ops
->insert_location
= insert_watchpoint
;
15441 ops
->remove_location
= remove_watchpoint
;
15442 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15443 ops
->check_status
= check_status_watchpoint
;
15444 ops
->resources_needed
= resources_needed_watchpoint
;
15445 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15446 ops
->print_it
= print_it_watchpoint
;
15447 ops
->print_mention
= print_mention_watchpoint
;
15448 ops
->print_recreate
= print_recreate_watchpoint
;
15449 ops
->explains_signal
= explains_signal_watchpoint
;
15451 /* Masked watchpoints. */
15452 ops
= &masked_watchpoint_breakpoint_ops
;
15453 *ops
= watchpoint_breakpoint_ops
;
15454 ops
->insert_location
= insert_masked_watchpoint
;
15455 ops
->remove_location
= remove_masked_watchpoint
;
15456 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15457 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15458 ops
->print_it
= print_it_masked_watchpoint
;
15459 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15460 ops
->print_mention
= print_mention_masked_watchpoint
;
15461 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15464 ops
= &tracepoint_breakpoint_ops
;
15465 *ops
= base_breakpoint_ops
;
15466 ops
->re_set
= tracepoint_re_set
;
15467 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15468 ops
->print_one_detail
= tracepoint_print_one_detail
;
15469 ops
->print_mention
= tracepoint_print_mention
;
15470 ops
->print_recreate
= tracepoint_print_recreate
;
15471 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15472 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15473 ops
->decode_location
= tracepoint_decode_location
;
15475 /* Probe tracepoints. */
15476 ops
= &tracepoint_probe_breakpoint_ops
;
15477 *ops
= tracepoint_breakpoint_ops
;
15478 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15479 ops
->decode_location
= tracepoint_probe_decode_location
;
15481 /* Static tracepoints with marker (`-m'). */
15482 ops
= &strace_marker_breakpoint_ops
;
15483 *ops
= tracepoint_breakpoint_ops
;
15484 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15485 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15486 ops
->decode_location
= strace_marker_decode_location
;
15488 /* Fork catchpoints. */
15489 ops
= &catch_fork_breakpoint_ops
;
15490 *ops
= base_breakpoint_ops
;
15491 ops
->insert_location
= insert_catch_fork
;
15492 ops
->remove_location
= remove_catch_fork
;
15493 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15494 ops
->print_it
= print_it_catch_fork
;
15495 ops
->print_one
= print_one_catch_fork
;
15496 ops
->print_mention
= print_mention_catch_fork
;
15497 ops
->print_recreate
= print_recreate_catch_fork
;
15499 /* Vfork catchpoints. */
15500 ops
= &catch_vfork_breakpoint_ops
;
15501 *ops
= base_breakpoint_ops
;
15502 ops
->insert_location
= insert_catch_vfork
;
15503 ops
->remove_location
= remove_catch_vfork
;
15504 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15505 ops
->print_it
= print_it_catch_vfork
;
15506 ops
->print_one
= print_one_catch_vfork
;
15507 ops
->print_mention
= print_mention_catch_vfork
;
15508 ops
->print_recreate
= print_recreate_catch_vfork
;
15510 /* Exec catchpoints. */
15511 ops
= &catch_exec_breakpoint_ops
;
15512 *ops
= base_breakpoint_ops
;
15513 ops
->insert_location
= insert_catch_exec
;
15514 ops
->remove_location
= remove_catch_exec
;
15515 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15516 ops
->print_it
= print_it_catch_exec
;
15517 ops
->print_one
= print_one_catch_exec
;
15518 ops
->print_mention
= print_mention_catch_exec
;
15519 ops
->print_recreate
= print_recreate_catch_exec
;
15521 /* Solib-related catchpoints. */
15522 ops
= &catch_solib_breakpoint_ops
;
15523 *ops
= base_breakpoint_ops
;
15524 ops
->insert_location
= insert_catch_solib
;
15525 ops
->remove_location
= remove_catch_solib
;
15526 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15527 ops
->check_status
= check_status_catch_solib
;
15528 ops
->print_it
= print_it_catch_solib
;
15529 ops
->print_one
= print_one_catch_solib
;
15530 ops
->print_mention
= print_mention_catch_solib
;
15531 ops
->print_recreate
= print_recreate_catch_solib
;
15533 ops
= &dprintf_breakpoint_ops
;
15534 *ops
= bkpt_base_breakpoint_ops
;
15535 ops
->re_set
= dprintf_re_set
;
15536 ops
->resources_needed
= bkpt_resources_needed
;
15537 ops
->print_it
= bkpt_print_it
;
15538 ops
->print_mention
= bkpt_print_mention
;
15539 ops
->print_recreate
= dprintf_print_recreate
;
15540 ops
->after_condition_true
= dprintf_after_condition_true
;
15541 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15544 /* Chain containing all defined "enable breakpoint" subcommands. */
15546 static struct cmd_list_element
*enablebreaklist
= NULL
;
15548 /* See breakpoint.h. */
15550 cmd_list_element
*commands_cmd_element
= nullptr;
15552 void _initialize_breakpoint ();
15554 _initialize_breakpoint ()
15556 struct cmd_list_element
*c
;
15558 initialize_breakpoint_ops ();
15560 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
);
15561 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
);
15562 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
);
15564 breakpoint_chain
= 0;
15565 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15566 before a breakpoint is set. */
15567 breakpoint_count
= 0;
15569 tracepoint_count
= 0;
15571 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15572 Set ignore-count of breakpoint number N to COUNT.\n\
15573 Usage is `ignore N COUNT'."));
15575 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15576 commands_command
, _("\
15577 Set commands to be executed when the given breakpoints are hit.\n\
15578 Give a space-separated breakpoint list as argument after \"commands\".\n\
15579 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15581 With no argument, the targeted breakpoint is the last one set.\n\
15582 The commands themselves follow starting on the next line.\n\
15583 Type a line containing \"end\" to indicate the end of them.\n\
15584 Give \"silent\" as the first line to make the breakpoint silent;\n\
15585 then no output is printed when it is hit, except what the commands print."));
15587 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15588 Specify breakpoint number N to break only if COND is true.\n\
15589 Usage is `condition N COND', where N is an integer and COND is an\n\
15590 expression to be evaluated whenever breakpoint N is reached."));
15591 set_cmd_completer (c
, condition_completer
);
15593 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15594 Set a temporary breakpoint.\n\
15595 Like \"break\" except the breakpoint is only temporary,\n\
15596 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15597 by using \"enable delete\" on the breakpoint number.\n\
15599 BREAK_ARGS_HELP ("tbreak")));
15600 set_cmd_completer (c
, location_completer
);
15602 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15603 Set a hardware assisted breakpoint.\n\
15604 Like \"break\" except the breakpoint requires hardware support,\n\
15605 some target hardware may not have this support.\n\
15607 BREAK_ARGS_HELP ("hbreak")));
15608 set_cmd_completer (c
, location_completer
);
15610 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15611 Set a temporary hardware assisted breakpoint.\n\
15612 Like \"hbreak\" except the breakpoint is only temporary,\n\
15613 so it will be deleted when hit.\n\
15615 BREAK_ARGS_HELP ("thbreak")));
15616 set_cmd_completer (c
, location_completer
);
15618 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15619 Enable all or some breakpoints.\n\
15620 Usage: enable [BREAKPOINTNUM]...\n\
15621 Give breakpoint numbers (separated by spaces) as arguments.\n\
15622 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15623 This is used to cancel the effect of the \"disable\" command.\n\
15624 With a subcommand you can enable temporarily."),
15625 &enablelist
, "enable ", 1, &cmdlist
);
15627 add_com_alias ("en", "enable", class_breakpoint
, 1);
15629 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15630 Enable all or some breakpoints.\n\
15631 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15632 Give breakpoint numbers (separated by spaces) as arguments.\n\
15633 This is used to cancel the effect of the \"disable\" command.\n\
15634 May be abbreviated to simply \"enable\"."),
15635 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15637 add_cmd ("once", no_class
, enable_once_command
, _("\
15638 Enable some breakpoints for one hit.\n\
15639 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15640 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15643 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15644 Enable some breakpoints and delete when hit.\n\
15645 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15646 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15649 add_cmd ("count", no_class
, enable_count_command
, _("\
15650 Enable some breakpoints for COUNT hits.\n\
15651 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15652 If a breakpoint is hit while enabled in this fashion,\n\
15653 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15656 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15657 Enable some breakpoints and delete when hit.\n\
15658 Usage: enable delete BREAKPOINTNUM...\n\
15659 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15662 add_cmd ("once", no_class
, enable_once_command
, _("\
15663 Enable some breakpoints for one hit.\n\
15664 Usage: enable once BREAKPOINTNUM...\n\
15665 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15668 add_cmd ("count", no_class
, enable_count_command
, _("\
15669 Enable some breakpoints for COUNT hits.\n\
15670 Usage: enable count COUNT BREAKPOINTNUM...\n\
15671 If a breakpoint is hit while enabled in this fashion,\n\
15672 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15675 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15676 Disable all or some breakpoints.\n\
15677 Usage: disable [BREAKPOINTNUM]...\n\
15678 Arguments are breakpoint numbers with spaces in between.\n\
15679 To disable all breakpoints, give no argument.\n\
15680 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15681 &disablelist
, "disable ", 1, &cmdlist
);
15682 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15683 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15685 add_cmd ("breakpoints", class_breakpoint
, disable_command
, _("\
15686 Disable all or some breakpoints.\n\
15687 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15688 Arguments are breakpoint numbers with spaces in between.\n\
15689 To disable all breakpoints, give no argument.\n\
15690 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15691 This command may be abbreviated \"disable\"."),
15694 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15695 Delete all or some breakpoints.\n\
15696 Usage: delete [BREAKPOINTNUM]...\n\
15697 Arguments are breakpoint numbers with spaces in between.\n\
15698 To delete all breakpoints, give no argument.\n\
15700 Also a prefix command for deletion of other GDB objects."),
15701 &deletelist
, "delete ", 1, &cmdlist
);
15702 add_com_alias ("d", "delete", class_breakpoint
, 1);
15703 add_com_alias ("del", "delete", class_breakpoint
, 1);
15705 add_cmd ("breakpoints", class_breakpoint
, delete_command
, _("\
15706 Delete all or some breakpoints or auto-display expressions.\n\
15707 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15708 Arguments are breakpoint numbers with spaces in between.\n\
15709 To delete all breakpoints, give no argument.\n\
15710 This command may be abbreviated \"delete\"."),
15713 add_com ("clear", class_breakpoint
, clear_command
, _("\
15714 Clear breakpoint at specified location.\n\
15715 Argument may be a linespec, explicit, or address location as described below.\n\
15717 With no argument, clears all breakpoints in the line that the selected frame\n\
15718 is executing in.\n"
15719 "\n" LOCATION_HELP_STRING
"\n\n\
15720 See also the \"delete\" command which clears breakpoints by number."));
15721 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15723 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15724 Set breakpoint at specified location.\n"
15725 BREAK_ARGS_HELP ("break")));
15726 set_cmd_completer (c
, location_completer
);
15728 add_com_alias ("b", "break", class_run
, 1);
15729 add_com_alias ("br", "break", class_run
, 1);
15730 add_com_alias ("bre", "break", class_run
, 1);
15731 add_com_alias ("brea", "break", class_run
, 1);
15735 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15736 Break in function/address or break at a line in the current file."),
15737 &stoplist
, "stop ", 1, &cmdlist
);
15738 add_cmd ("in", class_breakpoint
, stopin_command
,
15739 _("Break in function or address."), &stoplist
);
15740 add_cmd ("at", class_breakpoint
, stopat_command
,
15741 _("Break at a line in the current file."), &stoplist
);
15742 add_com ("status", class_info
, info_breakpoints_command
, _("\
15743 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15744 The \"Type\" column indicates one of:\n\
15745 \tbreakpoint - normal breakpoint\n\
15746 \twatchpoint - watchpoint\n\
15747 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15748 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15749 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15750 address and file/line number respectively.\n\
15752 Convenience variable \"$_\" and default examine address for \"x\"\n\
15753 are set to the address of the last breakpoint listed unless the command\n\
15754 is prefixed with \"server \".\n\n\
15755 Convenience variable \"$bpnum\" contains the number of the last\n\
15756 breakpoint set."));
15759 add_info ("breakpoints", info_breakpoints_command
, _("\
15760 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15761 The \"Type\" column indicates one of:\n\
15762 \tbreakpoint - normal breakpoint\n\
15763 \twatchpoint - watchpoint\n\
15764 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15765 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15766 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15767 address and file/line number respectively.\n\
15769 Convenience variable \"$_\" and default examine address for \"x\"\n\
15770 are set to the address of the last breakpoint listed unless the command\n\
15771 is prefixed with \"server \".\n\n\
15772 Convenience variable \"$bpnum\" contains the number of the last\n\
15773 breakpoint set."));
15775 add_info_alias ("b", "breakpoints", 1);
15777 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15778 Status of all breakpoints, or breakpoint number NUMBER.\n\
15779 The \"Type\" column indicates one of:\n\
15780 \tbreakpoint - normal breakpoint\n\
15781 \twatchpoint - watchpoint\n\
15782 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15783 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15784 \tuntil - internal breakpoint used by the \"until\" command\n\
15785 \tfinish - internal breakpoint used by the \"finish\" command\n\
15786 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15787 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15788 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15789 address and file/line number respectively.\n\
15791 Convenience variable \"$_\" and default examine address for \"x\"\n\
15792 are set to the address of the last breakpoint listed unless the command\n\
15793 is prefixed with \"server \".\n\n\
15794 Convenience variable \"$bpnum\" contains the number of the last\n\
15796 &maintenanceinfolist
);
15798 add_basic_prefix_cmd ("catch", class_breakpoint
, _("\
15799 Set catchpoints to catch events."),
15800 &catch_cmdlist
, "catch ",
15801 0/*allow-unknown*/, &cmdlist
);
15803 add_basic_prefix_cmd ("tcatch", class_breakpoint
, _("\
15804 Set temporary catchpoints to catch events."),
15805 &tcatch_cmdlist
, "tcatch ",
15806 0/*allow-unknown*/, &cmdlist
);
15808 add_catch_command ("fork", _("Catch calls to fork."),
15809 catch_fork_command_1
,
15811 (void *) (uintptr_t) catch_fork_permanent
,
15812 (void *) (uintptr_t) catch_fork_temporary
);
15813 add_catch_command ("vfork", _("Catch calls to vfork."),
15814 catch_fork_command_1
,
15816 (void *) (uintptr_t) catch_vfork_permanent
,
15817 (void *) (uintptr_t) catch_vfork_temporary
);
15818 add_catch_command ("exec", _("Catch calls to exec."),
15819 catch_exec_command_1
,
15823 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15824 Usage: catch load [REGEX]\n\
15825 If REGEX is given, only stop for libraries matching the regular expression."),
15826 catch_load_command_1
,
15830 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15831 Usage: catch unload [REGEX]\n\
15832 If REGEX is given, only stop for libraries matching the regular expression."),
15833 catch_unload_command_1
,
15838 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15839 Set a watchpoint for an expression.\n\
15840 Usage: watch [-l|-location] EXPRESSION\n\
15841 A watchpoint stops execution of your program whenever the value of\n\
15842 an expression changes.\n\
15843 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15844 the memory to which it refers."));
15845 set_cmd_completer (c
, expression_completer
);
15847 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15848 Set a read watchpoint for an expression.\n\
15849 Usage: rwatch [-l|-location] EXPRESSION\n\
15850 A watchpoint stops execution of your program whenever the value of\n\
15851 an expression is read.\n\
15852 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15853 the memory to which it refers."));
15854 set_cmd_completer (c
, expression_completer
);
15856 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15857 Set a watchpoint for an expression.\n\
15858 Usage: awatch [-l|-location] EXPRESSION\n\
15859 A watchpoint stops execution of your program whenever the value of\n\
15860 an expression is either read or written.\n\
15861 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15862 the memory to which it refers."));
15863 set_cmd_completer (c
, expression_completer
);
15865 add_info ("watchpoints", info_watchpoints_command
, _("\
15866 Status of specified watchpoints (all watchpoints if no argument)."));
15868 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15869 respond to changes - contrary to the description. */
15870 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15871 &can_use_hw_watchpoints
, _("\
15872 Set debugger's willingness to use watchpoint hardware."), _("\
15873 Show debugger's willingness to use watchpoint hardware."), _("\
15874 If zero, gdb will not use hardware for new watchpoints, even if\n\
15875 such is available. (However, any hardware watchpoints that were\n\
15876 created before setting this to nonzero, will continue to use watchpoint\n\
15879 show_can_use_hw_watchpoints
,
15880 &setlist
, &showlist
);
15882 can_use_hw_watchpoints
= 1;
15884 /* Tracepoint manipulation commands. */
15886 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15887 Set a tracepoint at specified location.\n\
15889 BREAK_ARGS_HELP ("trace") "\n\
15890 Do \"help tracepoints\" for info on other tracepoint commands."));
15891 set_cmd_completer (c
, location_completer
);
15893 add_com_alias ("tp", "trace", class_breakpoint
, 0);
15894 add_com_alias ("tr", "trace", class_breakpoint
, 1);
15895 add_com_alias ("tra", "trace", class_breakpoint
, 1);
15896 add_com_alias ("trac", "trace", class_breakpoint
, 1);
15898 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15899 Set a fast tracepoint at specified location.\n\
15901 BREAK_ARGS_HELP ("ftrace") "\n\
15902 Do \"help tracepoints\" for info on other tracepoint commands."));
15903 set_cmd_completer (c
, location_completer
);
15905 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15906 Set a static tracepoint at location or marker.\n\
15908 strace [LOCATION] [if CONDITION]\n\
15909 LOCATION may be a linespec, explicit, or address location (described below) \n\
15910 or -m MARKER_ID.\n\n\
15911 If a marker id is specified, probe the marker with that name. With\n\
15912 no LOCATION, uses current execution address of the selected stack frame.\n\
15913 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15914 This collects arbitrary user data passed in the probe point call to the\n\
15915 tracing library. You can inspect it when analyzing the trace buffer,\n\
15916 by printing the $_sdata variable like any other convenience variable.\n\
15918 CONDITION is a boolean expression.\n\
15919 \n" LOCATION_HELP_STRING
"\n\n\
15920 Multiple tracepoints at one place are permitted, and useful if their\n\
15921 conditions are different.\n\
15923 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15924 Do \"help tracepoints\" for info on other tracepoint commands."));
15925 set_cmd_completer (c
, location_completer
);
15927 add_info ("tracepoints", info_tracepoints_command
, _("\
15928 Status of specified tracepoints (all tracepoints if no argument).\n\
15929 Convenience variable \"$tpnum\" contains the number of the\n\
15930 last tracepoint set."));
15932 add_info_alias ("tp", "tracepoints", 1);
15934 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15935 Delete specified tracepoints.\n\
15936 Arguments are tracepoint numbers, separated by spaces.\n\
15937 No argument means delete all tracepoints."),
15939 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
15941 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15942 Disable specified tracepoints.\n\
15943 Arguments are tracepoint numbers, separated by spaces.\n\
15944 No argument means disable all tracepoints."),
15946 deprecate_cmd (c
, "disable");
15948 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15949 Enable specified tracepoints.\n\
15950 Arguments are tracepoint numbers, separated by spaces.\n\
15951 No argument means enable all tracepoints."),
15953 deprecate_cmd (c
, "enable");
15955 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15956 Set the passcount for a tracepoint.\n\
15957 The trace will end when the tracepoint has been passed 'count' times.\n\
15958 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15959 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15961 add_basic_prefix_cmd ("save", class_breakpoint
,
15962 _("Save breakpoint definitions as a script."),
15963 &save_cmdlist
, "save ",
15964 0/*allow-unknown*/, &cmdlist
);
15966 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15967 Save current breakpoint definitions as a script.\n\
15968 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15969 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15970 session to restore them."),
15972 set_cmd_completer (c
, filename_completer
);
15974 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15975 Save current tracepoint definitions as a script.\n\
15976 Use the 'source' command in another debug session to restore them."),
15978 set_cmd_completer (c
, filename_completer
);
15980 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
15981 deprecate_cmd (c
, "save tracepoints");
15983 add_basic_prefix_cmd ("breakpoint", class_maintenance
, _("\
15984 Breakpoint specific settings.\n\
15985 Configure various breakpoint-specific variables such as\n\
15986 pending breakpoint behavior."),
15987 &breakpoint_set_cmdlist
, "set breakpoint ",
15988 0/*allow-unknown*/, &setlist
);
15989 add_show_prefix_cmd ("breakpoint", class_maintenance
, _("\
15990 Breakpoint specific settings.\n\
15991 Configure various breakpoint-specific variables such as\n\
15992 pending breakpoint behavior."),
15993 &breakpoint_show_cmdlist
, "show breakpoint ",
15994 0/*allow-unknown*/, &showlist
);
15996 add_setshow_auto_boolean_cmd ("pending", no_class
,
15997 &pending_break_support
, _("\
15998 Set debugger's behavior regarding pending breakpoints."), _("\
15999 Show debugger's behavior regarding pending breakpoints."), _("\
16000 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16001 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16002 an error. If auto, an unrecognized breakpoint location results in a\n\
16003 user-query to see if a pending breakpoint should be created."),
16005 show_pending_break_support
,
16006 &breakpoint_set_cmdlist
,
16007 &breakpoint_show_cmdlist
);
16009 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16011 add_setshow_boolean_cmd ("auto-hw", no_class
,
16012 &automatic_hardware_breakpoints
, _("\
16013 Set automatic usage of hardware breakpoints."), _("\
16014 Show automatic usage of hardware breakpoints."), _("\
16015 If set, the debugger will automatically use hardware breakpoints for\n\
16016 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16017 a warning will be emitted for such breakpoints."),
16019 show_automatic_hardware_breakpoints
,
16020 &breakpoint_set_cmdlist
,
16021 &breakpoint_show_cmdlist
);
16023 add_setshow_boolean_cmd ("always-inserted", class_support
,
16024 &always_inserted_mode
, _("\
16025 Set mode for inserting breakpoints."), _("\
16026 Show mode for inserting breakpoints."), _("\
16027 When this mode is on, breakpoints are inserted immediately as soon as\n\
16028 they're created, kept inserted even when execution stops, and removed\n\
16029 only when the user deletes them. When this mode is off (the default),\n\
16030 breakpoints are inserted only when execution continues, and removed\n\
16031 when execution stops."),
16033 &show_always_inserted_mode
,
16034 &breakpoint_set_cmdlist
,
16035 &breakpoint_show_cmdlist
);
16037 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16038 condition_evaluation_enums
,
16039 &condition_evaluation_mode_1
, _("\
16040 Set mode of breakpoint condition evaluation."), _("\
16041 Show mode of breakpoint condition evaluation."), _("\
16042 When this is set to \"host\", breakpoint conditions will be\n\
16043 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16044 breakpoint conditions will be downloaded to the target (if the target\n\
16045 supports such feature) and conditions will be evaluated on the target's side.\n\
16046 If this is set to \"auto\" (default), this will be automatically set to\n\
16047 \"target\" if it supports condition evaluation, otherwise it will\n\
16048 be set to \"host\"."),
16049 &set_condition_evaluation_mode
,
16050 &show_condition_evaluation_mode
,
16051 &breakpoint_set_cmdlist
,
16052 &breakpoint_show_cmdlist
);
16054 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16055 Set a breakpoint for an address range.\n\
16056 break-range START-LOCATION, END-LOCATION\n\
16057 where START-LOCATION and END-LOCATION can be one of the following:\n\
16058 LINENUM, for that line in the current file,\n\
16059 FILE:LINENUM, for that line in that file,\n\
16060 +OFFSET, for that number of lines after the current line\n\
16061 or the start of the range\n\
16062 FUNCTION, for the first line in that function,\n\
16063 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16064 *ADDRESS, for the instruction at that address.\n\
16066 The breakpoint will stop execution of the inferior whenever it executes\n\
16067 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16068 range (including START-LOCATION and END-LOCATION)."));
16070 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16071 Set a dynamic printf at specified location.\n\
16072 dprintf location,format string,arg1,arg2,...\n\
16073 location may be a linespec, explicit, or address location.\n"
16074 "\n" LOCATION_HELP_STRING
));
16075 set_cmd_completer (c
, location_completer
);
16077 add_setshow_enum_cmd ("dprintf-style", class_support
,
16078 dprintf_style_enums
, &dprintf_style
, _("\
16079 Set the style of usage for dynamic printf."), _("\
16080 Show the style of usage for dynamic printf."), _("\
16081 This setting chooses how GDB will do a dynamic printf.\n\
16082 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16083 console, as with the \"printf\" command.\n\
16084 If the value is \"call\", the print is done by calling a function in your\n\
16085 program; by default printf(), but you can choose a different function or\n\
16086 output stream by setting dprintf-function and dprintf-channel."),
16087 update_dprintf_commands
, NULL
,
16088 &setlist
, &showlist
);
16090 dprintf_function
= xstrdup ("printf");
16091 add_setshow_string_cmd ("dprintf-function", class_support
,
16092 &dprintf_function
, _("\
16093 Set the function to use for dynamic printf."), _("\
16094 Show the function to use for dynamic printf."), NULL
,
16095 update_dprintf_commands
, NULL
,
16096 &setlist
, &showlist
);
16098 dprintf_channel
= xstrdup ("");
16099 add_setshow_string_cmd ("dprintf-channel", class_support
,
16100 &dprintf_channel
, _("\
16101 Set the channel to use for dynamic printf."), _("\
16102 Show the channel to use for dynamic printf."), NULL
,
16103 update_dprintf_commands
, NULL
,
16104 &setlist
, &showlist
);
16106 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16107 &disconnected_dprintf
, _("\
16108 Set whether dprintf continues after GDB disconnects."), _("\
16109 Show whether dprintf continues after GDB disconnects."), _("\
16110 Use this to let dprintf commands continue to hit and produce output\n\
16111 even if GDB disconnects or detaches from the target."),
16114 &setlist
, &showlist
);
16116 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16117 Target agent only formatted printing, like the C \"printf\" function.\n\
16118 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
16119 This supports most C printf format specifications, like %s, %d, etc.\n\
16120 This is useful for formatted output in user-defined commands."));
16122 automatic_hardware_breakpoints
= true;
16124 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
);
16125 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
);