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"
49 #include "cli/cli-script.h"
59 #include "parser-defs.h"
60 #include "gdb_regex.h"
62 #include "cli/cli-utils.h"
63 #include "continuations.h"
67 #include "dummy-frame.h"
70 #include "thread-fsm.h"
71 #include "tid-parse.h"
73 /* readline include files */
74 #include "readline/readline.h"
75 #include "readline/history.h"
77 /* readline defines this. */
80 #include "mi/mi-common.h"
81 #include "extension.h"
83 #include "progspace-and-thread.h"
84 #include "common/array-view.h"
85 #include "common/gdb_optional.h"
87 /* Enums for exception-handling support. */
88 enum exception_event_kind
95 /* Prototypes for local functions. */
97 static void enable_delete_command (char *, int);
99 static void enable_once_command (char *, int);
101 static void enable_count_command (char *, int);
103 static void disable_command (char *, int);
105 static void enable_command (char *, int);
107 static void map_breakpoint_numbers (const char *,
108 gdb::function_view
<void (breakpoint
*)>);
110 static void ignore_command (char *, int);
112 static int breakpoint_re_set_one (void *);
114 static void breakpoint_re_set_default (struct breakpoint
*);
117 create_sals_from_location_default (const struct event_location
*location
,
118 struct linespec_result
*canonical
,
119 enum bptype type_wanted
);
121 static void create_breakpoints_sal_default (struct gdbarch
*,
122 struct linespec_result
*,
123 gdb::unique_xmalloc_ptr
<char>,
124 gdb::unique_xmalloc_ptr
<char>,
126 enum bpdisp
, int, int,
128 const struct breakpoint_ops
*,
129 int, int, int, unsigned);
131 static std::vector
<symtab_and_line
> decode_location_default
132 (struct breakpoint
*b
, const struct event_location
*location
,
133 struct program_space
*search_pspace
);
135 static void clear_command (char *, int);
137 static void catch_command (char *, int);
139 static int can_use_hardware_watchpoint (struct value
*);
141 static void break_command_1 (char *, int, int);
143 static void mention (struct breakpoint
*);
145 static struct breakpoint
*set_raw_breakpoint_without_location (struct gdbarch
*,
147 const struct breakpoint_ops
*);
148 static struct bp_location
*add_location_to_breakpoint (struct breakpoint
*,
149 const struct symtab_and_line
*);
151 /* This function is used in gdbtk sources and thus can not be made
153 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
154 struct symtab_and_line
,
156 const struct breakpoint_ops
*);
158 static struct breakpoint
*
159 momentary_breakpoint_from_master (struct breakpoint
*orig
,
161 const struct breakpoint_ops
*ops
,
164 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
166 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
170 static void describe_other_breakpoints (struct gdbarch
*,
171 struct program_space
*, CORE_ADDR
,
172 struct obj_section
*, int);
174 static int watchpoint_locations_match (struct bp_location
*loc1
,
175 struct bp_location
*loc2
);
177 static int breakpoint_location_address_match (struct bp_location
*bl
,
178 struct address_space
*aspace
,
181 static int breakpoint_location_address_range_overlap (struct bp_location
*,
182 struct address_space
*,
185 static void info_breakpoints_command (char *, int);
187 static void info_watchpoints_command (char *, int);
189 static int breakpoint_1 (char *, int,
190 int (*) (const struct breakpoint
*));
192 static int breakpoint_cond_eval (void *);
194 static void cleanup_executing_breakpoints (void *);
196 static void commands_command (char *, int);
198 static void condition_command (char *, int);
200 static int remove_breakpoint (struct bp_location
*);
201 static int remove_breakpoint_1 (struct bp_location
*, enum remove_bp_reason
);
203 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
205 static int watchpoint_check (void *);
207 static void maintenance_info_breakpoints (char *, int);
209 static int hw_breakpoint_used_count (void);
211 static int hw_watchpoint_use_count (struct breakpoint
*);
213 static int hw_watchpoint_used_count_others (struct breakpoint
*except
,
215 int *other_type_used
);
217 static void hbreak_command (char *, int);
219 static void thbreak_command (char *, int);
221 static void enable_breakpoint_disp (struct breakpoint
*, enum bpdisp
,
224 static void stop_command (char *arg
, int from_tty
);
226 static void stopin_command (char *arg
, int from_tty
);
228 static void stopat_command (char *arg
, int from_tty
);
230 static void tcatch_command (char *arg
, int from_tty
);
232 static void free_bp_location (struct bp_location
*loc
);
233 static void incref_bp_location (struct bp_location
*loc
);
234 static void decref_bp_location (struct bp_location
**loc
);
236 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
238 /* update_global_location_list's modes of operation wrt to whether to
239 insert locations now. */
240 enum ugll_insert_mode
242 /* Don't insert any breakpoint locations into the inferior, only
243 remove already-inserted locations that no longer should be
244 inserted. Functions that delete a breakpoint or breakpoints
245 should specify this mode, so that deleting a breakpoint doesn't
246 have the side effect of inserting the locations of other
247 breakpoints that are marked not-inserted, but should_be_inserted
248 returns true on them.
250 This behavior is useful is situations close to tear-down -- e.g.,
251 after an exec, while the target still has execution, but
252 breakpoint shadows of the previous executable image should *NOT*
253 be restored to the new image; or before detaching, where the
254 target still has execution and wants to delete breakpoints from
255 GDB's lists, and all breakpoints had already been removed from
259 /* May insert breakpoints iff breakpoints_should_be_inserted_now
260 claims breakpoints should be inserted now. */
263 /* Insert locations now, irrespective of
264 breakpoints_should_be_inserted_now. E.g., say all threads are
265 stopped right now, and the user did "continue". We need to
266 insert breakpoints _before_ resuming the target, but
267 UGLL_MAY_INSERT wouldn't insert them, because
268 breakpoints_should_be_inserted_now returns false at that point,
269 as no thread is running yet. */
273 static void update_global_location_list (enum ugll_insert_mode
);
275 static void update_global_location_list_nothrow (enum ugll_insert_mode
);
277 static int is_hardware_watchpoint (const struct breakpoint
*bpt
);
279 static void insert_breakpoint_locations (void);
281 static void info_tracepoints_command (char *, int);
283 static void delete_trace_command (char *, int);
285 static void enable_trace_command (char *, int);
287 static void disable_trace_command (char *, int);
289 static void trace_pass_command (char *, int);
291 static void set_tracepoint_count (int num
);
293 static int is_masked_watchpoint (const struct breakpoint
*b
);
295 static struct bp_location
**get_first_locp_gte_addr (CORE_ADDR address
);
297 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero
300 static int strace_marker_p (struct breakpoint
*b
);
302 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
303 that are implemented on top of software or hardware breakpoints
304 (user breakpoints, internal and momentary breakpoints, etc.). */
305 static struct breakpoint_ops bkpt_base_breakpoint_ops
;
307 /* Internal breakpoints class type. */
308 static struct breakpoint_ops internal_breakpoint_ops
;
310 /* Momentary breakpoints class type. */
311 static struct breakpoint_ops momentary_breakpoint_ops
;
313 /* The breakpoint_ops structure to be used in regular user created
315 struct breakpoint_ops bkpt_breakpoint_ops
;
317 /* Breakpoints set on probes. */
318 static struct breakpoint_ops bkpt_probe_breakpoint_ops
;
320 /* Dynamic printf class type. */
321 struct breakpoint_ops dprintf_breakpoint_ops
;
323 /* The style in which to perform a dynamic printf. This is a user
324 option because different output options have different tradeoffs;
325 if GDB does the printing, there is better error handling if there
326 is a problem with any of the arguments, but using an inferior
327 function lets you have special-purpose printers and sending of
328 output to the same place as compiled-in print functions. */
330 static const char dprintf_style_gdb
[] = "gdb";
331 static const char dprintf_style_call
[] = "call";
332 static const char dprintf_style_agent
[] = "agent";
333 static const char *const dprintf_style_enums
[] = {
339 static const char *dprintf_style
= dprintf_style_gdb
;
341 /* The function to use for dynamic printf if the preferred style is to
342 call into the inferior. The value is simply a string that is
343 copied into the command, so it can be anything that GDB can
344 evaluate to a callable address, not necessarily a function name. */
346 static char *dprintf_function
;
348 /* The channel to use for dynamic printf if the preferred style is to
349 call into the inferior; if a nonempty string, it will be passed to
350 the call as the first argument, with the format string as the
351 second. As with the dprintf function, this can be anything that
352 GDB knows how to evaluate, so in addition to common choices like
353 "stderr", this could be an app-specific expression like
354 "mystreams[curlogger]". */
356 static char *dprintf_channel
;
358 /* True if dprintf commands should continue to operate even if GDB
360 static int disconnected_dprintf
= 1;
362 struct command_line
*
363 breakpoint_commands (struct breakpoint
*b
)
365 return b
->commands
? b
->commands
.get () : NULL
;
368 /* Flag indicating that a command has proceeded the inferior past the
369 current breakpoint. */
371 static int breakpoint_proceeded
;
374 bpdisp_text (enum bpdisp disp
)
376 /* NOTE: the following values are a part of MI protocol and
377 represent values of 'disp' field returned when inferior stops at
379 static const char * const bpdisps
[] = {"del", "dstp", "dis", "keep"};
381 return bpdisps
[(int) disp
];
384 /* Prototypes for exported functions. */
385 /* If FALSE, gdb will not use hardware support for watchpoints, even
386 if such is available. */
387 static int can_use_hw_watchpoints
;
390 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
391 struct cmd_list_element
*c
,
394 fprintf_filtered (file
,
395 _("Debugger's willingness to use "
396 "watchpoint hardware is %s.\n"),
400 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
401 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
402 for unrecognized breakpoint locations.
403 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
404 static enum auto_boolean pending_break_support
;
406 show_pending_break_support (struct ui_file
*file
, int from_tty
,
407 struct cmd_list_element
*c
,
410 fprintf_filtered (file
,
411 _("Debugger's behavior regarding "
412 "pending breakpoints is %s.\n"),
416 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
417 set with "break" but falling in read-only memory.
418 If 0, gdb will warn about such breakpoints, but won't automatically
419 use hardware breakpoints. */
420 static int automatic_hardware_breakpoints
;
422 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
423 struct cmd_list_element
*c
,
426 fprintf_filtered (file
,
427 _("Automatic usage of hardware breakpoints is %s.\n"),
431 /* If on, GDB keeps breakpoints inserted even if the inferior is
432 stopped, and immediately inserts any new breakpoints as soon as
433 they're created. If off (default), GDB keeps breakpoints off of
434 the target as long as possible. That is, it delays inserting
435 breakpoints until the next resume, and removes them again when the
436 target fully stops. This is a bit safer in case GDB crashes while
437 processing user input. */
438 static int always_inserted_mode
= 0;
441 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
442 struct cmd_list_element
*c
, const char *value
)
444 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"),
448 /* See breakpoint.h. */
451 breakpoints_should_be_inserted_now (void)
453 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
455 /* If breakpoints are global, they should be inserted even if no
456 thread under gdb's control is running, or even if there are
457 no threads under GDB's control yet. */
460 else if (target_has_execution
)
462 struct thread_info
*tp
;
464 if (always_inserted_mode
)
466 /* The user wants breakpoints inserted even if all threads
471 if (threads_are_executing ())
474 /* Don't remove breakpoints yet if, even though all threads are
475 stopped, we still have events to process. */
476 ALL_NON_EXITED_THREADS (tp
)
478 && tp
->suspend
.waitstatus_pending_p
)
484 static const char condition_evaluation_both
[] = "host or target";
486 /* Modes for breakpoint condition evaluation. */
487 static const char condition_evaluation_auto
[] = "auto";
488 static const char condition_evaluation_host
[] = "host";
489 static const char condition_evaluation_target
[] = "target";
490 static const char *const condition_evaluation_enums
[] = {
491 condition_evaluation_auto
,
492 condition_evaluation_host
,
493 condition_evaluation_target
,
497 /* Global that holds the current mode for breakpoint condition evaluation. */
498 static const char *condition_evaluation_mode_1
= condition_evaluation_auto
;
500 /* Global that we use to display information to the user (gets its value from
501 condition_evaluation_mode_1. */
502 static const char *condition_evaluation_mode
= condition_evaluation_auto
;
504 /* Translate a condition evaluation mode MODE into either "host"
505 or "target". This is used mostly to translate from "auto" to the
506 real setting that is being used. It returns the translated
510 translate_condition_evaluation_mode (const char *mode
)
512 if (mode
== condition_evaluation_auto
)
514 if (target_supports_evaluation_of_breakpoint_conditions ())
515 return condition_evaluation_target
;
517 return condition_evaluation_host
;
523 /* Discovers what condition_evaluation_auto translates to. */
526 breakpoint_condition_evaluation_mode (void)
528 return translate_condition_evaluation_mode (condition_evaluation_mode
);
531 /* Return true if GDB should evaluate breakpoint conditions or false
535 gdb_evaluates_breakpoint_condition_p (void)
537 const char *mode
= breakpoint_condition_evaluation_mode ();
539 return (mode
== condition_evaluation_host
);
542 /* Are we executing breakpoint commands? */
543 static int executing_breakpoint_commands
;
545 /* Are overlay event breakpoints enabled? */
546 static int overlay_events_enabled
;
548 /* See description in breakpoint.h. */
549 int target_exact_watchpoints
= 0;
551 /* Walk the following statement or block through all breakpoints.
552 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the
553 current breakpoint. */
555 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
557 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
558 for (B = breakpoint_chain; \
559 B ? (TMP=B->next, 1): 0; \
562 /* Similar iterator for the low-level breakpoints. SAFE variant is
563 not provided so update_global_location_list must not be called
564 while executing the block of ALL_BP_LOCATIONS. */
566 #define ALL_BP_LOCATIONS(B,BP_TMP) \
567 for (BP_TMP = bp_locations; \
568 BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\
571 /* Iterates through locations with address ADDRESS for the currently selected
572 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points
573 to where the loop should start from.
574 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the
575 appropriate location to start with. */
577 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \
578 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \
579 BP_LOCP_TMP = BP_LOCP_START; \
581 && (BP_LOCP_TMP < bp_locations + bp_locations_count \
582 && (*BP_LOCP_TMP)->address == ADDRESS); \
585 /* Iterator for tracepoints only. */
587 #define ALL_TRACEPOINTS(B) \
588 for (B = breakpoint_chain; B; B = B->next) \
589 if (is_tracepoint (B))
591 /* Chains of all breakpoints defined. */
593 struct breakpoint
*breakpoint_chain
;
595 /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */
597 static struct bp_location
**bp_locations
;
599 /* Number of elements of BP_LOCATIONS. */
601 static unsigned bp_locations_count
;
603 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and
604 ADDRESS for the current elements of BP_LOCATIONS which get a valid
605 result from bp_location_has_shadow. You can use it for roughly
606 limiting the subrange of BP_LOCATIONS to scan for shadow bytes for
607 an address you need to read. */
609 static CORE_ADDR bp_locations_placed_address_before_address_max
;
611 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS
612 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of
613 BP_LOCATIONS which get a valid result from bp_location_has_shadow.
614 You can use it for roughly limiting the subrange of BP_LOCATIONS to
615 scan for shadow bytes for an address you need to read. */
617 static CORE_ADDR bp_locations_shadow_len_after_address_max
;
619 /* The locations that no longer correspond to any breakpoint, unlinked
620 from the bp_locations array, but for which a hit may still be
621 reported by a target. */
622 VEC(bp_location_p
) *moribund_locations
= NULL
;
624 /* Number of last breakpoint made. */
626 static int breakpoint_count
;
628 /* The value of `breakpoint_count' before the last command that
629 created breakpoints. If the last (break-like) command created more
630 than one breakpoint, then the difference between BREAKPOINT_COUNT
631 and PREV_BREAKPOINT_COUNT is more than one. */
632 static int prev_breakpoint_count
;
634 /* Number of last tracepoint made. */
636 static int tracepoint_count
;
638 static struct cmd_list_element
*breakpoint_set_cmdlist
;
639 static struct cmd_list_element
*breakpoint_show_cmdlist
;
640 struct cmd_list_element
*save_cmdlist
;
642 /* See declaration at breakpoint.h. */
645 breakpoint_find_if (int (*func
) (struct breakpoint
*b
, void *d
),
648 struct breakpoint
*b
= NULL
;
652 if (func (b
, user_data
) != 0)
659 /* Return whether a breakpoint is an active enabled breakpoint. */
661 breakpoint_enabled (struct breakpoint
*b
)
663 return (b
->enable_state
== bp_enabled
);
666 /* Set breakpoint count to NUM. */
669 set_breakpoint_count (int num
)
671 prev_breakpoint_count
= breakpoint_count
;
672 breakpoint_count
= num
;
673 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
676 /* Used by `start_rbreak_breakpoints' below, to record the current
677 breakpoint count before "rbreak" creates any breakpoint. */
678 static int rbreak_start_breakpoint_count
;
680 /* Called at the start an "rbreak" command to record the first
684 start_rbreak_breakpoints (void)
686 rbreak_start_breakpoint_count
= breakpoint_count
;
689 /* Called at the end of an "rbreak" command to record the last
693 end_rbreak_breakpoints (void)
695 prev_breakpoint_count
= rbreak_start_breakpoint_count
;
698 /* Used in run_command to zero the hit count when a new run starts. */
701 clear_breakpoint_hit_counts (void)
703 struct breakpoint
*b
;
710 /* Return the breakpoint with the specified number, or NULL
711 if the number does not refer to an existing breakpoint. */
714 get_breakpoint (int num
)
716 struct breakpoint
*b
;
719 if (b
->number
== num
)
727 /* Mark locations as "conditions have changed" in case the target supports
728 evaluating conditions on its side. */
731 mark_breakpoint_modified (struct breakpoint
*b
)
733 struct bp_location
*loc
;
735 /* This is only meaningful if the target is
736 evaluating conditions and if the user has
737 opted for condition evaluation on the target's
739 if (gdb_evaluates_breakpoint_condition_p ()
740 || !target_supports_evaluation_of_breakpoint_conditions ())
743 if (!is_breakpoint (b
))
746 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
747 loc
->condition_changed
= condition_modified
;
750 /* Mark location as "conditions have changed" in case the target supports
751 evaluating conditions on its side. */
754 mark_breakpoint_location_modified (struct bp_location
*loc
)
756 /* This is only meaningful if the target is
757 evaluating conditions and if the user has
758 opted for condition evaluation on the target's
760 if (gdb_evaluates_breakpoint_condition_p ()
761 || !target_supports_evaluation_of_breakpoint_conditions ())
765 if (!is_breakpoint (loc
->owner
))
768 loc
->condition_changed
= condition_modified
;
771 /* Sets the condition-evaluation mode using the static global
772 condition_evaluation_mode. */
775 set_condition_evaluation_mode (char *args
, int from_tty
,
776 struct cmd_list_element
*c
)
778 const char *old_mode
, *new_mode
;
780 if ((condition_evaluation_mode_1
== condition_evaluation_target
)
781 && !target_supports_evaluation_of_breakpoint_conditions ())
783 condition_evaluation_mode_1
= condition_evaluation_mode
;
784 warning (_("Target does not support breakpoint condition evaluation.\n"
785 "Using host evaluation mode instead."));
789 new_mode
= translate_condition_evaluation_mode (condition_evaluation_mode_1
);
790 old_mode
= translate_condition_evaluation_mode (condition_evaluation_mode
);
792 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the
793 settings was "auto". */
794 condition_evaluation_mode
= condition_evaluation_mode_1
;
796 /* Only update the mode if the user picked a different one. */
797 if (new_mode
!= old_mode
)
799 struct bp_location
*loc
, **loc_tmp
;
800 /* If the user switched to a different evaluation mode, we
801 need to synch the changes with the target as follows:
803 "host" -> "target": Send all (valid) conditions to the target.
804 "target" -> "host": Remove all the conditions from the target.
807 if (new_mode
== condition_evaluation_target
)
809 /* Mark everything modified and synch conditions with the
811 ALL_BP_LOCATIONS (loc
, loc_tmp
)
812 mark_breakpoint_location_modified (loc
);
816 /* Manually mark non-duplicate locations to synch conditions
817 with the target. We do this to remove all the conditions the
818 target knows about. */
819 ALL_BP_LOCATIONS (loc
, loc_tmp
)
820 if (is_breakpoint (loc
->owner
) && loc
->inserted
)
821 loc
->needs_update
= 1;
825 update_global_location_list (UGLL_MAY_INSERT
);
831 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows
832 what "auto" is translating to. */
835 show_condition_evaluation_mode (struct ui_file
*file
, int from_tty
,
836 struct cmd_list_element
*c
, const char *value
)
838 if (condition_evaluation_mode
== condition_evaluation_auto
)
839 fprintf_filtered (file
,
840 _("Breakpoint condition evaluation "
841 "mode is %s (currently %s).\n"),
843 breakpoint_condition_evaluation_mode ());
845 fprintf_filtered (file
, _("Breakpoint condition evaluation mode is %s.\n"),
849 /* A comparison function for bp_location AP and BP that is used by
850 bsearch. This comparison function only cares about addresses, unlike
851 the more general bp_locations_compare function. */
854 bp_locations_compare_addrs (const void *ap
, const void *bp
)
856 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
857 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
859 if (a
->address
== b
->address
)
862 return ((a
->address
> b
->address
) - (a
->address
< b
->address
));
865 /* Helper function to skip all bp_locations with addresses
866 less than ADDRESS. It returns the first bp_location that
867 is greater than or equal to ADDRESS. If none is found, just
870 static struct bp_location
**
871 get_first_locp_gte_addr (CORE_ADDR address
)
873 struct bp_location dummy_loc
;
874 struct bp_location
*dummy_locp
= &dummy_loc
;
875 struct bp_location
**locp_found
= NULL
;
877 /* Initialize the dummy location's address field. */
878 dummy_loc
.address
= address
;
880 /* Find a close match to the first location at ADDRESS. */
881 locp_found
= ((struct bp_location
**)
882 bsearch (&dummy_locp
, bp_locations
, bp_locations_count
,
883 sizeof (struct bp_location
**),
884 bp_locations_compare_addrs
));
886 /* Nothing was found, nothing left to do. */
887 if (locp_found
== NULL
)
890 /* We may have found a location that is at ADDRESS but is not the first in the
891 location's list. Go backwards (if possible) and locate the first one. */
892 while ((locp_found
- 1) >= bp_locations
893 && (*(locp_found
- 1))->address
== address
)
900 set_breakpoint_condition (struct breakpoint
*b
, const char *exp
,
903 xfree (b
->cond_string
);
904 b
->cond_string
= NULL
;
906 if (is_watchpoint (b
))
908 struct watchpoint
*w
= (struct watchpoint
*) b
;
910 w
->cond_exp
.reset ();
914 struct bp_location
*loc
;
916 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
920 /* No need to free the condition agent expression
921 bytecode (if we have one). We will handle this
922 when we go through update_global_location_list. */
929 printf_filtered (_("Breakpoint %d now unconditional.\n"), b
->number
);
933 const char *arg
= exp
;
935 /* I don't know if it matters whether this is the string the user
936 typed in or the decompiled expression. */
937 b
->cond_string
= xstrdup (arg
);
938 b
->condition_not_parsed
= 0;
940 if (is_watchpoint (b
))
942 struct watchpoint
*w
= (struct watchpoint
*) b
;
944 innermost_block
= NULL
;
946 w
->cond_exp
= parse_exp_1 (&arg
, 0, 0, 0);
948 error (_("Junk at end of expression"));
949 w
->cond_exp_valid_block
= innermost_block
;
953 struct bp_location
*loc
;
955 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
959 parse_exp_1 (&arg
, loc
->address
,
960 block_for_pc (loc
->address
), 0);
962 error (_("Junk at end of expression"));
966 mark_breakpoint_modified (b
);
968 observer_notify_breakpoint_modified (b
);
971 /* Completion for the "condition" command. */
974 condition_completer (struct cmd_list_element
*cmd
,
975 completion_tracker
&tracker
,
976 const char *text
, const char *word
)
980 text
= skip_spaces (text
);
981 space
= skip_to_space (text
);
985 struct breakpoint
*b
;
986 VEC (char_ptr
) *result
= NULL
;
990 /* We don't support completion of history indices. */
991 if (!isdigit (text
[1]))
992 complete_internalvar (tracker
, &text
[1]);
996 /* We're completing the breakpoint number. */
1003 xsnprintf (number
, sizeof (number
), "%d", b
->number
);
1005 if (strncmp (number
, text
, len
) == 0)
1007 gdb::unique_xmalloc_ptr
<char> copy (xstrdup (number
));
1008 tracker
.add_completion (std::move (copy
));
1015 /* We're completing the expression part. */
1016 text
= skip_spaces (space
);
1017 expression_completer (cmd
, tracker
, text
, word
);
1020 /* condition N EXP -- set break condition of breakpoint N to EXP. */
1023 condition_command (char *arg
, int from_tty
)
1025 struct breakpoint
*b
;
1030 error_no_arg (_("breakpoint number"));
1033 bnum
= get_number (&p
);
1035 error (_("Bad breakpoint argument: '%s'"), arg
);
1038 if (b
->number
== bnum
)
1040 /* Check if this breakpoint has a "stop" method implemented in an
1041 extension language. This method and conditions entered into GDB
1042 from the CLI are mutually exclusive. */
1043 const struct extension_language_defn
*extlang
1044 = get_breakpoint_cond_ext_lang (b
, EXT_LANG_NONE
);
1046 if (extlang
!= NULL
)
1048 error (_("Only one stop condition allowed. There is currently"
1049 " a %s stop condition defined for this breakpoint."),
1050 ext_lang_capitalized_name (extlang
));
1052 set_breakpoint_condition (b
, p
, from_tty
);
1054 if (is_breakpoint (b
))
1055 update_global_location_list (UGLL_MAY_INSERT
);
1060 error (_("No breakpoint number %d."), bnum
);
1063 /* Check that COMMAND do not contain commands that are suitable
1064 only for tracepoints and not suitable for ordinary breakpoints.
1065 Throw if any such commands is found. */
1068 check_no_tracepoint_commands (struct command_line
*commands
)
1070 struct command_line
*c
;
1072 for (c
= commands
; c
; c
= c
->next
)
1076 if (c
->control_type
== while_stepping_control
)
1077 error (_("The 'while-stepping' command can "
1078 "only be used for tracepoints"));
1080 for (i
= 0; i
< c
->body_count
; ++i
)
1081 check_no_tracepoint_commands ((c
->body_list
)[i
]);
1083 /* Not that command parsing removes leading whitespace and comment
1084 lines and also empty lines. So, we only need to check for
1085 command directly. */
1086 if (strstr (c
->line
, "collect ") == c
->line
)
1087 error (_("The 'collect' command can only be used for tracepoints"));
1089 if (strstr (c
->line
, "teval ") == c
->line
)
1090 error (_("The 'teval' command can only be used for tracepoints"));
1094 struct longjmp_breakpoint
: public breakpoint
1096 ~longjmp_breakpoint () override
;
1099 /* Encapsulate tests for different types of tracepoints. */
1102 is_tracepoint_type (bptype type
)
1104 return (type
== bp_tracepoint
1105 || type
== bp_fast_tracepoint
1106 || type
== bp_static_tracepoint
);
1110 is_longjmp_type (bptype type
)
1112 return type
== bp_longjmp
|| type
== bp_exception
;
1116 is_tracepoint (const struct breakpoint
*b
)
1118 return is_tracepoint_type (b
->type
);
1121 /* Factory function to create an appropriate instance of breakpoint given
1124 static std::unique_ptr
<breakpoint
>
1125 new_breakpoint_from_type (bptype type
)
1129 if (is_tracepoint_type (type
))
1130 b
= new tracepoint ();
1131 else if (is_longjmp_type (type
))
1132 b
= new longjmp_breakpoint ();
1134 b
= new breakpoint ();
1136 return std::unique_ptr
<breakpoint
> (b
);
1139 /* A helper function that validates that COMMANDS are valid for a
1140 breakpoint. This function will throw an exception if a problem is
1144 validate_commands_for_breakpoint (struct breakpoint
*b
,
1145 struct command_line
*commands
)
1147 if (is_tracepoint (b
))
1149 struct tracepoint
*t
= (struct tracepoint
*) b
;
1150 struct command_line
*c
;
1151 struct command_line
*while_stepping
= 0;
1153 /* Reset the while-stepping step count. The previous commands
1154 might have included a while-stepping action, while the new
1158 /* We need to verify that each top-level element of commands is
1159 valid for tracepoints, that there's at most one
1160 while-stepping element, and that the while-stepping's body
1161 has valid tracing commands excluding nested while-stepping.
1162 We also need to validate the tracepoint action line in the
1163 context of the tracepoint --- validate_actionline actually
1164 has side effects, like setting the tracepoint's
1165 while-stepping STEP_COUNT, in addition to checking if the
1166 collect/teval actions parse and make sense in the
1167 tracepoint's context. */
1168 for (c
= commands
; c
; c
= c
->next
)
1170 if (c
->control_type
== while_stepping_control
)
1172 if (b
->type
== bp_fast_tracepoint
)
1173 error (_("The 'while-stepping' command "
1174 "cannot be used for fast tracepoint"));
1175 else if (b
->type
== bp_static_tracepoint
)
1176 error (_("The 'while-stepping' command "
1177 "cannot be used for static tracepoint"));
1180 error (_("The 'while-stepping' command "
1181 "can be used only once"));
1186 validate_actionline (c
->line
, b
);
1190 struct command_line
*c2
;
1192 gdb_assert (while_stepping
->body_count
== 1);
1193 c2
= while_stepping
->body_list
[0];
1194 for (; c2
; c2
= c2
->next
)
1196 if (c2
->control_type
== while_stepping_control
)
1197 error (_("The 'while-stepping' command cannot be nested"));
1203 check_no_tracepoint_commands (commands
);
1207 /* Return a vector of all the static tracepoints set at ADDR. The
1208 caller is responsible for releasing the vector. */
1211 static_tracepoints_here (CORE_ADDR addr
)
1213 struct breakpoint
*b
;
1214 VEC(breakpoint_p
) *found
= 0;
1215 struct bp_location
*loc
;
1218 if (b
->type
== bp_static_tracepoint
)
1220 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1221 if (loc
->address
== addr
)
1222 VEC_safe_push(breakpoint_p
, found
, b
);
1228 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
1229 validate that only allowed commands are included. */
1232 breakpoint_set_commands (struct breakpoint
*b
,
1233 command_line_up
&&commands
)
1235 validate_commands_for_breakpoint (b
, commands
.get ());
1237 b
->commands
= std::move (commands
);
1238 observer_notify_breakpoint_modified (b
);
1241 /* Set the internal `silent' flag on the breakpoint. Note that this
1242 is not the same as the "silent" that may appear in the breakpoint's
1246 breakpoint_set_silent (struct breakpoint
*b
, int silent
)
1248 int old_silent
= b
->silent
;
1251 if (old_silent
!= silent
)
1252 observer_notify_breakpoint_modified (b
);
1255 /* Set the thread for this breakpoint. If THREAD is -1, make the
1256 breakpoint work for any thread. */
1259 breakpoint_set_thread (struct breakpoint
*b
, int thread
)
1261 int old_thread
= b
->thread
;
1264 if (old_thread
!= thread
)
1265 observer_notify_breakpoint_modified (b
);
1268 /* Set the task for this breakpoint. If TASK is 0, make the
1269 breakpoint work for any task. */
1272 breakpoint_set_task (struct breakpoint
*b
, int task
)
1274 int old_task
= b
->task
;
1277 if (old_task
!= task
)
1278 observer_notify_breakpoint_modified (b
);
1282 check_tracepoint_command (char *line
, void *closure
)
1284 struct breakpoint
*b
= (struct breakpoint
*) closure
;
1286 validate_actionline (line
, b
);
1290 commands_command_1 (const char *arg
, int from_tty
,
1291 struct command_line
*control
)
1293 counted_command_line cmd
;
1295 std::string new_arg
;
1297 if (arg
== NULL
|| !*arg
)
1299 if (breakpoint_count
- prev_breakpoint_count
> 1)
1300 new_arg
= string_printf ("%d-%d", prev_breakpoint_count
+ 1,
1302 else if (breakpoint_count
> 0)
1303 new_arg
= string_printf ("%d", breakpoint_count
);
1304 arg
= new_arg
.c_str ();
1307 map_breakpoint_numbers
1308 (arg
, [&] (breakpoint
*b
)
1312 if (control
!= NULL
)
1313 cmd
= copy_command_lines (control
->body_list
[0]);
1316 struct cleanup
*old_chain
;
1319 str
= xstrprintf (_("Type commands for breakpoint(s) "
1320 "%s, one per line."),
1323 old_chain
= make_cleanup (xfree
, str
);
1325 cmd
= read_command_lines (str
,
1328 ? check_tracepoint_command
: 0),
1331 do_cleanups (old_chain
);
1335 /* If a breakpoint was on the list more than once, we don't need to
1337 if (b
->commands
!= cmd
)
1339 validate_commands_for_breakpoint (b
, cmd
.get ());
1341 observer_notify_breakpoint_modified (b
);
1346 error (_("No breakpoints specified."));
1350 commands_command (char *arg
, int from_tty
)
1352 commands_command_1 (arg
, from_tty
, NULL
);
1355 /* Like commands_command, but instead of reading the commands from
1356 input stream, takes them from an already parsed command structure.
1358 This is used by cli-script.c to DTRT with breakpoint commands
1359 that are part of if and while bodies. */
1360 enum command_control_type
1361 commands_from_control_command (const char *arg
, struct command_line
*cmd
)
1363 commands_command_1 (arg
, 0, cmd
);
1364 return simple_control
;
1367 /* Return non-zero if BL->TARGET_INFO contains valid information. */
1370 bp_location_has_shadow (struct bp_location
*bl
)
1372 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
1376 if (bl
->target_info
.shadow_len
== 0)
1377 /* BL isn't valid, or doesn't shadow memory. */
1382 /* Update BUF, which is LEN bytes read from the target address
1383 MEMADDR, by replacing a memory breakpoint with its shadowed
1386 If READBUF is not NULL, this buffer must not overlap with the of
1387 the breakpoint location's shadow_contents buffer. Otherwise, a
1388 failed assertion internal error will be raised. */
1391 one_breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1392 const gdb_byte
*writebuf_org
,
1393 ULONGEST memaddr
, LONGEST len
,
1394 struct bp_target_info
*target_info
,
1395 struct gdbarch
*gdbarch
)
1397 /* Now do full processing of the found relevant range of elements. */
1398 CORE_ADDR bp_addr
= 0;
1402 if (!breakpoint_address_match (target_info
->placed_address_space
, 0,
1403 current_program_space
->aspace
, 0))
1405 /* The breakpoint is inserted in a different address space. */
1409 /* Addresses and length of the part of the breakpoint that
1411 bp_addr
= target_info
->placed_address
;
1412 bp_size
= target_info
->shadow_len
;
1414 if (bp_addr
+ bp_size
<= memaddr
)
1416 /* The breakpoint is entirely before the chunk of memory we are
1421 if (bp_addr
>= memaddr
+ len
)
1423 /* The breakpoint is entirely after the chunk of memory we are
1428 /* Offset within shadow_contents. */
1429 if (bp_addr
< memaddr
)
1431 /* Only copy the second part of the breakpoint. */
1432 bp_size
-= memaddr
- bp_addr
;
1433 bptoffset
= memaddr
- bp_addr
;
1437 if (bp_addr
+ bp_size
> memaddr
+ len
)
1439 /* Only copy the first part of the breakpoint. */
1440 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1443 if (readbuf
!= NULL
)
1445 /* Verify that the readbuf buffer does not overlap with the
1446 shadow_contents buffer. */
1447 gdb_assert (target_info
->shadow_contents
>= readbuf
+ len
1448 || readbuf
>= (target_info
->shadow_contents
1449 + target_info
->shadow_len
));
1451 /* Update the read buffer with this inserted breakpoint's
1453 memcpy (readbuf
+ bp_addr
- memaddr
,
1454 target_info
->shadow_contents
+ bptoffset
, bp_size
);
1458 const unsigned char *bp
;
1459 CORE_ADDR addr
= target_info
->reqstd_address
;
1462 /* Update the shadow with what we want to write to memory. */
1463 memcpy (target_info
->shadow_contents
+ bptoffset
,
1464 writebuf_org
+ bp_addr
- memaddr
, bp_size
);
1466 /* Determine appropriate breakpoint contents and size for this
1468 bp
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &placed_size
);
1470 /* Update the final write buffer with this inserted
1471 breakpoint's INSN. */
1472 memcpy (writebuf
+ bp_addr
- memaddr
, bp
+ bptoffset
, bp_size
);
1476 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
1477 by replacing any memory breakpoints with their shadowed contents.
1479 If READBUF is not NULL, this buffer must not overlap with any of
1480 the breakpoint location's shadow_contents buffers. Otherwise,
1481 a failed assertion internal error will be raised.
1483 The range of shadowed area by each bp_location is:
1484 bl->address - bp_locations_placed_address_before_address_max
1485 up to bl->address + bp_locations_shadow_len_after_address_max
1486 The range we were requested to resolve shadows for is:
1487 memaddr ... memaddr + len
1488 Thus the safe cutoff boundaries for performance optimization are
1489 memaddr + len <= (bl->address
1490 - bp_locations_placed_address_before_address_max)
1492 bl->address + bp_locations_shadow_len_after_address_max <= memaddr */
1495 breakpoint_xfer_memory (gdb_byte
*readbuf
, gdb_byte
*writebuf
,
1496 const gdb_byte
*writebuf_org
,
1497 ULONGEST memaddr
, LONGEST len
)
1499 /* Left boundary, right boundary and median element of our binary
1501 unsigned bc_l
, bc_r
, bc
;
1503 /* Find BC_L which is a leftmost element which may affect BUF
1504 content. It is safe to report lower value but a failure to
1505 report higher one. */
1508 bc_r
= bp_locations_count
;
1509 while (bc_l
+ 1 < bc_r
)
1511 struct bp_location
*bl
;
1513 bc
= (bc_l
+ bc_r
) / 2;
1514 bl
= bp_locations
[bc
];
1516 /* Check first BL->ADDRESS will not overflow due to the added
1517 constant. Then advance the left boundary only if we are sure
1518 the BC element can in no way affect the BUF content (MEMADDR
1519 to MEMADDR + LEN range).
1521 Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety
1522 offset so that we cannot miss a breakpoint with its shadow
1523 range tail still reaching MEMADDR. */
1525 if ((bl
->address
+ bp_locations_shadow_len_after_address_max
1527 && (bl
->address
+ bp_locations_shadow_len_after_address_max
1534 /* Due to the binary search above, we need to make sure we pick the
1535 first location that's at BC_L's address. E.g., if there are
1536 multiple locations at the same address, BC_L may end up pointing
1537 at a duplicate location, and miss the "master"/"inserted"
1538 location. Say, given locations L1, L2 and L3 at addresses A and
1541 L1@A, L2@A, L3@B, ...
1543 BC_L could end up pointing at location L2, while the "master"
1544 location could be L1. Since the `loc->inserted' flag is only set
1545 on "master" locations, we'd forget to restore the shadow of L1
1548 && bp_locations
[bc_l
]->address
== bp_locations
[bc_l
- 1]->address
)
1551 /* Now do full processing of the found relevant range of elements. */
1553 for (bc
= bc_l
; bc
< bp_locations_count
; bc
++)
1555 struct bp_location
*bl
= bp_locations
[bc
];
1557 /* bp_location array has BL->OWNER always non-NULL. */
1558 if (bl
->owner
->type
== bp_none
)
1559 warning (_("reading through apparently deleted breakpoint #%d?"),
1562 /* Performance optimization: any further element can no longer affect BUF
1565 if (bl
->address
>= bp_locations_placed_address_before_address_max
1566 && memaddr
+ len
<= (bl
->address
1567 - bp_locations_placed_address_before_address_max
))
1570 if (!bp_location_has_shadow (bl
))
1573 one_breakpoint_xfer_memory (readbuf
, writebuf
, writebuf_org
,
1574 memaddr
, len
, &bl
->target_info
, bl
->gdbarch
);
1580 /* Return true if BPT is either a software breakpoint or a hardware
1584 is_breakpoint (const struct breakpoint
*bpt
)
1586 return (bpt
->type
== bp_breakpoint
1587 || bpt
->type
== bp_hardware_breakpoint
1588 || bpt
->type
== bp_dprintf
);
1591 /* Return true if BPT is of any hardware watchpoint kind. */
1594 is_hardware_watchpoint (const struct breakpoint
*bpt
)
1596 return (bpt
->type
== bp_hardware_watchpoint
1597 || bpt
->type
== bp_read_watchpoint
1598 || bpt
->type
== bp_access_watchpoint
);
1601 /* Return true if BPT is of any watchpoint kind, hardware or
1605 is_watchpoint (const struct breakpoint
*bpt
)
1607 return (is_hardware_watchpoint (bpt
)
1608 || bpt
->type
== bp_watchpoint
);
1611 /* Returns true if the current thread and its running state are safe
1612 to evaluate or update watchpoint B. Watchpoints on local
1613 expressions need to be evaluated in the context of the thread that
1614 was current when the watchpoint was created, and, that thread needs
1615 to be stopped to be able to select the correct frame context.
1616 Watchpoints on global expressions can be evaluated on any thread,
1617 and in any state. It is presently left to the target allowing
1618 memory accesses when threads are running. */
1621 watchpoint_in_thread_scope (struct watchpoint
*b
)
1623 return (b
->pspace
== current_program_space
1624 && (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1625 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1626 && !is_executing (inferior_ptid
))));
1629 /* Set watchpoint B to disp_del_at_next_stop, even including its possible
1630 associated bp_watchpoint_scope breakpoint. */
1633 watchpoint_del_at_next_stop (struct watchpoint
*w
)
1635 if (w
->related_breakpoint
!= w
)
1637 gdb_assert (w
->related_breakpoint
->type
== bp_watchpoint_scope
);
1638 gdb_assert (w
->related_breakpoint
->related_breakpoint
== w
);
1639 w
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1640 w
->related_breakpoint
->related_breakpoint
= w
->related_breakpoint
;
1641 w
->related_breakpoint
= w
;
1643 w
->disposition
= disp_del_at_next_stop
;
1646 /* Extract a bitfield value from value VAL using the bit parameters contained in
1649 static struct value
*
1650 extract_bitfield_from_watchpoint_value (struct watchpoint
*w
, struct value
*val
)
1652 struct value
*bit_val
;
1657 bit_val
= allocate_value (value_type (val
));
1659 unpack_value_bitfield (bit_val
,
1662 value_contents_for_printing (val
),
1669 /* Allocate a dummy location and add it to B, which must be a software
1670 watchpoint. This is required because even if a software watchpoint
1671 is not watching any memory, bpstat_stop_status requires a location
1672 to be able to report stops. */
1675 software_watchpoint_add_no_memory_location (struct breakpoint
*b
,
1676 struct program_space
*pspace
)
1678 gdb_assert (b
->type
== bp_watchpoint
&& b
->loc
== NULL
);
1680 b
->loc
= allocate_bp_location (b
);
1681 b
->loc
->pspace
= pspace
;
1682 b
->loc
->address
= -1;
1683 b
->loc
->length
= -1;
1686 /* Returns true if B is a software watchpoint that is not watching any
1687 memory (e.g., "watch $pc"). */
1690 is_no_memory_software_watchpoint (struct breakpoint
*b
)
1692 return (b
->type
== bp_watchpoint
1694 && b
->loc
->next
== NULL
1695 && b
->loc
->address
== -1
1696 && b
->loc
->length
== -1);
1699 /* Assuming that B is a watchpoint:
1700 - Reparse watchpoint expression, if REPARSE is non-zero
1701 - Evaluate expression and store the result in B->val
1702 - Evaluate the condition if there is one, and store the result
1704 - Update the list of values that must be watched in B->loc.
1706 If the watchpoint disposition is disp_del_at_next_stop, then do
1707 nothing. If this is local watchpoint that is out of scope, delete
1710 Even with `set breakpoint always-inserted on' the watchpoints are
1711 removed + inserted on each stop here. Normal breakpoints must
1712 never be removed because they might be missed by a running thread
1713 when debugging in non-stop mode. On the other hand, hardware
1714 watchpoints (is_hardware_watchpoint; processed here) are specific
1715 to each LWP since they are stored in each LWP's hardware debug
1716 registers. Therefore, such LWP must be stopped first in order to
1717 be able to modify its hardware watchpoints.
1719 Hardware watchpoints must be reset exactly once after being
1720 presented to the user. It cannot be done sooner, because it would
1721 reset the data used to present the watchpoint hit to the user. And
1722 it must not be done later because it could display the same single
1723 watchpoint hit during multiple GDB stops. Note that the latter is
1724 relevant only to the hardware watchpoint types bp_read_watchpoint
1725 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is
1726 not user-visible - its hit is suppressed if the memory content has
1729 The following constraints influence the location where we can reset
1730 hardware watchpoints:
1732 * target_stopped_by_watchpoint and target_stopped_data_address are
1733 called several times when GDB stops.
1736 * Multiple hardware watchpoints can be hit at the same time,
1737 causing GDB to stop. GDB only presents one hardware watchpoint
1738 hit at a time as the reason for stopping, and all the other hits
1739 are presented later, one after the other, each time the user
1740 requests the execution to be resumed. Execution is not resumed
1741 for the threads still having pending hit event stored in
1742 LWP_INFO->STATUS. While the watchpoint is already removed from
1743 the inferior on the first stop the thread hit event is kept being
1744 reported from its cached value by linux_nat_stopped_data_address
1745 until the real thread resume happens after the watchpoint gets
1746 presented and thus its LWP_INFO->STATUS gets reset.
1748 Therefore the hardware watchpoint hit can get safely reset on the
1749 watchpoint removal from inferior. */
1752 update_watchpoint (struct watchpoint
*b
, int reparse
)
1754 int within_current_scope
;
1755 struct frame_id saved_frame_id
;
1758 /* If this is a local watchpoint, we only want to check if the
1759 watchpoint frame is in scope if the current thread is the thread
1760 that was used to create the watchpoint. */
1761 if (!watchpoint_in_thread_scope (b
))
1764 if (b
->disposition
== disp_del_at_next_stop
)
1769 /* Determine if the watchpoint is within scope. */
1770 if (b
->exp_valid_block
== NULL
)
1771 within_current_scope
= 1;
1774 struct frame_info
*fi
= get_current_frame ();
1775 struct gdbarch
*frame_arch
= get_frame_arch (fi
);
1776 CORE_ADDR frame_pc
= get_frame_pc (fi
);
1778 /* If we're at a point where the stack has been destroyed
1779 (e.g. in a function epilogue), unwinding may not work
1780 properly. Do not attempt to recreate locations at this
1781 point. See similar comments in watchpoint_check. */
1782 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
1785 /* Save the current frame's ID so we can restore it after
1786 evaluating the watchpoint expression on its own frame. */
1787 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1788 took a frame parameter, so that we didn't have to change the
1791 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1793 fi
= frame_find_by_id (b
->watchpoint_frame
);
1794 within_current_scope
= (fi
!= NULL
);
1795 if (within_current_scope
)
1799 /* We don't free locations. They are stored in the bp_location array
1800 and update_global_location_list will eventually delete them and
1801 remove breakpoints if needed. */
1804 if (within_current_scope
&& reparse
)
1809 s
= b
->exp_string_reparse
? b
->exp_string_reparse
: b
->exp_string
;
1810 b
->exp
= parse_exp_1 (&s
, 0, b
->exp_valid_block
, 0);
1811 /* If the meaning of expression itself changed, the old value is
1812 no longer relevant. We don't want to report a watchpoint hit
1813 to the user when the old value and the new value may actually
1814 be completely different objects. */
1815 value_free (b
->val
);
1819 /* Note that unlike with breakpoints, the watchpoint's condition
1820 expression is stored in the breakpoint object, not in the
1821 locations (re)created below. */
1822 if (b
->cond_string
!= NULL
)
1824 b
->cond_exp
.reset ();
1827 b
->cond_exp
= parse_exp_1 (&s
, 0, b
->cond_exp_valid_block
, 0);
1831 /* If we failed to parse the expression, for example because
1832 it refers to a global variable in a not-yet-loaded shared library,
1833 don't try to insert watchpoint. We don't automatically delete
1834 such watchpoint, though, since failure to parse expression
1835 is different from out-of-scope watchpoint. */
1836 if (!target_has_execution
)
1838 /* Without execution, memory can't change. No use to try and
1839 set watchpoint locations. The watchpoint will be reset when
1840 the target gains execution, through breakpoint_re_set. */
1841 if (!can_use_hw_watchpoints
)
1843 if (b
->ops
->works_in_software_mode (b
))
1844 b
->type
= bp_watchpoint
;
1846 error (_("Can't set read/access watchpoint when "
1847 "hardware watchpoints are disabled."));
1850 else if (within_current_scope
&& b
->exp
)
1853 struct value
*val_chain
, *v
, *result
, *next
;
1854 struct program_space
*frame_pspace
;
1856 fetch_subexp_value (b
->exp
.get (), &pc
, &v
, &result
, &val_chain
, 0);
1858 /* Avoid setting b->val if it's already set. The meaning of
1859 b->val is 'the last value' user saw, and we should update
1860 it only if we reported that last value to user. As it
1861 happens, the code that reports it updates b->val directly.
1862 We don't keep track of the memory value for masked
1864 if (!b
->val_valid
&& !is_masked_watchpoint (b
))
1866 if (b
->val_bitsize
!= 0)
1868 v
= extract_bitfield_from_watchpoint_value (b
, v
);
1876 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1878 /* Look at each value on the value chain. */
1879 for (v
= val_chain
; v
; v
= value_next (v
))
1881 /* If it's a memory location, and GDB actually needed
1882 its contents to evaluate the expression, then we
1883 must watch it. If the first value returned is
1884 still lazy, that means an error occurred reading it;
1885 watch it anyway in case it becomes readable. */
1886 if (VALUE_LVAL (v
) == lval_memory
1887 && (v
== val_chain
|| ! value_lazy (v
)))
1889 struct type
*vtype
= check_typedef (value_type (v
));
1891 /* We only watch structs and arrays if user asked
1892 for it explicitly, never if they just happen to
1893 appear in the middle of some value chain. */
1895 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1896 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1899 enum target_hw_bp_type type
;
1900 struct bp_location
*loc
, **tmp
;
1901 int bitpos
= 0, bitsize
= 0;
1903 if (value_bitsize (v
) != 0)
1905 /* Extract the bit parameters out from the bitfield
1907 bitpos
= value_bitpos (v
);
1908 bitsize
= value_bitsize (v
);
1910 else if (v
== result
&& b
->val_bitsize
!= 0)
1912 /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield
1913 lvalue whose bit parameters are saved in the fields
1914 VAL_BITPOS and VAL_BITSIZE. */
1915 bitpos
= b
->val_bitpos
;
1916 bitsize
= b
->val_bitsize
;
1919 addr
= value_address (v
);
1922 /* Skip the bytes that don't contain the bitfield. */
1927 if (b
->type
== bp_read_watchpoint
)
1929 else if (b
->type
== bp_access_watchpoint
)
1932 loc
= allocate_bp_location (b
);
1933 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1936 loc
->gdbarch
= get_type_arch (value_type (v
));
1938 loc
->pspace
= frame_pspace
;
1939 loc
->address
= addr
;
1943 /* Just cover the bytes that make up the bitfield. */
1944 loc
->length
= ((bitpos
% 8) + bitsize
+ 7) / 8;
1947 loc
->length
= TYPE_LENGTH (value_type (v
));
1949 loc
->watchpoint_type
= type
;
1954 /* Change the type of breakpoint between hardware assisted or
1955 an ordinary watchpoint depending on the hardware support
1956 and free hardware slots. REPARSE is set when the inferior
1961 enum bp_loc_type loc_type
;
1962 struct bp_location
*bl
;
1964 reg_cnt
= can_use_hardware_watchpoint (val_chain
);
1968 int i
, target_resources_ok
, other_type_used
;
1971 /* Use an exact watchpoint when there's only one memory region to be
1972 watched, and only one debug register is needed to watch it. */
1973 b
->exact
= target_exact_watchpoints
&& reg_cnt
== 1;
1975 /* We need to determine how many resources are already
1976 used for all other hardware watchpoints plus this one
1977 to see if we still have enough resources to also fit
1978 this watchpoint in as well. */
1980 /* If this is a software watchpoint, we try to turn it
1981 to a hardware one -- count resources as if B was of
1982 hardware watchpoint type. */
1984 if (type
== bp_watchpoint
)
1985 type
= bp_hardware_watchpoint
;
1987 /* This watchpoint may or may not have been placed on
1988 the list yet at this point (it won't be in the list
1989 if we're trying to create it for the first time,
1990 through watch_command), so always account for it
1993 /* Count resources used by all watchpoints except B. */
1994 i
= hw_watchpoint_used_count_others (b
, type
, &other_type_used
);
1996 /* Add in the resources needed for B. */
1997 i
+= hw_watchpoint_use_count (b
);
2000 = target_can_use_hardware_watchpoint (type
, i
, other_type_used
);
2001 if (target_resources_ok
<= 0)
2003 int sw_mode
= b
->ops
->works_in_software_mode (b
);
2005 if (target_resources_ok
== 0 && !sw_mode
)
2006 error (_("Target does not support this type of "
2007 "hardware watchpoint."));
2008 else if (target_resources_ok
< 0 && !sw_mode
)
2009 error (_("There are not enough available hardware "
2010 "resources for this watchpoint."));
2012 /* Downgrade to software watchpoint. */
2013 b
->type
= bp_watchpoint
;
2017 /* If this was a software watchpoint, we've just
2018 found we have enough resources to turn it to a
2019 hardware watchpoint. Otherwise, this is a
2024 else if (!b
->ops
->works_in_software_mode (b
))
2026 if (!can_use_hw_watchpoints
)
2027 error (_("Can't set read/access watchpoint when "
2028 "hardware watchpoints are disabled."));
2030 error (_("Expression cannot be implemented with "
2031 "read/access watchpoint."));
2034 b
->type
= bp_watchpoint
;
2036 loc_type
= (b
->type
== bp_watchpoint
? bp_loc_other
2037 : bp_loc_hardware_watchpoint
);
2038 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
2039 bl
->loc_type
= loc_type
;
2042 for (v
= val_chain
; v
; v
= next
)
2044 next
= value_next (v
);
2049 /* If a software watchpoint is not watching any memory, then the
2050 above left it without any location set up. But,
2051 bpstat_stop_status requires a location to be able to report
2052 stops, so make sure there's at least a dummy one. */
2053 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
2054 software_watchpoint_add_no_memory_location (b
, frame_pspace
);
2056 else if (!within_current_scope
)
2058 printf_filtered (_("\
2059 Watchpoint %d deleted because the program has left the block\n\
2060 in which its expression is valid.\n"),
2062 watchpoint_del_at_next_stop (b
);
2065 /* Restore the selected frame. */
2067 select_frame (frame_find_by_id (saved_frame_id
));
2071 /* Returns 1 iff breakpoint location should be
2072 inserted in the inferior. We don't differentiate the type of BL's owner
2073 (breakpoint vs. tracepoint), although insert_location in tracepoint's
2074 breakpoint_ops is not defined, because in insert_bp_location,
2075 tracepoint's insert_location will not be called. */
2077 should_be_inserted (struct bp_location
*bl
)
2079 if (bl
->owner
== NULL
|| !breakpoint_enabled (bl
->owner
))
2082 if (bl
->owner
->disposition
== disp_del_at_next_stop
)
2085 if (!bl
->enabled
|| bl
->shlib_disabled
|| bl
->duplicate
)
2088 if (user_breakpoint_p (bl
->owner
) && bl
->pspace
->executing_startup
)
2091 /* This is set for example, when we're attached to the parent of a
2092 vfork, and have detached from the child. The child is running
2093 free, and we expect it to do an exec or exit, at which point the
2094 OS makes the parent schedulable again (and the target reports
2095 that the vfork is done). Until the child is done with the shared
2096 memory region, do not insert breakpoints in the parent, otherwise
2097 the child could still trip on the parent's breakpoints. Since
2098 the parent is blocked anyway, it won't miss any breakpoint. */
2099 if (bl
->pspace
->breakpoints_not_allowed
)
2102 /* Don't insert a breakpoint if we're trying to step past its
2103 location, except if the breakpoint is a single-step breakpoint,
2104 and the breakpoint's thread is the thread which is stepping past
2106 if ((bl
->loc_type
== bp_loc_software_breakpoint
2107 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2108 && stepping_past_instruction_at (bl
->pspace
->aspace
,
2110 /* The single-step breakpoint may be inserted at the location
2111 we're trying to step if the instruction branches to itself.
2112 However, the instruction won't be executed at all and it may
2113 break the semantics of the instruction, for example, the
2114 instruction is a conditional branch or updates some flags.
2115 We can't fix it unless GDB is able to emulate the instruction
2116 or switch to displaced stepping. */
2117 && !(bl
->owner
->type
== bp_single_step
2118 && thread_is_stepping_over_breakpoint (bl
->owner
->thread
)))
2122 fprintf_unfiltered (gdb_stdlog
,
2123 "infrun: skipping breakpoint: "
2124 "stepping past insn at: %s\n",
2125 paddress (bl
->gdbarch
, bl
->address
));
2130 /* Don't insert watchpoints if we're trying to step past the
2131 instruction that triggered one. */
2132 if ((bl
->loc_type
== bp_loc_hardware_watchpoint
)
2133 && stepping_past_nonsteppable_watchpoint ())
2137 fprintf_unfiltered (gdb_stdlog
,
2138 "infrun: stepping past non-steppable watchpoint. "
2139 "skipping watchpoint at %s:%d\n",
2140 paddress (bl
->gdbarch
, bl
->address
),
2149 /* Same as should_be_inserted but does the check assuming
2150 that the location is not duplicated. */
2153 unduplicated_should_be_inserted (struct bp_location
*bl
)
2156 const int save_duplicate
= bl
->duplicate
;
2159 result
= should_be_inserted (bl
);
2160 bl
->duplicate
= save_duplicate
;
2164 /* Parses a conditional described by an expression COND into an
2165 agent expression bytecode suitable for evaluation
2166 by the bytecode interpreter. Return NULL if there was
2167 any error during parsing. */
2169 static agent_expr_up
2170 parse_cond_to_aexpr (CORE_ADDR scope
, struct expression
*cond
)
2175 agent_expr_up aexpr
;
2177 /* We don't want to stop processing, so catch any errors
2178 that may show up. */
2181 aexpr
= gen_eval_for_expr (scope
, cond
);
2184 CATCH (ex
, RETURN_MASK_ERROR
)
2186 /* If we got here, it means the condition could not be parsed to a valid
2187 bytecode expression and thus can't be evaluated on the target's side.
2188 It's no use iterating through the conditions. */
2192 /* We have a valid agent expression. */
2196 /* Based on location BL, create a list of breakpoint conditions to be
2197 passed on to the target. If we have duplicated locations with different
2198 conditions, we will add such conditions to the list. The idea is that the
2199 target will evaluate the list of conditions and will only notify GDB when
2200 one of them is true. */
2203 build_target_condition_list (struct bp_location
*bl
)
2205 struct bp_location
**locp
= NULL
, **loc2p
;
2206 int null_condition_or_parse_error
= 0;
2207 int modified
= bl
->needs_update
;
2208 struct bp_location
*loc
;
2210 /* Release conditions left over from a previous insert. */
2211 bl
->target_info
.conditions
.clear ();
2213 /* This is only meaningful if the target is
2214 evaluating conditions and if the user has
2215 opted for condition evaluation on the target's
2217 if (gdb_evaluates_breakpoint_condition_p ()
2218 || !target_supports_evaluation_of_breakpoint_conditions ())
2221 /* Do a first pass to check for locations with no assigned
2222 conditions or conditions that fail to parse to a valid agent expression
2223 bytecode. If any of these happen, then it's no use to send conditions
2224 to the target since this location will always trigger and generate a
2225 response back to GDB. */
2226 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2229 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2233 /* Re-parse the conditions since something changed. In that
2234 case we already freed the condition bytecodes (see
2235 force_breakpoint_reinsertion). We just
2236 need to parse the condition to bytecodes again. */
2237 loc
->cond_bytecode
= parse_cond_to_aexpr (bl
->address
,
2241 /* If we have a NULL bytecode expression, it means something
2242 went wrong or we have a null condition expression. */
2243 if (!loc
->cond_bytecode
)
2245 null_condition_or_parse_error
= 1;
2251 /* If any of these happened, it means we will have to evaluate the conditions
2252 for the location's address on gdb's side. It is no use keeping bytecodes
2253 for all the other duplicate locations, thus we free all of them here.
2255 This is so we have a finer control over which locations' conditions are
2256 being evaluated by GDB or the remote stub. */
2257 if (null_condition_or_parse_error
)
2259 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2262 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2264 /* Only go as far as the first NULL bytecode is
2266 if (!loc
->cond_bytecode
)
2269 loc
->cond_bytecode
.reset ();
2274 /* No NULL conditions or failed bytecode generation. Build a condition list
2275 for this location's address. */
2276 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2280 && is_breakpoint (loc
->owner
)
2281 && loc
->pspace
->num
== bl
->pspace
->num
2282 && loc
->owner
->enable_state
== bp_enabled
2285 /* Add the condition to the vector. This will be used later
2286 to send the conditions to the target. */
2287 bl
->target_info
.conditions
.push_back (loc
->cond_bytecode
.get ());
2294 /* Parses a command described by string CMD into an agent expression
2295 bytecode suitable for evaluation by the bytecode interpreter.
2296 Return NULL if there was any error during parsing. */
2298 static agent_expr_up
2299 parse_cmd_to_aexpr (CORE_ADDR scope
, char *cmd
)
2301 struct cleanup
*old_cleanups
= 0;
2302 struct expression
**argvec
;
2303 const char *cmdrest
;
2304 const char *format_start
, *format_end
;
2305 struct format_piece
*fpieces
;
2307 struct gdbarch
*gdbarch
= get_current_arch ();
2314 if (*cmdrest
== ',')
2316 cmdrest
= skip_spaces (cmdrest
);
2318 if (*cmdrest
++ != '"')
2319 error (_("No format string following the location"));
2321 format_start
= cmdrest
;
2323 fpieces
= parse_format_string (&cmdrest
);
2325 old_cleanups
= make_cleanup (free_format_pieces_cleanup
, &fpieces
);
2327 format_end
= cmdrest
;
2329 if (*cmdrest
++ != '"')
2330 error (_("Bad format string, non-terminated '\"'."));
2332 cmdrest
= skip_spaces (cmdrest
);
2334 if (!(*cmdrest
== ',' || *cmdrest
== '\0'))
2335 error (_("Invalid argument syntax"));
2337 if (*cmdrest
== ',')
2339 cmdrest
= skip_spaces (cmdrest
);
2341 /* For each argument, make an expression. */
2343 argvec
= (struct expression
**) alloca (strlen (cmd
)
2344 * sizeof (struct expression
*));
2347 while (*cmdrest
!= '\0')
2352 expression_up expr
= parse_exp_1 (&cmd1
, scope
, block_for_pc (scope
), 1);
2353 argvec
[nargs
++] = expr
.release ();
2355 if (*cmdrest
== ',')
2359 agent_expr_up aexpr
;
2361 /* We don't want to stop processing, so catch any errors
2362 that may show up. */
2365 aexpr
= gen_printf (scope
, gdbarch
, 0, 0,
2366 format_start
, format_end
- format_start
,
2367 fpieces
, nargs
, argvec
);
2369 CATCH (ex
, RETURN_MASK_ERROR
)
2371 /* If we got here, it means the command could not be parsed to a valid
2372 bytecode expression and thus can't be evaluated on the target's side.
2373 It's no use iterating through the other commands. */
2377 do_cleanups (old_cleanups
);
2379 /* We have a valid agent expression, return it. */
2383 /* Based on location BL, create a list of breakpoint commands to be
2384 passed on to the target. If we have duplicated locations with
2385 different commands, we will add any such to the list. */
2388 build_target_command_list (struct bp_location
*bl
)
2390 struct bp_location
**locp
= NULL
, **loc2p
;
2391 int null_command_or_parse_error
= 0;
2392 int modified
= bl
->needs_update
;
2393 struct bp_location
*loc
;
2395 /* Clear commands left over from a previous insert. */
2396 bl
->target_info
.tcommands
.clear ();
2398 if (!target_can_run_breakpoint_commands ())
2401 /* For now, limit to agent-style dprintf breakpoints. */
2402 if (dprintf_style
!= dprintf_style_agent
)
2405 /* For now, if we have any duplicate location that isn't a dprintf,
2406 don't install the target-side commands, as that would make the
2407 breakpoint not be reported to the core, and we'd lose
2409 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2412 if (is_breakpoint (loc
->owner
)
2413 && loc
->pspace
->num
== bl
->pspace
->num
2414 && loc
->owner
->type
!= bp_dprintf
)
2418 /* Do a first pass to check for locations with no assigned
2419 conditions or conditions that fail to parse to a valid agent expression
2420 bytecode. If any of these happen, then it's no use to send conditions
2421 to the target since this location will always trigger and generate a
2422 response back to GDB. */
2423 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2426 if (is_breakpoint (loc
->owner
) && loc
->pspace
->num
== bl
->pspace
->num
)
2430 /* Re-parse the commands since something changed. In that
2431 case we already freed the command bytecodes (see
2432 force_breakpoint_reinsertion). We just
2433 need to parse the command to bytecodes again. */
2435 = parse_cmd_to_aexpr (bl
->address
,
2436 loc
->owner
->extra_string
);
2439 /* If we have a NULL bytecode expression, it means something
2440 went wrong or we have a null command expression. */
2441 if (!loc
->cmd_bytecode
)
2443 null_command_or_parse_error
= 1;
2449 /* If anything failed, then we're not doing target-side commands,
2451 if (null_command_or_parse_error
)
2453 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2456 if (is_breakpoint (loc
->owner
)
2457 && loc
->pspace
->num
== bl
->pspace
->num
)
2459 /* Only go as far as the first NULL bytecode is
2461 if (loc
->cmd_bytecode
== NULL
)
2464 loc
->cmd_bytecode
.reset ();
2469 /* No NULL commands or failed bytecode generation. Build a command list
2470 for this location's address. */
2471 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, bl
->address
)
2474 if (loc
->owner
->extra_string
2475 && is_breakpoint (loc
->owner
)
2476 && loc
->pspace
->num
== bl
->pspace
->num
2477 && loc
->owner
->enable_state
== bp_enabled
2480 /* Add the command to the vector. This will be used later
2481 to send the commands to the target. */
2482 bl
->target_info
.tcommands
.push_back (loc
->cmd_bytecode
.get ());
2486 bl
->target_info
.persist
= 0;
2487 /* Maybe flag this location as persistent. */
2488 if (bl
->owner
->type
== bp_dprintf
&& disconnected_dprintf
)
2489 bl
->target_info
.persist
= 1;
2492 /* Return the kind of breakpoint on address *ADDR. Get the kind
2493 of breakpoint according to ADDR except single-step breakpoint.
2494 Get the kind of single-step breakpoint according to the current
2498 breakpoint_kind (struct bp_location
*bl
, CORE_ADDR
*addr
)
2500 if (bl
->owner
->type
== bp_single_step
)
2502 struct thread_info
*thr
= find_thread_global_id (bl
->owner
->thread
);
2503 struct regcache
*regcache
;
2505 regcache
= get_thread_regcache (thr
->ptid
);
2507 return gdbarch_breakpoint_kind_from_current_state (bl
->gdbarch
,
2511 return gdbarch_breakpoint_kind_from_pc (bl
->gdbarch
, addr
);
2514 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint
2515 location. Any error messages are printed to TMP_ERROR_STREAM; and
2516 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
2517 Returns 0 for success, 1 if the bp_location type is not supported or
2520 NOTE drow/2003-09-09: This routine could be broken down to an
2521 object-style method for each breakpoint or catchpoint type. */
2523 insert_bp_location (struct bp_location
*bl
,
2524 struct ui_file
*tmp_error_stream
,
2525 int *disabled_breaks
,
2526 int *hw_breakpoint_error
,
2527 int *hw_bp_error_explained_already
)
2529 enum errors bp_err
= GDB_NO_ERROR
;
2530 const char *bp_err_message
= NULL
;
2532 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
2535 /* Note we don't initialize bl->target_info, as that wipes out
2536 the breakpoint location's shadow_contents if the breakpoint
2537 is still inserted at that location. This in turn breaks
2538 target_read_memory which depends on these buffers when
2539 a memory read is requested at the breakpoint location:
2540 Once the target_info has been wiped, we fail to see that
2541 we have a breakpoint inserted at that address and thus
2542 read the breakpoint instead of returning the data saved in
2543 the breakpoint location's shadow contents. */
2544 bl
->target_info
.reqstd_address
= bl
->address
;
2545 bl
->target_info
.placed_address_space
= bl
->pspace
->aspace
;
2546 bl
->target_info
.length
= bl
->length
;
2548 /* When working with target-side conditions, we must pass all the conditions
2549 for the same breakpoint address down to the target since GDB will not
2550 insert those locations. With a list of breakpoint conditions, the target
2551 can decide when to stop and notify GDB. */
2553 if (is_breakpoint (bl
->owner
))
2555 build_target_condition_list (bl
);
2556 build_target_command_list (bl
);
2557 /* Reset the modification marker. */
2558 bl
->needs_update
= 0;
2561 if (bl
->loc_type
== bp_loc_software_breakpoint
2562 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
2564 if (bl
->owner
->type
!= bp_hardware_breakpoint
)
2566 /* If the explicitly specified breakpoint type
2567 is not hardware breakpoint, check the memory map to see
2568 if the breakpoint address is in read only memory or not.
2570 Two important cases are:
2571 - location type is not hardware breakpoint, memory
2572 is readonly. We change the type of the location to
2573 hardware breakpoint.
2574 - location type is hardware breakpoint, memory is
2575 read-write. This means we've previously made the
2576 location hardware one, but then the memory map changed,
2579 When breakpoints are removed, remove_breakpoints will use
2580 location types we've just set here, the only possible
2581 problem is that memory map has changed during running
2582 program, but it's not going to work anyway with current
2584 struct mem_region
*mr
2585 = lookup_mem_region (bl
->target_info
.reqstd_address
);
2589 if (automatic_hardware_breakpoints
)
2591 enum bp_loc_type new_type
;
2593 if (mr
->attrib
.mode
!= MEM_RW
)
2594 new_type
= bp_loc_hardware_breakpoint
;
2596 new_type
= bp_loc_software_breakpoint
;
2598 if (new_type
!= bl
->loc_type
)
2600 static int said
= 0;
2602 bl
->loc_type
= new_type
;
2605 fprintf_filtered (gdb_stdout
,
2606 _("Note: automatically using "
2607 "hardware breakpoints for "
2608 "read-only addresses.\n"));
2613 else if (bl
->loc_type
== bp_loc_software_breakpoint
2614 && mr
->attrib
.mode
!= MEM_RW
)
2616 fprintf_unfiltered (tmp_error_stream
,
2617 _("Cannot insert breakpoint %d.\n"
2618 "Cannot set software breakpoint "
2619 "at read-only address %s\n"),
2621 paddress (bl
->gdbarch
, bl
->address
));
2627 /* First check to see if we have to handle an overlay. */
2628 if (overlay_debugging
== ovly_off
2629 || bl
->section
== NULL
2630 || !(section_is_overlay (bl
->section
)))
2632 /* No overlay handling: just set the breakpoint. */
2637 val
= bl
->owner
->ops
->insert_location (bl
);
2639 bp_err
= GENERIC_ERROR
;
2641 CATCH (e
, RETURN_MASK_ALL
)
2644 bp_err_message
= e
.message
;
2650 /* This breakpoint is in an overlay section.
2651 Shall we set a breakpoint at the LMA? */
2652 if (!overlay_events_enabled
)
2654 /* Yes -- overlay event support is not active,
2655 so we must try to set a breakpoint at the LMA.
2656 This will not work for a hardware breakpoint. */
2657 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2658 warning (_("hardware breakpoint %d not supported in overlay!"),
2662 CORE_ADDR addr
= overlay_unmapped_address (bl
->address
,
2664 /* Set a software (trap) breakpoint at the LMA. */
2665 bl
->overlay_target_info
= bl
->target_info
;
2666 bl
->overlay_target_info
.reqstd_address
= addr
;
2668 /* No overlay handling: just set the breakpoint. */
2673 bl
->overlay_target_info
.kind
2674 = breakpoint_kind (bl
, &addr
);
2675 bl
->overlay_target_info
.placed_address
= addr
;
2676 val
= target_insert_breakpoint (bl
->gdbarch
,
2677 &bl
->overlay_target_info
);
2679 bp_err
= GENERIC_ERROR
;
2681 CATCH (e
, RETURN_MASK_ALL
)
2684 bp_err_message
= e
.message
;
2688 if (bp_err
!= GDB_NO_ERROR
)
2689 fprintf_unfiltered (tmp_error_stream
,
2690 "Overlay breakpoint %d "
2691 "failed: in ROM?\n",
2695 /* Shall we set a breakpoint at the VMA? */
2696 if (section_is_mapped (bl
->section
))
2698 /* Yes. This overlay section is mapped into memory. */
2703 val
= bl
->owner
->ops
->insert_location (bl
);
2705 bp_err
= GENERIC_ERROR
;
2707 CATCH (e
, RETURN_MASK_ALL
)
2710 bp_err_message
= e
.message
;
2716 /* No. This breakpoint will not be inserted.
2717 No error, but do not mark the bp as 'inserted'. */
2722 if (bp_err
!= GDB_NO_ERROR
)
2724 /* Can't set the breakpoint. */
2726 /* In some cases, we might not be able to insert a
2727 breakpoint in a shared library that has already been
2728 removed, but we have not yet processed the shlib unload
2729 event. Unfortunately, some targets that implement
2730 breakpoint insertion themselves can't tell why the
2731 breakpoint insertion failed (e.g., the remote target
2732 doesn't define error codes), so we must treat generic
2733 errors as memory errors. */
2734 if ((bp_err
== GENERIC_ERROR
|| bp_err
== MEMORY_ERROR
)
2735 && bl
->loc_type
== bp_loc_software_breakpoint
2736 && (solib_name_from_address (bl
->pspace
, bl
->address
)
2737 || shared_objfile_contains_address_p (bl
->pspace
,
2740 /* See also: disable_breakpoints_in_shlibs. */
2741 bl
->shlib_disabled
= 1;
2742 observer_notify_breakpoint_modified (bl
->owner
);
2743 if (!*disabled_breaks
)
2745 fprintf_unfiltered (tmp_error_stream
,
2746 "Cannot insert breakpoint %d.\n",
2748 fprintf_unfiltered (tmp_error_stream
,
2749 "Temporarily disabling shared "
2750 "library breakpoints:\n");
2752 *disabled_breaks
= 1;
2753 fprintf_unfiltered (tmp_error_stream
,
2754 "breakpoint #%d\n", bl
->owner
->number
);
2759 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
2761 *hw_breakpoint_error
= 1;
2762 *hw_bp_error_explained_already
= bp_err_message
!= NULL
;
2763 fprintf_unfiltered (tmp_error_stream
,
2764 "Cannot insert hardware breakpoint %d%s",
2765 bl
->owner
->number
, bp_err_message
? ":" : ".\n");
2766 if (bp_err_message
!= NULL
)
2767 fprintf_unfiltered (tmp_error_stream
, "%s.\n", bp_err_message
);
2771 if (bp_err_message
== NULL
)
2774 = memory_error_message (TARGET_XFER_E_IO
,
2775 bl
->gdbarch
, bl
->address
);
2777 fprintf_unfiltered (tmp_error_stream
,
2778 "Cannot insert breakpoint %d.\n"
2780 bl
->owner
->number
, message
.c_str ());
2784 fprintf_unfiltered (tmp_error_stream
,
2785 "Cannot insert breakpoint %d: %s\n",
2800 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
2801 /* NOTE drow/2003-09-08: This state only exists for removing
2802 watchpoints. It's not clear that it's necessary... */
2803 && bl
->owner
->disposition
!= disp_del_at_next_stop
)
2807 gdb_assert (bl
->owner
->ops
!= NULL
2808 && bl
->owner
->ops
->insert_location
!= NULL
);
2810 val
= bl
->owner
->ops
->insert_location (bl
);
2812 /* If trying to set a read-watchpoint, and it turns out it's not
2813 supported, try emulating one with an access watchpoint. */
2814 if (val
== 1 && bl
->watchpoint_type
== hw_read
)
2816 struct bp_location
*loc
, **loc_temp
;
2818 /* But don't try to insert it, if there's already another
2819 hw_access location that would be considered a duplicate
2821 ALL_BP_LOCATIONS (loc
, loc_temp
)
2823 && loc
->watchpoint_type
== hw_access
2824 && watchpoint_locations_match (bl
, loc
))
2828 bl
->target_info
= loc
->target_info
;
2829 bl
->watchpoint_type
= hw_access
;
2836 bl
->watchpoint_type
= hw_access
;
2837 val
= bl
->owner
->ops
->insert_location (bl
);
2840 /* Back to the original value. */
2841 bl
->watchpoint_type
= hw_read
;
2845 bl
->inserted
= (val
== 0);
2848 else if (bl
->owner
->type
== bp_catchpoint
)
2852 gdb_assert (bl
->owner
->ops
!= NULL
2853 && bl
->owner
->ops
->insert_location
!= NULL
);
2855 val
= bl
->owner
->ops
->insert_location (bl
);
2858 bl
->owner
->enable_state
= bp_disabled
;
2862 Error inserting catchpoint %d: Your system does not support this type\n\
2863 of catchpoint."), bl
->owner
->number
);
2865 warning (_("Error inserting catchpoint %d."), bl
->owner
->number
);
2868 bl
->inserted
= (val
== 0);
2870 /* We've already printed an error message if there was a problem
2871 inserting this catchpoint, and we've disabled the catchpoint,
2872 so just return success. */
2879 /* This function is called when program space PSPACE is about to be
2880 deleted. It takes care of updating breakpoints to not reference
2884 breakpoint_program_space_exit (struct program_space
*pspace
)
2886 struct breakpoint
*b
, *b_temp
;
2887 struct bp_location
*loc
, **loc_temp
;
2889 /* Remove any breakpoint that was set through this program space. */
2890 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
2892 if (b
->pspace
== pspace
)
2893 delete_breakpoint (b
);
2896 /* Breakpoints set through other program spaces could have locations
2897 bound to PSPACE as well. Remove those. */
2898 ALL_BP_LOCATIONS (loc
, loc_temp
)
2900 struct bp_location
*tmp
;
2902 if (loc
->pspace
== pspace
)
2904 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
2905 if (loc
->owner
->loc
== loc
)
2906 loc
->owner
->loc
= loc
->next
;
2908 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
2909 if (tmp
->next
== loc
)
2911 tmp
->next
= loc
->next
;
2917 /* Now update the global location list to permanently delete the
2918 removed locations above. */
2919 update_global_location_list (UGLL_DONT_INSERT
);
2922 /* Make sure all breakpoints are inserted in inferior.
2923 Throws exception on any error.
2924 A breakpoint that is already inserted won't be inserted
2925 again, so calling this function twice is safe. */
2927 insert_breakpoints (void)
2929 struct breakpoint
*bpt
;
2931 ALL_BREAKPOINTS (bpt
)
2932 if (is_hardware_watchpoint (bpt
))
2934 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
2936 update_watchpoint (w
, 0 /* don't reparse. */);
2939 /* Updating watchpoints creates new locations, so update the global
2940 location list. Explicitly tell ugll to insert locations and
2941 ignore breakpoints_always_inserted_mode. */
2942 update_global_location_list (UGLL_INSERT
);
2945 /* Invoke CALLBACK for each of bp_location. */
2948 iterate_over_bp_locations (walk_bp_location_callback callback
)
2950 struct bp_location
*loc
, **loc_tmp
;
2952 ALL_BP_LOCATIONS (loc
, loc_tmp
)
2954 callback (loc
, NULL
);
2958 /* This is used when we need to synch breakpoint conditions between GDB and the
2959 target. It is the case with deleting and disabling of breakpoints when using
2960 always-inserted mode. */
2963 update_inserted_breakpoint_locations (void)
2965 struct bp_location
*bl
, **blp_tmp
;
2968 int disabled_breaks
= 0;
2969 int hw_breakpoint_error
= 0;
2970 int hw_bp_details_reported
= 0;
2972 string_file tmp_error_stream
;
2974 /* Explicitly mark the warning -- this will only be printed if
2975 there was an error. */
2976 tmp_error_stream
.puts ("Warning:\n");
2978 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
2980 ALL_BP_LOCATIONS (bl
, blp_tmp
)
2982 /* We only want to update software breakpoints and hardware
2984 if (!is_breakpoint (bl
->owner
))
2987 /* We only want to update locations that are already inserted
2988 and need updating. This is to avoid unwanted insertion during
2989 deletion of breakpoints. */
2990 if (!bl
->inserted
|| (bl
->inserted
&& !bl
->needs_update
))
2993 switch_to_program_space_and_thread (bl
->pspace
);
2995 /* For targets that support global breakpoints, there's no need
2996 to select an inferior to insert breakpoint to. In fact, even
2997 if we aren't attached to any process yet, we should still
2998 insert breakpoints. */
2999 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3000 && ptid_equal (inferior_ptid
, null_ptid
))
3003 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3004 &hw_breakpoint_error
, &hw_bp_details_reported
);
3011 target_terminal::ours_for_output ();
3012 error_stream (tmp_error_stream
);
3016 /* Used when starting or continuing the program. */
3019 insert_breakpoint_locations (void)
3021 struct breakpoint
*bpt
;
3022 struct bp_location
*bl
, **blp_tmp
;
3025 int disabled_breaks
= 0;
3026 int hw_breakpoint_error
= 0;
3027 int hw_bp_error_explained_already
= 0;
3029 string_file tmp_error_stream
;
3031 /* Explicitly mark the warning -- this will only be printed if
3032 there was an error. */
3033 tmp_error_stream
.puts ("Warning:\n");
3035 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3037 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3039 if (!should_be_inserted (bl
) || (bl
->inserted
&& !bl
->needs_update
))
3042 /* There is no point inserting thread-specific breakpoints if
3043 the thread no longer exists. ALL_BP_LOCATIONS bp_location
3044 has BL->OWNER always non-NULL. */
3045 if (bl
->owner
->thread
!= -1
3046 && !valid_global_thread_id (bl
->owner
->thread
))
3049 switch_to_program_space_and_thread (bl
->pspace
);
3051 /* For targets that support global breakpoints, there's no need
3052 to select an inferior to insert breakpoint to. In fact, even
3053 if we aren't attached to any process yet, we should still
3054 insert breakpoints. */
3055 if (!gdbarch_has_global_breakpoints (target_gdbarch ())
3056 && ptid_equal (inferior_ptid
, null_ptid
))
3059 val
= insert_bp_location (bl
, &tmp_error_stream
, &disabled_breaks
,
3060 &hw_breakpoint_error
, &hw_bp_error_explained_already
);
3065 /* If we failed to insert all locations of a watchpoint, remove
3066 them, as half-inserted watchpoint is of limited use. */
3067 ALL_BREAKPOINTS (bpt
)
3069 int some_failed
= 0;
3070 struct bp_location
*loc
;
3072 if (!is_hardware_watchpoint (bpt
))
3075 if (!breakpoint_enabled (bpt
))
3078 if (bpt
->disposition
== disp_del_at_next_stop
)
3081 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3082 if (!loc
->inserted
&& should_be_inserted (loc
))
3089 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
3091 remove_breakpoint (loc
);
3093 hw_breakpoint_error
= 1;
3094 tmp_error_stream
.printf ("Could not insert "
3095 "hardware watchpoint %d.\n",
3103 /* If a hardware breakpoint or watchpoint was inserted, add a
3104 message about possibly exhausted resources. */
3105 if (hw_breakpoint_error
&& !hw_bp_error_explained_already
)
3107 tmp_error_stream
.printf ("Could not insert hardware breakpoints:\n\
3108 You may have requested too many hardware breakpoints/watchpoints.\n");
3110 target_terminal::ours_for_output ();
3111 error_stream (tmp_error_stream
);
3115 /* Used when the program stops.
3116 Returns zero if successful, or non-zero if there was a problem
3117 removing a breakpoint location. */
3120 remove_breakpoints (void)
3122 struct bp_location
*bl
, **blp_tmp
;
3125 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3127 if (bl
->inserted
&& !is_tracepoint (bl
->owner
))
3128 val
|= remove_breakpoint (bl
);
3133 /* When a thread exits, remove breakpoints that are related to
3137 remove_threaded_breakpoints (struct thread_info
*tp
, int silent
)
3139 struct breakpoint
*b
, *b_tmp
;
3141 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3143 if (b
->thread
== tp
->global_num
&& user_breakpoint_p (b
))
3145 b
->disposition
= disp_del_at_next_stop
;
3147 printf_filtered (_("\
3148 Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"),
3149 b
->number
, print_thread_id (tp
));
3151 /* Hide it from the user. */
3157 /* Remove breakpoints of process PID. */
3160 remove_breakpoints_pid (int pid
)
3162 struct bp_location
*bl
, **blp_tmp
;
3164 struct inferior
*inf
= find_inferior_pid (pid
);
3166 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3168 if (bl
->pspace
!= inf
->pspace
)
3171 if (bl
->inserted
&& !bl
->target_info
.persist
)
3173 val
= remove_breakpoint (bl
);
3182 reattach_breakpoints (int pid
)
3184 struct bp_location
*bl
, **blp_tmp
;
3186 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
3187 struct inferior
*inf
;
3188 struct thread_info
*tp
;
3190 tp
= any_live_thread_of_process (pid
);
3194 inf
= find_inferior_pid (pid
);
3196 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3197 inferior_ptid
= tp
->ptid
;
3199 string_file tmp_error_stream
;
3201 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3203 if (bl
->pspace
!= inf
->pspace
)
3209 val
= insert_bp_location (bl
, &tmp_error_stream
, &dummy1
, &dummy2
, &dummy3
);
3217 static int internal_breakpoint_number
= -1;
3219 /* Set the breakpoint number of B, depending on the value of INTERNAL.
3220 If INTERNAL is non-zero, the breakpoint number will be populated
3221 from internal_breakpoint_number and that variable decremented.
3222 Otherwise the breakpoint number will be populated from
3223 breakpoint_count and that value incremented. Internal breakpoints
3224 do not set the internal var bpnum. */
3226 set_breakpoint_number (int internal
, struct breakpoint
*b
)
3229 b
->number
= internal_breakpoint_number
--;
3232 set_breakpoint_count (breakpoint_count
+ 1);
3233 b
->number
= breakpoint_count
;
3237 static struct breakpoint
*
3238 create_internal_breakpoint (struct gdbarch
*gdbarch
,
3239 CORE_ADDR address
, enum bptype type
,
3240 const struct breakpoint_ops
*ops
)
3242 symtab_and_line sal
;
3244 sal
.section
= find_pc_overlay (sal
.pc
);
3245 sal
.pspace
= current_program_space
;
3247 breakpoint
*b
= set_raw_breakpoint (gdbarch
, sal
, type
, ops
);
3248 b
->number
= internal_breakpoint_number
--;
3249 b
->disposition
= disp_donttouch
;
3254 static const char *const longjmp_names
[] =
3256 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp"
3258 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names)
3260 /* Per-objfile data private to breakpoint.c. */
3261 struct breakpoint_objfile_data
3263 /* Minimal symbol for "_ovly_debug_event" (if any). */
3264 struct bound_minimal_symbol overlay_msym
;
3266 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */
3267 struct bound_minimal_symbol longjmp_msym
[NUM_LONGJMP_NAMES
];
3269 /* True if we have looked for longjmp probes. */
3270 int longjmp_searched
;
3272 /* SystemTap probe points for longjmp (if any). */
3273 VEC (probe_p
) *longjmp_probes
;
3275 /* Minimal symbol for "std::terminate()" (if any). */
3276 struct bound_minimal_symbol terminate_msym
;
3278 /* Minimal symbol for "_Unwind_DebugHook" (if any). */
3279 struct bound_minimal_symbol exception_msym
;
3281 /* True if we have looked for exception probes. */
3282 int exception_searched
;
3284 /* SystemTap probe points for unwinding (if any). */
3285 VEC (probe_p
) *exception_probes
;
3288 static const struct objfile_data
*breakpoint_objfile_key
;
3290 /* Minimal symbol not found sentinel. */
3291 static struct minimal_symbol msym_not_found
;
3293 /* Returns TRUE if MSYM point to the "not found" sentinel. */
3296 msym_not_found_p (const struct minimal_symbol
*msym
)
3298 return msym
== &msym_not_found
;
3301 /* Return per-objfile data needed by breakpoint.c.
3302 Allocate the data if necessary. */
3304 static struct breakpoint_objfile_data
*
3305 get_breakpoint_objfile_data (struct objfile
*objfile
)
3307 struct breakpoint_objfile_data
*bp_objfile_data
;
3309 bp_objfile_data
= ((struct breakpoint_objfile_data
*)
3310 objfile_data (objfile
, breakpoint_objfile_key
));
3311 if (bp_objfile_data
== NULL
)
3314 XOBNEW (&objfile
->objfile_obstack
, struct breakpoint_objfile_data
);
3316 memset (bp_objfile_data
, 0, sizeof (*bp_objfile_data
));
3317 set_objfile_data (objfile
, breakpoint_objfile_key
, bp_objfile_data
);
3319 return bp_objfile_data
;
3323 free_breakpoint_probes (struct objfile
*obj
, void *data
)
3325 struct breakpoint_objfile_data
*bp_objfile_data
3326 = (struct breakpoint_objfile_data
*) data
;
3328 VEC_free (probe_p
, bp_objfile_data
->longjmp_probes
);
3329 VEC_free (probe_p
, bp_objfile_data
->exception_probes
);
3333 create_overlay_event_breakpoint (void)
3335 struct objfile
*objfile
;
3336 const char *const func_name
= "_ovly_debug_event";
3338 ALL_OBJFILES (objfile
)
3340 struct breakpoint
*b
;
3341 struct breakpoint_objfile_data
*bp_objfile_data
;
3343 struct explicit_location explicit_loc
;
3345 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3347 if (msym_not_found_p (bp_objfile_data
->overlay_msym
.minsym
))
3350 if (bp_objfile_data
->overlay_msym
.minsym
== NULL
)
3352 struct bound_minimal_symbol m
;
3354 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3355 if (m
.minsym
== NULL
)
3357 /* Avoid future lookups in this objfile. */
3358 bp_objfile_data
->overlay_msym
.minsym
= &msym_not_found
;
3361 bp_objfile_data
->overlay_msym
= m
;
3364 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->overlay_msym
);
3365 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3367 &internal_breakpoint_ops
);
3368 initialize_explicit_location (&explicit_loc
);
3369 explicit_loc
.function_name
= ASTRDUP (func_name
);
3370 b
->location
= new_explicit_location (&explicit_loc
);
3372 if (overlay_debugging
== ovly_auto
)
3374 b
->enable_state
= bp_enabled
;
3375 overlay_events_enabled
= 1;
3379 b
->enable_state
= bp_disabled
;
3380 overlay_events_enabled
= 0;
3386 create_longjmp_master_breakpoint (void)
3388 struct program_space
*pspace
;
3390 scoped_restore_current_program_space restore_pspace
;
3392 ALL_PSPACES (pspace
)
3394 struct objfile
*objfile
;
3396 set_current_program_space (pspace
);
3398 ALL_OBJFILES (objfile
)
3401 struct gdbarch
*gdbarch
;
3402 struct breakpoint_objfile_data
*bp_objfile_data
;
3404 gdbarch
= get_objfile_arch (objfile
);
3406 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3408 if (!bp_objfile_data
->longjmp_searched
)
3412 ret
= find_probes_in_objfile (objfile
, "libc", "longjmp");
3415 /* We are only interested in checking one element. */
3416 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3418 if (!can_evaluate_probe_arguments (p
))
3420 /* We cannot use the probe interface here, because it does
3421 not know how to evaluate arguments. */
3422 VEC_free (probe_p
, ret
);
3426 bp_objfile_data
->longjmp_probes
= ret
;
3427 bp_objfile_data
->longjmp_searched
= 1;
3430 if (bp_objfile_data
->longjmp_probes
!= NULL
)
3433 struct probe
*probe
;
3434 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3437 VEC_iterate (probe_p
,
3438 bp_objfile_data
->longjmp_probes
,
3442 struct breakpoint
*b
;
3444 b
= create_internal_breakpoint (gdbarch
,
3445 get_probe_address (probe
,
3448 &internal_breakpoint_ops
);
3449 b
->location
= new_probe_location ("-probe-stap libc:longjmp");
3450 b
->enable_state
= bp_disabled
;
3456 if (!gdbarch_get_longjmp_target_p (gdbarch
))
3459 for (i
= 0; i
< NUM_LONGJMP_NAMES
; i
++)
3461 struct breakpoint
*b
;
3462 const char *func_name
;
3464 struct explicit_location explicit_loc
;
3466 if (msym_not_found_p (bp_objfile_data
->longjmp_msym
[i
].minsym
))
3469 func_name
= longjmp_names
[i
];
3470 if (bp_objfile_data
->longjmp_msym
[i
].minsym
== NULL
)
3472 struct bound_minimal_symbol m
;
3474 m
= lookup_minimal_symbol_text (func_name
, objfile
);
3475 if (m
.minsym
== NULL
)
3477 /* Prevent future lookups in this objfile. */
3478 bp_objfile_data
->longjmp_msym
[i
].minsym
= &msym_not_found
;
3481 bp_objfile_data
->longjmp_msym
[i
] = m
;
3484 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->longjmp_msym
[i
]);
3485 b
= create_internal_breakpoint (gdbarch
, addr
, bp_longjmp_master
,
3486 &internal_breakpoint_ops
);
3487 initialize_explicit_location (&explicit_loc
);
3488 explicit_loc
.function_name
= ASTRDUP (func_name
);
3489 b
->location
= new_explicit_location (&explicit_loc
);
3490 b
->enable_state
= bp_disabled
;
3496 /* Create a master std::terminate breakpoint. */
3498 create_std_terminate_master_breakpoint (void)
3500 struct program_space
*pspace
;
3501 const char *const func_name
= "std::terminate()";
3503 scoped_restore_current_program_space restore_pspace
;
3505 ALL_PSPACES (pspace
)
3507 struct objfile
*objfile
;
3510 set_current_program_space (pspace
);
3512 ALL_OBJFILES (objfile
)
3514 struct breakpoint
*b
;
3515 struct breakpoint_objfile_data
*bp_objfile_data
;
3516 struct explicit_location explicit_loc
;
3518 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3520 if (msym_not_found_p (bp_objfile_data
->terminate_msym
.minsym
))
3523 if (bp_objfile_data
->terminate_msym
.minsym
== NULL
)
3525 struct bound_minimal_symbol m
;
3527 m
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3528 if (m
.minsym
== NULL
|| (MSYMBOL_TYPE (m
.minsym
) != mst_text
3529 && MSYMBOL_TYPE (m
.minsym
) != mst_file_text
))
3531 /* Prevent future lookups in this objfile. */
3532 bp_objfile_data
->terminate_msym
.minsym
= &msym_not_found
;
3535 bp_objfile_data
->terminate_msym
= m
;
3538 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->terminate_msym
);
3539 b
= create_internal_breakpoint (get_objfile_arch (objfile
), addr
,
3540 bp_std_terminate_master
,
3541 &internal_breakpoint_ops
);
3542 initialize_explicit_location (&explicit_loc
);
3543 explicit_loc
.function_name
= ASTRDUP (func_name
);
3544 b
->location
= new_explicit_location (&explicit_loc
);
3545 b
->enable_state
= bp_disabled
;
3550 /* Install a master breakpoint on the unwinder's debug hook. */
3553 create_exception_master_breakpoint (void)
3555 struct objfile
*objfile
;
3556 const char *const func_name
= "_Unwind_DebugHook";
3558 ALL_OBJFILES (objfile
)
3560 struct breakpoint
*b
;
3561 struct gdbarch
*gdbarch
;
3562 struct breakpoint_objfile_data
*bp_objfile_data
;
3564 struct explicit_location explicit_loc
;
3566 bp_objfile_data
= get_breakpoint_objfile_data (objfile
);
3568 /* We prefer the SystemTap probe point if it exists. */
3569 if (!bp_objfile_data
->exception_searched
)
3573 ret
= find_probes_in_objfile (objfile
, "libgcc", "unwind");
3577 /* We are only interested in checking one element. */
3578 struct probe
*p
= VEC_index (probe_p
, ret
, 0);
3580 if (!can_evaluate_probe_arguments (p
))
3582 /* We cannot use the probe interface here, because it does
3583 not know how to evaluate arguments. */
3584 VEC_free (probe_p
, ret
);
3588 bp_objfile_data
->exception_probes
= ret
;
3589 bp_objfile_data
->exception_searched
= 1;
3592 if (bp_objfile_data
->exception_probes
!= NULL
)
3594 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3596 struct probe
*probe
;
3599 VEC_iterate (probe_p
,
3600 bp_objfile_data
->exception_probes
,
3604 struct breakpoint
*b
;
3606 b
= create_internal_breakpoint (gdbarch
,
3607 get_probe_address (probe
,
3609 bp_exception_master
,
3610 &internal_breakpoint_ops
);
3611 b
->location
= new_probe_location ("-probe-stap libgcc:unwind");
3612 b
->enable_state
= bp_disabled
;
3618 /* Otherwise, try the hook function. */
3620 if (msym_not_found_p (bp_objfile_data
->exception_msym
.minsym
))
3623 gdbarch
= get_objfile_arch (objfile
);
3625 if (bp_objfile_data
->exception_msym
.minsym
== NULL
)
3627 struct bound_minimal_symbol debug_hook
;
3629 debug_hook
= lookup_minimal_symbol (func_name
, NULL
, objfile
);
3630 if (debug_hook
.minsym
== NULL
)
3632 bp_objfile_data
->exception_msym
.minsym
= &msym_not_found
;
3636 bp_objfile_data
->exception_msym
= debug_hook
;
3639 addr
= BMSYMBOL_VALUE_ADDRESS (bp_objfile_data
->exception_msym
);
3640 addr
= gdbarch_convert_from_func_ptr_addr (gdbarch
, addr
,
3642 b
= create_internal_breakpoint (gdbarch
, addr
, bp_exception_master
,
3643 &internal_breakpoint_ops
);
3644 initialize_explicit_location (&explicit_loc
);
3645 explicit_loc
.function_name
= ASTRDUP (func_name
);
3646 b
->location
= new_explicit_location (&explicit_loc
);
3647 b
->enable_state
= bp_disabled
;
3651 /* Does B have a location spec? */
3654 breakpoint_event_location_empty_p (const struct breakpoint
*b
)
3656 return b
->location
!= NULL
&& event_location_empty_p (b
->location
.get ());
3660 update_breakpoints_after_exec (void)
3662 struct breakpoint
*b
, *b_tmp
;
3663 struct bp_location
*bploc
, **bplocp_tmp
;
3665 /* We're about to delete breakpoints from GDB's lists. If the
3666 INSERTED flag is true, GDB will try to lift the breakpoints by
3667 writing the breakpoints' "shadow contents" back into memory. The
3668 "shadow contents" are NOT valid after an exec, so GDB should not
3669 do that. Instead, the target is responsible from marking
3670 breakpoints out as soon as it detects an exec. We don't do that
3671 here instead, because there may be other attempts to delete
3672 breakpoints after detecting an exec and before reaching here. */
3673 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
3674 if (bploc
->pspace
== current_program_space
)
3675 gdb_assert (!bploc
->inserted
);
3677 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
3679 if (b
->pspace
!= current_program_space
)
3682 /* Solib breakpoints must be explicitly reset after an exec(). */
3683 if (b
->type
== bp_shlib_event
)
3685 delete_breakpoint (b
);
3689 /* JIT breakpoints must be explicitly reset after an exec(). */
3690 if (b
->type
== bp_jit_event
)
3692 delete_breakpoint (b
);
3696 /* Thread event breakpoints must be set anew after an exec(),
3697 as must overlay event and longjmp master breakpoints. */
3698 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3699 || b
->type
== bp_longjmp_master
|| b
->type
== bp_std_terminate_master
3700 || b
->type
== bp_exception_master
)
3702 delete_breakpoint (b
);
3706 /* Step-resume breakpoints are meaningless after an exec(). */
3707 if (b
->type
== bp_step_resume
|| b
->type
== bp_hp_step_resume
)
3709 delete_breakpoint (b
);
3713 /* Just like single-step breakpoints. */
3714 if (b
->type
== bp_single_step
)
3716 delete_breakpoint (b
);
3720 /* Longjmp and longjmp-resume breakpoints are also meaningless
3722 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
3723 || b
->type
== bp_longjmp_call_dummy
3724 || b
->type
== bp_exception
|| b
->type
== bp_exception_resume
)
3726 delete_breakpoint (b
);
3730 if (b
->type
== bp_catchpoint
)
3732 /* For now, none of the bp_catchpoint breakpoints need to
3733 do anything at this point. In the future, if some of
3734 the catchpoints need to something, we will need to add
3735 a new method, and call this method from here. */
3739 /* bp_finish is a special case. The only way we ought to be able
3740 to see one of these when an exec() has happened, is if the user
3741 caught a vfork, and then said "finish". Ordinarily a finish just
3742 carries them to the call-site of the current callee, by setting
3743 a temporary bp there and resuming. But in this case, the finish
3744 will carry them entirely through the vfork & exec.
3746 We don't want to allow a bp_finish to remain inserted now. But
3747 we can't safely delete it, 'cause finish_command has a handle to
3748 the bp on a bpstat, and will later want to delete it. There's a
3749 chance (and I've seen it happen) that if we delete the bp_finish
3750 here, that its storage will get reused by the time finish_command
3751 gets 'round to deleting the "use to be a bp_finish" breakpoint.
3752 We really must allow finish_command to delete a bp_finish.
3754 In the absence of a general solution for the "how do we know
3755 it's safe to delete something others may have handles to?"
3756 problem, what we'll do here is just uninsert the bp_finish, and
3757 let finish_command delete it.
3759 (We know the bp_finish is "doomed" in the sense that it's
3760 momentary, and will be deleted as soon as finish_command sees
3761 the inferior stopped. So it doesn't matter that the bp's
3762 address is probably bogus in the new a.out, unlike e.g., the
3763 solib breakpoints.) */
3765 if (b
->type
== bp_finish
)
3770 /* Without a symbolic address, we have little hope of the
3771 pre-exec() address meaning the same thing in the post-exec()
3773 if (breakpoint_event_location_empty_p (b
))
3775 delete_breakpoint (b
);
3782 detach_breakpoints (ptid_t ptid
)
3784 struct bp_location
*bl
, **blp_tmp
;
3786 scoped_restore save_inferior_ptid
= make_scoped_restore (&inferior_ptid
);
3787 struct inferior
*inf
= current_inferior ();
3789 if (ptid_get_pid (ptid
) == ptid_get_pid (inferior_ptid
))
3790 error (_("Cannot detach breakpoints of inferior_ptid"));
3792 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
3793 inferior_ptid
= ptid
;
3794 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3796 if (bl
->pspace
!= inf
->pspace
)
3799 /* This function must physically remove breakpoints locations
3800 from the specified ptid, without modifying the breakpoint
3801 package's state. Locations of type bp_loc_other are only
3802 maintained at GDB side. So, there is no need to remove
3803 these bp_loc_other locations. Moreover, removing these
3804 would modify the breakpoint package's state. */
3805 if (bl
->loc_type
== bp_loc_other
)
3809 val
|= remove_breakpoint_1 (bl
, DETACH_BREAKPOINT
);
3815 /* Remove the breakpoint location BL from the current address space.
3816 Note that this is used to detach breakpoints from a child fork.
3817 When we get here, the child isn't in the inferior list, and neither
3818 do we have objects to represent its address space --- we should
3819 *not* look at bl->pspace->aspace here. */
3822 remove_breakpoint_1 (struct bp_location
*bl
, enum remove_bp_reason reason
)
3826 /* BL is never in moribund_locations by our callers. */
3827 gdb_assert (bl
->owner
!= NULL
);
3829 /* The type of none suggests that owner is actually deleted.
3830 This should not ever happen. */
3831 gdb_assert (bl
->owner
->type
!= bp_none
);
3833 if (bl
->loc_type
== bp_loc_software_breakpoint
3834 || bl
->loc_type
== bp_loc_hardware_breakpoint
)
3836 /* "Normal" instruction breakpoint: either the standard
3837 trap-instruction bp (bp_breakpoint), or a
3838 bp_hardware_breakpoint. */
3840 /* First check to see if we have to handle an overlay. */
3841 if (overlay_debugging
== ovly_off
3842 || bl
->section
== NULL
3843 || !(section_is_overlay (bl
->section
)))
3845 /* No overlay handling: just remove the breakpoint. */
3847 /* If we're trying to uninsert a memory breakpoint that we
3848 know is set in a dynamic object that is marked
3849 shlib_disabled, then either the dynamic object was
3850 removed with "remove-symbol-file" or with
3851 "nosharedlibrary". In the former case, we don't know
3852 whether another dynamic object might have loaded over the
3853 breakpoint's address -- the user might well let us know
3854 about it next with add-symbol-file (the whole point of
3855 add-symbol-file is letting the user manually maintain a
3856 list of dynamically loaded objects). If we have the
3857 breakpoint's shadow memory, that is, this is a software
3858 breakpoint managed by GDB, check whether the breakpoint
3859 is still inserted in memory, to avoid overwriting wrong
3860 code with stale saved shadow contents. Note that HW
3861 breakpoints don't have shadow memory, as they're
3862 implemented using a mechanism that is not dependent on
3863 being able to modify the target's memory, and as such
3864 they should always be removed. */
3865 if (bl
->shlib_disabled
3866 && bl
->target_info
.shadow_len
!= 0
3867 && !memory_validate_breakpoint (bl
->gdbarch
, &bl
->target_info
))
3870 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3874 /* This breakpoint is in an overlay section.
3875 Did we set a breakpoint at the LMA? */
3876 if (!overlay_events_enabled
)
3878 /* Yes -- overlay event support is not active, so we
3879 should have set a breakpoint at the LMA. Remove it.
3881 /* Ignore any failures: if the LMA is in ROM, we will
3882 have already warned when we failed to insert it. */
3883 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
3884 target_remove_hw_breakpoint (bl
->gdbarch
,
3885 &bl
->overlay_target_info
);
3887 target_remove_breakpoint (bl
->gdbarch
,
3888 &bl
->overlay_target_info
,
3891 /* Did we set a breakpoint at the VMA?
3892 If so, we will have marked the breakpoint 'inserted'. */
3895 /* Yes -- remove it. Previously we did not bother to
3896 remove the breakpoint if the section had been
3897 unmapped, but let's not rely on that being safe. We
3898 don't know what the overlay manager might do. */
3900 /* However, we should remove *software* breakpoints only
3901 if the section is still mapped, or else we overwrite
3902 wrong code with the saved shadow contents. */
3903 if (bl
->loc_type
== bp_loc_hardware_breakpoint
3904 || section_is_mapped (bl
->section
))
3905 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3911 /* No -- not inserted, so no need to remove. No error. */
3916 /* In some cases, we might not be able to remove a breakpoint in
3917 a shared library that has already been removed, but we have
3918 not yet processed the shlib unload event. Similarly for an
3919 unloaded add-symbol-file object - the user might not yet have
3920 had the chance to remove-symbol-file it. shlib_disabled will
3921 be set if the library/object has already been removed, but
3922 the breakpoint hasn't been uninserted yet, e.g., after
3923 "nosharedlibrary" or "remove-symbol-file" with breakpoints
3924 always-inserted mode. */
3926 && (bl
->loc_type
== bp_loc_software_breakpoint
3927 && (bl
->shlib_disabled
3928 || solib_name_from_address (bl
->pspace
, bl
->address
)
3929 || shared_objfile_contains_address_p (bl
->pspace
,
3935 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3937 else if (bl
->loc_type
== bp_loc_hardware_watchpoint
)
3939 gdb_assert (bl
->owner
->ops
!= NULL
3940 && bl
->owner
->ops
->remove_location
!= NULL
);
3942 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3943 bl
->owner
->ops
->remove_location (bl
, reason
);
3945 /* Failure to remove any of the hardware watchpoints comes here. */
3946 if (reason
== REMOVE_BREAKPOINT
&& bl
->inserted
)
3947 warning (_("Could not remove hardware watchpoint %d."),
3950 else if (bl
->owner
->type
== bp_catchpoint
3951 && breakpoint_enabled (bl
->owner
)
3954 gdb_assert (bl
->owner
->ops
!= NULL
3955 && bl
->owner
->ops
->remove_location
!= NULL
);
3957 val
= bl
->owner
->ops
->remove_location (bl
, reason
);
3961 bl
->inserted
= (reason
== DETACH_BREAKPOINT
);
3968 remove_breakpoint (struct bp_location
*bl
)
3970 /* BL is never in moribund_locations by our callers. */
3971 gdb_assert (bl
->owner
!= NULL
);
3973 /* The type of none suggests that owner is actually deleted.
3974 This should not ever happen. */
3975 gdb_assert (bl
->owner
->type
!= bp_none
);
3977 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
3979 switch_to_program_space_and_thread (bl
->pspace
);
3981 return remove_breakpoint_1 (bl
, REMOVE_BREAKPOINT
);
3984 /* Clear the "inserted" flag in all breakpoints. */
3987 mark_breakpoints_out (void)
3989 struct bp_location
*bl
, **blp_tmp
;
3991 ALL_BP_LOCATIONS (bl
, blp_tmp
)
3992 if (bl
->pspace
== current_program_space
)
3996 /* Clear the "inserted" flag in all breakpoints and delete any
3997 breakpoints which should go away between runs of the program.
3999 Plus other such housekeeping that has to be done for breakpoints
4002 Note: this function gets called at the end of a run (by
4003 generic_mourn_inferior) and when a run begins (by
4004 init_wait_for_inferior). */
4009 breakpoint_init_inferior (enum inf_context context
)
4011 struct breakpoint
*b
, *b_tmp
;
4012 struct bp_location
*bl
;
4014 struct program_space
*pspace
= current_program_space
;
4016 /* If breakpoint locations are shared across processes, then there's
4018 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
4021 mark_breakpoints_out ();
4023 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
4025 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
4031 case bp_longjmp_call_dummy
:
4033 /* If the call dummy breakpoint is at the entry point it will
4034 cause problems when the inferior is rerun, so we better get
4037 case bp_watchpoint_scope
:
4039 /* Also get rid of scope breakpoints. */
4041 case bp_shlib_event
:
4043 /* Also remove solib event breakpoints. Their addresses may
4044 have changed since the last time we ran the program.
4045 Actually we may now be debugging against different target;
4046 and so the solib backend that installed this breakpoint may
4047 not be used in by the target. E.g.,
4049 (gdb) file prog-linux
4050 (gdb) run # native linux target
4053 (gdb) file prog-win.exe
4054 (gdb) tar rem :9999 # remote Windows gdbserver.
4057 case bp_step_resume
:
4059 /* Also remove step-resume breakpoints. */
4061 case bp_single_step
:
4063 /* Also remove single-step breakpoints. */
4065 delete_breakpoint (b
);
4069 case bp_hardware_watchpoint
:
4070 case bp_read_watchpoint
:
4071 case bp_access_watchpoint
:
4073 struct watchpoint
*w
= (struct watchpoint
*) b
;
4075 /* Likewise for watchpoints on local expressions. */
4076 if (w
->exp_valid_block
!= NULL
)
4077 delete_breakpoint (b
);
4080 /* Get rid of existing locations, which are no longer
4081 valid. New ones will be created in
4082 update_watchpoint, when the inferior is restarted.
4083 The next update_global_location_list call will
4084 garbage collect them. */
4087 if (context
== inf_starting
)
4089 /* Reset val field to force reread of starting value in
4090 insert_breakpoints. */
4092 value_free (w
->val
);
4104 /* Get rid of the moribund locations. */
4105 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bl
); ++ix
)
4106 decref_bp_location (&bl
);
4107 VEC_free (bp_location_p
, moribund_locations
);
4110 /* These functions concern about actual breakpoints inserted in the
4111 target --- to e.g. check if we need to do decr_pc adjustment or if
4112 we need to hop over the bkpt --- so we check for address space
4113 match, not program space. */
4115 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
4116 exists at PC. It returns ordinary_breakpoint_here if it's an
4117 ordinary breakpoint, or permanent_breakpoint_here if it's a
4118 permanent breakpoint.
4119 - When continuing from a location with an ordinary breakpoint, we
4120 actually single step once before calling insert_breakpoints.
4121 - When continuing from a location with a permanent breakpoint, we
4122 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
4123 the target, to advance the PC past the breakpoint. */
4125 enum breakpoint_here
4126 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4128 struct bp_location
*bl
, **blp_tmp
;
4129 int any_breakpoint_here
= 0;
4131 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4133 if (bl
->loc_type
!= bp_loc_software_breakpoint
4134 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4137 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */
4138 if ((breakpoint_enabled (bl
->owner
)
4140 && breakpoint_location_address_match (bl
, aspace
, pc
))
4142 if (overlay_debugging
4143 && section_is_overlay (bl
->section
)
4144 && !section_is_mapped (bl
->section
))
4145 continue; /* unmapped overlay -- can't be a match */
4146 else if (bl
->permanent
)
4147 return permanent_breakpoint_here
;
4149 any_breakpoint_here
= 1;
4153 return any_breakpoint_here
? ordinary_breakpoint_here
: no_breakpoint_here
;
4156 /* See breakpoint.h. */
4159 breakpoint_in_range_p (struct address_space
*aspace
,
4160 CORE_ADDR addr
, ULONGEST len
)
4162 struct bp_location
*bl
, **blp_tmp
;
4164 ALL_BP_LOCATIONS (bl
, blp_tmp
)
4166 if (bl
->loc_type
!= bp_loc_software_breakpoint
4167 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4170 if ((breakpoint_enabled (bl
->owner
)
4172 && breakpoint_location_address_range_overlap (bl
, aspace
,
4175 if (overlay_debugging
4176 && section_is_overlay (bl
->section
)
4177 && !section_is_mapped (bl
->section
))
4179 /* Unmapped overlay -- can't be a match. */
4190 /* Return true if there's a moribund breakpoint at PC. */
4193 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4195 struct bp_location
*loc
;
4198 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4199 if (breakpoint_location_address_match (loc
, aspace
, pc
))
4205 /* Returns non-zero iff BL is inserted at PC, in address space
4209 bp_location_inserted_here_p (struct bp_location
*bl
,
4210 struct address_space
*aspace
, CORE_ADDR pc
)
4213 && breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
4216 if (overlay_debugging
4217 && section_is_overlay (bl
->section
)
4218 && !section_is_mapped (bl
->section
))
4219 return 0; /* unmapped overlay -- can't be a match */
4226 /* Returns non-zero iff there's a breakpoint inserted at PC. */
4229 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
4231 struct bp_location
**blp
, **blp_tmp
= NULL
;
4233 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4235 struct bp_location
*bl
= *blp
;
4237 if (bl
->loc_type
!= bp_loc_software_breakpoint
4238 && bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4241 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4247 /* This function returns non-zero iff there is a software breakpoint
4251 software_breakpoint_inserted_here_p (struct address_space
*aspace
,
4254 struct bp_location
**blp
, **blp_tmp
= NULL
;
4256 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4258 struct bp_location
*bl
= *blp
;
4260 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
4263 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4270 /* See breakpoint.h. */
4273 hardware_breakpoint_inserted_here_p (struct address_space
*aspace
,
4276 struct bp_location
**blp
, **blp_tmp
= NULL
;
4278 ALL_BP_LOCATIONS_AT_ADDR (blp
, blp_tmp
, pc
)
4280 struct bp_location
*bl
= *blp
;
4282 if (bl
->loc_type
!= bp_loc_hardware_breakpoint
)
4285 if (bp_location_inserted_here_p (bl
, aspace
, pc
))
4293 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
4294 CORE_ADDR addr
, ULONGEST len
)
4296 struct breakpoint
*bpt
;
4298 ALL_BREAKPOINTS (bpt
)
4300 struct bp_location
*loc
;
4302 if (bpt
->type
!= bp_hardware_watchpoint
4303 && bpt
->type
!= bp_access_watchpoint
)
4306 if (!breakpoint_enabled (bpt
))
4309 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
4310 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
4314 /* Check for intersection. */
4315 l
= std::max
<CORE_ADDR
> (loc
->address
, addr
);
4316 h
= std::min
<CORE_ADDR
> (loc
->address
+ loc
->length
, addr
+ len
);
4325 /* bpstat stuff. External routines' interfaces are documented
4329 is_catchpoint (struct breakpoint
*ep
)
4331 return (ep
->type
== bp_catchpoint
);
4334 /* Frees any storage that is part of a bpstat. Does not walk the
4337 bpstats::~bpstats ()
4339 if (old_val
!= NULL
)
4340 value_free (old_val
);
4341 if (bp_location_at
!= NULL
)
4342 decref_bp_location (&bp_location_at
);
4345 /* Clear a bpstat so that it says we are not at any breakpoint.
4346 Also free any storage that is part of a bpstat. */
4349 bpstat_clear (bpstat
*bsp
)
4366 bpstats::bpstats (const bpstats
&other
)
4368 bp_location_at (other
.bp_location_at
),
4369 breakpoint_at (other
.breakpoint_at
),
4370 commands (other
.commands
),
4371 old_val (other
.old_val
),
4372 print (other
.print
),
4374 print_it (other
.print_it
)
4376 if (old_val
!= NULL
)
4378 old_val
= value_copy (old_val
);
4379 release_value (old_val
);
4381 incref_bp_location (bp_location_at
);
4384 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
4385 is part of the bpstat is copied as well. */
4388 bpstat_copy (bpstat bs
)
4392 bpstat retval
= NULL
;
4397 for (; bs
!= NULL
; bs
= bs
->next
)
4399 tmp
= new bpstats (*bs
);
4402 /* This is the first thing in the chain. */
4412 /* Find the bpstat associated with this breakpoint. */
4415 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
4420 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4422 if (bsp
->breakpoint_at
== breakpoint
)
4428 /* See breakpoint.h. */
4431 bpstat_explains_signal (bpstat bsp
, enum gdb_signal sig
)
4433 for (; bsp
!= NULL
; bsp
= bsp
->next
)
4435 if (bsp
->breakpoint_at
== NULL
)
4437 /* A moribund location can never explain a signal other than
4439 if (sig
== GDB_SIGNAL_TRAP
)
4444 if (bsp
->breakpoint_at
->ops
->explains_signal (bsp
->breakpoint_at
,
4453 /* Put in *NUM the breakpoint number of the first breakpoint we are
4454 stopped at. *BSP upon return is a bpstat which points to the
4455 remaining breakpoints stopped at (but which is not guaranteed to be
4456 good for anything but further calls to bpstat_num).
4458 Return 0 if passed a bpstat which does not indicate any breakpoints.
4459 Return -1 if stopped at a breakpoint that has been deleted since
4461 Return 1 otherwise. */
4464 bpstat_num (bpstat
*bsp
, int *num
)
4466 struct breakpoint
*b
;
4469 return 0; /* No more breakpoint values */
4471 /* We assume we'll never have several bpstats that correspond to a
4472 single breakpoint -- otherwise, this function might return the
4473 same number more than once and this will look ugly. */
4474 b
= (*bsp
)->breakpoint_at
;
4475 *bsp
= (*bsp
)->next
;
4477 return -1; /* breakpoint that's been deleted since */
4479 *num
= b
->number
; /* We have its number */
4483 /* See breakpoint.h. */
4486 bpstat_clear_actions (void)
4488 struct thread_info
*tp
;
4491 if (ptid_equal (inferior_ptid
, null_ptid
))
4494 tp
= find_thread_ptid (inferior_ptid
);
4498 for (bs
= tp
->control
.stop_bpstat
; bs
!= NULL
; bs
= bs
->next
)
4500 bs
->commands
= NULL
;
4502 if (bs
->old_val
!= NULL
)
4504 value_free (bs
->old_val
);
4510 /* Called when a command is about to proceed the inferior. */
4513 breakpoint_about_to_proceed (void)
4515 if (!ptid_equal (inferior_ptid
, null_ptid
))
4517 struct thread_info
*tp
= inferior_thread ();
4519 /* Allow inferior function calls in breakpoint commands to not
4520 interrupt the command list. When the call finishes
4521 successfully, the inferior will be standing at the same
4522 breakpoint as if nothing happened. */
4523 if (tp
->control
.in_infcall
)
4527 breakpoint_proceeded
= 1;
4530 /* Stub for cleaning up our state if we error-out of a breakpoint
4533 cleanup_executing_breakpoints (void *ignore
)
4535 executing_breakpoint_commands
= 0;
4538 /* Return non-zero iff CMD as the first line of a command sequence is `silent'
4539 or its equivalent. */
4542 command_line_is_silent (struct command_line
*cmd
)
4544 return cmd
&& (strcmp ("silent", cmd
->line
) == 0);
4547 /* Execute all the commands associated with all the breakpoints at
4548 this location. Any of these commands could cause the process to
4549 proceed beyond this point, etc. We look out for such changes by
4550 checking the global "breakpoint_proceeded" after each command.
4552 Returns true if a breakpoint command resumed the inferior. In that
4553 case, it is the caller's responsibility to recall it again with the
4554 bpstat of the current thread. */
4557 bpstat_do_actions_1 (bpstat
*bsp
)
4560 struct cleanup
*old_chain
;
4563 /* Avoid endless recursion if a `source' command is contained
4565 if (executing_breakpoint_commands
)
4568 executing_breakpoint_commands
= 1;
4569 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
4571 scoped_restore preventer
= prevent_dont_repeat ();
4573 /* This pointer will iterate over the list of bpstat's. */
4576 breakpoint_proceeded
= 0;
4577 for (; bs
!= NULL
; bs
= bs
->next
)
4579 struct command_line
*cmd
= NULL
;
4581 /* Take ownership of the BSP's command tree, if it has one.
4583 The command tree could legitimately contain commands like
4584 'step' and 'next', which call clear_proceed_status, which
4585 frees stop_bpstat's command tree. To make sure this doesn't
4586 free the tree we're executing out from under us, we need to
4587 take ownership of the tree ourselves. Since a given bpstat's
4588 commands are only executed once, we don't need to copy it; we
4589 can clear the pointer in the bpstat, and make sure we free
4590 the tree when we're done. */
4591 counted_command_line ccmd
= bs
->commands
;
4592 bs
->commands
= NULL
;
4595 if (command_line_is_silent (cmd
))
4597 /* The action has been already done by bpstat_stop_status. */
4603 execute_control_command (cmd
);
4605 if (breakpoint_proceeded
)
4611 if (breakpoint_proceeded
)
4613 if (current_ui
->async
)
4614 /* If we are in async mode, then the target might be still
4615 running, not stopped at any breakpoint, so nothing for
4616 us to do here -- just return to the event loop. */
4619 /* In sync mode, when execute_control_command returns
4620 we're already standing on the next breakpoint.
4621 Breakpoint commands for that stop were not run, since
4622 execute_command does not run breakpoint commands --
4623 only command_line_handler does, but that one is not
4624 involved in execution of breakpoint commands. So, we
4625 can now execute breakpoint commands. It should be
4626 noted that making execute_command do bpstat actions is
4627 not an option -- in this case we'll have recursive
4628 invocation of bpstat for each breakpoint with a
4629 command, and can easily blow up GDB stack. Instead, we
4630 return true, which will trigger the caller to recall us
4631 with the new stop_bpstat. */
4636 do_cleanups (old_chain
);
4641 bpstat_do_actions (void)
4643 struct cleanup
*cleanup_if_error
= make_bpstat_clear_actions_cleanup ();
4645 /* Do any commands attached to breakpoint we are stopped at. */
4646 while (!ptid_equal (inferior_ptid
, null_ptid
)
4647 && target_has_execution
4648 && !is_exited (inferior_ptid
)
4649 && !is_executing (inferior_ptid
))
4650 /* Since in sync mode, bpstat_do_actions may resume the inferior,
4651 and only return when it is stopped at the next breakpoint, we
4652 keep doing breakpoint actions until it returns false to
4653 indicate the inferior was not resumed. */
4654 if (!bpstat_do_actions_1 (&inferior_thread ()->control
.stop_bpstat
))
4657 discard_cleanups (cleanup_if_error
);
4660 /* Print out the (old or new) value associated with a watchpoint. */
4663 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
4666 fprintf_unfiltered (stream
, _("<unreadable>"));
4669 struct value_print_options opts
;
4670 get_user_print_options (&opts
);
4671 value_print (val
, stream
, &opts
);
4675 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if
4676 debugging multiple threads. */
4679 maybe_print_thread_hit_breakpoint (struct ui_out
*uiout
)
4681 if (uiout
->is_mi_like_p ())
4686 if (show_thread_that_caused_stop ())
4689 struct thread_info
*thr
= inferior_thread ();
4691 uiout
->text ("Thread ");
4692 uiout
->field_fmt ("thread-id", "%s", print_thread_id (thr
));
4694 name
= thr
->name
!= NULL
? thr
->name
: target_thread_name (thr
);
4697 uiout
->text (" \"");
4698 uiout
->field_fmt ("name", "%s", name
);
4702 uiout
->text (" hit ");
4706 /* Generic routine for printing messages indicating why we
4707 stopped. The behavior of this function depends on the value
4708 'print_it' in the bpstat structure. Under some circumstances we
4709 may decide not to print anything here and delegate the task to
4712 static enum print_stop_action
4713 print_bp_stop_message (bpstat bs
)
4715 switch (bs
->print_it
)
4718 /* Nothing should be printed for this bpstat entry. */
4719 return PRINT_UNKNOWN
;
4723 /* We still want to print the frame, but we already printed the
4724 relevant messages. */
4725 return PRINT_SRC_AND_LOC
;
4728 case print_it_normal
:
4730 struct breakpoint
*b
= bs
->breakpoint_at
;
4732 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
4733 which has since been deleted. */
4735 return PRINT_UNKNOWN
;
4737 /* Normal case. Call the breakpoint's print_it method. */
4738 return b
->ops
->print_it (bs
);
4743 internal_error (__FILE__
, __LINE__
,
4744 _("print_bp_stop_message: unrecognized enum value"));
4749 /* A helper function that prints a shared library stopped event. */
4752 print_solib_event (int is_catchpoint
)
4755 = !VEC_empty (char_ptr
, current_program_space
->deleted_solibs
);
4757 = !VEC_empty (so_list_ptr
, current_program_space
->added_solibs
);
4761 if (any_added
|| any_deleted
)
4762 current_uiout
->text (_("Stopped due to shared library event:\n"));
4764 current_uiout
->text (_("Stopped due to shared library event (no "
4765 "libraries added or removed)\n"));
4768 if (current_uiout
->is_mi_like_p ())
4769 current_uiout
->field_string ("reason",
4770 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT
));
4777 current_uiout
->text (_(" Inferior unloaded "));
4778 ui_out_emit_list
list_emitter (current_uiout
, "removed");
4780 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
4785 current_uiout
->text (" ");
4786 current_uiout
->field_string ("library", name
);
4787 current_uiout
->text ("\n");
4793 struct so_list
*iter
;
4796 current_uiout
->text (_(" Inferior loaded "));
4797 ui_out_emit_list
list_emitter (current_uiout
, "added");
4799 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
4804 current_uiout
->text (" ");
4805 current_uiout
->field_string ("library", iter
->so_name
);
4806 current_uiout
->text ("\n");
4811 /* Print a message indicating what happened. This is called from
4812 normal_stop(). The input to this routine is the head of the bpstat
4813 list - a list of the eventpoints that caused this stop. KIND is
4814 the target_waitkind for the stopping event. This
4815 routine calls the generic print routine for printing a message
4816 about reasons for stopping. This will print (for example) the
4817 "Breakpoint n," part of the output. The return value of this
4820 PRINT_UNKNOWN: Means we printed nothing.
4821 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
4822 code to print the location. An example is
4823 "Breakpoint 1, " which should be followed by
4825 PRINT_SRC_ONLY: Means we printed something, but there is no need
4826 to also print the location part of the message.
4827 An example is the catch/throw messages, which
4828 don't require a location appended to the end.
4829 PRINT_NOTHING: We have done some printing and we don't need any
4830 further info to be printed. */
4832 enum print_stop_action
4833 bpstat_print (bpstat bs
, int kind
)
4835 enum print_stop_action val
;
4837 /* Maybe another breakpoint in the chain caused us to stop.
4838 (Currently all watchpoints go on the bpstat whether hit or not.
4839 That probably could (should) be changed, provided care is taken
4840 with respect to bpstat_explains_signal). */
4841 for (; bs
; bs
= bs
->next
)
4843 val
= print_bp_stop_message (bs
);
4844 if (val
== PRINT_SRC_ONLY
4845 || val
== PRINT_SRC_AND_LOC
4846 || val
== PRINT_NOTHING
)
4850 /* If we had hit a shared library event breakpoint,
4851 print_bp_stop_message would print out this message. If we hit an
4852 OS-level shared library event, do the same thing. */
4853 if (kind
== TARGET_WAITKIND_LOADED
)
4855 print_solib_event (0);
4856 return PRINT_NOTHING
;
4859 /* We reached the end of the chain, or we got a null BS to start
4860 with and nothing was printed. */
4861 return PRINT_UNKNOWN
;
4864 /* Evaluate the expression EXP and return 1 if value is zero.
4865 This returns the inverse of the condition because it is called
4866 from catch_errors which returns 0 if an exception happened, and if an
4867 exception happens we want execution to stop.
4868 The argument is a "struct expression *" that has been cast to a
4869 "void *" to make it pass through catch_errors. */
4872 breakpoint_cond_eval (void *exp
)
4874 struct value
*mark
= value_mark ();
4875 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
4877 value_free_to_mark (mark
);
4881 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
4883 bpstats::bpstats (struct bp_location
*bl
, bpstat
**bs_link_pointer
)
4885 bp_location_at (bl
),
4886 breakpoint_at (bl
->owner
),
4891 print_it (print_it_normal
)
4893 incref_bp_location (bl
);
4894 **bs_link_pointer
= this;
4895 *bs_link_pointer
= &next
;
4900 bp_location_at (NULL
),
4901 breakpoint_at (NULL
),
4906 print_it (print_it_normal
)
4910 /* The target has stopped with waitstatus WS. Check if any hardware
4911 watchpoints have triggered, according to the target. */
4914 watchpoints_triggered (struct target_waitstatus
*ws
)
4916 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
4918 struct breakpoint
*b
;
4920 if (!stopped_by_watchpoint
)
4922 /* We were not stopped by a watchpoint. Mark all watchpoints
4923 as not triggered. */
4925 if (is_hardware_watchpoint (b
))
4927 struct watchpoint
*w
= (struct watchpoint
*) b
;
4929 w
->watchpoint_triggered
= watch_triggered_no
;
4935 if (!target_stopped_data_address (¤t_target
, &addr
))
4937 /* We were stopped by a watchpoint, but we don't know where.
4938 Mark all watchpoints as unknown. */
4940 if (is_hardware_watchpoint (b
))
4942 struct watchpoint
*w
= (struct watchpoint
*) b
;
4944 w
->watchpoint_triggered
= watch_triggered_unknown
;
4950 /* The target could report the data address. Mark watchpoints
4951 affected by this data address as triggered, and all others as not
4955 if (is_hardware_watchpoint (b
))
4957 struct watchpoint
*w
= (struct watchpoint
*) b
;
4958 struct bp_location
*loc
;
4960 w
->watchpoint_triggered
= watch_triggered_no
;
4961 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4963 if (is_masked_watchpoint (b
))
4965 CORE_ADDR newaddr
= addr
& w
->hw_wp_mask
;
4966 CORE_ADDR start
= loc
->address
& w
->hw_wp_mask
;
4968 if (newaddr
== start
)
4970 w
->watchpoint_triggered
= watch_triggered_yes
;
4974 /* Exact match not required. Within range is sufficient. */
4975 else if (target_watchpoint_addr_within_range (¤t_target
,
4979 w
->watchpoint_triggered
= watch_triggered_yes
;
4988 /* Possible return values for watchpoint_check (this can't be an enum
4989 because of check_errors). */
4990 /* The watchpoint has been deleted. */
4991 #define WP_DELETED 1
4992 /* The value has changed. */
4993 #define WP_VALUE_CHANGED 2
4994 /* The value has not changed. */
4995 #define WP_VALUE_NOT_CHANGED 3
4996 /* Ignore this watchpoint, no matter if the value changed or not. */
4999 #define BP_TEMPFLAG 1
5000 #define BP_HARDWAREFLAG 2
5002 /* Evaluate watchpoint condition expression and check if its value
5005 P should be a pointer to struct bpstat, but is defined as a void *
5006 in order for this function to be usable with catch_errors. */
5009 watchpoint_check (void *p
)
5011 bpstat bs
= (bpstat
) p
;
5012 struct watchpoint
*b
;
5013 struct frame_info
*fr
;
5014 int within_current_scope
;
5016 /* BS is built from an existing struct breakpoint. */
5017 gdb_assert (bs
->breakpoint_at
!= NULL
);
5018 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5020 /* If this is a local watchpoint, we only want to check if the
5021 watchpoint frame is in scope if the current thread is the thread
5022 that was used to create the watchpoint. */
5023 if (!watchpoint_in_thread_scope (b
))
5026 if (b
->exp_valid_block
== NULL
)
5027 within_current_scope
= 1;
5030 struct frame_info
*frame
= get_current_frame ();
5031 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
5032 CORE_ADDR frame_pc
= get_frame_pc (frame
);
5034 /* stack_frame_destroyed_p() returns a non-zero value if we're
5035 still in the function but the stack frame has already been
5036 invalidated. Since we can't rely on the values of local
5037 variables after the stack has been destroyed, we are treating
5038 the watchpoint in that state as `not changed' without further
5039 checking. Don't mark watchpoints as changed if the current
5040 frame is in an epilogue - even if they are in some other
5041 frame, our view of the stack is likely to be wrong and
5042 frame_find_by_id could error out. */
5043 if (gdbarch_stack_frame_destroyed_p (frame_arch
, frame_pc
))
5046 fr
= frame_find_by_id (b
->watchpoint_frame
);
5047 within_current_scope
= (fr
!= NULL
);
5049 /* If we've gotten confused in the unwinder, we might have
5050 returned a frame that can't describe this variable. */
5051 if (within_current_scope
)
5053 struct symbol
*function
;
5055 function
= get_frame_function (fr
);
5056 if (function
== NULL
5057 || !contained_in (b
->exp_valid_block
,
5058 SYMBOL_BLOCK_VALUE (function
)))
5059 within_current_scope
= 0;
5062 if (within_current_scope
)
5063 /* If we end up stopping, the current frame will get selected
5064 in normal_stop. So this call to select_frame won't affect
5069 if (within_current_scope
)
5071 /* We use value_{,free_to_}mark because it could be a *long*
5072 time before we return to the command level and call
5073 free_all_values. We can't call free_all_values because we
5074 might be in the middle of evaluating a function call. */
5078 struct value
*new_val
;
5080 if (is_masked_watchpoint (b
))
5081 /* Since we don't know the exact trigger address (from
5082 stopped_data_address), just tell the user we've triggered
5083 a mask watchpoint. */
5084 return WP_VALUE_CHANGED
;
5086 mark
= value_mark ();
5087 fetch_subexp_value (b
->exp
.get (), &pc
, &new_val
, NULL
, NULL
, 0);
5089 if (b
->val_bitsize
!= 0)
5090 new_val
= extract_bitfield_from_watchpoint_value (b
, new_val
);
5092 /* We use value_equal_contents instead of value_equal because
5093 the latter coerces an array to a pointer, thus comparing just
5094 the address of the array instead of its contents. This is
5095 not what we want. */
5096 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
5097 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
5099 if (new_val
!= NULL
)
5101 release_value (new_val
);
5102 value_free_to_mark (mark
);
5104 bs
->old_val
= b
->val
;
5107 return WP_VALUE_CHANGED
;
5111 /* Nothing changed. */
5112 value_free_to_mark (mark
);
5113 return WP_VALUE_NOT_CHANGED
;
5118 /* This seems like the only logical thing to do because
5119 if we temporarily ignored the watchpoint, then when
5120 we reenter the block in which it is valid it contains
5121 garbage (in the case of a function, it may have two
5122 garbage values, one before and one after the prologue).
5123 So we can't even detect the first assignment to it and
5124 watch after that (since the garbage may or may not equal
5125 the first value assigned). */
5126 /* We print all the stop information in
5127 breakpoint_ops->print_it, but in this case, by the time we
5128 call breakpoint_ops->print_it this bp will be deleted
5129 already. So we have no choice but print the information
5132 SWITCH_THRU_ALL_UIS ()
5134 struct ui_out
*uiout
= current_uiout
;
5136 if (uiout
->is_mi_like_p ())
5138 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
5139 uiout
->text ("\nWatchpoint ");
5140 uiout
->field_int ("wpnum", b
->number
);
5141 uiout
->text (" deleted because the program has left the block in\n"
5142 "which its expression is valid.\n");
5145 /* Make sure the watchpoint's commands aren't executed. */
5147 watchpoint_del_at_next_stop (b
);
5153 /* Return true if it looks like target has stopped due to hitting
5154 breakpoint location BL. This function does not check if we should
5155 stop, only if BL explains the stop. */
5158 bpstat_check_location (const struct bp_location
*bl
,
5159 struct address_space
*aspace
, CORE_ADDR bp_addr
,
5160 const struct target_waitstatus
*ws
)
5162 struct breakpoint
*b
= bl
->owner
;
5164 /* BL is from an existing breakpoint. */
5165 gdb_assert (b
!= NULL
);
5167 return b
->ops
->breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
5170 /* Determine if the watched values have actually changed, and we
5171 should stop. If not, set BS->stop to 0. */
5174 bpstat_check_watchpoint (bpstat bs
)
5176 const struct bp_location
*bl
;
5177 struct watchpoint
*b
;
5179 /* BS is built for existing struct breakpoint. */
5180 bl
= bs
->bp_location_at
;
5181 gdb_assert (bl
!= NULL
);
5182 b
= (struct watchpoint
*) bs
->breakpoint_at
;
5183 gdb_assert (b
!= NULL
);
5186 int must_check_value
= 0;
5188 if (b
->type
== bp_watchpoint
)
5189 /* For a software watchpoint, we must always check the
5191 must_check_value
= 1;
5192 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
5193 /* We have a hardware watchpoint (read, write, or access)
5194 and the target earlier reported an address watched by
5196 must_check_value
= 1;
5197 else if (b
->watchpoint_triggered
== watch_triggered_unknown
5198 && b
->type
== bp_hardware_watchpoint
)
5199 /* We were stopped by a hardware watchpoint, but the target could
5200 not report the data address. We must check the watchpoint's
5201 value. Access and read watchpoints are out of luck; without
5202 a data address, we can't figure it out. */
5203 must_check_value
= 1;
5205 if (must_check_value
)
5208 = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5210 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
5211 int e
= catch_errors (watchpoint_check
, bs
, message
,
5213 do_cleanups (cleanups
);
5217 /* We've already printed what needs to be printed. */
5218 bs
->print_it
= print_it_done
;
5222 bs
->print_it
= print_it_noop
;
5225 case WP_VALUE_CHANGED
:
5226 if (b
->type
== bp_read_watchpoint
)
5228 /* There are two cases to consider here:
5230 1. We're watching the triggered memory for reads.
5231 In that case, trust the target, and always report
5232 the watchpoint hit to the user. Even though
5233 reads don't cause value changes, the value may
5234 have changed since the last time it was read, and
5235 since we're not trapping writes, we will not see
5236 those, and as such we should ignore our notion of
5239 2. We're watching the triggered memory for both
5240 reads and writes. There are two ways this may
5243 2.1. This is a target that can't break on data
5244 reads only, but can break on accesses (reads or
5245 writes), such as e.g., x86. We detect this case
5246 at the time we try to insert read watchpoints.
5248 2.2. Otherwise, the target supports read
5249 watchpoints, but, the user set an access or write
5250 watchpoint watching the same memory as this read
5253 If we're watching memory writes as well as reads,
5254 ignore watchpoint hits when we find that the
5255 value hasn't changed, as reads don't cause
5256 changes. This still gives false positives when
5257 the program writes the same value to memory as
5258 what there was already in memory (we will confuse
5259 it for a read), but it's much better than
5262 int other_write_watchpoint
= 0;
5264 if (bl
->watchpoint_type
== hw_read
)
5266 struct breakpoint
*other_b
;
5268 ALL_BREAKPOINTS (other_b
)
5269 if (other_b
->type
== bp_hardware_watchpoint
5270 || other_b
->type
== bp_access_watchpoint
)
5272 struct watchpoint
*other_w
=
5273 (struct watchpoint
*) other_b
;
5275 if (other_w
->watchpoint_triggered
5276 == watch_triggered_yes
)
5278 other_write_watchpoint
= 1;
5284 if (other_write_watchpoint
5285 || bl
->watchpoint_type
== hw_access
)
5287 /* We're watching the same memory for writes,
5288 and the value changed since the last time we
5289 updated it, so this trap must be for a write.
5291 bs
->print_it
= print_it_noop
;
5296 case WP_VALUE_NOT_CHANGED
:
5297 if (b
->type
== bp_hardware_watchpoint
5298 || b
->type
== bp_watchpoint
)
5300 /* Don't stop: write watchpoints shouldn't fire if
5301 the value hasn't changed. */
5302 bs
->print_it
= print_it_noop
;
5310 /* Error from catch_errors. */
5312 SWITCH_THRU_ALL_UIS ()
5314 printf_filtered (_("Watchpoint %d deleted.\n"),
5317 watchpoint_del_at_next_stop (b
);
5318 /* We've already printed what needs to be printed. */
5319 bs
->print_it
= print_it_done
;
5324 else /* must_check_value == 0 */
5326 /* This is a case where some watchpoint(s) triggered, but
5327 not at the address of this watchpoint, or else no
5328 watchpoint triggered after all. So don't print
5329 anything for this watchpoint. */
5330 bs
->print_it
= print_it_noop
;
5336 /* For breakpoints that are currently marked as telling gdb to stop,
5337 check conditions (condition proper, frame, thread and ignore count)
5338 of breakpoint referred to by BS. If we should not stop for this
5339 breakpoint, set BS->stop to 0. */
5342 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
5344 const struct bp_location
*bl
;
5345 struct breakpoint
*b
;
5346 int value_is_zero
= 0;
5347 struct expression
*cond
;
5349 gdb_assert (bs
->stop
);
5351 /* BS is built for existing struct breakpoint. */
5352 bl
= bs
->bp_location_at
;
5353 gdb_assert (bl
!= NULL
);
5354 b
= bs
->breakpoint_at
;
5355 gdb_assert (b
!= NULL
);
5357 /* Even if the target evaluated the condition on its end and notified GDB, we
5358 need to do so again since GDB does not know if we stopped due to a
5359 breakpoint or a single step breakpoint. */
5361 if (frame_id_p (b
->frame_id
)
5362 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
5368 /* If this is a thread/task-specific breakpoint, don't waste cpu
5369 evaluating the condition if this isn't the specified
5371 if ((b
->thread
!= -1 && b
->thread
!= ptid_to_global_thread_id (ptid
))
5372 || (b
->task
!= 0 && b
->task
!= ada_get_task_number (ptid
)))
5379 /* Evaluate extension language breakpoints that have a "stop" method
5381 bs
->stop
= breakpoint_ext_lang_cond_says_stop (b
);
5383 if (is_watchpoint (b
))
5385 struct watchpoint
*w
= (struct watchpoint
*) b
;
5387 cond
= w
->cond_exp
.get ();
5390 cond
= bl
->cond
.get ();
5392 if (cond
&& b
->disposition
!= disp_del_at_next_stop
)
5394 int within_current_scope
= 1;
5395 struct watchpoint
* w
;
5397 /* We use value_mark and value_free_to_mark because it could
5398 be a long time before we return to the command level and
5399 call free_all_values. We can't call free_all_values
5400 because we might be in the middle of evaluating a
5402 struct value
*mark
= value_mark ();
5404 if (is_watchpoint (b
))
5405 w
= (struct watchpoint
*) b
;
5409 /* Need to select the frame, with all that implies so that
5410 the conditions will have the right context. Because we
5411 use the frame, we will not see an inlined function's
5412 variables when we arrive at a breakpoint at the start
5413 of the inlined function; the current frame will be the
5415 if (w
== NULL
|| w
->cond_exp_valid_block
== NULL
)
5416 select_frame (get_current_frame ());
5419 struct frame_info
*frame
;
5421 /* For local watchpoint expressions, which particular
5422 instance of a local is being watched matters, so we
5423 keep track of the frame to evaluate the expression
5424 in. To evaluate the condition however, it doesn't
5425 really matter which instantiation of the function
5426 where the condition makes sense triggers the
5427 watchpoint. This allows an expression like "watch
5428 global if q > 10" set in `func', catch writes to
5429 global on all threads that call `func', or catch
5430 writes on all recursive calls of `func' by a single
5431 thread. We simply always evaluate the condition in
5432 the innermost frame that's executing where it makes
5433 sense to evaluate the condition. It seems
5435 frame
= block_innermost_frame (w
->cond_exp_valid_block
);
5437 select_frame (frame
);
5439 within_current_scope
= 0;
5441 if (within_current_scope
)
5443 = catch_errors (breakpoint_cond_eval
, cond
,
5444 "Error in testing breakpoint condition:\n",
5448 warning (_("Watchpoint condition cannot be tested "
5449 "in the current scope"));
5450 /* If we failed to set the right context for this
5451 watchpoint, unconditionally report it. */
5454 /* FIXME-someday, should give breakpoint #. */
5455 value_free_to_mark (mark
);
5458 if (cond
&& value_is_zero
)
5462 else if (b
->ignore_count
> 0)
5466 /* Increase the hit count even though we don't stop. */
5468 observer_notify_breakpoint_modified (b
);
5472 /* Returns true if we need to track moribund locations of LOC's type
5473 on the current target. */
5476 need_moribund_for_location_type (struct bp_location
*loc
)
5478 return ((loc
->loc_type
== bp_loc_software_breakpoint
5479 && !target_supports_stopped_by_sw_breakpoint ())
5480 || (loc
->loc_type
== bp_loc_hardware_breakpoint
5481 && !target_supports_stopped_by_hw_breakpoint ()));
5485 /* Get a bpstat associated with having just stopped at address
5486 BP_ADDR in thread PTID.
5488 Determine whether we stopped at a breakpoint, etc, or whether we
5489 don't understand this stop. Result is a chain of bpstat's such
5492 if we don't understand the stop, the result is a null pointer.
5494 if we understand why we stopped, the result is not null.
5496 Each element of the chain refers to a particular breakpoint or
5497 watchpoint at which we have stopped. (We may have stopped for
5498 several reasons concurrently.)
5500 Each element of the chain has valid next, breakpoint_at,
5501 commands, FIXME??? fields. */
5504 bpstat_stop_status (struct address_space
*aspace
,
5505 CORE_ADDR bp_addr
, ptid_t ptid
,
5506 const struct target_waitstatus
*ws
)
5508 struct breakpoint
*b
= NULL
;
5509 struct bp_location
*bl
;
5510 struct bp_location
*loc
;
5511 /* First item of allocated bpstat's. */
5512 bpstat bs_head
= NULL
, *bs_link
= &bs_head
;
5513 /* Pointer to the last thing in the chain currently. */
5516 int need_remove_insert
;
5519 /* First, build the bpstat chain with locations that explain a
5520 target stop, while being careful to not set the target running,
5521 as that may invalidate locations (in particular watchpoint
5522 locations are recreated). Resuming will happen here with
5523 breakpoint conditions or watchpoint expressions that include
5524 inferior function calls. */
5528 if (!breakpoint_enabled (b
))
5531 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
5533 /* For hardware watchpoints, we look only at the first
5534 location. The watchpoint_check function will work on the
5535 entire expression, not the individual locations. For
5536 read watchpoints, the watchpoints_triggered function has
5537 checked all locations already. */
5538 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
5541 if (!bl
->enabled
|| bl
->shlib_disabled
)
5544 if (!bpstat_check_location (bl
, aspace
, bp_addr
, ws
))
5547 /* Come here if it's a watchpoint, or if the break address
5550 bs
= new bpstats (bl
, &bs_link
); /* Alloc a bpstat to
5553 /* Assume we stop. Should we find a watchpoint that is not
5554 actually triggered, or if the condition of the breakpoint
5555 evaluates as false, we'll reset 'stop' to 0. */
5559 /* If this is a scope breakpoint, mark the associated
5560 watchpoint as triggered so that we will handle the
5561 out-of-scope event. We'll get to the watchpoint next
5563 if (b
->type
== bp_watchpoint_scope
&& b
->related_breakpoint
!= b
)
5565 struct watchpoint
*w
= (struct watchpoint
*) b
->related_breakpoint
;
5567 w
->watchpoint_triggered
= watch_triggered_yes
;
5572 /* Check if a moribund breakpoint explains the stop. */
5573 if (!target_supports_stopped_by_sw_breakpoint ()
5574 || !target_supports_stopped_by_hw_breakpoint ())
5576 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
5578 if (breakpoint_location_address_match (loc
, aspace
, bp_addr
)
5579 && need_moribund_for_location_type (loc
))
5581 bs
= new bpstats (loc
, &bs_link
);
5582 /* For hits of moribund locations, we should just proceed. */
5585 bs
->print_it
= print_it_noop
;
5590 /* A bit of special processing for shlib breakpoints. We need to
5591 process solib loading here, so that the lists of loaded and
5592 unloaded libraries are correct before we handle "catch load" and
5594 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5596 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->type
== bp_shlib_event
)
5598 handle_solib_event ();
5603 /* Now go through the locations that caused the target to stop, and
5604 check whether we're interested in reporting this stop to higher
5605 layers, or whether we should resume the target transparently. */
5609 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5614 b
= bs
->breakpoint_at
;
5615 b
->ops
->check_status (bs
);
5618 bpstat_check_breakpoint_conditions (bs
, ptid
);
5623 observer_notify_breakpoint_modified (b
);
5625 /* We will stop here. */
5626 if (b
->disposition
== disp_disable
)
5628 --(b
->enable_count
);
5629 if (b
->enable_count
<= 0)
5630 b
->enable_state
= bp_disabled
;
5635 bs
->commands
= b
->commands
;
5636 if (command_line_is_silent (bs
->commands
5637 ? bs
->commands
.get () : NULL
))
5640 b
->ops
->after_condition_true (bs
);
5645 /* Print nothing for this entry if we don't stop or don't
5647 if (!bs
->stop
|| !bs
->print
)
5648 bs
->print_it
= print_it_noop
;
5651 /* If we aren't stopping, the value of some hardware watchpoint may
5652 not have changed, but the intermediate memory locations we are
5653 watching may have. Don't bother if we're stopping; this will get
5655 need_remove_insert
= 0;
5656 if (! bpstat_causes_stop (bs_head
))
5657 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5659 && bs
->breakpoint_at
5660 && is_hardware_watchpoint (bs
->breakpoint_at
))
5662 struct watchpoint
*w
= (struct watchpoint
*) bs
->breakpoint_at
;
5664 update_watchpoint (w
, 0 /* don't reparse. */);
5665 need_remove_insert
= 1;
5668 if (need_remove_insert
)
5669 update_global_location_list (UGLL_MAY_INSERT
);
5670 else if (removed_any
)
5671 update_global_location_list (UGLL_DONT_INSERT
);
5677 handle_jit_event (void)
5679 struct frame_info
*frame
;
5680 struct gdbarch
*gdbarch
;
5683 fprintf_unfiltered (gdb_stdlog
, "handling bp_jit_event\n");
5685 /* Switch terminal for any messages produced by
5686 breakpoint_re_set. */
5687 target_terminal::ours_for_output ();
5689 frame
= get_current_frame ();
5690 gdbarch
= get_frame_arch (frame
);
5692 jit_event_handler (gdbarch
);
5694 target_terminal::inferior ();
5697 /* Prepare WHAT final decision for infrun. */
5699 /* Decide what infrun needs to do with this bpstat. */
5702 bpstat_what (bpstat bs_head
)
5704 struct bpstat_what retval
;
5707 retval
.main_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5708 retval
.call_dummy
= STOP_NONE
;
5709 retval
.is_longjmp
= 0;
5711 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5713 /* Extract this BS's action. After processing each BS, we check
5714 if its action overrides all we've seem so far. */
5715 enum bpstat_what_main_action this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5718 if (bs
->breakpoint_at
== NULL
)
5720 /* I suspect this can happen if it was a momentary
5721 breakpoint which has since been deleted. */
5725 bptype
= bs
->breakpoint_at
->type
;
5732 case bp_hardware_breakpoint
:
5733 case bp_single_step
:
5736 case bp_shlib_event
:
5740 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5742 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5745 this_action
= BPSTAT_WHAT_SINGLE
;
5748 case bp_hardware_watchpoint
:
5749 case bp_read_watchpoint
:
5750 case bp_access_watchpoint
:
5754 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5756 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5760 /* There was a watchpoint, but we're not stopping.
5761 This requires no further action. */
5765 case bp_longjmp_call_dummy
:
5769 this_action
= BPSTAT_WHAT_SET_LONGJMP_RESUME
;
5770 retval
.is_longjmp
= bptype
!= bp_exception
;
5773 this_action
= BPSTAT_WHAT_SINGLE
;
5775 case bp_longjmp_resume
:
5776 case bp_exception_resume
:
5779 this_action
= BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
;
5780 retval
.is_longjmp
= bptype
== bp_longjmp_resume
;
5783 this_action
= BPSTAT_WHAT_SINGLE
;
5785 case bp_step_resume
:
5787 this_action
= BPSTAT_WHAT_STEP_RESUME
;
5790 /* It is for the wrong frame. */
5791 this_action
= BPSTAT_WHAT_SINGLE
;
5794 case bp_hp_step_resume
:
5796 this_action
= BPSTAT_WHAT_HP_STEP_RESUME
;
5799 /* It is for the wrong frame. */
5800 this_action
= BPSTAT_WHAT_SINGLE
;
5803 case bp_watchpoint_scope
:
5804 case bp_thread_event
:
5805 case bp_overlay_event
:
5806 case bp_longjmp_master
:
5807 case bp_std_terminate_master
:
5808 case bp_exception_master
:
5809 this_action
= BPSTAT_WHAT_SINGLE
;
5815 this_action
= BPSTAT_WHAT_STOP_NOISY
;
5817 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5821 /* There was a catchpoint, but we're not stopping.
5822 This requires no further action. */
5826 this_action
= BPSTAT_WHAT_SINGLE
;
5829 /* Make sure the action is stop (silent or noisy),
5830 so infrun.c pops the dummy frame. */
5831 retval
.call_dummy
= STOP_STACK_DUMMY
;
5832 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5834 case bp_std_terminate
:
5835 /* Make sure the action is stop (silent or noisy),
5836 so infrun.c pops the dummy frame. */
5837 retval
.call_dummy
= STOP_STD_TERMINATE
;
5838 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5841 case bp_fast_tracepoint
:
5842 case bp_static_tracepoint
:
5843 /* Tracepoint hits should not be reported back to GDB, and
5844 if one got through somehow, it should have been filtered
5846 internal_error (__FILE__
, __LINE__
,
5847 _("bpstat_what: tracepoint encountered"));
5849 case bp_gnu_ifunc_resolver
:
5850 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */
5851 this_action
= BPSTAT_WHAT_SINGLE
;
5853 case bp_gnu_ifunc_resolver_return
:
5854 /* The breakpoint will be removed, execution will restart from the
5855 PC of the former breakpoint. */
5856 this_action
= BPSTAT_WHAT_KEEP_CHECKING
;
5861 this_action
= BPSTAT_WHAT_STOP_SILENT
;
5863 this_action
= BPSTAT_WHAT_SINGLE
;
5867 internal_error (__FILE__
, __LINE__
,
5868 _("bpstat_what: unhandled bptype %d"), (int) bptype
);
5871 retval
.main_action
= std::max (retval
.main_action
, this_action
);
5878 bpstat_run_callbacks (bpstat bs_head
)
5882 for (bs
= bs_head
; bs
!= NULL
; bs
= bs
->next
)
5884 struct breakpoint
*b
= bs
->breakpoint_at
;
5891 handle_jit_event ();
5893 case bp_gnu_ifunc_resolver
:
5894 gnu_ifunc_resolver_stop (b
);
5896 case bp_gnu_ifunc_resolver_return
:
5897 gnu_ifunc_resolver_return_stop (b
);
5903 /* Nonzero if we should step constantly (e.g. watchpoints on machines
5904 without hardware support). This isn't related to a specific bpstat,
5905 just to things like whether watchpoints are set. */
5908 bpstat_should_step (void)
5910 struct breakpoint
*b
;
5913 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
5919 bpstat_causes_stop (bpstat bs
)
5921 for (; bs
!= NULL
; bs
= bs
->next
)
5930 /* Compute a string of spaces suitable to indent the next line
5931 so it starts at the position corresponding to the table column
5932 named COL_NAME in the currently active table of UIOUT. */
5935 wrap_indent_at_field (struct ui_out
*uiout
, const char *col_name
)
5937 static char wrap_indent
[80];
5938 int i
, total_width
, width
, align
;
5942 for (i
= 1; uiout
->query_table_field (i
, &width
, &align
, &text
); i
++)
5944 if (strcmp (text
, col_name
) == 0)
5946 gdb_assert (total_width
< sizeof wrap_indent
);
5947 memset (wrap_indent
, ' ', total_width
);
5948 wrap_indent
[total_width
] = 0;
5953 total_width
+= width
+ 1;
5959 /* Determine if the locations of this breakpoint will have their conditions
5960 evaluated by the target, host or a mix of both. Returns the following:
5962 "host": Host evals condition.
5963 "host or target": Host or Target evals condition.
5964 "target": Target evals condition.
5968 bp_condition_evaluator (struct breakpoint
*b
)
5970 struct bp_location
*bl
;
5971 char host_evals
= 0;
5972 char target_evals
= 0;
5977 if (!is_breakpoint (b
))
5980 if (gdb_evaluates_breakpoint_condition_p ()
5981 || !target_supports_evaluation_of_breakpoint_conditions ())
5982 return condition_evaluation_host
;
5984 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5986 if (bl
->cond_bytecode
)
5992 if (host_evals
&& target_evals
)
5993 return condition_evaluation_both
;
5994 else if (target_evals
)
5995 return condition_evaluation_target
;
5997 return condition_evaluation_host
;
6000 /* Determine the breakpoint location's condition evaluator. This is
6001 similar to bp_condition_evaluator, but for locations. */
6004 bp_location_condition_evaluator (struct bp_location
*bl
)
6006 if (bl
&& !is_breakpoint (bl
->owner
))
6009 if (gdb_evaluates_breakpoint_condition_p ()
6010 || !target_supports_evaluation_of_breakpoint_conditions ())
6011 return condition_evaluation_host
;
6013 if (bl
&& bl
->cond_bytecode
)
6014 return condition_evaluation_target
;
6016 return condition_evaluation_host
;
6019 /* Print the LOC location out of the list of B->LOC locations. */
6022 print_breakpoint_location (struct breakpoint
*b
,
6023 struct bp_location
*loc
)
6025 struct ui_out
*uiout
= current_uiout
;
6027 scoped_restore_current_program_space restore_pspace
;
6029 if (loc
!= NULL
&& loc
->shlib_disabled
)
6033 set_current_program_space (loc
->pspace
);
6035 if (b
->display_canonical
)
6036 uiout
->field_string ("what", event_location_to_string (b
->location
.get ()));
6037 else if (loc
&& loc
->symtab
)
6040 = find_pc_sect_function (loc
->address
, loc
->section
);
6043 uiout
->text ("in ");
6044 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
6046 uiout
->wrap_hint (wrap_indent_at_field (uiout
, "what"));
6047 uiout
->text ("at ");
6049 uiout
->field_string ("file",
6050 symtab_to_filename_for_display (loc
->symtab
));
6053 if (uiout
->is_mi_like_p ())
6054 uiout
->field_string ("fullname", symtab_to_fullname (loc
->symtab
));
6056 uiout
->field_int ("line", loc
->line_number
);
6062 print_address_symbolic (loc
->gdbarch
, loc
->address
, &stb
,
6064 uiout
->field_stream ("at", stb
);
6068 uiout
->field_string ("pending",
6069 event_location_to_string (b
->location
.get ()));
6070 /* If extra_string is available, it could be holding a condition
6071 or dprintf arguments. In either case, make sure it is printed,
6072 too, but only for non-MI streams. */
6073 if (!uiout
->is_mi_like_p () && b
->extra_string
!= NULL
)
6075 if (b
->type
== bp_dprintf
)
6079 uiout
->text (b
->extra_string
);
6083 if (loc
&& is_breakpoint (b
)
6084 && breakpoint_condition_evaluation_mode () == condition_evaluation_target
6085 && bp_condition_evaluator (b
) == condition_evaluation_both
)
6088 uiout
->field_string ("evaluated-by",
6089 bp_location_condition_evaluator (loc
));
6095 bptype_string (enum bptype type
)
6097 struct ep_type_description
6100 const char *description
;
6102 static struct ep_type_description bptypes
[] =
6104 {bp_none
, "?deleted?"},
6105 {bp_breakpoint
, "breakpoint"},
6106 {bp_hardware_breakpoint
, "hw breakpoint"},
6107 {bp_single_step
, "sw single-step"},
6108 {bp_until
, "until"},
6109 {bp_finish
, "finish"},
6110 {bp_watchpoint
, "watchpoint"},
6111 {bp_hardware_watchpoint
, "hw watchpoint"},
6112 {bp_read_watchpoint
, "read watchpoint"},
6113 {bp_access_watchpoint
, "acc watchpoint"},
6114 {bp_longjmp
, "longjmp"},
6115 {bp_longjmp_resume
, "longjmp resume"},
6116 {bp_longjmp_call_dummy
, "longjmp for call dummy"},
6117 {bp_exception
, "exception"},
6118 {bp_exception_resume
, "exception resume"},
6119 {bp_step_resume
, "step resume"},
6120 {bp_hp_step_resume
, "high-priority step resume"},
6121 {bp_watchpoint_scope
, "watchpoint scope"},
6122 {bp_call_dummy
, "call dummy"},
6123 {bp_std_terminate
, "std::terminate"},
6124 {bp_shlib_event
, "shlib events"},
6125 {bp_thread_event
, "thread events"},
6126 {bp_overlay_event
, "overlay events"},
6127 {bp_longjmp_master
, "longjmp master"},
6128 {bp_std_terminate_master
, "std::terminate master"},
6129 {bp_exception_master
, "exception master"},
6130 {bp_catchpoint
, "catchpoint"},
6131 {bp_tracepoint
, "tracepoint"},
6132 {bp_fast_tracepoint
, "fast tracepoint"},
6133 {bp_static_tracepoint
, "static tracepoint"},
6134 {bp_dprintf
, "dprintf"},
6135 {bp_jit_event
, "jit events"},
6136 {bp_gnu_ifunc_resolver
, "STT_GNU_IFUNC resolver"},
6137 {bp_gnu_ifunc_resolver_return
, "STT_GNU_IFUNC resolver return"},
6140 if (((int) type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
6141 || ((int) type
!= bptypes
[(int) type
].type
))
6142 internal_error (__FILE__
, __LINE__
,
6143 _("bptypes table does not describe type #%d."),
6146 return bptypes
[(int) type
].description
;
6149 /* For MI, output a field named 'thread-groups' with a list as the value.
6150 For CLI, prefix the list with the string 'inf'. */
6153 output_thread_groups (struct ui_out
*uiout
,
6154 const char *field_name
,
6158 int is_mi
= uiout
->is_mi_like_p ();
6162 /* For backward compatibility, don't display inferiors in CLI unless
6163 there are several. Always display them for MI. */
6164 if (!is_mi
&& mi_only
)
6167 ui_out_emit_list
list_emitter (uiout
, field_name
);
6169 for (i
= 0; VEC_iterate (int, inf_num
, i
, inf
); ++i
)
6175 xsnprintf (mi_group
, sizeof (mi_group
), "i%d", inf
);
6176 uiout
->field_string (NULL
, mi_group
);
6181 uiout
->text (" inf ");
6185 uiout
->text (plongest (inf
));
6190 /* Print B to gdb_stdout. */
6193 print_one_breakpoint_location (struct breakpoint
*b
,
6194 struct bp_location
*loc
,
6196 struct bp_location
**last_loc
,
6199 struct command_line
*l
;
6200 static char bpenables
[] = "nynny";
6202 struct ui_out
*uiout
= current_uiout
;
6203 int header_of_multiple
= 0;
6204 int part_of_multiple
= (loc
!= NULL
);
6205 struct value_print_options opts
;
6207 get_user_print_options (&opts
);
6209 gdb_assert (!loc
|| loc_number
!= 0);
6210 /* See comment in print_one_breakpoint concerning treatment of
6211 breakpoints with single disabled location. */
6214 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
6215 header_of_multiple
= 1;
6223 if (part_of_multiple
)
6226 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
6227 uiout
->field_string ("number", formatted
);
6232 uiout
->field_int ("number", b
->number
);
6237 if (part_of_multiple
)
6238 uiout
->field_skip ("type");
6240 uiout
->field_string ("type", bptype_string (b
->type
));
6244 if (part_of_multiple
)
6245 uiout
->field_skip ("disp");
6247 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
6252 if (part_of_multiple
)
6253 uiout
->field_string ("enabled", loc
->enabled
? "y" : "n");
6255 uiout
->field_fmt ("enabled", "%c", bpenables
[(int) b
->enable_state
]);
6260 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
6262 /* Although the print_one can possibly print all locations,
6263 calling it here is not likely to get any nice result. So,
6264 make sure there's just one location. */
6265 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
6266 b
->ops
->print_one (b
, last_loc
);
6272 internal_error (__FILE__
, __LINE__
,
6273 _("print_one_breakpoint: bp_none encountered\n"));
6277 case bp_hardware_watchpoint
:
6278 case bp_read_watchpoint
:
6279 case bp_access_watchpoint
:
6281 struct watchpoint
*w
= (struct watchpoint
*) b
;
6283 /* Field 4, the address, is omitted (which makes the columns
6284 not line up too nicely with the headers, but the effect
6285 is relatively readable). */
6286 if (opts
.addressprint
)
6287 uiout
->field_skip ("addr");
6289 uiout
->field_string ("what", w
->exp_string
);
6294 case bp_hardware_breakpoint
:
6295 case bp_single_step
:
6299 case bp_longjmp_resume
:
6300 case bp_longjmp_call_dummy
:
6302 case bp_exception_resume
:
6303 case bp_step_resume
:
6304 case bp_hp_step_resume
:
6305 case bp_watchpoint_scope
:
6307 case bp_std_terminate
:
6308 case bp_shlib_event
:
6309 case bp_thread_event
:
6310 case bp_overlay_event
:
6311 case bp_longjmp_master
:
6312 case bp_std_terminate_master
:
6313 case bp_exception_master
:
6315 case bp_fast_tracepoint
:
6316 case bp_static_tracepoint
:
6319 case bp_gnu_ifunc_resolver
:
6320 case bp_gnu_ifunc_resolver_return
:
6321 if (opts
.addressprint
)
6324 if (header_of_multiple
)
6325 uiout
->field_string ("addr", "<MULTIPLE>");
6326 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
6327 uiout
->field_string ("addr", "<PENDING>");
6329 uiout
->field_core_addr ("addr",
6330 loc
->gdbarch
, loc
->address
);
6333 if (!header_of_multiple
)
6334 print_breakpoint_location (b
, loc
);
6341 if (loc
!= NULL
&& !header_of_multiple
)
6343 struct inferior
*inf
;
6344 VEC(int) *inf_num
= NULL
;
6349 if (inf
->pspace
== loc
->pspace
)
6350 VEC_safe_push (int, inf_num
, inf
->num
);
6353 /* For backward compatibility, don't display inferiors in CLI unless
6354 there are several. Always display for MI. */
6356 || (!gdbarch_has_global_breakpoints (target_gdbarch ())
6357 && (number_of_program_spaces () > 1
6358 || number_of_inferiors () > 1)
6359 /* LOC is for existing B, it cannot be in
6360 moribund_locations and thus having NULL OWNER. */
6361 && loc
->owner
->type
!= bp_catchpoint
))
6363 output_thread_groups (uiout
, "thread-groups", inf_num
, mi_only
);
6364 VEC_free (int, inf_num
);
6367 if (!part_of_multiple
)
6369 if (b
->thread
!= -1)
6371 /* FIXME: This seems to be redundant and lost here; see the
6372 "stop only in" line a little further down. */
6373 uiout
->text (" thread ");
6374 uiout
->field_int ("thread", b
->thread
);
6376 else if (b
->task
!= 0)
6378 uiout
->text (" task ");
6379 uiout
->field_int ("task", b
->task
);
6385 if (!part_of_multiple
)
6386 b
->ops
->print_one_detail (b
, uiout
);
6388 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
6391 uiout
->text ("\tstop only in stack frame at ");
6392 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside
6394 uiout
->field_core_addr ("frame",
6395 b
->gdbarch
, b
->frame_id
.stack_addr
);
6399 if (!part_of_multiple
&& b
->cond_string
)
6402 if (is_tracepoint (b
))
6403 uiout
->text ("\ttrace only if ");
6405 uiout
->text ("\tstop only if ");
6406 uiout
->field_string ("cond", b
->cond_string
);
6408 /* Print whether the target is doing the breakpoint's condition
6409 evaluation. If GDB is doing the evaluation, don't print anything. */
6410 if (is_breakpoint (b
)
6411 && breakpoint_condition_evaluation_mode ()
6412 == condition_evaluation_target
)
6415 uiout
->field_string ("evaluated-by",
6416 bp_condition_evaluator (b
));
6417 uiout
->text (" evals)");
6422 if (!part_of_multiple
&& b
->thread
!= -1)
6424 /* FIXME should make an annotation for this. */
6425 uiout
->text ("\tstop only in thread ");
6426 if (uiout
->is_mi_like_p ())
6427 uiout
->field_int ("thread", b
->thread
);
6430 struct thread_info
*thr
= find_thread_global_id (b
->thread
);
6432 uiout
->field_string ("thread", print_thread_id (thr
));
6437 if (!part_of_multiple
)
6441 /* FIXME should make an annotation for this. */
6442 if (is_catchpoint (b
))
6443 uiout
->text ("\tcatchpoint");
6444 else if (is_tracepoint (b
))
6445 uiout
->text ("\ttracepoint");
6447 uiout
->text ("\tbreakpoint");
6448 uiout
->text (" already hit ");
6449 uiout
->field_int ("times", b
->hit_count
);
6450 if (b
->hit_count
== 1)
6451 uiout
->text (" time\n");
6453 uiout
->text (" times\n");
6457 /* Output the count also if it is zero, but only if this is mi. */
6458 if (uiout
->is_mi_like_p ())
6459 uiout
->field_int ("times", b
->hit_count
);
6463 if (!part_of_multiple
&& b
->ignore_count
)
6466 uiout
->text ("\tignore next ");
6467 uiout
->field_int ("ignore", b
->ignore_count
);
6468 uiout
->text (" hits\n");
6471 /* Note that an enable count of 1 corresponds to "enable once"
6472 behavior, which is reported by the combination of enablement and
6473 disposition, so we don't need to mention it here. */
6474 if (!part_of_multiple
&& b
->enable_count
> 1)
6477 uiout
->text ("\tdisable after ");
6478 /* Tweak the wording to clarify that ignore and enable counts
6479 are distinct, and have additive effect. */
6480 if (b
->ignore_count
)
6481 uiout
->text ("additional ");
6483 uiout
->text ("next ");
6484 uiout
->field_int ("enable", b
->enable_count
);
6485 uiout
->text (" hits\n");
6488 if (!part_of_multiple
&& is_tracepoint (b
))
6490 struct tracepoint
*tp
= (struct tracepoint
*) b
;
6492 if (tp
->traceframe_usage
)
6494 uiout
->text ("\ttrace buffer usage ");
6495 uiout
->field_int ("traceframe-usage", tp
->traceframe_usage
);
6496 uiout
->text (" bytes\n");
6500 l
= b
->commands
? b
->commands
.get () : NULL
;
6501 if (!part_of_multiple
&& l
)
6504 ui_out_emit_tuple
tuple_emitter (uiout
, "script");
6505 print_command_lines (uiout
, l
, 4);
6508 if (is_tracepoint (b
))
6510 struct tracepoint
*t
= (struct tracepoint
*) b
;
6512 if (!part_of_multiple
&& t
->pass_count
)
6514 annotate_field (10);
6515 uiout
->text ("\tpass count ");
6516 uiout
->field_int ("pass", t
->pass_count
);
6517 uiout
->text (" \n");
6520 /* Don't display it when tracepoint or tracepoint location is
6522 if (!header_of_multiple
&& loc
!= NULL
&& !loc
->shlib_disabled
)
6524 annotate_field (11);
6526 if (uiout
->is_mi_like_p ())
6527 uiout
->field_string ("installed",
6528 loc
->inserted
? "y" : "n");
6534 uiout
->text ("\tnot ");
6535 uiout
->text ("installed on target\n");
6540 if (uiout
->is_mi_like_p () && !part_of_multiple
)
6542 if (is_watchpoint (b
))
6544 struct watchpoint
*w
= (struct watchpoint
*) b
;
6546 uiout
->field_string ("original-location", w
->exp_string
);
6548 else if (b
->location
!= NULL
6549 && event_location_to_string (b
->location
.get ()) != NULL
)
6550 uiout
->field_string ("original-location",
6551 event_location_to_string (b
->location
.get ()));
6556 print_one_breakpoint (struct breakpoint
*b
,
6557 struct bp_location
**last_loc
,
6560 struct ui_out
*uiout
= current_uiout
;
6563 ui_out_emit_tuple
tuple_emitter (uiout
, "bkpt");
6565 print_one_breakpoint_location (b
, NULL
, 0, last_loc
, allflag
);
6568 /* If this breakpoint has custom print function,
6569 it's already printed. Otherwise, print individual
6570 locations, if any. */
6571 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
6573 /* If breakpoint has a single location that is disabled, we
6574 print it as if it had several locations, since otherwise it's
6575 hard to represent "breakpoint enabled, location disabled"
6578 Note that while hardware watchpoints have several locations
6579 internally, that's not a property exposed to user. */
6581 && !is_hardware_watchpoint (b
)
6582 && (b
->loc
->next
|| !b
->loc
->enabled
))
6584 struct bp_location
*loc
;
6587 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
6589 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
6590 print_one_breakpoint_location (b
, loc
, n
, last_loc
, allflag
);
6597 breakpoint_address_bits (struct breakpoint
*b
)
6599 int print_address_bits
= 0;
6600 struct bp_location
*loc
;
6602 /* Software watchpoints that aren't watching memory don't have an
6603 address to print. */
6604 if (is_no_memory_software_watchpoint (b
))
6607 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6611 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
6612 if (addr_bit
> print_address_bits
)
6613 print_address_bits
= addr_bit
;
6616 return print_address_bits
;
6619 struct captured_breakpoint_query_args
6625 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
6627 struct captured_breakpoint_query_args
*args
6628 = (struct captured_breakpoint_query_args
*) data
;
6629 struct breakpoint
*b
;
6630 struct bp_location
*dummy_loc
= NULL
;
6634 if (args
->bnum
== b
->number
)
6636 print_one_breakpoint (b
, &dummy_loc
, 0);
6644 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
,
6645 char **error_message
)
6647 struct captured_breakpoint_query_args args
;
6650 /* For the moment we don't trust print_one_breakpoint() to not throw
6652 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
6653 error_message
, RETURN_MASK_ALL
) < 0)
6659 /* Return true if this breakpoint was set by the user, false if it is
6660 internal or momentary. */
6663 user_breakpoint_p (struct breakpoint
*b
)
6665 return b
->number
> 0;
6668 /* See breakpoint.h. */
6671 pending_breakpoint_p (struct breakpoint
*b
)
6673 return b
->loc
== NULL
;
6676 /* Print information on user settable breakpoint (watchpoint, etc)
6677 number BNUM. If BNUM is -1 print all user-settable breakpoints.
6678 If ALLFLAG is non-zero, include non-user-settable breakpoints. If
6679 FILTER is non-NULL, call it on each breakpoint and only include the
6680 ones for which it returns non-zero. Return the total number of
6681 breakpoints listed. */
6684 breakpoint_1 (char *args
, int allflag
,
6685 int (*filter
) (const struct breakpoint
*))
6687 struct breakpoint
*b
;
6688 struct bp_location
*last_loc
= NULL
;
6689 int nr_printable_breakpoints
;
6690 struct value_print_options opts
;
6691 int print_address_bits
= 0;
6692 int print_type_col_width
= 14;
6693 struct ui_out
*uiout
= current_uiout
;
6695 get_user_print_options (&opts
);
6697 /* Compute the number of rows in the table, as well as the size
6698 required for address fields. */
6699 nr_printable_breakpoints
= 0;
6702 /* If we have a filter, only list the breakpoints it accepts. */
6703 if (filter
&& !filter (b
))
6706 /* If we have an "args" string, it is a list of breakpoints to
6707 accept. Skip the others. */
6708 if (args
!= NULL
&& *args
!= '\0')
6710 if (allflag
&& parse_and_eval_long (args
) != b
->number
)
6712 if (!allflag
&& !number_is_in_list (args
, b
->number
))
6716 if (allflag
|| user_breakpoint_p (b
))
6718 int addr_bit
, type_len
;
6720 addr_bit
= breakpoint_address_bits (b
);
6721 if (addr_bit
> print_address_bits
)
6722 print_address_bits
= addr_bit
;
6724 type_len
= strlen (bptype_string (b
->type
));
6725 if (type_len
> print_type_col_width
)
6726 print_type_col_width
= type_len
;
6728 nr_printable_breakpoints
++;
6733 ui_out_emit_table
table_emitter (uiout
,
6734 opts
.addressprint
? 6 : 5,
6735 nr_printable_breakpoints
,
6738 if (nr_printable_breakpoints
> 0)
6739 annotate_breakpoints_headers ();
6740 if (nr_printable_breakpoints
> 0)
6742 uiout
->table_header (7, ui_left
, "number", "Num"); /* 1 */
6743 if (nr_printable_breakpoints
> 0)
6745 uiout
->table_header (print_type_col_width
, ui_left
, "type", "Type"); /* 2 */
6746 if (nr_printable_breakpoints
> 0)
6748 uiout
->table_header (4, ui_left
, "disp", "Disp"); /* 3 */
6749 if (nr_printable_breakpoints
> 0)
6751 uiout
->table_header (3, ui_left
, "enabled", "Enb"); /* 4 */
6752 if (opts
.addressprint
)
6754 if (nr_printable_breakpoints
> 0)
6756 if (print_address_bits
<= 32)
6757 uiout
->table_header (10, ui_left
, "addr", "Address"); /* 5 */
6759 uiout
->table_header (18, ui_left
, "addr", "Address"); /* 5 */
6761 if (nr_printable_breakpoints
> 0)
6763 uiout
->table_header (40, ui_noalign
, "what", "What"); /* 6 */
6764 uiout
->table_body ();
6765 if (nr_printable_breakpoints
> 0)
6766 annotate_breakpoints_table ();
6771 /* If we have a filter, only list the breakpoints it accepts. */
6772 if (filter
&& !filter (b
))
6775 /* If we have an "args" string, it is a list of breakpoints to
6776 accept. Skip the others. */
6778 if (args
!= NULL
&& *args
!= '\0')
6780 if (allflag
) /* maintenance info breakpoint */
6782 if (parse_and_eval_long (args
) != b
->number
)
6785 else /* all others */
6787 if (!number_is_in_list (args
, b
->number
))
6791 /* We only print out user settable breakpoints unless the
6793 if (allflag
|| user_breakpoint_p (b
))
6794 print_one_breakpoint (b
, &last_loc
, allflag
);
6798 if (nr_printable_breakpoints
== 0)
6800 /* If there's a filter, let the caller decide how to report
6804 if (args
== NULL
|| *args
== '\0')
6805 uiout
->message ("No breakpoints or watchpoints.\n");
6807 uiout
->message ("No breakpoint or watchpoint matching '%s'.\n",
6813 if (last_loc
&& !server_command
)
6814 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
6817 /* FIXME? Should this be moved up so that it is only called when
6818 there have been breakpoints? */
6819 annotate_breakpoints_table_end ();
6821 return nr_printable_breakpoints
;
6824 /* Display the value of default-collect in a way that is generally
6825 compatible with the breakpoint list. */
6828 default_collect_info (void)
6830 struct ui_out
*uiout
= current_uiout
;
6832 /* If it has no value (which is frequently the case), say nothing; a
6833 message like "No default-collect." gets in user's face when it's
6835 if (!*default_collect
)
6838 /* The following phrase lines up nicely with per-tracepoint collect
6840 uiout
->text ("default collect ");
6841 uiout
->field_string ("default-collect", default_collect
);
6842 uiout
->text (" \n");
6846 info_breakpoints_command (char *args
, int from_tty
)
6848 breakpoint_1 (args
, 0, NULL
);
6850 default_collect_info ();
6854 info_watchpoints_command (char *args
, int from_tty
)
6856 int num_printed
= breakpoint_1 (args
, 0, is_watchpoint
);
6857 struct ui_out
*uiout
= current_uiout
;
6859 if (num_printed
== 0)
6861 if (args
== NULL
|| *args
== '\0')
6862 uiout
->message ("No watchpoints.\n");
6864 uiout
->message ("No watchpoint matching '%s'.\n", args
);
6869 maintenance_info_breakpoints (char *args
, int from_tty
)
6871 breakpoint_1 (args
, 1, NULL
);
6873 default_collect_info ();
6877 breakpoint_has_pc (struct breakpoint
*b
,
6878 struct program_space
*pspace
,
6879 CORE_ADDR pc
, struct obj_section
*section
)
6881 struct bp_location
*bl
= b
->loc
;
6883 for (; bl
; bl
= bl
->next
)
6885 if (bl
->pspace
== pspace
6886 && bl
->address
== pc
6887 && (!overlay_debugging
|| bl
->section
== section
))
6893 /* Print a message describing any user-breakpoints set at PC. This
6894 concerns with logical breakpoints, so we match program spaces, not
6898 describe_other_breakpoints (struct gdbarch
*gdbarch
,
6899 struct program_space
*pspace
, CORE_ADDR pc
,
6900 struct obj_section
*section
, int thread
)
6903 struct breakpoint
*b
;
6906 others
+= (user_breakpoint_p (b
)
6907 && breakpoint_has_pc (b
, pspace
, pc
, section
));
6911 printf_filtered (_("Note: breakpoint "));
6912 else /* if (others == ???) */
6913 printf_filtered (_("Note: breakpoints "));
6915 if (user_breakpoint_p (b
) && breakpoint_has_pc (b
, pspace
, pc
, section
))
6918 printf_filtered ("%d", b
->number
);
6919 if (b
->thread
== -1 && thread
!= -1)
6920 printf_filtered (" (all threads)");
6921 else if (b
->thread
!= -1)
6922 printf_filtered (" (thread %d)", b
->thread
);
6923 printf_filtered ("%s%s ",
6924 ((b
->enable_state
== bp_disabled
6925 || b
->enable_state
== bp_call_disabled
)
6929 : ((others
== 1) ? " and" : ""));
6931 printf_filtered (_("also set at pc "));
6932 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
6933 printf_filtered (".\n");
6938 /* Return true iff it is meaningful to use the address member of
6939 BPT locations. For some breakpoint types, the locations' address members
6940 are irrelevant and it makes no sense to attempt to compare them to other
6941 addresses (or use them for any other purpose either).
6943 More specifically, each of the following breakpoint types will
6944 always have a zero valued location address and we don't want to mark
6945 breakpoints of any of these types to be a duplicate of an actual
6946 breakpoint location at address zero:
6954 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
6956 enum bptype type
= bpt
->type
;
6958 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
6961 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
6962 true if LOC1 and LOC2 represent the same watchpoint location. */
6965 watchpoint_locations_match (struct bp_location
*loc1
,
6966 struct bp_location
*loc2
)
6968 struct watchpoint
*w1
= (struct watchpoint
*) loc1
->owner
;
6969 struct watchpoint
*w2
= (struct watchpoint
*) loc2
->owner
;
6971 /* Both of them must exist. */
6972 gdb_assert (w1
!= NULL
);
6973 gdb_assert (w2
!= NULL
);
6975 /* If the target can evaluate the condition expression in hardware,
6976 then we we need to insert both watchpoints even if they are at
6977 the same place. Otherwise the watchpoint will only trigger when
6978 the condition of whichever watchpoint was inserted evaluates to
6979 true, not giving a chance for GDB to check the condition of the
6980 other watchpoint. */
6982 && target_can_accel_watchpoint_condition (loc1
->address
,
6984 loc1
->watchpoint_type
,
6985 w1
->cond_exp
.get ()))
6987 && target_can_accel_watchpoint_condition (loc2
->address
,
6989 loc2
->watchpoint_type
,
6990 w2
->cond_exp
.get ())))
6993 /* Note that this checks the owner's type, not the location's. In
6994 case the target does not support read watchpoints, but does
6995 support access watchpoints, we'll have bp_read_watchpoint
6996 watchpoints with hw_access locations. Those should be considered
6997 duplicates of hw_read locations. The hw_read locations will
6998 become hw_access locations later. */
6999 return (loc1
->owner
->type
== loc2
->owner
->type
7000 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
7001 && loc1
->address
== loc2
->address
7002 && loc1
->length
== loc2
->length
);
7005 /* See breakpoint.h. */
7008 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
7009 struct address_space
*aspace2
, CORE_ADDR addr2
)
7011 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7012 || aspace1
== aspace2
)
7016 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by
7017 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1
7018 matches ASPACE2. On targets that have global breakpoints, the address
7019 space doesn't really matter. */
7022 breakpoint_address_match_range (struct address_space
*aspace1
, CORE_ADDR addr1
,
7023 int len1
, struct address_space
*aspace2
,
7026 return ((gdbarch_has_global_breakpoints (target_gdbarch ())
7027 || aspace1
== aspace2
)
7028 && addr2
>= addr1
&& addr2
< addr1
+ len1
);
7031 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be
7032 a ranged breakpoint. In most targets, a match happens only if ASPACE
7033 matches the breakpoint's address space. On targets that have global
7034 breakpoints, the address space doesn't really matter. */
7037 breakpoint_location_address_match (struct bp_location
*bl
,
7038 struct address_space
*aspace
,
7041 return (breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
7044 && breakpoint_address_match_range (bl
->pspace
->aspace
,
7045 bl
->address
, bl
->length
,
7049 /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps
7050 breakpoint BL. BL may be a ranged breakpoint. In most targets, a
7051 match happens only if ASPACE matches the breakpoint's address
7052 space. On targets that have global breakpoints, the address space
7053 doesn't really matter. */
7056 breakpoint_location_address_range_overlap (struct bp_location
*bl
,
7057 struct address_space
*aspace
,
7058 CORE_ADDR addr
, int len
)
7060 if (gdbarch_has_global_breakpoints (target_gdbarch ())
7061 || bl
->pspace
->aspace
== aspace
)
7063 int bl_len
= bl
->length
!= 0 ? bl
->length
: 1;
7065 if (mem_ranges_overlap (addr
, len
, bl
->address
, bl_len
))
7071 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly.
7072 Then, if LOC1 and LOC2 represent the same tracepoint location, returns
7073 true, otherwise returns false. */
7076 tracepoint_locations_match (struct bp_location
*loc1
,
7077 struct bp_location
*loc2
)
7079 if (is_tracepoint (loc1
->owner
) && is_tracepoint (loc2
->owner
))
7080 /* Since tracepoint locations are never duplicated with others', tracepoint
7081 locations at the same address of different tracepoints are regarded as
7082 different locations. */
7083 return (loc1
->address
== loc2
->address
&& loc1
->owner
== loc2
->owner
);
7088 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
7089 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
7090 represent the same location. */
7093 breakpoint_locations_match (struct bp_location
*loc1
,
7094 struct bp_location
*loc2
)
7096 int hw_point1
, hw_point2
;
7098 /* Both of them must not be in moribund_locations. */
7099 gdb_assert (loc1
->owner
!= NULL
);
7100 gdb_assert (loc2
->owner
!= NULL
);
7102 hw_point1
= is_hardware_watchpoint (loc1
->owner
);
7103 hw_point2
= is_hardware_watchpoint (loc2
->owner
);
7105 if (hw_point1
!= hw_point2
)
7108 return watchpoint_locations_match (loc1
, loc2
);
7109 else if (is_tracepoint (loc1
->owner
) || is_tracepoint (loc2
->owner
))
7110 return tracepoint_locations_match (loc1
, loc2
);
7112 /* We compare bp_location.length in order to cover ranged breakpoints. */
7113 return (breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
7114 loc2
->pspace
->aspace
, loc2
->address
)
7115 && loc1
->length
== loc2
->length
);
7119 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
7120 int bnum
, int have_bnum
)
7122 /* The longest string possibly returned by hex_string_custom
7123 is 50 chars. These must be at least that big for safety. */
7127 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
7128 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
7130 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
7131 bnum
, astr1
, astr2
);
7133 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
7136 /* Adjust a breakpoint's address to account for architectural
7137 constraints on breakpoint placement. Return the adjusted address.
7138 Note: Very few targets require this kind of adjustment. For most
7139 targets, this function is simply the identity function. */
7142 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
7143 CORE_ADDR bpaddr
, enum bptype bptype
)
7145 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
7147 /* Very few targets need any kind of breakpoint adjustment. */
7150 else if (bptype
== bp_watchpoint
7151 || bptype
== bp_hardware_watchpoint
7152 || bptype
== bp_read_watchpoint
7153 || bptype
== bp_access_watchpoint
7154 || bptype
== bp_catchpoint
)
7156 /* Watchpoints and the various bp_catch_* eventpoints should not
7157 have their addresses modified. */
7160 else if (bptype
== bp_single_step
)
7162 /* Single-step breakpoints should not have their addresses
7163 modified. If there's any architectural constrain that
7164 applies to this address, then it should have already been
7165 taken into account when the breakpoint was created in the
7166 first place. If we didn't do this, stepping through e.g.,
7167 Thumb-2 IT blocks would break. */
7172 CORE_ADDR adjusted_bpaddr
;
7174 /* Some targets have architectural constraints on the placement
7175 of breakpoint instructions. Obtain the adjusted address. */
7176 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
7178 /* An adjusted breakpoint address can significantly alter
7179 a user's expectations. Print a warning if an adjustment
7181 if (adjusted_bpaddr
!= bpaddr
)
7182 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
7184 return adjusted_bpaddr
;
7188 bp_location::bp_location (const bp_location_ops
*ops
, breakpoint
*owner
)
7190 bp_location
*loc
= this;
7192 gdb_assert (ops
!= NULL
);
7196 loc
->cond_bytecode
= NULL
;
7197 loc
->shlib_disabled
= 0;
7200 switch (owner
->type
)
7203 case bp_single_step
:
7207 case bp_longjmp_resume
:
7208 case bp_longjmp_call_dummy
:
7210 case bp_exception_resume
:
7211 case bp_step_resume
:
7212 case bp_hp_step_resume
:
7213 case bp_watchpoint_scope
:
7215 case bp_std_terminate
:
7216 case bp_shlib_event
:
7217 case bp_thread_event
:
7218 case bp_overlay_event
:
7220 case bp_longjmp_master
:
7221 case bp_std_terminate_master
:
7222 case bp_exception_master
:
7223 case bp_gnu_ifunc_resolver
:
7224 case bp_gnu_ifunc_resolver_return
:
7226 loc
->loc_type
= bp_loc_software_breakpoint
;
7227 mark_breakpoint_location_modified (loc
);
7229 case bp_hardware_breakpoint
:
7230 loc
->loc_type
= bp_loc_hardware_breakpoint
;
7231 mark_breakpoint_location_modified (loc
);
7233 case bp_hardware_watchpoint
:
7234 case bp_read_watchpoint
:
7235 case bp_access_watchpoint
:
7236 loc
->loc_type
= bp_loc_hardware_watchpoint
;
7241 case bp_fast_tracepoint
:
7242 case bp_static_tracepoint
:
7243 loc
->loc_type
= bp_loc_other
;
7246 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
7252 /* Allocate a struct bp_location. */
7254 static struct bp_location
*
7255 allocate_bp_location (struct breakpoint
*bpt
)
7257 return bpt
->ops
->allocate_location (bpt
);
7261 free_bp_location (struct bp_location
*loc
)
7263 loc
->ops
->dtor (loc
);
7267 /* Increment reference count. */
7270 incref_bp_location (struct bp_location
*bl
)
7275 /* Decrement reference count. If the reference count reaches 0,
7276 destroy the bp_location. Sets *BLP to NULL. */
7279 decref_bp_location (struct bp_location
**blp
)
7281 gdb_assert ((*blp
)->refc
> 0);
7283 if (--(*blp
)->refc
== 0)
7284 free_bp_location (*blp
);
7288 /* Add breakpoint B at the end of the global breakpoint chain. */
7291 add_to_breakpoint_chain (std::unique_ptr
<breakpoint
> &&b
)
7293 struct breakpoint
*b1
;
7294 struct breakpoint
*result
= b
.get ();
7296 /* Add this breakpoint to the end of the chain so that a list of
7297 breakpoints will come out in order of increasing numbers. */
7299 b1
= breakpoint_chain
;
7301 breakpoint_chain
= b
.release ();
7306 b1
->next
= b
.release ();
7312 /* Initializes breakpoint B with type BPTYPE and no locations yet. */
7315 init_raw_breakpoint_without_location (struct breakpoint
*b
,
7316 struct gdbarch
*gdbarch
,
7318 const struct breakpoint_ops
*ops
)
7320 gdb_assert (ops
!= NULL
);
7324 b
->gdbarch
= gdbarch
;
7325 b
->language
= current_language
->la_language
;
7326 b
->input_radix
= input_radix
;
7327 b
->related_breakpoint
= b
;
7330 /* Helper to set_raw_breakpoint below. Creates a breakpoint
7331 that has type BPTYPE and has no locations as yet. */
7333 static struct breakpoint
*
7334 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
7336 const struct breakpoint_ops
*ops
)
7338 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7340 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bptype
, ops
);
7341 return add_to_breakpoint_chain (std::move (b
));
7344 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function
7345 resolutions should be made as the user specified the location explicitly
7349 set_breakpoint_location_function (struct bp_location
*loc
, int explicit_loc
)
7351 gdb_assert (loc
->owner
!= NULL
);
7353 if (loc
->owner
->type
== bp_breakpoint
7354 || loc
->owner
->type
== bp_hardware_breakpoint
7355 || is_tracepoint (loc
->owner
))
7358 const char *function_name
;
7359 CORE_ADDR func_addr
;
7361 find_pc_partial_function_gnu_ifunc (loc
->address
, &function_name
,
7362 &func_addr
, NULL
, &is_gnu_ifunc
);
7364 if (is_gnu_ifunc
&& !explicit_loc
)
7366 struct breakpoint
*b
= loc
->owner
;
7368 gdb_assert (loc
->pspace
== current_program_space
);
7369 if (gnu_ifunc_resolve_name (function_name
,
7370 &loc
->requested_address
))
7372 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */
7373 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
7374 loc
->requested_address
,
7377 else if (b
->type
== bp_breakpoint
&& b
->loc
== loc
7378 && loc
->next
== NULL
&& b
->related_breakpoint
== b
)
7380 /* Create only the whole new breakpoint of this type but do not
7381 mess more complicated breakpoints with multiple locations. */
7382 b
->type
= bp_gnu_ifunc_resolver
;
7383 /* Remember the resolver's address for use by the return
7385 loc
->related_address
= func_addr
;
7390 loc
->function_name
= xstrdup (function_name
);
7394 /* Attempt to determine architecture of location identified by SAL. */
7396 get_sal_arch (struct symtab_and_line sal
)
7399 return get_objfile_arch (sal
.section
->objfile
);
7401 return get_objfile_arch (SYMTAB_OBJFILE (sal
.symtab
));
7406 /* Low level routine for partially initializing a breakpoint of type
7407 BPTYPE. The newly created breakpoint's address, section, source
7408 file name, and line number are provided by SAL.
7410 It is expected that the caller will complete the initialization of
7411 the newly created breakpoint struct as well as output any status
7412 information regarding the creation of a new breakpoint. */
7415 init_raw_breakpoint (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
7416 struct symtab_and_line sal
, enum bptype bptype
,
7417 const struct breakpoint_ops
*ops
)
7419 init_raw_breakpoint_without_location (b
, gdbarch
, bptype
, ops
);
7421 add_location_to_breakpoint (b
, &sal
);
7423 if (bptype
!= bp_catchpoint
)
7424 gdb_assert (sal
.pspace
!= NULL
);
7426 /* Store the program space that was used to set the breakpoint,
7427 except for ordinary breakpoints, which are independent of the
7429 if (bptype
!= bp_breakpoint
&& bptype
!= bp_hardware_breakpoint
)
7430 b
->pspace
= sal
.pspace
;
7433 /* set_raw_breakpoint is a low level routine for allocating and
7434 partially initializing a breakpoint of type BPTYPE. The newly
7435 created breakpoint's address, section, source file name, and line
7436 number are provided by SAL. The newly created and partially
7437 initialized breakpoint is added to the breakpoint chain and
7438 is also returned as the value of this function.
7440 It is expected that the caller will complete the initialization of
7441 the newly created breakpoint struct as well as output any status
7442 information regarding the creation of a new breakpoint. In
7443 particular, set_raw_breakpoint does NOT set the breakpoint
7444 number! Care should be taken to not allow an error to occur
7445 prior to completing the initialization of the breakpoint. If this
7446 should happen, a bogus breakpoint will be left on the chain. */
7449 set_raw_breakpoint (struct gdbarch
*gdbarch
,
7450 struct symtab_and_line sal
, enum bptype bptype
,
7451 const struct breakpoint_ops
*ops
)
7453 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (bptype
);
7455 init_raw_breakpoint (b
.get (), gdbarch
, sal
, bptype
, ops
);
7456 return add_to_breakpoint_chain (std::move (b
));
7459 /* Call this routine when stepping and nexting to enable a breakpoint
7460 if we do a longjmp() or 'throw' in TP. FRAME is the frame which
7461 initiated the operation. */
7464 set_longjmp_breakpoint (struct thread_info
*tp
, struct frame_id frame
)
7466 struct breakpoint
*b
, *b_tmp
;
7467 int thread
= tp
->global_num
;
7469 /* To avoid having to rescan all objfile symbols at every step,
7470 we maintain a list of continually-inserted but always disabled
7471 longjmp "master" breakpoints. Here, we simply create momentary
7472 clones of those and enable them for the requested thread. */
7473 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7474 if (b
->pspace
== current_program_space
7475 && (b
->type
== bp_longjmp_master
7476 || b
->type
== bp_exception_master
))
7478 enum bptype type
= b
->type
== bp_longjmp_master
? bp_longjmp
: bp_exception
;
7479 struct breakpoint
*clone
;
7481 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again
7482 after their removal. */
7483 clone
= momentary_breakpoint_from_master (b
, type
,
7484 &momentary_breakpoint_ops
, 1);
7485 clone
->thread
= thread
;
7488 tp
->initiating_frame
= frame
;
7491 /* Delete all longjmp breakpoints from THREAD. */
7493 delete_longjmp_breakpoint (int thread
)
7495 struct breakpoint
*b
, *b_tmp
;
7497 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7498 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7500 if (b
->thread
== thread
)
7501 delete_breakpoint (b
);
7506 delete_longjmp_breakpoint_at_next_stop (int thread
)
7508 struct breakpoint
*b
, *b_tmp
;
7510 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7511 if (b
->type
== bp_longjmp
|| b
->type
== bp_exception
)
7513 if (b
->thread
== thread
)
7514 b
->disposition
= disp_del_at_next_stop
;
7518 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for
7519 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return
7520 pointer to any of them. Return NULL if this system cannot place longjmp
7524 set_longjmp_breakpoint_for_call_dummy (void)
7526 struct breakpoint
*b
, *retval
= NULL
;
7529 if (b
->pspace
== current_program_space
&& b
->type
== bp_longjmp_master
)
7531 struct breakpoint
*new_b
;
7533 new_b
= momentary_breakpoint_from_master (b
, bp_longjmp_call_dummy
,
7534 &momentary_breakpoint_ops
,
7536 new_b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
7538 /* Link NEW_B into the chain of RETVAL breakpoints. */
7540 gdb_assert (new_b
->related_breakpoint
== new_b
);
7543 new_b
->related_breakpoint
= retval
;
7544 while (retval
->related_breakpoint
!= new_b
->related_breakpoint
)
7545 retval
= retval
->related_breakpoint
;
7546 retval
->related_breakpoint
= new_b
;
7552 /* Verify all existing dummy frames and their associated breakpoints for
7553 TP. Remove those which can no longer be found in the current frame
7556 You should call this function only at places where it is safe to currently
7557 unwind the whole stack. Failed stack unwind would discard live dummy
7561 check_longjmp_breakpoint_for_call_dummy (struct thread_info
*tp
)
7563 struct breakpoint
*b
, *b_tmp
;
7565 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7566 if (b
->type
== bp_longjmp_call_dummy
&& b
->thread
== tp
->global_num
)
7568 struct breakpoint
*dummy_b
= b
->related_breakpoint
;
7570 while (dummy_b
!= b
&& dummy_b
->type
!= bp_call_dummy
)
7571 dummy_b
= dummy_b
->related_breakpoint
;
7572 if (dummy_b
->type
!= bp_call_dummy
7573 || frame_find_by_id (dummy_b
->frame_id
) != NULL
)
7576 dummy_frame_discard (dummy_b
->frame_id
, tp
->ptid
);
7578 while (b
->related_breakpoint
!= b
)
7580 if (b_tmp
== b
->related_breakpoint
)
7581 b_tmp
= b
->related_breakpoint
->next
;
7582 delete_breakpoint (b
->related_breakpoint
);
7584 delete_breakpoint (b
);
7589 enable_overlay_breakpoints (void)
7591 struct breakpoint
*b
;
7594 if (b
->type
== bp_overlay_event
)
7596 b
->enable_state
= bp_enabled
;
7597 update_global_location_list (UGLL_MAY_INSERT
);
7598 overlay_events_enabled
= 1;
7603 disable_overlay_breakpoints (void)
7605 struct breakpoint
*b
;
7608 if (b
->type
== bp_overlay_event
)
7610 b
->enable_state
= bp_disabled
;
7611 update_global_location_list (UGLL_DONT_INSERT
);
7612 overlay_events_enabled
= 0;
7616 /* Set an active std::terminate breakpoint for each std::terminate
7617 master breakpoint. */
7619 set_std_terminate_breakpoint (void)
7621 struct breakpoint
*b
, *b_tmp
;
7623 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7624 if (b
->pspace
== current_program_space
7625 && b
->type
== bp_std_terminate_master
)
7627 momentary_breakpoint_from_master (b
, bp_std_terminate
,
7628 &momentary_breakpoint_ops
, 1);
7632 /* Delete all the std::terminate breakpoints. */
7634 delete_std_terminate_breakpoint (void)
7636 struct breakpoint
*b
, *b_tmp
;
7638 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7639 if (b
->type
== bp_std_terminate
)
7640 delete_breakpoint (b
);
7644 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7646 struct breakpoint
*b
;
7648 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
,
7649 &internal_breakpoint_ops
);
7651 b
->enable_state
= bp_enabled
;
7652 /* location has to be used or breakpoint_re_set will delete me. */
7653 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
7655 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
7660 struct lang_and_radix
7666 /* Create a breakpoint for JIT code registration and unregistration. */
7669 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7671 return create_internal_breakpoint (gdbarch
, address
, bp_jit_event
,
7672 &internal_breakpoint_ops
);
7675 /* Remove JIT code registration and unregistration breakpoint(s). */
7678 remove_jit_event_breakpoints (void)
7680 struct breakpoint
*b
, *b_tmp
;
7682 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7683 if (b
->type
== bp_jit_event
7684 && b
->loc
->pspace
== current_program_space
)
7685 delete_breakpoint (b
);
7689 remove_solib_event_breakpoints (void)
7691 struct breakpoint
*b
, *b_tmp
;
7693 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7694 if (b
->type
== bp_shlib_event
7695 && b
->loc
->pspace
== current_program_space
)
7696 delete_breakpoint (b
);
7699 /* See breakpoint.h. */
7702 remove_solib_event_breakpoints_at_next_stop (void)
7704 struct breakpoint
*b
, *b_tmp
;
7706 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
7707 if (b
->type
== bp_shlib_event
7708 && b
->loc
->pspace
== current_program_space
)
7709 b
->disposition
= disp_del_at_next_stop
;
7712 /* Helper for create_solib_event_breakpoint /
7713 create_and_insert_solib_event_breakpoint. Allows specifying which
7714 INSERT_MODE to pass through to update_global_location_list. */
7716 static struct breakpoint
*
7717 create_solib_event_breakpoint_1 (struct gdbarch
*gdbarch
, CORE_ADDR address
,
7718 enum ugll_insert_mode insert_mode
)
7720 struct breakpoint
*b
;
7722 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
,
7723 &internal_breakpoint_ops
);
7724 update_global_location_list_nothrow (insert_mode
);
7729 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7731 return create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_MAY_INSERT
);
7734 /* See breakpoint.h. */
7737 create_and_insert_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
7739 struct breakpoint
*b
;
7741 /* Explicitly tell update_global_location_list to insert
7743 b
= create_solib_event_breakpoint_1 (gdbarch
, address
, UGLL_INSERT
);
7744 if (!b
->loc
->inserted
)
7746 delete_breakpoint (b
);
7752 /* Disable any breakpoints that are on code in shared libraries. Only
7753 apply to enabled breakpoints, disabled ones can just stay disabled. */
7756 disable_breakpoints_in_shlibs (void)
7758 struct bp_location
*loc
, **locp_tmp
;
7760 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7762 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7763 struct breakpoint
*b
= loc
->owner
;
7765 /* We apply the check to all breakpoints, including disabled for
7766 those with loc->duplicate set. This is so that when breakpoint
7767 becomes enabled, or the duplicate is removed, gdb will try to
7768 insert all breakpoints. If we don't set shlib_disabled here,
7769 we'll try to insert those breakpoints and fail. */
7770 if (((b
->type
== bp_breakpoint
)
7771 || (b
->type
== bp_jit_event
)
7772 || (b
->type
== bp_hardware_breakpoint
)
7773 || (is_tracepoint (b
)))
7774 && loc
->pspace
== current_program_space
7775 && !loc
->shlib_disabled
7776 && solib_name_from_address (loc
->pspace
, loc
->address
)
7779 loc
->shlib_disabled
= 1;
7784 /* Disable any breakpoints and tracepoints that are in SOLIB upon
7785 notification of unloaded_shlib. Only apply to enabled breakpoints,
7786 disabled ones can just stay disabled. */
7789 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
7791 struct bp_location
*loc
, **locp_tmp
;
7792 int disabled_shlib_breaks
= 0;
7794 ALL_BP_LOCATIONS (loc
, locp_tmp
)
7796 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */
7797 struct breakpoint
*b
= loc
->owner
;
7799 if (solib
->pspace
== loc
->pspace
7800 && !loc
->shlib_disabled
7801 && (((b
->type
== bp_breakpoint
7802 || b
->type
== bp_jit_event
7803 || b
->type
== bp_hardware_breakpoint
)
7804 && (loc
->loc_type
== bp_loc_hardware_breakpoint
7805 || loc
->loc_type
== bp_loc_software_breakpoint
))
7806 || is_tracepoint (b
))
7807 && solib_contains_address_p (solib
, loc
->address
))
7809 loc
->shlib_disabled
= 1;
7810 /* At this point, we cannot rely on remove_breakpoint
7811 succeeding so we must mark the breakpoint as not inserted
7812 to prevent future errors occurring in remove_breakpoints. */
7815 /* This may cause duplicate notifications for the same breakpoint. */
7816 observer_notify_breakpoint_modified (b
);
7818 if (!disabled_shlib_breaks
)
7820 target_terminal::ours_for_output ();
7821 warning (_("Temporarily disabling breakpoints "
7822 "for unloaded shared library \"%s\""),
7825 disabled_shlib_breaks
= 1;
7830 /* Disable any breakpoints and tracepoints in OBJFILE upon
7831 notification of free_objfile. Only apply to enabled breakpoints,
7832 disabled ones can just stay disabled. */
7835 disable_breakpoints_in_freed_objfile (struct objfile
*objfile
)
7837 struct breakpoint
*b
;
7839 if (objfile
== NULL
)
7842 /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually
7843 managed by the user with add-symbol-file/remove-symbol-file.
7844 Similarly to how breakpoints in shared libraries are handled in
7845 response to "nosharedlibrary", mark breakpoints in such modules
7846 shlib_disabled so they end up uninserted on the next global
7847 location list update. Shared libraries not loaded by the user
7848 aren't handled here -- they're already handled in
7849 disable_breakpoints_in_unloaded_shlib, called by solib.c's
7850 solib_unloaded observer. We skip objfiles that are not
7851 OBJF_SHARED as those aren't considered dynamic objects (e.g. the
7853 if ((objfile
->flags
& OBJF_SHARED
) == 0
7854 || (objfile
->flags
& OBJF_USERLOADED
) == 0)
7859 struct bp_location
*loc
;
7860 int bp_modified
= 0;
7862 if (!is_breakpoint (b
) && !is_tracepoint (b
))
7865 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
7867 CORE_ADDR loc_addr
= loc
->address
;
7869 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7870 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7873 if (loc
->shlib_disabled
!= 0)
7876 if (objfile
->pspace
!= loc
->pspace
)
7879 if (loc
->loc_type
!= bp_loc_hardware_breakpoint
7880 && loc
->loc_type
!= bp_loc_software_breakpoint
)
7883 if (is_addr_in_objfile (loc_addr
, objfile
))
7885 loc
->shlib_disabled
= 1;
7886 /* At this point, we don't know whether the object was
7887 unmapped from the inferior or not, so leave the
7888 inserted flag alone. We'll handle failure to
7889 uninsert quietly, in case the object was indeed
7892 mark_breakpoint_location_modified (loc
);
7899 observer_notify_breakpoint_modified (b
);
7903 /* FORK & VFORK catchpoints. */
7905 /* An instance of this type is used to represent a fork or vfork
7906 catchpoint. A breakpoint is really of this type iff its ops pointer points
7907 to CATCH_FORK_BREAKPOINT_OPS. */
7909 struct fork_catchpoint
: public breakpoint
7911 /* Process id of a child process whose forking triggered this
7912 catchpoint. This field is only valid immediately after this
7913 catchpoint has triggered. */
7914 ptid_t forked_inferior_pid
;
7917 /* Implement the "insert" breakpoint_ops method for fork
7921 insert_catch_fork (struct bp_location
*bl
)
7923 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7926 /* Implement the "remove" breakpoint_ops method for fork
7930 remove_catch_fork (struct bp_location
*bl
, enum remove_bp_reason reason
)
7932 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid
));
7935 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
7939 breakpoint_hit_catch_fork (const struct bp_location
*bl
,
7940 struct address_space
*aspace
, CORE_ADDR bp_addr
,
7941 const struct target_waitstatus
*ws
)
7943 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
7945 if (ws
->kind
!= TARGET_WAITKIND_FORKED
)
7948 c
->forked_inferior_pid
= ws
->value
.related_pid
;
7952 /* Implement the "print_it" breakpoint_ops method for fork
7955 static enum print_stop_action
7956 print_it_catch_fork (bpstat bs
)
7958 struct ui_out
*uiout
= current_uiout
;
7959 struct breakpoint
*b
= bs
->breakpoint_at
;
7960 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bs
->breakpoint_at
;
7962 annotate_catchpoint (b
->number
);
7963 maybe_print_thread_hit_breakpoint (uiout
);
7964 if (b
->disposition
== disp_del
)
7965 uiout
->text ("Temporary catchpoint ");
7967 uiout
->text ("Catchpoint ");
7968 if (uiout
->is_mi_like_p ())
7970 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK
));
7971 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
7973 uiout
->field_int ("bkptno", b
->number
);
7974 uiout
->text (" (forked process ");
7975 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
7976 uiout
->text ("), ");
7977 return PRINT_SRC_AND_LOC
;
7980 /* Implement the "print_one" breakpoint_ops method for fork
7984 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
7986 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
7987 struct value_print_options opts
;
7988 struct ui_out
*uiout
= current_uiout
;
7990 get_user_print_options (&opts
);
7992 /* Field 4, the address, is omitted (which makes the columns not
7993 line up too nicely with the headers, but the effect is relatively
7995 if (opts
.addressprint
)
7996 uiout
->field_skip ("addr");
7998 uiout
->text ("fork");
7999 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8001 uiout
->text (", process ");
8002 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8006 if (uiout
->is_mi_like_p ())
8007 uiout
->field_string ("catch-type", "fork");
8010 /* Implement the "print_mention" breakpoint_ops method for fork
8014 print_mention_catch_fork (struct breakpoint
*b
)
8016 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
8019 /* Implement the "print_recreate" breakpoint_ops method for fork
8023 print_recreate_catch_fork (struct breakpoint
*b
, struct ui_file
*fp
)
8025 fprintf_unfiltered (fp
, "catch fork");
8026 print_recreate_thread (b
, fp
);
8029 /* The breakpoint_ops structure to be used in fork catchpoints. */
8031 static struct breakpoint_ops catch_fork_breakpoint_ops
;
8033 /* Implement the "insert" breakpoint_ops method for vfork
8037 insert_catch_vfork (struct bp_location
*bl
)
8039 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8042 /* Implement the "remove" breakpoint_ops method for vfork
8046 remove_catch_vfork (struct bp_location
*bl
, enum remove_bp_reason reason
)
8048 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid
));
8051 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
8055 breakpoint_hit_catch_vfork (const struct bp_location
*bl
,
8056 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8057 const struct target_waitstatus
*ws
)
8059 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) bl
->owner
;
8061 if (ws
->kind
!= TARGET_WAITKIND_VFORKED
)
8064 c
->forked_inferior_pid
= ws
->value
.related_pid
;
8068 /* Implement the "print_it" breakpoint_ops method for vfork
8071 static enum print_stop_action
8072 print_it_catch_vfork (bpstat bs
)
8074 struct ui_out
*uiout
= current_uiout
;
8075 struct breakpoint
*b
= bs
->breakpoint_at
;
8076 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8078 annotate_catchpoint (b
->number
);
8079 maybe_print_thread_hit_breakpoint (uiout
);
8080 if (b
->disposition
== disp_del
)
8081 uiout
->text ("Temporary catchpoint ");
8083 uiout
->text ("Catchpoint ");
8084 if (uiout
->is_mi_like_p ())
8086 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK
));
8087 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8089 uiout
->field_int ("bkptno", b
->number
);
8090 uiout
->text (" (vforked process ");
8091 uiout
->field_int ("newpid", ptid_get_pid (c
->forked_inferior_pid
));
8092 uiout
->text ("), ");
8093 return PRINT_SRC_AND_LOC
;
8096 /* Implement the "print_one" breakpoint_ops method for vfork
8100 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
8102 struct fork_catchpoint
*c
= (struct fork_catchpoint
*) b
;
8103 struct value_print_options opts
;
8104 struct ui_out
*uiout
= current_uiout
;
8106 get_user_print_options (&opts
);
8107 /* Field 4, the address, is omitted (which makes the columns not
8108 line up too nicely with the headers, but the effect is relatively
8110 if (opts
.addressprint
)
8111 uiout
->field_skip ("addr");
8113 uiout
->text ("vfork");
8114 if (!ptid_equal (c
->forked_inferior_pid
, null_ptid
))
8116 uiout
->text (", process ");
8117 uiout
->field_int ("what", ptid_get_pid (c
->forked_inferior_pid
));
8121 if (uiout
->is_mi_like_p ())
8122 uiout
->field_string ("catch-type", "vfork");
8125 /* Implement the "print_mention" breakpoint_ops method for vfork
8129 print_mention_catch_vfork (struct breakpoint
*b
)
8131 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
8134 /* Implement the "print_recreate" breakpoint_ops method for vfork
8138 print_recreate_catch_vfork (struct breakpoint
*b
, struct ui_file
*fp
)
8140 fprintf_unfiltered (fp
, "catch vfork");
8141 print_recreate_thread (b
, fp
);
8144 /* The breakpoint_ops structure to be used in vfork catchpoints. */
8146 static struct breakpoint_ops catch_vfork_breakpoint_ops
;
8148 /* An instance of this type is used to represent an solib catchpoint.
8149 A breakpoint is really of this type iff its ops pointer points to
8150 CATCH_SOLIB_BREAKPOINT_OPS. */
8152 struct solib_catchpoint
: public breakpoint
8154 ~solib_catchpoint () override
;
8156 /* True for "catch load", false for "catch unload". */
8157 unsigned char is_load
;
8159 /* Regular expression to match, if any. COMPILED is only valid when
8160 REGEX is non-NULL. */
8162 std::unique_ptr
<compiled_regex
> compiled
;
8165 solib_catchpoint::~solib_catchpoint ()
8167 xfree (this->regex
);
8171 insert_catch_solib (struct bp_location
*ignore
)
8177 remove_catch_solib (struct bp_location
*ignore
, enum remove_bp_reason reason
)
8183 breakpoint_hit_catch_solib (const struct bp_location
*bl
,
8184 struct address_space
*aspace
,
8186 const struct target_waitstatus
*ws
)
8188 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) bl
->owner
;
8189 struct breakpoint
*other
;
8191 if (ws
->kind
== TARGET_WAITKIND_LOADED
)
8194 ALL_BREAKPOINTS (other
)
8196 struct bp_location
*other_bl
;
8198 if (other
== bl
->owner
)
8201 if (other
->type
!= bp_shlib_event
)
8204 if (self
->pspace
!= NULL
&& other
->pspace
!= self
->pspace
)
8207 for (other_bl
= other
->loc
; other_bl
!= NULL
; other_bl
= other_bl
->next
)
8209 if (other
->ops
->breakpoint_hit (other_bl
, aspace
, bp_addr
, ws
))
8218 check_status_catch_solib (struct bpstats
*bs
)
8220 struct solib_catchpoint
*self
8221 = (struct solib_catchpoint
*) bs
->breakpoint_at
;
8226 struct so_list
*iter
;
8229 VEC_iterate (so_list_ptr
, current_program_space
->added_solibs
,
8234 || self
->compiled
->exec (iter
->so_name
, 0, NULL
, 0) == 0)
8243 VEC_iterate (char_ptr
, current_program_space
->deleted_solibs
,
8248 || self
->compiled
->exec (iter
, 0, NULL
, 0) == 0)
8254 bs
->print_it
= print_it_noop
;
8257 static enum print_stop_action
8258 print_it_catch_solib (bpstat bs
)
8260 struct breakpoint
*b
= bs
->breakpoint_at
;
8261 struct ui_out
*uiout
= current_uiout
;
8263 annotate_catchpoint (b
->number
);
8264 maybe_print_thread_hit_breakpoint (uiout
);
8265 if (b
->disposition
== disp_del
)
8266 uiout
->text ("Temporary catchpoint ");
8268 uiout
->text ("Catchpoint ");
8269 uiout
->field_int ("bkptno", b
->number
);
8271 if (uiout
->is_mi_like_p ())
8272 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8273 print_solib_event (1);
8274 return PRINT_SRC_AND_LOC
;
8278 print_one_catch_solib (struct breakpoint
*b
, struct bp_location
**locs
)
8280 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8281 struct value_print_options opts
;
8282 struct ui_out
*uiout
= current_uiout
;
8285 get_user_print_options (&opts
);
8286 /* Field 4, the address, is omitted (which makes the columns not
8287 line up too nicely with the headers, but the effect is relatively
8289 if (opts
.addressprint
)
8292 uiout
->field_skip ("addr");
8299 msg
= xstrprintf (_("load of library matching %s"), self
->regex
);
8301 msg
= xstrdup (_("load of library"));
8306 msg
= xstrprintf (_("unload of library matching %s"), self
->regex
);
8308 msg
= xstrdup (_("unload of library"));
8310 uiout
->field_string ("what", msg
);
8313 if (uiout
->is_mi_like_p ())
8314 uiout
->field_string ("catch-type", self
->is_load
? "load" : "unload");
8318 print_mention_catch_solib (struct breakpoint
*b
)
8320 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8322 printf_filtered (_("Catchpoint %d (%s)"), b
->number
,
8323 self
->is_load
? "load" : "unload");
8327 print_recreate_catch_solib (struct breakpoint
*b
, struct ui_file
*fp
)
8329 struct solib_catchpoint
*self
= (struct solib_catchpoint
*) b
;
8331 fprintf_unfiltered (fp
, "%s %s",
8332 b
->disposition
== disp_del
? "tcatch" : "catch",
8333 self
->is_load
? "load" : "unload");
8335 fprintf_unfiltered (fp
, " %s", self
->regex
);
8336 fprintf_unfiltered (fp
, "\n");
8339 static struct breakpoint_ops catch_solib_breakpoint_ops
;
8341 /* Shared helper function (MI and CLI) for creating and installing
8342 a shared object event catchpoint. If IS_LOAD is non-zero then
8343 the events to be caught are load events, otherwise they are
8344 unload events. If IS_TEMP is non-zero the catchpoint is a
8345 temporary one. If ENABLED is non-zero the catchpoint is
8346 created in an enabled state. */
8349 add_solib_catchpoint (const char *arg
, int is_load
, int is_temp
, int enabled
)
8351 struct gdbarch
*gdbarch
= get_current_arch ();
8355 arg
= skip_spaces (arg
);
8357 std::unique_ptr
<solib_catchpoint
> c (new solib_catchpoint ());
8361 c
->compiled
.reset (new compiled_regex (arg
, REG_NOSUB
,
8362 _("Invalid regexp")));
8363 c
->regex
= xstrdup (arg
);
8366 c
->is_load
= is_load
;
8367 init_catchpoint (c
.get (), gdbarch
, is_temp
, NULL
,
8368 &catch_solib_breakpoint_ops
);
8370 c
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
8372 install_breakpoint (0, std::move (c
), 1);
8375 /* A helper function that does all the work for "catch load" and
8379 catch_load_or_unload (char *arg
, int from_tty
, int is_load
,
8380 struct cmd_list_element
*command
)
8383 const int enabled
= 1;
8385 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8387 add_solib_catchpoint (arg
, is_load
, tempflag
, enabled
);
8391 catch_load_command_1 (char *arg
, int from_tty
,
8392 struct cmd_list_element
*command
)
8394 catch_load_or_unload (arg
, from_tty
, 1, command
);
8398 catch_unload_command_1 (char *arg
, int from_tty
,
8399 struct cmd_list_element
*command
)
8401 catch_load_or_unload (arg
, from_tty
, 0, command
);
8404 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG
8405 is non-zero, then make the breakpoint temporary. If COND_STRING is
8406 not NULL, then store it in the breakpoint. OPS, if not NULL, is
8407 the breakpoint_ops structure associated to the catchpoint. */
8410 init_catchpoint (struct breakpoint
*b
,
8411 struct gdbarch
*gdbarch
, int tempflag
,
8412 const char *cond_string
,
8413 const struct breakpoint_ops
*ops
)
8415 symtab_and_line sal
;
8416 sal
.pspace
= current_program_space
;
8418 init_raw_breakpoint (b
, gdbarch
, sal
, bp_catchpoint
, ops
);
8420 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
8421 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8425 install_breakpoint (int internal
, std::unique_ptr
<breakpoint
> &&arg
, int update_gll
)
8427 breakpoint
*b
= add_to_breakpoint_chain (std::move (arg
));
8428 set_breakpoint_number (internal
, b
);
8429 if (is_tracepoint (b
))
8430 set_tracepoint_count (breakpoint_count
);
8433 observer_notify_breakpoint_created (b
);
8436 update_global_location_list (UGLL_MAY_INSERT
);
8440 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
8441 int tempflag
, const char *cond_string
,
8442 const struct breakpoint_ops
*ops
)
8444 std::unique_ptr
<fork_catchpoint
> c (new fork_catchpoint ());
8446 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
, ops
);
8448 c
->forked_inferior_pid
= null_ptid
;
8450 install_breakpoint (0, std::move (c
), 1);
8453 /* Exec catchpoints. */
8455 /* An instance of this type is used to represent an exec catchpoint.
8456 A breakpoint is really of this type iff its ops pointer points to
8457 CATCH_EXEC_BREAKPOINT_OPS. */
8459 struct exec_catchpoint
: public breakpoint
8461 ~exec_catchpoint () override
;
8463 /* Filename of a program whose exec triggered this catchpoint.
8464 This field is only valid immediately after this catchpoint has
8466 char *exec_pathname
;
8469 /* Exec catchpoint destructor. */
8471 exec_catchpoint::~exec_catchpoint ()
8473 xfree (this->exec_pathname
);
8477 insert_catch_exec (struct bp_location
*bl
)
8479 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8483 remove_catch_exec (struct bp_location
*bl
, enum remove_bp_reason reason
)
8485 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid
));
8489 breakpoint_hit_catch_exec (const struct bp_location
*bl
,
8490 struct address_space
*aspace
, CORE_ADDR bp_addr
,
8491 const struct target_waitstatus
*ws
)
8493 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) bl
->owner
;
8495 if (ws
->kind
!= TARGET_WAITKIND_EXECD
)
8498 c
->exec_pathname
= xstrdup (ws
->value
.execd_pathname
);
8502 static enum print_stop_action
8503 print_it_catch_exec (bpstat bs
)
8505 struct ui_out
*uiout
= current_uiout
;
8506 struct breakpoint
*b
= bs
->breakpoint_at
;
8507 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8509 annotate_catchpoint (b
->number
);
8510 maybe_print_thread_hit_breakpoint (uiout
);
8511 if (b
->disposition
== disp_del
)
8512 uiout
->text ("Temporary catchpoint ");
8514 uiout
->text ("Catchpoint ");
8515 if (uiout
->is_mi_like_p ())
8517 uiout
->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC
));
8518 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
8520 uiout
->field_int ("bkptno", b
->number
);
8521 uiout
->text (" (exec'd ");
8522 uiout
->field_string ("new-exec", c
->exec_pathname
);
8523 uiout
->text ("), ");
8525 return PRINT_SRC_AND_LOC
;
8529 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
8531 struct exec_catchpoint
*c
= (struct exec_catchpoint
*) b
;
8532 struct value_print_options opts
;
8533 struct ui_out
*uiout
= current_uiout
;
8535 get_user_print_options (&opts
);
8537 /* Field 4, the address, is omitted (which makes the columns
8538 not line up too nicely with the headers, but the effect
8539 is relatively readable). */
8540 if (opts
.addressprint
)
8541 uiout
->field_skip ("addr");
8543 uiout
->text ("exec");
8544 if (c
->exec_pathname
!= NULL
)
8546 uiout
->text (", program \"");
8547 uiout
->field_string ("what", c
->exec_pathname
);
8548 uiout
->text ("\" ");
8551 if (uiout
->is_mi_like_p ())
8552 uiout
->field_string ("catch-type", "exec");
8556 print_mention_catch_exec (struct breakpoint
*b
)
8558 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
8561 /* Implement the "print_recreate" breakpoint_ops method for exec
8565 print_recreate_catch_exec (struct breakpoint
*b
, struct ui_file
*fp
)
8567 fprintf_unfiltered (fp
, "catch exec");
8568 print_recreate_thread (b
, fp
);
8571 static struct breakpoint_ops catch_exec_breakpoint_ops
;
8574 hw_breakpoint_used_count (void)
8577 struct breakpoint
*b
;
8578 struct bp_location
*bl
;
8582 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
8583 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8585 /* Special types of hardware breakpoints may use more than
8587 i
+= b
->ops
->resources_needed (bl
);
8594 /* Returns the resources B would use if it were a hardware
8598 hw_watchpoint_use_count (struct breakpoint
*b
)
8601 struct bp_location
*bl
;
8603 if (!breakpoint_enabled (b
))
8606 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
8608 /* Special types of hardware watchpoints may use more than
8610 i
+= b
->ops
->resources_needed (bl
);
8616 /* Returns the sum the used resources of all hardware watchpoints of
8617 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED
8618 the sum of the used resources of all hardware watchpoints of other
8619 types _not_ TYPE. */
8622 hw_watchpoint_used_count_others (struct breakpoint
*except
,
8623 enum bptype type
, int *other_type_used
)
8626 struct breakpoint
*b
;
8628 *other_type_used
= 0;
8633 if (!breakpoint_enabled (b
))
8636 if (b
->type
== type
)
8637 i
+= hw_watchpoint_use_count (b
);
8638 else if (is_hardware_watchpoint (b
))
8639 *other_type_used
= 1;
8646 disable_watchpoints_before_interactive_call_start (void)
8648 struct breakpoint
*b
;
8652 if (is_watchpoint (b
) && breakpoint_enabled (b
))
8654 b
->enable_state
= bp_call_disabled
;
8655 update_global_location_list (UGLL_DONT_INSERT
);
8661 enable_watchpoints_after_interactive_call_stop (void)
8663 struct breakpoint
*b
;
8667 if (is_watchpoint (b
) && b
->enable_state
== bp_call_disabled
)
8669 b
->enable_state
= bp_enabled
;
8670 update_global_location_list (UGLL_MAY_INSERT
);
8676 disable_breakpoints_before_startup (void)
8678 current_program_space
->executing_startup
= 1;
8679 update_global_location_list (UGLL_DONT_INSERT
);
8683 enable_breakpoints_after_startup (void)
8685 current_program_space
->executing_startup
= 0;
8686 breakpoint_re_set ();
8689 /* Create a new single-step breakpoint for thread THREAD, with no
8692 static struct breakpoint
*
8693 new_single_step_breakpoint (int thread
, struct gdbarch
*gdbarch
)
8695 std::unique_ptr
<breakpoint
> b (new breakpoint ());
8697 init_raw_breakpoint_without_location (b
.get (), gdbarch
, bp_single_step
,
8698 &momentary_breakpoint_ops
);
8700 b
->disposition
= disp_donttouch
;
8701 b
->frame_id
= null_frame_id
;
8704 gdb_assert (b
->thread
!= 0);
8706 return add_to_breakpoint_chain (std::move (b
));
8709 /* Set a momentary breakpoint of type TYPE at address specified by
8710 SAL. If FRAME_ID is valid, the breakpoint is restricted to that
8714 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
8715 struct frame_id frame_id
, enum bptype type
)
8717 struct breakpoint
*b
;
8719 /* If FRAME_ID is valid, it should be a real frame, not an inlined or
8721 gdb_assert (!frame_id_artificial_p (frame_id
));
8723 b
= set_raw_breakpoint (gdbarch
, sal
, type
, &momentary_breakpoint_ops
);
8724 b
->enable_state
= bp_enabled
;
8725 b
->disposition
= disp_donttouch
;
8726 b
->frame_id
= frame_id
;
8728 /* If we're debugging a multi-threaded program, then we want
8729 momentary breakpoints to be active in only a single thread of
8731 if (in_thread_list (inferior_ptid
))
8732 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
8734 update_global_location_list_nothrow (UGLL_MAY_INSERT
);
8739 /* Make a momentary breakpoint based on the master breakpoint ORIG.
8740 The new breakpoint will have type TYPE, use OPS as its
8741 breakpoint_ops, and will set enabled to LOC_ENABLED. */
8743 static struct breakpoint
*
8744 momentary_breakpoint_from_master (struct breakpoint
*orig
,
8746 const struct breakpoint_ops
*ops
,
8749 struct breakpoint
*copy
;
8751 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, type
, ops
);
8752 copy
->loc
= allocate_bp_location (copy
);
8753 set_breakpoint_location_function (copy
->loc
, 1);
8755 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
8756 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
8757 copy
->loc
->address
= orig
->loc
->address
;
8758 copy
->loc
->section
= orig
->loc
->section
;
8759 copy
->loc
->pspace
= orig
->loc
->pspace
;
8760 copy
->loc
->probe
= orig
->loc
->probe
;
8761 copy
->loc
->line_number
= orig
->loc
->line_number
;
8762 copy
->loc
->symtab
= orig
->loc
->symtab
;
8763 copy
->loc
->enabled
= loc_enabled
;
8764 copy
->frame_id
= orig
->frame_id
;
8765 copy
->thread
= orig
->thread
;
8766 copy
->pspace
= orig
->pspace
;
8768 copy
->enable_state
= bp_enabled
;
8769 copy
->disposition
= disp_donttouch
;
8770 copy
->number
= internal_breakpoint_number
--;
8772 update_global_location_list_nothrow (UGLL_DONT_INSERT
);
8776 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
8780 clone_momentary_breakpoint (struct breakpoint
*orig
)
8782 /* If there's nothing to clone, then return nothing. */
8786 return momentary_breakpoint_from_master (orig
, orig
->type
, orig
->ops
, 0);
8790 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
8793 struct symtab_and_line sal
;
8795 sal
= find_pc_line (pc
, 0);
8797 sal
.section
= find_pc_overlay (pc
);
8798 sal
.explicit_pc
= 1;
8800 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
8804 /* Tell the user we have just set a breakpoint B. */
8807 mention (struct breakpoint
*b
)
8809 b
->ops
->print_mention (b
);
8810 if (current_uiout
->is_mi_like_p ())
8812 printf_filtered ("\n");
8816 static int bp_loc_is_permanent (struct bp_location
*loc
);
8818 static struct bp_location
*
8819 add_location_to_breakpoint (struct breakpoint
*b
,
8820 const struct symtab_and_line
*sal
)
8822 struct bp_location
*loc
, **tmp
;
8823 CORE_ADDR adjusted_address
;
8824 struct gdbarch
*loc_gdbarch
= get_sal_arch (*sal
);
8826 if (loc_gdbarch
== NULL
)
8827 loc_gdbarch
= b
->gdbarch
;
8829 /* Adjust the breakpoint's address prior to allocating a location.
8830 Once we call allocate_bp_location(), that mostly uninitialized
8831 location will be placed on the location chain. Adjustment of the
8832 breakpoint may cause target_read_memory() to be called and we do
8833 not want its scan of the location chain to find a breakpoint and
8834 location that's only been partially initialized. */
8835 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
,
8838 /* Sort the locations by their ADDRESS. */
8839 loc
= allocate_bp_location (b
);
8840 for (tmp
= &(b
->loc
); *tmp
!= NULL
&& (*tmp
)->address
<= adjusted_address
;
8841 tmp
= &((*tmp
)->next
))
8846 loc
->requested_address
= sal
->pc
;
8847 loc
->address
= adjusted_address
;
8848 loc
->pspace
= sal
->pspace
;
8849 loc
->probe
.probe
= sal
->probe
;
8850 loc
->probe
.objfile
= sal
->objfile
;
8851 gdb_assert (loc
->pspace
!= NULL
);
8852 loc
->section
= sal
->section
;
8853 loc
->gdbarch
= loc_gdbarch
;
8854 loc
->line_number
= sal
->line
;
8855 loc
->symtab
= sal
->symtab
;
8857 set_breakpoint_location_function (loc
,
8858 sal
->explicit_pc
|| sal
->explicit_line
);
8860 /* While by definition, permanent breakpoints are already present in the
8861 code, we don't mark the location as inserted. Normally one would expect
8862 that GDB could rely on that breakpoint instruction to stop the program,
8863 thus removing the need to insert its own breakpoint, except that executing
8864 the breakpoint instruction can kill the target instead of reporting a
8865 SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the
8866 instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies
8867 with "Trap 0x02 while interrupts disabled, Error state". Letting the
8868 breakpoint be inserted normally results in QEMU knowing about the GDB
8869 breakpoint, and thus trap before the breakpoint instruction is executed.
8870 (If GDB later needs to continue execution past the permanent breakpoint,
8871 it manually increments the PC, thus avoiding executing the breakpoint
8873 if (bp_loc_is_permanent (loc
))
8880 /* See breakpoint.h. */
8883 program_breakpoint_here_p (struct gdbarch
*gdbarch
, CORE_ADDR address
)
8887 const gdb_byte
*bpoint
;
8888 gdb_byte
*target_mem
;
8891 bpoint
= gdbarch_breakpoint_from_pc (gdbarch
, &addr
, &len
);
8893 /* Software breakpoints unsupported? */
8897 target_mem
= (gdb_byte
*) alloca (len
);
8899 /* Enable the automatic memory restoration from breakpoints while
8900 we read the memory. Otherwise we could say about our temporary
8901 breakpoints they are permanent. */
8902 scoped_restore restore_memory
8903 = make_scoped_restore_show_memory_breakpoints (0);
8905 if (target_read_memory (address
, target_mem
, len
) == 0
8906 && memcmp (target_mem
, bpoint
, len
) == 0)
8912 /* Return 1 if LOC is pointing to a permanent breakpoint,
8913 return 0 otherwise. */
8916 bp_loc_is_permanent (struct bp_location
*loc
)
8918 gdb_assert (loc
!= NULL
);
8920 /* If we have a catchpoint or a watchpoint, just return 0. We should not
8921 attempt to read from the addresses the locations of these breakpoint types
8922 point to. program_breakpoint_here_p, below, will attempt to read
8924 if (!breakpoint_address_is_meaningful (loc
->owner
))
8927 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
8928 switch_to_program_space_and_thread (loc
->pspace
);
8929 return program_breakpoint_here_p (loc
->gdbarch
, loc
->address
);
8932 /* Build a command list for the dprintf corresponding to the current
8933 settings of the dprintf style options. */
8936 update_dprintf_command_list (struct breakpoint
*b
)
8938 char *dprintf_args
= b
->extra_string
;
8939 char *printf_line
= NULL
;
8944 dprintf_args
= skip_spaces (dprintf_args
);
8946 /* Allow a comma, as it may have terminated a location, but don't
8948 if (*dprintf_args
== ',')
8950 dprintf_args
= skip_spaces (dprintf_args
);
8952 if (*dprintf_args
!= '"')
8953 error (_("Bad format string, missing '\"'."));
8955 if (strcmp (dprintf_style
, dprintf_style_gdb
) == 0)
8956 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8957 else if (strcmp (dprintf_style
, dprintf_style_call
) == 0)
8959 if (!dprintf_function
)
8960 error (_("No function supplied for dprintf call"));
8962 if (dprintf_channel
&& strlen (dprintf_channel
) > 0)
8963 printf_line
= xstrprintf ("call (void) %s (%s,%s)",
8968 printf_line
= xstrprintf ("call (void) %s (%s)",
8972 else if (strcmp (dprintf_style
, dprintf_style_agent
) == 0)
8974 if (target_can_run_breakpoint_commands ())
8975 printf_line
= xstrprintf ("agent-printf %s", dprintf_args
);
8978 warning (_("Target cannot run dprintf commands, falling back to GDB printf"));
8979 printf_line
= xstrprintf ("printf %s", dprintf_args
);
8983 internal_error (__FILE__
, __LINE__
,
8984 _("Invalid dprintf style."));
8986 gdb_assert (printf_line
!= NULL
);
8987 /* Manufacture a printf sequence. */
8989 struct command_line
*printf_cmd_line
= XNEW (struct command_line
);
8991 printf_cmd_line
->control_type
= simple_control
;
8992 printf_cmd_line
->body_count
= 0;
8993 printf_cmd_line
->body_list
= NULL
;
8994 printf_cmd_line
->next
= NULL
;
8995 printf_cmd_line
->line
= printf_line
;
8997 breakpoint_set_commands (b
, command_line_up (printf_cmd_line
));
9001 /* Update all dprintf commands, making their command lists reflect
9002 current style settings. */
9005 update_dprintf_commands (char *args
, int from_tty
,
9006 struct cmd_list_element
*c
)
9008 struct breakpoint
*b
;
9012 if (b
->type
== bp_dprintf
)
9013 update_dprintf_command_list (b
);
9017 /* Create a breakpoint with SAL as location. Use LOCATION
9018 as a description of the location, and COND_STRING
9019 as condition expression. If LOCATION is NULL then create an
9020 "address location" from the address in the SAL. */
9023 init_breakpoint_sal (struct breakpoint
*b
, struct gdbarch
*gdbarch
,
9024 gdb::array_view
<const symtab_and_line
> sals
,
9025 event_location_up
&&location
,
9026 gdb::unique_xmalloc_ptr
<char> filter
,
9027 gdb::unique_xmalloc_ptr
<char> cond_string
,
9028 gdb::unique_xmalloc_ptr
<char> extra_string
,
9029 enum bptype type
, enum bpdisp disposition
,
9030 int thread
, int task
, int ignore_count
,
9031 const struct breakpoint_ops
*ops
, int from_tty
,
9032 int enabled
, int internal
, unsigned flags
,
9033 int display_canonical
)
9037 if (type
== bp_hardware_breakpoint
)
9039 int target_resources_ok
;
9041 i
= hw_breakpoint_used_count ();
9042 target_resources_ok
=
9043 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9045 if (target_resources_ok
== 0)
9046 error (_("No hardware breakpoint support in the target."));
9047 else if (target_resources_ok
< 0)
9048 error (_("Hardware breakpoints used exceeds limit."));
9051 gdb_assert (!sals
.empty ());
9053 for (const auto &sal
: sals
)
9055 struct bp_location
*loc
;
9059 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
9061 loc_gdbarch
= gdbarch
;
9063 describe_other_breakpoints (loc_gdbarch
,
9064 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
9067 if (&sal
== &sals
[0])
9069 init_raw_breakpoint (b
, gdbarch
, sal
, type
, ops
);
9073 b
->cond_string
= cond_string
.release ();
9074 b
->extra_string
= extra_string
.release ();
9075 b
->ignore_count
= ignore_count
;
9076 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9077 b
->disposition
= disposition
;
9079 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9080 b
->loc
->inserted
= 1;
9082 if (type
== bp_static_tracepoint
)
9084 struct tracepoint
*t
= (struct tracepoint
*) b
;
9085 struct static_tracepoint_marker marker
;
9087 if (strace_marker_p (b
))
9089 /* We already know the marker exists, otherwise, we
9090 wouldn't see a sal for it. */
9092 = &event_location_to_string (b
->location
.get ())[3];
9096 p
= skip_spaces (p
);
9098 endp
= skip_to_space (p
);
9100 marker_str
= savestring (p
, endp
- p
);
9101 t
->static_trace_marker_id
= marker_str
;
9103 printf_filtered (_("Probed static tracepoint "
9105 t
->static_trace_marker_id
);
9107 else if (target_static_tracepoint_marker_at (sal
.pc
, &marker
))
9109 t
->static_trace_marker_id
= xstrdup (marker
.str_id
);
9110 release_static_tracepoint_marker (&marker
);
9112 printf_filtered (_("Probed static tracepoint "
9114 t
->static_trace_marker_id
);
9117 warning (_("Couldn't determine the static "
9118 "tracepoint marker to probe"));
9125 loc
= add_location_to_breakpoint (b
, &sal
);
9126 if ((flags
& CREATE_BREAKPOINT_FLAGS_INSERTED
) != 0)
9132 const char *arg
= b
->cond_string
;
9134 loc
->cond
= parse_exp_1 (&arg
, loc
->address
,
9135 block_for_pc (loc
->address
), 0);
9137 error (_("Garbage '%s' follows condition"), arg
);
9140 /* Dynamic printf requires and uses additional arguments on the
9141 command line, otherwise it's an error. */
9142 if (type
== bp_dprintf
)
9144 if (b
->extra_string
)
9145 update_dprintf_command_list (b
);
9147 error (_("Format string required"));
9149 else if (b
->extra_string
)
9150 error (_("Garbage '%s' at end of command"), b
->extra_string
);
9153 b
->display_canonical
= display_canonical
;
9154 if (location
!= NULL
)
9155 b
->location
= std::move (location
);
9157 b
->location
= new_address_location (b
->loc
->address
, NULL
, 0);
9158 b
->filter
= filter
.release ();
9162 create_breakpoint_sal (struct gdbarch
*gdbarch
,
9163 gdb::array_view
<const symtab_and_line
> sals
,
9164 event_location_up
&&location
,
9165 gdb::unique_xmalloc_ptr
<char> filter
,
9166 gdb::unique_xmalloc_ptr
<char> cond_string
,
9167 gdb::unique_xmalloc_ptr
<char> extra_string
,
9168 enum bptype type
, enum bpdisp disposition
,
9169 int thread
, int task
, int ignore_count
,
9170 const struct breakpoint_ops
*ops
, int from_tty
,
9171 int enabled
, int internal
, unsigned flags
,
9172 int display_canonical
)
9174 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type
);
9176 init_breakpoint_sal (b
.get (), gdbarch
,
9177 sals
, std::move (location
),
9179 std::move (cond_string
),
9180 std::move (extra_string
),
9182 thread
, task
, ignore_count
,
9184 enabled
, internal
, flags
,
9187 install_breakpoint (internal
, std::move (b
), 0);
9190 /* Add SALS.nelts breakpoints to the breakpoint table. For each
9191 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
9192 value. COND_STRING, if not NULL, specified the condition to be
9193 used for all breakpoints. Essentially the only case where
9194 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
9195 function. In that case, it's still not possible to specify
9196 separate conditions for different overloaded functions, so
9197 we take just a single condition string.
9199 NOTE: If the function succeeds, the caller is expected to cleanup
9200 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
9201 array contents). If the function fails (error() is called), the
9202 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
9203 COND and SALS arrays and each of those arrays contents. */
9206 create_breakpoints_sal (struct gdbarch
*gdbarch
,
9207 struct linespec_result
*canonical
,
9208 gdb::unique_xmalloc_ptr
<char> cond_string
,
9209 gdb::unique_xmalloc_ptr
<char> extra_string
,
9210 enum bptype type
, enum bpdisp disposition
,
9211 int thread
, int task
, int ignore_count
,
9212 const struct breakpoint_ops
*ops
, int from_tty
,
9213 int enabled
, int internal
, unsigned flags
)
9215 if (canonical
->pre_expanded
)
9216 gdb_assert (canonical
->lsals
.size () == 1);
9218 for (const auto &lsal
: canonical
->lsals
)
9220 /* Note that 'location' can be NULL in the case of a plain
9221 'break', without arguments. */
9222 event_location_up location
9223 = (canonical
->location
!= NULL
9224 ? copy_event_location (canonical
->location
.get ()) : NULL
);
9225 gdb::unique_xmalloc_ptr
<char> filter_string
9226 (lsal
.canonical
!= NULL
? xstrdup (lsal
.canonical
) : NULL
);
9228 create_breakpoint_sal (gdbarch
, lsal
.sals
,
9229 std::move (location
),
9230 std::move (filter_string
),
9231 std::move (cond_string
),
9232 std::move (extra_string
),
9234 thread
, task
, ignore_count
, ops
,
9235 from_tty
, enabled
, internal
, flags
,
9236 canonical
->special_display
);
9240 /* Parse LOCATION which is assumed to be a SAL specification possibly
9241 followed by conditionals. On return, SALS contains an array of SAL
9242 addresses found. LOCATION points to the end of the SAL (for
9243 linespec locations).
9245 The array and the line spec strings are allocated on the heap, it is
9246 the caller's responsibility to free them. */
9249 parse_breakpoint_sals (const struct event_location
*location
,
9250 struct linespec_result
*canonical
)
9252 struct symtab_and_line cursal
;
9254 if (event_location_type (location
) == LINESPEC_LOCATION
)
9256 const char *address
= get_linespec_location (location
);
9258 if (address
== NULL
)
9260 /* The last displayed codepoint, if it's valid, is our default
9261 breakpoint address. */
9262 if (last_displayed_sal_is_valid ())
9264 /* Set sal's pspace, pc, symtab, and line to the values
9265 corresponding to the last call to print_frame_info.
9266 Be sure to reinitialize LINE with NOTCURRENT == 0
9267 as the breakpoint line number is inappropriate otherwise.
9268 find_pc_line would adjust PC, re-set it back. */
9269 symtab_and_line sal
= get_last_displayed_sal ();
9270 CORE_ADDR pc
= sal
.pc
;
9272 sal
= find_pc_line (pc
, 0);
9274 /* "break" without arguments is equivalent to "break *PC"
9275 where PC is the last displayed codepoint's address. So
9276 make sure to set sal.explicit_pc to prevent GDB from
9277 trying to expand the list of sals to include all other
9278 instances with the same symtab and line. */
9280 sal
.explicit_pc
= 1;
9282 struct linespec_sals lsal
;
9284 lsal
.canonical
= NULL
;
9286 canonical
->lsals
.push_back (std::move (lsal
));
9290 error (_("No default breakpoint address now."));
9294 /* Force almost all breakpoints to be in terms of the
9295 current_source_symtab (which is decode_line_1's default).
9296 This should produce the results we want almost all of the
9297 time while leaving default_breakpoint_* alone.
9299 ObjC: However, don't match an Objective-C method name which
9300 may have a '+' or '-' succeeded by a '['. */
9301 cursal
= get_current_source_symtab_and_line ();
9302 if (last_displayed_sal_is_valid ())
9304 const char *address
= NULL
;
9306 if (event_location_type (location
) == LINESPEC_LOCATION
)
9307 address
= get_linespec_location (location
);
9311 && strchr ("+-", address
[0]) != NULL
9312 && address
[1] != '['))
9314 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9315 get_last_displayed_symtab (),
9316 get_last_displayed_line (),
9317 canonical
, NULL
, NULL
);
9322 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
,
9323 cursal
.symtab
, cursal
.line
, canonical
, NULL
, NULL
);
9327 /* Convert each SAL into a real PC. Verify that the PC can be
9328 inserted as a breakpoint. If it can't throw an error. */
9331 breakpoint_sals_to_pc (std::vector
<symtab_and_line
> &sals
)
9333 for (auto &sal
: sals
)
9334 resolve_sal_pc (&sal
);
9337 /* Fast tracepoints may have restrictions on valid locations. For
9338 instance, a fast tracepoint using a jump instead of a trap will
9339 likely have to overwrite more bytes than a trap would, and so can
9340 only be placed where the instruction is longer than the jump, or a
9341 multi-instruction sequence does not have a jump into the middle of
9345 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
9346 gdb::array_view
<const symtab_and_line
> sals
)
9350 struct cleanup
*old_chain
;
9352 for (const auto &sal
: sals
)
9354 struct gdbarch
*sarch
;
9356 sarch
= get_sal_arch (sal
);
9357 /* We fall back to GDBARCH if there is no architecture
9358 associated with SAL. */
9361 rslt
= gdbarch_fast_tracepoint_valid_at (sarch
, sal
.pc
, &msg
);
9362 old_chain
= make_cleanup (xfree
, msg
);
9365 error (_("May not have a fast tracepoint at %s%s"),
9366 paddress (sarch
, sal
.pc
), (msg
? msg
: ""));
9368 do_cleanups (old_chain
);
9372 /* Given TOK, a string specification of condition and thread, as
9373 accepted by the 'break' command, extract the condition
9374 string and thread number and set *COND_STRING and *THREAD.
9375 PC identifies the context at which the condition should be parsed.
9376 If no condition is found, *COND_STRING is set to NULL.
9377 If no thread is found, *THREAD is set to -1. */
9380 find_condition_and_thread (const char *tok
, CORE_ADDR pc
,
9381 char **cond_string
, int *thread
, int *task
,
9384 *cond_string
= NULL
;
9391 const char *end_tok
;
9393 const char *cond_start
= NULL
;
9394 const char *cond_end
= NULL
;
9396 tok
= skip_spaces (tok
);
9398 if ((*tok
== '"' || *tok
== ',') && rest
)
9400 *rest
= savestring (tok
, strlen (tok
));
9404 end_tok
= skip_to_space (tok
);
9406 toklen
= end_tok
- tok
;
9408 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
9410 tok
= cond_start
= end_tok
+ 1;
9411 parse_exp_1 (&tok
, pc
, block_for_pc (pc
), 0);
9413 *cond_string
= savestring (cond_start
, cond_end
- cond_start
);
9415 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
9418 struct thread_info
*thr
;
9421 thr
= parse_thread_id (tok
, &tmptok
);
9423 error (_("Junk after thread keyword."));
9424 *thread
= thr
->global_num
;
9427 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
9432 *task
= strtol (tok
, &tmptok
, 0);
9434 error (_("Junk after task keyword."));
9435 if (!valid_task_id (*task
))
9436 error (_("Unknown task %d."), *task
);
9441 *rest
= savestring (tok
, strlen (tok
));
9445 error (_("Junk at end of arguments."));
9449 /* Decode a static tracepoint marker spec. */
9451 static std::vector
<symtab_and_line
>
9452 decode_static_tracepoint_spec (const char **arg_p
)
9454 VEC(static_tracepoint_marker_p
) *markers
= NULL
;
9455 struct cleanup
*old_chain
;
9456 const char *p
= &(*arg_p
)[3];
9461 p
= skip_spaces (p
);
9463 endp
= skip_to_space (p
);
9465 marker_str
= savestring (p
, endp
- p
);
9466 old_chain
= make_cleanup (xfree
, marker_str
);
9468 markers
= target_static_tracepoint_markers_by_strid (marker_str
);
9469 if (VEC_empty(static_tracepoint_marker_p
, markers
))
9470 error (_("No known static tracepoint marker named %s"), marker_str
);
9472 std::vector
<symtab_and_line
> sals
;
9473 sals
.reserve (VEC_length(static_tracepoint_marker_p
, markers
));
9475 for (i
= 0; i
< VEC_length(static_tracepoint_marker_p
, markers
); i
++)
9477 struct static_tracepoint_marker
*marker
;
9479 marker
= VEC_index (static_tracepoint_marker_p
, markers
, i
);
9481 symtab_and_line sal
= find_pc_line (marker
->address
, 0);
9482 sal
.pc
= marker
->address
;
9483 sals
.push_back (sal
);
9485 release_static_tracepoint_marker (marker
);
9488 do_cleanups (old_chain
);
9494 /* See breakpoint.h. */
9497 create_breakpoint (struct gdbarch
*gdbarch
,
9498 const struct event_location
*location
,
9499 const char *cond_string
,
9500 int thread
, const char *extra_string
,
9502 int tempflag
, enum bptype type_wanted
,
9504 enum auto_boolean pending_break_support
,
9505 const struct breakpoint_ops
*ops
,
9506 int from_tty
, int enabled
, int internal
,
9509 struct linespec_result canonical
;
9510 struct cleanup
*bkpt_chain
= NULL
;
9513 int prev_bkpt_count
= breakpoint_count
;
9515 gdb_assert (ops
!= NULL
);
9517 /* If extra_string isn't useful, set it to NULL. */
9518 if (extra_string
!= NULL
&& *extra_string
== '\0')
9519 extra_string
= NULL
;
9523 ops
->create_sals_from_location (location
, &canonical
, type_wanted
);
9525 CATCH (e
, RETURN_MASK_ERROR
)
9527 /* If caller is interested in rc value from parse, set
9529 if (e
.error
== NOT_FOUND_ERROR
)
9531 /* If pending breakpoint support is turned off, throw
9534 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
9535 throw_exception (e
);
9537 exception_print (gdb_stderr
, e
);
9539 /* If pending breakpoint support is auto query and the user
9540 selects no, then simply return the error code. */
9541 if (pending_break_support
== AUTO_BOOLEAN_AUTO
9542 && !nquery (_("Make %s pending on future shared library load? "),
9543 bptype_string (type_wanted
)))
9546 /* At this point, either the user was queried about setting
9547 a pending breakpoint and selected yes, or pending
9548 breakpoint behavior is on and thus a pending breakpoint
9549 is defaulted on behalf of the user. */
9553 throw_exception (e
);
9557 if (!pending
&& canonical
.lsals
.empty ())
9560 /* ----------------------------- SNIP -----------------------------
9561 Anything added to the cleanup chain beyond this point is assumed
9562 to be part of a breakpoint. If the breakpoint create succeeds
9563 then the memory is not reclaimed. */
9564 bkpt_chain
= make_cleanup (null_cleanup
, 0);
9566 /* Resolve all line numbers to PC's and verify that the addresses
9567 are ok for the target. */
9570 for (auto &lsal
: canonical
.lsals
)
9571 breakpoint_sals_to_pc (lsal
.sals
);
9574 /* Fast tracepoints may have additional restrictions on location. */
9575 if (!pending
&& type_wanted
== bp_fast_tracepoint
)
9577 for (const auto &lsal
: canonical
.lsals
)
9578 check_fast_tracepoint_sals (gdbarch
, lsal
.sals
);
9581 /* Verify that condition can be parsed, before setting any
9582 breakpoints. Allocate a separate condition expression for each
9586 gdb::unique_xmalloc_ptr
<char> cond_string_copy
;
9587 gdb::unique_xmalloc_ptr
<char> extra_string_copy
;
9594 const linespec_sals
&lsal
= canonical
.lsals
[0];
9596 /* Here we only parse 'arg' to separate condition
9597 from thread number, so parsing in context of first
9598 sal is OK. When setting the breakpoint we'll
9599 re-parse it in context of each sal. */
9601 find_condition_and_thread (extra_string
, lsal
.sals
[0].pc
,
9602 &cond
, &thread
, &task
, &rest
);
9603 cond_string_copy
.reset (cond
);
9604 extra_string_copy
.reset (rest
);
9608 if (type_wanted
!= bp_dprintf
9609 && extra_string
!= NULL
&& *extra_string
!= '\0')
9610 error (_("Garbage '%s' at end of location"), extra_string
);
9612 /* Create a private copy of condition string. */
9614 cond_string_copy
.reset (xstrdup (cond_string
));
9615 /* Create a private copy of any extra string. */
9617 extra_string_copy
.reset (xstrdup (extra_string
));
9620 ops
->create_breakpoints_sal (gdbarch
, &canonical
,
9621 std::move (cond_string_copy
),
9622 std::move (extra_string_copy
),
9624 tempflag
? disp_del
: disp_donttouch
,
9625 thread
, task
, ignore_count
, ops
,
9626 from_tty
, enabled
, internal
, flags
);
9630 std::unique_ptr
<breakpoint
> b
= new_breakpoint_from_type (type_wanted
);
9632 init_raw_breakpoint_without_location (b
.get (), gdbarch
, type_wanted
, ops
);
9633 b
->location
= copy_event_location (location
);
9636 b
->cond_string
= NULL
;
9639 /* Create a private copy of condition string. */
9640 b
->cond_string
= cond_string
!= NULL
? xstrdup (cond_string
) : NULL
;
9644 /* Create a private copy of any extra string. */
9645 b
->extra_string
= extra_string
!= NULL
? xstrdup (extra_string
) : NULL
;
9646 b
->ignore_count
= ignore_count
;
9647 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
9648 b
->condition_not_parsed
= 1;
9649 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
9650 if ((type_wanted
!= bp_breakpoint
9651 && type_wanted
!= bp_hardware_breakpoint
) || thread
!= -1)
9652 b
->pspace
= current_program_space
;
9654 install_breakpoint (internal
, std::move (b
), 0);
9657 if (canonical
.lsals
.size () > 1)
9659 warning (_("Multiple breakpoints were set.\nUse the "
9660 "\"delete\" command to delete unwanted breakpoints."));
9661 prev_breakpoint_count
= prev_bkpt_count
;
9664 /* That's it. Discard the cleanups for data inserted into the
9666 discard_cleanups (bkpt_chain
);
9668 /* error call may happen here - have BKPT_CHAIN already discarded. */
9669 update_global_location_list (UGLL_MAY_INSERT
);
9674 /* Set a breakpoint.
9675 ARG is a string describing breakpoint address,
9676 condition, and thread.
9677 FLAG specifies if a breakpoint is hardware on,
9678 and if breakpoint is temporary, using BP_HARDWARE_FLAG
9682 break_command_1 (char *arg
, int flag
, int from_tty
)
9684 int tempflag
= flag
& BP_TEMPFLAG
;
9685 enum bptype type_wanted
= (flag
& BP_HARDWAREFLAG
9686 ? bp_hardware_breakpoint
9688 struct breakpoint_ops
*ops
;
9690 event_location_up location
= string_to_event_location (&arg
, current_language
);
9692 /* Matching breakpoints on probes. */
9693 if (location
!= NULL
9694 && event_location_type (location
.get ()) == PROBE_LOCATION
)
9695 ops
= &bkpt_probe_breakpoint_ops
;
9697 ops
= &bkpt_breakpoint_ops
;
9699 create_breakpoint (get_current_arch (),
9701 NULL
, 0, arg
, 1 /* parse arg */,
9702 tempflag
, type_wanted
,
9703 0 /* Ignore count */,
9704 pending_break_support
,
9712 /* Helper function for break_command_1 and disassemble_command. */
9715 resolve_sal_pc (struct symtab_and_line
*sal
)
9719 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
9721 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
9722 error (_("No line %d in file \"%s\"."),
9723 sal
->line
, symtab_to_filename_for_display (sal
->symtab
));
9726 /* If this SAL corresponds to a breakpoint inserted using a line
9727 number, then skip the function prologue if necessary. */
9728 if (sal
->explicit_line
)
9729 skip_prologue_sal (sal
);
9732 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
9734 const struct blockvector
*bv
;
9735 const struct block
*b
;
9738 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
,
9739 SYMTAB_COMPUNIT (sal
->symtab
));
9742 sym
= block_linkage_function (b
);
9745 fixup_symbol_section (sym
, SYMTAB_OBJFILE (sal
->symtab
));
9746 sal
->section
= SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal
->symtab
),
9751 /* It really is worthwhile to have the section, so we'll
9752 just have to look harder. This case can be executed
9753 if we have line numbers but no functions (as can
9754 happen in assembly source). */
9756 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
9757 switch_to_program_space_and_thread (sal
->pspace
);
9759 bound_minimal_symbol msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
9761 sal
->section
= MSYMBOL_OBJ_SECTION (msym
.objfile
, msym
.minsym
);
9768 break_command (char *arg
, int from_tty
)
9770 break_command_1 (arg
, 0, from_tty
);
9774 tbreak_command (char *arg
, int from_tty
)
9776 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
9780 hbreak_command (char *arg
, int from_tty
)
9782 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
9786 thbreak_command (char *arg
, int from_tty
)
9788 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
9792 stop_command (char *arg
, int from_tty
)
9794 printf_filtered (_("Specify the type of breakpoint to set.\n\
9795 Usage: stop in <function | address>\n\
9796 stop at <line>\n"));
9800 stopin_command (char *arg
, int from_tty
)
9804 if (arg
== (char *) NULL
)
9806 else if (*arg
!= '*')
9811 /* Look for a ':'. If this is a line number specification, then
9812 say it is bad, otherwise, it should be an address or
9813 function/method name. */
9814 while (*argptr
&& !hasColon
)
9816 hasColon
= (*argptr
== ':');
9821 badInput
= (*argptr
!= ':'); /* Not a class::method */
9823 badInput
= isdigit (*arg
); /* a simple line number */
9827 printf_filtered (_("Usage: stop in <function | address>\n"));
9829 break_command_1 (arg
, 0, from_tty
);
9833 stopat_command (char *arg
, int from_tty
)
9837 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
9844 /* Look for a ':'. If there is a '::' then get out, otherwise
9845 it is probably a line number. */
9846 while (*argptr
&& !hasColon
)
9848 hasColon
= (*argptr
== ':');
9853 badInput
= (*argptr
== ':'); /* we have class::method */
9855 badInput
= !isdigit (*arg
); /* not a line number */
9859 printf_filtered (_("Usage: stop at <line>\n"));
9861 break_command_1 (arg
, 0, from_tty
);
9864 /* The dynamic printf command is mostly like a regular breakpoint, but
9865 with a prewired command list consisting of a single output command,
9866 built from extra arguments supplied on the dprintf command
9870 dprintf_command (char *arg
, int from_tty
)
9872 event_location_up location
= string_to_event_location (&arg
, current_language
);
9874 /* If non-NULL, ARG should have been advanced past the location;
9875 the next character must be ','. */
9878 if (arg
[0] != ',' || arg
[1] == '\0')
9879 error (_("Format string required"));
9882 /* Skip the comma. */
9887 create_breakpoint (get_current_arch (),
9889 NULL
, 0, arg
, 1 /* parse arg */,
9891 0 /* Ignore count */,
9892 pending_break_support
,
9893 &dprintf_breakpoint_ops
,
9901 agent_printf_command (char *arg
, int from_tty
)
9903 error (_("May only run agent-printf on the target"));
9906 /* Implement the "breakpoint_hit" breakpoint_ops method for
9907 ranged breakpoints. */
9910 breakpoint_hit_ranged_breakpoint (const struct bp_location
*bl
,
9911 struct address_space
*aspace
,
9913 const struct target_waitstatus
*ws
)
9915 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
9916 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
9919 return breakpoint_address_match_range (bl
->pspace
->aspace
, bl
->address
,
9920 bl
->length
, aspace
, bp_addr
);
9923 /* Implement the "resources_needed" breakpoint_ops method for
9924 ranged breakpoints. */
9927 resources_needed_ranged_breakpoint (const struct bp_location
*bl
)
9929 return target_ranged_break_num_registers ();
9932 /* Implement the "print_it" breakpoint_ops method for
9933 ranged breakpoints. */
9935 static enum print_stop_action
9936 print_it_ranged_breakpoint (bpstat bs
)
9938 struct breakpoint
*b
= bs
->breakpoint_at
;
9939 struct bp_location
*bl
= b
->loc
;
9940 struct ui_out
*uiout
= current_uiout
;
9942 gdb_assert (b
->type
== bp_hardware_breakpoint
);
9944 /* Ranged breakpoints have only one location. */
9945 gdb_assert (bl
&& bl
->next
== NULL
);
9947 annotate_breakpoint (b
->number
);
9949 maybe_print_thread_hit_breakpoint (uiout
);
9951 if (b
->disposition
== disp_del
)
9952 uiout
->text ("Temporary ranged breakpoint ");
9954 uiout
->text ("Ranged breakpoint ");
9955 if (uiout
->is_mi_like_p ())
9957 uiout
->field_string ("reason",
9958 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
9959 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
9961 uiout
->field_int ("bkptno", b
->number
);
9964 return PRINT_SRC_AND_LOC
;
9967 /* Implement the "print_one" breakpoint_ops method for
9968 ranged breakpoints. */
9971 print_one_ranged_breakpoint (struct breakpoint
*b
,
9972 struct bp_location
**last_loc
)
9974 struct bp_location
*bl
= b
->loc
;
9975 struct value_print_options opts
;
9976 struct ui_out
*uiout
= current_uiout
;
9978 /* Ranged breakpoints have only one location. */
9979 gdb_assert (bl
&& bl
->next
== NULL
);
9981 get_user_print_options (&opts
);
9983 if (opts
.addressprint
)
9984 /* We don't print the address range here, it will be printed later
9985 by print_one_detail_ranged_breakpoint. */
9986 uiout
->field_skip ("addr");
9988 print_breakpoint_location (b
, bl
);
9992 /* Implement the "print_one_detail" breakpoint_ops method for
9993 ranged breakpoints. */
9996 print_one_detail_ranged_breakpoint (const struct breakpoint
*b
,
9997 struct ui_out
*uiout
)
9999 CORE_ADDR address_start
, address_end
;
10000 struct bp_location
*bl
= b
->loc
;
10005 address_start
= bl
->address
;
10006 address_end
= address_start
+ bl
->length
- 1;
10008 uiout
->text ("\taddress range: ");
10009 stb
.printf ("[%s, %s]",
10010 print_core_address (bl
->gdbarch
, address_start
),
10011 print_core_address (bl
->gdbarch
, address_end
));
10012 uiout
->field_stream ("addr", stb
);
10013 uiout
->text ("\n");
10016 /* Implement the "print_mention" breakpoint_ops method for
10017 ranged breakpoints. */
10020 print_mention_ranged_breakpoint (struct breakpoint
*b
)
10022 struct bp_location
*bl
= b
->loc
;
10023 struct ui_out
*uiout
= current_uiout
;
10026 gdb_assert (b
->type
== bp_hardware_breakpoint
);
10028 if (uiout
->is_mi_like_p ())
10031 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."),
10032 b
->number
, paddress (bl
->gdbarch
, bl
->address
),
10033 paddress (bl
->gdbarch
, bl
->address
+ bl
->length
- 1));
10036 /* Implement the "print_recreate" breakpoint_ops method for
10037 ranged breakpoints. */
10040 print_recreate_ranged_breakpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10042 fprintf_unfiltered (fp
, "break-range %s, %s",
10043 event_location_to_string (b
->location
.get ()),
10044 event_location_to_string (b
->location_range_end
.get ()));
10045 print_recreate_thread (b
, fp
);
10048 /* The breakpoint_ops structure to be used in ranged breakpoints. */
10050 static struct breakpoint_ops ranged_breakpoint_ops
;
10052 /* Find the address where the end of the breakpoint range should be
10053 placed, given the SAL of the end of the range. This is so that if
10054 the user provides a line number, the end of the range is set to the
10055 last instruction of the given line. */
10058 find_breakpoint_range_end (struct symtab_and_line sal
)
10062 /* If the user provided a PC value, use it. Otherwise,
10063 find the address of the end of the given location. */
10064 if (sal
.explicit_pc
)
10071 ret
= find_line_pc_range (sal
, &start
, &end
);
10073 error (_("Could not find location of the end of the range."));
10075 /* find_line_pc_range returns the start of the next line. */
10082 /* Implement the "break-range" CLI command. */
10085 break_range_command (char *arg
, int from_tty
)
10087 char *arg_start
, *addr_string_start
;
10088 struct linespec_result canonical_start
, canonical_end
;
10089 int bp_count
, can_use_bp
, length
;
10091 struct breakpoint
*b
;
10092 struct cleanup
*cleanup_bkpt
;
10094 /* We don't support software ranged breakpoints. */
10095 if (target_ranged_break_num_registers () < 0)
10096 error (_("This target does not support hardware ranged breakpoints."));
10098 bp_count
= hw_breakpoint_used_count ();
10099 bp_count
+= target_ranged_break_num_registers ();
10100 can_use_bp
= target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
10102 if (can_use_bp
< 0)
10103 error (_("Hardware breakpoints used exceeds limit."));
10105 arg
= skip_spaces (arg
);
10106 if (arg
== NULL
|| arg
[0] == '\0')
10107 error(_("No address range specified."));
10110 event_location_up start_location
= string_to_event_location (&arg
,
10112 parse_breakpoint_sals (start_location
.get (), &canonical_start
);
10115 error (_("Too few arguments."));
10116 else if (canonical_start
.lsals
.empty ())
10117 error (_("Could not find location of the beginning of the range."));
10119 const linespec_sals
&lsal_start
= canonical_start
.lsals
[0];
10121 if (canonical_start
.lsals
.size () > 1
10122 || lsal_start
.sals
.size () != 1)
10123 error (_("Cannot create a ranged breakpoint with multiple locations."));
10125 const symtab_and_line
&sal_start
= lsal_start
.sals
[0];
10126 addr_string_start
= savestring (arg_start
, arg
- arg_start
);
10127 cleanup_bkpt
= make_cleanup (xfree
, addr_string_start
);
10129 arg
++; /* Skip the comma. */
10130 arg
= skip_spaces (arg
);
10132 /* Parse the end location. */
10136 /* We call decode_line_full directly here instead of using
10137 parse_breakpoint_sals because we need to specify the start location's
10138 symtab and line as the default symtab and line for the end of the
10139 range. This makes it possible to have ranges like "foo.c:27, +14",
10140 where +14 means 14 lines from the start location. */
10141 event_location_up end_location
= string_to_event_location (&arg
,
10143 decode_line_full (end_location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
10144 sal_start
.symtab
, sal_start
.line
,
10145 &canonical_end
, NULL
, NULL
);
10147 if (canonical_end
.lsals
.empty ())
10148 error (_("Could not find location of the end of the range."));
10150 const linespec_sals
&lsal_end
= canonical_end
.lsals
[0];
10151 if (canonical_end
.lsals
.size () > 1
10152 || lsal_end
.sals
.size () != 1)
10153 error (_("Cannot create a ranged breakpoint with multiple locations."));
10155 const symtab_and_line
&sal_end
= lsal_end
.sals
[0];
10157 end
= find_breakpoint_range_end (sal_end
);
10158 if (sal_start
.pc
> end
)
10159 error (_("Invalid address range, end precedes start."));
10161 length
= end
- sal_start
.pc
+ 1;
10163 /* Length overflowed. */
10164 error (_("Address range too large."));
10165 else if (length
== 1)
10167 /* This range is simple enough to be handled by
10168 the `hbreak' command. */
10169 hbreak_command (addr_string_start
, 1);
10171 do_cleanups (cleanup_bkpt
);
10176 /* Now set up the breakpoint. */
10177 b
= set_raw_breakpoint (get_current_arch (), sal_start
,
10178 bp_hardware_breakpoint
, &ranged_breakpoint_ops
);
10179 set_breakpoint_count (breakpoint_count
+ 1);
10180 b
->number
= breakpoint_count
;
10181 b
->disposition
= disp_donttouch
;
10182 b
->location
= std::move (start_location
);
10183 b
->location_range_end
= std::move (end_location
);
10184 b
->loc
->length
= length
;
10186 do_cleanups (cleanup_bkpt
);
10189 observer_notify_breakpoint_created (b
);
10190 update_global_location_list (UGLL_MAY_INSERT
);
10193 /* Return non-zero if EXP is verified as constant. Returned zero
10194 means EXP is variable. Also the constant detection may fail for
10195 some constant expressions and in such case still falsely return
10199 watchpoint_exp_is_const (const struct expression
*exp
)
10201 int i
= exp
->nelts
;
10207 /* We are only interested in the descriptor of each element. */
10208 operator_length (exp
, i
, &oplenp
, &argsp
);
10211 switch (exp
->elts
[i
].opcode
)
10221 case BINOP_LOGICAL_AND
:
10222 case BINOP_LOGICAL_OR
:
10223 case BINOP_BITWISE_AND
:
10224 case BINOP_BITWISE_IOR
:
10225 case BINOP_BITWISE_XOR
:
10227 case BINOP_NOTEQUAL
:
10254 case OP_OBJC_NSSTRING
:
10257 case UNOP_LOGICAL_NOT
:
10258 case UNOP_COMPLEMENT
:
10263 case UNOP_CAST_TYPE
:
10264 case UNOP_REINTERPRET_CAST
:
10265 case UNOP_DYNAMIC_CAST
:
10266 /* Unary, binary and ternary operators: We have to check
10267 their operands. If they are constant, then so is the
10268 result of that operation. For instance, if A and B are
10269 determined to be constants, then so is "A + B".
10271 UNOP_IND is one exception to the rule above, because the
10272 value of *ADDR is not necessarily a constant, even when
10277 /* Check whether the associated symbol is a constant.
10279 We use SYMBOL_CLASS rather than TYPE_CONST because it's
10280 possible that a buggy compiler could mark a variable as
10281 constant even when it is not, and TYPE_CONST would return
10282 true in this case, while SYMBOL_CLASS wouldn't.
10284 We also have to check for function symbols because they
10285 are always constant. */
10287 struct symbol
*s
= exp
->elts
[i
+ 2].symbol
;
10289 if (SYMBOL_CLASS (s
) != LOC_BLOCK
10290 && SYMBOL_CLASS (s
) != LOC_CONST
10291 && SYMBOL_CLASS (s
) != LOC_CONST_BYTES
)
10296 /* The default action is to return 0 because we are using
10297 the optimistic approach here: If we don't know something,
10298 then it is not a constant. */
10307 /* Watchpoint destructor. */
10309 watchpoint::~watchpoint ()
10311 xfree (this->exp_string
);
10312 xfree (this->exp_string_reparse
);
10313 value_free (this->val
);
10316 /* Implement the "re_set" breakpoint_ops method for watchpoints. */
10319 re_set_watchpoint (struct breakpoint
*b
)
10321 struct watchpoint
*w
= (struct watchpoint
*) b
;
10323 /* Watchpoint can be either on expression using entirely global
10324 variables, or it can be on local variables.
10326 Watchpoints of the first kind are never auto-deleted, and even
10327 persist across program restarts. Since they can use variables
10328 from shared libraries, we need to reparse expression as libraries
10329 are loaded and unloaded.
10331 Watchpoints on local variables can also change meaning as result
10332 of solib event. For example, if a watchpoint uses both a local
10333 and a global variables in expression, it's a local watchpoint,
10334 but unloading of a shared library will make the expression
10335 invalid. This is not a very common use case, but we still
10336 re-evaluate expression, to avoid surprises to the user.
10338 Note that for local watchpoints, we re-evaluate it only if
10339 watchpoints frame id is still valid. If it's not, it means the
10340 watchpoint is out of scope and will be deleted soon. In fact,
10341 I'm not sure we'll ever be called in this case.
10343 If a local watchpoint's frame id is still valid, then
10344 w->exp_valid_block is likewise valid, and we can safely use it.
10346 Don't do anything about disabled watchpoints, since they will be
10347 reevaluated again when enabled. */
10348 update_watchpoint (w
, 1 /* reparse */);
10351 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */
10354 insert_watchpoint (struct bp_location
*bl
)
10356 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10357 int length
= w
->exact
? 1 : bl
->length
;
10359 return target_insert_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10360 w
->cond_exp
.get ());
10363 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */
10366 remove_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10368 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10369 int length
= w
->exact
? 1 : bl
->length
;
10371 return target_remove_watchpoint (bl
->address
, length
, bl
->watchpoint_type
,
10372 w
->cond_exp
.get ());
10376 breakpoint_hit_watchpoint (const struct bp_location
*bl
,
10377 struct address_space
*aspace
, CORE_ADDR bp_addr
,
10378 const struct target_waitstatus
*ws
)
10380 struct breakpoint
*b
= bl
->owner
;
10381 struct watchpoint
*w
= (struct watchpoint
*) b
;
10383 /* Continuable hardware watchpoints are treated as non-existent if the
10384 reason we stopped wasn't a hardware watchpoint (we didn't stop on
10385 some data address). Otherwise gdb won't stop on a break instruction
10386 in the code (not from a breakpoint) when a hardware watchpoint has
10387 been defined. Also skip watchpoints which we know did not trigger
10388 (did not match the data address). */
10389 if (is_hardware_watchpoint (b
)
10390 && w
->watchpoint_triggered
== watch_triggered_no
)
10397 check_status_watchpoint (bpstat bs
)
10399 gdb_assert (is_watchpoint (bs
->breakpoint_at
));
10401 bpstat_check_watchpoint (bs
);
10404 /* Implement the "resources_needed" breakpoint_ops method for
10405 hardware watchpoints. */
10408 resources_needed_watchpoint (const struct bp_location
*bl
)
10410 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10411 int length
= w
->exact
? 1 : bl
->length
;
10413 return target_region_ok_for_hw_watchpoint (bl
->address
, length
);
10416 /* Implement the "works_in_software_mode" breakpoint_ops method for
10417 hardware watchpoints. */
10420 works_in_software_mode_watchpoint (const struct breakpoint
*b
)
10422 /* Read and access watchpoints only work with hardware support. */
10423 return b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
;
10426 static enum print_stop_action
10427 print_it_watchpoint (bpstat bs
)
10429 struct breakpoint
*b
;
10430 enum print_stop_action result
;
10431 struct watchpoint
*w
;
10432 struct ui_out
*uiout
= current_uiout
;
10434 gdb_assert (bs
->bp_location_at
!= NULL
);
10436 b
= bs
->breakpoint_at
;
10437 w
= (struct watchpoint
*) b
;
10439 annotate_watchpoint (b
->number
);
10440 maybe_print_thread_hit_breakpoint (uiout
);
10444 gdb::optional
<ui_out_emit_tuple
> tuple_emitter
;
10447 case bp_watchpoint
:
10448 case bp_hardware_watchpoint
:
10449 if (uiout
->is_mi_like_p ())
10450 uiout
->field_string
10451 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10453 tuple_emitter
.emplace (uiout
, "value");
10454 uiout
->text ("\nOld value = ");
10455 watchpoint_value_print (bs
->old_val
, &stb
);
10456 uiout
->field_stream ("old", stb
);
10457 uiout
->text ("\nNew value = ");
10458 watchpoint_value_print (w
->val
, &stb
);
10459 uiout
->field_stream ("new", stb
);
10460 uiout
->text ("\n");
10461 /* More than one watchpoint may have been triggered. */
10462 result
= PRINT_UNKNOWN
;
10465 case bp_read_watchpoint
:
10466 if (uiout
->is_mi_like_p ())
10467 uiout
->field_string
10468 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10470 tuple_emitter
.emplace (uiout
, "value");
10471 uiout
->text ("\nValue = ");
10472 watchpoint_value_print (w
->val
, &stb
);
10473 uiout
->field_stream ("value", stb
);
10474 uiout
->text ("\n");
10475 result
= PRINT_UNKNOWN
;
10478 case bp_access_watchpoint
:
10479 if (bs
->old_val
!= NULL
)
10481 if (uiout
->is_mi_like_p ())
10482 uiout
->field_string
10484 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10486 tuple_emitter
.emplace (uiout
, "value");
10487 uiout
->text ("\nOld value = ");
10488 watchpoint_value_print (bs
->old_val
, &stb
);
10489 uiout
->field_stream ("old", stb
);
10490 uiout
->text ("\nNew value = ");
10495 if (uiout
->is_mi_like_p ())
10496 uiout
->field_string
10498 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10499 tuple_emitter
.emplace (uiout
, "value");
10500 uiout
->text ("\nValue = ");
10502 watchpoint_value_print (w
->val
, &stb
);
10503 uiout
->field_stream ("new", stb
);
10504 uiout
->text ("\n");
10505 result
= PRINT_UNKNOWN
;
10508 result
= PRINT_UNKNOWN
;
10514 /* Implement the "print_mention" breakpoint_ops method for hardware
10518 print_mention_watchpoint (struct breakpoint
*b
)
10520 struct watchpoint
*w
= (struct watchpoint
*) b
;
10521 struct ui_out
*uiout
= current_uiout
;
10522 const char *tuple_name
;
10526 case bp_watchpoint
:
10527 uiout
->text ("Watchpoint ");
10528 tuple_name
= "wpt";
10530 case bp_hardware_watchpoint
:
10531 uiout
->text ("Hardware watchpoint ");
10532 tuple_name
= "wpt";
10534 case bp_read_watchpoint
:
10535 uiout
->text ("Hardware read watchpoint ");
10536 tuple_name
= "hw-rwpt";
10538 case bp_access_watchpoint
:
10539 uiout
->text ("Hardware access (read/write) watchpoint ");
10540 tuple_name
= "hw-awpt";
10543 internal_error (__FILE__
, __LINE__
,
10544 _("Invalid hardware watchpoint type."));
10547 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10548 uiout
->field_int ("number", b
->number
);
10549 uiout
->text (": ");
10550 uiout
->field_string ("exp", w
->exp_string
);
10553 /* Implement the "print_recreate" breakpoint_ops method for
10557 print_recreate_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10559 struct watchpoint
*w
= (struct watchpoint
*) b
;
10563 case bp_watchpoint
:
10564 case bp_hardware_watchpoint
:
10565 fprintf_unfiltered (fp
, "watch");
10567 case bp_read_watchpoint
:
10568 fprintf_unfiltered (fp
, "rwatch");
10570 case bp_access_watchpoint
:
10571 fprintf_unfiltered (fp
, "awatch");
10574 internal_error (__FILE__
, __LINE__
,
10575 _("Invalid watchpoint type."));
10578 fprintf_unfiltered (fp
, " %s", w
->exp_string
);
10579 print_recreate_thread (b
, fp
);
10582 /* Implement the "explains_signal" breakpoint_ops method for
10586 explains_signal_watchpoint (struct breakpoint
*b
, enum gdb_signal sig
)
10588 /* A software watchpoint cannot cause a signal other than
10589 GDB_SIGNAL_TRAP. */
10590 if (b
->type
== bp_watchpoint
&& sig
!= GDB_SIGNAL_TRAP
)
10596 /* The breakpoint_ops structure to be used in hardware watchpoints. */
10598 static struct breakpoint_ops watchpoint_breakpoint_ops
;
10600 /* Implement the "insert" breakpoint_ops method for
10601 masked hardware watchpoints. */
10604 insert_masked_watchpoint (struct bp_location
*bl
)
10606 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10608 return target_insert_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10609 bl
->watchpoint_type
);
10612 /* Implement the "remove" breakpoint_ops method for
10613 masked hardware watchpoints. */
10616 remove_masked_watchpoint (struct bp_location
*bl
, enum remove_bp_reason reason
)
10618 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10620 return target_remove_mask_watchpoint (bl
->address
, w
->hw_wp_mask
,
10621 bl
->watchpoint_type
);
10624 /* Implement the "resources_needed" breakpoint_ops method for
10625 masked hardware watchpoints. */
10628 resources_needed_masked_watchpoint (const struct bp_location
*bl
)
10630 struct watchpoint
*w
= (struct watchpoint
*) bl
->owner
;
10632 return target_masked_watch_num_registers (bl
->address
, w
->hw_wp_mask
);
10635 /* Implement the "works_in_software_mode" breakpoint_ops method for
10636 masked hardware watchpoints. */
10639 works_in_software_mode_masked_watchpoint (const struct breakpoint
*b
)
10644 /* Implement the "print_it" breakpoint_ops method for
10645 masked hardware watchpoints. */
10647 static enum print_stop_action
10648 print_it_masked_watchpoint (bpstat bs
)
10650 struct breakpoint
*b
= bs
->breakpoint_at
;
10651 struct ui_out
*uiout
= current_uiout
;
10653 /* Masked watchpoints have only one location. */
10654 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10656 annotate_watchpoint (b
->number
);
10657 maybe_print_thread_hit_breakpoint (uiout
);
10661 case bp_hardware_watchpoint
:
10662 if (uiout
->is_mi_like_p ())
10663 uiout
->field_string
10664 ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
10667 case bp_read_watchpoint
:
10668 if (uiout
->is_mi_like_p ())
10669 uiout
->field_string
10670 ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
10673 case bp_access_watchpoint
:
10674 if (uiout
->is_mi_like_p ())
10675 uiout
->field_string
10677 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
10680 internal_error (__FILE__
, __LINE__
,
10681 _("Invalid hardware watchpoint type."));
10685 uiout
->text (_("\n\
10686 Check the underlying instruction at PC for the memory\n\
10687 address and value which triggered this watchpoint.\n"));
10688 uiout
->text ("\n");
10690 /* More than one watchpoint may have been triggered. */
10691 return PRINT_UNKNOWN
;
10694 /* Implement the "print_one_detail" breakpoint_ops method for
10695 masked hardware watchpoints. */
10698 print_one_detail_masked_watchpoint (const struct breakpoint
*b
,
10699 struct ui_out
*uiout
)
10701 struct watchpoint
*w
= (struct watchpoint
*) b
;
10703 /* Masked watchpoints have only one location. */
10704 gdb_assert (b
->loc
&& b
->loc
->next
== NULL
);
10706 uiout
->text ("\tmask ");
10707 uiout
->field_core_addr ("mask", b
->loc
->gdbarch
, w
->hw_wp_mask
);
10708 uiout
->text ("\n");
10711 /* Implement the "print_mention" breakpoint_ops method for
10712 masked hardware watchpoints. */
10715 print_mention_masked_watchpoint (struct breakpoint
*b
)
10717 struct watchpoint
*w
= (struct watchpoint
*) b
;
10718 struct ui_out
*uiout
= current_uiout
;
10719 const char *tuple_name
;
10723 case bp_hardware_watchpoint
:
10724 uiout
->text ("Masked hardware watchpoint ");
10725 tuple_name
= "wpt";
10727 case bp_read_watchpoint
:
10728 uiout
->text ("Masked hardware read watchpoint ");
10729 tuple_name
= "hw-rwpt";
10731 case bp_access_watchpoint
:
10732 uiout
->text ("Masked hardware access (read/write) watchpoint ");
10733 tuple_name
= "hw-awpt";
10736 internal_error (__FILE__
, __LINE__
,
10737 _("Invalid hardware watchpoint type."));
10740 ui_out_emit_tuple
tuple_emitter (uiout
, tuple_name
);
10741 uiout
->field_int ("number", b
->number
);
10742 uiout
->text (": ");
10743 uiout
->field_string ("exp", w
->exp_string
);
10746 /* Implement the "print_recreate" breakpoint_ops method for
10747 masked hardware watchpoints. */
10750 print_recreate_masked_watchpoint (struct breakpoint
*b
, struct ui_file
*fp
)
10752 struct watchpoint
*w
= (struct watchpoint
*) b
;
10757 case bp_hardware_watchpoint
:
10758 fprintf_unfiltered (fp
, "watch");
10760 case bp_read_watchpoint
:
10761 fprintf_unfiltered (fp
, "rwatch");
10763 case bp_access_watchpoint
:
10764 fprintf_unfiltered (fp
, "awatch");
10767 internal_error (__FILE__
, __LINE__
,
10768 _("Invalid hardware watchpoint type."));
10771 sprintf_vma (tmp
, w
->hw_wp_mask
);
10772 fprintf_unfiltered (fp
, " %s mask 0x%s", w
->exp_string
, tmp
);
10773 print_recreate_thread (b
, fp
);
10776 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */
10778 static struct breakpoint_ops masked_watchpoint_breakpoint_ops
;
10780 /* Tell whether the given watchpoint is a masked hardware watchpoint. */
10783 is_masked_watchpoint (const struct breakpoint
*b
)
10785 return b
->ops
== &masked_watchpoint_breakpoint_ops
;
10788 /* accessflag: hw_write: watch write,
10789 hw_read: watch read,
10790 hw_access: watch access (read or write) */
10792 watch_command_1 (const char *arg
, int accessflag
, int from_tty
,
10793 int just_location
, int internal
)
10795 struct breakpoint
*scope_breakpoint
= NULL
;
10796 const struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
10797 struct value
*val
, *mark
, *result
;
10798 int saved_bitpos
= 0, saved_bitsize
= 0;
10799 const char *exp_start
= NULL
;
10800 const char *exp_end
= NULL
;
10801 const char *tok
, *end_tok
;
10803 const char *cond_start
= NULL
;
10804 const char *cond_end
= NULL
;
10805 enum bptype bp_type
;
10808 /* Flag to indicate whether we are going to use masks for
10809 the hardware watchpoint. */
10811 CORE_ADDR mask
= 0;
10813 struct cleanup
*back_to
;
10815 /* Make sure that we actually have parameters to parse. */
10816 if (arg
!= NULL
&& arg
[0] != '\0')
10818 const char *value_start
;
10820 exp_end
= arg
+ strlen (arg
);
10822 /* Look for "parameter value" pairs at the end
10823 of the arguments string. */
10824 for (tok
= exp_end
- 1; tok
> arg
; tok
--)
10826 /* Skip whitespace at the end of the argument list. */
10827 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10830 /* Find the beginning of the last token.
10831 This is the value of the parameter. */
10832 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10834 value_start
= tok
+ 1;
10836 /* Skip whitespace. */
10837 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
10842 /* Find the beginning of the second to last token.
10843 This is the parameter itself. */
10844 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
10847 toklen
= end_tok
- tok
+ 1;
10849 if (toklen
== 6 && startswith (tok
, "thread"))
10851 struct thread_info
*thr
;
10852 /* At this point we've found a "thread" token, which means
10853 the user is trying to set a watchpoint that triggers
10854 only in a specific thread. */
10858 error(_("You can specify only one thread."));
10860 /* Extract the thread ID from the next token. */
10861 thr
= parse_thread_id (value_start
, &endp
);
10863 /* Check if the user provided a valid thread ID. */
10864 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
10865 invalid_thread_id_error (value_start
);
10867 thread
= thr
->global_num
;
10869 else if (toklen
== 4 && startswith (tok
, "mask"))
10871 /* We've found a "mask" token, which means the user wants to
10872 create a hardware watchpoint that is going to have the mask
10874 struct value
*mask_value
, *mark
;
10877 error(_("You can specify only one mask."));
10879 use_mask
= just_location
= 1;
10881 mark
= value_mark ();
10882 mask_value
= parse_to_comma_and_eval (&value_start
);
10883 mask
= value_as_address (mask_value
);
10884 value_free_to_mark (mark
);
10887 /* We didn't recognize what we found. We should stop here. */
10890 /* Truncate the string and get rid of the "parameter value" pair before
10891 the arguments string is parsed by the parse_exp_1 function. */
10898 /* Parse the rest of the arguments. From here on out, everything
10899 is in terms of a newly allocated string instead of the original
10901 innermost_block
= NULL
;
10902 expression
= savestring (arg
, exp_end
- arg
);
10903 back_to
= make_cleanup (xfree
, expression
);
10904 exp_start
= arg
= expression
;
10905 expression_up exp
= parse_exp_1 (&arg
, 0, 0, 0);
10907 /* Remove trailing whitespace from the expression before saving it.
10908 This makes the eventual display of the expression string a bit
10910 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
10913 /* Checking if the expression is not constant. */
10914 if (watchpoint_exp_is_const (exp
.get ()))
10918 len
= exp_end
- exp_start
;
10919 while (len
> 0 && isspace (exp_start
[len
- 1]))
10921 error (_("Cannot watch constant value `%.*s'."), len
, exp_start
);
10924 exp_valid_block
= innermost_block
;
10925 mark
= value_mark ();
10926 fetch_subexp_value (exp
.get (), &pc
, &val
, &result
, NULL
, just_location
);
10928 if (val
!= NULL
&& just_location
)
10930 saved_bitpos
= value_bitpos (val
);
10931 saved_bitsize
= value_bitsize (val
);
10938 exp_valid_block
= NULL
;
10939 val
= value_addr (result
);
10940 release_value (val
);
10941 value_free_to_mark (mark
);
10945 ret
= target_masked_watch_num_registers (value_as_address (val
),
10948 error (_("This target does not support masked watchpoints."));
10949 else if (ret
== -2)
10950 error (_("Invalid mask or memory region."));
10953 else if (val
!= NULL
)
10954 release_value (val
);
10956 tok
= skip_spaces (arg
);
10957 end_tok
= skip_to_space (tok
);
10959 toklen
= end_tok
- tok
;
10960 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
10962 innermost_block
= NULL
;
10963 tok
= cond_start
= end_tok
+ 1;
10964 parse_exp_1 (&tok
, 0, 0, 0);
10966 /* The watchpoint expression may not be local, but the condition
10967 may still be. E.g.: `watch global if local > 0'. */
10968 cond_exp_valid_block
= innermost_block
;
10973 error (_("Junk at end of command."));
10975 frame_info
*wp_frame
= block_innermost_frame (exp_valid_block
);
10977 /* Save this because create_internal_breakpoint below invalidates
10979 frame_id watchpoint_frame
= get_frame_id (wp_frame
);
10981 /* If the expression is "local", then set up a "watchpoint scope"
10982 breakpoint at the point where we've left the scope of the watchpoint
10983 expression. Create the scope breakpoint before the watchpoint, so
10984 that we will encounter it first in bpstat_stop_status. */
10985 if (exp_valid_block
!= NULL
&& wp_frame
!= NULL
)
10987 frame_id caller_frame_id
= frame_unwind_caller_id (wp_frame
);
10989 if (frame_id_p (caller_frame_id
))
10991 gdbarch
*caller_arch
= frame_unwind_caller_arch (wp_frame
);
10992 CORE_ADDR caller_pc
= frame_unwind_caller_pc (wp_frame
);
10995 = create_internal_breakpoint (caller_arch
, caller_pc
,
10996 bp_watchpoint_scope
,
10997 &momentary_breakpoint_ops
);
10999 /* create_internal_breakpoint could invalidate WP_FRAME. */
11002 scope_breakpoint
->enable_state
= bp_enabled
;
11004 /* Automatically delete the breakpoint when it hits. */
11005 scope_breakpoint
->disposition
= disp_del
;
11007 /* Only break in the proper frame (help with recursion). */
11008 scope_breakpoint
->frame_id
= caller_frame_id
;
11010 /* Set the address at which we will stop. */
11011 scope_breakpoint
->loc
->gdbarch
= caller_arch
;
11012 scope_breakpoint
->loc
->requested_address
= caller_pc
;
11013 scope_breakpoint
->loc
->address
11014 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
11015 scope_breakpoint
->loc
->requested_address
,
11016 scope_breakpoint
->type
);
11020 /* Now set up the breakpoint. We create all watchpoints as hardware
11021 watchpoints here even if hardware watchpoints are turned off, a call
11022 to update_watchpoint later in this function will cause the type to
11023 drop back to bp_watchpoint (software watchpoint) if required. */
11025 if (accessflag
== hw_read
)
11026 bp_type
= bp_read_watchpoint
;
11027 else if (accessflag
== hw_access
)
11028 bp_type
= bp_access_watchpoint
;
11030 bp_type
= bp_hardware_watchpoint
;
11032 std::unique_ptr
<watchpoint
> w (new watchpoint ());
11035 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
11036 &masked_watchpoint_breakpoint_ops
);
11038 init_raw_breakpoint_without_location (w
.get (), NULL
, bp_type
,
11039 &watchpoint_breakpoint_ops
);
11040 w
->thread
= thread
;
11041 w
->disposition
= disp_donttouch
;
11042 w
->pspace
= current_program_space
;
11043 w
->exp
= std::move (exp
);
11044 w
->exp_valid_block
= exp_valid_block
;
11045 w
->cond_exp_valid_block
= cond_exp_valid_block
;
11048 struct type
*t
= value_type (val
);
11049 CORE_ADDR addr
= value_as_address (val
);
11051 w
->exp_string_reparse
11052 = current_language
->la_watch_location_expression (t
, addr
).release ();
11054 w
->exp_string
= xstrprintf ("-location %.*s",
11055 (int) (exp_end
- exp_start
), exp_start
);
11058 w
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
11062 w
->hw_wp_mask
= mask
;
11067 w
->val_bitpos
= saved_bitpos
;
11068 w
->val_bitsize
= saved_bitsize
;
11073 w
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
11075 w
->cond_string
= 0;
11077 if (frame_id_p (watchpoint_frame
))
11079 w
->watchpoint_frame
= watchpoint_frame
;
11080 w
->watchpoint_thread
= inferior_ptid
;
11084 w
->watchpoint_frame
= null_frame_id
;
11085 w
->watchpoint_thread
= null_ptid
;
11088 if (scope_breakpoint
!= NULL
)
11090 /* The scope breakpoint is related to the watchpoint. We will
11091 need to act on them together. */
11092 w
->related_breakpoint
= scope_breakpoint
;
11093 scope_breakpoint
->related_breakpoint
= w
.get ();
11096 if (!just_location
)
11097 value_free_to_mark (mark
);
11099 /* Finally update the new watchpoint. This creates the locations
11100 that should be inserted. */
11101 update_watchpoint (w
.get (), 1);
11103 install_breakpoint (internal
, std::move (w
), 1);
11104 do_cleanups (back_to
);
11107 /* Return count of debug registers needed to watch the given expression.
11108 If the watchpoint cannot be handled in hardware return zero. */
11111 can_use_hardware_watchpoint (struct value
*v
)
11113 int found_memory_cnt
= 0;
11114 struct value
*head
= v
;
11116 /* Did the user specifically forbid us to use hardware watchpoints? */
11117 if (!can_use_hw_watchpoints
)
11120 /* Make sure that the value of the expression depends only upon
11121 memory contents, and values computed from them within GDB. If we
11122 find any register references or function calls, we can't use a
11123 hardware watchpoint.
11125 The idea here is that evaluating an expression generates a series
11126 of values, one holding the value of every subexpression. (The
11127 expression a*b+c has five subexpressions: a, b, a*b, c, and
11128 a*b+c.) GDB's values hold almost enough information to establish
11129 the criteria given above --- they identify memory lvalues,
11130 register lvalues, computed values, etcetera. So we can evaluate
11131 the expression, and then scan the chain of values that leaves
11132 behind to decide whether we can detect any possible change to the
11133 expression's final value using only hardware watchpoints.
11135 However, I don't think that the values returned by inferior
11136 function calls are special in any way. So this function may not
11137 notice that an expression involving an inferior function call
11138 can't be watched with hardware watchpoints. FIXME. */
11139 for (; v
; v
= value_next (v
))
11141 if (VALUE_LVAL (v
) == lval_memory
)
11143 if (v
!= head
&& value_lazy (v
))
11144 /* A lazy memory lvalue in the chain is one that GDB never
11145 needed to fetch; we either just used its address (e.g.,
11146 `a' in `a.b') or we never needed it at all (e.g., `a'
11147 in `a,b'). This doesn't apply to HEAD; if that is
11148 lazy then it was not readable, but watch it anyway. */
11152 /* Ahh, memory we actually used! Check if we can cover
11153 it with hardware watchpoints. */
11154 struct type
*vtype
= check_typedef (value_type (v
));
11156 /* We only watch structs and arrays if user asked for it
11157 explicitly, never if they just happen to appear in a
11158 middle of some value chain. */
11160 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
11161 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
11163 CORE_ADDR vaddr
= value_address (v
);
11167 len
= (target_exact_watchpoints
11168 && is_scalar_type_recursive (vtype
))?
11169 1 : TYPE_LENGTH (value_type (v
));
11171 num_regs
= target_region_ok_for_hw_watchpoint (vaddr
, len
);
11175 found_memory_cnt
+= num_regs
;
11179 else if (VALUE_LVAL (v
) != not_lval
11180 && deprecated_value_modifiable (v
) == 0)
11181 return 0; /* These are values from the history (e.g., $1). */
11182 else if (VALUE_LVAL (v
) == lval_register
)
11183 return 0; /* Cannot watch a register with a HW watchpoint. */
11186 /* The expression itself looks suitable for using a hardware
11187 watchpoint, but give the target machine a chance to reject it. */
11188 return found_memory_cnt
;
11192 watch_command_wrapper (char *arg
, int from_tty
, int internal
)
11194 watch_command_1 (arg
, hw_write
, from_tty
, 0, internal
);
11197 /* A helper function that looks for the "-location" argument and then
11198 calls watch_command_1. */
11201 watch_maybe_just_location (char *arg
, int accessflag
, int from_tty
)
11203 int just_location
= 0;
11206 && (check_for_argument (&arg
, "-location", sizeof ("-location") - 1)
11207 || check_for_argument (&arg
, "-l", sizeof ("-l") - 1)))
11209 arg
= skip_spaces (arg
);
11213 watch_command_1 (arg
, accessflag
, from_tty
, just_location
, 0);
11217 watch_command (char *arg
, int from_tty
)
11219 watch_maybe_just_location (arg
, hw_write
, from_tty
);
11223 rwatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11225 watch_command_1 (arg
, hw_read
, from_tty
, 0, internal
);
11229 rwatch_command (char *arg
, int from_tty
)
11231 watch_maybe_just_location (arg
, hw_read
, from_tty
);
11235 awatch_command_wrapper (char *arg
, int from_tty
, int internal
)
11237 watch_command_1 (arg
, hw_access
, from_tty
, 0, internal
);
11241 awatch_command (char *arg
, int from_tty
)
11243 watch_maybe_just_location (arg
, hw_access
, from_tty
);
11247 /* Data for the FSM that manages the until(location)/advance commands
11248 in infcmd.c. Here because it uses the mechanisms of
11251 struct until_break_fsm
11253 /* The base class. */
11254 struct thread_fsm thread_fsm
;
11256 /* The thread that as current when the command was executed. */
11259 /* The breakpoint set at the destination location. */
11260 struct breakpoint
*location_breakpoint
;
11262 /* Breakpoint set at the return address in the caller frame. May be
11264 struct breakpoint
*caller_breakpoint
;
11267 static void until_break_fsm_clean_up (struct thread_fsm
*self
,
11268 struct thread_info
*thread
);
11269 static int until_break_fsm_should_stop (struct thread_fsm
*self
,
11270 struct thread_info
*thread
);
11271 static enum async_reply_reason
11272 until_break_fsm_async_reply_reason (struct thread_fsm
*self
);
11274 /* until_break_fsm's vtable. */
11276 static struct thread_fsm_ops until_break_fsm_ops
=
11279 until_break_fsm_clean_up
,
11280 until_break_fsm_should_stop
,
11281 NULL
, /* return_value */
11282 until_break_fsm_async_reply_reason
,
11285 /* Allocate a new until_break_command_fsm. */
11287 static struct until_break_fsm
*
11288 new_until_break_fsm (struct interp
*cmd_interp
, int thread
,
11289 struct breakpoint
*location_breakpoint
,
11290 struct breakpoint
*caller_breakpoint
)
11292 struct until_break_fsm
*sm
;
11294 sm
= XCNEW (struct until_break_fsm
);
11295 thread_fsm_ctor (&sm
->thread_fsm
, &until_break_fsm_ops
, cmd_interp
);
11297 sm
->thread
= thread
;
11298 sm
->location_breakpoint
= location_breakpoint
;
11299 sm
->caller_breakpoint
= caller_breakpoint
;
11304 /* Implementation of the 'should_stop' FSM method for the
11305 until(location)/advance commands. */
11308 until_break_fsm_should_stop (struct thread_fsm
*self
,
11309 struct thread_info
*tp
)
11311 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11313 if (bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11314 sm
->location_breakpoint
) != NULL
11315 || (sm
->caller_breakpoint
!= NULL
11316 && bpstat_find_breakpoint (tp
->control
.stop_bpstat
,
11317 sm
->caller_breakpoint
) != NULL
))
11318 thread_fsm_set_finished (self
);
11323 /* Implementation of the 'clean_up' FSM method for the
11324 until(location)/advance commands. */
11327 until_break_fsm_clean_up (struct thread_fsm
*self
,
11328 struct thread_info
*thread
)
11330 struct until_break_fsm
*sm
= (struct until_break_fsm
*) self
;
11332 /* Clean up our temporary breakpoints. */
11333 if (sm
->location_breakpoint
!= NULL
)
11335 delete_breakpoint (sm
->location_breakpoint
);
11336 sm
->location_breakpoint
= NULL
;
11338 if (sm
->caller_breakpoint
!= NULL
)
11340 delete_breakpoint (sm
->caller_breakpoint
);
11341 sm
->caller_breakpoint
= NULL
;
11343 delete_longjmp_breakpoint (sm
->thread
);
11346 /* Implementation of the 'async_reply_reason' FSM method for the
11347 until(location)/advance commands. */
11349 static enum async_reply_reason
11350 until_break_fsm_async_reply_reason (struct thread_fsm
*self
)
11352 return EXEC_ASYNC_LOCATION_REACHED
;
11356 until_break_command (char *arg
, int from_tty
, int anywhere
)
11358 struct frame_info
*frame
;
11359 struct gdbarch
*frame_gdbarch
;
11360 struct frame_id stack_frame_id
;
11361 struct frame_id caller_frame_id
;
11362 struct breakpoint
*location_breakpoint
;
11363 struct breakpoint
*caller_breakpoint
= NULL
;
11364 struct cleanup
*old_chain
;
11366 struct thread_info
*tp
;
11367 struct until_break_fsm
*sm
;
11369 clear_proceed_status (0);
11371 /* Set a breakpoint where the user wants it and at return from
11374 event_location_up location
= string_to_event_location (&arg
, current_language
);
11376 std::vector
<symtab_and_line
> sals
11377 = (last_displayed_sal_is_valid ()
11378 ? decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
, NULL
,
11379 get_last_displayed_symtab (),
11380 get_last_displayed_line ())
11381 : decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
11382 NULL
, (struct symtab
*) NULL
, 0));
11384 if (sals
.size () != 1)
11385 error (_("Couldn't get information on specified line."));
11387 symtab_and_line
&sal
= sals
[0];
11390 error (_("Junk at end of arguments."));
11392 resolve_sal_pc (&sal
);
11394 tp
= inferior_thread ();
11395 thread
= tp
->global_num
;
11397 old_chain
= make_cleanup (null_cleanup
, NULL
);
11399 /* Note linespec handling above invalidates the frame chain.
11400 Installing a breakpoint also invalidates the frame chain (as it
11401 may need to switch threads), so do any frame handling before
11404 frame
= get_selected_frame (NULL
);
11405 frame_gdbarch
= get_frame_arch (frame
);
11406 stack_frame_id
= get_stack_frame_id (frame
);
11407 caller_frame_id
= frame_unwind_caller_id (frame
);
11409 /* Keep within the current frame, or in frames called by the current
11412 if (frame_id_p (caller_frame_id
))
11414 struct symtab_and_line sal2
;
11415 struct gdbarch
*caller_gdbarch
;
11417 sal2
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
11418 sal2
.pc
= frame_unwind_caller_pc (frame
);
11419 caller_gdbarch
= frame_unwind_caller_arch (frame
);
11420 caller_breakpoint
= set_momentary_breakpoint (caller_gdbarch
,
11424 make_cleanup_delete_breakpoint (caller_breakpoint
);
11426 set_longjmp_breakpoint (tp
, caller_frame_id
);
11427 make_cleanup (delete_longjmp_breakpoint_cleanup
, &thread
);
11430 /* set_momentary_breakpoint could invalidate FRAME. */
11434 /* If the user told us to continue until a specified location,
11435 we don't specify a frame at which we need to stop. */
11436 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11437 null_frame_id
, bp_until
);
11439 /* Otherwise, specify the selected frame, because we want to stop
11440 only at the very same frame. */
11441 location_breakpoint
= set_momentary_breakpoint (frame_gdbarch
, sal
,
11442 stack_frame_id
, bp_until
);
11443 make_cleanup_delete_breakpoint (location_breakpoint
);
11445 sm
= new_until_break_fsm (command_interp (), tp
->global_num
,
11446 location_breakpoint
, caller_breakpoint
);
11447 tp
->thread_fsm
= &sm
->thread_fsm
;
11449 discard_cleanups (old_chain
);
11451 proceed (-1, GDB_SIGNAL_DEFAULT
);
11454 /* This function attempts to parse an optional "if <cond>" clause
11455 from the arg string. If one is not found, it returns NULL.
11457 Else, it returns a pointer to the condition string. (It does not
11458 attempt to evaluate the string against a particular block.) And,
11459 it updates arg to point to the first character following the parsed
11460 if clause in the arg string. */
11463 ep_parse_optional_if_clause (const char **arg
)
11465 const char *cond_string
;
11467 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
11470 /* Skip the "if" keyword. */
11473 /* Skip any extra leading whitespace, and record the start of the
11474 condition string. */
11475 *arg
= skip_spaces (*arg
);
11476 cond_string
= *arg
;
11478 /* Assume that the condition occupies the remainder of the arg
11480 (*arg
) += strlen (cond_string
);
11482 return cond_string
;
11485 /* Commands to deal with catching events, such as signals, exceptions,
11486 process start/exit, etc. */
11490 catch_fork_temporary
, catch_vfork_temporary
,
11491 catch_fork_permanent
, catch_vfork_permanent
11496 catch_fork_command_1 (char *arg_entry
, int from_tty
,
11497 struct cmd_list_element
*command
)
11499 const char *arg
= arg_entry
;
11500 struct gdbarch
*gdbarch
= get_current_arch ();
11501 const char *cond_string
= NULL
;
11502 catch_fork_kind fork_kind
;
11505 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
11506 tempflag
= (fork_kind
== catch_fork_temporary
11507 || fork_kind
== catch_vfork_temporary
);
11511 arg
= skip_spaces (arg
);
11513 /* The allowed syntax is:
11515 catch [v]fork if <cond>
11517 First, check if there's an if clause. */
11518 cond_string
= ep_parse_optional_if_clause (&arg
);
11520 if ((*arg
!= '\0') && !isspace (*arg
))
11521 error (_("Junk at end of arguments."));
11523 /* If this target supports it, create a fork or vfork catchpoint
11524 and enable reporting of such events. */
11527 case catch_fork_temporary
:
11528 case catch_fork_permanent
:
11529 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11530 &catch_fork_breakpoint_ops
);
11532 case catch_vfork_temporary
:
11533 case catch_vfork_permanent
:
11534 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
11535 &catch_vfork_breakpoint_ops
);
11538 error (_("unsupported or unknown fork kind; cannot catch it"));
11544 catch_exec_command_1 (char *arg_entry
, int from_tty
,
11545 struct cmd_list_element
*command
)
11547 const char *arg
= arg_entry
;
11548 struct gdbarch
*gdbarch
= get_current_arch ();
11550 const char *cond_string
= NULL
;
11552 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
11556 arg
= skip_spaces (arg
);
11558 /* The allowed syntax is:
11560 catch exec if <cond>
11562 First, check if there's an if clause. */
11563 cond_string
= ep_parse_optional_if_clause (&arg
);
11565 if ((*arg
!= '\0') && !isspace (*arg
))
11566 error (_("Junk at end of arguments."));
11568 std::unique_ptr
<exec_catchpoint
> c (new exec_catchpoint ());
11569 init_catchpoint (c
.get (), gdbarch
, tempflag
, cond_string
,
11570 &catch_exec_breakpoint_ops
);
11571 c
->exec_pathname
= NULL
;
11573 install_breakpoint (0, std::move (c
), 1);
11577 init_ada_exception_breakpoint (struct breakpoint
*b
,
11578 struct gdbarch
*gdbarch
,
11579 struct symtab_and_line sal
,
11581 const struct breakpoint_ops
*ops
,
11588 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
11590 loc_gdbarch
= gdbarch
;
11592 describe_other_breakpoints (loc_gdbarch
,
11593 sal
.pspace
, sal
.pc
, sal
.section
, -1);
11594 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
11595 version for exception catchpoints, because two catchpoints
11596 used for different exception names will use the same address.
11597 In this case, a "breakpoint ... also set at..." warning is
11598 unproductive. Besides, the warning phrasing is also a bit
11599 inappropriate, we should use the word catchpoint, and tell
11600 the user what type of catchpoint it is. The above is good
11601 enough for now, though. */
11604 init_raw_breakpoint (b
, gdbarch
, sal
, bp_breakpoint
, ops
);
11606 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
11607 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
11608 b
->location
= string_to_event_location (&addr_string
,
11609 language_def (language_ada
));
11610 b
->language
= language_ada
;
11614 catch_command (char *arg
, int from_tty
)
11616 error (_("Catch requires an event name."));
11621 tcatch_command (char *arg
, int from_tty
)
11623 error (_("Catch requires an event name."));
11626 /* A qsort comparison function that sorts breakpoints in order. */
11629 compare_breakpoints (const void *a
, const void *b
)
11631 const breakpoint_p
*ba
= (const breakpoint_p
*) a
;
11632 uintptr_t ua
= (uintptr_t) *ba
;
11633 const breakpoint_p
*bb
= (const breakpoint_p
*) b
;
11634 uintptr_t ub
= (uintptr_t) *bb
;
11636 if ((*ba
)->number
< (*bb
)->number
)
11638 else if ((*ba
)->number
> (*bb
)->number
)
11641 /* Now sort by address, in case we see, e..g, two breakpoints with
11645 return ua
> ub
? 1 : 0;
11648 /* Delete breakpoints by address or line. */
11651 clear_command (char *arg
, int from_tty
)
11653 struct breakpoint
*b
, *prev
;
11654 VEC(breakpoint_p
) *found
= 0;
11658 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
11660 std::vector
<symtab_and_line
> decoded_sals
;
11661 symtab_and_line last_sal
;
11662 gdb::array_view
<symtab_and_line
> sals
;
11666 = decode_line_with_current_source (arg
,
11667 (DECODE_LINE_FUNFIRSTLINE
11668 | DECODE_LINE_LIST_MODE
));
11670 sals
= decoded_sals
;
11674 /* Set sal's line, symtab, pc, and pspace to the values
11675 corresponding to the last call to print_frame_info. If the
11676 codepoint is not valid, this will set all the fields to 0. */
11677 last_sal
= get_last_displayed_sal ();
11678 if (last_sal
.symtab
== 0)
11679 error (_("No source file specified."));
11685 /* We don't call resolve_sal_pc here. That's not as bad as it
11686 seems, because all existing breakpoints typically have both
11687 file/line and pc set. So, if clear is given file/line, we can
11688 match this to existing breakpoint without obtaining pc at all.
11690 We only support clearing given the address explicitly
11691 present in breakpoint table. Say, we've set breakpoint
11692 at file:line. There were several PC values for that file:line,
11693 due to optimization, all in one block.
11695 We've picked one PC value. If "clear" is issued with another
11696 PC corresponding to the same file:line, the breakpoint won't
11697 be cleared. We probably can still clear the breakpoint, but
11698 since the other PC value is never presented to user, user
11699 can only find it by guessing, and it does not seem important
11700 to support that. */
11702 /* For each line spec given, delete bps which correspond to it. Do
11703 it in two passes, solely to preserve the current behavior that
11704 from_tty is forced true if we delete more than one
11708 make_cleanup (VEC_cleanup (breakpoint_p
), &found
);
11709 for (const auto &sal
: sals
)
11711 const char *sal_fullname
;
11713 /* If exact pc given, clear bpts at that pc.
11714 If line given (pc == 0), clear all bpts on specified line.
11715 If defaulting, clear all bpts on default line
11718 defaulting sal.pc != 0 tests to do
11723 1 0 <can't happen> */
11725 sal_fullname
= (sal
.symtab
== NULL
11726 ? NULL
: symtab_to_fullname (sal
.symtab
));
11728 /* Find all matching breakpoints and add them to 'found'. */
11729 ALL_BREAKPOINTS (b
)
11732 /* Are we going to delete b? */
11733 if (b
->type
!= bp_none
&& !is_watchpoint (b
))
11735 struct bp_location
*loc
= b
->loc
;
11736 for (; loc
; loc
= loc
->next
)
11738 /* If the user specified file:line, don't allow a PC
11739 match. This matches historical gdb behavior. */
11740 int pc_match
= (!sal
.explicit_line
11742 && (loc
->pspace
== sal
.pspace
)
11743 && (loc
->address
== sal
.pc
)
11744 && (!section_is_overlay (loc
->section
)
11745 || loc
->section
== sal
.section
));
11746 int line_match
= 0;
11748 if ((default_match
|| sal
.explicit_line
)
11749 && loc
->symtab
!= NULL
11750 && sal_fullname
!= NULL
11751 && sal
.pspace
== loc
->pspace
11752 && loc
->line_number
== sal
.line
11753 && filename_cmp (symtab_to_fullname (loc
->symtab
),
11754 sal_fullname
) == 0)
11757 if (pc_match
|| line_match
)
11766 VEC_safe_push(breakpoint_p
, found
, b
);
11770 /* Now go thru the 'found' chain and delete them. */
11771 if (VEC_empty(breakpoint_p
, found
))
11774 error (_("No breakpoint at %s."), arg
);
11776 error (_("No breakpoint at this line."));
11779 /* Remove duplicates from the vec. */
11780 qsort (VEC_address (breakpoint_p
, found
),
11781 VEC_length (breakpoint_p
, found
),
11782 sizeof (breakpoint_p
),
11783 compare_breakpoints
);
11784 prev
= VEC_index (breakpoint_p
, found
, 0);
11785 for (ix
= 1; VEC_iterate (breakpoint_p
, found
, ix
, b
); ++ix
)
11789 VEC_ordered_remove (breakpoint_p
, found
, ix
);
11794 if (VEC_length(breakpoint_p
, found
) > 1)
11795 from_tty
= 1; /* Always report if deleted more than one. */
11798 if (VEC_length(breakpoint_p
, found
) == 1)
11799 printf_unfiltered (_("Deleted breakpoint "));
11801 printf_unfiltered (_("Deleted breakpoints "));
11804 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
11807 printf_unfiltered ("%d ", b
->number
);
11808 delete_breakpoint (b
);
11811 putchar_unfiltered ('\n');
11813 do_cleanups (cleanups
);
11816 /* Delete breakpoint in BS if they are `delete' breakpoints and
11817 all breakpoints that are marked for deletion, whether hit or not.
11818 This is called after any breakpoint is hit, or after errors. */
11821 breakpoint_auto_delete (bpstat bs
)
11823 struct breakpoint
*b
, *b_tmp
;
11825 for (; bs
; bs
= bs
->next
)
11826 if (bs
->breakpoint_at
11827 && bs
->breakpoint_at
->disposition
== disp_del
11829 delete_breakpoint (bs
->breakpoint_at
);
11831 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
11833 if (b
->disposition
== disp_del_at_next_stop
)
11834 delete_breakpoint (b
);
11838 /* A comparison function for bp_location AP and BP being interfaced to
11839 qsort. Sort elements primarily by their ADDRESS (no matter what
11840 does breakpoint_address_is_meaningful say for its OWNER),
11841 secondarily by ordering first permanent elements and
11842 terciarily just ensuring the array is sorted stable way despite
11843 qsort being an unstable algorithm. */
11846 bp_locations_compare (const void *ap
, const void *bp
)
11848 const struct bp_location
*a
= *(const struct bp_location
**) ap
;
11849 const struct bp_location
*b
= *(const struct bp_location
**) bp
;
11851 if (a
->address
!= b
->address
)
11852 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
11854 /* Sort locations at the same address by their pspace number, keeping
11855 locations of the same inferior (in a multi-inferior environment)
11858 if (a
->pspace
->num
!= b
->pspace
->num
)
11859 return ((a
->pspace
->num
> b
->pspace
->num
)
11860 - (a
->pspace
->num
< b
->pspace
->num
));
11862 /* Sort permanent breakpoints first. */
11863 if (a
->permanent
!= b
->permanent
)
11864 return (a
->permanent
< b
->permanent
) - (a
->permanent
> b
->permanent
);
11866 /* Make the internal GDB representation stable across GDB runs
11867 where A and B memory inside GDB can differ. Breakpoint locations of
11868 the same type at the same address can be sorted in arbitrary order. */
11870 if (a
->owner
->number
!= b
->owner
->number
)
11871 return ((a
->owner
->number
> b
->owner
->number
)
11872 - (a
->owner
->number
< b
->owner
->number
));
11874 return (a
> b
) - (a
< b
);
11877 /* Set bp_locations_placed_address_before_address_max and
11878 bp_locations_shadow_len_after_address_max according to the current
11879 content of the bp_locations array. */
11882 bp_locations_target_extensions_update (void)
11884 struct bp_location
*bl
, **blp_tmp
;
11886 bp_locations_placed_address_before_address_max
= 0;
11887 bp_locations_shadow_len_after_address_max
= 0;
11889 ALL_BP_LOCATIONS (bl
, blp_tmp
)
11891 CORE_ADDR start
, end
, addr
;
11893 if (!bp_location_has_shadow (bl
))
11896 start
= bl
->target_info
.placed_address
;
11897 end
= start
+ bl
->target_info
.shadow_len
;
11899 gdb_assert (bl
->address
>= start
);
11900 addr
= bl
->address
- start
;
11901 if (addr
> bp_locations_placed_address_before_address_max
)
11902 bp_locations_placed_address_before_address_max
= addr
;
11904 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
11906 gdb_assert (bl
->address
< end
);
11907 addr
= end
- bl
->address
;
11908 if (addr
> bp_locations_shadow_len_after_address_max
)
11909 bp_locations_shadow_len_after_address_max
= addr
;
11913 /* Download tracepoint locations if they haven't been. */
11916 download_tracepoint_locations (void)
11918 struct breakpoint
*b
;
11919 enum tribool can_download_tracepoint
= TRIBOOL_UNKNOWN
;
11921 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
11923 ALL_TRACEPOINTS (b
)
11925 struct bp_location
*bl
;
11926 struct tracepoint
*t
;
11927 int bp_location_downloaded
= 0;
11929 if ((b
->type
== bp_fast_tracepoint
11930 ? !may_insert_fast_tracepoints
11931 : !may_insert_tracepoints
))
11934 if (can_download_tracepoint
== TRIBOOL_UNKNOWN
)
11936 if (target_can_download_tracepoint ())
11937 can_download_tracepoint
= TRIBOOL_TRUE
;
11939 can_download_tracepoint
= TRIBOOL_FALSE
;
11942 if (can_download_tracepoint
== TRIBOOL_FALSE
)
11945 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
11947 /* In tracepoint, locations are _never_ duplicated, so
11948 should_be_inserted is equivalent to
11949 unduplicated_should_be_inserted. */
11950 if (!should_be_inserted (bl
) || bl
->inserted
)
11953 switch_to_program_space_and_thread (bl
->pspace
);
11955 target_download_tracepoint (bl
);
11958 bp_location_downloaded
= 1;
11960 t
= (struct tracepoint
*) b
;
11961 t
->number_on_target
= b
->number
;
11962 if (bp_location_downloaded
)
11963 observer_notify_breakpoint_modified (b
);
11967 /* Swap the insertion/duplication state between two locations. */
11970 swap_insertion (struct bp_location
*left
, struct bp_location
*right
)
11972 const int left_inserted
= left
->inserted
;
11973 const int left_duplicate
= left
->duplicate
;
11974 const int left_needs_update
= left
->needs_update
;
11975 const struct bp_target_info left_target_info
= left
->target_info
;
11977 /* Locations of tracepoints can never be duplicated. */
11978 if (is_tracepoint (left
->owner
))
11979 gdb_assert (!left
->duplicate
);
11980 if (is_tracepoint (right
->owner
))
11981 gdb_assert (!right
->duplicate
);
11983 left
->inserted
= right
->inserted
;
11984 left
->duplicate
= right
->duplicate
;
11985 left
->needs_update
= right
->needs_update
;
11986 left
->target_info
= right
->target_info
;
11987 right
->inserted
= left_inserted
;
11988 right
->duplicate
= left_duplicate
;
11989 right
->needs_update
= left_needs_update
;
11990 right
->target_info
= left_target_info
;
11993 /* Force the re-insertion of the locations at ADDRESS. This is called
11994 once a new/deleted/modified duplicate location is found and we are evaluating
11995 conditions on the target's side. Such conditions need to be updated on
11999 force_breakpoint_reinsertion (struct bp_location
*bl
)
12001 struct bp_location
**locp
= NULL
, **loc2p
;
12002 struct bp_location
*loc
;
12003 CORE_ADDR address
= 0;
12006 address
= bl
->address
;
12007 pspace_num
= bl
->pspace
->num
;
12009 /* This is only meaningful if the target is
12010 evaluating conditions and if the user has
12011 opted for condition evaluation on the target's
12013 if (gdb_evaluates_breakpoint_condition_p ()
12014 || !target_supports_evaluation_of_breakpoint_conditions ())
12017 /* Flag all breakpoint locations with this address and
12018 the same program space as the location
12019 as "its condition has changed". We need to
12020 update the conditions on the target's side. */
12021 ALL_BP_LOCATIONS_AT_ADDR (loc2p
, locp
, address
)
12025 if (!is_breakpoint (loc
->owner
)
12026 || pspace_num
!= loc
->pspace
->num
)
12029 /* Flag the location appropriately. We use a different state to
12030 let everyone know that we already updated the set of locations
12031 with addr bl->address and program space bl->pspace. This is so
12032 we don't have to keep calling these functions just to mark locations
12033 that have already been marked. */
12034 loc
->condition_changed
= condition_updated
;
12036 /* Free the agent expression bytecode as well. We will compute
12038 loc
->cond_bytecode
.reset ();
12041 /* Called whether new breakpoints are created, or existing breakpoints
12042 deleted, to update the global location list and recompute which
12043 locations are duplicate of which.
12045 The INSERT_MODE flag determines whether locations may not, may, or
12046 shall be inserted now. See 'enum ugll_insert_mode' for more
12050 update_global_location_list (enum ugll_insert_mode insert_mode
)
12052 struct breakpoint
*b
;
12053 struct bp_location
**locp
, *loc
;
12054 struct cleanup
*cleanups
;
12055 /* Last breakpoint location address that was marked for update. */
12056 CORE_ADDR last_addr
= 0;
12057 /* Last breakpoint location program space that was marked for update. */
12058 int last_pspace_num
= -1;
12060 /* Used in the duplicates detection below. When iterating over all
12061 bp_locations, points to the first bp_location of a given address.
12062 Breakpoints and watchpoints of different types are never
12063 duplicates of each other. Keep one pointer for each type of
12064 breakpoint/watchpoint, so we only need to loop over all locations
12066 struct bp_location
*bp_loc_first
; /* breakpoint */
12067 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
12068 struct bp_location
*awp_loc_first
; /* access watchpoint */
12069 struct bp_location
*rwp_loc_first
; /* read watchpoint */
12071 /* Saved former bp_locations array which we compare against the newly
12072 built bp_locations from the current state of ALL_BREAKPOINTS. */
12073 struct bp_location
**old_locations
, **old_locp
;
12074 unsigned old_locations_count
;
12076 old_locations
= bp_locations
;
12077 old_locations_count
= bp_locations_count
;
12078 bp_locations
= NULL
;
12079 bp_locations_count
= 0;
12080 cleanups
= make_cleanup (xfree
, old_locations
);
12082 ALL_BREAKPOINTS (b
)
12083 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12084 bp_locations_count
++;
12086 bp_locations
= XNEWVEC (struct bp_location
*, bp_locations_count
);
12087 locp
= bp_locations
;
12088 ALL_BREAKPOINTS (b
)
12089 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
12091 qsort (bp_locations
, bp_locations_count
, sizeof (*bp_locations
),
12092 bp_locations_compare
);
12094 bp_locations_target_extensions_update ();
12096 /* Identify bp_location instances that are no longer present in the
12097 new list, and therefore should be freed. Note that it's not
12098 necessary that those locations should be removed from inferior --
12099 if there's another location at the same address (previously
12100 marked as duplicate), we don't need to remove/insert the
12103 LOCP is kept in sync with OLD_LOCP, each pointing to the current
12104 and former bp_location array state respectively. */
12106 locp
= bp_locations
;
12107 for (old_locp
= old_locations
;
12108 old_locp
< old_locations
+ old_locations_count
;
12111 struct bp_location
*old_loc
= *old_locp
;
12112 struct bp_location
**loc2p
;
12114 /* Tells if 'old_loc' is found among the new locations. If
12115 not, we have to free it. */
12116 int found_object
= 0;
12117 /* Tells if the location should remain inserted in the target. */
12118 int keep_in_target
= 0;
12121 /* Skip LOCP entries which will definitely never be needed.
12122 Stop either at or being the one matching OLD_LOC. */
12123 while (locp
< bp_locations
+ bp_locations_count
12124 && (*locp
)->address
< old_loc
->address
)
12128 (loc2p
< bp_locations
+ bp_locations_count
12129 && (*loc2p
)->address
== old_loc
->address
);
12132 /* Check if this is a new/duplicated location or a duplicated
12133 location that had its condition modified. If so, we want to send
12134 its condition to the target if evaluation of conditions is taking
12136 if ((*loc2p
)->condition_changed
== condition_modified
12137 && (last_addr
!= old_loc
->address
12138 || last_pspace_num
!= old_loc
->pspace
->num
))
12140 force_breakpoint_reinsertion (*loc2p
);
12141 last_pspace_num
= old_loc
->pspace
->num
;
12144 if (*loc2p
== old_loc
)
12148 /* We have already handled this address, update it so that we don't
12149 have to go through updates again. */
12150 last_addr
= old_loc
->address
;
12152 /* Target-side condition evaluation: Handle deleted locations. */
12154 force_breakpoint_reinsertion (old_loc
);
12156 /* If this location is no longer present, and inserted, look if
12157 there's maybe a new location at the same address. If so,
12158 mark that one inserted, and don't remove this one. This is
12159 needed so that we don't have a time window where a breakpoint
12160 at certain location is not inserted. */
12162 if (old_loc
->inserted
)
12164 /* If the location is inserted now, we might have to remove
12167 if (found_object
&& should_be_inserted (old_loc
))
12169 /* The location is still present in the location list,
12170 and still should be inserted. Don't do anything. */
12171 keep_in_target
= 1;
12175 /* This location still exists, but it won't be kept in the
12176 target since it may have been disabled. We proceed to
12177 remove its target-side condition. */
12179 /* The location is either no longer present, or got
12180 disabled. See if there's another location at the
12181 same address, in which case we don't need to remove
12182 this one from the target. */
12184 /* OLD_LOC comes from existing struct breakpoint. */
12185 if (breakpoint_address_is_meaningful (old_loc
->owner
))
12188 (loc2p
< bp_locations
+ bp_locations_count
12189 && (*loc2p
)->address
== old_loc
->address
);
12192 struct bp_location
*loc2
= *loc2p
;
12194 if (breakpoint_locations_match (loc2
, old_loc
))
12196 /* Read watchpoint locations are switched to
12197 access watchpoints, if the former are not
12198 supported, but the latter are. */
12199 if (is_hardware_watchpoint (old_loc
->owner
))
12201 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
12202 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
12205 /* loc2 is a duplicated location. We need to check
12206 if it should be inserted in case it will be
12208 if (loc2
!= old_loc
12209 && unduplicated_should_be_inserted (loc2
))
12211 swap_insertion (old_loc
, loc2
);
12212 keep_in_target
= 1;
12220 if (!keep_in_target
)
12222 if (remove_breakpoint (old_loc
))
12224 /* This is just about all we can do. We could keep
12225 this location on the global list, and try to
12226 remove it next time, but there's no particular
12227 reason why we will succeed next time.
12229 Note that at this point, old_loc->owner is still
12230 valid, as delete_breakpoint frees the breakpoint
12231 only after calling us. */
12232 printf_filtered (_("warning: Error removing "
12233 "breakpoint %d\n"),
12234 old_loc
->owner
->number
);
12242 if (removed
&& target_is_non_stop_p ()
12243 && need_moribund_for_location_type (old_loc
))
12245 /* This location was removed from the target. In
12246 non-stop mode, a race condition is possible where
12247 we've removed a breakpoint, but stop events for that
12248 breakpoint are already queued and will arrive later.
12249 We apply an heuristic to be able to distinguish such
12250 SIGTRAPs from other random SIGTRAPs: we keep this
12251 breakpoint location for a bit, and will retire it
12252 after we see some number of events. The theory here
12253 is that reporting of events should, "on the average",
12254 be fair, so after a while we'll see events from all
12255 threads that have anything of interest, and no longer
12256 need to keep this breakpoint location around. We
12257 don't hold locations forever so to reduce chances of
12258 mistaking a non-breakpoint SIGTRAP for a breakpoint
12261 The heuristic failing can be disastrous on
12262 decr_pc_after_break targets.
12264 On decr_pc_after_break targets, like e.g., x86-linux,
12265 if we fail to recognize a late breakpoint SIGTRAP,
12266 because events_till_retirement has reached 0 too
12267 soon, we'll fail to do the PC adjustment, and report
12268 a random SIGTRAP to the user. When the user resumes
12269 the inferior, it will most likely immediately crash
12270 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently
12271 corrupted, because of being resumed e.g., in the
12272 middle of a multi-byte instruction, or skipped a
12273 one-byte instruction. This was actually seen happen
12274 on native x86-linux, and should be less rare on
12275 targets that do not support new thread events, like
12276 remote, due to the heuristic depending on
12279 Mistaking a random SIGTRAP for a breakpoint trap
12280 causes similar symptoms (PC adjustment applied when
12281 it shouldn't), but then again, playing with SIGTRAPs
12282 behind the debugger's back is asking for trouble.
12284 Since hardware watchpoint traps are always
12285 distinguishable from other traps, so we don't need to
12286 apply keep hardware watchpoint moribund locations
12287 around. We simply always ignore hardware watchpoint
12288 traps we can no longer explain. */
12290 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
12291 old_loc
->owner
= NULL
;
12293 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
12297 old_loc
->owner
= NULL
;
12298 decref_bp_location (&old_loc
);
12303 /* Rescan breakpoints at the same address and section, marking the
12304 first one as "first" and any others as "duplicates". This is so
12305 that the bpt instruction is only inserted once. If we have a
12306 permanent breakpoint at the same place as BPT, make that one the
12307 official one, and the rest as duplicates. Permanent breakpoints
12308 are sorted first for the same address.
12310 Do the same for hardware watchpoints, but also considering the
12311 watchpoint's type (regular/access/read) and length. */
12313 bp_loc_first
= NULL
;
12314 wp_loc_first
= NULL
;
12315 awp_loc_first
= NULL
;
12316 rwp_loc_first
= NULL
;
12317 ALL_BP_LOCATIONS (loc
, locp
)
12319 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always
12321 struct bp_location
**loc_first_p
;
12324 if (!unduplicated_should_be_inserted (loc
)
12325 || !breakpoint_address_is_meaningful (b
)
12326 /* Don't detect duplicate for tracepoint locations because they are
12327 never duplicated. See the comments in field `duplicate' of
12328 `struct bp_location'. */
12329 || is_tracepoint (b
))
12331 /* Clear the condition modification flag. */
12332 loc
->condition_changed
= condition_unchanged
;
12336 if (b
->type
== bp_hardware_watchpoint
)
12337 loc_first_p
= &wp_loc_first
;
12338 else if (b
->type
== bp_read_watchpoint
)
12339 loc_first_p
= &rwp_loc_first
;
12340 else if (b
->type
== bp_access_watchpoint
)
12341 loc_first_p
= &awp_loc_first
;
12343 loc_first_p
= &bp_loc_first
;
12345 if (*loc_first_p
== NULL
12346 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
12347 || !breakpoint_locations_match (loc
, *loc_first_p
))
12349 *loc_first_p
= loc
;
12350 loc
->duplicate
= 0;
12352 if (is_breakpoint (loc
->owner
) && loc
->condition_changed
)
12354 loc
->needs_update
= 1;
12355 /* Clear the condition modification flag. */
12356 loc
->condition_changed
= condition_unchanged
;
12362 /* This and the above ensure the invariant that the first location
12363 is not duplicated, and is the inserted one.
12364 All following are marked as duplicated, and are not inserted. */
12366 swap_insertion (loc
, *loc_first_p
);
12367 loc
->duplicate
= 1;
12369 /* Clear the condition modification flag. */
12370 loc
->condition_changed
= condition_unchanged
;
12373 if (insert_mode
== UGLL_INSERT
|| breakpoints_should_be_inserted_now ())
12375 if (insert_mode
!= UGLL_DONT_INSERT
)
12376 insert_breakpoint_locations ();
12379 /* Even though the caller told us to not insert new
12380 locations, we may still need to update conditions on the
12381 target's side of breakpoints that were already inserted
12382 if the target is evaluating breakpoint conditions. We
12383 only update conditions for locations that are marked
12385 update_inserted_breakpoint_locations ();
12389 if (insert_mode
!= UGLL_DONT_INSERT
)
12390 download_tracepoint_locations ();
12392 do_cleanups (cleanups
);
12396 breakpoint_retire_moribund (void)
12398 struct bp_location
*loc
;
12401 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
12402 if (--(loc
->events_till_retirement
) == 0)
12404 decref_bp_location (&loc
);
12405 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
12411 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode
)
12416 update_global_location_list (insert_mode
);
12418 CATCH (e
, RETURN_MASK_ERROR
)
12424 /* Clear BKP from a BPS. */
12427 bpstat_remove_bp_location (bpstat bps
, struct breakpoint
*bpt
)
12431 for (bs
= bps
; bs
; bs
= bs
->next
)
12432 if (bs
->breakpoint_at
== bpt
)
12434 bs
->breakpoint_at
= NULL
;
12435 bs
->old_val
= NULL
;
12436 /* bs->commands will be freed later. */
12440 /* Callback for iterate_over_threads. */
12442 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
12444 struct breakpoint
*bpt
= (struct breakpoint
*) data
;
12446 bpstat_remove_bp_location (th
->control
.stop_bpstat
, bpt
);
12450 /* Helper for breakpoint and tracepoint breakpoint_ops->mention
12454 say_where (struct breakpoint
*b
)
12456 struct value_print_options opts
;
12458 get_user_print_options (&opts
);
12460 /* i18n: cagney/2005-02-11: Below needs to be merged into a
12462 if (b
->loc
== NULL
)
12464 /* For pending locations, the output differs slightly based
12465 on b->extra_string. If this is non-NULL, it contains either
12466 a condition or dprintf arguments. */
12467 if (b
->extra_string
== NULL
)
12469 printf_filtered (_(" (%s) pending."),
12470 event_location_to_string (b
->location
.get ()));
12472 else if (b
->type
== bp_dprintf
)
12474 printf_filtered (_(" (%s,%s) pending."),
12475 event_location_to_string (b
->location
.get ()),
12480 printf_filtered (_(" (%s %s) pending."),
12481 event_location_to_string (b
->location
.get ()),
12487 if (opts
.addressprint
|| b
->loc
->symtab
== NULL
)
12489 printf_filtered (" at ");
12490 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
12493 if (b
->loc
->symtab
!= NULL
)
12495 /* If there is a single location, we can print the location
12497 if (b
->loc
->next
== NULL
)
12498 printf_filtered (": file %s, line %d.",
12499 symtab_to_filename_for_display (b
->loc
->symtab
),
12500 b
->loc
->line_number
);
12502 /* This is not ideal, but each location may have a
12503 different file name, and this at least reflects the
12504 real situation somewhat. */
12505 printf_filtered (": %s.",
12506 event_location_to_string (b
->location
.get ()));
12511 struct bp_location
*loc
= b
->loc
;
12513 for (; loc
; loc
= loc
->next
)
12515 printf_filtered (" (%d locations)", n
);
12520 /* Default bp_location_ops methods. */
12523 bp_location_dtor (struct bp_location
*self
)
12525 xfree (self
->function_name
);
12528 static const struct bp_location_ops bp_location_ops
=
12533 /* Destructor for the breakpoint base class. */
12535 breakpoint::~breakpoint ()
12537 xfree (this->cond_string
);
12538 xfree (this->extra_string
);
12539 xfree (this->filter
);
12542 static struct bp_location
*
12543 base_breakpoint_allocate_location (struct breakpoint
*self
)
12545 return new bp_location (&bp_location_ops
, self
);
12549 base_breakpoint_re_set (struct breakpoint
*b
)
12551 /* Nothing to re-set. */
12554 #define internal_error_pure_virtual_called() \
12555 gdb_assert_not_reached ("pure virtual function called")
12558 base_breakpoint_insert_location (struct bp_location
*bl
)
12560 internal_error_pure_virtual_called ();
12564 base_breakpoint_remove_location (struct bp_location
*bl
,
12565 enum remove_bp_reason reason
)
12567 internal_error_pure_virtual_called ();
12571 base_breakpoint_breakpoint_hit (const struct bp_location
*bl
,
12572 struct address_space
*aspace
,
12574 const struct target_waitstatus
*ws
)
12576 internal_error_pure_virtual_called ();
12580 base_breakpoint_check_status (bpstat bs
)
12585 /* A "works_in_software_mode" breakpoint_ops method that just internal
12589 base_breakpoint_works_in_software_mode (const struct breakpoint
*b
)
12591 internal_error_pure_virtual_called ();
12594 /* A "resources_needed" breakpoint_ops method that just internal
12598 base_breakpoint_resources_needed (const struct bp_location
*bl
)
12600 internal_error_pure_virtual_called ();
12603 static enum print_stop_action
12604 base_breakpoint_print_it (bpstat bs
)
12606 internal_error_pure_virtual_called ();
12610 base_breakpoint_print_one_detail (const struct breakpoint
*self
,
12611 struct ui_out
*uiout
)
12617 base_breakpoint_print_mention (struct breakpoint
*b
)
12619 internal_error_pure_virtual_called ();
12623 base_breakpoint_print_recreate (struct breakpoint
*b
, struct ui_file
*fp
)
12625 internal_error_pure_virtual_called ();
12629 base_breakpoint_create_sals_from_location
12630 (const struct event_location
*location
,
12631 struct linespec_result
*canonical
,
12632 enum bptype type_wanted
)
12634 internal_error_pure_virtual_called ();
12638 base_breakpoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12639 struct linespec_result
*c
,
12640 gdb::unique_xmalloc_ptr
<char> cond_string
,
12641 gdb::unique_xmalloc_ptr
<char> extra_string
,
12642 enum bptype type_wanted
,
12643 enum bpdisp disposition
,
12645 int task
, int ignore_count
,
12646 const struct breakpoint_ops
*o
,
12647 int from_tty
, int enabled
,
12648 int internal
, unsigned flags
)
12650 internal_error_pure_virtual_called ();
12653 static std::vector
<symtab_and_line
>
12654 base_breakpoint_decode_location (struct breakpoint
*b
,
12655 const struct event_location
*location
,
12656 struct program_space
*search_pspace
)
12658 internal_error_pure_virtual_called ();
12661 /* The default 'explains_signal' method. */
12664 base_breakpoint_explains_signal (struct breakpoint
*b
, enum gdb_signal sig
)
12669 /* The default "after_condition_true" method. */
12672 base_breakpoint_after_condition_true (struct bpstats
*bs
)
12674 /* Nothing to do. */
12677 struct breakpoint_ops base_breakpoint_ops
=
12679 base_breakpoint_allocate_location
,
12680 base_breakpoint_re_set
,
12681 base_breakpoint_insert_location
,
12682 base_breakpoint_remove_location
,
12683 base_breakpoint_breakpoint_hit
,
12684 base_breakpoint_check_status
,
12685 base_breakpoint_resources_needed
,
12686 base_breakpoint_works_in_software_mode
,
12687 base_breakpoint_print_it
,
12689 base_breakpoint_print_one_detail
,
12690 base_breakpoint_print_mention
,
12691 base_breakpoint_print_recreate
,
12692 base_breakpoint_create_sals_from_location
,
12693 base_breakpoint_create_breakpoints_sal
,
12694 base_breakpoint_decode_location
,
12695 base_breakpoint_explains_signal
,
12696 base_breakpoint_after_condition_true
,
12699 /* Default breakpoint_ops methods. */
12702 bkpt_re_set (struct breakpoint
*b
)
12704 /* FIXME: is this still reachable? */
12705 if (breakpoint_event_location_empty_p (b
))
12707 /* Anything without a location can't be re-set. */
12708 delete_breakpoint (b
);
12712 breakpoint_re_set_default (b
);
12716 bkpt_insert_location (struct bp_location
*bl
)
12718 CORE_ADDR addr
= bl
->target_info
.reqstd_address
;
12720 bl
->target_info
.kind
= breakpoint_kind (bl
, &addr
);
12721 bl
->target_info
.placed_address
= addr
;
12723 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12724 return target_insert_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12726 return target_insert_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12730 bkpt_remove_location (struct bp_location
*bl
, enum remove_bp_reason reason
)
12732 if (bl
->loc_type
== bp_loc_hardware_breakpoint
)
12733 return target_remove_hw_breakpoint (bl
->gdbarch
, &bl
->target_info
);
12735 return target_remove_breakpoint (bl
->gdbarch
, &bl
->target_info
, reason
);
12739 bkpt_breakpoint_hit (const struct bp_location
*bl
,
12740 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12741 const struct target_waitstatus
*ws
)
12743 if (ws
->kind
!= TARGET_WAITKIND_STOPPED
12744 || ws
->value
.sig
!= GDB_SIGNAL_TRAP
)
12747 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
12751 if (overlay_debugging
/* unmapped overlay section */
12752 && section_is_overlay (bl
->section
)
12753 && !section_is_mapped (bl
->section
))
12760 dprintf_breakpoint_hit (const struct bp_location
*bl
,
12761 struct address_space
*aspace
, CORE_ADDR bp_addr
,
12762 const struct target_waitstatus
*ws
)
12764 if (dprintf_style
== dprintf_style_agent
12765 && target_can_run_breakpoint_commands ())
12767 /* An agent-style dprintf never causes a stop. If we see a trap
12768 for this address it must be for a breakpoint that happens to
12769 be set at the same address. */
12773 return bkpt_breakpoint_hit (bl
, aspace
, bp_addr
, ws
);
12777 bkpt_resources_needed (const struct bp_location
*bl
)
12779 gdb_assert (bl
->owner
->type
== bp_hardware_breakpoint
);
12784 static enum print_stop_action
12785 bkpt_print_it (bpstat bs
)
12787 struct breakpoint
*b
;
12788 const struct bp_location
*bl
;
12790 struct ui_out
*uiout
= current_uiout
;
12792 gdb_assert (bs
->bp_location_at
!= NULL
);
12794 bl
= bs
->bp_location_at
;
12795 b
= bs
->breakpoint_at
;
12797 bp_temp
= b
->disposition
== disp_del
;
12798 if (bl
->address
!= bl
->requested_address
)
12799 breakpoint_adjustment_warning (bl
->requested_address
,
12802 annotate_breakpoint (b
->number
);
12803 maybe_print_thread_hit_breakpoint (uiout
);
12806 uiout
->text ("Temporary breakpoint ");
12808 uiout
->text ("Breakpoint ");
12809 if (uiout
->is_mi_like_p ())
12811 uiout
->field_string ("reason",
12812 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
12813 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
12815 uiout
->field_int ("bkptno", b
->number
);
12816 uiout
->text (", ");
12818 return PRINT_SRC_AND_LOC
;
12822 bkpt_print_mention (struct breakpoint
*b
)
12824 if (current_uiout
->is_mi_like_p ())
12829 case bp_breakpoint
:
12830 case bp_gnu_ifunc_resolver
:
12831 if (b
->disposition
== disp_del
)
12832 printf_filtered (_("Temporary breakpoint"));
12834 printf_filtered (_("Breakpoint"));
12835 printf_filtered (_(" %d"), b
->number
);
12836 if (b
->type
== bp_gnu_ifunc_resolver
)
12837 printf_filtered (_(" at gnu-indirect-function resolver"));
12839 case bp_hardware_breakpoint
:
12840 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
12843 printf_filtered (_("Dprintf %d"), b
->number
);
12851 bkpt_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
12853 if (tp
->type
== bp_breakpoint
&& tp
->disposition
== disp_del
)
12854 fprintf_unfiltered (fp
, "tbreak");
12855 else if (tp
->type
== bp_breakpoint
)
12856 fprintf_unfiltered (fp
, "break");
12857 else if (tp
->type
== bp_hardware_breakpoint
12858 && tp
->disposition
== disp_del
)
12859 fprintf_unfiltered (fp
, "thbreak");
12860 else if (tp
->type
== bp_hardware_breakpoint
)
12861 fprintf_unfiltered (fp
, "hbreak");
12863 internal_error (__FILE__
, __LINE__
,
12864 _("unhandled breakpoint type %d"), (int) tp
->type
);
12866 fprintf_unfiltered (fp
, " %s",
12867 event_location_to_string (tp
->location
.get ()));
12869 /* Print out extra_string if this breakpoint is pending. It might
12870 contain, for example, conditions that were set by the user. */
12871 if (tp
->loc
== NULL
&& tp
->extra_string
!= NULL
)
12872 fprintf_unfiltered (fp
, " %s", tp
->extra_string
);
12874 print_recreate_thread (tp
, fp
);
12878 bkpt_create_sals_from_location (const struct event_location
*location
,
12879 struct linespec_result
*canonical
,
12880 enum bptype type_wanted
)
12882 create_sals_from_location_default (location
, canonical
, type_wanted
);
12886 bkpt_create_breakpoints_sal (struct gdbarch
*gdbarch
,
12887 struct linespec_result
*canonical
,
12888 gdb::unique_xmalloc_ptr
<char> cond_string
,
12889 gdb::unique_xmalloc_ptr
<char> extra_string
,
12890 enum bptype type_wanted
,
12891 enum bpdisp disposition
,
12893 int task
, int ignore_count
,
12894 const struct breakpoint_ops
*ops
,
12895 int from_tty
, int enabled
,
12896 int internal
, unsigned flags
)
12898 create_breakpoints_sal_default (gdbarch
, canonical
,
12899 std::move (cond_string
),
12900 std::move (extra_string
),
12902 disposition
, thread
, task
,
12903 ignore_count
, ops
, from_tty
,
12904 enabled
, internal
, flags
);
12907 static std::vector
<symtab_and_line
>
12908 bkpt_decode_location (struct breakpoint
*b
,
12909 const struct event_location
*location
,
12910 struct program_space
*search_pspace
)
12912 return decode_location_default (b
, location
, search_pspace
);
12915 /* Virtual table for internal breakpoints. */
12918 internal_bkpt_re_set (struct breakpoint
*b
)
12922 /* Delete overlay event and longjmp master breakpoints; they
12923 will be reset later by breakpoint_re_set. */
12924 case bp_overlay_event
:
12925 case bp_longjmp_master
:
12926 case bp_std_terminate_master
:
12927 case bp_exception_master
:
12928 delete_breakpoint (b
);
12931 /* This breakpoint is special, it's set up when the inferior
12932 starts and we really don't want to touch it. */
12933 case bp_shlib_event
:
12935 /* Like bp_shlib_event, this breakpoint type is special. Once
12936 it is set up, we do not want to touch it. */
12937 case bp_thread_event
:
12943 internal_bkpt_check_status (bpstat bs
)
12945 if (bs
->breakpoint_at
->type
== bp_shlib_event
)
12947 /* If requested, stop when the dynamic linker notifies GDB of
12948 events. This allows the user to get control and place
12949 breakpoints in initializer routines for dynamically loaded
12950 objects (among other things). */
12951 bs
->stop
= stop_on_solib_events
;
12952 bs
->print
= stop_on_solib_events
;
12958 static enum print_stop_action
12959 internal_bkpt_print_it (bpstat bs
)
12961 struct breakpoint
*b
;
12963 b
= bs
->breakpoint_at
;
12967 case bp_shlib_event
:
12968 /* Did we stop because the user set the stop_on_solib_events
12969 variable? (If so, we report this as a generic, "Stopped due
12970 to shlib event" message.) */
12971 print_solib_event (0);
12974 case bp_thread_event
:
12975 /* Not sure how we will get here.
12976 GDB should not stop for these breakpoints. */
12977 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
12980 case bp_overlay_event
:
12981 /* By analogy with the thread event, GDB should not stop for these. */
12982 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
12985 case bp_longjmp_master
:
12986 /* These should never be enabled. */
12987 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
12990 case bp_std_terminate_master
:
12991 /* These should never be enabled. */
12992 printf_filtered (_("std::terminate Master Breakpoint: "
12993 "gdb should not stop!\n"));
12996 case bp_exception_master
:
12997 /* These should never be enabled. */
12998 printf_filtered (_("Exception Master Breakpoint: "
12999 "gdb should not stop!\n"));
13003 return PRINT_NOTHING
;
13007 internal_bkpt_print_mention (struct breakpoint
*b
)
13009 /* Nothing to mention. These breakpoints are internal. */
13012 /* Virtual table for momentary breakpoints */
13015 momentary_bkpt_re_set (struct breakpoint
*b
)
13017 /* Keep temporary breakpoints, which can be encountered when we step
13018 over a dlopen call and solib_add is resetting the breakpoints.
13019 Otherwise these should have been blown away via the cleanup chain
13020 or by breakpoint_init_inferior when we rerun the executable. */
13024 momentary_bkpt_check_status (bpstat bs
)
13026 /* Nothing. The point of these breakpoints is causing a stop. */
13029 static enum print_stop_action
13030 momentary_bkpt_print_it (bpstat bs
)
13032 return PRINT_UNKNOWN
;
13036 momentary_bkpt_print_mention (struct breakpoint
*b
)
13038 /* Nothing to mention. These breakpoints are internal. */
13041 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists.
13043 It gets cleared already on the removal of the first one of such placed
13044 breakpoints. This is OK as they get all removed altogether. */
13046 longjmp_breakpoint::~longjmp_breakpoint ()
13048 thread_info
*tp
= find_thread_global_id (this->thread
);
13051 tp
->initiating_frame
= null_frame_id
;
13054 /* Specific methods for probe breakpoints. */
13057 bkpt_probe_insert_location (struct bp_location
*bl
)
13059 int v
= bkpt_insert_location (bl
);
13063 /* The insertion was successful, now let's set the probe's semaphore
13065 if (bl
->probe
.probe
->pops
->set_semaphore
!= NULL
)
13066 bl
->probe
.probe
->pops
->set_semaphore (bl
->probe
.probe
,
13075 bkpt_probe_remove_location (struct bp_location
*bl
,
13076 enum remove_bp_reason reason
)
13078 /* Let's clear the semaphore before removing the location. */
13079 if (bl
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
13080 bl
->probe
.probe
->pops
->clear_semaphore (bl
->probe
.probe
,
13084 return bkpt_remove_location (bl
, reason
);
13088 bkpt_probe_create_sals_from_location (const struct event_location
*location
,
13089 struct linespec_result
*canonical
,
13090 enum bptype type_wanted
)
13092 struct linespec_sals lsal
;
13094 lsal
.sals
= parse_probes (location
, NULL
, canonical
);
13096 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13097 canonical
->lsals
.push_back (std::move (lsal
));
13100 static std::vector
<symtab_and_line
>
13101 bkpt_probe_decode_location (struct breakpoint
*b
,
13102 const struct event_location
*location
,
13103 struct program_space
*search_pspace
)
13105 std::vector
<symtab_and_line
> sals
= parse_probes (location
, search_pspace
, NULL
);
13107 error (_("probe not found"));
13111 /* The breakpoint_ops structure to be used in tracepoints. */
13114 tracepoint_re_set (struct breakpoint
*b
)
13116 breakpoint_re_set_default (b
);
13120 tracepoint_breakpoint_hit (const struct bp_location
*bl
,
13121 struct address_space
*aspace
, CORE_ADDR bp_addr
,
13122 const struct target_waitstatus
*ws
)
13124 /* By definition, the inferior does not report stops at
13130 tracepoint_print_one_detail (const struct breakpoint
*self
,
13131 struct ui_out
*uiout
)
13133 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13134 if (tp
->static_trace_marker_id
)
13136 gdb_assert (self
->type
== bp_static_tracepoint
);
13138 uiout
->text ("\tmarker id is ");
13139 uiout
->field_string ("static-tracepoint-marker-string-id",
13140 tp
->static_trace_marker_id
);
13141 uiout
->text ("\n");
13146 tracepoint_print_mention (struct breakpoint
*b
)
13148 if (current_uiout
->is_mi_like_p ())
13153 case bp_tracepoint
:
13154 printf_filtered (_("Tracepoint"));
13155 printf_filtered (_(" %d"), b
->number
);
13157 case bp_fast_tracepoint
:
13158 printf_filtered (_("Fast tracepoint"));
13159 printf_filtered (_(" %d"), b
->number
);
13161 case bp_static_tracepoint
:
13162 printf_filtered (_("Static tracepoint"));
13163 printf_filtered (_(" %d"), b
->number
);
13166 internal_error (__FILE__
, __LINE__
,
13167 _("unhandled tracepoint type %d"), (int) b
->type
);
13174 tracepoint_print_recreate (struct breakpoint
*self
, struct ui_file
*fp
)
13176 struct tracepoint
*tp
= (struct tracepoint
*) self
;
13178 if (self
->type
== bp_fast_tracepoint
)
13179 fprintf_unfiltered (fp
, "ftrace");
13180 else if (self
->type
== bp_static_tracepoint
)
13181 fprintf_unfiltered (fp
, "strace");
13182 else if (self
->type
== bp_tracepoint
)
13183 fprintf_unfiltered (fp
, "trace");
13185 internal_error (__FILE__
, __LINE__
,
13186 _("unhandled tracepoint type %d"), (int) self
->type
);
13188 fprintf_unfiltered (fp
, " %s",
13189 event_location_to_string (self
->location
.get ()));
13190 print_recreate_thread (self
, fp
);
13192 if (tp
->pass_count
)
13193 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
13197 tracepoint_create_sals_from_location (const struct event_location
*location
,
13198 struct linespec_result
*canonical
,
13199 enum bptype type_wanted
)
13201 create_sals_from_location_default (location
, canonical
, type_wanted
);
13205 tracepoint_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13206 struct linespec_result
*canonical
,
13207 gdb::unique_xmalloc_ptr
<char> cond_string
,
13208 gdb::unique_xmalloc_ptr
<char> extra_string
,
13209 enum bptype type_wanted
,
13210 enum bpdisp disposition
,
13212 int task
, int ignore_count
,
13213 const struct breakpoint_ops
*ops
,
13214 int from_tty
, int enabled
,
13215 int internal
, unsigned flags
)
13217 create_breakpoints_sal_default (gdbarch
, canonical
,
13218 std::move (cond_string
),
13219 std::move (extra_string
),
13221 disposition
, thread
, task
,
13222 ignore_count
, ops
, from_tty
,
13223 enabled
, internal
, flags
);
13226 static std::vector
<symtab_and_line
>
13227 tracepoint_decode_location (struct breakpoint
*b
,
13228 const struct event_location
*location
,
13229 struct program_space
*search_pspace
)
13231 return decode_location_default (b
, location
, search_pspace
);
13234 struct breakpoint_ops tracepoint_breakpoint_ops
;
13236 /* The breakpoint_ops structure to be use on tracepoints placed in a
13240 tracepoint_probe_create_sals_from_location
13241 (const struct event_location
*location
,
13242 struct linespec_result
*canonical
,
13243 enum bptype type_wanted
)
13245 /* We use the same method for breakpoint on probes. */
13246 bkpt_probe_create_sals_from_location (location
, canonical
, type_wanted
);
13249 static std::vector
<symtab_and_line
>
13250 tracepoint_probe_decode_location (struct breakpoint
*b
,
13251 const struct event_location
*location
,
13252 struct program_space
*search_pspace
)
13254 /* We use the same method for breakpoint on probes. */
13255 return bkpt_probe_decode_location (b
, location
, search_pspace
);
13258 static struct breakpoint_ops tracepoint_probe_breakpoint_ops
;
13260 /* Dprintf breakpoint_ops methods. */
13263 dprintf_re_set (struct breakpoint
*b
)
13265 breakpoint_re_set_default (b
);
13267 /* extra_string should never be non-NULL for dprintf. */
13268 gdb_assert (b
->extra_string
!= NULL
);
13270 /* 1 - connect to target 1, that can run breakpoint commands.
13271 2 - create a dprintf, which resolves fine.
13272 3 - disconnect from target 1
13273 4 - connect to target 2, that can NOT run breakpoint commands.
13275 After steps #3/#4, you'll want the dprintf command list to
13276 be updated, because target 1 and 2 may well return different
13277 answers for target_can_run_breakpoint_commands().
13278 Given absence of finer grained resetting, we get to do
13279 it all the time. */
13280 if (b
->extra_string
!= NULL
)
13281 update_dprintf_command_list (b
);
13284 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */
13287 dprintf_print_recreate (struct breakpoint
*tp
, struct ui_file
*fp
)
13289 fprintf_unfiltered (fp
, "dprintf %s,%s",
13290 event_location_to_string (tp
->location
.get ()),
13292 print_recreate_thread (tp
, fp
);
13295 /* Implement the "after_condition_true" breakpoint_ops method for
13298 dprintf's are implemented with regular commands in their command
13299 list, but we run the commands here instead of before presenting the
13300 stop to the user, as dprintf's don't actually cause a stop. This
13301 also makes it so that the commands of multiple dprintfs at the same
13302 address are all handled. */
13305 dprintf_after_condition_true (struct bpstats
*bs
)
13307 struct bpstats tmp_bs
;
13308 struct bpstats
*tmp_bs_p
= &tmp_bs
;
13310 /* dprintf's never cause a stop. This wasn't set in the
13311 check_status hook instead because that would make the dprintf's
13312 condition not be evaluated. */
13315 /* Run the command list here. Take ownership of it instead of
13316 copying. We never want these commands to run later in
13317 bpstat_do_actions, if a breakpoint that causes a stop happens to
13318 be set at same address as this dprintf, or even if running the
13319 commands here throws. */
13320 tmp_bs
.commands
= bs
->commands
;
13321 bs
->commands
= NULL
;
13323 bpstat_do_actions_1 (&tmp_bs_p
);
13325 /* 'tmp_bs.commands' will usually be NULL by now, but
13326 bpstat_do_actions_1 may return early without processing the whole
13330 /* The breakpoint_ops structure to be used on static tracepoints with
13334 strace_marker_create_sals_from_location (const struct event_location
*location
,
13335 struct linespec_result
*canonical
,
13336 enum bptype type_wanted
)
13338 struct linespec_sals lsal
;
13339 const char *arg_start
, *arg
;
13341 struct cleanup
*cleanup
;
13343 arg
= arg_start
= get_linespec_location (location
);
13344 lsal
.sals
= decode_static_tracepoint_spec (&arg
);
13346 str
= savestring (arg_start
, arg
- arg_start
);
13347 cleanup
= make_cleanup (xfree
, str
);
13348 canonical
->location
= new_linespec_location (&str
);
13349 do_cleanups (cleanup
);
13352 = xstrdup (event_location_to_string (canonical
->location
.get ()));
13353 canonical
->lsals
.push_back (std::move (lsal
));
13357 strace_marker_create_breakpoints_sal (struct gdbarch
*gdbarch
,
13358 struct linespec_result
*canonical
,
13359 gdb::unique_xmalloc_ptr
<char> cond_string
,
13360 gdb::unique_xmalloc_ptr
<char> extra_string
,
13361 enum bptype type_wanted
,
13362 enum bpdisp disposition
,
13364 int task
, int ignore_count
,
13365 const struct breakpoint_ops
*ops
,
13366 int from_tty
, int enabled
,
13367 int internal
, unsigned flags
)
13369 const linespec_sals
&lsal
= canonical
->lsals
[0];
13371 /* If the user is creating a static tracepoint by marker id
13372 (strace -m MARKER_ID), then store the sals index, so that
13373 breakpoint_re_set can try to match up which of the newly
13374 found markers corresponds to this one, and, don't try to
13375 expand multiple locations for each sal, given than SALS
13376 already should contain all sals for MARKER_ID. */
13378 for (size_t i
= 0; i
< lsal
.sals
.size (); i
++)
13380 event_location_up location
13381 = copy_event_location (canonical
->location
.get ());
13383 std::unique_ptr
<tracepoint
> tp (new tracepoint ());
13384 init_breakpoint_sal (tp
.get (), gdbarch
, lsal
.sals
[i
],
13385 std::move (location
), NULL
,
13386 std::move (cond_string
),
13387 std::move (extra_string
),
13388 type_wanted
, disposition
,
13389 thread
, task
, ignore_count
, ops
,
13390 from_tty
, enabled
, internal
, flags
,
13391 canonical
->special_display
);
13392 /* Given that its possible to have multiple markers with
13393 the same string id, if the user is creating a static
13394 tracepoint by marker id ("strace -m MARKER_ID"), then
13395 store the sals index, so that breakpoint_re_set can
13396 try to match up which of the newly found markers
13397 corresponds to this one */
13398 tp
->static_trace_marker_id_idx
= i
;
13400 install_breakpoint (internal
, std::move (tp
), 0);
13404 static std::vector
<symtab_and_line
>
13405 strace_marker_decode_location (struct breakpoint
*b
,
13406 const struct event_location
*location
,
13407 struct program_space
*search_pspace
)
13409 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13410 const char *s
= get_linespec_location (location
);
13412 std::vector
<symtab_and_line
> sals
= decode_static_tracepoint_spec (&s
);
13413 if (sals
.size () > tp
->static_trace_marker_id_idx
)
13415 sals
[0] = sals
[tp
->static_trace_marker_id_idx
];
13420 error (_("marker %s not found"), tp
->static_trace_marker_id
);
13423 static struct breakpoint_ops strace_marker_breakpoint_ops
;
13426 strace_marker_p (struct breakpoint
*b
)
13428 return b
->ops
== &strace_marker_breakpoint_ops
;
13431 /* Delete a breakpoint and clean up all traces of it in the data
13435 delete_breakpoint (struct breakpoint
*bpt
)
13437 struct breakpoint
*b
;
13439 gdb_assert (bpt
!= NULL
);
13441 /* Has this bp already been deleted? This can happen because
13442 multiple lists can hold pointers to bp's. bpstat lists are
13445 One example of this happening is a watchpoint's scope bp. When
13446 the scope bp triggers, we notice that the watchpoint is out of
13447 scope, and delete it. We also delete its scope bp. But the
13448 scope bp is marked "auto-deleting", and is already on a bpstat.
13449 That bpstat is then checked for auto-deleting bp's, which are
13452 A real solution to this problem might involve reference counts in
13453 bp's, and/or giving them pointers back to their referencing
13454 bpstat's, and teaching delete_breakpoint to only free a bp's
13455 storage when no more references were extent. A cheaper bandaid
13457 if (bpt
->type
== bp_none
)
13460 /* At least avoid this stale reference until the reference counting
13461 of breakpoints gets resolved. */
13462 if (bpt
->related_breakpoint
!= bpt
)
13464 struct breakpoint
*related
;
13465 struct watchpoint
*w
;
13467 if (bpt
->type
== bp_watchpoint_scope
)
13468 w
= (struct watchpoint
*) bpt
->related_breakpoint
;
13469 else if (bpt
->related_breakpoint
->type
== bp_watchpoint_scope
)
13470 w
= (struct watchpoint
*) bpt
;
13474 watchpoint_del_at_next_stop (w
);
13476 /* Unlink bpt from the bpt->related_breakpoint ring. */
13477 for (related
= bpt
; related
->related_breakpoint
!= bpt
;
13478 related
= related
->related_breakpoint
);
13479 related
->related_breakpoint
= bpt
->related_breakpoint
;
13480 bpt
->related_breakpoint
= bpt
;
13483 /* watch_command_1 creates a watchpoint but only sets its number if
13484 update_watchpoint succeeds in creating its bp_locations. If there's
13485 a problem in that process, we'll be asked to delete the half-created
13486 watchpoint. In that case, don't announce the deletion. */
13488 observer_notify_breakpoint_deleted (bpt
);
13490 if (breakpoint_chain
== bpt
)
13491 breakpoint_chain
= bpt
->next
;
13493 ALL_BREAKPOINTS (b
)
13494 if (b
->next
== bpt
)
13496 b
->next
= bpt
->next
;
13500 /* Be sure no bpstat's are pointing at the breakpoint after it's
13502 /* FIXME, how can we find all bpstat's? We just check stop_bpstat
13503 in all threads for now. Note that we cannot just remove bpstats
13504 pointing at bpt from the stop_bpstat list entirely, as breakpoint
13505 commands are associated with the bpstat; if we remove it here,
13506 then the later call to bpstat_do_actions (&stop_bpstat); in
13507 event-top.c won't do anything, and temporary breakpoints with
13508 commands won't work. */
13510 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
13512 /* Now that breakpoint is removed from breakpoint list, update the
13513 global location list. This will remove locations that used to
13514 belong to this breakpoint. Do this before freeing the breakpoint
13515 itself, since remove_breakpoint looks at location's owner. It
13516 might be better design to have location completely
13517 self-contained, but it's not the case now. */
13518 update_global_location_list (UGLL_DONT_INSERT
);
13520 /* On the chance that someone will soon try again to delete this
13521 same bp, we mark it as deleted before freeing its storage. */
13522 bpt
->type
= bp_none
;
13527 do_delete_breakpoint_cleanup (void *b
)
13529 delete_breakpoint ((struct breakpoint
*) b
);
13533 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
13535 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
13538 /* Iterator function to call a user-provided callback function once
13539 for each of B and its related breakpoints. */
13542 iterate_over_related_breakpoints (struct breakpoint
*b
,
13543 gdb::function_view
<void (breakpoint
*)> function
)
13545 struct breakpoint
*related
;
13550 struct breakpoint
*next
;
13552 /* FUNCTION may delete RELATED. */
13553 next
= related
->related_breakpoint
;
13555 if (next
== related
)
13557 /* RELATED is the last ring entry. */
13558 function (related
);
13560 /* FUNCTION may have deleted it, so we'd never reach back to
13561 B. There's nothing left to do anyway, so just break
13566 function (related
);
13570 while (related
!= b
);
13574 delete_command (char *arg
, int from_tty
)
13576 struct breakpoint
*b
, *b_tmp
;
13582 int breaks_to_delete
= 0;
13584 /* Delete all breakpoints if no argument. Do not delete
13585 internal breakpoints, these have to be deleted with an
13586 explicit breakpoint number argument. */
13587 ALL_BREAKPOINTS (b
)
13588 if (user_breakpoint_p (b
))
13590 breaks_to_delete
= 1;
13594 /* Ask user only if there are some breakpoints to delete. */
13596 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
13598 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
13599 if (user_breakpoint_p (b
))
13600 delete_breakpoint (b
);
13604 map_breakpoint_numbers
13605 (arg
, [&] (breakpoint
*b
)
13607 iterate_over_related_breakpoints (b
, delete_breakpoint
);
13611 /* Return true if all locations of B bound to PSPACE are pending. If
13612 PSPACE is NULL, all locations of all program spaces are
13616 all_locations_are_pending (struct breakpoint
*b
, struct program_space
*pspace
)
13618 struct bp_location
*loc
;
13620 for (loc
= b
->loc
; loc
!= NULL
; loc
= loc
->next
)
13621 if ((pspace
== NULL
13622 || loc
->pspace
== pspace
)
13623 && !loc
->shlib_disabled
13624 && !loc
->pspace
->executing_startup
)
13629 /* Subroutine of update_breakpoint_locations to simplify it.
13630 Return non-zero if multiple fns in list LOC have the same name.
13631 Null names are ignored. */
13634 ambiguous_names_p (struct bp_location
*loc
)
13636 struct bp_location
*l
;
13637 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
13638 (int (*) (const void *,
13639 const void *)) streq
,
13640 NULL
, xcalloc
, xfree
);
13642 for (l
= loc
; l
!= NULL
; l
= l
->next
)
13645 const char *name
= l
->function_name
;
13647 /* Allow for some names to be NULL, ignore them. */
13651 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
13653 /* NOTE: We can assume slot != NULL here because xcalloc never
13657 htab_delete (htab
);
13663 htab_delete (htab
);
13667 /* When symbols change, it probably means the sources changed as well,
13668 and it might mean the static tracepoint markers are no longer at
13669 the same address or line numbers they used to be at last we
13670 checked. Losing your static tracepoints whenever you rebuild is
13671 undesirable. This function tries to resync/rematch gdb static
13672 tracepoints with the markers on the target, for static tracepoints
13673 that have not been set by marker id. Static tracepoint that have
13674 been set by marker id are reset by marker id in breakpoint_re_set.
13677 1) For a tracepoint set at a specific address, look for a marker at
13678 the old PC. If one is found there, assume to be the same marker.
13679 If the name / string id of the marker found is different from the
13680 previous known name, assume that means the user renamed the marker
13681 in the sources, and output a warning.
13683 2) For a tracepoint set at a given line number, look for a marker
13684 at the new address of the old line number. If one is found there,
13685 assume to be the same marker. If the name / string id of the
13686 marker found is different from the previous known name, assume that
13687 means the user renamed the marker in the sources, and output a
13690 3) If a marker is no longer found at the same address or line, it
13691 may mean the marker no longer exists. But it may also just mean
13692 the code changed a bit. Maybe the user added a few lines of code
13693 that made the marker move up or down (in line number terms). Ask
13694 the target for info about the marker with the string id as we knew
13695 it. If found, update line number and address in the matching
13696 static tracepoint. This will get confused if there's more than one
13697 marker with the same ID (possible in UST, although unadvised
13698 precisely because it confuses tools). */
13700 static struct symtab_and_line
13701 update_static_tracepoint (struct breakpoint
*b
, struct symtab_and_line sal
)
13703 struct tracepoint
*tp
= (struct tracepoint
*) b
;
13704 struct static_tracepoint_marker marker
;
13709 find_line_pc (sal
.symtab
, sal
.line
, &pc
);
13711 if (target_static_tracepoint_marker_at (pc
, &marker
))
13713 if (strcmp (tp
->static_trace_marker_id
, marker
.str_id
) != 0)
13714 warning (_("static tracepoint %d changed probed marker from %s to %s"),
13716 tp
->static_trace_marker_id
, marker
.str_id
);
13718 xfree (tp
->static_trace_marker_id
);
13719 tp
->static_trace_marker_id
= xstrdup (marker
.str_id
);
13720 release_static_tracepoint_marker (&marker
);
13725 /* Old marker wasn't found on target at lineno. Try looking it up
13727 if (!sal
.explicit_pc
13729 && sal
.symtab
!= NULL
13730 && tp
->static_trace_marker_id
!= NULL
)
13732 VEC(static_tracepoint_marker_p
) *markers
;
13735 = target_static_tracepoint_markers_by_strid (tp
->static_trace_marker_id
);
13737 if (!VEC_empty(static_tracepoint_marker_p
, markers
))
13739 struct symbol
*sym
;
13740 struct static_tracepoint_marker
*tpmarker
;
13741 struct ui_out
*uiout
= current_uiout
;
13742 struct explicit_location explicit_loc
;
13744 tpmarker
= VEC_index (static_tracepoint_marker_p
, markers
, 0);
13746 xfree (tp
->static_trace_marker_id
);
13747 tp
->static_trace_marker_id
= xstrdup (tpmarker
->str_id
);
13749 warning (_("marker for static tracepoint %d (%s) not "
13750 "found at previous line number"),
13751 b
->number
, tp
->static_trace_marker_id
);
13753 symtab_and_line sal2
= find_pc_line (tpmarker
->address
, 0);
13754 sym
= find_pc_sect_function (tpmarker
->address
, NULL
);
13755 uiout
->text ("Now in ");
13758 uiout
->field_string ("func", SYMBOL_PRINT_NAME (sym
));
13759 uiout
->text (" at ");
13761 uiout
->field_string ("file",
13762 symtab_to_filename_for_display (sal2
.symtab
));
13765 if (uiout
->is_mi_like_p ())
13767 const char *fullname
= symtab_to_fullname (sal2
.symtab
);
13769 uiout
->field_string ("fullname", fullname
);
13772 uiout
->field_int ("line", sal2
.line
);
13773 uiout
->text ("\n");
13775 b
->loc
->line_number
= sal2
.line
;
13776 b
->loc
->symtab
= sym
!= NULL
? sal2
.symtab
: NULL
;
13778 b
->location
.reset (NULL
);
13779 initialize_explicit_location (&explicit_loc
);
13780 explicit_loc
.source_filename
13781 = ASTRDUP (symtab_to_filename_for_display (sal2
.symtab
));
13782 explicit_loc
.line_offset
.offset
= b
->loc
->line_number
;
13783 explicit_loc
.line_offset
.sign
= LINE_OFFSET_NONE
;
13784 b
->location
= new_explicit_location (&explicit_loc
);
13786 /* Might be nice to check if function changed, and warn if
13789 release_static_tracepoint_marker (tpmarker
);
13795 /* Returns 1 iff locations A and B are sufficiently same that
13796 we don't need to report breakpoint as changed. */
13799 locations_are_equal (struct bp_location
*a
, struct bp_location
*b
)
13803 if (a
->address
!= b
->address
)
13806 if (a
->shlib_disabled
!= b
->shlib_disabled
)
13809 if (a
->enabled
!= b
->enabled
)
13816 if ((a
== NULL
) != (b
== NULL
))
13822 /* Split all locations of B that are bound to PSPACE out of B's
13823 location list to a separate list and return that list's head. If
13824 PSPACE is NULL, hoist out all locations of B. */
13826 static struct bp_location
*
13827 hoist_existing_locations (struct breakpoint
*b
, struct program_space
*pspace
)
13829 struct bp_location head
;
13830 struct bp_location
*i
= b
->loc
;
13831 struct bp_location
**i_link
= &b
->loc
;
13832 struct bp_location
*hoisted
= &head
;
13834 if (pspace
== NULL
)
13845 if (i
->pspace
== pspace
)
13860 /* Create new breakpoint locations for B (a hardware or software
13861 breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not
13862 zero, then B is a ranged breakpoint. Only recreates locations for
13863 FILTER_PSPACE. Locations of other program spaces are left
13867 update_breakpoint_locations (struct breakpoint
*b
,
13868 struct program_space
*filter_pspace
,
13869 gdb::array_view
<const symtab_and_line
> sals
,
13870 gdb::array_view
<const symtab_and_line
> sals_end
)
13873 struct bp_location
*existing_locations
;
13875 if (!sals_end
.empty () && (sals
.size () != 1 || sals_end
.size () != 1))
13877 /* Ranged breakpoints have only one start location and one end
13879 b
->enable_state
= bp_disabled
;
13880 printf_unfiltered (_("Could not reset ranged breakpoint %d: "
13881 "multiple locations found\n"),
13886 /* If there's no new locations, and all existing locations are
13887 pending, don't do anything. This optimizes the common case where
13888 all locations are in the same shared library, that was unloaded.
13889 We'd like to retain the location, so that when the library is
13890 loaded again, we don't loose the enabled/disabled status of the
13891 individual locations. */
13892 if (all_locations_are_pending (b
, filter_pspace
) && sals
.empty ())
13895 existing_locations
= hoist_existing_locations (b
, filter_pspace
);
13897 for (const auto &sal
: sals
)
13899 struct bp_location
*new_loc
;
13901 switch_to_program_space_and_thread (sal
.pspace
);
13903 new_loc
= add_location_to_breakpoint (b
, &sal
);
13905 /* Reparse conditions, they might contain references to the
13907 if (b
->cond_string
!= NULL
)
13911 s
= b
->cond_string
;
13914 new_loc
->cond
= parse_exp_1 (&s
, sal
.pc
,
13915 block_for_pc (sal
.pc
),
13918 CATCH (e
, RETURN_MASK_ERROR
)
13920 warning (_("failed to reevaluate condition "
13921 "for breakpoint %d: %s"),
13922 b
->number
, e
.message
);
13923 new_loc
->enabled
= 0;
13928 if (!sals_end
.empty ())
13930 CORE_ADDR end
= find_breakpoint_range_end (sals_end
[0]);
13932 new_loc
->length
= end
- sals
[0].pc
+ 1;
13936 /* If possible, carry over 'disable' status from existing
13939 struct bp_location
*e
= existing_locations
;
13940 /* If there are multiple breakpoints with the same function name,
13941 e.g. for inline functions, comparing function names won't work.
13942 Instead compare pc addresses; this is just a heuristic as things
13943 may have moved, but in practice it gives the correct answer
13944 often enough until a better solution is found. */
13945 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
13947 for (; e
; e
= e
->next
)
13949 if (!e
->enabled
&& e
->function_name
)
13951 struct bp_location
*l
= b
->loc
;
13952 if (have_ambiguous_names
)
13954 for (; l
; l
= l
->next
)
13955 if (breakpoint_locations_match (e
, l
))
13963 for (; l
; l
= l
->next
)
13964 if (l
->function_name
13965 && strcmp (e
->function_name
, l
->function_name
) == 0)
13975 if (!locations_are_equal (existing_locations
, b
->loc
))
13976 observer_notify_breakpoint_modified (b
);
13979 /* Find the SaL locations corresponding to the given LOCATION.
13980 On return, FOUND will be 1 if any SaL was found, zero otherwise. */
13982 static std::vector
<symtab_and_line
>
13983 location_to_sals (struct breakpoint
*b
, struct event_location
*location
,
13984 struct program_space
*search_pspace
, int *found
)
13986 struct gdb_exception exception
= exception_none
;
13988 gdb_assert (b
->ops
!= NULL
);
13990 std::vector
<symtab_and_line
> sals
;
13994 sals
= b
->ops
->decode_location (b
, location
, search_pspace
);
13996 CATCH (e
, RETURN_MASK_ERROR
)
13998 int not_found_and_ok
= 0;
14002 /* For pending breakpoints, it's expected that parsing will
14003 fail until the right shared library is loaded. User has
14004 already told to create pending breakpoints and don't need
14005 extra messages. If breakpoint is in bp_shlib_disabled
14006 state, then user already saw the message about that
14007 breakpoint being disabled, and don't want to see more
14009 if (e
.error
== NOT_FOUND_ERROR
14010 && (b
->condition_not_parsed
14012 && search_pspace
!= NULL
14013 && b
->loc
->pspace
!= search_pspace
)
14014 || (b
->loc
&& b
->loc
->shlib_disabled
)
14015 || (b
->loc
&& b
->loc
->pspace
->executing_startup
)
14016 || b
->enable_state
== bp_disabled
))
14017 not_found_and_ok
= 1;
14019 if (!not_found_and_ok
)
14021 /* We surely don't want to warn about the same breakpoint
14022 10 times. One solution, implemented here, is disable
14023 the breakpoint on error. Another solution would be to
14024 have separate 'warning emitted' flag. Since this
14025 happens only when a binary has changed, I don't know
14026 which approach is better. */
14027 b
->enable_state
= bp_disabled
;
14028 throw_exception (e
);
14033 if (exception
.reason
== 0 || exception
.error
!= NOT_FOUND_ERROR
)
14035 for (auto &sal
: sals
)
14036 resolve_sal_pc (&sal
);
14037 if (b
->condition_not_parsed
&& b
->extra_string
!= NULL
)
14039 char *cond_string
, *extra_string
;
14042 find_condition_and_thread (b
->extra_string
, sals
[0].pc
,
14043 &cond_string
, &thread
, &task
,
14045 gdb_assert (b
->cond_string
== NULL
);
14047 b
->cond_string
= cond_string
;
14048 b
->thread
= thread
;
14052 xfree (b
->extra_string
);
14053 b
->extra_string
= extra_string
;
14055 b
->condition_not_parsed
= 0;
14058 if (b
->type
== bp_static_tracepoint
&& !strace_marker_p (b
))
14059 sals
[0] = update_static_tracepoint (b
, sals
[0]);
14069 /* The default re_set method, for typical hardware or software
14070 breakpoints. Reevaluate the breakpoint and recreate its
14074 breakpoint_re_set_default (struct breakpoint
*b
)
14076 struct program_space
*filter_pspace
= current_program_space
;
14077 std::vector
<symtab_and_line
> expanded
, expanded_end
;
14080 std::vector
<symtab_and_line
> sals
= location_to_sals (b
, b
->location
.get (),
14081 filter_pspace
, &found
);
14083 expanded
= std::move (sals
);
14085 if (b
->location_range_end
!= NULL
)
14087 std::vector
<symtab_and_line
> sals_end
14088 = location_to_sals (b
, b
->location_range_end
.get (),
14089 filter_pspace
, &found
);
14091 expanded_end
= std::move (sals_end
);
14094 update_breakpoint_locations (b
, filter_pspace
, expanded
, expanded_end
);
14097 /* Default method for creating SALs from an address string. It basically
14098 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
14101 create_sals_from_location_default (const struct event_location
*location
,
14102 struct linespec_result
*canonical
,
14103 enum bptype type_wanted
)
14105 parse_breakpoint_sals (location
, canonical
);
14108 /* Call create_breakpoints_sal for the given arguments. This is the default
14109 function for the `create_breakpoints_sal' method of
14113 create_breakpoints_sal_default (struct gdbarch
*gdbarch
,
14114 struct linespec_result
*canonical
,
14115 gdb::unique_xmalloc_ptr
<char> cond_string
,
14116 gdb::unique_xmalloc_ptr
<char> extra_string
,
14117 enum bptype type_wanted
,
14118 enum bpdisp disposition
,
14120 int task
, int ignore_count
,
14121 const struct breakpoint_ops
*ops
,
14122 int from_tty
, int enabled
,
14123 int internal
, unsigned flags
)
14125 create_breakpoints_sal (gdbarch
, canonical
,
14126 std::move (cond_string
),
14127 std::move (extra_string
),
14128 type_wanted
, disposition
,
14129 thread
, task
, ignore_count
, ops
, from_tty
,
14130 enabled
, internal
, flags
);
14133 /* Decode the line represented by S by calling decode_line_full. This is the
14134 default function for the `decode_location' method of breakpoint_ops. */
14136 static std::vector
<symtab_and_line
>
14137 decode_location_default (struct breakpoint
*b
,
14138 const struct event_location
*location
,
14139 struct program_space
*search_pspace
)
14141 struct linespec_result canonical
;
14143 decode_line_full (location
, DECODE_LINE_FUNFIRSTLINE
, search_pspace
,
14144 (struct symtab
*) NULL
, 0,
14145 &canonical
, multiple_symbols_all
,
14148 /* We should get 0 or 1 resulting SALs. */
14149 gdb_assert (canonical
.lsals
.size () < 2);
14151 if (!canonical
.lsals
.empty ())
14153 const linespec_sals
&lsal
= canonical
.lsals
[0];
14154 return std::move (lsal
.sals
);
14159 /* Prepare the global context for a re-set of breakpoint B. */
14161 static struct cleanup
*
14162 prepare_re_set_context (struct breakpoint
*b
)
14164 input_radix
= b
->input_radix
;
14165 set_language (b
->language
);
14167 return make_cleanup (null_cleanup
, NULL
);
14170 /* Reset a breakpoint given it's struct breakpoint * BINT.
14171 The value we return ends up being the return value from catch_errors.
14172 Unused in this case. */
14175 breakpoint_re_set_one (void *bint
)
14177 /* Get past catch_errs. */
14178 struct breakpoint
*b
= (struct breakpoint
*) bint
;
14179 struct cleanup
*cleanups
;
14181 cleanups
= prepare_re_set_context (b
);
14182 b
->ops
->re_set (b
);
14183 do_cleanups (cleanups
);
14187 /* Re-set breakpoint locations for the current program space.
14188 Locations bound to other program spaces are left untouched. */
14191 breakpoint_re_set (void)
14193 struct breakpoint
*b
, *b_tmp
;
14194 enum language save_language
;
14195 int save_input_radix
;
14197 save_language
= current_language
->la_language
;
14198 save_input_radix
= input_radix
;
14201 scoped_restore_current_pspace_and_thread restore_pspace_thread
;
14203 /* Note: we must not try to insert locations until after all
14204 breakpoints have been re-set. Otherwise, e.g., when re-setting
14205 breakpoint 1, we'd insert the locations of breakpoint 2, which
14206 hadn't been re-set yet, and thus may have stale locations. */
14208 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
14210 /* Format possible error msg. */
14211 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
14213 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
14214 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
14215 do_cleanups (cleanups
);
14217 set_language (save_language
);
14218 input_radix
= save_input_radix
;
14220 jit_breakpoint_re_set ();
14223 create_overlay_event_breakpoint ();
14224 create_longjmp_master_breakpoint ();
14225 create_std_terminate_master_breakpoint ();
14226 create_exception_master_breakpoint ();
14228 /* Now we can insert. */
14229 update_global_location_list (UGLL_MAY_INSERT
);
14232 /* Reset the thread number of this breakpoint:
14234 - If the breakpoint is for all threads, leave it as-is.
14235 - Else, reset it to the current thread for inferior_ptid. */
14237 breakpoint_re_set_thread (struct breakpoint
*b
)
14239 if (b
->thread
!= -1)
14241 if (in_thread_list (inferior_ptid
))
14242 b
->thread
= ptid_to_global_thread_id (inferior_ptid
);
14244 /* We're being called after following a fork. The new fork is
14245 selected as current, and unless this was a vfork will have a
14246 different program space from the original thread. Reset that
14248 b
->loc
->pspace
= current_program_space
;
14252 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14253 If from_tty is nonzero, it prints a message to that effect,
14254 which ends with a period (no newline). */
14257 set_ignore_count (int bptnum
, int count
, int from_tty
)
14259 struct breakpoint
*b
;
14264 ALL_BREAKPOINTS (b
)
14265 if (b
->number
== bptnum
)
14267 if (is_tracepoint (b
))
14269 if (from_tty
&& count
!= 0)
14270 printf_filtered (_("Ignore count ignored for tracepoint %d."),
14275 b
->ignore_count
= count
;
14279 printf_filtered (_("Will stop next time "
14280 "breakpoint %d is reached."),
14282 else if (count
== 1)
14283 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
14286 printf_filtered (_("Will ignore next %d "
14287 "crossings of breakpoint %d."),
14290 observer_notify_breakpoint_modified (b
);
14294 error (_("No breakpoint number %d."), bptnum
);
14297 /* Command to set ignore-count of breakpoint N to COUNT. */
14300 ignore_command (char *args
, int from_tty
)
14306 error_no_arg (_("a breakpoint number"));
14308 num
= get_number (&p
);
14310 error (_("bad breakpoint number: '%s'"), args
);
14312 error (_("Second argument (specified ignore-count) is missing."));
14314 set_ignore_count (num
,
14315 longest_to_int (value_as_long (parse_and_eval (p
))),
14318 printf_filtered ("\n");
14321 /* Call FUNCTION on each of the breakpoints
14322 whose numbers are given in ARGS. */
14325 map_breakpoint_numbers (const char *args
,
14326 gdb::function_view
<void (breakpoint
*)> function
)
14329 struct breakpoint
*b
, *tmp
;
14331 if (args
== 0 || *args
== '\0')
14332 error_no_arg (_("one or more breakpoint numbers"));
14334 number_or_range_parser
parser (args
);
14336 while (!parser
.finished ())
14338 const char *p
= parser
.cur_tok ();
14339 bool match
= false;
14341 num
= parser
.get_number ();
14344 warning (_("bad breakpoint number at or near '%s'"), p
);
14348 ALL_BREAKPOINTS_SAFE (b
, tmp
)
14349 if (b
->number
== num
)
14356 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
14361 static struct bp_location
*
14362 find_location_by_number (const char *number
)
14367 struct breakpoint
*b
;
14368 struct bp_location
*loc
;
14371 bp_num
= get_number_trailer (&p1
, '.');
14372 if (bp_num
== 0 || p1
[0] != '.')
14373 error (_("Bad breakpoint number '%s'"), number
);
14375 ALL_BREAKPOINTS (b
)
14376 if (b
->number
== bp_num
)
14381 if (!b
|| b
->number
!= bp_num
)
14382 error (_("Bad breakpoint number '%s'"), number
);
14384 /* Skip the dot. */
14386 const char *save
= p1
;
14387 loc_num
= get_number (&p1
);
14389 error (_("Bad breakpoint location number '%s'"), number
);
14393 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
14396 error (_("Bad breakpoint location number '%s'"), save
);
14402 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
14403 If from_tty is nonzero, it prints a message to that effect,
14404 which ends with a period (no newline). */
14407 disable_breakpoint (struct breakpoint
*bpt
)
14409 /* Never disable a watchpoint scope breakpoint; we want to
14410 hit them when we leave scope so we can delete both the
14411 watchpoint and its scope breakpoint at that time. */
14412 if (bpt
->type
== bp_watchpoint_scope
)
14415 bpt
->enable_state
= bp_disabled
;
14417 /* Mark breakpoint locations modified. */
14418 mark_breakpoint_modified (bpt
);
14420 if (target_supports_enable_disable_tracepoint ()
14421 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14423 struct bp_location
*location
;
14425 for (location
= bpt
->loc
; location
; location
= location
->next
)
14426 target_disable_tracepoint (location
);
14429 update_global_location_list (UGLL_DONT_INSERT
);
14431 observer_notify_breakpoint_modified (bpt
);
14435 disable_command (char *args
, int from_tty
)
14439 struct breakpoint
*bpt
;
14441 ALL_BREAKPOINTS (bpt
)
14442 if (user_breakpoint_p (bpt
))
14443 disable_breakpoint (bpt
);
14447 std::string num
= extract_arg (&args
);
14449 while (!num
.empty ())
14451 if (num
.find ('.') != std::string::npos
)
14453 struct bp_location
*loc
= find_location_by_number (num
.c_str ());
14460 mark_breakpoint_location_modified (loc
);
14462 if (target_supports_enable_disable_tracepoint ()
14463 && current_trace_status ()->running
&& loc
->owner
14464 && is_tracepoint (loc
->owner
))
14465 target_disable_tracepoint (loc
);
14467 update_global_location_list (UGLL_DONT_INSERT
);
14470 map_breakpoint_numbers
14471 (num
.c_str (), [&] (breakpoint
*b
)
14473 iterate_over_related_breakpoints (b
, disable_breakpoint
);
14475 num
= extract_arg (&args
);
14481 enable_breakpoint_disp (struct breakpoint
*bpt
, enum bpdisp disposition
,
14484 int target_resources_ok
;
14486 if (bpt
->type
== bp_hardware_breakpoint
)
14489 i
= hw_breakpoint_used_count ();
14490 target_resources_ok
=
14491 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
14493 if (target_resources_ok
== 0)
14494 error (_("No hardware breakpoint support in the target."));
14495 else if (target_resources_ok
< 0)
14496 error (_("Hardware breakpoints used exceeds limit."));
14499 if (is_watchpoint (bpt
))
14501 /* Initialize it just to avoid a GCC false warning. */
14502 enum enable_state orig_enable_state
= bp_disabled
;
14506 struct watchpoint
*w
= (struct watchpoint
*) bpt
;
14508 orig_enable_state
= bpt
->enable_state
;
14509 bpt
->enable_state
= bp_enabled
;
14510 update_watchpoint (w
, 1 /* reparse */);
14512 CATCH (e
, RETURN_MASK_ALL
)
14514 bpt
->enable_state
= orig_enable_state
;
14515 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
14522 bpt
->enable_state
= bp_enabled
;
14524 /* Mark breakpoint locations modified. */
14525 mark_breakpoint_modified (bpt
);
14527 if (target_supports_enable_disable_tracepoint ()
14528 && current_trace_status ()->running
&& is_tracepoint (bpt
))
14530 struct bp_location
*location
;
14532 for (location
= bpt
->loc
; location
; location
= location
->next
)
14533 target_enable_tracepoint (location
);
14536 bpt
->disposition
= disposition
;
14537 bpt
->enable_count
= count
;
14538 update_global_location_list (UGLL_MAY_INSERT
);
14540 observer_notify_breakpoint_modified (bpt
);
14545 enable_breakpoint (struct breakpoint
*bpt
)
14547 enable_breakpoint_disp (bpt
, bpt
->disposition
, 0);
14550 /* The enable command enables the specified breakpoints (or all defined
14551 breakpoints) so they once again become (or continue to be) effective
14552 in stopping the inferior. */
14555 enable_command (char *args
, int from_tty
)
14559 struct breakpoint
*bpt
;
14561 ALL_BREAKPOINTS (bpt
)
14562 if (user_breakpoint_p (bpt
))
14563 enable_breakpoint (bpt
);
14567 std::string num
= extract_arg (&args
);
14569 while (!num
.empty ())
14571 if (num
.find ('.') != std::string::npos
)
14573 struct bp_location
*loc
= find_location_by_number (num
.c_str ());
14580 mark_breakpoint_location_modified (loc
);
14582 if (target_supports_enable_disable_tracepoint ()
14583 && current_trace_status ()->running
&& loc
->owner
14584 && is_tracepoint (loc
->owner
))
14585 target_enable_tracepoint (loc
);
14587 update_global_location_list (UGLL_MAY_INSERT
);
14590 map_breakpoint_numbers
14591 (num
.c_str (), [&] (breakpoint
*b
)
14593 iterate_over_related_breakpoints (b
, enable_breakpoint
);
14595 num
= extract_arg (&args
);
14601 enable_once_command (char *args
, int from_tty
)
14603 map_breakpoint_numbers
14604 (args
, [&] (breakpoint
*b
)
14606 iterate_over_related_breakpoints
14607 (b
, [&] (breakpoint
*bpt
)
14609 enable_breakpoint_disp (bpt
, disp_disable
, 1);
14615 enable_count_command (char *args
, int from_tty
)
14620 error_no_arg (_("hit count"));
14622 count
= get_number (&args
);
14624 map_breakpoint_numbers
14625 (args
, [&] (breakpoint
*b
)
14627 iterate_over_related_breakpoints
14628 (b
, [&] (breakpoint
*bpt
)
14630 enable_breakpoint_disp (bpt
, disp_disable
, count
);
14636 enable_delete_command (char *args
, int from_tty
)
14638 map_breakpoint_numbers
14639 (args
, [&] (breakpoint
*b
)
14641 iterate_over_related_breakpoints
14642 (b
, [&] (breakpoint
*bpt
)
14644 enable_breakpoint_disp (bpt
, disp_del
, 1);
14650 set_breakpoint_cmd (char *args
, int from_tty
)
14655 show_breakpoint_cmd (char *args
, int from_tty
)
14659 /* Invalidate last known value of any hardware watchpoint if
14660 the memory which that value represents has been written to by
14664 invalidate_bp_value_on_memory_change (struct inferior
*inferior
,
14665 CORE_ADDR addr
, ssize_t len
,
14666 const bfd_byte
*data
)
14668 struct breakpoint
*bp
;
14670 ALL_BREAKPOINTS (bp
)
14671 if (bp
->enable_state
== bp_enabled
14672 && bp
->type
== bp_hardware_watchpoint
)
14674 struct watchpoint
*wp
= (struct watchpoint
*) bp
;
14676 if (wp
->val_valid
&& wp
->val
)
14678 struct bp_location
*loc
;
14680 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14681 if (loc
->loc_type
== bp_loc_hardware_watchpoint
14682 && loc
->address
+ loc
->length
> addr
14683 && addr
+ len
> loc
->address
)
14685 value_free (wp
->val
);
14693 /* Create and insert a breakpoint for software single step. */
14696 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
14697 struct address_space
*aspace
,
14700 struct thread_info
*tp
= inferior_thread ();
14701 struct symtab_and_line sal
;
14702 CORE_ADDR pc
= next_pc
;
14704 if (tp
->control
.single_step_breakpoints
== NULL
)
14706 tp
->control
.single_step_breakpoints
14707 = new_single_step_breakpoint (tp
->global_num
, gdbarch
);
14710 sal
= find_pc_line (pc
, 0);
14712 sal
.section
= find_pc_overlay (pc
);
14713 sal
.explicit_pc
= 1;
14714 add_location_to_breakpoint (tp
->control
.single_step_breakpoints
, &sal
);
14716 update_global_location_list (UGLL_INSERT
);
14719 /* Insert single step breakpoints according to the current state. */
14722 insert_single_step_breakpoints (struct gdbarch
*gdbarch
)
14724 struct regcache
*regcache
= get_current_regcache ();
14725 std::vector
<CORE_ADDR
> next_pcs
;
14727 next_pcs
= gdbarch_software_single_step (gdbarch
, regcache
);
14729 if (!next_pcs
.empty ())
14731 struct frame_info
*frame
= get_current_frame ();
14732 struct address_space
*aspace
= get_frame_address_space (frame
);
14734 for (CORE_ADDR pc
: next_pcs
)
14735 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
14743 /* See breakpoint.h. */
14746 breakpoint_has_location_inserted_here (struct breakpoint
*bp
,
14747 struct address_space
*aspace
,
14750 struct bp_location
*loc
;
14752 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
14754 && breakpoint_location_address_match (loc
, aspace
, pc
))
14760 /* Check whether a software single-step breakpoint is inserted at
14764 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
,
14767 struct breakpoint
*bpt
;
14769 ALL_BREAKPOINTS (bpt
)
14771 if (bpt
->type
== bp_single_step
14772 && breakpoint_has_location_inserted_here (bpt
, aspace
, pc
))
14778 /* Tracepoint-specific operations. */
14780 /* Set tracepoint count to NUM. */
14782 set_tracepoint_count (int num
)
14784 tracepoint_count
= num
;
14785 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
14789 trace_command (char *arg
, int from_tty
)
14791 struct breakpoint_ops
*ops
;
14793 event_location_up location
= string_to_event_location (&arg
,
14795 if (location
!= NULL
14796 && event_location_type (location
.get ()) == PROBE_LOCATION
)
14797 ops
= &tracepoint_probe_breakpoint_ops
;
14799 ops
= &tracepoint_breakpoint_ops
;
14801 create_breakpoint (get_current_arch (),
14803 NULL
, 0, arg
, 1 /* parse arg */,
14805 bp_tracepoint
/* type_wanted */,
14806 0 /* Ignore count */,
14807 pending_break_support
,
14811 0 /* internal */, 0);
14815 ftrace_command (char *arg
, int from_tty
)
14817 event_location_up location
= string_to_event_location (&arg
,
14819 create_breakpoint (get_current_arch (),
14821 NULL
, 0, arg
, 1 /* parse arg */,
14823 bp_fast_tracepoint
/* type_wanted */,
14824 0 /* Ignore count */,
14825 pending_break_support
,
14826 &tracepoint_breakpoint_ops
,
14829 0 /* internal */, 0);
14832 /* strace command implementation. Creates a static tracepoint. */
14835 strace_command (char *arg
, int from_tty
)
14837 struct breakpoint_ops
*ops
;
14838 event_location_up location
;
14839 struct cleanup
*back_to
;
14841 /* Decide if we are dealing with a static tracepoint marker (`-m'),
14842 or with a normal static tracepoint. */
14843 if (arg
&& startswith (arg
, "-m") && isspace (arg
[2]))
14845 ops
= &strace_marker_breakpoint_ops
;
14846 location
= new_linespec_location (&arg
);
14850 ops
= &tracepoint_breakpoint_ops
;
14851 location
= string_to_event_location (&arg
, current_language
);
14854 create_breakpoint (get_current_arch (),
14856 NULL
, 0, arg
, 1 /* parse arg */,
14858 bp_static_tracepoint
/* type_wanted */,
14859 0 /* Ignore count */,
14860 pending_break_support
,
14864 0 /* internal */, 0);
14867 /* Set up a fake reader function that gets command lines from a linked
14868 list that was acquired during tracepoint uploading. */
14870 static struct uploaded_tp
*this_utp
;
14871 static int next_cmd
;
14874 read_uploaded_action (void)
14878 VEC_iterate (char_ptr
, this_utp
->cmd_strings
, next_cmd
, rslt
);
14885 /* Given information about a tracepoint as recorded on a target (which
14886 can be either a live system or a trace file), attempt to create an
14887 equivalent GDB tracepoint. This is not a reliable process, since
14888 the target does not necessarily have all the information used when
14889 the tracepoint was originally defined. */
14891 struct tracepoint
*
14892 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
14894 char *addr_str
, small_buf
[100];
14895 struct tracepoint
*tp
;
14897 if (utp
->at_string
)
14898 addr_str
= utp
->at_string
;
14901 /* In the absence of a source location, fall back to raw
14902 address. Since there is no way to confirm that the address
14903 means the same thing as when the trace was started, warn the
14905 warning (_("Uploaded tracepoint %d has no "
14906 "source location, using raw address"),
14908 xsnprintf (small_buf
, sizeof (small_buf
), "*%s", hex_string (utp
->addr
));
14909 addr_str
= small_buf
;
14912 /* There's not much we can do with a sequence of bytecodes. */
14913 if (utp
->cond
&& !utp
->cond_string
)
14914 warning (_("Uploaded tracepoint %d condition "
14915 "has no source form, ignoring it"),
14918 event_location_up location
= string_to_event_location (&addr_str
,
14920 if (!create_breakpoint (get_current_arch (),
14922 utp
->cond_string
, -1, addr_str
,
14923 0 /* parse cond/thread */,
14925 utp
->type
/* type_wanted */,
14926 0 /* Ignore count */,
14927 pending_break_support
,
14928 &tracepoint_breakpoint_ops
,
14930 utp
->enabled
/* enabled */,
14932 CREATE_BREAKPOINT_FLAGS_INSERTED
))
14935 /* Get the tracepoint we just created. */
14936 tp
= get_tracepoint (tracepoint_count
);
14937 gdb_assert (tp
!= NULL
);
14941 xsnprintf (small_buf
, sizeof (small_buf
), "%d %d", utp
->pass
,
14944 trace_pass_command (small_buf
, 0);
14947 /* If we have uploaded versions of the original commands, set up a
14948 special-purpose "reader" function and call the usual command line
14949 reader, then pass the result to the breakpoint command-setting
14951 if (!VEC_empty (char_ptr
, utp
->cmd_strings
))
14953 command_line_up cmd_list
;
14958 cmd_list
= read_command_lines_1 (read_uploaded_action
, 1, NULL
, NULL
);
14960 breakpoint_set_commands (tp
, std::move (cmd_list
));
14962 else if (!VEC_empty (char_ptr
, utp
->actions
)
14963 || !VEC_empty (char_ptr
, utp
->step_actions
))
14964 warning (_("Uploaded tracepoint %d actions "
14965 "have no source form, ignoring them"),
14968 /* Copy any status information that might be available. */
14969 tp
->hit_count
= utp
->hit_count
;
14970 tp
->traceframe_usage
= utp
->traceframe_usage
;
14975 /* Print information on tracepoint number TPNUM_EXP, or all if
14979 info_tracepoints_command (char *args
, int from_tty
)
14981 struct ui_out
*uiout
= current_uiout
;
14984 num_printed
= breakpoint_1 (args
, 0, is_tracepoint
);
14986 if (num_printed
== 0)
14988 if (args
== NULL
|| *args
== '\0')
14989 uiout
->message ("No tracepoints.\n");
14991 uiout
->message ("No tracepoint matching '%s'.\n", args
);
14994 default_collect_info ();
14997 /* The 'enable trace' command enables tracepoints.
14998 Not supported by all targets. */
15000 enable_trace_command (char *args
, int from_tty
)
15002 enable_command (args
, from_tty
);
15005 /* The 'disable trace' command disables tracepoints.
15006 Not supported by all targets. */
15008 disable_trace_command (char *args
, int from_tty
)
15010 disable_command (args
, from_tty
);
15013 /* Remove a tracepoint (or all if no argument). */
15015 delete_trace_command (char *arg
, int from_tty
)
15017 struct breakpoint
*b
, *b_tmp
;
15023 int breaks_to_delete
= 0;
15025 /* Delete all breakpoints if no argument.
15026 Do not delete internal or call-dummy breakpoints, these
15027 have to be deleted with an explicit breakpoint number
15029 ALL_TRACEPOINTS (b
)
15030 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15032 breaks_to_delete
= 1;
15036 /* Ask user only if there are some breakpoints to delete. */
15038 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
15040 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15041 if (is_tracepoint (b
) && user_breakpoint_p (b
))
15042 delete_breakpoint (b
);
15046 map_breakpoint_numbers
15047 (arg
, [&] (breakpoint
*b
)
15049 iterate_over_related_breakpoints (b
, delete_breakpoint
);
15053 /* Helper function for trace_pass_command. */
15056 trace_pass_set_count (struct tracepoint
*tp
, int count
, int from_tty
)
15058 tp
->pass_count
= count
;
15059 observer_notify_breakpoint_modified (tp
);
15061 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
15062 tp
->number
, count
);
15065 /* Set passcount for tracepoint.
15067 First command argument is passcount, second is tracepoint number.
15068 If tracepoint number omitted, apply to most recently defined.
15069 Also accepts special argument "all". */
15072 trace_pass_command (char *args
, int from_tty
)
15074 struct tracepoint
*t1
;
15075 unsigned int count
;
15077 if (args
== 0 || *args
== 0)
15078 error (_("passcount command requires an "
15079 "argument (count + optional TP num)"));
15081 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
15083 args
= skip_spaces (args
);
15084 if (*args
&& strncasecmp (args
, "all", 3) == 0)
15086 struct breakpoint
*b
;
15088 args
+= 3; /* Skip special argument "all". */
15090 error (_("Junk at end of arguments."));
15092 ALL_TRACEPOINTS (b
)
15094 t1
= (struct tracepoint
*) b
;
15095 trace_pass_set_count (t1
, count
, from_tty
);
15098 else if (*args
== '\0')
15100 t1
= get_tracepoint_by_number (&args
, NULL
);
15102 trace_pass_set_count (t1
, count
, from_tty
);
15106 number_or_range_parser
parser (args
);
15107 while (!parser
.finished ())
15109 t1
= get_tracepoint_by_number (&args
, &parser
);
15111 trace_pass_set_count (t1
, count
, from_tty
);
15116 struct tracepoint
*
15117 get_tracepoint (int num
)
15119 struct breakpoint
*t
;
15121 ALL_TRACEPOINTS (t
)
15122 if (t
->number
== num
)
15123 return (struct tracepoint
*) t
;
15128 /* Find the tracepoint with the given target-side number (which may be
15129 different from the tracepoint number after disconnecting and
15132 struct tracepoint
*
15133 get_tracepoint_by_number_on_target (int num
)
15135 struct breakpoint
*b
;
15137 ALL_TRACEPOINTS (b
)
15139 struct tracepoint
*t
= (struct tracepoint
*) b
;
15141 if (t
->number_on_target
== num
)
15148 /* Utility: parse a tracepoint number and look it up in the list.
15149 If STATE is not NULL, use, get_number_or_range_state and ignore ARG.
15150 If the argument is missing, the most recent tracepoint
15151 (tracepoint_count) is returned. */
15153 struct tracepoint
*
15154 get_tracepoint_by_number (char **arg
,
15155 number_or_range_parser
*parser
)
15157 struct breakpoint
*t
;
15159 char *instring
= arg
== NULL
? NULL
: *arg
;
15161 if (parser
!= NULL
)
15163 gdb_assert (!parser
->finished ());
15164 tpnum
= parser
->get_number ();
15166 else if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
15167 tpnum
= tracepoint_count
;
15169 tpnum
= get_number (arg
);
15173 if (instring
&& *instring
)
15174 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
15177 printf_filtered (_("No previous tracepoint\n"));
15181 ALL_TRACEPOINTS (t
)
15182 if (t
->number
== tpnum
)
15184 return (struct tracepoint
*) t
;
15187 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
15192 print_recreate_thread (struct breakpoint
*b
, struct ui_file
*fp
)
15194 if (b
->thread
!= -1)
15195 fprintf_unfiltered (fp
, " thread %d", b
->thread
);
15198 fprintf_unfiltered (fp
, " task %d", b
->task
);
15200 fprintf_unfiltered (fp
, "\n");
15203 /* Save information on user settable breakpoints (watchpoints, etc) to
15204 a new script file named FILENAME. If FILTER is non-NULL, call it
15205 on each breakpoint and only include the ones for which it returns
15209 save_breakpoints (char *filename
, int from_tty
,
15210 int (*filter
) (const struct breakpoint
*))
15212 struct breakpoint
*tp
;
15214 int extra_trace_bits
= 0;
15216 if (filename
== 0 || *filename
== 0)
15217 error (_("Argument required (file name in which to save)"));
15219 /* See if we have anything to save. */
15220 ALL_BREAKPOINTS (tp
)
15222 /* Skip internal and momentary breakpoints. */
15223 if (!user_breakpoint_p (tp
))
15226 /* If we have a filter, only save the breakpoints it accepts. */
15227 if (filter
&& !filter (tp
))
15232 if (is_tracepoint (tp
))
15234 extra_trace_bits
= 1;
15236 /* We can stop searching. */
15243 warning (_("Nothing to save."));
15247 gdb::unique_xmalloc_ptr
<char> expanded_filename (tilde_expand (filename
));
15251 if (!fp
.open (expanded_filename
.get (), "w"))
15252 error (_("Unable to open file '%s' for saving (%s)"),
15253 expanded_filename
.get (), safe_strerror (errno
));
15255 if (extra_trace_bits
)
15256 save_trace_state_variables (&fp
);
15258 ALL_BREAKPOINTS (tp
)
15260 /* Skip internal and momentary breakpoints. */
15261 if (!user_breakpoint_p (tp
))
15264 /* If we have a filter, only save the breakpoints it accepts. */
15265 if (filter
&& !filter (tp
))
15268 tp
->ops
->print_recreate (tp
, &fp
);
15270 /* Note, we can't rely on tp->number for anything, as we can't
15271 assume the recreated breakpoint numbers will match. Use $bpnum
15274 if (tp
->cond_string
)
15275 fp
.printf (" condition $bpnum %s\n", tp
->cond_string
);
15277 if (tp
->ignore_count
)
15278 fp
.printf (" ignore $bpnum %d\n", tp
->ignore_count
);
15280 if (tp
->type
!= bp_dprintf
&& tp
->commands
)
15282 fp
.puts (" commands\n");
15284 current_uiout
->redirect (&fp
);
15287 print_command_lines (current_uiout
, tp
->commands
.get (), 2);
15289 CATCH (ex
, RETURN_MASK_ALL
)
15291 current_uiout
->redirect (NULL
);
15292 throw_exception (ex
);
15296 current_uiout
->redirect (NULL
);
15297 fp
.puts (" end\n");
15300 if (tp
->enable_state
== bp_disabled
)
15301 fp
.puts ("disable $bpnum\n");
15303 /* If this is a multi-location breakpoint, check if the locations
15304 should be individually disabled. Watchpoint locations are
15305 special, and not user visible. */
15306 if (!is_watchpoint (tp
) && tp
->loc
&& tp
->loc
->next
)
15308 struct bp_location
*loc
;
15311 for (loc
= tp
->loc
; loc
!= NULL
; loc
= loc
->next
, n
++)
15313 fp
.printf ("disable $bpnum.%d\n", n
);
15317 if (extra_trace_bits
&& *default_collect
)
15318 fp
.printf ("set default-collect %s\n", default_collect
);
15321 printf_filtered (_("Saved to file '%s'.\n"), expanded_filename
.get ());
15324 /* The `save breakpoints' command. */
15327 save_breakpoints_command (char *args
, int from_tty
)
15329 save_breakpoints (args
, from_tty
, NULL
);
15332 /* The `save tracepoints' command. */
15335 save_tracepoints_command (char *args
, int from_tty
)
15337 save_breakpoints (args
, from_tty
, is_tracepoint
);
15340 /* Create a vector of all tracepoints. */
15342 VEC(breakpoint_p
) *
15343 all_tracepoints (void)
15345 VEC(breakpoint_p
) *tp_vec
= 0;
15346 struct breakpoint
*tp
;
15348 ALL_TRACEPOINTS (tp
)
15350 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
15357 /* This help string is used to consolidate all the help string for specifying
15358 locations used by several commands. */
15360 #define LOCATION_HELP_STRING \
15361 "Linespecs are colon-separated lists of location parameters, such as\n\
15362 source filename, function name, label name, and line number.\n\
15363 Example: To specify the start of a label named \"the_top\" in the\n\
15364 function \"fact\" in the file \"factorial.c\", use\n\
15365 \"factorial.c:fact:the_top\".\n\
15367 Address locations begin with \"*\" and specify an exact address in the\n\
15368 program. Example: To specify the fourth byte past the start function\n\
15369 \"main\", use \"*main + 4\".\n\
15371 Explicit locations are similar to linespecs but use an option/argument\n\
15372 syntax to specify location parameters.\n\
15373 Example: To specify the start of the label named \"the_top\" in the\n\
15374 function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\
15375 -function fact -label the_top\".\n"
15377 /* This help string is used for the break, hbreak, tbreak and thbreak
15378 commands. It is defined as a macro to prevent duplication.
15379 COMMAND should be a string constant containing the name of the
15382 #define BREAK_ARGS_HELP(command) \
15383 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
15384 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
15385 probe point. Accepted values are `-probe' (for a generic, automatically\n\
15386 guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
15387 `-probe-dtrace' (for a DTrace probe).\n\
15388 LOCATION may be a linespec, address, or explicit location as described\n\
15391 With no LOCATION, uses current execution address of the selected\n\
15392 stack frame. This is useful for breaking on return to a stack frame.\n\
15394 THREADNUM is the number from \"info threads\".\n\
15395 CONDITION is a boolean expression.\n\
15396 \n" LOCATION_HELP_STRING "\n\
15397 Multiple breakpoints at one place are permitted, and useful if their\n\
15398 conditions are different.\n\
15400 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
15402 /* List of subcommands for "catch". */
15403 static struct cmd_list_element
*catch_cmdlist
;
15405 /* List of subcommands for "tcatch". */
15406 static struct cmd_list_element
*tcatch_cmdlist
;
15409 add_catch_command (const char *name
, const char *docstring
,
15410 cmd_sfunc_ftype
*sfunc
,
15411 completer_ftype
*completer
,
15412 void *user_data_catch
,
15413 void *user_data_tcatch
)
15415 struct cmd_list_element
*command
;
15417 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15419 set_cmd_sfunc (command
, sfunc
);
15420 set_cmd_context (command
, user_data_catch
);
15421 set_cmd_completer (command
, completer
);
15423 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
15425 set_cmd_sfunc (command
, sfunc
);
15426 set_cmd_context (command
, user_data_tcatch
);
15427 set_cmd_completer (command
, completer
);
15431 save_command (char *arg
, int from_tty
)
15433 printf_unfiltered (_("\"save\" must be followed by "
15434 "the name of a save subcommand.\n"));
15435 help_list (save_cmdlist
, "save ", all_commands
, gdb_stdout
);
15438 struct breakpoint
*
15439 iterate_over_breakpoints (int (*callback
) (struct breakpoint
*, void *),
15442 struct breakpoint
*b
, *b_tmp
;
15444 ALL_BREAKPOINTS_SAFE (b
, b_tmp
)
15446 if ((*callback
) (b
, data
))
15453 /* Zero if any of the breakpoint's locations could be a location where
15454 functions have been inlined, nonzero otherwise. */
15457 is_non_inline_function (struct breakpoint
*b
)
15459 /* The shared library event breakpoint is set on the address of a
15460 non-inline function. */
15461 if (b
->type
== bp_shlib_event
)
15467 /* Nonzero if the specified PC cannot be a location where functions
15468 have been inlined. */
15471 pc_at_non_inline_function (struct address_space
*aspace
, CORE_ADDR pc
,
15472 const struct target_waitstatus
*ws
)
15474 struct breakpoint
*b
;
15475 struct bp_location
*bl
;
15477 ALL_BREAKPOINTS (b
)
15479 if (!is_non_inline_function (b
))
15482 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
15484 if (!bl
->shlib_disabled
15485 && bpstat_check_location (bl
, aspace
, pc
, ws
))
15493 /* Remove any references to OBJFILE which is going to be freed. */
15496 breakpoint_free_objfile (struct objfile
*objfile
)
15498 struct bp_location
**locp
, *loc
;
15500 ALL_BP_LOCATIONS (loc
, locp
)
15501 if (loc
->symtab
!= NULL
&& SYMTAB_OBJFILE (loc
->symtab
) == objfile
)
15502 loc
->symtab
= NULL
;
15506 initialize_breakpoint_ops (void)
15508 static int initialized
= 0;
15510 struct breakpoint_ops
*ops
;
15516 /* The breakpoint_ops structure to be inherit by all kinds of
15517 breakpoints (real breakpoints, i.e., user "break" breakpoints,
15518 internal and momentary breakpoints, etc.). */
15519 ops
= &bkpt_base_breakpoint_ops
;
15520 *ops
= base_breakpoint_ops
;
15521 ops
->re_set
= bkpt_re_set
;
15522 ops
->insert_location
= bkpt_insert_location
;
15523 ops
->remove_location
= bkpt_remove_location
;
15524 ops
->breakpoint_hit
= bkpt_breakpoint_hit
;
15525 ops
->create_sals_from_location
= bkpt_create_sals_from_location
;
15526 ops
->create_breakpoints_sal
= bkpt_create_breakpoints_sal
;
15527 ops
->decode_location
= bkpt_decode_location
;
15529 /* The breakpoint_ops structure to be used in regular breakpoints. */
15530 ops
= &bkpt_breakpoint_ops
;
15531 *ops
= bkpt_base_breakpoint_ops
;
15532 ops
->re_set
= bkpt_re_set
;
15533 ops
->resources_needed
= bkpt_resources_needed
;
15534 ops
->print_it
= bkpt_print_it
;
15535 ops
->print_mention
= bkpt_print_mention
;
15536 ops
->print_recreate
= bkpt_print_recreate
;
15538 /* Ranged breakpoints. */
15539 ops
= &ranged_breakpoint_ops
;
15540 *ops
= bkpt_breakpoint_ops
;
15541 ops
->breakpoint_hit
= breakpoint_hit_ranged_breakpoint
;
15542 ops
->resources_needed
= resources_needed_ranged_breakpoint
;
15543 ops
->print_it
= print_it_ranged_breakpoint
;
15544 ops
->print_one
= print_one_ranged_breakpoint
;
15545 ops
->print_one_detail
= print_one_detail_ranged_breakpoint
;
15546 ops
->print_mention
= print_mention_ranged_breakpoint
;
15547 ops
->print_recreate
= print_recreate_ranged_breakpoint
;
15549 /* Internal breakpoints. */
15550 ops
= &internal_breakpoint_ops
;
15551 *ops
= bkpt_base_breakpoint_ops
;
15552 ops
->re_set
= internal_bkpt_re_set
;
15553 ops
->check_status
= internal_bkpt_check_status
;
15554 ops
->print_it
= internal_bkpt_print_it
;
15555 ops
->print_mention
= internal_bkpt_print_mention
;
15557 /* Momentary breakpoints. */
15558 ops
= &momentary_breakpoint_ops
;
15559 *ops
= bkpt_base_breakpoint_ops
;
15560 ops
->re_set
= momentary_bkpt_re_set
;
15561 ops
->check_status
= momentary_bkpt_check_status
;
15562 ops
->print_it
= momentary_bkpt_print_it
;
15563 ops
->print_mention
= momentary_bkpt_print_mention
;
15565 /* Probe breakpoints. */
15566 ops
= &bkpt_probe_breakpoint_ops
;
15567 *ops
= bkpt_breakpoint_ops
;
15568 ops
->insert_location
= bkpt_probe_insert_location
;
15569 ops
->remove_location
= bkpt_probe_remove_location
;
15570 ops
->create_sals_from_location
= bkpt_probe_create_sals_from_location
;
15571 ops
->decode_location
= bkpt_probe_decode_location
;
15574 ops
= &watchpoint_breakpoint_ops
;
15575 *ops
= base_breakpoint_ops
;
15576 ops
->re_set
= re_set_watchpoint
;
15577 ops
->insert_location
= insert_watchpoint
;
15578 ops
->remove_location
= remove_watchpoint
;
15579 ops
->breakpoint_hit
= breakpoint_hit_watchpoint
;
15580 ops
->check_status
= check_status_watchpoint
;
15581 ops
->resources_needed
= resources_needed_watchpoint
;
15582 ops
->works_in_software_mode
= works_in_software_mode_watchpoint
;
15583 ops
->print_it
= print_it_watchpoint
;
15584 ops
->print_mention
= print_mention_watchpoint
;
15585 ops
->print_recreate
= print_recreate_watchpoint
;
15586 ops
->explains_signal
= explains_signal_watchpoint
;
15588 /* Masked watchpoints. */
15589 ops
= &masked_watchpoint_breakpoint_ops
;
15590 *ops
= watchpoint_breakpoint_ops
;
15591 ops
->insert_location
= insert_masked_watchpoint
;
15592 ops
->remove_location
= remove_masked_watchpoint
;
15593 ops
->resources_needed
= resources_needed_masked_watchpoint
;
15594 ops
->works_in_software_mode
= works_in_software_mode_masked_watchpoint
;
15595 ops
->print_it
= print_it_masked_watchpoint
;
15596 ops
->print_one_detail
= print_one_detail_masked_watchpoint
;
15597 ops
->print_mention
= print_mention_masked_watchpoint
;
15598 ops
->print_recreate
= print_recreate_masked_watchpoint
;
15601 ops
= &tracepoint_breakpoint_ops
;
15602 *ops
= base_breakpoint_ops
;
15603 ops
->re_set
= tracepoint_re_set
;
15604 ops
->breakpoint_hit
= tracepoint_breakpoint_hit
;
15605 ops
->print_one_detail
= tracepoint_print_one_detail
;
15606 ops
->print_mention
= tracepoint_print_mention
;
15607 ops
->print_recreate
= tracepoint_print_recreate
;
15608 ops
->create_sals_from_location
= tracepoint_create_sals_from_location
;
15609 ops
->create_breakpoints_sal
= tracepoint_create_breakpoints_sal
;
15610 ops
->decode_location
= tracepoint_decode_location
;
15612 /* Probe tracepoints. */
15613 ops
= &tracepoint_probe_breakpoint_ops
;
15614 *ops
= tracepoint_breakpoint_ops
;
15615 ops
->create_sals_from_location
= tracepoint_probe_create_sals_from_location
;
15616 ops
->decode_location
= tracepoint_probe_decode_location
;
15618 /* Static tracepoints with marker (`-m'). */
15619 ops
= &strace_marker_breakpoint_ops
;
15620 *ops
= tracepoint_breakpoint_ops
;
15621 ops
->create_sals_from_location
= strace_marker_create_sals_from_location
;
15622 ops
->create_breakpoints_sal
= strace_marker_create_breakpoints_sal
;
15623 ops
->decode_location
= strace_marker_decode_location
;
15625 /* Fork catchpoints. */
15626 ops
= &catch_fork_breakpoint_ops
;
15627 *ops
= base_breakpoint_ops
;
15628 ops
->insert_location
= insert_catch_fork
;
15629 ops
->remove_location
= remove_catch_fork
;
15630 ops
->breakpoint_hit
= breakpoint_hit_catch_fork
;
15631 ops
->print_it
= print_it_catch_fork
;
15632 ops
->print_one
= print_one_catch_fork
;
15633 ops
->print_mention
= print_mention_catch_fork
;
15634 ops
->print_recreate
= print_recreate_catch_fork
;
15636 /* Vfork catchpoints. */
15637 ops
= &catch_vfork_breakpoint_ops
;
15638 *ops
= base_breakpoint_ops
;
15639 ops
->insert_location
= insert_catch_vfork
;
15640 ops
->remove_location
= remove_catch_vfork
;
15641 ops
->breakpoint_hit
= breakpoint_hit_catch_vfork
;
15642 ops
->print_it
= print_it_catch_vfork
;
15643 ops
->print_one
= print_one_catch_vfork
;
15644 ops
->print_mention
= print_mention_catch_vfork
;
15645 ops
->print_recreate
= print_recreate_catch_vfork
;
15647 /* Exec catchpoints. */
15648 ops
= &catch_exec_breakpoint_ops
;
15649 *ops
= base_breakpoint_ops
;
15650 ops
->insert_location
= insert_catch_exec
;
15651 ops
->remove_location
= remove_catch_exec
;
15652 ops
->breakpoint_hit
= breakpoint_hit_catch_exec
;
15653 ops
->print_it
= print_it_catch_exec
;
15654 ops
->print_one
= print_one_catch_exec
;
15655 ops
->print_mention
= print_mention_catch_exec
;
15656 ops
->print_recreate
= print_recreate_catch_exec
;
15658 /* Solib-related catchpoints. */
15659 ops
= &catch_solib_breakpoint_ops
;
15660 *ops
= base_breakpoint_ops
;
15661 ops
->insert_location
= insert_catch_solib
;
15662 ops
->remove_location
= remove_catch_solib
;
15663 ops
->breakpoint_hit
= breakpoint_hit_catch_solib
;
15664 ops
->check_status
= check_status_catch_solib
;
15665 ops
->print_it
= print_it_catch_solib
;
15666 ops
->print_one
= print_one_catch_solib
;
15667 ops
->print_mention
= print_mention_catch_solib
;
15668 ops
->print_recreate
= print_recreate_catch_solib
;
15670 ops
= &dprintf_breakpoint_ops
;
15671 *ops
= bkpt_base_breakpoint_ops
;
15672 ops
->re_set
= dprintf_re_set
;
15673 ops
->resources_needed
= bkpt_resources_needed
;
15674 ops
->print_it
= bkpt_print_it
;
15675 ops
->print_mention
= bkpt_print_mention
;
15676 ops
->print_recreate
= dprintf_print_recreate
;
15677 ops
->after_condition_true
= dprintf_after_condition_true
;
15678 ops
->breakpoint_hit
= dprintf_breakpoint_hit
;
15681 /* Chain containing all defined "enable breakpoint" subcommands. */
15683 static struct cmd_list_element
*enablebreaklist
= NULL
;
15686 _initialize_breakpoint (void)
15688 struct cmd_list_element
*c
;
15690 initialize_breakpoint_ops ();
15692 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
15693 observer_attach_free_objfile (disable_breakpoints_in_freed_objfile
);
15694 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
15696 breakpoint_objfile_key
15697 = register_objfile_data_with_cleanup (NULL
, free_breakpoint_probes
);
15699 breakpoint_chain
= 0;
15700 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
15701 before a breakpoint is set. */
15702 breakpoint_count
= 0;
15704 tracepoint_count
= 0;
15706 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
15707 Set ignore-count of breakpoint number N to COUNT.\n\
15708 Usage is `ignore N COUNT'."));
15710 add_com ("commands", class_breakpoint
, commands_command
, _("\
15711 Set commands to be executed when the given breakpoints are hit.\n\
15712 Give a space-separated breakpoint list as argument after \"commands\".\n\
15713 A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\
15715 With no argument, the targeted breakpoint is the last one set.\n\
15716 The commands themselves follow starting on the next line.\n\
15717 Type a line containing \"end\" to indicate the end of them.\n\
15718 Give \"silent\" as the first line to make the breakpoint silent;\n\
15719 then no output is printed when it is hit, except what the commands print."));
15721 c
= add_com ("condition", class_breakpoint
, condition_command
, _("\
15722 Specify breakpoint number N to break only if COND is true.\n\
15723 Usage is `condition N COND', where N is an integer and COND is an\n\
15724 expression to be evaluated whenever breakpoint N is reached."));
15725 set_cmd_completer (c
, condition_completer
);
15727 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
15728 Set a temporary breakpoint.\n\
15729 Like \"break\" except the breakpoint is only temporary,\n\
15730 so it will be deleted when hit. Equivalent to \"break\" followed\n\
15731 by using \"enable delete\" on the breakpoint number.\n\
15733 BREAK_ARGS_HELP ("tbreak")));
15734 set_cmd_completer (c
, location_completer
);
15736 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
15737 Set a hardware assisted breakpoint.\n\
15738 Like \"break\" except the breakpoint requires hardware support,\n\
15739 some target hardware may not have this support.\n\
15741 BREAK_ARGS_HELP ("hbreak")));
15742 set_cmd_completer (c
, location_completer
);
15744 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
15745 Set a temporary hardware assisted breakpoint.\n\
15746 Like \"hbreak\" except the breakpoint is only temporary,\n\
15747 so it will be deleted when hit.\n\
15749 BREAK_ARGS_HELP ("thbreak")));
15750 set_cmd_completer (c
, location_completer
);
15752 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
15753 Enable some breakpoints.\n\
15754 Give breakpoint numbers (separated by spaces) as arguments.\n\
15755 With no subcommand, breakpoints are enabled until you command otherwise.\n\
15756 This is used to cancel the effect of the \"disable\" command.\n\
15757 With a subcommand you can enable temporarily."),
15758 &enablelist
, "enable ", 1, &cmdlist
);
15760 add_com_alias ("en", "enable", class_breakpoint
, 1);
15762 add_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
15763 Enable some breakpoints.\n\
15764 Give breakpoint numbers (separated by spaces) as arguments.\n\
15765 This is used to cancel the effect of the \"disable\" command.\n\
15766 May be abbreviated to simply \"enable\".\n"),
15767 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
15769 add_cmd ("once", no_class
, enable_once_command
, _("\
15770 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15771 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15774 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15775 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15776 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15779 add_cmd ("count", no_class
, enable_count_command
, _("\
15780 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15781 If a breakpoint is hit while enabled in this fashion,\n\
15782 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15785 add_cmd ("delete", no_class
, enable_delete_command
, _("\
15786 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
15787 If a breakpoint is hit while enabled in this fashion, it is deleted."),
15790 add_cmd ("once", no_class
, enable_once_command
, _("\
15791 Enable breakpoints for one hit. Give breakpoint numbers.\n\
15792 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
15795 add_cmd ("count", no_class
, enable_count_command
, _("\
15796 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\
15797 If a breakpoint is hit while enabled in this fashion,\n\
15798 the count is decremented; when it reaches zero, the breakpoint is disabled."),
15801 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
15802 Disable some breakpoints.\n\
15803 Arguments are breakpoint numbers with spaces in between.\n\
15804 To disable all breakpoints, give no argument.\n\
15805 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
15806 &disablelist
, "disable ", 1, &cmdlist
);
15807 add_com_alias ("dis", "disable", class_breakpoint
, 1);
15808 add_com_alias ("disa", "disable", class_breakpoint
, 1);
15810 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
15811 Disable some breakpoints.\n\
15812 Arguments are breakpoint numbers with spaces in between.\n\
15813 To disable all breakpoints, give no argument.\n\
15814 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
15815 This command may be abbreviated \"disable\"."),
15818 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
15819 Delete some breakpoints or auto-display expressions.\n\
15820 Arguments are breakpoint numbers with spaces in between.\n\
15821 To delete all breakpoints, give no argument.\n\
15823 Also a prefix command for deletion of other GDB objects.\n\
15824 The \"unset\" command is also an alias for \"delete\"."),
15825 &deletelist
, "delete ", 1, &cmdlist
);
15826 add_com_alias ("d", "delete", class_breakpoint
, 1);
15827 add_com_alias ("del", "delete", class_breakpoint
, 1);
15829 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
15830 Delete some breakpoints or auto-display expressions.\n\
15831 Arguments are breakpoint numbers with spaces in between.\n\
15832 To delete all breakpoints, give no argument.\n\
15833 This command may be abbreviated \"delete\"."),
15836 add_com ("clear", class_breakpoint
, clear_command
, _("\
15837 Clear breakpoint at specified location.\n\
15838 Argument may be a linespec, explicit, or address location as described below.\n\
15840 With no argument, clears all breakpoints in the line that the selected frame\n\
15841 is executing in.\n"
15842 "\n" LOCATION_HELP_STRING
"\n\
15843 See also the \"delete\" command which clears breakpoints by number."));
15844 add_com_alias ("cl", "clear", class_breakpoint
, 1);
15846 c
= add_com ("break", class_breakpoint
, break_command
, _("\
15847 Set breakpoint at specified location.\n"
15848 BREAK_ARGS_HELP ("break")));
15849 set_cmd_completer (c
, location_completer
);
15851 add_com_alias ("b", "break", class_run
, 1);
15852 add_com_alias ("br", "break", class_run
, 1);
15853 add_com_alias ("bre", "break", class_run
, 1);
15854 add_com_alias ("brea", "break", class_run
, 1);
15858 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
15859 Break in function/address or break at a line in the current file."),
15860 &stoplist
, "stop ", 1, &cmdlist
);
15861 add_cmd ("in", class_breakpoint
, stopin_command
,
15862 _("Break in function or address."), &stoplist
);
15863 add_cmd ("at", class_breakpoint
, stopat_command
,
15864 _("Break at a line in the current file."), &stoplist
);
15865 add_com ("status", class_info
, info_breakpoints_command
, _("\
15866 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
15867 The \"Type\" column indicates one of:\n\
15868 \tbreakpoint - normal breakpoint\n\
15869 \twatchpoint - watchpoint\n\
15870 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15871 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15872 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15873 address and file/line number respectively.\n\
15875 Convenience variable \"$_\" and default examine address for \"x\"\n\
15876 are set to the address of the last breakpoint listed unless the command\n\
15877 is prefixed with \"server \".\n\n\
15878 Convenience variable \"$bpnum\" contains the number of the last\n\
15879 breakpoint set."));
15882 add_info ("breakpoints", info_breakpoints_command
, _("\
15883 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
15884 The \"Type\" column indicates one of:\n\
15885 \tbreakpoint - normal breakpoint\n\
15886 \twatchpoint - watchpoint\n\
15887 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15888 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15889 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15890 address and file/line number respectively.\n\
15892 Convenience variable \"$_\" and default examine address for \"x\"\n\
15893 are set to the address of the last breakpoint listed unless the command\n\
15894 is prefixed with \"server \".\n\n\
15895 Convenience variable \"$bpnum\" contains the number of the last\n\
15896 breakpoint set."));
15898 add_info_alias ("b", "breakpoints", 1);
15900 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
15901 Status of all breakpoints, or breakpoint number NUMBER.\n\
15902 The \"Type\" column indicates one of:\n\
15903 \tbreakpoint - normal breakpoint\n\
15904 \twatchpoint - watchpoint\n\
15905 \tlongjmp - internal breakpoint used to step through longjmp()\n\
15906 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
15907 \tuntil - internal breakpoint used by the \"until\" command\n\
15908 \tfinish - internal breakpoint used by the \"finish\" command\n\
15909 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
15910 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
15911 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
15912 address and file/line number respectively.\n\
15914 Convenience variable \"$_\" and default examine address for \"x\"\n\
15915 are set to the address of the last breakpoint listed unless the command\n\
15916 is prefixed with \"server \".\n\n\
15917 Convenience variable \"$bpnum\" contains the number of the last\n\
15919 &maintenanceinfolist
);
15921 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
15922 Set catchpoints to catch events."),
15923 &catch_cmdlist
, "catch ",
15924 0/*allow-unknown*/, &cmdlist
);
15926 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
15927 Set temporary catchpoints to catch events."),
15928 &tcatch_cmdlist
, "tcatch ",
15929 0/*allow-unknown*/, &cmdlist
);
15931 add_catch_command ("fork", _("Catch calls to fork."),
15932 catch_fork_command_1
,
15934 (void *) (uintptr_t) catch_fork_permanent
,
15935 (void *) (uintptr_t) catch_fork_temporary
);
15936 add_catch_command ("vfork", _("Catch calls to vfork."),
15937 catch_fork_command_1
,
15939 (void *) (uintptr_t) catch_vfork_permanent
,
15940 (void *) (uintptr_t) catch_vfork_temporary
);
15941 add_catch_command ("exec", _("Catch calls to exec."),
15942 catch_exec_command_1
,
15946 add_catch_command ("load", _("Catch loads of shared libraries.\n\
15947 Usage: catch load [REGEX]\n\
15948 If REGEX is given, only stop for libraries matching the regular expression."),
15949 catch_load_command_1
,
15953 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\
15954 Usage: catch unload [REGEX]\n\
15955 If REGEX is given, only stop for libraries matching the regular expression."),
15956 catch_unload_command_1
,
15961 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
15962 Set a watchpoint for an expression.\n\
15963 Usage: watch [-l|-location] EXPRESSION\n\
15964 A watchpoint stops execution of your program whenever the value of\n\
15965 an expression changes.\n\
15966 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15967 the memory to which it refers."));
15968 set_cmd_completer (c
, expression_completer
);
15970 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
15971 Set a read watchpoint for an expression.\n\
15972 Usage: rwatch [-l|-location] EXPRESSION\n\
15973 A watchpoint stops execution of your program whenever the value of\n\
15974 an expression is read.\n\
15975 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15976 the memory to which it refers."));
15977 set_cmd_completer (c
, expression_completer
);
15979 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
15980 Set a watchpoint for an expression.\n\
15981 Usage: awatch [-l|-location] EXPRESSION\n\
15982 A watchpoint stops execution of your program whenever the value of\n\
15983 an expression is either read or written.\n\
15984 If -l or -location is given, this evaluates EXPRESSION and watches\n\
15985 the memory to which it refers."));
15986 set_cmd_completer (c
, expression_completer
);
15988 add_info ("watchpoints", info_watchpoints_command
, _("\
15989 Status of specified watchpoints (all watchpoints if no argument)."));
15991 /* XXX: cagney/2005-02-23: This should be a boolean, and should
15992 respond to changes - contrary to the description. */
15993 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
15994 &can_use_hw_watchpoints
, _("\
15995 Set debugger's willingness to use watchpoint hardware."), _("\
15996 Show debugger's willingness to use watchpoint hardware."), _("\
15997 If zero, gdb will not use hardware for new watchpoints, even if\n\
15998 such is available. (However, any hardware watchpoints that were\n\
15999 created before setting this to nonzero, will continue to use watchpoint\n\
16002 show_can_use_hw_watchpoints
,
16003 &setlist
, &showlist
);
16005 can_use_hw_watchpoints
= 1;
16007 /* Tracepoint manipulation commands. */
16009 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
16010 Set a tracepoint at specified location.\n\
16012 BREAK_ARGS_HELP ("trace") "\n\
16013 Do \"help tracepoints\" for info on other tracepoint commands."));
16014 set_cmd_completer (c
, location_completer
);
16016 add_com_alias ("tp", "trace", class_alias
, 0);
16017 add_com_alias ("tr", "trace", class_alias
, 1);
16018 add_com_alias ("tra", "trace", class_alias
, 1);
16019 add_com_alias ("trac", "trace", class_alias
, 1);
16021 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
16022 Set a fast tracepoint at specified location.\n\
16024 BREAK_ARGS_HELP ("ftrace") "\n\
16025 Do \"help tracepoints\" for info on other tracepoint commands."));
16026 set_cmd_completer (c
, location_completer
);
16028 c
= add_com ("strace", class_breakpoint
, strace_command
, _("\
16029 Set a static tracepoint at location or marker.\n\
16031 strace [LOCATION] [if CONDITION]\n\
16032 LOCATION may be a linespec, explicit, or address location (described below) \n\
16033 or -m MARKER_ID.\n\n\
16034 If a marker id is specified, probe the marker with that name. With\n\
16035 no LOCATION, uses current execution address of the selected stack frame.\n\
16036 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\
16037 This collects arbitrary user data passed in the probe point call to the\n\
16038 tracing library. You can inspect it when analyzing the trace buffer,\n\
16039 by printing the $_sdata variable like any other convenience variable.\n\
16041 CONDITION is a boolean expression.\n\
16042 \n" LOCATION_HELP_STRING
"\n\
16043 Multiple tracepoints at one place are permitted, and useful if their\n\
16044 conditions are different.\n\
16046 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
16047 Do \"help tracepoints\" for info on other tracepoint commands."));
16048 set_cmd_completer (c
, location_completer
);
16050 add_info ("tracepoints", info_tracepoints_command
, _("\
16051 Status of specified tracepoints (all tracepoints if no argument).\n\
16052 Convenience variable \"$tpnum\" contains the number of the\n\
16053 last tracepoint set."));
16055 add_info_alias ("tp", "tracepoints", 1);
16057 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
16058 Delete specified tracepoints.\n\
16059 Arguments are tracepoint numbers, separated by spaces.\n\
16060 No argument means delete all tracepoints."),
16062 add_alias_cmd ("tr", "tracepoints", class_trace
, 1, &deletelist
);
16064 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
16065 Disable specified tracepoints.\n\
16066 Arguments are tracepoint numbers, separated by spaces.\n\
16067 No argument means disable all tracepoints."),
16069 deprecate_cmd (c
, "disable");
16071 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
16072 Enable specified tracepoints.\n\
16073 Arguments are tracepoint numbers, separated by spaces.\n\
16074 No argument means enable all tracepoints."),
16076 deprecate_cmd (c
, "enable");
16078 add_com ("passcount", class_trace
, trace_pass_command
, _("\
16079 Set the passcount for a tracepoint.\n\
16080 The trace will end when the tracepoint has been passed 'count' times.\n\
16081 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
16082 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
16084 add_prefix_cmd ("save", class_breakpoint
, save_command
,
16085 _("Save breakpoint definitions as a script."),
16086 &save_cmdlist
, "save ",
16087 0/*allow-unknown*/, &cmdlist
);
16089 c
= add_cmd ("breakpoints", class_breakpoint
, save_breakpoints_command
, _("\
16090 Save current breakpoint definitions as a script.\n\
16091 This includes all types of breakpoints (breakpoints, watchpoints,\n\
16092 catchpoints, tracepoints). Use the 'source' command in another debug\n\
16093 session to restore them."),
16095 set_cmd_completer (c
, filename_completer
);
16097 c
= add_cmd ("tracepoints", class_trace
, save_tracepoints_command
, _("\
16098 Save current tracepoint definitions as a script.\n\
16099 Use the 'source' command in another debug session to restore them."),
16101 set_cmd_completer (c
, filename_completer
);
16103 c
= add_com_alias ("save-tracepoints", "save tracepoints", class_trace
, 0);
16104 deprecate_cmd (c
, "save tracepoints");
16106 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
16107 Breakpoint specific settings\n\
16108 Configure various breakpoint-specific variables such as\n\
16109 pending breakpoint behavior"),
16110 &breakpoint_set_cmdlist
, "set breakpoint ",
16111 0/*allow-unknown*/, &setlist
);
16112 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
16113 Breakpoint specific settings\n\
16114 Configure various breakpoint-specific variables such as\n\
16115 pending breakpoint behavior"),
16116 &breakpoint_show_cmdlist
, "show breakpoint ",
16117 0/*allow-unknown*/, &showlist
);
16119 add_setshow_auto_boolean_cmd ("pending", no_class
,
16120 &pending_break_support
, _("\
16121 Set debugger's behavior regarding pending breakpoints."), _("\
16122 Show debugger's behavior regarding pending breakpoints."), _("\
16123 If on, an unrecognized breakpoint location will cause gdb to create a\n\
16124 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
16125 an error. If auto, an unrecognized breakpoint location results in a\n\
16126 user-query to see if a pending breakpoint should be created."),
16128 show_pending_break_support
,
16129 &breakpoint_set_cmdlist
,
16130 &breakpoint_show_cmdlist
);
16132 pending_break_support
= AUTO_BOOLEAN_AUTO
;
16134 add_setshow_boolean_cmd ("auto-hw", no_class
,
16135 &automatic_hardware_breakpoints
, _("\
16136 Set automatic usage of hardware breakpoints."), _("\
16137 Show automatic usage of hardware breakpoints."), _("\
16138 If set, the debugger will automatically use hardware breakpoints for\n\
16139 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
16140 a warning will be emitted for such breakpoints."),
16142 show_automatic_hardware_breakpoints
,
16143 &breakpoint_set_cmdlist
,
16144 &breakpoint_show_cmdlist
);
16146 add_setshow_boolean_cmd ("always-inserted", class_support
,
16147 &always_inserted_mode
, _("\
16148 Set mode for inserting breakpoints."), _("\
16149 Show mode for inserting breakpoints."), _("\
16150 When this mode is on, breakpoints are inserted immediately as soon as\n\
16151 they're created, kept inserted even when execution stops, and removed\n\
16152 only when the user deletes them. When this mode is off (the default),\n\
16153 breakpoints are inserted only when execution continues, and removed\n\
16154 when execution stops."),
16156 &show_always_inserted_mode
,
16157 &breakpoint_set_cmdlist
,
16158 &breakpoint_show_cmdlist
);
16160 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint
,
16161 condition_evaluation_enums
,
16162 &condition_evaluation_mode_1
, _("\
16163 Set mode of breakpoint condition evaluation."), _("\
16164 Show mode of breakpoint condition evaluation."), _("\
16165 When this is set to \"host\", breakpoint conditions will be\n\
16166 evaluated on the host's side by GDB. When it is set to \"target\",\n\
16167 breakpoint conditions will be downloaded to the target (if the target\n\
16168 supports such feature) and conditions will be evaluated on the target's side.\n\
16169 If this is set to \"auto\" (default), this will be automatically set to\n\
16170 \"target\" if it supports condition evaluation, otherwise it will\n\
16171 be set to \"gdb\""),
16172 &set_condition_evaluation_mode
,
16173 &show_condition_evaluation_mode
,
16174 &breakpoint_set_cmdlist
,
16175 &breakpoint_show_cmdlist
);
16177 add_com ("break-range", class_breakpoint
, break_range_command
, _("\
16178 Set a breakpoint for an address range.\n\
16179 break-range START-LOCATION, END-LOCATION\n\
16180 where START-LOCATION and END-LOCATION can be one of the following:\n\
16181 LINENUM, for that line in the current file,\n\
16182 FILE:LINENUM, for that line in that file,\n\
16183 +OFFSET, for that number of lines after the current line\n\
16184 or the start of the range\n\
16185 FUNCTION, for the first line in that function,\n\
16186 FILE:FUNCTION, to distinguish among like-named static functions.\n\
16187 *ADDRESS, for the instruction at that address.\n\
16189 The breakpoint will stop execution of the inferior whenever it executes\n\
16190 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\
16191 range (including START-LOCATION and END-LOCATION)."));
16193 c
= add_com ("dprintf", class_breakpoint
, dprintf_command
, _("\
16194 Set a dynamic printf at specified location.\n\
16195 dprintf location,format string,arg1,arg2,...\n\
16196 location may be a linespec, explicit, or address location.\n"
16197 "\n" LOCATION_HELP_STRING
));
16198 set_cmd_completer (c
, location_completer
);
16200 add_setshow_enum_cmd ("dprintf-style", class_support
,
16201 dprintf_style_enums
, &dprintf_style
, _("\
16202 Set the style of usage for dynamic printf."), _("\
16203 Show the style of usage for dynamic printf."), _("\
16204 This setting chooses how GDB will do a dynamic printf.\n\
16205 If the value is \"gdb\", then the printing is done by GDB to its own\n\
16206 console, as with the \"printf\" command.\n\
16207 If the value is \"call\", the print is done by calling a function in your\n\
16208 program; by default printf(), but you can choose a different function or\n\
16209 output stream by setting dprintf-function and dprintf-channel."),
16210 update_dprintf_commands
, NULL
,
16211 &setlist
, &showlist
);
16213 dprintf_function
= xstrdup ("printf");
16214 add_setshow_string_cmd ("dprintf-function", class_support
,
16215 &dprintf_function
, _("\
16216 Set the function to use for dynamic printf"), _("\
16217 Show the function to use for dynamic printf"), NULL
,
16218 update_dprintf_commands
, NULL
,
16219 &setlist
, &showlist
);
16221 dprintf_channel
= xstrdup ("");
16222 add_setshow_string_cmd ("dprintf-channel", class_support
,
16223 &dprintf_channel
, _("\
16224 Set the channel to use for dynamic printf"), _("\
16225 Show the channel to use for dynamic printf"), NULL
,
16226 update_dprintf_commands
, NULL
,
16227 &setlist
, &showlist
);
16229 add_setshow_boolean_cmd ("disconnected-dprintf", no_class
,
16230 &disconnected_dprintf
, _("\
16231 Set whether dprintf continues after GDB disconnects."), _("\
16232 Show whether dprintf continues after GDB disconnects."), _("\
16233 Use this to let dprintf commands continue to hit and produce output\n\
16234 even if GDB disconnects or detaches from the target."),
16237 &setlist
, &showlist
);
16239 add_com ("agent-printf", class_vars
, agent_printf_command
, _("\
16240 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
16241 (target agent only) This is useful for formatted output in user-defined commands."));
16243 automatic_hardware_breakpoints
= 1;
16245 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);
16246 observer_attach_thread_exit (remove_threaded_breakpoints
);