1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
4 Copyright (C) 2019 Advanced Micro Devices, Inc. All rights reserved.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "arch-utils.h"
27 #include "breakpoint.h"
28 #include "tracepoint.h"
30 #include "expression.h"
37 #include "gdbthread.h"
40 #include "gdb-demangle.h"
41 #include "filenames.h"
47 #include "completer.h"
49 #include "cli/cli-script.h"
53 #include "observable.h"
59 #include "parser-defs.h"
60 #include "gdb_regex.h"
62 #include "cli/cli-utils.h"
65 #include "dummy-frame.h"
67 #include "gdbsupport/format.h"
68 #include "thread-fsm.h"
69 #include "tid-parse.h"
70 #include "cli/cli-style.h"
72 /* readline include files */
73 #include "readline/tilde.h"
75 /* readline defines this. */
78 #include "mi/mi-common.h"
79 #include "extension.h"
81 #include "progspace-and-thread.h"
82 #include "gdbsupport/array-view.h"
83 #include "gdbsupport/gdb_optional.h"
85 /* Prototypes for local functions. */
87 static void map_breakpoint_numbers (const char *,
88 gdb::function_view
<void (breakpoint
*)>);
90 static void breakpoint_re_set_default (struct breakpoint
*);
93 create_sals_from_location_default (const struct event_location
*location
,
94 struct linespec_result
*canonical
,
95 enum bptype type_wanted
);
97 static void create_breakpoints_sal_default (struct gdbarch
*,
98 struct linespec_result
*,
99 gdb::unique_xmalloc_ptr
<char>,
100 gdb::unique_xmalloc_ptr
<char>,
102 enum bpdisp
, int, int,
104 const struct breakpoint_ops
*,
105 int, int, int, unsigned);
107 static std::vector
<symtab_and_line
> decode_location_default
108 (struct breakpoint
*b
, const struct event_location
*location
,
109 struct program_space
*search_pspace
);
111 static int can_use_hardware_watchpoint
112 (const std::vector
<value_ref_ptr
> &vals
);
114 static void mention (struct breakpoint
*);
116 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
118 const struct breakpoint_ops
*);
119 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
120 const struct symtab_and_line
*);
122 /* This function is used in gdbtk sources and thus can not be made
124 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
125 struct symtab_and_line
,
127 const struct breakpoint_ops
*);
129 static struct breakpoint
*
130 momentary_breakpoint_from_master (struct breakpoint
*orig
,
132 const struct breakpoint_ops
*ops
,
135 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
137 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
141 static void describe_other_breakpoints (struct gdbarch
*,
142 struct program_space
*, CORE_ADDR
,
143 struct obj_section
*, int);
145 static int watchpoint_locations_match (struct bp_location
*loc1
,
146 struct bp_location
*loc2
);
148 static int breakpoint_location_address_match (struct bp_location
*bl
,
149 const struct address_space
*aspace
,
152 static int breakpoint_location_address_range_overlap (struct bp_location
*,
153 const address_space
*,
156 static int remove_breakpoint (struct bp_location
*);
157 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
159 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
161 static int hw_breakpoint_used_count (void);
163 static int hw_watchpoint_use_count (struct breakpoint
*);
165 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
167 int *other_type_used
);
169 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
172 static void free_bp_location (struct bp_location
*loc
);
173 static void incref_bp_location (struct bp_location
*loc
);
174 static void decref_bp_location (struct bp_location
**loc
);
176 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
178 /* update_global_location_list's modes of operation wrt to whether to
179 insert locations now. */
180 enum ugll_insert_mode
182 /* Don't insert any breakpoint locations into the inferior, only
183 remove already-inserted locations that no longer should be
184 inserted. Functions that delete a breakpoint or breakpoints
185 should specify this mode, so that deleting a breakpoint doesn't
186 have the side effect of inserting the locations of other
187 breakpoints that are marked not-inserted, but should_be_inserted
188 returns true on them.
190 This behavior is useful is situations close to tear-down -- e.g.,
191 after an exec, while the target still has execution, but
192 breakpoint shadows of the previous executable image should *NOT*
193 be restored to the new image; or before detaching, where the
194 target still has execution and wants to delete breakpoints from
195 GDB's lists, and all breakpoints had already been removed from
199 /* May insert breakpoints iff breakpoints_should_be_inserted_now
200 claims breakpoints should be inserted now. */
203 /* Insert locations now, irrespective of
204 breakpoints_should_be_inserted_now. E.g., say all threads are
205 stopped right now, and the user did "continue". We need to
206 insert breakpoints _before_ resuming the target, but
207 UGLL_MAY_INSERT wouldn't insert them, because
208 breakpoints_should_be_inserted_now returns false at that point,
209 as no thread is running yet. */
213 static void update_global_location_list (enum ugll_insert_mode
);
215 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
217 static void insert_breakpoint_locations (void);
219 static void trace_pass_command (const char *, int);
221 static void set_tracepoint_count (int num
);
223 static bool is_masked_watchpoint (const struct breakpoint
*b
);
225 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
227 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
230 static int strace_marker_p (struct breakpoint
*b
);
232 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
233 that are implemented on top of software or hardware breakpoints
234 (user breakpoints, internal and momentary breakpoints, etc.). */
235 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
237 /* Internal breakpoints class type. */
238 static struct breakpoint_ops internal_breakpoint_ops
;
240 /* Momentary breakpoints class type. */
241 static struct breakpoint_ops momentary_breakpoint_ops
;
243 /* The breakpoint_ops structure to be used in regular user created
245 struct breakpoint_ops bkpt_breakpoint_ops
;
247 /* Breakpoints set on probes. */
248 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
250 /* Tracepoints set on probes. */
251 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
253 /* Dynamic printf class type. */
254 struct breakpoint_ops dprintf_breakpoint_ops
;
256 /* The style in which to perform a dynamic printf. This is a user
257 option because different output options have different tradeoffs;
258 if GDB does the printing, there is better error handling if there
259 is a problem with any of the arguments, but using an inferior
260 function lets you have special-purpose printers and sending of
261 output to the same place as compiled-in print functions. */
263 static const char dprintf_style_gdb
[] = "gdb";
264 static const char dprintf_style_call
[] = "call";
265 static const char dprintf_style_agent
[] = "agent";
266 static const char *const dprintf_style_enums
[] = {
272 static const char *dprintf_style
= dprintf_style_gdb
;
274 /* The function to use for dynamic printf if the preferred style is to
275 call into the inferior. The value is simply a string that is
276 copied into the command, so it can be anything that GDB can
277 evaluate to a callable address, not necessarily a function name. */
279 static char *dprintf_function
;
281 /* The channel to use for dynamic printf if the preferred style is to
282 call into the inferior; if a nonempty string, it will be passed to
283 the call as the first argument, with the format string as the
284 second. As with the dprintf function, this can be anything that
285 GDB knows how to evaluate, so in addition to common choices like
286 "stderr", this could be an app-specific expression like
287 "mystreams[curlogger]". */
289 static char *dprintf_channel
;
291 /* True if dprintf commands should continue to operate even if GDB
293 static bool disconnected_dprintf
= true;
295 struct command_line
*
296 breakpoint_commands (struct breakpoint
*b
)
298 return b
->commands
? b
->commands
.get () : NULL
;
301 /* Flag indicating that a command has proceeded the inferior past the
302 current breakpoint. */
304 static bool breakpoint_proceeded
;
307 bpdisp_text (enum bpdisp disp
)
309 /* NOTE: the following values are a part of MI protocol and
310 represent values of 'disp' field returned when inferior stops at
312 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
314 return bpdisps
[(int) disp
];
317 /* Prototypes for exported functions. */
318 /* If FALSE, gdb will not use hardware support for watchpoints, even
319 if such is available. */
320 static int can_use_hw_watchpoints
;
323 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
324 struct cmd_list_element
*c
,
327 fprintf_filtered (file
,
328 _("Debugger's willingness to use "
329 "watchpoint hardware is %s.\n"),
333 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
334 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
335 for unrecognized breakpoint locations.
336 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
337 static enum auto_boolean pending_break_support
;
339 show_pending_break_support (struct ui_file
*file
, int from_tty
,
340 struct cmd_list_element
*c
,
343 fprintf_filtered (file
,
344 _("Debugger's behavior regarding "
345 "pending breakpoints is %s.\n"),
349 /* If true, gdb will automatically use hardware breakpoints for breakpoints
350 set with "break" but falling in read-only memory.
351 If false, gdb will warn about such breakpoints, but won't automatically
352 use hardware breakpoints. */
353 static bool automatic_hardware_breakpoints
;
355 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
356 struct cmd_list_element
*c
,
359 fprintf_filtered (file
,
360 _("Automatic usage of hardware breakpoints is %s.\n"),
364 /* If on, GDB keeps breakpoints inserted even if the inferior is
365 stopped, and immediately inserts any new breakpoints as soon as
366 they're created. If off (default), GDB keeps breakpoints off of
367 the target as long as possible. That is, it delays inserting
368 breakpoints until the next resume, and removes them again when the
369 target fully stops. This is a bit safer in case GDB crashes while
370 processing user input. */
371 /* FIXME: this is a temporary workaround to make sure waves created while
372 all known threads are stopped, and the gdb prompt is presented, do not
373 execute past the enabled breakpoints. */
374 static bool always_inserted_mode
= true;
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. */
396 else if (target_has_execution
)
398 if (always_inserted_mode
)
400 /* The user wants breakpoints inserted even if all threads
405 if (threads_are_executing ())
408 /* Don't remove breakpoints yet if, even though all threads are
409 stopped, we still have events to process. */
410 for (thread_info
*tp
: all_non_exited_threads ())
412 && tp
->suspend
.waitstatus_pending_p
)
418 static const char condition_evaluation_both
[] = "host or target";
420 /* Modes for breakpoint condition evaluation. */
421 static const char condition_evaluation_auto
[] = "auto";
422 static const char condition_evaluation_host
[] = "host";
423 static const char condition_evaluation_target
[] = "target";
424 static const char *const condition_evaluation_enums
[] = {
425 condition_evaluation_auto
,
426 condition_evaluation_host
,
427 condition_evaluation_target
,
431 /* Global that holds the current mode for breakpoint condition evaluation. */
432 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
434 /* Global that we use to display information to the user (gets its value from
435 condition_evaluation_mode_1. */
436 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
438 /* Translate a condition evaluation mode MODE into either "host"
439 or "target". This is used mostly to translate from "auto" to the
440 real setting that is being used. It returns the translated
444 translate_condition_evaluation_mode (const char *mode
)
446 if (mode
== condition_evaluation_auto
)
448 if (target_supports_evaluation_of_breakpoint_conditions ())
449 return condition_evaluation_target
;
451 return condition_evaluation_host
;
457 /* Discovers what condition_evaluation_auto translates to. */
460 breakpoint_condition_evaluation_mode (void)
462 return translate_condition_evaluation_mode (condition_evaluation_mode
);
465 /* Return true if GDB should evaluate breakpoint conditions or false
469 gdb_evaluates_breakpoint_condition_p (void)
471 const char *mode
= breakpoint_condition_evaluation_mode ();
473 return (mode
== condition_evaluation_host
);
476 /* Are we executing breakpoint commands? */
477 static int executing_breakpoint_commands
;
479 /* Are overlay event breakpoints enabled? */
480 static int overlay_events_enabled
;
482 /* See description in breakpoint.h. */
483 bool target_exact_watchpoints
= false;
485 /* Walk the following statement or block through all breakpoints.
486 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
487 current breakpoint. */
489 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
491 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
492 for (B = breakpoint_chain; \
493 B ? (TMP=B->next, 1): 0; \
496 /* Similar iterator for the low-level breakpoints. SAFE variant is
497 not provided so update_global_location_list must not be called
498 while executing the block of ALL_BP_LOCATIONS. */
500 #define ALL_BP_LOCATIONS(B,BP_TMP) \
501 for (BP_TMP = bp_locations; \
502 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
505 /* Iterates through locations with address ADDRESS for the currently selected
506 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
507 to where the loop should start from.
508 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
509 appropriate location to start with. */
511 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
512 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
513 BP_LOCP_TMP = BP_LOCP_START; \
515 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
516 && (*BP_LOCP_TMP)->address == ADDRESS); \
519 /* Iterator for tracepoints only. */
521 #define ALL_TRACEPOINTS(B) \
522 for (B = breakpoint_chain; B; B = B->next) \
523 if (is_tracepoint (B))
525 /* Chains of all breakpoints defined. */
527 static struct breakpoint
*breakpoint_chain
;
529 /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */
531 static struct bp_location
**bp_locations
;
533 /* Number of elements of BP_LOCATIONS. */
535 static unsigned bp_locations_count
;
537 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
538 ADDRESS for the current elements of BP_LOCATIONS which get a valid
539 result from bp_location_has_shadow. You can use it for roughly
540 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
541 an address you need to read. */
543 static CORE_ADDR bp_locations_placed_address_before_address_max
;
545 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
546 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
547 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
548 You can use it for roughly limiting the subrange of BP_LOCATIONS to
549 scan for shadow bytes for an address you need to read. */
551 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
553 /* The locations that no longer correspond to any breakpoint, unlinked
554 from the bp_locations array, but for which a hit may still be
555 reported by a target. */
556 static std::vector
<bp_location
*> moribund_locations
;
558 /* Number of last breakpoint made. */
560 static int breakpoint_count
;
562 /* The value of `breakpoint_count' before the last command that
563 created breakpoints. If the last (break-like) command created more
564 than one breakpoint, then the difference between BREAKPOINT_COUNT
565 and PREV_BREAKPOINT_COUNT is more than one. */
566 static int prev_breakpoint_count
;
568 /* Number of last tracepoint made. */
570 static int tracepoint_count
;
572 static struct cmd_list_element
*breakpoint_set_cmdlist
;
573 static struct cmd_list_element
*breakpoint_show_cmdlist
;
574 struct cmd_list_element
*save_cmdlist
;
576 /* See declaration at breakpoint.h. */
579 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
582 struct breakpoint
*b
= NULL
;
586 if (func (b
, user_data
) != 0)
593 /* Return whether a breakpoint is an active enabled breakpoint. */
595 breakpoint_enabled (struct breakpoint
*b
)
597 return (b
->enable_state
== bp_enabled
);
600 /* Set breakpoint count to NUM. */
603 set_breakpoint_count (int num
)
605 prev_breakpoint_count
= breakpoint_count
;
606 breakpoint_count
= num
;
607 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
610 /* Used by `start_rbreak_breakpoints' below, to record the current
611 breakpoint count before "rbreak" creates any breakpoint. */
612 static int rbreak_start_breakpoint_count
;
614 /* Called at the start an "rbreak" command to record the first
617 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
619 rbreak_start_breakpoint_count
= breakpoint_count
;
622 /* Called at the end of an "rbreak" command to record the last
625 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
627 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
630 /* Used in run_command to zero the hit count when a new run starts. */
633 clear_breakpoint_hit_counts (void)
635 struct breakpoint
*b
;
642 /* Return the breakpoint with the specified number, or NULL
643 if the number does not refer to an existing breakpoint. */
646 get_breakpoint (int num
)
648 struct breakpoint
*b
;
651 if (b
->number
== num
)
659 /* Mark locations as "conditions have changed" in case the target supports
660 evaluating conditions on its side. */
663 mark_breakpoint_modified (struct breakpoint
*b
)
665 struct bp_location
*loc
;
667 /* This is only meaningful if the target is
668 evaluating conditions and if the user has
669 opted for condition evaluation on the target's
671 if (gdb_evaluates_breakpoint_condition_p ()
672 || !target_supports_evaluation_of_breakpoint_conditions ())
675 if (!is_breakpoint (b
))
678 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
679 loc
->condition_changed
= condition_modified
;
682 /* Mark location as "conditions have changed" in case the target supports
683 evaluating conditions on its side. */
686 mark_breakpoint_location_modified (struct bp_location
*loc
)
688 /* This is only meaningful if the target is
689 evaluating conditions and if the user has
690 opted for condition evaluation on the target's
692 if (gdb_evaluates_breakpoint_condition_p ()
693 || !target_supports_evaluation_of_breakpoint_conditions ())
697 if (!is_breakpoint (loc
->owner
))
700 loc
->condition_changed
= condition_modified
;
703 /* Sets the condition-evaluation mode using the static global
704 condition_evaluation_mode. */
707 set_condition_evaluation_mode (const char *args
, int from_tty
,
708 struct cmd_list_element
*c
)
710 const char *old_mode
, *new_mode
;
712 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
713 && !target_supports_evaluation_of_breakpoint_conditions ())
715 condition_evaluation_mode_1
= condition_evaluation_mode
;
716 warning (_("Target does not support breakpoint condition evaluation.\n"
717 "Using host evaluation mode instead."));
721 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
722 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
724 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
725 settings was "auto". */
726 condition_evaluation_mode
= condition_evaluation_mode_1
;
728 /* Only update the mode if the user picked a different one. */
729 if (new_mode
!= old_mode
)
731 struct bp_location
*loc
, **loc_tmp
;
732 /* If the user switched to a different evaluation mode, we
733 need to synch the changes with the target as follows:
735 "host" -> "target": Send all (valid) conditions to the target.
736 "target" -> "host": Remove all the conditions from the target.
739 if (new_mode
== condition_evaluation_target
)
741 /* Mark everything modified and synch conditions with the
743 ALL_BP_LOCATIONS (loc
, loc_tmp
)
744 mark_breakpoint_location_modified (loc
);
748 /* Manually mark non-duplicate locations to synch conditions
749 with the target. We do this to remove all the conditions the
750 target knows about. */
751 ALL_BP_LOCATIONS (loc
, loc_tmp
)
752 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
753 loc
->needs_update
= 1;
757 update_global_location_list (UGLL_MAY_INSERT
);
763 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
764 what "auto" is translating to. */
767 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
768 struct cmd_list_element
*c
, const char *value
)
770 if (condition_evaluation_mode
== condition_evaluation_auto
)
771 fprintf_filtered (file
,
772 _("Breakpoint condition evaluation "
773 "mode is %s (currently %s).\n"),
775 breakpoint_condition_evaluation_mode ());
777 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
781 /* A comparison function for bp_location AP and BP that is used by
782 bsearch. This comparison function only cares about addresses, unlike
783 the more general bp_location_is_less_than function. */
786 bp_locations_compare_addrs (const void *ap
, const void *bp
)
788 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
789 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
791 if (a
->address
== b
->address
)
794 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
797 /* Helper function to skip all bp_locations with addresses
798 less than ADDRESS. It returns the first bp_location that
799 is greater than or equal to ADDRESS. If none is found, just
802 static struct bp_location
**
803 get_first_locp_gte_addr (CORE_ADDR address
)
805 struct bp_location dummy_loc
;
806 struct bp_location
*dummy_locp
= &dummy_loc
;
807 struct bp_location
**locp_found
= NULL
;
809 /* Initialize the dummy location's address field. */
810 dummy_loc
.address
= address
;
812 /* Find a close match to the first location at ADDRESS. */
813 locp_found
= ((struct bp_location
**)
814 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
815 sizeof (struct bp_location
**),
816 bp_locations_compare_addrs
));
818 /* Nothing was found, nothing left to do. */
819 if (locp_found
== NULL
)
822 /* We may have found a location that is at ADDRESS but is not the first in the
823 location's list. Go backwards (if possible) and locate the first one. */
824 while ((locp_found
- 1) >= bp_locations
825 && (*(locp_found
- 1))->address
== address
)
832 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
835 xfree (b
->cond_string
);
836 b
->cond_string
= NULL
;
838 if (is_watchpoint (b
))
840 struct watchpoint
*w
= (struct watchpoint
*) b
;
842 w
->cond_exp
.reset ();
846 struct bp_location
*loc
;
848 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
852 /* No need to free the condition agent expression
853 bytecode (if we have one). We will handle this
854 when we go through update_global_location_list. */
861 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
865 const char *arg
= exp
;
867 /* I don't know if it matters whether this is the string the user
868 typed in or the decompiled expression. */
869 b
->cond_string
= xstrdup (arg
);
870 b
->condition_not_parsed
= 0;
872 if (is_watchpoint (b
))
874 struct watchpoint
*w
= (struct watchpoint
*) b
;
876 innermost_block_tracker tracker
;
878 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
880 error (_("Junk at end of expression"));
881 w
->cond_exp_valid_block
= tracker
.block ();
885 struct bp_location
*loc
;
887 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
891 parse_exp_1 (&arg
, loc
->address
,
892 block_for_pc (loc
->address
), 0);
894 error (_("Junk at end of expression"));
898 mark_breakpoint_modified (b
);
900 gdb::observers::breakpoint_modified
.notify (b
);
903 /* Completion for the "condition" command. */
906 condition_completer (struct cmd_list_element
*cmd
,
907 completion_tracker
&tracker
,
908 const char *text
, const char *word
)
912 text
= skip_spaces (text
);
913 space
= skip_to_space (text
);
917 struct breakpoint
*b
;
921 /* We don't support completion of history indices. */
922 if (!isdigit (text
[1]))
923 complete_internalvar (tracker
, &text
[1]);
927 /* We're completing the breakpoint number. */
934 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
936 if (strncmp (number
, text
, len
) == 0)
937 tracker
.add_completion (make_unique_xstrdup (number
));
943 /* We're completing the expression part. */
944 text
= skip_spaces (space
);
945 expression_completer (cmd
, tracker
, text
, word
);
948 /* condition N EXP -- set break condition of breakpoint N to EXP. */
951 condition_command (const char *arg
, int from_tty
)
953 struct breakpoint
*b
;
958 error_no_arg (_("breakpoint number"));
961 bnum
= get_number (&p
);
963 error (_("Bad breakpoint argument: '%s'"), arg
);
966 if (b
->number
== bnum
)
968 /* Check if this breakpoint has a "stop" method implemented in an
969 extension language. This method and conditions entered into GDB
970 from the CLI are mutually exclusive. */
971 const struct extension_language_defn
*extlang
972 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
976 error (_("Only one stop condition allowed. There is currently"
977 " a %s stop condition defined for this breakpoint."),
978 ext_lang_capitalized_name (extlang
));
980 set_breakpoint_condition (b
, p
, from_tty
);
982 if (is_breakpoint (b
))
983 update_global_location_list (UGLL_MAY_INSERT
);
988 error (_("No breakpoint number %d."), bnum
);
991 /* Check that COMMAND do not contain commands that are suitable
992 only for tracepoints and not suitable for ordinary breakpoints.
993 Throw if any such commands is found. */
996 check_no_tracepoint_commands (struct command_line
*commands
)
998 struct command_line
*c
;
1000 for (c
= commands
; c
; c
= c
->next
)
1002 if (c
->control_type
== while_stepping_control
)
1003 error (_("The 'while-stepping' command can "
1004 "only be used for tracepoints"));
1006 check_no_tracepoint_commands (c
->body_list_0
.get ());
1007 check_no_tracepoint_commands (c
->body_list_1
.get ());
1009 /* Not that command parsing removes leading whitespace and comment
1010 lines and also empty lines. So, we only need to check for
1011 command directly. */
1012 if (strstr (c
->line
, "collect ") == c
->line
)
1013 error (_("The 'collect' command can only be used for tracepoints"));
1015 if (strstr (c
->line
, "teval ") == c
->line
)
1016 error (_("The 'teval' command can only be used for tracepoints"));
1020 struct longjmp_breakpoint
: public breakpoint
1022 ~longjmp_breakpoint () override
;
1025 /* Encapsulate tests for different types of tracepoints. */
1028 is_tracepoint_type (bptype type
)
1030 return (type
== bp_tracepoint
1031 || type
== bp_fast_tracepoint
1032 || type
== bp_static_tracepoint
);
1036 is_longjmp_type (bptype type
)
1038 return type
== bp_longjmp
|| type
== bp_exception
;
1041 /* See breakpoint.h. */
1044 is_tracepoint (const struct breakpoint
*b
)
1046 return is_tracepoint_type (b
->type
);
1049 /* Factory function to create an appropriate instance of breakpoint given
1052 static std::unique_ptr
<breakpoint
>
1053 new_breakpoint_from_type (bptype type
)
1057 if (is_tracepoint_type (type
))
1058 b
= new tracepoint ();
1059 else if (is_longjmp_type (type
))
1060 b
= new longjmp_breakpoint ();
1062 b
= new breakpoint ();
1064 return std::unique_ptr
<breakpoint
> (b
);
1067 /* A helper function that validates that COMMANDS are valid for a
1068 breakpoint. This function will throw an exception if a problem is
1072 validate_commands_for_breakpoint (struct breakpoint
*b
,
1073 struct command_line
*commands
)
1075 if (is_tracepoint (b
))
1077 struct tracepoint
*t
= (struct tracepoint
*) b
;
1078 struct command_line
*c
;
1079 struct command_line
*while_stepping
= 0;
1081 /* Reset the while-stepping step count. The previous commands
1082 might have included a while-stepping action, while the new
1086 /* We need to verify that each top-level element of commands is
1087 valid for tracepoints, that there's at most one
1088 while-stepping element, and that the while-stepping's body
1089 has valid tracing commands excluding nested while-stepping.
1090 We also need to validate the tracepoint action line in the
1091 context of the tracepoint --- validate_actionline actually
1092 has side effects, like setting the tracepoint's
1093 while-stepping STEP_COUNT, in addition to checking if the
1094 collect/teval actions parse and make sense in the
1095 tracepoint's context. */
1096 for (c
= commands
; c
; c
= c
->next
)
1098 if (c
->control_type
== while_stepping_control
)
1100 if (b
->type
== bp_fast_tracepoint
)
1101 error (_("The 'while-stepping' command "
1102 "cannot be used for fast tracepoint"));
1103 else if (b
->type
== bp_static_tracepoint
)
1104 error (_("The 'while-stepping' command "
1105 "cannot be used for static tracepoint"));
1108 error (_("The 'while-stepping' command "
1109 "can be used only once"));
1114 validate_actionline (c
->line
, b
);
1118 struct command_line
*c2
;
1120 gdb_assert (while_stepping
->body_list_1
== nullptr);
1121 c2
= while_stepping
->body_list_0
.get ();
1122 for (; c2
; c2
= c2
->next
)
1124 if (c2
->control_type
== while_stepping_control
)
1125 error (_("The 'while-stepping' command cannot be nested"));
1131 check_no_tracepoint_commands (commands
);
1135 /* Return a vector of all the static tracepoints set at ADDR. The
1136 caller is responsible for releasing the vector. */
1138 std::vector
<breakpoint
*>
1139 static_tracepoints_here (CORE_ADDR addr
)
1141 struct breakpoint
*b
;
1142 std::vector
<breakpoint
*> found
;
1143 struct bp_location
*loc
;
1146 if (b
->type
== bp_static_tracepoint
)
1148 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1149 if (loc
->address
== addr
)
1150 found
.push_back (b
);
1156 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1157 validate that only allowed commands are included. */
1160 breakpoint_set_commands (struct breakpoint
*b
,
1161 counted_command_line
&&commands
)
1163 validate_commands_for_breakpoint (b
, commands
.get ());
1165 b
->commands
= std::move (commands
);
1166 gdb::observers::breakpoint_modified
.notify (b
);
1169 /* Set the internal `silent' flag on the breakpoint. Note that this
1170 is not the same as the "silent" that may appear in the breakpoint's
1174 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1176 int old_silent
= b
->silent
;
1179 if (old_silent
!= silent
)
1180 gdb::observers::breakpoint_modified
.notify (b
);
1183 /* Set the thread for this breakpoint. If THREAD is -1, make the
1184 breakpoint work for any thread. */
1187 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1189 int old_thread
= b
->thread
;
1192 if (old_thread
!= thread
)
1193 gdb::observers::breakpoint_modified
.notify (b
);
1196 /* Set the task for this breakpoint. If TASK is 0, make the
1197 breakpoint work for any task. */
1200 breakpoint_set_task (struct breakpoint
*b
, int task
)
1202 int old_task
= b
->task
;
1205 if (old_task
!= task
)
1206 gdb::observers::breakpoint_modified
.notify (b
);
1210 commands_command_1 (const char *arg
, int from_tty
,
1211 struct command_line
*control
)
1213 counted_command_line cmd
;
1214 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1215 NULL after the call to read_command_lines if the user provides an empty
1216 list of command by just typing "end". */
1217 bool cmd_read
= false;
1219 std::string new_arg
;
1221 if (arg
== NULL
|| !*arg
)
1223 if (breakpoint_count
- prev_breakpoint_count
> 1)
1224 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1226 else if (breakpoint_count
> 0)
1227 new_arg
= string_printf ("%d", breakpoint_count
);
1228 arg
= new_arg
.c_str ();
1231 map_breakpoint_numbers
1232 (arg
, [&] (breakpoint
*b
)
1236 gdb_assert (cmd
== NULL
);
1237 if (control
!= NULL
)
1238 cmd
= control
->body_list_0
;
1242 = string_printf (_("Type commands for breakpoint(s) "
1243 "%s, one per line."),
1246 auto do_validate
= [=] (const char *line
)
1248 validate_actionline (line
, b
);
1250 gdb::function_view
<void (const char *)> validator
;
1251 if (is_tracepoint (b
))
1252 validator
= do_validate
;
1254 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1259 /* If a breakpoint was on the list more than once, we don't need to
1261 if (b
->commands
!= cmd
)
1263 validate_commands_for_breakpoint (b
, cmd
.get ());
1265 gdb::observers::breakpoint_modified
.notify (b
);
1271 commands_command (const char *arg
, int from_tty
)
1273 commands_command_1 (arg
, from_tty
, NULL
);
1276 /* Like commands_command, but instead of reading the commands from
1277 input stream, takes them from an already parsed command structure.
1279 This is used by cli-script.c to DTRT with breakpoint commands
1280 that are part of if and while bodies. */
1281 enum command_control_type
1282 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1284 commands_command_1 (arg
, 0, cmd
);
1285 return simple_control
;
1288 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1291 bp_location_has_shadow (struct bp_location
*bl
)
1293 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1297 if (bl
->target_info
.shadow_len
== 0)
1298 /* BL isn't valid, or doesn't shadow memory. */
1303 /* Update BUF, which is LEN bytes read from the target address
1304 MEMADDR, by replacing a memory breakpoint with its shadowed
1307 If READBUF is not NULL, this buffer must not overlap with the of
1308 the breakpoint location's shadow_contents buffer. Otherwise, a
1309 failed assertion internal error will be raised. */
1312 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1313 const gdb_byte
*writebuf_org
,
1314 ULONGEST memaddr
, LONGEST len
,
1315 struct bp_target_info
*target_info
,
1316 struct gdbarch
*gdbarch
)
1318 /* Now do full processing of the found relevant range of elements. */
1319 CORE_ADDR bp_addr
= 0;
1323 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1324 current_program_space
->aspace
, 0))
1326 /* The breakpoint is inserted in a different address space. */
1330 /* Addresses and length of the part of the breakpoint that
1332 bp_addr
= target_info
->placed_address
;
1333 bp_size
= target_info
->shadow_len
;
1335 if (bp_addr
+ bp_size
<= memaddr
)
1337 /* The breakpoint is entirely before the chunk of memory we are
1342 if (bp_addr
>= memaddr
+ len
)
1344 /* The breakpoint is entirely after the chunk of memory we are
1349 /* Offset within shadow_contents. */
1350 if (bp_addr
< memaddr
)
1352 /* Only copy the second part of the breakpoint. */
1353 bp_size
-= memaddr
- bp_addr
;
1354 bptoffset
= memaddr
- bp_addr
;
1358 if (bp_addr
+ bp_size
> memaddr
+ len
)
1360 /* Only copy the first part of the breakpoint. */
1361 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1364 if (readbuf
!= NULL
)
1366 /* Verify that the readbuf buffer does not overlap with the
1367 shadow_contents buffer. */
1368 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1369 || readbuf
>= (target_info
->shadow_contents
1370 + target_info
->shadow_len
));
1372 /* Update the read buffer with this inserted breakpoint's
1374 memcpy (readbuf
+ bp_addr
- memaddr
,
1375 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1379 const unsigned char *bp
;
1380 CORE_ADDR addr
= target_info
->reqstd_address
;
1383 /* Update the shadow with what we want to write to memory. */
1384 memcpy (target_info
->shadow_contents
+ bptoffset
,
1385 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1387 /* Determine appropriate breakpoint contents and size for this
1389 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1391 /* Update the final write buffer with this inserted
1392 breakpoint's INSN. */
1393 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1397 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1398 by replacing any memory breakpoints with their shadowed contents.
1400 If READBUF is not NULL, this buffer must not overlap with any of
1401 the breakpoint location's shadow_contents buffers. Otherwise,
1402 a failed assertion internal error will be raised.
1404 The range of shadowed area by each bp_location is:
1405 bl->address - bp_locations_placed_address_before_address_max
1406 up to bl->address + bp_locations_shadow_len_after_address_max
1407 The range we were requested to resolve shadows for is:
1408 memaddr ... memaddr + len
1409 Thus the safe cutoff boundaries for performance optimization are
1410 memaddr + len <= (bl->address
1411 - bp_locations_placed_address_before_address_max)
1413 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1416 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1417 const gdb_byte
*writebuf_org
,
1418 ULONGEST memaddr
, LONGEST len
)
1420 /* Left boundary, right boundary and median element of our binary
1422 unsigned bc_l
, bc_r
, bc
;
1424 /* Find BC_L which is a leftmost element which may affect BUF
1425 content. It is safe to report lower value but a failure to
1426 report higher one. */
1429 bc_r
= bp_locations_count
;
1430 while (bc_l
+ 1 < bc_r
)
1432 struct bp_location
*bl
;
1434 bc
= (bc_l
+ bc_r
) / 2;
1435 bl
= bp_locations
[bc
];
1437 /* Check first BL->ADDRESS will not overflow due to the added
1438 constant. Then advance the left boundary only if we are sure
1439 the BC element can in no way affect the BUF content (MEMADDR
1440 to MEMADDR + LEN range).
1442 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1443 offset so that we cannot miss a breakpoint with its shadow
1444 range tail still reaching MEMADDR. */
1446 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1448 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1455 /* Due to the binary search above, we need to make sure we pick the
1456 first location that's at BC_L's address. E.g., if there are
1457 multiple locations at the same address, BC_L may end up pointing
1458 at a duplicate location, and miss the "master"/"inserted"
1459 location. Say, given locations L1, L2 and L3 at addresses A and
1462 L1@A, L2@A, L3@B, ...
1464 BC_L could end up pointing at location L2, while the "master"
1465 location could be L1. Since the `loc->inserted' flag is only set
1466 on "master" locations, we'd forget to restore the shadow of L1
1469 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1472 /* Now do full processing of the found relevant range of elements. */
1474 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1476 struct bp_location
*bl
= bp_locations
[bc
];
1478 /* bp_location array has BL->OWNER always non-NULL. */
1479 if (bl
->owner
->type
== bp_none
)
1480 warning (_("reading through apparently deleted breakpoint #%d?"),
1483 /* Performance optimization: any further element can no longer affect BUF
1486 if (bl
->address
>= bp_locations_placed_address_before_address_max
1487 && memaddr
+ len
<= (bl
->address
1488 - bp_locations_placed_address_before_address_max
))
1491 if (!bp_location_has_shadow (bl
))
1494 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1495 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1499 /* See breakpoint.h. */
1502 is_breakpoint (const struct breakpoint
*bpt
)
1504 return (bpt
->type
== bp_breakpoint
1505 || bpt
->type
== bp_hardware_breakpoint
1506 || bpt
->type
== bp_dprintf
);
1509 /* Return true if BPT is of any hardware watchpoint kind. */
1512 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1514 return (bpt
->type
== bp_hardware_watchpoint
1515 || bpt
->type
== bp_read_watchpoint
1516 || bpt
->type
== bp_access_watchpoint
);
1519 /* See breakpoint.h. */
1522 is_watchpoint (const struct breakpoint
*bpt
)
1524 return (is_hardware_watchpoint (bpt
)
1525 || bpt
->type
== bp_watchpoint
);
1528 /* Returns true if the current thread and its running state are safe
1529 to evaluate or update watchpoint B. Watchpoints on local
1530 expressions need to be evaluated in the context of the thread that
1531 was current when the watchpoint was created, and, that thread needs
1532 to be stopped to be able to select the correct frame context.
1533 Watchpoints on global expressions can be evaluated on any thread,
1534 and in any state. It is presently left to the target allowing
1535 memory accesses when threads are running. */
1538 watchpoint_in_thread_scope (struct watchpoint
*b
)
1540 return (b
->pspace
== current_program_space
1541 && (b
->watchpoint_thread
== null_ptid
1542 || (inferior_ptid
== b
->watchpoint_thread
1543 && !inferior_thread ()->executing
)));
1546 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1547 associated bp_watchpoint_scope breakpoint. */
1550 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1552 if (w
->related_breakpoint
!= w
)
1554 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1555 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1556 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1557 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1558 w
->related_breakpoint
= w
;
1560 w
->disposition
= disp_del_at_next_stop
;
1563 /* Extract a bitfield value from value VAL using the bit parameters contained in
1566 static struct value
*
1567 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1569 struct value
*bit_val
;
1574 bit_val
= allocate_value (value_type (val
));
1576 unpack_value_bitfield (bit_val
,
1579 value_contents_for_printing (val
),
1586 /* Allocate a dummy location and add it to B, which must be a software
1587 watchpoint. This is required because even if a software watchpoint
1588 is not watching any memory, bpstat_stop_status requires a location
1589 to be able to report stops. */
1592 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1593 struct program_space
*pspace
)
1595 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1597 b
->loc
= allocate_bp_location (b
);
1598 b
->loc
->pspace
= pspace
;
1599 b
->loc
->address
= -1;
1600 b
->loc
->length
= -1;
1603 /* Returns true if B is a software watchpoint that is not watching any
1604 memory (e.g., "watch $pc"). */
1607 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1609 return (b
->type
== bp_watchpoint
1611 && b
->loc
->next
== NULL
1612 && b
->loc
->address
== -1
1613 && b
->loc
->length
== -1);
1616 /* Assuming that B is a watchpoint:
1617 - Reparse watchpoint expression, if REPARSE is non-zero
1618 - Evaluate expression and store the result in B->val
1619 - Evaluate the condition if there is one, and store the result
1621 - Update the list of values that must be watched in B->loc.
1623 If the watchpoint disposition is disp_del_at_next_stop, then do
1624 nothing. If this is local watchpoint that is out of scope, delete
1627 Even with `set breakpoint always-inserted on' the watchpoints are
1628 removed + inserted on each stop here. Normal breakpoints must
1629 never be removed because they might be missed by a running thread
1630 when debugging in non-stop mode. On the other hand, hardware
1631 watchpoints (is_hardware_watchpoint; processed here) are specific
1632 to each LWP since they are stored in each LWP's hardware debug
1633 registers. Therefore, such LWP must be stopped first in order to
1634 be able to modify its hardware watchpoints.
1636 Hardware watchpoints must be reset exactly once after being
1637 presented to the user. It cannot be done sooner, because it would
1638 reset the data used to present the watchpoint hit to the user. And
1639 it must not be done later because it could display the same single
1640 watchpoint hit during multiple GDB stops. Note that the latter is
1641 relevant only to the hardware watchpoint types bp_read_watchpoint
1642 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1643 not user-visible - its hit is suppressed if the memory content has
1646 The following constraints influence the location where we can reset
1647 hardware watchpoints:
1649 * target_stopped_by_watchpoint and target_stopped_data_address are
1650 called several times when GDB stops.
1653 * Multiple hardware watchpoints can be hit at the same time,
1654 causing GDB to stop. GDB only presents one hardware watchpoint
1655 hit at a time as the reason for stopping, and all the other hits
1656 are presented later, one after the other, each time the user
1657 requests the execution to be resumed. Execution is not resumed
1658 for the threads still having pending hit event stored in
1659 LWP_INFO->STATUS. While the watchpoint is already removed from
1660 the inferior on the first stop the thread hit event is kept being
1661 reported from its cached value by linux_nat_stopped_data_address
1662 until the real thread resume happens after the watchpoint gets
1663 presented and thus its LWP_INFO->STATUS gets reset.
1665 Therefore the hardware watchpoint hit can get safely reset on the
1666 watchpoint removal from inferior. */
1669 update_watchpoint (struct watchpoint
*b
, int reparse
)
1671 int within_current_scope
;
1672 struct frame_id saved_frame_id
;
1675 /* If this is a local watchpoint, we only want to check if the
1676 watchpoint frame is in scope if the current thread is the thread
1677 that was used to create the watchpoint. */
1678 if (!watchpoint_in_thread_scope (b
))
1681 if (b
->disposition
== disp_del_at_next_stop
)
1686 /* Determine if the watchpoint is within scope. */
1687 if (b
->exp_valid_block
== NULL
)
1688 within_current_scope
= 1;
1691 struct frame_info
*fi
= get_current_frame ();
1692 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1693 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1695 /* If we're at a point where the stack has been destroyed
1696 (e.g. in a function epilogue), unwinding may not work
1697 properly. Do not attempt to recreate locations at this
1698 point. See similar comments in watchpoint_check. */
1699 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1702 /* Save the current frame's ID so we can restore it after
1703 evaluating the watchpoint expression on its own frame. */
1704 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1705 took a frame parameter, so that we didn't have to change the
1708 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1710 fi
= frame_find_by_id (b
->watchpoint_frame
);
1711 within_current_scope
= (fi
!= NULL
);
1712 if (within_current_scope
)
1716 /* We don't free locations. They are stored in the bp_location array
1717 and update_global_location_list will eventually delete them and
1718 remove breakpoints if needed. */
1721 if (within_current_scope
&& reparse
)
1726 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1727 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1728 /* If the meaning of expression itself changed, the old value is
1729 no longer relevant. We don't want to report a watchpoint hit
1730 to the user when the old value and the new value may actually
1731 be completely different objects. */
1733 b
->val_valid
= false;
1735 /* Note that unlike with breakpoints, the watchpoint's condition
1736 expression is stored in the breakpoint object, not in the
1737 locations (re)created below. */
1738 if (b
->cond_string
!= NULL
)
1740 b
->cond_exp
.reset ();
1743 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1747 /* If we failed to parse the expression, for example because
1748 it refers to a global variable in a not-yet-loaded shared library,
1749 don't try to insert watchpoint. We don't automatically delete
1750 such watchpoint, though, since failure to parse expression
1751 is different from out-of-scope watchpoint. */
1752 if (!target_has_execution
)
1754 /* Without execution, memory can't change. No use to try and
1755 set watchpoint locations. The watchpoint will be reset when
1756 the target gains execution, through breakpoint_re_set. */
1757 if (!can_use_hw_watchpoints
)
1759 if (b
->ops
->works_in_software_mode (b
))
1760 b
->type
= bp_watchpoint
;
1762 error (_("Can't set read/access watchpoint when "
1763 "hardware watchpoints are disabled."));
1766 else if (within_current_scope
&& b
->exp
)
1769 std::vector
<value_ref_ptr
> val_chain
;
1770 struct value
*v
, *result
;
1771 struct program_space
*frame_pspace
;
1773 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1775 /* Avoid setting b->val if it's already set. The meaning of
1776 b->val is 'the last value' user saw, and we should update
1777 it only if we reported that last value to user. As it
1778 happens, the code that reports it updates b->val directly.
1779 We don't keep track of the memory value for masked
1781 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1783 if (b
->val_bitsize
!= 0)
1784 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1785 b
->val
= release_value (v
);
1786 b
->val_valid
= true;
1789 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1791 /* Look at each value on the value chain. */
1792 gdb_assert (!val_chain
.empty ());
1793 for (const value_ref_ptr
&iter
: val_chain
)
1797 /* If it's a memory location, and GDB actually needed
1798 its contents to evaluate the expression, then we
1799 must watch it. If the first value returned is
1800 still lazy, that means an error occurred reading it;
1801 watch it anyway in case it becomes readable. */
1802 if (VALUE_LVAL (v
) == lval_memory
1803 && (v
== val_chain
[0] || ! value_lazy (v
)))
1805 struct type
*vtype
= check_typedef (value_type (v
));
1807 /* We only watch structs and arrays if user asked
1808 for it explicitly, never if they just happen to
1809 appear in the middle of some value chain. */
1811 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1812 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1815 enum target_hw_bp_type type
;
1816 struct bp_location
*loc
, **tmp
;
1817 int bitpos
= 0, bitsize
= 0;
1819 if (value_bitsize (v
) != 0)
1821 /* Extract the bit parameters out from the bitfield
1823 bitpos
= value_bitpos (v
);
1824 bitsize
= value_bitsize (v
);
1826 else if (v
== result
&& b
->val_bitsize
!= 0)
1828 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1829 lvalue whose bit parameters are saved in the fields
1830 VAL_BITPOS and VAL_BITSIZE. */
1831 bitpos
= b
->val_bitpos
;
1832 bitsize
= b
->val_bitsize
;
1835 addr
= value_address (v
);
1838 /* Skip the bytes that don't contain the bitfield. */
1843 if (b
->type
== bp_read_watchpoint
)
1845 else if (b
->type
== bp_access_watchpoint
)
1848 loc
= allocate_bp_location (b
);
1849 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1852 loc
->gdbarch
= get_type_arch (value_type (v
));
1854 loc
->pspace
= frame_pspace
;
1855 loc
->address
= address_significant (loc
->gdbarch
, addr
);
1859 /* Just cover the bytes that make up the bitfield. */
1860 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1863 loc
->length
= TYPE_LENGTH (value_type (v
));
1865 loc
->watchpoint_type
= type
;
1870 /* Change the type of breakpoint between hardware assisted or
1871 an ordinary watchpoint depending on the hardware support
1872 and free hardware slots. REPARSE is set when the inferior
1877 enum bp_loc_type loc_type
;
1878 struct bp_location
*bl
;
1880 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1884 int i
, target_resources_ok
, other_type_used
;
1887 /* Use an exact watchpoint when there's only one memory region to be
1888 watched, and only one debug register is needed to watch it. */
1889 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1891 /* We need to determine how many resources are already
1892 used for all other hardware watchpoints plus this one
1893 to see if we still have enough resources to also fit
1894 this watchpoint in as well. */
1896 /* If this is a software watchpoint, we try to turn it
1897 to a hardware one -- count resources as if B was of
1898 hardware watchpoint type. */
1900 if (type
== bp_watchpoint
)
1901 type
= bp_hardware_watchpoint
;
1903 /* This watchpoint may or may not have been placed on
1904 the list yet at this point (it won't be in the list
1905 if we're trying to create it for the first time,
1906 through watch_command), so always account for it
1909 /* Count resources used by all watchpoints except B. */
1910 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1912 /* Add in the resources needed for B. */
1913 i
+= hw_watchpoint_use_count (b
);
1916 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1917 if (target_resources_ok
<= 0)
1919 int sw_mode
= b
->ops
->works_in_software_mode (b
);
1921 if (target_resources_ok
== 0 && !sw_mode
)
1922 error (_("Target does not support this type of "
1923 "hardware watchpoint."));
1924 else if (target_resources_ok
< 0 && !sw_mode
)
1925 error (_("There are not enough available hardware "
1926 "resources for this watchpoint."));
1928 /* Downgrade to software watchpoint. */
1929 b
->type
= bp_watchpoint
;
1933 /* If this was a software watchpoint, we've just
1934 found we have enough resources to turn it to a
1935 hardware watchpoint. Otherwise, this is a
1940 else if (!b
->ops
->works_in_software_mode (b
))
1942 if (!can_use_hw_watchpoints
)
1943 error (_("Can't set read/access watchpoint when "
1944 "hardware watchpoints are disabled."));
1946 error (_("Expression cannot be implemented with "
1947 "read/access watchpoint."));
1950 b
->type
= bp_watchpoint
;
1952 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1953 : bp_loc_hardware_watchpoint
);
1954 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1955 bl
->loc_type
= loc_type
;
1958 /* If a software watchpoint is not watching any memory, then the
1959 above left it without any location set up. But,
1960 bpstat_stop_status requires a location to be able to report
1961 stops, so make sure there's at least a dummy one. */
1962 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1963 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
1965 else if (!within_current_scope
)
1967 printf_filtered (_("\
1968 Watchpoint %d deleted because the program has left the block\n\
1969 in which its expression is valid.\n"),
1971 watchpoint_del_at_next_stop (b
);
1974 /* Restore the selected frame. */
1976 select_frame (frame_find_by_id (saved_frame_id
));
1980 /* Returns 1 iff breakpoint location should be
1981 inserted in the inferior. We don't differentiate the type of BL's owner
1982 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1983 breakpoint_ops is not defined, because in insert_bp_location,
1984 tracepoint's insert_location will not be called. */
1986 should_be_inserted (struct bp_location
*bl
)
1988 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1991 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1994 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1997 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2000 /* This is set for example, when we're attached to the parent of a
2001 vfork, and have detached from the child. The child is running
2002 free, and we expect it to do an exec or exit, at which point the
2003 OS makes the parent schedulable again (and the target reports
2004 that the vfork is done). Until the child is done with the shared
2005 memory region, do not insert breakpoints in the parent, otherwise
2006 the child could still trip on the parent's breakpoints. Since
2007 the parent is blocked anyway, it won't miss any breakpoint. */
2008 if (bl
->pspace
->breakpoints_not_allowed
)
2011 /* Don't insert a breakpoint if we're trying to step past its
2012 location, except if the breakpoint is a single-step breakpoint,
2013 and the breakpoint's thread is the thread which is stepping past
2015 if ((bl
->loc_type
== bp_loc_software_breakpoint
2016 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2017 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2019 /* The single-step breakpoint may be inserted at the location
2020 we're trying to step if the instruction branches to itself.
2021 However, the instruction won't be executed at all and it may
2022 break the semantics of the instruction, for example, the
2023 instruction is a conditional branch or updates some flags.
2024 We can't fix it unless GDB is able to emulate the instruction
2025 or switch to displaced stepping. */
2026 && !(bl
->owner
->type
== bp_single_step
2027 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2031 fprintf_unfiltered (gdb_stdlog
,
2032 "infrun: skipping breakpoint: "
2033 "stepping past insn at: %s\n",
2034 paddress (bl
->gdbarch
, bl
->address
));
2039 /* Don't insert watchpoints if we're trying to step past the
2040 instruction that triggered one. */
2041 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2042 && stepping_past_nonsteppable_watchpoint ())
2046 fprintf_unfiltered (gdb_stdlog
,
2047 "infrun: stepping past non-steppable watchpoint. "
2048 "skipping watchpoint at %s:%d\n",
2049 paddress (bl
->gdbarch
, bl
->address
),
2058 /* Same as should_be_inserted but does the check assuming
2059 that the location is not duplicated. */
2062 unduplicated_should_be_inserted (struct bp_location
*bl
)
2065 const int save_duplicate
= bl
->duplicate
;
2068 result
= should_be_inserted (bl
);
2069 bl
->duplicate
= save_duplicate
;
2073 /* Parses a conditional described by an expression COND into an
2074 agent expression bytecode suitable for evaluation
2075 by the bytecode interpreter. Return NULL if there was
2076 any error during parsing. */
2078 static agent_expr_up
2079 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2084 agent_expr_up aexpr
;
2086 /* We don't want to stop processing, so catch any errors
2087 that may show up. */
2090 aexpr
= gen_eval_for_expr (scope
, cond
);
2093 catch (const gdb_exception_error
&ex
)
2095 /* If we got here, it means the condition could not be parsed to a valid
2096 bytecode expression and thus can't be evaluated on the target's side.
2097 It's no use iterating through the conditions. */
2100 /* We have a valid agent expression. */
2104 /* Based on location BL, create a list of breakpoint conditions to be
2105 passed on to the target. If we have duplicated locations with different
2106 conditions, we will add such conditions to the list. The idea is that the
2107 target will evaluate the list of conditions and will only notify GDB when
2108 one of them is true. */
2111 build_target_condition_list (struct bp_location
*bl
)
2113 struct bp_location
**locp
= NULL
, **loc2p
;
2114 int null_condition_or_parse_error
= 0;
2115 int modified
= bl
->needs_update
;
2116 struct bp_location
*loc
;
2118 /* Release conditions left over from a previous insert. */
2119 bl
->target_info
.conditions
.clear ();
2121 /* This is only meaningful if the target is
2122 evaluating conditions and if the user has
2123 opted for condition evaluation on the target's
2125 if (gdb_evaluates_breakpoint_condition_p ()
2126 || !target_supports_evaluation_of_breakpoint_conditions ())
2129 /* Do a first pass to check for locations with no assigned
2130 conditions or conditions that fail to parse to a valid agent expression
2131 bytecode. If any of these happen, then it's no use to send conditions
2132 to the target since this location will always trigger and generate a
2133 response back to GDB. */
2134 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2137 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2141 /* Re-parse the conditions since something changed. In that
2142 case we already freed the condition bytecodes (see
2143 force_breakpoint_reinsertion). We just
2144 need to parse the condition to bytecodes again. */
2145 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2149 /* If we have a NULL bytecode expression, it means something
2150 went wrong or we have a null condition expression. */
2151 if (!loc
->cond_bytecode
)
2153 null_condition_or_parse_error
= 1;
2159 /* If any of these happened, it means we will have to evaluate the conditions
2160 for the location's address on gdb's side. It is no use keeping bytecodes
2161 for all the other duplicate locations, thus we free all of them here.
2163 This is so we have a finer control over which locations' conditions are
2164 being evaluated by GDB or the remote stub. */
2165 if (null_condition_or_parse_error
)
2167 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2170 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2172 /* Only go as far as the first NULL bytecode is
2174 if (!loc
->cond_bytecode
)
2177 loc
->cond_bytecode
.reset ();
2182 /* No NULL conditions or failed bytecode generation. Build a condition list
2183 for this location's address. */
2184 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2188 && is_breakpoint (loc
->owner
)
2189 && loc
->pspace
->num
== bl
->pspace
->num
2190 && loc
->owner
->enable_state
== bp_enabled
2193 /* Add the condition to the vector. This will be used later
2194 to send the conditions to the target. */
2195 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2202 /* Parses a command described by string CMD into an agent expression
2203 bytecode suitable for evaluation by the bytecode interpreter.
2204 Return NULL if there was any error during parsing. */
2206 static agent_expr_up
2207 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2209 const char *cmdrest
;
2210 const char *format_start
, *format_end
;
2211 struct gdbarch
*gdbarch
= get_current_arch ();
2218 if (*cmdrest
== ',')
2220 cmdrest
= skip_spaces (cmdrest
);
2222 if (*cmdrest
++ != '"')
2223 error (_("No format string following the location"));
2225 format_start
= cmdrest
;
2227 format_pieces
fpieces (&cmdrest
);
2229 format_end
= cmdrest
;
2231 if (*cmdrest
++ != '"')
2232 error (_("Bad format string, non-terminated '\"'."));
2234 cmdrest
= skip_spaces (cmdrest
);
2236 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2237 error (_("Invalid argument syntax"));
2239 if (*cmdrest
== ',')
2241 cmdrest
= skip_spaces (cmdrest
);
2243 /* For each argument, make an expression. */
2245 std::vector
<struct expression
*> argvec
;
2246 while (*cmdrest
!= '\0')
2251 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2252 argvec
.push_back (expr
.release ());
2254 if (*cmdrest
== ',')
2258 agent_expr_up aexpr
;
2260 /* We don't want to stop processing, so catch any errors
2261 that may show up. */
2264 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2265 format_start
, format_end
- format_start
,
2266 argvec
.size (), argvec
.data ());
2268 catch (const gdb_exception_error
&ex
)
2270 /* If we got here, it means the command could not be parsed to a valid
2271 bytecode expression and thus can't be evaluated on the target's side.
2272 It's no use iterating through the other commands. */
2275 /* We have a valid agent expression, return it. */
2279 /* Based on location BL, create a list of breakpoint commands to be
2280 passed on to the target. If we have duplicated locations with
2281 different commands, we will add any such to the list. */
2284 build_target_command_list (struct bp_location
*bl
)
2286 struct bp_location
**locp
= NULL
, **loc2p
;
2287 int null_command_or_parse_error
= 0;
2288 int modified
= bl
->needs_update
;
2289 struct bp_location
*loc
;
2291 /* Clear commands left over from a previous insert. */
2292 bl
->target_info
.tcommands
.clear ();
2294 if (!target_can_run_breakpoint_commands ())
2297 /* For now, limit to agent-style dprintf breakpoints. */
2298 if (dprintf_style
!= dprintf_style_agent
)
2301 /* For now, if we have any duplicate location that isn't a dprintf,
2302 don't install the target-side commands, as that would make the
2303 breakpoint not be reported to the core, and we'd lose
2305 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2308 if (is_breakpoint (loc
->owner
)
2309 && loc
->pspace
->num
== bl
->pspace
->num
2310 && loc
->owner
->type
!= bp_dprintf
)
2314 /* Do a first pass to check for locations with no assigned
2315 conditions or conditions that fail to parse to a valid agent expression
2316 bytecode. If any of these happen, then it's no use to send conditions
2317 to the target since this location will always trigger and generate a
2318 response back to GDB. */
2319 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2322 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2326 /* Re-parse the commands since something changed. In that
2327 case we already freed the command bytecodes (see
2328 force_breakpoint_reinsertion). We just
2329 need to parse the command to bytecodes again. */
2331 = parse_cmd_to_aexpr (bl
->address
,
2332 loc
->owner
->extra_string
);
2335 /* If we have a NULL bytecode expression, it means something
2336 went wrong or we have a null command expression. */
2337 if (!loc
->cmd_bytecode
)
2339 null_command_or_parse_error
= 1;
2345 /* If anything failed, then we're not doing target-side commands,
2347 if (null_command_or_parse_error
)
2349 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2352 if (is_breakpoint (loc
->owner
)
2353 && loc
->pspace
->num
== bl
->pspace
->num
)
2355 /* Only go as far as the first NULL bytecode is
2357 if (loc
->cmd_bytecode
== NULL
)
2360 loc
->cmd_bytecode
.reset ();
2365 /* No NULL commands or failed bytecode generation. Build a command list
2366 for this location's address. */
2367 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2370 if (loc
->owner
->extra_string
2371 && is_breakpoint (loc
->owner
)
2372 && loc
->pspace
->num
== bl
->pspace
->num
2373 && loc
->owner
->enable_state
== bp_enabled
2376 /* Add the command to the vector. This will be used later
2377 to send the commands to the target. */
2378 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2382 bl
->target_info
.persist
= 0;
2383 /* Maybe flag this location as persistent. */
2384 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2385 bl
->target_info
.persist
= 1;
2388 /* Return the kind of breakpoint on address *ADDR. Get the kind
2389 of breakpoint according to ADDR except single-step breakpoint.
2390 Get the kind of single-step breakpoint according to the current
2394 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2396 if (bl
->owner
->type
== bp_single_step
)
2398 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2399 struct regcache
*regcache
;
2401 regcache
= get_thread_regcache (thr
);
2403 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2407 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2410 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2411 location. Any error messages are printed to TMP_ERROR_STREAM; and
2412 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2413 Returns 0 for success, 1 if the bp_location type is not supported or
2416 NOTE drow/2003-09-09: This routine could be broken down to an
2417 object-style method for each breakpoint or catchpoint type. */
2419 insert_bp_location (struct bp_location
*bl
,
2420 struct ui_file
*tmp_error_stream
,
2421 int *disabled_breaks
,
2422 int *hw_breakpoint_error
,
2423 int *hw_bp_error_explained_already
)
2425 gdb_exception bp_excpt
;
2427 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2430 /* Note we don't initialize bl->target_info, as that wipes out
2431 the breakpoint location's shadow_contents if the breakpoint
2432 is still inserted at that location. This in turn breaks
2433 target_read_memory which depends on these buffers when
2434 a memory read is requested at the breakpoint location:
2435 Once the target_info has been wiped, we fail to see that
2436 we have a breakpoint inserted at that address and thus
2437 read the breakpoint instead of returning the data saved in
2438 the breakpoint location's shadow contents. */
2439 bl
->target_info
.reqstd_address
= bl
->address
;
2440 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2441 bl
->target_info
.length
= bl
->length
;
2443 /* When working with target-side conditions, we must pass all the conditions
2444 for the same breakpoint address down to the target since GDB will not
2445 insert those locations. With a list of breakpoint conditions, the target
2446 can decide when to stop and notify GDB. */
2448 if (is_breakpoint (bl
->owner
))
2450 build_target_condition_list (bl
);
2451 build_target_command_list (bl
);
2452 /* Reset the modification marker. */
2453 bl
->needs_update
= 0;
2456 if (bl
->loc_type
== bp_loc_software_breakpoint
2457 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2459 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2461 /* If the explicitly specified breakpoint type
2462 is not hardware breakpoint, check the memory map to see
2463 if the breakpoint address is in read only memory or not.
2465 Two important cases are:
2466 - location type is not hardware breakpoint, memory
2467 is readonly. We change the type of the location to
2468 hardware breakpoint.
2469 - location type is hardware breakpoint, memory is
2470 read-write. This means we've previously made the
2471 location hardware one, but then the memory map changed,
2474 When breakpoints are removed, remove_breakpoints will use
2475 location types we've just set here, the only possible
2476 problem is that memory map has changed during running
2477 program, but it's not going to work anyway with current
2479 struct mem_region
*mr
2480 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2484 if (automatic_hardware_breakpoints
)
2486 enum bp_loc_type new_type
;
2488 if (mr
->attrib
.mode
!= MEM_RW
)
2489 new_type
= bp_loc_hardware_breakpoint
;
2491 new_type
= bp_loc_software_breakpoint
;
2493 if (new_type
!= bl
->loc_type
)
2495 static int said
= 0;
2497 bl
->loc_type
= new_type
;
2500 fprintf_filtered (gdb_stdout
,
2501 _("Note: automatically using "
2502 "hardware breakpoints for "
2503 "read-only addresses.\n"));
2508 else if (bl
->loc_type
== bp_loc_software_breakpoint
2509 && mr
->attrib
.mode
!= MEM_RW
)
2511 fprintf_unfiltered (tmp_error_stream
,
2512 _("Cannot insert breakpoint %d.\n"
2513 "Cannot set software breakpoint "
2514 "at read-only address %s\n"),
2516 paddress (bl
->gdbarch
, bl
->address
));
2522 /* First check to see if we have to handle an overlay. */
2523 if (overlay_debugging
== ovly_off
2524 || bl
->section
== NULL
2525 || !(section_is_overlay (bl
->section
)))
2527 /* No overlay handling: just set the breakpoint. */
2532 val
= bl
->owner
->ops
->insert_location (bl
);
2534 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2536 catch (gdb_exception
&e
)
2538 bp_excpt
= std::move (e
);
2543 /* This breakpoint is in an overlay section.
2544 Shall we set a breakpoint at the LMA? */
2545 if (!overlay_events_enabled
)
2547 /* Yes -- overlay event support is not active,
2548 so we must try to set a breakpoint at the LMA.
2549 This will not work for a hardware breakpoint. */
2550 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2551 warning (_("hardware breakpoint %d not supported in overlay!"),
2555 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2557 /* Set a software (trap) breakpoint at the LMA. */
2558 bl
->overlay_target_info
= bl
->target_info
;
2559 bl
->overlay_target_info
.reqstd_address
= addr
;
2561 /* No overlay handling: just set the breakpoint. */
2566 bl
->overlay_target_info
.kind
2567 = breakpoint_kind (bl
, &addr
);
2568 bl
->overlay_target_info
.placed_address
= addr
;
2569 val
= target_insert_breakpoint (bl
->gdbarch
,
2570 &bl
->overlay_target_info
);
2573 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2575 catch (gdb_exception
&e
)
2577 bp_excpt
= std::move (e
);
2580 if (bp_excpt
.reason
!= 0)
2581 fprintf_unfiltered (tmp_error_stream
,
2582 "Overlay breakpoint %d "
2583 "failed: in ROM?\n",
2587 /* Shall we set a breakpoint at the VMA? */
2588 if (section_is_mapped (bl
->section
))
2590 /* Yes. This overlay section is mapped into memory. */
2595 val
= bl
->owner
->ops
->insert_location (bl
);
2597 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2599 catch (gdb_exception
&e
)
2601 bp_excpt
= std::move (e
);
2606 /* No. This breakpoint will not be inserted.
2607 No error, but do not mark the bp as 'inserted'. */
2612 if (bp_excpt
.reason
!= 0)
2614 /* Can't set the breakpoint. */
2616 /* In some cases, we might not be able to insert a
2617 breakpoint in a shared library that has already been
2618 removed, but we have not yet processed the shlib unload
2619 event. Unfortunately, some targets that implement
2620 breakpoint insertion themselves can't tell why the
2621 breakpoint insertion failed (e.g., the remote target
2622 doesn't define error codes), so we must treat generic
2623 errors as memory errors. */
2624 if (bp_excpt
.reason
== RETURN_ERROR
2625 && (bp_excpt
.error
== GENERIC_ERROR
2626 || bp_excpt
.error
== MEMORY_ERROR
)
2627 && bl
->loc_type
== bp_loc_software_breakpoint
2628 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2629 || shared_objfile_contains_address_p (bl
->pspace
,
2632 /* See also: disable_breakpoints_in_shlibs. */
2633 bl
->shlib_disabled
= 1;
2634 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2635 if (!*disabled_breaks
)
2637 fprintf_unfiltered (tmp_error_stream
,
2638 "Cannot insert breakpoint %d.\n",
2640 fprintf_unfiltered (tmp_error_stream
,
2641 "Temporarily disabling shared "
2642 "library breakpoints:\n");
2644 *disabled_breaks
= 1;
2645 fprintf_unfiltered (tmp_error_stream
,
2646 "breakpoint #%d\n", bl
->owner
->number
);
2651 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2653 *hw_breakpoint_error
= 1;
2654 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2655 fprintf_unfiltered (tmp_error_stream
,
2656 "Cannot insert hardware breakpoint %d%s",
2658 bp_excpt
.message
? ":" : ".\n");
2659 if (bp_excpt
.message
!= NULL
)
2660 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2665 if (bp_excpt
.message
== NULL
)
2668 = memory_error_message (TARGET_XFER_E_IO
,
2669 bl
->gdbarch
, bl
->address
);
2671 fprintf_unfiltered (tmp_error_stream
,
2672 "Cannot insert breakpoint %d.\n"
2674 bl
->owner
->number
, message
.c_str ());
2678 fprintf_unfiltered (tmp_error_stream
,
2679 "Cannot insert breakpoint %d: %s\n",
2694 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2695 /* NOTE drow/2003-09-08: This state only exists for removing
2696 watchpoints. It's not clear that it's necessary... */
2697 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2701 gdb_assert (bl
->owner
->ops
!= NULL
2702 && bl
->owner
->ops
->insert_location
!= NULL
);
2704 val
= bl
->owner
->ops
->insert_location (bl
);
2706 /* If trying to set a read-watchpoint, and it turns out it's not
2707 supported, try emulating one with an access watchpoint. */
2708 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2710 struct bp_location
*loc
, **loc_temp
;
2712 /* But don't try to insert it, if there's already another
2713 hw_access location that would be considered a duplicate
2715 ALL_BP_LOCATIONS (loc
, loc_temp
)
2717 && loc
->watchpoint_type
== hw_access
2718 && watchpoint_locations_match (bl
, loc
))
2722 bl
->target_info
= loc
->target_info
;
2723 bl
->watchpoint_type
= hw_access
;
2730 bl
->watchpoint_type
= hw_access
;
2731 val
= bl
->owner
->ops
->insert_location (bl
);
2734 /* Back to the original value. */
2735 bl
->watchpoint_type
= hw_read
;
2739 bl
->inserted
= (val
== 0);
2742 else if (bl
->owner
->type
== bp_catchpoint
)
2746 gdb_assert (bl
->owner
->ops
!= NULL
2747 && bl
->owner
->ops
->insert_location
!= NULL
);
2749 val
= bl
->owner
->ops
->insert_location (bl
);
2752 bl
->owner
->enable_state
= bp_disabled
;
2756 Error inserting catchpoint %d: Your system does not support this type\n\
2757 of catchpoint."), bl
->owner
->number
);
2759 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2762 bl
->inserted
= (val
== 0);
2764 /* We've already printed an error message if there was a problem
2765 inserting this catchpoint, and we've disabled the catchpoint,
2766 so just return success. */
2773 /* This function is called when program space PSPACE is about to be
2774 deleted. It takes care of updating breakpoints to not reference
2778 breakpoint_program_space_exit (struct program_space
*pspace
)
2780 struct breakpoint
*b
, *b_temp
;
2781 struct bp_location
*loc
, **loc_temp
;
2783 /* Remove any breakpoint that was set through this program space. */
2784 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2786 if (b
->pspace
== pspace
)
2787 delete_breakpoint (b
);
2790 /* Breakpoints set through other program spaces could have locations
2791 bound to PSPACE as well. Remove those. */
2792 ALL_BP_LOCATIONS (loc
, loc_temp
)
2794 struct bp_location
*tmp
;
2796 if (loc
->pspace
== pspace
)
2798 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2799 if (loc
->owner
->loc
== loc
)
2800 loc
->owner
->loc
= loc
->next
;
2802 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2803 if (tmp
->next
== loc
)
2805 tmp
->next
= loc
->next
;
2811 /* Now update the global location list to permanently delete the
2812 removed locations above. */
2813 update_global_location_list (UGLL_DONT_INSERT
);
2816 /* Make sure all breakpoints are inserted in inferior.
2817 Throws exception on any error.
2818 A breakpoint that is already inserted won't be inserted
2819 again, so calling this function twice is safe. */
2821 insert_breakpoints (void)
2823 struct breakpoint
*bpt
;
2825 ALL_BREAKPOINTS (bpt
)
2826 if (is_hardware_watchpoint (bpt
))
2828 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2830 update_watchpoint (w
, 0 /* don't reparse. */);
2833 /* Updating watchpoints creates new locations, so update the global
2834 location list. Explicitly tell ugll to insert locations and
2835 ignore breakpoints_always_inserted_mode. */
2836 update_global_location_list (UGLL_INSERT
);
2839 /* Invoke CALLBACK for each of bp_location. */
2842 iterate_over_bp_locations (walk_bp_location_callback callback
)
2844 struct bp_location
*loc
, **loc_tmp
;
2846 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2848 callback (loc
, NULL
);
2852 /* This is used when we need to synch breakpoint conditions between GDB and the
2853 target. It is the case with deleting and disabling of breakpoints when using
2854 always-inserted mode. */
2857 update_inserted_breakpoint_locations (void)
2859 struct bp_location
*bl
, **blp_tmp
;
2862 int disabled_breaks
= 0;
2863 int hw_breakpoint_error
= 0;
2864 int hw_bp_details_reported
= 0;
2866 string_file tmp_error_stream
;
2868 /* Explicitly mark the warning -- this will only be printed if
2869 there was an error. */
2870 tmp_error_stream
.puts ("Warning:\n");
2872 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2874 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2876 /* We only want to update software breakpoints and hardware
2878 if (!is_breakpoint (bl
->owner
))
2881 /* We only want to update locations that are already inserted
2882 and need updating. This is to avoid unwanted insertion during
2883 deletion of breakpoints. */
2884 if (!bl
->inserted
|| !bl
->needs_update
)
2887 switch_to_program_space_and_thread (bl
->pspace
);
2889 /* For targets that support global breakpoints, there's no need
2890 to select an inferior to insert breakpoint to. In fact, even
2891 if we aren't attached to any process yet, we should still
2892 insert breakpoints. */
2893 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2894 && inferior_ptid
== null_ptid
)
2897 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2898 &hw_breakpoint_error
, &hw_bp_details_reported
);
2905 target_terminal::ours_for_output ();
2906 error_stream (tmp_error_stream
);
2910 /* Used when starting or continuing the program. */
2913 insert_breakpoint_locations (void)
2915 struct breakpoint
*bpt
;
2916 struct bp_location
*bl
, **blp_tmp
;
2919 int disabled_breaks
= 0;
2920 int hw_breakpoint_error
= 0;
2921 int hw_bp_error_explained_already
= 0;
2923 string_file tmp_error_stream
;
2925 /* Explicitly mark the warning -- this will only be printed if
2926 there was an error. */
2927 tmp_error_stream
.puts ("Warning:\n");
2929 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2931 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2933 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2936 /* There is no point inserting thread-specific breakpoints if
2937 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2938 has BL->OWNER always non-NULL. */
2939 if (bl
->owner
->thread
!= -1
2940 && !valid_global_thread_id (bl
->owner
->thread
))
2943 switch_to_program_space_and_thread (bl
->pspace
);
2945 /* For targets that support global breakpoints, there's no need
2946 to select an inferior to insert breakpoint to. In fact, even
2947 if we aren't attached to any process yet, we should still
2948 insert breakpoints. */
2949 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2950 && inferior_ptid
== null_ptid
)
2953 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2954 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
2959 /* If we failed to insert all locations of a watchpoint, remove
2960 them, as half-inserted watchpoint is of limited use. */
2961 ALL_BREAKPOINTS (bpt
)
2963 int some_failed
= 0;
2964 struct bp_location
*loc
;
2966 if (!is_hardware_watchpoint (bpt
))
2969 if (!breakpoint_enabled (bpt
))
2972 if (bpt
->disposition
== disp_del_at_next_stop
)
2975 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2976 if (!loc
->inserted
&& should_be_inserted (loc
))
2983 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2985 remove_breakpoint (loc
);
2987 hw_breakpoint_error
= 1;
2988 tmp_error_stream
.printf ("Could not insert "
2989 "hardware watchpoint %d.\n",
2997 /* If a hardware breakpoint or watchpoint was inserted, add a
2998 message about possibly exhausted resources. */
2999 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3001 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3002 You may have requested too many hardware breakpoints/watchpoints.\n");
3004 target_terminal::ours_for_output ();
3005 error_stream (tmp_error_stream
);
3009 /* Used when the program stops.
3010 Returns zero if successful, or non-zero if there was a problem
3011 removing a breakpoint location. */
3014 remove_breakpoints (void)
3016 struct bp_location
*bl
, **blp_tmp
;
3019 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3021 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3022 val
|= remove_breakpoint (bl
);
3027 /* When a thread exits, remove breakpoints that are related to
3031 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3033 struct breakpoint
*b
, *b_tmp
;
3035 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3037 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3039 b
->disposition
= disp_del_at_next_stop
;
3041 printf_filtered (_("\
3042 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3043 b
->number
, print_thread_id (tp
));
3045 /* Hide it from the user. */
3051 /* See breakpoint.h. */
3054 remove_breakpoints_inf (inferior
*inf
)
3056 struct bp_location
*bl
, **blp_tmp
;
3059 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3061 if (bl
->pspace
!= inf
->pspace
)
3064 if (bl
->inserted
&& !bl
->target_info
.persist
)
3066 val
= remove_breakpoint (bl
);
3073 static int internal_breakpoint_number
= -1;
3075 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3076 If INTERNAL is non-zero, the breakpoint number will be populated
3077 from internal_breakpoint_number and that variable decremented.
3078 Otherwise the breakpoint number will be populated from
3079 breakpoint_count and that value incremented. Internal breakpoints
3080 do not set the internal var bpnum. */
3082 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3085 b
->number
= internal_breakpoint_number
--;
3088 set_breakpoint_count (breakpoint_count
+ 1);
3089 b
->number
= breakpoint_count
;
3093 static struct breakpoint
*
3094 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3095 CORE_ADDR address
, enum bptype type
,
3096 const struct breakpoint_ops
*ops
)
3098 symtab_and_line sal
;
3100 sal
.section
= find_pc_overlay (sal
.pc
);
3101 sal
.pspace
= current_program_space
;
3103 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3104 b
->number
= internal_breakpoint_number
--;
3105 b
->disposition
= disp_donttouch
;
3110 static const char *const longjmp_names
[] =
3112 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3114 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3116 /* Per-objfile data private to breakpoint.c. */
3117 struct breakpoint_objfile_data
3119 /* Minimal symbol for "_ovly_debug_event" (if any). */
3120 struct bound_minimal_symbol overlay_msym
{};
3122 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3123 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3125 /* True if we have looked for longjmp probes. */
3126 int longjmp_searched
= 0;
3128 /* SystemTap probe points for longjmp (if any). These are non-owning
3130 std::vector
<probe
*> longjmp_probes
;
3132 /* Minimal symbol for "std::terminate()" (if any). */
3133 struct bound_minimal_symbol terminate_msym
{};
3135 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3136 struct bound_minimal_symbol exception_msym
{};
3138 /* True if we have looked for exception probes. */
3139 int exception_searched
= 0;
3141 /* SystemTap probe points for unwinding (if any). These are non-owning
3143 std::vector
<probe
*> exception_probes
;
3146 static const struct objfile_key
<breakpoint_objfile_data
>
3147 breakpoint_objfile_key
;
3149 /* Minimal symbol not found sentinel. */
3150 static struct minimal_symbol msym_not_found
;
3152 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3155 msym_not_found_p (const struct minimal_symbol
*msym
)
3157 return msym
== &msym_not_found
;
3160 /* Return per-objfile data needed by breakpoint.c.
3161 Allocate the data if necessary. */
3163 static struct breakpoint_objfile_data
*
3164 get_breakpoint_objfile_data (struct objfile
*objfile
)
3166 struct breakpoint_objfile_data
*bp_objfile_data
;
3168 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3169 if (bp_objfile_data
== NULL
)
3170 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3171 return bp_objfile_data
;
3175 create_overlay_event_breakpoint (void)
3177 const char *const func_name
= "_ovly_debug_event";
3179 for (objfile
*objfile
: current_program_space
->objfiles ())
3181 struct breakpoint
*b
;
3182 struct breakpoint_objfile_data
*bp_objfile_data
;
3184 struct explicit_location explicit_loc
;
3186 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3188 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3191 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3193 struct bound_minimal_symbol m
;
3195 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3196 if (m
.minsym
== NULL
)
3198 /* Avoid future lookups in this objfile. */
3199 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3202 bp_objfile_data
->overlay_msym
= m
;
3205 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3206 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3208 &internal_breakpoint_ops
);
3209 initialize_explicit_location (&explicit_loc
);
3210 explicit_loc
.function_name
= ASTRDUP (func_name
);
3211 b
->location
= new_explicit_location (&explicit_loc
);
3213 if (overlay_debugging
== ovly_auto
)
3215 b
->enable_state
= bp_enabled
;
3216 overlay_events_enabled
= 1;
3220 b
->enable_state
= bp_disabled
;
3221 overlay_events_enabled
= 0;
3227 create_longjmp_master_breakpoint (void)
3229 struct program_space
*pspace
;
3231 scoped_restore_current_program_space restore_pspace
;
3233 ALL_PSPACES (pspace
)
3235 set_current_program_space (pspace
);
3237 for (objfile
*objfile
: current_program_space
->objfiles ())
3240 struct gdbarch
*gdbarch
;
3241 struct breakpoint_objfile_data
*bp_objfile_data
;
3243 gdbarch
= get_objfile_arch (objfile
);
3245 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3247 if (!bp_objfile_data
->longjmp_searched
)
3249 std::vector
<probe
*> ret
3250 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3254 /* We are only interested in checking one element. */
3257 if (!p
->can_evaluate_arguments ())
3259 /* We cannot use the probe interface here, because it does
3260 not know how to evaluate arguments. */
3264 bp_objfile_data
->longjmp_probes
= ret
;
3265 bp_objfile_data
->longjmp_searched
= 1;
3268 if (!bp_objfile_data
->longjmp_probes
.empty ())
3270 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3272 struct breakpoint
*b
;
3274 b
= create_internal_breakpoint (gdbarch
,
3275 p
->get_relocated_address (objfile
),
3277 &internal_breakpoint_ops
);
3278 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3279 b
->enable_state
= bp_disabled
;
3285 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3288 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3290 struct breakpoint
*b
;
3291 const char *func_name
;
3293 struct explicit_location explicit_loc
;
3295 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3298 func_name
= longjmp_names
[i
];
3299 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3301 struct bound_minimal_symbol m
;
3303 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3304 if (m
.minsym
== NULL
)
3306 /* Prevent future lookups in this objfile. */
3307 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3310 bp_objfile_data
->longjmp_msym
[i
] = m
;
3313 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3314 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3315 &internal_breakpoint_ops
);
3316 initialize_explicit_location (&explicit_loc
);
3317 explicit_loc
.function_name
= ASTRDUP (func_name
);
3318 b
->location
= new_explicit_location (&explicit_loc
);
3319 b
->enable_state
= bp_disabled
;
3325 /* Create a master std::terminate breakpoint. */
3327 create_std_terminate_master_breakpoint (void)
3329 struct program_space
*pspace
;
3330 const char *const func_name
= "std::terminate()";
3332 scoped_restore_current_program_space restore_pspace
;
3334 ALL_PSPACES (pspace
)
3338 set_current_program_space (pspace
);
3340 for (objfile
*objfile
: current_program_space
->objfiles ())
3342 struct breakpoint
*b
;
3343 struct breakpoint_objfile_data
*bp_objfile_data
;
3344 struct explicit_location explicit_loc
;
3346 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3348 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3351 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3353 struct bound_minimal_symbol m
;
3355 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3356 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3357 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3359 /* Prevent future lookups in this objfile. */
3360 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3363 bp_objfile_data
->terminate_msym
= m
;
3366 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3367 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3368 bp_std_terminate_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
;
3378 /* Install a master breakpoint on the unwinder's debug hook. */
3381 create_exception_master_breakpoint (void)
3383 const char *const func_name
= "_Unwind_DebugHook";
3385 for (objfile
*objfile
: current_program_space
->objfiles ())
3387 struct breakpoint
*b
;
3388 struct gdbarch
*gdbarch
;
3389 struct breakpoint_objfile_data
*bp_objfile_data
;
3391 struct explicit_location explicit_loc
;
3393 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3395 /* We prefer the SystemTap probe point if it exists. */
3396 if (!bp_objfile_data
->exception_searched
)
3398 std::vector
<probe
*> ret
3399 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3403 /* We are only interested in checking one element. */
3406 if (!p
->can_evaluate_arguments ())
3408 /* We cannot use the probe interface here, because it does
3409 not know how to evaluate arguments. */
3413 bp_objfile_data
->exception_probes
= ret
;
3414 bp_objfile_data
->exception_searched
= 1;
3417 if (!bp_objfile_data
->exception_probes
.empty ())
3419 gdbarch
= get_objfile_arch (objfile
);
3421 for (probe
*p
: bp_objfile_data
->exception_probes
)
3423 b
= create_internal_breakpoint (gdbarch
,
3424 p
->get_relocated_address (objfile
),
3425 bp_exception_master
,
3426 &internal_breakpoint_ops
);
3427 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3428 b
->enable_state
= bp_disabled
;
3434 /* Otherwise, try the hook function. */
3436 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3439 gdbarch
= get_objfile_arch (objfile
);
3441 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3443 struct bound_minimal_symbol debug_hook
;
3445 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3446 if (debug_hook
.minsym
== NULL
)
3448 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3452 bp_objfile_data
->exception_msym
= debug_hook
;
3455 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3456 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3457 current_top_target ());
3458 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3459 &internal_breakpoint_ops
);
3460 initialize_explicit_location (&explicit_loc
);
3461 explicit_loc
.function_name
= ASTRDUP (func_name
);
3462 b
->location
= new_explicit_location (&explicit_loc
);
3463 b
->enable_state
= bp_disabled
;
3467 /* Does B have a location spec? */
3470 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3472 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3476 update_breakpoints_after_exec (void)
3478 struct breakpoint
*b
, *b_tmp
;
3479 struct bp_location
*bploc
, **bplocp_tmp
;
3481 /* We're about to delete breakpoints from GDB's lists. If the
3482 INSERTED flag is true, GDB will try to lift the breakpoints by
3483 writing the breakpoints' "shadow contents" back into memory. The
3484 "shadow contents" are NOT valid after an exec, so GDB should not
3485 do that. Instead, the target is responsible from marking
3486 breakpoints out as soon as it detects an exec. We don't do that
3487 here instead, because there may be other attempts to delete
3488 breakpoints after detecting an exec and before reaching here. */
3489 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3490 if (bploc
->pspace
== current_program_space
)
3491 gdb_assert (!bploc
->inserted
);
3493 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3495 if (b
->pspace
!= current_program_space
)
3498 /* Solib breakpoints must be explicitly reset after an exec(). */
3499 if (b
->type
== bp_shlib_event
)
3501 delete_breakpoint (b
);
3505 /* JIT breakpoints must be explicitly reset after an exec(). */
3506 if (b
->type
== bp_jit_event
)
3508 delete_breakpoint (b
);
3512 /* Thread event breakpoints must be set anew after an exec(),
3513 as must overlay event and longjmp master breakpoints. */
3514 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3515 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3516 || b
->type
== bp_exception_master
)
3518 delete_breakpoint (b
);
3522 /* Step-resume breakpoints are meaningless after an exec(). */
3523 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3525 delete_breakpoint (b
);
3529 /* Just like single-step breakpoints. */
3530 if (b
->type
== bp_single_step
)
3532 delete_breakpoint (b
);
3536 /* Longjmp and longjmp-resume breakpoints are also meaningless
3538 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3539 || b
->type
== bp_longjmp_call_dummy
3540 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3542 delete_breakpoint (b
);
3546 if (b
->type
== bp_catchpoint
)
3548 /* For now, none of the bp_catchpoint breakpoints need to
3549 do anything at this point. In the future, if some of
3550 the catchpoints need to something, we will need to add
3551 a new method, and call this method from here. */
3555 /* bp_finish is a special case. The only way we ought to be able
3556 to see one of these when an exec() has happened, is if the user
3557 caught a vfork, and then said "finish". Ordinarily a finish just
3558 carries them to the call-site of the current callee, by setting
3559 a temporary bp there and resuming. But in this case, the finish
3560 will carry them entirely through the vfork & exec.
3562 We don't want to allow a bp_finish to remain inserted now. But
3563 we can't safely delete it, 'cause finish_command has a handle to
3564 the bp on a bpstat, and will later want to delete it. There's a
3565 chance (and I've seen it happen) that if we delete the bp_finish
3566 here, that its storage will get reused by the time finish_command
3567 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3568 We really must allow finish_command to delete a bp_finish.
3570 In the absence of a general solution for the "how do we know
3571 it's safe to delete something others may have handles to?"
3572 problem, what we'll do here is just uninsert the bp_finish, and
3573 let finish_command delete it.
3575 (We know the bp_finish is "doomed" in the sense that it's
3576 momentary, and will be deleted as soon as finish_command sees
3577 the inferior stopped. So it doesn't matter that the bp's
3578 address is probably bogus in the new a.out, unlike e.g., the
3579 solib breakpoints.) */
3581 if (b
->type
== bp_finish
)
3586 /* Without a symbolic address, we have little hope of the
3587 pre-exec() address meaning the same thing in the post-exec()
3589 if (breakpoint_event_location_empty_p (b
))
3591 delete_breakpoint (b
);
3598 detach_breakpoints (ptid_t ptid
)
3600 struct bp_location
*bl
, **blp_tmp
;
3602 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3603 struct inferior
*inf
= current_inferior ();
3605 if (ptid
.pid () == inferior_ptid
.pid ())
3606 error (_("Cannot detach breakpoints of inferior_ptid"));
3608 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3609 inferior_ptid
= ptid
;
3610 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3612 if (bl
->pspace
!= inf
->pspace
)
3615 /* This function must physically remove breakpoints locations
3616 from the specified ptid, without modifying the breakpoint
3617 package's state. Locations of type bp_loc_other are only
3618 maintained at GDB side. So, there is no need to remove
3619 these bp_loc_other locations. Moreover, removing these
3620 would modify the breakpoint package's state. */
3621 if (bl
->loc_type
== bp_loc_other
)
3625 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3631 /* Remove the breakpoint location BL from the current address space.
3632 Note that this is used to detach breakpoints from a child fork.
3633 When we get here, the child isn't in the inferior list, and neither
3634 do we have objects to represent its address space --- we should
3635 *not* look at bl->pspace->aspace here. */
3638 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3642 /* BL is never in moribund_locations by our callers. */
3643 gdb_assert (bl
->owner
!= NULL
);
3645 /* The type of none suggests that owner is actually deleted.
3646 This should not ever happen. */
3647 gdb_assert (bl
->owner
->type
!= bp_none
);
3649 if (bl
->loc_type
== bp_loc_software_breakpoint
3650 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3652 /* "Normal" instruction breakpoint: either the standard
3653 trap-instruction bp (bp_breakpoint), or a
3654 bp_hardware_breakpoint. */
3656 /* First check to see if we have to handle an overlay. */
3657 if (overlay_debugging
== ovly_off
3658 || bl
->section
== NULL
3659 || !(section_is_overlay (bl
->section
)))
3661 /* No overlay handling: just remove the breakpoint. */
3663 /* If we're trying to uninsert a memory breakpoint that we
3664 know is set in a dynamic object that is marked
3665 shlib_disabled, then either the dynamic object was
3666 removed with "remove-symbol-file" or with
3667 "nosharedlibrary". In the former case, we don't know
3668 whether another dynamic object might have loaded over the
3669 breakpoint's address -- the user might well let us know
3670 about it next with add-symbol-file (the whole point of
3671 add-symbol-file is letting the user manually maintain a
3672 list of dynamically loaded objects). If we have the
3673 breakpoint's shadow memory, that is, this is a software
3674 breakpoint managed by GDB, check whether the breakpoint
3675 is still inserted in memory, to avoid overwriting wrong
3676 code with stale saved shadow contents. Note that HW
3677 breakpoints don't have shadow memory, as they're
3678 implemented using a mechanism that is not dependent on
3679 being able to modify the target's memory, and as such
3680 they should always be removed. */
3681 if (bl
->shlib_disabled
3682 && bl
->target_info
.shadow_len
!= 0
3683 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3686 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3690 /* This breakpoint is in an overlay section.
3691 Did we set a breakpoint at the LMA? */
3692 if (!overlay_events_enabled
)
3694 /* Yes -- overlay event support is not active, so we
3695 should have set a breakpoint at the LMA. Remove it.
3697 /* Ignore any failures: if the LMA is in ROM, we will
3698 have already warned when we failed to insert it. */
3699 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3700 target_remove_hw_breakpoint (bl
->gdbarch
,
3701 &bl
->overlay_target_info
);
3703 target_remove_breakpoint (bl
->gdbarch
,
3704 &bl
->overlay_target_info
,
3707 /* Did we set a breakpoint at the VMA?
3708 If so, we will have marked the breakpoint 'inserted'. */
3711 /* Yes -- remove it. Previously we did not bother to
3712 remove the breakpoint if the section had been
3713 unmapped, but let's not rely on that being safe. We
3714 don't know what the overlay manager might do. */
3716 /* However, we should remove *software* breakpoints only
3717 if the section is still mapped, or else we overwrite
3718 wrong code with the saved shadow contents. */
3719 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3720 || section_is_mapped (bl
->section
))
3721 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3727 /* No -- not inserted, so no need to remove. No error. */
3732 /* In some cases, we might not be able to remove a breakpoint in
3733 a shared library that has already been removed, but we have
3734 not yet processed the shlib unload event. Similarly for an
3735 unloaded add-symbol-file object - the user might not yet have
3736 had the chance to remove-symbol-file it. shlib_disabled will
3737 be set if the library/object has already been removed, but
3738 the breakpoint hasn't been uninserted yet, e.g., after
3739 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3740 always-inserted mode. */
3742 && (bl
->loc_type
== bp_loc_software_breakpoint
3743 && (bl
->shlib_disabled
3744 || solib_name_from_address (bl
->pspace
, bl
->address
)
3745 || shared_objfile_contains_address_p (bl
->pspace
,
3751 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3753 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3755 gdb_assert (bl
->owner
->ops
!= NULL
3756 && bl
->owner
->ops
->remove_location
!= NULL
);
3758 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3759 bl
->owner
->ops
->remove_location (bl
, reason
);
3761 /* Failure to remove any of the hardware watchpoints comes here. */
3762 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3763 warning (_("Could not remove hardware watchpoint %d."),
3766 else if (bl
->owner
->type
== bp_catchpoint
3767 && breakpoint_enabled (bl
->owner
)
3770 gdb_assert (bl
->owner
->ops
!= NULL
3771 && bl
->owner
->ops
->remove_location
!= NULL
);
3773 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3777 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3784 remove_breakpoint (struct bp_location
*bl
)
3786 /* BL is never in moribund_locations by our callers. */
3787 gdb_assert (bl
->owner
!= NULL
);
3789 /* The type of none suggests that owner is actually deleted.
3790 This should not ever happen. */
3791 gdb_assert (bl
->owner
->type
!= bp_none
);
3793 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3795 switch_to_program_space_and_thread (bl
->pspace
);
3797 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3800 /* Clear the "inserted" flag in all breakpoints. */
3803 mark_breakpoints_out (void)
3805 struct bp_location
*bl
, **blp_tmp
;
3807 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3808 if (bl
->pspace
== current_program_space
)
3812 /* Clear the "inserted" flag in all breakpoints and delete any
3813 breakpoints which should go away between runs of the program.
3815 Plus other such housekeeping that has to be done for breakpoints
3818 Note: this function gets called at the end of a run (by
3819 generic_mourn_inferior) and when a run begins (by
3820 init_wait_for_inferior). */
3825 breakpoint_init_inferior (enum inf_context context
)
3827 struct breakpoint
*b
, *b_tmp
;
3828 struct program_space
*pspace
= current_program_space
;
3830 /* If breakpoint locations are shared across processes, then there's
3832 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3835 mark_breakpoints_out ();
3837 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3839 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3845 case bp_longjmp_call_dummy
:
3847 /* If the call dummy breakpoint is at the entry point it will
3848 cause problems when the inferior is rerun, so we better get
3851 case bp_watchpoint_scope
:
3853 /* Also get rid of scope breakpoints. */
3855 case bp_shlib_event
:
3857 /* Also remove solib event breakpoints. Their addresses may
3858 have changed since the last time we ran the program.
3859 Actually we may now be debugging against different target;
3860 and so the solib backend that installed this breakpoint may
3861 not be used in by the target. E.g.,
3863 (gdb) file prog-linux
3864 (gdb) run # native linux target
3867 (gdb) file prog-win.exe
3868 (gdb) tar rem :9999 # remote Windows gdbserver.
3871 case bp_step_resume
:
3873 /* Also remove step-resume breakpoints. */
3875 case bp_single_step
:
3877 /* Also remove single-step breakpoints. */
3879 delete_breakpoint (b
);
3883 case bp_hardware_watchpoint
:
3884 case bp_read_watchpoint
:
3885 case bp_access_watchpoint
:
3887 struct watchpoint
*w
= (struct watchpoint
*) b
;
3889 /* Likewise for watchpoints on local expressions. */
3890 if (w
->exp_valid_block
!= NULL
)
3891 delete_breakpoint (b
);
3894 /* Get rid of existing locations, which are no longer
3895 valid. New ones will be created in
3896 update_watchpoint, when the inferior is restarted.
3897 The next update_global_location_list call will
3898 garbage collect them. */
3901 if (context
== inf_starting
)
3903 /* Reset val field to force reread of starting value in
3904 insert_breakpoints. */
3905 w
->val
.reset (nullptr);
3906 w
->val_valid
= false;
3916 /* Get rid of the moribund locations. */
3917 for (bp_location
*bl
: moribund_locations
)
3918 decref_bp_location (&bl
);
3919 moribund_locations
.clear ();
3922 /* These functions concern about actual breakpoints inserted in the
3923 target --- to e.g. check if we need to do decr_pc adjustment or if
3924 we need to hop over the bkpt --- so we check for address space
3925 match, not program space. */
3927 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3928 exists at PC. It returns ordinary_breakpoint_here if it's an
3929 ordinary breakpoint, or permanent_breakpoint_here if it's a
3930 permanent breakpoint.
3931 - When continuing from a location with an ordinary breakpoint, we
3932 actually single step once before calling insert_breakpoints.
3933 - When continuing from a location with a permanent breakpoint, we
3934 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3935 the target, to advance the PC past the breakpoint. */
3937 enum breakpoint_here
3938 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
3940 struct bp_location
*bl
, **blp_tmp
;
3941 int any_breakpoint_here
= 0;
3943 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3945 if (bl
->loc_type
!= bp_loc_software_breakpoint
3946 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3949 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3950 if ((breakpoint_enabled (bl
->owner
)
3952 && breakpoint_location_address_match (bl
, aspace
, pc
))
3954 if (overlay_debugging
3955 && section_is_overlay (bl
->section
)
3956 && !section_is_mapped (bl
->section
))
3957 continue; /* unmapped overlay -- can't be a match */
3958 else if (bl
->permanent
)
3959 return permanent_breakpoint_here
;
3961 any_breakpoint_here
= 1;
3965 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
3968 /* See breakpoint.h. */
3971 breakpoint_in_range_p (const address_space
*aspace
,
3972 CORE_ADDR addr
, ULONGEST len
)
3974 struct bp_location
*bl
, **blp_tmp
;
3976 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3978 if (bl
->loc_type
!= bp_loc_software_breakpoint
3979 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3982 if ((breakpoint_enabled (bl
->owner
)
3984 && breakpoint_location_address_range_overlap (bl
, aspace
,
3987 if (overlay_debugging
3988 && section_is_overlay (bl
->section
)
3989 && !section_is_mapped (bl
->section
))
3991 /* Unmapped overlay -- can't be a match. */
4002 /* Return true if there's a moribund breakpoint at PC. */
4005 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4007 for (bp_location
*loc
: moribund_locations
)
4008 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4014 /* Returns non-zero iff BL is inserted at PC, in address space
4018 bp_location_inserted_here_p (struct bp_location
*bl
,
4019 const address_space
*aspace
, CORE_ADDR pc
)
4022 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4025 if (overlay_debugging
4026 && section_is_overlay (bl
->section
)
4027 && !section_is_mapped (bl
->section
))
4028 return 0; /* unmapped overlay -- can't be a match */
4035 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4038 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4040 struct bp_location
**blp
, **blp_tmp
= NULL
;
4042 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4044 struct bp_location
*bl
= *blp
;
4046 if (bl
->loc_type
!= bp_loc_software_breakpoint
4047 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4050 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4056 /* This function returns non-zero iff there is a software breakpoint
4060 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4063 struct bp_location
**blp
, **blp_tmp
= NULL
;
4065 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4067 struct bp_location
*bl
= *blp
;
4069 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4072 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4079 /* See breakpoint.h. */
4082 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4085 struct bp_location
**blp
, **blp_tmp
= NULL
;
4087 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4089 struct bp_location
*bl
= *blp
;
4091 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4094 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4102 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4103 CORE_ADDR addr
, ULONGEST len
)
4105 struct breakpoint
*bpt
;
4107 ALL_BREAKPOINTS (bpt
)
4109 struct bp_location
*loc
;
4111 if (bpt
->type
!= bp_hardware_watchpoint
4112 && bpt
->type
!= bp_access_watchpoint
)
4115 if (!breakpoint_enabled (bpt
))
4118 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4119 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4123 /* Check for intersection. */
4124 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4125 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4133 /* See breakpoint.h. */
4136 is_catchpoint (struct breakpoint
*b
)
4138 return (b
->type
== bp_catchpoint
);
4141 /* Frees any storage that is part of a bpstat. Does not walk the
4144 bpstats::~bpstats ()
4146 if (bp_location_at
!= NULL
)
4147 decref_bp_location (&bp_location_at
);
4150 /* Clear a bpstat so that it says we are not at any breakpoint.
4151 Also free any storage that is part of a bpstat. */
4154 bpstat_clear (bpstat
*bsp
)
4171 bpstats::bpstats (const bpstats
&other
)
4173 bp_location_at (other
.bp_location_at
),
4174 breakpoint_at (other
.breakpoint_at
),
4175 commands (other
.commands
),
4176 print (other
.print
),
4178 print_it (other
.print_it
)
4180 if (other
.old_val
!= NULL
)
4181 old_val
= release_value (value_copy (other
.old_val
.get ()));
4182 incref_bp_location (bp_location_at
);
4185 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4186 is part of the bpstat is copied as well. */
4189 bpstat_copy (bpstat bs
)
4193 bpstat retval
= NULL
;
4198 for (; bs
!= NULL
; bs
= bs
->next
)
4200 tmp
= new bpstats (*bs
);
4203 /* This is the first thing in the chain. */
4213 /* Find the bpstat associated with this breakpoint. */
4216 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4221 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4223 if (bsp
->breakpoint_at
== breakpoint
)
4229 /* See breakpoint.h. */
4232 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4234 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4236 if (bsp
->breakpoint_at
== NULL
)
4238 /* A moribund location can never explain a signal other than
4240 if (sig
== GDB_SIGNAL_TRAP
)
4245 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4254 /* Put in *NUM the breakpoint number of the first breakpoint we are
4255 stopped at. *BSP upon return is a bpstat which points to the
4256 remaining breakpoints stopped at (but which is not guaranteed to be
4257 good for anything but further calls to bpstat_num).
4259 Return 0 if passed a bpstat which does not indicate any breakpoints.
4260 Return -1 if stopped at a breakpoint that has been deleted since
4262 Return 1 otherwise. */
4265 bpstat_num (bpstat
*bsp
, int *num
)
4267 struct breakpoint
*b
;
4270 return 0; /* No more breakpoint values */
4272 /* We assume we'll never have several bpstats that correspond to a
4273 single breakpoint -- otherwise, this function might return the
4274 same number more than once and this will look ugly. */
4275 b
= (*bsp
)->breakpoint_at
;
4276 *bsp
= (*bsp
)->next
;
4278 return -1; /* breakpoint that's been deleted since */
4280 *num
= b
->number
; /* We have its number */
4284 /* See breakpoint.h. */
4287 bpstat_clear_actions (void)
4291 if (inferior_ptid
== null_ptid
)
4294 thread_info
*tp
= inferior_thread ();
4295 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4297 bs
->commands
= NULL
;
4298 bs
->old_val
.reset (nullptr);
4302 /* Called when a command is about to proceed the inferior. */
4305 breakpoint_about_to_proceed (void)
4307 if (inferior_ptid
!= null_ptid
)
4309 struct thread_info
*tp
= inferior_thread ();
4311 /* Allow inferior function calls in breakpoint commands to not
4312 interrupt the command list. When the call finishes
4313 successfully, the inferior will be standing at the same
4314 breakpoint as if nothing happened. */
4315 if (tp
->control
.in_infcall
)
4319 breakpoint_proceeded
= 1;
4322 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4323 or its equivalent. */
4326 command_line_is_silent (struct command_line
*cmd
)
4328 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4331 /* Execute all the commands associated with all the breakpoints at
4332 this location. Any of these commands could cause the process to
4333 proceed beyond this point, etc. We look out for such changes by
4334 checking the global "breakpoint_proceeded" after each command.
4336 Returns true if a breakpoint command resumed the inferior. In that
4337 case, it is the caller's responsibility to recall it again with the
4338 bpstat of the current thread. */
4341 bpstat_do_actions_1 (bpstat
*bsp
)
4346 /* Avoid endless recursion if a `source' command is contained
4348 if (executing_breakpoint_commands
)
4351 scoped_restore save_executing
4352 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4354 scoped_restore preventer
= prevent_dont_repeat ();
4356 /* This pointer will iterate over the list of bpstat's. */
4359 breakpoint_proceeded
= 0;
4360 for (; bs
!= NULL
; bs
= bs
->next
)
4362 struct command_line
*cmd
= NULL
;
4364 /* Take ownership of the BSP's command tree, if it has one.
4366 The command tree could legitimately contain commands like
4367 'step' and 'next', which call clear_proceed_status, which
4368 frees stop_bpstat's command tree. To make sure this doesn't
4369 free the tree we're executing out from under us, we need to
4370 take ownership of the tree ourselves. Since a given bpstat's
4371 commands are only executed once, we don't need to copy it; we
4372 can clear the pointer in the bpstat, and make sure we free
4373 the tree when we're done. */
4374 counted_command_line ccmd
= bs
->commands
;
4375 bs
->commands
= NULL
;
4378 if (command_line_is_silent (cmd
))
4380 /* The action has been already done by bpstat_stop_status. */
4386 execute_control_command (cmd
);
4388 if (breakpoint_proceeded
)
4394 if (breakpoint_proceeded
)
4396 if (current_ui
->async
)
4397 /* If we are in async mode, then the target might be still
4398 running, not stopped at any breakpoint, so nothing for
4399 us to do here -- just return to the event loop. */
4402 /* In sync mode, when execute_control_command returns
4403 we're already standing on the next breakpoint.
4404 Breakpoint commands for that stop were not run, since
4405 execute_command does not run breakpoint commands --
4406 only command_line_handler does, but that one is not
4407 involved in execution of breakpoint commands. So, we
4408 can now execute breakpoint commands. It should be
4409 noted that making execute_command do bpstat actions is
4410 not an option -- in this case we'll have recursive
4411 invocation of bpstat for each breakpoint with a
4412 command, and can easily blow up GDB stack. Instead, we
4413 return true, which will trigger the caller to recall us
4414 with the new stop_bpstat. */
4422 /* Helper for bpstat_do_actions. Get the current thread, if there's
4423 one, is alive and has execution. Return NULL otherwise. */
4425 static thread_info
*
4426 get_bpstat_thread ()
4428 if (inferior_ptid
== null_ptid
|| !target_has_execution
)
4431 thread_info
*tp
= inferior_thread ();
4432 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4438 bpstat_do_actions (void)
4440 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4443 /* Do any commands attached to breakpoint we are stopped at. */
4444 while ((tp
= get_bpstat_thread ()) != NULL
)
4446 /* Since in sync mode, bpstat_do_actions may resume the
4447 inferior, and only return when it is stopped at the next
4448 breakpoint, we keep doing breakpoint actions until it returns
4449 false to indicate the inferior was not resumed. */
4450 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4454 cleanup_if_error
.release ();
4457 /* Print out the (old or new) value associated with a watchpoint. */
4460 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4463 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4466 struct value_print_options opts
;
4467 get_user_print_options (&opts
);
4468 value_print (val
, stream
, &opts
);
4472 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4473 debugging multiple threads. */
4476 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4478 if (uiout
->is_mi_like_p ())
4483 if (show_thread_that_caused_stop ())
4486 struct thread_info
*thr
= inferior_thread ();
4488 uiout
->text ("Thread ");
4489 uiout
->field_string ("thread-id", print_thread_id (thr
));
4491 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4494 uiout
->text (" \"");
4495 uiout
->field_string ("name", name
);
4499 uiout
->text (" hit ");
4503 /* Generic routine for printing messages indicating why we
4504 stopped. The behavior of this function depends on the value
4505 'print_it' in the bpstat structure. Under some circumstances we
4506 may decide not to print anything here and delegate the task to
4509 static enum print_stop_action
4510 print_bp_stop_message (bpstat bs
)
4512 switch (bs
->print_it
)
4515 /* Nothing should be printed for this bpstat entry. */
4516 return PRINT_UNKNOWN
;
4520 /* We still want to print the frame, but we already printed the
4521 relevant messages. */
4522 return PRINT_SRC_AND_LOC
;
4525 case print_it_normal
:
4527 struct breakpoint
*b
= bs
->breakpoint_at
;
4529 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4530 which has since been deleted. */
4532 return PRINT_UNKNOWN
;
4534 /* Normal case. Call the breakpoint's print_it method. */
4535 return b
->ops
->print_it (bs
);
4540 internal_error (__FILE__
, __LINE__
,
4541 _("print_bp_stop_message: unrecognized enum value"));
4546 /* A helper function that prints a shared library stopped event. */
4549 print_solib_event (int is_catchpoint
)
4551 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4552 bool any_added
= !current_program_space
->added_solibs
.empty ();
4556 if (any_added
|| any_deleted
)
4557 current_uiout
->text (_("Stopped due to shared library event:\n"));
4559 current_uiout
->text (_("Stopped due to shared library event (no "
4560 "libraries added or removed)\n"));
4563 if (current_uiout
->is_mi_like_p ())
4564 current_uiout
->field_string ("reason",
4565 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4569 current_uiout
->text (_(" Inferior unloaded "));
4570 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4571 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4573 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4576 current_uiout
->text (" ");
4577 current_uiout
->field_string ("library", name
);
4578 current_uiout
->text ("\n");
4584 current_uiout
->text (_(" Inferior loaded "));
4585 ui_out_emit_list
list_emitter (current_uiout
, "added");
4587 for (so_list
*iter
: current_program_space
->added_solibs
)
4590 current_uiout
->text (" ");
4592 current_uiout
->field_string ("library", iter
->so_name
);
4593 current_uiout
->text ("\n");
4598 /* Print a message indicating what happened. This is called from
4599 normal_stop(). The input to this routine is the head of the bpstat
4600 list - a list of the eventpoints that caused this stop. KIND is
4601 the target_waitkind for the stopping event. This
4602 routine calls the generic print routine for printing a message
4603 about reasons for stopping. This will print (for example) the
4604 "Breakpoint n," part of the output. The return value of this
4607 PRINT_UNKNOWN: Means we printed nothing.
4608 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4609 code to print the location. An example is
4610 "Breakpoint 1, " which should be followed by
4612 PRINT_SRC_ONLY: Means we printed something, but there is no need
4613 to also print the location part of the message.
4614 An example is the catch/throw messages, which
4615 don't require a location appended to the end.
4616 PRINT_NOTHING: We have done some printing and we don't need any
4617 further info to be printed. */
4619 enum print_stop_action
4620 bpstat_print (bpstat bs
, int kind
)
4622 enum print_stop_action val
;
4624 /* Maybe another breakpoint in the chain caused us to stop.
4625 (Currently all watchpoints go on the bpstat whether hit or not.
4626 That probably could (should) be changed, provided care is taken
4627 with respect to bpstat_explains_signal). */
4628 for (; bs
; bs
= bs
->next
)
4630 val
= print_bp_stop_message (bs
);
4631 if (val
== PRINT_SRC_ONLY
4632 || val
== PRINT_SRC_AND_LOC
4633 || val
== PRINT_NOTHING
)
4637 /* If we had hit a shared library event breakpoint,
4638 print_bp_stop_message would print out this message. If we hit an
4639 OS-level shared library event, do the same thing. */
4640 if (kind
== TARGET_WAITKIND_LOADED
)
4642 print_solib_event (0);
4643 return PRINT_NOTHING
;
4646 /* We reached the end of the chain, or we got a null BS to start
4647 with and nothing was printed. */
4648 return PRINT_UNKNOWN
;
4651 /* Evaluate the boolean expression EXP and return the result. */
4654 breakpoint_cond_eval (expression
*exp
)
4656 struct value
*mark
= value_mark ();
4657 bool res
= value_true (evaluate_expression (exp
));
4659 value_free_to_mark (mark
);
4663 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4665 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4667 bp_location_at (bl
),
4668 breakpoint_at (bl
->owner
),
4672 print_it (print_it_normal
)
4674 incref_bp_location (bl
);
4675 **bs_link_pointer
= this;
4676 *bs_link_pointer
= &next
;
4681 bp_location_at (NULL
),
4682 breakpoint_at (NULL
),
4686 print_it (print_it_normal
)
4690 /* The target has stopped with waitstatus WS. Check if any hardware
4691 watchpoints have triggered, according to the target. */
4694 watchpoints_triggered (struct target_waitstatus
*ws
)
4696 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4698 struct breakpoint
*b
;
4700 if (!stopped_by_watchpoint
)
4702 /* We were not stopped by a watchpoint. Mark all watchpoints
4703 as not triggered. */
4705 if (is_hardware_watchpoint (b
))
4707 struct watchpoint
*w
= (struct watchpoint
*) b
;
4709 w
->watchpoint_triggered
= watch_triggered_no
;
4715 if (!target_stopped_data_address (current_top_target (), &addr
))
4717 /* We were stopped by a watchpoint, but we don't know where.
4718 Mark all watchpoints as unknown. */
4720 if (is_hardware_watchpoint (b
))
4722 struct watchpoint
*w
= (struct watchpoint
*) b
;
4724 w
->watchpoint_triggered
= watch_triggered_unknown
;
4730 /* The target could report the data address. Mark watchpoints
4731 affected by this data address as triggered, and all others as not
4735 if (is_hardware_watchpoint (b
))
4737 struct watchpoint
*w
= (struct watchpoint
*) b
;
4738 struct bp_location
*loc
;
4740 w
->watchpoint_triggered
= watch_triggered_no
;
4741 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4743 if (is_masked_watchpoint (b
))
4745 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4746 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4748 if (newaddr
== start
)
4750 w
->watchpoint_triggered
= watch_triggered_yes
;
4754 /* Exact match not required. Within range is sufficient. */
4755 else if (target_watchpoint_addr_within_range (current_top_target (),
4759 w
->watchpoint_triggered
= watch_triggered_yes
;
4768 /* Possible return values for watchpoint_check. */
4769 enum wp_check_result
4771 /* The watchpoint has been deleted. */
4774 /* The value has changed. */
4775 WP_VALUE_CHANGED
= 2,
4777 /* The value has not changed. */
4778 WP_VALUE_NOT_CHANGED
= 3,
4780 /* Ignore this watchpoint, no matter if the value changed or not. */
4784 #define BP_TEMPFLAG 1
4785 #define BP_HARDWAREFLAG 2
4787 /* Evaluate watchpoint condition expression and check if its value
4790 static wp_check_result
4791 watchpoint_check (bpstat bs
)
4793 struct watchpoint
*b
;
4794 struct frame_info
*fr
;
4795 int within_current_scope
;
4797 /* BS is built from an existing struct breakpoint. */
4798 gdb_assert (bs
->breakpoint_at
!= NULL
);
4799 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4801 /* If this is a local watchpoint, we only want to check if the
4802 watchpoint frame is in scope if the current thread is the thread
4803 that was used to create the watchpoint. */
4804 if (!watchpoint_in_thread_scope (b
))
4807 if (b
->exp_valid_block
== NULL
)
4808 within_current_scope
= 1;
4811 struct frame_info
*frame
= get_current_frame ();
4812 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4813 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4815 /* stack_frame_destroyed_p() returns a non-zero value if we're
4816 still in the function but the stack frame has already been
4817 invalidated. Since we can't rely on the values of local
4818 variables after the stack has been destroyed, we are treating
4819 the watchpoint in that state as `not changed' without further
4820 checking. Don't mark watchpoints as changed if the current
4821 frame is in an epilogue - even if they are in some other
4822 frame, our view of the stack is likely to be wrong and
4823 frame_find_by_id could error out. */
4824 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4827 fr
= frame_find_by_id (b
->watchpoint_frame
);
4828 within_current_scope
= (fr
!= NULL
);
4830 /* If we've gotten confused in the unwinder, we might have
4831 returned a frame that can't describe this variable. */
4832 if (within_current_scope
)
4834 struct symbol
*function
;
4836 function
= get_frame_function (fr
);
4837 if (function
== NULL
4838 || !contained_in (b
->exp_valid_block
,
4839 SYMBOL_BLOCK_VALUE (function
)))
4840 within_current_scope
= 0;
4843 if (within_current_scope
)
4844 /* If we end up stopping, the current frame will get selected
4845 in normal_stop. So this call to select_frame won't affect
4850 if (within_current_scope
)
4852 /* We use value_{,free_to_}mark because it could be a *long*
4853 time before we return to the command level and call
4854 free_all_values. We can't call free_all_values because we
4855 might be in the middle of evaluating a function call. */
4859 struct value
*new_val
;
4861 if (is_masked_watchpoint (b
))
4862 /* Since we don't know the exact trigger address (from
4863 stopped_data_address), just tell the user we've triggered
4864 a mask watchpoint. */
4865 return WP_VALUE_CHANGED
;
4867 mark
= value_mark ();
4868 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
4870 if (b
->val_bitsize
!= 0)
4871 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4873 /* We use value_equal_contents instead of value_equal because
4874 the latter coerces an array to a pointer, thus comparing just
4875 the address of the array instead of its contents. This is
4876 not what we want. */
4877 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4878 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
4881 bs
->old_val
= b
->val
;
4882 b
->val
= release_value (new_val
);
4883 b
->val_valid
= true;
4884 if (new_val
!= NULL
)
4885 value_free_to_mark (mark
);
4886 return WP_VALUE_CHANGED
;
4890 /* Nothing changed. */
4891 value_free_to_mark (mark
);
4892 return WP_VALUE_NOT_CHANGED
;
4897 /* This seems like the only logical thing to do because
4898 if we temporarily ignored the watchpoint, then when
4899 we reenter the block in which it is valid it contains
4900 garbage (in the case of a function, it may have two
4901 garbage values, one before and one after the prologue).
4902 So we can't even detect the first assignment to it and
4903 watch after that (since the garbage may or may not equal
4904 the first value assigned). */
4905 /* We print all the stop information in
4906 breakpoint_ops->print_it, but in this case, by the time we
4907 call breakpoint_ops->print_it this bp will be deleted
4908 already. So we have no choice but print the information
4911 SWITCH_THRU_ALL_UIS ()
4913 struct ui_out
*uiout
= current_uiout
;
4915 if (uiout
->is_mi_like_p ())
4917 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4918 uiout
->message ("\nWatchpoint %pF deleted because the program has "
4919 "left the block in\n"
4920 "which its expression is valid.\n",
4921 signed_field ("wpnum", b
->number
));
4924 /* Make sure the watchpoint's commands aren't executed. */
4926 watchpoint_del_at_next_stop (b
);
4932 /* Return true if it looks like target has stopped due to hitting
4933 breakpoint location BL. This function does not check if we should
4934 stop, only if BL explains the stop. */
4937 bpstat_check_location (const struct bp_location
*bl
,
4938 const address_space
*aspace
, CORE_ADDR bp_addr
,
4939 const struct target_waitstatus
*ws
)
4941 struct breakpoint
*b
= bl
->owner
;
4943 /* BL is from an existing breakpoint. */
4944 gdb_assert (b
!= NULL
);
4946 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4949 /* Determine if the watched values have actually changed, and we
4950 should stop. If not, set BS->stop to 0. */
4953 bpstat_check_watchpoint (bpstat bs
)
4955 const struct bp_location
*bl
;
4956 struct watchpoint
*b
;
4958 /* BS is built for existing struct breakpoint. */
4959 bl
= bs
->bp_location_at
;
4960 gdb_assert (bl
!= NULL
);
4961 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4962 gdb_assert (b
!= NULL
);
4965 int must_check_value
= 0;
4967 if (b
->type
== bp_watchpoint
)
4968 /* For a software watchpoint, we must always check the
4970 must_check_value
= 1;
4971 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4972 /* We have a hardware watchpoint (read, write, or access)
4973 and the target earlier reported an address watched by
4975 must_check_value
= 1;
4976 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4977 && b
->type
== bp_hardware_watchpoint
)
4978 /* We were stopped by a hardware watchpoint, but the target could
4979 not report the data address. We must check the watchpoint's
4980 value. Access and read watchpoints are out of luck; without
4981 a data address, we can't figure it out. */
4982 must_check_value
= 1;
4984 if (must_check_value
)
4990 e
= watchpoint_check (bs
);
4992 catch (const gdb_exception
&ex
)
4994 exception_fprintf (gdb_stderr
, ex
,
4995 "Error evaluating expression "
4996 "for watchpoint %d\n",
4999 SWITCH_THRU_ALL_UIS ()
5001 printf_filtered (_("Watchpoint %d deleted.\n"),
5004 watchpoint_del_at_next_stop (b
);
5011 /* We've already printed what needs to be printed. */
5012 bs
->print_it
= print_it_done
;
5016 bs
->print_it
= print_it_noop
;
5019 case WP_VALUE_CHANGED
:
5020 if (b
->type
== bp_read_watchpoint
)
5022 /* There are two cases to consider here:
5024 1. We're watching the triggered memory for reads.
5025 In that case, trust the target, and always report
5026 the watchpoint hit to the user. Even though
5027 reads don't cause value changes, the value may
5028 have changed since the last time it was read, and
5029 since we're not trapping writes, we will not see
5030 those, and as such we should ignore our notion of
5033 2. We're watching the triggered memory for both
5034 reads and writes. There are two ways this may
5037 2.1. This is a target that can't break on data
5038 reads only, but can break on accesses (reads or
5039 writes), such as e.g., x86. We detect this case
5040 at the time we try to insert read watchpoints.
5042 2.2. Otherwise, the target supports read
5043 watchpoints, but, the user set an access or write
5044 watchpoint watching the same memory as this read
5047 If we're watching memory writes as well as reads,
5048 ignore watchpoint hits when we find that the
5049 value hasn't changed, as reads don't cause
5050 changes. This still gives false positives when
5051 the program writes the same value to memory as
5052 what there was already in memory (we will confuse
5053 it for a read), but it's much better than
5056 int other_write_watchpoint
= 0;
5058 if (bl
->watchpoint_type
== hw_read
)
5060 struct breakpoint
*other_b
;
5062 ALL_BREAKPOINTS (other_b
)
5063 if (other_b
->type
== bp_hardware_watchpoint
5064 || other_b
->type
== bp_access_watchpoint
)
5066 struct watchpoint
*other_w
=
5067 (struct watchpoint
*) other_b
;
5069 if (other_w
->watchpoint_triggered
5070 == watch_triggered_yes
)
5072 other_write_watchpoint
= 1;
5078 if (other_write_watchpoint
5079 || bl
->watchpoint_type
== hw_access
)
5081 /* We're watching the same memory for writes,
5082 and the value changed since the last time we
5083 updated it, so this trap must be for a write.
5085 bs
->print_it
= print_it_noop
;
5090 case WP_VALUE_NOT_CHANGED
:
5091 if (b
->type
== bp_hardware_watchpoint
5092 || b
->type
== bp_watchpoint
)
5094 /* Don't stop: write watchpoints shouldn't fire if
5095 the value hasn't changed. */
5096 bs
->print_it
= print_it_noop
;
5106 else /* must_check_value == 0 */
5108 /* This is a case where some watchpoint(s) triggered, but
5109 not at the address of this watchpoint, or else no
5110 watchpoint triggered after all. So don't print
5111 anything for this watchpoint. */
5112 bs
->print_it
= print_it_noop
;
5118 /* For breakpoints that are currently marked as telling gdb to stop,
5119 check conditions (condition proper, frame, thread and ignore count)
5120 of breakpoint referred to by BS. If we should not stop for this
5121 breakpoint, set BS->stop to 0. */
5124 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5126 const struct bp_location
*bl
;
5127 struct breakpoint
*b
;
5129 bool condition_result
= true;
5130 struct expression
*cond
;
5132 gdb_assert (bs
->stop
);
5134 /* BS is built for existing struct breakpoint. */
5135 bl
= bs
->bp_location_at
;
5136 gdb_assert (bl
!= NULL
);
5137 b
= bs
->breakpoint_at
;
5138 gdb_assert (b
!= NULL
);
5140 /* Even if the target evaluated the condition on its end and notified GDB, we
5141 need to do so again since GDB does not know if we stopped due to a
5142 breakpoint or a single step breakpoint. */
5144 if (frame_id_p (b
->frame_id
)
5145 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5151 /* If this is a thread/task-specific breakpoint, don't waste cpu
5152 evaluating the condition if this isn't the specified
5154 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5155 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5161 /* Evaluate extension language breakpoints that have a "stop" method
5163 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5165 if (is_watchpoint (b
))
5167 struct watchpoint
*w
= (struct watchpoint
*) b
;
5169 cond
= w
->cond_exp
.get ();
5172 cond
= bl
->cond
.get ();
5174 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5176 int within_current_scope
= 1;
5177 struct watchpoint
* w
;
5179 /* We use value_mark and value_free_to_mark because it could
5180 be a long time before we return to the command level and
5181 call free_all_values. We can't call free_all_values
5182 because we might be in the middle of evaluating a
5184 struct value
*mark
= value_mark ();
5186 if (is_watchpoint (b
))
5187 w
= (struct watchpoint
*) b
;
5191 /* Need to select the frame, with all that implies so that
5192 the conditions will have the right context. Because we
5193 use the frame, we will not see an inlined function's
5194 variables when we arrive at a breakpoint at the start
5195 of the inlined function; the current frame will be the
5197 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5198 select_frame (get_current_frame ());
5201 struct frame_info
*frame
;
5203 /* For local watchpoint expressions, which particular
5204 instance of a local is being watched matters, so we
5205 keep track of the frame to evaluate the expression
5206 in. To evaluate the condition however, it doesn't
5207 really matter which instantiation of the function
5208 where the condition makes sense triggers the
5209 watchpoint. This allows an expression like "watch
5210 global if q > 10" set in `func', catch writes to
5211 global on all threads that call `func', or catch
5212 writes on all recursive calls of `func' by a single
5213 thread. We simply always evaluate the condition in
5214 the innermost frame that's executing where it makes
5215 sense to evaluate the condition. It seems
5217 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5219 select_frame (frame
);
5221 within_current_scope
= 0;
5223 if (within_current_scope
)
5227 condition_result
= breakpoint_cond_eval (cond
);
5229 catch (const gdb_exception
&ex
)
5231 exception_fprintf (gdb_stderr
, ex
,
5232 "Error in testing breakpoint condition:\n");
5237 warning (_("Watchpoint condition cannot be tested "
5238 "in the current scope"));
5239 /* If we failed to set the right context for this
5240 watchpoint, unconditionally report it. */
5242 /* FIXME-someday, should give breakpoint #. */
5243 value_free_to_mark (mark
);
5246 if (cond
&& !condition_result
)
5250 else if (b
->ignore_count
> 0)
5254 /* Increase the hit count even though we don't stop. */
5256 gdb::observers::breakpoint_modified
.notify (b
);
5260 /* Returns true if we need to track moribund locations of LOC's type
5261 on the current target. */
5264 need_moribund_for_location_type (struct bp_location
*loc
)
5266 return ((loc
->loc_type
== bp_loc_software_breakpoint
5267 && !target_supports_stopped_by_sw_breakpoint ())
5268 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5269 && !target_supports_stopped_by_hw_breakpoint ()));
5272 /* See breakpoint.h. */
5275 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5276 const struct target_waitstatus
*ws
)
5278 struct breakpoint
*b
;
5279 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5283 if (!breakpoint_enabled (b
))
5286 for (bp_location
*bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5288 /* For hardware watchpoints, we look only at the first
5289 location. The watchpoint_check function will work on the
5290 entire expression, not the individual locations. For
5291 read watchpoints, the watchpoints_triggered function has
5292 checked all locations already. */
5293 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5296 if (!bl
->enabled
|| bl
->shlib_disabled
)
5299 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5302 /* Come here if it's a watchpoint, or if the break address
5305 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5308 /* Assume we stop. Should we find a watchpoint that is not
5309 actually triggered, or if the condition of the breakpoint
5310 evaluates as false, we'll reset 'stop' to 0. */
5314 /* If this is a scope breakpoint, mark the associated
5315 watchpoint as triggered so that we will handle the
5316 out-of-scope event. We'll get to the watchpoint next
5318 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5320 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5322 w
->watchpoint_triggered
= watch_triggered_yes
;
5327 /* Check if a moribund breakpoint explains the stop. */
5328 if (!target_supports_stopped_by_sw_breakpoint ()
5329 || !target_supports_stopped_by_hw_breakpoint ())
5331 for (bp_location
*loc
: moribund_locations
)
5333 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5334 && need_moribund_for_location_type (loc
))
5336 bpstat bs
= new bpstats (loc
, &bs_link
);
5337 /* For hits of moribund locations, we should just proceed. */
5340 bs
->print_it
= print_it_noop
;
5348 /* See breakpoint.h. */
5351 bpstat_stop_status (const address_space
*aspace
,
5352 CORE_ADDR bp_addr
, thread_info
*thread
,
5353 const struct target_waitstatus
*ws
,
5356 struct breakpoint
*b
= NULL
;
5357 /* First item of allocated bpstat's. */
5358 bpstat bs_head
= stop_chain
;
5360 int need_remove_insert
;
5363 /* First, build the bpstat chain with locations that explain a
5364 target stop, while being careful to not set the target running,
5365 as that may invalidate locations (in particular watchpoint
5366 locations are recreated). Resuming will happen here with
5367 breakpoint conditions or watchpoint expressions that include
5368 inferior function calls. */
5369 if (bs_head
== NULL
)
5370 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5372 /* A bit of special processing for shlib breakpoints. We need to
5373 process solib loading here, so that the lists of loaded and
5374 unloaded libraries are correct before we handle "catch load" and
5376 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5378 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5380 handle_solib_event ();
5385 /* Now go through the locations that caused the target to stop, and
5386 check whether we're interested in reporting this stop to higher
5387 layers, or whether we should resume the target transparently. */
5391 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5396 b
= bs
->breakpoint_at
;
5397 b
->ops
->check_status (bs
);
5400 bpstat_check_breakpoint_conditions (bs
, thread
);
5405 gdb::observers::breakpoint_modified
.notify (b
);
5407 /* We will stop here. */
5408 if (b
->disposition
== disp_disable
)
5410 --(b
->enable_count
);
5411 if (b
->enable_count
<= 0)
5412 b
->enable_state
= bp_disabled
;
5417 bs
->commands
= b
->commands
;
5418 if (command_line_is_silent (bs
->commands
5419 ? bs
->commands
.get () : NULL
))
5422 b
->ops
->after_condition_true (bs
);
5427 /* Print nothing for this entry if we don't stop or don't
5429 if (!bs
->stop
|| !bs
->print
)
5430 bs
->print_it
= print_it_noop
;
5433 /* If we aren't stopping, the value of some hardware watchpoint may
5434 not have changed, but the intermediate memory locations we are
5435 watching may have. Don't bother if we're stopping; this will get
5437 need_remove_insert
= 0;
5438 if (! bpstat_causes_stop (bs_head
))
5439 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5441 && bs
->breakpoint_at
5442 && is_hardware_watchpoint (bs
->breakpoint_at
))
5444 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5446 update_watchpoint (w
, 0 /* don't reparse. */);
5447 need_remove_insert
= 1;
5450 if (need_remove_insert
)
5451 update_global_location_list (UGLL_MAY_INSERT
);
5452 else if (removed_any
)
5453 update_global_location_list (UGLL_DONT_INSERT
);
5459 handle_jit_event (void)
5461 struct frame_info
*frame
;
5462 struct gdbarch
*gdbarch
;
5465 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5467 /* Switch terminal for any messages produced by
5468 breakpoint_re_set. */
5469 target_terminal::ours_for_output ();
5471 frame
= get_current_frame ();
5472 gdbarch
= get_frame_arch (frame
);
5474 jit_event_handler (gdbarch
);
5476 target_terminal::inferior ();
5479 /* Prepare WHAT final decision for infrun. */
5481 /* Decide what infrun needs to do with this bpstat. */
5484 bpstat_what (bpstat bs_head
)
5486 struct bpstat_what retval
;
5489 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5490 retval
.call_dummy
= STOP_NONE
;
5491 retval
.is_longjmp
= false;
5493 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5495 /* Extract this BS's action. After processing each BS, we check
5496 if its action overrides all we've seem so far. */
5497 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5500 if (bs
->breakpoint_at
== NULL
)
5502 /* I suspect this can happen if it was a momentary
5503 breakpoint which has since been deleted. */
5507 bptype
= bs
->breakpoint_at
->type
;
5514 case bp_hardware_breakpoint
:
5515 case bp_single_step
:
5518 case bp_shlib_event
:
5522 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5524 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5527 this_action
= BPSTAT_WHAT_SINGLE
;
5530 case bp_hardware_watchpoint
:
5531 case bp_read_watchpoint
:
5532 case bp_access_watchpoint
:
5536 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5538 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5542 /* There was a watchpoint, but we're not stopping.
5543 This requires no further action. */
5547 case bp_longjmp_call_dummy
:
5551 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5552 retval
.is_longjmp
= bptype
!= bp_exception
;
5555 this_action
= BPSTAT_WHAT_SINGLE
;
5557 case bp_longjmp_resume
:
5558 case bp_exception_resume
:
5561 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5562 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5565 this_action
= BPSTAT_WHAT_SINGLE
;
5567 case bp_step_resume
:
5569 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5572 /* It is for the wrong frame. */
5573 this_action
= BPSTAT_WHAT_SINGLE
;
5576 case bp_hp_step_resume
:
5578 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5581 /* It is for the wrong frame. */
5582 this_action
= BPSTAT_WHAT_SINGLE
;
5585 case bp_watchpoint_scope
:
5586 case bp_thread_event
:
5587 case bp_overlay_event
:
5588 case bp_longjmp_master
:
5589 case bp_std_terminate_master
:
5590 case bp_exception_master
:
5591 this_action
= BPSTAT_WHAT_SINGLE
;
5597 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5599 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5603 /* Some catchpoints are implemented with breakpoints.
5604 For those, we need to step over the breakpoint. */
5605 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5606 this_action
= BPSTAT_WHAT_SINGLE
;
5610 this_action
= BPSTAT_WHAT_SINGLE
;
5613 /* Make sure the action is stop (silent or noisy),
5614 so infrun.c pops the dummy frame. */
5615 retval
.call_dummy
= STOP_STACK_DUMMY
;
5616 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5618 case bp_std_terminate
:
5619 /* Make sure the action is stop (silent or noisy),
5620 so infrun.c pops the dummy frame. */
5621 retval
.call_dummy
= STOP_STD_TERMINATE
;
5622 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5625 case bp_fast_tracepoint
:
5626 case bp_static_tracepoint
:
5627 /* Tracepoint hits should not be reported back to GDB, and
5628 if one got through somehow, it should have been filtered
5630 internal_error (__FILE__
, __LINE__
,
5631 _("bpstat_what: tracepoint encountered"));
5633 case bp_gnu_ifunc_resolver
:
5634 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5635 this_action
= BPSTAT_WHAT_SINGLE
;
5637 case bp_gnu_ifunc_resolver_return
:
5638 /* The breakpoint will be removed, execution will restart from the
5639 PC of the former breakpoint. */
5640 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5645 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5647 this_action
= BPSTAT_WHAT_SINGLE
;
5651 internal_error (__FILE__
, __LINE__
,
5652 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5655 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5662 bpstat_run_callbacks (bpstat bs_head
)
5666 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5668 struct breakpoint
*b
= bs
->breakpoint_at
;
5675 handle_jit_event ();
5677 case bp_gnu_ifunc_resolver
:
5678 gnu_ifunc_resolver_stop (b
);
5680 case bp_gnu_ifunc_resolver_return
:
5681 gnu_ifunc_resolver_return_stop (b
);
5687 /* See breakpoint.h. */
5690 bpstat_should_step ()
5692 struct breakpoint
*b
;
5695 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5700 /* See breakpoint.h. */
5703 bpstat_causes_stop (bpstat bs
)
5705 for (; bs
!= NULL
; bs
= bs
->next
)
5714 /* Compute a string of spaces suitable to indent the next line
5715 so it starts at the position corresponding to the table column
5716 named COL_NAME in the currently active table of UIOUT. */
5719 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5721 static char wrap_indent
[80];
5722 int i
, total_width
, width
, align
;
5726 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5728 if (strcmp (text
, col_name
) == 0)
5730 gdb_assert (total_width
< sizeof wrap_indent
);
5731 memset (wrap_indent
, ' ', total_width
);
5732 wrap_indent
[total_width
] = 0;
5737 total_width
+= width
+ 1;
5743 /* Determine if the locations of this breakpoint will have their conditions
5744 evaluated by the target, host or a mix of both. Returns the following:
5746 "host": Host evals condition.
5747 "host or target": Host or Target evals condition.
5748 "target": Target evals condition.
5752 bp_condition_evaluator (struct breakpoint
*b
)
5754 struct bp_location
*bl
;
5755 char host_evals
= 0;
5756 char target_evals
= 0;
5761 if (!is_breakpoint (b
))
5764 if (gdb_evaluates_breakpoint_condition_p ()
5765 || !target_supports_evaluation_of_breakpoint_conditions ())
5766 return condition_evaluation_host
;
5768 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5770 if (bl
->cond_bytecode
)
5776 if (host_evals
&& target_evals
)
5777 return condition_evaluation_both
;
5778 else if (target_evals
)
5779 return condition_evaluation_target
;
5781 return condition_evaluation_host
;
5784 /* Determine the breakpoint location's condition evaluator. This is
5785 similar to bp_condition_evaluator, but for locations. */
5788 bp_location_condition_evaluator (struct bp_location
*bl
)
5790 if (bl
&& !is_breakpoint (bl
->owner
))
5793 if (gdb_evaluates_breakpoint_condition_p ()
5794 || !target_supports_evaluation_of_breakpoint_conditions ())
5795 return condition_evaluation_host
;
5797 if (bl
&& bl
->cond_bytecode
)
5798 return condition_evaluation_target
;
5800 return condition_evaluation_host
;
5803 /* Print the LOC location out of the list of B->LOC locations. */
5806 print_breakpoint_location (struct breakpoint
*b
,
5807 struct bp_location
*loc
)
5809 struct ui_out
*uiout
= current_uiout
;
5811 scoped_restore_current_program_space restore_pspace
;
5813 if (loc
!= NULL
&& loc
->shlib_disabled
)
5817 set_current_program_space (loc
->pspace
);
5819 if (b
->display_canonical
)
5820 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5821 else if (loc
&& loc
->symtab
)
5823 const struct symbol
*sym
= loc
->symbol
;
5827 uiout
->text ("in ");
5828 uiout
->field_string ("func", sym
->print_name (),
5829 function_name_style
.style ());
5831 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5832 uiout
->text ("at ");
5834 uiout
->field_string ("file",
5835 symtab_to_filename_for_display (loc
->symtab
),
5836 file_name_style
.style ());
5839 if (uiout
->is_mi_like_p ())
5840 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5842 uiout
->field_signed ("line", loc
->line_number
);
5848 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5850 uiout
->field_stream ("at", stb
);
5854 uiout
->field_string ("pending",
5855 event_location_to_string (b
->location
.get ()));
5856 /* If extra_string is available, it could be holding a condition
5857 or dprintf arguments. In either case, make sure it is printed,
5858 too, but only for non-MI streams. */
5859 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5861 if (b
->type
== bp_dprintf
)
5865 uiout
->text (b
->extra_string
);
5869 if (loc
&& is_breakpoint (b
)
5870 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5871 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5874 uiout
->field_string ("evaluated-by",
5875 bp_location_condition_evaluator (loc
));
5881 bptype_string (enum bptype type
)
5883 struct ep_type_description
5886 const char *description
;
5888 static struct ep_type_description bptypes
[] =
5890 {bp_none
, "?deleted?"},
5891 {bp_breakpoint
, "breakpoint"},
5892 {bp_hardware_breakpoint
, "hw breakpoint"},
5893 {bp_single_step
, "sw single-step"},
5894 {bp_until
, "until"},
5895 {bp_finish
, "finish"},
5896 {bp_watchpoint
, "watchpoint"},
5897 {bp_hardware_watchpoint
, "hw watchpoint"},
5898 {bp_read_watchpoint
, "read watchpoint"},
5899 {bp_access_watchpoint
, "acc watchpoint"},
5900 {bp_longjmp
, "longjmp"},
5901 {bp_longjmp_resume
, "longjmp resume"},
5902 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5903 {bp_exception
, "exception"},
5904 {bp_exception_resume
, "exception resume"},
5905 {bp_step_resume
, "step resume"},
5906 {bp_hp_step_resume
, "high-priority step resume"},
5907 {bp_watchpoint_scope
, "watchpoint scope"},
5908 {bp_call_dummy
, "call dummy"},
5909 {bp_std_terminate
, "std::terminate"},
5910 {bp_shlib_event
, "shlib events"},
5911 {bp_thread_event
, "thread events"},
5912 {bp_overlay_event
, "overlay events"},
5913 {bp_longjmp_master
, "longjmp master"},
5914 {bp_std_terminate_master
, "std::terminate master"},
5915 {bp_exception_master
, "exception master"},
5916 {bp_catchpoint
, "catchpoint"},
5917 {bp_tracepoint
, "tracepoint"},
5918 {bp_fast_tracepoint
, "fast tracepoint"},
5919 {bp_static_tracepoint
, "static tracepoint"},
5920 {bp_dprintf
, "dprintf"},
5921 {bp_jit_event
, "jit events"},
5922 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5923 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5926 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5927 || ((int) type
!= bptypes
[(int) type
].type
))
5928 internal_error (__FILE__
, __LINE__
,
5929 _("bptypes table does not describe type #%d."),
5932 return bptypes
[(int) type
].description
;
5935 /* For MI, output a field named 'thread-groups' with a list as the value.
5936 For CLI, prefix the list with the string 'inf'. */
5939 output_thread_groups (struct ui_out
*uiout
,
5940 const char *field_name
,
5941 const std::vector
<int> &inf_nums
,
5944 int is_mi
= uiout
->is_mi_like_p ();
5946 /* For backward compatibility, don't display inferiors in CLI unless
5947 there are several. Always display them for MI. */
5948 if (!is_mi
&& mi_only
)
5951 ui_out_emit_list
list_emitter (uiout
, field_name
);
5953 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
5959 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
5960 uiout
->field_string (NULL
, mi_group
);
5965 uiout
->text (" inf ");
5969 uiout
->text (plongest (inf_nums
[i
]));
5974 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
5975 instead of going via breakpoint_ops::print_one. This makes "maint
5976 info breakpoints" show the software breakpoint locations of
5977 catchpoints, which are considered internal implementation
5981 print_one_breakpoint_location (struct breakpoint
*b
,
5982 struct bp_location
*loc
,
5984 struct bp_location
**last_loc
,
5985 int allflag
, bool raw_loc
)
5987 struct command_line
*l
;
5988 static char bpenables
[] = "nynny";
5990 struct ui_out
*uiout
= current_uiout
;
5991 int header_of_multiple
= 0;
5992 int part_of_multiple
= (loc
!= NULL
);
5993 struct value_print_options opts
;
5995 get_user_print_options (&opts
);
5997 gdb_assert (!loc
|| loc_number
!= 0);
5998 /* See comment in print_one_breakpoint concerning treatment of
5999 breakpoints with single disabled location. */
6002 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6003 header_of_multiple
= 1;
6011 if (part_of_multiple
)
6012 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6014 uiout
->field_signed ("number", b
->number
);
6018 if (part_of_multiple
)
6019 uiout
->field_skip ("type");
6021 uiout
->field_string ("type", bptype_string (b
->type
));
6025 if (part_of_multiple
)
6026 uiout
->field_skip ("disp");
6028 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6032 if (part_of_multiple
)
6033 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6035 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6038 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6039 b
->ops
->print_one (b
, last_loc
);
6042 if (is_watchpoint (b
))
6044 struct watchpoint
*w
= (struct watchpoint
*) b
;
6046 /* Field 4, the address, is omitted (which makes the columns
6047 not line up too nicely with the headers, but the effect
6048 is relatively readable). */
6049 if (opts
.addressprint
)
6050 uiout
->field_skip ("addr");
6052 uiout
->field_string ("what", w
->exp_string
);
6054 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6055 || is_ada_exception_catchpoint (b
))
6057 if (opts
.addressprint
)
6060 if (header_of_multiple
)
6061 uiout
->field_string ("addr", "<MULTIPLE>",
6062 metadata_style
.style ());
6063 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6064 uiout
->field_string ("addr", "<PENDING>",
6065 metadata_style
.style ());
6067 uiout
->field_core_addr ("addr",
6068 loc
->gdbarch
, loc
->address
);
6071 if (!header_of_multiple
)
6072 print_breakpoint_location (b
, loc
);
6078 if (loc
!= NULL
&& !header_of_multiple
)
6080 std::vector
<int> inf_nums
;
6083 for (inferior
*inf
: all_inferiors ())
6085 if (inf
->pspace
== loc
->pspace
)
6086 inf_nums
.push_back (inf
->num
);
6089 /* For backward compatibility, don't display inferiors in CLI unless
6090 there are several. Always display for MI. */
6092 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6093 && (number_of_program_spaces () > 1
6094 || number_of_inferiors () > 1)
6095 /* LOC is for existing B, it cannot be in
6096 moribund_locations and thus having NULL OWNER. */
6097 && loc
->owner
->type
!= bp_catchpoint
))
6099 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6102 if (!part_of_multiple
)
6104 if (b
->thread
!= -1)
6106 /* FIXME: This seems to be redundant and lost here; see the
6107 "stop only in" line a little further down. */
6108 uiout
->text (" thread ");
6109 uiout
->field_signed ("thread", b
->thread
);
6111 else if (b
->task
!= 0)
6113 uiout
->text (" task ");
6114 uiout
->field_signed ("task", b
->task
);
6120 if (!part_of_multiple
)
6121 b
->ops
->print_one_detail (b
, uiout
);
6123 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6126 uiout
->text ("\tstop only in stack frame at ");
6127 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6129 uiout
->field_core_addr ("frame",
6130 b
->gdbarch
, b
->frame_id
.stack_addr
);
6134 if (!part_of_multiple
&& b
->cond_string
)
6137 if (is_tracepoint (b
))
6138 uiout
->text ("\ttrace only if ");
6140 uiout
->text ("\tstop only if ");
6141 uiout
->field_string ("cond", b
->cond_string
);
6143 /* Print whether the target is doing the breakpoint's condition
6144 evaluation. If GDB is doing the evaluation, don't print anything. */
6145 if (is_breakpoint (b
)
6146 && breakpoint_condition_evaluation_mode ()
6147 == condition_evaluation_target
)
6149 uiout
->message (" (%pF evals)",
6150 string_field ("evaluated-by",
6151 bp_condition_evaluator (b
)));
6156 if (!part_of_multiple
&& b
->thread
!= -1)
6158 /* FIXME should make an annotation for this. */
6159 uiout
->text ("\tstop only in thread ");
6160 if (uiout
->is_mi_like_p ())
6161 uiout
->field_signed ("thread", b
->thread
);
6164 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6166 uiout
->field_string ("thread", print_thread_id (thr
));
6171 if (!part_of_multiple
)
6175 /* FIXME should make an annotation for this. */
6176 if (is_catchpoint (b
))
6177 uiout
->text ("\tcatchpoint");
6178 else if (is_tracepoint (b
))
6179 uiout
->text ("\ttracepoint");
6181 uiout
->text ("\tbreakpoint");
6182 uiout
->text (" already hit ");
6183 uiout
->field_signed ("times", b
->hit_count
);
6184 if (b
->hit_count
== 1)
6185 uiout
->text (" time\n");
6187 uiout
->text (" times\n");
6191 /* Output the count also if it is zero, but only if this is mi. */
6192 if (uiout
->is_mi_like_p ())
6193 uiout
->field_signed ("times", b
->hit_count
);
6197 if (!part_of_multiple
&& b
->ignore_count
)
6200 uiout
->message ("\tignore next %pF hits\n",
6201 signed_field ("ignore", b
->ignore_count
));
6204 /* Note that an enable count of 1 corresponds to "enable once"
6205 behavior, which is reported by the combination of enablement and
6206 disposition, so we don't need to mention it here. */
6207 if (!part_of_multiple
&& b
->enable_count
> 1)
6210 uiout
->text ("\tdisable after ");
6211 /* Tweak the wording to clarify that ignore and enable counts
6212 are distinct, and have additive effect. */
6213 if (b
->ignore_count
)
6214 uiout
->text ("additional ");
6216 uiout
->text ("next ");
6217 uiout
->field_signed ("enable", b
->enable_count
);
6218 uiout
->text (" hits\n");
6221 if (!part_of_multiple
&& is_tracepoint (b
))
6223 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6225 if (tp
->traceframe_usage
)
6227 uiout
->text ("\ttrace buffer usage ");
6228 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6229 uiout
->text (" bytes\n");
6233 l
= b
->commands
? b
->commands
.get () : NULL
;
6234 if (!part_of_multiple
&& l
)
6237 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6238 print_command_lines (uiout
, l
, 4);
6241 if (is_tracepoint (b
))
6243 struct tracepoint
*t
= (struct tracepoint
*) b
;
6245 if (!part_of_multiple
&& t
->pass_count
)
6247 annotate_field (10);
6248 uiout
->text ("\tpass count ");
6249 uiout
->field_signed ("pass", t
->pass_count
);
6250 uiout
->text (" \n");
6253 /* Don't display it when tracepoint or tracepoint location is
6255 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6257 annotate_field (11);
6259 if (uiout
->is_mi_like_p ())
6260 uiout
->field_string ("installed",
6261 loc
->inserted
? "y" : "n");
6267 uiout
->text ("\tnot ");
6268 uiout
->text ("installed on target\n");
6273 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6275 if (is_watchpoint (b
))
6277 struct watchpoint
*w
= (struct watchpoint
*) b
;
6279 uiout
->field_string ("original-location", w
->exp_string
);
6281 else if (b
->location
!= NULL
6282 && event_location_to_string (b
->location
.get ()) != NULL
)
6283 uiout
->field_string ("original-location",
6284 event_location_to_string (b
->location
.get ()));
6288 /* See breakpoint.h. */
6290 bool fix_multi_location_breakpoint_output_globally
= false;
6293 print_one_breakpoint (struct breakpoint
*b
,
6294 struct bp_location
**last_loc
,
6297 struct ui_out
*uiout
= current_uiout
;
6298 bool use_fixed_output
6299 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6300 || fix_multi_location_breakpoint_output_globally
);
6302 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6303 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6305 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6307 if (!use_fixed_output
)
6308 bkpt_tuple_emitter
.reset ();
6310 /* If this breakpoint has custom print function,
6311 it's already printed. Otherwise, print individual
6312 locations, if any. */
6314 || b
->ops
->print_one
== NULL
6317 /* If breakpoint has a single location that is disabled, we
6318 print it as if it had several locations, since otherwise it's
6319 hard to represent "breakpoint enabled, location disabled"
6322 Note that while hardware watchpoints have several locations
6323 internally, that's not a property exposed to users.
6325 Likewise, while catchpoints may be implemented with
6326 breakpoints (e.g., catch throw), that's not a property
6327 exposed to users. We do however display the internal
6328 breakpoint locations with "maint info breakpoints". */
6329 if (!is_hardware_watchpoint (b
)
6330 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6331 || is_ada_exception_catchpoint (b
))
6333 || (b
->loc
&& (b
->loc
->next
|| !b
->loc
->enabled
))))
6335 gdb::optional
<ui_out_emit_list
> locations_list
;
6337 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6338 MI record. For later versions, place breakpoint locations in a
6340 if (uiout
->is_mi_like_p () && use_fixed_output
)
6341 locations_list
.emplace (uiout
, "locations");
6344 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
, ++n
)
6346 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6347 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6355 breakpoint_address_bits (struct breakpoint
*b
)
6357 int print_address_bits
= 0;
6358 struct bp_location
*loc
;
6360 /* Software watchpoints that aren't watching memory don't have an
6361 address to print. */
6362 if (is_no_memory_software_watchpoint (b
))
6365 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6369 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6370 if (addr_bit
> print_address_bits
)
6371 print_address_bits
= addr_bit
;
6374 return print_address_bits
;
6377 /* See breakpoint.h. */
6380 print_breakpoint (breakpoint
*b
)
6382 struct bp_location
*dummy_loc
= NULL
;
6383 print_one_breakpoint (b
, &dummy_loc
, 0);
6386 /* Return true if this breakpoint was set by the user, false if it is
6387 internal or momentary. */
6390 user_breakpoint_p (struct breakpoint
*b
)
6392 return b
->number
> 0;
6395 /* See breakpoint.h. */
6398 pending_breakpoint_p (struct breakpoint
*b
)
6400 return b
->loc
== NULL
;
6403 /* Print information on breakpoints (including watchpoints and tracepoints).
6405 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6406 understood by number_or_range_parser. Only breakpoints included in this
6407 list are then printed.
6409 If SHOW_INTERNAL is true, print internal breakpoints.
6411 If FILTER is non-NULL, call it on each breakpoint and only include the
6412 ones for which it returns true.
6414 Return the total number of breakpoints listed. */
6417 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6418 bool (*filter
) (const struct breakpoint
*))
6420 struct breakpoint
*b
;
6421 struct bp_location
*last_loc
= NULL
;
6422 int nr_printable_breakpoints
;
6423 struct value_print_options opts
;
6424 int print_address_bits
= 0;
6425 int print_type_col_width
= 14;
6426 struct ui_out
*uiout
= current_uiout
;
6428 get_user_print_options (&opts
);
6430 /* Compute the number of rows in the table, as well as the size
6431 required for address fields. */
6432 nr_printable_breakpoints
= 0;
6435 /* If we have a filter, only list the breakpoints it accepts. */
6436 if (filter
&& !filter (b
))
6439 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6440 accept. Skip the others. */
6441 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6443 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6445 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6449 if (show_internal
|| user_breakpoint_p (b
))
6451 int addr_bit
, type_len
;
6453 addr_bit
= breakpoint_address_bits (b
);
6454 if (addr_bit
> print_address_bits
)
6455 print_address_bits
= addr_bit
;
6457 type_len
= strlen (bptype_string (b
->type
));
6458 if (type_len
> print_type_col_width
)
6459 print_type_col_width
= type_len
;
6461 nr_printable_breakpoints
++;
6466 ui_out_emit_table
table_emitter (uiout
,
6467 opts
.addressprint
? 6 : 5,
6468 nr_printable_breakpoints
,
6471 if (nr_printable_breakpoints
> 0)
6472 annotate_breakpoints_headers ();
6473 if (nr_printable_breakpoints
> 0)
6475 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6476 if (nr_printable_breakpoints
> 0)
6478 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6479 if (nr_printable_breakpoints
> 0)
6481 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6482 if (nr_printable_breakpoints
> 0)
6484 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6485 if (opts
.addressprint
)
6487 if (nr_printable_breakpoints
> 0)
6489 if (print_address_bits
<= 32)
6490 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6492 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6494 if (nr_printable_breakpoints
> 0)
6496 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6497 uiout
->table_body ();
6498 if (nr_printable_breakpoints
> 0)
6499 annotate_breakpoints_table ();
6504 /* If we have a filter, only list the breakpoints it accepts. */
6505 if (filter
&& !filter (b
))
6508 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6509 accept. Skip the others. */
6511 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6513 if (show_internal
) /* maintenance info breakpoint */
6515 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6518 else /* all others */
6520 if (!number_is_in_list (bp_num_list
, b
->number
))
6524 /* We only print out user settable breakpoints unless the
6525 show_internal is set. */
6526 if (show_internal
|| user_breakpoint_p (b
))
6527 print_one_breakpoint (b
, &last_loc
, show_internal
);
6531 if (nr_printable_breakpoints
== 0)
6533 /* If there's a filter, let the caller decide how to report
6537 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6538 uiout
->message ("No breakpoints or watchpoints.\n");
6540 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6546 if (last_loc
&& !server_command
)
6547 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6550 /* FIXME? Should this be moved up so that it is only called when
6551 there have been breakpoints? */
6552 annotate_breakpoints_table_end ();
6554 return nr_printable_breakpoints
;
6557 /* Display the value of default-collect in a way that is generally
6558 compatible with the breakpoint list. */
6561 default_collect_info (void)
6563 struct ui_out
*uiout
= current_uiout
;
6565 /* If it has no value (which is frequently the case), say nothing; a
6566 message like "No default-collect." gets in user's face when it's
6568 if (!*default_collect
)
6571 /* The following phrase lines up nicely with per-tracepoint collect
6573 uiout
->text ("default collect ");
6574 uiout
->field_string ("default-collect", default_collect
);
6575 uiout
->text (" \n");
6579 info_breakpoints_command (const char *args
, int from_tty
)
6581 breakpoint_1 (args
, false, NULL
);
6583 default_collect_info ();
6587 info_watchpoints_command (const char *args
, int from_tty
)
6589 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6590 struct ui_out
*uiout
= current_uiout
;
6592 if (num_printed
== 0)
6594 if (args
== NULL
|| *args
== '\0')
6595 uiout
->message ("No watchpoints.\n");
6597 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6602 maintenance_info_breakpoints (const char *args
, int from_tty
)
6604 breakpoint_1 (args
, true, NULL
);
6606 default_collect_info ();
6610 breakpoint_has_pc (struct breakpoint
*b
,
6611 struct program_space
*pspace
,
6612 CORE_ADDR pc
, struct obj_section
*section
)
6614 struct bp_location
*bl
= b
->loc
;
6616 for (; bl
; bl
= bl
->next
)
6618 if (bl
->pspace
== pspace
6619 && bl
->address
== pc
6620 && (!overlay_debugging
|| bl
->section
== section
))
6626 /* Print a message describing any user-breakpoints set at PC. This
6627 concerns with logical breakpoints, so we match program spaces, not
6631 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6632 struct program_space
*pspace
, CORE_ADDR pc
,
6633 struct obj_section
*section
, int thread
)
6636 struct breakpoint
*b
;
6639 others
+= (user_breakpoint_p (b
)
6640 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6644 printf_filtered (_("Note: breakpoint "));
6645 else /* if (others == ???) */
6646 printf_filtered (_("Note: breakpoints "));
6648 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6651 printf_filtered ("%d", b
->number
);
6652 if (b
->thread
== -1 && thread
!= -1)
6653 printf_filtered (" (all threads)");
6654 else if (b
->thread
!= -1)
6655 printf_filtered (" (thread %d)", b
->thread
);
6656 printf_filtered ("%s%s ",
6657 ((b
->enable_state
== bp_disabled
6658 || b
->enable_state
== bp_call_disabled
)
6662 : ((others
== 1) ? " and" : ""));
6664 current_uiout
->message (_("also set at pc %ps.\n"),
6665 styled_string (address_style
.style (),
6666 paddress (gdbarch
, pc
)));
6671 /* Return true iff it is meaningful to use the address member of LOC.
6672 For some breakpoint types, the locations' address members are
6673 irrelevant and it makes no sense to attempt to compare them to
6674 other addresses (or use them for any other purpose either).
6676 More specifically, software watchpoints and catchpoints that are
6677 not backed by breakpoints always have a zero valued location
6678 address and we don't want to mark breakpoints of any of these types
6679 to be a duplicate of an actual breakpoint location at address
6683 bl_address_is_meaningful (bp_location
*loc
)
6685 return loc
->loc_type
!= bp_loc_other
;
6688 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6689 true if LOC1 and LOC2 represent the same watchpoint location. */
6692 watchpoint_locations_match (struct bp_location
*loc1
,
6693 struct bp_location
*loc2
)
6695 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6696 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6698 /* Both of them must exist. */
6699 gdb_assert (w1
!= NULL
);
6700 gdb_assert (w2
!= NULL
);
6702 /* If the target can evaluate the condition expression in hardware,
6703 then we we need to insert both watchpoints even if they are at
6704 the same place. Otherwise the watchpoint will only trigger when
6705 the condition of whichever watchpoint was inserted evaluates to
6706 true, not giving a chance for GDB to check the condition of the
6707 other watchpoint. */
6709 && target_can_accel_watchpoint_condition (loc1
->address
,
6711 loc1
->watchpoint_type
,
6712 w1
->cond_exp
.get ()))
6714 && target_can_accel_watchpoint_condition (loc2
->address
,
6716 loc2
->watchpoint_type
,
6717 w2
->cond_exp
.get ())))
6720 /* Note that this checks the owner's type, not the location's. In
6721 case the target does not support read watchpoints, but does
6722 support access watchpoints, we'll have bp_read_watchpoint
6723 watchpoints with hw_access locations. Those should be considered
6724 duplicates of hw_read locations. The hw_read locations will
6725 become hw_access locations later. */
6726 return (loc1
->owner
->type
== loc2
->owner
->type
6727 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6728 && loc1
->address
== loc2
->address
6729 && loc1
->length
== loc2
->length
);
6732 /* See breakpoint.h. */
6735 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6736 const address_space
*aspace2
, CORE_ADDR addr2
)
6738 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6739 || aspace1
== aspace2
)
6743 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6744 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6745 matches ASPACE2. On targets that have global breakpoints, the address
6746 space doesn't really matter. */
6749 breakpoint_address_match_range (const address_space
*aspace1
,
6751 int len1
, const address_space
*aspace2
,
6754 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6755 || aspace1
== aspace2
)
6756 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6759 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6760 a ranged breakpoint. In most targets, a match happens only if ASPACE
6761 matches the breakpoint's address space. On targets that have global
6762 breakpoints, the address space doesn't really matter. */
6765 breakpoint_location_address_match (struct bp_location
*bl
,
6766 const address_space
*aspace
,
6769 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6772 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6773 bl
->address
, bl
->length
,
6777 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6778 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6779 match happens only if ASPACE matches the breakpoint's address
6780 space. On targets that have global breakpoints, the address space
6781 doesn't really matter. */
6784 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6785 const address_space
*aspace
,
6786 CORE_ADDR addr
, int len
)
6788 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6789 || bl
->pspace
->aspace
== aspace
)
6791 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6793 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6799 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6800 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6801 true, otherwise returns false. */
6804 tracepoint_locations_match (struct bp_location
*loc1
,
6805 struct bp_location
*loc2
)
6807 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6808 /* Since tracepoint locations are never duplicated with others', tracepoint
6809 locations at the same address of different tracepoints are regarded as
6810 different locations. */
6811 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6816 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6817 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6818 the same location. */
6821 breakpoint_locations_match (struct bp_location
*loc1
,
6822 struct bp_location
*loc2
)
6824 int hw_point1
, hw_point2
;
6826 /* Both of them must not be in moribund_locations. */
6827 gdb_assert (loc1
->owner
!= NULL
);
6828 gdb_assert (loc2
->owner
!= NULL
);
6830 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6831 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6833 if (hw_point1
!= hw_point2
)
6836 return watchpoint_locations_match (loc1
, loc2
);
6837 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6838 return tracepoint_locations_match (loc1
, loc2
);
6840 /* We compare bp_location.length in order to cover ranged breakpoints. */
6841 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6842 loc2
->pspace
->aspace
, loc2
->address
)
6843 && loc1
->length
== loc2
->length
);
6847 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6848 int bnum
, int have_bnum
)
6850 /* The longest string possibly returned by hex_string_custom
6851 is 50 chars. These must be at least that big for safety. */
6855 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6856 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6858 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6859 bnum
, astr1
, astr2
);
6861 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6864 /* Adjust a breakpoint's address to account for architectural
6865 constraints on breakpoint placement. Return the adjusted address.
6866 Note: Very few targets require this kind of adjustment. For most
6867 targets, this function is simply the identity function. */
6870 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6871 CORE_ADDR bpaddr
, enum bptype bptype
)
6873 if (bptype
== bp_watchpoint
6874 || bptype
== bp_hardware_watchpoint
6875 || bptype
== bp_read_watchpoint
6876 || bptype
== bp_access_watchpoint
6877 || bptype
== bp_catchpoint
)
6879 /* Watchpoints and the various bp_catch_* eventpoints should not
6880 have their addresses modified. */
6883 else if (bptype
== bp_single_step
)
6885 /* Single-step breakpoints should not have their addresses
6886 modified. If there's any architectural constrain that
6887 applies to this address, then it should have already been
6888 taken into account when the breakpoint was created in the
6889 first place. If we didn't do this, stepping through e.g.,
6890 Thumb-2 IT blocks would break. */
6895 CORE_ADDR adjusted_bpaddr
= bpaddr
;
6897 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
6899 /* Some targets have architectural constraints on the placement
6900 of breakpoint instructions. Obtain the adjusted address. */
6901 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6904 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
6906 /* An adjusted breakpoint address can significantly alter
6907 a user's expectations. Print a warning if an adjustment
6909 if (adjusted_bpaddr
!= bpaddr
)
6910 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6912 return adjusted_bpaddr
;
6917 bp_location_from_bp_type (bptype type
)
6922 case bp_single_step
:
6926 case bp_longjmp_resume
:
6927 case bp_longjmp_call_dummy
:
6929 case bp_exception_resume
:
6930 case bp_step_resume
:
6931 case bp_hp_step_resume
:
6932 case bp_watchpoint_scope
:
6934 case bp_std_terminate
:
6935 case bp_shlib_event
:
6936 case bp_thread_event
:
6937 case bp_overlay_event
:
6939 case bp_longjmp_master
:
6940 case bp_std_terminate_master
:
6941 case bp_exception_master
:
6942 case bp_gnu_ifunc_resolver
:
6943 case bp_gnu_ifunc_resolver_return
:
6945 return bp_loc_software_breakpoint
;
6946 case bp_hardware_breakpoint
:
6947 return bp_loc_hardware_breakpoint
;
6948 case bp_hardware_watchpoint
:
6949 case bp_read_watchpoint
:
6950 case bp_access_watchpoint
:
6951 return bp_loc_hardware_watchpoint
;
6955 case bp_fast_tracepoint
:
6956 case bp_static_tracepoint
:
6957 return bp_loc_other
;
6959 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
6963 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
6965 this->owner
= owner
;
6966 this->cond_bytecode
= NULL
;
6967 this->shlib_disabled
= 0;
6970 this->loc_type
= type
;
6972 if (this->loc_type
== bp_loc_software_breakpoint
6973 || this->loc_type
== bp_loc_hardware_breakpoint
)
6974 mark_breakpoint_location_modified (this);
6979 bp_location::bp_location (breakpoint
*owner
)
6980 : bp_location::bp_location (owner
,
6981 bp_location_from_bp_type (owner
->type
))
6985 /* Allocate a struct bp_location. */
6987 static struct bp_location
*
6988 allocate_bp_location (struct breakpoint
*bpt
)
6990 return bpt
->ops
->allocate_location (bpt
);
6994 free_bp_location (struct bp_location
*loc
)
6999 /* Increment reference count. */
7002 incref_bp_location (struct bp_location
*bl
)
7007 /* Decrement reference count. If the reference count reaches 0,
7008 destroy the bp_location. Sets *BLP to NULL. */
7011 decref_bp_location (struct bp_location
**blp
)
7013 gdb_assert ((*blp
)->refc
> 0);
7015 if (--(*blp
)->refc
== 0)
7016 free_bp_location (*blp
);
7020 /* Add breakpoint B at the end of the global breakpoint chain. */
7023 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7025 struct breakpoint
*b1
;
7026 struct breakpoint
*result
= b
.get ();
7028 /* Add this breakpoint to the end of the chain so that a list of
7029 breakpoints will come out in order of increasing numbers. */
7031 b1
= breakpoint_chain
;
7033 breakpoint_chain
= b
.release ();
7038 b1
->next
= b
.release ();
7044 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7047 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7048 struct gdbarch
*gdbarch
,
7050 const struct breakpoint_ops
*ops
)
7052 gdb_assert (ops
!= NULL
);
7056 b
->gdbarch
= gdbarch
;
7057 b
->language
= current_language
->la_language
;
7058 b
->input_radix
= input_radix
;
7059 b
->related_breakpoint
= b
;
7062 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7063 that has type BPTYPE and has no locations as yet. */
7065 static struct breakpoint
*
7066 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7068 const struct breakpoint_ops
*ops
)
7070 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7072 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7073 return add_to_breakpoint_chain (std::move (b
));
7076 /* Initialize loc->function_name. */
7079 set_breakpoint_location_function (struct bp_location
*loc
)
7081 gdb_assert (loc
->owner
!= NULL
);
7083 if (loc
->owner
->type
== bp_breakpoint
7084 || loc
->owner
->type
== bp_hardware_breakpoint
7085 || is_tracepoint (loc
->owner
))
7087 const char *function_name
;
7089 if (loc
->msymbol
!= NULL
7090 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7091 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7093 struct breakpoint
*b
= loc
->owner
;
7095 function_name
= loc
->msymbol
->linkage_name ();
7097 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7098 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7100 /* Create only the whole new breakpoint of this type but do not
7101 mess more complicated breakpoints with multiple locations. */
7102 b
->type
= bp_gnu_ifunc_resolver
;
7103 /* Remember the resolver's address for use by the return
7105 loc
->related_address
= loc
->address
;
7109 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7112 loc
->function_name
= xstrdup (function_name
);
7116 /* Attempt to determine architecture of location identified by SAL. */
7118 get_sal_arch (struct symtab_and_line sal
)
7121 return get_objfile_arch (sal
.section
->objfile
);
7123 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7128 /* Low level routine for partially initializing a breakpoint of type
7129 BPTYPE. The newly created breakpoint's address, section, source
7130 file name, and line number are provided by SAL.
7132 It is expected that the caller will complete the initialization of
7133 the newly created breakpoint struct as well as output any status
7134 information regarding the creation of a new breakpoint. */
7137 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7138 struct symtab_and_line sal
, enum bptype bptype
,
7139 const struct breakpoint_ops
*ops
)
7141 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7143 add_location_to_breakpoint (b
, &sal
);
7145 if (bptype
!= bp_catchpoint
)
7146 gdb_assert (sal
.pspace
!= NULL
);
7148 /* Store the program space that was used to set the breakpoint,
7149 except for ordinary breakpoints, which are independent of the
7151 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7152 b
->pspace
= sal
.pspace
;
7155 /* set_raw_breakpoint is a low level routine for allocating and
7156 partially initializing a breakpoint of type BPTYPE. The newly
7157 created breakpoint's address, section, source file name, and line
7158 number are provided by SAL. The newly created and partially
7159 initialized breakpoint is added to the breakpoint chain and
7160 is also returned as the value of this function.
7162 It is expected that the caller will complete the initialization of
7163 the newly created breakpoint struct as well as output any status
7164 information regarding the creation of a new breakpoint. In
7165 particular, set_raw_breakpoint does NOT set the breakpoint
7166 number! Care should be taken to not allow an error to occur
7167 prior to completing the initialization of the breakpoint. If this
7168 should happen, a bogus breakpoint will be left on the chain. */
7171 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7172 struct symtab_and_line sal
, enum bptype bptype
,
7173 const struct breakpoint_ops
*ops
)
7175 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7177 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7178 return add_to_breakpoint_chain (std::move (b
));
7181 /* Call this routine when stepping and nexting to enable a breakpoint
7182 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7183 initiated the operation. */
7186 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7188 struct breakpoint
*b
, *b_tmp
;
7189 int thread
= tp
->global_num
;
7191 /* To avoid having to rescan all objfile symbols at every step,
7192 we maintain a list of continually-inserted but always disabled
7193 longjmp "master" breakpoints. Here, we simply create momentary
7194 clones of those and enable them for the requested thread. */
7195 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7196 if (b
->pspace
== current_program_space
7197 && (b
->type
== bp_longjmp_master
7198 || b
->type
== bp_exception_master
))
7200 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7201 struct breakpoint
*clone
;
7203 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7204 after their removal. */
7205 clone
= momentary_breakpoint_from_master (b
, type
,
7206 &momentary_breakpoint_ops
, 1);
7207 clone
->thread
= thread
;
7210 tp
->initiating_frame
= frame
;
7213 /* Delete all longjmp breakpoints from THREAD. */
7215 delete_longjmp_breakpoint (int thread
)
7217 struct breakpoint
*b
, *b_tmp
;
7219 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7220 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7222 if (b
->thread
== thread
)
7223 delete_breakpoint (b
);
7228 delete_longjmp_breakpoint_at_next_stop (int thread
)
7230 struct breakpoint
*b
, *b_tmp
;
7232 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7233 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7235 if (b
->thread
== thread
)
7236 b
->disposition
= disp_del_at_next_stop
;
7240 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7241 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7242 pointer to any of them. Return NULL if this system cannot place longjmp
7246 set_longjmp_breakpoint_for_call_dummy (void)
7248 struct breakpoint
*b
, *retval
= NULL
;
7251 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7253 struct breakpoint
*new_b
;
7255 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7256 &momentary_breakpoint_ops
,
7258 new_b
->thread
= inferior_thread ()->global_num
;
7260 /* Link NEW_B into the chain of RETVAL breakpoints. */
7262 gdb_assert (new_b
->related_breakpoint
== new_b
);
7265 new_b
->related_breakpoint
= retval
;
7266 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7267 retval
= retval
->related_breakpoint
;
7268 retval
->related_breakpoint
= new_b
;
7274 /* Verify all existing dummy frames and their associated breakpoints for
7275 TP. Remove those which can no longer be found in the current frame
7278 You should call this function only at places where it is safe to currently
7279 unwind the whole stack. Failed stack unwind would discard live dummy
7283 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7285 struct breakpoint
*b
, *b_tmp
;
7287 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7288 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7290 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7292 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7293 dummy_b
= dummy_b
->related_breakpoint
;
7294 if (dummy_b
->type
!= bp_call_dummy
7295 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7298 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7300 while (b
->related_breakpoint
!= b
)
7302 if (b_tmp
== b
->related_breakpoint
)
7303 b_tmp
= b
->related_breakpoint
->next
;
7304 delete_breakpoint (b
->related_breakpoint
);
7306 delete_breakpoint (b
);
7311 enable_overlay_breakpoints (void)
7313 struct breakpoint
*b
;
7316 if (b
->type
== bp_overlay_event
)
7318 b
->enable_state
= bp_enabled
;
7319 update_global_location_list (UGLL_MAY_INSERT
);
7320 overlay_events_enabled
= 1;
7325 disable_overlay_breakpoints (void)
7327 struct breakpoint
*b
;
7330 if (b
->type
== bp_overlay_event
)
7332 b
->enable_state
= bp_disabled
;
7333 update_global_location_list (UGLL_DONT_INSERT
);
7334 overlay_events_enabled
= 0;
7338 /* Set an active std::terminate breakpoint for each std::terminate
7339 master breakpoint. */
7341 set_std_terminate_breakpoint (void)
7343 struct breakpoint
*b
, *b_tmp
;
7345 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7346 if (b
->pspace
== current_program_space
7347 && b
->type
== bp_std_terminate_master
)
7349 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7350 &momentary_breakpoint_ops
, 1);
7354 /* Delete all the std::terminate breakpoints. */
7356 delete_std_terminate_breakpoint (void)
7358 struct breakpoint
*b
, *b_tmp
;
7360 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7361 if (b
->type
== bp_std_terminate
)
7362 delete_breakpoint (b
);
7366 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7368 struct breakpoint
*b
;
7370 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7371 &internal_breakpoint_ops
);
7373 b
->enable_state
= bp_enabled
;
7374 /* location has to be used or breakpoint_re_set will delete me. */
7375 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7377 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7382 struct lang_and_radix
7388 /* Create a breakpoint for JIT code registration and unregistration. */
7391 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7393 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7394 &internal_breakpoint_ops
);
7397 /* Remove JIT code registration and unregistration breakpoint(s). */
7400 remove_jit_event_breakpoints (void)
7402 struct breakpoint
*b
, *b_tmp
;
7404 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7405 if (b
->type
== bp_jit_event
7406 && b
->loc
->pspace
== current_program_space
)
7407 delete_breakpoint (b
);
7411 remove_solib_event_breakpoints (void)
7413 struct breakpoint
*b
, *b_tmp
;
7415 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7416 if (b
->type
== bp_shlib_event
7417 && b
->loc
->pspace
== current_program_space
)
7418 delete_breakpoint (b
);
7421 /* See breakpoint.h. */
7424 remove_solib_event_breakpoints_at_next_stop (void)
7426 struct breakpoint
*b
, *b_tmp
;
7428 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7429 if (b
->type
== bp_shlib_event
7430 && b
->loc
->pspace
== current_program_space
)
7431 b
->disposition
= disp_del_at_next_stop
;
7434 /* Helper for create_solib_event_breakpoint /
7435 create_and_insert_solib_event_breakpoint. Allows specifying which
7436 INSERT_MODE to pass through to update_global_location_list. */
7438 static struct breakpoint
*
7439 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7440 enum ugll_insert_mode insert_mode
)
7442 struct breakpoint
*b
;
7444 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7445 &internal_breakpoint_ops
);
7446 update_global_location_list_nothrow (insert_mode
);
7451 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7453 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7456 /* See breakpoint.h. */
7459 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7461 struct breakpoint
*b
;
7463 /* Explicitly tell update_global_location_list to insert
7465 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7466 if (!b
->loc
->inserted
)
7468 delete_breakpoint (b
);
7474 /* Disable any breakpoints that are on code in shared libraries. Only
7475 apply to enabled breakpoints, disabled ones can just stay disabled. */
7478 disable_breakpoints_in_shlibs (void)
7480 struct bp_location
*loc
, **locp_tmp
;
7482 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7484 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7485 struct breakpoint
*b
= loc
->owner
;
7487 /* We apply the check to all breakpoints, including disabled for
7488 those with loc->duplicate set. This is so that when breakpoint
7489 becomes enabled, or the duplicate is removed, gdb will try to
7490 insert all breakpoints. If we don't set shlib_disabled here,
7491 we'll try to insert those breakpoints and fail. */
7492 if (((b
->type
== bp_breakpoint
)
7493 || (b
->type
== bp_jit_event
)
7494 || (b
->type
== bp_hardware_breakpoint
)
7495 || (is_tracepoint (b
)))
7496 && loc
->pspace
== current_program_space
7497 && !loc
->shlib_disabled
7498 && solib_name_from_address (loc
->pspace
, loc
->address
)
7501 loc
->shlib_disabled
= 1;
7506 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7507 notification of unloaded_shlib. Only apply to enabled breakpoints,
7508 disabled ones can just stay disabled. */
7511 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7513 struct bp_location
*loc
, **locp_tmp
;
7514 int disabled_shlib_breaks
= 0;
7516 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7518 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7519 struct breakpoint
*b
= loc
->owner
;
7521 if (solib
->pspace
== loc
->pspace
7522 && !loc
->shlib_disabled
7523 && (((b
->type
== bp_breakpoint
7524 || b
->type
== bp_jit_event
7525 || b
->type
== bp_hardware_breakpoint
)
7526 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7527 || loc
->loc_type
== bp_loc_software_breakpoint
))
7528 || is_tracepoint (b
))
7529 && solib_contains_address_p (solib
, loc
->address
))
7531 loc
->shlib_disabled
= 1;
7532 /* At this point, we cannot rely on remove_breakpoint
7533 succeeding so we must mark the breakpoint as not inserted
7534 to prevent future errors occurring in remove_breakpoints. */
7537 /* This may cause duplicate notifications for the same breakpoint. */
7538 gdb::observers::breakpoint_modified
.notify (b
);
7540 if (!disabled_shlib_breaks
)
7542 target_terminal::ours_for_output ();
7543 warning (_("Temporarily disabling breakpoints "
7544 "for unloaded shared library \"%s\""),
7547 disabled_shlib_breaks
= 1;
7552 /* Disable any breakpoints and tracepoints in OBJFILE upon
7553 notification of free_objfile. Only apply to enabled breakpoints,
7554 disabled ones can just stay disabled. */
7557 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7559 struct breakpoint
*b
;
7561 if (objfile
== NULL
)
7564 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7565 managed by the user with add-symbol-file/remove-symbol-file.
7566 Similarly to how breakpoints in shared libraries are handled in
7567 response to "nosharedlibrary", mark breakpoints in such modules
7568 shlib_disabled so they end up uninserted on the next global
7569 location list update. Shared libraries not loaded by the user
7570 aren't handled here -- they're already handled in
7571 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7572 solib_unloaded observer. We skip objfiles that are not
7573 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7575 if ((objfile
->flags
& OBJF_SHARED
) == 0
7576 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7581 struct bp_location
*loc
;
7582 int bp_modified
= 0;
7584 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7587 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7589 CORE_ADDR loc_addr
= loc
->address
;
7591 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7592 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7595 if (loc
->shlib_disabled
!= 0)
7598 if (objfile
->pspace
!= loc
->pspace
)
7601 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7602 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7605 if (is_addr_in_objfile (loc_addr
, objfile
))
7607 loc
->shlib_disabled
= 1;
7608 /* At this point, we don't know whether the object was
7609 unmapped from the inferior or not, so leave the
7610 inserted flag alone. We'll handle failure to
7611 uninsert quietly, in case the object was indeed
7614 mark_breakpoint_location_modified (loc
);
7621 gdb::observers::breakpoint_modified
.notify (b
);
7625 /* FORK & VFORK catchpoints. */
7627 /* An instance of this type is used to represent a fork or vfork
7628 catchpoint. A breakpoint is really of this type iff its ops pointer points
7629 to CATCH_FORK_BREAKPOINT_OPS. */
7631 struct fork_catchpoint
: public breakpoint
7633 /* Process id of a child process whose forking triggered this
7634 catchpoint. This field is only valid immediately after this
7635 catchpoint has triggered. */
7636 ptid_t forked_inferior_pid
;
7639 /* Implement the "insert" breakpoint_ops method for fork
7643 insert_catch_fork (struct bp_location
*bl
)
7645 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7648 /* Implement the "remove" breakpoint_ops method for fork
7652 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7654 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7657 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7661 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7662 const address_space
*aspace
, CORE_ADDR bp_addr
,
7663 const struct target_waitstatus
*ws
)
7665 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7667 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7670 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7674 /* Implement the "print_it" breakpoint_ops method for fork
7677 static enum print_stop_action
7678 print_it_catch_fork (bpstat bs
)
7680 struct ui_out
*uiout
= current_uiout
;
7681 struct breakpoint
*b
= bs
->breakpoint_at
;
7682 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7684 annotate_catchpoint (b
->number
);
7685 maybe_print_thread_hit_breakpoint (uiout
);
7686 if (b
->disposition
== disp_del
)
7687 uiout
->text ("Temporary catchpoint ");
7689 uiout
->text ("Catchpoint ");
7690 if (uiout
->is_mi_like_p ())
7692 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7693 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7695 uiout
->field_signed ("bkptno", b
->number
);
7696 uiout
->text (" (forked process ");
7697 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7698 uiout
->text ("), ");
7699 return PRINT_SRC_AND_LOC
;
7702 /* Implement the "print_one" breakpoint_ops method for fork
7706 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7708 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7709 struct value_print_options opts
;
7710 struct ui_out
*uiout
= current_uiout
;
7712 get_user_print_options (&opts
);
7714 /* Field 4, the address, is omitted (which makes the columns not
7715 line up too nicely with the headers, but the effect is relatively
7717 if (opts
.addressprint
)
7718 uiout
->field_skip ("addr");
7720 uiout
->text ("fork");
7721 if (c
->forked_inferior_pid
!= null_ptid
)
7723 uiout
->text (", process ");
7724 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7728 if (uiout
->is_mi_like_p ())
7729 uiout
->field_string ("catch-type", "fork");
7732 /* Implement the "print_mention" breakpoint_ops method for fork
7736 print_mention_catch_fork (struct breakpoint
*b
)
7738 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7741 /* Implement the "print_recreate" breakpoint_ops method for fork
7745 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7747 fprintf_unfiltered (fp
, "catch fork");
7748 print_recreate_thread (b
, fp
);
7751 /* The breakpoint_ops structure to be used in fork catchpoints. */
7753 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7755 /* Implement the "insert" breakpoint_ops method for vfork
7759 insert_catch_vfork (struct bp_location
*bl
)
7761 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7764 /* Implement the "remove" breakpoint_ops method for vfork
7768 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7770 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7773 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7777 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7778 const address_space
*aspace
, CORE_ADDR bp_addr
,
7779 const struct target_waitstatus
*ws
)
7781 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7783 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7786 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7790 /* Implement the "print_it" breakpoint_ops method for vfork
7793 static enum print_stop_action
7794 print_it_catch_vfork (bpstat bs
)
7796 struct ui_out
*uiout
= current_uiout
;
7797 struct breakpoint
*b
= bs
->breakpoint_at
;
7798 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7800 annotate_catchpoint (b
->number
);
7801 maybe_print_thread_hit_breakpoint (uiout
);
7802 if (b
->disposition
== disp_del
)
7803 uiout
->text ("Temporary catchpoint ");
7805 uiout
->text ("Catchpoint ");
7806 if (uiout
->is_mi_like_p ())
7808 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7809 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7811 uiout
->field_signed ("bkptno", b
->number
);
7812 uiout
->text (" (vforked process ");
7813 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7814 uiout
->text ("), ");
7815 return PRINT_SRC_AND_LOC
;
7818 /* Implement the "print_one" breakpoint_ops method for vfork
7822 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7824 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7825 struct value_print_options opts
;
7826 struct ui_out
*uiout
= current_uiout
;
7828 get_user_print_options (&opts
);
7829 /* Field 4, the address, is omitted (which makes the columns not
7830 line up too nicely with the headers, but the effect is relatively
7832 if (opts
.addressprint
)
7833 uiout
->field_skip ("addr");
7835 uiout
->text ("vfork");
7836 if (c
->forked_inferior_pid
!= null_ptid
)
7838 uiout
->text (", process ");
7839 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7843 if (uiout
->is_mi_like_p ())
7844 uiout
->field_string ("catch-type", "vfork");
7847 /* Implement the "print_mention" breakpoint_ops method for vfork
7851 print_mention_catch_vfork (struct breakpoint
*b
)
7853 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7856 /* Implement the "print_recreate" breakpoint_ops method for vfork
7860 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7862 fprintf_unfiltered (fp
, "catch vfork");
7863 print_recreate_thread (b
, fp
);
7866 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7868 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7870 /* An instance of this type is used to represent an solib catchpoint.
7871 A breakpoint is really of this type iff its ops pointer points to
7872 CATCH_SOLIB_BREAKPOINT_OPS. */
7874 struct solib_catchpoint
: public breakpoint
7876 ~solib_catchpoint () override
;
7878 /* True for "catch load", false for "catch unload". */
7879 unsigned char is_load
;
7881 /* Regular expression to match, if any. COMPILED is only valid when
7882 REGEX is non-NULL. */
7884 std::unique_ptr
<compiled_regex
> compiled
;
7887 solib_catchpoint::~solib_catchpoint ()
7889 xfree (this->regex
);
7893 insert_catch_solib (struct bp_location
*ignore
)
7899 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
7905 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7906 const address_space
*aspace
,
7908 const struct target_waitstatus
*ws
)
7910 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7911 struct breakpoint
*other
;
7913 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7916 ALL_BREAKPOINTS (other
)
7918 struct bp_location
*other_bl
;
7920 if (other
== bl
->owner
)
7923 if (other
->type
!= bp_shlib_event
)
7926 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
7929 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7931 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7940 check_status_catch_solib (struct bpstats
*bs
)
7942 struct solib_catchpoint
*self
7943 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7947 for (so_list
*iter
: current_program_space
->added_solibs
)
7950 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
7956 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
7959 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
7965 bs
->print_it
= print_it_noop
;
7968 static enum print_stop_action
7969 print_it_catch_solib (bpstat bs
)
7971 struct breakpoint
*b
= bs
->breakpoint_at
;
7972 struct ui_out
*uiout
= current_uiout
;
7974 annotate_catchpoint (b
->number
);
7975 maybe_print_thread_hit_breakpoint (uiout
);
7976 if (b
->disposition
== disp_del
)
7977 uiout
->text ("Temporary catchpoint ");
7979 uiout
->text ("Catchpoint ");
7980 uiout
->field_signed ("bkptno", b
->number
);
7982 if (uiout
->is_mi_like_p ())
7983 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7984 print_solib_event (1);
7985 return PRINT_SRC_AND_LOC
;
7989 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7991 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7992 struct value_print_options opts
;
7993 struct ui_out
*uiout
= current_uiout
;
7995 get_user_print_options (&opts
);
7996 /* Field 4, the address, is omitted (which makes the columns not
7997 line up too nicely with the headers, but the effect is relatively
7999 if (opts
.addressprint
)
8002 uiout
->field_skip ("addr");
8010 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8012 msg
= _("load of library");
8017 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8019 msg
= _("unload of library");
8021 uiout
->field_string ("what", msg
);
8023 if (uiout
->is_mi_like_p ())
8024 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8028 print_mention_catch_solib (struct breakpoint
*b
)
8030 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8032 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8033 self
->is_load
? "load" : "unload");
8037 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8039 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8041 fprintf_unfiltered (fp
, "%s %s",
8042 b
->disposition
== disp_del
? "tcatch" : "catch",
8043 self
->is_load
? "load" : "unload");
8045 fprintf_unfiltered (fp
, " %s", self
->regex
);
8046 fprintf_unfiltered (fp
, "\n");
8049 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8051 /* Shared helper function (MI and CLI) for creating and installing
8052 a shared object event catchpoint. If IS_LOAD is non-zero then
8053 the events to be caught are load events, otherwise they are
8054 unload events. If IS_TEMP is non-zero the catchpoint is a
8055 temporary one. If ENABLED is non-zero the catchpoint is
8056 created in an enabled state. */
8059 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8061 struct gdbarch
*gdbarch
= get_current_arch ();
8065 arg
= skip_spaces (arg
);
8067 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8071 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8072 _("Invalid regexp")));
8073 c
->regex
= xstrdup (arg
);
8076 c
->is_load
= is_load
;
8077 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8078 &catch_solib_breakpoint_ops
);
8080 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8082 install_breakpoint (0, std::move (c
), 1);
8085 /* A helper function that does all the work for "catch load" and
8089 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8090 struct cmd_list_element
*command
)
8093 const int enabled
= 1;
8095 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8097 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8101 catch_load_command_1 (const char *arg
, int from_tty
,
8102 struct cmd_list_element
*command
)
8104 catch_load_or_unload (arg
, from_tty
, 1, command
);
8108 catch_unload_command_1 (const char *arg
, int from_tty
,
8109 struct cmd_list_element
*command
)
8111 catch_load_or_unload (arg
, from_tty
, 0, command
);
8114 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8115 is non-zero, then make the breakpoint temporary. If COND_STRING is
8116 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8117 the breakpoint_ops structure associated to the catchpoint. */
8120 init_catchpoint (struct breakpoint
*b
,
8121 struct gdbarch
*gdbarch
, int tempflag
,
8122 const char *cond_string
,
8123 const struct breakpoint_ops
*ops
)
8125 symtab_and_line sal
;
8126 sal
.pspace
= current_program_space
;
8128 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8130 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8131 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8135 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8137 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8138 set_breakpoint_number (internal
, b
);
8139 if (is_tracepoint (b
))
8140 set_tracepoint_count (breakpoint_count
);
8143 gdb::observers::breakpoint_created
.notify (b
);
8146 update_global_location_list (UGLL_MAY_INSERT
);
8150 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8151 int tempflag
, const char *cond_string
,
8152 const struct breakpoint_ops
*ops
)
8154 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8156 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8158 c
->forked_inferior_pid
= null_ptid
;
8160 install_breakpoint (0, std::move (c
), 1);
8163 /* Exec catchpoints. */
8165 /* An instance of this type is used to represent an exec catchpoint.
8166 A breakpoint is really of this type iff its ops pointer points to
8167 CATCH_EXEC_BREAKPOINT_OPS. */
8169 struct exec_catchpoint
: public breakpoint
8171 ~exec_catchpoint () override
;
8173 /* Filename of a program whose exec triggered this catchpoint.
8174 This field is only valid immediately after this catchpoint has
8176 char *exec_pathname
;
8179 /* Exec catchpoint destructor. */
8181 exec_catchpoint::~exec_catchpoint ()
8183 xfree (this->exec_pathname
);
8187 insert_catch_exec (struct bp_location
*bl
)
8189 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8193 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8195 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8199 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8200 const address_space
*aspace
, CORE_ADDR bp_addr
,
8201 const struct target_waitstatus
*ws
)
8203 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8205 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8208 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8212 static enum print_stop_action
8213 print_it_catch_exec (bpstat bs
)
8215 struct ui_out
*uiout
= current_uiout
;
8216 struct breakpoint
*b
= bs
->breakpoint_at
;
8217 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8219 annotate_catchpoint (b
->number
);
8220 maybe_print_thread_hit_breakpoint (uiout
);
8221 if (b
->disposition
== disp_del
)
8222 uiout
->text ("Temporary catchpoint ");
8224 uiout
->text ("Catchpoint ");
8225 if (uiout
->is_mi_like_p ())
8227 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8228 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8230 uiout
->field_signed ("bkptno", b
->number
);
8231 uiout
->text (" (exec'd ");
8232 uiout
->field_string ("new-exec", c
->exec_pathname
);
8233 uiout
->text ("), ");
8235 return PRINT_SRC_AND_LOC
;
8239 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8241 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8242 struct value_print_options opts
;
8243 struct ui_out
*uiout
= current_uiout
;
8245 get_user_print_options (&opts
);
8247 /* Field 4, the address, is omitted (which makes the columns
8248 not line up too nicely with the headers, but the effect
8249 is relatively readable). */
8250 if (opts
.addressprint
)
8251 uiout
->field_skip ("addr");
8253 uiout
->text ("exec");
8254 if (c
->exec_pathname
!= NULL
)
8256 uiout
->text (", program \"");
8257 uiout
->field_string ("what", c
->exec_pathname
);
8258 uiout
->text ("\" ");
8261 if (uiout
->is_mi_like_p ())
8262 uiout
->field_string ("catch-type", "exec");
8266 print_mention_catch_exec (struct breakpoint
*b
)
8268 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8271 /* Implement the "print_recreate" breakpoint_ops method for exec
8275 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8277 fprintf_unfiltered (fp
, "catch exec");
8278 print_recreate_thread (b
, fp
);
8281 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8284 hw_breakpoint_used_count (void)
8287 struct breakpoint
*b
;
8288 struct bp_location
*bl
;
8292 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8293 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8295 /* Special types of hardware breakpoints may use more than
8297 i
+= b
->ops
->resources_needed (bl
);
8304 /* Returns the resources B would use if it were a hardware
8308 hw_watchpoint_use_count (struct breakpoint
*b
)
8311 struct bp_location
*bl
;
8313 if (!breakpoint_enabled (b
))
8316 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8318 /* Special types of hardware watchpoints may use more than
8320 i
+= b
->ops
->resources_needed (bl
);
8326 /* Returns the sum the used resources of all hardware watchpoints of
8327 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8328 the sum of the used resources of all hardware watchpoints of other
8329 types _not_ TYPE. */
8332 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8333 enum bptype type
, int *other_type_used
)
8336 struct breakpoint
*b
;
8338 *other_type_used
= 0;
8343 if (!breakpoint_enabled (b
))
8346 if (b
->type
== type
)
8347 i
+= hw_watchpoint_use_count (b
);
8348 else if (is_hardware_watchpoint (b
))
8349 *other_type_used
= 1;
8356 disable_watchpoints_before_interactive_call_start (void)
8358 struct breakpoint
*b
;
8362 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8364 b
->enable_state
= bp_call_disabled
;
8365 update_global_location_list (UGLL_DONT_INSERT
);
8371 enable_watchpoints_after_interactive_call_stop (void)
8373 struct breakpoint
*b
;
8377 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8379 b
->enable_state
= bp_enabled
;
8380 update_global_location_list (UGLL_MAY_INSERT
);
8386 disable_breakpoints_before_startup (void)
8388 current_program_space
->executing_startup
= 1;
8389 update_global_location_list (UGLL_DONT_INSERT
);
8393 enable_breakpoints_after_startup (void)
8395 current_program_space
->executing_startup
= 0;
8396 breakpoint_re_set ();
8399 /* Create a new single-step breakpoint for thread THREAD, with no
8402 static struct breakpoint
*
8403 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8405 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8407 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8408 &momentary_breakpoint_ops
);
8410 b
->disposition
= disp_donttouch
;
8411 b
->frame_id
= null_frame_id
;
8414 gdb_assert (b
->thread
!= 0);
8416 return add_to_breakpoint_chain (std::move (b
));
8419 /* Set a momentary breakpoint of type TYPE at address specified by
8420 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8424 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8425 struct frame_id frame_id
, enum bptype type
)
8427 struct breakpoint
*b
;
8429 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8431 gdb_assert (!frame_id_artificial_p (frame_id
));
8433 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8434 b
->enable_state
= bp_enabled
;
8435 b
->disposition
= disp_donttouch
;
8436 b
->frame_id
= frame_id
;
8438 b
->thread
= inferior_thread ()->global_num
;
8440 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8442 return breakpoint_up (b
);
8445 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8446 The new breakpoint will have type TYPE, use OPS as its
8447 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8449 static struct breakpoint
*
8450 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8452 const struct breakpoint_ops
*ops
,
8455 struct breakpoint
*copy
;
8457 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8458 copy
->loc
= allocate_bp_location (copy
);
8459 set_breakpoint_location_function (copy
->loc
);
8461 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8462 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8463 copy
->loc
->address
= orig
->loc
->address
;
8464 copy
->loc
->section
= orig
->loc
->section
;
8465 copy
->loc
->pspace
= orig
->loc
->pspace
;
8466 copy
->loc
->probe
= orig
->loc
->probe
;
8467 copy
->loc
->line_number
= orig
->loc
->line_number
;
8468 copy
->loc
->symtab
= orig
->loc
->symtab
;
8469 copy
->loc
->enabled
= loc_enabled
;
8470 copy
->frame_id
= orig
->frame_id
;
8471 copy
->thread
= orig
->thread
;
8472 copy
->pspace
= orig
->pspace
;
8474 copy
->enable_state
= bp_enabled
;
8475 copy
->disposition
= disp_donttouch
;
8476 copy
->number
= internal_breakpoint_number
--;
8478 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8482 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8486 clone_momentary_breakpoint (struct breakpoint
*orig
)
8488 /* If there's nothing to clone, then return nothing. */
8492 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8496 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8499 struct symtab_and_line sal
;
8501 sal
= find_pc_line (pc
, 0);
8503 sal
.section
= find_pc_overlay (pc
);
8504 sal
.explicit_pc
= 1;
8506 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8510 /* Tell the user we have just set a breakpoint B. */
8513 mention (struct breakpoint
*b
)
8515 b
->ops
->print_mention (b
);
8516 if (current_uiout
->is_mi_like_p ())
8518 printf_filtered ("\n");
8522 static int bp_loc_is_permanent (struct bp_location
*loc
);
8524 static struct bp_location
*
8525 add_location_to_breakpoint (struct breakpoint
*b
,
8526 const struct symtab_and_line
*sal
)
8528 struct bp_location
*loc
, **tmp
;
8529 CORE_ADDR adjusted_address
;
8530 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8532 if (loc_gdbarch
== NULL
)
8533 loc_gdbarch
= b
->gdbarch
;
8535 /* Adjust the breakpoint's address prior to allocating a location.
8536 Once we call allocate_bp_location(), that mostly uninitialized
8537 location will be placed on the location chain. Adjustment of the
8538 breakpoint may cause target_read_memory() to be called and we do
8539 not want its scan of the location chain to find a breakpoint and
8540 location that's only been partially initialized. */
8541 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8544 /* Sort the locations by their ADDRESS. */
8545 loc
= allocate_bp_location (b
);
8546 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8547 tmp
= &((*tmp
)->next
))
8552 loc
->requested_address
= sal
->pc
;
8553 loc
->address
= adjusted_address
;
8554 loc
->pspace
= sal
->pspace
;
8555 loc
->probe
.prob
= sal
->prob
;
8556 loc
->probe
.objfile
= sal
->objfile
;
8557 gdb_assert (loc
->pspace
!= NULL
);
8558 loc
->section
= sal
->section
;
8559 loc
->gdbarch
= loc_gdbarch
;
8560 loc
->line_number
= sal
->line
;
8561 loc
->symtab
= sal
->symtab
;
8562 loc
->symbol
= sal
->symbol
;
8563 loc
->msymbol
= sal
->msymbol
;
8564 loc
->objfile
= sal
->objfile
;
8566 set_breakpoint_location_function (loc
);
8568 /* While by definition, permanent breakpoints are already present in the
8569 code, we don't mark the location as inserted. Normally one would expect
8570 that GDB could rely on that breakpoint instruction to stop the program,
8571 thus removing the need to insert its own breakpoint, except that executing
8572 the breakpoint instruction can kill the target instead of reporting a
8573 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8574 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8575 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8576 breakpoint be inserted normally results in QEMU knowing about the GDB
8577 breakpoint, and thus trap before the breakpoint instruction is executed.
8578 (If GDB later needs to continue execution past the permanent breakpoint,
8579 it manually increments the PC, thus avoiding executing the breakpoint
8581 if (bp_loc_is_permanent (loc
))
8588 /* See breakpoint.h. */
8591 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8595 const gdb_byte
*bpoint
;
8596 gdb_byte
*target_mem
;
8599 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8601 /* Software breakpoints unsupported? */
8605 target_mem
= (gdb_byte
*) alloca (len
);
8607 /* Enable the automatic memory restoration from breakpoints while
8608 we read the memory. Otherwise we could say about our temporary
8609 breakpoints they are permanent. */
8610 scoped_restore restore_memory
8611 = make_scoped_restore_show_memory_breakpoints (0);
8613 if (target_read_memory (address
, target_mem
, len
) == 0
8614 && memcmp (target_mem
, bpoint
, len
) == 0)
8620 /* Return 1 if LOC is pointing to a permanent breakpoint,
8621 return 0 otherwise. */
8624 bp_loc_is_permanent (struct bp_location
*loc
)
8626 gdb_assert (loc
!= NULL
);
8628 /* If we have a non-breakpoint-backed catchpoint or a software
8629 watchpoint, just return 0. We should not attempt to read from
8630 the addresses the locations of these breakpoint types point to.
8631 program_breakpoint_here_p, below, will attempt to read
8633 if (!bl_address_is_meaningful (loc
))
8636 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8637 switch_to_program_space_and_thread (loc
->pspace
);
8638 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8641 /* Build a command list for the dprintf corresponding to the current
8642 settings of the dprintf style options. */
8645 update_dprintf_command_list (struct breakpoint
*b
)
8647 char *dprintf_args
= b
->extra_string
;
8648 char *printf_line
= NULL
;
8653 dprintf_args
= skip_spaces (dprintf_args
);
8655 /* Allow a comma, as it may have terminated a location, but don't
8657 if (*dprintf_args
== ',')
8659 dprintf_args
= skip_spaces (dprintf_args
);
8661 if (*dprintf_args
!= '"')
8662 error (_("Bad format string, missing '\"'."));
8664 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8665 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8666 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8668 if (!dprintf_function
)
8669 error (_("No function supplied for dprintf call"));
8671 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8672 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8677 printf_line
= xstrprintf ("call (void) %s (%s)",
8681 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8683 if (target_can_run_breakpoint_commands ())
8684 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8687 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8688 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8692 internal_error (__FILE__
, __LINE__
,
8693 _("Invalid dprintf style."));
8695 gdb_assert (printf_line
!= NULL
);
8697 /* Manufacture a printf sequence. */
8698 struct command_line
*printf_cmd_line
8699 = new struct command_line (simple_control
, printf_line
);
8700 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8701 command_lines_deleter ()));
8704 /* Update all dprintf commands, making their command lists reflect
8705 current style settings. */
8708 update_dprintf_commands (const char *args
, int from_tty
,
8709 struct cmd_list_element
*c
)
8711 struct breakpoint
*b
;
8715 if (b
->type
== bp_dprintf
)
8716 update_dprintf_command_list (b
);
8720 /* Create a breakpoint with SAL as location. Use LOCATION
8721 as a description of the location, and COND_STRING
8722 as condition expression. If LOCATION is NULL then create an
8723 "address location" from the address in the SAL. */
8726 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8727 gdb::array_view
<const symtab_and_line
> sals
,
8728 event_location_up
&&location
,
8729 gdb::unique_xmalloc_ptr
<char> filter
,
8730 gdb::unique_xmalloc_ptr
<char> cond_string
,
8731 gdb::unique_xmalloc_ptr
<char> extra_string
,
8732 enum bptype type
, enum bpdisp disposition
,
8733 int thread
, int task
, int ignore_count
,
8734 const struct breakpoint_ops
*ops
, int from_tty
,
8735 int enabled
, int internal
, unsigned flags
,
8736 int display_canonical
)
8740 if (type
== bp_hardware_breakpoint
)
8742 int target_resources_ok
;
8744 i
= hw_breakpoint_used_count ();
8745 target_resources_ok
=
8746 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8748 if (target_resources_ok
== 0)
8749 error (_("No hardware breakpoint support in the target."));
8750 else if (target_resources_ok
< 0)
8751 error (_("Hardware breakpoints used exceeds limit."));
8754 gdb_assert (!sals
.empty ());
8756 for (const auto &sal
: sals
)
8758 struct bp_location
*loc
;
8762 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8764 loc_gdbarch
= gdbarch
;
8766 describe_other_breakpoints (loc_gdbarch
,
8767 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8770 if (&sal
== &sals
[0])
8772 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8776 b
->cond_string
= cond_string
.release ();
8777 b
->extra_string
= extra_string
.release ();
8778 b
->ignore_count
= ignore_count
;
8779 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8780 b
->disposition
= disposition
;
8782 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8783 b
->loc
->inserted
= 1;
8785 if (type
== bp_static_tracepoint
)
8787 struct tracepoint
*t
= (struct tracepoint
*) b
;
8788 struct static_tracepoint_marker marker
;
8790 if (strace_marker_p (b
))
8792 /* We already know the marker exists, otherwise, we
8793 wouldn't see a sal for it. */
8795 = &event_location_to_string (b
->location
.get ())[3];
8798 p
= skip_spaces (p
);
8800 endp
= skip_to_space (p
);
8802 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8804 printf_filtered (_("Probed static tracepoint "
8806 t
->static_trace_marker_id
.c_str ());
8808 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8810 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8812 printf_filtered (_("Probed static tracepoint "
8814 t
->static_trace_marker_id
.c_str ());
8817 warning (_("Couldn't determine the static "
8818 "tracepoint marker to probe"));
8825 loc
= add_location_to_breakpoint (b
, &sal
);
8826 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8832 const char *arg
= b
->cond_string
;
8834 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
8835 block_for_pc (loc
->address
), 0);
8837 error (_("Garbage '%s' follows condition"), arg
);
8840 /* Dynamic printf requires and uses additional arguments on the
8841 command line, otherwise it's an error. */
8842 if (type
== bp_dprintf
)
8844 if (b
->extra_string
)
8845 update_dprintf_command_list (b
);
8847 error (_("Format string required"));
8849 else if (b
->extra_string
)
8850 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8853 b
->display_canonical
= display_canonical
;
8854 if (location
!= NULL
)
8855 b
->location
= std::move (location
);
8857 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8858 b
->filter
= std::move (filter
);
8862 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8863 gdb::array_view
<const symtab_and_line
> sals
,
8864 event_location_up
&&location
,
8865 gdb::unique_xmalloc_ptr
<char> filter
,
8866 gdb::unique_xmalloc_ptr
<char> cond_string
,
8867 gdb::unique_xmalloc_ptr
<char> extra_string
,
8868 enum bptype type
, enum bpdisp disposition
,
8869 int thread
, int task
, int ignore_count
,
8870 const struct breakpoint_ops
*ops
, int from_tty
,
8871 int enabled
, int internal
, unsigned flags
,
8872 int display_canonical
)
8874 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8876 init_breakpoint_sal (b
.get (), gdbarch
,
8877 sals
, std::move (location
),
8879 std::move (cond_string
),
8880 std::move (extra_string
),
8882 thread
, task
, ignore_count
,
8884 enabled
, internal
, flags
,
8887 install_breakpoint (internal
, std::move (b
), 0);
8890 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8891 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8892 value. COND_STRING, if not NULL, specified the condition to be
8893 used for all breakpoints. Essentially the only case where
8894 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8895 function. In that case, it's still not possible to specify
8896 separate conditions for different overloaded functions, so
8897 we take just a single condition string.
8899 NOTE: If the function succeeds, the caller is expected to cleanup
8900 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8901 array contents). If the function fails (error() is called), the
8902 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8903 COND and SALS arrays and each of those arrays contents. */
8906 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8907 struct linespec_result
*canonical
,
8908 gdb::unique_xmalloc_ptr
<char> cond_string
,
8909 gdb::unique_xmalloc_ptr
<char> extra_string
,
8910 enum bptype type
, enum bpdisp disposition
,
8911 int thread
, int task
, int ignore_count
,
8912 const struct breakpoint_ops
*ops
, int from_tty
,
8913 int enabled
, int internal
, unsigned flags
)
8915 if (canonical
->pre_expanded
)
8916 gdb_assert (canonical
->lsals
.size () == 1);
8918 for (const auto &lsal
: canonical
->lsals
)
8920 /* Note that 'location' can be NULL in the case of a plain
8921 'break', without arguments. */
8922 event_location_up location
8923 = (canonical
->location
!= NULL
8924 ? copy_event_location (canonical
->location
.get ()) : NULL
);
8925 gdb::unique_xmalloc_ptr
<char> filter_string
8926 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8928 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8929 std::move (location
),
8930 std::move (filter_string
),
8931 std::move (cond_string
),
8932 std::move (extra_string
),
8934 thread
, task
, ignore_count
, ops
,
8935 from_tty
, enabled
, internal
, flags
,
8936 canonical
->special_display
);
8940 /* Parse LOCATION which is assumed to be a SAL specification possibly
8941 followed by conditionals. On return, SALS contains an array of SAL
8942 addresses found. LOCATION points to the end of the SAL (for
8943 linespec locations).
8945 The array and the line spec strings are allocated on the heap, it is
8946 the caller's responsibility to free them. */
8949 parse_breakpoint_sals (const struct event_location
*location
,
8950 struct linespec_result
*canonical
)
8952 struct symtab_and_line cursal
;
8954 if (event_location_type (location
) == LINESPEC_LOCATION
)
8956 const char *spec
= get_linespec_location (location
)->spec_string
;
8960 /* The last displayed codepoint, if it's valid, is our default
8961 breakpoint address. */
8962 if (last_displayed_sal_is_valid ())
8964 /* Set sal's pspace, pc, symtab, and line to the values
8965 corresponding to the last call to print_frame_info.
8966 Be sure to reinitialize LINE with NOTCURRENT == 0
8967 as the breakpoint line number is inappropriate otherwise.
8968 find_pc_line would adjust PC, re-set it back. */
8969 symtab_and_line sal
= get_last_displayed_sal ();
8970 CORE_ADDR pc
= sal
.pc
;
8972 sal
= find_pc_line (pc
, 0);
8974 /* "break" without arguments is equivalent to "break *PC"
8975 where PC is the last displayed codepoint's address. So
8976 make sure to set sal.explicit_pc to prevent GDB from
8977 trying to expand the list of sals to include all other
8978 instances with the same symtab and line. */
8980 sal
.explicit_pc
= 1;
8982 struct linespec_sals lsal
;
8984 lsal
.canonical
= NULL
;
8986 canonical
->lsals
.push_back (std::move (lsal
));
8990 error (_("No default breakpoint address now."));
8994 /* Force almost all breakpoints to be in terms of the
8995 current_source_symtab (which is decode_line_1's default).
8996 This should produce the results we want almost all of the
8997 time while leaving default_breakpoint_* alone.
8999 ObjC: However, don't match an Objective-C method name which
9000 may have a '+' or '-' succeeded by a '['. */
9001 cursal
= get_current_source_symtab_and_line ();
9002 if (last_displayed_sal_is_valid ())
9004 const char *spec
= NULL
;
9006 if (event_location_type (location
) == LINESPEC_LOCATION
)
9007 spec
= get_linespec_location (location
)->spec_string
;
9011 && strchr ("+-", spec
[0]) != NULL
9014 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9015 get_last_displayed_symtab (),
9016 get_last_displayed_line (),
9017 canonical
, NULL
, NULL
);
9022 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9023 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9027 /* Convert each SAL into a real PC. Verify that the PC can be
9028 inserted as a breakpoint. If it can't throw an error. */
9031 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9033 for (auto &sal
: sals
)
9034 resolve_sal_pc (&sal
);
9037 /* Fast tracepoints may have restrictions on valid locations. For
9038 instance, a fast tracepoint using a jump instead of a trap will
9039 likely have to overwrite more bytes than a trap would, and so can
9040 only be placed where the instruction is longer than the jump, or a
9041 multi-instruction sequence does not have a jump into the middle of
9045 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9046 gdb::array_view
<const symtab_and_line
> sals
)
9048 for (const auto &sal
: sals
)
9050 struct gdbarch
*sarch
;
9052 sarch
= get_sal_arch (sal
);
9053 /* We fall back to GDBARCH if there is no architecture
9054 associated with SAL. */
9058 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9059 error (_("May not have a fast tracepoint at %s%s"),
9060 paddress (sarch
, sal
.pc
), msg
.c_str ());
9064 /* Given TOK, a string specification of condition and thread, as
9065 accepted by the 'break' command, extract the condition
9066 string and thread number and set *COND_STRING and *THREAD.
9067 PC identifies the context at which the condition should be parsed.
9068 If no condition is found, *COND_STRING is set to NULL.
9069 If no thread is found, *THREAD is set to -1. */
9072 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9073 char **cond_string
, int *thread
, int *task
,
9076 *cond_string
= NULL
;
9083 const char *end_tok
;
9085 const char *cond_start
= NULL
;
9086 const char *cond_end
= NULL
;
9088 tok
= skip_spaces (tok
);
9090 if ((*tok
== '"' || *tok
== ',') && rest
)
9092 *rest
= savestring (tok
, strlen (tok
));
9096 end_tok
= skip_to_space (tok
);
9098 toklen
= end_tok
- tok
;
9100 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9102 tok
= cond_start
= end_tok
+ 1;
9103 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9105 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9107 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9110 struct thread_info
*thr
;
9113 thr
= parse_thread_id (tok
, &tmptok
);
9115 error (_("Junk after thread keyword."));
9116 *thread
= thr
->global_num
;
9119 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9124 *task
= strtol (tok
, &tmptok
, 0);
9126 error (_("Junk after task keyword."));
9127 if (!valid_task_id (*task
))
9128 error (_("Unknown task %d."), *task
);
9133 *rest
= savestring (tok
, strlen (tok
));
9137 error (_("Junk at end of arguments."));
9141 /* Decode a static tracepoint marker spec. */
9143 static std::vector
<symtab_and_line
>
9144 decode_static_tracepoint_spec (const char **arg_p
)
9146 const char *p
= &(*arg_p
)[3];
9149 p
= skip_spaces (p
);
9151 endp
= skip_to_space (p
);
9153 std::string
marker_str (p
, endp
- p
);
9155 std::vector
<static_tracepoint_marker
> markers
9156 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9157 if (markers
.empty ())
9158 error (_("No known static tracepoint marker named %s"),
9159 marker_str
.c_str ());
9161 std::vector
<symtab_and_line
> sals
;
9162 sals
.reserve (markers
.size ());
9164 for (const static_tracepoint_marker
&marker
: markers
)
9166 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9167 sal
.pc
= marker
.address
;
9168 sals
.push_back (sal
);
9175 /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and
9176 according to IS_TRACEPOINT. */
9178 static const struct breakpoint_ops
*
9179 breakpoint_ops_for_event_location_type (enum event_location_type location_type
,
9184 if (location_type
== PROBE_LOCATION
)
9185 return &tracepoint_probe_breakpoint_ops
;
9187 return &tracepoint_breakpoint_ops
;
9191 if (location_type
== PROBE_LOCATION
)
9192 return &bkpt_probe_breakpoint_ops
;
9194 return &bkpt_breakpoint_ops
;
9198 /* See breakpoint.h. */
9200 const struct breakpoint_ops
*
9201 breakpoint_ops_for_event_location (const struct event_location
*location
,
9204 if (location
!= nullptr)
9205 return breakpoint_ops_for_event_location_type
9206 (event_location_type (location
), is_tracepoint
);
9207 return is_tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
9210 /* See breakpoint.h. */
9213 create_breakpoint (struct gdbarch
*gdbarch
,
9214 const struct event_location
*location
,
9215 const char *cond_string
,
9216 int thread
, const char *extra_string
,
9218 int tempflag
, enum bptype type_wanted
,
9220 enum auto_boolean pending_break_support
,
9221 const struct breakpoint_ops
*ops
,
9222 int from_tty
, int enabled
, int internal
,
9225 struct linespec_result canonical
;
9228 int prev_bkpt_count
= breakpoint_count
;
9230 gdb_assert (ops
!= NULL
);
9232 /* If extra_string isn't useful, set it to NULL. */
9233 if (extra_string
!= NULL
&& *extra_string
== '\0')
9234 extra_string
= NULL
;
9238 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9240 catch (const gdb_exception_error
&e
)
9242 /* If caller is interested in rc value from parse, set
9244 if (e
.error
== NOT_FOUND_ERROR
)
9246 /* If pending breakpoint support is turned off, throw
9249 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9252 exception_print (gdb_stderr
, e
);
9254 /* If pending breakpoint support is auto query and the user
9255 selects no, then simply return the error code. */
9256 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9257 && !nquery (_("Make %s pending on future shared library load? "),
9258 bptype_string (type_wanted
)))
9261 /* At this point, either the user was queried about setting
9262 a pending breakpoint and selected yes, or pending
9263 breakpoint behavior is on and thus a pending breakpoint
9264 is defaulted on behalf of the user. */
9271 if (!pending
&& canonical
.lsals
.empty ())
9274 /* Resolve all line numbers to PC's and verify that the addresses
9275 are ok for the target. */
9278 for (auto &lsal
: canonical
.lsals
)
9279 breakpoint_sals_to_pc (lsal
.sals
);
9282 /* Fast tracepoints may have additional restrictions on location. */
9283 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9285 for (const auto &lsal
: canonical
.lsals
)
9286 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9289 /* Verify that condition can be parsed, before setting any
9290 breakpoints. Allocate a separate condition expression for each
9294 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9295 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9302 const linespec_sals
&lsal
= canonical
.lsals
[0];
9304 /* Here we only parse 'arg' to separate condition
9305 from thread number, so parsing in context of first
9306 sal is OK. When setting the breakpoint we'll
9307 re-parse it in context of each sal. */
9309 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9310 &cond
, &thread
, &task
, &rest
);
9311 cond_string_copy
.reset (cond
);
9312 extra_string_copy
.reset (rest
);
9316 if (type_wanted
!= bp_dprintf
9317 && extra_string
!= NULL
&& *extra_string
!= '\0')
9318 error (_("Garbage '%s' at end of location"), extra_string
);
9320 /* Create a private copy of condition string. */
9322 cond_string_copy
.reset (xstrdup (cond_string
));
9323 /* Create a private copy of any extra string. */
9325 extra_string_copy
.reset (xstrdup (extra_string
));
9328 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9329 std::move (cond_string_copy
),
9330 std::move (extra_string_copy
),
9332 tempflag
? disp_del
: disp_donttouch
,
9333 thread
, task
, ignore_count
, ops
,
9334 from_tty
, enabled
, internal
, flags
);
9338 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9340 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9341 b
->location
= copy_event_location (location
);
9344 b
->cond_string
= NULL
;
9347 /* Create a private copy of condition string. */
9348 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9352 /* Create a private copy of any extra string. */
9353 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9354 b
->ignore_count
= ignore_count
;
9355 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9356 b
->condition_not_parsed
= 1;
9357 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9358 if ((type_wanted
!= bp_breakpoint
9359 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9360 b
->pspace
= current_program_space
;
9362 install_breakpoint (internal
, std::move (b
), 0);
9365 if (canonical
.lsals
.size () > 1)
9367 warning (_("Multiple breakpoints were set.\nUse the "
9368 "\"delete\" command to delete unwanted breakpoints."));
9369 prev_breakpoint_count
= prev_bkpt_count
;
9372 update_global_location_list (UGLL_MAY_INSERT
);
9377 /* Set a breakpoint.
9378 ARG is a string describing breakpoint address,
9379 condition, and thread.
9380 FLAG specifies if a breakpoint is hardware on,
9381 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9385 break_command_1 (const char *arg
, int flag
, int from_tty
)
9387 int tempflag
= flag
& BP_TEMPFLAG
;
9388 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9389 ? bp_hardware_breakpoint
9392 event_location_up location
= string_to_event_location (&arg
, current_language
);
9393 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
9394 (location
.get (), false /* is_tracepoint */);
9396 create_breakpoint (get_current_arch (),
9398 NULL
, 0, arg
, 1 /* parse arg */,
9399 tempflag
, type_wanted
,
9400 0 /* Ignore count */,
9401 pending_break_support
,
9409 /* Helper function for break_command_1 and disassemble_command. */
9412 resolve_sal_pc (struct symtab_and_line
*sal
)
9416 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9418 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9419 error (_("No line %d in file \"%s\"."),
9420 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9423 /* If this SAL corresponds to a breakpoint inserted using a line
9424 number, then skip the function prologue if necessary. */
9425 if (sal
->explicit_line
)
9426 skip_prologue_sal (sal
);
9429 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9431 const struct blockvector
*bv
;
9432 const struct block
*b
;
9435 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9436 SYMTAB_COMPUNIT (sal
->symtab
));
9439 sym
= block_linkage_function (b
);
9442 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9443 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9448 /* It really is worthwhile to have the section, so we'll
9449 just have to look harder. This case can be executed
9450 if we have line numbers but no functions (as can
9451 happen in assembly source). */
9453 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9454 switch_to_program_space_and_thread (sal
->pspace
);
9456 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9458 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9465 break_command (const char *arg
, int from_tty
)
9467 break_command_1 (arg
, 0, from_tty
);
9471 tbreak_command (const char *arg
, int from_tty
)
9473 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9477 hbreak_command (const char *arg
, int from_tty
)
9479 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9483 thbreak_command (const char *arg
, int from_tty
)
9485 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9489 stop_command (const char *arg
, int from_tty
)
9491 printf_filtered (_("Specify the type of breakpoint to set.\n\
9492 Usage: stop in <function | address>\n\
9493 stop at <line>\n"));
9497 stopin_command (const char *arg
, int from_tty
)
9503 else if (*arg
!= '*')
9505 const char *argptr
= arg
;
9508 /* Look for a ':'. If this is a line number specification, then
9509 say it is bad, otherwise, it should be an address or
9510 function/method name. */
9511 while (*argptr
&& !hasColon
)
9513 hasColon
= (*argptr
== ':');
9518 badInput
= (*argptr
!= ':'); /* Not a class::method */
9520 badInput
= isdigit (*arg
); /* a simple line number */
9524 printf_filtered (_("Usage: stop in <function | address>\n"));
9526 break_command_1 (arg
, 0, from_tty
);
9530 stopat_command (const char *arg
, int from_tty
)
9534 if (arg
== NULL
|| *arg
== '*') /* no line number */
9538 const char *argptr
= arg
;
9541 /* Look for a ':'. If there is a '::' then get out, otherwise
9542 it is probably a line number. */
9543 while (*argptr
&& !hasColon
)
9545 hasColon
= (*argptr
== ':');
9550 badInput
= (*argptr
== ':'); /* we have class::method */
9552 badInput
= !isdigit (*arg
); /* not a line number */
9556 printf_filtered (_("Usage: stop at LINE\n"));
9558 break_command_1 (arg
, 0, from_tty
);
9561 /* The dynamic printf command is mostly like a regular breakpoint, but
9562 with a prewired command list consisting of a single output command,
9563 built from extra arguments supplied on the dprintf command
9567 dprintf_command (const char *arg
, int from_tty
)
9569 event_location_up location
= string_to_event_location (&arg
, current_language
);
9571 /* If non-NULL, ARG should have been advanced past the location;
9572 the next character must be ','. */
9575 if (arg
[0] != ',' || arg
[1] == '\0')
9576 error (_("Format string required"));
9579 /* Skip the comma. */
9584 create_breakpoint (get_current_arch (),
9586 NULL
, 0, arg
, 1 /* parse arg */,
9588 0 /* Ignore count */,
9589 pending_break_support
,
9590 &dprintf_breakpoint_ops
,
9598 agent_printf_command (const char *arg
, int from_tty
)
9600 error (_("May only run agent-printf on the target"));
9603 /* Implement the "breakpoint_hit" breakpoint_ops method for
9604 ranged breakpoints. */
9607 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9608 const address_space
*aspace
,
9610 const struct target_waitstatus
*ws
)
9612 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9613 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9616 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9617 bl
->length
, aspace
, bp_addr
);
9620 /* Implement the "resources_needed" breakpoint_ops method for
9621 ranged breakpoints. */
9624 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9626 return target_ranged_break_num_registers ();
9629 /* Implement the "print_it" breakpoint_ops method for
9630 ranged breakpoints. */
9632 static enum print_stop_action
9633 print_it_ranged_breakpoint (bpstat bs
)
9635 struct breakpoint
*b
= bs
->breakpoint_at
;
9636 struct bp_location
*bl
= b
->loc
;
9637 struct ui_out
*uiout
= current_uiout
;
9639 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9641 /* Ranged breakpoints have only one location. */
9642 gdb_assert (bl
&& bl
->next
== NULL
);
9644 annotate_breakpoint (b
->number
);
9646 maybe_print_thread_hit_breakpoint (uiout
);
9648 if (b
->disposition
== disp_del
)
9649 uiout
->text ("Temporary ranged breakpoint ");
9651 uiout
->text ("Ranged breakpoint ");
9652 if (uiout
->is_mi_like_p ())
9654 uiout
->field_string ("reason",
9655 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9656 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9658 uiout
->field_signed ("bkptno", b
->number
);
9661 return PRINT_SRC_AND_LOC
;
9664 /* Implement the "print_one" breakpoint_ops method for
9665 ranged breakpoints. */
9668 print_one_ranged_breakpoint (struct breakpoint
*b
,
9669 struct bp_location
**last_loc
)
9671 struct bp_location
*bl
= b
->loc
;
9672 struct value_print_options opts
;
9673 struct ui_out
*uiout
= current_uiout
;
9675 /* Ranged breakpoints have only one location. */
9676 gdb_assert (bl
&& bl
->next
== NULL
);
9678 get_user_print_options (&opts
);
9680 if (opts
.addressprint
)
9681 /* We don't print the address range here, it will be printed later
9682 by print_one_detail_ranged_breakpoint. */
9683 uiout
->field_skip ("addr");
9685 print_breakpoint_location (b
, bl
);
9689 /* Implement the "print_one_detail" breakpoint_ops method for
9690 ranged breakpoints. */
9693 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9694 struct ui_out
*uiout
)
9696 CORE_ADDR address_start
, address_end
;
9697 struct bp_location
*bl
= b
->loc
;
9702 address_start
= bl
->address
;
9703 address_end
= address_start
+ bl
->length
- 1;
9705 uiout
->text ("\taddress range: ");
9706 stb
.printf ("[%s, %s]",
9707 print_core_address (bl
->gdbarch
, address_start
),
9708 print_core_address (bl
->gdbarch
, address_end
));
9709 uiout
->field_stream ("addr", stb
);
9713 /* Implement the "print_mention" breakpoint_ops method for
9714 ranged breakpoints. */
9717 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9719 struct bp_location
*bl
= b
->loc
;
9720 struct ui_out
*uiout
= current_uiout
;
9723 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9725 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9726 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9727 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9730 /* Implement the "print_recreate" breakpoint_ops method for
9731 ranged breakpoints. */
9734 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9736 fprintf_unfiltered (fp
, "break-range %s, %s",
9737 event_location_to_string (b
->location
.get ()),
9738 event_location_to_string (b
->location_range_end
.get ()));
9739 print_recreate_thread (b
, fp
);
9742 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9744 static struct breakpoint_ops ranged_breakpoint_ops
;
9746 /* Find the address where the end of the breakpoint range should be
9747 placed, given the SAL of the end of the range. This is so that if
9748 the user provides a line number, the end of the range is set to the
9749 last instruction of the given line. */
9752 find_breakpoint_range_end (struct symtab_and_line sal
)
9756 /* If the user provided a PC value, use it. Otherwise,
9757 find the address of the end of the given location. */
9758 if (sal
.explicit_pc
)
9765 ret
= find_line_pc_range (sal
, &start
, &end
);
9767 error (_("Could not find location of the end of the range."));
9769 /* find_line_pc_range returns the start of the next line. */
9776 /* Implement the "break-range" CLI command. */
9779 break_range_command (const char *arg
, int from_tty
)
9781 const char *arg_start
;
9782 struct linespec_result canonical_start
, canonical_end
;
9783 int bp_count
, can_use_bp
, length
;
9785 struct breakpoint
*b
;
9787 /* We don't support software ranged breakpoints. */
9788 if (target_ranged_break_num_registers () < 0)
9789 error (_("This target does not support hardware ranged breakpoints."));
9791 bp_count
= hw_breakpoint_used_count ();
9792 bp_count
+= target_ranged_break_num_registers ();
9793 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9796 error (_("Hardware breakpoints used exceeds limit."));
9798 arg
= skip_spaces (arg
);
9799 if (arg
== NULL
|| arg
[0] == '\0')
9800 error(_("No address range specified."));
9803 event_location_up start_location
= string_to_event_location (&arg
,
9805 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9808 error (_("Too few arguments."));
9809 else if (canonical_start
.lsals
.empty ())
9810 error (_("Could not find location of the beginning of the range."));
9812 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9814 if (canonical_start
.lsals
.size () > 1
9815 || lsal_start
.sals
.size () != 1)
9816 error (_("Cannot create a ranged breakpoint with multiple locations."));
9818 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9819 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9821 arg
++; /* Skip the comma. */
9822 arg
= skip_spaces (arg
);
9824 /* Parse the end location. */
9828 /* We call decode_line_full directly here instead of using
9829 parse_breakpoint_sals because we need to specify the start location's
9830 symtab and line as the default symtab and line for the end of the
9831 range. This makes it possible to have ranges like "foo.c:27, +14",
9832 where +14 means 14 lines from the start location. */
9833 event_location_up end_location
= string_to_event_location (&arg
,
9835 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9836 sal_start
.symtab
, sal_start
.line
,
9837 &canonical_end
, NULL
, NULL
);
9839 if (canonical_end
.lsals
.empty ())
9840 error (_("Could not find location of the end of the range."));
9842 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9843 if (canonical_end
.lsals
.size () > 1
9844 || lsal_end
.sals
.size () != 1)
9845 error (_("Cannot create a ranged breakpoint with multiple locations."));
9847 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9849 end
= find_breakpoint_range_end (sal_end
);
9850 if (sal_start
.pc
> end
)
9851 error (_("Invalid address range, end precedes start."));
9853 length
= end
- sal_start
.pc
+ 1;
9855 /* Length overflowed. */
9856 error (_("Address range too large."));
9857 else if (length
== 1)
9859 /* This range is simple enough to be handled by
9860 the `hbreak' command. */
9861 hbreak_command (&addr_string_start
[0], 1);
9866 /* Now set up the breakpoint. */
9867 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9868 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9869 set_breakpoint_count (breakpoint_count
+ 1);
9870 b
->number
= breakpoint_count
;
9871 b
->disposition
= disp_donttouch
;
9872 b
->location
= std::move (start_location
);
9873 b
->location_range_end
= std::move (end_location
);
9874 b
->loc
->length
= length
;
9877 gdb::observers::breakpoint_created
.notify (b
);
9878 update_global_location_list (UGLL_MAY_INSERT
);
9881 /* Return non-zero if EXP is verified as constant. Returned zero
9882 means EXP is variable. Also the constant detection may fail for
9883 some constant expressions and in such case still falsely return
9887 watchpoint_exp_is_const (const struct expression
*exp
)
9895 /* We are only interested in the descriptor of each element. */
9896 operator_length (exp
, i
, &oplenp
, &argsp
);
9899 switch (exp
->elts
[i
].opcode
)
9909 case BINOP_LOGICAL_AND
:
9910 case BINOP_LOGICAL_OR
:
9911 case BINOP_BITWISE_AND
:
9912 case BINOP_BITWISE_IOR
:
9913 case BINOP_BITWISE_XOR
:
9915 case BINOP_NOTEQUAL
:
9941 case OP_OBJC_NSSTRING
:
9944 case UNOP_LOGICAL_NOT
:
9945 case UNOP_COMPLEMENT
:
9950 case UNOP_CAST_TYPE
:
9951 case UNOP_REINTERPRET_CAST
:
9952 case UNOP_DYNAMIC_CAST
:
9953 /* Unary, binary and ternary operators: We have to check
9954 their operands. If they are constant, then so is the
9955 result of that operation. For instance, if A and B are
9956 determined to be constants, then so is "A + B".
9958 UNOP_IND is one exception to the rule above, because the
9959 value of *ADDR is not necessarily a constant, even when
9964 /* Check whether the associated symbol is a constant.
9966 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9967 possible that a buggy compiler could mark a variable as
9968 constant even when it is not, and TYPE_CONST would return
9969 true in this case, while SYMBOL_CLASS wouldn't.
9971 We also have to check for function symbols because they
9972 are always constant. */
9974 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
9976 if (SYMBOL_CLASS (s
) != LOC_BLOCK
9977 && SYMBOL_CLASS (s
) != LOC_CONST
9978 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
9983 /* The default action is to return 0 because we are using
9984 the optimistic approach here: If we don't know something,
9985 then it is not a constant. */
9994 /* Watchpoint destructor. */
9996 watchpoint::~watchpoint ()
9998 xfree (this->exp_string
);
9999 xfree (this->exp_string_reparse
);
10002 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10005 re_set_watchpoint (struct breakpoint
*b
)
10007 struct watchpoint
*w
= (struct watchpoint
*) b
;
10009 /* Watchpoint can be either on expression using entirely global
10010 variables, or it can be on local variables.
10012 Watchpoints of the first kind are never auto-deleted, and even
10013 persist across program restarts. Since they can use variables
10014 from shared libraries, we need to reparse expression as libraries
10015 are loaded and unloaded.
10017 Watchpoints on local variables can also change meaning as result
10018 of solib event. For example, if a watchpoint uses both a local
10019 and a global variables in expression, it's a local watchpoint,
10020 but unloading of a shared library will make the expression
10021 invalid. This is not a very common use case, but we still
10022 re-evaluate expression, to avoid surprises to the user.
10024 Note that for local watchpoints, we re-evaluate it only if
10025 watchpoints frame id is still valid. If it's not, it means the
10026 watchpoint is out of scope and will be deleted soon. In fact,
10027 I'm not sure we'll ever be called in this case.
10029 If a local watchpoint's frame id is still valid, then
10030 w->exp_valid_block is likewise valid, and we can safely use it.
10032 Don't do anything about disabled watchpoints, since they will be
10033 reevaluated again when enabled. */
10034 update_watchpoint (w
, 1 /* reparse */);
10037 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10040 insert_watchpoint (struct bp_location
*bl
)
10042 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10043 int length
= w
->exact
? 1 : bl
->length
;
10045 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10046 w
->cond_exp
.get ());
10049 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10052 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10054 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10055 int length
= w
->exact
? 1 : bl
->length
;
10057 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10058 w
->cond_exp
.get ());
10062 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10063 const address_space
*aspace
, CORE_ADDR bp_addr
,
10064 const struct target_waitstatus
*ws
)
10066 struct breakpoint
*b
= bl
->owner
;
10067 struct watchpoint
*w
= (struct watchpoint
*) b
;
10069 /* Continuable hardware watchpoints are treated as non-existent if the
10070 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10071 some data address). Otherwise gdb won't stop on a break instruction
10072 in the code (not from a breakpoint) when a hardware watchpoint has
10073 been defined. Also skip watchpoints which we know did not trigger
10074 (did not match the data address). */
10075 if (is_hardware_watchpoint (b
)
10076 && w
->watchpoint_triggered
== watch_triggered_no
)
10083 check_status_watchpoint (bpstat bs
)
10085 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10087 bpstat_check_watchpoint (bs
);
10090 /* Implement the "resources_needed" breakpoint_ops method for
10091 hardware watchpoints. */
10094 resources_needed_watchpoint (const struct bp_location
*bl
)
10096 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10097 int length
= w
->exact
? 1 : bl
->length
;
10099 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10102 /* Implement the "works_in_software_mode" breakpoint_ops method for
10103 hardware watchpoints. */
10106 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10108 /* Read and access watchpoints only work with hardware support. */
10109 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10112 static enum print_stop_action
10113 print_it_watchpoint (bpstat bs
)
10115 struct breakpoint
*b
;
10116 enum print_stop_action result
;
10117 struct watchpoint
*w
;
10118 struct ui_out
*uiout
= current_uiout
;
10120 gdb_assert (bs
->bp_location_at
!= NULL
);
10122 b
= bs
->breakpoint_at
;
10123 w
= (struct watchpoint
*) b
;
10125 annotate_watchpoint (b
->number
);
10126 maybe_print_thread_hit_breakpoint (uiout
);
10130 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10133 case bp_watchpoint
:
10134 case bp_hardware_watchpoint
:
10135 if (uiout
->is_mi_like_p ())
10136 uiout
->field_string
10137 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10139 tuple_emitter
.emplace (uiout
, "value");
10140 uiout
->text ("\nOld value = ");
10141 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10142 uiout
->field_stream ("old", stb
);
10143 uiout
->text ("\nNew value = ");
10144 watchpoint_value_print (w
->val
.get (), &stb
);
10145 uiout
->field_stream ("new", stb
);
10146 uiout
->text ("\n");
10147 /* More than one watchpoint may have been triggered. */
10148 result
= PRINT_UNKNOWN
;
10151 case bp_read_watchpoint
:
10152 if (uiout
->is_mi_like_p ())
10153 uiout
->field_string
10154 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10156 tuple_emitter
.emplace (uiout
, "value");
10157 uiout
->text ("\nValue = ");
10158 watchpoint_value_print (w
->val
.get (), &stb
);
10159 uiout
->field_stream ("value", stb
);
10160 uiout
->text ("\n");
10161 result
= PRINT_UNKNOWN
;
10164 case bp_access_watchpoint
:
10165 if (bs
->old_val
!= NULL
)
10167 if (uiout
->is_mi_like_p ())
10168 uiout
->field_string
10170 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10172 tuple_emitter
.emplace (uiout
, "value");
10173 uiout
->text ("\nOld value = ");
10174 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10175 uiout
->field_stream ("old", stb
);
10176 uiout
->text ("\nNew value = ");
10181 if (uiout
->is_mi_like_p ())
10182 uiout
->field_string
10184 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10185 tuple_emitter
.emplace (uiout
, "value");
10186 uiout
->text ("\nValue = ");
10188 watchpoint_value_print (w
->val
.get (), &stb
);
10189 uiout
->field_stream ("new", stb
);
10190 uiout
->text ("\n");
10191 result
= PRINT_UNKNOWN
;
10194 result
= PRINT_UNKNOWN
;
10200 /* Implement the "print_mention" breakpoint_ops method for hardware
10204 print_mention_watchpoint (struct breakpoint
*b
)
10206 struct watchpoint
*w
= (struct watchpoint
*) b
;
10207 struct ui_out
*uiout
= current_uiout
;
10208 const char *tuple_name
;
10212 case bp_watchpoint
:
10213 uiout
->text ("Watchpoint ");
10214 tuple_name
= "wpt";
10216 case bp_hardware_watchpoint
:
10217 uiout
->text ("Hardware watchpoint ");
10218 tuple_name
= "wpt";
10220 case bp_read_watchpoint
:
10221 uiout
->text ("Hardware read watchpoint ");
10222 tuple_name
= "hw-rwpt";
10224 case bp_access_watchpoint
:
10225 uiout
->text ("Hardware access (read/write) watchpoint ");
10226 tuple_name
= "hw-awpt";
10229 internal_error (__FILE__
, __LINE__
,
10230 _("Invalid hardware watchpoint type."));
10233 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10234 uiout
->field_signed ("number", b
->number
);
10235 uiout
->text (": ");
10236 uiout
->field_string ("exp", w
->exp_string
);
10239 /* Implement the "print_recreate" breakpoint_ops method for
10243 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10245 struct watchpoint
*w
= (struct watchpoint
*) b
;
10249 case bp_watchpoint
:
10250 case bp_hardware_watchpoint
:
10251 fprintf_unfiltered (fp
, "watch");
10253 case bp_read_watchpoint
:
10254 fprintf_unfiltered (fp
, "rwatch");
10256 case bp_access_watchpoint
:
10257 fprintf_unfiltered (fp
, "awatch");
10260 internal_error (__FILE__
, __LINE__
,
10261 _("Invalid watchpoint type."));
10264 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10265 print_recreate_thread (b
, fp
);
10268 /* Implement the "explains_signal" breakpoint_ops method for
10272 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10274 /* A software watchpoint cannot cause a signal other than
10275 GDB_SIGNAL_TRAP. */
10276 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10282 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10284 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10286 /* Implement the "insert" breakpoint_ops method for
10287 masked hardware watchpoints. */
10290 insert_masked_watchpoint (struct bp_location
*bl
)
10292 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10294 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10295 bl
->watchpoint_type
);
10298 /* Implement the "remove" breakpoint_ops method for
10299 masked hardware watchpoints. */
10302 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10304 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10306 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10307 bl
->watchpoint_type
);
10310 /* Implement the "resources_needed" breakpoint_ops method for
10311 masked hardware watchpoints. */
10314 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10316 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10318 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10321 /* Implement the "works_in_software_mode" breakpoint_ops method for
10322 masked hardware watchpoints. */
10325 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10330 /* Implement the "print_it" breakpoint_ops method for
10331 masked hardware watchpoints. */
10333 static enum print_stop_action
10334 print_it_masked_watchpoint (bpstat bs
)
10336 struct breakpoint
*b
= bs
->breakpoint_at
;
10337 struct ui_out
*uiout
= current_uiout
;
10339 /* Masked watchpoints have only one location. */
10340 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10342 annotate_watchpoint (b
->number
);
10343 maybe_print_thread_hit_breakpoint (uiout
);
10347 case bp_hardware_watchpoint
:
10348 if (uiout
->is_mi_like_p ())
10349 uiout
->field_string
10350 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10353 case bp_read_watchpoint
:
10354 if (uiout
->is_mi_like_p ())
10355 uiout
->field_string
10356 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10359 case bp_access_watchpoint
:
10360 if (uiout
->is_mi_like_p ())
10361 uiout
->field_string
10363 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10366 internal_error (__FILE__
, __LINE__
,
10367 _("Invalid hardware watchpoint type."));
10371 uiout
->text (_("\n\
10372 Check the underlying instruction at PC for the memory\n\
10373 address and value which triggered this watchpoint.\n"));
10374 uiout
->text ("\n");
10376 /* More than one watchpoint may have been triggered. */
10377 return PRINT_UNKNOWN
;
10380 /* Implement the "print_one_detail" breakpoint_ops method for
10381 masked hardware watchpoints. */
10384 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10385 struct ui_out
*uiout
)
10387 struct watchpoint
*w
= (struct watchpoint
*) b
;
10389 /* Masked watchpoints have only one location. */
10390 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10392 uiout
->text ("\tmask ");
10393 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10394 uiout
->text ("\n");
10397 /* Implement the "print_mention" breakpoint_ops method for
10398 masked hardware watchpoints. */
10401 print_mention_masked_watchpoint (struct breakpoint
*b
)
10403 struct watchpoint
*w
= (struct watchpoint
*) b
;
10404 struct ui_out
*uiout
= current_uiout
;
10405 const char *tuple_name
;
10409 case bp_hardware_watchpoint
:
10410 uiout
->text ("Masked hardware watchpoint ");
10411 tuple_name
= "wpt";
10413 case bp_read_watchpoint
:
10414 uiout
->text ("Masked hardware read watchpoint ");
10415 tuple_name
= "hw-rwpt";
10417 case bp_access_watchpoint
:
10418 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10419 tuple_name
= "hw-awpt";
10422 internal_error (__FILE__
, __LINE__
,
10423 _("Invalid hardware watchpoint type."));
10426 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10427 uiout
->field_signed ("number", b
->number
);
10428 uiout
->text (": ");
10429 uiout
->field_string ("exp", w
->exp_string
);
10432 /* Implement the "print_recreate" breakpoint_ops method for
10433 masked hardware watchpoints. */
10436 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10438 struct watchpoint
*w
= (struct watchpoint
*) b
;
10443 case bp_hardware_watchpoint
:
10444 fprintf_unfiltered (fp
, "watch");
10446 case bp_read_watchpoint
:
10447 fprintf_unfiltered (fp
, "rwatch");
10449 case bp_access_watchpoint
:
10450 fprintf_unfiltered (fp
, "awatch");
10453 internal_error (__FILE__
, __LINE__
,
10454 _("Invalid hardware watchpoint type."));
10457 sprintf_vma (tmp
, w
->hw_wp_mask
);
10458 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10459 print_recreate_thread (b
, fp
);
10462 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10464 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10466 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10469 is_masked_watchpoint (const struct breakpoint
*b
)
10471 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10474 /* accessflag: hw_write: watch write,
10475 hw_read: watch read,
10476 hw_access: watch access (read or write) */
10478 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10479 int just_location
, int internal
)
10481 struct breakpoint
*scope_breakpoint
= NULL
;
10482 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10483 struct value
*result
;
10484 int saved_bitpos
= 0, saved_bitsize
= 0;
10485 const char *exp_start
= NULL
;
10486 const char *exp_end
= NULL
;
10487 const char *tok
, *end_tok
;
10489 const char *cond_start
= NULL
;
10490 const char *cond_end
= NULL
;
10491 enum bptype bp_type
;
10494 /* Flag to indicate whether we are going to use masks for
10495 the hardware watchpoint. */
10497 CORE_ADDR mask
= 0;
10499 /* Make sure that we actually have parameters to parse. */
10500 if (arg
!= NULL
&& arg
[0] != '\0')
10502 const char *value_start
;
10504 exp_end
= arg
+ strlen (arg
);
10506 /* Look for "parameter value" pairs at the end
10507 of the arguments string. */
10508 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10510 /* Skip whitespace at the end of the argument list. */
10511 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10514 /* Find the beginning of the last token.
10515 This is the value of the parameter. */
10516 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10518 value_start
= tok
+ 1;
10520 /* Skip whitespace. */
10521 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10526 /* Find the beginning of the second to last token.
10527 This is the parameter itself. */
10528 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10531 toklen
= end_tok
- tok
+ 1;
10533 if (toklen
== 6 && startswith (tok
, "thread"))
10535 struct thread_info
*thr
;
10536 /* At this point we've found a "thread" token, which means
10537 the user is trying to set a watchpoint that triggers
10538 only in a specific thread. */
10542 error(_("You can specify only one thread."));
10544 /* Extract the thread ID from the next token. */
10545 thr
= parse_thread_id (value_start
, &endp
);
10547 /* Check if the user provided a valid thread ID. */
10548 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10549 invalid_thread_id_error (value_start
);
10551 thread
= thr
->global_num
;
10553 else if (toklen
== 4 && startswith (tok
, "mask"))
10555 /* We've found a "mask" token, which means the user wants to
10556 create a hardware watchpoint that is going to have the mask
10558 struct value
*mask_value
, *mark
;
10561 error(_("You can specify only one mask."));
10563 use_mask
= just_location
= 1;
10565 mark
= value_mark ();
10566 mask_value
= parse_to_comma_and_eval (&value_start
);
10567 mask
= value_as_address (mask_value
);
10568 value_free_to_mark (mark
);
10571 /* We didn't recognize what we found. We should stop here. */
10574 /* Truncate the string and get rid of the "parameter value" pair before
10575 the arguments string is parsed by the parse_exp_1 function. */
10582 /* Parse the rest of the arguments. From here on out, everything
10583 is in terms of a newly allocated string instead of the original
10585 std::string
expression (arg
, exp_end
- arg
);
10586 exp_start
= arg
= expression
.c_str ();
10587 innermost_block_tracker tracker
;
10588 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10590 /* Remove trailing whitespace from the expression before saving it.
10591 This makes the eventual display of the expression string a bit
10593 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10596 /* Checking if the expression is not constant. */
10597 if (watchpoint_exp_is_const (exp
.get ()))
10601 len
= exp_end
- exp_start
;
10602 while (len
> 0 && isspace (exp_start
[len
- 1]))
10604 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10607 exp_valid_block
= tracker
.block ();
10608 struct value
*mark
= value_mark ();
10609 struct value
*val_as_value
= nullptr;
10610 fetch_subexp_value (exp
.get (), &pc
, &val_as_value
, &result
, NULL
,
10613 if (val_as_value
!= NULL
&& just_location
)
10615 saved_bitpos
= value_bitpos (val_as_value
);
10616 saved_bitsize
= value_bitsize (val_as_value
);
10624 exp_valid_block
= NULL
;
10625 val
= release_value (value_addr (result
));
10626 value_free_to_mark (mark
);
10630 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10633 error (_("This target does not support masked watchpoints."));
10634 else if (ret
== -2)
10635 error (_("Invalid mask or memory region."));
10638 else if (val_as_value
!= NULL
)
10639 val
= release_value (val_as_value
);
10641 tok
= skip_spaces (arg
);
10642 end_tok
= skip_to_space (tok
);
10644 toklen
= end_tok
- tok
;
10645 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10647 tok
= cond_start
= end_tok
+ 1;
10648 innermost_block_tracker if_tracker
;
10649 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10651 /* The watchpoint expression may not be local, but the condition
10652 may still be. E.g.: `watch global if local > 0'. */
10653 cond_exp_valid_block
= if_tracker
.block ();
10658 error (_("Junk at end of command."));
10660 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10662 /* Save this because create_internal_breakpoint below invalidates
10664 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10666 /* If the expression is "local", then set up a "watchpoint scope"
10667 breakpoint at the point where we've left the scope of the watchpoint
10668 expression. Create the scope breakpoint before the watchpoint, so
10669 that we will encounter it first in bpstat_stop_status. */
10670 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10672 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10674 if (frame_id_p (caller_frame_id
))
10676 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10677 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10680 = create_internal_breakpoint (caller_arch
, caller_pc
,
10681 bp_watchpoint_scope
,
10682 &momentary_breakpoint_ops
);
10684 /* create_internal_breakpoint could invalidate WP_FRAME. */
10687 scope_breakpoint
->enable_state
= bp_enabled
;
10689 /* Automatically delete the breakpoint when it hits. */
10690 scope_breakpoint
->disposition
= disp_del
;
10692 /* Only break in the proper frame (help with recursion). */
10693 scope_breakpoint
->frame_id
= caller_frame_id
;
10695 /* Set the address at which we will stop. */
10696 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10697 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10698 scope_breakpoint
->loc
->address
10699 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10700 scope_breakpoint
->loc
->requested_address
,
10701 scope_breakpoint
->type
);
10705 /* Now set up the breakpoint. We create all watchpoints as hardware
10706 watchpoints here even if hardware watchpoints are turned off, a call
10707 to update_watchpoint later in this function will cause the type to
10708 drop back to bp_watchpoint (software watchpoint) if required. */
10710 if (accessflag
== hw_read
)
10711 bp_type
= bp_read_watchpoint
;
10712 else if (accessflag
== hw_access
)
10713 bp_type
= bp_access_watchpoint
;
10715 bp_type
= bp_hardware_watchpoint
;
10717 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10720 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10721 &masked_watchpoint_breakpoint_ops
);
10723 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10724 &watchpoint_breakpoint_ops
);
10725 w
->thread
= thread
;
10726 w
->disposition
= disp_donttouch
;
10727 w
->pspace
= current_program_space
;
10728 w
->exp
= std::move (exp
);
10729 w
->exp_valid_block
= exp_valid_block
;
10730 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10733 struct type
*t
= value_type (val
.get ());
10734 CORE_ADDR addr
= value_as_address (val
.get ());
10736 w
->exp_string_reparse
10737 = current_language
->la_watch_location_expression (t
, addr
).release ();
10739 w
->exp_string
= xstrprintf ("-location %.*s",
10740 (int) (exp_end
- exp_start
), exp_start
);
10743 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10747 w
->hw_wp_mask
= mask
;
10752 w
->val_bitpos
= saved_bitpos
;
10753 w
->val_bitsize
= saved_bitsize
;
10754 w
->val_valid
= true;
10758 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10760 w
->cond_string
= 0;
10762 if (frame_id_p (watchpoint_frame
))
10764 w
->watchpoint_frame
= watchpoint_frame
;
10765 w
->watchpoint_thread
= inferior_ptid
;
10769 w
->watchpoint_frame
= null_frame_id
;
10770 w
->watchpoint_thread
= null_ptid
;
10773 if (scope_breakpoint
!= NULL
)
10775 /* The scope breakpoint is related to the watchpoint. We will
10776 need to act on them together. */
10777 w
->related_breakpoint
= scope_breakpoint
;
10778 scope_breakpoint
->related_breakpoint
= w
.get ();
10781 if (!just_location
)
10782 value_free_to_mark (mark
);
10784 /* Finally update the new watchpoint. This creates the locations
10785 that should be inserted. */
10786 update_watchpoint (w
.get (), 1);
10788 install_breakpoint (internal
, std::move (w
), 1);
10791 /* Return count of debug registers needed to watch the given expression.
10792 If the watchpoint cannot be handled in hardware return zero. */
10795 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10797 int found_memory_cnt
= 0;
10799 /* Did the user specifically forbid us to use hardware watchpoints? */
10800 if (!can_use_hw_watchpoints
)
10803 gdb_assert (!vals
.empty ());
10804 struct value
*head
= vals
[0].get ();
10806 /* Make sure that the value of the expression depends only upon
10807 memory contents, and values computed from them within GDB. If we
10808 find any register references or function calls, we can't use a
10809 hardware watchpoint.
10811 The idea here is that evaluating an expression generates a series
10812 of values, one holding the value of every subexpression. (The
10813 expression a*b+c has five subexpressions: a, b, a*b, c, and
10814 a*b+c.) GDB's values hold almost enough information to establish
10815 the criteria given above --- they identify memory lvalues,
10816 register lvalues, computed values, etcetera. So we can evaluate
10817 the expression, and then scan the chain of values that leaves
10818 behind to decide whether we can detect any possible change to the
10819 expression's final value using only hardware watchpoints.
10821 However, I don't think that the values returned by inferior
10822 function calls are special in any way. So this function may not
10823 notice that an expression involving an inferior function call
10824 can't be watched with hardware watchpoints. FIXME. */
10825 for (const value_ref_ptr
&iter
: vals
)
10827 struct value
*v
= iter
.get ();
10829 if (VALUE_LVAL (v
) == lval_memory
)
10831 if (v
!= head
&& value_lazy (v
))
10832 /* A lazy memory lvalue in the chain is one that GDB never
10833 needed to fetch; we either just used its address (e.g.,
10834 `a' in `a.b') or we never needed it at all (e.g., `a'
10835 in `a,b'). This doesn't apply to HEAD; if that is
10836 lazy then it was not readable, but watch it anyway. */
10840 /* Ahh, memory we actually used! Check if we can cover
10841 it with hardware watchpoints. */
10842 struct type
*vtype
= check_typedef (value_type (v
));
10844 /* We only watch structs and arrays if user asked for it
10845 explicitly, never if they just happen to appear in a
10846 middle of some value chain. */
10848 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
10849 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
10851 CORE_ADDR vaddr
= value_address (v
);
10855 len
= (target_exact_watchpoints
10856 && is_scalar_type_recursive (vtype
))?
10857 1 : TYPE_LENGTH (value_type (v
));
10859 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10863 found_memory_cnt
+= num_regs
;
10867 else if (VALUE_LVAL (v
) != not_lval
10868 && deprecated_value_modifiable (v
) == 0)
10869 return 0; /* These are values from the history (e.g., $1). */
10870 else if (VALUE_LVAL (v
) == lval_register
)
10871 return 0; /* Cannot watch a register with a HW watchpoint. */
10874 /* The expression itself looks suitable for using a hardware
10875 watchpoint, but give the target machine a chance to reject it. */
10876 return found_memory_cnt
;
10880 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10882 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10885 /* A helper function that looks for the "-location" argument and then
10886 calls watch_command_1. */
10889 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10891 int just_location
= 0;
10894 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
10895 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
10898 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
10902 watch_command (const char *arg
, int from_tty
)
10904 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10908 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10910 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10914 rwatch_command (const char *arg
, int from_tty
)
10916 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10920 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10922 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10926 awatch_command (const char *arg
, int from_tty
)
10928 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10932 /* Data for the FSM that manages the until(location)/advance commands
10933 in infcmd.c. Here because it uses the mechanisms of
10936 struct until_break_fsm
: public thread_fsm
10938 /* The thread that was current when the command was executed. */
10941 /* The breakpoint set at the destination location. */
10942 breakpoint_up location_breakpoint
;
10944 /* Breakpoint set at the return address in the caller frame. May be
10946 breakpoint_up caller_breakpoint
;
10948 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10949 breakpoint_up
&&location_breakpoint
,
10950 breakpoint_up
&&caller_breakpoint
)
10951 : thread_fsm (cmd_interp
),
10953 location_breakpoint (std::move (location_breakpoint
)),
10954 caller_breakpoint (std::move (caller_breakpoint
))
10958 void clean_up (struct thread_info
*thread
) override
;
10959 bool should_stop (struct thread_info
*thread
) override
;
10960 enum async_reply_reason
do_async_reply_reason () override
;
10963 /* Implementation of the 'should_stop' FSM method for the
10964 until(location)/advance commands. */
10967 until_break_fsm::should_stop (struct thread_info
*tp
)
10969 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10970 location_breakpoint
.get ()) != NULL
10971 || (caller_breakpoint
!= NULL
10972 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10973 caller_breakpoint
.get ()) != NULL
))
10979 /* Implementation of the 'clean_up' FSM method for the
10980 until(location)/advance commands. */
10983 until_break_fsm::clean_up (struct thread_info
*)
10985 /* Clean up our temporary breakpoints. */
10986 location_breakpoint
.reset ();
10987 caller_breakpoint
.reset ();
10988 delete_longjmp_breakpoint (thread
);
10991 /* Implementation of the 'async_reply_reason' FSM method for the
10992 until(location)/advance commands. */
10994 enum async_reply_reason
10995 until_break_fsm::do_async_reply_reason ()
10997 return EXEC_ASYNC_LOCATION_REACHED
;
11001 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11003 struct frame_info
*frame
;
11004 struct gdbarch
*frame_gdbarch
;
11005 struct frame_id stack_frame_id
;
11006 struct frame_id caller_frame_id
;
11008 struct thread_info
*tp
;
11010 clear_proceed_status (0);
11012 /* Set a breakpoint where the user wants it and at return from
11015 event_location_up location
= string_to_event_location (&arg
, current_language
);
11017 std::vector
<symtab_and_line
> sals
11018 = (last_displayed_sal_is_valid ()
11019 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11020 get_last_displayed_symtab (),
11021 get_last_displayed_line ())
11022 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11025 if (sals
.size () != 1)
11026 error (_("Couldn't get information on specified line."));
11028 symtab_and_line
&sal
= sals
[0];
11031 error (_("Junk at end of arguments."));
11033 resolve_sal_pc (&sal
);
11035 tp
= inferior_thread ();
11036 thread
= tp
->global_num
;
11038 /* Note linespec handling above invalidates the frame chain.
11039 Installing a breakpoint also invalidates the frame chain (as it
11040 may need to switch threads), so do any frame handling before
11043 frame
= get_selected_frame (NULL
);
11044 frame_gdbarch
= get_frame_arch (frame
);
11045 stack_frame_id
= get_stack_frame_id (frame
);
11046 caller_frame_id
= frame_unwind_caller_id (frame
);
11048 /* Keep within the current frame, or in frames called by the current
11051 breakpoint_up caller_breakpoint
;
11053 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11055 if (frame_id_p (caller_frame_id
))
11057 struct symtab_and_line sal2
;
11058 struct gdbarch
*caller_gdbarch
;
11060 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11061 sal2
.pc
= frame_unwind_caller_pc (frame
);
11062 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11063 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11068 set_longjmp_breakpoint (tp
, caller_frame_id
);
11069 lj_deleter
.emplace (thread
);
11072 /* set_momentary_breakpoint could invalidate FRAME. */
11075 breakpoint_up location_breakpoint
;
11077 /* If the user told us to continue until a specified location,
11078 we don't specify a frame at which we need to stop. */
11079 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11080 null_frame_id
, bp_until
);
11082 /* Otherwise, specify the selected frame, because we want to stop
11083 only at the very same frame. */
11084 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11085 stack_frame_id
, bp_until
);
11087 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11088 std::move (location_breakpoint
),
11089 std::move (caller_breakpoint
));
11092 lj_deleter
->release ();
11094 proceed (-1, GDB_SIGNAL_DEFAULT
);
11097 /* This function attempts to parse an optional "if <cond>" clause
11098 from the arg string. If one is not found, it returns NULL.
11100 Else, it returns a pointer to the condition string. (It does not
11101 attempt to evaluate the string against a particular block.) And,
11102 it updates arg to point to the first character following the parsed
11103 if clause in the arg string. */
11106 ep_parse_optional_if_clause (const char **arg
)
11108 const char *cond_string
;
11110 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11113 /* Skip the "if" keyword. */
11116 /* Skip any extra leading whitespace, and record the start of the
11117 condition string. */
11118 *arg
= skip_spaces (*arg
);
11119 cond_string
= *arg
;
11121 /* Assume that the condition occupies the remainder of the arg
11123 (*arg
) += strlen (cond_string
);
11125 return cond_string
;
11128 /* Commands to deal with catching events, such as signals, exceptions,
11129 process start/exit, etc. */
11133 catch_fork_temporary
, catch_vfork_temporary
,
11134 catch_fork_permanent
, catch_vfork_permanent
11139 catch_fork_command_1 (const char *arg
, int from_tty
,
11140 struct cmd_list_element
*command
)
11142 struct gdbarch
*gdbarch
= get_current_arch ();
11143 const char *cond_string
= NULL
;
11144 catch_fork_kind fork_kind
;
11147 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11148 tempflag
= (fork_kind
== catch_fork_temporary
11149 || fork_kind
== catch_vfork_temporary
);
11153 arg
= skip_spaces (arg
);
11155 /* The allowed syntax is:
11157 catch [v]fork if <cond>
11159 First, check if there's an if clause. */
11160 cond_string
= ep_parse_optional_if_clause (&arg
);
11162 if ((*arg
!= '\0') && !isspace (*arg
))
11163 error (_("Junk at end of arguments."));
11165 /* If this target supports it, create a fork or vfork catchpoint
11166 and enable reporting of such events. */
11169 case catch_fork_temporary
:
11170 case catch_fork_permanent
:
11171 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11172 &catch_fork_breakpoint_ops
);
11174 case catch_vfork_temporary
:
11175 case catch_vfork_permanent
:
11176 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11177 &catch_vfork_breakpoint_ops
);
11180 error (_("unsupported or unknown fork kind; cannot catch it"));
11186 catch_exec_command_1 (const char *arg
, int from_tty
,
11187 struct cmd_list_element
*command
)
11189 struct gdbarch
*gdbarch
= get_current_arch ();
11191 const char *cond_string
= NULL
;
11193 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11197 arg
= skip_spaces (arg
);
11199 /* The allowed syntax is:
11201 catch exec if <cond>
11203 First, check if there's an if clause. */
11204 cond_string
= ep_parse_optional_if_clause (&arg
);
11206 if ((*arg
!= '\0') && !isspace (*arg
))
11207 error (_("Junk at end of arguments."));
11209 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11210 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11211 &catch_exec_breakpoint_ops
);
11212 c
->exec_pathname
= NULL
;
11214 install_breakpoint (0, std::move (c
), 1);
11218 init_ada_exception_breakpoint (struct breakpoint
*b
,
11219 struct gdbarch
*gdbarch
,
11220 struct symtab_and_line sal
,
11221 const char *addr_string
,
11222 const struct breakpoint_ops
*ops
,
11229 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11231 loc_gdbarch
= gdbarch
;
11233 describe_other_breakpoints (loc_gdbarch
,
11234 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11235 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11236 version for exception catchpoints, because two catchpoints
11237 used for different exception names will use the same address.
11238 In this case, a "breakpoint ... also set at..." warning is
11239 unproductive. Besides, the warning phrasing is also a bit
11240 inappropriate, we should use the word catchpoint, and tell
11241 the user what type of catchpoint it is. The above is good
11242 enough for now, though. */
11245 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11247 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11248 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11249 b
->location
= string_to_event_location (&addr_string
,
11250 language_def (language_ada
));
11251 b
->language
= language_ada
;
11255 catch_command (const char *arg
, int from_tty
)
11257 error (_("Catch requires an event name."));
11262 tcatch_command (const char *arg
, int from_tty
)
11264 error (_("Catch requires an event name."));
11267 /* Compare two breakpoints and return a strcmp-like result. */
11270 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11272 uintptr_t ua
= (uintptr_t) a
;
11273 uintptr_t ub
= (uintptr_t) b
;
11275 if (a
->number
< b
->number
)
11277 else if (a
->number
> b
->number
)
11280 /* Now sort by address, in case we see, e..g, two breakpoints with
11284 return ua
> ub
? 1 : 0;
11287 /* Delete breakpoints by address or line. */
11290 clear_command (const char *arg
, int from_tty
)
11292 struct breakpoint
*b
;
11295 std::vector
<symtab_and_line
> decoded_sals
;
11296 symtab_and_line last_sal
;
11297 gdb::array_view
<symtab_and_line
> sals
;
11301 = decode_line_with_current_source (arg
,
11302 (DECODE_LINE_FUNFIRSTLINE
11303 | DECODE_LINE_LIST_MODE
));
11305 sals
= decoded_sals
;
11309 /* Set sal's line, symtab, pc, and pspace to the values
11310 corresponding to the last call to print_frame_info. If the
11311 codepoint is not valid, this will set all the fields to 0. */
11312 last_sal
= get_last_displayed_sal ();
11313 if (last_sal
.symtab
== 0)
11314 error (_("No source file specified."));
11320 /* We don't call resolve_sal_pc here. That's not as bad as it
11321 seems, because all existing breakpoints typically have both
11322 file/line and pc set. So, if clear is given file/line, we can
11323 match this to existing breakpoint without obtaining pc at all.
11325 We only support clearing given the address explicitly
11326 present in breakpoint table. Say, we've set breakpoint
11327 at file:line. There were several PC values for that file:line,
11328 due to optimization, all in one block.
11330 We've picked one PC value. If "clear" is issued with another
11331 PC corresponding to the same file:line, the breakpoint won't
11332 be cleared. We probably can still clear the breakpoint, but
11333 since the other PC value is never presented to user, user
11334 can only find it by guessing, and it does not seem important
11335 to support that. */
11337 /* For each line spec given, delete bps which correspond to it. Do
11338 it in two passes, solely to preserve the current behavior that
11339 from_tty is forced true if we delete more than one
11342 std::vector
<struct breakpoint
*> found
;
11343 for (const auto &sal
: sals
)
11345 const char *sal_fullname
;
11347 /* If exact pc given, clear bpts at that pc.
11348 If line given (pc == 0), clear all bpts on specified line.
11349 If defaulting, clear all bpts on default line
11352 defaulting sal.pc != 0 tests to do
11357 1 0 <can't happen> */
11359 sal_fullname
= (sal
.symtab
== NULL
11360 ? NULL
: symtab_to_fullname (sal
.symtab
));
11362 /* Find all matching breakpoints and add them to 'found'. */
11363 ALL_BREAKPOINTS (b
)
11366 /* Are we going to delete b? */
11367 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11369 struct bp_location
*loc
= b
->loc
;
11370 for (; loc
; loc
= loc
->next
)
11372 /* If the user specified file:line, don't allow a PC
11373 match. This matches historical gdb behavior. */
11374 int pc_match
= (!sal
.explicit_line
11376 && (loc
->pspace
== sal
.pspace
)
11377 && (loc
->address
== sal
.pc
)
11378 && (!section_is_overlay (loc
->section
)
11379 || loc
->section
== sal
.section
));
11380 int line_match
= 0;
11382 if ((default_match
|| sal
.explicit_line
)
11383 && loc
->symtab
!= NULL
11384 && sal_fullname
!= NULL
11385 && sal
.pspace
== loc
->pspace
11386 && loc
->line_number
== sal
.line
11387 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11388 sal_fullname
) == 0)
11391 if (pc_match
|| line_match
)
11400 found
.push_back (b
);
11404 /* Now go thru the 'found' chain and delete them. */
11405 if (found
.empty ())
11408 error (_("No breakpoint at %s."), arg
);
11410 error (_("No breakpoint at this line."));
11413 /* Remove duplicates from the vec. */
11414 std::sort (found
.begin (), found
.end (),
11415 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11417 return compare_breakpoints (bp_a
, bp_b
) < 0;
11419 found
.erase (std::unique (found
.begin (), found
.end (),
11420 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11422 return compare_breakpoints (bp_a
, bp_b
) == 0;
11426 if (found
.size () > 1)
11427 from_tty
= 1; /* Always report if deleted more than one. */
11430 if (found
.size () == 1)
11431 printf_unfiltered (_("Deleted breakpoint "));
11433 printf_unfiltered (_("Deleted breakpoints "));
11436 for (breakpoint
*iter
: found
)
11439 printf_unfiltered ("%d ", iter
->number
);
11440 delete_breakpoint (iter
);
11443 putchar_unfiltered ('\n');
11446 /* Delete breakpoint in BS if they are `delete' breakpoints and
11447 all breakpoints that are marked for deletion, whether hit or not.
11448 This is called after any breakpoint is hit, or after errors. */
11451 breakpoint_auto_delete (bpstat bs
)
11453 struct breakpoint
*b
, *b_tmp
;
11455 for (; bs
; bs
= bs
->next
)
11456 if (bs
->breakpoint_at
11457 && bs
->breakpoint_at
->disposition
== disp_del
11459 delete_breakpoint (bs
->breakpoint_at
);
11461 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11463 if (b
->disposition
== disp_del_at_next_stop
)
11464 delete_breakpoint (b
);
11468 /* A comparison function for bp_location AP and BP being interfaced to
11469 std::sort. Sort elements primarily by their ADDRESS (no matter what
11470 bl_address_is_meaningful says), secondarily by ordering first
11471 permanent elements and terciarily just ensuring the array is sorted
11472 stable way despite std::sort being an unstable algorithm. */
11475 bp_location_is_less_than (const bp_location
*a
, const bp_location
*b
)
11477 if (a
->address
!= b
->address
)
11478 return a
->address
< b
->address
;
11480 /* Sort locations at the same address by their pspace number, keeping
11481 locations of the same inferior (in a multi-inferior environment)
11484 if (a
->pspace
->num
!= b
->pspace
->num
)
11485 return a
->pspace
->num
< b
->pspace
->num
;
11487 /* Sort permanent breakpoints first. */
11488 if (a
->permanent
!= b
->permanent
)
11489 return a
->permanent
> b
->permanent
;
11491 /* Make the internal GDB representation stable across GDB runs
11492 where A and B memory inside GDB can differ. Breakpoint locations of
11493 the same type at the same address can be sorted in arbitrary order. */
11495 if (a
->owner
->number
!= b
->owner
->number
)
11496 return a
->owner
->number
< b
->owner
->number
;
11501 /* Set bp_locations_placed_address_before_address_max and
11502 bp_locations_shadow_len_after_address_max according to the current
11503 content of the bp_locations array. */
11506 bp_locations_target_extensions_update (void)
11508 struct bp_location
*bl
, **blp_tmp
;
11510 bp_locations_placed_address_before_address_max
= 0;
11511 bp_locations_shadow_len_after_address_max
= 0;
11513 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11515 CORE_ADDR start
, end
, addr
;
11517 if (!bp_location_has_shadow (bl
))
11520 start
= bl
->target_info
.placed_address
;
11521 end
= start
+ bl
->target_info
.shadow_len
;
11523 gdb_assert (bl
->address
>= start
);
11524 addr
= bl
->address
- start
;
11525 if (addr
> bp_locations_placed_address_before_address_max
)
11526 bp_locations_placed_address_before_address_max
= addr
;
11528 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11530 gdb_assert (bl
->address
< end
);
11531 addr
= end
- bl
->address
;
11532 if (addr
> bp_locations_shadow_len_after_address_max
)
11533 bp_locations_shadow_len_after_address_max
= addr
;
11537 /* Download tracepoint locations if they haven't been. */
11540 download_tracepoint_locations (void)
11542 struct breakpoint
*b
;
11543 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11545 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11547 ALL_TRACEPOINTS (b
)
11549 struct bp_location
*bl
;
11550 struct tracepoint
*t
;
11551 int bp_location_downloaded
= 0;
11553 if ((b
->type
== bp_fast_tracepoint
11554 ? !may_insert_fast_tracepoints
11555 : !may_insert_tracepoints
))
11558 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11560 if (target_can_download_tracepoint ())
11561 can_download_tracepoint
= TRIBOOL_TRUE
;
11563 can_download_tracepoint
= TRIBOOL_FALSE
;
11566 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11569 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11571 /* In tracepoint, locations are _never_ duplicated, so
11572 should_be_inserted is equivalent to
11573 unduplicated_should_be_inserted. */
11574 if (!should_be_inserted (bl
) || bl
->inserted
)
11577 switch_to_program_space_and_thread (bl
->pspace
);
11579 target_download_tracepoint (bl
);
11582 bp_location_downloaded
= 1;
11584 t
= (struct tracepoint
*) b
;
11585 t
->number_on_target
= b
->number
;
11586 if (bp_location_downloaded
)
11587 gdb::observers::breakpoint_modified
.notify (b
);
11591 /* Swap the insertion/duplication state between two locations. */
11594 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11596 const int left_inserted
= left
->inserted
;
11597 const int left_duplicate
= left
->duplicate
;
11598 const int left_needs_update
= left
->needs_update
;
11599 const struct bp_target_info left_target_info
= left
->target_info
;
11601 /* Locations of tracepoints can never be duplicated. */
11602 if (is_tracepoint (left
->owner
))
11603 gdb_assert (!left
->duplicate
);
11604 if (is_tracepoint (right
->owner
))
11605 gdb_assert (!right
->duplicate
);
11607 left
->inserted
= right
->inserted
;
11608 left
->duplicate
= right
->duplicate
;
11609 left
->needs_update
= right
->needs_update
;
11610 left
->target_info
= right
->target_info
;
11611 right
->inserted
= left_inserted
;
11612 right
->duplicate
= left_duplicate
;
11613 right
->needs_update
= left_needs_update
;
11614 right
->target_info
= left_target_info
;
11617 /* Force the re-insertion of the locations at ADDRESS. This is called
11618 once a new/deleted/modified duplicate location is found and we are evaluating
11619 conditions on the target's side. Such conditions need to be updated on
11623 force_breakpoint_reinsertion (struct bp_location
*bl
)
11625 struct bp_location
**locp
= NULL
, **loc2p
;
11626 struct bp_location
*loc
;
11627 CORE_ADDR address
= 0;
11630 address
= bl
->address
;
11631 pspace_num
= bl
->pspace
->num
;
11633 /* This is only meaningful if the target is
11634 evaluating conditions and if the user has
11635 opted for condition evaluation on the target's
11637 if (gdb_evaluates_breakpoint_condition_p ()
11638 || !target_supports_evaluation_of_breakpoint_conditions ())
11641 /* Flag all breakpoint locations with this address and
11642 the same program space as the location
11643 as "its condition has changed". We need to
11644 update the conditions on the target's side. */
11645 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11649 if (!is_breakpoint (loc
->owner
)
11650 || pspace_num
!= loc
->pspace
->num
)
11653 /* Flag the location appropriately. We use a different state to
11654 let everyone know that we already updated the set of locations
11655 with addr bl->address and program space bl->pspace. This is so
11656 we don't have to keep calling these functions just to mark locations
11657 that have already been marked. */
11658 loc
->condition_changed
= condition_updated
;
11660 /* Free the agent expression bytecode as well. We will compute
11662 loc
->cond_bytecode
.reset ();
11665 /* Called whether new breakpoints are created, or existing breakpoints
11666 deleted, to update the global location list and recompute which
11667 locations are duplicate of which.
11669 The INSERT_MODE flag determines whether locations may not, may, or
11670 shall be inserted now. See 'enum ugll_insert_mode' for more
11674 update_global_location_list (enum ugll_insert_mode insert_mode
)
11676 struct breakpoint
*b
;
11677 struct bp_location
**locp
, *loc
;
11678 /* Last breakpoint location address that was marked for update. */
11679 CORE_ADDR last_addr
= 0;
11680 /* Last breakpoint location program space that was marked for update. */
11681 int last_pspace_num
= -1;
11683 /* Used in the duplicates detection below. When iterating over all
11684 bp_locations, points to the first bp_location of a given address.
11685 Breakpoints and watchpoints of different types are never
11686 duplicates of each other. Keep one pointer for each type of
11687 breakpoint/watchpoint, so we only need to loop over all locations
11689 struct bp_location
*bp_loc_first
; /* breakpoint */
11690 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11691 struct bp_location
*awp_loc_first
; /* access watchpoint */
11692 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11694 /* Saved former bp_locations array which we compare against the newly
11695 built bp_locations from the current state of ALL_BREAKPOINTS. */
11696 struct bp_location
**old_locp
;
11697 unsigned old_locations_count
;
11698 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11700 old_locations_count
= bp_locations_count
;
11701 bp_locations
= NULL
;
11702 bp_locations_count
= 0;
11704 ALL_BREAKPOINTS (b
)
11705 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11706 bp_locations_count
++;
11708 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11709 locp
= bp_locations
;
11710 ALL_BREAKPOINTS (b
)
11711 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11713 std::sort (bp_locations
, bp_locations
+ bp_locations_count
,
11714 bp_location_is_less_than
);
11716 bp_locations_target_extensions_update ();
11718 /* Identify bp_location instances that are no longer present in the
11719 new list, and therefore should be freed. Note that it's not
11720 necessary that those locations should be removed from inferior --
11721 if there's another location at the same address (previously
11722 marked as duplicate), we don't need to remove/insert the
11725 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11726 and former bp_location array state respectively. */
11728 locp
= bp_locations
;
11729 for (old_locp
= old_locations
.get ();
11730 old_locp
< old_locations
.get () + old_locations_count
;
11733 struct bp_location
*old_loc
= *old_locp
;
11734 struct bp_location
**loc2p
;
11736 /* Tells if 'old_loc' is found among the new locations. If
11737 not, we have to free it. */
11738 int found_object
= 0;
11739 /* Tells if the location should remain inserted in the target. */
11740 int keep_in_target
= 0;
11743 /* Skip LOCP entries which will definitely never be needed.
11744 Stop either at or being the one matching OLD_LOC. */
11745 while (locp
< bp_locations
+ bp_locations_count
11746 && (*locp
)->address
< old_loc
->address
)
11750 (loc2p
< bp_locations
+ bp_locations_count
11751 && (*loc2p
)->address
== old_loc
->address
);
11754 /* Check if this is a new/duplicated location or a duplicated
11755 location that had its condition modified. If so, we want to send
11756 its condition to the target if evaluation of conditions is taking
11758 if ((*loc2p
)->condition_changed
== condition_modified
11759 && (last_addr
!= old_loc
->address
11760 || last_pspace_num
!= old_loc
->pspace
->num
))
11762 force_breakpoint_reinsertion (*loc2p
);
11763 last_pspace_num
= old_loc
->pspace
->num
;
11766 if (*loc2p
== old_loc
)
11770 /* We have already handled this address, update it so that we don't
11771 have to go through updates again. */
11772 last_addr
= old_loc
->address
;
11774 /* Target-side condition evaluation: Handle deleted locations. */
11776 force_breakpoint_reinsertion (old_loc
);
11778 /* If this location is no longer present, and inserted, look if
11779 there's maybe a new location at the same address. If so,
11780 mark that one inserted, and don't remove this one. This is
11781 needed so that we don't have a time window where a breakpoint
11782 at certain location is not inserted. */
11784 if (old_loc
->inserted
)
11786 /* If the location is inserted now, we might have to remove
11789 if (found_object
&& should_be_inserted (old_loc
))
11791 /* The location is still present in the location list,
11792 and still should be inserted. Don't do anything. */
11793 keep_in_target
= 1;
11797 /* This location still exists, but it won't be kept in the
11798 target since it may have been disabled. We proceed to
11799 remove its target-side condition. */
11801 /* The location is either no longer present, or got
11802 disabled. See if there's another location at the
11803 same address, in which case we don't need to remove
11804 this one from the target. */
11806 /* OLD_LOC comes from existing struct breakpoint. */
11807 if (bl_address_is_meaningful (old_loc
))
11810 (loc2p
< bp_locations
+ bp_locations_count
11811 && (*loc2p
)->address
== old_loc
->address
);
11814 struct bp_location
*loc2
= *loc2p
;
11816 if (breakpoint_locations_match (loc2
, old_loc
))
11818 /* Read watchpoint locations are switched to
11819 access watchpoints, if the former are not
11820 supported, but the latter are. */
11821 if (is_hardware_watchpoint (old_loc
->owner
))
11823 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11824 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11827 /* loc2 is a duplicated location. We need to check
11828 if it should be inserted in case it will be
11830 if (loc2
!= old_loc
11831 && unduplicated_should_be_inserted (loc2
))
11833 swap_insertion (old_loc
, loc2
);
11834 keep_in_target
= 1;
11842 if (!keep_in_target
)
11844 if (remove_breakpoint (old_loc
))
11846 /* This is just about all we can do. We could keep
11847 this location on the global list, and try to
11848 remove it next time, but there's no particular
11849 reason why we will succeed next time.
11851 Note that at this point, old_loc->owner is still
11852 valid, as delete_breakpoint frees the breakpoint
11853 only after calling us. */
11854 printf_filtered (_("warning: Error removing "
11855 "breakpoint %d\n"),
11856 old_loc
->owner
->number
);
11864 if (removed
&& target_is_non_stop_p ()
11865 && need_moribund_for_location_type (old_loc
))
11867 /* This location was removed from the target. In
11868 non-stop mode, a race condition is possible where
11869 we've removed a breakpoint, but stop events for that
11870 breakpoint are already queued and will arrive later.
11871 We apply an heuristic to be able to distinguish such
11872 SIGTRAPs from other random SIGTRAPs: we keep this
11873 breakpoint location for a bit, and will retire it
11874 after we see some number of events. The theory here
11875 is that reporting of events should, "on the average",
11876 be fair, so after a while we'll see events from all
11877 threads that have anything of interest, and no longer
11878 need to keep this breakpoint location around. We
11879 don't hold locations forever so to reduce chances of
11880 mistaking a non-breakpoint SIGTRAP for a breakpoint
11883 The heuristic failing can be disastrous on
11884 decr_pc_after_break targets.
11886 On decr_pc_after_break targets, like e.g., x86-linux,
11887 if we fail to recognize a late breakpoint SIGTRAP,
11888 because events_till_retirement has reached 0 too
11889 soon, we'll fail to do the PC adjustment, and report
11890 a random SIGTRAP to the user. When the user resumes
11891 the inferior, it will most likely immediately crash
11892 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11893 corrupted, because of being resumed e.g., in the
11894 middle of a multi-byte instruction, or skipped a
11895 one-byte instruction. This was actually seen happen
11896 on native x86-linux, and should be less rare on
11897 targets that do not support new thread events, like
11898 remote, due to the heuristic depending on
11901 Mistaking a random SIGTRAP for a breakpoint trap
11902 causes similar symptoms (PC adjustment applied when
11903 it shouldn't), but then again, playing with SIGTRAPs
11904 behind the debugger's back is asking for trouble.
11906 Since hardware watchpoint traps are always
11907 distinguishable from other traps, so we don't need to
11908 apply keep hardware watchpoint moribund locations
11909 around. We simply always ignore hardware watchpoint
11910 traps we can no longer explain. */
11912 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
11913 old_loc
->owner
= NULL
;
11915 moribund_locations
.push_back (old_loc
);
11919 old_loc
->owner
= NULL
;
11920 decref_bp_location (&old_loc
);
11925 /* Rescan breakpoints at the same address and section, marking the
11926 first one as "first" and any others as "duplicates". This is so
11927 that the bpt instruction is only inserted once. If we have a
11928 permanent breakpoint at the same place as BPT, make that one the
11929 official one, and the rest as duplicates. Permanent breakpoints
11930 are sorted first for the same address.
11932 Do the same for hardware watchpoints, but also considering the
11933 watchpoint's type (regular/access/read) and length. */
11935 bp_loc_first
= NULL
;
11936 wp_loc_first
= NULL
;
11937 awp_loc_first
= NULL
;
11938 rwp_loc_first
= NULL
;
11939 ALL_BP_LOCATIONS (loc
, locp
)
11941 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11943 struct bp_location
**loc_first_p
;
11946 if (!unduplicated_should_be_inserted (loc
)
11947 || !bl_address_is_meaningful (loc
)
11948 /* Don't detect duplicate for tracepoint locations because they are
11949 never duplicated. See the comments in field `duplicate' of
11950 `struct bp_location'. */
11951 || is_tracepoint (b
))
11953 /* Clear the condition modification flag. */
11954 loc
->condition_changed
= condition_unchanged
;
11958 if (b
->type
== bp_hardware_watchpoint
)
11959 loc_first_p
= &wp_loc_first
;
11960 else if (b
->type
== bp_read_watchpoint
)
11961 loc_first_p
= &rwp_loc_first
;
11962 else if (b
->type
== bp_access_watchpoint
)
11963 loc_first_p
= &awp_loc_first
;
11965 loc_first_p
= &bp_loc_first
;
11967 if (*loc_first_p
== NULL
11968 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11969 || !breakpoint_locations_match (loc
, *loc_first_p
))
11971 *loc_first_p
= loc
;
11972 loc
->duplicate
= 0;
11974 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11976 loc
->needs_update
= 1;
11977 /* Clear the condition modification flag. */
11978 loc
->condition_changed
= condition_unchanged
;
11984 /* This and the above ensure the invariant that the first location
11985 is not duplicated, and is the inserted one.
11986 All following are marked as duplicated, and are not inserted. */
11988 swap_insertion (loc
, *loc_first_p
);
11989 loc
->duplicate
= 1;
11991 /* Clear the condition modification flag. */
11992 loc
->condition_changed
= condition_unchanged
;
11995 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11997 if (insert_mode
!= UGLL_DONT_INSERT
)
11998 insert_breakpoint_locations ();
12001 /* Even though the caller told us to not insert new
12002 locations, we may still need to update conditions on the
12003 target's side of breakpoints that were already inserted
12004 if the target is evaluating breakpoint conditions. We
12005 only update conditions for locations that are marked
12007 update_inserted_breakpoint_locations ();
12011 if (insert_mode
!= UGLL_DONT_INSERT
)
12012 download_tracepoint_locations ();
12016 breakpoint_retire_moribund (void)
12018 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
12020 struct bp_location
*loc
= moribund_locations
[ix
];
12021 if (--(loc
->events_till_retirement
) == 0)
12023 decref_bp_location (&loc
);
12024 unordered_remove (moribund_locations
, ix
);
12031 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12036 update_global_location_list (insert_mode
);
12038 catch (const gdb_exception_error
&e
)
12043 /* Clear BKP from a BPS. */
12046 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12050 for (bs
= bps
; bs
; bs
= bs
->next
)
12051 if (bs
->breakpoint_at
== bpt
)
12053 bs
->breakpoint_at
= NULL
;
12054 bs
->old_val
= NULL
;
12055 /* bs->commands will be freed later. */
12059 /* Callback for iterate_over_threads. */
12061 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12063 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12065 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12069 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12073 say_where (struct breakpoint
*b
)
12075 struct value_print_options opts
;
12077 get_user_print_options (&opts
);
12079 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12081 if (b
->loc
== NULL
)
12083 /* For pending locations, the output differs slightly based
12084 on b->extra_string. If this is non-NULL, it contains either
12085 a condition or dprintf arguments. */
12086 if (b
->extra_string
== NULL
)
12088 printf_filtered (_(" (%s) pending."),
12089 event_location_to_string (b
->location
.get ()));
12091 else if (b
->type
== bp_dprintf
)
12093 printf_filtered (_(" (%s,%s) pending."),
12094 event_location_to_string (b
->location
.get ()),
12099 printf_filtered (_(" (%s %s) pending."),
12100 event_location_to_string (b
->location
.get ()),
12106 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12107 printf_filtered (" at %ps",
12108 styled_string (address_style
.style (),
12109 paddress (b
->loc
->gdbarch
,
12110 b
->loc
->address
)));
12111 if (b
->loc
->symtab
!= NULL
)
12113 /* If there is a single location, we can print the location
12115 if (b
->loc
->next
== NULL
)
12117 const char *filename
12118 = symtab_to_filename_for_display (b
->loc
->symtab
);
12119 printf_filtered (": file %ps, line %d.",
12120 styled_string (file_name_style
.style (),
12122 b
->loc
->line_number
);
12125 /* This is not ideal, but each location may have a
12126 different file name, and this at least reflects the
12127 real situation somewhat. */
12128 printf_filtered (": %s.",
12129 event_location_to_string (b
->location
.get ()));
12134 struct bp_location
*loc
= b
->loc
;
12136 for (; loc
; loc
= loc
->next
)
12138 printf_filtered (" (%d locations)", n
);
12143 bp_location::~bp_location ()
12145 xfree (function_name
);
12148 /* Destructor for the breakpoint base class. */
12150 breakpoint::~breakpoint ()
12152 xfree (this->cond_string
);
12153 xfree (this->extra_string
);
12156 static struct bp_location
*
12157 base_breakpoint_allocate_location (struct breakpoint
*self
)
12159 return new bp_location (self
);
12163 base_breakpoint_re_set (struct breakpoint
*b
)
12165 /* Nothing to re-set. */
12168 #define internal_error_pure_virtual_called() \
12169 gdb_assert_not_reached ("pure virtual function called")
12172 base_breakpoint_insert_location (struct bp_location
*bl
)
12174 internal_error_pure_virtual_called ();
12178 base_breakpoint_remove_location (struct bp_location
*bl
,
12179 enum remove_bp_reason reason
)
12181 internal_error_pure_virtual_called ();
12185 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12186 const address_space
*aspace
,
12188 const struct target_waitstatus
*ws
)
12190 internal_error_pure_virtual_called ();
12194 base_breakpoint_check_status (bpstat bs
)
12199 /* A "works_in_software_mode" breakpoint_ops method that just internal
12203 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12205 internal_error_pure_virtual_called ();
12208 /* A "resources_needed" breakpoint_ops method that just internal
12212 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12214 internal_error_pure_virtual_called ();
12217 static enum print_stop_action
12218 base_breakpoint_print_it (bpstat bs
)
12220 internal_error_pure_virtual_called ();
12224 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12225 struct ui_out
*uiout
)
12231 base_breakpoint_print_mention (struct breakpoint
*b
)
12233 internal_error_pure_virtual_called ();
12237 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12239 internal_error_pure_virtual_called ();
12243 base_breakpoint_create_sals_from_location
12244 (const struct event_location
*location
,
12245 struct linespec_result
*canonical
,
12246 enum bptype type_wanted
)
12248 internal_error_pure_virtual_called ();
12252 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12253 struct linespec_result
*c
,
12254 gdb::unique_xmalloc_ptr
<char> cond_string
,
12255 gdb::unique_xmalloc_ptr
<char> extra_string
,
12256 enum bptype type_wanted
,
12257 enum bpdisp disposition
,
12259 int task
, int ignore_count
,
12260 const struct breakpoint_ops
*o
,
12261 int from_tty
, int enabled
,
12262 int internal
, unsigned flags
)
12264 internal_error_pure_virtual_called ();
12267 static std::vector
<symtab_and_line
>
12268 base_breakpoint_decode_location (struct breakpoint
*b
,
12269 const struct event_location
*location
,
12270 struct program_space
*search_pspace
)
12272 internal_error_pure_virtual_called ();
12275 /* The default 'explains_signal' method. */
12278 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12283 /* The default "after_condition_true" method. */
12286 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12288 /* Nothing to do. */
12291 struct breakpoint_ops base_breakpoint_ops
=
12293 base_breakpoint_allocate_location
,
12294 base_breakpoint_re_set
,
12295 base_breakpoint_insert_location
,
12296 base_breakpoint_remove_location
,
12297 base_breakpoint_breakpoint_hit
,
12298 base_breakpoint_check_status
,
12299 base_breakpoint_resources_needed
,
12300 base_breakpoint_works_in_software_mode
,
12301 base_breakpoint_print_it
,
12303 base_breakpoint_print_one_detail
,
12304 base_breakpoint_print_mention
,
12305 base_breakpoint_print_recreate
,
12306 base_breakpoint_create_sals_from_location
,
12307 base_breakpoint_create_breakpoints_sal
,
12308 base_breakpoint_decode_location
,
12309 base_breakpoint_explains_signal
,
12310 base_breakpoint_after_condition_true
,
12313 /* Default breakpoint_ops methods. */
12316 bkpt_re_set (struct breakpoint
*b
)
12318 /* FIXME: is this still reachable? */
12319 if (breakpoint_event_location_empty_p (b
))
12321 /* Anything without a location can't be re-set. */
12322 delete_breakpoint (b
);
12326 breakpoint_re_set_default (b
);
12330 bkpt_insert_location (struct bp_location
*bl
)
12332 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12334 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12335 bl
->target_info
.placed_address
= addr
;
12337 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12338 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12340 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12344 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12346 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12347 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12349 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12353 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12354 const address_space
*aspace
, CORE_ADDR bp_addr
,
12355 const struct target_waitstatus
*ws
)
12357 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12358 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12361 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12365 if (overlay_debugging
/* unmapped overlay section */
12366 && section_is_overlay (bl
->section
)
12367 && !section_is_mapped (bl
->section
))
12374 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12375 const address_space
*aspace
, CORE_ADDR bp_addr
,
12376 const struct target_waitstatus
*ws
)
12378 if (dprintf_style
== dprintf_style_agent
12379 && target_can_run_breakpoint_commands ())
12381 /* An agent-style dprintf never causes a stop. If we see a trap
12382 for this address it must be for a breakpoint that happens to
12383 be set at the same address. */
12387 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12391 bkpt_resources_needed (const struct bp_location
*bl
)
12393 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12398 static enum print_stop_action
12399 bkpt_print_it (bpstat bs
)
12401 struct breakpoint
*b
;
12402 const struct bp_location
*bl
;
12404 struct ui_out
*uiout
= current_uiout
;
12406 gdb_assert (bs
->bp_location_at
!= NULL
);
12408 bl
= bs
->bp_location_at
;
12409 b
= bs
->breakpoint_at
;
12411 bp_temp
= b
->disposition
== disp_del
;
12412 if (bl
->address
!= bl
->requested_address
)
12413 breakpoint_adjustment_warning (bl
->requested_address
,
12416 annotate_breakpoint (b
->number
);
12417 maybe_print_thread_hit_breakpoint (uiout
);
12419 if (uiout
->is_mi_like_p ())
12421 uiout
->field_string ("reason",
12422 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12423 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12426 uiout
->message ("Temporary breakpoint %pF, ",
12427 signed_field ("bkptno", b
->number
));
12429 uiout
->message ("Breakpoint %pF, ",
12430 signed_field ("bkptno", b
->number
));
12432 return PRINT_SRC_AND_LOC
;
12436 bkpt_print_mention (struct breakpoint
*b
)
12438 if (current_uiout
->is_mi_like_p ())
12443 case bp_breakpoint
:
12444 case bp_gnu_ifunc_resolver
:
12445 if (b
->disposition
== disp_del
)
12446 printf_filtered (_("Temporary breakpoint"));
12448 printf_filtered (_("Breakpoint"));
12449 printf_filtered (_(" %d"), b
->number
);
12450 if (b
->type
== bp_gnu_ifunc_resolver
)
12451 printf_filtered (_(" at gnu-indirect-function resolver"));
12453 case bp_hardware_breakpoint
:
12454 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12457 printf_filtered (_("Dprintf %d"), b
->number
);
12465 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12467 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12468 fprintf_unfiltered (fp
, "tbreak");
12469 else if (tp
->type
== bp_breakpoint
)
12470 fprintf_unfiltered (fp
, "break");
12471 else if (tp
->type
== bp_hardware_breakpoint
12472 && tp
->disposition
== disp_del
)
12473 fprintf_unfiltered (fp
, "thbreak");
12474 else if (tp
->type
== bp_hardware_breakpoint
)
12475 fprintf_unfiltered (fp
, "hbreak");
12477 internal_error (__FILE__
, __LINE__
,
12478 _("unhandled breakpoint type %d"), (int) tp
->type
);
12480 fprintf_unfiltered (fp
, " %s",
12481 event_location_to_string (tp
->location
.get ()));
12483 /* Print out extra_string if this breakpoint is pending. It might
12484 contain, for example, conditions that were set by the user. */
12485 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12486 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12488 print_recreate_thread (tp
, fp
);
12492 bkpt_create_sals_from_location (const struct event_location
*location
,
12493 struct linespec_result
*canonical
,
12494 enum bptype type_wanted
)
12496 create_sals_from_location_default (location
, canonical
, type_wanted
);
12500 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12501 struct linespec_result
*canonical
,
12502 gdb::unique_xmalloc_ptr
<char> cond_string
,
12503 gdb::unique_xmalloc_ptr
<char> extra_string
,
12504 enum bptype type_wanted
,
12505 enum bpdisp disposition
,
12507 int task
, int ignore_count
,
12508 const struct breakpoint_ops
*ops
,
12509 int from_tty
, int enabled
,
12510 int internal
, unsigned flags
)
12512 create_breakpoints_sal_default (gdbarch
, canonical
,
12513 std::move (cond_string
),
12514 std::move (extra_string
),
12516 disposition
, thread
, task
,
12517 ignore_count
, ops
, from_tty
,
12518 enabled
, internal
, flags
);
12521 static std::vector
<symtab_and_line
>
12522 bkpt_decode_location (struct breakpoint
*b
,
12523 const struct event_location
*location
,
12524 struct program_space
*search_pspace
)
12526 return decode_location_default (b
, location
, search_pspace
);
12529 /* Virtual table for internal breakpoints. */
12532 internal_bkpt_re_set (struct breakpoint
*b
)
12536 /* Delete overlay event and longjmp master breakpoints; they
12537 will be reset later by breakpoint_re_set. */
12538 case bp_overlay_event
:
12539 case bp_longjmp_master
:
12540 case bp_std_terminate_master
:
12541 case bp_exception_master
:
12542 delete_breakpoint (b
);
12545 /* This breakpoint is special, it's set up when the inferior
12546 starts and we really don't want to touch it. */
12547 case bp_shlib_event
:
12549 /* Like bp_shlib_event, this breakpoint type is special. Once
12550 it is set up, we do not want to touch it. */
12551 case bp_thread_event
:
12557 internal_bkpt_check_status (bpstat bs
)
12559 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12561 /* If requested, stop when the dynamic linker notifies GDB of
12562 events. This allows the user to get control and place
12563 breakpoints in initializer routines for dynamically loaded
12564 objects (among other things). */
12565 bs
->stop
= stop_on_solib_events
;
12566 bs
->print
= stop_on_solib_events
;
12572 static enum print_stop_action
12573 internal_bkpt_print_it (bpstat bs
)
12575 struct breakpoint
*b
;
12577 b
= bs
->breakpoint_at
;
12581 case bp_shlib_event
:
12582 /* Did we stop because the user set the stop_on_solib_events
12583 variable? (If so, we report this as a generic, "Stopped due
12584 to shlib event" message.) */
12585 print_solib_event (0);
12588 case bp_thread_event
:
12589 /* Not sure how we will get here.
12590 GDB should not stop for these breakpoints. */
12591 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12594 case bp_overlay_event
:
12595 /* By analogy with the thread event, GDB should not stop for these. */
12596 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12599 case bp_longjmp_master
:
12600 /* These should never be enabled. */
12601 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12604 case bp_std_terminate_master
:
12605 /* These should never be enabled. */
12606 printf_filtered (_("std::terminate Master Breakpoint: "
12607 "gdb should not stop!\n"));
12610 case bp_exception_master
:
12611 /* These should never be enabled. */
12612 printf_filtered (_("Exception Master Breakpoint: "
12613 "gdb should not stop!\n"));
12617 return PRINT_NOTHING
;
12621 internal_bkpt_print_mention (struct breakpoint
*b
)
12623 /* Nothing to mention. These breakpoints are internal. */
12626 /* Virtual table for momentary breakpoints */
12629 momentary_bkpt_re_set (struct breakpoint
*b
)
12631 /* Keep temporary breakpoints, which can be encountered when we step
12632 over a dlopen call and solib_add is resetting the breakpoints.
12633 Otherwise these should have been blown away via the cleanup chain
12634 or by breakpoint_init_inferior when we rerun the executable. */
12638 momentary_bkpt_check_status (bpstat bs
)
12640 /* Nothing. The point of these breakpoints is causing a stop. */
12643 static enum print_stop_action
12644 momentary_bkpt_print_it (bpstat bs
)
12646 return PRINT_UNKNOWN
;
12650 momentary_bkpt_print_mention (struct breakpoint
*b
)
12652 /* Nothing to mention. These breakpoints are internal. */
12655 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12657 It gets cleared already on the removal of the first one of such placed
12658 breakpoints. This is OK as they get all removed altogether. */
12660 longjmp_breakpoint::~longjmp_breakpoint ()
12662 thread_info
*tp
= find_thread_global_id (this->thread
);
12665 tp
->initiating_frame
= null_frame_id
;
12668 /* Specific methods for probe breakpoints. */
12671 bkpt_probe_insert_location (struct bp_location
*bl
)
12673 int v
= bkpt_insert_location (bl
);
12677 /* The insertion was successful, now let's set the probe's semaphore
12679 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12686 bkpt_probe_remove_location (struct bp_location
*bl
,
12687 enum remove_bp_reason reason
)
12689 /* Let's clear the semaphore before removing the location. */
12690 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12692 return bkpt_remove_location (bl
, reason
);
12696 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
12697 struct linespec_result
*canonical
,
12698 enum bptype type_wanted
)
12700 struct linespec_sals lsal
;
12702 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12704 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12705 canonical
->lsals
.push_back (std::move (lsal
));
12708 static std::vector
<symtab_and_line
>
12709 bkpt_probe_decode_location (struct breakpoint
*b
,
12710 const struct event_location
*location
,
12711 struct program_space
*search_pspace
)
12713 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12715 error (_("probe not found"));
12719 /* The breakpoint_ops structure to be used in tracepoints. */
12722 tracepoint_re_set (struct breakpoint
*b
)
12724 breakpoint_re_set_default (b
);
12728 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12729 const address_space
*aspace
, CORE_ADDR bp_addr
,
12730 const struct target_waitstatus
*ws
)
12732 /* By definition, the inferior does not report stops at
12738 tracepoint_print_one_detail (const struct breakpoint
*self
,
12739 struct ui_out
*uiout
)
12741 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12742 if (!tp
->static_trace_marker_id
.empty ())
12744 gdb_assert (self
->type
== bp_static_tracepoint
);
12746 uiout
->message ("\tmarker id is %pF\n",
12747 string_field ("static-tracepoint-marker-string-id",
12748 tp
->static_trace_marker_id
.c_str ()));
12753 tracepoint_print_mention (struct breakpoint
*b
)
12755 if (current_uiout
->is_mi_like_p ())
12760 case bp_tracepoint
:
12761 printf_filtered (_("Tracepoint"));
12762 printf_filtered (_(" %d"), b
->number
);
12764 case bp_fast_tracepoint
:
12765 printf_filtered (_("Fast tracepoint"));
12766 printf_filtered (_(" %d"), b
->number
);
12768 case bp_static_tracepoint
:
12769 printf_filtered (_("Static tracepoint"));
12770 printf_filtered (_(" %d"), b
->number
);
12773 internal_error (__FILE__
, __LINE__
,
12774 _("unhandled tracepoint type %d"), (int) b
->type
);
12781 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12783 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12785 if (self
->type
== bp_fast_tracepoint
)
12786 fprintf_unfiltered (fp
, "ftrace");
12787 else if (self
->type
== bp_static_tracepoint
)
12788 fprintf_unfiltered (fp
, "strace");
12789 else if (self
->type
== bp_tracepoint
)
12790 fprintf_unfiltered (fp
, "trace");
12792 internal_error (__FILE__
, __LINE__
,
12793 _("unhandled tracepoint type %d"), (int) self
->type
);
12795 fprintf_unfiltered (fp
, " %s",
12796 event_location_to_string (self
->location
.get ()));
12797 print_recreate_thread (self
, fp
);
12799 if (tp
->pass_count
)
12800 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12804 tracepoint_create_sals_from_location (const struct event_location
*location
,
12805 struct linespec_result
*canonical
,
12806 enum bptype type_wanted
)
12808 create_sals_from_location_default (location
, canonical
, type_wanted
);
12812 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12813 struct linespec_result
*canonical
,
12814 gdb::unique_xmalloc_ptr
<char> cond_string
,
12815 gdb::unique_xmalloc_ptr
<char> extra_string
,
12816 enum bptype type_wanted
,
12817 enum bpdisp disposition
,
12819 int task
, int ignore_count
,
12820 const struct breakpoint_ops
*ops
,
12821 int from_tty
, int enabled
,
12822 int internal
, unsigned flags
)
12824 create_breakpoints_sal_default (gdbarch
, canonical
,
12825 std::move (cond_string
),
12826 std::move (extra_string
),
12828 disposition
, thread
, task
,
12829 ignore_count
, ops
, from_tty
,
12830 enabled
, internal
, flags
);
12833 static std::vector
<symtab_and_line
>
12834 tracepoint_decode_location (struct breakpoint
*b
,
12835 const struct event_location
*location
,
12836 struct program_space
*search_pspace
)
12838 return decode_location_default (b
, location
, search_pspace
);
12841 struct breakpoint_ops tracepoint_breakpoint_ops
;
12843 /* Virtual table for tracepoints on static probes. */
12846 tracepoint_probe_create_sals_from_location
12847 (const struct event_location
*location
,
12848 struct linespec_result
*canonical
,
12849 enum bptype type_wanted
)
12851 /* We use the same method for breakpoint on probes. */
12852 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
12855 static std::vector
<symtab_and_line
>
12856 tracepoint_probe_decode_location (struct breakpoint
*b
,
12857 const struct event_location
*location
,
12858 struct program_space
*search_pspace
)
12860 /* We use the same method for breakpoint on probes. */
12861 return bkpt_probe_decode_location (b
, location
, search_pspace
);
12864 /* Dprintf breakpoint_ops methods. */
12867 dprintf_re_set (struct breakpoint
*b
)
12869 breakpoint_re_set_default (b
);
12871 /* extra_string should never be non-NULL for dprintf. */
12872 gdb_assert (b
->extra_string
!= NULL
);
12874 /* 1 - connect to target 1, that can run breakpoint commands.
12875 2 - create a dprintf, which resolves fine.
12876 3 - disconnect from target 1
12877 4 - connect to target 2, that can NOT run breakpoint commands.
12879 After steps #3/#4, you'll want the dprintf command list to
12880 be updated, because target 1 and 2 may well return different
12881 answers for target_can_run_breakpoint_commands().
12882 Given absence of finer grained resetting, we get to do
12883 it all the time. */
12884 if (b
->extra_string
!= NULL
)
12885 update_dprintf_command_list (b
);
12888 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
12891 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12893 fprintf_unfiltered (fp
, "dprintf %s,%s",
12894 event_location_to_string (tp
->location
.get ()),
12896 print_recreate_thread (tp
, fp
);
12899 /* Implement the "after_condition_true" breakpoint_ops method for
12902 dprintf's are implemented with regular commands in their command
12903 list, but we run the commands here instead of before presenting the
12904 stop to the user, as dprintf's don't actually cause a stop. This
12905 also makes it so that the commands of multiple dprintfs at the same
12906 address are all handled. */
12909 dprintf_after_condition_true (struct bpstats
*bs
)
12911 struct bpstats tmp_bs
;
12912 struct bpstats
*tmp_bs_p
= &tmp_bs
;
12914 /* dprintf's never cause a stop. This wasn't set in the
12915 check_status hook instead because that would make the dprintf's
12916 condition not be evaluated. */
12919 /* Run the command list here. Take ownership of it instead of
12920 copying. We never want these commands to run later in
12921 bpstat_do_actions, if a breakpoint that causes a stop happens to
12922 be set at same address as this dprintf, or even if running the
12923 commands here throws. */
12924 tmp_bs
.commands
= bs
->commands
;
12925 bs
->commands
= NULL
;
12927 bpstat_do_actions_1 (&tmp_bs_p
);
12929 /* 'tmp_bs.commands' will usually be NULL by now, but
12930 bpstat_do_actions_1 may return early without processing the whole
12934 /* The breakpoint_ops structure to be used on static tracepoints with
12938 strace_marker_create_sals_from_location (const struct event_location
*location
,
12939 struct linespec_result
*canonical
,
12940 enum bptype type_wanted
)
12942 struct linespec_sals lsal
;
12943 const char *arg_start
, *arg
;
12945 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
12946 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12948 std::string
str (arg_start
, arg
- arg_start
);
12949 const char *ptr
= str
.c_str ();
12950 canonical
->location
12951 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
12954 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12955 canonical
->lsals
.push_back (std::move (lsal
));
12959 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12960 struct linespec_result
*canonical
,
12961 gdb::unique_xmalloc_ptr
<char> cond_string
,
12962 gdb::unique_xmalloc_ptr
<char> extra_string
,
12963 enum bptype type_wanted
,
12964 enum bpdisp disposition
,
12966 int task
, int ignore_count
,
12967 const struct breakpoint_ops
*ops
,
12968 int from_tty
, int enabled
,
12969 int internal
, unsigned flags
)
12971 const linespec_sals
&lsal
= canonical
->lsals
[0];
12973 /* If the user is creating a static tracepoint by marker id
12974 (strace -m MARKER_ID), then store the sals index, so that
12975 breakpoint_re_set can try to match up which of the newly
12976 found markers corresponds to this one, and, don't try to
12977 expand multiple locations for each sal, given than SALS
12978 already should contain all sals for MARKER_ID. */
12980 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12982 event_location_up location
12983 = copy_event_location (canonical
->location
.get ());
12985 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
12986 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
12987 std::move (location
), NULL
,
12988 std::move (cond_string
),
12989 std::move (extra_string
),
12990 type_wanted
, disposition
,
12991 thread
, task
, ignore_count
, ops
,
12992 from_tty
, enabled
, internal
, flags
,
12993 canonical
->special_display
);
12994 /* Given that its possible to have multiple markers with
12995 the same string id, if the user is creating a static
12996 tracepoint by marker id ("strace -m MARKER_ID"), then
12997 store the sals index, so that breakpoint_re_set can
12998 try to match up which of the newly found markers
12999 corresponds to this one */
13000 tp
->static_trace_marker_id_idx
= i
;
13002 install_breakpoint (internal
, std::move (tp
), 0);
13006 static std::vector
<symtab_and_line
>
13007 strace_marker_decode_location (struct breakpoint
*b
,
13008 const struct event_location
*location
,
13009 struct program_space
*search_pspace
)
13011 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13012 const char *s
= get_linespec_location (location
)->spec_string
;
13014 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13015 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13017 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13022 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
13025 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13028 strace_marker_p (struct breakpoint
*b
)
13030 return b
->ops
== &strace_marker_breakpoint_ops
;
13033 /* Delete a breakpoint and clean up all traces of it in the data
13037 delete_breakpoint (struct breakpoint
*bpt
)
13039 struct breakpoint
*b
;
13041 gdb_assert (bpt
!= NULL
);
13043 /* Has this bp already been deleted? This can happen because
13044 multiple lists can hold pointers to bp's. bpstat lists are
13047 One example of this happening is a watchpoint's scope bp. When
13048 the scope bp triggers, we notice that the watchpoint is out of
13049 scope, and delete it. We also delete its scope bp. But the
13050 scope bp is marked "auto-deleting", and is already on a bpstat.
13051 That bpstat is then checked for auto-deleting bp's, which are
13054 A real solution to this problem might involve reference counts in
13055 bp's, and/or giving them pointers back to their referencing
13056 bpstat's, and teaching delete_breakpoint to only free a bp's
13057 storage when no more references were extent. A cheaper bandaid
13059 if (bpt
->type
== bp_none
)
13062 /* At least avoid this stale reference until the reference counting
13063 of breakpoints gets resolved. */
13064 if (bpt
->related_breakpoint
!= bpt
)
13066 struct breakpoint
*related
;
13067 struct watchpoint
*w
;
13069 if (bpt
->type
== bp_watchpoint_scope
)
13070 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13071 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13072 w
= (struct watchpoint
*) bpt
;
13076 watchpoint_del_at_next_stop (w
);
13078 /* Unlink bpt from the bpt->related_breakpoint ring. */
13079 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13080 related
= related
->related_breakpoint
);
13081 related
->related_breakpoint
= bpt
->related_breakpoint
;
13082 bpt
->related_breakpoint
= bpt
;
13085 /* watch_command_1 creates a watchpoint but only sets its number if
13086 update_watchpoint succeeds in creating its bp_locations. If there's
13087 a problem in that process, we'll be asked to delete the half-created
13088 watchpoint. In that case, don't announce the deletion. */
13090 gdb::observers::breakpoint_deleted
.notify (bpt
);
13092 if (breakpoint_chain
== bpt
)
13093 breakpoint_chain
= bpt
->next
;
13095 ALL_BREAKPOINTS (b
)
13096 if (b
->next
== bpt
)
13098 b
->next
= bpt
->next
;
13102 /* Be sure no bpstat's are pointing at the breakpoint after it's
13104 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13105 in all threads for now. Note that we cannot just remove bpstats
13106 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13107 commands are associated with the bpstat; if we remove it here,
13108 then the later call to bpstat_do_actions (&stop_bpstat); in
13109 event-top.c won't do anything, and temporary breakpoints with
13110 commands won't work. */
13112 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13114 /* Now that breakpoint is removed from breakpoint list, update the
13115 global location list. This will remove locations that used to
13116 belong to this breakpoint. Do this before freeing the breakpoint
13117 itself, since remove_breakpoint looks at location's owner. It
13118 might be better design to have location completely
13119 self-contained, but it's not the case now. */
13120 update_global_location_list (UGLL_DONT_INSERT
);
13122 /* On the chance that someone will soon try again to delete this
13123 same bp, we mark it as deleted before freeing its storage. */
13124 bpt
->type
= bp_none
;
13128 /* Iterator function to call a user-provided callback function once
13129 for each of B and its related breakpoints. */
13132 iterate_over_related_breakpoints (struct breakpoint
*b
,
13133 gdb::function_view
<void (breakpoint
*)> function
)
13135 struct breakpoint
*related
;
13140 struct breakpoint
*next
;
13142 /* FUNCTION may delete RELATED. */
13143 next
= related
->related_breakpoint
;
13145 if (next
== related
)
13147 /* RELATED is the last ring entry. */
13148 function (related
);
13150 /* FUNCTION may have deleted it, so we'd never reach back to
13151 B. There's nothing left to do anyway, so just break
13156 function (related
);
13160 while (related
!= b
);
13164 delete_command (const char *arg
, int from_tty
)
13166 struct breakpoint
*b
, *b_tmp
;
13172 int breaks_to_delete
= 0;
13174 /* Delete all breakpoints if no argument. Do not delete
13175 internal breakpoints, these have to be deleted with an
13176 explicit breakpoint number argument. */
13177 ALL_BREAKPOINTS (b
)
13178 if (user_breakpoint_p (b
))
13180 breaks_to_delete
= 1;
13184 /* Ask user only if there are some breakpoints to delete. */
13186 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13188 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13189 if (user_breakpoint_p (b
))
13190 delete_breakpoint (b
);
13194 map_breakpoint_numbers
13195 (arg
, [&] (breakpoint
*br
)
13197 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13201 /* Return true if all locations of B bound to PSPACE are pending. If
13202 PSPACE is NULL, all locations of all program spaces are
13206 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13208 struct bp_location
*loc
;
13210 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13211 if ((pspace
== NULL
13212 || loc
->pspace
== pspace
)
13213 && !loc
->shlib_disabled
13214 && !loc
->pspace
->executing_startup
)
13219 /* Subroutine of update_breakpoint_locations to simplify it.
13220 Return non-zero if multiple fns in list LOC have the same name.
13221 Null names are ignored. */
13224 ambiguous_names_p (struct bp_location
*loc
)
13226 struct bp_location
*l
;
13227 htab_t htab
= htab_create_alloc (13, htab_hash_string
, streq_hash
, NULL
,
13230 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13233 const char *name
= l
->function_name
;
13235 /* Allow for some names to be NULL, ignore them. */
13239 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13241 /* NOTE: We can assume slot != NULL here because xcalloc never
13245 htab_delete (htab
);
13251 htab_delete (htab
);
13255 /* When symbols change, it probably means the sources changed as well,
13256 and it might mean the static tracepoint markers are no longer at
13257 the same address or line numbers they used to be at last we
13258 checked. Losing your static tracepoints whenever you rebuild is
13259 undesirable. This function tries to resync/rematch gdb static
13260 tracepoints with the markers on the target, for static tracepoints
13261 that have not been set by marker id. Static tracepoint that have
13262 been set by marker id are reset by marker id in breakpoint_re_set.
13265 1) For a tracepoint set at a specific address, look for a marker at
13266 the old PC. If one is found there, assume to be the same marker.
13267 If the name / string id of the marker found is different from the
13268 previous known name, assume that means the user renamed the marker
13269 in the sources, and output a warning.
13271 2) For a tracepoint set at a given line number, look for a marker
13272 at the new address of the old line number. If one is found there,
13273 assume to be the same marker. If the name / string id of the
13274 marker found is different from the previous known name, assume that
13275 means the user renamed the marker in the sources, and output a
13278 3) If a marker is no longer found at the same address or line, it
13279 may mean the marker no longer exists. But it may also just mean
13280 the code changed a bit. Maybe the user added a few lines of code
13281 that made the marker move up or down (in line number terms). Ask
13282 the target for info about the marker with the string id as we knew
13283 it. If found, update line number and address in the matching
13284 static tracepoint. This will get confused if there's more than one
13285 marker with the same ID (possible in UST, although unadvised
13286 precisely because it confuses tools). */
13288 static struct symtab_and_line
13289 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13291 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13292 struct static_tracepoint_marker marker
;
13297 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13299 if (target_static_tracepoint_marker_at (pc
, &marker
))
13301 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13302 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13303 b
->number
, tp
->static_trace_marker_id
.c_str (),
13304 marker
.str_id
.c_str ());
13306 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13311 /* Old marker wasn't found on target at lineno. Try looking it up
13313 if (!sal
.explicit_pc
13315 && sal
.symtab
!= NULL
13316 && !tp
->static_trace_marker_id
.empty ())
13318 std::vector
<static_tracepoint_marker
> markers
13319 = target_static_tracepoint_markers_by_strid
13320 (tp
->static_trace_marker_id
.c_str ());
13322 if (!markers
.empty ())
13324 struct symbol
*sym
;
13325 struct static_tracepoint_marker
*tpmarker
;
13326 struct ui_out
*uiout
= current_uiout
;
13327 struct explicit_location explicit_loc
;
13329 tpmarker
= &markers
[0];
13331 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13333 warning (_("marker for static tracepoint %d (%s) not "
13334 "found at previous line number"),
13335 b
->number
, tp
->static_trace_marker_id
.c_str ());
13337 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13338 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13339 uiout
->text ("Now in ");
13342 uiout
->field_string ("func", sym
->print_name (),
13343 function_name_style
.style ());
13344 uiout
->text (" at ");
13346 uiout
->field_string ("file",
13347 symtab_to_filename_for_display (sal2
.symtab
),
13348 file_name_style
.style ());
13351 if (uiout
->is_mi_like_p ())
13353 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13355 uiout
->field_string ("fullname", fullname
);
13358 uiout
->field_signed ("line", sal2
.line
);
13359 uiout
->text ("\n");
13361 b
->loc
->line_number
= sal2
.line
;
13362 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13364 b
->location
.reset (NULL
);
13365 initialize_explicit_location (&explicit_loc
);
13366 explicit_loc
.source_filename
13367 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13368 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13369 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13370 b
->location
= new_explicit_location (&explicit_loc
);
13372 /* Might be nice to check if function changed, and warn if
13379 /* Returns 1 iff locations A and B are sufficiently same that
13380 we don't need to report breakpoint as changed. */
13383 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13387 if (a
->address
!= b
->address
)
13390 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13393 if (a
->enabled
!= b
->enabled
)
13400 if ((a
== NULL
) != (b
== NULL
))
13406 /* Split all locations of B that are bound to PSPACE out of B's
13407 location list to a separate list and return that list's head. If
13408 PSPACE is NULL, hoist out all locations of B. */
13410 static struct bp_location
*
13411 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13413 struct bp_location head
;
13414 struct bp_location
*i
= b
->loc
;
13415 struct bp_location
**i_link
= &b
->loc
;
13416 struct bp_location
*hoisted
= &head
;
13418 if (pspace
== NULL
)
13429 if (i
->pspace
== pspace
)
13444 /* Create new breakpoint locations for B (a hardware or software
13445 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13446 zero, then B is a ranged breakpoint. Only recreates locations for
13447 FILTER_PSPACE. Locations of other program spaces are left
13451 update_breakpoint_locations (struct breakpoint
*b
,
13452 struct program_space
*filter_pspace
,
13453 gdb::array_view
<const symtab_and_line
> sals
,
13454 gdb::array_view
<const symtab_and_line
> sals_end
)
13456 struct bp_location
*existing_locations
;
13458 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13460 /* Ranged breakpoints have only one start location and one end
13462 b
->enable_state
= bp_disabled
;
13463 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13464 "multiple locations found\n"),
13469 /* If there's no new locations, and all existing locations are
13470 pending, don't do anything. This optimizes the common case where
13471 all locations are in the same shared library, that was unloaded.
13472 We'd like to retain the location, so that when the library is
13473 loaded again, we don't loose the enabled/disabled status of the
13474 individual locations. */
13475 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13478 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13480 for (const auto &sal
: sals
)
13482 struct bp_location
*new_loc
;
13484 switch_to_program_space_and_thread (sal
.pspace
);
13486 new_loc
= add_location_to_breakpoint (b
, &sal
);
13488 /* Reparse conditions, they might contain references to the
13490 if (b
->cond_string
!= NULL
)
13494 s
= b
->cond_string
;
13497 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13498 block_for_pc (sal
.pc
),
13501 catch (const gdb_exception_error
&e
)
13503 warning (_("failed to reevaluate condition "
13504 "for breakpoint %d: %s"),
13505 b
->number
, e
.what ());
13506 new_loc
->enabled
= 0;
13510 if (!sals_end
.empty ())
13512 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13514 new_loc
->length
= end
- sals
[0].pc
+ 1;
13518 /* If possible, carry over 'disable' status from existing
13521 struct bp_location
*e
= existing_locations
;
13522 /* If there are multiple breakpoints with the same function name,
13523 e.g. for inline functions, comparing function names won't work.
13524 Instead compare pc addresses; this is just a heuristic as things
13525 may have moved, but in practice it gives the correct answer
13526 often enough until a better solution is found. */
13527 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13529 for (; e
; e
= e
->next
)
13531 if (!e
->enabled
&& e
->function_name
)
13533 struct bp_location
*l
= b
->loc
;
13534 if (have_ambiguous_names
)
13536 for (; l
; l
= l
->next
)
13537 if (breakpoint_locations_match (e
, l
))
13545 for (; l
; l
= l
->next
)
13546 if (l
->function_name
13547 && strcmp (e
->function_name
, l
->function_name
) == 0)
13557 if (!locations_are_equal (existing_locations
, b
->loc
))
13558 gdb::observers::breakpoint_modified
.notify (b
);
13561 /* Find the SaL locations corresponding to the given LOCATION.
13562 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13564 static std::vector
<symtab_and_line
>
13565 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13566 struct program_space
*search_pspace
, int *found
)
13568 struct gdb_exception exception
;
13570 gdb_assert (b
->ops
!= NULL
);
13572 std::vector
<symtab_and_line
> sals
;
13576 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13578 catch (gdb_exception_error
&e
)
13580 int not_found_and_ok
= 0;
13582 /* For pending breakpoints, it's expected that parsing will
13583 fail until the right shared library is loaded. User has
13584 already told to create pending breakpoints and don't need
13585 extra messages. If breakpoint is in bp_shlib_disabled
13586 state, then user already saw the message about that
13587 breakpoint being disabled, and don't want to see more
13589 if (e
.error
== NOT_FOUND_ERROR
13590 && (b
->condition_not_parsed
13592 && search_pspace
!= NULL
13593 && b
->loc
->pspace
!= search_pspace
)
13594 || (b
->loc
&& b
->loc
->shlib_disabled
)
13595 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13596 || b
->enable_state
== bp_disabled
))
13597 not_found_and_ok
= 1;
13599 if (!not_found_and_ok
)
13601 /* We surely don't want to warn about the same breakpoint
13602 10 times. One solution, implemented here, is disable
13603 the breakpoint on error. Another solution would be to
13604 have separate 'warning emitted' flag. Since this
13605 happens only when a binary has changed, I don't know
13606 which approach is better. */
13607 b
->enable_state
= bp_disabled
;
13611 exception
= std::move (e
);
13614 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13616 for (auto &sal
: sals
)
13617 resolve_sal_pc (&sal
);
13618 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13620 char *cond_string
, *extra_string
;
13623 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
13624 &cond_string
, &thread
, &task
,
13626 gdb_assert (b
->cond_string
== NULL
);
13628 b
->cond_string
= cond_string
;
13629 b
->thread
= thread
;
13633 xfree (b
->extra_string
);
13634 b
->extra_string
= extra_string
;
13636 b
->condition_not_parsed
= 0;
13639 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13640 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13650 /* The default re_set method, for typical hardware or software
13651 breakpoints. Reevaluate the breakpoint and recreate its
13655 breakpoint_re_set_default (struct breakpoint
*b
)
13657 struct program_space
*filter_pspace
= current_program_space
;
13658 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13661 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13662 filter_pspace
, &found
);
13664 expanded
= std::move (sals
);
13666 if (b
->location_range_end
!= NULL
)
13668 std::vector
<symtab_and_line
> sals_end
13669 = location_to_sals (b
, b
->location_range_end
.get (),
13670 filter_pspace
, &found
);
13672 expanded_end
= std::move (sals_end
);
13675 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13678 /* Default method for creating SALs from an address string. It basically
13679 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13682 create_sals_from_location_default (const struct event_location
*location
,
13683 struct linespec_result
*canonical
,
13684 enum bptype type_wanted
)
13686 parse_breakpoint_sals (location
, canonical
);
13689 /* Call create_breakpoints_sal for the given arguments. This is the default
13690 function for the `create_breakpoints_sal' method of
13694 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13695 struct linespec_result
*canonical
,
13696 gdb::unique_xmalloc_ptr
<char> cond_string
,
13697 gdb::unique_xmalloc_ptr
<char> extra_string
,
13698 enum bptype type_wanted
,
13699 enum bpdisp disposition
,
13701 int task
, int ignore_count
,
13702 const struct breakpoint_ops
*ops
,
13703 int from_tty
, int enabled
,
13704 int internal
, unsigned flags
)
13706 create_breakpoints_sal (gdbarch
, canonical
,
13707 std::move (cond_string
),
13708 std::move (extra_string
),
13709 type_wanted
, disposition
,
13710 thread
, task
, ignore_count
, ops
, from_tty
,
13711 enabled
, internal
, flags
);
13714 /* Decode the line represented by S by calling decode_line_full. This is the
13715 default function for the `decode_location' method of breakpoint_ops. */
13717 static std::vector
<symtab_and_line
>
13718 decode_location_default (struct breakpoint
*b
,
13719 const struct event_location
*location
,
13720 struct program_space
*search_pspace
)
13722 struct linespec_result canonical
;
13724 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13725 NULL
, 0, &canonical
, multiple_symbols_all
,
13728 /* We should get 0 or 1 resulting SALs. */
13729 gdb_assert (canonical
.lsals
.size () < 2);
13731 if (!canonical
.lsals
.empty ())
13733 const linespec_sals
&lsal
= canonical
.lsals
[0];
13734 return std::move (lsal
.sals
);
13739 /* Reset a breakpoint. */
13742 breakpoint_re_set_one (breakpoint
*b
)
13744 input_radix
= b
->input_radix
;
13745 set_language (b
->language
);
13747 b
->ops
->re_set (b
);
13750 /* Re-set breakpoint locations for the current program space.
13751 Locations bound to other program spaces are left untouched. */
13754 breakpoint_re_set (void)
13756 struct breakpoint
*b
, *b_tmp
;
13759 scoped_restore_current_language save_language
;
13760 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13761 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13763 /* breakpoint_re_set_one sets the current_language to the language
13764 of the breakpoint it is resetting (see prepare_re_set_context)
13765 before re-evaluating the breakpoint's location. This change can
13766 unfortunately get undone by accident if the language_mode is set
13767 to auto, and we either switch frames, or more likely in this context,
13768 we select the current frame.
13770 We prevent this by temporarily turning the language_mode to
13771 language_mode_manual. We restore it once all breakpoints
13772 have been reset. */
13773 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13774 language_mode
= language_mode_manual
;
13776 /* Note: we must not try to insert locations until after all
13777 breakpoints have been re-set. Otherwise, e.g., when re-setting
13778 breakpoint 1, we'd insert the locations of breakpoint 2, which
13779 hadn't been re-set yet, and thus may have stale locations. */
13781 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13785 breakpoint_re_set_one (b
);
13787 catch (const gdb_exception
&ex
)
13789 exception_fprintf (gdb_stderr
, ex
,
13790 "Error in re-setting breakpoint %d: ",
13795 jit_breakpoint_re_set ();
13798 create_overlay_event_breakpoint ();
13799 create_longjmp_master_breakpoint ();
13800 create_std_terminate_master_breakpoint ();
13801 create_exception_master_breakpoint ();
13803 /* Now we can insert. */
13804 update_global_location_list (UGLL_MAY_INSERT
);
13807 /* Reset the thread number of this breakpoint:
13809 - If the breakpoint is for all threads, leave it as-is.
13810 - Else, reset it to the current thread for inferior_ptid. */
13812 breakpoint_re_set_thread (struct breakpoint
*b
)
13814 if (b
->thread
!= -1)
13816 b
->thread
= inferior_thread ()->global_num
;
13818 /* We're being called after following a fork. The new fork is
13819 selected as current, and unless this was a vfork will have a
13820 different program space from the original thread. Reset that
13822 b
->loc
->pspace
= current_program_space
;
13826 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13827 If from_tty is nonzero, it prints a message to that effect,
13828 which ends with a period (no newline). */
13831 set_ignore_count (int bptnum
, int count
, int from_tty
)
13833 struct breakpoint
*b
;
13838 ALL_BREAKPOINTS (b
)
13839 if (b
->number
== bptnum
)
13841 if (is_tracepoint (b
))
13843 if (from_tty
&& count
!= 0)
13844 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13849 b
->ignore_count
= count
;
13853 printf_filtered (_("Will stop next time "
13854 "breakpoint %d is reached."),
13856 else if (count
== 1)
13857 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13860 printf_filtered (_("Will ignore next %d "
13861 "crossings of breakpoint %d."),
13864 gdb::observers::breakpoint_modified
.notify (b
);
13868 error (_("No breakpoint number %d."), bptnum
);
13871 /* Command to set ignore-count of breakpoint N to COUNT. */
13874 ignore_command (const char *args
, int from_tty
)
13876 const char *p
= args
;
13880 error_no_arg (_("a breakpoint number"));
13882 num
= get_number (&p
);
13884 error (_("bad breakpoint number: '%s'"), args
);
13886 error (_("Second argument (specified ignore-count) is missing."));
13888 set_ignore_count (num
,
13889 longest_to_int (value_as_long (parse_and_eval (p
))),
13892 printf_filtered ("\n");
13896 /* Call FUNCTION on each of the breakpoints with numbers in the range
13897 defined by BP_NUM_RANGE (an inclusive range). */
13900 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13901 gdb::function_view
<void (breakpoint
*)> function
)
13903 if (bp_num_range
.first
== 0)
13905 warning (_("bad breakpoint number at or near '%d'"),
13906 bp_num_range
.first
);
13910 struct breakpoint
*b
, *tmp
;
13912 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13914 bool match
= false;
13916 ALL_BREAKPOINTS_SAFE (b
, tmp
)
13917 if (b
->number
== i
)
13924 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
13929 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13933 map_breakpoint_numbers (const char *args
,
13934 gdb::function_view
<void (breakpoint
*)> function
)
13936 if (args
== NULL
|| *args
== '\0')
13937 error_no_arg (_("one or more breakpoint numbers"));
13939 number_or_range_parser
parser (args
);
13941 while (!parser
.finished ())
13943 int num
= parser
.get_number ();
13944 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13948 /* Return the breakpoint location structure corresponding to the
13949 BP_NUM and LOC_NUM values. */
13951 static struct bp_location
*
13952 find_location_by_number (int bp_num
, int loc_num
)
13954 struct breakpoint
*b
;
13956 ALL_BREAKPOINTS (b
)
13957 if (b
->number
== bp_num
)
13962 if (!b
|| b
->number
!= bp_num
)
13963 error (_("Bad breakpoint number '%d'"), bp_num
);
13966 error (_("Bad breakpoint location number '%d'"), loc_num
);
13969 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13970 if (++n
== loc_num
)
13973 error (_("Bad breakpoint location number '%d'"), loc_num
);
13976 /* Modes of operation for extract_bp_num. */
13977 enum class extract_bp_kind
13979 /* Extracting a breakpoint number. */
13982 /* Extracting a location number. */
13986 /* Extract a breakpoint or location number (as determined by KIND)
13987 from the string starting at START. TRAILER is a character which
13988 can be found after the number. If you don't want a trailer, use
13989 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13990 string. This always returns a positive integer. */
13993 extract_bp_num (extract_bp_kind kind
, const char *start
,
13994 int trailer
, const char **end_out
= NULL
)
13996 const char *end
= start
;
13997 int num
= get_number_trailer (&end
, trailer
);
13999 error (kind
== extract_bp_kind::bp
14000 ? _("Negative breakpoint number '%.*s'")
14001 : _("Negative breakpoint location number '%.*s'"),
14002 int (end
- start
), start
);
14004 error (kind
== extract_bp_kind::bp
14005 ? _("Bad breakpoint number '%.*s'")
14006 : _("Bad breakpoint location number '%.*s'"),
14007 int (end
- start
), start
);
14009 if (end_out
!= NULL
)
14014 /* Extract a breakpoint or location range (as determined by KIND) in
14015 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14016 representing the (inclusive) range. The returned pair's elements
14017 are always positive integers. */
14019 static std::pair
<int, int>
14020 extract_bp_or_bp_range (extract_bp_kind kind
,
14021 const std::string
&arg
,
14022 std::string::size_type arg_offset
)
14024 std::pair
<int, int> range
;
14025 const char *bp_loc
= &arg
[arg_offset
];
14026 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14027 if (dash
!= std::string::npos
)
14029 /* bp_loc is a range (x-z). */
14030 if (arg
.length () == dash
+ 1)
14031 error (kind
== extract_bp_kind::bp
14032 ? _("Bad breakpoint number at or near: '%s'")
14033 : _("Bad breakpoint location number at or near: '%s'"),
14037 const char *start_first
= bp_loc
;
14038 const char *start_second
= &arg
[dash
+ 1];
14039 range
.first
= extract_bp_num (kind
, start_first
, '-');
14040 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14042 if (range
.first
> range
.second
)
14043 error (kind
== extract_bp_kind::bp
14044 ? _("Inverted breakpoint range at '%.*s'")
14045 : _("Inverted breakpoint location range at '%.*s'"),
14046 int (end
- start_first
), start_first
);
14050 /* bp_loc is a single value. */
14051 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14052 range
.second
= range
.first
;
14057 /* Extract the breakpoint/location range specified by ARG. Returns
14058 the breakpoint range in BP_NUM_RANGE, and the location range in
14061 ARG may be in any of the following forms:
14063 x where 'x' is a breakpoint number.
14064 x-y where 'x' and 'y' specify a breakpoint numbers range.
14065 x.y where 'x' is a breakpoint number and 'y' a location number.
14066 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14067 location number range.
14071 extract_bp_number_and_location (const std::string
&arg
,
14072 std::pair
<int, int> &bp_num_range
,
14073 std::pair
<int, int> &bp_loc_range
)
14075 std::string::size_type dot
= arg
.find ('.');
14077 if (dot
!= std::string::npos
)
14079 /* Handle 'x.y' and 'x.y-z' cases. */
14081 if (arg
.length () == dot
+ 1 || dot
== 0)
14082 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14085 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14086 bp_num_range
.second
= bp_num_range
.first
;
14088 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14093 /* Handle x and x-y cases. */
14095 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14096 bp_loc_range
.first
= 0;
14097 bp_loc_range
.second
= 0;
14101 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14102 specifies whether to enable or disable. */
14105 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14107 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14110 if (loc
->enabled
!= enable
)
14112 loc
->enabled
= enable
;
14113 mark_breakpoint_location_modified (loc
);
14115 if (target_supports_enable_disable_tracepoint ()
14116 && current_trace_status ()->running
&& loc
->owner
14117 && is_tracepoint (loc
->owner
))
14118 target_disable_tracepoint (loc
);
14120 update_global_location_list (UGLL_DONT_INSERT
);
14122 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14125 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14126 number of the breakpoint, and BP_LOC_RANGE specifies the
14127 (inclusive) range of location numbers of that breakpoint to
14128 enable/disable. ENABLE specifies whether to enable or disable the
14132 enable_disable_breakpoint_location_range (int bp_num
,
14133 std::pair
<int, int> &bp_loc_range
,
14136 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14137 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14140 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14141 If from_tty is nonzero, it prints a message to that effect,
14142 which ends with a period (no newline). */
14145 disable_breakpoint (struct breakpoint
*bpt
)
14147 /* Never disable a watchpoint scope breakpoint; we want to
14148 hit them when we leave scope so we can delete both the
14149 watchpoint and its scope breakpoint at that time. */
14150 if (bpt
->type
== bp_watchpoint_scope
)
14153 bpt
->enable_state
= bp_disabled
;
14155 /* Mark breakpoint locations modified. */
14156 mark_breakpoint_modified (bpt
);
14158 if (target_supports_enable_disable_tracepoint ()
14159 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14161 struct bp_location
*location
;
14163 for (location
= bpt
->loc
; location
; location
= location
->next
)
14164 target_disable_tracepoint (location
);
14167 update_global_location_list (UGLL_DONT_INSERT
);
14169 gdb::observers::breakpoint_modified
.notify (bpt
);
14172 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14173 specified in ARGS. ARGS may be in any of the formats handled by
14174 extract_bp_number_and_location. ENABLE specifies whether to enable
14175 or disable the breakpoints/locations. */
14178 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14182 struct breakpoint
*bpt
;
14184 ALL_BREAKPOINTS (bpt
)
14185 if (user_breakpoint_p (bpt
))
14188 enable_breakpoint (bpt
);
14190 disable_breakpoint (bpt
);
14195 std::string num
= extract_arg (&args
);
14197 while (!num
.empty ())
14199 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14201 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14203 if (bp_loc_range
.first
== bp_loc_range
.second
14204 && bp_loc_range
.first
== 0)
14206 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14207 map_breakpoint_number_range (bp_num_range
,
14209 ? enable_breakpoint
14210 : disable_breakpoint
);
14214 /* Handle breakpoint ids with formats 'x.y' or
14216 enable_disable_breakpoint_location_range
14217 (bp_num_range
.first
, bp_loc_range
, enable
);
14219 num
= extract_arg (&args
);
14224 /* The disable command disables the specified breakpoints/locations
14225 (or all defined breakpoints) so they're no longer effective in
14226 stopping the inferior. ARGS may be in any of the forms defined in
14227 extract_bp_number_and_location. */
14230 disable_command (const char *args
, int from_tty
)
14232 enable_disable_command (args
, from_tty
, false);
14236 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14239 int target_resources_ok
;
14241 if (bpt
->type
== bp_hardware_breakpoint
)
14244 i
= hw_breakpoint_used_count ();
14245 target_resources_ok
=
14246 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14248 if (target_resources_ok
== 0)
14249 error (_("No hardware breakpoint support in the target."));
14250 else if (target_resources_ok
< 0)
14251 error (_("Hardware breakpoints used exceeds limit."));
14254 if (is_watchpoint (bpt
))
14256 /* Initialize it just to avoid a GCC false warning. */
14257 enum enable_state orig_enable_state
= bp_disabled
;
14261 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14263 orig_enable_state
= bpt
->enable_state
;
14264 bpt
->enable_state
= bp_enabled
;
14265 update_watchpoint (w
, 1 /* reparse */);
14267 catch (const gdb_exception
&e
)
14269 bpt
->enable_state
= orig_enable_state
;
14270 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14276 bpt
->enable_state
= bp_enabled
;
14278 /* Mark breakpoint locations modified. */
14279 mark_breakpoint_modified (bpt
);
14281 if (target_supports_enable_disable_tracepoint ()
14282 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14284 struct bp_location
*location
;
14286 for (location
= bpt
->loc
; location
; location
= location
->next
)
14287 target_enable_tracepoint (location
);
14290 bpt
->disposition
= disposition
;
14291 bpt
->enable_count
= count
;
14292 update_global_location_list (UGLL_MAY_INSERT
);
14294 gdb::observers::breakpoint_modified
.notify (bpt
);
14299 enable_breakpoint (struct breakpoint
*bpt
)
14301 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14304 /* The enable command enables the specified breakpoints/locations (or
14305 all defined breakpoints) so they once again become (or continue to
14306 be) effective in stopping the inferior. ARGS may be in any of the
14307 forms defined in extract_bp_number_and_location. */
14310 enable_command (const char *args
, int from_tty
)
14312 enable_disable_command (args
, from_tty
, true);
14316 enable_once_command (const char *args
, int from_tty
)
14318 map_breakpoint_numbers
14319 (args
, [&] (breakpoint
*b
)
14321 iterate_over_related_breakpoints
14322 (b
, [&] (breakpoint
*bpt
)
14324 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14330 enable_count_command (const char *args
, int from_tty
)
14335 error_no_arg (_("hit count"));
14337 count
= get_number (&args
);
14339 map_breakpoint_numbers
14340 (args
, [&] (breakpoint
*b
)
14342 iterate_over_related_breakpoints
14343 (b
, [&] (breakpoint
*bpt
)
14345 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14351 enable_delete_command (const char *args
, int from_tty
)
14353 map_breakpoint_numbers
14354 (args
, [&] (breakpoint
*b
)
14356 iterate_over_related_breakpoints
14357 (b
, [&] (breakpoint
*bpt
)
14359 enable_breakpoint_disp (bpt
, disp_del
, 1);
14365 set_breakpoint_cmd (const char *args
, int from_tty
)
14370 show_breakpoint_cmd (const char *args
, int from_tty
)
14374 /* Invalidate last known value of any hardware watchpoint if
14375 the memory which that value represents has been written to by
14379 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14380 CORE_ADDR addr
, ssize_t len
,
14381 const bfd_byte
*data
)
14383 struct breakpoint
*bp
;
14385 ALL_BREAKPOINTS (bp
)
14386 if (bp
->enable_state
== bp_enabled
14387 && bp
->type
== bp_hardware_watchpoint
)
14389 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14391 if (wp
->val_valid
&& wp
->val
!= nullptr)
14393 struct bp_location
*loc
;
14395 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14396 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14397 && loc
->address
+ loc
->length
> addr
14398 && addr
+ len
> loc
->address
)
14401 wp
->val_valid
= false;
14407 /* Create and insert a breakpoint for software single step. */
14410 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14411 const address_space
*aspace
,
14414 struct thread_info
*tp
= inferior_thread ();
14415 struct symtab_and_line sal
;
14416 CORE_ADDR pc
= next_pc
;
14418 if (tp
->control
.single_step_breakpoints
== NULL
)
14420 tp
->control
.single_step_breakpoints
14421 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14424 sal
= find_pc_line (pc
, 0);
14426 sal
.section
= find_pc_overlay (pc
);
14427 sal
.explicit_pc
= 1;
14428 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14430 update_global_location_list (UGLL_INSERT
);
14433 /* Insert single step breakpoints according to the current state. */
14436 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14438 struct regcache
*regcache
= get_current_regcache ();
14439 std::vector
<CORE_ADDR
> next_pcs
;
14441 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14443 if (!next_pcs
.empty ())
14445 struct frame_info
*frame
= get_current_frame ();
14446 const address_space
*aspace
= get_frame_address_space (frame
);
14448 for (CORE_ADDR pc
: next_pcs
)
14449 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14457 /* See breakpoint.h. */
14460 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14461 const address_space
*aspace
,
14464 struct bp_location
*loc
;
14466 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14468 && breakpoint_location_address_match (loc
, aspace
, pc
))
14474 /* Check whether a software single-step breakpoint is inserted at
14478 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14481 struct breakpoint
*bpt
;
14483 ALL_BREAKPOINTS (bpt
)
14485 if (bpt
->type
== bp_single_step
14486 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14492 /* Tracepoint-specific operations. */
14494 /* Set tracepoint count to NUM. */
14496 set_tracepoint_count (int num
)
14498 tracepoint_count
= num
;
14499 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14503 trace_command (const char *arg
, int from_tty
)
14505 event_location_up location
= string_to_event_location (&arg
,
14507 const struct breakpoint_ops
*ops
= breakpoint_ops_for_event_location
14508 (location
.get (), true /* is_tracepoint */);
14510 create_breakpoint (get_current_arch (),
14512 NULL
, 0, arg
, 1 /* parse arg */,
14514 bp_tracepoint
/* type_wanted */,
14515 0 /* Ignore count */,
14516 pending_break_support
,
14520 0 /* internal */, 0);
14524 ftrace_command (const char *arg
, int from_tty
)
14526 event_location_up location
= string_to_event_location (&arg
,
14528 create_breakpoint (get_current_arch (),
14530 NULL
, 0, arg
, 1 /* parse arg */,
14532 bp_fast_tracepoint
/* type_wanted */,
14533 0 /* Ignore count */,
14534 pending_break_support
,
14535 &tracepoint_breakpoint_ops
,
14538 0 /* internal */, 0);
14541 /* strace command implementation. Creates a static tracepoint. */
14544 strace_command (const char *arg
, int from_tty
)
14546 struct breakpoint_ops
*ops
;
14547 event_location_up location
;
14549 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14550 or with a normal static tracepoint. */
14551 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14553 ops
= &strace_marker_breakpoint_ops
;
14554 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14558 ops
= &tracepoint_breakpoint_ops
;
14559 location
= string_to_event_location (&arg
, current_language
);
14562 create_breakpoint (get_current_arch (),
14564 NULL
, 0, arg
, 1 /* parse arg */,
14566 bp_static_tracepoint
/* type_wanted */,
14567 0 /* Ignore count */,
14568 pending_break_support
,
14572 0 /* internal */, 0);
14575 /* Set up a fake reader function that gets command lines from a linked
14576 list that was acquired during tracepoint uploading. */
14578 static struct uploaded_tp
*this_utp
;
14579 static int next_cmd
;
14582 read_uploaded_action (void)
14584 char *rslt
= nullptr;
14586 if (next_cmd
< this_utp
->cmd_strings
.size ())
14588 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14595 /* Given information about a tracepoint as recorded on a target (which
14596 can be either a live system or a trace file), attempt to create an
14597 equivalent GDB tracepoint. This is not a reliable process, since
14598 the target does not necessarily have all the information used when
14599 the tracepoint was originally defined. */
14601 struct tracepoint
*
14602 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14604 const char *addr_str
;
14605 char small_buf
[100];
14606 struct tracepoint
*tp
;
14608 if (utp
->at_string
)
14609 addr_str
= utp
->at_string
.get ();
14612 /* In the absence of a source location, fall back to raw
14613 address. Since there is no way to confirm that the address
14614 means the same thing as when the trace was started, warn the
14616 warning (_("Uploaded tracepoint %d has no "
14617 "source location, using raw address"),
14619 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14620 addr_str
= small_buf
;
14623 /* There's not much we can do with a sequence of bytecodes. */
14624 if (utp
->cond
&& !utp
->cond_string
)
14625 warning (_("Uploaded tracepoint %d condition "
14626 "has no source form, ignoring it"),
14629 event_location_up location
= string_to_event_location (&addr_str
,
14631 if (!create_breakpoint (get_current_arch (),
14633 utp
->cond_string
.get (), -1, addr_str
,
14634 0 /* parse cond/thread */,
14636 utp
->type
/* type_wanted */,
14637 0 /* Ignore count */,
14638 pending_break_support
,
14639 &tracepoint_breakpoint_ops
,
14641 utp
->enabled
/* enabled */,
14643 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14646 /* Get the tracepoint we just created. */
14647 tp
= get_tracepoint (tracepoint_count
);
14648 gdb_assert (tp
!= NULL
);
14652 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14655 trace_pass_command (small_buf
, 0);
14658 /* If we have uploaded versions of the original commands, set up a
14659 special-purpose "reader" function and call the usual command line
14660 reader, then pass the result to the breakpoint command-setting
14662 if (!utp
->cmd_strings
.empty ())
14664 counted_command_line cmd_list
;
14669 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14671 breakpoint_set_commands (tp
, std::move (cmd_list
));
14673 else if (!utp
->actions
.empty ()
14674 || !utp
->step_actions
.empty ())
14675 warning (_("Uploaded tracepoint %d actions "
14676 "have no source form, ignoring them"),
14679 /* Copy any status information that might be available. */
14680 tp
->hit_count
= utp
->hit_count
;
14681 tp
->traceframe_usage
= utp
->traceframe_usage
;
14686 /* Print information on tracepoint number TPNUM_EXP, or all if
14690 info_tracepoints_command (const char *args
, int from_tty
)
14692 struct ui_out
*uiout
= current_uiout
;
14695 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14697 if (num_printed
== 0)
14699 if (args
== NULL
|| *args
== '\0')
14700 uiout
->message ("No tracepoints.\n");
14702 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14705 default_collect_info ();
14708 /* The 'enable trace' command enables tracepoints.
14709 Not supported by all targets. */
14711 enable_trace_command (const char *args
, int from_tty
)
14713 enable_command (args
, from_tty
);
14716 /* The 'disable trace' command disables tracepoints.
14717 Not supported by all targets. */
14719 disable_trace_command (const char *args
, int from_tty
)
14721 disable_command (args
, from_tty
);
14724 /* Remove a tracepoint (or all if no argument). */
14726 delete_trace_command (const char *arg
, int from_tty
)
14728 struct breakpoint
*b
, *b_tmp
;
14734 int breaks_to_delete
= 0;
14736 /* Delete all breakpoints if no argument.
14737 Do not delete internal or call-dummy breakpoints, these
14738 have to be deleted with an explicit breakpoint number
14740 ALL_TRACEPOINTS (b
)
14741 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14743 breaks_to_delete
= 1;
14747 /* Ask user only if there are some breakpoints to delete. */
14749 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14751 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14752 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14753 delete_breakpoint (b
);
14757 map_breakpoint_numbers
14758 (arg
, [&] (breakpoint
*br
)
14760 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14764 /* Helper function for trace_pass_command. */
14767 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14769 tp
->pass_count
= count
;
14770 gdb::observers::breakpoint_modified
.notify (tp
);
14772 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14773 tp
->number
, count
);
14776 /* Set passcount for tracepoint.
14778 First command argument is passcount, second is tracepoint number.
14779 If tracepoint number omitted, apply to most recently defined.
14780 Also accepts special argument "all". */
14783 trace_pass_command (const char *args
, int from_tty
)
14785 struct tracepoint
*t1
;
14788 if (args
== 0 || *args
== 0)
14789 error (_("passcount command requires an "
14790 "argument (count + optional TP num)"));
14792 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14794 args
= skip_spaces (args
);
14795 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14797 struct breakpoint
*b
;
14799 args
+= 3; /* Skip special argument "all". */
14801 error (_("Junk at end of arguments."));
14803 ALL_TRACEPOINTS (b
)
14805 t1
= (struct tracepoint
*) b
;
14806 trace_pass_set_count (t1
, count
, from_tty
);
14809 else if (*args
== '\0')
14811 t1
= get_tracepoint_by_number (&args
, NULL
);
14813 trace_pass_set_count (t1
, count
, from_tty
);
14817 number_or_range_parser
parser (args
);
14818 while (!parser
.finished ())
14820 t1
= get_tracepoint_by_number (&args
, &parser
);
14822 trace_pass_set_count (t1
, count
, from_tty
);
14827 struct tracepoint
*
14828 get_tracepoint (int num
)
14830 struct breakpoint
*t
;
14832 ALL_TRACEPOINTS (t
)
14833 if (t
->number
== num
)
14834 return (struct tracepoint
*) t
;
14839 /* Find the tracepoint with the given target-side number (which may be
14840 different from the tracepoint number after disconnecting and
14843 struct tracepoint
*
14844 get_tracepoint_by_number_on_target (int num
)
14846 struct breakpoint
*b
;
14848 ALL_TRACEPOINTS (b
)
14850 struct tracepoint
*t
= (struct tracepoint
*) b
;
14852 if (t
->number_on_target
== num
)
14859 /* Utility: parse a tracepoint number and look it up in the list.
14860 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14861 If the argument is missing, the most recent tracepoint
14862 (tracepoint_count) is returned. */
14864 struct tracepoint
*
14865 get_tracepoint_by_number (const char **arg
,
14866 number_or_range_parser
*parser
)
14868 struct breakpoint
*t
;
14870 const char *instring
= arg
== NULL
? NULL
: *arg
;
14872 if (parser
!= NULL
)
14874 gdb_assert (!parser
->finished ());
14875 tpnum
= parser
->get_number ();
14877 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14878 tpnum
= tracepoint_count
;
14880 tpnum
= get_number (arg
);
14884 if (instring
&& *instring
)
14885 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14888 printf_filtered (_("No previous tracepoint\n"));
14892 ALL_TRACEPOINTS (t
)
14893 if (t
->number
== tpnum
)
14895 return (struct tracepoint
*) t
;
14898 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
14903 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14905 if (b
->thread
!= -1)
14906 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
14909 fprintf_unfiltered (fp
, " task %d", b
->task
);
14911 fprintf_unfiltered (fp
, "\n");
14914 /* Save information on user settable breakpoints (watchpoints, etc) to
14915 a new script file named FILENAME. If FILTER is non-NULL, call it
14916 on each breakpoint and only include the ones for which it returns
14920 save_breakpoints (const char *filename
, int from_tty
,
14921 bool (*filter
) (const struct breakpoint
*))
14923 struct breakpoint
*tp
;
14925 int extra_trace_bits
= 0;
14927 if (filename
== 0 || *filename
== 0)
14928 error (_("Argument required (file name in which to save)"));
14930 /* See if we have anything to save. */
14931 ALL_BREAKPOINTS (tp
)
14933 /* Skip internal and momentary breakpoints. */
14934 if (!user_breakpoint_p (tp
))
14937 /* If we have a filter, only save the breakpoints it accepts. */
14938 if (filter
&& !filter (tp
))
14943 if (is_tracepoint (tp
))
14945 extra_trace_bits
= 1;
14947 /* We can stop searching. */
14954 warning (_("Nothing to save."));
14958 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14962 if (!fp
.open (expanded_filename
.get (), "w"))
14963 error (_("Unable to open file '%s' for saving (%s)"),
14964 expanded_filename
.get (), safe_strerror (errno
));
14966 if (extra_trace_bits
)
14967 save_trace_state_variables (&fp
);
14969 ALL_BREAKPOINTS (tp
)
14971 /* Skip internal and momentary breakpoints. */
14972 if (!user_breakpoint_p (tp
))
14975 /* If we have a filter, only save the breakpoints it accepts. */
14976 if (filter
&& !filter (tp
))
14979 tp
->ops
->print_recreate (tp
, &fp
);
14981 /* Note, we can't rely on tp->number for anything, as we can't
14982 assume the recreated breakpoint numbers will match. Use $bpnum
14985 if (tp
->cond_string
)
14986 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
14988 if (tp
->ignore_count
)
14989 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14991 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
14993 fp
.puts (" commands\n");
14995 current_uiout
->redirect (&fp
);
14998 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15000 catch (const gdb_exception
&ex
)
15002 current_uiout
->redirect (NULL
);
15006 current_uiout
->redirect (NULL
);
15007 fp
.puts (" end\n");
15010 if (tp
->enable_state
== bp_disabled
)
15011 fp
.puts ("disable $bpnum\n");
15013 /* If this is a multi-location breakpoint, check if the locations
15014 should be individually disabled. Watchpoint locations are
15015 special, and not user visible. */
15016 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15018 struct bp_location
*loc
;
15021 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15023 fp
.printf ("disable $bpnum.%d\n", n
);
15027 if (extra_trace_bits
&& *default_collect
)
15028 fp
.printf ("set default-collect %s\n", default_collect
);
15031 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15034 /* The `save breakpoints' command. */
15037 save_breakpoints_command (const char *args
, int from_tty
)
15039 save_breakpoints (args
, from_tty
, NULL
);
15042 /* The `save tracepoints' command. */
15045 save_tracepoints_command (const char *args
, int from_tty
)
15047 save_breakpoints (args
, from_tty
, is_tracepoint
);
15050 /* Create a vector of all tracepoints. */
15052 std::vector
<breakpoint
*>
15053 all_tracepoints (void)
15055 std::vector
<breakpoint
*> tp_vec
;
15056 struct breakpoint
*tp
;
15058 ALL_TRACEPOINTS (tp
)
15060 tp_vec
.push_back (tp
);
15067 /* This help string is used to consolidate all the help string for specifying
15068 locations used by several commands. */
15070 #define LOCATION_HELP_STRING \
15071 "Linespecs are colon-separated lists of location parameters, such as\n\
15072 source filename, function name, label name, and line number.\n\
15073 Example: To specify the start of a label named \"the_top\" in the\n\
15074 function \"fact\" in the file \"factorial.c\", use\n\
15075 \"factorial.c:fact:the_top\".\n\
15077 Address locations begin with \"*\" and specify an exact address in the\n\
15078 program. Example: To specify the fourth byte past the start function\n\
15079 \"main\", use \"*main + 4\".\n\
15081 Explicit locations are similar to linespecs but use an option/argument\n\
15082 syntax to specify location parameters.\n\
15083 Example: To specify the start of the label named \"the_top\" in the\n\
15084 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15085 -function fact -label the_top\".\n\
15087 By default, a specified function is matched against the program's\n\
15088 functions in all scopes. For C++, this means in all namespaces and\n\
15089 classes. For Ada, this means in all packages. E.g., in C++,\n\
15090 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15091 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15092 specified name as a complete fully-qualified name instead."
15094 /* This help string is used for the break, hbreak, tbreak and thbreak
15095 commands. It is defined as a macro to prevent duplication.
15096 COMMAND should be a string constant containing the name of the
15099 #define BREAK_ARGS_HELP(command) \
15100 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15101 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15102 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15103 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15104 `-probe-dtrace' (for a DTrace probe).\n\
15105 LOCATION may be a linespec, address, or explicit location as described\n\
15108 With no LOCATION, uses current execution address of the selected\n\
15109 stack frame. This is useful for breaking on return to a stack frame.\n\
15111 THREADNUM is the number from \"info threads\".\n\
15112 CONDITION is a boolean expression.\n\
15113 \n" LOCATION_HELP_STRING "\n\n\
15114 Multiple breakpoints at one place are permitted, and useful if their\n\
15115 conditions are different.\n\
15117 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15119 /* List of subcommands for "catch". */
15120 static struct cmd_list_element
*catch_cmdlist
;
15122 /* List of subcommands for "tcatch". */
15123 static struct cmd_list_element
*tcatch_cmdlist
;
15126 add_catch_command (const char *name
, const char *docstring
,
15127 cmd_const_sfunc_ftype
*sfunc
,
15128 completer_ftype
*completer
,
15129 void *user_data_catch
,
15130 void *user_data_tcatch
)
15132 struct cmd_list_element
*command
;
15134 command
= add_cmd (name
, class_breakpoint
, docstring
,
15136 set_cmd_sfunc (command
, sfunc
);
15137 set_cmd_context (command
, user_data_catch
);
15138 set_cmd_completer (command
, completer
);
15140 command
= add_cmd (name
, class_breakpoint
, docstring
,
15142 set_cmd_sfunc (command
, sfunc
);
15143 set_cmd_context (command
, user_data_tcatch
);
15144 set_cmd_completer (command
, completer
);
15148 save_command (const char *arg
, int from_tty
)
15150 printf_unfiltered (_("\"save\" must be followed by "
15151 "the name of a save subcommand.\n"));
15152 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15155 struct breakpoint
*
15156 iterate_over_breakpoints (gdb::function_view
<bool (breakpoint
*)> callback
)
15158 struct breakpoint
*b
, *b_tmp
;
15160 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15169 /* Zero if any of the breakpoint's locations could be a location where
15170 functions have been inlined, nonzero otherwise. */
15173 is_non_inline_function (struct breakpoint
*b
)
15175 /* The shared library event breakpoint is set on the address of a
15176 non-inline function. */
15177 if (b
->type
== bp_shlib_event
)
15183 /* Nonzero if the specified PC cannot be a location where functions
15184 have been inlined. */
15187 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15188 const struct target_waitstatus
*ws
)
15190 struct breakpoint
*b
;
15191 struct bp_location
*bl
;
15193 ALL_BREAKPOINTS (b
)
15195 if (!is_non_inline_function (b
))
15198 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15200 if (!bl
->shlib_disabled
15201 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15209 /* Remove any references to OBJFILE which is going to be freed. */
15212 breakpoint_free_objfile (struct objfile
*objfile
)
15214 struct bp_location
**locp
, *loc
;
15216 ALL_BP_LOCATIONS (loc
, locp
)
15217 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15218 loc
->symtab
= NULL
;
15222 initialize_breakpoint_ops (void)
15224 static int initialized
= 0;
15226 struct breakpoint_ops
*ops
;
15232 /* The breakpoint_ops structure to be inherit by all kinds of
15233 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15234 internal and momentary breakpoints, etc.). */
15235 ops
= &bkpt_base_breakpoint_ops
;
15236 *ops
= base_breakpoint_ops
;
15237 ops
->re_set
= bkpt_re_set
;
15238 ops
->insert_location
= bkpt_insert_location
;
15239 ops
->remove_location
= bkpt_remove_location
;
15240 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15241 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15242 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15243 ops
->decode_location
= bkpt_decode_location
;
15245 /* The breakpoint_ops structure to be used in regular breakpoints. */
15246 ops
= &bkpt_breakpoint_ops
;
15247 *ops
= bkpt_base_breakpoint_ops
;
15248 ops
->re_set
= bkpt_re_set
;
15249 ops
->resources_needed
= bkpt_resources_needed
;
15250 ops
->print_it
= bkpt_print_it
;
15251 ops
->print_mention
= bkpt_print_mention
;
15252 ops
->print_recreate
= bkpt_print_recreate
;
15254 /* Ranged breakpoints. */
15255 ops
= &ranged_breakpoint_ops
;
15256 *ops
= bkpt_breakpoint_ops
;
15257 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15258 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15259 ops
->print_it
= print_it_ranged_breakpoint
;
15260 ops
->print_one
= print_one_ranged_breakpoint
;
15261 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15262 ops
->print_mention
= print_mention_ranged_breakpoint
;
15263 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15265 /* Internal breakpoints. */
15266 ops
= &internal_breakpoint_ops
;
15267 *ops
= bkpt_base_breakpoint_ops
;
15268 ops
->re_set
= internal_bkpt_re_set
;
15269 ops
->check_status
= internal_bkpt_check_status
;
15270 ops
->print_it
= internal_bkpt_print_it
;
15271 ops
->print_mention
= internal_bkpt_print_mention
;
15273 /* Momentary breakpoints. */
15274 ops
= &momentary_breakpoint_ops
;
15275 *ops
= bkpt_base_breakpoint_ops
;
15276 ops
->re_set
= momentary_bkpt_re_set
;
15277 ops
->check_status
= momentary_bkpt_check_status
;
15278 ops
->print_it
= momentary_bkpt_print_it
;
15279 ops
->print_mention
= momentary_bkpt_print_mention
;
15281 /* Probe breakpoints. */
15282 ops
= &bkpt_probe_breakpoint_ops
;
15283 *ops
= bkpt_breakpoint_ops
;
15284 ops
->insert_location
= bkpt_probe_insert_location
;
15285 ops
->remove_location
= bkpt_probe_remove_location
;
15286 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15287 ops
->decode_location
= bkpt_probe_decode_location
;
15290 ops
= &watchpoint_breakpoint_ops
;
15291 *ops
= base_breakpoint_ops
;
15292 ops
->re_set
= re_set_watchpoint
;
15293 ops
->insert_location
= insert_watchpoint
;
15294 ops
->remove_location
= remove_watchpoint
;
15295 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15296 ops
->check_status
= check_status_watchpoint
;
15297 ops
->resources_needed
= resources_needed_watchpoint
;
15298 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15299 ops
->print_it
= print_it_watchpoint
;
15300 ops
->print_mention
= print_mention_watchpoint
;
15301 ops
->print_recreate
= print_recreate_watchpoint
;
15302 ops
->explains_signal
= explains_signal_watchpoint
;
15304 /* Masked watchpoints. */
15305 ops
= &masked_watchpoint_breakpoint_ops
;
15306 *ops
= watchpoint_breakpoint_ops
;
15307 ops
->insert_location
= insert_masked_watchpoint
;
15308 ops
->remove_location
= remove_masked_watchpoint
;
15309 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15310 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15311 ops
->print_it
= print_it_masked_watchpoint
;
15312 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15313 ops
->print_mention
= print_mention_masked_watchpoint
;
15314 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15317 ops
= &tracepoint_breakpoint_ops
;
15318 *ops
= base_breakpoint_ops
;
15319 ops
->re_set
= tracepoint_re_set
;
15320 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15321 ops
->print_one_detail
= tracepoint_print_one_detail
;
15322 ops
->print_mention
= tracepoint_print_mention
;
15323 ops
->print_recreate
= tracepoint_print_recreate
;
15324 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15325 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15326 ops
->decode_location
= tracepoint_decode_location
;
15328 /* Probe tracepoints. */
15329 ops
= &tracepoint_probe_breakpoint_ops
;
15330 *ops
= tracepoint_breakpoint_ops
;
15331 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15332 ops
->decode_location
= tracepoint_probe_decode_location
;
15334 /* Static tracepoints with marker (`-m'). */
15335 ops
= &strace_marker_breakpoint_ops
;
15336 *ops
= tracepoint_breakpoint_ops
;
15337 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15338 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15339 ops
->decode_location
= strace_marker_decode_location
;
15341 /* Fork catchpoints. */
15342 ops
= &catch_fork_breakpoint_ops
;
15343 *ops
= base_breakpoint_ops
;
15344 ops
->insert_location
= insert_catch_fork
;
15345 ops
->remove_location
= remove_catch_fork
;
15346 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15347 ops
->print_it
= print_it_catch_fork
;
15348 ops
->print_one
= print_one_catch_fork
;
15349 ops
->print_mention
= print_mention_catch_fork
;
15350 ops
->print_recreate
= print_recreate_catch_fork
;
15352 /* Vfork catchpoints. */
15353 ops
= &catch_vfork_breakpoint_ops
;
15354 *ops
= base_breakpoint_ops
;
15355 ops
->insert_location
= insert_catch_vfork
;
15356 ops
->remove_location
= remove_catch_vfork
;
15357 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15358 ops
->print_it
= print_it_catch_vfork
;
15359 ops
->print_one
= print_one_catch_vfork
;
15360 ops
->print_mention
= print_mention_catch_vfork
;
15361 ops
->print_recreate
= print_recreate_catch_vfork
;
15363 /* Exec catchpoints. */
15364 ops
= &catch_exec_breakpoint_ops
;
15365 *ops
= base_breakpoint_ops
;
15366 ops
->insert_location
= insert_catch_exec
;
15367 ops
->remove_location
= remove_catch_exec
;
15368 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15369 ops
->print_it
= print_it_catch_exec
;
15370 ops
->print_one
= print_one_catch_exec
;
15371 ops
->print_mention
= print_mention_catch_exec
;
15372 ops
->print_recreate
= print_recreate_catch_exec
;
15374 /* Solib-related catchpoints. */
15375 ops
= &catch_solib_breakpoint_ops
;
15376 *ops
= base_breakpoint_ops
;
15377 ops
->insert_location
= insert_catch_solib
;
15378 ops
->remove_location
= remove_catch_solib
;
15379 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15380 ops
->check_status
= check_status_catch_solib
;
15381 ops
->print_it
= print_it_catch_solib
;
15382 ops
->print_one
= print_one_catch_solib
;
15383 ops
->print_mention
= print_mention_catch_solib
;
15384 ops
->print_recreate
= print_recreate_catch_solib
;
15386 ops
= &dprintf_breakpoint_ops
;
15387 *ops
= bkpt_base_breakpoint_ops
;
15388 ops
->re_set
= dprintf_re_set
;
15389 ops
->resources_needed
= bkpt_resources_needed
;
15390 ops
->print_it
= bkpt_print_it
;
15391 ops
->print_mention
= bkpt_print_mention
;
15392 ops
->print_recreate
= dprintf_print_recreate
;
15393 ops
->after_condition_true
= dprintf_after_condition_true
;
15394 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15397 /* Chain containing all defined "enable breakpoint" subcommands. */
15399 static struct cmd_list_element
*enablebreaklist
= NULL
;
15401 /* See breakpoint.h. */
15403 cmd_list_element
*commands_cmd_element
= nullptr;
15406 _initialize_breakpoint (void)
15408 struct cmd_list_element
*c
;
15410 initialize_breakpoint_ops ();
15412 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
);
15413 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
);
15414 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
);
15416 breakpoint_chain
= 0;
15417 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15418 before a breakpoint is set. */
15419 breakpoint_count
= 0;
15421 tracepoint_count
= 0;
15423 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15424 Set ignore-count of breakpoint number N to COUNT.\n\
15425 Usage is `ignore N COUNT'."));
15427 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15428 commands_command
, _("\
15429 Set commands to be executed when the given breakpoints are hit.\n\
15430 Give a space-separated breakpoint list as argument after \"commands\".\n\
15431 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15433 With no argument, the targeted breakpoint is the last one set.\n\
15434 The commands themselves follow starting on the next line.\n\
15435 Type a line containing \"end\" to indicate the end of them.\n\
15436 Give \"silent\" as the first line to make the breakpoint silent;\n\
15437 then no output is printed when it is hit, except what the commands print."));
15439 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15440 Specify breakpoint number N to break only if COND is true.\n\
15441 Usage is `condition N COND', where N is an integer and COND is an\n\
15442 expression to be evaluated whenever breakpoint N is reached."));
15443 set_cmd_completer (c
, condition_completer
);
15445 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15446 Set a temporary breakpoint.\n\
15447 Like \"break\" except the breakpoint is only temporary,\n\
15448 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15449 by using \"enable delete\" on the breakpoint number.\n\
15451 BREAK_ARGS_HELP ("tbreak")));
15452 set_cmd_completer (c
, location_completer
);
15454 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15455 Set a hardware assisted breakpoint.\n\
15456 Like \"break\" except the breakpoint requires hardware support,\n\
15457 some target hardware may not have this support.\n\
15459 BREAK_ARGS_HELP ("hbreak")));
15460 set_cmd_completer (c
, location_completer
);
15462 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15463 Set a temporary hardware assisted breakpoint.\n\
15464 Like \"hbreak\" except the breakpoint is only temporary,\n\
15465 so it will be deleted when hit.\n\
15467 BREAK_ARGS_HELP ("thbreak")));
15468 set_cmd_completer (c
, location_completer
);
15470 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15471 Enable all or some breakpoints.\n\
15472 Usage: enable [BREAKPOINTNUM]...\n\
15473 Give breakpoint numbers (separated by spaces) as arguments.\n\
15474 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15475 This is used to cancel the effect of the \"disable\" command.\n\
15476 With a subcommand you can enable temporarily."),
15477 &enablelist
, "enable ", 1, &cmdlist
);
15479 add_com_alias ("en", "enable", class_breakpoint
, 1);
15481 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15482 Enable all or some breakpoints.\n\
15483 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15484 Give breakpoint numbers (separated by spaces) as arguments.\n\
15485 This is used to cancel the effect of the \"disable\" command.\n\
15486 May be abbreviated to simply \"enable\"."),
15487 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15489 add_cmd ("once", no_class
, enable_once_command
, _("\
15490 Enable some breakpoints for one hit.\n\
15491 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15492 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15495 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15496 Enable some breakpoints and delete when hit.\n\
15497 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15498 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15501 add_cmd ("count", no_class
, enable_count_command
, _("\
15502 Enable some breakpoints for COUNT hits.\n\
15503 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15504 If a breakpoint is hit while enabled in this fashion,\n\
15505 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15508 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15509 Enable some breakpoints and delete when hit.\n\
15510 Usage: enable delete BREAKPOINTNUM...\n\
15511 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15514 add_cmd ("once", no_class
, enable_once_command
, _("\
15515 Enable some breakpoints for one hit.\n\
15516 Usage: enable once BREAKPOINTNUM...\n\
15517 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15520 add_cmd ("count", no_class
, enable_count_command
, _("\
15521 Enable some breakpoints for COUNT hits.\n\
15522 Usage: enable count COUNT BREAKPOINTNUM...\n\
15523 If a breakpoint is hit while enabled in this fashion,\n\
15524 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15527 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15528 Disable all or some breakpoints.\n\
15529 Usage: disable [BREAKPOINTNUM]...\n\
15530 Arguments are breakpoint numbers with spaces in between.\n\
15531 To disable all breakpoints, give no argument.\n\
15532 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15533 &disablelist
, "disable ", 1, &cmdlist
);
15534 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15535 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15537 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15538 Disable all or some breakpoints.\n\
15539 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15540 Arguments are breakpoint numbers with spaces in between.\n\
15541 To disable all breakpoints, give no argument.\n\
15542 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15543 This command may be abbreviated \"disable\"."),
15546 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15547 Delete all or some breakpoints.\n\
15548 Usage: delete [BREAKPOINTNUM]...\n\
15549 Arguments are breakpoint numbers with spaces in between.\n\
15550 To delete all breakpoints, give no argument.\n\
15552 Also a prefix command for deletion of other GDB objects."),
15553 &deletelist
, "delete ", 1, &cmdlist
);
15554 add_com_alias ("d", "delete", class_breakpoint
, 1);
15555 add_com_alias ("del", "delete", class_breakpoint
, 1);
15557 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15558 Delete all or some breakpoints or auto-display expressions.\n\
15559 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15560 Arguments are breakpoint numbers with spaces in between.\n\
15561 To delete all breakpoints, give no argument.\n\
15562 This command may be abbreviated \"delete\"."),
15565 add_com ("clear", class_breakpoint
, clear_command
, _("\
15566 Clear breakpoint at specified location.\n\
15567 Argument may be a linespec, explicit, or address location as described below.\n\
15569 With no argument, clears all breakpoints in the line that the selected frame\n\
15570 is executing in.\n"
15571 "\n" LOCATION_HELP_STRING
"\n\n\
15572 See also the \"delete\" command which clears breakpoints by number."));
15573 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15575 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15576 Set breakpoint at specified location.\n"
15577 BREAK_ARGS_HELP ("break")));
15578 set_cmd_completer (c
, location_completer
);
15580 add_com_alias ("b", "break", class_run
, 1);
15581 add_com_alias ("br", "break", class_run
, 1);
15582 add_com_alias ("bre", "break", class_run
, 1);
15583 add_com_alias ("brea", "break", class_run
, 1);
15587 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15588 Break in function/address or break at a line in the current file."),
15589 &stoplist
, "stop ", 1, &cmdlist
);
15590 add_cmd ("in", class_breakpoint
, stopin_command
,
15591 _("Break in function or address."), &stoplist
);
15592 add_cmd ("at", class_breakpoint
, stopat_command
,
15593 _("Break at a line in the current file."), &stoplist
);
15594 add_com ("status", class_info
, info_breakpoints_command
, _("\
15595 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15596 The \"Type\" column indicates one of:\n\
15597 \tbreakpoint - normal breakpoint\n\
15598 \twatchpoint - watchpoint\n\
15599 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15600 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15601 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15602 address and file/line number respectively.\n\
15604 Convenience variable \"$_\" and default examine address for \"x\"\n\
15605 are set to the address of the last breakpoint listed unless the command\n\
15606 is prefixed with \"server \".\n\n\
15607 Convenience variable \"$bpnum\" contains the number of the last\n\
15608 breakpoint set."));
15611 add_info ("breakpoints", info_breakpoints_command
, _("\
15612 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15613 The \"Type\" column indicates one of:\n\
15614 \tbreakpoint - normal breakpoint\n\
15615 \twatchpoint - watchpoint\n\
15616 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15617 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15618 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15619 address and file/line number respectively.\n\
15621 Convenience variable \"$_\" and default examine address for \"x\"\n\
15622 are set to the address of the last breakpoint listed unless the command\n\
15623 is prefixed with \"server \".\n\n\
15624 Convenience variable \"$bpnum\" contains the number of the last\n\
15625 breakpoint set."));
15627 add_info_alias ("b", "breakpoints", 1);
15629 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15630 Status of all breakpoints, or breakpoint number NUMBER.\n\
15631 The \"Type\" column indicates one of:\n\
15632 \tbreakpoint - normal breakpoint\n\
15633 \twatchpoint - watchpoint\n\
15634 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15635 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15636 \tuntil - internal breakpoint used by the \"until\" command\n\
15637 \tfinish - internal breakpoint used by the \"finish\" command\n\
15638 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15639 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15640 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15641 address and file/line number respectively.\n\
15643 Convenience variable \"$_\" and default examine address for \"x\"\n\
15644 are set to the address of the last breakpoint listed unless the command\n\
15645 is prefixed with \"server \".\n\n\
15646 Convenience variable \"$bpnum\" contains the number of the last\n\
15648 &maintenanceinfolist
);
15650 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15651 Set catchpoints to catch events."),
15652 &catch_cmdlist
, "catch ",
15653 0/*allow-unknown*/, &cmdlist
);
15655 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15656 Set temporary catchpoints to catch events."),
15657 &tcatch_cmdlist
, "tcatch ",
15658 0/*allow-unknown*/, &cmdlist
);
15660 add_catch_command ("fork", _("Catch calls to fork."),
15661 catch_fork_command_1
,
15663 (void *) (uintptr_t) catch_fork_permanent
,
15664 (void *) (uintptr_t) catch_fork_temporary
);
15665 add_catch_command ("vfork", _("Catch calls to vfork."),
15666 catch_fork_command_1
,
15668 (void *) (uintptr_t) catch_vfork_permanent
,
15669 (void *) (uintptr_t) catch_vfork_temporary
);
15670 add_catch_command ("exec", _("Catch calls to exec."),
15671 catch_exec_command_1
,
15675 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15676 Usage: catch load [REGEX]\n\
15677 If REGEX is given, only stop for libraries matching the regular expression."),
15678 catch_load_command_1
,
15682 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15683 Usage: catch unload [REGEX]\n\
15684 If REGEX is given, only stop for libraries matching the regular expression."),
15685 catch_unload_command_1
,
15690 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15691 Set a watchpoint for an expression.\n\
15692 Usage: watch [-l|-location] EXPRESSION\n\
15693 A watchpoint stops execution of your program whenever the value of\n\
15694 an expression changes.\n\
15695 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15696 the memory to which it refers."));
15697 set_cmd_completer (c
, expression_completer
);
15699 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15700 Set a read watchpoint for an expression.\n\
15701 Usage: rwatch [-l|-location] EXPRESSION\n\
15702 A watchpoint stops execution of your program whenever the value of\n\
15703 an expression is read.\n\
15704 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15705 the memory to which it refers."));
15706 set_cmd_completer (c
, expression_completer
);
15708 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15709 Set a watchpoint for an expression.\n\
15710 Usage: awatch [-l|-location] EXPRESSION\n\
15711 A watchpoint stops execution of your program whenever the value of\n\
15712 an expression is either read or written.\n\
15713 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15714 the memory to which it refers."));
15715 set_cmd_completer (c
, expression_completer
);
15717 add_info ("watchpoints", info_watchpoints_command
, _("\
15718 Status of specified watchpoints (all watchpoints if no argument)."));
15720 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15721 respond to changes - contrary to the description. */
15722 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15723 &can_use_hw_watchpoints
, _("\
15724 Set debugger's willingness to use watchpoint hardware."), _("\
15725 Show debugger's willingness to use watchpoint hardware."), _("\
15726 If zero, gdb will not use hardware for new watchpoints, even if\n\
15727 such is available. (However, any hardware watchpoints that were\n\
15728 created before setting this to nonzero, will continue to use watchpoint\n\
15731 show_can_use_hw_watchpoints
,
15732 &setlist
, &showlist
);
15734 can_use_hw_watchpoints
= 1;
15736 /* Tracepoint manipulation commands. */
15738 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15739 Set a tracepoint at specified location.\n\
15741 BREAK_ARGS_HELP ("trace") "\n\
15742 Do \"help tracepoints\" for info on other tracepoint commands."));
15743 set_cmd_completer (c
, location_completer
);
15745 add_com_alias ("tp", "trace", class_alias
, 0);
15746 add_com_alias ("tr", "trace", class_alias
, 1);
15747 add_com_alias ("tra", "trace", class_alias
, 1);
15748 add_com_alias ("trac", "trace", class_alias
, 1);
15750 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15751 Set a fast tracepoint at specified location.\n\
15753 BREAK_ARGS_HELP ("ftrace") "\n\
15754 Do \"help tracepoints\" for info on other tracepoint commands."));
15755 set_cmd_completer (c
, location_completer
);
15757 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15758 Set a static tracepoint at location or marker.\n\
15760 strace [LOCATION] [if CONDITION]\n\
15761 LOCATION may be a linespec, explicit, or address location (described below) \n\
15762 or -m MARKER_ID.\n\n\
15763 If a marker id is specified, probe the marker with that name. With\n\
15764 no LOCATION, uses current execution address of the selected stack frame.\n\
15765 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15766 This collects arbitrary user data passed in the probe point call to the\n\
15767 tracing library. You can inspect it when analyzing the trace buffer,\n\
15768 by printing the $_sdata variable like any other convenience variable.\n\
15770 CONDITION is a boolean expression.\n\
15771 \n" LOCATION_HELP_STRING
"\n\n\
15772 Multiple tracepoints at one place are permitted, and useful if their\n\
15773 conditions are different.\n\
15775 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15776 Do \"help tracepoints\" for info on other tracepoint commands."));
15777 set_cmd_completer (c
, location_completer
);
15779 add_info ("tracepoints", info_tracepoints_command
, _("\
15780 Status of specified tracepoints (all tracepoints if no argument).\n\
15781 Convenience variable \"$tpnum\" contains the number of the\n\
15782 last tracepoint set."));
15784 add_info_alias ("tp", "tracepoints", 1);
15786 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15787 Delete specified tracepoints.\n\
15788 Arguments are tracepoint numbers, separated by spaces.\n\
15789 No argument means delete all tracepoints."),
15791 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
15793 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15794 Disable specified tracepoints.\n\
15795 Arguments are tracepoint numbers, separated by spaces.\n\
15796 No argument means disable all tracepoints."),
15798 deprecate_cmd (c
, "disable");
15800 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15801 Enable specified tracepoints.\n\
15802 Arguments are tracepoint numbers, separated by spaces.\n\
15803 No argument means enable all tracepoints."),
15805 deprecate_cmd (c
, "enable");
15807 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15808 Set the passcount for a tracepoint.\n\
15809 The trace will end when the tracepoint has been passed 'count' times.\n\
15810 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15811 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15813 add_prefix_cmd ("save", class_breakpoint
, save_command
,
15814 _("Save breakpoint definitions as a script."),
15815 &save_cmdlist
, "save ",
15816 0/*allow-unknown*/, &cmdlist
);
15818 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15819 Save current breakpoint definitions as a script.\n\
15820 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15821 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15822 session to restore them."),
15824 set_cmd_completer (c
, filename_completer
);
15826 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15827 Save current tracepoint definitions as a script.\n\
15828 Use the 'source' command in another debug session to restore them."),
15830 set_cmd_completer (c
, filename_completer
);
15832 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
15833 deprecate_cmd (c
, "save tracepoints");
15835 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
15836 Breakpoint specific settings.\n\
15837 Configure various breakpoint-specific variables such as\n\
15838 pending breakpoint behavior."),
15839 &breakpoint_set_cmdlist
, "set breakpoint ",
15840 0/*allow-unknown*/, &setlist
);
15841 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
15842 Breakpoint specific settings.\n\
15843 Configure various breakpoint-specific variables such as\n\
15844 pending breakpoint behavior."),
15845 &breakpoint_show_cmdlist
, "show breakpoint ",
15846 0/*allow-unknown*/, &showlist
);
15848 add_setshow_auto_boolean_cmd ("pending", no_class
,
15849 &pending_break_support
, _("\
15850 Set debugger's behavior regarding pending breakpoints."), _("\
15851 Show debugger's behavior regarding pending breakpoints."), _("\
15852 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15853 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15854 an error. If auto, an unrecognized breakpoint location results in a\n\
15855 user-query to see if a pending breakpoint should be created."),
15857 show_pending_break_support
,
15858 &breakpoint_set_cmdlist
,
15859 &breakpoint_show_cmdlist
);
15861 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15863 add_setshow_boolean_cmd ("auto-hw", no_class
,
15864 &automatic_hardware_breakpoints
, _("\
15865 Set automatic usage of hardware breakpoints."), _("\
15866 Show automatic usage of hardware breakpoints."), _("\
15867 If set, the debugger will automatically use hardware breakpoints for\n\
15868 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15869 a warning will be emitted for such breakpoints."),
15871 show_automatic_hardware_breakpoints
,
15872 &breakpoint_set_cmdlist
,
15873 &breakpoint_show_cmdlist
);
15875 add_setshow_boolean_cmd ("always-inserted", class_support
,
15876 &always_inserted_mode
, _("\
15877 Set mode for inserting breakpoints."), _("\
15878 Show mode for inserting breakpoints."), _("\
15879 When this mode is on, breakpoints are inserted immediately as soon as\n\
15880 they're created, kept inserted even when execution stops, and removed\n\
15881 only when the user deletes them. When this mode is off (the default),\n\
15882 breakpoints are inserted only when execution continues, and removed\n\
15883 when execution stops."),
15885 &show_always_inserted_mode
,
15886 &breakpoint_set_cmdlist
,
15887 &breakpoint_show_cmdlist
);
15889 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15890 condition_evaluation_enums
,
15891 &condition_evaluation_mode_1
, _("\
15892 Set mode of breakpoint condition evaluation."), _("\
15893 Show mode of breakpoint condition evaluation."), _("\
15894 When this is set to \"host\", breakpoint conditions will be\n\
15895 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15896 breakpoint conditions will be downloaded to the target (if the target\n\
15897 supports such feature) and conditions will be evaluated on the target's side.\n\
15898 If this is set to \"auto\" (default), this will be automatically set to\n\
15899 \"target\" if it supports condition evaluation, otherwise it will\n\
15900 be set to \"gdb\""),
15901 &set_condition_evaluation_mode
,
15902 &show_condition_evaluation_mode
,
15903 &breakpoint_set_cmdlist
,
15904 &breakpoint_show_cmdlist
);
15906 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15907 Set a breakpoint for an address range.\n\
15908 break-range START-LOCATION, END-LOCATION\n\
15909 where START-LOCATION and END-LOCATION can be one of the following:\n\
15910 LINENUM, for that line in the current file,\n\
15911 FILE:LINENUM, for that line in that file,\n\
15912 +OFFSET, for that number of lines after the current line\n\
15913 or the start of the range\n\
15914 FUNCTION, for the first line in that function,\n\
15915 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15916 *ADDRESS, for the instruction at that address.\n\
15918 The breakpoint will stop execution of the inferior whenever it executes\n\
15919 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15920 range (including START-LOCATION and END-LOCATION)."));
15922 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
15923 Set a dynamic printf at specified location.\n\
15924 dprintf location,format string,arg1,arg2,...\n\
15925 location may be a linespec, explicit, or address location.\n"
15926 "\n" LOCATION_HELP_STRING
));
15927 set_cmd_completer (c
, location_completer
);
15929 add_setshow_enum_cmd ("dprintf-style", class_support
,
15930 dprintf_style_enums
, &dprintf_style
, _("\
15931 Set the style of usage for dynamic printf."), _("\
15932 Show the style of usage for dynamic printf."), _("\
15933 This setting chooses how GDB will do a dynamic printf.\n\
15934 If the value is \"gdb\", then the printing is done by GDB to its own\n\
15935 console, as with the \"printf\" command.\n\
15936 If the value is \"call\", the print is done by calling a function in your\n\
15937 program; by default printf(), but you can choose a different function or\n\
15938 output stream by setting dprintf-function and dprintf-channel."),
15939 update_dprintf_commands
, NULL
,
15940 &setlist
, &showlist
);
15942 dprintf_function
= xstrdup ("printf");
15943 add_setshow_string_cmd ("dprintf-function", class_support
,
15944 &dprintf_function
, _("\
15945 Set the function to use for dynamic printf."), _("\
15946 Show the function to use for dynamic printf."), NULL
,
15947 update_dprintf_commands
, NULL
,
15948 &setlist
, &showlist
);
15950 dprintf_channel
= xstrdup ("");
15951 add_setshow_string_cmd ("dprintf-channel", class_support
,
15952 &dprintf_channel
, _("\
15953 Set the channel to use for dynamic printf."), _("\
15954 Show the channel to use for dynamic printf."), NULL
,
15955 update_dprintf_commands
, NULL
,
15956 &setlist
, &showlist
);
15958 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
15959 &disconnected_dprintf
, _("\
15960 Set whether dprintf continues after GDB disconnects."), _("\
15961 Show whether dprintf continues after GDB disconnects."), _("\
15962 Use this to let dprintf commands continue to hit and produce output\n\
15963 even if GDB disconnects or detaches from the target."),
15966 &setlist
, &showlist
);
15968 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
15969 Target agent only formatted printing, like the C \"printf\" function.\n\
15970 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
15971 This supports most C printf format specifications, like %s, %d, etc.\n\
15972 This is useful for formatted output in user-defined commands."));
15974 automatic_hardware_breakpoints
= true;
15976 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
);
15977 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
);