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"
62 #include "continuations.h"
66 #include "dummy-frame.h"
68 #include "common/format.h"
69 #include "thread-fsm.h"
70 #include "tid-parse.h"
71 #include "cli/cli-style.h"
72 #include "mi/mi-main.h"
74 /* readline include files */
75 #include "readline/readline.h"
76 #include "readline/history.h"
78 /* readline defines this. */
81 #include "mi/mi-common.h"
82 #include "extension.h"
84 #include "progspace-and-thread.h"
85 #include "common/array-view.h"
86 #include "common/gdb_optional.h"
88 /* Prototypes for local functions. */
90 static void map_breakpoint_numbers (const char *,
91 gdb::function_view
<void (breakpoint
*)>);
93 static void breakpoint_re_set_default (struct breakpoint
*);
96 create_sals_from_location_default (const struct event_location
*location
,
97 struct linespec_result
*canonical
,
98 enum bptype type_wanted
);
100 static void create_breakpoints_sal_default (struct gdbarch
*,
101 struct linespec_result
*,
102 gdb::unique_xmalloc_ptr
<char>,
103 gdb::unique_xmalloc_ptr
<char>,
105 enum bpdisp
, int, int,
107 const struct breakpoint_ops
*,
108 int, int, int, unsigned);
110 static std::vector
<symtab_and_line
> decode_location_default
111 (struct breakpoint
*b
, const struct event_location
*location
,
112 struct program_space
*search_pspace
);
114 static int can_use_hardware_watchpoint
115 (const std::vector
<value_ref_ptr
> &vals
);
117 static void mention (struct breakpoint
*);
119 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
121 const struct breakpoint_ops
*);
122 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
123 const struct symtab_and_line
*);
125 /* This function is used in gdbtk sources and thus can not be made
127 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
128 struct symtab_and_line
,
130 const struct breakpoint_ops
*);
132 static struct breakpoint
*
133 momentary_breakpoint_from_master (struct breakpoint
*orig
,
135 const struct breakpoint_ops
*ops
,
138 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
140 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
144 static void describe_other_breakpoints (struct gdbarch
*,
145 struct program_space
*, CORE_ADDR
,
146 struct obj_section
*, int);
148 static int watchpoint_locations_match (struct bp_location
*loc1
,
149 struct bp_location
*loc2
);
151 static int breakpoint_location_address_match (struct bp_location
*bl
,
152 const struct address_space
*aspace
,
155 static int breakpoint_location_address_range_overlap (struct bp_location
*,
156 const address_space
*,
159 static int remove_breakpoint (struct bp_location
*);
160 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
162 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
164 static int hw_breakpoint_used_count (void);
166 static int hw_watchpoint_use_count (struct breakpoint
*);
168 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
170 int *other_type_used
);
172 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
175 static void free_bp_location (struct bp_location
*loc
);
176 static void incref_bp_location (struct bp_location
*loc
);
177 static void decref_bp_location (struct bp_location
**loc
);
179 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
181 /* update_global_location_list's modes of operation wrt to whether to
182 insert locations now. */
183 enum ugll_insert_mode
185 /* Don't insert any breakpoint locations into the inferior, only
186 remove already-inserted locations that no longer should be
187 inserted. Functions that delete a breakpoint or breakpoints
188 should specify this mode, so that deleting a breakpoint doesn't
189 have the side effect of inserting the locations of other
190 breakpoints that are marked not-inserted, but should_be_inserted
191 returns true on them.
193 This behavior is useful is situations close to tear-down -- e.g.,
194 after an exec, while the target still has execution, but
195 breakpoint shadows of the previous executable image should *NOT*
196 be restored to the new image; or before detaching, where the
197 target still has execution and wants to delete breakpoints from
198 GDB's lists, and all breakpoints had already been removed from
202 /* May insert breakpoints iff breakpoints_should_be_inserted_now
203 claims breakpoints should be inserted now. */
206 /* Insert locations now, irrespective of
207 breakpoints_should_be_inserted_now. E.g., say all threads are
208 stopped right now, and the user did "continue". We need to
209 insert breakpoints _before_ resuming the target, but
210 UGLL_MAY_INSERT wouldn't insert them, because
211 breakpoints_should_be_inserted_now returns false at that point,
212 as no thread is running yet. */
216 static void update_global_location_list (enum ugll_insert_mode
);
218 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
220 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
222 static void insert_breakpoint_locations (void);
224 static void trace_pass_command (const char *, int);
226 static void set_tracepoint_count (int num
);
228 static int is_masked_watchpoint (const struct breakpoint
*b
);
230 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
232 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
235 static int strace_marker_p (struct breakpoint
*b
);
237 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
238 that are implemented on top of software or hardware breakpoints
239 (user breakpoints, internal and momentary breakpoints, etc.). */
240 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
242 /* Internal breakpoints class type. */
243 static struct breakpoint_ops internal_breakpoint_ops
;
245 /* Momentary breakpoints class type. */
246 static struct breakpoint_ops momentary_breakpoint_ops
;
248 /* The breakpoint_ops structure to be used in regular user created
250 struct breakpoint_ops bkpt_breakpoint_ops
;
252 /* Breakpoints set on probes. */
253 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
255 /* Dynamic printf class type. */
256 struct breakpoint_ops dprintf_breakpoint_ops
;
258 /* The style in which to perform a dynamic printf. This is a user
259 option because different output options have different tradeoffs;
260 if GDB does the printing, there is better error handling if there
261 is a problem with any of the arguments, but using an inferior
262 function lets you have special-purpose printers and sending of
263 output to the same place as compiled-in print functions. */
265 static const char dprintf_style_gdb
[] = "gdb";
266 static const char dprintf_style_call
[] = "call";
267 static const char dprintf_style_agent
[] = "agent";
268 static const char *const dprintf_style_enums
[] = {
274 static const char *dprintf_style
= dprintf_style_gdb
;
276 /* The function to use for dynamic printf if the preferred style is to
277 call into the inferior. The value is simply a string that is
278 copied into the command, so it can be anything that GDB can
279 evaluate to a callable address, not necessarily a function name. */
281 static char *dprintf_function
;
283 /* The channel to use for dynamic printf if the preferred style is to
284 call into the inferior; if a nonempty string, it will be passed to
285 the call as the first argument, with the format string as the
286 second. As with the dprintf function, this can be anything that
287 GDB knows how to evaluate, so in addition to common choices like
288 "stderr", this could be an app-specific expression like
289 "mystreams[curlogger]". */
291 static char *dprintf_channel
;
293 /* True if dprintf commands should continue to operate even if GDB
295 static int disconnected_dprintf
= 1;
297 struct command_line
*
298 breakpoint_commands (struct breakpoint
*b
)
300 return b
->commands
? b
->commands
.get () : NULL
;
303 /* Flag indicating that a command has proceeded the inferior past the
304 current breakpoint. */
306 static int breakpoint_proceeded
;
309 bpdisp_text (enum bpdisp disp
)
311 /* NOTE: the following values are a part of MI protocol and
312 represent values of 'disp' field returned when inferior stops at
314 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
316 return bpdisps
[(int) disp
];
319 /* Prototypes for exported functions. */
320 /* If FALSE, gdb will not use hardware support for watchpoints, even
321 if such is available. */
322 static int can_use_hw_watchpoints
;
325 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
326 struct cmd_list_element
*c
,
329 fprintf_filtered (file
,
330 _("Debugger's willingness to use "
331 "watchpoint hardware is %s.\n"),
335 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
336 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
337 for unrecognized breakpoint locations.
338 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
339 static enum auto_boolean pending_break_support
;
341 show_pending_break_support (struct ui_file
*file
, int from_tty
,
342 struct cmd_list_element
*c
,
345 fprintf_filtered (file
,
346 _("Debugger's behavior regarding "
347 "pending breakpoints is %s.\n"),
351 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
352 set with "break" but falling in read-only memory.
353 If 0, gdb will warn about such breakpoints, but won't automatically
354 use hardware breakpoints. */
355 static int automatic_hardware_breakpoints
;
357 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
358 struct cmd_list_element
*c
,
361 fprintf_filtered (file
,
362 _("Automatic usage of hardware breakpoints is %s.\n"),
366 /* If on, GDB keeps breakpoints inserted even if the inferior is
367 stopped, and immediately inserts any new breakpoints as soon as
368 they're created. If off (default), GDB keeps breakpoints off of
369 the target as long as possible. That is, it delays inserting
370 breakpoints until the next resume, and removes them again when the
371 target fully stops. This is a bit safer in case GDB crashes while
372 processing user input. */
373 static int always_inserted_mode
= 0;
376 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
377 struct cmd_list_element
*c
, const char *value
)
379 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
383 /* See breakpoint.h. */
386 breakpoints_should_be_inserted_now (void)
388 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
390 /* If breakpoints are global, they should be inserted even if no
391 thread under gdb's control is running, or even if there are
392 no threads under GDB's control yet. */
395 else if (target_has_execution
)
397 if (always_inserted_mode
)
399 /* The user wants breakpoints inserted even if all threads
404 if (threads_are_executing ())
407 /* Don't remove breakpoints yet if, even though all threads are
408 stopped, we still have events to process. */
409 for (thread_info
*tp
: all_non_exited_threads ())
411 && tp
->suspend
.waitstatus_pending_p
)
417 static const char condition_evaluation_both
[] = "host or target";
419 /* Modes for breakpoint condition evaluation. */
420 static const char condition_evaluation_auto
[] = "auto";
421 static const char condition_evaluation_host
[] = "host";
422 static const char condition_evaluation_target
[] = "target";
423 static const char *const condition_evaluation_enums
[] = {
424 condition_evaluation_auto
,
425 condition_evaluation_host
,
426 condition_evaluation_target
,
430 /* Global that holds the current mode for breakpoint condition evaluation. */
431 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
433 /* Global that we use to display information to the user (gets its value from
434 condition_evaluation_mode_1. */
435 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
437 /* Translate a condition evaluation mode MODE into either "host"
438 or "target". This is used mostly to translate from "auto" to the
439 real setting that is being used. It returns the translated
443 translate_condition_evaluation_mode (const char *mode
)
445 if (mode
== condition_evaluation_auto
)
447 if (target_supports_evaluation_of_breakpoint_conditions ())
448 return condition_evaluation_target
;
450 return condition_evaluation_host
;
456 /* Discovers what condition_evaluation_auto translates to. */
459 breakpoint_condition_evaluation_mode (void)
461 return translate_condition_evaluation_mode (condition_evaluation_mode
);
464 /* Return true if GDB should evaluate breakpoint conditions or false
468 gdb_evaluates_breakpoint_condition_p (void)
470 const char *mode
= breakpoint_condition_evaluation_mode ();
472 return (mode
== condition_evaluation_host
);
475 /* Are we executing breakpoint commands? */
476 static int executing_breakpoint_commands
;
478 /* Are overlay event breakpoints enabled? */
479 static int overlay_events_enabled
;
481 /* See description in breakpoint.h. */
482 int target_exact_watchpoints
= 0;
484 /* Walk the following statement or block through all breakpoints.
485 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
486 current breakpoint. */
488 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
490 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
491 for (B = breakpoint_chain; \
492 B ? (TMP=B->next, 1): 0; \
495 /* Similar iterator for the low-level breakpoints. SAFE variant is
496 not provided so update_global_location_list must not be called
497 while executing the block of ALL_BP_LOCATIONS. */
499 #define ALL_BP_LOCATIONS(B,BP_TMP) \
500 for (BP_TMP = bp_locations; \
501 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
504 /* Iterates through locations with address ADDRESS for the currently selected
505 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
506 to where the loop should start from.
507 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
508 appropriate location to start with. */
510 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
511 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
512 BP_LOCP_TMP = BP_LOCP_START; \
514 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
515 && (*BP_LOCP_TMP)->address == ADDRESS); \
518 /* Iterator for tracepoints only. */
520 #define ALL_TRACEPOINTS(B) \
521 for (B = breakpoint_chain; B; B = B->next) \
522 if (is_tracepoint (B))
524 /* Chains of all breakpoints defined. */
526 struct breakpoint
*breakpoint_chain
;
528 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
530 static struct bp_location
**bp_locations
;
532 /* Number of elements of BP_LOCATIONS. */
534 static unsigned bp_locations_count
;
536 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
537 ADDRESS for the current elements of BP_LOCATIONS which get a valid
538 result from bp_location_has_shadow. You can use it for roughly
539 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
540 an address you need to read. */
542 static CORE_ADDR bp_locations_placed_address_before_address_max
;
544 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
545 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
546 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
547 You can use it for roughly limiting the subrange of BP_LOCATIONS to
548 scan for shadow bytes for an address you need to read. */
550 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
552 /* The locations that no longer correspond to any breakpoint, unlinked
553 from the bp_locations array, but for which a hit may still be
554 reported by a target. */
555 static std::vector
<bp_location
*> moribund_locations
;
557 /* Number of last breakpoint made. */
559 static int breakpoint_count
;
561 /* The value of `breakpoint_count' before the last command that
562 created breakpoints. If the last (break-like) command created more
563 than one breakpoint, then the difference between BREAKPOINT_COUNT
564 and PREV_BREAKPOINT_COUNT is more than one. */
565 static int prev_breakpoint_count
;
567 /* Number of last tracepoint made. */
569 static int tracepoint_count
;
571 static struct cmd_list_element
*breakpoint_set_cmdlist
;
572 static struct cmd_list_element
*breakpoint_show_cmdlist
;
573 struct cmd_list_element
*save_cmdlist
;
575 /* See declaration at breakpoint.h. */
578 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
581 struct breakpoint
*b
= NULL
;
585 if (func (b
, user_data
) != 0)
592 /* Return whether a breakpoint is an active enabled breakpoint. */
594 breakpoint_enabled (struct breakpoint
*b
)
596 return (b
->enable_state
== bp_enabled
);
599 /* Set breakpoint count to NUM. */
602 set_breakpoint_count (int num
)
604 prev_breakpoint_count
= breakpoint_count
;
605 breakpoint_count
= num
;
606 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
609 /* Used by `start_rbreak_breakpoints' below, to record the current
610 breakpoint count before "rbreak" creates any breakpoint. */
611 static int rbreak_start_breakpoint_count
;
613 /* Called at the start an "rbreak" command to record the first
616 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
618 rbreak_start_breakpoint_count
= breakpoint_count
;
621 /* Called at the end of an "rbreak" command to record the last
624 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
626 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
629 /* Used in run_command to zero the hit count when a new run starts. */
632 clear_breakpoint_hit_counts (void)
634 struct breakpoint
*b
;
641 /* Return the breakpoint with the specified number, or NULL
642 if the number does not refer to an existing breakpoint. */
645 get_breakpoint (int num
)
647 struct breakpoint
*b
;
650 if (b
->number
== num
)
658 /* Mark locations as "conditions have changed" in case the target supports
659 evaluating conditions on its side. */
662 mark_breakpoint_modified (struct breakpoint
*b
)
664 struct bp_location
*loc
;
666 /* This is only meaningful if the target is
667 evaluating conditions and if the user has
668 opted for condition evaluation on the target's
670 if (gdb_evaluates_breakpoint_condition_p ()
671 || !target_supports_evaluation_of_breakpoint_conditions ())
674 if (!is_breakpoint (b
))
677 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
678 loc
->condition_changed
= condition_modified
;
681 /* Mark location as "conditions have changed" in case the target supports
682 evaluating conditions on its side. */
685 mark_breakpoint_location_modified (struct bp_location
*loc
)
687 /* This is only meaningful if the target is
688 evaluating conditions and if the user has
689 opted for condition evaluation on the target's
691 if (gdb_evaluates_breakpoint_condition_p ()
692 || !target_supports_evaluation_of_breakpoint_conditions ())
696 if (!is_breakpoint (loc
->owner
))
699 loc
->condition_changed
= condition_modified
;
702 /* Sets the condition-evaluation mode using the static global
703 condition_evaluation_mode. */
706 set_condition_evaluation_mode (const char *args
, int from_tty
,
707 struct cmd_list_element
*c
)
709 const char *old_mode
, *new_mode
;
711 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
712 && !target_supports_evaluation_of_breakpoint_conditions ())
714 condition_evaluation_mode_1
= condition_evaluation_mode
;
715 warning (_("Target does not support breakpoint condition evaluation.\n"
716 "Using host evaluation mode instead."));
720 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
721 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
723 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
724 settings was "auto". */
725 condition_evaluation_mode
= condition_evaluation_mode_1
;
727 /* Only update the mode if the user picked a different one. */
728 if (new_mode
!= old_mode
)
730 struct bp_location
*loc
, **loc_tmp
;
731 /* If the user switched to a different evaluation mode, we
732 need to synch the changes with the target as follows:
734 "host" -> "target": Send all (valid) conditions to the target.
735 "target" -> "host": Remove all the conditions from the target.
738 if (new_mode
== condition_evaluation_target
)
740 /* Mark everything modified and synch conditions with the
742 ALL_BP_LOCATIONS (loc
, loc_tmp
)
743 mark_breakpoint_location_modified (loc
);
747 /* Manually mark non-duplicate locations to synch conditions
748 with the target. We do this to remove all the conditions the
749 target knows about. */
750 ALL_BP_LOCATIONS (loc
, loc_tmp
)
751 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
752 loc
->needs_update
= 1;
756 update_global_location_list (UGLL_MAY_INSERT
);
762 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
763 what "auto" is translating to. */
766 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
767 struct cmd_list_element
*c
, const char *value
)
769 if (condition_evaluation_mode
== condition_evaluation_auto
)
770 fprintf_filtered (file
,
771 _("Breakpoint condition evaluation "
772 "mode is %s (currently %s).\n"),
774 breakpoint_condition_evaluation_mode ());
776 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
780 /* A comparison function for bp_location AP and BP that is used by
781 bsearch. This comparison function only cares about addresses, unlike
782 the more general bp_locations_compare function. */
785 bp_locations_compare_addrs (const void *ap
, const void *bp
)
787 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
788 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
790 if (a
->address
== b
->address
)
793 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
796 /* Helper function to skip all bp_locations with addresses
797 less than ADDRESS. It returns the first bp_location that
798 is greater than or equal to ADDRESS. If none is found, just
801 static struct bp_location
**
802 get_first_locp_gte_addr (CORE_ADDR address
)
804 struct bp_location dummy_loc
;
805 struct bp_location
*dummy_locp
= &dummy_loc
;
806 struct bp_location
**locp_found
= NULL
;
808 /* Initialize the dummy location's address field. */
809 dummy_loc
.address
= address
;
811 /* Find a close match to the first location at ADDRESS. */
812 locp_found
= ((struct bp_location
**)
813 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
814 sizeof (struct bp_location
**),
815 bp_locations_compare_addrs
));
817 /* Nothing was found, nothing left to do. */
818 if (locp_found
== NULL
)
821 /* We may have found a location that is at ADDRESS but is not the first in the
822 location's list. Go backwards (if possible) and locate the first one. */
823 while ((locp_found
- 1) >= bp_locations
824 && (*(locp_found
- 1))->address
== address
)
831 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
834 xfree (b
->cond_string
);
835 b
->cond_string
= NULL
;
837 if (is_watchpoint (b
))
839 struct watchpoint
*w
= (struct watchpoint
*) b
;
841 w
->cond_exp
.reset ();
845 struct bp_location
*loc
;
847 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
851 /* No need to free the condition agent expression
852 bytecode (if we have one). We will handle this
853 when we go through update_global_location_list. */
860 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
864 const char *arg
= exp
;
866 /* I don't know if it matters whether this is the string the user
867 typed in or the decompiled expression. */
868 b
->cond_string
= xstrdup (arg
);
869 b
->condition_not_parsed
= 0;
871 if (is_watchpoint (b
))
873 struct watchpoint
*w
= (struct watchpoint
*) b
;
875 innermost_block_tracker tracker
;
877 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
879 error (_("Junk at end of expression"));
880 w
->cond_exp_valid_block
= tracker
.block ();
884 struct bp_location
*loc
;
886 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
890 parse_exp_1 (&arg
, loc
->address
,
891 block_for_pc (loc
->address
), 0);
893 error (_("Junk at end of expression"));
897 mark_breakpoint_modified (b
);
899 gdb::observers::breakpoint_modified
.notify (b
);
902 /* Completion for the "condition" command. */
905 condition_completer (struct cmd_list_element
*cmd
,
906 completion_tracker
&tracker
,
907 const char *text
, const char *word
)
911 text
= skip_spaces (text
);
912 space
= skip_to_space (text
);
916 struct breakpoint
*b
;
920 /* We don't support completion of history indices. */
921 if (!isdigit (text
[1]))
922 complete_internalvar (tracker
, &text
[1]);
926 /* We're completing the breakpoint number. */
933 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
935 if (strncmp (number
, text
, len
) == 0)
936 tracker
.add_completion (make_unique_xstrdup (number
));
942 /* We're completing the expression part. */
943 text
= skip_spaces (space
);
944 expression_completer (cmd
, tracker
, text
, word
);
947 /* condition N EXP -- set break condition of breakpoint N to EXP. */
950 condition_command (const char *arg
, int from_tty
)
952 struct breakpoint
*b
;
957 error_no_arg (_("breakpoint number"));
960 bnum
= get_number (&p
);
962 error (_("Bad breakpoint argument: '%s'"), arg
);
965 if (b
->number
== bnum
)
967 /* Check if this breakpoint has a "stop" method implemented in an
968 extension language. This method and conditions entered into GDB
969 from the CLI are mutually exclusive. */
970 const struct extension_language_defn
*extlang
971 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
975 error (_("Only one stop condition allowed. There is currently"
976 " a %s stop condition defined for this breakpoint."),
977 ext_lang_capitalized_name (extlang
));
979 set_breakpoint_condition (b
, p
, from_tty
);
981 if (is_breakpoint (b
))
982 update_global_location_list (UGLL_MAY_INSERT
);
987 error (_("No breakpoint number %d."), bnum
);
990 /* Check that COMMAND do not contain commands that are suitable
991 only for tracepoints and not suitable for ordinary breakpoints.
992 Throw if any such commands is found. */
995 check_no_tracepoint_commands (struct command_line
*commands
)
997 struct command_line
*c
;
999 for (c
= commands
; c
; c
= c
->next
)
1001 if (c
->control_type
== while_stepping_control
)
1002 error (_("The 'while-stepping' command can "
1003 "only be used for tracepoints"));
1005 check_no_tracepoint_commands (c
->body_list_0
.get ());
1006 check_no_tracepoint_commands (c
->body_list_1
.get ());
1008 /* Not that command parsing removes leading whitespace and comment
1009 lines and also empty lines. So, we only need to check for
1010 command directly. */
1011 if (strstr (c
->line
, "collect ") == c
->line
)
1012 error (_("The 'collect' command can only be used for tracepoints"));
1014 if (strstr (c
->line
, "teval ") == c
->line
)
1015 error (_("The 'teval' command can only be used for tracepoints"));
1019 struct longjmp_breakpoint
: public breakpoint
1021 ~longjmp_breakpoint () override
;
1024 /* Encapsulate tests for different types of tracepoints. */
1027 is_tracepoint_type (bptype type
)
1029 return (type
== bp_tracepoint
1030 || type
== bp_fast_tracepoint
1031 || type
== bp_static_tracepoint
);
1035 is_longjmp_type (bptype type
)
1037 return type
== bp_longjmp
|| type
== bp_exception
;
1041 is_tracepoint (const struct breakpoint
*b
)
1043 return is_tracepoint_type (b
->type
);
1046 /* Factory function to create an appropriate instance of breakpoint given
1049 static std::unique_ptr
<breakpoint
>
1050 new_breakpoint_from_type (bptype type
)
1054 if (is_tracepoint_type (type
))
1055 b
= new tracepoint ();
1056 else if (is_longjmp_type (type
))
1057 b
= new longjmp_breakpoint ();
1059 b
= new breakpoint ();
1061 return std::unique_ptr
<breakpoint
> (b
);
1064 /* A helper function that validates that COMMANDS are valid for a
1065 breakpoint. This function will throw an exception if a problem is
1069 validate_commands_for_breakpoint (struct breakpoint
*b
,
1070 struct command_line
*commands
)
1072 if (is_tracepoint (b
))
1074 struct tracepoint
*t
= (struct tracepoint
*) b
;
1075 struct command_line
*c
;
1076 struct command_line
*while_stepping
= 0;
1078 /* Reset the while-stepping step count. The previous commands
1079 might have included a while-stepping action, while the new
1083 /* We need to verify that each top-level element of commands is
1084 valid for tracepoints, that there's at most one
1085 while-stepping element, and that the while-stepping's body
1086 has valid tracing commands excluding nested while-stepping.
1087 We also need to validate the tracepoint action line in the
1088 context of the tracepoint --- validate_actionline actually
1089 has side effects, like setting the tracepoint's
1090 while-stepping STEP_COUNT, in addition to checking if the
1091 collect/teval actions parse and make sense in the
1092 tracepoint's context. */
1093 for (c
= commands
; c
; c
= c
->next
)
1095 if (c
->control_type
== while_stepping_control
)
1097 if (b
->type
== bp_fast_tracepoint
)
1098 error (_("The 'while-stepping' command "
1099 "cannot be used for fast tracepoint"));
1100 else if (b
->type
== bp_static_tracepoint
)
1101 error (_("The 'while-stepping' command "
1102 "cannot be used for static tracepoint"));
1105 error (_("The 'while-stepping' command "
1106 "can be used only once"));
1111 validate_actionline (c
->line
, b
);
1115 struct command_line
*c2
;
1117 gdb_assert (while_stepping
->body_list_1
== nullptr);
1118 c2
= while_stepping
->body_list_0
.get ();
1119 for (; c2
; c2
= c2
->next
)
1121 if (c2
->control_type
== while_stepping_control
)
1122 error (_("The 'while-stepping' command cannot be nested"));
1128 check_no_tracepoint_commands (commands
);
1132 /* Return a vector of all the static tracepoints set at ADDR. The
1133 caller is responsible for releasing the vector. */
1135 std::vector
<breakpoint
*>
1136 static_tracepoints_here (CORE_ADDR addr
)
1138 struct breakpoint
*b
;
1139 std::vector
<breakpoint
*> found
;
1140 struct bp_location
*loc
;
1143 if (b
->type
== bp_static_tracepoint
)
1145 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1146 if (loc
->address
== addr
)
1147 found
.push_back (b
);
1153 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1154 validate that only allowed commands are included. */
1157 breakpoint_set_commands (struct breakpoint
*b
,
1158 counted_command_line
&&commands
)
1160 validate_commands_for_breakpoint (b
, commands
.get ());
1162 b
->commands
= std::move (commands
);
1163 gdb::observers::breakpoint_modified
.notify (b
);
1166 /* Set the internal `silent' flag on the breakpoint. Note that this
1167 is not the same as the "silent" that may appear in the breakpoint's
1171 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1173 int old_silent
= b
->silent
;
1176 if (old_silent
!= silent
)
1177 gdb::observers::breakpoint_modified
.notify (b
);
1180 /* Set the thread for this breakpoint. If THREAD is -1, make the
1181 breakpoint work for any thread. */
1184 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1186 int old_thread
= b
->thread
;
1189 if (old_thread
!= thread
)
1190 gdb::observers::breakpoint_modified
.notify (b
);
1193 /* Set the task for this breakpoint. If TASK is 0, make the
1194 breakpoint work for any task. */
1197 breakpoint_set_task (struct breakpoint
*b
, int task
)
1199 int old_task
= b
->task
;
1202 if (old_task
!= task
)
1203 gdb::observers::breakpoint_modified
.notify (b
);
1207 commands_command_1 (const char *arg
, int from_tty
,
1208 struct command_line
*control
)
1210 counted_command_line cmd
;
1211 /* cmd_read will be true once we have read cmd. Note that cmd might still be
1212 NULL after the call to read_command_lines if the user provides an empty
1213 list of command by just typing "end". */
1214 bool cmd_read
= false;
1216 std::string new_arg
;
1218 if (arg
== NULL
|| !*arg
)
1220 if (breakpoint_count
- prev_breakpoint_count
> 1)
1221 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1223 else if (breakpoint_count
> 0)
1224 new_arg
= string_printf ("%d", breakpoint_count
);
1225 arg
= new_arg
.c_str ();
1228 map_breakpoint_numbers
1229 (arg
, [&] (breakpoint
*b
)
1233 gdb_assert (cmd
== NULL
);
1234 if (control
!= NULL
)
1235 cmd
= control
->body_list_0
;
1239 = string_printf (_("Type commands for breakpoint(s) "
1240 "%s, one per line."),
1243 auto do_validate
= [=] (const char *line
)
1245 validate_actionline (line
, b
);
1247 gdb::function_view
<void (const char *)> validator
;
1248 if (is_tracepoint (b
))
1249 validator
= do_validate
;
1251 cmd
= read_command_lines (str
.c_str (), from_tty
, 1, validator
);
1256 /* If a breakpoint was on the list more than once, we don't need to
1258 if (b
->commands
!= cmd
)
1260 validate_commands_for_breakpoint (b
, cmd
.get ());
1262 gdb::observers::breakpoint_modified
.notify (b
);
1268 commands_command (const char *arg
, int from_tty
)
1270 commands_command_1 (arg
, from_tty
, NULL
);
1273 /* Like commands_command, but instead of reading the commands from
1274 input stream, takes them from an already parsed command structure.
1276 This is used by cli-script.c to DTRT with breakpoint commands
1277 that are part of if and while bodies. */
1278 enum command_control_type
1279 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1281 commands_command_1 (arg
, 0, cmd
);
1282 return simple_control
;
1285 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1288 bp_location_has_shadow (struct bp_location
*bl
)
1290 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1294 if (bl
->target_info
.shadow_len
== 0)
1295 /* BL isn't valid, or doesn't shadow memory. */
1300 /* Update BUF, which is LEN bytes read from the target address
1301 MEMADDR, by replacing a memory breakpoint with its shadowed
1304 If READBUF is not NULL, this buffer must not overlap with the of
1305 the breakpoint location's shadow_contents buffer. Otherwise, a
1306 failed assertion internal error will be raised. */
1309 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1310 const gdb_byte
*writebuf_org
,
1311 ULONGEST memaddr
, LONGEST len
,
1312 struct bp_target_info
*target_info
,
1313 struct gdbarch
*gdbarch
)
1315 /* Now do full processing of the found relevant range of elements. */
1316 CORE_ADDR bp_addr
= 0;
1320 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1321 current_program_space
->aspace
, 0))
1323 /* The breakpoint is inserted in a different address space. */
1327 /* Addresses and length of the part of the breakpoint that
1329 bp_addr
= target_info
->placed_address
;
1330 bp_size
= target_info
->shadow_len
;
1332 if (bp_addr
+ bp_size
<= memaddr
)
1334 /* The breakpoint is entirely before the chunk of memory we are
1339 if (bp_addr
>= memaddr
+ len
)
1341 /* The breakpoint is entirely after the chunk of memory we are
1346 /* Offset within shadow_contents. */
1347 if (bp_addr
< memaddr
)
1349 /* Only copy the second part of the breakpoint. */
1350 bp_size
-= memaddr
- bp_addr
;
1351 bptoffset
= memaddr
- bp_addr
;
1355 if (bp_addr
+ bp_size
> memaddr
+ len
)
1357 /* Only copy the first part of the breakpoint. */
1358 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1361 if (readbuf
!= NULL
)
1363 /* Verify that the readbuf buffer does not overlap with the
1364 shadow_contents buffer. */
1365 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1366 || readbuf
>= (target_info
->shadow_contents
1367 + target_info
->shadow_len
));
1369 /* Update the read buffer with this inserted breakpoint's
1371 memcpy (readbuf
+ bp_addr
- memaddr
,
1372 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1376 const unsigned char *bp
;
1377 CORE_ADDR addr
= target_info
->reqstd_address
;
1380 /* Update the shadow with what we want to write to memory. */
1381 memcpy (target_info
->shadow_contents
+ bptoffset
,
1382 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1384 /* Determine appropriate breakpoint contents and size for this
1386 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1388 /* Update the final write buffer with this inserted
1389 breakpoint's INSN. */
1390 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1394 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1395 by replacing any memory breakpoints with their shadowed contents.
1397 If READBUF is not NULL, this buffer must not overlap with any of
1398 the breakpoint location's shadow_contents buffers. Otherwise,
1399 a failed assertion internal error will be raised.
1401 The range of shadowed area by each bp_location is:
1402 bl->address - bp_locations_placed_address_before_address_max
1403 up to bl->address + bp_locations_shadow_len_after_address_max
1404 The range we were requested to resolve shadows for is:
1405 memaddr ... memaddr + len
1406 Thus the safe cutoff boundaries for performance optimization are
1407 memaddr + len <= (bl->address
1408 - bp_locations_placed_address_before_address_max)
1410 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1413 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1414 const gdb_byte
*writebuf_org
,
1415 ULONGEST memaddr
, LONGEST len
)
1417 /* Left boundary, right boundary and median element of our binary
1419 unsigned bc_l
, bc_r
, bc
;
1421 /* Find BC_L which is a leftmost element which may affect BUF
1422 content. It is safe to report lower value but a failure to
1423 report higher one. */
1426 bc_r
= bp_locations_count
;
1427 while (bc_l
+ 1 < bc_r
)
1429 struct bp_location
*bl
;
1431 bc
= (bc_l
+ bc_r
) / 2;
1432 bl
= bp_locations
[bc
];
1434 /* Check first BL->ADDRESS will not overflow due to the added
1435 constant. Then advance the left boundary only if we are sure
1436 the BC element can in no way affect the BUF content (MEMADDR
1437 to MEMADDR + LEN range).
1439 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1440 offset so that we cannot miss a breakpoint with its shadow
1441 range tail still reaching MEMADDR. */
1443 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1445 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1452 /* Due to the binary search above, we need to make sure we pick the
1453 first location that's at BC_L's address. E.g., if there are
1454 multiple locations at the same address, BC_L may end up pointing
1455 at a duplicate location, and miss the "master"/"inserted"
1456 location. Say, given locations L1, L2 and L3 at addresses A and
1459 L1@A, L2@A, L3@B, ...
1461 BC_L could end up pointing at location L2, while the "master"
1462 location could be L1. Since the `loc->inserted' flag is only set
1463 on "master" locations, we'd forget to restore the shadow of L1
1466 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1469 /* Now do full processing of the found relevant range of elements. */
1471 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1473 struct bp_location
*bl
= bp_locations
[bc
];
1475 /* bp_location array has BL->OWNER always non-NULL. */
1476 if (bl
->owner
->type
== bp_none
)
1477 warning (_("reading through apparently deleted breakpoint #%d?"),
1480 /* Performance optimization: any further element can no longer affect BUF
1483 if (bl
->address
>= bp_locations_placed_address_before_address_max
1484 && memaddr
+ len
<= (bl
->address
1485 - bp_locations_placed_address_before_address_max
))
1488 if (!bp_location_has_shadow (bl
))
1491 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1492 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1498 /* Return true if BPT is either a software breakpoint or a hardware
1502 is_breakpoint (const struct breakpoint
*bpt
)
1504 return (bpt
->type
== bp_breakpoint
1505 || bpt
->type
== bp_hardware_breakpoint
1506 || bpt
->type
== bp_dprintf
);
1509 /* Return true if BPT is of any hardware watchpoint kind. */
1512 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1514 return (bpt
->type
== bp_hardware_watchpoint
1515 || bpt
->type
== bp_read_watchpoint
1516 || bpt
->type
== bp_access_watchpoint
);
1519 /* Return true if BPT is of any watchpoint kind, hardware or
1523 is_watchpoint (const struct breakpoint
*bpt
)
1525 return (is_hardware_watchpoint (bpt
)
1526 || bpt
->type
== bp_watchpoint
);
1529 /* Returns true if the current thread and its running state are safe
1530 to evaluate or update watchpoint B. Watchpoints on local
1531 expressions need to be evaluated in the context of the thread that
1532 was current when the watchpoint was created, and, that thread needs
1533 to be stopped to be able to select the correct frame context.
1534 Watchpoints on global expressions can be evaluated on any thread,
1535 and in any state. It is presently left to the target allowing
1536 memory accesses when threads are running. */
1539 watchpoint_in_thread_scope (struct watchpoint
*b
)
1541 return (b
->pspace
== current_program_space
1542 && (b
->watchpoint_thread
== null_ptid
1543 || (inferior_ptid
== b
->watchpoint_thread
1544 && !inferior_thread ()->executing
)));
1547 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1548 associated bp_watchpoint_scope breakpoint. */
1551 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1553 if (w
->related_breakpoint
!= w
)
1555 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1556 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1557 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1558 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1559 w
->related_breakpoint
= w
;
1561 w
->disposition
= disp_del_at_next_stop
;
1564 /* Extract a bitfield value from value VAL using the bit parameters contained in
1567 static struct value
*
1568 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1570 struct value
*bit_val
;
1575 bit_val
= allocate_value (value_type (val
));
1577 unpack_value_bitfield (bit_val
,
1580 value_contents_for_printing (val
),
1587 /* Allocate a dummy location and add it to B, which must be a software
1588 watchpoint. This is required because even if a software watchpoint
1589 is not watching any memory, bpstat_stop_status requires a location
1590 to be able to report stops. */
1593 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1594 struct program_space
*pspace
)
1596 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1598 b
->loc
= allocate_bp_location (b
);
1599 b
->loc
->pspace
= pspace
;
1600 b
->loc
->address
= -1;
1601 b
->loc
->length
= -1;
1604 /* Returns true if B is a software watchpoint that is not watching any
1605 memory (e.g., "watch $pc"). */
1608 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1610 return (b
->type
== bp_watchpoint
1612 && b
->loc
->next
== NULL
1613 && b
->loc
->address
== -1
1614 && b
->loc
->length
== -1);
1617 /* Assuming that B is a watchpoint:
1618 - Reparse watchpoint expression, if REPARSE is non-zero
1619 - Evaluate expression and store the result in B->val
1620 - Evaluate the condition if there is one, and store the result
1622 - Update the list of values that must be watched in B->loc.
1624 If the watchpoint disposition is disp_del_at_next_stop, then do
1625 nothing. If this is local watchpoint that is out of scope, delete
1628 Even with `set breakpoint always-inserted on' the watchpoints are
1629 removed + inserted on each stop here. Normal breakpoints must
1630 never be removed because they might be missed by a running thread
1631 when debugging in non-stop mode. On the other hand, hardware
1632 watchpoints (is_hardware_watchpoint; processed here) are specific
1633 to each LWP since they are stored in each LWP's hardware debug
1634 registers. Therefore, such LWP must be stopped first in order to
1635 be able to modify its hardware watchpoints.
1637 Hardware watchpoints must be reset exactly once after being
1638 presented to the user. It cannot be done sooner, because it would
1639 reset the data used to present the watchpoint hit to the user. And
1640 it must not be done later because it could display the same single
1641 watchpoint hit during multiple GDB stops. Note that the latter is
1642 relevant only to the hardware watchpoint types bp_read_watchpoint
1643 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1644 not user-visible - its hit is suppressed if the memory content has
1647 The following constraints influence the location where we can reset
1648 hardware watchpoints:
1650 * target_stopped_by_watchpoint and target_stopped_data_address are
1651 called several times when GDB stops.
1654 * Multiple hardware watchpoints can be hit at the same time,
1655 causing GDB to stop. GDB only presents one hardware watchpoint
1656 hit at a time as the reason for stopping, and all the other hits
1657 are presented later, one after the other, each time the user
1658 requests the execution to be resumed. Execution is not resumed
1659 for the threads still having pending hit event stored in
1660 LWP_INFO->STATUS. While the watchpoint is already removed from
1661 the inferior on the first stop the thread hit event is kept being
1662 reported from its cached value by linux_nat_stopped_data_address
1663 until the real thread resume happens after the watchpoint gets
1664 presented and thus its LWP_INFO->STATUS gets reset.
1666 Therefore the hardware watchpoint hit can get safely reset on the
1667 watchpoint removal from inferior. */
1670 update_watchpoint (struct watchpoint
*b
, int reparse
)
1672 int within_current_scope
;
1673 struct frame_id saved_frame_id
;
1676 /* If this is a local watchpoint, we only want to check if the
1677 watchpoint frame is in scope if the current thread is the thread
1678 that was used to create the watchpoint. */
1679 if (!watchpoint_in_thread_scope (b
))
1682 if (b
->disposition
== disp_del_at_next_stop
)
1687 /* Determine if the watchpoint is within scope. */
1688 if (b
->exp_valid_block
== NULL
)
1689 within_current_scope
= 1;
1692 struct frame_info
*fi
= get_current_frame ();
1693 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1694 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1696 /* If we're at a point where the stack has been destroyed
1697 (e.g. in a function epilogue), unwinding may not work
1698 properly. Do not attempt to recreate locations at this
1699 point. See similar comments in watchpoint_check. */
1700 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1703 /* Save the current frame's ID so we can restore it after
1704 evaluating the watchpoint expression on its own frame. */
1705 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1706 took a frame parameter, so that we didn't have to change the
1709 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1711 fi
= frame_find_by_id (b
->watchpoint_frame
);
1712 within_current_scope
= (fi
!= NULL
);
1713 if (within_current_scope
)
1717 /* We don't free locations. They are stored in the bp_location array
1718 and update_global_location_list will eventually delete them and
1719 remove breakpoints if needed. */
1722 if (within_current_scope
&& reparse
)
1727 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1728 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1729 /* If the meaning of expression itself changed, the old value is
1730 no longer relevant. We don't want to report a watchpoint hit
1731 to the user when the old value and the new value may actually
1732 be completely different objects. */
1736 /* Note that unlike with breakpoints, the watchpoint's condition
1737 expression is stored in the breakpoint object, not in the
1738 locations (re)created below. */
1739 if (b
->cond_string
!= NULL
)
1741 b
->cond_exp
.reset ();
1744 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1748 /* If we failed to parse the expression, for example because
1749 it refers to a global variable in a not-yet-loaded shared library,
1750 don't try to insert watchpoint. We don't automatically delete
1751 such watchpoint, though, since failure to parse expression
1752 is different from out-of-scope watchpoint. */
1753 if (!target_has_execution
)
1755 /* Without execution, memory can't change. No use to try and
1756 set watchpoint locations. The watchpoint will be reset when
1757 the target gains execution, through breakpoint_re_set. */
1758 if (!can_use_hw_watchpoints
)
1760 if (b
->ops
->works_in_software_mode (b
))
1761 b
->type
= bp_watchpoint
;
1763 error (_("Can't set read/access watchpoint when "
1764 "hardware watchpoints are disabled."));
1767 else if (within_current_scope
&& b
->exp
)
1770 std::vector
<value_ref_ptr
> val_chain
;
1771 struct value
*v
, *result
;
1772 struct program_space
*frame_pspace
;
1774 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1776 /* Avoid setting b->val if it's already set. The meaning of
1777 b->val is 'the last value' user saw, and we should update
1778 it only if we reported that last value to user. As it
1779 happens, the code that reports it updates b->val directly.
1780 We don't keep track of the memory value for masked
1782 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1784 if (b
->val_bitsize
!= 0)
1785 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1786 b
->val
= release_value (v
);
1790 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1792 /* Look at each value on the value chain. */
1793 gdb_assert (!val_chain
.empty ());
1794 for (const value_ref_ptr
&iter
: val_chain
)
1798 /* If it's a memory location, and GDB actually needed
1799 its contents to evaluate the expression, then we
1800 must watch it. If the first value returned is
1801 still lazy, that means an error occurred reading it;
1802 watch it anyway in case it becomes readable. */
1803 if (VALUE_LVAL (v
) == lval_memory
1804 && (v
== val_chain
[0] || ! value_lazy (v
)))
1806 struct type
*vtype
= check_typedef (value_type (v
));
1808 /* We only watch structs and arrays if user asked
1809 for it explicitly, never if they just happen to
1810 appear in the middle of some value chain. */
1812 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1813 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1816 enum target_hw_bp_type type
;
1817 struct bp_location
*loc
, **tmp
;
1818 int bitpos
= 0, bitsize
= 0;
1820 if (value_bitsize (v
) != 0)
1822 /* Extract the bit parameters out from the bitfield
1824 bitpos
= value_bitpos (v
);
1825 bitsize
= value_bitsize (v
);
1827 else if (v
== result
&& b
->val_bitsize
!= 0)
1829 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1830 lvalue whose bit parameters are saved in the fields
1831 VAL_BITPOS and VAL_BITSIZE. */
1832 bitpos
= b
->val_bitpos
;
1833 bitsize
= b
->val_bitsize
;
1836 addr
= value_address (v
);
1839 /* Skip the bytes that don't contain the bitfield. */
1844 if (b
->type
== bp_read_watchpoint
)
1846 else if (b
->type
== bp_access_watchpoint
)
1849 loc
= allocate_bp_location (b
);
1850 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1853 loc
->gdbarch
= get_type_arch (value_type (v
));
1855 loc
->pspace
= frame_pspace
;
1856 loc
->address
= address_significant (loc
->gdbarch
, addr
);
1860 /* Just cover the bytes that make up the bitfield. */
1861 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1864 loc
->length
= TYPE_LENGTH (value_type (v
));
1866 loc
->watchpoint_type
= type
;
1871 /* Change the type of breakpoint between hardware assisted or
1872 an ordinary watchpoint depending on the hardware support
1873 and free hardware slots. REPARSE is set when the inferior
1878 enum bp_loc_type loc_type
;
1879 struct bp_location
*bl
;
1881 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1885 int i
, target_resources_ok
, other_type_used
;
1888 /* Use an exact watchpoint when there's only one memory region to be
1889 watched, and only one debug register is needed to watch it. */
1890 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1892 /* We need to determine how many resources are already
1893 used for all other hardware watchpoints plus this one
1894 to see if we still have enough resources to also fit
1895 this watchpoint in as well. */
1897 /* If this is a software watchpoint, we try to turn it
1898 to a hardware one -- count resources as if B was of
1899 hardware watchpoint type. */
1901 if (type
== bp_watchpoint
)
1902 type
= bp_hardware_watchpoint
;
1904 /* This watchpoint may or may not have been placed on
1905 the list yet at this point (it won't be in the list
1906 if we're trying to create it for the first time,
1907 through watch_command), so always account for it
1910 /* Count resources used by all watchpoints except B. */
1911 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1913 /* Add in the resources needed for B. */
1914 i
+= hw_watchpoint_use_count (b
);
1917 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1918 if (target_resources_ok
<= 0)
1920 int sw_mode
= b
->ops
->works_in_software_mode (b
);
1922 if (target_resources_ok
== 0 && !sw_mode
)
1923 error (_("Target does not support this type of "
1924 "hardware watchpoint."));
1925 else if (target_resources_ok
< 0 && !sw_mode
)
1926 error (_("There are not enough available hardware "
1927 "resources for this watchpoint."));
1929 /* Downgrade to software watchpoint. */
1930 b
->type
= bp_watchpoint
;
1934 /* If this was a software watchpoint, we've just
1935 found we have enough resources to turn it to a
1936 hardware watchpoint. Otherwise, this is a
1941 else if (!b
->ops
->works_in_software_mode (b
))
1943 if (!can_use_hw_watchpoints
)
1944 error (_("Can't set read/access watchpoint when "
1945 "hardware watchpoints are disabled."));
1947 error (_("Expression cannot be implemented with "
1948 "read/access watchpoint."));
1951 b
->type
= bp_watchpoint
;
1953 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1954 : bp_loc_hardware_watchpoint
);
1955 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1956 bl
->loc_type
= loc_type
;
1959 /* If a software watchpoint is not watching any memory, then the
1960 above left it without any location set up. But,
1961 bpstat_stop_status requires a location to be able to report
1962 stops, so make sure there's at least a dummy one. */
1963 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1964 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
1966 else if (!within_current_scope
)
1968 printf_filtered (_("\
1969 Watchpoint %d deleted because the program has left the block\n\
1970 in which its expression is valid.\n"),
1972 watchpoint_del_at_next_stop (b
);
1975 /* Restore the selected frame. */
1977 select_frame (frame_find_by_id (saved_frame_id
));
1981 /* Returns 1 iff breakpoint location should be
1982 inserted in the inferior. We don't differentiate the type of BL's owner
1983 (breakpoint vs. tracepoint), although insert_location in tracepoint's
1984 breakpoint_ops is not defined, because in insert_bp_location,
1985 tracepoint's insert_location will not be called. */
1987 should_be_inserted (struct bp_location
*bl
)
1989 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
1992 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
1995 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
1998 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2001 /* This is set for example, when we're attached to the parent of a
2002 vfork, and have detached from the child. The child is running
2003 free, and we expect it to do an exec or exit, at which point the
2004 OS makes the parent schedulable again (and the target reports
2005 that the vfork is done). Until the child is done with the shared
2006 memory region, do not insert breakpoints in the parent, otherwise
2007 the child could still trip on the parent's breakpoints. Since
2008 the parent is blocked anyway, it won't miss any breakpoint. */
2009 if (bl
->pspace
->breakpoints_not_allowed
)
2012 /* Don't insert a breakpoint if we're trying to step past its
2013 location, except if the breakpoint is a single-step breakpoint,
2014 and the breakpoint's thread is the thread which is stepping past
2016 if ((bl
->loc_type
== bp_loc_software_breakpoint
2017 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2018 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2020 /* The single-step breakpoint may be inserted at the location
2021 we're trying to step if the instruction branches to itself.
2022 However, the instruction won't be executed at all and it may
2023 break the semantics of the instruction, for example, the
2024 instruction is a conditional branch or updates some flags.
2025 We can't fix it unless GDB is able to emulate the instruction
2026 or switch to displaced stepping. */
2027 && !(bl
->owner
->type
== bp_single_step
2028 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2032 fprintf_unfiltered (gdb_stdlog
,
2033 "infrun: skipping breakpoint: "
2034 "stepping past insn at: %s\n",
2035 paddress (bl
->gdbarch
, bl
->address
));
2040 /* Don't insert watchpoints if we're trying to step past the
2041 instruction that triggered one. */
2042 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2043 && stepping_past_nonsteppable_watchpoint ())
2047 fprintf_unfiltered (gdb_stdlog
,
2048 "infrun: stepping past non-steppable watchpoint. "
2049 "skipping watchpoint at %s:%d\n",
2050 paddress (bl
->gdbarch
, bl
->address
),
2059 /* Same as should_be_inserted but does the check assuming
2060 that the location is not duplicated. */
2063 unduplicated_should_be_inserted (struct bp_location
*bl
)
2066 const int save_duplicate
= bl
->duplicate
;
2069 result
= should_be_inserted (bl
);
2070 bl
->duplicate
= save_duplicate
;
2074 /* Parses a conditional described by an expression COND into an
2075 agent expression bytecode suitable for evaluation
2076 by the bytecode interpreter. Return NULL if there was
2077 any error during parsing. */
2079 static agent_expr_up
2080 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2085 agent_expr_up aexpr
;
2087 /* We don't want to stop processing, so catch any errors
2088 that may show up. */
2091 aexpr
= gen_eval_for_expr (scope
, cond
);
2094 catch (const gdb_exception_error
&ex
)
2096 /* If we got here, it means the condition could not be parsed to a valid
2097 bytecode expression and thus can't be evaluated on the target's side.
2098 It's no use iterating through the conditions. */
2101 /* We have a valid agent expression. */
2105 /* Based on location BL, create a list of breakpoint conditions to be
2106 passed on to the target. If we have duplicated locations with different
2107 conditions, we will add such conditions to the list. The idea is that the
2108 target will evaluate the list of conditions and will only notify GDB when
2109 one of them is true. */
2112 build_target_condition_list (struct bp_location
*bl
)
2114 struct bp_location
**locp
= NULL
, **loc2p
;
2115 int null_condition_or_parse_error
= 0;
2116 int modified
= bl
->needs_update
;
2117 struct bp_location
*loc
;
2119 /* Release conditions left over from a previous insert. */
2120 bl
->target_info
.conditions
.clear ();
2122 /* This is only meaningful if the target is
2123 evaluating conditions and if the user has
2124 opted for condition evaluation on the target's
2126 if (gdb_evaluates_breakpoint_condition_p ()
2127 || !target_supports_evaluation_of_breakpoint_conditions ())
2130 /* Do a first pass to check for locations with no assigned
2131 conditions or conditions that fail to parse to a valid agent expression
2132 bytecode. If any of these happen, then it's no use to send conditions
2133 to the target since this location will always trigger and generate a
2134 response back to GDB. */
2135 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2138 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2142 /* Re-parse the conditions since something changed. In that
2143 case we already freed the condition bytecodes (see
2144 force_breakpoint_reinsertion). We just
2145 need to parse the condition to bytecodes again. */
2146 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2150 /* If we have a NULL bytecode expression, it means something
2151 went wrong or we have a null condition expression. */
2152 if (!loc
->cond_bytecode
)
2154 null_condition_or_parse_error
= 1;
2160 /* If any of these happened, it means we will have to evaluate the conditions
2161 for the location's address on gdb's side. It is no use keeping bytecodes
2162 for all the other duplicate locations, thus we free all of them here.
2164 This is so we have a finer control over which locations' conditions are
2165 being evaluated by GDB or the remote stub. */
2166 if (null_condition_or_parse_error
)
2168 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2171 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2173 /* Only go as far as the first NULL bytecode is
2175 if (!loc
->cond_bytecode
)
2178 loc
->cond_bytecode
.reset ();
2183 /* No NULL conditions or failed bytecode generation. Build a condition list
2184 for this location's address. */
2185 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2189 && is_breakpoint (loc
->owner
)
2190 && loc
->pspace
->num
== bl
->pspace
->num
2191 && loc
->owner
->enable_state
== bp_enabled
2194 /* Add the condition to the vector. This will be used later
2195 to send the conditions to the target. */
2196 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2203 /* Parses a command described by string CMD into an agent expression
2204 bytecode suitable for evaluation by the bytecode interpreter.
2205 Return NULL if there was any error during parsing. */
2207 static agent_expr_up
2208 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2210 const char *cmdrest
;
2211 const char *format_start
, *format_end
;
2212 struct gdbarch
*gdbarch
= get_current_arch ();
2219 if (*cmdrest
== ',')
2221 cmdrest
= skip_spaces (cmdrest
);
2223 if (*cmdrest
++ != '"')
2224 error (_("No format string following the location"));
2226 format_start
= cmdrest
;
2228 format_pieces
fpieces (&cmdrest
);
2230 format_end
= cmdrest
;
2232 if (*cmdrest
++ != '"')
2233 error (_("Bad format string, non-terminated '\"'."));
2235 cmdrest
= skip_spaces (cmdrest
);
2237 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2238 error (_("Invalid argument syntax"));
2240 if (*cmdrest
== ',')
2242 cmdrest
= skip_spaces (cmdrest
);
2244 /* For each argument, make an expression. */
2246 std::vector
<struct expression
*> argvec
;
2247 while (*cmdrest
!= '\0')
2252 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2253 argvec
.push_back (expr
.release ());
2255 if (*cmdrest
== ',')
2259 agent_expr_up aexpr
;
2261 /* We don't want to stop processing, so catch any errors
2262 that may show up. */
2265 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2266 format_start
, format_end
- format_start
,
2267 argvec
.size (), argvec
.data ());
2269 catch (const gdb_exception_error
&ex
)
2271 /* If we got here, it means the command could not be parsed to a valid
2272 bytecode expression and thus can't be evaluated on the target's side.
2273 It's no use iterating through the other commands. */
2276 /* We have a valid agent expression, return it. */
2280 /* Based on location BL, create a list of breakpoint commands to be
2281 passed on to the target. If we have duplicated locations with
2282 different commands, we will add any such to the list. */
2285 build_target_command_list (struct bp_location
*bl
)
2287 struct bp_location
**locp
= NULL
, **loc2p
;
2288 int null_command_or_parse_error
= 0;
2289 int modified
= bl
->needs_update
;
2290 struct bp_location
*loc
;
2292 /* Clear commands left over from a previous insert. */
2293 bl
->target_info
.tcommands
.clear ();
2295 if (!target_can_run_breakpoint_commands ())
2298 /* For now, limit to agent-style dprintf breakpoints. */
2299 if (dprintf_style
!= dprintf_style_agent
)
2302 /* For now, if we have any duplicate location that isn't a dprintf,
2303 don't install the target-side commands, as that would make the
2304 breakpoint not be reported to the core, and we'd lose
2306 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2309 if (is_breakpoint (loc
->owner
)
2310 && loc
->pspace
->num
== bl
->pspace
->num
2311 && loc
->owner
->type
!= bp_dprintf
)
2315 /* Do a first pass to check for locations with no assigned
2316 conditions or conditions that fail to parse to a valid agent expression
2317 bytecode. If any of these happen, then it's no use to send conditions
2318 to the target since this location will always trigger and generate a
2319 response back to GDB. */
2320 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2323 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2327 /* Re-parse the commands since something changed. In that
2328 case we already freed the command bytecodes (see
2329 force_breakpoint_reinsertion). We just
2330 need to parse the command to bytecodes again. */
2332 = parse_cmd_to_aexpr (bl
->address
,
2333 loc
->owner
->extra_string
);
2336 /* If we have a NULL bytecode expression, it means something
2337 went wrong or we have a null command expression. */
2338 if (!loc
->cmd_bytecode
)
2340 null_command_or_parse_error
= 1;
2346 /* If anything failed, then we're not doing target-side commands,
2348 if (null_command_or_parse_error
)
2350 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2353 if (is_breakpoint (loc
->owner
)
2354 && loc
->pspace
->num
== bl
->pspace
->num
)
2356 /* Only go as far as the first NULL bytecode is
2358 if (loc
->cmd_bytecode
== NULL
)
2361 loc
->cmd_bytecode
.reset ();
2366 /* No NULL commands or failed bytecode generation. Build a command list
2367 for this location's address. */
2368 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2371 if (loc
->owner
->extra_string
2372 && is_breakpoint (loc
->owner
)
2373 && loc
->pspace
->num
== bl
->pspace
->num
2374 && loc
->owner
->enable_state
== bp_enabled
2377 /* Add the command to the vector. This will be used later
2378 to send the commands to the target. */
2379 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2383 bl
->target_info
.persist
= 0;
2384 /* Maybe flag this location as persistent. */
2385 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2386 bl
->target_info
.persist
= 1;
2389 /* Return the kind of breakpoint on address *ADDR. Get the kind
2390 of breakpoint according to ADDR except single-step breakpoint.
2391 Get the kind of single-step breakpoint according to the current
2395 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2397 if (bl
->owner
->type
== bp_single_step
)
2399 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2400 struct regcache
*regcache
;
2402 regcache
= get_thread_regcache (thr
);
2404 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2408 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2411 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2412 location. Any error messages are printed to TMP_ERROR_STREAM; and
2413 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2414 Returns 0 for success, 1 if the bp_location type is not supported or
2417 NOTE drow/2003-09-09: This routine could be broken down to an
2418 object-style method for each breakpoint or catchpoint type. */
2420 insert_bp_location (struct bp_location
*bl
,
2421 struct ui_file
*tmp_error_stream
,
2422 int *disabled_breaks
,
2423 int *hw_breakpoint_error
,
2424 int *hw_bp_error_explained_already
)
2426 gdb_exception bp_excpt
;
2428 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2431 /* Note we don't initialize bl->target_info, as that wipes out
2432 the breakpoint location's shadow_contents if the breakpoint
2433 is still inserted at that location. This in turn breaks
2434 target_read_memory which depends on these buffers when
2435 a memory read is requested at the breakpoint location:
2436 Once the target_info has been wiped, we fail to see that
2437 we have a breakpoint inserted at that address and thus
2438 read the breakpoint instead of returning the data saved in
2439 the breakpoint location's shadow contents. */
2440 bl
->target_info
.reqstd_address
= bl
->address
;
2441 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2442 bl
->target_info
.length
= bl
->length
;
2444 /* When working with target-side conditions, we must pass all the conditions
2445 for the same breakpoint address down to the target since GDB will not
2446 insert those locations. With a list of breakpoint conditions, the target
2447 can decide when to stop and notify GDB. */
2449 if (is_breakpoint (bl
->owner
))
2451 build_target_condition_list (bl
);
2452 build_target_command_list (bl
);
2453 /* Reset the modification marker. */
2454 bl
->needs_update
= 0;
2457 if (bl
->loc_type
== bp_loc_software_breakpoint
2458 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2460 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2462 /* If the explicitly specified breakpoint type
2463 is not hardware breakpoint, check the memory map to see
2464 if the breakpoint address is in read only memory or not.
2466 Two important cases are:
2467 - location type is not hardware breakpoint, memory
2468 is readonly. We change the type of the location to
2469 hardware breakpoint.
2470 - location type is hardware breakpoint, memory is
2471 read-write. This means we've previously made the
2472 location hardware one, but then the memory map changed,
2475 When breakpoints are removed, remove_breakpoints will use
2476 location types we've just set here, the only possible
2477 problem is that memory map has changed during running
2478 program, but it's not going to work anyway with current
2480 struct mem_region
*mr
2481 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2485 if (automatic_hardware_breakpoints
)
2487 enum bp_loc_type new_type
;
2489 if (mr
->attrib
.mode
!= MEM_RW
)
2490 new_type
= bp_loc_hardware_breakpoint
;
2492 new_type
= bp_loc_software_breakpoint
;
2494 if (new_type
!= bl
->loc_type
)
2496 static int said
= 0;
2498 bl
->loc_type
= new_type
;
2501 fprintf_filtered (gdb_stdout
,
2502 _("Note: automatically using "
2503 "hardware breakpoints for "
2504 "read-only addresses.\n"));
2509 else if (bl
->loc_type
== bp_loc_software_breakpoint
2510 && mr
->attrib
.mode
!= MEM_RW
)
2512 fprintf_unfiltered (tmp_error_stream
,
2513 _("Cannot insert breakpoint %d.\n"
2514 "Cannot set software breakpoint "
2515 "at read-only address %s\n"),
2517 paddress (bl
->gdbarch
, bl
->address
));
2523 /* First check to see if we have to handle an overlay. */
2524 if (overlay_debugging
== ovly_off
2525 || bl
->section
== NULL
2526 || !(section_is_overlay (bl
->section
)))
2528 /* No overlay handling: just set the breakpoint. */
2533 val
= bl
->owner
->ops
->insert_location (bl
);
2535 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2537 catch (gdb_exception
&e
)
2539 bp_excpt
= std::move (e
);
2544 /* This breakpoint is in an overlay section.
2545 Shall we set a breakpoint at the LMA? */
2546 if (!overlay_events_enabled
)
2548 /* Yes -- overlay event support is not active,
2549 so we must try to set a breakpoint at the LMA.
2550 This will not work for a hardware breakpoint. */
2551 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2552 warning (_("hardware breakpoint %d not supported in overlay!"),
2556 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2558 /* Set a software (trap) breakpoint at the LMA. */
2559 bl
->overlay_target_info
= bl
->target_info
;
2560 bl
->overlay_target_info
.reqstd_address
= addr
;
2562 /* No overlay handling: just set the breakpoint. */
2567 bl
->overlay_target_info
.kind
2568 = breakpoint_kind (bl
, &addr
);
2569 bl
->overlay_target_info
.placed_address
= addr
;
2570 val
= target_insert_breakpoint (bl
->gdbarch
,
2571 &bl
->overlay_target_info
);
2574 = gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2576 catch (gdb_exception
&e
)
2578 bp_excpt
= std::move (e
);
2581 if (bp_excpt
.reason
!= 0)
2582 fprintf_unfiltered (tmp_error_stream
,
2583 "Overlay breakpoint %d "
2584 "failed: in ROM?\n",
2588 /* Shall we set a breakpoint at the VMA? */
2589 if (section_is_mapped (bl
->section
))
2591 /* Yes. This overlay section is mapped into memory. */
2596 val
= bl
->owner
->ops
->insert_location (bl
);
2598 bp_excpt
= gdb_exception
{RETURN_ERROR
, GENERIC_ERROR
};
2600 catch (gdb_exception
&e
)
2602 bp_excpt
= std::move (e
);
2607 /* No. This breakpoint will not be inserted.
2608 No error, but do not mark the bp as 'inserted'. */
2613 if (bp_excpt
.reason
!= 0)
2615 /* Can't set the breakpoint. */
2617 /* In some cases, we might not be able to insert a
2618 breakpoint in a shared library that has already been
2619 removed, but we have not yet processed the shlib unload
2620 event. Unfortunately, some targets that implement
2621 breakpoint insertion themselves can't tell why the
2622 breakpoint insertion failed (e.g., the remote target
2623 doesn't define error codes), so we must treat generic
2624 errors as memory errors. */
2625 if (bp_excpt
.reason
== RETURN_ERROR
2626 && (bp_excpt
.error
== GENERIC_ERROR
2627 || bp_excpt
.error
== MEMORY_ERROR
)
2628 && bl
->loc_type
== bp_loc_software_breakpoint
2629 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2630 || shared_objfile_contains_address_p (bl
->pspace
,
2633 /* See also: disable_breakpoints_in_shlibs. */
2634 bl
->shlib_disabled
= 1;
2635 gdb::observers::breakpoint_modified
.notify (bl
->owner
);
2636 if (!*disabled_breaks
)
2638 fprintf_unfiltered (tmp_error_stream
,
2639 "Cannot insert breakpoint %d.\n",
2641 fprintf_unfiltered (tmp_error_stream
,
2642 "Temporarily disabling shared "
2643 "library breakpoints:\n");
2645 *disabled_breaks
= 1;
2646 fprintf_unfiltered (tmp_error_stream
,
2647 "breakpoint #%d\n", bl
->owner
->number
);
2652 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2654 *hw_breakpoint_error
= 1;
2655 *hw_bp_error_explained_already
= bp_excpt
.message
!= NULL
;
2656 fprintf_unfiltered (tmp_error_stream
,
2657 "Cannot insert hardware breakpoint %d%s",
2659 bp_excpt
.message
? ":" : ".\n");
2660 if (bp_excpt
.message
!= NULL
)
2661 fprintf_unfiltered (tmp_error_stream
, "%s.\n",
2666 if (bp_excpt
.message
== NULL
)
2669 = memory_error_message (TARGET_XFER_E_IO
,
2670 bl
->gdbarch
, bl
->address
);
2672 fprintf_unfiltered (tmp_error_stream
,
2673 "Cannot insert breakpoint %d.\n"
2675 bl
->owner
->number
, message
.c_str ());
2679 fprintf_unfiltered (tmp_error_stream
,
2680 "Cannot insert breakpoint %d: %s\n",
2695 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2696 /* NOTE drow/2003-09-08: This state only exists for removing
2697 watchpoints. It's not clear that it's necessary... */
2698 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2702 gdb_assert (bl
->owner
->ops
!= NULL
2703 && bl
->owner
->ops
->insert_location
!= NULL
);
2705 val
= bl
->owner
->ops
->insert_location (bl
);
2707 /* If trying to set a read-watchpoint, and it turns out it's not
2708 supported, try emulating one with an access watchpoint. */
2709 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2711 struct bp_location
*loc
, **loc_temp
;
2713 /* But don't try to insert it, if there's already another
2714 hw_access location that would be considered a duplicate
2716 ALL_BP_LOCATIONS (loc
, loc_temp
)
2718 && loc
->watchpoint_type
== hw_access
2719 && watchpoint_locations_match (bl
, loc
))
2723 bl
->target_info
= loc
->target_info
;
2724 bl
->watchpoint_type
= hw_access
;
2731 bl
->watchpoint_type
= hw_access
;
2732 val
= bl
->owner
->ops
->insert_location (bl
);
2735 /* Back to the original value. */
2736 bl
->watchpoint_type
= hw_read
;
2740 bl
->inserted
= (val
== 0);
2743 else if (bl
->owner
->type
== bp_catchpoint
)
2747 gdb_assert (bl
->owner
->ops
!= NULL
2748 && bl
->owner
->ops
->insert_location
!= NULL
);
2750 val
= bl
->owner
->ops
->insert_location (bl
);
2753 bl
->owner
->enable_state
= bp_disabled
;
2757 Error inserting catchpoint %d: Your system does not support this type\n\
2758 of catchpoint."), bl
->owner
->number
);
2760 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2763 bl
->inserted
= (val
== 0);
2765 /* We've already printed an error message if there was a problem
2766 inserting this catchpoint, and we've disabled the catchpoint,
2767 so just return success. */
2774 /* This function is called when program space PSPACE is about to be
2775 deleted. It takes care of updating breakpoints to not reference
2779 breakpoint_program_space_exit (struct program_space
*pspace
)
2781 struct breakpoint
*b
, *b_temp
;
2782 struct bp_location
*loc
, **loc_temp
;
2784 /* Remove any breakpoint that was set through this program space. */
2785 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2787 if (b
->pspace
== pspace
)
2788 delete_breakpoint (b
);
2791 /* Breakpoints set through other program spaces could have locations
2792 bound to PSPACE as well. Remove those. */
2793 ALL_BP_LOCATIONS (loc
, loc_temp
)
2795 struct bp_location
*tmp
;
2797 if (loc
->pspace
== pspace
)
2799 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2800 if (loc
->owner
->loc
== loc
)
2801 loc
->owner
->loc
= loc
->next
;
2803 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2804 if (tmp
->next
== loc
)
2806 tmp
->next
= loc
->next
;
2812 /* Now update the global location list to permanently delete the
2813 removed locations above. */
2814 update_global_location_list (UGLL_DONT_INSERT
);
2817 /* Make sure all breakpoints are inserted in inferior.
2818 Throws exception on any error.
2819 A breakpoint that is already inserted won't be inserted
2820 again, so calling this function twice is safe. */
2822 insert_breakpoints (void)
2824 struct breakpoint
*bpt
;
2826 ALL_BREAKPOINTS (bpt
)
2827 if (is_hardware_watchpoint (bpt
))
2829 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2831 update_watchpoint (w
, 0 /* don't reparse. */);
2834 /* Updating watchpoints creates new locations, so update the global
2835 location list. Explicitly tell ugll to insert locations and
2836 ignore breakpoints_always_inserted_mode. */
2837 update_global_location_list (UGLL_INSERT
);
2840 /* Invoke CALLBACK for each of bp_location. */
2843 iterate_over_bp_locations (walk_bp_location_callback callback
)
2845 struct bp_location
*loc
, **loc_tmp
;
2847 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2849 callback (loc
, NULL
);
2853 /* This is used when we need to synch breakpoint conditions between GDB and the
2854 target. It is the case with deleting and disabling of breakpoints when using
2855 always-inserted mode. */
2858 update_inserted_breakpoint_locations (void)
2860 struct bp_location
*bl
, **blp_tmp
;
2863 int disabled_breaks
= 0;
2864 int hw_breakpoint_error
= 0;
2865 int hw_bp_details_reported
= 0;
2867 string_file tmp_error_stream
;
2869 /* Explicitly mark the warning -- this will only be printed if
2870 there was an error. */
2871 tmp_error_stream
.puts ("Warning:\n");
2873 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2875 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2877 /* We only want to update software breakpoints and hardware
2879 if (!is_breakpoint (bl
->owner
))
2882 /* We only want to update locations that are already inserted
2883 and need updating. This is to avoid unwanted insertion during
2884 deletion of breakpoints. */
2885 if (!bl
->inserted
|| !bl
->needs_update
)
2888 switch_to_program_space_and_thread (bl
->pspace
);
2890 /* For targets that support global breakpoints, there's no need
2891 to select an inferior to insert breakpoint to. In fact, even
2892 if we aren't attached to any process yet, we should still
2893 insert breakpoints. */
2894 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2895 && inferior_ptid
== null_ptid
)
2898 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2899 &hw_breakpoint_error
, &hw_bp_details_reported
);
2906 target_terminal::ours_for_output ();
2907 error_stream (tmp_error_stream
);
2911 /* Used when starting or continuing the program. */
2914 insert_breakpoint_locations (void)
2916 struct breakpoint
*bpt
;
2917 struct bp_location
*bl
, **blp_tmp
;
2920 int disabled_breaks
= 0;
2921 int hw_breakpoint_error
= 0;
2922 int hw_bp_error_explained_already
= 0;
2924 string_file tmp_error_stream
;
2926 /* Explicitly mark the warning -- this will only be printed if
2927 there was an error. */
2928 tmp_error_stream
.puts ("Warning:\n");
2930 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2932 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2934 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2937 /* There is no point inserting thread-specific breakpoints if
2938 the thread no longer exists. ALL_BP_LOCATIONS bp_location
2939 has BL->OWNER always non-NULL. */
2940 if (bl
->owner
->thread
!= -1
2941 && !valid_global_thread_id (bl
->owner
->thread
))
2944 switch_to_program_space_and_thread (bl
->pspace
);
2946 /* For targets that support global breakpoints, there's no need
2947 to select an inferior to insert breakpoint to. In fact, even
2948 if we aren't attached to any process yet, we should still
2949 insert breakpoints. */
2950 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2951 && inferior_ptid
== null_ptid
)
2954 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2955 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
2960 /* If we failed to insert all locations of a watchpoint, remove
2961 them, as half-inserted watchpoint is of limited use. */
2962 ALL_BREAKPOINTS (bpt
)
2964 int some_failed
= 0;
2965 struct bp_location
*loc
;
2967 if (!is_hardware_watchpoint (bpt
))
2970 if (!breakpoint_enabled (bpt
))
2973 if (bpt
->disposition
== disp_del_at_next_stop
)
2976 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2977 if (!loc
->inserted
&& should_be_inserted (loc
))
2984 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2986 remove_breakpoint (loc
);
2988 hw_breakpoint_error
= 1;
2989 tmp_error_stream
.printf ("Could not insert "
2990 "hardware watchpoint %d.\n",
2998 /* If a hardware breakpoint or watchpoint was inserted, add a
2999 message about possibly exhausted resources. */
3000 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3002 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3003 You may have requested too many hardware breakpoints/watchpoints.\n");
3005 target_terminal::ours_for_output ();
3006 error_stream (tmp_error_stream
);
3010 /* Used when the program stops.
3011 Returns zero if successful, or non-zero if there was a problem
3012 removing a breakpoint location. */
3015 remove_breakpoints (void)
3017 struct bp_location
*bl
, **blp_tmp
;
3020 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3022 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3023 val
|= remove_breakpoint (bl
);
3028 /* When a thread exits, remove breakpoints that are related to
3032 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3034 struct breakpoint
*b
, *b_tmp
;
3036 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3038 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3040 b
->disposition
= disp_del_at_next_stop
;
3042 printf_filtered (_("\
3043 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3044 b
->number
, print_thread_id (tp
));
3046 /* Hide it from the user. */
3052 /* See breakpoint.h. */
3055 remove_breakpoints_inf (inferior
*inf
)
3057 struct bp_location
*bl
, **blp_tmp
;
3060 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3062 if (bl
->pspace
!= inf
->pspace
)
3065 if (bl
->inserted
&& !bl
->target_info
.persist
)
3067 val
= remove_breakpoint (bl
);
3074 static int internal_breakpoint_number
= -1;
3076 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3077 If INTERNAL is non-zero, the breakpoint number will be populated
3078 from internal_breakpoint_number and that variable decremented.
3079 Otherwise the breakpoint number will be populated from
3080 breakpoint_count and that value incremented. Internal breakpoints
3081 do not set the internal var bpnum. */
3083 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3086 b
->number
= internal_breakpoint_number
--;
3089 set_breakpoint_count (breakpoint_count
+ 1);
3090 b
->number
= breakpoint_count
;
3094 static struct breakpoint
*
3095 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3096 CORE_ADDR address
, enum bptype type
,
3097 const struct breakpoint_ops
*ops
)
3099 symtab_and_line sal
;
3101 sal
.section
= find_pc_overlay (sal
.pc
);
3102 sal
.pspace
= current_program_space
;
3104 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3105 b
->number
= internal_breakpoint_number
--;
3106 b
->disposition
= disp_donttouch
;
3111 static const char *const longjmp_names
[] =
3113 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3115 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3117 /* Per-objfile data private to breakpoint.c. */
3118 struct breakpoint_objfile_data
3120 /* Minimal symbol for "_ovly_debug_event" (if any). */
3121 struct bound_minimal_symbol overlay_msym
{};
3123 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3124 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3126 /* True if we have looked for longjmp probes. */
3127 int longjmp_searched
= 0;
3129 /* SystemTap probe points for longjmp (if any). These are non-owning
3131 std::vector
<probe
*> longjmp_probes
;
3133 /* Minimal symbol for "std::terminate()" (if any). */
3134 struct bound_minimal_symbol terminate_msym
{};
3136 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3137 struct bound_minimal_symbol exception_msym
{};
3139 /* True if we have looked for exception probes. */
3140 int exception_searched
= 0;
3142 /* SystemTap probe points for unwinding (if any). These are non-owning
3144 std::vector
<probe
*> exception_probes
;
3147 static const struct objfile_key
<breakpoint_objfile_data
>
3148 breakpoint_objfile_key
;
3150 /* Minimal symbol not found sentinel. */
3151 static struct minimal_symbol msym_not_found
;
3153 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3156 msym_not_found_p (const struct minimal_symbol
*msym
)
3158 return msym
== &msym_not_found
;
3161 /* Return per-objfile data needed by breakpoint.c.
3162 Allocate the data if necessary. */
3164 static struct breakpoint_objfile_data
*
3165 get_breakpoint_objfile_data (struct objfile
*objfile
)
3167 struct breakpoint_objfile_data
*bp_objfile_data
;
3169 bp_objfile_data
= breakpoint_objfile_key
.get (objfile
);
3170 if (bp_objfile_data
== NULL
)
3171 bp_objfile_data
= breakpoint_objfile_key
.emplace (objfile
);
3172 return bp_objfile_data
;
3176 create_overlay_event_breakpoint (void)
3178 const char *const func_name
= "_ovly_debug_event";
3180 for (objfile
*objfile
: current_program_space
->objfiles ())
3182 struct breakpoint
*b
;
3183 struct breakpoint_objfile_data
*bp_objfile_data
;
3185 struct explicit_location explicit_loc
;
3187 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3189 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3192 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3194 struct bound_minimal_symbol m
;
3196 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3197 if (m
.minsym
== NULL
)
3199 /* Avoid future lookups in this objfile. */
3200 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3203 bp_objfile_data
->overlay_msym
= m
;
3206 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3207 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3209 &internal_breakpoint_ops
);
3210 initialize_explicit_location (&explicit_loc
);
3211 explicit_loc
.function_name
= ASTRDUP (func_name
);
3212 b
->location
= new_explicit_location (&explicit_loc
);
3214 if (overlay_debugging
== ovly_auto
)
3216 b
->enable_state
= bp_enabled
;
3217 overlay_events_enabled
= 1;
3221 b
->enable_state
= bp_disabled
;
3222 overlay_events_enabled
= 0;
3228 create_longjmp_master_breakpoint (void)
3230 struct program_space
*pspace
;
3232 scoped_restore_current_program_space restore_pspace
;
3234 ALL_PSPACES (pspace
)
3236 set_current_program_space (pspace
);
3238 for (objfile
*objfile
: current_program_space
->objfiles ())
3241 struct gdbarch
*gdbarch
;
3242 struct breakpoint_objfile_data
*bp_objfile_data
;
3244 gdbarch
= get_objfile_arch (objfile
);
3246 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3248 if (!bp_objfile_data
->longjmp_searched
)
3250 std::vector
<probe
*> ret
3251 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3255 /* We are only interested in checking one element. */
3258 if (!p
->can_evaluate_arguments ())
3260 /* We cannot use the probe interface here, because it does
3261 not know how to evaluate arguments. */
3265 bp_objfile_data
->longjmp_probes
= ret
;
3266 bp_objfile_data
->longjmp_searched
= 1;
3269 if (!bp_objfile_data
->longjmp_probes
.empty ())
3271 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3273 struct breakpoint
*b
;
3275 b
= create_internal_breakpoint (gdbarch
,
3276 p
->get_relocated_address (objfile
),
3278 &internal_breakpoint_ops
);
3279 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3280 b
->enable_state
= bp_disabled
;
3286 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3289 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3291 struct breakpoint
*b
;
3292 const char *func_name
;
3294 struct explicit_location explicit_loc
;
3296 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3299 func_name
= longjmp_names
[i
];
3300 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3302 struct bound_minimal_symbol m
;
3304 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3305 if (m
.minsym
== NULL
)
3307 /* Prevent future lookups in this objfile. */
3308 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3311 bp_objfile_data
->longjmp_msym
[i
] = m
;
3314 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3315 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3316 &internal_breakpoint_ops
);
3317 initialize_explicit_location (&explicit_loc
);
3318 explicit_loc
.function_name
= ASTRDUP (func_name
);
3319 b
->location
= new_explicit_location (&explicit_loc
);
3320 b
->enable_state
= bp_disabled
;
3326 /* Create a master std::terminate breakpoint. */
3328 create_std_terminate_master_breakpoint (void)
3330 struct program_space
*pspace
;
3331 const char *const func_name
= "std::terminate()";
3333 scoped_restore_current_program_space restore_pspace
;
3335 ALL_PSPACES (pspace
)
3339 set_current_program_space (pspace
);
3341 for (objfile
*objfile
: current_program_space
->objfiles ())
3343 struct breakpoint
*b
;
3344 struct breakpoint_objfile_data
*bp_objfile_data
;
3345 struct explicit_location explicit_loc
;
3347 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3349 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3352 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3354 struct bound_minimal_symbol m
;
3356 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3357 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3358 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3360 /* Prevent future lookups in this objfile. */
3361 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3364 bp_objfile_data
->terminate_msym
= m
;
3367 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3368 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3369 bp_std_terminate_master
,
3370 &internal_breakpoint_ops
);
3371 initialize_explicit_location (&explicit_loc
);
3372 explicit_loc
.function_name
= ASTRDUP (func_name
);
3373 b
->location
= new_explicit_location (&explicit_loc
);
3374 b
->enable_state
= bp_disabled
;
3379 /* Install a master breakpoint on the unwinder's debug hook. */
3382 create_exception_master_breakpoint (void)
3384 const char *const func_name
= "_Unwind_DebugHook";
3386 for (objfile
*objfile
: current_program_space
->objfiles ())
3388 struct breakpoint
*b
;
3389 struct gdbarch
*gdbarch
;
3390 struct breakpoint_objfile_data
*bp_objfile_data
;
3392 struct explicit_location explicit_loc
;
3394 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3396 /* We prefer the SystemTap probe point if it exists. */
3397 if (!bp_objfile_data
->exception_searched
)
3399 std::vector
<probe
*> ret
3400 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3404 /* We are only interested in checking one element. */
3407 if (!p
->can_evaluate_arguments ())
3409 /* We cannot use the probe interface here, because it does
3410 not know how to evaluate arguments. */
3414 bp_objfile_data
->exception_probes
= ret
;
3415 bp_objfile_data
->exception_searched
= 1;
3418 if (!bp_objfile_data
->exception_probes
.empty ())
3420 gdbarch
= get_objfile_arch (objfile
);
3422 for (probe
*p
: bp_objfile_data
->exception_probes
)
3424 b
= create_internal_breakpoint (gdbarch
,
3425 p
->get_relocated_address (objfile
),
3426 bp_exception_master
,
3427 &internal_breakpoint_ops
);
3428 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3429 b
->enable_state
= bp_disabled
;
3435 /* Otherwise, try the hook function. */
3437 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3440 gdbarch
= get_objfile_arch (objfile
);
3442 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3444 struct bound_minimal_symbol debug_hook
;
3446 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3447 if (debug_hook
.minsym
== NULL
)
3449 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3453 bp_objfile_data
->exception_msym
= debug_hook
;
3456 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3457 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3458 current_top_target ());
3459 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3460 &internal_breakpoint_ops
);
3461 initialize_explicit_location (&explicit_loc
);
3462 explicit_loc
.function_name
= ASTRDUP (func_name
);
3463 b
->location
= new_explicit_location (&explicit_loc
);
3464 b
->enable_state
= bp_disabled
;
3468 /* Does B have a location spec? */
3471 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3473 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3477 update_breakpoints_after_exec (void)
3479 struct breakpoint
*b
, *b_tmp
;
3480 struct bp_location
*bploc
, **bplocp_tmp
;
3482 /* We're about to delete breakpoints from GDB's lists. If the
3483 INSERTED flag is true, GDB will try to lift the breakpoints by
3484 writing the breakpoints' "shadow contents" back into memory. The
3485 "shadow contents" are NOT valid after an exec, so GDB should not
3486 do that. Instead, the target is responsible from marking
3487 breakpoints out as soon as it detects an exec. We don't do that
3488 here instead, because there may be other attempts to delete
3489 breakpoints after detecting an exec and before reaching here. */
3490 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3491 if (bploc
->pspace
== current_program_space
)
3492 gdb_assert (!bploc
->inserted
);
3494 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3496 if (b
->pspace
!= current_program_space
)
3499 /* Solib breakpoints must be explicitly reset after an exec(). */
3500 if (b
->type
== bp_shlib_event
)
3502 delete_breakpoint (b
);
3506 /* JIT breakpoints must be explicitly reset after an exec(). */
3507 if (b
->type
== bp_jit_event
)
3509 delete_breakpoint (b
);
3513 /* Thread event breakpoints must be set anew after an exec(),
3514 as must overlay event and longjmp master breakpoints. */
3515 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3516 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3517 || b
->type
== bp_exception_master
)
3519 delete_breakpoint (b
);
3523 /* Step-resume breakpoints are meaningless after an exec(). */
3524 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3526 delete_breakpoint (b
);
3530 /* Just like single-step breakpoints. */
3531 if (b
->type
== bp_single_step
)
3533 delete_breakpoint (b
);
3537 /* Longjmp and longjmp-resume breakpoints are also meaningless
3539 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3540 || b
->type
== bp_longjmp_call_dummy
3541 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3543 delete_breakpoint (b
);
3547 if (b
->type
== bp_catchpoint
)
3549 /* For now, none of the bp_catchpoint breakpoints need to
3550 do anything at this point. In the future, if some of
3551 the catchpoints need to something, we will need to add
3552 a new method, and call this method from here. */
3556 /* bp_finish is a special case. The only way we ought to be able
3557 to see one of these when an exec() has happened, is if the user
3558 caught a vfork, and then said "finish". Ordinarily a finish just
3559 carries them to the call-site of the current callee, by setting
3560 a temporary bp there and resuming. But in this case, the finish
3561 will carry them entirely through the vfork & exec.
3563 We don't want to allow a bp_finish to remain inserted now. But
3564 we can't safely delete it, 'cause finish_command has a handle to
3565 the bp on a bpstat, and will later want to delete it. There's a
3566 chance (and I've seen it happen) that if we delete the bp_finish
3567 here, that its storage will get reused by the time finish_command
3568 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3569 We really must allow finish_command to delete a bp_finish.
3571 In the absence of a general solution for the "how do we know
3572 it's safe to delete something others may have handles to?"
3573 problem, what we'll do here is just uninsert the bp_finish, and
3574 let finish_command delete it.
3576 (We know the bp_finish is "doomed" in the sense that it's
3577 momentary, and will be deleted as soon as finish_command sees
3578 the inferior stopped. So it doesn't matter that the bp's
3579 address is probably bogus in the new a.out, unlike e.g., the
3580 solib breakpoints.) */
3582 if (b
->type
== bp_finish
)
3587 /* Without a symbolic address, we have little hope of the
3588 pre-exec() address meaning the same thing in the post-exec()
3590 if (breakpoint_event_location_empty_p (b
))
3592 delete_breakpoint (b
);
3599 detach_breakpoints (ptid_t ptid
)
3601 struct bp_location
*bl
, **blp_tmp
;
3603 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3604 struct inferior
*inf
= current_inferior ();
3606 if (ptid
.pid () == inferior_ptid
.pid ())
3607 error (_("Cannot detach breakpoints of inferior_ptid"));
3609 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3610 inferior_ptid
= ptid
;
3611 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3613 if (bl
->pspace
!= inf
->pspace
)
3616 /* This function must physically remove breakpoints locations
3617 from the specified ptid, without modifying the breakpoint
3618 package's state. Locations of type bp_loc_other are only
3619 maintained at GDB side. So, there is no need to remove
3620 these bp_loc_other locations. Moreover, removing these
3621 would modify the breakpoint package's state. */
3622 if (bl
->loc_type
== bp_loc_other
)
3626 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3632 /* Remove the breakpoint location BL from the current address space.
3633 Note that this is used to detach breakpoints from a child fork.
3634 When we get here, the child isn't in the inferior list, and neither
3635 do we have objects to represent its address space --- we should
3636 *not* look at bl->pspace->aspace here. */
3639 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3643 /* BL is never in moribund_locations by our callers. */
3644 gdb_assert (bl
->owner
!= NULL
);
3646 /* The type of none suggests that owner is actually deleted.
3647 This should not ever happen. */
3648 gdb_assert (bl
->owner
->type
!= bp_none
);
3650 if (bl
->loc_type
== bp_loc_software_breakpoint
3651 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3653 /* "Normal" instruction breakpoint: either the standard
3654 trap-instruction bp (bp_breakpoint), or a
3655 bp_hardware_breakpoint. */
3657 /* First check to see if we have to handle an overlay. */
3658 if (overlay_debugging
== ovly_off
3659 || bl
->section
== NULL
3660 || !(section_is_overlay (bl
->section
)))
3662 /* No overlay handling: just remove the breakpoint. */
3664 /* If we're trying to uninsert a memory breakpoint that we
3665 know is set in a dynamic object that is marked
3666 shlib_disabled, then either the dynamic object was
3667 removed with "remove-symbol-file" or with
3668 "nosharedlibrary". In the former case, we don't know
3669 whether another dynamic object might have loaded over the
3670 breakpoint's address -- the user might well let us know
3671 about it next with add-symbol-file (the whole point of
3672 add-symbol-file is letting the user manually maintain a
3673 list of dynamically loaded objects). If we have the
3674 breakpoint's shadow memory, that is, this is a software
3675 breakpoint managed by GDB, check whether the breakpoint
3676 is still inserted in memory, to avoid overwriting wrong
3677 code with stale saved shadow contents. Note that HW
3678 breakpoints don't have shadow memory, as they're
3679 implemented using a mechanism that is not dependent on
3680 being able to modify the target's memory, and as such
3681 they should always be removed. */
3682 if (bl
->shlib_disabled
3683 && bl
->target_info
.shadow_len
!= 0
3684 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3687 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3691 /* This breakpoint is in an overlay section.
3692 Did we set a breakpoint at the LMA? */
3693 if (!overlay_events_enabled
)
3695 /* Yes -- overlay event support is not active, so we
3696 should have set a breakpoint at the LMA. Remove it.
3698 /* Ignore any failures: if the LMA is in ROM, we will
3699 have already warned when we failed to insert it. */
3700 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3701 target_remove_hw_breakpoint (bl
->gdbarch
,
3702 &bl
->overlay_target_info
);
3704 target_remove_breakpoint (bl
->gdbarch
,
3705 &bl
->overlay_target_info
,
3708 /* Did we set a breakpoint at the VMA?
3709 If so, we will have marked the breakpoint 'inserted'. */
3712 /* Yes -- remove it. Previously we did not bother to
3713 remove the breakpoint if the section had been
3714 unmapped, but let's not rely on that being safe. We
3715 don't know what the overlay manager might do. */
3717 /* However, we should remove *software* breakpoints only
3718 if the section is still mapped, or else we overwrite
3719 wrong code with the saved shadow contents. */
3720 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3721 || section_is_mapped (bl
->section
))
3722 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3728 /* No -- not inserted, so no need to remove. No error. */
3733 /* In some cases, we might not be able to remove a breakpoint in
3734 a shared library that has already been removed, but we have
3735 not yet processed the shlib unload event. Similarly for an
3736 unloaded add-symbol-file object - the user might not yet have
3737 had the chance to remove-symbol-file it. shlib_disabled will
3738 be set if the library/object has already been removed, but
3739 the breakpoint hasn't been uninserted yet, e.g., after
3740 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3741 always-inserted mode. */
3743 && (bl
->loc_type
== bp_loc_software_breakpoint
3744 && (bl
->shlib_disabled
3745 || solib_name_from_address (bl
->pspace
, bl
->address
)
3746 || shared_objfile_contains_address_p (bl
->pspace
,
3752 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3754 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3756 gdb_assert (bl
->owner
->ops
!= NULL
3757 && bl
->owner
->ops
->remove_location
!= NULL
);
3759 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3760 bl
->owner
->ops
->remove_location (bl
, reason
);
3762 /* Failure to remove any of the hardware watchpoints comes here. */
3763 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3764 warning (_("Could not remove hardware watchpoint %d."),
3767 else if (bl
->owner
->type
== bp_catchpoint
3768 && breakpoint_enabled (bl
->owner
)
3771 gdb_assert (bl
->owner
->ops
!= NULL
3772 && bl
->owner
->ops
->remove_location
!= NULL
);
3774 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3778 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3785 remove_breakpoint (struct bp_location
*bl
)
3787 /* BL is never in moribund_locations by our callers. */
3788 gdb_assert (bl
->owner
!= NULL
);
3790 /* The type of none suggests that owner is actually deleted.
3791 This should not ever happen. */
3792 gdb_assert (bl
->owner
->type
!= bp_none
);
3794 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3796 switch_to_program_space_and_thread (bl
->pspace
);
3798 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3801 /* Clear the "inserted" flag in all breakpoints. */
3804 mark_breakpoints_out (void)
3806 struct bp_location
*bl
, **blp_tmp
;
3808 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3809 if (bl
->pspace
== current_program_space
)
3813 /* Clear the "inserted" flag in all breakpoints and delete any
3814 breakpoints which should go away between runs of the program.
3816 Plus other such housekeeping that has to be done for breakpoints
3819 Note: this function gets called at the end of a run (by
3820 generic_mourn_inferior) and when a run begins (by
3821 init_wait_for_inferior). */
3826 breakpoint_init_inferior (enum inf_context context
)
3828 struct breakpoint
*b
, *b_tmp
;
3829 struct program_space
*pspace
= current_program_space
;
3831 /* If breakpoint locations are shared across processes, then there's
3833 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3836 mark_breakpoints_out ();
3838 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3840 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3846 case bp_longjmp_call_dummy
:
3848 /* If the call dummy breakpoint is at the entry point it will
3849 cause problems when the inferior is rerun, so we better get
3852 case bp_watchpoint_scope
:
3854 /* Also get rid of scope breakpoints. */
3856 case bp_shlib_event
:
3858 /* Also remove solib event breakpoints. Their addresses may
3859 have changed since the last time we ran the program.
3860 Actually we may now be debugging against different target;
3861 and so the solib backend that installed this breakpoint may
3862 not be used in by the target. E.g.,
3864 (gdb) file prog-linux
3865 (gdb) run # native linux target
3868 (gdb) file prog-win.exe
3869 (gdb) tar rem :9999 # remote Windows gdbserver.
3872 case bp_step_resume
:
3874 /* Also remove step-resume breakpoints. */
3876 case bp_single_step
:
3878 /* Also remove single-step breakpoints. */
3880 delete_breakpoint (b
);
3884 case bp_hardware_watchpoint
:
3885 case bp_read_watchpoint
:
3886 case bp_access_watchpoint
:
3888 struct watchpoint
*w
= (struct watchpoint
*) b
;
3890 /* Likewise for watchpoints on local expressions. */
3891 if (w
->exp_valid_block
!= NULL
)
3892 delete_breakpoint (b
);
3895 /* Get rid of existing locations, which are no longer
3896 valid. New ones will be created in
3897 update_watchpoint, when the inferior is restarted.
3898 The next update_global_location_list call will
3899 garbage collect them. */
3902 if (context
== inf_starting
)
3904 /* Reset val field to force reread of starting value in
3905 insert_breakpoints. */
3906 w
->val
.reset (nullptr);
3917 /* Get rid of the moribund locations. */
3918 for (bp_location
*bl
: moribund_locations
)
3919 decref_bp_location (&bl
);
3920 moribund_locations
.clear ();
3923 /* These functions concern about actual breakpoints inserted in the
3924 target --- to e.g. check if we need to do decr_pc adjustment or if
3925 we need to hop over the bkpt --- so we check for address space
3926 match, not program space. */
3928 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
3929 exists at PC. It returns ordinary_breakpoint_here if it's an
3930 ordinary breakpoint, or permanent_breakpoint_here if it's a
3931 permanent breakpoint.
3932 - When continuing from a location with an ordinary breakpoint, we
3933 actually single step once before calling insert_breakpoints.
3934 - When continuing from a location with a permanent breakpoint, we
3935 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
3936 the target, to advance the PC past the breakpoint. */
3938 enum breakpoint_here
3939 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
3941 struct bp_location
*bl
, **blp_tmp
;
3942 int any_breakpoint_here
= 0;
3944 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3946 if (bl
->loc_type
!= bp_loc_software_breakpoint
3947 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3950 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
3951 if ((breakpoint_enabled (bl
->owner
)
3953 && breakpoint_location_address_match (bl
, aspace
, pc
))
3955 if (overlay_debugging
3956 && section_is_overlay (bl
->section
)
3957 && !section_is_mapped (bl
->section
))
3958 continue; /* unmapped overlay -- can't be a match */
3959 else if (bl
->permanent
)
3960 return permanent_breakpoint_here
;
3962 any_breakpoint_here
= 1;
3966 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
3969 /* See breakpoint.h. */
3972 breakpoint_in_range_p (const address_space
*aspace
,
3973 CORE_ADDR addr
, ULONGEST len
)
3975 struct bp_location
*bl
, **blp_tmp
;
3977 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3979 if (bl
->loc_type
!= bp_loc_software_breakpoint
3980 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
3983 if ((breakpoint_enabled (bl
->owner
)
3985 && breakpoint_location_address_range_overlap (bl
, aspace
,
3988 if (overlay_debugging
3989 && section_is_overlay (bl
->section
)
3990 && !section_is_mapped (bl
->section
))
3992 /* Unmapped overlay -- can't be a match. */
4003 /* Return true if there's a moribund breakpoint at PC. */
4006 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4008 for (bp_location
*loc
: moribund_locations
)
4009 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4015 /* Returns non-zero iff BL is inserted at PC, in address space
4019 bp_location_inserted_here_p (struct bp_location
*bl
,
4020 const address_space
*aspace
, CORE_ADDR pc
)
4023 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4026 if (overlay_debugging
4027 && section_is_overlay (bl
->section
)
4028 && !section_is_mapped (bl
->section
))
4029 return 0; /* unmapped overlay -- can't be a match */
4036 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4039 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4041 struct bp_location
**blp
, **blp_tmp
= NULL
;
4043 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4045 struct bp_location
*bl
= *blp
;
4047 if (bl
->loc_type
!= bp_loc_software_breakpoint
4048 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4051 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4057 /* This function returns non-zero iff there is a software breakpoint
4061 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4064 struct bp_location
**blp
, **blp_tmp
= NULL
;
4066 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4068 struct bp_location
*bl
= *blp
;
4070 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4073 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4080 /* See breakpoint.h. */
4083 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4086 struct bp_location
**blp
, **blp_tmp
= NULL
;
4088 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4090 struct bp_location
*bl
= *blp
;
4092 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4095 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4103 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4104 CORE_ADDR addr
, ULONGEST len
)
4106 struct breakpoint
*bpt
;
4108 ALL_BREAKPOINTS (bpt
)
4110 struct bp_location
*loc
;
4112 if (bpt
->type
!= bp_hardware_watchpoint
4113 && bpt
->type
!= bp_access_watchpoint
)
4116 if (!breakpoint_enabled (bpt
))
4119 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4120 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4124 /* Check for intersection. */
4125 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4126 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4135 /* bpstat stuff. External routines' interfaces are documented
4139 is_catchpoint (struct breakpoint
*ep
)
4141 return (ep
->type
== bp_catchpoint
);
4144 /* Frees any storage that is part of a bpstat. Does not walk the
4147 bpstats::~bpstats ()
4149 if (bp_location_at
!= NULL
)
4150 decref_bp_location (&bp_location_at
);
4153 /* Clear a bpstat so that it says we are not at any breakpoint.
4154 Also free any storage that is part of a bpstat. */
4157 bpstat_clear (bpstat
*bsp
)
4174 bpstats::bpstats (const bpstats
&other
)
4176 bp_location_at (other
.bp_location_at
),
4177 breakpoint_at (other
.breakpoint_at
),
4178 commands (other
.commands
),
4179 print (other
.print
),
4181 print_it (other
.print_it
)
4183 if (other
.old_val
!= NULL
)
4184 old_val
= release_value (value_copy (other
.old_val
.get ()));
4185 incref_bp_location (bp_location_at
);
4188 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4189 is part of the bpstat is copied as well. */
4192 bpstat_copy (bpstat bs
)
4196 bpstat retval
= NULL
;
4201 for (; bs
!= NULL
; bs
= bs
->next
)
4203 tmp
= new bpstats (*bs
);
4206 /* This is the first thing in the chain. */
4216 /* Find the bpstat associated with this breakpoint. */
4219 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4224 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4226 if (bsp
->breakpoint_at
== breakpoint
)
4232 /* See breakpoint.h. */
4235 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4237 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4239 if (bsp
->breakpoint_at
== NULL
)
4241 /* A moribund location can never explain a signal other than
4243 if (sig
== GDB_SIGNAL_TRAP
)
4248 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4257 /* Put in *NUM the breakpoint number of the first breakpoint we are
4258 stopped at. *BSP upon return is a bpstat which points to the
4259 remaining breakpoints stopped at (but which is not guaranteed to be
4260 good for anything but further calls to bpstat_num).
4262 Return 0 if passed a bpstat which does not indicate any breakpoints.
4263 Return -1 if stopped at a breakpoint that has been deleted since
4265 Return 1 otherwise. */
4268 bpstat_num (bpstat
*bsp
, int *num
)
4270 struct breakpoint
*b
;
4273 return 0; /* No more breakpoint values */
4275 /* We assume we'll never have several bpstats that correspond to a
4276 single breakpoint -- otherwise, this function might return the
4277 same number more than once and this will look ugly. */
4278 b
= (*bsp
)->breakpoint_at
;
4279 *bsp
= (*bsp
)->next
;
4281 return -1; /* breakpoint that's been deleted since */
4283 *num
= b
->number
; /* We have its number */
4287 /* See breakpoint.h. */
4290 bpstat_clear_actions (void)
4294 if (inferior_ptid
== null_ptid
)
4297 thread_info
*tp
= inferior_thread ();
4298 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4300 bs
->commands
= NULL
;
4301 bs
->old_val
.reset (nullptr);
4305 /* Called when a command is about to proceed the inferior. */
4308 breakpoint_about_to_proceed (void)
4310 if (inferior_ptid
!= null_ptid
)
4312 struct thread_info
*tp
= inferior_thread ();
4314 /* Allow inferior function calls in breakpoint commands to not
4315 interrupt the command list. When the call finishes
4316 successfully, the inferior will be standing at the same
4317 breakpoint as if nothing happened. */
4318 if (tp
->control
.in_infcall
)
4322 breakpoint_proceeded
= 1;
4325 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4326 or its equivalent. */
4329 command_line_is_silent (struct command_line
*cmd
)
4331 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4334 /* Execute all the commands associated with all the breakpoints at
4335 this location. Any of these commands could cause the process to
4336 proceed beyond this point, etc. We look out for such changes by
4337 checking the global "breakpoint_proceeded" after each command.
4339 Returns true if a breakpoint command resumed the inferior. In that
4340 case, it is the caller's responsibility to recall it again with the
4341 bpstat of the current thread. */
4344 bpstat_do_actions_1 (bpstat
*bsp
)
4349 /* Avoid endless recursion if a `source' command is contained
4351 if (executing_breakpoint_commands
)
4354 scoped_restore save_executing
4355 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4357 scoped_restore preventer
= prevent_dont_repeat ();
4359 /* This pointer will iterate over the list of bpstat's. */
4362 breakpoint_proceeded
= 0;
4363 for (; bs
!= NULL
; bs
= bs
->next
)
4365 struct command_line
*cmd
= NULL
;
4367 /* Take ownership of the BSP's command tree, if it has one.
4369 The command tree could legitimately contain commands like
4370 'step' and 'next', which call clear_proceed_status, which
4371 frees stop_bpstat's command tree. To make sure this doesn't
4372 free the tree we're executing out from under us, we need to
4373 take ownership of the tree ourselves. Since a given bpstat's
4374 commands are only executed once, we don't need to copy it; we
4375 can clear the pointer in the bpstat, and make sure we free
4376 the tree when we're done. */
4377 counted_command_line ccmd
= bs
->commands
;
4378 bs
->commands
= NULL
;
4381 if (command_line_is_silent (cmd
))
4383 /* The action has been already done by bpstat_stop_status. */
4389 execute_control_command (cmd
);
4391 if (breakpoint_proceeded
)
4397 if (breakpoint_proceeded
)
4399 if (current_ui
->async
)
4400 /* If we are in async mode, then the target might be still
4401 running, not stopped at any breakpoint, so nothing for
4402 us to do here -- just return to the event loop. */
4405 /* In sync mode, when execute_control_command returns
4406 we're already standing on the next breakpoint.
4407 Breakpoint commands for that stop were not run, since
4408 execute_command does not run breakpoint commands --
4409 only command_line_handler does, but that one is not
4410 involved in execution of breakpoint commands. So, we
4411 can now execute breakpoint commands. It should be
4412 noted that making execute_command do bpstat actions is
4413 not an option -- in this case we'll have recursive
4414 invocation of bpstat for each breakpoint with a
4415 command, and can easily blow up GDB stack. Instead, we
4416 return true, which will trigger the caller to recall us
4417 with the new stop_bpstat. */
4425 /* Helper for bpstat_do_actions. Get the current thread, if there's
4426 one, is alive and has execution. Return NULL otherwise. */
4428 static thread_info
*
4429 get_bpstat_thread ()
4431 if (inferior_ptid
== null_ptid
|| !target_has_execution
)
4434 thread_info
*tp
= inferior_thread ();
4435 if (tp
->state
== THREAD_EXITED
|| tp
->executing
)
4441 bpstat_do_actions (void)
4443 auto cleanup_if_error
= make_scope_exit (bpstat_clear_actions
);
4446 /* Do any commands attached to breakpoint we are stopped at. */
4447 while ((tp
= get_bpstat_thread ()) != NULL
)
4449 /* Since in sync mode, bpstat_do_actions may resume the
4450 inferior, and only return when it is stopped at the next
4451 breakpoint, we keep doing breakpoint actions until it returns
4452 false to indicate the inferior was not resumed. */
4453 if (!bpstat_do_actions_1 (&tp
->control
.stop_bpstat
))
4457 cleanup_if_error
.release ();
4460 /* Print out the (old or new) value associated with a watchpoint. */
4463 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4466 fprintf_unfiltered (stream
, _("<unreadable>"));
4469 struct value_print_options opts
;
4470 get_user_print_options (&opts
);
4471 value_print (val
, stream
, &opts
);
4475 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4476 debugging multiple threads. */
4479 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4481 if (uiout
->is_mi_like_p ())
4486 if (show_thread_that_caused_stop ())
4489 struct thread_info
*thr
= inferior_thread ();
4491 uiout
->text ("Thread ");
4492 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4494 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4497 uiout
->text (" \"");
4498 uiout
->field_fmt ("name", "%s", name
);
4502 uiout
->text (" hit ");
4506 /* Generic routine for printing messages indicating why we
4507 stopped. The behavior of this function depends on the value
4508 'print_it' in the bpstat structure. Under some circumstances we
4509 may decide not to print anything here and delegate the task to
4512 static enum print_stop_action
4513 print_bp_stop_message (bpstat bs
)
4515 switch (bs
->print_it
)
4518 /* Nothing should be printed for this bpstat entry. */
4519 return PRINT_UNKNOWN
;
4523 /* We still want to print the frame, but we already printed the
4524 relevant messages. */
4525 return PRINT_SRC_AND_LOC
;
4528 case print_it_normal
:
4530 struct breakpoint
*b
= bs
->breakpoint_at
;
4532 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4533 which has since been deleted. */
4535 return PRINT_UNKNOWN
;
4537 /* Normal case. Call the breakpoint's print_it method. */
4538 return b
->ops
->print_it (bs
);
4543 internal_error (__FILE__
, __LINE__
,
4544 _("print_bp_stop_message: unrecognized enum value"));
4549 /* A helper function that prints a shared library stopped event. */
4552 print_solib_event (int is_catchpoint
)
4554 bool any_deleted
= !current_program_space
->deleted_solibs
.empty ();
4555 bool any_added
= !current_program_space
->added_solibs
.empty ();
4559 if (any_added
|| any_deleted
)
4560 current_uiout
->text (_("Stopped due to shared library event:\n"));
4562 current_uiout
->text (_("Stopped due to shared library event (no "
4563 "libraries added or removed)\n"));
4566 if (current_uiout
->is_mi_like_p ())
4567 current_uiout
->field_string ("reason",
4568 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4572 current_uiout
->text (_(" Inferior unloaded "));
4573 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4574 for (int ix
= 0; ix
< current_program_space
->deleted_solibs
.size (); ix
++)
4576 const std::string
&name
= current_program_space
->deleted_solibs
[ix
];
4579 current_uiout
->text (" ");
4580 current_uiout
->field_string ("library", name
);
4581 current_uiout
->text ("\n");
4587 current_uiout
->text (_(" Inferior loaded "));
4588 ui_out_emit_list
list_emitter (current_uiout
, "added");
4590 for (so_list
*iter
: current_program_space
->added_solibs
)
4593 current_uiout
->text (" ");
4595 current_uiout
->field_string ("library", iter
->so_name
);
4596 current_uiout
->text ("\n");
4601 /* Print a message indicating what happened. This is called from
4602 normal_stop(). The input to this routine is the head of the bpstat
4603 list - a list of the eventpoints that caused this stop. KIND is
4604 the target_waitkind for the stopping event. This
4605 routine calls the generic print routine for printing a message
4606 about reasons for stopping. This will print (for example) the
4607 "Breakpoint n," part of the output. The return value of this
4610 PRINT_UNKNOWN: Means we printed nothing.
4611 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4612 code to print the location. An example is
4613 "Breakpoint 1, " which should be followed by
4615 PRINT_SRC_ONLY: Means we printed something, but there is no need
4616 to also print the location part of the message.
4617 An example is the catch/throw messages, which
4618 don't require a location appended to the end.
4619 PRINT_NOTHING: We have done some printing and we don't need any
4620 further info to be printed. */
4622 enum print_stop_action
4623 bpstat_print (bpstat bs
, int kind
)
4625 enum print_stop_action val
;
4627 /* Maybe another breakpoint in the chain caused us to stop.
4628 (Currently all watchpoints go on the bpstat whether hit or not.
4629 That probably could (should) be changed, provided care is taken
4630 with respect to bpstat_explains_signal). */
4631 for (; bs
; bs
= bs
->next
)
4633 val
= print_bp_stop_message (bs
);
4634 if (val
== PRINT_SRC_ONLY
4635 || val
== PRINT_SRC_AND_LOC
4636 || val
== PRINT_NOTHING
)
4640 /* If we had hit a shared library event breakpoint,
4641 print_bp_stop_message would print out this message. If we hit an
4642 OS-level shared library event, do the same thing. */
4643 if (kind
== TARGET_WAITKIND_LOADED
)
4645 print_solib_event (0);
4646 return PRINT_NOTHING
;
4649 /* We reached the end of the chain, or we got a null BS to start
4650 with and nothing was printed. */
4651 return PRINT_UNKNOWN
;
4654 /* Evaluate the boolean expression EXP and return the result. */
4657 breakpoint_cond_eval (expression
*exp
)
4659 struct value
*mark
= value_mark ();
4660 bool res
= value_true (evaluate_expression (exp
));
4662 value_free_to_mark (mark
);
4666 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4668 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4670 bp_location_at (bl
),
4671 breakpoint_at (bl
->owner
),
4675 print_it (print_it_normal
)
4677 incref_bp_location (bl
);
4678 **bs_link_pointer
= this;
4679 *bs_link_pointer
= &next
;
4684 bp_location_at (NULL
),
4685 breakpoint_at (NULL
),
4689 print_it (print_it_normal
)
4693 /* The target has stopped with waitstatus WS. Check if any hardware
4694 watchpoints have triggered, according to the target. */
4697 watchpoints_triggered (struct target_waitstatus
*ws
)
4699 bool stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4701 struct breakpoint
*b
;
4703 if (!stopped_by_watchpoint
)
4705 /* We were not stopped by a watchpoint. Mark all watchpoints
4706 as not triggered. */
4708 if (is_hardware_watchpoint (b
))
4710 struct watchpoint
*w
= (struct watchpoint
*) b
;
4712 w
->watchpoint_triggered
= watch_triggered_no
;
4718 if (!target_stopped_data_address (current_top_target (), &addr
))
4720 /* We were stopped by a watchpoint, but we don't know where.
4721 Mark all watchpoints as unknown. */
4723 if (is_hardware_watchpoint (b
))
4725 struct watchpoint
*w
= (struct watchpoint
*) b
;
4727 w
->watchpoint_triggered
= watch_triggered_unknown
;
4733 /* The target could report the data address. Mark watchpoints
4734 affected by this data address as triggered, and all others as not
4738 if (is_hardware_watchpoint (b
))
4740 struct watchpoint
*w
= (struct watchpoint
*) b
;
4741 struct bp_location
*loc
;
4743 w
->watchpoint_triggered
= watch_triggered_no
;
4744 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4746 if (is_masked_watchpoint (b
))
4748 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4749 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4751 if (newaddr
== start
)
4753 w
->watchpoint_triggered
= watch_triggered_yes
;
4757 /* Exact match not required. Within range is sufficient. */
4758 else if (target_watchpoint_addr_within_range (current_top_target (),
4762 w
->watchpoint_triggered
= watch_triggered_yes
;
4771 /* Possible return values for watchpoint_check. */
4772 enum wp_check_result
4774 /* The watchpoint has been deleted. */
4777 /* The value has changed. */
4778 WP_VALUE_CHANGED
= 2,
4780 /* The value has not changed. */
4781 WP_VALUE_NOT_CHANGED
= 3,
4783 /* Ignore this watchpoint, no matter if the value changed or not. */
4787 #define BP_TEMPFLAG 1
4788 #define BP_HARDWAREFLAG 2
4790 /* Evaluate watchpoint condition expression and check if its value
4793 static wp_check_result
4794 watchpoint_check (bpstat bs
)
4796 struct watchpoint
*b
;
4797 struct frame_info
*fr
;
4798 int within_current_scope
;
4800 /* BS is built from an existing struct breakpoint. */
4801 gdb_assert (bs
->breakpoint_at
!= NULL
);
4802 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4804 /* If this is a local watchpoint, we only want to check if the
4805 watchpoint frame is in scope if the current thread is the thread
4806 that was used to create the watchpoint. */
4807 if (!watchpoint_in_thread_scope (b
))
4810 if (b
->exp_valid_block
== NULL
)
4811 within_current_scope
= 1;
4814 struct frame_info
*frame
= get_current_frame ();
4815 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4816 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4818 /* stack_frame_destroyed_p() returns a non-zero value if we're
4819 still in the function but the stack frame has already been
4820 invalidated. Since we can't rely on the values of local
4821 variables after the stack has been destroyed, we are treating
4822 the watchpoint in that state as `not changed' without further
4823 checking. Don't mark watchpoints as changed if the current
4824 frame is in an epilogue - even if they are in some other
4825 frame, our view of the stack is likely to be wrong and
4826 frame_find_by_id could error out. */
4827 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4830 fr
= frame_find_by_id (b
->watchpoint_frame
);
4831 within_current_scope
= (fr
!= NULL
);
4833 /* If we've gotten confused in the unwinder, we might have
4834 returned a frame that can't describe this variable. */
4835 if (within_current_scope
)
4837 struct symbol
*function
;
4839 function
= get_frame_function (fr
);
4840 if (function
== NULL
4841 || !contained_in (b
->exp_valid_block
,
4842 SYMBOL_BLOCK_VALUE (function
)))
4843 within_current_scope
= 0;
4846 if (within_current_scope
)
4847 /* If we end up stopping, the current frame will get selected
4848 in normal_stop. So this call to select_frame won't affect
4853 if (within_current_scope
)
4855 /* We use value_{,free_to_}mark because it could be a *long*
4856 time before we return to the command level and call
4857 free_all_values. We can't call free_all_values because we
4858 might be in the middle of evaluating a function call. */
4862 struct value
*new_val
;
4864 if (is_masked_watchpoint (b
))
4865 /* Since we don't know the exact trigger address (from
4866 stopped_data_address), just tell the user we've triggered
4867 a mask watchpoint. */
4868 return WP_VALUE_CHANGED
;
4870 mark
= value_mark ();
4871 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
4873 if (b
->val_bitsize
!= 0)
4874 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4876 /* We use value_equal_contents instead of value_equal because
4877 the latter coerces an array to a pointer, thus comparing just
4878 the address of the array instead of its contents. This is
4879 not what we want. */
4880 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4881 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
.get (),
4884 bs
->old_val
= b
->val
;
4885 b
->val
= release_value (new_val
);
4887 if (new_val
!= NULL
)
4888 value_free_to_mark (mark
);
4889 return WP_VALUE_CHANGED
;
4893 /* Nothing changed. */
4894 value_free_to_mark (mark
);
4895 return WP_VALUE_NOT_CHANGED
;
4900 /* This seems like the only logical thing to do because
4901 if we temporarily ignored the watchpoint, then when
4902 we reenter the block in which it is valid it contains
4903 garbage (in the case of a function, it may have two
4904 garbage values, one before and one after the prologue).
4905 So we can't even detect the first assignment to it and
4906 watch after that (since the garbage may or may not equal
4907 the first value assigned). */
4908 /* We print all the stop information in
4909 breakpoint_ops->print_it, but in this case, by the time we
4910 call breakpoint_ops->print_it this bp will be deleted
4911 already. So we have no choice but print the information
4914 SWITCH_THRU_ALL_UIS ()
4916 struct ui_out
*uiout
= current_uiout
;
4918 if (uiout
->is_mi_like_p ())
4920 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
4921 uiout
->text ("\nWatchpoint ");
4922 uiout
->field_int ("wpnum", b
->number
);
4923 uiout
->text (" deleted because the program has left the block in\n"
4924 "which its expression is valid.\n");
4927 /* Make sure the watchpoint's commands aren't executed. */
4929 watchpoint_del_at_next_stop (b
);
4935 /* Return true if it looks like target has stopped due to hitting
4936 breakpoint location BL. This function does not check if we should
4937 stop, only if BL explains the stop. */
4940 bpstat_check_location (const struct bp_location
*bl
,
4941 const address_space
*aspace
, CORE_ADDR bp_addr
,
4942 const struct target_waitstatus
*ws
)
4944 struct breakpoint
*b
= bl
->owner
;
4946 /* BL is from an existing breakpoint. */
4947 gdb_assert (b
!= NULL
);
4949 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
4952 /* Determine if the watched values have actually changed, and we
4953 should stop. If not, set BS->stop to 0. */
4956 bpstat_check_watchpoint (bpstat bs
)
4958 const struct bp_location
*bl
;
4959 struct watchpoint
*b
;
4961 /* BS is built for existing struct breakpoint. */
4962 bl
= bs
->bp_location_at
;
4963 gdb_assert (bl
!= NULL
);
4964 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4965 gdb_assert (b
!= NULL
);
4968 int must_check_value
= 0;
4970 if (b
->type
== bp_watchpoint
)
4971 /* For a software watchpoint, we must always check the
4973 must_check_value
= 1;
4974 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
4975 /* We have a hardware watchpoint (read, write, or access)
4976 and the target earlier reported an address watched by
4978 must_check_value
= 1;
4979 else if (b
->watchpoint_triggered
== watch_triggered_unknown
4980 && b
->type
== bp_hardware_watchpoint
)
4981 /* We were stopped by a hardware watchpoint, but the target could
4982 not report the data address. We must check the watchpoint's
4983 value. Access and read watchpoints are out of luck; without
4984 a data address, we can't figure it out. */
4985 must_check_value
= 1;
4987 if (must_check_value
)
4993 e
= watchpoint_check (bs
);
4995 catch (const gdb_exception
&ex
)
4997 exception_fprintf (gdb_stderr
, ex
,
4998 "Error evaluating expression "
4999 "for watchpoint %d\n",
5002 SWITCH_THRU_ALL_UIS ()
5004 printf_filtered (_("Watchpoint %d deleted.\n"),
5007 watchpoint_del_at_next_stop (b
);
5014 /* We've already printed what needs to be printed. */
5015 bs
->print_it
= print_it_done
;
5019 bs
->print_it
= print_it_noop
;
5022 case WP_VALUE_CHANGED
:
5023 if (b
->type
== bp_read_watchpoint
)
5025 /* There are two cases to consider here:
5027 1. We're watching the triggered memory for reads.
5028 In that case, trust the target, and always report
5029 the watchpoint hit to the user. Even though
5030 reads don't cause value changes, the value may
5031 have changed since the last time it was read, and
5032 since we're not trapping writes, we will not see
5033 those, and as such we should ignore our notion of
5036 2. We're watching the triggered memory for both
5037 reads and writes. There are two ways this may
5040 2.1. This is a target that can't break on data
5041 reads only, but can break on accesses (reads or
5042 writes), such as e.g., x86. We detect this case
5043 at the time we try to insert read watchpoints.
5045 2.2. Otherwise, the target supports read
5046 watchpoints, but, the user set an access or write
5047 watchpoint watching the same memory as this read
5050 If we're watching memory writes as well as reads,
5051 ignore watchpoint hits when we find that the
5052 value hasn't changed, as reads don't cause
5053 changes. This still gives false positives when
5054 the program writes the same value to memory as
5055 what there was already in memory (we will confuse
5056 it for a read), but it's much better than
5059 int other_write_watchpoint
= 0;
5061 if (bl
->watchpoint_type
== hw_read
)
5063 struct breakpoint
*other_b
;
5065 ALL_BREAKPOINTS (other_b
)
5066 if (other_b
->type
== bp_hardware_watchpoint
5067 || other_b
->type
== bp_access_watchpoint
)
5069 struct watchpoint
*other_w
=
5070 (struct watchpoint
*) other_b
;
5072 if (other_w
->watchpoint_triggered
5073 == watch_triggered_yes
)
5075 other_write_watchpoint
= 1;
5081 if (other_write_watchpoint
5082 || bl
->watchpoint_type
== hw_access
)
5084 /* We're watching the same memory for writes,
5085 and the value changed since the last time we
5086 updated it, so this trap must be for a write.
5088 bs
->print_it
= print_it_noop
;
5093 case WP_VALUE_NOT_CHANGED
:
5094 if (b
->type
== bp_hardware_watchpoint
5095 || b
->type
== bp_watchpoint
)
5097 /* Don't stop: write watchpoints shouldn't fire if
5098 the value hasn't changed. */
5099 bs
->print_it
= print_it_noop
;
5109 else /* must_check_value == 0 */
5111 /* This is a case where some watchpoint(s) triggered, but
5112 not at the address of this watchpoint, or else no
5113 watchpoint triggered after all. So don't print
5114 anything for this watchpoint. */
5115 bs
->print_it
= print_it_noop
;
5121 /* For breakpoints that are currently marked as telling gdb to stop,
5122 check conditions (condition proper, frame, thread and ignore count)
5123 of breakpoint referred to by BS. If we should not stop for this
5124 breakpoint, set BS->stop to 0. */
5127 bpstat_check_breakpoint_conditions (bpstat bs
, thread_info
*thread
)
5129 const struct bp_location
*bl
;
5130 struct breakpoint
*b
;
5132 bool condition_result
= true;
5133 struct expression
*cond
;
5135 gdb_assert (bs
->stop
);
5137 /* BS is built for existing struct breakpoint. */
5138 bl
= bs
->bp_location_at
;
5139 gdb_assert (bl
!= NULL
);
5140 b
= bs
->breakpoint_at
;
5141 gdb_assert (b
!= NULL
);
5143 /* Even if the target evaluated the condition on its end and notified GDB, we
5144 need to do so again since GDB does not know if we stopped due to a
5145 breakpoint or a single step breakpoint. */
5147 if (frame_id_p (b
->frame_id
)
5148 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5154 /* If this is a thread/task-specific breakpoint, don't waste cpu
5155 evaluating the condition if this isn't the specified
5157 if ((b
->thread
!= -1 && b
->thread
!= thread
->global_num
)
5158 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (thread
)))
5164 /* Evaluate extension language breakpoints that have a "stop" method
5166 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5168 if (is_watchpoint (b
))
5170 struct watchpoint
*w
= (struct watchpoint
*) b
;
5172 cond
= w
->cond_exp
.get ();
5175 cond
= bl
->cond
.get ();
5177 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5179 int within_current_scope
= 1;
5180 struct watchpoint
* w
;
5182 /* We use value_mark and value_free_to_mark because it could
5183 be a long time before we return to the command level and
5184 call free_all_values. We can't call free_all_values
5185 because we might be in the middle of evaluating a
5187 struct value
*mark
= value_mark ();
5189 if (is_watchpoint (b
))
5190 w
= (struct watchpoint
*) b
;
5194 /* Need to select the frame, with all that implies so that
5195 the conditions will have the right context. Because we
5196 use the frame, we will not see an inlined function's
5197 variables when we arrive at a breakpoint at the start
5198 of the inlined function; the current frame will be the
5200 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5201 select_frame (get_current_frame ());
5204 struct frame_info
*frame
;
5206 /* For local watchpoint expressions, which particular
5207 instance of a local is being watched matters, so we
5208 keep track of the frame to evaluate the expression
5209 in. To evaluate the condition however, it doesn't
5210 really matter which instantiation of the function
5211 where the condition makes sense triggers the
5212 watchpoint. This allows an expression like "watch
5213 global if q > 10" set in `func', catch writes to
5214 global on all threads that call `func', or catch
5215 writes on all recursive calls of `func' by a single
5216 thread. We simply always evaluate the condition in
5217 the innermost frame that's executing where it makes
5218 sense to evaluate the condition. It seems
5220 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5222 select_frame (frame
);
5224 within_current_scope
= 0;
5226 if (within_current_scope
)
5230 condition_result
= breakpoint_cond_eval (cond
);
5232 catch (const gdb_exception
&ex
)
5234 exception_fprintf (gdb_stderr
, ex
,
5235 "Error in testing breakpoint condition:\n");
5240 warning (_("Watchpoint condition cannot be tested "
5241 "in the current scope"));
5242 /* If we failed to set the right context for this
5243 watchpoint, unconditionally report it. */
5245 /* FIXME-someday, should give breakpoint #. */
5246 value_free_to_mark (mark
);
5249 if (cond
&& !condition_result
)
5253 else if (b
->ignore_count
> 0)
5257 /* Increase the hit count even though we don't stop. */
5259 gdb::observers::breakpoint_modified
.notify (b
);
5263 /* Returns true if we need to track moribund locations of LOC's type
5264 on the current target. */
5267 need_moribund_for_location_type (struct bp_location
*loc
)
5269 return ((loc
->loc_type
== bp_loc_software_breakpoint
5270 && !target_supports_stopped_by_sw_breakpoint ())
5271 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5272 && !target_supports_stopped_by_hw_breakpoint ()));
5275 /* See breakpoint.h. */
5278 build_bpstat_chain (const address_space
*aspace
, CORE_ADDR bp_addr
,
5279 const struct target_waitstatus
*ws
)
5281 struct breakpoint
*b
;
5282 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5286 if (!breakpoint_enabled (b
))
5289 for (bp_location
*bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5291 /* For hardware watchpoints, we look only at the first
5292 location. The watchpoint_check function will work on the
5293 entire expression, not the individual locations. For
5294 read watchpoints, the watchpoints_triggered function has
5295 checked all locations already. */
5296 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5299 if (!bl
->enabled
|| bl
->shlib_disabled
)
5302 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5305 /* Come here if it's a watchpoint, or if the break address
5308 bpstat bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5311 /* Assume we stop. Should we find a watchpoint that is not
5312 actually triggered, or if the condition of the breakpoint
5313 evaluates as false, we'll reset 'stop' to 0. */
5317 /* If this is a scope breakpoint, mark the associated
5318 watchpoint as triggered so that we will handle the
5319 out-of-scope event. We'll get to the watchpoint next
5321 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5323 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5325 w
->watchpoint_triggered
= watch_triggered_yes
;
5330 /* Check if a moribund breakpoint explains the stop. */
5331 if (!target_supports_stopped_by_sw_breakpoint ()
5332 || !target_supports_stopped_by_hw_breakpoint ())
5334 for (bp_location
*loc
: moribund_locations
)
5336 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5337 && need_moribund_for_location_type (loc
))
5339 bpstat bs
= new bpstats (loc
, &bs_link
);
5340 /* For hits of moribund locations, we should just proceed. */
5343 bs
->print_it
= print_it_noop
;
5351 /* See breakpoint.h. */
5354 bpstat_stop_status (const address_space
*aspace
,
5355 CORE_ADDR bp_addr
, thread_info
*thread
,
5356 const struct target_waitstatus
*ws
,
5359 struct breakpoint
*b
= NULL
;
5360 /* First item of allocated bpstat's. */
5361 bpstat bs_head
= stop_chain
;
5363 int need_remove_insert
;
5366 /* First, build the bpstat chain with locations that explain a
5367 target stop, while being careful to not set the target running,
5368 as that may invalidate locations (in particular watchpoint
5369 locations are recreated). Resuming will happen here with
5370 breakpoint conditions or watchpoint expressions that include
5371 inferior function calls. */
5372 if (bs_head
== NULL
)
5373 bs_head
= build_bpstat_chain (aspace
, bp_addr
, ws
);
5375 /* A bit of special processing for shlib breakpoints. We need to
5376 process solib loading here, so that the lists of loaded and
5377 unloaded libraries are correct before we handle "catch load" and
5379 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5381 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5383 handle_solib_event ();
5388 /* Now go through the locations that caused the target to stop, and
5389 check whether we're interested in reporting this stop to higher
5390 layers, or whether we should resume the target transparently. */
5394 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5399 b
= bs
->breakpoint_at
;
5400 b
->ops
->check_status (bs
);
5403 bpstat_check_breakpoint_conditions (bs
, thread
);
5408 gdb::observers::breakpoint_modified
.notify (b
);
5410 /* We will stop here. */
5411 if (b
->disposition
== disp_disable
)
5413 --(b
->enable_count
);
5414 if (b
->enable_count
<= 0)
5415 b
->enable_state
= bp_disabled
;
5420 bs
->commands
= b
->commands
;
5421 if (command_line_is_silent (bs
->commands
5422 ? bs
->commands
.get () : NULL
))
5425 b
->ops
->after_condition_true (bs
);
5430 /* Print nothing for this entry if we don't stop or don't
5432 if (!bs
->stop
|| !bs
->print
)
5433 bs
->print_it
= print_it_noop
;
5436 /* If we aren't stopping, the value of some hardware watchpoint may
5437 not have changed, but the intermediate memory locations we are
5438 watching may have. Don't bother if we're stopping; this will get
5440 need_remove_insert
= 0;
5441 if (! bpstat_causes_stop (bs_head
))
5442 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5444 && bs
->breakpoint_at
5445 && is_hardware_watchpoint (bs
->breakpoint_at
))
5447 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5449 update_watchpoint (w
, 0 /* don't reparse. */);
5450 need_remove_insert
= 1;
5453 if (need_remove_insert
)
5454 update_global_location_list (UGLL_MAY_INSERT
);
5455 else if (removed_any
)
5456 update_global_location_list (UGLL_DONT_INSERT
);
5462 handle_jit_event (void)
5464 struct frame_info
*frame
;
5465 struct gdbarch
*gdbarch
;
5468 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5470 /* Switch terminal for any messages produced by
5471 breakpoint_re_set. */
5472 target_terminal::ours_for_output ();
5474 frame
= get_current_frame ();
5475 gdbarch
= get_frame_arch (frame
);
5477 jit_event_handler (gdbarch
);
5479 target_terminal::inferior ();
5482 /* Prepare WHAT final decision for infrun. */
5484 /* Decide what infrun needs to do with this bpstat. */
5487 bpstat_what (bpstat bs_head
)
5489 struct bpstat_what retval
;
5492 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5493 retval
.call_dummy
= STOP_NONE
;
5494 retval
.is_longjmp
= 0;
5496 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5498 /* Extract this BS's action. After processing each BS, we check
5499 if its action overrides all we've seem so far. */
5500 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5503 if (bs
->breakpoint_at
== NULL
)
5505 /* I suspect this can happen if it was a momentary
5506 breakpoint which has since been deleted. */
5510 bptype
= bs
->breakpoint_at
->type
;
5517 case bp_hardware_breakpoint
:
5518 case bp_single_step
:
5521 case bp_shlib_event
:
5525 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5527 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5530 this_action
= BPSTAT_WHAT_SINGLE
;
5533 case bp_hardware_watchpoint
:
5534 case bp_read_watchpoint
:
5535 case bp_access_watchpoint
:
5539 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5541 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5545 /* There was a watchpoint, but we're not stopping.
5546 This requires no further action. */
5550 case bp_longjmp_call_dummy
:
5554 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5555 retval
.is_longjmp
= bptype
!= bp_exception
;
5558 this_action
= BPSTAT_WHAT_SINGLE
;
5560 case bp_longjmp_resume
:
5561 case bp_exception_resume
:
5564 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5565 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5568 this_action
= BPSTAT_WHAT_SINGLE
;
5570 case bp_step_resume
:
5572 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5575 /* It is for the wrong frame. */
5576 this_action
= BPSTAT_WHAT_SINGLE
;
5579 case bp_hp_step_resume
:
5581 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5584 /* It is for the wrong frame. */
5585 this_action
= BPSTAT_WHAT_SINGLE
;
5588 case bp_watchpoint_scope
:
5589 case bp_thread_event
:
5590 case bp_overlay_event
:
5591 case bp_longjmp_master
:
5592 case bp_std_terminate_master
:
5593 case bp_exception_master
:
5594 this_action
= BPSTAT_WHAT_SINGLE
;
5600 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5602 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5606 /* There was a catchpoint, but we're not stopping.
5607 This requires no further action. */
5611 this_action
= BPSTAT_WHAT_SINGLE
;
5614 /* Make sure the action is stop (silent or noisy),
5615 so infrun.c pops the dummy frame. */
5616 retval
.call_dummy
= STOP_STACK_DUMMY
;
5617 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5619 case bp_std_terminate
:
5620 /* Make sure the action is stop (silent or noisy),
5621 so infrun.c pops the dummy frame. */
5622 retval
.call_dummy
= STOP_STD_TERMINATE
;
5623 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5626 case bp_fast_tracepoint
:
5627 case bp_static_tracepoint
:
5628 /* Tracepoint hits should not be reported back to GDB, and
5629 if one got through somehow, it should have been filtered
5631 internal_error (__FILE__
, __LINE__
,
5632 _("bpstat_what: tracepoint encountered"));
5634 case bp_gnu_ifunc_resolver
:
5635 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5636 this_action
= BPSTAT_WHAT_SINGLE
;
5638 case bp_gnu_ifunc_resolver_return
:
5639 /* The breakpoint will be removed, execution will restart from the
5640 PC of the former breakpoint. */
5641 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5646 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5648 this_action
= BPSTAT_WHAT_SINGLE
;
5652 internal_error (__FILE__
, __LINE__
,
5653 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5656 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5663 bpstat_run_callbacks (bpstat bs_head
)
5667 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5669 struct breakpoint
*b
= bs
->breakpoint_at
;
5676 handle_jit_event ();
5678 case bp_gnu_ifunc_resolver
:
5679 gnu_ifunc_resolver_stop (b
);
5681 case bp_gnu_ifunc_resolver_return
:
5682 gnu_ifunc_resolver_return_stop (b
);
5688 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5689 without hardware support). This isn't related to a specific bpstat,
5690 just to things like whether watchpoints are set. */
5693 bpstat_should_step (void)
5695 struct breakpoint
*b
;
5698 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5704 bpstat_causes_stop (bpstat bs
)
5706 for (; bs
!= NULL
; bs
= bs
->next
)
5715 /* Compute a string of spaces suitable to indent the next line
5716 so it starts at the position corresponding to the table column
5717 named COL_NAME in the currently active table of UIOUT. */
5720 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5722 static char wrap_indent
[80];
5723 int i
, total_width
, width
, align
;
5727 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5729 if (strcmp (text
, col_name
) == 0)
5731 gdb_assert (total_width
< sizeof wrap_indent
);
5732 memset (wrap_indent
, ' ', total_width
);
5733 wrap_indent
[total_width
] = 0;
5738 total_width
+= width
+ 1;
5744 /* Determine if the locations of this breakpoint will have their conditions
5745 evaluated by the target, host or a mix of both. Returns the following:
5747 "host": Host evals condition.
5748 "host or target": Host or Target evals condition.
5749 "target": Target evals condition.
5753 bp_condition_evaluator (struct breakpoint
*b
)
5755 struct bp_location
*bl
;
5756 char host_evals
= 0;
5757 char target_evals
= 0;
5762 if (!is_breakpoint (b
))
5765 if (gdb_evaluates_breakpoint_condition_p ()
5766 || !target_supports_evaluation_of_breakpoint_conditions ())
5767 return condition_evaluation_host
;
5769 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5771 if (bl
->cond_bytecode
)
5777 if (host_evals
&& target_evals
)
5778 return condition_evaluation_both
;
5779 else if (target_evals
)
5780 return condition_evaluation_target
;
5782 return condition_evaluation_host
;
5785 /* Determine the breakpoint location's condition evaluator. This is
5786 similar to bp_condition_evaluator, but for locations. */
5789 bp_location_condition_evaluator (struct bp_location
*bl
)
5791 if (bl
&& !is_breakpoint (bl
->owner
))
5794 if (gdb_evaluates_breakpoint_condition_p ()
5795 || !target_supports_evaluation_of_breakpoint_conditions ())
5796 return condition_evaluation_host
;
5798 if (bl
&& bl
->cond_bytecode
)
5799 return condition_evaluation_target
;
5801 return condition_evaluation_host
;
5804 /* Print the LOC location out of the list of B->LOC locations. */
5807 print_breakpoint_location (struct breakpoint
*b
,
5808 struct bp_location
*loc
)
5810 struct ui_out
*uiout
= current_uiout
;
5812 scoped_restore_current_program_space restore_pspace
;
5814 if (loc
!= NULL
&& loc
->shlib_disabled
)
5818 set_current_program_space (loc
->pspace
);
5820 if (b
->display_canonical
)
5821 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5822 else if (loc
&& loc
->symtab
)
5824 const struct symbol
*sym
= loc
->symbol
;
5828 uiout
->text ("in ");
5829 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
),
5830 ui_out_style_kind::FUNCTION
);
5832 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5833 uiout
->text ("at ");
5835 uiout
->field_string ("file",
5836 symtab_to_filename_for_display (loc
->symtab
),
5837 ui_out_style_kind::FILE);
5840 if (uiout
->is_mi_like_p ())
5841 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5843 uiout
->field_int ("line", loc
->line_number
);
5849 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5851 uiout
->field_stream ("at", stb
);
5855 uiout
->field_string ("pending",
5856 event_location_to_string (b
->location
.get ()));
5857 /* If extra_string is available, it could be holding a condition
5858 or dprintf arguments. In either case, make sure it is printed,
5859 too, but only for non-MI streams. */
5860 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5862 if (b
->type
== bp_dprintf
)
5866 uiout
->text (b
->extra_string
);
5870 if (loc
&& is_breakpoint (b
)
5871 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5872 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5875 uiout
->field_string ("evaluated-by",
5876 bp_location_condition_evaluator (loc
));
5882 bptype_string (enum bptype type
)
5884 struct ep_type_description
5887 const char *description
;
5889 static struct ep_type_description bptypes
[] =
5891 {bp_none
, "?deleted?"},
5892 {bp_breakpoint
, "breakpoint"},
5893 {bp_hardware_breakpoint
, "hw breakpoint"},
5894 {bp_single_step
, "sw single-step"},
5895 {bp_until
, "until"},
5896 {bp_finish
, "finish"},
5897 {bp_watchpoint
, "watchpoint"},
5898 {bp_hardware_watchpoint
, "hw watchpoint"},
5899 {bp_read_watchpoint
, "read watchpoint"},
5900 {bp_access_watchpoint
, "acc watchpoint"},
5901 {bp_longjmp
, "longjmp"},
5902 {bp_longjmp_resume
, "longjmp resume"},
5903 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
5904 {bp_exception
, "exception"},
5905 {bp_exception_resume
, "exception resume"},
5906 {bp_step_resume
, "step resume"},
5907 {bp_hp_step_resume
, "high-priority step resume"},
5908 {bp_watchpoint_scope
, "watchpoint scope"},
5909 {bp_call_dummy
, "call dummy"},
5910 {bp_std_terminate
, "std::terminate"},
5911 {bp_shlib_event
, "shlib events"},
5912 {bp_thread_event
, "thread events"},
5913 {bp_overlay_event
, "overlay events"},
5914 {bp_longjmp_master
, "longjmp master"},
5915 {bp_std_terminate_master
, "std::terminate master"},
5916 {bp_exception_master
, "exception master"},
5917 {bp_catchpoint
, "catchpoint"},
5918 {bp_tracepoint
, "tracepoint"},
5919 {bp_fast_tracepoint
, "fast tracepoint"},
5920 {bp_static_tracepoint
, "static tracepoint"},
5921 {bp_dprintf
, "dprintf"},
5922 {bp_jit_event
, "jit events"},
5923 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
5924 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
5927 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
5928 || ((int) type
!= bptypes
[(int) type
].type
))
5929 internal_error (__FILE__
, __LINE__
,
5930 _("bptypes table does not describe type #%d."),
5933 return bptypes
[(int) type
].description
;
5936 /* For MI, output a field named 'thread-groups' with a list as the value.
5937 For CLI, prefix the list with the string 'inf'. */
5940 output_thread_groups (struct ui_out
*uiout
,
5941 const char *field_name
,
5942 const std::vector
<int> &inf_nums
,
5945 int is_mi
= uiout
->is_mi_like_p ();
5947 /* For backward compatibility, don't display inferiors in CLI unless
5948 there are several. Always display them for MI. */
5949 if (!is_mi
&& mi_only
)
5952 ui_out_emit_list
list_emitter (uiout
, field_name
);
5954 for (size_t i
= 0; i
< inf_nums
.size (); i
++)
5960 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf_nums
[i
]);
5961 uiout
->field_string (NULL
, mi_group
);
5966 uiout
->text (" inf ");
5970 uiout
->text (plongest (inf_nums
[i
]));
5975 /* Print B to gdb_stdout. */
5978 print_one_breakpoint_location (struct breakpoint
*b
,
5979 struct bp_location
*loc
,
5981 struct bp_location
**last_loc
,
5984 struct command_line
*l
;
5985 static char bpenables
[] = "nynny";
5987 struct ui_out
*uiout
= current_uiout
;
5988 int header_of_multiple
= 0;
5989 int part_of_multiple
= (loc
!= NULL
);
5990 struct value_print_options opts
;
5992 get_user_print_options (&opts
);
5994 gdb_assert (!loc
|| loc_number
!= 0);
5995 /* See comment in print_one_breakpoint concerning treatment of
5996 breakpoints with single disabled location. */
5999 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6000 header_of_multiple
= 1;
6008 if (part_of_multiple
)
6009 uiout
->field_fmt ("number", "%d.%d", b
->number
, loc_number
);
6011 uiout
->field_int ("number", b
->number
);
6015 if (part_of_multiple
)
6016 uiout
->field_skip ("type");
6018 uiout
->field_string ("type", bptype_string (b
->type
));
6022 if (part_of_multiple
)
6023 uiout
->field_skip ("disp");
6025 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6029 if (part_of_multiple
)
6030 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6032 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6035 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6037 /* Although the print_one can possibly print all locations,
6038 calling it here is not likely to get any nice result. So,
6039 make sure there's just one location. */
6040 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6041 b
->ops
->print_one (b
, last_loc
);
6047 internal_error (__FILE__
, __LINE__
,
6048 _("print_one_breakpoint: bp_none encountered\n"));
6052 case bp_hardware_watchpoint
:
6053 case bp_read_watchpoint
:
6054 case bp_access_watchpoint
:
6056 struct watchpoint
*w
= (struct watchpoint
*) b
;
6058 /* Field 4, the address, is omitted (which makes the columns
6059 not line up too nicely with the headers, but the effect
6060 is relatively readable). */
6061 if (opts
.addressprint
)
6062 uiout
->field_skip ("addr");
6064 uiout
->field_string ("what", w
->exp_string
);
6069 case bp_hardware_breakpoint
:
6070 case bp_single_step
:
6074 case bp_longjmp_resume
:
6075 case bp_longjmp_call_dummy
:
6077 case bp_exception_resume
:
6078 case bp_step_resume
:
6079 case bp_hp_step_resume
:
6080 case bp_watchpoint_scope
:
6082 case bp_std_terminate
:
6083 case bp_shlib_event
:
6084 case bp_thread_event
:
6085 case bp_overlay_event
:
6086 case bp_longjmp_master
:
6087 case bp_std_terminate_master
:
6088 case bp_exception_master
:
6090 case bp_fast_tracepoint
:
6091 case bp_static_tracepoint
:
6094 case bp_gnu_ifunc_resolver
:
6095 case bp_gnu_ifunc_resolver_return
:
6096 if (opts
.addressprint
)
6099 if (header_of_multiple
)
6100 uiout
->field_string ("addr", "<MULTIPLE>");
6101 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6102 uiout
->field_string ("addr", "<PENDING>");
6104 uiout
->field_core_addr ("addr",
6105 loc
->gdbarch
, loc
->address
);
6108 if (!header_of_multiple
)
6109 print_breakpoint_location (b
, loc
);
6116 if (loc
!= NULL
&& !header_of_multiple
)
6118 std::vector
<int> inf_nums
;
6121 for (inferior
*inf
: all_inferiors ())
6123 if (inf
->pspace
== loc
->pspace
)
6124 inf_nums
.push_back (inf
->num
);
6127 /* For backward compatibility, don't display inferiors in CLI unless
6128 there are several. Always display for MI. */
6130 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6131 && (number_of_program_spaces () > 1
6132 || number_of_inferiors () > 1)
6133 /* LOC is for existing B, it cannot be in
6134 moribund_locations and thus having NULL OWNER. */
6135 && loc
->owner
->type
!= bp_catchpoint
))
6137 output_thread_groups (uiout
, "thread-groups", inf_nums
, mi_only
);
6140 if (!part_of_multiple
)
6142 if (b
->thread
!= -1)
6144 /* FIXME: This seems to be redundant and lost here; see the
6145 "stop only in" line a little further down. */
6146 uiout
->text (" thread ");
6147 uiout
->field_int ("thread", b
->thread
);
6149 else if (b
->task
!= 0)
6151 uiout
->text (" task ");
6152 uiout
->field_int ("task", b
->task
);
6158 if (!part_of_multiple
)
6159 b
->ops
->print_one_detail (b
, uiout
);
6161 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6164 uiout
->text ("\tstop only in stack frame at ");
6165 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6167 uiout
->field_core_addr ("frame",
6168 b
->gdbarch
, b
->frame_id
.stack_addr
);
6172 if (!part_of_multiple
&& b
->cond_string
)
6175 if (is_tracepoint (b
))
6176 uiout
->text ("\ttrace only if ");
6178 uiout
->text ("\tstop only if ");
6179 uiout
->field_string ("cond", b
->cond_string
);
6181 /* Print whether the target is doing the breakpoint's condition
6182 evaluation. If GDB is doing the evaluation, don't print anything. */
6183 if (is_breakpoint (b
)
6184 && breakpoint_condition_evaluation_mode ()
6185 == condition_evaluation_target
)
6188 uiout
->field_string ("evaluated-by",
6189 bp_condition_evaluator (b
));
6190 uiout
->text (" evals)");
6195 if (!part_of_multiple
&& b
->thread
!= -1)
6197 /* FIXME should make an annotation for this. */
6198 uiout
->text ("\tstop only in thread ");
6199 if (uiout
->is_mi_like_p ())
6200 uiout
->field_int ("thread", b
->thread
);
6203 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6205 uiout
->field_string ("thread", print_thread_id (thr
));
6210 if (!part_of_multiple
)
6214 /* FIXME should make an annotation for this. */
6215 if (is_catchpoint (b
))
6216 uiout
->text ("\tcatchpoint");
6217 else if (is_tracepoint (b
))
6218 uiout
->text ("\ttracepoint");
6220 uiout
->text ("\tbreakpoint");
6221 uiout
->text (" already hit ");
6222 uiout
->field_int ("times", b
->hit_count
);
6223 if (b
->hit_count
== 1)
6224 uiout
->text (" time\n");
6226 uiout
->text (" times\n");
6230 /* Output the count also if it is zero, but only if this is mi. */
6231 if (uiout
->is_mi_like_p ())
6232 uiout
->field_int ("times", b
->hit_count
);
6236 if (!part_of_multiple
&& b
->ignore_count
)
6239 uiout
->text ("\tignore next ");
6240 uiout
->field_int ("ignore", b
->ignore_count
);
6241 uiout
->text (" hits\n");
6244 /* Note that an enable count of 1 corresponds to "enable once"
6245 behavior, which is reported by the combination of enablement and
6246 disposition, so we don't need to mention it here. */
6247 if (!part_of_multiple
&& b
->enable_count
> 1)
6250 uiout
->text ("\tdisable after ");
6251 /* Tweak the wording to clarify that ignore and enable counts
6252 are distinct, and have additive effect. */
6253 if (b
->ignore_count
)
6254 uiout
->text ("additional ");
6256 uiout
->text ("next ");
6257 uiout
->field_int ("enable", b
->enable_count
);
6258 uiout
->text (" hits\n");
6261 if (!part_of_multiple
&& is_tracepoint (b
))
6263 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6265 if (tp
->traceframe_usage
)
6267 uiout
->text ("\ttrace buffer usage ");
6268 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6269 uiout
->text (" bytes\n");
6273 l
= b
->commands
? b
->commands
.get () : NULL
;
6274 if (!part_of_multiple
&& l
)
6277 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6278 print_command_lines (uiout
, l
, 4);
6281 if (is_tracepoint (b
))
6283 struct tracepoint
*t
= (struct tracepoint
*) b
;
6285 if (!part_of_multiple
&& t
->pass_count
)
6287 annotate_field (10);
6288 uiout
->text ("\tpass count ");
6289 uiout
->field_int ("pass", t
->pass_count
);
6290 uiout
->text (" \n");
6293 /* Don't display it when tracepoint or tracepoint location is
6295 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6297 annotate_field (11);
6299 if (uiout
->is_mi_like_p ())
6300 uiout
->field_string ("installed",
6301 loc
->inserted
? "y" : "n");
6307 uiout
->text ("\tnot ");
6308 uiout
->text ("installed on target\n");
6313 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6315 if (is_watchpoint (b
))
6317 struct watchpoint
*w
= (struct watchpoint
*) b
;
6319 uiout
->field_string ("original-location", w
->exp_string
);
6321 else if (b
->location
!= NULL
6322 && event_location_to_string (b
->location
.get ()) != NULL
)
6323 uiout
->field_string ("original-location",
6324 event_location_to_string (b
->location
.get ()));
6328 /* See breakpoint.h. */
6330 bool fix_multi_location_breakpoint_output_globally
= false;
6333 print_one_breakpoint (struct breakpoint
*b
,
6334 struct bp_location
**last_loc
,
6337 struct ui_out
*uiout
= current_uiout
;
6338 bool use_fixed_output
6339 = (uiout
->test_flags (fix_multi_location_breakpoint_output
)
6340 || fix_multi_location_breakpoint_output_globally
);
6342 gdb::optional
<ui_out_emit_tuple
> bkpt_tuple_emitter (gdb::in_place
, uiout
, "bkpt");
6343 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6345 /* The mi2 broken format: the main breakpoint tuple ends here, the locations
6347 if (!use_fixed_output
)
6348 bkpt_tuple_emitter
.reset ();
6350 /* If this breakpoint has custom print function,
6351 it's already printed. Otherwise, print individual
6352 locations, if any. */
6353 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6355 /* If breakpoint has a single location that is disabled, we
6356 print it as if it had several locations, since otherwise it's
6357 hard to represent "breakpoint enabled, location disabled"
6360 Note that while hardware watchpoints have several locations
6361 internally, that's not a property exposed to user. */
6363 && !is_hardware_watchpoint (b
)
6364 && (b
->loc
->next
|| !b
->loc
->enabled
))
6366 gdb::optional
<ui_out_emit_list
> locations_list
;
6368 /* For MI version <= 2, keep the behavior where GDB outputs an invalid
6369 MI record. For later versions, place breakpoint locations in a
6371 if (uiout
->is_mi_like_p () && use_fixed_output
)
6372 locations_list
.emplace (uiout
, "locations");
6375 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
, ++n
)
6377 ui_out_emit_tuple
loc_tuple_emitter (uiout
, NULL
);
6378 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6385 breakpoint_address_bits (struct breakpoint
*b
)
6387 int print_address_bits
= 0;
6388 struct bp_location
*loc
;
6390 /* Software watchpoints that aren't watching memory don't have an
6391 address to print. */
6392 if (is_no_memory_software_watchpoint (b
))
6395 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6399 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6400 if (addr_bit
> print_address_bits
)
6401 print_address_bits
= addr_bit
;
6404 return print_address_bits
;
6407 /* See breakpoint.h. */
6410 print_breakpoint (breakpoint
*b
)
6412 struct bp_location
*dummy_loc
= NULL
;
6413 print_one_breakpoint (b
, &dummy_loc
, 0);
6416 /* Return true if this breakpoint was set by the user, false if it is
6417 internal or momentary. */
6420 user_breakpoint_p (struct breakpoint
*b
)
6422 return b
->number
> 0;
6425 /* See breakpoint.h. */
6428 pending_breakpoint_p (struct breakpoint
*b
)
6430 return b
->loc
== NULL
;
6433 /* Print information on user settable breakpoint (watchpoint, etc)
6434 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6435 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6436 FILTER is non-NULL, call it on each breakpoint and only include the
6437 ones for which it returns non-zero. Return the total number of
6438 breakpoints listed. */
6441 breakpoint_1 (const char *args
, int allflag
,
6442 int (*filter
) (const struct breakpoint
*))
6444 struct breakpoint
*b
;
6445 struct bp_location
*last_loc
= NULL
;
6446 int nr_printable_breakpoints
;
6447 struct value_print_options opts
;
6448 int print_address_bits
= 0;
6449 int print_type_col_width
= 14;
6450 struct ui_out
*uiout
= current_uiout
;
6452 get_user_print_options (&opts
);
6454 /* Compute the number of rows in the table, as well as the size
6455 required for address fields. */
6456 nr_printable_breakpoints
= 0;
6459 /* If we have a filter, only list the breakpoints it accepts. */
6460 if (filter
&& !filter (b
))
6463 /* If we have an "args" string, it is a list of breakpoints to
6464 accept. Skip the others. */
6465 if (args
!= NULL
&& *args
!= '\0')
6467 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6469 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6473 if (allflag
|| user_breakpoint_p (b
))
6475 int addr_bit
, type_len
;
6477 addr_bit
= breakpoint_address_bits (b
);
6478 if (addr_bit
> print_address_bits
)
6479 print_address_bits
= addr_bit
;
6481 type_len
= strlen (bptype_string (b
->type
));
6482 if (type_len
> print_type_col_width
)
6483 print_type_col_width
= type_len
;
6485 nr_printable_breakpoints
++;
6490 ui_out_emit_table
table_emitter (uiout
,
6491 opts
.addressprint
? 6 : 5,
6492 nr_printable_breakpoints
,
6495 if (nr_printable_breakpoints
> 0)
6496 annotate_breakpoints_headers ();
6497 if (nr_printable_breakpoints
> 0)
6499 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6500 if (nr_printable_breakpoints
> 0)
6502 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6503 if (nr_printable_breakpoints
> 0)
6505 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6506 if (nr_printable_breakpoints
> 0)
6508 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6509 if (opts
.addressprint
)
6511 if (nr_printable_breakpoints
> 0)
6513 if (print_address_bits
<= 32)
6514 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6516 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6518 if (nr_printable_breakpoints
> 0)
6520 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6521 uiout
->table_body ();
6522 if (nr_printable_breakpoints
> 0)
6523 annotate_breakpoints_table ();
6528 /* If we have a filter, only list the breakpoints it accepts. */
6529 if (filter
&& !filter (b
))
6532 /* If we have an "args" string, it is a list of breakpoints to
6533 accept. Skip the others. */
6535 if (args
!= NULL
&& *args
!= '\0')
6537 if (allflag
) /* maintenance info breakpoint */
6539 if (parse_and_eval_long (args
) != b
->number
)
6542 else /* all others */
6544 if (!number_is_in_list (args
, b
->number
))
6548 /* We only print out user settable breakpoints unless the
6550 if (allflag
|| user_breakpoint_p (b
))
6551 print_one_breakpoint (b
, &last_loc
, allflag
);
6555 if (nr_printable_breakpoints
== 0)
6557 /* If there's a filter, let the caller decide how to report
6561 if (args
== NULL
|| *args
== '\0')
6562 uiout
->message ("No breakpoints or watchpoints.\n");
6564 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6570 if (last_loc
&& !server_command
)
6571 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6574 /* FIXME? Should this be moved up so that it is only called when
6575 there have been breakpoints? */
6576 annotate_breakpoints_table_end ();
6578 return nr_printable_breakpoints
;
6581 /* Display the value of default-collect in a way that is generally
6582 compatible with the breakpoint list. */
6585 default_collect_info (void)
6587 struct ui_out
*uiout
= current_uiout
;
6589 /* If it has no value (which is frequently the case), say nothing; a
6590 message like "No default-collect." gets in user's face when it's
6592 if (!*default_collect
)
6595 /* The following phrase lines up nicely with per-tracepoint collect
6597 uiout
->text ("default collect ");
6598 uiout
->field_string ("default-collect", default_collect
);
6599 uiout
->text (" \n");
6603 info_breakpoints_command (const char *args
, int from_tty
)
6605 breakpoint_1 (args
, 0, NULL
);
6607 default_collect_info ();
6611 info_watchpoints_command (const char *args
, int from_tty
)
6613 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6614 struct ui_out
*uiout
= current_uiout
;
6616 if (num_printed
== 0)
6618 if (args
== NULL
|| *args
== '\0')
6619 uiout
->message ("No watchpoints.\n");
6621 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6626 maintenance_info_breakpoints (const char *args
, int from_tty
)
6628 breakpoint_1 (args
, 1, NULL
);
6630 default_collect_info ();
6634 breakpoint_has_pc (struct breakpoint
*b
,
6635 struct program_space
*pspace
,
6636 CORE_ADDR pc
, struct obj_section
*section
)
6638 struct bp_location
*bl
= b
->loc
;
6640 for (; bl
; bl
= bl
->next
)
6642 if (bl
->pspace
== pspace
6643 && bl
->address
== pc
6644 && (!overlay_debugging
|| bl
->section
== section
))
6650 /* Print a message describing any user-breakpoints set at PC. This
6651 concerns with logical breakpoints, so we match program spaces, not
6655 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6656 struct program_space
*pspace
, CORE_ADDR pc
,
6657 struct obj_section
*section
, int thread
)
6660 struct breakpoint
*b
;
6663 others
+= (user_breakpoint_p (b
)
6664 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6668 printf_filtered (_("Note: breakpoint "));
6669 else /* if (others == ???) */
6670 printf_filtered (_("Note: breakpoints "));
6672 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6675 printf_filtered ("%d", b
->number
);
6676 if (b
->thread
== -1 && thread
!= -1)
6677 printf_filtered (" (all threads)");
6678 else if (b
->thread
!= -1)
6679 printf_filtered (" (thread %d)", b
->thread
);
6680 printf_filtered ("%s%s ",
6681 ((b
->enable_state
== bp_disabled
6682 || b
->enable_state
== bp_call_disabled
)
6686 : ((others
== 1) ? " and" : ""));
6688 printf_filtered (_("also set at pc "));
6689 fputs_styled (paddress (gdbarch
, pc
), address_style
.style (), gdb_stdout
);
6690 printf_filtered (".\n");
6695 /* Return true iff it is meaningful to use the address member of
6696 BPT locations. For some breakpoint types, the locations' address members
6697 are irrelevant and it makes no sense to attempt to compare them to other
6698 addresses (or use them for any other purpose either).
6700 More specifically, each of the following breakpoint types will
6701 always have a zero valued location address and we don't want to mark
6702 breakpoints of any of these types to be a duplicate of an actual
6703 breakpoint location at address zero:
6711 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6713 enum bptype type
= bpt
->type
;
6715 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6718 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6719 true if LOC1 and LOC2 represent the same watchpoint location. */
6722 watchpoint_locations_match (struct bp_location
*loc1
,
6723 struct bp_location
*loc2
)
6725 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6726 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6728 /* Both of them must exist. */
6729 gdb_assert (w1
!= NULL
);
6730 gdb_assert (w2
!= NULL
);
6732 /* If the target can evaluate the condition expression in hardware,
6733 then we we need to insert both watchpoints even if they are at
6734 the same place. Otherwise the watchpoint will only trigger when
6735 the condition of whichever watchpoint was inserted evaluates to
6736 true, not giving a chance for GDB to check the condition of the
6737 other watchpoint. */
6739 && target_can_accel_watchpoint_condition (loc1
->address
,
6741 loc1
->watchpoint_type
,
6742 w1
->cond_exp
.get ()))
6744 && target_can_accel_watchpoint_condition (loc2
->address
,
6746 loc2
->watchpoint_type
,
6747 w2
->cond_exp
.get ())))
6750 /* Note that this checks the owner's type, not the location's. In
6751 case the target does not support read watchpoints, but does
6752 support access watchpoints, we'll have bp_read_watchpoint
6753 watchpoints with hw_access locations. Those should be considered
6754 duplicates of hw_read locations. The hw_read locations will
6755 become hw_access locations later. */
6756 return (loc1
->owner
->type
== loc2
->owner
->type
6757 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6758 && loc1
->address
== loc2
->address
6759 && loc1
->length
== loc2
->length
);
6762 /* See breakpoint.h. */
6765 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6766 const address_space
*aspace2
, CORE_ADDR addr2
)
6768 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6769 || aspace1
== aspace2
)
6773 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6774 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6775 matches ASPACE2. On targets that have global breakpoints, the address
6776 space doesn't really matter. */
6779 breakpoint_address_match_range (const address_space
*aspace1
,
6781 int len1
, const address_space
*aspace2
,
6784 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6785 || aspace1
== aspace2
)
6786 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6789 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6790 a ranged breakpoint. In most targets, a match happens only if ASPACE
6791 matches the breakpoint's address space. On targets that have global
6792 breakpoints, the address space doesn't really matter. */
6795 breakpoint_location_address_match (struct bp_location
*bl
,
6796 const address_space
*aspace
,
6799 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6802 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6803 bl
->address
, bl
->length
,
6807 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6808 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6809 match happens only if ASPACE matches the breakpoint's address
6810 space. On targets that have global breakpoints, the address space
6811 doesn't really matter. */
6814 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6815 const address_space
*aspace
,
6816 CORE_ADDR addr
, int len
)
6818 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6819 || bl
->pspace
->aspace
== aspace
)
6821 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6823 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6829 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6830 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6831 true, otherwise returns false. */
6834 tracepoint_locations_match (struct bp_location
*loc1
,
6835 struct bp_location
*loc2
)
6837 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6838 /* Since tracepoint locations are never duplicated with others', tracepoint
6839 locations at the same address of different tracepoints are regarded as
6840 different locations. */
6841 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6846 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6847 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6848 represent the same location. */
6851 breakpoint_locations_match (struct bp_location
*loc1
,
6852 struct bp_location
*loc2
)
6854 int hw_point1
, hw_point2
;
6856 /* Both of them must not be in moribund_locations. */
6857 gdb_assert (loc1
->owner
!= NULL
);
6858 gdb_assert (loc2
->owner
!= NULL
);
6860 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6861 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6863 if (hw_point1
!= hw_point2
)
6866 return watchpoint_locations_match (loc1
, loc2
);
6867 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6868 return tracepoint_locations_match (loc1
, loc2
);
6870 /* We compare bp_location.length in order to cover ranged breakpoints. */
6871 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6872 loc2
->pspace
->aspace
, loc2
->address
)
6873 && loc1
->length
== loc2
->length
);
6877 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6878 int bnum
, int have_bnum
)
6880 /* The longest string possibly returned by hex_string_custom
6881 is 50 chars. These must be at least that big for safety. */
6885 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
6886 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
6888 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
6889 bnum
, astr1
, astr2
);
6891 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
6894 /* Adjust a breakpoint's address to account for architectural
6895 constraints on breakpoint placement. Return the adjusted address.
6896 Note: Very few targets require this kind of adjustment. For most
6897 targets, this function is simply the identity function. */
6900 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
6901 CORE_ADDR bpaddr
, enum bptype bptype
)
6903 if (bptype
== bp_watchpoint
6904 || bptype
== bp_hardware_watchpoint
6905 || bptype
== bp_read_watchpoint
6906 || bptype
== bp_access_watchpoint
6907 || bptype
== bp_catchpoint
)
6909 /* Watchpoints and the various bp_catch_* eventpoints should not
6910 have their addresses modified. */
6913 else if (bptype
== bp_single_step
)
6915 /* Single-step breakpoints should not have their addresses
6916 modified. If there's any architectural constrain that
6917 applies to this address, then it should have already been
6918 taken into account when the breakpoint was created in the
6919 first place. If we didn't do this, stepping through e.g.,
6920 Thumb-2 IT blocks would break. */
6925 CORE_ADDR adjusted_bpaddr
= bpaddr
;
6927 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
6929 /* Some targets have architectural constraints on the placement
6930 of breakpoint instructions. Obtain the adjusted address. */
6931 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
6934 adjusted_bpaddr
= address_significant (gdbarch
, adjusted_bpaddr
);
6936 /* An adjusted breakpoint address can significantly alter
6937 a user's expectations. Print a warning if an adjustment
6939 if (adjusted_bpaddr
!= bpaddr
)
6940 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
6942 return adjusted_bpaddr
;
6946 bp_location::bp_location (breakpoint
*owner
)
6948 bp_location
*loc
= this;
6951 loc
->cond_bytecode
= NULL
;
6952 loc
->shlib_disabled
= 0;
6955 switch (owner
->type
)
6958 case bp_single_step
:
6962 case bp_longjmp_resume
:
6963 case bp_longjmp_call_dummy
:
6965 case bp_exception_resume
:
6966 case bp_step_resume
:
6967 case bp_hp_step_resume
:
6968 case bp_watchpoint_scope
:
6970 case bp_std_terminate
:
6971 case bp_shlib_event
:
6972 case bp_thread_event
:
6973 case bp_overlay_event
:
6975 case bp_longjmp_master
:
6976 case bp_std_terminate_master
:
6977 case bp_exception_master
:
6978 case bp_gnu_ifunc_resolver
:
6979 case bp_gnu_ifunc_resolver_return
:
6981 loc
->loc_type
= bp_loc_software_breakpoint
;
6982 mark_breakpoint_location_modified (loc
);
6984 case bp_hardware_breakpoint
:
6985 loc
->loc_type
= bp_loc_hardware_breakpoint
;
6986 mark_breakpoint_location_modified (loc
);
6988 case bp_hardware_watchpoint
:
6989 case bp_read_watchpoint
:
6990 case bp_access_watchpoint
:
6991 loc
->loc_type
= bp_loc_hardware_watchpoint
;
6996 case bp_fast_tracepoint
:
6997 case bp_static_tracepoint
:
6998 loc
->loc_type
= bp_loc_other
;
7001 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7007 /* Allocate a struct bp_location. */
7009 static struct bp_location
*
7010 allocate_bp_location (struct breakpoint
*bpt
)
7012 return bpt
->ops
->allocate_location (bpt
);
7016 free_bp_location (struct bp_location
*loc
)
7021 /* Increment reference count. */
7024 incref_bp_location (struct bp_location
*bl
)
7029 /* Decrement reference count. If the reference count reaches 0,
7030 destroy the bp_location. Sets *BLP to NULL. */
7033 decref_bp_location (struct bp_location
**blp
)
7035 gdb_assert ((*blp
)->refc
> 0);
7037 if (--(*blp
)->refc
== 0)
7038 free_bp_location (*blp
);
7042 /* Add breakpoint B at the end of the global breakpoint chain. */
7045 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7047 struct breakpoint
*b1
;
7048 struct breakpoint
*result
= b
.get ();
7050 /* Add this breakpoint to the end of the chain so that a list of
7051 breakpoints will come out in order of increasing numbers. */
7053 b1
= breakpoint_chain
;
7055 breakpoint_chain
= b
.release ();
7060 b1
->next
= b
.release ();
7066 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7069 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7070 struct gdbarch
*gdbarch
,
7072 const struct breakpoint_ops
*ops
)
7074 gdb_assert (ops
!= NULL
);
7078 b
->gdbarch
= gdbarch
;
7079 b
->language
= current_language
->la_language
;
7080 b
->input_radix
= input_radix
;
7081 b
->related_breakpoint
= b
;
7084 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7085 that has type BPTYPE and has no locations as yet. */
7087 static struct breakpoint
*
7088 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7090 const struct breakpoint_ops
*ops
)
7092 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7094 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7095 return add_to_breakpoint_chain (std::move (b
));
7098 /* Initialize loc->function_name. */
7101 set_breakpoint_location_function (struct bp_location
*loc
)
7103 gdb_assert (loc
->owner
!= NULL
);
7105 if (loc
->owner
->type
== bp_breakpoint
7106 || loc
->owner
->type
== bp_hardware_breakpoint
7107 || is_tracepoint (loc
->owner
))
7109 const char *function_name
;
7111 if (loc
->msymbol
!= NULL
7112 && (MSYMBOL_TYPE (loc
->msymbol
) == mst_text_gnu_ifunc
7113 || MSYMBOL_TYPE (loc
->msymbol
) == mst_data_gnu_ifunc
))
7115 struct breakpoint
*b
= loc
->owner
;
7117 function_name
= MSYMBOL_LINKAGE_NAME (loc
->msymbol
);
7119 if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7120 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7122 /* Create only the whole new breakpoint of this type but do not
7123 mess more complicated breakpoints with multiple locations. */
7124 b
->type
= bp_gnu_ifunc_resolver
;
7125 /* Remember the resolver's address for use by the return
7127 loc
->related_address
= loc
->address
;
7131 find_pc_partial_function (loc
->address
, &function_name
, NULL
, NULL
);
7134 loc
->function_name
= xstrdup (function_name
);
7138 /* Attempt to determine architecture of location identified by SAL. */
7140 get_sal_arch (struct symtab_and_line sal
)
7143 return get_objfile_arch (sal
.section
->objfile
);
7145 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7150 /* Low level routine for partially initializing a breakpoint of type
7151 BPTYPE. The newly created breakpoint's address, section, source
7152 file name, and line number are provided by SAL.
7154 It is expected that the caller will complete the initialization of
7155 the newly created breakpoint struct as well as output any status
7156 information regarding the creation of a new breakpoint. */
7159 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7160 struct symtab_and_line sal
, enum bptype bptype
,
7161 const struct breakpoint_ops
*ops
)
7163 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7165 add_location_to_breakpoint (b
, &sal
);
7167 if (bptype
!= bp_catchpoint
)
7168 gdb_assert (sal
.pspace
!= NULL
);
7170 /* Store the program space that was used to set the breakpoint,
7171 except for ordinary breakpoints, which are independent of the
7173 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7174 b
->pspace
= sal
.pspace
;
7177 /* set_raw_breakpoint is a low level routine for allocating and
7178 partially initializing a breakpoint of type BPTYPE. The newly
7179 created breakpoint's address, section, source file name, and line
7180 number are provided by SAL. The newly created and partially
7181 initialized breakpoint is added to the breakpoint chain and
7182 is also returned as the value of this function.
7184 It is expected that the caller will complete the initialization of
7185 the newly created breakpoint struct as well as output any status
7186 information regarding the creation of a new breakpoint. In
7187 particular, set_raw_breakpoint does NOT set the breakpoint
7188 number! Care should be taken to not allow an error to occur
7189 prior to completing the initialization of the breakpoint. If this
7190 should happen, a bogus breakpoint will be left on the chain. */
7193 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7194 struct symtab_and_line sal
, enum bptype bptype
,
7195 const struct breakpoint_ops
*ops
)
7197 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7199 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7200 return add_to_breakpoint_chain (std::move (b
));
7203 /* Call this routine when stepping and nexting to enable a breakpoint
7204 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7205 initiated the operation. */
7208 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7210 struct breakpoint
*b
, *b_tmp
;
7211 int thread
= tp
->global_num
;
7213 /* To avoid having to rescan all objfile symbols at every step,
7214 we maintain a list of continually-inserted but always disabled
7215 longjmp "master" breakpoints. Here, we simply create momentary
7216 clones of those and enable them for the requested thread. */
7217 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7218 if (b
->pspace
== current_program_space
7219 && (b
->type
== bp_longjmp_master
7220 || b
->type
== bp_exception_master
))
7222 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7223 struct breakpoint
*clone
;
7225 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7226 after their removal. */
7227 clone
= momentary_breakpoint_from_master (b
, type
,
7228 &momentary_breakpoint_ops
, 1);
7229 clone
->thread
= thread
;
7232 tp
->initiating_frame
= frame
;
7235 /* Delete all longjmp breakpoints from THREAD. */
7237 delete_longjmp_breakpoint (int thread
)
7239 struct breakpoint
*b
, *b_tmp
;
7241 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7242 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7244 if (b
->thread
== thread
)
7245 delete_breakpoint (b
);
7250 delete_longjmp_breakpoint_at_next_stop (int thread
)
7252 struct breakpoint
*b
, *b_tmp
;
7254 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7255 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7257 if (b
->thread
== thread
)
7258 b
->disposition
= disp_del_at_next_stop
;
7262 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7263 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7264 pointer to any of them. Return NULL if this system cannot place longjmp
7268 set_longjmp_breakpoint_for_call_dummy (void)
7270 struct breakpoint
*b
, *retval
= NULL
;
7273 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7275 struct breakpoint
*new_b
;
7277 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7278 &momentary_breakpoint_ops
,
7280 new_b
->thread
= inferior_thread ()->global_num
;
7282 /* Link NEW_B into the chain of RETVAL breakpoints. */
7284 gdb_assert (new_b
->related_breakpoint
== new_b
);
7287 new_b
->related_breakpoint
= retval
;
7288 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7289 retval
= retval
->related_breakpoint
;
7290 retval
->related_breakpoint
= new_b
;
7296 /* Verify all existing dummy frames and their associated breakpoints for
7297 TP. Remove those which can no longer be found in the current frame
7300 You should call this function only at places where it is safe to currently
7301 unwind the whole stack. Failed stack unwind would discard live dummy
7305 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7307 struct breakpoint
*b
, *b_tmp
;
7309 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7310 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7312 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7314 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7315 dummy_b
= dummy_b
->related_breakpoint
;
7316 if (dummy_b
->type
!= bp_call_dummy
7317 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7320 dummy_frame_discard (dummy_b
->frame_id
, tp
);
7322 while (b
->related_breakpoint
!= b
)
7324 if (b_tmp
== b
->related_breakpoint
)
7325 b_tmp
= b
->related_breakpoint
->next
;
7326 delete_breakpoint (b
->related_breakpoint
);
7328 delete_breakpoint (b
);
7333 enable_overlay_breakpoints (void)
7335 struct breakpoint
*b
;
7338 if (b
->type
== bp_overlay_event
)
7340 b
->enable_state
= bp_enabled
;
7341 update_global_location_list (UGLL_MAY_INSERT
);
7342 overlay_events_enabled
= 1;
7347 disable_overlay_breakpoints (void)
7349 struct breakpoint
*b
;
7352 if (b
->type
== bp_overlay_event
)
7354 b
->enable_state
= bp_disabled
;
7355 update_global_location_list (UGLL_DONT_INSERT
);
7356 overlay_events_enabled
= 0;
7360 /* Set an active std::terminate breakpoint for each std::terminate
7361 master breakpoint. */
7363 set_std_terminate_breakpoint (void)
7365 struct breakpoint
*b
, *b_tmp
;
7367 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7368 if (b
->pspace
== current_program_space
7369 && b
->type
== bp_std_terminate_master
)
7371 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7372 &momentary_breakpoint_ops
, 1);
7376 /* Delete all the std::terminate breakpoints. */
7378 delete_std_terminate_breakpoint (void)
7380 struct breakpoint
*b
, *b_tmp
;
7382 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7383 if (b
->type
== bp_std_terminate
)
7384 delete_breakpoint (b
);
7388 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7390 struct breakpoint
*b
;
7392 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7393 &internal_breakpoint_ops
);
7395 b
->enable_state
= bp_enabled
;
7396 /* location has to be used or breakpoint_re_set will delete me. */
7397 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7399 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7404 struct lang_and_radix
7410 /* Create a breakpoint for JIT code registration and unregistration. */
7413 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7415 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7416 &internal_breakpoint_ops
);
7419 /* Remove JIT code registration and unregistration breakpoint(s). */
7422 remove_jit_event_breakpoints (void)
7424 struct breakpoint
*b
, *b_tmp
;
7426 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7427 if (b
->type
== bp_jit_event
7428 && b
->loc
->pspace
== current_program_space
)
7429 delete_breakpoint (b
);
7433 remove_solib_event_breakpoints (void)
7435 struct breakpoint
*b
, *b_tmp
;
7437 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7438 if (b
->type
== bp_shlib_event
7439 && b
->loc
->pspace
== current_program_space
)
7440 delete_breakpoint (b
);
7443 /* See breakpoint.h. */
7446 remove_solib_event_breakpoints_at_next_stop (void)
7448 struct breakpoint
*b
, *b_tmp
;
7450 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7451 if (b
->type
== bp_shlib_event
7452 && b
->loc
->pspace
== current_program_space
)
7453 b
->disposition
= disp_del_at_next_stop
;
7456 /* Helper for create_solib_event_breakpoint /
7457 create_and_insert_solib_event_breakpoint. Allows specifying which
7458 INSERT_MODE to pass through to update_global_location_list. */
7460 static struct breakpoint
*
7461 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7462 enum ugll_insert_mode insert_mode
)
7464 struct breakpoint
*b
;
7466 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7467 &internal_breakpoint_ops
);
7468 update_global_location_list_nothrow (insert_mode
);
7473 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7475 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7478 /* See breakpoint.h. */
7481 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7483 struct breakpoint
*b
;
7485 /* Explicitly tell update_global_location_list to insert
7487 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7488 if (!b
->loc
->inserted
)
7490 delete_breakpoint (b
);
7496 /* Disable any breakpoints that are on code in shared libraries. Only
7497 apply to enabled breakpoints, disabled ones can just stay disabled. */
7500 disable_breakpoints_in_shlibs (void)
7502 struct bp_location
*loc
, **locp_tmp
;
7504 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7506 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7507 struct breakpoint
*b
= loc
->owner
;
7509 /* We apply the check to all breakpoints, including disabled for
7510 those with loc->duplicate set. This is so that when breakpoint
7511 becomes enabled, or the duplicate is removed, gdb will try to
7512 insert all breakpoints. If we don't set shlib_disabled here,
7513 we'll try to insert those breakpoints and fail. */
7514 if (((b
->type
== bp_breakpoint
)
7515 || (b
->type
== bp_jit_event
)
7516 || (b
->type
== bp_hardware_breakpoint
)
7517 || (is_tracepoint (b
)))
7518 && loc
->pspace
== current_program_space
7519 && !loc
->shlib_disabled
7520 && solib_name_from_address (loc
->pspace
, loc
->address
)
7523 loc
->shlib_disabled
= 1;
7528 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7529 notification of unloaded_shlib. Only apply to enabled breakpoints,
7530 disabled ones can just stay disabled. */
7533 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7535 struct bp_location
*loc
, **locp_tmp
;
7536 int disabled_shlib_breaks
= 0;
7538 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7540 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7541 struct breakpoint
*b
= loc
->owner
;
7543 if (solib
->pspace
== loc
->pspace
7544 && !loc
->shlib_disabled
7545 && (((b
->type
== bp_breakpoint
7546 || b
->type
== bp_jit_event
7547 || b
->type
== bp_hardware_breakpoint
)
7548 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7549 || loc
->loc_type
== bp_loc_software_breakpoint
))
7550 || is_tracepoint (b
))
7551 && solib_contains_address_p (solib
, loc
->address
))
7553 loc
->shlib_disabled
= 1;
7554 /* At this point, we cannot rely on remove_breakpoint
7555 succeeding so we must mark the breakpoint as not inserted
7556 to prevent future errors occurring in remove_breakpoints. */
7559 /* This may cause duplicate notifications for the same breakpoint. */
7560 gdb::observers::breakpoint_modified
.notify (b
);
7562 if (!disabled_shlib_breaks
)
7564 target_terminal::ours_for_output ();
7565 warning (_("Temporarily disabling breakpoints "
7566 "for unloaded shared library \"%s\""),
7569 disabled_shlib_breaks
= 1;
7574 /* Disable any breakpoints and tracepoints in OBJFILE upon
7575 notification of free_objfile. Only apply to enabled breakpoints,
7576 disabled ones can just stay disabled. */
7579 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7581 struct breakpoint
*b
;
7583 if (objfile
== NULL
)
7586 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7587 managed by the user with add-symbol-file/remove-symbol-file.
7588 Similarly to how breakpoints in shared libraries are handled in
7589 response to "nosharedlibrary", mark breakpoints in such modules
7590 shlib_disabled so they end up uninserted on the next global
7591 location list update. Shared libraries not loaded by the user
7592 aren't handled here -- they're already handled in
7593 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7594 solib_unloaded observer. We skip objfiles that are not
7595 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7597 if ((objfile
->flags
& OBJF_SHARED
) == 0
7598 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7603 struct bp_location
*loc
;
7604 int bp_modified
= 0;
7606 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7609 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7611 CORE_ADDR loc_addr
= loc
->address
;
7613 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7614 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7617 if (loc
->shlib_disabled
!= 0)
7620 if (objfile
->pspace
!= loc
->pspace
)
7623 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7624 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7627 if (is_addr_in_objfile (loc_addr
, objfile
))
7629 loc
->shlib_disabled
= 1;
7630 /* At this point, we don't know whether the object was
7631 unmapped from the inferior or not, so leave the
7632 inserted flag alone. We'll handle failure to
7633 uninsert quietly, in case the object was indeed
7636 mark_breakpoint_location_modified (loc
);
7643 gdb::observers::breakpoint_modified
.notify (b
);
7647 /* FORK & VFORK catchpoints. */
7649 /* An instance of this type is used to represent a fork or vfork
7650 catchpoint. A breakpoint is really of this type iff its ops pointer points
7651 to CATCH_FORK_BREAKPOINT_OPS. */
7653 struct fork_catchpoint
: public breakpoint
7655 /* Process id of a child process whose forking triggered this
7656 catchpoint. This field is only valid immediately after this
7657 catchpoint has triggered. */
7658 ptid_t forked_inferior_pid
;
7661 /* Implement the "insert" breakpoint_ops method for fork
7665 insert_catch_fork (struct bp_location
*bl
)
7667 return target_insert_fork_catchpoint (inferior_ptid
.pid ());
7670 /* Implement the "remove" breakpoint_ops method for fork
7674 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7676 return target_remove_fork_catchpoint (inferior_ptid
.pid ());
7679 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7683 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7684 const address_space
*aspace
, CORE_ADDR bp_addr
,
7685 const struct target_waitstatus
*ws
)
7687 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7689 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7692 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7696 /* Implement the "print_it" breakpoint_ops method for fork
7699 static enum print_stop_action
7700 print_it_catch_fork (bpstat bs
)
7702 struct ui_out
*uiout
= current_uiout
;
7703 struct breakpoint
*b
= bs
->breakpoint_at
;
7704 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7706 annotate_catchpoint (b
->number
);
7707 maybe_print_thread_hit_breakpoint (uiout
);
7708 if (b
->disposition
== disp_del
)
7709 uiout
->text ("Temporary catchpoint ");
7711 uiout
->text ("Catchpoint ");
7712 if (uiout
->is_mi_like_p ())
7714 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7715 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7717 uiout
->field_int ("bkptno", b
->number
);
7718 uiout
->text (" (forked process ");
7719 uiout
->field_int ("newpid", c
->forked_inferior_pid
.pid ());
7720 uiout
->text ("), ");
7721 return PRINT_SRC_AND_LOC
;
7724 /* Implement the "print_one" breakpoint_ops method for fork
7728 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7730 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7731 struct value_print_options opts
;
7732 struct ui_out
*uiout
= current_uiout
;
7734 get_user_print_options (&opts
);
7736 /* Field 4, the address, is omitted (which makes the columns not
7737 line up too nicely with the headers, but the effect is relatively
7739 if (opts
.addressprint
)
7740 uiout
->field_skip ("addr");
7742 uiout
->text ("fork");
7743 if (c
->forked_inferior_pid
!= null_ptid
)
7745 uiout
->text (", process ");
7746 uiout
->field_int ("what", c
->forked_inferior_pid
.pid ());
7750 if (uiout
->is_mi_like_p ())
7751 uiout
->field_string ("catch-type", "fork");
7754 /* Implement the "print_mention" breakpoint_ops method for fork
7758 print_mention_catch_fork (struct breakpoint
*b
)
7760 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7763 /* Implement the "print_recreate" breakpoint_ops method for fork
7767 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7769 fprintf_unfiltered (fp
, "catch fork");
7770 print_recreate_thread (b
, fp
);
7773 /* The breakpoint_ops structure to be used in fork catchpoints. */
7775 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7777 /* Implement the "insert" breakpoint_ops method for vfork
7781 insert_catch_vfork (struct bp_location
*bl
)
7783 return target_insert_vfork_catchpoint (inferior_ptid
.pid ());
7786 /* Implement the "remove" breakpoint_ops method for vfork
7790 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7792 return target_remove_vfork_catchpoint (inferior_ptid
.pid ());
7795 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7799 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7800 const address_space
*aspace
, CORE_ADDR bp_addr
,
7801 const struct target_waitstatus
*ws
)
7803 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7805 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7808 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7812 /* Implement the "print_it" breakpoint_ops method for vfork
7815 static enum print_stop_action
7816 print_it_catch_vfork (bpstat bs
)
7818 struct ui_out
*uiout
= current_uiout
;
7819 struct breakpoint
*b
= bs
->breakpoint_at
;
7820 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7822 annotate_catchpoint (b
->number
);
7823 maybe_print_thread_hit_breakpoint (uiout
);
7824 if (b
->disposition
== disp_del
)
7825 uiout
->text ("Temporary catchpoint ");
7827 uiout
->text ("Catchpoint ");
7828 if (uiout
->is_mi_like_p ())
7830 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7831 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7833 uiout
->field_int ("bkptno", b
->number
);
7834 uiout
->text (" (vforked process ");
7835 uiout
->field_int ("newpid", c
->forked_inferior_pid
.pid ());
7836 uiout
->text ("), ");
7837 return PRINT_SRC_AND_LOC
;
7840 /* Implement the "print_one" breakpoint_ops method for vfork
7844 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7846 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7847 struct value_print_options opts
;
7848 struct ui_out
*uiout
= current_uiout
;
7850 get_user_print_options (&opts
);
7851 /* Field 4, the address, is omitted (which makes the columns not
7852 line up too nicely with the headers, but the effect is relatively
7854 if (opts
.addressprint
)
7855 uiout
->field_skip ("addr");
7857 uiout
->text ("vfork");
7858 if (c
->forked_inferior_pid
!= null_ptid
)
7860 uiout
->text (", process ");
7861 uiout
->field_int ("what", c
->forked_inferior_pid
.pid ());
7865 if (uiout
->is_mi_like_p ())
7866 uiout
->field_string ("catch-type", "vfork");
7869 /* Implement the "print_mention" breakpoint_ops method for vfork
7873 print_mention_catch_vfork (struct breakpoint
*b
)
7875 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
7878 /* Implement the "print_recreate" breakpoint_ops method for vfork
7882 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
7884 fprintf_unfiltered (fp
, "catch vfork");
7885 print_recreate_thread (b
, fp
);
7888 /* The breakpoint_ops structure to be used in vfork catchpoints. */
7890 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
7892 /* An instance of this type is used to represent an solib catchpoint.
7893 A breakpoint is really of this type iff its ops pointer points to
7894 CATCH_SOLIB_BREAKPOINT_OPS. */
7896 struct solib_catchpoint
: public breakpoint
7898 ~solib_catchpoint () override
;
7900 /* True for "catch load", false for "catch unload". */
7901 unsigned char is_load
;
7903 /* Regular expression to match, if any. COMPILED is only valid when
7904 REGEX is non-NULL. */
7906 std::unique_ptr
<compiled_regex
> compiled
;
7909 solib_catchpoint::~solib_catchpoint ()
7911 xfree (this->regex
);
7915 insert_catch_solib (struct bp_location
*ignore
)
7921 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
7927 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
7928 const address_space
*aspace
,
7930 const struct target_waitstatus
*ws
)
7932 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
7933 struct breakpoint
*other
;
7935 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
7938 ALL_BREAKPOINTS (other
)
7940 struct bp_location
*other_bl
;
7942 if (other
== bl
->owner
)
7945 if (other
->type
!= bp_shlib_event
)
7948 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
7951 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
7953 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
7962 check_status_catch_solib (struct bpstats
*bs
)
7964 struct solib_catchpoint
*self
7965 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
7969 for (so_list
*iter
: current_program_space
->added_solibs
)
7972 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
7978 for (const std::string
&iter
: current_program_space
->deleted_solibs
)
7981 || self
->compiled
->exec (iter
.c_str (), 0, NULL
, 0) == 0)
7987 bs
->print_it
= print_it_noop
;
7990 static enum print_stop_action
7991 print_it_catch_solib (bpstat bs
)
7993 struct breakpoint
*b
= bs
->breakpoint_at
;
7994 struct ui_out
*uiout
= current_uiout
;
7996 annotate_catchpoint (b
->number
);
7997 maybe_print_thread_hit_breakpoint (uiout
);
7998 if (b
->disposition
== disp_del
)
7999 uiout
->text ("Temporary catchpoint ");
8001 uiout
->text ("Catchpoint ");
8002 uiout
->field_int ("bkptno", b
->number
);
8004 if (uiout
->is_mi_like_p ())
8005 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8006 print_solib_event (1);
8007 return PRINT_SRC_AND_LOC
;
8011 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8013 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8014 struct value_print_options opts
;
8015 struct ui_out
*uiout
= current_uiout
;
8017 get_user_print_options (&opts
);
8018 /* Field 4, the address, is omitted (which makes the columns not
8019 line up too nicely with the headers, but the effect is relatively
8021 if (opts
.addressprint
)
8024 uiout
->field_skip ("addr");
8032 msg
= string_printf (_("load of library matching %s"), self
->regex
);
8034 msg
= _("load of library");
8039 msg
= string_printf (_("unload of library matching %s"), self
->regex
);
8041 msg
= _("unload of library");
8043 uiout
->field_string ("what", msg
);
8045 if (uiout
->is_mi_like_p ())
8046 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8050 print_mention_catch_solib (struct breakpoint
*b
)
8052 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8054 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8055 self
->is_load
? "load" : "unload");
8059 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8061 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8063 fprintf_unfiltered (fp
, "%s %s",
8064 b
->disposition
== disp_del
? "tcatch" : "catch",
8065 self
->is_load
? "load" : "unload");
8067 fprintf_unfiltered (fp
, " %s", self
->regex
);
8068 fprintf_unfiltered (fp
, "\n");
8071 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8073 /* Shared helper function (MI and CLI) for creating and installing
8074 a shared object event catchpoint. If IS_LOAD is non-zero then
8075 the events to be caught are load events, otherwise they are
8076 unload events. If IS_TEMP is non-zero the catchpoint is a
8077 temporary one. If ENABLED is non-zero the catchpoint is
8078 created in an enabled state. */
8081 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8083 struct gdbarch
*gdbarch
= get_current_arch ();
8087 arg
= skip_spaces (arg
);
8089 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8093 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8094 _("Invalid regexp")));
8095 c
->regex
= xstrdup (arg
);
8098 c
->is_load
= is_load
;
8099 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8100 &catch_solib_breakpoint_ops
);
8102 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8104 install_breakpoint (0, std::move (c
), 1);
8107 /* A helper function that does all the work for "catch load" and
8111 catch_load_or_unload (const char *arg
, int from_tty
, int is_load
,
8112 struct cmd_list_element
*command
)
8115 const int enabled
= 1;
8117 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8119 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8123 catch_load_command_1 (const char *arg
, int from_tty
,
8124 struct cmd_list_element
*command
)
8126 catch_load_or_unload (arg
, from_tty
, 1, command
);
8130 catch_unload_command_1 (const char *arg
, int from_tty
,
8131 struct cmd_list_element
*command
)
8133 catch_load_or_unload (arg
, from_tty
, 0, command
);
8136 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8137 is non-zero, then make the breakpoint temporary. If COND_STRING is
8138 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8139 the breakpoint_ops structure associated to the catchpoint. */
8142 init_catchpoint (struct breakpoint
*b
,
8143 struct gdbarch
*gdbarch
, int tempflag
,
8144 const char *cond_string
,
8145 const struct breakpoint_ops
*ops
)
8147 symtab_and_line sal
;
8148 sal
.pspace
= current_program_space
;
8150 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8152 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8153 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8157 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8159 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8160 set_breakpoint_number (internal
, b
);
8161 if (is_tracepoint (b
))
8162 set_tracepoint_count (breakpoint_count
);
8165 gdb::observers::breakpoint_created
.notify (b
);
8168 update_global_location_list (UGLL_MAY_INSERT
);
8172 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8173 int tempflag
, const char *cond_string
,
8174 const struct breakpoint_ops
*ops
)
8176 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8178 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8180 c
->forked_inferior_pid
= null_ptid
;
8182 install_breakpoint (0, std::move (c
), 1);
8185 /* Exec catchpoints. */
8187 /* An instance of this type is used to represent an exec catchpoint.
8188 A breakpoint is really of this type iff its ops pointer points to
8189 CATCH_EXEC_BREAKPOINT_OPS. */
8191 struct exec_catchpoint
: public breakpoint
8193 ~exec_catchpoint () override
;
8195 /* Filename of a program whose exec triggered this catchpoint.
8196 This field is only valid immediately after this catchpoint has
8198 char *exec_pathname
;
8201 /* Exec catchpoint destructor. */
8203 exec_catchpoint::~exec_catchpoint ()
8205 xfree (this->exec_pathname
);
8209 insert_catch_exec (struct bp_location
*bl
)
8211 return target_insert_exec_catchpoint (inferior_ptid
.pid ());
8215 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8217 return target_remove_exec_catchpoint (inferior_ptid
.pid ());
8221 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8222 const address_space
*aspace
, CORE_ADDR bp_addr
,
8223 const struct target_waitstatus
*ws
)
8225 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8227 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8230 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8234 static enum print_stop_action
8235 print_it_catch_exec (bpstat bs
)
8237 struct ui_out
*uiout
= current_uiout
;
8238 struct breakpoint
*b
= bs
->breakpoint_at
;
8239 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8241 annotate_catchpoint (b
->number
);
8242 maybe_print_thread_hit_breakpoint (uiout
);
8243 if (b
->disposition
== disp_del
)
8244 uiout
->text ("Temporary catchpoint ");
8246 uiout
->text ("Catchpoint ");
8247 if (uiout
->is_mi_like_p ())
8249 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8250 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8252 uiout
->field_int ("bkptno", b
->number
);
8253 uiout
->text (" (exec'd ");
8254 uiout
->field_string ("new-exec", c
->exec_pathname
);
8255 uiout
->text ("), ");
8257 return PRINT_SRC_AND_LOC
;
8261 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8263 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8264 struct value_print_options opts
;
8265 struct ui_out
*uiout
= current_uiout
;
8267 get_user_print_options (&opts
);
8269 /* Field 4, the address, is omitted (which makes the columns
8270 not line up too nicely with the headers, but the effect
8271 is relatively readable). */
8272 if (opts
.addressprint
)
8273 uiout
->field_skip ("addr");
8275 uiout
->text ("exec");
8276 if (c
->exec_pathname
!= NULL
)
8278 uiout
->text (", program \"");
8279 uiout
->field_string ("what", c
->exec_pathname
);
8280 uiout
->text ("\" ");
8283 if (uiout
->is_mi_like_p ())
8284 uiout
->field_string ("catch-type", "exec");
8288 print_mention_catch_exec (struct breakpoint
*b
)
8290 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8293 /* Implement the "print_recreate" breakpoint_ops method for exec
8297 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8299 fprintf_unfiltered (fp
, "catch exec");
8300 print_recreate_thread (b
, fp
);
8303 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8306 hw_breakpoint_used_count (void)
8309 struct breakpoint
*b
;
8310 struct bp_location
*bl
;
8314 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8315 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8317 /* Special types of hardware breakpoints may use more than
8319 i
+= b
->ops
->resources_needed (bl
);
8326 /* Returns the resources B would use if it were a hardware
8330 hw_watchpoint_use_count (struct breakpoint
*b
)
8333 struct bp_location
*bl
;
8335 if (!breakpoint_enabled (b
))
8338 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8340 /* Special types of hardware watchpoints may use more than
8342 i
+= b
->ops
->resources_needed (bl
);
8348 /* Returns the sum the used resources of all hardware watchpoints of
8349 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8350 the sum of the used resources of all hardware watchpoints of other
8351 types _not_ TYPE. */
8354 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8355 enum bptype type
, int *other_type_used
)
8358 struct breakpoint
*b
;
8360 *other_type_used
= 0;
8365 if (!breakpoint_enabled (b
))
8368 if (b
->type
== type
)
8369 i
+= hw_watchpoint_use_count (b
);
8370 else if (is_hardware_watchpoint (b
))
8371 *other_type_used
= 1;
8378 disable_watchpoints_before_interactive_call_start (void)
8380 struct breakpoint
*b
;
8384 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8386 b
->enable_state
= bp_call_disabled
;
8387 update_global_location_list (UGLL_DONT_INSERT
);
8393 enable_watchpoints_after_interactive_call_stop (void)
8395 struct breakpoint
*b
;
8399 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8401 b
->enable_state
= bp_enabled
;
8402 update_global_location_list (UGLL_MAY_INSERT
);
8408 disable_breakpoints_before_startup (void)
8410 current_program_space
->executing_startup
= 1;
8411 update_global_location_list (UGLL_DONT_INSERT
);
8415 enable_breakpoints_after_startup (void)
8417 current_program_space
->executing_startup
= 0;
8418 breakpoint_re_set ();
8421 /* Create a new single-step breakpoint for thread THREAD, with no
8424 static struct breakpoint
*
8425 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8427 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8429 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8430 &momentary_breakpoint_ops
);
8432 b
->disposition
= disp_donttouch
;
8433 b
->frame_id
= null_frame_id
;
8436 gdb_assert (b
->thread
!= 0);
8438 return add_to_breakpoint_chain (std::move (b
));
8441 /* Set a momentary breakpoint of type TYPE at address specified by
8442 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8446 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8447 struct frame_id frame_id
, enum bptype type
)
8449 struct breakpoint
*b
;
8451 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8453 gdb_assert (!frame_id_artificial_p (frame_id
));
8455 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8456 b
->enable_state
= bp_enabled
;
8457 b
->disposition
= disp_donttouch
;
8458 b
->frame_id
= frame_id
;
8460 b
->thread
= inferior_thread ()->global_num
;
8462 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8464 return breakpoint_up (b
);
8467 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8468 The new breakpoint will have type TYPE, use OPS as its
8469 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8471 static struct breakpoint
*
8472 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8474 const struct breakpoint_ops
*ops
,
8477 struct breakpoint
*copy
;
8479 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8480 copy
->loc
= allocate_bp_location (copy
);
8481 set_breakpoint_location_function (copy
->loc
);
8483 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8484 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8485 copy
->loc
->address
= orig
->loc
->address
;
8486 copy
->loc
->section
= orig
->loc
->section
;
8487 copy
->loc
->pspace
= orig
->loc
->pspace
;
8488 copy
->loc
->probe
= orig
->loc
->probe
;
8489 copy
->loc
->line_number
= orig
->loc
->line_number
;
8490 copy
->loc
->symtab
= orig
->loc
->symtab
;
8491 copy
->loc
->enabled
= loc_enabled
;
8492 copy
->frame_id
= orig
->frame_id
;
8493 copy
->thread
= orig
->thread
;
8494 copy
->pspace
= orig
->pspace
;
8496 copy
->enable_state
= bp_enabled
;
8497 copy
->disposition
= disp_donttouch
;
8498 copy
->number
= internal_breakpoint_number
--;
8500 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8504 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8508 clone_momentary_breakpoint (struct breakpoint
*orig
)
8510 /* If there's nothing to clone, then return nothing. */
8514 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8518 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8521 struct symtab_and_line sal
;
8523 sal
= find_pc_line (pc
, 0);
8525 sal
.section
= find_pc_overlay (pc
);
8526 sal
.explicit_pc
= 1;
8528 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8532 /* Tell the user we have just set a breakpoint B. */
8535 mention (struct breakpoint
*b
)
8537 b
->ops
->print_mention (b
);
8538 current_uiout
->text ("\n");
8542 static int bp_loc_is_permanent (struct bp_location
*loc
);
8544 static struct bp_location
*
8545 add_location_to_breakpoint (struct breakpoint
*b
,
8546 const struct symtab_and_line
*sal
)
8548 struct bp_location
*loc
, **tmp
;
8549 CORE_ADDR adjusted_address
;
8550 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8552 if (loc_gdbarch
== NULL
)
8553 loc_gdbarch
= b
->gdbarch
;
8555 /* Adjust the breakpoint's address prior to allocating a location.
8556 Once we call allocate_bp_location(), that mostly uninitialized
8557 location will be placed on the location chain. Adjustment of the
8558 breakpoint may cause target_read_memory() to be called and we do
8559 not want its scan of the location chain to find a breakpoint and
8560 location that's only been partially initialized. */
8561 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8564 /* Sort the locations by their ADDRESS. */
8565 loc
= allocate_bp_location (b
);
8566 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8567 tmp
= &((*tmp
)->next
))
8572 loc
->requested_address
= sal
->pc
;
8573 loc
->address
= adjusted_address
;
8574 loc
->pspace
= sal
->pspace
;
8575 loc
->probe
.prob
= sal
->prob
;
8576 loc
->probe
.objfile
= sal
->objfile
;
8577 gdb_assert (loc
->pspace
!= NULL
);
8578 loc
->section
= sal
->section
;
8579 loc
->gdbarch
= loc_gdbarch
;
8580 loc
->line_number
= sal
->line
;
8581 loc
->symtab
= sal
->symtab
;
8582 loc
->symbol
= sal
->symbol
;
8583 loc
->msymbol
= sal
->msymbol
;
8584 loc
->objfile
= sal
->objfile
;
8586 set_breakpoint_location_function (loc
);
8588 /* While by definition, permanent breakpoints are already present in the
8589 code, we don't mark the location as inserted. Normally one would expect
8590 that GDB could rely on that breakpoint instruction to stop the program,
8591 thus removing the need to insert its own breakpoint, except that executing
8592 the breakpoint instruction can kill the target instead of reporting a
8593 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8594 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8595 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8596 breakpoint be inserted normally results in QEMU knowing about the GDB
8597 breakpoint, and thus trap before the breakpoint instruction is executed.
8598 (If GDB later needs to continue execution past the permanent breakpoint,
8599 it manually increments the PC, thus avoiding executing the breakpoint
8601 if (bp_loc_is_permanent (loc
))
8608 /* See breakpoint.h. */
8611 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8615 const gdb_byte
*bpoint
;
8616 gdb_byte
*target_mem
;
8619 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8621 /* Software breakpoints unsupported? */
8625 target_mem
= (gdb_byte
*) alloca (len
);
8627 /* Enable the automatic memory restoration from breakpoints while
8628 we read the memory. Otherwise we could say about our temporary
8629 breakpoints they are permanent. */
8630 scoped_restore restore_memory
8631 = make_scoped_restore_show_memory_breakpoints (0);
8633 if (target_read_memory (address
, target_mem
, len
) == 0
8634 && memcmp (target_mem
, bpoint
, len
) == 0)
8640 /* Return 1 if LOC is pointing to a permanent breakpoint,
8641 return 0 otherwise. */
8644 bp_loc_is_permanent (struct bp_location
*loc
)
8646 gdb_assert (loc
!= NULL
);
8648 /* If we have a catchpoint or a watchpoint, just return 0. We should not
8649 attempt to read from the addresses the locations of these breakpoint types
8650 point to. program_breakpoint_here_p, below, will attempt to read
8652 if (!breakpoint_address_is_meaningful (loc
->owner
))
8655 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8656 switch_to_program_space_and_thread (loc
->pspace
);
8657 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8660 /* Build a command list for the dprintf corresponding to the current
8661 settings of the dprintf style options. */
8664 update_dprintf_command_list (struct breakpoint
*b
)
8666 char *dprintf_args
= b
->extra_string
;
8667 char *printf_line
= NULL
;
8672 dprintf_args
= skip_spaces (dprintf_args
);
8674 /* Allow a comma, as it may have terminated a location, but don't
8676 if (*dprintf_args
== ',')
8678 dprintf_args
= skip_spaces (dprintf_args
);
8680 if (*dprintf_args
!= '"')
8681 error (_("Bad format string, missing '\"'."));
8683 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8684 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8685 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8687 if (!dprintf_function
)
8688 error (_("No function supplied for dprintf call"));
8690 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8691 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8696 printf_line
= xstrprintf ("call (void) %s (%s)",
8700 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8702 if (target_can_run_breakpoint_commands ())
8703 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8706 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8707 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8711 internal_error (__FILE__
, __LINE__
,
8712 _("Invalid dprintf style."));
8714 gdb_assert (printf_line
!= NULL
);
8716 /* Manufacture a printf sequence. */
8717 struct command_line
*printf_cmd_line
8718 = new struct command_line (simple_control
, printf_line
);
8719 breakpoint_set_commands (b
, counted_command_line (printf_cmd_line
,
8720 command_lines_deleter ()));
8723 /* Update all dprintf commands, making their command lists reflect
8724 current style settings. */
8727 update_dprintf_commands (const char *args
, int from_tty
,
8728 struct cmd_list_element
*c
)
8730 struct breakpoint
*b
;
8734 if (b
->type
== bp_dprintf
)
8735 update_dprintf_command_list (b
);
8739 /* Create a breakpoint with SAL as location. Use LOCATION
8740 as a description of the location, and COND_STRING
8741 as condition expression. If LOCATION is NULL then create an
8742 "address location" from the address in the SAL. */
8745 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8746 gdb::array_view
<const symtab_and_line
> sals
,
8747 event_location_up
&&location
,
8748 gdb::unique_xmalloc_ptr
<char> filter
,
8749 gdb::unique_xmalloc_ptr
<char> cond_string
,
8750 gdb::unique_xmalloc_ptr
<char> extra_string
,
8751 enum bptype type
, enum bpdisp disposition
,
8752 int thread
, int task
, int ignore_count
,
8753 const struct breakpoint_ops
*ops
, int from_tty
,
8754 int enabled
, int internal
, unsigned flags
,
8755 int display_canonical
)
8759 if (type
== bp_hardware_breakpoint
)
8761 int target_resources_ok
;
8763 i
= hw_breakpoint_used_count ();
8764 target_resources_ok
=
8765 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8767 if (target_resources_ok
== 0)
8768 error (_("No hardware breakpoint support in the target."));
8769 else if (target_resources_ok
< 0)
8770 error (_("Hardware breakpoints used exceeds limit."));
8773 gdb_assert (!sals
.empty ());
8775 for (const auto &sal
: sals
)
8777 struct bp_location
*loc
;
8781 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8783 loc_gdbarch
= gdbarch
;
8785 describe_other_breakpoints (loc_gdbarch
,
8786 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8789 if (&sal
== &sals
[0])
8791 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8795 b
->cond_string
= cond_string
.release ();
8796 b
->extra_string
= extra_string
.release ();
8797 b
->ignore_count
= ignore_count
;
8798 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8799 b
->disposition
= disposition
;
8801 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8802 b
->loc
->inserted
= 1;
8804 if (type
== bp_static_tracepoint
)
8806 struct tracepoint
*t
= (struct tracepoint
*) b
;
8807 struct static_tracepoint_marker marker
;
8809 if (strace_marker_p (b
))
8811 /* We already know the marker exists, otherwise, we
8812 wouldn't see a sal for it. */
8814 = &event_location_to_string (b
->location
.get ())[3];
8817 p
= skip_spaces (p
);
8819 endp
= skip_to_space (p
);
8821 t
->static_trace_marker_id
.assign (p
, endp
- p
);
8823 printf_filtered (_("Probed static tracepoint "
8825 t
->static_trace_marker_id
.c_str ());
8827 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8829 t
->static_trace_marker_id
= std::move (marker
.str_id
);
8831 printf_filtered (_("Probed static tracepoint "
8833 t
->static_trace_marker_id
.c_str ());
8836 warning (_("Couldn't determine the static "
8837 "tracepoint marker to probe"));
8844 loc
= add_location_to_breakpoint (b
, &sal
);
8845 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8851 const char *arg
= b
->cond_string
;
8853 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
8854 block_for_pc (loc
->address
), 0);
8856 error (_("Garbage '%s' follows condition"), arg
);
8859 /* Dynamic printf requires and uses additional arguments on the
8860 command line, otherwise it's an error. */
8861 if (type
== bp_dprintf
)
8863 if (b
->extra_string
)
8864 update_dprintf_command_list (b
);
8866 error (_("Format string required"));
8868 else if (b
->extra_string
)
8869 error (_("Garbage '%s' at end of command"), b
->extra_string
);
8872 b
->display_canonical
= display_canonical
;
8873 if (location
!= NULL
)
8874 b
->location
= std::move (location
);
8876 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
8877 b
->filter
= filter
.release ();
8881 create_breakpoint_sal (struct gdbarch
*gdbarch
,
8882 gdb::array_view
<const symtab_and_line
> sals
,
8883 event_location_up
&&location
,
8884 gdb::unique_xmalloc_ptr
<char> filter
,
8885 gdb::unique_xmalloc_ptr
<char> cond_string
,
8886 gdb::unique_xmalloc_ptr
<char> extra_string
,
8887 enum bptype type
, enum bpdisp disposition
,
8888 int thread
, int task
, int ignore_count
,
8889 const struct breakpoint_ops
*ops
, int from_tty
,
8890 int enabled
, int internal
, unsigned flags
,
8891 int display_canonical
)
8893 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
8895 init_breakpoint_sal (b
.get (), gdbarch
,
8896 sals
, std::move (location
),
8898 std::move (cond_string
),
8899 std::move (extra_string
),
8901 thread
, task
, ignore_count
,
8903 enabled
, internal
, flags
,
8906 install_breakpoint (internal
, std::move (b
), 0);
8909 /* Add SALS.nelts breakpoints to the breakpoint table. For each
8910 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
8911 value. COND_STRING, if not NULL, specified the condition to be
8912 used for all breakpoints. Essentially the only case where
8913 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
8914 function. In that case, it's still not possible to specify
8915 separate conditions for different overloaded functions, so
8916 we take just a single condition string.
8918 NOTE: If the function succeeds, the caller is expected to cleanup
8919 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
8920 array contents). If the function fails (error() is called), the
8921 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
8922 COND and SALS arrays and each of those arrays contents. */
8925 create_breakpoints_sal (struct gdbarch
*gdbarch
,
8926 struct linespec_result
*canonical
,
8927 gdb::unique_xmalloc_ptr
<char> cond_string
,
8928 gdb::unique_xmalloc_ptr
<char> extra_string
,
8929 enum bptype type
, enum bpdisp disposition
,
8930 int thread
, int task
, int ignore_count
,
8931 const struct breakpoint_ops
*ops
, int from_tty
,
8932 int enabled
, int internal
, unsigned flags
)
8934 if (canonical
->pre_expanded
)
8935 gdb_assert (canonical
->lsals
.size () == 1);
8937 for (const auto &lsal
: canonical
->lsals
)
8939 /* Note that 'location' can be NULL in the case of a plain
8940 'break', without arguments. */
8941 event_location_up location
8942 = (canonical
->location
!= NULL
8943 ? copy_event_location (canonical
->location
.get ()) : NULL
);
8944 gdb::unique_xmalloc_ptr
<char> filter_string
8945 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
8947 create_breakpoint_sal (gdbarch
, lsal
.sals
,
8948 std::move (location
),
8949 std::move (filter_string
),
8950 std::move (cond_string
),
8951 std::move (extra_string
),
8953 thread
, task
, ignore_count
, ops
,
8954 from_tty
, enabled
, internal
, flags
,
8955 canonical
->special_display
);
8959 /* Parse LOCATION which is assumed to be a SAL specification possibly
8960 followed by conditionals. On return, SALS contains an array of SAL
8961 addresses found. LOCATION points to the end of the SAL (for
8962 linespec locations).
8964 The array and the line spec strings are allocated on the heap, it is
8965 the caller's responsibility to free them. */
8968 parse_breakpoint_sals (const struct event_location
*location
,
8969 struct linespec_result
*canonical
)
8971 struct symtab_and_line cursal
;
8973 if (event_location_type (location
) == LINESPEC_LOCATION
)
8975 const char *spec
= get_linespec_location (location
)->spec_string
;
8979 /* The last displayed codepoint, if it's valid, is our default
8980 breakpoint address. */
8981 if (last_displayed_sal_is_valid ())
8983 /* Set sal's pspace, pc, symtab, and line to the values
8984 corresponding to the last call to print_frame_info.
8985 Be sure to reinitialize LINE with NOTCURRENT == 0
8986 as the breakpoint line number is inappropriate otherwise.
8987 find_pc_line would adjust PC, re-set it back. */
8988 symtab_and_line sal
= get_last_displayed_sal ();
8989 CORE_ADDR pc
= sal
.pc
;
8991 sal
= find_pc_line (pc
, 0);
8993 /* "break" without arguments is equivalent to "break *PC"
8994 where PC is the last displayed codepoint's address. So
8995 make sure to set sal.explicit_pc to prevent GDB from
8996 trying to expand the list of sals to include all other
8997 instances with the same symtab and line. */
8999 sal
.explicit_pc
= 1;
9001 struct linespec_sals lsal
;
9003 lsal
.canonical
= NULL
;
9005 canonical
->lsals
.push_back (std::move (lsal
));
9009 error (_("No default breakpoint address now."));
9013 /* Force almost all breakpoints to be in terms of the
9014 current_source_symtab (which is decode_line_1's default).
9015 This should produce the results we want almost all of the
9016 time while leaving default_breakpoint_* alone.
9018 ObjC: However, don't match an Objective-C method name which
9019 may have a '+' or '-' succeeded by a '['. */
9020 cursal
= get_current_source_symtab_and_line ();
9021 if (last_displayed_sal_is_valid ())
9023 const char *spec
= NULL
;
9025 if (event_location_type (location
) == LINESPEC_LOCATION
)
9026 spec
= get_linespec_location (location
)->spec_string
;
9030 && strchr ("+-", spec
[0]) != NULL
9033 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9034 get_last_displayed_symtab (),
9035 get_last_displayed_line (),
9036 canonical
, NULL
, NULL
);
9041 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9042 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9046 /* Convert each SAL into a real PC. Verify that the PC can be
9047 inserted as a breakpoint. If it can't throw an error. */
9050 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9052 for (auto &sal
: sals
)
9053 resolve_sal_pc (&sal
);
9056 /* Fast tracepoints may have restrictions on valid locations. For
9057 instance, a fast tracepoint using a jump instead of a trap will
9058 likely have to overwrite more bytes than a trap would, and so can
9059 only be placed where the instruction is longer than the jump, or a
9060 multi-instruction sequence does not have a jump into the middle of
9064 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9065 gdb::array_view
<const symtab_and_line
> sals
)
9067 for (const auto &sal
: sals
)
9069 struct gdbarch
*sarch
;
9071 sarch
= get_sal_arch (sal
);
9072 /* We fall back to GDBARCH if there is no architecture
9073 associated with SAL. */
9077 if (!gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
))
9078 error (_("May not have a fast tracepoint at %s%s"),
9079 paddress (sarch
, sal
.pc
), msg
.c_str ());
9083 /* Given TOK, a string specification of condition and thread, as
9084 accepted by the 'break' command, extract the condition
9085 string and thread number and set *COND_STRING and *THREAD.
9086 PC identifies the context at which the condition should be parsed.
9087 If no condition is found, *COND_STRING is set to NULL.
9088 If no thread is found, *THREAD is set to -1. */
9091 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9092 char **cond_string
, int *thread
, int *task
,
9095 *cond_string
= NULL
;
9102 const char *end_tok
;
9104 const char *cond_start
= NULL
;
9105 const char *cond_end
= NULL
;
9107 tok
= skip_spaces (tok
);
9109 if ((*tok
== '"' || *tok
== ',') && rest
)
9111 *rest
= savestring (tok
, strlen (tok
));
9115 end_tok
= skip_to_space (tok
);
9117 toklen
= end_tok
- tok
;
9119 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9121 tok
= cond_start
= end_tok
+ 1;
9122 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9124 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9126 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9129 struct thread_info
*thr
;
9132 thr
= parse_thread_id (tok
, &tmptok
);
9134 error (_("Junk after thread keyword."));
9135 *thread
= thr
->global_num
;
9138 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9143 *task
= strtol (tok
, &tmptok
, 0);
9145 error (_("Junk after task keyword."));
9146 if (!valid_task_id (*task
))
9147 error (_("Unknown task %d."), *task
);
9152 *rest
= savestring (tok
, strlen (tok
));
9156 error (_("Junk at end of arguments."));
9160 /* Decode a static tracepoint marker spec. */
9162 static std::vector
<symtab_and_line
>
9163 decode_static_tracepoint_spec (const char **arg_p
)
9165 const char *p
= &(*arg_p
)[3];
9168 p
= skip_spaces (p
);
9170 endp
= skip_to_space (p
);
9172 std::string
marker_str (p
, endp
- p
);
9174 std::vector
<static_tracepoint_marker
> markers
9175 = target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9176 if (markers
.empty ())
9177 error (_("No known static tracepoint marker named %s"),
9178 marker_str
.c_str ());
9180 std::vector
<symtab_and_line
> sals
;
9181 sals
.reserve (markers
.size ());
9183 for (const static_tracepoint_marker
&marker
: markers
)
9185 symtab_and_line sal
= find_pc_line (marker
.address
, 0);
9186 sal
.pc
= marker
.address
;
9187 sals
.push_back (sal
);
9194 /* See breakpoint.h. */
9197 create_breakpoint (struct gdbarch
*gdbarch
,
9198 const struct event_location
*location
,
9199 const char *cond_string
,
9200 int thread
, const char *extra_string
,
9202 int tempflag
, enum bptype type_wanted
,
9204 enum auto_boolean pending_break_support
,
9205 const struct breakpoint_ops
*ops
,
9206 int from_tty
, int enabled
, int internal
,
9209 struct linespec_result canonical
;
9212 int prev_bkpt_count
= breakpoint_count
;
9214 gdb_assert (ops
!= NULL
);
9216 /* If extra_string isn't useful, set it to NULL. */
9217 if (extra_string
!= NULL
&& *extra_string
== '\0')
9218 extra_string
= NULL
;
9222 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9224 catch (const gdb_exception_error
&e
)
9226 /* If caller is interested in rc value from parse, set
9228 if (e
.error
== NOT_FOUND_ERROR
)
9230 /* If pending breakpoint support is turned off, throw
9233 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9236 exception_print (gdb_stderr
, e
);
9238 /* If pending breakpoint support is auto query and the user
9239 selects no, then simply return the error code. */
9240 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9241 && !nquery (_("Make %s pending on future shared library load? "),
9242 bptype_string (type_wanted
)))
9245 /* At this point, either the user was queried about setting
9246 a pending breakpoint and selected yes, or pending
9247 breakpoint behavior is on and thus a pending breakpoint
9248 is defaulted on behalf of the user. */
9255 if (!pending
&& canonical
.lsals
.empty ())
9258 /* Resolve all line numbers to PC's and verify that the addresses
9259 are ok for the target. */
9262 for (auto &lsal
: canonical
.lsals
)
9263 breakpoint_sals_to_pc (lsal
.sals
);
9266 /* Fast tracepoints may have additional restrictions on location. */
9267 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9269 for (const auto &lsal
: canonical
.lsals
)
9270 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9273 /* Verify that condition can be parsed, before setting any
9274 breakpoints. Allocate a separate condition expression for each
9278 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9279 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9286 const linespec_sals
&lsal
= canonical
.lsals
[0];
9288 /* Here we only parse 'arg' to separate condition
9289 from thread number, so parsing in context of first
9290 sal is OK. When setting the breakpoint we'll
9291 re-parse it in context of each sal. */
9293 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9294 &cond
, &thread
, &task
, &rest
);
9295 cond_string_copy
.reset (cond
);
9296 extra_string_copy
.reset (rest
);
9300 if (type_wanted
!= bp_dprintf
9301 && extra_string
!= NULL
&& *extra_string
!= '\0')
9302 error (_("Garbage '%s' at end of location"), extra_string
);
9304 /* Create a private copy of condition string. */
9306 cond_string_copy
.reset (xstrdup (cond_string
));
9307 /* Create a private copy of any extra string. */
9309 extra_string_copy
.reset (xstrdup (extra_string
));
9312 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9313 std::move (cond_string_copy
),
9314 std::move (extra_string_copy
),
9316 tempflag
? disp_del
: disp_donttouch
,
9317 thread
, task
, ignore_count
, ops
,
9318 from_tty
, enabled
, internal
, flags
);
9322 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9324 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9325 b
->location
= copy_event_location (location
);
9328 b
->cond_string
= NULL
;
9331 /* Create a private copy of condition string. */
9332 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9336 /* Create a private copy of any extra string. */
9337 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9338 b
->ignore_count
= ignore_count
;
9339 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9340 b
->condition_not_parsed
= 1;
9341 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9342 if ((type_wanted
!= bp_breakpoint
9343 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9344 b
->pspace
= current_program_space
;
9346 install_breakpoint (internal
, std::move (b
), 0);
9349 if (canonical
.lsals
.size () > 1)
9351 warning (_("Multiple breakpoints were set.\nUse the "
9352 "\"delete\" command to delete unwanted breakpoints."));
9353 prev_breakpoint_count
= prev_bkpt_count
;
9356 update_global_location_list (UGLL_MAY_INSERT
);
9361 /* Set a breakpoint.
9362 ARG is a string describing breakpoint address,
9363 condition, and thread.
9364 FLAG specifies if a breakpoint is hardware on,
9365 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9369 break_command_1 (const char *arg
, int flag
, int from_tty
)
9371 int tempflag
= flag
& BP_TEMPFLAG
;
9372 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9373 ? bp_hardware_breakpoint
9375 struct breakpoint_ops
*ops
;
9377 event_location_up location
= string_to_event_location (&arg
, current_language
);
9379 /* Matching breakpoints on probes. */
9380 if (location
!= NULL
9381 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9382 ops
= &bkpt_probe_breakpoint_ops
;
9384 ops
= &bkpt_breakpoint_ops
;
9386 create_breakpoint (get_current_arch (),
9388 NULL
, 0, arg
, 1 /* parse arg */,
9389 tempflag
, type_wanted
,
9390 0 /* Ignore count */,
9391 pending_break_support
,
9399 /* Helper function for break_command_1 and disassemble_command. */
9402 resolve_sal_pc (struct symtab_and_line
*sal
)
9406 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9408 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9409 error (_("No line %d in file \"%s\"."),
9410 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9413 /* If this SAL corresponds to a breakpoint inserted using a line
9414 number, then skip the function prologue if necessary. */
9415 if (sal
->explicit_line
)
9416 skip_prologue_sal (sal
);
9419 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9421 const struct blockvector
*bv
;
9422 const struct block
*b
;
9425 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9426 SYMTAB_COMPUNIT (sal
->symtab
));
9429 sym
= block_linkage_function (b
);
9432 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9433 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9438 /* It really is worthwhile to have the section, so we'll
9439 just have to look harder. This case can be executed
9440 if we have line numbers but no functions (as can
9441 happen in assembly source). */
9443 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9444 switch_to_program_space_and_thread (sal
->pspace
);
9446 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9448 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9455 break_command (const char *arg
, int from_tty
)
9457 break_command_1 (arg
, 0, from_tty
);
9461 tbreak_command (const char *arg
, int from_tty
)
9463 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9467 hbreak_command (const char *arg
, int from_tty
)
9469 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9473 thbreak_command (const char *arg
, int from_tty
)
9475 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9479 stop_command (const char *arg
, int from_tty
)
9481 printf_filtered (_("Specify the type of breakpoint to set.\n\
9482 Usage: stop in <function | address>\n\
9483 stop at <line>\n"));
9487 stopin_command (const char *arg
, int from_tty
)
9493 else if (*arg
!= '*')
9495 const char *argptr
= arg
;
9498 /* Look for a ':'. If this is a line number specification, then
9499 say it is bad, otherwise, it should be an address or
9500 function/method name. */
9501 while (*argptr
&& !hasColon
)
9503 hasColon
= (*argptr
== ':');
9508 badInput
= (*argptr
!= ':'); /* Not a class::method */
9510 badInput
= isdigit (*arg
); /* a simple line number */
9514 printf_filtered (_("Usage: stop in <function | address>\n"));
9516 break_command_1 (arg
, 0, from_tty
);
9520 stopat_command (const char *arg
, int from_tty
)
9524 if (arg
== NULL
|| *arg
== '*') /* no line number */
9528 const char *argptr
= arg
;
9531 /* Look for a ':'. If there is a '::' then get out, otherwise
9532 it is probably a line number. */
9533 while (*argptr
&& !hasColon
)
9535 hasColon
= (*argptr
== ':');
9540 badInput
= (*argptr
== ':'); /* we have class::method */
9542 badInput
= !isdigit (*arg
); /* not a line number */
9546 printf_filtered (_("Usage: stop at LINE\n"));
9548 break_command_1 (arg
, 0, from_tty
);
9551 /* The dynamic printf command is mostly like a regular breakpoint, but
9552 with a prewired command list consisting of a single output command,
9553 built from extra arguments supplied on the dprintf command
9557 dprintf_command (const char *arg
, int from_tty
)
9559 event_location_up location
= string_to_event_location (&arg
, current_language
);
9561 /* If non-NULL, ARG should have been advanced past the location;
9562 the next character must be ','. */
9565 if (arg
[0] != ',' || arg
[1] == '\0')
9566 error (_("Format string required"));
9569 /* Skip the comma. */
9574 create_breakpoint (get_current_arch (),
9576 NULL
, 0, arg
, 1 /* parse arg */,
9578 0 /* Ignore count */,
9579 pending_break_support
,
9580 &dprintf_breakpoint_ops
,
9588 agent_printf_command (const char *arg
, int from_tty
)
9590 error (_("May only run agent-printf on the target"));
9593 /* Implement the "breakpoint_hit" breakpoint_ops method for
9594 ranged breakpoints. */
9597 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9598 const address_space
*aspace
,
9600 const struct target_waitstatus
*ws
)
9602 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9603 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9606 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9607 bl
->length
, aspace
, bp_addr
);
9610 /* Implement the "resources_needed" breakpoint_ops method for
9611 ranged breakpoints. */
9614 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9616 return target_ranged_break_num_registers ();
9619 /* Implement the "print_it" breakpoint_ops method for
9620 ranged breakpoints. */
9622 static enum print_stop_action
9623 print_it_ranged_breakpoint (bpstat bs
)
9625 struct breakpoint
*b
= bs
->breakpoint_at
;
9626 struct bp_location
*bl
= b
->loc
;
9627 struct ui_out
*uiout
= current_uiout
;
9629 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9631 /* Ranged breakpoints have only one location. */
9632 gdb_assert (bl
&& bl
->next
== NULL
);
9634 annotate_breakpoint (b
->number
);
9636 maybe_print_thread_hit_breakpoint (uiout
);
9638 if (b
->disposition
== disp_del
)
9639 uiout
->text ("Temporary ranged breakpoint ");
9641 uiout
->text ("Ranged breakpoint ");
9642 if (uiout
->is_mi_like_p ())
9644 uiout
->field_string ("reason",
9645 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9646 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9648 uiout
->field_int ("bkptno", b
->number
);
9651 return PRINT_SRC_AND_LOC
;
9654 /* Implement the "print_one" breakpoint_ops method for
9655 ranged breakpoints. */
9658 print_one_ranged_breakpoint (struct breakpoint
*b
,
9659 struct bp_location
**last_loc
)
9661 struct bp_location
*bl
= b
->loc
;
9662 struct value_print_options opts
;
9663 struct ui_out
*uiout
= current_uiout
;
9665 /* Ranged breakpoints have only one location. */
9666 gdb_assert (bl
&& bl
->next
== NULL
);
9668 get_user_print_options (&opts
);
9670 if (opts
.addressprint
)
9671 /* We don't print the address range here, it will be printed later
9672 by print_one_detail_ranged_breakpoint. */
9673 uiout
->field_skip ("addr");
9675 print_breakpoint_location (b
, bl
);
9679 /* Implement the "print_one_detail" breakpoint_ops method for
9680 ranged breakpoints. */
9683 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9684 struct ui_out
*uiout
)
9686 CORE_ADDR address_start
, address_end
;
9687 struct bp_location
*bl
= b
->loc
;
9692 address_start
= bl
->address
;
9693 address_end
= address_start
+ bl
->length
- 1;
9695 uiout
->text ("\taddress range: ");
9696 stb
.printf ("[%s, %s]",
9697 print_core_address (bl
->gdbarch
, address_start
),
9698 print_core_address (bl
->gdbarch
, address_end
));
9699 uiout
->field_stream ("addr", stb
);
9703 /* Implement the "print_mention" breakpoint_ops method for
9704 ranged breakpoints. */
9707 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9709 struct bp_location
*bl
= b
->loc
;
9710 struct ui_out
*uiout
= current_uiout
;
9713 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9715 uiout
->message (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9716 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9717 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9720 /* Implement the "print_recreate" breakpoint_ops method for
9721 ranged breakpoints. */
9724 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9726 fprintf_unfiltered (fp
, "break-range %s, %s",
9727 event_location_to_string (b
->location
.get ()),
9728 event_location_to_string (b
->location_range_end
.get ()));
9729 print_recreate_thread (b
, fp
);
9732 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9734 static struct breakpoint_ops ranged_breakpoint_ops
;
9736 /* Find the address where the end of the breakpoint range should be
9737 placed, given the SAL of the end of the range. This is so that if
9738 the user provides a line number, the end of the range is set to the
9739 last instruction of the given line. */
9742 find_breakpoint_range_end (struct symtab_and_line sal
)
9746 /* If the user provided a PC value, use it. Otherwise,
9747 find the address of the end of the given location. */
9748 if (sal
.explicit_pc
)
9755 ret
= find_line_pc_range (sal
, &start
, &end
);
9757 error (_("Could not find location of the end of the range."));
9759 /* find_line_pc_range returns the start of the next line. */
9766 /* Implement the "break-range" CLI command. */
9769 break_range_command (const char *arg
, int from_tty
)
9771 const char *arg_start
;
9772 struct linespec_result canonical_start
, canonical_end
;
9773 int bp_count
, can_use_bp
, length
;
9775 struct breakpoint
*b
;
9777 /* We don't support software ranged breakpoints. */
9778 if (target_ranged_break_num_registers () < 0)
9779 error (_("This target does not support hardware ranged breakpoints."));
9781 bp_count
= hw_breakpoint_used_count ();
9782 bp_count
+= target_ranged_break_num_registers ();
9783 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9786 error (_("Hardware breakpoints used exceeds limit."));
9788 arg
= skip_spaces (arg
);
9789 if (arg
== NULL
|| arg
[0] == '\0')
9790 error(_("No address range specified."));
9793 event_location_up start_location
= string_to_event_location (&arg
,
9795 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9798 error (_("Too few arguments."));
9799 else if (canonical_start
.lsals
.empty ())
9800 error (_("Could not find location of the beginning of the range."));
9802 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9804 if (canonical_start
.lsals
.size () > 1
9805 || lsal_start
.sals
.size () != 1)
9806 error (_("Cannot create a ranged breakpoint with multiple locations."));
9808 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9809 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9811 arg
++; /* Skip the comma. */
9812 arg
= skip_spaces (arg
);
9814 /* Parse the end location. */
9818 /* We call decode_line_full directly here instead of using
9819 parse_breakpoint_sals because we need to specify the start location's
9820 symtab and line as the default symtab and line for the end of the
9821 range. This makes it possible to have ranges like "foo.c:27, +14",
9822 where +14 means 14 lines from the start location. */
9823 event_location_up end_location
= string_to_event_location (&arg
,
9825 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
9826 sal_start
.symtab
, sal_start
.line
,
9827 &canonical_end
, NULL
, NULL
);
9829 if (canonical_end
.lsals
.empty ())
9830 error (_("Could not find location of the end of the range."));
9832 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
9833 if (canonical_end
.lsals
.size () > 1
9834 || lsal_end
.sals
.size () != 1)
9835 error (_("Cannot create a ranged breakpoint with multiple locations."));
9837 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
9839 end
= find_breakpoint_range_end (sal_end
);
9840 if (sal_start
.pc
> end
)
9841 error (_("Invalid address range, end precedes start."));
9843 length
= end
- sal_start
.pc
+ 1;
9845 /* Length overflowed. */
9846 error (_("Address range too large."));
9847 else if (length
== 1)
9849 /* This range is simple enough to be handled by
9850 the `hbreak' command. */
9851 hbreak_command (&addr_string_start
[0], 1);
9856 /* Now set up the breakpoint. */
9857 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
9858 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
9859 set_breakpoint_count (breakpoint_count
+ 1);
9860 b
->number
= breakpoint_count
;
9861 b
->disposition
= disp_donttouch
;
9862 b
->location
= std::move (start_location
);
9863 b
->location_range_end
= std::move (end_location
);
9864 b
->loc
->length
= length
;
9867 gdb::observers::breakpoint_created
.notify (b
);
9868 update_global_location_list (UGLL_MAY_INSERT
);
9871 /* Return non-zero if EXP is verified as constant. Returned zero
9872 means EXP is variable. Also the constant detection may fail for
9873 some constant expressions and in such case still falsely return
9877 watchpoint_exp_is_const (const struct expression
*exp
)
9885 /* We are only interested in the descriptor of each element. */
9886 operator_length (exp
, i
, &oplenp
, &argsp
);
9889 switch (exp
->elts
[i
].opcode
)
9899 case BINOP_LOGICAL_AND
:
9900 case BINOP_LOGICAL_OR
:
9901 case BINOP_BITWISE_AND
:
9902 case BINOP_BITWISE_IOR
:
9903 case BINOP_BITWISE_XOR
:
9905 case BINOP_NOTEQUAL
:
9931 case OP_OBJC_NSSTRING
:
9934 case UNOP_LOGICAL_NOT
:
9935 case UNOP_COMPLEMENT
:
9940 case UNOP_CAST_TYPE
:
9941 case UNOP_REINTERPRET_CAST
:
9942 case UNOP_DYNAMIC_CAST
:
9943 /* Unary, binary and ternary operators: We have to check
9944 their operands. If they are constant, then so is the
9945 result of that operation. For instance, if A and B are
9946 determined to be constants, then so is "A + B".
9948 UNOP_IND is one exception to the rule above, because the
9949 value of *ADDR is not necessarily a constant, even when
9954 /* Check whether the associated symbol is a constant.
9956 We use SYMBOL_CLASS rather than TYPE_CONST because it's
9957 possible that a buggy compiler could mark a variable as
9958 constant even when it is not, and TYPE_CONST would return
9959 true in this case, while SYMBOL_CLASS wouldn't.
9961 We also have to check for function symbols because they
9962 are always constant. */
9964 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
9966 if (SYMBOL_CLASS (s
) != LOC_BLOCK
9967 && SYMBOL_CLASS (s
) != LOC_CONST
9968 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
9973 /* The default action is to return 0 because we are using
9974 the optimistic approach here: If we don't know something,
9975 then it is not a constant. */
9984 /* Watchpoint destructor. */
9986 watchpoint::~watchpoint ()
9988 xfree (this->exp_string
);
9989 xfree (this->exp_string_reparse
);
9992 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
9995 re_set_watchpoint (struct breakpoint
*b
)
9997 struct watchpoint
*w
= (struct watchpoint
*) b
;
9999 /* Watchpoint can be either on expression using entirely global
10000 variables, or it can be on local variables.
10002 Watchpoints of the first kind are never auto-deleted, and even
10003 persist across program restarts. Since they can use variables
10004 from shared libraries, we need to reparse expression as libraries
10005 are loaded and unloaded.
10007 Watchpoints on local variables can also change meaning as result
10008 of solib event. For example, if a watchpoint uses both a local
10009 and a global variables in expression, it's a local watchpoint,
10010 but unloading of a shared library will make the expression
10011 invalid. This is not a very common use case, but we still
10012 re-evaluate expression, to avoid surprises to the user.
10014 Note that for local watchpoints, we re-evaluate it only if
10015 watchpoints frame id is still valid. If it's not, it means the
10016 watchpoint is out of scope and will be deleted soon. In fact,
10017 I'm not sure we'll ever be called in this case.
10019 If a local watchpoint's frame id is still valid, then
10020 w->exp_valid_block is likewise valid, and we can safely use it.
10022 Don't do anything about disabled watchpoints, since they will be
10023 reevaluated again when enabled. */
10024 update_watchpoint (w
, 1 /* reparse */);
10027 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10030 insert_watchpoint (struct bp_location
*bl
)
10032 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10033 int length
= w
->exact
? 1 : bl
->length
;
10035 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10036 w
->cond_exp
.get ());
10039 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10042 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10044 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10045 int length
= w
->exact
? 1 : bl
->length
;
10047 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10048 w
->cond_exp
.get ());
10052 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10053 const address_space
*aspace
, CORE_ADDR bp_addr
,
10054 const struct target_waitstatus
*ws
)
10056 struct breakpoint
*b
= bl
->owner
;
10057 struct watchpoint
*w
= (struct watchpoint
*) b
;
10059 /* Continuable hardware watchpoints are treated as non-existent if the
10060 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10061 some data address). Otherwise gdb won't stop on a break instruction
10062 in the code (not from a breakpoint) when a hardware watchpoint has
10063 been defined. Also skip watchpoints which we know did not trigger
10064 (did not match the data address). */
10065 if (is_hardware_watchpoint (b
)
10066 && w
->watchpoint_triggered
== watch_triggered_no
)
10073 check_status_watchpoint (bpstat bs
)
10075 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10077 bpstat_check_watchpoint (bs
);
10080 /* Implement the "resources_needed" breakpoint_ops method for
10081 hardware watchpoints. */
10084 resources_needed_watchpoint (const struct bp_location
*bl
)
10086 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10087 int length
= w
->exact
? 1 : bl
->length
;
10089 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10092 /* Implement the "works_in_software_mode" breakpoint_ops method for
10093 hardware watchpoints. */
10096 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10098 /* Read and access watchpoints only work with hardware support. */
10099 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10102 static enum print_stop_action
10103 print_it_watchpoint (bpstat bs
)
10105 struct breakpoint
*b
;
10106 enum print_stop_action result
;
10107 struct watchpoint
*w
;
10108 struct ui_out
*uiout
= current_uiout
;
10110 gdb_assert (bs
->bp_location_at
!= NULL
);
10112 b
= bs
->breakpoint_at
;
10113 w
= (struct watchpoint
*) b
;
10115 annotate_watchpoint (b
->number
);
10116 maybe_print_thread_hit_breakpoint (uiout
);
10120 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10123 case bp_watchpoint
:
10124 case bp_hardware_watchpoint
:
10125 if (uiout
->is_mi_like_p ())
10126 uiout
->field_string
10127 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10129 tuple_emitter
.emplace (uiout
, "value");
10130 uiout
->text ("\nOld value = ");
10131 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10132 uiout
->field_stream ("old", stb
);
10133 uiout
->text ("\nNew value = ");
10134 watchpoint_value_print (w
->val
.get (), &stb
);
10135 uiout
->field_stream ("new", stb
);
10136 uiout
->text ("\n");
10137 /* More than one watchpoint may have been triggered. */
10138 result
= PRINT_UNKNOWN
;
10141 case bp_read_watchpoint
:
10142 if (uiout
->is_mi_like_p ())
10143 uiout
->field_string
10144 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10146 tuple_emitter
.emplace (uiout
, "value");
10147 uiout
->text ("\nValue = ");
10148 watchpoint_value_print (w
->val
.get (), &stb
);
10149 uiout
->field_stream ("value", stb
);
10150 uiout
->text ("\n");
10151 result
= PRINT_UNKNOWN
;
10154 case bp_access_watchpoint
:
10155 if (bs
->old_val
!= NULL
)
10157 if (uiout
->is_mi_like_p ())
10158 uiout
->field_string
10160 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10162 tuple_emitter
.emplace (uiout
, "value");
10163 uiout
->text ("\nOld value = ");
10164 watchpoint_value_print (bs
->old_val
.get (), &stb
);
10165 uiout
->field_stream ("old", stb
);
10166 uiout
->text ("\nNew value = ");
10171 if (uiout
->is_mi_like_p ())
10172 uiout
->field_string
10174 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10175 tuple_emitter
.emplace (uiout
, "value");
10176 uiout
->text ("\nValue = ");
10178 watchpoint_value_print (w
->val
.get (), &stb
);
10179 uiout
->field_stream ("new", stb
);
10180 uiout
->text ("\n");
10181 result
= PRINT_UNKNOWN
;
10184 result
= PRINT_UNKNOWN
;
10190 /* Implement the "print_mention" breakpoint_ops method for hardware
10194 print_mention_watchpoint (struct breakpoint
*b
)
10196 struct watchpoint
*w
= (struct watchpoint
*) b
;
10197 struct ui_out
*uiout
= current_uiout
;
10198 const char *tuple_name
;
10202 case bp_watchpoint
:
10203 uiout
->text ("Watchpoint ");
10204 tuple_name
= "wpt";
10206 case bp_hardware_watchpoint
:
10207 uiout
->text ("Hardware watchpoint ");
10208 tuple_name
= "wpt";
10210 case bp_read_watchpoint
:
10211 uiout
->text ("Hardware read watchpoint ");
10212 tuple_name
= "hw-rwpt";
10214 case bp_access_watchpoint
:
10215 uiout
->text ("Hardware access (read/write) watchpoint ");
10216 tuple_name
= "hw-awpt";
10219 internal_error (__FILE__
, __LINE__
,
10220 _("Invalid hardware watchpoint type."));
10223 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10224 uiout
->field_int ("number", b
->number
);
10225 uiout
->text (": ");
10226 uiout
->field_string ("exp", w
->exp_string
);
10229 /* Implement the "print_recreate" breakpoint_ops method for
10233 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10235 struct watchpoint
*w
= (struct watchpoint
*) b
;
10239 case bp_watchpoint
:
10240 case bp_hardware_watchpoint
:
10241 fprintf_unfiltered (fp
, "watch");
10243 case bp_read_watchpoint
:
10244 fprintf_unfiltered (fp
, "rwatch");
10246 case bp_access_watchpoint
:
10247 fprintf_unfiltered (fp
, "awatch");
10250 internal_error (__FILE__
, __LINE__
,
10251 _("Invalid watchpoint type."));
10254 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10255 print_recreate_thread (b
, fp
);
10258 /* Implement the "explains_signal" breakpoint_ops method for
10262 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10264 /* A software watchpoint cannot cause a signal other than
10265 GDB_SIGNAL_TRAP. */
10266 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10272 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10274 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10276 /* Implement the "insert" breakpoint_ops method for
10277 masked hardware watchpoints. */
10280 insert_masked_watchpoint (struct bp_location
*bl
)
10282 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10284 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10285 bl
->watchpoint_type
);
10288 /* Implement the "remove" breakpoint_ops method for
10289 masked hardware watchpoints. */
10292 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10294 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10296 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10297 bl
->watchpoint_type
);
10300 /* Implement the "resources_needed" breakpoint_ops method for
10301 masked hardware watchpoints. */
10304 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10306 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10308 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10311 /* Implement the "works_in_software_mode" breakpoint_ops method for
10312 masked hardware watchpoints. */
10315 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10320 /* Implement the "print_it" breakpoint_ops method for
10321 masked hardware watchpoints. */
10323 static enum print_stop_action
10324 print_it_masked_watchpoint (bpstat bs
)
10326 struct breakpoint
*b
= bs
->breakpoint_at
;
10327 struct ui_out
*uiout
= current_uiout
;
10329 /* Masked watchpoints have only one location. */
10330 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10332 annotate_watchpoint (b
->number
);
10333 maybe_print_thread_hit_breakpoint (uiout
);
10337 case bp_hardware_watchpoint
:
10338 if (uiout
->is_mi_like_p ())
10339 uiout
->field_string
10340 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10343 case bp_read_watchpoint
:
10344 if (uiout
->is_mi_like_p ())
10345 uiout
->field_string
10346 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10349 case bp_access_watchpoint
:
10350 if (uiout
->is_mi_like_p ())
10351 uiout
->field_string
10353 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10356 internal_error (__FILE__
, __LINE__
,
10357 _("Invalid hardware watchpoint type."));
10361 uiout
->text (_("\n\
10362 Check the underlying instruction at PC for the memory\n\
10363 address and value which triggered this watchpoint.\n"));
10364 uiout
->text ("\n");
10366 /* More than one watchpoint may have been triggered. */
10367 return PRINT_UNKNOWN
;
10370 /* Implement the "print_one_detail" breakpoint_ops method for
10371 masked hardware watchpoints. */
10374 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10375 struct ui_out
*uiout
)
10377 struct watchpoint
*w
= (struct watchpoint
*) b
;
10379 /* Masked watchpoints have only one location. */
10380 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10382 uiout
->text ("\tmask ");
10383 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10384 uiout
->text ("\n");
10387 /* Implement the "print_mention" breakpoint_ops method for
10388 masked hardware watchpoints. */
10391 print_mention_masked_watchpoint (struct breakpoint
*b
)
10393 struct watchpoint
*w
= (struct watchpoint
*) b
;
10394 struct ui_out
*uiout
= current_uiout
;
10395 const char *tuple_name
;
10399 case bp_hardware_watchpoint
:
10400 uiout
->text ("Masked hardware watchpoint ");
10401 tuple_name
= "wpt";
10403 case bp_read_watchpoint
:
10404 uiout
->text ("Masked hardware read watchpoint ");
10405 tuple_name
= "hw-rwpt";
10407 case bp_access_watchpoint
:
10408 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10409 tuple_name
= "hw-awpt";
10412 internal_error (__FILE__
, __LINE__
,
10413 _("Invalid hardware watchpoint type."));
10416 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10417 uiout
->field_int ("number", b
->number
);
10418 uiout
->text (": ");
10419 uiout
->field_string ("exp", w
->exp_string
);
10422 /* Implement the "print_recreate" breakpoint_ops method for
10423 masked hardware watchpoints. */
10426 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10428 struct watchpoint
*w
= (struct watchpoint
*) b
;
10433 case bp_hardware_watchpoint
:
10434 fprintf_unfiltered (fp
, "watch");
10436 case bp_read_watchpoint
:
10437 fprintf_unfiltered (fp
, "rwatch");
10439 case bp_access_watchpoint
:
10440 fprintf_unfiltered (fp
, "awatch");
10443 internal_error (__FILE__
, __LINE__
,
10444 _("Invalid hardware watchpoint type."));
10447 sprintf_vma (tmp
, w
->hw_wp_mask
);
10448 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10449 print_recreate_thread (b
, fp
);
10452 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10454 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10456 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10459 is_masked_watchpoint (const struct breakpoint
*b
)
10461 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10464 /* accessflag: hw_write: watch write,
10465 hw_read: watch read,
10466 hw_access: watch access (read or write) */
10468 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10469 int just_location
, int internal
)
10471 struct breakpoint
*scope_breakpoint
= NULL
;
10472 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10473 struct value
*result
;
10474 int saved_bitpos
= 0, saved_bitsize
= 0;
10475 const char *exp_start
= NULL
;
10476 const char *exp_end
= NULL
;
10477 const char *tok
, *end_tok
;
10479 const char *cond_start
= NULL
;
10480 const char *cond_end
= NULL
;
10481 enum bptype bp_type
;
10484 /* Flag to indicate whether we are going to use masks for
10485 the hardware watchpoint. */
10487 CORE_ADDR mask
= 0;
10489 /* Make sure that we actually have parameters to parse. */
10490 if (arg
!= NULL
&& arg
[0] != '\0')
10492 const char *value_start
;
10494 exp_end
= arg
+ strlen (arg
);
10496 /* Look for "parameter value" pairs at the end
10497 of the arguments string. */
10498 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10500 /* Skip whitespace at the end of the argument list. */
10501 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10504 /* Find the beginning of the last token.
10505 This is the value of the parameter. */
10506 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10508 value_start
= tok
+ 1;
10510 /* Skip whitespace. */
10511 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10516 /* Find the beginning of the second to last token.
10517 This is the parameter itself. */
10518 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10521 toklen
= end_tok
- tok
+ 1;
10523 if (toklen
== 6 && startswith (tok
, "thread"))
10525 struct thread_info
*thr
;
10526 /* At this point we've found a "thread" token, which means
10527 the user is trying to set a watchpoint that triggers
10528 only in a specific thread. */
10532 error(_("You can specify only one thread."));
10534 /* Extract the thread ID from the next token. */
10535 thr
= parse_thread_id (value_start
, &endp
);
10537 /* Check if the user provided a valid thread ID. */
10538 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10539 invalid_thread_id_error (value_start
);
10541 thread
= thr
->global_num
;
10543 else if (toklen
== 4 && startswith (tok
, "mask"))
10545 /* We've found a "mask" token, which means the user wants to
10546 create a hardware watchpoint that is going to have the mask
10548 struct value
*mask_value
, *mark
;
10551 error(_("You can specify only one mask."));
10553 use_mask
= just_location
= 1;
10555 mark
= value_mark ();
10556 mask_value
= parse_to_comma_and_eval (&value_start
);
10557 mask
= value_as_address (mask_value
);
10558 value_free_to_mark (mark
);
10561 /* We didn't recognize what we found. We should stop here. */
10564 /* Truncate the string and get rid of the "parameter value" pair before
10565 the arguments string is parsed by the parse_exp_1 function. */
10572 /* Parse the rest of the arguments. From here on out, everything
10573 is in terms of a newly allocated string instead of the original
10575 std::string
expression (arg
, exp_end
- arg
);
10576 exp_start
= arg
= expression
.c_str ();
10577 innermost_block_tracker tracker
;
10578 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0, &tracker
);
10580 /* Remove trailing whitespace from the expression before saving it.
10581 This makes the eventual display of the expression string a bit
10583 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10586 /* Checking if the expression is not constant. */
10587 if (watchpoint_exp_is_const (exp
.get ()))
10591 len
= exp_end
- exp_start
;
10592 while (len
> 0 && isspace (exp_start
[len
- 1]))
10594 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10597 exp_valid_block
= tracker
.block ();
10598 struct value
*mark
= value_mark ();
10599 struct value
*val_as_value
= nullptr;
10600 fetch_subexp_value (exp
.get (), &pc
, &val_as_value
, &result
, NULL
,
10603 if (val_as_value
!= NULL
&& just_location
)
10605 saved_bitpos
= value_bitpos (val_as_value
);
10606 saved_bitsize
= value_bitsize (val_as_value
);
10614 exp_valid_block
= NULL
;
10615 val
= release_value (value_addr (result
));
10616 value_free_to_mark (mark
);
10620 ret
= target_masked_watch_num_registers (value_as_address (val
.get ()),
10623 error (_("This target does not support masked watchpoints."));
10624 else if (ret
== -2)
10625 error (_("Invalid mask or memory region."));
10628 else if (val_as_value
!= NULL
)
10629 val
= release_value (val_as_value
);
10631 tok
= skip_spaces (arg
);
10632 end_tok
= skip_to_space (tok
);
10634 toklen
= end_tok
- tok
;
10635 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10637 tok
= cond_start
= end_tok
+ 1;
10638 innermost_block_tracker if_tracker
;
10639 parse_exp_1 (&tok
, 0, 0, 0, &if_tracker
);
10641 /* The watchpoint expression may not be local, but the condition
10642 may still be. E.g.: `watch global if local > 0'. */
10643 cond_exp_valid_block
= if_tracker
.block ();
10648 error (_("Junk at end of command."));
10650 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10652 /* Save this because create_internal_breakpoint below invalidates
10654 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10656 /* If the expression is "local", then set up a "watchpoint scope"
10657 breakpoint at the point where we've left the scope of the watchpoint
10658 expression. Create the scope breakpoint before the watchpoint, so
10659 that we will encounter it first in bpstat_stop_status. */
10660 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10662 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10664 if (frame_id_p (caller_frame_id
))
10666 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10667 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10670 = create_internal_breakpoint (caller_arch
, caller_pc
,
10671 bp_watchpoint_scope
,
10672 &momentary_breakpoint_ops
);
10674 /* create_internal_breakpoint could invalidate WP_FRAME. */
10677 scope_breakpoint
->enable_state
= bp_enabled
;
10679 /* Automatically delete the breakpoint when it hits. */
10680 scope_breakpoint
->disposition
= disp_del
;
10682 /* Only break in the proper frame (help with recursion). */
10683 scope_breakpoint
->frame_id
= caller_frame_id
;
10685 /* Set the address at which we will stop. */
10686 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10687 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10688 scope_breakpoint
->loc
->address
10689 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10690 scope_breakpoint
->loc
->requested_address
,
10691 scope_breakpoint
->type
);
10695 /* Now set up the breakpoint. We create all watchpoints as hardware
10696 watchpoints here even if hardware watchpoints are turned off, a call
10697 to update_watchpoint later in this function will cause the type to
10698 drop back to bp_watchpoint (software watchpoint) if required. */
10700 if (accessflag
== hw_read
)
10701 bp_type
= bp_read_watchpoint
;
10702 else if (accessflag
== hw_access
)
10703 bp_type
= bp_access_watchpoint
;
10705 bp_type
= bp_hardware_watchpoint
;
10707 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10710 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10711 &masked_watchpoint_breakpoint_ops
);
10713 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10714 &watchpoint_breakpoint_ops
);
10715 w
->thread
= thread
;
10716 w
->disposition
= disp_donttouch
;
10717 w
->pspace
= current_program_space
;
10718 w
->exp
= std::move (exp
);
10719 w
->exp_valid_block
= exp_valid_block
;
10720 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10723 struct type
*t
= value_type (val
.get ());
10724 CORE_ADDR addr
= value_as_address (val
.get ());
10726 w
->exp_string_reparse
10727 = current_language
->la_watch_location_expression (t
, addr
).release ();
10729 w
->exp_string
= xstrprintf ("-location %.*s",
10730 (int) (exp_end
- exp_start
), exp_start
);
10733 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10737 w
->hw_wp_mask
= mask
;
10742 w
->val_bitpos
= saved_bitpos
;
10743 w
->val_bitsize
= saved_bitsize
;
10748 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10750 w
->cond_string
= 0;
10752 if (frame_id_p (watchpoint_frame
))
10754 w
->watchpoint_frame
= watchpoint_frame
;
10755 w
->watchpoint_thread
= inferior_ptid
;
10759 w
->watchpoint_frame
= null_frame_id
;
10760 w
->watchpoint_thread
= null_ptid
;
10763 if (scope_breakpoint
!= NULL
)
10765 /* The scope breakpoint is related to the watchpoint. We will
10766 need to act on them together. */
10767 w
->related_breakpoint
= scope_breakpoint
;
10768 scope_breakpoint
->related_breakpoint
= w
.get ();
10771 if (!just_location
)
10772 value_free_to_mark (mark
);
10774 /* Finally update the new watchpoint. This creates the locations
10775 that should be inserted. */
10776 update_watchpoint (w
.get (), 1);
10778 install_breakpoint (internal
, std::move (w
), 1);
10781 /* Return count of debug registers needed to watch the given expression.
10782 If the watchpoint cannot be handled in hardware return zero. */
10785 can_use_hardware_watchpoint (const std::vector
<value_ref_ptr
> &vals
)
10787 int found_memory_cnt
= 0;
10789 /* Did the user specifically forbid us to use hardware watchpoints? */
10790 if (!can_use_hw_watchpoints
)
10793 gdb_assert (!vals
.empty ());
10794 struct value
*head
= vals
[0].get ();
10796 /* Make sure that the value of the expression depends only upon
10797 memory contents, and values computed from them within GDB. If we
10798 find any register references or function calls, we can't use a
10799 hardware watchpoint.
10801 The idea here is that evaluating an expression generates a series
10802 of values, one holding the value of every subexpression. (The
10803 expression a*b+c has five subexpressions: a, b, a*b, c, and
10804 a*b+c.) GDB's values hold almost enough information to establish
10805 the criteria given above --- they identify memory lvalues,
10806 register lvalues, computed values, etcetera. So we can evaluate
10807 the expression, and then scan the chain of values that leaves
10808 behind to decide whether we can detect any possible change to the
10809 expression's final value using only hardware watchpoints.
10811 However, I don't think that the values returned by inferior
10812 function calls are special in any way. So this function may not
10813 notice that an expression involving an inferior function call
10814 can't be watched with hardware watchpoints. FIXME. */
10815 for (const value_ref_ptr
&iter
: vals
)
10817 struct value
*v
= iter
.get ();
10819 if (VALUE_LVAL (v
) == lval_memory
)
10821 if (v
!= head
&& value_lazy (v
))
10822 /* A lazy memory lvalue in the chain is one that GDB never
10823 needed to fetch; we either just used its address (e.g.,
10824 `a' in `a.b') or we never needed it at all (e.g., `a'
10825 in `a,b'). This doesn't apply to HEAD; if that is
10826 lazy then it was not readable, but watch it anyway. */
10830 /* Ahh, memory we actually used! Check if we can cover
10831 it with hardware watchpoints. */
10832 struct type
*vtype
= check_typedef (value_type (v
));
10834 /* We only watch structs and arrays if user asked for it
10835 explicitly, never if they just happen to appear in a
10836 middle of some value chain. */
10838 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
10839 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
10841 CORE_ADDR vaddr
= value_address (v
);
10845 len
= (target_exact_watchpoints
10846 && is_scalar_type_recursive (vtype
))?
10847 1 : TYPE_LENGTH (value_type (v
));
10849 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
10853 found_memory_cnt
+= num_regs
;
10857 else if (VALUE_LVAL (v
) != not_lval
10858 && deprecated_value_modifiable (v
) == 0)
10859 return 0; /* These are values from the history (e.g., $1). */
10860 else if (VALUE_LVAL (v
) == lval_register
)
10861 return 0; /* Cannot watch a register with a HW watchpoint. */
10864 /* The expression itself looks suitable for using a hardware
10865 watchpoint, but give the target machine a chance to reject it. */
10866 return found_memory_cnt
;
10870 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10872 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
10875 /* A helper function that looks for the "-location" argument and then
10876 calls watch_command_1. */
10879 watch_maybe_just_location (const char *arg
, int accessflag
, int from_tty
)
10881 int just_location
= 0;
10884 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
10885 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
10888 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
10892 watch_command (const char *arg
, int from_tty
)
10894 watch_maybe_just_location (arg
, hw_write
, from_tty
);
10898 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10900 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
10904 rwatch_command (const char *arg
, int from_tty
)
10906 watch_maybe_just_location (arg
, hw_read
, from_tty
);
10910 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
10912 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
10916 awatch_command (const char *arg
, int from_tty
)
10918 watch_maybe_just_location (arg
, hw_access
, from_tty
);
10922 /* Data for the FSM that manages the until(location)/advance commands
10923 in infcmd.c. Here because it uses the mechanisms of
10926 struct until_break_fsm
: public thread_fsm
10928 /* The thread that was current when the command was executed. */
10931 /* The breakpoint set at the destination location. */
10932 breakpoint_up location_breakpoint
;
10934 /* Breakpoint set at the return address in the caller frame. May be
10936 breakpoint_up caller_breakpoint
;
10938 until_break_fsm (struct interp
*cmd_interp
, int thread
,
10939 breakpoint_up
&&location_breakpoint
,
10940 breakpoint_up
&&caller_breakpoint
)
10941 : thread_fsm (cmd_interp
),
10943 location_breakpoint (std::move (location_breakpoint
)),
10944 caller_breakpoint (std::move (caller_breakpoint
))
10948 void clean_up (struct thread_info
*thread
) override
;
10949 bool should_stop (struct thread_info
*thread
) override
;
10950 enum async_reply_reason
do_async_reply_reason () override
;
10953 /* Implementation of the 'should_stop' FSM method for the
10954 until(location)/advance commands. */
10957 until_break_fsm::should_stop (struct thread_info
*tp
)
10959 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10960 location_breakpoint
.get ()) != NULL
10961 || (caller_breakpoint
!= NULL
10962 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
10963 caller_breakpoint
.get ()) != NULL
))
10969 /* Implementation of the 'clean_up' FSM method for the
10970 until(location)/advance commands. */
10973 until_break_fsm::clean_up (struct thread_info
*)
10975 /* Clean up our temporary breakpoints. */
10976 location_breakpoint
.reset ();
10977 caller_breakpoint
.reset ();
10978 delete_longjmp_breakpoint (thread
);
10981 /* Implementation of the 'async_reply_reason' FSM method for the
10982 until(location)/advance commands. */
10984 enum async_reply_reason
10985 until_break_fsm::do_async_reply_reason ()
10987 return EXEC_ASYNC_LOCATION_REACHED
;
10991 until_break_command (const char *arg
, int from_tty
, int anywhere
)
10993 struct frame_info
*frame
;
10994 struct gdbarch
*frame_gdbarch
;
10995 struct frame_id stack_frame_id
;
10996 struct frame_id caller_frame_id
;
10998 struct thread_info
*tp
;
11000 clear_proceed_status (0);
11002 /* Set a breakpoint where the user wants it and at return from
11005 event_location_up location
= string_to_event_location (&arg
, current_language
);
11007 std::vector
<symtab_and_line
> sals
11008 = (last_displayed_sal_is_valid ()
11009 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11010 get_last_displayed_symtab (),
11011 get_last_displayed_line ())
11012 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11015 if (sals
.size () != 1)
11016 error (_("Couldn't get information on specified line."));
11018 symtab_and_line
&sal
= sals
[0];
11021 error (_("Junk at end of arguments."));
11023 resolve_sal_pc (&sal
);
11025 tp
= inferior_thread ();
11026 thread
= tp
->global_num
;
11028 /* Note linespec handling above invalidates the frame chain.
11029 Installing a breakpoint also invalidates the frame chain (as it
11030 may need to switch threads), so do any frame handling before
11033 frame
= get_selected_frame (NULL
);
11034 frame_gdbarch
= get_frame_arch (frame
);
11035 stack_frame_id
= get_stack_frame_id (frame
);
11036 caller_frame_id
= frame_unwind_caller_id (frame
);
11038 /* Keep within the current frame, or in frames called by the current
11041 breakpoint_up caller_breakpoint
;
11043 gdb::optional
<delete_longjmp_breakpoint_cleanup
> lj_deleter
;
11045 if (frame_id_p (caller_frame_id
))
11047 struct symtab_and_line sal2
;
11048 struct gdbarch
*caller_gdbarch
;
11050 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11051 sal2
.pc
= frame_unwind_caller_pc (frame
);
11052 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11053 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11058 set_longjmp_breakpoint (tp
, caller_frame_id
);
11059 lj_deleter
.emplace (thread
);
11062 /* set_momentary_breakpoint could invalidate FRAME. */
11065 breakpoint_up location_breakpoint
;
11067 /* If the user told us to continue until a specified location,
11068 we don't specify a frame at which we need to stop. */
11069 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11070 null_frame_id
, bp_until
);
11072 /* Otherwise, specify the selected frame, because we want to stop
11073 only at the very same frame. */
11074 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11075 stack_frame_id
, bp_until
);
11077 tp
->thread_fsm
= new until_break_fsm (command_interp (), tp
->global_num
,
11078 std::move (location_breakpoint
),
11079 std::move (caller_breakpoint
));
11082 lj_deleter
->release ();
11084 proceed (-1, GDB_SIGNAL_DEFAULT
);
11087 /* This function attempts to parse an optional "if <cond>" clause
11088 from the arg string. If one is not found, it returns NULL.
11090 Else, it returns a pointer to the condition string. (It does not
11091 attempt to evaluate the string against a particular block.) And,
11092 it updates arg to point to the first character following the parsed
11093 if clause in the arg string. */
11096 ep_parse_optional_if_clause (const char **arg
)
11098 const char *cond_string
;
11100 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11103 /* Skip the "if" keyword. */
11106 /* Skip any extra leading whitespace, and record the start of the
11107 condition string. */
11108 *arg
= skip_spaces (*arg
);
11109 cond_string
= *arg
;
11111 /* Assume that the condition occupies the remainder of the arg
11113 (*arg
) += strlen (cond_string
);
11115 return cond_string
;
11118 /* Commands to deal with catching events, such as signals, exceptions,
11119 process start/exit, etc. */
11123 catch_fork_temporary
, catch_vfork_temporary
,
11124 catch_fork_permanent
, catch_vfork_permanent
11129 catch_fork_command_1 (const char *arg
, int from_tty
,
11130 struct cmd_list_element
*command
)
11132 struct gdbarch
*gdbarch
= get_current_arch ();
11133 const char *cond_string
= NULL
;
11134 catch_fork_kind fork_kind
;
11137 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11138 tempflag
= (fork_kind
== catch_fork_temporary
11139 || fork_kind
== catch_vfork_temporary
);
11143 arg
= skip_spaces (arg
);
11145 /* The allowed syntax is:
11147 catch [v]fork if <cond>
11149 First, check if there's an if clause. */
11150 cond_string
= ep_parse_optional_if_clause (&arg
);
11152 if ((*arg
!= '\0') && !isspace (*arg
))
11153 error (_("Junk at end of arguments."));
11155 /* If this target supports it, create a fork or vfork catchpoint
11156 and enable reporting of such events. */
11159 case catch_fork_temporary
:
11160 case catch_fork_permanent
:
11161 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11162 &catch_fork_breakpoint_ops
);
11164 case catch_vfork_temporary
:
11165 case catch_vfork_permanent
:
11166 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11167 &catch_vfork_breakpoint_ops
);
11170 error (_("unsupported or unknown fork kind; cannot catch it"));
11176 catch_exec_command_1 (const char *arg
, int from_tty
,
11177 struct cmd_list_element
*command
)
11179 struct gdbarch
*gdbarch
= get_current_arch ();
11181 const char *cond_string
= NULL
;
11183 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11187 arg
= skip_spaces (arg
);
11189 /* The allowed syntax is:
11191 catch exec if <cond>
11193 First, check if there's an if clause. */
11194 cond_string
= ep_parse_optional_if_clause (&arg
);
11196 if ((*arg
!= '\0') && !isspace (*arg
))
11197 error (_("Junk at end of arguments."));
11199 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11200 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11201 &catch_exec_breakpoint_ops
);
11202 c
->exec_pathname
= NULL
;
11204 install_breakpoint (0, std::move (c
), 1);
11208 init_ada_exception_breakpoint (struct breakpoint
*b
,
11209 struct gdbarch
*gdbarch
,
11210 struct symtab_and_line sal
,
11211 const char *addr_string
,
11212 const struct breakpoint_ops
*ops
,
11219 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11221 loc_gdbarch
= gdbarch
;
11223 describe_other_breakpoints (loc_gdbarch
,
11224 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11225 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11226 version for exception catchpoints, because two catchpoints
11227 used for different exception names will use the same address.
11228 In this case, a "breakpoint ... also set at..." warning is
11229 unproductive. Besides, the warning phrasing is also a bit
11230 inappropriate, we should use the word catchpoint, and tell
11231 the user what type of catchpoint it is. The above is good
11232 enough for now, though. */
11235 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11237 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11238 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11239 b
->location
= string_to_event_location (&addr_string
,
11240 language_def (language_ada
));
11241 b
->language
= language_ada
;
11245 catch_command (const char *arg
, int from_tty
)
11247 error (_("Catch requires an event name."));
11252 tcatch_command (const char *arg
, int from_tty
)
11254 error (_("Catch requires an event name."));
11257 /* Compare two breakpoints and return a strcmp-like result. */
11260 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11262 uintptr_t ua
= (uintptr_t) a
;
11263 uintptr_t ub
= (uintptr_t) b
;
11265 if (a
->number
< b
->number
)
11267 else if (a
->number
> b
->number
)
11270 /* Now sort by address, in case we see, e..g, two breakpoints with
11274 return ua
> ub
? 1 : 0;
11277 /* Delete breakpoints by address or line. */
11280 clear_command (const char *arg
, int from_tty
)
11282 struct breakpoint
*b
;
11285 std::vector
<symtab_and_line
> decoded_sals
;
11286 symtab_and_line last_sal
;
11287 gdb::array_view
<symtab_and_line
> sals
;
11291 = decode_line_with_current_source (arg
,
11292 (DECODE_LINE_FUNFIRSTLINE
11293 | DECODE_LINE_LIST_MODE
));
11295 sals
= decoded_sals
;
11299 /* Set sal's line, symtab, pc, and pspace to the values
11300 corresponding to the last call to print_frame_info. If the
11301 codepoint is not valid, this will set all the fields to 0. */
11302 last_sal
= get_last_displayed_sal ();
11303 if (last_sal
.symtab
== 0)
11304 error (_("No source file specified."));
11310 /* We don't call resolve_sal_pc here. That's not as bad as it
11311 seems, because all existing breakpoints typically have both
11312 file/line and pc set. So, if clear is given file/line, we can
11313 match this to existing breakpoint without obtaining pc at all.
11315 We only support clearing given the address explicitly
11316 present in breakpoint table. Say, we've set breakpoint
11317 at file:line. There were several PC values for that file:line,
11318 due to optimization, all in one block.
11320 We've picked one PC value. If "clear" is issued with another
11321 PC corresponding to the same file:line, the breakpoint won't
11322 be cleared. We probably can still clear the breakpoint, but
11323 since the other PC value is never presented to user, user
11324 can only find it by guessing, and it does not seem important
11325 to support that. */
11327 /* For each line spec given, delete bps which correspond to it. Do
11328 it in two passes, solely to preserve the current behavior that
11329 from_tty is forced true if we delete more than one
11332 std::vector
<struct breakpoint
*> found
;
11333 for (const auto &sal
: sals
)
11335 const char *sal_fullname
;
11337 /* If exact pc given, clear bpts at that pc.
11338 If line given (pc == 0), clear all bpts on specified line.
11339 If defaulting, clear all bpts on default line
11342 defaulting sal.pc != 0 tests to do
11347 1 0 <can't happen> */
11349 sal_fullname
= (sal
.symtab
== NULL
11350 ? NULL
: symtab_to_fullname (sal
.symtab
));
11352 /* Find all matching breakpoints and add them to 'found'. */
11353 ALL_BREAKPOINTS (b
)
11356 /* Are we going to delete b? */
11357 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11359 struct bp_location
*loc
= b
->loc
;
11360 for (; loc
; loc
= loc
->next
)
11362 /* If the user specified file:line, don't allow a PC
11363 match. This matches historical gdb behavior. */
11364 int pc_match
= (!sal
.explicit_line
11366 && (loc
->pspace
== sal
.pspace
)
11367 && (loc
->address
== sal
.pc
)
11368 && (!section_is_overlay (loc
->section
)
11369 || loc
->section
== sal
.section
));
11370 int line_match
= 0;
11372 if ((default_match
|| sal
.explicit_line
)
11373 && loc
->symtab
!= NULL
11374 && sal_fullname
!= NULL
11375 && sal
.pspace
== loc
->pspace
11376 && loc
->line_number
== sal
.line
11377 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11378 sal_fullname
) == 0)
11381 if (pc_match
|| line_match
)
11390 found
.push_back (b
);
11394 /* Now go thru the 'found' chain and delete them. */
11395 if (found
.empty ())
11398 error (_("No breakpoint at %s."), arg
);
11400 error (_("No breakpoint at this line."));
11403 /* Remove duplicates from the vec. */
11404 std::sort (found
.begin (), found
.end (),
11405 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11407 return compare_breakpoints (bp_a
, bp_b
) < 0;
11409 found
.erase (std::unique (found
.begin (), found
.end (),
11410 [] (const breakpoint
*bp_a
, const breakpoint
*bp_b
)
11412 return compare_breakpoints (bp_a
, bp_b
) == 0;
11416 if (found
.size () > 1)
11417 from_tty
= 1; /* Always report if deleted more than one. */
11420 if (found
.size () == 1)
11421 printf_unfiltered (_("Deleted breakpoint "));
11423 printf_unfiltered (_("Deleted breakpoints "));
11426 for (breakpoint
*iter
: found
)
11429 printf_unfiltered ("%d ", iter
->number
);
11430 delete_breakpoint (iter
);
11433 putchar_unfiltered ('\n');
11436 /* Delete breakpoint in BS if they are `delete' breakpoints and
11437 all breakpoints that are marked for deletion, whether hit or not.
11438 This is called after any breakpoint is hit, or after errors. */
11441 breakpoint_auto_delete (bpstat bs
)
11443 struct breakpoint
*b
, *b_tmp
;
11445 for (; bs
; bs
= bs
->next
)
11446 if (bs
->breakpoint_at
11447 && bs
->breakpoint_at
->disposition
== disp_del
11449 delete_breakpoint (bs
->breakpoint_at
);
11451 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11453 if (b
->disposition
== disp_del_at_next_stop
)
11454 delete_breakpoint (b
);
11458 /* A comparison function for bp_location AP and BP being interfaced to
11459 qsort. Sort elements primarily by their ADDRESS (no matter what
11460 does breakpoint_address_is_meaningful say for its OWNER),
11461 secondarily by ordering first permanent elements and
11462 terciarily just ensuring the array is sorted stable way despite
11463 qsort being an unstable algorithm. */
11466 bp_locations_compare (const void *ap
, const void *bp
)
11468 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
11469 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
11471 if (a
->address
!= b
->address
)
11472 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11474 /* Sort locations at the same address by their pspace number, keeping
11475 locations of the same inferior (in a multi-inferior environment)
11478 if (a
->pspace
->num
!= b
->pspace
->num
)
11479 return ((a
->pspace
->num
> b
->pspace
->num
)
11480 - (a
->pspace
->num
< b
->pspace
->num
));
11482 /* Sort permanent breakpoints first. */
11483 if (a
->permanent
!= b
->permanent
)
11484 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11486 /* Make the internal GDB representation stable across GDB runs
11487 where A and B memory inside GDB can differ. Breakpoint locations of
11488 the same type at the same address can be sorted in arbitrary order. */
11490 if (a
->owner
->number
!= b
->owner
->number
)
11491 return ((a
->owner
->number
> b
->owner
->number
)
11492 - (a
->owner
->number
< b
->owner
->number
));
11494 return (a
> b
) - (a
< b
);
11497 /* Set bp_locations_placed_address_before_address_max and
11498 bp_locations_shadow_len_after_address_max according to the current
11499 content of the bp_locations array. */
11502 bp_locations_target_extensions_update (void)
11504 struct bp_location
*bl
, **blp_tmp
;
11506 bp_locations_placed_address_before_address_max
= 0;
11507 bp_locations_shadow_len_after_address_max
= 0;
11509 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11511 CORE_ADDR start
, end
, addr
;
11513 if (!bp_location_has_shadow (bl
))
11516 start
= bl
->target_info
.placed_address
;
11517 end
= start
+ bl
->target_info
.shadow_len
;
11519 gdb_assert (bl
->address
>= start
);
11520 addr
= bl
->address
- start
;
11521 if (addr
> bp_locations_placed_address_before_address_max
)
11522 bp_locations_placed_address_before_address_max
= addr
;
11524 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11526 gdb_assert (bl
->address
< end
);
11527 addr
= end
- bl
->address
;
11528 if (addr
> bp_locations_shadow_len_after_address_max
)
11529 bp_locations_shadow_len_after_address_max
= addr
;
11533 /* Download tracepoint locations if they haven't been. */
11536 download_tracepoint_locations (void)
11538 struct breakpoint
*b
;
11539 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11541 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11543 ALL_TRACEPOINTS (b
)
11545 struct bp_location
*bl
;
11546 struct tracepoint
*t
;
11547 int bp_location_downloaded
= 0;
11549 if ((b
->type
== bp_fast_tracepoint
11550 ? !may_insert_fast_tracepoints
11551 : !may_insert_tracepoints
))
11554 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11556 if (target_can_download_tracepoint ())
11557 can_download_tracepoint
= TRIBOOL_TRUE
;
11559 can_download_tracepoint
= TRIBOOL_FALSE
;
11562 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11565 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11567 /* In tracepoint, locations are _never_ duplicated, so
11568 should_be_inserted is equivalent to
11569 unduplicated_should_be_inserted. */
11570 if (!should_be_inserted (bl
) || bl
->inserted
)
11573 switch_to_program_space_and_thread (bl
->pspace
);
11575 target_download_tracepoint (bl
);
11578 bp_location_downloaded
= 1;
11580 t
= (struct tracepoint
*) b
;
11581 t
->number_on_target
= b
->number
;
11582 if (bp_location_downloaded
)
11583 gdb::observers::breakpoint_modified
.notify (b
);
11587 /* Swap the insertion/duplication state between two locations. */
11590 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11592 const int left_inserted
= left
->inserted
;
11593 const int left_duplicate
= left
->duplicate
;
11594 const int left_needs_update
= left
->needs_update
;
11595 const struct bp_target_info left_target_info
= left
->target_info
;
11597 /* Locations of tracepoints can never be duplicated. */
11598 if (is_tracepoint (left
->owner
))
11599 gdb_assert (!left
->duplicate
);
11600 if (is_tracepoint (right
->owner
))
11601 gdb_assert (!right
->duplicate
);
11603 left
->inserted
= right
->inserted
;
11604 left
->duplicate
= right
->duplicate
;
11605 left
->needs_update
= right
->needs_update
;
11606 left
->target_info
= right
->target_info
;
11607 right
->inserted
= left_inserted
;
11608 right
->duplicate
= left_duplicate
;
11609 right
->needs_update
= left_needs_update
;
11610 right
->target_info
= left_target_info
;
11613 /* Force the re-insertion of the locations at ADDRESS. This is called
11614 once a new/deleted/modified duplicate location is found and we are evaluating
11615 conditions on the target's side. Such conditions need to be updated on
11619 force_breakpoint_reinsertion (struct bp_location
*bl
)
11621 struct bp_location
**locp
= NULL
, **loc2p
;
11622 struct bp_location
*loc
;
11623 CORE_ADDR address
= 0;
11626 address
= bl
->address
;
11627 pspace_num
= bl
->pspace
->num
;
11629 /* This is only meaningful if the target is
11630 evaluating conditions and if the user has
11631 opted for condition evaluation on the target's
11633 if (gdb_evaluates_breakpoint_condition_p ()
11634 || !target_supports_evaluation_of_breakpoint_conditions ())
11637 /* Flag all breakpoint locations with this address and
11638 the same program space as the location
11639 as "its condition has changed". We need to
11640 update the conditions on the target's side. */
11641 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11645 if (!is_breakpoint (loc
->owner
)
11646 || pspace_num
!= loc
->pspace
->num
)
11649 /* Flag the location appropriately. We use a different state to
11650 let everyone know that we already updated the set of locations
11651 with addr bl->address and program space bl->pspace. This is so
11652 we don't have to keep calling these functions just to mark locations
11653 that have already been marked. */
11654 loc
->condition_changed
= condition_updated
;
11656 /* Free the agent expression bytecode as well. We will compute
11658 loc
->cond_bytecode
.reset ();
11661 /* Called whether new breakpoints are created, or existing breakpoints
11662 deleted, to update the global location list and recompute which
11663 locations are duplicate of which.
11665 The INSERT_MODE flag determines whether locations may not, may, or
11666 shall be inserted now. See 'enum ugll_insert_mode' for more
11670 update_global_location_list (enum ugll_insert_mode insert_mode
)
11672 struct breakpoint
*b
;
11673 struct bp_location
**locp
, *loc
;
11674 /* Last breakpoint location address that was marked for update. */
11675 CORE_ADDR last_addr
= 0;
11676 /* Last breakpoint location program space that was marked for update. */
11677 int last_pspace_num
= -1;
11679 /* Used in the duplicates detection below. When iterating over all
11680 bp_locations, points to the first bp_location of a given address.
11681 Breakpoints and watchpoints of different types are never
11682 duplicates of each other. Keep one pointer for each type of
11683 breakpoint/watchpoint, so we only need to loop over all locations
11685 struct bp_location
*bp_loc_first
; /* breakpoint */
11686 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11687 struct bp_location
*awp_loc_first
; /* access watchpoint */
11688 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11690 /* Saved former bp_locations array which we compare against the newly
11691 built bp_locations from the current state of ALL_BREAKPOINTS. */
11692 struct bp_location
**old_locp
;
11693 unsigned old_locations_count
;
11694 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11696 old_locations_count
= bp_locations_count
;
11697 bp_locations
= NULL
;
11698 bp_locations_count
= 0;
11700 ALL_BREAKPOINTS (b
)
11701 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11702 bp_locations_count
++;
11704 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11705 locp
= bp_locations
;
11706 ALL_BREAKPOINTS (b
)
11707 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11709 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
11710 bp_locations_compare
);
11712 bp_locations_target_extensions_update ();
11714 /* Identify bp_location instances that are no longer present in the
11715 new list, and therefore should be freed. Note that it's not
11716 necessary that those locations should be removed from inferior --
11717 if there's another location at the same address (previously
11718 marked as duplicate), we don't need to remove/insert the
11721 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11722 and former bp_location array state respectively. */
11724 locp
= bp_locations
;
11725 for (old_locp
= old_locations
.get ();
11726 old_locp
< old_locations
.get () + old_locations_count
;
11729 struct bp_location
*old_loc
= *old_locp
;
11730 struct bp_location
**loc2p
;
11732 /* Tells if 'old_loc' is found among the new locations. If
11733 not, we have to free it. */
11734 int found_object
= 0;
11735 /* Tells if the location should remain inserted in the target. */
11736 int keep_in_target
= 0;
11739 /* Skip LOCP entries which will definitely never be needed.
11740 Stop either at or being the one matching OLD_LOC. */
11741 while (locp
< bp_locations
+ bp_locations_count
11742 && (*locp
)->address
< old_loc
->address
)
11746 (loc2p
< bp_locations
+ bp_locations_count
11747 && (*loc2p
)->address
== old_loc
->address
);
11750 /* Check if this is a new/duplicated location or a duplicated
11751 location that had its condition modified. If so, we want to send
11752 its condition to the target if evaluation of conditions is taking
11754 if ((*loc2p
)->condition_changed
== condition_modified
11755 && (last_addr
!= old_loc
->address
11756 || last_pspace_num
!= old_loc
->pspace
->num
))
11758 force_breakpoint_reinsertion (*loc2p
);
11759 last_pspace_num
= old_loc
->pspace
->num
;
11762 if (*loc2p
== old_loc
)
11766 /* We have already handled this address, update it so that we don't
11767 have to go through updates again. */
11768 last_addr
= old_loc
->address
;
11770 /* Target-side condition evaluation: Handle deleted locations. */
11772 force_breakpoint_reinsertion (old_loc
);
11774 /* If this location is no longer present, and inserted, look if
11775 there's maybe a new location at the same address. If so,
11776 mark that one inserted, and don't remove this one. This is
11777 needed so that we don't have a time window where a breakpoint
11778 at certain location is not inserted. */
11780 if (old_loc
->inserted
)
11782 /* If the location is inserted now, we might have to remove
11785 if (found_object
&& should_be_inserted (old_loc
))
11787 /* The location is still present in the location list,
11788 and still should be inserted. Don't do anything. */
11789 keep_in_target
= 1;
11793 /* This location still exists, but it won't be kept in the
11794 target since it may have been disabled. We proceed to
11795 remove its target-side condition. */
11797 /* The location is either no longer present, or got
11798 disabled. See if there's another location at the
11799 same address, in which case we don't need to remove
11800 this one from the target. */
11802 /* OLD_LOC comes from existing struct breakpoint. */
11803 if (breakpoint_address_is_meaningful (old_loc
->owner
))
11806 (loc2p
< bp_locations
+ bp_locations_count
11807 && (*loc2p
)->address
== old_loc
->address
);
11810 struct bp_location
*loc2
= *loc2p
;
11812 if (breakpoint_locations_match (loc2
, old_loc
))
11814 /* Read watchpoint locations are switched to
11815 access watchpoints, if the former are not
11816 supported, but the latter are. */
11817 if (is_hardware_watchpoint (old_loc
->owner
))
11819 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
11820 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
11823 /* loc2 is a duplicated location. We need to check
11824 if it should be inserted in case it will be
11826 if (loc2
!= old_loc
11827 && unduplicated_should_be_inserted (loc2
))
11829 swap_insertion (old_loc
, loc2
);
11830 keep_in_target
= 1;
11838 if (!keep_in_target
)
11840 if (remove_breakpoint (old_loc
))
11842 /* This is just about all we can do. We could keep
11843 this location on the global list, and try to
11844 remove it next time, but there's no particular
11845 reason why we will succeed next time.
11847 Note that at this point, old_loc->owner is still
11848 valid, as delete_breakpoint frees the breakpoint
11849 only after calling us. */
11850 printf_filtered (_("warning: Error removing "
11851 "breakpoint %d\n"),
11852 old_loc
->owner
->number
);
11860 if (removed
&& target_is_non_stop_p ()
11861 && need_moribund_for_location_type (old_loc
))
11863 /* This location was removed from the target. In
11864 non-stop mode, a race condition is possible where
11865 we've removed a breakpoint, but stop events for that
11866 breakpoint are already queued and will arrive later.
11867 We apply an heuristic to be able to distinguish such
11868 SIGTRAPs from other random SIGTRAPs: we keep this
11869 breakpoint location for a bit, and will retire it
11870 after we see some number of events. The theory here
11871 is that reporting of events should, "on the average",
11872 be fair, so after a while we'll see events from all
11873 threads that have anything of interest, and no longer
11874 need to keep this breakpoint location around. We
11875 don't hold locations forever so to reduce chances of
11876 mistaking a non-breakpoint SIGTRAP for a breakpoint
11879 The heuristic failing can be disastrous on
11880 decr_pc_after_break targets.
11882 On decr_pc_after_break targets, like e.g., x86-linux,
11883 if we fail to recognize a late breakpoint SIGTRAP,
11884 because events_till_retirement has reached 0 too
11885 soon, we'll fail to do the PC adjustment, and report
11886 a random SIGTRAP to the user. When the user resumes
11887 the inferior, it will most likely immediately crash
11888 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
11889 corrupted, because of being resumed e.g., in the
11890 middle of a multi-byte instruction, or skipped a
11891 one-byte instruction. This was actually seen happen
11892 on native x86-linux, and should be less rare on
11893 targets that do not support new thread events, like
11894 remote, due to the heuristic depending on
11897 Mistaking a random SIGTRAP for a breakpoint trap
11898 causes similar symptoms (PC adjustment applied when
11899 it shouldn't), but then again, playing with SIGTRAPs
11900 behind the debugger's back is asking for trouble.
11902 Since hardware watchpoint traps are always
11903 distinguishable from other traps, so we don't need to
11904 apply keep hardware watchpoint moribund locations
11905 around. We simply always ignore hardware watchpoint
11906 traps we can no longer explain. */
11908 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
11909 old_loc
->owner
= NULL
;
11911 moribund_locations
.push_back (old_loc
);
11915 old_loc
->owner
= NULL
;
11916 decref_bp_location (&old_loc
);
11921 /* Rescan breakpoints at the same address and section, marking the
11922 first one as "first" and any others as "duplicates". This is so
11923 that the bpt instruction is only inserted once. If we have a
11924 permanent breakpoint at the same place as BPT, make that one the
11925 official one, and the rest as duplicates. Permanent breakpoints
11926 are sorted first for the same address.
11928 Do the same for hardware watchpoints, but also considering the
11929 watchpoint's type (regular/access/read) and length. */
11931 bp_loc_first
= NULL
;
11932 wp_loc_first
= NULL
;
11933 awp_loc_first
= NULL
;
11934 rwp_loc_first
= NULL
;
11935 ALL_BP_LOCATIONS (loc
, locp
)
11937 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
11939 struct bp_location
**loc_first_p
;
11942 if (!unduplicated_should_be_inserted (loc
)
11943 || !breakpoint_address_is_meaningful (b
)
11944 /* Don't detect duplicate for tracepoint locations because they are
11945 never duplicated. See the comments in field `duplicate' of
11946 `struct bp_location'. */
11947 || is_tracepoint (b
))
11949 /* Clear the condition modification flag. */
11950 loc
->condition_changed
= condition_unchanged
;
11954 if (b
->type
== bp_hardware_watchpoint
)
11955 loc_first_p
= &wp_loc_first
;
11956 else if (b
->type
== bp_read_watchpoint
)
11957 loc_first_p
= &rwp_loc_first
;
11958 else if (b
->type
== bp_access_watchpoint
)
11959 loc_first_p
= &awp_loc_first
;
11961 loc_first_p
= &bp_loc_first
;
11963 if (*loc_first_p
== NULL
11964 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
11965 || !breakpoint_locations_match (loc
, *loc_first_p
))
11967 *loc_first_p
= loc
;
11968 loc
->duplicate
= 0;
11970 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
11972 loc
->needs_update
= 1;
11973 /* Clear the condition modification flag. */
11974 loc
->condition_changed
= condition_unchanged
;
11980 /* This and the above ensure the invariant that the first location
11981 is not duplicated, and is the inserted one.
11982 All following are marked as duplicated, and are not inserted. */
11984 swap_insertion (loc
, *loc_first_p
);
11985 loc
->duplicate
= 1;
11987 /* Clear the condition modification flag. */
11988 loc
->condition_changed
= condition_unchanged
;
11991 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
11993 if (insert_mode
!= UGLL_DONT_INSERT
)
11994 insert_breakpoint_locations ();
11997 /* Even though the caller told us to not insert new
11998 locations, we may still need to update conditions on the
11999 target's side of breakpoints that were already inserted
12000 if the target is evaluating breakpoint conditions. We
12001 only update conditions for locations that are marked
12003 update_inserted_breakpoint_locations ();
12007 if (insert_mode
!= UGLL_DONT_INSERT
)
12008 download_tracepoint_locations ();
12012 breakpoint_retire_moribund (void)
12014 for (int ix
= 0; ix
< moribund_locations
.size (); ++ix
)
12016 struct bp_location
*loc
= moribund_locations
[ix
];
12017 if (--(loc
->events_till_retirement
) == 0)
12019 decref_bp_location (&loc
);
12020 unordered_remove (moribund_locations
, ix
);
12027 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12032 update_global_location_list (insert_mode
);
12034 catch (const gdb_exception_error
&e
)
12039 /* Clear BKP from a BPS. */
12042 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12046 for (bs
= bps
; bs
; bs
= bs
->next
)
12047 if (bs
->breakpoint_at
== bpt
)
12049 bs
->breakpoint_at
= NULL
;
12050 bs
->old_val
= NULL
;
12051 /* bs->commands will be freed later. */
12055 /* Callback for iterate_over_threads. */
12057 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12059 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12061 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12065 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12069 say_where (struct breakpoint
*b
)
12071 struct value_print_options opts
;
12073 get_user_print_options (&opts
);
12075 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12077 if (b
->loc
== NULL
)
12079 /* For pending locations, the output differs slightly based
12080 on b->extra_string. If this is non-NULL, it contains either
12081 a condition or dprintf arguments. */
12082 if (b
->extra_string
== NULL
)
12084 printf_filtered (_(" (%s) pending."),
12085 event_location_to_string (b
->location
.get ()));
12087 else if (b
->type
== bp_dprintf
)
12089 printf_filtered (_(" (%s,%s) pending."),
12090 event_location_to_string (b
->location
.get ()),
12095 printf_filtered (_(" (%s %s) pending."),
12096 event_location_to_string (b
->location
.get ()),
12102 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12104 printf_filtered (" at ");
12105 fputs_styled (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12106 address_style
.style (),
12109 if (b
->loc
->symtab
!= NULL
)
12111 /* If there is a single location, we can print the location
12113 if (b
->loc
->next
== NULL
)
12115 puts_filtered (": file ");
12116 fputs_styled (symtab_to_filename_for_display (b
->loc
->symtab
),
12117 file_name_style
.style (),
12119 printf_filtered (", line %d.",
12120 b
->loc
->line_number
);
12123 /* This is not ideal, but each location may have a
12124 different file name, and this at least reflects the
12125 real situation somewhat. */
12126 printf_filtered (": %s.",
12127 event_location_to_string (b
->location
.get ()));
12132 struct bp_location
*loc
= b
->loc
;
12134 for (; loc
; loc
= loc
->next
)
12136 printf_filtered (" (%d locations)", n
);
12141 bp_location::~bp_location ()
12143 xfree (function_name
);
12146 /* Destructor for the breakpoint base class. */
12148 breakpoint::~breakpoint ()
12150 xfree (this->cond_string
);
12151 xfree (this->extra_string
);
12152 xfree (this->filter
);
12155 static struct bp_location
*
12156 base_breakpoint_allocate_location (struct breakpoint
*self
)
12158 return new bp_location (self
);
12162 base_breakpoint_re_set (struct breakpoint
*b
)
12164 /* Nothing to re-set. */
12167 #define internal_error_pure_virtual_called() \
12168 gdb_assert_not_reached ("pure virtual function called")
12171 base_breakpoint_insert_location (struct bp_location
*bl
)
12173 internal_error_pure_virtual_called ();
12177 base_breakpoint_remove_location (struct bp_location
*bl
,
12178 enum remove_bp_reason reason
)
12180 internal_error_pure_virtual_called ();
12184 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12185 const address_space
*aspace
,
12187 const struct target_waitstatus
*ws
)
12189 internal_error_pure_virtual_called ();
12193 base_breakpoint_check_status (bpstat bs
)
12198 /* A "works_in_software_mode" breakpoint_ops method that just internal
12202 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12204 internal_error_pure_virtual_called ();
12207 /* A "resources_needed" breakpoint_ops method that just internal
12211 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12213 internal_error_pure_virtual_called ();
12216 static enum print_stop_action
12217 base_breakpoint_print_it (bpstat bs
)
12219 internal_error_pure_virtual_called ();
12223 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12224 struct ui_out
*uiout
)
12230 base_breakpoint_print_mention (struct breakpoint
*b
)
12232 internal_error_pure_virtual_called ();
12236 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12238 internal_error_pure_virtual_called ();
12242 base_breakpoint_create_sals_from_location
12243 (const struct event_location
*location
,
12244 struct linespec_result
*canonical
,
12245 enum bptype type_wanted
)
12247 internal_error_pure_virtual_called ();
12251 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12252 struct linespec_result
*c
,
12253 gdb::unique_xmalloc_ptr
<char> cond_string
,
12254 gdb::unique_xmalloc_ptr
<char> extra_string
,
12255 enum bptype type_wanted
,
12256 enum bpdisp disposition
,
12258 int task
, int ignore_count
,
12259 const struct breakpoint_ops
*o
,
12260 int from_tty
, int enabled
,
12261 int internal
, unsigned flags
)
12263 internal_error_pure_virtual_called ();
12266 static std::vector
<symtab_and_line
>
12267 base_breakpoint_decode_location (struct breakpoint
*b
,
12268 const struct event_location
*location
,
12269 struct program_space
*search_pspace
)
12271 internal_error_pure_virtual_called ();
12274 /* The default 'explains_signal' method. */
12277 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12282 /* The default "after_condition_true" method. */
12285 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12287 /* Nothing to do. */
12290 struct breakpoint_ops base_breakpoint_ops
=
12292 base_breakpoint_allocate_location
,
12293 base_breakpoint_re_set
,
12294 base_breakpoint_insert_location
,
12295 base_breakpoint_remove_location
,
12296 base_breakpoint_breakpoint_hit
,
12297 base_breakpoint_check_status
,
12298 base_breakpoint_resources_needed
,
12299 base_breakpoint_works_in_software_mode
,
12300 base_breakpoint_print_it
,
12302 base_breakpoint_print_one_detail
,
12303 base_breakpoint_print_mention
,
12304 base_breakpoint_print_recreate
,
12305 base_breakpoint_create_sals_from_location
,
12306 base_breakpoint_create_breakpoints_sal
,
12307 base_breakpoint_decode_location
,
12308 base_breakpoint_explains_signal
,
12309 base_breakpoint_after_condition_true
,
12312 /* Default breakpoint_ops methods. */
12315 bkpt_re_set (struct breakpoint
*b
)
12317 /* FIXME: is this still reachable? */
12318 if (breakpoint_event_location_empty_p (b
))
12320 /* Anything without a location can't be re-set. */
12321 delete_breakpoint (b
);
12325 breakpoint_re_set_default (b
);
12329 bkpt_insert_location (struct bp_location
*bl
)
12331 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12333 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12334 bl
->target_info
.placed_address
= addr
;
12336 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12337 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12339 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12343 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12345 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12346 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12348 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12352 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12353 const address_space
*aspace
, CORE_ADDR bp_addr
,
12354 const struct target_waitstatus
*ws
)
12356 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12357 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12360 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12364 if (overlay_debugging
/* unmapped overlay section */
12365 && section_is_overlay (bl
->section
)
12366 && !section_is_mapped (bl
->section
))
12373 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12374 const address_space
*aspace
, CORE_ADDR bp_addr
,
12375 const struct target_waitstatus
*ws
)
12377 if (dprintf_style
== dprintf_style_agent
12378 && target_can_run_breakpoint_commands ())
12380 /* An agent-style dprintf never causes a stop. If we see a trap
12381 for this address it must be for a breakpoint that happens to
12382 be set at the same address. */
12386 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12390 bkpt_resources_needed (const struct bp_location
*bl
)
12392 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12397 static enum print_stop_action
12398 bkpt_print_it (bpstat bs
)
12400 struct breakpoint
*b
;
12401 const struct bp_location
*bl
;
12403 struct ui_out
*uiout
= current_uiout
;
12405 gdb_assert (bs
->bp_location_at
!= NULL
);
12407 bl
= bs
->bp_location_at
;
12408 b
= bs
->breakpoint_at
;
12410 bp_temp
= b
->disposition
== disp_del
;
12411 if (bl
->address
!= bl
->requested_address
)
12412 breakpoint_adjustment_warning (bl
->requested_address
,
12415 annotate_breakpoint (b
->number
);
12416 maybe_print_thread_hit_breakpoint (uiout
);
12419 uiout
->text ("Temporary breakpoint ");
12421 uiout
->text ("Breakpoint ");
12422 if (uiout
->is_mi_like_p ())
12424 uiout
->field_string ("reason",
12425 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12426 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12428 uiout
->field_int ("bkptno", b
->number
);
12429 uiout
->text (", ");
12431 return PRINT_SRC_AND_LOC
;
12435 bkpt_print_mention (struct breakpoint
*b
)
12437 if (current_uiout
->is_mi_like_p ())
12442 case bp_breakpoint
:
12443 case bp_gnu_ifunc_resolver
:
12444 if (b
->disposition
== disp_del
)
12445 printf_filtered (_("Temporary breakpoint"));
12447 printf_filtered (_("Breakpoint"));
12448 printf_filtered (_(" %d"), b
->number
);
12449 if (b
->type
== bp_gnu_ifunc_resolver
)
12450 printf_filtered (_(" at gnu-indirect-function resolver"));
12452 case bp_hardware_breakpoint
:
12453 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12456 printf_filtered (_("Dprintf %d"), b
->number
);
12464 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12466 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12467 fprintf_unfiltered (fp
, "tbreak");
12468 else if (tp
->type
== bp_breakpoint
)
12469 fprintf_unfiltered (fp
, "break");
12470 else if (tp
->type
== bp_hardware_breakpoint
12471 && tp
->disposition
== disp_del
)
12472 fprintf_unfiltered (fp
, "thbreak");
12473 else if (tp
->type
== bp_hardware_breakpoint
)
12474 fprintf_unfiltered (fp
, "hbreak");
12476 internal_error (__FILE__
, __LINE__
,
12477 _("unhandled breakpoint type %d"), (int) tp
->type
);
12479 fprintf_unfiltered (fp
, " %s",
12480 event_location_to_string (tp
->location
.get ()));
12482 /* Print out extra_string if this breakpoint is pending. It might
12483 contain, for example, conditions that were set by the user. */
12484 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12485 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12487 print_recreate_thread (tp
, fp
);
12491 bkpt_create_sals_from_location (const struct event_location
*location
,
12492 struct linespec_result
*canonical
,
12493 enum bptype type_wanted
)
12495 create_sals_from_location_default (location
, canonical
, type_wanted
);
12499 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12500 struct linespec_result
*canonical
,
12501 gdb::unique_xmalloc_ptr
<char> cond_string
,
12502 gdb::unique_xmalloc_ptr
<char> extra_string
,
12503 enum bptype type_wanted
,
12504 enum bpdisp disposition
,
12506 int task
, int ignore_count
,
12507 const struct breakpoint_ops
*ops
,
12508 int from_tty
, int enabled
,
12509 int internal
, unsigned flags
)
12511 create_breakpoints_sal_default (gdbarch
, canonical
,
12512 std::move (cond_string
),
12513 std::move (extra_string
),
12515 disposition
, thread
, task
,
12516 ignore_count
, ops
, from_tty
,
12517 enabled
, internal
, flags
);
12520 static std::vector
<symtab_and_line
>
12521 bkpt_decode_location (struct breakpoint
*b
,
12522 const struct event_location
*location
,
12523 struct program_space
*search_pspace
)
12525 return decode_location_default (b
, location
, search_pspace
);
12528 /* Virtual table for internal breakpoints. */
12531 internal_bkpt_re_set (struct breakpoint
*b
)
12535 /* Delete overlay event and longjmp master breakpoints; they
12536 will be reset later by breakpoint_re_set. */
12537 case bp_overlay_event
:
12538 case bp_longjmp_master
:
12539 case bp_std_terminate_master
:
12540 case bp_exception_master
:
12541 delete_breakpoint (b
);
12544 /* This breakpoint is special, it's set up when the inferior
12545 starts and we really don't want to touch it. */
12546 case bp_shlib_event
:
12548 /* Like bp_shlib_event, this breakpoint type is special. Once
12549 it is set up, we do not want to touch it. */
12550 case bp_thread_event
:
12556 internal_bkpt_check_status (bpstat bs
)
12558 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12560 /* If requested, stop when the dynamic linker notifies GDB of
12561 events. This allows the user to get control and place
12562 breakpoints in initializer routines for dynamically loaded
12563 objects (among other things). */
12564 bs
->stop
= stop_on_solib_events
;
12565 bs
->print
= stop_on_solib_events
;
12571 static enum print_stop_action
12572 internal_bkpt_print_it (bpstat bs
)
12574 struct breakpoint
*b
;
12576 b
= bs
->breakpoint_at
;
12580 case bp_shlib_event
:
12581 /* Did we stop because the user set the stop_on_solib_events
12582 variable? (If so, we report this as a generic, "Stopped due
12583 to shlib event" message.) */
12584 print_solib_event (0);
12587 case bp_thread_event
:
12588 /* Not sure how we will get here.
12589 GDB should not stop for these breakpoints. */
12590 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12593 case bp_overlay_event
:
12594 /* By analogy with the thread event, GDB should not stop for these. */
12595 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12598 case bp_longjmp_master
:
12599 /* These should never be enabled. */
12600 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12603 case bp_std_terminate_master
:
12604 /* These should never be enabled. */
12605 printf_filtered (_("std::terminate Master Breakpoint: "
12606 "gdb should not stop!\n"));
12609 case bp_exception_master
:
12610 /* These should never be enabled. */
12611 printf_filtered (_("Exception Master Breakpoint: "
12612 "gdb should not stop!\n"));
12616 return PRINT_NOTHING
;
12620 internal_bkpt_print_mention (struct breakpoint
*b
)
12622 /* Nothing to mention. These breakpoints are internal. */
12625 /* Virtual table for momentary breakpoints */
12628 momentary_bkpt_re_set (struct breakpoint
*b
)
12630 /* Keep temporary breakpoints, which can be encountered when we step
12631 over a dlopen call and solib_add is resetting the breakpoints.
12632 Otherwise these should have been blown away via the cleanup chain
12633 or by breakpoint_init_inferior when we rerun the executable. */
12637 momentary_bkpt_check_status (bpstat bs
)
12639 /* Nothing. The point of these breakpoints is causing a stop. */
12642 static enum print_stop_action
12643 momentary_bkpt_print_it (bpstat bs
)
12645 return PRINT_UNKNOWN
;
12649 momentary_bkpt_print_mention (struct breakpoint
*b
)
12651 /* Nothing to mention. These breakpoints are internal. */
12654 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12656 It gets cleared already on the removal of the first one of such placed
12657 breakpoints. This is OK as they get all removed altogether. */
12659 longjmp_breakpoint::~longjmp_breakpoint ()
12661 thread_info
*tp
= find_thread_global_id (this->thread
);
12664 tp
->initiating_frame
= null_frame_id
;
12667 /* Specific methods for probe breakpoints. */
12670 bkpt_probe_insert_location (struct bp_location
*bl
)
12672 int v
= bkpt_insert_location (bl
);
12676 /* The insertion was successful, now let's set the probe's semaphore
12678 bl
->probe
.prob
->set_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12685 bkpt_probe_remove_location (struct bp_location
*bl
,
12686 enum remove_bp_reason reason
)
12688 /* Let's clear the semaphore before removing the location. */
12689 bl
->probe
.prob
->clear_semaphore (bl
->probe
.objfile
, bl
->gdbarch
);
12691 return bkpt_remove_location (bl
, reason
);
12695 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
12696 struct linespec_result
*canonical
,
12697 enum bptype type_wanted
)
12699 struct linespec_sals lsal
;
12701 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12703 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12704 canonical
->lsals
.push_back (std::move (lsal
));
12707 static std::vector
<symtab_and_line
>
12708 bkpt_probe_decode_location (struct breakpoint
*b
,
12709 const struct event_location
*location
,
12710 struct program_space
*search_pspace
)
12712 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12714 error (_("probe not found"));
12718 /* The breakpoint_ops structure to be used in tracepoints. */
12721 tracepoint_re_set (struct breakpoint
*b
)
12723 breakpoint_re_set_default (b
);
12727 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12728 const address_space
*aspace
, CORE_ADDR bp_addr
,
12729 const struct target_waitstatus
*ws
)
12731 /* By definition, the inferior does not report stops at
12737 tracepoint_print_one_detail (const struct breakpoint
*self
,
12738 struct ui_out
*uiout
)
12740 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12741 if (!tp
->static_trace_marker_id
.empty ())
12743 gdb_assert (self
->type
== bp_static_tracepoint
);
12745 uiout
->text ("\tmarker id is ");
12746 uiout
->field_string ("static-tracepoint-marker-string-id",
12747 tp
->static_trace_marker_id
);
12748 uiout
->text ("\n");
12753 tracepoint_print_mention (struct breakpoint
*b
)
12755 if (current_uiout
->is_mi_like_p ())
12760 case bp_tracepoint
:
12761 printf_filtered (_("Tracepoint"));
12762 printf_filtered (_(" %d"), b
->number
);
12764 case bp_fast_tracepoint
:
12765 printf_filtered (_("Fast tracepoint"));
12766 printf_filtered (_(" %d"), b
->number
);
12768 case bp_static_tracepoint
:
12769 printf_filtered (_("Static tracepoint"));
12770 printf_filtered (_(" %d"), b
->number
);
12773 internal_error (__FILE__
, __LINE__
,
12774 _("unhandled tracepoint type %d"), (int) b
->type
);
12781 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
12783 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12785 if (self
->type
== bp_fast_tracepoint
)
12786 fprintf_unfiltered (fp
, "ftrace");
12787 else if (self
->type
== bp_static_tracepoint
)
12788 fprintf_unfiltered (fp
, "strace");
12789 else if (self
->type
== bp_tracepoint
)
12790 fprintf_unfiltered (fp
, "trace");
12792 internal_error (__FILE__
, __LINE__
,
12793 _("unhandled tracepoint type %d"), (int) self
->type
);
12795 fprintf_unfiltered (fp
, " %s",
12796 event_location_to_string (self
->location
.get ()));
12797 print_recreate_thread (self
, fp
);
12799 if (tp
->pass_count
)
12800 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
12804 tracepoint_create_sals_from_location (const struct event_location
*location
,
12805 struct linespec_result
*canonical
,
12806 enum bptype type_wanted
)
12808 create_sals_from_location_default (location
, canonical
, type_wanted
);
12812 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12813 struct linespec_result
*canonical
,
12814 gdb::unique_xmalloc_ptr
<char> cond_string
,
12815 gdb::unique_xmalloc_ptr
<char> extra_string
,
12816 enum bptype type_wanted
,
12817 enum bpdisp disposition
,
12819 int task
, int ignore_count
,
12820 const struct breakpoint_ops
*ops
,
12821 int from_tty
, int enabled
,
12822 int internal
, unsigned flags
)
12824 create_breakpoints_sal_default (gdbarch
, canonical
,
12825 std::move (cond_string
),
12826 std::move (extra_string
),
12828 disposition
, thread
, task
,
12829 ignore_count
, ops
, from_tty
,
12830 enabled
, internal
, flags
);
12833 static std::vector
<symtab_and_line
>
12834 tracepoint_decode_location (struct breakpoint
*b
,
12835 const struct event_location
*location
,
12836 struct program_space
*search_pspace
)
12838 return decode_location_default (b
, location
, search_pspace
);
12841 struct breakpoint_ops tracepoint_breakpoint_ops
;
12843 /* The breakpoint_ops structure to be use on tracepoints placed in a
12847 tracepoint_probe_create_sals_from_location
12848 (const struct event_location
*location
,
12849 struct linespec_result
*canonical
,
12850 enum bptype type_wanted
)
12852 /* We use the same method for breakpoint on probes. */
12853 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
12856 static std::vector
<symtab_and_line
>
12857 tracepoint_probe_decode_location (struct breakpoint
*b
,
12858 const struct event_location
*location
,
12859 struct program_space
*search_pspace
)
12861 /* We use the same method for breakpoint on probes. */
12862 return bkpt_probe_decode_location (b
, location
, search_pspace
);
12865 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
12867 /* Dprintf breakpoint_ops methods. */
12870 dprintf_re_set (struct breakpoint
*b
)
12872 breakpoint_re_set_default (b
);
12874 /* extra_string should never be non-NULL for dprintf. */
12875 gdb_assert (b
->extra_string
!= NULL
);
12877 /* 1 - connect to target 1, that can run breakpoint commands.
12878 2 - create a dprintf, which resolves fine.
12879 3 - disconnect from target 1
12880 4 - connect to target 2, that can NOT run breakpoint commands.
12882 After steps #3/#4, you'll want the dprintf command list to
12883 be updated, because target 1 and 2 may well return different
12884 answers for target_can_run_breakpoint_commands().
12885 Given absence of finer grained resetting, we get to do
12886 it all the time. */
12887 if (b
->extra_string
!= NULL
)
12888 update_dprintf_command_list (b
);
12891 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
12894 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12896 fprintf_unfiltered (fp
, "dprintf %s,%s",
12897 event_location_to_string (tp
->location
.get ()),
12899 print_recreate_thread (tp
, fp
);
12902 /* Implement the "after_condition_true" breakpoint_ops method for
12905 dprintf's are implemented with regular commands in their command
12906 list, but we run the commands here instead of before presenting the
12907 stop to the user, as dprintf's don't actually cause a stop. This
12908 also makes it so that the commands of multiple dprintfs at the same
12909 address are all handled. */
12912 dprintf_after_condition_true (struct bpstats
*bs
)
12914 struct bpstats tmp_bs
;
12915 struct bpstats
*tmp_bs_p
= &tmp_bs
;
12917 /* dprintf's never cause a stop. This wasn't set in the
12918 check_status hook instead because that would make the dprintf's
12919 condition not be evaluated. */
12922 /* Run the command list here. Take ownership of it instead of
12923 copying. We never want these commands to run later in
12924 bpstat_do_actions, if a breakpoint that causes a stop happens to
12925 be set at same address as this dprintf, or even if running the
12926 commands here throws. */
12927 tmp_bs
.commands
= bs
->commands
;
12928 bs
->commands
= NULL
;
12930 bpstat_do_actions_1 (&tmp_bs_p
);
12932 /* 'tmp_bs.commands' will usually be NULL by now, but
12933 bpstat_do_actions_1 may return early without processing the whole
12937 /* The breakpoint_ops structure to be used on static tracepoints with
12941 strace_marker_create_sals_from_location (const struct event_location
*location
,
12942 struct linespec_result
*canonical
,
12943 enum bptype type_wanted
)
12945 struct linespec_sals lsal
;
12946 const char *arg_start
, *arg
;
12948 arg
= arg_start
= get_linespec_location (location
)->spec_string
;
12949 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
12951 std::string
str (arg_start
, arg
- arg_start
);
12952 const char *ptr
= str
.c_str ();
12953 canonical
->location
12954 = new_linespec_location (&ptr
, symbol_name_match_type::FULL
);
12957 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12958 canonical
->lsals
.push_back (std::move (lsal
));
12962 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12963 struct linespec_result
*canonical
,
12964 gdb::unique_xmalloc_ptr
<char> cond_string
,
12965 gdb::unique_xmalloc_ptr
<char> extra_string
,
12966 enum bptype type_wanted
,
12967 enum bpdisp disposition
,
12969 int task
, int ignore_count
,
12970 const struct breakpoint_ops
*ops
,
12971 int from_tty
, int enabled
,
12972 int internal
, unsigned flags
)
12974 const linespec_sals
&lsal
= canonical
->lsals
[0];
12976 /* If the user is creating a static tracepoint by marker id
12977 (strace -m MARKER_ID), then store the sals index, so that
12978 breakpoint_re_set can try to match up which of the newly
12979 found markers corresponds to this one, and, don't try to
12980 expand multiple locations for each sal, given than SALS
12981 already should contain all sals for MARKER_ID. */
12983 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
12985 event_location_up location
12986 = copy_event_location (canonical
->location
.get ());
12988 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
12989 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
12990 std::move (location
), NULL
,
12991 std::move (cond_string
),
12992 std::move (extra_string
),
12993 type_wanted
, disposition
,
12994 thread
, task
, ignore_count
, ops
,
12995 from_tty
, enabled
, internal
, flags
,
12996 canonical
->special_display
);
12997 /* Given that its possible to have multiple markers with
12998 the same string id, if the user is creating a static
12999 tracepoint by marker id ("strace -m MARKER_ID"), then
13000 store the sals index, so that breakpoint_re_set can
13001 try to match up which of the newly found markers
13002 corresponds to this one */
13003 tp
->static_trace_marker_id_idx
= i
;
13005 install_breakpoint (internal
, std::move (tp
), 0);
13009 static std::vector
<symtab_and_line
>
13010 strace_marker_decode_location (struct breakpoint
*b
,
13011 const struct event_location
*location
,
13012 struct program_space
*search_pspace
)
13014 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13015 const char *s
= get_linespec_location (location
)->spec_string
;
13017 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13018 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13020 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13025 error (_("marker %s not found"), tp
->static_trace_marker_id
.c_str ());
13028 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13031 strace_marker_p (struct breakpoint
*b
)
13033 return b
->ops
== &strace_marker_breakpoint_ops
;
13036 /* Delete a breakpoint and clean up all traces of it in the data
13040 delete_breakpoint (struct breakpoint
*bpt
)
13042 struct breakpoint
*b
;
13044 gdb_assert (bpt
!= NULL
);
13046 /* Has this bp already been deleted? This can happen because
13047 multiple lists can hold pointers to bp's. bpstat lists are
13050 One example of this happening is a watchpoint's scope bp. When
13051 the scope bp triggers, we notice that the watchpoint is out of
13052 scope, and delete it. We also delete its scope bp. But the
13053 scope bp is marked "auto-deleting", and is already on a bpstat.
13054 That bpstat is then checked for auto-deleting bp's, which are
13057 A real solution to this problem might involve reference counts in
13058 bp's, and/or giving them pointers back to their referencing
13059 bpstat's, and teaching delete_breakpoint to only free a bp's
13060 storage when no more references were extent. A cheaper bandaid
13062 if (bpt
->type
== bp_none
)
13065 /* At least avoid this stale reference until the reference counting
13066 of breakpoints gets resolved. */
13067 if (bpt
->related_breakpoint
!= bpt
)
13069 struct breakpoint
*related
;
13070 struct watchpoint
*w
;
13072 if (bpt
->type
== bp_watchpoint_scope
)
13073 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13074 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13075 w
= (struct watchpoint
*) bpt
;
13079 watchpoint_del_at_next_stop (w
);
13081 /* Unlink bpt from the bpt->related_breakpoint ring. */
13082 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13083 related
= related
->related_breakpoint
);
13084 related
->related_breakpoint
= bpt
->related_breakpoint
;
13085 bpt
->related_breakpoint
= bpt
;
13088 /* watch_command_1 creates a watchpoint but only sets its number if
13089 update_watchpoint succeeds in creating its bp_locations. If there's
13090 a problem in that process, we'll be asked to delete the half-created
13091 watchpoint. In that case, don't announce the deletion. */
13093 gdb::observers::breakpoint_deleted
.notify (bpt
);
13095 if (breakpoint_chain
== bpt
)
13096 breakpoint_chain
= bpt
->next
;
13098 ALL_BREAKPOINTS (b
)
13099 if (b
->next
== bpt
)
13101 b
->next
= bpt
->next
;
13105 /* Be sure no bpstat's are pointing at the breakpoint after it's
13107 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13108 in all threads for now. Note that we cannot just remove bpstats
13109 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13110 commands are associated with the bpstat; if we remove it here,
13111 then the later call to bpstat_do_actions (&stop_bpstat); in
13112 event-top.c won't do anything, and temporary breakpoints with
13113 commands won't work. */
13115 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13117 /* Now that breakpoint is removed from breakpoint list, update the
13118 global location list. This will remove locations that used to
13119 belong to this breakpoint. Do this before freeing the breakpoint
13120 itself, since remove_breakpoint looks at location's owner. It
13121 might be better design to have location completely
13122 self-contained, but it's not the case now. */
13123 update_global_location_list (UGLL_DONT_INSERT
);
13125 /* On the chance that someone will soon try again to delete this
13126 same bp, we mark it as deleted before freeing its storage. */
13127 bpt
->type
= bp_none
;
13131 /* Iterator function to call a user-provided callback function once
13132 for each of B and its related breakpoints. */
13135 iterate_over_related_breakpoints (struct breakpoint
*b
,
13136 gdb::function_view
<void (breakpoint
*)> function
)
13138 struct breakpoint
*related
;
13143 struct breakpoint
*next
;
13145 /* FUNCTION may delete RELATED. */
13146 next
= related
->related_breakpoint
;
13148 if (next
== related
)
13150 /* RELATED is the last ring entry. */
13151 function (related
);
13153 /* FUNCTION may have deleted it, so we'd never reach back to
13154 B. There's nothing left to do anyway, so just break
13159 function (related
);
13163 while (related
!= b
);
13167 delete_command (const char *arg
, int from_tty
)
13169 struct breakpoint
*b
, *b_tmp
;
13175 int breaks_to_delete
= 0;
13177 /* Delete all breakpoints if no argument. Do not delete
13178 internal breakpoints, these have to be deleted with an
13179 explicit breakpoint number argument. */
13180 ALL_BREAKPOINTS (b
)
13181 if (user_breakpoint_p (b
))
13183 breaks_to_delete
= 1;
13187 /* Ask user only if there are some breakpoints to delete. */
13189 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13191 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13192 if (user_breakpoint_p (b
))
13193 delete_breakpoint (b
);
13197 map_breakpoint_numbers
13198 (arg
, [&] (breakpoint
*br
)
13200 iterate_over_related_breakpoints (br
, delete_breakpoint
);
13204 /* Return true if all locations of B bound to PSPACE are pending. If
13205 PSPACE is NULL, all locations of all program spaces are
13209 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13211 struct bp_location
*loc
;
13213 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13214 if ((pspace
== NULL
13215 || loc
->pspace
== pspace
)
13216 && !loc
->shlib_disabled
13217 && !loc
->pspace
->executing_startup
)
13222 /* Subroutine of update_breakpoint_locations to simplify it.
13223 Return non-zero if multiple fns in list LOC have the same name.
13224 Null names are ignored. */
13227 ambiguous_names_p (struct bp_location
*loc
)
13229 struct bp_location
*l
;
13230 htab_t htab
= htab_create_alloc (13, htab_hash_string
, streq_hash
, NULL
,
13233 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13236 const char *name
= l
->function_name
;
13238 /* Allow for some names to be NULL, ignore them. */
13242 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13244 /* NOTE: We can assume slot != NULL here because xcalloc never
13248 htab_delete (htab
);
13254 htab_delete (htab
);
13258 /* When symbols change, it probably means the sources changed as well,
13259 and it might mean the static tracepoint markers are no longer at
13260 the same address or line numbers they used to be at last we
13261 checked. Losing your static tracepoints whenever you rebuild is
13262 undesirable. This function tries to resync/rematch gdb static
13263 tracepoints with the markers on the target, for static tracepoints
13264 that have not been set by marker id. Static tracepoint that have
13265 been set by marker id are reset by marker id in breakpoint_re_set.
13268 1) For a tracepoint set at a specific address, look for a marker at
13269 the old PC. If one is found there, assume to be the same marker.
13270 If the name / string id of the marker found is different from the
13271 previous known name, assume that means the user renamed the marker
13272 in the sources, and output a warning.
13274 2) For a tracepoint set at a given line number, look for a marker
13275 at the new address of the old line number. If one is found there,
13276 assume to be the same marker. If the name / string id of the
13277 marker found is different from the previous known name, assume that
13278 means the user renamed the marker in the sources, and output a
13281 3) If a marker is no longer found at the same address or line, it
13282 may mean the marker no longer exists. But it may also just mean
13283 the code changed a bit. Maybe the user added a few lines of code
13284 that made the marker move up or down (in line number terms). Ask
13285 the target for info about the marker with the string id as we knew
13286 it. If found, update line number and address in the matching
13287 static tracepoint. This will get confused if there's more than one
13288 marker with the same ID (possible in UST, although unadvised
13289 precisely because it confuses tools). */
13291 static struct symtab_and_line
13292 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13294 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13295 struct static_tracepoint_marker marker
;
13300 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13302 if (target_static_tracepoint_marker_at (pc
, &marker
))
13304 if (tp
->static_trace_marker_id
!= marker
.str_id
)
13305 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13306 b
->number
, tp
->static_trace_marker_id
.c_str (),
13307 marker
.str_id
.c_str ());
13309 tp
->static_trace_marker_id
= std::move (marker
.str_id
);
13314 /* Old marker wasn't found on target at lineno. Try looking it up
13316 if (!sal
.explicit_pc
13318 && sal
.symtab
!= NULL
13319 && !tp
->static_trace_marker_id
.empty ())
13321 std::vector
<static_tracepoint_marker
> markers
13322 = target_static_tracepoint_markers_by_strid
13323 (tp
->static_trace_marker_id
.c_str ());
13325 if (!markers
.empty ())
13327 struct symbol
*sym
;
13328 struct static_tracepoint_marker
*tpmarker
;
13329 struct ui_out
*uiout
= current_uiout
;
13330 struct explicit_location explicit_loc
;
13332 tpmarker
= &markers
[0];
13334 tp
->static_trace_marker_id
= std::move (tpmarker
->str_id
);
13336 warning (_("marker for static tracepoint %d (%s) not "
13337 "found at previous line number"),
13338 b
->number
, tp
->static_trace_marker_id
.c_str ());
13340 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13341 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13342 uiout
->text ("Now in ");
13345 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
),
13346 ui_out_style_kind::FUNCTION
);
13347 uiout
->text (" at ");
13349 uiout
->field_string ("file",
13350 symtab_to_filename_for_display (sal2
.symtab
),
13351 ui_out_style_kind::FILE);
13354 if (uiout
->is_mi_like_p ())
13356 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13358 uiout
->field_string ("fullname", fullname
);
13361 uiout
->field_int ("line", sal2
.line
);
13362 uiout
->text ("\n");
13364 b
->loc
->line_number
= sal2
.line
;
13365 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13367 b
->location
.reset (NULL
);
13368 initialize_explicit_location (&explicit_loc
);
13369 explicit_loc
.source_filename
13370 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13371 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13372 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13373 b
->location
= new_explicit_location (&explicit_loc
);
13375 /* Might be nice to check if function changed, and warn if
13382 /* Returns 1 iff locations A and B are sufficiently same that
13383 we don't need to report breakpoint as changed. */
13386 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13390 if (a
->address
!= b
->address
)
13393 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13396 if (a
->enabled
!= b
->enabled
)
13403 if ((a
== NULL
) != (b
== NULL
))
13409 /* Split all locations of B that are bound to PSPACE out of B's
13410 location list to a separate list and return that list's head. If
13411 PSPACE is NULL, hoist out all locations of B. */
13413 static struct bp_location
*
13414 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13416 struct bp_location head
;
13417 struct bp_location
*i
= b
->loc
;
13418 struct bp_location
**i_link
= &b
->loc
;
13419 struct bp_location
*hoisted
= &head
;
13421 if (pspace
== NULL
)
13432 if (i
->pspace
== pspace
)
13447 /* Create new breakpoint locations for B (a hardware or software
13448 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13449 zero, then B is a ranged breakpoint. Only recreates locations for
13450 FILTER_PSPACE. Locations of other program spaces are left
13454 update_breakpoint_locations (struct breakpoint
*b
,
13455 struct program_space
*filter_pspace
,
13456 gdb::array_view
<const symtab_and_line
> sals
,
13457 gdb::array_view
<const symtab_and_line
> sals_end
)
13459 struct bp_location
*existing_locations
;
13461 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13463 /* Ranged breakpoints have only one start location and one end
13465 b
->enable_state
= bp_disabled
;
13466 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13467 "multiple locations found\n"),
13472 /* If there's no new locations, and all existing locations are
13473 pending, don't do anything. This optimizes the common case where
13474 all locations are in the same shared library, that was unloaded.
13475 We'd like to retain the location, so that when the library is
13476 loaded again, we don't loose the enabled/disabled status of the
13477 individual locations. */
13478 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13481 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13483 for (const auto &sal
: sals
)
13485 struct bp_location
*new_loc
;
13487 switch_to_program_space_and_thread (sal
.pspace
);
13489 new_loc
= add_location_to_breakpoint (b
, &sal
);
13491 /* Reparse conditions, they might contain references to the
13493 if (b
->cond_string
!= NULL
)
13497 s
= b
->cond_string
;
13500 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13501 block_for_pc (sal
.pc
),
13504 catch (const gdb_exception_error
&e
)
13506 warning (_("failed to reevaluate condition "
13507 "for breakpoint %d: %s"),
13508 b
->number
, e
.what ());
13509 new_loc
->enabled
= 0;
13513 if (!sals_end
.empty ())
13515 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13517 new_loc
->length
= end
- sals
[0].pc
+ 1;
13521 /* If possible, carry over 'disable' status from existing
13524 struct bp_location
*e
= existing_locations
;
13525 /* If there are multiple breakpoints with the same function name,
13526 e.g. for inline functions, comparing function names won't work.
13527 Instead compare pc addresses; this is just a heuristic as things
13528 may have moved, but in practice it gives the correct answer
13529 often enough until a better solution is found. */
13530 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13532 for (; e
; e
= e
->next
)
13534 if (!e
->enabled
&& e
->function_name
)
13536 struct bp_location
*l
= b
->loc
;
13537 if (have_ambiguous_names
)
13539 for (; l
; l
= l
->next
)
13540 if (breakpoint_locations_match (e
, l
))
13548 for (; l
; l
= l
->next
)
13549 if (l
->function_name
13550 && strcmp (e
->function_name
, l
->function_name
) == 0)
13560 if (!locations_are_equal (existing_locations
, b
->loc
))
13561 gdb::observers::breakpoint_modified
.notify (b
);
13564 /* Find the SaL locations corresponding to the given LOCATION.
13565 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13567 static std::vector
<symtab_and_line
>
13568 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13569 struct program_space
*search_pspace
, int *found
)
13571 struct gdb_exception exception
;
13573 gdb_assert (b
->ops
!= NULL
);
13575 std::vector
<symtab_and_line
> sals
;
13579 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13581 catch (gdb_exception_error
&e
)
13583 int not_found_and_ok
= 0;
13585 /* For pending breakpoints, it's expected that parsing will
13586 fail until the right shared library is loaded. User has
13587 already told to create pending breakpoints and don't need
13588 extra messages. If breakpoint is in bp_shlib_disabled
13589 state, then user already saw the message about that
13590 breakpoint being disabled, and don't want to see more
13592 if (e
.error
== NOT_FOUND_ERROR
13593 && (b
->condition_not_parsed
13595 && search_pspace
!= NULL
13596 && b
->loc
->pspace
!= search_pspace
)
13597 || (b
->loc
&& b
->loc
->shlib_disabled
)
13598 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13599 || b
->enable_state
== bp_disabled
))
13600 not_found_and_ok
= 1;
13602 if (!not_found_and_ok
)
13604 /* We surely don't want to warn about the same breakpoint
13605 10 times. One solution, implemented here, is disable
13606 the breakpoint on error. Another solution would be to
13607 have separate 'warning emitted' flag. Since this
13608 happens only when a binary has changed, I don't know
13609 which approach is better. */
13610 b
->enable_state
= bp_disabled
;
13614 exception
= std::move (e
);
13617 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13619 for (auto &sal
: sals
)
13620 resolve_sal_pc (&sal
);
13621 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13623 char *cond_string
, *extra_string
;
13626 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
13627 &cond_string
, &thread
, &task
,
13629 gdb_assert (b
->cond_string
== NULL
);
13631 b
->cond_string
= cond_string
;
13632 b
->thread
= thread
;
13636 xfree (b
->extra_string
);
13637 b
->extra_string
= extra_string
;
13639 b
->condition_not_parsed
= 0;
13642 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13643 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13653 /* The default re_set method, for typical hardware or software
13654 breakpoints. Reevaluate the breakpoint and recreate its
13658 breakpoint_re_set_default (struct breakpoint
*b
)
13660 struct program_space
*filter_pspace
= current_program_space
;
13661 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13664 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13665 filter_pspace
, &found
);
13667 expanded
= std::move (sals
);
13669 if (b
->location_range_end
!= NULL
)
13671 std::vector
<symtab_and_line
> sals_end
13672 = location_to_sals (b
, b
->location_range_end
.get (),
13673 filter_pspace
, &found
);
13675 expanded_end
= std::move (sals_end
);
13678 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13681 /* Default method for creating SALs from an address string. It basically
13682 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13685 create_sals_from_location_default (const struct event_location
*location
,
13686 struct linespec_result
*canonical
,
13687 enum bptype type_wanted
)
13689 parse_breakpoint_sals (location
, canonical
);
13692 /* Call create_breakpoints_sal for the given arguments. This is the default
13693 function for the `create_breakpoints_sal' method of
13697 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13698 struct linespec_result
*canonical
,
13699 gdb::unique_xmalloc_ptr
<char> cond_string
,
13700 gdb::unique_xmalloc_ptr
<char> extra_string
,
13701 enum bptype type_wanted
,
13702 enum bpdisp disposition
,
13704 int task
, int ignore_count
,
13705 const struct breakpoint_ops
*ops
,
13706 int from_tty
, int enabled
,
13707 int internal
, unsigned flags
)
13709 create_breakpoints_sal (gdbarch
, canonical
,
13710 std::move (cond_string
),
13711 std::move (extra_string
),
13712 type_wanted
, disposition
,
13713 thread
, task
, ignore_count
, ops
, from_tty
,
13714 enabled
, internal
, flags
);
13717 /* Decode the line represented by S by calling decode_line_full. This is the
13718 default function for the `decode_location' method of breakpoint_ops. */
13720 static std::vector
<symtab_and_line
>
13721 decode_location_default (struct breakpoint
*b
,
13722 const struct event_location
*location
,
13723 struct program_space
*search_pspace
)
13725 struct linespec_result canonical
;
13727 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13728 NULL
, 0, &canonical
, multiple_symbols_all
,
13731 /* We should get 0 or 1 resulting SALs. */
13732 gdb_assert (canonical
.lsals
.size () < 2);
13734 if (!canonical
.lsals
.empty ())
13736 const linespec_sals
&lsal
= canonical
.lsals
[0];
13737 return std::move (lsal
.sals
);
13742 /* Reset a breakpoint. */
13745 breakpoint_re_set_one (breakpoint
*b
)
13747 input_radix
= b
->input_radix
;
13748 set_language (b
->language
);
13750 b
->ops
->re_set (b
);
13753 /* Re-set breakpoint locations for the current program space.
13754 Locations bound to other program spaces are left untouched. */
13757 breakpoint_re_set (void)
13759 struct breakpoint
*b
, *b_tmp
;
13762 scoped_restore_current_language save_language
;
13763 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
13764 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
13766 /* breakpoint_re_set_one sets the current_language to the language
13767 of the breakpoint it is resetting (see prepare_re_set_context)
13768 before re-evaluating the breakpoint's location. This change can
13769 unfortunately get undone by accident if the language_mode is set
13770 to auto, and we either switch frames, or more likely in this context,
13771 we select the current frame.
13773 We prevent this by temporarily turning the language_mode to
13774 language_mode_manual. We restore it once all breakpoints
13775 have been reset. */
13776 scoped_restore save_language_mode
= make_scoped_restore (&language_mode
);
13777 language_mode
= language_mode_manual
;
13779 /* Note: we must not try to insert locations until after all
13780 breakpoints have been re-set. Otherwise, e.g., when re-setting
13781 breakpoint 1, we'd insert the locations of breakpoint 2, which
13782 hadn't been re-set yet, and thus may have stale locations. */
13784 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13788 breakpoint_re_set_one (b
);
13790 catch (const gdb_exception
&ex
)
13792 exception_fprintf (gdb_stderr
, ex
,
13793 "Error in re-setting breakpoint %d: ",
13798 jit_breakpoint_re_set ();
13801 create_overlay_event_breakpoint ();
13802 create_longjmp_master_breakpoint ();
13803 create_std_terminate_master_breakpoint ();
13804 create_exception_master_breakpoint ();
13806 /* Now we can insert. */
13807 update_global_location_list (UGLL_MAY_INSERT
);
13810 /* Reset the thread number of this breakpoint:
13812 - If the breakpoint is for all threads, leave it as-is.
13813 - Else, reset it to the current thread for inferior_ptid. */
13815 breakpoint_re_set_thread (struct breakpoint
*b
)
13817 if (b
->thread
!= -1)
13819 b
->thread
= inferior_thread ()->global_num
;
13821 /* We're being called after following a fork. The new fork is
13822 selected as current, and unless this was a vfork will have a
13823 different program space from the original thread. Reset that
13825 b
->loc
->pspace
= current_program_space
;
13829 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
13830 If from_tty is nonzero, it prints a message to that effect,
13831 which ends with a period (no newline). */
13834 set_ignore_count (int bptnum
, int count
, int from_tty
)
13836 struct breakpoint
*b
;
13841 ALL_BREAKPOINTS (b
)
13842 if (b
->number
== bptnum
)
13844 if (is_tracepoint (b
))
13846 if (from_tty
&& count
!= 0)
13847 printf_filtered (_("Ignore count ignored for tracepoint %d."),
13852 b
->ignore_count
= count
;
13856 printf_filtered (_("Will stop next time "
13857 "breakpoint %d is reached."),
13859 else if (count
== 1)
13860 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
13863 printf_filtered (_("Will ignore next %d "
13864 "crossings of breakpoint %d."),
13867 gdb::observers::breakpoint_modified
.notify (b
);
13871 error (_("No breakpoint number %d."), bptnum
);
13874 /* Command to set ignore-count of breakpoint N to COUNT. */
13877 ignore_command (const char *args
, int from_tty
)
13879 const char *p
= args
;
13883 error_no_arg (_("a breakpoint number"));
13885 num
= get_number (&p
);
13887 error (_("bad breakpoint number: '%s'"), args
);
13889 error (_("Second argument (specified ignore-count) is missing."));
13891 set_ignore_count (num
,
13892 longest_to_int (value_as_long (parse_and_eval (p
))),
13895 printf_filtered ("\n");
13899 /* Call FUNCTION on each of the breakpoints with numbers in the range
13900 defined by BP_NUM_RANGE (an inclusive range). */
13903 map_breakpoint_number_range (std::pair
<int, int> bp_num_range
,
13904 gdb::function_view
<void (breakpoint
*)> function
)
13906 if (bp_num_range
.first
== 0)
13908 warning (_("bad breakpoint number at or near '%d'"),
13909 bp_num_range
.first
);
13913 struct breakpoint
*b
, *tmp
;
13915 for (int i
= bp_num_range
.first
; i
<= bp_num_range
.second
; i
++)
13917 bool match
= false;
13919 ALL_BREAKPOINTS_SAFE (b
, tmp
)
13920 if (b
->number
== i
)
13927 printf_unfiltered (_("No breakpoint number %d.\n"), i
);
13932 /* Call FUNCTION on each of the breakpoints whose numbers are given in
13936 map_breakpoint_numbers (const char *args
,
13937 gdb::function_view
<void (breakpoint
*)> function
)
13939 if (args
== NULL
|| *args
== '\0')
13940 error_no_arg (_("one or more breakpoint numbers"));
13942 number_or_range_parser
parser (args
);
13944 while (!parser
.finished ())
13946 int num
= parser
.get_number ();
13947 map_breakpoint_number_range (std::make_pair (num
, num
), function
);
13951 /* Return the breakpoint location structure corresponding to the
13952 BP_NUM and LOC_NUM values. */
13954 static struct bp_location
*
13955 find_location_by_number (int bp_num
, int loc_num
)
13957 struct breakpoint
*b
;
13959 ALL_BREAKPOINTS (b
)
13960 if (b
->number
== bp_num
)
13965 if (!b
|| b
->number
!= bp_num
)
13966 error (_("Bad breakpoint number '%d'"), bp_num
);
13969 error (_("Bad breakpoint location number '%d'"), loc_num
);
13972 for (bp_location
*loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13973 if (++n
== loc_num
)
13976 error (_("Bad breakpoint location number '%d'"), loc_num
);
13979 /* Modes of operation for extract_bp_num. */
13980 enum class extract_bp_kind
13982 /* Extracting a breakpoint number. */
13985 /* Extracting a location number. */
13989 /* Extract a breakpoint or location number (as determined by KIND)
13990 from the string starting at START. TRAILER is a character which
13991 can be found after the number. If you don't want a trailer, use
13992 '\0'. If END_OUT is not NULL, it is set to point after the parsed
13993 string. This always returns a positive integer. */
13996 extract_bp_num (extract_bp_kind kind
, const char *start
,
13997 int trailer
, const char **end_out
= NULL
)
13999 const char *end
= start
;
14000 int num
= get_number_trailer (&end
, trailer
);
14002 error (kind
== extract_bp_kind::bp
14003 ? _("Negative breakpoint number '%.*s'")
14004 : _("Negative breakpoint location number '%.*s'"),
14005 int (end
- start
), start
);
14007 error (kind
== extract_bp_kind::bp
14008 ? _("Bad breakpoint number '%.*s'")
14009 : _("Bad breakpoint location number '%.*s'"),
14010 int (end
- start
), start
);
14012 if (end_out
!= NULL
)
14017 /* Extract a breakpoint or location range (as determined by KIND) in
14018 the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair
14019 representing the (inclusive) range. The returned pair's elements
14020 are always positive integers. */
14022 static std::pair
<int, int>
14023 extract_bp_or_bp_range (extract_bp_kind kind
,
14024 const std::string
&arg
,
14025 std::string::size_type arg_offset
)
14027 std::pair
<int, int> range
;
14028 const char *bp_loc
= &arg
[arg_offset
];
14029 std::string::size_type dash
= arg
.find ('-', arg_offset
);
14030 if (dash
!= std::string::npos
)
14032 /* bp_loc is a range (x-z). */
14033 if (arg
.length () == dash
+ 1)
14034 error (kind
== extract_bp_kind::bp
14035 ? _("Bad breakpoint number at or near: '%s'")
14036 : _("Bad breakpoint location number at or near: '%s'"),
14040 const char *start_first
= bp_loc
;
14041 const char *start_second
= &arg
[dash
+ 1];
14042 range
.first
= extract_bp_num (kind
, start_first
, '-');
14043 range
.second
= extract_bp_num (kind
, start_second
, '\0', &end
);
14045 if (range
.first
> range
.second
)
14046 error (kind
== extract_bp_kind::bp
14047 ? _("Inverted breakpoint range at '%.*s'")
14048 : _("Inverted breakpoint location range at '%.*s'"),
14049 int (end
- start_first
), start_first
);
14053 /* bp_loc is a single value. */
14054 range
.first
= extract_bp_num (kind
, bp_loc
, '\0');
14055 range
.second
= range
.first
;
14060 /* Extract the breakpoint/location range specified by ARG. Returns
14061 the breakpoint range in BP_NUM_RANGE, and the location range in
14064 ARG may be in any of the following forms:
14066 x where 'x' is a breakpoint number.
14067 x-y where 'x' and 'y' specify a breakpoint numbers range.
14068 x.y where 'x' is a breakpoint number and 'y' a location number.
14069 x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a
14070 location number range.
14074 extract_bp_number_and_location (const std::string
&arg
,
14075 std::pair
<int, int> &bp_num_range
,
14076 std::pair
<int, int> &bp_loc_range
)
14078 std::string::size_type dot
= arg
.find ('.');
14080 if (dot
!= std::string::npos
)
14082 /* Handle 'x.y' and 'x.y-z' cases. */
14084 if (arg
.length () == dot
+ 1 || dot
== 0)
14085 error (_("Bad breakpoint number at or near: '%s'"), arg
.c_str ());
14088 = extract_bp_num (extract_bp_kind::bp
, arg
.c_str (), '.');
14089 bp_num_range
.second
= bp_num_range
.first
;
14091 bp_loc_range
= extract_bp_or_bp_range (extract_bp_kind::loc
,
14096 /* Handle x and x-y cases. */
14098 bp_num_range
= extract_bp_or_bp_range (extract_bp_kind::bp
, arg
, 0);
14099 bp_loc_range
.first
= 0;
14100 bp_loc_range
.second
= 0;
14104 /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE
14105 specifies whether to enable or disable. */
14108 enable_disable_bp_num_loc (int bp_num
, int loc_num
, bool enable
)
14110 struct bp_location
*loc
= find_location_by_number (bp_num
, loc_num
);
14113 if (loc
->enabled
!= enable
)
14115 loc
->enabled
= enable
;
14116 mark_breakpoint_location_modified (loc
);
14118 if (target_supports_enable_disable_tracepoint ()
14119 && current_trace_status ()->running
&& loc
->owner
14120 && is_tracepoint (loc
->owner
))
14121 target_disable_tracepoint (loc
);
14123 update_global_location_list (UGLL_DONT_INSERT
);
14125 gdb::observers::breakpoint_modified
.notify (loc
->owner
);
14128 /* Enable or disable a range of breakpoint locations. BP_NUM is the
14129 number of the breakpoint, and BP_LOC_RANGE specifies the
14130 (inclusive) range of location numbers of that breakpoint to
14131 enable/disable. ENABLE specifies whether to enable or disable the
14135 enable_disable_breakpoint_location_range (int bp_num
,
14136 std::pair
<int, int> &bp_loc_range
,
14139 for (int i
= bp_loc_range
.first
; i
<= bp_loc_range
.second
; i
++)
14140 enable_disable_bp_num_loc (bp_num
, i
, enable
);
14143 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14144 If from_tty is nonzero, it prints a message to that effect,
14145 which ends with a period (no newline). */
14148 disable_breakpoint (struct breakpoint
*bpt
)
14150 /* Never disable a watchpoint scope breakpoint; we want to
14151 hit them when we leave scope so we can delete both the
14152 watchpoint and its scope breakpoint at that time. */
14153 if (bpt
->type
== bp_watchpoint_scope
)
14156 bpt
->enable_state
= bp_disabled
;
14158 /* Mark breakpoint locations modified. */
14159 mark_breakpoint_modified (bpt
);
14161 if (target_supports_enable_disable_tracepoint ()
14162 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14164 struct bp_location
*location
;
14166 for (location
= bpt
->loc
; location
; location
= location
->next
)
14167 target_disable_tracepoint (location
);
14170 update_global_location_list (UGLL_DONT_INSERT
);
14172 gdb::observers::breakpoint_modified
.notify (bpt
);
14175 /* Enable or disable the breakpoint(s) or breakpoint location(s)
14176 specified in ARGS. ARGS may be in any of the formats handled by
14177 extract_bp_number_and_location. ENABLE specifies whether to enable
14178 or disable the breakpoints/locations. */
14181 enable_disable_command (const char *args
, int from_tty
, bool enable
)
14185 struct breakpoint
*bpt
;
14187 ALL_BREAKPOINTS (bpt
)
14188 if (user_breakpoint_p (bpt
))
14191 enable_breakpoint (bpt
);
14193 disable_breakpoint (bpt
);
14198 std::string num
= extract_arg (&args
);
14200 while (!num
.empty ())
14202 std::pair
<int, int> bp_num_range
, bp_loc_range
;
14204 extract_bp_number_and_location (num
, bp_num_range
, bp_loc_range
);
14206 if (bp_loc_range
.first
== bp_loc_range
.second
14207 && bp_loc_range
.first
== 0)
14209 /* Handle breakpoint ids with formats 'x' or 'x-z'. */
14210 map_breakpoint_number_range (bp_num_range
,
14212 ? enable_breakpoint
14213 : disable_breakpoint
);
14217 /* Handle breakpoint ids with formats 'x.y' or
14219 enable_disable_breakpoint_location_range
14220 (bp_num_range
.first
, bp_loc_range
, enable
);
14222 num
= extract_arg (&args
);
14227 /* The disable command disables the specified breakpoints/locations
14228 (or all defined breakpoints) so they're no longer effective in
14229 stopping the inferior. ARGS may be in any of the forms defined in
14230 extract_bp_number_and_location. */
14233 disable_command (const char *args
, int from_tty
)
14235 enable_disable_command (args
, from_tty
, false);
14239 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14242 int target_resources_ok
;
14244 if (bpt
->type
== bp_hardware_breakpoint
)
14247 i
= hw_breakpoint_used_count ();
14248 target_resources_ok
=
14249 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14251 if (target_resources_ok
== 0)
14252 error (_("No hardware breakpoint support in the target."));
14253 else if (target_resources_ok
< 0)
14254 error (_("Hardware breakpoints used exceeds limit."));
14257 if (is_watchpoint (bpt
))
14259 /* Initialize it just to avoid a GCC false warning. */
14260 enum enable_state orig_enable_state
= bp_disabled
;
14264 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14266 orig_enable_state
= bpt
->enable_state
;
14267 bpt
->enable_state
= bp_enabled
;
14268 update_watchpoint (w
, 1 /* reparse */);
14270 catch (const gdb_exception
&e
)
14272 bpt
->enable_state
= orig_enable_state
;
14273 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14279 bpt
->enable_state
= bp_enabled
;
14281 /* Mark breakpoint locations modified. */
14282 mark_breakpoint_modified (bpt
);
14284 if (target_supports_enable_disable_tracepoint ()
14285 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14287 struct bp_location
*location
;
14289 for (location
= bpt
->loc
; location
; location
= location
->next
)
14290 target_enable_tracepoint (location
);
14293 bpt
->disposition
= disposition
;
14294 bpt
->enable_count
= count
;
14295 update_global_location_list (UGLL_MAY_INSERT
);
14297 gdb::observers::breakpoint_modified
.notify (bpt
);
14302 enable_breakpoint (struct breakpoint
*bpt
)
14304 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14307 /* The enable command enables the specified breakpoints/locations (or
14308 all defined breakpoints) so they once again become (or continue to
14309 be) effective in stopping the inferior. ARGS may be in any of the
14310 forms defined in extract_bp_number_and_location. */
14313 enable_command (const char *args
, int from_tty
)
14315 enable_disable_command (args
, from_tty
, true);
14319 enable_once_command (const char *args
, int from_tty
)
14321 map_breakpoint_numbers
14322 (args
, [&] (breakpoint
*b
)
14324 iterate_over_related_breakpoints
14325 (b
, [&] (breakpoint
*bpt
)
14327 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14333 enable_count_command (const char *args
, int from_tty
)
14338 error_no_arg (_("hit count"));
14340 count
= get_number (&args
);
14342 map_breakpoint_numbers
14343 (args
, [&] (breakpoint
*b
)
14345 iterate_over_related_breakpoints
14346 (b
, [&] (breakpoint
*bpt
)
14348 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14354 enable_delete_command (const char *args
, int from_tty
)
14356 map_breakpoint_numbers
14357 (args
, [&] (breakpoint
*b
)
14359 iterate_over_related_breakpoints
14360 (b
, [&] (breakpoint
*bpt
)
14362 enable_breakpoint_disp (bpt
, disp_del
, 1);
14368 set_breakpoint_cmd (const char *args
, int from_tty
)
14373 show_breakpoint_cmd (const char *args
, int from_tty
)
14377 /* Invalidate last known value of any hardware watchpoint if
14378 the memory which that value represents has been written to by
14382 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14383 CORE_ADDR addr
, ssize_t len
,
14384 const bfd_byte
*data
)
14386 struct breakpoint
*bp
;
14388 ALL_BREAKPOINTS (bp
)
14389 if (bp
->enable_state
== bp_enabled
14390 && bp
->type
== bp_hardware_watchpoint
)
14392 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14394 if (wp
->val_valid
&& wp
->val
!= nullptr)
14396 struct bp_location
*loc
;
14398 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14399 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14400 && loc
->address
+ loc
->length
> addr
14401 && addr
+ len
> loc
->address
)
14410 /* Create and insert a breakpoint for software single step. */
14413 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14414 const address_space
*aspace
,
14417 struct thread_info
*tp
= inferior_thread ();
14418 struct symtab_and_line sal
;
14419 CORE_ADDR pc
= next_pc
;
14421 if (tp
->control
.single_step_breakpoints
== NULL
)
14423 tp
->control
.single_step_breakpoints
14424 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14427 sal
= find_pc_line (pc
, 0);
14429 sal
.section
= find_pc_overlay (pc
);
14430 sal
.explicit_pc
= 1;
14431 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14433 update_global_location_list (UGLL_INSERT
);
14436 /* Insert single step breakpoints according to the current state. */
14439 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14441 struct regcache
*regcache
= get_current_regcache ();
14442 std::vector
<CORE_ADDR
> next_pcs
;
14444 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14446 if (!next_pcs
.empty ())
14448 struct frame_info
*frame
= get_current_frame ();
14449 const address_space
*aspace
= get_frame_address_space (frame
);
14451 for (CORE_ADDR pc
: next_pcs
)
14452 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14460 /* See breakpoint.h. */
14463 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14464 const address_space
*aspace
,
14467 struct bp_location
*loc
;
14469 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14471 && breakpoint_location_address_match (loc
, aspace
, pc
))
14477 /* Check whether a software single-step breakpoint is inserted at
14481 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14484 struct breakpoint
*bpt
;
14486 ALL_BREAKPOINTS (bpt
)
14488 if (bpt
->type
== bp_single_step
14489 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14495 /* Tracepoint-specific operations. */
14497 /* Set tracepoint count to NUM. */
14499 set_tracepoint_count (int num
)
14501 tracepoint_count
= num
;
14502 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14506 trace_command (const char *arg
, int from_tty
)
14508 struct breakpoint_ops
*ops
;
14510 event_location_up location
= string_to_event_location (&arg
,
14512 if (location
!= NULL
14513 && event_location_type (location
.get ()) == PROBE_LOCATION
)
14514 ops
= &tracepoint_probe_breakpoint_ops
;
14516 ops
= &tracepoint_breakpoint_ops
;
14518 create_breakpoint (get_current_arch (),
14520 NULL
, 0, arg
, 1 /* parse arg */,
14522 bp_tracepoint
/* type_wanted */,
14523 0 /* Ignore count */,
14524 pending_break_support
,
14528 0 /* internal */, 0);
14532 ftrace_command (const char *arg
, int from_tty
)
14534 event_location_up location
= string_to_event_location (&arg
,
14536 create_breakpoint (get_current_arch (),
14538 NULL
, 0, arg
, 1 /* parse arg */,
14540 bp_fast_tracepoint
/* type_wanted */,
14541 0 /* Ignore count */,
14542 pending_break_support
,
14543 &tracepoint_breakpoint_ops
,
14546 0 /* internal */, 0);
14549 /* strace command implementation. Creates a static tracepoint. */
14552 strace_command (const char *arg
, int from_tty
)
14554 struct breakpoint_ops
*ops
;
14555 event_location_up location
;
14557 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14558 or with a normal static tracepoint. */
14559 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14561 ops
= &strace_marker_breakpoint_ops
;
14562 location
= new_linespec_location (&arg
, symbol_name_match_type::FULL
);
14566 ops
= &tracepoint_breakpoint_ops
;
14567 location
= string_to_event_location (&arg
, current_language
);
14570 create_breakpoint (get_current_arch (),
14572 NULL
, 0, arg
, 1 /* parse arg */,
14574 bp_static_tracepoint
/* type_wanted */,
14575 0 /* Ignore count */,
14576 pending_break_support
,
14580 0 /* internal */, 0);
14583 /* Set up a fake reader function that gets command lines from a linked
14584 list that was acquired during tracepoint uploading. */
14586 static struct uploaded_tp
*this_utp
;
14587 static int next_cmd
;
14590 read_uploaded_action (void)
14592 char *rslt
= nullptr;
14594 if (next_cmd
< this_utp
->cmd_strings
.size ())
14596 rslt
= this_utp
->cmd_strings
[next_cmd
].get ();
14603 /* Given information about a tracepoint as recorded on a target (which
14604 can be either a live system or a trace file), attempt to create an
14605 equivalent GDB tracepoint. This is not a reliable process, since
14606 the target does not necessarily have all the information used when
14607 the tracepoint was originally defined. */
14609 struct tracepoint
*
14610 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14612 const char *addr_str
;
14613 char small_buf
[100];
14614 struct tracepoint
*tp
;
14616 if (utp
->at_string
)
14617 addr_str
= utp
->at_string
.get ();
14620 /* In the absence of a source location, fall back to raw
14621 address. Since there is no way to confirm that the address
14622 means the same thing as when the trace was started, warn the
14624 warning (_("Uploaded tracepoint %d has no "
14625 "source location, using raw address"),
14627 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14628 addr_str
= small_buf
;
14631 /* There's not much we can do with a sequence of bytecodes. */
14632 if (utp
->cond
&& !utp
->cond_string
)
14633 warning (_("Uploaded tracepoint %d condition "
14634 "has no source form, ignoring it"),
14637 event_location_up location
= string_to_event_location (&addr_str
,
14639 if (!create_breakpoint (get_current_arch (),
14641 utp
->cond_string
.get (), -1, addr_str
,
14642 0 /* parse cond/thread */,
14644 utp
->type
/* type_wanted */,
14645 0 /* Ignore count */,
14646 pending_break_support
,
14647 &tracepoint_breakpoint_ops
,
14649 utp
->enabled
/* enabled */,
14651 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14654 /* Get the tracepoint we just created. */
14655 tp
= get_tracepoint (tracepoint_count
);
14656 gdb_assert (tp
!= NULL
);
14660 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14663 trace_pass_command (small_buf
, 0);
14666 /* If we have uploaded versions of the original commands, set up a
14667 special-purpose "reader" function and call the usual command line
14668 reader, then pass the result to the breakpoint command-setting
14670 if (!utp
->cmd_strings
.empty ())
14672 counted_command_line cmd_list
;
14677 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
);
14679 breakpoint_set_commands (tp
, std::move (cmd_list
));
14681 else if (!utp
->actions
.empty ()
14682 || !utp
->step_actions
.empty ())
14683 warning (_("Uploaded tracepoint %d actions "
14684 "have no source form, ignoring them"),
14687 /* Copy any status information that might be available. */
14688 tp
->hit_count
= utp
->hit_count
;
14689 tp
->traceframe_usage
= utp
->traceframe_usage
;
14694 /* Print information on tracepoint number TPNUM_EXP, or all if
14698 info_tracepoints_command (const char *args
, int from_tty
)
14700 struct ui_out
*uiout
= current_uiout
;
14703 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14705 if (num_printed
== 0)
14707 if (args
== NULL
|| *args
== '\0')
14708 uiout
->message ("No tracepoints.\n");
14710 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14713 default_collect_info ();
14716 /* The 'enable trace' command enables tracepoints.
14717 Not supported by all targets. */
14719 enable_trace_command (const char *args
, int from_tty
)
14721 enable_command (args
, from_tty
);
14724 /* The 'disable trace' command disables tracepoints.
14725 Not supported by all targets. */
14727 disable_trace_command (const char *args
, int from_tty
)
14729 disable_command (args
, from_tty
);
14732 /* Remove a tracepoint (or all if no argument). */
14734 delete_trace_command (const char *arg
, int from_tty
)
14736 struct breakpoint
*b
, *b_tmp
;
14742 int breaks_to_delete
= 0;
14744 /* Delete all breakpoints if no argument.
14745 Do not delete internal or call-dummy breakpoints, these
14746 have to be deleted with an explicit breakpoint number
14748 ALL_TRACEPOINTS (b
)
14749 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14751 breaks_to_delete
= 1;
14755 /* Ask user only if there are some breakpoints to delete. */
14757 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14759 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14760 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14761 delete_breakpoint (b
);
14765 map_breakpoint_numbers
14766 (arg
, [&] (breakpoint
*br
)
14768 iterate_over_related_breakpoints (br
, delete_breakpoint
);
14772 /* Helper function for trace_pass_command. */
14775 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14777 tp
->pass_count
= count
;
14778 gdb::observers::breakpoint_modified
.notify (tp
);
14780 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14781 tp
->number
, count
);
14784 /* Set passcount for tracepoint.
14786 First command argument is passcount, second is tracepoint number.
14787 If tracepoint number omitted, apply to most recently defined.
14788 Also accepts special argument "all". */
14791 trace_pass_command (const char *args
, int from_tty
)
14793 struct tracepoint
*t1
;
14796 if (args
== 0 || *args
== 0)
14797 error (_("passcount command requires an "
14798 "argument (count + optional TP num)"));
14800 count
= strtoulst (args
, &args
, 10); /* Count comes first, then TP num. */
14802 args
= skip_spaces (args
);
14803 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14805 struct breakpoint
*b
;
14807 args
+= 3; /* Skip special argument "all". */
14809 error (_("Junk at end of arguments."));
14811 ALL_TRACEPOINTS (b
)
14813 t1
= (struct tracepoint
*) b
;
14814 trace_pass_set_count (t1
, count
, from_tty
);
14817 else if (*args
== '\0')
14819 t1
= get_tracepoint_by_number (&args
, NULL
);
14821 trace_pass_set_count (t1
, count
, from_tty
);
14825 number_or_range_parser
parser (args
);
14826 while (!parser
.finished ())
14828 t1
= get_tracepoint_by_number (&args
, &parser
);
14830 trace_pass_set_count (t1
, count
, from_tty
);
14835 struct tracepoint
*
14836 get_tracepoint (int num
)
14838 struct breakpoint
*t
;
14840 ALL_TRACEPOINTS (t
)
14841 if (t
->number
== num
)
14842 return (struct tracepoint
*) t
;
14847 /* Find the tracepoint with the given target-side number (which may be
14848 different from the tracepoint number after disconnecting and
14851 struct tracepoint
*
14852 get_tracepoint_by_number_on_target (int num
)
14854 struct breakpoint
*b
;
14856 ALL_TRACEPOINTS (b
)
14858 struct tracepoint
*t
= (struct tracepoint
*) b
;
14860 if (t
->number_on_target
== num
)
14867 /* Utility: parse a tracepoint number and look it up in the list.
14868 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14869 If the argument is missing, the most recent tracepoint
14870 (tracepoint_count) is returned. */
14872 struct tracepoint
*
14873 get_tracepoint_by_number (const char **arg
,
14874 number_or_range_parser
*parser
)
14876 struct breakpoint
*t
;
14878 const char *instring
= arg
== NULL
? NULL
: *arg
;
14880 if (parser
!= NULL
)
14882 gdb_assert (!parser
->finished ());
14883 tpnum
= parser
->get_number ();
14885 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14886 tpnum
= tracepoint_count
;
14888 tpnum
= get_number (arg
);
14892 if (instring
&& *instring
)
14893 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14896 printf_filtered (_("No previous tracepoint\n"));
14900 ALL_TRACEPOINTS (t
)
14901 if (t
->number
== tpnum
)
14903 return (struct tracepoint
*) t
;
14906 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
14911 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
14913 if (b
->thread
!= -1)
14914 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
14917 fprintf_unfiltered (fp
, " task %d", b
->task
);
14919 fprintf_unfiltered (fp
, "\n");
14922 /* Save information on user settable breakpoints (watchpoints, etc) to
14923 a new script file named FILENAME. If FILTER is non-NULL, call it
14924 on each breakpoint and only include the ones for which it returns
14928 save_breakpoints (const char *filename
, int from_tty
,
14929 int (*filter
) (const struct breakpoint
*))
14931 struct breakpoint
*tp
;
14933 int extra_trace_bits
= 0;
14935 if (filename
== 0 || *filename
== 0)
14936 error (_("Argument required (file name in which to save)"));
14938 /* See if we have anything to save. */
14939 ALL_BREAKPOINTS (tp
)
14941 /* Skip internal and momentary breakpoints. */
14942 if (!user_breakpoint_p (tp
))
14945 /* If we have a filter, only save the breakpoints it accepts. */
14946 if (filter
&& !filter (tp
))
14951 if (is_tracepoint (tp
))
14953 extra_trace_bits
= 1;
14955 /* We can stop searching. */
14962 warning (_("Nothing to save."));
14966 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
14970 if (!fp
.open (expanded_filename
.get (), "w"))
14971 error (_("Unable to open file '%s' for saving (%s)"),
14972 expanded_filename
.get (), safe_strerror (errno
));
14974 if (extra_trace_bits
)
14975 save_trace_state_variables (&fp
);
14977 ALL_BREAKPOINTS (tp
)
14979 /* Skip internal and momentary breakpoints. */
14980 if (!user_breakpoint_p (tp
))
14983 /* If we have a filter, only save the breakpoints it accepts. */
14984 if (filter
&& !filter (tp
))
14987 tp
->ops
->print_recreate (tp
, &fp
);
14989 /* Note, we can't rely on tp->number for anything, as we can't
14990 assume the recreated breakpoint numbers will match. Use $bpnum
14993 if (tp
->cond_string
)
14994 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
14996 if (tp
->ignore_count
)
14997 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
14999 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15001 fp
.puts (" commands\n");
15003 current_uiout
->redirect (&fp
);
15006 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15008 catch (const gdb_exception
&ex
)
15010 current_uiout
->redirect (NULL
);
15014 current_uiout
->redirect (NULL
);
15015 fp
.puts (" end\n");
15018 if (tp
->enable_state
== bp_disabled
)
15019 fp
.puts ("disable $bpnum\n");
15021 /* If this is a multi-location breakpoint, check if the locations
15022 should be individually disabled. Watchpoint locations are
15023 special, and not user visible. */
15024 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15026 struct bp_location
*loc
;
15029 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15031 fp
.printf ("disable $bpnum.%d\n", n
);
15035 if (extra_trace_bits
&& *default_collect
)
15036 fp
.printf ("set default-collect %s\n", default_collect
);
15039 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15042 /* The `save breakpoints' command. */
15045 save_breakpoints_command (const char *args
, int from_tty
)
15047 save_breakpoints (args
, from_tty
, NULL
);
15050 /* The `save tracepoints' command. */
15053 save_tracepoints_command (const char *args
, int from_tty
)
15055 save_breakpoints (args
, from_tty
, is_tracepoint
);
15058 /* Create a vector of all tracepoints. */
15060 std::vector
<breakpoint
*>
15061 all_tracepoints (void)
15063 std::vector
<breakpoint
*> tp_vec
;
15064 struct breakpoint
*tp
;
15066 ALL_TRACEPOINTS (tp
)
15068 tp_vec
.push_back (tp
);
15075 /* This help string is used to consolidate all the help string for specifying
15076 locations used by several commands. */
15078 #define LOCATION_HELP_STRING \
15079 "Linespecs are colon-separated lists of location parameters, such as\n\
15080 source filename, function name, label name, and line number.\n\
15081 Example: To specify the start of a label named \"the_top\" in the\n\
15082 function \"fact\" in the file \"factorial.c\", use\n\
15083 \"factorial.c:fact:the_top\".\n\
15085 Address locations begin with \"*\" and specify an exact address in the\n\
15086 program. Example: To specify the fourth byte past the start function\n\
15087 \"main\", use \"*main + 4\".\n\
15089 Explicit locations are similar to linespecs but use an option/argument\n\
15090 syntax to specify location parameters.\n\
15091 Example: To specify the start of the label named \"the_top\" in the\n\
15092 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15093 -function fact -label the_top\".\n\
15095 By default, a specified function is matched against the program's\n\
15096 functions in all scopes. For C++, this means in all namespaces and\n\
15097 classes. For Ada, this means in all packages. E.g., in C++,\n\
15098 \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\
15099 \"-qualified\" flag overrides this behavior, making GDB interpret the\n\
15100 specified name as a complete fully-qualified name instead."
15102 /* This help string is used for the break, hbreak, tbreak and thbreak
15103 commands. It is defined as a macro to prevent duplication.
15104 COMMAND should be a string constant containing the name of the
15107 #define BREAK_ARGS_HELP(command) \
15108 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15109 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15110 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15111 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15112 `-probe-dtrace' (for a DTrace probe).\n\
15113 LOCATION may be a linespec, address, or explicit location as described\n\
15116 With no LOCATION, uses current execution address of the selected\n\
15117 stack frame. This is useful for breaking on return to a stack frame.\n\
15119 THREADNUM is the number from \"info threads\".\n\
15120 CONDITION is a boolean expression.\n\
15121 \n" LOCATION_HELP_STRING "\n\n\
15122 Multiple breakpoints at one place are permitted, and useful if their\n\
15123 conditions are different.\n\
15125 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15127 /* List of subcommands for "catch". */
15128 static struct cmd_list_element
*catch_cmdlist
;
15130 /* List of subcommands for "tcatch". */
15131 static struct cmd_list_element
*tcatch_cmdlist
;
15134 add_catch_command (const char *name
, const char *docstring
,
15135 cmd_const_sfunc_ftype
*sfunc
,
15136 completer_ftype
*completer
,
15137 void *user_data_catch
,
15138 void *user_data_tcatch
)
15140 struct cmd_list_element
*command
;
15142 command
= add_cmd (name
, class_breakpoint
, docstring
,
15144 set_cmd_sfunc (command
, sfunc
);
15145 set_cmd_context (command
, user_data_catch
);
15146 set_cmd_completer (command
, completer
);
15148 command
= add_cmd (name
, class_breakpoint
, docstring
,
15150 set_cmd_sfunc (command
, sfunc
);
15151 set_cmd_context (command
, user_data_tcatch
);
15152 set_cmd_completer (command
, completer
);
15156 save_command (const char *arg
, int from_tty
)
15158 printf_unfiltered (_("\"save\" must be followed by "
15159 "the name of a save subcommand.\n"));
15160 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15163 struct breakpoint
*
15164 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15167 struct breakpoint
*b
, *b_tmp
;
15169 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15171 if ((*callback
) (b
, data
))
15178 /* Zero if any of the breakpoint's locations could be a location where
15179 functions have been inlined, nonzero otherwise. */
15182 is_non_inline_function (struct breakpoint
*b
)
15184 /* The shared library event breakpoint is set on the address of a
15185 non-inline function. */
15186 if (b
->type
== bp_shlib_event
)
15192 /* Nonzero if the specified PC cannot be a location where functions
15193 have been inlined. */
15196 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15197 const struct target_waitstatus
*ws
)
15199 struct breakpoint
*b
;
15200 struct bp_location
*bl
;
15202 ALL_BREAKPOINTS (b
)
15204 if (!is_non_inline_function (b
))
15207 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15209 if (!bl
->shlib_disabled
15210 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15218 /* Remove any references to OBJFILE which is going to be freed. */
15221 breakpoint_free_objfile (struct objfile
*objfile
)
15223 struct bp_location
**locp
, *loc
;
15225 ALL_BP_LOCATIONS (loc
, locp
)
15226 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15227 loc
->symtab
= NULL
;
15231 initialize_breakpoint_ops (void)
15233 static int initialized
= 0;
15235 struct breakpoint_ops
*ops
;
15241 /* The breakpoint_ops structure to be inherit by all kinds of
15242 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15243 internal and momentary breakpoints, etc.). */
15244 ops
= &bkpt_base_breakpoint_ops
;
15245 *ops
= base_breakpoint_ops
;
15246 ops
->re_set
= bkpt_re_set
;
15247 ops
->insert_location
= bkpt_insert_location
;
15248 ops
->remove_location
= bkpt_remove_location
;
15249 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15250 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15251 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15252 ops
->decode_location
= bkpt_decode_location
;
15254 /* The breakpoint_ops structure to be used in regular breakpoints. */
15255 ops
= &bkpt_breakpoint_ops
;
15256 *ops
= bkpt_base_breakpoint_ops
;
15257 ops
->re_set
= bkpt_re_set
;
15258 ops
->resources_needed
= bkpt_resources_needed
;
15259 ops
->print_it
= bkpt_print_it
;
15260 ops
->print_mention
= bkpt_print_mention
;
15261 ops
->print_recreate
= bkpt_print_recreate
;
15263 /* Ranged breakpoints. */
15264 ops
= &ranged_breakpoint_ops
;
15265 *ops
= bkpt_breakpoint_ops
;
15266 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15267 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15268 ops
->print_it
= print_it_ranged_breakpoint
;
15269 ops
->print_one
= print_one_ranged_breakpoint
;
15270 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15271 ops
->print_mention
= print_mention_ranged_breakpoint
;
15272 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15274 /* Internal breakpoints. */
15275 ops
= &internal_breakpoint_ops
;
15276 *ops
= bkpt_base_breakpoint_ops
;
15277 ops
->re_set
= internal_bkpt_re_set
;
15278 ops
->check_status
= internal_bkpt_check_status
;
15279 ops
->print_it
= internal_bkpt_print_it
;
15280 ops
->print_mention
= internal_bkpt_print_mention
;
15282 /* Momentary breakpoints. */
15283 ops
= &momentary_breakpoint_ops
;
15284 *ops
= bkpt_base_breakpoint_ops
;
15285 ops
->re_set
= momentary_bkpt_re_set
;
15286 ops
->check_status
= momentary_bkpt_check_status
;
15287 ops
->print_it
= momentary_bkpt_print_it
;
15288 ops
->print_mention
= momentary_bkpt_print_mention
;
15290 /* Probe breakpoints. */
15291 ops
= &bkpt_probe_breakpoint_ops
;
15292 *ops
= bkpt_breakpoint_ops
;
15293 ops
->insert_location
= bkpt_probe_insert_location
;
15294 ops
->remove_location
= bkpt_probe_remove_location
;
15295 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15296 ops
->decode_location
= bkpt_probe_decode_location
;
15299 ops
= &watchpoint_breakpoint_ops
;
15300 *ops
= base_breakpoint_ops
;
15301 ops
->re_set
= re_set_watchpoint
;
15302 ops
->insert_location
= insert_watchpoint
;
15303 ops
->remove_location
= remove_watchpoint
;
15304 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15305 ops
->check_status
= check_status_watchpoint
;
15306 ops
->resources_needed
= resources_needed_watchpoint
;
15307 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15308 ops
->print_it
= print_it_watchpoint
;
15309 ops
->print_mention
= print_mention_watchpoint
;
15310 ops
->print_recreate
= print_recreate_watchpoint
;
15311 ops
->explains_signal
= explains_signal_watchpoint
;
15313 /* Masked watchpoints. */
15314 ops
= &masked_watchpoint_breakpoint_ops
;
15315 *ops
= watchpoint_breakpoint_ops
;
15316 ops
->insert_location
= insert_masked_watchpoint
;
15317 ops
->remove_location
= remove_masked_watchpoint
;
15318 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15319 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15320 ops
->print_it
= print_it_masked_watchpoint
;
15321 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15322 ops
->print_mention
= print_mention_masked_watchpoint
;
15323 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15326 ops
= &tracepoint_breakpoint_ops
;
15327 *ops
= base_breakpoint_ops
;
15328 ops
->re_set
= tracepoint_re_set
;
15329 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15330 ops
->print_one_detail
= tracepoint_print_one_detail
;
15331 ops
->print_mention
= tracepoint_print_mention
;
15332 ops
->print_recreate
= tracepoint_print_recreate
;
15333 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15334 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15335 ops
->decode_location
= tracepoint_decode_location
;
15337 /* Probe tracepoints. */
15338 ops
= &tracepoint_probe_breakpoint_ops
;
15339 *ops
= tracepoint_breakpoint_ops
;
15340 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15341 ops
->decode_location
= tracepoint_probe_decode_location
;
15343 /* Static tracepoints with marker (`-m'). */
15344 ops
= &strace_marker_breakpoint_ops
;
15345 *ops
= tracepoint_breakpoint_ops
;
15346 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15347 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15348 ops
->decode_location
= strace_marker_decode_location
;
15350 /* Fork catchpoints. */
15351 ops
= &catch_fork_breakpoint_ops
;
15352 *ops
= base_breakpoint_ops
;
15353 ops
->insert_location
= insert_catch_fork
;
15354 ops
->remove_location
= remove_catch_fork
;
15355 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15356 ops
->print_it
= print_it_catch_fork
;
15357 ops
->print_one
= print_one_catch_fork
;
15358 ops
->print_mention
= print_mention_catch_fork
;
15359 ops
->print_recreate
= print_recreate_catch_fork
;
15361 /* Vfork catchpoints. */
15362 ops
= &catch_vfork_breakpoint_ops
;
15363 *ops
= base_breakpoint_ops
;
15364 ops
->insert_location
= insert_catch_vfork
;
15365 ops
->remove_location
= remove_catch_vfork
;
15366 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15367 ops
->print_it
= print_it_catch_vfork
;
15368 ops
->print_one
= print_one_catch_vfork
;
15369 ops
->print_mention
= print_mention_catch_vfork
;
15370 ops
->print_recreate
= print_recreate_catch_vfork
;
15372 /* Exec catchpoints. */
15373 ops
= &catch_exec_breakpoint_ops
;
15374 *ops
= base_breakpoint_ops
;
15375 ops
->insert_location
= insert_catch_exec
;
15376 ops
->remove_location
= remove_catch_exec
;
15377 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15378 ops
->print_it
= print_it_catch_exec
;
15379 ops
->print_one
= print_one_catch_exec
;
15380 ops
->print_mention
= print_mention_catch_exec
;
15381 ops
->print_recreate
= print_recreate_catch_exec
;
15383 /* Solib-related catchpoints. */
15384 ops
= &catch_solib_breakpoint_ops
;
15385 *ops
= base_breakpoint_ops
;
15386 ops
->insert_location
= insert_catch_solib
;
15387 ops
->remove_location
= remove_catch_solib
;
15388 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15389 ops
->check_status
= check_status_catch_solib
;
15390 ops
->print_it
= print_it_catch_solib
;
15391 ops
->print_one
= print_one_catch_solib
;
15392 ops
->print_mention
= print_mention_catch_solib
;
15393 ops
->print_recreate
= print_recreate_catch_solib
;
15395 ops
= &dprintf_breakpoint_ops
;
15396 *ops
= bkpt_base_breakpoint_ops
;
15397 ops
->re_set
= dprintf_re_set
;
15398 ops
->resources_needed
= bkpt_resources_needed
;
15399 ops
->print_it
= bkpt_print_it
;
15400 ops
->print_mention
= bkpt_print_mention
;
15401 ops
->print_recreate
= dprintf_print_recreate
;
15402 ops
->after_condition_true
= dprintf_after_condition_true
;
15403 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15406 /* Chain containing all defined "enable breakpoint" subcommands. */
15408 static struct cmd_list_element
*enablebreaklist
= NULL
;
15410 /* See breakpoint.h. */
15412 cmd_list_element
*commands_cmd_element
= nullptr;
15415 _initialize_breakpoint (void)
15417 struct cmd_list_element
*c
;
15419 initialize_breakpoint_ops ();
15421 gdb::observers::solib_unloaded
.attach (disable_breakpoints_in_unloaded_shlib
);
15422 gdb::observers::free_objfile
.attach (disable_breakpoints_in_freed_objfile
);
15423 gdb::observers::memory_changed
.attach (invalidate_bp_value_on_memory_change
);
15425 breakpoint_chain
= 0;
15426 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15427 before a breakpoint is set. */
15428 breakpoint_count
= 0;
15430 tracepoint_count
= 0;
15432 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15433 Set ignore-count of breakpoint number N to COUNT.\n\
15434 Usage is `ignore N COUNT'."));
15436 commands_cmd_element
= add_com ("commands", class_breakpoint
,
15437 commands_command
, _("\
15438 Set commands to be executed when the given breakpoints are hit.\n\
15439 Give a space-separated breakpoint list as argument after \"commands\".\n\
15440 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15442 With no argument, the targeted breakpoint is the last one set.\n\
15443 The commands themselves follow starting on the next line.\n\
15444 Type a line containing \"end\" to indicate the end of them.\n\
15445 Give \"silent\" as the first line to make the breakpoint silent;\n\
15446 then no output is printed when it is hit, except what the commands print."));
15448 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15449 Specify breakpoint number N to break only if COND is true.\n\
15450 Usage is `condition N COND', where N is an integer and COND is an\n\
15451 expression to be evaluated whenever breakpoint N is reached."));
15452 set_cmd_completer (c
, condition_completer
);
15454 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15455 Set a temporary breakpoint.\n\
15456 Like \"break\" except the breakpoint is only temporary,\n\
15457 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15458 by using \"enable delete\" on the breakpoint number.\n\
15460 BREAK_ARGS_HELP ("tbreak")));
15461 set_cmd_completer (c
, location_completer
);
15463 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15464 Set a hardware assisted breakpoint.\n\
15465 Like \"break\" except the breakpoint requires hardware support,\n\
15466 some target hardware may not have this support.\n\
15468 BREAK_ARGS_HELP ("hbreak")));
15469 set_cmd_completer (c
, location_completer
);
15471 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15472 Set a temporary hardware assisted breakpoint.\n\
15473 Like \"hbreak\" except the breakpoint is only temporary,\n\
15474 so it will be deleted when hit.\n\
15476 BREAK_ARGS_HELP ("thbreak")));
15477 set_cmd_completer (c
, location_completer
);
15479 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15480 Enable some breakpoints.\n\
15481 Give breakpoint numbers (separated by spaces) as arguments.\n\
15482 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15483 This is used to cancel the effect of the \"disable\" command.\n\
15484 With a subcommand you can enable temporarily."),
15485 &enablelist
, "enable ", 1, &cmdlist
);
15487 add_com_alias ("en", "enable", class_breakpoint
, 1);
15489 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15490 Enable some breakpoints.\n\
15491 Give breakpoint numbers (separated by spaces) as arguments.\n\
15492 This is used to cancel the effect of the \"disable\" command.\n\
15493 May be abbreviated to simply \"enable\"."),
15494 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15496 add_cmd ("once", no_class
, enable_once_command
, _("\
15497 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15498 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15501 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15502 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15503 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15506 add_cmd ("count", no_class
, enable_count_command
, _("\
15507 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15508 If a breakpoint is hit while enabled in this fashion,\n\
15509 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15512 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15513 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15514 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15517 add_cmd ("once", no_class
, enable_once_command
, _("\
15518 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15519 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15522 add_cmd ("count", no_class
, enable_count_command
, _("\
15523 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15524 If a breakpoint is hit while enabled in this fashion,\n\
15525 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15528 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15529 Disable some breakpoints.\n\
15530 Arguments are breakpoint numbers with spaces in between.\n\
15531 To disable all breakpoints, give no argument.\n\
15532 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15533 &disablelist
, "disable ", 1, &cmdlist
);
15534 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15535 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15537 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15538 Disable some breakpoints.\n\
15539 Arguments are breakpoint numbers with spaces in between.\n\
15540 To disable all breakpoints, give no argument.\n\
15541 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15542 This command may be abbreviated \"disable\"."),
15545 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15546 Delete some breakpoints or auto-display expressions.\n\
15547 Arguments are breakpoint numbers with spaces in between.\n\
15548 To delete all breakpoints, give no argument.\n\
15550 Also a prefix command for deletion of other GDB objects.\n\
15551 The \"unset\" command is also an alias for \"delete\"."),
15552 &deletelist
, "delete ", 1, &cmdlist
);
15553 add_com_alias ("d", "delete", class_breakpoint
, 1);
15554 add_com_alias ("del", "delete", class_breakpoint
, 1);
15556 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15557 Delete some breakpoints or auto-display expressions.\n\
15558 Arguments are breakpoint numbers with spaces in between.\n\
15559 To delete all breakpoints, give no argument.\n\
15560 This command may be abbreviated \"delete\"."),
15563 add_com ("clear", class_breakpoint
, clear_command
, _("\
15564 Clear breakpoint at specified location.\n\
15565 Argument may be a linespec, explicit, or address location as described below.\n\
15567 With no argument, clears all breakpoints in the line that the selected frame\n\
15568 is executing in.\n"
15569 "\n" LOCATION_HELP_STRING
"\n\n\
15570 See also the \"delete\" command which clears breakpoints by number."));
15571 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15573 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15574 Set breakpoint at specified location.\n"
15575 BREAK_ARGS_HELP ("break")));
15576 set_cmd_completer (c
, location_completer
);
15578 add_com_alias ("b", "break", class_run
, 1);
15579 add_com_alias ("br", "break", class_run
, 1);
15580 add_com_alias ("bre", "break", class_run
, 1);
15581 add_com_alias ("brea", "break", class_run
, 1);
15585 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15586 Break in function/address or break at a line in the current file."),
15587 &stoplist
, "stop ", 1, &cmdlist
);
15588 add_cmd ("in", class_breakpoint
, stopin_command
,
15589 _("Break in function or address."), &stoplist
);
15590 add_cmd ("at", class_breakpoint
, stopat_command
,
15591 _("Break at a line in the current file."), &stoplist
);
15592 add_com ("status", class_info
, info_breakpoints_command
, _("\
15593 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15594 The \"Type\" column indicates one of:\n\
15595 \tbreakpoint - normal breakpoint\n\
15596 \twatchpoint - watchpoint\n\
15597 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15598 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15599 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15600 address and file/line number respectively.\n\
15602 Convenience variable \"$_\" and default examine address for \"x\"\n\
15603 are set to the address of the last breakpoint listed unless the command\n\
15604 is prefixed with \"server \".\n\n\
15605 Convenience variable \"$bpnum\" contains the number of the last\n\
15606 breakpoint set."));
15609 add_info ("breakpoints", info_breakpoints_command
, _("\
15610 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15611 The \"Type\" column indicates one of:\n\
15612 \tbreakpoint - normal breakpoint\n\
15613 \twatchpoint - watchpoint\n\
15614 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15615 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15616 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15617 address and file/line number respectively.\n\
15619 Convenience variable \"$_\" and default examine address for \"x\"\n\
15620 are set to the address of the last breakpoint listed unless the command\n\
15621 is prefixed with \"server \".\n\n\
15622 Convenience variable \"$bpnum\" contains the number of the last\n\
15623 breakpoint set."));
15625 add_info_alias ("b", "breakpoints", 1);
15627 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15628 Status of all breakpoints, or breakpoint number NUMBER.\n\
15629 The \"Type\" column indicates one of:\n\
15630 \tbreakpoint - normal breakpoint\n\
15631 \twatchpoint - watchpoint\n\
15632 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15633 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15634 \tuntil - internal breakpoint used by the \"until\" command\n\
15635 \tfinish - internal breakpoint used by the \"finish\" command\n\
15636 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15637 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15638 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15639 address and file/line number respectively.\n\
15641 Convenience variable \"$_\" and default examine address for \"x\"\n\
15642 are set to the address of the last breakpoint listed unless the command\n\
15643 is prefixed with \"server \".\n\n\
15644 Convenience variable \"$bpnum\" contains the number of the last\n\
15646 &maintenanceinfolist
);
15648 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15649 Set catchpoints to catch events."),
15650 &catch_cmdlist
, "catch ",
15651 0/*allow-unknown*/, &cmdlist
);
15653 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15654 Set temporary catchpoints to catch events."),
15655 &tcatch_cmdlist
, "tcatch ",
15656 0/*allow-unknown*/, &cmdlist
);
15658 add_catch_command ("fork", _("Catch calls to fork."),
15659 catch_fork_command_1
,
15661 (void *) (uintptr_t) catch_fork_permanent
,
15662 (void *) (uintptr_t) catch_fork_temporary
);
15663 add_catch_command ("vfork", _("Catch calls to vfork."),
15664 catch_fork_command_1
,
15666 (void *) (uintptr_t) catch_vfork_permanent
,
15667 (void *) (uintptr_t) catch_vfork_temporary
);
15668 add_catch_command ("exec", _("Catch calls to exec."),
15669 catch_exec_command_1
,
15673 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15674 Usage: catch load [REGEX]\n\
15675 If REGEX is given, only stop for libraries matching the regular expression."),
15676 catch_load_command_1
,
15680 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15681 Usage: catch unload [REGEX]\n\
15682 If REGEX is given, only stop for libraries matching the regular expression."),
15683 catch_unload_command_1
,
15688 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15689 Set a watchpoint for an expression.\n\
15690 Usage: watch [-l|-location] EXPRESSION\n\
15691 A watchpoint stops execution of your program whenever the value of\n\
15692 an expression changes.\n\
15693 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15694 the memory to which it refers."));
15695 set_cmd_completer (c
, expression_completer
);
15697 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15698 Set a read watchpoint for an expression.\n\
15699 Usage: rwatch [-l|-location] EXPRESSION\n\
15700 A watchpoint stops execution of your program whenever the value of\n\
15701 an expression is read.\n\
15702 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15703 the memory to which it refers."));
15704 set_cmd_completer (c
, expression_completer
);
15706 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15707 Set a watchpoint for an expression.\n\
15708 Usage: awatch [-l|-location] EXPRESSION\n\
15709 A watchpoint stops execution of your program whenever the value of\n\
15710 an expression is either read or written.\n\
15711 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15712 the memory to which it refers."));
15713 set_cmd_completer (c
, expression_completer
);
15715 add_info ("watchpoints", info_watchpoints_command
, _("\
15716 Status of specified watchpoints (all watchpoints if no argument)."));
15718 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15719 respond to changes - contrary to the description. */
15720 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15721 &can_use_hw_watchpoints
, _("\
15722 Set debugger's willingness to use watchpoint hardware."), _("\
15723 Show debugger's willingness to use watchpoint hardware."), _("\
15724 If zero, gdb will not use hardware for new watchpoints, even if\n\
15725 such is available. (However, any hardware watchpoints that were\n\
15726 created before setting this to nonzero, will continue to use watchpoint\n\
15729 show_can_use_hw_watchpoints
,
15730 &setlist
, &showlist
);
15732 can_use_hw_watchpoints
= 1;
15734 /* Tracepoint manipulation commands. */
15736 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15737 Set a tracepoint at specified location.\n\
15739 BREAK_ARGS_HELP ("trace") "\n\
15740 Do \"help tracepoints\" for info on other tracepoint commands."));
15741 set_cmd_completer (c
, location_completer
);
15743 add_com_alias ("tp", "trace", class_alias
, 0);
15744 add_com_alias ("tr", "trace", class_alias
, 1);
15745 add_com_alias ("tra", "trace", class_alias
, 1);
15746 add_com_alias ("trac", "trace", class_alias
, 1);
15748 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15749 Set a fast tracepoint at specified location.\n\
15751 BREAK_ARGS_HELP ("ftrace") "\n\
15752 Do \"help tracepoints\" for info on other tracepoint commands."));
15753 set_cmd_completer (c
, location_completer
);
15755 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15756 Set a static tracepoint at location or marker.\n\
15758 strace [LOCATION] [if CONDITION]\n\
15759 LOCATION may be a linespec, explicit, or address location (described below) \n\
15760 or -m MARKER_ID.\n\n\
15761 If a marker id is specified, probe the marker with that name. With\n\
15762 no LOCATION, uses current execution address of the selected stack frame.\n\
15763 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15764 This collects arbitrary user data passed in the probe point call to the\n\
15765 tracing library. You can inspect it when analyzing the trace buffer,\n\
15766 by printing the $_sdata variable like any other convenience variable.\n\
15768 CONDITION is a boolean expression.\n\
15769 \n" LOCATION_HELP_STRING
"\n\n\
15770 Multiple tracepoints at one place are permitted, and useful if their\n\
15771 conditions are different.\n\
15773 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15774 Do \"help tracepoints\" for info on other tracepoint commands."));
15775 set_cmd_completer (c
, location_completer
);
15777 add_info ("tracepoints", info_tracepoints_command
, _("\
15778 Status of specified tracepoints (all tracepoints if no argument).\n\
15779 Convenience variable \"$tpnum\" contains the number of the\n\
15780 last tracepoint set."));
15782 add_info_alias ("tp", "tracepoints", 1);
15784 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15785 Delete specified tracepoints.\n\
15786 Arguments are tracepoint numbers, separated by spaces.\n\
15787 No argument means delete all tracepoints."),
15789 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
15791 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15792 Disable specified tracepoints.\n\
15793 Arguments are tracepoint numbers, separated by spaces.\n\
15794 No argument means disable all tracepoints."),
15796 deprecate_cmd (c
, "disable");
15798 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15799 Enable specified tracepoints.\n\
15800 Arguments are tracepoint numbers, separated by spaces.\n\
15801 No argument means enable all tracepoints."),
15803 deprecate_cmd (c
, "enable");
15805 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15806 Set the passcount for a tracepoint.\n\
15807 The trace will end when the tracepoint has been passed 'count' times.\n\
15808 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15809 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15811 add_prefix_cmd ("save", class_breakpoint
, save_command
,
15812 _("Save breakpoint definitions as a script."),
15813 &save_cmdlist
, "save ",
15814 0/*allow-unknown*/, &cmdlist
);
15816 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15817 Save current breakpoint definitions as a script.\n\
15818 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15819 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15820 session to restore them."),
15822 set_cmd_completer (c
, filename_completer
);
15824 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15825 Save current tracepoint definitions as a script.\n\
15826 Use the 'source' command in another debug session to restore them."),
15828 set_cmd_completer (c
, filename_completer
);
15830 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
15831 deprecate_cmd (c
, "save tracepoints");
15833 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
15834 Breakpoint specific settings\n\
15835 Configure various breakpoint-specific variables such as\n\
15836 pending breakpoint behavior"),
15837 &breakpoint_set_cmdlist
, "set breakpoint ",
15838 0/*allow-unknown*/, &setlist
);
15839 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
15840 Breakpoint specific settings\n\
15841 Configure various breakpoint-specific variables such as\n\
15842 pending breakpoint behavior"),
15843 &breakpoint_show_cmdlist
, "show breakpoint ",
15844 0/*allow-unknown*/, &showlist
);
15846 add_setshow_auto_boolean_cmd ("pending", no_class
,
15847 &pending_break_support
, _("\
15848 Set debugger's behavior regarding pending breakpoints."), _("\
15849 Show debugger's behavior regarding pending breakpoints."), _("\
15850 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15851 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15852 an error. If auto, an unrecognized breakpoint location results in a\n\
15853 user-query to see if a pending breakpoint should be created."),
15855 show_pending_break_support
,
15856 &breakpoint_set_cmdlist
,
15857 &breakpoint_show_cmdlist
);
15859 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15861 add_setshow_boolean_cmd ("auto-hw", no_class
,
15862 &automatic_hardware_breakpoints
, _("\
15863 Set automatic usage of hardware breakpoints."), _("\
15864 Show automatic usage of hardware breakpoints."), _("\
15865 If set, the debugger will automatically use hardware breakpoints for\n\
15866 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15867 a warning will be emitted for such breakpoints."),
15869 show_automatic_hardware_breakpoints
,
15870 &breakpoint_set_cmdlist
,
15871 &breakpoint_show_cmdlist
);
15873 add_setshow_boolean_cmd ("always-inserted", class_support
,
15874 &always_inserted_mode
, _("\
15875 Set mode for inserting breakpoints."), _("\
15876 Show mode for inserting breakpoints."), _("\
15877 When this mode is on, breakpoints are inserted immediately as soon as\n\
15878 they're created, kept inserted even when execution stops, and removed\n\
15879 only when the user deletes them. When this mode is off (the default),\n\
15880 breakpoints are inserted only when execution continues, and removed\n\
15881 when execution stops."),
15883 &show_always_inserted_mode
,
15884 &breakpoint_set_cmdlist
,
15885 &breakpoint_show_cmdlist
);
15887 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15888 condition_evaluation_enums
,
15889 &condition_evaluation_mode_1
, _("\
15890 Set mode of breakpoint condition evaluation."), _("\
15891 Show mode of breakpoint condition evaluation."), _("\
15892 When this is set to \"host\", breakpoint conditions will be\n\
15893 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15894 breakpoint conditions will be downloaded to the target (if the target\n\
15895 supports such feature) and conditions will be evaluated on the target's side.\n\
15896 If this is set to \"auto\" (default), this will be automatically set to\n\
15897 \"target\" if it supports condition evaluation, otherwise it will\n\
15898 be set to \"gdb\""),
15899 &set_condition_evaluation_mode
,
15900 &show_condition_evaluation_mode
,
15901 &breakpoint_set_cmdlist
,
15902 &breakpoint_show_cmdlist
);
15904 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15905 Set a breakpoint for an address range.\n\
15906 break-range START-LOCATION, END-LOCATION\n\
15907 where START-LOCATION and END-LOCATION can be one of the following:\n\
15908 LINENUM, for that line in the current file,\n\
15909 FILE:LINENUM, for that line in that file,\n\
15910 +OFFSET, for that number of lines after the current line\n\
15911 or the start of the range\n\
15912 FUNCTION, for the first line in that function,\n\
15913 FILE:FUNCTION, to distinguish among like-named static functions.\n\
15914 *ADDRESS, for the instruction at that address.\n\
15916 The breakpoint will stop execution of the inferior whenever it executes\n\
15917 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
15918 range (including START-LOCATION and END-LOCATION)."));
15920 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
15921 Set a dynamic printf at specified location.\n\
15922 dprintf location,format string,arg1,arg2,...\n\
15923 location may be a linespec, explicit, or address location.\n"
15924 "\n" LOCATION_HELP_STRING
));
15925 set_cmd_completer (c
, location_completer
);
15927 add_setshow_enum_cmd ("dprintf-style", class_support
,
15928 dprintf_style_enums
, &dprintf_style
, _("\
15929 Set the style of usage for dynamic printf."), _("\
15930 Show the style of usage for dynamic printf."), _("\
15931 This setting chooses how GDB will do a dynamic printf.\n\
15932 If the value is \"gdb\", then the printing is done by GDB to its own\n\
15933 console, as with the \"printf\" command.\n\
15934 If the value is \"call\", the print is done by calling a function in your\n\
15935 program; by default printf(), but you can choose a different function or\n\
15936 output stream by setting dprintf-function and dprintf-channel."),
15937 update_dprintf_commands
, NULL
,
15938 &setlist
, &showlist
);
15940 dprintf_function
= xstrdup ("printf");
15941 add_setshow_string_cmd ("dprintf-function", class_support
,
15942 &dprintf_function
, _("\
15943 Set the function to use for dynamic printf"), _("\
15944 Show the function to use for dynamic printf"), NULL
,
15945 update_dprintf_commands
, NULL
,
15946 &setlist
, &showlist
);
15948 dprintf_channel
= xstrdup ("");
15949 add_setshow_string_cmd ("dprintf-channel", class_support
,
15950 &dprintf_channel
, _("\
15951 Set the channel to use for dynamic printf"), _("\
15952 Show the channel to use for dynamic printf"), NULL
,
15953 update_dprintf_commands
, NULL
,
15954 &setlist
, &showlist
);
15956 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
15957 &disconnected_dprintf
, _("\
15958 Set whether dprintf continues after GDB disconnects."), _("\
15959 Show whether dprintf continues after GDB disconnects."), _("\
15960 Use this to let dprintf commands continue to hit and produce output\n\
15961 even if GDB disconnects or detaches from the target."),
15964 &setlist
, &showlist
);
15966 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
15967 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
15968 (target agent only) This is useful for formatted output in user-defined commands."));
15970 automatic_hardware_breakpoints
= 1;
15972 gdb::observers::about_to_proceed
.attach (breakpoint_about_to_proceed
);
15973 gdb::observers::thread_exit
.attach (remove_threaded_breakpoints
);