1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986-2017 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"
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"
69 #include "thread-fsm.h"
70 #include "tid-parse.h"
72 /* readline include files */
73 #include "readline/readline.h"
74 #include "readline/history.h"
76 /* readline defines this. */
79 #include "mi/mi-common.h"
80 #include "extension.h"
82 #include "progspace-and-thread.h"
83 #include "common/array-view.h"
84 #include "common/gdb_optional.h"
86 /* Enums for exception-handling support. */
87 enum exception_event_kind
94 /* Prototypes for local functions. */
96 static void map_breakpoint_numbers (const char *,
97 gdb::function_view
<void (breakpoint
*)>);
99 static void ignore_command (char *, int);
101 static void breakpoint_re_set_default (struct breakpoint
*);
104 create_sals_from_location_default (const struct event_location
*location
,
105 struct linespec_result
*canonical
,
106 enum bptype type_wanted
);
108 static void create_breakpoints_sal_default (struct gdbarch
*,
109 struct linespec_result
*,
110 gdb::unique_xmalloc_ptr
<char>,
111 gdb::unique_xmalloc_ptr
<char>,
113 enum bpdisp
, int, int,
115 const struct breakpoint_ops
*,
116 int, int, int, unsigned);
118 static std::vector
<symtab_and_line
> decode_location_default
119 (struct breakpoint
*b
, const struct event_location
*location
,
120 struct program_space
*search_pspace
);
122 static void clear_command (char *, int);
124 static int can_use_hardware_watchpoint (struct value
*);
126 static void mention (struct breakpoint
*);
128 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
130 const struct breakpoint_ops
*);
131 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
132 const struct symtab_and_line
*);
134 /* This function is used in gdbtk sources and thus can not be made
136 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
137 struct symtab_and_line
,
139 const struct breakpoint_ops
*);
141 static struct breakpoint
*
142 momentary_breakpoint_from_master (struct breakpoint
*orig
,
144 const struct breakpoint_ops
*ops
,
147 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
149 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
153 static void describe_other_breakpoints (struct gdbarch
*,
154 struct program_space
*, CORE_ADDR
,
155 struct obj_section
*, int);
157 static int watchpoint_locations_match (struct bp_location
*loc1
,
158 struct bp_location
*loc2
);
160 static int breakpoint_location_address_match (struct bp_location
*bl
,
161 const struct address_space
*aspace
,
164 static int breakpoint_location_address_range_overlap (struct bp_location
*,
165 const address_space
*,
168 static void info_breakpoints_command (char *, int);
170 static void info_watchpoints_command (char *, int);
172 static void commands_command (char *, int);
174 static void condition_command (char *, int);
176 static int remove_breakpoint (struct bp_location
*);
177 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
179 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
181 static int hw_breakpoint_used_count (void);
183 static int hw_watchpoint_use_count (struct breakpoint
*);
185 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
187 int *other_type_used
);
189 static void hbreak_command (char *, int);
191 static void thbreak_command (char *, int);
193 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
196 static void stop_command (char *arg
, int from_tty
);
198 static void free_bp_location (struct bp_location
*loc
);
199 static void incref_bp_location (struct bp_location
*loc
);
200 static void decref_bp_location (struct bp_location
**loc
);
202 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
204 /* update_global_location_list's modes of operation wrt to whether to
205 insert locations now. */
206 enum ugll_insert_mode
208 /* Don't insert any breakpoint locations into the inferior, only
209 remove already-inserted locations that no longer should be
210 inserted. Functions that delete a breakpoint or breakpoints
211 should specify this mode, so that deleting a breakpoint doesn't
212 have the side effect of inserting the locations of other
213 breakpoints that are marked not-inserted, but should_be_inserted
214 returns true on them.
216 This behavior is useful is situations close to tear-down -- e.g.,
217 after an exec, while the target still has execution, but
218 breakpoint shadows of the previous executable image should *NOT*
219 be restored to the new image; or before detaching, where the
220 target still has execution and wants to delete breakpoints from
221 GDB's lists, and all breakpoints had already been removed from
225 /* May insert breakpoints iff breakpoints_should_be_inserted_now
226 claims breakpoints should be inserted now. */
229 /* Insert locations now, irrespective of
230 breakpoints_should_be_inserted_now. E.g., say all threads are
231 stopped right now, and the user did "continue". We need to
232 insert breakpoints _before_ resuming the target, but
233 UGLL_MAY_INSERT wouldn't insert them, because
234 breakpoints_should_be_inserted_now returns false at that point,
235 as no thread is running yet. */
239 static void update_global_location_list (enum ugll_insert_mode
);
241 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
243 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
245 static void insert_breakpoint_locations (void);
247 static void info_tracepoints_command (char *, int);
249 static void enable_trace_command (char *, int);
251 static void disable_trace_command (char *, int);
253 static void trace_pass_command (char *, int);
255 static void set_tracepoint_count (int num
);
257 static int is_masked_watchpoint (const struct breakpoint
*b
);
259 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
261 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
264 static int strace_marker_p (struct breakpoint
*b
);
266 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
267 that are implemented on top of software or hardware breakpoints
268 (user breakpoints, internal and momentary breakpoints, etc.). */
269 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
271 /* Internal breakpoints class type. */
272 static struct breakpoint_ops internal_breakpoint_ops
;
274 /* Momentary breakpoints class type. */
275 static struct breakpoint_ops momentary_breakpoint_ops
;
277 /* The breakpoint_ops structure to be used in regular user created
279 struct breakpoint_ops bkpt_breakpoint_ops
;
281 /* Breakpoints set on probes. */
282 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
284 /* Dynamic printf class type. */
285 struct breakpoint_ops dprintf_breakpoint_ops
;
287 /* The style in which to perform a dynamic printf. This is a user
288 option because different output options have different tradeoffs;
289 if GDB does the printing, there is better error handling if there
290 is a problem with any of the arguments, but using an inferior
291 function lets you have special-purpose printers and sending of
292 output to the same place as compiled-in print functions. */
294 static const char dprintf_style_gdb
[] = "gdb";
295 static const char dprintf_style_call
[] = "call";
296 static const char dprintf_style_agent
[] = "agent";
297 static const char *const dprintf_style_enums
[] = {
303 static const char *dprintf_style
= dprintf_style_gdb
;
305 /* The function to use for dynamic printf if the preferred style is to
306 call into the inferior. The value is simply a string that is
307 copied into the command, so it can be anything that GDB can
308 evaluate to a callable address, not necessarily a function name. */
310 static char *dprintf_function
;
312 /* The channel to use for dynamic printf if the preferred style is to
313 call into the inferior; if a nonempty string, it will be passed to
314 the call as the first argument, with the format string as the
315 second. As with the dprintf function, this can be anything that
316 GDB knows how to evaluate, so in addition to common choices like
317 "stderr", this could be an app-specific expression like
318 "mystreams[curlogger]". */
320 static char *dprintf_channel
;
322 /* True if dprintf commands should continue to operate even if GDB
324 static int disconnected_dprintf
= 1;
326 struct command_line
*
327 breakpoint_commands (struct breakpoint
*b
)
329 return b
->commands
? b
->commands
.get () : NULL
;
332 /* Flag indicating that a command has proceeded the inferior past the
333 current breakpoint. */
335 static int breakpoint_proceeded
;
338 bpdisp_text (enum bpdisp disp
)
340 /* NOTE: the following values are a part of MI protocol and
341 represent values of 'disp' field returned when inferior stops at
343 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
345 return bpdisps
[(int) disp
];
348 /* Prototypes for exported functions. */
349 /* If FALSE, gdb will not use hardware support for watchpoints, even
350 if such is available. */
351 static int can_use_hw_watchpoints
;
354 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
355 struct cmd_list_element
*c
,
358 fprintf_filtered (file
,
359 _("Debugger's willingness to use "
360 "watchpoint hardware is %s.\n"),
364 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
365 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
366 for unrecognized breakpoint locations.
367 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
368 static enum auto_boolean pending_break_support
;
370 show_pending_break_support (struct ui_file
*file
, int from_tty
,
371 struct cmd_list_element
*c
,
374 fprintf_filtered (file
,
375 _("Debugger's behavior regarding "
376 "pending breakpoints is %s.\n"),
380 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
381 set with "break" but falling in read-only memory.
382 If 0, gdb will warn about such breakpoints, but won't automatically
383 use hardware breakpoints. */
384 static int automatic_hardware_breakpoints
;
386 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
387 struct cmd_list_element
*c
,
390 fprintf_filtered (file
,
391 _("Automatic usage of hardware breakpoints is %s.\n"),
395 /* If on, GDB keeps breakpoints inserted even if the inferior is
396 stopped, and immediately inserts any new breakpoints as soon as
397 they're created. If off (default), GDB keeps breakpoints off of
398 the target as long as possible. That is, it delays inserting
399 breakpoints until the next resume, and removes them again when the
400 target fully stops. This is a bit safer in case GDB crashes while
401 processing user input. */
402 static int always_inserted_mode
= 0;
405 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
406 struct cmd_list_element
*c
, const char *value
)
408 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
412 /* See breakpoint.h. */
415 breakpoints_should_be_inserted_now (void)
417 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
419 /* If breakpoints are global, they should be inserted even if no
420 thread under gdb's control is running, or even if there are
421 no threads under GDB's control yet. */
424 else if (target_has_execution
)
426 struct thread_info
*tp
;
428 if (always_inserted_mode
)
430 /* The user wants breakpoints inserted even if all threads
435 if (threads_are_executing ())
438 /* Don't remove breakpoints yet if, even though all threads are
439 stopped, we still have events to process. */
440 ALL_NON_EXITED_THREADS (tp
)
442 && tp
->suspend
.waitstatus_pending_p
)
448 static const char condition_evaluation_both
[] = "host or target";
450 /* Modes for breakpoint condition evaluation. */
451 static const char condition_evaluation_auto
[] = "auto";
452 static const char condition_evaluation_host
[] = "host";
453 static const char condition_evaluation_target
[] = "target";
454 static const char *const condition_evaluation_enums
[] = {
455 condition_evaluation_auto
,
456 condition_evaluation_host
,
457 condition_evaluation_target
,
461 /* Global that holds the current mode for breakpoint condition evaluation. */
462 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
464 /* Global that we use to display information to the user (gets its value from
465 condition_evaluation_mode_1. */
466 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
468 /* Translate a condition evaluation mode MODE into either "host"
469 or "target". This is used mostly to translate from "auto" to the
470 real setting that is being used. It returns the translated
474 translate_condition_evaluation_mode (const char *mode
)
476 if (mode
== condition_evaluation_auto
)
478 if (target_supports_evaluation_of_breakpoint_conditions ())
479 return condition_evaluation_target
;
481 return condition_evaluation_host
;
487 /* Discovers what condition_evaluation_auto translates to. */
490 breakpoint_condition_evaluation_mode (void)
492 return translate_condition_evaluation_mode (condition_evaluation_mode
);
495 /* Return true if GDB should evaluate breakpoint conditions or false
499 gdb_evaluates_breakpoint_condition_p (void)
501 const char *mode
= breakpoint_condition_evaluation_mode ();
503 return (mode
== condition_evaluation_host
);
506 /* Are we executing breakpoint commands? */
507 static int executing_breakpoint_commands
;
509 /* Are overlay event breakpoints enabled? */
510 static int overlay_events_enabled
;
512 /* See description in breakpoint.h. */
513 int target_exact_watchpoints
= 0;
515 /* Walk the following statement or block through all breakpoints.
516 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
517 current breakpoint. */
519 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
521 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
522 for (B = breakpoint_chain; \
523 B ? (TMP=B->next, 1): 0; \
526 /* Similar iterator for the low-level breakpoints. SAFE variant is
527 not provided so update_global_location_list must not be called
528 while executing the block of ALL_BP_LOCATIONS. */
530 #define ALL_BP_LOCATIONS(B,BP_TMP) \
531 for (BP_TMP = bp_locations; \
532 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
535 /* Iterates through locations with address ADDRESS for the currently selected
536 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
537 to where the loop should start from.
538 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
539 appropriate location to start with. */
541 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
542 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
543 BP_LOCP_TMP = BP_LOCP_START; \
545 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
546 && (*BP_LOCP_TMP)->address == ADDRESS); \
549 /* Iterator for tracepoints only. */
551 #define ALL_TRACEPOINTS(B) \
552 for (B = breakpoint_chain; B; B = B->next) \
553 if (is_tracepoint (B))
555 /* Chains of all breakpoints defined. */
557 struct breakpoint
*breakpoint_chain
;
559 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
561 static struct bp_location
**bp_locations
;
563 /* Number of elements of BP_LOCATIONS. */
565 static unsigned bp_locations_count
;
567 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
568 ADDRESS for the current elements of BP_LOCATIONS which get a valid
569 result from bp_location_has_shadow. You can use it for roughly
570 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
571 an address you need to read. */
573 static CORE_ADDR bp_locations_placed_address_before_address_max
;
575 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
576 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
577 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
578 You can use it for roughly limiting the subrange of BP_LOCATIONS to
579 scan for shadow bytes for an address you need to read. */
581 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
583 /* The locations that no longer correspond to any breakpoint, unlinked
584 from the bp_locations array, but for which a hit may still be
585 reported by a target. */
586 VEC(bp_location_p
) *moribund_locations
= NULL
;
588 /* Number of last breakpoint made. */
590 static int breakpoint_count
;
592 /* The value of `breakpoint_count' before the last command that
593 created breakpoints. If the last (break-like) command created more
594 than one breakpoint, then the difference between BREAKPOINT_COUNT
595 and PREV_BREAKPOINT_COUNT is more than one. */
596 static int prev_breakpoint_count
;
598 /* Number of last tracepoint made. */
600 static int tracepoint_count
;
602 static struct cmd_list_element
*breakpoint_set_cmdlist
;
603 static struct cmd_list_element
*breakpoint_show_cmdlist
;
604 struct cmd_list_element
*save_cmdlist
;
606 /* See declaration at breakpoint.h. */
609 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
612 struct breakpoint
*b
= NULL
;
616 if (func (b
, user_data
) != 0)
623 /* Return whether a breakpoint is an active enabled breakpoint. */
625 breakpoint_enabled (struct breakpoint
*b
)
627 return (b
->enable_state
== bp_enabled
);
630 /* Set breakpoint count to NUM. */
633 set_breakpoint_count (int num
)
635 prev_breakpoint_count
= breakpoint_count
;
636 breakpoint_count
= num
;
637 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
640 /* Used by `start_rbreak_breakpoints' below, to record the current
641 breakpoint count before "rbreak" creates any breakpoint. */
642 static int rbreak_start_breakpoint_count
;
644 /* Called at the start an "rbreak" command to record the first
647 scoped_rbreak_breakpoints::scoped_rbreak_breakpoints ()
649 rbreak_start_breakpoint_count
= breakpoint_count
;
652 /* Called at the end of an "rbreak" command to record the last
655 scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints ()
657 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
660 /* Used in run_command to zero the hit count when a new run starts. */
663 clear_breakpoint_hit_counts (void)
665 struct breakpoint
*b
;
672 /* Return the breakpoint with the specified number, or NULL
673 if the number does not refer to an existing breakpoint. */
676 get_breakpoint (int num
)
678 struct breakpoint
*b
;
681 if (b
->number
== num
)
689 /* Mark locations as "conditions have changed" in case the target supports
690 evaluating conditions on its side. */
693 mark_breakpoint_modified (struct breakpoint
*b
)
695 struct bp_location
*loc
;
697 /* This is only meaningful if the target is
698 evaluating conditions and if the user has
699 opted for condition evaluation on the target's
701 if (gdb_evaluates_breakpoint_condition_p ()
702 || !target_supports_evaluation_of_breakpoint_conditions ())
705 if (!is_breakpoint (b
))
708 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
709 loc
->condition_changed
= condition_modified
;
712 /* Mark location as "conditions have changed" in case the target supports
713 evaluating conditions on its side. */
716 mark_breakpoint_location_modified (struct bp_location
*loc
)
718 /* This is only meaningful if the target is
719 evaluating conditions and if the user has
720 opted for condition evaluation on the target's
722 if (gdb_evaluates_breakpoint_condition_p ()
723 || !target_supports_evaluation_of_breakpoint_conditions ())
727 if (!is_breakpoint (loc
->owner
))
730 loc
->condition_changed
= condition_modified
;
733 /* Sets the condition-evaluation mode using the static global
734 condition_evaluation_mode. */
737 set_condition_evaluation_mode (char *args
, int from_tty
,
738 struct cmd_list_element
*c
)
740 const char *old_mode
, *new_mode
;
742 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
743 && !target_supports_evaluation_of_breakpoint_conditions ())
745 condition_evaluation_mode_1
= condition_evaluation_mode
;
746 warning (_("Target does not support breakpoint condition evaluation.\n"
747 "Using host evaluation mode instead."));
751 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
752 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
754 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
755 settings was "auto". */
756 condition_evaluation_mode
= condition_evaluation_mode_1
;
758 /* Only update the mode if the user picked a different one. */
759 if (new_mode
!= old_mode
)
761 struct bp_location
*loc
, **loc_tmp
;
762 /* If the user switched to a different evaluation mode, we
763 need to synch the changes with the target as follows:
765 "host" -> "target": Send all (valid) conditions to the target.
766 "target" -> "host": Remove all the conditions from the target.
769 if (new_mode
== condition_evaluation_target
)
771 /* Mark everything modified and synch conditions with the
773 ALL_BP_LOCATIONS (loc
, loc_tmp
)
774 mark_breakpoint_location_modified (loc
);
778 /* Manually mark non-duplicate locations to synch conditions
779 with the target. We do this to remove all the conditions the
780 target knows about. */
781 ALL_BP_LOCATIONS (loc
, loc_tmp
)
782 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
783 loc
->needs_update
= 1;
787 update_global_location_list (UGLL_MAY_INSERT
);
793 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
794 what "auto" is translating to. */
797 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
798 struct cmd_list_element
*c
, const char *value
)
800 if (condition_evaluation_mode
== condition_evaluation_auto
)
801 fprintf_filtered (file
,
802 _("Breakpoint condition evaluation "
803 "mode is %s (currently %s).\n"),
805 breakpoint_condition_evaluation_mode ());
807 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
811 /* A comparison function for bp_location AP and BP that is used by
812 bsearch. This comparison function only cares about addresses, unlike
813 the more general bp_locations_compare function. */
816 bp_locations_compare_addrs (const void *ap
, const void *bp
)
818 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
819 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
821 if (a
->address
== b
->address
)
824 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
827 /* Helper function to skip all bp_locations with addresses
828 less than ADDRESS. It returns the first bp_location that
829 is greater than or equal to ADDRESS. If none is found, just
832 static struct bp_location
**
833 get_first_locp_gte_addr (CORE_ADDR address
)
835 struct bp_location dummy_loc
;
836 struct bp_location
*dummy_locp
= &dummy_loc
;
837 struct bp_location
**locp_found
= NULL
;
839 /* Initialize the dummy location's address field. */
840 dummy_loc
.address
= address
;
842 /* Find a close match to the first location at ADDRESS. */
843 locp_found
= ((struct bp_location
**)
844 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
845 sizeof (struct bp_location
**),
846 bp_locations_compare_addrs
));
848 /* Nothing was found, nothing left to do. */
849 if (locp_found
== NULL
)
852 /* We may have found a location that is at ADDRESS but is not the first in the
853 location's list. Go backwards (if possible) and locate the first one. */
854 while ((locp_found
- 1) >= bp_locations
855 && (*(locp_found
- 1))->address
== address
)
862 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
865 xfree (b
->cond_string
);
866 b
->cond_string
= NULL
;
868 if (is_watchpoint (b
))
870 struct watchpoint
*w
= (struct watchpoint
*) b
;
872 w
->cond_exp
.reset ();
876 struct bp_location
*loc
;
878 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
882 /* No need to free the condition agent expression
883 bytecode (if we have one). We will handle this
884 when we go through update_global_location_list. */
891 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
895 const char *arg
= exp
;
897 /* I don't know if it matters whether this is the string the user
898 typed in or the decompiled expression. */
899 b
->cond_string
= xstrdup (arg
);
900 b
->condition_not_parsed
= 0;
902 if (is_watchpoint (b
))
904 struct watchpoint
*w
= (struct watchpoint
*) b
;
906 innermost_block
= NULL
;
908 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
910 error (_("Junk at end of expression"));
911 w
->cond_exp_valid_block
= innermost_block
;
915 struct bp_location
*loc
;
917 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
921 parse_exp_1 (&arg
, loc
->address
,
922 block_for_pc (loc
->address
), 0);
924 error (_("Junk at end of expression"));
928 mark_breakpoint_modified (b
);
930 observer_notify_breakpoint_modified (b
);
933 /* Completion for the "condition" command. */
936 condition_completer (struct cmd_list_element
*cmd
,
937 completion_tracker
&tracker
,
938 const char *text
, const char *word
)
942 text
= skip_spaces (text
);
943 space
= skip_to_space (text
);
947 struct breakpoint
*b
;
948 VEC (char_ptr
) *result
= NULL
;
952 /* We don't support completion of history indices. */
953 if (!isdigit (text
[1]))
954 complete_internalvar (tracker
, &text
[1]);
958 /* We're completing the breakpoint number. */
965 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
967 if (strncmp (number
, text
, len
) == 0)
969 gdb::unique_xmalloc_ptr
<char> copy (xstrdup (number
));
970 tracker
.add_completion (std::move (copy
));
977 /* We're completing the expression part. */
978 text
= skip_spaces (space
);
979 expression_completer (cmd
, tracker
, text
, word
);
982 /* condition N EXP -- set break condition of breakpoint N to EXP. */
985 condition_command (char *arg
, int from_tty
)
987 struct breakpoint
*b
;
992 error_no_arg (_("breakpoint number"));
995 bnum
= get_number (&p
);
997 error (_("Bad breakpoint argument: '%s'"), arg
);
1000 if (b
->number
== bnum
)
1002 /* Check if this breakpoint has a "stop" method implemented in an
1003 extension language. This method and conditions entered into GDB
1004 from the CLI are mutually exclusive. */
1005 const struct extension_language_defn
*extlang
1006 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1008 if (extlang
!= NULL
)
1010 error (_("Only one stop condition allowed. There is currently"
1011 " a %s stop condition defined for this breakpoint."),
1012 ext_lang_capitalized_name (extlang
));
1014 set_breakpoint_condition (b
, p
, from_tty
);
1016 if (is_breakpoint (b
))
1017 update_global_location_list (UGLL_MAY_INSERT
);
1022 error (_("No breakpoint number %d."), bnum
);
1025 /* Check that COMMAND do not contain commands that are suitable
1026 only for tracepoints and not suitable for ordinary breakpoints.
1027 Throw if any such commands is found. */
1030 check_no_tracepoint_commands (struct command_line
*commands
)
1032 struct command_line
*c
;
1034 for (c
= commands
; c
; c
= c
->next
)
1038 if (c
->control_type
== while_stepping_control
)
1039 error (_("The 'while-stepping' command can "
1040 "only be used for tracepoints"));
1042 for (i
= 0; i
< c
->body_count
; ++i
)
1043 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1045 /* Not that command parsing removes leading whitespace and comment
1046 lines and also empty lines. So, we only need to check for
1047 command directly. */
1048 if (strstr (c
->line
, "collect ") == c
->line
)
1049 error (_("The 'collect' command can only be used for tracepoints"));
1051 if (strstr (c
->line
, "teval ") == c
->line
)
1052 error (_("The 'teval' command can only be used for tracepoints"));
1056 struct longjmp_breakpoint
: public breakpoint
1058 ~longjmp_breakpoint () override
;
1061 /* Encapsulate tests for different types of tracepoints. */
1064 is_tracepoint_type (bptype type
)
1066 return (type
== bp_tracepoint
1067 || type
== bp_fast_tracepoint
1068 || type
== bp_static_tracepoint
);
1072 is_longjmp_type (bptype type
)
1074 return type
== bp_longjmp
|| type
== bp_exception
;
1078 is_tracepoint (const struct breakpoint
*b
)
1080 return is_tracepoint_type (b
->type
);
1083 /* Factory function to create an appropriate instance of breakpoint given
1086 static std::unique_ptr
<breakpoint
>
1087 new_breakpoint_from_type (bptype type
)
1091 if (is_tracepoint_type (type
))
1092 b
= new tracepoint ();
1093 else if (is_longjmp_type (type
))
1094 b
= new longjmp_breakpoint ();
1096 b
= new breakpoint ();
1098 return std::unique_ptr
<breakpoint
> (b
);
1101 /* A helper function that validates that COMMANDS are valid for a
1102 breakpoint. This function will throw an exception if a problem is
1106 validate_commands_for_breakpoint (struct breakpoint
*b
,
1107 struct command_line
*commands
)
1109 if (is_tracepoint (b
))
1111 struct tracepoint
*t
= (struct tracepoint
*) b
;
1112 struct command_line
*c
;
1113 struct command_line
*while_stepping
= 0;
1115 /* Reset the while-stepping step count. The previous commands
1116 might have included a while-stepping action, while the new
1120 /* We need to verify that each top-level element of commands is
1121 valid for tracepoints, that there's at most one
1122 while-stepping element, and that the while-stepping's body
1123 has valid tracing commands excluding nested while-stepping.
1124 We also need to validate the tracepoint action line in the
1125 context of the tracepoint --- validate_actionline actually
1126 has side effects, like setting the tracepoint's
1127 while-stepping STEP_COUNT, in addition to checking if the
1128 collect/teval actions parse and make sense in the
1129 tracepoint's context. */
1130 for (c
= commands
; c
; c
= c
->next
)
1132 if (c
->control_type
== while_stepping_control
)
1134 if (b
->type
== bp_fast_tracepoint
)
1135 error (_("The 'while-stepping' command "
1136 "cannot be used for fast tracepoint"));
1137 else if (b
->type
== bp_static_tracepoint
)
1138 error (_("The 'while-stepping' command "
1139 "cannot be used for static tracepoint"));
1142 error (_("The 'while-stepping' command "
1143 "can be used only once"));
1148 validate_actionline (c
->line
, b
);
1152 struct command_line
*c2
;
1154 gdb_assert (while_stepping
->body_count
== 1);
1155 c2
= while_stepping
->body_list
[0];
1156 for (; c2
; c2
= c2
->next
)
1158 if (c2
->control_type
== while_stepping_control
)
1159 error (_("The 'while-stepping' command cannot be nested"));
1165 check_no_tracepoint_commands (commands
);
1169 /* Return a vector of all the static tracepoints set at ADDR. The
1170 caller is responsible for releasing the vector. */
1173 static_tracepoints_here (CORE_ADDR addr
)
1175 struct breakpoint
*b
;
1176 VEC(breakpoint_p
) *found
= 0;
1177 struct bp_location
*loc
;
1180 if (b
->type
== bp_static_tracepoint
)
1182 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1183 if (loc
->address
== addr
)
1184 VEC_safe_push(breakpoint_p
, found
, b
);
1190 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1191 validate that only allowed commands are included. */
1194 breakpoint_set_commands (struct breakpoint
*b
,
1195 command_line_up
&&commands
)
1197 validate_commands_for_breakpoint (b
, commands
.get ());
1199 b
->commands
= std::move (commands
);
1200 observer_notify_breakpoint_modified (b
);
1203 /* Set the internal `silent' flag on the breakpoint. Note that this
1204 is not the same as the "silent" that may appear in the breakpoint's
1208 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1210 int old_silent
= b
->silent
;
1213 if (old_silent
!= silent
)
1214 observer_notify_breakpoint_modified (b
);
1217 /* Set the thread for this breakpoint. If THREAD is -1, make the
1218 breakpoint work for any thread. */
1221 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1223 int old_thread
= b
->thread
;
1226 if (old_thread
!= thread
)
1227 observer_notify_breakpoint_modified (b
);
1230 /* Set the task for this breakpoint. If TASK is 0, make the
1231 breakpoint work for any task. */
1234 breakpoint_set_task (struct breakpoint
*b
, int task
)
1236 int old_task
= b
->task
;
1239 if (old_task
!= task
)
1240 observer_notify_breakpoint_modified (b
);
1244 check_tracepoint_command (char *line
, void *closure
)
1246 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1248 validate_actionline (line
, b
);
1252 commands_command_1 (const char *arg
, int from_tty
,
1253 struct command_line
*control
)
1255 counted_command_line cmd
;
1257 std::string new_arg
;
1259 if (arg
== NULL
|| !*arg
)
1261 if (breakpoint_count
- prev_breakpoint_count
> 1)
1262 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1264 else if (breakpoint_count
> 0)
1265 new_arg
= string_printf ("%d", breakpoint_count
);
1266 arg
= new_arg
.c_str ();
1269 map_breakpoint_numbers
1270 (arg
, [&] (breakpoint
*b
)
1274 if (control
!= NULL
)
1275 cmd
= copy_command_lines (control
->body_list
[0]);
1279 = string_printf (_("Type commands for breakpoint(s) "
1280 "%s, one per line."),
1283 cmd
= read_command_lines (&str
[0],
1286 ? check_tracepoint_command
: 0),
1291 /* If a breakpoint was on the list more than once, we don't need to
1293 if (b
->commands
!= cmd
)
1295 validate_commands_for_breakpoint (b
, cmd
.get ());
1297 observer_notify_breakpoint_modified (b
);
1302 error (_("No breakpoints specified."));
1306 commands_command (char *arg
, int from_tty
)
1308 commands_command_1 (arg
, from_tty
, NULL
);
1311 /* Like commands_command, but instead of reading the commands from
1312 input stream, takes them from an already parsed command structure.
1314 This is used by cli-script.c to DTRT with breakpoint commands
1315 that are part of if and while bodies. */
1316 enum command_control_type
1317 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1319 commands_command_1 (arg
, 0, cmd
);
1320 return simple_control
;
1323 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1326 bp_location_has_shadow (struct bp_location
*bl
)
1328 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1332 if (bl
->target_info
.shadow_len
== 0)
1333 /* BL isn't valid, or doesn't shadow memory. */
1338 /* Update BUF, which is LEN bytes read from the target address
1339 MEMADDR, by replacing a memory breakpoint with its shadowed
1342 If READBUF is not NULL, this buffer must not overlap with the of
1343 the breakpoint location's shadow_contents buffer. Otherwise, a
1344 failed assertion internal error will be raised. */
1347 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1348 const gdb_byte
*writebuf_org
,
1349 ULONGEST memaddr
, LONGEST len
,
1350 struct bp_target_info
*target_info
,
1351 struct gdbarch
*gdbarch
)
1353 /* Now do full processing of the found relevant range of elements. */
1354 CORE_ADDR bp_addr
= 0;
1358 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1359 current_program_space
->aspace
, 0))
1361 /* The breakpoint is inserted in a different address space. */
1365 /* Addresses and length of the part of the breakpoint that
1367 bp_addr
= target_info
->placed_address
;
1368 bp_size
= target_info
->shadow_len
;
1370 if (bp_addr
+ bp_size
<= memaddr
)
1372 /* The breakpoint is entirely before the chunk of memory we are
1377 if (bp_addr
>= memaddr
+ len
)
1379 /* The breakpoint is entirely after the chunk of memory we are
1384 /* Offset within shadow_contents. */
1385 if (bp_addr
< memaddr
)
1387 /* Only copy the second part of the breakpoint. */
1388 bp_size
-= memaddr
- bp_addr
;
1389 bptoffset
= memaddr
- bp_addr
;
1393 if (bp_addr
+ bp_size
> memaddr
+ len
)
1395 /* Only copy the first part of the breakpoint. */
1396 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1399 if (readbuf
!= NULL
)
1401 /* Verify that the readbuf buffer does not overlap with the
1402 shadow_contents buffer. */
1403 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1404 || readbuf
>= (target_info
->shadow_contents
1405 + target_info
->shadow_len
));
1407 /* Update the read buffer with this inserted breakpoint's
1409 memcpy (readbuf
+ bp_addr
- memaddr
,
1410 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1414 const unsigned char *bp
;
1415 CORE_ADDR addr
= target_info
->reqstd_address
;
1418 /* Update the shadow with what we want to write to memory. */
1419 memcpy (target_info
->shadow_contents
+ bptoffset
,
1420 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1422 /* Determine appropriate breakpoint contents and size for this
1424 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1426 /* Update the final write buffer with this inserted
1427 breakpoint's INSN. */
1428 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1432 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1433 by replacing any memory breakpoints with their shadowed contents.
1435 If READBUF is not NULL, this buffer must not overlap with any of
1436 the breakpoint location's shadow_contents buffers. Otherwise,
1437 a failed assertion internal error will be raised.
1439 The range of shadowed area by each bp_location is:
1440 bl->address - bp_locations_placed_address_before_address_max
1441 up to bl->address + bp_locations_shadow_len_after_address_max
1442 The range we were requested to resolve shadows for is:
1443 memaddr ... memaddr + len
1444 Thus the safe cutoff boundaries for performance optimization are
1445 memaddr + len <= (bl->address
1446 - bp_locations_placed_address_before_address_max)
1448 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1451 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1452 const gdb_byte
*writebuf_org
,
1453 ULONGEST memaddr
, LONGEST len
)
1455 /* Left boundary, right boundary and median element of our binary
1457 unsigned bc_l
, bc_r
, bc
;
1459 /* Find BC_L which is a leftmost element which may affect BUF
1460 content. It is safe to report lower value but a failure to
1461 report higher one. */
1464 bc_r
= bp_locations_count
;
1465 while (bc_l
+ 1 < bc_r
)
1467 struct bp_location
*bl
;
1469 bc
= (bc_l
+ bc_r
) / 2;
1470 bl
= bp_locations
[bc
];
1472 /* Check first BL->ADDRESS will not overflow due to the added
1473 constant. Then advance the left boundary only if we are sure
1474 the BC element can in no way affect the BUF content (MEMADDR
1475 to MEMADDR + LEN range).
1477 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1478 offset so that we cannot miss a breakpoint with its shadow
1479 range tail still reaching MEMADDR. */
1481 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1483 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1490 /* Due to the binary search above, we need to make sure we pick the
1491 first location that's at BC_L's address. E.g., if there are
1492 multiple locations at the same address, BC_L may end up pointing
1493 at a duplicate location, and miss the "master"/"inserted"
1494 location. Say, given locations L1, L2 and L3 at addresses A and
1497 L1@A, L2@A, L3@B, ...
1499 BC_L could end up pointing at location L2, while the "master"
1500 location could be L1. Since the `loc->inserted' flag is only set
1501 on "master" locations, we'd forget to restore the shadow of L1
1504 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1507 /* Now do full processing of the found relevant range of elements. */
1509 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1511 struct bp_location
*bl
= bp_locations
[bc
];
1513 /* bp_location array has BL->OWNER always non-NULL. */
1514 if (bl
->owner
->type
== bp_none
)
1515 warning (_("reading through apparently deleted breakpoint #%d?"),
1518 /* Performance optimization: any further element can no longer affect BUF
1521 if (bl
->address
>= bp_locations_placed_address_before_address_max
1522 && memaddr
+ len
<= (bl
->address
1523 - bp_locations_placed_address_before_address_max
))
1526 if (!bp_location_has_shadow (bl
))
1529 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1530 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1536 /* Return true if BPT is either a software breakpoint or a hardware
1540 is_breakpoint (const struct breakpoint
*bpt
)
1542 return (bpt
->type
== bp_breakpoint
1543 || bpt
->type
== bp_hardware_breakpoint
1544 || bpt
->type
== bp_dprintf
);
1547 /* Return true if BPT is of any hardware watchpoint kind. */
1550 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1552 return (bpt
->type
== bp_hardware_watchpoint
1553 || bpt
->type
== bp_read_watchpoint
1554 || bpt
->type
== bp_access_watchpoint
);
1557 /* Return true if BPT is of any watchpoint kind, hardware or
1561 is_watchpoint (const struct breakpoint
*bpt
)
1563 return (is_hardware_watchpoint (bpt
)
1564 || bpt
->type
== bp_watchpoint
);
1567 /* Returns true if the current thread and its running state are safe
1568 to evaluate or update watchpoint B. Watchpoints on local
1569 expressions need to be evaluated in the context of the thread that
1570 was current when the watchpoint was created, and, that thread needs
1571 to be stopped to be able to select the correct frame context.
1572 Watchpoints on global expressions can be evaluated on any thread,
1573 and in any state. It is presently left to the target allowing
1574 memory accesses when threads are running. */
1577 watchpoint_in_thread_scope (struct watchpoint
*b
)
1579 return (b
->pspace
== current_program_space
1580 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1581 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1582 && !is_executing (inferior_ptid
))));
1585 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1586 associated bp_watchpoint_scope breakpoint. */
1589 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1591 if (w
->related_breakpoint
!= w
)
1593 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1594 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1595 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1596 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1597 w
->related_breakpoint
= w
;
1599 w
->disposition
= disp_del_at_next_stop
;
1602 /* Extract a bitfield value from value VAL using the bit parameters contained in
1605 static struct value
*
1606 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1608 struct value
*bit_val
;
1613 bit_val
= allocate_value (value_type (val
));
1615 unpack_value_bitfield (bit_val
,
1618 value_contents_for_printing (val
),
1625 /* Allocate a dummy location and add it to B, which must be a software
1626 watchpoint. This is required because even if a software watchpoint
1627 is not watching any memory, bpstat_stop_status requires a location
1628 to be able to report stops. */
1631 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1632 struct program_space
*pspace
)
1634 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1636 b
->loc
= allocate_bp_location (b
);
1637 b
->loc
->pspace
= pspace
;
1638 b
->loc
->address
= -1;
1639 b
->loc
->length
= -1;
1642 /* Returns true if B is a software watchpoint that is not watching any
1643 memory (e.g., "watch $pc"). */
1646 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1648 return (b
->type
== bp_watchpoint
1650 && b
->loc
->next
== NULL
1651 && b
->loc
->address
== -1
1652 && b
->loc
->length
== -1);
1655 /* Assuming that B is a watchpoint:
1656 - Reparse watchpoint expression, if REPARSE is non-zero
1657 - Evaluate expression and store the result in B->val
1658 - Evaluate the condition if there is one, and store the result
1660 - Update the list of values that must be watched in B->loc.
1662 If the watchpoint disposition is disp_del_at_next_stop, then do
1663 nothing. If this is local watchpoint that is out of scope, delete
1666 Even with `set breakpoint always-inserted on' the watchpoints are
1667 removed + inserted on each stop here. Normal breakpoints must
1668 never be removed because they might be missed by a running thread
1669 when debugging in non-stop mode. On the other hand, hardware
1670 watchpoints (is_hardware_watchpoint; processed here) are specific
1671 to each LWP since they are stored in each LWP's hardware debug
1672 registers. Therefore, such LWP must be stopped first in order to
1673 be able to modify its hardware watchpoints.
1675 Hardware watchpoints must be reset exactly once after being
1676 presented to the user. It cannot be done sooner, because it would
1677 reset the data used to present the watchpoint hit to the user. And
1678 it must not be done later because it could display the same single
1679 watchpoint hit during multiple GDB stops. Note that the latter is
1680 relevant only to the hardware watchpoint types bp_read_watchpoint
1681 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1682 not user-visible - its hit is suppressed if the memory content has
1685 The following constraints influence the location where we can reset
1686 hardware watchpoints:
1688 * target_stopped_by_watchpoint and target_stopped_data_address are
1689 called several times when GDB stops.
1692 * Multiple hardware watchpoints can be hit at the same time,
1693 causing GDB to stop. GDB only presents one hardware watchpoint
1694 hit at a time as the reason for stopping, and all the other hits
1695 are presented later, one after the other, each time the user
1696 requests the execution to be resumed. Execution is not resumed
1697 for the threads still having pending hit event stored in
1698 LWP_INFO->STATUS. While the watchpoint is already removed from
1699 the inferior on the first stop the thread hit event is kept being
1700 reported from its cached value by linux_nat_stopped_data_address
1701 until the real thread resume happens after the watchpoint gets
1702 presented and thus its LWP_INFO->STATUS gets reset.
1704 Therefore the hardware watchpoint hit can get safely reset on the
1705 watchpoint removal from inferior. */
1708 update_watchpoint (struct watchpoint
*b
, int reparse
)
1710 int within_current_scope
;
1711 struct frame_id saved_frame_id
;
1714 /* If this is a local watchpoint, we only want to check if the
1715 watchpoint frame is in scope if the current thread is the thread
1716 that was used to create the watchpoint. */
1717 if (!watchpoint_in_thread_scope (b
))
1720 if (b
->disposition
== disp_del_at_next_stop
)
1725 /* Determine if the watchpoint is within scope. */
1726 if (b
->exp_valid_block
== NULL
)
1727 within_current_scope
= 1;
1730 struct frame_info
*fi
= get_current_frame ();
1731 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1732 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1734 /* If we're at a point where the stack has been destroyed
1735 (e.g. in a function epilogue), unwinding may not work
1736 properly. Do not attempt to recreate locations at this
1737 point. See similar comments in watchpoint_check. */
1738 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1741 /* Save the current frame's ID so we can restore it after
1742 evaluating the watchpoint expression on its own frame. */
1743 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1744 took a frame parameter, so that we didn't have to change the
1747 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1749 fi
= frame_find_by_id (b
->watchpoint_frame
);
1750 within_current_scope
= (fi
!= NULL
);
1751 if (within_current_scope
)
1755 /* We don't free locations. They are stored in the bp_location array
1756 and update_global_location_list will eventually delete them and
1757 remove breakpoints if needed. */
1760 if (within_current_scope
&& reparse
)
1765 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1766 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1767 /* If the meaning of expression itself changed, the old value is
1768 no longer relevant. We don't want to report a watchpoint hit
1769 to the user when the old value and the new value may actually
1770 be completely different objects. */
1771 value_free (b
->val
);
1775 /* Note that unlike with breakpoints, the watchpoint's condition
1776 expression is stored in the breakpoint object, not in the
1777 locations (re)created below. */
1778 if (b
->cond_string
!= NULL
)
1780 b
->cond_exp
.reset ();
1783 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1787 /* If we failed to parse the expression, for example because
1788 it refers to a global variable in a not-yet-loaded shared library,
1789 don't try to insert watchpoint. We don't automatically delete
1790 such watchpoint, though, since failure to parse expression
1791 is different from out-of-scope watchpoint. */
1792 if (!target_has_execution
)
1794 /* Without execution, memory can't change. No use to try and
1795 set watchpoint locations. The watchpoint will be reset when
1796 the target gains execution, through breakpoint_re_set. */
1797 if (!can_use_hw_watchpoints
)
1799 if (b
->ops
->works_in_software_mode (b
))
1800 b
->type
= bp_watchpoint
;
1802 error (_("Can't set read/access watchpoint when "
1803 "hardware watchpoints are disabled."));
1806 else if (within_current_scope
&& b
->exp
)
1809 struct value
*val_chain
, *v
, *result
, *next
;
1810 struct program_space
*frame_pspace
;
1812 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1814 /* Avoid setting b->val if it's already set. The meaning of
1815 b->val is 'the last value' user saw, and we should update
1816 it only if we reported that last value to user. As it
1817 happens, the code that reports it updates b->val directly.
1818 We don't keep track of the memory value for masked
1820 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1822 if (b
->val_bitsize
!= 0)
1824 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1832 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1834 /* Look at each value on the value chain. */
1835 for (v
= val_chain
; v
; v
= value_next (v
))
1837 /* If it's a memory location, and GDB actually needed
1838 its contents to evaluate the expression, then we
1839 must watch it. If the first value returned is
1840 still lazy, that means an error occurred reading it;
1841 watch it anyway in case it becomes readable. */
1842 if (VALUE_LVAL (v
) == lval_memory
1843 && (v
== val_chain
|| ! value_lazy (v
)))
1845 struct type
*vtype
= check_typedef (value_type (v
));
1847 /* We only watch structs and arrays if user asked
1848 for it explicitly, never if they just happen to
1849 appear in the middle of some value chain. */
1851 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1852 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1855 enum target_hw_bp_type type
;
1856 struct bp_location
*loc
, **tmp
;
1857 int bitpos
= 0, bitsize
= 0;
1859 if (value_bitsize (v
) != 0)
1861 /* Extract the bit parameters out from the bitfield
1863 bitpos
= value_bitpos (v
);
1864 bitsize
= value_bitsize (v
);
1866 else if (v
== result
&& b
->val_bitsize
!= 0)
1868 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1869 lvalue whose bit parameters are saved in the fields
1870 VAL_BITPOS and VAL_BITSIZE. */
1871 bitpos
= b
->val_bitpos
;
1872 bitsize
= b
->val_bitsize
;
1875 addr
= value_address (v
);
1878 /* Skip the bytes that don't contain the bitfield. */
1883 if (b
->type
== bp_read_watchpoint
)
1885 else if (b
->type
== bp_access_watchpoint
)
1888 loc
= allocate_bp_location (b
);
1889 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1892 loc
->gdbarch
= get_type_arch (value_type (v
));
1894 loc
->pspace
= frame_pspace
;
1895 loc
->address
= addr
;
1899 /* Just cover the bytes that make up the bitfield. */
1900 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1903 loc
->length
= TYPE_LENGTH (value_type (v
));
1905 loc
->watchpoint_type
= type
;
1910 /* Change the type of breakpoint between hardware assisted or
1911 an ordinary watchpoint depending on the hardware support
1912 and free hardware slots. REPARSE is set when the inferior
1917 enum bp_loc_type loc_type
;
1918 struct bp_location
*bl
;
1920 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1924 int i
, target_resources_ok
, other_type_used
;
1927 /* Use an exact watchpoint when there's only one memory region to be
1928 watched, and only one debug register is needed to watch it. */
1929 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1931 /* We need to determine how many resources are already
1932 used for all other hardware watchpoints plus this one
1933 to see if we still have enough resources to also fit
1934 this watchpoint in as well. */
1936 /* If this is a software watchpoint, we try to turn it
1937 to a hardware one -- count resources as if B was of
1938 hardware watchpoint type. */
1940 if (type
== bp_watchpoint
)
1941 type
= bp_hardware_watchpoint
;
1943 /* This watchpoint may or may not have been placed on
1944 the list yet at this point (it won't be in the list
1945 if we're trying to create it for the first time,
1946 through watch_command), so always account for it
1949 /* Count resources used by all watchpoints except B. */
1950 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1952 /* Add in the resources needed for B. */
1953 i
+= hw_watchpoint_use_count (b
);
1956 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1957 if (target_resources_ok
<= 0)
1959 int sw_mode
= b
->ops
->works_in_software_mode (b
);
1961 if (target_resources_ok
== 0 && !sw_mode
)
1962 error (_("Target does not support this type of "
1963 "hardware watchpoint."));
1964 else if (target_resources_ok
< 0 && !sw_mode
)
1965 error (_("There are not enough available hardware "
1966 "resources for this watchpoint."));
1968 /* Downgrade to software watchpoint. */
1969 b
->type
= bp_watchpoint
;
1973 /* If this was a software watchpoint, we've just
1974 found we have enough resources to turn it to a
1975 hardware watchpoint. Otherwise, this is a
1980 else if (!b
->ops
->works_in_software_mode (b
))
1982 if (!can_use_hw_watchpoints
)
1983 error (_("Can't set read/access watchpoint when "
1984 "hardware watchpoints are disabled."));
1986 error (_("Expression cannot be implemented with "
1987 "read/access watchpoint."));
1990 b
->type
= bp_watchpoint
;
1992 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1993 : bp_loc_hardware_watchpoint
);
1994 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1995 bl
->loc_type
= loc_type
;
1998 for (v
= val_chain
; v
; v
= next
)
2000 next
= value_next (v
);
2005 /* If a software watchpoint is not watching any memory, then the
2006 above left it without any location set up. But,
2007 bpstat_stop_status requires a location to be able to report
2008 stops, so make sure there's at least a dummy one. */
2009 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2010 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2012 else if (!within_current_scope
)
2014 printf_filtered (_("\
2015 Watchpoint %d deleted because the program has left the block\n\
2016 in which its expression is valid.\n"),
2018 watchpoint_del_at_next_stop (b
);
2021 /* Restore the selected frame. */
2023 select_frame (frame_find_by_id (saved_frame_id
));
2027 /* Returns 1 iff breakpoint location should be
2028 inserted in the inferior. We don't differentiate the type of BL's owner
2029 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2030 breakpoint_ops is not defined, because in insert_bp_location,
2031 tracepoint's insert_location will not be called. */
2033 should_be_inserted (struct bp_location
*bl
)
2035 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2038 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2041 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2044 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2047 /* This is set for example, when we're attached to the parent of a
2048 vfork, and have detached from the child. The child is running
2049 free, and we expect it to do an exec or exit, at which point the
2050 OS makes the parent schedulable again (and the target reports
2051 that the vfork is done). Until the child is done with the shared
2052 memory region, do not insert breakpoints in the parent, otherwise
2053 the child could still trip on the parent's breakpoints. Since
2054 the parent is blocked anyway, it won't miss any breakpoint. */
2055 if (bl
->pspace
->breakpoints_not_allowed
)
2058 /* Don't insert a breakpoint if we're trying to step past its
2059 location, except if the breakpoint is a single-step breakpoint,
2060 and the breakpoint's thread is the thread which is stepping past
2062 if ((bl
->loc_type
== bp_loc_software_breakpoint
2063 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2064 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2066 /* The single-step breakpoint may be inserted at the location
2067 we're trying to step if the instruction branches to itself.
2068 However, the instruction won't be executed at all and it may
2069 break the semantics of the instruction, for example, the
2070 instruction is a conditional branch or updates some flags.
2071 We can't fix it unless GDB is able to emulate the instruction
2072 or switch to displaced stepping. */
2073 && !(bl
->owner
->type
== bp_single_step
2074 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2078 fprintf_unfiltered (gdb_stdlog
,
2079 "infrun: skipping breakpoint: "
2080 "stepping past insn at: %s\n",
2081 paddress (bl
->gdbarch
, bl
->address
));
2086 /* Don't insert watchpoints if we're trying to step past the
2087 instruction that triggered one. */
2088 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2089 && stepping_past_nonsteppable_watchpoint ())
2093 fprintf_unfiltered (gdb_stdlog
,
2094 "infrun: stepping past non-steppable watchpoint. "
2095 "skipping watchpoint at %s:%d\n",
2096 paddress (bl
->gdbarch
, bl
->address
),
2105 /* Same as should_be_inserted but does the check assuming
2106 that the location is not duplicated. */
2109 unduplicated_should_be_inserted (struct bp_location
*bl
)
2112 const int save_duplicate
= bl
->duplicate
;
2115 result
= should_be_inserted (bl
);
2116 bl
->duplicate
= save_duplicate
;
2120 /* Parses a conditional described by an expression COND into an
2121 agent expression bytecode suitable for evaluation
2122 by the bytecode interpreter. Return NULL if there was
2123 any error during parsing. */
2125 static agent_expr_up
2126 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2131 agent_expr_up aexpr
;
2133 /* We don't want to stop processing, so catch any errors
2134 that may show up. */
2137 aexpr
= gen_eval_for_expr (scope
, cond
);
2140 CATCH (ex
, RETURN_MASK_ERROR
)
2142 /* If we got here, it means the condition could not be parsed to a valid
2143 bytecode expression and thus can't be evaluated on the target's side.
2144 It's no use iterating through the conditions. */
2148 /* We have a valid agent expression. */
2152 /* Based on location BL, create a list of breakpoint conditions to be
2153 passed on to the target. If we have duplicated locations with different
2154 conditions, we will add such conditions to the list. The idea is that the
2155 target will evaluate the list of conditions and will only notify GDB when
2156 one of them is true. */
2159 build_target_condition_list (struct bp_location
*bl
)
2161 struct bp_location
**locp
= NULL
, **loc2p
;
2162 int null_condition_or_parse_error
= 0;
2163 int modified
= bl
->needs_update
;
2164 struct bp_location
*loc
;
2166 /* Release conditions left over from a previous insert. */
2167 bl
->target_info
.conditions
.clear ();
2169 /* This is only meaningful if the target is
2170 evaluating conditions and if the user has
2171 opted for condition evaluation on the target's
2173 if (gdb_evaluates_breakpoint_condition_p ()
2174 || !target_supports_evaluation_of_breakpoint_conditions ())
2177 /* Do a first pass to check for locations with no assigned
2178 conditions or conditions that fail to parse to a valid agent expression
2179 bytecode. If any of these happen, then it's no use to send conditions
2180 to the target since this location will always trigger and generate a
2181 response back to GDB. */
2182 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2185 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2189 /* Re-parse the conditions since something changed. In that
2190 case we already freed the condition bytecodes (see
2191 force_breakpoint_reinsertion). We just
2192 need to parse the condition to bytecodes again. */
2193 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2197 /* If we have a NULL bytecode expression, it means something
2198 went wrong or we have a null condition expression. */
2199 if (!loc
->cond_bytecode
)
2201 null_condition_or_parse_error
= 1;
2207 /* If any of these happened, it means we will have to evaluate the conditions
2208 for the location's address on gdb's side. It is no use keeping bytecodes
2209 for all the other duplicate locations, thus we free all of them here.
2211 This is so we have a finer control over which locations' conditions are
2212 being evaluated by GDB or the remote stub. */
2213 if (null_condition_or_parse_error
)
2215 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2218 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2220 /* Only go as far as the first NULL bytecode is
2222 if (!loc
->cond_bytecode
)
2225 loc
->cond_bytecode
.reset ();
2230 /* No NULL conditions or failed bytecode generation. Build a condition list
2231 for this location's address. */
2232 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2236 && is_breakpoint (loc
->owner
)
2237 && loc
->pspace
->num
== bl
->pspace
->num
2238 && loc
->owner
->enable_state
== bp_enabled
2241 /* Add the condition to the vector. This will be used later
2242 to send the conditions to the target. */
2243 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2250 /* Parses a command described by string CMD into an agent expression
2251 bytecode suitable for evaluation by the bytecode interpreter.
2252 Return NULL if there was any error during parsing. */
2254 static agent_expr_up
2255 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2257 struct cleanup
*old_cleanups
= 0;
2258 struct expression
**argvec
;
2259 const char *cmdrest
;
2260 const char *format_start
, *format_end
;
2261 struct format_piece
*fpieces
;
2263 struct gdbarch
*gdbarch
= get_current_arch ();
2270 if (*cmdrest
== ',')
2272 cmdrest
= skip_spaces (cmdrest
);
2274 if (*cmdrest
++ != '"')
2275 error (_("No format string following the location"));
2277 format_start
= cmdrest
;
2279 fpieces
= parse_format_string (&cmdrest
);
2281 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2283 format_end
= cmdrest
;
2285 if (*cmdrest
++ != '"')
2286 error (_("Bad format string, non-terminated '\"'."));
2288 cmdrest
= skip_spaces (cmdrest
);
2290 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2291 error (_("Invalid argument syntax"));
2293 if (*cmdrest
== ',')
2295 cmdrest
= skip_spaces (cmdrest
);
2297 /* For each argument, make an expression. */
2299 argvec
= (struct expression
**) alloca (strlen (cmd
)
2300 * sizeof (struct expression
*));
2303 while (*cmdrest
!= '\0')
2308 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2309 argvec
[nargs
++] = expr
.release ();
2311 if (*cmdrest
== ',')
2315 agent_expr_up aexpr
;
2317 /* We don't want to stop processing, so catch any errors
2318 that may show up. */
2321 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2322 format_start
, format_end
- format_start
,
2323 fpieces
, nargs
, argvec
);
2325 CATCH (ex
, RETURN_MASK_ERROR
)
2327 /* If we got here, it means the command could not be parsed to a valid
2328 bytecode expression and thus can't be evaluated on the target's side.
2329 It's no use iterating through the other commands. */
2333 do_cleanups (old_cleanups
);
2335 /* We have a valid agent expression, return it. */
2339 /* Based on location BL, create a list of breakpoint commands to be
2340 passed on to the target. If we have duplicated locations with
2341 different commands, we will add any such to the list. */
2344 build_target_command_list (struct bp_location
*bl
)
2346 struct bp_location
**locp
= NULL
, **loc2p
;
2347 int null_command_or_parse_error
= 0;
2348 int modified
= bl
->needs_update
;
2349 struct bp_location
*loc
;
2351 /* Clear commands left over from a previous insert. */
2352 bl
->target_info
.tcommands
.clear ();
2354 if (!target_can_run_breakpoint_commands ())
2357 /* For now, limit to agent-style dprintf breakpoints. */
2358 if (dprintf_style
!= dprintf_style_agent
)
2361 /* For now, if we have any duplicate location that isn't a dprintf,
2362 don't install the target-side commands, as that would make the
2363 breakpoint not be reported to the core, and we'd lose
2365 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2368 if (is_breakpoint (loc
->owner
)
2369 && loc
->pspace
->num
== bl
->pspace
->num
2370 && loc
->owner
->type
!= bp_dprintf
)
2374 /* Do a first pass to check for locations with no assigned
2375 conditions or conditions that fail to parse to a valid agent expression
2376 bytecode. If any of these happen, then it's no use to send conditions
2377 to the target since this location will always trigger and generate a
2378 response back to GDB. */
2379 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2382 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2386 /* Re-parse the commands since something changed. In that
2387 case we already freed the command bytecodes (see
2388 force_breakpoint_reinsertion). We just
2389 need to parse the command to bytecodes again. */
2391 = parse_cmd_to_aexpr (bl
->address
,
2392 loc
->owner
->extra_string
);
2395 /* If we have a NULL bytecode expression, it means something
2396 went wrong or we have a null command expression. */
2397 if (!loc
->cmd_bytecode
)
2399 null_command_or_parse_error
= 1;
2405 /* If anything failed, then we're not doing target-side commands,
2407 if (null_command_or_parse_error
)
2409 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2412 if (is_breakpoint (loc
->owner
)
2413 && loc
->pspace
->num
== bl
->pspace
->num
)
2415 /* Only go as far as the first NULL bytecode is
2417 if (loc
->cmd_bytecode
== NULL
)
2420 loc
->cmd_bytecode
.reset ();
2425 /* No NULL commands or failed bytecode generation. Build a command list
2426 for this location's address. */
2427 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2430 if (loc
->owner
->extra_string
2431 && is_breakpoint (loc
->owner
)
2432 && loc
->pspace
->num
== bl
->pspace
->num
2433 && loc
->owner
->enable_state
== bp_enabled
2436 /* Add the command to the vector. This will be used later
2437 to send the commands to the target. */
2438 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2442 bl
->target_info
.persist
= 0;
2443 /* Maybe flag this location as persistent. */
2444 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2445 bl
->target_info
.persist
= 1;
2448 /* Return the kind of breakpoint on address *ADDR. Get the kind
2449 of breakpoint according to ADDR except single-step breakpoint.
2450 Get the kind of single-step breakpoint according to the current
2454 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2456 if (bl
->owner
->type
== bp_single_step
)
2458 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2459 struct regcache
*regcache
;
2461 regcache
= get_thread_regcache (thr
->ptid
);
2463 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2467 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2470 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2471 location. Any error messages are printed to TMP_ERROR_STREAM; and
2472 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2473 Returns 0 for success, 1 if the bp_location type is not supported or
2476 NOTE drow/2003-09-09: This routine could be broken down to an
2477 object-style method for each breakpoint or catchpoint type. */
2479 insert_bp_location (struct bp_location
*bl
,
2480 struct ui_file
*tmp_error_stream
,
2481 int *disabled_breaks
,
2482 int *hw_breakpoint_error
,
2483 int *hw_bp_error_explained_already
)
2485 enum errors bp_err
= GDB_NO_ERROR
;
2486 const char *bp_err_message
= NULL
;
2488 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2491 /* Note we don't initialize bl->target_info, as that wipes out
2492 the breakpoint location's shadow_contents if the breakpoint
2493 is still inserted at that location. This in turn breaks
2494 target_read_memory which depends on these buffers when
2495 a memory read is requested at the breakpoint location:
2496 Once the target_info has been wiped, we fail to see that
2497 we have a breakpoint inserted at that address and thus
2498 read the breakpoint instead of returning the data saved in
2499 the breakpoint location's shadow contents. */
2500 bl
->target_info
.reqstd_address
= bl
->address
;
2501 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2502 bl
->target_info
.length
= bl
->length
;
2504 /* When working with target-side conditions, we must pass all the conditions
2505 for the same breakpoint address down to the target since GDB will not
2506 insert those locations. With a list of breakpoint conditions, the target
2507 can decide when to stop and notify GDB. */
2509 if (is_breakpoint (bl
->owner
))
2511 build_target_condition_list (bl
);
2512 build_target_command_list (bl
);
2513 /* Reset the modification marker. */
2514 bl
->needs_update
= 0;
2517 if (bl
->loc_type
== bp_loc_software_breakpoint
2518 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2520 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2522 /* If the explicitly specified breakpoint type
2523 is not hardware breakpoint, check the memory map to see
2524 if the breakpoint address is in read only memory or not.
2526 Two important cases are:
2527 - location type is not hardware breakpoint, memory
2528 is readonly. We change the type of the location to
2529 hardware breakpoint.
2530 - location type is hardware breakpoint, memory is
2531 read-write. This means we've previously made the
2532 location hardware one, but then the memory map changed,
2535 When breakpoints are removed, remove_breakpoints will use
2536 location types we've just set here, the only possible
2537 problem is that memory map has changed during running
2538 program, but it's not going to work anyway with current
2540 struct mem_region
*mr
2541 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2545 if (automatic_hardware_breakpoints
)
2547 enum bp_loc_type new_type
;
2549 if (mr
->attrib
.mode
!= MEM_RW
)
2550 new_type
= bp_loc_hardware_breakpoint
;
2552 new_type
= bp_loc_software_breakpoint
;
2554 if (new_type
!= bl
->loc_type
)
2556 static int said
= 0;
2558 bl
->loc_type
= new_type
;
2561 fprintf_filtered (gdb_stdout
,
2562 _("Note: automatically using "
2563 "hardware breakpoints for "
2564 "read-only addresses.\n"));
2569 else if (bl
->loc_type
== bp_loc_software_breakpoint
2570 && mr
->attrib
.mode
!= MEM_RW
)
2572 fprintf_unfiltered (tmp_error_stream
,
2573 _("Cannot insert breakpoint %d.\n"
2574 "Cannot set software breakpoint "
2575 "at read-only address %s\n"),
2577 paddress (bl
->gdbarch
, bl
->address
));
2583 /* First check to see if we have to handle an overlay. */
2584 if (overlay_debugging
== ovly_off
2585 || bl
->section
== NULL
2586 || !(section_is_overlay (bl
->section
)))
2588 /* No overlay handling: just set the breakpoint. */
2593 val
= bl
->owner
->ops
->insert_location (bl
);
2595 bp_err
= GENERIC_ERROR
;
2597 CATCH (e
, RETURN_MASK_ALL
)
2600 bp_err_message
= e
.message
;
2606 /* This breakpoint is in an overlay section.
2607 Shall we set a breakpoint at the LMA? */
2608 if (!overlay_events_enabled
)
2610 /* Yes -- overlay event support is not active,
2611 so we must try to set a breakpoint at the LMA.
2612 This will not work for a hardware breakpoint. */
2613 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2614 warning (_("hardware breakpoint %d not supported in overlay!"),
2618 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2620 /* Set a software (trap) breakpoint at the LMA. */
2621 bl
->overlay_target_info
= bl
->target_info
;
2622 bl
->overlay_target_info
.reqstd_address
= addr
;
2624 /* No overlay handling: just set the breakpoint. */
2629 bl
->overlay_target_info
.kind
2630 = breakpoint_kind (bl
, &addr
);
2631 bl
->overlay_target_info
.placed_address
= addr
;
2632 val
= target_insert_breakpoint (bl
->gdbarch
,
2633 &bl
->overlay_target_info
);
2635 bp_err
= GENERIC_ERROR
;
2637 CATCH (e
, RETURN_MASK_ALL
)
2640 bp_err_message
= e
.message
;
2644 if (bp_err
!= GDB_NO_ERROR
)
2645 fprintf_unfiltered (tmp_error_stream
,
2646 "Overlay breakpoint %d "
2647 "failed: in ROM?\n",
2651 /* Shall we set a breakpoint at the VMA? */
2652 if (section_is_mapped (bl
->section
))
2654 /* Yes. This overlay section is mapped into memory. */
2659 val
= bl
->owner
->ops
->insert_location (bl
);
2661 bp_err
= GENERIC_ERROR
;
2663 CATCH (e
, RETURN_MASK_ALL
)
2666 bp_err_message
= e
.message
;
2672 /* No. This breakpoint will not be inserted.
2673 No error, but do not mark the bp as 'inserted'. */
2678 if (bp_err
!= GDB_NO_ERROR
)
2680 /* Can't set the breakpoint. */
2682 /* In some cases, we might not be able to insert a
2683 breakpoint in a shared library that has already been
2684 removed, but we have not yet processed the shlib unload
2685 event. Unfortunately, some targets that implement
2686 breakpoint insertion themselves can't tell why the
2687 breakpoint insertion failed (e.g., the remote target
2688 doesn't define error codes), so we must treat generic
2689 errors as memory errors. */
2690 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2691 && bl
->loc_type
== bp_loc_software_breakpoint
2692 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2693 || shared_objfile_contains_address_p (bl
->pspace
,
2696 /* See also: disable_breakpoints_in_shlibs. */
2697 bl
->shlib_disabled
= 1;
2698 observer_notify_breakpoint_modified (bl
->owner
);
2699 if (!*disabled_breaks
)
2701 fprintf_unfiltered (tmp_error_stream
,
2702 "Cannot insert breakpoint %d.\n",
2704 fprintf_unfiltered (tmp_error_stream
,
2705 "Temporarily disabling shared "
2706 "library breakpoints:\n");
2708 *disabled_breaks
= 1;
2709 fprintf_unfiltered (tmp_error_stream
,
2710 "breakpoint #%d\n", bl
->owner
->number
);
2715 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2717 *hw_breakpoint_error
= 1;
2718 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2719 fprintf_unfiltered (tmp_error_stream
,
2720 "Cannot insert hardware breakpoint %d%s",
2721 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2722 if (bp_err_message
!= NULL
)
2723 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2727 if (bp_err_message
== NULL
)
2730 = memory_error_message (TARGET_XFER_E_IO
,
2731 bl
->gdbarch
, bl
->address
);
2733 fprintf_unfiltered (tmp_error_stream
,
2734 "Cannot insert breakpoint %d.\n"
2736 bl
->owner
->number
, message
.c_str ());
2740 fprintf_unfiltered (tmp_error_stream
,
2741 "Cannot insert breakpoint %d: %s\n",
2756 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2757 /* NOTE drow/2003-09-08: This state only exists for removing
2758 watchpoints. It's not clear that it's necessary... */
2759 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2763 gdb_assert (bl
->owner
->ops
!= NULL
2764 && bl
->owner
->ops
->insert_location
!= NULL
);
2766 val
= bl
->owner
->ops
->insert_location (bl
);
2768 /* If trying to set a read-watchpoint, and it turns out it's not
2769 supported, try emulating one with an access watchpoint. */
2770 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2772 struct bp_location
*loc
, **loc_temp
;
2774 /* But don't try to insert it, if there's already another
2775 hw_access location that would be considered a duplicate
2777 ALL_BP_LOCATIONS (loc
, loc_temp
)
2779 && loc
->watchpoint_type
== hw_access
2780 && watchpoint_locations_match (bl
, loc
))
2784 bl
->target_info
= loc
->target_info
;
2785 bl
->watchpoint_type
= hw_access
;
2792 bl
->watchpoint_type
= hw_access
;
2793 val
= bl
->owner
->ops
->insert_location (bl
);
2796 /* Back to the original value. */
2797 bl
->watchpoint_type
= hw_read
;
2801 bl
->inserted
= (val
== 0);
2804 else if (bl
->owner
->type
== bp_catchpoint
)
2808 gdb_assert (bl
->owner
->ops
!= NULL
2809 && bl
->owner
->ops
->insert_location
!= NULL
);
2811 val
= bl
->owner
->ops
->insert_location (bl
);
2814 bl
->owner
->enable_state
= bp_disabled
;
2818 Error inserting catchpoint %d: Your system does not support this type\n\
2819 of catchpoint."), bl
->owner
->number
);
2821 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2824 bl
->inserted
= (val
== 0);
2826 /* We've already printed an error message if there was a problem
2827 inserting this catchpoint, and we've disabled the catchpoint,
2828 so just return success. */
2835 /* This function is called when program space PSPACE is about to be
2836 deleted. It takes care of updating breakpoints to not reference
2840 breakpoint_program_space_exit (struct program_space
*pspace
)
2842 struct breakpoint
*b
, *b_temp
;
2843 struct bp_location
*loc
, **loc_temp
;
2845 /* Remove any breakpoint that was set through this program space. */
2846 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2848 if (b
->pspace
== pspace
)
2849 delete_breakpoint (b
);
2852 /* Breakpoints set through other program spaces could have locations
2853 bound to PSPACE as well. Remove those. */
2854 ALL_BP_LOCATIONS (loc
, loc_temp
)
2856 struct bp_location
*tmp
;
2858 if (loc
->pspace
== pspace
)
2860 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2861 if (loc
->owner
->loc
== loc
)
2862 loc
->owner
->loc
= loc
->next
;
2864 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2865 if (tmp
->next
== loc
)
2867 tmp
->next
= loc
->next
;
2873 /* Now update the global location list to permanently delete the
2874 removed locations above. */
2875 update_global_location_list (UGLL_DONT_INSERT
);
2878 /* Make sure all breakpoints are inserted in inferior.
2879 Throws exception on any error.
2880 A breakpoint that is already inserted won't be inserted
2881 again, so calling this function twice is safe. */
2883 insert_breakpoints (void)
2885 struct breakpoint
*bpt
;
2887 ALL_BREAKPOINTS (bpt
)
2888 if (is_hardware_watchpoint (bpt
))
2890 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2892 update_watchpoint (w
, 0 /* don't reparse. */);
2895 /* Updating watchpoints creates new locations, so update the global
2896 location list. Explicitly tell ugll to insert locations and
2897 ignore breakpoints_always_inserted_mode. */
2898 update_global_location_list (UGLL_INSERT
);
2901 /* Invoke CALLBACK for each of bp_location. */
2904 iterate_over_bp_locations (walk_bp_location_callback callback
)
2906 struct bp_location
*loc
, **loc_tmp
;
2908 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2910 callback (loc
, NULL
);
2914 /* This is used when we need to synch breakpoint conditions between GDB and the
2915 target. It is the case with deleting and disabling of breakpoints when using
2916 always-inserted mode. */
2919 update_inserted_breakpoint_locations (void)
2921 struct bp_location
*bl
, **blp_tmp
;
2924 int disabled_breaks
= 0;
2925 int hw_breakpoint_error
= 0;
2926 int hw_bp_details_reported
= 0;
2928 string_file tmp_error_stream
;
2930 /* Explicitly mark the warning -- this will only be printed if
2931 there was an error. */
2932 tmp_error_stream
.puts ("Warning:\n");
2934 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2936 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2938 /* We only want to update software breakpoints and hardware
2940 if (!is_breakpoint (bl
->owner
))
2943 /* We only want to update locations that are already inserted
2944 and need updating. This is to avoid unwanted insertion during
2945 deletion of breakpoints. */
2946 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2949 switch_to_program_space_and_thread (bl
->pspace
);
2951 /* For targets that support global breakpoints, there's no need
2952 to select an inferior to insert breakpoint to. In fact, even
2953 if we aren't attached to any process yet, we should still
2954 insert breakpoints. */
2955 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2956 && ptid_equal (inferior_ptid
, null_ptid
))
2959 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2960 &hw_breakpoint_error
, &hw_bp_details_reported
);
2967 target_terminal::ours_for_output ();
2968 error_stream (tmp_error_stream
);
2972 /* Used when starting or continuing the program. */
2975 insert_breakpoint_locations (void)
2977 struct breakpoint
*bpt
;
2978 struct bp_location
*bl
, **blp_tmp
;
2981 int disabled_breaks
= 0;
2982 int hw_breakpoint_error
= 0;
2983 int hw_bp_error_explained_already
= 0;
2985 string_file tmp_error_stream
;
2987 /* Explicitly mark the warning -- this will only be printed if
2988 there was an error. */
2989 tmp_error_stream
.puts ("Warning:\n");
2991 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2993 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2995 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2998 /* There is no point inserting thread-specific breakpoints if
2999 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3000 has BL->OWNER always non-NULL. */
3001 if (bl
->owner
->thread
!= -1
3002 && !valid_global_thread_id (bl
->owner
->thread
))
3005 switch_to_program_space_and_thread (bl
->pspace
);
3007 /* For targets that support global breakpoints, there's no need
3008 to select an inferior to insert breakpoint to. In fact, even
3009 if we aren't attached to any process yet, we should still
3010 insert breakpoints. */
3011 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3012 && ptid_equal (inferior_ptid
, null_ptid
))
3015 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3016 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3021 /* If we failed to insert all locations of a watchpoint, remove
3022 them, as half-inserted watchpoint is of limited use. */
3023 ALL_BREAKPOINTS (bpt
)
3025 int some_failed
= 0;
3026 struct bp_location
*loc
;
3028 if (!is_hardware_watchpoint (bpt
))
3031 if (!breakpoint_enabled (bpt
))
3034 if (bpt
->disposition
== disp_del_at_next_stop
)
3037 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3038 if (!loc
->inserted
&& should_be_inserted (loc
))
3045 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3047 remove_breakpoint (loc
);
3049 hw_breakpoint_error
= 1;
3050 tmp_error_stream
.printf ("Could not insert "
3051 "hardware watchpoint %d.\n",
3059 /* If a hardware breakpoint or watchpoint was inserted, add a
3060 message about possibly exhausted resources. */
3061 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3063 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3064 You may have requested too many hardware breakpoints/watchpoints.\n");
3066 target_terminal::ours_for_output ();
3067 error_stream (tmp_error_stream
);
3071 /* Used when the program stops.
3072 Returns zero if successful, or non-zero if there was a problem
3073 removing a breakpoint location. */
3076 remove_breakpoints (void)
3078 struct bp_location
*bl
, **blp_tmp
;
3081 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3083 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3084 val
|= remove_breakpoint (bl
);
3089 /* When a thread exits, remove breakpoints that are related to
3093 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3095 struct breakpoint
*b
, *b_tmp
;
3097 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3099 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3101 b
->disposition
= disp_del_at_next_stop
;
3103 printf_filtered (_("\
3104 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3105 b
->number
, print_thread_id (tp
));
3107 /* Hide it from the user. */
3113 /* Remove breakpoints of process PID. */
3116 remove_breakpoints_pid (int pid
)
3118 struct bp_location
*bl
, **blp_tmp
;
3120 struct inferior
*inf
= find_inferior_pid (pid
);
3122 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3124 if (bl
->pspace
!= inf
->pspace
)
3127 if (bl
->inserted
&& !bl
->target_info
.persist
)
3129 val
= remove_breakpoint (bl
);
3137 static int internal_breakpoint_number
= -1;
3139 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3140 If INTERNAL is non-zero, the breakpoint number will be populated
3141 from internal_breakpoint_number and that variable decremented.
3142 Otherwise the breakpoint number will be populated from
3143 breakpoint_count and that value incremented. Internal breakpoints
3144 do not set the internal var bpnum. */
3146 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3149 b
->number
= internal_breakpoint_number
--;
3152 set_breakpoint_count (breakpoint_count
+ 1);
3153 b
->number
= breakpoint_count
;
3157 static struct breakpoint
*
3158 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3159 CORE_ADDR address
, enum bptype type
,
3160 const struct breakpoint_ops
*ops
)
3162 symtab_and_line sal
;
3164 sal
.section
= find_pc_overlay (sal
.pc
);
3165 sal
.pspace
= current_program_space
;
3167 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3168 b
->number
= internal_breakpoint_number
--;
3169 b
->disposition
= disp_donttouch
;
3174 static const char *const longjmp_names
[] =
3176 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3178 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3180 /* Per-objfile data private to breakpoint.c. */
3181 struct breakpoint_objfile_data
3183 /* Minimal symbol for "_ovly_debug_event" (if any). */
3184 struct bound_minimal_symbol overlay_msym
{};
3186 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3187 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3189 /* True if we have looked for longjmp probes. */
3190 int longjmp_searched
= 0;
3192 /* SystemTap probe points for longjmp (if any). These are non-owning
3194 std::vector
<probe
*> longjmp_probes
;
3196 /* Minimal symbol for "std::terminate()" (if any). */
3197 struct bound_minimal_symbol terminate_msym
{};
3199 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3200 struct bound_minimal_symbol exception_msym
{};
3202 /* True if we have looked for exception probes. */
3203 int exception_searched
= 0;
3205 /* SystemTap probe points for unwinding (if any). These are non-owning
3207 std::vector
<probe
*> exception_probes
;
3210 static const struct objfile_data
*breakpoint_objfile_key
;
3212 /* Minimal symbol not found sentinel. */
3213 static struct minimal_symbol msym_not_found
;
3215 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3218 msym_not_found_p (const struct minimal_symbol
*msym
)
3220 return msym
== &msym_not_found
;
3223 /* Return per-objfile data needed by breakpoint.c.
3224 Allocate the data if necessary. */
3226 static struct breakpoint_objfile_data
*
3227 get_breakpoint_objfile_data (struct objfile
*objfile
)
3229 struct breakpoint_objfile_data
*bp_objfile_data
;
3231 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3232 objfile_data (objfile
, breakpoint_objfile_key
));
3233 if (bp_objfile_data
== NULL
)
3235 bp_objfile_data
= new breakpoint_objfile_data ();
3236 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3238 return bp_objfile_data
;
3242 free_breakpoint_objfile_data (struct objfile
*obj
, void *data
)
3244 struct breakpoint_objfile_data
*bp_objfile_data
3245 = (struct breakpoint_objfile_data
*) data
;
3247 delete bp_objfile_data
;
3251 create_overlay_event_breakpoint (void)
3253 struct objfile
*objfile
;
3254 const char *const func_name
= "_ovly_debug_event";
3256 ALL_OBJFILES (objfile
)
3258 struct breakpoint
*b
;
3259 struct breakpoint_objfile_data
*bp_objfile_data
;
3261 struct explicit_location explicit_loc
;
3263 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3265 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3268 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3270 struct bound_minimal_symbol m
;
3272 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3273 if (m
.minsym
== NULL
)
3275 /* Avoid future lookups in this objfile. */
3276 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3279 bp_objfile_data
->overlay_msym
= m
;
3282 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3283 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3285 &internal_breakpoint_ops
);
3286 initialize_explicit_location (&explicit_loc
);
3287 explicit_loc
.function_name
= ASTRDUP (func_name
);
3288 b
->location
= new_explicit_location (&explicit_loc
);
3290 if (overlay_debugging
== ovly_auto
)
3292 b
->enable_state
= bp_enabled
;
3293 overlay_events_enabled
= 1;
3297 b
->enable_state
= bp_disabled
;
3298 overlay_events_enabled
= 0;
3304 create_longjmp_master_breakpoint (void)
3306 struct program_space
*pspace
;
3308 scoped_restore_current_program_space restore_pspace
;
3310 ALL_PSPACES (pspace
)
3312 struct objfile
*objfile
;
3314 set_current_program_space (pspace
);
3316 ALL_OBJFILES (objfile
)
3319 struct gdbarch
*gdbarch
;
3320 struct breakpoint_objfile_data
*bp_objfile_data
;
3322 gdbarch
= get_objfile_arch (objfile
);
3324 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3326 if (!bp_objfile_data
->longjmp_searched
)
3328 std::vector
<probe
*> ret
3329 = find_probes_in_objfile (objfile
, "libc", "longjmp");
3333 /* We are only interested in checking one element. */
3336 if (!can_evaluate_probe_arguments (p
))
3338 /* We cannot use the probe interface here, because it does
3339 not know how to evaluate arguments. */
3343 bp_objfile_data
->longjmp_probes
= ret
;
3344 bp_objfile_data
->longjmp_searched
= 1;
3347 if (!bp_objfile_data
->longjmp_probes
.empty ())
3349 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3351 for (probe
*p
: bp_objfile_data
->longjmp_probes
)
3353 struct breakpoint
*b
;
3355 b
= create_internal_breakpoint (gdbarch
,
3356 get_probe_address (p
, objfile
),
3358 &internal_breakpoint_ops
);
3359 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3360 b
->enable_state
= bp_disabled
;
3366 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3369 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3371 struct breakpoint
*b
;
3372 const char *func_name
;
3374 struct explicit_location explicit_loc
;
3376 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3379 func_name
= longjmp_names
[i
];
3380 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3382 struct bound_minimal_symbol m
;
3384 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3385 if (m
.minsym
== NULL
)
3387 /* Prevent future lookups in this objfile. */
3388 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3391 bp_objfile_data
->longjmp_msym
[i
] = m
;
3394 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3395 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3396 &internal_breakpoint_ops
);
3397 initialize_explicit_location (&explicit_loc
);
3398 explicit_loc
.function_name
= ASTRDUP (func_name
);
3399 b
->location
= new_explicit_location (&explicit_loc
);
3400 b
->enable_state
= bp_disabled
;
3406 /* Create a master std::terminate breakpoint. */
3408 create_std_terminate_master_breakpoint (void)
3410 struct program_space
*pspace
;
3411 const char *const func_name
= "std::terminate()";
3413 scoped_restore_current_program_space restore_pspace
;
3415 ALL_PSPACES (pspace
)
3417 struct objfile
*objfile
;
3420 set_current_program_space (pspace
);
3422 ALL_OBJFILES (objfile
)
3424 struct breakpoint
*b
;
3425 struct breakpoint_objfile_data
*bp_objfile_data
;
3426 struct explicit_location explicit_loc
;
3428 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3430 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3433 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3435 struct bound_minimal_symbol m
;
3437 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3438 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3439 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3441 /* Prevent future lookups in this objfile. */
3442 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3445 bp_objfile_data
->terminate_msym
= m
;
3448 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3449 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3450 bp_std_terminate_master
,
3451 &internal_breakpoint_ops
);
3452 initialize_explicit_location (&explicit_loc
);
3453 explicit_loc
.function_name
= ASTRDUP (func_name
);
3454 b
->location
= new_explicit_location (&explicit_loc
);
3455 b
->enable_state
= bp_disabled
;
3460 /* Install a master breakpoint on the unwinder's debug hook. */
3463 create_exception_master_breakpoint (void)
3465 struct objfile
*objfile
;
3466 const char *const func_name
= "_Unwind_DebugHook";
3468 ALL_OBJFILES (objfile
)
3470 struct breakpoint
*b
;
3471 struct gdbarch
*gdbarch
;
3472 struct breakpoint_objfile_data
*bp_objfile_data
;
3474 struct explicit_location explicit_loc
;
3476 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3478 /* We prefer the SystemTap probe point if it exists. */
3479 if (!bp_objfile_data
->exception_searched
)
3481 std::vector
<probe
*> ret
3482 = find_probes_in_objfile (objfile
, "libgcc", "unwind");
3486 /* We are only interested in checking one element. */
3489 if (!can_evaluate_probe_arguments (p
))
3491 /* We cannot use the probe interface here, because it does
3492 not know how to evaluate arguments. */
3496 bp_objfile_data
->exception_probes
= ret
;
3497 bp_objfile_data
->exception_searched
= 1;
3500 if (!bp_objfile_data
->exception_probes
.empty ())
3502 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3504 for (probe
*p
: bp_objfile_data
->exception_probes
)
3506 struct breakpoint
*b
;
3508 b
= create_internal_breakpoint (gdbarch
,
3509 get_probe_address (p
, objfile
),
3510 bp_exception_master
,
3511 &internal_breakpoint_ops
);
3512 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3513 b
->enable_state
= bp_disabled
;
3519 /* Otherwise, try the hook function. */
3521 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3524 gdbarch
= get_objfile_arch (objfile
);
3526 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3528 struct bound_minimal_symbol debug_hook
;
3530 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3531 if (debug_hook
.minsym
== NULL
)
3533 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3537 bp_objfile_data
->exception_msym
= debug_hook
;
3540 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3541 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3543 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3544 &internal_breakpoint_ops
);
3545 initialize_explicit_location (&explicit_loc
);
3546 explicit_loc
.function_name
= ASTRDUP (func_name
);
3547 b
->location
= new_explicit_location (&explicit_loc
);
3548 b
->enable_state
= bp_disabled
;
3552 /* Does B have a location spec? */
3555 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3557 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3561 update_breakpoints_after_exec (void)
3563 struct breakpoint
*b
, *b_tmp
;
3564 struct bp_location
*bploc
, **bplocp_tmp
;
3566 /* We're about to delete breakpoints from GDB's lists. If the
3567 INSERTED flag is true, GDB will try to lift the breakpoints by
3568 writing the breakpoints' "shadow contents" back into memory. The
3569 "shadow contents" are NOT valid after an exec, so GDB should not
3570 do that. Instead, the target is responsible from marking
3571 breakpoints out as soon as it detects an exec. We don't do that
3572 here instead, because there may be other attempts to delete
3573 breakpoints after detecting an exec and before reaching here. */
3574 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3575 if (bploc
->pspace
== current_program_space
)
3576 gdb_assert (!bploc
->inserted
);
3578 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3580 if (b
->pspace
!= current_program_space
)
3583 /* Solib breakpoints must be explicitly reset after an exec(). */
3584 if (b
->type
== bp_shlib_event
)
3586 delete_breakpoint (b
);
3590 /* JIT breakpoints must be explicitly reset after an exec(). */
3591 if (b
->type
== bp_jit_event
)
3593 delete_breakpoint (b
);
3597 /* Thread event breakpoints must be set anew after an exec(),
3598 as must overlay event and longjmp master breakpoints. */
3599 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3600 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3601 || b
->type
== bp_exception_master
)
3603 delete_breakpoint (b
);
3607 /* Step-resume breakpoints are meaningless after an exec(). */
3608 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3610 delete_breakpoint (b
);
3614 /* Just like single-step breakpoints. */
3615 if (b
->type
== bp_single_step
)
3617 delete_breakpoint (b
);
3621 /* Longjmp and longjmp-resume breakpoints are also meaningless
3623 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3624 || b
->type
== bp_longjmp_call_dummy
3625 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3627 delete_breakpoint (b
);
3631 if (b
->type
== bp_catchpoint
)
3633 /* For now, none of the bp_catchpoint breakpoints need to
3634 do anything at this point. In the future, if some of
3635 the catchpoints need to something, we will need to add
3636 a new method, and call this method from here. */
3640 /* bp_finish is a special case. The only way we ought to be able
3641 to see one of these when an exec() has happened, is if the user
3642 caught a vfork, and then said "finish". Ordinarily a finish just
3643 carries them to the call-site of the current callee, by setting
3644 a temporary bp there and resuming. But in this case, the finish
3645 will carry them entirely through the vfork & exec.
3647 We don't want to allow a bp_finish to remain inserted now. But
3648 we can't safely delete it, 'cause finish_command has a handle to
3649 the bp on a bpstat, and will later want to delete it. There's a
3650 chance (and I've seen it happen) that if we delete the bp_finish
3651 here, that its storage will get reused by the time finish_command
3652 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3653 We really must allow finish_command to delete a bp_finish.
3655 In the absence of a general solution for the "how do we know
3656 it's safe to delete something others may have handles to?"
3657 problem, what we'll do here is just uninsert the bp_finish, and
3658 let finish_command delete it.
3660 (We know the bp_finish is "doomed" in the sense that it's
3661 momentary, and will be deleted as soon as finish_command sees
3662 the inferior stopped. So it doesn't matter that the bp's
3663 address is probably bogus in the new a.out, unlike e.g., the
3664 solib breakpoints.) */
3666 if (b
->type
== bp_finish
)
3671 /* Without a symbolic address, we have little hope of the
3672 pre-exec() address meaning the same thing in the post-exec()
3674 if (breakpoint_event_location_empty_p (b
))
3676 delete_breakpoint (b
);
3683 detach_breakpoints (ptid_t ptid
)
3685 struct bp_location
*bl
, **blp_tmp
;
3687 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3688 struct inferior
*inf
= current_inferior ();
3690 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3691 error (_("Cannot detach breakpoints of inferior_ptid"));
3693 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3694 inferior_ptid
= ptid
;
3695 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3697 if (bl
->pspace
!= inf
->pspace
)
3700 /* This function must physically remove breakpoints locations
3701 from the specified ptid, without modifying the breakpoint
3702 package's state. Locations of type bp_loc_other are only
3703 maintained at GDB side. So, there is no need to remove
3704 these bp_loc_other locations. Moreover, removing these
3705 would modify the breakpoint package's state. */
3706 if (bl
->loc_type
== bp_loc_other
)
3710 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3716 /* Remove the breakpoint location BL from the current address space.
3717 Note that this is used to detach breakpoints from a child fork.
3718 When we get here, the child isn't in the inferior list, and neither
3719 do we have objects to represent its address space --- we should
3720 *not* look at bl->pspace->aspace here. */
3723 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3727 /* BL is never in moribund_locations by our callers. */
3728 gdb_assert (bl
->owner
!= NULL
);
3730 /* The type of none suggests that owner is actually deleted.
3731 This should not ever happen. */
3732 gdb_assert (bl
->owner
->type
!= bp_none
);
3734 if (bl
->loc_type
== bp_loc_software_breakpoint
3735 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3737 /* "Normal" instruction breakpoint: either the standard
3738 trap-instruction bp (bp_breakpoint), or a
3739 bp_hardware_breakpoint. */
3741 /* First check to see if we have to handle an overlay. */
3742 if (overlay_debugging
== ovly_off
3743 || bl
->section
== NULL
3744 || !(section_is_overlay (bl
->section
)))
3746 /* No overlay handling: just remove the breakpoint. */
3748 /* If we're trying to uninsert a memory breakpoint that we
3749 know is set in a dynamic object that is marked
3750 shlib_disabled, then either the dynamic object was
3751 removed with "remove-symbol-file" or with
3752 "nosharedlibrary". In the former case, we don't know
3753 whether another dynamic object might have loaded over the
3754 breakpoint's address -- the user might well let us know
3755 about it next with add-symbol-file (the whole point of
3756 add-symbol-file is letting the user manually maintain a
3757 list of dynamically loaded objects). If we have the
3758 breakpoint's shadow memory, that is, this is a software
3759 breakpoint managed by GDB, check whether the breakpoint
3760 is still inserted in memory, to avoid overwriting wrong
3761 code with stale saved shadow contents. Note that HW
3762 breakpoints don't have shadow memory, as they're
3763 implemented using a mechanism that is not dependent on
3764 being able to modify the target's memory, and as such
3765 they should always be removed. */
3766 if (bl
->shlib_disabled
3767 && bl
->target_info
.shadow_len
!= 0
3768 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3771 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3775 /* This breakpoint is in an overlay section.
3776 Did we set a breakpoint at the LMA? */
3777 if (!overlay_events_enabled
)
3779 /* Yes -- overlay event support is not active, so we
3780 should have set a breakpoint at the LMA. Remove it.
3782 /* Ignore any failures: if the LMA is in ROM, we will
3783 have already warned when we failed to insert it. */
3784 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3785 target_remove_hw_breakpoint (bl
->gdbarch
,
3786 &bl
->overlay_target_info
);
3788 target_remove_breakpoint (bl
->gdbarch
,
3789 &bl
->overlay_target_info
,
3792 /* Did we set a breakpoint at the VMA?
3793 If so, we will have marked the breakpoint 'inserted'. */
3796 /* Yes -- remove it. Previously we did not bother to
3797 remove the breakpoint if the section had been
3798 unmapped, but let's not rely on that being safe. We
3799 don't know what the overlay manager might do. */
3801 /* However, we should remove *software* breakpoints only
3802 if the section is still mapped, or else we overwrite
3803 wrong code with the saved shadow contents. */
3804 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3805 || section_is_mapped (bl
->section
))
3806 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3812 /* No -- not inserted, so no need to remove. No error. */
3817 /* In some cases, we might not be able to remove a breakpoint in
3818 a shared library that has already been removed, but we have
3819 not yet processed the shlib unload event. Similarly for an
3820 unloaded add-symbol-file object - the user might not yet have
3821 had the chance to remove-symbol-file it. shlib_disabled will
3822 be set if the library/object has already been removed, but
3823 the breakpoint hasn't been uninserted yet, e.g., after
3824 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3825 always-inserted mode. */
3827 && (bl
->loc_type
== bp_loc_software_breakpoint
3828 && (bl
->shlib_disabled
3829 || solib_name_from_address (bl
->pspace
, bl
->address
)
3830 || shared_objfile_contains_address_p (bl
->pspace
,
3836 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3838 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3840 gdb_assert (bl
->owner
->ops
!= NULL
3841 && bl
->owner
->ops
->remove_location
!= NULL
);
3843 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3844 bl
->owner
->ops
->remove_location (bl
, reason
);
3846 /* Failure to remove any of the hardware watchpoints comes here. */
3847 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3848 warning (_("Could not remove hardware watchpoint %d."),
3851 else if (bl
->owner
->type
== bp_catchpoint
3852 && breakpoint_enabled (bl
->owner
)
3855 gdb_assert (bl
->owner
->ops
!= NULL
3856 && bl
->owner
->ops
->remove_location
!= NULL
);
3858 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3862 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3869 remove_breakpoint (struct bp_location
*bl
)
3871 /* BL is never in moribund_locations by our callers. */
3872 gdb_assert (bl
->owner
!= NULL
);
3874 /* The type of none suggests that owner is actually deleted.
3875 This should not ever happen. */
3876 gdb_assert (bl
->owner
->type
!= bp_none
);
3878 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3880 switch_to_program_space_and_thread (bl
->pspace
);
3882 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3885 /* Clear the "inserted" flag in all breakpoints. */
3888 mark_breakpoints_out (void)
3890 struct bp_location
*bl
, **blp_tmp
;
3892 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3893 if (bl
->pspace
== current_program_space
)
3897 /* Clear the "inserted" flag in all breakpoints and delete any
3898 breakpoints which should go away between runs of the program.
3900 Plus other such housekeeping that has to be done for breakpoints
3903 Note: this function gets called at the end of a run (by
3904 generic_mourn_inferior) and when a run begins (by
3905 init_wait_for_inferior). */
3910 breakpoint_init_inferior (enum inf_context context
)
3912 struct breakpoint
*b
, *b_tmp
;
3913 struct bp_location
*bl
;
3915 struct program_space
*pspace
= current_program_space
;
3917 /* If breakpoint locations are shared across processes, then there's
3919 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3922 mark_breakpoints_out ();
3924 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3926 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3932 case bp_longjmp_call_dummy
:
3934 /* If the call dummy breakpoint is at the entry point it will
3935 cause problems when the inferior is rerun, so we better get
3938 case bp_watchpoint_scope
:
3940 /* Also get rid of scope breakpoints. */
3942 case bp_shlib_event
:
3944 /* Also remove solib event breakpoints. Their addresses may
3945 have changed since the last time we ran the program.
3946 Actually we may now be debugging against different target;
3947 and so the solib backend that installed this breakpoint may
3948 not be used in by the target. E.g.,
3950 (gdb) file prog-linux
3951 (gdb) run # native linux target
3954 (gdb) file prog-win.exe
3955 (gdb) tar rem :9999 # remote Windows gdbserver.
3958 case bp_step_resume
:
3960 /* Also remove step-resume breakpoints. */
3962 case bp_single_step
:
3964 /* Also remove single-step breakpoints. */
3966 delete_breakpoint (b
);
3970 case bp_hardware_watchpoint
:
3971 case bp_read_watchpoint
:
3972 case bp_access_watchpoint
:
3974 struct watchpoint
*w
= (struct watchpoint
*) b
;
3976 /* Likewise for watchpoints on local expressions. */
3977 if (w
->exp_valid_block
!= NULL
)
3978 delete_breakpoint (b
);
3981 /* Get rid of existing locations, which are no longer
3982 valid. New ones will be created in
3983 update_watchpoint, when the inferior is restarted.
3984 The next update_global_location_list call will
3985 garbage collect them. */
3988 if (context
== inf_starting
)
3990 /* Reset val field to force reread of starting value in
3991 insert_breakpoints. */
3993 value_free (w
->val
);
4005 /* Get rid of the moribund locations. */
4006 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4007 decref_bp_location (&bl
);
4008 VEC_free (bp_location_p
, moribund_locations
);
4011 /* These functions concern about actual breakpoints inserted in the
4012 target --- to e.g. check if we need to do decr_pc adjustment or if
4013 we need to hop over the bkpt --- so we check for address space
4014 match, not program space. */
4016 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4017 exists at PC. It returns ordinary_breakpoint_here if it's an
4018 ordinary breakpoint, or permanent_breakpoint_here if it's a
4019 permanent breakpoint.
4020 - When continuing from a location with an ordinary breakpoint, we
4021 actually single step once before calling insert_breakpoints.
4022 - When continuing from a location with a permanent breakpoint, we
4023 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4024 the target, to advance the PC past the breakpoint. */
4026 enum breakpoint_here
4027 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4029 struct bp_location
*bl
, **blp_tmp
;
4030 int any_breakpoint_here
= 0;
4032 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4034 if (bl
->loc_type
!= bp_loc_software_breakpoint
4035 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4038 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4039 if ((breakpoint_enabled (bl
->owner
)
4041 && breakpoint_location_address_match (bl
, aspace
, pc
))
4043 if (overlay_debugging
4044 && section_is_overlay (bl
->section
)
4045 && !section_is_mapped (bl
->section
))
4046 continue; /* unmapped overlay -- can't be a match */
4047 else if (bl
->permanent
)
4048 return permanent_breakpoint_here
;
4050 any_breakpoint_here
= 1;
4054 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4057 /* See breakpoint.h. */
4060 breakpoint_in_range_p (const address_space
*aspace
,
4061 CORE_ADDR addr
, ULONGEST len
)
4063 struct bp_location
*bl
, **blp_tmp
;
4065 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4067 if (bl
->loc_type
!= bp_loc_software_breakpoint
4068 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4071 if ((breakpoint_enabled (bl
->owner
)
4073 && breakpoint_location_address_range_overlap (bl
, aspace
,
4076 if (overlay_debugging
4077 && section_is_overlay (bl
->section
)
4078 && !section_is_mapped (bl
->section
))
4080 /* Unmapped overlay -- can't be a match. */
4091 /* Return true if there's a moribund breakpoint at PC. */
4094 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4096 struct bp_location
*loc
;
4099 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4100 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4106 /* Returns non-zero iff BL is inserted at PC, in address space
4110 bp_location_inserted_here_p (struct bp_location
*bl
,
4111 const address_space
*aspace
, CORE_ADDR pc
)
4114 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4117 if (overlay_debugging
4118 && section_is_overlay (bl
->section
)
4119 && !section_is_mapped (bl
->section
))
4120 return 0; /* unmapped overlay -- can't be a match */
4127 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4130 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4132 struct bp_location
**blp
, **blp_tmp
= NULL
;
4134 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4136 struct bp_location
*bl
= *blp
;
4138 if (bl
->loc_type
!= bp_loc_software_breakpoint
4139 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4142 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4148 /* This function returns non-zero iff there is a software breakpoint
4152 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4155 struct bp_location
**blp
, **blp_tmp
= NULL
;
4157 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4159 struct bp_location
*bl
= *blp
;
4161 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4164 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4171 /* See breakpoint.h. */
4174 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4177 struct bp_location
**blp
, **blp_tmp
= NULL
;
4179 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4181 struct bp_location
*bl
= *blp
;
4183 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4186 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4194 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4195 CORE_ADDR addr
, ULONGEST len
)
4197 struct breakpoint
*bpt
;
4199 ALL_BREAKPOINTS (bpt
)
4201 struct bp_location
*loc
;
4203 if (bpt
->type
!= bp_hardware_watchpoint
4204 && bpt
->type
!= bp_access_watchpoint
)
4207 if (!breakpoint_enabled (bpt
))
4210 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4211 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4215 /* Check for intersection. */
4216 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4217 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4226 /* bpstat stuff. External routines' interfaces are documented
4230 is_catchpoint (struct breakpoint
*ep
)
4232 return (ep
->type
== bp_catchpoint
);
4235 /* Frees any storage that is part of a bpstat. Does not walk the
4238 bpstats::~bpstats ()
4240 if (old_val
!= NULL
)
4241 value_free (old_val
);
4242 if (bp_location_at
!= NULL
)
4243 decref_bp_location (&bp_location_at
);
4246 /* Clear a bpstat so that it says we are not at any breakpoint.
4247 Also free any storage that is part of a bpstat. */
4250 bpstat_clear (bpstat
*bsp
)
4267 bpstats::bpstats (const bpstats
&other
)
4269 bp_location_at (other
.bp_location_at
),
4270 breakpoint_at (other
.breakpoint_at
),
4271 commands (other
.commands
),
4272 old_val (other
.old_val
),
4273 print (other
.print
),
4275 print_it (other
.print_it
)
4277 if (old_val
!= NULL
)
4279 old_val
= value_copy (old_val
);
4280 release_value (old_val
);
4282 incref_bp_location (bp_location_at
);
4285 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4286 is part of the bpstat is copied as well. */
4289 bpstat_copy (bpstat bs
)
4293 bpstat retval
= NULL
;
4298 for (; bs
!= NULL
; bs
= bs
->next
)
4300 tmp
= new bpstats (*bs
);
4303 /* This is the first thing in the chain. */
4313 /* Find the bpstat associated with this breakpoint. */
4316 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4321 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4323 if (bsp
->breakpoint_at
== breakpoint
)
4329 /* See breakpoint.h. */
4332 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4334 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4336 if (bsp
->breakpoint_at
== NULL
)
4338 /* A moribund location can never explain a signal other than
4340 if (sig
== GDB_SIGNAL_TRAP
)
4345 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4354 /* Put in *NUM the breakpoint number of the first breakpoint we are
4355 stopped at. *BSP upon return is a bpstat which points to the
4356 remaining breakpoints stopped at (but which is not guaranteed to be
4357 good for anything but further calls to bpstat_num).
4359 Return 0 if passed a bpstat which does not indicate any breakpoints.
4360 Return -1 if stopped at a breakpoint that has been deleted since
4362 Return 1 otherwise. */
4365 bpstat_num (bpstat
*bsp
, int *num
)
4367 struct breakpoint
*b
;
4370 return 0; /* No more breakpoint values */
4372 /* We assume we'll never have several bpstats that correspond to a
4373 single breakpoint -- otherwise, this function might return the
4374 same number more than once and this will look ugly. */
4375 b
= (*bsp
)->breakpoint_at
;
4376 *bsp
= (*bsp
)->next
;
4378 return -1; /* breakpoint that's been deleted since */
4380 *num
= b
->number
; /* We have its number */
4384 /* See breakpoint.h. */
4387 bpstat_clear_actions (void)
4389 struct thread_info
*tp
;
4392 if (ptid_equal (inferior_ptid
, null_ptid
))
4395 tp
= find_thread_ptid (inferior_ptid
);
4399 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4401 bs
->commands
= NULL
;
4403 if (bs
->old_val
!= NULL
)
4405 value_free (bs
->old_val
);
4411 /* Called when a command is about to proceed the inferior. */
4414 breakpoint_about_to_proceed (void)
4416 if (!ptid_equal (inferior_ptid
, null_ptid
))
4418 struct thread_info
*tp
= inferior_thread ();
4420 /* Allow inferior function calls in breakpoint commands to not
4421 interrupt the command list. When the call finishes
4422 successfully, the inferior will be standing at the same
4423 breakpoint as if nothing happened. */
4424 if (tp
->control
.in_infcall
)
4428 breakpoint_proceeded
= 1;
4431 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4432 or its equivalent. */
4435 command_line_is_silent (struct command_line
*cmd
)
4437 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4440 /* Execute all the commands associated with all the breakpoints at
4441 this location. Any of these commands could cause the process to
4442 proceed beyond this point, etc. We look out for such changes by
4443 checking the global "breakpoint_proceeded" after each command.
4445 Returns true if a breakpoint command resumed the inferior. In that
4446 case, it is the caller's responsibility to recall it again with the
4447 bpstat of the current thread. */
4450 bpstat_do_actions_1 (bpstat
*bsp
)
4455 /* Avoid endless recursion if a `source' command is contained
4457 if (executing_breakpoint_commands
)
4460 scoped_restore save_executing
4461 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4463 scoped_restore preventer
= prevent_dont_repeat ();
4465 /* This pointer will iterate over the list of bpstat's. */
4468 breakpoint_proceeded
= 0;
4469 for (; bs
!= NULL
; bs
= bs
->next
)
4471 struct command_line
*cmd
= NULL
;
4473 /* Take ownership of the BSP's command tree, if it has one.
4475 The command tree could legitimately contain commands like
4476 'step' and 'next', which call clear_proceed_status, which
4477 frees stop_bpstat's command tree. To make sure this doesn't
4478 free the tree we're executing out from under us, we need to
4479 take ownership of the tree ourselves. Since a given bpstat's
4480 commands are only executed once, we don't need to copy it; we
4481 can clear the pointer in the bpstat, and make sure we free
4482 the tree when we're done. */
4483 counted_command_line ccmd
= bs
->commands
;
4484 bs
->commands
= NULL
;
4487 if (command_line_is_silent (cmd
))
4489 /* The action has been already done by bpstat_stop_status. */
4495 execute_control_command (cmd
);
4497 if (breakpoint_proceeded
)
4503 if (breakpoint_proceeded
)
4505 if (current_ui
->async
)
4506 /* If we are in async mode, then the target might be still
4507 running, not stopped at any breakpoint, so nothing for
4508 us to do here -- just return to the event loop. */
4511 /* In sync mode, when execute_control_command returns
4512 we're already standing on the next breakpoint.
4513 Breakpoint commands for that stop were not run, since
4514 execute_command does not run breakpoint commands --
4515 only command_line_handler does, but that one is not
4516 involved in execution of breakpoint commands. So, we
4517 can now execute breakpoint commands. It should be
4518 noted that making execute_command do bpstat actions is
4519 not an option -- in this case we'll have recursive
4520 invocation of bpstat for each breakpoint with a
4521 command, and can easily blow up GDB stack. Instead, we
4522 return true, which will trigger the caller to recall us
4523 with the new stop_bpstat. */
4532 bpstat_do_actions (void)
4534 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4536 /* Do any commands attached to breakpoint we are stopped at. */
4537 while (!ptid_equal (inferior_ptid
, null_ptid
)
4538 && target_has_execution
4539 && !is_exited (inferior_ptid
)
4540 && !is_executing (inferior_ptid
))
4541 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4542 and only return when it is stopped at the next breakpoint, we
4543 keep doing breakpoint actions until it returns false to
4544 indicate the inferior was not resumed. */
4545 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4548 discard_cleanups (cleanup_if_error
);
4551 /* Print out the (old or new) value associated with a watchpoint. */
4554 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4557 fprintf_unfiltered (stream
, _("<unreadable>"));
4560 struct value_print_options opts
;
4561 get_user_print_options (&opts
);
4562 value_print (val
, stream
, &opts
);
4566 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4567 debugging multiple threads. */
4570 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4572 if (uiout
->is_mi_like_p ())
4577 if (show_thread_that_caused_stop ())
4580 struct thread_info
*thr
= inferior_thread ();
4582 uiout
->text ("Thread ");
4583 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4585 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4588 uiout
->text (" \"");
4589 uiout
->field_fmt ("name", "%s", name
);
4593 uiout
->text (" hit ");
4597 /* Generic routine for printing messages indicating why we
4598 stopped. The behavior of this function depends on the value
4599 'print_it' in the bpstat structure. Under some circumstances we
4600 may decide not to print anything here and delegate the task to
4603 static enum print_stop_action
4604 print_bp_stop_message (bpstat bs
)
4606 switch (bs
->print_it
)
4609 /* Nothing should be printed for this bpstat entry. */
4610 return PRINT_UNKNOWN
;
4614 /* We still want to print the frame, but we already printed the
4615 relevant messages. */
4616 return PRINT_SRC_AND_LOC
;
4619 case print_it_normal
:
4621 struct breakpoint
*b
= bs
->breakpoint_at
;
4623 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4624 which has since been deleted. */
4626 return PRINT_UNKNOWN
;
4628 /* Normal case. Call the breakpoint's print_it method. */
4629 return b
->ops
->print_it (bs
);
4634 internal_error (__FILE__
, __LINE__
,
4635 _("print_bp_stop_message: unrecognized enum value"));
4640 /* A helper function that prints a shared library stopped event. */
4643 print_solib_event (int is_catchpoint
)
4646 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4648 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4652 if (any_added
|| any_deleted
)
4653 current_uiout
->text (_("Stopped due to shared library event:\n"));
4655 current_uiout
->text (_("Stopped due to shared library event (no "
4656 "libraries added or removed)\n"));
4659 if (current_uiout
->is_mi_like_p ())
4660 current_uiout
->field_string ("reason",
4661 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4668 current_uiout
->text (_(" Inferior unloaded "));
4669 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4671 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4676 current_uiout
->text (" ");
4677 current_uiout
->field_string ("library", name
);
4678 current_uiout
->text ("\n");
4684 struct so_list
*iter
;
4687 current_uiout
->text (_(" Inferior loaded "));
4688 ui_out_emit_list
list_emitter (current_uiout
, "added");
4690 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4695 current_uiout
->text (" ");
4696 current_uiout
->field_string ("library", iter
->so_name
);
4697 current_uiout
->text ("\n");
4702 /* Print a message indicating what happened. This is called from
4703 normal_stop(). The input to this routine is the head of the bpstat
4704 list - a list of the eventpoints that caused this stop. KIND is
4705 the target_waitkind for the stopping event. This
4706 routine calls the generic print routine for printing a message
4707 about reasons for stopping. This will print (for example) the
4708 "Breakpoint n," part of the output. The return value of this
4711 PRINT_UNKNOWN: Means we printed nothing.
4712 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4713 code to print the location. An example is
4714 "Breakpoint 1, " which should be followed by
4716 PRINT_SRC_ONLY: Means we printed something, but there is no need
4717 to also print the location part of the message.
4718 An example is the catch/throw messages, which
4719 don't require a location appended to the end.
4720 PRINT_NOTHING: We have done some printing and we don't need any
4721 further info to be printed. */
4723 enum print_stop_action
4724 bpstat_print (bpstat bs
, int kind
)
4726 enum print_stop_action val
;
4728 /* Maybe another breakpoint in the chain caused us to stop.
4729 (Currently all watchpoints go on the bpstat whether hit or not.
4730 That probably could (should) be changed, provided care is taken
4731 with respect to bpstat_explains_signal). */
4732 for (; bs
; bs
= bs
->next
)
4734 val
= print_bp_stop_message (bs
);
4735 if (val
== PRINT_SRC_ONLY
4736 || val
== PRINT_SRC_AND_LOC
4737 || val
== PRINT_NOTHING
)
4741 /* If we had hit a shared library event breakpoint,
4742 print_bp_stop_message would print out this message. If we hit an
4743 OS-level shared library event, do the same thing. */
4744 if (kind
== TARGET_WAITKIND_LOADED
)
4746 print_solib_event (0);
4747 return PRINT_NOTHING
;
4750 /* We reached the end of the chain, or we got a null BS to start
4751 with and nothing was printed. */
4752 return PRINT_UNKNOWN
;
4755 /* Evaluate the boolean expression EXP and return the result. */
4758 breakpoint_cond_eval (expression
*exp
)
4760 struct value
*mark
= value_mark ();
4761 bool res
= value_true (evaluate_expression (exp
));
4763 value_free_to_mark (mark
);
4767 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4769 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4771 bp_location_at (bl
),
4772 breakpoint_at (bl
->owner
),
4777 print_it (print_it_normal
)
4779 incref_bp_location (bl
);
4780 **bs_link_pointer
= this;
4781 *bs_link_pointer
= &next
;
4786 bp_location_at (NULL
),
4787 breakpoint_at (NULL
),
4792 print_it (print_it_normal
)
4796 /* The target has stopped with waitstatus WS. Check if any hardware
4797 watchpoints have triggered, according to the target. */
4800 watchpoints_triggered (struct target_waitstatus
*ws
)
4802 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4804 struct breakpoint
*b
;
4806 if (!stopped_by_watchpoint
)
4808 /* We were not stopped by a watchpoint. Mark all watchpoints
4809 as not triggered. */
4811 if (is_hardware_watchpoint (b
))
4813 struct watchpoint
*w
= (struct watchpoint
*) b
;
4815 w
->watchpoint_triggered
= watch_triggered_no
;
4821 if (!target_stopped_data_address (¤t_target
, &addr
))
4823 /* We were stopped by a watchpoint, but we don't know where.
4824 Mark all watchpoints as unknown. */
4826 if (is_hardware_watchpoint (b
))
4828 struct watchpoint
*w
= (struct watchpoint
*) b
;
4830 w
->watchpoint_triggered
= watch_triggered_unknown
;
4836 /* The target could report the data address. Mark watchpoints
4837 affected by this data address as triggered, and all others as not
4841 if (is_hardware_watchpoint (b
))
4843 struct watchpoint
*w
= (struct watchpoint
*) b
;
4844 struct bp_location
*loc
;
4846 w
->watchpoint_triggered
= watch_triggered_no
;
4847 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4849 if (is_masked_watchpoint (b
))
4851 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4852 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4854 if (newaddr
== start
)
4856 w
->watchpoint_triggered
= watch_triggered_yes
;
4860 /* Exact match not required. Within range is sufficient. */
4861 else if (target_watchpoint_addr_within_range (¤t_target
,
4865 w
->watchpoint_triggered
= watch_triggered_yes
;
4874 /* Possible return values for watchpoint_check. */
4875 enum wp_check_result
4877 /* The watchpoint has been deleted. */
4880 /* The value has changed. */
4881 WP_VALUE_CHANGED
= 2,
4883 /* The value has not changed. */
4884 WP_VALUE_NOT_CHANGED
= 3,
4886 /* Ignore this watchpoint, no matter if the value changed or not. */
4890 #define BP_TEMPFLAG 1
4891 #define BP_HARDWAREFLAG 2
4893 /* Evaluate watchpoint condition expression and check if its value
4896 static wp_check_result
4897 watchpoint_check (bpstat bs
)
4899 struct watchpoint
*b
;
4900 struct frame_info
*fr
;
4901 int within_current_scope
;
4903 /* BS is built from an existing struct breakpoint. */
4904 gdb_assert (bs
->breakpoint_at
!= NULL
);
4905 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4907 /* If this is a local watchpoint, we only want to check if the
4908 watchpoint frame is in scope if the current thread is the thread
4909 that was used to create the watchpoint. */
4910 if (!watchpoint_in_thread_scope (b
))
4913 if (b
->exp_valid_block
== NULL
)
4914 within_current_scope
= 1;
4917 struct frame_info
*frame
= get_current_frame ();
4918 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4919 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4921 /* stack_frame_destroyed_p() returns a non-zero value if we're
4922 still in the function but the stack frame has already been
4923 invalidated. Since we can't rely on the values of local
4924 variables after the stack has been destroyed, we are treating
4925 the watchpoint in that state as `not changed' without further
4926 checking. Don't mark watchpoints as changed if the current
4927 frame is in an epilogue - even if they are in some other
4928 frame, our view of the stack is likely to be wrong and
4929 frame_find_by_id could error out. */
4930 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4933 fr
= frame_find_by_id (b
->watchpoint_frame
);
4934 within_current_scope
= (fr
!= NULL
);
4936 /* If we've gotten confused in the unwinder, we might have
4937 returned a frame that can't describe this variable. */
4938 if (within_current_scope
)
4940 struct symbol
*function
;
4942 function
= get_frame_function (fr
);
4943 if (function
== NULL
4944 || !contained_in (b
->exp_valid_block
,
4945 SYMBOL_BLOCK_VALUE (function
)))
4946 within_current_scope
= 0;
4949 if (within_current_scope
)
4950 /* If we end up stopping, the current frame will get selected
4951 in normal_stop. So this call to select_frame won't affect
4956 if (within_current_scope
)
4958 /* We use value_{,free_to_}mark because it could be a *long*
4959 time before we return to the command level and call
4960 free_all_values. We can't call free_all_values because we
4961 might be in the middle of evaluating a function call. */
4965 struct value
*new_val
;
4967 if (is_masked_watchpoint (b
))
4968 /* Since we don't know the exact trigger address (from
4969 stopped_data_address), just tell the user we've triggered
4970 a mask watchpoint. */
4971 return WP_VALUE_CHANGED
;
4973 mark
= value_mark ();
4974 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
4976 if (b
->val_bitsize
!= 0)
4977 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4979 /* We use value_equal_contents instead of value_equal because
4980 the latter coerces an array to a pointer, thus comparing just
4981 the address of the array instead of its contents. This is
4982 not what we want. */
4983 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
4984 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
4986 if (new_val
!= NULL
)
4988 release_value (new_val
);
4989 value_free_to_mark (mark
);
4991 bs
->old_val
= b
->val
;
4994 return WP_VALUE_CHANGED
;
4998 /* Nothing changed. */
4999 value_free_to_mark (mark
);
5000 return WP_VALUE_NOT_CHANGED
;
5005 /* This seems like the only logical thing to do because
5006 if we temporarily ignored the watchpoint, then when
5007 we reenter the block in which it is valid it contains
5008 garbage (in the case of a function, it may have two
5009 garbage values, one before and one after the prologue).
5010 So we can't even detect the first assignment to it and
5011 watch after that (since the garbage may or may not equal
5012 the first value assigned). */
5013 /* We print all the stop information in
5014 breakpoint_ops->print_it, but in this case, by the time we
5015 call breakpoint_ops->print_it this bp will be deleted
5016 already. So we have no choice but print the information
5019 SWITCH_THRU_ALL_UIS ()
5021 struct ui_out
*uiout
= current_uiout
;
5023 if (uiout
->is_mi_like_p ())
5025 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5026 uiout
->text ("\nWatchpoint ");
5027 uiout
->field_int ("wpnum", b
->number
);
5028 uiout
->text (" deleted because the program has left the block in\n"
5029 "which its expression is valid.\n");
5032 /* Make sure the watchpoint's commands aren't executed. */
5034 watchpoint_del_at_next_stop (b
);
5040 /* Return true if it looks like target has stopped due to hitting
5041 breakpoint location BL. This function does not check if we should
5042 stop, only if BL explains the stop. */
5045 bpstat_check_location (const struct bp_location
*bl
,
5046 const address_space
*aspace
, CORE_ADDR bp_addr
,
5047 const struct target_waitstatus
*ws
)
5049 struct breakpoint
*b
= bl
->owner
;
5051 /* BL is from an existing breakpoint. */
5052 gdb_assert (b
!= NULL
);
5054 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5057 /* Determine if the watched values have actually changed, and we
5058 should stop. If not, set BS->stop to 0. */
5061 bpstat_check_watchpoint (bpstat bs
)
5063 const struct bp_location
*bl
;
5064 struct watchpoint
*b
;
5066 /* BS is built for existing struct breakpoint. */
5067 bl
= bs
->bp_location_at
;
5068 gdb_assert (bl
!= NULL
);
5069 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5070 gdb_assert (b
!= NULL
);
5073 int must_check_value
= 0;
5075 if (b
->type
== bp_watchpoint
)
5076 /* For a software watchpoint, we must always check the
5078 must_check_value
= 1;
5079 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5080 /* We have a hardware watchpoint (read, write, or access)
5081 and the target earlier reported an address watched by
5083 must_check_value
= 1;
5084 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5085 && b
->type
== bp_hardware_watchpoint
)
5086 /* We were stopped by a hardware watchpoint, but the target could
5087 not report the data address. We must check the watchpoint's
5088 value. Access and read watchpoints are out of luck; without
5089 a data address, we can't figure it out. */
5090 must_check_value
= 1;
5092 if (must_check_value
)
5098 e
= watchpoint_check (bs
);
5100 CATCH (ex
, RETURN_MASK_ALL
)
5102 exception_fprintf (gdb_stderr
, ex
,
5103 "Error evaluating expression "
5104 "for watchpoint %d\n",
5107 SWITCH_THRU_ALL_UIS ()
5109 printf_filtered (_("Watchpoint %d deleted.\n"),
5112 watchpoint_del_at_next_stop (b
);
5120 /* We've already printed what needs to be printed. */
5121 bs
->print_it
= print_it_done
;
5125 bs
->print_it
= print_it_noop
;
5128 case WP_VALUE_CHANGED
:
5129 if (b
->type
== bp_read_watchpoint
)
5131 /* There are two cases to consider here:
5133 1. We're watching the triggered memory for reads.
5134 In that case, trust the target, and always report
5135 the watchpoint hit to the user. Even though
5136 reads don't cause value changes, the value may
5137 have changed since the last time it was read, and
5138 since we're not trapping writes, we will not see
5139 those, and as such we should ignore our notion of
5142 2. We're watching the triggered memory for both
5143 reads and writes. There are two ways this may
5146 2.1. This is a target that can't break on data
5147 reads only, but can break on accesses (reads or
5148 writes), such as e.g., x86. We detect this case
5149 at the time we try to insert read watchpoints.
5151 2.2. Otherwise, the target supports read
5152 watchpoints, but, the user set an access or write
5153 watchpoint watching the same memory as this read
5156 If we're watching memory writes as well as reads,
5157 ignore watchpoint hits when we find that the
5158 value hasn't changed, as reads don't cause
5159 changes. This still gives false positives when
5160 the program writes the same value to memory as
5161 what there was already in memory (we will confuse
5162 it for a read), but it's much better than
5165 int other_write_watchpoint
= 0;
5167 if (bl
->watchpoint_type
== hw_read
)
5169 struct breakpoint
*other_b
;
5171 ALL_BREAKPOINTS (other_b
)
5172 if (other_b
->type
== bp_hardware_watchpoint
5173 || other_b
->type
== bp_access_watchpoint
)
5175 struct watchpoint
*other_w
=
5176 (struct watchpoint
*) other_b
;
5178 if (other_w
->watchpoint_triggered
5179 == watch_triggered_yes
)
5181 other_write_watchpoint
= 1;
5187 if (other_write_watchpoint
5188 || bl
->watchpoint_type
== hw_access
)
5190 /* We're watching the same memory for writes,
5191 and the value changed since the last time we
5192 updated it, so this trap must be for a write.
5194 bs
->print_it
= print_it_noop
;
5199 case WP_VALUE_NOT_CHANGED
:
5200 if (b
->type
== bp_hardware_watchpoint
5201 || b
->type
== bp_watchpoint
)
5203 /* Don't stop: write watchpoints shouldn't fire if
5204 the value hasn't changed. */
5205 bs
->print_it
= print_it_noop
;
5215 else /* must_check_value == 0 */
5217 /* This is a case where some watchpoint(s) triggered, but
5218 not at the address of this watchpoint, or else no
5219 watchpoint triggered after all. So don't print
5220 anything for this watchpoint. */
5221 bs
->print_it
= print_it_noop
;
5227 /* For breakpoints that are currently marked as telling gdb to stop,
5228 check conditions (condition proper, frame, thread and ignore count)
5229 of breakpoint referred to by BS. If we should not stop for this
5230 breakpoint, set BS->stop to 0. */
5233 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5235 const struct bp_location
*bl
;
5236 struct breakpoint
*b
;
5238 bool condition_result
= true;
5239 struct expression
*cond
;
5241 gdb_assert (bs
->stop
);
5243 /* BS is built for existing struct breakpoint. */
5244 bl
= bs
->bp_location_at
;
5245 gdb_assert (bl
!= NULL
);
5246 b
= bs
->breakpoint_at
;
5247 gdb_assert (b
!= NULL
);
5249 /* Even if the target evaluated the condition on its end and notified GDB, we
5250 need to do so again since GDB does not know if we stopped due to a
5251 breakpoint or a single step breakpoint. */
5253 if (frame_id_p (b
->frame_id
)
5254 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5260 /* If this is a thread/task-specific breakpoint, don't waste cpu
5261 evaluating the condition if this isn't the specified
5263 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5264 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5271 /* Evaluate extension language breakpoints that have a "stop" method
5273 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5275 if (is_watchpoint (b
))
5277 struct watchpoint
*w
= (struct watchpoint
*) b
;
5279 cond
= w
->cond_exp
.get ();
5282 cond
= bl
->cond
.get ();
5284 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5286 int within_current_scope
= 1;
5287 struct watchpoint
* w
;
5289 /* We use value_mark and value_free_to_mark because it could
5290 be a long time before we return to the command level and
5291 call free_all_values. We can't call free_all_values
5292 because we might be in the middle of evaluating a
5294 struct value
*mark
= value_mark ();
5296 if (is_watchpoint (b
))
5297 w
= (struct watchpoint
*) b
;
5301 /* Need to select the frame, with all that implies so that
5302 the conditions will have the right context. Because we
5303 use the frame, we will not see an inlined function's
5304 variables when we arrive at a breakpoint at the start
5305 of the inlined function; the current frame will be the
5307 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5308 select_frame (get_current_frame ());
5311 struct frame_info
*frame
;
5313 /* For local watchpoint expressions, which particular
5314 instance of a local is being watched matters, so we
5315 keep track of the frame to evaluate the expression
5316 in. To evaluate the condition however, it doesn't
5317 really matter which instantiation of the function
5318 where the condition makes sense triggers the
5319 watchpoint. This allows an expression like "watch
5320 global if q > 10" set in `func', catch writes to
5321 global on all threads that call `func', or catch
5322 writes on all recursive calls of `func' by a single
5323 thread. We simply always evaluate the condition in
5324 the innermost frame that's executing where it makes
5325 sense to evaluate the condition. It seems
5327 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5329 select_frame (frame
);
5331 within_current_scope
= 0;
5333 if (within_current_scope
)
5337 condition_result
= breakpoint_cond_eval (cond
);
5339 CATCH (ex
, RETURN_MASK_ALL
)
5341 exception_fprintf (gdb_stderr
, ex
,
5342 "Error in testing breakpoint condition:\n");
5348 warning (_("Watchpoint condition cannot be tested "
5349 "in the current scope"));
5350 /* If we failed to set the right context for this
5351 watchpoint, unconditionally report it. */
5353 /* FIXME-someday, should give breakpoint #. */
5354 value_free_to_mark (mark
);
5357 if (cond
&& !condition_result
)
5361 else if (b
->ignore_count
> 0)
5365 /* Increase the hit count even though we don't stop. */
5367 observer_notify_breakpoint_modified (b
);
5371 /* Returns true if we need to track moribund locations of LOC's type
5372 on the current target. */
5375 need_moribund_for_location_type (struct bp_location
*loc
)
5377 return ((loc
->loc_type
== bp_loc_software_breakpoint
5378 && !target_supports_stopped_by_sw_breakpoint ())
5379 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5380 && !target_supports_stopped_by_hw_breakpoint ()));
5384 /* Get a bpstat associated with having just stopped at address
5385 BP_ADDR in thread PTID.
5387 Determine whether we stopped at a breakpoint, etc, or whether we
5388 don't understand this stop. Result is a chain of bpstat's such
5391 if we don't understand the stop, the result is a null pointer.
5393 if we understand why we stopped, the result is not null.
5395 Each element of the chain refers to a particular breakpoint or
5396 watchpoint at which we have stopped. (We may have stopped for
5397 several reasons concurrently.)
5399 Each element of the chain has valid next, breakpoint_at,
5400 commands, FIXME??? fields. */
5403 bpstat_stop_status (const address_space
*aspace
,
5404 CORE_ADDR bp_addr
, ptid_t ptid
,
5405 const struct target_waitstatus
*ws
)
5407 struct breakpoint
*b
= NULL
;
5408 struct bp_location
*bl
;
5409 struct bp_location
*loc
;
5410 /* First item of allocated bpstat's. */
5411 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5412 /* Pointer to the last thing in the chain currently. */
5415 int need_remove_insert
;
5418 /* First, build the bpstat chain with locations that explain a
5419 target stop, while being careful to not set the target running,
5420 as that may invalidate locations (in particular watchpoint
5421 locations are recreated). Resuming will happen here with
5422 breakpoint conditions or watchpoint expressions that include
5423 inferior function calls. */
5427 if (!breakpoint_enabled (b
))
5430 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5432 /* For hardware watchpoints, we look only at the first
5433 location. The watchpoint_check function will work on the
5434 entire expression, not the individual locations. For
5435 read watchpoints, the watchpoints_triggered function has
5436 checked all locations already. */
5437 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5440 if (!bl
->enabled
|| bl
->shlib_disabled
)
5443 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5446 /* Come here if it's a watchpoint, or if the break address
5449 bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5452 /* Assume we stop. Should we find a watchpoint that is not
5453 actually triggered, or if the condition of the breakpoint
5454 evaluates as false, we'll reset 'stop' to 0. */
5458 /* If this is a scope breakpoint, mark the associated
5459 watchpoint as triggered so that we will handle the
5460 out-of-scope event. We'll get to the watchpoint next
5462 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5464 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5466 w
->watchpoint_triggered
= watch_triggered_yes
;
5471 /* Check if a moribund breakpoint explains the stop. */
5472 if (!target_supports_stopped_by_sw_breakpoint ()
5473 || !target_supports_stopped_by_hw_breakpoint ())
5475 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5477 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5478 && need_moribund_for_location_type (loc
))
5480 bs
= new bpstats (loc
, &bs_link
);
5481 /* For hits of moribund locations, we should just proceed. */
5484 bs
->print_it
= print_it_noop
;
5489 /* A bit of special processing for shlib breakpoints. We need to
5490 process solib loading here, so that the lists of loaded and
5491 unloaded libraries are correct before we handle "catch load" and
5493 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5495 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5497 handle_solib_event ();
5502 /* Now go through the locations that caused the target to stop, and
5503 check whether we're interested in reporting this stop to higher
5504 layers, or whether we should resume the target transparently. */
5508 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5513 b
= bs
->breakpoint_at
;
5514 b
->ops
->check_status (bs
);
5517 bpstat_check_breakpoint_conditions (bs
, ptid
);
5522 observer_notify_breakpoint_modified (b
);
5524 /* We will stop here. */
5525 if (b
->disposition
== disp_disable
)
5527 --(b
->enable_count
);
5528 if (b
->enable_count
<= 0)
5529 b
->enable_state
= bp_disabled
;
5534 bs
->commands
= b
->commands
;
5535 if (command_line_is_silent (bs
->commands
5536 ? bs
->commands
.get () : NULL
))
5539 b
->ops
->after_condition_true (bs
);
5544 /* Print nothing for this entry if we don't stop or don't
5546 if (!bs
->stop
|| !bs
->print
)
5547 bs
->print_it
= print_it_noop
;
5550 /* If we aren't stopping, the value of some hardware watchpoint may
5551 not have changed, but the intermediate memory locations we are
5552 watching may have. Don't bother if we're stopping; this will get
5554 need_remove_insert
= 0;
5555 if (! bpstat_causes_stop (bs_head
))
5556 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5558 && bs
->breakpoint_at
5559 && is_hardware_watchpoint (bs
->breakpoint_at
))
5561 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5563 update_watchpoint (w
, 0 /* don't reparse. */);
5564 need_remove_insert
= 1;
5567 if (need_remove_insert
)
5568 update_global_location_list (UGLL_MAY_INSERT
);
5569 else if (removed_any
)
5570 update_global_location_list (UGLL_DONT_INSERT
);
5576 handle_jit_event (void)
5578 struct frame_info
*frame
;
5579 struct gdbarch
*gdbarch
;
5582 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5584 /* Switch terminal for any messages produced by
5585 breakpoint_re_set. */
5586 target_terminal::ours_for_output ();
5588 frame
= get_current_frame ();
5589 gdbarch
= get_frame_arch (frame
);
5591 jit_event_handler (gdbarch
);
5593 target_terminal::inferior ();
5596 /* Prepare WHAT final decision for infrun. */
5598 /* Decide what infrun needs to do with this bpstat. */
5601 bpstat_what (bpstat bs_head
)
5603 struct bpstat_what retval
;
5606 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5607 retval
.call_dummy
= STOP_NONE
;
5608 retval
.is_longjmp
= 0;
5610 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5612 /* Extract this BS's action. After processing each BS, we check
5613 if its action overrides all we've seem so far. */
5614 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5617 if (bs
->breakpoint_at
== NULL
)
5619 /* I suspect this can happen if it was a momentary
5620 breakpoint which has since been deleted. */
5624 bptype
= bs
->breakpoint_at
->type
;
5631 case bp_hardware_breakpoint
:
5632 case bp_single_step
:
5635 case bp_shlib_event
:
5639 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5641 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5644 this_action
= BPSTAT_WHAT_SINGLE
;
5647 case bp_hardware_watchpoint
:
5648 case bp_read_watchpoint
:
5649 case bp_access_watchpoint
:
5653 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5655 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5659 /* There was a watchpoint, but we're not stopping.
5660 This requires no further action. */
5664 case bp_longjmp_call_dummy
:
5668 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5669 retval
.is_longjmp
= bptype
!= bp_exception
;
5672 this_action
= BPSTAT_WHAT_SINGLE
;
5674 case bp_longjmp_resume
:
5675 case bp_exception_resume
:
5678 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5679 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5682 this_action
= BPSTAT_WHAT_SINGLE
;
5684 case bp_step_resume
:
5686 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5689 /* It is for the wrong frame. */
5690 this_action
= BPSTAT_WHAT_SINGLE
;
5693 case bp_hp_step_resume
:
5695 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5698 /* It is for the wrong frame. */
5699 this_action
= BPSTAT_WHAT_SINGLE
;
5702 case bp_watchpoint_scope
:
5703 case bp_thread_event
:
5704 case bp_overlay_event
:
5705 case bp_longjmp_master
:
5706 case bp_std_terminate_master
:
5707 case bp_exception_master
:
5708 this_action
= BPSTAT_WHAT_SINGLE
;
5714 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5716 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5720 /* There was a catchpoint, but we're not stopping.
5721 This requires no further action. */
5725 this_action
= BPSTAT_WHAT_SINGLE
;
5728 /* Make sure the action is stop (silent or noisy),
5729 so infrun.c pops the dummy frame. */
5730 retval
.call_dummy
= STOP_STACK_DUMMY
;
5731 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5733 case bp_std_terminate
:
5734 /* Make sure the action is stop (silent or noisy),
5735 so infrun.c pops the dummy frame. */
5736 retval
.call_dummy
= STOP_STD_TERMINATE
;
5737 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5740 case bp_fast_tracepoint
:
5741 case bp_static_tracepoint
:
5742 /* Tracepoint hits should not be reported back to GDB, and
5743 if one got through somehow, it should have been filtered
5745 internal_error (__FILE__
, __LINE__
,
5746 _("bpstat_what: tracepoint encountered"));
5748 case bp_gnu_ifunc_resolver
:
5749 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5750 this_action
= BPSTAT_WHAT_SINGLE
;
5752 case bp_gnu_ifunc_resolver_return
:
5753 /* The breakpoint will be removed, execution will restart from the
5754 PC of the former breakpoint. */
5755 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5760 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5762 this_action
= BPSTAT_WHAT_SINGLE
;
5766 internal_error (__FILE__
, __LINE__
,
5767 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5770 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5777 bpstat_run_callbacks (bpstat bs_head
)
5781 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5783 struct breakpoint
*b
= bs
->breakpoint_at
;
5790 handle_jit_event ();
5792 case bp_gnu_ifunc_resolver
:
5793 gnu_ifunc_resolver_stop (b
);
5795 case bp_gnu_ifunc_resolver_return
:
5796 gnu_ifunc_resolver_return_stop (b
);
5802 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5803 without hardware support). This isn't related to a specific bpstat,
5804 just to things like whether watchpoints are set. */
5807 bpstat_should_step (void)
5809 struct breakpoint
*b
;
5812 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5818 bpstat_causes_stop (bpstat bs
)
5820 for (; bs
!= NULL
; bs
= bs
->next
)
5829 /* Compute a string of spaces suitable to indent the next line
5830 so it starts at the position corresponding to the table column
5831 named COL_NAME in the currently active table of UIOUT. */
5834 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5836 static char wrap_indent
[80];
5837 int i
, total_width
, width
, align
;
5841 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5843 if (strcmp (text
, col_name
) == 0)
5845 gdb_assert (total_width
< sizeof wrap_indent
);
5846 memset (wrap_indent
, ' ', total_width
);
5847 wrap_indent
[total_width
] = 0;
5852 total_width
+= width
+ 1;
5858 /* Determine if the locations of this breakpoint will have their conditions
5859 evaluated by the target, host or a mix of both. Returns the following:
5861 "host": Host evals condition.
5862 "host or target": Host or Target evals condition.
5863 "target": Target evals condition.
5867 bp_condition_evaluator (struct breakpoint
*b
)
5869 struct bp_location
*bl
;
5870 char host_evals
= 0;
5871 char target_evals
= 0;
5876 if (!is_breakpoint (b
))
5879 if (gdb_evaluates_breakpoint_condition_p ()
5880 || !target_supports_evaluation_of_breakpoint_conditions ())
5881 return condition_evaluation_host
;
5883 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5885 if (bl
->cond_bytecode
)
5891 if (host_evals
&& target_evals
)
5892 return condition_evaluation_both
;
5893 else if (target_evals
)
5894 return condition_evaluation_target
;
5896 return condition_evaluation_host
;
5899 /* Determine the breakpoint location's condition evaluator. This is
5900 similar to bp_condition_evaluator, but for locations. */
5903 bp_location_condition_evaluator (struct bp_location
*bl
)
5905 if (bl
&& !is_breakpoint (bl
->owner
))
5908 if (gdb_evaluates_breakpoint_condition_p ()
5909 || !target_supports_evaluation_of_breakpoint_conditions ())
5910 return condition_evaluation_host
;
5912 if (bl
&& bl
->cond_bytecode
)
5913 return condition_evaluation_target
;
5915 return condition_evaluation_host
;
5918 /* Print the LOC location out of the list of B->LOC locations. */
5921 print_breakpoint_location (struct breakpoint
*b
,
5922 struct bp_location
*loc
)
5924 struct ui_out
*uiout
= current_uiout
;
5926 scoped_restore_current_program_space restore_pspace
;
5928 if (loc
!= NULL
&& loc
->shlib_disabled
)
5932 set_current_program_space (loc
->pspace
);
5934 if (b
->display_canonical
)
5935 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5936 else if (loc
&& loc
->symtab
)
5938 const struct symbol
*sym
= loc
->symbol
;
5941 sym
= find_pc_sect_function (loc
->address
, loc
->section
);
5945 uiout
->text ("in ");
5946 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
5948 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5949 uiout
->text ("at ");
5951 uiout
->field_string ("file",
5952 symtab_to_filename_for_display (loc
->symtab
));
5955 if (uiout
->is_mi_like_p ())
5956 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5958 uiout
->field_int ("line", loc
->line_number
);
5964 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5966 uiout
->field_stream ("at", stb
);
5970 uiout
->field_string ("pending",
5971 event_location_to_string (b
->location
.get ()));
5972 /* If extra_string is available, it could be holding a condition
5973 or dprintf arguments. In either case, make sure it is printed,
5974 too, but only for non-MI streams. */
5975 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5977 if (b
->type
== bp_dprintf
)
5981 uiout
->text (b
->extra_string
);
5985 if (loc
&& is_breakpoint (b
)
5986 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
5987 && bp_condition_evaluator (b
) == condition_evaluation_both
)
5990 uiout
->field_string ("evaluated-by",
5991 bp_location_condition_evaluator (loc
));
5997 bptype_string (enum bptype type
)
5999 struct ep_type_description
6002 const char *description
;
6004 static struct ep_type_description bptypes
[] =
6006 {bp_none
, "?deleted?"},
6007 {bp_breakpoint
, "breakpoint"},
6008 {bp_hardware_breakpoint
, "hw breakpoint"},
6009 {bp_single_step
, "sw single-step"},
6010 {bp_until
, "until"},
6011 {bp_finish
, "finish"},
6012 {bp_watchpoint
, "watchpoint"},
6013 {bp_hardware_watchpoint
, "hw watchpoint"},
6014 {bp_read_watchpoint
, "read watchpoint"},
6015 {bp_access_watchpoint
, "acc watchpoint"},
6016 {bp_longjmp
, "longjmp"},
6017 {bp_longjmp_resume
, "longjmp resume"},
6018 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6019 {bp_exception
, "exception"},
6020 {bp_exception_resume
, "exception resume"},
6021 {bp_step_resume
, "step resume"},
6022 {bp_hp_step_resume
, "high-priority step resume"},
6023 {bp_watchpoint_scope
, "watchpoint scope"},
6024 {bp_call_dummy
, "call dummy"},
6025 {bp_std_terminate
, "std::terminate"},
6026 {bp_shlib_event
, "shlib events"},
6027 {bp_thread_event
, "thread events"},
6028 {bp_overlay_event
, "overlay events"},
6029 {bp_longjmp_master
, "longjmp master"},
6030 {bp_std_terminate_master
, "std::terminate master"},
6031 {bp_exception_master
, "exception master"},
6032 {bp_catchpoint
, "catchpoint"},
6033 {bp_tracepoint
, "tracepoint"},
6034 {bp_fast_tracepoint
, "fast tracepoint"},
6035 {bp_static_tracepoint
, "static tracepoint"},
6036 {bp_dprintf
, "dprintf"},
6037 {bp_jit_event
, "jit events"},
6038 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6039 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6042 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6043 || ((int) type
!= bptypes
[(int) type
].type
))
6044 internal_error (__FILE__
, __LINE__
,
6045 _("bptypes table does not describe type #%d."),
6048 return bptypes
[(int) type
].description
;
6051 /* For MI, output a field named 'thread-groups' with a list as the value.
6052 For CLI, prefix the list with the string 'inf'. */
6055 output_thread_groups (struct ui_out
*uiout
,
6056 const char *field_name
,
6060 int is_mi
= uiout
->is_mi_like_p ();
6064 /* For backward compatibility, don't display inferiors in CLI unless
6065 there are several. Always display them for MI. */
6066 if (!is_mi
&& mi_only
)
6069 ui_out_emit_list
list_emitter (uiout
, field_name
);
6071 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6077 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6078 uiout
->field_string (NULL
, mi_group
);
6083 uiout
->text (" inf ");
6087 uiout
->text (plongest (inf
));
6092 /* Print B to gdb_stdout. */
6095 print_one_breakpoint_location (struct breakpoint
*b
,
6096 struct bp_location
*loc
,
6098 struct bp_location
**last_loc
,
6101 struct command_line
*l
;
6102 static char bpenables
[] = "nynny";
6104 struct ui_out
*uiout
= current_uiout
;
6105 int header_of_multiple
= 0;
6106 int part_of_multiple
= (loc
!= NULL
);
6107 struct value_print_options opts
;
6109 get_user_print_options (&opts
);
6111 gdb_assert (!loc
|| loc_number
!= 0);
6112 /* See comment in print_one_breakpoint concerning treatment of
6113 breakpoints with single disabled location. */
6116 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6117 header_of_multiple
= 1;
6125 if (part_of_multiple
)
6128 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6129 uiout
->field_string ("number", formatted
);
6134 uiout
->field_int ("number", b
->number
);
6139 if (part_of_multiple
)
6140 uiout
->field_skip ("type");
6142 uiout
->field_string ("type", bptype_string (b
->type
));
6146 if (part_of_multiple
)
6147 uiout
->field_skip ("disp");
6149 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6154 if (part_of_multiple
)
6155 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6157 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6162 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6164 /* Although the print_one can possibly print all locations,
6165 calling it here is not likely to get any nice result. So,
6166 make sure there's just one location. */
6167 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6168 b
->ops
->print_one (b
, last_loc
);
6174 internal_error (__FILE__
, __LINE__
,
6175 _("print_one_breakpoint: bp_none encountered\n"));
6179 case bp_hardware_watchpoint
:
6180 case bp_read_watchpoint
:
6181 case bp_access_watchpoint
:
6183 struct watchpoint
*w
= (struct watchpoint
*) b
;
6185 /* Field 4, the address, is omitted (which makes the columns
6186 not line up too nicely with the headers, but the effect
6187 is relatively readable). */
6188 if (opts
.addressprint
)
6189 uiout
->field_skip ("addr");
6191 uiout
->field_string ("what", w
->exp_string
);
6196 case bp_hardware_breakpoint
:
6197 case bp_single_step
:
6201 case bp_longjmp_resume
:
6202 case bp_longjmp_call_dummy
:
6204 case bp_exception_resume
:
6205 case bp_step_resume
:
6206 case bp_hp_step_resume
:
6207 case bp_watchpoint_scope
:
6209 case bp_std_terminate
:
6210 case bp_shlib_event
:
6211 case bp_thread_event
:
6212 case bp_overlay_event
:
6213 case bp_longjmp_master
:
6214 case bp_std_terminate_master
:
6215 case bp_exception_master
:
6217 case bp_fast_tracepoint
:
6218 case bp_static_tracepoint
:
6221 case bp_gnu_ifunc_resolver
:
6222 case bp_gnu_ifunc_resolver_return
:
6223 if (opts
.addressprint
)
6226 if (header_of_multiple
)
6227 uiout
->field_string ("addr", "<MULTIPLE>");
6228 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6229 uiout
->field_string ("addr", "<PENDING>");
6231 uiout
->field_core_addr ("addr",
6232 loc
->gdbarch
, loc
->address
);
6235 if (!header_of_multiple
)
6236 print_breakpoint_location (b
, loc
);
6243 if (loc
!= NULL
&& !header_of_multiple
)
6245 struct inferior
*inf
;
6246 VEC(int) *inf_num
= NULL
;
6251 if (inf
->pspace
== loc
->pspace
)
6252 VEC_safe_push (int, inf_num
, inf
->num
);
6255 /* For backward compatibility, don't display inferiors in CLI unless
6256 there are several. Always display for MI. */
6258 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6259 && (number_of_program_spaces () > 1
6260 || number_of_inferiors () > 1)
6261 /* LOC is for existing B, it cannot be in
6262 moribund_locations and thus having NULL OWNER. */
6263 && loc
->owner
->type
!= bp_catchpoint
))
6265 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6266 VEC_free (int, inf_num
);
6269 if (!part_of_multiple
)
6271 if (b
->thread
!= -1)
6273 /* FIXME: This seems to be redundant and lost here; see the
6274 "stop only in" line a little further down. */
6275 uiout
->text (" thread ");
6276 uiout
->field_int ("thread", b
->thread
);
6278 else if (b
->task
!= 0)
6280 uiout
->text (" task ");
6281 uiout
->field_int ("task", b
->task
);
6287 if (!part_of_multiple
)
6288 b
->ops
->print_one_detail (b
, uiout
);
6290 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6293 uiout
->text ("\tstop only in stack frame at ");
6294 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6296 uiout
->field_core_addr ("frame",
6297 b
->gdbarch
, b
->frame_id
.stack_addr
);
6301 if (!part_of_multiple
&& b
->cond_string
)
6304 if (is_tracepoint (b
))
6305 uiout
->text ("\ttrace only if ");
6307 uiout
->text ("\tstop only if ");
6308 uiout
->field_string ("cond", b
->cond_string
);
6310 /* Print whether the target is doing the breakpoint's condition
6311 evaluation. If GDB is doing the evaluation, don't print anything. */
6312 if (is_breakpoint (b
)
6313 && breakpoint_condition_evaluation_mode ()
6314 == condition_evaluation_target
)
6317 uiout
->field_string ("evaluated-by",
6318 bp_condition_evaluator (b
));
6319 uiout
->text (" evals)");
6324 if (!part_of_multiple
&& b
->thread
!= -1)
6326 /* FIXME should make an annotation for this. */
6327 uiout
->text ("\tstop only in thread ");
6328 if (uiout
->is_mi_like_p ())
6329 uiout
->field_int ("thread", b
->thread
);
6332 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6334 uiout
->field_string ("thread", print_thread_id (thr
));
6339 if (!part_of_multiple
)
6343 /* FIXME should make an annotation for this. */
6344 if (is_catchpoint (b
))
6345 uiout
->text ("\tcatchpoint");
6346 else if (is_tracepoint (b
))
6347 uiout
->text ("\ttracepoint");
6349 uiout
->text ("\tbreakpoint");
6350 uiout
->text (" already hit ");
6351 uiout
->field_int ("times", b
->hit_count
);
6352 if (b
->hit_count
== 1)
6353 uiout
->text (" time\n");
6355 uiout
->text (" times\n");
6359 /* Output the count also if it is zero, but only if this is mi. */
6360 if (uiout
->is_mi_like_p ())
6361 uiout
->field_int ("times", b
->hit_count
);
6365 if (!part_of_multiple
&& b
->ignore_count
)
6368 uiout
->text ("\tignore next ");
6369 uiout
->field_int ("ignore", b
->ignore_count
);
6370 uiout
->text (" hits\n");
6373 /* Note that an enable count of 1 corresponds to "enable once"
6374 behavior, which is reported by the combination of enablement and
6375 disposition, so we don't need to mention it here. */
6376 if (!part_of_multiple
&& b
->enable_count
> 1)
6379 uiout
->text ("\tdisable after ");
6380 /* Tweak the wording to clarify that ignore and enable counts
6381 are distinct, and have additive effect. */
6382 if (b
->ignore_count
)
6383 uiout
->text ("additional ");
6385 uiout
->text ("next ");
6386 uiout
->field_int ("enable", b
->enable_count
);
6387 uiout
->text (" hits\n");
6390 if (!part_of_multiple
&& is_tracepoint (b
))
6392 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6394 if (tp
->traceframe_usage
)
6396 uiout
->text ("\ttrace buffer usage ");
6397 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6398 uiout
->text (" bytes\n");
6402 l
= b
->commands
? b
->commands
.get () : NULL
;
6403 if (!part_of_multiple
&& l
)
6406 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6407 print_command_lines (uiout
, l
, 4);
6410 if (is_tracepoint (b
))
6412 struct tracepoint
*t
= (struct tracepoint
*) b
;
6414 if (!part_of_multiple
&& t
->pass_count
)
6416 annotate_field (10);
6417 uiout
->text ("\tpass count ");
6418 uiout
->field_int ("pass", t
->pass_count
);
6419 uiout
->text (" \n");
6422 /* Don't display it when tracepoint or tracepoint location is
6424 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6426 annotate_field (11);
6428 if (uiout
->is_mi_like_p ())
6429 uiout
->field_string ("installed",
6430 loc
->inserted
? "y" : "n");
6436 uiout
->text ("\tnot ");
6437 uiout
->text ("installed on target\n");
6442 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6444 if (is_watchpoint (b
))
6446 struct watchpoint
*w
= (struct watchpoint
*) b
;
6448 uiout
->field_string ("original-location", w
->exp_string
);
6450 else if (b
->location
!= NULL
6451 && event_location_to_string (b
->location
.get ()) != NULL
)
6452 uiout
->field_string ("original-location",
6453 event_location_to_string (b
->location
.get ()));
6458 print_one_breakpoint (struct breakpoint
*b
,
6459 struct bp_location
**last_loc
,
6462 struct ui_out
*uiout
= current_uiout
;
6465 ui_out_emit_tuple
tuple_emitter (uiout
, "bkpt");
6467 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6470 /* If this breakpoint has custom print function,
6471 it's already printed. Otherwise, print individual
6472 locations, if any. */
6473 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6475 /* If breakpoint has a single location that is disabled, we
6476 print it as if it had several locations, since otherwise it's
6477 hard to represent "breakpoint enabled, location disabled"
6480 Note that while hardware watchpoints have several locations
6481 internally, that's not a property exposed to user. */
6483 && !is_hardware_watchpoint (b
)
6484 && (b
->loc
->next
|| !b
->loc
->enabled
))
6486 struct bp_location
*loc
;
6489 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6491 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
6492 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6499 breakpoint_address_bits (struct breakpoint
*b
)
6501 int print_address_bits
= 0;
6502 struct bp_location
*loc
;
6504 /* Software watchpoints that aren't watching memory don't have an
6505 address to print. */
6506 if (is_no_memory_software_watchpoint (b
))
6509 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6513 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6514 if (addr_bit
> print_address_bits
)
6515 print_address_bits
= addr_bit
;
6518 return print_address_bits
;
6521 /* See breakpoint.h. */
6524 print_breakpoint (breakpoint
*b
)
6526 struct bp_location
*dummy_loc
= NULL
;
6527 print_one_breakpoint (b
, &dummy_loc
, 0);
6530 /* Return true if this breakpoint was set by the user, false if it is
6531 internal or momentary. */
6534 user_breakpoint_p (struct breakpoint
*b
)
6536 return b
->number
> 0;
6539 /* See breakpoint.h. */
6542 pending_breakpoint_p (struct breakpoint
*b
)
6544 return b
->loc
== NULL
;
6547 /* Print information on user settable breakpoint (watchpoint, etc)
6548 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6549 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6550 FILTER is non-NULL, call it on each breakpoint and only include the
6551 ones for which it returns non-zero. Return the total number of
6552 breakpoints listed. */
6555 breakpoint_1 (const char *args
, int allflag
,
6556 int (*filter
) (const struct breakpoint
*))
6558 struct breakpoint
*b
;
6559 struct bp_location
*last_loc
= NULL
;
6560 int nr_printable_breakpoints
;
6561 struct value_print_options opts
;
6562 int print_address_bits
= 0;
6563 int print_type_col_width
= 14;
6564 struct ui_out
*uiout
= current_uiout
;
6566 get_user_print_options (&opts
);
6568 /* Compute the number of rows in the table, as well as the size
6569 required for address fields. */
6570 nr_printable_breakpoints
= 0;
6573 /* If we have a filter, only list the breakpoints it accepts. */
6574 if (filter
&& !filter (b
))
6577 /* If we have an "args" string, it is a list of breakpoints to
6578 accept. Skip the others. */
6579 if (args
!= NULL
&& *args
!= '\0')
6581 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6583 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6587 if (allflag
|| user_breakpoint_p (b
))
6589 int addr_bit
, type_len
;
6591 addr_bit
= breakpoint_address_bits (b
);
6592 if (addr_bit
> print_address_bits
)
6593 print_address_bits
= addr_bit
;
6595 type_len
= strlen (bptype_string (b
->type
));
6596 if (type_len
> print_type_col_width
)
6597 print_type_col_width
= type_len
;
6599 nr_printable_breakpoints
++;
6604 ui_out_emit_table
table_emitter (uiout
,
6605 opts
.addressprint
? 6 : 5,
6606 nr_printable_breakpoints
,
6609 if (nr_printable_breakpoints
> 0)
6610 annotate_breakpoints_headers ();
6611 if (nr_printable_breakpoints
> 0)
6613 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6614 if (nr_printable_breakpoints
> 0)
6616 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6617 if (nr_printable_breakpoints
> 0)
6619 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6620 if (nr_printable_breakpoints
> 0)
6622 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6623 if (opts
.addressprint
)
6625 if (nr_printable_breakpoints
> 0)
6627 if (print_address_bits
<= 32)
6628 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6630 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6632 if (nr_printable_breakpoints
> 0)
6634 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6635 uiout
->table_body ();
6636 if (nr_printable_breakpoints
> 0)
6637 annotate_breakpoints_table ();
6642 /* If we have a filter, only list the breakpoints it accepts. */
6643 if (filter
&& !filter (b
))
6646 /* If we have an "args" string, it is a list of breakpoints to
6647 accept. Skip the others. */
6649 if (args
!= NULL
&& *args
!= '\0')
6651 if (allflag
) /* maintenance info breakpoint */
6653 if (parse_and_eval_long (args
) != b
->number
)
6656 else /* all others */
6658 if (!number_is_in_list (args
, b
->number
))
6662 /* We only print out user settable breakpoints unless the
6664 if (allflag
|| user_breakpoint_p (b
))
6665 print_one_breakpoint (b
, &last_loc
, allflag
);
6669 if (nr_printable_breakpoints
== 0)
6671 /* If there's a filter, let the caller decide how to report
6675 if (args
== NULL
|| *args
== '\0')
6676 uiout
->message ("No breakpoints or watchpoints.\n");
6678 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6684 if (last_loc
&& !server_command
)
6685 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6688 /* FIXME? Should this be moved up so that it is only called when
6689 there have been breakpoints? */
6690 annotate_breakpoints_table_end ();
6692 return nr_printable_breakpoints
;
6695 /* Display the value of default-collect in a way that is generally
6696 compatible with the breakpoint list. */
6699 default_collect_info (void)
6701 struct ui_out
*uiout
= current_uiout
;
6703 /* If it has no value (which is frequently the case), say nothing; a
6704 message like "No default-collect." gets in user's face when it's
6706 if (!*default_collect
)
6709 /* The following phrase lines up nicely with per-tracepoint collect
6711 uiout
->text ("default collect ");
6712 uiout
->field_string ("default-collect", default_collect
);
6713 uiout
->text (" \n");
6717 info_breakpoints_command (char *args
, int from_tty
)
6719 breakpoint_1 (args
, 0, NULL
);
6721 default_collect_info ();
6725 info_watchpoints_command (char *args
, int from_tty
)
6727 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6728 struct ui_out
*uiout
= current_uiout
;
6730 if (num_printed
== 0)
6732 if (args
== NULL
|| *args
== '\0')
6733 uiout
->message ("No watchpoints.\n");
6735 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6740 maintenance_info_breakpoints (const char *args
, int from_tty
)
6742 breakpoint_1 (args
, 1, NULL
);
6744 default_collect_info ();
6748 breakpoint_has_pc (struct breakpoint
*b
,
6749 struct program_space
*pspace
,
6750 CORE_ADDR pc
, struct obj_section
*section
)
6752 struct bp_location
*bl
= b
->loc
;
6754 for (; bl
; bl
= bl
->next
)
6756 if (bl
->pspace
== pspace
6757 && bl
->address
== pc
6758 && (!overlay_debugging
|| bl
->section
== section
))
6764 /* Print a message describing any user-breakpoints set at PC. This
6765 concerns with logical breakpoints, so we match program spaces, not
6769 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6770 struct program_space
*pspace
, CORE_ADDR pc
,
6771 struct obj_section
*section
, int thread
)
6774 struct breakpoint
*b
;
6777 others
+= (user_breakpoint_p (b
)
6778 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6782 printf_filtered (_("Note: breakpoint "));
6783 else /* if (others == ???) */
6784 printf_filtered (_("Note: breakpoints "));
6786 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6789 printf_filtered ("%d", b
->number
);
6790 if (b
->thread
== -1 && thread
!= -1)
6791 printf_filtered (" (all threads)");
6792 else if (b
->thread
!= -1)
6793 printf_filtered (" (thread %d)", b
->thread
);
6794 printf_filtered ("%s%s ",
6795 ((b
->enable_state
== bp_disabled
6796 || b
->enable_state
== bp_call_disabled
)
6800 : ((others
== 1) ? " and" : ""));
6802 printf_filtered (_("also set at pc "));
6803 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6804 printf_filtered (".\n");
6809 /* Return true iff it is meaningful to use the address member of
6810 BPT locations. For some breakpoint types, the locations' address members
6811 are irrelevant and it makes no sense to attempt to compare them to other
6812 addresses (or use them for any other purpose either).
6814 More specifically, each of the following breakpoint types will
6815 always have a zero valued location address and we don't want to mark
6816 breakpoints of any of these types to be a duplicate of an actual
6817 breakpoint location at address zero:
6825 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6827 enum bptype type
= bpt
->type
;
6829 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6832 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6833 true if LOC1 and LOC2 represent the same watchpoint location. */
6836 watchpoint_locations_match (struct bp_location
*loc1
,
6837 struct bp_location
*loc2
)
6839 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6840 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6842 /* Both of them must exist. */
6843 gdb_assert (w1
!= NULL
);
6844 gdb_assert (w2
!= NULL
);
6846 /* If the target can evaluate the condition expression in hardware,
6847 then we we need to insert both watchpoints even if they are at
6848 the same place. Otherwise the watchpoint will only trigger when
6849 the condition of whichever watchpoint was inserted evaluates to
6850 true, not giving a chance for GDB to check the condition of the
6851 other watchpoint. */
6853 && target_can_accel_watchpoint_condition (loc1
->address
,
6855 loc1
->watchpoint_type
,
6856 w1
->cond_exp
.get ()))
6858 && target_can_accel_watchpoint_condition (loc2
->address
,
6860 loc2
->watchpoint_type
,
6861 w2
->cond_exp
.get ())))
6864 /* Note that this checks the owner's type, not the location's. In
6865 case the target does not support read watchpoints, but does
6866 support access watchpoints, we'll have bp_read_watchpoint
6867 watchpoints with hw_access locations. Those should be considered
6868 duplicates of hw_read locations. The hw_read locations will
6869 become hw_access locations later. */
6870 return (loc1
->owner
->type
== loc2
->owner
->type
6871 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6872 && loc1
->address
== loc2
->address
6873 && loc1
->length
== loc2
->length
);
6876 /* See breakpoint.h. */
6879 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6880 const address_space
*aspace2
, CORE_ADDR addr2
)
6882 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6883 || aspace1
== aspace2
)
6887 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6888 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6889 matches ASPACE2. On targets that have global breakpoints, the address
6890 space doesn't really matter. */
6893 breakpoint_address_match_range (const address_space
*aspace1
,
6895 int len1
, const address_space
*aspace2
,
6898 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6899 || aspace1
== aspace2
)
6900 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6903 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6904 a ranged breakpoint. In most targets, a match happens only if ASPACE
6905 matches the breakpoint's address space. On targets that have global
6906 breakpoints, the address space doesn't really matter. */
6909 breakpoint_location_address_match (struct bp_location
*bl
,
6910 const address_space
*aspace
,
6913 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6916 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6917 bl
->address
, bl
->length
,
6921 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6922 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6923 match happens only if ASPACE matches the breakpoint's address
6924 space. On targets that have global breakpoints, the address space
6925 doesn't really matter. */
6928 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6929 const address_space
*aspace
,
6930 CORE_ADDR addr
, int len
)
6932 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6933 || bl
->pspace
->aspace
== aspace
)
6935 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6937 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6943 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6944 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6945 true, otherwise returns false. */
6948 tracepoint_locations_match (struct bp_location
*loc1
,
6949 struct bp_location
*loc2
)
6951 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6952 /* Since tracepoint locations are never duplicated with others', tracepoint
6953 locations at the same address of different tracepoints are regarded as
6954 different locations. */
6955 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6960 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6961 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6962 represent the same location. */
6965 breakpoint_locations_match (struct bp_location
*loc1
,
6966 struct bp_location
*loc2
)
6968 int hw_point1
, hw_point2
;
6970 /* Both of them must not be in moribund_locations. */
6971 gdb_assert (loc1
->owner
!= NULL
);
6972 gdb_assert (loc2
->owner
!= NULL
);
6974 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6975 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6977 if (hw_point1
!= hw_point2
)
6980 return watchpoint_locations_match (loc1
, loc2
);
6981 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
6982 return tracepoint_locations_match (loc1
, loc2
);
6984 /* We compare bp_location.length in order to cover ranged breakpoints. */
6985 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
6986 loc2
->pspace
->aspace
, loc2
->address
)
6987 && loc1
->length
== loc2
->length
);
6991 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
6992 int bnum
, int have_bnum
)
6994 /* The longest string possibly returned by hex_string_custom
6995 is 50 chars. These must be at least that big for safety. */
6999 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7000 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7002 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7003 bnum
, astr1
, astr2
);
7005 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7008 /* Adjust a breakpoint's address to account for architectural
7009 constraints on breakpoint placement. Return the adjusted address.
7010 Note: Very few targets require this kind of adjustment. For most
7011 targets, this function is simply the identity function. */
7014 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7015 CORE_ADDR bpaddr
, enum bptype bptype
)
7017 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7019 /* Very few targets need any kind of breakpoint adjustment. */
7022 else if (bptype
== bp_watchpoint
7023 || bptype
== bp_hardware_watchpoint
7024 || bptype
== bp_read_watchpoint
7025 || bptype
== bp_access_watchpoint
7026 || bptype
== bp_catchpoint
)
7028 /* Watchpoints and the various bp_catch_* eventpoints should not
7029 have their addresses modified. */
7032 else if (bptype
== bp_single_step
)
7034 /* Single-step breakpoints should not have their addresses
7035 modified. If there's any architectural constrain that
7036 applies to this address, then it should have already been
7037 taken into account when the breakpoint was created in the
7038 first place. If we didn't do this, stepping through e.g.,
7039 Thumb-2 IT blocks would break. */
7044 CORE_ADDR adjusted_bpaddr
;
7046 /* Some targets have architectural constraints on the placement
7047 of breakpoint instructions. Obtain the adjusted address. */
7048 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7050 /* An adjusted breakpoint address can significantly alter
7051 a user's expectations. Print a warning if an adjustment
7053 if (adjusted_bpaddr
!= bpaddr
)
7054 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7056 return adjusted_bpaddr
;
7060 bp_location::bp_location (const bp_location_ops
*ops
, breakpoint
*owner
)
7062 bp_location
*loc
= this;
7064 gdb_assert (ops
!= NULL
);
7068 loc
->cond_bytecode
= NULL
;
7069 loc
->shlib_disabled
= 0;
7072 switch (owner
->type
)
7075 case bp_single_step
:
7079 case bp_longjmp_resume
:
7080 case bp_longjmp_call_dummy
:
7082 case bp_exception_resume
:
7083 case bp_step_resume
:
7084 case bp_hp_step_resume
:
7085 case bp_watchpoint_scope
:
7087 case bp_std_terminate
:
7088 case bp_shlib_event
:
7089 case bp_thread_event
:
7090 case bp_overlay_event
:
7092 case bp_longjmp_master
:
7093 case bp_std_terminate_master
:
7094 case bp_exception_master
:
7095 case bp_gnu_ifunc_resolver
:
7096 case bp_gnu_ifunc_resolver_return
:
7098 loc
->loc_type
= bp_loc_software_breakpoint
;
7099 mark_breakpoint_location_modified (loc
);
7101 case bp_hardware_breakpoint
:
7102 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7103 mark_breakpoint_location_modified (loc
);
7105 case bp_hardware_watchpoint
:
7106 case bp_read_watchpoint
:
7107 case bp_access_watchpoint
:
7108 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7113 case bp_fast_tracepoint
:
7114 case bp_static_tracepoint
:
7115 loc
->loc_type
= bp_loc_other
;
7118 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7124 /* Allocate a struct bp_location. */
7126 static struct bp_location
*
7127 allocate_bp_location (struct breakpoint
*bpt
)
7129 return bpt
->ops
->allocate_location (bpt
);
7133 free_bp_location (struct bp_location
*loc
)
7135 loc
->ops
->dtor (loc
);
7139 /* Increment reference count. */
7142 incref_bp_location (struct bp_location
*bl
)
7147 /* Decrement reference count. If the reference count reaches 0,
7148 destroy the bp_location. Sets *BLP to NULL. */
7151 decref_bp_location (struct bp_location
**blp
)
7153 gdb_assert ((*blp
)->refc
> 0);
7155 if (--(*blp
)->refc
== 0)
7156 free_bp_location (*blp
);
7160 /* Add breakpoint B at the end of the global breakpoint chain. */
7163 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7165 struct breakpoint
*b1
;
7166 struct breakpoint
*result
= b
.get ();
7168 /* Add this breakpoint to the end of the chain so that a list of
7169 breakpoints will come out in order of increasing numbers. */
7171 b1
= breakpoint_chain
;
7173 breakpoint_chain
= b
.release ();
7178 b1
->next
= b
.release ();
7184 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7187 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7188 struct gdbarch
*gdbarch
,
7190 const struct breakpoint_ops
*ops
)
7192 gdb_assert (ops
!= NULL
);
7196 b
->gdbarch
= gdbarch
;
7197 b
->language
= current_language
->la_language
;
7198 b
->input_radix
= input_radix
;
7199 b
->related_breakpoint
= b
;
7202 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7203 that has type BPTYPE and has no locations as yet. */
7205 static struct breakpoint
*
7206 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7208 const struct breakpoint_ops
*ops
)
7210 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7212 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7213 return add_to_breakpoint_chain (std::move (b
));
7216 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7217 resolutions should be made as the user specified the location explicitly
7221 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7223 gdb_assert (loc
->owner
!= NULL
);
7225 if (loc
->owner
->type
== bp_breakpoint
7226 || loc
->owner
->type
== bp_hardware_breakpoint
7227 || is_tracepoint (loc
->owner
))
7230 const char *function_name
;
7231 CORE_ADDR func_addr
;
7233 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7234 &func_addr
, NULL
, &is_gnu_ifunc
);
7236 if (is_gnu_ifunc
&& !explicit_loc
)
7238 struct breakpoint
*b
= loc
->owner
;
7240 gdb_assert (loc
->pspace
== current_program_space
);
7241 if (gnu_ifunc_resolve_name (function_name
,
7242 &loc
->requested_address
))
7244 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7245 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7246 loc
->requested_address
,
7249 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7250 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7252 /* Create only the whole new breakpoint of this type but do not
7253 mess more complicated breakpoints with multiple locations. */
7254 b
->type
= bp_gnu_ifunc_resolver
;
7255 /* Remember the resolver's address for use by the return
7257 loc
->related_address
= func_addr
;
7262 loc
->function_name
= xstrdup (function_name
);
7266 /* Attempt to determine architecture of location identified by SAL. */
7268 get_sal_arch (struct symtab_and_line sal
)
7271 return get_objfile_arch (sal
.section
->objfile
);
7273 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7278 /* Low level routine for partially initializing a breakpoint of type
7279 BPTYPE. The newly created breakpoint's address, section, source
7280 file name, and line number are provided by SAL.
7282 It is expected that the caller will complete the initialization of
7283 the newly created breakpoint struct as well as output any status
7284 information regarding the creation of a new breakpoint. */
7287 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7288 struct symtab_and_line sal
, enum bptype bptype
,
7289 const struct breakpoint_ops
*ops
)
7291 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7293 add_location_to_breakpoint (b
, &sal
);
7295 if (bptype
!= bp_catchpoint
)
7296 gdb_assert (sal
.pspace
!= NULL
);
7298 /* Store the program space that was used to set the breakpoint,
7299 except for ordinary breakpoints, which are independent of the
7301 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7302 b
->pspace
= sal
.pspace
;
7305 /* set_raw_breakpoint is a low level routine for allocating and
7306 partially initializing a breakpoint of type BPTYPE. The newly
7307 created breakpoint's address, section, source file name, and line
7308 number are provided by SAL. The newly created and partially
7309 initialized breakpoint is added to the breakpoint chain and
7310 is also returned as the value of this function.
7312 It is expected that the caller will complete the initialization of
7313 the newly created breakpoint struct as well as output any status
7314 information regarding the creation of a new breakpoint. In
7315 particular, set_raw_breakpoint does NOT set the breakpoint
7316 number! Care should be taken to not allow an error to occur
7317 prior to completing the initialization of the breakpoint. If this
7318 should happen, a bogus breakpoint will be left on the chain. */
7321 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7322 struct symtab_and_line sal
, enum bptype bptype
,
7323 const struct breakpoint_ops
*ops
)
7325 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7327 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7328 return add_to_breakpoint_chain (std::move (b
));
7331 /* Call this routine when stepping and nexting to enable a breakpoint
7332 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7333 initiated the operation. */
7336 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7338 struct breakpoint
*b
, *b_tmp
;
7339 int thread
= tp
->global_num
;
7341 /* To avoid having to rescan all objfile symbols at every step,
7342 we maintain a list of continually-inserted but always disabled
7343 longjmp "master" breakpoints. Here, we simply create momentary
7344 clones of those and enable them for the requested thread. */
7345 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7346 if (b
->pspace
== current_program_space
7347 && (b
->type
== bp_longjmp_master
7348 || b
->type
== bp_exception_master
))
7350 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7351 struct breakpoint
*clone
;
7353 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7354 after their removal. */
7355 clone
= momentary_breakpoint_from_master (b
, type
,
7356 &momentary_breakpoint_ops
, 1);
7357 clone
->thread
= thread
;
7360 tp
->initiating_frame
= frame
;
7363 /* Delete all longjmp breakpoints from THREAD. */
7365 delete_longjmp_breakpoint (int thread
)
7367 struct breakpoint
*b
, *b_tmp
;
7369 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7370 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7372 if (b
->thread
== thread
)
7373 delete_breakpoint (b
);
7378 delete_longjmp_breakpoint_at_next_stop (int thread
)
7380 struct breakpoint
*b
, *b_tmp
;
7382 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7383 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7385 if (b
->thread
== thread
)
7386 b
->disposition
= disp_del_at_next_stop
;
7390 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7391 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7392 pointer to any of them. Return NULL if this system cannot place longjmp
7396 set_longjmp_breakpoint_for_call_dummy (void)
7398 struct breakpoint
*b
, *retval
= NULL
;
7401 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7403 struct breakpoint
*new_b
;
7405 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7406 &momentary_breakpoint_ops
,
7408 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7410 /* Link NEW_B into the chain of RETVAL breakpoints. */
7412 gdb_assert (new_b
->related_breakpoint
== new_b
);
7415 new_b
->related_breakpoint
= retval
;
7416 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7417 retval
= retval
->related_breakpoint
;
7418 retval
->related_breakpoint
= new_b
;
7424 /* Verify all existing dummy frames and their associated breakpoints for
7425 TP. Remove those which can no longer be found in the current frame
7428 You should call this function only at places where it is safe to currently
7429 unwind the whole stack. Failed stack unwind would discard live dummy
7433 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7435 struct breakpoint
*b
, *b_tmp
;
7437 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7438 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7440 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7442 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7443 dummy_b
= dummy_b
->related_breakpoint
;
7444 if (dummy_b
->type
!= bp_call_dummy
7445 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7448 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7450 while (b
->related_breakpoint
!= b
)
7452 if (b_tmp
== b
->related_breakpoint
)
7453 b_tmp
= b
->related_breakpoint
->next
;
7454 delete_breakpoint (b
->related_breakpoint
);
7456 delete_breakpoint (b
);
7461 enable_overlay_breakpoints (void)
7463 struct breakpoint
*b
;
7466 if (b
->type
== bp_overlay_event
)
7468 b
->enable_state
= bp_enabled
;
7469 update_global_location_list (UGLL_MAY_INSERT
);
7470 overlay_events_enabled
= 1;
7475 disable_overlay_breakpoints (void)
7477 struct breakpoint
*b
;
7480 if (b
->type
== bp_overlay_event
)
7482 b
->enable_state
= bp_disabled
;
7483 update_global_location_list (UGLL_DONT_INSERT
);
7484 overlay_events_enabled
= 0;
7488 /* Set an active std::terminate breakpoint for each std::terminate
7489 master breakpoint. */
7491 set_std_terminate_breakpoint (void)
7493 struct breakpoint
*b
, *b_tmp
;
7495 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7496 if (b
->pspace
== current_program_space
7497 && b
->type
== bp_std_terminate_master
)
7499 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7500 &momentary_breakpoint_ops
, 1);
7504 /* Delete all the std::terminate breakpoints. */
7506 delete_std_terminate_breakpoint (void)
7508 struct breakpoint
*b
, *b_tmp
;
7510 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7511 if (b
->type
== bp_std_terminate
)
7512 delete_breakpoint (b
);
7516 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7518 struct breakpoint
*b
;
7520 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7521 &internal_breakpoint_ops
);
7523 b
->enable_state
= bp_enabled
;
7524 /* location has to be used or breakpoint_re_set will delete me. */
7525 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7527 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7532 struct lang_and_radix
7538 /* Create a breakpoint for JIT code registration and unregistration. */
7541 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7543 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7544 &internal_breakpoint_ops
);
7547 /* Remove JIT code registration and unregistration breakpoint(s). */
7550 remove_jit_event_breakpoints (void)
7552 struct breakpoint
*b
, *b_tmp
;
7554 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7555 if (b
->type
== bp_jit_event
7556 && b
->loc
->pspace
== current_program_space
)
7557 delete_breakpoint (b
);
7561 remove_solib_event_breakpoints (void)
7563 struct breakpoint
*b
, *b_tmp
;
7565 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7566 if (b
->type
== bp_shlib_event
7567 && b
->loc
->pspace
== current_program_space
)
7568 delete_breakpoint (b
);
7571 /* See breakpoint.h. */
7574 remove_solib_event_breakpoints_at_next_stop (void)
7576 struct breakpoint
*b
, *b_tmp
;
7578 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7579 if (b
->type
== bp_shlib_event
7580 && b
->loc
->pspace
== current_program_space
)
7581 b
->disposition
= disp_del_at_next_stop
;
7584 /* Helper for create_solib_event_breakpoint /
7585 create_and_insert_solib_event_breakpoint. Allows specifying which
7586 INSERT_MODE to pass through to update_global_location_list. */
7588 static struct breakpoint
*
7589 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7590 enum ugll_insert_mode insert_mode
)
7592 struct breakpoint
*b
;
7594 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7595 &internal_breakpoint_ops
);
7596 update_global_location_list_nothrow (insert_mode
);
7601 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7603 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7606 /* See breakpoint.h. */
7609 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7611 struct breakpoint
*b
;
7613 /* Explicitly tell update_global_location_list to insert
7615 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7616 if (!b
->loc
->inserted
)
7618 delete_breakpoint (b
);
7624 /* Disable any breakpoints that are on code in shared libraries. Only
7625 apply to enabled breakpoints, disabled ones can just stay disabled. */
7628 disable_breakpoints_in_shlibs (void)
7630 struct bp_location
*loc
, **locp_tmp
;
7632 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7634 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7635 struct breakpoint
*b
= loc
->owner
;
7637 /* We apply the check to all breakpoints, including disabled for
7638 those with loc->duplicate set. This is so that when breakpoint
7639 becomes enabled, or the duplicate is removed, gdb will try to
7640 insert all breakpoints. If we don't set shlib_disabled here,
7641 we'll try to insert those breakpoints and fail. */
7642 if (((b
->type
== bp_breakpoint
)
7643 || (b
->type
== bp_jit_event
)
7644 || (b
->type
== bp_hardware_breakpoint
)
7645 || (is_tracepoint (b
)))
7646 && loc
->pspace
== current_program_space
7647 && !loc
->shlib_disabled
7648 && solib_name_from_address (loc
->pspace
, loc
->address
)
7651 loc
->shlib_disabled
= 1;
7656 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7657 notification of unloaded_shlib. Only apply to enabled breakpoints,
7658 disabled ones can just stay disabled. */
7661 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7663 struct bp_location
*loc
, **locp_tmp
;
7664 int disabled_shlib_breaks
= 0;
7666 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7668 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7669 struct breakpoint
*b
= loc
->owner
;
7671 if (solib
->pspace
== loc
->pspace
7672 && !loc
->shlib_disabled
7673 && (((b
->type
== bp_breakpoint
7674 || b
->type
== bp_jit_event
7675 || b
->type
== bp_hardware_breakpoint
)
7676 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7677 || loc
->loc_type
== bp_loc_software_breakpoint
))
7678 || is_tracepoint (b
))
7679 && solib_contains_address_p (solib
, loc
->address
))
7681 loc
->shlib_disabled
= 1;
7682 /* At this point, we cannot rely on remove_breakpoint
7683 succeeding so we must mark the breakpoint as not inserted
7684 to prevent future errors occurring in remove_breakpoints. */
7687 /* This may cause duplicate notifications for the same breakpoint. */
7688 observer_notify_breakpoint_modified (b
);
7690 if (!disabled_shlib_breaks
)
7692 target_terminal::ours_for_output ();
7693 warning (_("Temporarily disabling breakpoints "
7694 "for unloaded shared library \"%s\""),
7697 disabled_shlib_breaks
= 1;
7702 /* Disable any breakpoints and tracepoints in OBJFILE upon
7703 notification of free_objfile. Only apply to enabled breakpoints,
7704 disabled ones can just stay disabled. */
7707 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7709 struct breakpoint
*b
;
7711 if (objfile
== NULL
)
7714 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7715 managed by the user with add-symbol-file/remove-symbol-file.
7716 Similarly to how breakpoints in shared libraries are handled in
7717 response to "nosharedlibrary", mark breakpoints in such modules
7718 shlib_disabled so they end up uninserted on the next global
7719 location list update. Shared libraries not loaded by the user
7720 aren't handled here -- they're already handled in
7721 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7722 solib_unloaded observer. We skip objfiles that are not
7723 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7725 if ((objfile
->flags
& OBJF_SHARED
) == 0
7726 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7731 struct bp_location
*loc
;
7732 int bp_modified
= 0;
7734 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7737 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7739 CORE_ADDR loc_addr
= loc
->address
;
7741 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7742 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7745 if (loc
->shlib_disabled
!= 0)
7748 if (objfile
->pspace
!= loc
->pspace
)
7751 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7752 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7755 if (is_addr_in_objfile (loc_addr
, objfile
))
7757 loc
->shlib_disabled
= 1;
7758 /* At this point, we don't know whether the object was
7759 unmapped from the inferior or not, so leave the
7760 inserted flag alone. We'll handle failure to
7761 uninsert quietly, in case the object was indeed
7764 mark_breakpoint_location_modified (loc
);
7771 observer_notify_breakpoint_modified (b
);
7775 /* FORK & VFORK catchpoints. */
7777 /* An instance of this type is used to represent a fork or vfork
7778 catchpoint. A breakpoint is really of this type iff its ops pointer points
7779 to CATCH_FORK_BREAKPOINT_OPS. */
7781 struct fork_catchpoint
: public breakpoint
7783 /* Process id of a child process whose forking triggered this
7784 catchpoint. This field is only valid immediately after this
7785 catchpoint has triggered. */
7786 ptid_t forked_inferior_pid
;
7789 /* Implement the "insert" breakpoint_ops method for fork
7793 insert_catch_fork (struct bp_location
*bl
)
7795 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7798 /* Implement the "remove" breakpoint_ops method for fork
7802 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7804 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7807 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7811 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7812 const address_space
*aspace
, CORE_ADDR bp_addr
,
7813 const struct target_waitstatus
*ws
)
7815 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7817 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7820 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7824 /* Implement the "print_it" breakpoint_ops method for fork
7827 static enum print_stop_action
7828 print_it_catch_fork (bpstat bs
)
7830 struct ui_out
*uiout
= current_uiout
;
7831 struct breakpoint
*b
= bs
->breakpoint_at
;
7832 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7834 annotate_catchpoint (b
->number
);
7835 maybe_print_thread_hit_breakpoint (uiout
);
7836 if (b
->disposition
== disp_del
)
7837 uiout
->text ("Temporary catchpoint ");
7839 uiout
->text ("Catchpoint ");
7840 if (uiout
->is_mi_like_p ())
7842 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7843 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7845 uiout
->field_int ("bkptno", b
->number
);
7846 uiout
->text (" (forked process ");
7847 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
7848 uiout
->text ("), ");
7849 return PRINT_SRC_AND_LOC
;
7852 /* Implement the "print_one" breakpoint_ops method for fork
7856 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7858 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7859 struct value_print_options opts
;
7860 struct ui_out
*uiout
= current_uiout
;
7862 get_user_print_options (&opts
);
7864 /* Field 4, the address, is omitted (which makes the columns not
7865 line up too nicely with the headers, but the effect is relatively
7867 if (opts
.addressprint
)
7868 uiout
->field_skip ("addr");
7870 uiout
->text ("fork");
7871 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7873 uiout
->text (", process ");
7874 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
7878 if (uiout
->is_mi_like_p ())
7879 uiout
->field_string ("catch-type", "fork");
7882 /* Implement the "print_mention" breakpoint_ops method for fork
7886 print_mention_catch_fork (struct breakpoint
*b
)
7888 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7891 /* Implement the "print_recreate" breakpoint_ops method for fork
7895 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7897 fprintf_unfiltered (fp
, "catch fork");
7898 print_recreate_thread (b
, fp
);
7901 /* The breakpoint_ops structure to be used in fork catchpoints. */
7903 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7905 /* Implement the "insert" breakpoint_ops method for vfork
7909 insert_catch_vfork (struct bp_location
*bl
)
7911 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7914 /* Implement the "remove" breakpoint_ops method for vfork
7918 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7920 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7923 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7927 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7928 const address_space
*aspace
, CORE_ADDR bp_addr
,
7929 const struct target_waitstatus
*ws
)
7931 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7933 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7936 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7940 /* Implement the "print_it" breakpoint_ops method for vfork
7943 static enum print_stop_action
7944 print_it_catch_vfork (bpstat bs
)
7946 struct ui_out
*uiout
= current_uiout
;
7947 struct breakpoint
*b
= bs
->breakpoint_at
;
7948 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7950 annotate_catchpoint (b
->number
);
7951 maybe_print_thread_hit_breakpoint (uiout
);
7952 if (b
->disposition
== disp_del
)
7953 uiout
->text ("Temporary catchpoint ");
7955 uiout
->text ("Catchpoint ");
7956 if (uiout
->is_mi_like_p ())
7958 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7959 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7961 uiout
->field_int ("bkptno", b
->number
);
7962 uiout
->text (" (vforked process ");
7963 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
7964 uiout
->text ("), ");
7965 return PRINT_SRC_AND_LOC
;
7968 /* Implement the "print_one" breakpoint_ops method for vfork
7972 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7974 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7975 struct value_print_options opts
;
7976 struct ui_out
*uiout
= current_uiout
;
7978 get_user_print_options (&opts
);
7979 /* Field 4, the address, is omitted (which makes the columns not
7980 line up too nicely with the headers, but the effect is relatively
7982 if (opts
.addressprint
)
7983 uiout
->field_skip ("addr");
7985 uiout
->text ("vfork");
7986 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7988 uiout
->text (", process ");
7989 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
7993 if (uiout
->is_mi_like_p ())
7994 uiout
->field_string ("catch-type", "vfork");
7997 /* Implement the "print_mention" breakpoint_ops method for vfork
8001 print_mention_catch_vfork (struct breakpoint
*b
)
8003 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8006 /* Implement the "print_recreate" breakpoint_ops method for vfork
8010 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8012 fprintf_unfiltered (fp
, "catch vfork");
8013 print_recreate_thread (b
, fp
);
8016 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8018 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8020 /* An instance of this type is used to represent an solib catchpoint.
8021 A breakpoint is really of this type iff its ops pointer points to
8022 CATCH_SOLIB_BREAKPOINT_OPS. */
8024 struct solib_catchpoint
: public breakpoint
8026 ~solib_catchpoint () override
;
8028 /* True for "catch load", false for "catch unload". */
8029 unsigned char is_load
;
8031 /* Regular expression to match, if any. COMPILED is only valid when
8032 REGEX is non-NULL. */
8034 std::unique_ptr
<compiled_regex
> compiled
;
8037 solib_catchpoint::~solib_catchpoint ()
8039 xfree (this->regex
);
8043 insert_catch_solib (struct bp_location
*ignore
)
8049 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8055 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8056 const address_space
*aspace
,
8058 const struct target_waitstatus
*ws
)
8060 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8061 struct breakpoint
*other
;
8063 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8066 ALL_BREAKPOINTS (other
)
8068 struct bp_location
*other_bl
;
8070 if (other
== bl
->owner
)
8073 if (other
->type
!= bp_shlib_event
)
8076 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8079 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8081 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8090 check_status_catch_solib (struct bpstats
*bs
)
8092 struct solib_catchpoint
*self
8093 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8098 struct so_list
*iter
;
8101 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8106 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8115 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8120 || self
->compiled
->exec (iter
, 0, NULL
, 0) == 0)
8126 bs
->print_it
= print_it_noop
;
8129 static enum print_stop_action
8130 print_it_catch_solib (bpstat bs
)
8132 struct breakpoint
*b
= bs
->breakpoint_at
;
8133 struct ui_out
*uiout
= current_uiout
;
8135 annotate_catchpoint (b
->number
);
8136 maybe_print_thread_hit_breakpoint (uiout
);
8137 if (b
->disposition
== disp_del
)
8138 uiout
->text ("Temporary catchpoint ");
8140 uiout
->text ("Catchpoint ");
8141 uiout
->field_int ("bkptno", b
->number
);
8143 if (uiout
->is_mi_like_p ())
8144 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8145 print_solib_event (1);
8146 return PRINT_SRC_AND_LOC
;
8150 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8152 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8153 struct value_print_options opts
;
8154 struct ui_out
*uiout
= current_uiout
;
8157 get_user_print_options (&opts
);
8158 /* Field 4, the address, is omitted (which makes the columns not
8159 line up too nicely with the headers, but the effect is relatively
8161 if (opts
.addressprint
)
8164 uiout
->field_skip ("addr");
8171 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8173 msg
= xstrdup (_("load of library"));
8178 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8180 msg
= xstrdup (_("unload of library"));
8182 uiout
->field_string ("what", msg
);
8185 if (uiout
->is_mi_like_p ())
8186 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8190 print_mention_catch_solib (struct breakpoint
*b
)
8192 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8194 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8195 self
->is_load
? "load" : "unload");
8199 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8201 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8203 fprintf_unfiltered (fp
, "%s %s",
8204 b
->disposition
== disp_del
? "tcatch" : "catch",
8205 self
->is_load
? "load" : "unload");
8207 fprintf_unfiltered (fp
, " %s", self
->regex
);
8208 fprintf_unfiltered (fp
, "\n");
8211 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8213 /* Shared helper function (MI and CLI) for creating and installing
8214 a shared object event catchpoint. If IS_LOAD is non-zero then
8215 the events to be caught are load events, otherwise they are
8216 unload events. If IS_TEMP is non-zero the catchpoint is a
8217 temporary one. If ENABLED is non-zero the catchpoint is
8218 created in an enabled state. */
8221 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8223 struct gdbarch
*gdbarch
= get_current_arch ();
8227 arg
= skip_spaces (arg
);
8229 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8233 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8234 _("Invalid regexp")));
8235 c
->regex
= xstrdup (arg
);
8238 c
->is_load
= is_load
;
8239 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8240 &catch_solib_breakpoint_ops
);
8242 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8244 install_breakpoint (0, std::move (c
), 1);
8247 /* A helper function that does all the work for "catch load" and
8251 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8252 struct cmd_list_element
*command
)
8255 const int enabled
= 1;
8257 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8259 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8263 catch_load_command_1 (char *arg
, int from_tty
,
8264 struct cmd_list_element
*command
)
8266 catch_load_or_unload (arg
, from_tty
, 1, command
);
8270 catch_unload_command_1 (char *arg
, int from_tty
,
8271 struct cmd_list_element
*command
)
8273 catch_load_or_unload (arg
, from_tty
, 0, command
);
8276 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8277 is non-zero, then make the breakpoint temporary. If COND_STRING is
8278 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8279 the breakpoint_ops structure associated to the catchpoint. */
8282 init_catchpoint (struct breakpoint
*b
,
8283 struct gdbarch
*gdbarch
, int tempflag
,
8284 const char *cond_string
,
8285 const struct breakpoint_ops
*ops
)
8287 symtab_and_line sal
;
8288 sal
.pspace
= current_program_space
;
8290 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8292 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8293 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8297 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8299 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8300 set_breakpoint_number (internal
, b
);
8301 if (is_tracepoint (b
))
8302 set_tracepoint_count (breakpoint_count
);
8305 observer_notify_breakpoint_created (b
);
8308 update_global_location_list (UGLL_MAY_INSERT
);
8312 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8313 int tempflag
, const char *cond_string
,
8314 const struct breakpoint_ops
*ops
)
8316 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8318 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8320 c
->forked_inferior_pid
= null_ptid
;
8322 install_breakpoint (0, std::move (c
), 1);
8325 /* Exec catchpoints. */
8327 /* An instance of this type is used to represent an exec catchpoint.
8328 A breakpoint is really of this type iff its ops pointer points to
8329 CATCH_EXEC_BREAKPOINT_OPS. */
8331 struct exec_catchpoint
: public breakpoint
8333 ~exec_catchpoint () override
;
8335 /* Filename of a program whose exec triggered this catchpoint.
8336 This field is only valid immediately after this catchpoint has
8338 char *exec_pathname
;
8341 /* Exec catchpoint destructor. */
8343 exec_catchpoint::~exec_catchpoint ()
8345 xfree (this->exec_pathname
);
8349 insert_catch_exec (struct bp_location
*bl
)
8351 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8355 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8357 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8361 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8362 const address_space
*aspace
, CORE_ADDR bp_addr
,
8363 const struct target_waitstatus
*ws
)
8365 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8367 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8370 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8374 static enum print_stop_action
8375 print_it_catch_exec (bpstat bs
)
8377 struct ui_out
*uiout
= current_uiout
;
8378 struct breakpoint
*b
= bs
->breakpoint_at
;
8379 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8381 annotate_catchpoint (b
->number
);
8382 maybe_print_thread_hit_breakpoint (uiout
);
8383 if (b
->disposition
== disp_del
)
8384 uiout
->text ("Temporary catchpoint ");
8386 uiout
->text ("Catchpoint ");
8387 if (uiout
->is_mi_like_p ())
8389 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8390 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8392 uiout
->field_int ("bkptno", b
->number
);
8393 uiout
->text (" (exec'd ");
8394 uiout
->field_string ("new-exec", c
->exec_pathname
);
8395 uiout
->text ("), ");
8397 return PRINT_SRC_AND_LOC
;
8401 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8403 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8404 struct value_print_options opts
;
8405 struct ui_out
*uiout
= current_uiout
;
8407 get_user_print_options (&opts
);
8409 /* Field 4, the address, is omitted (which makes the columns
8410 not line up too nicely with the headers, but the effect
8411 is relatively readable). */
8412 if (opts
.addressprint
)
8413 uiout
->field_skip ("addr");
8415 uiout
->text ("exec");
8416 if (c
->exec_pathname
!= NULL
)
8418 uiout
->text (", program \"");
8419 uiout
->field_string ("what", c
->exec_pathname
);
8420 uiout
->text ("\" ");
8423 if (uiout
->is_mi_like_p ())
8424 uiout
->field_string ("catch-type", "exec");
8428 print_mention_catch_exec (struct breakpoint
*b
)
8430 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8433 /* Implement the "print_recreate" breakpoint_ops method for exec
8437 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8439 fprintf_unfiltered (fp
, "catch exec");
8440 print_recreate_thread (b
, fp
);
8443 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8446 hw_breakpoint_used_count (void)
8449 struct breakpoint
*b
;
8450 struct bp_location
*bl
;
8454 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8455 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8457 /* Special types of hardware breakpoints may use more than
8459 i
+= b
->ops
->resources_needed (bl
);
8466 /* Returns the resources B would use if it were a hardware
8470 hw_watchpoint_use_count (struct breakpoint
*b
)
8473 struct bp_location
*bl
;
8475 if (!breakpoint_enabled (b
))
8478 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8480 /* Special types of hardware watchpoints may use more than
8482 i
+= b
->ops
->resources_needed (bl
);
8488 /* Returns the sum the used resources of all hardware watchpoints of
8489 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8490 the sum of the used resources of all hardware watchpoints of other
8491 types _not_ TYPE. */
8494 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8495 enum bptype type
, int *other_type_used
)
8498 struct breakpoint
*b
;
8500 *other_type_used
= 0;
8505 if (!breakpoint_enabled (b
))
8508 if (b
->type
== type
)
8509 i
+= hw_watchpoint_use_count (b
);
8510 else if (is_hardware_watchpoint (b
))
8511 *other_type_used
= 1;
8518 disable_watchpoints_before_interactive_call_start (void)
8520 struct breakpoint
*b
;
8524 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8526 b
->enable_state
= bp_call_disabled
;
8527 update_global_location_list (UGLL_DONT_INSERT
);
8533 enable_watchpoints_after_interactive_call_stop (void)
8535 struct breakpoint
*b
;
8539 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8541 b
->enable_state
= bp_enabled
;
8542 update_global_location_list (UGLL_MAY_INSERT
);
8548 disable_breakpoints_before_startup (void)
8550 current_program_space
->executing_startup
= 1;
8551 update_global_location_list (UGLL_DONT_INSERT
);
8555 enable_breakpoints_after_startup (void)
8557 current_program_space
->executing_startup
= 0;
8558 breakpoint_re_set ();
8561 /* Create a new single-step breakpoint for thread THREAD, with no
8564 static struct breakpoint
*
8565 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8567 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8569 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8570 &momentary_breakpoint_ops
);
8572 b
->disposition
= disp_donttouch
;
8573 b
->frame_id
= null_frame_id
;
8576 gdb_assert (b
->thread
!= 0);
8578 return add_to_breakpoint_chain (std::move (b
));
8581 /* Set a momentary breakpoint of type TYPE at address specified by
8582 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8586 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8587 struct frame_id frame_id
, enum bptype type
)
8589 struct breakpoint
*b
;
8591 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8593 gdb_assert (!frame_id_artificial_p (frame_id
));
8595 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8596 b
->enable_state
= bp_enabled
;
8597 b
->disposition
= disp_donttouch
;
8598 b
->frame_id
= frame_id
;
8600 /* If we're debugging a multi-threaded program, then we want
8601 momentary breakpoints to be active in only a single thread of
8603 if (in_thread_list (inferior_ptid
))
8604 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8606 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8608 return breakpoint_up (b
);
8611 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8612 The new breakpoint will have type TYPE, use OPS as its
8613 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8615 static struct breakpoint
*
8616 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8618 const struct breakpoint_ops
*ops
,
8621 struct breakpoint
*copy
;
8623 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8624 copy
->loc
= allocate_bp_location (copy
);
8625 set_breakpoint_location_function (copy
->loc
, 1);
8627 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8628 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8629 copy
->loc
->address
= orig
->loc
->address
;
8630 copy
->loc
->section
= orig
->loc
->section
;
8631 copy
->loc
->pspace
= orig
->loc
->pspace
;
8632 copy
->loc
->probe
= orig
->loc
->probe
;
8633 copy
->loc
->line_number
= orig
->loc
->line_number
;
8634 copy
->loc
->symtab
= orig
->loc
->symtab
;
8635 copy
->loc
->enabled
= loc_enabled
;
8636 copy
->frame_id
= orig
->frame_id
;
8637 copy
->thread
= orig
->thread
;
8638 copy
->pspace
= orig
->pspace
;
8640 copy
->enable_state
= bp_enabled
;
8641 copy
->disposition
= disp_donttouch
;
8642 copy
->number
= internal_breakpoint_number
--;
8644 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8648 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8652 clone_momentary_breakpoint (struct breakpoint
*orig
)
8654 /* If there's nothing to clone, then return nothing. */
8658 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8662 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8665 struct symtab_and_line sal
;
8667 sal
= find_pc_line (pc
, 0);
8669 sal
.section
= find_pc_overlay (pc
);
8670 sal
.explicit_pc
= 1;
8672 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8676 /* Tell the user we have just set a breakpoint B. */
8679 mention (struct breakpoint
*b
)
8681 b
->ops
->print_mention (b
);
8682 if (current_uiout
->is_mi_like_p ())
8684 printf_filtered ("\n");
8688 static int bp_loc_is_permanent (struct bp_location
*loc
);
8690 static struct bp_location
*
8691 add_location_to_breakpoint (struct breakpoint
*b
,
8692 const struct symtab_and_line
*sal
)
8694 struct bp_location
*loc
, **tmp
;
8695 CORE_ADDR adjusted_address
;
8696 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8698 if (loc_gdbarch
== NULL
)
8699 loc_gdbarch
= b
->gdbarch
;
8701 /* Adjust the breakpoint's address prior to allocating a location.
8702 Once we call allocate_bp_location(), that mostly uninitialized
8703 location will be placed on the location chain. Adjustment of the
8704 breakpoint may cause target_read_memory() to be called and we do
8705 not want its scan of the location chain to find a breakpoint and
8706 location that's only been partially initialized. */
8707 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8710 /* Sort the locations by their ADDRESS. */
8711 loc
= allocate_bp_location (b
);
8712 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8713 tmp
= &((*tmp
)->next
))
8718 loc
->requested_address
= sal
->pc
;
8719 loc
->address
= adjusted_address
;
8720 loc
->pspace
= sal
->pspace
;
8721 loc
->probe
.probe
= sal
->probe
;
8722 loc
->probe
.objfile
= sal
->objfile
;
8723 gdb_assert (loc
->pspace
!= NULL
);
8724 loc
->section
= sal
->section
;
8725 loc
->gdbarch
= loc_gdbarch
;
8726 loc
->line_number
= sal
->line
;
8727 loc
->symtab
= sal
->symtab
;
8728 loc
->symbol
= sal
->symbol
;
8730 set_breakpoint_location_function (loc
,
8731 sal
->explicit_pc
|| sal
->explicit_line
);
8733 /* While by definition, permanent breakpoints are already present in the
8734 code, we don't mark the location as inserted. Normally one would expect
8735 that GDB could rely on that breakpoint instruction to stop the program,
8736 thus removing the need to insert its own breakpoint, except that executing
8737 the breakpoint instruction can kill the target instead of reporting a
8738 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8739 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8740 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8741 breakpoint be inserted normally results in QEMU knowing about the GDB
8742 breakpoint, and thus trap before the breakpoint instruction is executed.
8743 (If GDB later needs to continue execution past the permanent breakpoint,
8744 it manually increments the PC, thus avoiding executing the breakpoint
8746 if (bp_loc_is_permanent (loc
))
8753 /* See breakpoint.h. */
8756 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8760 const gdb_byte
*bpoint
;
8761 gdb_byte
*target_mem
;
8764 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8766 /* Software breakpoints unsupported? */
8770 target_mem
= (gdb_byte
*) alloca (len
);
8772 /* Enable the automatic memory restoration from breakpoints while
8773 we read the memory. Otherwise we could say about our temporary
8774 breakpoints they are permanent. */
8775 scoped_restore restore_memory
8776 = make_scoped_restore_show_memory_breakpoints (0);
8778 if (target_read_memory (address
, target_mem
, len
) == 0
8779 && memcmp (target_mem
, bpoint
, len
) == 0)
8785 /* Return 1 if LOC is pointing to a permanent breakpoint,
8786 return 0 otherwise. */
8789 bp_loc_is_permanent (struct bp_location
*loc
)
8791 gdb_assert (loc
!= NULL
);
8793 /* If we have a catchpoint or a watchpoint, just return 0. We should not
8794 attempt to read from the addresses the locations of these breakpoint types
8795 point to. program_breakpoint_here_p, below, will attempt to read
8797 if (!breakpoint_address_is_meaningful (loc
->owner
))
8800 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8801 switch_to_program_space_and_thread (loc
->pspace
);
8802 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8805 /* Build a command list for the dprintf corresponding to the current
8806 settings of the dprintf style options. */
8809 update_dprintf_command_list (struct breakpoint
*b
)
8811 char *dprintf_args
= b
->extra_string
;
8812 char *printf_line
= NULL
;
8817 dprintf_args
= skip_spaces (dprintf_args
);
8819 /* Allow a comma, as it may have terminated a location, but don't
8821 if (*dprintf_args
== ',')
8823 dprintf_args
= skip_spaces (dprintf_args
);
8825 if (*dprintf_args
!= '"')
8826 error (_("Bad format string, missing '\"'."));
8828 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8829 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8830 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8832 if (!dprintf_function
)
8833 error (_("No function supplied for dprintf call"));
8835 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8836 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8841 printf_line
= xstrprintf ("call (void) %s (%s)",
8845 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8847 if (target_can_run_breakpoint_commands ())
8848 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8851 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8852 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8856 internal_error (__FILE__
, __LINE__
,
8857 _("Invalid dprintf style."));
8859 gdb_assert (printf_line
!= NULL
);
8860 /* Manufacture a printf sequence. */
8862 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
8864 printf_cmd_line
->control_type
= simple_control
;
8865 printf_cmd_line
->body_count
= 0;
8866 printf_cmd_line
->body_list
= NULL
;
8867 printf_cmd_line
->next
= NULL
;
8868 printf_cmd_line
->line
= printf_line
;
8870 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
8874 /* Update all dprintf commands, making their command lists reflect
8875 current style settings. */
8878 update_dprintf_commands (char *args
, int from_tty
,
8879 struct cmd_list_element
*c
)
8881 struct breakpoint
*b
;
8885 if (b
->type
== bp_dprintf
)
8886 update_dprintf_command_list (b
);
8890 /* Create a breakpoint with SAL as location. Use LOCATION
8891 as a description of the location, and COND_STRING
8892 as condition expression. If LOCATION is NULL then create an
8893 "address location" from the address in the SAL. */
8896 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8897 gdb::array_view
<const symtab_and_line
> sals
,
8898 event_location_up
&&location
,
8899 gdb::unique_xmalloc_ptr
<char> filter
,
8900 gdb::unique_xmalloc_ptr
<char> cond_string
,
8901 gdb::unique_xmalloc_ptr
<char> extra_string
,
8902 enum bptype type
, enum bpdisp disposition
,
8903 int thread
, int task
, int ignore_count
,
8904 const struct breakpoint_ops
*ops
, int from_tty
,
8905 int enabled
, int internal
, unsigned flags
,
8906 int display_canonical
)
8910 if (type
== bp_hardware_breakpoint
)
8912 int target_resources_ok
;
8914 i
= hw_breakpoint_used_count ();
8915 target_resources_ok
=
8916 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8918 if (target_resources_ok
== 0)
8919 error (_("No hardware breakpoint support in the target."));
8920 else if (target_resources_ok
< 0)
8921 error (_("Hardware breakpoints used exceeds limit."));
8924 gdb_assert (!sals
.empty ());
8926 for (const auto &sal
: sals
)
8928 struct bp_location
*loc
;
8932 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8934 loc_gdbarch
= gdbarch
;
8936 describe_other_breakpoints (loc_gdbarch
,
8937 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8940 if (&sal
== &sals
[0])
8942 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8946 b
->cond_string
= cond_string
.release ();
8947 b
->extra_string
= extra_string
.release ();
8948 b
->ignore_count
= ignore_count
;
8949 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8950 b
->disposition
= disposition
;
8952 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8953 b
->loc
->inserted
= 1;
8955 if (type
== bp_static_tracepoint
)
8957 struct tracepoint
*t
= (struct tracepoint
*) b
;
8958 struct static_tracepoint_marker marker
;
8960 if (strace_marker_p (b
))
8962 /* We already know the marker exists, otherwise, we
8963 wouldn't see a sal for it. */
8965 = &event_location_to_string (b
->location
.get ())[3];
8969 p
= skip_spaces (p
);
8971 endp
= skip_to_space (p
);
8973 marker_str
= savestring (p
, endp
- p
);
8974 t
->static_trace_marker_id
= marker_str
;
8976 printf_filtered (_("Probed static tracepoint "
8978 t
->static_trace_marker_id
);
8980 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
8982 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
8983 release_static_tracepoint_marker (&marker
);
8985 printf_filtered (_("Probed static tracepoint "
8987 t
->static_trace_marker_id
);
8990 warning (_("Couldn't determine the static "
8991 "tracepoint marker to probe"));
8998 loc
= add_location_to_breakpoint (b
, &sal
);
8999 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9005 const char *arg
= b
->cond_string
;
9007 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9008 block_for_pc (loc
->address
), 0);
9010 error (_("Garbage '%s' follows condition"), arg
);
9013 /* Dynamic printf requires and uses additional arguments on the
9014 command line, otherwise it's an error. */
9015 if (type
== bp_dprintf
)
9017 if (b
->extra_string
)
9018 update_dprintf_command_list (b
);
9020 error (_("Format string required"));
9022 else if (b
->extra_string
)
9023 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9026 b
->display_canonical
= display_canonical
;
9027 if (location
!= NULL
)
9028 b
->location
= std::move (location
);
9030 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9031 b
->filter
= filter
.release ();
9035 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9036 gdb::array_view
<const symtab_and_line
> sals
,
9037 event_location_up
&&location
,
9038 gdb::unique_xmalloc_ptr
<char> filter
,
9039 gdb::unique_xmalloc_ptr
<char> cond_string
,
9040 gdb::unique_xmalloc_ptr
<char> extra_string
,
9041 enum bptype type
, enum bpdisp disposition
,
9042 int thread
, int task
, int ignore_count
,
9043 const struct breakpoint_ops
*ops
, int from_tty
,
9044 int enabled
, int internal
, unsigned flags
,
9045 int display_canonical
)
9047 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9049 init_breakpoint_sal (b
.get (), gdbarch
,
9050 sals
, std::move (location
),
9052 std::move (cond_string
),
9053 std::move (extra_string
),
9055 thread
, task
, ignore_count
,
9057 enabled
, internal
, flags
,
9060 install_breakpoint (internal
, std::move (b
), 0);
9063 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9064 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9065 value. COND_STRING, if not NULL, specified the condition to be
9066 used for all breakpoints. Essentially the only case where
9067 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9068 function. In that case, it's still not possible to specify
9069 separate conditions for different overloaded functions, so
9070 we take just a single condition string.
9072 NOTE: If the function succeeds, the caller is expected to cleanup
9073 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9074 array contents). If the function fails (error() is called), the
9075 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9076 COND and SALS arrays and each of those arrays contents. */
9079 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9080 struct linespec_result
*canonical
,
9081 gdb::unique_xmalloc_ptr
<char> cond_string
,
9082 gdb::unique_xmalloc_ptr
<char> extra_string
,
9083 enum bptype type
, enum bpdisp disposition
,
9084 int thread
, int task
, int ignore_count
,
9085 const struct breakpoint_ops
*ops
, int from_tty
,
9086 int enabled
, int internal
, unsigned flags
)
9088 if (canonical
->pre_expanded
)
9089 gdb_assert (canonical
->lsals
.size () == 1);
9091 for (const auto &lsal
: canonical
->lsals
)
9093 /* Note that 'location' can be NULL in the case of a plain
9094 'break', without arguments. */
9095 event_location_up location
9096 = (canonical
->location
!= NULL
9097 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9098 gdb::unique_xmalloc_ptr
<char> filter_string
9099 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9101 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9102 std::move (location
),
9103 std::move (filter_string
),
9104 std::move (cond_string
),
9105 std::move (extra_string
),
9107 thread
, task
, ignore_count
, ops
,
9108 from_tty
, enabled
, internal
, flags
,
9109 canonical
->special_display
);
9113 /* Parse LOCATION which is assumed to be a SAL specification possibly
9114 followed by conditionals. On return, SALS contains an array of SAL
9115 addresses found. LOCATION points to the end of the SAL (for
9116 linespec locations).
9118 The array and the line spec strings are allocated on the heap, it is
9119 the caller's responsibility to free them. */
9122 parse_breakpoint_sals (const struct event_location
*location
,
9123 struct linespec_result
*canonical
)
9125 struct symtab_and_line cursal
;
9127 if (event_location_type (location
) == LINESPEC_LOCATION
)
9129 const char *address
= get_linespec_location (location
);
9131 if (address
== NULL
)
9133 /* The last displayed codepoint, if it's valid, is our default
9134 breakpoint address. */
9135 if (last_displayed_sal_is_valid ())
9137 /* Set sal's pspace, pc, symtab, and line to the values
9138 corresponding to the last call to print_frame_info.
9139 Be sure to reinitialize LINE with NOTCURRENT == 0
9140 as the breakpoint line number is inappropriate otherwise.
9141 find_pc_line would adjust PC, re-set it back. */
9142 symtab_and_line sal
= get_last_displayed_sal ();
9143 CORE_ADDR pc
= sal
.pc
;
9145 sal
= find_pc_line (pc
, 0);
9147 /* "break" without arguments is equivalent to "break *PC"
9148 where PC is the last displayed codepoint's address. So
9149 make sure to set sal.explicit_pc to prevent GDB from
9150 trying to expand the list of sals to include all other
9151 instances with the same symtab and line. */
9153 sal
.explicit_pc
= 1;
9155 struct linespec_sals lsal
;
9157 lsal
.canonical
= NULL
;
9159 canonical
->lsals
.push_back (std::move (lsal
));
9163 error (_("No default breakpoint address now."));
9167 /* Force almost all breakpoints to be in terms of the
9168 current_source_symtab (which is decode_line_1's default).
9169 This should produce the results we want almost all of the
9170 time while leaving default_breakpoint_* alone.
9172 ObjC: However, don't match an Objective-C method name which
9173 may have a '+' or '-' succeeded by a '['. */
9174 cursal
= get_current_source_symtab_and_line ();
9175 if (last_displayed_sal_is_valid ())
9177 const char *address
= NULL
;
9179 if (event_location_type (location
) == LINESPEC_LOCATION
)
9180 address
= get_linespec_location (location
);
9184 && strchr ("+-", address
[0]) != NULL
9185 && address
[1] != '['))
9187 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9188 get_last_displayed_symtab (),
9189 get_last_displayed_line (),
9190 canonical
, NULL
, NULL
);
9195 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9196 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9200 /* Convert each SAL into a real PC. Verify that the PC can be
9201 inserted as a breakpoint. If it can't throw an error. */
9204 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9206 for (auto &sal
: sals
)
9207 resolve_sal_pc (&sal
);
9210 /* Fast tracepoints may have restrictions on valid locations. For
9211 instance, a fast tracepoint using a jump instead of a trap will
9212 likely have to overwrite more bytes than a trap would, and so can
9213 only be placed where the instruction is longer than the jump, or a
9214 multi-instruction sequence does not have a jump into the middle of
9218 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9219 gdb::array_view
<const symtab_and_line
> sals
)
9223 struct cleanup
*old_chain
;
9225 for (const auto &sal
: sals
)
9227 struct gdbarch
*sarch
;
9229 sarch
= get_sal_arch (sal
);
9230 /* We fall back to GDBARCH if there is no architecture
9231 associated with SAL. */
9234 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
);
9235 old_chain
= make_cleanup (xfree
, msg
);
9238 error (_("May not have a fast tracepoint at %s%s"),
9239 paddress (sarch
, sal
.pc
), (msg
? msg
: ""));
9241 do_cleanups (old_chain
);
9245 /* Given TOK, a string specification of condition and thread, as
9246 accepted by the 'break' command, extract the condition
9247 string and thread number and set *COND_STRING and *THREAD.
9248 PC identifies the context at which the condition should be parsed.
9249 If no condition is found, *COND_STRING is set to NULL.
9250 If no thread is found, *THREAD is set to -1. */
9253 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9254 char **cond_string
, int *thread
, int *task
,
9257 *cond_string
= NULL
;
9264 const char *end_tok
;
9266 const char *cond_start
= NULL
;
9267 const char *cond_end
= NULL
;
9269 tok
= skip_spaces (tok
);
9271 if ((*tok
== '"' || *tok
== ',') && rest
)
9273 *rest
= savestring (tok
, strlen (tok
));
9277 end_tok
= skip_to_space (tok
);
9279 toklen
= end_tok
- tok
;
9281 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9283 tok
= cond_start
= end_tok
+ 1;
9284 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9286 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9288 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9291 struct thread_info
*thr
;
9294 thr
= parse_thread_id (tok
, &tmptok
);
9296 error (_("Junk after thread keyword."));
9297 *thread
= thr
->global_num
;
9300 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9305 *task
= strtol (tok
, &tmptok
, 0);
9307 error (_("Junk after task keyword."));
9308 if (!valid_task_id (*task
))
9309 error (_("Unknown task %d."), *task
);
9314 *rest
= savestring (tok
, strlen (tok
));
9318 error (_("Junk at end of arguments."));
9322 /* Decode a static tracepoint marker spec. */
9324 static std::vector
<symtab_and_line
>
9325 decode_static_tracepoint_spec (const char **arg_p
)
9327 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9328 const char *p
= &(*arg_p
)[3];
9332 p
= skip_spaces (p
);
9334 endp
= skip_to_space (p
);
9336 std::string
marker_str (p
, endp
- p
);
9338 markers
= target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9339 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9340 error (_("No known static tracepoint marker named %s"),
9341 marker_str
.c_str ());
9343 std::vector
<symtab_and_line
> sals
;
9344 sals
.reserve (VEC_length(static_tracepoint_marker_p
, markers
));
9346 for (i
= 0; i
< VEC_length(static_tracepoint_marker_p
, markers
); i
++)
9348 struct static_tracepoint_marker
*marker
;
9350 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9352 symtab_and_line sal
= find_pc_line (marker
->address
, 0);
9353 sal
.pc
= marker
->address
;
9354 sals
.push_back (sal
);
9356 release_static_tracepoint_marker (marker
);
9363 /* See breakpoint.h. */
9366 create_breakpoint (struct gdbarch
*gdbarch
,
9367 const struct event_location
*location
,
9368 const char *cond_string
,
9369 int thread
, const char *extra_string
,
9371 int tempflag
, enum bptype type_wanted
,
9373 enum auto_boolean pending_break_support
,
9374 const struct breakpoint_ops
*ops
,
9375 int from_tty
, int enabled
, int internal
,
9378 struct linespec_result canonical
;
9379 struct cleanup
*bkpt_chain
= NULL
;
9382 int prev_bkpt_count
= breakpoint_count
;
9384 gdb_assert (ops
!= NULL
);
9386 /* If extra_string isn't useful, set it to NULL. */
9387 if (extra_string
!= NULL
&& *extra_string
== '\0')
9388 extra_string
= NULL
;
9392 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9394 CATCH (e
, RETURN_MASK_ERROR
)
9396 /* If caller is interested in rc value from parse, set
9398 if (e
.error
== NOT_FOUND_ERROR
)
9400 /* If pending breakpoint support is turned off, throw
9403 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9404 throw_exception (e
);
9406 exception_print (gdb_stderr
, e
);
9408 /* If pending breakpoint support is auto query and the user
9409 selects no, then simply return the error code. */
9410 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9411 && !nquery (_("Make %s pending on future shared library load? "),
9412 bptype_string (type_wanted
)))
9415 /* At this point, either the user was queried about setting
9416 a pending breakpoint and selected yes, or pending
9417 breakpoint behavior is on and thus a pending breakpoint
9418 is defaulted on behalf of the user. */
9422 throw_exception (e
);
9426 if (!pending
&& canonical
.lsals
.empty ())
9429 /* ----------------------------- SNIP -----------------------------
9430 Anything added to the cleanup chain beyond this point is assumed
9431 to be part of a breakpoint. If the breakpoint create succeeds
9432 then the memory is not reclaimed. */
9433 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9435 /* Resolve all line numbers to PC's and verify that the addresses
9436 are ok for the target. */
9439 for (auto &lsal
: canonical
.lsals
)
9440 breakpoint_sals_to_pc (lsal
.sals
);
9443 /* Fast tracepoints may have additional restrictions on location. */
9444 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9446 for (const auto &lsal
: canonical
.lsals
)
9447 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9450 /* Verify that condition can be parsed, before setting any
9451 breakpoints. Allocate a separate condition expression for each
9455 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9456 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9463 const linespec_sals
&lsal
= canonical
.lsals
[0];
9465 /* Here we only parse 'arg' to separate condition
9466 from thread number, so parsing in context of first
9467 sal is OK. When setting the breakpoint we'll
9468 re-parse it in context of each sal. */
9470 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9471 &cond
, &thread
, &task
, &rest
);
9472 cond_string_copy
.reset (cond
);
9473 extra_string_copy
.reset (rest
);
9477 if (type_wanted
!= bp_dprintf
9478 && extra_string
!= NULL
&& *extra_string
!= '\0')
9479 error (_("Garbage '%s' at end of location"), extra_string
);
9481 /* Create a private copy of condition string. */
9483 cond_string_copy
.reset (xstrdup (cond_string
));
9484 /* Create a private copy of any extra string. */
9486 extra_string_copy
.reset (xstrdup (extra_string
));
9489 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9490 std::move (cond_string_copy
),
9491 std::move (extra_string_copy
),
9493 tempflag
? disp_del
: disp_donttouch
,
9494 thread
, task
, ignore_count
, ops
,
9495 from_tty
, enabled
, internal
, flags
);
9499 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9501 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9502 b
->location
= copy_event_location (location
);
9505 b
->cond_string
= NULL
;
9508 /* Create a private copy of condition string. */
9509 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9513 /* Create a private copy of any extra string. */
9514 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9515 b
->ignore_count
= ignore_count
;
9516 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9517 b
->condition_not_parsed
= 1;
9518 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9519 if ((type_wanted
!= bp_breakpoint
9520 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9521 b
->pspace
= current_program_space
;
9523 install_breakpoint (internal
, std::move (b
), 0);
9526 if (canonical
.lsals
.size () > 1)
9528 warning (_("Multiple breakpoints were set.\nUse the "
9529 "\"delete\" command to delete unwanted breakpoints."));
9530 prev_breakpoint_count
= prev_bkpt_count
;
9533 /* That's it. Discard the cleanups for data inserted into the
9535 discard_cleanups (bkpt_chain
);
9537 /* error call may happen here - have BKPT_CHAIN already discarded. */
9538 update_global_location_list (UGLL_MAY_INSERT
);
9543 /* Set a breakpoint.
9544 ARG is a string describing breakpoint address,
9545 condition, and thread.
9546 FLAG specifies if a breakpoint is hardware on,
9547 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9551 break_command_1 (const char *arg
, int flag
, int from_tty
)
9553 int tempflag
= flag
& BP_TEMPFLAG
;
9554 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9555 ? bp_hardware_breakpoint
9557 struct breakpoint_ops
*ops
;
9559 event_location_up location
= string_to_event_location (&arg
, current_language
);
9561 /* Matching breakpoints on probes. */
9562 if (location
!= NULL
9563 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9564 ops
= &bkpt_probe_breakpoint_ops
;
9566 ops
= &bkpt_breakpoint_ops
;
9568 create_breakpoint (get_current_arch (),
9570 NULL
, 0, arg
, 1 /* parse arg */,
9571 tempflag
, type_wanted
,
9572 0 /* Ignore count */,
9573 pending_break_support
,
9581 /* Helper function for break_command_1 and disassemble_command. */
9584 resolve_sal_pc (struct symtab_and_line
*sal
)
9588 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9590 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9591 error (_("No line %d in file \"%s\"."),
9592 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9595 /* If this SAL corresponds to a breakpoint inserted using a line
9596 number, then skip the function prologue if necessary. */
9597 if (sal
->explicit_line
)
9598 skip_prologue_sal (sal
);
9601 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9603 const struct blockvector
*bv
;
9604 const struct block
*b
;
9607 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9608 SYMTAB_COMPUNIT (sal
->symtab
));
9611 sym
= block_linkage_function (b
);
9614 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9615 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9620 /* It really is worthwhile to have the section, so we'll
9621 just have to look harder. This case can be executed
9622 if we have line numbers but no functions (as can
9623 happen in assembly source). */
9625 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9626 switch_to_program_space_and_thread (sal
->pspace
);
9628 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9630 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9637 break_command (char *arg
, int from_tty
)
9639 break_command_1 (arg
, 0, from_tty
);
9643 tbreak_command (char *arg
, int from_tty
)
9645 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9649 hbreak_command (char *arg
, int from_tty
)
9651 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9655 thbreak_command (char *arg
, int from_tty
)
9657 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9661 stop_command (char *arg
, int from_tty
)
9663 printf_filtered (_("Specify the type of breakpoint to set.\n\
9664 Usage: stop in <function | address>\n\
9665 stop at <line>\n"));
9669 stopin_command (const char *arg
, int from_tty
)
9673 if (arg
== (char *) NULL
)
9675 else if (*arg
!= '*')
9677 const char *argptr
= arg
;
9680 /* Look for a ':'. If this is a line number specification, then
9681 say it is bad, otherwise, it should be an address or
9682 function/method name. */
9683 while (*argptr
&& !hasColon
)
9685 hasColon
= (*argptr
== ':');
9690 badInput
= (*argptr
!= ':'); /* Not a class::method */
9692 badInput
= isdigit (*arg
); /* a simple line number */
9696 printf_filtered (_("Usage: stop in <function | address>\n"));
9698 break_command_1 (arg
, 0, from_tty
);
9702 stopat_command (const char *arg
, int from_tty
)
9706 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9710 const char *argptr
= arg
;
9713 /* Look for a ':'. If there is a '::' then get out, otherwise
9714 it is probably a line number. */
9715 while (*argptr
&& !hasColon
)
9717 hasColon
= (*argptr
== ':');
9722 badInput
= (*argptr
== ':'); /* we have class::method */
9724 badInput
= !isdigit (*arg
); /* not a line number */
9728 printf_filtered (_("Usage: stop at <line>\n"));
9730 break_command_1 (arg
, 0, from_tty
);
9733 /* The dynamic printf command is mostly like a regular breakpoint, but
9734 with a prewired command list consisting of a single output command,
9735 built from extra arguments supplied on the dprintf command
9739 dprintf_command (char *arg_in
, int from_tty
)
9741 const char *arg
= arg_in
;
9742 event_location_up location
= string_to_event_location (&arg
, current_language
);
9744 /* If non-NULL, ARG should have been advanced past the location;
9745 the next character must be ','. */
9748 if (arg
[0] != ',' || arg
[1] == '\0')
9749 error (_("Format string required"));
9752 /* Skip the comma. */
9757 create_breakpoint (get_current_arch (),
9759 NULL
, 0, arg
, 1 /* parse arg */,
9761 0 /* Ignore count */,
9762 pending_break_support
,
9763 &dprintf_breakpoint_ops
,
9771 agent_printf_command (char *arg
, int from_tty
)
9773 error (_("May only run agent-printf on the target"));
9776 /* Implement the "breakpoint_hit" breakpoint_ops method for
9777 ranged breakpoints. */
9780 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9781 const address_space
*aspace
,
9783 const struct target_waitstatus
*ws
)
9785 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9786 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9789 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9790 bl
->length
, aspace
, bp_addr
);
9793 /* Implement the "resources_needed" breakpoint_ops method for
9794 ranged breakpoints. */
9797 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9799 return target_ranged_break_num_registers ();
9802 /* Implement the "print_it" breakpoint_ops method for
9803 ranged breakpoints. */
9805 static enum print_stop_action
9806 print_it_ranged_breakpoint (bpstat bs
)
9808 struct breakpoint
*b
= bs
->breakpoint_at
;
9809 struct bp_location
*bl
= b
->loc
;
9810 struct ui_out
*uiout
= current_uiout
;
9812 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9814 /* Ranged breakpoints have only one location. */
9815 gdb_assert (bl
&& bl
->next
== NULL
);
9817 annotate_breakpoint (b
->number
);
9819 maybe_print_thread_hit_breakpoint (uiout
);
9821 if (b
->disposition
== disp_del
)
9822 uiout
->text ("Temporary ranged breakpoint ");
9824 uiout
->text ("Ranged breakpoint ");
9825 if (uiout
->is_mi_like_p ())
9827 uiout
->field_string ("reason",
9828 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9829 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9831 uiout
->field_int ("bkptno", b
->number
);
9834 return PRINT_SRC_AND_LOC
;
9837 /* Implement the "print_one" breakpoint_ops method for
9838 ranged breakpoints. */
9841 print_one_ranged_breakpoint (struct breakpoint
*b
,
9842 struct bp_location
**last_loc
)
9844 struct bp_location
*bl
= b
->loc
;
9845 struct value_print_options opts
;
9846 struct ui_out
*uiout
= current_uiout
;
9848 /* Ranged breakpoints have only one location. */
9849 gdb_assert (bl
&& bl
->next
== NULL
);
9851 get_user_print_options (&opts
);
9853 if (opts
.addressprint
)
9854 /* We don't print the address range here, it will be printed later
9855 by print_one_detail_ranged_breakpoint. */
9856 uiout
->field_skip ("addr");
9858 print_breakpoint_location (b
, bl
);
9862 /* Implement the "print_one_detail" breakpoint_ops method for
9863 ranged breakpoints. */
9866 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9867 struct ui_out
*uiout
)
9869 CORE_ADDR address_start
, address_end
;
9870 struct bp_location
*bl
= b
->loc
;
9875 address_start
= bl
->address
;
9876 address_end
= address_start
+ bl
->length
- 1;
9878 uiout
->text ("\taddress range: ");
9879 stb
.printf ("[%s, %s]",
9880 print_core_address (bl
->gdbarch
, address_start
),
9881 print_core_address (bl
->gdbarch
, address_end
));
9882 uiout
->field_stream ("addr", stb
);
9886 /* Implement the "print_mention" breakpoint_ops method for
9887 ranged breakpoints. */
9890 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9892 struct bp_location
*bl
= b
->loc
;
9893 struct ui_out
*uiout
= current_uiout
;
9896 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9898 if (uiout
->is_mi_like_p ())
9901 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9902 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9903 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9906 /* Implement the "print_recreate" breakpoint_ops method for
9907 ranged breakpoints. */
9910 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9912 fprintf_unfiltered (fp
, "break-range %s, %s",
9913 event_location_to_string (b
->location
.get ()),
9914 event_location_to_string (b
->location_range_end
.get ()));
9915 print_recreate_thread (b
, fp
);
9918 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9920 static struct breakpoint_ops ranged_breakpoint_ops
;
9922 /* Find the address where the end of the breakpoint range should be
9923 placed, given the SAL of the end of the range. This is so that if
9924 the user provides a line number, the end of the range is set to the
9925 last instruction of the given line. */
9928 find_breakpoint_range_end (struct symtab_and_line sal
)
9932 /* If the user provided a PC value, use it. Otherwise,
9933 find the address of the end of the given location. */
9934 if (sal
.explicit_pc
)
9941 ret
= find_line_pc_range (sal
, &start
, &end
);
9943 error (_("Could not find location of the end of the range."));
9945 /* find_line_pc_range returns the start of the next line. */
9952 /* Implement the "break-range" CLI command. */
9955 break_range_command (char *arg_in
, int from_tty
)
9957 const char *arg
= arg_in
;
9958 const char *arg_start
;
9959 struct linespec_result canonical_start
, canonical_end
;
9960 int bp_count
, can_use_bp
, length
;
9962 struct breakpoint
*b
;
9964 /* We don't support software ranged breakpoints. */
9965 if (target_ranged_break_num_registers () < 0)
9966 error (_("This target does not support hardware ranged breakpoints."));
9968 bp_count
= hw_breakpoint_used_count ();
9969 bp_count
+= target_ranged_break_num_registers ();
9970 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9973 error (_("Hardware breakpoints used exceeds limit."));
9975 arg
= skip_spaces (arg
);
9976 if (arg
== NULL
|| arg
[0] == '\0')
9977 error(_("No address range specified."));
9980 event_location_up start_location
= string_to_event_location (&arg
,
9982 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
9985 error (_("Too few arguments."));
9986 else if (canonical_start
.lsals
.empty ())
9987 error (_("Could not find location of the beginning of the range."));
9989 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
9991 if (canonical_start
.lsals
.size () > 1
9992 || lsal_start
.sals
.size () != 1)
9993 error (_("Cannot create a ranged breakpoint with multiple locations."));
9995 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
9996 std::string
addr_string_start (arg_start
, arg
- arg_start
);
9998 arg
++; /* Skip the comma. */
9999 arg
= skip_spaces (arg
);
10001 /* Parse the end location. */
10005 /* We call decode_line_full directly here instead of using
10006 parse_breakpoint_sals because we need to specify the start location's
10007 symtab and line as the default symtab and line for the end of the
10008 range. This makes it possible to have ranges like "foo.c:27, +14",
10009 where +14 means 14 lines from the start location. */
10010 event_location_up end_location
= string_to_event_location (&arg
,
10012 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10013 sal_start
.symtab
, sal_start
.line
,
10014 &canonical_end
, NULL
, NULL
);
10016 if (canonical_end
.lsals
.empty ())
10017 error (_("Could not find location of the end of the range."));
10019 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10020 if (canonical_end
.lsals
.size () > 1
10021 || lsal_end
.sals
.size () != 1)
10022 error (_("Cannot create a ranged breakpoint with multiple locations."));
10024 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10026 end
= find_breakpoint_range_end (sal_end
);
10027 if (sal_start
.pc
> end
)
10028 error (_("Invalid address range, end precedes start."));
10030 length
= end
- sal_start
.pc
+ 1;
10032 /* Length overflowed. */
10033 error (_("Address range too large."));
10034 else if (length
== 1)
10036 /* This range is simple enough to be handled by
10037 the `hbreak' command. */
10038 hbreak_command (&addr_string_start
[0], 1);
10043 /* Now set up the breakpoint. */
10044 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10045 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10046 set_breakpoint_count (breakpoint_count
+ 1);
10047 b
->number
= breakpoint_count
;
10048 b
->disposition
= disp_donttouch
;
10049 b
->location
= std::move (start_location
);
10050 b
->location_range_end
= std::move (end_location
);
10051 b
->loc
->length
= length
;
10054 observer_notify_breakpoint_created (b
);
10055 update_global_location_list (UGLL_MAY_INSERT
);
10058 /* Return non-zero if EXP is verified as constant. Returned zero
10059 means EXP is variable. Also the constant detection may fail for
10060 some constant expressions and in such case still falsely return
10064 watchpoint_exp_is_const (const struct expression
*exp
)
10066 int i
= exp
->nelts
;
10072 /* We are only interested in the descriptor of each element. */
10073 operator_length (exp
, i
, &oplenp
, &argsp
);
10076 switch (exp
->elts
[i
].opcode
)
10086 case BINOP_LOGICAL_AND
:
10087 case BINOP_LOGICAL_OR
:
10088 case BINOP_BITWISE_AND
:
10089 case BINOP_BITWISE_IOR
:
10090 case BINOP_BITWISE_XOR
:
10092 case BINOP_NOTEQUAL
:
10118 case OP_OBJC_NSSTRING
:
10121 case UNOP_LOGICAL_NOT
:
10122 case UNOP_COMPLEMENT
:
10127 case UNOP_CAST_TYPE
:
10128 case UNOP_REINTERPRET_CAST
:
10129 case UNOP_DYNAMIC_CAST
:
10130 /* Unary, binary and ternary operators: We have to check
10131 their operands. If they are constant, then so is the
10132 result of that operation. For instance, if A and B are
10133 determined to be constants, then so is "A + B".
10135 UNOP_IND is one exception to the rule above, because the
10136 value of *ADDR is not necessarily a constant, even when
10141 /* Check whether the associated symbol is a constant.
10143 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10144 possible that a buggy compiler could mark a variable as
10145 constant even when it is not, and TYPE_CONST would return
10146 true in this case, while SYMBOL_CLASS wouldn't.
10148 We also have to check for function symbols because they
10149 are always constant. */
10151 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10153 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10154 && SYMBOL_CLASS (s
) != LOC_CONST
10155 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10160 /* The default action is to return 0 because we are using
10161 the optimistic approach here: If we don't know something,
10162 then it is not a constant. */
10171 /* Watchpoint destructor. */
10173 watchpoint::~watchpoint ()
10175 xfree (this->exp_string
);
10176 xfree (this->exp_string_reparse
);
10177 value_free (this->val
);
10180 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10183 re_set_watchpoint (struct breakpoint
*b
)
10185 struct watchpoint
*w
= (struct watchpoint
*) b
;
10187 /* Watchpoint can be either on expression using entirely global
10188 variables, or it can be on local variables.
10190 Watchpoints of the first kind are never auto-deleted, and even
10191 persist across program restarts. Since they can use variables
10192 from shared libraries, we need to reparse expression as libraries
10193 are loaded and unloaded.
10195 Watchpoints on local variables can also change meaning as result
10196 of solib event. For example, if a watchpoint uses both a local
10197 and a global variables in expression, it's a local watchpoint,
10198 but unloading of a shared library will make the expression
10199 invalid. This is not a very common use case, but we still
10200 re-evaluate expression, to avoid surprises to the user.
10202 Note that for local watchpoints, we re-evaluate it only if
10203 watchpoints frame id is still valid. If it's not, it means the
10204 watchpoint is out of scope and will be deleted soon. In fact,
10205 I'm not sure we'll ever be called in this case.
10207 If a local watchpoint's frame id is still valid, then
10208 w->exp_valid_block is likewise valid, and we can safely use it.
10210 Don't do anything about disabled watchpoints, since they will be
10211 reevaluated again when enabled. */
10212 update_watchpoint (w
, 1 /* reparse */);
10215 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10218 insert_watchpoint (struct bp_location
*bl
)
10220 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10221 int length
= w
->exact
? 1 : bl
->length
;
10223 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10224 w
->cond_exp
.get ());
10227 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10230 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10232 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10233 int length
= w
->exact
? 1 : bl
->length
;
10235 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10236 w
->cond_exp
.get ());
10240 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10241 const address_space
*aspace
, CORE_ADDR bp_addr
,
10242 const struct target_waitstatus
*ws
)
10244 struct breakpoint
*b
= bl
->owner
;
10245 struct watchpoint
*w
= (struct watchpoint
*) b
;
10247 /* Continuable hardware watchpoints are treated as non-existent if the
10248 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10249 some data address). Otherwise gdb won't stop on a break instruction
10250 in the code (not from a breakpoint) when a hardware watchpoint has
10251 been defined. Also skip watchpoints which we know did not trigger
10252 (did not match the data address). */
10253 if (is_hardware_watchpoint (b
)
10254 && w
->watchpoint_triggered
== watch_triggered_no
)
10261 check_status_watchpoint (bpstat bs
)
10263 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10265 bpstat_check_watchpoint (bs
);
10268 /* Implement the "resources_needed" breakpoint_ops method for
10269 hardware watchpoints. */
10272 resources_needed_watchpoint (const struct bp_location
*bl
)
10274 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10275 int length
= w
->exact
? 1 : bl
->length
;
10277 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10280 /* Implement the "works_in_software_mode" breakpoint_ops method for
10281 hardware watchpoints. */
10284 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10286 /* Read and access watchpoints only work with hardware support. */
10287 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10290 static enum print_stop_action
10291 print_it_watchpoint (bpstat bs
)
10293 struct breakpoint
*b
;
10294 enum print_stop_action result
;
10295 struct watchpoint
*w
;
10296 struct ui_out
*uiout
= current_uiout
;
10298 gdb_assert (bs
->bp_location_at
!= NULL
);
10300 b
= bs
->breakpoint_at
;
10301 w
= (struct watchpoint
*) b
;
10303 annotate_watchpoint (b
->number
);
10304 maybe_print_thread_hit_breakpoint (uiout
);
10308 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10311 case bp_watchpoint
:
10312 case bp_hardware_watchpoint
:
10313 if (uiout
->is_mi_like_p ())
10314 uiout
->field_string
10315 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10317 tuple_emitter
.emplace (uiout
, "value");
10318 uiout
->text ("\nOld value = ");
10319 watchpoint_value_print (bs
->old_val
, &stb
);
10320 uiout
->field_stream ("old", stb
);
10321 uiout
->text ("\nNew value = ");
10322 watchpoint_value_print (w
->val
, &stb
);
10323 uiout
->field_stream ("new", stb
);
10324 uiout
->text ("\n");
10325 /* More than one watchpoint may have been triggered. */
10326 result
= PRINT_UNKNOWN
;
10329 case bp_read_watchpoint
:
10330 if (uiout
->is_mi_like_p ())
10331 uiout
->field_string
10332 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10334 tuple_emitter
.emplace (uiout
, "value");
10335 uiout
->text ("\nValue = ");
10336 watchpoint_value_print (w
->val
, &stb
);
10337 uiout
->field_stream ("value", stb
);
10338 uiout
->text ("\n");
10339 result
= PRINT_UNKNOWN
;
10342 case bp_access_watchpoint
:
10343 if (bs
->old_val
!= NULL
)
10345 if (uiout
->is_mi_like_p ())
10346 uiout
->field_string
10348 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10350 tuple_emitter
.emplace (uiout
, "value");
10351 uiout
->text ("\nOld value = ");
10352 watchpoint_value_print (bs
->old_val
, &stb
);
10353 uiout
->field_stream ("old", stb
);
10354 uiout
->text ("\nNew value = ");
10359 if (uiout
->is_mi_like_p ())
10360 uiout
->field_string
10362 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10363 tuple_emitter
.emplace (uiout
, "value");
10364 uiout
->text ("\nValue = ");
10366 watchpoint_value_print (w
->val
, &stb
);
10367 uiout
->field_stream ("new", stb
);
10368 uiout
->text ("\n");
10369 result
= PRINT_UNKNOWN
;
10372 result
= PRINT_UNKNOWN
;
10378 /* Implement the "print_mention" breakpoint_ops method for hardware
10382 print_mention_watchpoint (struct breakpoint
*b
)
10384 struct watchpoint
*w
= (struct watchpoint
*) b
;
10385 struct ui_out
*uiout
= current_uiout
;
10386 const char *tuple_name
;
10390 case bp_watchpoint
:
10391 uiout
->text ("Watchpoint ");
10392 tuple_name
= "wpt";
10394 case bp_hardware_watchpoint
:
10395 uiout
->text ("Hardware watchpoint ");
10396 tuple_name
= "wpt";
10398 case bp_read_watchpoint
:
10399 uiout
->text ("Hardware read watchpoint ");
10400 tuple_name
= "hw-rwpt";
10402 case bp_access_watchpoint
:
10403 uiout
->text ("Hardware access (read/write) watchpoint ");
10404 tuple_name
= "hw-awpt";
10407 internal_error (__FILE__
, __LINE__
,
10408 _("Invalid hardware watchpoint type."));
10411 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10412 uiout
->field_int ("number", b
->number
);
10413 uiout
->text (": ");
10414 uiout
->field_string ("exp", w
->exp_string
);
10417 /* Implement the "print_recreate" breakpoint_ops method for
10421 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10423 struct watchpoint
*w
= (struct watchpoint
*) b
;
10427 case bp_watchpoint
:
10428 case bp_hardware_watchpoint
:
10429 fprintf_unfiltered (fp
, "watch");
10431 case bp_read_watchpoint
:
10432 fprintf_unfiltered (fp
, "rwatch");
10434 case bp_access_watchpoint
:
10435 fprintf_unfiltered (fp
, "awatch");
10438 internal_error (__FILE__
, __LINE__
,
10439 _("Invalid watchpoint type."));
10442 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10443 print_recreate_thread (b
, fp
);
10446 /* Implement the "explains_signal" breakpoint_ops method for
10450 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10452 /* A software watchpoint cannot cause a signal other than
10453 GDB_SIGNAL_TRAP. */
10454 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10460 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10462 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10464 /* Implement the "insert" breakpoint_ops method for
10465 masked hardware watchpoints. */
10468 insert_masked_watchpoint (struct bp_location
*bl
)
10470 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10472 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10473 bl
->watchpoint_type
);
10476 /* Implement the "remove" breakpoint_ops method for
10477 masked hardware watchpoints. */
10480 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10482 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10484 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10485 bl
->watchpoint_type
);
10488 /* Implement the "resources_needed" breakpoint_ops method for
10489 masked hardware watchpoints. */
10492 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10494 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10496 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10499 /* Implement the "works_in_software_mode" breakpoint_ops method for
10500 masked hardware watchpoints. */
10503 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10508 /* Implement the "print_it" breakpoint_ops method for
10509 masked hardware watchpoints. */
10511 static enum print_stop_action
10512 print_it_masked_watchpoint (bpstat bs
)
10514 struct breakpoint
*b
= bs
->breakpoint_at
;
10515 struct ui_out
*uiout
= current_uiout
;
10517 /* Masked watchpoints have only one location. */
10518 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10520 annotate_watchpoint (b
->number
);
10521 maybe_print_thread_hit_breakpoint (uiout
);
10525 case bp_hardware_watchpoint
:
10526 if (uiout
->is_mi_like_p ())
10527 uiout
->field_string
10528 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10531 case bp_read_watchpoint
:
10532 if (uiout
->is_mi_like_p ())
10533 uiout
->field_string
10534 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10537 case bp_access_watchpoint
:
10538 if (uiout
->is_mi_like_p ())
10539 uiout
->field_string
10541 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10544 internal_error (__FILE__
, __LINE__
,
10545 _("Invalid hardware watchpoint type."));
10549 uiout
->text (_("\n\
10550 Check the underlying instruction at PC for the memory\n\
10551 address and value which triggered this watchpoint.\n"));
10552 uiout
->text ("\n");
10554 /* More than one watchpoint may have been triggered. */
10555 return PRINT_UNKNOWN
;
10558 /* Implement the "print_one_detail" breakpoint_ops method for
10559 masked hardware watchpoints. */
10562 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10563 struct ui_out
*uiout
)
10565 struct watchpoint
*w
= (struct watchpoint
*) b
;
10567 /* Masked watchpoints have only one location. */
10568 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10570 uiout
->text ("\tmask ");
10571 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10572 uiout
->text ("\n");
10575 /* Implement the "print_mention" breakpoint_ops method for
10576 masked hardware watchpoints. */
10579 print_mention_masked_watchpoint (struct breakpoint
*b
)
10581 struct watchpoint
*w
= (struct watchpoint
*) b
;
10582 struct ui_out
*uiout
= current_uiout
;
10583 const char *tuple_name
;
10587 case bp_hardware_watchpoint
:
10588 uiout
->text ("Masked hardware watchpoint ");
10589 tuple_name
= "wpt";
10591 case bp_read_watchpoint
:
10592 uiout
->text ("Masked hardware read watchpoint ");
10593 tuple_name
= "hw-rwpt";
10595 case bp_access_watchpoint
:
10596 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10597 tuple_name
= "hw-awpt";
10600 internal_error (__FILE__
, __LINE__
,
10601 _("Invalid hardware watchpoint type."));
10604 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10605 uiout
->field_int ("number", b
->number
);
10606 uiout
->text (": ");
10607 uiout
->field_string ("exp", w
->exp_string
);
10610 /* Implement the "print_recreate" breakpoint_ops method for
10611 masked hardware watchpoints. */
10614 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10616 struct watchpoint
*w
= (struct watchpoint
*) b
;
10621 case bp_hardware_watchpoint
:
10622 fprintf_unfiltered (fp
, "watch");
10624 case bp_read_watchpoint
:
10625 fprintf_unfiltered (fp
, "rwatch");
10627 case bp_access_watchpoint
:
10628 fprintf_unfiltered (fp
, "awatch");
10631 internal_error (__FILE__
, __LINE__
,
10632 _("Invalid hardware watchpoint type."));
10635 sprintf_vma (tmp
, w
->hw_wp_mask
);
10636 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10637 print_recreate_thread (b
, fp
);
10640 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10642 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10644 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10647 is_masked_watchpoint (const struct breakpoint
*b
)
10649 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10652 /* accessflag: hw_write: watch write,
10653 hw_read: watch read,
10654 hw_access: watch access (read or write) */
10656 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10657 int just_location
, int internal
)
10659 struct breakpoint
*scope_breakpoint
= NULL
;
10660 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10661 struct value
*val
, *mark
, *result
;
10662 int saved_bitpos
= 0, saved_bitsize
= 0;
10663 const char *exp_start
= NULL
;
10664 const char *exp_end
= NULL
;
10665 const char *tok
, *end_tok
;
10667 const char *cond_start
= NULL
;
10668 const char *cond_end
= NULL
;
10669 enum bptype bp_type
;
10672 /* Flag to indicate whether we are going to use masks for
10673 the hardware watchpoint. */
10675 CORE_ADDR mask
= 0;
10677 /* Make sure that we actually have parameters to parse. */
10678 if (arg
!= NULL
&& arg
[0] != '\0')
10680 const char *value_start
;
10682 exp_end
= arg
+ strlen (arg
);
10684 /* Look for "parameter value" pairs at the end
10685 of the arguments string. */
10686 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10688 /* Skip whitespace at the end of the argument list. */
10689 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10692 /* Find the beginning of the last token.
10693 This is the value of the parameter. */
10694 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10696 value_start
= tok
+ 1;
10698 /* Skip whitespace. */
10699 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10704 /* Find the beginning of the second to last token.
10705 This is the parameter itself. */
10706 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10709 toklen
= end_tok
- tok
+ 1;
10711 if (toklen
== 6 && startswith (tok
, "thread"))
10713 struct thread_info
*thr
;
10714 /* At this point we've found a "thread" token, which means
10715 the user is trying to set a watchpoint that triggers
10716 only in a specific thread. */
10720 error(_("You can specify only one thread."));
10722 /* Extract the thread ID from the next token. */
10723 thr
= parse_thread_id (value_start
, &endp
);
10725 /* Check if the user provided a valid thread ID. */
10726 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10727 invalid_thread_id_error (value_start
);
10729 thread
= thr
->global_num
;
10731 else if (toklen
== 4 && startswith (tok
, "mask"))
10733 /* We've found a "mask" token, which means the user wants to
10734 create a hardware watchpoint that is going to have the mask
10736 struct value
*mask_value
, *mark
;
10739 error(_("You can specify only one mask."));
10741 use_mask
= just_location
= 1;
10743 mark
= value_mark ();
10744 mask_value
= parse_to_comma_and_eval (&value_start
);
10745 mask
= value_as_address (mask_value
);
10746 value_free_to_mark (mark
);
10749 /* We didn't recognize what we found. We should stop here. */
10752 /* Truncate the string and get rid of the "parameter value" pair before
10753 the arguments string is parsed by the parse_exp_1 function. */
10760 /* Parse the rest of the arguments. From here on out, everything
10761 is in terms of a newly allocated string instead of the original
10763 innermost_block
= NULL
;
10764 std::string
expression (arg
, exp_end
- arg
);
10765 exp_start
= arg
= expression
.c_str ();
10766 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
10768 /* Remove trailing whitespace from the expression before saving it.
10769 This makes the eventual display of the expression string a bit
10771 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10774 /* Checking if the expression is not constant. */
10775 if (watchpoint_exp_is_const (exp
.get ()))
10779 len
= exp_end
- exp_start
;
10780 while (len
> 0 && isspace (exp_start
[len
- 1]))
10782 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10785 exp_valid_block
= innermost_block
;
10786 mark
= value_mark ();
10787 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
10789 if (val
!= NULL
&& just_location
)
10791 saved_bitpos
= value_bitpos (val
);
10792 saved_bitsize
= value_bitsize (val
);
10799 exp_valid_block
= NULL
;
10800 val
= value_addr (result
);
10801 release_value (val
);
10802 value_free_to_mark (mark
);
10806 ret
= target_masked_watch_num_registers (value_as_address (val
),
10809 error (_("This target does not support masked watchpoints."));
10810 else if (ret
== -2)
10811 error (_("Invalid mask or memory region."));
10814 else if (val
!= NULL
)
10815 release_value (val
);
10817 tok
= skip_spaces (arg
);
10818 end_tok
= skip_to_space (tok
);
10820 toklen
= end_tok
- tok
;
10821 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10823 innermost_block
= NULL
;
10824 tok
= cond_start
= end_tok
+ 1;
10825 parse_exp_1 (&tok
, 0, 0, 0);
10827 /* The watchpoint expression may not be local, but the condition
10828 may still be. E.g.: `watch global if local > 0'. */
10829 cond_exp_valid_block
= innermost_block
;
10834 error (_("Junk at end of command."));
10836 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10838 /* Save this because create_internal_breakpoint below invalidates
10840 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10842 /* If the expression is "local", then set up a "watchpoint scope"
10843 breakpoint at the point where we've left the scope of the watchpoint
10844 expression. Create the scope breakpoint before the watchpoint, so
10845 that we will encounter it first in bpstat_stop_status. */
10846 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10848 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10850 if (frame_id_p (caller_frame_id
))
10852 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10853 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10856 = create_internal_breakpoint (caller_arch
, caller_pc
,
10857 bp_watchpoint_scope
,
10858 &momentary_breakpoint_ops
);
10860 /* create_internal_breakpoint could invalidate WP_FRAME. */
10863 scope_breakpoint
->enable_state
= bp_enabled
;
10865 /* Automatically delete the breakpoint when it hits. */
10866 scope_breakpoint
->disposition
= disp_del
;
10868 /* Only break in the proper frame (help with recursion). */
10869 scope_breakpoint
->frame_id
= caller_frame_id
;
10871 /* Set the address at which we will stop. */
10872 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10873 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10874 scope_breakpoint
->loc
->address
10875 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10876 scope_breakpoint
->loc
->requested_address
,
10877 scope_breakpoint
->type
);
10881 /* Now set up the breakpoint. We create all watchpoints as hardware
10882 watchpoints here even if hardware watchpoints are turned off, a call
10883 to update_watchpoint later in this function will cause the type to
10884 drop back to bp_watchpoint (software watchpoint) if required. */
10886 if (accessflag
== hw_read
)
10887 bp_type
= bp_read_watchpoint
;
10888 else if (accessflag
== hw_access
)
10889 bp_type
= bp_access_watchpoint
;
10891 bp_type
= bp_hardware_watchpoint
;
10893 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10896 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10897 &masked_watchpoint_breakpoint_ops
);
10899 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10900 &watchpoint_breakpoint_ops
);
10901 w
->thread
= thread
;
10902 w
->disposition
= disp_donttouch
;
10903 w
->pspace
= current_program_space
;
10904 w
->exp
= std::move (exp
);
10905 w
->exp_valid_block
= exp_valid_block
;
10906 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10909 struct type
*t
= value_type (val
);
10910 CORE_ADDR addr
= value_as_address (val
);
10912 w
->exp_string_reparse
10913 = current_language
->la_watch_location_expression (t
, addr
).release ();
10915 w
->exp_string
= xstrprintf ("-location %.*s",
10916 (int) (exp_end
- exp_start
), exp_start
);
10919 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10923 w
->hw_wp_mask
= mask
;
10928 w
->val_bitpos
= saved_bitpos
;
10929 w
->val_bitsize
= saved_bitsize
;
10934 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10936 w
->cond_string
= 0;
10938 if (frame_id_p (watchpoint_frame
))
10940 w
->watchpoint_frame
= watchpoint_frame
;
10941 w
->watchpoint_thread
= inferior_ptid
;
10945 w
->watchpoint_frame
= null_frame_id
;
10946 w
->watchpoint_thread
= null_ptid
;
10949 if (scope_breakpoint
!= NULL
)
10951 /* The scope breakpoint is related to the watchpoint. We will
10952 need to act on them together. */
10953 w
->related_breakpoint
= scope_breakpoint
;
10954 scope_breakpoint
->related_breakpoint
= w
.get ();
10957 if (!just_location
)
10958 value_free_to_mark (mark
);
10960 /* Finally update the new watchpoint. This creates the locations
10961 that should be inserted. */
10962 update_watchpoint (w
.get (), 1);
10964 install_breakpoint (internal
, std::move (w
), 1);
10967 /* Return count of debug registers needed to watch the given expression.
10968 If the watchpoint cannot be handled in hardware return zero. */
10971 can_use_hardware_watchpoint (struct value
*v
)
10973 int found_memory_cnt
= 0;
10974 struct value
*head
= v
;
10976 /* Did the user specifically forbid us to use hardware watchpoints? */
10977 if (!can_use_hw_watchpoints
)
10980 /* Make sure that the value of the expression depends only upon
10981 memory contents, and values computed from them within GDB. If we
10982 find any register references or function calls, we can't use a
10983 hardware watchpoint.
10985 The idea here is that evaluating an expression generates a series
10986 of values, one holding the value of every subexpression. (The
10987 expression a*b+c has five subexpressions: a, b, a*b, c, and
10988 a*b+c.) GDB's values hold almost enough information to establish
10989 the criteria given above --- they identify memory lvalues,
10990 register lvalues, computed values, etcetera. So we can evaluate
10991 the expression, and then scan the chain of values that leaves
10992 behind to decide whether we can detect any possible change to the
10993 expression's final value using only hardware watchpoints.
10995 However, I don't think that the values returned by inferior
10996 function calls are special in any way. So this function may not
10997 notice that an expression involving an inferior function call
10998 can't be watched with hardware watchpoints. FIXME. */
10999 for (; v
; v
= value_next (v
))
11001 if (VALUE_LVAL (v
) == lval_memory
)
11003 if (v
!= head
&& value_lazy (v
))
11004 /* A lazy memory lvalue in the chain is one that GDB never
11005 needed to fetch; we either just used its address (e.g.,
11006 `a' in `a.b') or we never needed it at all (e.g., `a'
11007 in `a,b'). This doesn't apply to HEAD; if that is
11008 lazy then it was not readable, but watch it anyway. */
11012 /* Ahh, memory we actually used! Check if we can cover
11013 it with hardware watchpoints. */
11014 struct type
*vtype
= check_typedef (value_type (v
));
11016 /* We only watch structs and arrays if user asked for it
11017 explicitly, never if they just happen to appear in a
11018 middle of some value chain. */
11020 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11021 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11023 CORE_ADDR vaddr
= value_address (v
);
11027 len
= (target_exact_watchpoints
11028 && is_scalar_type_recursive (vtype
))?
11029 1 : TYPE_LENGTH (value_type (v
));
11031 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11035 found_memory_cnt
+= num_regs
;
11039 else if (VALUE_LVAL (v
) != not_lval
11040 && deprecated_value_modifiable (v
) == 0)
11041 return 0; /* These are values from the history (e.g., $1). */
11042 else if (VALUE_LVAL (v
) == lval_register
)
11043 return 0; /* Cannot watch a register with a HW watchpoint. */
11046 /* The expression itself looks suitable for using a hardware
11047 watchpoint, but give the target machine a chance to reject it. */
11048 return found_memory_cnt
;
11052 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11054 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11057 /* A helper function that looks for the "-location" argument and then
11058 calls watch_command_1. */
11061 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11063 int just_location
= 0;
11066 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11067 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11069 arg
= skip_spaces (arg
);
11073 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11077 watch_command (char *arg
, int from_tty
)
11079 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11083 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11085 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11089 rwatch_command (char *arg
, int from_tty
)
11091 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11095 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11097 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11101 awatch_command (char *arg
, int from_tty
)
11103 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11107 /* Data for the FSM that manages the until(location)/advance commands
11108 in infcmd.c. Here because it uses the mechanisms of
11111 struct until_break_fsm
11113 /* The base class. */
11114 struct thread_fsm thread_fsm
;
11116 /* The thread that as current when the command was executed. */
11119 /* The breakpoint set at the destination location. */
11120 struct breakpoint
*location_breakpoint
;
11122 /* Breakpoint set at the return address in the caller frame. May be
11124 struct breakpoint
*caller_breakpoint
;
11127 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11128 struct thread_info
*thread
);
11129 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11130 struct thread_info
*thread
);
11131 static enum async_reply_reason
11132 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11134 /* until_break_fsm's vtable. */
11136 static struct thread_fsm_ops until_break_fsm_ops
=
11139 until_break_fsm_clean_up
,
11140 until_break_fsm_should_stop
,
11141 NULL
, /* return_value */
11142 until_break_fsm_async_reply_reason
,
11145 /* Allocate a new until_break_command_fsm. */
11147 static struct until_break_fsm
*
11148 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11149 breakpoint_up
&&location_breakpoint
,
11150 breakpoint_up
&&caller_breakpoint
)
11152 struct until_break_fsm
*sm
;
11154 sm
= XCNEW (struct until_break_fsm
);
11155 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11157 sm
->thread
= thread
;
11158 sm
->location_breakpoint
= location_breakpoint
.release ();
11159 sm
->caller_breakpoint
= caller_breakpoint
.release ();
11164 /* Implementation of the 'should_stop' FSM method for the
11165 until(location)/advance commands. */
11168 until_break_fsm_should_stop (struct thread_fsm
*self
,
11169 struct thread_info
*tp
)
11171 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11173 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11174 sm
->location_breakpoint
) != NULL
11175 || (sm
->caller_breakpoint
!= NULL
11176 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11177 sm
->caller_breakpoint
) != NULL
))
11178 thread_fsm_set_finished (self
);
11183 /* Implementation of the 'clean_up' FSM method for the
11184 until(location)/advance commands. */
11187 until_break_fsm_clean_up (struct thread_fsm
*self
,
11188 struct thread_info
*thread
)
11190 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11192 /* Clean up our temporary breakpoints. */
11193 if (sm
->location_breakpoint
!= NULL
)
11195 delete_breakpoint (sm
->location_breakpoint
);
11196 sm
->location_breakpoint
= NULL
;
11198 if (sm
->caller_breakpoint
!= NULL
)
11200 delete_breakpoint (sm
->caller_breakpoint
);
11201 sm
->caller_breakpoint
= NULL
;
11203 delete_longjmp_breakpoint (sm
->thread
);
11206 /* Implementation of the 'async_reply_reason' FSM method for the
11207 until(location)/advance commands. */
11209 static enum async_reply_reason
11210 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11212 return EXEC_ASYNC_LOCATION_REACHED
;
11216 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11218 struct frame_info
*frame
;
11219 struct gdbarch
*frame_gdbarch
;
11220 struct frame_id stack_frame_id
;
11221 struct frame_id caller_frame_id
;
11222 struct cleanup
*old_chain
;
11224 struct thread_info
*tp
;
11225 struct until_break_fsm
*sm
;
11227 clear_proceed_status (0);
11229 /* Set a breakpoint where the user wants it and at return from
11232 event_location_up location
= string_to_event_location (&arg
, current_language
);
11234 std::vector
<symtab_and_line
> sals
11235 = (last_displayed_sal_is_valid ()
11236 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11237 get_last_displayed_symtab (),
11238 get_last_displayed_line ())
11239 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11240 NULL
, (struct symtab
*) NULL
, 0));
11242 if (sals
.size () != 1)
11243 error (_("Couldn't get information on specified line."));
11245 symtab_and_line
&sal
= sals
[0];
11248 error (_("Junk at end of arguments."));
11250 resolve_sal_pc (&sal
);
11252 tp
= inferior_thread ();
11253 thread
= tp
->global_num
;
11255 old_chain
= make_cleanup (null_cleanup
, NULL
);
11257 /* Note linespec handling above invalidates the frame chain.
11258 Installing a breakpoint also invalidates the frame chain (as it
11259 may need to switch threads), so do any frame handling before
11262 frame
= get_selected_frame (NULL
);
11263 frame_gdbarch
= get_frame_arch (frame
);
11264 stack_frame_id
= get_stack_frame_id (frame
);
11265 caller_frame_id
= frame_unwind_caller_id (frame
);
11267 /* Keep within the current frame, or in frames called by the current
11270 breakpoint_up caller_breakpoint
;
11271 if (frame_id_p (caller_frame_id
))
11273 struct symtab_and_line sal2
;
11274 struct gdbarch
*caller_gdbarch
;
11276 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11277 sal2
.pc
= frame_unwind_caller_pc (frame
);
11278 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11279 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11284 set_longjmp_breakpoint (tp
, caller_frame_id
);
11285 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11288 /* set_momentary_breakpoint could invalidate FRAME. */
11291 breakpoint_up location_breakpoint
;
11293 /* If the user told us to continue until a specified location,
11294 we don't specify a frame at which we need to stop. */
11295 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11296 null_frame_id
, bp_until
);
11298 /* Otherwise, specify the selected frame, because we want to stop
11299 only at the very same frame. */
11300 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11301 stack_frame_id
, bp_until
);
11303 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11304 std::move (location_breakpoint
),
11305 std::move (caller_breakpoint
));
11306 tp
->thread_fsm
= &sm
->thread_fsm
;
11308 discard_cleanups (old_chain
);
11310 proceed (-1, GDB_SIGNAL_DEFAULT
);
11313 /* This function attempts to parse an optional "if <cond>" clause
11314 from the arg string. If one is not found, it returns NULL.
11316 Else, it returns a pointer to the condition string. (It does not
11317 attempt to evaluate the string against a particular block.) And,
11318 it updates arg to point to the first character following the parsed
11319 if clause in the arg string. */
11322 ep_parse_optional_if_clause (const char **arg
)
11324 const char *cond_string
;
11326 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11329 /* Skip the "if" keyword. */
11332 /* Skip any extra leading whitespace, and record the start of the
11333 condition string. */
11334 *arg
= skip_spaces (*arg
);
11335 cond_string
= *arg
;
11337 /* Assume that the condition occupies the remainder of the arg
11339 (*arg
) += strlen (cond_string
);
11341 return cond_string
;
11344 /* Commands to deal with catching events, such as signals, exceptions,
11345 process start/exit, etc. */
11349 catch_fork_temporary
, catch_vfork_temporary
,
11350 catch_fork_permanent
, catch_vfork_permanent
11355 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11356 struct cmd_list_element
*command
)
11358 const char *arg
= arg_entry
;
11359 struct gdbarch
*gdbarch
= get_current_arch ();
11360 const char *cond_string
= NULL
;
11361 catch_fork_kind fork_kind
;
11364 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11365 tempflag
= (fork_kind
== catch_fork_temporary
11366 || fork_kind
== catch_vfork_temporary
);
11370 arg
= skip_spaces (arg
);
11372 /* The allowed syntax is:
11374 catch [v]fork if <cond>
11376 First, check if there's an if clause. */
11377 cond_string
= ep_parse_optional_if_clause (&arg
);
11379 if ((*arg
!= '\0') && !isspace (*arg
))
11380 error (_("Junk at end of arguments."));
11382 /* If this target supports it, create a fork or vfork catchpoint
11383 and enable reporting of such events. */
11386 case catch_fork_temporary
:
11387 case catch_fork_permanent
:
11388 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11389 &catch_fork_breakpoint_ops
);
11391 case catch_vfork_temporary
:
11392 case catch_vfork_permanent
:
11393 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11394 &catch_vfork_breakpoint_ops
);
11397 error (_("unsupported or unknown fork kind; cannot catch it"));
11403 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11404 struct cmd_list_element
*command
)
11406 const char *arg
= arg_entry
;
11407 struct gdbarch
*gdbarch
= get_current_arch ();
11409 const char *cond_string
= NULL
;
11411 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11415 arg
= skip_spaces (arg
);
11417 /* The allowed syntax is:
11419 catch exec if <cond>
11421 First, check if there's an if clause. */
11422 cond_string
= ep_parse_optional_if_clause (&arg
);
11424 if ((*arg
!= '\0') && !isspace (*arg
))
11425 error (_("Junk at end of arguments."));
11427 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11428 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11429 &catch_exec_breakpoint_ops
);
11430 c
->exec_pathname
= NULL
;
11432 install_breakpoint (0, std::move (c
), 1);
11436 init_ada_exception_breakpoint (struct breakpoint
*b
,
11437 struct gdbarch
*gdbarch
,
11438 struct symtab_and_line sal
,
11439 const char *addr_string
,
11440 const struct breakpoint_ops
*ops
,
11447 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11449 loc_gdbarch
= gdbarch
;
11451 describe_other_breakpoints (loc_gdbarch
,
11452 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11453 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11454 version for exception catchpoints, because two catchpoints
11455 used for different exception names will use the same address.
11456 In this case, a "breakpoint ... also set at..." warning is
11457 unproductive. Besides, the warning phrasing is also a bit
11458 inappropriate, we should use the word catchpoint, and tell
11459 the user what type of catchpoint it is. The above is good
11460 enough for now, though. */
11463 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11465 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11466 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11467 b
->location
= string_to_event_location (&addr_string
,
11468 language_def (language_ada
));
11469 b
->language
= language_ada
;
11473 catch_command (const char *arg
, int from_tty
)
11475 error (_("Catch requires an event name."));
11480 tcatch_command (const char *arg
, int from_tty
)
11482 error (_("Catch requires an event name."));
11485 /* Compare two breakpoints and return a strcmp-like result. */
11488 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11490 uintptr_t ua
= (uintptr_t) a
;
11491 uintptr_t ub
= (uintptr_t) b
;
11493 if (a
->number
< b
->number
)
11495 else if (a
->number
> b
->number
)
11498 /* Now sort by address, in case we see, e..g, two breakpoints with
11502 return ua
> ub
? 1 : 0;
11505 /* Delete breakpoints by address or line. */
11508 clear_command (char *arg
, int from_tty
)
11510 struct breakpoint
*b
;
11514 std::vector
<symtab_and_line
> decoded_sals
;
11515 symtab_and_line last_sal
;
11516 gdb::array_view
<symtab_and_line
> sals
;
11520 = decode_line_with_current_source (arg
,
11521 (DECODE_LINE_FUNFIRSTLINE
11522 | DECODE_LINE_LIST_MODE
));
11524 sals
= decoded_sals
;
11528 /* Set sal's line, symtab, pc, and pspace to the values
11529 corresponding to the last call to print_frame_info. If the
11530 codepoint is not valid, this will set all the fields to 0. */
11531 last_sal
= get_last_displayed_sal ();
11532 if (last_sal
.symtab
== 0)
11533 error (_("No source file specified."));
11539 /* We don't call resolve_sal_pc here. That's not as bad as it
11540 seems, because all existing breakpoints typically have both
11541 file/line and pc set. So, if clear is given file/line, we can
11542 match this to existing breakpoint without obtaining pc at all.
11544 We only support clearing given the address explicitly
11545 present in breakpoint table. Say, we've set breakpoint
11546 at file:line. There were several PC values for that file:line,
11547 due to optimization, all in one block.
11549 We've picked one PC value. If "clear" is issued with another
11550 PC corresponding to the same file:line, the breakpoint won't
11551 be cleared. We probably can still clear the breakpoint, but
11552 since the other PC value is never presented to user, user
11553 can only find it by guessing, and it does not seem important
11554 to support that. */
11556 /* For each line spec given, delete bps which correspond to it. Do
11557 it in two passes, solely to preserve the current behavior that
11558 from_tty is forced true if we delete more than one
11561 std::vector
<struct breakpoint
*> found
;
11562 for (const auto &sal
: sals
)
11564 const char *sal_fullname
;
11566 /* If exact pc given, clear bpts at that pc.
11567 If line given (pc == 0), clear all bpts on specified line.
11568 If defaulting, clear all bpts on default line
11571 defaulting sal.pc != 0 tests to do
11576 1 0 <can't happen> */
11578 sal_fullname
= (sal
.symtab
== NULL
11579 ? NULL
: symtab_to_fullname (sal
.symtab
));
11581 /* Find all matching breakpoints and add them to 'found'. */
11582 ALL_BREAKPOINTS (b
)
11585 /* Are we going to delete b? */
11586 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11588 struct bp_location
*loc
= b
->loc
;
11589 for (; loc
; loc
= loc
->next
)
11591 /* If the user specified file:line, don't allow a PC
11592 match. This matches historical gdb behavior. */
11593 int pc_match
= (!sal
.explicit_line
11595 && (loc
->pspace
== sal
.pspace
)
11596 && (loc
->address
== sal
.pc
)
11597 && (!section_is_overlay (loc
->section
)
11598 || loc
->section
== sal
.section
));
11599 int line_match
= 0;
11601 if ((default_match
|| sal
.explicit_line
)
11602 && loc
->symtab
!= NULL
11603 && sal_fullname
!= NULL
11604 && sal
.pspace
== loc
->pspace
11605 && loc
->line_number
== sal
.line
11606 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11607 sal_fullname
) == 0)
11610 if (pc_match
|| line_match
)
11619 found
.push_back (b
);
11623 /* Now go thru the 'found' chain and delete them. */
11624 if (found
.empty ())
11627 error (_("No breakpoint at %s."), arg
);
11629 error (_("No breakpoint at this line."));
11632 /* Remove duplicates from the vec. */
11633 std::sort (found
.begin (), found
.end (),
11634 [] (const breakpoint
*a
, const breakpoint
*b
)
11636 return compare_breakpoints (a
, b
) < 0;
11638 found
.erase (std::unique (found
.begin (), found
.end (),
11639 [] (const breakpoint
*a
, const breakpoint
*b
)
11641 return compare_breakpoints (a
, b
) == 0;
11645 if (found
.size () > 1)
11646 from_tty
= 1; /* Always report if deleted more than one. */
11649 if (found
.size () == 1)
11650 printf_unfiltered (_("Deleted breakpoint "));
11652 printf_unfiltered (_("Deleted breakpoints "));
11655 for (breakpoint
*iter
: found
)
11658 printf_unfiltered ("%d ", iter
->number
);
11659 delete_breakpoint (iter
);
11662 putchar_unfiltered ('\n');
11665 /* Delete breakpoint in BS if they are `delete' breakpoints and
11666 all breakpoints that are marked for deletion, whether hit or not.
11667 This is called after any breakpoint is hit, or after errors. */
11670 breakpoint_auto_delete (bpstat bs
)
11672 struct breakpoint
*b
, *b_tmp
;
11674 for (; bs
; bs
= bs
->next
)
11675 if (bs
->breakpoint_at
11676 && bs
->breakpoint_at
->disposition
== disp_del
11678 delete_breakpoint (bs
->breakpoint_at
);
11680 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11682 if (b
->disposition
== disp_del_at_next_stop
)
11683 delete_breakpoint (b
);
11687 /* A comparison function for bp_location AP and BP being interfaced to
11688 qsort. Sort elements primarily by their ADDRESS (no matter what
11689 does breakpoint_address_is_meaningful say for its OWNER),
11690 secondarily by ordering first permanent elements and
11691 terciarily just ensuring the array is sorted stable way despite
11692 qsort being an unstable algorithm. */
11695 bp_locations_compare (const void *ap
, const void *bp
)
11697 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
11698 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
11700 if (a
->address
!= b
->address
)
11701 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11703 /* Sort locations at the same address by their pspace number, keeping
11704 locations of the same inferior (in a multi-inferior environment)
11707 if (a
->pspace
->num
!= b
->pspace
->num
)
11708 return ((a
->pspace
->num
> b
->pspace
->num
)
11709 - (a
->pspace
->num
< b
->pspace
->num
));
11711 /* Sort permanent breakpoints first. */
11712 if (a
->permanent
!= b
->permanent
)
11713 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11715 /* Make the internal GDB representation stable across GDB runs
11716 where A and B memory inside GDB can differ. Breakpoint locations of
11717 the same type at the same address can be sorted in arbitrary order. */
11719 if (a
->owner
->number
!= b
->owner
->number
)
11720 return ((a
->owner
->number
> b
->owner
->number
)
11721 - (a
->owner
->number
< b
->owner
->number
));
11723 return (a
> b
) - (a
< b
);
11726 /* Set bp_locations_placed_address_before_address_max and
11727 bp_locations_shadow_len_after_address_max according to the current
11728 content of the bp_locations array. */
11731 bp_locations_target_extensions_update (void)
11733 struct bp_location
*bl
, **blp_tmp
;
11735 bp_locations_placed_address_before_address_max
= 0;
11736 bp_locations_shadow_len_after_address_max
= 0;
11738 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11740 CORE_ADDR start
, end
, addr
;
11742 if (!bp_location_has_shadow (bl
))
11745 start
= bl
->target_info
.placed_address
;
11746 end
= start
+ bl
->target_info
.shadow_len
;
11748 gdb_assert (bl
->address
>= start
);
11749 addr
= bl
->address
- start
;
11750 if (addr
> bp_locations_placed_address_before_address_max
)
11751 bp_locations_placed_address_before_address_max
= addr
;
11753 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11755 gdb_assert (bl
->address
< end
);
11756 addr
= end
- bl
->address
;
11757 if (addr
> bp_locations_shadow_len_after_address_max
)
11758 bp_locations_shadow_len_after_address_max
= addr
;
11762 /* Download tracepoint locations if they haven't been. */
11765 download_tracepoint_locations (void)
11767 struct breakpoint
*b
;
11768 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11770 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11772 ALL_TRACEPOINTS (b
)
11774 struct bp_location
*bl
;
11775 struct tracepoint
*t
;
11776 int bp_location_downloaded
= 0;
11778 if ((b
->type
== bp_fast_tracepoint
11779 ? !may_insert_fast_tracepoints
11780 : !may_insert_tracepoints
))
11783 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11785 if (target_can_download_tracepoint ())
11786 can_download_tracepoint
= TRIBOOL_TRUE
;
11788 can_download_tracepoint
= TRIBOOL_FALSE
;
11791 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11794 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11796 /* In tracepoint, locations are _never_ duplicated, so
11797 should_be_inserted is equivalent to
11798 unduplicated_should_be_inserted. */
11799 if (!should_be_inserted (bl
) || bl
->inserted
)
11802 switch_to_program_space_and_thread (bl
->pspace
);
11804 target_download_tracepoint (bl
);
11807 bp_location_downloaded
= 1;
11809 t
= (struct tracepoint
*) b
;
11810 t
->number_on_target
= b
->number
;
11811 if (bp_location_downloaded
)
11812 observer_notify_breakpoint_modified (b
);
11816 /* Swap the insertion/duplication state between two locations. */
11819 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11821 const int left_inserted
= left
->inserted
;
11822 const int left_duplicate
= left
->duplicate
;
11823 const int left_needs_update
= left
->needs_update
;
11824 const struct bp_target_info left_target_info
= left
->target_info
;
11826 /* Locations of tracepoints can never be duplicated. */
11827 if (is_tracepoint (left
->owner
))
11828 gdb_assert (!left
->duplicate
);
11829 if (is_tracepoint (right
->owner
))
11830 gdb_assert (!right
->duplicate
);
11832 left
->inserted
= right
->inserted
;
11833 left
->duplicate
= right
->duplicate
;
11834 left
->needs_update
= right
->needs_update
;
11835 left
->target_info
= right
->target_info
;
11836 right
->inserted
= left_inserted
;
11837 right
->duplicate
= left_duplicate
;
11838 right
->needs_update
= left_needs_update
;
11839 right
->target_info
= left_target_info
;
11842 /* Force the re-insertion of the locations at ADDRESS. This is called
11843 once a new/deleted/modified duplicate location is found and we are evaluating
11844 conditions on the target's side. Such conditions need to be updated on
11848 force_breakpoint_reinsertion (struct bp_location
*bl
)
11850 struct bp_location
**locp
= NULL
, **loc2p
;
11851 struct bp_location
*loc
;
11852 CORE_ADDR address
= 0;
11855 address
= bl
->address
;
11856 pspace_num
= bl
->pspace
->num
;
11858 /* This is only meaningful if the target is
11859 evaluating conditions and if the user has
11860 opted for condition evaluation on the target's
11862 if (gdb_evaluates_breakpoint_condition_p ()
11863 || !target_supports_evaluation_of_breakpoint_conditions ())
11866 /* Flag all breakpoint locations with this address and
11867 the same program space as the location
11868 as "its condition has changed". We need to
11869 update the conditions on the target's side. */
11870 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11874 if (!is_breakpoint (loc
->owner
)
11875 || pspace_num
!= loc
->pspace
->num
)
11878 /* Flag the location appropriately. We use a different state to
11879 let everyone know that we already updated the set of locations
11880 with addr bl->address and program space bl->pspace. This is so
11881 we don't have to keep calling these functions just to mark locations
11882 that have already been marked. */
11883 loc
->condition_changed
= condition_updated
;
11885 /* Free the agent expression bytecode as well. We will compute
11887 loc
->cond_bytecode
.reset ();
11890 /* Called whether new breakpoints are created, or existing breakpoints
11891 deleted, to update the global location list and recompute which
11892 locations are duplicate of which.
11894 The INSERT_MODE flag determines whether locations may not, may, or
11895 shall be inserted now. See 'enum ugll_insert_mode' for more
11899 update_global_location_list (enum ugll_insert_mode insert_mode
)
11901 struct breakpoint
*b
;
11902 struct bp_location
**locp
, *loc
;
11903 /* Last breakpoint location address that was marked for update. */
11904 CORE_ADDR last_addr
= 0;
11905 /* Last breakpoint location program space that was marked for update. */
11906 int last_pspace_num
= -1;
11908 /* Used in the duplicates detection below. When iterating over all
11909 bp_locations, points to the first bp_location of a given address.
11910 Breakpoints and watchpoints of different types are never
11911 duplicates of each other. Keep one pointer for each type of
11912 breakpoint/watchpoint, so we only need to loop over all locations
11914 struct bp_location
*bp_loc_first
; /* breakpoint */
11915 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11916 struct bp_location
*awp_loc_first
; /* access watchpoint */
11917 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11919 /* Saved former bp_locations array which we compare against the newly
11920 built bp_locations from the current state of ALL_BREAKPOINTS. */
11921 struct bp_location
**old_locp
;
11922 unsigned old_locations_count
;
11923 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11925 old_locations_count
= bp_locations_count
;
11926 bp_locations
= NULL
;
11927 bp_locations_count
= 0;
11929 ALL_BREAKPOINTS (b
)
11930 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11931 bp_locations_count
++;
11933 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11934 locp
= bp_locations
;
11935 ALL_BREAKPOINTS (b
)
11936 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11938 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
11939 bp_locations_compare
);
11941 bp_locations_target_extensions_update ();
11943 /* Identify bp_location instances that are no longer present in the
11944 new list, and therefore should be freed. Note that it's not
11945 necessary that those locations should be removed from inferior --
11946 if there's another location at the same address (previously
11947 marked as duplicate), we don't need to remove/insert the
11950 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11951 and former bp_location array state respectively. */
11953 locp
= bp_locations
;
11954 for (old_locp
= old_locations
.get ();
11955 old_locp
< old_locations
.get () + old_locations_count
;
11958 struct bp_location
*old_loc
= *old_locp
;
11959 struct bp_location
**loc2p
;
11961 /* Tells if 'old_loc' is found among the new locations. If
11962 not, we have to free it. */
11963 int found_object
= 0;
11964 /* Tells if the location should remain inserted in the target. */
11965 int keep_in_target
= 0;
11968 /* Skip LOCP entries which will definitely never be needed.
11969 Stop either at or being the one matching OLD_LOC. */
11970 while (locp
< bp_locations
+ bp_locations_count
11971 && (*locp
)->address
< old_loc
->address
)
11975 (loc2p
< bp_locations
+ bp_locations_count
11976 && (*loc2p
)->address
== old_loc
->address
);
11979 /* Check if this is a new/duplicated location or a duplicated
11980 location that had its condition modified. If so, we want to send
11981 its condition to the target if evaluation of conditions is taking
11983 if ((*loc2p
)->condition_changed
== condition_modified
11984 && (last_addr
!= old_loc
->address
11985 || last_pspace_num
!= old_loc
->pspace
->num
))
11987 force_breakpoint_reinsertion (*loc2p
);
11988 last_pspace_num
= old_loc
->pspace
->num
;
11991 if (*loc2p
== old_loc
)
11995 /* We have already handled this address, update it so that we don't
11996 have to go through updates again. */
11997 last_addr
= old_loc
->address
;
11999 /* Target-side condition evaluation: Handle deleted locations. */
12001 force_breakpoint_reinsertion (old_loc
);
12003 /* If this location is no longer present, and inserted, look if
12004 there's maybe a new location at the same address. If so,
12005 mark that one inserted, and don't remove this one. This is
12006 needed so that we don't have a time window where a breakpoint
12007 at certain location is not inserted. */
12009 if (old_loc
->inserted
)
12011 /* If the location is inserted now, we might have to remove
12014 if (found_object
&& should_be_inserted (old_loc
))
12016 /* The location is still present in the location list,
12017 and still should be inserted. Don't do anything. */
12018 keep_in_target
= 1;
12022 /* This location still exists, but it won't be kept in the
12023 target since it may have been disabled. We proceed to
12024 remove its target-side condition. */
12026 /* The location is either no longer present, or got
12027 disabled. See if there's another location at the
12028 same address, in which case we don't need to remove
12029 this one from the target. */
12031 /* OLD_LOC comes from existing struct breakpoint. */
12032 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12035 (loc2p
< bp_locations
+ bp_locations_count
12036 && (*loc2p
)->address
== old_loc
->address
);
12039 struct bp_location
*loc2
= *loc2p
;
12041 if (breakpoint_locations_match (loc2
, old_loc
))
12043 /* Read watchpoint locations are switched to
12044 access watchpoints, if the former are not
12045 supported, but the latter are. */
12046 if (is_hardware_watchpoint (old_loc
->owner
))
12048 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12049 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12052 /* loc2 is a duplicated location. We need to check
12053 if it should be inserted in case it will be
12055 if (loc2
!= old_loc
12056 && unduplicated_should_be_inserted (loc2
))
12058 swap_insertion (old_loc
, loc2
);
12059 keep_in_target
= 1;
12067 if (!keep_in_target
)
12069 if (remove_breakpoint (old_loc
))
12071 /* This is just about all we can do. We could keep
12072 this location on the global list, and try to
12073 remove it next time, but there's no particular
12074 reason why we will succeed next time.
12076 Note that at this point, old_loc->owner is still
12077 valid, as delete_breakpoint frees the breakpoint
12078 only after calling us. */
12079 printf_filtered (_("warning: Error removing "
12080 "breakpoint %d\n"),
12081 old_loc
->owner
->number
);
12089 if (removed
&& target_is_non_stop_p ()
12090 && need_moribund_for_location_type (old_loc
))
12092 /* This location was removed from the target. In
12093 non-stop mode, a race condition is possible where
12094 we've removed a breakpoint, but stop events for that
12095 breakpoint are already queued and will arrive later.
12096 We apply an heuristic to be able to distinguish such
12097 SIGTRAPs from other random SIGTRAPs: we keep this
12098 breakpoint location for a bit, and will retire it
12099 after we see some number of events. The theory here
12100 is that reporting of events should, "on the average",
12101 be fair, so after a while we'll see events from all
12102 threads that have anything of interest, and no longer
12103 need to keep this breakpoint location around. We
12104 don't hold locations forever so to reduce chances of
12105 mistaking a non-breakpoint SIGTRAP for a breakpoint
12108 The heuristic failing can be disastrous on
12109 decr_pc_after_break targets.
12111 On decr_pc_after_break targets, like e.g., x86-linux,
12112 if we fail to recognize a late breakpoint SIGTRAP,
12113 because events_till_retirement has reached 0 too
12114 soon, we'll fail to do the PC adjustment, and report
12115 a random SIGTRAP to the user. When the user resumes
12116 the inferior, it will most likely immediately crash
12117 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12118 corrupted, because of being resumed e.g., in the
12119 middle of a multi-byte instruction, or skipped a
12120 one-byte instruction. This was actually seen happen
12121 on native x86-linux, and should be less rare on
12122 targets that do not support new thread events, like
12123 remote, due to the heuristic depending on
12126 Mistaking a random SIGTRAP for a breakpoint trap
12127 causes similar symptoms (PC adjustment applied when
12128 it shouldn't), but then again, playing with SIGTRAPs
12129 behind the debugger's back is asking for trouble.
12131 Since hardware watchpoint traps are always
12132 distinguishable from other traps, so we don't need to
12133 apply keep hardware watchpoint moribund locations
12134 around. We simply always ignore hardware watchpoint
12135 traps we can no longer explain. */
12137 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12138 old_loc
->owner
= NULL
;
12140 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12144 old_loc
->owner
= NULL
;
12145 decref_bp_location (&old_loc
);
12150 /* Rescan breakpoints at the same address and section, marking the
12151 first one as "first" and any others as "duplicates". This is so
12152 that the bpt instruction is only inserted once. If we have a
12153 permanent breakpoint at the same place as BPT, make that one the
12154 official one, and the rest as duplicates. Permanent breakpoints
12155 are sorted first for the same address.
12157 Do the same for hardware watchpoints, but also considering the
12158 watchpoint's type (regular/access/read) and length. */
12160 bp_loc_first
= NULL
;
12161 wp_loc_first
= NULL
;
12162 awp_loc_first
= NULL
;
12163 rwp_loc_first
= NULL
;
12164 ALL_BP_LOCATIONS (loc
, locp
)
12166 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12168 struct bp_location
**loc_first_p
;
12171 if (!unduplicated_should_be_inserted (loc
)
12172 || !breakpoint_address_is_meaningful (b
)
12173 /* Don't detect duplicate for tracepoint locations because they are
12174 never duplicated. See the comments in field `duplicate' of
12175 `struct bp_location'. */
12176 || is_tracepoint (b
))
12178 /* Clear the condition modification flag. */
12179 loc
->condition_changed
= condition_unchanged
;
12183 if (b
->type
== bp_hardware_watchpoint
)
12184 loc_first_p
= &wp_loc_first
;
12185 else if (b
->type
== bp_read_watchpoint
)
12186 loc_first_p
= &rwp_loc_first
;
12187 else if (b
->type
== bp_access_watchpoint
)
12188 loc_first_p
= &awp_loc_first
;
12190 loc_first_p
= &bp_loc_first
;
12192 if (*loc_first_p
== NULL
12193 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12194 || !breakpoint_locations_match (loc
, *loc_first_p
))
12196 *loc_first_p
= loc
;
12197 loc
->duplicate
= 0;
12199 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12201 loc
->needs_update
= 1;
12202 /* Clear the condition modification flag. */
12203 loc
->condition_changed
= condition_unchanged
;
12209 /* This and the above ensure the invariant that the first location
12210 is not duplicated, and is the inserted one.
12211 All following are marked as duplicated, and are not inserted. */
12213 swap_insertion (loc
, *loc_first_p
);
12214 loc
->duplicate
= 1;
12216 /* Clear the condition modification flag. */
12217 loc
->condition_changed
= condition_unchanged
;
12220 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12222 if (insert_mode
!= UGLL_DONT_INSERT
)
12223 insert_breakpoint_locations ();
12226 /* Even though the caller told us to not insert new
12227 locations, we may still need to update conditions on the
12228 target's side of breakpoints that were already inserted
12229 if the target is evaluating breakpoint conditions. We
12230 only update conditions for locations that are marked
12232 update_inserted_breakpoint_locations ();
12236 if (insert_mode
!= UGLL_DONT_INSERT
)
12237 download_tracepoint_locations ();
12241 breakpoint_retire_moribund (void)
12243 struct bp_location
*loc
;
12246 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12247 if (--(loc
->events_till_retirement
) == 0)
12249 decref_bp_location (&loc
);
12250 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12256 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12261 update_global_location_list (insert_mode
);
12263 CATCH (e
, RETURN_MASK_ERROR
)
12269 /* Clear BKP from a BPS. */
12272 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12276 for (bs
= bps
; bs
; bs
= bs
->next
)
12277 if (bs
->breakpoint_at
== bpt
)
12279 bs
->breakpoint_at
= NULL
;
12280 bs
->old_val
= NULL
;
12281 /* bs->commands will be freed later. */
12285 /* Callback for iterate_over_threads. */
12287 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12289 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12291 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12295 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12299 say_where (struct breakpoint
*b
)
12301 struct value_print_options opts
;
12303 get_user_print_options (&opts
);
12305 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12307 if (b
->loc
== NULL
)
12309 /* For pending locations, the output differs slightly based
12310 on b->extra_string. If this is non-NULL, it contains either
12311 a condition or dprintf arguments. */
12312 if (b
->extra_string
== NULL
)
12314 printf_filtered (_(" (%s) pending."),
12315 event_location_to_string (b
->location
.get ()));
12317 else if (b
->type
== bp_dprintf
)
12319 printf_filtered (_(" (%s,%s) pending."),
12320 event_location_to_string (b
->location
.get ()),
12325 printf_filtered (_(" (%s %s) pending."),
12326 event_location_to_string (b
->location
.get ()),
12332 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12334 printf_filtered (" at ");
12335 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12338 if (b
->loc
->symtab
!= NULL
)
12340 /* If there is a single location, we can print the location
12342 if (b
->loc
->next
== NULL
)
12343 printf_filtered (": file %s, line %d.",
12344 symtab_to_filename_for_display (b
->loc
->symtab
),
12345 b
->loc
->line_number
);
12347 /* This is not ideal, but each location may have a
12348 different file name, and this at least reflects the
12349 real situation somewhat. */
12350 printf_filtered (": %s.",
12351 event_location_to_string (b
->location
.get ()));
12356 struct bp_location
*loc
= b
->loc
;
12358 for (; loc
; loc
= loc
->next
)
12360 printf_filtered (" (%d locations)", n
);
12365 /* Default bp_location_ops methods. */
12368 bp_location_dtor (struct bp_location
*self
)
12370 xfree (self
->function_name
);
12373 static const struct bp_location_ops bp_location_ops
=
12378 /* Destructor for the breakpoint base class. */
12380 breakpoint::~breakpoint ()
12382 xfree (this->cond_string
);
12383 xfree (this->extra_string
);
12384 xfree (this->filter
);
12387 static struct bp_location
*
12388 base_breakpoint_allocate_location (struct breakpoint
*self
)
12390 return new bp_location (&bp_location_ops
, self
);
12394 base_breakpoint_re_set (struct breakpoint
*b
)
12396 /* Nothing to re-set. */
12399 #define internal_error_pure_virtual_called() \
12400 gdb_assert_not_reached ("pure virtual function called")
12403 base_breakpoint_insert_location (struct bp_location
*bl
)
12405 internal_error_pure_virtual_called ();
12409 base_breakpoint_remove_location (struct bp_location
*bl
,
12410 enum remove_bp_reason reason
)
12412 internal_error_pure_virtual_called ();
12416 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12417 const address_space
*aspace
,
12419 const struct target_waitstatus
*ws
)
12421 internal_error_pure_virtual_called ();
12425 base_breakpoint_check_status (bpstat bs
)
12430 /* A "works_in_software_mode" breakpoint_ops method that just internal
12434 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12436 internal_error_pure_virtual_called ();
12439 /* A "resources_needed" breakpoint_ops method that just internal
12443 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12445 internal_error_pure_virtual_called ();
12448 static enum print_stop_action
12449 base_breakpoint_print_it (bpstat bs
)
12451 internal_error_pure_virtual_called ();
12455 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12456 struct ui_out
*uiout
)
12462 base_breakpoint_print_mention (struct breakpoint
*b
)
12464 internal_error_pure_virtual_called ();
12468 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12470 internal_error_pure_virtual_called ();
12474 base_breakpoint_create_sals_from_location
12475 (const struct event_location
*location
,
12476 struct linespec_result
*canonical
,
12477 enum bptype type_wanted
)
12479 internal_error_pure_virtual_called ();
12483 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12484 struct linespec_result
*c
,
12485 gdb::unique_xmalloc_ptr
<char> cond_string
,
12486 gdb::unique_xmalloc_ptr
<char> extra_string
,
12487 enum bptype type_wanted
,
12488 enum bpdisp disposition
,
12490 int task
, int ignore_count
,
12491 const struct breakpoint_ops
*o
,
12492 int from_tty
, int enabled
,
12493 int internal
, unsigned flags
)
12495 internal_error_pure_virtual_called ();
12498 static std::vector
<symtab_and_line
>
12499 base_breakpoint_decode_location (struct breakpoint
*b
,
12500 const struct event_location
*location
,
12501 struct program_space
*search_pspace
)
12503 internal_error_pure_virtual_called ();
12506 /* The default 'explains_signal' method. */
12509 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12514 /* The default "after_condition_true" method. */
12517 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12519 /* Nothing to do. */
12522 struct breakpoint_ops base_breakpoint_ops
=
12524 base_breakpoint_allocate_location
,
12525 base_breakpoint_re_set
,
12526 base_breakpoint_insert_location
,
12527 base_breakpoint_remove_location
,
12528 base_breakpoint_breakpoint_hit
,
12529 base_breakpoint_check_status
,
12530 base_breakpoint_resources_needed
,
12531 base_breakpoint_works_in_software_mode
,
12532 base_breakpoint_print_it
,
12534 base_breakpoint_print_one_detail
,
12535 base_breakpoint_print_mention
,
12536 base_breakpoint_print_recreate
,
12537 base_breakpoint_create_sals_from_location
,
12538 base_breakpoint_create_breakpoints_sal
,
12539 base_breakpoint_decode_location
,
12540 base_breakpoint_explains_signal
,
12541 base_breakpoint_after_condition_true
,
12544 /* Default breakpoint_ops methods. */
12547 bkpt_re_set (struct breakpoint
*b
)
12549 /* FIXME: is this still reachable? */
12550 if (breakpoint_event_location_empty_p (b
))
12552 /* Anything without a location can't be re-set. */
12553 delete_breakpoint (b
);
12557 breakpoint_re_set_default (b
);
12561 bkpt_insert_location (struct bp_location
*bl
)
12563 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12565 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12566 bl
->target_info
.placed_address
= addr
;
12568 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12569 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12571 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12575 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12577 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12578 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12580 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12584 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12585 const address_space
*aspace
, CORE_ADDR bp_addr
,
12586 const struct target_waitstatus
*ws
)
12588 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12589 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12592 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12596 if (overlay_debugging
/* unmapped overlay section */
12597 && section_is_overlay (bl
->section
)
12598 && !section_is_mapped (bl
->section
))
12605 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12606 const address_space
*aspace
, CORE_ADDR bp_addr
,
12607 const struct target_waitstatus
*ws
)
12609 if (dprintf_style
== dprintf_style_agent
12610 && target_can_run_breakpoint_commands ())
12612 /* An agent-style dprintf never causes a stop. If we see a trap
12613 for this address it must be for a breakpoint that happens to
12614 be set at the same address. */
12618 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12622 bkpt_resources_needed (const struct bp_location
*bl
)
12624 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12629 static enum print_stop_action
12630 bkpt_print_it (bpstat bs
)
12632 struct breakpoint
*b
;
12633 const struct bp_location
*bl
;
12635 struct ui_out
*uiout
= current_uiout
;
12637 gdb_assert (bs
->bp_location_at
!= NULL
);
12639 bl
= bs
->bp_location_at
;
12640 b
= bs
->breakpoint_at
;
12642 bp_temp
= b
->disposition
== disp_del
;
12643 if (bl
->address
!= bl
->requested_address
)
12644 breakpoint_adjustment_warning (bl
->requested_address
,
12647 annotate_breakpoint (b
->number
);
12648 maybe_print_thread_hit_breakpoint (uiout
);
12651 uiout
->text ("Temporary breakpoint ");
12653 uiout
->text ("Breakpoint ");
12654 if (uiout
->is_mi_like_p ())
12656 uiout
->field_string ("reason",
12657 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12658 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12660 uiout
->field_int ("bkptno", b
->number
);
12661 uiout
->text (", ");
12663 return PRINT_SRC_AND_LOC
;
12667 bkpt_print_mention (struct breakpoint
*b
)
12669 if (current_uiout
->is_mi_like_p ())
12674 case bp_breakpoint
:
12675 case bp_gnu_ifunc_resolver
:
12676 if (b
->disposition
== disp_del
)
12677 printf_filtered (_("Temporary breakpoint"));
12679 printf_filtered (_("Breakpoint"));
12680 printf_filtered (_(" %d"), b
->number
);
12681 if (b
->type
== bp_gnu_ifunc_resolver
)
12682 printf_filtered (_(" at gnu-indirect-function resolver"));
12684 case bp_hardware_breakpoint
:
12685 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12688 printf_filtered (_("Dprintf %d"), b
->number
);
12696 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12698 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12699 fprintf_unfiltered (fp
, "tbreak");
12700 else if (tp
->type
== bp_breakpoint
)
12701 fprintf_unfiltered (fp
, "break");
12702 else if (tp
->type
== bp_hardware_breakpoint
12703 && tp
->disposition
== disp_del
)
12704 fprintf_unfiltered (fp
, "thbreak");
12705 else if (tp
->type
== bp_hardware_breakpoint
)
12706 fprintf_unfiltered (fp
, "hbreak");
12708 internal_error (__FILE__
, __LINE__
,
12709 _("unhandled breakpoint type %d"), (int) tp
->type
);
12711 fprintf_unfiltered (fp
, " %s",
12712 event_location_to_string (tp
->location
.get ()));
12714 /* Print out extra_string if this breakpoint is pending. It might
12715 contain, for example, conditions that were set by the user. */
12716 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12717 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12719 print_recreate_thread (tp
, fp
);
12723 bkpt_create_sals_from_location (const struct event_location
*location
,
12724 struct linespec_result
*canonical
,
12725 enum bptype type_wanted
)
12727 create_sals_from_location_default (location
, canonical
, type_wanted
);
12731 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12732 struct linespec_result
*canonical
,
12733 gdb::unique_xmalloc_ptr
<char> cond_string
,
12734 gdb::unique_xmalloc_ptr
<char> extra_string
,
12735 enum bptype type_wanted
,
12736 enum bpdisp disposition
,
12738 int task
, int ignore_count
,
12739 const struct breakpoint_ops
*ops
,
12740 int from_tty
, int enabled
,
12741 int internal
, unsigned flags
)
12743 create_breakpoints_sal_default (gdbarch
, canonical
,
12744 std::move (cond_string
),
12745 std::move (extra_string
),
12747 disposition
, thread
, task
,
12748 ignore_count
, ops
, from_tty
,
12749 enabled
, internal
, flags
);
12752 static std::vector
<symtab_and_line
>
12753 bkpt_decode_location (struct breakpoint
*b
,
12754 const struct event_location
*location
,
12755 struct program_space
*search_pspace
)
12757 return decode_location_default (b
, location
, search_pspace
);
12760 /* Virtual table for internal breakpoints. */
12763 internal_bkpt_re_set (struct breakpoint
*b
)
12767 /* Delete overlay event and longjmp master breakpoints; they
12768 will be reset later by breakpoint_re_set. */
12769 case bp_overlay_event
:
12770 case bp_longjmp_master
:
12771 case bp_std_terminate_master
:
12772 case bp_exception_master
:
12773 delete_breakpoint (b
);
12776 /* This breakpoint is special, it's set up when the inferior
12777 starts and we really don't want to touch it. */
12778 case bp_shlib_event
:
12780 /* Like bp_shlib_event, this breakpoint type is special. Once
12781 it is set up, we do not want to touch it. */
12782 case bp_thread_event
:
12788 internal_bkpt_check_status (bpstat bs
)
12790 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12792 /* If requested, stop when the dynamic linker notifies GDB of
12793 events. This allows the user to get control and place
12794 breakpoints in initializer routines for dynamically loaded
12795 objects (among other things). */
12796 bs
->stop
= stop_on_solib_events
;
12797 bs
->print
= stop_on_solib_events
;
12803 static enum print_stop_action
12804 internal_bkpt_print_it (bpstat bs
)
12806 struct breakpoint
*b
;
12808 b
= bs
->breakpoint_at
;
12812 case bp_shlib_event
:
12813 /* Did we stop because the user set the stop_on_solib_events
12814 variable? (If so, we report this as a generic, "Stopped due
12815 to shlib event" message.) */
12816 print_solib_event (0);
12819 case bp_thread_event
:
12820 /* Not sure how we will get here.
12821 GDB should not stop for these breakpoints. */
12822 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12825 case bp_overlay_event
:
12826 /* By analogy with the thread event, GDB should not stop for these. */
12827 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12830 case bp_longjmp_master
:
12831 /* These should never be enabled. */
12832 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12835 case bp_std_terminate_master
:
12836 /* These should never be enabled. */
12837 printf_filtered (_("std::terminate Master Breakpoint: "
12838 "gdb should not stop!\n"));
12841 case bp_exception_master
:
12842 /* These should never be enabled. */
12843 printf_filtered (_("Exception Master Breakpoint: "
12844 "gdb should not stop!\n"));
12848 return PRINT_NOTHING
;
12852 internal_bkpt_print_mention (struct breakpoint
*b
)
12854 /* Nothing to mention. These breakpoints are internal. */
12857 /* Virtual table for momentary breakpoints */
12860 momentary_bkpt_re_set (struct breakpoint
*b
)
12862 /* Keep temporary breakpoints, which can be encountered when we step
12863 over a dlopen call and solib_add is resetting the breakpoints.
12864 Otherwise these should have been blown away via the cleanup chain
12865 or by breakpoint_init_inferior when we rerun the executable. */
12869 momentary_bkpt_check_status (bpstat bs
)
12871 /* Nothing. The point of these breakpoints is causing a stop. */
12874 static enum print_stop_action
12875 momentary_bkpt_print_it (bpstat bs
)
12877 return PRINT_UNKNOWN
;
12881 momentary_bkpt_print_mention (struct breakpoint
*b
)
12883 /* Nothing to mention. These breakpoints are internal. */
12886 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12888 It gets cleared already on the removal of the first one of such placed
12889 breakpoints. This is OK as they get all removed altogether. */
12891 longjmp_breakpoint::~longjmp_breakpoint ()
12893 thread_info
*tp
= find_thread_global_id (this->thread
);
12896 tp
->initiating_frame
= null_frame_id
;
12899 /* Specific methods for probe breakpoints. */
12902 bkpt_probe_insert_location (struct bp_location
*bl
)
12904 int v
= bkpt_insert_location (bl
);
12908 /* The insertion was successful, now let's set the probe's semaphore
12910 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
12911 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
12920 bkpt_probe_remove_location (struct bp_location
*bl
,
12921 enum remove_bp_reason reason
)
12923 /* Let's clear the semaphore before removing the location. */
12924 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
12925 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
12929 return bkpt_remove_location (bl
, reason
);
12933 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
12934 struct linespec_result
*canonical
,
12935 enum bptype type_wanted
)
12937 struct linespec_sals lsal
;
12939 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12941 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12942 canonical
->lsals
.push_back (std::move (lsal
));
12945 static std::vector
<symtab_and_line
>
12946 bkpt_probe_decode_location (struct breakpoint
*b
,
12947 const struct event_location
*location
,
12948 struct program_space
*search_pspace
)
12950 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12952 error (_("probe not found"));
12956 /* The breakpoint_ops structure to be used in tracepoints. */
12959 tracepoint_re_set (struct breakpoint
*b
)
12961 breakpoint_re_set_default (b
);
12965 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12966 const address_space
*aspace
, CORE_ADDR bp_addr
,
12967 const struct target_waitstatus
*ws
)
12969 /* By definition, the inferior does not report stops at
12975 tracepoint_print_one_detail (const struct breakpoint
*self
,
12976 struct ui_out
*uiout
)
12978 struct tracepoint
*tp
= (struct tracepoint
*) self
;
12979 if (tp
->static_trace_marker_id
)
12981 gdb_assert (self
->type
== bp_static_tracepoint
);
12983 uiout
->text ("\tmarker id is ");
12984 uiout
->field_string ("static-tracepoint-marker-string-id",
12985 tp
->static_trace_marker_id
);
12986 uiout
->text ("\n");
12991 tracepoint_print_mention (struct breakpoint
*b
)
12993 if (current_uiout
->is_mi_like_p ())
12998 case bp_tracepoint
:
12999 printf_filtered (_("Tracepoint"));
13000 printf_filtered (_(" %d"), b
->number
);
13002 case bp_fast_tracepoint
:
13003 printf_filtered (_("Fast tracepoint"));
13004 printf_filtered (_(" %d"), b
->number
);
13006 case bp_static_tracepoint
:
13007 printf_filtered (_("Static tracepoint"));
13008 printf_filtered (_(" %d"), b
->number
);
13011 internal_error (__FILE__
, __LINE__
,
13012 _("unhandled tracepoint type %d"), (int) b
->type
);
13019 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13021 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13023 if (self
->type
== bp_fast_tracepoint
)
13024 fprintf_unfiltered (fp
, "ftrace");
13025 else if (self
->type
== bp_static_tracepoint
)
13026 fprintf_unfiltered (fp
, "strace");
13027 else if (self
->type
== bp_tracepoint
)
13028 fprintf_unfiltered (fp
, "trace");
13030 internal_error (__FILE__
, __LINE__
,
13031 _("unhandled tracepoint type %d"), (int) self
->type
);
13033 fprintf_unfiltered (fp
, " %s",
13034 event_location_to_string (self
->location
.get ()));
13035 print_recreate_thread (self
, fp
);
13037 if (tp
->pass_count
)
13038 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13042 tracepoint_create_sals_from_location (const struct event_location
*location
,
13043 struct linespec_result
*canonical
,
13044 enum bptype type_wanted
)
13046 create_sals_from_location_default (location
, canonical
, type_wanted
);
13050 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13051 struct linespec_result
*canonical
,
13052 gdb::unique_xmalloc_ptr
<char> cond_string
,
13053 gdb::unique_xmalloc_ptr
<char> extra_string
,
13054 enum bptype type_wanted
,
13055 enum bpdisp disposition
,
13057 int task
, int ignore_count
,
13058 const struct breakpoint_ops
*ops
,
13059 int from_tty
, int enabled
,
13060 int internal
, unsigned flags
)
13062 create_breakpoints_sal_default (gdbarch
, canonical
,
13063 std::move (cond_string
),
13064 std::move (extra_string
),
13066 disposition
, thread
, task
,
13067 ignore_count
, ops
, from_tty
,
13068 enabled
, internal
, flags
);
13071 static std::vector
<symtab_and_line
>
13072 tracepoint_decode_location (struct breakpoint
*b
,
13073 const struct event_location
*location
,
13074 struct program_space
*search_pspace
)
13076 return decode_location_default (b
, location
, search_pspace
);
13079 struct breakpoint_ops tracepoint_breakpoint_ops
;
13081 /* The breakpoint_ops structure to be use on tracepoints placed in a
13085 tracepoint_probe_create_sals_from_location
13086 (const struct event_location
*location
,
13087 struct linespec_result
*canonical
,
13088 enum bptype type_wanted
)
13090 /* We use the same method for breakpoint on probes. */
13091 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13094 static std::vector
<symtab_and_line
>
13095 tracepoint_probe_decode_location (struct breakpoint
*b
,
13096 const struct event_location
*location
,
13097 struct program_space
*search_pspace
)
13099 /* We use the same method for breakpoint on probes. */
13100 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13103 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13105 /* Dprintf breakpoint_ops methods. */
13108 dprintf_re_set (struct breakpoint
*b
)
13110 breakpoint_re_set_default (b
);
13112 /* extra_string should never be non-NULL for dprintf. */
13113 gdb_assert (b
->extra_string
!= NULL
);
13115 /* 1 - connect to target 1, that can run breakpoint commands.
13116 2 - create a dprintf, which resolves fine.
13117 3 - disconnect from target 1
13118 4 - connect to target 2, that can NOT run breakpoint commands.
13120 After steps #3/#4, you'll want the dprintf command list to
13121 be updated, because target 1 and 2 may well return different
13122 answers for target_can_run_breakpoint_commands().
13123 Given absence of finer grained resetting, we get to do
13124 it all the time. */
13125 if (b
->extra_string
!= NULL
)
13126 update_dprintf_command_list (b
);
13129 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13132 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13134 fprintf_unfiltered (fp
, "dprintf %s,%s",
13135 event_location_to_string (tp
->location
.get ()),
13137 print_recreate_thread (tp
, fp
);
13140 /* Implement the "after_condition_true" breakpoint_ops method for
13143 dprintf's are implemented with regular commands in their command
13144 list, but we run the commands here instead of before presenting the
13145 stop to the user, as dprintf's don't actually cause a stop. This
13146 also makes it so that the commands of multiple dprintfs at the same
13147 address are all handled. */
13150 dprintf_after_condition_true (struct bpstats
*bs
)
13152 struct bpstats tmp_bs
;
13153 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13155 /* dprintf's never cause a stop. This wasn't set in the
13156 check_status hook instead because that would make the dprintf's
13157 condition not be evaluated. */
13160 /* Run the command list here. Take ownership of it instead of
13161 copying. We never want these commands to run later in
13162 bpstat_do_actions, if a breakpoint that causes a stop happens to
13163 be set at same address as this dprintf, or even if running the
13164 commands here throws. */
13165 tmp_bs
.commands
= bs
->commands
;
13166 bs
->commands
= NULL
;
13168 bpstat_do_actions_1 (&tmp_bs_p
);
13170 /* 'tmp_bs.commands' will usually be NULL by now, but
13171 bpstat_do_actions_1 may return early without processing the whole
13175 /* The breakpoint_ops structure to be used on static tracepoints with
13179 strace_marker_create_sals_from_location (const struct event_location
*location
,
13180 struct linespec_result
*canonical
,
13181 enum bptype type_wanted
)
13183 struct linespec_sals lsal
;
13184 const char *arg_start
, *arg
;
13186 arg
= arg_start
= get_linespec_location (location
);
13187 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13189 std::string
str (arg_start
, arg
- arg_start
);
13190 const char *ptr
= str
.c_str ();
13191 canonical
->location
= new_linespec_location (&ptr
);
13194 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13195 canonical
->lsals
.push_back (std::move (lsal
));
13199 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13200 struct linespec_result
*canonical
,
13201 gdb::unique_xmalloc_ptr
<char> cond_string
,
13202 gdb::unique_xmalloc_ptr
<char> extra_string
,
13203 enum bptype type_wanted
,
13204 enum bpdisp disposition
,
13206 int task
, int ignore_count
,
13207 const struct breakpoint_ops
*ops
,
13208 int from_tty
, int enabled
,
13209 int internal
, unsigned flags
)
13211 const linespec_sals
&lsal
= canonical
->lsals
[0];
13213 /* If the user is creating a static tracepoint by marker id
13214 (strace -m MARKER_ID), then store the sals index, so that
13215 breakpoint_re_set can try to match up which of the newly
13216 found markers corresponds to this one, and, don't try to
13217 expand multiple locations for each sal, given than SALS
13218 already should contain all sals for MARKER_ID. */
13220 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13222 event_location_up location
13223 = copy_event_location (canonical
->location
.get ());
13225 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13226 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13227 std::move (location
), NULL
,
13228 std::move (cond_string
),
13229 std::move (extra_string
),
13230 type_wanted
, disposition
,
13231 thread
, task
, ignore_count
, ops
,
13232 from_tty
, enabled
, internal
, flags
,
13233 canonical
->special_display
);
13234 /* Given that its possible to have multiple markers with
13235 the same string id, if the user is creating a static
13236 tracepoint by marker id ("strace -m MARKER_ID"), then
13237 store the sals index, so that breakpoint_re_set can
13238 try to match up which of the newly found markers
13239 corresponds to this one */
13240 tp
->static_trace_marker_id_idx
= i
;
13242 install_breakpoint (internal
, std::move (tp
), 0);
13246 static std::vector
<symtab_and_line
>
13247 strace_marker_decode_location (struct breakpoint
*b
,
13248 const struct event_location
*location
,
13249 struct program_space
*search_pspace
)
13251 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13252 const char *s
= get_linespec_location (location
);
13254 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13255 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13257 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13262 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13265 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13268 strace_marker_p (struct breakpoint
*b
)
13270 return b
->ops
== &strace_marker_breakpoint_ops
;
13273 /* Delete a breakpoint and clean up all traces of it in the data
13277 delete_breakpoint (struct breakpoint
*bpt
)
13279 struct breakpoint
*b
;
13281 gdb_assert (bpt
!= NULL
);
13283 /* Has this bp already been deleted? This can happen because
13284 multiple lists can hold pointers to bp's. bpstat lists are
13287 One example of this happening is a watchpoint's scope bp. When
13288 the scope bp triggers, we notice that the watchpoint is out of
13289 scope, and delete it. We also delete its scope bp. But the
13290 scope bp is marked "auto-deleting", and is already on a bpstat.
13291 That bpstat is then checked for auto-deleting bp's, which are
13294 A real solution to this problem might involve reference counts in
13295 bp's, and/or giving them pointers back to their referencing
13296 bpstat's, and teaching delete_breakpoint to only free a bp's
13297 storage when no more references were extent. A cheaper bandaid
13299 if (bpt
->type
== bp_none
)
13302 /* At least avoid this stale reference until the reference counting
13303 of breakpoints gets resolved. */
13304 if (bpt
->related_breakpoint
!= bpt
)
13306 struct breakpoint
*related
;
13307 struct watchpoint
*w
;
13309 if (bpt
->type
== bp_watchpoint_scope
)
13310 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13311 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13312 w
= (struct watchpoint
*) bpt
;
13316 watchpoint_del_at_next_stop (w
);
13318 /* Unlink bpt from the bpt->related_breakpoint ring. */
13319 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13320 related
= related
->related_breakpoint
);
13321 related
->related_breakpoint
= bpt
->related_breakpoint
;
13322 bpt
->related_breakpoint
= bpt
;
13325 /* watch_command_1 creates a watchpoint but only sets its number if
13326 update_watchpoint succeeds in creating its bp_locations. If there's
13327 a problem in that process, we'll be asked to delete the half-created
13328 watchpoint. In that case, don't announce the deletion. */
13330 observer_notify_breakpoint_deleted (bpt
);
13332 if (breakpoint_chain
== bpt
)
13333 breakpoint_chain
= bpt
->next
;
13335 ALL_BREAKPOINTS (b
)
13336 if (b
->next
== bpt
)
13338 b
->next
= bpt
->next
;
13342 /* Be sure no bpstat's are pointing at the breakpoint after it's
13344 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13345 in all threads for now. Note that we cannot just remove bpstats
13346 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13347 commands are associated with the bpstat; if we remove it here,
13348 then the later call to bpstat_do_actions (&stop_bpstat); in
13349 event-top.c won't do anything, and temporary breakpoints with
13350 commands won't work. */
13352 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13354 /* Now that breakpoint is removed from breakpoint list, update the
13355 global location list. This will remove locations that used to
13356 belong to this breakpoint. Do this before freeing the breakpoint
13357 itself, since remove_breakpoint looks at location's owner. It
13358 might be better design to have location completely
13359 self-contained, but it's not the case now. */
13360 update_global_location_list (UGLL_DONT_INSERT
);
13362 /* On the chance that someone will soon try again to delete this
13363 same bp, we mark it as deleted before freeing its storage. */
13364 bpt
->type
= bp_none
;
13368 /* Iterator function to call a user-provided callback function once
13369 for each of B and its related breakpoints. */
13372 iterate_over_related_breakpoints (struct breakpoint
*b
,
13373 gdb::function_view
<void (breakpoint
*)> function
)
13375 struct breakpoint
*related
;
13380 struct breakpoint
*next
;
13382 /* FUNCTION may delete RELATED. */
13383 next
= related
->related_breakpoint
;
13385 if (next
== related
)
13387 /* RELATED is the last ring entry. */
13388 function (related
);
13390 /* FUNCTION may have deleted it, so we'd never reach back to
13391 B. There's nothing left to do anyway, so just break
13396 function (related
);
13400 while (related
!= b
);
13404 delete_command (const char *arg
, int from_tty
)
13406 struct breakpoint
*b
, *b_tmp
;
13412 int breaks_to_delete
= 0;
13414 /* Delete all breakpoints if no argument. Do not delete
13415 internal breakpoints, these have to be deleted with an
13416 explicit breakpoint number argument. */
13417 ALL_BREAKPOINTS (b
)
13418 if (user_breakpoint_p (b
))
13420 breaks_to_delete
= 1;
13424 /* Ask user only if there are some breakpoints to delete. */
13426 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13428 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13429 if (user_breakpoint_p (b
))
13430 delete_breakpoint (b
);
13434 map_breakpoint_numbers
13435 (arg
, [&] (breakpoint
*b
)
13437 iterate_over_related_breakpoints (b
, delete_breakpoint
);
13441 /* Return true if all locations of B bound to PSPACE are pending. If
13442 PSPACE is NULL, all locations of all program spaces are
13446 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13448 struct bp_location
*loc
;
13450 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13451 if ((pspace
== NULL
13452 || loc
->pspace
== pspace
)
13453 && !loc
->shlib_disabled
13454 && !loc
->pspace
->executing_startup
)
13459 /* Subroutine of update_breakpoint_locations to simplify it.
13460 Return non-zero if multiple fns in list LOC have the same name.
13461 Null names are ignored. */
13464 ambiguous_names_p (struct bp_location
*loc
)
13466 struct bp_location
*l
;
13467 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13468 (int (*) (const void *,
13469 const void *)) streq
,
13470 NULL
, xcalloc
, xfree
);
13472 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13475 const char *name
= l
->function_name
;
13477 /* Allow for some names to be NULL, ignore them. */
13481 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13483 /* NOTE: We can assume slot != NULL here because xcalloc never
13487 htab_delete (htab
);
13493 htab_delete (htab
);
13497 /* When symbols change, it probably means the sources changed as well,
13498 and it might mean the static tracepoint markers are no longer at
13499 the same address or line numbers they used to be at last we
13500 checked. Losing your static tracepoints whenever you rebuild is
13501 undesirable. This function tries to resync/rematch gdb static
13502 tracepoints with the markers on the target, for static tracepoints
13503 that have not been set by marker id. Static tracepoint that have
13504 been set by marker id are reset by marker id in breakpoint_re_set.
13507 1) For a tracepoint set at a specific address, look for a marker at
13508 the old PC. If one is found there, assume to be the same marker.
13509 If the name / string id of the marker found is different from the
13510 previous known name, assume that means the user renamed the marker
13511 in the sources, and output a warning.
13513 2) For a tracepoint set at a given line number, look for a marker
13514 at the new address of the old line number. If one is found there,
13515 assume to be the same marker. If the name / string id of the
13516 marker found is different from the previous known name, assume that
13517 means the user renamed the marker in the sources, and output a
13520 3) If a marker is no longer found at the same address or line, it
13521 may mean the marker no longer exists. But it may also just mean
13522 the code changed a bit. Maybe the user added a few lines of code
13523 that made the marker move up or down (in line number terms). Ask
13524 the target for info about the marker with the string id as we knew
13525 it. If found, update line number and address in the matching
13526 static tracepoint. This will get confused if there's more than one
13527 marker with the same ID (possible in UST, although unadvised
13528 precisely because it confuses tools). */
13530 static struct symtab_and_line
13531 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13533 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13534 struct static_tracepoint_marker marker
;
13539 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13541 if (target_static_tracepoint_marker_at (pc
, &marker
))
13543 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13544 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13546 tp
->static_trace_marker_id
, marker
.str_id
);
13548 xfree (tp
->static_trace_marker_id
);
13549 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13550 release_static_tracepoint_marker (&marker
);
13555 /* Old marker wasn't found on target at lineno. Try looking it up
13557 if (!sal
.explicit_pc
13559 && sal
.symtab
!= NULL
13560 && tp
->static_trace_marker_id
!= NULL
)
13562 VEC(static_tracepoint_marker_p
) *markers
;
13565 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13567 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13569 struct symbol
*sym
;
13570 struct static_tracepoint_marker
*tpmarker
;
13571 struct ui_out
*uiout
= current_uiout
;
13572 struct explicit_location explicit_loc
;
13574 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13576 xfree (tp
->static_trace_marker_id
);
13577 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13579 warning (_("marker for static tracepoint %d (%s) not "
13580 "found at previous line number"),
13581 b
->number
, tp
->static_trace_marker_id
);
13583 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13584 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13585 uiout
->text ("Now in ");
13588 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
13589 uiout
->text (" at ");
13591 uiout
->field_string ("file",
13592 symtab_to_filename_for_display (sal2
.symtab
));
13595 if (uiout
->is_mi_like_p ())
13597 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13599 uiout
->field_string ("fullname", fullname
);
13602 uiout
->field_int ("line", sal2
.line
);
13603 uiout
->text ("\n");
13605 b
->loc
->line_number
= sal2
.line
;
13606 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13608 b
->location
.reset (NULL
);
13609 initialize_explicit_location (&explicit_loc
);
13610 explicit_loc
.source_filename
13611 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13612 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13613 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13614 b
->location
= new_explicit_location (&explicit_loc
);
13616 /* Might be nice to check if function changed, and warn if
13619 release_static_tracepoint_marker (tpmarker
);
13625 /* Returns 1 iff locations A and B are sufficiently same that
13626 we don't need to report breakpoint as changed. */
13629 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13633 if (a
->address
!= b
->address
)
13636 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13639 if (a
->enabled
!= b
->enabled
)
13646 if ((a
== NULL
) != (b
== NULL
))
13652 /* Split all locations of B that are bound to PSPACE out of B's
13653 location list to a separate list and return that list's head. If
13654 PSPACE is NULL, hoist out all locations of B. */
13656 static struct bp_location
*
13657 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13659 struct bp_location head
;
13660 struct bp_location
*i
= b
->loc
;
13661 struct bp_location
**i_link
= &b
->loc
;
13662 struct bp_location
*hoisted
= &head
;
13664 if (pspace
== NULL
)
13675 if (i
->pspace
== pspace
)
13690 /* Create new breakpoint locations for B (a hardware or software
13691 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13692 zero, then B is a ranged breakpoint. Only recreates locations for
13693 FILTER_PSPACE. Locations of other program spaces are left
13697 update_breakpoint_locations (struct breakpoint
*b
,
13698 struct program_space
*filter_pspace
,
13699 gdb::array_view
<const symtab_and_line
> sals
,
13700 gdb::array_view
<const symtab_and_line
> sals_end
)
13703 struct bp_location
*existing_locations
;
13705 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13707 /* Ranged breakpoints have only one start location and one end
13709 b
->enable_state
= bp_disabled
;
13710 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13711 "multiple locations found\n"),
13716 /* If there's no new locations, and all existing locations are
13717 pending, don't do anything. This optimizes the common case where
13718 all locations are in the same shared library, that was unloaded.
13719 We'd like to retain the location, so that when the library is
13720 loaded again, we don't loose the enabled/disabled status of the
13721 individual locations. */
13722 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13725 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13727 for (const auto &sal
: sals
)
13729 struct bp_location
*new_loc
;
13731 switch_to_program_space_and_thread (sal
.pspace
);
13733 new_loc
= add_location_to_breakpoint (b
, &sal
);
13735 /* Reparse conditions, they might contain references to the
13737 if (b
->cond_string
!= NULL
)
13741 s
= b
->cond_string
;
13744 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13745 block_for_pc (sal
.pc
),
13748 CATCH (e
, RETURN_MASK_ERROR
)
13750 warning (_("failed to reevaluate condition "
13751 "for breakpoint %d: %s"),
13752 b
->number
, e
.message
);
13753 new_loc
->enabled
= 0;
13758 if (!sals_end
.empty ())
13760 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13762 new_loc
->length
= end
- sals
[0].pc
+ 1;
13766 /* If possible, carry over 'disable' status from existing
13769 struct bp_location
*e
= existing_locations
;
13770 /* If there are multiple breakpoints with the same function name,
13771 e.g. for inline functions, comparing function names won't work.
13772 Instead compare pc addresses; this is just a heuristic as things
13773 may have moved, but in practice it gives the correct answer
13774 often enough until a better solution is found. */
13775 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13777 for (; e
; e
= e
->next
)
13779 if (!e
->enabled
&& e
->function_name
)
13781 struct bp_location
*l
= b
->loc
;
13782 if (have_ambiguous_names
)
13784 for (; l
; l
= l
->next
)
13785 if (breakpoint_locations_match (e
, l
))
13793 for (; l
; l
= l
->next
)
13794 if (l
->function_name
13795 && strcmp (e
->function_name
, l
->function_name
) == 0)
13805 if (!locations_are_equal (existing_locations
, b
->loc
))
13806 observer_notify_breakpoint_modified (b
);
13809 /* Find the SaL locations corresponding to the given LOCATION.
13810 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13812 static std::vector
<symtab_and_line
>
13813 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13814 struct program_space
*search_pspace
, int *found
)
13816 struct gdb_exception exception
= exception_none
;
13818 gdb_assert (b
->ops
!= NULL
);
13820 std::vector
<symtab_and_line
> sals
;
13824 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13826 CATCH (e
, RETURN_MASK_ERROR
)
13828 int not_found_and_ok
= 0;
13832 /* For pending breakpoints, it's expected that parsing will
13833 fail until the right shared library is loaded. User has
13834 already told to create pending breakpoints and don't need
13835 extra messages. If breakpoint is in bp_shlib_disabled
13836 state, then user already saw the message about that
13837 breakpoint being disabled, and don't want to see more
13839 if (e
.error
== NOT_FOUND_ERROR
13840 && (b
->condition_not_parsed
13842 && search_pspace
!= NULL
13843 && b
->loc
->pspace
!= search_pspace
)
13844 || (b
->loc
&& b
->loc
->shlib_disabled
)
13845 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13846 || b
->enable_state
== bp_disabled
))
13847 not_found_and_ok
= 1;
13849 if (!not_found_and_ok
)
13851 /* We surely don't want to warn about the same breakpoint
13852 10 times. One solution, implemented here, is disable
13853 the breakpoint on error. Another solution would be to
13854 have separate 'warning emitted' flag. Since this
13855 happens only when a binary has changed, I don't know
13856 which approach is better. */
13857 b
->enable_state
= bp_disabled
;
13858 throw_exception (e
);
13863 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13865 for (auto &sal
: sals
)
13866 resolve_sal_pc (&sal
);
13867 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13869 char *cond_string
, *extra_string
;
13872 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
13873 &cond_string
, &thread
, &task
,
13875 gdb_assert (b
->cond_string
== NULL
);
13877 b
->cond_string
= cond_string
;
13878 b
->thread
= thread
;
13882 xfree (b
->extra_string
);
13883 b
->extra_string
= extra_string
;
13885 b
->condition_not_parsed
= 0;
13888 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13889 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13899 /* The default re_set method, for typical hardware or software
13900 breakpoints. Reevaluate the breakpoint and recreate its
13904 breakpoint_re_set_default (struct breakpoint
*b
)
13906 struct program_space
*filter_pspace
= current_program_space
;
13907 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13910 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13911 filter_pspace
, &found
);
13913 expanded
= std::move (sals
);
13915 if (b
->location_range_end
!= NULL
)
13917 std::vector
<symtab_and_line
> sals_end
13918 = location_to_sals (b
, b
->location_range_end
.get (),
13919 filter_pspace
, &found
);
13921 expanded_end
= std::move (sals_end
);
13924 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13927 /* Default method for creating SALs from an address string. It basically
13928 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13931 create_sals_from_location_default (const struct event_location
*location
,
13932 struct linespec_result
*canonical
,
13933 enum bptype type_wanted
)
13935 parse_breakpoint_sals (location
, canonical
);
13938 /* Call create_breakpoints_sal for the given arguments. This is the default
13939 function for the `create_breakpoints_sal' method of
13943 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13944 struct linespec_result
*canonical
,
13945 gdb::unique_xmalloc_ptr
<char> cond_string
,
13946 gdb::unique_xmalloc_ptr
<char> extra_string
,
13947 enum bptype type_wanted
,
13948 enum bpdisp disposition
,
13950 int task
, int ignore_count
,
13951 const struct breakpoint_ops
*ops
,
13952 int from_tty
, int enabled
,
13953 int internal
, unsigned flags
)
13955 create_breakpoints_sal (gdbarch
, canonical
,
13956 std::move (cond_string
),
13957 std::move (extra_string
),
13958 type_wanted
, disposition
,
13959 thread
, task
, ignore_count
, ops
, from_tty
,
13960 enabled
, internal
, flags
);
13963 /* Decode the line represented by S by calling decode_line_full. This is the
13964 default function for the `decode_location' method of breakpoint_ops. */
13966 static std::vector
<symtab_and_line
>
13967 decode_location_default (struct breakpoint
*b
,
13968 const struct event_location
*location
,
13969 struct program_space
*search_pspace
)
13971 struct linespec_result canonical
;
13973 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
13974 (struct symtab
*) NULL
, 0,
13975 &canonical
, multiple_symbols_all
,
13978 /* We should get 0 or 1 resulting SALs. */
13979 gdb_assert (canonical
.lsals
.size () < 2);
13981 if (!canonical
.lsals
.empty ())
13983 const linespec_sals
&lsal
= canonical
.lsals
[0];
13984 return std::move (lsal
.sals
);
13989 /* Reset a breakpoint. */
13992 breakpoint_re_set_one (breakpoint
*b
)
13994 input_radix
= b
->input_radix
;
13995 set_language (b
->language
);
13997 b
->ops
->re_set (b
);
14000 /* Re-set breakpoint locations for the current program space.
14001 Locations bound to other program spaces are left untouched. */
14004 breakpoint_re_set (void)
14006 struct breakpoint
*b
, *b_tmp
;
14009 scoped_restore_current_language save_language
;
14010 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
14011 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
14013 /* Note: we must not try to insert locations until after all
14014 breakpoints have been re-set. Otherwise, e.g., when re-setting
14015 breakpoint 1, we'd insert the locations of breakpoint 2, which
14016 hadn't been re-set yet, and thus may have stale locations. */
14018 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14022 breakpoint_re_set_one (b
);
14024 CATCH (ex
, RETURN_MASK_ALL
)
14026 exception_fprintf (gdb_stderr
, ex
,
14027 "Error in re-setting breakpoint %d: ",
14033 jit_breakpoint_re_set ();
14036 create_overlay_event_breakpoint ();
14037 create_longjmp_master_breakpoint ();
14038 create_std_terminate_master_breakpoint ();
14039 create_exception_master_breakpoint ();
14041 /* Now we can insert. */
14042 update_global_location_list (UGLL_MAY_INSERT
);
14045 /* Reset the thread number of this breakpoint:
14047 - If the breakpoint is for all threads, leave it as-is.
14048 - Else, reset it to the current thread for inferior_ptid. */
14050 breakpoint_re_set_thread (struct breakpoint
*b
)
14052 if (b
->thread
!= -1)
14054 if (in_thread_list (inferior_ptid
))
14055 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14057 /* We're being called after following a fork. The new fork is
14058 selected as current, and unless this was a vfork will have a
14059 different program space from the original thread. Reset that
14061 b
->loc
->pspace
= current_program_space
;
14065 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14066 If from_tty is nonzero, it prints a message to that effect,
14067 which ends with a period (no newline). */
14070 set_ignore_count (int bptnum
, int count
, int from_tty
)
14072 struct breakpoint
*b
;
14077 ALL_BREAKPOINTS (b
)
14078 if (b
->number
== bptnum
)
14080 if (is_tracepoint (b
))
14082 if (from_tty
&& count
!= 0)
14083 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14088 b
->ignore_count
= count
;
14092 printf_filtered (_("Will stop next time "
14093 "breakpoint %d is reached."),
14095 else if (count
== 1)
14096 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14099 printf_filtered (_("Will ignore next %d "
14100 "crossings of breakpoint %d."),
14103 observer_notify_breakpoint_modified (b
);
14107 error (_("No breakpoint number %d."), bptnum
);
14110 /* Command to set ignore-count of breakpoint N to COUNT. */
14113 ignore_command (char *args
, int from_tty
)
14119 error_no_arg (_("a breakpoint number"));
14121 num
= get_number (&p
);
14123 error (_("bad breakpoint number: '%s'"), args
);
14125 error (_("Second argument (specified ignore-count) is missing."));
14127 set_ignore_count (num
,
14128 longest_to_int (value_as_long (parse_and_eval (p
))),
14131 printf_filtered ("\n");
14134 /* Call FUNCTION on each of the breakpoints
14135 whose numbers are given in ARGS. */
14138 map_breakpoint_numbers (const char *args
,
14139 gdb::function_view
<void (breakpoint
*)> function
)
14142 struct breakpoint
*b
, *tmp
;
14144 if (args
== 0 || *args
== '\0')
14145 error_no_arg (_("one or more breakpoint numbers"));
14147 number_or_range_parser
parser (args
);
14149 while (!parser
.finished ())
14151 const char *p
= parser
.cur_tok ();
14152 bool match
= false;
14154 num
= parser
.get_number ();
14157 warning (_("bad breakpoint number at or near '%s'"), p
);
14161 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14162 if (b
->number
== num
)
14169 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14174 static struct bp_location
*
14175 find_location_by_number (const char *number
)
14180 struct breakpoint
*b
;
14181 struct bp_location
*loc
;
14184 bp_num
= get_number_trailer (&p1
, '.');
14185 if (bp_num
== 0 || p1
[0] != '.')
14186 error (_("Bad breakpoint number '%s'"), number
);
14188 ALL_BREAKPOINTS (b
)
14189 if (b
->number
== bp_num
)
14194 if (!b
|| b
->number
!= bp_num
)
14195 error (_("Bad breakpoint number '%s'"), number
);
14197 /* Skip the dot. */
14199 const char *save
= p1
;
14200 loc_num
= get_number (&p1
);
14202 error (_("Bad breakpoint location number '%s'"), number
);
14206 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14209 error (_("Bad breakpoint location number '%s'"), save
);
14215 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14216 If from_tty is nonzero, it prints a message to that effect,
14217 which ends with a period (no newline). */
14220 disable_breakpoint (struct breakpoint
*bpt
)
14222 /* Never disable a watchpoint scope breakpoint; we want to
14223 hit them when we leave scope so we can delete both the
14224 watchpoint and its scope breakpoint at that time. */
14225 if (bpt
->type
== bp_watchpoint_scope
)
14228 bpt
->enable_state
= bp_disabled
;
14230 /* Mark breakpoint locations modified. */
14231 mark_breakpoint_modified (bpt
);
14233 if (target_supports_enable_disable_tracepoint ()
14234 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14236 struct bp_location
*location
;
14238 for (location
= bpt
->loc
; location
; location
= location
->next
)
14239 target_disable_tracepoint (location
);
14242 update_global_location_list (UGLL_DONT_INSERT
);
14244 observer_notify_breakpoint_modified (bpt
);
14248 disable_command (const char *args
, int from_tty
)
14252 struct breakpoint
*bpt
;
14254 ALL_BREAKPOINTS (bpt
)
14255 if (user_breakpoint_p (bpt
))
14256 disable_breakpoint (bpt
);
14260 std::string num
= extract_arg (&args
);
14262 while (!num
.empty ())
14264 if (num
.find ('.') != std::string::npos
)
14266 struct bp_location
*loc
= find_location_by_number (num
.c_str ());
14273 mark_breakpoint_location_modified (loc
);
14275 if (target_supports_enable_disable_tracepoint ()
14276 && current_trace_status ()->running
&& loc
->owner
14277 && is_tracepoint (loc
->owner
))
14278 target_disable_tracepoint (loc
);
14280 update_global_location_list (UGLL_DONT_INSERT
);
14283 map_breakpoint_numbers
14284 (num
.c_str (), [&] (breakpoint
*b
)
14286 iterate_over_related_breakpoints (b
, disable_breakpoint
);
14288 num
= extract_arg (&args
);
14294 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14297 int target_resources_ok
;
14299 if (bpt
->type
== bp_hardware_breakpoint
)
14302 i
= hw_breakpoint_used_count ();
14303 target_resources_ok
=
14304 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14306 if (target_resources_ok
== 0)
14307 error (_("No hardware breakpoint support in the target."));
14308 else if (target_resources_ok
< 0)
14309 error (_("Hardware breakpoints used exceeds limit."));
14312 if (is_watchpoint (bpt
))
14314 /* Initialize it just to avoid a GCC false warning. */
14315 enum enable_state orig_enable_state
= bp_disabled
;
14319 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14321 orig_enable_state
= bpt
->enable_state
;
14322 bpt
->enable_state
= bp_enabled
;
14323 update_watchpoint (w
, 1 /* reparse */);
14325 CATCH (e
, RETURN_MASK_ALL
)
14327 bpt
->enable_state
= orig_enable_state
;
14328 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14335 bpt
->enable_state
= bp_enabled
;
14337 /* Mark breakpoint locations modified. */
14338 mark_breakpoint_modified (bpt
);
14340 if (target_supports_enable_disable_tracepoint ()
14341 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14343 struct bp_location
*location
;
14345 for (location
= bpt
->loc
; location
; location
= location
->next
)
14346 target_enable_tracepoint (location
);
14349 bpt
->disposition
= disposition
;
14350 bpt
->enable_count
= count
;
14351 update_global_location_list (UGLL_MAY_INSERT
);
14353 observer_notify_breakpoint_modified (bpt
);
14358 enable_breakpoint (struct breakpoint
*bpt
)
14360 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14363 /* The enable command enables the specified breakpoints (or all defined
14364 breakpoints) so they once again become (or continue to be) effective
14365 in stopping the inferior. */
14368 enable_command (const char *args
, int from_tty
)
14372 struct breakpoint
*bpt
;
14374 ALL_BREAKPOINTS (bpt
)
14375 if (user_breakpoint_p (bpt
))
14376 enable_breakpoint (bpt
);
14380 std::string num
= extract_arg (&args
);
14382 while (!num
.empty ())
14384 if (num
.find ('.') != std::string::npos
)
14386 struct bp_location
*loc
= find_location_by_number (num
.c_str ());
14393 mark_breakpoint_location_modified (loc
);
14395 if (target_supports_enable_disable_tracepoint ()
14396 && current_trace_status ()->running
&& loc
->owner
14397 && is_tracepoint (loc
->owner
))
14398 target_enable_tracepoint (loc
);
14400 update_global_location_list (UGLL_MAY_INSERT
);
14403 map_breakpoint_numbers
14404 (num
.c_str (), [&] (breakpoint
*b
)
14406 iterate_over_related_breakpoints (b
, enable_breakpoint
);
14408 num
= extract_arg (&args
);
14414 enable_once_command (const char *args
, int from_tty
)
14416 map_breakpoint_numbers
14417 (args
, [&] (breakpoint
*b
)
14419 iterate_over_related_breakpoints
14420 (b
, [&] (breakpoint
*bpt
)
14422 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14428 enable_count_command (const char *args
, int from_tty
)
14433 error_no_arg (_("hit count"));
14435 count
= get_number (&args
);
14437 map_breakpoint_numbers
14438 (args
, [&] (breakpoint
*b
)
14440 iterate_over_related_breakpoints
14441 (b
, [&] (breakpoint
*bpt
)
14443 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14449 enable_delete_command (const char *args
, int from_tty
)
14451 map_breakpoint_numbers
14452 (args
, [&] (breakpoint
*b
)
14454 iterate_over_related_breakpoints
14455 (b
, [&] (breakpoint
*bpt
)
14457 enable_breakpoint_disp (bpt
, disp_del
, 1);
14463 set_breakpoint_cmd (const char *args
, int from_tty
)
14468 show_breakpoint_cmd (const char *args
, int from_tty
)
14472 /* Invalidate last known value of any hardware watchpoint if
14473 the memory which that value represents has been written to by
14477 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14478 CORE_ADDR addr
, ssize_t len
,
14479 const bfd_byte
*data
)
14481 struct breakpoint
*bp
;
14483 ALL_BREAKPOINTS (bp
)
14484 if (bp
->enable_state
== bp_enabled
14485 && bp
->type
== bp_hardware_watchpoint
)
14487 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14489 if (wp
->val_valid
&& wp
->val
)
14491 struct bp_location
*loc
;
14493 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14494 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14495 && loc
->address
+ loc
->length
> addr
14496 && addr
+ len
> loc
->address
)
14498 value_free (wp
->val
);
14506 /* Create and insert a breakpoint for software single step. */
14509 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14510 const address_space
*aspace
,
14513 struct thread_info
*tp
= inferior_thread ();
14514 struct symtab_and_line sal
;
14515 CORE_ADDR pc
= next_pc
;
14517 if (tp
->control
.single_step_breakpoints
== NULL
)
14519 tp
->control
.single_step_breakpoints
14520 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14523 sal
= find_pc_line (pc
, 0);
14525 sal
.section
= find_pc_overlay (pc
);
14526 sal
.explicit_pc
= 1;
14527 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14529 update_global_location_list (UGLL_INSERT
);
14532 /* Insert single step breakpoints according to the current state. */
14535 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14537 struct regcache
*regcache
= get_current_regcache ();
14538 std::vector
<CORE_ADDR
> next_pcs
;
14540 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14542 if (!next_pcs
.empty ())
14544 struct frame_info
*frame
= get_current_frame ();
14545 const address_space
*aspace
= get_frame_address_space (frame
);
14547 for (CORE_ADDR pc
: next_pcs
)
14548 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14556 /* See breakpoint.h. */
14559 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14560 const address_space
*aspace
,
14563 struct bp_location
*loc
;
14565 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14567 && breakpoint_location_address_match (loc
, aspace
, pc
))
14573 /* Check whether a software single-step breakpoint is inserted at
14577 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14580 struct breakpoint
*bpt
;
14582 ALL_BREAKPOINTS (bpt
)
14584 if (bpt
->type
== bp_single_step
14585 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14591 /* Tracepoint-specific operations. */
14593 /* Set tracepoint count to NUM. */
14595 set_tracepoint_count (int num
)
14597 tracepoint_count
= num
;
14598 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14602 trace_command (char *arg_in
, int from_tty
)
14604 const char *arg
= arg_in
;
14605 struct breakpoint_ops
*ops
;
14607 event_location_up location
= string_to_event_location (&arg
,
14609 if (location
!= NULL
14610 && event_location_type (location
.get ()) == PROBE_LOCATION
)
14611 ops
= &tracepoint_probe_breakpoint_ops
;
14613 ops
= &tracepoint_breakpoint_ops
;
14615 create_breakpoint (get_current_arch (),
14617 NULL
, 0, arg
, 1 /* parse arg */,
14619 bp_tracepoint
/* type_wanted */,
14620 0 /* Ignore count */,
14621 pending_break_support
,
14625 0 /* internal */, 0);
14629 ftrace_command (char *arg_in
, int from_tty
)
14631 const char *arg
= arg_in
;
14632 event_location_up location
= string_to_event_location (&arg
,
14634 create_breakpoint (get_current_arch (),
14636 NULL
, 0, arg
, 1 /* parse arg */,
14638 bp_fast_tracepoint
/* type_wanted */,
14639 0 /* Ignore count */,
14640 pending_break_support
,
14641 &tracepoint_breakpoint_ops
,
14644 0 /* internal */, 0);
14647 /* strace command implementation. Creates a static tracepoint. */
14650 strace_command (char *arg_in
, int from_tty
)
14652 const char *arg
= arg_in
;
14653 struct breakpoint_ops
*ops
;
14654 event_location_up location
;
14656 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14657 or with a normal static tracepoint. */
14658 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14660 ops
= &strace_marker_breakpoint_ops
;
14661 location
= new_linespec_location (&arg
);
14665 ops
= &tracepoint_breakpoint_ops
;
14666 location
= string_to_event_location (&arg
, current_language
);
14669 create_breakpoint (get_current_arch (),
14671 NULL
, 0, arg
, 1 /* parse arg */,
14673 bp_static_tracepoint
/* type_wanted */,
14674 0 /* Ignore count */,
14675 pending_break_support
,
14679 0 /* internal */, 0);
14682 /* Set up a fake reader function that gets command lines from a linked
14683 list that was acquired during tracepoint uploading. */
14685 static struct uploaded_tp
*this_utp
;
14686 static int next_cmd
;
14689 read_uploaded_action (void)
14693 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14700 /* Given information about a tracepoint as recorded on a target (which
14701 can be either a live system or a trace file), attempt to create an
14702 equivalent GDB tracepoint. This is not a reliable process, since
14703 the target does not necessarily have all the information used when
14704 the tracepoint was originally defined. */
14706 struct tracepoint
*
14707 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14709 const char *addr_str
;
14710 char small_buf
[100];
14711 struct tracepoint
*tp
;
14713 if (utp
->at_string
)
14714 addr_str
= utp
->at_string
;
14717 /* In the absence of a source location, fall back to raw
14718 address. Since there is no way to confirm that the address
14719 means the same thing as when the trace was started, warn the
14721 warning (_("Uploaded tracepoint %d has no "
14722 "source location, using raw address"),
14724 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14725 addr_str
= small_buf
;
14728 /* There's not much we can do with a sequence of bytecodes. */
14729 if (utp
->cond
&& !utp
->cond_string
)
14730 warning (_("Uploaded tracepoint %d condition "
14731 "has no source form, ignoring it"),
14734 event_location_up location
= string_to_event_location (&addr_str
,
14736 if (!create_breakpoint (get_current_arch (),
14738 utp
->cond_string
, -1, addr_str
,
14739 0 /* parse cond/thread */,
14741 utp
->type
/* type_wanted */,
14742 0 /* Ignore count */,
14743 pending_break_support
,
14744 &tracepoint_breakpoint_ops
,
14746 utp
->enabled
/* enabled */,
14748 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14751 /* Get the tracepoint we just created. */
14752 tp
= get_tracepoint (tracepoint_count
);
14753 gdb_assert (tp
!= NULL
);
14757 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14760 trace_pass_command (small_buf
, 0);
14763 /* If we have uploaded versions of the original commands, set up a
14764 special-purpose "reader" function and call the usual command line
14765 reader, then pass the result to the breakpoint command-setting
14767 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
14769 command_line_up cmd_list
;
14774 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
14776 breakpoint_set_commands (tp
, std::move (cmd_list
));
14778 else if (!VEC_empty (char_ptr
, utp
->actions
)
14779 || !VEC_empty (char_ptr
, utp
->step_actions
))
14780 warning (_("Uploaded tracepoint %d actions "
14781 "have no source form, ignoring them"),
14784 /* Copy any status information that might be available. */
14785 tp
->hit_count
= utp
->hit_count
;
14786 tp
->traceframe_usage
= utp
->traceframe_usage
;
14791 /* Print information on tracepoint number TPNUM_EXP, or all if
14795 info_tracepoints_command (char *args
, int from_tty
)
14797 struct ui_out
*uiout
= current_uiout
;
14800 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14802 if (num_printed
== 0)
14804 if (args
== NULL
|| *args
== '\0')
14805 uiout
->message ("No tracepoints.\n");
14807 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14810 default_collect_info ();
14813 /* The 'enable trace' command enables tracepoints.
14814 Not supported by all targets. */
14816 enable_trace_command (char *args
, int from_tty
)
14818 enable_command (args
, from_tty
);
14821 /* The 'disable trace' command disables tracepoints.
14822 Not supported by all targets. */
14824 disable_trace_command (char *args
, int from_tty
)
14826 disable_command (args
, from_tty
);
14829 /* Remove a tracepoint (or all if no argument). */
14831 delete_trace_command (const char *arg
, int from_tty
)
14833 struct breakpoint
*b
, *b_tmp
;
14839 int breaks_to_delete
= 0;
14841 /* Delete all breakpoints if no argument.
14842 Do not delete internal or call-dummy breakpoints, these
14843 have to be deleted with an explicit breakpoint number
14845 ALL_TRACEPOINTS (b
)
14846 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14848 breaks_to_delete
= 1;
14852 /* Ask user only if there are some breakpoints to delete. */
14854 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14856 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14857 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14858 delete_breakpoint (b
);
14862 map_breakpoint_numbers
14863 (arg
, [&] (breakpoint
*b
)
14865 iterate_over_related_breakpoints (b
, delete_breakpoint
);
14869 /* Helper function for trace_pass_command. */
14872 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14874 tp
->pass_count
= count
;
14875 observer_notify_breakpoint_modified (tp
);
14877 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14878 tp
->number
, count
);
14881 /* Set passcount for tracepoint.
14883 First command argument is passcount, second is tracepoint number.
14884 If tracepoint number omitted, apply to most recently defined.
14885 Also accepts special argument "all". */
14888 trace_pass_command (char *args
, int from_tty
)
14890 struct tracepoint
*t1
;
14891 unsigned int count
;
14893 if (args
== 0 || *args
== 0)
14894 error (_("passcount command requires an "
14895 "argument (count + optional TP num)"));
14897 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
14899 args
= skip_spaces (args
);
14900 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14902 struct breakpoint
*b
;
14904 args
+= 3; /* Skip special argument "all". */
14906 error (_("Junk at end of arguments."));
14908 ALL_TRACEPOINTS (b
)
14910 t1
= (struct tracepoint
*) b
;
14911 trace_pass_set_count (t1
, count
, from_tty
);
14914 else if (*args
== '\0')
14916 t1
= get_tracepoint_by_number (&args
, NULL
);
14918 trace_pass_set_count (t1
, count
, from_tty
);
14922 number_or_range_parser
parser (args
);
14923 while (!parser
.finished ())
14925 t1
= get_tracepoint_by_number (&args
, &parser
);
14927 trace_pass_set_count (t1
, count
, from_tty
);
14932 struct tracepoint
*
14933 get_tracepoint (int num
)
14935 struct breakpoint
*t
;
14937 ALL_TRACEPOINTS (t
)
14938 if (t
->number
== num
)
14939 return (struct tracepoint
*) t
;
14944 /* Find the tracepoint with the given target-side number (which may be
14945 different from the tracepoint number after disconnecting and
14948 struct tracepoint
*
14949 get_tracepoint_by_number_on_target (int num
)
14951 struct breakpoint
*b
;
14953 ALL_TRACEPOINTS (b
)
14955 struct tracepoint
*t
= (struct tracepoint
*) b
;
14957 if (t
->number_on_target
== num
)
14964 /* Utility: parse a tracepoint number and look it up in the list.
14965 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14966 If the argument is missing, the most recent tracepoint
14967 (tracepoint_count) is returned. */
14969 struct tracepoint
*
14970 get_tracepoint_by_number (char **arg
,
14971 number_or_range_parser
*parser
)
14973 struct breakpoint
*t
;
14975 char *instring
= arg
== NULL
? NULL
: *arg
;
14977 if (parser
!= NULL
)
14979 gdb_assert (!parser
->finished ());
14980 tpnum
= parser
->get_number ();
14982 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
14983 tpnum
= tracepoint_count
;
14985 tpnum
= get_number (arg
);
14989 if (instring
&& *instring
)
14990 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
14993 printf_filtered (_("No previous tracepoint\n"));
14997 ALL_TRACEPOINTS (t
)
14998 if (t
->number
== tpnum
)
15000 return (struct tracepoint
*) t
;
15003 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15008 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15010 if (b
->thread
!= -1)
15011 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15014 fprintf_unfiltered (fp
, " task %d", b
->task
);
15016 fprintf_unfiltered (fp
, "\n");
15019 /* Save information on user settable breakpoints (watchpoints, etc) to
15020 a new script file named FILENAME. If FILTER is non-NULL, call it
15021 on each breakpoint and only include the ones for which it returns
15025 save_breakpoints (const char *filename
, int from_tty
,
15026 int (*filter
) (const struct breakpoint
*))
15028 struct breakpoint
*tp
;
15030 int extra_trace_bits
= 0;
15032 if (filename
== 0 || *filename
== 0)
15033 error (_("Argument required (file name in which to save)"));
15035 /* See if we have anything to save. */
15036 ALL_BREAKPOINTS (tp
)
15038 /* Skip internal and momentary breakpoints. */
15039 if (!user_breakpoint_p (tp
))
15042 /* If we have a filter, only save the breakpoints it accepts. */
15043 if (filter
&& !filter (tp
))
15048 if (is_tracepoint (tp
))
15050 extra_trace_bits
= 1;
15052 /* We can stop searching. */
15059 warning (_("Nothing to save."));
15063 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15067 if (!fp
.open (expanded_filename
.get (), "w"))
15068 error (_("Unable to open file '%s' for saving (%s)"),
15069 expanded_filename
.get (), safe_strerror (errno
));
15071 if (extra_trace_bits
)
15072 save_trace_state_variables (&fp
);
15074 ALL_BREAKPOINTS (tp
)
15076 /* Skip internal and momentary breakpoints. */
15077 if (!user_breakpoint_p (tp
))
15080 /* If we have a filter, only save the breakpoints it accepts. */
15081 if (filter
&& !filter (tp
))
15084 tp
->ops
->print_recreate (tp
, &fp
);
15086 /* Note, we can't rely on tp->number for anything, as we can't
15087 assume the recreated breakpoint numbers will match. Use $bpnum
15090 if (tp
->cond_string
)
15091 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15093 if (tp
->ignore_count
)
15094 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15096 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15098 fp
.puts (" commands\n");
15100 current_uiout
->redirect (&fp
);
15103 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15105 CATCH (ex
, RETURN_MASK_ALL
)
15107 current_uiout
->redirect (NULL
);
15108 throw_exception (ex
);
15112 current_uiout
->redirect (NULL
);
15113 fp
.puts (" end\n");
15116 if (tp
->enable_state
== bp_disabled
)
15117 fp
.puts ("disable $bpnum\n");
15119 /* If this is a multi-location breakpoint, check if the locations
15120 should be individually disabled. Watchpoint locations are
15121 special, and not user visible. */
15122 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15124 struct bp_location
*loc
;
15127 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15129 fp
.printf ("disable $bpnum.%d\n", n
);
15133 if (extra_trace_bits
&& *default_collect
)
15134 fp
.printf ("set default-collect %s\n", default_collect
);
15137 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15140 /* The `save breakpoints' command. */
15143 save_breakpoints_command (const char *args
, int from_tty
)
15145 save_breakpoints (args
, from_tty
, NULL
);
15148 /* The `save tracepoints' command. */
15151 save_tracepoints_command (const char *args
, int from_tty
)
15153 save_breakpoints (args
, from_tty
, is_tracepoint
);
15156 /* Create a vector of all tracepoints. */
15158 VEC(breakpoint_p
) *
15159 all_tracepoints (void)
15161 VEC(breakpoint_p
) *tp_vec
= 0;
15162 struct breakpoint
*tp
;
15164 ALL_TRACEPOINTS (tp
)
15166 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15173 /* This help string is used to consolidate all the help string for specifying
15174 locations used by several commands. */
15176 #define LOCATION_HELP_STRING \
15177 "Linespecs are colon-separated lists of location parameters, such as\n\
15178 source filename, function name, label name, and line number.\n\
15179 Example: To specify the start of a label named \"the_top\" in the\n\
15180 function \"fact\" in the file \"factorial.c\", use\n\
15181 \"factorial.c:fact:the_top\".\n\
15183 Address locations begin with \"*\" and specify an exact address in the\n\
15184 program. Example: To specify the fourth byte past the start function\n\
15185 \"main\", use \"*main + 4\".\n\
15187 Explicit locations are similar to linespecs but use an option/argument\n\
15188 syntax to specify location parameters.\n\
15189 Example: To specify the start of the label named \"the_top\" in the\n\
15190 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15191 -function fact -label the_top\".\n"
15193 /* This help string is used for the break, hbreak, tbreak and thbreak
15194 commands. It is defined as a macro to prevent duplication.
15195 COMMAND should be a string constant containing the name of the
15198 #define BREAK_ARGS_HELP(command) \
15199 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15200 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15201 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15202 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15203 `-probe-dtrace' (for a DTrace probe).\n\
15204 LOCATION may be a linespec, address, or explicit location as described\n\
15207 With no LOCATION, uses current execution address of the selected\n\
15208 stack frame. This is useful for breaking on return to a stack frame.\n\
15210 THREADNUM is the number from \"info threads\".\n\
15211 CONDITION is a boolean expression.\n\
15212 \n" LOCATION_HELP_STRING "\n\
15213 Multiple breakpoints at one place are permitted, and useful if their\n\
15214 conditions are different.\n\
15216 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15218 /* List of subcommands for "catch". */
15219 static struct cmd_list_element
*catch_cmdlist
;
15221 /* List of subcommands for "tcatch". */
15222 static struct cmd_list_element
*tcatch_cmdlist
;
15225 add_catch_command (const char *name
, const char *docstring
,
15226 cmd_sfunc_ftype
*sfunc
,
15227 completer_ftype
*completer
,
15228 void *user_data_catch
,
15229 void *user_data_tcatch
)
15231 struct cmd_list_element
*command
;
15233 command
= add_cmd (name
, class_breakpoint
, docstring
,
15235 set_cmd_sfunc (command
, sfunc
);
15236 set_cmd_context (command
, user_data_catch
);
15237 set_cmd_completer (command
, completer
);
15239 command
= add_cmd (name
, class_breakpoint
, docstring
,
15241 set_cmd_sfunc (command
, sfunc
);
15242 set_cmd_context (command
, user_data_tcatch
);
15243 set_cmd_completer (command
, completer
);
15247 save_command (const char *arg
, int from_tty
)
15249 printf_unfiltered (_("\"save\" must be followed by "
15250 "the name of a save subcommand.\n"));
15251 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15254 struct breakpoint
*
15255 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15258 struct breakpoint
*b
, *b_tmp
;
15260 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15262 if ((*callback
) (b
, data
))
15269 /* Zero if any of the breakpoint's locations could be a location where
15270 functions have been inlined, nonzero otherwise. */
15273 is_non_inline_function (struct breakpoint
*b
)
15275 /* The shared library event breakpoint is set on the address of a
15276 non-inline function. */
15277 if (b
->type
== bp_shlib_event
)
15283 /* Nonzero if the specified PC cannot be a location where functions
15284 have been inlined. */
15287 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15288 const struct target_waitstatus
*ws
)
15290 struct breakpoint
*b
;
15291 struct bp_location
*bl
;
15293 ALL_BREAKPOINTS (b
)
15295 if (!is_non_inline_function (b
))
15298 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15300 if (!bl
->shlib_disabled
15301 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15309 /* Remove any references to OBJFILE which is going to be freed. */
15312 breakpoint_free_objfile (struct objfile
*objfile
)
15314 struct bp_location
**locp
, *loc
;
15316 ALL_BP_LOCATIONS (loc
, locp
)
15317 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15318 loc
->symtab
= NULL
;
15322 initialize_breakpoint_ops (void)
15324 static int initialized
= 0;
15326 struct breakpoint_ops
*ops
;
15332 /* The breakpoint_ops structure to be inherit by all kinds of
15333 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15334 internal and momentary breakpoints, etc.). */
15335 ops
= &bkpt_base_breakpoint_ops
;
15336 *ops
= base_breakpoint_ops
;
15337 ops
->re_set
= bkpt_re_set
;
15338 ops
->insert_location
= bkpt_insert_location
;
15339 ops
->remove_location
= bkpt_remove_location
;
15340 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15341 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15342 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15343 ops
->decode_location
= bkpt_decode_location
;
15345 /* The breakpoint_ops structure to be used in regular breakpoints. */
15346 ops
= &bkpt_breakpoint_ops
;
15347 *ops
= bkpt_base_breakpoint_ops
;
15348 ops
->re_set
= bkpt_re_set
;
15349 ops
->resources_needed
= bkpt_resources_needed
;
15350 ops
->print_it
= bkpt_print_it
;
15351 ops
->print_mention
= bkpt_print_mention
;
15352 ops
->print_recreate
= bkpt_print_recreate
;
15354 /* Ranged breakpoints. */
15355 ops
= &ranged_breakpoint_ops
;
15356 *ops
= bkpt_breakpoint_ops
;
15357 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15358 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15359 ops
->print_it
= print_it_ranged_breakpoint
;
15360 ops
->print_one
= print_one_ranged_breakpoint
;
15361 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15362 ops
->print_mention
= print_mention_ranged_breakpoint
;
15363 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15365 /* Internal breakpoints. */
15366 ops
= &internal_breakpoint_ops
;
15367 *ops
= bkpt_base_breakpoint_ops
;
15368 ops
->re_set
= internal_bkpt_re_set
;
15369 ops
->check_status
= internal_bkpt_check_status
;
15370 ops
->print_it
= internal_bkpt_print_it
;
15371 ops
->print_mention
= internal_bkpt_print_mention
;
15373 /* Momentary breakpoints. */
15374 ops
= &momentary_breakpoint_ops
;
15375 *ops
= bkpt_base_breakpoint_ops
;
15376 ops
->re_set
= momentary_bkpt_re_set
;
15377 ops
->check_status
= momentary_bkpt_check_status
;
15378 ops
->print_it
= momentary_bkpt_print_it
;
15379 ops
->print_mention
= momentary_bkpt_print_mention
;
15381 /* Probe breakpoints. */
15382 ops
= &bkpt_probe_breakpoint_ops
;
15383 *ops
= bkpt_breakpoint_ops
;
15384 ops
->insert_location
= bkpt_probe_insert_location
;
15385 ops
->remove_location
= bkpt_probe_remove_location
;
15386 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15387 ops
->decode_location
= bkpt_probe_decode_location
;
15390 ops
= &watchpoint_breakpoint_ops
;
15391 *ops
= base_breakpoint_ops
;
15392 ops
->re_set
= re_set_watchpoint
;
15393 ops
->insert_location
= insert_watchpoint
;
15394 ops
->remove_location
= remove_watchpoint
;
15395 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15396 ops
->check_status
= check_status_watchpoint
;
15397 ops
->resources_needed
= resources_needed_watchpoint
;
15398 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15399 ops
->print_it
= print_it_watchpoint
;
15400 ops
->print_mention
= print_mention_watchpoint
;
15401 ops
->print_recreate
= print_recreate_watchpoint
;
15402 ops
->explains_signal
= explains_signal_watchpoint
;
15404 /* Masked watchpoints. */
15405 ops
= &masked_watchpoint_breakpoint_ops
;
15406 *ops
= watchpoint_breakpoint_ops
;
15407 ops
->insert_location
= insert_masked_watchpoint
;
15408 ops
->remove_location
= remove_masked_watchpoint
;
15409 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15410 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15411 ops
->print_it
= print_it_masked_watchpoint
;
15412 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15413 ops
->print_mention
= print_mention_masked_watchpoint
;
15414 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15417 ops
= &tracepoint_breakpoint_ops
;
15418 *ops
= base_breakpoint_ops
;
15419 ops
->re_set
= tracepoint_re_set
;
15420 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15421 ops
->print_one_detail
= tracepoint_print_one_detail
;
15422 ops
->print_mention
= tracepoint_print_mention
;
15423 ops
->print_recreate
= tracepoint_print_recreate
;
15424 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15425 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15426 ops
->decode_location
= tracepoint_decode_location
;
15428 /* Probe tracepoints. */
15429 ops
= &tracepoint_probe_breakpoint_ops
;
15430 *ops
= tracepoint_breakpoint_ops
;
15431 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15432 ops
->decode_location
= tracepoint_probe_decode_location
;
15434 /* Static tracepoints with marker (`-m'). */
15435 ops
= &strace_marker_breakpoint_ops
;
15436 *ops
= tracepoint_breakpoint_ops
;
15437 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15438 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15439 ops
->decode_location
= strace_marker_decode_location
;
15441 /* Fork catchpoints. */
15442 ops
= &catch_fork_breakpoint_ops
;
15443 *ops
= base_breakpoint_ops
;
15444 ops
->insert_location
= insert_catch_fork
;
15445 ops
->remove_location
= remove_catch_fork
;
15446 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15447 ops
->print_it
= print_it_catch_fork
;
15448 ops
->print_one
= print_one_catch_fork
;
15449 ops
->print_mention
= print_mention_catch_fork
;
15450 ops
->print_recreate
= print_recreate_catch_fork
;
15452 /* Vfork catchpoints. */
15453 ops
= &catch_vfork_breakpoint_ops
;
15454 *ops
= base_breakpoint_ops
;
15455 ops
->insert_location
= insert_catch_vfork
;
15456 ops
->remove_location
= remove_catch_vfork
;
15457 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15458 ops
->print_it
= print_it_catch_vfork
;
15459 ops
->print_one
= print_one_catch_vfork
;
15460 ops
->print_mention
= print_mention_catch_vfork
;
15461 ops
->print_recreate
= print_recreate_catch_vfork
;
15463 /* Exec catchpoints. */
15464 ops
= &catch_exec_breakpoint_ops
;
15465 *ops
= base_breakpoint_ops
;
15466 ops
->insert_location
= insert_catch_exec
;
15467 ops
->remove_location
= remove_catch_exec
;
15468 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15469 ops
->print_it
= print_it_catch_exec
;
15470 ops
->print_one
= print_one_catch_exec
;
15471 ops
->print_mention
= print_mention_catch_exec
;
15472 ops
->print_recreate
= print_recreate_catch_exec
;
15474 /* Solib-related catchpoints. */
15475 ops
= &catch_solib_breakpoint_ops
;
15476 *ops
= base_breakpoint_ops
;
15477 ops
->insert_location
= insert_catch_solib
;
15478 ops
->remove_location
= remove_catch_solib
;
15479 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15480 ops
->check_status
= check_status_catch_solib
;
15481 ops
->print_it
= print_it_catch_solib
;
15482 ops
->print_one
= print_one_catch_solib
;
15483 ops
->print_mention
= print_mention_catch_solib
;
15484 ops
->print_recreate
= print_recreate_catch_solib
;
15486 ops
= &dprintf_breakpoint_ops
;
15487 *ops
= bkpt_base_breakpoint_ops
;
15488 ops
->re_set
= dprintf_re_set
;
15489 ops
->resources_needed
= bkpt_resources_needed
;
15490 ops
->print_it
= bkpt_print_it
;
15491 ops
->print_mention
= bkpt_print_mention
;
15492 ops
->print_recreate
= dprintf_print_recreate
;
15493 ops
->after_condition_true
= dprintf_after_condition_true
;
15494 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15497 /* Chain containing all defined "enable breakpoint" subcommands. */
15499 static struct cmd_list_element
*enablebreaklist
= NULL
;
15502 _initialize_breakpoint (void)
15504 struct cmd_list_element
*c
;
15506 initialize_breakpoint_ops ();
15508 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15509 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15510 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15512 breakpoint_objfile_key
15513 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_objfile_data
);
15515 breakpoint_chain
= 0;
15516 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15517 before a breakpoint is set. */
15518 breakpoint_count
= 0;
15520 tracepoint_count
= 0;
15522 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15523 Set ignore-count of breakpoint number N to COUNT.\n\
15524 Usage is `ignore N COUNT'."));
15526 add_com ("commands", class_breakpoint
, commands_command
, _("\
15527 Set commands to be executed when the given breakpoints are hit.\n\
15528 Give a space-separated breakpoint list as argument after \"commands\".\n\
15529 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15531 With no argument, the targeted breakpoint is the last one set.\n\
15532 The commands themselves follow starting on the next line.\n\
15533 Type a line containing \"end\" to indicate the end of them.\n\
15534 Give \"silent\" as the first line to make the breakpoint silent;\n\
15535 then no output is printed when it is hit, except what the commands print."));
15537 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15538 Specify breakpoint number N to break only if COND is true.\n\
15539 Usage is `condition N COND', where N is an integer and COND is an\n\
15540 expression to be evaluated whenever breakpoint N is reached."));
15541 set_cmd_completer (c
, condition_completer
);
15543 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15544 Set a temporary breakpoint.\n\
15545 Like \"break\" except the breakpoint is only temporary,\n\
15546 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15547 by using \"enable delete\" on the breakpoint number.\n\
15549 BREAK_ARGS_HELP ("tbreak")));
15550 set_cmd_completer (c
, location_completer
);
15552 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15553 Set a hardware assisted breakpoint.\n\
15554 Like \"break\" except the breakpoint requires hardware support,\n\
15555 some target hardware may not have this support.\n\
15557 BREAK_ARGS_HELP ("hbreak")));
15558 set_cmd_completer (c
, location_completer
);
15560 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15561 Set a temporary hardware assisted breakpoint.\n\
15562 Like \"hbreak\" except the breakpoint is only temporary,\n\
15563 so it will be deleted when hit.\n\
15565 BREAK_ARGS_HELP ("thbreak")));
15566 set_cmd_completer (c
, location_completer
);
15568 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15569 Enable some breakpoints.\n\
15570 Give breakpoint numbers (separated by spaces) as arguments.\n\
15571 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15572 This is used to cancel the effect of the \"disable\" command.\n\
15573 With a subcommand you can enable temporarily."),
15574 &enablelist
, "enable ", 1, &cmdlist
);
15576 add_com_alias ("en", "enable", class_breakpoint
, 1);
15578 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15579 Enable some breakpoints.\n\
15580 Give breakpoint numbers (separated by spaces) as arguments.\n\
15581 This is used to cancel the effect of the \"disable\" command.\n\
15582 May be abbreviated to simply \"enable\".\n"),
15583 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15585 add_cmd ("once", no_class
, enable_once_command
, _("\
15586 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15587 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15590 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15591 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15592 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15595 add_cmd ("count", no_class
, enable_count_command
, _("\
15596 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15597 If a breakpoint is hit while enabled in this fashion,\n\
15598 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15601 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15602 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15603 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15606 add_cmd ("once", no_class
, enable_once_command
, _("\
15607 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15608 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15611 add_cmd ("count", no_class
, enable_count_command
, _("\
15612 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15613 If a breakpoint is hit while enabled in this fashion,\n\
15614 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15617 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15618 Disable some breakpoints.\n\
15619 Arguments are breakpoint numbers with spaces in between.\n\
15620 To disable all breakpoints, give no argument.\n\
15621 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15622 &disablelist
, "disable ", 1, &cmdlist
);
15623 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15624 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15626 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15627 Disable some breakpoints.\n\
15628 Arguments are breakpoint numbers with spaces in between.\n\
15629 To disable all breakpoints, give no argument.\n\
15630 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15631 This command may be abbreviated \"disable\"."),
15634 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15635 Delete some breakpoints or auto-display expressions.\n\
15636 Arguments are breakpoint numbers with spaces in between.\n\
15637 To delete all breakpoints, give no argument.\n\
15639 Also a prefix command for deletion of other GDB objects.\n\
15640 The \"unset\" command is also an alias for \"delete\"."),
15641 &deletelist
, "delete ", 1, &cmdlist
);
15642 add_com_alias ("d", "delete", class_breakpoint
, 1);
15643 add_com_alias ("del", "delete", class_breakpoint
, 1);
15645 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15646 Delete some breakpoints or auto-display expressions.\n\
15647 Arguments are breakpoint numbers with spaces in between.\n\
15648 To delete all breakpoints, give no argument.\n\
15649 This command may be abbreviated \"delete\"."),
15652 add_com ("clear", class_breakpoint
, clear_command
, _("\
15653 Clear breakpoint at specified location.\n\
15654 Argument may be a linespec, explicit, or address location as described below.\n\
15656 With no argument, clears all breakpoints in the line that the selected frame\n\
15657 is executing in.\n"
15658 "\n" LOCATION_HELP_STRING
"\n\
15659 See also the \"delete\" command which clears breakpoints by number."));
15660 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15662 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15663 Set breakpoint at specified location.\n"
15664 BREAK_ARGS_HELP ("break")));
15665 set_cmd_completer (c
, location_completer
);
15667 add_com_alias ("b", "break", class_run
, 1);
15668 add_com_alias ("br", "break", class_run
, 1);
15669 add_com_alias ("bre", "break", class_run
, 1);
15670 add_com_alias ("brea", "break", class_run
, 1);
15674 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15675 Break in function/address or break at a line in the current file."),
15676 &stoplist
, "stop ", 1, &cmdlist
);
15677 add_cmd ("in", class_breakpoint
, stopin_command
,
15678 _("Break in function or address."), &stoplist
);
15679 add_cmd ("at", class_breakpoint
, stopat_command
,
15680 _("Break at a line in the current file."), &stoplist
);
15681 add_com ("status", class_info
, info_breakpoints_command
, _("\
15682 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15683 The \"Type\" column indicates one of:\n\
15684 \tbreakpoint - normal breakpoint\n\
15685 \twatchpoint - watchpoint\n\
15686 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15687 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15688 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15689 address and file/line number respectively.\n\
15691 Convenience variable \"$_\" and default examine address for \"x\"\n\
15692 are set to the address of the last breakpoint listed unless the command\n\
15693 is prefixed with \"server \".\n\n\
15694 Convenience variable \"$bpnum\" contains the number of the last\n\
15695 breakpoint set."));
15698 add_info ("breakpoints", info_breakpoints_command
, _("\
15699 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15700 The \"Type\" column indicates one of:\n\
15701 \tbreakpoint - normal breakpoint\n\
15702 \twatchpoint - watchpoint\n\
15703 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15704 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15705 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15706 address and file/line number respectively.\n\
15708 Convenience variable \"$_\" and default examine address for \"x\"\n\
15709 are set to the address of the last breakpoint listed unless the command\n\
15710 is prefixed with \"server \".\n\n\
15711 Convenience variable \"$bpnum\" contains the number of the last\n\
15712 breakpoint set."));
15714 add_info_alias ("b", "breakpoints", 1);
15716 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15717 Status of all breakpoints, or breakpoint number NUMBER.\n\
15718 The \"Type\" column indicates one of:\n\
15719 \tbreakpoint - normal breakpoint\n\
15720 \twatchpoint - watchpoint\n\
15721 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15722 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15723 \tuntil - internal breakpoint used by the \"until\" command\n\
15724 \tfinish - internal breakpoint used by the \"finish\" command\n\
15725 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15726 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15727 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15728 address and file/line number respectively.\n\
15730 Convenience variable \"$_\" and default examine address for \"x\"\n\
15731 are set to the address of the last breakpoint listed unless the command\n\
15732 is prefixed with \"server \".\n\n\
15733 Convenience variable \"$bpnum\" contains the number of the last\n\
15735 &maintenanceinfolist
);
15737 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15738 Set catchpoints to catch events."),
15739 &catch_cmdlist
, "catch ",
15740 0/*allow-unknown*/, &cmdlist
);
15742 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15743 Set temporary catchpoints to catch events."),
15744 &tcatch_cmdlist
, "tcatch ",
15745 0/*allow-unknown*/, &cmdlist
);
15747 add_catch_command ("fork", _("Catch calls to fork."),
15748 catch_fork_command_1
,
15750 (void *) (uintptr_t) catch_fork_permanent
,
15751 (void *) (uintptr_t) catch_fork_temporary
);
15752 add_catch_command ("vfork", _("Catch calls to vfork."),
15753 catch_fork_command_1
,
15755 (void *) (uintptr_t) catch_vfork_permanent
,
15756 (void *) (uintptr_t) catch_vfork_temporary
);
15757 add_catch_command ("exec", _("Catch calls to exec."),
15758 catch_exec_command_1
,
15762 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15763 Usage: catch load [REGEX]\n\
15764 If REGEX is given, only stop for libraries matching the regular expression."),
15765 catch_load_command_1
,
15769 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15770 Usage: catch unload [REGEX]\n\
15771 If REGEX is given, only stop for libraries matching the regular expression."),
15772 catch_unload_command_1
,
15777 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15778 Set a watchpoint for an expression.\n\
15779 Usage: watch [-l|-location] EXPRESSION\n\
15780 A watchpoint stops execution of your program whenever the value of\n\
15781 an expression changes.\n\
15782 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15783 the memory to which it refers."));
15784 set_cmd_completer (c
, expression_completer
);
15786 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15787 Set a read watchpoint for an expression.\n\
15788 Usage: rwatch [-l|-location] EXPRESSION\n\
15789 A watchpoint stops execution of your program whenever the value of\n\
15790 an expression is read.\n\
15791 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15792 the memory to which it refers."));
15793 set_cmd_completer (c
, expression_completer
);
15795 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15796 Set a watchpoint for an expression.\n\
15797 Usage: awatch [-l|-location] EXPRESSION\n\
15798 A watchpoint stops execution of your program whenever the value of\n\
15799 an expression is either read or written.\n\
15800 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15801 the memory to which it refers."));
15802 set_cmd_completer (c
, expression_completer
);
15804 add_info ("watchpoints", info_watchpoints_command
, _("\
15805 Status of specified watchpoints (all watchpoints if no argument)."));
15807 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15808 respond to changes - contrary to the description. */
15809 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15810 &can_use_hw_watchpoints
, _("\
15811 Set debugger's willingness to use watchpoint hardware."), _("\
15812 Show debugger's willingness to use watchpoint hardware."), _("\
15813 If zero, gdb will not use hardware for new watchpoints, even if\n\
15814 such is available. (However, any hardware watchpoints that were\n\
15815 created before setting this to nonzero, will continue to use watchpoint\n\
15818 show_can_use_hw_watchpoints
,
15819 &setlist
, &showlist
);
15821 can_use_hw_watchpoints
= 1;
15823 /* Tracepoint manipulation commands. */
15825 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15826 Set a tracepoint at specified location.\n\
15828 BREAK_ARGS_HELP ("trace") "\n\
15829 Do \"help tracepoints\" for info on other tracepoint commands."));
15830 set_cmd_completer (c
, location_completer
);
15832 add_com_alias ("tp", "trace", class_alias
, 0);
15833 add_com_alias ("tr", "trace", class_alias
, 1);
15834 add_com_alias ("tra", "trace", class_alias
, 1);
15835 add_com_alias ("trac", "trace", class_alias
, 1);
15837 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15838 Set a fast tracepoint at specified location.\n\
15840 BREAK_ARGS_HELP ("ftrace") "\n\
15841 Do \"help tracepoints\" for info on other tracepoint commands."));
15842 set_cmd_completer (c
, location_completer
);
15844 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15845 Set a static tracepoint at location or marker.\n\
15847 strace [LOCATION] [if CONDITION]\n\
15848 LOCATION may be a linespec, explicit, or address location (described below) \n\
15849 or -m MARKER_ID.\n\n\
15850 If a marker id is specified, probe the marker with that name. With\n\
15851 no LOCATION, uses current execution address of the selected stack frame.\n\
15852 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15853 This collects arbitrary user data passed in the probe point call to the\n\
15854 tracing library. You can inspect it when analyzing the trace buffer,\n\
15855 by printing the $_sdata variable like any other convenience variable.\n\
15857 CONDITION is a boolean expression.\n\
15858 \n" LOCATION_HELP_STRING
"\n\
15859 Multiple tracepoints at one place are permitted, and useful if their\n\
15860 conditions are different.\n\
15862 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15863 Do \"help tracepoints\" for info on other tracepoint commands."));
15864 set_cmd_completer (c
, location_completer
);
15866 add_info ("tracepoints", info_tracepoints_command
, _("\
15867 Status of specified tracepoints (all tracepoints if no argument).\n\
15868 Convenience variable \"$tpnum\" contains the number of the\n\
15869 last tracepoint set."));
15871 add_info_alias ("tp", "tracepoints", 1);
15873 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15874 Delete specified tracepoints.\n\
15875 Arguments are tracepoint numbers, separated by spaces.\n\
15876 No argument means delete all tracepoints."),
15878 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
15880 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15881 Disable specified tracepoints.\n\
15882 Arguments are tracepoint numbers, separated by spaces.\n\
15883 No argument means disable all tracepoints."),
15885 deprecate_cmd (c
, "disable");
15887 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15888 Enable specified tracepoints.\n\
15889 Arguments are tracepoint numbers, separated by spaces.\n\
15890 No argument means enable all tracepoints."),
15892 deprecate_cmd (c
, "enable");
15894 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15895 Set the passcount for a tracepoint.\n\
15896 The trace will end when the tracepoint has been passed 'count' times.\n\
15897 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15898 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15900 add_prefix_cmd ("save", class_breakpoint
, save_command
,
15901 _("Save breakpoint definitions as a script."),
15902 &save_cmdlist
, "save ",
15903 0/*allow-unknown*/, &cmdlist
);
15905 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15906 Save current breakpoint definitions as a script.\n\
15907 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15908 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15909 session to restore them."),
15911 set_cmd_completer (c
, filename_completer
);
15913 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15914 Save current tracepoint definitions as a script.\n\
15915 Use the 'source' command in another debug session to restore them."),
15917 set_cmd_completer (c
, filename_completer
);
15919 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
15920 deprecate_cmd (c
, "save tracepoints");
15922 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
15923 Breakpoint specific settings\n\
15924 Configure various breakpoint-specific variables such as\n\
15925 pending breakpoint behavior"),
15926 &breakpoint_set_cmdlist
, "set breakpoint ",
15927 0/*allow-unknown*/, &setlist
);
15928 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
15929 Breakpoint specific settings\n\
15930 Configure various breakpoint-specific variables such as\n\
15931 pending breakpoint behavior"),
15932 &breakpoint_show_cmdlist
, "show breakpoint ",
15933 0/*allow-unknown*/, &showlist
);
15935 add_setshow_auto_boolean_cmd ("pending", no_class
,
15936 &pending_break_support
, _("\
15937 Set debugger's behavior regarding pending breakpoints."), _("\
15938 Show debugger's behavior regarding pending breakpoints."), _("\
15939 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15940 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15941 an error. If auto, an unrecognized breakpoint location results in a\n\
15942 user-query to see if a pending breakpoint should be created."),
15944 show_pending_break_support
,
15945 &breakpoint_set_cmdlist
,
15946 &breakpoint_show_cmdlist
);
15948 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15950 add_setshow_boolean_cmd ("auto-hw", no_class
,
15951 &automatic_hardware_breakpoints
, _("\
15952 Set automatic usage of hardware breakpoints."), _("\
15953 Show automatic usage of hardware breakpoints."), _("\
15954 If set, the debugger will automatically use hardware breakpoints for\n\
15955 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15956 a warning will be emitted for such breakpoints."),
15958 show_automatic_hardware_breakpoints
,
15959 &breakpoint_set_cmdlist
,
15960 &breakpoint_show_cmdlist
);
15962 add_setshow_boolean_cmd ("always-inserted", class_support
,
15963 &always_inserted_mode
, _("\
15964 Set mode for inserting breakpoints."), _("\
15965 Show mode for inserting breakpoints."), _("\
15966 When this mode is on, breakpoints are inserted immediately as soon as\n\
15967 they're created, kept inserted even when execution stops, and removed\n\
15968 only when the user deletes them. When this mode is off (the default),\n\
15969 breakpoints are inserted only when execution continues, and removed\n\
15970 when execution stops."),
15972 &show_always_inserted_mode
,
15973 &breakpoint_set_cmdlist
,
15974 &breakpoint_show_cmdlist
);
15976 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
15977 condition_evaluation_enums
,
15978 &condition_evaluation_mode_1
, _("\
15979 Set mode of breakpoint condition evaluation."), _("\
15980 Show mode of breakpoint condition evaluation."), _("\
15981 When this is set to \"host\", breakpoint conditions will be\n\
15982 evaluated on the host's side by GDB. When it is set to \"target\",\n\
15983 breakpoint conditions will be downloaded to the target (if the target\n\
15984 supports such feature) and conditions will be evaluated on the target's side.\n\
15985 If this is set to \"auto\" (default), this will be automatically set to\n\
15986 \"target\" if it supports condition evaluation, otherwise it will\n\
15987 be set to \"gdb\""),
15988 &set_condition_evaluation_mode
,
15989 &show_condition_evaluation_mode
,
15990 &breakpoint_set_cmdlist
,
15991 &breakpoint_show_cmdlist
);
15993 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
15994 Set a breakpoint for an address range.\n\
15995 break-range START-LOCATION, END-LOCATION\n\
15996 where START-LOCATION and END-LOCATION can be one of the following:\n\
15997 LINENUM, for that line in the current file,\n\
15998 FILE:LINENUM, for that line in that file,\n\
15999 +OFFSET, for that number of lines after the current line\n\
16000 or the start of the range\n\
16001 FUNCTION, for the first line in that function,\n\
16002 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16003 *ADDRESS, for the instruction at that address.\n\
16005 The breakpoint will stop execution of the inferior whenever it executes\n\
16006 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16007 range (including START-LOCATION and END-LOCATION)."));
16009 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16010 Set a dynamic printf at specified location.\n\
16011 dprintf location,format string,arg1,arg2,...\n\
16012 location may be a linespec, explicit, or address location.\n"
16013 "\n" LOCATION_HELP_STRING
));
16014 set_cmd_completer (c
, location_completer
);
16016 add_setshow_enum_cmd ("dprintf-style", class_support
,
16017 dprintf_style_enums
, &dprintf_style
, _("\
16018 Set the style of usage for dynamic printf."), _("\
16019 Show the style of usage for dynamic printf."), _("\
16020 This setting chooses how GDB will do a dynamic printf.\n\
16021 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16022 console, as with the \"printf\" command.\n\
16023 If the value is \"call\", the print is done by calling a function in your\n\
16024 program; by default printf(), but you can choose a different function or\n\
16025 output stream by setting dprintf-function and dprintf-channel."),
16026 update_dprintf_commands
, NULL
,
16027 &setlist
, &showlist
);
16029 dprintf_function
= xstrdup ("printf");
16030 add_setshow_string_cmd ("dprintf-function", class_support
,
16031 &dprintf_function
, _("\
16032 Set the function to use for dynamic printf"), _("\
16033 Show the function to use for dynamic printf"), NULL
,
16034 update_dprintf_commands
, NULL
,
16035 &setlist
, &showlist
);
16037 dprintf_channel
= xstrdup ("");
16038 add_setshow_string_cmd ("dprintf-channel", class_support
,
16039 &dprintf_channel
, _("\
16040 Set the channel to use for dynamic printf"), _("\
16041 Show the channel to use for dynamic printf"), NULL
,
16042 update_dprintf_commands
, NULL
,
16043 &setlist
, &showlist
);
16045 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16046 &disconnected_dprintf
, _("\
16047 Set whether dprintf continues after GDB disconnects."), _("\
16048 Show whether dprintf continues after GDB disconnects."), _("\
16049 Use this to let dprintf commands continue to hit and produce output\n\
16050 even if GDB disconnects or detaches from the target."),
16053 &setlist
, &showlist
);
16055 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16056 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16057 (target agent only) This is useful for formatted output in user-defined commands."));
16059 automatic_hardware_breakpoints
= 1;
16061 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16062 observer_attach_thread_exit (remove_threaded_breakpoints
);