1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "tracepoint.h"
29 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb-demangle.h"
40 #include "filenames.h"
46 #include "completer.h"
48 #include "cli/cli-script.h"
52 #include "observable.h"
58 #include "parser-defs.h"
59 #include "gdb_regex.h"
61 #include "cli/cli-utils.h"
64 #include "dummy-frame.h"
66 #include "gdbsupport/format.h"
67 #include "thread-fsm.h"
68 #include "tid-parse.h"
69 #include "cli/cli-style.h"
71 /* readline include files */
72 #include "readline/tilde.h"
74 /* readline defines this. */
77 #include "mi/mi-common.h"
78 #include "extension.h"
80 #include "progspace-and-thread.h"
81 #include "gdbsupport/array-view.h"
82 #include "gdbsupport/gdb_optional.h"
84 /* Prototypes for local functions. */
86 static void map_breakpoint_numbers (const char *,
87 gdb::function_view
<void (breakpoint
*)>);
89 static void breakpoint_re_set_default (struct breakpoint
*);
92 create_sals_from_location_default (const struct event_location
*location
,
93 struct linespec_result
*canonical
,
94 enum bptype type_wanted
);
96 static void create_breakpoints_sal_default (struct gdbarch
*,
97 struct linespec_result
*,
98 gdb::unique_xmalloc_ptr
<char>,
99 gdb::unique_xmalloc_ptr
<char>,
101 enum bpdisp
, int, int,
103 const struct breakpoint_ops
*,
104 int, int, int, unsigned);
106 static std::vector
<symtab_and_line
> decode_location_default
107 (struct breakpoint
*b
, const struct event_location
*location
,
108 struct program_space
*search_pspace
);
110 static int can_use_hardware_watchpoint
111 (const std::vector
<value_ref_ptr
> &vals
);
113 static void mention (struct breakpoint
*);
115 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
117 const struct breakpoint_ops
*);
118 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
119 const struct symtab_and_line
*);
121 /* This function is used in gdbtk sources and thus can not be made
123 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
124 struct symtab_and_line
,
126 const struct breakpoint_ops
*);
128 static struct breakpoint
*
129 momentary_breakpoint_from_master (struct breakpoint
*orig
,
131 const struct breakpoint_ops
*ops
,
134 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
136 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
140 static void describe_other_breakpoints (struct gdbarch
*,
141 struct program_space
*, CORE_ADDR
,
142 struct obj_section
*, int);
144 static int watchpoint_locations_match (struct bp_location
*loc1
,
145 struct bp_location
*loc2
);
147 static int breakpoint_location_address_match (struct bp_location
*bl
,
148 const struct address_space
*aspace
,
151 static int breakpoint_location_address_range_overlap (struct bp_location
*,
152 const address_space
*,
155 static int remove_breakpoint (struct bp_location
*);
156 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
158 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
160 static int hw_breakpoint_used_count (void);
162 static int hw_watchpoint_use_count (struct breakpoint
*);
164 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
166 int *other_type_used
);
168 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
171 static void free_bp_location (struct bp_location
*loc
);
172 static void incref_bp_location (struct bp_location
*loc
);
173 static void decref_bp_location (struct bp_location
**loc
);
175 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
177 /* update_global_location_list's modes of operation wrt to whether to
178 insert locations now. */
179 enum ugll_insert_mode
181 /* Don't insert any breakpoint locations into the inferior, only
182 remove already-inserted locations that no longer should be
183 inserted. Functions that delete a breakpoint or breakpoints
184 should specify this mode, so that deleting a breakpoint doesn't
185 have the side effect of inserting the locations of other
186 breakpoints that are marked not-inserted, but should_be_inserted
187 returns true on them.
189 This behavior is useful is situations close to tear-down -- e.g.,
190 after an exec, while the target still has execution, but
191 breakpoint shadows of the previous executable image should *NOT*
192 be restored to the new image; or before detaching, where the
193 target still has execution and wants to delete breakpoints from
194 GDB's lists, and all breakpoints had already been removed from
198 /* May insert breakpoints iff breakpoints_should_be_inserted_now
199 claims breakpoints should be inserted now. */
202 /* Insert locations now, irrespective of
203 breakpoints_should_be_inserted_now. E.g., say all threads are
204 stopped right now, and the user did "continue". We need to
205 insert breakpoints _before_ resuming the target, but
206 UGLL_MAY_INSERT wouldn't insert them, because
207 breakpoints_should_be_inserted_now returns false at that point,
208 as no thread is running yet. */
212 static void update_global_location_list (enum ugll_insert_mode
);
214 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
216 static void insert_breakpoint_locations (void);
218 static void trace_pass_command (const char *, int);
220 static void set_tracepoint_count (int num
);
222 static bool is_masked_watchpoint (const struct breakpoint
*b
);
224 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
226 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
229 static int strace_marker_p (struct breakpoint
*b
);
231 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
232 that are implemented on top of software or hardware breakpoints
233 (user breakpoints, internal and momentary breakpoints, etc.). */
234 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
236 /* Internal breakpoints class type. */
237 static struct breakpoint_ops internal_breakpoint_ops
;
239 /* Momentary breakpoints class type. */
240 static struct breakpoint_ops momentary_breakpoint_ops
;
242 /* The breakpoint_ops structure to be used in regular user created
244 struct breakpoint_ops bkpt_breakpoint_ops
;
246 /* Breakpoints set on probes. */
247 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
249 /* Dynamic printf class type. */
250 struct breakpoint_ops dprintf_breakpoint_ops
;
252 /* The style in which to perform a dynamic printf. This is a user
253 option because different output options have different tradeoffs;
254 if GDB does the printing, there is better error handling if there
255 is a problem with any of the arguments, but using an inferior
256 function lets you have special-purpose printers and sending of
257 output to the same place as compiled-in print functions. */
259 static const char dprintf_style_gdb
[] = "gdb";
260 static const char dprintf_style_call
[] = "call";
261 static const char dprintf_style_agent
[] = "agent";
262 static const char *const dprintf_style_enums
[] = {
268 static const char *dprintf_style
= dprintf_style_gdb
;
270 /* The function to use for dynamic printf if the preferred style is to
271 call into the inferior. The value is simply a string that is
272 copied into the command, so it can be anything that GDB can
273 evaluate to a callable address, not necessarily a function name. */
275 static char *dprintf_function
;
277 /* The channel to use for dynamic printf if the preferred style is to
278 call into the inferior; if a nonempty string, it will be passed to
279 the call as the first argument, with the format string as the
280 second. As with the dprintf function, this can be anything that
281 GDB knows how to evaluate, so in addition to common choices like
282 "stderr", this could be an app-specific expression like
283 "mystreams[curlogger]". */
285 static char *dprintf_channel
;
287 /* True if dprintf commands should continue to operate even if GDB
289 static bool disconnected_dprintf
= true;
291 struct command_line
*
292 breakpoint_commands (struct breakpoint
*b
)
294 return b
->commands
? b
->commands
.get () : NULL
;
297 /* Flag indicating that a command has proceeded the inferior past the
298 current breakpoint. */
300 static bool breakpoint_proceeded
;
303 bpdisp_text (enum bpdisp disp
)
305 /* NOTE: the following values are a part of MI protocol and
306 represent values of 'disp' field returned when inferior stops at
308 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
310 return bpdisps
[(int) disp
];
313 /* Prototypes for exported functions. */
314 /* If FALSE, gdb will not use hardware support for watchpoints, even
315 if such is available. */
316 static int can_use_hw_watchpoints
;
319 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
320 struct cmd_list_element
*c
,
323 fprintf_filtered (file
,
324 _("Debugger's willingness to use "
325 "watchpoint hardware is %s.\n"),
329 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
330 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
331 for unrecognized breakpoint locations.
332 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
333 static enum auto_boolean pending_break_support
;
335 show_pending_break_support (struct ui_file
*file
, int from_tty
,
336 struct cmd_list_element
*c
,
339 fprintf_filtered (file
,
340 _("Debugger's behavior regarding "
341 "pending breakpoints is %s.\n"),
345 /* If true, gdb will automatically use hardware breakpoints for breakpoints
346 set with "break" but falling in read-only memory.
347 If false, gdb will warn about such breakpoints, but won't automatically
348 use hardware breakpoints. */
349 static bool automatic_hardware_breakpoints
;
351 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
352 struct cmd_list_element
*c
,
355 fprintf_filtered (file
,
356 _("Automatic usage of hardware breakpoints is %s.\n"),
360 /* If on, GDB keeps breakpoints inserted even if the inferior is
361 stopped, and immediately inserts any new breakpoints as soon as
362 they're created. If off (default), GDB keeps breakpoints off of
363 the target as long as possible. That is, it delays inserting
364 breakpoints until the next resume, and removes them again when the
365 target fully stops. This is a bit safer in case GDB crashes while
366 processing user input. */
367 static bool always_inserted_mode
= false;
370 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
371 struct cmd_list_element
*c
, const char *value
)
373 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
377 /* See breakpoint.h. */
380 breakpoints_should_be_inserted_now (void)
382 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
384 /* If breakpoints are global, they should be inserted even if no
385 thread under gdb's control is running, or even if there are
386 no threads under GDB's control yet. */
389 else if (target_has_execution
)
391 if (always_inserted_mode
)
393 /* The user wants breakpoints inserted even if all threads
398 if (threads_are_executing ())
401 /* Don't remove breakpoints yet if, even though all threads are
402 stopped, we still have events to process. */
403 for (thread_info
*tp
: all_non_exited_threads ())
405 && tp
->suspend
.waitstatus_pending_p
)
411 static const char condition_evaluation_both
[] = "host or target";
413 /* Modes for breakpoint condition evaluation. */
414 static const char condition_evaluation_auto
[] = "auto";
415 static const char condition_evaluation_host
[] = "host";
416 static const char condition_evaluation_target
[] = "target";
417 static const char *const condition_evaluation_enums
[] = {
418 condition_evaluation_auto
,
419 condition_evaluation_host
,
420 condition_evaluation_target
,
424 /* Global that holds the current mode for breakpoint condition evaluation. */
425 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
427 /* Global that we use to display information to the user (gets its value from
428 condition_evaluation_mode_1. */
429 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
431 /* Translate a condition evaluation mode MODE into either "host"
432 or "target". This is used mostly to translate from "auto" to the
433 real setting that is being used. It returns the translated
437 translate_condition_evaluation_mode (const char *mode
)
439 if (mode
== condition_evaluation_auto
)
441 if (target_supports_evaluation_of_breakpoint_conditions ())
442 return condition_evaluation_target
;
444 return condition_evaluation_host
;
450 /* Discovers what condition_evaluation_auto translates to. */
453 breakpoint_condition_evaluation_mode (void)
455 return translate_condition_evaluation_mode (condition_evaluation_mode
);
458 /* Return true if GDB should evaluate breakpoint conditions or false
462 gdb_evaluates_breakpoint_condition_p (void)
464 const char *mode
= breakpoint_condition_evaluation_mode ();
466 return (mode
== condition_evaluation_host
);
469 /* Are we executing breakpoint commands? */
470 static int executing_breakpoint_commands
;
472 /* Are overlay event breakpoints enabled? */
473 static int overlay_events_enabled
;
475 /* See description in breakpoint.h. */
476 bool target_exact_watchpoints
= false;
478 /* Walk the following statement or block through all breakpoints.
479 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
480 current breakpoint. */
482 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
484 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
485 for (B = breakpoint_chain; \
486 B ? (TMP=B->next, 1): 0; \
489 /* Similar iterator for the low-level breakpoints. SAFE variant is
490 not provided so update_global_location_list must not be called
491 while executing the block of ALL_BP_LOCATIONS. */
493 #define ALL_BP_LOCATIONS(B,BP_TMP) \
494 for (BP_TMP = bp_locations; \
495 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
498 /* Iterates through locations with address ADDRESS for the currently selected
499 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
500 to where the loop should start from.
501 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
502 appropriate location to start with. */
504 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
505 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
506 BP_LOCP_TMP = BP_LOCP_START; \
508 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
509 && (*BP_LOCP_TMP)->address == ADDRESS); \
512 /* Iterator for tracepoints only. */
514 #define ALL_TRACEPOINTS(B) \
515 for (B = breakpoint_chain; B; B = B->next) \
516 if (is_tracepoint (B))
518 /* Chains of all breakpoints defined. */
520 static struct breakpoint
*breakpoint_chain
;
522 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
524 static struct bp_location
**bp_locations
;
526 /* Number of elements of BP_LOCATIONS. */
528 static unsigned bp_locations_count
;
530 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
531 ADDRESS for the current elements of BP_LOCATIONS which get a valid
532 result from bp_location_has_shadow. You can use it for roughly
533 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
534 an address you need to read. */
536 static CORE_ADDR bp_locations_placed_address_before_address_max
;
538 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
539 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
540 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
541 You can use it for roughly limiting the subrange of BP_LOCATIONS to
542 scan for shadow bytes for an address you need to read. */
544 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
546 /* The locations that no longer correspond to any breakpoint, unlinked
547 from the bp_locations array, but for which a hit may still be
548 reported by a target. */
549 static std::vector
<bp_location
*> moribund_locations
;
551 /* Number of last breakpoint made. */
553 static int breakpoint_count
;
555 /* The value of `breakpoint_count' before the last command that
556 created breakpoints. If the last (break-like) command created more
557 than one breakpoint, then the difference between BREAKPOINT_COUNT
558 and PREV_BREAKPOINT_COUNT is more than one. */
559 static int prev_breakpoint_count
;
561 /* Number of last tracepoint made. */
563 static int tracepoint_count
;
565 static struct cmd_list_element
*breakpoint_set_cmdlist
;
566 static struct cmd_list_element
*breakpoint_show_cmdlist
;
567 struct cmd_list_element
*save_cmdlist
;
569 /* See declaration at breakpoint.h. */
572 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
575 struct breakpoint
*b
= NULL
;
579 if (func (b
, user_data
) != 0)
586 /* Return whether a breakpoint is an active enabled breakpoint. */
588 breakpoint_enabled (struct breakpoint
*b
)
590 return (b
->enable_state
== bp_enabled
);
593 /* Set breakpoint count to NUM. */
596 set_breakpoint_count (int num
)
598 prev_breakpoint_count
= breakpoint_count
;
599 breakpoint_count
= num
;
600 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
603 /* Used by `start_rbreak_breakpoints' below, to record the current
604 breakpoint count before "rbreak" creates any breakpoint. */
605 static int rbreak_start_breakpoint_count
;
607 /* Called at the start an "rbreak" command to record the first
610 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
612 rbreak_start_breakpoint_count
= breakpoint_count
;
615 /* Called at the end of an "rbreak" command to record the last
618 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
620 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
623 /* Used in run_command to zero the hit count when a new run starts. */
626 clear_breakpoint_hit_counts (void)
628 struct breakpoint
*b
;
635 /* Return the breakpoint with the specified number, or NULL
636 if the number does not refer to an existing breakpoint. */
639 get_breakpoint (int num
)
641 struct breakpoint
*b
;
644 if (b
->number
== num
)
652 /* Mark locations as "conditions have changed" in case the target supports
653 evaluating conditions on its side. */
656 mark_breakpoint_modified (struct breakpoint
*b
)
658 struct bp_location
*loc
;
660 /* This is only meaningful if the target is
661 evaluating conditions and if the user has
662 opted for condition evaluation on the target's
664 if (gdb_evaluates_breakpoint_condition_p ()
665 || !target_supports_evaluation_of_breakpoint_conditions ())
668 if (!is_breakpoint (b
))
671 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
672 loc
->condition_changed
= condition_modified
;
675 /* Mark location as "conditions have changed" in case the target supports
676 evaluating conditions on its side. */
679 mark_breakpoint_location_modified (struct bp_location
*loc
)
681 /* This is only meaningful if the target is
682 evaluating conditions and if the user has
683 opted for condition evaluation on the target's
685 if (gdb_evaluates_breakpoint_condition_p ()
686 || !target_supports_evaluation_of_breakpoint_conditions ())
690 if (!is_breakpoint (loc
->owner
))
693 loc
->condition_changed
= condition_modified
;
696 /* Sets the condition-evaluation mode using the static global
697 condition_evaluation_mode. */
700 set_condition_evaluation_mode (const char *args
, int from_tty
,
701 struct cmd_list_element
*c
)
703 const char *old_mode
, *new_mode
;
705 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
706 && !target_supports_evaluation_of_breakpoint_conditions ())
708 condition_evaluation_mode_1
= condition_evaluation_mode
;
709 warning (_("Target does not support breakpoint condition evaluation.\n"
710 "Using host evaluation mode instead."));
714 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
715 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
717 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
718 settings was "auto". */
719 condition_evaluation_mode
= condition_evaluation_mode_1
;
721 /* Only update the mode if the user picked a different one. */
722 if (new_mode
!= old_mode
)
724 struct bp_location
*loc
, **loc_tmp
;
725 /* If the user switched to a different evaluation mode, we
726 need to synch the changes with the target as follows:
728 "host" -> "target": Send all (valid) conditions to the target.
729 "target" -> "host": Remove all the conditions from the target.
732 if (new_mode
== condition_evaluation_target
)
734 /* Mark everything modified and synch conditions with the
736 ALL_BP_LOCATIONS (loc
, loc_tmp
)
737 mark_breakpoint_location_modified (loc
);
741 /* Manually mark non-duplicate locations to synch conditions
742 with the target. We do this to remove all the conditions the
743 target knows about. */
744 ALL_BP_LOCATIONS (loc
, loc_tmp
)
745 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
746 loc
->needs_update
= 1;
750 update_global_location_list (UGLL_MAY_INSERT
);
756 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
757 what "auto" is translating to. */
760 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
761 struct cmd_list_element
*c
, const char *value
)
763 if (condition_evaluation_mode
== condition_evaluation_auto
)
764 fprintf_filtered (file
,
765 _("Breakpoint condition evaluation "
766 "mode is %s (currently %s).\n"),
768 breakpoint_condition_evaluation_mode ());
770 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
774 /* A comparison function for bp_location AP and BP that is used by
775 bsearch. This comparison function only cares about addresses, unlike
776 the more general bp_locations_compare function. */
779 bp_locations_compare_addrs (const void *ap
, const void *bp
)
781 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
782 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
784 if (a
->address
== b
->address
)
787 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
790 /* Helper function to skip all bp_locations with addresses
791 less than ADDRESS. It returns the first bp_location that
792 is greater than or equal to ADDRESS. If none is found, just
795 static struct bp_location
**
796 get_first_locp_gte_addr (CORE_ADDR address
)
798 struct bp_location dummy_loc
;
799 struct bp_location
*dummy_locp
= &dummy_loc
;
800 struct bp_location
**locp_found
= NULL
;
802 /* Initialize the dummy location's address field. */
803 dummy_loc
.address
= address
;
805 /* Find a close match to the first location at ADDRESS. */
806 locp_found
= ((struct bp_location
**)
807 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
808 sizeof (struct bp_location
**),
809 bp_locations_compare_addrs
));
811 /* Nothing was found, nothing left to do. */
812 if (locp_found
== NULL
)
815 /* We may have found a location that is at ADDRESS but is not the first in the
816 location's list. Go backwards (if possible) and locate the first one. */
817 while ((locp_found
- 1) >= bp_locations
818 && (*(locp_found
- 1))->address
== address
)
825 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
828 xfree (b
->cond_string
);
829 b
->cond_string
= NULL
;
831 if (is_watchpoint (b
))
833 struct watchpoint
*w
= (struct watchpoint
*) b
;
835 w
->cond_exp
.reset ();
839 struct bp_location
*loc
;
841 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
845 /* No need to free the condition agent expression
846 bytecode (if we have one). We will handle this
847 when we go through update_global_location_list. */
854 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
858 const char *arg
= exp
;
860 /* I don't know if it matters whether this is the string the user
861 typed in or the decompiled expression. */
862 b
->cond_string
= xstrdup (arg
);
863 b
->condition_not_parsed
= 0;
865 if (is_watchpoint (b
))
867 struct watchpoint
*w
= (struct watchpoint
*) b
;
869 innermost_block_tracker tracker
;
871 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
873 error (_("Junk at end of expression"));
874 w
->cond_exp_valid_block
= tracker
.block ();
878 struct bp_location
*loc
;
880 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
884 parse_exp_1 (&arg
, loc
->address
,
885 block_for_pc (loc
->address
), 0);
887 error (_("Junk at end of expression"));
891 mark_breakpoint_modified (b
);
893 gdb::observers::breakpoint_modified
.notify (b
);
896 /* Completion for the "condition" command. */
899 condition_completer (struct cmd_list_element
*cmd
,
900 completion_tracker
&tracker
,
901 const char *text
, const char *word
)
905 text
= skip_spaces (text
);
906 space
= skip_to_space (text
);
910 struct breakpoint
*b
;
914 /* We don't support completion of history indices. */
915 if (!isdigit (text
[1]))
916 complete_internalvar (tracker
, &text
[1]);
920 /* We're completing the breakpoint number. */
927 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
929 if (strncmp (number
, text
, len
) == 0)
930 tracker
.add_completion (make_unique_xstrdup (number
));
936 /* We're completing the expression part. */
937 text
= skip_spaces (space
);
938 expression_completer (cmd
, tracker
, text
, word
);
941 /* condition N EXP -- set break condition of breakpoint N to EXP. */
944 condition_command (const char *arg
, int from_tty
)
946 struct breakpoint
*b
;
951 error_no_arg (_("breakpoint number"));
954 bnum
= get_number (&p
);
956 error (_("Bad breakpoint argument: '%s'"), arg
);
959 if (b
->number
== bnum
)
961 /* Check if this breakpoint has a "stop" method implemented in an
962 extension language. This method and conditions entered into GDB
963 from the CLI are mutually exclusive. */
964 const struct extension_language_defn
*extlang
965 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
969 error (_("Only one stop condition allowed. There is currently"
970 " a %s stop condition defined for this breakpoint."),
971 ext_lang_capitalized_name (extlang
));
973 set_breakpoint_condition (b
, p
, from_tty
);
975 if (is_breakpoint (b
))
976 update_global_location_list (UGLL_MAY_INSERT
);
981 error (_("No breakpoint number %d."), bnum
);
984 /* Check that COMMAND do not contain commands that are suitable
985 only for tracepoints and not suitable for ordinary breakpoints.
986 Throw if any such commands is found. */
989 check_no_tracepoint_commands (struct command_line
*commands
)
991 struct command_line
*c
;
993 for (c
= commands
; c
; c
= c
->next
)
995 if (c
->control_type
== while_stepping_control
)
996 error (_("The 'while-stepping' command can "
997 "only be used for tracepoints"));
999 check_no_tracepoint_commands (c
->body_list_0
.get ());
1000 check_no_tracepoint_commands (c
->body_list_1
.get ());
1002 /* Not that command parsing removes leading whitespace and comment
1003 lines and also empty lines. So, we only need to check for
1004 command directly. */
1005 if (strstr (c
->line
, "collect ") == c
->line
)
1006 error (_("The 'collect' command can only be used for tracepoints"));
1008 if (strstr (c
->line
, "teval ") == c
->line
)
1009 error (_("The 'teval' command can only be used for tracepoints"));
1013 struct longjmp_breakpoint
: public breakpoint
1015 ~longjmp_breakpoint () override
;
1018 /* Encapsulate tests for different types of tracepoints. */
1021 is_tracepoint_type (bptype type
)
1023 return (type
== bp_tracepoint
1024 || type
== bp_fast_tracepoint
1025 || type
== bp_static_tracepoint
);
1029 is_longjmp_type (bptype type
)
1031 return type
== bp_longjmp
|| type
== bp_exception
;
1034 /* See breakpoint.h. */
1037 is_tracepoint (const struct breakpoint
*b
)
1039 return is_tracepoint_type (b
->type
);
1042 /* Factory function to create an appropriate instance of breakpoint given
1045 static std::unique_ptr
<breakpoint
>
1046 new_breakpoint_from_type (bptype type
)
1050 if (is_tracepoint_type (type
))
1051 b
= new tracepoint ();
1052 else if (is_longjmp_type (type
))
1053 b
= new longjmp_breakpoint ();
1055 b
= new breakpoint ();
1057 return std::unique_ptr
<breakpoint
> (b
);
1060 /* A helper function that validates that COMMANDS are valid for a
1061 breakpoint. This function will throw an exception if a problem is
1065 validate_commands_for_breakpoint (struct breakpoint
*b
,
1066 struct command_line
*commands
)
1068 if (is_tracepoint (b
))
1070 struct tracepoint
*t
= (struct tracepoint
*) b
;
1071 struct command_line
*c
;
1072 struct command_line
*while_stepping
= 0;
1074 /* Reset the while-stepping step count. The previous commands
1075 might have included a while-stepping action, while the new
1079 /* We need to verify that each top-level element of commands is
1080 valid for tracepoints, that there's at most one
1081 while-stepping element, and that the while-stepping's body
1082 has valid tracing commands excluding nested while-stepping.
1083 We also need to validate the tracepoint action line in the
1084 context of the tracepoint --- validate_actionline actually
1085 has side effects, like setting the tracepoint's
1086 while-stepping STEP_COUNT, in addition to checking if the
1087 collect/teval actions parse and make sense in the
1088 tracepoint's context. */
1089 for (c
= commands
; c
; c
= c
->next
)
1091 if (c
->control_type
== while_stepping_control
)
1093 if (b
->type
== bp_fast_tracepoint
)
1094 error (_("The 'while-stepping' command "
1095 "cannot be used for fast tracepoint"));
1096 else if (b
->type
== bp_static_tracepoint
)
1097 error (_("The 'while-stepping' command "
1098 "cannot be used for static tracepoint"));
1101 error (_("The 'while-stepping' command "
1102 "can be used only once"));
1107 validate_actionline (c
->line
, b
);
1111 struct command_line
*c2
;
1113 gdb_assert (while_stepping
->body_list_1
== nullptr);
1114 c2
= while_stepping
->body_list_0
.get ();
1115 for (; c2
; c2
= c2
->next
)
1117 if (c2
->control_type
== while_stepping_control
)
1118 error (_("The 'while-stepping' command cannot be nested"));
1124 check_no_tracepoint_commands (commands
);
1128 /* Return a vector of all the static tracepoints set at ADDR. The
1129 caller is responsible for releasing the vector. */
1131 std::vector
<breakpoint
*>
1132 static_tracepoints_here (CORE_ADDR addr
)
1134 struct breakpoint
*b
;
1135 std::vector
<breakpoint
*> found
;
1136 struct bp_location
*loc
;
1139 if (b
->type
== bp_static_tracepoint
)
1141 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1142 if (loc
->address
== addr
)
1143 found
.push_back (b
);
1149 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1150 validate that only allowed commands are included. */
1153 breakpoint_set_commands (struct breakpoint
*b
,
1154 counted_command_line
&&commands
)
1156 validate_commands_for_breakpoint (b
, commands
.get ());
1158 b
->commands
= std::move (commands
);
1159 gdb::observers::breakpoint_modified
.notify (b
);
1162 /* Set the internal `silent' flag on the breakpoint. Note that this
1163 is not the same as the "silent" that may appear in the breakpoint's
1167 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1169 int old_silent
= b
->silent
;
1172 if (old_silent
!= silent
)
1173 gdb::observers::breakpoint_modified
.notify (b
);
1176 /* Set the thread for this breakpoint. If THREAD is -1, make the
1177 breakpoint work for any thread. */
1180 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1182 int old_thread
= b
->thread
;
1185 if (old_thread
!= thread
)
1186 gdb::observers::breakpoint_modified
.notify (b
);
1189 /* Set the task for this breakpoint. If TASK is 0, make the
1190 breakpoint work for any task. */
1193 breakpoint_set_task (struct breakpoint
*b
, int task
)
1195 int old_task
= b
->task
;
1198 if (old_task
!= task
)
1199 gdb::observers::breakpoint_modified
.notify (b
);
1203 commands_command_1 (const char *arg
, int from_tty
,
1204 struct command_line
*control
)
1206 counted_command_line cmd
;
1207 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1208 NULL after the call to read_command_lines if the user provides an empty
1209 list of command by just typing "end". */
1210 bool cmd_read
= false;
1212 std::string new_arg
;
1214 if (arg
== NULL
|| !*arg
)
1216 if (breakpoint_count
- prev_breakpoint_count
> 1)
1217 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1219 else if (breakpoint_count
> 0)
1220 new_arg
= string_printf ("%d", breakpoint_count
);
1221 arg
= new_arg
.c_str ();
1224 map_breakpoint_numbers
1225 (arg
, [&] (breakpoint
*b
)
1229 gdb_assert (cmd
== NULL
);
1230 if (control
!= NULL
)
1231 cmd
= control
->body_list_0
;
1235 = string_printf (_("Type commands for breakpoint(s) "
1236 "%s, one per line."),
1239 auto do_validate
= [=] (const char *line
)
1241 validate_actionline (line
, b
);
1243 gdb::function_view
<void (const char *)> validator
;
1244 if (is_tracepoint (b
))
1245 validator
= do_validate
;
1247 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1252 /* If a breakpoint was on the list more than once, we don't need to
1254 if (b
->commands
!= cmd
)
1256 validate_commands_for_breakpoint (b
, cmd
.get ());
1258 gdb::observers::breakpoint_modified
.notify (b
);
1264 commands_command (const char *arg
, int from_tty
)
1266 commands_command_1 (arg
, from_tty
, NULL
);
1269 /* Like commands_command, but instead of reading the commands from
1270 input stream, takes them from an already parsed command structure.
1272 This is used by cli-script.c to DTRT with breakpoint commands
1273 that are part of if and while bodies. */
1274 enum command_control_type
1275 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1277 commands_command_1 (arg
, 0, cmd
);
1278 return simple_control
;
1281 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1284 bp_location_has_shadow (struct bp_location
*bl
)
1286 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1290 if (bl
->target_info
.shadow_len
== 0)
1291 /* BL isn't valid, or doesn't shadow memory. */
1296 /* Update BUF, which is LEN bytes read from the target address
1297 MEMADDR, by replacing a memory breakpoint with its shadowed
1300 If READBUF is not NULL, this buffer must not overlap with the of
1301 the breakpoint location's shadow_contents buffer. Otherwise, a
1302 failed assertion internal error will be raised. */
1305 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1306 const gdb_byte
*writebuf_org
,
1307 ULONGEST memaddr
, LONGEST len
,
1308 struct bp_target_info
*target_info
,
1309 struct gdbarch
*gdbarch
)
1311 /* Now do full processing of the found relevant range of elements. */
1312 CORE_ADDR bp_addr
= 0;
1316 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1317 current_program_space
->aspace
, 0))
1319 /* The breakpoint is inserted in a different address space. */
1323 /* Addresses and length of the part of the breakpoint that
1325 bp_addr
= target_info
->placed_address
;
1326 bp_size
= target_info
->shadow_len
;
1328 if (bp_addr
+ bp_size
<= memaddr
)
1330 /* The breakpoint is entirely before the chunk of memory we are
1335 if (bp_addr
>= memaddr
+ len
)
1337 /* The breakpoint is entirely after the chunk of memory we are
1342 /* Offset within shadow_contents. */
1343 if (bp_addr
< memaddr
)
1345 /* Only copy the second part of the breakpoint. */
1346 bp_size
-= memaddr
- bp_addr
;
1347 bptoffset
= memaddr
- bp_addr
;
1351 if (bp_addr
+ bp_size
> memaddr
+ len
)
1353 /* Only copy the first part of the breakpoint. */
1354 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1357 if (readbuf
!= NULL
)
1359 /* Verify that the readbuf buffer does not overlap with the
1360 shadow_contents buffer. */
1361 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1362 || readbuf
>= (target_info
->shadow_contents
1363 + target_info
->shadow_len
));
1365 /* Update the read buffer with this inserted breakpoint's
1367 memcpy (readbuf
+ bp_addr
- memaddr
,
1368 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1372 const unsigned char *bp
;
1373 CORE_ADDR addr
= target_info
->reqstd_address
;
1376 /* Update the shadow with what we want to write to memory. */
1377 memcpy (target_info
->shadow_contents
+ bptoffset
,
1378 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1380 /* Determine appropriate breakpoint contents and size for this
1382 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1384 /* Update the final write buffer with this inserted
1385 breakpoint's INSN. */
1386 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1390 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1391 by replacing any memory breakpoints with their shadowed contents.
1393 If READBUF is not NULL, this buffer must not overlap with any of
1394 the breakpoint location's shadow_contents buffers. Otherwise,
1395 a failed assertion internal error will be raised.
1397 The range of shadowed area by each bp_location is:
1398 bl->address - bp_locations_placed_address_before_address_max
1399 up to bl->address + bp_locations_shadow_len_after_address_max
1400 The range we were requested to resolve shadows for is:
1401 memaddr ... memaddr + len
1402 Thus the safe cutoff boundaries for performance optimization are
1403 memaddr + len <= (bl->address
1404 - bp_locations_placed_address_before_address_max)
1406 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1409 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1410 const gdb_byte
*writebuf_org
,
1411 ULONGEST memaddr
, LONGEST len
)
1413 /* Left boundary, right boundary and median element of our binary
1415 unsigned bc_l
, bc_r
, bc
;
1417 /* Find BC_L which is a leftmost element which may affect BUF
1418 content. It is safe to report lower value but a failure to
1419 report higher one. */
1422 bc_r
= bp_locations_count
;
1423 while (bc_l
+ 1 < bc_r
)
1425 struct bp_location
*bl
;
1427 bc
= (bc_l
+ bc_r
) / 2;
1428 bl
= bp_locations
[bc
];
1430 /* Check first BL->ADDRESS will not overflow due to the added
1431 constant. Then advance the left boundary only if we are sure
1432 the BC element can in no way affect the BUF content (MEMADDR
1433 to MEMADDR + LEN range).
1435 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1436 offset so that we cannot miss a breakpoint with its shadow
1437 range tail still reaching MEMADDR. */
1439 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1441 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1448 /* Due to the binary search above, we need to make sure we pick the
1449 first location that's at BC_L's address. E.g., if there are
1450 multiple locations at the same address, BC_L may end up pointing
1451 at a duplicate location, and miss the "master"/"inserted"
1452 location. Say, given locations L1, L2 and L3 at addresses A and
1455 L1@A, L2@A, L3@B, ...
1457 BC_L could end up pointing at location L2, while the "master"
1458 location could be L1. Since the `loc->inserted' flag is only set
1459 on "master" locations, we'd forget to restore the shadow of L1
1462 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1465 /* Now do full processing of the found relevant range of elements. */
1467 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1469 struct bp_location
*bl
= bp_locations
[bc
];
1471 /* bp_location array has BL->OWNER always non-NULL. */
1472 if (bl
->owner
->type
== bp_none
)
1473 warning (_("reading through apparently deleted breakpoint #%d?"),
1476 /* Performance optimization: any further element can no longer affect BUF
1479 if (bl
->address
>= bp_locations_placed_address_before_address_max
1480 && memaddr
+ len
<= (bl
->address
1481 - bp_locations_placed_address_before_address_max
))
1484 if (!bp_location_has_shadow (bl
))
1487 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1488 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1492 /* See breakpoint.h. */
1495 is_breakpoint (const struct breakpoint
*bpt
)
1497 return (bpt
->type
== bp_breakpoint
1498 || bpt
->type
== bp_hardware_breakpoint
1499 || bpt
->type
== bp_dprintf
);
1502 /* Return true if BPT is of any hardware watchpoint kind. */
1505 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1507 return (bpt
->type
== bp_hardware_watchpoint
1508 || bpt
->type
== bp_read_watchpoint
1509 || bpt
->type
== bp_access_watchpoint
);
1512 /* See breakpoint.h. */
1515 is_watchpoint (const struct breakpoint
*bpt
)
1517 return (is_hardware_watchpoint (bpt
)
1518 || bpt
->type
== bp_watchpoint
);
1521 /* Returns true if the current thread and its running state are safe
1522 to evaluate or update watchpoint B. Watchpoints on local
1523 expressions need to be evaluated in the context of the thread that
1524 was current when the watchpoint was created, and, that thread needs
1525 to be stopped to be able to select the correct frame context.
1526 Watchpoints on global expressions can be evaluated on any thread,
1527 and in any state. It is presently left to the target allowing
1528 memory accesses when threads are running. */
1531 watchpoint_in_thread_scope (struct watchpoint
*b
)
1533 return (b
->pspace
== current_program_space
1534 && (b
->watchpoint_thread
== null_ptid
1535 || (inferior_ptid
== b
->watchpoint_thread
1536 && !inferior_thread ()->executing
)));
1539 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1540 associated bp_watchpoint_scope breakpoint. */
1543 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1545 if (w
->related_breakpoint
!= w
)
1547 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1548 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1549 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1550 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1551 w
->related_breakpoint
= w
;
1553 w
->disposition
= disp_del_at_next_stop
;
1556 /* Extract a bitfield value from value VAL using the bit parameters contained in
1559 static struct value
*
1560 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1562 struct value
*bit_val
;
1567 bit_val
= allocate_value (value_type (val
));
1569 unpack_value_bitfield (bit_val
,
1572 value_contents_for_printing (val
),
1579 /* Allocate a dummy location and add it to B, which must be a software
1580 watchpoint. This is required because even if a software watchpoint
1581 is not watching any memory, bpstat_stop_status requires a location
1582 to be able to report stops. */
1585 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1586 struct program_space
*pspace
)
1588 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1590 b
->loc
= allocate_bp_location (b
);
1591 b
->loc
->pspace
= pspace
;
1592 b
->loc
->address
= -1;
1593 b
->loc
->length
= -1;
1596 /* Returns true if B is a software watchpoint that is not watching any
1597 memory (e.g., "watch $pc"). */
1600 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1602 return (b
->type
== bp_watchpoint
1604 && b
->loc
->next
== NULL
1605 && b
->loc
->address
== -1
1606 && b
->loc
->length
== -1);
1609 /* Assuming that B is a watchpoint:
1610 - Reparse watchpoint expression, if REPARSE is non-zero
1611 - Evaluate expression and store the result in B->val
1612 - Evaluate the condition if there is one, and store the result
1614 - Update the list of values that must be watched in B->loc.
1616 If the watchpoint disposition is disp_del_at_next_stop, then do
1617 nothing. If this is local watchpoint that is out of scope, delete
1620 Even with `set breakpoint always-inserted on' the watchpoints are
1621 removed + inserted on each stop here. Normal breakpoints must
1622 never be removed because they might be missed by a running thread
1623 when debugging in non-stop mode. On the other hand, hardware
1624 watchpoints (is_hardware_watchpoint; processed here) are specific
1625 to each LWP since they are stored in each LWP's hardware debug
1626 registers. Therefore, such LWP must be stopped first in order to
1627 be able to modify its hardware watchpoints.
1629 Hardware watchpoints must be reset exactly once after being
1630 presented to the user. It cannot be done sooner, because it would
1631 reset the data used to present the watchpoint hit to the user. And
1632 it must not be done later because it could display the same single
1633 watchpoint hit during multiple GDB stops. Note that the latter is
1634 relevant only to the hardware watchpoint types bp_read_watchpoint
1635 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1636 not user-visible - its hit is suppressed if the memory content has
1639 The following constraints influence the location where we can reset
1640 hardware watchpoints:
1642 * target_stopped_by_watchpoint and target_stopped_data_address are
1643 called several times when GDB stops.
1646 * Multiple hardware watchpoints can be hit at the same time,
1647 causing GDB to stop. GDB only presents one hardware watchpoint
1648 hit at a time as the reason for stopping, and all the other hits
1649 are presented later, one after the other, each time the user
1650 requests the execution to be resumed. Execution is not resumed
1651 for the threads still having pending hit event stored in
1652 LWP_INFO->STATUS. While the watchpoint is already removed from
1653 the inferior on the first stop the thread hit event is kept being
1654 reported from its cached value by linux_nat_stopped_data_address
1655 until the real thread resume happens after the watchpoint gets
1656 presented and thus its LWP_INFO->STATUS gets reset.
1658 Therefore the hardware watchpoint hit can get safely reset on the
1659 watchpoint removal from inferior. */
1662 update_watchpoint (struct watchpoint
*b
, int reparse
)
1664 int within_current_scope
;
1665 struct frame_id saved_frame_id
;
1668 /* If this is a local watchpoint, we only want to check if the
1669 watchpoint frame is in scope if the current thread is the thread
1670 that was used to create the watchpoint. */
1671 if (!watchpoint_in_thread_scope (b
))
1674 if (b
->disposition
== disp_del_at_next_stop
)
1679 /* Determine if the watchpoint is within scope. */
1680 if (b
->exp_valid_block
== NULL
)
1681 within_current_scope
= 1;
1684 struct frame_info
*fi
= get_current_frame ();
1685 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1686 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1688 /* If we're at a point where the stack has been destroyed
1689 (e.g. in a function epilogue), unwinding may not work
1690 properly. Do not attempt to recreate locations at this
1691 point. See similar comments in watchpoint_check. */
1692 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1695 /* Save the current frame's ID so we can restore it after
1696 evaluating the watchpoint expression on its own frame. */
1697 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1698 took a frame parameter, so that we didn't have to change the
1701 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1703 fi
= frame_find_by_id (b
->watchpoint_frame
);
1704 within_current_scope
= (fi
!= NULL
);
1705 if (within_current_scope
)
1709 /* We don't free locations. They are stored in the bp_location array
1710 and update_global_location_list will eventually delete them and
1711 remove breakpoints if needed. */
1714 if (within_current_scope
&& reparse
)
1719 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1720 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1721 /* If the meaning of expression itself changed, the old value is
1722 no longer relevant. We don't want to report a watchpoint hit
1723 to the user when the old value and the new value may actually
1724 be completely different objects. */
1726 b
->val_valid
= false;
1728 /* Note that unlike with breakpoints, the watchpoint's condition
1729 expression is stored in the breakpoint object, not in the
1730 locations (re)created below. */
1731 if (b
->cond_string
!= NULL
)
1733 b
->cond_exp
.reset ();
1736 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1740 /* If we failed to parse the expression, for example because
1741 it refers to a global variable in a not-yet-loaded shared library,
1742 don't try to insert watchpoint. We don't automatically delete
1743 such watchpoint, though, since failure to parse expression
1744 is different from out-of-scope watchpoint. */
1745 if (!target_has_execution
)
1747 /* Without execution, memory can't change. No use to try and
1748 set watchpoint locations. The watchpoint will be reset when
1749 the target gains execution, through breakpoint_re_set. */
1750 if (!can_use_hw_watchpoints
)
1752 if (b
->ops
->works_in_software_mode (b
))
1753 b
->type
= bp_watchpoint
;
1755 error (_("Can't set read/access watchpoint when "
1756 "hardware watchpoints are disabled."));
1759 else if (within_current_scope
&& b
->exp
)
1762 std::vector
<value_ref_ptr
> val_chain
;
1763 struct value
*v
, *result
;
1764 struct program_space
*frame_pspace
;
1766 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1768 /* Avoid setting b->val if it's already set. The meaning of
1769 b->val is 'the last value' user saw, and we should update
1770 it only if we reported that last value to user. As it
1771 happens, the code that reports it updates b->val directly.
1772 We don't keep track of the memory value for masked
1774 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1776 if (b
->val_bitsize
!= 0)
1777 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1778 b
->val
= release_value (v
);
1779 b
->val_valid
= true;
1782 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1784 /* Look at each value on the value chain. */
1785 gdb_assert (!val_chain
.empty ());
1786 for (const value_ref_ptr
&iter
: val_chain
)
1790 /* If it's a memory location, and GDB actually needed
1791 its contents to evaluate the expression, then we
1792 must watch it. If the first value returned is
1793 still lazy, that means an error occurred reading it;
1794 watch it anyway in case it becomes readable. */
1795 if (VALUE_LVAL (v
) == lval_memory
1796 && (v
== val_chain
[0] || ! value_lazy (v
)))
1798 struct type
*vtype
= check_typedef (value_type (v
));
1800 /* We only watch structs and arrays if user asked
1801 for it explicitly, never if they just happen to
1802 appear in the middle of some value chain. */
1804 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1805 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1808 enum target_hw_bp_type type
;
1809 struct bp_location
*loc
, **tmp
;
1810 int bitpos
= 0, bitsize
= 0;
1812 if (value_bitsize (v
) != 0)
1814 /* Extract the bit parameters out from the bitfield
1816 bitpos
= value_bitpos (v
);
1817 bitsize
= value_bitsize (v
);
1819 else if (v
== result
&& b
->val_bitsize
!= 0)
1821 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1822 lvalue whose bit parameters are saved in the fields
1823 VAL_BITPOS and VAL_BITSIZE. */
1824 bitpos
= b
->val_bitpos
;
1825 bitsize
= b
->val_bitsize
;
1828 addr
= value_address (v
);
1831 /* Skip the bytes that don't contain the bitfield. */
1836 if (b
->type
== bp_read_watchpoint
)
1838 else if (b
->type
== bp_access_watchpoint
)
1841 loc
= allocate_bp_location (b
);
1842 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1845 loc
->gdbarch
= get_type_arch (value_type (v
));
1847 loc
->pspace
= frame_pspace
;
1848 loc
->address
= address_significant (loc
->gdbarch
, addr
);
1852 /* Just cover the bytes that make up the bitfield. */
1853 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1856 loc
->length
= TYPE_LENGTH (value_type (v
));
1858 loc
->watchpoint_type
= type
;
1863 /* Change the type of breakpoint between hardware assisted or
1864 an ordinary watchpoint depending on the hardware support
1865 and free hardware slots. REPARSE is set when the inferior
1870 enum bp_loc_type loc_type
;
1871 struct bp_location
*bl
;
1873 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1877 int i
, target_resources_ok
, other_type_used
;
1880 /* Use an exact watchpoint when there's only one memory region to be
1881 watched, and only one debug register is needed to watch it. */
1882 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1884 /* We need to determine how many resources are already
1885 used for all other hardware watchpoints plus this one
1886 to see if we still have enough resources to also fit
1887 this watchpoint in as well. */
1889 /* If this is a software watchpoint, we try to turn it
1890 to a hardware one -- count resources as if B was of
1891 hardware watchpoint type. */
1893 if (type
== bp_watchpoint
)
1894 type
= bp_hardware_watchpoint
;
1896 /* This watchpoint may or may not have been placed on
1897 the list yet at this point (it won't be in the list
1898 if we're trying to create it for the first time,
1899 through watch_command), so always account for it
1902 /* Count resources used by all watchpoints except B. */
1903 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1905 /* Add in the resources needed for B. */
1906 i
+= hw_watchpoint_use_count (b
);
1909 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1910 if (target_resources_ok
<= 0)
1912 int sw_mode
= b
->ops
->works_in_software_mode (b
);
1914 if (target_resources_ok
== 0 && !sw_mode
)
1915 error (_("Target does not support this type of "
1916 "hardware watchpoint."));
1917 else if (target_resources_ok
< 0 && !sw_mode
)
1918 error (_("There are not enough available hardware "
1919 "resources for this watchpoint."));
1921 /* Downgrade to software watchpoint. */
1922 b
->type
= bp_watchpoint
;
1926 /* If this was a software watchpoint, we've just
1927 found we have enough resources to turn it to a
1928 hardware watchpoint. Otherwise, this is a
1933 else if (!b
->ops
->works_in_software_mode (b
))
1935 if (!can_use_hw_watchpoints
)
1936 error (_("Can't set read/access watchpoint when "
1937 "hardware watchpoints are disabled."));
1939 error (_("Expression cannot be implemented with "
1940 "read/access watchpoint."));
1943 b
->type
= bp_watchpoint
;
1945 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1946 : bp_loc_hardware_watchpoint
);
1947 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1948 bl
->loc_type
= loc_type
;
1951 /* If a software watchpoint is not watching any memory, then the
1952 above left it without any location set up. But,
1953 bpstat_stop_status requires a location to be able to report
1954 stops, so make sure there's at least a dummy one. */
1955 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1956 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
1958 else if (!within_current_scope
)
1960 printf_filtered (_("\
1961 Watchpoint %d deleted because the program has left the block\n\
1962 in which its expression is valid.\n"),
1964 watchpoint_del_at_next_stop (b
);
1967 /* Restore the selected frame. */
1969 select_frame (frame_find_by_id (saved_frame_id
));
1973 /* Returns 1 iff breakpoint location should be
1974 inserted in the inferior. We don't differentiate the type of BL's owner
1975 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1976 breakpoint_ops is not defined, because in insert_bp_location,
1977 tracepoint's insert_location will not be called. */
1979 should_be_inserted (struct bp_location
*bl
)
1981 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1984 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1987 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1990 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
1993 /* This is set for example, when we're attached to the parent of a
1994 vfork, and have detached from the child. The child is running
1995 free, and we expect it to do an exec or exit, at which point the
1996 OS makes the parent schedulable again (and the target reports
1997 that the vfork is done). Until the child is done with the shared
1998 memory region, do not insert breakpoints in the parent, otherwise
1999 the child could still trip on the parent's breakpoints. Since
2000 the parent is blocked anyway, it won't miss any breakpoint. */
2001 if (bl
->pspace
->breakpoints_not_allowed
)
2004 /* Don't insert a breakpoint if we're trying to step past its
2005 location, except if the breakpoint is a single-step breakpoint,
2006 and the breakpoint's thread is the thread which is stepping past
2008 if ((bl
->loc_type
== bp_loc_software_breakpoint
2009 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2010 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2012 /* The single-step breakpoint may be inserted at the location
2013 we're trying to step if the instruction branches to itself.
2014 However, the instruction won't be executed at all and it may
2015 break the semantics of the instruction, for example, the
2016 instruction is a conditional branch or updates some flags.
2017 We can't fix it unless GDB is able to emulate the instruction
2018 or switch to displaced stepping. */
2019 && !(bl
->owner
->type
== bp_single_step
2020 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2024 fprintf_unfiltered (gdb_stdlog
,
2025 "infrun: skipping breakpoint: "
2026 "stepping past insn at: %s\n",
2027 paddress (bl
->gdbarch
, bl
->address
));
2032 /* Don't insert watchpoints if we're trying to step past the
2033 instruction that triggered one. */
2034 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2035 && stepping_past_nonsteppable_watchpoint ())
2039 fprintf_unfiltered (gdb_stdlog
,
2040 "infrun: stepping past non-steppable watchpoint. "
2041 "skipping watchpoint at %s:%d\n",
2042 paddress (bl
->gdbarch
, bl
->address
),
2051 /* Same as should_be_inserted but does the check assuming
2052 that the location is not duplicated. */
2055 unduplicated_should_be_inserted (struct bp_location
*bl
)
2058 const int save_duplicate
= bl
->duplicate
;
2061 result
= should_be_inserted (bl
);
2062 bl
->duplicate
= save_duplicate
;
2066 /* Parses a conditional described by an expression COND into an
2067 agent expression bytecode suitable for evaluation
2068 by the bytecode interpreter. Return NULL if there was
2069 any error during parsing. */
2071 static agent_expr_up
2072 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2077 agent_expr_up aexpr
;
2079 /* We don't want to stop processing, so catch any errors
2080 that may show up. */
2083 aexpr
= gen_eval_for_expr (scope
, cond
);
2086 catch (const gdb_exception_error
&ex
)
2088 /* If we got here, it means the condition could not be parsed to a valid
2089 bytecode expression and thus can't be evaluated on the target's side.
2090 It's no use iterating through the conditions. */
2093 /* We have a valid agent expression. */
2097 /* Based on location BL, create a list of breakpoint conditions to be
2098 passed on to the target. If we have duplicated locations with different
2099 conditions, we will add such conditions to the list. The idea is that the
2100 target will evaluate the list of conditions and will only notify GDB when
2101 one of them is true. */
2104 build_target_condition_list (struct bp_location
*bl
)
2106 struct bp_location
**locp
= NULL
, **loc2p
;
2107 int null_condition_or_parse_error
= 0;
2108 int modified
= bl
->needs_update
;
2109 struct bp_location
*loc
;
2111 /* Release conditions left over from a previous insert. */
2112 bl
->target_info
.conditions
.clear ();
2114 /* This is only meaningful if the target is
2115 evaluating conditions and if the user has
2116 opted for condition evaluation on the target's
2118 if (gdb_evaluates_breakpoint_condition_p ()
2119 || !target_supports_evaluation_of_breakpoint_conditions ())
2122 /* Do a first pass to check for locations with no assigned
2123 conditions or conditions that fail to parse to a valid agent expression
2124 bytecode. If any of these happen, then it's no use to send conditions
2125 to the target since this location will always trigger and generate a
2126 response back to GDB. */
2127 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2130 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2134 /* Re-parse the conditions since something changed. In that
2135 case we already freed the condition bytecodes (see
2136 force_breakpoint_reinsertion). We just
2137 need to parse the condition to bytecodes again. */
2138 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2142 /* If we have a NULL bytecode expression, it means something
2143 went wrong or we have a null condition expression. */
2144 if (!loc
->cond_bytecode
)
2146 null_condition_or_parse_error
= 1;
2152 /* If any of these happened, it means we will have to evaluate the conditions
2153 for the location's address on gdb's side. It is no use keeping bytecodes
2154 for all the other duplicate locations, thus we free all of them here.
2156 This is so we have a finer control over which locations' conditions are
2157 being evaluated by GDB or the remote stub. */
2158 if (null_condition_or_parse_error
)
2160 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2163 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2165 /* Only go as far as the first NULL bytecode is
2167 if (!loc
->cond_bytecode
)
2170 loc
->cond_bytecode
.reset ();
2175 /* No NULL conditions or failed bytecode generation. Build a condition list
2176 for this location's address. */
2177 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2181 && is_breakpoint (loc
->owner
)
2182 && loc
->pspace
->num
== bl
->pspace
->num
2183 && loc
->owner
->enable_state
== bp_enabled
2186 /* Add the condition to the vector. This will be used later
2187 to send the conditions to the target. */
2188 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2195 /* Parses a command described by string CMD into an agent expression
2196 bytecode suitable for evaluation by the bytecode interpreter.
2197 Return NULL if there was any error during parsing. */
2199 static agent_expr_up
2200 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2202 const char *cmdrest
;
2203 const char *format_start
, *format_end
;
2204 struct gdbarch
*gdbarch
= get_current_arch ();
2211 if (*cmdrest
== ',')
2213 cmdrest
= skip_spaces (cmdrest
);
2215 if (*cmdrest
++ != '"')
2216 error (_("No format string following the location"));
2218 format_start
= cmdrest
;
2220 format_pieces
fpieces (&cmdrest
);
2222 format_end
= cmdrest
;
2224 if (*cmdrest
++ != '"')
2225 error (_("Bad format string, non-terminated '\"'."));
2227 cmdrest
= skip_spaces (cmdrest
);
2229 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2230 error (_("Invalid argument syntax"));
2232 if (*cmdrest
== ',')
2234 cmdrest
= skip_spaces (cmdrest
);
2236 /* For each argument, make an expression. */
2238 std::vector
<struct expression
*> argvec
;
2239 while (*cmdrest
!= '\0')
2244 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2245 argvec
.push_back (expr
.release ());
2247 if (*cmdrest
== ',')
2251 agent_expr_up aexpr
;
2253 /* We don't want to stop processing, so catch any errors
2254 that may show up. */
2257 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2258 format_start
, format_end
- format_start
,
2259 argvec
.size (), argvec
.data ());
2261 catch (const gdb_exception_error
&ex
)
2263 /* If we got here, it means the command could not be parsed to a valid
2264 bytecode expression and thus can't be evaluated on the target's side.
2265 It's no use iterating through the other commands. */
2268 /* We have a valid agent expression, return it. */
2272 /* Based on location BL, create a list of breakpoint commands to be
2273 passed on to the target. If we have duplicated locations with
2274 different commands, we will add any such to the list. */
2277 build_target_command_list (struct bp_location
*bl
)
2279 struct bp_location
**locp
= NULL
, **loc2p
;
2280 int null_command_or_parse_error
= 0;
2281 int modified
= bl
->needs_update
;
2282 struct bp_location
*loc
;
2284 /* Clear commands left over from a previous insert. */
2285 bl
->target_info
.tcommands
.clear ();
2287 if (!target_can_run_breakpoint_commands ())
2290 /* For now, limit to agent-style dprintf breakpoints. */
2291 if (dprintf_style
!= dprintf_style_agent
)
2294 /* For now, if we have any duplicate location that isn't a dprintf,
2295 don't install the target-side commands, as that would make the
2296 breakpoint not be reported to the core, and we'd lose
2298 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2301 if (is_breakpoint (loc
->owner
)
2302 && loc
->pspace
->num
== bl
->pspace
->num
2303 && loc
->owner
->type
!= bp_dprintf
)
2307 /* Do a first pass to check for locations with no assigned
2308 conditions or conditions that fail to parse to a valid agent expression
2309 bytecode. If any of these happen, then it's no use to send conditions
2310 to the target since this location will always trigger and generate a
2311 response back to GDB. */
2312 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2315 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2319 /* Re-parse the commands since something changed. In that
2320 case we already freed the command bytecodes (see
2321 force_breakpoint_reinsertion). We just
2322 need to parse the command to bytecodes again. */
2324 = parse_cmd_to_aexpr (bl
->address
,
2325 loc
->owner
->extra_string
);
2328 /* If we have a NULL bytecode expression, it means something
2329 went wrong or we have a null command expression. */
2330 if (!loc
->cmd_bytecode
)
2332 null_command_or_parse_error
= 1;
2338 /* If anything failed, then we're not doing target-side commands,
2340 if (null_command_or_parse_error
)
2342 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2345 if (is_breakpoint (loc
->owner
)
2346 && loc
->pspace
->num
== bl
->pspace
->num
)
2348 /* Only go as far as the first NULL bytecode is
2350 if (loc
->cmd_bytecode
== NULL
)
2353 loc
->cmd_bytecode
.reset ();
2358 /* No NULL commands or failed bytecode generation. Build a command list
2359 for this location's address. */
2360 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2363 if (loc
->owner
->extra_string
2364 && is_breakpoint (loc
->owner
)
2365 && loc
->pspace
->num
== bl
->pspace
->num
2366 && loc
->owner
->enable_state
== bp_enabled
2369 /* Add the command to the vector. This will be used later
2370 to send the commands to the target. */
2371 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2375 bl
->target_info
.persist
= 0;
2376 /* Maybe flag this location as persistent. */
2377 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2378 bl
->target_info
.persist
= 1;
2381 /* Return the kind of breakpoint on address *ADDR. Get the kind
2382 of breakpoint according to ADDR except single-step breakpoint.
2383 Get the kind of single-step breakpoint according to the current
2387 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2389 if (bl
->owner
->type
== bp_single_step
)
2391 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2392 struct regcache
*regcache
;
2394 regcache
= get_thread_regcache (thr
);
2396 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2400 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2403 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2404 location. Any error messages are printed to TMP_ERROR_STREAM; and
2405 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2406 Returns 0 for success, 1 if the bp_location type is not supported or
2409 NOTE drow/2003-09-09: This routine could be broken down to an
2410 object-style method for each breakpoint or catchpoint type. */
2412 insert_bp_location (struct bp_location
*bl
,
2413 struct ui_file
*tmp_error_stream
,
2414 int *disabled_breaks
,
2415 int *hw_breakpoint_error
,
2416 int *hw_bp_error_explained_already
)
2418 gdb_exception bp_excpt
;
2420 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2423 /* Note we don't initialize bl->target_info, as that wipes out
2424 the breakpoint location's shadow_contents if the breakpoint
2425 is still inserted at that location. This in turn breaks
2426 target_read_memory which depends on these buffers when
2427 a memory read is requested at the breakpoint location:
2428 Once the target_info has been wiped, we fail to see that
2429 we have a breakpoint inserted at that address and thus
2430 read the breakpoint instead of returning the data saved in
2431 the breakpoint location's shadow contents. */
2432 bl
->target_info
.reqstd_address
= bl
->address
;
2433 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2434 bl
->target_info
.length
= bl
->length
;
2436 /* When working with target-side conditions, we must pass all the conditions
2437 for the same breakpoint address down to the target since GDB will not
2438 insert those locations. With a list of breakpoint conditions, the target
2439 can decide when to stop and notify GDB. */
2441 if (is_breakpoint (bl
->owner
))
2443 build_target_condition_list (bl
);
2444 build_target_command_list (bl
);
2445 /* Reset the modification marker. */
2446 bl
->needs_update
= 0;
2449 if (bl
->loc_type
== bp_loc_software_breakpoint
2450 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2452 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2454 /* If the explicitly specified breakpoint type
2455 is not hardware breakpoint, check the memory map to see
2456 if the breakpoint address is in read only memory or not.
2458 Two important cases are:
2459 - location type is not hardware breakpoint, memory
2460 is readonly. We change the type of the location to
2461 hardware breakpoint.
2462 - location type is hardware breakpoint, memory is
2463 read-write. This means we've previously made the
2464 location hardware one, but then the memory map changed,
2467 When breakpoints are removed, remove_breakpoints will use
2468 location types we've just set here, the only possible
2469 problem is that memory map has changed during running
2470 program, but it's not going to work anyway with current
2472 struct mem_region
*mr
2473 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2477 if (automatic_hardware_breakpoints
)
2479 enum bp_loc_type new_type
;
2481 if (mr
->attrib
.mode
!= MEM_RW
)
2482 new_type
= bp_loc_hardware_breakpoint
;
2484 new_type
= bp_loc_software_breakpoint
;
2486 if (new_type
!= bl
->loc_type
)
2488 static int said
= 0;
2490 bl
->loc_type
= new_type
;
2493 fprintf_filtered (gdb_stdout
,
2494 _("Note: automatically using "
2495 "hardware breakpoints for "
2496 "read-only addresses.\n"));
2501 else if (bl
->loc_type
== bp_loc_software_breakpoint
2502 && mr
->attrib
.mode
!= MEM_RW
)
2504 fprintf_unfiltered (tmp_error_stream
,
2505 _("Cannot insert breakpoint %d.\n"
2506 "Cannot set software breakpoint "
2507 "at read-only address %s\n"),
2509 paddress (bl
->gdbarch
, bl
->address
));
2515 /* First check to see if we have to handle an overlay. */
2516 if (overlay_debugging
== ovly_off
2517 || bl
->section
== NULL
2518 || !(section_is_overlay (bl
->section
)))
2520 /* No overlay handling: just set the breakpoint. */
2525 val
= bl
->owner
->ops
->insert_location (bl
);
2527 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2529 catch (gdb_exception
&e
)
2531 bp_excpt
= std::move (e
);
2536 /* This breakpoint is in an overlay section.
2537 Shall we set a breakpoint at the LMA? */
2538 if (!overlay_events_enabled
)
2540 /* Yes -- overlay event support is not active,
2541 so we must try to set a breakpoint at the LMA.
2542 This will not work for a hardware breakpoint. */
2543 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2544 warning (_("hardware breakpoint %d not supported in overlay!"),
2548 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2550 /* Set a software (trap) breakpoint at the LMA. */
2551 bl
->overlay_target_info
= bl
->target_info
;
2552 bl
->overlay_target_info
.reqstd_address
= addr
;
2554 /* No overlay handling: just set the breakpoint. */
2559 bl
->overlay_target_info
.kind
2560 = breakpoint_kind (bl
, &addr
);
2561 bl
->overlay_target_info
.placed_address
= addr
;
2562 val
= target_insert_breakpoint (bl
->gdbarch
,
2563 &bl
->overlay_target_info
);
2566 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2568 catch (gdb_exception
&e
)
2570 bp_excpt
= std::move (e
);
2573 if (bp_excpt
.reason
!= 0)
2574 fprintf_unfiltered (tmp_error_stream
,
2575 "Overlay breakpoint %d "
2576 "failed: in ROM?\n",
2580 /* Shall we set a breakpoint at the VMA? */
2581 if (section_is_mapped (bl
->section
))
2583 /* Yes. This overlay section is mapped into memory. */
2588 val
= bl
->owner
->ops
->insert_location (bl
);
2590 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2592 catch (gdb_exception
&e
)
2594 bp_excpt
= std::move (e
);
2599 /* No. This breakpoint will not be inserted.
2600 No error, but do not mark the bp as 'inserted'. */
2605 if (bp_excpt
.reason
!= 0)
2607 /* Can't set the breakpoint. */
2609 /* In some cases, we might not be able to insert a
2610 breakpoint in a shared library that has already been
2611 removed, but we have not yet processed the shlib unload
2612 event. Unfortunately, some targets that implement
2613 breakpoint insertion themselves can't tell why the
2614 breakpoint insertion failed (e.g., the remote target
2615 doesn't define error codes), so we must treat generic
2616 errors as memory errors. */
2617 if (bp_excpt
.reason
== RETURN_ERROR
2618 && (bp_excpt
.error
== GENERIC_ERROR
2619 || bp_excpt
.error
== MEMORY_ERROR
)
2620 && bl
->loc_type
== bp_loc_software_breakpoint
2621 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2622 || shared_objfile_contains_address_p (bl
->pspace
,
2625 /* See also: disable_breakpoints_in_shlibs. */
2626 bl
->shlib_disabled
= 1;
2627 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2628 if (!*disabled_breaks
)
2630 fprintf_unfiltered (tmp_error_stream
,
2631 "Cannot insert breakpoint %d.\n",
2633 fprintf_unfiltered (tmp_error_stream
,
2634 "Temporarily disabling shared "
2635 "library breakpoints:\n");
2637 *disabled_breaks
= 1;
2638 fprintf_unfiltered (tmp_error_stream
,
2639 "breakpoint #%d\n", bl
->owner
->number
);
2644 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2646 *hw_breakpoint_error
= 1;
2647 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2648 fprintf_unfiltered (tmp_error_stream
,
2649 "Cannot insert hardware breakpoint %d%s",
2651 bp_excpt
.message
? ":" : ".\n");
2652 if (bp_excpt
.message
!= NULL
)
2653 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2658 if (bp_excpt
.message
== NULL
)
2661 = memory_error_message (TARGET_XFER_E_IO
,
2662 bl
->gdbarch
, bl
->address
);
2664 fprintf_unfiltered (tmp_error_stream
,
2665 "Cannot insert breakpoint %d.\n"
2667 bl
->owner
->number
, message
.c_str ());
2671 fprintf_unfiltered (tmp_error_stream
,
2672 "Cannot insert breakpoint %d: %s\n",
2687 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2688 /* NOTE drow/2003-09-08: This state only exists for removing
2689 watchpoints. It's not clear that it's necessary... */
2690 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2694 gdb_assert (bl
->owner
->ops
!= NULL
2695 && bl
->owner
->ops
->insert_location
!= NULL
);
2697 val
= bl
->owner
->ops
->insert_location (bl
);
2699 /* If trying to set a read-watchpoint, and it turns out it's not
2700 supported, try emulating one with an access watchpoint. */
2701 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2703 struct bp_location
*loc
, **loc_temp
;
2705 /* But don't try to insert it, if there's already another
2706 hw_access location that would be considered a duplicate
2708 ALL_BP_LOCATIONS (loc
, loc_temp
)
2710 && loc
->watchpoint_type
== hw_access
2711 && watchpoint_locations_match (bl
, loc
))
2715 bl
->target_info
= loc
->target_info
;
2716 bl
->watchpoint_type
= hw_access
;
2723 bl
->watchpoint_type
= hw_access
;
2724 val
= bl
->owner
->ops
->insert_location (bl
);
2727 /* Back to the original value. */
2728 bl
->watchpoint_type
= hw_read
;
2732 bl
->inserted
= (val
== 0);
2735 else if (bl
->owner
->type
== bp_catchpoint
)
2739 gdb_assert (bl
->owner
->ops
!= NULL
2740 && bl
->owner
->ops
->insert_location
!= NULL
);
2742 val
= bl
->owner
->ops
->insert_location (bl
);
2745 bl
->owner
->enable_state
= bp_disabled
;
2749 Error inserting catchpoint %d: Your system does not support this type\n\
2750 of catchpoint."), bl
->owner
->number
);
2752 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2755 bl
->inserted
= (val
== 0);
2757 /* We've already printed an error message if there was a problem
2758 inserting this catchpoint, and we've disabled the catchpoint,
2759 so just return success. */
2766 /* This function is called when program space PSPACE is about to be
2767 deleted. It takes care of updating breakpoints to not reference
2771 breakpoint_program_space_exit (struct program_space
*pspace
)
2773 struct breakpoint
*b
, *b_temp
;
2774 struct bp_location
*loc
, **loc_temp
;
2776 /* Remove any breakpoint that was set through this program space. */
2777 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2779 if (b
->pspace
== pspace
)
2780 delete_breakpoint (b
);
2783 /* Breakpoints set through other program spaces could have locations
2784 bound to PSPACE as well. Remove those. */
2785 ALL_BP_LOCATIONS (loc
, loc_temp
)
2787 struct bp_location
*tmp
;
2789 if (loc
->pspace
== pspace
)
2791 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2792 if (loc
->owner
->loc
== loc
)
2793 loc
->owner
->loc
= loc
->next
;
2795 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2796 if (tmp
->next
== loc
)
2798 tmp
->next
= loc
->next
;
2804 /* Now update the global location list to permanently delete the
2805 removed locations above. */
2806 update_global_location_list (UGLL_DONT_INSERT
);
2809 /* Make sure all breakpoints are inserted in inferior.
2810 Throws exception on any error.
2811 A breakpoint that is already inserted won't be inserted
2812 again, so calling this function twice is safe. */
2814 insert_breakpoints (void)
2816 struct breakpoint
*bpt
;
2818 ALL_BREAKPOINTS (bpt
)
2819 if (is_hardware_watchpoint (bpt
))
2821 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2823 update_watchpoint (w
, 0 /* don't reparse. */);
2826 /* Updating watchpoints creates new locations, so update the global
2827 location list. Explicitly tell ugll to insert locations and
2828 ignore breakpoints_always_inserted_mode. */
2829 update_global_location_list (UGLL_INSERT
);
2832 /* Invoke CALLBACK for each of bp_location. */
2835 iterate_over_bp_locations (walk_bp_location_callback callback
)
2837 struct bp_location
*loc
, **loc_tmp
;
2839 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2841 callback (loc
, NULL
);
2845 /* This is used when we need to synch breakpoint conditions between GDB and the
2846 target. It is the case with deleting and disabling of breakpoints when using
2847 always-inserted mode. */
2850 update_inserted_breakpoint_locations (void)
2852 struct bp_location
*bl
, **blp_tmp
;
2855 int disabled_breaks
= 0;
2856 int hw_breakpoint_error
= 0;
2857 int hw_bp_details_reported
= 0;
2859 string_file tmp_error_stream
;
2861 /* Explicitly mark the warning -- this will only be printed if
2862 there was an error. */
2863 tmp_error_stream
.puts ("Warning:\n");
2865 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2867 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2869 /* We only want to update software breakpoints and hardware
2871 if (!is_breakpoint (bl
->owner
))
2874 /* We only want to update locations that are already inserted
2875 and need updating. This is to avoid unwanted insertion during
2876 deletion of breakpoints. */
2877 if (!bl
->inserted
|| !bl
->needs_update
)
2880 switch_to_program_space_and_thread (bl
->pspace
);
2882 /* For targets that support global breakpoints, there's no need
2883 to select an inferior to insert breakpoint to. In fact, even
2884 if we aren't attached to any process yet, we should still
2885 insert breakpoints. */
2886 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2887 && inferior_ptid
== null_ptid
)
2890 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2891 &hw_breakpoint_error
, &hw_bp_details_reported
);
2898 target_terminal::ours_for_output ();
2899 error_stream (tmp_error_stream
);
2903 /* Used when starting or continuing the program. */
2906 insert_breakpoint_locations (void)
2908 struct breakpoint
*bpt
;
2909 struct bp_location
*bl
, **blp_tmp
;
2912 int disabled_breaks
= 0;
2913 int hw_breakpoint_error
= 0;
2914 int hw_bp_error_explained_already
= 0;
2916 string_file tmp_error_stream
;
2918 /* Explicitly mark the warning -- this will only be printed if
2919 there was an error. */
2920 tmp_error_stream
.puts ("Warning:\n");
2922 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2924 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2926 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2929 /* There is no point inserting thread-specific breakpoints if
2930 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2931 has BL->OWNER always non-NULL. */
2932 if (bl
->owner
->thread
!= -1
2933 && !valid_global_thread_id (bl
->owner
->thread
))
2936 switch_to_program_space_and_thread (bl
->pspace
);
2938 /* For targets that support global breakpoints, there's no need
2939 to select an inferior to insert breakpoint to. In fact, even
2940 if we aren't attached to any process yet, we should still
2941 insert breakpoints. */
2942 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2943 && inferior_ptid
== null_ptid
)
2946 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2947 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
2952 /* If we failed to insert all locations of a watchpoint, remove
2953 them, as half-inserted watchpoint is of limited use. */
2954 ALL_BREAKPOINTS (bpt
)
2956 int some_failed
= 0;
2957 struct bp_location
*loc
;
2959 if (!is_hardware_watchpoint (bpt
))
2962 if (!breakpoint_enabled (bpt
))
2965 if (bpt
->disposition
== disp_del_at_next_stop
)
2968 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2969 if (!loc
->inserted
&& should_be_inserted (loc
))
2976 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2978 remove_breakpoint (loc
);
2980 hw_breakpoint_error
= 1;
2981 tmp_error_stream
.printf ("Could not insert "
2982 "hardware watchpoint %d.\n",
2990 /* If a hardware breakpoint or watchpoint was inserted, add a
2991 message about possibly exhausted resources. */
2992 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
2994 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
2995 You may have requested too many hardware breakpoints/watchpoints.\n");
2997 target_terminal::ours_for_output ();
2998 error_stream (tmp_error_stream
);
3002 /* Used when the program stops.
3003 Returns zero if successful, or non-zero if there was a problem
3004 removing a breakpoint location. */
3007 remove_breakpoints (void)
3009 struct bp_location
*bl
, **blp_tmp
;
3012 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3014 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3015 val
|= remove_breakpoint (bl
);
3020 /* When a thread exits, remove breakpoints that are related to
3024 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3026 struct breakpoint
*b
, *b_tmp
;
3028 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3030 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3032 b
->disposition
= disp_del_at_next_stop
;
3034 printf_filtered (_("\
3035 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3036 b
->number
, print_thread_id (tp
));
3038 /* Hide it from the user. */
3044 /* See breakpoint.h. */
3047 remove_breakpoints_inf (inferior
*inf
)
3049 struct bp_location
*bl
, **blp_tmp
;
3052 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3054 if (bl
->pspace
!= inf
->pspace
)
3057 if (bl
->inserted
&& !bl
->target_info
.persist
)
3059 val
= remove_breakpoint (bl
);
3066 static int internal_breakpoint_number
= -1;
3068 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3069 If INTERNAL is non-zero, the breakpoint number will be populated
3070 from internal_breakpoint_number and that variable decremented.
3071 Otherwise the breakpoint number will be populated from
3072 breakpoint_count and that value incremented. Internal breakpoints
3073 do not set the internal var bpnum. */
3075 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3078 b
->number
= internal_breakpoint_number
--;
3081 set_breakpoint_count (breakpoint_count
+ 1);
3082 b
->number
= breakpoint_count
;
3086 static struct breakpoint
*
3087 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3088 CORE_ADDR address
, enum bptype type
,
3089 const struct breakpoint_ops
*ops
)
3091 symtab_and_line sal
;
3093 sal
.section
= find_pc_overlay (sal
.pc
);
3094 sal
.pspace
= current_program_space
;
3096 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3097 b
->number
= internal_breakpoint_number
--;
3098 b
->disposition
= disp_donttouch
;
3103 static const char *const longjmp_names
[] =
3105 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3107 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3109 /* Per-objfile data private to breakpoint.c. */
3110 struct breakpoint_objfile_data
3112 /* Minimal symbol for "_ovly_debug_event" (if any). */
3113 struct bound_minimal_symbol overlay_msym
{};
3115 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3116 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3118 /* True if we have looked for longjmp probes. */
3119 int longjmp_searched
= 0;
3121 /* SystemTap probe points for longjmp (if any). These are non-owning
3123 std::vector
<probe
*> longjmp_probes
;
3125 /* Minimal symbol for "std::terminate()" (if any). */
3126 struct bound_minimal_symbol terminate_msym
{};
3128 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3129 struct bound_minimal_symbol exception_msym
{};
3131 /* True if we have looked for exception probes. */
3132 int exception_searched
= 0;
3134 /* SystemTap probe points for unwinding (if any). These are non-owning
3136 std::vector
<probe
*> exception_probes
;
3139 static const struct objfile_key
<breakpoint_objfile_data
>
3140 breakpoint_objfile_key
;
3142 /* Minimal symbol not found sentinel. */
3143 static struct minimal_symbol msym_not_found
;
3145 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3148 msym_not_found_p (const struct minimal_symbol
*msym
)
3150 return msym
== &msym_not_found
;
3153 /* Return per-objfile data needed by breakpoint.c.
3154 Allocate the data if necessary. */
3156 static struct breakpoint_objfile_data
*
3157 get_breakpoint_objfile_data (struct objfile
*objfile
)
3159 struct breakpoint_objfile_data
*bp_objfile_data
;
3161 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3162 if (bp_objfile_data
== NULL
)
3163 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3164 return bp_objfile_data
;
3168 create_overlay_event_breakpoint (void)
3170 const char *const func_name
= "_ovly_debug_event";
3172 for (objfile
*objfile
: current_program_space
->objfiles ())
3174 struct breakpoint
*b
;
3175 struct breakpoint_objfile_data
*bp_objfile_data
;
3177 struct explicit_location explicit_loc
;
3179 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3181 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3184 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3186 struct bound_minimal_symbol m
;
3188 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3189 if (m
.minsym
== NULL
)
3191 /* Avoid future lookups in this objfile. */
3192 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3195 bp_objfile_data
->overlay_msym
= m
;
3198 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3199 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3201 &internal_breakpoint_ops
);
3202 initialize_explicit_location (&explicit_loc
);
3203 explicit_loc
.function_name
= ASTRDUP (func_name
);
3204 b
->location
= new_explicit_location (&explicit_loc
);
3206 if (overlay_debugging
== ovly_auto
)
3208 b
->enable_state
= bp_enabled
;
3209 overlay_events_enabled
= 1;
3213 b
->enable_state
= bp_disabled
;
3214 overlay_events_enabled
= 0;
3220 create_longjmp_master_breakpoint (void)
3222 struct program_space
*pspace
;
3224 scoped_restore_current_program_space restore_pspace
;
3226 ALL_PSPACES (pspace
)
3228 set_current_program_space (pspace
);
3230 for (objfile
*objfile
: current_program_space
->objfiles ())
3233 struct gdbarch
*gdbarch
;
3234 struct breakpoint_objfile_data
*bp_objfile_data
;
3236 gdbarch
= get_objfile_arch (objfile
);
3238 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3240 if (!bp_objfile_data
->longjmp_searched
)
3242 std::vector
<probe
*> ret
3243 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3247 /* We are only interested in checking one element. */
3250 if (!p
->can_evaluate_arguments ())
3252 /* We cannot use the probe interface here, because it does
3253 not know how to evaluate arguments. */
3257 bp_objfile_data
->longjmp_probes
= ret
;
3258 bp_objfile_data
->longjmp_searched
= 1;
3261 if (!bp_objfile_data
->longjmp_probes
.empty ())
3263 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3265 struct breakpoint
*b
;
3267 b
= create_internal_breakpoint (gdbarch
,
3268 p
->get_relocated_address (objfile
),
3270 &internal_breakpoint_ops
);
3271 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3272 b
->enable_state
= bp_disabled
;
3278 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3281 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3283 struct breakpoint
*b
;
3284 const char *func_name
;
3286 struct explicit_location explicit_loc
;
3288 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3291 func_name
= longjmp_names
[i
];
3292 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3294 struct bound_minimal_symbol m
;
3296 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3297 if (m
.minsym
== NULL
)
3299 /* Prevent future lookups in this objfile. */
3300 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3303 bp_objfile_data
->longjmp_msym
[i
] = m
;
3306 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3307 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3308 &internal_breakpoint_ops
);
3309 initialize_explicit_location (&explicit_loc
);
3310 explicit_loc
.function_name
= ASTRDUP (func_name
);
3311 b
->location
= new_explicit_location (&explicit_loc
);
3312 b
->enable_state
= bp_disabled
;
3318 /* Create a master std::terminate breakpoint. */
3320 create_std_terminate_master_breakpoint (void)
3322 struct program_space
*pspace
;
3323 const char *const func_name
= "std::terminate()";
3325 scoped_restore_current_program_space restore_pspace
;
3327 ALL_PSPACES (pspace
)
3331 set_current_program_space (pspace
);
3333 for (objfile
*objfile
: current_program_space
->objfiles ())
3335 struct breakpoint
*b
;
3336 struct breakpoint_objfile_data
*bp_objfile_data
;
3337 struct explicit_location explicit_loc
;
3339 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3341 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3344 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3346 struct bound_minimal_symbol m
;
3348 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3349 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3350 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3352 /* Prevent future lookups in this objfile. */
3353 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3356 bp_objfile_data
->terminate_msym
= m
;
3359 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3360 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3361 bp_std_terminate_master
,
3362 &internal_breakpoint_ops
);
3363 initialize_explicit_location (&explicit_loc
);
3364 explicit_loc
.function_name
= ASTRDUP (func_name
);
3365 b
->location
= new_explicit_location (&explicit_loc
);
3366 b
->enable_state
= bp_disabled
;
3371 /* Install a master breakpoint on the unwinder's debug hook. */
3374 create_exception_master_breakpoint (void)
3376 const char *const func_name
= "_Unwind_DebugHook";
3378 for (objfile
*objfile
: current_program_space
->objfiles ())
3380 struct breakpoint
*b
;
3381 struct gdbarch
*gdbarch
;
3382 struct breakpoint_objfile_data
*bp_objfile_data
;
3384 struct explicit_location explicit_loc
;
3386 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3388 /* We prefer the SystemTap probe point if it exists. */
3389 if (!bp_objfile_data
->exception_searched
)
3391 std::vector
<probe
*> ret
3392 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3396 /* We are only interested in checking one element. */
3399 if (!p
->can_evaluate_arguments ())
3401 /* We cannot use the probe interface here, because it does
3402 not know how to evaluate arguments. */
3406 bp_objfile_data
->exception_probes
= ret
;
3407 bp_objfile_data
->exception_searched
= 1;
3410 if (!bp_objfile_data
->exception_probes
.empty ())
3412 gdbarch
= get_objfile_arch (objfile
);
3414 for (probe
*p
: bp_objfile_data
->exception_probes
)
3416 b
= create_internal_breakpoint (gdbarch
,
3417 p
->get_relocated_address (objfile
),
3418 bp_exception_master
,
3419 &internal_breakpoint_ops
);
3420 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3421 b
->enable_state
= bp_disabled
;
3427 /* Otherwise, try the hook function. */
3429 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3432 gdbarch
= get_objfile_arch (objfile
);
3434 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3436 struct bound_minimal_symbol debug_hook
;
3438 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3439 if (debug_hook
.minsym
== NULL
)
3441 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3445 bp_objfile_data
->exception_msym
= debug_hook
;
3448 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3449 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3450 current_top_target ());
3451 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3452 &internal_breakpoint_ops
);
3453 initialize_explicit_location (&explicit_loc
);
3454 explicit_loc
.function_name
= ASTRDUP (func_name
);
3455 b
->location
= new_explicit_location (&explicit_loc
);
3456 b
->enable_state
= bp_disabled
;
3460 /* Does B have a location spec? */
3463 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3465 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3469 update_breakpoints_after_exec (void)
3471 struct breakpoint
*b
, *b_tmp
;
3472 struct bp_location
*bploc
, **bplocp_tmp
;
3474 /* We're about to delete breakpoints from GDB's lists. If the
3475 INSERTED flag is true, GDB will try to lift the breakpoints by
3476 writing the breakpoints' "shadow contents" back into memory. The
3477 "shadow contents" are NOT valid after an exec, so GDB should not
3478 do that. Instead, the target is responsible from marking
3479 breakpoints out as soon as it detects an exec. We don't do that
3480 here instead, because there may be other attempts to delete
3481 breakpoints after detecting an exec and before reaching here. */
3482 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3483 if (bploc
->pspace
== current_program_space
)
3484 gdb_assert (!bploc
->inserted
);
3486 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3488 if (b
->pspace
!= current_program_space
)
3491 /* Solib breakpoints must be explicitly reset after an exec(). */
3492 if (b
->type
== bp_shlib_event
)
3494 delete_breakpoint (b
);
3498 /* JIT breakpoints must be explicitly reset after an exec(). */
3499 if (b
->type
== bp_jit_event
)
3501 delete_breakpoint (b
);
3505 /* Thread event breakpoints must be set anew after an exec(),
3506 as must overlay event and longjmp master breakpoints. */
3507 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3508 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3509 || b
->type
== bp_exception_master
)
3511 delete_breakpoint (b
);
3515 /* Step-resume breakpoints are meaningless after an exec(). */
3516 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3518 delete_breakpoint (b
);
3522 /* Just like single-step breakpoints. */
3523 if (b
->type
== bp_single_step
)
3525 delete_breakpoint (b
);
3529 /* Longjmp and longjmp-resume breakpoints are also meaningless
3531 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3532 || b
->type
== bp_longjmp_call_dummy
3533 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3535 delete_breakpoint (b
);
3539 if (b
->type
== bp_catchpoint
)
3541 /* For now, none of the bp_catchpoint breakpoints need to
3542 do anything at this point. In the future, if some of
3543 the catchpoints need to something, we will need to add
3544 a new method, and call this method from here. */
3548 /* bp_finish is a special case. The only way we ought to be able
3549 to see one of these when an exec() has happened, is if the user
3550 caught a vfork, and then said "finish". Ordinarily a finish just
3551 carries them to the call-site of the current callee, by setting
3552 a temporary bp there and resuming. But in this case, the finish
3553 will carry them entirely through the vfork & exec.
3555 We don't want to allow a bp_finish to remain inserted now. But
3556 we can't safely delete it, 'cause finish_command has a handle to
3557 the bp on a bpstat, and will later want to delete it. There's a
3558 chance (and I've seen it happen) that if we delete the bp_finish
3559 here, that its storage will get reused by the time finish_command
3560 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3561 We really must allow finish_command to delete a bp_finish.
3563 In the absence of a general solution for the "how do we know
3564 it's safe to delete something others may have handles to?"
3565 problem, what we'll do here is just uninsert the bp_finish, and
3566 let finish_command delete it.
3568 (We know the bp_finish is "doomed" in the sense that it's
3569 momentary, and will be deleted as soon as finish_command sees
3570 the inferior stopped. So it doesn't matter that the bp's
3571 address is probably bogus in the new a.out, unlike e.g., the
3572 solib breakpoints.) */
3574 if (b
->type
== bp_finish
)
3579 /* Without a symbolic address, we have little hope of the
3580 pre-exec() address meaning the same thing in the post-exec()
3582 if (breakpoint_event_location_empty_p (b
))
3584 delete_breakpoint (b
);
3591 detach_breakpoints (ptid_t ptid
)
3593 struct bp_location
*bl
, **blp_tmp
;
3595 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3596 struct inferior
*inf
= current_inferior ();
3598 if (ptid
.pid () == inferior_ptid
.pid ())
3599 error (_("Cannot detach breakpoints of inferior_ptid"));
3601 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3602 inferior_ptid
= ptid
;
3603 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3605 if (bl
->pspace
!= inf
->pspace
)
3608 /* This function must physically remove breakpoints locations
3609 from the specified ptid, without modifying the breakpoint
3610 package's state. Locations of type bp_loc_other are only
3611 maintained at GDB side. So, there is no need to remove
3612 these bp_loc_other locations. Moreover, removing these
3613 would modify the breakpoint package's state. */
3614 if (bl
->loc_type
== bp_loc_other
)
3618 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3624 /* Remove the breakpoint location BL from the current address space.
3625 Note that this is used to detach breakpoints from a child fork.
3626 When we get here, the child isn't in the inferior list, and neither
3627 do we have objects to represent its address space --- we should
3628 *not* look at bl->pspace->aspace here. */
3631 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3635 /* BL is never in moribund_locations by our callers. */
3636 gdb_assert (bl
->owner
!= NULL
);
3638 /* The type of none suggests that owner is actually deleted.
3639 This should not ever happen. */
3640 gdb_assert (bl
->owner
->type
!= bp_none
);
3642 if (bl
->loc_type
== bp_loc_software_breakpoint
3643 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3645 /* "Normal" instruction breakpoint: either the standard
3646 trap-instruction bp (bp_breakpoint), or a
3647 bp_hardware_breakpoint. */
3649 /* First check to see if we have to handle an overlay. */
3650 if (overlay_debugging
== ovly_off
3651 || bl
->section
== NULL
3652 || !(section_is_overlay (bl
->section
)))
3654 /* No overlay handling: just remove the breakpoint. */
3656 /* If we're trying to uninsert a memory breakpoint that we
3657 know is set in a dynamic object that is marked
3658 shlib_disabled, then either the dynamic object was
3659 removed with "remove-symbol-file" or with
3660 "nosharedlibrary". In the former case, we don't know
3661 whether another dynamic object might have loaded over the
3662 breakpoint's address -- the user might well let us know
3663 about it next with add-symbol-file (the whole point of
3664 add-symbol-file is letting the user manually maintain a
3665 list of dynamically loaded objects). If we have the
3666 breakpoint's shadow memory, that is, this is a software
3667 breakpoint managed by GDB, check whether the breakpoint
3668 is still inserted in memory, to avoid overwriting wrong
3669 code with stale saved shadow contents. Note that HW
3670 breakpoints don't have shadow memory, as they're
3671 implemented using a mechanism that is not dependent on
3672 being able to modify the target's memory, and as such
3673 they should always be removed. */
3674 if (bl
->shlib_disabled
3675 && bl
->target_info
.shadow_len
!= 0
3676 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3679 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3683 /* This breakpoint is in an overlay section.
3684 Did we set a breakpoint at the LMA? */
3685 if (!overlay_events_enabled
)
3687 /* Yes -- overlay event support is not active, so we
3688 should have set a breakpoint at the LMA. Remove it.
3690 /* Ignore any failures: if the LMA is in ROM, we will
3691 have already warned when we failed to insert it. */
3692 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3693 target_remove_hw_breakpoint (bl
->gdbarch
,
3694 &bl
->overlay_target_info
);
3696 target_remove_breakpoint (bl
->gdbarch
,
3697 &bl
->overlay_target_info
,
3700 /* Did we set a breakpoint at the VMA?
3701 If so, we will have marked the breakpoint 'inserted'. */
3704 /* Yes -- remove it. Previously we did not bother to
3705 remove the breakpoint if the section had been
3706 unmapped, but let's not rely on that being safe. We
3707 don't know what the overlay manager might do. */
3709 /* However, we should remove *software* breakpoints only
3710 if the section is still mapped, or else we overwrite
3711 wrong code with the saved shadow contents. */
3712 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3713 || section_is_mapped (bl
->section
))
3714 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3720 /* No -- not inserted, so no need to remove. No error. */
3725 /* In some cases, we might not be able to remove a breakpoint in
3726 a shared library that has already been removed, but we have
3727 not yet processed the shlib unload event. Similarly for an
3728 unloaded add-symbol-file object - the user might not yet have
3729 had the chance to remove-symbol-file it. shlib_disabled will
3730 be set if the library/object has already been removed, but
3731 the breakpoint hasn't been uninserted yet, e.g., after
3732 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3733 always-inserted mode. */
3735 && (bl
->loc_type
== bp_loc_software_breakpoint
3736 && (bl
->shlib_disabled
3737 || solib_name_from_address (bl
->pspace
, bl
->address
)
3738 || shared_objfile_contains_address_p (bl
->pspace
,
3744 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3746 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3748 gdb_assert (bl
->owner
->ops
!= NULL
3749 && bl
->owner
->ops
->remove_location
!= NULL
);
3751 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3752 bl
->owner
->ops
->remove_location (bl
, reason
);
3754 /* Failure to remove any of the hardware watchpoints comes here. */
3755 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3756 warning (_("Could not remove hardware watchpoint %d."),
3759 else if (bl
->owner
->type
== bp_catchpoint
3760 && breakpoint_enabled (bl
->owner
)
3763 gdb_assert (bl
->owner
->ops
!= NULL
3764 && bl
->owner
->ops
->remove_location
!= NULL
);
3766 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3770 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3777 remove_breakpoint (struct bp_location
*bl
)
3779 /* BL is never in moribund_locations by our callers. */
3780 gdb_assert (bl
->owner
!= NULL
);
3782 /* The type of none suggests that owner is actually deleted.
3783 This should not ever happen. */
3784 gdb_assert (bl
->owner
->type
!= bp_none
);
3786 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3788 switch_to_program_space_and_thread (bl
->pspace
);
3790 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3793 /* Clear the "inserted" flag in all breakpoints. */
3796 mark_breakpoints_out (void)
3798 struct bp_location
*bl
, **blp_tmp
;
3800 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3801 if (bl
->pspace
== current_program_space
)
3805 /* Clear the "inserted" flag in all breakpoints and delete any
3806 breakpoints which should go away between runs of the program.
3808 Plus other such housekeeping that has to be done for breakpoints
3811 Note: this function gets called at the end of a run (by
3812 generic_mourn_inferior) and when a run begins (by
3813 init_wait_for_inferior). */
3818 breakpoint_init_inferior (enum inf_context context
)
3820 struct breakpoint
*b
, *b_tmp
;
3821 struct program_space
*pspace
= current_program_space
;
3823 /* If breakpoint locations are shared across processes, then there's
3825 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3828 mark_breakpoints_out ();
3830 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3832 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3838 case bp_longjmp_call_dummy
:
3840 /* If the call dummy breakpoint is at the entry point it will
3841 cause problems when the inferior is rerun, so we better get
3844 case bp_watchpoint_scope
:
3846 /* Also get rid of scope breakpoints. */
3848 case bp_shlib_event
:
3850 /* Also remove solib event breakpoints. Their addresses may
3851 have changed since the last time we ran the program.
3852 Actually we may now be debugging against different target;
3853 and so the solib backend that installed this breakpoint may
3854 not be used in by the target. E.g.,
3856 (gdb) file prog-linux
3857 (gdb) run # native linux target
3860 (gdb) file prog-win.exe
3861 (gdb) tar rem :9999 # remote Windows gdbserver.
3864 case bp_step_resume
:
3866 /* Also remove step-resume breakpoints. */
3868 case bp_single_step
:
3870 /* Also remove single-step breakpoints. */
3872 delete_breakpoint (b
);
3876 case bp_hardware_watchpoint
:
3877 case bp_read_watchpoint
:
3878 case bp_access_watchpoint
:
3880 struct watchpoint
*w
= (struct watchpoint
*) b
;
3882 /* Likewise for watchpoints on local expressions. */
3883 if (w
->exp_valid_block
!= NULL
)
3884 delete_breakpoint (b
);
3887 /* Get rid of existing locations, which are no longer
3888 valid. New ones will be created in
3889 update_watchpoint, when the inferior is restarted.
3890 The next update_global_location_list call will
3891 garbage collect them. */
3894 if (context
== inf_starting
)
3896 /* Reset val field to force reread of starting value in
3897 insert_breakpoints. */
3898 w
->val
.reset (nullptr);
3899 w
->val_valid
= false;
3909 /* Get rid of the moribund locations. */
3910 for (bp_location
*bl
: moribund_locations
)
3911 decref_bp_location (&bl
);
3912 moribund_locations
.clear ();
3915 /* These functions concern about actual breakpoints inserted in the
3916 target --- to e.g. check if we need to do decr_pc adjustment or if
3917 we need to hop over the bkpt --- so we check for address space
3918 match, not program space. */
3920 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3921 exists at PC. It returns ordinary_breakpoint_here if it's an
3922 ordinary breakpoint, or permanent_breakpoint_here if it's a
3923 permanent breakpoint.
3924 - When continuing from a location with an ordinary breakpoint, we
3925 actually single step once before calling insert_breakpoints.
3926 - When continuing from a location with a permanent breakpoint, we
3927 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3928 the target, to advance the PC past the breakpoint. */
3930 enum breakpoint_here
3931 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
3933 struct bp_location
*bl
, **blp_tmp
;
3934 int any_breakpoint_here
= 0;
3936 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3938 if (bl
->loc_type
!= bp_loc_software_breakpoint
3939 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3942 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3943 if ((breakpoint_enabled (bl
->owner
)
3945 && breakpoint_location_address_match (bl
, aspace
, pc
))
3947 if (overlay_debugging
3948 && section_is_overlay (bl
->section
)
3949 && !section_is_mapped (bl
->section
))
3950 continue; /* unmapped overlay -- can't be a match */
3951 else if (bl
->permanent
)
3952 return permanent_breakpoint_here
;
3954 any_breakpoint_here
= 1;
3958 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
3961 /* See breakpoint.h. */
3964 breakpoint_in_range_p (const address_space
*aspace
,
3965 CORE_ADDR addr
, ULONGEST len
)
3967 struct bp_location
*bl
, **blp_tmp
;
3969 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3971 if (bl
->loc_type
!= bp_loc_software_breakpoint
3972 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3975 if ((breakpoint_enabled (bl
->owner
)
3977 && breakpoint_location_address_range_overlap (bl
, aspace
,
3980 if (overlay_debugging
3981 && section_is_overlay (bl
->section
)
3982 && !section_is_mapped (bl
->section
))
3984 /* Unmapped overlay -- can't be a match. */
3995 /* Return true if there's a moribund breakpoint at PC. */
3998 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4000 for (bp_location
*loc
: moribund_locations
)
4001 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4007 /* Returns non-zero iff BL is inserted at PC, in address space
4011 bp_location_inserted_here_p (struct bp_location
*bl
,
4012 const address_space
*aspace
, CORE_ADDR pc
)
4015 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4018 if (overlay_debugging
4019 && section_is_overlay (bl
->section
)
4020 && !section_is_mapped (bl
->section
))
4021 return 0; /* unmapped overlay -- can't be a match */
4028 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4031 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4033 struct bp_location
**blp
, **blp_tmp
= NULL
;
4035 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4037 struct bp_location
*bl
= *blp
;
4039 if (bl
->loc_type
!= bp_loc_software_breakpoint
4040 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4043 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4049 /* This function returns non-zero iff there is a software breakpoint
4053 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4056 struct bp_location
**blp
, **blp_tmp
= NULL
;
4058 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4060 struct bp_location
*bl
= *blp
;
4062 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4065 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4072 /* See breakpoint.h. */
4075 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4078 struct bp_location
**blp
, **blp_tmp
= NULL
;
4080 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4082 struct bp_location
*bl
= *blp
;
4084 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4087 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4095 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4096 CORE_ADDR addr
, ULONGEST len
)
4098 struct breakpoint
*bpt
;
4100 ALL_BREAKPOINTS (bpt
)
4102 struct bp_location
*loc
;
4104 if (bpt
->type
!= bp_hardware_watchpoint
4105 && bpt
->type
!= bp_access_watchpoint
)
4108 if (!breakpoint_enabled (bpt
))
4111 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4112 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4116 /* Check for intersection. */
4117 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4118 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4126 /* See breakpoint.h. */
4129 is_catchpoint (struct breakpoint
*b
)
4131 return (b
->type
== bp_catchpoint
);
4134 /* Frees any storage that is part of a bpstat. Does not walk the
4137 bpstats::~bpstats ()
4139 if (bp_location_at
!= NULL
)
4140 decref_bp_location (&bp_location_at
);
4143 /* Clear a bpstat so that it says we are not at any breakpoint.
4144 Also free any storage that is part of a bpstat. */
4147 bpstat_clear (bpstat
*bsp
)
4164 bpstats::bpstats (const bpstats
&other
)
4166 bp_location_at (other
.bp_location_at
),
4167 breakpoint_at (other
.breakpoint_at
),
4168 commands (other
.commands
),
4169 print (other
.print
),
4171 print_it (other
.print_it
)
4173 if (other
.old_val
!= NULL
)
4174 old_val
= release_value (value_copy (other
.old_val
.get ()));
4175 incref_bp_location (bp_location_at
);
4178 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4179 is part of the bpstat is copied as well. */
4182 bpstat_copy (bpstat bs
)
4186 bpstat retval
= NULL
;
4191 for (; bs
!= NULL
; bs
= bs
->next
)
4193 tmp
= new bpstats (*bs
);
4196 /* This is the first thing in the chain. */
4206 /* Find the bpstat associated with this breakpoint. */
4209 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4214 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4216 if (bsp
->breakpoint_at
== breakpoint
)
4222 /* See breakpoint.h. */
4225 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4227 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4229 if (bsp
->breakpoint_at
== NULL
)
4231 /* A moribund location can never explain a signal other than
4233 if (sig
== GDB_SIGNAL_TRAP
)
4238 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4247 /* Put in *NUM the breakpoint number of the first breakpoint we are
4248 stopped at. *BSP upon return is a bpstat which points to the
4249 remaining breakpoints stopped at (but which is not guaranteed to be
4250 good for anything but further calls to bpstat_num).
4252 Return 0 if passed a bpstat which does not indicate any breakpoints.
4253 Return -1 if stopped at a breakpoint that has been deleted since
4255 Return 1 otherwise. */
4258 bpstat_num (bpstat
*bsp
, int *num
)
4260 struct breakpoint
*b
;
4263 return 0; /* No more breakpoint values */
4265 /* We assume we'll never have several bpstats that correspond to a
4266 single breakpoint -- otherwise, this function might return the
4267 same number more than once and this will look ugly. */
4268 b
= (*bsp
)->breakpoint_at
;
4269 *bsp
= (*bsp
)->next
;
4271 return -1; /* breakpoint that's been deleted since */
4273 *num
= b
->number
; /* We have its number */
4277 /* See breakpoint.h. */
4280 bpstat_clear_actions (void)
4284 if (inferior_ptid
== null_ptid
)
4287 thread_info
*tp
= inferior_thread ();
4288 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4290 bs
->commands
= NULL
;
4291 bs
->old_val
.reset (nullptr);
4295 /* Called when a command is about to proceed the inferior. */
4298 breakpoint_about_to_proceed (void)
4300 if (inferior_ptid
!= null_ptid
)
4302 struct thread_info
*tp
= inferior_thread ();
4304 /* Allow inferior function calls in breakpoint commands to not
4305 interrupt the command list. When the call finishes
4306 successfully, the inferior will be standing at the same
4307 breakpoint as if nothing happened. */
4308 if (tp
->control
.in_infcall
)
4312 breakpoint_proceeded
= 1;
4315 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4316 or its equivalent. */
4319 command_line_is_silent (struct command_line
*cmd
)
4321 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4324 /* Execute all the commands associated with all the breakpoints at
4325 this location. Any of these commands could cause the process to
4326 proceed beyond this point, etc. We look out for such changes by
4327 checking the global "breakpoint_proceeded" after each command.
4329 Returns true if a breakpoint command resumed the inferior. In that
4330 case, it is the caller's responsibility to recall it again with the
4331 bpstat of the current thread. */
4334 bpstat_do_actions_1 (bpstat
*bsp
)
4339 /* Avoid endless recursion if a `source' command is contained
4341 if (executing_breakpoint_commands
)
4344 scoped_restore save_executing
4345 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4347 scoped_restore preventer
= prevent_dont_repeat ();
4349 /* This pointer will iterate over the list of bpstat's. */
4352 breakpoint_proceeded
= 0;
4353 for (; bs
!= NULL
; bs
= bs
->next
)
4355 struct command_line
*cmd
= NULL
;
4357 /* Take ownership of the BSP's command tree, if it has one.
4359 The command tree could legitimately contain commands like
4360 'step' and 'next', which call clear_proceed_status, which
4361 frees stop_bpstat's command tree. To make sure this doesn't
4362 free the tree we're executing out from under us, we need to
4363 take ownership of the tree ourselves. Since a given bpstat's
4364 commands are only executed once, we don't need to copy it; we
4365 can clear the pointer in the bpstat, and make sure we free
4366 the tree when we're done. */
4367 counted_command_line ccmd
= bs
->commands
;
4368 bs
->commands
= NULL
;
4371 if (command_line_is_silent (cmd
))
4373 /* The action has been already done by bpstat_stop_status. */
4379 execute_control_command (cmd
);
4381 if (breakpoint_proceeded
)
4387 if (breakpoint_proceeded
)
4389 if (current_ui
->async
)
4390 /* If we are in async mode, then the target might be still
4391 running, not stopped at any breakpoint, so nothing for
4392 us to do here -- just return to the event loop. */
4395 /* In sync mode, when execute_control_command returns
4396 we're already standing on the next breakpoint.
4397 Breakpoint commands for that stop were not run, since
4398 execute_command does not run breakpoint commands --
4399 only command_line_handler does, but that one is not
4400 involved in execution of breakpoint commands. So, we
4401 can now execute breakpoint commands. It should be
4402 noted that making execute_command do bpstat actions is
4403 not an option -- in this case we'll have recursive
4404 invocation of bpstat for each breakpoint with a
4405 command, and can easily blow up GDB stack. Instead, we
4406 return true, which will trigger the caller to recall us
4407 with the new stop_bpstat. */
4415 /* Helper for bpstat_do_actions. Get the current thread, if there's
4416 one, is alive and has execution. Return NULL otherwise. */
4418 static thread_info
*
4419 get_bpstat_thread ()
4421 if (inferior_ptid
== null_ptid
|| !target_has_execution
)
4424 thread_info
*tp
= inferior_thread ();
4425 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4431 bpstat_do_actions (void)
4433 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4436 /* Do any commands attached to breakpoint we are stopped at. */
4437 while ((tp
= get_bpstat_thread ()) != NULL
)
4439 /* Since in sync mode, bpstat_do_actions may resume the
4440 inferior, and only return when it is stopped at the next
4441 breakpoint, we keep doing breakpoint actions until it returns
4442 false to indicate the inferior was not resumed. */
4443 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4447 cleanup_if_error
.release ();
4450 /* Print out the (old or new) value associated with a watchpoint. */
4453 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4456 fprintf_styled (stream
, metadata_style
.style (), _("<unreadable>"));
4459 struct value_print_options opts
;
4460 get_user_print_options (&opts
);
4461 value_print (val
, stream
, &opts
);
4465 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4466 debugging multiple threads. */
4469 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4471 if (uiout
->is_mi_like_p ())
4476 if (show_thread_that_caused_stop ())
4479 struct thread_info
*thr
= inferior_thread ();
4481 uiout
->text ("Thread ");
4482 uiout
->field_string ("thread-id", print_thread_id (thr
));
4484 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4487 uiout
->text (" \"");
4488 uiout
->field_string ("name", name
);
4492 uiout
->text (" hit ");
4496 /* Generic routine for printing messages indicating why we
4497 stopped. The behavior of this function depends on the value
4498 'print_it' in the bpstat structure. Under some circumstances we
4499 may decide not to print anything here and delegate the task to
4502 static enum print_stop_action
4503 print_bp_stop_message (bpstat bs
)
4505 switch (bs
->print_it
)
4508 /* Nothing should be printed for this bpstat entry. */
4509 return PRINT_UNKNOWN
;
4513 /* We still want to print the frame, but we already printed the
4514 relevant messages. */
4515 return PRINT_SRC_AND_LOC
;
4518 case print_it_normal
:
4520 struct breakpoint
*b
= bs
->breakpoint_at
;
4522 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4523 which has since been deleted. */
4525 return PRINT_UNKNOWN
;
4527 /* Normal case. Call the breakpoint's print_it method. */
4528 return b
->ops
->print_it (bs
);
4533 internal_error (__FILE__
, __LINE__
,
4534 _("print_bp_stop_message: unrecognized enum value"));
4539 /* A helper function that prints a shared library stopped event. */
4542 print_solib_event (int is_catchpoint
)
4544 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4545 bool any_added
= !current_program_space
->added_solibs
.empty ();
4549 if (any_added
|| any_deleted
)
4550 current_uiout
->text (_("Stopped due to shared library event:\n"));
4552 current_uiout
->text (_("Stopped due to shared library event (no "
4553 "libraries added or removed)\n"));
4556 if (current_uiout
->is_mi_like_p ())
4557 current_uiout
->field_string ("reason",
4558 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4562 current_uiout
->text (_(" Inferior unloaded "));
4563 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4564 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4566 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4569 current_uiout
->text (" ");
4570 current_uiout
->field_string ("library", name
);
4571 current_uiout
->text ("\n");
4577 current_uiout
->text (_(" Inferior loaded "));
4578 ui_out_emit_list
list_emitter (current_uiout
, "added");
4580 for (so_list
*iter
: current_program_space
->added_solibs
)
4583 current_uiout
->text (" ");
4585 current_uiout
->field_string ("library", iter
->so_name
);
4586 current_uiout
->text ("\n");
4591 /* Print a message indicating what happened. This is called from
4592 normal_stop(). The input to this routine is the head of the bpstat
4593 list - a list of the eventpoints that caused this stop. KIND is
4594 the target_waitkind for the stopping event. This
4595 routine calls the generic print routine for printing a message
4596 about reasons for stopping. This will print (for example) the
4597 "Breakpoint n," part of the output. The return value of this
4600 PRINT_UNKNOWN: Means we printed nothing.
4601 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4602 code to print the location. An example is
4603 "Breakpoint 1, " which should be followed by
4605 PRINT_SRC_ONLY: Means we printed something, but there is no need
4606 to also print the location part of the message.
4607 An example is the catch/throw messages, which
4608 don't require a location appended to the end.
4609 PRINT_NOTHING: We have done some printing and we don't need any
4610 further info to be printed. */
4612 enum print_stop_action
4613 bpstat_print (bpstat bs
, int kind
)
4615 enum print_stop_action val
;
4617 /* Maybe another breakpoint in the chain caused us to stop.
4618 (Currently all watchpoints go on the bpstat whether hit or not.
4619 That probably could (should) be changed, provided care is taken
4620 with respect to bpstat_explains_signal). */
4621 for (; bs
; bs
= bs
->next
)
4623 val
= print_bp_stop_message (bs
);
4624 if (val
== PRINT_SRC_ONLY
4625 || val
== PRINT_SRC_AND_LOC
4626 || val
== PRINT_NOTHING
)
4630 /* If we had hit a shared library event breakpoint,
4631 print_bp_stop_message would print out this message. If we hit an
4632 OS-level shared library event, do the same thing. */
4633 if (kind
== TARGET_WAITKIND_LOADED
)
4635 print_solib_event (0);
4636 return PRINT_NOTHING
;
4639 /* We reached the end of the chain, or we got a null BS to start
4640 with and nothing was printed. */
4641 return PRINT_UNKNOWN
;
4644 /* Evaluate the boolean expression EXP and return the result. */
4647 breakpoint_cond_eval (expression
*exp
)
4649 struct value
*mark
= value_mark ();
4650 bool res
= value_true (evaluate_expression (exp
));
4652 value_free_to_mark (mark
);
4656 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4658 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4660 bp_location_at (bl
),
4661 breakpoint_at (bl
->owner
),
4665 print_it (print_it_normal
)
4667 incref_bp_location (bl
);
4668 **bs_link_pointer
= this;
4669 *bs_link_pointer
= &next
;
4674 bp_location_at (NULL
),
4675 breakpoint_at (NULL
),
4679 print_it (print_it_normal
)
4683 /* The target has stopped with waitstatus WS. Check if any hardware
4684 watchpoints have triggered, according to the target. */
4687 watchpoints_triggered (struct target_waitstatus
*ws
)
4689 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4691 struct breakpoint
*b
;
4693 if (!stopped_by_watchpoint
)
4695 /* We were not stopped by a watchpoint. Mark all watchpoints
4696 as not triggered. */
4698 if (is_hardware_watchpoint (b
))
4700 struct watchpoint
*w
= (struct watchpoint
*) b
;
4702 w
->watchpoint_triggered
= watch_triggered_no
;
4708 if (!target_stopped_data_address (current_top_target (), &addr
))
4710 /* We were stopped by a watchpoint, but we don't know where.
4711 Mark all watchpoints as unknown. */
4713 if (is_hardware_watchpoint (b
))
4715 struct watchpoint
*w
= (struct watchpoint
*) b
;
4717 w
->watchpoint_triggered
= watch_triggered_unknown
;
4723 /* The target could report the data address. Mark watchpoints
4724 affected by this data address as triggered, and all others as not
4728 if (is_hardware_watchpoint (b
))
4730 struct watchpoint
*w
= (struct watchpoint
*) b
;
4731 struct bp_location
*loc
;
4733 w
->watchpoint_triggered
= watch_triggered_no
;
4734 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4736 if (is_masked_watchpoint (b
))
4738 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4739 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4741 if (newaddr
== start
)
4743 w
->watchpoint_triggered
= watch_triggered_yes
;
4747 /* Exact match not required. Within range is sufficient. */
4748 else if (target_watchpoint_addr_within_range (current_top_target (),
4752 w
->watchpoint_triggered
= watch_triggered_yes
;
4761 /* Possible return values for watchpoint_check. */
4762 enum wp_check_result
4764 /* The watchpoint has been deleted. */
4767 /* The value has changed. */
4768 WP_VALUE_CHANGED
= 2,
4770 /* The value has not changed. */
4771 WP_VALUE_NOT_CHANGED
= 3,
4773 /* Ignore this watchpoint, no matter if the value changed or not. */
4777 #define BP_TEMPFLAG 1
4778 #define BP_HARDWAREFLAG 2
4780 /* Evaluate watchpoint condition expression and check if its value
4783 static wp_check_result
4784 watchpoint_check (bpstat bs
)
4786 struct watchpoint
*b
;
4787 struct frame_info
*fr
;
4788 int within_current_scope
;
4790 /* BS is built from an existing struct breakpoint. */
4791 gdb_assert (bs
->breakpoint_at
!= NULL
);
4792 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4794 /* If this is a local watchpoint, we only want to check if the
4795 watchpoint frame is in scope if the current thread is the thread
4796 that was used to create the watchpoint. */
4797 if (!watchpoint_in_thread_scope (b
))
4800 if (b
->exp_valid_block
== NULL
)
4801 within_current_scope
= 1;
4804 struct frame_info
*frame
= get_current_frame ();
4805 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4806 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4808 /* stack_frame_destroyed_p() returns a non-zero value if we're
4809 still in the function but the stack frame has already been
4810 invalidated. Since we can't rely on the values of local
4811 variables after the stack has been destroyed, we are treating
4812 the watchpoint in that state as `not changed' without further
4813 checking. Don't mark watchpoints as changed if the current
4814 frame is in an epilogue - even if they are in some other
4815 frame, our view of the stack is likely to be wrong and
4816 frame_find_by_id could error out. */
4817 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4820 fr
= frame_find_by_id (b
->watchpoint_frame
);
4821 within_current_scope
= (fr
!= NULL
);
4823 /* If we've gotten confused in the unwinder, we might have
4824 returned a frame that can't describe this variable. */
4825 if (within_current_scope
)
4827 struct symbol
*function
;
4829 function
= get_frame_function (fr
);
4830 if (function
== NULL
4831 || !contained_in (b
->exp_valid_block
,
4832 SYMBOL_BLOCK_VALUE (function
)))
4833 within_current_scope
= 0;
4836 if (within_current_scope
)
4837 /* If we end up stopping, the current frame will get selected
4838 in normal_stop. So this call to select_frame won't affect
4843 if (within_current_scope
)
4845 /* We use value_{,free_to_}mark because it could be a *long*
4846 time before we return to the command level and call
4847 free_all_values. We can't call free_all_values because we
4848 might be in the middle of evaluating a function call. */
4852 struct value
*new_val
;
4854 if (is_masked_watchpoint (b
))
4855 /* Since we don't know the exact trigger address (from
4856 stopped_data_address), just tell the user we've triggered
4857 a mask watchpoint. */
4858 return WP_VALUE_CHANGED
;
4860 mark
= value_mark ();
4861 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
4863 if (b
->val_bitsize
!= 0)
4864 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4866 /* We use value_equal_contents instead of value_equal because
4867 the latter coerces an array to a pointer, thus comparing just
4868 the address of the array instead of its contents. This is
4869 not what we want. */
4870 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4871 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
4874 bs
->old_val
= b
->val
;
4875 b
->val
= release_value (new_val
);
4876 b
->val_valid
= true;
4877 if (new_val
!= NULL
)
4878 value_free_to_mark (mark
);
4879 return WP_VALUE_CHANGED
;
4883 /* Nothing changed. */
4884 value_free_to_mark (mark
);
4885 return WP_VALUE_NOT_CHANGED
;
4890 /* This seems like the only logical thing to do because
4891 if we temporarily ignored the watchpoint, then when
4892 we reenter the block in which it is valid it contains
4893 garbage (in the case of a function, it may have two
4894 garbage values, one before and one after the prologue).
4895 So we can't even detect the first assignment to it and
4896 watch after that (since the garbage may or may not equal
4897 the first value assigned). */
4898 /* We print all the stop information in
4899 breakpoint_ops->print_it, but in this case, by the time we
4900 call breakpoint_ops->print_it this bp will be deleted
4901 already. So we have no choice but print the information
4904 SWITCH_THRU_ALL_UIS ()
4906 struct ui_out
*uiout
= current_uiout
;
4908 if (uiout
->is_mi_like_p ())
4910 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4911 uiout
->message ("\nWatchpoint %pF deleted because the program has "
4912 "left the block in\n"
4913 "which its expression is valid.\n",
4914 signed_field ("wpnum", b
->number
));
4917 /* Make sure the watchpoint's commands aren't executed. */
4919 watchpoint_del_at_next_stop (b
);
4925 /* Return true if it looks like target has stopped due to hitting
4926 breakpoint location BL. This function does not check if we should
4927 stop, only if BL explains the stop. */
4930 bpstat_check_location (const struct bp_location
*bl
,
4931 const address_space
*aspace
, CORE_ADDR bp_addr
,
4932 const struct target_waitstatus
*ws
)
4934 struct breakpoint
*b
= bl
->owner
;
4936 /* BL is from an existing breakpoint. */
4937 gdb_assert (b
!= NULL
);
4939 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4942 /* Determine if the watched values have actually changed, and we
4943 should stop. If not, set BS->stop to 0. */
4946 bpstat_check_watchpoint (bpstat bs
)
4948 const struct bp_location
*bl
;
4949 struct watchpoint
*b
;
4951 /* BS is built for existing struct breakpoint. */
4952 bl
= bs
->bp_location_at
;
4953 gdb_assert (bl
!= NULL
);
4954 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4955 gdb_assert (b
!= NULL
);
4958 int must_check_value
= 0;
4960 if (b
->type
== bp_watchpoint
)
4961 /* For a software watchpoint, we must always check the
4963 must_check_value
= 1;
4964 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4965 /* We have a hardware watchpoint (read, write, or access)
4966 and the target earlier reported an address watched by
4968 must_check_value
= 1;
4969 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4970 && b
->type
== bp_hardware_watchpoint
)
4971 /* We were stopped by a hardware watchpoint, but the target could
4972 not report the data address. We must check the watchpoint's
4973 value. Access and read watchpoints are out of luck; without
4974 a data address, we can't figure it out. */
4975 must_check_value
= 1;
4977 if (must_check_value
)
4983 e
= watchpoint_check (bs
);
4985 catch (const gdb_exception
&ex
)
4987 exception_fprintf (gdb_stderr
, ex
,
4988 "Error evaluating expression "
4989 "for watchpoint %d\n",
4992 SWITCH_THRU_ALL_UIS ()
4994 printf_filtered (_("Watchpoint %d deleted.\n"),
4997 watchpoint_del_at_next_stop (b
);
5004 /* We've already printed what needs to be printed. */
5005 bs
->print_it
= print_it_done
;
5009 bs
->print_it
= print_it_noop
;
5012 case WP_VALUE_CHANGED
:
5013 if (b
->type
== bp_read_watchpoint
)
5015 /* There are two cases to consider here:
5017 1. We're watching the triggered memory for reads.
5018 In that case, trust the target, and always report
5019 the watchpoint hit to the user. Even though
5020 reads don't cause value changes, the value may
5021 have changed since the last time it was read, and
5022 since we're not trapping writes, we will not see
5023 those, and as such we should ignore our notion of
5026 2. We're watching the triggered memory for both
5027 reads and writes. There are two ways this may
5030 2.1. This is a target that can't break on data
5031 reads only, but can break on accesses (reads or
5032 writes), such as e.g., x86. We detect this case
5033 at the time we try to insert read watchpoints.
5035 2.2. Otherwise, the target supports read
5036 watchpoints, but, the user set an access or write
5037 watchpoint watching the same memory as this read
5040 If we're watching memory writes as well as reads,
5041 ignore watchpoint hits when we find that the
5042 value hasn't changed, as reads don't cause
5043 changes. This still gives false positives when
5044 the program writes the same value to memory as
5045 what there was already in memory (we will confuse
5046 it for a read), but it's much better than
5049 int other_write_watchpoint
= 0;
5051 if (bl
->watchpoint_type
== hw_read
)
5053 struct breakpoint
*other_b
;
5055 ALL_BREAKPOINTS (other_b
)
5056 if (other_b
->type
== bp_hardware_watchpoint
5057 || other_b
->type
== bp_access_watchpoint
)
5059 struct watchpoint
*other_w
=
5060 (struct watchpoint
*) other_b
;
5062 if (other_w
->watchpoint_triggered
5063 == watch_triggered_yes
)
5065 other_write_watchpoint
= 1;
5071 if (other_write_watchpoint
5072 || bl
->watchpoint_type
== hw_access
)
5074 /* We're watching the same memory for writes,
5075 and the value changed since the last time we
5076 updated it, so this trap must be for a write.
5078 bs
->print_it
= print_it_noop
;
5083 case WP_VALUE_NOT_CHANGED
:
5084 if (b
->type
== bp_hardware_watchpoint
5085 || b
->type
== bp_watchpoint
)
5087 /* Don't stop: write watchpoints shouldn't fire if
5088 the value hasn't changed. */
5089 bs
->print_it
= print_it_noop
;
5099 else /* must_check_value == 0 */
5101 /* This is a case where some watchpoint(s) triggered, but
5102 not at the address of this watchpoint, or else no
5103 watchpoint triggered after all. So don't print
5104 anything for this watchpoint. */
5105 bs
->print_it
= print_it_noop
;
5111 /* For breakpoints that are currently marked as telling gdb to stop,
5112 check conditions (condition proper, frame, thread and ignore count)
5113 of breakpoint referred to by BS. If we should not stop for this
5114 breakpoint, set BS->stop to 0. */
5117 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5119 const struct bp_location
*bl
;
5120 struct breakpoint
*b
;
5122 bool condition_result
= true;
5123 struct expression
*cond
;
5125 gdb_assert (bs
->stop
);
5127 /* BS is built for existing struct breakpoint. */
5128 bl
= bs
->bp_location_at
;
5129 gdb_assert (bl
!= NULL
);
5130 b
= bs
->breakpoint_at
;
5131 gdb_assert (b
!= NULL
);
5133 /* Even if the target evaluated the condition on its end and notified GDB, we
5134 need to do so again since GDB does not know if we stopped due to a
5135 breakpoint or a single step breakpoint. */
5137 if (frame_id_p (b
->frame_id
)
5138 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5144 /* If this is a thread/task-specific breakpoint, don't waste cpu
5145 evaluating the condition if this isn't the specified
5147 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5148 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5154 /* Evaluate extension language breakpoints that have a "stop" method
5156 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5158 if (is_watchpoint (b
))
5160 struct watchpoint
*w
= (struct watchpoint
*) b
;
5162 cond
= w
->cond_exp
.get ();
5165 cond
= bl
->cond
.get ();
5167 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5169 int within_current_scope
= 1;
5170 struct watchpoint
* w
;
5172 /* We use value_mark and value_free_to_mark because it could
5173 be a long time before we return to the command level and
5174 call free_all_values. We can't call free_all_values
5175 because we might be in the middle of evaluating a
5177 struct value
*mark
= value_mark ();
5179 if (is_watchpoint (b
))
5180 w
= (struct watchpoint
*) b
;
5184 /* Need to select the frame, with all that implies so that
5185 the conditions will have the right context. Because we
5186 use the frame, we will not see an inlined function's
5187 variables when we arrive at a breakpoint at the start
5188 of the inlined function; the current frame will be the
5190 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5191 select_frame (get_current_frame ());
5194 struct frame_info
*frame
;
5196 /* For local watchpoint expressions, which particular
5197 instance of a local is being watched matters, so we
5198 keep track of the frame to evaluate the expression
5199 in. To evaluate the condition however, it doesn't
5200 really matter which instantiation of the function
5201 where the condition makes sense triggers the
5202 watchpoint. This allows an expression like "watch
5203 global if q > 10" set in `func', catch writes to
5204 global on all threads that call `func', or catch
5205 writes on all recursive calls of `func' by a single
5206 thread. We simply always evaluate the condition in
5207 the innermost frame that's executing where it makes
5208 sense to evaluate the condition. It seems
5210 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5212 select_frame (frame
);
5214 within_current_scope
= 0;
5216 if (within_current_scope
)
5220 condition_result
= breakpoint_cond_eval (cond
);
5222 catch (const gdb_exception
&ex
)
5224 exception_fprintf (gdb_stderr
, ex
,
5225 "Error in testing breakpoint condition:\n");
5230 warning (_("Watchpoint condition cannot be tested "
5231 "in the current scope"));
5232 /* If we failed to set the right context for this
5233 watchpoint, unconditionally report it. */
5235 /* FIXME-someday, should give breakpoint #. */
5236 value_free_to_mark (mark
);
5239 if (cond
&& !condition_result
)
5243 else if (b
->ignore_count
> 0)
5247 /* Increase the hit count even though we don't stop. */
5249 gdb::observers::breakpoint_modified
.notify (b
);
5253 /* Returns true if we need to track moribund locations of LOC's type
5254 on the current target. */
5257 need_moribund_for_location_type (struct bp_location
*loc
)
5259 return ((loc
->loc_type
== bp_loc_software_breakpoint
5260 && !target_supports_stopped_by_sw_breakpoint ())
5261 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5262 && !target_supports_stopped_by_hw_breakpoint ()));
5265 /* See breakpoint.h. */
5268 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5269 const struct target_waitstatus
*ws
)
5271 struct breakpoint
*b
;
5272 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5276 if (!breakpoint_enabled (b
))
5279 for (bp_location
*bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5281 /* For hardware watchpoints, we look only at the first
5282 location. The watchpoint_check function will work on the
5283 entire expression, not the individual locations. For
5284 read watchpoints, the watchpoints_triggered function has
5285 checked all locations already. */
5286 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5289 if (!bl
->enabled
|| bl
->shlib_disabled
)
5292 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5295 /* Come here if it's a watchpoint, or if the break address
5298 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5301 /* Assume we stop. Should we find a watchpoint that is not
5302 actually triggered, or if the condition of the breakpoint
5303 evaluates as false, we'll reset 'stop' to 0. */
5307 /* If this is a scope breakpoint, mark the associated
5308 watchpoint as triggered so that we will handle the
5309 out-of-scope event. We'll get to the watchpoint next
5311 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5313 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5315 w
->watchpoint_triggered
= watch_triggered_yes
;
5320 /* Check if a moribund breakpoint explains the stop. */
5321 if (!target_supports_stopped_by_sw_breakpoint ()
5322 || !target_supports_stopped_by_hw_breakpoint ())
5324 for (bp_location
*loc
: moribund_locations
)
5326 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5327 && need_moribund_for_location_type (loc
))
5329 bpstat bs
= new bpstats (loc
, &bs_link
);
5330 /* For hits of moribund locations, we should just proceed. */
5333 bs
->print_it
= print_it_noop
;
5341 /* See breakpoint.h. */
5344 bpstat_stop_status (const address_space
*aspace
,
5345 CORE_ADDR bp_addr
, thread_info
*thread
,
5346 const struct target_waitstatus
*ws
,
5349 struct breakpoint
*b
= NULL
;
5350 /* First item of allocated bpstat's. */
5351 bpstat bs_head
= stop_chain
;
5353 int need_remove_insert
;
5356 /* First, build the bpstat chain with locations that explain a
5357 target stop, while being careful to not set the target running,
5358 as that may invalidate locations (in particular watchpoint
5359 locations are recreated). Resuming will happen here with
5360 breakpoint conditions or watchpoint expressions that include
5361 inferior function calls. */
5362 if (bs_head
== NULL
)
5363 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5365 /* A bit of special processing for shlib breakpoints. We need to
5366 process solib loading here, so that the lists of loaded and
5367 unloaded libraries are correct before we handle "catch load" and
5369 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5371 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5373 handle_solib_event ();
5378 /* Now go through the locations that caused the target to stop, and
5379 check whether we're interested in reporting this stop to higher
5380 layers, or whether we should resume the target transparently. */
5384 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5389 b
= bs
->breakpoint_at
;
5390 b
->ops
->check_status (bs
);
5393 bpstat_check_breakpoint_conditions (bs
, thread
);
5398 gdb::observers::breakpoint_modified
.notify (b
);
5400 /* We will stop here. */
5401 if (b
->disposition
== disp_disable
)
5403 --(b
->enable_count
);
5404 if (b
->enable_count
<= 0)
5405 b
->enable_state
= bp_disabled
;
5410 bs
->commands
= b
->commands
;
5411 if (command_line_is_silent (bs
->commands
5412 ? bs
->commands
.get () : NULL
))
5415 b
->ops
->after_condition_true (bs
);
5420 /* Print nothing for this entry if we don't stop or don't
5422 if (!bs
->stop
|| !bs
->print
)
5423 bs
->print_it
= print_it_noop
;
5426 /* If we aren't stopping, the value of some hardware watchpoint may
5427 not have changed, but the intermediate memory locations we are
5428 watching may have. Don't bother if we're stopping; this will get
5430 need_remove_insert
= 0;
5431 if (! bpstat_causes_stop (bs_head
))
5432 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5434 && bs
->breakpoint_at
5435 && is_hardware_watchpoint (bs
->breakpoint_at
))
5437 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5439 update_watchpoint (w
, 0 /* don't reparse. */);
5440 need_remove_insert
= 1;
5443 if (need_remove_insert
)
5444 update_global_location_list (UGLL_MAY_INSERT
);
5445 else if (removed_any
)
5446 update_global_location_list (UGLL_DONT_INSERT
);
5452 handle_jit_event (void)
5454 struct frame_info
*frame
;
5455 struct gdbarch
*gdbarch
;
5458 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5460 /* Switch terminal for any messages produced by
5461 breakpoint_re_set. */
5462 target_terminal::ours_for_output ();
5464 frame
= get_current_frame ();
5465 gdbarch
= get_frame_arch (frame
);
5467 jit_event_handler (gdbarch
);
5469 target_terminal::inferior ();
5472 /* Prepare WHAT final decision for infrun. */
5474 /* Decide what infrun needs to do with this bpstat. */
5477 bpstat_what (bpstat bs_head
)
5479 struct bpstat_what retval
;
5482 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5483 retval
.call_dummy
= STOP_NONE
;
5484 retval
.is_longjmp
= false;
5486 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5488 /* Extract this BS's action. After processing each BS, we check
5489 if its action overrides all we've seem so far. */
5490 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5493 if (bs
->breakpoint_at
== NULL
)
5495 /* I suspect this can happen if it was a momentary
5496 breakpoint which has since been deleted. */
5500 bptype
= bs
->breakpoint_at
->type
;
5507 case bp_hardware_breakpoint
:
5508 case bp_single_step
:
5511 case bp_shlib_event
:
5515 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5517 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5520 this_action
= BPSTAT_WHAT_SINGLE
;
5523 case bp_hardware_watchpoint
:
5524 case bp_read_watchpoint
:
5525 case bp_access_watchpoint
:
5529 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5531 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5535 /* There was a watchpoint, but we're not stopping.
5536 This requires no further action. */
5540 case bp_longjmp_call_dummy
:
5544 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5545 retval
.is_longjmp
= bptype
!= bp_exception
;
5548 this_action
= BPSTAT_WHAT_SINGLE
;
5550 case bp_longjmp_resume
:
5551 case bp_exception_resume
:
5554 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5555 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5558 this_action
= BPSTAT_WHAT_SINGLE
;
5560 case bp_step_resume
:
5562 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5565 /* It is for the wrong frame. */
5566 this_action
= BPSTAT_WHAT_SINGLE
;
5569 case bp_hp_step_resume
:
5571 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5574 /* It is for the wrong frame. */
5575 this_action
= BPSTAT_WHAT_SINGLE
;
5578 case bp_watchpoint_scope
:
5579 case bp_thread_event
:
5580 case bp_overlay_event
:
5581 case bp_longjmp_master
:
5582 case bp_std_terminate_master
:
5583 case bp_exception_master
:
5584 this_action
= BPSTAT_WHAT_SINGLE
;
5590 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5592 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5596 /* Some catchpoints are implemented with breakpoints.
5597 For those, we need to step over the breakpoint. */
5598 if (bs
->bp_location_at
->loc_type
!= bp_loc_other
)
5599 this_action
= BPSTAT_WHAT_SINGLE
;
5603 this_action
= BPSTAT_WHAT_SINGLE
;
5606 /* Make sure the action is stop (silent or noisy),
5607 so infrun.c pops the dummy frame. */
5608 retval
.call_dummy
= STOP_STACK_DUMMY
;
5609 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5611 case bp_std_terminate
:
5612 /* Make sure the action is stop (silent or noisy),
5613 so infrun.c pops the dummy frame. */
5614 retval
.call_dummy
= STOP_STD_TERMINATE
;
5615 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5618 case bp_fast_tracepoint
:
5619 case bp_static_tracepoint
:
5620 /* Tracepoint hits should not be reported back to GDB, and
5621 if one got through somehow, it should have been filtered
5623 internal_error (__FILE__
, __LINE__
,
5624 _("bpstat_what: tracepoint encountered"));
5626 case bp_gnu_ifunc_resolver
:
5627 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5628 this_action
= BPSTAT_WHAT_SINGLE
;
5630 case bp_gnu_ifunc_resolver_return
:
5631 /* The breakpoint will be removed, execution will restart from the
5632 PC of the former breakpoint. */
5633 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5638 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5640 this_action
= BPSTAT_WHAT_SINGLE
;
5644 internal_error (__FILE__
, __LINE__
,
5645 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5648 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5655 bpstat_run_callbacks (bpstat bs_head
)
5659 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5661 struct breakpoint
*b
= bs
->breakpoint_at
;
5668 handle_jit_event ();
5670 case bp_gnu_ifunc_resolver
:
5671 gnu_ifunc_resolver_stop (b
);
5673 case bp_gnu_ifunc_resolver_return
:
5674 gnu_ifunc_resolver_return_stop (b
);
5680 /* See breakpoint.h. */
5683 bpstat_should_step ()
5685 struct breakpoint
*b
;
5688 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5693 /* See breakpoint.h. */
5696 bpstat_causes_stop (bpstat bs
)
5698 for (; bs
!= NULL
; bs
= bs
->next
)
5707 /* Compute a string of spaces suitable to indent the next line
5708 so it starts at the position corresponding to the table column
5709 named COL_NAME in the currently active table of UIOUT. */
5712 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5714 static char wrap_indent
[80];
5715 int i
, total_width
, width
, align
;
5719 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5721 if (strcmp (text
, col_name
) == 0)
5723 gdb_assert (total_width
< sizeof wrap_indent
);
5724 memset (wrap_indent
, ' ', total_width
);
5725 wrap_indent
[total_width
] = 0;
5730 total_width
+= width
+ 1;
5736 /* Determine if the locations of this breakpoint will have their conditions
5737 evaluated by the target, host or a mix of both. Returns the following:
5739 "host": Host evals condition.
5740 "host or target": Host or Target evals condition.
5741 "target": Target evals condition.
5745 bp_condition_evaluator (struct breakpoint
*b
)
5747 struct bp_location
*bl
;
5748 char host_evals
= 0;
5749 char target_evals
= 0;
5754 if (!is_breakpoint (b
))
5757 if (gdb_evaluates_breakpoint_condition_p ()
5758 || !target_supports_evaluation_of_breakpoint_conditions ())
5759 return condition_evaluation_host
;
5761 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5763 if (bl
->cond_bytecode
)
5769 if (host_evals
&& target_evals
)
5770 return condition_evaluation_both
;
5771 else if (target_evals
)
5772 return condition_evaluation_target
;
5774 return condition_evaluation_host
;
5777 /* Determine the breakpoint location's condition evaluator. This is
5778 similar to bp_condition_evaluator, but for locations. */
5781 bp_location_condition_evaluator (struct bp_location
*bl
)
5783 if (bl
&& !is_breakpoint (bl
->owner
))
5786 if (gdb_evaluates_breakpoint_condition_p ()
5787 || !target_supports_evaluation_of_breakpoint_conditions ())
5788 return condition_evaluation_host
;
5790 if (bl
&& bl
->cond_bytecode
)
5791 return condition_evaluation_target
;
5793 return condition_evaluation_host
;
5796 /* Print the LOC location out of the list of B->LOC locations. */
5799 print_breakpoint_location (struct breakpoint
*b
,
5800 struct bp_location
*loc
)
5802 struct ui_out
*uiout
= current_uiout
;
5804 scoped_restore_current_program_space restore_pspace
;
5806 if (loc
!= NULL
&& loc
->shlib_disabled
)
5810 set_current_program_space (loc
->pspace
);
5812 if (b
->display_canonical
)
5813 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5814 else if (loc
&& loc
->symtab
)
5816 const struct symbol
*sym
= loc
->symbol
;
5820 uiout
->text ("in ");
5821 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
),
5822 function_name_style
.style ());
5824 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5825 uiout
->text ("at ");
5827 uiout
->field_string ("file",
5828 symtab_to_filename_for_display (loc
->symtab
),
5829 file_name_style
.style ());
5832 if (uiout
->is_mi_like_p ())
5833 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5835 uiout
->field_signed ("line", loc
->line_number
);
5841 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5843 uiout
->field_stream ("at", stb
);
5847 uiout
->field_string ("pending",
5848 event_location_to_string (b
->location
.get ()));
5849 /* If extra_string is available, it could be holding a condition
5850 or dprintf arguments. In either case, make sure it is printed,
5851 too, but only for non-MI streams. */
5852 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5854 if (b
->type
== bp_dprintf
)
5858 uiout
->text (b
->extra_string
);
5862 if (loc
&& is_breakpoint (b
)
5863 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5864 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5867 uiout
->field_string ("evaluated-by",
5868 bp_location_condition_evaluator (loc
));
5874 bptype_string (enum bptype type
)
5876 struct ep_type_description
5879 const char *description
;
5881 static struct ep_type_description bptypes
[] =
5883 {bp_none
, "?deleted?"},
5884 {bp_breakpoint
, "breakpoint"},
5885 {bp_hardware_breakpoint
, "hw breakpoint"},
5886 {bp_single_step
, "sw single-step"},
5887 {bp_until
, "until"},
5888 {bp_finish
, "finish"},
5889 {bp_watchpoint
, "watchpoint"},
5890 {bp_hardware_watchpoint
, "hw watchpoint"},
5891 {bp_read_watchpoint
, "read watchpoint"},
5892 {bp_access_watchpoint
, "acc watchpoint"},
5893 {bp_longjmp
, "longjmp"},
5894 {bp_longjmp_resume
, "longjmp resume"},
5895 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5896 {bp_exception
, "exception"},
5897 {bp_exception_resume
, "exception resume"},
5898 {bp_step_resume
, "step resume"},
5899 {bp_hp_step_resume
, "high-priority step resume"},
5900 {bp_watchpoint_scope
, "watchpoint scope"},
5901 {bp_call_dummy
, "call dummy"},
5902 {bp_std_terminate
, "std::terminate"},
5903 {bp_shlib_event
, "shlib events"},
5904 {bp_thread_event
, "thread events"},
5905 {bp_overlay_event
, "overlay events"},
5906 {bp_longjmp_master
, "longjmp master"},
5907 {bp_std_terminate_master
, "std::terminate master"},
5908 {bp_exception_master
, "exception master"},
5909 {bp_catchpoint
, "catchpoint"},
5910 {bp_tracepoint
, "tracepoint"},
5911 {bp_fast_tracepoint
, "fast tracepoint"},
5912 {bp_static_tracepoint
, "static tracepoint"},
5913 {bp_dprintf
, "dprintf"},
5914 {bp_jit_event
, "jit events"},
5915 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5916 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5919 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5920 || ((int) type
!= bptypes
[(int) type
].type
))
5921 internal_error (__FILE__
, __LINE__
,
5922 _("bptypes table does not describe type #%d."),
5925 return bptypes
[(int) type
].description
;
5928 /* For MI, output a field named 'thread-groups' with a list as the value.
5929 For CLI, prefix the list with the string 'inf'. */
5932 output_thread_groups (struct ui_out
*uiout
,
5933 const char *field_name
,
5934 const std::vector
<int> &inf_nums
,
5937 int is_mi
= uiout
->is_mi_like_p ();
5939 /* For backward compatibility, don't display inferiors in CLI unless
5940 there are several. Always display them for MI. */
5941 if (!is_mi
&& mi_only
)
5944 ui_out_emit_list
list_emitter (uiout
, field_name
);
5946 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
5952 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
5953 uiout
->field_string (NULL
, mi_group
);
5958 uiout
->text (" inf ");
5962 uiout
->text (plongest (inf_nums
[i
]));
5967 /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations
5968 instead of going via breakpoint_ops::print_one. This makes "maint
5969 info breakpoints" show the software breakpoint locations of
5970 catchpoints, which are considered internal implementation
5974 print_one_breakpoint_location (struct breakpoint
*b
,
5975 struct bp_location
*loc
,
5977 struct bp_location
**last_loc
,
5978 int allflag
, bool raw_loc
)
5980 struct command_line
*l
;
5981 static char bpenables
[] = "nynny";
5983 struct ui_out
*uiout
= current_uiout
;
5984 int header_of_multiple
= 0;
5985 int part_of_multiple
= (loc
!= NULL
);
5986 struct value_print_options opts
;
5988 get_user_print_options (&opts
);
5990 gdb_assert (!loc
|| loc_number
!= 0);
5991 /* See comment in print_one_breakpoint concerning treatment of
5992 breakpoints with single disabled location. */
5995 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
5996 header_of_multiple
= 1;
6004 if (part_of_multiple
)
6005 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6007 uiout
->field_signed ("number", b
->number
);
6011 if (part_of_multiple
)
6012 uiout
->field_skip ("type");
6014 uiout
->field_string ("type", bptype_string (b
->type
));
6018 if (part_of_multiple
)
6019 uiout
->field_skip ("disp");
6021 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6025 if (part_of_multiple
)
6026 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6028 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6031 if (!raw_loc
&& b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6032 b
->ops
->print_one (b
, last_loc
);
6035 if (is_watchpoint (b
))
6037 struct watchpoint
*w
= (struct watchpoint
*) b
;
6039 /* Field 4, the address, is omitted (which makes the columns
6040 not line up too nicely with the headers, but the effect
6041 is relatively readable). */
6042 if (opts
.addressprint
)
6043 uiout
->field_skip ("addr");
6045 uiout
->field_string ("what", w
->exp_string
);
6047 else if (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6048 || is_ada_exception_catchpoint (b
))
6050 if (opts
.addressprint
)
6053 if (header_of_multiple
)
6054 uiout
->field_string ("addr", "<MULTIPLE>",
6055 metadata_style
.style ());
6056 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6057 uiout
->field_string ("addr", "<PENDING>",
6058 metadata_style
.style ());
6060 uiout
->field_core_addr ("addr",
6061 loc
->gdbarch
, loc
->address
);
6064 if (!header_of_multiple
)
6065 print_breakpoint_location (b
, loc
);
6071 if (loc
!= NULL
&& !header_of_multiple
)
6073 std::vector
<int> inf_nums
;
6076 for (inferior
*inf
: all_inferiors ())
6078 if (inf
->pspace
== loc
->pspace
)
6079 inf_nums
.push_back (inf
->num
);
6082 /* For backward compatibility, don't display inferiors in CLI unless
6083 there are several. Always display for MI. */
6085 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6086 && (number_of_program_spaces () > 1
6087 || number_of_inferiors () > 1)
6088 /* LOC is for existing B, it cannot be in
6089 moribund_locations and thus having NULL OWNER. */
6090 && loc
->owner
->type
!= bp_catchpoint
))
6092 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6095 if (!part_of_multiple
)
6097 if (b
->thread
!= -1)
6099 /* FIXME: This seems to be redundant and lost here; see the
6100 "stop only in" line a little further down. */
6101 uiout
->text (" thread ");
6102 uiout
->field_signed ("thread", b
->thread
);
6104 else if (b
->task
!= 0)
6106 uiout
->text (" task ");
6107 uiout
->field_signed ("task", b
->task
);
6113 if (!part_of_multiple
)
6114 b
->ops
->print_one_detail (b
, uiout
);
6116 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6119 uiout
->text ("\tstop only in stack frame at ");
6120 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6122 uiout
->field_core_addr ("frame",
6123 b
->gdbarch
, b
->frame_id
.stack_addr
);
6127 if (!part_of_multiple
&& b
->cond_string
)
6130 if (is_tracepoint (b
))
6131 uiout
->text ("\ttrace only if ");
6133 uiout
->text ("\tstop only if ");
6134 uiout
->field_string ("cond", b
->cond_string
);
6136 /* Print whether the target is doing the breakpoint's condition
6137 evaluation. If GDB is doing the evaluation, don't print anything. */
6138 if (is_breakpoint (b
)
6139 && breakpoint_condition_evaluation_mode ()
6140 == condition_evaluation_target
)
6142 uiout
->message (" (%pF evals)",
6143 string_field ("evaluated-by",
6144 bp_condition_evaluator (b
)));
6149 if (!part_of_multiple
&& b
->thread
!= -1)
6151 /* FIXME should make an annotation for this. */
6152 uiout
->text ("\tstop only in thread ");
6153 if (uiout
->is_mi_like_p ())
6154 uiout
->field_signed ("thread", b
->thread
);
6157 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6159 uiout
->field_string ("thread", print_thread_id (thr
));
6164 if (!part_of_multiple
)
6168 /* FIXME should make an annotation for this. */
6169 if (is_catchpoint (b
))
6170 uiout
->text ("\tcatchpoint");
6171 else if (is_tracepoint (b
))
6172 uiout
->text ("\ttracepoint");
6174 uiout
->text ("\tbreakpoint");
6175 uiout
->text (" already hit ");
6176 uiout
->field_signed ("times", b
->hit_count
);
6177 if (b
->hit_count
== 1)
6178 uiout
->text (" time\n");
6180 uiout
->text (" times\n");
6184 /* Output the count also if it is zero, but only if this is mi. */
6185 if (uiout
->is_mi_like_p ())
6186 uiout
->field_signed ("times", b
->hit_count
);
6190 if (!part_of_multiple
&& b
->ignore_count
)
6193 uiout
->message ("\tignore next %pF hits\n",
6194 signed_field ("ignore", b
->ignore_count
));
6197 /* Note that an enable count of 1 corresponds to "enable once"
6198 behavior, which is reported by the combination of enablement and
6199 disposition, so we don't need to mention it here. */
6200 if (!part_of_multiple
&& b
->enable_count
> 1)
6203 uiout
->text ("\tdisable after ");
6204 /* Tweak the wording to clarify that ignore and enable counts
6205 are distinct, and have additive effect. */
6206 if (b
->ignore_count
)
6207 uiout
->text ("additional ");
6209 uiout
->text ("next ");
6210 uiout
->field_signed ("enable", b
->enable_count
);
6211 uiout
->text (" hits\n");
6214 if (!part_of_multiple
&& is_tracepoint (b
))
6216 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6218 if (tp
->traceframe_usage
)
6220 uiout
->text ("\ttrace buffer usage ");
6221 uiout
->field_signed ("traceframe-usage", tp
->traceframe_usage
);
6222 uiout
->text (" bytes\n");
6226 l
= b
->commands
? b
->commands
.get () : NULL
;
6227 if (!part_of_multiple
&& l
)
6230 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6231 print_command_lines (uiout
, l
, 4);
6234 if (is_tracepoint (b
))
6236 struct tracepoint
*t
= (struct tracepoint
*) b
;
6238 if (!part_of_multiple
&& t
->pass_count
)
6240 annotate_field (10);
6241 uiout
->text ("\tpass count ");
6242 uiout
->field_signed ("pass", t
->pass_count
);
6243 uiout
->text (" \n");
6246 /* Don't display it when tracepoint or tracepoint location is
6248 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6250 annotate_field (11);
6252 if (uiout
->is_mi_like_p ())
6253 uiout
->field_string ("installed",
6254 loc
->inserted
? "y" : "n");
6260 uiout
->text ("\tnot ");
6261 uiout
->text ("installed on target\n");
6266 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6268 if (is_watchpoint (b
))
6270 struct watchpoint
*w
= (struct watchpoint
*) b
;
6272 uiout
->field_string ("original-location", w
->exp_string
);
6274 else if (b
->location
!= NULL
6275 && event_location_to_string (b
->location
.get ()) != NULL
)
6276 uiout
->field_string ("original-location",
6277 event_location_to_string (b
->location
.get ()));
6281 /* See breakpoint.h. */
6283 bool fix_multi_location_breakpoint_output_globally
= false;
6286 print_one_breakpoint (struct breakpoint
*b
,
6287 struct bp_location
**last_loc
,
6290 struct ui_out
*uiout
= current_uiout
;
6291 bool use_fixed_output
6292 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6293 || fix_multi_location_breakpoint_output_globally
);
6295 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6296 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
, false);
6298 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6300 if (!use_fixed_output
)
6301 bkpt_tuple_emitter
.reset ();
6303 /* If this breakpoint has custom print function,
6304 it's already printed. Otherwise, print individual
6305 locations, if any. */
6307 || b
->ops
->print_one
== NULL
6310 /* If breakpoint has a single location that is disabled, we
6311 print it as if it had several locations, since otherwise it's
6312 hard to represent "breakpoint enabled, location disabled"
6315 Note that while hardware watchpoints have several locations
6316 internally, that's not a property exposed to users.
6318 Likewise, while catchpoints may be implemented with
6319 breakpoints (e.g., catch throw), that's not a property
6320 exposed to users. We do however display the internal
6321 breakpoint locations with "maint info breakpoints". */
6322 if (!is_hardware_watchpoint (b
)
6323 && (!is_catchpoint (b
) || is_exception_catchpoint (b
)
6324 || is_ada_exception_catchpoint (b
))
6326 || (b
->loc
&& (b
->loc
->next
|| !b
->loc
->enabled
))))
6328 gdb::optional
<ui_out_emit_list
> locations_list
;
6330 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6331 MI record. For later versions, place breakpoint locations in a
6333 if (uiout
->is_mi_like_p () && use_fixed_output
)
6334 locations_list
.emplace (uiout
, "locations");
6337 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
, ++n
)
6339 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6340 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
6348 breakpoint_address_bits (struct breakpoint
*b
)
6350 int print_address_bits
= 0;
6351 struct bp_location
*loc
;
6353 /* Software watchpoints that aren't watching memory don't have an
6354 address to print. */
6355 if (is_no_memory_software_watchpoint (b
))
6358 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6362 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6363 if (addr_bit
> print_address_bits
)
6364 print_address_bits
= addr_bit
;
6367 return print_address_bits
;
6370 /* See breakpoint.h. */
6373 print_breakpoint (breakpoint
*b
)
6375 struct bp_location
*dummy_loc
= NULL
;
6376 print_one_breakpoint (b
, &dummy_loc
, 0);
6379 /* Return true if this breakpoint was set by the user, false if it is
6380 internal or momentary. */
6383 user_breakpoint_p (struct breakpoint
*b
)
6385 return b
->number
> 0;
6388 /* See breakpoint.h. */
6391 pending_breakpoint_p (struct breakpoint
*b
)
6393 return b
->loc
== NULL
;
6396 /* Print information on breakpoints (including watchpoints and tracepoints).
6398 If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as
6399 understood by number_or_range_parser. Only breakpoints included in this
6400 list are then printed.
6402 If SHOW_INTERNAL is true, print internal breakpoints.
6404 If FILTER is non-NULL, call it on each breakpoint and only include the
6405 ones for which it returns true.
6407 Return the total number of breakpoints listed. */
6410 breakpoint_1 (const char *bp_num_list
, bool show_internal
,
6411 bool (*filter
) (const struct breakpoint
*))
6413 struct breakpoint
*b
;
6414 struct bp_location
*last_loc
= NULL
;
6415 int nr_printable_breakpoints
;
6416 struct value_print_options opts
;
6417 int print_address_bits
= 0;
6418 int print_type_col_width
= 14;
6419 struct ui_out
*uiout
= current_uiout
;
6421 get_user_print_options (&opts
);
6423 /* Compute the number of rows in the table, as well as the size
6424 required for address fields. */
6425 nr_printable_breakpoints
= 0;
6428 /* If we have a filter, only list the breakpoints it accepts. */
6429 if (filter
&& !filter (b
))
6432 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6433 accept. Skip the others. */
6434 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6436 if (show_internal
&& parse_and_eval_long (bp_num_list
) != b
->number
)
6438 if (!show_internal
&& !number_is_in_list (bp_num_list
, b
->number
))
6442 if (show_internal
|| user_breakpoint_p (b
))
6444 int addr_bit
, type_len
;
6446 addr_bit
= breakpoint_address_bits (b
);
6447 if (addr_bit
> print_address_bits
)
6448 print_address_bits
= addr_bit
;
6450 type_len
= strlen (bptype_string (b
->type
));
6451 if (type_len
> print_type_col_width
)
6452 print_type_col_width
= type_len
;
6454 nr_printable_breakpoints
++;
6459 ui_out_emit_table
table_emitter (uiout
,
6460 opts
.addressprint
? 6 : 5,
6461 nr_printable_breakpoints
,
6464 if (nr_printable_breakpoints
> 0)
6465 annotate_breakpoints_headers ();
6466 if (nr_printable_breakpoints
> 0)
6468 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6469 if (nr_printable_breakpoints
> 0)
6471 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6472 if (nr_printable_breakpoints
> 0)
6474 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6475 if (nr_printable_breakpoints
> 0)
6477 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6478 if (opts
.addressprint
)
6480 if (nr_printable_breakpoints
> 0)
6482 if (print_address_bits
<= 32)
6483 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6485 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6487 if (nr_printable_breakpoints
> 0)
6489 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6490 uiout
->table_body ();
6491 if (nr_printable_breakpoints
> 0)
6492 annotate_breakpoints_table ();
6497 /* If we have a filter, only list the breakpoints it accepts. */
6498 if (filter
&& !filter (b
))
6501 /* If we have a BP_NUM_LIST string, it is a list of breakpoints to
6502 accept. Skip the others. */
6504 if (bp_num_list
!= NULL
&& *bp_num_list
!= '\0')
6506 if (show_internal
) /* maintenance info breakpoint */
6508 if (parse_and_eval_long (bp_num_list
) != b
->number
)
6511 else /* all others */
6513 if (!number_is_in_list (bp_num_list
, b
->number
))
6517 /* We only print out user settable breakpoints unless the
6518 show_internal is set. */
6519 if (show_internal
|| user_breakpoint_p (b
))
6520 print_one_breakpoint (b
, &last_loc
, show_internal
);
6524 if (nr_printable_breakpoints
== 0)
6526 /* If there's a filter, let the caller decide how to report
6530 if (bp_num_list
== NULL
|| *bp_num_list
== '\0')
6531 uiout
->message ("No breakpoints or watchpoints.\n");
6533 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6539 if (last_loc
&& !server_command
)
6540 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6543 /* FIXME? Should this be moved up so that it is only called when
6544 there have been breakpoints? */
6545 annotate_breakpoints_table_end ();
6547 return nr_printable_breakpoints
;
6550 /* Display the value of default-collect in a way that is generally
6551 compatible with the breakpoint list. */
6554 default_collect_info (void)
6556 struct ui_out
*uiout
= current_uiout
;
6558 /* If it has no value (which is frequently the case), say nothing; a
6559 message like "No default-collect." gets in user's face when it's
6561 if (!*default_collect
)
6564 /* The following phrase lines up nicely with per-tracepoint collect
6566 uiout
->text ("default collect ");
6567 uiout
->field_string ("default-collect", default_collect
);
6568 uiout
->text (" \n");
6572 info_breakpoints_command (const char *args
, int from_tty
)
6574 breakpoint_1 (args
, false, NULL
);
6576 default_collect_info ();
6580 info_watchpoints_command (const char *args
, int from_tty
)
6582 int num_printed
= breakpoint_1 (args
, false, is_watchpoint
);
6583 struct ui_out
*uiout
= current_uiout
;
6585 if (num_printed
== 0)
6587 if (args
== NULL
|| *args
== '\0')
6588 uiout
->message ("No watchpoints.\n");
6590 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6595 maintenance_info_breakpoints (const char *args
, int from_tty
)
6597 breakpoint_1 (args
, true, NULL
);
6599 default_collect_info ();
6603 breakpoint_has_pc (struct breakpoint
*b
,
6604 struct program_space
*pspace
,
6605 CORE_ADDR pc
, struct obj_section
*section
)
6607 struct bp_location
*bl
= b
->loc
;
6609 for (; bl
; bl
= bl
->next
)
6611 if (bl
->pspace
== pspace
6612 && bl
->address
== pc
6613 && (!overlay_debugging
|| bl
->section
== section
))
6619 /* Print a message describing any user-breakpoints set at PC. This
6620 concerns with logical breakpoints, so we match program spaces, not
6624 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6625 struct program_space
*pspace
, CORE_ADDR pc
,
6626 struct obj_section
*section
, int thread
)
6629 struct breakpoint
*b
;
6632 others
+= (user_breakpoint_p (b
)
6633 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6637 printf_filtered (_("Note: breakpoint "));
6638 else /* if (others == ???) */
6639 printf_filtered (_("Note: breakpoints "));
6641 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6644 printf_filtered ("%d", b
->number
);
6645 if (b
->thread
== -1 && thread
!= -1)
6646 printf_filtered (" (all threads)");
6647 else if (b
->thread
!= -1)
6648 printf_filtered (" (thread %d)", b
->thread
);
6649 printf_filtered ("%s%s ",
6650 ((b
->enable_state
== bp_disabled
6651 || b
->enable_state
== bp_call_disabled
)
6655 : ((others
== 1) ? " and" : ""));
6657 current_uiout
->message (_("also set at pc %ps.\n"),
6658 styled_string (address_style
.style (),
6659 paddress (gdbarch
, pc
)));
6664 /* Return true iff it is meaningful to use the address member of LOC.
6665 For some breakpoint types, the locations' address members are
6666 irrelevant and it makes no sense to attempt to compare them to
6667 other addresses (or use them for any other purpose either).
6669 More specifically, software watchpoints and catchpoints that are
6670 not backed by breakpoints always have a zero valued location
6671 address and we don't want to mark breakpoints of any of these types
6672 to be a duplicate of an actual breakpoint location at address
6676 bl_address_is_meaningful (bp_location
*loc
)
6678 return loc
->loc_type
!= bp_loc_other
;
6681 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6682 true if LOC1 and LOC2 represent the same watchpoint location. */
6685 watchpoint_locations_match (struct bp_location
*loc1
,
6686 struct bp_location
*loc2
)
6688 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6689 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6691 /* Both of them must exist. */
6692 gdb_assert (w1
!= NULL
);
6693 gdb_assert (w2
!= NULL
);
6695 /* If the target can evaluate the condition expression in hardware,
6696 then we we need to insert both watchpoints even if they are at
6697 the same place. Otherwise the watchpoint will only trigger when
6698 the condition of whichever watchpoint was inserted evaluates to
6699 true, not giving a chance for GDB to check the condition of the
6700 other watchpoint. */
6702 && target_can_accel_watchpoint_condition (loc1
->address
,
6704 loc1
->watchpoint_type
,
6705 w1
->cond_exp
.get ()))
6707 && target_can_accel_watchpoint_condition (loc2
->address
,
6709 loc2
->watchpoint_type
,
6710 w2
->cond_exp
.get ())))
6713 /* Note that this checks the owner's type, not the location's. In
6714 case the target does not support read watchpoints, but does
6715 support access watchpoints, we'll have bp_read_watchpoint
6716 watchpoints with hw_access locations. Those should be considered
6717 duplicates of hw_read locations. The hw_read locations will
6718 become hw_access locations later. */
6719 return (loc1
->owner
->type
== loc2
->owner
->type
6720 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6721 && loc1
->address
== loc2
->address
6722 && loc1
->length
== loc2
->length
);
6725 /* See breakpoint.h. */
6728 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6729 const address_space
*aspace2
, CORE_ADDR addr2
)
6731 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6732 || aspace1
== aspace2
)
6736 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6737 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6738 matches ASPACE2. On targets that have global breakpoints, the address
6739 space doesn't really matter. */
6742 breakpoint_address_match_range (const address_space
*aspace1
,
6744 int len1
, const address_space
*aspace2
,
6747 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6748 || aspace1
== aspace2
)
6749 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6752 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6753 a ranged breakpoint. In most targets, a match happens only if ASPACE
6754 matches the breakpoint's address space. On targets that have global
6755 breakpoints, the address space doesn't really matter. */
6758 breakpoint_location_address_match (struct bp_location
*bl
,
6759 const address_space
*aspace
,
6762 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6765 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6766 bl
->address
, bl
->length
,
6770 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6771 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6772 match happens only if ASPACE matches the breakpoint's address
6773 space. On targets that have global breakpoints, the address space
6774 doesn't really matter. */
6777 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6778 const address_space
*aspace
,
6779 CORE_ADDR addr
, int len
)
6781 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6782 || bl
->pspace
->aspace
== aspace
)
6784 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6786 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6792 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6793 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6794 true, otherwise returns false. */
6797 tracepoint_locations_match (struct bp_location
*loc1
,
6798 struct bp_location
*loc2
)
6800 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6801 /* Since tracepoint locations are never duplicated with others', tracepoint
6802 locations at the same address of different tracepoints are regarded as
6803 different locations. */
6804 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6809 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6810 (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent
6811 the same location. */
6814 breakpoint_locations_match (struct bp_location
*loc1
,
6815 struct bp_location
*loc2
)
6817 int hw_point1
, hw_point2
;
6819 /* Both of them must not be in moribund_locations. */
6820 gdb_assert (loc1
->owner
!= NULL
);
6821 gdb_assert (loc2
->owner
!= NULL
);
6823 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6824 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6826 if (hw_point1
!= hw_point2
)
6829 return watchpoint_locations_match (loc1
, loc2
);
6830 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6831 return tracepoint_locations_match (loc1
, loc2
);
6833 /* We compare bp_location.length in order to cover ranged breakpoints. */
6834 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6835 loc2
->pspace
->aspace
, loc2
->address
)
6836 && loc1
->length
== loc2
->length
);
6840 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6841 int bnum
, int have_bnum
)
6843 /* The longest string possibly returned by hex_string_custom
6844 is 50 chars. These must be at least that big for safety. */
6848 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6849 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6851 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6852 bnum
, astr1
, astr2
);
6854 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6857 /* Adjust a breakpoint's address to account for architectural
6858 constraints on breakpoint placement. Return the adjusted address.
6859 Note: Very few targets require this kind of adjustment. For most
6860 targets, this function is simply the identity function. */
6863 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6864 CORE_ADDR bpaddr
, enum bptype bptype
)
6866 if (bptype
== bp_watchpoint
6867 || bptype
== bp_hardware_watchpoint
6868 || bptype
== bp_read_watchpoint
6869 || bptype
== bp_access_watchpoint
6870 || bptype
== bp_catchpoint
)
6872 /* Watchpoints and the various bp_catch_* eventpoints should not
6873 have their addresses modified. */
6876 else if (bptype
== bp_single_step
)
6878 /* Single-step breakpoints should not have their addresses
6879 modified. If there's any architectural constrain that
6880 applies to this address, then it should have already been
6881 taken into account when the breakpoint was created in the
6882 first place. If we didn't do this, stepping through e.g.,
6883 Thumb-2 IT blocks would break. */
6888 CORE_ADDR adjusted_bpaddr
= bpaddr
;
6890 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
6892 /* Some targets have architectural constraints on the placement
6893 of breakpoint instructions. Obtain the adjusted address. */
6894 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6897 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
6899 /* An adjusted breakpoint address can significantly alter
6900 a user's expectations. Print a warning if an adjustment
6902 if (adjusted_bpaddr
!= bpaddr
)
6903 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6905 return adjusted_bpaddr
;
6910 bp_location_from_bp_type (bptype type
)
6915 case bp_single_step
:
6919 case bp_longjmp_resume
:
6920 case bp_longjmp_call_dummy
:
6922 case bp_exception_resume
:
6923 case bp_step_resume
:
6924 case bp_hp_step_resume
:
6925 case bp_watchpoint_scope
:
6927 case bp_std_terminate
:
6928 case bp_shlib_event
:
6929 case bp_thread_event
:
6930 case bp_overlay_event
:
6932 case bp_longjmp_master
:
6933 case bp_std_terminate_master
:
6934 case bp_exception_master
:
6935 case bp_gnu_ifunc_resolver
:
6936 case bp_gnu_ifunc_resolver_return
:
6938 return bp_loc_software_breakpoint
;
6939 case bp_hardware_breakpoint
:
6940 return bp_loc_hardware_breakpoint
;
6941 case bp_hardware_watchpoint
:
6942 case bp_read_watchpoint
:
6943 case bp_access_watchpoint
:
6944 return bp_loc_hardware_watchpoint
;
6948 case bp_fast_tracepoint
:
6949 case bp_static_tracepoint
:
6950 return bp_loc_other
;
6952 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
6956 bp_location::bp_location (breakpoint
*owner
, bp_loc_type type
)
6958 this->owner
= owner
;
6959 this->cond_bytecode
= NULL
;
6960 this->shlib_disabled
= 0;
6963 this->loc_type
= type
;
6965 if (this->loc_type
== bp_loc_software_breakpoint
6966 || this->loc_type
== bp_loc_hardware_breakpoint
)
6967 mark_breakpoint_location_modified (this);
6972 bp_location::bp_location (breakpoint
*owner
)
6973 : bp_location::bp_location (owner
,
6974 bp_location_from_bp_type (owner
->type
))
6978 /* Allocate a struct bp_location. */
6980 static struct bp_location
*
6981 allocate_bp_location (struct breakpoint
*bpt
)
6983 return bpt
->ops
->allocate_location (bpt
);
6987 free_bp_location (struct bp_location
*loc
)
6992 /* Increment reference count. */
6995 incref_bp_location (struct bp_location
*bl
)
7000 /* Decrement reference count. If the reference count reaches 0,
7001 destroy the bp_location. Sets *BLP to NULL. */
7004 decref_bp_location (struct bp_location
**blp
)
7006 gdb_assert ((*blp
)->refc
> 0);
7008 if (--(*blp
)->refc
== 0)
7009 free_bp_location (*blp
);
7013 /* Add breakpoint B at the end of the global breakpoint chain. */
7016 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7018 struct breakpoint
*b1
;
7019 struct breakpoint
*result
= b
.get ();
7021 /* Add this breakpoint to the end of the chain so that a list of
7022 breakpoints will come out in order of increasing numbers. */
7024 b1
= breakpoint_chain
;
7026 breakpoint_chain
= b
.release ();
7031 b1
->next
= b
.release ();
7037 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7040 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7041 struct gdbarch
*gdbarch
,
7043 const struct breakpoint_ops
*ops
)
7045 gdb_assert (ops
!= NULL
);
7049 b
->gdbarch
= gdbarch
;
7050 b
->language
= current_language
->la_language
;
7051 b
->input_radix
= input_radix
;
7052 b
->related_breakpoint
= b
;
7055 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7056 that has type BPTYPE and has no locations as yet. */
7058 static struct breakpoint
*
7059 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7061 const struct breakpoint_ops
*ops
)
7063 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7065 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7066 return add_to_breakpoint_chain (std::move (b
));
7069 /* Initialize loc->function_name. */
7072 set_breakpoint_location_function (struct bp_location
*loc
)
7074 gdb_assert (loc
->owner
!= NULL
);
7076 if (loc
->owner
->type
== bp_breakpoint
7077 || loc
->owner
->type
== bp_hardware_breakpoint
7078 || is_tracepoint (loc
->owner
))
7080 const char *function_name
;
7082 if (loc
->msymbol
!= NULL
7083 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7084 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7086 struct breakpoint
*b
= loc
->owner
;
7088 function_name
= MSYMBOL_LINKAGE_NAME (loc
->msymbol
);
7090 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7091 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7093 /* Create only the whole new breakpoint of this type but do not
7094 mess more complicated breakpoints with multiple locations. */
7095 b
->type
= bp_gnu_ifunc_resolver
;
7096 /* Remember the resolver's address for use by the return
7098 loc
->related_address
= loc
->address
;
7102 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7105 loc
->function_name
= xstrdup (function_name
);
7109 /* Attempt to determine architecture of location identified by SAL. */
7111 get_sal_arch (struct symtab_and_line sal
)
7114 return get_objfile_arch (sal
.section
->objfile
);
7116 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7121 /* Low level routine for partially initializing a breakpoint of type
7122 BPTYPE. The newly created breakpoint's address, section, source
7123 file name, and line number are provided by SAL.
7125 It is expected that the caller will complete the initialization of
7126 the newly created breakpoint struct as well as output any status
7127 information regarding the creation of a new breakpoint. */
7130 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7131 struct symtab_and_line sal
, enum bptype bptype
,
7132 const struct breakpoint_ops
*ops
)
7134 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7136 add_location_to_breakpoint (b
, &sal
);
7138 if (bptype
!= bp_catchpoint
)
7139 gdb_assert (sal
.pspace
!= NULL
);
7141 /* Store the program space that was used to set the breakpoint,
7142 except for ordinary breakpoints, which are independent of the
7144 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7145 b
->pspace
= sal
.pspace
;
7148 /* set_raw_breakpoint is a low level routine for allocating and
7149 partially initializing a breakpoint of type BPTYPE. The newly
7150 created breakpoint's address, section, source file name, and line
7151 number are provided by SAL. The newly created and partially
7152 initialized breakpoint is added to the breakpoint chain and
7153 is also returned as the value of this function.
7155 It is expected that the caller will complete the initialization of
7156 the newly created breakpoint struct as well as output any status
7157 information regarding the creation of a new breakpoint. In
7158 particular, set_raw_breakpoint does NOT set the breakpoint
7159 number! Care should be taken to not allow an error to occur
7160 prior to completing the initialization of the breakpoint. If this
7161 should happen, a bogus breakpoint will be left on the chain. */
7164 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7165 struct symtab_and_line sal
, enum bptype bptype
,
7166 const struct breakpoint_ops
*ops
)
7168 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7170 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7171 return add_to_breakpoint_chain (std::move (b
));
7174 /* Call this routine when stepping and nexting to enable a breakpoint
7175 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7176 initiated the operation. */
7179 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7181 struct breakpoint
*b
, *b_tmp
;
7182 int thread
= tp
->global_num
;
7184 /* To avoid having to rescan all objfile symbols at every step,
7185 we maintain a list of continually-inserted but always disabled
7186 longjmp "master" breakpoints. Here, we simply create momentary
7187 clones of those and enable them for the requested thread. */
7188 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7189 if (b
->pspace
== current_program_space
7190 && (b
->type
== bp_longjmp_master
7191 || b
->type
== bp_exception_master
))
7193 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7194 struct breakpoint
*clone
;
7196 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7197 after their removal. */
7198 clone
= momentary_breakpoint_from_master (b
, type
,
7199 &momentary_breakpoint_ops
, 1);
7200 clone
->thread
= thread
;
7203 tp
->initiating_frame
= frame
;
7206 /* Delete all longjmp breakpoints from THREAD. */
7208 delete_longjmp_breakpoint (int thread
)
7210 struct breakpoint
*b
, *b_tmp
;
7212 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7213 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7215 if (b
->thread
== thread
)
7216 delete_breakpoint (b
);
7221 delete_longjmp_breakpoint_at_next_stop (int thread
)
7223 struct breakpoint
*b
, *b_tmp
;
7225 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7226 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7228 if (b
->thread
== thread
)
7229 b
->disposition
= disp_del_at_next_stop
;
7233 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7234 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7235 pointer to any of them. Return NULL if this system cannot place longjmp
7239 set_longjmp_breakpoint_for_call_dummy (void)
7241 struct breakpoint
*b
, *retval
= NULL
;
7244 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7246 struct breakpoint
*new_b
;
7248 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7249 &momentary_breakpoint_ops
,
7251 new_b
->thread
= inferior_thread ()->global_num
;
7253 /* Link NEW_B into the chain of RETVAL breakpoints. */
7255 gdb_assert (new_b
->related_breakpoint
== new_b
);
7258 new_b
->related_breakpoint
= retval
;
7259 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7260 retval
= retval
->related_breakpoint
;
7261 retval
->related_breakpoint
= new_b
;
7267 /* Verify all existing dummy frames and their associated breakpoints for
7268 TP. Remove those which can no longer be found in the current frame
7271 You should call this function only at places where it is safe to currently
7272 unwind the whole stack. Failed stack unwind would discard live dummy
7276 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7278 struct breakpoint
*b
, *b_tmp
;
7280 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7281 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7283 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7285 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7286 dummy_b
= dummy_b
->related_breakpoint
;
7287 if (dummy_b
->type
!= bp_call_dummy
7288 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7291 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7293 while (b
->related_breakpoint
!= b
)
7295 if (b_tmp
== b
->related_breakpoint
)
7296 b_tmp
= b
->related_breakpoint
->next
;
7297 delete_breakpoint (b
->related_breakpoint
);
7299 delete_breakpoint (b
);
7304 enable_overlay_breakpoints (void)
7306 struct breakpoint
*b
;
7309 if (b
->type
== bp_overlay_event
)
7311 b
->enable_state
= bp_enabled
;
7312 update_global_location_list (UGLL_MAY_INSERT
);
7313 overlay_events_enabled
= 1;
7318 disable_overlay_breakpoints (void)
7320 struct breakpoint
*b
;
7323 if (b
->type
== bp_overlay_event
)
7325 b
->enable_state
= bp_disabled
;
7326 update_global_location_list (UGLL_DONT_INSERT
);
7327 overlay_events_enabled
= 0;
7331 /* Set an active std::terminate breakpoint for each std::terminate
7332 master breakpoint. */
7334 set_std_terminate_breakpoint (void)
7336 struct breakpoint
*b
, *b_tmp
;
7338 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7339 if (b
->pspace
== current_program_space
7340 && b
->type
== bp_std_terminate_master
)
7342 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7343 &momentary_breakpoint_ops
, 1);
7347 /* Delete all the std::terminate breakpoints. */
7349 delete_std_terminate_breakpoint (void)
7351 struct breakpoint
*b
, *b_tmp
;
7353 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7354 if (b
->type
== bp_std_terminate
)
7355 delete_breakpoint (b
);
7359 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7361 struct breakpoint
*b
;
7363 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7364 &internal_breakpoint_ops
);
7366 b
->enable_state
= bp_enabled
;
7367 /* location has to be used or breakpoint_re_set will delete me. */
7368 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7370 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7375 struct lang_and_radix
7381 /* Create a breakpoint for JIT code registration and unregistration. */
7384 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7386 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7387 &internal_breakpoint_ops
);
7390 /* Remove JIT code registration and unregistration breakpoint(s). */
7393 remove_jit_event_breakpoints (void)
7395 struct breakpoint
*b
, *b_tmp
;
7397 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7398 if (b
->type
== bp_jit_event
7399 && b
->loc
->pspace
== current_program_space
)
7400 delete_breakpoint (b
);
7404 remove_solib_event_breakpoints (void)
7406 struct breakpoint
*b
, *b_tmp
;
7408 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7409 if (b
->type
== bp_shlib_event
7410 && b
->loc
->pspace
== current_program_space
)
7411 delete_breakpoint (b
);
7414 /* See breakpoint.h. */
7417 remove_solib_event_breakpoints_at_next_stop (void)
7419 struct breakpoint
*b
, *b_tmp
;
7421 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7422 if (b
->type
== bp_shlib_event
7423 && b
->loc
->pspace
== current_program_space
)
7424 b
->disposition
= disp_del_at_next_stop
;
7427 /* Helper for create_solib_event_breakpoint /
7428 create_and_insert_solib_event_breakpoint. Allows specifying which
7429 INSERT_MODE to pass through to update_global_location_list. */
7431 static struct breakpoint
*
7432 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7433 enum ugll_insert_mode insert_mode
)
7435 struct breakpoint
*b
;
7437 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7438 &internal_breakpoint_ops
);
7439 update_global_location_list_nothrow (insert_mode
);
7444 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7446 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7449 /* See breakpoint.h. */
7452 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7454 struct breakpoint
*b
;
7456 /* Explicitly tell update_global_location_list to insert
7458 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7459 if (!b
->loc
->inserted
)
7461 delete_breakpoint (b
);
7467 /* Disable any breakpoints that are on code in shared libraries. Only
7468 apply to enabled breakpoints, disabled ones can just stay disabled. */
7471 disable_breakpoints_in_shlibs (void)
7473 struct bp_location
*loc
, **locp_tmp
;
7475 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7477 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7478 struct breakpoint
*b
= loc
->owner
;
7480 /* We apply the check to all breakpoints, including disabled for
7481 those with loc->duplicate set. This is so that when breakpoint
7482 becomes enabled, or the duplicate is removed, gdb will try to
7483 insert all breakpoints. If we don't set shlib_disabled here,
7484 we'll try to insert those breakpoints and fail. */
7485 if (((b
->type
== bp_breakpoint
)
7486 || (b
->type
== bp_jit_event
)
7487 || (b
->type
== bp_hardware_breakpoint
)
7488 || (is_tracepoint (b
)))
7489 && loc
->pspace
== current_program_space
7490 && !loc
->shlib_disabled
7491 && solib_name_from_address (loc
->pspace
, loc
->address
)
7494 loc
->shlib_disabled
= 1;
7499 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7500 notification of unloaded_shlib. Only apply to enabled breakpoints,
7501 disabled ones can just stay disabled. */
7504 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7506 struct bp_location
*loc
, **locp_tmp
;
7507 int disabled_shlib_breaks
= 0;
7509 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7511 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7512 struct breakpoint
*b
= loc
->owner
;
7514 if (solib
->pspace
== loc
->pspace
7515 && !loc
->shlib_disabled
7516 && (((b
->type
== bp_breakpoint
7517 || b
->type
== bp_jit_event
7518 || b
->type
== bp_hardware_breakpoint
)
7519 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7520 || loc
->loc_type
== bp_loc_software_breakpoint
))
7521 || is_tracepoint (b
))
7522 && solib_contains_address_p (solib
, loc
->address
))
7524 loc
->shlib_disabled
= 1;
7525 /* At this point, we cannot rely on remove_breakpoint
7526 succeeding so we must mark the breakpoint as not inserted
7527 to prevent future errors occurring in remove_breakpoints. */
7530 /* This may cause duplicate notifications for the same breakpoint. */
7531 gdb::observers::breakpoint_modified
.notify (b
);
7533 if (!disabled_shlib_breaks
)
7535 target_terminal::ours_for_output ();
7536 warning (_("Temporarily disabling breakpoints "
7537 "for unloaded shared library \"%s\""),
7540 disabled_shlib_breaks
= 1;
7545 /* Disable any breakpoints and tracepoints in OBJFILE upon
7546 notification of free_objfile. Only apply to enabled breakpoints,
7547 disabled ones can just stay disabled. */
7550 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7552 struct breakpoint
*b
;
7554 if (objfile
== NULL
)
7557 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7558 managed by the user with add-symbol-file/remove-symbol-file.
7559 Similarly to how breakpoints in shared libraries are handled in
7560 response to "nosharedlibrary", mark breakpoints in such modules
7561 shlib_disabled so they end up uninserted on the next global
7562 location list update. Shared libraries not loaded by the user
7563 aren't handled here -- they're already handled in
7564 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7565 solib_unloaded observer. We skip objfiles that are not
7566 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7568 if ((objfile
->flags
& OBJF_SHARED
) == 0
7569 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7574 struct bp_location
*loc
;
7575 int bp_modified
= 0;
7577 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7580 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7582 CORE_ADDR loc_addr
= loc
->address
;
7584 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7585 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7588 if (loc
->shlib_disabled
!= 0)
7591 if (objfile
->pspace
!= loc
->pspace
)
7594 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7595 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7598 if (is_addr_in_objfile (loc_addr
, objfile
))
7600 loc
->shlib_disabled
= 1;
7601 /* At this point, we don't know whether the object was
7602 unmapped from the inferior or not, so leave the
7603 inserted flag alone. We'll handle failure to
7604 uninsert quietly, in case the object was indeed
7607 mark_breakpoint_location_modified (loc
);
7614 gdb::observers::breakpoint_modified
.notify (b
);
7618 /* FORK & VFORK catchpoints. */
7620 /* An instance of this type is used to represent a fork or vfork
7621 catchpoint. A breakpoint is really of this type iff its ops pointer points
7622 to CATCH_FORK_BREAKPOINT_OPS. */
7624 struct fork_catchpoint
: public breakpoint
7626 /* Process id of a child process whose forking triggered this
7627 catchpoint. This field is only valid immediately after this
7628 catchpoint has triggered. */
7629 ptid_t forked_inferior_pid
;
7632 /* Implement the "insert" breakpoint_ops method for fork
7636 insert_catch_fork (struct bp_location
*bl
)
7638 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7641 /* Implement the "remove" breakpoint_ops method for fork
7645 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7647 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7650 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7654 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7655 const address_space
*aspace
, CORE_ADDR bp_addr
,
7656 const struct target_waitstatus
*ws
)
7658 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7660 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7663 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7667 /* Implement the "print_it" breakpoint_ops method for fork
7670 static enum print_stop_action
7671 print_it_catch_fork (bpstat bs
)
7673 struct ui_out
*uiout
= current_uiout
;
7674 struct breakpoint
*b
= bs
->breakpoint_at
;
7675 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7677 annotate_catchpoint (b
->number
);
7678 maybe_print_thread_hit_breakpoint (uiout
);
7679 if (b
->disposition
== disp_del
)
7680 uiout
->text ("Temporary catchpoint ");
7682 uiout
->text ("Catchpoint ");
7683 if (uiout
->is_mi_like_p ())
7685 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7686 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7688 uiout
->field_signed ("bkptno", b
->number
);
7689 uiout
->text (" (forked process ");
7690 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7691 uiout
->text ("), ");
7692 return PRINT_SRC_AND_LOC
;
7695 /* Implement the "print_one" breakpoint_ops method for fork
7699 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7701 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7702 struct value_print_options opts
;
7703 struct ui_out
*uiout
= current_uiout
;
7705 get_user_print_options (&opts
);
7707 /* Field 4, the address, is omitted (which makes the columns not
7708 line up too nicely with the headers, but the effect is relatively
7710 if (opts
.addressprint
)
7711 uiout
->field_skip ("addr");
7713 uiout
->text ("fork");
7714 if (c
->forked_inferior_pid
!= null_ptid
)
7716 uiout
->text (", process ");
7717 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7721 if (uiout
->is_mi_like_p ())
7722 uiout
->field_string ("catch-type", "fork");
7725 /* Implement the "print_mention" breakpoint_ops method for fork
7729 print_mention_catch_fork (struct breakpoint
*b
)
7731 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7734 /* Implement the "print_recreate" breakpoint_ops method for fork
7738 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7740 fprintf_unfiltered (fp
, "catch fork");
7741 print_recreate_thread (b
, fp
);
7744 /* The breakpoint_ops structure to be used in fork catchpoints. */
7746 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7748 /* Implement the "insert" breakpoint_ops method for vfork
7752 insert_catch_vfork (struct bp_location
*bl
)
7754 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7757 /* Implement the "remove" breakpoint_ops method for vfork
7761 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7763 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7766 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7770 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7771 const address_space
*aspace
, CORE_ADDR bp_addr
,
7772 const struct target_waitstatus
*ws
)
7774 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7776 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7779 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7783 /* Implement the "print_it" breakpoint_ops method for vfork
7786 static enum print_stop_action
7787 print_it_catch_vfork (bpstat bs
)
7789 struct ui_out
*uiout
= current_uiout
;
7790 struct breakpoint
*b
= bs
->breakpoint_at
;
7791 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7793 annotate_catchpoint (b
->number
);
7794 maybe_print_thread_hit_breakpoint (uiout
);
7795 if (b
->disposition
== disp_del
)
7796 uiout
->text ("Temporary catchpoint ");
7798 uiout
->text ("Catchpoint ");
7799 if (uiout
->is_mi_like_p ())
7801 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7802 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7804 uiout
->field_signed ("bkptno", b
->number
);
7805 uiout
->text (" (vforked process ");
7806 uiout
->field_signed ("newpid", c
->forked_inferior_pid
.pid ());
7807 uiout
->text ("), ");
7808 return PRINT_SRC_AND_LOC
;
7811 /* Implement the "print_one" breakpoint_ops method for vfork
7815 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7817 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7818 struct value_print_options opts
;
7819 struct ui_out
*uiout
= current_uiout
;
7821 get_user_print_options (&opts
);
7822 /* Field 4, the address, is omitted (which makes the columns not
7823 line up too nicely with the headers, but the effect is relatively
7825 if (opts
.addressprint
)
7826 uiout
->field_skip ("addr");
7828 uiout
->text ("vfork");
7829 if (c
->forked_inferior_pid
!= null_ptid
)
7831 uiout
->text (", process ");
7832 uiout
->field_signed ("what", c
->forked_inferior_pid
.pid ());
7836 if (uiout
->is_mi_like_p ())
7837 uiout
->field_string ("catch-type", "vfork");
7840 /* Implement the "print_mention" breakpoint_ops method for vfork
7844 print_mention_catch_vfork (struct breakpoint
*b
)
7846 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7849 /* Implement the "print_recreate" breakpoint_ops method for vfork
7853 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7855 fprintf_unfiltered (fp
, "catch vfork");
7856 print_recreate_thread (b
, fp
);
7859 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7861 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7863 /* An instance of this type is used to represent an solib catchpoint.
7864 A breakpoint is really of this type iff its ops pointer points to
7865 CATCH_SOLIB_BREAKPOINT_OPS. */
7867 struct solib_catchpoint
: public breakpoint
7869 ~solib_catchpoint () override
;
7871 /* True for "catch load", false for "catch unload". */
7872 unsigned char is_load
;
7874 /* Regular expression to match, if any. COMPILED is only valid when
7875 REGEX is non-NULL. */
7877 std::unique_ptr
<compiled_regex
> compiled
;
7880 solib_catchpoint::~solib_catchpoint ()
7882 xfree (this->regex
);
7886 insert_catch_solib (struct bp_location
*ignore
)
7892 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
7898 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7899 const address_space
*aspace
,
7901 const struct target_waitstatus
*ws
)
7903 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7904 struct breakpoint
*other
;
7906 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7909 ALL_BREAKPOINTS (other
)
7911 struct bp_location
*other_bl
;
7913 if (other
== bl
->owner
)
7916 if (other
->type
!= bp_shlib_event
)
7919 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
7922 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7924 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7933 check_status_catch_solib (struct bpstats
*bs
)
7935 struct solib_catchpoint
*self
7936 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7940 for (so_list
*iter
: current_program_space
->added_solibs
)
7943 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
7949 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
7952 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
7958 bs
->print_it
= print_it_noop
;
7961 static enum print_stop_action
7962 print_it_catch_solib (bpstat bs
)
7964 struct breakpoint
*b
= bs
->breakpoint_at
;
7965 struct ui_out
*uiout
= current_uiout
;
7967 annotate_catchpoint (b
->number
);
7968 maybe_print_thread_hit_breakpoint (uiout
);
7969 if (b
->disposition
== disp_del
)
7970 uiout
->text ("Temporary catchpoint ");
7972 uiout
->text ("Catchpoint ");
7973 uiout
->field_signed ("bkptno", b
->number
);
7975 if (uiout
->is_mi_like_p ())
7976 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7977 print_solib_event (1);
7978 return PRINT_SRC_AND_LOC
;
7982 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
7984 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
7985 struct value_print_options opts
;
7986 struct ui_out
*uiout
= current_uiout
;
7988 get_user_print_options (&opts
);
7989 /* Field 4, the address, is omitted (which makes the columns not
7990 line up too nicely with the headers, but the effect is relatively
7992 if (opts
.addressprint
)
7995 uiout
->field_skip ("addr");
8003 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8005 msg
= _("load of library");
8010 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8012 msg
= _("unload of library");
8014 uiout
->field_string ("what", msg
);
8016 if (uiout
->is_mi_like_p ())
8017 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8021 print_mention_catch_solib (struct breakpoint
*b
)
8023 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8025 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8026 self
->is_load
? "load" : "unload");
8030 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8032 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8034 fprintf_unfiltered (fp
, "%s %s",
8035 b
->disposition
== disp_del
? "tcatch" : "catch",
8036 self
->is_load
? "load" : "unload");
8038 fprintf_unfiltered (fp
, " %s", self
->regex
);
8039 fprintf_unfiltered (fp
, "\n");
8042 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8044 /* Shared helper function (MI and CLI) for creating and installing
8045 a shared object event catchpoint. If IS_LOAD is non-zero then
8046 the events to be caught are load events, otherwise they are
8047 unload events. If IS_TEMP is non-zero the catchpoint is a
8048 temporary one. If ENABLED is non-zero the catchpoint is
8049 created in an enabled state. */
8052 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8054 struct gdbarch
*gdbarch
= get_current_arch ();
8058 arg
= skip_spaces (arg
);
8060 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8064 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8065 _("Invalid regexp")));
8066 c
->regex
= xstrdup (arg
);
8069 c
->is_load
= is_load
;
8070 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8071 &catch_solib_breakpoint_ops
);
8073 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8075 install_breakpoint (0, std::move (c
), 1);
8078 /* A helper function that does all the work for "catch load" and
8082 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8083 struct cmd_list_element
*command
)
8086 const int enabled
= 1;
8088 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8090 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8094 catch_load_command_1 (const char *arg
, int from_tty
,
8095 struct cmd_list_element
*command
)
8097 catch_load_or_unload (arg
, from_tty
, 1, command
);
8101 catch_unload_command_1 (const char *arg
, int from_tty
,
8102 struct cmd_list_element
*command
)
8104 catch_load_or_unload (arg
, from_tty
, 0, command
);
8107 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8108 is non-zero, then make the breakpoint temporary. If COND_STRING is
8109 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8110 the breakpoint_ops structure associated to the catchpoint. */
8113 init_catchpoint (struct breakpoint
*b
,
8114 struct gdbarch
*gdbarch
, int tempflag
,
8115 const char *cond_string
,
8116 const struct breakpoint_ops
*ops
)
8118 symtab_and_line sal
;
8119 sal
.pspace
= current_program_space
;
8121 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8123 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8124 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8128 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8130 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8131 set_breakpoint_number (internal
, b
);
8132 if (is_tracepoint (b
))
8133 set_tracepoint_count (breakpoint_count
);
8136 gdb::observers::breakpoint_created
.notify (b
);
8139 update_global_location_list (UGLL_MAY_INSERT
);
8143 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8144 int tempflag
, const char *cond_string
,
8145 const struct breakpoint_ops
*ops
)
8147 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8149 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8151 c
->forked_inferior_pid
= null_ptid
;
8153 install_breakpoint (0, std::move (c
), 1);
8156 /* Exec catchpoints. */
8158 /* An instance of this type is used to represent an exec catchpoint.
8159 A breakpoint is really of this type iff its ops pointer points to
8160 CATCH_EXEC_BREAKPOINT_OPS. */
8162 struct exec_catchpoint
: public breakpoint
8164 ~exec_catchpoint () override
;
8166 /* Filename of a program whose exec triggered this catchpoint.
8167 This field is only valid immediately after this catchpoint has
8169 char *exec_pathname
;
8172 /* Exec catchpoint destructor. */
8174 exec_catchpoint::~exec_catchpoint ()
8176 xfree (this->exec_pathname
);
8180 insert_catch_exec (struct bp_location
*bl
)
8182 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8186 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8188 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8192 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8193 const address_space
*aspace
, CORE_ADDR bp_addr
,
8194 const struct target_waitstatus
*ws
)
8196 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8198 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8201 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8205 static enum print_stop_action
8206 print_it_catch_exec (bpstat bs
)
8208 struct ui_out
*uiout
= current_uiout
;
8209 struct breakpoint
*b
= bs
->breakpoint_at
;
8210 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8212 annotate_catchpoint (b
->number
);
8213 maybe_print_thread_hit_breakpoint (uiout
);
8214 if (b
->disposition
== disp_del
)
8215 uiout
->text ("Temporary catchpoint ");
8217 uiout
->text ("Catchpoint ");
8218 if (uiout
->is_mi_like_p ())
8220 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8221 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8223 uiout
->field_signed ("bkptno", b
->number
);
8224 uiout
->text (" (exec'd ");
8225 uiout
->field_string ("new-exec", c
->exec_pathname
);
8226 uiout
->text ("), ");
8228 return PRINT_SRC_AND_LOC
;
8232 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8234 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8235 struct value_print_options opts
;
8236 struct ui_out
*uiout
= current_uiout
;
8238 get_user_print_options (&opts
);
8240 /* Field 4, the address, is omitted (which makes the columns
8241 not line up too nicely with the headers, but the effect
8242 is relatively readable). */
8243 if (opts
.addressprint
)
8244 uiout
->field_skip ("addr");
8246 uiout
->text ("exec");
8247 if (c
->exec_pathname
!= NULL
)
8249 uiout
->text (", program \"");
8250 uiout
->field_string ("what", c
->exec_pathname
);
8251 uiout
->text ("\" ");
8254 if (uiout
->is_mi_like_p ())
8255 uiout
->field_string ("catch-type", "exec");
8259 print_mention_catch_exec (struct breakpoint
*b
)
8261 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8264 /* Implement the "print_recreate" breakpoint_ops method for exec
8268 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8270 fprintf_unfiltered (fp
, "catch exec");
8271 print_recreate_thread (b
, fp
);
8274 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8277 hw_breakpoint_used_count (void)
8280 struct breakpoint
*b
;
8281 struct bp_location
*bl
;
8285 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8286 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8288 /* Special types of hardware breakpoints may use more than
8290 i
+= b
->ops
->resources_needed (bl
);
8297 /* Returns the resources B would use if it were a hardware
8301 hw_watchpoint_use_count (struct breakpoint
*b
)
8304 struct bp_location
*bl
;
8306 if (!breakpoint_enabled (b
))
8309 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8311 /* Special types of hardware watchpoints may use more than
8313 i
+= b
->ops
->resources_needed (bl
);
8319 /* Returns the sum the used resources of all hardware watchpoints of
8320 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8321 the sum of the used resources of all hardware watchpoints of other
8322 types _not_ TYPE. */
8325 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8326 enum bptype type
, int *other_type_used
)
8329 struct breakpoint
*b
;
8331 *other_type_used
= 0;
8336 if (!breakpoint_enabled (b
))
8339 if (b
->type
== type
)
8340 i
+= hw_watchpoint_use_count (b
);
8341 else if (is_hardware_watchpoint (b
))
8342 *other_type_used
= 1;
8349 disable_watchpoints_before_interactive_call_start (void)
8351 struct breakpoint
*b
;
8355 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8357 b
->enable_state
= bp_call_disabled
;
8358 update_global_location_list (UGLL_DONT_INSERT
);
8364 enable_watchpoints_after_interactive_call_stop (void)
8366 struct breakpoint
*b
;
8370 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8372 b
->enable_state
= bp_enabled
;
8373 update_global_location_list (UGLL_MAY_INSERT
);
8379 disable_breakpoints_before_startup (void)
8381 current_program_space
->executing_startup
= 1;
8382 update_global_location_list (UGLL_DONT_INSERT
);
8386 enable_breakpoints_after_startup (void)
8388 current_program_space
->executing_startup
= 0;
8389 breakpoint_re_set ();
8392 /* Create a new single-step breakpoint for thread THREAD, with no
8395 static struct breakpoint
*
8396 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8398 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8400 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8401 &momentary_breakpoint_ops
);
8403 b
->disposition
= disp_donttouch
;
8404 b
->frame_id
= null_frame_id
;
8407 gdb_assert (b
->thread
!= 0);
8409 return add_to_breakpoint_chain (std::move (b
));
8412 /* Set a momentary breakpoint of type TYPE at address specified by
8413 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8417 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8418 struct frame_id frame_id
, enum bptype type
)
8420 struct breakpoint
*b
;
8422 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8424 gdb_assert (!frame_id_artificial_p (frame_id
));
8426 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8427 b
->enable_state
= bp_enabled
;
8428 b
->disposition
= disp_donttouch
;
8429 b
->frame_id
= frame_id
;
8431 b
->thread
= inferior_thread ()->global_num
;
8433 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8435 return breakpoint_up (b
);
8438 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8439 The new breakpoint will have type TYPE, use OPS as its
8440 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8442 static struct breakpoint
*
8443 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8445 const struct breakpoint_ops
*ops
,
8448 struct breakpoint
*copy
;
8450 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8451 copy
->loc
= allocate_bp_location (copy
);
8452 set_breakpoint_location_function (copy
->loc
);
8454 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8455 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8456 copy
->loc
->address
= orig
->loc
->address
;
8457 copy
->loc
->section
= orig
->loc
->section
;
8458 copy
->loc
->pspace
= orig
->loc
->pspace
;
8459 copy
->loc
->probe
= orig
->loc
->probe
;
8460 copy
->loc
->line_number
= orig
->loc
->line_number
;
8461 copy
->loc
->symtab
= orig
->loc
->symtab
;
8462 copy
->loc
->enabled
= loc_enabled
;
8463 copy
->frame_id
= orig
->frame_id
;
8464 copy
->thread
= orig
->thread
;
8465 copy
->pspace
= orig
->pspace
;
8467 copy
->enable_state
= bp_enabled
;
8468 copy
->disposition
= disp_donttouch
;
8469 copy
->number
= internal_breakpoint_number
--;
8471 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8475 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8479 clone_momentary_breakpoint (struct breakpoint
*orig
)
8481 /* If there's nothing to clone, then return nothing. */
8485 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8489 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8492 struct symtab_and_line sal
;
8494 sal
= find_pc_line (pc
, 0);
8496 sal
.section
= find_pc_overlay (pc
);
8497 sal
.explicit_pc
= 1;
8499 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8503 /* Tell the user we have just set a breakpoint B. */
8506 mention (struct breakpoint
*b
)
8508 b
->ops
->print_mention (b
);
8509 current_uiout
->text ("\n");
8513 static int bp_loc_is_permanent (struct bp_location
*loc
);
8515 static struct bp_location
*
8516 add_location_to_breakpoint (struct breakpoint
*b
,
8517 const struct symtab_and_line
*sal
)
8519 struct bp_location
*loc
, **tmp
;
8520 CORE_ADDR adjusted_address
;
8521 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8523 if (loc_gdbarch
== NULL
)
8524 loc_gdbarch
= b
->gdbarch
;
8526 /* Adjust the breakpoint's address prior to allocating a location.
8527 Once we call allocate_bp_location(), that mostly uninitialized
8528 location will be placed on the location chain. Adjustment of the
8529 breakpoint may cause target_read_memory() to be called and we do
8530 not want its scan of the location chain to find a breakpoint and
8531 location that's only been partially initialized. */
8532 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8535 /* Sort the locations by their ADDRESS. */
8536 loc
= allocate_bp_location (b
);
8537 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8538 tmp
= &((*tmp
)->next
))
8543 loc
->requested_address
= sal
->pc
;
8544 loc
->address
= adjusted_address
;
8545 loc
->pspace
= sal
->pspace
;
8546 loc
->probe
.prob
= sal
->prob
;
8547 loc
->probe
.objfile
= sal
->objfile
;
8548 gdb_assert (loc
->pspace
!= NULL
);
8549 loc
->section
= sal
->section
;
8550 loc
->gdbarch
= loc_gdbarch
;
8551 loc
->line_number
= sal
->line
;
8552 loc
->symtab
= sal
->symtab
;
8553 loc
->symbol
= sal
->symbol
;
8554 loc
->msymbol
= sal
->msymbol
;
8555 loc
->objfile
= sal
->objfile
;
8557 set_breakpoint_location_function (loc
);
8559 /* While by definition, permanent breakpoints are already present in the
8560 code, we don't mark the location as inserted. Normally one would expect
8561 that GDB could rely on that breakpoint instruction to stop the program,
8562 thus removing the need to insert its own breakpoint, except that executing
8563 the breakpoint instruction can kill the target instead of reporting a
8564 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8565 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8566 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8567 breakpoint be inserted normally results in QEMU knowing about the GDB
8568 breakpoint, and thus trap before the breakpoint instruction is executed.
8569 (If GDB later needs to continue execution past the permanent breakpoint,
8570 it manually increments the PC, thus avoiding executing the breakpoint
8572 if (bp_loc_is_permanent (loc
))
8579 /* See breakpoint.h. */
8582 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8586 const gdb_byte
*bpoint
;
8587 gdb_byte
*target_mem
;
8590 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8592 /* Software breakpoints unsupported? */
8596 target_mem
= (gdb_byte
*) alloca (len
);
8598 /* Enable the automatic memory restoration from breakpoints while
8599 we read the memory. Otherwise we could say about our temporary
8600 breakpoints they are permanent. */
8601 scoped_restore restore_memory
8602 = make_scoped_restore_show_memory_breakpoints (0);
8604 if (target_read_memory (address
, target_mem
, len
) == 0
8605 && memcmp (target_mem
, bpoint
, len
) == 0)
8611 /* Return 1 if LOC is pointing to a permanent breakpoint,
8612 return 0 otherwise. */
8615 bp_loc_is_permanent (struct bp_location
*loc
)
8617 gdb_assert (loc
!= NULL
);
8619 /* If we have a non-breakpoint-backed catchpoint or a software
8620 watchpoint, just return 0. We should not attempt to read from
8621 the addresses the locations of these breakpoint types point to.
8622 program_breakpoint_here_p, below, will attempt to read
8624 if (!bl_address_is_meaningful (loc
))
8627 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8628 switch_to_program_space_and_thread (loc
->pspace
);
8629 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8632 /* Build a command list for the dprintf corresponding to the current
8633 settings of the dprintf style options. */
8636 update_dprintf_command_list (struct breakpoint
*b
)
8638 char *dprintf_args
= b
->extra_string
;
8639 char *printf_line
= NULL
;
8644 dprintf_args
= skip_spaces (dprintf_args
);
8646 /* Allow a comma, as it may have terminated a location, but don't
8648 if (*dprintf_args
== ',')
8650 dprintf_args
= skip_spaces (dprintf_args
);
8652 if (*dprintf_args
!= '"')
8653 error (_("Bad format string, missing '\"'."));
8655 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8656 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8657 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8659 if (!dprintf_function
)
8660 error (_("No function supplied for dprintf call"));
8662 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8663 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8668 printf_line
= xstrprintf ("call (void) %s (%s)",
8672 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8674 if (target_can_run_breakpoint_commands ())
8675 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8678 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8679 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8683 internal_error (__FILE__
, __LINE__
,
8684 _("Invalid dprintf style."));
8686 gdb_assert (printf_line
!= NULL
);
8688 /* Manufacture a printf sequence. */
8689 struct command_line
*printf_cmd_line
8690 = new struct command_line (simple_control
, printf_line
);
8691 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8692 command_lines_deleter ()));
8695 /* Update all dprintf commands, making their command lists reflect
8696 current style settings. */
8699 update_dprintf_commands (const char *args
, int from_tty
,
8700 struct cmd_list_element
*c
)
8702 struct breakpoint
*b
;
8706 if (b
->type
== bp_dprintf
)
8707 update_dprintf_command_list (b
);
8711 /* Create a breakpoint with SAL as location. Use LOCATION
8712 as a description of the location, and COND_STRING
8713 as condition expression. If LOCATION is NULL then create an
8714 "address location" from the address in the SAL. */
8717 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8718 gdb::array_view
<const symtab_and_line
> sals
,
8719 event_location_up
&&location
,
8720 gdb::unique_xmalloc_ptr
<char> filter
,
8721 gdb::unique_xmalloc_ptr
<char> cond_string
,
8722 gdb::unique_xmalloc_ptr
<char> extra_string
,
8723 enum bptype type
, enum bpdisp disposition
,
8724 int thread
, int task
, int ignore_count
,
8725 const struct breakpoint_ops
*ops
, int from_tty
,
8726 int enabled
, int internal
, unsigned flags
,
8727 int display_canonical
)
8731 if (type
== bp_hardware_breakpoint
)
8733 int target_resources_ok
;
8735 i
= hw_breakpoint_used_count ();
8736 target_resources_ok
=
8737 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8739 if (target_resources_ok
== 0)
8740 error (_("No hardware breakpoint support in the target."));
8741 else if (target_resources_ok
< 0)
8742 error (_("Hardware breakpoints used exceeds limit."));
8745 gdb_assert (!sals
.empty ());
8747 for (const auto &sal
: sals
)
8749 struct bp_location
*loc
;
8753 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8755 loc_gdbarch
= gdbarch
;
8757 describe_other_breakpoints (loc_gdbarch
,
8758 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8761 if (&sal
== &sals
[0])
8763 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8767 b
->cond_string
= cond_string
.release ();
8768 b
->extra_string
= extra_string
.release ();
8769 b
->ignore_count
= ignore_count
;
8770 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8771 b
->disposition
= disposition
;
8773 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8774 b
->loc
->inserted
= 1;
8776 if (type
== bp_static_tracepoint
)
8778 struct tracepoint
*t
= (struct tracepoint
*) b
;
8779 struct static_tracepoint_marker marker
;
8781 if (strace_marker_p (b
))
8783 /* We already know the marker exists, otherwise, we
8784 wouldn't see a sal for it. */
8786 = &event_location_to_string (b
->location
.get ())[3];
8789 p
= skip_spaces (p
);
8791 endp
= skip_to_space (p
);
8793 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8795 printf_filtered (_("Probed static tracepoint "
8797 t
->static_trace_marker_id
.c_str ());
8799 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8801 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8803 printf_filtered (_("Probed static tracepoint "
8805 t
->static_trace_marker_id
.c_str ());
8808 warning (_("Couldn't determine the static "
8809 "tracepoint marker to probe"));
8816 loc
= add_location_to_breakpoint (b
, &sal
);
8817 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8823 const char *arg
= b
->cond_string
;
8825 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
8826 block_for_pc (loc
->address
), 0);
8828 error (_("Garbage '%s' follows condition"), arg
);
8831 /* Dynamic printf requires and uses additional arguments on the
8832 command line, otherwise it's an error. */
8833 if (type
== bp_dprintf
)
8835 if (b
->extra_string
)
8836 update_dprintf_command_list (b
);
8838 error (_("Format string required"));
8840 else if (b
->extra_string
)
8841 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8844 b
->display_canonical
= display_canonical
;
8845 if (location
!= NULL
)
8846 b
->location
= std::move (location
);
8848 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8849 b
->filter
= std::move (filter
);
8853 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8854 gdb::array_view
<const symtab_and_line
> sals
,
8855 event_location_up
&&location
,
8856 gdb::unique_xmalloc_ptr
<char> filter
,
8857 gdb::unique_xmalloc_ptr
<char> cond_string
,
8858 gdb::unique_xmalloc_ptr
<char> extra_string
,
8859 enum bptype type
, enum bpdisp disposition
,
8860 int thread
, int task
, int ignore_count
,
8861 const struct breakpoint_ops
*ops
, int from_tty
,
8862 int enabled
, int internal
, unsigned flags
,
8863 int display_canonical
)
8865 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8867 init_breakpoint_sal (b
.get (), gdbarch
,
8868 sals
, std::move (location
),
8870 std::move (cond_string
),
8871 std::move (extra_string
),
8873 thread
, task
, ignore_count
,
8875 enabled
, internal
, flags
,
8878 install_breakpoint (internal
, std::move (b
), 0);
8881 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8882 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8883 value. COND_STRING, if not NULL, specified the condition to be
8884 used for all breakpoints. Essentially the only case where
8885 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8886 function. In that case, it's still not possible to specify
8887 separate conditions for different overloaded functions, so
8888 we take just a single condition string.
8890 NOTE: If the function succeeds, the caller is expected to cleanup
8891 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8892 array contents). If the function fails (error() is called), the
8893 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8894 COND and SALS arrays and each of those arrays contents. */
8897 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8898 struct linespec_result
*canonical
,
8899 gdb::unique_xmalloc_ptr
<char> cond_string
,
8900 gdb::unique_xmalloc_ptr
<char> extra_string
,
8901 enum bptype type
, enum bpdisp disposition
,
8902 int thread
, int task
, int ignore_count
,
8903 const struct breakpoint_ops
*ops
, int from_tty
,
8904 int enabled
, int internal
, unsigned flags
)
8906 if (canonical
->pre_expanded
)
8907 gdb_assert (canonical
->lsals
.size () == 1);
8909 for (const auto &lsal
: canonical
->lsals
)
8911 /* Note that 'location' can be NULL in the case of a plain
8912 'break', without arguments. */
8913 event_location_up location
8914 = (canonical
->location
!= NULL
8915 ? copy_event_location (canonical
->location
.get ()) : NULL
);
8916 gdb::unique_xmalloc_ptr
<char> filter_string
8917 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8919 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8920 std::move (location
),
8921 std::move (filter_string
),
8922 std::move (cond_string
),
8923 std::move (extra_string
),
8925 thread
, task
, ignore_count
, ops
,
8926 from_tty
, enabled
, internal
, flags
,
8927 canonical
->special_display
);
8931 /* Parse LOCATION which is assumed to be a SAL specification possibly
8932 followed by conditionals. On return, SALS contains an array of SAL
8933 addresses found. LOCATION points to the end of the SAL (for
8934 linespec locations).
8936 The array and the line spec strings are allocated on the heap, it is
8937 the caller's responsibility to free them. */
8940 parse_breakpoint_sals (const struct event_location
*location
,
8941 struct linespec_result
*canonical
)
8943 struct symtab_and_line cursal
;
8945 if (event_location_type (location
) == LINESPEC_LOCATION
)
8947 const char *spec
= get_linespec_location (location
)->spec_string
;
8951 /* The last displayed codepoint, if it's valid, is our default
8952 breakpoint address. */
8953 if (last_displayed_sal_is_valid ())
8955 /* Set sal's pspace, pc, symtab, and line to the values
8956 corresponding to the last call to print_frame_info.
8957 Be sure to reinitialize LINE with NOTCURRENT == 0
8958 as the breakpoint line number is inappropriate otherwise.
8959 find_pc_line would adjust PC, re-set it back. */
8960 symtab_and_line sal
= get_last_displayed_sal ();
8961 CORE_ADDR pc
= sal
.pc
;
8963 sal
= find_pc_line (pc
, 0);
8965 /* "break" without arguments is equivalent to "break *PC"
8966 where PC is the last displayed codepoint's address. So
8967 make sure to set sal.explicit_pc to prevent GDB from
8968 trying to expand the list of sals to include all other
8969 instances with the same symtab and line. */
8971 sal
.explicit_pc
= 1;
8973 struct linespec_sals lsal
;
8975 lsal
.canonical
= NULL
;
8977 canonical
->lsals
.push_back (std::move (lsal
));
8981 error (_("No default breakpoint address now."));
8985 /* Force almost all breakpoints to be in terms of the
8986 current_source_symtab (which is decode_line_1's default).
8987 This should produce the results we want almost all of the
8988 time while leaving default_breakpoint_* alone.
8990 ObjC: However, don't match an Objective-C method name which
8991 may have a '+' or '-' succeeded by a '['. */
8992 cursal
= get_current_source_symtab_and_line ();
8993 if (last_displayed_sal_is_valid ())
8995 const char *spec
= NULL
;
8997 if (event_location_type (location
) == LINESPEC_LOCATION
)
8998 spec
= get_linespec_location (location
)->spec_string
;
9002 && strchr ("+-", spec
[0]) != NULL
9005 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9006 get_last_displayed_symtab (),
9007 get_last_displayed_line (),
9008 canonical
, NULL
, NULL
);
9013 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9014 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9018 /* Convert each SAL into a real PC. Verify that the PC can be
9019 inserted as a breakpoint. If it can't throw an error. */
9022 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9024 for (auto &sal
: sals
)
9025 resolve_sal_pc (&sal
);
9028 /* Fast tracepoints may have restrictions on valid locations. For
9029 instance, a fast tracepoint using a jump instead of a trap will
9030 likely have to overwrite more bytes than a trap would, and so can
9031 only be placed where the instruction is longer than the jump, or a
9032 multi-instruction sequence does not have a jump into the middle of
9036 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9037 gdb::array_view
<const symtab_and_line
> sals
)
9039 for (const auto &sal
: sals
)
9041 struct gdbarch
*sarch
;
9043 sarch
= get_sal_arch (sal
);
9044 /* We fall back to GDBARCH if there is no architecture
9045 associated with SAL. */
9049 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9050 error (_("May not have a fast tracepoint at %s%s"),
9051 paddress (sarch
, sal
.pc
), msg
.c_str ());
9055 /* Given TOK, a string specification of condition and thread, as
9056 accepted by the 'break' command, extract the condition
9057 string and thread number and set *COND_STRING and *THREAD.
9058 PC identifies the context at which the condition should be parsed.
9059 If no condition is found, *COND_STRING is set to NULL.
9060 If no thread is found, *THREAD is set to -1. */
9063 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9064 char **cond_string
, int *thread
, int *task
,
9067 *cond_string
= NULL
;
9074 const char *end_tok
;
9076 const char *cond_start
= NULL
;
9077 const char *cond_end
= NULL
;
9079 tok
= skip_spaces (tok
);
9081 if ((*tok
== '"' || *tok
== ',') && rest
)
9083 *rest
= savestring (tok
, strlen (tok
));
9087 end_tok
= skip_to_space (tok
);
9089 toklen
= end_tok
- tok
;
9091 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9093 tok
= cond_start
= end_tok
+ 1;
9094 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9096 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9098 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9101 struct thread_info
*thr
;
9104 thr
= parse_thread_id (tok
, &tmptok
);
9106 error (_("Junk after thread keyword."));
9107 *thread
= thr
->global_num
;
9110 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9115 *task
= strtol (tok
, &tmptok
, 0);
9117 error (_("Junk after task keyword."));
9118 if (!valid_task_id (*task
))
9119 error (_("Unknown task %d."), *task
);
9124 *rest
= savestring (tok
, strlen (tok
));
9128 error (_("Junk at end of arguments."));
9132 /* Decode a static tracepoint marker spec. */
9134 static std::vector
<symtab_and_line
>
9135 decode_static_tracepoint_spec (const char **arg_p
)
9137 const char *p
= &(*arg_p
)[3];
9140 p
= skip_spaces (p
);
9142 endp
= skip_to_space (p
);
9144 std::string
marker_str (p
, endp
- p
);
9146 std::vector
<static_tracepoint_marker
> markers
9147 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9148 if (markers
.empty ())
9149 error (_("No known static tracepoint marker named %s"),
9150 marker_str
.c_str ());
9152 std::vector
<symtab_and_line
> sals
;
9153 sals
.reserve (markers
.size ());
9155 for (const static_tracepoint_marker
&marker
: markers
)
9157 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9158 sal
.pc
= marker
.address
;
9159 sals
.push_back (sal
);
9166 /* See breakpoint.h. */
9169 create_breakpoint (struct gdbarch
*gdbarch
,
9170 const struct event_location
*location
,
9171 const char *cond_string
,
9172 int thread
, const char *extra_string
,
9174 int tempflag
, enum bptype type_wanted
,
9176 enum auto_boolean pending_break_support
,
9177 const struct breakpoint_ops
*ops
,
9178 int from_tty
, int enabled
, int internal
,
9181 struct linespec_result canonical
;
9184 int prev_bkpt_count
= breakpoint_count
;
9186 gdb_assert (ops
!= NULL
);
9188 /* If extra_string isn't useful, set it to NULL. */
9189 if (extra_string
!= NULL
&& *extra_string
== '\0')
9190 extra_string
= NULL
;
9194 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9196 catch (const gdb_exception_error
&e
)
9198 /* If caller is interested in rc value from parse, set
9200 if (e
.error
== NOT_FOUND_ERROR
)
9202 /* If pending breakpoint support is turned off, throw
9205 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9208 exception_print (gdb_stderr
, e
);
9210 /* If pending breakpoint support is auto query and the user
9211 selects no, then simply return the error code. */
9212 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9213 && !nquery (_("Make %s pending on future shared library load? "),
9214 bptype_string (type_wanted
)))
9217 /* At this point, either the user was queried about setting
9218 a pending breakpoint and selected yes, or pending
9219 breakpoint behavior is on and thus a pending breakpoint
9220 is defaulted on behalf of the user. */
9227 if (!pending
&& canonical
.lsals
.empty ())
9230 /* Resolve all line numbers to PC's and verify that the addresses
9231 are ok for the target. */
9234 for (auto &lsal
: canonical
.lsals
)
9235 breakpoint_sals_to_pc (lsal
.sals
);
9238 /* Fast tracepoints may have additional restrictions on location. */
9239 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9241 for (const auto &lsal
: canonical
.lsals
)
9242 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9245 /* Verify that condition can be parsed, before setting any
9246 breakpoints. Allocate a separate condition expression for each
9250 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9251 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9258 const linespec_sals
&lsal
= canonical
.lsals
[0];
9260 /* Here we only parse 'arg' to separate condition
9261 from thread number, so parsing in context of first
9262 sal is OK. When setting the breakpoint we'll
9263 re-parse it in context of each sal. */
9265 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9266 &cond
, &thread
, &task
, &rest
);
9267 cond_string_copy
.reset (cond
);
9268 extra_string_copy
.reset (rest
);
9272 if (type_wanted
!= bp_dprintf
9273 && extra_string
!= NULL
&& *extra_string
!= '\0')
9274 error (_("Garbage '%s' at end of location"), extra_string
);
9276 /* Create a private copy of condition string. */
9278 cond_string_copy
.reset (xstrdup (cond_string
));
9279 /* Create a private copy of any extra string. */
9281 extra_string_copy
.reset (xstrdup (extra_string
));
9284 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9285 std::move (cond_string_copy
),
9286 std::move (extra_string_copy
),
9288 tempflag
? disp_del
: disp_donttouch
,
9289 thread
, task
, ignore_count
, ops
,
9290 from_tty
, enabled
, internal
, flags
);
9294 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9296 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9297 b
->location
= copy_event_location (location
);
9300 b
->cond_string
= NULL
;
9303 /* Create a private copy of condition string. */
9304 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9308 /* Create a private copy of any extra string. */
9309 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9310 b
->ignore_count
= ignore_count
;
9311 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9312 b
->condition_not_parsed
= 1;
9313 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9314 if ((type_wanted
!= bp_breakpoint
9315 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9316 b
->pspace
= current_program_space
;
9318 install_breakpoint (internal
, std::move (b
), 0);
9321 if (canonical
.lsals
.size () > 1)
9323 warning (_("Multiple breakpoints were set.\nUse the "
9324 "\"delete\" command to delete unwanted breakpoints."));
9325 prev_breakpoint_count
= prev_bkpt_count
;
9328 update_global_location_list (UGLL_MAY_INSERT
);
9333 /* Set a breakpoint.
9334 ARG is a string describing breakpoint address,
9335 condition, and thread.
9336 FLAG specifies if a breakpoint is hardware on,
9337 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9341 break_command_1 (const char *arg
, int flag
, int from_tty
)
9343 int tempflag
= flag
& BP_TEMPFLAG
;
9344 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9345 ? bp_hardware_breakpoint
9347 struct breakpoint_ops
*ops
;
9349 event_location_up location
= string_to_event_location (&arg
, current_language
);
9351 /* Matching breakpoints on probes. */
9352 if (location
!= NULL
9353 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9354 ops
= &bkpt_probe_breakpoint_ops
;
9356 ops
= &bkpt_breakpoint_ops
;
9358 create_breakpoint (get_current_arch (),
9360 NULL
, 0, arg
, 1 /* parse arg */,
9361 tempflag
, type_wanted
,
9362 0 /* Ignore count */,
9363 pending_break_support
,
9371 /* Helper function for break_command_1 and disassemble_command. */
9374 resolve_sal_pc (struct symtab_and_line
*sal
)
9378 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9380 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9381 error (_("No line %d in file \"%s\"."),
9382 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9385 /* If this SAL corresponds to a breakpoint inserted using a line
9386 number, then skip the function prologue if necessary. */
9387 if (sal
->explicit_line
)
9388 skip_prologue_sal (sal
);
9391 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9393 const struct blockvector
*bv
;
9394 const struct block
*b
;
9397 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9398 SYMTAB_COMPUNIT (sal
->symtab
));
9401 sym
= block_linkage_function (b
);
9404 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9405 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9410 /* It really is worthwhile to have the section, so we'll
9411 just have to look harder. This case can be executed
9412 if we have line numbers but no functions (as can
9413 happen in assembly source). */
9415 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9416 switch_to_program_space_and_thread (sal
->pspace
);
9418 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9420 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9427 break_command (const char *arg
, int from_tty
)
9429 break_command_1 (arg
, 0, from_tty
);
9433 tbreak_command (const char *arg
, int from_tty
)
9435 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9439 hbreak_command (const char *arg
, int from_tty
)
9441 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9445 thbreak_command (const char *arg
, int from_tty
)
9447 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9451 stop_command (const char *arg
, int from_tty
)
9453 printf_filtered (_("Specify the type of breakpoint to set.\n\
9454 Usage: stop in <function | address>\n\
9455 stop at <line>\n"));
9459 stopin_command (const char *arg
, int from_tty
)
9465 else if (*arg
!= '*')
9467 const char *argptr
= arg
;
9470 /* Look for a ':'. If this is a line number specification, then
9471 say it is bad, otherwise, it should be an address or
9472 function/method name. */
9473 while (*argptr
&& !hasColon
)
9475 hasColon
= (*argptr
== ':');
9480 badInput
= (*argptr
!= ':'); /* Not a class::method */
9482 badInput
= isdigit (*arg
); /* a simple line number */
9486 printf_filtered (_("Usage: stop in <function | address>\n"));
9488 break_command_1 (arg
, 0, from_tty
);
9492 stopat_command (const char *arg
, int from_tty
)
9496 if (arg
== NULL
|| *arg
== '*') /* no line number */
9500 const char *argptr
= arg
;
9503 /* Look for a ':'. If there is a '::' then get out, otherwise
9504 it is probably a line number. */
9505 while (*argptr
&& !hasColon
)
9507 hasColon
= (*argptr
== ':');
9512 badInput
= (*argptr
== ':'); /* we have class::method */
9514 badInput
= !isdigit (*arg
); /* not a line number */
9518 printf_filtered (_("Usage: stop at LINE\n"));
9520 break_command_1 (arg
, 0, from_tty
);
9523 /* The dynamic printf command is mostly like a regular breakpoint, but
9524 with a prewired command list consisting of a single output command,
9525 built from extra arguments supplied on the dprintf command
9529 dprintf_command (const char *arg
, int from_tty
)
9531 event_location_up location
= string_to_event_location (&arg
, current_language
);
9533 /* If non-NULL, ARG should have been advanced past the location;
9534 the next character must be ','. */
9537 if (arg
[0] != ',' || arg
[1] == '\0')
9538 error (_("Format string required"));
9541 /* Skip the comma. */
9546 create_breakpoint (get_current_arch (),
9548 NULL
, 0, arg
, 1 /* parse arg */,
9550 0 /* Ignore count */,
9551 pending_break_support
,
9552 &dprintf_breakpoint_ops
,
9560 agent_printf_command (const char *arg
, int from_tty
)
9562 error (_("May only run agent-printf on the target"));
9565 /* Implement the "breakpoint_hit" breakpoint_ops method for
9566 ranged breakpoints. */
9569 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9570 const address_space
*aspace
,
9572 const struct target_waitstatus
*ws
)
9574 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9575 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9578 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9579 bl
->length
, aspace
, bp_addr
);
9582 /* Implement the "resources_needed" breakpoint_ops method for
9583 ranged breakpoints. */
9586 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9588 return target_ranged_break_num_registers ();
9591 /* Implement the "print_it" breakpoint_ops method for
9592 ranged breakpoints. */
9594 static enum print_stop_action
9595 print_it_ranged_breakpoint (bpstat bs
)
9597 struct breakpoint
*b
= bs
->breakpoint_at
;
9598 struct bp_location
*bl
= b
->loc
;
9599 struct ui_out
*uiout
= current_uiout
;
9601 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9603 /* Ranged breakpoints have only one location. */
9604 gdb_assert (bl
&& bl
->next
== NULL
);
9606 annotate_breakpoint (b
->number
);
9608 maybe_print_thread_hit_breakpoint (uiout
);
9610 if (b
->disposition
== disp_del
)
9611 uiout
->text ("Temporary ranged breakpoint ");
9613 uiout
->text ("Ranged breakpoint ");
9614 if (uiout
->is_mi_like_p ())
9616 uiout
->field_string ("reason",
9617 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9618 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9620 uiout
->field_signed ("bkptno", b
->number
);
9623 return PRINT_SRC_AND_LOC
;
9626 /* Implement the "print_one" breakpoint_ops method for
9627 ranged breakpoints. */
9630 print_one_ranged_breakpoint (struct breakpoint
*b
,
9631 struct bp_location
**last_loc
)
9633 struct bp_location
*bl
= b
->loc
;
9634 struct value_print_options opts
;
9635 struct ui_out
*uiout
= current_uiout
;
9637 /* Ranged breakpoints have only one location. */
9638 gdb_assert (bl
&& bl
->next
== NULL
);
9640 get_user_print_options (&opts
);
9642 if (opts
.addressprint
)
9643 /* We don't print the address range here, it will be printed later
9644 by print_one_detail_ranged_breakpoint. */
9645 uiout
->field_skip ("addr");
9647 print_breakpoint_location (b
, bl
);
9651 /* Implement the "print_one_detail" breakpoint_ops method for
9652 ranged breakpoints. */
9655 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9656 struct ui_out
*uiout
)
9658 CORE_ADDR address_start
, address_end
;
9659 struct bp_location
*bl
= b
->loc
;
9664 address_start
= bl
->address
;
9665 address_end
= address_start
+ bl
->length
- 1;
9667 uiout
->text ("\taddress range: ");
9668 stb
.printf ("[%s, %s]",
9669 print_core_address (bl
->gdbarch
, address_start
),
9670 print_core_address (bl
->gdbarch
, address_end
));
9671 uiout
->field_stream ("addr", stb
);
9675 /* Implement the "print_mention" breakpoint_ops method for
9676 ranged breakpoints. */
9679 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9681 struct bp_location
*bl
= b
->loc
;
9682 struct ui_out
*uiout
= current_uiout
;
9685 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9687 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9688 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9689 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9692 /* Implement the "print_recreate" breakpoint_ops method for
9693 ranged breakpoints. */
9696 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9698 fprintf_unfiltered (fp
, "break-range %s, %s",
9699 event_location_to_string (b
->location
.get ()),
9700 event_location_to_string (b
->location_range_end
.get ()));
9701 print_recreate_thread (b
, fp
);
9704 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9706 static struct breakpoint_ops ranged_breakpoint_ops
;
9708 /* Find the address where the end of the breakpoint range should be
9709 placed, given the SAL of the end of the range. This is so that if
9710 the user provides a line number, the end of the range is set to the
9711 last instruction of the given line. */
9714 find_breakpoint_range_end (struct symtab_and_line sal
)
9718 /* If the user provided a PC value, use it. Otherwise,
9719 find the address of the end of the given location. */
9720 if (sal
.explicit_pc
)
9727 ret
= find_line_pc_range (sal
, &start
, &end
);
9729 error (_("Could not find location of the end of the range."));
9731 /* find_line_pc_range returns the start of the next line. */
9738 /* Implement the "break-range" CLI command. */
9741 break_range_command (const char *arg
, int from_tty
)
9743 const char *arg_start
;
9744 struct linespec_result canonical_start
, canonical_end
;
9745 int bp_count
, can_use_bp
, length
;
9747 struct breakpoint
*b
;
9749 /* We don't support software ranged breakpoints. */
9750 if (target_ranged_break_num_registers () < 0)
9751 error (_("This target does not support hardware ranged breakpoints."));
9753 bp_count
= hw_breakpoint_used_count ();
9754 bp_count
+= target_ranged_break_num_registers ();
9755 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9758 error (_("Hardware breakpoints used exceeds limit."));
9760 arg
= skip_spaces (arg
);
9761 if (arg
== NULL
|| arg
[0] == '\0')
9762 error(_("No address range specified."));
9765 event_location_up start_location
= string_to_event_location (&arg
,
9767 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9770 error (_("Too few arguments."));
9771 else if (canonical_start
.lsals
.empty ())
9772 error (_("Could not find location of the beginning of the range."));
9774 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9776 if (canonical_start
.lsals
.size () > 1
9777 || lsal_start
.sals
.size () != 1)
9778 error (_("Cannot create a ranged breakpoint with multiple locations."));
9780 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9781 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9783 arg
++; /* Skip the comma. */
9784 arg
= skip_spaces (arg
);
9786 /* Parse the end location. */
9790 /* We call decode_line_full directly here instead of using
9791 parse_breakpoint_sals because we need to specify the start location's
9792 symtab and line as the default symtab and line for the end of the
9793 range. This makes it possible to have ranges like "foo.c:27, +14",
9794 where +14 means 14 lines from the start location. */
9795 event_location_up end_location
= string_to_event_location (&arg
,
9797 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9798 sal_start
.symtab
, sal_start
.line
,
9799 &canonical_end
, NULL
, NULL
);
9801 if (canonical_end
.lsals
.empty ())
9802 error (_("Could not find location of the end of the range."));
9804 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9805 if (canonical_end
.lsals
.size () > 1
9806 || lsal_end
.sals
.size () != 1)
9807 error (_("Cannot create a ranged breakpoint with multiple locations."));
9809 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9811 end
= find_breakpoint_range_end (sal_end
);
9812 if (sal_start
.pc
> end
)
9813 error (_("Invalid address range, end precedes start."));
9815 length
= end
- sal_start
.pc
+ 1;
9817 /* Length overflowed. */
9818 error (_("Address range too large."));
9819 else if (length
== 1)
9821 /* This range is simple enough to be handled by
9822 the `hbreak' command. */
9823 hbreak_command (&addr_string_start
[0], 1);
9828 /* Now set up the breakpoint. */
9829 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9830 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9831 set_breakpoint_count (breakpoint_count
+ 1);
9832 b
->number
= breakpoint_count
;
9833 b
->disposition
= disp_donttouch
;
9834 b
->location
= std::move (start_location
);
9835 b
->location_range_end
= std::move (end_location
);
9836 b
->loc
->length
= length
;
9839 gdb::observers::breakpoint_created
.notify (b
);
9840 update_global_location_list (UGLL_MAY_INSERT
);
9843 /* Return non-zero if EXP is verified as constant. Returned zero
9844 means EXP is variable. Also the constant detection may fail for
9845 some constant expressions and in such case still falsely return
9849 watchpoint_exp_is_const (const struct expression
*exp
)
9857 /* We are only interested in the descriptor of each element. */
9858 operator_length (exp
, i
, &oplenp
, &argsp
);
9861 switch (exp
->elts
[i
].opcode
)
9871 case BINOP_LOGICAL_AND
:
9872 case BINOP_LOGICAL_OR
:
9873 case BINOP_BITWISE_AND
:
9874 case BINOP_BITWISE_IOR
:
9875 case BINOP_BITWISE_XOR
:
9877 case BINOP_NOTEQUAL
:
9903 case OP_OBJC_NSSTRING
:
9906 case UNOP_LOGICAL_NOT
:
9907 case UNOP_COMPLEMENT
:
9912 case UNOP_CAST_TYPE
:
9913 case UNOP_REINTERPRET_CAST
:
9914 case UNOP_DYNAMIC_CAST
:
9915 /* Unary, binary and ternary operators: We have to check
9916 their operands. If they are constant, then so is the
9917 result of that operation. For instance, if A and B are
9918 determined to be constants, then so is "A + B".
9920 UNOP_IND is one exception to the rule above, because the
9921 value of *ADDR is not necessarily a constant, even when
9926 /* Check whether the associated symbol is a constant.
9928 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9929 possible that a buggy compiler could mark a variable as
9930 constant even when it is not, and TYPE_CONST would return
9931 true in this case, while SYMBOL_CLASS wouldn't.
9933 We also have to check for function symbols because they
9934 are always constant. */
9936 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
9938 if (SYMBOL_CLASS (s
) != LOC_BLOCK
9939 && SYMBOL_CLASS (s
) != LOC_CONST
9940 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
9945 /* The default action is to return 0 because we are using
9946 the optimistic approach here: If we don't know something,
9947 then it is not a constant. */
9956 /* Watchpoint destructor. */
9958 watchpoint::~watchpoint ()
9960 xfree (this->exp_string
);
9961 xfree (this->exp_string_reparse
);
9964 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9967 re_set_watchpoint (struct breakpoint
*b
)
9969 struct watchpoint
*w
= (struct watchpoint
*) b
;
9971 /* Watchpoint can be either on expression using entirely global
9972 variables, or it can be on local variables.
9974 Watchpoints of the first kind are never auto-deleted, and even
9975 persist across program restarts. Since they can use variables
9976 from shared libraries, we need to reparse expression as libraries
9977 are loaded and unloaded.
9979 Watchpoints on local variables can also change meaning as result
9980 of solib event. For example, if a watchpoint uses both a local
9981 and a global variables in expression, it's a local watchpoint,
9982 but unloading of a shared library will make the expression
9983 invalid. This is not a very common use case, but we still
9984 re-evaluate expression, to avoid surprises to the user.
9986 Note that for local watchpoints, we re-evaluate it only if
9987 watchpoints frame id is still valid. If it's not, it means the
9988 watchpoint is out of scope and will be deleted soon. In fact,
9989 I'm not sure we'll ever be called in this case.
9991 If a local watchpoint's frame id is still valid, then
9992 w->exp_valid_block is likewise valid, and we can safely use it.
9994 Don't do anything about disabled watchpoints, since they will be
9995 reevaluated again when enabled. */
9996 update_watchpoint (w
, 1 /* reparse */);
9999 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10002 insert_watchpoint (struct bp_location
*bl
)
10004 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10005 int length
= w
->exact
? 1 : bl
->length
;
10007 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10008 w
->cond_exp
.get ());
10011 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10014 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10016 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10017 int length
= w
->exact
? 1 : bl
->length
;
10019 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10020 w
->cond_exp
.get ());
10024 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10025 const address_space
*aspace
, CORE_ADDR bp_addr
,
10026 const struct target_waitstatus
*ws
)
10028 struct breakpoint
*b
= bl
->owner
;
10029 struct watchpoint
*w
= (struct watchpoint
*) b
;
10031 /* Continuable hardware watchpoints are treated as non-existent if the
10032 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10033 some data address). Otherwise gdb won't stop on a break instruction
10034 in the code (not from a breakpoint) when a hardware watchpoint has
10035 been defined. Also skip watchpoints which we know did not trigger
10036 (did not match the data address). */
10037 if (is_hardware_watchpoint (b
)
10038 && w
->watchpoint_triggered
== watch_triggered_no
)
10045 check_status_watchpoint (bpstat bs
)
10047 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10049 bpstat_check_watchpoint (bs
);
10052 /* Implement the "resources_needed" breakpoint_ops method for
10053 hardware watchpoints. */
10056 resources_needed_watchpoint (const struct bp_location
*bl
)
10058 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10059 int length
= w
->exact
? 1 : bl
->length
;
10061 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10064 /* Implement the "works_in_software_mode" breakpoint_ops method for
10065 hardware watchpoints. */
10068 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10070 /* Read and access watchpoints only work with hardware support. */
10071 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10074 static enum print_stop_action
10075 print_it_watchpoint (bpstat bs
)
10077 struct breakpoint
*b
;
10078 enum print_stop_action result
;
10079 struct watchpoint
*w
;
10080 struct ui_out
*uiout
= current_uiout
;
10082 gdb_assert (bs
->bp_location_at
!= NULL
);
10084 b
= bs
->breakpoint_at
;
10085 w
= (struct watchpoint
*) b
;
10087 annotate_watchpoint (b
->number
);
10088 maybe_print_thread_hit_breakpoint (uiout
);
10092 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10095 case bp_watchpoint
:
10096 case bp_hardware_watchpoint
:
10097 if (uiout
->is_mi_like_p ())
10098 uiout
->field_string
10099 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10101 tuple_emitter
.emplace (uiout
, "value");
10102 uiout
->text ("\nOld value = ");
10103 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10104 uiout
->field_stream ("old", stb
);
10105 uiout
->text ("\nNew value = ");
10106 watchpoint_value_print (w
->val
.get (), &stb
);
10107 uiout
->field_stream ("new", stb
);
10108 uiout
->text ("\n");
10109 /* More than one watchpoint may have been triggered. */
10110 result
= PRINT_UNKNOWN
;
10113 case bp_read_watchpoint
:
10114 if (uiout
->is_mi_like_p ())
10115 uiout
->field_string
10116 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10118 tuple_emitter
.emplace (uiout
, "value");
10119 uiout
->text ("\nValue = ");
10120 watchpoint_value_print (w
->val
.get (), &stb
);
10121 uiout
->field_stream ("value", stb
);
10122 uiout
->text ("\n");
10123 result
= PRINT_UNKNOWN
;
10126 case bp_access_watchpoint
:
10127 if (bs
->old_val
!= NULL
)
10129 if (uiout
->is_mi_like_p ())
10130 uiout
->field_string
10132 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10134 tuple_emitter
.emplace (uiout
, "value");
10135 uiout
->text ("\nOld value = ");
10136 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10137 uiout
->field_stream ("old", stb
);
10138 uiout
->text ("\nNew value = ");
10143 if (uiout
->is_mi_like_p ())
10144 uiout
->field_string
10146 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10147 tuple_emitter
.emplace (uiout
, "value");
10148 uiout
->text ("\nValue = ");
10150 watchpoint_value_print (w
->val
.get (), &stb
);
10151 uiout
->field_stream ("new", stb
);
10152 uiout
->text ("\n");
10153 result
= PRINT_UNKNOWN
;
10156 result
= PRINT_UNKNOWN
;
10162 /* Implement the "print_mention" breakpoint_ops method for hardware
10166 print_mention_watchpoint (struct breakpoint
*b
)
10168 struct watchpoint
*w
= (struct watchpoint
*) b
;
10169 struct ui_out
*uiout
= current_uiout
;
10170 const char *tuple_name
;
10174 case bp_watchpoint
:
10175 uiout
->text ("Watchpoint ");
10176 tuple_name
= "wpt";
10178 case bp_hardware_watchpoint
:
10179 uiout
->text ("Hardware watchpoint ");
10180 tuple_name
= "wpt";
10182 case bp_read_watchpoint
:
10183 uiout
->text ("Hardware read watchpoint ");
10184 tuple_name
= "hw-rwpt";
10186 case bp_access_watchpoint
:
10187 uiout
->text ("Hardware access (read/write) watchpoint ");
10188 tuple_name
= "hw-awpt";
10191 internal_error (__FILE__
, __LINE__
,
10192 _("Invalid hardware watchpoint type."));
10195 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10196 uiout
->field_signed ("number", b
->number
);
10197 uiout
->text (": ");
10198 uiout
->field_string ("exp", w
->exp_string
);
10201 /* Implement the "print_recreate" breakpoint_ops method for
10205 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10207 struct watchpoint
*w
= (struct watchpoint
*) b
;
10211 case bp_watchpoint
:
10212 case bp_hardware_watchpoint
:
10213 fprintf_unfiltered (fp
, "watch");
10215 case bp_read_watchpoint
:
10216 fprintf_unfiltered (fp
, "rwatch");
10218 case bp_access_watchpoint
:
10219 fprintf_unfiltered (fp
, "awatch");
10222 internal_error (__FILE__
, __LINE__
,
10223 _("Invalid watchpoint type."));
10226 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10227 print_recreate_thread (b
, fp
);
10230 /* Implement the "explains_signal" breakpoint_ops method for
10234 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10236 /* A software watchpoint cannot cause a signal other than
10237 GDB_SIGNAL_TRAP. */
10238 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10244 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10246 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10248 /* Implement the "insert" breakpoint_ops method for
10249 masked hardware watchpoints. */
10252 insert_masked_watchpoint (struct bp_location
*bl
)
10254 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10256 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10257 bl
->watchpoint_type
);
10260 /* Implement the "remove" breakpoint_ops method for
10261 masked hardware watchpoints. */
10264 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10266 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10268 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10269 bl
->watchpoint_type
);
10272 /* Implement the "resources_needed" breakpoint_ops method for
10273 masked hardware watchpoints. */
10276 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10278 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10280 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10283 /* Implement the "works_in_software_mode" breakpoint_ops method for
10284 masked hardware watchpoints. */
10287 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10292 /* Implement the "print_it" breakpoint_ops method for
10293 masked hardware watchpoints. */
10295 static enum print_stop_action
10296 print_it_masked_watchpoint (bpstat bs
)
10298 struct breakpoint
*b
= bs
->breakpoint_at
;
10299 struct ui_out
*uiout
= current_uiout
;
10301 /* Masked watchpoints have only one location. */
10302 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10304 annotate_watchpoint (b
->number
);
10305 maybe_print_thread_hit_breakpoint (uiout
);
10309 case bp_hardware_watchpoint
:
10310 if (uiout
->is_mi_like_p ())
10311 uiout
->field_string
10312 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10315 case bp_read_watchpoint
:
10316 if (uiout
->is_mi_like_p ())
10317 uiout
->field_string
10318 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10321 case bp_access_watchpoint
:
10322 if (uiout
->is_mi_like_p ())
10323 uiout
->field_string
10325 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10328 internal_error (__FILE__
, __LINE__
,
10329 _("Invalid hardware watchpoint type."));
10333 uiout
->text (_("\n\
10334 Check the underlying instruction at PC for the memory\n\
10335 address and value which triggered this watchpoint.\n"));
10336 uiout
->text ("\n");
10338 /* More than one watchpoint may have been triggered. */
10339 return PRINT_UNKNOWN
;
10342 /* Implement the "print_one_detail" breakpoint_ops method for
10343 masked hardware watchpoints. */
10346 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10347 struct ui_out
*uiout
)
10349 struct watchpoint
*w
= (struct watchpoint
*) b
;
10351 /* Masked watchpoints have only one location. */
10352 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10354 uiout
->text ("\tmask ");
10355 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10356 uiout
->text ("\n");
10359 /* Implement the "print_mention" breakpoint_ops method for
10360 masked hardware watchpoints. */
10363 print_mention_masked_watchpoint (struct breakpoint
*b
)
10365 struct watchpoint
*w
= (struct watchpoint
*) b
;
10366 struct ui_out
*uiout
= current_uiout
;
10367 const char *tuple_name
;
10371 case bp_hardware_watchpoint
:
10372 uiout
->text ("Masked hardware watchpoint ");
10373 tuple_name
= "wpt";
10375 case bp_read_watchpoint
:
10376 uiout
->text ("Masked hardware read watchpoint ");
10377 tuple_name
= "hw-rwpt";
10379 case bp_access_watchpoint
:
10380 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10381 tuple_name
= "hw-awpt";
10384 internal_error (__FILE__
, __LINE__
,
10385 _("Invalid hardware watchpoint type."));
10388 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10389 uiout
->field_signed ("number", b
->number
);
10390 uiout
->text (": ");
10391 uiout
->field_string ("exp", w
->exp_string
);
10394 /* Implement the "print_recreate" breakpoint_ops method for
10395 masked hardware watchpoints. */
10398 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10400 struct watchpoint
*w
= (struct watchpoint
*) b
;
10405 case bp_hardware_watchpoint
:
10406 fprintf_unfiltered (fp
, "watch");
10408 case bp_read_watchpoint
:
10409 fprintf_unfiltered (fp
, "rwatch");
10411 case bp_access_watchpoint
:
10412 fprintf_unfiltered (fp
, "awatch");
10415 internal_error (__FILE__
, __LINE__
,
10416 _("Invalid hardware watchpoint type."));
10419 sprintf_vma (tmp
, w
->hw_wp_mask
);
10420 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10421 print_recreate_thread (b
, fp
);
10424 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10426 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10428 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10431 is_masked_watchpoint (const struct breakpoint
*b
)
10433 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10436 /* accessflag: hw_write: watch write,
10437 hw_read: watch read,
10438 hw_access: watch access (read or write) */
10440 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10441 int just_location
, int internal
)
10443 struct breakpoint
*scope_breakpoint
= NULL
;
10444 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10445 struct value
*result
;
10446 int saved_bitpos
= 0, saved_bitsize
= 0;
10447 const char *exp_start
= NULL
;
10448 const char *exp_end
= NULL
;
10449 const char *tok
, *end_tok
;
10451 const char *cond_start
= NULL
;
10452 const char *cond_end
= NULL
;
10453 enum bptype bp_type
;
10456 /* Flag to indicate whether we are going to use masks for
10457 the hardware watchpoint. */
10459 CORE_ADDR mask
= 0;
10461 /* Make sure that we actually have parameters to parse. */
10462 if (arg
!= NULL
&& arg
[0] != '\0')
10464 const char *value_start
;
10466 exp_end
= arg
+ strlen (arg
);
10468 /* Look for "parameter value" pairs at the end
10469 of the arguments string. */
10470 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10472 /* Skip whitespace at the end of the argument list. */
10473 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10476 /* Find the beginning of the last token.
10477 This is the value of the parameter. */
10478 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10480 value_start
= tok
+ 1;
10482 /* Skip whitespace. */
10483 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10488 /* Find the beginning of the second to last token.
10489 This is the parameter itself. */
10490 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10493 toklen
= end_tok
- tok
+ 1;
10495 if (toklen
== 6 && startswith (tok
, "thread"))
10497 struct thread_info
*thr
;
10498 /* At this point we've found a "thread" token, which means
10499 the user is trying to set a watchpoint that triggers
10500 only in a specific thread. */
10504 error(_("You can specify only one thread."));
10506 /* Extract the thread ID from the next token. */
10507 thr
= parse_thread_id (value_start
, &endp
);
10509 /* Check if the user provided a valid thread ID. */
10510 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10511 invalid_thread_id_error (value_start
);
10513 thread
= thr
->global_num
;
10515 else if (toklen
== 4 && startswith (tok
, "mask"))
10517 /* We've found a "mask" token, which means the user wants to
10518 create a hardware watchpoint that is going to have the mask
10520 struct value
*mask_value
, *mark
;
10523 error(_("You can specify only one mask."));
10525 use_mask
= just_location
= 1;
10527 mark
= value_mark ();
10528 mask_value
= parse_to_comma_and_eval (&value_start
);
10529 mask
= value_as_address (mask_value
);
10530 value_free_to_mark (mark
);
10533 /* We didn't recognize what we found. We should stop here. */
10536 /* Truncate the string and get rid of the "parameter value" pair before
10537 the arguments string is parsed by the parse_exp_1 function. */
10544 /* Parse the rest of the arguments. From here on out, everything
10545 is in terms of a newly allocated string instead of the original
10547 std::string
expression (arg
, exp_end
- arg
);
10548 exp_start
= arg
= expression
.c_str ();
10549 innermost_block_tracker tracker
;
10550 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10552 /* Remove trailing whitespace from the expression before saving it.
10553 This makes the eventual display of the expression string a bit
10555 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10558 /* Checking if the expression is not constant. */
10559 if (watchpoint_exp_is_const (exp
.get ()))
10563 len
= exp_end
- exp_start
;
10564 while (len
> 0 && isspace (exp_start
[len
- 1]))
10566 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10569 exp_valid_block
= tracker
.block ();
10570 struct value
*mark
= value_mark ();
10571 struct value
*val_as_value
= nullptr;
10572 fetch_subexp_value (exp
.get (), &pc
, &val_as_value
, &result
, NULL
,
10575 if (val_as_value
!= NULL
&& just_location
)
10577 saved_bitpos
= value_bitpos (val_as_value
);
10578 saved_bitsize
= value_bitsize (val_as_value
);
10586 exp_valid_block
= NULL
;
10587 val
= release_value (value_addr (result
));
10588 value_free_to_mark (mark
);
10592 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10595 error (_("This target does not support masked watchpoints."));
10596 else if (ret
== -2)
10597 error (_("Invalid mask or memory region."));
10600 else if (val_as_value
!= NULL
)
10601 val
= release_value (val_as_value
);
10603 tok
= skip_spaces (arg
);
10604 end_tok
= skip_to_space (tok
);
10606 toklen
= end_tok
- tok
;
10607 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10609 tok
= cond_start
= end_tok
+ 1;
10610 innermost_block_tracker if_tracker
;
10611 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10613 /* The watchpoint expression may not be local, but the condition
10614 may still be. E.g.: `watch global if local > 0'. */
10615 cond_exp_valid_block
= if_tracker
.block ();
10620 error (_("Junk at end of command."));
10622 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10624 /* Save this because create_internal_breakpoint below invalidates
10626 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10628 /* If the expression is "local", then set up a "watchpoint scope"
10629 breakpoint at the point where we've left the scope of the watchpoint
10630 expression. Create the scope breakpoint before the watchpoint, so
10631 that we will encounter it first in bpstat_stop_status. */
10632 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10634 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10636 if (frame_id_p (caller_frame_id
))
10638 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10639 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10642 = create_internal_breakpoint (caller_arch
, caller_pc
,
10643 bp_watchpoint_scope
,
10644 &momentary_breakpoint_ops
);
10646 /* create_internal_breakpoint could invalidate WP_FRAME. */
10649 scope_breakpoint
->enable_state
= bp_enabled
;
10651 /* Automatically delete the breakpoint when it hits. */
10652 scope_breakpoint
->disposition
= disp_del
;
10654 /* Only break in the proper frame (help with recursion). */
10655 scope_breakpoint
->frame_id
= caller_frame_id
;
10657 /* Set the address at which we will stop. */
10658 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10659 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10660 scope_breakpoint
->loc
->address
10661 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10662 scope_breakpoint
->loc
->requested_address
,
10663 scope_breakpoint
->type
);
10667 /* Now set up the breakpoint. We create all watchpoints as hardware
10668 watchpoints here even if hardware watchpoints are turned off, a call
10669 to update_watchpoint later in this function will cause the type to
10670 drop back to bp_watchpoint (software watchpoint) if required. */
10672 if (accessflag
== hw_read
)
10673 bp_type
= bp_read_watchpoint
;
10674 else if (accessflag
== hw_access
)
10675 bp_type
= bp_access_watchpoint
;
10677 bp_type
= bp_hardware_watchpoint
;
10679 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10682 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10683 &masked_watchpoint_breakpoint_ops
);
10685 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10686 &watchpoint_breakpoint_ops
);
10687 w
->thread
= thread
;
10688 w
->disposition
= disp_donttouch
;
10689 w
->pspace
= current_program_space
;
10690 w
->exp
= std::move (exp
);
10691 w
->exp_valid_block
= exp_valid_block
;
10692 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10695 struct type
*t
= value_type (val
.get ());
10696 CORE_ADDR addr
= value_as_address (val
.get ());
10698 w
->exp_string_reparse
10699 = current_language
->la_watch_location_expression (t
, addr
).release ();
10701 w
->exp_string
= xstrprintf ("-location %.*s",
10702 (int) (exp_end
- exp_start
), exp_start
);
10705 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10709 w
->hw_wp_mask
= mask
;
10714 w
->val_bitpos
= saved_bitpos
;
10715 w
->val_bitsize
= saved_bitsize
;
10716 w
->val_valid
= true;
10720 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10722 w
->cond_string
= 0;
10724 if (frame_id_p (watchpoint_frame
))
10726 w
->watchpoint_frame
= watchpoint_frame
;
10727 w
->watchpoint_thread
= inferior_ptid
;
10731 w
->watchpoint_frame
= null_frame_id
;
10732 w
->watchpoint_thread
= null_ptid
;
10735 if (scope_breakpoint
!= NULL
)
10737 /* The scope breakpoint is related to the watchpoint. We will
10738 need to act on them together. */
10739 w
->related_breakpoint
= scope_breakpoint
;
10740 scope_breakpoint
->related_breakpoint
= w
.get ();
10743 if (!just_location
)
10744 value_free_to_mark (mark
);
10746 /* Finally update the new watchpoint. This creates the locations
10747 that should be inserted. */
10748 update_watchpoint (w
.get (), 1);
10750 install_breakpoint (internal
, std::move (w
), 1);
10753 /* Return count of debug registers needed to watch the given expression.
10754 If the watchpoint cannot be handled in hardware return zero. */
10757 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10759 int found_memory_cnt
= 0;
10761 /* Did the user specifically forbid us to use hardware watchpoints? */
10762 if (!can_use_hw_watchpoints
)
10765 gdb_assert (!vals
.empty ());
10766 struct value
*head
= vals
[0].get ();
10768 /* Make sure that the value of the expression depends only upon
10769 memory contents, and values computed from them within GDB. If we
10770 find any register references or function calls, we can't use a
10771 hardware watchpoint.
10773 The idea here is that evaluating an expression generates a series
10774 of values, one holding the value of every subexpression. (The
10775 expression a*b+c has five subexpressions: a, b, a*b, c, and
10776 a*b+c.) GDB's values hold almost enough information to establish
10777 the criteria given above --- they identify memory lvalues,
10778 register lvalues, computed values, etcetera. So we can evaluate
10779 the expression, and then scan the chain of values that leaves
10780 behind to decide whether we can detect any possible change to the
10781 expression's final value using only hardware watchpoints.
10783 However, I don't think that the values returned by inferior
10784 function calls are special in any way. So this function may not
10785 notice that an expression involving an inferior function call
10786 can't be watched with hardware watchpoints. FIXME. */
10787 for (const value_ref_ptr
&iter
: vals
)
10789 struct value
*v
= iter
.get ();
10791 if (VALUE_LVAL (v
) == lval_memory
)
10793 if (v
!= head
&& value_lazy (v
))
10794 /* A lazy memory lvalue in the chain is one that GDB never
10795 needed to fetch; we either just used its address (e.g.,
10796 `a' in `a.b') or we never needed it at all (e.g., `a'
10797 in `a,b'). This doesn't apply to HEAD; if that is
10798 lazy then it was not readable, but watch it anyway. */
10802 /* Ahh, memory we actually used! Check if we can cover
10803 it with hardware watchpoints. */
10804 struct type
*vtype
= check_typedef (value_type (v
));
10806 /* We only watch structs and arrays if user asked for it
10807 explicitly, never if they just happen to appear in a
10808 middle of some value chain. */
10810 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
10811 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
10813 CORE_ADDR vaddr
= value_address (v
);
10817 len
= (target_exact_watchpoints
10818 && is_scalar_type_recursive (vtype
))?
10819 1 : TYPE_LENGTH (value_type (v
));
10821 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10825 found_memory_cnt
+= num_regs
;
10829 else if (VALUE_LVAL (v
) != not_lval
10830 && deprecated_value_modifiable (v
) == 0)
10831 return 0; /* These are values from the history (e.g., $1). */
10832 else if (VALUE_LVAL (v
) == lval_register
)
10833 return 0; /* Cannot watch a register with a HW watchpoint. */
10836 /* The expression itself looks suitable for using a hardware
10837 watchpoint, but give the target machine a chance to reject it. */
10838 return found_memory_cnt
;
10842 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10844 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10847 /* A helper function that looks for the "-location" argument and then
10848 calls watch_command_1. */
10851 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10853 int just_location
= 0;
10856 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
10857 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
10860 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
10864 watch_command (const char *arg
, int from_tty
)
10866 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10870 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10872 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10876 rwatch_command (const char *arg
, int from_tty
)
10878 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10882 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10884 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10888 awatch_command (const char *arg
, int from_tty
)
10890 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10894 /* Data for the FSM that manages the until(location)/advance commands
10895 in infcmd.c. Here because it uses the mechanisms of
10898 struct until_break_fsm
: public thread_fsm
10900 /* The thread that was current when the command was executed. */
10903 /* The breakpoint set at the destination location. */
10904 breakpoint_up location_breakpoint
;
10906 /* Breakpoint set at the return address in the caller frame. May be
10908 breakpoint_up caller_breakpoint
;
10910 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10911 breakpoint_up
&&location_breakpoint
,
10912 breakpoint_up
&&caller_breakpoint
)
10913 : thread_fsm (cmd_interp
),
10915 location_breakpoint (std::move (location_breakpoint
)),
10916 caller_breakpoint (std::move (caller_breakpoint
))
10920 void clean_up (struct thread_info
*thread
) override
;
10921 bool should_stop (struct thread_info
*thread
) override
;
10922 enum async_reply_reason
do_async_reply_reason () override
;
10925 /* Implementation of the 'should_stop' FSM method for the
10926 until(location)/advance commands. */
10929 until_break_fsm::should_stop (struct thread_info
*tp
)
10931 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10932 location_breakpoint
.get ()) != NULL
10933 || (caller_breakpoint
!= NULL
10934 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10935 caller_breakpoint
.get ()) != NULL
))
10941 /* Implementation of the 'clean_up' FSM method for the
10942 until(location)/advance commands. */
10945 until_break_fsm::clean_up (struct thread_info
*)
10947 /* Clean up our temporary breakpoints. */
10948 location_breakpoint
.reset ();
10949 caller_breakpoint
.reset ();
10950 delete_longjmp_breakpoint (thread
);
10953 /* Implementation of the 'async_reply_reason' FSM method for the
10954 until(location)/advance commands. */
10956 enum async_reply_reason
10957 until_break_fsm::do_async_reply_reason ()
10959 return EXEC_ASYNC_LOCATION_REACHED
;
10963 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10965 struct frame_info
*frame
;
10966 struct gdbarch
*frame_gdbarch
;
10967 struct frame_id stack_frame_id
;
10968 struct frame_id caller_frame_id
;
10970 struct thread_info
*tp
;
10972 clear_proceed_status (0);
10974 /* Set a breakpoint where the user wants it and at return from
10977 event_location_up location
= string_to_event_location (&arg
, current_language
);
10979 std::vector
<symtab_and_line
> sals
10980 = (last_displayed_sal_is_valid ()
10981 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10982 get_last_displayed_symtab (),
10983 get_last_displayed_line ())
10984 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
10987 if (sals
.size () != 1)
10988 error (_("Couldn't get information on specified line."));
10990 symtab_and_line
&sal
= sals
[0];
10993 error (_("Junk at end of arguments."));
10995 resolve_sal_pc (&sal
);
10997 tp
= inferior_thread ();
10998 thread
= tp
->global_num
;
11000 /* Note linespec handling above invalidates the frame chain.
11001 Installing a breakpoint also invalidates the frame chain (as it
11002 may need to switch threads), so do any frame handling before
11005 frame
= get_selected_frame (NULL
);
11006 frame_gdbarch
= get_frame_arch (frame
);
11007 stack_frame_id
= get_stack_frame_id (frame
);
11008 caller_frame_id
= frame_unwind_caller_id (frame
);
11010 /* Keep within the current frame, or in frames called by the current
11013 breakpoint_up caller_breakpoint
;
11015 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11017 if (frame_id_p (caller_frame_id
))
11019 struct symtab_and_line sal2
;
11020 struct gdbarch
*caller_gdbarch
;
11022 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11023 sal2
.pc
= frame_unwind_caller_pc (frame
);
11024 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11025 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11030 set_longjmp_breakpoint (tp
, caller_frame_id
);
11031 lj_deleter
.emplace (thread
);
11034 /* set_momentary_breakpoint could invalidate FRAME. */
11037 breakpoint_up location_breakpoint
;
11039 /* If the user told us to continue until a specified location,
11040 we don't specify a frame at which we need to stop. */
11041 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11042 null_frame_id
, bp_until
);
11044 /* Otherwise, specify the selected frame, because we want to stop
11045 only at the very same frame. */
11046 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11047 stack_frame_id
, bp_until
);
11049 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11050 std::move (location_breakpoint
),
11051 std::move (caller_breakpoint
));
11054 lj_deleter
->release ();
11056 proceed (-1, GDB_SIGNAL_DEFAULT
);
11059 /* This function attempts to parse an optional "if <cond>" clause
11060 from the arg string. If one is not found, it returns NULL.
11062 Else, it returns a pointer to the condition string. (It does not
11063 attempt to evaluate the string against a particular block.) And,
11064 it updates arg to point to the first character following the parsed
11065 if clause in the arg string. */
11068 ep_parse_optional_if_clause (const char **arg
)
11070 const char *cond_string
;
11072 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11075 /* Skip the "if" keyword. */
11078 /* Skip any extra leading whitespace, and record the start of the
11079 condition string. */
11080 *arg
= skip_spaces (*arg
);
11081 cond_string
= *arg
;
11083 /* Assume that the condition occupies the remainder of the arg
11085 (*arg
) += strlen (cond_string
);
11087 return cond_string
;
11090 /* Commands to deal with catching events, such as signals, exceptions,
11091 process start/exit, etc. */
11095 catch_fork_temporary
, catch_vfork_temporary
,
11096 catch_fork_permanent
, catch_vfork_permanent
11101 catch_fork_command_1 (const char *arg
, int from_tty
,
11102 struct cmd_list_element
*command
)
11104 struct gdbarch
*gdbarch
= get_current_arch ();
11105 const char *cond_string
= NULL
;
11106 catch_fork_kind fork_kind
;
11109 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11110 tempflag
= (fork_kind
== catch_fork_temporary
11111 || fork_kind
== catch_vfork_temporary
);
11115 arg
= skip_spaces (arg
);
11117 /* The allowed syntax is:
11119 catch [v]fork if <cond>
11121 First, check if there's an if clause. */
11122 cond_string
= ep_parse_optional_if_clause (&arg
);
11124 if ((*arg
!= '\0') && !isspace (*arg
))
11125 error (_("Junk at end of arguments."));
11127 /* If this target supports it, create a fork or vfork catchpoint
11128 and enable reporting of such events. */
11131 case catch_fork_temporary
:
11132 case catch_fork_permanent
:
11133 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11134 &catch_fork_breakpoint_ops
);
11136 case catch_vfork_temporary
:
11137 case catch_vfork_permanent
:
11138 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11139 &catch_vfork_breakpoint_ops
);
11142 error (_("unsupported or unknown fork kind; cannot catch it"));
11148 catch_exec_command_1 (const char *arg
, int from_tty
,
11149 struct cmd_list_element
*command
)
11151 struct gdbarch
*gdbarch
= get_current_arch ();
11153 const char *cond_string
= NULL
;
11155 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11159 arg
= skip_spaces (arg
);
11161 /* The allowed syntax is:
11163 catch exec if <cond>
11165 First, check if there's an if clause. */
11166 cond_string
= ep_parse_optional_if_clause (&arg
);
11168 if ((*arg
!= '\0') && !isspace (*arg
))
11169 error (_("Junk at end of arguments."));
11171 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11172 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11173 &catch_exec_breakpoint_ops
);
11174 c
->exec_pathname
= NULL
;
11176 install_breakpoint (0, std::move (c
), 1);
11180 init_ada_exception_breakpoint (struct breakpoint
*b
,
11181 struct gdbarch
*gdbarch
,
11182 struct symtab_and_line sal
,
11183 const char *addr_string
,
11184 const struct breakpoint_ops
*ops
,
11191 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11193 loc_gdbarch
= gdbarch
;
11195 describe_other_breakpoints (loc_gdbarch
,
11196 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11197 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11198 version for exception catchpoints, because two catchpoints
11199 used for different exception names will use the same address.
11200 In this case, a "breakpoint ... also set at..." warning is
11201 unproductive. Besides, the warning phrasing is also a bit
11202 inappropriate, we should use the word catchpoint, and tell
11203 the user what type of catchpoint it is. The above is good
11204 enough for now, though. */
11207 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
11209 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11210 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11211 b
->location
= string_to_event_location (&addr_string
,
11212 language_def (language_ada
));
11213 b
->language
= language_ada
;
11217 catch_command (const char *arg
, int from_tty
)
11219 error (_("Catch requires an event name."));
11224 tcatch_command (const char *arg
, int from_tty
)
11226 error (_("Catch requires an event name."));
11229 /* Compare two breakpoints and return a strcmp-like result. */
11232 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11234 uintptr_t ua
= (uintptr_t) a
;
11235 uintptr_t ub
= (uintptr_t) b
;
11237 if (a
->number
< b
->number
)
11239 else if (a
->number
> b
->number
)
11242 /* Now sort by address, in case we see, e..g, two breakpoints with
11246 return ua
> ub
? 1 : 0;
11249 /* Delete breakpoints by address or line. */
11252 clear_command (const char *arg
, int from_tty
)
11254 struct breakpoint
*b
;
11257 std::vector
<symtab_and_line
> decoded_sals
;
11258 symtab_and_line last_sal
;
11259 gdb::array_view
<symtab_and_line
> sals
;
11263 = decode_line_with_current_source (arg
,
11264 (DECODE_LINE_FUNFIRSTLINE
11265 | DECODE_LINE_LIST_MODE
));
11267 sals
= decoded_sals
;
11271 /* Set sal's line, symtab, pc, and pspace to the values
11272 corresponding to the last call to print_frame_info. If the
11273 codepoint is not valid, this will set all the fields to 0. */
11274 last_sal
= get_last_displayed_sal ();
11275 if (last_sal
.symtab
== 0)
11276 error (_("No source file specified."));
11282 /* We don't call resolve_sal_pc here. That's not as bad as it
11283 seems, because all existing breakpoints typically have both
11284 file/line and pc set. So, if clear is given file/line, we can
11285 match this to existing breakpoint without obtaining pc at all.
11287 We only support clearing given the address explicitly
11288 present in breakpoint table. Say, we've set breakpoint
11289 at file:line. There were several PC values for that file:line,
11290 due to optimization, all in one block.
11292 We've picked one PC value. If "clear" is issued with another
11293 PC corresponding to the same file:line, the breakpoint won't
11294 be cleared. We probably can still clear the breakpoint, but
11295 since the other PC value is never presented to user, user
11296 can only find it by guessing, and it does not seem important
11297 to support that. */
11299 /* For each line spec given, delete bps which correspond to it. Do
11300 it in two passes, solely to preserve the current behavior that
11301 from_tty is forced true if we delete more than one
11304 std::vector
<struct breakpoint
*> found
;
11305 for (const auto &sal
: sals
)
11307 const char *sal_fullname
;
11309 /* If exact pc given, clear bpts at that pc.
11310 If line given (pc == 0), clear all bpts on specified line.
11311 If defaulting, clear all bpts on default line
11314 defaulting sal.pc != 0 tests to do
11319 1 0 <can't happen> */
11321 sal_fullname
= (sal
.symtab
== NULL
11322 ? NULL
: symtab_to_fullname (sal
.symtab
));
11324 /* Find all matching breakpoints and add them to 'found'. */
11325 ALL_BREAKPOINTS (b
)
11328 /* Are we going to delete b? */
11329 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11331 struct bp_location
*loc
= b
->loc
;
11332 for (; loc
; loc
= loc
->next
)
11334 /* If the user specified file:line, don't allow a PC
11335 match. This matches historical gdb behavior. */
11336 int pc_match
= (!sal
.explicit_line
11338 && (loc
->pspace
== sal
.pspace
)
11339 && (loc
->address
== sal
.pc
)
11340 && (!section_is_overlay (loc
->section
)
11341 || loc
->section
== sal
.section
));
11342 int line_match
= 0;
11344 if ((default_match
|| sal
.explicit_line
)
11345 && loc
->symtab
!= NULL
11346 && sal_fullname
!= NULL
11347 && sal
.pspace
== loc
->pspace
11348 && loc
->line_number
== sal
.line
11349 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11350 sal_fullname
) == 0)
11353 if (pc_match
|| line_match
)
11362 found
.push_back (b
);
11366 /* Now go thru the 'found' chain and delete them. */
11367 if (found
.empty ())
11370 error (_("No breakpoint at %s."), arg
);
11372 error (_("No breakpoint at this line."));
11375 /* Remove duplicates from the vec. */
11376 std::sort (found
.begin (), found
.end (),
11377 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11379 return compare_breakpoints (bp_a
, bp_b
) < 0;
11381 found
.erase (std::unique (found
.begin (), found
.end (),
11382 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11384 return compare_breakpoints (bp_a
, bp_b
) == 0;
11388 if (found
.size () > 1)
11389 from_tty
= 1; /* Always report if deleted more than one. */
11392 if (found
.size () == 1)
11393 printf_unfiltered (_("Deleted breakpoint "));
11395 printf_unfiltered (_("Deleted breakpoints "));
11398 for (breakpoint
*iter
: found
)
11401 printf_unfiltered ("%d ", iter
->number
);
11402 delete_breakpoint (iter
);
11405 putchar_unfiltered ('\n');
11408 /* Delete breakpoint in BS if they are `delete' breakpoints and
11409 all breakpoints that are marked for deletion, whether hit or not.
11410 This is called after any breakpoint is hit, or after errors. */
11413 breakpoint_auto_delete (bpstat bs
)
11415 struct breakpoint
*b
, *b_tmp
;
11417 for (; bs
; bs
= bs
->next
)
11418 if (bs
->breakpoint_at
11419 && bs
->breakpoint_at
->disposition
== disp_del
11421 delete_breakpoint (bs
->breakpoint_at
);
11423 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11425 if (b
->disposition
== disp_del_at_next_stop
)
11426 delete_breakpoint (b
);
11430 /* A comparison function for bp_location AP and BP being interfaced to
11431 qsort. Sort elements primarily by their ADDRESS (no matter what
11432 bl_address_is_meaningful says), secondarily by ordering first
11433 permanent elements and terciarily just ensuring the array is sorted
11434 stable way despite qsort being an unstable algorithm. */
11437 bp_locations_compare (const void *ap
, const void *bp
)
11439 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
11440 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
11442 if (a
->address
!= b
->address
)
11443 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11445 /* Sort locations at the same address by their pspace number, keeping
11446 locations of the same inferior (in a multi-inferior environment)
11449 if (a
->pspace
->num
!= b
->pspace
->num
)
11450 return ((a
->pspace
->num
> b
->pspace
->num
)
11451 - (a
->pspace
->num
< b
->pspace
->num
));
11453 /* Sort permanent breakpoints first. */
11454 if (a
->permanent
!= b
->permanent
)
11455 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11457 /* Make the internal GDB representation stable across GDB runs
11458 where A and B memory inside GDB can differ. Breakpoint locations of
11459 the same type at the same address can be sorted in arbitrary order. */
11461 if (a
->owner
->number
!= b
->owner
->number
)
11462 return ((a
->owner
->number
> b
->owner
->number
)
11463 - (a
->owner
->number
< b
->owner
->number
));
11465 return (a
> b
) - (a
< b
);
11468 /* Set bp_locations_placed_address_before_address_max and
11469 bp_locations_shadow_len_after_address_max according to the current
11470 content of the bp_locations array. */
11473 bp_locations_target_extensions_update (void)
11475 struct bp_location
*bl
, **blp_tmp
;
11477 bp_locations_placed_address_before_address_max
= 0;
11478 bp_locations_shadow_len_after_address_max
= 0;
11480 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11482 CORE_ADDR start
, end
, addr
;
11484 if (!bp_location_has_shadow (bl
))
11487 start
= bl
->target_info
.placed_address
;
11488 end
= start
+ bl
->target_info
.shadow_len
;
11490 gdb_assert (bl
->address
>= start
);
11491 addr
= bl
->address
- start
;
11492 if (addr
> bp_locations_placed_address_before_address_max
)
11493 bp_locations_placed_address_before_address_max
= addr
;
11495 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11497 gdb_assert (bl
->address
< end
);
11498 addr
= end
- bl
->address
;
11499 if (addr
> bp_locations_shadow_len_after_address_max
)
11500 bp_locations_shadow_len_after_address_max
= addr
;
11504 /* Download tracepoint locations if they haven't been. */
11507 download_tracepoint_locations (void)
11509 struct breakpoint
*b
;
11510 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11512 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11514 ALL_TRACEPOINTS (b
)
11516 struct bp_location
*bl
;
11517 struct tracepoint
*t
;
11518 int bp_location_downloaded
= 0;
11520 if ((b
->type
== bp_fast_tracepoint
11521 ? !may_insert_fast_tracepoints
11522 : !may_insert_tracepoints
))
11525 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11527 if (target_can_download_tracepoint ())
11528 can_download_tracepoint
= TRIBOOL_TRUE
;
11530 can_download_tracepoint
= TRIBOOL_FALSE
;
11533 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11536 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11538 /* In tracepoint, locations are _never_ duplicated, so
11539 should_be_inserted is equivalent to
11540 unduplicated_should_be_inserted. */
11541 if (!should_be_inserted (bl
) || bl
->inserted
)
11544 switch_to_program_space_and_thread (bl
->pspace
);
11546 target_download_tracepoint (bl
);
11549 bp_location_downloaded
= 1;
11551 t
= (struct tracepoint
*) b
;
11552 t
->number_on_target
= b
->number
;
11553 if (bp_location_downloaded
)
11554 gdb::observers::breakpoint_modified
.notify (b
);
11558 /* Swap the insertion/duplication state between two locations. */
11561 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11563 const int left_inserted
= left
->inserted
;
11564 const int left_duplicate
= left
->duplicate
;
11565 const int left_needs_update
= left
->needs_update
;
11566 const struct bp_target_info left_target_info
= left
->target_info
;
11568 /* Locations of tracepoints can never be duplicated. */
11569 if (is_tracepoint (left
->owner
))
11570 gdb_assert (!left
->duplicate
);
11571 if (is_tracepoint (right
->owner
))
11572 gdb_assert (!right
->duplicate
);
11574 left
->inserted
= right
->inserted
;
11575 left
->duplicate
= right
->duplicate
;
11576 left
->needs_update
= right
->needs_update
;
11577 left
->target_info
= right
->target_info
;
11578 right
->inserted
= left_inserted
;
11579 right
->duplicate
= left_duplicate
;
11580 right
->needs_update
= left_needs_update
;
11581 right
->target_info
= left_target_info
;
11584 /* Force the re-insertion of the locations at ADDRESS. This is called
11585 once a new/deleted/modified duplicate location is found and we are evaluating
11586 conditions on the target's side. Such conditions need to be updated on
11590 force_breakpoint_reinsertion (struct bp_location
*bl
)
11592 struct bp_location
**locp
= NULL
, **loc2p
;
11593 struct bp_location
*loc
;
11594 CORE_ADDR address
= 0;
11597 address
= bl
->address
;
11598 pspace_num
= bl
->pspace
->num
;
11600 /* This is only meaningful if the target is
11601 evaluating conditions and if the user has
11602 opted for condition evaluation on the target's
11604 if (gdb_evaluates_breakpoint_condition_p ()
11605 || !target_supports_evaluation_of_breakpoint_conditions ())
11608 /* Flag all breakpoint locations with this address and
11609 the same program space as the location
11610 as "its condition has changed". We need to
11611 update the conditions on the target's side. */
11612 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11616 if (!is_breakpoint (loc
->owner
)
11617 || pspace_num
!= loc
->pspace
->num
)
11620 /* Flag the location appropriately. We use a different state to
11621 let everyone know that we already updated the set of locations
11622 with addr bl->address and program space bl->pspace. This is so
11623 we don't have to keep calling these functions just to mark locations
11624 that have already been marked. */
11625 loc
->condition_changed
= condition_updated
;
11627 /* Free the agent expression bytecode as well. We will compute
11629 loc
->cond_bytecode
.reset ();
11632 /* Called whether new breakpoints are created, or existing breakpoints
11633 deleted, to update the global location list and recompute which
11634 locations are duplicate of which.
11636 The INSERT_MODE flag determines whether locations may not, may, or
11637 shall be inserted now. See 'enum ugll_insert_mode' for more
11641 update_global_location_list (enum ugll_insert_mode insert_mode
)
11643 struct breakpoint
*b
;
11644 struct bp_location
**locp
, *loc
;
11645 /* Last breakpoint location address that was marked for update. */
11646 CORE_ADDR last_addr
= 0;
11647 /* Last breakpoint location program space that was marked for update. */
11648 int last_pspace_num
= -1;
11650 /* Used in the duplicates detection below. When iterating over all
11651 bp_locations, points to the first bp_location of a given address.
11652 Breakpoints and watchpoints of different types are never
11653 duplicates of each other. Keep one pointer for each type of
11654 breakpoint/watchpoint, so we only need to loop over all locations
11656 struct bp_location
*bp_loc_first
; /* breakpoint */
11657 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11658 struct bp_location
*awp_loc_first
; /* access watchpoint */
11659 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11661 /* Saved former bp_locations array which we compare against the newly
11662 built bp_locations from the current state of ALL_BREAKPOINTS. */
11663 struct bp_location
**old_locp
;
11664 unsigned old_locations_count
;
11665 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11667 old_locations_count
= bp_locations_count
;
11668 bp_locations
= NULL
;
11669 bp_locations_count
= 0;
11671 ALL_BREAKPOINTS (b
)
11672 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11673 bp_locations_count
++;
11675 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11676 locp
= bp_locations
;
11677 ALL_BREAKPOINTS (b
)
11678 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11680 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
11681 bp_locations_compare
);
11683 bp_locations_target_extensions_update ();
11685 /* Identify bp_location instances that are no longer present in the
11686 new list, and therefore should be freed. Note that it's not
11687 necessary that those locations should be removed from inferior --
11688 if there's another location at the same address (previously
11689 marked as duplicate), we don't need to remove/insert the
11692 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11693 and former bp_location array state respectively. */
11695 locp
= bp_locations
;
11696 for (old_locp
= old_locations
.get ();
11697 old_locp
< old_locations
.get () + old_locations_count
;
11700 struct bp_location
*old_loc
= *old_locp
;
11701 struct bp_location
**loc2p
;
11703 /* Tells if 'old_loc' is found among the new locations. If
11704 not, we have to free it. */
11705 int found_object
= 0;
11706 /* Tells if the location should remain inserted in the target. */
11707 int keep_in_target
= 0;
11710 /* Skip LOCP entries which will definitely never be needed.
11711 Stop either at or being the one matching OLD_LOC. */
11712 while (locp
< bp_locations
+ bp_locations_count
11713 && (*locp
)->address
< old_loc
->address
)
11717 (loc2p
< bp_locations
+ bp_locations_count
11718 && (*loc2p
)->address
== old_loc
->address
);
11721 /* Check if this is a new/duplicated location or a duplicated
11722 location that had its condition modified. If so, we want to send
11723 its condition to the target if evaluation of conditions is taking
11725 if ((*loc2p
)->condition_changed
== condition_modified
11726 && (last_addr
!= old_loc
->address
11727 || last_pspace_num
!= old_loc
->pspace
->num
))
11729 force_breakpoint_reinsertion (*loc2p
);
11730 last_pspace_num
= old_loc
->pspace
->num
;
11733 if (*loc2p
== old_loc
)
11737 /* We have already handled this address, update it so that we don't
11738 have to go through updates again. */
11739 last_addr
= old_loc
->address
;
11741 /* Target-side condition evaluation: Handle deleted locations. */
11743 force_breakpoint_reinsertion (old_loc
);
11745 /* If this location is no longer present, and inserted, look if
11746 there's maybe a new location at the same address. If so,
11747 mark that one inserted, and don't remove this one. This is
11748 needed so that we don't have a time window where a breakpoint
11749 at certain location is not inserted. */
11751 if (old_loc
->inserted
)
11753 /* If the location is inserted now, we might have to remove
11756 if (found_object
&& should_be_inserted (old_loc
))
11758 /* The location is still present in the location list,
11759 and still should be inserted. Don't do anything. */
11760 keep_in_target
= 1;
11764 /* This location still exists, but it won't be kept in the
11765 target since it may have been disabled. We proceed to
11766 remove its target-side condition. */
11768 /* The location is either no longer present, or got
11769 disabled. See if there's another location at the
11770 same address, in which case we don't need to remove
11771 this one from the target. */
11773 /* OLD_LOC comes from existing struct breakpoint. */
11774 if (bl_address_is_meaningful (old_loc
))
11777 (loc2p
< bp_locations
+ bp_locations_count
11778 && (*loc2p
)->address
== old_loc
->address
);
11781 struct bp_location
*loc2
= *loc2p
;
11783 if (breakpoint_locations_match (loc2
, old_loc
))
11785 /* Read watchpoint locations are switched to
11786 access watchpoints, if the former are not
11787 supported, but the latter are. */
11788 if (is_hardware_watchpoint (old_loc
->owner
))
11790 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11791 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11794 /* loc2 is a duplicated location. We need to check
11795 if it should be inserted in case it will be
11797 if (loc2
!= old_loc
11798 && unduplicated_should_be_inserted (loc2
))
11800 swap_insertion (old_loc
, loc2
);
11801 keep_in_target
= 1;
11809 if (!keep_in_target
)
11811 if (remove_breakpoint (old_loc
))
11813 /* This is just about all we can do. We could keep
11814 this location on the global list, and try to
11815 remove it next time, but there's no particular
11816 reason why we will succeed next time.
11818 Note that at this point, old_loc->owner is still
11819 valid, as delete_breakpoint frees the breakpoint
11820 only after calling us. */
11821 printf_filtered (_("warning: Error removing "
11822 "breakpoint %d\n"),
11823 old_loc
->owner
->number
);
11831 if (removed
&& target_is_non_stop_p ()
11832 && need_moribund_for_location_type (old_loc
))
11834 /* This location was removed from the target. In
11835 non-stop mode, a race condition is possible where
11836 we've removed a breakpoint, but stop events for that
11837 breakpoint are already queued and will arrive later.
11838 We apply an heuristic to be able to distinguish such
11839 SIGTRAPs from other random SIGTRAPs: we keep this
11840 breakpoint location for a bit, and will retire it
11841 after we see some number of events. The theory here
11842 is that reporting of events should, "on the average",
11843 be fair, so after a while we'll see events from all
11844 threads that have anything of interest, and no longer
11845 need to keep this breakpoint location around. We
11846 don't hold locations forever so to reduce chances of
11847 mistaking a non-breakpoint SIGTRAP for a breakpoint
11850 The heuristic failing can be disastrous on
11851 decr_pc_after_break targets.
11853 On decr_pc_after_break targets, like e.g., x86-linux,
11854 if we fail to recognize a late breakpoint SIGTRAP,
11855 because events_till_retirement has reached 0 too
11856 soon, we'll fail to do the PC adjustment, and report
11857 a random SIGTRAP to the user. When the user resumes
11858 the inferior, it will most likely immediately crash
11859 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11860 corrupted, because of being resumed e.g., in the
11861 middle of a multi-byte instruction, or skipped a
11862 one-byte instruction. This was actually seen happen
11863 on native x86-linux, and should be less rare on
11864 targets that do not support new thread events, like
11865 remote, due to the heuristic depending on
11868 Mistaking a random SIGTRAP for a breakpoint trap
11869 causes similar symptoms (PC adjustment applied when
11870 it shouldn't), but then again, playing with SIGTRAPs
11871 behind the debugger's back is asking for trouble.
11873 Since hardware watchpoint traps are always
11874 distinguishable from other traps, so we don't need to
11875 apply keep hardware watchpoint moribund locations
11876 around. We simply always ignore hardware watchpoint
11877 traps we can no longer explain. */
11879 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
11880 old_loc
->owner
= NULL
;
11882 moribund_locations
.push_back (old_loc
);
11886 old_loc
->owner
= NULL
;
11887 decref_bp_location (&old_loc
);
11892 /* Rescan breakpoints at the same address and section, marking the
11893 first one as "first" and any others as "duplicates". This is so
11894 that the bpt instruction is only inserted once. If we have a
11895 permanent breakpoint at the same place as BPT, make that one the
11896 official one, and the rest as duplicates. Permanent breakpoints
11897 are sorted first for the same address.
11899 Do the same for hardware watchpoints, but also considering the
11900 watchpoint's type (regular/access/read) and length. */
11902 bp_loc_first
= NULL
;
11903 wp_loc_first
= NULL
;
11904 awp_loc_first
= NULL
;
11905 rwp_loc_first
= NULL
;
11906 ALL_BP_LOCATIONS (loc
, locp
)
11908 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11910 struct bp_location
**loc_first_p
;
11913 if (!unduplicated_should_be_inserted (loc
)
11914 || !bl_address_is_meaningful (loc
)
11915 /* Don't detect duplicate for tracepoint locations because they are
11916 never duplicated. See the comments in field `duplicate' of
11917 `struct bp_location'. */
11918 || is_tracepoint (b
))
11920 /* Clear the condition modification flag. */
11921 loc
->condition_changed
= condition_unchanged
;
11925 if (b
->type
== bp_hardware_watchpoint
)
11926 loc_first_p
= &wp_loc_first
;
11927 else if (b
->type
== bp_read_watchpoint
)
11928 loc_first_p
= &rwp_loc_first
;
11929 else if (b
->type
== bp_access_watchpoint
)
11930 loc_first_p
= &awp_loc_first
;
11932 loc_first_p
= &bp_loc_first
;
11934 if (*loc_first_p
== NULL
11935 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11936 || !breakpoint_locations_match (loc
, *loc_first_p
))
11938 *loc_first_p
= loc
;
11939 loc
->duplicate
= 0;
11941 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11943 loc
->needs_update
= 1;
11944 /* Clear the condition modification flag. */
11945 loc
->condition_changed
= condition_unchanged
;
11951 /* This and the above ensure the invariant that the first location
11952 is not duplicated, and is the inserted one.
11953 All following are marked as duplicated, and are not inserted. */
11955 swap_insertion (loc
, *loc_first_p
);
11956 loc
->duplicate
= 1;
11958 /* Clear the condition modification flag. */
11959 loc
->condition_changed
= condition_unchanged
;
11962 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11964 if (insert_mode
!= UGLL_DONT_INSERT
)
11965 insert_breakpoint_locations ();
11968 /* Even though the caller told us to not insert new
11969 locations, we may still need to update conditions on the
11970 target's side of breakpoints that were already inserted
11971 if the target is evaluating breakpoint conditions. We
11972 only update conditions for locations that are marked
11974 update_inserted_breakpoint_locations ();
11978 if (insert_mode
!= UGLL_DONT_INSERT
)
11979 download_tracepoint_locations ();
11983 breakpoint_retire_moribund (void)
11985 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
11987 struct bp_location
*loc
= moribund_locations
[ix
];
11988 if (--(loc
->events_till_retirement
) == 0)
11990 decref_bp_location (&loc
);
11991 unordered_remove (moribund_locations
, ix
);
11998 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12003 update_global_location_list (insert_mode
);
12005 catch (const gdb_exception_error
&e
)
12010 /* Clear BKP from a BPS. */
12013 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12017 for (bs
= bps
; bs
; bs
= bs
->next
)
12018 if (bs
->breakpoint_at
== bpt
)
12020 bs
->breakpoint_at
= NULL
;
12021 bs
->old_val
= NULL
;
12022 /* bs->commands will be freed later. */
12026 /* Callback for iterate_over_threads. */
12028 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12030 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12032 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12036 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12040 say_where (struct breakpoint
*b
)
12042 struct value_print_options opts
;
12044 get_user_print_options (&opts
);
12046 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12048 if (b
->loc
== NULL
)
12050 /* For pending locations, the output differs slightly based
12051 on b->extra_string. If this is non-NULL, it contains either
12052 a condition or dprintf arguments. */
12053 if (b
->extra_string
== NULL
)
12055 printf_filtered (_(" (%s) pending."),
12056 event_location_to_string (b
->location
.get ()));
12058 else if (b
->type
== bp_dprintf
)
12060 printf_filtered (_(" (%s,%s) pending."),
12061 event_location_to_string (b
->location
.get ()),
12066 printf_filtered (_(" (%s %s) pending."),
12067 event_location_to_string (b
->location
.get ()),
12073 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12074 printf_filtered (" at %ps",
12075 styled_string (address_style
.style (),
12076 paddress (b
->loc
->gdbarch
,
12077 b
->loc
->address
)));
12078 if (b
->loc
->symtab
!= NULL
)
12080 /* If there is a single location, we can print the location
12082 if (b
->loc
->next
== NULL
)
12084 const char *filename
12085 = symtab_to_filename_for_display (b
->loc
->symtab
);
12086 printf_filtered (": file %ps, line %d.",
12087 styled_string (file_name_style
.style (),
12089 b
->loc
->line_number
);
12092 /* This is not ideal, but each location may have a
12093 different file name, and this at least reflects the
12094 real situation somewhat. */
12095 printf_filtered (": %s.",
12096 event_location_to_string (b
->location
.get ()));
12101 struct bp_location
*loc
= b
->loc
;
12103 for (; loc
; loc
= loc
->next
)
12105 printf_filtered (" (%d locations)", n
);
12110 bp_location::~bp_location ()
12112 xfree (function_name
);
12115 /* Destructor for the breakpoint base class. */
12117 breakpoint::~breakpoint ()
12119 xfree (this->cond_string
);
12120 xfree (this->extra_string
);
12123 static struct bp_location
*
12124 base_breakpoint_allocate_location (struct breakpoint
*self
)
12126 return new bp_location (self
);
12130 base_breakpoint_re_set (struct breakpoint
*b
)
12132 /* Nothing to re-set. */
12135 #define internal_error_pure_virtual_called() \
12136 gdb_assert_not_reached ("pure virtual function called")
12139 base_breakpoint_insert_location (struct bp_location
*bl
)
12141 internal_error_pure_virtual_called ();
12145 base_breakpoint_remove_location (struct bp_location
*bl
,
12146 enum remove_bp_reason reason
)
12148 internal_error_pure_virtual_called ();
12152 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12153 const address_space
*aspace
,
12155 const struct target_waitstatus
*ws
)
12157 internal_error_pure_virtual_called ();
12161 base_breakpoint_check_status (bpstat bs
)
12166 /* A "works_in_software_mode" breakpoint_ops method that just internal
12170 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12172 internal_error_pure_virtual_called ();
12175 /* A "resources_needed" breakpoint_ops method that just internal
12179 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12181 internal_error_pure_virtual_called ();
12184 static enum print_stop_action
12185 base_breakpoint_print_it (bpstat bs
)
12187 internal_error_pure_virtual_called ();
12191 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12192 struct ui_out
*uiout
)
12198 base_breakpoint_print_mention (struct breakpoint
*b
)
12200 internal_error_pure_virtual_called ();
12204 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12206 internal_error_pure_virtual_called ();
12210 base_breakpoint_create_sals_from_location
12211 (const struct event_location
*location
,
12212 struct linespec_result
*canonical
,
12213 enum bptype type_wanted
)
12215 internal_error_pure_virtual_called ();
12219 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12220 struct linespec_result
*c
,
12221 gdb::unique_xmalloc_ptr
<char> cond_string
,
12222 gdb::unique_xmalloc_ptr
<char> extra_string
,
12223 enum bptype type_wanted
,
12224 enum bpdisp disposition
,
12226 int task
, int ignore_count
,
12227 const struct breakpoint_ops
*o
,
12228 int from_tty
, int enabled
,
12229 int internal
, unsigned flags
)
12231 internal_error_pure_virtual_called ();
12234 static std::vector
<symtab_and_line
>
12235 base_breakpoint_decode_location (struct breakpoint
*b
,
12236 const struct event_location
*location
,
12237 struct program_space
*search_pspace
)
12239 internal_error_pure_virtual_called ();
12242 /* The default 'explains_signal' method. */
12245 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12250 /* The default "after_condition_true" method. */
12253 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12255 /* Nothing to do. */
12258 struct breakpoint_ops base_breakpoint_ops
=
12260 base_breakpoint_allocate_location
,
12261 base_breakpoint_re_set
,
12262 base_breakpoint_insert_location
,
12263 base_breakpoint_remove_location
,
12264 base_breakpoint_breakpoint_hit
,
12265 base_breakpoint_check_status
,
12266 base_breakpoint_resources_needed
,
12267 base_breakpoint_works_in_software_mode
,
12268 base_breakpoint_print_it
,
12270 base_breakpoint_print_one_detail
,
12271 base_breakpoint_print_mention
,
12272 base_breakpoint_print_recreate
,
12273 base_breakpoint_create_sals_from_location
,
12274 base_breakpoint_create_breakpoints_sal
,
12275 base_breakpoint_decode_location
,
12276 base_breakpoint_explains_signal
,
12277 base_breakpoint_after_condition_true
,
12280 /* Default breakpoint_ops methods. */
12283 bkpt_re_set (struct breakpoint
*b
)
12285 /* FIXME: is this still reachable? */
12286 if (breakpoint_event_location_empty_p (b
))
12288 /* Anything without a location can't be re-set. */
12289 delete_breakpoint (b
);
12293 breakpoint_re_set_default (b
);
12297 bkpt_insert_location (struct bp_location
*bl
)
12299 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12301 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12302 bl
->target_info
.placed_address
= addr
;
12304 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12305 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12307 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12311 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12313 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12314 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12316 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12320 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12321 const address_space
*aspace
, CORE_ADDR bp_addr
,
12322 const struct target_waitstatus
*ws
)
12324 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12325 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12328 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12332 if (overlay_debugging
/* unmapped overlay section */
12333 && section_is_overlay (bl
->section
)
12334 && !section_is_mapped (bl
->section
))
12341 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12342 const address_space
*aspace
, CORE_ADDR bp_addr
,
12343 const struct target_waitstatus
*ws
)
12345 if (dprintf_style
== dprintf_style_agent
12346 && target_can_run_breakpoint_commands ())
12348 /* An agent-style dprintf never causes a stop. If we see a trap
12349 for this address it must be for a breakpoint that happens to
12350 be set at the same address. */
12354 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12358 bkpt_resources_needed (const struct bp_location
*bl
)
12360 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12365 static enum print_stop_action
12366 bkpt_print_it (bpstat bs
)
12368 struct breakpoint
*b
;
12369 const struct bp_location
*bl
;
12371 struct ui_out
*uiout
= current_uiout
;
12373 gdb_assert (bs
->bp_location_at
!= NULL
);
12375 bl
= bs
->bp_location_at
;
12376 b
= bs
->breakpoint_at
;
12378 bp_temp
= b
->disposition
== disp_del
;
12379 if (bl
->address
!= bl
->requested_address
)
12380 breakpoint_adjustment_warning (bl
->requested_address
,
12383 annotate_breakpoint (b
->number
);
12384 maybe_print_thread_hit_breakpoint (uiout
);
12386 if (uiout
->is_mi_like_p ())
12388 uiout
->field_string ("reason",
12389 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12390 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12393 uiout
->message ("Temporary breakpoint %pF, ",
12394 signed_field ("bkptno", b
->number
));
12396 uiout
->message ("Breakpoint %pF, ",
12397 signed_field ("bkptno", b
->number
));
12399 return PRINT_SRC_AND_LOC
;
12403 bkpt_print_mention (struct breakpoint
*b
)
12405 if (current_uiout
->is_mi_like_p ())
12410 case bp_breakpoint
:
12411 case bp_gnu_ifunc_resolver
:
12412 if (b
->disposition
== disp_del
)
12413 printf_filtered (_("Temporary breakpoint"));
12415 printf_filtered (_("Breakpoint"));
12416 printf_filtered (_(" %d"), b
->number
);
12417 if (b
->type
== bp_gnu_ifunc_resolver
)
12418 printf_filtered (_(" at gnu-indirect-function resolver"));
12420 case bp_hardware_breakpoint
:
12421 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12424 printf_filtered (_("Dprintf %d"), b
->number
);
12432 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12434 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12435 fprintf_unfiltered (fp
, "tbreak");
12436 else if (tp
->type
== bp_breakpoint
)
12437 fprintf_unfiltered (fp
, "break");
12438 else if (tp
->type
== bp_hardware_breakpoint
12439 && tp
->disposition
== disp_del
)
12440 fprintf_unfiltered (fp
, "thbreak");
12441 else if (tp
->type
== bp_hardware_breakpoint
)
12442 fprintf_unfiltered (fp
, "hbreak");
12444 internal_error (__FILE__
, __LINE__
,
12445 _("unhandled breakpoint type %d"), (int) tp
->type
);
12447 fprintf_unfiltered (fp
, " %s",
12448 event_location_to_string (tp
->location
.get ()));
12450 /* Print out extra_string if this breakpoint is pending. It might
12451 contain, for example, conditions that were set by the user. */
12452 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12453 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12455 print_recreate_thread (tp
, fp
);
12459 bkpt_create_sals_from_location (const struct event_location
*location
,
12460 struct linespec_result
*canonical
,
12461 enum bptype type_wanted
)
12463 create_sals_from_location_default (location
, canonical
, type_wanted
);
12467 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12468 struct linespec_result
*canonical
,
12469 gdb::unique_xmalloc_ptr
<char> cond_string
,
12470 gdb::unique_xmalloc_ptr
<char> extra_string
,
12471 enum bptype type_wanted
,
12472 enum bpdisp disposition
,
12474 int task
, int ignore_count
,
12475 const struct breakpoint_ops
*ops
,
12476 int from_tty
, int enabled
,
12477 int internal
, unsigned flags
)
12479 create_breakpoints_sal_default (gdbarch
, canonical
,
12480 std::move (cond_string
),
12481 std::move (extra_string
),
12483 disposition
, thread
, task
,
12484 ignore_count
, ops
, from_tty
,
12485 enabled
, internal
, flags
);
12488 static std::vector
<symtab_and_line
>
12489 bkpt_decode_location (struct breakpoint
*b
,
12490 const struct event_location
*location
,
12491 struct program_space
*search_pspace
)
12493 return decode_location_default (b
, location
, search_pspace
);
12496 /* Virtual table for internal breakpoints. */
12499 internal_bkpt_re_set (struct breakpoint
*b
)
12503 /* Delete overlay event and longjmp master breakpoints; they
12504 will be reset later by breakpoint_re_set. */
12505 case bp_overlay_event
:
12506 case bp_longjmp_master
:
12507 case bp_std_terminate_master
:
12508 case bp_exception_master
:
12509 delete_breakpoint (b
);
12512 /* This breakpoint is special, it's set up when the inferior
12513 starts and we really don't want to touch it. */
12514 case bp_shlib_event
:
12516 /* Like bp_shlib_event, this breakpoint type is special. Once
12517 it is set up, we do not want to touch it. */
12518 case bp_thread_event
:
12524 internal_bkpt_check_status (bpstat bs
)
12526 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12528 /* If requested, stop when the dynamic linker notifies GDB of
12529 events. This allows the user to get control and place
12530 breakpoints in initializer routines for dynamically loaded
12531 objects (among other things). */
12532 bs
->stop
= stop_on_solib_events
;
12533 bs
->print
= stop_on_solib_events
;
12539 static enum print_stop_action
12540 internal_bkpt_print_it (bpstat bs
)
12542 struct breakpoint
*b
;
12544 b
= bs
->breakpoint_at
;
12548 case bp_shlib_event
:
12549 /* Did we stop because the user set the stop_on_solib_events
12550 variable? (If so, we report this as a generic, "Stopped due
12551 to shlib event" message.) */
12552 print_solib_event (0);
12555 case bp_thread_event
:
12556 /* Not sure how we will get here.
12557 GDB should not stop for these breakpoints. */
12558 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12561 case bp_overlay_event
:
12562 /* By analogy with the thread event, GDB should not stop for these. */
12563 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12566 case bp_longjmp_master
:
12567 /* These should never be enabled. */
12568 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12571 case bp_std_terminate_master
:
12572 /* These should never be enabled. */
12573 printf_filtered (_("std::terminate Master Breakpoint: "
12574 "gdb should not stop!\n"));
12577 case bp_exception_master
:
12578 /* These should never be enabled. */
12579 printf_filtered (_("Exception Master Breakpoint: "
12580 "gdb should not stop!\n"));
12584 return PRINT_NOTHING
;
12588 internal_bkpt_print_mention (struct breakpoint
*b
)
12590 /* Nothing to mention. These breakpoints are internal. */
12593 /* Virtual table for momentary breakpoints */
12596 momentary_bkpt_re_set (struct breakpoint
*b
)
12598 /* Keep temporary breakpoints, which can be encountered when we step
12599 over a dlopen call and solib_add is resetting the breakpoints.
12600 Otherwise these should have been blown away via the cleanup chain
12601 or by breakpoint_init_inferior when we rerun the executable. */
12605 momentary_bkpt_check_status (bpstat bs
)
12607 /* Nothing. The point of these breakpoints is causing a stop. */
12610 static enum print_stop_action
12611 momentary_bkpt_print_it (bpstat bs
)
12613 return PRINT_UNKNOWN
;
12617 momentary_bkpt_print_mention (struct breakpoint
*b
)
12619 /* Nothing to mention. These breakpoints are internal. */
12622 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12624 It gets cleared already on the removal of the first one of such placed
12625 breakpoints. This is OK as they get all removed altogether. */
12627 longjmp_breakpoint::~longjmp_breakpoint ()
12629 thread_info
*tp
= find_thread_global_id (this->thread
);
12632 tp
->initiating_frame
= null_frame_id
;
12635 /* Specific methods for probe breakpoints. */
12638 bkpt_probe_insert_location (struct bp_location
*bl
)
12640 int v
= bkpt_insert_location (bl
);
12644 /* The insertion was successful, now let's set the probe's semaphore
12646 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12653 bkpt_probe_remove_location (struct bp_location
*bl
,
12654 enum remove_bp_reason reason
)
12656 /* Let's clear the semaphore before removing the location. */
12657 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12659 return bkpt_remove_location (bl
, reason
);
12663 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
12664 struct linespec_result
*canonical
,
12665 enum bptype type_wanted
)
12667 struct linespec_sals lsal
;
12669 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12671 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12672 canonical
->lsals
.push_back (std::move (lsal
));
12675 static std::vector
<symtab_and_line
>
12676 bkpt_probe_decode_location (struct breakpoint
*b
,
12677 const struct event_location
*location
,
12678 struct program_space
*search_pspace
)
12680 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12682 error (_("probe not found"));
12686 /* The breakpoint_ops structure to be used in tracepoints. */
12689 tracepoint_re_set (struct breakpoint
*b
)
12691 breakpoint_re_set_default (b
);
12695 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12696 const address_space
*aspace
, CORE_ADDR bp_addr
,
12697 const struct target_waitstatus
*ws
)
12699 /* By definition, the inferior does not report stops at
12705 tracepoint_print_one_detail (const struct breakpoint
*self
,
12706 struct ui_out
*uiout
)
12708 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12709 if (!tp
->static_trace_marker_id
.empty ())
12711 gdb_assert (self
->type
== bp_static_tracepoint
);
12713 uiout
->message ("\tmarker id is %pF\n",
12714 string_field ("static-tracepoint-marker-string-id",
12715 tp
->static_trace_marker_id
.c_str ()));
12720 tracepoint_print_mention (struct breakpoint
*b
)
12722 if (current_uiout
->is_mi_like_p ())
12727 case bp_tracepoint
:
12728 printf_filtered (_("Tracepoint"));
12729 printf_filtered (_(" %d"), b
->number
);
12731 case bp_fast_tracepoint
:
12732 printf_filtered (_("Fast tracepoint"));
12733 printf_filtered (_(" %d"), b
->number
);
12735 case bp_static_tracepoint
:
12736 printf_filtered (_("Static tracepoint"));
12737 printf_filtered (_(" %d"), b
->number
);
12740 internal_error (__FILE__
, __LINE__
,
12741 _("unhandled tracepoint type %d"), (int) b
->type
);
12748 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12750 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12752 if (self
->type
== bp_fast_tracepoint
)
12753 fprintf_unfiltered (fp
, "ftrace");
12754 else if (self
->type
== bp_static_tracepoint
)
12755 fprintf_unfiltered (fp
, "strace");
12756 else if (self
->type
== bp_tracepoint
)
12757 fprintf_unfiltered (fp
, "trace");
12759 internal_error (__FILE__
, __LINE__
,
12760 _("unhandled tracepoint type %d"), (int) self
->type
);
12762 fprintf_unfiltered (fp
, " %s",
12763 event_location_to_string (self
->location
.get ()));
12764 print_recreate_thread (self
, fp
);
12766 if (tp
->pass_count
)
12767 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12771 tracepoint_create_sals_from_location (const struct event_location
*location
,
12772 struct linespec_result
*canonical
,
12773 enum bptype type_wanted
)
12775 create_sals_from_location_default (location
, canonical
, type_wanted
);
12779 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12780 struct linespec_result
*canonical
,
12781 gdb::unique_xmalloc_ptr
<char> cond_string
,
12782 gdb::unique_xmalloc_ptr
<char> extra_string
,
12783 enum bptype type_wanted
,
12784 enum bpdisp disposition
,
12786 int task
, int ignore_count
,
12787 const struct breakpoint_ops
*ops
,
12788 int from_tty
, int enabled
,
12789 int internal
, unsigned flags
)
12791 create_breakpoints_sal_default (gdbarch
, canonical
,
12792 std::move (cond_string
),
12793 std::move (extra_string
),
12795 disposition
, thread
, task
,
12796 ignore_count
, ops
, from_tty
,
12797 enabled
, internal
, flags
);
12800 static std::vector
<symtab_and_line
>
12801 tracepoint_decode_location (struct breakpoint
*b
,
12802 const struct event_location
*location
,
12803 struct program_space
*search_pspace
)
12805 return decode_location_default (b
, location
, search_pspace
);
12808 struct breakpoint_ops tracepoint_breakpoint_ops
;
12810 /* The breakpoint_ops structure to be use on tracepoints placed in a
12814 tracepoint_probe_create_sals_from_location
12815 (const struct event_location
*location
,
12816 struct linespec_result
*canonical
,
12817 enum bptype type_wanted
)
12819 /* We use the same method for breakpoint on probes. */
12820 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
12823 static std::vector
<symtab_and_line
>
12824 tracepoint_probe_decode_location (struct breakpoint
*b
,
12825 const struct event_location
*location
,
12826 struct program_space
*search_pspace
)
12828 /* We use the same method for breakpoint on probes. */
12829 return bkpt_probe_decode_location (b
, location
, search_pspace
);
12832 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
12834 /* Dprintf breakpoint_ops methods. */
12837 dprintf_re_set (struct breakpoint
*b
)
12839 breakpoint_re_set_default (b
);
12841 /* extra_string should never be non-NULL for dprintf. */
12842 gdb_assert (b
->extra_string
!= NULL
);
12844 /* 1 - connect to target 1, that can run breakpoint commands.
12845 2 - create a dprintf, which resolves fine.
12846 3 - disconnect from target 1
12847 4 - connect to target 2, that can NOT run breakpoint commands.
12849 After steps #3/#4, you'll want the dprintf command list to
12850 be updated, because target 1 and 2 may well return different
12851 answers for target_can_run_breakpoint_commands().
12852 Given absence of finer grained resetting, we get to do
12853 it all the time. */
12854 if (b
->extra_string
!= NULL
)
12855 update_dprintf_command_list (b
);
12858 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
12861 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12863 fprintf_unfiltered (fp
, "dprintf %s,%s",
12864 event_location_to_string (tp
->location
.get ()),
12866 print_recreate_thread (tp
, fp
);
12869 /* Implement the "after_condition_true" breakpoint_ops method for
12872 dprintf's are implemented with regular commands in their command
12873 list, but we run the commands here instead of before presenting the
12874 stop to the user, as dprintf's don't actually cause a stop. This
12875 also makes it so that the commands of multiple dprintfs at the same
12876 address are all handled. */
12879 dprintf_after_condition_true (struct bpstats
*bs
)
12881 struct bpstats tmp_bs
;
12882 struct bpstats
*tmp_bs_p
= &tmp_bs
;
12884 /* dprintf's never cause a stop. This wasn't set in the
12885 check_status hook instead because that would make the dprintf's
12886 condition not be evaluated. */
12889 /* Run the command list here. Take ownership of it instead of
12890 copying. We never want these commands to run later in
12891 bpstat_do_actions, if a breakpoint that causes a stop happens to
12892 be set at same address as this dprintf, or even if running the
12893 commands here throws. */
12894 tmp_bs
.commands
= bs
->commands
;
12895 bs
->commands
= NULL
;
12897 bpstat_do_actions_1 (&tmp_bs_p
);
12899 /* 'tmp_bs.commands' will usually be NULL by now, but
12900 bpstat_do_actions_1 may return early without processing the whole
12904 /* The breakpoint_ops structure to be used on static tracepoints with
12908 strace_marker_create_sals_from_location (const struct event_location
*location
,
12909 struct linespec_result
*canonical
,
12910 enum bptype type_wanted
)
12912 struct linespec_sals lsal
;
12913 const char *arg_start
, *arg
;
12915 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
12916 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12918 std::string
str (arg_start
, arg
- arg_start
);
12919 const char *ptr
= str
.c_str ();
12920 canonical
->location
12921 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
12924 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12925 canonical
->lsals
.push_back (std::move (lsal
));
12929 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12930 struct linespec_result
*canonical
,
12931 gdb::unique_xmalloc_ptr
<char> cond_string
,
12932 gdb::unique_xmalloc_ptr
<char> extra_string
,
12933 enum bptype type_wanted
,
12934 enum bpdisp disposition
,
12936 int task
, int ignore_count
,
12937 const struct breakpoint_ops
*ops
,
12938 int from_tty
, int enabled
,
12939 int internal
, unsigned flags
)
12941 const linespec_sals
&lsal
= canonical
->lsals
[0];
12943 /* If the user is creating a static tracepoint by marker id
12944 (strace -m MARKER_ID), then store the sals index, so that
12945 breakpoint_re_set can try to match up which of the newly
12946 found markers corresponds to this one, and, don't try to
12947 expand multiple locations for each sal, given than SALS
12948 already should contain all sals for MARKER_ID. */
12950 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12952 event_location_up location
12953 = copy_event_location (canonical
->location
.get ());
12955 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
12956 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
12957 std::move (location
), NULL
,
12958 std::move (cond_string
),
12959 std::move (extra_string
),
12960 type_wanted
, disposition
,
12961 thread
, task
, ignore_count
, ops
,
12962 from_tty
, enabled
, internal
, flags
,
12963 canonical
->special_display
);
12964 /* Given that its possible to have multiple markers with
12965 the same string id, if the user is creating a static
12966 tracepoint by marker id ("strace -m MARKER_ID"), then
12967 store the sals index, so that breakpoint_re_set can
12968 try to match up which of the newly found markers
12969 corresponds to this one */
12970 tp
->static_trace_marker_id_idx
= i
;
12972 install_breakpoint (internal
, std::move (tp
), 0);
12976 static std::vector
<symtab_and_line
>
12977 strace_marker_decode_location (struct breakpoint
*b
,
12978 const struct event_location
*location
,
12979 struct program_space
*search_pspace
)
12981 struct tracepoint
*tp
= (struct tracepoint
*) b
;
12982 const char *s
= get_linespec_location (location
)->spec_string
;
12984 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
12985 if (sals
.size () > tp
->static_trace_marker_id_idx
)
12987 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
12992 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
12995 static struct breakpoint_ops strace_marker_breakpoint_ops
;
12998 strace_marker_p (struct breakpoint
*b
)
13000 return b
->ops
== &strace_marker_breakpoint_ops
;
13003 /* Delete a breakpoint and clean up all traces of it in the data
13007 delete_breakpoint (struct breakpoint
*bpt
)
13009 struct breakpoint
*b
;
13011 gdb_assert (bpt
!= NULL
);
13013 /* Has this bp already been deleted? This can happen because
13014 multiple lists can hold pointers to bp's. bpstat lists are
13017 One example of this happening is a watchpoint's scope bp. When
13018 the scope bp triggers, we notice that the watchpoint is out of
13019 scope, and delete it. We also delete its scope bp. But the
13020 scope bp is marked "auto-deleting", and is already on a bpstat.
13021 That bpstat is then checked for auto-deleting bp's, which are
13024 A real solution to this problem might involve reference counts in
13025 bp's, and/or giving them pointers back to their referencing
13026 bpstat's, and teaching delete_breakpoint to only free a bp's
13027 storage when no more references were extent. A cheaper bandaid
13029 if (bpt
->type
== bp_none
)
13032 /* At least avoid this stale reference until the reference counting
13033 of breakpoints gets resolved. */
13034 if (bpt
->related_breakpoint
!= bpt
)
13036 struct breakpoint
*related
;
13037 struct watchpoint
*w
;
13039 if (bpt
->type
== bp_watchpoint_scope
)
13040 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13041 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13042 w
= (struct watchpoint
*) bpt
;
13046 watchpoint_del_at_next_stop (w
);
13048 /* Unlink bpt from the bpt->related_breakpoint ring. */
13049 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13050 related
= related
->related_breakpoint
);
13051 related
->related_breakpoint
= bpt
->related_breakpoint
;
13052 bpt
->related_breakpoint
= bpt
;
13055 /* watch_command_1 creates a watchpoint but only sets its number if
13056 update_watchpoint succeeds in creating its bp_locations. If there's
13057 a problem in that process, we'll be asked to delete the half-created
13058 watchpoint. In that case, don't announce the deletion. */
13060 gdb::observers::breakpoint_deleted
.notify (bpt
);
13062 if (breakpoint_chain
== bpt
)
13063 breakpoint_chain
= bpt
->next
;
13065 ALL_BREAKPOINTS (b
)
13066 if (b
->next
== bpt
)
13068 b
->next
= bpt
->next
;
13072 /* Be sure no bpstat's are pointing at the breakpoint after it's
13074 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13075 in all threads for now. Note that we cannot just remove bpstats
13076 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13077 commands are associated with the bpstat; if we remove it here,
13078 then the later call to bpstat_do_actions (&stop_bpstat); in
13079 event-top.c won't do anything, and temporary breakpoints with
13080 commands won't work. */
13082 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13084 /* Now that breakpoint is removed from breakpoint list, update the
13085 global location list. This will remove locations that used to
13086 belong to this breakpoint. Do this before freeing the breakpoint
13087 itself, since remove_breakpoint looks at location's owner. It
13088 might be better design to have location completely
13089 self-contained, but it's not the case now. */
13090 update_global_location_list (UGLL_DONT_INSERT
);
13092 /* On the chance that someone will soon try again to delete this
13093 same bp, we mark it as deleted before freeing its storage. */
13094 bpt
->type
= bp_none
;
13098 /* Iterator function to call a user-provided callback function once
13099 for each of B and its related breakpoints. */
13102 iterate_over_related_breakpoints (struct breakpoint
*b
,
13103 gdb::function_view
<void (breakpoint
*)> function
)
13105 struct breakpoint
*related
;
13110 struct breakpoint
*next
;
13112 /* FUNCTION may delete RELATED. */
13113 next
= related
->related_breakpoint
;
13115 if (next
== related
)
13117 /* RELATED is the last ring entry. */
13118 function (related
);
13120 /* FUNCTION may have deleted it, so we'd never reach back to
13121 B. There's nothing left to do anyway, so just break
13126 function (related
);
13130 while (related
!= b
);
13134 delete_command (const char *arg
, int from_tty
)
13136 struct breakpoint
*b
, *b_tmp
;
13142 int breaks_to_delete
= 0;
13144 /* Delete all breakpoints if no argument. Do not delete
13145 internal breakpoints, these have to be deleted with an
13146 explicit breakpoint number argument. */
13147 ALL_BREAKPOINTS (b
)
13148 if (user_breakpoint_p (b
))
13150 breaks_to_delete
= 1;
13154 /* Ask user only if there are some breakpoints to delete. */
13156 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13158 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13159 if (user_breakpoint_p (b
))
13160 delete_breakpoint (b
);
13164 map_breakpoint_numbers
13165 (arg
, [&] (breakpoint
*br
)
13167 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13171 /* Return true if all locations of B bound to PSPACE are pending. If
13172 PSPACE is NULL, all locations of all program spaces are
13176 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13178 struct bp_location
*loc
;
13180 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13181 if ((pspace
== NULL
13182 || loc
->pspace
== pspace
)
13183 && !loc
->shlib_disabled
13184 && !loc
->pspace
->executing_startup
)
13189 /* Subroutine of update_breakpoint_locations to simplify it.
13190 Return non-zero if multiple fns in list LOC have the same name.
13191 Null names are ignored. */
13194 ambiguous_names_p (struct bp_location
*loc
)
13196 struct bp_location
*l
;
13197 htab_t htab
= htab_create_alloc (13, htab_hash_string
, streq_hash
, NULL
,
13200 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13203 const char *name
= l
->function_name
;
13205 /* Allow for some names to be NULL, ignore them. */
13209 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13211 /* NOTE: We can assume slot != NULL here because xcalloc never
13215 htab_delete (htab
);
13221 htab_delete (htab
);
13225 /* When symbols change, it probably means the sources changed as well,
13226 and it might mean the static tracepoint markers are no longer at
13227 the same address or line numbers they used to be at last we
13228 checked. Losing your static tracepoints whenever you rebuild is
13229 undesirable. This function tries to resync/rematch gdb static
13230 tracepoints with the markers on the target, for static tracepoints
13231 that have not been set by marker id. Static tracepoint that have
13232 been set by marker id are reset by marker id in breakpoint_re_set.
13235 1) For a tracepoint set at a specific address, look for a marker at
13236 the old PC. If one is found there, assume to be the same marker.
13237 If the name / string id of the marker found is different from the
13238 previous known name, assume that means the user renamed the marker
13239 in the sources, and output a warning.
13241 2) For a tracepoint set at a given line number, look for a marker
13242 at the new address of the old line number. If one is found there,
13243 assume to be the same marker. If the name / string id of the
13244 marker found is different from the previous known name, assume that
13245 means the user renamed the marker in the sources, and output a
13248 3) If a marker is no longer found at the same address or line, it
13249 may mean the marker no longer exists. But it may also just mean
13250 the code changed a bit. Maybe the user added a few lines of code
13251 that made the marker move up or down (in line number terms). Ask
13252 the target for info about the marker with the string id as we knew
13253 it. If found, update line number and address in the matching
13254 static tracepoint. This will get confused if there's more than one
13255 marker with the same ID (possible in UST, although unadvised
13256 precisely because it confuses tools). */
13258 static struct symtab_and_line
13259 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13261 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13262 struct static_tracepoint_marker marker
;
13267 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13269 if (target_static_tracepoint_marker_at (pc
, &marker
))
13271 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13272 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13273 b
->number
, tp
->static_trace_marker_id
.c_str (),
13274 marker
.str_id
.c_str ());
13276 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13281 /* Old marker wasn't found on target at lineno. Try looking it up
13283 if (!sal
.explicit_pc
13285 && sal
.symtab
!= NULL
13286 && !tp
->static_trace_marker_id
.empty ())
13288 std::vector
<static_tracepoint_marker
> markers
13289 = target_static_tracepoint_markers_by_strid
13290 (tp
->static_trace_marker_id
.c_str ());
13292 if (!markers
.empty ())
13294 struct symbol
*sym
;
13295 struct static_tracepoint_marker
*tpmarker
;
13296 struct ui_out
*uiout
= current_uiout
;
13297 struct explicit_location explicit_loc
;
13299 tpmarker
= &markers
[0];
13301 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13303 warning (_("marker for static tracepoint %d (%s) not "
13304 "found at previous line number"),
13305 b
->number
, tp
->static_trace_marker_id
.c_str ());
13307 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13308 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13309 uiout
->text ("Now in ");
13312 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
),
13313 function_name_style
.style ());
13314 uiout
->text (" at ");
13316 uiout
->field_string ("file",
13317 symtab_to_filename_for_display (sal2
.symtab
),
13318 file_name_style
.style ());
13321 if (uiout
->is_mi_like_p ())
13323 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13325 uiout
->field_string ("fullname", fullname
);
13328 uiout
->field_signed ("line", sal2
.line
);
13329 uiout
->text ("\n");
13331 b
->loc
->line_number
= sal2
.line
;
13332 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13334 b
->location
.reset (NULL
);
13335 initialize_explicit_location (&explicit_loc
);
13336 explicit_loc
.source_filename
13337 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13338 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13339 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13340 b
->location
= new_explicit_location (&explicit_loc
);
13342 /* Might be nice to check if function changed, and warn if
13349 /* Returns 1 iff locations A and B are sufficiently same that
13350 we don't need to report breakpoint as changed. */
13353 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13357 if (a
->address
!= b
->address
)
13360 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13363 if (a
->enabled
!= b
->enabled
)
13370 if ((a
== NULL
) != (b
== NULL
))
13376 /* Split all locations of B that are bound to PSPACE out of B's
13377 location list to a separate list and return that list's head. If
13378 PSPACE is NULL, hoist out all locations of B. */
13380 static struct bp_location
*
13381 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13383 struct bp_location head
;
13384 struct bp_location
*i
= b
->loc
;
13385 struct bp_location
**i_link
= &b
->loc
;
13386 struct bp_location
*hoisted
= &head
;
13388 if (pspace
== NULL
)
13399 if (i
->pspace
== pspace
)
13414 /* Create new breakpoint locations for B (a hardware or software
13415 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13416 zero, then B is a ranged breakpoint. Only recreates locations for
13417 FILTER_PSPACE. Locations of other program spaces are left
13421 update_breakpoint_locations (struct breakpoint
*b
,
13422 struct program_space
*filter_pspace
,
13423 gdb::array_view
<const symtab_and_line
> sals
,
13424 gdb::array_view
<const symtab_and_line
> sals_end
)
13426 struct bp_location
*existing_locations
;
13428 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13430 /* Ranged breakpoints have only one start location and one end
13432 b
->enable_state
= bp_disabled
;
13433 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13434 "multiple locations found\n"),
13439 /* If there's no new locations, and all existing locations are
13440 pending, don't do anything. This optimizes the common case where
13441 all locations are in the same shared library, that was unloaded.
13442 We'd like to retain the location, so that when the library is
13443 loaded again, we don't loose the enabled/disabled status of the
13444 individual locations. */
13445 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13448 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13450 for (const auto &sal
: sals
)
13452 struct bp_location
*new_loc
;
13454 switch_to_program_space_and_thread (sal
.pspace
);
13456 new_loc
= add_location_to_breakpoint (b
, &sal
);
13458 /* Reparse conditions, they might contain references to the
13460 if (b
->cond_string
!= NULL
)
13464 s
= b
->cond_string
;
13467 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13468 block_for_pc (sal
.pc
),
13471 catch (const gdb_exception_error
&e
)
13473 warning (_("failed to reevaluate condition "
13474 "for breakpoint %d: %s"),
13475 b
->number
, e
.what ());
13476 new_loc
->enabled
= 0;
13480 if (!sals_end
.empty ())
13482 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13484 new_loc
->length
= end
- sals
[0].pc
+ 1;
13488 /* If possible, carry over 'disable' status from existing
13491 struct bp_location
*e
= existing_locations
;
13492 /* If there are multiple breakpoints with the same function name,
13493 e.g. for inline functions, comparing function names won't work.
13494 Instead compare pc addresses; this is just a heuristic as things
13495 may have moved, but in practice it gives the correct answer
13496 often enough until a better solution is found. */
13497 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13499 for (; e
; e
= e
->next
)
13501 if (!e
->enabled
&& e
->function_name
)
13503 struct bp_location
*l
= b
->loc
;
13504 if (have_ambiguous_names
)
13506 for (; l
; l
= l
->next
)
13507 if (breakpoint_locations_match (e
, l
))
13515 for (; l
; l
= l
->next
)
13516 if (l
->function_name
13517 && strcmp (e
->function_name
, l
->function_name
) == 0)
13527 if (!locations_are_equal (existing_locations
, b
->loc
))
13528 gdb::observers::breakpoint_modified
.notify (b
);
13531 /* Find the SaL locations corresponding to the given LOCATION.
13532 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13534 static std::vector
<symtab_and_line
>
13535 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13536 struct program_space
*search_pspace
, int *found
)
13538 struct gdb_exception exception
;
13540 gdb_assert (b
->ops
!= NULL
);
13542 std::vector
<symtab_and_line
> sals
;
13546 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13548 catch (gdb_exception_error
&e
)
13550 int not_found_and_ok
= 0;
13552 /* For pending breakpoints, it's expected that parsing will
13553 fail until the right shared library is loaded. User has
13554 already told to create pending breakpoints and don't need
13555 extra messages. If breakpoint is in bp_shlib_disabled
13556 state, then user already saw the message about that
13557 breakpoint being disabled, and don't want to see more
13559 if (e
.error
== NOT_FOUND_ERROR
13560 && (b
->condition_not_parsed
13562 && search_pspace
!= NULL
13563 && b
->loc
->pspace
!= search_pspace
)
13564 || (b
->loc
&& b
->loc
->shlib_disabled
)
13565 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13566 || b
->enable_state
== bp_disabled
))
13567 not_found_and_ok
= 1;
13569 if (!not_found_and_ok
)
13571 /* We surely don't want to warn about the same breakpoint
13572 10 times. One solution, implemented here, is disable
13573 the breakpoint on error. Another solution would be to
13574 have separate 'warning emitted' flag. Since this
13575 happens only when a binary has changed, I don't know
13576 which approach is better. */
13577 b
->enable_state
= bp_disabled
;
13581 exception
= std::move (e
);
13584 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13586 for (auto &sal
: sals
)
13587 resolve_sal_pc (&sal
);
13588 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13590 char *cond_string
, *extra_string
;
13593 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
13594 &cond_string
, &thread
, &task
,
13596 gdb_assert (b
->cond_string
== NULL
);
13598 b
->cond_string
= cond_string
;
13599 b
->thread
= thread
;
13603 xfree (b
->extra_string
);
13604 b
->extra_string
= extra_string
;
13606 b
->condition_not_parsed
= 0;
13609 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13610 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13620 /* The default re_set method, for typical hardware or software
13621 breakpoints. Reevaluate the breakpoint and recreate its
13625 breakpoint_re_set_default (struct breakpoint
*b
)
13627 struct program_space
*filter_pspace
= current_program_space
;
13628 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13631 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13632 filter_pspace
, &found
);
13634 expanded
= std::move (sals
);
13636 if (b
->location_range_end
!= NULL
)
13638 std::vector
<symtab_and_line
> sals_end
13639 = location_to_sals (b
, b
->location_range_end
.get (),
13640 filter_pspace
, &found
);
13642 expanded_end
= std::move (sals_end
);
13645 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13648 /* Default method for creating SALs from an address string. It basically
13649 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13652 create_sals_from_location_default (const struct event_location
*location
,
13653 struct linespec_result
*canonical
,
13654 enum bptype type_wanted
)
13656 parse_breakpoint_sals (location
, canonical
);
13659 /* Call create_breakpoints_sal for the given arguments. This is the default
13660 function for the `create_breakpoints_sal' method of
13664 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13665 struct linespec_result
*canonical
,
13666 gdb::unique_xmalloc_ptr
<char> cond_string
,
13667 gdb::unique_xmalloc_ptr
<char> extra_string
,
13668 enum bptype type_wanted
,
13669 enum bpdisp disposition
,
13671 int task
, int ignore_count
,
13672 const struct breakpoint_ops
*ops
,
13673 int from_tty
, int enabled
,
13674 int internal
, unsigned flags
)
13676 create_breakpoints_sal (gdbarch
, canonical
,
13677 std::move (cond_string
),
13678 std::move (extra_string
),
13679 type_wanted
, disposition
,
13680 thread
, task
, ignore_count
, ops
, from_tty
,
13681 enabled
, internal
, flags
);
13684 /* Decode the line represented by S by calling decode_line_full. This is the
13685 default function for the `decode_location' method of breakpoint_ops. */
13687 static std::vector
<symtab_and_line
>
13688 decode_location_default (struct breakpoint
*b
,
13689 const struct event_location
*location
,
13690 struct program_space
*search_pspace
)
13692 struct linespec_result canonical
;
13694 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13695 NULL
, 0, &canonical
, multiple_symbols_all
,
13698 /* We should get 0 or 1 resulting SALs. */
13699 gdb_assert (canonical
.lsals
.size () < 2);
13701 if (!canonical
.lsals
.empty ())
13703 const linespec_sals
&lsal
= canonical
.lsals
[0];
13704 return std::move (lsal
.sals
);
13709 /* Reset a breakpoint. */
13712 breakpoint_re_set_one (breakpoint
*b
)
13714 input_radix
= b
->input_radix
;
13715 set_language (b
->language
);
13717 b
->ops
->re_set (b
);
13720 /* Re-set breakpoint locations for the current program space.
13721 Locations bound to other program spaces are left untouched. */
13724 breakpoint_re_set (void)
13726 struct breakpoint
*b
, *b_tmp
;
13729 scoped_restore_current_language save_language
;
13730 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13731 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13733 /* breakpoint_re_set_one sets the current_language to the language
13734 of the breakpoint it is resetting (see prepare_re_set_context)
13735 before re-evaluating the breakpoint's location. This change can
13736 unfortunately get undone by accident if the language_mode is set
13737 to auto, and we either switch frames, or more likely in this context,
13738 we select the current frame.
13740 We prevent this by temporarily turning the language_mode to
13741 language_mode_manual. We restore it once all breakpoints
13742 have been reset. */
13743 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13744 language_mode
= language_mode_manual
;
13746 /* Note: we must not try to insert locations until after all
13747 breakpoints have been re-set. Otherwise, e.g., when re-setting
13748 breakpoint 1, we'd insert the locations of breakpoint 2, which
13749 hadn't been re-set yet, and thus may have stale locations. */
13751 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13755 breakpoint_re_set_one (b
);
13757 catch (const gdb_exception
&ex
)
13759 exception_fprintf (gdb_stderr
, ex
,
13760 "Error in re-setting breakpoint %d: ",
13765 jit_breakpoint_re_set ();
13768 create_overlay_event_breakpoint ();
13769 create_longjmp_master_breakpoint ();
13770 create_std_terminate_master_breakpoint ();
13771 create_exception_master_breakpoint ();
13773 /* Now we can insert. */
13774 update_global_location_list (UGLL_MAY_INSERT
);
13777 /* Reset the thread number of this breakpoint:
13779 - If the breakpoint is for all threads, leave it as-is.
13780 - Else, reset it to the current thread for inferior_ptid. */
13782 breakpoint_re_set_thread (struct breakpoint
*b
)
13784 if (b
->thread
!= -1)
13786 b
->thread
= inferior_thread ()->global_num
;
13788 /* We're being called after following a fork. The new fork is
13789 selected as current, and unless this was a vfork will have a
13790 different program space from the original thread. Reset that
13792 b
->loc
->pspace
= current_program_space
;
13796 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13797 If from_tty is nonzero, it prints a message to that effect,
13798 which ends with a period (no newline). */
13801 set_ignore_count (int bptnum
, int count
, int from_tty
)
13803 struct breakpoint
*b
;
13808 ALL_BREAKPOINTS (b
)
13809 if (b
->number
== bptnum
)
13811 if (is_tracepoint (b
))
13813 if (from_tty
&& count
!= 0)
13814 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13819 b
->ignore_count
= count
;
13823 printf_filtered (_("Will stop next time "
13824 "breakpoint %d is reached."),
13826 else if (count
== 1)
13827 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13830 printf_filtered (_("Will ignore next %d "
13831 "crossings of breakpoint %d."),
13834 gdb::observers::breakpoint_modified
.notify (b
);
13838 error (_("No breakpoint number %d."), bptnum
);
13841 /* Command to set ignore-count of breakpoint N to COUNT. */
13844 ignore_command (const char *args
, int from_tty
)
13846 const char *p
= args
;
13850 error_no_arg (_("a breakpoint number"));
13852 num
= get_number (&p
);
13854 error (_("bad breakpoint number: '%s'"), args
);
13856 error (_("Second argument (specified ignore-count) is missing."));
13858 set_ignore_count (num
,
13859 longest_to_int (value_as_long (parse_and_eval (p
))),
13862 printf_filtered ("\n");
13866 /* Call FUNCTION on each of the breakpoints with numbers in the range
13867 defined by BP_NUM_RANGE (an inclusive range). */
13870 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13871 gdb::function_view
<void (breakpoint
*)> function
)
13873 if (bp_num_range
.first
== 0)
13875 warning (_("bad breakpoint number at or near '%d'"),
13876 bp_num_range
.first
);
13880 struct breakpoint
*b
, *tmp
;
13882 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13884 bool match
= false;
13886 ALL_BREAKPOINTS_SAFE (b
, tmp
)
13887 if (b
->number
== i
)
13894 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
13899 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13903 map_breakpoint_numbers (const char *args
,
13904 gdb::function_view
<void (breakpoint
*)> function
)
13906 if (args
== NULL
|| *args
== '\0')
13907 error_no_arg (_("one or more breakpoint numbers"));
13909 number_or_range_parser
parser (args
);
13911 while (!parser
.finished ())
13913 int num
= parser
.get_number ();
13914 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13918 /* Return the breakpoint location structure corresponding to the
13919 BP_NUM and LOC_NUM values. */
13921 static struct bp_location
*
13922 find_location_by_number (int bp_num
, int loc_num
)
13924 struct breakpoint
*b
;
13926 ALL_BREAKPOINTS (b
)
13927 if (b
->number
== bp_num
)
13932 if (!b
|| b
->number
!= bp_num
)
13933 error (_("Bad breakpoint number '%d'"), bp_num
);
13936 error (_("Bad breakpoint location number '%d'"), loc_num
);
13939 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13940 if (++n
== loc_num
)
13943 error (_("Bad breakpoint location number '%d'"), loc_num
);
13946 /* Modes of operation for extract_bp_num. */
13947 enum class extract_bp_kind
13949 /* Extracting a breakpoint number. */
13952 /* Extracting a location number. */
13956 /* Extract a breakpoint or location number (as determined by KIND)
13957 from the string starting at START. TRAILER is a character which
13958 can be found after the number. If you don't want a trailer, use
13959 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13960 string. This always returns a positive integer. */
13963 extract_bp_num (extract_bp_kind kind
, const char *start
,
13964 int trailer
, const char **end_out
= NULL
)
13966 const char *end
= start
;
13967 int num
= get_number_trailer (&end
, trailer
);
13969 error (kind
== extract_bp_kind::bp
13970 ? _("Negative breakpoint number '%.*s'")
13971 : _("Negative breakpoint location number '%.*s'"),
13972 int (end
- start
), start
);
13974 error (kind
== extract_bp_kind::bp
13975 ? _("Bad breakpoint number '%.*s'")
13976 : _("Bad breakpoint location number '%.*s'"),
13977 int (end
- start
), start
);
13979 if (end_out
!= NULL
)
13984 /* Extract a breakpoint or location range (as determined by KIND) in
13985 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
13986 representing the (inclusive) range. The returned pair's elements
13987 are always positive integers. */
13989 static std::pair
<int, int>
13990 extract_bp_or_bp_range (extract_bp_kind kind
,
13991 const std::string
&arg
,
13992 std::string::size_type arg_offset
)
13994 std::pair
<int, int> range
;
13995 const char *bp_loc
= &arg
[arg_offset
];
13996 std::string::size_type dash
= arg
.find ('-', arg_offset
);
13997 if (dash
!= std::string::npos
)
13999 /* bp_loc is a range (x-z). */
14000 if (arg
.length () == dash
+ 1)
14001 error (kind
== extract_bp_kind::bp
14002 ? _("Bad breakpoint number at or near: '%s'")
14003 : _("Bad breakpoint location number at or near: '%s'"),
14007 const char *start_first
= bp_loc
;
14008 const char *start_second
= &arg
[dash
+ 1];
14009 range
.first
= extract_bp_num (kind
, start_first
, '-');
14010 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14012 if (range
.first
> range
.second
)
14013 error (kind
== extract_bp_kind::bp
14014 ? _("Inverted breakpoint range at '%.*s'")
14015 : _("Inverted breakpoint location range at '%.*s'"),
14016 int (end
- start_first
), start_first
);
14020 /* bp_loc is a single value. */
14021 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14022 range
.second
= range
.first
;
14027 /* Extract the breakpoint/location range specified by ARG. Returns
14028 the breakpoint range in BP_NUM_RANGE, and the location range in
14031 ARG may be in any of the following forms:
14033 x where 'x' is a breakpoint number.
14034 x-y where 'x' and 'y' specify a breakpoint numbers range.
14035 x.y where 'x' is a breakpoint number and 'y' a location number.
14036 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14037 location number range.
14041 extract_bp_number_and_location (const std::string
&arg
,
14042 std::pair
<int, int> &bp_num_range
,
14043 std::pair
<int, int> &bp_loc_range
)
14045 std::string::size_type dot
= arg
.find ('.');
14047 if (dot
!= std::string::npos
)
14049 /* Handle 'x.y' and 'x.y-z' cases. */
14051 if (arg
.length () == dot
+ 1 || dot
== 0)
14052 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14055 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14056 bp_num_range
.second
= bp_num_range
.first
;
14058 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14063 /* Handle x and x-y cases. */
14065 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14066 bp_loc_range
.first
= 0;
14067 bp_loc_range
.second
= 0;
14071 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14072 specifies whether to enable or disable. */
14075 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14077 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14080 if (loc
->enabled
!= enable
)
14082 loc
->enabled
= enable
;
14083 mark_breakpoint_location_modified (loc
);
14085 if (target_supports_enable_disable_tracepoint ()
14086 && current_trace_status ()->running
&& loc
->owner
14087 && is_tracepoint (loc
->owner
))
14088 target_disable_tracepoint (loc
);
14090 update_global_location_list (UGLL_DONT_INSERT
);
14092 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14095 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14096 number of the breakpoint, and BP_LOC_RANGE specifies the
14097 (inclusive) range of location numbers of that breakpoint to
14098 enable/disable. ENABLE specifies whether to enable or disable the
14102 enable_disable_breakpoint_location_range (int bp_num
,
14103 std::pair
<int, int> &bp_loc_range
,
14106 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14107 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14110 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14111 If from_tty is nonzero, it prints a message to that effect,
14112 which ends with a period (no newline). */
14115 disable_breakpoint (struct breakpoint
*bpt
)
14117 /* Never disable a watchpoint scope breakpoint; we want to
14118 hit them when we leave scope so we can delete both the
14119 watchpoint and its scope breakpoint at that time. */
14120 if (bpt
->type
== bp_watchpoint_scope
)
14123 bpt
->enable_state
= bp_disabled
;
14125 /* Mark breakpoint locations modified. */
14126 mark_breakpoint_modified (bpt
);
14128 if (target_supports_enable_disable_tracepoint ()
14129 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14131 struct bp_location
*location
;
14133 for (location
= bpt
->loc
; location
; location
= location
->next
)
14134 target_disable_tracepoint (location
);
14137 update_global_location_list (UGLL_DONT_INSERT
);
14139 gdb::observers::breakpoint_modified
.notify (bpt
);
14142 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14143 specified in ARGS. ARGS may be in any of the formats handled by
14144 extract_bp_number_and_location. ENABLE specifies whether to enable
14145 or disable the breakpoints/locations. */
14148 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14152 struct breakpoint
*bpt
;
14154 ALL_BREAKPOINTS (bpt
)
14155 if (user_breakpoint_p (bpt
))
14158 enable_breakpoint (bpt
);
14160 disable_breakpoint (bpt
);
14165 std::string num
= extract_arg (&args
);
14167 while (!num
.empty ())
14169 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14171 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14173 if (bp_loc_range
.first
== bp_loc_range
.second
14174 && bp_loc_range
.first
== 0)
14176 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14177 map_breakpoint_number_range (bp_num_range
,
14179 ? enable_breakpoint
14180 : disable_breakpoint
);
14184 /* Handle breakpoint ids with formats 'x.y' or
14186 enable_disable_breakpoint_location_range
14187 (bp_num_range
.first
, bp_loc_range
, enable
);
14189 num
= extract_arg (&args
);
14194 /* The disable command disables the specified breakpoints/locations
14195 (or all defined breakpoints) so they're no longer effective in
14196 stopping the inferior. ARGS may be in any of the forms defined in
14197 extract_bp_number_and_location. */
14200 disable_command (const char *args
, int from_tty
)
14202 enable_disable_command (args
, from_tty
, false);
14206 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14209 int target_resources_ok
;
14211 if (bpt
->type
== bp_hardware_breakpoint
)
14214 i
= hw_breakpoint_used_count ();
14215 target_resources_ok
=
14216 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14218 if (target_resources_ok
== 0)
14219 error (_("No hardware breakpoint support in the target."));
14220 else if (target_resources_ok
< 0)
14221 error (_("Hardware breakpoints used exceeds limit."));
14224 if (is_watchpoint (bpt
))
14226 /* Initialize it just to avoid a GCC false warning. */
14227 enum enable_state orig_enable_state
= bp_disabled
;
14231 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14233 orig_enable_state
= bpt
->enable_state
;
14234 bpt
->enable_state
= bp_enabled
;
14235 update_watchpoint (w
, 1 /* reparse */);
14237 catch (const gdb_exception
&e
)
14239 bpt
->enable_state
= orig_enable_state
;
14240 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14246 bpt
->enable_state
= bp_enabled
;
14248 /* Mark breakpoint locations modified. */
14249 mark_breakpoint_modified (bpt
);
14251 if (target_supports_enable_disable_tracepoint ()
14252 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14254 struct bp_location
*location
;
14256 for (location
= bpt
->loc
; location
; location
= location
->next
)
14257 target_enable_tracepoint (location
);
14260 bpt
->disposition
= disposition
;
14261 bpt
->enable_count
= count
;
14262 update_global_location_list (UGLL_MAY_INSERT
);
14264 gdb::observers::breakpoint_modified
.notify (bpt
);
14269 enable_breakpoint (struct breakpoint
*bpt
)
14271 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14274 /* The enable command enables the specified breakpoints/locations (or
14275 all defined breakpoints) so they once again become (or continue to
14276 be) effective in stopping the inferior. ARGS may be in any of the
14277 forms defined in extract_bp_number_and_location. */
14280 enable_command (const char *args
, int from_tty
)
14282 enable_disable_command (args
, from_tty
, true);
14286 enable_once_command (const char *args
, int from_tty
)
14288 map_breakpoint_numbers
14289 (args
, [&] (breakpoint
*b
)
14291 iterate_over_related_breakpoints
14292 (b
, [&] (breakpoint
*bpt
)
14294 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14300 enable_count_command (const char *args
, int from_tty
)
14305 error_no_arg (_("hit count"));
14307 count
= get_number (&args
);
14309 map_breakpoint_numbers
14310 (args
, [&] (breakpoint
*b
)
14312 iterate_over_related_breakpoints
14313 (b
, [&] (breakpoint
*bpt
)
14315 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14321 enable_delete_command (const char *args
, int from_tty
)
14323 map_breakpoint_numbers
14324 (args
, [&] (breakpoint
*b
)
14326 iterate_over_related_breakpoints
14327 (b
, [&] (breakpoint
*bpt
)
14329 enable_breakpoint_disp (bpt
, disp_del
, 1);
14335 set_breakpoint_cmd (const char *args
, int from_tty
)
14340 show_breakpoint_cmd (const char *args
, int from_tty
)
14344 /* Invalidate last known value of any hardware watchpoint if
14345 the memory which that value represents has been written to by
14349 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14350 CORE_ADDR addr
, ssize_t len
,
14351 const bfd_byte
*data
)
14353 struct breakpoint
*bp
;
14355 ALL_BREAKPOINTS (bp
)
14356 if (bp
->enable_state
== bp_enabled
14357 && bp
->type
== bp_hardware_watchpoint
)
14359 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14361 if (wp
->val_valid
&& wp
->val
!= nullptr)
14363 struct bp_location
*loc
;
14365 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14366 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14367 && loc
->address
+ loc
->length
> addr
14368 && addr
+ len
> loc
->address
)
14371 wp
->val_valid
= false;
14377 /* Create and insert a breakpoint for software single step. */
14380 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14381 const address_space
*aspace
,
14384 struct thread_info
*tp
= inferior_thread ();
14385 struct symtab_and_line sal
;
14386 CORE_ADDR pc
= next_pc
;
14388 if (tp
->control
.single_step_breakpoints
== NULL
)
14390 tp
->control
.single_step_breakpoints
14391 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14394 sal
= find_pc_line (pc
, 0);
14396 sal
.section
= find_pc_overlay (pc
);
14397 sal
.explicit_pc
= 1;
14398 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14400 update_global_location_list (UGLL_INSERT
);
14403 /* Insert single step breakpoints according to the current state. */
14406 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14408 struct regcache
*regcache
= get_current_regcache ();
14409 std::vector
<CORE_ADDR
> next_pcs
;
14411 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14413 if (!next_pcs
.empty ())
14415 struct frame_info
*frame
= get_current_frame ();
14416 const address_space
*aspace
= get_frame_address_space (frame
);
14418 for (CORE_ADDR pc
: next_pcs
)
14419 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14427 /* See breakpoint.h. */
14430 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14431 const address_space
*aspace
,
14434 struct bp_location
*loc
;
14436 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14438 && breakpoint_location_address_match (loc
, aspace
, pc
))
14444 /* Check whether a software single-step breakpoint is inserted at
14448 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14451 struct breakpoint
*bpt
;
14453 ALL_BREAKPOINTS (bpt
)
14455 if (bpt
->type
== bp_single_step
14456 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14462 /* Tracepoint-specific operations. */
14464 /* Set tracepoint count to NUM. */
14466 set_tracepoint_count (int num
)
14468 tracepoint_count
= num
;
14469 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14473 trace_command (const char *arg
, int from_tty
)
14475 struct breakpoint_ops
*ops
;
14477 event_location_up location
= string_to_event_location (&arg
,
14479 if (location
!= NULL
14480 && event_location_type (location
.get ()) == PROBE_LOCATION
)
14481 ops
= &tracepoint_probe_breakpoint_ops
;
14483 ops
= &tracepoint_breakpoint_ops
;
14485 create_breakpoint (get_current_arch (),
14487 NULL
, 0, arg
, 1 /* parse arg */,
14489 bp_tracepoint
/* type_wanted */,
14490 0 /* Ignore count */,
14491 pending_break_support
,
14495 0 /* internal */, 0);
14499 ftrace_command (const char *arg
, int from_tty
)
14501 event_location_up location
= string_to_event_location (&arg
,
14503 create_breakpoint (get_current_arch (),
14505 NULL
, 0, arg
, 1 /* parse arg */,
14507 bp_fast_tracepoint
/* type_wanted */,
14508 0 /* Ignore count */,
14509 pending_break_support
,
14510 &tracepoint_breakpoint_ops
,
14513 0 /* internal */, 0);
14516 /* strace command implementation. Creates a static tracepoint. */
14519 strace_command (const char *arg
, int from_tty
)
14521 struct breakpoint_ops
*ops
;
14522 event_location_up location
;
14524 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14525 or with a normal static tracepoint. */
14526 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14528 ops
= &strace_marker_breakpoint_ops
;
14529 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14533 ops
= &tracepoint_breakpoint_ops
;
14534 location
= string_to_event_location (&arg
, current_language
);
14537 create_breakpoint (get_current_arch (),
14539 NULL
, 0, arg
, 1 /* parse arg */,
14541 bp_static_tracepoint
/* type_wanted */,
14542 0 /* Ignore count */,
14543 pending_break_support
,
14547 0 /* internal */, 0);
14550 /* Set up a fake reader function that gets command lines from a linked
14551 list that was acquired during tracepoint uploading. */
14553 static struct uploaded_tp
*this_utp
;
14554 static int next_cmd
;
14557 read_uploaded_action (void)
14559 char *rslt
= nullptr;
14561 if (next_cmd
< this_utp
->cmd_strings
.size ())
14563 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14570 /* Given information about a tracepoint as recorded on a target (which
14571 can be either a live system or a trace file), attempt to create an
14572 equivalent GDB tracepoint. This is not a reliable process, since
14573 the target does not necessarily have all the information used when
14574 the tracepoint was originally defined. */
14576 struct tracepoint
*
14577 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14579 const char *addr_str
;
14580 char small_buf
[100];
14581 struct tracepoint
*tp
;
14583 if (utp
->at_string
)
14584 addr_str
= utp
->at_string
.get ();
14587 /* In the absence of a source location, fall back to raw
14588 address. Since there is no way to confirm that the address
14589 means the same thing as when the trace was started, warn the
14591 warning (_("Uploaded tracepoint %d has no "
14592 "source location, using raw address"),
14594 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14595 addr_str
= small_buf
;
14598 /* There's not much we can do with a sequence of bytecodes. */
14599 if (utp
->cond
&& !utp
->cond_string
)
14600 warning (_("Uploaded tracepoint %d condition "
14601 "has no source form, ignoring it"),
14604 event_location_up location
= string_to_event_location (&addr_str
,
14606 if (!create_breakpoint (get_current_arch (),
14608 utp
->cond_string
.get (), -1, addr_str
,
14609 0 /* parse cond/thread */,
14611 utp
->type
/* type_wanted */,
14612 0 /* Ignore count */,
14613 pending_break_support
,
14614 &tracepoint_breakpoint_ops
,
14616 utp
->enabled
/* enabled */,
14618 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14621 /* Get the tracepoint we just created. */
14622 tp
= get_tracepoint (tracepoint_count
);
14623 gdb_assert (tp
!= NULL
);
14627 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14630 trace_pass_command (small_buf
, 0);
14633 /* If we have uploaded versions of the original commands, set up a
14634 special-purpose "reader" function and call the usual command line
14635 reader, then pass the result to the breakpoint command-setting
14637 if (!utp
->cmd_strings
.empty ())
14639 counted_command_line cmd_list
;
14644 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14646 breakpoint_set_commands (tp
, std::move (cmd_list
));
14648 else if (!utp
->actions
.empty ()
14649 || !utp
->step_actions
.empty ())
14650 warning (_("Uploaded tracepoint %d actions "
14651 "have no source form, ignoring them"),
14654 /* Copy any status information that might be available. */
14655 tp
->hit_count
= utp
->hit_count
;
14656 tp
->traceframe_usage
= utp
->traceframe_usage
;
14661 /* Print information on tracepoint number TPNUM_EXP, or all if
14665 info_tracepoints_command (const char *args
, int from_tty
)
14667 struct ui_out
*uiout
= current_uiout
;
14670 num_printed
= breakpoint_1 (args
, false, is_tracepoint
);
14672 if (num_printed
== 0)
14674 if (args
== NULL
|| *args
== '\0')
14675 uiout
->message ("No tracepoints.\n");
14677 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14680 default_collect_info ();
14683 /* The 'enable trace' command enables tracepoints.
14684 Not supported by all targets. */
14686 enable_trace_command (const char *args
, int from_tty
)
14688 enable_command (args
, from_tty
);
14691 /* The 'disable trace' command disables tracepoints.
14692 Not supported by all targets. */
14694 disable_trace_command (const char *args
, int from_tty
)
14696 disable_command (args
, from_tty
);
14699 /* Remove a tracepoint (or all if no argument). */
14701 delete_trace_command (const char *arg
, int from_tty
)
14703 struct breakpoint
*b
, *b_tmp
;
14709 int breaks_to_delete
= 0;
14711 /* Delete all breakpoints if no argument.
14712 Do not delete internal or call-dummy breakpoints, these
14713 have to be deleted with an explicit breakpoint number
14715 ALL_TRACEPOINTS (b
)
14716 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14718 breaks_to_delete
= 1;
14722 /* Ask user only if there are some breakpoints to delete. */
14724 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14726 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14727 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14728 delete_breakpoint (b
);
14732 map_breakpoint_numbers
14733 (arg
, [&] (breakpoint
*br
)
14735 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14739 /* Helper function for trace_pass_command. */
14742 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14744 tp
->pass_count
= count
;
14745 gdb::observers::breakpoint_modified
.notify (tp
);
14747 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14748 tp
->number
, count
);
14751 /* Set passcount for tracepoint.
14753 First command argument is passcount, second is tracepoint number.
14754 If tracepoint number omitted, apply to most recently defined.
14755 Also accepts special argument "all". */
14758 trace_pass_command (const char *args
, int from_tty
)
14760 struct tracepoint
*t1
;
14763 if (args
== 0 || *args
== 0)
14764 error (_("passcount command requires an "
14765 "argument (count + optional TP num)"));
14767 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14769 args
= skip_spaces (args
);
14770 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14772 struct breakpoint
*b
;
14774 args
+= 3; /* Skip special argument "all". */
14776 error (_("Junk at end of arguments."));
14778 ALL_TRACEPOINTS (b
)
14780 t1
= (struct tracepoint
*) b
;
14781 trace_pass_set_count (t1
, count
, from_tty
);
14784 else if (*args
== '\0')
14786 t1
= get_tracepoint_by_number (&args
, NULL
);
14788 trace_pass_set_count (t1
, count
, from_tty
);
14792 number_or_range_parser
parser (args
);
14793 while (!parser
.finished ())
14795 t1
= get_tracepoint_by_number (&args
, &parser
);
14797 trace_pass_set_count (t1
, count
, from_tty
);
14802 struct tracepoint
*
14803 get_tracepoint (int num
)
14805 struct breakpoint
*t
;
14807 ALL_TRACEPOINTS (t
)
14808 if (t
->number
== num
)
14809 return (struct tracepoint
*) t
;
14814 /* Find the tracepoint with the given target-side number (which may be
14815 different from the tracepoint number after disconnecting and
14818 struct tracepoint
*
14819 get_tracepoint_by_number_on_target (int num
)
14821 struct breakpoint
*b
;
14823 ALL_TRACEPOINTS (b
)
14825 struct tracepoint
*t
= (struct tracepoint
*) b
;
14827 if (t
->number_on_target
== num
)
14834 /* Utility: parse a tracepoint number and look it up in the list.
14835 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14836 If the argument is missing, the most recent tracepoint
14837 (tracepoint_count) is returned. */
14839 struct tracepoint
*
14840 get_tracepoint_by_number (const char **arg
,
14841 number_or_range_parser
*parser
)
14843 struct breakpoint
*t
;
14845 const char *instring
= arg
== NULL
? NULL
: *arg
;
14847 if (parser
!= NULL
)
14849 gdb_assert (!parser
->finished ());
14850 tpnum
= parser
->get_number ();
14852 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14853 tpnum
= tracepoint_count
;
14855 tpnum
= get_number (arg
);
14859 if (instring
&& *instring
)
14860 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14863 printf_filtered (_("No previous tracepoint\n"));
14867 ALL_TRACEPOINTS (t
)
14868 if (t
->number
== tpnum
)
14870 return (struct tracepoint
*) t
;
14873 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
14878 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14880 if (b
->thread
!= -1)
14881 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
14884 fprintf_unfiltered (fp
, " task %d", b
->task
);
14886 fprintf_unfiltered (fp
, "\n");
14889 /* Save information on user settable breakpoints (watchpoints, etc) to
14890 a new script file named FILENAME. If FILTER is non-NULL, call it
14891 on each breakpoint and only include the ones for which it returns
14895 save_breakpoints (const char *filename
, int from_tty
,
14896 bool (*filter
) (const struct breakpoint
*))
14898 struct breakpoint
*tp
;
14900 int extra_trace_bits
= 0;
14902 if (filename
== 0 || *filename
== 0)
14903 error (_("Argument required (file name in which to save)"));
14905 /* See if we have anything to save. */
14906 ALL_BREAKPOINTS (tp
)
14908 /* Skip internal and momentary breakpoints. */
14909 if (!user_breakpoint_p (tp
))
14912 /* If we have a filter, only save the breakpoints it accepts. */
14913 if (filter
&& !filter (tp
))
14918 if (is_tracepoint (tp
))
14920 extra_trace_bits
= 1;
14922 /* We can stop searching. */
14929 warning (_("Nothing to save."));
14933 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14937 if (!fp
.open (expanded_filename
.get (), "w"))
14938 error (_("Unable to open file '%s' for saving (%s)"),
14939 expanded_filename
.get (), safe_strerror (errno
));
14941 if (extra_trace_bits
)
14942 save_trace_state_variables (&fp
);
14944 ALL_BREAKPOINTS (tp
)
14946 /* Skip internal and momentary breakpoints. */
14947 if (!user_breakpoint_p (tp
))
14950 /* If we have a filter, only save the breakpoints it accepts. */
14951 if (filter
&& !filter (tp
))
14954 tp
->ops
->print_recreate (tp
, &fp
);
14956 /* Note, we can't rely on tp->number for anything, as we can't
14957 assume the recreated breakpoint numbers will match. Use $bpnum
14960 if (tp
->cond_string
)
14961 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
14963 if (tp
->ignore_count
)
14964 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14966 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
14968 fp
.puts (" commands\n");
14970 current_uiout
->redirect (&fp
);
14973 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
14975 catch (const gdb_exception
&ex
)
14977 current_uiout
->redirect (NULL
);
14981 current_uiout
->redirect (NULL
);
14982 fp
.puts (" end\n");
14985 if (tp
->enable_state
== bp_disabled
)
14986 fp
.puts ("disable $bpnum\n");
14988 /* If this is a multi-location breakpoint, check if the locations
14989 should be individually disabled. Watchpoint locations are
14990 special, and not user visible. */
14991 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
14993 struct bp_location
*loc
;
14996 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
14998 fp
.printf ("disable $bpnum.%d\n", n
);
15002 if (extra_trace_bits
&& *default_collect
)
15003 fp
.printf ("set default-collect %s\n", default_collect
);
15006 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15009 /* The `save breakpoints' command. */
15012 save_breakpoints_command (const char *args
, int from_tty
)
15014 save_breakpoints (args
, from_tty
, NULL
);
15017 /* The `save tracepoints' command. */
15020 save_tracepoints_command (const char *args
, int from_tty
)
15022 save_breakpoints (args
, from_tty
, is_tracepoint
);
15025 /* Create a vector of all tracepoints. */
15027 std::vector
<breakpoint
*>
15028 all_tracepoints (void)
15030 std::vector
<breakpoint
*> tp_vec
;
15031 struct breakpoint
*tp
;
15033 ALL_TRACEPOINTS (tp
)
15035 tp_vec
.push_back (tp
);
15042 /* This help string is used to consolidate all the help string for specifying
15043 locations used by several commands. */
15045 #define LOCATION_HELP_STRING \
15046 "Linespecs are colon-separated lists of location parameters, such as\n\
15047 source filename, function name, label name, and line number.\n\
15048 Example: To specify the start of a label named \"the_top\" in the\n\
15049 function \"fact\" in the file \"factorial.c\", use\n\
15050 \"factorial.c:fact:the_top\".\n\
15052 Address locations begin with \"*\" and specify an exact address in the\n\
15053 program. Example: To specify the fourth byte past the start function\n\
15054 \"main\", use \"*main + 4\".\n\
15056 Explicit locations are similar to linespecs but use an option/argument\n\
15057 syntax to specify location parameters.\n\
15058 Example: To specify the start of the label named \"the_top\" in the\n\
15059 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15060 -function fact -label the_top\".\n\
15062 By default, a specified function is matched against the program's\n\
15063 functions in all scopes. For C++, this means in all namespaces and\n\
15064 classes. For Ada, this means in all packages. E.g., in C++,\n\
15065 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15066 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15067 specified name as a complete fully-qualified name instead."
15069 /* This help string is used for the break, hbreak, tbreak and thbreak
15070 commands. It is defined as a macro to prevent duplication.
15071 COMMAND should be a string constant containing the name of the
15074 #define BREAK_ARGS_HELP(command) \
15075 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15076 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15077 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15078 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15079 `-probe-dtrace' (for a DTrace probe).\n\
15080 LOCATION may be a linespec, address, or explicit location as described\n\
15083 With no LOCATION, uses current execution address of the selected\n\
15084 stack frame. This is useful for breaking on return to a stack frame.\n\
15086 THREADNUM is the number from \"info threads\".\n\
15087 CONDITION is a boolean expression.\n\
15088 \n" LOCATION_HELP_STRING "\n\n\
15089 Multiple breakpoints at one place are permitted, and useful if their\n\
15090 conditions are different.\n\
15092 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15094 /* List of subcommands for "catch". */
15095 static struct cmd_list_element
*catch_cmdlist
;
15097 /* List of subcommands for "tcatch". */
15098 static struct cmd_list_element
*tcatch_cmdlist
;
15101 add_catch_command (const char *name
, const char *docstring
,
15102 cmd_const_sfunc_ftype
*sfunc
,
15103 completer_ftype
*completer
,
15104 void *user_data_catch
,
15105 void *user_data_tcatch
)
15107 struct cmd_list_element
*command
;
15109 command
= add_cmd (name
, class_breakpoint
, docstring
,
15111 set_cmd_sfunc (command
, sfunc
);
15112 set_cmd_context (command
, user_data_catch
);
15113 set_cmd_completer (command
, completer
);
15115 command
= add_cmd (name
, class_breakpoint
, docstring
,
15117 set_cmd_sfunc (command
, sfunc
);
15118 set_cmd_context (command
, user_data_tcatch
);
15119 set_cmd_completer (command
, completer
);
15123 save_command (const char *arg
, int from_tty
)
15125 printf_unfiltered (_("\"save\" must be followed by "
15126 "the name of a save subcommand.\n"));
15127 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15130 struct breakpoint
*
15131 iterate_over_breakpoints (gdb::function_view
<bool (breakpoint
*)> callback
)
15133 struct breakpoint
*b
, *b_tmp
;
15135 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15144 /* Zero if any of the breakpoint's locations could be a location where
15145 functions have been inlined, nonzero otherwise. */
15148 is_non_inline_function (struct breakpoint
*b
)
15150 /* The shared library event breakpoint is set on the address of a
15151 non-inline function. */
15152 if (b
->type
== bp_shlib_event
)
15158 /* Nonzero if the specified PC cannot be a location where functions
15159 have been inlined. */
15162 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15163 const struct target_waitstatus
*ws
)
15165 struct breakpoint
*b
;
15166 struct bp_location
*bl
;
15168 ALL_BREAKPOINTS (b
)
15170 if (!is_non_inline_function (b
))
15173 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15175 if (!bl
->shlib_disabled
15176 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15184 /* Remove any references to OBJFILE which is going to be freed. */
15187 breakpoint_free_objfile (struct objfile
*objfile
)
15189 struct bp_location
**locp
, *loc
;
15191 ALL_BP_LOCATIONS (loc
, locp
)
15192 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15193 loc
->symtab
= NULL
;
15197 initialize_breakpoint_ops (void)
15199 static int initialized
= 0;
15201 struct breakpoint_ops
*ops
;
15207 /* The breakpoint_ops structure to be inherit by all kinds of
15208 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15209 internal and momentary breakpoints, etc.). */
15210 ops
= &bkpt_base_breakpoint_ops
;
15211 *ops
= base_breakpoint_ops
;
15212 ops
->re_set
= bkpt_re_set
;
15213 ops
->insert_location
= bkpt_insert_location
;
15214 ops
->remove_location
= bkpt_remove_location
;
15215 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15216 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15217 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15218 ops
->decode_location
= bkpt_decode_location
;
15220 /* The breakpoint_ops structure to be used in regular breakpoints. */
15221 ops
= &bkpt_breakpoint_ops
;
15222 *ops
= bkpt_base_breakpoint_ops
;
15223 ops
->re_set
= bkpt_re_set
;
15224 ops
->resources_needed
= bkpt_resources_needed
;
15225 ops
->print_it
= bkpt_print_it
;
15226 ops
->print_mention
= bkpt_print_mention
;
15227 ops
->print_recreate
= bkpt_print_recreate
;
15229 /* Ranged breakpoints. */
15230 ops
= &ranged_breakpoint_ops
;
15231 *ops
= bkpt_breakpoint_ops
;
15232 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15233 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15234 ops
->print_it
= print_it_ranged_breakpoint
;
15235 ops
->print_one
= print_one_ranged_breakpoint
;
15236 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15237 ops
->print_mention
= print_mention_ranged_breakpoint
;
15238 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15240 /* Internal breakpoints. */
15241 ops
= &internal_breakpoint_ops
;
15242 *ops
= bkpt_base_breakpoint_ops
;
15243 ops
->re_set
= internal_bkpt_re_set
;
15244 ops
->check_status
= internal_bkpt_check_status
;
15245 ops
->print_it
= internal_bkpt_print_it
;
15246 ops
->print_mention
= internal_bkpt_print_mention
;
15248 /* Momentary breakpoints. */
15249 ops
= &momentary_breakpoint_ops
;
15250 *ops
= bkpt_base_breakpoint_ops
;
15251 ops
->re_set
= momentary_bkpt_re_set
;
15252 ops
->check_status
= momentary_bkpt_check_status
;
15253 ops
->print_it
= momentary_bkpt_print_it
;
15254 ops
->print_mention
= momentary_bkpt_print_mention
;
15256 /* Probe breakpoints. */
15257 ops
= &bkpt_probe_breakpoint_ops
;
15258 *ops
= bkpt_breakpoint_ops
;
15259 ops
->insert_location
= bkpt_probe_insert_location
;
15260 ops
->remove_location
= bkpt_probe_remove_location
;
15261 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15262 ops
->decode_location
= bkpt_probe_decode_location
;
15265 ops
= &watchpoint_breakpoint_ops
;
15266 *ops
= base_breakpoint_ops
;
15267 ops
->re_set
= re_set_watchpoint
;
15268 ops
->insert_location
= insert_watchpoint
;
15269 ops
->remove_location
= remove_watchpoint
;
15270 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15271 ops
->check_status
= check_status_watchpoint
;
15272 ops
->resources_needed
= resources_needed_watchpoint
;
15273 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15274 ops
->print_it
= print_it_watchpoint
;
15275 ops
->print_mention
= print_mention_watchpoint
;
15276 ops
->print_recreate
= print_recreate_watchpoint
;
15277 ops
->explains_signal
= explains_signal_watchpoint
;
15279 /* Masked watchpoints. */
15280 ops
= &masked_watchpoint_breakpoint_ops
;
15281 *ops
= watchpoint_breakpoint_ops
;
15282 ops
->insert_location
= insert_masked_watchpoint
;
15283 ops
->remove_location
= remove_masked_watchpoint
;
15284 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15285 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15286 ops
->print_it
= print_it_masked_watchpoint
;
15287 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15288 ops
->print_mention
= print_mention_masked_watchpoint
;
15289 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15292 ops
= &tracepoint_breakpoint_ops
;
15293 *ops
= base_breakpoint_ops
;
15294 ops
->re_set
= tracepoint_re_set
;
15295 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15296 ops
->print_one_detail
= tracepoint_print_one_detail
;
15297 ops
->print_mention
= tracepoint_print_mention
;
15298 ops
->print_recreate
= tracepoint_print_recreate
;
15299 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15300 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15301 ops
->decode_location
= tracepoint_decode_location
;
15303 /* Probe tracepoints. */
15304 ops
= &tracepoint_probe_breakpoint_ops
;
15305 *ops
= tracepoint_breakpoint_ops
;
15306 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15307 ops
->decode_location
= tracepoint_probe_decode_location
;
15309 /* Static tracepoints with marker (`-m'). */
15310 ops
= &strace_marker_breakpoint_ops
;
15311 *ops
= tracepoint_breakpoint_ops
;
15312 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15313 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15314 ops
->decode_location
= strace_marker_decode_location
;
15316 /* Fork catchpoints. */
15317 ops
= &catch_fork_breakpoint_ops
;
15318 *ops
= base_breakpoint_ops
;
15319 ops
->insert_location
= insert_catch_fork
;
15320 ops
->remove_location
= remove_catch_fork
;
15321 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15322 ops
->print_it
= print_it_catch_fork
;
15323 ops
->print_one
= print_one_catch_fork
;
15324 ops
->print_mention
= print_mention_catch_fork
;
15325 ops
->print_recreate
= print_recreate_catch_fork
;
15327 /* Vfork catchpoints. */
15328 ops
= &catch_vfork_breakpoint_ops
;
15329 *ops
= base_breakpoint_ops
;
15330 ops
->insert_location
= insert_catch_vfork
;
15331 ops
->remove_location
= remove_catch_vfork
;
15332 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15333 ops
->print_it
= print_it_catch_vfork
;
15334 ops
->print_one
= print_one_catch_vfork
;
15335 ops
->print_mention
= print_mention_catch_vfork
;
15336 ops
->print_recreate
= print_recreate_catch_vfork
;
15338 /* Exec catchpoints. */
15339 ops
= &catch_exec_breakpoint_ops
;
15340 *ops
= base_breakpoint_ops
;
15341 ops
->insert_location
= insert_catch_exec
;
15342 ops
->remove_location
= remove_catch_exec
;
15343 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15344 ops
->print_it
= print_it_catch_exec
;
15345 ops
->print_one
= print_one_catch_exec
;
15346 ops
->print_mention
= print_mention_catch_exec
;
15347 ops
->print_recreate
= print_recreate_catch_exec
;
15349 /* Solib-related catchpoints. */
15350 ops
= &catch_solib_breakpoint_ops
;
15351 *ops
= base_breakpoint_ops
;
15352 ops
->insert_location
= insert_catch_solib
;
15353 ops
->remove_location
= remove_catch_solib
;
15354 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15355 ops
->check_status
= check_status_catch_solib
;
15356 ops
->print_it
= print_it_catch_solib
;
15357 ops
->print_one
= print_one_catch_solib
;
15358 ops
->print_mention
= print_mention_catch_solib
;
15359 ops
->print_recreate
= print_recreate_catch_solib
;
15361 ops
= &dprintf_breakpoint_ops
;
15362 *ops
= bkpt_base_breakpoint_ops
;
15363 ops
->re_set
= dprintf_re_set
;
15364 ops
->resources_needed
= bkpt_resources_needed
;
15365 ops
->print_it
= bkpt_print_it
;
15366 ops
->print_mention
= bkpt_print_mention
;
15367 ops
->print_recreate
= dprintf_print_recreate
;
15368 ops
->after_condition_true
= dprintf_after_condition_true
;
15369 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15372 /* Chain containing all defined "enable breakpoint" subcommands. */
15374 static struct cmd_list_element
*enablebreaklist
= NULL
;
15376 /* See breakpoint.h. */
15378 cmd_list_element
*commands_cmd_element
= nullptr;
15381 _initialize_breakpoint (void)
15383 struct cmd_list_element
*c
;
15385 initialize_breakpoint_ops ();
15387 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
);
15388 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
);
15389 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
);
15391 breakpoint_chain
= 0;
15392 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15393 before a breakpoint is set. */
15394 breakpoint_count
= 0;
15396 tracepoint_count
= 0;
15398 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15399 Set ignore-count of breakpoint number N to COUNT.\n\
15400 Usage is `ignore N COUNT'."));
15402 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15403 commands_command
, _("\
15404 Set commands to be executed when the given breakpoints are hit.\n\
15405 Give a space-separated breakpoint list as argument after \"commands\".\n\
15406 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15408 With no argument, the targeted breakpoint is the last one set.\n\
15409 The commands themselves follow starting on the next line.\n\
15410 Type a line containing \"end\" to indicate the end of them.\n\
15411 Give \"silent\" as the first line to make the breakpoint silent;\n\
15412 then no output is printed when it is hit, except what the commands print."));
15414 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15415 Specify breakpoint number N to break only if COND is true.\n\
15416 Usage is `condition N COND', where N is an integer and COND is an\n\
15417 expression to be evaluated whenever breakpoint N is reached."));
15418 set_cmd_completer (c
, condition_completer
);
15420 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15421 Set a temporary breakpoint.\n\
15422 Like \"break\" except the breakpoint is only temporary,\n\
15423 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15424 by using \"enable delete\" on the breakpoint number.\n\
15426 BREAK_ARGS_HELP ("tbreak")));
15427 set_cmd_completer (c
, location_completer
);
15429 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15430 Set a hardware assisted breakpoint.\n\
15431 Like \"break\" except the breakpoint requires hardware support,\n\
15432 some target hardware may not have this support.\n\
15434 BREAK_ARGS_HELP ("hbreak")));
15435 set_cmd_completer (c
, location_completer
);
15437 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15438 Set a temporary hardware assisted breakpoint.\n\
15439 Like \"hbreak\" except the breakpoint is only temporary,\n\
15440 so it will be deleted when hit.\n\
15442 BREAK_ARGS_HELP ("thbreak")));
15443 set_cmd_completer (c
, location_completer
);
15445 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15446 Enable all or some breakpoints.\n\
15447 Usage: enable [BREAKPOINTNUM]...\n\
15448 Give breakpoint numbers (separated by spaces) as arguments.\n\
15449 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15450 This is used to cancel the effect of the \"disable\" command.\n\
15451 With a subcommand you can enable temporarily."),
15452 &enablelist
, "enable ", 1, &cmdlist
);
15454 add_com_alias ("en", "enable", class_breakpoint
, 1);
15456 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15457 Enable all or some breakpoints.\n\
15458 Usage: enable breakpoints [BREAKPOINTNUM]...\n\
15459 Give breakpoint numbers (separated by spaces) as arguments.\n\
15460 This is used to cancel the effect of the \"disable\" command.\n\
15461 May be abbreviated to simply \"enable\"."),
15462 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15464 add_cmd ("once", no_class
, enable_once_command
, _("\
15465 Enable some breakpoints for one hit.\n\
15466 Usage: enable breakpoints once BREAKPOINTNUM...\n\
15467 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15470 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15471 Enable some breakpoints and delete when hit.\n\
15472 Usage: enable breakpoints delete BREAKPOINTNUM...\n\
15473 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15476 add_cmd ("count", no_class
, enable_count_command
, _("\
15477 Enable some breakpoints for COUNT hits.\n\
15478 Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\
15479 If a breakpoint is hit while enabled in this fashion,\n\
15480 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15483 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15484 Enable some breakpoints and delete when hit.\n\
15485 Usage: enable delete BREAKPOINTNUM...\n\
15486 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15489 add_cmd ("once", no_class
, enable_once_command
, _("\
15490 Enable some breakpoints for one hit.\n\
15491 Usage: enable once BREAKPOINTNUM...\n\
15492 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15495 add_cmd ("count", no_class
, enable_count_command
, _("\
15496 Enable some breakpoints for COUNT hits.\n\
15497 Usage: enable count COUNT BREAKPOINTNUM...\n\
15498 If a breakpoint is hit while enabled in this fashion,\n\
15499 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15502 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15503 Disable all or some breakpoints.\n\
15504 Usage: disable [BREAKPOINTNUM]...\n\
15505 Arguments are breakpoint numbers with spaces in between.\n\
15506 To disable all breakpoints, give no argument.\n\
15507 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15508 &disablelist
, "disable ", 1, &cmdlist
);
15509 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15510 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15512 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15513 Disable all or some breakpoints.\n\
15514 Usage: disable breakpoints [BREAKPOINTNUM]...\n\
15515 Arguments are breakpoint numbers with spaces in between.\n\
15516 To disable all breakpoints, give no argument.\n\
15517 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15518 This command may be abbreviated \"disable\"."),
15521 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15522 Delete all or some breakpoints.\n\
15523 Usage: delete [BREAKPOINTNUM]...\n\
15524 Arguments are breakpoint numbers with spaces in between.\n\
15525 To delete all breakpoints, give no argument.\n\
15527 Also a prefix command for deletion of other GDB objects."),
15528 &deletelist
, "delete ", 1, &cmdlist
);
15529 add_com_alias ("d", "delete", class_breakpoint
, 1);
15530 add_com_alias ("del", "delete", class_breakpoint
, 1);
15532 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15533 Delete all or some breakpoints or auto-display expressions.\n\
15534 Usage: delete breakpoints [BREAKPOINTNUM]...\n\
15535 Arguments are breakpoint numbers with spaces in between.\n\
15536 To delete all breakpoints, give no argument.\n\
15537 This command may be abbreviated \"delete\"."),
15540 add_com ("clear", class_breakpoint
, clear_command
, _("\
15541 Clear breakpoint at specified location.\n\
15542 Argument may be a linespec, explicit, or address location as described below.\n\
15544 With no argument, clears all breakpoints in the line that the selected frame\n\
15545 is executing in.\n"
15546 "\n" LOCATION_HELP_STRING
"\n\n\
15547 See also the \"delete\" command which clears breakpoints by number."));
15548 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15550 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15551 Set breakpoint at specified location.\n"
15552 BREAK_ARGS_HELP ("break")));
15553 set_cmd_completer (c
, location_completer
);
15555 add_com_alias ("b", "break", class_run
, 1);
15556 add_com_alias ("br", "break", class_run
, 1);
15557 add_com_alias ("bre", "break", class_run
, 1);
15558 add_com_alias ("brea", "break", class_run
, 1);
15562 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15563 Break in function/address or break at a line in the current file."),
15564 &stoplist
, "stop ", 1, &cmdlist
);
15565 add_cmd ("in", class_breakpoint
, stopin_command
,
15566 _("Break in function or address."), &stoplist
);
15567 add_cmd ("at", class_breakpoint
, stopat_command
,
15568 _("Break at a line in the current file."), &stoplist
);
15569 add_com ("status", class_info
, info_breakpoints_command
, _("\
15570 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15571 The \"Type\" column indicates one of:\n\
15572 \tbreakpoint - normal breakpoint\n\
15573 \twatchpoint - watchpoint\n\
15574 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15575 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15576 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15577 address and file/line number respectively.\n\
15579 Convenience variable \"$_\" and default examine address for \"x\"\n\
15580 are set to the address of the last breakpoint listed unless the command\n\
15581 is prefixed with \"server \".\n\n\
15582 Convenience variable \"$bpnum\" contains the number of the last\n\
15583 breakpoint set."));
15586 add_info ("breakpoints", info_breakpoints_command
, _("\
15587 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15588 The \"Type\" column indicates one of:\n\
15589 \tbreakpoint - normal breakpoint\n\
15590 \twatchpoint - watchpoint\n\
15591 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15592 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15593 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15594 address and file/line number respectively.\n\
15596 Convenience variable \"$_\" and default examine address for \"x\"\n\
15597 are set to the address of the last breakpoint listed unless the command\n\
15598 is prefixed with \"server \".\n\n\
15599 Convenience variable \"$bpnum\" contains the number of the last\n\
15600 breakpoint set."));
15602 add_info_alias ("b", "breakpoints", 1);
15604 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15605 Status of all breakpoints, or breakpoint number NUMBER.\n\
15606 The \"Type\" column indicates one of:\n\
15607 \tbreakpoint - normal breakpoint\n\
15608 \twatchpoint - watchpoint\n\
15609 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15610 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15611 \tuntil - internal breakpoint used by the \"until\" command\n\
15612 \tfinish - internal breakpoint used by the \"finish\" command\n\
15613 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15614 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15615 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15616 address and file/line number respectively.\n\
15618 Convenience variable \"$_\" and default examine address for \"x\"\n\
15619 are set to the address of the last breakpoint listed unless the command\n\
15620 is prefixed with \"server \".\n\n\
15621 Convenience variable \"$bpnum\" contains the number of the last\n\
15623 &maintenanceinfolist
);
15625 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15626 Set catchpoints to catch events."),
15627 &catch_cmdlist
, "catch ",
15628 0/*allow-unknown*/, &cmdlist
);
15630 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15631 Set temporary catchpoints to catch events."),
15632 &tcatch_cmdlist
, "tcatch ",
15633 0/*allow-unknown*/, &cmdlist
);
15635 add_catch_command ("fork", _("Catch calls to fork."),
15636 catch_fork_command_1
,
15638 (void *) (uintptr_t) catch_fork_permanent
,
15639 (void *) (uintptr_t) catch_fork_temporary
);
15640 add_catch_command ("vfork", _("Catch calls to vfork."),
15641 catch_fork_command_1
,
15643 (void *) (uintptr_t) catch_vfork_permanent
,
15644 (void *) (uintptr_t) catch_vfork_temporary
);
15645 add_catch_command ("exec", _("Catch calls to exec."),
15646 catch_exec_command_1
,
15650 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15651 Usage: catch load [REGEX]\n\
15652 If REGEX is given, only stop for libraries matching the regular expression."),
15653 catch_load_command_1
,
15657 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15658 Usage: catch unload [REGEX]\n\
15659 If REGEX is given, only stop for libraries matching the regular expression."),
15660 catch_unload_command_1
,
15665 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15666 Set a watchpoint for an expression.\n\
15667 Usage: watch [-l|-location] EXPRESSION\n\
15668 A watchpoint stops execution of your program whenever the value of\n\
15669 an expression changes.\n\
15670 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15671 the memory to which it refers."));
15672 set_cmd_completer (c
, expression_completer
);
15674 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15675 Set a read watchpoint for an expression.\n\
15676 Usage: rwatch [-l|-location] EXPRESSION\n\
15677 A watchpoint stops execution of your program whenever the value of\n\
15678 an expression is read.\n\
15679 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15680 the memory to which it refers."));
15681 set_cmd_completer (c
, expression_completer
);
15683 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15684 Set a watchpoint for an expression.\n\
15685 Usage: awatch [-l|-location] EXPRESSION\n\
15686 A watchpoint stops execution of your program whenever the value of\n\
15687 an expression is either read or written.\n\
15688 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15689 the memory to which it refers."));
15690 set_cmd_completer (c
, expression_completer
);
15692 add_info ("watchpoints", info_watchpoints_command
, _("\
15693 Status of specified watchpoints (all watchpoints if no argument)."));
15695 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15696 respond to changes - contrary to the description. */
15697 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15698 &can_use_hw_watchpoints
, _("\
15699 Set debugger's willingness to use watchpoint hardware."), _("\
15700 Show debugger's willingness to use watchpoint hardware."), _("\
15701 If zero, gdb will not use hardware for new watchpoints, even if\n\
15702 such is available. (However, any hardware watchpoints that were\n\
15703 created before setting this to nonzero, will continue to use watchpoint\n\
15706 show_can_use_hw_watchpoints
,
15707 &setlist
, &showlist
);
15709 can_use_hw_watchpoints
= 1;
15711 /* Tracepoint manipulation commands. */
15713 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15714 Set a tracepoint at specified location.\n\
15716 BREAK_ARGS_HELP ("trace") "\n\
15717 Do \"help tracepoints\" for info on other tracepoint commands."));
15718 set_cmd_completer (c
, location_completer
);
15720 add_com_alias ("tp", "trace", class_alias
, 0);
15721 add_com_alias ("tr", "trace", class_alias
, 1);
15722 add_com_alias ("tra", "trace", class_alias
, 1);
15723 add_com_alias ("trac", "trace", class_alias
, 1);
15725 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15726 Set a fast tracepoint at specified location.\n\
15728 BREAK_ARGS_HELP ("ftrace") "\n\
15729 Do \"help tracepoints\" for info on other tracepoint commands."));
15730 set_cmd_completer (c
, location_completer
);
15732 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15733 Set a static tracepoint at location or marker.\n\
15735 strace [LOCATION] [if CONDITION]\n\
15736 LOCATION may be a linespec, explicit, or address location (described below) \n\
15737 or -m MARKER_ID.\n\n\
15738 If a marker id is specified, probe the marker with that name. With\n\
15739 no LOCATION, uses current execution address of the selected stack frame.\n\
15740 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15741 This collects arbitrary user data passed in the probe point call to the\n\
15742 tracing library. You can inspect it when analyzing the trace buffer,\n\
15743 by printing the $_sdata variable like any other convenience variable.\n\
15745 CONDITION is a boolean expression.\n\
15746 \n" LOCATION_HELP_STRING
"\n\n\
15747 Multiple tracepoints at one place are permitted, and useful if their\n\
15748 conditions are different.\n\
15750 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15751 Do \"help tracepoints\" for info on other tracepoint commands."));
15752 set_cmd_completer (c
, location_completer
);
15754 add_info ("tracepoints", info_tracepoints_command
, _("\
15755 Status of specified tracepoints (all tracepoints if no argument).\n\
15756 Convenience variable \"$tpnum\" contains the number of the\n\
15757 last tracepoint set."));
15759 add_info_alias ("tp", "tracepoints", 1);
15761 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15762 Delete specified tracepoints.\n\
15763 Arguments are tracepoint numbers, separated by spaces.\n\
15764 No argument means delete all tracepoints."),
15766 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
15768 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15769 Disable specified tracepoints.\n\
15770 Arguments are tracepoint numbers, separated by spaces.\n\
15771 No argument means disable all tracepoints."),
15773 deprecate_cmd (c
, "disable");
15775 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15776 Enable specified tracepoints.\n\
15777 Arguments are tracepoint numbers, separated by spaces.\n\
15778 No argument means enable all tracepoints."),
15780 deprecate_cmd (c
, "enable");
15782 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15783 Set the passcount for a tracepoint.\n\
15784 The trace will end when the tracepoint has been passed 'count' times.\n\
15785 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15786 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15788 add_prefix_cmd ("save", class_breakpoint
, save_command
,
15789 _("Save breakpoint definitions as a script."),
15790 &save_cmdlist
, "save ",
15791 0/*allow-unknown*/, &cmdlist
);
15793 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15794 Save current breakpoint definitions as a script.\n\
15795 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15796 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15797 session to restore them."),
15799 set_cmd_completer (c
, filename_completer
);
15801 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15802 Save current tracepoint definitions as a script.\n\
15803 Use the 'source' command in another debug session to restore them."),
15805 set_cmd_completer (c
, filename_completer
);
15807 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
15808 deprecate_cmd (c
, "save tracepoints");
15810 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
15811 Breakpoint specific settings.\n\
15812 Configure various breakpoint-specific variables such as\n\
15813 pending breakpoint behavior."),
15814 &breakpoint_set_cmdlist
, "set breakpoint ",
15815 0/*allow-unknown*/, &setlist
);
15816 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
15817 Breakpoint specific settings.\n\
15818 Configure various breakpoint-specific variables such as\n\
15819 pending breakpoint behavior."),
15820 &breakpoint_show_cmdlist
, "show breakpoint ",
15821 0/*allow-unknown*/, &showlist
);
15823 add_setshow_auto_boolean_cmd ("pending", no_class
,
15824 &pending_break_support
, _("\
15825 Set debugger's behavior regarding pending breakpoints."), _("\
15826 Show debugger's behavior regarding pending breakpoints."), _("\
15827 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15828 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15829 an error. If auto, an unrecognized breakpoint location results in a\n\
15830 user-query to see if a pending breakpoint should be created."),
15832 show_pending_break_support
,
15833 &breakpoint_set_cmdlist
,
15834 &breakpoint_show_cmdlist
);
15836 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15838 add_setshow_boolean_cmd ("auto-hw", no_class
,
15839 &automatic_hardware_breakpoints
, _("\
15840 Set automatic usage of hardware breakpoints."), _("\
15841 Show automatic usage of hardware breakpoints."), _("\
15842 If set, the debugger will automatically use hardware breakpoints for\n\
15843 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15844 a warning will be emitted for such breakpoints."),
15846 show_automatic_hardware_breakpoints
,
15847 &breakpoint_set_cmdlist
,
15848 &breakpoint_show_cmdlist
);
15850 add_setshow_boolean_cmd ("always-inserted", class_support
,
15851 &always_inserted_mode
, _("\
15852 Set mode for inserting breakpoints."), _("\
15853 Show mode for inserting breakpoints."), _("\
15854 When this mode is on, breakpoints are inserted immediately as soon as\n\
15855 they're created, kept inserted even when execution stops, and removed\n\
15856 only when the user deletes them. When this mode is off (the default),\n\
15857 breakpoints are inserted only when execution continues, and removed\n\
15858 when execution stops."),
15860 &show_always_inserted_mode
,
15861 &breakpoint_set_cmdlist
,
15862 &breakpoint_show_cmdlist
);
15864 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15865 condition_evaluation_enums
,
15866 &condition_evaluation_mode_1
, _("\
15867 Set mode of breakpoint condition evaluation."), _("\
15868 Show mode of breakpoint condition evaluation."), _("\
15869 When this is set to \"host\", breakpoint conditions will be\n\
15870 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15871 breakpoint conditions will be downloaded to the target (if the target\n\
15872 supports such feature) and conditions will be evaluated on the target's side.\n\
15873 If this is set to \"auto\" (default), this will be automatically set to\n\
15874 \"target\" if it supports condition evaluation, otherwise it will\n\
15875 be set to \"gdb\""),
15876 &set_condition_evaluation_mode
,
15877 &show_condition_evaluation_mode
,
15878 &breakpoint_set_cmdlist
,
15879 &breakpoint_show_cmdlist
);
15881 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15882 Set a breakpoint for an address range.\n\
15883 break-range START-LOCATION, END-LOCATION\n\
15884 where START-LOCATION and END-LOCATION can be one of the following:\n\
15885 LINENUM, for that line in the current file,\n\
15886 FILE:LINENUM, for that line in that file,\n\
15887 +OFFSET, for that number of lines after the current line\n\
15888 or the start of the range\n\
15889 FUNCTION, for the first line in that function,\n\
15890 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15891 *ADDRESS, for the instruction at that address.\n\
15893 The breakpoint will stop execution of the inferior whenever it executes\n\
15894 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15895 range (including START-LOCATION and END-LOCATION)."));
15897 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
15898 Set a dynamic printf at specified location.\n\
15899 dprintf location,format string,arg1,arg2,...\n\
15900 location may be a linespec, explicit, or address location.\n"
15901 "\n" LOCATION_HELP_STRING
));
15902 set_cmd_completer (c
, location_completer
);
15904 add_setshow_enum_cmd ("dprintf-style", class_support
,
15905 dprintf_style_enums
, &dprintf_style
, _("\
15906 Set the style of usage for dynamic printf."), _("\
15907 Show the style of usage for dynamic printf."), _("\
15908 This setting chooses how GDB will do a dynamic printf.\n\
15909 If the value is \"gdb\", then the printing is done by GDB to its own\n\
15910 console, as with the \"printf\" command.\n\
15911 If the value is \"call\", the print is done by calling a function in your\n\
15912 program; by default printf(), but you can choose a different function or\n\
15913 output stream by setting dprintf-function and dprintf-channel."),
15914 update_dprintf_commands
, NULL
,
15915 &setlist
, &showlist
);
15917 dprintf_function
= xstrdup ("printf");
15918 add_setshow_string_cmd ("dprintf-function", class_support
,
15919 &dprintf_function
, _("\
15920 Set the function to use for dynamic printf."), _("\
15921 Show the function to use for dynamic printf."), NULL
,
15922 update_dprintf_commands
, NULL
,
15923 &setlist
, &showlist
);
15925 dprintf_channel
= xstrdup ("");
15926 add_setshow_string_cmd ("dprintf-channel", class_support
,
15927 &dprintf_channel
, _("\
15928 Set the channel to use for dynamic printf."), _("\
15929 Show the channel to use for dynamic printf."), NULL
,
15930 update_dprintf_commands
, NULL
,
15931 &setlist
, &showlist
);
15933 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
15934 &disconnected_dprintf
, _("\
15935 Set whether dprintf continues after GDB disconnects."), _("\
15936 Show whether dprintf continues after GDB disconnects."), _("\
15937 Use this to let dprintf commands continue to hit and produce output\n\
15938 even if GDB disconnects or detaches from the target."),
15941 &setlist
, &showlist
);
15943 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
15944 Target agent only formatted printing, like the C \"printf\" function.\n\
15945 Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\
15946 This supports most C printf format specifications, like %s, %d, etc.\n\
15947 This is useful for formatted output in user-defined commands."));
15949 automatic_hardware_breakpoints
= true;
15951 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
);
15952 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
);