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
648 start_rbreak_breakpoints (void)
650 rbreak_start_breakpoint_count
= breakpoint_count
;
653 /* Called at the end of an "rbreak" command to record the last
657 end_rbreak_breakpoints (void)
659 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
662 /* Used in run_command to zero the hit count when a new run starts. */
665 clear_breakpoint_hit_counts (void)
667 struct breakpoint
*b
;
674 /* Return the breakpoint with the specified number, or NULL
675 if the number does not refer to an existing breakpoint. */
678 get_breakpoint (int num
)
680 struct breakpoint
*b
;
683 if (b
->number
== num
)
691 /* Mark locations as "conditions have changed" in case the target supports
692 evaluating conditions on its side. */
695 mark_breakpoint_modified (struct breakpoint
*b
)
697 struct bp_location
*loc
;
699 /* This is only meaningful if the target is
700 evaluating conditions and if the user has
701 opted for condition evaluation on the target's
703 if (gdb_evaluates_breakpoint_condition_p ()
704 || !target_supports_evaluation_of_breakpoint_conditions ())
707 if (!is_breakpoint (b
))
710 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
711 loc
->condition_changed
= condition_modified
;
714 /* Mark location as "conditions have changed" in case the target supports
715 evaluating conditions on its side. */
718 mark_breakpoint_location_modified (struct bp_location
*loc
)
720 /* This is only meaningful if the target is
721 evaluating conditions and if the user has
722 opted for condition evaluation on the target's
724 if (gdb_evaluates_breakpoint_condition_p ()
725 || !target_supports_evaluation_of_breakpoint_conditions ())
729 if (!is_breakpoint (loc
->owner
))
732 loc
->condition_changed
= condition_modified
;
735 /* Sets the condition-evaluation mode using the static global
736 condition_evaluation_mode. */
739 set_condition_evaluation_mode (char *args
, int from_tty
,
740 struct cmd_list_element
*c
)
742 const char *old_mode
, *new_mode
;
744 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
745 && !target_supports_evaluation_of_breakpoint_conditions ())
747 condition_evaluation_mode_1
= condition_evaluation_mode
;
748 warning (_("Target does not support breakpoint condition evaluation.\n"
749 "Using host evaluation mode instead."));
753 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
754 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
756 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
757 settings was "auto". */
758 condition_evaluation_mode
= condition_evaluation_mode_1
;
760 /* Only update the mode if the user picked a different one. */
761 if (new_mode
!= old_mode
)
763 struct bp_location
*loc
, **loc_tmp
;
764 /* If the user switched to a different evaluation mode, we
765 need to synch the changes with the target as follows:
767 "host" -> "target": Send all (valid) conditions to the target.
768 "target" -> "host": Remove all the conditions from the target.
771 if (new_mode
== condition_evaluation_target
)
773 /* Mark everything modified and synch conditions with the
775 ALL_BP_LOCATIONS (loc
, loc_tmp
)
776 mark_breakpoint_location_modified (loc
);
780 /* Manually mark non-duplicate locations to synch conditions
781 with the target. We do this to remove all the conditions the
782 target knows about. */
783 ALL_BP_LOCATIONS (loc
, loc_tmp
)
784 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
785 loc
->needs_update
= 1;
789 update_global_location_list (UGLL_MAY_INSERT
);
795 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
796 what "auto" is translating to. */
799 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
800 struct cmd_list_element
*c
, const char *value
)
802 if (condition_evaluation_mode
== condition_evaluation_auto
)
803 fprintf_filtered (file
,
804 _("Breakpoint condition evaluation "
805 "mode is %s (currently %s).\n"),
807 breakpoint_condition_evaluation_mode ());
809 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
813 /* A comparison function for bp_location AP and BP that is used by
814 bsearch. This comparison function only cares about addresses, unlike
815 the more general bp_locations_compare function. */
818 bp_locations_compare_addrs (const void *ap
, const void *bp
)
820 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
821 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
823 if (a
->address
== b
->address
)
826 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
829 /* Helper function to skip all bp_locations with addresses
830 less than ADDRESS. It returns the first bp_location that
831 is greater than or equal to ADDRESS. If none is found, just
834 static struct bp_location
**
835 get_first_locp_gte_addr (CORE_ADDR address
)
837 struct bp_location dummy_loc
;
838 struct bp_location
*dummy_locp
= &dummy_loc
;
839 struct bp_location
**locp_found
= NULL
;
841 /* Initialize the dummy location's address field. */
842 dummy_loc
.address
= address
;
844 /* Find a close match to the first location at ADDRESS. */
845 locp_found
= ((struct bp_location
**)
846 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
847 sizeof (struct bp_location
**),
848 bp_locations_compare_addrs
));
850 /* Nothing was found, nothing left to do. */
851 if (locp_found
== NULL
)
854 /* We may have found a location that is at ADDRESS but is not the first in the
855 location's list. Go backwards (if possible) and locate the first one. */
856 while ((locp_found
- 1) >= bp_locations
857 && (*(locp_found
- 1))->address
== address
)
864 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
867 xfree (b
->cond_string
);
868 b
->cond_string
= NULL
;
870 if (is_watchpoint (b
))
872 struct watchpoint
*w
= (struct watchpoint
*) b
;
874 w
->cond_exp
.reset ();
878 struct bp_location
*loc
;
880 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
884 /* No need to free the condition agent expression
885 bytecode (if we have one). We will handle this
886 when we go through update_global_location_list. */
893 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
897 const char *arg
= exp
;
899 /* I don't know if it matters whether this is the string the user
900 typed in or the decompiled expression. */
901 b
->cond_string
= xstrdup (arg
);
902 b
->condition_not_parsed
= 0;
904 if (is_watchpoint (b
))
906 struct watchpoint
*w
= (struct watchpoint
*) b
;
908 innermost_block
= NULL
;
910 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
912 error (_("Junk at end of expression"));
913 w
->cond_exp_valid_block
= innermost_block
;
917 struct bp_location
*loc
;
919 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
923 parse_exp_1 (&arg
, loc
->address
,
924 block_for_pc (loc
->address
), 0);
926 error (_("Junk at end of expression"));
930 mark_breakpoint_modified (b
);
932 observer_notify_breakpoint_modified (b
);
935 /* Completion for the "condition" command. */
938 condition_completer (struct cmd_list_element
*cmd
,
939 completion_tracker
&tracker
,
940 const char *text
, const char *word
)
944 text
= skip_spaces (text
);
945 space
= skip_to_space (text
);
949 struct breakpoint
*b
;
950 VEC (char_ptr
) *result
= NULL
;
954 /* We don't support completion of history indices. */
955 if (!isdigit (text
[1]))
956 complete_internalvar (tracker
, &text
[1]);
960 /* We're completing the breakpoint number. */
967 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
969 if (strncmp (number
, text
, len
) == 0)
971 gdb::unique_xmalloc_ptr
<char> copy (xstrdup (number
));
972 tracker
.add_completion (std::move (copy
));
979 /* We're completing the expression part. */
980 text
= skip_spaces (space
);
981 expression_completer (cmd
, tracker
, text
, word
);
984 /* condition N EXP -- set break condition of breakpoint N to EXP. */
987 condition_command (char *arg
, int from_tty
)
989 struct breakpoint
*b
;
994 error_no_arg (_("breakpoint number"));
997 bnum
= get_number (&p
);
999 error (_("Bad breakpoint argument: '%s'"), arg
);
1002 if (b
->number
== bnum
)
1004 /* Check if this breakpoint has a "stop" method implemented in an
1005 extension language. This method and conditions entered into GDB
1006 from the CLI are mutually exclusive. */
1007 const struct extension_language_defn
*extlang
1008 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1010 if (extlang
!= NULL
)
1012 error (_("Only one stop condition allowed. There is currently"
1013 " a %s stop condition defined for this breakpoint."),
1014 ext_lang_capitalized_name (extlang
));
1016 set_breakpoint_condition (b
, p
, from_tty
);
1018 if (is_breakpoint (b
))
1019 update_global_location_list (UGLL_MAY_INSERT
);
1024 error (_("No breakpoint number %d."), bnum
);
1027 /* Check that COMMAND do not contain commands that are suitable
1028 only for tracepoints and not suitable for ordinary breakpoints.
1029 Throw if any such commands is found. */
1032 check_no_tracepoint_commands (struct command_line
*commands
)
1034 struct command_line
*c
;
1036 for (c
= commands
; c
; c
= c
->next
)
1040 if (c
->control_type
== while_stepping_control
)
1041 error (_("The 'while-stepping' command can "
1042 "only be used for tracepoints"));
1044 for (i
= 0; i
< c
->body_count
; ++i
)
1045 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1047 /* Not that command parsing removes leading whitespace and comment
1048 lines and also empty lines. So, we only need to check for
1049 command directly. */
1050 if (strstr (c
->line
, "collect ") == c
->line
)
1051 error (_("The 'collect' command can only be used for tracepoints"));
1053 if (strstr (c
->line
, "teval ") == c
->line
)
1054 error (_("The 'teval' command can only be used for tracepoints"));
1058 struct longjmp_breakpoint
: public breakpoint
1060 ~longjmp_breakpoint () override
;
1063 /* Encapsulate tests for different types of tracepoints. */
1066 is_tracepoint_type (bptype type
)
1068 return (type
== bp_tracepoint
1069 || type
== bp_fast_tracepoint
1070 || type
== bp_static_tracepoint
);
1074 is_longjmp_type (bptype type
)
1076 return type
== bp_longjmp
|| type
== bp_exception
;
1080 is_tracepoint (const struct breakpoint
*b
)
1082 return is_tracepoint_type (b
->type
);
1085 /* Factory function to create an appropriate instance of breakpoint given
1088 static std::unique_ptr
<breakpoint
>
1089 new_breakpoint_from_type (bptype type
)
1093 if (is_tracepoint_type (type
))
1094 b
= new tracepoint ();
1095 else if (is_longjmp_type (type
))
1096 b
= new longjmp_breakpoint ();
1098 b
= new breakpoint ();
1100 return std::unique_ptr
<breakpoint
> (b
);
1103 /* A helper function that validates that COMMANDS are valid for a
1104 breakpoint. This function will throw an exception if a problem is
1108 validate_commands_for_breakpoint (struct breakpoint
*b
,
1109 struct command_line
*commands
)
1111 if (is_tracepoint (b
))
1113 struct tracepoint
*t
= (struct tracepoint
*) b
;
1114 struct command_line
*c
;
1115 struct command_line
*while_stepping
= 0;
1117 /* Reset the while-stepping step count. The previous commands
1118 might have included a while-stepping action, while the new
1122 /* We need to verify that each top-level element of commands is
1123 valid for tracepoints, that there's at most one
1124 while-stepping element, and that the while-stepping's body
1125 has valid tracing commands excluding nested while-stepping.
1126 We also need to validate the tracepoint action line in the
1127 context of the tracepoint --- validate_actionline actually
1128 has side effects, like setting the tracepoint's
1129 while-stepping STEP_COUNT, in addition to checking if the
1130 collect/teval actions parse and make sense in the
1131 tracepoint's context. */
1132 for (c
= commands
; c
; c
= c
->next
)
1134 if (c
->control_type
== while_stepping_control
)
1136 if (b
->type
== bp_fast_tracepoint
)
1137 error (_("The 'while-stepping' command "
1138 "cannot be used for fast tracepoint"));
1139 else if (b
->type
== bp_static_tracepoint
)
1140 error (_("The 'while-stepping' command "
1141 "cannot be used for static tracepoint"));
1144 error (_("The 'while-stepping' command "
1145 "can be used only once"));
1150 validate_actionline (c
->line
, b
);
1154 struct command_line
*c2
;
1156 gdb_assert (while_stepping
->body_count
== 1);
1157 c2
= while_stepping
->body_list
[0];
1158 for (; c2
; c2
= c2
->next
)
1160 if (c2
->control_type
== while_stepping_control
)
1161 error (_("The 'while-stepping' command cannot be nested"));
1167 check_no_tracepoint_commands (commands
);
1171 /* Return a vector of all the static tracepoints set at ADDR. The
1172 caller is responsible for releasing the vector. */
1175 static_tracepoints_here (CORE_ADDR addr
)
1177 struct breakpoint
*b
;
1178 VEC(breakpoint_p
) *found
= 0;
1179 struct bp_location
*loc
;
1182 if (b
->type
== bp_static_tracepoint
)
1184 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1185 if (loc
->address
== addr
)
1186 VEC_safe_push(breakpoint_p
, found
, b
);
1192 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1193 validate that only allowed commands are included. */
1196 breakpoint_set_commands (struct breakpoint
*b
,
1197 command_line_up
&&commands
)
1199 validate_commands_for_breakpoint (b
, commands
.get ());
1201 b
->commands
= std::move (commands
);
1202 observer_notify_breakpoint_modified (b
);
1205 /* Set the internal `silent' flag on the breakpoint. Note that this
1206 is not the same as the "silent" that may appear in the breakpoint's
1210 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1212 int old_silent
= b
->silent
;
1215 if (old_silent
!= silent
)
1216 observer_notify_breakpoint_modified (b
);
1219 /* Set the thread for this breakpoint. If THREAD is -1, make the
1220 breakpoint work for any thread. */
1223 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1225 int old_thread
= b
->thread
;
1228 if (old_thread
!= thread
)
1229 observer_notify_breakpoint_modified (b
);
1232 /* Set the task for this breakpoint. If TASK is 0, make the
1233 breakpoint work for any task. */
1236 breakpoint_set_task (struct breakpoint
*b
, int task
)
1238 int old_task
= b
->task
;
1241 if (old_task
!= task
)
1242 observer_notify_breakpoint_modified (b
);
1246 check_tracepoint_command (char *line
, void *closure
)
1248 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1250 validate_actionline (line
, b
);
1254 commands_command_1 (const char *arg
, int from_tty
,
1255 struct command_line
*control
)
1257 counted_command_line cmd
;
1259 std::string new_arg
;
1261 if (arg
== NULL
|| !*arg
)
1263 if (breakpoint_count
- prev_breakpoint_count
> 1)
1264 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1266 else if (breakpoint_count
> 0)
1267 new_arg
= string_printf ("%d", breakpoint_count
);
1268 arg
= new_arg
.c_str ();
1271 map_breakpoint_numbers
1272 (arg
, [&] (breakpoint
*b
)
1276 if (control
!= NULL
)
1277 cmd
= copy_command_lines (control
->body_list
[0]);
1281 = string_printf (_("Type commands for breakpoint(s) "
1282 "%s, one per line."),
1285 cmd
= read_command_lines (&str
[0],
1288 ? check_tracepoint_command
: 0),
1293 /* If a breakpoint was on the list more than once, we don't need to
1295 if (b
->commands
!= cmd
)
1297 validate_commands_for_breakpoint (b
, cmd
.get ());
1299 observer_notify_breakpoint_modified (b
);
1304 error (_("No breakpoints specified."));
1308 commands_command (char *arg
, int from_tty
)
1310 commands_command_1 (arg
, from_tty
, NULL
);
1313 /* Like commands_command, but instead of reading the commands from
1314 input stream, takes them from an already parsed command structure.
1316 This is used by cli-script.c to DTRT with breakpoint commands
1317 that are part of if and while bodies. */
1318 enum command_control_type
1319 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1321 commands_command_1 (arg
, 0, cmd
);
1322 return simple_control
;
1325 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1328 bp_location_has_shadow (struct bp_location
*bl
)
1330 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1334 if (bl
->target_info
.shadow_len
== 0)
1335 /* BL isn't valid, or doesn't shadow memory. */
1340 /* Update BUF, which is LEN bytes read from the target address
1341 MEMADDR, by replacing a memory breakpoint with its shadowed
1344 If READBUF is not NULL, this buffer must not overlap with the of
1345 the breakpoint location's shadow_contents buffer. Otherwise, a
1346 failed assertion internal error will be raised. */
1349 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1350 const gdb_byte
*writebuf_org
,
1351 ULONGEST memaddr
, LONGEST len
,
1352 struct bp_target_info
*target_info
,
1353 struct gdbarch
*gdbarch
)
1355 /* Now do full processing of the found relevant range of elements. */
1356 CORE_ADDR bp_addr
= 0;
1360 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1361 current_program_space
->aspace
, 0))
1363 /* The breakpoint is inserted in a different address space. */
1367 /* Addresses and length of the part of the breakpoint that
1369 bp_addr
= target_info
->placed_address
;
1370 bp_size
= target_info
->shadow_len
;
1372 if (bp_addr
+ bp_size
<= memaddr
)
1374 /* The breakpoint is entirely before the chunk of memory we are
1379 if (bp_addr
>= memaddr
+ len
)
1381 /* The breakpoint is entirely after the chunk of memory we are
1386 /* Offset within shadow_contents. */
1387 if (bp_addr
< memaddr
)
1389 /* Only copy the second part of the breakpoint. */
1390 bp_size
-= memaddr
- bp_addr
;
1391 bptoffset
= memaddr
- bp_addr
;
1395 if (bp_addr
+ bp_size
> memaddr
+ len
)
1397 /* Only copy the first part of the breakpoint. */
1398 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1401 if (readbuf
!= NULL
)
1403 /* Verify that the readbuf buffer does not overlap with the
1404 shadow_contents buffer. */
1405 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1406 || readbuf
>= (target_info
->shadow_contents
1407 + target_info
->shadow_len
));
1409 /* Update the read buffer with this inserted breakpoint's
1411 memcpy (readbuf
+ bp_addr
- memaddr
,
1412 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1416 const unsigned char *bp
;
1417 CORE_ADDR addr
= target_info
->reqstd_address
;
1420 /* Update the shadow with what we want to write to memory. */
1421 memcpy (target_info
->shadow_contents
+ bptoffset
,
1422 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1424 /* Determine appropriate breakpoint contents and size for this
1426 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1428 /* Update the final write buffer with this inserted
1429 breakpoint's INSN. */
1430 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1434 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1435 by replacing any memory breakpoints with their shadowed contents.
1437 If READBUF is not NULL, this buffer must not overlap with any of
1438 the breakpoint location's shadow_contents buffers. Otherwise,
1439 a failed assertion internal error will be raised.
1441 The range of shadowed area by each bp_location is:
1442 bl->address - bp_locations_placed_address_before_address_max
1443 up to bl->address + bp_locations_shadow_len_after_address_max
1444 The range we were requested to resolve shadows for is:
1445 memaddr ... memaddr + len
1446 Thus the safe cutoff boundaries for performance optimization are
1447 memaddr + len <= (bl->address
1448 - bp_locations_placed_address_before_address_max)
1450 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1453 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1454 const gdb_byte
*writebuf_org
,
1455 ULONGEST memaddr
, LONGEST len
)
1457 /* Left boundary, right boundary and median element of our binary
1459 unsigned bc_l
, bc_r
, bc
;
1461 /* Find BC_L which is a leftmost element which may affect BUF
1462 content. It is safe to report lower value but a failure to
1463 report higher one. */
1466 bc_r
= bp_locations_count
;
1467 while (bc_l
+ 1 < bc_r
)
1469 struct bp_location
*bl
;
1471 bc
= (bc_l
+ bc_r
) / 2;
1472 bl
= bp_locations
[bc
];
1474 /* Check first BL->ADDRESS will not overflow due to the added
1475 constant. Then advance the left boundary only if we are sure
1476 the BC element can in no way affect the BUF content (MEMADDR
1477 to MEMADDR + LEN range).
1479 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1480 offset so that we cannot miss a breakpoint with its shadow
1481 range tail still reaching MEMADDR. */
1483 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1485 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1492 /* Due to the binary search above, we need to make sure we pick the
1493 first location that's at BC_L's address. E.g., if there are
1494 multiple locations at the same address, BC_L may end up pointing
1495 at a duplicate location, and miss the "master"/"inserted"
1496 location. Say, given locations L1, L2 and L3 at addresses A and
1499 L1@A, L2@A, L3@B, ...
1501 BC_L could end up pointing at location L2, while the "master"
1502 location could be L1. Since the `loc->inserted' flag is only set
1503 on "master" locations, we'd forget to restore the shadow of L1
1506 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1509 /* Now do full processing of the found relevant range of elements. */
1511 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1513 struct bp_location
*bl
= bp_locations
[bc
];
1515 /* bp_location array has BL->OWNER always non-NULL. */
1516 if (bl
->owner
->type
== bp_none
)
1517 warning (_("reading through apparently deleted breakpoint #%d?"),
1520 /* Performance optimization: any further element can no longer affect BUF
1523 if (bl
->address
>= bp_locations_placed_address_before_address_max
1524 && memaddr
+ len
<= (bl
->address
1525 - bp_locations_placed_address_before_address_max
))
1528 if (!bp_location_has_shadow (bl
))
1531 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1532 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1538 /* Return true if BPT is either a software breakpoint or a hardware
1542 is_breakpoint (const struct breakpoint
*bpt
)
1544 return (bpt
->type
== bp_breakpoint
1545 || bpt
->type
== bp_hardware_breakpoint
1546 || bpt
->type
== bp_dprintf
);
1549 /* Return true if BPT is of any hardware watchpoint kind. */
1552 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1554 return (bpt
->type
== bp_hardware_watchpoint
1555 || bpt
->type
== bp_read_watchpoint
1556 || bpt
->type
== bp_access_watchpoint
);
1559 /* Return true if BPT is of any watchpoint kind, hardware or
1563 is_watchpoint (const struct breakpoint
*bpt
)
1565 return (is_hardware_watchpoint (bpt
)
1566 || bpt
->type
== bp_watchpoint
);
1569 /* Returns true if the current thread and its running state are safe
1570 to evaluate or update watchpoint B. Watchpoints on local
1571 expressions need to be evaluated in the context of the thread that
1572 was current when the watchpoint was created, and, that thread needs
1573 to be stopped to be able to select the correct frame context.
1574 Watchpoints on global expressions can be evaluated on any thread,
1575 and in any state. It is presently left to the target allowing
1576 memory accesses when threads are running. */
1579 watchpoint_in_thread_scope (struct watchpoint
*b
)
1581 return (b
->pspace
== current_program_space
1582 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1583 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1584 && !is_executing (inferior_ptid
))));
1587 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1588 associated bp_watchpoint_scope breakpoint. */
1591 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1593 if (w
->related_breakpoint
!= w
)
1595 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1596 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1597 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1598 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1599 w
->related_breakpoint
= w
;
1601 w
->disposition
= disp_del_at_next_stop
;
1604 /* Extract a bitfield value from value VAL using the bit parameters contained in
1607 static struct value
*
1608 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1610 struct value
*bit_val
;
1615 bit_val
= allocate_value (value_type (val
));
1617 unpack_value_bitfield (bit_val
,
1620 value_contents_for_printing (val
),
1627 /* Allocate a dummy location and add it to B, which must be a software
1628 watchpoint. This is required because even if a software watchpoint
1629 is not watching any memory, bpstat_stop_status requires a location
1630 to be able to report stops. */
1633 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1634 struct program_space
*pspace
)
1636 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1638 b
->loc
= allocate_bp_location (b
);
1639 b
->loc
->pspace
= pspace
;
1640 b
->loc
->address
= -1;
1641 b
->loc
->length
= -1;
1644 /* Returns true if B is a software watchpoint that is not watching any
1645 memory (e.g., "watch $pc"). */
1648 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1650 return (b
->type
== bp_watchpoint
1652 && b
->loc
->next
== NULL
1653 && b
->loc
->address
== -1
1654 && b
->loc
->length
== -1);
1657 /* Assuming that B is a watchpoint:
1658 - Reparse watchpoint expression, if REPARSE is non-zero
1659 - Evaluate expression and store the result in B->val
1660 - Evaluate the condition if there is one, and store the result
1662 - Update the list of values that must be watched in B->loc.
1664 If the watchpoint disposition is disp_del_at_next_stop, then do
1665 nothing. If this is local watchpoint that is out of scope, delete
1668 Even with `set breakpoint always-inserted on' the watchpoints are
1669 removed + inserted on each stop here. Normal breakpoints must
1670 never be removed because they might be missed by a running thread
1671 when debugging in non-stop mode. On the other hand, hardware
1672 watchpoints (is_hardware_watchpoint; processed here) are specific
1673 to each LWP since they are stored in each LWP's hardware debug
1674 registers. Therefore, such LWP must be stopped first in order to
1675 be able to modify its hardware watchpoints.
1677 Hardware watchpoints must be reset exactly once after being
1678 presented to the user. It cannot be done sooner, because it would
1679 reset the data used to present the watchpoint hit to the user. And
1680 it must not be done later because it could display the same single
1681 watchpoint hit during multiple GDB stops. Note that the latter is
1682 relevant only to the hardware watchpoint types bp_read_watchpoint
1683 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1684 not user-visible - its hit is suppressed if the memory content has
1687 The following constraints influence the location where we can reset
1688 hardware watchpoints:
1690 * target_stopped_by_watchpoint and target_stopped_data_address are
1691 called several times when GDB stops.
1694 * Multiple hardware watchpoints can be hit at the same time,
1695 causing GDB to stop. GDB only presents one hardware watchpoint
1696 hit at a time as the reason for stopping, and all the other hits
1697 are presented later, one after the other, each time the user
1698 requests the execution to be resumed. Execution is not resumed
1699 for the threads still having pending hit event stored in
1700 LWP_INFO->STATUS. While the watchpoint is already removed from
1701 the inferior on the first stop the thread hit event is kept being
1702 reported from its cached value by linux_nat_stopped_data_address
1703 until the real thread resume happens after the watchpoint gets
1704 presented and thus its LWP_INFO->STATUS gets reset.
1706 Therefore the hardware watchpoint hit can get safely reset on the
1707 watchpoint removal from inferior. */
1710 update_watchpoint (struct watchpoint
*b
, int reparse
)
1712 int within_current_scope
;
1713 struct frame_id saved_frame_id
;
1716 /* If this is a local watchpoint, we only want to check if the
1717 watchpoint frame is in scope if the current thread is the thread
1718 that was used to create the watchpoint. */
1719 if (!watchpoint_in_thread_scope (b
))
1722 if (b
->disposition
== disp_del_at_next_stop
)
1727 /* Determine if the watchpoint is within scope. */
1728 if (b
->exp_valid_block
== NULL
)
1729 within_current_scope
= 1;
1732 struct frame_info
*fi
= get_current_frame ();
1733 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1734 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1736 /* If we're at a point where the stack has been destroyed
1737 (e.g. in a function epilogue), unwinding may not work
1738 properly. Do not attempt to recreate locations at this
1739 point. See similar comments in watchpoint_check. */
1740 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1743 /* Save the current frame's ID so we can restore it after
1744 evaluating the watchpoint expression on its own frame. */
1745 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1746 took a frame parameter, so that we didn't have to change the
1749 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1751 fi
= frame_find_by_id (b
->watchpoint_frame
);
1752 within_current_scope
= (fi
!= NULL
);
1753 if (within_current_scope
)
1757 /* We don't free locations. They are stored in the bp_location array
1758 and update_global_location_list will eventually delete them and
1759 remove breakpoints if needed. */
1762 if (within_current_scope
&& reparse
)
1767 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1768 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1769 /* If the meaning of expression itself changed, the old value is
1770 no longer relevant. We don't want to report a watchpoint hit
1771 to the user when the old value and the new value may actually
1772 be completely different objects. */
1773 value_free (b
->val
);
1777 /* Note that unlike with breakpoints, the watchpoint's condition
1778 expression is stored in the breakpoint object, not in the
1779 locations (re)created below. */
1780 if (b
->cond_string
!= NULL
)
1782 b
->cond_exp
.reset ();
1785 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1789 /* If we failed to parse the expression, for example because
1790 it refers to a global variable in a not-yet-loaded shared library,
1791 don't try to insert watchpoint. We don't automatically delete
1792 such watchpoint, though, since failure to parse expression
1793 is different from out-of-scope watchpoint. */
1794 if (!target_has_execution
)
1796 /* Without execution, memory can't change. No use to try and
1797 set watchpoint locations. The watchpoint will be reset when
1798 the target gains execution, through breakpoint_re_set. */
1799 if (!can_use_hw_watchpoints
)
1801 if (b
->ops
->works_in_software_mode (b
))
1802 b
->type
= bp_watchpoint
;
1804 error (_("Can't set read/access watchpoint when "
1805 "hardware watchpoints are disabled."));
1808 else if (within_current_scope
&& b
->exp
)
1811 struct value
*val_chain
, *v
, *result
, *next
;
1812 struct program_space
*frame_pspace
;
1814 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1816 /* Avoid setting b->val if it's already set. The meaning of
1817 b->val is 'the last value' user saw, and we should update
1818 it only if we reported that last value to user. As it
1819 happens, the code that reports it updates b->val directly.
1820 We don't keep track of the memory value for masked
1822 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1824 if (b
->val_bitsize
!= 0)
1826 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1834 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1836 /* Look at each value on the value chain. */
1837 for (v
= val_chain
; v
; v
= value_next (v
))
1839 /* If it's a memory location, and GDB actually needed
1840 its contents to evaluate the expression, then we
1841 must watch it. If the first value returned is
1842 still lazy, that means an error occurred reading it;
1843 watch it anyway in case it becomes readable. */
1844 if (VALUE_LVAL (v
) == lval_memory
1845 && (v
== val_chain
|| ! value_lazy (v
)))
1847 struct type
*vtype
= check_typedef (value_type (v
));
1849 /* We only watch structs and arrays if user asked
1850 for it explicitly, never if they just happen to
1851 appear in the middle of some value chain. */
1853 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1854 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1857 enum target_hw_bp_type type
;
1858 struct bp_location
*loc
, **tmp
;
1859 int bitpos
= 0, bitsize
= 0;
1861 if (value_bitsize (v
) != 0)
1863 /* Extract the bit parameters out from the bitfield
1865 bitpos
= value_bitpos (v
);
1866 bitsize
= value_bitsize (v
);
1868 else if (v
== result
&& b
->val_bitsize
!= 0)
1870 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1871 lvalue whose bit parameters are saved in the fields
1872 VAL_BITPOS and VAL_BITSIZE. */
1873 bitpos
= b
->val_bitpos
;
1874 bitsize
= b
->val_bitsize
;
1877 addr
= value_address (v
);
1880 /* Skip the bytes that don't contain the bitfield. */
1885 if (b
->type
== bp_read_watchpoint
)
1887 else if (b
->type
== bp_access_watchpoint
)
1890 loc
= allocate_bp_location (b
);
1891 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1894 loc
->gdbarch
= get_type_arch (value_type (v
));
1896 loc
->pspace
= frame_pspace
;
1897 loc
->address
= addr
;
1901 /* Just cover the bytes that make up the bitfield. */
1902 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1905 loc
->length
= TYPE_LENGTH (value_type (v
));
1907 loc
->watchpoint_type
= type
;
1912 /* Change the type of breakpoint between hardware assisted or
1913 an ordinary watchpoint depending on the hardware support
1914 and free hardware slots. REPARSE is set when the inferior
1919 enum bp_loc_type loc_type
;
1920 struct bp_location
*bl
;
1922 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1926 int i
, target_resources_ok
, other_type_used
;
1929 /* Use an exact watchpoint when there's only one memory region to be
1930 watched, and only one debug register is needed to watch it. */
1931 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1933 /* We need to determine how many resources are already
1934 used for all other hardware watchpoints plus this one
1935 to see if we still have enough resources to also fit
1936 this watchpoint in as well. */
1938 /* If this is a software watchpoint, we try to turn it
1939 to a hardware one -- count resources as if B was of
1940 hardware watchpoint type. */
1942 if (type
== bp_watchpoint
)
1943 type
= bp_hardware_watchpoint
;
1945 /* This watchpoint may or may not have been placed on
1946 the list yet at this point (it won't be in the list
1947 if we're trying to create it for the first time,
1948 through watch_command), so always account for it
1951 /* Count resources used by all watchpoints except B. */
1952 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1954 /* Add in the resources needed for B. */
1955 i
+= hw_watchpoint_use_count (b
);
1958 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
1959 if (target_resources_ok
<= 0)
1961 int sw_mode
= b
->ops
->works_in_software_mode (b
);
1963 if (target_resources_ok
== 0 && !sw_mode
)
1964 error (_("Target does not support this type of "
1965 "hardware watchpoint."));
1966 else if (target_resources_ok
< 0 && !sw_mode
)
1967 error (_("There are not enough available hardware "
1968 "resources for this watchpoint."));
1970 /* Downgrade to software watchpoint. */
1971 b
->type
= bp_watchpoint
;
1975 /* If this was a software watchpoint, we've just
1976 found we have enough resources to turn it to a
1977 hardware watchpoint. Otherwise, this is a
1982 else if (!b
->ops
->works_in_software_mode (b
))
1984 if (!can_use_hw_watchpoints
)
1985 error (_("Can't set read/access watchpoint when "
1986 "hardware watchpoints are disabled."));
1988 error (_("Expression cannot be implemented with "
1989 "read/access watchpoint."));
1992 b
->type
= bp_watchpoint
;
1994 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
1995 : bp_loc_hardware_watchpoint
);
1996 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
1997 bl
->loc_type
= loc_type
;
2000 for (v
= val_chain
; v
; v
= next
)
2002 next
= value_next (v
);
2007 /* If a software watchpoint is not watching any memory, then the
2008 above left it without any location set up. But,
2009 bpstat_stop_status requires a location to be able to report
2010 stops, so make sure there's at least a dummy one. */
2011 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2012 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2014 else if (!within_current_scope
)
2016 printf_filtered (_("\
2017 Watchpoint %d deleted because the program has left the block\n\
2018 in which its expression is valid.\n"),
2020 watchpoint_del_at_next_stop (b
);
2023 /* Restore the selected frame. */
2025 select_frame (frame_find_by_id (saved_frame_id
));
2029 /* Returns 1 iff breakpoint location should be
2030 inserted in the inferior. We don't differentiate the type of BL's owner
2031 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2032 breakpoint_ops is not defined, because in insert_bp_location,
2033 tracepoint's insert_location will not be called. */
2035 should_be_inserted (struct bp_location
*bl
)
2037 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2040 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2043 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2046 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2049 /* This is set for example, when we're attached to the parent of a
2050 vfork, and have detached from the child. The child is running
2051 free, and we expect it to do an exec or exit, at which point the
2052 OS makes the parent schedulable again (and the target reports
2053 that the vfork is done). Until the child is done with the shared
2054 memory region, do not insert breakpoints in the parent, otherwise
2055 the child could still trip on the parent's breakpoints. Since
2056 the parent is blocked anyway, it won't miss any breakpoint. */
2057 if (bl
->pspace
->breakpoints_not_allowed
)
2060 /* Don't insert a breakpoint if we're trying to step past its
2061 location, except if the breakpoint is a single-step breakpoint,
2062 and the breakpoint's thread is the thread which is stepping past
2064 if ((bl
->loc_type
== bp_loc_software_breakpoint
2065 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2066 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2068 /* The single-step breakpoint may be inserted at the location
2069 we're trying to step if the instruction branches to itself.
2070 However, the instruction won't be executed at all and it may
2071 break the semantics of the instruction, for example, the
2072 instruction is a conditional branch or updates some flags.
2073 We can't fix it unless GDB is able to emulate the instruction
2074 or switch to displaced stepping. */
2075 && !(bl
->owner
->type
== bp_single_step
2076 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2080 fprintf_unfiltered (gdb_stdlog
,
2081 "infrun: skipping breakpoint: "
2082 "stepping past insn at: %s\n",
2083 paddress (bl
->gdbarch
, bl
->address
));
2088 /* Don't insert watchpoints if we're trying to step past the
2089 instruction that triggered one. */
2090 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2091 && stepping_past_nonsteppable_watchpoint ())
2095 fprintf_unfiltered (gdb_stdlog
,
2096 "infrun: stepping past non-steppable watchpoint. "
2097 "skipping watchpoint at %s:%d\n",
2098 paddress (bl
->gdbarch
, bl
->address
),
2107 /* Same as should_be_inserted but does the check assuming
2108 that the location is not duplicated. */
2111 unduplicated_should_be_inserted (struct bp_location
*bl
)
2114 const int save_duplicate
= bl
->duplicate
;
2117 result
= should_be_inserted (bl
);
2118 bl
->duplicate
= save_duplicate
;
2122 /* Parses a conditional described by an expression COND into an
2123 agent expression bytecode suitable for evaluation
2124 by the bytecode interpreter. Return NULL if there was
2125 any error during parsing. */
2127 static agent_expr_up
2128 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2133 agent_expr_up aexpr
;
2135 /* We don't want to stop processing, so catch any errors
2136 that may show up. */
2139 aexpr
= gen_eval_for_expr (scope
, cond
);
2142 CATCH (ex
, RETURN_MASK_ERROR
)
2144 /* If we got here, it means the condition could not be parsed to a valid
2145 bytecode expression and thus can't be evaluated on the target's side.
2146 It's no use iterating through the conditions. */
2150 /* We have a valid agent expression. */
2154 /* Based on location BL, create a list of breakpoint conditions to be
2155 passed on to the target. If we have duplicated locations with different
2156 conditions, we will add such conditions to the list. The idea is that the
2157 target will evaluate the list of conditions and will only notify GDB when
2158 one of them is true. */
2161 build_target_condition_list (struct bp_location
*bl
)
2163 struct bp_location
**locp
= NULL
, **loc2p
;
2164 int null_condition_or_parse_error
= 0;
2165 int modified
= bl
->needs_update
;
2166 struct bp_location
*loc
;
2168 /* Release conditions left over from a previous insert. */
2169 bl
->target_info
.conditions
.clear ();
2171 /* This is only meaningful if the target is
2172 evaluating conditions and if the user has
2173 opted for condition evaluation on the target's
2175 if (gdb_evaluates_breakpoint_condition_p ()
2176 || !target_supports_evaluation_of_breakpoint_conditions ())
2179 /* Do a first pass to check for locations with no assigned
2180 conditions or conditions that fail to parse to a valid agent expression
2181 bytecode. If any of these happen, then it's no use to send conditions
2182 to the target since this location will always trigger and generate a
2183 response back to GDB. */
2184 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2187 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2191 /* Re-parse the conditions since something changed. In that
2192 case we already freed the condition bytecodes (see
2193 force_breakpoint_reinsertion). We just
2194 need to parse the condition to bytecodes again. */
2195 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2199 /* If we have a NULL bytecode expression, it means something
2200 went wrong or we have a null condition expression. */
2201 if (!loc
->cond_bytecode
)
2203 null_condition_or_parse_error
= 1;
2209 /* If any of these happened, it means we will have to evaluate the conditions
2210 for the location's address on gdb's side. It is no use keeping bytecodes
2211 for all the other duplicate locations, thus we free all of them here.
2213 This is so we have a finer control over which locations' conditions are
2214 being evaluated by GDB or the remote stub. */
2215 if (null_condition_or_parse_error
)
2217 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2220 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2222 /* Only go as far as the first NULL bytecode is
2224 if (!loc
->cond_bytecode
)
2227 loc
->cond_bytecode
.reset ();
2232 /* No NULL conditions or failed bytecode generation. Build a condition list
2233 for this location's address. */
2234 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2238 && is_breakpoint (loc
->owner
)
2239 && loc
->pspace
->num
== bl
->pspace
->num
2240 && loc
->owner
->enable_state
== bp_enabled
2243 /* Add the condition to the vector. This will be used later
2244 to send the conditions to the target. */
2245 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2252 /* Parses a command described by string CMD into an agent expression
2253 bytecode suitable for evaluation by the bytecode interpreter.
2254 Return NULL if there was any error during parsing. */
2256 static agent_expr_up
2257 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2259 struct cleanup
*old_cleanups
= 0;
2260 struct expression
**argvec
;
2261 const char *cmdrest
;
2262 const char *format_start
, *format_end
;
2263 struct format_piece
*fpieces
;
2265 struct gdbarch
*gdbarch
= get_current_arch ();
2272 if (*cmdrest
== ',')
2274 cmdrest
= skip_spaces (cmdrest
);
2276 if (*cmdrest
++ != '"')
2277 error (_("No format string following the location"));
2279 format_start
= cmdrest
;
2281 fpieces
= parse_format_string (&cmdrest
);
2283 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2285 format_end
= cmdrest
;
2287 if (*cmdrest
++ != '"')
2288 error (_("Bad format string, non-terminated '\"'."));
2290 cmdrest
= skip_spaces (cmdrest
);
2292 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2293 error (_("Invalid argument syntax"));
2295 if (*cmdrest
== ',')
2297 cmdrest
= skip_spaces (cmdrest
);
2299 /* For each argument, make an expression. */
2301 argvec
= (struct expression
**) alloca (strlen (cmd
)
2302 * sizeof (struct expression
*));
2305 while (*cmdrest
!= '\0')
2310 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2311 argvec
[nargs
++] = expr
.release ();
2313 if (*cmdrest
== ',')
2317 agent_expr_up aexpr
;
2319 /* We don't want to stop processing, so catch any errors
2320 that may show up. */
2323 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2324 format_start
, format_end
- format_start
,
2325 fpieces
, nargs
, argvec
);
2327 CATCH (ex
, RETURN_MASK_ERROR
)
2329 /* If we got here, it means the command could not be parsed to a valid
2330 bytecode expression and thus can't be evaluated on the target's side.
2331 It's no use iterating through the other commands. */
2335 do_cleanups (old_cleanups
);
2337 /* We have a valid agent expression, return it. */
2341 /* Based on location BL, create a list of breakpoint commands to be
2342 passed on to the target. If we have duplicated locations with
2343 different commands, we will add any such to the list. */
2346 build_target_command_list (struct bp_location
*bl
)
2348 struct bp_location
**locp
= NULL
, **loc2p
;
2349 int null_command_or_parse_error
= 0;
2350 int modified
= bl
->needs_update
;
2351 struct bp_location
*loc
;
2353 /* Clear commands left over from a previous insert. */
2354 bl
->target_info
.tcommands
.clear ();
2356 if (!target_can_run_breakpoint_commands ())
2359 /* For now, limit to agent-style dprintf breakpoints. */
2360 if (dprintf_style
!= dprintf_style_agent
)
2363 /* For now, if we have any duplicate location that isn't a dprintf,
2364 don't install the target-side commands, as that would make the
2365 breakpoint not be reported to the core, and we'd lose
2367 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2370 if (is_breakpoint (loc
->owner
)
2371 && loc
->pspace
->num
== bl
->pspace
->num
2372 && loc
->owner
->type
!= bp_dprintf
)
2376 /* Do a first pass to check for locations with no assigned
2377 conditions or conditions that fail to parse to a valid agent expression
2378 bytecode. If any of these happen, then it's no use to send conditions
2379 to the target since this location will always trigger and generate a
2380 response back to GDB. */
2381 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2384 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2388 /* Re-parse the commands since something changed. In that
2389 case we already freed the command bytecodes (see
2390 force_breakpoint_reinsertion). We just
2391 need to parse the command to bytecodes again. */
2393 = parse_cmd_to_aexpr (bl
->address
,
2394 loc
->owner
->extra_string
);
2397 /* If we have a NULL bytecode expression, it means something
2398 went wrong or we have a null command expression. */
2399 if (!loc
->cmd_bytecode
)
2401 null_command_or_parse_error
= 1;
2407 /* If anything failed, then we're not doing target-side commands,
2409 if (null_command_or_parse_error
)
2411 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2414 if (is_breakpoint (loc
->owner
)
2415 && loc
->pspace
->num
== bl
->pspace
->num
)
2417 /* Only go as far as the first NULL bytecode is
2419 if (loc
->cmd_bytecode
== NULL
)
2422 loc
->cmd_bytecode
.reset ();
2427 /* No NULL commands or failed bytecode generation. Build a command list
2428 for this location's address. */
2429 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2432 if (loc
->owner
->extra_string
2433 && is_breakpoint (loc
->owner
)
2434 && loc
->pspace
->num
== bl
->pspace
->num
2435 && loc
->owner
->enable_state
== bp_enabled
2438 /* Add the command to the vector. This will be used later
2439 to send the commands to the target. */
2440 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2444 bl
->target_info
.persist
= 0;
2445 /* Maybe flag this location as persistent. */
2446 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2447 bl
->target_info
.persist
= 1;
2450 /* Return the kind of breakpoint on address *ADDR. Get the kind
2451 of breakpoint according to ADDR except single-step breakpoint.
2452 Get the kind of single-step breakpoint according to the current
2456 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2458 if (bl
->owner
->type
== bp_single_step
)
2460 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2461 struct regcache
*regcache
;
2463 regcache
= get_thread_regcache (thr
->ptid
);
2465 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2469 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2472 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2473 location. Any error messages are printed to TMP_ERROR_STREAM; and
2474 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2475 Returns 0 for success, 1 if the bp_location type is not supported or
2478 NOTE drow/2003-09-09: This routine could be broken down to an
2479 object-style method for each breakpoint or catchpoint type. */
2481 insert_bp_location (struct bp_location
*bl
,
2482 struct ui_file
*tmp_error_stream
,
2483 int *disabled_breaks
,
2484 int *hw_breakpoint_error
,
2485 int *hw_bp_error_explained_already
)
2487 enum errors bp_err
= GDB_NO_ERROR
;
2488 const char *bp_err_message
= NULL
;
2490 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2493 /* Note we don't initialize bl->target_info, as that wipes out
2494 the breakpoint location's shadow_contents if the breakpoint
2495 is still inserted at that location. This in turn breaks
2496 target_read_memory which depends on these buffers when
2497 a memory read is requested at the breakpoint location:
2498 Once the target_info has been wiped, we fail to see that
2499 we have a breakpoint inserted at that address and thus
2500 read the breakpoint instead of returning the data saved in
2501 the breakpoint location's shadow contents. */
2502 bl
->target_info
.reqstd_address
= bl
->address
;
2503 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2504 bl
->target_info
.length
= bl
->length
;
2506 /* When working with target-side conditions, we must pass all the conditions
2507 for the same breakpoint address down to the target since GDB will not
2508 insert those locations. With a list of breakpoint conditions, the target
2509 can decide when to stop and notify GDB. */
2511 if (is_breakpoint (bl
->owner
))
2513 build_target_condition_list (bl
);
2514 build_target_command_list (bl
);
2515 /* Reset the modification marker. */
2516 bl
->needs_update
= 0;
2519 if (bl
->loc_type
== bp_loc_software_breakpoint
2520 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2522 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2524 /* If the explicitly specified breakpoint type
2525 is not hardware breakpoint, check the memory map to see
2526 if the breakpoint address is in read only memory or not.
2528 Two important cases are:
2529 - location type is not hardware breakpoint, memory
2530 is readonly. We change the type of the location to
2531 hardware breakpoint.
2532 - location type is hardware breakpoint, memory is
2533 read-write. This means we've previously made the
2534 location hardware one, but then the memory map changed,
2537 When breakpoints are removed, remove_breakpoints will use
2538 location types we've just set here, the only possible
2539 problem is that memory map has changed during running
2540 program, but it's not going to work anyway with current
2542 struct mem_region
*mr
2543 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2547 if (automatic_hardware_breakpoints
)
2549 enum bp_loc_type new_type
;
2551 if (mr
->attrib
.mode
!= MEM_RW
)
2552 new_type
= bp_loc_hardware_breakpoint
;
2554 new_type
= bp_loc_software_breakpoint
;
2556 if (new_type
!= bl
->loc_type
)
2558 static int said
= 0;
2560 bl
->loc_type
= new_type
;
2563 fprintf_filtered (gdb_stdout
,
2564 _("Note: automatically using "
2565 "hardware breakpoints for "
2566 "read-only addresses.\n"));
2571 else if (bl
->loc_type
== bp_loc_software_breakpoint
2572 && mr
->attrib
.mode
!= MEM_RW
)
2574 fprintf_unfiltered (tmp_error_stream
,
2575 _("Cannot insert breakpoint %d.\n"
2576 "Cannot set software breakpoint "
2577 "at read-only address %s\n"),
2579 paddress (bl
->gdbarch
, bl
->address
));
2585 /* First check to see if we have to handle an overlay. */
2586 if (overlay_debugging
== ovly_off
2587 || bl
->section
== NULL
2588 || !(section_is_overlay (bl
->section
)))
2590 /* No overlay handling: just set the breakpoint. */
2595 val
= bl
->owner
->ops
->insert_location (bl
);
2597 bp_err
= GENERIC_ERROR
;
2599 CATCH (e
, RETURN_MASK_ALL
)
2602 bp_err_message
= e
.message
;
2608 /* This breakpoint is in an overlay section.
2609 Shall we set a breakpoint at the LMA? */
2610 if (!overlay_events_enabled
)
2612 /* Yes -- overlay event support is not active,
2613 so we must try to set a breakpoint at the LMA.
2614 This will not work for a hardware breakpoint. */
2615 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2616 warning (_("hardware breakpoint %d not supported in overlay!"),
2620 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2622 /* Set a software (trap) breakpoint at the LMA. */
2623 bl
->overlay_target_info
= bl
->target_info
;
2624 bl
->overlay_target_info
.reqstd_address
= addr
;
2626 /* No overlay handling: just set the breakpoint. */
2631 bl
->overlay_target_info
.kind
2632 = breakpoint_kind (bl
, &addr
);
2633 bl
->overlay_target_info
.placed_address
= addr
;
2634 val
= target_insert_breakpoint (bl
->gdbarch
,
2635 &bl
->overlay_target_info
);
2637 bp_err
= GENERIC_ERROR
;
2639 CATCH (e
, RETURN_MASK_ALL
)
2642 bp_err_message
= e
.message
;
2646 if (bp_err
!= GDB_NO_ERROR
)
2647 fprintf_unfiltered (tmp_error_stream
,
2648 "Overlay breakpoint %d "
2649 "failed: in ROM?\n",
2653 /* Shall we set a breakpoint at the VMA? */
2654 if (section_is_mapped (bl
->section
))
2656 /* Yes. This overlay section is mapped into memory. */
2661 val
= bl
->owner
->ops
->insert_location (bl
);
2663 bp_err
= GENERIC_ERROR
;
2665 CATCH (e
, RETURN_MASK_ALL
)
2668 bp_err_message
= e
.message
;
2674 /* No. This breakpoint will not be inserted.
2675 No error, but do not mark the bp as 'inserted'. */
2680 if (bp_err
!= GDB_NO_ERROR
)
2682 /* Can't set the breakpoint. */
2684 /* In some cases, we might not be able to insert a
2685 breakpoint in a shared library that has already been
2686 removed, but we have not yet processed the shlib unload
2687 event. Unfortunately, some targets that implement
2688 breakpoint insertion themselves can't tell why the
2689 breakpoint insertion failed (e.g., the remote target
2690 doesn't define error codes), so we must treat generic
2691 errors as memory errors. */
2692 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2693 && bl
->loc_type
== bp_loc_software_breakpoint
2694 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2695 || shared_objfile_contains_address_p (bl
->pspace
,
2698 /* See also: disable_breakpoints_in_shlibs. */
2699 bl
->shlib_disabled
= 1;
2700 observer_notify_breakpoint_modified (bl
->owner
);
2701 if (!*disabled_breaks
)
2703 fprintf_unfiltered (tmp_error_stream
,
2704 "Cannot insert breakpoint %d.\n",
2706 fprintf_unfiltered (tmp_error_stream
,
2707 "Temporarily disabling shared "
2708 "library breakpoints:\n");
2710 *disabled_breaks
= 1;
2711 fprintf_unfiltered (tmp_error_stream
,
2712 "breakpoint #%d\n", bl
->owner
->number
);
2717 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2719 *hw_breakpoint_error
= 1;
2720 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2721 fprintf_unfiltered (tmp_error_stream
,
2722 "Cannot insert hardware breakpoint %d%s",
2723 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2724 if (bp_err_message
!= NULL
)
2725 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2729 if (bp_err_message
== NULL
)
2732 = memory_error_message (TARGET_XFER_E_IO
,
2733 bl
->gdbarch
, bl
->address
);
2735 fprintf_unfiltered (tmp_error_stream
,
2736 "Cannot insert breakpoint %d.\n"
2738 bl
->owner
->number
, message
.c_str ());
2742 fprintf_unfiltered (tmp_error_stream
,
2743 "Cannot insert breakpoint %d: %s\n",
2758 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2759 /* NOTE drow/2003-09-08: This state only exists for removing
2760 watchpoints. It's not clear that it's necessary... */
2761 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2765 gdb_assert (bl
->owner
->ops
!= NULL
2766 && bl
->owner
->ops
->insert_location
!= NULL
);
2768 val
= bl
->owner
->ops
->insert_location (bl
);
2770 /* If trying to set a read-watchpoint, and it turns out it's not
2771 supported, try emulating one with an access watchpoint. */
2772 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2774 struct bp_location
*loc
, **loc_temp
;
2776 /* But don't try to insert it, if there's already another
2777 hw_access location that would be considered a duplicate
2779 ALL_BP_LOCATIONS (loc
, loc_temp
)
2781 && loc
->watchpoint_type
== hw_access
2782 && watchpoint_locations_match (bl
, loc
))
2786 bl
->target_info
= loc
->target_info
;
2787 bl
->watchpoint_type
= hw_access
;
2794 bl
->watchpoint_type
= hw_access
;
2795 val
= bl
->owner
->ops
->insert_location (bl
);
2798 /* Back to the original value. */
2799 bl
->watchpoint_type
= hw_read
;
2803 bl
->inserted
= (val
== 0);
2806 else if (bl
->owner
->type
== bp_catchpoint
)
2810 gdb_assert (bl
->owner
->ops
!= NULL
2811 && bl
->owner
->ops
->insert_location
!= NULL
);
2813 val
= bl
->owner
->ops
->insert_location (bl
);
2816 bl
->owner
->enable_state
= bp_disabled
;
2820 Error inserting catchpoint %d: Your system does not support this type\n\
2821 of catchpoint."), bl
->owner
->number
);
2823 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2826 bl
->inserted
= (val
== 0);
2828 /* We've already printed an error message if there was a problem
2829 inserting this catchpoint, and we've disabled the catchpoint,
2830 so just return success. */
2837 /* This function is called when program space PSPACE is about to be
2838 deleted. It takes care of updating breakpoints to not reference
2842 breakpoint_program_space_exit (struct program_space
*pspace
)
2844 struct breakpoint
*b
, *b_temp
;
2845 struct bp_location
*loc
, **loc_temp
;
2847 /* Remove any breakpoint that was set through this program space. */
2848 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2850 if (b
->pspace
== pspace
)
2851 delete_breakpoint (b
);
2854 /* Breakpoints set through other program spaces could have locations
2855 bound to PSPACE as well. Remove those. */
2856 ALL_BP_LOCATIONS (loc
, loc_temp
)
2858 struct bp_location
*tmp
;
2860 if (loc
->pspace
== pspace
)
2862 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2863 if (loc
->owner
->loc
== loc
)
2864 loc
->owner
->loc
= loc
->next
;
2866 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2867 if (tmp
->next
== loc
)
2869 tmp
->next
= loc
->next
;
2875 /* Now update the global location list to permanently delete the
2876 removed locations above. */
2877 update_global_location_list (UGLL_DONT_INSERT
);
2880 /* Make sure all breakpoints are inserted in inferior.
2881 Throws exception on any error.
2882 A breakpoint that is already inserted won't be inserted
2883 again, so calling this function twice is safe. */
2885 insert_breakpoints (void)
2887 struct breakpoint
*bpt
;
2889 ALL_BREAKPOINTS (bpt
)
2890 if (is_hardware_watchpoint (bpt
))
2892 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2894 update_watchpoint (w
, 0 /* don't reparse. */);
2897 /* Updating watchpoints creates new locations, so update the global
2898 location list. Explicitly tell ugll to insert locations and
2899 ignore breakpoints_always_inserted_mode. */
2900 update_global_location_list (UGLL_INSERT
);
2903 /* Invoke CALLBACK for each of bp_location. */
2906 iterate_over_bp_locations (walk_bp_location_callback callback
)
2908 struct bp_location
*loc
, **loc_tmp
;
2910 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2912 callback (loc
, NULL
);
2916 /* This is used when we need to synch breakpoint conditions between GDB and the
2917 target. It is the case with deleting and disabling of breakpoints when using
2918 always-inserted mode. */
2921 update_inserted_breakpoint_locations (void)
2923 struct bp_location
*bl
, **blp_tmp
;
2926 int disabled_breaks
= 0;
2927 int hw_breakpoint_error
= 0;
2928 int hw_bp_details_reported
= 0;
2930 string_file tmp_error_stream
;
2932 /* Explicitly mark the warning -- this will only be printed if
2933 there was an error. */
2934 tmp_error_stream
.puts ("Warning:\n");
2936 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2938 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2940 /* We only want to update software breakpoints and hardware
2942 if (!is_breakpoint (bl
->owner
))
2945 /* We only want to update locations that are already inserted
2946 and need updating. This is to avoid unwanted insertion during
2947 deletion of breakpoints. */
2948 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2951 switch_to_program_space_and_thread (bl
->pspace
);
2953 /* For targets that support global breakpoints, there's no need
2954 to select an inferior to insert breakpoint to. In fact, even
2955 if we aren't attached to any process yet, we should still
2956 insert breakpoints. */
2957 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
2958 && ptid_equal (inferior_ptid
, null_ptid
))
2961 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
2962 &hw_breakpoint_error
, &hw_bp_details_reported
);
2969 target_terminal::ours_for_output ();
2970 error_stream (tmp_error_stream
);
2974 /* Used when starting or continuing the program. */
2977 insert_breakpoint_locations (void)
2979 struct breakpoint
*bpt
;
2980 struct bp_location
*bl
, **blp_tmp
;
2983 int disabled_breaks
= 0;
2984 int hw_breakpoint_error
= 0;
2985 int hw_bp_error_explained_already
= 0;
2987 string_file tmp_error_stream
;
2989 /* Explicitly mark the warning -- this will only be printed if
2990 there was an error. */
2991 tmp_error_stream
.puts ("Warning:\n");
2993 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2995 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2997 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3000 /* There is no point inserting thread-specific breakpoints if
3001 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3002 has BL->OWNER always non-NULL. */
3003 if (bl
->owner
->thread
!= -1
3004 && !valid_global_thread_id (bl
->owner
->thread
))
3007 switch_to_program_space_and_thread (bl
->pspace
);
3009 /* For targets that support global breakpoints, there's no need
3010 to select an inferior to insert breakpoint to. In fact, even
3011 if we aren't attached to any process yet, we should still
3012 insert breakpoints. */
3013 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3014 && ptid_equal (inferior_ptid
, null_ptid
))
3017 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3018 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3023 /* If we failed to insert all locations of a watchpoint, remove
3024 them, as half-inserted watchpoint is of limited use. */
3025 ALL_BREAKPOINTS (bpt
)
3027 int some_failed
= 0;
3028 struct bp_location
*loc
;
3030 if (!is_hardware_watchpoint (bpt
))
3033 if (!breakpoint_enabled (bpt
))
3036 if (bpt
->disposition
== disp_del_at_next_stop
)
3039 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3040 if (!loc
->inserted
&& should_be_inserted (loc
))
3047 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3049 remove_breakpoint (loc
);
3051 hw_breakpoint_error
= 1;
3052 tmp_error_stream
.printf ("Could not insert "
3053 "hardware watchpoint %d.\n",
3061 /* If a hardware breakpoint or watchpoint was inserted, add a
3062 message about possibly exhausted resources. */
3063 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3065 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3066 You may have requested too many hardware breakpoints/watchpoints.\n");
3068 target_terminal::ours_for_output ();
3069 error_stream (tmp_error_stream
);
3073 /* Used when the program stops.
3074 Returns zero if successful, or non-zero if there was a problem
3075 removing a breakpoint location. */
3078 remove_breakpoints (void)
3080 struct bp_location
*bl
, **blp_tmp
;
3083 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3085 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3086 val
|= remove_breakpoint (bl
);
3091 /* When a thread exits, remove breakpoints that are related to
3095 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3097 struct breakpoint
*b
, *b_tmp
;
3099 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3101 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3103 b
->disposition
= disp_del_at_next_stop
;
3105 printf_filtered (_("\
3106 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3107 b
->number
, print_thread_id (tp
));
3109 /* Hide it from the user. */
3115 /* Remove breakpoints of process PID. */
3118 remove_breakpoints_pid (int pid
)
3120 struct bp_location
*bl
, **blp_tmp
;
3122 struct inferior
*inf
= find_inferior_pid (pid
);
3124 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3126 if (bl
->pspace
!= inf
->pspace
)
3129 if (bl
->inserted
&& !bl
->target_info
.persist
)
3131 val
= remove_breakpoint (bl
);
3139 static int internal_breakpoint_number
= -1;
3141 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3142 If INTERNAL is non-zero, the breakpoint number will be populated
3143 from internal_breakpoint_number and that variable decremented.
3144 Otherwise the breakpoint number will be populated from
3145 breakpoint_count and that value incremented. Internal breakpoints
3146 do not set the internal var bpnum. */
3148 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3151 b
->number
= internal_breakpoint_number
--;
3154 set_breakpoint_count (breakpoint_count
+ 1);
3155 b
->number
= breakpoint_count
;
3159 static struct breakpoint
*
3160 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3161 CORE_ADDR address
, enum bptype type
,
3162 const struct breakpoint_ops
*ops
)
3164 symtab_and_line sal
;
3166 sal
.section
= find_pc_overlay (sal
.pc
);
3167 sal
.pspace
= current_program_space
;
3169 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3170 b
->number
= internal_breakpoint_number
--;
3171 b
->disposition
= disp_donttouch
;
3176 static const char *const longjmp_names
[] =
3178 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3180 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3182 /* Per-objfile data private to breakpoint.c. */
3183 struct breakpoint_objfile_data
3185 /* Minimal symbol for "_ovly_debug_event" (if any). */
3186 struct bound_minimal_symbol overlay_msym
{};
3188 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3189 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
] {};
3191 /* True if we have looked for longjmp probes. */
3192 int longjmp_searched
= 0;
3194 /* SystemTap probe points for longjmp (if any). */
3195 VEC (probe_p
) *longjmp_probes
= NULL
;
3197 /* Minimal symbol for "std::terminate()" (if any). */
3198 struct bound_minimal_symbol terminate_msym
{};
3200 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3201 struct bound_minimal_symbol exception_msym
{};
3203 /* True if we have looked for exception probes. */
3204 int exception_searched
= 0;
3206 /* SystemTap probe points for unwinding (if any). */
3207 VEC (probe_p
) *exception_probes
= NULL
;
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 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3248 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3250 delete bp_objfile_data
;
3254 create_overlay_event_breakpoint (void)
3256 struct objfile
*objfile
;
3257 const char *const func_name
= "_ovly_debug_event";
3259 ALL_OBJFILES (objfile
)
3261 struct breakpoint
*b
;
3262 struct breakpoint_objfile_data
*bp_objfile_data
;
3264 struct explicit_location explicit_loc
;
3266 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3268 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3271 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3273 struct bound_minimal_symbol m
;
3275 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3276 if (m
.minsym
== NULL
)
3278 /* Avoid future lookups in this objfile. */
3279 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3282 bp_objfile_data
->overlay_msym
= m
;
3285 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3286 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3288 &internal_breakpoint_ops
);
3289 initialize_explicit_location (&explicit_loc
);
3290 explicit_loc
.function_name
= ASTRDUP (func_name
);
3291 b
->location
= new_explicit_location (&explicit_loc
);
3293 if (overlay_debugging
== ovly_auto
)
3295 b
->enable_state
= bp_enabled
;
3296 overlay_events_enabled
= 1;
3300 b
->enable_state
= bp_disabled
;
3301 overlay_events_enabled
= 0;
3307 create_longjmp_master_breakpoint (void)
3309 struct program_space
*pspace
;
3311 scoped_restore_current_program_space restore_pspace
;
3313 ALL_PSPACES (pspace
)
3315 struct objfile
*objfile
;
3317 set_current_program_space (pspace
);
3319 ALL_OBJFILES (objfile
)
3322 struct gdbarch
*gdbarch
;
3323 struct breakpoint_objfile_data
*bp_objfile_data
;
3325 gdbarch
= get_objfile_arch (objfile
);
3327 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3329 if (!bp_objfile_data
->longjmp_searched
)
3333 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3336 /* We are only interested in checking one element. */
3337 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3339 if (!can_evaluate_probe_arguments (p
))
3341 /* We cannot use the probe interface here, because it does
3342 not know how to evaluate arguments. */
3343 VEC_free (probe_p
, ret
);
3347 bp_objfile_data
->longjmp_probes
= ret
;
3348 bp_objfile_data
->longjmp_searched
= 1;
3351 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3354 struct probe
*probe
;
3355 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3358 VEC_iterate (probe_p
,
3359 bp_objfile_data
->longjmp_probes
,
3363 struct breakpoint
*b
;
3365 b
= create_internal_breakpoint (gdbarch
,
3366 get_probe_address (probe
,
3369 &internal_breakpoint_ops
);
3370 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3371 b
->enable_state
= bp_disabled
;
3377 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3380 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3382 struct breakpoint
*b
;
3383 const char *func_name
;
3385 struct explicit_location explicit_loc
;
3387 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3390 func_name
= longjmp_names
[i
];
3391 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3393 struct bound_minimal_symbol m
;
3395 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3396 if (m
.minsym
== NULL
)
3398 /* Prevent future lookups in this objfile. */
3399 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3402 bp_objfile_data
->longjmp_msym
[i
] = m
;
3405 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3406 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3407 &internal_breakpoint_ops
);
3408 initialize_explicit_location (&explicit_loc
);
3409 explicit_loc
.function_name
= ASTRDUP (func_name
);
3410 b
->location
= new_explicit_location (&explicit_loc
);
3411 b
->enable_state
= bp_disabled
;
3417 /* Create a master std::terminate breakpoint. */
3419 create_std_terminate_master_breakpoint (void)
3421 struct program_space
*pspace
;
3422 const char *const func_name
= "std::terminate()";
3424 scoped_restore_current_program_space restore_pspace
;
3426 ALL_PSPACES (pspace
)
3428 struct objfile
*objfile
;
3431 set_current_program_space (pspace
);
3433 ALL_OBJFILES (objfile
)
3435 struct breakpoint
*b
;
3436 struct breakpoint_objfile_data
*bp_objfile_data
;
3437 struct explicit_location explicit_loc
;
3439 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3441 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3444 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3446 struct bound_minimal_symbol m
;
3448 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3449 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3450 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3452 /* Prevent future lookups in this objfile. */
3453 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3456 bp_objfile_data
->terminate_msym
= m
;
3459 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3460 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3461 bp_std_terminate_master
,
3462 &internal_breakpoint_ops
);
3463 initialize_explicit_location (&explicit_loc
);
3464 explicit_loc
.function_name
= ASTRDUP (func_name
);
3465 b
->location
= new_explicit_location (&explicit_loc
);
3466 b
->enable_state
= bp_disabled
;
3471 /* Install a master breakpoint on the unwinder's debug hook. */
3474 create_exception_master_breakpoint (void)
3476 struct objfile
*objfile
;
3477 const char *const func_name
= "_Unwind_DebugHook";
3479 ALL_OBJFILES (objfile
)
3481 struct breakpoint
*b
;
3482 struct gdbarch
*gdbarch
;
3483 struct breakpoint_objfile_data
*bp_objfile_data
;
3485 struct explicit_location explicit_loc
;
3487 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3489 /* We prefer the SystemTap probe point if it exists. */
3490 if (!bp_objfile_data
->exception_searched
)
3494 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3498 /* We are only interested in checking one element. */
3499 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3501 if (!can_evaluate_probe_arguments (p
))
3503 /* We cannot use the probe interface here, because it does
3504 not know how to evaluate arguments. */
3505 VEC_free (probe_p
, ret
);
3509 bp_objfile_data
->exception_probes
= ret
;
3510 bp_objfile_data
->exception_searched
= 1;
3513 if (bp_objfile_data
->exception_probes
!= NULL
)
3515 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3517 struct probe
*probe
;
3520 VEC_iterate (probe_p
,
3521 bp_objfile_data
->exception_probes
,
3525 struct breakpoint
*b
;
3527 b
= create_internal_breakpoint (gdbarch
,
3528 get_probe_address (probe
,
3530 bp_exception_master
,
3531 &internal_breakpoint_ops
);
3532 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3533 b
->enable_state
= bp_disabled
;
3539 /* Otherwise, try the hook function. */
3541 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3544 gdbarch
= get_objfile_arch (objfile
);
3546 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3548 struct bound_minimal_symbol debug_hook
;
3550 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3551 if (debug_hook
.minsym
== NULL
)
3553 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3557 bp_objfile_data
->exception_msym
= debug_hook
;
3560 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3561 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3563 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3564 &internal_breakpoint_ops
);
3565 initialize_explicit_location (&explicit_loc
);
3566 explicit_loc
.function_name
= ASTRDUP (func_name
);
3567 b
->location
= new_explicit_location (&explicit_loc
);
3568 b
->enable_state
= bp_disabled
;
3572 /* Does B have a location spec? */
3575 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3577 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3581 update_breakpoints_after_exec (void)
3583 struct breakpoint
*b
, *b_tmp
;
3584 struct bp_location
*bploc
, **bplocp_tmp
;
3586 /* We're about to delete breakpoints from GDB's lists. If the
3587 INSERTED flag is true, GDB will try to lift the breakpoints by
3588 writing the breakpoints' "shadow contents" back into memory. The
3589 "shadow contents" are NOT valid after an exec, so GDB should not
3590 do that. Instead, the target is responsible from marking
3591 breakpoints out as soon as it detects an exec. We don't do that
3592 here instead, because there may be other attempts to delete
3593 breakpoints after detecting an exec and before reaching here. */
3594 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3595 if (bploc
->pspace
== current_program_space
)
3596 gdb_assert (!bploc
->inserted
);
3598 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3600 if (b
->pspace
!= current_program_space
)
3603 /* Solib breakpoints must be explicitly reset after an exec(). */
3604 if (b
->type
== bp_shlib_event
)
3606 delete_breakpoint (b
);
3610 /* JIT breakpoints must be explicitly reset after an exec(). */
3611 if (b
->type
== bp_jit_event
)
3613 delete_breakpoint (b
);
3617 /* Thread event breakpoints must be set anew after an exec(),
3618 as must overlay event and longjmp master breakpoints. */
3619 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3620 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3621 || b
->type
== bp_exception_master
)
3623 delete_breakpoint (b
);
3627 /* Step-resume breakpoints are meaningless after an exec(). */
3628 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3630 delete_breakpoint (b
);
3634 /* Just like single-step breakpoints. */
3635 if (b
->type
== bp_single_step
)
3637 delete_breakpoint (b
);
3641 /* Longjmp and longjmp-resume breakpoints are also meaningless
3643 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3644 || b
->type
== bp_longjmp_call_dummy
3645 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3647 delete_breakpoint (b
);
3651 if (b
->type
== bp_catchpoint
)
3653 /* For now, none of the bp_catchpoint breakpoints need to
3654 do anything at this point. In the future, if some of
3655 the catchpoints need to something, we will need to add
3656 a new method, and call this method from here. */
3660 /* bp_finish is a special case. The only way we ought to be able
3661 to see one of these when an exec() has happened, is if the user
3662 caught a vfork, and then said "finish". Ordinarily a finish just
3663 carries them to the call-site of the current callee, by setting
3664 a temporary bp there and resuming. But in this case, the finish
3665 will carry them entirely through the vfork & exec.
3667 We don't want to allow a bp_finish to remain inserted now. But
3668 we can't safely delete it, 'cause finish_command has a handle to
3669 the bp on a bpstat, and will later want to delete it. There's a
3670 chance (and I've seen it happen) that if we delete the bp_finish
3671 here, that its storage will get reused by the time finish_command
3672 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3673 We really must allow finish_command to delete a bp_finish.
3675 In the absence of a general solution for the "how do we know
3676 it's safe to delete something others may have handles to?"
3677 problem, what we'll do here is just uninsert the bp_finish, and
3678 let finish_command delete it.
3680 (We know the bp_finish is "doomed" in the sense that it's
3681 momentary, and will be deleted as soon as finish_command sees
3682 the inferior stopped. So it doesn't matter that the bp's
3683 address is probably bogus in the new a.out, unlike e.g., the
3684 solib breakpoints.) */
3686 if (b
->type
== bp_finish
)
3691 /* Without a symbolic address, we have little hope of the
3692 pre-exec() address meaning the same thing in the post-exec()
3694 if (breakpoint_event_location_empty_p (b
))
3696 delete_breakpoint (b
);
3703 detach_breakpoints (ptid_t ptid
)
3705 struct bp_location
*bl
, **blp_tmp
;
3707 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3708 struct inferior
*inf
= current_inferior ();
3710 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3711 error (_("Cannot detach breakpoints of inferior_ptid"));
3713 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3714 inferior_ptid
= ptid
;
3715 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3717 if (bl
->pspace
!= inf
->pspace
)
3720 /* This function must physically remove breakpoints locations
3721 from the specified ptid, without modifying the breakpoint
3722 package's state. Locations of type bp_loc_other are only
3723 maintained at GDB side. So, there is no need to remove
3724 these bp_loc_other locations. Moreover, removing these
3725 would modify the breakpoint package's state. */
3726 if (bl
->loc_type
== bp_loc_other
)
3730 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3736 /* Remove the breakpoint location BL from the current address space.
3737 Note that this is used to detach breakpoints from a child fork.
3738 When we get here, the child isn't in the inferior list, and neither
3739 do we have objects to represent its address space --- we should
3740 *not* look at bl->pspace->aspace here. */
3743 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3747 /* BL is never in moribund_locations by our callers. */
3748 gdb_assert (bl
->owner
!= NULL
);
3750 /* The type of none suggests that owner is actually deleted.
3751 This should not ever happen. */
3752 gdb_assert (bl
->owner
->type
!= bp_none
);
3754 if (bl
->loc_type
== bp_loc_software_breakpoint
3755 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3757 /* "Normal" instruction breakpoint: either the standard
3758 trap-instruction bp (bp_breakpoint), or a
3759 bp_hardware_breakpoint. */
3761 /* First check to see if we have to handle an overlay. */
3762 if (overlay_debugging
== ovly_off
3763 || bl
->section
== NULL
3764 || !(section_is_overlay (bl
->section
)))
3766 /* No overlay handling: just remove the breakpoint. */
3768 /* If we're trying to uninsert a memory breakpoint that we
3769 know is set in a dynamic object that is marked
3770 shlib_disabled, then either the dynamic object was
3771 removed with "remove-symbol-file" or with
3772 "nosharedlibrary". In the former case, we don't know
3773 whether another dynamic object might have loaded over the
3774 breakpoint's address -- the user might well let us know
3775 about it next with add-symbol-file (the whole point of
3776 add-symbol-file is letting the user manually maintain a
3777 list of dynamically loaded objects). If we have the
3778 breakpoint's shadow memory, that is, this is a software
3779 breakpoint managed by GDB, check whether the breakpoint
3780 is still inserted in memory, to avoid overwriting wrong
3781 code with stale saved shadow contents. Note that HW
3782 breakpoints don't have shadow memory, as they're
3783 implemented using a mechanism that is not dependent on
3784 being able to modify the target's memory, and as such
3785 they should always be removed. */
3786 if (bl
->shlib_disabled
3787 && bl
->target_info
.shadow_len
!= 0
3788 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3791 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3795 /* This breakpoint is in an overlay section.
3796 Did we set a breakpoint at the LMA? */
3797 if (!overlay_events_enabled
)
3799 /* Yes -- overlay event support is not active, so we
3800 should have set a breakpoint at the LMA. Remove it.
3802 /* Ignore any failures: if the LMA is in ROM, we will
3803 have already warned when we failed to insert it. */
3804 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3805 target_remove_hw_breakpoint (bl
->gdbarch
,
3806 &bl
->overlay_target_info
);
3808 target_remove_breakpoint (bl
->gdbarch
,
3809 &bl
->overlay_target_info
,
3812 /* Did we set a breakpoint at the VMA?
3813 If so, we will have marked the breakpoint 'inserted'. */
3816 /* Yes -- remove it. Previously we did not bother to
3817 remove the breakpoint if the section had been
3818 unmapped, but let's not rely on that being safe. We
3819 don't know what the overlay manager might do. */
3821 /* However, we should remove *software* breakpoints only
3822 if the section is still mapped, or else we overwrite
3823 wrong code with the saved shadow contents. */
3824 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3825 || section_is_mapped (bl
->section
))
3826 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3832 /* No -- not inserted, so no need to remove. No error. */
3837 /* In some cases, we might not be able to remove a breakpoint in
3838 a shared library that has already been removed, but we have
3839 not yet processed the shlib unload event. Similarly for an
3840 unloaded add-symbol-file object - the user might not yet have
3841 had the chance to remove-symbol-file it. shlib_disabled will
3842 be set if the library/object has already been removed, but
3843 the breakpoint hasn't been uninserted yet, e.g., after
3844 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3845 always-inserted mode. */
3847 && (bl
->loc_type
== bp_loc_software_breakpoint
3848 && (bl
->shlib_disabled
3849 || solib_name_from_address (bl
->pspace
, bl
->address
)
3850 || shared_objfile_contains_address_p (bl
->pspace
,
3856 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3858 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3860 gdb_assert (bl
->owner
->ops
!= NULL
3861 && bl
->owner
->ops
->remove_location
!= NULL
);
3863 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3864 bl
->owner
->ops
->remove_location (bl
, reason
);
3866 /* Failure to remove any of the hardware watchpoints comes here. */
3867 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3868 warning (_("Could not remove hardware watchpoint %d."),
3871 else if (bl
->owner
->type
== bp_catchpoint
3872 && breakpoint_enabled (bl
->owner
)
3875 gdb_assert (bl
->owner
->ops
!= NULL
3876 && bl
->owner
->ops
->remove_location
!= NULL
);
3878 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3882 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3889 remove_breakpoint (struct bp_location
*bl
)
3891 /* BL is never in moribund_locations by our callers. */
3892 gdb_assert (bl
->owner
!= NULL
);
3894 /* The type of none suggests that owner is actually deleted.
3895 This should not ever happen. */
3896 gdb_assert (bl
->owner
->type
!= bp_none
);
3898 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3900 switch_to_program_space_and_thread (bl
->pspace
);
3902 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3905 /* Clear the "inserted" flag in all breakpoints. */
3908 mark_breakpoints_out (void)
3910 struct bp_location
*bl
, **blp_tmp
;
3912 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3913 if (bl
->pspace
== current_program_space
)
3917 /* Clear the "inserted" flag in all breakpoints and delete any
3918 breakpoints which should go away between runs of the program.
3920 Plus other such housekeeping that has to be done for breakpoints
3923 Note: this function gets called at the end of a run (by
3924 generic_mourn_inferior) and when a run begins (by
3925 init_wait_for_inferior). */
3930 breakpoint_init_inferior (enum inf_context context
)
3932 struct breakpoint
*b
, *b_tmp
;
3933 struct bp_location
*bl
;
3935 struct program_space
*pspace
= current_program_space
;
3937 /* If breakpoint locations are shared across processes, then there's
3939 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
3942 mark_breakpoints_out ();
3944 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3946 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
3952 case bp_longjmp_call_dummy
:
3954 /* If the call dummy breakpoint is at the entry point it will
3955 cause problems when the inferior is rerun, so we better get
3958 case bp_watchpoint_scope
:
3960 /* Also get rid of scope breakpoints. */
3962 case bp_shlib_event
:
3964 /* Also remove solib event breakpoints. Their addresses may
3965 have changed since the last time we ran the program.
3966 Actually we may now be debugging against different target;
3967 and so the solib backend that installed this breakpoint may
3968 not be used in by the target. E.g.,
3970 (gdb) file prog-linux
3971 (gdb) run # native linux target
3974 (gdb) file prog-win.exe
3975 (gdb) tar rem :9999 # remote Windows gdbserver.
3978 case bp_step_resume
:
3980 /* Also remove step-resume breakpoints. */
3982 case bp_single_step
:
3984 /* Also remove single-step breakpoints. */
3986 delete_breakpoint (b
);
3990 case bp_hardware_watchpoint
:
3991 case bp_read_watchpoint
:
3992 case bp_access_watchpoint
:
3994 struct watchpoint
*w
= (struct watchpoint
*) b
;
3996 /* Likewise for watchpoints on local expressions. */
3997 if (w
->exp_valid_block
!= NULL
)
3998 delete_breakpoint (b
);
4001 /* Get rid of existing locations, which are no longer
4002 valid. New ones will be created in
4003 update_watchpoint, when the inferior is restarted.
4004 The next update_global_location_list call will
4005 garbage collect them. */
4008 if (context
== inf_starting
)
4010 /* Reset val field to force reread of starting value in
4011 insert_breakpoints. */
4013 value_free (w
->val
);
4025 /* Get rid of the moribund locations. */
4026 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4027 decref_bp_location (&bl
);
4028 VEC_free (bp_location_p
, moribund_locations
);
4031 /* These functions concern about actual breakpoints inserted in the
4032 target --- to e.g. check if we need to do decr_pc adjustment or if
4033 we need to hop over the bkpt --- so we check for address space
4034 match, not program space. */
4036 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4037 exists at PC. It returns ordinary_breakpoint_here if it's an
4038 ordinary breakpoint, or permanent_breakpoint_here if it's a
4039 permanent breakpoint.
4040 - When continuing from a location with an ordinary breakpoint, we
4041 actually single step once before calling insert_breakpoints.
4042 - When continuing from a location with a permanent breakpoint, we
4043 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4044 the target, to advance the PC past the breakpoint. */
4046 enum breakpoint_here
4047 breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4049 struct bp_location
*bl
, **blp_tmp
;
4050 int any_breakpoint_here
= 0;
4052 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4054 if (bl
->loc_type
!= bp_loc_software_breakpoint
4055 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4058 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4059 if ((breakpoint_enabled (bl
->owner
)
4061 && breakpoint_location_address_match (bl
, aspace
, pc
))
4063 if (overlay_debugging
4064 && section_is_overlay (bl
->section
)
4065 && !section_is_mapped (bl
->section
))
4066 continue; /* unmapped overlay -- can't be a match */
4067 else if (bl
->permanent
)
4068 return permanent_breakpoint_here
;
4070 any_breakpoint_here
= 1;
4074 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4077 /* See breakpoint.h. */
4080 breakpoint_in_range_p (const address_space
*aspace
,
4081 CORE_ADDR addr
, ULONGEST len
)
4083 struct bp_location
*bl
, **blp_tmp
;
4085 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4087 if (bl
->loc_type
!= bp_loc_software_breakpoint
4088 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4091 if ((breakpoint_enabled (bl
->owner
)
4093 && breakpoint_location_address_range_overlap (bl
, aspace
,
4096 if (overlay_debugging
4097 && section_is_overlay (bl
->section
)
4098 && !section_is_mapped (bl
->section
))
4100 /* Unmapped overlay -- can't be a match. */
4111 /* Return true if there's a moribund breakpoint at PC. */
4114 moribund_breakpoint_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4116 struct bp_location
*loc
;
4119 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4120 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4126 /* Returns non-zero iff BL is inserted at PC, in address space
4130 bp_location_inserted_here_p (struct bp_location
*bl
,
4131 const address_space
*aspace
, CORE_ADDR pc
)
4134 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4137 if (overlay_debugging
4138 && section_is_overlay (bl
->section
)
4139 && !section_is_mapped (bl
->section
))
4140 return 0; /* unmapped overlay -- can't be a match */
4147 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4150 breakpoint_inserted_here_p (const address_space
*aspace
, CORE_ADDR pc
)
4152 struct bp_location
**blp
, **blp_tmp
= NULL
;
4154 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4156 struct bp_location
*bl
= *blp
;
4158 if (bl
->loc_type
!= bp_loc_software_breakpoint
4159 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4162 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4168 /* This function returns non-zero iff there is a software breakpoint
4172 software_breakpoint_inserted_here_p (const address_space
*aspace
,
4175 struct bp_location
**blp
, **blp_tmp
= NULL
;
4177 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4179 struct bp_location
*bl
= *blp
;
4181 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4184 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4191 /* See breakpoint.h. */
4194 hardware_breakpoint_inserted_here_p (const address_space
*aspace
,
4197 struct bp_location
**blp
, **blp_tmp
= NULL
;
4199 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4201 struct bp_location
*bl
= *blp
;
4203 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4206 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4214 hardware_watchpoint_inserted_in_range (const address_space
*aspace
,
4215 CORE_ADDR addr
, ULONGEST len
)
4217 struct breakpoint
*bpt
;
4219 ALL_BREAKPOINTS (bpt
)
4221 struct bp_location
*loc
;
4223 if (bpt
->type
!= bp_hardware_watchpoint
4224 && bpt
->type
!= bp_access_watchpoint
)
4227 if (!breakpoint_enabled (bpt
))
4230 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4231 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4235 /* Check for intersection. */
4236 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4237 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4246 /* bpstat stuff. External routines' interfaces are documented
4250 is_catchpoint (struct breakpoint
*ep
)
4252 return (ep
->type
== bp_catchpoint
);
4255 /* Frees any storage that is part of a bpstat. Does not walk the
4258 bpstats::~bpstats ()
4260 if (old_val
!= NULL
)
4261 value_free (old_val
);
4262 if (bp_location_at
!= NULL
)
4263 decref_bp_location (&bp_location_at
);
4266 /* Clear a bpstat so that it says we are not at any breakpoint.
4267 Also free any storage that is part of a bpstat. */
4270 bpstat_clear (bpstat
*bsp
)
4287 bpstats::bpstats (const bpstats
&other
)
4289 bp_location_at (other
.bp_location_at
),
4290 breakpoint_at (other
.breakpoint_at
),
4291 commands (other
.commands
),
4292 old_val (other
.old_val
),
4293 print (other
.print
),
4295 print_it (other
.print_it
)
4297 if (old_val
!= NULL
)
4299 old_val
= value_copy (old_val
);
4300 release_value (old_val
);
4302 incref_bp_location (bp_location_at
);
4305 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4306 is part of the bpstat is copied as well. */
4309 bpstat_copy (bpstat bs
)
4313 bpstat retval
= NULL
;
4318 for (; bs
!= NULL
; bs
= bs
->next
)
4320 tmp
= new bpstats (*bs
);
4323 /* This is the first thing in the chain. */
4333 /* Find the bpstat associated with this breakpoint. */
4336 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4341 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4343 if (bsp
->breakpoint_at
== breakpoint
)
4349 /* See breakpoint.h. */
4352 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4354 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4356 if (bsp
->breakpoint_at
== NULL
)
4358 /* A moribund location can never explain a signal other than
4360 if (sig
== GDB_SIGNAL_TRAP
)
4365 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4374 /* Put in *NUM the breakpoint number of the first breakpoint we are
4375 stopped at. *BSP upon return is a bpstat which points to the
4376 remaining breakpoints stopped at (but which is not guaranteed to be
4377 good for anything but further calls to bpstat_num).
4379 Return 0 if passed a bpstat which does not indicate any breakpoints.
4380 Return -1 if stopped at a breakpoint that has been deleted since
4382 Return 1 otherwise. */
4385 bpstat_num (bpstat
*bsp
, int *num
)
4387 struct breakpoint
*b
;
4390 return 0; /* No more breakpoint values */
4392 /* We assume we'll never have several bpstats that correspond to a
4393 single breakpoint -- otherwise, this function might return the
4394 same number more than once and this will look ugly. */
4395 b
= (*bsp
)->breakpoint_at
;
4396 *bsp
= (*bsp
)->next
;
4398 return -1; /* breakpoint that's been deleted since */
4400 *num
= b
->number
; /* We have its number */
4404 /* See breakpoint.h. */
4407 bpstat_clear_actions (void)
4409 struct thread_info
*tp
;
4412 if (ptid_equal (inferior_ptid
, null_ptid
))
4415 tp
= find_thread_ptid (inferior_ptid
);
4419 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4421 bs
->commands
= NULL
;
4423 if (bs
->old_val
!= NULL
)
4425 value_free (bs
->old_val
);
4431 /* Called when a command is about to proceed the inferior. */
4434 breakpoint_about_to_proceed (void)
4436 if (!ptid_equal (inferior_ptid
, null_ptid
))
4438 struct thread_info
*tp
= inferior_thread ();
4440 /* Allow inferior function calls in breakpoint commands to not
4441 interrupt the command list. When the call finishes
4442 successfully, the inferior will be standing at the same
4443 breakpoint as if nothing happened. */
4444 if (tp
->control
.in_infcall
)
4448 breakpoint_proceeded
= 1;
4451 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4452 or its equivalent. */
4455 command_line_is_silent (struct command_line
*cmd
)
4457 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4460 /* Execute all the commands associated with all the breakpoints at
4461 this location. Any of these commands could cause the process to
4462 proceed beyond this point, etc. We look out for such changes by
4463 checking the global "breakpoint_proceeded" after each command.
4465 Returns true if a breakpoint command resumed the inferior. In that
4466 case, it is the caller's responsibility to recall it again with the
4467 bpstat of the current thread. */
4470 bpstat_do_actions_1 (bpstat
*bsp
)
4475 /* Avoid endless recursion if a `source' command is contained
4477 if (executing_breakpoint_commands
)
4480 scoped_restore save_executing
4481 = make_scoped_restore (&executing_breakpoint_commands
, 1);
4483 scoped_restore preventer
= prevent_dont_repeat ();
4485 /* This pointer will iterate over the list of bpstat's. */
4488 breakpoint_proceeded
= 0;
4489 for (; bs
!= NULL
; bs
= bs
->next
)
4491 struct command_line
*cmd
= NULL
;
4493 /* Take ownership of the BSP's command tree, if it has one.
4495 The command tree could legitimately contain commands like
4496 'step' and 'next', which call clear_proceed_status, which
4497 frees stop_bpstat's command tree. To make sure this doesn't
4498 free the tree we're executing out from under us, we need to
4499 take ownership of the tree ourselves. Since a given bpstat's
4500 commands are only executed once, we don't need to copy it; we
4501 can clear the pointer in the bpstat, and make sure we free
4502 the tree when we're done. */
4503 counted_command_line ccmd
= bs
->commands
;
4504 bs
->commands
= NULL
;
4507 if (command_line_is_silent (cmd
))
4509 /* The action has been already done by bpstat_stop_status. */
4515 execute_control_command (cmd
);
4517 if (breakpoint_proceeded
)
4523 if (breakpoint_proceeded
)
4525 if (current_ui
->async
)
4526 /* If we are in async mode, then the target might be still
4527 running, not stopped at any breakpoint, so nothing for
4528 us to do here -- just return to the event loop. */
4531 /* In sync mode, when execute_control_command returns
4532 we're already standing on the next breakpoint.
4533 Breakpoint commands for that stop were not run, since
4534 execute_command does not run breakpoint commands --
4535 only command_line_handler does, but that one is not
4536 involved in execution of breakpoint commands. So, we
4537 can now execute breakpoint commands. It should be
4538 noted that making execute_command do bpstat actions is
4539 not an option -- in this case we'll have recursive
4540 invocation of bpstat for each breakpoint with a
4541 command, and can easily blow up GDB stack. Instead, we
4542 return true, which will trigger the caller to recall us
4543 with the new stop_bpstat. */
4552 bpstat_do_actions (void)
4554 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4556 /* Do any commands attached to breakpoint we are stopped at. */
4557 while (!ptid_equal (inferior_ptid
, null_ptid
)
4558 && target_has_execution
4559 && !is_exited (inferior_ptid
)
4560 && !is_executing (inferior_ptid
))
4561 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4562 and only return when it is stopped at the next breakpoint, we
4563 keep doing breakpoint actions until it returns false to
4564 indicate the inferior was not resumed. */
4565 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4568 discard_cleanups (cleanup_if_error
);
4571 /* Print out the (old or new) value associated with a watchpoint. */
4574 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4577 fprintf_unfiltered (stream
, _("<unreadable>"));
4580 struct value_print_options opts
;
4581 get_user_print_options (&opts
);
4582 value_print (val
, stream
, &opts
);
4586 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4587 debugging multiple threads. */
4590 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4592 if (uiout
->is_mi_like_p ())
4597 if (show_thread_that_caused_stop ())
4600 struct thread_info
*thr
= inferior_thread ();
4602 uiout
->text ("Thread ");
4603 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4605 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4608 uiout
->text (" \"");
4609 uiout
->field_fmt ("name", "%s", name
);
4613 uiout
->text (" hit ");
4617 /* Generic routine for printing messages indicating why we
4618 stopped. The behavior of this function depends on the value
4619 'print_it' in the bpstat structure. Under some circumstances we
4620 may decide not to print anything here and delegate the task to
4623 static enum print_stop_action
4624 print_bp_stop_message (bpstat bs
)
4626 switch (bs
->print_it
)
4629 /* Nothing should be printed for this bpstat entry. */
4630 return PRINT_UNKNOWN
;
4634 /* We still want to print the frame, but we already printed the
4635 relevant messages. */
4636 return PRINT_SRC_AND_LOC
;
4639 case print_it_normal
:
4641 struct breakpoint
*b
= bs
->breakpoint_at
;
4643 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4644 which has since been deleted. */
4646 return PRINT_UNKNOWN
;
4648 /* Normal case. Call the breakpoint's print_it method. */
4649 return b
->ops
->print_it (bs
);
4654 internal_error (__FILE__
, __LINE__
,
4655 _("print_bp_stop_message: unrecognized enum value"));
4660 /* A helper function that prints a shared library stopped event. */
4663 print_solib_event (int is_catchpoint
)
4666 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4668 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4672 if (any_added
|| any_deleted
)
4673 current_uiout
->text (_("Stopped due to shared library event:\n"));
4675 current_uiout
->text (_("Stopped due to shared library event (no "
4676 "libraries added or removed)\n"));
4679 if (current_uiout
->is_mi_like_p ())
4680 current_uiout
->field_string ("reason",
4681 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4688 current_uiout
->text (_(" Inferior unloaded "));
4689 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4691 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4696 current_uiout
->text (" ");
4697 current_uiout
->field_string ("library", name
);
4698 current_uiout
->text ("\n");
4704 struct so_list
*iter
;
4707 current_uiout
->text (_(" Inferior loaded "));
4708 ui_out_emit_list
list_emitter (current_uiout
, "added");
4710 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4715 current_uiout
->text (" ");
4716 current_uiout
->field_string ("library", iter
->so_name
);
4717 current_uiout
->text ("\n");
4722 /* Print a message indicating what happened. This is called from
4723 normal_stop(). The input to this routine is the head of the bpstat
4724 list - a list of the eventpoints that caused this stop. KIND is
4725 the target_waitkind for the stopping event. This
4726 routine calls the generic print routine for printing a message
4727 about reasons for stopping. This will print (for example) the
4728 "Breakpoint n," part of the output. The return value of this
4731 PRINT_UNKNOWN: Means we printed nothing.
4732 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4733 code to print the location. An example is
4734 "Breakpoint 1, " which should be followed by
4736 PRINT_SRC_ONLY: Means we printed something, but there is no need
4737 to also print the location part of the message.
4738 An example is the catch/throw messages, which
4739 don't require a location appended to the end.
4740 PRINT_NOTHING: We have done some printing and we don't need any
4741 further info to be printed. */
4743 enum print_stop_action
4744 bpstat_print (bpstat bs
, int kind
)
4746 enum print_stop_action val
;
4748 /* Maybe another breakpoint in the chain caused us to stop.
4749 (Currently all watchpoints go on the bpstat whether hit or not.
4750 That probably could (should) be changed, provided care is taken
4751 with respect to bpstat_explains_signal). */
4752 for (; bs
; bs
= bs
->next
)
4754 val
= print_bp_stop_message (bs
);
4755 if (val
== PRINT_SRC_ONLY
4756 || val
== PRINT_SRC_AND_LOC
4757 || val
== PRINT_NOTHING
)
4761 /* If we had hit a shared library event breakpoint,
4762 print_bp_stop_message would print out this message. If we hit an
4763 OS-level shared library event, do the same thing. */
4764 if (kind
== TARGET_WAITKIND_LOADED
)
4766 print_solib_event (0);
4767 return PRINT_NOTHING
;
4770 /* We reached the end of the chain, or we got a null BS to start
4771 with and nothing was printed. */
4772 return PRINT_UNKNOWN
;
4775 /* Evaluate the boolean expression EXP and return the result. */
4778 breakpoint_cond_eval (expression
*exp
)
4780 struct value
*mark
= value_mark ();
4781 bool res
= value_true (evaluate_expression (exp
));
4783 value_free_to_mark (mark
);
4787 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4789 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4791 bp_location_at (bl
),
4792 breakpoint_at (bl
->owner
),
4797 print_it (print_it_normal
)
4799 incref_bp_location (bl
);
4800 **bs_link_pointer
= this;
4801 *bs_link_pointer
= &next
;
4806 bp_location_at (NULL
),
4807 breakpoint_at (NULL
),
4812 print_it (print_it_normal
)
4816 /* The target has stopped with waitstatus WS. Check if any hardware
4817 watchpoints have triggered, according to the target. */
4820 watchpoints_triggered (struct target_waitstatus
*ws
)
4822 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4824 struct breakpoint
*b
;
4826 if (!stopped_by_watchpoint
)
4828 /* We were not stopped by a watchpoint. Mark all watchpoints
4829 as not triggered. */
4831 if (is_hardware_watchpoint (b
))
4833 struct watchpoint
*w
= (struct watchpoint
*) b
;
4835 w
->watchpoint_triggered
= watch_triggered_no
;
4841 if (!target_stopped_data_address (¤t_target
, &addr
))
4843 /* We were stopped by a watchpoint, but we don't know where.
4844 Mark all watchpoints as unknown. */
4846 if (is_hardware_watchpoint (b
))
4848 struct watchpoint
*w
= (struct watchpoint
*) b
;
4850 w
->watchpoint_triggered
= watch_triggered_unknown
;
4856 /* The target could report the data address. Mark watchpoints
4857 affected by this data address as triggered, and all others as not
4861 if (is_hardware_watchpoint (b
))
4863 struct watchpoint
*w
= (struct watchpoint
*) b
;
4864 struct bp_location
*loc
;
4866 w
->watchpoint_triggered
= watch_triggered_no
;
4867 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4869 if (is_masked_watchpoint (b
))
4871 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4872 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4874 if (newaddr
== start
)
4876 w
->watchpoint_triggered
= watch_triggered_yes
;
4880 /* Exact match not required. Within range is sufficient. */
4881 else if (target_watchpoint_addr_within_range (¤t_target
,
4885 w
->watchpoint_triggered
= watch_triggered_yes
;
4894 /* Possible return values for watchpoint_check. */
4895 enum wp_check_result
4897 /* The watchpoint has been deleted. */
4900 /* The value has changed. */
4901 WP_VALUE_CHANGED
= 2,
4903 /* The value has not changed. */
4904 WP_VALUE_NOT_CHANGED
= 3,
4906 /* Ignore this watchpoint, no matter if the value changed or not. */
4910 #define BP_TEMPFLAG 1
4911 #define BP_HARDWAREFLAG 2
4913 /* Evaluate watchpoint condition expression and check if its value
4916 static wp_check_result
4917 watchpoint_check (bpstat bs
)
4919 struct watchpoint
*b
;
4920 struct frame_info
*fr
;
4921 int within_current_scope
;
4923 /* BS is built from an existing struct breakpoint. */
4924 gdb_assert (bs
->breakpoint_at
!= NULL
);
4925 b
= (struct watchpoint
*) bs
->breakpoint_at
;
4927 /* If this is a local watchpoint, we only want to check if the
4928 watchpoint frame is in scope if the current thread is the thread
4929 that was used to create the watchpoint. */
4930 if (!watchpoint_in_thread_scope (b
))
4933 if (b
->exp_valid_block
== NULL
)
4934 within_current_scope
= 1;
4937 struct frame_info
*frame
= get_current_frame ();
4938 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
4939 CORE_ADDR frame_pc
= get_frame_pc (frame
);
4941 /* stack_frame_destroyed_p() returns a non-zero value if we're
4942 still in the function but the stack frame has already been
4943 invalidated. Since we can't rely on the values of local
4944 variables after the stack has been destroyed, we are treating
4945 the watchpoint in that state as `not changed' without further
4946 checking. Don't mark watchpoints as changed if the current
4947 frame is in an epilogue - even if they are in some other
4948 frame, our view of the stack is likely to be wrong and
4949 frame_find_by_id could error out. */
4950 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
4953 fr
= frame_find_by_id (b
->watchpoint_frame
);
4954 within_current_scope
= (fr
!= NULL
);
4956 /* If we've gotten confused in the unwinder, we might have
4957 returned a frame that can't describe this variable. */
4958 if (within_current_scope
)
4960 struct symbol
*function
;
4962 function
= get_frame_function (fr
);
4963 if (function
== NULL
4964 || !contained_in (b
->exp_valid_block
,
4965 SYMBOL_BLOCK_VALUE (function
)))
4966 within_current_scope
= 0;
4969 if (within_current_scope
)
4970 /* If we end up stopping, the current frame will get selected
4971 in normal_stop. So this call to select_frame won't affect
4976 if (within_current_scope
)
4978 /* We use value_{,free_to_}mark because it could be a *long*
4979 time before we return to the command level and call
4980 free_all_values. We can't call free_all_values because we
4981 might be in the middle of evaluating a function call. */
4985 struct value
*new_val
;
4987 if (is_masked_watchpoint (b
))
4988 /* Since we don't know the exact trigger address (from
4989 stopped_data_address), just tell the user we've triggered
4990 a mask watchpoint. */
4991 return WP_VALUE_CHANGED
;
4993 mark
= value_mark ();
4994 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
4996 if (b
->val_bitsize
!= 0)
4997 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
4999 /* We use value_equal_contents instead of value_equal because
5000 the latter coerces an array to a pointer, thus comparing just
5001 the address of the array instead of its contents. This is
5002 not what we want. */
5003 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5004 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5006 if (new_val
!= NULL
)
5008 release_value (new_val
);
5009 value_free_to_mark (mark
);
5011 bs
->old_val
= b
->val
;
5014 return WP_VALUE_CHANGED
;
5018 /* Nothing changed. */
5019 value_free_to_mark (mark
);
5020 return WP_VALUE_NOT_CHANGED
;
5025 /* This seems like the only logical thing to do because
5026 if we temporarily ignored the watchpoint, then when
5027 we reenter the block in which it is valid it contains
5028 garbage (in the case of a function, it may have two
5029 garbage values, one before and one after the prologue).
5030 So we can't even detect the first assignment to it and
5031 watch after that (since the garbage may or may not equal
5032 the first value assigned). */
5033 /* We print all the stop information in
5034 breakpoint_ops->print_it, but in this case, by the time we
5035 call breakpoint_ops->print_it this bp will be deleted
5036 already. So we have no choice but print the information
5039 SWITCH_THRU_ALL_UIS ()
5041 struct ui_out
*uiout
= current_uiout
;
5043 if (uiout
->is_mi_like_p ())
5045 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5046 uiout
->text ("\nWatchpoint ");
5047 uiout
->field_int ("wpnum", b
->number
);
5048 uiout
->text (" deleted because the program has left the block in\n"
5049 "which its expression is valid.\n");
5052 /* Make sure the watchpoint's commands aren't executed. */
5054 watchpoint_del_at_next_stop (b
);
5060 /* Return true if it looks like target has stopped due to hitting
5061 breakpoint location BL. This function does not check if we should
5062 stop, only if BL explains the stop. */
5065 bpstat_check_location (const struct bp_location
*bl
,
5066 const address_space
*aspace
, CORE_ADDR bp_addr
,
5067 const struct target_waitstatus
*ws
)
5069 struct breakpoint
*b
= bl
->owner
;
5071 /* BL is from an existing breakpoint. */
5072 gdb_assert (b
!= NULL
);
5074 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5077 /* Determine if the watched values have actually changed, and we
5078 should stop. If not, set BS->stop to 0. */
5081 bpstat_check_watchpoint (bpstat bs
)
5083 const struct bp_location
*bl
;
5084 struct watchpoint
*b
;
5086 /* BS is built for existing struct breakpoint. */
5087 bl
= bs
->bp_location_at
;
5088 gdb_assert (bl
!= NULL
);
5089 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5090 gdb_assert (b
!= NULL
);
5093 int must_check_value
= 0;
5095 if (b
->type
== bp_watchpoint
)
5096 /* For a software watchpoint, we must always check the
5098 must_check_value
= 1;
5099 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5100 /* We have a hardware watchpoint (read, write, or access)
5101 and the target earlier reported an address watched by
5103 must_check_value
= 1;
5104 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5105 && b
->type
== bp_hardware_watchpoint
)
5106 /* We were stopped by a hardware watchpoint, but the target could
5107 not report the data address. We must check the watchpoint's
5108 value. Access and read watchpoints are out of luck; without
5109 a data address, we can't figure it out. */
5110 must_check_value
= 1;
5112 if (must_check_value
)
5118 e
= watchpoint_check (bs
);
5120 CATCH (ex
, RETURN_MASK_ALL
)
5122 exception_fprintf (gdb_stderr
, ex
,
5123 "Error evaluating expression "
5124 "for watchpoint %d\n",
5127 SWITCH_THRU_ALL_UIS ()
5129 printf_filtered (_("Watchpoint %d deleted.\n"),
5132 watchpoint_del_at_next_stop (b
);
5140 /* We've already printed what needs to be printed. */
5141 bs
->print_it
= print_it_done
;
5145 bs
->print_it
= print_it_noop
;
5148 case WP_VALUE_CHANGED
:
5149 if (b
->type
== bp_read_watchpoint
)
5151 /* There are two cases to consider here:
5153 1. We're watching the triggered memory for reads.
5154 In that case, trust the target, and always report
5155 the watchpoint hit to the user. Even though
5156 reads don't cause value changes, the value may
5157 have changed since the last time it was read, and
5158 since we're not trapping writes, we will not see
5159 those, and as such we should ignore our notion of
5162 2. We're watching the triggered memory for both
5163 reads and writes. There are two ways this may
5166 2.1. This is a target that can't break on data
5167 reads only, but can break on accesses (reads or
5168 writes), such as e.g., x86. We detect this case
5169 at the time we try to insert read watchpoints.
5171 2.2. Otherwise, the target supports read
5172 watchpoints, but, the user set an access or write
5173 watchpoint watching the same memory as this read
5176 If we're watching memory writes as well as reads,
5177 ignore watchpoint hits when we find that the
5178 value hasn't changed, as reads don't cause
5179 changes. This still gives false positives when
5180 the program writes the same value to memory as
5181 what there was already in memory (we will confuse
5182 it for a read), but it's much better than
5185 int other_write_watchpoint
= 0;
5187 if (bl
->watchpoint_type
== hw_read
)
5189 struct breakpoint
*other_b
;
5191 ALL_BREAKPOINTS (other_b
)
5192 if (other_b
->type
== bp_hardware_watchpoint
5193 || other_b
->type
== bp_access_watchpoint
)
5195 struct watchpoint
*other_w
=
5196 (struct watchpoint
*) other_b
;
5198 if (other_w
->watchpoint_triggered
5199 == watch_triggered_yes
)
5201 other_write_watchpoint
= 1;
5207 if (other_write_watchpoint
5208 || bl
->watchpoint_type
== hw_access
)
5210 /* We're watching the same memory for writes,
5211 and the value changed since the last time we
5212 updated it, so this trap must be for a write.
5214 bs
->print_it
= print_it_noop
;
5219 case WP_VALUE_NOT_CHANGED
:
5220 if (b
->type
== bp_hardware_watchpoint
5221 || b
->type
== bp_watchpoint
)
5223 /* Don't stop: write watchpoints shouldn't fire if
5224 the value hasn't changed. */
5225 bs
->print_it
= print_it_noop
;
5235 else /* must_check_value == 0 */
5237 /* This is a case where some watchpoint(s) triggered, but
5238 not at the address of this watchpoint, or else no
5239 watchpoint triggered after all. So don't print
5240 anything for this watchpoint. */
5241 bs
->print_it
= print_it_noop
;
5247 /* For breakpoints that are currently marked as telling gdb to stop,
5248 check conditions (condition proper, frame, thread and ignore count)
5249 of breakpoint referred to by BS. If we should not stop for this
5250 breakpoint, set BS->stop to 0. */
5253 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5255 const struct bp_location
*bl
;
5256 struct breakpoint
*b
;
5258 bool condition_result
= true;
5259 struct expression
*cond
;
5261 gdb_assert (bs
->stop
);
5263 /* BS is built for existing struct breakpoint. */
5264 bl
= bs
->bp_location_at
;
5265 gdb_assert (bl
!= NULL
);
5266 b
= bs
->breakpoint_at
;
5267 gdb_assert (b
!= NULL
);
5269 /* Even if the target evaluated the condition on its end and notified GDB, we
5270 need to do so again since GDB does not know if we stopped due to a
5271 breakpoint or a single step breakpoint. */
5273 if (frame_id_p (b
->frame_id
)
5274 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5280 /* If this is a thread/task-specific breakpoint, don't waste cpu
5281 evaluating the condition if this isn't the specified
5283 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5284 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5291 /* Evaluate extension language breakpoints that have a "stop" method
5293 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5295 if (is_watchpoint (b
))
5297 struct watchpoint
*w
= (struct watchpoint
*) b
;
5299 cond
= w
->cond_exp
.get ();
5302 cond
= bl
->cond
.get ();
5304 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5306 int within_current_scope
= 1;
5307 struct watchpoint
* w
;
5309 /* We use value_mark and value_free_to_mark because it could
5310 be a long time before we return to the command level and
5311 call free_all_values. We can't call free_all_values
5312 because we might be in the middle of evaluating a
5314 struct value
*mark
= value_mark ();
5316 if (is_watchpoint (b
))
5317 w
= (struct watchpoint
*) b
;
5321 /* Need to select the frame, with all that implies so that
5322 the conditions will have the right context. Because we
5323 use the frame, we will not see an inlined function's
5324 variables when we arrive at a breakpoint at the start
5325 of the inlined function; the current frame will be the
5327 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5328 select_frame (get_current_frame ());
5331 struct frame_info
*frame
;
5333 /* For local watchpoint expressions, which particular
5334 instance of a local is being watched matters, so we
5335 keep track of the frame to evaluate the expression
5336 in. To evaluate the condition however, it doesn't
5337 really matter which instantiation of the function
5338 where the condition makes sense triggers the
5339 watchpoint. This allows an expression like "watch
5340 global if q > 10" set in `func', catch writes to
5341 global on all threads that call `func', or catch
5342 writes on all recursive calls of `func' by a single
5343 thread. We simply always evaluate the condition in
5344 the innermost frame that's executing where it makes
5345 sense to evaluate the condition. It seems
5347 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5349 select_frame (frame
);
5351 within_current_scope
= 0;
5353 if (within_current_scope
)
5357 condition_result
= breakpoint_cond_eval (cond
);
5359 CATCH (ex
, RETURN_MASK_ALL
)
5361 exception_fprintf (gdb_stderr
, ex
,
5362 "Error in testing breakpoint condition:\n");
5368 warning (_("Watchpoint condition cannot be tested "
5369 "in the current scope"));
5370 /* If we failed to set the right context for this
5371 watchpoint, unconditionally report it. */
5373 /* FIXME-someday, should give breakpoint #. */
5374 value_free_to_mark (mark
);
5377 if (cond
&& !condition_result
)
5381 else if (b
->ignore_count
> 0)
5385 /* Increase the hit count even though we don't stop. */
5387 observer_notify_breakpoint_modified (b
);
5391 /* Returns true if we need to track moribund locations of LOC's type
5392 on the current target. */
5395 need_moribund_for_location_type (struct bp_location
*loc
)
5397 return ((loc
->loc_type
== bp_loc_software_breakpoint
5398 && !target_supports_stopped_by_sw_breakpoint ())
5399 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5400 && !target_supports_stopped_by_hw_breakpoint ()));
5404 /* Get a bpstat associated with having just stopped at address
5405 BP_ADDR in thread PTID.
5407 Determine whether we stopped at a breakpoint, etc, or whether we
5408 don't understand this stop. Result is a chain of bpstat's such
5411 if we don't understand the stop, the result is a null pointer.
5413 if we understand why we stopped, the result is not null.
5415 Each element of the chain refers to a particular breakpoint or
5416 watchpoint at which we have stopped. (We may have stopped for
5417 several reasons concurrently.)
5419 Each element of the chain has valid next, breakpoint_at,
5420 commands, FIXME??? fields. */
5423 bpstat_stop_status (const address_space
*aspace
,
5424 CORE_ADDR bp_addr
, ptid_t ptid
,
5425 const struct target_waitstatus
*ws
)
5427 struct breakpoint
*b
= NULL
;
5428 struct bp_location
*bl
;
5429 struct bp_location
*loc
;
5430 /* First item of allocated bpstat's. */
5431 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5432 /* Pointer to the last thing in the chain currently. */
5435 int need_remove_insert
;
5438 /* First, build the bpstat chain with locations that explain a
5439 target stop, while being careful to not set the target running,
5440 as that may invalidate locations (in particular watchpoint
5441 locations are recreated). Resuming will happen here with
5442 breakpoint conditions or watchpoint expressions that include
5443 inferior function calls. */
5447 if (!breakpoint_enabled (b
))
5450 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5452 /* For hardware watchpoints, we look only at the first
5453 location. The watchpoint_check function will work on the
5454 entire expression, not the individual locations. For
5455 read watchpoints, the watchpoints_triggered function has
5456 checked all locations already. */
5457 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5460 if (!bl
->enabled
|| bl
->shlib_disabled
)
5463 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5466 /* Come here if it's a watchpoint, or if the break address
5469 bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5472 /* Assume we stop. Should we find a watchpoint that is not
5473 actually triggered, or if the condition of the breakpoint
5474 evaluates as false, we'll reset 'stop' to 0. */
5478 /* If this is a scope breakpoint, mark the associated
5479 watchpoint as triggered so that we will handle the
5480 out-of-scope event. We'll get to the watchpoint next
5482 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5484 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5486 w
->watchpoint_triggered
= watch_triggered_yes
;
5491 /* Check if a moribund breakpoint explains the stop. */
5492 if (!target_supports_stopped_by_sw_breakpoint ()
5493 || !target_supports_stopped_by_hw_breakpoint ())
5495 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5497 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5498 && need_moribund_for_location_type (loc
))
5500 bs
= new bpstats (loc
, &bs_link
);
5501 /* For hits of moribund locations, we should just proceed. */
5504 bs
->print_it
= print_it_noop
;
5509 /* A bit of special processing for shlib breakpoints. We need to
5510 process solib loading here, so that the lists of loaded and
5511 unloaded libraries are correct before we handle "catch load" and
5513 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5515 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5517 handle_solib_event ();
5522 /* Now go through the locations that caused the target to stop, and
5523 check whether we're interested in reporting this stop to higher
5524 layers, or whether we should resume the target transparently. */
5528 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5533 b
= bs
->breakpoint_at
;
5534 b
->ops
->check_status (bs
);
5537 bpstat_check_breakpoint_conditions (bs
, ptid
);
5542 observer_notify_breakpoint_modified (b
);
5544 /* We will stop here. */
5545 if (b
->disposition
== disp_disable
)
5547 --(b
->enable_count
);
5548 if (b
->enable_count
<= 0)
5549 b
->enable_state
= bp_disabled
;
5554 bs
->commands
= b
->commands
;
5555 if (command_line_is_silent (bs
->commands
5556 ? bs
->commands
.get () : NULL
))
5559 b
->ops
->after_condition_true (bs
);
5564 /* Print nothing for this entry if we don't stop or don't
5566 if (!bs
->stop
|| !bs
->print
)
5567 bs
->print_it
= print_it_noop
;
5570 /* If we aren't stopping, the value of some hardware watchpoint may
5571 not have changed, but the intermediate memory locations we are
5572 watching may have. Don't bother if we're stopping; this will get
5574 need_remove_insert
= 0;
5575 if (! bpstat_causes_stop (bs_head
))
5576 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5578 && bs
->breakpoint_at
5579 && is_hardware_watchpoint (bs
->breakpoint_at
))
5581 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5583 update_watchpoint (w
, 0 /* don't reparse. */);
5584 need_remove_insert
= 1;
5587 if (need_remove_insert
)
5588 update_global_location_list (UGLL_MAY_INSERT
);
5589 else if (removed_any
)
5590 update_global_location_list (UGLL_DONT_INSERT
);
5596 handle_jit_event (void)
5598 struct frame_info
*frame
;
5599 struct gdbarch
*gdbarch
;
5602 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5604 /* Switch terminal for any messages produced by
5605 breakpoint_re_set. */
5606 target_terminal::ours_for_output ();
5608 frame
= get_current_frame ();
5609 gdbarch
= get_frame_arch (frame
);
5611 jit_event_handler (gdbarch
);
5613 target_terminal::inferior ();
5616 /* Prepare WHAT final decision for infrun. */
5618 /* Decide what infrun needs to do with this bpstat. */
5621 bpstat_what (bpstat bs_head
)
5623 struct bpstat_what retval
;
5626 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5627 retval
.call_dummy
= STOP_NONE
;
5628 retval
.is_longjmp
= 0;
5630 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5632 /* Extract this BS's action. After processing each BS, we check
5633 if its action overrides all we've seem so far. */
5634 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5637 if (bs
->breakpoint_at
== NULL
)
5639 /* I suspect this can happen if it was a momentary
5640 breakpoint which has since been deleted. */
5644 bptype
= bs
->breakpoint_at
->type
;
5651 case bp_hardware_breakpoint
:
5652 case bp_single_step
:
5655 case bp_shlib_event
:
5659 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5661 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5664 this_action
= BPSTAT_WHAT_SINGLE
;
5667 case bp_hardware_watchpoint
:
5668 case bp_read_watchpoint
:
5669 case bp_access_watchpoint
:
5673 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5675 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5679 /* There was a watchpoint, but we're not stopping.
5680 This requires no further action. */
5684 case bp_longjmp_call_dummy
:
5688 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5689 retval
.is_longjmp
= bptype
!= bp_exception
;
5692 this_action
= BPSTAT_WHAT_SINGLE
;
5694 case bp_longjmp_resume
:
5695 case bp_exception_resume
:
5698 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5699 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5702 this_action
= BPSTAT_WHAT_SINGLE
;
5704 case bp_step_resume
:
5706 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5709 /* It is for the wrong frame. */
5710 this_action
= BPSTAT_WHAT_SINGLE
;
5713 case bp_hp_step_resume
:
5715 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5718 /* It is for the wrong frame. */
5719 this_action
= BPSTAT_WHAT_SINGLE
;
5722 case bp_watchpoint_scope
:
5723 case bp_thread_event
:
5724 case bp_overlay_event
:
5725 case bp_longjmp_master
:
5726 case bp_std_terminate_master
:
5727 case bp_exception_master
:
5728 this_action
= BPSTAT_WHAT_SINGLE
;
5734 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5736 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5740 /* There was a catchpoint, but we're not stopping.
5741 This requires no further action. */
5745 this_action
= BPSTAT_WHAT_SINGLE
;
5748 /* Make sure the action is stop (silent or noisy),
5749 so infrun.c pops the dummy frame. */
5750 retval
.call_dummy
= STOP_STACK_DUMMY
;
5751 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5753 case bp_std_terminate
:
5754 /* Make sure the action is stop (silent or noisy),
5755 so infrun.c pops the dummy frame. */
5756 retval
.call_dummy
= STOP_STD_TERMINATE
;
5757 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5760 case bp_fast_tracepoint
:
5761 case bp_static_tracepoint
:
5762 /* Tracepoint hits should not be reported back to GDB, and
5763 if one got through somehow, it should have been filtered
5765 internal_error (__FILE__
, __LINE__
,
5766 _("bpstat_what: tracepoint encountered"));
5768 case bp_gnu_ifunc_resolver
:
5769 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5770 this_action
= BPSTAT_WHAT_SINGLE
;
5772 case bp_gnu_ifunc_resolver_return
:
5773 /* The breakpoint will be removed, execution will restart from the
5774 PC of the former breakpoint. */
5775 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5780 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5782 this_action
= BPSTAT_WHAT_SINGLE
;
5786 internal_error (__FILE__
, __LINE__
,
5787 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5790 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5797 bpstat_run_callbacks (bpstat bs_head
)
5801 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5803 struct breakpoint
*b
= bs
->breakpoint_at
;
5810 handle_jit_event ();
5812 case bp_gnu_ifunc_resolver
:
5813 gnu_ifunc_resolver_stop (b
);
5815 case bp_gnu_ifunc_resolver_return
:
5816 gnu_ifunc_resolver_return_stop (b
);
5822 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5823 without hardware support). This isn't related to a specific bpstat,
5824 just to things like whether watchpoints are set. */
5827 bpstat_should_step (void)
5829 struct breakpoint
*b
;
5832 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5838 bpstat_causes_stop (bpstat bs
)
5840 for (; bs
!= NULL
; bs
= bs
->next
)
5849 /* Compute a string of spaces suitable to indent the next line
5850 so it starts at the position corresponding to the table column
5851 named COL_NAME in the currently active table of UIOUT. */
5854 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5856 static char wrap_indent
[80];
5857 int i
, total_width
, width
, align
;
5861 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5863 if (strcmp (text
, col_name
) == 0)
5865 gdb_assert (total_width
< sizeof wrap_indent
);
5866 memset (wrap_indent
, ' ', total_width
);
5867 wrap_indent
[total_width
] = 0;
5872 total_width
+= width
+ 1;
5878 /* Determine if the locations of this breakpoint will have their conditions
5879 evaluated by the target, host or a mix of both. Returns the following:
5881 "host": Host evals condition.
5882 "host or target": Host or Target evals condition.
5883 "target": Target evals condition.
5887 bp_condition_evaluator (struct breakpoint
*b
)
5889 struct bp_location
*bl
;
5890 char host_evals
= 0;
5891 char target_evals
= 0;
5896 if (!is_breakpoint (b
))
5899 if (gdb_evaluates_breakpoint_condition_p ()
5900 || !target_supports_evaluation_of_breakpoint_conditions ())
5901 return condition_evaluation_host
;
5903 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5905 if (bl
->cond_bytecode
)
5911 if (host_evals
&& target_evals
)
5912 return condition_evaluation_both
;
5913 else if (target_evals
)
5914 return condition_evaluation_target
;
5916 return condition_evaluation_host
;
5919 /* Determine the breakpoint location's condition evaluator. This is
5920 similar to bp_condition_evaluator, but for locations. */
5923 bp_location_condition_evaluator (struct bp_location
*bl
)
5925 if (bl
&& !is_breakpoint (bl
->owner
))
5928 if (gdb_evaluates_breakpoint_condition_p ()
5929 || !target_supports_evaluation_of_breakpoint_conditions ())
5930 return condition_evaluation_host
;
5932 if (bl
&& bl
->cond_bytecode
)
5933 return condition_evaluation_target
;
5935 return condition_evaluation_host
;
5938 /* Print the LOC location out of the list of B->LOC locations. */
5941 print_breakpoint_location (struct breakpoint
*b
,
5942 struct bp_location
*loc
)
5944 struct ui_out
*uiout
= current_uiout
;
5946 scoped_restore_current_program_space restore_pspace
;
5948 if (loc
!= NULL
&& loc
->shlib_disabled
)
5952 set_current_program_space (loc
->pspace
);
5954 if (b
->display_canonical
)
5955 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
5956 else if (loc
&& loc
->symtab
)
5958 const struct symbol
*sym
= loc
->symbol
;
5961 sym
= find_pc_sect_function (loc
->address
, loc
->section
);
5965 uiout
->text ("in ");
5966 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
5968 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
5969 uiout
->text ("at ");
5971 uiout
->field_string ("file",
5972 symtab_to_filename_for_display (loc
->symtab
));
5975 if (uiout
->is_mi_like_p ())
5976 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
5978 uiout
->field_int ("line", loc
->line_number
);
5984 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
5986 uiout
->field_stream ("at", stb
);
5990 uiout
->field_string ("pending",
5991 event_location_to_string (b
->location
.get ()));
5992 /* If extra_string is available, it could be holding a condition
5993 or dprintf arguments. In either case, make sure it is printed,
5994 too, but only for non-MI streams. */
5995 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
5997 if (b
->type
== bp_dprintf
)
6001 uiout
->text (b
->extra_string
);
6005 if (loc
&& is_breakpoint (b
)
6006 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6007 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6010 uiout
->field_string ("evaluated-by",
6011 bp_location_condition_evaluator (loc
));
6017 bptype_string (enum bptype type
)
6019 struct ep_type_description
6022 const char *description
;
6024 static struct ep_type_description bptypes
[] =
6026 {bp_none
, "?deleted?"},
6027 {bp_breakpoint
, "breakpoint"},
6028 {bp_hardware_breakpoint
, "hw breakpoint"},
6029 {bp_single_step
, "sw single-step"},
6030 {bp_until
, "until"},
6031 {bp_finish
, "finish"},
6032 {bp_watchpoint
, "watchpoint"},
6033 {bp_hardware_watchpoint
, "hw watchpoint"},
6034 {bp_read_watchpoint
, "read watchpoint"},
6035 {bp_access_watchpoint
, "acc watchpoint"},
6036 {bp_longjmp
, "longjmp"},
6037 {bp_longjmp_resume
, "longjmp resume"},
6038 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6039 {bp_exception
, "exception"},
6040 {bp_exception_resume
, "exception resume"},
6041 {bp_step_resume
, "step resume"},
6042 {bp_hp_step_resume
, "high-priority step resume"},
6043 {bp_watchpoint_scope
, "watchpoint scope"},
6044 {bp_call_dummy
, "call dummy"},
6045 {bp_std_terminate
, "std::terminate"},
6046 {bp_shlib_event
, "shlib events"},
6047 {bp_thread_event
, "thread events"},
6048 {bp_overlay_event
, "overlay events"},
6049 {bp_longjmp_master
, "longjmp master"},
6050 {bp_std_terminate_master
, "std::terminate master"},
6051 {bp_exception_master
, "exception master"},
6052 {bp_catchpoint
, "catchpoint"},
6053 {bp_tracepoint
, "tracepoint"},
6054 {bp_fast_tracepoint
, "fast tracepoint"},
6055 {bp_static_tracepoint
, "static tracepoint"},
6056 {bp_dprintf
, "dprintf"},
6057 {bp_jit_event
, "jit events"},
6058 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6059 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6062 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6063 || ((int) type
!= bptypes
[(int) type
].type
))
6064 internal_error (__FILE__
, __LINE__
,
6065 _("bptypes table does not describe type #%d."),
6068 return bptypes
[(int) type
].description
;
6071 /* For MI, output a field named 'thread-groups' with a list as the value.
6072 For CLI, prefix the list with the string 'inf'. */
6075 output_thread_groups (struct ui_out
*uiout
,
6076 const char *field_name
,
6080 int is_mi
= uiout
->is_mi_like_p ();
6084 /* For backward compatibility, don't display inferiors in CLI unless
6085 there are several. Always display them for MI. */
6086 if (!is_mi
&& mi_only
)
6089 ui_out_emit_list
list_emitter (uiout
, field_name
);
6091 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6097 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6098 uiout
->field_string (NULL
, mi_group
);
6103 uiout
->text (" inf ");
6107 uiout
->text (plongest (inf
));
6112 /* Print B to gdb_stdout. */
6115 print_one_breakpoint_location (struct breakpoint
*b
,
6116 struct bp_location
*loc
,
6118 struct bp_location
**last_loc
,
6121 struct command_line
*l
;
6122 static char bpenables
[] = "nynny";
6124 struct ui_out
*uiout
= current_uiout
;
6125 int header_of_multiple
= 0;
6126 int part_of_multiple
= (loc
!= NULL
);
6127 struct value_print_options opts
;
6129 get_user_print_options (&opts
);
6131 gdb_assert (!loc
|| loc_number
!= 0);
6132 /* See comment in print_one_breakpoint concerning treatment of
6133 breakpoints with single disabled location. */
6136 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6137 header_of_multiple
= 1;
6145 if (part_of_multiple
)
6148 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6149 uiout
->field_string ("number", formatted
);
6154 uiout
->field_int ("number", b
->number
);
6159 if (part_of_multiple
)
6160 uiout
->field_skip ("type");
6162 uiout
->field_string ("type", bptype_string (b
->type
));
6166 if (part_of_multiple
)
6167 uiout
->field_skip ("disp");
6169 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6174 if (part_of_multiple
)
6175 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6177 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6182 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6184 /* Although the print_one can possibly print all locations,
6185 calling it here is not likely to get any nice result. So,
6186 make sure there's just one location. */
6187 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6188 b
->ops
->print_one (b
, last_loc
);
6194 internal_error (__FILE__
, __LINE__
,
6195 _("print_one_breakpoint: bp_none encountered\n"));
6199 case bp_hardware_watchpoint
:
6200 case bp_read_watchpoint
:
6201 case bp_access_watchpoint
:
6203 struct watchpoint
*w
= (struct watchpoint
*) b
;
6205 /* Field 4, the address, is omitted (which makes the columns
6206 not line up too nicely with the headers, but the effect
6207 is relatively readable). */
6208 if (opts
.addressprint
)
6209 uiout
->field_skip ("addr");
6211 uiout
->field_string ("what", w
->exp_string
);
6216 case bp_hardware_breakpoint
:
6217 case bp_single_step
:
6221 case bp_longjmp_resume
:
6222 case bp_longjmp_call_dummy
:
6224 case bp_exception_resume
:
6225 case bp_step_resume
:
6226 case bp_hp_step_resume
:
6227 case bp_watchpoint_scope
:
6229 case bp_std_terminate
:
6230 case bp_shlib_event
:
6231 case bp_thread_event
:
6232 case bp_overlay_event
:
6233 case bp_longjmp_master
:
6234 case bp_std_terminate_master
:
6235 case bp_exception_master
:
6237 case bp_fast_tracepoint
:
6238 case bp_static_tracepoint
:
6241 case bp_gnu_ifunc_resolver
:
6242 case bp_gnu_ifunc_resolver_return
:
6243 if (opts
.addressprint
)
6246 if (header_of_multiple
)
6247 uiout
->field_string ("addr", "<MULTIPLE>");
6248 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6249 uiout
->field_string ("addr", "<PENDING>");
6251 uiout
->field_core_addr ("addr",
6252 loc
->gdbarch
, loc
->address
);
6255 if (!header_of_multiple
)
6256 print_breakpoint_location (b
, loc
);
6263 if (loc
!= NULL
&& !header_of_multiple
)
6265 struct inferior
*inf
;
6266 VEC(int) *inf_num
= NULL
;
6271 if (inf
->pspace
== loc
->pspace
)
6272 VEC_safe_push (int, inf_num
, inf
->num
);
6275 /* For backward compatibility, don't display inferiors in CLI unless
6276 there are several. Always display for MI. */
6278 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6279 && (number_of_program_spaces () > 1
6280 || number_of_inferiors () > 1)
6281 /* LOC is for existing B, it cannot be in
6282 moribund_locations and thus having NULL OWNER. */
6283 && loc
->owner
->type
!= bp_catchpoint
))
6285 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6286 VEC_free (int, inf_num
);
6289 if (!part_of_multiple
)
6291 if (b
->thread
!= -1)
6293 /* FIXME: This seems to be redundant and lost here; see the
6294 "stop only in" line a little further down. */
6295 uiout
->text (" thread ");
6296 uiout
->field_int ("thread", b
->thread
);
6298 else if (b
->task
!= 0)
6300 uiout
->text (" task ");
6301 uiout
->field_int ("task", b
->task
);
6307 if (!part_of_multiple
)
6308 b
->ops
->print_one_detail (b
, uiout
);
6310 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6313 uiout
->text ("\tstop only in stack frame at ");
6314 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6316 uiout
->field_core_addr ("frame",
6317 b
->gdbarch
, b
->frame_id
.stack_addr
);
6321 if (!part_of_multiple
&& b
->cond_string
)
6324 if (is_tracepoint (b
))
6325 uiout
->text ("\ttrace only if ");
6327 uiout
->text ("\tstop only if ");
6328 uiout
->field_string ("cond", b
->cond_string
);
6330 /* Print whether the target is doing the breakpoint's condition
6331 evaluation. If GDB is doing the evaluation, don't print anything. */
6332 if (is_breakpoint (b
)
6333 && breakpoint_condition_evaluation_mode ()
6334 == condition_evaluation_target
)
6337 uiout
->field_string ("evaluated-by",
6338 bp_condition_evaluator (b
));
6339 uiout
->text (" evals)");
6344 if (!part_of_multiple
&& b
->thread
!= -1)
6346 /* FIXME should make an annotation for this. */
6347 uiout
->text ("\tstop only in thread ");
6348 if (uiout
->is_mi_like_p ())
6349 uiout
->field_int ("thread", b
->thread
);
6352 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6354 uiout
->field_string ("thread", print_thread_id (thr
));
6359 if (!part_of_multiple
)
6363 /* FIXME should make an annotation for this. */
6364 if (is_catchpoint (b
))
6365 uiout
->text ("\tcatchpoint");
6366 else if (is_tracepoint (b
))
6367 uiout
->text ("\ttracepoint");
6369 uiout
->text ("\tbreakpoint");
6370 uiout
->text (" already hit ");
6371 uiout
->field_int ("times", b
->hit_count
);
6372 if (b
->hit_count
== 1)
6373 uiout
->text (" time\n");
6375 uiout
->text (" times\n");
6379 /* Output the count also if it is zero, but only if this is mi. */
6380 if (uiout
->is_mi_like_p ())
6381 uiout
->field_int ("times", b
->hit_count
);
6385 if (!part_of_multiple
&& b
->ignore_count
)
6388 uiout
->text ("\tignore next ");
6389 uiout
->field_int ("ignore", b
->ignore_count
);
6390 uiout
->text (" hits\n");
6393 /* Note that an enable count of 1 corresponds to "enable once"
6394 behavior, which is reported by the combination of enablement and
6395 disposition, so we don't need to mention it here. */
6396 if (!part_of_multiple
&& b
->enable_count
> 1)
6399 uiout
->text ("\tdisable after ");
6400 /* Tweak the wording to clarify that ignore and enable counts
6401 are distinct, and have additive effect. */
6402 if (b
->ignore_count
)
6403 uiout
->text ("additional ");
6405 uiout
->text ("next ");
6406 uiout
->field_int ("enable", b
->enable_count
);
6407 uiout
->text (" hits\n");
6410 if (!part_of_multiple
&& is_tracepoint (b
))
6412 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6414 if (tp
->traceframe_usage
)
6416 uiout
->text ("\ttrace buffer usage ");
6417 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6418 uiout
->text (" bytes\n");
6422 l
= b
->commands
? b
->commands
.get () : NULL
;
6423 if (!part_of_multiple
&& l
)
6426 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6427 print_command_lines (uiout
, l
, 4);
6430 if (is_tracepoint (b
))
6432 struct tracepoint
*t
= (struct tracepoint
*) b
;
6434 if (!part_of_multiple
&& t
->pass_count
)
6436 annotate_field (10);
6437 uiout
->text ("\tpass count ");
6438 uiout
->field_int ("pass", t
->pass_count
);
6439 uiout
->text (" \n");
6442 /* Don't display it when tracepoint or tracepoint location is
6444 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6446 annotate_field (11);
6448 if (uiout
->is_mi_like_p ())
6449 uiout
->field_string ("installed",
6450 loc
->inserted
? "y" : "n");
6456 uiout
->text ("\tnot ");
6457 uiout
->text ("installed on target\n");
6462 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6464 if (is_watchpoint (b
))
6466 struct watchpoint
*w
= (struct watchpoint
*) b
;
6468 uiout
->field_string ("original-location", w
->exp_string
);
6470 else if (b
->location
!= NULL
6471 && event_location_to_string (b
->location
.get ()) != NULL
)
6472 uiout
->field_string ("original-location",
6473 event_location_to_string (b
->location
.get ()));
6478 print_one_breakpoint (struct breakpoint
*b
,
6479 struct bp_location
**last_loc
,
6482 struct ui_out
*uiout
= current_uiout
;
6485 ui_out_emit_tuple
tuple_emitter (uiout
, "bkpt");
6487 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6490 /* If this breakpoint has custom print function,
6491 it's already printed. Otherwise, print individual
6492 locations, if any. */
6493 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6495 /* If breakpoint has a single location that is disabled, we
6496 print it as if it had several locations, since otherwise it's
6497 hard to represent "breakpoint enabled, location disabled"
6500 Note that while hardware watchpoints have several locations
6501 internally, that's not a property exposed to user. */
6503 && !is_hardware_watchpoint (b
)
6504 && (b
->loc
->next
|| !b
->loc
->enabled
))
6506 struct bp_location
*loc
;
6509 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6511 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
6512 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6519 breakpoint_address_bits (struct breakpoint
*b
)
6521 int print_address_bits
= 0;
6522 struct bp_location
*loc
;
6524 /* Software watchpoints that aren't watching memory don't have an
6525 address to print. */
6526 if (is_no_memory_software_watchpoint (b
))
6529 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6533 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6534 if (addr_bit
> print_address_bits
)
6535 print_address_bits
= addr_bit
;
6538 return print_address_bits
;
6541 /* See breakpoint.h. */
6544 print_breakpoint (breakpoint
*b
)
6546 struct bp_location
*dummy_loc
= NULL
;
6547 print_one_breakpoint (b
, &dummy_loc
, 0);
6550 /* Return true if this breakpoint was set by the user, false if it is
6551 internal or momentary. */
6554 user_breakpoint_p (struct breakpoint
*b
)
6556 return b
->number
> 0;
6559 /* See breakpoint.h. */
6562 pending_breakpoint_p (struct breakpoint
*b
)
6564 return b
->loc
== NULL
;
6567 /* Print information on user settable breakpoint (watchpoint, etc)
6568 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6569 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6570 FILTER is non-NULL, call it on each breakpoint and only include the
6571 ones for which it returns non-zero. Return the total number of
6572 breakpoints listed. */
6575 breakpoint_1 (const char *args
, int allflag
,
6576 int (*filter
) (const struct breakpoint
*))
6578 struct breakpoint
*b
;
6579 struct bp_location
*last_loc
= NULL
;
6580 int nr_printable_breakpoints
;
6581 struct value_print_options opts
;
6582 int print_address_bits
= 0;
6583 int print_type_col_width
= 14;
6584 struct ui_out
*uiout
= current_uiout
;
6586 get_user_print_options (&opts
);
6588 /* Compute the number of rows in the table, as well as the size
6589 required for address fields. */
6590 nr_printable_breakpoints
= 0;
6593 /* If we have a filter, only list the breakpoints it accepts. */
6594 if (filter
&& !filter (b
))
6597 /* If we have an "args" string, it is a list of breakpoints to
6598 accept. Skip the others. */
6599 if (args
!= NULL
&& *args
!= '\0')
6601 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6603 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6607 if (allflag
|| user_breakpoint_p (b
))
6609 int addr_bit
, type_len
;
6611 addr_bit
= breakpoint_address_bits (b
);
6612 if (addr_bit
> print_address_bits
)
6613 print_address_bits
= addr_bit
;
6615 type_len
= strlen (bptype_string (b
->type
));
6616 if (type_len
> print_type_col_width
)
6617 print_type_col_width
= type_len
;
6619 nr_printable_breakpoints
++;
6624 ui_out_emit_table
table_emitter (uiout
,
6625 opts
.addressprint
? 6 : 5,
6626 nr_printable_breakpoints
,
6629 if (nr_printable_breakpoints
> 0)
6630 annotate_breakpoints_headers ();
6631 if (nr_printable_breakpoints
> 0)
6633 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6634 if (nr_printable_breakpoints
> 0)
6636 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6637 if (nr_printable_breakpoints
> 0)
6639 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6640 if (nr_printable_breakpoints
> 0)
6642 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6643 if (opts
.addressprint
)
6645 if (nr_printable_breakpoints
> 0)
6647 if (print_address_bits
<= 32)
6648 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6650 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6652 if (nr_printable_breakpoints
> 0)
6654 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6655 uiout
->table_body ();
6656 if (nr_printable_breakpoints
> 0)
6657 annotate_breakpoints_table ();
6662 /* If we have a filter, only list the breakpoints it accepts. */
6663 if (filter
&& !filter (b
))
6666 /* If we have an "args" string, it is a list of breakpoints to
6667 accept. Skip the others. */
6669 if (args
!= NULL
&& *args
!= '\0')
6671 if (allflag
) /* maintenance info breakpoint */
6673 if (parse_and_eval_long (args
) != b
->number
)
6676 else /* all others */
6678 if (!number_is_in_list (args
, b
->number
))
6682 /* We only print out user settable breakpoints unless the
6684 if (allflag
|| user_breakpoint_p (b
))
6685 print_one_breakpoint (b
, &last_loc
, allflag
);
6689 if (nr_printable_breakpoints
== 0)
6691 /* If there's a filter, let the caller decide how to report
6695 if (args
== NULL
|| *args
== '\0')
6696 uiout
->message ("No breakpoints or watchpoints.\n");
6698 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6704 if (last_loc
&& !server_command
)
6705 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6708 /* FIXME? Should this be moved up so that it is only called when
6709 there have been breakpoints? */
6710 annotate_breakpoints_table_end ();
6712 return nr_printable_breakpoints
;
6715 /* Display the value of default-collect in a way that is generally
6716 compatible with the breakpoint list. */
6719 default_collect_info (void)
6721 struct ui_out
*uiout
= current_uiout
;
6723 /* If it has no value (which is frequently the case), say nothing; a
6724 message like "No default-collect." gets in user's face when it's
6726 if (!*default_collect
)
6729 /* The following phrase lines up nicely with per-tracepoint collect
6731 uiout
->text ("default collect ");
6732 uiout
->field_string ("default-collect", default_collect
);
6733 uiout
->text (" \n");
6737 info_breakpoints_command (char *args
, int from_tty
)
6739 breakpoint_1 (args
, 0, NULL
);
6741 default_collect_info ();
6745 info_watchpoints_command (char *args
, int from_tty
)
6747 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6748 struct ui_out
*uiout
= current_uiout
;
6750 if (num_printed
== 0)
6752 if (args
== NULL
|| *args
== '\0')
6753 uiout
->message ("No watchpoints.\n");
6755 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6760 maintenance_info_breakpoints (const char *args
, int from_tty
)
6762 breakpoint_1 (args
, 1, NULL
);
6764 default_collect_info ();
6768 breakpoint_has_pc (struct breakpoint
*b
,
6769 struct program_space
*pspace
,
6770 CORE_ADDR pc
, struct obj_section
*section
)
6772 struct bp_location
*bl
= b
->loc
;
6774 for (; bl
; bl
= bl
->next
)
6776 if (bl
->pspace
== pspace
6777 && bl
->address
== pc
6778 && (!overlay_debugging
|| bl
->section
== section
))
6784 /* Print a message describing any user-breakpoints set at PC. This
6785 concerns with logical breakpoints, so we match program spaces, not
6789 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6790 struct program_space
*pspace
, CORE_ADDR pc
,
6791 struct obj_section
*section
, int thread
)
6794 struct breakpoint
*b
;
6797 others
+= (user_breakpoint_p (b
)
6798 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6802 printf_filtered (_("Note: breakpoint "));
6803 else /* if (others == ???) */
6804 printf_filtered (_("Note: breakpoints "));
6806 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6809 printf_filtered ("%d", b
->number
);
6810 if (b
->thread
== -1 && thread
!= -1)
6811 printf_filtered (" (all threads)");
6812 else if (b
->thread
!= -1)
6813 printf_filtered (" (thread %d)", b
->thread
);
6814 printf_filtered ("%s%s ",
6815 ((b
->enable_state
== bp_disabled
6816 || b
->enable_state
== bp_call_disabled
)
6820 : ((others
== 1) ? " and" : ""));
6822 printf_filtered (_("also set at pc "));
6823 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6824 printf_filtered (".\n");
6829 /* Return true iff it is meaningful to use the address member of
6830 BPT locations. For some breakpoint types, the locations' address members
6831 are irrelevant and it makes no sense to attempt to compare them to other
6832 addresses (or use them for any other purpose either).
6834 More specifically, each of the following breakpoint types will
6835 always have a zero valued location address and we don't want to mark
6836 breakpoints of any of these types to be a duplicate of an actual
6837 breakpoint location at address zero:
6845 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6847 enum bptype type
= bpt
->type
;
6849 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6852 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6853 true if LOC1 and LOC2 represent the same watchpoint location. */
6856 watchpoint_locations_match (struct bp_location
*loc1
,
6857 struct bp_location
*loc2
)
6859 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6860 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6862 /* Both of them must exist. */
6863 gdb_assert (w1
!= NULL
);
6864 gdb_assert (w2
!= NULL
);
6866 /* If the target can evaluate the condition expression in hardware,
6867 then we we need to insert both watchpoints even if they are at
6868 the same place. Otherwise the watchpoint will only trigger when
6869 the condition of whichever watchpoint was inserted evaluates to
6870 true, not giving a chance for GDB to check the condition of the
6871 other watchpoint. */
6873 && target_can_accel_watchpoint_condition (loc1
->address
,
6875 loc1
->watchpoint_type
,
6876 w1
->cond_exp
.get ()))
6878 && target_can_accel_watchpoint_condition (loc2
->address
,
6880 loc2
->watchpoint_type
,
6881 w2
->cond_exp
.get ())))
6884 /* Note that this checks the owner's type, not the location's. In
6885 case the target does not support read watchpoints, but does
6886 support access watchpoints, we'll have bp_read_watchpoint
6887 watchpoints with hw_access locations. Those should be considered
6888 duplicates of hw_read locations. The hw_read locations will
6889 become hw_access locations later. */
6890 return (loc1
->owner
->type
== loc2
->owner
->type
6891 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
6892 && loc1
->address
== loc2
->address
6893 && loc1
->length
== loc2
->length
);
6896 /* See breakpoint.h. */
6899 breakpoint_address_match (const address_space
*aspace1
, CORE_ADDR addr1
,
6900 const address_space
*aspace2
, CORE_ADDR addr2
)
6902 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6903 || aspace1
== aspace2
)
6907 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
6908 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
6909 matches ASPACE2. On targets that have global breakpoints, the address
6910 space doesn't really matter. */
6913 breakpoint_address_match_range (const address_space
*aspace1
,
6915 int len1
, const address_space
*aspace2
,
6918 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
6919 || aspace1
== aspace2
)
6920 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
6923 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
6924 a ranged breakpoint. In most targets, a match happens only if ASPACE
6925 matches the breakpoint's address space. On targets that have global
6926 breakpoints, the address space doesn't really matter. */
6929 breakpoint_location_address_match (struct bp_location
*bl
,
6930 const address_space
*aspace
,
6933 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
6936 && breakpoint_address_match_range (bl
->pspace
->aspace
,
6937 bl
->address
, bl
->length
,
6941 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
6942 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
6943 match happens only if ASPACE matches the breakpoint's address
6944 space. On targets that have global breakpoints, the address space
6945 doesn't really matter. */
6948 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
6949 const address_space
*aspace
,
6950 CORE_ADDR addr
, int len
)
6952 if (gdbarch_has_global_breakpoints (target_gdbarch ())
6953 || bl
->pspace
->aspace
== aspace
)
6955 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
6957 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
6963 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
6964 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
6965 true, otherwise returns false. */
6968 tracepoint_locations_match (struct bp_location
*loc1
,
6969 struct bp_location
*loc2
)
6971 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
6972 /* Since tracepoint locations are never duplicated with others', tracepoint
6973 locations at the same address of different tracepoints are regarded as
6974 different locations. */
6975 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
6980 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
6981 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
6982 represent the same location. */
6985 breakpoint_locations_match (struct bp_location
*loc1
,
6986 struct bp_location
*loc2
)
6988 int hw_point1
, hw_point2
;
6990 /* Both of them must not be in moribund_locations. */
6991 gdb_assert (loc1
->owner
!= NULL
);
6992 gdb_assert (loc2
->owner
!= NULL
);
6994 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
6995 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
6997 if (hw_point1
!= hw_point2
)
7000 return watchpoint_locations_match (loc1
, loc2
);
7001 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7002 return tracepoint_locations_match (loc1
, loc2
);
7004 /* We compare bp_location.length in order to cover ranged breakpoints. */
7005 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7006 loc2
->pspace
->aspace
, loc2
->address
)
7007 && loc1
->length
== loc2
->length
);
7011 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7012 int bnum
, int have_bnum
)
7014 /* The longest string possibly returned by hex_string_custom
7015 is 50 chars. These must be at least that big for safety. */
7019 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7020 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7022 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7023 bnum
, astr1
, astr2
);
7025 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7028 /* Adjust a breakpoint's address to account for architectural
7029 constraints on breakpoint placement. Return the adjusted address.
7030 Note: Very few targets require this kind of adjustment. For most
7031 targets, this function is simply the identity function. */
7034 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7035 CORE_ADDR bpaddr
, enum bptype bptype
)
7037 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7039 /* Very few targets need any kind of breakpoint adjustment. */
7042 else if (bptype
== bp_watchpoint
7043 || bptype
== bp_hardware_watchpoint
7044 || bptype
== bp_read_watchpoint
7045 || bptype
== bp_access_watchpoint
7046 || bptype
== bp_catchpoint
)
7048 /* Watchpoints and the various bp_catch_* eventpoints should not
7049 have their addresses modified. */
7052 else if (bptype
== bp_single_step
)
7054 /* Single-step breakpoints should not have their addresses
7055 modified. If there's any architectural constrain that
7056 applies to this address, then it should have already been
7057 taken into account when the breakpoint was created in the
7058 first place. If we didn't do this, stepping through e.g.,
7059 Thumb-2 IT blocks would break. */
7064 CORE_ADDR adjusted_bpaddr
;
7066 /* Some targets have architectural constraints on the placement
7067 of breakpoint instructions. Obtain the adjusted address. */
7068 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7070 /* An adjusted breakpoint address can significantly alter
7071 a user's expectations. Print a warning if an adjustment
7073 if (adjusted_bpaddr
!= bpaddr
)
7074 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7076 return adjusted_bpaddr
;
7080 bp_location::bp_location (const bp_location_ops
*ops
, breakpoint
*owner
)
7082 bp_location
*loc
= this;
7084 gdb_assert (ops
!= NULL
);
7088 loc
->cond_bytecode
= NULL
;
7089 loc
->shlib_disabled
= 0;
7092 switch (owner
->type
)
7095 case bp_single_step
:
7099 case bp_longjmp_resume
:
7100 case bp_longjmp_call_dummy
:
7102 case bp_exception_resume
:
7103 case bp_step_resume
:
7104 case bp_hp_step_resume
:
7105 case bp_watchpoint_scope
:
7107 case bp_std_terminate
:
7108 case bp_shlib_event
:
7109 case bp_thread_event
:
7110 case bp_overlay_event
:
7112 case bp_longjmp_master
:
7113 case bp_std_terminate_master
:
7114 case bp_exception_master
:
7115 case bp_gnu_ifunc_resolver
:
7116 case bp_gnu_ifunc_resolver_return
:
7118 loc
->loc_type
= bp_loc_software_breakpoint
;
7119 mark_breakpoint_location_modified (loc
);
7121 case bp_hardware_breakpoint
:
7122 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7123 mark_breakpoint_location_modified (loc
);
7125 case bp_hardware_watchpoint
:
7126 case bp_read_watchpoint
:
7127 case bp_access_watchpoint
:
7128 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7133 case bp_fast_tracepoint
:
7134 case bp_static_tracepoint
:
7135 loc
->loc_type
= bp_loc_other
;
7138 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7144 /* Allocate a struct bp_location. */
7146 static struct bp_location
*
7147 allocate_bp_location (struct breakpoint
*bpt
)
7149 return bpt
->ops
->allocate_location (bpt
);
7153 free_bp_location (struct bp_location
*loc
)
7155 loc
->ops
->dtor (loc
);
7159 /* Increment reference count. */
7162 incref_bp_location (struct bp_location
*bl
)
7167 /* Decrement reference count. If the reference count reaches 0,
7168 destroy the bp_location. Sets *BLP to NULL. */
7171 decref_bp_location (struct bp_location
**blp
)
7173 gdb_assert ((*blp
)->refc
> 0);
7175 if (--(*blp
)->refc
== 0)
7176 free_bp_location (*blp
);
7180 /* Add breakpoint B at the end of the global breakpoint chain. */
7183 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7185 struct breakpoint
*b1
;
7186 struct breakpoint
*result
= b
.get ();
7188 /* Add this breakpoint to the end of the chain so that a list of
7189 breakpoints will come out in order of increasing numbers. */
7191 b1
= breakpoint_chain
;
7193 breakpoint_chain
= b
.release ();
7198 b1
->next
= b
.release ();
7204 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7207 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7208 struct gdbarch
*gdbarch
,
7210 const struct breakpoint_ops
*ops
)
7212 gdb_assert (ops
!= NULL
);
7216 b
->gdbarch
= gdbarch
;
7217 b
->language
= current_language
->la_language
;
7218 b
->input_radix
= input_radix
;
7219 b
->related_breakpoint
= b
;
7222 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7223 that has type BPTYPE and has no locations as yet. */
7225 static struct breakpoint
*
7226 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7228 const struct breakpoint_ops
*ops
)
7230 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7232 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7233 return add_to_breakpoint_chain (std::move (b
));
7236 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7237 resolutions should be made as the user specified the location explicitly
7241 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7243 gdb_assert (loc
->owner
!= NULL
);
7245 if (loc
->owner
->type
== bp_breakpoint
7246 || loc
->owner
->type
== bp_hardware_breakpoint
7247 || is_tracepoint (loc
->owner
))
7250 const char *function_name
;
7251 CORE_ADDR func_addr
;
7253 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7254 &func_addr
, NULL
, &is_gnu_ifunc
);
7256 if (is_gnu_ifunc
&& !explicit_loc
)
7258 struct breakpoint
*b
= loc
->owner
;
7260 gdb_assert (loc
->pspace
== current_program_space
);
7261 if (gnu_ifunc_resolve_name (function_name
,
7262 &loc
->requested_address
))
7264 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7265 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7266 loc
->requested_address
,
7269 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7270 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7272 /* Create only the whole new breakpoint of this type but do not
7273 mess more complicated breakpoints with multiple locations. */
7274 b
->type
= bp_gnu_ifunc_resolver
;
7275 /* Remember the resolver's address for use by the return
7277 loc
->related_address
= func_addr
;
7282 loc
->function_name
= xstrdup (function_name
);
7286 /* Attempt to determine architecture of location identified by SAL. */
7288 get_sal_arch (struct symtab_and_line sal
)
7291 return get_objfile_arch (sal
.section
->objfile
);
7293 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7298 /* Low level routine for partially initializing a breakpoint of type
7299 BPTYPE. The newly created breakpoint's address, section, source
7300 file name, and line number are provided by SAL.
7302 It is expected that the caller will complete the initialization of
7303 the newly created breakpoint struct as well as output any status
7304 information regarding the creation of a new breakpoint. */
7307 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7308 struct symtab_and_line sal
, enum bptype bptype
,
7309 const struct breakpoint_ops
*ops
)
7311 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7313 add_location_to_breakpoint (b
, &sal
);
7315 if (bptype
!= bp_catchpoint
)
7316 gdb_assert (sal
.pspace
!= NULL
);
7318 /* Store the program space that was used to set the breakpoint,
7319 except for ordinary breakpoints, which are independent of the
7321 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7322 b
->pspace
= sal
.pspace
;
7325 /* set_raw_breakpoint is a low level routine for allocating and
7326 partially initializing a breakpoint of type BPTYPE. The newly
7327 created breakpoint's address, section, source file name, and line
7328 number are provided by SAL. The newly created and partially
7329 initialized breakpoint is added to the breakpoint chain and
7330 is also returned as the value of this function.
7332 It is expected that the caller will complete the initialization of
7333 the newly created breakpoint struct as well as output any status
7334 information regarding the creation of a new breakpoint. In
7335 particular, set_raw_breakpoint does NOT set the breakpoint
7336 number! Care should be taken to not allow an error to occur
7337 prior to completing the initialization of the breakpoint. If this
7338 should happen, a bogus breakpoint will be left on the chain. */
7341 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7342 struct symtab_and_line sal
, enum bptype bptype
,
7343 const struct breakpoint_ops
*ops
)
7345 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7347 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7348 return add_to_breakpoint_chain (std::move (b
));
7351 /* Call this routine when stepping and nexting to enable a breakpoint
7352 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7353 initiated the operation. */
7356 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7358 struct breakpoint
*b
, *b_tmp
;
7359 int thread
= tp
->global_num
;
7361 /* To avoid having to rescan all objfile symbols at every step,
7362 we maintain a list of continually-inserted but always disabled
7363 longjmp "master" breakpoints. Here, we simply create momentary
7364 clones of those and enable them for the requested thread. */
7365 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7366 if (b
->pspace
== current_program_space
7367 && (b
->type
== bp_longjmp_master
7368 || b
->type
== bp_exception_master
))
7370 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7371 struct breakpoint
*clone
;
7373 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7374 after their removal. */
7375 clone
= momentary_breakpoint_from_master (b
, type
,
7376 &momentary_breakpoint_ops
, 1);
7377 clone
->thread
= thread
;
7380 tp
->initiating_frame
= frame
;
7383 /* Delete all longjmp breakpoints from THREAD. */
7385 delete_longjmp_breakpoint (int thread
)
7387 struct breakpoint
*b
, *b_tmp
;
7389 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7390 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7392 if (b
->thread
== thread
)
7393 delete_breakpoint (b
);
7398 delete_longjmp_breakpoint_at_next_stop (int thread
)
7400 struct breakpoint
*b
, *b_tmp
;
7402 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7403 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7405 if (b
->thread
== thread
)
7406 b
->disposition
= disp_del_at_next_stop
;
7410 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7411 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7412 pointer to any of them. Return NULL if this system cannot place longjmp
7416 set_longjmp_breakpoint_for_call_dummy (void)
7418 struct breakpoint
*b
, *retval
= NULL
;
7421 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7423 struct breakpoint
*new_b
;
7425 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7426 &momentary_breakpoint_ops
,
7428 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7430 /* Link NEW_B into the chain of RETVAL breakpoints. */
7432 gdb_assert (new_b
->related_breakpoint
== new_b
);
7435 new_b
->related_breakpoint
= retval
;
7436 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7437 retval
= retval
->related_breakpoint
;
7438 retval
->related_breakpoint
= new_b
;
7444 /* Verify all existing dummy frames and their associated breakpoints for
7445 TP. Remove those which can no longer be found in the current frame
7448 You should call this function only at places where it is safe to currently
7449 unwind the whole stack. Failed stack unwind would discard live dummy
7453 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7455 struct breakpoint
*b
, *b_tmp
;
7457 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7458 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7460 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7462 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7463 dummy_b
= dummy_b
->related_breakpoint
;
7464 if (dummy_b
->type
!= bp_call_dummy
7465 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7468 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7470 while (b
->related_breakpoint
!= b
)
7472 if (b_tmp
== b
->related_breakpoint
)
7473 b_tmp
= b
->related_breakpoint
->next
;
7474 delete_breakpoint (b
->related_breakpoint
);
7476 delete_breakpoint (b
);
7481 enable_overlay_breakpoints (void)
7483 struct breakpoint
*b
;
7486 if (b
->type
== bp_overlay_event
)
7488 b
->enable_state
= bp_enabled
;
7489 update_global_location_list (UGLL_MAY_INSERT
);
7490 overlay_events_enabled
= 1;
7495 disable_overlay_breakpoints (void)
7497 struct breakpoint
*b
;
7500 if (b
->type
== bp_overlay_event
)
7502 b
->enable_state
= bp_disabled
;
7503 update_global_location_list (UGLL_DONT_INSERT
);
7504 overlay_events_enabled
= 0;
7508 /* Set an active std::terminate breakpoint for each std::terminate
7509 master breakpoint. */
7511 set_std_terminate_breakpoint (void)
7513 struct breakpoint
*b
, *b_tmp
;
7515 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7516 if (b
->pspace
== current_program_space
7517 && b
->type
== bp_std_terminate_master
)
7519 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7520 &momentary_breakpoint_ops
, 1);
7524 /* Delete all the std::terminate breakpoints. */
7526 delete_std_terminate_breakpoint (void)
7528 struct breakpoint
*b
, *b_tmp
;
7530 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7531 if (b
->type
== bp_std_terminate
)
7532 delete_breakpoint (b
);
7536 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7538 struct breakpoint
*b
;
7540 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7541 &internal_breakpoint_ops
);
7543 b
->enable_state
= bp_enabled
;
7544 /* location has to be used or breakpoint_re_set will delete me. */
7545 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7547 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7552 struct lang_and_radix
7558 /* Create a breakpoint for JIT code registration and unregistration. */
7561 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7563 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7564 &internal_breakpoint_ops
);
7567 /* Remove JIT code registration and unregistration breakpoint(s). */
7570 remove_jit_event_breakpoints (void)
7572 struct breakpoint
*b
, *b_tmp
;
7574 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7575 if (b
->type
== bp_jit_event
7576 && b
->loc
->pspace
== current_program_space
)
7577 delete_breakpoint (b
);
7581 remove_solib_event_breakpoints (void)
7583 struct breakpoint
*b
, *b_tmp
;
7585 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7586 if (b
->type
== bp_shlib_event
7587 && b
->loc
->pspace
== current_program_space
)
7588 delete_breakpoint (b
);
7591 /* See breakpoint.h. */
7594 remove_solib_event_breakpoints_at_next_stop (void)
7596 struct breakpoint
*b
, *b_tmp
;
7598 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7599 if (b
->type
== bp_shlib_event
7600 && b
->loc
->pspace
== current_program_space
)
7601 b
->disposition
= disp_del_at_next_stop
;
7604 /* Helper for create_solib_event_breakpoint /
7605 create_and_insert_solib_event_breakpoint. Allows specifying which
7606 INSERT_MODE to pass through to update_global_location_list. */
7608 static struct breakpoint
*
7609 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7610 enum ugll_insert_mode insert_mode
)
7612 struct breakpoint
*b
;
7614 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7615 &internal_breakpoint_ops
);
7616 update_global_location_list_nothrow (insert_mode
);
7621 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7623 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7626 /* See breakpoint.h. */
7629 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7631 struct breakpoint
*b
;
7633 /* Explicitly tell update_global_location_list to insert
7635 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7636 if (!b
->loc
->inserted
)
7638 delete_breakpoint (b
);
7644 /* Disable any breakpoints that are on code in shared libraries. Only
7645 apply to enabled breakpoints, disabled ones can just stay disabled. */
7648 disable_breakpoints_in_shlibs (void)
7650 struct bp_location
*loc
, **locp_tmp
;
7652 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7654 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7655 struct breakpoint
*b
= loc
->owner
;
7657 /* We apply the check to all breakpoints, including disabled for
7658 those with loc->duplicate set. This is so that when breakpoint
7659 becomes enabled, or the duplicate is removed, gdb will try to
7660 insert all breakpoints. If we don't set shlib_disabled here,
7661 we'll try to insert those breakpoints and fail. */
7662 if (((b
->type
== bp_breakpoint
)
7663 || (b
->type
== bp_jit_event
)
7664 || (b
->type
== bp_hardware_breakpoint
)
7665 || (is_tracepoint (b
)))
7666 && loc
->pspace
== current_program_space
7667 && !loc
->shlib_disabled
7668 && solib_name_from_address (loc
->pspace
, loc
->address
)
7671 loc
->shlib_disabled
= 1;
7676 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7677 notification of unloaded_shlib. Only apply to enabled breakpoints,
7678 disabled ones can just stay disabled. */
7681 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7683 struct bp_location
*loc
, **locp_tmp
;
7684 int disabled_shlib_breaks
= 0;
7686 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7688 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7689 struct breakpoint
*b
= loc
->owner
;
7691 if (solib
->pspace
== loc
->pspace
7692 && !loc
->shlib_disabled
7693 && (((b
->type
== bp_breakpoint
7694 || b
->type
== bp_jit_event
7695 || b
->type
== bp_hardware_breakpoint
)
7696 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7697 || loc
->loc_type
== bp_loc_software_breakpoint
))
7698 || is_tracepoint (b
))
7699 && solib_contains_address_p (solib
, loc
->address
))
7701 loc
->shlib_disabled
= 1;
7702 /* At this point, we cannot rely on remove_breakpoint
7703 succeeding so we must mark the breakpoint as not inserted
7704 to prevent future errors occurring in remove_breakpoints. */
7707 /* This may cause duplicate notifications for the same breakpoint. */
7708 observer_notify_breakpoint_modified (b
);
7710 if (!disabled_shlib_breaks
)
7712 target_terminal::ours_for_output ();
7713 warning (_("Temporarily disabling breakpoints "
7714 "for unloaded shared library \"%s\""),
7717 disabled_shlib_breaks
= 1;
7722 /* Disable any breakpoints and tracepoints in OBJFILE upon
7723 notification of free_objfile. Only apply to enabled breakpoints,
7724 disabled ones can just stay disabled. */
7727 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7729 struct breakpoint
*b
;
7731 if (objfile
== NULL
)
7734 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7735 managed by the user with add-symbol-file/remove-symbol-file.
7736 Similarly to how breakpoints in shared libraries are handled in
7737 response to "nosharedlibrary", mark breakpoints in such modules
7738 shlib_disabled so they end up uninserted on the next global
7739 location list update. Shared libraries not loaded by the user
7740 aren't handled here -- they're already handled in
7741 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7742 solib_unloaded observer. We skip objfiles that are not
7743 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7745 if ((objfile
->flags
& OBJF_SHARED
) == 0
7746 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7751 struct bp_location
*loc
;
7752 int bp_modified
= 0;
7754 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7757 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7759 CORE_ADDR loc_addr
= loc
->address
;
7761 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7762 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7765 if (loc
->shlib_disabled
!= 0)
7768 if (objfile
->pspace
!= loc
->pspace
)
7771 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7772 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7775 if (is_addr_in_objfile (loc_addr
, objfile
))
7777 loc
->shlib_disabled
= 1;
7778 /* At this point, we don't know whether the object was
7779 unmapped from the inferior or not, so leave the
7780 inserted flag alone. We'll handle failure to
7781 uninsert quietly, in case the object was indeed
7784 mark_breakpoint_location_modified (loc
);
7791 observer_notify_breakpoint_modified (b
);
7795 /* FORK & VFORK catchpoints. */
7797 /* An instance of this type is used to represent a fork or vfork
7798 catchpoint. A breakpoint is really of this type iff its ops pointer points
7799 to CATCH_FORK_BREAKPOINT_OPS. */
7801 struct fork_catchpoint
: public breakpoint
7803 /* Process id of a child process whose forking triggered this
7804 catchpoint. This field is only valid immediately after this
7805 catchpoint has triggered. */
7806 ptid_t forked_inferior_pid
;
7809 /* Implement the "insert" breakpoint_ops method for fork
7813 insert_catch_fork (struct bp_location
*bl
)
7815 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7818 /* Implement the "remove" breakpoint_ops method for fork
7822 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7824 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7827 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7831 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7832 const address_space
*aspace
, CORE_ADDR bp_addr
,
7833 const struct target_waitstatus
*ws
)
7835 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7837 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7840 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7844 /* Implement the "print_it" breakpoint_ops method for fork
7847 static enum print_stop_action
7848 print_it_catch_fork (bpstat bs
)
7850 struct ui_out
*uiout
= current_uiout
;
7851 struct breakpoint
*b
= bs
->breakpoint_at
;
7852 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7854 annotate_catchpoint (b
->number
);
7855 maybe_print_thread_hit_breakpoint (uiout
);
7856 if (b
->disposition
== disp_del
)
7857 uiout
->text ("Temporary catchpoint ");
7859 uiout
->text ("Catchpoint ");
7860 if (uiout
->is_mi_like_p ())
7862 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7863 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7865 uiout
->field_int ("bkptno", b
->number
);
7866 uiout
->text (" (forked process ");
7867 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
7868 uiout
->text ("), ");
7869 return PRINT_SRC_AND_LOC
;
7872 /* Implement the "print_one" breakpoint_ops method for fork
7876 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7878 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7879 struct value_print_options opts
;
7880 struct ui_out
*uiout
= current_uiout
;
7882 get_user_print_options (&opts
);
7884 /* Field 4, the address, is omitted (which makes the columns not
7885 line up too nicely with the headers, but the effect is relatively
7887 if (opts
.addressprint
)
7888 uiout
->field_skip ("addr");
7890 uiout
->text ("fork");
7891 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
7893 uiout
->text (", process ");
7894 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
7898 if (uiout
->is_mi_like_p ())
7899 uiout
->field_string ("catch-type", "fork");
7902 /* Implement the "print_mention" breakpoint_ops method for fork
7906 print_mention_catch_fork (struct breakpoint
*b
)
7908 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
7911 /* Implement the "print_recreate" breakpoint_ops method for fork
7915 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
7917 fprintf_unfiltered (fp
, "catch fork");
7918 print_recreate_thread (b
, fp
);
7921 /* The breakpoint_ops structure to be used in fork catchpoints. */
7923 static struct breakpoint_ops catch_fork_breakpoint_ops
;
7925 /* Implement the "insert" breakpoint_ops method for vfork
7929 insert_catch_vfork (struct bp_location
*bl
)
7931 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7934 /* Implement the "remove" breakpoint_ops method for vfork
7938 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7940 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
7943 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
7947 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
7948 const address_space
*aspace
, CORE_ADDR bp_addr
,
7949 const struct target_waitstatus
*ws
)
7951 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7953 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
7956 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7960 /* Implement the "print_it" breakpoint_ops method for vfork
7963 static enum print_stop_action
7964 print_it_catch_vfork (bpstat bs
)
7966 struct ui_out
*uiout
= current_uiout
;
7967 struct breakpoint
*b
= bs
->breakpoint_at
;
7968 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7970 annotate_catchpoint (b
->number
);
7971 maybe_print_thread_hit_breakpoint (uiout
);
7972 if (b
->disposition
== disp_del
)
7973 uiout
->text ("Temporary catchpoint ");
7975 uiout
->text ("Catchpoint ");
7976 if (uiout
->is_mi_like_p ())
7978 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
7979 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7981 uiout
->field_int ("bkptno", b
->number
);
7982 uiout
->text (" (vforked process ");
7983 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
7984 uiout
->text ("), ");
7985 return PRINT_SRC_AND_LOC
;
7988 /* Implement the "print_one" breakpoint_ops method for vfork
7992 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7994 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7995 struct value_print_options opts
;
7996 struct ui_out
*uiout
= current_uiout
;
7998 get_user_print_options (&opts
);
7999 /* Field 4, the address, is omitted (which makes the columns not
8000 line up too nicely with the headers, but the effect is relatively
8002 if (opts
.addressprint
)
8003 uiout
->field_skip ("addr");
8005 uiout
->text ("vfork");
8006 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8008 uiout
->text (", process ");
8009 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8013 if (uiout
->is_mi_like_p ())
8014 uiout
->field_string ("catch-type", "vfork");
8017 /* Implement the "print_mention" breakpoint_ops method for vfork
8021 print_mention_catch_vfork (struct breakpoint
*b
)
8023 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8026 /* Implement the "print_recreate" breakpoint_ops method for vfork
8030 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8032 fprintf_unfiltered (fp
, "catch vfork");
8033 print_recreate_thread (b
, fp
);
8036 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8038 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8040 /* An instance of this type is used to represent an solib catchpoint.
8041 A breakpoint is really of this type iff its ops pointer points to
8042 CATCH_SOLIB_BREAKPOINT_OPS. */
8044 struct solib_catchpoint
: public breakpoint
8046 ~solib_catchpoint () override
;
8048 /* True for "catch load", false for "catch unload". */
8049 unsigned char is_load
;
8051 /* Regular expression to match, if any. COMPILED is only valid when
8052 REGEX is non-NULL. */
8054 std::unique_ptr
<compiled_regex
> compiled
;
8057 solib_catchpoint::~solib_catchpoint ()
8059 xfree (this->regex
);
8063 insert_catch_solib (struct bp_location
*ignore
)
8069 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8075 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8076 const address_space
*aspace
,
8078 const struct target_waitstatus
*ws
)
8080 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8081 struct breakpoint
*other
;
8083 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8086 ALL_BREAKPOINTS (other
)
8088 struct bp_location
*other_bl
;
8090 if (other
== bl
->owner
)
8093 if (other
->type
!= bp_shlib_event
)
8096 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8099 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8101 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8110 check_status_catch_solib (struct bpstats
*bs
)
8112 struct solib_catchpoint
*self
8113 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8118 struct so_list
*iter
;
8121 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8126 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8135 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8140 || self
->compiled
->exec (iter
, 0, NULL
, 0) == 0)
8146 bs
->print_it
= print_it_noop
;
8149 static enum print_stop_action
8150 print_it_catch_solib (bpstat bs
)
8152 struct breakpoint
*b
= bs
->breakpoint_at
;
8153 struct ui_out
*uiout
= current_uiout
;
8155 annotate_catchpoint (b
->number
);
8156 maybe_print_thread_hit_breakpoint (uiout
);
8157 if (b
->disposition
== disp_del
)
8158 uiout
->text ("Temporary catchpoint ");
8160 uiout
->text ("Catchpoint ");
8161 uiout
->field_int ("bkptno", b
->number
);
8163 if (uiout
->is_mi_like_p ())
8164 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8165 print_solib_event (1);
8166 return PRINT_SRC_AND_LOC
;
8170 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8172 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8173 struct value_print_options opts
;
8174 struct ui_out
*uiout
= current_uiout
;
8177 get_user_print_options (&opts
);
8178 /* Field 4, the address, is omitted (which makes the columns not
8179 line up too nicely with the headers, but the effect is relatively
8181 if (opts
.addressprint
)
8184 uiout
->field_skip ("addr");
8191 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8193 msg
= xstrdup (_("load of library"));
8198 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8200 msg
= xstrdup (_("unload of library"));
8202 uiout
->field_string ("what", msg
);
8205 if (uiout
->is_mi_like_p ())
8206 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8210 print_mention_catch_solib (struct breakpoint
*b
)
8212 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8214 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8215 self
->is_load
? "load" : "unload");
8219 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8221 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8223 fprintf_unfiltered (fp
, "%s %s",
8224 b
->disposition
== disp_del
? "tcatch" : "catch",
8225 self
->is_load
? "load" : "unload");
8227 fprintf_unfiltered (fp
, " %s", self
->regex
);
8228 fprintf_unfiltered (fp
, "\n");
8231 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8233 /* Shared helper function (MI and CLI) for creating and installing
8234 a shared object event catchpoint. If IS_LOAD is non-zero then
8235 the events to be caught are load events, otherwise they are
8236 unload events. If IS_TEMP is non-zero the catchpoint is a
8237 temporary one. If ENABLED is non-zero the catchpoint is
8238 created in an enabled state. */
8241 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8243 struct gdbarch
*gdbarch
= get_current_arch ();
8247 arg
= skip_spaces (arg
);
8249 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8253 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8254 _("Invalid regexp")));
8255 c
->regex
= xstrdup (arg
);
8258 c
->is_load
= is_load
;
8259 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8260 &catch_solib_breakpoint_ops
);
8262 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8264 install_breakpoint (0, std::move (c
), 1);
8267 /* A helper function that does all the work for "catch load" and
8271 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8272 struct cmd_list_element
*command
)
8275 const int enabled
= 1;
8277 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8279 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8283 catch_load_command_1 (char *arg
, int from_tty
,
8284 struct cmd_list_element
*command
)
8286 catch_load_or_unload (arg
, from_tty
, 1, command
);
8290 catch_unload_command_1 (char *arg
, int from_tty
,
8291 struct cmd_list_element
*command
)
8293 catch_load_or_unload (arg
, from_tty
, 0, command
);
8296 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8297 is non-zero, then make the breakpoint temporary. If COND_STRING is
8298 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8299 the breakpoint_ops structure associated to the catchpoint. */
8302 init_catchpoint (struct breakpoint
*b
,
8303 struct gdbarch
*gdbarch
, int tempflag
,
8304 const char *cond_string
,
8305 const struct breakpoint_ops
*ops
)
8307 symtab_and_line sal
;
8308 sal
.pspace
= current_program_space
;
8310 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8312 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8313 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8317 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8319 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8320 set_breakpoint_number (internal
, b
);
8321 if (is_tracepoint (b
))
8322 set_tracepoint_count (breakpoint_count
);
8325 observer_notify_breakpoint_created (b
);
8328 update_global_location_list (UGLL_MAY_INSERT
);
8332 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8333 int tempflag
, const char *cond_string
,
8334 const struct breakpoint_ops
*ops
)
8336 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8338 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8340 c
->forked_inferior_pid
= null_ptid
;
8342 install_breakpoint (0, std::move (c
), 1);
8345 /* Exec catchpoints. */
8347 /* An instance of this type is used to represent an exec catchpoint.
8348 A breakpoint is really of this type iff its ops pointer points to
8349 CATCH_EXEC_BREAKPOINT_OPS. */
8351 struct exec_catchpoint
: public breakpoint
8353 ~exec_catchpoint () override
;
8355 /* Filename of a program whose exec triggered this catchpoint.
8356 This field is only valid immediately after this catchpoint has
8358 char *exec_pathname
;
8361 /* Exec catchpoint destructor. */
8363 exec_catchpoint::~exec_catchpoint ()
8365 xfree (this->exec_pathname
);
8369 insert_catch_exec (struct bp_location
*bl
)
8371 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8375 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8377 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8381 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8382 const address_space
*aspace
, CORE_ADDR bp_addr
,
8383 const struct target_waitstatus
*ws
)
8385 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8387 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8390 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8394 static enum print_stop_action
8395 print_it_catch_exec (bpstat bs
)
8397 struct ui_out
*uiout
= current_uiout
;
8398 struct breakpoint
*b
= bs
->breakpoint_at
;
8399 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8401 annotate_catchpoint (b
->number
);
8402 maybe_print_thread_hit_breakpoint (uiout
);
8403 if (b
->disposition
== disp_del
)
8404 uiout
->text ("Temporary catchpoint ");
8406 uiout
->text ("Catchpoint ");
8407 if (uiout
->is_mi_like_p ())
8409 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8410 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8412 uiout
->field_int ("bkptno", b
->number
);
8413 uiout
->text (" (exec'd ");
8414 uiout
->field_string ("new-exec", c
->exec_pathname
);
8415 uiout
->text ("), ");
8417 return PRINT_SRC_AND_LOC
;
8421 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8423 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8424 struct value_print_options opts
;
8425 struct ui_out
*uiout
= current_uiout
;
8427 get_user_print_options (&opts
);
8429 /* Field 4, the address, is omitted (which makes the columns
8430 not line up too nicely with the headers, but the effect
8431 is relatively readable). */
8432 if (opts
.addressprint
)
8433 uiout
->field_skip ("addr");
8435 uiout
->text ("exec");
8436 if (c
->exec_pathname
!= NULL
)
8438 uiout
->text (", program \"");
8439 uiout
->field_string ("what", c
->exec_pathname
);
8440 uiout
->text ("\" ");
8443 if (uiout
->is_mi_like_p ())
8444 uiout
->field_string ("catch-type", "exec");
8448 print_mention_catch_exec (struct breakpoint
*b
)
8450 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8453 /* Implement the "print_recreate" breakpoint_ops method for exec
8457 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8459 fprintf_unfiltered (fp
, "catch exec");
8460 print_recreate_thread (b
, fp
);
8463 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8466 hw_breakpoint_used_count (void)
8469 struct breakpoint
*b
;
8470 struct bp_location
*bl
;
8474 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8475 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8477 /* Special types of hardware breakpoints may use more than
8479 i
+= b
->ops
->resources_needed (bl
);
8486 /* Returns the resources B would use if it were a hardware
8490 hw_watchpoint_use_count (struct breakpoint
*b
)
8493 struct bp_location
*bl
;
8495 if (!breakpoint_enabled (b
))
8498 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8500 /* Special types of hardware watchpoints may use more than
8502 i
+= b
->ops
->resources_needed (bl
);
8508 /* Returns the sum the used resources of all hardware watchpoints of
8509 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8510 the sum of the used resources of all hardware watchpoints of other
8511 types _not_ TYPE. */
8514 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8515 enum bptype type
, int *other_type_used
)
8518 struct breakpoint
*b
;
8520 *other_type_used
= 0;
8525 if (!breakpoint_enabled (b
))
8528 if (b
->type
== type
)
8529 i
+= hw_watchpoint_use_count (b
);
8530 else if (is_hardware_watchpoint (b
))
8531 *other_type_used
= 1;
8538 disable_watchpoints_before_interactive_call_start (void)
8540 struct breakpoint
*b
;
8544 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8546 b
->enable_state
= bp_call_disabled
;
8547 update_global_location_list (UGLL_DONT_INSERT
);
8553 enable_watchpoints_after_interactive_call_stop (void)
8555 struct breakpoint
*b
;
8559 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8561 b
->enable_state
= bp_enabled
;
8562 update_global_location_list (UGLL_MAY_INSERT
);
8568 disable_breakpoints_before_startup (void)
8570 current_program_space
->executing_startup
= 1;
8571 update_global_location_list (UGLL_DONT_INSERT
);
8575 enable_breakpoints_after_startup (void)
8577 current_program_space
->executing_startup
= 0;
8578 breakpoint_re_set ();
8581 /* Create a new single-step breakpoint for thread THREAD, with no
8584 static struct breakpoint
*
8585 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8587 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8589 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8590 &momentary_breakpoint_ops
);
8592 b
->disposition
= disp_donttouch
;
8593 b
->frame_id
= null_frame_id
;
8596 gdb_assert (b
->thread
!= 0);
8598 return add_to_breakpoint_chain (std::move (b
));
8601 /* Set a momentary breakpoint of type TYPE at address specified by
8602 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8606 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8607 struct frame_id frame_id
, enum bptype type
)
8609 struct breakpoint
*b
;
8611 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8613 gdb_assert (!frame_id_artificial_p (frame_id
));
8615 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8616 b
->enable_state
= bp_enabled
;
8617 b
->disposition
= disp_donttouch
;
8618 b
->frame_id
= frame_id
;
8620 /* If we're debugging a multi-threaded program, then we want
8621 momentary breakpoints to be active in only a single thread of
8623 if (in_thread_list (inferior_ptid
))
8624 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8626 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8631 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8632 The new breakpoint will have type TYPE, use OPS as its
8633 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8635 static struct breakpoint
*
8636 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8638 const struct breakpoint_ops
*ops
,
8641 struct breakpoint
*copy
;
8643 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8644 copy
->loc
= allocate_bp_location (copy
);
8645 set_breakpoint_location_function (copy
->loc
, 1);
8647 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8648 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8649 copy
->loc
->address
= orig
->loc
->address
;
8650 copy
->loc
->section
= orig
->loc
->section
;
8651 copy
->loc
->pspace
= orig
->loc
->pspace
;
8652 copy
->loc
->probe
= orig
->loc
->probe
;
8653 copy
->loc
->line_number
= orig
->loc
->line_number
;
8654 copy
->loc
->symtab
= orig
->loc
->symtab
;
8655 copy
->loc
->enabled
= loc_enabled
;
8656 copy
->frame_id
= orig
->frame_id
;
8657 copy
->thread
= orig
->thread
;
8658 copy
->pspace
= orig
->pspace
;
8660 copy
->enable_state
= bp_enabled
;
8661 copy
->disposition
= disp_donttouch
;
8662 copy
->number
= internal_breakpoint_number
--;
8664 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8668 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8672 clone_momentary_breakpoint (struct breakpoint
*orig
)
8674 /* If there's nothing to clone, then return nothing. */
8678 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8682 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8685 struct symtab_and_line sal
;
8687 sal
= find_pc_line (pc
, 0);
8689 sal
.section
= find_pc_overlay (pc
);
8690 sal
.explicit_pc
= 1;
8692 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8696 /* Tell the user we have just set a breakpoint B. */
8699 mention (struct breakpoint
*b
)
8701 b
->ops
->print_mention (b
);
8702 if (current_uiout
->is_mi_like_p ())
8704 printf_filtered ("\n");
8708 static int bp_loc_is_permanent (struct bp_location
*loc
);
8710 static struct bp_location
*
8711 add_location_to_breakpoint (struct breakpoint
*b
,
8712 const struct symtab_and_line
*sal
)
8714 struct bp_location
*loc
, **tmp
;
8715 CORE_ADDR adjusted_address
;
8716 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8718 if (loc_gdbarch
== NULL
)
8719 loc_gdbarch
= b
->gdbarch
;
8721 /* Adjust the breakpoint's address prior to allocating a location.
8722 Once we call allocate_bp_location(), that mostly uninitialized
8723 location will be placed on the location chain. Adjustment of the
8724 breakpoint may cause target_read_memory() to be called and we do
8725 not want its scan of the location chain to find a breakpoint and
8726 location that's only been partially initialized. */
8727 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8730 /* Sort the locations by their ADDRESS. */
8731 loc
= allocate_bp_location (b
);
8732 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8733 tmp
= &((*tmp
)->next
))
8738 loc
->requested_address
= sal
->pc
;
8739 loc
->address
= adjusted_address
;
8740 loc
->pspace
= sal
->pspace
;
8741 loc
->probe
.probe
= sal
->probe
;
8742 loc
->probe
.objfile
= sal
->objfile
;
8743 gdb_assert (loc
->pspace
!= NULL
);
8744 loc
->section
= sal
->section
;
8745 loc
->gdbarch
= loc_gdbarch
;
8746 loc
->line_number
= sal
->line
;
8747 loc
->symtab
= sal
->symtab
;
8748 loc
->symbol
= sal
->symbol
;
8750 set_breakpoint_location_function (loc
,
8751 sal
->explicit_pc
|| sal
->explicit_line
);
8753 /* While by definition, permanent breakpoints are already present in the
8754 code, we don't mark the location as inserted. Normally one would expect
8755 that GDB could rely on that breakpoint instruction to stop the program,
8756 thus removing the need to insert its own breakpoint, except that executing
8757 the breakpoint instruction can kill the target instead of reporting a
8758 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8759 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8760 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8761 breakpoint be inserted normally results in QEMU knowing about the GDB
8762 breakpoint, and thus trap before the breakpoint instruction is executed.
8763 (If GDB later needs to continue execution past the permanent breakpoint,
8764 it manually increments the PC, thus avoiding executing the breakpoint
8766 if (bp_loc_is_permanent (loc
))
8773 /* See breakpoint.h. */
8776 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8780 const gdb_byte
*bpoint
;
8781 gdb_byte
*target_mem
;
8784 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8786 /* Software breakpoints unsupported? */
8790 target_mem
= (gdb_byte
*) alloca (len
);
8792 /* Enable the automatic memory restoration from breakpoints while
8793 we read the memory. Otherwise we could say about our temporary
8794 breakpoints they are permanent. */
8795 scoped_restore restore_memory
8796 = make_scoped_restore_show_memory_breakpoints (0);
8798 if (target_read_memory (address
, target_mem
, len
) == 0
8799 && memcmp (target_mem
, bpoint
, len
) == 0)
8805 /* Return 1 if LOC is pointing to a permanent breakpoint,
8806 return 0 otherwise. */
8809 bp_loc_is_permanent (struct bp_location
*loc
)
8811 gdb_assert (loc
!= NULL
);
8813 /* If we have a catchpoint or a watchpoint, just return 0. We should not
8814 attempt to read from the addresses the locations of these breakpoint types
8815 point to. program_breakpoint_here_p, below, will attempt to read
8817 if (!breakpoint_address_is_meaningful (loc
->owner
))
8820 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8821 switch_to_program_space_and_thread (loc
->pspace
);
8822 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8825 /* Build a command list for the dprintf corresponding to the current
8826 settings of the dprintf style options. */
8829 update_dprintf_command_list (struct breakpoint
*b
)
8831 char *dprintf_args
= b
->extra_string
;
8832 char *printf_line
= NULL
;
8837 dprintf_args
= skip_spaces (dprintf_args
);
8839 /* Allow a comma, as it may have terminated a location, but don't
8841 if (*dprintf_args
== ',')
8843 dprintf_args
= skip_spaces (dprintf_args
);
8845 if (*dprintf_args
!= '"')
8846 error (_("Bad format string, missing '\"'."));
8848 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8849 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8850 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8852 if (!dprintf_function
)
8853 error (_("No function supplied for dprintf call"));
8855 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8856 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8861 printf_line
= xstrprintf ("call (void) %s (%s)",
8865 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8867 if (target_can_run_breakpoint_commands ())
8868 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8871 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8872 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8876 internal_error (__FILE__
, __LINE__
,
8877 _("Invalid dprintf style."));
8879 gdb_assert (printf_line
!= NULL
);
8880 /* Manufacture a printf sequence. */
8882 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
8884 printf_cmd_line
->control_type
= simple_control
;
8885 printf_cmd_line
->body_count
= 0;
8886 printf_cmd_line
->body_list
= NULL
;
8887 printf_cmd_line
->next
= NULL
;
8888 printf_cmd_line
->line
= printf_line
;
8890 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
8894 /* Update all dprintf commands, making their command lists reflect
8895 current style settings. */
8898 update_dprintf_commands (char *args
, int from_tty
,
8899 struct cmd_list_element
*c
)
8901 struct breakpoint
*b
;
8905 if (b
->type
== bp_dprintf
)
8906 update_dprintf_command_list (b
);
8910 /* Create a breakpoint with SAL as location. Use LOCATION
8911 as a description of the location, and COND_STRING
8912 as condition expression. If LOCATION is NULL then create an
8913 "address location" from the address in the SAL. */
8916 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
8917 gdb::array_view
<const symtab_and_line
> sals
,
8918 event_location_up
&&location
,
8919 gdb::unique_xmalloc_ptr
<char> filter
,
8920 gdb::unique_xmalloc_ptr
<char> cond_string
,
8921 gdb::unique_xmalloc_ptr
<char> extra_string
,
8922 enum bptype type
, enum bpdisp disposition
,
8923 int thread
, int task
, int ignore_count
,
8924 const struct breakpoint_ops
*ops
, int from_tty
,
8925 int enabled
, int internal
, unsigned flags
,
8926 int display_canonical
)
8930 if (type
== bp_hardware_breakpoint
)
8932 int target_resources_ok
;
8934 i
= hw_breakpoint_used_count ();
8935 target_resources_ok
=
8936 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
8938 if (target_resources_ok
== 0)
8939 error (_("No hardware breakpoint support in the target."));
8940 else if (target_resources_ok
< 0)
8941 error (_("Hardware breakpoints used exceeds limit."));
8944 gdb_assert (!sals
.empty ());
8946 for (const auto &sal
: sals
)
8948 struct bp_location
*loc
;
8952 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8954 loc_gdbarch
= gdbarch
;
8956 describe_other_breakpoints (loc_gdbarch
,
8957 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
8960 if (&sal
== &sals
[0])
8962 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
8966 b
->cond_string
= cond_string
.release ();
8967 b
->extra_string
= extra_string
.release ();
8968 b
->ignore_count
= ignore_count
;
8969 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8970 b
->disposition
= disposition
;
8972 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
8973 b
->loc
->inserted
= 1;
8975 if (type
== bp_static_tracepoint
)
8977 struct tracepoint
*t
= (struct tracepoint
*) b
;
8978 struct static_tracepoint_marker marker
;
8980 if (strace_marker_p (b
))
8982 /* We already know the marker exists, otherwise, we
8983 wouldn't see a sal for it. */
8985 = &event_location_to_string (b
->location
.get ())[3];
8989 p
= skip_spaces (p
);
8991 endp
= skip_to_space (p
);
8993 marker_str
= savestring (p
, endp
- p
);
8994 t
->static_trace_marker_id
= marker_str
;
8996 printf_filtered (_("Probed static tracepoint "
8998 t
->static_trace_marker_id
);
9000 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9002 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9003 release_static_tracepoint_marker (&marker
);
9005 printf_filtered (_("Probed static tracepoint "
9007 t
->static_trace_marker_id
);
9010 warning (_("Couldn't determine the static "
9011 "tracepoint marker to probe"));
9018 loc
= add_location_to_breakpoint (b
, &sal
);
9019 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9025 const char *arg
= b
->cond_string
;
9027 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9028 block_for_pc (loc
->address
), 0);
9030 error (_("Garbage '%s' follows condition"), arg
);
9033 /* Dynamic printf requires and uses additional arguments on the
9034 command line, otherwise it's an error. */
9035 if (type
== bp_dprintf
)
9037 if (b
->extra_string
)
9038 update_dprintf_command_list (b
);
9040 error (_("Format string required"));
9042 else if (b
->extra_string
)
9043 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9046 b
->display_canonical
= display_canonical
;
9047 if (location
!= NULL
)
9048 b
->location
= std::move (location
);
9050 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9051 b
->filter
= filter
.release ();
9055 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9056 gdb::array_view
<const symtab_and_line
> sals
,
9057 event_location_up
&&location
,
9058 gdb::unique_xmalloc_ptr
<char> filter
,
9059 gdb::unique_xmalloc_ptr
<char> cond_string
,
9060 gdb::unique_xmalloc_ptr
<char> extra_string
,
9061 enum bptype type
, enum bpdisp disposition
,
9062 int thread
, int task
, int ignore_count
,
9063 const struct breakpoint_ops
*ops
, int from_tty
,
9064 int enabled
, int internal
, unsigned flags
,
9065 int display_canonical
)
9067 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9069 init_breakpoint_sal (b
.get (), gdbarch
,
9070 sals
, std::move (location
),
9072 std::move (cond_string
),
9073 std::move (extra_string
),
9075 thread
, task
, ignore_count
,
9077 enabled
, internal
, flags
,
9080 install_breakpoint (internal
, std::move (b
), 0);
9083 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9084 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9085 value. COND_STRING, if not NULL, specified the condition to be
9086 used for all breakpoints. Essentially the only case where
9087 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9088 function. In that case, it's still not possible to specify
9089 separate conditions for different overloaded functions, so
9090 we take just a single condition string.
9092 NOTE: If the function succeeds, the caller is expected to cleanup
9093 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9094 array contents). If the function fails (error() is called), the
9095 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9096 COND and SALS arrays and each of those arrays contents. */
9099 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9100 struct linespec_result
*canonical
,
9101 gdb::unique_xmalloc_ptr
<char> cond_string
,
9102 gdb::unique_xmalloc_ptr
<char> extra_string
,
9103 enum bptype type
, enum bpdisp disposition
,
9104 int thread
, int task
, int ignore_count
,
9105 const struct breakpoint_ops
*ops
, int from_tty
,
9106 int enabled
, int internal
, unsigned flags
)
9108 if (canonical
->pre_expanded
)
9109 gdb_assert (canonical
->lsals
.size () == 1);
9111 for (const auto &lsal
: canonical
->lsals
)
9113 /* Note that 'location' can be NULL in the case of a plain
9114 'break', without arguments. */
9115 event_location_up location
9116 = (canonical
->location
!= NULL
9117 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9118 gdb::unique_xmalloc_ptr
<char> filter_string
9119 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9121 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9122 std::move (location
),
9123 std::move (filter_string
),
9124 std::move (cond_string
),
9125 std::move (extra_string
),
9127 thread
, task
, ignore_count
, ops
,
9128 from_tty
, enabled
, internal
, flags
,
9129 canonical
->special_display
);
9133 /* Parse LOCATION which is assumed to be a SAL specification possibly
9134 followed by conditionals. On return, SALS contains an array of SAL
9135 addresses found. LOCATION points to the end of the SAL (for
9136 linespec locations).
9138 The array and the line spec strings are allocated on the heap, it is
9139 the caller's responsibility to free them. */
9142 parse_breakpoint_sals (const struct event_location
*location
,
9143 struct linespec_result
*canonical
)
9145 struct symtab_and_line cursal
;
9147 if (event_location_type (location
) == LINESPEC_LOCATION
)
9149 const char *address
= get_linespec_location (location
);
9151 if (address
== NULL
)
9153 /* The last displayed codepoint, if it's valid, is our default
9154 breakpoint address. */
9155 if (last_displayed_sal_is_valid ())
9157 /* Set sal's pspace, pc, symtab, and line to the values
9158 corresponding to the last call to print_frame_info.
9159 Be sure to reinitialize LINE with NOTCURRENT == 0
9160 as the breakpoint line number is inappropriate otherwise.
9161 find_pc_line would adjust PC, re-set it back. */
9162 symtab_and_line sal
= get_last_displayed_sal ();
9163 CORE_ADDR pc
= sal
.pc
;
9165 sal
= find_pc_line (pc
, 0);
9167 /* "break" without arguments is equivalent to "break *PC"
9168 where PC is the last displayed codepoint's address. So
9169 make sure to set sal.explicit_pc to prevent GDB from
9170 trying to expand the list of sals to include all other
9171 instances with the same symtab and line. */
9173 sal
.explicit_pc
= 1;
9175 struct linespec_sals lsal
;
9177 lsal
.canonical
= NULL
;
9179 canonical
->lsals
.push_back (std::move (lsal
));
9183 error (_("No default breakpoint address now."));
9187 /* Force almost all breakpoints to be in terms of the
9188 current_source_symtab (which is decode_line_1's default).
9189 This should produce the results we want almost all of the
9190 time while leaving default_breakpoint_* alone.
9192 ObjC: However, don't match an Objective-C method name which
9193 may have a '+' or '-' succeeded by a '['. */
9194 cursal
= get_current_source_symtab_and_line ();
9195 if (last_displayed_sal_is_valid ())
9197 const char *address
= NULL
;
9199 if (event_location_type (location
) == LINESPEC_LOCATION
)
9200 address
= get_linespec_location (location
);
9204 && strchr ("+-", address
[0]) != NULL
9205 && address
[1] != '['))
9207 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9208 get_last_displayed_symtab (),
9209 get_last_displayed_line (),
9210 canonical
, NULL
, NULL
);
9215 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9216 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9220 /* Convert each SAL into a real PC. Verify that the PC can be
9221 inserted as a breakpoint. If it can't throw an error. */
9224 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9226 for (auto &sal
: sals
)
9227 resolve_sal_pc (&sal
);
9230 /* Fast tracepoints may have restrictions on valid locations. For
9231 instance, a fast tracepoint using a jump instead of a trap will
9232 likely have to overwrite more bytes than a trap would, and so can
9233 only be placed where the instruction is longer than the jump, or a
9234 multi-instruction sequence does not have a jump into the middle of
9238 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9239 gdb::array_view
<const symtab_and_line
> sals
)
9243 struct cleanup
*old_chain
;
9245 for (const auto &sal
: sals
)
9247 struct gdbarch
*sarch
;
9249 sarch
= get_sal_arch (sal
);
9250 /* We fall back to GDBARCH if there is no architecture
9251 associated with SAL. */
9254 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
);
9255 old_chain
= make_cleanup (xfree
, msg
);
9258 error (_("May not have a fast tracepoint at %s%s"),
9259 paddress (sarch
, sal
.pc
), (msg
? msg
: ""));
9261 do_cleanups (old_chain
);
9265 /* Given TOK, a string specification of condition and thread, as
9266 accepted by the 'break' command, extract the condition
9267 string and thread number and set *COND_STRING and *THREAD.
9268 PC identifies the context at which the condition should be parsed.
9269 If no condition is found, *COND_STRING is set to NULL.
9270 If no thread is found, *THREAD is set to -1. */
9273 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9274 char **cond_string
, int *thread
, int *task
,
9277 *cond_string
= NULL
;
9284 const char *end_tok
;
9286 const char *cond_start
= NULL
;
9287 const char *cond_end
= NULL
;
9289 tok
= skip_spaces (tok
);
9291 if ((*tok
== '"' || *tok
== ',') && rest
)
9293 *rest
= savestring (tok
, strlen (tok
));
9297 end_tok
= skip_to_space (tok
);
9299 toklen
= end_tok
- tok
;
9301 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9303 tok
= cond_start
= end_tok
+ 1;
9304 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9306 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9308 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9311 struct thread_info
*thr
;
9314 thr
= parse_thread_id (tok
, &tmptok
);
9316 error (_("Junk after thread keyword."));
9317 *thread
= thr
->global_num
;
9320 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9325 *task
= strtol (tok
, &tmptok
, 0);
9327 error (_("Junk after task keyword."));
9328 if (!valid_task_id (*task
))
9329 error (_("Unknown task %d."), *task
);
9334 *rest
= savestring (tok
, strlen (tok
));
9338 error (_("Junk at end of arguments."));
9342 /* Decode a static tracepoint marker spec. */
9344 static std::vector
<symtab_and_line
>
9345 decode_static_tracepoint_spec (const char **arg_p
)
9347 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9348 const char *p
= &(*arg_p
)[3];
9352 p
= skip_spaces (p
);
9354 endp
= skip_to_space (p
);
9356 std::string
marker_str (p
, endp
- p
);
9358 markers
= target_static_tracepoint_markers_by_strid (marker_str
.c_str ());
9359 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9360 error (_("No known static tracepoint marker named %s"),
9361 marker_str
.c_str ());
9363 std::vector
<symtab_and_line
> sals
;
9364 sals
.reserve (VEC_length(static_tracepoint_marker_p
, markers
));
9366 for (i
= 0; i
< VEC_length(static_tracepoint_marker_p
, markers
); i
++)
9368 struct static_tracepoint_marker
*marker
;
9370 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9372 symtab_and_line sal
= find_pc_line (marker
->address
, 0);
9373 sal
.pc
= marker
->address
;
9374 sals
.push_back (sal
);
9376 release_static_tracepoint_marker (marker
);
9383 /* See breakpoint.h. */
9386 create_breakpoint (struct gdbarch
*gdbarch
,
9387 const struct event_location
*location
,
9388 const char *cond_string
,
9389 int thread
, const char *extra_string
,
9391 int tempflag
, enum bptype type_wanted
,
9393 enum auto_boolean pending_break_support
,
9394 const struct breakpoint_ops
*ops
,
9395 int from_tty
, int enabled
, int internal
,
9398 struct linespec_result canonical
;
9399 struct cleanup
*bkpt_chain
= NULL
;
9402 int prev_bkpt_count
= breakpoint_count
;
9404 gdb_assert (ops
!= NULL
);
9406 /* If extra_string isn't useful, set it to NULL. */
9407 if (extra_string
!= NULL
&& *extra_string
== '\0')
9408 extra_string
= NULL
;
9412 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9414 CATCH (e
, RETURN_MASK_ERROR
)
9416 /* If caller is interested in rc value from parse, set
9418 if (e
.error
== NOT_FOUND_ERROR
)
9420 /* If pending breakpoint support is turned off, throw
9423 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9424 throw_exception (e
);
9426 exception_print (gdb_stderr
, e
);
9428 /* If pending breakpoint support is auto query and the user
9429 selects no, then simply return the error code. */
9430 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9431 && !nquery (_("Make %s pending on future shared library load? "),
9432 bptype_string (type_wanted
)))
9435 /* At this point, either the user was queried about setting
9436 a pending breakpoint and selected yes, or pending
9437 breakpoint behavior is on and thus a pending breakpoint
9438 is defaulted on behalf of the user. */
9442 throw_exception (e
);
9446 if (!pending
&& canonical
.lsals
.empty ())
9449 /* ----------------------------- SNIP -----------------------------
9450 Anything added to the cleanup chain beyond this point is assumed
9451 to be part of a breakpoint. If the breakpoint create succeeds
9452 then the memory is not reclaimed. */
9453 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9455 /* Resolve all line numbers to PC's and verify that the addresses
9456 are ok for the target. */
9459 for (auto &lsal
: canonical
.lsals
)
9460 breakpoint_sals_to_pc (lsal
.sals
);
9463 /* Fast tracepoints may have additional restrictions on location. */
9464 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9466 for (const auto &lsal
: canonical
.lsals
)
9467 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9470 /* Verify that condition can be parsed, before setting any
9471 breakpoints. Allocate a separate condition expression for each
9475 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9476 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9483 const linespec_sals
&lsal
= canonical
.lsals
[0];
9485 /* Here we only parse 'arg' to separate condition
9486 from thread number, so parsing in context of first
9487 sal is OK. When setting the breakpoint we'll
9488 re-parse it in context of each sal. */
9490 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9491 &cond
, &thread
, &task
, &rest
);
9492 cond_string_copy
.reset (cond
);
9493 extra_string_copy
.reset (rest
);
9497 if (type_wanted
!= bp_dprintf
9498 && extra_string
!= NULL
&& *extra_string
!= '\0')
9499 error (_("Garbage '%s' at end of location"), extra_string
);
9501 /* Create a private copy of condition string. */
9503 cond_string_copy
.reset (xstrdup (cond_string
));
9504 /* Create a private copy of any extra string. */
9506 extra_string_copy
.reset (xstrdup (extra_string
));
9509 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9510 std::move (cond_string_copy
),
9511 std::move (extra_string_copy
),
9513 tempflag
? disp_del
: disp_donttouch
,
9514 thread
, task
, ignore_count
, ops
,
9515 from_tty
, enabled
, internal
, flags
);
9519 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9521 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9522 b
->location
= copy_event_location (location
);
9525 b
->cond_string
= NULL
;
9528 /* Create a private copy of condition string. */
9529 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9533 /* Create a private copy of any extra string. */
9534 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9535 b
->ignore_count
= ignore_count
;
9536 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9537 b
->condition_not_parsed
= 1;
9538 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9539 if ((type_wanted
!= bp_breakpoint
9540 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9541 b
->pspace
= current_program_space
;
9543 install_breakpoint (internal
, std::move (b
), 0);
9546 if (canonical
.lsals
.size () > 1)
9548 warning (_("Multiple breakpoints were set.\nUse the "
9549 "\"delete\" command to delete unwanted breakpoints."));
9550 prev_breakpoint_count
= prev_bkpt_count
;
9553 /* That's it. Discard the cleanups for data inserted into the
9555 discard_cleanups (bkpt_chain
);
9557 /* error call may happen here - have BKPT_CHAIN already discarded. */
9558 update_global_location_list (UGLL_MAY_INSERT
);
9563 /* Set a breakpoint.
9564 ARG is a string describing breakpoint address,
9565 condition, and thread.
9566 FLAG specifies if a breakpoint is hardware on,
9567 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9571 break_command_1 (const char *arg
, int flag
, int from_tty
)
9573 int tempflag
= flag
& BP_TEMPFLAG
;
9574 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9575 ? bp_hardware_breakpoint
9577 struct breakpoint_ops
*ops
;
9579 event_location_up location
= string_to_event_location (&arg
, current_language
);
9581 /* Matching breakpoints on probes. */
9582 if (location
!= NULL
9583 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9584 ops
= &bkpt_probe_breakpoint_ops
;
9586 ops
= &bkpt_breakpoint_ops
;
9588 create_breakpoint (get_current_arch (),
9590 NULL
, 0, arg
, 1 /* parse arg */,
9591 tempflag
, type_wanted
,
9592 0 /* Ignore count */,
9593 pending_break_support
,
9601 /* Helper function for break_command_1 and disassemble_command. */
9604 resolve_sal_pc (struct symtab_and_line
*sal
)
9608 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9610 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9611 error (_("No line %d in file \"%s\"."),
9612 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9615 /* If this SAL corresponds to a breakpoint inserted using a line
9616 number, then skip the function prologue if necessary. */
9617 if (sal
->explicit_line
)
9618 skip_prologue_sal (sal
);
9621 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9623 const struct blockvector
*bv
;
9624 const struct block
*b
;
9627 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9628 SYMTAB_COMPUNIT (sal
->symtab
));
9631 sym
= block_linkage_function (b
);
9634 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9635 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9640 /* It really is worthwhile to have the section, so we'll
9641 just have to look harder. This case can be executed
9642 if we have line numbers but no functions (as can
9643 happen in assembly source). */
9645 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9646 switch_to_program_space_and_thread (sal
->pspace
);
9648 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9650 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9657 break_command (char *arg
, int from_tty
)
9659 break_command_1 (arg
, 0, from_tty
);
9663 tbreak_command (char *arg
, int from_tty
)
9665 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9669 hbreak_command (char *arg
, int from_tty
)
9671 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9675 thbreak_command (char *arg
, int from_tty
)
9677 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9681 stop_command (char *arg
, int from_tty
)
9683 printf_filtered (_("Specify the type of breakpoint to set.\n\
9684 Usage: stop in <function | address>\n\
9685 stop at <line>\n"));
9689 stopin_command (const char *arg
, int from_tty
)
9693 if (arg
== (char *) NULL
)
9695 else if (*arg
!= '*')
9697 const char *argptr
= arg
;
9700 /* Look for a ':'. If this is a line number specification, then
9701 say it is bad, otherwise, it should be an address or
9702 function/method name. */
9703 while (*argptr
&& !hasColon
)
9705 hasColon
= (*argptr
== ':');
9710 badInput
= (*argptr
!= ':'); /* Not a class::method */
9712 badInput
= isdigit (*arg
); /* a simple line number */
9716 printf_filtered (_("Usage: stop in <function | address>\n"));
9718 break_command_1 (arg
, 0, from_tty
);
9722 stopat_command (const char *arg
, int from_tty
)
9726 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9730 const char *argptr
= arg
;
9733 /* Look for a ':'. If there is a '::' then get out, otherwise
9734 it is probably a line number. */
9735 while (*argptr
&& !hasColon
)
9737 hasColon
= (*argptr
== ':');
9742 badInput
= (*argptr
== ':'); /* we have class::method */
9744 badInput
= !isdigit (*arg
); /* not a line number */
9748 printf_filtered (_("Usage: stop at <line>\n"));
9750 break_command_1 (arg
, 0, from_tty
);
9753 /* The dynamic printf command is mostly like a regular breakpoint, but
9754 with a prewired command list consisting of a single output command,
9755 built from extra arguments supplied on the dprintf command
9759 dprintf_command (char *arg_in
, int from_tty
)
9761 const char *arg
= arg_in
;
9762 event_location_up location
= string_to_event_location (&arg
, current_language
);
9764 /* If non-NULL, ARG should have been advanced past the location;
9765 the next character must be ','. */
9768 if (arg
[0] != ',' || arg
[1] == '\0')
9769 error (_("Format string required"));
9772 /* Skip the comma. */
9777 create_breakpoint (get_current_arch (),
9779 NULL
, 0, arg
, 1 /* parse arg */,
9781 0 /* Ignore count */,
9782 pending_break_support
,
9783 &dprintf_breakpoint_ops
,
9791 agent_printf_command (char *arg
, int from_tty
)
9793 error (_("May only run agent-printf on the target"));
9796 /* Implement the "breakpoint_hit" breakpoint_ops method for
9797 ranged breakpoints. */
9800 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9801 const address_space
*aspace
,
9803 const struct target_waitstatus
*ws
)
9805 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9806 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9809 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9810 bl
->length
, aspace
, bp_addr
);
9813 /* Implement the "resources_needed" breakpoint_ops method for
9814 ranged breakpoints. */
9817 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9819 return target_ranged_break_num_registers ();
9822 /* Implement the "print_it" breakpoint_ops method for
9823 ranged breakpoints. */
9825 static enum print_stop_action
9826 print_it_ranged_breakpoint (bpstat bs
)
9828 struct breakpoint
*b
= bs
->breakpoint_at
;
9829 struct bp_location
*bl
= b
->loc
;
9830 struct ui_out
*uiout
= current_uiout
;
9832 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9834 /* Ranged breakpoints have only one location. */
9835 gdb_assert (bl
&& bl
->next
== NULL
);
9837 annotate_breakpoint (b
->number
);
9839 maybe_print_thread_hit_breakpoint (uiout
);
9841 if (b
->disposition
== disp_del
)
9842 uiout
->text ("Temporary ranged breakpoint ");
9844 uiout
->text ("Ranged breakpoint ");
9845 if (uiout
->is_mi_like_p ())
9847 uiout
->field_string ("reason",
9848 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9849 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9851 uiout
->field_int ("bkptno", b
->number
);
9854 return PRINT_SRC_AND_LOC
;
9857 /* Implement the "print_one" breakpoint_ops method for
9858 ranged breakpoints. */
9861 print_one_ranged_breakpoint (struct breakpoint
*b
,
9862 struct bp_location
**last_loc
)
9864 struct bp_location
*bl
= b
->loc
;
9865 struct value_print_options opts
;
9866 struct ui_out
*uiout
= current_uiout
;
9868 /* Ranged breakpoints have only one location. */
9869 gdb_assert (bl
&& bl
->next
== NULL
);
9871 get_user_print_options (&opts
);
9873 if (opts
.addressprint
)
9874 /* We don't print the address range here, it will be printed later
9875 by print_one_detail_ranged_breakpoint. */
9876 uiout
->field_skip ("addr");
9878 print_breakpoint_location (b
, bl
);
9882 /* Implement the "print_one_detail" breakpoint_ops method for
9883 ranged breakpoints. */
9886 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9887 struct ui_out
*uiout
)
9889 CORE_ADDR address_start
, address_end
;
9890 struct bp_location
*bl
= b
->loc
;
9895 address_start
= bl
->address
;
9896 address_end
= address_start
+ bl
->length
- 1;
9898 uiout
->text ("\taddress range: ");
9899 stb
.printf ("[%s, %s]",
9900 print_core_address (bl
->gdbarch
, address_start
),
9901 print_core_address (bl
->gdbarch
, address_end
));
9902 uiout
->field_stream ("addr", stb
);
9906 /* Implement the "print_mention" breakpoint_ops method for
9907 ranged breakpoints. */
9910 print_mention_ranged_breakpoint (struct breakpoint
*b
)
9912 struct bp_location
*bl
= b
->loc
;
9913 struct ui_out
*uiout
= current_uiout
;
9916 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9918 if (uiout
->is_mi_like_p ())
9921 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
9922 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
9923 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
9926 /* Implement the "print_recreate" breakpoint_ops method for
9927 ranged breakpoints. */
9930 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
9932 fprintf_unfiltered (fp
, "break-range %s, %s",
9933 event_location_to_string (b
->location
.get ()),
9934 event_location_to_string (b
->location_range_end
.get ()));
9935 print_recreate_thread (b
, fp
);
9938 /* The breakpoint_ops structure to be used in ranged breakpoints. */
9940 static struct breakpoint_ops ranged_breakpoint_ops
;
9942 /* Find the address where the end of the breakpoint range should be
9943 placed, given the SAL of the end of the range. This is so that if
9944 the user provides a line number, the end of the range is set to the
9945 last instruction of the given line. */
9948 find_breakpoint_range_end (struct symtab_and_line sal
)
9952 /* If the user provided a PC value, use it. Otherwise,
9953 find the address of the end of the given location. */
9954 if (sal
.explicit_pc
)
9961 ret
= find_line_pc_range (sal
, &start
, &end
);
9963 error (_("Could not find location of the end of the range."));
9965 /* find_line_pc_range returns the start of the next line. */
9972 /* Implement the "break-range" CLI command. */
9975 break_range_command (char *arg_in
, int from_tty
)
9977 const char *arg
= arg_in
;
9978 const char *arg_start
;
9979 struct linespec_result canonical_start
, canonical_end
;
9980 int bp_count
, can_use_bp
, length
;
9982 struct breakpoint
*b
;
9984 /* We don't support software ranged breakpoints. */
9985 if (target_ranged_break_num_registers () < 0)
9986 error (_("This target does not support hardware ranged breakpoints."));
9988 bp_count
= hw_breakpoint_used_count ();
9989 bp_count
+= target_ranged_break_num_registers ();
9990 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9993 error (_("Hardware breakpoints used exceeds limit."));
9995 arg
= skip_spaces (arg
);
9996 if (arg
== NULL
|| arg
[0] == '\0')
9997 error(_("No address range specified."));
10000 event_location_up start_location
= string_to_event_location (&arg
,
10002 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10005 error (_("Too few arguments."));
10006 else if (canonical_start
.lsals
.empty ())
10007 error (_("Could not find location of the beginning of the range."));
10009 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
10011 if (canonical_start
.lsals
.size () > 1
10012 || lsal_start
.sals
.size () != 1)
10013 error (_("Cannot create a ranged breakpoint with multiple locations."));
10015 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
10016 std::string
addr_string_start (arg_start
, arg
- arg_start
);
10018 arg
++; /* Skip the comma. */
10019 arg
= skip_spaces (arg
);
10021 /* Parse the end location. */
10025 /* We call decode_line_full directly here instead of using
10026 parse_breakpoint_sals because we need to specify the start location's
10027 symtab and line as the default symtab and line for the end of the
10028 range. This makes it possible to have ranges like "foo.c:27, +14",
10029 where +14 means 14 lines from the start location. */
10030 event_location_up end_location
= string_to_event_location (&arg
,
10032 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10033 sal_start
.symtab
, sal_start
.line
,
10034 &canonical_end
, NULL
, NULL
);
10036 if (canonical_end
.lsals
.empty ())
10037 error (_("Could not find location of the end of the range."));
10039 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10040 if (canonical_end
.lsals
.size () > 1
10041 || lsal_end
.sals
.size () != 1)
10042 error (_("Cannot create a ranged breakpoint with multiple locations."));
10044 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10046 end
= find_breakpoint_range_end (sal_end
);
10047 if (sal_start
.pc
> end
)
10048 error (_("Invalid address range, end precedes start."));
10050 length
= end
- sal_start
.pc
+ 1;
10052 /* Length overflowed. */
10053 error (_("Address range too large."));
10054 else if (length
== 1)
10056 /* This range is simple enough to be handled by
10057 the `hbreak' command. */
10058 hbreak_command (&addr_string_start
[0], 1);
10063 /* Now set up the breakpoint. */
10064 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10065 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10066 set_breakpoint_count (breakpoint_count
+ 1);
10067 b
->number
= breakpoint_count
;
10068 b
->disposition
= disp_donttouch
;
10069 b
->location
= std::move (start_location
);
10070 b
->location_range_end
= std::move (end_location
);
10071 b
->loc
->length
= length
;
10074 observer_notify_breakpoint_created (b
);
10075 update_global_location_list (UGLL_MAY_INSERT
);
10078 /* Return non-zero if EXP is verified as constant. Returned zero
10079 means EXP is variable. Also the constant detection may fail for
10080 some constant expressions and in such case still falsely return
10084 watchpoint_exp_is_const (const struct expression
*exp
)
10086 int i
= exp
->nelts
;
10092 /* We are only interested in the descriptor of each element. */
10093 operator_length (exp
, i
, &oplenp
, &argsp
);
10096 switch (exp
->elts
[i
].opcode
)
10106 case BINOP_LOGICAL_AND
:
10107 case BINOP_LOGICAL_OR
:
10108 case BINOP_BITWISE_AND
:
10109 case BINOP_BITWISE_IOR
:
10110 case BINOP_BITWISE_XOR
:
10112 case BINOP_NOTEQUAL
:
10138 case OP_OBJC_NSSTRING
:
10141 case UNOP_LOGICAL_NOT
:
10142 case UNOP_COMPLEMENT
:
10147 case UNOP_CAST_TYPE
:
10148 case UNOP_REINTERPRET_CAST
:
10149 case UNOP_DYNAMIC_CAST
:
10150 /* Unary, binary and ternary operators: We have to check
10151 their operands. If they are constant, then so is the
10152 result of that operation. For instance, if A and B are
10153 determined to be constants, then so is "A + B".
10155 UNOP_IND is one exception to the rule above, because the
10156 value of *ADDR is not necessarily a constant, even when
10161 /* Check whether the associated symbol is a constant.
10163 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10164 possible that a buggy compiler could mark a variable as
10165 constant even when it is not, and TYPE_CONST would return
10166 true in this case, while SYMBOL_CLASS wouldn't.
10168 We also have to check for function symbols because they
10169 are always constant. */
10171 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10173 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10174 && SYMBOL_CLASS (s
) != LOC_CONST
10175 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10180 /* The default action is to return 0 because we are using
10181 the optimistic approach here: If we don't know something,
10182 then it is not a constant. */
10191 /* Watchpoint destructor. */
10193 watchpoint::~watchpoint ()
10195 xfree (this->exp_string
);
10196 xfree (this->exp_string_reparse
);
10197 value_free (this->val
);
10200 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10203 re_set_watchpoint (struct breakpoint
*b
)
10205 struct watchpoint
*w
= (struct watchpoint
*) b
;
10207 /* Watchpoint can be either on expression using entirely global
10208 variables, or it can be on local variables.
10210 Watchpoints of the first kind are never auto-deleted, and even
10211 persist across program restarts. Since they can use variables
10212 from shared libraries, we need to reparse expression as libraries
10213 are loaded and unloaded.
10215 Watchpoints on local variables can also change meaning as result
10216 of solib event. For example, if a watchpoint uses both a local
10217 and a global variables in expression, it's a local watchpoint,
10218 but unloading of a shared library will make the expression
10219 invalid. This is not a very common use case, but we still
10220 re-evaluate expression, to avoid surprises to the user.
10222 Note that for local watchpoints, we re-evaluate it only if
10223 watchpoints frame id is still valid. If it's not, it means the
10224 watchpoint is out of scope and will be deleted soon. In fact,
10225 I'm not sure we'll ever be called in this case.
10227 If a local watchpoint's frame id is still valid, then
10228 w->exp_valid_block is likewise valid, and we can safely use it.
10230 Don't do anything about disabled watchpoints, since they will be
10231 reevaluated again when enabled. */
10232 update_watchpoint (w
, 1 /* reparse */);
10235 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10238 insert_watchpoint (struct bp_location
*bl
)
10240 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10241 int length
= w
->exact
? 1 : bl
->length
;
10243 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10244 w
->cond_exp
.get ());
10247 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10250 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10252 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10253 int length
= w
->exact
? 1 : bl
->length
;
10255 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10256 w
->cond_exp
.get ());
10260 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10261 const address_space
*aspace
, CORE_ADDR bp_addr
,
10262 const struct target_waitstatus
*ws
)
10264 struct breakpoint
*b
= bl
->owner
;
10265 struct watchpoint
*w
= (struct watchpoint
*) b
;
10267 /* Continuable hardware watchpoints are treated as non-existent if the
10268 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10269 some data address). Otherwise gdb won't stop on a break instruction
10270 in the code (not from a breakpoint) when a hardware watchpoint has
10271 been defined. Also skip watchpoints which we know did not trigger
10272 (did not match the data address). */
10273 if (is_hardware_watchpoint (b
)
10274 && w
->watchpoint_triggered
== watch_triggered_no
)
10281 check_status_watchpoint (bpstat bs
)
10283 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10285 bpstat_check_watchpoint (bs
);
10288 /* Implement the "resources_needed" breakpoint_ops method for
10289 hardware watchpoints. */
10292 resources_needed_watchpoint (const struct bp_location
*bl
)
10294 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10295 int length
= w
->exact
? 1 : bl
->length
;
10297 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10300 /* Implement the "works_in_software_mode" breakpoint_ops method for
10301 hardware watchpoints. */
10304 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10306 /* Read and access watchpoints only work with hardware support. */
10307 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10310 static enum print_stop_action
10311 print_it_watchpoint (bpstat bs
)
10313 struct breakpoint
*b
;
10314 enum print_stop_action result
;
10315 struct watchpoint
*w
;
10316 struct ui_out
*uiout
= current_uiout
;
10318 gdb_assert (bs
->bp_location_at
!= NULL
);
10320 b
= bs
->breakpoint_at
;
10321 w
= (struct watchpoint
*) b
;
10323 annotate_watchpoint (b
->number
);
10324 maybe_print_thread_hit_breakpoint (uiout
);
10328 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10331 case bp_watchpoint
:
10332 case bp_hardware_watchpoint
:
10333 if (uiout
->is_mi_like_p ())
10334 uiout
->field_string
10335 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10337 tuple_emitter
.emplace (uiout
, "value");
10338 uiout
->text ("\nOld value = ");
10339 watchpoint_value_print (bs
->old_val
, &stb
);
10340 uiout
->field_stream ("old", stb
);
10341 uiout
->text ("\nNew value = ");
10342 watchpoint_value_print (w
->val
, &stb
);
10343 uiout
->field_stream ("new", stb
);
10344 uiout
->text ("\n");
10345 /* More than one watchpoint may have been triggered. */
10346 result
= PRINT_UNKNOWN
;
10349 case bp_read_watchpoint
:
10350 if (uiout
->is_mi_like_p ())
10351 uiout
->field_string
10352 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10354 tuple_emitter
.emplace (uiout
, "value");
10355 uiout
->text ("\nValue = ");
10356 watchpoint_value_print (w
->val
, &stb
);
10357 uiout
->field_stream ("value", stb
);
10358 uiout
->text ("\n");
10359 result
= PRINT_UNKNOWN
;
10362 case bp_access_watchpoint
:
10363 if (bs
->old_val
!= NULL
)
10365 if (uiout
->is_mi_like_p ())
10366 uiout
->field_string
10368 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10370 tuple_emitter
.emplace (uiout
, "value");
10371 uiout
->text ("\nOld value = ");
10372 watchpoint_value_print (bs
->old_val
, &stb
);
10373 uiout
->field_stream ("old", stb
);
10374 uiout
->text ("\nNew value = ");
10379 if (uiout
->is_mi_like_p ())
10380 uiout
->field_string
10382 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10383 tuple_emitter
.emplace (uiout
, "value");
10384 uiout
->text ("\nValue = ");
10386 watchpoint_value_print (w
->val
, &stb
);
10387 uiout
->field_stream ("new", stb
);
10388 uiout
->text ("\n");
10389 result
= PRINT_UNKNOWN
;
10392 result
= PRINT_UNKNOWN
;
10398 /* Implement the "print_mention" breakpoint_ops method for hardware
10402 print_mention_watchpoint (struct breakpoint
*b
)
10404 struct watchpoint
*w
= (struct watchpoint
*) b
;
10405 struct ui_out
*uiout
= current_uiout
;
10406 const char *tuple_name
;
10410 case bp_watchpoint
:
10411 uiout
->text ("Watchpoint ");
10412 tuple_name
= "wpt";
10414 case bp_hardware_watchpoint
:
10415 uiout
->text ("Hardware watchpoint ");
10416 tuple_name
= "wpt";
10418 case bp_read_watchpoint
:
10419 uiout
->text ("Hardware read watchpoint ");
10420 tuple_name
= "hw-rwpt";
10422 case bp_access_watchpoint
:
10423 uiout
->text ("Hardware access (read/write) watchpoint ");
10424 tuple_name
= "hw-awpt";
10427 internal_error (__FILE__
, __LINE__
,
10428 _("Invalid hardware watchpoint type."));
10431 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10432 uiout
->field_int ("number", b
->number
);
10433 uiout
->text (": ");
10434 uiout
->field_string ("exp", w
->exp_string
);
10437 /* Implement the "print_recreate" breakpoint_ops method for
10441 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10443 struct watchpoint
*w
= (struct watchpoint
*) b
;
10447 case bp_watchpoint
:
10448 case bp_hardware_watchpoint
:
10449 fprintf_unfiltered (fp
, "watch");
10451 case bp_read_watchpoint
:
10452 fprintf_unfiltered (fp
, "rwatch");
10454 case bp_access_watchpoint
:
10455 fprintf_unfiltered (fp
, "awatch");
10458 internal_error (__FILE__
, __LINE__
,
10459 _("Invalid watchpoint type."));
10462 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10463 print_recreate_thread (b
, fp
);
10466 /* Implement the "explains_signal" breakpoint_ops method for
10470 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10472 /* A software watchpoint cannot cause a signal other than
10473 GDB_SIGNAL_TRAP. */
10474 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10480 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10482 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10484 /* Implement the "insert" breakpoint_ops method for
10485 masked hardware watchpoints. */
10488 insert_masked_watchpoint (struct bp_location
*bl
)
10490 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10492 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10493 bl
->watchpoint_type
);
10496 /* Implement the "remove" breakpoint_ops method for
10497 masked hardware watchpoints. */
10500 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10502 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10504 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10505 bl
->watchpoint_type
);
10508 /* Implement the "resources_needed" breakpoint_ops method for
10509 masked hardware watchpoints. */
10512 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10514 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10516 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10519 /* Implement the "works_in_software_mode" breakpoint_ops method for
10520 masked hardware watchpoints. */
10523 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10528 /* Implement the "print_it" breakpoint_ops method for
10529 masked hardware watchpoints. */
10531 static enum print_stop_action
10532 print_it_masked_watchpoint (bpstat bs
)
10534 struct breakpoint
*b
= bs
->breakpoint_at
;
10535 struct ui_out
*uiout
= current_uiout
;
10537 /* Masked watchpoints have only one location. */
10538 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10540 annotate_watchpoint (b
->number
);
10541 maybe_print_thread_hit_breakpoint (uiout
);
10545 case bp_hardware_watchpoint
:
10546 if (uiout
->is_mi_like_p ())
10547 uiout
->field_string
10548 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10551 case bp_read_watchpoint
:
10552 if (uiout
->is_mi_like_p ())
10553 uiout
->field_string
10554 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10557 case bp_access_watchpoint
:
10558 if (uiout
->is_mi_like_p ())
10559 uiout
->field_string
10561 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10564 internal_error (__FILE__
, __LINE__
,
10565 _("Invalid hardware watchpoint type."));
10569 uiout
->text (_("\n\
10570 Check the underlying instruction at PC for the memory\n\
10571 address and value which triggered this watchpoint.\n"));
10572 uiout
->text ("\n");
10574 /* More than one watchpoint may have been triggered. */
10575 return PRINT_UNKNOWN
;
10578 /* Implement the "print_one_detail" breakpoint_ops method for
10579 masked hardware watchpoints. */
10582 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10583 struct ui_out
*uiout
)
10585 struct watchpoint
*w
= (struct watchpoint
*) b
;
10587 /* Masked watchpoints have only one location. */
10588 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10590 uiout
->text ("\tmask ");
10591 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10592 uiout
->text ("\n");
10595 /* Implement the "print_mention" breakpoint_ops method for
10596 masked hardware watchpoints. */
10599 print_mention_masked_watchpoint (struct breakpoint
*b
)
10601 struct watchpoint
*w
= (struct watchpoint
*) b
;
10602 struct ui_out
*uiout
= current_uiout
;
10603 const char *tuple_name
;
10607 case bp_hardware_watchpoint
:
10608 uiout
->text ("Masked hardware watchpoint ");
10609 tuple_name
= "wpt";
10611 case bp_read_watchpoint
:
10612 uiout
->text ("Masked hardware read watchpoint ");
10613 tuple_name
= "hw-rwpt";
10615 case bp_access_watchpoint
:
10616 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10617 tuple_name
= "hw-awpt";
10620 internal_error (__FILE__
, __LINE__
,
10621 _("Invalid hardware watchpoint type."));
10624 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10625 uiout
->field_int ("number", b
->number
);
10626 uiout
->text (": ");
10627 uiout
->field_string ("exp", w
->exp_string
);
10630 /* Implement the "print_recreate" breakpoint_ops method for
10631 masked hardware watchpoints. */
10634 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10636 struct watchpoint
*w
= (struct watchpoint
*) b
;
10641 case bp_hardware_watchpoint
:
10642 fprintf_unfiltered (fp
, "watch");
10644 case bp_read_watchpoint
:
10645 fprintf_unfiltered (fp
, "rwatch");
10647 case bp_access_watchpoint
:
10648 fprintf_unfiltered (fp
, "awatch");
10651 internal_error (__FILE__
, __LINE__
,
10652 _("Invalid hardware watchpoint type."));
10655 sprintf_vma (tmp
, w
->hw_wp_mask
);
10656 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10657 print_recreate_thread (b
, fp
);
10660 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10662 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10664 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10667 is_masked_watchpoint (const struct breakpoint
*b
)
10669 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10672 /* accessflag: hw_write: watch write,
10673 hw_read: watch read,
10674 hw_access: watch access (read or write) */
10676 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10677 int just_location
, int internal
)
10679 struct breakpoint
*scope_breakpoint
= NULL
;
10680 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10681 struct value
*val
, *mark
, *result
;
10682 int saved_bitpos
= 0, saved_bitsize
= 0;
10683 const char *exp_start
= NULL
;
10684 const char *exp_end
= NULL
;
10685 const char *tok
, *end_tok
;
10687 const char *cond_start
= NULL
;
10688 const char *cond_end
= NULL
;
10689 enum bptype bp_type
;
10692 /* Flag to indicate whether we are going to use masks for
10693 the hardware watchpoint. */
10695 CORE_ADDR mask
= 0;
10697 /* Make sure that we actually have parameters to parse. */
10698 if (arg
!= NULL
&& arg
[0] != '\0')
10700 const char *value_start
;
10702 exp_end
= arg
+ strlen (arg
);
10704 /* Look for "parameter value" pairs at the end
10705 of the arguments string. */
10706 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10708 /* Skip whitespace at the end of the argument list. */
10709 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10712 /* Find the beginning of the last token.
10713 This is the value of the parameter. */
10714 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10716 value_start
= tok
+ 1;
10718 /* Skip whitespace. */
10719 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10724 /* Find the beginning of the second to last token.
10725 This is the parameter itself. */
10726 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10729 toklen
= end_tok
- tok
+ 1;
10731 if (toklen
== 6 && startswith (tok
, "thread"))
10733 struct thread_info
*thr
;
10734 /* At this point we've found a "thread" token, which means
10735 the user is trying to set a watchpoint that triggers
10736 only in a specific thread. */
10740 error(_("You can specify only one thread."));
10742 /* Extract the thread ID from the next token. */
10743 thr
= parse_thread_id (value_start
, &endp
);
10745 /* Check if the user provided a valid thread ID. */
10746 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10747 invalid_thread_id_error (value_start
);
10749 thread
= thr
->global_num
;
10751 else if (toklen
== 4 && startswith (tok
, "mask"))
10753 /* We've found a "mask" token, which means the user wants to
10754 create a hardware watchpoint that is going to have the mask
10756 struct value
*mask_value
, *mark
;
10759 error(_("You can specify only one mask."));
10761 use_mask
= just_location
= 1;
10763 mark
= value_mark ();
10764 mask_value
= parse_to_comma_and_eval (&value_start
);
10765 mask
= value_as_address (mask_value
);
10766 value_free_to_mark (mark
);
10769 /* We didn't recognize what we found. We should stop here. */
10772 /* Truncate the string and get rid of the "parameter value" pair before
10773 the arguments string is parsed by the parse_exp_1 function. */
10780 /* Parse the rest of the arguments. From here on out, everything
10781 is in terms of a newly allocated string instead of the original
10783 innermost_block
= NULL
;
10784 std::string
expression (arg
, exp_end
- arg
);
10785 exp_start
= arg
= expression
.c_str ();
10786 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
10788 /* Remove trailing whitespace from the expression before saving it.
10789 This makes the eventual display of the expression string a bit
10791 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10794 /* Checking if the expression is not constant. */
10795 if (watchpoint_exp_is_const (exp
.get ()))
10799 len
= exp_end
- exp_start
;
10800 while (len
> 0 && isspace (exp_start
[len
- 1]))
10802 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10805 exp_valid_block
= innermost_block
;
10806 mark
= value_mark ();
10807 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
10809 if (val
!= NULL
&& just_location
)
10811 saved_bitpos
= value_bitpos (val
);
10812 saved_bitsize
= value_bitsize (val
);
10819 exp_valid_block
= NULL
;
10820 val
= value_addr (result
);
10821 release_value (val
);
10822 value_free_to_mark (mark
);
10826 ret
= target_masked_watch_num_registers (value_as_address (val
),
10829 error (_("This target does not support masked watchpoints."));
10830 else if (ret
== -2)
10831 error (_("Invalid mask or memory region."));
10834 else if (val
!= NULL
)
10835 release_value (val
);
10837 tok
= skip_spaces (arg
);
10838 end_tok
= skip_to_space (tok
);
10840 toklen
= end_tok
- tok
;
10841 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10843 innermost_block
= NULL
;
10844 tok
= cond_start
= end_tok
+ 1;
10845 parse_exp_1 (&tok
, 0, 0, 0);
10847 /* The watchpoint expression may not be local, but the condition
10848 may still be. E.g.: `watch global if local > 0'. */
10849 cond_exp_valid_block
= innermost_block
;
10854 error (_("Junk at end of command."));
10856 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10858 /* Save this because create_internal_breakpoint below invalidates
10860 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10862 /* If the expression is "local", then set up a "watchpoint scope"
10863 breakpoint at the point where we've left the scope of the watchpoint
10864 expression. Create the scope breakpoint before the watchpoint, so
10865 that we will encounter it first in bpstat_stop_status. */
10866 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10868 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10870 if (frame_id_p (caller_frame_id
))
10872 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10873 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10876 = create_internal_breakpoint (caller_arch
, caller_pc
,
10877 bp_watchpoint_scope
,
10878 &momentary_breakpoint_ops
);
10880 /* create_internal_breakpoint could invalidate WP_FRAME. */
10883 scope_breakpoint
->enable_state
= bp_enabled
;
10885 /* Automatically delete the breakpoint when it hits. */
10886 scope_breakpoint
->disposition
= disp_del
;
10888 /* Only break in the proper frame (help with recursion). */
10889 scope_breakpoint
->frame_id
= caller_frame_id
;
10891 /* Set the address at which we will stop. */
10892 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
10893 scope_breakpoint
->loc
->requested_address
= caller_pc
;
10894 scope_breakpoint
->loc
->address
10895 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
10896 scope_breakpoint
->loc
->requested_address
,
10897 scope_breakpoint
->type
);
10901 /* Now set up the breakpoint. We create all watchpoints as hardware
10902 watchpoints here even if hardware watchpoints are turned off, a call
10903 to update_watchpoint later in this function will cause the type to
10904 drop back to bp_watchpoint (software watchpoint) if required. */
10906 if (accessflag
== hw_read
)
10907 bp_type
= bp_read_watchpoint
;
10908 else if (accessflag
== hw_access
)
10909 bp_type
= bp_access_watchpoint
;
10911 bp_type
= bp_hardware_watchpoint
;
10913 std::unique_ptr
<watchpoint
> w (new watchpoint ());
10916 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10917 &masked_watchpoint_breakpoint_ops
);
10919 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
10920 &watchpoint_breakpoint_ops
);
10921 w
->thread
= thread
;
10922 w
->disposition
= disp_donttouch
;
10923 w
->pspace
= current_program_space
;
10924 w
->exp
= std::move (exp
);
10925 w
->exp_valid_block
= exp_valid_block
;
10926 w
->cond_exp_valid_block
= cond_exp_valid_block
;
10929 struct type
*t
= value_type (val
);
10930 CORE_ADDR addr
= value_as_address (val
);
10932 w
->exp_string_reparse
10933 = current_language
->la_watch_location_expression (t
, addr
).release ();
10935 w
->exp_string
= xstrprintf ("-location %.*s",
10936 (int) (exp_end
- exp_start
), exp_start
);
10939 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
10943 w
->hw_wp_mask
= mask
;
10948 w
->val_bitpos
= saved_bitpos
;
10949 w
->val_bitsize
= saved_bitsize
;
10954 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
10956 w
->cond_string
= 0;
10958 if (frame_id_p (watchpoint_frame
))
10960 w
->watchpoint_frame
= watchpoint_frame
;
10961 w
->watchpoint_thread
= inferior_ptid
;
10965 w
->watchpoint_frame
= null_frame_id
;
10966 w
->watchpoint_thread
= null_ptid
;
10969 if (scope_breakpoint
!= NULL
)
10971 /* The scope breakpoint is related to the watchpoint. We will
10972 need to act on them together. */
10973 w
->related_breakpoint
= scope_breakpoint
;
10974 scope_breakpoint
->related_breakpoint
= w
.get ();
10977 if (!just_location
)
10978 value_free_to_mark (mark
);
10980 /* Finally update the new watchpoint. This creates the locations
10981 that should be inserted. */
10982 update_watchpoint (w
.get (), 1);
10984 install_breakpoint (internal
, std::move (w
), 1);
10987 /* Return count of debug registers needed to watch the given expression.
10988 If the watchpoint cannot be handled in hardware return zero. */
10991 can_use_hardware_watchpoint (struct value
*v
)
10993 int found_memory_cnt
= 0;
10994 struct value
*head
= v
;
10996 /* Did the user specifically forbid us to use hardware watchpoints? */
10997 if (!can_use_hw_watchpoints
)
11000 /* Make sure that the value of the expression depends only upon
11001 memory contents, and values computed from them within GDB. If we
11002 find any register references or function calls, we can't use a
11003 hardware watchpoint.
11005 The idea here is that evaluating an expression generates a series
11006 of values, one holding the value of every subexpression. (The
11007 expression a*b+c has five subexpressions: a, b, a*b, c, and
11008 a*b+c.) GDB's values hold almost enough information to establish
11009 the criteria given above --- they identify memory lvalues,
11010 register lvalues, computed values, etcetera. So we can evaluate
11011 the expression, and then scan the chain of values that leaves
11012 behind to decide whether we can detect any possible change to the
11013 expression's final value using only hardware watchpoints.
11015 However, I don't think that the values returned by inferior
11016 function calls are special in any way. So this function may not
11017 notice that an expression involving an inferior function call
11018 can't be watched with hardware watchpoints. FIXME. */
11019 for (; v
; v
= value_next (v
))
11021 if (VALUE_LVAL (v
) == lval_memory
)
11023 if (v
!= head
&& value_lazy (v
))
11024 /* A lazy memory lvalue in the chain is one that GDB never
11025 needed to fetch; we either just used its address (e.g.,
11026 `a' in `a.b') or we never needed it at all (e.g., `a'
11027 in `a,b'). This doesn't apply to HEAD; if that is
11028 lazy then it was not readable, but watch it anyway. */
11032 /* Ahh, memory we actually used! Check if we can cover
11033 it with hardware watchpoints. */
11034 struct type
*vtype
= check_typedef (value_type (v
));
11036 /* We only watch structs and arrays if user asked for it
11037 explicitly, never if they just happen to appear in a
11038 middle of some value chain. */
11040 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11041 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11043 CORE_ADDR vaddr
= value_address (v
);
11047 len
= (target_exact_watchpoints
11048 && is_scalar_type_recursive (vtype
))?
11049 1 : TYPE_LENGTH (value_type (v
));
11051 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11055 found_memory_cnt
+= num_regs
;
11059 else if (VALUE_LVAL (v
) != not_lval
11060 && deprecated_value_modifiable (v
) == 0)
11061 return 0; /* These are values from the history (e.g., $1). */
11062 else if (VALUE_LVAL (v
) == lval_register
)
11063 return 0; /* Cannot watch a register with a HW watchpoint. */
11066 /* The expression itself looks suitable for using a hardware
11067 watchpoint, but give the target machine a chance to reject it. */
11068 return found_memory_cnt
;
11072 watch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11074 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11077 /* A helper function that looks for the "-location" argument and then
11078 calls watch_command_1. */
11081 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11083 int just_location
= 0;
11086 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11087 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11089 arg
= skip_spaces (arg
);
11093 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11097 watch_command (char *arg
, int from_tty
)
11099 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11103 rwatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11105 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11109 rwatch_command (char *arg
, int from_tty
)
11111 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11115 awatch_command_wrapper (const char *arg
, int from_tty
, int internal
)
11117 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11121 awatch_command (char *arg
, int from_tty
)
11123 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11127 /* Data for the FSM that manages the until(location)/advance commands
11128 in infcmd.c. Here because it uses the mechanisms of
11131 struct until_break_fsm
11133 /* The base class. */
11134 struct thread_fsm thread_fsm
;
11136 /* The thread that as current when the command was executed. */
11139 /* The breakpoint set at the destination location. */
11140 struct breakpoint
*location_breakpoint
;
11142 /* Breakpoint set at the return address in the caller frame. May be
11144 struct breakpoint
*caller_breakpoint
;
11147 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11148 struct thread_info
*thread
);
11149 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11150 struct thread_info
*thread
);
11151 static enum async_reply_reason
11152 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11154 /* until_break_fsm's vtable. */
11156 static struct thread_fsm_ops until_break_fsm_ops
=
11159 until_break_fsm_clean_up
,
11160 until_break_fsm_should_stop
,
11161 NULL
, /* return_value */
11162 until_break_fsm_async_reply_reason
,
11165 /* Allocate a new until_break_command_fsm. */
11167 static struct until_break_fsm
*
11168 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11169 struct breakpoint
*location_breakpoint
,
11170 struct breakpoint
*caller_breakpoint
)
11172 struct until_break_fsm
*sm
;
11174 sm
= XCNEW (struct until_break_fsm
);
11175 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11177 sm
->thread
= thread
;
11178 sm
->location_breakpoint
= location_breakpoint
;
11179 sm
->caller_breakpoint
= caller_breakpoint
;
11184 /* Implementation of the 'should_stop' FSM method for the
11185 until(location)/advance commands. */
11188 until_break_fsm_should_stop (struct thread_fsm
*self
,
11189 struct thread_info
*tp
)
11191 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11193 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11194 sm
->location_breakpoint
) != NULL
11195 || (sm
->caller_breakpoint
!= NULL
11196 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11197 sm
->caller_breakpoint
) != NULL
))
11198 thread_fsm_set_finished (self
);
11203 /* Implementation of the 'clean_up' FSM method for the
11204 until(location)/advance commands. */
11207 until_break_fsm_clean_up (struct thread_fsm
*self
,
11208 struct thread_info
*thread
)
11210 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11212 /* Clean up our temporary breakpoints. */
11213 if (sm
->location_breakpoint
!= NULL
)
11215 delete_breakpoint (sm
->location_breakpoint
);
11216 sm
->location_breakpoint
= NULL
;
11218 if (sm
->caller_breakpoint
!= NULL
)
11220 delete_breakpoint (sm
->caller_breakpoint
);
11221 sm
->caller_breakpoint
= NULL
;
11223 delete_longjmp_breakpoint (sm
->thread
);
11226 /* Implementation of the 'async_reply_reason' FSM method for the
11227 until(location)/advance commands. */
11229 static enum async_reply_reason
11230 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11232 return EXEC_ASYNC_LOCATION_REACHED
;
11236 until_break_command (const char *arg
, int from_tty
, int anywhere
)
11238 struct frame_info
*frame
;
11239 struct gdbarch
*frame_gdbarch
;
11240 struct frame_id stack_frame_id
;
11241 struct frame_id caller_frame_id
;
11242 struct breakpoint
*location_breakpoint
;
11243 struct breakpoint
*caller_breakpoint
= NULL
;
11244 struct cleanup
*old_chain
;
11246 struct thread_info
*tp
;
11247 struct until_break_fsm
*sm
;
11249 clear_proceed_status (0);
11251 /* Set a breakpoint where the user wants it and at return from
11254 event_location_up location
= string_to_event_location (&arg
, current_language
);
11256 std::vector
<symtab_and_line
> sals
11257 = (last_displayed_sal_is_valid ()
11258 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11259 get_last_displayed_symtab (),
11260 get_last_displayed_line ())
11261 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11262 NULL
, (struct symtab
*) NULL
, 0));
11264 if (sals
.size () != 1)
11265 error (_("Couldn't get information on specified line."));
11267 symtab_and_line
&sal
= sals
[0];
11270 error (_("Junk at end of arguments."));
11272 resolve_sal_pc (&sal
);
11274 tp
= inferior_thread ();
11275 thread
= tp
->global_num
;
11277 old_chain
= make_cleanup (null_cleanup
, NULL
);
11279 /* Note linespec handling above invalidates the frame chain.
11280 Installing a breakpoint also invalidates the frame chain (as it
11281 may need to switch threads), so do any frame handling before
11284 frame
= get_selected_frame (NULL
);
11285 frame_gdbarch
= get_frame_arch (frame
);
11286 stack_frame_id
= get_stack_frame_id (frame
);
11287 caller_frame_id
= frame_unwind_caller_id (frame
);
11289 /* Keep within the current frame, or in frames called by the current
11292 if (frame_id_p (caller_frame_id
))
11294 struct symtab_and_line sal2
;
11295 struct gdbarch
*caller_gdbarch
;
11297 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11298 sal2
.pc
= frame_unwind_caller_pc (frame
);
11299 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11300 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11304 make_cleanup_delete_breakpoint (caller_breakpoint
);
11306 set_longjmp_breakpoint (tp
, caller_frame_id
);
11307 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11310 /* set_momentary_breakpoint could invalidate FRAME. */
11314 /* If the user told us to continue until a specified location,
11315 we don't specify a frame at which we need to stop. */
11316 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11317 null_frame_id
, bp_until
);
11319 /* Otherwise, specify the selected frame, because we want to stop
11320 only at the very same frame. */
11321 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11322 stack_frame_id
, bp_until
);
11323 make_cleanup_delete_breakpoint (location_breakpoint
);
11325 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11326 location_breakpoint
, caller_breakpoint
);
11327 tp
->thread_fsm
= &sm
->thread_fsm
;
11329 discard_cleanups (old_chain
);
11331 proceed (-1, GDB_SIGNAL_DEFAULT
);
11334 /* This function attempts to parse an optional "if <cond>" clause
11335 from the arg string. If one is not found, it returns NULL.
11337 Else, it returns a pointer to the condition string. (It does not
11338 attempt to evaluate the string against a particular block.) And,
11339 it updates arg to point to the first character following the parsed
11340 if clause in the arg string. */
11343 ep_parse_optional_if_clause (const char **arg
)
11345 const char *cond_string
;
11347 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11350 /* Skip the "if" keyword. */
11353 /* Skip any extra leading whitespace, and record the start of the
11354 condition string. */
11355 *arg
= skip_spaces (*arg
);
11356 cond_string
= *arg
;
11358 /* Assume that the condition occupies the remainder of the arg
11360 (*arg
) += strlen (cond_string
);
11362 return cond_string
;
11365 /* Commands to deal with catching events, such as signals, exceptions,
11366 process start/exit, etc. */
11370 catch_fork_temporary
, catch_vfork_temporary
,
11371 catch_fork_permanent
, catch_vfork_permanent
11376 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11377 struct cmd_list_element
*command
)
11379 const char *arg
= arg_entry
;
11380 struct gdbarch
*gdbarch
= get_current_arch ();
11381 const char *cond_string
= NULL
;
11382 catch_fork_kind fork_kind
;
11385 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11386 tempflag
= (fork_kind
== catch_fork_temporary
11387 || fork_kind
== catch_vfork_temporary
);
11391 arg
= skip_spaces (arg
);
11393 /* The allowed syntax is:
11395 catch [v]fork if <cond>
11397 First, check if there's an if clause. */
11398 cond_string
= ep_parse_optional_if_clause (&arg
);
11400 if ((*arg
!= '\0') && !isspace (*arg
))
11401 error (_("Junk at end of arguments."));
11403 /* If this target supports it, create a fork or vfork catchpoint
11404 and enable reporting of such events. */
11407 case catch_fork_temporary
:
11408 case catch_fork_permanent
:
11409 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11410 &catch_fork_breakpoint_ops
);
11412 case catch_vfork_temporary
:
11413 case catch_vfork_permanent
:
11414 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11415 &catch_vfork_breakpoint_ops
);
11418 error (_("unsupported or unknown fork kind; cannot catch it"));
11424 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11425 struct cmd_list_element
*command
)
11427 const char *arg
= arg_entry
;
11428 struct gdbarch
*gdbarch
= get_current_arch ();
11430 const char *cond_string
= NULL
;
11432 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11436 arg
= skip_spaces (arg
);
11438 /* The allowed syntax is:
11440 catch exec if <cond>
11442 First, check if there's an if clause. */
11443 cond_string
= ep_parse_optional_if_clause (&arg
);
11445 if ((*arg
!= '\0') && !isspace (*arg
))
11446 error (_("Junk at end of arguments."));
11448 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11449 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11450 &catch_exec_breakpoint_ops
);
11451 c
->exec_pathname
= NULL
;
11453 install_breakpoint (0, std::move (c
), 1);
11457 init_ada_exception_breakpoint (struct breakpoint
*b
,
11458 struct gdbarch
*gdbarch
,
11459 struct symtab_and_line sal
,
11460 const char *addr_string
,
11461 const struct breakpoint_ops
*ops
,
11468 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11470 loc_gdbarch
= gdbarch
;
11472 describe_other_breakpoints (loc_gdbarch
,
11473 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11474 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11475 version for exception catchpoints, because two catchpoints
11476 used for different exception names will use the same address.
11477 In this case, a "breakpoint ... also set at..." warning is
11478 unproductive. Besides, the warning phrasing is also a bit
11479 inappropriate, we should use the word catchpoint, and tell
11480 the user what type of catchpoint it is. The above is good
11481 enough for now, though. */
11484 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11486 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11487 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11488 b
->location
= string_to_event_location (&addr_string
,
11489 language_def (language_ada
));
11490 b
->language
= language_ada
;
11494 catch_command (const char *arg
, int from_tty
)
11496 error (_("Catch requires an event name."));
11501 tcatch_command (const char *arg
, int from_tty
)
11503 error (_("Catch requires an event name."));
11506 /* Compare two breakpoints and return a strcmp-like result. */
11509 compare_breakpoints (const breakpoint
*a
, const breakpoint
*b
)
11511 uintptr_t ua
= (uintptr_t) a
;
11512 uintptr_t ub
= (uintptr_t) b
;
11514 if (a
->number
< b
->number
)
11516 else if (a
->number
> b
->number
)
11519 /* Now sort by address, in case we see, e..g, two breakpoints with
11523 return ua
> ub
? 1 : 0;
11526 /* Delete breakpoints by address or line. */
11529 clear_command (char *arg
, int from_tty
)
11531 struct breakpoint
*b
;
11535 std::vector
<symtab_and_line
> decoded_sals
;
11536 symtab_and_line last_sal
;
11537 gdb::array_view
<symtab_and_line
> sals
;
11541 = decode_line_with_current_source (arg
,
11542 (DECODE_LINE_FUNFIRSTLINE
11543 | DECODE_LINE_LIST_MODE
));
11545 sals
= decoded_sals
;
11549 /* Set sal's line, symtab, pc, and pspace to the values
11550 corresponding to the last call to print_frame_info. If the
11551 codepoint is not valid, this will set all the fields to 0. */
11552 last_sal
= get_last_displayed_sal ();
11553 if (last_sal
.symtab
== 0)
11554 error (_("No source file specified."));
11560 /* We don't call resolve_sal_pc here. That's not as bad as it
11561 seems, because all existing breakpoints typically have both
11562 file/line and pc set. So, if clear is given file/line, we can
11563 match this to existing breakpoint without obtaining pc at all.
11565 We only support clearing given the address explicitly
11566 present in breakpoint table. Say, we've set breakpoint
11567 at file:line. There were several PC values for that file:line,
11568 due to optimization, all in one block.
11570 We've picked one PC value. If "clear" is issued with another
11571 PC corresponding to the same file:line, the breakpoint won't
11572 be cleared. We probably can still clear the breakpoint, but
11573 since the other PC value is never presented to user, user
11574 can only find it by guessing, and it does not seem important
11575 to support that. */
11577 /* For each line spec given, delete bps which correspond to it. Do
11578 it in two passes, solely to preserve the current behavior that
11579 from_tty is forced true if we delete more than one
11582 std::vector
<struct breakpoint
*> found
;
11583 for (const auto &sal
: sals
)
11585 const char *sal_fullname
;
11587 /* If exact pc given, clear bpts at that pc.
11588 If line given (pc == 0), clear all bpts on specified line.
11589 If defaulting, clear all bpts on default line
11592 defaulting sal.pc != 0 tests to do
11597 1 0 <can't happen> */
11599 sal_fullname
= (sal
.symtab
== NULL
11600 ? NULL
: symtab_to_fullname (sal
.symtab
));
11602 /* Find all matching breakpoints and add them to 'found'. */
11603 ALL_BREAKPOINTS (b
)
11606 /* Are we going to delete b? */
11607 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11609 struct bp_location
*loc
= b
->loc
;
11610 for (; loc
; loc
= loc
->next
)
11612 /* If the user specified file:line, don't allow a PC
11613 match. This matches historical gdb behavior. */
11614 int pc_match
= (!sal
.explicit_line
11616 && (loc
->pspace
== sal
.pspace
)
11617 && (loc
->address
== sal
.pc
)
11618 && (!section_is_overlay (loc
->section
)
11619 || loc
->section
== sal
.section
));
11620 int line_match
= 0;
11622 if ((default_match
|| sal
.explicit_line
)
11623 && loc
->symtab
!= NULL
11624 && sal_fullname
!= NULL
11625 && sal
.pspace
== loc
->pspace
11626 && loc
->line_number
== sal
.line
11627 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11628 sal_fullname
) == 0)
11631 if (pc_match
|| line_match
)
11640 found
.push_back (b
);
11644 /* Now go thru the 'found' chain and delete them. */
11645 if (found
.empty ())
11648 error (_("No breakpoint at %s."), arg
);
11650 error (_("No breakpoint at this line."));
11653 /* Remove duplicates from the vec. */
11654 std::sort (found
.begin (), found
.end (),
11655 [] (const breakpoint
*a
, const breakpoint
*b
)
11657 return compare_breakpoints (a
, b
) < 0;
11659 found
.erase (std::unique (found
.begin (), found
.end (),
11660 [] (const breakpoint
*a
, const breakpoint
*b
)
11662 return compare_breakpoints (a
, b
) == 0;
11666 if (found
.size () > 1)
11667 from_tty
= 1; /* Always report if deleted more than one. */
11670 if (found
.size () == 1)
11671 printf_unfiltered (_("Deleted breakpoint "));
11673 printf_unfiltered (_("Deleted breakpoints "));
11676 for (breakpoint
*iter
: found
)
11679 printf_unfiltered ("%d ", iter
->number
);
11680 delete_breakpoint (iter
);
11683 putchar_unfiltered ('\n');
11686 /* Delete breakpoint in BS if they are `delete' breakpoints and
11687 all breakpoints that are marked for deletion, whether hit or not.
11688 This is called after any breakpoint is hit, or after errors. */
11691 breakpoint_auto_delete (bpstat bs
)
11693 struct breakpoint
*b
, *b_tmp
;
11695 for (; bs
; bs
= bs
->next
)
11696 if (bs
->breakpoint_at
11697 && bs
->breakpoint_at
->disposition
== disp_del
11699 delete_breakpoint (bs
->breakpoint_at
);
11701 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11703 if (b
->disposition
== disp_del_at_next_stop
)
11704 delete_breakpoint (b
);
11708 /* A comparison function for bp_location AP and BP being interfaced to
11709 qsort. Sort elements primarily by their ADDRESS (no matter what
11710 does breakpoint_address_is_meaningful say for its OWNER),
11711 secondarily by ordering first permanent elements and
11712 terciarily just ensuring the array is sorted stable way despite
11713 qsort being an unstable algorithm. */
11716 bp_locations_compare (const void *ap
, const void *bp
)
11718 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
11719 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
11721 if (a
->address
!= b
->address
)
11722 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11724 /* Sort locations at the same address by their pspace number, keeping
11725 locations of the same inferior (in a multi-inferior environment)
11728 if (a
->pspace
->num
!= b
->pspace
->num
)
11729 return ((a
->pspace
->num
> b
->pspace
->num
)
11730 - (a
->pspace
->num
< b
->pspace
->num
));
11732 /* Sort permanent breakpoints first. */
11733 if (a
->permanent
!= b
->permanent
)
11734 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11736 /* Make the internal GDB representation stable across GDB runs
11737 where A and B memory inside GDB can differ. Breakpoint locations of
11738 the same type at the same address can be sorted in arbitrary order. */
11740 if (a
->owner
->number
!= b
->owner
->number
)
11741 return ((a
->owner
->number
> b
->owner
->number
)
11742 - (a
->owner
->number
< b
->owner
->number
));
11744 return (a
> b
) - (a
< b
);
11747 /* Set bp_locations_placed_address_before_address_max and
11748 bp_locations_shadow_len_after_address_max according to the current
11749 content of the bp_locations array. */
11752 bp_locations_target_extensions_update (void)
11754 struct bp_location
*bl
, **blp_tmp
;
11756 bp_locations_placed_address_before_address_max
= 0;
11757 bp_locations_shadow_len_after_address_max
= 0;
11759 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11761 CORE_ADDR start
, end
, addr
;
11763 if (!bp_location_has_shadow (bl
))
11766 start
= bl
->target_info
.placed_address
;
11767 end
= start
+ bl
->target_info
.shadow_len
;
11769 gdb_assert (bl
->address
>= start
);
11770 addr
= bl
->address
- start
;
11771 if (addr
> bp_locations_placed_address_before_address_max
)
11772 bp_locations_placed_address_before_address_max
= addr
;
11774 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11776 gdb_assert (bl
->address
< end
);
11777 addr
= end
- bl
->address
;
11778 if (addr
> bp_locations_shadow_len_after_address_max
)
11779 bp_locations_shadow_len_after_address_max
= addr
;
11783 /* Download tracepoint locations if they haven't been. */
11786 download_tracepoint_locations (void)
11788 struct breakpoint
*b
;
11789 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11791 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11793 ALL_TRACEPOINTS (b
)
11795 struct bp_location
*bl
;
11796 struct tracepoint
*t
;
11797 int bp_location_downloaded
= 0;
11799 if ((b
->type
== bp_fast_tracepoint
11800 ? !may_insert_fast_tracepoints
11801 : !may_insert_tracepoints
))
11804 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11806 if (target_can_download_tracepoint ())
11807 can_download_tracepoint
= TRIBOOL_TRUE
;
11809 can_download_tracepoint
= TRIBOOL_FALSE
;
11812 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11815 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11817 /* In tracepoint, locations are _never_ duplicated, so
11818 should_be_inserted is equivalent to
11819 unduplicated_should_be_inserted. */
11820 if (!should_be_inserted (bl
) || bl
->inserted
)
11823 switch_to_program_space_and_thread (bl
->pspace
);
11825 target_download_tracepoint (bl
);
11828 bp_location_downloaded
= 1;
11830 t
= (struct tracepoint
*) b
;
11831 t
->number_on_target
= b
->number
;
11832 if (bp_location_downloaded
)
11833 observer_notify_breakpoint_modified (b
);
11837 /* Swap the insertion/duplication state between two locations. */
11840 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11842 const int left_inserted
= left
->inserted
;
11843 const int left_duplicate
= left
->duplicate
;
11844 const int left_needs_update
= left
->needs_update
;
11845 const struct bp_target_info left_target_info
= left
->target_info
;
11847 /* Locations of tracepoints can never be duplicated. */
11848 if (is_tracepoint (left
->owner
))
11849 gdb_assert (!left
->duplicate
);
11850 if (is_tracepoint (right
->owner
))
11851 gdb_assert (!right
->duplicate
);
11853 left
->inserted
= right
->inserted
;
11854 left
->duplicate
= right
->duplicate
;
11855 left
->needs_update
= right
->needs_update
;
11856 left
->target_info
= right
->target_info
;
11857 right
->inserted
= left_inserted
;
11858 right
->duplicate
= left_duplicate
;
11859 right
->needs_update
= left_needs_update
;
11860 right
->target_info
= left_target_info
;
11863 /* Force the re-insertion of the locations at ADDRESS. This is called
11864 once a new/deleted/modified duplicate location is found and we are evaluating
11865 conditions on the target's side. Such conditions need to be updated on
11869 force_breakpoint_reinsertion (struct bp_location
*bl
)
11871 struct bp_location
**locp
= NULL
, **loc2p
;
11872 struct bp_location
*loc
;
11873 CORE_ADDR address
= 0;
11876 address
= bl
->address
;
11877 pspace_num
= bl
->pspace
->num
;
11879 /* This is only meaningful if the target is
11880 evaluating conditions and if the user has
11881 opted for condition evaluation on the target's
11883 if (gdb_evaluates_breakpoint_condition_p ()
11884 || !target_supports_evaluation_of_breakpoint_conditions ())
11887 /* Flag all breakpoint locations with this address and
11888 the same program space as the location
11889 as "its condition has changed". We need to
11890 update the conditions on the target's side. */
11891 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
11895 if (!is_breakpoint (loc
->owner
)
11896 || pspace_num
!= loc
->pspace
->num
)
11899 /* Flag the location appropriately. We use a different state to
11900 let everyone know that we already updated the set of locations
11901 with addr bl->address and program space bl->pspace. This is so
11902 we don't have to keep calling these functions just to mark locations
11903 that have already been marked. */
11904 loc
->condition_changed
= condition_updated
;
11906 /* Free the agent expression bytecode as well. We will compute
11908 loc
->cond_bytecode
.reset ();
11911 /* Called whether new breakpoints are created, or existing breakpoints
11912 deleted, to update the global location list and recompute which
11913 locations are duplicate of which.
11915 The INSERT_MODE flag determines whether locations may not, may, or
11916 shall be inserted now. See 'enum ugll_insert_mode' for more
11920 update_global_location_list (enum ugll_insert_mode insert_mode
)
11922 struct breakpoint
*b
;
11923 struct bp_location
**locp
, *loc
;
11924 /* Last breakpoint location address that was marked for update. */
11925 CORE_ADDR last_addr
= 0;
11926 /* Last breakpoint location program space that was marked for update. */
11927 int last_pspace_num
= -1;
11929 /* Used in the duplicates detection below. When iterating over all
11930 bp_locations, points to the first bp_location of a given address.
11931 Breakpoints and watchpoints of different types are never
11932 duplicates of each other. Keep one pointer for each type of
11933 breakpoint/watchpoint, so we only need to loop over all locations
11935 struct bp_location
*bp_loc_first
; /* breakpoint */
11936 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
11937 struct bp_location
*awp_loc_first
; /* access watchpoint */
11938 struct bp_location
*rwp_loc_first
; /* read watchpoint */
11940 /* Saved former bp_locations array which we compare against the newly
11941 built bp_locations from the current state of ALL_BREAKPOINTS. */
11942 struct bp_location
**old_locp
;
11943 unsigned old_locations_count
;
11944 gdb::unique_xmalloc_ptr
<struct bp_location
*> old_locations (bp_locations
);
11946 old_locations_count
= bp_locations_count
;
11947 bp_locations
= NULL
;
11948 bp_locations_count
= 0;
11950 ALL_BREAKPOINTS (b
)
11951 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11952 bp_locations_count
++;
11954 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
11955 locp
= bp_locations
;
11956 ALL_BREAKPOINTS (b
)
11957 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
11959 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
11960 bp_locations_compare
);
11962 bp_locations_target_extensions_update ();
11964 /* Identify bp_location instances that are no longer present in the
11965 new list, and therefore should be freed. Note that it's not
11966 necessary that those locations should be removed from inferior --
11967 if there's another location at the same address (previously
11968 marked as duplicate), we don't need to remove/insert the
11971 LOCP is kept in sync with OLD_LOCP, each pointing to the current
11972 and former bp_location array state respectively. */
11974 locp
= bp_locations
;
11975 for (old_locp
= old_locations
.get ();
11976 old_locp
< old_locations
.get () + old_locations_count
;
11979 struct bp_location
*old_loc
= *old_locp
;
11980 struct bp_location
**loc2p
;
11982 /* Tells if 'old_loc' is found among the new locations. If
11983 not, we have to free it. */
11984 int found_object
= 0;
11985 /* Tells if the location should remain inserted in the target. */
11986 int keep_in_target
= 0;
11989 /* Skip LOCP entries which will definitely never be needed.
11990 Stop either at or being the one matching OLD_LOC. */
11991 while (locp
< bp_locations
+ bp_locations_count
11992 && (*locp
)->address
< old_loc
->address
)
11996 (loc2p
< bp_locations
+ bp_locations_count
11997 && (*loc2p
)->address
== old_loc
->address
);
12000 /* Check if this is a new/duplicated location or a duplicated
12001 location that had its condition modified. If so, we want to send
12002 its condition to the target if evaluation of conditions is taking
12004 if ((*loc2p
)->condition_changed
== condition_modified
12005 && (last_addr
!= old_loc
->address
12006 || last_pspace_num
!= old_loc
->pspace
->num
))
12008 force_breakpoint_reinsertion (*loc2p
);
12009 last_pspace_num
= old_loc
->pspace
->num
;
12012 if (*loc2p
== old_loc
)
12016 /* We have already handled this address, update it so that we don't
12017 have to go through updates again. */
12018 last_addr
= old_loc
->address
;
12020 /* Target-side condition evaluation: Handle deleted locations. */
12022 force_breakpoint_reinsertion (old_loc
);
12024 /* If this location is no longer present, and inserted, look if
12025 there's maybe a new location at the same address. If so,
12026 mark that one inserted, and don't remove this one. This is
12027 needed so that we don't have a time window where a breakpoint
12028 at certain location is not inserted. */
12030 if (old_loc
->inserted
)
12032 /* If the location is inserted now, we might have to remove
12035 if (found_object
&& should_be_inserted (old_loc
))
12037 /* The location is still present in the location list,
12038 and still should be inserted. Don't do anything. */
12039 keep_in_target
= 1;
12043 /* This location still exists, but it won't be kept in the
12044 target since it may have been disabled. We proceed to
12045 remove its target-side condition. */
12047 /* The location is either no longer present, or got
12048 disabled. See if there's another location at the
12049 same address, in which case we don't need to remove
12050 this one from the target. */
12052 /* OLD_LOC comes from existing struct breakpoint. */
12053 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12056 (loc2p
< bp_locations
+ bp_locations_count
12057 && (*loc2p
)->address
== old_loc
->address
);
12060 struct bp_location
*loc2
= *loc2p
;
12062 if (breakpoint_locations_match (loc2
, old_loc
))
12064 /* Read watchpoint locations are switched to
12065 access watchpoints, if the former are not
12066 supported, but the latter are. */
12067 if (is_hardware_watchpoint (old_loc
->owner
))
12069 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12070 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12073 /* loc2 is a duplicated location. We need to check
12074 if it should be inserted in case it will be
12076 if (loc2
!= old_loc
12077 && unduplicated_should_be_inserted (loc2
))
12079 swap_insertion (old_loc
, loc2
);
12080 keep_in_target
= 1;
12088 if (!keep_in_target
)
12090 if (remove_breakpoint (old_loc
))
12092 /* This is just about all we can do. We could keep
12093 this location on the global list, and try to
12094 remove it next time, but there's no particular
12095 reason why we will succeed next time.
12097 Note that at this point, old_loc->owner is still
12098 valid, as delete_breakpoint frees the breakpoint
12099 only after calling us. */
12100 printf_filtered (_("warning: Error removing "
12101 "breakpoint %d\n"),
12102 old_loc
->owner
->number
);
12110 if (removed
&& target_is_non_stop_p ()
12111 && need_moribund_for_location_type (old_loc
))
12113 /* This location was removed from the target. In
12114 non-stop mode, a race condition is possible where
12115 we've removed a breakpoint, but stop events for that
12116 breakpoint are already queued and will arrive later.
12117 We apply an heuristic to be able to distinguish such
12118 SIGTRAPs from other random SIGTRAPs: we keep this
12119 breakpoint location for a bit, and will retire it
12120 after we see some number of events. The theory here
12121 is that reporting of events should, "on the average",
12122 be fair, so after a while we'll see events from all
12123 threads that have anything of interest, and no longer
12124 need to keep this breakpoint location around. We
12125 don't hold locations forever so to reduce chances of
12126 mistaking a non-breakpoint SIGTRAP for a breakpoint
12129 The heuristic failing can be disastrous on
12130 decr_pc_after_break targets.
12132 On decr_pc_after_break targets, like e.g., x86-linux,
12133 if we fail to recognize a late breakpoint SIGTRAP,
12134 because events_till_retirement has reached 0 too
12135 soon, we'll fail to do the PC adjustment, and report
12136 a random SIGTRAP to the user. When the user resumes
12137 the inferior, it will most likely immediately crash
12138 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12139 corrupted, because of being resumed e.g., in the
12140 middle of a multi-byte instruction, or skipped a
12141 one-byte instruction. This was actually seen happen
12142 on native x86-linux, and should be less rare on
12143 targets that do not support new thread events, like
12144 remote, due to the heuristic depending on
12147 Mistaking a random SIGTRAP for a breakpoint trap
12148 causes similar symptoms (PC adjustment applied when
12149 it shouldn't), but then again, playing with SIGTRAPs
12150 behind the debugger's back is asking for trouble.
12152 Since hardware watchpoint traps are always
12153 distinguishable from other traps, so we don't need to
12154 apply keep hardware watchpoint moribund locations
12155 around. We simply always ignore hardware watchpoint
12156 traps we can no longer explain. */
12158 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12159 old_loc
->owner
= NULL
;
12161 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12165 old_loc
->owner
= NULL
;
12166 decref_bp_location (&old_loc
);
12171 /* Rescan breakpoints at the same address and section, marking the
12172 first one as "first" and any others as "duplicates". This is so
12173 that the bpt instruction is only inserted once. If we have a
12174 permanent breakpoint at the same place as BPT, make that one the
12175 official one, and the rest as duplicates. Permanent breakpoints
12176 are sorted first for the same address.
12178 Do the same for hardware watchpoints, but also considering the
12179 watchpoint's type (regular/access/read) and length. */
12181 bp_loc_first
= NULL
;
12182 wp_loc_first
= NULL
;
12183 awp_loc_first
= NULL
;
12184 rwp_loc_first
= NULL
;
12185 ALL_BP_LOCATIONS (loc
, locp
)
12187 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12189 struct bp_location
**loc_first_p
;
12192 if (!unduplicated_should_be_inserted (loc
)
12193 || !breakpoint_address_is_meaningful (b
)
12194 /* Don't detect duplicate for tracepoint locations because they are
12195 never duplicated. See the comments in field `duplicate' of
12196 `struct bp_location'. */
12197 || is_tracepoint (b
))
12199 /* Clear the condition modification flag. */
12200 loc
->condition_changed
= condition_unchanged
;
12204 if (b
->type
== bp_hardware_watchpoint
)
12205 loc_first_p
= &wp_loc_first
;
12206 else if (b
->type
== bp_read_watchpoint
)
12207 loc_first_p
= &rwp_loc_first
;
12208 else if (b
->type
== bp_access_watchpoint
)
12209 loc_first_p
= &awp_loc_first
;
12211 loc_first_p
= &bp_loc_first
;
12213 if (*loc_first_p
== NULL
12214 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12215 || !breakpoint_locations_match (loc
, *loc_first_p
))
12217 *loc_first_p
= loc
;
12218 loc
->duplicate
= 0;
12220 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12222 loc
->needs_update
= 1;
12223 /* Clear the condition modification flag. */
12224 loc
->condition_changed
= condition_unchanged
;
12230 /* This and the above ensure the invariant that the first location
12231 is not duplicated, and is the inserted one.
12232 All following are marked as duplicated, and are not inserted. */
12234 swap_insertion (loc
, *loc_first_p
);
12235 loc
->duplicate
= 1;
12237 /* Clear the condition modification flag. */
12238 loc
->condition_changed
= condition_unchanged
;
12241 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12243 if (insert_mode
!= UGLL_DONT_INSERT
)
12244 insert_breakpoint_locations ();
12247 /* Even though the caller told us to not insert new
12248 locations, we may still need to update conditions on the
12249 target's side of breakpoints that were already inserted
12250 if the target is evaluating breakpoint conditions. We
12251 only update conditions for locations that are marked
12253 update_inserted_breakpoint_locations ();
12257 if (insert_mode
!= UGLL_DONT_INSERT
)
12258 download_tracepoint_locations ();
12262 breakpoint_retire_moribund (void)
12264 struct bp_location
*loc
;
12267 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12268 if (--(loc
->events_till_retirement
) == 0)
12270 decref_bp_location (&loc
);
12271 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12277 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12282 update_global_location_list (insert_mode
);
12284 CATCH (e
, RETURN_MASK_ERROR
)
12290 /* Clear BKP from a BPS. */
12293 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12297 for (bs
= bps
; bs
; bs
= bs
->next
)
12298 if (bs
->breakpoint_at
== bpt
)
12300 bs
->breakpoint_at
= NULL
;
12301 bs
->old_val
= NULL
;
12302 /* bs->commands will be freed later. */
12306 /* Callback for iterate_over_threads. */
12308 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12310 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12312 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12316 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12320 say_where (struct breakpoint
*b
)
12322 struct value_print_options opts
;
12324 get_user_print_options (&opts
);
12326 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12328 if (b
->loc
== NULL
)
12330 /* For pending locations, the output differs slightly based
12331 on b->extra_string. If this is non-NULL, it contains either
12332 a condition or dprintf arguments. */
12333 if (b
->extra_string
== NULL
)
12335 printf_filtered (_(" (%s) pending."),
12336 event_location_to_string (b
->location
.get ()));
12338 else if (b
->type
== bp_dprintf
)
12340 printf_filtered (_(" (%s,%s) pending."),
12341 event_location_to_string (b
->location
.get ()),
12346 printf_filtered (_(" (%s %s) pending."),
12347 event_location_to_string (b
->location
.get ()),
12353 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12355 printf_filtered (" at ");
12356 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12359 if (b
->loc
->symtab
!= NULL
)
12361 /* If there is a single location, we can print the location
12363 if (b
->loc
->next
== NULL
)
12364 printf_filtered (": file %s, line %d.",
12365 symtab_to_filename_for_display (b
->loc
->symtab
),
12366 b
->loc
->line_number
);
12368 /* This is not ideal, but each location may have a
12369 different file name, and this at least reflects the
12370 real situation somewhat. */
12371 printf_filtered (": %s.",
12372 event_location_to_string (b
->location
.get ()));
12377 struct bp_location
*loc
= b
->loc
;
12379 for (; loc
; loc
= loc
->next
)
12381 printf_filtered (" (%d locations)", n
);
12386 /* Default bp_location_ops methods. */
12389 bp_location_dtor (struct bp_location
*self
)
12391 xfree (self
->function_name
);
12394 static const struct bp_location_ops bp_location_ops
=
12399 /* Destructor for the breakpoint base class. */
12401 breakpoint::~breakpoint ()
12403 xfree (this->cond_string
);
12404 xfree (this->extra_string
);
12405 xfree (this->filter
);
12408 static struct bp_location
*
12409 base_breakpoint_allocate_location (struct breakpoint
*self
)
12411 return new bp_location (&bp_location_ops
, self
);
12415 base_breakpoint_re_set (struct breakpoint
*b
)
12417 /* Nothing to re-set. */
12420 #define internal_error_pure_virtual_called() \
12421 gdb_assert_not_reached ("pure virtual function called")
12424 base_breakpoint_insert_location (struct bp_location
*bl
)
12426 internal_error_pure_virtual_called ();
12430 base_breakpoint_remove_location (struct bp_location
*bl
,
12431 enum remove_bp_reason reason
)
12433 internal_error_pure_virtual_called ();
12437 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12438 const address_space
*aspace
,
12440 const struct target_waitstatus
*ws
)
12442 internal_error_pure_virtual_called ();
12446 base_breakpoint_check_status (bpstat bs
)
12451 /* A "works_in_software_mode" breakpoint_ops method that just internal
12455 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12457 internal_error_pure_virtual_called ();
12460 /* A "resources_needed" breakpoint_ops method that just internal
12464 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12466 internal_error_pure_virtual_called ();
12469 static enum print_stop_action
12470 base_breakpoint_print_it (bpstat bs
)
12472 internal_error_pure_virtual_called ();
12476 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12477 struct ui_out
*uiout
)
12483 base_breakpoint_print_mention (struct breakpoint
*b
)
12485 internal_error_pure_virtual_called ();
12489 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12491 internal_error_pure_virtual_called ();
12495 base_breakpoint_create_sals_from_location
12496 (const struct event_location
*location
,
12497 struct linespec_result
*canonical
,
12498 enum bptype type_wanted
)
12500 internal_error_pure_virtual_called ();
12504 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12505 struct linespec_result
*c
,
12506 gdb::unique_xmalloc_ptr
<char> cond_string
,
12507 gdb::unique_xmalloc_ptr
<char> extra_string
,
12508 enum bptype type_wanted
,
12509 enum bpdisp disposition
,
12511 int task
, int ignore_count
,
12512 const struct breakpoint_ops
*o
,
12513 int from_tty
, int enabled
,
12514 int internal
, unsigned flags
)
12516 internal_error_pure_virtual_called ();
12519 static std::vector
<symtab_and_line
>
12520 base_breakpoint_decode_location (struct breakpoint
*b
,
12521 const struct event_location
*location
,
12522 struct program_space
*search_pspace
)
12524 internal_error_pure_virtual_called ();
12527 /* The default 'explains_signal' method. */
12530 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12535 /* The default "after_condition_true" method. */
12538 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12540 /* Nothing to do. */
12543 struct breakpoint_ops base_breakpoint_ops
=
12545 base_breakpoint_allocate_location
,
12546 base_breakpoint_re_set
,
12547 base_breakpoint_insert_location
,
12548 base_breakpoint_remove_location
,
12549 base_breakpoint_breakpoint_hit
,
12550 base_breakpoint_check_status
,
12551 base_breakpoint_resources_needed
,
12552 base_breakpoint_works_in_software_mode
,
12553 base_breakpoint_print_it
,
12555 base_breakpoint_print_one_detail
,
12556 base_breakpoint_print_mention
,
12557 base_breakpoint_print_recreate
,
12558 base_breakpoint_create_sals_from_location
,
12559 base_breakpoint_create_breakpoints_sal
,
12560 base_breakpoint_decode_location
,
12561 base_breakpoint_explains_signal
,
12562 base_breakpoint_after_condition_true
,
12565 /* Default breakpoint_ops methods. */
12568 bkpt_re_set (struct breakpoint
*b
)
12570 /* FIXME: is this still reachable? */
12571 if (breakpoint_event_location_empty_p (b
))
12573 /* Anything without a location can't be re-set. */
12574 delete_breakpoint (b
);
12578 breakpoint_re_set_default (b
);
12582 bkpt_insert_location (struct bp_location
*bl
)
12584 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12586 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12587 bl
->target_info
.placed_address
= addr
;
12589 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12590 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12592 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12596 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12598 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12599 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12601 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12605 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12606 const address_space
*aspace
, CORE_ADDR bp_addr
,
12607 const struct target_waitstatus
*ws
)
12609 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12610 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12613 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12617 if (overlay_debugging
/* unmapped overlay section */
12618 && section_is_overlay (bl
->section
)
12619 && !section_is_mapped (bl
->section
))
12626 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12627 const address_space
*aspace
, CORE_ADDR bp_addr
,
12628 const struct target_waitstatus
*ws
)
12630 if (dprintf_style
== dprintf_style_agent
12631 && target_can_run_breakpoint_commands ())
12633 /* An agent-style dprintf never causes a stop. If we see a trap
12634 for this address it must be for a breakpoint that happens to
12635 be set at the same address. */
12639 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12643 bkpt_resources_needed (const struct bp_location
*bl
)
12645 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12650 static enum print_stop_action
12651 bkpt_print_it (bpstat bs
)
12653 struct breakpoint
*b
;
12654 const struct bp_location
*bl
;
12656 struct ui_out
*uiout
= current_uiout
;
12658 gdb_assert (bs
->bp_location_at
!= NULL
);
12660 bl
= bs
->bp_location_at
;
12661 b
= bs
->breakpoint_at
;
12663 bp_temp
= b
->disposition
== disp_del
;
12664 if (bl
->address
!= bl
->requested_address
)
12665 breakpoint_adjustment_warning (bl
->requested_address
,
12668 annotate_breakpoint (b
->number
);
12669 maybe_print_thread_hit_breakpoint (uiout
);
12672 uiout
->text ("Temporary breakpoint ");
12674 uiout
->text ("Breakpoint ");
12675 if (uiout
->is_mi_like_p ())
12677 uiout
->field_string ("reason",
12678 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12679 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12681 uiout
->field_int ("bkptno", b
->number
);
12682 uiout
->text (", ");
12684 return PRINT_SRC_AND_LOC
;
12688 bkpt_print_mention (struct breakpoint
*b
)
12690 if (current_uiout
->is_mi_like_p ())
12695 case bp_breakpoint
:
12696 case bp_gnu_ifunc_resolver
:
12697 if (b
->disposition
== disp_del
)
12698 printf_filtered (_("Temporary breakpoint"));
12700 printf_filtered (_("Breakpoint"));
12701 printf_filtered (_(" %d"), b
->number
);
12702 if (b
->type
== bp_gnu_ifunc_resolver
)
12703 printf_filtered (_(" at gnu-indirect-function resolver"));
12705 case bp_hardware_breakpoint
:
12706 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12709 printf_filtered (_("Dprintf %d"), b
->number
);
12717 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12719 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12720 fprintf_unfiltered (fp
, "tbreak");
12721 else if (tp
->type
== bp_breakpoint
)
12722 fprintf_unfiltered (fp
, "break");
12723 else if (tp
->type
== bp_hardware_breakpoint
12724 && tp
->disposition
== disp_del
)
12725 fprintf_unfiltered (fp
, "thbreak");
12726 else if (tp
->type
== bp_hardware_breakpoint
)
12727 fprintf_unfiltered (fp
, "hbreak");
12729 internal_error (__FILE__
, __LINE__
,
12730 _("unhandled breakpoint type %d"), (int) tp
->type
);
12732 fprintf_unfiltered (fp
, " %s",
12733 event_location_to_string (tp
->location
.get ()));
12735 /* Print out extra_string if this breakpoint is pending. It might
12736 contain, for example, conditions that were set by the user. */
12737 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12738 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12740 print_recreate_thread (tp
, fp
);
12744 bkpt_create_sals_from_location (const struct event_location
*location
,
12745 struct linespec_result
*canonical
,
12746 enum bptype type_wanted
)
12748 create_sals_from_location_default (location
, canonical
, type_wanted
);
12752 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12753 struct linespec_result
*canonical
,
12754 gdb::unique_xmalloc_ptr
<char> cond_string
,
12755 gdb::unique_xmalloc_ptr
<char> extra_string
,
12756 enum bptype type_wanted
,
12757 enum bpdisp disposition
,
12759 int task
, int ignore_count
,
12760 const struct breakpoint_ops
*ops
,
12761 int from_tty
, int enabled
,
12762 int internal
, unsigned flags
)
12764 create_breakpoints_sal_default (gdbarch
, canonical
,
12765 std::move (cond_string
),
12766 std::move (extra_string
),
12768 disposition
, thread
, task
,
12769 ignore_count
, ops
, from_tty
,
12770 enabled
, internal
, flags
);
12773 static std::vector
<symtab_and_line
>
12774 bkpt_decode_location (struct breakpoint
*b
,
12775 const struct event_location
*location
,
12776 struct program_space
*search_pspace
)
12778 return decode_location_default (b
, location
, search_pspace
);
12781 /* Virtual table for internal breakpoints. */
12784 internal_bkpt_re_set (struct breakpoint
*b
)
12788 /* Delete overlay event and longjmp master breakpoints; they
12789 will be reset later by breakpoint_re_set. */
12790 case bp_overlay_event
:
12791 case bp_longjmp_master
:
12792 case bp_std_terminate_master
:
12793 case bp_exception_master
:
12794 delete_breakpoint (b
);
12797 /* This breakpoint is special, it's set up when the inferior
12798 starts and we really don't want to touch it. */
12799 case bp_shlib_event
:
12801 /* Like bp_shlib_event, this breakpoint type is special. Once
12802 it is set up, we do not want to touch it. */
12803 case bp_thread_event
:
12809 internal_bkpt_check_status (bpstat bs
)
12811 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12813 /* If requested, stop when the dynamic linker notifies GDB of
12814 events. This allows the user to get control and place
12815 breakpoints in initializer routines for dynamically loaded
12816 objects (among other things). */
12817 bs
->stop
= stop_on_solib_events
;
12818 bs
->print
= stop_on_solib_events
;
12824 static enum print_stop_action
12825 internal_bkpt_print_it (bpstat bs
)
12827 struct breakpoint
*b
;
12829 b
= bs
->breakpoint_at
;
12833 case bp_shlib_event
:
12834 /* Did we stop because the user set the stop_on_solib_events
12835 variable? (If so, we report this as a generic, "Stopped due
12836 to shlib event" message.) */
12837 print_solib_event (0);
12840 case bp_thread_event
:
12841 /* Not sure how we will get here.
12842 GDB should not stop for these breakpoints. */
12843 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12846 case bp_overlay_event
:
12847 /* By analogy with the thread event, GDB should not stop for these. */
12848 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12851 case bp_longjmp_master
:
12852 /* These should never be enabled. */
12853 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12856 case bp_std_terminate_master
:
12857 /* These should never be enabled. */
12858 printf_filtered (_("std::terminate Master Breakpoint: "
12859 "gdb should not stop!\n"));
12862 case bp_exception_master
:
12863 /* These should never be enabled. */
12864 printf_filtered (_("Exception Master Breakpoint: "
12865 "gdb should not stop!\n"));
12869 return PRINT_NOTHING
;
12873 internal_bkpt_print_mention (struct breakpoint
*b
)
12875 /* Nothing to mention. These breakpoints are internal. */
12878 /* Virtual table for momentary breakpoints */
12881 momentary_bkpt_re_set (struct breakpoint
*b
)
12883 /* Keep temporary breakpoints, which can be encountered when we step
12884 over a dlopen call and solib_add is resetting the breakpoints.
12885 Otherwise these should have been blown away via the cleanup chain
12886 or by breakpoint_init_inferior when we rerun the executable. */
12890 momentary_bkpt_check_status (bpstat bs
)
12892 /* Nothing. The point of these breakpoints is causing a stop. */
12895 static enum print_stop_action
12896 momentary_bkpt_print_it (bpstat bs
)
12898 return PRINT_UNKNOWN
;
12902 momentary_bkpt_print_mention (struct breakpoint
*b
)
12904 /* Nothing to mention. These breakpoints are internal. */
12907 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
12909 It gets cleared already on the removal of the first one of such placed
12910 breakpoints. This is OK as they get all removed altogether. */
12912 longjmp_breakpoint::~longjmp_breakpoint ()
12914 thread_info
*tp
= find_thread_global_id (this->thread
);
12917 tp
->initiating_frame
= null_frame_id
;
12920 /* Specific methods for probe breakpoints. */
12923 bkpt_probe_insert_location (struct bp_location
*bl
)
12925 int v
= bkpt_insert_location (bl
);
12929 /* The insertion was successful, now let's set the probe's semaphore
12931 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
12932 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
12941 bkpt_probe_remove_location (struct bp_location
*bl
,
12942 enum remove_bp_reason reason
)
12944 /* Let's clear the semaphore before removing the location. */
12945 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
12946 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
12950 return bkpt_remove_location (bl
, reason
);
12954 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
12955 struct linespec_result
*canonical
,
12956 enum bptype type_wanted
)
12958 struct linespec_sals lsal
;
12960 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
12962 = xstrdup (event_location_to_string (canonical
->location
.get ()));
12963 canonical
->lsals
.push_back (std::move (lsal
));
12966 static std::vector
<symtab_and_line
>
12967 bkpt_probe_decode_location (struct breakpoint
*b
,
12968 const struct event_location
*location
,
12969 struct program_space
*search_pspace
)
12971 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
12973 error (_("probe not found"));
12977 /* The breakpoint_ops structure to be used in tracepoints. */
12980 tracepoint_re_set (struct breakpoint
*b
)
12982 breakpoint_re_set_default (b
);
12986 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
12987 const address_space
*aspace
, CORE_ADDR bp_addr
,
12988 const struct target_waitstatus
*ws
)
12990 /* By definition, the inferior does not report stops at
12996 tracepoint_print_one_detail (const struct breakpoint
*self
,
12997 struct ui_out
*uiout
)
12999 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13000 if (tp
->static_trace_marker_id
)
13002 gdb_assert (self
->type
== bp_static_tracepoint
);
13004 uiout
->text ("\tmarker id is ");
13005 uiout
->field_string ("static-tracepoint-marker-string-id",
13006 tp
->static_trace_marker_id
);
13007 uiout
->text ("\n");
13012 tracepoint_print_mention (struct breakpoint
*b
)
13014 if (current_uiout
->is_mi_like_p ())
13019 case bp_tracepoint
:
13020 printf_filtered (_("Tracepoint"));
13021 printf_filtered (_(" %d"), b
->number
);
13023 case bp_fast_tracepoint
:
13024 printf_filtered (_("Fast tracepoint"));
13025 printf_filtered (_(" %d"), b
->number
);
13027 case bp_static_tracepoint
:
13028 printf_filtered (_("Static tracepoint"));
13029 printf_filtered (_(" %d"), b
->number
);
13032 internal_error (__FILE__
, __LINE__
,
13033 _("unhandled tracepoint type %d"), (int) b
->type
);
13040 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13042 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13044 if (self
->type
== bp_fast_tracepoint
)
13045 fprintf_unfiltered (fp
, "ftrace");
13046 else if (self
->type
== bp_static_tracepoint
)
13047 fprintf_unfiltered (fp
, "strace");
13048 else if (self
->type
== bp_tracepoint
)
13049 fprintf_unfiltered (fp
, "trace");
13051 internal_error (__FILE__
, __LINE__
,
13052 _("unhandled tracepoint type %d"), (int) self
->type
);
13054 fprintf_unfiltered (fp
, " %s",
13055 event_location_to_string (self
->location
.get ()));
13056 print_recreate_thread (self
, fp
);
13058 if (tp
->pass_count
)
13059 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13063 tracepoint_create_sals_from_location (const struct event_location
*location
,
13064 struct linespec_result
*canonical
,
13065 enum bptype type_wanted
)
13067 create_sals_from_location_default (location
, canonical
, type_wanted
);
13071 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13072 struct linespec_result
*canonical
,
13073 gdb::unique_xmalloc_ptr
<char> cond_string
,
13074 gdb::unique_xmalloc_ptr
<char> extra_string
,
13075 enum bptype type_wanted
,
13076 enum bpdisp disposition
,
13078 int task
, int ignore_count
,
13079 const struct breakpoint_ops
*ops
,
13080 int from_tty
, int enabled
,
13081 int internal
, unsigned flags
)
13083 create_breakpoints_sal_default (gdbarch
, canonical
,
13084 std::move (cond_string
),
13085 std::move (extra_string
),
13087 disposition
, thread
, task
,
13088 ignore_count
, ops
, from_tty
,
13089 enabled
, internal
, flags
);
13092 static std::vector
<symtab_and_line
>
13093 tracepoint_decode_location (struct breakpoint
*b
,
13094 const struct event_location
*location
,
13095 struct program_space
*search_pspace
)
13097 return decode_location_default (b
, location
, search_pspace
);
13100 struct breakpoint_ops tracepoint_breakpoint_ops
;
13102 /* The breakpoint_ops structure to be use on tracepoints placed in a
13106 tracepoint_probe_create_sals_from_location
13107 (const struct event_location
*location
,
13108 struct linespec_result
*canonical
,
13109 enum bptype type_wanted
)
13111 /* We use the same method for breakpoint on probes. */
13112 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13115 static std::vector
<symtab_and_line
>
13116 tracepoint_probe_decode_location (struct breakpoint
*b
,
13117 const struct event_location
*location
,
13118 struct program_space
*search_pspace
)
13120 /* We use the same method for breakpoint on probes. */
13121 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13124 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13126 /* Dprintf breakpoint_ops methods. */
13129 dprintf_re_set (struct breakpoint
*b
)
13131 breakpoint_re_set_default (b
);
13133 /* extra_string should never be non-NULL for dprintf. */
13134 gdb_assert (b
->extra_string
!= NULL
);
13136 /* 1 - connect to target 1, that can run breakpoint commands.
13137 2 - create a dprintf, which resolves fine.
13138 3 - disconnect from target 1
13139 4 - connect to target 2, that can NOT run breakpoint commands.
13141 After steps #3/#4, you'll want the dprintf command list to
13142 be updated, because target 1 and 2 may well return different
13143 answers for target_can_run_breakpoint_commands().
13144 Given absence of finer grained resetting, we get to do
13145 it all the time. */
13146 if (b
->extra_string
!= NULL
)
13147 update_dprintf_command_list (b
);
13150 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13153 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13155 fprintf_unfiltered (fp
, "dprintf %s,%s",
13156 event_location_to_string (tp
->location
.get ()),
13158 print_recreate_thread (tp
, fp
);
13161 /* Implement the "after_condition_true" breakpoint_ops method for
13164 dprintf's are implemented with regular commands in their command
13165 list, but we run the commands here instead of before presenting the
13166 stop to the user, as dprintf's don't actually cause a stop. This
13167 also makes it so that the commands of multiple dprintfs at the same
13168 address are all handled. */
13171 dprintf_after_condition_true (struct bpstats
*bs
)
13173 struct bpstats tmp_bs
;
13174 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13176 /* dprintf's never cause a stop. This wasn't set in the
13177 check_status hook instead because that would make the dprintf's
13178 condition not be evaluated. */
13181 /* Run the command list here. Take ownership of it instead of
13182 copying. We never want these commands to run later in
13183 bpstat_do_actions, if a breakpoint that causes a stop happens to
13184 be set at same address as this dprintf, or even if running the
13185 commands here throws. */
13186 tmp_bs
.commands
= bs
->commands
;
13187 bs
->commands
= NULL
;
13189 bpstat_do_actions_1 (&tmp_bs_p
);
13191 /* 'tmp_bs.commands' will usually be NULL by now, but
13192 bpstat_do_actions_1 may return early without processing the whole
13196 /* The breakpoint_ops structure to be used on static tracepoints with
13200 strace_marker_create_sals_from_location (const struct event_location
*location
,
13201 struct linespec_result
*canonical
,
13202 enum bptype type_wanted
)
13204 struct linespec_sals lsal
;
13205 const char *arg_start
, *arg
;
13207 arg
= arg_start
= get_linespec_location (location
);
13208 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13210 std::string
str (arg_start
, arg
- arg_start
);
13211 const char *ptr
= str
.c_str ();
13212 canonical
->location
= new_linespec_location (&ptr
);
13215 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13216 canonical
->lsals
.push_back (std::move (lsal
));
13220 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13221 struct linespec_result
*canonical
,
13222 gdb::unique_xmalloc_ptr
<char> cond_string
,
13223 gdb::unique_xmalloc_ptr
<char> extra_string
,
13224 enum bptype type_wanted
,
13225 enum bpdisp disposition
,
13227 int task
, int ignore_count
,
13228 const struct breakpoint_ops
*ops
,
13229 int from_tty
, int enabled
,
13230 int internal
, unsigned flags
)
13232 const linespec_sals
&lsal
= canonical
->lsals
[0];
13234 /* If the user is creating a static tracepoint by marker id
13235 (strace -m MARKER_ID), then store the sals index, so that
13236 breakpoint_re_set can try to match up which of the newly
13237 found markers corresponds to this one, and, don't try to
13238 expand multiple locations for each sal, given than SALS
13239 already should contain all sals for MARKER_ID. */
13241 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13243 event_location_up location
13244 = copy_event_location (canonical
->location
.get ());
13246 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13247 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13248 std::move (location
), NULL
,
13249 std::move (cond_string
),
13250 std::move (extra_string
),
13251 type_wanted
, disposition
,
13252 thread
, task
, ignore_count
, ops
,
13253 from_tty
, enabled
, internal
, flags
,
13254 canonical
->special_display
);
13255 /* Given that its possible to have multiple markers with
13256 the same string id, if the user is creating a static
13257 tracepoint by marker id ("strace -m MARKER_ID"), then
13258 store the sals index, so that breakpoint_re_set can
13259 try to match up which of the newly found markers
13260 corresponds to this one */
13261 tp
->static_trace_marker_id_idx
= i
;
13263 install_breakpoint (internal
, std::move (tp
), 0);
13267 static std::vector
<symtab_and_line
>
13268 strace_marker_decode_location (struct breakpoint
*b
,
13269 const struct event_location
*location
,
13270 struct program_space
*search_pspace
)
13272 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13273 const char *s
= get_linespec_location (location
);
13275 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13276 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13278 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13283 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13286 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13289 strace_marker_p (struct breakpoint
*b
)
13291 return b
->ops
== &strace_marker_breakpoint_ops
;
13294 /* Delete a breakpoint and clean up all traces of it in the data
13298 delete_breakpoint (struct breakpoint
*bpt
)
13300 struct breakpoint
*b
;
13302 gdb_assert (bpt
!= NULL
);
13304 /* Has this bp already been deleted? This can happen because
13305 multiple lists can hold pointers to bp's. bpstat lists are
13308 One example of this happening is a watchpoint's scope bp. When
13309 the scope bp triggers, we notice that the watchpoint is out of
13310 scope, and delete it. We also delete its scope bp. But the
13311 scope bp is marked "auto-deleting", and is already on a bpstat.
13312 That bpstat is then checked for auto-deleting bp's, which are
13315 A real solution to this problem might involve reference counts in
13316 bp's, and/or giving them pointers back to their referencing
13317 bpstat's, and teaching delete_breakpoint to only free a bp's
13318 storage when no more references were extent. A cheaper bandaid
13320 if (bpt
->type
== bp_none
)
13323 /* At least avoid this stale reference until the reference counting
13324 of breakpoints gets resolved. */
13325 if (bpt
->related_breakpoint
!= bpt
)
13327 struct breakpoint
*related
;
13328 struct watchpoint
*w
;
13330 if (bpt
->type
== bp_watchpoint_scope
)
13331 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13332 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13333 w
= (struct watchpoint
*) bpt
;
13337 watchpoint_del_at_next_stop (w
);
13339 /* Unlink bpt from the bpt->related_breakpoint ring. */
13340 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13341 related
= related
->related_breakpoint
);
13342 related
->related_breakpoint
= bpt
->related_breakpoint
;
13343 bpt
->related_breakpoint
= bpt
;
13346 /* watch_command_1 creates a watchpoint but only sets its number if
13347 update_watchpoint succeeds in creating its bp_locations. If there's
13348 a problem in that process, we'll be asked to delete the half-created
13349 watchpoint. In that case, don't announce the deletion. */
13351 observer_notify_breakpoint_deleted (bpt
);
13353 if (breakpoint_chain
== bpt
)
13354 breakpoint_chain
= bpt
->next
;
13356 ALL_BREAKPOINTS (b
)
13357 if (b
->next
== bpt
)
13359 b
->next
= bpt
->next
;
13363 /* Be sure no bpstat's are pointing at the breakpoint after it's
13365 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13366 in all threads for now. Note that we cannot just remove bpstats
13367 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13368 commands are associated with the bpstat; if we remove it here,
13369 then the later call to bpstat_do_actions (&stop_bpstat); in
13370 event-top.c won't do anything, and temporary breakpoints with
13371 commands won't work. */
13373 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13375 /* Now that breakpoint is removed from breakpoint list, update the
13376 global location list. This will remove locations that used to
13377 belong to this breakpoint. Do this before freeing the breakpoint
13378 itself, since remove_breakpoint looks at location's owner. It
13379 might be better design to have location completely
13380 self-contained, but it's not the case now. */
13381 update_global_location_list (UGLL_DONT_INSERT
);
13383 /* On the chance that someone will soon try again to delete this
13384 same bp, we mark it as deleted before freeing its storage. */
13385 bpt
->type
= bp_none
;
13390 do_delete_breakpoint_cleanup (void *b
)
13392 delete_breakpoint ((struct breakpoint
*) b
);
13396 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13398 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13401 /* Iterator function to call a user-provided callback function once
13402 for each of B and its related breakpoints. */
13405 iterate_over_related_breakpoints (struct breakpoint
*b
,
13406 gdb::function_view
<void (breakpoint
*)> function
)
13408 struct breakpoint
*related
;
13413 struct breakpoint
*next
;
13415 /* FUNCTION may delete RELATED. */
13416 next
= related
->related_breakpoint
;
13418 if (next
== related
)
13420 /* RELATED is the last ring entry. */
13421 function (related
);
13423 /* FUNCTION may have deleted it, so we'd never reach back to
13424 B. There's nothing left to do anyway, so just break
13429 function (related
);
13433 while (related
!= b
);
13437 delete_command (const char *arg
, int from_tty
)
13439 struct breakpoint
*b
, *b_tmp
;
13445 int breaks_to_delete
= 0;
13447 /* Delete all breakpoints if no argument. Do not delete
13448 internal breakpoints, these have to be deleted with an
13449 explicit breakpoint number argument. */
13450 ALL_BREAKPOINTS (b
)
13451 if (user_breakpoint_p (b
))
13453 breaks_to_delete
= 1;
13457 /* Ask user only if there are some breakpoints to delete. */
13459 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13461 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13462 if (user_breakpoint_p (b
))
13463 delete_breakpoint (b
);
13467 map_breakpoint_numbers
13468 (arg
, [&] (breakpoint
*b
)
13470 iterate_over_related_breakpoints (b
, delete_breakpoint
);
13474 /* Return true if all locations of B bound to PSPACE are pending. If
13475 PSPACE is NULL, all locations of all program spaces are
13479 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13481 struct bp_location
*loc
;
13483 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13484 if ((pspace
== NULL
13485 || loc
->pspace
== pspace
)
13486 && !loc
->shlib_disabled
13487 && !loc
->pspace
->executing_startup
)
13492 /* Subroutine of update_breakpoint_locations to simplify it.
13493 Return non-zero if multiple fns in list LOC have the same name.
13494 Null names are ignored. */
13497 ambiguous_names_p (struct bp_location
*loc
)
13499 struct bp_location
*l
;
13500 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13501 (int (*) (const void *,
13502 const void *)) streq
,
13503 NULL
, xcalloc
, xfree
);
13505 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13508 const char *name
= l
->function_name
;
13510 /* Allow for some names to be NULL, ignore them. */
13514 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13516 /* NOTE: We can assume slot != NULL here because xcalloc never
13520 htab_delete (htab
);
13526 htab_delete (htab
);
13530 /* When symbols change, it probably means the sources changed as well,
13531 and it might mean the static tracepoint markers are no longer at
13532 the same address or line numbers they used to be at last we
13533 checked. Losing your static tracepoints whenever you rebuild is
13534 undesirable. This function tries to resync/rematch gdb static
13535 tracepoints with the markers on the target, for static tracepoints
13536 that have not been set by marker id. Static tracepoint that have
13537 been set by marker id are reset by marker id in breakpoint_re_set.
13540 1) For a tracepoint set at a specific address, look for a marker at
13541 the old PC. If one is found there, assume to be the same marker.
13542 If the name / string id of the marker found is different from the
13543 previous known name, assume that means the user renamed the marker
13544 in the sources, and output a warning.
13546 2) For a tracepoint set at a given line number, look for a marker
13547 at the new address of the old line number. If one is found there,
13548 assume to be the same marker. If the name / string id of the
13549 marker found is different from the previous known name, assume that
13550 means the user renamed the marker in the sources, and output a
13553 3) If a marker is no longer found at the same address or line, it
13554 may mean the marker no longer exists. But it may also just mean
13555 the code changed a bit. Maybe the user added a few lines of code
13556 that made the marker move up or down (in line number terms). Ask
13557 the target for info about the marker with the string id as we knew
13558 it. If found, update line number and address in the matching
13559 static tracepoint. This will get confused if there's more than one
13560 marker with the same ID (possible in UST, although unadvised
13561 precisely because it confuses tools). */
13563 static struct symtab_and_line
13564 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13566 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13567 struct static_tracepoint_marker marker
;
13572 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13574 if (target_static_tracepoint_marker_at (pc
, &marker
))
13576 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13577 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13579 tp
->static_trace_marker_id
, marker
.str_id
);
13581 xfree (tp
->static_trace_marker_id
);
13582 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13583 release_static_tracepoint_marker (&marker
);
13588 /* Old marker wasn't found on target at lineno. Try looking it up
13590 if (!sal
.explicit_pc
13592 && sal
.symtab
!= NULL
13593 && tp
->static_trace_marker_id
!= NULL
)
13595 VEC(static_tracepoint_marker_p
) *markers
;
13598 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13600 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13602 struct symbol
*sym
;
13603 struct static_tracepoint_marker
*tpmarker
;
13604 struct ui_out
*uiout
= current_uiout
;
13605 struct explicit_location explicit_loc
;
13607 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13609 xfree (tp
->static_trace_marker_id
);
13610 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13612 warning (_("marker for static tracepoint %d (%s) not "
13613 "found at previous line number"),
13614 b
->number
, tp
->static_trace_marker_id
);
13616 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13617 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13618 uiout
->text ("Now in ");
13621 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
13622 uiout
->text (" at ");
13624 uiout
->field_string ("file",
13625 symtab_to_filename_for_display (sal2
.symtab
));
13628 if (uiout
->is_mi_like_p ())
13630 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13632 uiout
->field_string ("fullname", fullname
);
13635 uiout
->field_int ("line", sal2
.line
);
13636 uiout
->text ("\n");
13638 b
->loc
->line_number
= sal2
.line
;
13639 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13641 b
->location
.reset (NULL
);
13642 initialize_explicit_location (&explicit_loc
);
13643 explicit_loc
.source_filename
13644 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13645 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13646 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13647 b
->location
= new_explicit_location (&explicit_loc
);
13649 /* Might be nice to check if function changed, and warn if
13652 release_static_tracepoint_marker (tpmarker
);
13658 /* Returns 1 iff locations A and B are sufficiently same that
13659 we don't need to report breakpoint as changed. */
13662 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13666 if (a
->address
!= b
->address
)
13669 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13672 if (a
->enabled
!= b
->enabled
)
13679 if ((a
== NULL
) != (b
== NULL
))
13685 /* Split all locations of B that are bound to PSPACE out of B's
13686 location list to a separate list and return that list's head. If
13687 PSPACE is NULL, hoist out all locations of B. */
13689 static struct bp_location
*
13690 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13692 struct bp_location head
;
13693 struct bp_location
*i
= b
->loc
;
13694 struct bp_location
**i_link
= &b
->loc
;
13695 struct bp_location
*hoisted
= &head
;
13697 if (pspace
== NULL
)
13708 if (i
->pspace
== pspace
)
13723 /* Create new breakpoint locations for B (a hardware or software
13724 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13725 zero, then B is a ranged breakpoint. Only recreates locations for
13726 FILTER_PSPACE. Locations of other program spaces are left
13730 update_breakpoint_locations (struct breakpoint
*b
,
13731 struct program_space
*filter_pspace
,
13732 gdb::array_view
<const symtab_and_line
> sals
,
13733 gdb::array_view
<const symtab_and_line
> sals_end
)
13736 struct bp_location
*existing_locations
;
13738 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13740 /* Ranged breakpoints have only one start location and one end
13742 b
->enable_state
= bp_disabled
;
13743 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13744 "multiple locations found\n"),
13749 /* If there's no new locations, and all existing locations are
13750 pending, don't do anything. This optimizes the common case where
13751 all locations are in the same shared library, that was unloaded.
13752 We'd like to retain the location, so that when the library is
13753 loaded again, we don't loose the enabled/disabled status of the
13754 individual locations. */
13755 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13758 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13760 for (const auto &sal
: sals
)
13762 struct bp_location
*new_loc
;
13764 switch_to_program_space_and_thread (sal
.pspace
);
13766 new_loc
= add_location_to_breakpoint (b
, &sal
);
13768 /* Reparse conditions, they might contain references to the
13770 if (b
->cond_string
!= NULL
)
13774 s
= b
->cond_string
;
13777 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13778 block_for_pc (sal
.pc
),
13781 CATCH (e
, RETURN_MASK_ERROR
)
13783 warning (_("failed to reevaluate condition "
13784 "for breakpoint %d: %s"),
13785 b
->number
, e
.message
);
13786 new_loc
->enabled
= 0;
13791 if (!sals_end
.empty ())
13793 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13795 new_loc
->length
= end
- sals
[0].pc
+ 1;
13799 /* If possible, carry over 'disable' status from existing
13802 struct bp_location
*e
= existing_locations
;
13803 /* If there are multiple breakpoints with the same function name,
13804 e.g. for inline functions, comparing function names won't work.
13805 Instead compare pc addresses; this is just a heuristic as things
13806 may have moved, but in practice it gives the correct answer
13807 often enough until a better solution is found. */
13808 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13810 for (; e
; e
= e
->next
)
13812 if (!e
->enabled
&& e
->function_name
)
13814 struct bp_location
*l
= b
->loc
;
13815 if (have_ambiguous_names
)
13817 for (; l
; l
= l
->next
)
13818 if (breakpoint_locations_match (e
, l
))
13826 for (; l
; l
= l
->next
)
13827 if (l
->function_name
13828 && strcmp (e
->function_name
, l
->function_name
) == 0)
13838 if (!locations_are_equal (existing_locations
, b
->loc
))
13839 observer_notify_breakpoint_modified (b
);
13842 /* Find the SaL locations corresponding to the given LOCATION.
13843 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13845 static std::vector
<symtab_and_line
>
13846 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13847 struct program_space
*search_pspace
, int *found
)
13849 struct gdb_exception exception
= exception_none
;
13851 gdb_assert (b
->ops
!= NULL
);
13853 std::vector
<symtab_and_line
> sals
;
13857 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13859 CATCH (e
, RETURN_MASK_ERROR
)
13861 int not_found_and_ok
= 0;
13865 /* For pending breakpoints, it's expected that parsing will
13866 fail until the right shared library is loaded. User has
13867 already told to create pending breakpoints and don't need
13868 extra messages. If breakpoint is in bp_shlib_disabled
13869 state, then user already saw the message about that
13870 breakpoint being disabled, and don't want to see more
13872 if (e
.error
== NOT_FOUND_ERROR
13873 && (b
->condition_not_parsed
13875 && search_pspace
!= NULL
13876 && b
->loc
->pspace
!= search_pspace
)
13877 || (b
->loc
&& b
->loc
->shlib_disabled
)
13878 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
13879 || b
->enable_state
== bp_disabled
))
13880 not_found_and_ok
= 1;
13882 if (!not_found_and_ok
)
13884 /* We surely don't want to warn about the same breakpoint
13885 10 times. One solution, implemented here, is disable
13886 the breakpoint on error. Another solution would be to
13887 have separate 'warning emitted' flag. Since this
13888 happens only when a binary has changed, I don't know
13889 which approach is better. */
13890 b
->enable_state
= bp_disabled
;
13891 throw_exception (e
);
13896 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
13898 for (auto &sal
: sals
)
13899 resolve_sal_pc (&sal
);
13900 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
13902 char *cond_string
, *extra_string
;
13905 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
13906 &cond_string
, &thread
, &task
,
13908 gdb_assert (b
->cond_string
== NULL
);
13910 b
->cond_string
= cond_string
;
13911 b
->thread
= thread
;
13915 xfree (b
->extra_string
);
13916 b
->extra_string
= extra_string
;
13918 b
->condition_not_parsed
= 0;
13921 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
13922 sals
[0] = update_static_tracepoint (b
, sals
[0]);
13932 /* The default re_set method, for typical hardware or software
13933 breakpoints. Reevaluate the breakpoint and recreate its
13937 breakpoint_re_set_default (struct breakpoint
*b
)
13939 struct program_space
*filter_pspace
= current_program_space
;
13940 std::vector
<symtab_and_line
> expanded
, expanded_end
;
13943 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
13944 filter_pspace
, &found
);
13946 expanded
= std::move (sals
);
13948 if (b
->location_range_end
!= NULL
)
13950 std::vector
<symtab_and_line
> sals_end
13951 = location_to_sals (b
, b
->location_range_end
.get (),
13952 filter_pspace
, &found
);
13954 expanded_end
= std::move (sals_end
);
13957 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
13960 /* Default method for creating SALs from an address string. It basically
13961 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
13964 create_sals_from_location_default (const struct event_location
*location
,
13965 struct linespec_result
*canonical
,
13966 enum bptype type_wanted
)
13968 parse_breakpoint_sals (location
, canonical
);
13971 /* Call create_breakpoints_sal for the given arguments. This is the default
13972 function for the `create_breakpoints_sal' method of
13976 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
13977 struct linespec_result
*canonical
,
13978 gdb::unique_xmalloc_ptr
<char> cond_string
,
13979 gdb::unique_xmalloc_ptr
<char> extra_string
,
13980 enum bptype type_wanted
,
13981 enum bpdisp disposition
,
13983 int task
, int ignore_count
,
13984 const struct breakpoint_ops
*ops
,
13985 int from_tty
, int enabled
,
13986 int internal
, unsigned flags
)
13988 create_breakpoints_sal (gdbarch
, canonical
,
13989 std::move (cond_string
),
13990 std::move (extra_string
),
13991 type_wanted
, disposition
,
13992 thread
, task
, ignore_count
, ops
, from_tty
,
13993 enabled
, internal
, flags
);
13996 /* Decode the line represented by S by calling decode_line_full. This is the
13997 default function for the `decode_location' method of breakpoint_ops. */
13999 static std::vector
<symtab_and_line
>
14000 decode_location_default (struct breakpoint
*b
,
14001 const struct event_location
*location
,
14002 struct program_space
*search_pspace
)
14004 struct linespec_result canonical
;
14006 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14007 (struct symtab
*) NULL
, 0,
14008 &canonical
, multiple_symbols_all
,
14011 /* We should get 0 or 1 resulting SALs. */
14012 gdb_assert (canonical
.lsals
.size () < 2);
14014 if (!canonical
.lsals
.empty ())
14016 const linespec_sals
&lsal
= canonical
.lsals
[0];
14017 return std::move (lsal
.sals
);
14022 /* Reset a breakpoint. */
14025 breakpoint_re_set_one (breakpoint
*b
)
14027 input_radix
= b
->input_radix
;
14028 set_language (b
->language
);
14030 b
->ops
->re_set (b
);
14033 /* Re-set breakpoint locations for the current program space.
14034 Locations bound to other program spaces are left untouched. */
14037 breakpoint_re_set (void)
14039 struct breakpoint
*b
, *b_tmp
;
14042 scoped_restore_current_language save_language
;
14043 scoped_restore save_input_radix
= make_scoped_restore (&input_radix
);
14044 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
14046 /* Note: we must not try to insert locations until after all
14047 breakpoints have been re-set. Otherwise, e.g., when re-setting
14048 breakpoint 1, we'd insert the locations of breakpoint 2, which
14049 hadn't been re-set yet, and thus may have stale locations. */
14051 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14055 breakpoint_re_set_one (b
);
14057 CATCH (ex
, RETURN_MASK_ALL
)
14059 exception_fprintf (gdb_stderr
, ex
,
14060 "Error in re-setting breakpoint %d: ",
14066 jit_breakpoint_re_set ();
14069 create_overlay_event_breakpoint ();
14070 create_longjmp_master_breakpoint ();
14071 create_std_terminate_master_breakpoint ();
14072 create_exception_master_breakpoint ();
14074 /* Now we can insert. */
14075 update_global_location_list (UGLL_MAY_INSERT
);
14078 /* Reset the thread number of this breakpoint:
14080 - If the breakpoint is for all threads, leave it as-is.
14081 - Else, reset it to the current thread for inferior_ptid. */
14083 breakpoint_re_set_thread (struct breakpoint
*b
)
14085 if (b
->thread
!= -1)
14087 if (in_thread_list (inferior_ptid
))
14088 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14090 /* We're being called after following a fork. The new fork is
14091 selected as current, and unless this was a vfork will have a
14092 different program space from the original thread. Reset that
14094 b
->loc
->pspace
= current_program_space
;
14098 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14099 If from_tty is nonzero, it prints a message to that effect,
14100 which ends with a period (no newline). */
14103 set_ignore_count (int bptnum
, int count
, int from_tty
)
14105 struct breakpoint
*b
;
14110 ALL_BREAKPOINTS (b
)
14111 if (b
->number
== bptnum
)
14113 if (is_tracepoint (b
))
14115 if (from_tty
&& count
!= 0)
14116 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14121 b
->ignore_count
= count
;
14125 printf_filtered (_("Will stop next time "
14126 "breakpoint %d is reached."),
14128 else if (count
== 1)
14129 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14132 printf_filtered (_("Will ignore next %d "
14133 "crossings of breakpoint %d."),
14136 observer_notify_breakpoint_modified (b
);
14140 error (_("No breakpoint number %d."), bptnum
);
14143 /* Command to set ignore-count of breakpoint N to COUNT. */
14146 ignore_command (char *args
, int from_tty
)
14152 error_no_arg (_("a breakpoint number"));
14154 num
= get_number (&p
);
14156 error (_("bad breakpoint number: '%s'"), args
);
14158 error (_("Second argument (specified ignore-count) is missing."));
14160 set_ignore_count (num
,
14161 longest_to_int (value_as_long (parse_and_eval (p
))),
14164 printf_filtered ("\n");
14167 /* Call FUNCTION on each of the breakpoints
14168 whose numbers are given in ARGS. */
14171 map_breakpoint_numbers (const char *args
,
14172 gdb::function_view
<void (breakpoint
*)> function
)
14175 struct breakpoint
*b
, *tmp
;
14177 if (args
== 0 || *args
== '\0')
14178 error_no_arg (_("one or more breakpoint numbers"));
14180 number_or_range_parser
parser (args
);
14182 while (!parser
.finished ())
14184 const char *p
= parser
.cur_tok ();
14185 bool match
= false;
14187 num
= parser
.get_number ();
14190 warning (_("bad breakpoint number at or near '%s'"), p
);
14194 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14195 if (b
->number
== num
)
14202 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14207 static struct bp_location
*
14208 find_location_by_number (const char *number
)
14213 struct breakpoint
*b
;
14214 struct bp_location
*loc
;
14217 bp_num
= get_number_trailer (&p1
, '.');
14218 if (bp_num
== 0 || p1
[0] != '.')
14219 error (_("Bad breakpoint number '%s'"), number
);
14221 ALL_BREAKPOINTS (b
)
14222 if (b
->number
== bp_num
)
14227 if (!b
|| b
->number
!= bp_num
)
14228 error (_("Bad breakpoint number '%s'"), number
);
14230 /* Skip the dot. */
14232 const char *save
= p1
;
14233 loc_num
= get_number (&p1
);
14235 error (_("Bad breakpoint location number '%s'"), number
);
14239 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14242 error (_("Bad breakpoint location number '%s'"), save
);
14248 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14249 If from_tty is nonzero, it prints a message to that effect,
14250 which ends with a period (no newline). */
14253 disable_breakpoint (struct breakpoint
*bpt
)
14255 /* Never disable a watchpoint scope breakpoint; we want to
14256 hit them when we leave scope so we can delete both the
14257 watchpoint and its scope breakpoint at that time. */
14258 if (bpt
->type
== bp_watchpoint_scope
)
14261 bpt
->enable_state
= bp_disabled
;
14263 /* Mark breakpoint locations modified. */
14264 mark_breakpoint_modified (bpt
);
14266 if (target_supports_enable_disable_tracepoint ()
14267 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14269 struct bp_location
*location
;
14271 for (location
= bpt
->loc
; location
; location
= location
->next
)
14272 target_disable_tracepoint (location
);
14275 update_global_location_list (UGLL_DONT_INSERT
);
14277 observer_notify_breakpoint_modified (bpt
);
14281 disable_command (const char *args
, int from_tty
)
14285 struct breakpoint
*bpt
;
14287 ALL_BREAKPOINTS (bpt
)
14288 if (user_breakpoint_p (bpt
))
14289 disable_breakpoint (bpt
);
14293 std::string num
= extract_arg (&args
);
14295 while (!num
.empty ())
14297 if (num
.find ('.') != std::string::npos
)
14299 struct bp_location
*loc
= find_location_by_number (num
.c_str ());
14306 mark_breakpoint_location_modified (loc
);
14308 if (target_supports_enable_disable_tracepoint ()
14309 && current_trace_status ()->running
&& loc
->owner
14310 && is_tracepoint (loc
->owner
))
14311 target_disable_tracepoint (loc
);
14313 update_global_location_list (UGLL_DONT_INSERT
);
14316 map_breakpoint_numbers
14317 (num
.c_str (), [&] (breakpoint
*b
)
14319 iterate_over_related_breakpoints (b
, disable_breakpoint
);
14321 num
= extract_arg (&args
);
14327 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14330 int target_resources_ok
;
14332 if (bpt
->type
== bp_hardware_breakpoint
)
14335 i
= hw_breakpoint_used_count ();
14336 target_resources_ok
=
14337 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14339 if (target_resources_ok
== 0)
14340 error (_("No hardware breakpoint support in the target."));
14341 else if (target_resources_ok
< 0)
14342 error (_("Hardware breakpoints used exceeds limit."));
14345 if (is_watchpoint (bpt
))
14347 /* Initialize it just to avoid a GCC false warning. */
14348 enum enable_state orig_enable_state
= bp_disabled
;
14352 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14354 orig_enable_state
= bpt
->enable_state
;
14355 bpt
->enable_state
= bp_enabled
;
14356 update_watchpoint (w
, 1 /* reparse */);
14358 CATCH (e
, RETURN_MASK_ALL
)
14360 bpt
->enable_state
= orig_enable_state
;
14361 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14368 bpt
->enable_state
= bp_enabled
;
14370 /* Mark breakpoint locations modified. */
14371 mark_breakpoint_modified (bpt
);
14373 if (target_supports_enable_disable_tracepoint ()
14374 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14376 struct bp_location
*location
;
14378 for (location
= bpt
->loc
; location
; location
= location
->next
)
14379 target_enable_tracepoint (location
);
14382 bpt
->disposition
= disposition
;
14383 bpt
->enable_count
= count
;
14384 update_global_location_list (UGLL_MAY_INSERT
);
14386 observer_notify_breakpoint_modified (bpt
);
14391 enable_breakpoint (struct breakpoint
*bpt
)
14393 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14396 /* The enable command enables the specified breakpoints (or all defined
14397 breakpoints) so they once again become (or continue to be) effective
14398 in stopping the inferior. */
14401 enable_command (const char *args
, int from_tty
)
14405 struct breakpoint
*bpt
;
14407 ALL_BREAKPOINTS (bpt
)
14408 if (user_breakpoint_p (bpt
))
14409 enable_breakpoint (bpt
);
14413 std::string num
= extract_arg (&args
);
14415 while (!num
.empty ())
14417 if (num
.find ('.') != std::string::npos
)
14419 struct bp_location
*loc
= find_location_by_number (num
.c_str ());
14426 mark_breakpoint_location_modified (loc
);
14428 if (target_supports_enable_disable_tracepoint ()
14429 && current_trace_status ()->running
&& loc
->owner
14430 && is_tracepoint (loc
->owner
))
14431 target_enable_tracepoint (loc
);
14433 update_global_location_list (UGLL_MAY_INSERT
);
14436 map_breakpoint_numbers
14437 (num
.c_str (), [&] (breakpoint
*b
)
14439 iterate_over_related_breakpoints (b
, enable_breakpoint
);
14441 num
= extract_arg (&args
);
14447 enable_once_command (const char *args
, int from_tty
)
14449 map_breakpoint_numbers
14450 (args
, [&] (breakpoint
*b
)
14452 iterate_over_related_breakpoints
14453 (b
, [&] (breakpoint
*bpt
)
14455 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14461 enable_count_command (const char *args
, int from_tty
)
14466 error_no_arg (_("hit count"));
14468 count
= get_number (&args
);
14470 map_breakpoint_numbers
14471 (args
, [&] (breakpoint
*b
)
14473 iterate_over_related_breakpoints
14474 (b
, [&] (breakpoint
*bpt
)
14476 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14482 enable_delete_command (const char *args
, int from_tty
)
14484 map_breakpoint_numbers
14485 (args
, [&] (breakpoint
*b
)
14487 iterate_over_related_breakpoints
14488 (b
, [&] (breakpoint
*bpt
)
14490 enable_breakpoint_disp (bpt
, disp_del
, 1);
14496 set_breakpoint_cmd (const char *args
, int from_tty
)
14501 show_breakpoint_cmd (const char *args
, int from_tty
)
14505 /* Invalidate last known value of any hardware watchpoint if
14506 the memory which that value represents has been written to by
14510 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14511 CORE_ADDR addr
, ssize_t len
,
14512 const bfd_byte
*data
)
14514 struct breakpoint
*bp
;
14516 ALL_BREAKPOINTS (bp
)
14517 if (bp
->enable_state
== bp_enabled
14518 && bp
->type
== bp_hardware_watchpoint
)
14520 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14522 if (wp
->val_valid
&& wp
->val
)
14524 struct bp_location
*loc
;
14526 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14527 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14528 && loc
->address
+ loc
->length
> addr
14529 && addr
+ len
> loc
->address
)
14531 value_free (wp
->val
);
14539 /* Create and insert a breakpoint for software single step. */
14542 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14543 const address_space
*aspace
,
14546 struct thread_info
*tp
= inferior_thread ();
14547 struct symtab_and_line sal
;
14548 CORE_ADDR pc
= next_pc
;
14550 if (tp
->control
.single_step_breakpoints
== NULL
)
14552 tp
->control
.single_step_breakpoints
14553 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14556 sal
= find_pc_line (pc
, 0);
14558 sal
.section
= find_pc_overlay (pc
);
14559 sal
.explicit_pc
= 1;
14560 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14562 update_global_location_list (UGLL_INSERT
);
14565 /* Insert single step breakpoints according to the current state. */
14568 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14570 struct regcache
*regcache
= get_current_regcache ();
14571 std::vector
<CORE_ADDR
> next_pcs
;
14573 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14575 if (!next_pcs
.empty ())
14577 struct frame_info
*frame
= get_current_frame ();
14578 struct address_space
*aspace
= get_frame_address_space (frame
);
14580 for (CORE_ADDR pc
: next_pcs
)
14581 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14589 /* See breakpoint.h. */
14592 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14593 const address_space
*aspace
,
14596 struct bp_location
*loc
;
14598 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14600 && breakpoint_location_address_match (loc
, aspace
, pc
))
14606 /* Check whether a software single-step breakpoint is inserted at
14610 single_step_breakpoint_inserted_here_p (const address_space
*aspace
,
14613 struct breakpoint
*bpt
;
14615 ALL_BREAKPOINTS (bpt
)
14617 if (bpt
->type
== bp_single_step
14618 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14624 /* Tracepoint-specific operations. */
14626 /* Set tracepoint count to NUM. */
14628 set_tracepoint_count (int num
)
14630 tracepoint_count
= num
;
14631 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14635 trace_command (char *arg_in
, int from_tty
)
14637 const char *arg
= arg_in
;
14638 struct breakpoint_ops
*ops
;
14640 event_location_up location
= string_to_event_location (&arg
,
14642 if (location
!= NULL
14643 && event_location_type (location
.get ()) == PROBE_LOCATION
)
14644 ops
= &tracepoint_probe_breakpoint_ops
;
14646 ops
= &tracepoint_breakpoint_ops
;
14648 create_breakpoint (get_current_arch (),
14650 NULL
, 0, arg
, 1 /* parse arg */,
14652 bp_tracepoint
/* type_wanted */,
14653 0 /* Ignore count */,
14654 pending_break_support
,
14658 0 /* internal */, 0);
14662 ftrace_command (char *arg_in
, int from_tty
)
14664 const char *arg
= arg_in
;
14665 event_location_up location
= string_to_event_location (&arg
,
14667 create_breakpoint (get_current_arch (),
14669 NULL
, 0, arg
, 1 /* parse arg */,
14671 bp_fast_tracepoint
/* type_wanted */,
14672 0 /* Ignore count */,
14673 pending_break_support
,
14674 &tracepoint_breakpoint_ops
,
14677 0 /* internal */, 0);
14680 /* strace command implementation. Creates a static tracepoint. */
14683 strace_command (char *arg_in
, int from_tty
)
14685 const char *arg
= arg_in
;
14686 struct breakpoint_ops
*ops
;
14687 event_location_up location
;
14689 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14690 or with a normal static tracepoint. */
14691 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14693 ops
= &strace_marker_breakpoint_ops
;
14694 location
= new_linespec_location (&arg
);
14698 ops
= &tracepoint_breakpoint_ops
;
14699 location
= string_to_event_location (&arg
, current_language
);
14702 create_breakpoint (get_current_arch (),
14704 NULL
, 0, arg
, 1 /* parse arg */,
14706 bp_static_tracepoint
/* type_wanted */,
14707 0 /* Ignore count */,
14708 pending_break_support
,
14712 0 /* internal */, 0);
14715 /* Set up a fake reader function that gets command lines from a linked
14716 list that was acquired during tracepoint uploading. */
14718 static struct uploaded_tp
*this_utp
;
14719 static int next_cmd
;
14722 read_uploaded_action (void)
14726 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14733 /* Given information about a tracepoint as recorded on a target (which
14734 can be either a live system or a trace file), attempt to create an
14735 equivalent GDB tracepoint. This is not a reliable process, since
14736 the target does not necessarily have all the information used when
14737 the tracepoint was originally defined. */
14739 struct tracepoint
*
14740 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14742 const char *addr_str
;
14743 char small_buf
[100];
14744 struct tracepoint
*tp
;
14746 if (utp
->at_string
)
14747 addr_str
= utp
->at_string
;
14750 /* In the absence of a source location, fall back to raw
14751 address. Since there is no way to confirm that the address
14752 means the same thing as when the trace was started, warn the
14754 warning (_("Uploaded tracepoint %d has no "
14755 "source location, using raw address"),
14757 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14758 addr_str
= small_buf
;
14761 /* There's not much we can do with a sequence of bytecodes. */
14762 if (utp
->cond
&& !utp
->cond_string
)
14763 warning (_("Uploaded tracepoint %d condition "
14764 "has no source form, ignoring it"),
14767 event_location_up location
= string_to_event_location (&addr_str
,
14769 if (!create_breakpoint (get_current_arch (),
14771 utp
->cond_string
, -1, addr_str
,
14772 0 /* parse cond/thread */,
14774 utp
->type
/* type_wanted */,
14775 0 /* Ignore count */,
14776 pending_break_support
,
14777 &tracepoint_breakpoint_ops
,
14779 utp
->enabled
/* enabled */,
14781 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14784 /* Get the tracepoint we just created. */
14785 tp
= get_tracepoint (tracepoint_count
);
14786 gdb_assert (tp
!= NULL
);
14790 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14793 trace_pass_command (small_buf
, 0);
14796 /* If we have uploaded versions of the original commands, set up a
14797 special-purpose "reader" function and call the usual command line
14798 reader, then pass the result to the breakpoint command-setting
14800 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
14802 command_line_up cmd_list
;
14807 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
14809 breakpoint_set_commands (tp
, std::move (cmd_list
));
14811 else if (!VEC_empty (char_ptr
, utp
->actions
)
14812 || !VEC_empty (char_ptr
, utp
->step_actions
))
14813 warning (_("Uploaded tracepoint %d actions "
14814 "have no source form, ignoring them"),
14817 /* Copy any status information that might be available. */
14818 tp
->hit_count
= utp
->hit_count
;
14819 tp
->traceframe_usage
= utp
->traceframe_usage
;
14824 /* Print information on tracepoint number TPNUM_EXP, or all if
14828 info_tracepoints_command (char *args
, int from_tty
)
14830 struct ui_out
*uiout
= current_uiout
;
14833 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14835 if (num_printed
== 0)
14837 if (args
== NULL
|| *args
== '\0')
14838 uiout
->message ("No tracepoints.\n");
14840 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14843 default_collect_info ();
14846 /* The 'enable trace' command enables tracepoints.
14847 Not supported by all targets. */
14849 enable_trace_command (char *args
, int from_tty
)
14851 enable_command (args
, from_tty
);
14854 /* The 'disable trace' command disables tracepoints.
14855 Not supported by all targets. */
14857 disable_trace_command (char *args
, int from_tty
)
14859 disable_command (args
, from_tty
);
14862 /* Remove a tracepoint (or all if no argument). */
14864 delete_trace_command (const char *arg
, int from_tty
)
14866 struct breakpoint
*b
, *b_tmp
;
14872 int breaks_to_delete
= 0;
14874 /* Delete all breakpoints if no argument.
14875 Do not delete internal or call-dummy breakpoints, these
14876 have to be deleted with an explicit breakpoint number
14878 ALL_TRACEPOINTS (b
)
14879 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14881 breaks_to_delete
= 1;
14885 /* Ask user only if there are some breakpoints to delete. */
14887 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
14889 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14890 if (is_tracepoint (b
) && user_breakpoint_p (b
))
14891 delete_breakpoint (b
);
14895 map_breakpoint_numbers
14896 (arg
, [&] (breakpoint
*b
)
14898 iterate_over_related_breakpoints (b
, delete_breakpoint
);
14902 /* Helper function for trace_pass_command. */
14905 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
14907 tp
->pass_count
= count
;
14908 observer_notify_breakpoint_modified (tp
);
14910 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
14911 tp
->number
, count
);
14914 /* Set passcount for tracepoint.
14916 First command argument is passcount, second is tracepoint number.
14917 If tracepoint number omitted, apply to most recently defined.
14918 Also accepts special argument "all". */
14921 trace_pass_command (char *args
, int from_tty
)
14923 struct tracepoint
*t1
;
14924 unsigned int count
;
14926 if (args
== 0 || *args
== 0)
14927 error (_("passcount command requires an "
14928 "argument (count + optional TP num)"));
14930 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
14932 args
= skip_spaces (args
);
14933 if (*args
&& strncasecmp (args
, "all", 3) == 0)
14935 struct breakpoint
*b
;
14937 args
+= 3; /* Skip special argument "all". */
14939 error (_("Junk at end of arguments."));
14941 ALL_TRACEPOINTS (b
)
14943 t1
= (struct tracepoint
*) b
;
14944 trace_pass_set_count (t1
, count
, from_tty
);
14947 else if (*args
== '\0')
14949 t1
= get_tracepoint_by_number (&args
, NULL
);
14951 trace_pass_set_count (t1
, count
, from_tty
);
14955 number_or_range_parser
parser (args
);
14956 while (!parser
.finished ())
14958 t1
= get_tracepoint_by_number (&args
, &parser
);
14960 trace_pass_set_count (t1
, count
, from_tty
);
14965 struct tracepoint
*
14966 get_tracepoint (int num
)
14968 struct breakpoint
*t
;
14970 ALL_TRACEPOINTS (t
)
14971 if (t
->number
== num
)
14972 return (struct tracepoint
*) t
;
14977 /* Find the tracepoint with the given target-side number (which may be
14978 different from the tracepoint number after disconnecting and
14981 struct tracepoint
*
14982 get_tracepoint_by_number_on_target (int num
)
14984 struct breakpoint
*b
;
14986 ALL_TRACEPOINTS (b
)
14988 struct tracepoint
*t
= (struct tracepoint
*) b
;
14990 if (t
->number_on_target
== num
)
14997 /* Utility: parse a tracepoint number and look it up in the list.
14998 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
14999 If the argument is missing, the most recent tracepoint
15000 (tracepoint_count) is returned. */
15002 struct tracepoint
*
15003 get_tracepoint_by_number (char **arg
,
15004 number_or_range_parser
*parser
)
15006 struct breakpoint
*t
;
15008 char *instring
= arg
== NULL
? NULL
: *arg
;
15010 if (parser
!= NULL
)
15012 gdb_assert (!parser
->finished ());
15013 tpnum
= parser
->get_number ();
15015 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15016 tpnum
= tracepoint_count
;
15018 tpnum
= get_number (arg
);
15022 if (instring
&& *instring
)
15023 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15026 printf_filtered (_("No previous tracepoint\n"));
15030 ALL_TRACEPOINTS (t
)
15031 if (t
->number
== tpnum
)
15033 return (struct tracepoint
*) t
;
15036 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15041 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15043 if (b
->thread
!= -1)
15044 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15047 fprintf_unfiltered (fp
, " task %d", b
->task
);
15049 fprintf_unfiltered (fp
, "\n");
15052 /* Save information on user settable breakpoints (watchpoints, etc) to
15053 a new script file named FILENAME. If FILTER is non-NULL, call it
15054 on each breakpoint and only include the ones for which it returns
15058 save_breakpoints (const char *filename
, int from_tty
,
15059 int (*filter
) (const struct breakpoint
*))
15061 struct breakpoint
*tp
;
15063 int extra_trace_bits
= 0;
15065 if (filename
== 0 || *filename
== 0)
15066 error (_("Argument required (file name in which to save)"));
15068 /* See if we have anything to save. */
15069 ALL_BREAKPOINTS (tp
)
15071 /* Skip internal and momentary breakpoints. */
15072 if (!user_breakpoint_p (tp
))
15075 /* If we have a filter, only save the breakpoints it accepts. */
15076 if (filter
&& !filter (tp
))
15081 if (is_tracepoint (tp
))
15083 extra_trace_bits
= 1;
15085 /* We can stop searching. */
15092 warning (_("Nothing to save."));
15096 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15100 if (!fp
.open (expanded_filename
.get (), "w"))
15101 error (_("Unable to open file '%s' for saving (%s)"),
15102 expanded_filename
.get (), safe_strerror (errno
));
15104 if (extra_trace_bits
)
15105 save_trace_state_variables (&fp
);
15107 ALL_BREAKPOINTS (tp
)
15109 /* Skip internal and momentary breakpoints. */
15110 if (!user_breakpoint_p (tp
))
15113 /* If we have a filter, only save the breakpoints it accepts. */
15114 if (filter
&& !filter (tp
))
15117 tp
->ops
->print_recreate (tp
, &fp
);
15119 /* Note, we can't rely on tp->number for anything, as we can't
15120 assume the recreated breakpoint numbers will match. Use $bpnum
15123 if (tp
->cond_string
)
15124 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15126 if (tp
->ignore_count
)
15127 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15129 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15131 fp
.puts (" commands\n");
15133 current_uiout
->redirect (&fp
);
15136 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15138 CATCH (ex
, RETURN_MASK_ALL
)
15140 current_uiout
->redirect (NULL
);
15141 throw_exception (ex
);
15145 current_uiout
->redirect (NULL
);
15146 fp
.puts (" end\n");
15149 if (tp
->enable_state
== bp_disabled
)
15150 fp
.puts ("disable $bpnum\n");
15152 /* If this is a multi-location breakpoint, check if the locations
15153 should be individually disabled. Watchpoint locations are
15154 special, and not user visible. */
15155 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15157 struct bp_location
*loc
;
15160 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15162 fp
.printf ("disable $bpnum.%d\n", n
);
15166 if (extra_trace_bits
&& *default_collect
)
15167 fp
.printf ("set default-collect %s\n", default_collect
);
15170 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15173 /* The `save breakpoints' command. */
15176 save_breakpoints_command (const char *args
, int from_tty
)
15178 save_breakpoints (args
, from_tty
, NULL
);
15181 /* The `save tracepoints' command. */
15184 save_tracepoints_command (const char *args
, int from_tty
)
15186 save_breakpoints (args
, from_tty
, is_tracepoint
);
15189 /* Create a vector of all tracepoints. */
15191 VEC(breakpoint_p
) *
15192 all_tracepoints (void)
15194 VEC(breakpoint_p
) *tp_vec
= 0;
15195 struct breakpoint
*tp
;
15197 ALL_TRACEPOINTS (tp
)
15199 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15206 /* This help string is used to consolidate all the help string for specifying
15207 locations used by several commands. */
15209 #define LOCATION_HELP_STRING \
15210 "Linespecs are colon-separated lists of location parameters, such as\n\
15211 source filename, function name, label name, and line number.\n\
15212 Example: To specify the start of a label named \"the_top\" in the\n\
15213 function \"fact\" in the file \"factorial.c\", use\n\
15214 \"factorial.c:fact:the_top\".\n\
15216 Address locations begin with \"*\" and specify an exact address in the\n\
15217 program. Example: To specify the fourth byte past the start function\n\
15218 \"main\", use \"*main + 4\".\n\
15220 Explicit locations are similar to linespecs but use an option/argument\n\
15221 syntax to specify location parameters.\n\
15222 Example: To specify the start of the label named \"the_top\" in the\n\
15223 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15224 -function fact -label the_top\".\n"
15226 /* This help string is used for the break, hbreak, tbreak and thbreak
15227 commands. It is defined as a macro to prevent duplication.
15228 COMMAND should be a string constant containing the name of the
15231 #define BREAK_ARGS_HELP(command) \
15232 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15233 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15234 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15235 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15236 `-probe-dtrace' (for a DTrace probe).\n\
15237 LOCATION may be a linespec, address, or explicit location as described\n\
15240 With no LOCATION, uses current execution address of the selected\n\
15241 stack frame. This is useful for breaking on return to a stack frame.\n\
15243 THREADNUM is the number from \"info threads\".\n\
15244 CONDITION is a boolean expression.\n\
15245 \n" LOCATION_HELP_STRING "\n\
15246 Multiple breakpoints at one place are permitted, and useful if their\n\
15247 conditions are different.\n\
15249 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15251 /* List of subcommands for "catch". */
15252 static struct cmd_list_element
*catch_cmdlist
;
15254 /* List of subcommands for "tcatch". */
15255 static struct cmd_list_element
*tcatch_cmdlist
;
15258 add_catch_command (const char *name
, const char *docstring
,
15259 cmd_sfunc_ftype
*sfunc
,
15260 completer_ftype
*completer
,
15261 void *user_data_catch
,
15262 void *user_data_tcatch
)
15264 struct cmd_list_element
*command
;
15266 command
= add_cmd (name
, class_breakpoint
, docstring
,
15268 set_cmd_sfunc (command
, sfunc
);
15269 set_cmd_context (command
, user_data_catch
);
15270 set_cmd_completer (command
, completer
);
15272 command
= add_cmd (name
, class_breakpoint
, docstring
,
15274 set_cmd_sfunc (command
, sfunc
);
15275 set_cmd_context (command
, user_data_tcatch
);
15276 set_cmd_completer (command
, completer
);
15280 save_command (const char *arg
, int from_tty
)
15282 printf_unfiltered (_("\"save\" must be followed by "
15283 "the name of a save subcommand.\n"));
15284 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15287 struct breakpoint
*
15288 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15291 struct breakpoint
*b
, *b_tmp
;
15293 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15295 if ((*callback
) (b
, data
))
15302 /* Zero if any of the breakpoint's locations could be a location where
15303 functions have been inlined, nonzero otherwise. */
15306 is_non_inline_function (struct breakpoint
*b
)
15308 /* The shared library event breakpoint is set on the address of a
15309 non-inline function. */
15310 if (b
->type
== bp_shlib_event
)
15316 /* Nonzero if the specified PC cannot be a location where functions
15317 have been inlined. */
15320 pc_at_non_inline_function (const address_space
*aspace
, CORE_ADDR pc
,
15321 const struct target_waitstatus
*ws
)
15323 struct breakpoint
*b
;
15324 struct bp_location
*bl
;
15326 ALL_BREAKPOINTS (b
)
15328 if (!is_non_inline_function (b
))
15331 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15333 if (!bl
->shlib_disabled
15334 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15342 /* Remove any references to OBJFILE which is going to be freed. */
15345 breakpoint_free_objfile (struct objfile
*objfile
)
15347 struct bp_location
**locp
, *loc
;
15349 ALL_BP_LOCATIONS (loc
, locp
)
15350 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15351 loc
->symtab
= NULL
;
15355 initialize_breakpoint_ops (void)
15357 static int initialized
= 0;
15359 struct breakpoint_ops
*ops
;
15365 /* The breakpoint_ops structure to be inherit by all kinds of
15366 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15367 internal and momentary breakpoints, etc.). */
15368 ops
= &bkpt_base_breakpoint_ops
;
15369 *ops
= base_breakpoint_ops
;
15370 ops
->re_set
= bkpt_re_set
;
15371 ops
->insert_location
= bkpt_insert_location
;
15372 ops
->remove_location
= bkpt_remove_location
;
15373 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15374 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15375 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15376 ops
->decode_location
= bkpt_decode_location
;
15378 /* The breakpoint_ops structure to be used in regular breakpoints. */
15379 ops
= &bkpt_breakpoint_ops
;
15380 *ops
= bkpt_base_breakpoint_ops
;
15381 ops
->re_set
= bkpt_re_set
;
15382 ops
->resources_needed
= bkpt_resources_needed
;
15383 ops
->print_it
= bkpt_print_it
;
15384 ops
->print_mention
= bkpt_print_mention
;
15385 ops
->print_recreate
= bkpt_print_recreate
;
15387 /* Ranged breakpoints. */
15388 ops
= &ranged_breakpoint_ops
;
15389 *ops
= bkpt_breakpoint_ops
;
15390 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15391 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15392 ops
->print_it
= print_it_ranged_breakpoint
;
15393 ops
->print_one
= print_one_ranged_breakpoint
;
15394 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15395 ops
->print_mention
= print_mention_ranged_breakpoint
;
15396 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15398 /* Internal breakpoints. */
15399 ops
= &internal_breakpoint_ops
;
15400 *ops
= bkpt_base_breakpoint_ops
;
15401 ops
->re_set
= internal_bkpt_re_set
;
15402 ops
->check_status
= internal_bkpt_check_status
;
15403 ops
->print_it
= internal_bkpt_print_it
;
15404 ops
->print_mention
= internal_bkpt_print_mention
;
15406 /* Momentary breakpoints. */
15407 ops
= &momentary_breakpoint_ops
;
15408 *ops
= bkpt_base_breakpoint_ops
;
15409 ops
->re_set
= momentary_bkpt_re_set
;
15410 ops
->check_status
= momentary_bkpt_check_status
;
15411 ops
->print_it
= momentary_bkpt_print_it
;
15412 ops
->print_mention
= momentary_bkpt_print_mention
;
15414 /* Probe breakpoints. */
15415 ops
= &bkpt_probe_breakpoint_ops
;
15416 *ops
= bkpt_breakpoint_ops
;
15417 ops
->insert_location
= bkpt_probe_insert_location
;
15418 ops
->remove_location
= bkpt_probe_remove_location
;
15419 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15420 ops
->decode_location
= bkpt_probe_decode_location
;
15423 ops
= &watchpoint_breakpoint_ops
;
15424 *ops
= base_breakpoint_ops
;
15425 ops
->re_set
= re_set_watchpoint
;
15426 ops
->insert_location
= insert_watchpoint
;
15427 ops
->remove_location
= remove_watchpoint
;
15428 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15429 ops
->check_status
= check_status_watchpoint
;
15430 ops
->resources_needed
= resources_needed_watchpoint
;
15431 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15432 ops
->print_it
= print_it_watchpoint
;
15433 ops
->print_mention
= print_mention_watchpoint
;
15434 ops
->print_recreate
= print_recreate_watchpoint
;
15435 ops
->explains_signal
= explains_signal_watchpoint
;
15437 /* Masked watchpoints. */
15438 ops
= &masked_watchpoint_breakpoint_ops
;
15439 *ops
= watchpoint_breakpoint_ops
;
15440 ops
->insert_location
= insert_masked_watchpoint
;
15441 ops
->remove_location
= remove_masked_watchpoint
;
15442 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15443 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15444 ops
->print_it
= print_it_masked_watchpoint
;
15445 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15446 ops
->print_mention
= print_mention_masked_watchpoint
;
15447 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15450 ops
= &tracepoint_breakpoint_ops
;
15451 *ops
= base_breakpoint_ops
;
15452 ops
->re_set
= tracepoint_re_set
;
15453 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15454 ops
->print_one_detail
= tracepoint_print_one_detail
;
15455 ops
->print_mention
= tracepoint_print_mention
;
15456 ops
->print_recreate
= tracepoint_print_recreate
;
15457 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15458 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15459 ops
->decode_location
= tracepoint_decode_location
;
15461 /* Probe tracepoints. */
15462 ops
= &tracepoint_probe_breakpoint_ops
;
15463 *ops
= tracepoint_breakpoint_ops
;
15464 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15465 ops
->decode_location
= tracepoint_probe_decode_location
;
15467 /* Static tracepoints with marker (`-m'). */
15468 ops
= &strace_marker_breakpoint_ops
;
15469 *ops
= tracepoint_breakpoint_ops
;
15470 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15471 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15472 ops
->decode_location
= strace_marker_decode_location
;
15474 /* Fork catchpoints. */
15475 ops
= &catch_fork_breakpoint_ops
;
15476 *ops
= base_breakpoint_ops
;
15477 ops
->insert_location
= insert_catch_fork
;
15478 ops
->remove_location
= remove_catch_fork
;
15479 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15480 ops
->print_it
= print_it_catch_fork
;
15481 ops
->print_one
= print_one_catch_fork
;
15482 ops
->print_mention
= print_mention_catch_fork
;
15483 ops
->print_recreate
= print_recreate_catch_fork
;
15485 /* Vfork catchpoints. */
15486 ops
= &catch_vfork_breakpoint_ops
;
15487 *ops
= base_breakpoint_ops
;
15488 ops
->insert_location
= insert_catch_vfork
;
15489 ops
->remove_location
= remove_catch_vfork
;
15490 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15491 ops
->print_it
= print_it_catch_vfork
;
15492 ops
->print_one
= print_one_catch_vfork
;
15493 ops
->print_mention
= print_mention_catch_vfork
;
15494 ops
->print_recreate
= print_recreate_catch_vfork
;
15496 /* Exec catchpoints. */
15497 ops
= &catch_exec_breakpoint_ops
;
15498 *ops
= base_breakpoint_ops
;
15499 ops
->insert_location
= insert_catch_exec
;
15500 ops
->remove_location
= remove_catch_exec
;
15501 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15502 ops
->print_it
= print_it_catch_exec
;
15503 ops
->print_one
= print_one_catch_exec
;
15504 ops
->print_mention
= print_mention_catch_exec
;
15505 ops
->print_recreate
= print_recreate_catch_exec
;
15507 /* Solib-related catchpoints. */
15508 ops
= &catch_solib_breakpoint_ops
;
15509 *ops
= base_breakpoint_ops
;
15510 ops
->insert_location
= insert_catch_solib
;
15511 ops
->remove_location
= remove_catch_solib
;
15512 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15513 ops
->check_status
= check_status_catch_solib
;
15514 ops
->print_it
= print_it_catch_solib
;
15515 ops
->print_one
= print_one_catch_solib
;
15516 ops
->print_mention
= print_mention_catch_solib
;
15517 ops
->print_recreate
= print_recreate_catch_solib
;
15519 ops
= &dprintf_breakpoint_ops
;
15520 *ops
= bkpt_base_breakpoint_ops
;
15521 ops
->re_set
= dprintf_re_set
;
15522 ops
->resources_needed
= bkpt_resources_needed
;
15523 ops
->print_it
= bkpt_print_it
;
15524 ops
->print_mention
= bkpt_print_mention
;
15525 ops
->print_recreate
= dprintf_print_recreate
;
15526 ops
->after_condition_true
= dprintf_after_condition_true
;
15527 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15530 /* Chain containing all defined "enable breakpoint" subcommands. */
15532 static struct cmd_list_element
*enablebreaklist
= NULL
;
15535 _initialize_breakpoint (void)
15537 struct cmd_list_element
*c
;
15539 initialize_breakpoint_ops ();
15541 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15542 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15543 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15545 breakpoint_objfile_key
15546 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_objfile_data
);
15548 breakpoint_chain
= 0;
15549 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15550 before a breakpoint is set. */
15551 breakpoint_count
= 0;
15553 tracepoint_count
= 0;
15555 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15556 Set ignore-count of breakpoint number N to COUNT.\n\
15557 Usage is `ignore N COUNT'."));
15559 add_com ("commands", class_breakpoint
, commands_command
, _("\
15560 Set commands to be executed when the given breakpoints are hit.\n\
15561 Give a space-separated breakpoint list as argument after \"commands\".\n\
15562 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15564 With no argument, the targeted breakpoint is the last one set.\n\
15565 The commands themselves follow starting on the next line.\n\
15566 Type a line containing \"end\" to indicate the end of them.\n\
15567 Give \"silent\" as the first line to make the breakpoint silent;\n\
15568 then no output is printed when it is hit, except what the commands print."));
15570 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15571 Specify breakpoint number N to break only if COND is true.\n\
15572 Usage is `condition N COND', where N is an integer and COND is an\n\
15573 expression to be evaluated whenever breakpoint N is reached."));
15574 set_cmd_completer (c
, condition_completer
);
15576 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15577 Set a temporary breakpoint.\n\
15578 Like \"break\" except the breakpoint is only temporary,\n\
15579 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15580 by using \"enable delete\" on the breakpoint number.\n\
15582 BREAK_ARGS_HELP ("tbreak")));
15583 set_cmd_completer (c
, location_completer
);
15585 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15586 Set a hardware assisted breakpoint.\n\
15587 Like \"break\" except the breakpoint requires hardware support,\n\
15588 some target hardware may not have this support.\n\
15590 BREAK_ARGS_HELP ("hbreak")));
15591 set_cmd_completer (c
, location_completer
);
15593 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15594 Set a temporary hardware assisted breakpoint.\n\
15595 Like \"hbreak\" except the breakpoint is only temporary,\n\
15596 so it will be deleted when hit.\n\
15598 BREAK_ARGS_HELP ("thbreak")));
15599 set_cmd_completer (c
, location_completer
);
15601 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15602 Enable some breakpoints.\n\
15603 Give breakpoint numbers (separated by spaces) as arguments.\n\
15604 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15605 This is used to cancel the effect of the \"disable\" command.\n\
15606 With a subcommand you can enable temporarily."),
15607 &enablelist
, "enable ", 1, &cmdlist
);
15609 add_com_alias ("en", "enable", class_breakpoint
, 1);
15611 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15612 Enable some breakpoints.\n\
15613 Give breakpoint numbers (separated by spaces) as arguments.\n\
15614 This is used to cancel the effect of the \"disable\" command.\n\
15615 May be abbreviated to simply \"enable\".\n"),
15616 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15618 add_cmd ("once", no_class
, enable_once_command
, _("\
15619 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15620 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15623 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15624 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15625 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15628 add_cmd ("count", no_class
, enable_count_command
, _("\
15629 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15630 If a breakpoint is hit while enabled in this fashion,\n\
15631 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15634 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15635 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15636 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15639 add_cmd ("once", no_class
, enable_once_command
, _("\
15640 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15641 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15644 add_cmd ("count", no_class
, enable_count_command
, _("\
15645 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15646 If a breakpoint is hit while enabled in this fashion,\n\
15647 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15650 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15651 Disable some breakpoints.\n\
15652 Arguments are breakpoint numbers with spaces in between.\n\
15653 To disable all breakpoints, give no argument.\n\
15654 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15655 &disablelist
, "disable ", 1, &cmdlist
);
15656 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15657 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15659 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15660 Disable some breakpoints.\n\
15661 Arguments are breakpoint numbers with spaces in between.\n\
15662 To disable all breakpoints, give no argument.\n\
15663 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15664 This command may be abbreviated \"disable\"."),
15667 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15668 Delete some breakpoints or auto-display expressions.\n\
15669 Arguments are breakpoint numbers with spaces in between.\n\
15670 To delete all breakpoints, give no argument.\n\
15672 Also a prefix command for deletion of other GDB objects.\n\
15673 The \"unset\" command is also an alias for \"delete\"."),
15674 &deletelist
, "delete ", 1, &cmdlist
);
15675 add_com_alias ("d", "delete", class_breakpoint
, 1);
15676 add_com_alias ("del", "delete", class_breakpoint
, 1);
15678 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15679 Delete some breakpoints or auto-display expressions.\n\
15680 Arguments are breakpoint numbers with spaces in between.\n\
15681 To delete all breakpoints, give no argument.\n\
15682 This command may be abbreviated \"delete\"."),
15685 add_com ("clear", class_breakpoint
, clear_command
, _("\
15686 Clear breakpoint at specified location.\n\
15687 Argument may be a linespec, explicit, or address location as described below.\n\
15689 With no argument, clears all breakpoints in the line that the selected frame\n\
15690 is executing in.\n"
15691 "\n" LOCATION_HELP_STRING
"\n\
15692 See also the \"delete\" command which clears breakpoints by number."));
15693 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15695 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15696 Set breakpoint at specified location.\n"
15697 BREAK_ARGS_HELP ("break")));
15698 set_cmd_completer (c
, location_completer
);
15700 add_com_alias ("b", "break", class_run
, 1);
15701 add_com_alias ("br", "break", class_run
, 1);
15702 add_com_alias ("bre", "break", class_run
, 1);
15703 add_com_alias ("brea", "break", class_run
, 1);
15707 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15708 Break in function/address or break at a line in the current file."),
15709 &stoplist
, "stop ", 1, &cmdlist
);
15710 add_cmd ("in", class_breakpoint
, stopin_command
,
15711 _("Break in function or address."), &stoplist
);
15712 add_cmd ("at", class_breakpoint
, stopat_command
,
15713 _("Break at a line in the current file."), &stoplist
);
15714 add_com ("status", class_info
, info_breakpoints_command
, _("\
15715 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15716 The \"Type\" column indicates one of:\n\
15717 \tbreakpoint - normal breakpoint\n\
15718 \twatchpoint - watchpoint\n\
15719 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15720 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15721 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15722 address and file/line number respectively.\n\
15724 Convenience variable \"$_\" and default examine address for \"x\"\n\
15725 are set to the address of the last breakpoint listed unless the command\n\
15726 is prefixed with \"server \".\n\n\
15727 Convenience variable \"$bpnum\" contains the number of the last\n\
15728 breakpoint set."));
15731 add_info ("breakpoints", info_breakpoints_command
, _("\
15732 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15733 The \"Type\" column indicates one of:\n\
15734 \tbreakpoint - normal breakpoint\n\
15735 \twatchpoint - watchpoint\n\
15736 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15737 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15738 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15739 address and file/line number respectively.\n\
15741 Convenience variable \"$_\" and default examine address for \"x\"\n\
15742 are set to the address of the last breakpoint listed unless the command\n\
15743 is prefixed with \"server \".\n\n\
15744 Convenience variable \"$bpnum\" contains the number of the last\n\
15745 breakpoint set."));
15747 add_info_alias ("b", "breakpoints", 1);
15749 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15750 Status of all breakpoints, or breakpoint number NUMBER.\n\
15751 The \"Type\" column indicates one of:\n\
15752 \tbreakpoint - normal breakpoint\n\
15753 \twatchpoint - watchpoint\n\
15754 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15755 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15756 \tuntil - internal breakpoint used by the \"until\" command\n\
15757 \tfinish - internal breakpoint used by the \"finish\" command\n\
15758 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15759 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15760 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15761 address and file/line number respectively.\n\
15763 Convenience variable \"$_\" and default examine address for \"x\"\n\
15764 are set to the address of the last breakpoint listed unless the command\n\
15765 is prefixed with \"server \".\n\n\
15766 Convenience variable \"$bpnum\" contains the number of the last\n\
15768 &maintenanceinfolist
);
15770 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15771 Set catchpoints to catch events."),
15772 &catch_cmdlist
, "catch ",
15773 0/*allow-unknown*/, &cmdlist
);
15775 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15776 Set temporary catchpoints to catch events."),
15777 &tcatch_cmdlist
, "tcatch ",
15778 0/*allow-unknown*/, &cmdlist
);
15780 add_catch_command ("fork", _("Catch calls to fork."),
15781 catch_fork_command_1
,
15783 (void *) (uintptr_t) catch_fork_permanent
,
15784 (void *) (uintptr_t) catch_fork_temporary
);
15785 add_catch_command ("vfork", _("Catch calls to vfork."),
15786 catch_fork_command_1
,
15788 (void *) (uintptr_t) catch_vfork_permanent
,
15789 (void *) (uintptr_t) catch_vfork_temporary
);
15790 add_catch_command ("exec", _("Catch calls to exec."),
15791 catch_exec_command_1
,
15795 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15796 Usage: catch load [REGEX]\n\
15797 If REGEX is given, only stop for libraries matching the regular expression."),
15798 catch_load_command_1
,
15802 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15803 Usage: catch unload [REGEX]\n\
15804 If REGEX is given, only stop for libraries matching the regular expression."),
15805 catch_unload_command_1
,
15810 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15811 Set a watchpoint for an expression.\n\
15812 Usage: watch [-l|-location] EXPRESSION\n\
15813 A watchpoint stops execution of your program whenever the value of\n\
15814 an expression changes.\n\
15815 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15816 the memory to which it refers."));
15817 set_cmd_completer (c
, expression_completer
);
15819 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15820 Set a read watchpoint for an expression.\n\
15821 Usage: rwatch [-l|-location] EXPRESSION\n\
15822 A watchpoint stops execution of your program whenever the value of\n\
15823 an expression is read.\n\
15824 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15825 the memory to which it refers."));
15826 set_cmd_completer (c
, expression_completer
);
15828 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15829 Set a watchpoint for an expression.\n\
15830 Usage: awatch [-l|-location] EXPRESSION\n\
15831 A watchpoint stops execution of your program whenever the value of\n\
15832 an expression is either read or written.\n\
15833 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15834 the memory to which it refers."));
15835 set_cmd_completer (c
, expression_completer
);
15837 add_info ("watchpoints", info_watchpoints_command
, _("\
15838 Status of specified watchpoints (all watchpoints if no argument)."));
15840 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15841 respond to changes - contrary to the description. */
15842 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15843 &can_use_hw_watchpoints
, _("\
15844 Set debugger's willingness to use watchpoint hardware."), _("\
15845 Show debugger's willingness to use watchpoint hardware."), _("\
15846 If zero, gdb will not use hardware for new watchpoints, even if\n\
15847 such is available. (However, any hardware watchpoints that were\n\
15848 created before setting this to nonzero, will continue to use watchpoint\n\
15851 show_can_use_hw_watchpoints
,
15852 &setlist
, &showlist
);
15854 can_use_hw_watchpoints
= 1;
15856 /* Tracepoint manipulation commands. */
15858 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
15859 Set a tracepoint at specified location.\n\
15861 BREAK_ARGS_HELP ("trace") "\n\
15862 Do \"help tracepoints\" for info on other tracepoint commands."));
15863 set_cmd_completer (c
, location_completer
);
15865 add_com_alias ("tp", "trace", class_alias
, 0);
15866 add_com_alias ("tr", "trace", class_alias
, 1);
15867 add_com_alias ("tra", "trace", class_alias
, 1);
15868 add_com_alias ("trac", "trace", class_alias
, 1);
15870 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
15871 Set a fast tracepoint at specified location.\n\
15873 BREAK_ARGS_HELP ("ftrace") "\n\
15874 Do \"help tracepoints\" for info on other tracepoint commands."));
15875 set_cmd_completer (c
, location_completer
);
15877 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
15878 Set a static tracepoint at location or marker.\n\
15880 strace [LOCATION] [if CONDITION]\n\
15881 LOCATION may be a linespec, explicit, or address location (described below) \n\
15882 or -m MARKER_ID.\n\n\
15883 If a marker id is specified, probe the marker with that name. With\n\
15884 no LOCATION, uses current execution address of the selected stack frame.\n\
15885 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
15886 This collects arbitrary user data passed in the probe point call to the\n\
15887 tracing library. You can inspect it when analyzing the trace buffer,\n\
15888 by printing the $_sdata variable like any other convenience variable.\n\
15890 CONDITION is a boolean expression.\n\
15891 \n" LOCATION_HELP_STRING
"\n\
15892 Multiple tracepoints at one place are permitted, and useful if their\n\
15893 conditions are different.\n\
15895 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
15896 Do \"help tracepoints\" for info on other tracepoint commands."));
15897 set_cmd_completer (c
, location_completer
);
15899 add_info ("tracepoints", info_tracepoints_command
, _("\
15900 Status of specified tracepoints (all tracepoints if no argument).\n\
15901 Convenience variable \"$tpnum\" contains the number of the\n\
15902 last tracepoint set."));
15904 add_info_alias ("tp", "tracepoints", 1);
15906 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
15907 Delete specified tracepoints.\n\
15908 Arguments are tracepoint numbers, separated by spaces.\n\
15909 No argument means delete all tracepoints."),
15911 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
15913 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
15914 Disable specified tracepoints.\n\
15915 Arguments are tracepoint numbers, separated by spaces.\n\
15916 No argument means disable all tracepoints."),
15918 deprecate_cmd (c
, "disable");
15920 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
15921 Enable specified tracepoints.\n\
15922 Arguments are tracepoint numbers, separated by spaces.\n\
15923 No argument means enable all tracepoints."),
15925 deprecate_cmd (c
, "enable");
15927 add_com ("passcount", class_trace
, trace_pass_command
, _("\
15928 Set the passcount for a tracepoint.\n\
15929 The trace will end when the tracepoint has been passed 'count' times.\n\
15930 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
15931 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
15933 add_prefix_cmd ("save", class_breakpoint
, save_command
,
15934 _("Save breakpoint definitions as a script."),
15935 &save_cmdlist
, "save ",
15936 0/*allow-unknown*/, &cmdlist
);
15938 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
15939 Save current breakpoint definitions as a script.\n\
15940 This includes all types of breakpoints (breakpoints, watchpoints,\n\
15941 catchpoints, tracepoints). Use the 'source' command in another debug\n\
15942 session to restore them."),
15944 set_cmd_completer (c
, filename_completer
);
15946 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
15947 Save current tracepoint definitions as a script.\n\
15948 Use the 'source' command in another debug session to restore them."),
15950 set_cmd_completer (c
, filename_completer
);
15952 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
15953 deprecate_cmd (c
, "save tracepoints");
15955 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
15956 Breakpoint specific settings\n\
15957 Configure various breakpoint-specific variables such as\n\
15958 pending breakpoint behavior"),
15959 &breakpoint_set_cmdlist
, "set breakpoint ",
15960 0/*allow-unknown*/, &setlist
);
15961 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
15962 Breakpoint specific settings\n\
15963 Configure various breakpoint-specific variables such as\n\
15964 pending breakpoint behavior"),
15965 &breakpoint_show_cmdlist
, "show breakpoint ",
15966 0/*allow-unknown*/, &showlist
);
15968 add_setshow_auto_boolean_cmd ("pending", no_class
,
15969 &pending_break_support
, _("\
15970 Set debugger's behavior regarding pending breakpoints."), _("\
15971 Show debugger's behavior regarding pending breakpoints."), _("\
15972 If on, an unrecognized breakpoint location will cause gdb to create a\n\
15973 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
15974 an error. If auto, an unrecognized breakpoint location results in a\n\
15975 user-query to see if a pending breakpoint should be created."),
15977 show_pending_break_support
,
15978 &breakpoint_set_cmdlist
,
15979 &breakpoint_show_cmdlist
);
15981 pending_break_support
= AUTO_BOOLEAN_AUTO
;
15983 add_setshow_boolean_cmd ("auto-hw", no_class
,
15984 &automatic_hardware_breakpoints
, _("\
15985 Set automatic usage of hardware breakpoints."), _("\
15986 Show automatic usage of hardware breakpoints."), _("\
15987 If set, the debugger will automatically use hardware breakpoints for\n\
15988 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
15989 a warning will be emitted for such breakpoints."),
15991 show_automatic_hardware_breakpoints
,
15992 &breakpoint_set_cmdlist
,
15993 &breakpoint_show_cmdlist
);
15995 add_setshow_boolean_cmd ("always-inserted", class_support
,
15996 &always_inserted_mode
, _("\
15997 Set mode for inserting breakpoints."), _("\
15998 Show mode for inserting breakpoints."), _("\
15999 When this mode is on, breakpoints are inserted immediately as soon as\n\
16000 they're created, kept inserted even when execution stops, and removed\n\
16001 only when the user deletes them. When this mode is off (the default),\n\
16002 breakpoints are inserted only when execution continues, and removed\n\
16003 when execution stops."),
16005 &show_always_inserted_mode
,
16006 &breakpoint_set_cmdlist
,
16007 &breakpoint_show_cmdlist
);
16009 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16010 condition_evaluation_enums
,
16011 &condition_evaluation_mode_1
, _("\
16012 Set mode of breakpoint condition evaluation."), _("\
16013 Show mode of breakpoint condition evaluation."), _("\
16014 When this is set to \"host\", breakpoint conditions will be\n\
16015 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16016 breakpoint conditions will be downloaded to the target (if the target\n\
16017 supports such feature) and conditions will be evaluated on the target's side.\n\
16018 If this is set to \"auto\" (default), this will be automatically set to\n\
16019 \"target\" if it supports condition evaluation, otherwise it will\n\
16020 be set to \"gdb\""),
16021 &set_condition_evaluation_mode
,
16022 &show_condition_evaluation_mode
,
16023 &breakpoint_set_cmdlist
,
16024 &breakpoint_show_cmdlist
);
16026 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16027 Set a breakpoint for an address range.\n\
16028 break-range START-LOCATION, END-LOCATION\n\
16029 where START-LOCATION and END-LOCATION can be one of the following:\n\
16030 LINENUM, for that line in the current file,\n\
16031 FILE:LINENUM, for that line in that file,\n\
16032 +OFFSET, for that number of lines after the current line\n\
16033 or the start of the range\n\
16034 FUNCTION, for the first line in that function,\n\
16035 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16036 *ADDRESS, for the instruction at that address.\n\
16038 The breakpoint will stop execution of the inferior whenever it executes\n\
16039 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16040 range (including START-LOCATION and END-LOCATION)."));
16042 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16043 Set a dynamic printf at specified location.\n\
16044 dprintf location,format string,arg1,arg2,...\n\
16045 location may be a linespec, explicit, or address location.\n"
16046 "\n" LOCATION_HELP_STRING
));
16047 set_cmd_completer (c
, location_completer
);
16049 add_setshow_enum_cmd ("dprintf-style", class_support
,
16050 dprintf_style_enums
, &dprintf_style
, _("\
16051 Set the style of usage for dynamic printf."), _("\
16052 Show the style of usage for dynamic printf."), _("\
16053 This setting chooses how GDB will do a dynamic printf.\n\
16054 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16055 console, as with the \"printf\" command.\n\
16056 If the value is \"call\", the print is done by calling a function in your\n\
16057 program; by default printf(), but you can choose a different function or\n\
16058 output stream by setting dprintf-function and dprintf-channel."),
16059 update_dprintf_commands
, NULL
,
16060 &setlist
, &showlist
);
16062 dprintf_function
= xstrdup ("printf");
16063 add_setshow_string_cmd ("dprintf-function", class_support
,
16064 &dprintf_function
, _("\
16065 Set the function to use for dynamic printf"), _("\
16066 Show the function to use for dynamic printf"), NULL
,
16067 update_dprintf_commands
, NULL
,
16068 &setlist
, &showlist
);
16070 dprintf_channel
= xstrdup ("");
16071 add_setshow_string_cmd ("dprintf-channel", class_support
,
16072 &dprintf_channel
, _("\
16073 Set the channel to use for dynamic printf"), _("\
16074 Show the channel to use for dynamic printf"), NULL
,
16075 update_dprintf_commands
, NULL
,
16076 &setlist
, &showlist
);
16078 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16079 &disconnected_dprintf
, _("\
16080 Set whether dprintf continues after GDB disconnects."), _("\
16081 Show whether dprintf continues after GDB disconnects."), _("\
16082 Use this to let dprintf commands continue to hit and produce output\n\
16083 even if GDB disconnects or detaches from the target."),
16086 &setlist
, &showlist
);
16088 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16089 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16090 (target agent only) This is useful for formatted output in user-defined commands."));
16092 automatic_hardware_breakpoints
= 1;
16094 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16095 observer_attach_thread_exit (remove_threaded_breakpoints
);